@keymanapp/common-types 17.0.85-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.
Files changed (248) hide show
  1. package/build/src/consts/virtual-key-constants.d.ts +131 -0
  2. package/build/src/consts/virtual-key-constants.d.ts.map +1 -0
  3. package/build/src/consts/virtual-key-constants.js +245 -0
  4. package/build/src/consts/virtual-key-constants.js.map +1 -0
  5. package/build/src/import/techpreview/cldr_info.json +5 -0
  6. package/build/src/import/techpreview/keys-Latn-implied.xml +80 -0
  7. package/build/src/import/techpreview/keys-Zyyy-currency.xml +22 -0
  8. package/build/src/import/techpreview/keys-Zyyy-punctuation.xml +46 -0
  9. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts +7 -0
  10. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts.map +1 -0
  11. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js +74 -0
  12. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js.map +1 -0
  13. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts +24 -0
  14. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts.map +1 -0
  15. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js +75 -0
  16. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js.map +1 -0
  17. package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts +76 -0
  18. package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts.map +1 -0
  19. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js +26 -0
  20. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js.map +1 -0
  21. package/build/src/keyman-touch-layout.clean.spec.json +170 -0
  22. package/build/src/kmx/element-string.d.ts +19 -0
  23. package/build/src/kmx/element-string.d.ts.map +1 -0
  24. package/build/src/kmx/element-string.js +72 -0
  25. package/build/src/kmx/element-string.js.map +1 -0
  26. package/build/src/kmx/kmx-builder.d.ts +77 -0
  27. package/build/src/kmx/kmx-builder.d.ts.map +1 -0
  28. package/build/src/kmx/kmx-builder.js +193 -0
  29. package/build/src/kmx/kmx-builder.js.map +1 -0
  30. package/build/src/kmx/kmx-plus-builder/build-disp.d.ts +18 -0
  31. package/build/src/kmx/kmx-plus-builder/build-disp.d.ts.map +1 -0
  32. package/build/src/kmx/kmx-plus-builder/build-disp.js +25 -0
  33. package/build/src/kmx/kmx-plus-builder/build-disp.js.map +1 -0
  34. package/build/src/kmx/kmx-plus-builder/build-elem.d.ts +26 -0
  35. package/build/src/kmx/kmx-plus-builder/build-elem.d.ts.map +1 -0
  36. package/build/src/kmx/kmx-plus-builder/build-elem.js +78 -0
  37. package/build/src/kmx/kmx-plus-builder/build-elem.js.map +1 -0
  38. package/build/src/kmx/kmx-plus-builder/build-keys.d.ts +60 -0
  39. package/build/src/kmx/kmx-plus-builder/build-keys.d.ts.map +1 -0
  40. package/build/src/kmx/kmx-plus-builder/build-keys.js +107 -0
  41. package/build/src/kmx/kmx-plus-builder/build-keys.js.map +1 -0
  42. package/build/src/kmx/kmx-plus-builder/build-layr.d.ts +54 -0
  43. package/build/src/kmx/kmx-plus-builder/build-layr.d.ts.map +1 -0
  44. package/build/src/kmx/kmx-plus-builder/build-layr.js +99 -0
  45. package/build/src/kmx/kmx-plus-builder/build-layr.js.map +1 -0
  46. package/build/src/kmx/kmx-plus-builder/build-list.d.ts +34 -0
  47. package/build/src/kmx/kmx-plus-builder/build-list.d.ts.map +1 -0
  48. package/build/src/kmx/kmx-plus-builder/build-list.js +62 -0
  49. package/build/src/kmx/kmx-plus-builder/build-list.js.map +1 -0
  50. package/build/src/kmx/kmx-plus-builder/build-loca.d.ts +12 -0
  51. package/build/src/kmx/kmx-plus-builder/build-loca.d.ts.map +1 -0
  52. package/build/src/kmx/kmx-plus-builder/build-loca.js +20 -0
  53. package/build/src/kmx/kmx-plus-builder/build-loca.js.map +1 -0
  54. package/build/src/kmx/kmx-plus-builder/build-meta.d.ts +17 -0
  55. package/build/src/kmx/kmx-plus-builder/build-meta.d.ts.map +1 -0
  56. package/build/src/kmx/kmx-plus-builder/build-meta.js +21 -0
  57. package/build/src/kmx/kmx-plus-builder/build-meta.js.map +1 -0
  58. package/build/src/kmx/kmx-plus-builder/build-name.d.ts +12 -0
  59. package/build/src/kmx/kmx-plus-builder/build-name.d.ts.map +1 -0
  60. package/build/src/kmx/kmx-plus-builder/build-name.js +23 -0
  61. package/build/src/kmx/kmx-plus-builder/build-name.js.map +1 -0
  62. package/build/src/kmx/kmx-plus-builder/build-ordr.d.ts +18 -0
  63. package/build/src/kmx/kmx-plus-builder/build-ordr.d.ts.map +1 -0
  64. package/build/src/kmx/kmx-plus-builder/build-ordr.js +27 -0
  65. package/build/src/kmx/kmx-plus-builder/build-ordr.js.map +1 -0
  66. package/build/src/kmx/kmx-plus-builder/build-sect.d.ts +16 -0
  67. package/build/src/kmx/kmx-plus-builder/build-sect.d.ts.map +1 -0
  68. package/build/src/kmx/kmx-plus-builder/build-sect.js +14 -0
  69. package/build/src/kmx/kmx-plus-builder/build-sect.js.map +1 -0
  70. package/build/src/kmx/kmx-plus-builder/build-strs.d.ts +18 -0
  71. package/build/src/kmx/kmx-plus-builder/build-strs.d.ts.map +1 -0
  72. package/build/src/kmx/kmx-plus-builder/build-strs.js +34 -0
  73. package/build/src/kmx/kmx-plus-builder/build-strs.js.map +1 -0
  74. package/build/src/kmx/kmx-plus-builder/build-tran.d.ts +20 -0
  75. package/build/src/kmx/kmx-plus-builder/build-tran.d.ts.map +1 -0
  76. package/build/src/kmx/kmx-plus-builder/build-tran.js +30 -0
  77. package/build/src/kmx/kmx-plus-builder/build-tran.js.map +1 -0
  78. package/build/src/kmx/kmx-plus-builder/build-vkey.d.ts +16 -0
  79. package/build/src/kmx/kmx-plus-builder/build-vkey.d.ts.map +1 -0
  80. package/build/src/kmx/kmx-plus-builder/build-vkey.js +23 -0
  81. package/build/src/kmx/kmx-plus-builder/build-vkey.js.map +1 -0
  82. package/build/src/kmx/kmx-plus-builder/builder-section.d.ts +6 -0
  83. package/build/src/kmx/kmx-plus-builder/builder-section.d.ts.map +1 -0
  84. package/build/src/kmx/kmx-plus-builder/builder-section.js +3 -0
  85. package/build/src/kmx/kmx-plus-builder/builder-section.js.map +1 -0
  86. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts +47 -0
  87. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts.map +1 -0
  88. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js +143 -0
  89. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js.map +1 -0
  90. package/build/src/kmx/kmx-plus.d.ts +259 -0
  91. package/build/src/kmx/kmx-plus.d.ts.map +1 -0
  92. package/build/src/kmx/kmx-plus.js +594 -0
  93. package/build/src/kmx/kmx-plus.js.map +1 -0
  94. package/build/src/kmx/kmx.d.ts +166 -0
  95. package/build/src/kmx/kmx.d.ts.map +1 -0
  96. package/build/src/kmx/kmx.js +271 -0
  97. package/build/src/kmx/kmx.js.map +1 -0
  98. package/build/src/kmx/string-list.d.ts +29 -0
  99. package/build/src/kmx/string-list.d.ts.map +1 -0
  100. package/build/src/kmx/string-list.js +75 -0
  101. package/build/src/kmx/string-list.js.map +1 -0
  102. package/build/src/kpj/keyman-developer-project.d.ts +58 -0
  103. package/build/src/kpj/keyman-developer-project.d.ts.map +1 -0
  104. package/build/src/kpj/keyman-developer-project.js +141 -0
  105. package/build/src/kpj/keyman-developer-project.js.map +1 -0
  106. package/build/src/kpj/kpj-file-reader.d.ts +17 -0
  107. package/build/src/kpj/kpj-file-reader.d.ts.map +1 -0
  108. package/build/src/kpj/kpj-file-reader.js +92 -0
  109. package/build/src/kpj/kpj-file-reader.js.map +1 -0
  110. package/build/src/kpj/kpj-file.d.ts +39 -0
  111. package/build/src/kpj/kpj-file.d.ts.map +1 -0
  112. package/build/src/kpj/kpj-file.js +11 -0
  113. package/build/src/kpj/kpj-file.js.map +1 -0
  114. package/build/src/kpj.schema.json +127 -0
  115. package/build/src/kvk/kvk-file-reader.d.ts +5 -0
  116. package/build/src/kvk/kvk-file-reader.d.ts.map +1 -0
  117. package/build/src/kvk/kvk-file-reader.js +35 -0
  118. package/build/src/kvk/kvk-file-reader.js.map +1 -0
  119. package/build/src/kvk/kvk-file-writer.d.ts +20 -0
  120. package/build/src/kvk/kvk-file-writer.d.ts.map +1 -0
  121. package/build/src/kvk/kvk-file-writer.js +67 -0
  122. package/build/src/kvk/kvk-file-writer.js.map +1 -0
  123. package/build/src/kvk/kvk-file.d.ts +64 -0
  124. package/build/src/kvk/kvk-file.d.ts.map +1 -0
  125. package/build/src/kvk/kvk-file.js +63 -0
  126. package/build/src/kvk/kvk-file.js.map +1 -0
  127. package/build/src/kvk/kvks-file-reader.d.ts +30 -0
  128. package/build/src/kvk/kvks-file-reader.d.ts.map +1 -0
  129. package/build/src/kvk/kvks-file-reader.js +154 -0
  130. package/build/src/kvk/kvks-file-reader.js.map +1 -0
  131. package/build/src/kvk/kvks-file-writer.d.ts +6 -0
  132. package/build/src/kvk/kvks-file-writer.d.ts.map +1 -0
  133. package/build/src/kvk/kvks-file-writer.js +99 -0
  134. package/build/src/kvk/kvks-file-writer.js.map +1 -0
  135. package/build/src/kvk/kvks-file.d.ts +44 -0
  136. package/build/src/kvk/kvks-file.d.ts.map +1 -0
  137. package/build/src/kvk/kvks-file.js +10 -0
  138. package/build/src/kvk/kvks-file.js.map +1 -0
  139. package/build/src/kvk/visual-keyboard.d.ts +35 -0
  140. package/build/src/kvk/visual-keyboard.d.ts.map +1 -0
  141. package/build/src/kvk/visual-keyboard.js +61 -0
  142. package/build/src/kvk/visual-keyboard.js.map +1 -0
  143. package/build/src/kvks.schema.json +182 -0
  144. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts +56 -0
  145. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts.map +1 -0
  146. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js +20 -0
  147. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js.map +1 -0
  148. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts +91 -0
  149. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts.map +1 -0
  150. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js +370 -0
  151. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js.map +1 -0
  152. package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts +143 -0
  153. package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts.map +1 -0
  154. package/build/src/ldml-keyboard/ldml-keyboard-xml.js +34 -0
  155. package/build/src/ldml-keyboard/ldml-keyboard-xml.js.map +1 -0
  156. package/build/src/ldml-keyboard.schema.json +634 -0
  157. package/build/src/ldml-keyboardtest.schema.json +221 -0
  158. package/build/src/main.d.ts +21 -0
  159. package/build/src/main.d.ts.map +1 -0
  160. package/build/src/main.js +20 -0
  161. package/build/src/main.js.map +1 -0
  162. package/build/src/util/common-events.d.ts +49 -0
  163. package/build/src/util/common-events.d.ts.map +1 -0
  164. package/build/src/util/common-events.js +29 -0
  165. package/build/src/util/common-events.js.map +1 -0
  166. package/build/src/util/compiler-interfaces.d.ts +51 -0
  167. package/build/src/util/compiler-interfaces.d.ts.map +1 -0
  168. package/build/src/util/compiler-interfaces.js +33 -0
  169. package/build/src/util/compiler-interfaces.js.map +1 -0
  170. package/build/src/util/util.d.ts +17 -0
  171. package/build/src/util/util.d.ts.map +1 -0
  172. package/build/src/util/util.js +67 -0
  173. package/build/src/util/util.js.map +1 -0
  174. package/build/tsconfig.tsbuildinfo +1 -0
  175. package/build.sh +86 -0
  176. package/package.json +58 -0
  177. package/src/consts/virtual-key-constants.ts +257 -0
  178. package/src/keyman-touch-layout/keyman-touch-layout-file-reader.ts +81 -0
  179. package/src/keyman-touch-layout/keyman-touch-layout-file-writer.ts +84 -0
  180. package/src/keyman-touch-layout/keyman-touch-layout-file.ts +87 -0
  181. package/src/kmx/element-string.ts +79 -0
  182. package/src/kmx/kmx-builder.ts +287 -0
  183. package/src/kmx/kmx-plus-builder/build-disp.ts +46 -0
  184. package/src/kmx/kmx-plus-builder/build-elem.ts +103 -0
  185. package/src/kmx/kmx-plus-builder/build-keys.ts +175 -0
  186. package/src/kmx/kmx-plus-builder/build-layr.ts +154 -0
  187. package/src/kmx/kmx-plus-builder/build-list.ts +95 -0
  188. package/src/kmx/kmx-plus-builder/build-loca.ts +34 -0
  189. package/src/kmx/kmx-plus-builder/build-meta.ts +37 -0
  190. package/src/kmx/kmx-plus-builder/build-name.ts +37 -0
  191. package/src/kmx/kmx-plus-builder/build-ordr.ts +45 -0
  192. package/src/kmx/kmx-plus-builder/build-sect.ts +31 -0
  193. package/src/kmx/kmx-plus-builder/build-strs.ts +58 -0
  194. package/src/kmx/kmx-plus-builder/build-tran.ts +50 -0
  195. package/src/kmx/kmx-plus-builder/build-vkey.ts +43 -0
  196. package/src/kmx/kmx-plus-builder/builder-section.ts +6 -0
  197. package/src/kmx/kmx-plus-builder/kmx-plus-builder.ts +190 -0
  198. package/src/kmx/kmx-plus.ts +692 -0
  199. package/src/kmx/kmx.ts +360 -0
  200. package/src/kmx/string-list.ts +74 -0
  201. package/src/kpj/keyman-developer-project.ts +155 -0
  202. package/src/kpj/kpj-file-reader.ts +103 -0
  203. package/src/kpj/kpj-file.ts +52 -0
  204. package/src/kvk/kvk-file-reader.ts +34 -0
  205. package/src/kvk/kvk-file-writer.ts +72 -0
  206. package/src/kvk/kvk-file.ts +122 -0
  207. package/src/kvk/kvks-file-reader.ts +164 -0
  208. package/src/kvk/kvks-file-writer.ts +113 -0
  209. package/src/kvk/kvks-file.ts +53 -0
  210. package/src/kvk/visual-keyboard.ts +80 -0
  211. package/src/ldml-keyboard/ldml-keyboard-testdata-xml.ts +74 -0
  212. package/src/ldml-keyboard/ldml-keyboard-xml-reader.ts +387 -0
  213. package/src/ldml-keyboard/ldml-keyboard-xml.ts +177 -0
  214. package/src/main.ts +27 -0
  215. package/src/restructure.d.ts +2 -0
  216. package/src/util/common-events.ts +50 -0
  217. package/src/util/compiler-interfaces.ts +54 -0
  218. package/src/util/util.ts +68 -0
  219. package/test/fixtures/import-minimal.xml +8 -0
  220. package/test/fixtures/import-minimal1.xml +11 -0
  221. package/test/fixtures/import-minimal2.xml +11 -0
  222. package/test/fixtures/import-symbols.xml +13 -0
  223. package/test/fixtures/invalid-conforms-to.xml +19 -0
  224. package/test/fixtures/invalid-import-base.xml +16 -0
  225. package/test/fixtures/invalid-import-path.xml +16 -0
  226. package/test/fixtures/invalid-import-readfail.xml +16 -0
  227. package/test/fixtures/invalid-import-wrongroot.xml +16 -0
  228. package/test/fixtures/invalid-structure-per-dtd.xml +8 -0
  229. package/test/fixtures/keyman-touch-layout/khmer_angkor.keyman-touch-layout +1950 -0
  230. package/test/fixtures/keyman-touch-layout/legacy.keyman-touch-layout +36 -0
  231. package/test/fixtures/kpj/khmer_angkor.kpj +187 -0
  232. package/test/fixtures/kvk/khmer_angkor.kvk +0 -0
  233. package/test/fixtures/kvk/khmer_angkor.kvks +206 -0
  234. package/test/fixtures/test-fr.xml +22 -0
  235. package/test/helpers/index.ts +39 -0
  236. package/test/helpers/reader-callback-test.ts +199 -0
  237. package/test/keyman-touch-layout/test-keyman-touch-layout-file-reader.ts +71 -0
  238. package/test/keyman-touch-layout/test-keyman-touch-layout-round-trip.ts +35 -0
  239. package/test/kpj/test-kpj-file-reader.ts +123 -0
  240. package/test/kvk/test-kvk-file.ts +15 -0
  241. package/test/kvk/test-kvk-round-trip.ts +87 -0
  242. package/test/kvk/test-kvk-utils.ts +24 -0
  243. package/test/kvk/test-kvks-file.ts +45 -0
  244. package/test/ldml-keyboard/test-ldml-keyboard-testdata-reader.ts +51 -0
  245. package/test/ldml-keyboard/test-ldml-keyboard-xml-reader.ts +131 -0
  246. package/test/tsconfig.json +21 -0
  247. package/test/util/test-unescape.ts +38 -0
  248. package/tsconfig.json +17 -0
@@ -0,0 +1,175 @@
1
+
2
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
3
+ import { KeysFlick, KMXPlusData, StrsItem } from "../kmx-plus.js";
4
+ import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
5
+ import { build_list_index, BUILDER_LIST } from "./build-list.js";
6
+ import { BUILDER_SECTION } from "./builder-section.js";
7
+
8
+ /* ------------------------------------------------------------------
9
+ * keys section
10
+ ------------------------------------------------------------------ */
11
+
12
+ /**
13
+ * This struct is a single <key> in the keys keybag
14
+ */
15
+ interface BUILDER_KEYS_KEY {
16
+ to: number; // str or single codepoint
17
+ flags: number;
18
+ id: number; // str with original key id
19
+ _id: string; // original key id, for sorting
20
+ switch: number; // str with layer of new l
21
+ width: number; // ceil((width||1)*10), so 12 for width 1.2
22
+ longPress: number; // list of longPress sequences
23
+ longPressDefault: number; // str with the default longPress target
24
+ multiTap: number; // list of multiTap sequences
25
+ flicks: number; // index into the flicks[] subtable for this flick list
26
+ };
27
+
28
+ /**
29
+ * This is a <flicks>, a list of <flick> elements.
30
+ */
31
+ interface BUILDER_KEYS_FLICKS {
32
+ count: number; // number of BUILDER_KEYS_FLICK entries in this flick list
33
+ flick: number; // index into the flick[] subtable of the first flick in the list
34
+ id: number; // str with the original id of this flicks
35
+ _id: string; // copy of the flicks id, used for sorting during build
36
+ _flicks: KeysFlick[]; // temporary copy of KeysFlick object
37
+ };
38
+
39
+ /**
40
+ * This is a single <flick> element.
41
+ */
42
+ interface BUILDER_KEYS_FLICK {
43
+ directions: number; // list of cardinal/intercardinal directions
44
+ flags: number; //
45
+ to: number; // str or single codepoint
46
+ };
47
+
48
+
49
+ interface BUILDER_KEYS_KMAP {
50
+ vkey: number;
51
+ mod: number;
52
+ key: number; //index to keys.key
53
+ };
54
+
55
+ /**
56
+ * Builder for the 'keys' section
57
+ */
58
+ export interface BUILDER_KEYS extends BUILDER_SECTION {
59
+ ident: number;
60
+ size: number;
61
+ keyCount: number;
62
+ flicksCount: number;
63
+ flickCount: number;
64
+ kmapCount: number;
65
+ keys: BUILDER_KEYS_KEY[];
66
+ flicks: BUILDER_KEYS_FLICKS[];
67
+ flick: BUILDER_KEYS_FLICK[];
68
+ kmap: BUILDER_KEYS_KMAP[];
69
+ };
70
+
71
+ export function build_keys(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_list: BUILDER_LIST): BUILDER_KEYS {
72
+ if(kmxplus.keys.keys.length == 0 &&
73
+ (kmxplus.keys.flicks.length <= 1)) { // if no keys and only the 'null' flick.
74
+ return null;
75
+ }
76
+
77
+ let keys: BUILDER_KEYS = {
78
+ ident: constants.hex_section_id(constants.section.keys),
79
+ size: 0,
80
+ keyCount: kmxplus.keys.keys.length,
81
+ flicksCount: kmxplus.keys.flicks.length,
82
+ flickCount: 0,
83
+ kmapCount: kmxplus.keys.kmap.length,
84
+ keys: [],
85
+ flicks: [],
86
+ flick: [],
87
+ kmap: [],
88
+ _offset: 0,
89
+ };
90
+
91
+ // flicks first: the keys will need to index into the flicks table.
92
+
93
+ // Note that per the Keys class and spec, there is always a flicks=0 meaning 'no flicks'
94
+ keys.flicks = kmxplus.keys.flicks.map((flicks) => {
95
+ let result : BUILDER_KEYS_FLICKS = {
96
+ count: flicks.flicks.length,
97
+ flick: keys.flick.length, // index of first flick
98
+ id: build_strs_index(sect_strs, flicks.id),
99
+ _id: flicks.id.value,
100
+ _flicks: flicks.flicks,
101
+ };
102
+ return result;
103
+ });
104
+ // Sort the flicks array by id
105
+ keys.flicks.sort((a, b) => StrsItem.binaryStringCompare(a._id, b._id));
106
+ // now, allocate 'flick' entries for each 'flicks'
107
+ keys.flicks.forEach((flicks) => {
108
+ flicks._flicks.forEach((flick) => {
109
+ keys.flick.push({
110
+ directions: build_list_index(sect_list, flick.directions),
111
+ flags: flick.flags,
112
+ to: build_strs_index(sect_strs, flick.to),
113
+ });
114
+ keys.flickCount++;
115
+ });
116
+ });
117
+
118
+ // now, keys
119
+ keys.keys = kmxplus.keys.keys.map((key) => {
120
+ let result : BUILDER_KEYS_KEY = {
121
+ to: build_strs_index(sect_strs, key.to),
122
+ flags: key.flags,
123
+ id: build_strs_index(sect_strs, key.id),
124
+ _id: key.id.value,
125
+ switch: build_strs_index(sect_strs, key.switch),
126
+ width: key.width,
127
+ longPress: build_list_index(sect_list, key.longPress),
128
+ longPressDefault: build_strs_index(sect_strs, key.longPressDefault),
129
+ multiTap: build_list_index(sect_list, key.multiTap),
130
+ flicks: keys.flicks.findIndex(v => v._id === (key.flicks || '')), // flicks id='' is the 'null' flicks
131
+ };
132
+ // Make sure the flicks were found
133
+ if (result.flicks === -1) {
134
+ throw new Error(`Keys: Could not find flicks id=${key.flicks} for key=${key.id.value}`);
135
+ }
136
+ return result;
137
+ });
138
+ // sort the keys by id
139
+ keys.keys.sort((a, b) => StrsItem.binaryStringCompare(a._id, b._id));
140
+
141
+ // finally, kmap
142
+ keys.kmap = kmxplus.keys.kmap.map(({vkey, mod, key}) => {
143
+ let result : BUILDER_KEYS_KMAP = {
144
+ vkey,
145
+ mod,
146
+ key: keys.keys.findIndex(k => k._id === key),
147
+ };
148
+ // Make sure the key was found
149
+ if (result.key === -1) {
150
+ throw new Error(`Keys: Could not find keys.key id=${result.key} for keys.kmap.key=${key}`);
151
+ }
152
+ return result;
153
+ });
154
+
155
+ // Sort kmap by vkey, mod order, per C7043
156
+ keys.kmap.sort((a,b) => {
157
+ let rc = 0;
158
+ if (rc === 0) {
159
+ rc = (a.vkey - b.vkey);
160
+ }
161
+ if (rc === 0) {
162
+ rc = (a.mod - b.mod);
163
+ }
164
+ return rc;
165
+ });
166
+
167
+ let offset = constants.length_keys +
168
+ (constants.length_keys_key * keys.keyCount) +
169
+ (constants.length_keys_flick_element * keys.flickCount) +
170
+ (constants.length_keys_flick_list * keys.flicksCount) +
171
+ (constants.length_keys_kmap * keys.kmapCount);
172
+ keys.size = offset;
173
+
174
+ return keys;
175
+ }
@@ -0,0 +1,154 @@
1
+
2
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
3
+ import { KMXPlusData, LayrEntry, LayrRow, StrsItem } from "../kmx-plus.js";
4
+ import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
5
+ import { BUILDER_LIST } from "./build-list.js";
6
+ import { BUILDER_SECTION } from "./builder-section.js";
7
+
8
+ /* ------------------------------------------------------------------
9
+ * layr section -
10
+ ------------------------------------------------------------------ */
11
+
12
+ /**
13
+ * List of layers, the <layers> element
14
+ */
15
+ interface BUILDER_LAYR_LIST {
16
+ hardware: number; // hardware indicator
17
+ layer: number; // index of first layer in the list, in the
18
+ count: number; // number of layer entries in the list
19
+ minDeviceWidth: number; // width in millimeters
20
+ _layers: LayrEntry[]; // original layer entry, for in-memory only
21
+ };
22
+
23
+ /**
24
+ * <layer> element
25
+ */
26
+ interface BUILDER_LAYR_LAYER {
27
+ id: number; // str of layer id
28
+ _id: string; // original layer id, for sorting
29
+ mod: number; // bitfield with modifier info
30
+ row: number; // row index into row subtable
31
+ _rows: LayrRow[]; // original rows, for in-memory only
32
+ count: number; // number of row entries
33
+ };
34
+
35
+ /**
36
+ * <row> element
37
+ */
38
+ interface BUILDER_LAYR_ROW {
39
+ key: number; // index into key subtable
40
+ count: number; // number of keys
41
+ };
42
+
43
+ /**
44
+ * portion of keys attribute of <row>
45
+ */
46
+ interface BUILDER_LAYR_KEY {
47
+ key: number;
48
+ };
49
+
50
+ /**
51
+ * Builder for the 'keys' section
52
+ */
53
+ export interface BUILDER_LAYR extends BUILDER_SECTION {
54
+ listCount: number, // number of entries in lists subtable
55
+ layerCount: number, // number of entries in layers subtable
56
+ rowCount: number, // number of entries in rows subtable
57
+ keyCount: number, // number of entries in keys subtable
58
+ lists: BUILDER_LAYR_LIST[], // subtable of <layers> elements
59
+ layers: BUILDER_LAYR_LAYER[], // subtable of <layer> elements
60
+ rows: BUILDER_LAYR_ROW[], // subtable of <row> elements
61
+ keys: BUILDER_LAYR_KEY[], // subtable of key entries
62
+ };
63
+
64
+ export function build_layr(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_list: BUILDER_LIST): BUILDER_LAYR {
65
+ if (!kmxplus.layr?.lists) {
66
+ return null; // if there aren't any layers at all (which should be an invalid keyboard)
67
+ }
68
+
69
+ let layr: BUILDER_LAYR = {
70
+ ident: constants.hex_section_id(constants.section.layr),
71
+ size: constants.length_layr,
72
+ _offset: 0,
73
+ listCount: kmxplus.layr.lists.length,
74
+ layerCount: 0, // calculated below
75
+ rowCount: 0, // calculated below
76
+ keyCount: 0, // calculated below
77
+ lists: [],
78
+ layers: [],
79
+ rows: [],
80
+ keys: []
81
+ };
82
+
83
+ layr.lists = kmxplus.layr.lists.map((list) => {
84
+ const blist: BUILDER_LAYR_LIST = {
85
+ hardware: list.hardware,
86
+ layer: null, // to be set below
87
+ _layers: list.layers,
88
+ count: list.layers.length,
89
+ minDeviceWidth: list.minDeviceWidth,
90
+ };
91
+ return blist;
92
+ });
93
+ // now sort the lists
94
+ layr.lists.sort((a, b) => {
95
+ if (a.hardware < b.hardware) {
96
+ return -1;
97
+ } else if (a.hardware > b.hardware) {
98
+ return 1;
99
+ }
100
+ if (a.minDeviceWidth < b.minDeviceWidth) {
101
+ return -1;
102
+ } else if (a.minDeviceWidth > b.minDeviceWidth) {
103
+ return 1;
104
+ } else {
105
+ return 0; // same
106
+ }
107
+ });
108
+ // Now allocate the layers, rows, and keys
109
+ layr.lists.forEach((list) => {
110
+ list.layer = layr.layers.length; // index to first layer in list
111
+ const blayers = list._layers.map((layer) => {
112
+ const blayer: BUILDER_LAYR_LAYER = {
113
+ _id: layer.id.value, // original id
114
+ id: build_strs_index(sect_strs, layer.id),
115
+ mod: layer.mod,
116
+ row: null, // row ID, to be filled in
117
+ _rows: layer.rows, // temporary
118
+ count: layer.rows.length, // number of rows
119
+ };
120
+ return blayer;
121
+ });
122
+ // sort the new layers
123
+ blayers.sort((a, b) => StrsItem.binaryStringCompare(a._id, b._id));
124
+ blayers.forEach((layer) => {
125
+ layer.row = layr.rows.length; // index to first row in list
126
+ layer._rows.forEach((row) => {
127
+ const brow: BUILDER_LAYR_ROW = {
128
+ key: layr.keys.length,
129
+ count: row.keys.length,
130
+ };
131
+ row.keys.forEach((key) => {
132
+ const bkey: BUILDER_LAYR_KEY = {
133
+ key: build_strs_index(sect_strs, key),
134
+ };
135
+ layr.keys.push(bkey);
136
+ });
137
+ layr.rows.push(brow);
138
+ });
139
+ layr.layers.push(layer);
140
+ });
141
+ });
142
+
143
+ layr.layerCount = layr.layers.length;
144
+ layr.rowCount = layr.rows.length;
145
+ layr.keyCount = layr.keys.length;
146
+
147
+ let offset = constants.length_layr +
148
+ (constants.length_layr_list * layr.listCount) +
149
+ (constants.length_layr_entry * layr.layerCount) +
150
+ (constants.length_layr_row * layr.rowCount) +
151
+ (constants.length_layr_key * layr.keyCount);
152
+ layr.size = offset;
153
+ return layr;
154
+ }
@@ -0,0 +1,95 @@
1
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
2
+ import { List, ListItem } from "../kmx-plus.js";
3
+ import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
4
+ import { BUILDER_SECTION } from "./builder-section.js";
5
+
6
+ /* ------------------------------------------------------------------
7
+ * list section
8
+ ------------------------------------------------------------------ */
9
+
10
+ /**
11
+ * A list entry.
12
+ */
13
+ interface BUILDER_LIST_LIST {
14
+ index: number; // index into indices[] subtable
15
+ count: number; // number of strings in this list
16
+ _value: ListItem; // for locating the list during finalization
17
+ };
18
+
19
+ interface BUILDER_LIST_INDEX {
20
+ str: number; // str for this string
21
+ _value: string; // for locating this string during finalization
22
+ };
23
+
24
+ /**
25
+ * Builder for the 'list' section
26
+ */
27
+ export interface BUILDER_LIST extends BUILDER_SECTION {
28
+ listCount: number; // Number of lists total in the subtable
29
+ indexCount: number; // Total number of indices in the subtable
30
+ lists: BUILDER_LIST_LIST[];
31
+ indices: BUILDER_LIST_INDEX[];
32
+ };
33
+
34
+ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_LIST {
35
+ if(!source_list?.lists?.length) {
36
+ // there's always the null list
37
+ return null;
38
+ }
39
+
40
+ let result: BUILDER_LIST = {
41
+ ident: constants.hex_section_id(constants.section.list),
42
+ size: 0,
43
+ _offset: 0,
44
+ listCount: source_list.lists.length,
45
+ indexCount: 0,
46
+ lists: [],
47
+ indices: [],
48
+ };
49
+
50
+ result.lists = source_list.lists.map(array => {
51
+ let list : BUILDER_LIST_LIST = {
52
+ index: result.indices.length, // the next indexcount
53
+ count: array.length,
54
+ _value: array
55
+ };
56
+ array.forEach((i) => {
57
+ let index : BUILDER_LIST_INDEX = {
58
+ // Get the final string index
59
+ str: build_strs_index(sect_strs, i.value),
60
+ _value: i.value.value, // unwrap the actual string value
61
+ };
62
+ result.indices.push(index); // increment the indexCount
63
+ result.indexCount++;
64
+ });
65
+ return list;
66
+ });
67
+
68
+ // Sort the lists.
69
+ result.lists.sort((a,b) => a._value.compareTo(b._value));
70
+
71
+ let offset = constants.length_list +
72
+ (constants.length_list_item * result.listCount) +
73
+ (constants.length_list_index * result.indexCount);
74
+ result.size = offset;
75
+
76
+ return result;
77
+ }
78
+
79
+ /**
80
+ * Returns the index into the list, analagous to build_strs_index
81
+ * @param sect_strs
82
+ * @param value
83
+ * @returns
84
+ */
85
+ export function build_list_index(sect_list: BUILDER_LIST, value: ListItem) {
86
+ if(!(value instanceof ListItem)) {
87
+ throw new Error('unexpected value '+ value);
88
+ }
89
+
90
+ let result = sect_list.lists.findIndex(v => v._value === value);
91
+ if(result < 0) {
92
+ throw new Error('unexpectedly missing ListItem ' + value); // TODO-LDML: it's an array of strs
93
+ }
94
+ return result;
95
+ }
@@ -0,0 +1,34 @@
1
+
2
+ /* ------------------------------------------------------------------
3
+ * loca section
4
+ ------------------------------------------------------------------ */
5
+
6
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
7
+ import { KMXPlusData } from "../kmx-plus.js";
8
+ import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
9
+ import { BUILDER_SECTION } from "./builder-section.js";
10
+
11
+ /**
12
+ * Builder for the 'loca' section
13
+ */
14
+ export interface BUILDER_LOCA extends BUILDER_SECTION {
15
+ count: number;
16
+ items: number[]; //str[]
17
+ };
18
+
19
+ export function build_loca(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_LOCA {
20
+ let loca: BUILDER_LOCA = {
21
+ ident: constants.hex_section_id(constants.section.loca),
22
+ size: constants.length_loca + constants.length_loca_item * kmxplus.loca.locales.length,
23
+ _offset: 0,
24
+ count: kmxplus.loca.locales.length,
25
+ items: []
26
+ };
27
+
28
+ for(let item of kmxplus.loca.locales) {
29
+ loca.items.push(build_strs_index(sect_strs, item));
30
+ }
31
+
32
+ return loca;
33
+ }
34
+
@@ -0,0 +1,37 @@
1
+
2
+ /* ------------------------------------------------------------------
3
+ * meta section
4
+ ------------------------------------------------------------------ */
5
+
6
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
7
+ import { KMXPlusData } from "../kmx-plus.js";
8
+ import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
9
+ import { BUILDER_SECTION } from "./builder-section.js";
10
+
11
+ /**
12
+ * Builder for the 'meta' section
13
+ */
14
+ export interface BUILDER_META extends BUILDER_SECTION {
15
+ author: number; //str
16
+ conform: number; //str
17
+ layout: number; //str
18
+ normalization: number; //str
19
+ indicator: number; //str
20
+ version: number; //str
21
+ settings: number; //bitfield
22
+ };
23
+
24
+ export function build_meta(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_META {
25
+ return {
26
+ ident: constants.hex_section_id(constants.section.meta),
27
+ size: constants.length_meta,
28
+ _offset: 0,
29
+ author: build_strs_index(sect_strs, kmxplus.meta.author),
30
+ conform: build_strs_index(sect_strs, kmxplus.meta.conform),
31
+ layout: build_strs_index(sect_strs, kmxplus.meta.layout),
32
+ normalization: build_strs_index(sect_strs, kmxplus.meta.normalization),
33
+ indicator: build_strs_index(sect_strs, kmxplus.meta.indicator),
34
+ version: build_strs_index(sect_strs, kmxplus.meta.version),
35
+ settings: kmxplus.meta.settings ?? 0,
36
+ };
37
+ }
@@ -0,0 +1,37 @@
1
+
2
+ /* ------------------------------------------------------------------
3
+ * name section
4
+ ------------------------------------------------------------------ */
5
+
6
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
7
+ import { KMXPlusData } from "../kmx-plus.js";
8
+ import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
9
+ import { BUILDER_SECTION } from "./builder-section.js";
10
+
11
+ /**
12
+ * Builder for the 'name' section
13
+ */
14
+ export interface BUILDER_NAME extends BUILDER_SECTION {
15
+ count: number;
16
+ items: number[]; //str[]
17
+ };
18
+
19
+ export function build_name(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_NAME {
20
+ if(!kmxplus.name.names.length) {
21
+ return null;
22
+ }
23
+
24
+ let name: BUILDER_NAME = {
25
+ ident: constants.hex_section_id(constants.section.name),
26
+ size: constants.length_name + constants.length_name_item * kmxplus.name.names.length,
27
+ _offset: 0,
28
+ count: kmxplus.name.names.length,
29
+ items: []
30
+ };
31
+
32
+ for(let item of kmxplus.name.names) {
33
+ name.items.push(build_strs_index(sect_strs, item));
34
+ }
35
+
36
+ return name;
37
+ }
@@ -0,0 +1,45 @@
1
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
2
+ import { KMXPlusData } from "../kmx-plus.js";
3
+ import { build_elem_index, BUILDER_ELEM } from "./build-elem.js";
4
+ import { BUILDER_STRS } from "./build-strs.js";
5
+ import { BUILDER_SECTION } from "./builder-section.js";
6
+
7
+ /* ------------------------------------------------------------------
8
+ * ordr section
9
+ ------------------------------------------------------------------ */
10
+
11
+ interface BUILDER_ORDR_ITEM {
12
+ elements: number; //elem.string
13
+ before: number; //elem.string
14
+ };
15
+
16
+ export interface BUILDER_ORDR extends BUILDER_SECTION {
17
+ count: number;
18
+ items: BUILDER_ORDR_ITEM[];
19
+ };
20
+
21
+ /**
22
+ * Builder for the 'ordr' section
23
+ */
24
+ export function build_ordr(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_elem: BUILDER_ELEM): BUILDER_ORDR {
25
+ if(!kmxplus.ordr?.items.length) {
26
+ return null;
27
+ }
28
+
29
+ let ordr: BUILDER_ORDR = {
30
+ ident: constants.hex_section_id(constants.section.ordr),
31
+ size: constants.length_ordr + constants.length_ordr_item * kmxplus.ordr.items.length,
32
+ _offset: 0,
33
+ count: kmxplus.ordr.items.length,
34
+ items: []
35
+ };
36
+
37
+ for(let item of kmxplus.ordr.items) {
38
+ ordr.items.push({
39
+ elements: build_elem_index(sect_elem, item.elements),
40
+ before: build_elem_index(sect_elem, item.before)
41
+ });
42
+ }
43
+
44
+ return ordr;
45
+ }
@@ -0,0 +1,31 @@
1
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
2
+ import { BUILDER_SECTION } from "./builder-section.js";
3
+
4
+ /* ------------------------------------------------------------------
5
+ * sect section
6
+ ------------------------------------------------------------------ */
7
+
8
+ interface BUILDER_SECT_ITEM {
9
+ sect: number;
10
+ offset: number; //? new r.VoidPointer(r.uint32le, {type: 'global'})
11
+ };
12
+
13
+ /**
14
+ * Builder for the 'sect' (Section table of contents) section
15
+ */
16
+ export interface BUILDER_SECT extends BUILDER_SECTION {
17
+ total: number;
18
+ count: number;
19
+ items: BUILDER_SECT_ITEM[];
20
+ };
21
+
22
+ export function build_sect(): BUILDER_SECT {
23
+ return {
24
+ ident: constants.hex_section_id(constants.section.sect),
25
+ size: 0, // finalized later
26
+ _offset: 0,
27
+ total: 0, // finalized later
28
+ count: 0, // finalized later
29
+ items: [], // finalized later
30
+ };
31
+ }
@@ -0,0 +1,58 @@
1
+ import { constants } from "@keymanapp/ldml-keyboard-constants";
2
+ import { Strs, StrsItem } from "../kmx-plus.js";
3
+ import { BUILDER_SECTION } from "./builder-section.js";
4
+
5
+ /* ------------------------------------------------------------------
6
+ * strs section
7
+ ------------------------------------------------------------------ */
8
+
9
+ interface BUILDER_STRS_ITEM {
10
+ // While we use length which is number of utf-16 code units excluding null terminator,
11
+ // we always write a null terminator, so we can get restructure to do that for us here
12
+ offset: number; //? new r.Pointer(r.uint32le, new r.String(null, 'utf16le')),
13
+ length: number; // in UTF-16 code units
14
+ _value: string
15
+ };
16
+
17
+ /**
18
+ * Builder for the 'strs' section
19
+ */
20
+ export interface BUILDER_STRS extends BUILDER_SECTION {
21
+ count: number;
22
+ items: BUILDER_STRS_ITEM[];
23
+ };
24
+
25
+ export function build_strs(source_strs: Strs): BUILDER_STRS {
26
+ let result: BUILDER_STRS = {
27
+ ident: constants.hex_section_id(constants.section.strs),
28
+ size: 0, // finalized later
29
+ _offset: 0,
30
+ count: source_strs.strings.length,
31
+ items: [], // filled below
32
+ };
33
+
34
+ result.items = source_strs.strings.map(item => { return {_value: item.value, length: item.value.length, offset: 0}; });
35
+ result.items.sort((a,b) => StrsItem.binaryStringCompare(a._value, b._value));
36
+
37
+ let offset = constants.length_strs + constants.length_strs_item * result.count;
38
+ // TODO: consider padding
39
+ for(let item of result.items) {
40
+ item.offset = offset;
41
+ offset += item.length * 2 + 2; /* UTF-16 code units + sizeof null terminator */
42
+ }
43
+ result.size = offset;
44
+
45
+ return result;
46
+ }
47
+
48
+ export function build_strs_index(sect_strs: BUILDER_STRS, value: StrsItem) {
49
+ if(!(value instanceof StrsItem)) {
50
+ throw new Error('unexpected value '+ value);
51
+ }
52
+
53
+ let result = sect_strs.items.findIndex(v => v._value === value.value);
54
+ if(result < 0) {
55
+ throw new Error('unexpectedly missing StrsItem '+value.value);
56
+ }
57
+ return result;
58
+ }