@keymanapp/common-types 18.0.41-alpha → 18.0.46-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 (189) hide show
  1. package/build/src/consts/virtual-key-constants.d.ts +191 -191
  2. package/build/src/consts/virtual-key-constants.js +221 -221
  3. package/build/src/consts/virtual-key-constants.js.map +1 -1
  4. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts +5 -5
  5. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js +72 -72
  6. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js.map +1 -1
  7. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts +28 -28
  8. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js +120 -120
  9. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js.map +1 -1
  10. package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts +95 -95
  11. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js +52 -52
  12. package/build/src/kmx/element-string.d.ts +23 -23
  13. package/build/src/kmx/element-string.js +125 -125
  14. package/build/src/kmx/element-string.js.map +1 -1
  15. package/build/src/kmx/keyman-targets.d.ts +20 -20
  16. package/build/src/kmx/keyman-targets.js +79 -79
  17. package/build/src/kmx/keyman-targets.js.map +1 -1
  18. package/build/src/kmx/kmx-builder.d.ts +32 -32
  19. package/build/src/kmx/kmx-builder.js +189 -189
  20. package/build/src/kmx/kmx-builder.js.map +1 -1
  21. package/build/src/kmx/kmx-file-reader.d.ts +13 -13
  22. package/build/src/kmx/kmx-file-reader.js +134 -134
  23. package/build/src/kmx/kmx-file-reader.js.map +1 -1
  24. package/build/src/kmx/kmx-plus-builder/build-disp.d.ts +18 -18
  25. package/build/src/kmx/kmx-plus-builder/build-disp.js +27 -27
  26. package/build/src/kmx/kmx-plus-builder/build-disp.js.map +1 -1
  27. package/build/src/kmx/kmx-plus-builder/build-elem.d.ts +28 -28
  28. package/build/src/kmx/kmx-plus-builder/build-elem.js +89 -89
  29. package/build/src/kmx/kmx-plus-builder/build-elem.js.map +1 -1
  30. package/build/src/kmx/kmx-plus-builder/build-keys.d.ts +56 -56
  31. package/build/src/kmx/kmx-plus-builder/build-keys.js +107 -107
  32. package/build/src/kmx/kmx-plus-builder/build-keys.js.map +1 -1
  33. package/build/src/kmx/kmx-plus-builder/build-layr.d.ts +53 -53
  34. package/build/src/kmx/kmx-plus-builder/build-layr.js +101 -101
  35. package/build/src/kmx/kmx-plus-builder/build-layr.js.map +1 -1
  36. package/build/src/kmx/kmx-plus-builder/build-list.d.ts +35 -35
  37. package/build/src/kmx/kmx-plus-builder/build-list.js +66 -66
  38. package/build/src/kmx/kmx-plus-builder/build-list.js.map +1 -1
  39. package/build/src/kmx/kmx-plus-builder/build-loca.d.ts +11 -11
  40. package/build/src/kmx/kmx-plus-builder/build-loca.js +21 -21
  41. package/build/src/kmx/kmx-plus-builder/build-loca.js.map +1 -1
  42. package/build/src/kmx/kmx-plus-builder/build-meta.d.ts +16 -16
  43. package/build/src/kmx/kmx-plus-builder/build-meta.js +20 -20
  44. package/build/src/kmx/kmx-plus-builder/build-sect.d.ts +15 -15
  45. package/build/src/kmx/kmx-plus-builder/build-sect.js +15 -15
  46. package/build/src/kmx/kmx-plus-builder/build-sect.js.map +1 -1
  47. package/build/src/kmx/kmx-plus-builder/build-strs.d.ts +22 -22
  48. package/build/src/kmx/kmx-plus-builder/build-strs.js +46 -46
  49. package/build/src/kmx/kmx-plus-builder/build-strs.js.map +1 -1
  50. package/build/src/kmx/kmx-plus-builder/build-tran.d.ts +32 -32
  51. package/build/src/kmx/kmx-plus-builder/build-tran.js +69 -69
  52. package/build/src/kmx/kmx-plus-builder/build-tran.js.map +1 -1
  53. package/build/src/kmx/kmx-plus-builder/build-uset.d.ts +30 -30
  54. package/build/src/kmx/kmx-plus-builder/build-uset.js +60 -60
  55. package/build/src/kmx/kmx-plus-builder/build-uset.js.map +1 -1
  56. package/build/src/kmx/kmx-plus-builder/build-vars.d.ts +21 -21
  57. package/build/src/kmx/kmx-plus-builder/build-vars.js +48 -48
  58. package/build/src/kmx/kmx-plus-builder/build-vars.js.map +1 -1
  59. package/build/src/kmx/kmx-plus-builder/builder-section.d.ts +9 -9
  60. package/build/src/kmx/kmx-plus-builder/builder-section.js +2 -2
  61. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts +42 -42
  62. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js +137 -137
  63. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js.map +1 -1
  64. package/build/src/kmx/kmx-plus.d.ts +322 -322
  65. package/build/src/kmx/kmx-plus.js +830 -830
  66. package/build/src/kmx/kmx-plus.js.map +1 -1
  67. package/build/src/kmx/kmx.d.ts +233 -233
  68. package/build/src/kmx/kmx.js +302 -302
  69. package/build/src/kmx/kmx.js.map +1 -1
  70. package/build/src/kmx/string-list.d.ts +35 -35
  71. package/build/src/kmx/string-list.js +88 -88
  72. package/build/src/kmx/string-list.js.map +1 -1
  73. package/build/src/kpj/keyman-developer-project.d.ts +78 -78
  74. package/build/src/kpj/keyman-developer-project.js +195 -195
  75. package/build/src/kpj/keyman-developer-project.js.map +1 -1
  76. package/build/src/kpj/kpj-file-reader.d.ts +18 -18
  77. package/build/src/kpj/kpj-file-reader.js +119 -119
  78. package/build/src/kpj/kpj-file-reader.js.map +1 -1
  79. package/build/src/kpj/kpj-file.d.ts +39 -39
  80. package/build/src/kpj/kpj-file.js +10 -10
  81. package/build/src/kvk/kvk-file-reader.d.ts +4 -4
  82. package/build/src/kvk/kvk-file-reader.js +37 -37
  83. package/build/src/kvk/kvk-file-reader.js.map +1 -1
  84. package/build/src/kvk/kvk-file-writer.d.ts +19 -19
  85. package/build/src/kvk/kvk-file-writer.js +77 -77
  86. package/build/src/kvk/kvk-file-writer.js.map +1 -1
  87. package/build/src/kvk/kvk-file.d.ts +66 -66
  88. package/build/src/kvk/kvk-file.d.ts.map +1 -1
  89. package/build/src/kvk/kvk-file.js +90 -90
  90. package/build/src/kvk/kvk-file.js.map +1 -1
  91. package/build/src/kvk/kvks-file-reader.d.ts +23 -23
  92. package/build/src/kvk/kvks-file-reader.js +175 -175
  93. package/build/src/kvk/kvks-file-reader.js.map +1 -1
  94. package/build/src/kvk/kvks-file-writer.d.ts +6 -6
  95. package/build/src/kvk/kvks-file-writer.js +106 -106
  96. package/build/src/kvk/kvks-file-writer.js.map +1 -1
  97. package/build/src/kvk/kvks-file.d.ts +43 -43
  98. package/build/src/kvk/kvks-file.js +9 -9
  99. package/build/src/kvk/visual-keyboard.d.ts +44 -44
  100. package/build/src/kvk/visual-keyboard.js +75 -75
  101. package/build/src/kvk/visual-keyboard.js.map +1 -1
  102. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts +60 -60
  103. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js +19 -19
  104. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts +95 -95
  105. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js +409 -409
  106. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js.map +1 -1
  107. package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts +170 -170
  108. package/build/src/ldml-keyboard/ldml-keyboard-xml.js +55 -55
  109. package/build/src/ldml-keyboard/pattern-parser.d.ts +201 -201
  110. package/build/src/ldml-keyboard/pattern-parser.js +490 -490
  111. package/build/src/ldml-keyboard/pattern-parser.js.map +1 -1
  112. package/build/src/ldml-keyboard/unicodeset-parser-api.d.ts +37 -37
  113. package/build/src/ldml-keyboard/unicodeset-parser-api.js +27 -27
  114. package/build/src/main.d.ts +33 -33
  115. package/build/src/main.js +32 -32
  116. package/build/src/package/kmp-json-file.d.ts +115 -115
  117. package/build/src/package/kmp-json-file.js +1 -1
  118. package/build/src/package/kps-file.d.ts +175 -175
  119. package/build/src/package/kps-file.js +15 -15
  120. package/build/src/schema-validators.d.ts +13 -13
  121. package/build/src/schema-validators.js +25 -25
  122. package/build/src/schemas/displaymap.schema.d.ts +57 -57
  123. package/build/src/schemas/displaymap.schema.js +35 -35
  124. package/build/src/schemas/displaymap.schema.validator.d.mts +2 -2
  125. package/build/src/schemas/displaymap.schema.validator.mjs +266 -266
  126. package/build/src/schemas/displaymap.schema.validator.mjs.map +1 -1
  127. package/build/src/schemas/keyboard_info.schema.d.ts +209 -209
  128. package/build/src/schemas/keyboard_info.schema.js +98 -98
  129. package/build/src/schemas/keyboard_info.schema.validator.d.mts +2 -2
  130. package/build/src/schemas/keyboard_info.schema.validator.mjs +1160 -1160
  131. package/build/src/schemas/keyboard_info.schema.validator.mjs.map +1 -1
  132. package/build/src/schemas/keyman-touch-layout.clean.spec.d.ts +227 -227
  133. package/build/src/schemas/keyman-touch-layout.clean.spec.js +151 -151
  134. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.d.mts +2 -2
  135. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.mjs +1094 -1094
  136. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.mjs.map +1 -1
  137. package/build/src/schemas/keyman-touch-layout.spec.d.ts +229 -229
  138. package/build/src/schemas/keyman-touch-layout.spec.js +140 -140
  139. package/build/src/schemas/keyman-touch-layout.spec.validator.d.mts +2 -2
  140. package/build/src/schemas/keyman-touch-layout.spec.validator.mjs +1436 -1436
  141. package/build/src/schemas/keyman-touch-layout.spec.validator.mjs.map +1 -1
  142. package/build/src/schemas/kmp.schema.d.ts +324 -324
  143. package/build/src/schemas/kmp.schema.js +353 -353
  144. package/build/src/schemas/kmp.schema.validator.d.mts +2 -2
  145. package/build/src/schemas/kmp.schema.validator.mjs +1627 -1627
  146. package/build/src/schemas/kmp.schema.validator.mjs.map +1 -1
  147. package/build/src/schemas/kpj-9.0.schema.d.ts +152 -152
  148. package/build/src/schemas/kpj-9.0.schema.js +131 -131
  149. package/build/src/schemas/kpj-9.0.schema.validator.d.mts +2 -2
  150. package/build/src/schemas/kpj-9.0.schema.validator.mjs +655 -655
  151. package/build/src/schemas/kpj-9.0.schema.validator.mjs.map +1 -1
  152. package/build/src/schemas/kpj.schema.d.ts +122 -122
  153. package/build/src/schemas/kpj.schema.js +129 -129
  154. package/build/src/schemas/kpj.schema.validator.d.mts +2 -2
  155. package/build/src/schemas/kpj.schema.validator.mjs +515 -515
  156. package/build/src/schemas/kpj.schema.validator.mjs.map +1 -1
  157. package/build/src/schemas/kvks.schema.d.ts +160 -160
  158. package/build/src/schemas/kvks.schema.js +182 -182
  159. package/build/src/schemas/kvks.schema.validator.d.mts +2 -2
  160. package/build/src/schemas/kvks.schema.validator.mjs +625 -625
  161. package/build/src/schemas/kvks.schema.validator.mjs.map +1 -1
  162. package/build/src/schemas/ldml-keyboard3.schema.d.ts +635 -635
  163. package/build/src/schemas/ldml-keyboard3.schema.js +696 -696
  164. package/build/src/schemas/ldml-keyboard3.schema.validator.d.mts +2 -2
  165. package/build/src/schemas/ldml-keyboard3.schema.validator.mjs +3117 -3117
  166. package/build/src/schemas/ldml-keyboard3.schema.validator.mjs.map +1 -1
  167. package/build/src/schemas/ldml-keyboardtest3.schema.d.ts +192 -192
  168. package/build/src/schemas/ldml-keyboardtest3.schema.js +225 -225
  169. package/build/src/schemas/ldml-keyboardtest3.schema.validator.d.mts +2 -2
  170. package/build/src/schemas/ldml-keyboardtest3.schema.validator.mjs +744 -744
  171. package/build/src/schemas/ldml-keyboardtest3.schema.validator.mjs.map +1 -1
  172. package/build/src/schemas.d.ts +2300 -2300
  173. package/build/src/schemas.js +23 -23
  174. package/build/src/util/common-events.d.ts +44 -44
  175. package/build/src/util/common-events.js +26 -26
  176. package/build/src/util/compiler-interfaces.d.ts +371 -371
  177. package/build/src/util/compiler-interfaces.d.ts.map +1 -1
  178. package/build/src/util/compiler-interfaces.js +380 -380
  179. package/build/src/util/compiler-interfaces.js.map +1 -1
  180. package/build/src/util/errors.d.ts +5 -5
  181. package/build/src/util/errors.js +5 -5
  182. package/build/src/util/file-types.d.ts +93 -93
  183. package/build/src/util/file-types.d.ts.map +1 -1
  184. package/build/src/util/file-types.js +142 -142
  185. package/build/src/util/file-types.js.map +1 -1
  186. package/build/src/util/util.d.ts +98 -98
  187. package/build/src/util/util.js +368 -368
  188. package/build/src/util/util.js.map +1 -1
  189. package/package.json +3 -3
@@ -1,411 +1,411 @@
1
1
 
2
- !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]="065afd3b-524c-565a-b20d-4b1e3cfd778f")}catch(e){}}();
3
- import * as xml2js from 'xml2js';
4
- import { ImportStatus } from './ldml-keyboard-xml.js';
5
- import { boxXmlArray } from '../util/util.js';
6
- import { constants } from '@keymanapp/ldml-keyboard-constants';
7
- import { CommonTypesMessages } from '../util/common-events.js';
8
- import SchemaValidators from '../schema-validators.js';
9
- ;
10
- export class LDMLKeyboardXMLSourceFileReaderOptions {
11
- importsPath;
12
- }
13
- ;
14
- export class LDMLKeyboardXMLSourceFileReader {
15
- options;
16
- callbacks;
17
- constructor(options, callbacks) {
18
- this.options = options;
19
- this.callbacks = callbacks;
20
- }
21
- static get defaultImportsURL() {
22
- return ['../import/', import.meta.url];
23
- }
24
- readImportFile(version, subpath) {
25
- const importPath = this.callbacks.resolveFilename(this.options.importsPath, `${version}/${subpath}`);
26
- return this.callbacks.loadFile(importPath);
27
- }
28
- /**
29
- * xml2js will not place single-entry objects into arrays.
30
- * Easiest way to fix this is to box them ourselves as needed
31
- * @param source any
32
- * @returns true on success, false on failure
33
- */
34
- boxArrays(source) {
35
- if (source?.keyboard3) {
36
- if (!source.keyboard3.keys) {
37
- // Note: this is here to put a substrate for the imported keys
38
- source.keyboard3.keys = {
39
- key: [],
40
- };
41
- }
42
- if (!source.keyboard3.keys.import) {
43
- source.keyboard3.keys.import = [];
44
- }
45
- if (!source.keyboard3.forms) {
46
- source.keyboard3.forms = {
47
- form: [],
48
- };
49
- }
50
- if (!source.keyboard3.forms.import) {
51
- source.keyboard3.forms.import = [];
52
- }
53
- }
54
- boxXmlArray(source?.keyboard3, 'layers');
55
- boxXmlArray(source?.keyboard3?.displays, 'display');
56
- boxXmlArray(source?.keyboard3?.keys, 'key');
57
- boxXmlArray(source?.keyboard3?.flicks, 'flick');
58
- boxXmlArray(source?.keyboard3?.locales, 'locale');
59
- boxXmlArray(source?.keyboard3, 'transforms');
60
- if (source?.keyboard3?.layers) {
61
- for (let layers of source?.keyboard3?.layers) {
62
- boxXmlArray(layers, 'layer');
63
- if (layers?.layer) {
64
- for (let layer of layers?.layer) {
65
- boxXmlArray(layer, 'row');
66
- }
67
- }
68
- }
69
- }
70
- if (source?.keyboard3?.forms?.form) {
71
- boxXmlArray(source?.keyboard3?.forms, 'form');
72
- for (let form of source?.keyboard3?.forms?.form) {
73
- boxXmlArray(form, 'scanCodes');
74
- }
75
- }
76
- if (source?.keyboard3?.flicks) {
77
- boxXmlArray(source?.keyboard3?.flicks, 'flick');
78
- for (let flick of source?.keyboard3?.flicks?.flick) {
79
- boxXmlArray(flick, 'flickSegment');
80
- }
81
- }
82
- if (source?.keyboard3?.variables) {
83
- boxXmlArray(source?.keyboard3?.variables, 'set');
84
- boxXmlArray(source?.keyboard3?.variables, 'string');
85
- boxXmlArray(source?.keyboard3?.variables, 'uset');
86
- }
87
- if (source?.keyboard3?.transforms) {
88
- for (let transforms of source.keyboard3.transforms) {
89
- boxXmlArray(transforms, 'transformGroup');
90
- for (let transformGroup of transforms.transformGroup) {
91
- boxXmlArray(transformGroup, 'transform');
92
- boxXmlArray(transformGroup, 'reorder');
93
- }
94
- }
95
- }
96
- return this.boxImportsAndSpecials(source, 'keyboard3');
97
- }
98
- /**
99
- * Recurse over object, boxing up any specials or imports
100
- * @param obj any object to be traversed
101
- * @param subtag the leafmost enclosing tag such as 'keyboard3'
102
- * @returns true on success, false on failure
103
- */
104
- boxImportsAndSpecials(obj, subtag) {
105
- if (!obj)
106
- return true;
107
- if (Array.isArray(obj)) {
108
- for (const sub of obj) {
109
- // retain the same subtag
110
- if (!this.boxImportsAndSpecials(sub, subtag)) {
111
- return false;
112
- }
113
- }
114
- }
115
- else if (typeof obj === 'object') {
116
- for (const key of Object.keys(obj)) {
117
- if (key === 'special') {
118
- boxXmlArray(obj, key);
119
- }
120
- else if (key === 'import') {
121
- // Need to 'box it up' first for processing
122
- boxXmlArray(obj, key);
123
- // Now, resolve the import
124
- if (!this.resolveImports(obj, subtag)) {
125
- return false;
126
- }
127
- // now delete the import array we so carefully constructed, the caller does not
128
- // want to see it.
129
- delete obj['import'];
130
- }
131
- else {
132
- if (!this.boxImportsAndSpecials(obj[key], key)) {
133
- return false;
134
- }
135
- }
136
- }
137
- }
138
- return true;
139
- }
140
- /**
141
- *
142
- * @param obj object to be imported into
143
- * @param subtag obj's element tag, e.g. `keys`
144
- * @returns true on success, false on failure
145
- */
146
- resolveImports(obj, subtag) {
147
- // These are in reverse order, because the imports insert at the beginning of the array.
148
- // first, the explicit imports
149
- for (const asImport of ([...obj['import']].reverse())) {
150
- if (!this.resolveOneImport(obj, subtag, asImport)) {
151
- return false;
152
- }
153
- }
154
- // then, the implied imports
155
- if (subtag === 'keys') {
156
- // <import base="cldr" path="45/keys-Latn-implied.xml"/>
157
- if (!this.resolveOneImport(obj, subtag, {
158
- base: constants.cldr_import_base,
159
- path: constants.cldr_implied_keys_import
160
- }, true)) {
161
- return false;
162
- }
163
- }
164
- else if (subtag === 'forms') {
165
- // <import base="cldr" path="45/scanCodes-implied.xml"/>
166
- if (!this.resolveOneImport(obj, subtag, {
167
- base: constants.cldr_import_base,
168
- path: constants.cldr_implied_forms_import
169
- }, true)) {
170
- return false;
171
- }
172
- }
173
- return true;
174
- }
175
- /**
176
- * @param obj the object being imported into
177
- * @param subtag obj's element tag, e.g. `keys`
178
- * @param asImport the import structure
179
- * @param implied true if it is an implied import
180
- * @returns true on success, false on failure
181
- */
182
- resolveOneImport(obj, subtag, asImport, implied) {
183
- const { base, path } = asImport;
184
- if (base !== constants.cldr_import_base) {
185
- this.callbacks.reportMessage(CommonTypesMessages.Error_ImportInvalidBase({ base, path, subtag }));
186
- return false;
187
- }
188
- const paths = path.split('/');
189
- if (paths[0] == '' || paths[1] == '' || paths.length !== 2) {
190
- this.callbacks.reportMessage(CommonTypesMessages.Error_ImportInvalidPath({ base, path, subtag }));
191
- return false;
192
- }
193
- const importData = this.readImportFile(paths[0], paths[1]);
194
- if (!importData || !importData.length) {
195
- this.callbacks.reportMessage(CommonTypesMessages.Error_ImportReadFail({ base, path, subtag }));
196
- return false;
197
- }
198
- const importXml = this.loadUnboxed(importData); // TODO-LDML: have to load as any because it is an arbitrary part
199
- const importRootNode = importXml[subtag]; // e.g. <keys/>
200
- // importXml will have one property: the root element.
201
- if (!importRootNode) {
202
- this.callbacks.reportMessage(CommonTypesMessages.Error_ImportWrongRoot({ base, path, subtag }));
203
- return false;
204
- }
205
- // pull all children of importXml[subtag] into obj
206
- for (const subsubtag of Object.keys(importRootNode).reverse()) { // e.g. <key/>
207
- const subsubval = importRootNode[subsubtag];
208
- const basePath = `${base}/${path}`;
209
- if (!Array.isArray(subsubval)) {
210
- // This is somewhat of an internal error, indicating that a non-mergeable XML file was imported
211
- // Not exercisable with the standard LDML imports.
212
- this.callbacks.reportMessage(CommonTypesMessages.Error_ImportMergeFail({ base, path, subtag, subsubtag }));
213
- return false;
214
- }
215
- // Mark all children as an import
216
- subsubval.forEach(o => o[ImportStatus.import] = basePath);
217
- if (implied) {
218
- // mark all children as an implied import
219
- subsubval.forEach(o => o[ImportStatus.impliedImport] = basePath);
220
- }
221
- if (!obj[subsubtag]) {
222
- obj[subsubtag] = []; // start with empty array
223
- }
224
- obj[subsubtag] = [...subsubval, ...obj[subsubtag]];
225
- }
226
- return true;
227
- }
228
- /**
229
- * @returns true if valid, false if invalid
230
- */
231
- validate(source) {
232
- if (!SchemaValidators.ldmlKeyboard3(source)) {
233
- for (let err of SchemaValidators.ldmlKeyboard3.errors) {
234
- this.callbacks.reportMessage(CommonTypesMessages.Error_SchemaValidationError({
235
- instancePath: err.instancePath,
236
- keyword: err.keyword,
237
- message: err.message || 'Unknown AJV Error',
238
- params: Object.entries(err.params || {}).sort().map(([k, v]) => `${k}="${v}"`).join(' '),
239
- }));
240
- }
241
- return false;
242
- }
243
- return true;
244
- }
245
- loadUnboxed(file) {
246
- let source = (() => {
247
- let a;
248
- let parser = new xml2js.Parser({
249
- explicitArray: false,
250
- mergeAttrs: true,
251
- includeWhiteChars: false,
252
- emptyTag: {}
253
- // Why "as any"? xml2js is broken:
254
- // https://github.com/Leonidas-from-XIV/node-xml2js/issues/648 means
255
- // that an old version of `emptyTag` is used which doesn't support
256
- // functions, but DefinitelyTyped is requiring use of function or a
257
- // string. See also notes at
258
- // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59259#issuecomment-1254405470
259
- // An alternative fix would be to pull xml2js directly from github
260
- // rather than using the version tagged on npmjs.com.
261
- });
262
- parser.parseString(file, (e, r) => { a = r; }); // TODO-LDML: isn't 'e' the error?
263
- return a;
264
- })();
265
- return source;
266
- }
267
- /**
268
- * @param file
269
- * @returns source on success, otherwise null
270
- */
271
- load(file) {
272
- if (!file) {
273
- return null;
274
- }
275
- const source = this.loadUnboxed(file);
276
- if (this.boxArrays(source)) {
277
- return source;
278
- }
279
- else {
280
- return null;
281
- }
282
- }
283
- loadTestDataUnboxed(file) {
284
- let source = (() => {
285
- let a;
286
- let parser = new xml2js.Parser({
287
- // explicitArray: false,
288
- preserveChildrenOrder: true,
289
- explicitChildren: true, // needed for test data
290
- // mergeAttrs: true,
291
- // includeWhiteChars: false,
292
- // emptyTag: {} as any
293
- // Why "as any"? xml2js is broken:
294
- // https://github.com/Leonidas-from-XIV/node-xml2js/issues/648 means
295
- // that an old version of `emptyTag` is used which doesn't support
296
- // functions, but DefinitelyTyped is requiring use of function or a
297
- // string. See also notes at
298
- // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59259#issuecomment-1254405470
299
- // An alternative fix would be to pull xml2js directly from github
300
- // rather than using the version tagged on npmjs.com.
301
- });
302
- parser.parseString(file, (e, r) => { a = r; }); // TODO-LDML: isn't 'e' the error?
303
- return a; // Why 'any'? Because we need to box up the $'s into proper properties.
304
- })();
305
- return source;
306
- }
307
- /**
308
- * Filter the obj array for a subtag
309
- * @param source array of source objs
310
- * @param subtag subtag to filter on
311
- * @returns
312
- */
313
- findSubtagArray(source, subtag) {
314
- return source?.filter(o => o['#name'] === subtag);
315
- }
316
- /**
317
- * Get exactly one element
318
- * @param source
319
- * @param subtag
320
- * @returns
321
- */
322
- findSubtag(source, subtag) {
323
- const r = this.findSubtagArray(source, subtag);
324
- if (!r || r.length === 0) {
325
- return null;
326
- }
327
- else if (r.length === 1) {
328
- return r[0];
329
- }
330
- else {
331
- this.callbacks.reportMessage(CommonTypesMessages.Error_TestDataUnexpectedArray({ subtag }));
332
- return null; // ERROR
333
- }
334
- }
335
- /**
336
- * The default test data stuffer.
337
- * Just gets $ (the attrs) as the body.
338
- * Override to use something more complex, such as including child nodes.
339
- * @param o object to map
340
- * @param r back ref to reader
341
- */
342
- static defaultMapper = ((o, r) => o?.$);
343
- /**
344
- *
345
- * @param obj target object
346
- * @param source array of $/#name strings
347
- * @param subtag name to extract
348
- * @param mapper custom mapper function
349
- */
350
- stuffBoxes(obj, source, subtag, asArray, mapper) {
351
- if (!mapper) {
352
- mapper = LDMLKeyboardXMLSourceFileReader.defaultMapper;
353
- }
354
- if (asArray) {
355
- const r = this;
356
- obj[subtag] = this.findSubtagArray(source, subtag)?.map((v) => mapper(v, r)); // extract contents only
357
- }
358
- else {
359
- obj[subtag] = mapper(this.findSubtag(source, subtag), this); // run the mapper once
360
- }
361
- }
362
- boxTestDataArrays(raw) {
363
- if (!raw)
364
- return null;
365
- const a = {
366
- keyboardTest3: {
367
- conformsTo: raw?.keyboardTest3?.$?.conformsTo,
368
- }
369
- };
370
- const $$ = raw?.keyboardTest3?.$$;
371
- this.stuffBoxes(a.keyboardTest3, $$, 'info');
372
- this.stuffBoxes(a.keyboardTest3, $$, 'repertoire', true);
373
- this.stuffBoxes(a.keyboardTest3, $$, 'tests', true, (o, r) => {
374
- // start with basic unpack
375
- const tests = LDMLKeyboardXMLSourceFileReader.defaultMapper(o, r);
376
- // add ingredients
377
- r.stuffBoxes(tests, o.$$, 'test', true, (o, r) => {
378
- // start with basic unpack
379
- const test = LDMLKeyboardXMLSourceFileReader.defaultMapper(o, r);
380
- // add ingredients
381
- const $$ = o.$$;
382
- r.stuffBoxes(test, $$, 'startContext'); // singleton
383
- // now the actions
384
- test.actions = $$.map(v => {
385
- const type = v['#name']; // element name
386
- if (type === 'startContext') {
387
- return null; // handled above
388
- }
389
- const subv = LDMLKeyboardXMLSourceFileReader.defaultMapper(v, r);
390
- return Object.assign({ type }, subv);
391
- }).filter(v => v !== null);
392
- return test;
393
- });
394
- return tests;
395
- });
396
- return a;
397
- }
398
- /**
399
- * @param file test file
400
- * @returns source on success, otherwise null
401
- */
402
- loadTestData(file) {
403
- if (!file) {
404
- return null;
405
- }
406
- const source = this.loadTestDataUnboxed(file);
407
- return this.boxTestDataArrays(source);
408
- }
409
- }
2
+ !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]="ad64e78e-6c60-5376-bc04-4a7f613d99f9")}catch(e){}}();
3
+ import * as xml2js from 'xml2js';
4
+ import { ImportStatus } from './ldml-keyboard-xml.js';
5
+ import { boxXmlArray } from '../util/util.js';
6
+ import { constants } from '@keymanapp/ldml-keyboard-constants';
7
+ import { CommonTypesMessages } from '../util/common-events.js';
8
+ import SchemaValidators from '../schema-validators.js';
9
+ ;
10
+ export class LDMLKeyboardXMLSourceFileReaderOptions {
11
+ importsPath;
12
+ }
13
+ ;
14
+ export class LDMLKeyboardXMLSourceFileReader {
15
+ options;
16
+ callbacks;
17
+ constructor(options, callbacks) {
18
+ this.options = options;
19
+ this.callbacks = callbacks;
20
+ }
21
+ static get defaultImportsURL() {
22
+ return ['../import/', import.meta.url];
23
+ }
24
+ readImportFile(version, subpath) {
25
+ const importPath = this.callbacks.resolveFilename(this.options.importsPath, `${version}/${subpath}`);
26
+ return this.callbacks.loadFile(importPath);
27
+ }
28
+ /**
29
+ * xml2js will not place single-entry objects into arrays.
30
+ * Easiest way to fix this is to box them ourselves as needed
31
+ * @param source any
32
+ * @returns true on success, false on failure
33
+ */
34
+ boxArrays(source) {
35
+ if (source?.keyboard3) {
36
+ if (!source.keyboard3.keys) {
37
+ // Note: this is here to put a substrate for the imported keys
38
+ source.keyboard3.keys = {
39
+ key: [],
40
+ };
41
+ }
42
+ if (!source.keyboard3.keys.import) {
43
+ source.keyboard3.keys.import = [];
44
+ }
45
+ if (!source.keyboard3.forms) {
46
+ source.keyboard3.forms = {
47
+ form: [],
48
+ };
49
+ }
50
+ if (!source.keyboard3.forms.import) {
51
+ source.keyboard3.forms.import = [];
52
+ }
53
+ }
54
+ boxXmlArray(source?.keyboard3, 'layers');
55
+ boxXmlArray(source?.keyboard3?.displays, 'display');
56
+ boxXmlArray(source?.keyboard3?.keys, 'key');
57
+ boxXmlArray(source?.keyboard3?.flicks, 'flick');
58
+ boxXmlArray(source?.keyboard3?.locales, 'locale');
59
+ boxXmlArray(source?.keyboard3, 'transforms');
60
+ if (source?.keyboard3?.layers) {
61
+ for (let layers of source?.keyboard3?.layers) {
62
+ boxXmlArray(layers, 'layer');
63
+ if (layers?.layer) {
64
+ for (let layer of layers?.layer) {
65
+ boxXmlArray(layer, 'row');
66
+ }
67
+ }
68
+ }
69
+ }
70
+ if (source?.keyboard3?.forms?.form) {
71
+ boxXmlArray(source?.keyboard3?.forms, 'form');
72
+ for (let form of source?.keyboard3?.forms?.form) {
73
+ boxXmlArray(form, 'scanCodes');
74
+ }
75
+ }
76
+ if (source?.keyboard3?.flicks) {
77
+ boxXmlArray(source?.keyboard3?.flicks, 'flick');
78
+ for (let flick of source?.keyboard3?.flicks?.flick) {
79
+ boxXmlArray(flick, 'flickSegment');
80
+ }
81
+ }
82
+ if (source?.keyboard3?.variables) {
83
+ boxXmlArray(source?.keyboard3?.variables, 'set');
84
+ boxXmlArray(source?.keyboard3?.variables, 'string');
85
+ boxXmlArray(source?.keyboard3?.variables, 'uset');
86
+ }
87
+ if (source?.keyboard3?.transforms) {
88
+ for (let transforms of source.keyboard3.transforms) {
89
+ boxXmlArray(transforms, 'transformGroup');
90
+ for (let transformGroup of transforms.transformGroup) {
91
+ boxXmlArray(transformGroup, 'transform');
92
+ boxXmlArray(transformGroup, 'reorder');
93
+ }
94
+ }
95
+ }
96
+ return this.boxImportsAndSpecials(source, 'keyboard3');
97
+ }
98
+ /**
99
+ * Recurse over object, boxing up any specials or imports
100
+ * @param obj any object to be traversed
101
+ * @param subtag the leafmost enclosing tag such as 'keyboard3'
102
+ * @returns true on success, false on failure
103
+ */
104
+ boxImportsAndSpecials(obj, subtag) {
105
+ if (!obj)
106
+ return true;
107
+ if (Array.isArray(obj)) {
108
+ for (const sub of obj) {
109
+ // retain the same subtag
110
+ if (!this.boxImportsAndSpecials(sub, subtag)) {
111
+ return false;
112
+ }
113
+ }
114
+ }
115
+ else if (typeof obj === 'object') {
116
+ for (const key of Object.keys(obj)) {
117
+ if (key === 'special') {
118
+ boxXmlArray(obj, key);
119
+ }
120
+ else if (key === 'import') {
121
+ // Need to 'box it up' first for processing
122
+ boxXmlArray(obj, key);
123
+ // Now, resolve the import
124
+ if (!this.resolveImports(obj, subtag)) {
125
+ return false;
126
+ }
127
+ // now delete the import array we so carefully constructed, the caller does not
128
+ // want to see it.
129
+ delete obj['import'];
130
+ }
131
+ else {
132
+ if (!this.boxImportsAndSpecials(obj[key], key)) {
133
+ return false;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ return true;
139
+ }
140
+ /**
141
+ *
142
+ * @param obj object to be imported into
143
+ * @param subtag obj's element tag, e.g. `keys`
144
+ * @returns true on success, false on failure
145
+ */
146
+ resolveImports(obj, subtag) {
147
+ // These are in reverse order, because the imports insert at the beginning of the array.
148
+ // first, the explicit imports
149
+ for (const asImport of ([...obj['import']].reverse())) {
150
+ if (!this.resolveOneImport(obj, subtag, asImport)) {
151
+ return false;
152
+ }
153
+ }
154
+ // then, the implied imports
155
+ if (subtag === 'keys') {
156
+ // <import base="cldr" path="45/keys-Latn-implied.xml"/>
157
+ if (!this.resolveOneImport(obj, subtag, {
158
+ base: constants.cldr_import_base,
159
+ path: constants.cldr_implied_keys_import
160
+ }, true)) {
161
+ return false;
162
+ }
163
+ }
164
+ else if (subtag === 'forms') {
165
+ // <import base="cldr" path="45/scanCodes-implied.xml"/>
166
+ if (!this.resolveOneImport(obj, subtag, {
167
+ base: constants.cldr_import_base,
168
+ path: constants.cldr_implied_forms_import
169
+ }, true)) {
170
+ return false;
171
+ }
172
+ }
173
+ return true;
174
+ }
175
+ /**
176
+ * @param obj the object being imported into
177
+ * @param subtag obj's element tag, e.g. `keys`
178
+ * @param asImport the import structure
179
+ * @param implied true if it is an implied import
180
+ * @returns true on success, false on failure
181
+ */
182
+ resolveOneImport(obj, subtag, asImport, implied) {
183
+ const { base, path } = asImport;
184
+ if (base !== constants.cldr_import_base) {
185
+ this.callbacks.reportMessage(CommonTypesMessages.Error_ImportInvalidBase({ base, path, subtag }));
186
+ return false;
187
+ }
188
+ const paths = path.split('/');
189
+ if (paths[0] == '' || paths[1] == '' || paths.length !== 2) {
190
+ this.callbacks.reportMessage(CommonTypesMessages.Error_ImportInvalidPath({ base, path, subtag }));
191
+ return false;
192
+ }
193
+ const importData = this.readImportFile(paths[0], paths[1]);
194
+ if (!importData || !importData.length) {
195
+ this.callbacks.reportMessage(CommonTypesMessages.Error_ImportReadFail({ base, path, subtag }));
196
+ return false;
197
+ }
198
+ const importXml = this.loadUnboxed(importData); // TODO-LDML: have to load as any because it is an arbitrary part
199
+ const importRootNode = importXml[subtag]; // e.g. <keys/>
200
+ // importXml will have one property: the root element.
201
+ if (!importRootNode) {
202
+ this.callbacks.reportMessage(CommonTypesMessages.Error_ImportWrongRoot({ base, path, subtag }));
203
+ return false;
204
+ }
205
+ // pull all children of importXml[subtag] into obj
206
+ for (const subsubtag of Object.keys(importRootNode).reverse()) { // e.g. <key/>
207
+ const subsubval = importRootNode[subsubtag];
208
+ const basePath = `${base}/${path}`;
209
+ if (!Array.isArray(subsubval)) {
210
+ // This is somewhat of an internal error, indicating that a non-mergeable XML file was imported
211
+ // Not exercisable with the standard LDML imports.
212
+ this.callbacks.reportMessage(CommonTypesMessages.Error_ImportMergeFail({ base, path, subtag, subsubtag }));
213
+ return false;
214
+ }
215
+ // Mark all children as an import
216
+ subsubval.forEach(o => o[ImportStatus.import] = basePath);
217
+ if (implied) {
218
+ // mark all children as an implied import
219
+ subsubval.forEach(o => o[ImportStatus.impliedImport] = basePath);
220
+ }
221
+ if (!obj[subsubtag]) {
222
+ obj[subsubtag] = []; // start with empty array
223
+ }
224
+ obj[subsubtag] = [...subsubval, ...obj[subsubtag]];
225
+ }
226
+ return true;
227
+ }
228
+ /**
229
+ * @returns true if valid, false if invalid
230
+ */
231
+ validate(source) {
232
+ if (!SchemaValidators.ldmlKeyboard3(source)) {
233
+ for (let err of SchemaValidators.ldmlKeyboard3.errors) {
234
+ this.callbacks.reportMessage(CommonTypesMessages.Error_SchemaValidationError({
235
+ instancePath: err.instancePath,
236
+ keyword: err.keyword,
237
+ message: err.message || 'Unknown AJV Error', // docs say 'message' is optional if 'messages:false' in options
238
+ params: Object.entries(err.params || {}).sort().map(([k, v]) => `${k}="${v}"`).join(' '),
239
+ }));
240
+ }
241
+ return false;
242
+ }
243
+ return true;
244
+ }
245
+ loadUnboxed(file) {
246
+ let source = (() => {
247
+ let a;
248
+ let parser = new xml2js.Parser({
249
+ explicitArray: false,
250
+ mergeAttrs: true,
251
+ includeWhiteChars: false,
252
+ emptyTag: {}
253
+ // Why "as any"? xml2js is broken:
254
+ // https://github.com/Leonidas-from-XIV/node-xml2js/issues/648 means
255
+ // that an old version of `emptyTag` is used which doesn't support
256
+ // functions, but DefinitelyTyped is requiring use of function or a
257
+ // string. See also notes at
258
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59259#issuecomment-1254405470
259
+ // An alternative fix would be to pull xml2js directly from github
260
+ // rather than using the version tagged on npmjs.com.
261
+ });
262
+ parser.parseString(file, (e, r) => { a = r; }); // TODO-LDML: isn't 'e' the error?
263
+ return a;
264
+ })();
265
+ return source;
266
+ }
267
+ /**
268
+ * @param file
269
+ * @returns source on success, otherwise null
270
+ */
271
+ load(file) {
272
+ if (!file) {
273
+ return null;
274
+ }
275
+ const source = this.loadUnboxed(file);
276
+ if (this.boxArrays(source)) {
277
+ return source;
278
+ }
279
+ else {
280
+ return null;
281
+ }
282
+ }
283
+ loadTestDataUnboxed(file) {
284
+ let source = (() => {
285
+ let a;
286
+ let parser = new xml2js.Parser({
287
+ // explicitArray: false,
288
+ preserveChildrenOrder: true, // needed for test data
289
+ explicitChildren: true, // needed for test data
290
+ // mergeAttrs: true,
291
+ // includeWhiteChars: false,
292
+ // emptyTag: {} as any
293
+ // Why "as any"? xml2js is broken:
294
+ // https://github.com/Leonidas-from-XIV/node-xml2js/issues/648 means
295
+ // that an old version of `emptyTag` is used which doesn't support
296
+ // functions, but DefinitelyTyped is requiring use of function or a
297
+ // string. See also notes at
298
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59259#issuecomment-1254405470
299
+ // An alternative fix would be to pull xml2js directly from github
300
+ // rather than using the version tagged on npmjs.com.
301
+ });
302
+ parser.parseString(file, (e, r) => { a = r; }); // TODO-LDML: isn't 'e' the error?
303
+ return a; // Why 'any'? Because we need to box up the $'s into proper properties.
304
+ })();
305
+ return source;
306
+ }
307
+ /**
308
+ * Filter the obj array for a subtag
309
+ * @param source array of source objs
310
+ * @param subtag subtag to filter on
311
+ * @returns
312
+ */
313
+ findSubtagArray(source, subtag) {
314
+ return source?.filter(o => o['#name'] === subtag);
315
+ }
316
+ /**
317
+ * Get exactly one element
318
+ * @param source
319
+ * @param subtag
320
+ * @returns
321
+ */
322
+ findSubtag(source, subtag) {
323
+ const r = this.findSubtagArray(source, subtag);
324
+ if (!r || r.length === 0) {
325
+ return null;
326
+ }
327
+ else if (r.length === 1) {
328
+ return r[0];
329
+ }
330
+ else {
331
+ this.callbacks.reportMessage(CommonTypesMessages.Error_TestDataUnexpectedArray({ subtag }));
332
+ return null; // ERROR
333
+ }
334
+ }
335
+ /**
336
+ * The default test data stuffer.
337
+ * Just gets $ (the attrs) as the body.
338
+ * Override to use something more complex, such as including child nodes.
339
+ * @param o object to map
340
+ * @param r back ref to reader
341
+ */
342
+ static defaultMapper = ((o, r) => o?.$);
343
+ /**
344
+ *
345
+ * @param obj target object
346
+ * @param source array of $/#name strings
347
+ * @param subtag name to extract
348
+ * @param mapper custom mapper function
349
+ */
350
+ stuffBoxes(obj, source, subtag, asArray, mapper) {
351
+ if (!mapper) {
352
+ mapper = LDMLKeyboardXMLSourceFileReader.defaultMapper;
353
+ }
354
+ if (asArray) {
355
+ const r = this;
356
+ obj[subtag] = this.findSubtagArray(source, subtag)?.map((v) => mapper(v, r)); // extract contents only
357
+ }
358
+ else {
359
+ obj[subtag] = mapper(this.findSubtag(source, subtag), this); // run the mapper once
360
+ }
361
+ }
362
+ boxTestDataArrays(raw) {
363
+ if (!raw)
364
+ return null;
365
+ const a = {
366
+ keyboardTest3: {
367
+ conformsTo: raw?.keyboardTest3?.$?.conformsTo,
368
+ }
369
+ };
370
+ const $$ = raw?.keyboardTest3?.$$;
371
+ this.stuffBoxes(a.keyboardTest3, $$, 'info');
372
+ this.stuffBoxes(a.keyboardTest3, $$, 'repertoire', true);
373
+ this.stuffBoxes(a.keyboardTest3, $$, 'tests', true, (o, r) => {
374
+ // start with basic unpack
375
+ const tests = LDMLKeyboardXMLSourceFileReader.defaultMapper(o, r);
376
+ // add ingredients
377
+ r.stuffBoxes(tests, o.$$, 'test', true, (o, r) => {
378
+ // start with basic unpack
379
+ const test = LDMLKeyboardXMLSourceFileReader.defaultMapper(o, r);
380
+ // add ingredients
381
+ const $$ = o.$$;
382
+ r.stuffBoxes(test, $$, 'startContext'); // singleton
383
+ // now the actions
384
+ test.actions = $$.map(v => {
385
+ const type = v['#name']; // element name
386
+ if (type === 'startContext') {
387
+ return null; // handled above
388
+ }
389
+ const subv = LDMLKeyboardXMLSourceFileReader.defaultMapper(v, r);
390
+ return Object.assign({ type }, subv);
391
+ }).filter(v => v !== null);
392
+ return test;
393
+ });
394
+ return tests;
395
+ });
396
+ return a;
397
+ }
398
+ /**
399
+ * @param file test file
400
+ * @returns source on success, otherwise null
401
+ */
402
+ loadTestData(file) {
403
+ if (!file) {
404
+ return null;
405
+ }
406
+ const source = this.loadTestDataUnboxed(file);
407
+ return this.boxTestDataArrays(source);
408
+ }
409
+ }
410
410
  //# sourceMappingURL=ldml-keyboard-xml-reader.js.map
411
- //# debugId=065afd3b-524c-565a-b20d-4b1e3cfd778f
411
+ //# debugId=ad64e78e-6c60-5376-bc04-4a7f613d99f9