@keymanapp/common-types
Version:
Keyman Developer keyboard file types
325 lines (323 loc) • 14.4 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a0fa81e6-5866-5723-9335-f956b27108ac")}catch(e){}}();
import * as r from 'restructure';
import { ModifierKeyConstants } from '../consts/modifier-key-constants.js';
/* Definitions from kmx_file.h. Must be kept in sync */
// TODO: split kmx-file from kmx in-memory, similar to what I've done for kvk (keep restructure decl + BUILDER_ interfaces together)
// In memory representations of KMX structures
// kmx-builder will transform these to the corresponding COMP_xxxx
export var KMX_Version;
(function (KMX_Version) {
KMX_Version[KMX_Version["VERSION_30"] = 768] = "VERSION_30";
KMX_Version[KMX_Version["VERSION_31"] = 769] = "VERSION_31";
KMX_Version[KMX_Version["VERSION_32"] = 770] = "VERSION_32";
KMX_Version[KMX_Version["VERSION_40"] = 1024] = "VERSION_40";
KMX_Version[KMX_Version["VERSION_50"] = 1280] = "VERSION_50";
KMX_Version[KMX_Version["VERSION_501"] = 1281] = "VERSION_501";
KMX_Version[KMX_Version["VERSION_60"] = 1536] = "VERSION_60";
KMX_Version[KMX_Version["VERSION_70"] = 1792] = "VERSION_70";
KMX_Version[KMX_Version["VERSION_80"] = 2048] = "VERSION_80";
KMX_Version[KMX_Version["VERSION_90"] = 2304] = "VERSION_90";
KMX_Version[KMX_Version["VERSION_100"] = 2560] = "VERSION_100";
KMX_Version[KMX_Version["VERSION_140"] = 3584] = "VERSION_140";
KMX_Version[KMX_Version["VERSION_150"] = 3840] = "VERSION_150";
KMX_Version[KMX_Version["VERSION_160"] = 4096] = "VERSION_160";
KMX_Version[KMX_Version["VERSION_170"] = 4352] = "VERSION_170";
})(KMX_Version || (KMX_Version = {}));
;
export class KEYBOARD {
fileVersion; // dwFileVersion (TSS_FILEVERSION)
startGroup = { ansi: -1, unicode: -1, newContext: -1, postKeystroke: -1 };
flags;
hotkey;
//bitmap:
groups = [];
stores = [];
// Following values are extracted from stores[] but are
// informative only
keyboardVersion; // version (TSS_KEYBOARDVERSION)
isMnemonic; // TSS_MNEMONICLAYOUT store
targets; // TSS_TARGETS store ('desktop' if missing)
}
;
export class STORE {
dwSystemID;
dpName;
dpString;
}
;
export class GROUP {
dpName;
keys = [];
dpMatch;
dpNoMatch;
fUsingKeys;
}
;
export class KEY {
Key;
Line;
ShiftFlags;
dpOutput;
dpContext;
}
;
;
;
;
;
;
export class KMXFile {
/* KMX file structures */
COMP_STORE;
COMP_KEY;
COMP_GROUP;
COMP_KEYBOARD_KMXPLUSINFO;
COMP_KEYBOARD;
static FILEID_COMPILED = 0x5354584B; // 'KXTS'
//
// File version identifiers (COMP_KEYBOARD.dwFileVersion)
//
static VERSION_30 = KMX_Version.VERSION_30;
static VERSION_31 = KMX_Version.VERSION_31;
static VERSION_32 = KMX_Version.VERSION_32;
static VERSION_40 = KMX_Version.VERSION_40;
static VERSION_50 = KMX_Version.VERSION_50;
static VERSION_501 = KMX_Version.VERSION_501;
static VERSION_60 = KMX_Version.VERSION_60;
static VERSION_70 = KMX_Version.VERSION_70;
static VERSION_80 = KMX_Version.VERSION_80;
static VERSION_90 = KMX_Version.VERSION_90;
static VERSION_100 = KMX_Version.VERSION_100;
static VERSION_140 = KMX_Version.VERSION_140;
static VERSION_150 = KMX_Version.VERSION_150;
static VERSION_160 = KMX_Version.VERSION_160;
static VERSION_170 = KMX_Version.VERSION_170;
static VERSION_MIN = this.VERSION_50;
static VERSION_MAX = this.VERSION_170;
//
// Backspace types
//
static BK_DEFAULT = 0;
static BK_DEADKEY = 1;
// Different begin types (COMP_STORE.StartGroup_*)
static BEGIN_ANSI = 0;
static BEGIN_UNICODE = 1;
//
// System Store values (COMP_STORE.dwSystemID)
//
static TSS_NONE = 0;
static TSS_BITMAP = 1;
static TSS_COPYRIGHT = 2;
static TSS_HOTKEY = 3;
static TSS_LANGUAGE = 4;
static TSS_LAYOUT = 5;
static TSS_MESSAGE = 6;
static TSS_NAME = 7;
static TSS_VERSION = 8;
static TSS_CAPSONONLY = 9;
static TSS_CAPSALWAYSOFF = 10;
static TSS_SHIFTFREESCAPS = 11;
static TSS_LANGUAGENAME = 12;
static TSS_CALLDEFINITION = 13;
static TSS_CALLDEFINITION_LOADFAILED = 14;
static TSS_ETHNOLOGUECODE = 15;
static TSS_DEBUG_LINE = 16;
static TSS_MNEMONIC = 17;
static TSS_INCLUDECODES = 18;
static TSS_OLDCHARPOSMATCHING = 19;
static TSS_COMPILEDVERSION = 20;
static TSS_KEYMANCOPYRIGHT = 21;
static TSS_CUSTOMKEYMANEDITION = 22;
static TSS_CUSTOMKEYMANEDITIONNAME = 23;
/* Keyman 7.0 system stores */
static TSS__KEYMAN_60_MAX = 23;
static TSS_VISUALKEYBOARD = 24;
static TSS_KMW_RTL = 25;
static TSS_KMW_HELPFILE = 26;
static TSS_KMW_HELPTEXT = 27;
static TSS_KMW_EMBEDJS = 28;
static TSS_WINDOWSLANGUAGES = 29;
static TSS__KEYMAN_70_MAX = 29;
/* Keyman 8.0 system stores */
static TSS_COMPARISON = 30;
static TSS__KEYMAN_80_MAX = 30;
/* Keyman 9.0 system stores */
static TSS_PLATFORM = 31;
static TSS_BASELAYOUT = 32;
static TSS_LAYER = 33;
static TSS_PLATFORM_NOMATCH = 0x8001; // Reserved for internal use - after platform statement is run, set to either TSS_PLATFORM_NOMATCH or TSS_PLATFORM_MATCH
static TSS_PLATFORM_MATCH = 0x8002; // Reserved for internal use - as the result will never change for the lifetime of the process.
static TSS_VKDICTIONARY = 34; // Dictionary of virtual key names for v9 dynamic layouts
static TSS_LAYOUTFILE = 35; // Keyman 9 layer-based JSON OSK
static TSS_KEYBOARDVERSION = 36; // &keyboardversion system store // I4140
static TSS_KMW_EMBEDCSS = 37;
static TSS_TARGETS = 38;
static TSS__KEYMAN_90_MAX = 38;
/* Keyman 14.0 system stores */
static TSS_CASEDKEYS = 39;
static TSS__KEYMAN_140_MAX = 39;
/* Keyman 15.0 system stores */
static TSS_BEGIN_NEWCONTEXT = 40;
static TSS_BEGIN_POSTKEYSTROKE = 41;
static TSS_NEWLAYER = 42;
static TSS_OLDLAYER = 43;
static TSS__KEYMAN_150_MAX = 43;
/* Keyman 17.0 system stores */
static TSS_DISPLAYMAP = 44;
static TSS__KEYMAN_170_MAX = 44;
static TSS__MAX = 44;
static UC_SENTINEL = 0xFFFF;
static UC_SENTINEL_EXTENDEDEND = 0x10;
static U_UC_SENTINEL = "\uFFFF";
//
// VK__MAX defines the highest virtual key code defined in the system = 0xFF. Custom VK codes start at 256
//
static VK__MAX = 255;
//
// Extended String CODE_ values
//
static CODE_ANY = 0x01;
static CODE_INDEX = 0x02;
static CODE_CONTEXT = 0x03;
static CODE_NUL = 0x04;
static CODE_USE = 0x05;
static CODE_RETURN = 0x06;
static CODE_BEEP = 0x07;
static CODE_DEADKEY = 0x08;
// 0x09 = bkspace.-- we don't need to keep this separate though with UC_SENTINEL
static CODE_EXTENDED = 0x0A;
//public static readonly CODE_EXTENDEDEND = 0x0B; deprecated
static CODE_SWITCH = 0x0C;
static CODE_KEY = 0x0D;
static CODE_CLEARCONTEXT = 0x0E;
static CODE_CALL = 0x0F;
// UC_SENTINEL_EXTENDEDEND 0x10
static CODE_CONTEXTEX = 0x11;
static CODE_NOTANY = 0x12;
static CODE_KEYMAN70_LASTCODE = 0x12;
static CODE_SETOPT = 0x13;
static CODE_IFOPT = 0x14;
static CODE_SAVEOPT = 0x15;
static CODE_RESETOPT = 0x16;
static CODE_KEYMAN80_LASTCODE = 0x16;
/* Keyman 9.0 codes */
static CODE_IFSYSTEMSTORE = 0x17;
static CODE_SETSYSTEMSTORE = 0x18;
static CODE_LASTCODE = 0x18;
static KF_SHIFTFREESCAPS = 0x0001;
static KF_CAPSONONLY = 0x0002;
static KF_CAPSALWAYSOFF = 0x0004;
static KF_LOGICALLAYOUT = 0x0008;
static KF_AUTOMATICVERSION = 0x0010;
// 16.0: Support for LDML Keyboards in KMXPlus file format
static KF_KMXPLUS = 0x0020;
static HK_ALT = 0x00010000;
static HK_CTRL = 0x00020000;
static HK_SHIFT = 0x00040000;
static LCTRLFLAG = ModifierKeyConstants.LCTRLFLAG; // Left Control flag
static RCTRLFLAG = ModifierKeyConstants.RCTRLFLAG; // Right Control flag
static LALTFLAG = ModifierKeyConstants.LALTFLAG; // Left Alt flag
static RALTFLAG = ModifierKeyConstants.RALTFLAG; // Right Alt flag
static K_SHIFTFLAG = ModifierKeyConstants.K_SHIFTFLAG; // Either shift flag
static K_CTRLFLAG = ModifierKeyConstants.K_CTRLFLAG; // Either ctrl flag
static K_ALTFLAG = ModifierKeyConstants.K_ALTFLAG; // Either alt flag
//public static readonly K_METAFLAG = 0x0080; // Either Meta-key flag (tentative). Not usable in keyboard rules;
// Used internally (currently, only by KMW) to ensure Meta-key
// shortcuts safely bypass rules
// Meta key = Command key on macOS, Windows key on Windows
static CAPITALFLAG = ModifierKeyConstants.CAPITALFLAG; // Caps lock on
static NOTCAPITALFLAG = ModifierKeyConstants.NOTCAPITALFLAG; // Caps lock NOT on
static NUMLOCKFLAG = ModifierKeyConstants.NUMLOCKFLAG; // Num lock on
static NOTNUMLOCKFLAG = ModifierKeyConstants.NOTNUMLOCKFLAG; // Num lock NOT on
static SCROLLFLAG = ModifierKeyConstants.SCROLLFLAG; // Scroll lock on
static NOTSCROLLFLAG = ModifierKeyConstants.NOTSCROLLFLAG; // Scroll lock NOT on
static ISVIRTUALKEY = ModifierKeyConstants.ISVIRTUALKEY; // It is a Virtual Key Sequence
static VIRTUALCHARKEY = ModifierKeyConstants.VIRTUALCHARKEY; // Keyman 6.0: Virtual Key Cap Sequence NOT YET
// Note: OTHER_MODIFIER = 0x10000, used by KMX+ for the
// other modifier flag in layers, > 16 bit so not available here.
// See keys_mod_other in keyman_core_ldml.ts
static MASK_MODIFIER_CHIRAL = KMXFile.LCTRLFLAG | KMXFile.RCTRLFLAG | KMXFile.LALTFLAG | KMXFile.RALTFLAG;
static MASK_MODIFIER_SHIFT = KMXFile.K_SHIFTFLAG;
static MASK_MODIFIER_NONCHIRAL = KMXFile.K_CTRLFLAG | KMXFile.K_ALTFLAG;
static MASK_STATEKEY = KMXFile.CAPITALFLAG | KMXFile.NOTCAPITALFLAG |
KMXFile.NUMLOCKFLAG | KMXFile.NOTNUMLOCKFLAG |
KMXFile.SCROLLFLAG | KMXFile.NOTSCROLLFLAG;
static MASK_KEYTYPE = KMXFile.ISVIRTUALKEY | KMXFile.VIRTUALCHARKEY;
static MASK_MODIFIER = KMXFile.MASK_MODIFIER_CHIRAL | KMXFile.MASK_MODIFIER_SHIFT | KMXFile.MASK_MODIFIER_NONCHIRAL;
static MASK_KEYS = KMXFile.MASK_MODIFIER | KMXFile.MASK_STATEKEY;
static KMX_MASK_VALID = KMXFile.MASK_KEYS | KMXFile.MASK_KEYTYPE;
static K_MODIFIERFLAG = 0x007F;
static K_NOTMODIFIERFLAG = 0xFF00; // I4548
static COMP_KEYBOARD_SIZE = 64;
static COMP_KEYBOARD_KMXPLUSINFO_SIZE = 8;
static COMP_STORE_SIZE = 12;
static COMP_GROUP_SIZE = 24;
static COMP_KEY_SIZE = 20;
static VERSION_MASK_MINOR = 0x00FF;
static VERSION_MASK_MAJOR = 0xFF00;
/* In-memory representation of the keyboard */
keyboard = new KEYBOARD();
constructor() {
// Binary-correct structures matching kmx_file.h
this.COMP_STORE = new r.Struct({
dwSystemID: r.uint32le,
dpName: r.uint32le,
dpString: r.uint32le
});
if (this.COMP_STORE.size() != KMXFile.COMP_STORE_SIZE) {
throw "COMP_STORE size is " + this.COMP_STORE.size() + " but should be " + KMXFile.COMP_STORE_SIZE + " bytes";
}
this.COMP_KEY = new r.Struct({
Key: r.uint16le,
_padding: new r.Reserved(r.uint16le), // padding
Line: r.uint32le,
ShiftFlags: r.uint32le,
dpOutput: r.uint32le,
dpContext: r.uint32le
});
if (this.COMP_KEY.size() != KMXFile.COMP_KEY_SIZE) {
throw "COMP_KEY size is " + this.COMP_KEY.size() + " but should be " + KMXFile.COMP_KEY_SIZE + " bytes";
}
this.COMP_GROUP = new r.Struct({
dpName: r.uint32le,
dpKeyArray: r.uint32le, // [LPKEY] address of first item in key array
dpMatch: r.uint32le,
dpNoMatch: r.uint32le,
cxKeyArray: r.uint32le, // in array entries
fUsingKeys: r.uint32le // group(xx) [using keys] <-- specified or not
});
if (this.COMP_GROUP.size() != KMXFile.COMP_GROUP_SIZE) {
throw "COMP_GROUP size is " + this.COMP_GROUP.size() + " but should be " + KMXFile.COMP_GROUP_SIZE + " bytes";
}
this.COMP_KEYBOARD_KMXPLUSINFO = new r.Struct({
dpKMXPlus: r.uint32le, // 0040 offset of KMXPlus data, <sect> header is first
dwKMXPlusSize: r.uint32le // 0044 size in bytes of entire KMXPlus data
});
if (this.COMP_KEYBOARD_KMXPLUSINFO.size() != KMXFile.COMP_KEYBOARD_KMXPLUSINFO_SIZE) {
throw "COMP_KEYBOARD_KMXPLUSINFO size is " + this.COMP_KEYBOARD_KMXPLUSINFO.size() + " but should be " + KMXFile.COMP_KEYBOARD_KMXPLUSINFO_SIZE + " bytes";
}
this.COMP_KEYBOARD = new r.Struct({
dwIdentifier: r.uint32le, // 0000 Keyman compiled keyboard id
dwFileVersion: r.uint32le, // 0004 Version of the file - Keyman 4.0 is 0x0400
dwCheckSum: r.uint32le, // 0008 As stored in keyboard
KeyboardID: r.uint32le, // 000C as stored in HKEY_LOCAL_MACHINE//system//currentcontrolset//control//keyboard layouts
IsRegistered: r.uint32le, // 0010
version: r.uint32le, // 0014 keyboard version
cxStoreArray: r.uint32le, // 0018 in array entries
cxGroupArray: r.uint32le, // 001C in array entries
dpStoreArray: r.uint32le, // 0020 [LPSTORE] address of first item in store array
dpGroupArray: r.uint32le, // 0024 [LPGROUP] address of first item in group array
StartGroup_ANSI: r.uint32le, // 0028 index of starting ANSI group
StartGroup_Unicode: r.uint32le, // 0028 index of starting Unicode groups
dwFlags: r.uint32le, // 0030 Flags for the keyboard file
dwHotKey: r.uint32le, // 0034 standard windows hotkey (hiword=shift/ctrl/alt stuff, loword=vkey)
dpBitmapOffset: r.uint32le, // 0038 offset of the bitmaps in the file
dwBitmapSize: r.uint32le // 003C size in bytes of the bitmaps
});
if (this.COMP_KEYBOARD.size() != KMXFile.COMP_KEYBOARD_SIZE) {
throw "COMP_KEYBOARD size is " + this.COMP_KEYBOARD.size() + " but should be " + KMXFile.COMP_KEYBOARD_SIZE + " bytes";
}
}
}
//# sourceMappingURL=kmx.js.map
//# debugId=a0fa81e6-5866-5723-9335-f956b27108ac