From 7b094f42e741c6ba3655e7b8255ff335a4efe454 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 11 Jul 2023 18:08:46 -0500 Subject: [PATCH 1/2] =?UTF-8?q?chore(common):=20add=20BUILDER=5FSTR=5FREF?= =?UTF-8?q?=20=20=F0=9F=99=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - and similar - also aliases for r.uint32le on the KMXPlusFile side. Fixes #9079 --- .../src/kmx/kmx-plus-builder/build-disp.ts | 8 +- .../src/kmx/kmx-plus-builder/build-elem.ts | 13 ++- .../src/kmx/kmx-plus-builder/build-keys.ts | 20 ++-- .../src/kmx/kmx-plus-builder/build-layr.ts | 4 +- .../src/kmx/kmx-plus-builder/build-list.ts | 13 ++- .../src/kmx/kmx-plus-builder/build-loca.ts | 4 +- .../src/kmx/kmx-plus-builder/build-meta.ts | 14 +-- .../src/kmx/kmx-plus-builder/build-name.ts | 4 +- .../src/kmx/kmx-plus-builder/build-strs.ts | 9 +- .../src/kmx/kmx-plus-builder/build-tran.ts | 16 +-- .../src/kmx/kmx-plus-builder/build-uset.ts | 10 +- .../src/kmx/kmx-plus-builder/build-vars.ts | 16 +-- .../kmx/kmx-plus-builder/builder-section.ts | 3 +- .../kmx/kmx-plus-builder/kmx-plus-builder.ts | 2 +- common/web/types/src/kmx/kmx-plus.ts | 102 ++++++++++-------- 15 files changed, 131 insertions(+), 107 deletions(-) diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-disp.ts b/common/web/types/src/kmx/kmx-plus-builder/build-disp.ts index 512bcca0b2..117fae2be1 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-disp.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-disp.ts @@ -1,6 +1,6 @@ import { constants } from '@keymanapp/ldml-keyboard-constants'; import { KMXPlusData } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from './builder-section.js'; /* ------------------------------------------------------------------ @@ -11,13 +11,13 @@ import { BUILDER_SECTION } from './builder-section.js'; * Builder for the 'disp' section */ interface BUILDER_DISP_ITEM { - to: number; - display: number; + to: BUILDER_STR_REF; + display: BUILDER_STR_REF; }; export interface BUILDER_DISP extends BUILDER_SECTION { count: number; - baseCharacter: number; + baseCharacter: BUILDER_STR_REF; items: BUILDER_DISP_ITEM[]; }; diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts b/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts index ed4a39c93d..47ab438e24 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts @@ -1,16 +1,19 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { ElementString } from "../element-string.js"; import { Elem } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; -import { build_uset_index, BUILDER_USET } from "./build-uset.js"; +import { build_uset_index, BUILDER_USET, BUILDER_USET_REF } from "./build-uset.js"; /* ------------------------------------------------------------------ * elem section ------------------------------------------------------------------ */ +/** return from build_elem_index */ +export type BUILDER_ELEM_REF = number; + interface BUILDER_ELEM_ELEMENT { - element: number; // str | UTF-32 char + element: BUILDER_STR_REF | BUILDER_USET_REF | number; // str | UTF-32 char flags: number; _value: string; }; @@ -98,7 +101,7 @@ export function build_elem(source_elem: Elem, sect_strs: BUILDER_STRS, sect_uset return result; } -export function build_elem_index(sect_elem: BUILDER_ELEM, value: ElementString) { +export function build_elem_index(sect_elem: BUILDER_ELEM, value: ElementString) : BUILDER_ELEM_REF{ if(!(value instanceof ElementString)) { throw new Error('unexpected value '+value); } @@ -107,5 +110,5 @@ export function build_elem_index(sect_elem: BUILDER_ELEM, value: ElementString) if(result < 0) { throw new Error('unexpectedly missing StrsItem '+value); } - return result; + return result; } diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts b/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts index 0e9d38e908..2e91c6b357 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts @@ -1,8 +1,8 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KeysFlick, KMXPlusData, StrsItem } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; -import { build_list_index, BUILDER_LIST } from "./build-list.js"; +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 } from "./builder-section.js"; /* ------------------------------------------------------------------ @@ -15,13 +15,13 @@ import { BUILDER_SECTION } from "./builder-section.js"; interface BUILDER_KEYS_KEY { to: number; // str or single codepoint flags: number; - id: number; // str with original key id + id: BUILDER_STR_REF; // str with original key id _id: string; // original key id, for sorting - switch: number; // str with layer of new l + switch: BUILDER_STR_REF; // str with layer of new l width: number; // ceil((width||1)*10), so 12 for width 1.2 - longPress: number; // list of longPress sequences - longPressDefault: number; // str with the default longPress target - multiTap: number; // list of multiTap sequences + longPress: BUILDER_LIST_REF; // list of longPress sequences + longPressDefault: BUILDER_STR_REF; // str with the default longPress target + multiTap: BUILDER_LIST_REF; // list of multiTap sequences flicks: number; // index into the flicks[] subtable for this flick list }; @@ -31,7 +31,7 @@ interface BUILDER_KEYS_KEY { interface BUILDER_KEYS_FLICKS { count: number; // number of BUILDER_KEYS_FLICK entries in this flick list flick: number; // index into the flick[] subtable of the first flick in the list - id: number; // str with the original id of this flicks + id: BUILDER_STR_REF; // str with the original id of this flicks _id: string; // copy of the flicks id, used for sorting during build _flicks: KeysFlick[]; // temporary copy of KeysFlick object }; @@ -40,9 +40,9 @@ interface BUILDER_KEYS_FLICKS { * This is a single element. */ interface BUILDER_KEYS_FLICK { - directions: number; // list of cardinal/intercardinal directions + directions: BUILDER_LIST_REF; // list of cardinal/intercardinal directions flags: number; // - to: number; // str or single codepoint + to: BUILDER_STR_REF | number; // str or single codepoint }; diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-layr.ts b/common/web/types/src/kmx/kmx-plus-builder/build-layr.ts index da4e79f38f..057158f186 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-layr.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-layr.ts @@ -1,7 +1,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData, LayrEntry, LayrRow, StrsItem } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +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"; @@ -24,7 +24,7 @@ interface BUILDER_LAYR_LIST { * element */ interface BUILDER_LAYR_LAYER { - id: number; // str of layer id + id: BUILDER_STR_REF; // str of layer id _id: string; // original layer id, for sorting mod: number; // bitfield with modifier info row: number; // row index into row subtable diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-list.ts b/common/web/types/src/kmx/kmx-plus-builder/build-list.ts index a1ed950463..e770e7b278 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-list.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-list.ts @@ -1,13 +1,16 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { List, ListItem } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; /* ------------------------------------------------------------------ * list section ------------------------------------------------------------------ */ -/** +/** reference from build_list_index */ +export type BUILDER_LIST_REF = number; + + /** * A list entry. */ interface BUILDER_LIST_LIST { @@ -17,7 +20,7 @@ interface BUILDER_LIST_LIST { }; interface BUILDER_LIST_INDEX { - str: number; // str for this string + str: BUILDER_STR_REF; // str for this string _value: string; // for locating this string during finalization }; @@ -82,7 +85,7 @@ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_ * @param value * @returns */ -export function build_list_index(sect_list: BUILDER_LIST, value: ListItem) { +export function build_list_index(sect_list: BUILDER_LIST, value: ListItem) : BUILDER_LIST_REF { if(!(value instanceof ListItem)) { throw new Error('unexpected value '+ value); } @@ -91,5 +94,5 @@ export function build_list_index(sect_list: BUILDER_LIST, value: ListItem) { if(result < 0) { throw new Error('unexpectedly missing ListItem ' + value); // TODO-LDML: it's an array of strs } - return result; + return result; } diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-loca.ts b/common/web/types/src/kmx/kmx-plus-builder/build-loca.ts index e7d3198fc2..9a72402c8c 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-loca.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-loca.ts @@ -5,7 +5,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; /** @@ -13,7 +13,7 @@ import { BUILDER_SECTION } from "./builder-section.js"; */ export interface BUILDER_LOCA extends BUILDER_SECTION { count: number; - items: number[]; //str[] + items: BUILDER_STR_REF[]; //str[] }; export function build_loca(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_LOCA { diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-meta.ts b/common/web/types/src/kmx/kmx-plus-builder/build-meta.ts index 5c60472f35..c1633aeca7 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-meta.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-meta.ts @@ -5,19 +5,19 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; /** * Builder for the 'meta' section */ export interface BUILDER_META extends BUILDER_SECTION { - author: number; //str - conform: number; //str - layout: number; //str - normalization: number; //str - indicator: number; //str - version: number; //str + author: BUILDER_STR_REF; //str + conform: BUILDER_STR_REF; //str + layout: BUILDER_STR_REF; //str + normalization: BUILDER_STR_REF; //str + indicator: BUILDER_STR_REF; //str + version: BUILDER_STR_REF; //str settings: number; //bitfield }; diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-name.ts b/common/web/types/src/kmx/kmx-plus-builder/build-name.ts index 9397ff0b0a..9463d15204 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-name.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-name.ts @@ -5,7 +5,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; /** @@ -13,7 +13,7 @@ import { BUILDER_SECTION } from "./builder-section.js"; */ export interface BUILDER_NAME extends BUILDER_SECTION { count: number; - items: number[]; //str[] + items: BUILDER_STR_REF[]; }; export function build_name(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_NAME { diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts b/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts index c136647528..57c38c1f40 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts @@ -2,6 +2,9 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { Strs, StrsItem } from "../kmx-plus.js"; import { BUILDER_SECTION } from "./builder-section.js"; +/** reference from build_strs_index */ +export type BUILDER_STR_REF = number; + /* ------------------------------------------------------------------ * strs section ------------------------------------------------------------------ */ @@ -48,7 +51,7 @@ export function build_strs(source_strs: Strs): BUILDER_STRS { /** * @returns str index, or UTF-32 char if value.char is set (single char) */ -export function build_strs_index(sect_strs: BUILDER_STRS, value: StrsItem) { +export function build_strs_index(sect_strs: BUILDER_STRS, value: StrsItem) : BUILDER_STR_REF { if(!(value instanceof StrsItem)) { if (value === null) { throw new Error('unexpected null StrsItem, use an empty string instead'); @@ -58,12 +61,12 @@ export function build_strs_index(sect_strs: BUILDER_STRS, value: StrsItem) { } if(value.isOneChar) { - return value.char; + return value.char; } let result = sect_strs.items.findIndex(v => v._value === value.value); if(result < 0) { throw new Error('unexpectedly missing StrsItem '+value.value); } - return result; + return result; } diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-tran.ts b/common/web/types/src/kmx/kmx-plus-builder/build-tran.ts index 11f819f360..316df69853 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-tran.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-tran.ts @@ -1,8 +1,8 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { Bksp, Tran } from "../kmx-plus.js"; -import { BUILDER_ELEM, build_elem_index } from "./build-elem.js"; -import { BUILDER_STRS, build_strs_index } from "./build-strs.js"; +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"; /* ------------------------------------------------------------------ @@ -16,15 +16,15 @@ interface BUILDER_TRAN_GROUP { }; interface BUILDER_TRAN_TRANSFORM { - from: number; //str - to: number; //str - mapFrom: number; // elem - mapTo: number; // elem + from: BUILDER_STR_REF; //str + to: BUILDER_STR_REF; //str + mapFrom: BUILDER_ELEM_REF; // elem + mapTo: BUILDER_ELEM_REF; // elem }; interface BUILDER_TRAN_REORDER { - elements: number; //elem - before: number; //elem + elements: BUILDER_ELEM_REF; //elem + before: BUILDER_ELEM_REF; //elem }; export interface BUILDER_TRAN extends BUILDER_SECTION { diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts b/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts index 7255b23ef7..05460f3176 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts @@ -1,19 +1,21 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData, StrsItem, UsetItem } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; +/** reference from build_uset_index */ +export type BUILDER_USET_REF = number; interface BUILDER_USET_USET { range: number; count: number; - pattern: number; // str + pattern: BUILDER_STR_REF; _pattern: StrsItem; // for sorting }; interface BUILDER_USET_RANGE { - start: number; - end: number; + start: number; // uchar32 + end: number; // uchar32 } export interface BUILDER_USET extends BUILDER_SECTION { diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-vars.ts b/common/web/types/src/kmx/kmx-plus-builder/build-vars.ts index 41111f7cf6..25c7f174ec 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-vars.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-vars.ts @@ -1,18 +1,20 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData } from "../kmx-plus.js"; -import { build_strs_index, BUILDER_STRS } from "./build-strs.js"; +import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; import { BUILDER_SECTION } from "./builder-section.js"; +import { BUILDER_LIST_REF } from "./build-list.js"; +import { /*build_elem_index, BUILDER_ELEM,*/ BUILDER_ELEM_REF } from "./build-elem.js"; interface BUILDER_VARS_ITEM { type: number; - id: number; // str - value: number; // str - elem?: number; // elem, TODO-LDML + id: BUILDER_STR_REF; // str + value: BUILDER_STR_REF; // str + elem?: BUILDER_ELEM_REF; // elem }; export interface BUILDER_VARS extends BUILDER_SECTION { - markers: number; // list, TODO-LDML + markers: BUILDER_LIST_REF; varCount: number; varEntries: BUILDER_VARS_ITEM[]; }; @@ -20,7 +22,7 @@ export interface BUILDER_VARS extends BUILDER_SECTION { /** * Builder for the 'vars' section */ -export function build_vars(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS /*, sect_elem: BUILDER_ELEM*/) : BUILDER_VARS { +export function build_vars(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS /*, sect_elem: BUILDER_ELEM */) : BUILDER_VARS { if(!kmxplus.vars) { return null; } @@ -34,6 +36,8 @@ export function build_vars(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS /*, sec type: constants.vars_entry_type_set, id: build_strs_index(sect_strs, v.id), value: build_strs_index(sect_strs, v.value), + // TODO-LDML: elem + // elem: build_elem_index(sect_elem, v.items), }); const uniSetVars = kmxplus.vars.unicodeSets.map(v => { type: constants.vars_entry_type_unicodeSet, diff --git a/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts b/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts index 1a6108af4e..714b118f56 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts @@ -1,5 +1,6 @@ +export type BUILDER_IDENT = number; export interface BUILDER_SECTION { - ident: number; + ident: BUILDER_IDENT; size: number; _offset: number; // used only for building the output } diff --git a/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts b/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts index 641868908b..74f363011f 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts @@ -99,7 +99,7 @@ export default class KMXPlusBuilder { this.sect.name = build_name(this.file.kmxplus, this.sect.strs); this.sect.tran = build_tran(this.file.kmxplus.tran, this.sect.strs, this.sect.elem); this.sect.uset = build_uset(this.file.kmxplus, this.sect.strs); - this.sect.vars = build_vars(this.file.kmxplus, this.sect.strs); + this.sect.vars = build_vars(this.file.kmxplus, this.sect.strs, /*TODO-LDML: this.sect.elem*/); this.sect.vkey = build_vkey(this.file.kmxplus); // Finalize the sect (index) section diff --git a/common/web/types/src/kmx/kmx-plus.ts b/common/web/types/src/kmx/kmx-plus.ts index 90942f7f41..9ca0a13ad7 100644 --- a/common/web/types/src/kmx/kmx-plus.ts +++ b/common/web/types/src/kmx/kmx-plus.ts @@ -639,6 +639,14 @@ export class KMXPlusFile extends KMXFile { super(); // Binary-correct structures matching kmx_plus.h + // helpers + const STR_REF = r.uint32le; + const ELEM_REF = r.uint32le; + const LIST_REF = r.uint32le; + const STR_OR_CHAR32 = r.uint32le; + const CHAR32 = r.uint32le; + const STR_OR_CHAR32_OR_USET = r.uint32le; + const IDENT = r.uint32le; // 'sect' this.COMP_PLUS_SECT_ITEM = new r.Struct({ @@ -647,7 +655,7 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_SECT = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, total: r.uint32le, count: r.uint32le, @@ -658,22 +666,22 @@ export class KMXPlusFile extends KMXFile { // 'disp' this.COMP_PLUS_DISP_ITEM = new r.Struct({ - to: r.uint32le, - display: r.uint32le, + to: STR_REF, + display: STR_REF, }); this.COMP_PLUS_DISP = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, count: r.uint32le, - baseCharacter: r.uint32le, + baseCharacter: CHAR32, items: new r.Array(this.COMP_PLUS_DISP_ITEM, 'count'), }); // 'elem' this.COMP_PLUS_ELEM_ELEMENT = new r.Struct({ - element: r.uint32le, + element: STR_OR_CHAR32_OR_USET, flags: r.uint32le }); @@ -683,7 +691,7 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_ELEM = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, count: r.uint32le, strings: new r.Array(this.COMP_PLUS_ELEM_STRING, 'count') @@ -720,7 +728,7 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_LAYR = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, listCount: r.uint32le, layerCount: r.uint32le, @@ -733,26 +741,26 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_KEYS_FLICK = new r.Struct({ - directions: r.uint32le, // list + directions: LIST_REF, // list flags: r.uint32le, - to: r.uint32le, // str | codepoint + to: STR_OR_CHAR32, // str | codepoint }); this.COMP_PLUS_KEYS_FLICKS = new r.Struct({ count: r.uint32le, flick: r.uint32le, - id: r.uint32le, // str + id: STR_REF, // str }); this.COMP_PLUS_KEYS_KEY = new r.Struct({ - to: r.uint32le, // str | codepoint + to: STR_OR_CHAR32, // str | codepoint flags: r.uint32le, - id: r.uint32le, // str - switch: r.uint32le, // str + id: STR_REF, // str + switch: STR_REF, // str width: r.uint32le, // width*10 ( 1 = 0.1 keys) - longPress: r.uint32le, // list index - longPressDefault: r.uint32le, // str - multiTap: r.uint32le, // list index + longPress: LIST_REF, // list index + longPressDefault: STR_REF, // str + multiTap: LIST_REF, // list index flicks: r.uint32le, // index into flicks table }); @@ -763,7 +771,7 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_KEYS = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, keyCount: r.uint32le, flicksCount: r.uint32le, @@ -783,11 +791,11 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_LIST_INDEX = new r.Struct({ - str: r.uint32le, // str + str: STR_REF, // str }); this.COMP_PLUS_LIST = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, listCount: r.uint32le, indexCount: r.uint32le, @@ -800,7 +808,7 @@ export class KMXPlusFile extends KMXFile { this.COMP_PLUS_LOCA_ITEM = r.uint32le; //str this.COMP_PLUS_LOCA = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, count: r.uint32le, items: new r.Array(this.COMP_PLUS_LOCA_ITEM, 'count') @@ -809,14 +817,14 @@ export class KMXPlusFile extends KMXFile { // 'meta' this.COMP_PLUS_META = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, - author: r.uint32le, //str - conform: r.uint32le, //str - layout: r.uint32le, //str - normalization: r.uint32le, //str - indicator: r.uint32le, //str - version: r.uint32le, //str + author: STR_REF, //str + conform: STR_REF, //str + layout: STR_REF, //str + normalization: STR_REF, //str + indicator: STR_REF, //str + version: STR_REF, //str settings: r.uint32le, //new r.Bitfield(r.uint32le, ['fallback', 'transformFailure', 'transformPartial']) }); @@ -825,7 +833,7 @@ export class KMXPlusFile extends KMXFile { this.COMP_PLUS_NAME_ITEM = r.uint32le; //str this.COMP_PLUS_NAME = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, count: r.uint32le, items: new r.Array(this.COMP_PLUS_NAME_ITEM, 'count') @@ -843,7 +851,7 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_STRS = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, count: r.uint32le, items: new r.Array(this.COMP_PLUS_STRS_ITEM, 'count') @@ -859,19 +867,19 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_TRAN_TRANSFORM = new r.Struct({ - from: r.uint32le, //str - to: r.uint32le, //str - mapFrom: r.uint32le, //elem - mapTo: r.uint32le //elem + from: STR_REF, //str + to: STR_REF, //str + mapFrom: ELEM_REF, //elem + mapTo: ELEM_REF //elem }); this.COMP_PLUS_TRAN_REORDER = new r.Struct({ - elements: r.uint32le, //elem - before: r.uint32le, //elem + elements: ELEM_REF, //elem + before: ELEM_REF, //elem }); this.COMP_PLUS_TRAN = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, groupCount: r.uint32le, transformCount: r.uint32le, @@ -885,16 +893,16 @@ export class KMXPlusFile extends KMXFile { this.COMP_PLUS_USET_USET = new r.Struct({ range: r.uint32le, count: r.uint32le, - pattern: r.uint32le, // str + pattern: STR_REF, // str }); this.COMP_PLUS_USET_RANGE = new r.Struct({ - start: r.uint32le, - end: r.uint32le, + start: CHAR32, + end: CHAR32, }); this.COMP_PLUS_USET = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, usetCount: r.uint32le, rangeCount: r.uint32le, @@ -906,15 +914,15 @@ export class KMXPlusFile extends KMXFile { this.COMP_PLUS_VARS_ITEM = new r.Struct({ type: r.uint32le, - id: r.uint32le, // str - value: r.uint32le, // str - elem: r.uint32le, // elem TODO-LDML + id: STR_REF, // str + value: STR_REF, // str + elem: ELEM_REF, }); this.COMP_PLUS_VARS = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, - markers: r.uint32le, // list TODO-LDML + markers: LIST_REF, varCount: r.uint32le, varEntries: new r.Array(this.COMP_PLUS_VARS_ITEM, 'varCount'), }); @@ -927,7 +935,7 @@ export class KMXPlusFile extends KMXFile { }); this.COMP_PLUS_VKEY = new r.Struct({ - ident: r.uint32le, + ident: IDENT, size: r.uint32le, count: r.uint32le, items: new r.Array(this.COMP_PLUS_VKEY_ITEM, 'count') From 3268be0c342b3027dd64aa707b8bd362a8829eb7 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Fri, 14 Jul 2023 12:42:35 -0500 Subject: [PATCH 2/2] =?UTF-8?q?chore(common):=20add=20BUILDER=5FU32CHAR=20?= =?UTF-8?q?=20=F0=9F=99=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fix some other minor nits and documentation todos (no semantics) - BUILDER_KEYS accidentally repeated 'ident' and 'size' from the parent interface Fixes #9079 --- common/web/types/src/kmx/kmx-plus-builder/build-elem.ts | 4 ++-- common/web/types/src/kmx/kmx-plus-builder/build-keys.ts | 6 ++---- common/web/types/src/kmx/kmx-plus-builder/build-strs.ts | 2 +- common/web/types/src/kmx/kmx-plus-builder/build-uset.ts | 6 +++--- .../web/types/src/kmx/kmx-plus-builder/builder-section.ts | 4 ++++ .../web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts | 1 - 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts b/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts index 47ab438e24..8e325f9591 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-elem.ts @@ -2,7 +2,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { ElementString } from "../element-string.js"; import { Elem } from "../kmx-plus.js"; import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; -import { BUILDER_SECTION } from "./builder-section.js"; +import { BUILDER_SECTION, BUILDER_U32CHAR } from "./builder-section.js"; import { build_uset_index, BUILDER_USET, BUILDER_USET_REF } from "./build-uset.js"; /* ------------------------------------------------------------------ @@ -13,7 +13,7 @@ import { build_uset_index, BUILDER_USET, BUILDER_USET_REF } from "./build-uset.j export type BUILDER_ELEM_REF = number; interface BUILDER_ELEM_ELEMENT { - element: BUILDER_STR_REF | BUILDER_USET_REF | number; // str | UTF-32 char + element: BUILDER_STR_REF | BUILDER_USET_REF | BUILDER_U32CHAR; // str | UTF-32 char flags: number; _value: string; }; diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts b/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts index 2e91c6b357..d9d30e8683 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-keys.ts @@ -3,7 +3,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KeysFlick, KMXPlusData, StrsItem } from "../kmx-plus.js"; 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 } from "./builder-section.js"; +import { BUILDER_SECTION, BUILDER_U32CHAR } from "./builder-section.js"; /* ------------------------------------------------------------------ * keys section @@ -13,7 +13,7 @@ import { BUILDER_SECTION } from "./builder-section.js"; * This struct is a single in the keys keybag */ interface BUILDER_KEYS_KEY { - to: number; // str or single codepoint + to: BUILDER_STR_REF | BUILDER_U32CHAR; // str or single codepoint flags: number; id: BUILDER_STR_REF; // str with original key id _id: string; // original key id, for sorting @@ -56,8 +56,6 @@ interface BUILDER_KEYS_KMAP { * Builder for the 'keys' section */ export interface BUILDER_KEYS extends BUILDER_SECTION { - ident: number; - size: number; keyCount: number; flicksCount: number; flickCount: number; diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts b/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts index 57c38c1f40..503de2d404 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-strs.ts @@ -14,7 +14,7 @@ interface BUILDER_STRS_ITEM { // we always write a null terminator, so we can get restructure to do that for us here offset: number; //? new r.Pointer(r.uint32le, new r.String(null, 'utf16le')), length: number; // in UTF-16 code units - _value: string + _value: string; // in-memory: for finding and sorting }; /** diff --git a/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts b/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts index 05460f3176..8c73afb796 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/build-uset.ts @@ -1,7 +1,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants"; import { KMXPlusData, StrsItem, UsetItem } from "../kmx-plus.js"; import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js"; -import { BUILDER_SECTION } from "./builder-section.js"; +import { BUILDER_SECTION, BUILDER_U32CHAR } from "./builder-section.js"; /** reference from build_uset_index */ export type BUILDER_USET_REF = number; @@ -14,8 +14,8 @@ interface BUILDER_USET_USET { }; interface BUILDER_USET_RANGE { - start: number; // uchar32 - end: number; // uchar32 + start: BUILDER_U32CHAR; // uchar32 + end: BUILDER_U32CHAR; // uchar32 } export interface BUILDER_USET extends BUILDER_SECTION { diff --git a/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts b/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts index 714b118f56..a6d81fd25e 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/builder-section.ts @@ -1,4 +1,8 @@ +/** for a 4-byte section identity */ export type BUILDER_IDENT = number; +/** for a single UTF-32 character (Unicode codepoint) */ +export type BUILDER_U32CHAR = number; + export interface BUILDER_SECTION { ident: BUILDER_IDENT; size: number; diff --git a/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts b/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts index 001223697e..082e5495eb 100644 --- a/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts +++ b/common/web/types/src/kmx/kmx-plus-builder/kmx-plus-builder.ts @@ -187,5 +187,4 @@ export default class KMXPlusBuilder { } } } - }