@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.
- package/build/src/consts/virtual-key-constants.d.ts +131 -0
- package/build/src/consts/virtual-key-constants.d.ts.map +1 -0
- package/build/src/consts/virtual-key-constants.js +245 -0
- package/build/src/consts/virtual-key-constants.js.map +1 -0
- package/build/src/import/techpreview/cldr_info.json +5 -0
- package/build/src/import/techpreview/keys-Latn-implied.xml +80 -0
- package/build/src/import/techpreview/keys-Zyyy-currency.xml +22 -0
- package/build/src/import/techpreview/keys-Zyyy-punctuation.xml +46 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts +7 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts.map +1 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js +74 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js.map +1 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts +24 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts.map +1 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js +75 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js.map +1 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts +76 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts.map +1 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file.js +26 -0
- package/build/src/keyman-touch-layout/keyman-touch-layout-file.js.map +1 -0
- package/build/src/keyman-touch-layout.clean.spec.json +170 -0
- package/build/src/kmx/element-string.d.ts +19 -0
- package/build/src/kmx/element-string.d.ts.map +1 -0
- package/build/src/kmx/element-string.js +72 -0
- package/build/src/kmx/element-string.js.map +1 -0
- package/build/src/kmx/kmx-builder.d.ts +77 -0
- package/build/src/kmx/kmx-builder.d.ts.map +1 -0
- package/build/src/kmx/kmx-builder.js +193 -0
- package/build/src/kmx/kmx-builder.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-disp.d.ts +18 -0
- package/build/src/kmx/kmx-plus-builder/build-disp.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-disp.js +25 -0
- package/build/src/kmx/kmx-plus-builder/build-disp.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-elem.d.ts +26 -0
- package/build/src/kmx/kmx-plus-builder/build-elem.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-elem.js +78 -0
- package/build/src/kmx/kmx-plus-builder/build-elem.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-keys.d.ts +60 -0
- package/build/src/kmx/kmx-plus-builder/build-keys.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-keys.js +107 -0
- package/build/src/kmx/kmx-plus-builder/build-keys.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-layr.d.ts +54 -0
- package/build/src/kmx/kmx-plus-builder/build-layr.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-layr.js +99 -0
- package/build/src/kmx/kmx-plus-builder/build-layr.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-list.d.ts +34 -0
- package/build/src/kmx/kmx-plus-builder/build-list.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-list.js +62 -0
- package/build/src/kmx/kmx-plus-builder/build-list.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-loca.d.ts +12 -0
- package/build/src/kmx/kmx-plus-builder/build-loca.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-loca.js +20 -0
- package/build/src/kmx/kmx-plus-builder/build-loca.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-meta.d.ts +17 -0
- package/build/src/kmx/kmx-plus-builder/build-meta.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-meta.js +21 -0
- package/build/src/kmx/kmx-plus-builder/build-meta.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-name.d.ts +12 -0
- package/build/src/kmx/kmx-plus-builder/build-name.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-name.js +23 -0
- package/build/src/kmx/kmx-plus-builder/build-name.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-ordr.d.ts +18 -0
- package/build/src/kmx/kmx-plus-builder/build-ordr.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-ordr.js +27 -0
- package/build/src/kmx/kmx-plus-builder/build-ordr.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-sect.d.ts +16 -0
- package/build/src/kmx/kmx-plus-builder/build-sect.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-sect.js +14 -0
- package/build/src/kmx/kmx-plus-builder/build-sect.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-strs.d.ts +18 -0
- package/build/src/kmx/kmx-plus-builder/build-strs.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-strs.js +34 -0
- package/build/src/kmx/kmx-plus-builder/build-strs.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-tran.d.ts +20 -0
- package/build/src/kmx/kmx-plus-builder/build-tran.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-tran.js +30 -0
- package/build/src/kmx/kmx-plus-builder/build-tran.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-vkey.d.ts +16 -0
- package/build/src/kmx/kmx-plus-builder/build-vkey.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/build-vkey.js +23 -0
- package/build/src/kmx/kmx-plus-builder/build-vkey.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/builder-section.d.ts +6 -0
- package/build/src/kmx/kmx-plus-builder/builder-section.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/builder-section.js +3 -0
- package/build/src/kmx/kmx-plus-builder/builder-section.js.map +1 -0
- package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts +47 -0
- package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js +143 -0
- package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js.map +1 -0
- package/build/src/kmx/kmx-plus.d.ts +259 -0
- package/build/src/kmx/kmx-plus.d.ts.map +1 -0
- package/build/src/kmx/kmx-plus.js +594 -0
- package/build/src/kmx/kmx-plus.js.map +1 -0
- package/build/src/kmx/kmx.d.ts +166 -0
- package/build/src/kmx/kmx.d.ts.map +1 -0
- package/build/src/kmx/kmx.js +271 -0
- package/build/src/kmx/kmx.js.map +1 -0
- package/build/src/kmx/string-list.d.ts +29 -0
- package/build/src/kmx/string-list.d.ts.map +1 -0
- package/build/src/kmx/string-list.js +75 -0
- package/build/src/kmx/string-list.js.map +1 -0
- package/build/src/kpj/keyman-developer-project.d.ts +58 -0
- package/build/src/kpj/keyman-developer-project.d.ts.map +1 -0
- package/build/src/kpj/keyman-developer-project.js +141 -0
- package/build/src/kpj/keyman-developer-project.js.map +1 -0
- package/build/src/kpj/kpj-file-reader.d.ts +17 -0
- package/build/src/kpj/kpj-file-reader.d.ts.map +1 -0
- package/build/src/kpj/kpj-file-reader.js +92 -0
- package/build/src/kpj/kpj-file-reader.js.map +1 -0
- package/build/src/kpj/kpj-file.d.ts +39 -0
- package/build/src/kpj/kpj-file.d.ts.map +1 -0
- package/build/src/kpj/kpj-file.js +11 -0
- package/build/src/kpj/kpj-file.js.map +1 -0
- package/build/src/kpj.schema.json +127 -0
- package/build/src/kvk/kvk-file-reader.d.ts +5 -0
- package/build/src/kvk/kvk-file-reader.d.ts.map +1 -0
- package/build/src/kvk/kvk-file-reader.js +35 -0
- package/build/src/kvk/kvk-file-reader.js.map +1 -0
- package/build/src/kvk/kvk-file-writer.d.ts +20 -0
- package/build/src/kvk/kvk-file-writer.d.ts.map +1 -0
- package/build/src/kvk/kvk-file-writer.js +67 -0
- package/build/src/kvk/kvk-file-writer.js.map +1 -0
- package/build/src/kvk/kvk-file.d.ts +64 -0
- package/build/src/kvk/kvk-file.d.ts.map +1 -0
- package/build/src/kvk/kvk-file.js +63 -0
- package/build/src/kvk/kvk-file.js.map +1 -0
- package/build/src/kvk/kvks-file-reader.d.ts +30 -0
- package/build/src/kvk/kvks-file-reader.d.ts.map +1 -0
- package/build/src/kvk/kvks-file-reader.js +154 -0
- package/build/src/kvk/kvks-file-reader.js.map +1 -0
- package/build/src/kvk/kvks-file-writer.d.ts +6 -0
- package/build/src/kvk/kvks-file-writer.d.ts.map +1 -0
- package/build/src/kvk/kvks-file-writer.js +99 -0
- package/build/src/kvk/kvks-file-writer.js.map +1 -0
- package/build/src/kvk/kvks-file.d.ts +44 -0
- package/build/src/kvk/kvks-file.d.ts.map +1 -0
- package/build/src/kvk/kvks-file.js +10 -0
- package/build/src/kvk/kvks-file.js.map +1 -0
- package/build/src/kvk/visual-keyboard.d.ts +35 -0
- package/build/src/kvk/visual-keyboard.d.ts.map +1 -0
- package/build/src/kvk/visual-keyboard.js +61 -0
- package/build/src/kvk/visual-keyboard.js.map +1 -0
- package/build/src/kvks.schema.json +182 -0
- package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts +56 -0
- package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts.map +1 -0
- package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js +20 -0
- package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js.map +1 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts +91 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts.map +1 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js +370 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js.map +1 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts +143 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts.map +1 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml.js +34 -0
- package/build/src/ldml-keyboard/ldml-keyboard-xml.js.map +1 -0
- package/build/src/ldml-keyboard.schema.json +634 -0
- package/build/src/ldml-keyboardtest.schema.json +221 -0
- package/build/src/main.d.ts +21 -0
- package/build/src/main.d.ts.map +1 -0
- package/build/src/main.js +20 -0
- package/build/src/main.js.map +1 -0
- package/build/src/util/common-events.d.ts +49 -0
- package/build/src/util/common-events.d.ts.map +1 -0
- package/build/src/util/common-events.js +29 -0
- package/build/src/util/common-events.js.map +1 -0
- package/build/src/util/compiler-interfaces.d.ts +51 -0
- package/build/src/util/compiler-interfaces.d.ts.map +1 -0
- package/build/src/util/compiler-interfaces.js +33 -0
- package/build/src/util/compiler-interfaces.js.map +1 -0
- package/build/src/util/util.d.ts +17 -0
- package/build/src/util/util.d.ts.map +1 -0
- package/build/src/util/util.js +67 -0
- package/build/src/util/util.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build.sh +86 -0
- package/package.json +58 -0
- package/src/consts/virtual-key-constants.ts +257 -0
- package/src/keyman-touch-layout/keyman-touch-layout-file-reader.ts +81 -0
- package/src/keyman-touch-layout/keyman-touch-layout-file-writer.ts +84 -0
- package/src/keyman-touch-layout/keyman-touch-layout-file.ts +87 -0
- package/src/kmx/element-string.ts +79 -0
- package/src/kmx/kmx-builder.ts +287 -0
- package/src/kmx/kmx-plus-builder/build-disp.ts +46 -0
- package/src/kmx/kmx-plus-builder/build-elem.ts +103 -0
- package/src/kmx/kmx-plus-builder/build-keys.ts +175 -0
- package/src/kmx/kmx-plus-builder/build-layr.ts +154 -0
- package/src/kmx/kmx-plus-builder/build-list.ts +95 -0
- package/src/kmx/kmx-plus-builder/build-loca.ts +34 -0
- package/src/kmx/kmx-plus-builder/build-meta.ts +37 -0
- package/src/kmx/kmx-plus-builder/build-name.ts +37 -0
- package/src/kmx/kmx-plus-builder/build-ordr.ts +45 -0
- package/src/kmx/kmx-plus-builder/build-sect.ts +31 -0
- package/src/kmx/kmx-plus-builder/build-strs.ts +58 -0
- package/src/kmx/kmx-plus-builder/build-tran.ts +50 -0
- package/src/kmx/kmx-plus-builder/build-vkey.ts +43 -0
- package/src/kmx/kmx-plus-builder/builder-section.ts +6 -0
- package/src/kmx/kmx-plus-builder/kmx-plus-builder.ts +190 -0
- package/src/kmx/kmx-plus.ts +692 -0
- package/src/kmx/kmx.ts +360 -0
- package/src/kmx/string-list.ts +74 -0
- package/src/kpj/keyman-developer-project.ts +155 -0
- package/src/kpj/kpj-file-reader.ts +103 -0
- package/src/kpj/kpj-file.ts +52 -0
- package/src/kvk/kvk-file-reader.ts +34 -0
- package/src/kvk/kvk-file-writer.ts +72 -0
- package/src/kvk/kvk-file.ts +122 -0
- package/src/kvk/kvks-file-reader.ts +164 -0
- package/src/kvk/kvks-file-writer.ts +113 -0
- package/src/kvk/kvks-file.ts +53 -0
- package/src/kvk/visual-keyboard.ts +80 -0
- package/src/ldml-keyboard/ldml-keyboard-testdata-xml.ts +74 -0
- package/src/ldml-keyboard/ldml-keyboard-xml-reader.ts +387 -0
- package/src/ldml-keyboard/ldml-keyboard-xml.ts +177 -0
- package/src/main.ts +27 -0
- package/src/restructure.d.ts +2 -0
- package/src/util/common-events.ts +50 -0
- package/src/util/compiler-interfaces.ts +54 -0
- package/src/util/util.ts +68 -0
- package/test/fixtures/import-minimal.xml +8 -0
- package/test/fixtures/import-minimal1.xml +11 -0
- package/test/fixtures/import-minimal2.xml +11 -0
- package/test/fixtures/import-symbols.xml +13 -0
- package/test/fixtures/invalid-conforms-to.xml +19 -0
- package/test/fixtures/invalid-import-base.xml +16 -0
- package/test/fixtures/invalid-import-path.xml +16 -0
- package/test/fixtures/invalid-import-readfail.xml +16 -0
- package/test/fixtures/invalid-import-wrongroot.xml +16 -0
- package/test/fixtures/invalid-structure-per-dtd.xml +8 -0
- package/test/fixtures/keyman-touch-layout/khmer_angkor.keyman-touch-layout +1950 -0
- package/test/fixtures/keyman-touch-layout/legacy.keyman-touch-layout +36 -0
- package/test/fixtures/kpj/khmer_angkor.kpj +187 -0
- package/test/fixtures/kvk/khmer_angkor.kvk +0 -0
- package/test/fixtures/kvk/khmer_angkor.kvks +206 -0
- package/test/fixtures/test-fr.xml +22 -0
- package/test/helpers/index.ts +39 -0
- package/test/helpers/reader-callback-test.ts +199 -0
- package/test/keyman-touch-layout/test-keyman-touch-layout-file-reader.ts +71 -0
- package/test/keyman-touch-layout/test-keyman-touch-layout-round-trip.ts +35 -0
- package/test/kpj/test-kpj-file-reader.ts +123 -0
- package/test/kvk/test-kvk-file.ts +15 -0
- package/test/kvk/test-kvk-round-trip.ts +87 -0
- package/test/kvk/test-kvk-utils.ts +24 -0
- package/test/kvk/test-kvks-file.ts +45 -0
- package/test/ldml-keyboard/test-ldml-keyboard-testdata-reader.ts +51 -0
- package/test/ldml-keyboard/test-ldml-keyboard-xml-reader.ts +131 -0
- package/test/tsconfig.json +21 -0
- package/test/util/test-unescape.ts +38 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
|
3
|
+
import { Bksp, Finl, Tran } from "../kmx-plus.js";
|
|
4
|
+
import { build_elem_index, BUILDER_ELEM } from "./build-elem.js";
|
|
5
|
+
import { build_strs_index, BUILDER_STRS } from "./build-strs.js";
|
|
6
|
+
import { BUILDER_SECTION } from "./builder-section.js";
|
|
7
|
+
|
|
8
|
+
/* ------------------------------------------------------------------
|
|
9
|
+
* tran section
|
|
10
|
+
------------------------------------------------------------------ */
|
|
11
|
+
|
|
12
|
+
interface BUILDER_TRAN_ITEM {
|
|
13
|
+
from: number; //elem.string
|
|
14
|
+
to: number; //str
|
|
15
|
+
before: number; //elem.string
|
|
16
|
+
flags: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface BUILDER_TRAN extends BUILDER_SECTION {
|
|
20
|
+
count: number;
|
|
21
|
+
items: BUILDER_TRAN_ITEM[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Builder for the 'tran', 'finl', and 'bksp' sections, all of which use the BUILDER_TRAN layout
|
|
26
|
+
*/
|
|
27
|
+
export function build_tran(source_tran: Tran|Finl|Bksp, sect_strs: BUILDER_STRS, sect_elem: BUILDER_ELEM): BUILDER_TRAN {
|
|
28
|
+
if(!source_tran?.items.length) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let tran: BUILDER_TRAN = {
|
|
33
|
+
ident: constants.hex_section_id(source_tran.id),
|
|
34
|
+
size: constants.length_tran + constants.length_tran_item * source_tran.items.length,
|
|
35
|
+
_offset: 0,
|
|
36
|
+
count: source_tran.items.length,
|
|
37
|
+
items: []
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
for(let item of source_tran.items) {
|
|
41
|
+
tran.items.push({
|
|
42
|
+
from: build_elem_index(sect_elem, item.from),
|
|
43
|
+
to: build_strs_index(sect_strs, item.to),
|
|
44
|
+
before: build_elem_index(sect_elem, item.before),
|
|
45
|
+
flags: item.flags
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return tran;
|
|
50
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { constants } from '@keymanapp/ldml-keyboard-constants';
|
|
2
|
+
import { KMXPlusData } from "../kmx-plus.js";
|
|
3
|
+
import { BUILDER_SECTION } from './builder-section.js';
|
|
4
|
+
|
|
5
|
+
/* ------------------------------------------------------------------
|
|
6
|
+
* vkey section
|
|
7
|
+
------------------------------------------------------------------ */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Builder for the 'vkey' section
|
|
11
|
+
*/
|
|
12
|
+
interface BUILDER_VKEY_ITEM {
|
|
13
|
+
vkey: number;
|
|
14
|
+
target: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export interface BUILDER_VKEY extends BUILDER_SECTION {
|
|
18
|
+
count: number;
|
|
19
|
+
items: BUILDER_VKEY_ITEM[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function build_vkey(kmxplus: KMXPlusData): BUILDER_VKEY {
|
|
23
|
+
if(!kmxplus.vkey.vkeys.length) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let vkey: BUILDER_VKEY = {
|
|
28
|
+
ident: constants.hex_section_id(constants.section.vkey),
|
|
29
|
+
size: constants.length_vkey + constants.length_vkey_item * kmxplus.vkey.vkeys.length,
|
|
30
|
+
_offset: 0,
|
|
31
|
+
count: kmxplus.vkey.vkeys.length,
|
|
32
|
+
items: []
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
for(let item of kmxplus.vkey.vkeys) {
|
|
36
|
+
vkey.items.push({
|
|
37
|
+
vkey: item.vkey,
|
|
38
|
+
target: item.target
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return vkey;
|
|
43
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import * as r from 'restructure';
|
|
2
|
+
import { KMXPlusFile } from "../kmx-plus.js";
|
|
3
|
+
import { constants, SectionIdent } from '@keymanapp/ldml-keyboard-constants';
|
|
4
|
+
import { BUILDER_SECTION } from './builder-section.js';
|
|
5
|
+
import { BUILDER_SECT, build_sect } from './build-sect.js';
|
|
6
|
+
import { BUILDER_DISP, build_disp } from './build-disp.js';
|
|
7
|
+
import { BUILDER_ELEM, build_elem } from './build-elem.js';
|
|
8
|
+
import { BUILDER_KEYS, build_keys } from './build-keys.js';
|
|
9
|
+
import { BUILDER_LAYR, build_layr } from './build-layr.js';
|
|
10
|
+
import { BUILDER_LIST, build_list } from './build-list.js';
|
|
11
|
+
import { BUILDER_LOCA, build_loca } from './build-loca.js';
|
|
12
|
+
import { BUILDER_META, build_meta } from './build-meta.js';
|
|
13
|
+
import { BUILDER_NAME, build_name } from './build-name.js';
|
|
14
|
+
import { BUILDER_ORDR, build_ordr } from './build-ordr.js';
|
|
15
|
+
import { BUILDER_STRS, build_strs } from './build-strs.js';
|
|
16
|
+
import { BUILDER_TRAN, build_tran } from './build-tran.js';
|
|
17
|
+
import { BUILDER_VKEY, build_vkey } from './build-vkey.js';
|
|
18
|
+
|
|
19
|
+
type BUILDER_BKSP = BUILDER_TRAN;
|
|
20
|
+
type BUILDER_FINL = BUILDER_TRAN;
|
|
21
|
+
|
|
22
|
+
type SectionBuilders = {
|
|
23
|
+
// [id in SectionIdent]: BUILDER_SECTION;
|
|
24
|
+
sect?: BUILDER_SECT;
|
|
25
|
+
bksp?: BUILDER_BKSP;
|
|
26
|
+
disp?: BUILDER_DISP;
|
|
27
|
+
elem?: BUILDER_ELEM;
|
|
28
|
+
finl?: BUILDER_FINL;
|
|
29
|
+
keys?: BUILDER_KEYS;
|
|
30
|
+
layr?: BUILDER_LAYR;
|
|
31
|
+
list?: BUILDER_LIST;
|
|
32
|
+
loca?: BUILDER_LOCA;
|
|
33
|
+
meta?: BUILDER_META;
|
|
34
|
+
name?: BUILDER_NAME;
|
|
35
|
+
ordr?: BUILDER_ORDR;
|
|
36
|
+
strs?: BUILDER_STRS;
|
|
37
|
+
tran?: BUILDER_TRAN;
|
|
38
|
+
vkey?: BUILDER_VKEY;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default class KMXPlusBuilder {
|
|
42
|
+
private file: KMXPlusFile;
|
|
43
|
+
//private writeDebug: boolean;
|
|
44
|
+
|
|
45
|
+
sect : SectionBuilders = {
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
constructor(file: KMXPlusFile, _writeDebug: boolean) {
|
|
50
|
+
this.file = file;
|
|
51
|
+
//this.writeDebug = _writeDebug;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public compile(): Uint8Array {
|
|
55
|
+
const fileSize = this.build();
|
|
56
|
+
let file: Uint8Array = new Uint8Array(fileSize);
|
|
57
|
+
|
|
58
|
+
this.emitSection(file, this.file.COMP_PLUS_SECT, this.sect.sect);
|
|
59
|
+
// Keep the rest of these in order.
|
|
60
|
+
this.emitSection(file, this.file.COMP_PLUS_BKSP, this.sect.bksp);
|
|
61
|
+
this.emitSection(file, this.file.COMP_PLUS_DISP, this.sect.disp);
|
|
62
|
+
this.emitSection(file, this.file.COMP_PLUS_ELEM, this.sect.elem);
|
|
63
|
+
this.emitElements(file);
|
|
64
|
+
this.emitSection(file, this.file.COMP_PLUS_FINL, this.sect.finl);
|
|
65
|
+
this.emitSection(file, this.file.COMP_PLUS_KEYS, this.sect.keys);
|
|
66
|
+
this.emitSection(file, this.file.COMP_PLUS_LAYR, this.sect.layr);
|
|
67
|
+
this.emitSection(file, this.file.COMP_PLUS_LIST, this.sect.list);
|
|
68
|
+
this.emitSection(file, this.file.COMP_PLUS_LOCA, this.sect.loca);
|
|
69
|
+
this.emitSection(file, this.file.COMP_PLUS_META, this.sect.meta);
|
|
70
|
+
this.emitSection(file, this.file.COMP_PLUS_NAME, this.sect.name);
|
|
71
|
+
this.emitSection(file, this.file.COMP_PLUS_ORDR, this.sect.ordr);
|
|
72
|
+
this.emitSection(file, this.file.COMP_PLUS_STRS, this.sect.strs);
|
|
73
|
+
this.emitStrings(file);
|
|
74
|
+
this.emitSection(file, this.file.COMP_PLUS_TRAN, this.sect.tran);
|
|
75
|
+
this.emitSection(file, this.file.COMP_PLUS_VKEY, this.sect.vkey);
|
|
76
|
+
|
|
77
|
+
return file;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private build() {
|
|
81
|
+
// Required sections: sect, strs, loca, meta
|
|
82
|
+
|
|
83
|
+
// We must prepare the strs, list, and elem sections early so that other sections can
|
|
84
|
+
// reference them. However, they will be emitted in alpha order.
|
|
85
|
+
this.sect.strs = build_strs(this.file.kmxplus.strs);
|
|
86
|
+
this.sect.list = build_list(this.file.kmxplus.list, this.sect.strs);
|
|
87
|
+
this.sect.elem = build_elem(this.file.kmxplus.elem, this.sect.strs);
|
|
88
|
+
|
|
89
|
+
const build_bksp = build_tran;
|
|
90
|
+
const build_finl = build_tran;
|
|
91
|
+
|
|
92
|
+
this.sect.bksp = build_bksp(this.file.kmxplus.bksp, this.sect.strs, this.sect.elem);
|
|
93
|
+
this.sect.disp = build_disp(this.file.kmxplus, this.sect.strs);
|
|
94
|
+
this.sect.finl = build_finl(this.file.kmxplus.finl, this.sect.strs, this.sect.elem);
|
|
95
|
+
this.sect.keys = build_keys(this.file.kmxplus, this.sect.strs, this.sect.list);
|
|
96
|
+
this.sect.layr = build_layr(this.file.kmxplus, this.sect.strs, this.sect.list);
|
|
97
|
+
this.sect.loca = build_loca(this.file.kmxplus, this.sect.strs);
|
|
98
|
+
this.sect.meta = build_meta(this.file.kmxplus, this.sect.strs);
|
|
99
|
+
this.sect.name = build_name(this.file.kmxplus, this.sect.strs);
|
|
100
|
+
this.sect.ordr = build_ordr(this.file.kmxplus, this.sect.strs, this.sect.elem);
|
|
101
|
+
this.sect.tran = build_tran(this.file.kmxplus.tran, this.sect.strs, this.sect.elem);
|
|
102
|
+
this.sect.vkey = build_vkey(this.file.kmxplus);
|
|
103
|
+
|
|
104
|
+
// Finalize the sect (index) section
|
|
105
|
+
|
|
106
|
+
this.sect.sect = build_sect();
|
|
107
|
+
this.finalize_sect(); // must be done last
|
|
108
|
+
return this.sect.sect.total;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private finalize_sect() {
|
|
112
|
+
// 'sect' section
|
|
113
|
+
|
|
114
|
+
this.sect.sect.count = 0;
|
|
115
|
+
|
|
116
|
+
Object.keys(constants.section).forEach((sectstr : string) => {
|
|
117
|
+
const sect : SectionIdent = constants.section[<SectionIdent>sectstr];
|
|
118
|
+
if(this.sect[sect] && sect !== 'sect') {
|
|
119
|
+
this.sect.sect.count++;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
this.sect.sect.size = constants.length_sect + constants.length_sect_item * this.sect.sect.count;
|
|
124
|
+
|
|
125
|
+
let offset = this.sect.sect.size;
|
|
126
|
+
// Note: in order! Everyone's here except 'sect' which is at offset 0
|
|
127
|
+
offset = this.finalize_sect_item(this.sect.bksp, offset);
|
|
128
|
+
offset = this.finalize_sect_item(this.sect.disp, offset);
|
|
129
|
+
offset = this.finalize_sect_item(this.sect.elem, offset);
|
|
130
|
+
offset = this.finalize_sect_item(this.sect.finl, offset);
|
|
131
|
+
offset = this.finalize_sect_item(this.sect.keys, offset);
|
|
132
|
+
offset = this.finalize_sect_item(this.sect.layr, offset);
|
|
133
|
+
offset = this.finalize_sect_item(this.sect.list, offset);
|
|
134
|
+
offset = this.finalize_sect_item(this.sect.loca, offset);
|
|
135
|
+
offset = this.finalize_sect_item(this.sect.meta, offset);
|
|
136
|
+
offset = this.finalize_sect_item(this.sect.name, offset);
|
|
137
|
+
offset = this.finalize_sect_item(this.sect.ordr, offset);
|
|
138
|
+
offset = this.finalize_sect_item(this.sect.strs, offset);
|
|
139
|
+
offset = this.finalize_sect_item(this.sect.tran, offset);
|
|
140
|
+
offset = this.finalize_sect_item(this.sect.vkey, offset);
|
|
141
|
+
|
|
142
|
+
this.sect.sect.total = offset;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private finalize_sect_item(sect: BUILDER_SECTION, offset: number): number {
|
|
146
|
+
if(!sect) {
|
|
147
|
+
// Don't include null sections
|
|
148
|
+
return offset;
|
|
149
|
+
}
|
|
150
|
+
sect._offset = offset;
|
|
151
|
+
this.sect.sect.items.push({sect: sect.ident, offset: offset});
|
|
152
|
+
return offset + sect.size;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private emitSection(file: Uint8Array, comp: any, sect: BUILDER_SECTION) {
|
|
156
|
+
if(sect) {
|
|
157
|
+
const buf = comp.toBuffer(sect);
|
|
158
|
+
if (buf.length > sect.size) {
|
|
159
|
+
// buf.length may be < sect.size if there is a variable part (i.e. elem)
|
|
160
|
+
throw new RangeError(`Internal Error: Section ${constants.str_section_id(sect.ident)} claimed size ${sect.size} but produced buffer of size ${buf.length}.`);
|
|
161
|
+
}
|
|
162
|
+
file.set(buf, sect._offset);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private emitStrings(file: Uint8Array) {
|
|
167
|
+
for(let item of this.sect.strs.items) {
|
|
168
|
+
if(item._value === '') {
|
|
169
|
+
// We have a special case for the zero-length string
|
|
170
|
+
let sbuf = r.uint16le;
|
|
171
|
+
file.set(sbuf.toBuffer(0), item.offset + this.sect.strs._offset);
|
|
172
|
+
} else {
|
|
173
|
+
let sbuf = new r.String(null, 'utf16le');
|
|
174
|
+
file.set(sbuf.toBuffer(item._value), item.offset + this.sect.strs._offset);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private emitElements(file: Uint8Array) {
|
|
180
|
+
if(this.sect.elem) {
|
|
181
|
+
for(let str of this.sect.elem.strings) {
|
|
182
|
+
if(str.items.length > 0) {
|
|
183
|
+
let COMP_PLUS_ELEM_ELEMENTS = new r.Array(this.file.COMP_PLUS_ELEM_ELEMENT, str.items.length);
|
|
184
|
+
file.set(COMP_PLUS_ELEM_ELEMENTS.toBuffer(str.items), str.offset + this.sect.elem._offset);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
}
|