
!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]="f493adbf-e018-53a0-a979-00479c104c12")}catch(e){}}();
import { SchemaValidators } from "@keymanapp/common-types";
;
;
;
export function parseMapping(mapping) {
    if (!SchemaValidators.default.displayMap(mapping)) 
    /* c8 ignore next 3 */
    {
        throw new Error(JSON.stringify(SchemaValidators.default.displayMap.errors));
    }
    const map = {};
    for (const item of mapping.map) {
        map[item.str] = String.fromCharCode(parseInt(item.pua, 16));
    }
    return map;
}
function cleanString(s) {
    s = s.replace(/\u25cc/g, '');
    return s.trim();
}
function remap(text, map) {
    if (map[text.trim()]) {
        return map[text.trim()];
    }
    text = cleanString(text);
    if (map[text]) {
        return map[text];
    }
    return text;
}
export function remapVisualKeyboard(vk, map) {
    let dirty = false;
    for (const key of vk.keys) {
        if (!key.text) {
            continue;
        }
        const text = remap(key.text, map);
        dirty = dirty || text != key.text;
        key.text = text;
    }
    return dirty;
}
export function remapTouchLayout(source, map) {
    let dirty = false;
    const scanKey = (key) => {
        if (!key.text) {
            return;
        }
        if (key.text.length > 2 && key.text[0] == '*' && key.text[key.text.length - 1] == '*') {
            // Don't touch '*special*' key captions
            return;
        }
        const text = remap(key.text, map);
        dirty = dirty || text != key.text;
        key.text = text;
    };
    const scanPlatform = (platform) => {
        if (!platform) {
            return;
        }
        for (const layer of platform.layer) {
            for (const row of layer.row) {
                for (const key of row.key) {
                    scanKey(key);
                    if (key.hint && !key.hint.match(/^\*.+\*$/)) {
                        const hint = remap(key.hint, map);
                        dirty = dirty || hint != key.hint;
                        key.hint = hint;
                    }
                    let f;
                    for (f in key.flick ?? {}) {
                        scanKey(key.flick[f]);
                    }
                    for (const sk of key.sk ?? []) {
                        scanKey(sk);
                    }
                    for (const mt of key.multitap ?? []) {
                        scanKey(mt);
                    }
                }
            }
        }
    };
    scanPlatform(source.desktop);
    scanPlatform(source.phone);
    scanPlatform(source.tablet);
    return dirty;
}
//# sourceMappingURL=osk.js.map
//# debugId=f493adbf-e018-53a0-a979-00479c104c12
