@keymanapp/kmc-model 18.0.53-alpha → 18.0.55-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.
- package/build/src/build-trie.d.ts +39 -39
- package/build/src/build-trie.js +374 -374
- package/build/src/build-trie.js.map +1 -1
- package/build/src/compiler-callbacks.d.ts +3 -3
- package/build/src/compiler-callbacks.js +4 -4
- package/build/src/join-word-breaker-decorator.d.ts +9 -9
- package/build/src/join-word-breaker-decorator.js +120 -120
- package/build/src/join-word-breaker-decorator.js.map +1 -1
- package/build/src/lexical-model-compiler.d.ts +87 -87
- package/build/src/lexical-model-compiler.js +260 -260
- package/build/src/lexical-model-compiler.js.map +1 -1
- package/build/src/lexical-model.d.ts +143 -143
- package/build/src/lexical-model.js +5 -5
- package/build/src/main.d.ts +3 -3
- package/build/src/main.js +2 -2
- package/build/src/model-compiler-messages.d.ts +56 -56
- package/build/src/model-compiler-messages.js +63 -63
- package/build/src/model-defaults.d.ts +55 -55
- package/build/src/model-defaults.js +101 -101
- package/build/src/model-defaults.js.map +1 -1
- package/build/src/model-definitions.d.ts +70 -70
- package/build/src/model-definitions.js +182 -182
- package/build/src/model-definitions.js.map +1 -1
- package/build/src/script-overrides-decorator.d.ts +3 -3
- package/build/src/script-overrides-decorator.js +63 -63
- package/build/src/script-overrides-decorator.js.map +1 -1
- package/package.json +8 -9
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
import { defaultApplyCasing, defaultCasedSearchTermToKey, defaultSearchTermToKey } from "./model-defaults.js";
|
|
2
|
-
import KEYMAN_VERSION from "@keymanapp/keyman-version";
|
|
3
|
-
/**
|
|
4
|
-
* Processes certain defined model behaviors in such a way that the needed closures
|
|
5
|
-
* may be safely compiled to a JS file and loaded within the LMLayer.
|
|
6
|
-
*
|
|
7
|
-
* This is accomplished by writing out a 'pseudoclosure' within the model's IIFE,
|
|
8
|
-
* then used to build _actual_ closures at LMLayer load time. This 'pseudoclosure'
|
|
9
|
-
* will very closely match the organizational patterns of this class in order to
|
|
10
|
-
* facilitate the maintenance of this approach.
|
|
11
|
-
*/
|
|
12
|
-
export class ModelDefinitions {
|
|
13
|
-
static COMPILED_NAME = 'definitions';
|
|
14
|
-
/**
|
|
15
|
-
* A closure fully implementing the model's defined `applyCasing` behavior with
|
|
16
|
-
* the function parameter preset to the version-appropriate default.
|
|
17
|
-
* `defaults.applyCasing` is captured as part of the closure.
|
|
18
|
-
*
|
|
19
|
-
* During compilation of some models (such as Trie-based wordlist templated models),
|
|
20
|
-
* this closure will be directly used as part of searchTermToKey.
|
|
21
|
-
*
|
|
22
|
-
* In compiled code, this will instead be defined in-line as an autogenerated closure
|
|
23
|
-
* using the other properties of the pseudoclosure.
|
|
24
|
-
*/
|
|
25
|
-
applyCasing;
|
|
26
|
-
/**
|
|
27
|
-
* A closure fully implementing the model's defined `searchTermToKey` behavior
|
|
28
|
-
* based upon the model's specified casing rules. The `applyCasing` closure is
|
|
29
|
-
* itself captured within this closure.
|
|
30
|
-
*
|
|
31
|
-
* During compilation of some models (such as Trie-based wordlist templated models),
|
|
32
|
-
* this closure will be directly utilized when compiling the lexicon.
|
|
33
|
-
*
|
|
34
|
-
* In compiled code, this will instead be defined in-line as an autogenerated closure
|
|
35
|
-
* using the other properties of the pseudoclosure.
|
|
36
|
-
*/
|
|
37
|
-
searchTermToKey;
|
|
38
|
-
/**
|
|
39
|
-
* Contains embedded 'default' implementations that may be needed for
|
|
40
|
-
* closures in the compiled version, annotated with the current version
|
|
41
|
-
* of Developer.
|
|
42
|
-
*/
|
|
43
|
-
defaults = {
|
|
44
|
-
version: KEYMAN_VERSION.VERSION_WITH_TAG
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Contains the model-specific definitions specified in the model's source.
|
|
48
|
-
*
|
|
49
|
-
* These definitions may expect `defaults.applyCasing` as a parameter in
|
|
50
|
-
* their final closures.
|
|
51
|
-
*/
|
|
52
|
-
model = {};
|
|
53
|
-
constructor(modelSource) {
|
|
54
|
-
// Determine the model's `applyCasing` function / implementation.
|
|
55
|
-
if (modelSource.languageUsesCasing) {
|
|
56
|
-
this.defaults.applyCasing = defaultApplyCasing;
|
|
57
|
-
if (modelSource.applyCasing) {
|
|
58
|
-
this.model.applyCasing = modelSource.applyCasing;
|
|
59
|
-
let _this = this;
|
|
60
|
-
// Since the defined casing function may expect to take our default implementation
|
|
61
|
-
// as a parameter, we can define the full implementation via closure capture.
|
|
62
|
-
this.applyCasing = function (casing, text) {
|
|
63
|
-
return _this.model.applyCasing(casing, text, _this.defaults.applyCasing);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.applyCasing = this.defaults.applyCasing;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// START: if(model type uses keying)...
|
|
71
|
-
// Use the default search term to key function, if left unspecified.
|
|
72
|
-
if (modelSource.searchTermToKey) {
|
|
73
|
-
this.model.searchTermToKey = modelSource.searchTermToKey;
|
|
74
|
-
}
|
|
75
|
-
else if (modelSource.languageUsesCasing) {
|
|
76
|
-
// applyCasing is defined here.
|
|
77
|
-
// Unfortunately, this only works conceptually. .toString on a closure
|
|
78
|
-
// does not result in proper compilation.
|
|
79
|
-
this.model.searchTermToKey = defaultCasedSearchTermToKey;
|
|
80
|
-
}
|
|
81
|
-
else if (modelSource.languageUsesCasing == false) {
|
|
82
|
-
this.model.searchTermToKey = defaultSearchTermToKey;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
// If languageUsesCasing is not defined, then we use pre-14.0 behavior,
|
|
86
|
-
// which expects a lowercased default.
|
|
87
|
-
this.model.searchTermToKey = defaultCasedSearchTermToKey;
|
|
88
|
-
// Needed to provide pre-14.0 default lowercasing as part of the
|
|
89
|
-
// search-term keying operation.
|
|
90
|
-
this.defaults.applyCasing = defaultApplyCasing;
|
|
91
|
-
// For compile-time use.
|
|
92
|
-
this.applyCasing = this.defaults.applyCasing;
|
|
93
|
-
}
|
|
94
|
-
let _this = this;
|
|
95
|
-
this.searchTermToKey = function (text) {
|
|
96
|
-
return _this.model.searchTermToKey(text, _this.applyCasing);
|
|
97
|
-
};
|
|
98
|
-
// END: if(model type uses keying)...
|
|
99
|
-
}
|
|
100
|
-
// ------------ end: common compile-time / run-time code ---------------
|
|
101
|
-
// START: handwritten compilation code (to accomplish the 'common' pattern defined above)
|
|
102
|
-
/**
|
|
103
|
-
* Writes out a compiled JS version of the pseudoclosure, preserving all function
|
|
104
|
-
* implementations.
|
|
105
|
-
*
|
|
106
|
-
* This should be written to the file within the same IIFE as the model but BEFORE
|
|
107
|
-
* the model itself, as the model will need to refer to the definitions herein.
|
|
108
|
-
*/
|
|
109
|
-
compileDefinitions() {
|
|
110
|
-
let defn = '';
|
|
111
|
-
defn += `var ${PSEUDOCLOSURE} = {\n`;
|
|
112
|
-
// ----------------------
|
|
113
|
-
// START - the 'defaults', which are common within the same Developer version.
|
|
114
|
-
defn += ` defaults: {\n version: "${this.defaults.version}"`;
|
|
115
|
-
// Only write out `applyCasing` if and when it is needed.
|
|
116
|
-
if (this.defaults.applyCasing) {
|
|
117
|
-
defn += `,\n applyCasing: ${this.defaults.applyCasing.toString()}`;
|
|
118
|
-
}
|
|
119
|
-
// Finalizes `defaults`
|
|
120
|
-
defn += `\n },`;
|
|
121
|
-
// END - the 'defaults'
|
|
122
|
-
// ----------------------
|
|
123
|
-
// START - model-specific definitions (when defined)
|
|
124
|
-
defn += ` model: {\n`;
|
|
125
|
-
defn += ` searchTermToKey: ${this.model.searchTermToKey.toString()}`;
|
|
126
|
-
if (this.model.applyCasing) {
|
|
127
|
-
defn += `,\n applyCasing: ${this.model.applyCasing.toString()}`;
|
|
128
|
-
}
|
|
129
|
-
defn += `\n }`;
|
|
130
|
-
// END - model-specific definitions
|
|
131
|
-
// ----------------------
|
|
132
|
-
// START - compiled closures. Given those definitions, write out the
|
|
133
|
-
// pseudoclosure-referencing closures for the needed methods.
|
|
134
|
-
// We should be able to define these closures in-line with the object's
|
|
135
|
-
// initialization. Worst-case, we simply move the definitions outside
|
|
136
|
-
// of the pseudoclosure's init and THEN define/assign these closures to
|
|
137
|
-
// the object, as references will be available then for sure.
|
|
138
|
-
if (this.model.applyCasing) {
|
|
139
|
-
// A major potential issue: if the user wants to call extra custom functions that they've written.
|
|
140
|
-
//
|
|
141
|
-
// `applyCasing` recursion SHOULD be fine if they write `this.applyCasing() and forward all arguments
|
|
142
|
-
// appropriately, as it will be known as `applyCasing` on the runtime `this` (`model`) object.
|
|
143
|
-
//
|
|
144
|
-
// Similarly, as long as any helper functions are similarly compiled and stored as part of `model`,
|
|
145
|
-
// they should be accessible too. The issue would be to actually allow use of extra custom funcs
|
|
146
|
-
// and include them as part of this object as part of compilation.
|
|
1
|
+
import { defaultApplyCasing, defaultCasedSearchTermToKey, defaultSearchTermToKey } from "./model-defaults.js";
|
|
2
|
+
import KEYMAN_VERSION from "@keymanapp/keyman-version";
|
|
3
|
+
/**
|
|
4
|
+
* Processes certain defined model behaviors in such a way that the needed closures
|
|
5
|
+
* may be safely compiled to a JS file and loaded within the LMLayer.
|
|
6
|
+
*
|
|
7
|
+
* This is accomplished by writing out a 'pseudoclosure' within the model's IIFE,
|
|
8
|
+
* then used to build _actual_ closures at LMLayer load time. This 'pseudoclosure'
|
|
9
|
+
* will very closely match the organizational patterns of this class in order to
|
|
10
|
+
* facilitate the maintenance of this approach.
|
|
11
|
+
*/
|
|
12
|
+
export class ModelDefinitions {
|
|
13
|
+
static COMPILED_NAME = 'definitions';
|
|
14
|
+
/**
|
|
15
|
+
* A closure fully implementing the model's defined `applyCasing` behavior with
|
|
16
|
+
* the function parameter preset to the version-appropriate default.
|
|
17
|
+
* `defaults.applyCasing` is captured as part of the closure.
|
|
18
|
+
*
|
|
19
|
+
* During compilation of some models (such as Trie-based wordlist templated models),
|
|
20
|
+
* this closure will be directly used as part of searchTermToKey.
|
|
21
|
+
*
|
|
22
|
+
* In compiled code, this will instead be defined in-line as an autogenerated closure
|
|
23
|
+
* using the other properties of the pseudoclosure.
|
|
24
|
+
*/
|
|
25
|
+
applyCasing;
|
|
26
|
+
/**
|
|
27
|
+
* A closure fully implementing the model's defined `searchTermToKey` behavior
|
|
28
|
+
* based upon the model's specified casing rules. The `applyCasing` closure is
|
|
29
|
+
* itself captured within this closure.
|
|
30
|
+
*
|
|
31
|
+
* During compilation of some models (such as Trie-based wordlist templated models),
|
|
32
|
+
* this closure will be directly utilized when compiling the lexicon.
|
|
33
|
+
*
|
|
34
|
+
* In compiled code, this will instead be defined in-line as an autogenerated closure
|
|
35
|
+
* using the other properties of the pseudoclosure.
|
|
36
|
+
*/
|
|
37
|
+
searchTermToKey;
|
|
38
|
+
/**
|
|
39
|
+
* Contains embedded 'default' implementations that may be needed for
|
|
40
|
+
* closures in the compiled version, annotated with the current version
|
|
41
|
+
* of Developer.
|
|
42
|
+
*/
|
|
43
|
+
defaults = {
|
|
44
|
+
version: KEYMAN_VERSION.VERSION_WITH_TAG
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Contains the model-specific definitions specified in the model's source.
|
|
48
|
+
*
|
|
49
|
+
* These definitions may expect `defaults.applyCasing` as a parameter in
|
|
50
|
+
* their final closures.
|
|
51
|
+
*/
|
|
52
|
+
model = {};
|
|
53
|
+
constructor(modelSource) {
|
|
54
|
+
// Determine the model's `applyCasing` function / implementation.
|
|
55
|
+
if (modelSource.languageUsesCasing) {
|
|
56
|
+
this.defaults.applyCasing = defaultApplyCasing;
|
|
57
|
+
if (modelSource.applyCasing) {
|
|
58
|
+
this.model.applyCasing = modelSource.applyCasing;
|
|
59
|
+
let _this = this;
|
|
60
|
+
// Since the defined casing function may expect to take our default implementation
|
|
61
|
+
// as a parameter, we can define the full implementation via closure capture.
|
|
62
|
+
this.applyCasing = function (casing, text) {
|
|
63
|
+
return _this.model.applyCasing(casing, text, _this.defaults.applyCasing);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.applyCasing = this.defaults.applyCasing;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// START: if(model type uses keying)...
|
|
71
|
+
// Use the default search term to key function, if left unspecified.
|
|
72
|
+
if (modelSource.searchTermToKey) {
|
|
73
|
+
this.model.searchTermToKey = modelSource.searchTermToKey;
|
|
74
|
+
}
|
|
75
|
+
else if (modelSource.languageUsesCasing) {
|
|
76
|
+
// applyCasing is defined here.
|
|
77
|
+
// Unfortunately, this only works conceptually. .toString on a closure
|
|
78
|
+
// does not result in proper compilation.
|
|
79
|
+
this.model.searchTermToKey = defaultCasedSearchTermToKey;
|
|
80
|
+
}
|
|
81
|
+
else if (modelSource.languageUsesCasing == false) {
|
|
82
|
+
this.model.searchTermToKey = defaultSearchTermToKey;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// If languageUsesCasing is not defined, then we use pre-14.0 behavior,
|
|
86
|
+
// which expects a lowercased default.
|
|
87
|
+
this.model.searchTermToKey = defaultCasedSearchTermToKey;
|
|
88
|
+
// Needed to provide pre-14.0 default lowercasing as part of the
|
|
89
|
+
// search-term keying operation.
|
|
90
|
+
this.defaults.applyCasing = defaultApplyCasing;
|
|
91
|
+
// For compile-time use.
|
|
92
|
+
this.applyCasing = this.defaults.applyCasing;
|
|
93
|
+
}
|
|
94
|
+
let _this = this;
|
|
95
|
+
this.searchTermToKey = function (text) {
|
|
96
|
+
return _this.model.searchTermToKey(text, _this.applyCasing);
|
|
97
|
+
};
|
|
98
|
+
// END: if(model type uses keying)...
|
|
99
|
+
}
|
|
100
|
+
// ------------ end: common compile-time / run-time code ---------------
|
|
101
|
+
// START: handwritten compilation code (to accomplish the 'common' pattern defined above)
|
|
102
|
+
/**
|
|
103
|
+
* Writes out a compiled JS version of the pseudoclosure, preserving all function
|
|
104
|
+
* implementations.
|
|
105
|
+
*
|
|
106
|
+
* This should be written to the file within the same IIFE as the model but BEFORE
|
|
107
|
+
* the model itself, as the model will need to refer to the definitions herein.
|
|
108
|
+
*/
|
|
109
|
+
compileDefinitions() {
|
|
110
|
+
let defn = '';
|
|
111
|
+
defn += `var ${PSEUDOCLOSURE} = {\n`;
|
|
112
|
+
// ----------------------
|
|
113
|
+
// START - the 'defaults', which are common within the same Developer version.
|
|
114
|
+
defn += ` defaults: {\n version: "${this.defaults.version}"`;
|
|
115
|
+
// Only write out `applyCasing` if and when it is needed.
|
|
116
|
+
if (this.defaults.applyCasing) {
|
|
117
|
+
defn += `,\n applyCasing: ${this.defaults.applyCasing.toString()}`;
|
|
118
|
+
}
|
|
119
|
+
// Finalizes `defaults`
|
|
120
|
+
defn += `\n },`;
|
|
121
|
+
// END - the 'defaults'
|
|
122
|
+
// ----------------------
|
|
123
|
+
// START - model-specific definitions (when defined)
|
|
124
|
+
defn += ` model: {\n`;
|
|
125
|
+
defn += ` searchTermToKey: ${this.model.searchTermToKey.toString()}`;
|
|
126
|
+
if (this.model.applyCasing) {
|
|
127
|
+
defn += `,\n applyCasing: ${this.model.applyCasing.toString()}`;
|
|
128
|
+
}
|
|
129
|
+
defn += `\n }`;
|
|
130
|
+
// END - model-specific definitions
|
|
131
|
+
// ----------------------
|
|
132
|
+
// START - compiled closures. Given those definitions, write out the
|
|
133
|
+
// pseudoclosure-referencing closures for the needed methods.
|
|
134
|
+
// We should be able to define these closures in-line with the object's
|
|
135
|
+
// initialization. Worst-case, we simply move the definitions outside
|
|
136
|
+
// of the pseudoclosure's init and THEN define/assign these closures to
|
|
137
|
+
// the object, as references will be available then for sure.
|
|
138
|
+
if (this.model.applyCasing) {
|
|
139
|
+
// A major potential issue: if the user wants to call extra custom functions that they've written.
|
|
140
|
+
//
|
|
141
|
+
// `applyCasing` recursion SHOULD be fine if they write `this.applyCasing() and forward all arguments
|
|
142
|
+
// appropriately, as it will be known as `applyCasing` on the runtime `this` (`model`) object.
|
|
143
|
+
//
|
|
144
|
+
// Similarly, as long as any helper functions are similarly compiled and stored as part of `model`,
|
|
145
|
+
// they should be accessible too. The issue would be to actually allow use of extra custom funcs
|
|
146
|
+
// and include them as part of this object as part of compilation.
|
|
147
147
|
defn += `,\n applyCasing: function(caseToApply, text) {
|
|
148
148
|
return ${PSEUDOCLOSURE}.model.applyCasing(caseToApply, text, ${PSEUDOCLOSURE}.defaults.applyCasing);
|
|
149
|
-
}`;
|
|
150
|
-
}
|
|
151
|
-
else if (this.defaults.applyCasing) {
|
|
152
|
-
// We can't directly assign from `.defaults`, as initialization-time field reads
|
|
153
|
-
// are not permitted within JS. Function references, however, are valid.
|
|
149
|
+
}`;
|
|
150
|
+
}
|
|
151
|
+
else if (this.defaults.applyCasing) {
|
|
152
|
+
// We can't directly assign from `.defaults`, as initialization-time field reads
|
|
153
|
+
// are not permitted within JS. Function references, however, are valid.
|
|
154
154
|
defn += `,\n applyCasing: function(caseToApply, text) {
|
|
155
155
|
return ${PSEUDOCLOSURE}.defaults.applyCasing(caseToApply, text);
|
|
156
|
-
}`;
|
|
157
|
-
}
|
|
158
|
-
// if(this.searchTermToKey) {
|
|
156
|
+
}`;
|
|
157
|
+
}
|
|
158
|
+
// if(this.searchTermToKey) {
|
|
159
159
|
defn += `,\n searchTermToKey: function(text) {
|
|
160
160
|
return ${PSEUDOCLOSURE}.model.searchTermToKey(text, ${PSEUDOCLOSURE}.applyCasing);
|
|
161
|
-
}`;
|
|
162
|
-
// }
|
|
163
|
-
// END - compiled closures.
|
|
164
|
-
// ----------------------
|
|
165
|
-
// Finalize the definition of... `definitions`.
|
|
166
|
-
defn += `\n};\n`;
|
|
167
|
-
return defn;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Compiles the model-options entry for `searchTermToKey` in reference to the
|
|
171
|
-
* compiled pseudoclosure.
|
|
172
|
-
*/
|
|
173
|
-
compileSearchTermToKey() {
|
|
174
|
-
// Simply point the model to the constructed closure defined by `compilePseudoclosure`.
|
|
175
|
-
// See "START - compiled closures" section.
|
|
176
|
-
return `${PSEUDOCLOSURE}.searchTermToKey`;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Compiles the model-options entry for `applyCasing` in reference to the
|
|
180
|
-
* compiled pseudoclosure.
|
|
181
|
-
*/
|
|
182
|
-
compileApplyCasing() {
|
|
183
|
-
// See "START - compiled closures" section.
|
|
184
|
-
return `${PSEUDOCLOSURE}.applyCasing`;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// Because it references the class field, this line must come afterward.
|
|
188
|
-
const PSEUDOCLOSURE = ModelDefinitions.COMPILED_NAME;
|
|
161
|
+
}`;
|
|
162
|
+
// }
|
|
163
|
+
// END - compiled closures.
|
|
164
|
+
// ----------------------
|
|
165
|
+
// Finalize the definition of... `definitions`.
|
|
166
|
+
defn += `\n};\n`;
|
|
167
|
+
return defn;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Compiles the model-options entry for `searchTermToKey` in reference to the
|
|
171
|
+
* compiled pseudoclosure.
|
|
172
|
+
*/
|
|
173
|
+
compileSearchTermToKey() {
|
|
174
|
+
// Simply point the model to the constructed closure defined by `compilePseudoclosure`.
|
|
175
|
+
// See "START - compiled closures" section.
|
|
176
|
+
return `${PSEUDOCLOSURE}.searchTermToKey`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Compiles the model-options entry for `applyCasing` in reference to the
|
|
180
|
+
* compiled pseudoclosure.
|
|
181
|
+
*/
|
|
182
|
+
compileApplyCasing() {
|
|
183
|
+
// See "START - compiled closures" section.
|
|
184
|
+
return `${PSEUDOCLOSURE}.applyCasing`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Because it references the class field, this line must come afterward.
|
|
188
|
+
const PSEUDOCLOSURE = ModelDefinitions.COMPILED_NAME;
|
|
189
189
|
//# sourceMappingURL=model-definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-definitions.js","sourceRoot":"","sources":["../../src/model-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAClB,2BAA2B,EAC3B,sBAAsB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AQ,CAAC,WAAW,EAAE,CAAC;YACpC,gFAAgF;YAChF,yEAAyE;YACzE,IAAI,IAAI;iBACG,aAAa;QACtB,CAAC;QACL,CAAC;QAED,6BAA6B;QAC7B,IAAI,IAAI;eACG,aAAa,gCAAgC,aAAa;MACnE,CAAC;QACH,IAAI;QAEJ,2BAA2B;QAE3B,yBAAyB;QACzB,+CAA+C;QAC/C,IAAI,IAAI,QAAQ,CAAC;QAEjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,sBAAsB;QACpB,uFAAuF;QACvF,2CAA2C;QAC3C,OAAO,GAAG,aAAa,kBAAkB,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,2CAA2C;QAC3C,OAAO,GAAG,aAAa,cAAc,CAAC;IACxC,CAAC;;AAGH,wEAAwE;AACxE,MAAM,aAAa,GAAG,gBAAgB,CAAC,aAAa,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="@keymanapp/models-types" />
|
|
2
|
-
import { OverrideScriptDefaults } from "./lexical-model.js";
|
|
3
|
-
export declare function decorateWithScriptOverrides(breaker: WordBreakingFunction, option: OverrideScriptDefaults): (phrase: string) => Span[];
|
|
1
|
+
/// <reference types="@keymanapp/models-types" />
|
|
2
|
+
import { OverrideScriptDefaults } from "./lexical-model.js";
|
|
3
|
+
export declare function decorateWithScriptOverrides(breaker: WordBreakingFunction, option: OverrideScriptDefaults): (phrase: string) => Span[];
|
|
4
4
|
//# sourceMappingURL=script-overrides-decorator.d.ts.map
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { ModelCompilerError, ModelCompilerMessages } from "./model-compiler-messages.js";
|
|
2
|
-
export function decorateWithScriptOverrides(breaker, option) {
|
|
3
|
-
if (option !== 'break-words-at-spaces') {
|
|
4
|
-
throw new ModelCompilerError(ModelCompilerMessages.Error_UnsupportedScriptOverride({ option }));
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Matches if when a span contains a Southeast-Asian letter or mark anywhere.
|
|
8
|
-
* This makes it a candidate for joining.
|
|
9
|
-
*
|
|
10
|
-
* See: tools/create-override-script-regexp.ts for how this RegExp was
|
|
11
|
-
* generated.
|
|
12
|
-
*
|
|
13
|
-
* Last updated for Unicode 13.0.0.
|
|
14
|
-
*/
|
|
15
|
-
const HAS_SOUTHEAST_ASIAN_LETTER = /[\u0E01-\u0E3A\u0E40-\u0E4E\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0EDC-\u0EDF\u1000-\u103F\u1050-\u108F\u109A-\u109D\u1780-\u17D3\u17D7\u17DC\u17DD\u30A1-\u30FA\u30FC-\u30FF]/;
|
|
16
|
-
return function enhancedBreaker(phrase) {
|
|
17
|
-
let originalSpans = breaker(phrase);
|
|
18
|
-
if (originalSpans.length === 0) {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
let outputSpans = [originalSpans.shift()];
|
|
22
|
-
for (let currentSpan of originalSpans) {
|
|
23
|
-
let previousSpan = lastFrom(outputSpans);
|
|
24
|
-
if (spansAreBackToBack(previousSpan, currentSpan) &&
|
|
25
|
-
hasSouthEastAsianLetter(previousSpan) &&
|
|
26
|
-
hasSouthEastAsianLetter(currentSpan)) {
|
|
27
|
-
// previous span SHOULD be joined with current!
|
|
28
|
-
outputSpans[outputSpans.length - 1] = concatenateSpans(previousSpan, currentSpan);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
outputSpans.push(currentSpan);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return outputSpans;
|
|
35
|
-
};
|
|
36
|
-
function hasSouthEastAsianLetter(span) {
|
|
37
|
-
return HAS_SOUTHEAST_ASIAN_LETTER.test(span.text);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns true when the spans are contiguous.
|
|
41
|
-
* Order matters when calling this function!
|
|
42
|
-
*/
|
|
43
|
-
function spansAreBackToBack(former, latter) {
|
|
44
|
-
return former.end === latter.start;
|
|
45
|
-
}
|
|
46
|
-
function concatenateSpans(former, latter) {
|
|
47
|
-
if (latter.start !== former.end) {
|
|
48
|
-
throw new Error(`Cannot concatenate non-contiguous spans: ${JSON.stringify(former)}/${JSON.stringify(latter)}`);
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
start: former.start,
|
|
52
|
-
end: latter.end,
|
|
53
|
-
length: former.length + latter.length,
|
|
54
|
-
text: former.text + latter.text
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Get the last element from the array.
|
|
59
|
-
*/
|
|
60
|
-
function lastFrom(array) {
|
|
61
|
-
return array[array.length - 1];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import { ModelCompilerError, ModelCompilerMessages } from "./model-compiler-messages.js";
|
|
2
|
+
export function decorateWithScriptOverrides(breaker, option) {
|
|
3
|
+
if (option !== 'break-words-at-spaces') {
|
|
4
|
+
throw new ModelCompilerError(ModelCompilerMessages.Error_UnsupportedScriptOverride({ option }));
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Matches if when a span contains a Southeast-Asian letter or mark anywhere.
|
|
8
|
+
* This makes it a candidate for joining.
|
|
9
|
+
*
|
|
10
|
+
* See: tools/create-override-script-regexp.ts for how this RegExp was
|
|
11
|
+
* generated.
|
|
12
|
+
*
|
|
13
|
+
* Last updated for Unicode 13.0.0.
|
|
14
|
+
*/
|
|
15
|
+
const HAS_SOUTHEAST_ASIAN_LETTER = /[\u0E01-\u0E3A\u0E40-\u0E4E\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0EDC-\u0EDF\u1000-\u103F\u1050-\u108F\u109A-\u109D\u1780-\u17D3\u17D7\u17DC\u17DD\u30A1-\u30FA\u30FC-\u30FF]/;
|
|
16
|
+
return function enhancedBreaker(phrase) {
|
|
17
|
+
let originalSpans = breaker(phrase);
|
|
18
|
+
if (originalSpans.length === 0) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
let outputSpans = [originalSpans.shift()];
|
|
22
|
+
for (let currentSpan of originalSpans) {
|
|
23
|
+
let previousSpan = lastFrom(outputSpans);
|
|
24
|
+
if (spansAreBackToBack(previousSpan, currentSpan) &&
|
|
25
|
+
hasSouthEastAsianLetter(previousSpan) &&
|
|
26
|
+
hasSouthEastAsianLetter(currentSpan)) {
|
|
27
|
+
// previous span SHOULD be joined with current!
|
|
28
|
+
outputSpans[outputSpans.length - 1] = concatenateSpans(previousSpan, currentSpan);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
outputSpans.push(currentSpan);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return outputSpans;
|
|
35
|
+
};
|
|
36
|
+
function hasSouthEastAsianLetter(span) {
|
|
37
|
+
return HAS_SOUTHEAST_ASIAN_LETTER.test(span.text);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns true when the spans are contiguous.
|
|
41
|
+
* Order matters when calling this function!
|
|
42
|
+
*/
|
|
43
|
+
function spansAreBackToBack(former, latter) {
|
|
44
|
+
return former.end === latter.start;
|
|
45
|
+
}
|
|
46
|
+
function concatenateSpans(former, latter) {
|
|
47
|
+
if (latter.start !== former.end) {
|
|
48
|
+
throw new Error(`Cannot concatenate non-contiguous spans: ${JSON.stringify(former)}/${JSON.stringify(latter)}`);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
start: former.start,
|
|
52
|
+
end: latter.end,
|
|
53
|
+
length: former.length + latter.length,
|
|
54
|
+
text: former.text + latter.text
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the last element from the array.
|
|
59
|
+
*/
|
|
60
|
+
function lastFrom(array) {
|
|
61
|
+
return array[array.length - 1];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
//# sourceMappingURL=script-overrides-decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script-overrides-decorator.js","sourceRoot":"","sources":["../../src/script-overrides-decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAEzF,MAAM,UAAU,2BAA2B,CAAC,OAA6B,EAAE,MAA8B;IACvG,IAAI,MAAM,KAAK,uBAAuB,EAAE;
|
|
1
|
+
{"version":3,"file":"script-overrides-decorator.js","sourceRoot":"","sources":["../../src/script-overrides-decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAEzF,MAAM,UAAU,2BAA2B,CAAC,OAA6B,EAAE,MAA8B;IACvG,IAAI,MAAM,KAAK,uBAAuB,EAAE,CAAC;QACvC,MAAM,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,+BAA+B,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC,CAAC;IAChG,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,0BAA0B,GAAG,0OAA0O,CAAC;IAE9Q,OAAO,SAAS,eAAe,CAAC,MAAc;QAC5C,IAAI,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAEpC,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,WAAW,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1C,KAAK,IAAI,WAAW,IAAI,aAAa,EAAE,CAAC;YACtC,IAAI,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;YAEzC,IAAI,kBAAkB,CAAC,YAAY,EAAE,WAAW,CAAC;gBAC7C,uBAAuB,CAAC,YAAY,CAAC;gBAC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man/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@keymanapp/common-types": "18.0.
|
|
34
|
-
"@keymanapp/keyman-version": "18.0.
|
|
35
|
-
"@keymanapp/models-types": "18.0.
|
|
36
|
-
"typescript": "^4.
|
|
33
|
+
"@keymanapp/common-types": "18.0.55-alpha",
|
|
34
|
+
"@keymanapp/keyman-version": "18.0.55-alpha",
|
|
35
|
+
"@keymanapp/models-types": "18.0.55-alpha",
|
|
36
|
+
"typescript": "^5.4.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@keymanapp/developer-test-helpers": "18.0.
|
|
40
|
-
"@keymanapp/models-templates": "18.0.
|
|
39
|
+
"@keymanapp/developer-test-helpers": "18.0.55-alpha",
|
|
40
|
+
"@keymanapp/models-templates": "18.0.55-alpha",
|
|
41
41
|
"@types/mocha": "^5.2.7",
|
|
42
42
|
"@types/node": "^20.4.1",
|
|
43
43
|
"c8": "^7.12.0",
|
|
44
44
|
"chalk": "^2.4.2",
|
|
45
45
|
"esbuild": "^0.15.7",
|
|
46
|
-
"mocha": "^10.0.0"
|
|
47
|
-
"ts-node": "^10.9.1"
|
|
46
|
+
"mocha": "^10.0.0"
|
|
48
47
|
},
|
|
49
48
|
"mocha": {
|
|
50
49
|
"spec": "build/test/**/test-*.js",
|
|
@@ -68,5 +67,5 @@
|
|
|
68
67
|
"type": "git",
|
|
69
68
|
"url": "git+https://github.com/keymanapp/keyman.git"
|
|
70
69
|
},
|
|
71
|
-
"version": "18.0.
|
|
70
|
+
"version": "18.0.55-alpha"
|
|
72
71
|
}
|