mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-16 05:39:24 +00:00
refactor(common): move LDML keyboard .xml reader/writer and kmx-plus builder to @keymanapp/developer-utils
Relates-to: #9665
This commit is contained in:
parent
bd070683f4
commit
d3d3ac1eec
61 changed files with 240 additions and 162 deletions
|
|
@ -73,34 +73,16 @@ function compile_schemas() {
|
|||
node tools/schema-bundler.js
|
||||
}
|
||||
|
||||
function copy_cldr_imports() {
|
||||
# Store CLDR imports
|
||||
# load all versions that have a cldr_info.json
|
||||
for CLDR_INFO_PATH in "$KEYMAN_ROOT/resources/standards-data/ldml-keyboards/"*/cldr_info.json
|
||||
do
|
||||
# TODO-LDML: developer/src/inst/download.in.mak needs these also...
|
||||
CLDR_PATH=$(dirname "$CLDR_INFO_PATH")
|
||||
CLDR_VER=$(basename "$CLDR_PATH")
|
||||
mkdir -p "$THIS_SCRIPT_PATH/build/src/import/$CLDR_VER"
|
||||
# TODO-LDML: When these are copied, the DOCTYPE will break due to the wrong path. We don't use the DTD so it should be OK.
|
||||
cp "$CLDR_INFO_PATH" "$CLDR_PATH/import/"*.xml "$THIS_SCRIPT_PATH/build/src/import/$CLDR_VER/"
|
||||
done
|
||||
}
|
||||
|
||||
function do_configure() {
|
||||
compile_schemas
|
||||
verify_npm_setup
|
||||
}
|
||||
|
||||
function do_build() {
|
||||
copy_cldr_imports
|
||||
tsc --build
|
||||
}
|
||||
|
||||
function do_test() {
|
||||
eslint .
|
||||
tsc --build test
|
||||
readonly C8_THRESHOLD=70
|
||||
readonly C8_THRESHOLD=40
|
||||
c8 -skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha "${builder_extra_params[@]}"
|
||||
builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal."
|
||||
builder_echo warning "Please increase threshold in build.sh as test coverage improves."
|
||||
|
|
@ -110,6 +92,6 @@ function do_test() {
|
|||
|
||||
builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
|
||||
builder_run_action configure do_configure
|
||||
builder_run_action build do_build
|
||||
builder_run_action build tsc --build
|
||||
builder_run_action test do_test
|
||||
builder_run_action publish builder_publish_npm
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { DependencySections, StrsItem, UsetItem } from './kmx-plus.js';
|
||||
import { ElementParser, ElementSegment, ElementType } from '../ldml-keyboard/pattern-parser.js';
|
||||
import { MATCH_HEX_ESCAPE } from '../util/consts.js';
|
||||
import { unescapeOneQuadString } from '../util/util.js';
|
||||
import { ElementParser, ElementSegment, ElementType } from '../../ldml-keyboard/pattern-parser.js';
|
||||
import { util } from '@keymanapp/common-types';
|
||||
import MATCH_HEX_ESCAPE = util.MATCH_HEX_ESCAPE;
|
||||
import unescapeOneQuadString = util.unescapeOneQuadString;
|
||||
|
||||
export enum ElemElementFlags {
|
||||
none = 0,
|
||||
|
|
@ -1,12 +1,18 @@
|
|||
import { constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import * as r from 'restructure';
|
||||
import { ElementString } from './element-string.js';
|
||||
import { ListItem } from './string-list.js';
|
||||
import { isOneChar, toOneChar, unescapeString, escapeStringForRegex } from '../util/util.js';
|
||||
import { KMXFile } from './kmx.js';
|
||||
import { UnicodeSetParser, UnicodeSet } from '@keymanapp/common-types';
|
||||
import { VariableParser } from '../ldml-keyboard/pattern-parser.js';
|
||||
import { MarkerParser } from '../ldml-keyboard/pattern-parser.js';
|
||||
import { ListItem } from '../../ldml-keyboard/string-list.js';
|
||||
import { util } from '@keymanapp/common-types';
|
||||
import { KMX } from '@keymanapp/common-types';
|
||||
import { UnicodeSetParser, UnicodeSet } from '../../ldml-keyboard/unicodeset-parser-api.js';
|
||||
import { VariableParser } from '../../ldml-keyboard/pattern-parser.js';
|
||||
import { MarkerParser } from '../../ldml-keyboard/pattern-parser.js';
|
||||
|
||||
import isOneChar = util.isOneChar;
|
||||
import toOneChar = util.toOneChar;
|
||||
import unescapeString = util.unescapeString;
|
||||
import escapeStringForRegex = util.escapeStringForRegex;
|
||||
import KMXFile = KMX.KMXFile;
|
||||
|
||||
// Implementation of file structures from /core/src/ldml/C7043_ldml.md
|
||||
// Writer in kmx-builder.ts
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { OrderedStringList } from '../ldml-keyboard/pattern-parser.js';
|
||||
import { DependencySections, StrsItem, StrsOptions } from './kmx-plus.js';
|
||||
import { OrderedStringList } from './pattern-parser.js';
|
||||
import { DependencySections, StrsItem, StrsOptions } from '../kmx/kmx-plus/kmx-plus.js';
|
||||
|
||||
/**
|
||||
* A single entry in a ListItem.
|
||||
|
|
@ -1,21 +1,12 @@
|
|||
export * as KMX from './kmx/kmx.js';
|
||||
export * as KMXPlus from './kmx/kmx-plus.js';
|
||||
export { default as KMXBuilder } from './kmx/kmx-builder.js';
|
||||
export { KmxFileReader, KmxFileReaderError } from './kmx/kmx-file-reader.js';
|
||||
export * as KeymanTargets from './kmx/keyman-targets.js';
|
||||
|
||||
export * as VisualKeyboard from './kvk/visual-keyboard.js';
|
||||
export { default as KMXPlusBuilder} from './kmx/kmx-plus-builder/kmx-plus-builder.js';
|
||||
export { default as KvkFileReader } from './kvk/kvk-file-reader.js';
|
||||
export { default as KvkFileWriter } from './kvk/kvk-file-writer.js';
|
||||
export * as KvkFile from './kvk/kvk-file.js';
|
||||
|
||||
export * as LDMLKeyboard from './ldml-keyboard/ldml-keyboard-xml.js';
|
||||
export { LDMLKeyboardTestDataXMLSourceFile } from './ldml-keyboard/ldml-keyboard-testdata-xml.js';
|
||||
export { UnicodeSetParser, UnicodeSet } from './ldml-keyboard/unicodeset-parser-api.js';
|
||||
export { VariableParser, MarkerParser } from './ldml-keyboard/pattern-parser.js';
|
||||
export { LDMLKeyboardXMLSourceFileReader, LDMLKeyboardXMLSourceFileReaderOptions } from './ldml-keyboard/ldml-keyboard-xml-reader.js';
|
||||
|
||||
export * as Constants from './consts/virtual-key-constants.js';
|
||||
|
||||
export { defaultCompilerOptions, CompilerBaseOptions, CompilerCallbacks, CompilerOptions, CompilerEvent, CompilerErrorNamespace,
|
||||
|
|
@ -34,6 +25,7 @@ export { defaultCompilerOptions, CompilerBaseOptions, CompilerCallbacks, Compile
|
|||
KeymanCompiler
|
||||
|
||||
} from './util/compiler-interfaces.js';
|
||||
|
||||
export { CommonTypesMessages } from './util/common-events.js';
|
||||
|
||||
export * as TouchLayout from './keyman-touch-layout/keyman-touch-layout-file.js';
|
||||
|
|
@ -48,4 +40,10 @@ export * as KeymanFileTypes from './util/file-types.js';
|
|||
export * as Schemas from './schemas.js';
|
||||
export * as SchemaValidators from './schema-validators.js';
|
||||
|
||||
export * as xml2js from './deps/xml2js/xml2js.js';
|
||||
export * as xml2js from './deps/xml2js/xml2js.js';
|
||||
|
||||
export * as KMXPlus from './kmx/kmx-plus/kmx-plus.js';
|
||||
// TODO: these exports are really not well named
|
||||
export { UnicodeSetParser, UnicodeSet } from './ldml-keyboard/unicodeset-parser-api.js';
|
||||
export { VariableParser, MarkerParser } from './ldml-keyboard/pattern-parser.js';
|
||||
export { ElementString } from './kmx/kmx-plus/element-string.js';
|
||||
|
|
@ -27,9 +27,28 @@ builder_parse "$@"
|
|||
|
||||
#-------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function copy_cldr_imports() {
|
||||
# Store CLDR imports
|
||||
# load all versions that have a cldr_info.json
|
||||
for CLDR_INFO_PATH in "$KEYMAN_ROOT/resources/standards-data/ldml-keyboards/"*/cldr_info.json
|
||||
do
|
||||
# TODO-LDML: developer/src/inst/download.in.mak needs these also...
|
||||
CLDR_PATH=$(dirname "$CLDR_INFO_PATH")
|
||||
CLDR_VER=$(basename "$CLDR_PATH")
|
||||
mkdir -p "$THIS_SCRIPT_PATH/build/src/import/$CLDR_VER"
|
||||
# TODO-LDML: When these are copied, the DOCTYPE will break due to the wrong path. We don't use the DTD so it should be OK.
|
||||
cp "$CLDR_INFO_PATH" "$CLDR_PATH/import/"*.xml "$THIS_SCRIPT_PATH/build/src/import/$CLDR_VER/"
|
||||
done
|
||||
}
|
||||
|
||||
function do_build() {
|
||||
copy_cldr_imports
|
||||
tsc --build
|
||||
}
|
||||
|
||||
builder_run_action clean rm -rf ./build/
|
||||
builder_run_action configure verify_npm_setup
|
||||
builder_run_action build tsc --build
|
||||
builder_run_action build do_build
|
||||
|
||||
if builder_start_action test; then
|
||||
eslint .
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@
|
|||
"/build/"
|
||||
],
|
||||
"dependencies": {
|
||||
"@sentry/node": "^7.57.0"
|
||||
"@sentry/node": "^7.57.0",
|
||||
"restructure": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.4.1",
|
||||
"typescript": "^5.4.5",
|
||||
"c8": "^7.12.0",
|
||||
"mocha": "^8.4.0"
|
||||
"mocha": "^8.4.0",
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -b"
|
||||
|
|
|
|||
|
|
@ -17,3 +17,10 @@ export * as KvksFile from './types/kvks/kvks-file.js';
|
|||
|
||||
export { TouchLayoutFileReader } from './types/keyman-touch-layout/keyman-touch-layout-file-reader.js';
|
||||
export { TouchLayoutFileWriter, TouchLayoutFileWriterOptions } from './types/keyman-touch-layout/keyman-touch-layout-file-writer.js';
|
||||
|
||||
export { default as KMXBuilder } from './types/kmx/kmx-builder.js';
|
||||
export { default as KMXPlusBuilder} from './types/kmx/kmx-plus-builder/kmx-plus-builder.js';
|
||||
|
||||
export * as LDMLKeyboard from './types/ldml-keyboard/ldml-keyboard-xml.js';
|
||||
export { LDMLKeyboardTestDataXMLSourceFile } from './types/ldml-keyboard/ldml-keyboard-testdata-xml.js';
|
||||
export { LDMLKeyboardXMLSourceFileReader, LDMLKeyboardXMLSourceFileReaderOptions } from './types/ldml-keyboard/ldml-keyboard-xml-reader.js';
|
||||
|
|
|
|||
2
developer/src/common/web/utils/src/restructure.d.ts
vendored
Normal file
2
developer/src/common/web/utils/src/restructure.d.ts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// TODO: consider defining more types?
|
||||
declare module 'restructure';
|
||||
|
|
@ -1,8 +1,18 @@
|
|||
import { KMXPlus, KMX } from '@keymanapp/common-types';
|
||||
import * as r from 'restructure';
|
||||
import { KMXFile, GROUP, KEY, STORE, BUILDER_COMP_KEYBOARD, BUILDER_COMP_KEYBOARD_KMXPLUSINFO, BUILDER_COMP_STORE, BUILDER_COMP_GROUP, BUILDER_COMP_KEY } from './kmx.js';
|
||||
import { KMXPlusFile } from './kmx-plus.js';
|
||||
import KMXPlusBuilder from './kmx-plus-builder/kmx-plus-builder.js';
|
||||
|
||||
import KMXPlusFile = KMXPlus.KMXPlusFile;
|
||||
import KMXFile = KMX.KMXFile;
|
||||
import GROUP = KMX.GROUP;
|
||||
import KEY = KMX.KEY;
|
||||
import STORE = KMX.STORE;
|
||||
import BUILDER_COMP_KEYBOARD = KMX.BUILDER_COMP_KEYBOARD;
|
||||
import BUILDER_COMP_KEYBOARD_KMXPLUSINFO = KMX.BUILDER_COMP_KEYBOARD_KMXPLUSINFO;
|
||||
import BUILDER_COMP_STORE = KMX.BUILDER_COMP_STORE;
|
||||
import BUILDER_COMP_GROUP = KMX.BUILDER_COMP_GROUP;
|
||||
import BUILDER_COMP_KEY = KMX.BUILDER_COMP_KEY;
|
||||
|
||||
export default class KMXBuilder {
|
||||
file: KMXFile;
|
||||
base_keyboard: number = 0;
|
||||
|
|
@ -69,8 +79,8 @@ export default class KMXBuilder {
|
|||
this.comp_header.dpStoreArray = this.comp_header.cxStoreArray ? size : 0;
|
||||
let storeBase = size;
|
||||
size += this.file.keyboard.stores.length * KMXFile.COMP_STORE_SIZE;
|
||||
for(let store of this.file.keyboard.stores) {
|
||||
let comp_store: BUILDER_COMP_STORE = {
|
||||
for(const store of this.file.keyboard.stores) {
|
||||
const comp_store: BUILDER_COMP_STORE = {
|
||||
dwSystemID: store.dwSystemID,
|
||||
dpName: 0,
|
||||
dpString: 0
|
||||
|
|
@ -90,8 +100,8 @@ export default class KMXBuilder {
|
|||
this.comp_header.dpGroupArray = this.comp_header.cxGroupArray ? size : 0;
|
||||
let groupBase = size;
|
||||
size += this.file.keyboard.groups.length * KMXFile.COMP_GROUP_SIZE;
|
||||
for(let group of this.file.keyboard.groups) {
|
||||
let comp_group: BUILDER_COMP_GROUP = {
|
||||
for(const group of this.file.keyboard.groups) {
|
||||
const comp_group: BUILDER_COMP_GROUP = {
|
||||
dpName: 0,
|
||||
dpKeyArray: 0,
|
||||
dpMatch: 0,
|
||||
|
|
@ -100,7 +110,7 @@ export default class KMXBuilder {
|
|||
fUsingKeys: group.fUsingKeys ? 1 : 0
|
||||
};
|
||||
|
||||
let comp_keys: {base: number, key: KEY, obj: BUILDER_COMP_KEY}[] = [];
|
||||
const comp_keys: {base: number, key: KEY, obj: BUILDER_COMP_KEY}[] = [];
|
||||
|
||||
this.comp_groups.push({base: groupBase, group: group, obj: comp_group, keys: comp_keys});
|
||||
|
||||
|
|
@ -116,8 +126,8 @@ export default class KMXBuilder {
|
|||
|
||||
let keyBase = size;
|
||||
size += group.keys.length * KMXFile.COMP_KEY_SIZE;
|
||||
for(let key of group.keys) {
|
||||
let comp_key: BUILDER_COMP_KEY = {
|
||||
for(const key of group.keys) {
|
||||
const comp_key: BUILDER_COMP_KEY = {
|
||||
Key: key.Key,
|
||||
_padding: 0,
|
||||
Line: key.Line,
|
||||
|
|
@ -164,11 +174,11 @@ export default class KMXBuilder {
|
|||
if(requireString && !str.length) {
|
||||
// Just write zero terminator, as r.String for a zero-length string
|
||||
// seems to fail.
|
||||
let sbuf = r.uint16le;
|
||||
const sbuf = r.uint16le;
|
||||
file.set(sbuf.toBuffer(0), pos);
|
||||
}
|
||||
else if(pos && str.length) {
|
||||
let sbuf = new r.String(null, 'utf16le'); // null-terminated string
|
||||
const sbuf = new r.String(null, 'utf16le'); // null-terminated string
|
||||
file.set(sbuf.toBuffer(str), pos);
|
||||
}
|
||||
}
|
||||
|
|
@ -176,7 +186,7 @@ export default class KMXBuilder {
|
|||
compile(): Uint8Array {
|
||||
const fileSize = this.build();
|
||||
|
||||
let file: Uint8Array = new Uint8Array(fileSize);
|
||||
const file: Uint8Array = new Uint8Array(fileSize);
|
||||
|
||||
// Write headers
|
||||
|
||||
|
|
@ -190,7 +200,7 @@ export default class KMXBuilder {
|
|||
|
||||
// Write store array and data
|
||||
|
||||
for(let store of this.comp_stores) {
|
||||
for(const store of this.comp_stores) {
|
||||
file.set(this.file.COMP_STORE.toBuffer(store.obj), store.base);
|
||||
if(this.writeDebug) {
|
||||
this.setString(file, store.obj.dpName, store.store.dpName);
|
||||
|
|
@ -200,7 +210,7 @@ export default class KMXBuilder {
|
|||
|
||||
// Write group array and data
|
||||
|
||||
for(let group of this.comp_groups) {
|
||||
for(const group of this.comp_groups) {
|
||||
file.set(this.file.COMP_GROUP.toBuffer(group.obj), group.base);
|
||||
if(this.writeDebug) {
|
||||
this.setString(file, group.obj.dpName, group.group.dpName);
|
||||
|
|
@ -208,7 +218,7 @@ export default class KMXBuilder {
|
|||
this.setString(file, group.obj.dpMatch, group.group.dpMatch);
|
||||
this.setString(file, group.obj.dpNoMatch, group.group.dpNoMatch);
|
||||
|
||||
for(let key of group.keys) {
|
||||
for(const key of group.keys) {
|
||||
file.set(this.file.COMP_KEY.toBuffer(key.obj), key.base);
|
||||
// for back-compat reasons, these are never NULL strings
|
||||
this.setString(file, key.obj.dpContext, key.key.dpContext, true);
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
import { constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { KMXPlusData } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION } from './builder-section.js';
|
||||
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* disp section
|
||||
------------------------------------------------------------------ */
|
||||
|
|
@ -27,7 +29,7 @@ export function build_disp(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILD
|
|||
return null;
|
||||
}
|
||||
|
||||
let disp: BUILDER_DISP = {
|
||||
const disp: BUILDER_DISP = {
|
||||
ident: constants.hex_section_id(constants.section.disp),
|
||||
size: constants.length_disp + constants.length_disp_item * kmxplus.disp.disps.length,
|
||||
_offset: 0,
|
||||
|
|
@ -36,7 +38,7 @@ export function build_disp(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILD
|
|||
items: []
|
||||
};
|
||||
|
||||
for(let item of kmxplus.disp.disps) {
|
||||
for(const item of kmxplus.disp.disps) {
|
||||
disp.items.push({
|
||||
to: build_strs_index(sect_strs, item.to),
|
||||
id: build_strs_index(sect_strs, item.id),
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { ElementString } from "../element-string.js";
|
||||
import { Elem } from "../kmx-plus.js";
|
||||
import { KMXPlus, ElementString } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION, BUILDER_U32CHAR } from "./builder-section.js";
|
||||
import { build_uset_index, BUILDER_USET, BUILDER_USET_REF } from "./build-uset.js";
|
||||
|
||||
import Elem = KMXPlus.Elem;
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* elem section
|
||||
------------------------------------------------------------------ */
|
||||
|
|
@ -46,7 +47,7 @@ function binaryElemCompare(a: BUILDER_ELEM_STRING, b: BUILDER_ELEM_STRING): numb
|
|||
}
|
||||
|
||||
export function build_elem(source_elem: Elem, sect_strs: BUILDER_STRS, sect_uset: BUILDER_USET): BUILDER_ELEM {
|
||||
let result: BUILDER_ELEM = {
|
||||
const result: BUILDER_ELEM = {
|
||||
ident: constants.hex_section_id(constants.section.elem),
|
||||
size: 0, // finalized below
|
||||
_offset: 0,
|
||||
|
|
@ -55,7 +56,7 @@ export function build_elem(source_elem: Elem, sect_strs: BUILDER_STRS, sect_uset
|
|||
};
|
||||
|
||||
result.strings = source_elem.strings.map(item => {
|
||||
let res: BUILDER_ELEM_STRING = {
|
||||
const res: BUILDER_ELEM_STRING = {
|
||||
offset: 0, // finalized below
|
||||
length: item.length,
|
||||
items: [],
|
||||
|
|
@ -87,7 +88,7 @@ export function build_elem(source_elem: Elem, sect_strs: BUILDER_STRS, sect_uset
|
|||
/* Calculate offsets and total size */
|
||||
|
||||
let offset = constants.length_elem + constants.length_elem_item * result.count;
|
||||
for(let item of result.strings) {
|
||||
for(const item of result.strings) {
|
||||
if (item.length === 0) {
|
||||
// no length gets a zero offset
|
||||
item.offset = 0;
|
||||
|
|
@ -1,10 +1,14 @@
|
|||
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KeysFlick, KMXPlusData, StrsItem } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { build_list_index, BUILDER_LIST, BUILDER_LIST_REF } from "./build-list.js";
|
||||
import { BUILDER_SECTION, BUILDER_U32CHAR } from "./builder-section.js";
|
||||
|
||||
import KeysFlick = KMXPlus.KeysFlick;
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
import StrsItem = KMXPlus.StrsItem;
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* keys section
|
||||
------------------------------------------------------------------ */
|
||||
|
|
@ -71,7 +75,7 @@ export function build_keys(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
return null;
|
||||
}
|
||||
|
||||
let keys: BUILDER_KEYS = {
|
||||
const keys: BUILDER_KEYS = {
|
||||
ident: constants.hex_section_id(constants.section.keys),
|
||||
size: 0,
|
||||
keyCount: kmxplus.keys.keys.length,
|
||||
|
|
@ -89,7 +93,7 @@ export function build_keys(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
|
||||
// Note that per the Keys class and spec, there is always a flicks=0 meaning 'no flicks'
|
||||
keys.flicks = kmxplus.keys.flicks.map((flicks) => {
|
||||
let result : BUILDER_KEYS_FLICKS = {
|
||||
const result : BUILDER_KEYS_FLICKS = {
|
||||
count: flicks.flicks.length,
|
||||
flick: keys.flick.length, // index of first flick
|
||||
id: build_strs_index(sect_strs, flicks.id),
|
||||
|
|
@ -113,7 +117,7 @@ export function build_keys(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
|
||||
// now, keys
|
||||
keys.keys = kmxplus.keys.keys.map((key) => {
|
||||
let result : BUILDER_KEYS_KEY = {
|
||||
const result : BUILDER_KEYS_KEY = {
|
||||
to: build_strs_index(sect_strs, key.to),
|
||||
flags: key.flags,
|
||||
id: build_strs_index(sect_strs, key.id),
|
||||
|
|
@ -136,7 +140,7 @@ export function build_keys(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
|
||||
// finally, kmap
|
||||
keys.kmap = kmxplus.keys.kmap.map(({vkey, mod, key}) => {
|
||||
let result : BUILDER_KEYS_KMAP = {
|
||||
const result : BUILDER_KEYS_KMAP = {
|
||||
vkey,
|
||||
mod,
|
||||
key: keys.keys.findIndex(k => k._id === key),
|
||||
|
|
@ -160,7 +164,7 @@ export function build_keys(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
return rc;
|
||||
});
|
||||
|
||||
let offset = constants.length_keys +
|
||||
const offset = constants.length_keys +
|
||||
(constants.length_keys_key * keys.keyCount) +
|
||||
(constants.length_keys_flick_element * keys.flickCount) +
|
||||
(constants.length_keys_flick_list * keys.flicksCount) +
|
||||
|
|
@ -1,10 +1,15 @@
|
|||
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlusData, LayrEntry, LayrRow, StrsItem } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_LIST } from "./build-list.js";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
import LayrEntry = KMXPlus.LayrEntry;
|
||||
import LayrRow = KMXPlus.LayrRow;
|
||||
import StrsItem = KMXPlus.StrsItem;
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* layr section -
|
||||
------------------------------------------------------------------ */
|
||||
|
|
@ -66,7 +71,7 @@ export function build_layr(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
return null; // if there aren't any layers at all (which should be an invalid keyboard)
|
||||
}
|
||||
|
||||
let layr: BUILDER_LAYR = {
|
||||
const layr: BUILDER_LAYR = {
|
||||
ident: constants.hex_section_id(constants.section.layr),
|
||||
size: constants.length_layr,
|
||||
_offset: 0,
|
||||
|
|
@ -145,7 +150,7 @@ export function build_layr(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
|
|||
layr.rowCount = layr.rows.length;
|
||||
layr.keyCount = layr.keys.length;
|
||||
|
||||
let offset = constants.length_layr +
|
||||
const offset = constants.length_layr +
|
||||
(constants.length_layr_list * layr.listCount) +
|
||||
(constants.length_layr_entry * layr.layerCount) +
|
||||
(constants.length_layr_row * layr.rowCount) +
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { List, ListItem } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
|
||||
import List = KMXPlus.List;
|
||||
import ListItem = KMXPlus.ListItem;
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* list section
|
||||
------------------------------------------------------------------ */
|
||||
|
|
@ -40,7 +43,7 @@ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_
|
|||
return null;
|
||||
}
|
||||
|
||||
let result: BUILDER_LIST = {
|
||||
const result: BUILDER_LIST = {
|
||||
ident: constants.hex_section_id(constants.section.list),
|
||||
size: 0,
|
||||
_offset: 0,
|
||||
|
|
@ -51,13 +54,13 @@ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_
|
|||
};
|
||||
|
||||
result.lists = source_list.lists.map(array => {
|
||||
let list : BUILDER_LIST_LIST = {
|
||||
const list : BUILDER_LIST_LIST = {
|
||||
index: result.indices.length, // the next indexcount
|
||||
count: array.length,
|
||||
_value: array
|
||||
};
|
||||
array.forEach((i) => {
|
||||
let index : BUILDER_LIST_INDEX = {
|
||||
const index : BUILDER_LIST_INDEX = {
|
||||
// Get the final string index
|
||||
str: build_strs_index(sect_strs, i.value),
|
||||
_value: i.value.value, // unwrap the actual string value
|
||||
|
|
@ -71,7 +74,7 @@ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_
|
|||
// Sort the lists.
|
||||
result.lists.sort((a,b) => a._value.compareTo(b._value));
|
||||
|
||||
let offset = constants.length_list +
|
||||
const offset = constants.length_list +
|
||||
(constants.length_list_item * result.listCount) +
|
||||
(constants.length_list_index * result.indexCount);
|
||||
result.size = offset;
|
||||
|
|
@ -86,14 +89,14 @@ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_
|
|||
* @returns
|
||||
*/
|
||||
export function build_list_index(sect_list: BUILDER_LIST, value: ListItem) : BUILDER_LIST_REF {
|
||||
if (!value) {
|
||||
if (!value) {
|
||||
return 0; // empty list
|
||||
}
|
||||
if(!(value instanceof ListItem)) {
|
||||
throw new Error('unexpected value '+ value);
|
||||
}
|
||||
|
||||
let result = sect_list.lists.findIndex(v => v._value === value);
|
||||
const result = sect_list.lists.findIndex(v => v._value === value);
|
||||
if(result < 0) {
|
||||
throw new Error('unexpectedly missing ListItem ' + value); // TODO-LDML: it's an array of strs
|
||||
}
|
||||
|
|
@ -4,10 +4,12 @@
|
|||
------------------------------------------------------------------ */
|
||||
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlusData } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
|
||||
/**
|
||||
* Builder for the 'loca' section
|
||||
*/
|
||||
|
|
@ -17,7 +19,7 @@ export interface BUILDER_LOCA extends BUILDER_SECTION {
|
|||
};
|
||||
|
||||
export function build_loca(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_LOCA {
|
||||
let loca: BUILDER_LOCA = {
|
||||
const loca: BUILDER_LOCA = {
|
||||
ident: constants.hex_section_id(constants.section.loca),
|
||||
size: constants.length_loca + constants.length_loca_item * kmxplus.loca.locales.length,
|
||||
_offset: 0,
|
||||
|
|
@ -25,7 +27,7 @@ export function build_loca(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILD
|
|||
items: []
|
||||
};
|
||||
|
||||
for(let item of kmxplus.loca.locales) {
|
||||
for(const item of kmxplus.loca.locales) {
|
||||
loca.items.push(build_strs_index(sect_strs, item));
|
||||
}
|
||||
|
||||
|
|
@ -4,10 +4,12 @@
|
|||
------------------------------------------------------------------ */
|
||||
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlusData } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
|
||||
/**
|
||||
* Builder for the 'meta' section
|
||||
*/
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { Strs, StrsItem } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
|
||||
import Strs = KMXPlus.Strs;
|
||||
import StrsItem = KMXPlus.StrsItem;
|
||||
|
||||
/** reference from build_strs_index */
|
||||
export type BUILDER_STR_REF = number;
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ export interface BUILDER_STRS extends BUILDER_SECTION {
|
|||
};
|
||||
|
||||
export function build_strs(source_strs: Strs): BUILDER_STRS {
|
||||
let result: BUILDER_STRS = {
|
||||
const result: BUILDER_STRS = {
|
||||
ident: constants.hex_section_id(constants.section.strs),
|
||||
size: 0, // finalized later
|
||||
_offset: 0,
|
||||
|
|
@ -39,7 +42,7 @@ export function build_strs(source_strs: Strs): BUILDER_STRS {
|
|||
|
||||
let offset = constants.length_strs + constants.length_strs_item * result.count;
|
||||
// TODO: consider padding
|
||||
for(let item of result.items) {
|
||||
for(const item of result.items) {
|
||||
item.offset = offset;
|
||||
offset += item.length * 2 + 2; /* UTF-16 code units + sizeof null terminator */
|
||||
}
|
||||
|
|
@ -64,7 +67,7 @@ export function build_strs_index(sect_strs: BUILDER_STRS, value: StrsItem) : BUI
|
|||
return <BUILDER_STR_REF>value.char;
|
||||
}
|
||||
|
||||
let result = sect_strs.items.findIndex(v => v._value === value.value);
|
||||
const result = sect_strs.items.findIndex(v => v._value === value.value);
|
||||
if(result < 0) {
|
||||
throw new Error('unexpectedly missing StrsItem '+value.value);
|
||||
}
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { Bksp, Tran } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { BUILDER_ELEM, BUILDER_ELEM_REF, build_elem_index } from "./build-elem.js";
|
||||
import { BUILDER_STRS, BUILDER_STR_REF, build_strs_index } from "./build-strs.js";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
|
||||
import Bksp = KMXPlus.Bksp;
|
||||
import Tran = KMXPlus.Tran;
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* tran section
|
||||
------------------------------------------------------------------ */
|
||||
|
|
@ -44,7 +47,7 @@ export function build_tran(source_tran: Tran | Bksp, sect_strs: BUILDER_STRS, se
|
|||
return null;
|
||||
}
|
||||
|
||||
let tran: BUILDER_TRAN = {
|
||||
const tran: BUILDER_TRAN = {
|
||||
ident: constants.hex_section_id(source_tran.id),
|
||||
size: 0, // need to compute total transforms + reorders
|
||||
_offset: 0,
|
||||
|
|
@ -56,14 +59,14 @@ export function build_tran(source_tran: Tran | Bksp, sect_strs: BUILDER_STRS, se
|
|||
reorders: [],
|
||||
};
|
||||
|
||||
for (let group of source_tran.groups) {
|
||||
for (const group of source_tran.groups) {
|
||||
if (group.type === constants.tran_group_type_transform) {
|
||||
tran.groups.push({
|
||||
type: group.type,
|
||||
count: group.transforms.length,
|
||||
index: tran.transforms.length, // index of first item
|
||||
});
|
||||
for (let transform of group.transforms) {
|
||||
for (const transform of group.transforms) {
|
||||
tran.transforms.push({
|
||||
from: build_strs_index(sect_strs, transform.from),
|
||||
to: build_strs_index(sect_strs, transform.to),
|
||||
|
|
@ -77,7 +80,7 @@ export function build_tran(source_tran: Tran | Bksp, sect_strs: BUILDER_STRS, se
|
|||
count: group.reorders.length,
|
||||
index: tran.reorders.length, // index of first item
|
||||
});
|
||||
for (let reorder of group.reorders) {
|
||||
for (const reorder of group.reorders) {
|
||||
tran.reorders.push({
|
||||
elements: build_elem_index(sect_elem, reorder.elements),
|
||||
before: build_elem_index(sect_elem, reorder.before),
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlusData, StrsItem, UsetItem } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION, BUILDER_U32CHAR } from "./builder-section.js";
|
||||
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
import StrsItem = KMXPlus.StrsItem;
|
||||
import UsetItem = KMXPlus.UsetItem;
|
||||
|
||||
/** reference from build_uset_index */
|
||||
export type BUILDER_USET_REF = number;
|
||||
|
||||
|
|
@ -80,7 +84,7 @@ export function build_uset_index(sect_uset: BUILDER_USET, value: UsetItem) {
|
|||
}
|
||||
}
|
||||
|
||||
let result = sect_uset.usets.findIndex(v => v._pattern.value === value.str.value);
|
||||
const result = sect_uset.usets.findIndex(v => v._pattern.value === value.str.value);
|
||||
if(result < 0) {
|
||||
throw new Error('unexpectedly missing UsetItem ' + value.uset.toString());
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlusData } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
|
||||
import { BUILDER_SECTION } from "./builder-section.js";
|
||||
import { build_list_index, BUILDER_LIST, BUILDER_LIST_REF } from "./build-list.js";
|
||||
import { build_elem_index, BUILDER_ELEM, BUILDER_ELEM_REF } from "./build-elem.js";
|
||||
|
||||
import KMXPlusData = KMXPlus.KMXPlusData;
|
||||
|
||||
interface BUILDER_VARS_ITEM {
|
||||
type: number;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import * as r from 'restructure';
|
||||
import { KMXPlusFile } from "../kmx-plus.js";
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
import { constants, SectionIdent } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { BUILDER_SECTION } from './builder-section.js';
|
||||
import { BUILDER_SECT, build_sect } from './build-sect.js';
|
||||
|
|
@ -15,6 +15,8 @@ import { BUILDER_TRAN, build_tran } from './build-tran.js';
|
|||
import { BUILDER_USET, build_uset } from './build-uset.js';
|
||||
import { BUILDER_VARS, build_vars } from './build-vars.js';
|
||||
|
||||
import KMXPlusFile = KMXPlus.KMXPlusFile;
|
||||
|
||||
type BUILDER_BKSP = BUILDER_TRAN;
|
||||
// type BUILDER_FINL = BUILDER_TRAN;
|
||||
|
||||
|
|
@ -50,7 +52,7 @@ export default class KMXPlusBuilder {
|
|||
|
||||
public compile(): Uint8Array {
|
||||
const fileSize = this.build();
|
||||
let file: Uint8Array = new Uint8Array(fileSize);
|
||||
const file: Uint8Array = new Uint8Array(fileSize);
|
||||
|
||||
this.emitSection(file, this.file.COMP_PLUS_SECT, this.sect.sect);
|
||||
// Keep the rest of these in order.
|
||||
|
|
@ -155,13 +157,13 @@ export default class KMXPlusBuilder {
|
|||
}
|
||||
|
||||
private emitStrings(file: Uint8Array) {
|
||||
for(let item of this.sect.strs.items) {
|
||||
for(const item of this.sect.strs.items) {
|
||||
if(item._value === '') {
|
||||
// We have a special case for the zero-length string
|
||||
let sbuf = r.uint16le;
|
||||
const sbuf = r.uint16le;
|
||||
file.set(sbuf.toBuffer(0), item.offset + this.sect.strs._offset);
|
||||
} else {
|
||||
let sbuf = new r.String(null, 'utf16le');
|
||||
const sbuf = new r.String(null, 'utf16le');
|
||||
file.set(sbuf.toBuffer(item._value), item.offset + this.sect.strs._offset);
|
||||
}
|
||||
}
|
||||
|
|
@ -169,9 +171,9 @@ export default class KMXPlusBuilder {
|
|||
|
||||
private emitElements(file: Uint8Array) {
|
||||
if(this.sect.elem) {
|
||||
for(let str of this.sect.elem.strings) {
|
||||
for(const str of this.sect.elem.strings) {
|
||||
if(str.items.length > 0) {
|
||||
let COMP_PLUS_ELEM_ELEMENTS = new r.Array(this.file.COMP_PLUS_ELEM_ELEMENT, str.items.length);
|
||||
const COMP_PLUS_ELEM_ELEMENTS = new r.Array(this.file.COMP_PLUS_ELEM_ELEMENT, str.items.length);
|
||||
file.set(COMP_PLUS_ELEM_ELEMENTS.toBuffer(str.items), str.offset + this.sect.elem._offset);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
import * as xml2js from '../deps/xml2js/xml2js.js';
|
||||
import { SchemaValidators, CommonTypesMessages, CompilerCallbacks, util, xml2js } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboardXMLSourceFile, LKImport, ImportStatus } from './ldml-keyboard-xml.js';
|
||||
import { boxXmlArray } from '../util/util.js';
|
||||
import { CompilerCallbacks } from '../util/compiler-interfaces.js';
|
||||
import { constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { CommonTypesMessages } from '../util/common-events.js';
|
||||
import { LDMLKeyboardTestDataXMLSourceFile, LKTTest, LKTTests } from './ldml-keyboard-testdata-xml.js';
|
||||
import SchemaValidators from '../schema-validators.js';
|
||||
|
||||
import boxXmlArray = util.boxXmlArray;
|
||||
|
||||
interface NameAndProps {
|
||||
'$'?: any; // content
|
||||
|
|
@ -22,7 +20,7 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
}
|
||||
|
||||
static get defaultImportsURL(): [string,string] {
|
||||
return ['../import/', import.meta.url];
|
||||
return ['../../import/', import.meta.url];
|
||||
}
|
||||
|
||||
readImportFile(version: string, subpath: string): Uint8Array {
|
||||
|
|
@ -63,10 +61,10 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
boxXmlArray(source?.keyboard3?.locales, 'locale');
|
||||
boxXmlArray(source?.keyboard3, 'transforms');
|
||||
if(source?.keyboard3?.layers) {
|
||||
for(let layers of source?.keyboard3?.layers) {
|
||||
for(const layers of source?.keyboard3?.layers) {
|
||||
boxXmlArray(layers, 'layer');
|
||||
if(layers?.layer) {
|
||||
for(let layer of layers?.layer) {
|
||||
for(const layer of layers?.layer) {
|
||||
boxXmlArray(layer, 'row');
|
||||
}
|
||||
}
|
||||
|
|
@ -74,13 +72,13 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
}
|
||||
if(source?.keyboard3?.forms?.form) {
|
||||
boxXmlArray(source?.keyboard3?.forms, 'form');
|
||||
for(let form of source?.keyboard3?.forms?.form) {
|
||||
for(const form of source?.keyboard3?.forms?.form) {
|
||||
boxXmlArray(form, 'scanCodes');
|
||||
}
|
||||
}
|
||||
if(source?.keyboard3?.flicks) {
|
||||
boxXmlArray(source?.keyboard3?.flicks, 'flick');
|
||||
for(let flick of source?.keyboard3?.flicks?.flick) {
|
||||
for(const flick of source?.keyboard3?.flicks?.flick) {
|
||||
boxXmlArray(flick, 'flickSegment');
|
||||
}
|
||||
}
|
||||
|
|
@ -90,9 +88,9 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
boxXmlArray(source?.keyboard3?.variables, 'uset');
|
||||
}
|
||||
if(source?.keyboard3?.transforms) {
|
||||
for(let transforms of source.keyboard3.transforms) {
|
||||
for(const transforms of source.keyboard3.transforms) {
|
||||
boxXmlArray(transforms, 'transformGroup');
|
||||
for (let transformGroup of transforms.transformGroup) {
|
||||
for (const transformGroup of transforms.transformGroup) {
|
||||
boxXmlArray(transformGroup, 'transform');
|
||||
boxXmlArray(transformGroup, 'reorder');
|
||||
}
|
||||
|
|
@ -235,8 +233,8 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
* @returns true if valid, false if invalid
|
||||
*/
|
||||
public validate(source: LDMLKeyboardXMLSourceFile | LDMLKeyboardTestDataXMLSourceFile): boolean {
|
||||
if(!SchemaValidators.ldmlKeyboard3(source)) {
|
||||
for (let err of (<any>SchemaValidators.ldmlKeyboard3).errors) {
|
||||
if(!SchemaValidators.default.ldmlKeyboard3(source)) {
|
||||
for (const err of (<any>SchemaValidators.default.ldmlKeyboard3).errors) {
|
||||
this.callbacks.reportMessage(CommonTypesMessages.Error_SchemaValidationError({
|
||||
instancePath: err.instancePath,
|
||||
keyword: err.keyword,
|
||||
|
|
@ -250,9 +248,9 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
}
|
||||
|
||||
loadUnboxed(file: Uint8Array): LDMLKeyboardXMLSourceFile {
|
||||
let source = (() => {
|
||||
const source = (() => {
|
||||
let a: LDMLKeyboardXMLSourceFile;
|
||||
let parser = new xml2js.Parser({
|
||||
const parser = new xml2js.Parser({
|
||||
explicitArray: false,
|
||||
mergeAttrs: true,
|
||||
includeWhiteChars: false,
|
||||
|
|
@ -289,9 +287,9 @@ export class LDMLKeyboardXMLSourceFileReader {
|
|||
}
|
||||
|
||||
loadTestDataUnboxed(file: Uint8Array): any {
|
||||
let source = (() => {
|
||||
const source = (() => {
|
||||
let a: any;
|
||||
let parser = new xml2js.Parser({
|
||||
const parser = new xml2js.Parser({
|
||||
// explicitArray: false,
|
||||
preserveChildrenOrder:true, // needed for test data
|
||||
explicitChildren: true, // needed for test data
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
* Helpers and utilities for the Mocha tests.
|
||||
*/
|
||||
import * as path from 'path';
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
|
|
@ -16,3 +17,6 @@ import { fileURLToPath } from 'url';
|
|||
return fileURLToPath(new URL(path.join('..', '..', '..', 'test', 'fixtures', ...components), import.meta.url));
|
||||
}
|
||||
|
||||
export function loadFile(filename: string | URL): Buffer {
|
||||
return fs.readFileSync(filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import 'mocha';
|
||||
import {assert} from 'chai';
|
||||
import { loadFile, makePathToFixture } from '../helpers/index.js';
|
||||
import { LDMLKeyboardXMLSourceFileReader, LDMLKeyboardXMLSourceFileReaderOptions } from '../../src/ldml-keyboard/ldml-keyboard-xml-reader.js';
|
||||
import { CompilerEvent } from '../../src/util/compiler-interfaces.js';
|
||||
import { LDMLKeyboardXMLSourceFile } from '../../src/ldml-keyboard/ldml-keyboard-xml.js';
|
||||
import { LDMLKeyboardTestDataXMLSourceFile } from '../ldml-keyboard/ldml-keyboard-testdata-xml.js';
|
||||
import { TestCompilerCallbacks } from './TestCompilerCallbacks.js';
|
||||
import { loadFile, makePathToFixture } from './index.js';
|
||||
import { LDMLKeyboardXMLSourceFileReader, LDMLKeyboardXMLSourceFileReaderOptions } from '../../src/types/ldml-keyboard/ldml-keyboard-xml-reader.js';
|
||||
import { CompilerEvent } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboardXMLSourceFile } from '../../src/types/ldml-keyboard/ldml-keyboard-xml.js';
|
||||
import { LDMLKeyboardTestDataXMLSourceFile } from '../../src/types/ldml-keyboard/ldml-keyboard-testdata-xml.js';
|
||||
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const readerOptions: LDMLKeyboardXMLSourceFileReaderOptions = {
|
||||
|
|
@ -77,14 +77,14 @@ export function testReaderCases(cases : CompilationCase[]) {
|
|||
// we need our own callbacks rather than using the global so messages don't get mixed
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
const reader = new LDMLKeyboardXMLSourceFileReader(readerOptions, callbacks);
|
||||
for (let testcase of cases) {
|
||||
for (const testcase of cases) {
|
||||
const expectFailure = testcase.throws || !!(testcase.errors); // if true, we expect this to fail
|
||||
const testHeading = expectFailure ? `should fail to load: ${testcase.subpath}`:
|
||||
`should load: ${testcase.subpath}`;
|
||||
it(testHeading, function () {
|
||||
callbacks.clear();
|
||||
|
||||
const data = loadFile(makePathToFixture(testcase.subpath));
|
||||
const data = loadFile(makePathToFixture('ldml-keyboard', testcase.subpath));
|
||||
assert.ok(data, `reading ${testcase.subpath}`);
|
||||
const source = reader.load(data);
|
||||
if (!testcase.loadfail) {
|
||||
|
|
@ -128,14 +128,14 @@ export function testTestdataReaderCases(cases : TestDataCase[]) {
|
|||
// we need our own callbacks rather than using the global so messages don't get mixed
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
const reader = new LDMLKeyboardXMLSourceFileReader(readerOptions, callbacks);
|
||||
for (let testcase of cases) {
|
||||
for (const testcase of cases) {
|
||||
const expectFailure = testcase.throws || !!(testcase.errors); // if true, we expect this to fail
|
||||
const testHeading = expectFailure ? `should fail to load: ${testcase.subpath}`:
|
||||
`should load: ${testcase.subpath}`;
|
||||
it(testHeading, function () {
|
||||
callbacks.clear();
|
||||
|
||||
const data = loadFile(makePathToFixture(testcase.subpath));
|
||||
const data = loadFile(makePathToFixture('ldml-keyboard', testcase.subpath));
|
||||
assert.ok(data, `reading ${testcase.subpath}`);
|
||||
const source = reader.loadTestData(data);
|
||||
if (!testcase.loadfail) {
|
||||
|
|
@ -2,7 +2,7 @@ import { constants } from '@keymanapp/ldml-keyboard-constants';
|
|||
import { assert } from 'chai';
|
||||
import 'mocha';
|
||||
import { testTestdataReaderCases } from '../helpers/reader-callback-test.js';
|
||||
import { LKTAnyAction } from './ldml-keyboard-testdata-xml.js';
|
||||
import { LKTAnyAction } from '../../src/types/ldml-keyboard/ldml-keyboard-testdata-xml.js';
|
||||
|
||||
describe('ldml keyboard xml reader tests', function () {
|
||||
this.slow(500); // 0.5 sec -- json schema validation takes a while
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
import { LKKey, ImportStatus } from './../../src/ldml-keyboard/ldml-keyboard-xml.js';
|
||||
import { LKKey, ImportStatus } from '../../src/types/ldml-keyboard/ldml-keyboard-xml.js';
|
||||
import 'mocha';
|
||||
import {assert} from 'chai';
|
||||
import { CommonTypesMessages } from '../../src/util/common-events.js';
|
||||
import { CommonTypesMessages } from '@keymanapp/common-types';
|
||||
import { testReaderCases } from '../helpers/reader-callback-test.js';
|
||||
import { CLDRScanToVkey, CLDRScanToKeyMap, USVirtualKeyCodes } from '../../src/consts/virtual-key-constants.js';
|
||||
import { Constants } from '@keymanapp/common-types';
|
||||
|
||||
import CLDRScanToVkey = Constants.CLDRScanToVkey;
|
||||
import CLDRScanToKeyMap = Constants.CLDRScanToKeyMap;
|
||||
import USVirtualKeyCodes = Constants.USVirtualKeyCodes;
|
||||
|
||||
function pluckKeysFromKeybag(keys: LKKey[], ids: string[]) {
|
||||
return keys.filter(({id}) => ids.indexOf(id) !== -1);
|
||||
|
|
@ -6,8 +6,8 @@ TODO: implement additional interfaces:
|
|||
*/
|
||||
|
||||
// TODO: rename wasm-host?
|
||||
import { UnicodeSetParser, UnicodeSet, VisualKeyboard, KvkFileReader, KeymanCompiler, KeymanCompilerArtifacts, KeymanCompilerArtifactOptional, KeymanCompilerResult, KeymanCompilerArtifact } from '@keymanapp/common-types';
|
||||
import { CompilerCallbacks, CompilerEvent, CompilerOptions, KeymanFileTypes, KvkFileWriter } from '@keymanapp/common-types';
|
||||
import { VisualKeyboard, KvkFileReader, KeymanCompiler, KeymanCompilerArtifacts, KeymanCompilerArtifactOptional, KeymanCompilerResult, KeymanCompilerArtifact } from '@keymanapp/common-types';
|
||||
import { UnicodeSetParser, UnicodeSet, CompilerCallbacks, CompilerEvent, CompilerOptions, KeymanFileTypes, KvkFileWriter } from '@keymanapp/common-types';
|
||||
import { KvksFileReader } from '@keymanapp/developer-utils';
|
||||
import * as Osk from './osk.js';
|
||||
import loadWasmHost from '../import/kmcmplib/wasm-host.js';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { LDMLKeyboardXMLSourceFileReader, LDMLKeyboard, KMXPlus, CompilerCallbacks, LDMLKeyboardTestDataXMLSourceFile, UnicodeSetParser, KeymanCompiler, KeymanCompilerResult, KeymanCompilerArtifacts, defaultCompilerOptions, KMXBuilder, KvkFileWriter, KeymanCompilerArtifactOptional } from '@keymanapp/common-types';
|
||||
import { KMXPlus, UnicodeSetParser, CompilerCallbacks, KeymanCompiler, KeymanCompilerResult, KeymanCompilerArtifacts, defaultCompilerOptions, KvkFileWriter, KeymanCompilerArtifactOptional } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboardXMLSourceFileReader, LDMLKeyboard, LDMLKeyboardTestDataXMLSourceFile, KMXBuilder, } from "@keymanapp/developer-utils"
|
||||
import { LdmlCompilerOptions } from './ldml-compiler-options.js';
|
||||
import { LdmlCompilerMessages } from './ldml-compiler-messages.js';
|
||||
import { BkspCompiler, TranCompiler } from './tran.js';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlus, LDMLKeyboard } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboard } from '@keymanapp/developer-utils';
|
||||
import { KMXPlus } from "@keymanapp/common-types";
|
||||
|
||||
import { LdmlCompilerMessages } from "./ldml-compiler-messages.js";
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { SectionIdent, constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
import { util, LDMLKeyboard, KMXPlus, CompilerCallbacks, MarkerParser } from "@keymanapp/common-types";
|
||||
import { util, KMXPlus, MarkerParser, CompilerCallbacks } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
import { VarsCompiler } from './vars.js';
|
||||
import { LdmlCompilerMessages } from './ldml-compiler-messages.js';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { CompilerCallbacks, VisualKeyboard, LDMLKeyboard, KeymanFileTypes } from "@keymanapp/common-types";
|
||||
import { TouchLayoutFileWriter } from "@keymanapp/developer-utils";
|
||||
import { CompilerCallbacks, VisualKeyboard, KeymanFileTypes } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard, TouchLayoutFileWriter } from "@keymanapp/developer-utils";
|
||||
import { LdmlCompilerOptions } from "./ldml-compiler-options.js";
|
||||
import { TouchLayoutCompiler } from "./touch-layout-compiler.js";
|
||||
import { LdmlKeyboardVisualKeyboardCompiler } from "./visual-keyboard-compiler.js";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { SectionIdent, constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { LDMLKeyboard, KMXPlus, Constants } from '@keymanapp/common-types';
|
||||
import { KMXPlus, Constants } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboard } from '@keymanapp/developer-utils';
|
||||
import { LdmlCompilerMessages } from './ldml-compiler-messages.js';
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { CompilerOptions, LDMLKeyboardXMLSourceFileReaderOptions } from "@keymanapp/common-types";
|
||||
import { CompilerOptions } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboardXMLSourceFileReaderOptions } from "@keymanapp/developer-utils";
|
||||
|
||||
/**
|
||||
* @public
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { LDMLKeyboard, KMXPlus, CompilerCallbacks } from "@keymanapp/common-types";
|
||||
import { CompilerCallbacks, KMXPlus } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
|
||||
/** newable interface to Linter c'tor */
|
||||
export type LinterNew = new (source: LDMLKeyboard.LDMLKeyboardXMLSourceFile, kmx: KMXPlus.KMXPlusFile, callbacks: CompilerCallbacks) => Linter;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { LDMLKeyboard, KMXPlus } from '@keymanapp/common-types';
|
||||
import { KMXPlus } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboard } from '@keymanapp/developer-utils';
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
import { LdmlCompilerMessages } from "./ldml-compiler-messages.js";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { LDMLKeyboard, KMXPlus, CompilerCallbacks } from "@keymanapp/common-types";
|
||||
import { KMXPlus, CompilerCallbacks } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
import { SectionIdent, constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
|
||||
/** newable interface to SectionCompiler c'tor */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { TouchLayout, LDMLKeyboard } from "@keymanapp/common-types";
|
||||
import { TouchLayout } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
|
||||
export class TouchLayoutCompiler {
|
||||
public compileToJavascript(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile): TouchLayout.TouchLayoutFile {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { constants, SectionIdent } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { util, KMXPlus, LDMLKeyboard, CompilerCallbacks, VariableParser, MarkerParser } from '@keymanapp/common-types';
|
||||
import { KMXPlus, VariableParser, MarkerParser, util, CompilerCallbacks } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
|
||||
import Bksp = KMXPlus.Bksp;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { SectionIdent, constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlus, LDMLKeyboard, CompilerCallbacks, MarkerParser } from '@keymanapp/common-types';
|
||||
import { VariableParser } from '@keymanapp/common-types';
|
||||
import { KMXPlus, VariableParser, MarkerParser, CompilerCallbacks } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboard, } from '@keymanapp/developer-utils';
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
import Vars = KMXPlus.Vars;
|
||||
import StringVarItem = KMXPlus.StringVarItem;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { VisualKeyboard, LDMLKeyboard, CompilerCallbacks } from "@keymanapp/common-types";
|
||||
import { VisualKeyboard, CompilerCallbacks } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
import { KeysCompiler } from "./keys.js";
|
||||
import { LdmlCompilerMessages } from "./ldml-compiler-messages.js";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { LDMLKeyboard } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard } from "@keymanapp/developer-utils";
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
/**
|
||||
* Verifies that value is an item in the enumeration.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ import 'mocha';
|
|||
import * as path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { SectionCompiler, SectionCompilerNew } from '../../src/compiler/section-compiler.js';
|
||||
import { util, KMXPlus, LDMLKeyboardXMLSourceFileReader, VisualKeyboard, CompilerEvent, LDMLKeyboardTestDataXMLSourceFile, compilerEventFormat, LDMLKeyboard, UnicodeSetParser, CompilerCallbacks } from '@keymanapp/common-types';
|
||||
import { util, KMXPlus, UnicodeSetParser, VisualKeyboard, CompilerEvent, compilerEventFormat, CompilerCallbacks } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboardXMLSourceFileReader, LDMLKeyboardTestDataXMLSourceFile, LDMLKeyboard, } from "@keymanapp/developer-utils";
|
||||
import { LdmlKeyboardCompiler } from '../../src/main.js'; // make sure main.js compiles
|
||||
import { assert } from 'chai';
|
||||
import { KMXPlusMetadataCompiler } from '../../src/compiler/metadata-compiler.js';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'mocha';
|
||||
import {assert} from 'chai';
|
||||
import hextobin from '@keymanapp/hextobin';
|
||||
import { KMXBuilder } from '@keymanapp/common-types';
|
||||
import { KMXBuilder } from '@keymanapp/developer-utils';
|
||||
import {checkMessages, compileKeyboard, compilerTestCallbacks, compilerTestOptions, makePathToFixture} from './helpers/index.js';
|
||||
import { LdmlKeyboardCompiler } from '../src/compiler/compiler.js';
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
isValidEnumValue, calculateUniqueKeys, allUsedKeyIdsInLayers,
|
||||
translateLayerAttrToModifier, validModifier, verifyValidAndUnique } from '../src/util/util.js';
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { LDMLKeyboard } from '@keymanapp/common-types';
|
||||
import { LDMLKeyboard } from '@keymanapp/developer-utils';
|
||||
|
||||
describe('test of util/util.ts', () => {
|
||||
describe('isValidEnumValue()', () => {
|
||||
|
|
|
|||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -504,7 +504,8 @@
|
|||
"name": "@keymanapp/developer-utils",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@sentry/node": "^7.57.0"
|
||||
"@sentry/node": "^7.57.0",
|
||||
"restructure": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.4.1",
|
||||
|
|
@ -12615,7 +12616,8 @@
|
|||
"node_modules/restructure": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.1.tgz",
|
||||
"integrity": "sha512-6neDpI/yE9eogQo22qmWwKIA9wFPRyYjQleDEh6zaNAf2ZPqLJYUvNBJBWEWNoBlCeQMQkvIOe2YI/K2GOag+g=="
|
||||
"integrity": "sha512-6neDpI/yE9eogQo22qmWwKIA9wFPRyYjQleDEh6zaNAf2ZPqLJYUvNBJBWEWNoBlCeQMQkvIOe2YI/K2GOag+g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/retry": {
|
||||
"version": "0.12.0",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue