mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-06 08:55:34 +00:00
chore(web): expose util.ts as separate sub-export
The exports of the `util.ts` can now be imported as `@keymanapp/common-types/utils`. Those methods are used by developer. We still export the `Uni_IsSurrogate*` methods in `main.js` because they are needed by the keyboard-processor, but exporting everything would increase the size of the resulting `keymanweb.js`. Doing it this way keeps the size the same.
This commit is contained in:
parent
1945965d8a
commit
5552fdd5ad
11 changed files with 33 additions and 21 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { util } from '@keymanapp/common-types';
|
||||
import { Uni_IsSurrogate1, Uni_IsSurrogate2 } from '@keymanapp/common-types';
|
||||
|
||||
/**
|
||||
* Returns the index for the code point divergence point between two strings, as measured in code
|
||||
|
|
@ -72,8 +72,8 @@ export function findCommonSubstringEndIndex(str1: string, str2: string, commonSu
|
|||
const divergentChar1 = str1.charCodeAt(index);
|
||||
const divergentChar2 = str2.charCodeAt(index + offset);
|
||||
|
||||
const commonSurrogateChecker = commonSuffix ? util.Uni_IsSurrogate2 : util.Uni_IsSurrogate1;
|
||||
const divergentSurrogateChecker = commonSuffix ? util.Uni_IsSurrogate1 : util.Uni_IsSurrogate2;
|
||||
const commonSurrogateChecker = commonSuffix ? Uni_IsSurrogate2 : Uni_IsSurrogate1;
|
||||
const divergentSurrogateChecker = commonSuffix ? Uni_IsSurrogate1 : Uni_IsSurrogate2;
|
||||
|
||||
// If the last common character if of the direction-appropriate surrogate type (for
|
||||
// comprising a potential split surrogate pair representing a non-BMP char)...
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@
|
|||
".": {
|
||||
"es6-bundling": "./src/main.ts",
|
||||
"default": "./build/src/main.js"
|
||||
},
|
||||
"./utils": {
|
||||
"es6-bundling": "./src/util/index.ts",
|
||||
"default": "./build/src/util/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
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, unescapeOneQuadString } from '../util/util.js';
|
||||
import { MATCH_HEX_ESCAPE } from '../util/consts.js';
|
||||
import { unescapeOneQuadString } from '../util/util.js';
|
||||
|
||||
export enum ElemElementFlags {
|
||||
none = 0,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
*/
|
||||
|
||||
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { MATCH_QUAD_ESCAPE, isOneChar, unescapeOneQuadString, unescapeString, hexQuad } from "../util/util.js";
|
||||
import { MATCH_QUAD_ESCAPE } from "../util/consts.js";
|
||||
import { isOneChar, unescapeOneQuadString, unescapeString, hexQuad } from "../util/util.js";
|
||||
|
||||
/**
|
||||
* Helper function for extracting matched items
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export { KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanDeveloperProj
|
|||
export * as KpsFile from './package/kps-file.js';
|
||||
export * as KmpJsonFile from './package/kmp-json-file.js';
|
||||
|
||||
export * as util from './util/util.js';
|
||||
export { Uni_IsSurrogate1, Uni_IsSurrogate2 } from './util/util.js';
|
||||
|
||||
export * as KeymanFileTypes from './util/file-types.js';
|
||||
|
||||
|
|
|
|||
12
common/web/types/src/util/consts.ts
Normal file
12
common/web/types/src/util/consts.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// TODO-LDML: #7569 the below regex works, but captures more than it should
|
||||
// (it would include \u{fffffffffffffffff } which
|
||||
// is overlong and has a space at the end.) The second regex does not work yet.
|
||||
export const MATCH_HEX_ESCAPE = /\\u{([0-9a-fA-F ]{1,})}/g;
|
||||
// const MATCH_HEX_ESCAPE = /\\u{((?:(?:[0-9a-fA-F]{1,5})|(?:10[0-9a-fA-F]{4})(?: (?!}))?)+)}/g;
|
||||
|
||||
/** regex for single quad escape such as \u0127 or \U00000000 */
|
||||
export const CONTAINS_QUAD_ESCAPE = /(?:\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8}))/;
|
||||
|
||||
/** regex for single quad escape such as \u0127 */
|
||||
export const MATCH_QUAD_ESCAPE = new RegExp(CONTAINS_QUAD_ESCAPE, 'g');
|
||||
|
||||
2
common/web/types/src/util/index.ts
Normal file
2
common/web/types/src/util/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from './consts.js';
|
||||
export * from './util.js';
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { MATCH_HEX_ESCAPE, MATCH_QUAD_ESCAPE } from './consts.js';
|
||||
/**
|
||||
* xml2js will not place single-entry objects into arrays. Easiest way to fix
|
||||
* this is to box them ourselves as needed. Ensures that o.x is an array.
|
||||
|
|
@ -16,18 +17,6 @@ export function boxXmlArray(o: any, x: string): void {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO-LDML: #7569 the below regex works, but captures more than it should
|
||||
// (it would include \u{fffffffffffffffff } which
|
||||
// is overlong and has a space at the end.) The second regex does not work yet.
|
||||
export const MATCH_HEX_ESCAPE = /\\u{([0-9a-fA-F ]{1,})}/g;
|
||||
// const MATCH_HEX_ESCAPE = /\\u{((?:(?:[0-9a-fA-F]{1,5})|(?:10[0-9a-fA-F]{4})(?: (?!}))?)+)}/g;
|
||||
|
||||
/** regex for single quad escape such as \u0127 or \U00000000 */
|
||||
export const CONTAINS_QUAD_ESCAPE = /(?:\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8}))/;
|
||||
|
||||
/** regex for single quad escape such as \u0127 */
|
||||
export const MATCH_QUAD_ESCAPE = new RegExp(CONTAINS_QUAD_ESCAPE, 'g');
|
||||
|
||||
export class UnescapeError extends Error {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { SectionIdent, constants } from '@keymanapp/ldml-keyboard-constants';
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
import { LDMLKeyboard, KMXPlus, CompilerCallbacks, util, MarkerParser } from "@keymanapp/common-types";
|
||||
import { LDMLKeyboard, KMXPlus, CompilerCallbacks, MarkerParser } from "@keymanapp/common-types";
|
||||
import * as util from '@keymanapp/common-types/utils';
|
||||
import { VarsCompiler } from './vars.js';
|
||||
import { CompilerMessages } from './messages.js';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { util, CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m, CompilerMessageDef as def } from "@keymanapp/common-types";
|
||||
import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m, CompilerMessageDef as def } from "@keymanapp/common-types";
|
||||
import * as util from '@keymanapp/common-types/utils';
|
||||
// const SevInfo = CompilerErrorSeverity.Info | CompilerErrorNamespace.LdmlKeyboardCompiler;
|
||||
const SevHint = CompilerErrorSeverity.Hint | CompilerErrorNamespace.LdmlKeyboardCompiler;
|
||||
const SevWarn = CompilerErrorSeverity.Warn | CompilerErrorNamespace.LdmlKeyboardCompiler;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { constants, SectionIdent } from "@keymanapp/ldml-keyboard-constants";
|
||||
import { KMXPlus, LDMLKeyboard, CompilerCallbacks, VariableParser, MarkerParser, util } from '@keymanapp/common-types';
|
||||
import { KMXPlus, LDMLKeyboard, CompilerCallbacks, VariableParser, MarkerParser } from '@keymanapp/common-types';
|
||||
import * as util from '@keymanapp/common-types/utils';
|
||||
import { SectionCompiler } from "./section-compiler.js";
|
||||
|
||||
import Bksp = KMXPlus.Bksp;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue