@keymanapp/common-types 18.0.17-alpha → 18.0.19-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/build/src/consts/virtual-key-constants.js +222 -221
  2. package/build/src/consts/virtual-key-constants.js.map +1 -1
  3. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js +73 -72
  4. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js.map +1 -1
  5. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js +121 -120
  6. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js.map +1 -1
  7. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js +55 -54
  8. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js.map +1 -1
  9. package/build/src/kmx/element-string.d.ts.map +1 -1
  10. package/build/src/kmx/element-string.js +126 -120
  11. package/build/src/kmx/element-string.js.map +1 -1
  12. package/build/src/kmx/keyman-targets.js +80 -79
  13. package/build/src/kmx/keyman-targets.js.map +1 -1
  14. package/build/src/kmx/kmx-builder.js +190 -189
  15. package/build/src/kmx/kmx-builder.js.map +1 -1
  16. package/build/src/kmx/kmx-file-reader.js +135 -134
  17. package/build/src/kmx/kmx-file-reader.js.map +1 -1
  18. package/build/src/kmx/kmx-plus-builder/build-disp.js +28 -27
  19. package/build/src/kmx/kmx-plus-builder/build-disp.js.map +1 -1
  20. package/build/src/kmx/kmx-plus-builder/build-elem.js +90 -89
  21. package/build/src/kmx/kmx-plus-builder/build-elem.js.map +1 -1
  22. package/build/src/kmx/kmx-plus-builder/build-keys.js +108 -107
  23. package/build/src/kmx/kmx-plus-builder/build-keys.js.map +1 -1
  24. package/build/src/kmx/kmx-plus-builder/build-layr.js +102 -101
  25. package/build/src/kmx/kmx-plus-builder/build-layr.js.map +1 -1
  26. package/build/src/kmx/kmx-plus-builder/build-list.js +67 -66
  27. package/build/src/kmx/kmx-plus-builder/build-list.js.map +1 -1
  28. package/build/src/kmx/kmx-plus-builder/build-loca.js +22 -21
  29. package/build/src/kmx/kmx-plus-builder/build-loca.js.map +1 -1
  30. package/build/src/kmx/kmx-plus-builder/build-meta.js +23 -22
  31. package/build/src/kmx/kmx-plus-builder/build-meta.js.map +1 -1
  32. package/build/src/kmx/kmx-plus-builder/build-sect.js +16 -15
  33. package/build/src/kmx/kmx-plus-builder/build-sect.js.map +1 -1
  34. package/build/src/kmx/kmx-plus-builder/build-strs.js +47 -46
  35. package/build/src/kmx/kmx-plus-builder/build-strs.js.map +1 -1
  36. package/build/src/kmx/kmx-plus-builder/build-tran.js +70 -69
  37. package/build/src/kmx/kmx-plus-builder/build-tran.js.map +1 -1
  38. package/build/src/kmx/kmx-plus-builder/build-uset.js +61 -60
  39. package/build/src/kmx/kmx-plus-builder/build-uset.js.map +1 -1
  40. package/build/src/kmx/kmx-plus-builder/build-vars.js +49 -48
  41. package/build/src/kmx/kmx-plus-builder/build-vars.js.map +1 -1
  42. package/build/src/kmx/kmx-plus-builder/builder-section.js +5 -4
  43. package/build/src/kmx/kmx-plus-builder/builder-section.js.map +1 -1
  44. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js +138 -137
  45. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js.map +1 -1
  46. package/build/src/kmx/kmx-plus.d.ts +3 -2
  47. package/build/src/kmx/kmx-plus.d.ts.map +1 -1
  48. package/build/src/kmx/kmx-plus.js +831 -823
  49. package/build/src/kmx/kmx-plus.js.map +1 -1
  50. package/build/src/kmx/kmx.d.ts.map +1 -1
  51. package/build/src/kmx/kmx.js +303 -299
  52. package/build/src/kmx/kmx.js.map +1 -1
  53. package/build/src/kmx/string-list.js +89 -88
  54. package/build/src/kmx/string-list.js.map +1 -1
  55. package/build/src/kpj/keyman-developer-project.js +196 -195
  56. package/build/src/kpj/keyman-developer-project.js.map +1 -1
  57. package/build/src/kpj/kpj-file-reader.js +120 -119
  58. package/build/src/kpj/kpj-file-reader.js.map +1 -1
  59. package/build/src/kpj/kpj-file.js +13 -12
  60. package/build/src/kpj/kpj-file.js.map +1 -1
  61. package/build/src/kvk/kvk-file-reader.js +38 -37
  62. package/build/src/kvk/kvk-file-reader.js.map +1 -1
  63. package/build/src/kvk/kvk-file-writer.js +78 -77
  64. package/build/src/kvk/kvk-file-writer.js.map +1 -1
  65. package/build/src/kvk/kvk-file.js +91 -90
  66. package/build/src/kvk/kvk-file.js.map +1 -1
  67. package/build/src/kvk/kvks-file-reader.js +176 -175
  68. package/build/src/kvk/kvks-file-reader.js.map +1 -1
  69. package/build/src/kvk/kvks-file-writer.js +107 -106
  70. package/build/src/kvk/kvks-file-writer.js.map +1 -1
  71. package/build/src/kvk/kvks-file.js +12 -11
  72. package/build/src/kvk/kvks-file.js.map +1 -1
  73. package/build/src/kvk/visual-keyboard.js +76 -75
  74. package/build/src/kvk/visual-keyboard.js.map +1 -1
  75. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js +22 -21
  76. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js.map +1 -1
  77. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js +410 -409
  78. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js.map +1 -1
  79. package/build/src/ldml-keyboard/ldml-keyboard-xml.js +58 -57
  80. package/build/src/ldml-keyboard/ldml-keyboard-xml.js.map +1 -1
  81. package/build/src/ldml-keyboard/pattern-parser.js +491 -490
  82. package/build/src/ldml-keyboard/pattern-parser.js.map +1 -1
  83. package/build/src/ldml-keyboard/unicodeset-parser-api.js +30 -29
  84. package/build/src/ldml-keyboard/unicodeset-parser-api.js.map +1 -1
  85. package/build/src/main.js +35 -34
  86. package/build/src/main.js.map +1 -1
  87. package/build/src/package/kmp-json-file.js +4 -3
  88. package/build/src/package/kmp-json-file.js.map +1 -1
  89. package/build/src/package/kps-file.js +18 -17
  90. package/build/src/package/kps-file.js.map +1 -1
  91. package/build/src/schema-validators.js +28 -27
  92. package/build/src/schema-validators.js.map +1 -1
  93. package/build/src/schemas/displaymap.schema.js +38 -37
  94. package/build/src/schemas/displaymap.schema.js.map +1 -1
  95. package/build/src/schemas/displaymap.schema.validator.mjs +267 -266
  96. package/build/src/schemas/displaymap.schema.validator.mjs.map +1 -1
  97. package/build/src/schemas/keyboard_info.schema.js +101 -100
  98. package/build/src/schemas/keyboard_info.schema.js.map +1 -1
  99. package/build/src/schemas/keyboard_info.schema.validator.mjs +1161 -1160
  100. package/build/src/schemas/keyboard_info.schema.validator.mjs.map +1 -1
  101. package/build/src/schemas/keyman-touch-layout.clean.spec.js +154 -153
  102. package/build/src/schemas/keyman-touch-layout.clean.spec.js.map +1 -1
  103. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.mjs +1095 -1094
  104. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.mjs.map +1 -1
  105. package/build/src/schemas/keyman-touch-layout.spec.js +143 -142
  106. package/build/src/schemas/keyman-touch-layout.spec.js.map +1 -1
  107. package/build/src/schemas/keyman-touch-layout.spec.validator.mjs +1437 -1436
  108. package/build/src/schemas/keyman-touch-layout.spec.validator.mjs.map +1 -1
  109. package/build/src/schemas/kmp.schema.js +356 -355
  110. package/build/src/schemas/kmp.schema.js.map +1 -1
  111. package/build/src/schemas/kmp.schema.validator.mjs +1628 -1627
  112. package/build/src/schemas/kmp.schema.validator.mjs.map +1 -1
  113. package/build/src/schemas/kpj-9.0.schema.js +134 -133
  114. package/build/src/schemas/kpj-9.0.schema.js.map +1 -1
  115. package/build/src/schemas/kpj-9.0.schema.validator.mjs +656 -655
  116. package/build/src/schemas/kpj-9.0.schema.validator.mjs.map +1 -1
  117. package/build/src/schemas/kpj.schema.js +132 -131
  118. package/build/src/schemas/kpj.schema.js.map +1 -1
  119. package/build/src/schemas/kpj.schema.validator.mjs +516 -515
  120. package/build/src/schemas/kpj.schema.validator.mjs.map +1 -1
  121. package/build/src/schemas/kvks.schema.js +185 -184
  122. package/build/src/schemas/kvks.schema.js.map +1 -1
  123. package/build/src/schemas/kvks.schema.validator.mjs +626 -625
  124. package/build/src/schemas/kvks.schema.validator.mjs.map +1 -1
  125. package/build/src/schemas/ldml-keyboard3.schema.js +699 -698
  126. package/build/src/schemas/ldml-keyboard3.schema.js.map +1 -1
  127. package/build/src/schemas/ldml-keyboard3.schema.validator.mjs +3118 -3117
  128. package/build/src/schemas/ldml-keyboard3.schema.validator.mjs.map +1 -1
  129. package/build/src/schemas/ldml-keyboardtest3.schema.js +228 -227
  130. package/build/src/schemas/ldml-keyboardtest3.schema.js.map +1 -1
  131. package/build/src/schemas/ldml-keyboardtest3.schema.validator.mjs +745 -744
  132. package/build/src/schemas/ldml-keyboardtest3.schema.validator.mjs.map +1 -1
  133. package/build/src/schemas.js +26 -25
  134. package/build/src/schemas.js.map +1 -1
  135. package/build/src/util/common-events.js +29 -28
  136. package/build/src/util/common-events.js.map +1 -1
  137. package/build/src/util/compiler-interfaces.js +381 -380
  138. package/build/src/util/compiler-interfaces.js.map +1 -1
  139. package/build/src/util/errors.js +8 -7
  140. package/build/src/util/errors.js.map +1 -1
  141. package/build/src/util/file-types.js +143 -142
  142. package/build/src/util/file-types.js.map +1 -1
  143. package/build/src/util/util.d.ts +4 -0
  144. package/build/src/util/util.d.ts.map +1 -1
  145. package/build/src/util/util.js +369 -362
  146. package/build/src/util/util.js.map +1 -1
  147. package/package.json +2 -2
@@ -1,363 +1,370 @@
1
- !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]="58741681-24af-5280-b74e-befdae2af7b9")}catch(e){}}();
2
- /**
3
- * xml2js will not place single-entry objects into arrays. Easiest way to fix
4
- * this is to box them ourselves as needed. Ensures that o.x is an array.
5
- *
6
- * @param o Object with property to box
7
- * @param x Name of element to box
8
- */
9
- export function boxXmlArray(o, x) {
10
- if (typeof o == 'object' && !Array.isArray(o[x])) {
11
- if (o[x] === null || o[x] === undefined) {
12
- o[x] = [];
13
- }
14
- else {
15
- o[x] = [o[x]];
16
- }
17
- }
18
- }
19
- // TODO-LDML: #7569 the below regex works, but captures more than it should
20
- // (it would include \u{fffffffffffffffff } which
21
- // is overlong and has a space at the end.) The second regex does not work yet.
22
- export const MATCH_HEX_ESCAPE = /\\u{([0-9a-fA-F ]{1,})}/g;
23
- // const MATCH_HEX_ESCAPE = /\\u{((?:(?:[0-9a-fA-F]{1,5})|(?:10[0-9a-fA-F]{4})(?: (?!}))?)+)}/g;
24
- /** regex for single quad escape such as \u0127 or \U00000000 */
25
- export const CONTAINS_QUAD_ESCAPE = /(?:\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8}))/;
26
- /** regex for single quad escape such as \u0127 */
27
- export const MATCH_QUAD_ESCAPE = new RegExp(CONTAINS_QUAD_ESCAPE, 'g');
28
- export class UnescapeError extends Error {
29
- }
30
- /**
31
- * Unescape one codepoint
32
- * @param hex one codepoint in hex, such as '0127'
33
- * @returns the unescaped codepoint
34
- */
35
- export function unescapeOne(hex) {
36
- const codepoint = Number.parseInt(hex, 16);
37
- return String.fromCodePoint(codepoint);
38
- }
39
- /**
40
- * Unescape one single quad string such as \u0127 / \U00000000
41
- * Throws exception if the string doesn't match MATCH_QUAD_ESCAPE
42
- * Note this does not attempt to handle or reject surrogates.
43
- * So, `\\uD838\\uDD09` will work but other combinations may not.
44
- * @param s input string
45
- * @returns output
46
- */
47
- export function unescapeOneQuadString(s) {
48
- if (!s || !s.match(MATCH_QUAD_ESCAPE)) {
49
- throw new UnescapeError(`Not a quad escape: ${s}`);
50
- }
51
- function processMatch(str, m16, m32) {
52
- return unescapeOne(m16 || m32); // either \u or \U
53
- }
54
- s = s.replace(MATCH_QUAD_ESCAPE, processMatch);
55
- return s;
56
- }
57
- /** unscape multiple occurences of \u0127 style strings */
58
- export function unescapeQuadString(s) {
59
- s = s.replaceAll(MATCH_QUAD_ESCAPE, (quad) => unescapeOneQuadString(quad));
60
- return s;
61
- }
62
- /**
63
- * Unescapes a string according to UTS#18§1.1, see <https://www.unicode.org/reports/tr18/#Hex_notation>
64
- * @param s escaped string
65
- * @returns
66
- */
67
- export function unescapeString(s) {
68
- if (!s) {
69
- return s;
70
- }
71
- try {
72
- /**
73
- * process one regex match
74
- * @param str ignored
75
- * @param matched the entire match such as '0127' or '22 22'
76
- * @returns the unescaped match
77
- */
78
- function processMatch(str, matched) {
79
- const codepoints = matched.split(' ');
80
- const unescaped = codepoints.map(unescapeOne);
81
- return unescaped.join('');
82
- }
83
- s = s.replaceAll(MATCH_HEX_ESCAPE, processMatch);
84
- }
85
- catch (e) {
86
- if (e instanceof RangeError) {
87
- throw new UnescapeError(`Out of range while unescaping '${s}': ${e.message}`, { cause: e });
88
- /* c8 ignore next 3 */
89
- }
90
- else {
91
- throw e; // pass through some other error
92
- }
93
- }
94
- return s;
95
- }
96
- /** 0000 … FFFF */
97
- export function hexQuad(n) {
98
- if (n < 0x0000 || n > 0xFFFF) {
99
- throw RangeError(`${n} not in [0x0000,0xFFFF]`);
100
- }
101
- return n.toString(16).padStart(4, '0');
102
- }
103
- /** 00000000 … FFFFFFFF */
104
- export function hexOcts(n) {
105
- if (n < 0x0000 || n > 0xFFFFFFFF) {
106
- throw RangeError(`${n} not in [0x00000000,0xFFFFFFFF]`);
107
- }
108
- return n.toString(16).padStart(8, '0');
109
- }
110
- /** escape one char for regex in \uXXXX form */
111
- export function escapeRegexChar(ch) {
112
- const code = ch.codePointAt(0);
113
- if (code <= 0xFFFF) {
114
- return '\\u' + hexQuad(code);
115
- }
116
- else {
117
- return '\\U' + hexOcts(code);
118
- }
119
- }
120
- /** chars that must be escaped: syntax, C0 + C1 controls */
121
- const REGEX_SYNTAX_CHAR = /^[\u0000-\u001F\u007F-\u009F{}\[\]\\?.^$*()/-]$/;
122
- function escapeRegexCharIfSyntax(ch) {
123
- // escape if syntax or not valid
124
- if (REGEX_SYNTAX_CHAR.test(ch) || !isValidUnicode(ch.codePointAt(0))) {
125
- return escapeRegexChar(ch);
126
- }
127
- else {
128
- return ch; // leave unescaped
129
- }
130
- }
131
- /**
132
- * Unescape one codepoint to \u or \U format
133
- * @param hex one codepoint in hex, such as '0127'
134
- * @returns the unescaped codepoint
135
- */
136
- function regexOne(hex) {
137
- const unescaped = unescapeOne(hex);
138
- // re-escape as 16 or 32 bit code units
139
- return Array.from(unescaped).map(ch => escapeRegexCharIfSyntax(ch)).join('');
140
- }
141
- /**
142
- * Unescapes a string according to UTS#18§1.1, see <https://www.unicode.org/reports/tr18/#Hex_notation>
143
- * @param s escaped string
144
- * @returns
145
- */
146
- export function unescapeStringToRegex(s) {
147
- if (!s) {
148
- return s;
149
- }
150
- try {
151
- /**
152
- * process one regex match
153
- * @param str ignored
154
- * @param matched the entire match such as '0127' or '22 22'
155
- * @returns the unescaped match
156
- */
157
- function processMatch(str, matched) {
158
- const codepoints = matched.split(' ');
159
- const unescaped = codepoints.map(regexOne);
160
- return unescaped.join('');
161
- }
162
- s = s.replaceAll(MATCH_HEX_ESCAPE, processMatch);
163
- }
164
- catch (e) {
165
- if (e instanceof RangeError) {
166
- throw new UnescapeError(`Out of range while unescaping '${s}': ${e.message}`, { cause: e });
167
- /* c8 ignore next 3 */
168
- }
169
- else {
170
- throw e; // pass through some other error
171
- }
172
- }
173
- return s;
174
- }
175
- /** True if this string *could* be a UTF-32 single char */
176
- export function isOneChar(value) {
177
- return [...value].length === 1;
178
- }
179
- export function toOneChar(value) {
180
- if (!isOneChar(value)) {
181
- throw Error(`Not a single char: ${value}`);
182
- }
183
- return value.codePointAt(0);
184
- }
185
- export function describeCodepoint(ch) {
186
- let s;
187
- const p = BadStringAnalyzer.getProblem(ch);
188
- if (p != null) {
189
- // for example: 'PUA (U+E010)'
190
- s = p;
191
- }
192
- else {
193
- // for example: '"a" (U+61)'
194
- s = `"${String.fromCodePoint(ch)}"`;
195
- }
196
- return `${s} (U+${Number(ch).toString(16).toUpperCase()})`;
197
- }
198
- export var BadStringType;
199
- (function (BadStringType) {
200
- BadStringType["pua"] = "PUA";
201
- BadStringType["unassigned"] = "Unassigned";
202
- BadStringType["illegal"] = "Illegal";
203
- BadStringType["denormalized"] = "Denormalized";
204
- })(BadStringType || (BadStringType = {}));
205
- ;
206
- // Following from kmx_xstring.h / .cpp
207
- const Uni_LEAD_SURROGATE_START = 0xD800;
208
- const Uni_LEAD_SURROGATE_END = 0xDBFF;
209
- const Uni_TRAIL_SURROGATE_START = 0xDC00;
210
- const Uni_TRAIL_SURROGATE_END = 0xDFFF;
211
- const Uni_SURROGATE_START = Uni_LEAD_SURROGATE_START;
212
- const Uni_SURROGATE_END = Uni_TRAIL_SURROGATE_END;
213
- const Uni_FD_NONCHARACTER_START = 0xFDD0;
214
- const Uni_FD_NONCHARACTER_END = 0xFDEF;
215
- const Uni_FFFE_NONCHARACTER = 0xFFFE;
216
- const Uni_PLANE_MASK = 0x1F0000;
217
- const Uni_MAX_CODEPOINT = 0x10FFFF;
218
- // plane 0, 15, and 16 PUA
219
- const Uni_PUA_00_START = 0xE000;
220
- const Uni_PUA_00_END = 0xF8FF;
221
- const Uni_PUA_15_START = 0x0F0000;
222
- const Uni_PUA_15_END = 0x0FFFFD;
223
- const Uni_PUA_16_START = 0x100000;
224
- const Uni_PUA_16_END = 0x10FFFD;
225
- /**
226
- * @brief True if a lead surrogate
227
- * \def Uni_IsSurrogate1
228
- */
229
- function Uni_IsSurrogate1(ch) {
230
- return ((ch) >= Uni_LEAD_SURROGATE_START && (ch) <= Uni_LEAD_SURROGATE_END);
231
- }
232
- /**
233
- * @brief True if a trail surrogate
234
- * \def Uni_IsSurrogate2
235
- */
236
- function Uni_IsSurrogate2(ch) {
237
- return ((ch) >= Uni_TRAIL_SURROGATE_START && (ch) <= Uni_TRAIL_SURROGATE_END);
238
- }
239
- /**
240
- * @brief True if any surrogate
241
- * \def UniIsSurrogate
242
- */
243
- function Uni_IsSurrogate(ch) {
244
- return (Uni_IsSurrogate1(ch) || Uni_IsSurrogate2(ch));
245
- }
246
- function Uni_IsEndOfPlaneNonCharacter(ch) {
247
- return (((ch) & Uni_FFFE_NONCHARACTER) == Uni_FFFE_NONCHARACTER); // matches FFFF or FFFE
248
- }
249
- function Uni_IsNoncharacter(ch) {
250
- return (((ch) >= Uni_FD_NONCHARACTER_START && (ch) <= Uni_FD_NONCHARACTER_END) || Uni_IsEndOfPlaneNonCharacter(ch));
251
- }
252
- function Uni_InCodespace(ch) {
253
- return (ch >= 0 && ch <= Uni_MAX_CODEPOINT);
254
- }
255
- ;
256
- function Uni_IsValid1(ch) {
257
- return (Uni_InCodespace(ch) && !Uni_IsSurrogate(ch) && !Uni_IsNoncharacter(ch));
258
- }
259
- export function isValidUnicode(start, end) {
260
- if (!end) {
261
- // single char
262
- return Uni_IsValid1(start);
263
- }
264
- else if (!Uni_IsValid1(end) || !Uni_IsValid1(start) || (end < start)) {
265
- // start or end out of range, or inverted range
266
- return false;
267
- }
268
- else if ((start <= Uni_SURROGATE_END) && (end >= Uni_SURROGATE_START)) {
269
- // contains some of the surrogate range
270
- return false;
271
- }
272
- else if ((start <= Uni_FD_NONCHARACTER_END) && (end >= Uni_FD_NONCHARACTER_START)) {
273
- // contains some of the noncharacter range
274
- return false;
275
- }
276
- else if ((start & Uni_PLANE_MASK) != (end & Uni_PLANE_MASK)) {
277
- // start and end are on different planes, meaning that the U+__FFFE/U+__FFFF noncharacters
278
- // are contained.
279
- // As a reminder, we already checked that start/end are themselves valid,
280
- // so we know that 'end' is not on a noncharacter at end of plane.
281
- return false;
282
- }
283
- else {
284
- return true;
285
- }
286
- }
287
- export function isPUA(ch) {
288
- return ((ch >= Uni_PUA_00_START && ch <= Uni_PUA_00_END) ||
289
- (ch >= Uni_PUA_15_START && ch <= Uni_PUA_15_END) ||
290
- (ch >= Uni_PUA_16_START && ch <= Uni_PUA_16_END));
291
- }
292
- class BadStringMap extends Map {
293
- toString() {
294
- if (!this.size) {
295
- return "{}";
296
- }
297
- return Array.from(this.entries()).map(([t, s]) => `${t}: ${Array.from(s.values()).map(describeCodepoint).join(' ')}`).join(', ');
298
- }
299
- }
300
- /** abstract class for analyzing and categorizing strings */
301
- export class StringAnalyzer {
302
- /** add a string for analysis */
303
- add(s) {
304
- for (const c of [...s]) {
305
- const ch = c.codePointAt(0);
306
- const problem = this.analyzeCodePoint(c, ch);
307
- if (problem) {
308
- this.addProblem(ch, problem);
309
- }
310
- }
311
- }
312
- /** internal interface for the result of an analysis */
313
- addProblem(ch, type) {
314
- if (!this.m.has(type)) {
315
- this.m.set(type, new Set());
316
- }
317
- this.m.get(type).add(ch);
318
- }
319
- /** get the results of the analysis */
320
- analyze() {
321
- if (this.m.size == 0) {
322
- return null;
323
- }
324
- else {
325
- return this.m;
326
- }
327
- }
328
- /** internal map */
329
- m = new BadStringMap();
330
- }
331
- /** analyze a string looking for bad unicode */
332
- export class BadStringAnalyzer extends StringAnalyzer {
333
- /** analyze one codepoint */
334
- analyzeCodePoint(c, ch) {
335
- return BadStringAnalyzer.getProblem(ch);
336
- }
337
- /** export analyzer function */
338
- static getProblem(ch) {
339
- if (!isValidUnicode(ch)) {
340
- return BadStringType.illegal;
341
- }
342
- else if (isPUA(ch)) {
343
- return BadStringType.pua;
344
- }
345
- else { // TODO-LDML: unassigned
346
- return null;
347
- }
348
- }
349
- }
350
- /** Analyzer that checks if something isn't NFD */
351
- export class NFDAnalyzer extends StringAnalyzer {
352
- analyzeCodePoint(c, ch) {
353
- const nfd = c.normalize("NFD");
354
- if (c !== nfd) {
355
- return BadStringType.denormalized;
356
- }
357
- else {
358
- return null;
359
- }
360
- }
361
- }
362
- //# debugId=58741681-24af-5280-b74e-befdae2af7b9
1
+ /**
2
+ * xml2js will not place single-entry objects into arrays. Easiest way to fix
3
+ * this is to box them ourselves as needed. Ensures that o.x is an array.
4
+ *
5
+ * @param o Object with property to box
6
+ * @param x Name of element to box
7
+ */
8
+
9
+ !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]="91216ba4-c47b-5153-87f2-ec7858626e3a")}catch(e){}}();
10
+ export function boxXmlArray(o, x) {
11
+ if (typeof o == 'object' && !Array.isArray(o[x])) {
12
+ if (o[x] === null || o[x] === undefined) {
13
+ o[x] = [];
14
+ }
15
+ else {
16
+ o[x] = [o[x]];
17
+ }
18
+ }
19
+ }
20
+ // TODO-LDML: #7569 the below regex works, but captures more than it should
21
+ // (it would include \u{fffffffffffffffff } which
22
+ // is overlong and has a space at the end.) The second regex does not work yet.
23
+ export const MATCH_HEX_ESCAPE = /\\u{([0-9a-fA-F ]{1,})}/g;
24
+ // const MATCH_HEX_ESCAPE = /\\u{((?:(?:[0-9a-fA-F]{1,5})|(?:10[0-9a-fA-F]{4})(?: (?!}))?)+)}/g;
25
+ /** regex for single quad escape such as \u0127 or \U00000000 */
26
+ export const CONTAINS_QUAD_ESCAPE = /(?:\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8}))/;
27
+ /** regex for single quad escape such as \u0127 */
28
+ export const MATCH_QUAD_ESCAPE = new RegExp(CONTAINS_QUAD_ESCAPE, 'g');
29
+ export class UnescapeError extends Error {
30
+ }
31
+ /**
32
+ * Unescape one codepoint
33
+ * @param hex one codepoint in hex, such as '0127'
34
+ * @returns the unescaped codepoint
35
+ */
36
+ export function unescapeOne(hex) {
37
+ const codepoint = Number.parseInt(hex, 16);
38
+ return String.fromCodePoint(codepoint);
39
+ }
40
+ /**
41
+ * Unescape one single quad string such as \u0127 / \U00000000
42
+ * Throws exception if the string doesn't match MATCH_QUAD_ESCAPE
43
+ * Note this does not attempt to handle or reject surrogates.
44
+ * So, `\\uD838\\uDD09` will work but other combinations may not.
45
+ * @param s input string
46
+ * @returns output
47
+ */
48
+ export function unescapeOneQuadString(s) {
49
+ if (!s || !s.match(MATCH_QUAD_ESCAPE)) {
50
+ throw new UnescapeError(`Not a quad escape: ${s}`);
51
+ }
52
+ function processMatch(str, m16, m32) {
53
+ return unescapeOne(m16 || m32); // either \u or \U
54
+ }
55
+ s = s.replace(MATCH_QUAD_ESCAPE, processMatch);
56
+ return s;
57
+ }
58
+ /** unscape multiple occurences of \u0127 style strings */
59
+ export function unescapeQuadString(s) {
60
+ s = s.replaceAll(MATCH_QUAD_ESCAPE, (quad) => unescapeOneQuadString(quad));
61
+ return s;
62
+ }
63
+ /**
64
+ * Unescapes a string according to UTS#18§1.1, see <https://www.unicode.org/reports/tr18/#Hex_notation>
65
+ * @param s escaped string
66
+ * @returns
67
+ */
68
+ export function unescapeString(s) {
69
+ if (!s) {
70
+ return s;
71
+ }
72
+ try {
73
+ /**
74
+ * process one regex match
75
+ * @param str ignored
76
+ * @param matched the entire match such as '0127' or '22 22'
77
+ * @returns the unescaped match
78
+ */
79
+ function processMatch(str, matched) {
80
+ const codepoints = matched.split(' ');
81
+ const unescaped = codepoints.map(unescapeOne);
82
+ return unescaped.join('');
83
+ }
84
+ s = s.replaceAll(MATCH_HEX_ESCAPE, processMatch);
85
+ }
86
+ catch (e) {
87
+ if (e instanceof RangeError) {
88
+ throw new UnescapeError(`Out of range while unescaping '${s}': ${e.message}`, { cause: e });
89
+ /* c8 ignore next 3 */
90
+ }
91
+ else {
92
+ throw e; // pass through some other error
93
+ }
94
+ }
95
+ return s;
96
+ }
97
+ /** 0000 … FFFF */
98
+ export function hexQuad(n) {
99
+ if (n < 0x0000 || n > 0xFFFF) {
100
+ throw RangeError(`${n} not in [0x0000,0xFFFF]`);
101
+ }
102
+ return n.toString(16).padStart(4, '0');
103
+ }
104
+ /** 00000000 … FFFFFFFF */
105
+ export function hexOcts(n) {
106
+ if (n < 0x0000 || n > 0xFFFFFFFF) {
107
+ throw RangeError(`${n} not in [0x00000000,0xFFFFFFFF]`);
108
+ }
109
+ return n.toString(16).padStart(8, '0');
110
+ }
111
+ /** escape one char for regex in \uXXXX form */
112
+ export function escapeRegexChar(ch) {
113
+ const code = ch.codePointAt(0);
114
+ if (code <= 0xFFFF) {
115
+ return '\\u' + hexQuad(code);
116
+ }
117
+ else {
118
+ return '\\U' + hexOcts(code);
119
+ }
120
+ }
121
+ /** chars that must be escaped: syntax, C0 + C1 controls */
122
+ const REGEX_SYNTAX_CHAR = /^[\u0000-\u001F\u007F-\u009F{}\[\]\\?|.^$*()/-]$/;
123
+ function escapeRegexCharIfSyntax(ch) {
124
+ // escape if syntax or not valid
125
+ if (REGEX_SYNTAX_CHAR.test(ch) || !isValidUnicode(ch.codePointAt(0))) {
126
+ return escapeRegexChar(ch);
127
+ }
128
+ else {
129
+ return ch; // leave unescaped
130
+ }
131
+ }
132
+ /**
133
+ * Unescape one codepoint to \u or \U format
134
+ * @param hex one codepoint in hex, such as '0127'
135
+ * @returns the unescaped codepoint
136
+ */
137
+ function regexOne(hex) {
138
+ const unescaped = unescapeOne(hex);
139
+ // re-escape as 16 or 32 bit code units
140
+ return Array.from(unescaped).map(ch => escapeRegexCharIfSyntax(ch)).join('');
141
+ }
142
+ /**
143
+ * Escape a string (\uxxxx form) if there are any problematic codepoints
144
+ */
145
+ export function escapeStringForRegex(s) {
146
+ return s.split('').map(ch => escapeRegexCharIfSyntax(ch)).join('');
147
+ }
148
+ /**
149
+ * Unescapes a string according to UTS#18§1.1, see <https://www.unicode.org/reports/tr18/#Hex_notation>
150
+ * @param s escaped string
151
+ * @returns
152
+ */
153
+ export function unescapeStringToRegex(s) {
154
+ if (!s) {
155
+ return s;
156
+ }
157
+ try {
158
+ /**
159
+ * process one regex match
160
+ * @param str ignored
161
+ * @param matched the entire match such as '0127' or '22 22'
162
+ * @returns the unescaped match
163
+ */
164
+ function processMatch(str, matched) {
165
+ const codepoints = matched.split(' ');
166
+ const unescaped = codepoints.map(regexOne);
167
+ return unescaped.join('');
168
+ }
169
+ s = s.replaceAll(MATCH_HEX_ESCAPE, processMatch);
170
+ }
171
+ catch (e) {
172
+ if (e instanceof RangeError) {
173
+ throw new UnescapeError(`Out of range while unescaping '${s}': ${e.message}`, { cause: e });
174
+ /* c8 ignore next 3 */
175
+ }
176
+ else {
177
+ throw e; // pass through some other error
178
+ }
179
+ }
180
+ return s;
181
+ }
182
+ /** True if this string *could* be a UTF-32 single char */
183
+ export function isOneChar(value) {
184
+ return [...value].length === 1;
185
+ }
186
+ export function toOneChar(value) {
187
+ if (!isOneChar(value)) {
188
+ throw Error(`Not a single char: ${value}`);
189
+ }
190
+ return value.codePointAt(0);
191
+ }
192
+ export function describeCodepoint(ch) {
193
+ let s;
194
+ const p = BadStringAnalyzer.getProblem(ch);
195
+ if (p != null) {
196
+ // for example: 'PUA (U+E010)'
197
+ s = p;
198
+ }
199
+ else {
200
+ // for example: '"a" (U+61)'
201
+ s = `"${String.fromCodePoint(ch)}"`;
202
+ }
203
+ return `${s} (U+${Number(ch).toString(16).toUpperCase()})`;
204
+ }
205
+ export var BadStringType;
206
+ (function (BadStringType) {
207
+ BadStringType["pua"] = "PUA";
208
+ BadStringType["unassigned"] = "Unassigned";
209
+ BadStringType["illegal"] = "Illegal";
210
+ BadStringType["denormalized"] = "Denormalized";
211
+ })(BadStringType || (BadStringType = {}));
212
+ ;
213
+ // Following from kmx_xstring.h / .cpp
214
+ const Uni_LEAD_SURROGATE_START = 0xD800;
215
+ const Uni_LEAD_SURROGATE_END = 0xDBFF;
216
+ const Uni_TRAIL_SURROGATE_START = 0xDC00;
217
+ const Uni_TRAIL_SURROGATE_END = 0xDFFF;
218
+ const Uni_SURROGATE_START = Uni_LEAD_SURROGATE_START;
219
+ const Uni_SURROGATE_END = Uni_TRAIL_SURROGATE_END;
220
+ const Uni_FD_NONCHARACTER_START = 0xFDD0;
221
+ const Uni_FD_NONCHARACTER_END = 0xFDEF;
222
+ const Uni_FFFE_NONCHARACTER = 0xFFFE;
223
+ const Uni_PLANE_MASK = 0x1F0000;
224
+ const Uni_MAX_CODEPOINT = 0x10FFFF;
225
+ // plane 0, 15, and 16 PUA
226
+ const Uni_PUA_00_START = 0xE000;
227
+ const Uni_PUA_00_END = 0xF8FF;
228
+ const Uni_PUA_15_START = 0x0F0000;
229
+ const Uni_PUA_15_END = 0x0FFFFD;
230
+ const Uni_PUA_16_START = 0x100000;
231
+ const Uni_PUA_16_END = 0x10FFFD;
232
+ /**
233
+ * @brief True if a lead surrogate
234
+ * \def Uni_IsSurrogate1
235
+ */
236
+ function Uni_IsSurrogate1(ch) {
237
+ return ((ch) >= Uni_LEAD_SURROGATE_START && (ch) <= Uni_LEAD_SURROGATE_END);
238
+ }
239
+ /**
240
+ * @brief True if a trail surrogate
241
+ * \def Uni_IsSurrogate2
242
+ */
243
+ function Uni_IsSurrogate2(ch) {
244
+ return ((ch) >= Uni_TRAIL_SURROGATE_START && (ch) <= Uni_TRAIL_SURROGATE_END);
245
+ }
246
+ /**
247
+ * @brief True if any surrogate
248
+ * \def UniIsSurrogate
249
+ */
250
+ function Uni_IsSurrogate(ch) {
251
+ return (Uni_IsSurrogate1(ch) || Uni_IsSurrogate2(ch));
252
+ }
253
+ function Uni_IsEndOfPlaneNonCharacter(ch) {
254
+ return (((ch) & Uni_FFFE_NONCHARACTER) == Uni_FFFE_NONCHARACTER); // matches FFFF or FFFE
255
+ }
256
+ function Uni_IsNoncharacter(ch) {
257
+ return (((ch) >= Uni_FD_NONCHARACTER_START && (ch) <= Uni_FD_NONCHARACTER_END) || Uni_IsEndOfPlaneNonCharacter(ch));
258
+ }
259
+ function Uni_InCodespace(ch) {
260
+ return (ch >= 0 && ch <= Uni_MAX_CODEPOINT);
261
+ }
262
+ ;
263
+ function Uni_IsValid1(ch) {
264
+ return (Uni_InCodespace(ch) && !Uni_IsSurrogate(ch) && !Uni_IsNoncharacter(ch));
265
+ }
266
+ export function isValidUnicode(start, end) {
267
+ if (!end) {
268
+ // single char
269
+ return Uni_IsValid1(start);
270
+ }
271
+ else if (!Uni_IsValid1(end) || !Uni_IsValid1(start) || (end < start)) {
272
+ // start or end out of range, or inverted range
273
+ return false;
274
+ }
275
+ else if ((start <= Uni_SURROGATE_END) && (end >= Uni_SURROGATE_START)) {
276
+ // contains some of the surrogate range
277
+ return false;
278
+ }
279
+ else if ((start <= Uni_FD_NONCHARACTER_END) && (end >= Uni_FD_NONCHARACTER_START)) {
280
+ // contains some of the noncharacter range
281
+ return false;
282
+ }
283
+ else if ((start & Uni_PLANE_MASK) != (end & Uni_PLANE_MASK)) {
284
+ // start and end are on different planes, meaning that the U+__FFFE/U+__FFFF noncharacters
285
+ // are contained.
286
+ // As a reminder, we already checked that start/end are themselves valid,
287
+ // so we know that 'end' is not on a noncharacter at end of plane.
288
+ return false;
289
+ }
290
+ else {
291
+ return true;
292
+ }
293
+ }
294
+ export function isPUA(ch) {
295
+ return ((ch >= Uni_PUA_00_START && ch <= Uni_PUA_00_END) ||
296
+ (ch >= Uni_PUA_15_START && ch <= Uni_PUA_15_END) ||
297
+ (ch >= Uni_PUA_16_START && ch <= Uni_PUA_16_END));
298
+ }
299
+ class BadStringMap extends Map {
300
+ toString() {
301
+ if (!this.size) {
302
+ return "{}";
303
+ }
304
+ return Array.from(this.entries()).map(([t, s]) => `${t}: ${Array.from(s.values()).map(describeCodepoint).join(' ')}`).join(', ');
305
+ }
306
+ }
307
+ /** abstract class for analyzing and categorizing strings */
308
+ export class StringAnalyzer {
309
+ /** add a string for analysis */
310
+ add(s) {
311
+ for (const c of [...s]) {
312
+ const ch = c.codePointAt(0);
313
+ const problem = this.analyzeCodePoint(c, ch);
314
+ if (problem) {
315
+ this.addProblem(ch, problem);
316
+ }
317
+ }
318
+ }
319
+ /** internal interface for the result of an analysis */
320
+ addProblem(ch, type) {
321
+ if (!this.m.has(type)) {
322
+ this.m.set(type, new Set());
323
+ }
324
+ this.m.get(type).add(ch);
325
+ }
326
+ /** get the results of the analysis */
327
+ analyze() {
328
+ if (this.m.size == 0) {
329
+ return null;
330
+ }
331
+ else {
332
+ return this.m;
333
+ }
334
+ }
335
+ /** internal map */
336
+ m = new BadStringMap();
337
+ }
338
+ /** analyze a string looking for bad unicode */
339
+ export class BadStringAnalyzer extends StringAnalyzer {
340
+ /** analyze one codepoint */
341
+ analyzeCodePoint(c, ch) {
342
+ return BadStringAnalyzer.getProblem(ch);
343
+ }
344
+ /** export analyzer function */
345
+ static getProblem(ch) {
346
+ if (!isValidUnicode(ch)) {
347
+ return BadStringType.illegal;
348
+ }
349
+ else if (isPUA(ch)) {
350
+ return BadStringType.pua;
351
+ }
352
+ else { // TODO-LDML: unassigned
353
+ return null;
354
+ }
355
+ }
356
+ }
357
+ /** Analyzer that checks if something isn't NFD */
358
+ export class NFDAnalyzer extends StringAnalyzer {
359
+ analyzeCodePoint(c, ch) {
360
+ const nfd = c.normalize("NFD");
361
+ if (c !== nfd) {
362
+ return BadStringType.denormalized;
363
+ }
364
+ else {
365
+ return null;
366
+ }
367
+ }
368
+ }
363
369
  //# sourceMappingURL=util.js.map
370
+ //# debugId=91216ba4-c47b-5153-87f2-ec7858626e3a