@myrmidon/cadmus-core 0.0.23 → 0.3.0
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/README.md +24 -24
- package/esm2020/lib/cadmus-core.module.mjs +20 -0
- package/esm2020/lib/datation.mjs +521 -0
- package/esm2020/lib/guards/pending-changes.guard.mjs +24 -0
- package/esm2020/lib/historical-date.mjs +299 -0
- package/esm2020/lib/models.mjs +11 -0
- package/esm2020/lib/pipes/sort.pipe.mjs +42 -0
- package/esm2020/lib/services/gravatar.service.mjs +30 -0
- package/esm2020/lib/services/library-route.service.mjs +211 -0
- package/esm2020/lib/services/text-layer.service.mjs +682 -0
- package/{esm2015/lib/text-range.js → esm2020/lib/text-range.mjs} +1 -1
- package/esm2020/lib/token-location.mjs +74 -0
- package/esm2020/lib/token-point.mjs +65 -0
- package/esm2020/lib/validators/cadmus-validators.mjs +61 -0
- package/{esm2015/lib/validators/password.validator.js → esm2020/lib/validators/password.validator.mjs} +6 -6
- package/{esm2015/myrmidon-cadmus-core.js → esm2020/myrmidon-cadmus-core.mjs} +0 -0
- package/esm2020/public-api.mjs +19 -0
- package/fesm2015/{myrmidon-cadmus-core.js → myrmidon-cadmus-core.mjs} +154 -536
- package/fesm2015/myrmidon-cadmus-core.mjs.map +1 -0
- package/fesm2020/myrmidon-cadmus-core.mjs +2127 -0
- package/fesm2020/myrmidon-cadmus-core.mjs.map +1 -0
- package/lib/cadmus-core.module.d.ts +8 -0
- package/lib/datation.d.ts +2 -2
- package/lib/guards/pending-changes.guard.d.ts +3 -0
- package/lib/historical-date.d.ts +7 -7
- package/lib/models.d.ts +1 -18
- package/lib/pipes/sort.pipe.d.ts +3 -0
- package/lib/services/gravatar.service.d.ts +3 -0
- package/lib/services/library-route.service.d.ts +10 -7
- package/lib/services/text-layer.service.d.ts +9 -6
- package/lib/text-range.d.ts +1 -1
- package/lib/token-location.d.ts +1 -1
- package/lib/token-point.d.ts +1 -1
- package/lib/validators/cadmus-validators.d.ts +11 -0
- package/lib/validators/password.validator.d.ts +2 -4
- package/myrmidon-cadmus-core.d.ts +1 -0
- package/package.json +21 -9
- package/public-api.d.ts +0 -6
- package/bundles/myrmidon-cadmus-core.umd.js +0 -2943
- package/bundles/myrmidon-cadmus-core.umd.js.map +0 -1
- package/esm2015/lib/cadmus-core.module.js +0 -14
- package/esm2015/lib/datation.js +0 -520
- package/esm2015/lib/guards/pending-changes.guard.js +0 -22
- package/esm2015/lib/historical-date.js +0 -297
- package/esm2015/lib/models.js +0 -11
- package/esm2015/lib/pipes/sort.pipe.js +0 -37
- package/esm2015/lib/roman-number.js +0 -155
- package/esm2015/lib/services/env.service.js +0 -76
- package/esm2015/lib/services/env.service.provider.js +0 -31
- package/esm2015/lib/services/error.service.js +0 -38
- package/esm2015/lib/services/gravatar.service.js +0 -28
- package/esm2015/lib/services/library-route.service.js +0 -208
- package/esm2015/lib/services/local-storage.service.js +0 -99
- package/esm2015/lib/services/text-layer.service.js +0 -680
- package/esm2015/lib/token-location.js +0 -74
- package/esm2015/lib/token-point.js +0 -65
- package/esm2015/lib/utils.js +0 -36
- package/esm2015/lib/validators/cadmus-validators.js +0 -40
- package/esm2015/public-api.js +0 -25
- package/fesm2015/myrmidon-cadmus-core.js.map +0 -1
- package/lib/roman-number.d.ts +0 -34
- package/lib/services/env.service.d.ts +0 -52
- package/lib/services/env.service.provider.d.ts +0 -15
- package/lib/services/error.service.d.ts +0 -13
- package/lib/services/local-storage.service.d.ts +0 -32
- package/lib/utils.d.ts +0 -4
- package/myrmidon-cadmus-core.metadata.json +0 -1
|
@@ -1,2943 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('gravatar'), require('rangy'), require('@angular/common'), require('@angular/common/http')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@myrmidon/cadmus-core', ['exports', '@angular/core', 'rxjs', 'gravatar', 'rangy', '@angular/common', '@angular/common/http'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.myrmidon = global.myrmidon || {}, global.myrmidon['cadmus-core'] = {}), global.ng.core, global.rxjs, global.gravatar, global.rangy, global.ng.common, global.ng.common.http));
|
|
5
|
-
}(this, (function (exports, i0, rxjs, gravatar, rangy, common, http) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function _interopNamespace(e) {
|
|
8
|
-
if (e && e.__esModule) return e;
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return e[k];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
n['default'] = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
|
28
|
-
var gravatar__namespace = /*#__PURE__*/_interopNamespace(gravatar);
|
|
29
|
-
var rangy__namespace = /*#__PURE__*/_interopNamespace(rangy);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Roman number converter.
|
|
33
|
-
*/
|
|
34
|
-
var RomanNumber = /** @class */ (function () {
|
|
35
|
-
function RomanNumber() {
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Convert the specified numeric value to a Roman number.
|
|
39
|
-
*
|
|
40
|
-
* @param value The value.
|
|
41
|
-
* @param allowBar True to allow bar on letters. A bar on a letter
|
|
42
|
-
* multiplies its value by 1000.
|
|
43
|
-
* @param allowPrefix True to allow prefix notation.
|
|
44
|
-
* @param ancient True to use the ancient preferred notation, i.e.
|
|
45
|
-
* the preferred epigraphical notation (IIII instead of IV, VIIII instead of IX).
|
|
46
|
-
*/
|
|
47
|
-
RomanNumber.toRoman = function (value, allowBar, allowPrefix, ancient) {
|
|
48
|
-
if (allowBar === void 0) { allowBar = true; }
|
|
49
|
-
if (allowPrefix === void 0) { allowPrefix = true; }
|
|
50
|
-
if (ancient === void 0) { ancient = false; }
|
|
51
|
-
if (value <= 0) {
|
|
52
|
-
return '';
|
|
53
|
-
}
|
|
54
|
-
var place = allowBar ? 0 : 6;
|
|
55
|
-
var sb = [];
|
|
56
|
-
while (value > 0) {
|
|
57
|
-
while (value >= this._postVal[place]) {
|
|
58
|
-
sb.push(this._postAlpha[place]);
|
|
59
|
-
value -= this._postVal[place];
|
|
60
|
-
}
|
|
61
|
-
if (allowPrefix) {
|
|
62
|
-
if (value >= this._preVal[place]) {
|
|
63
|
-
sb.push(this._preAlpha[place]);
|
|
64
|
-
value -= this._preVal[place];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
place++;
|
|
68
|
-
}
|
|
69
|
-
if (ancient) {
|
|
70
|
-
var s = sb.join('');
|
|
71
|
-
s = s.replace('IV', 'IIII');
|
|
72
|
-
return s.replace('IX', 'VIII');
|
|
73
|
-
}
|
|
74
|
-
return sb.join('');
|
|
75
|
-
};
|
|
76
|
-
RomanNumber.isLower = function (c) {
|
|
77
|
-
return c.toLowerCase() === c;
|
|
78
|
-
};
|
|
79
|
-
RomanNumber.isUpper = function (c) {
|
|
80
|
-
return c.toUpperCase() === c;
|
|
81
|
-
};
|
|
82
|
-
RomanNumber.isCaseEqual = function (c1, c2) {
|
|
83
|
-
return ((this.isLower(c1) && this.isLower(c2)) ||
|
|
84
|
-
(this.isUpper(c1) && this.isUpper(c2)));
|
|
85
|
-
};
|
|
86
|
-
RomanNumber.getRomanDigitValue = function (digit) {
|
|
87
|
-
var i = this._romanDigits.indexOf(digit.toUpperCase());
|
|
88
|
-
if (i === -1) {
|
|
89
|
-
return 0;
|
|
90
|
-
}
|
|
91
|
-
return this.isLower(digit)
|
|
92
|
-
? this._romanValues[i] * 1000
|
|
93
|
-
: this._romanValues[i];
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Convert the specified Roman number to a numeric value.
|
|
97
|
-
*
|
|
98
|
-
* @param roman: The Roman number.
|
|
99
|
-
* @param allowBar: True to allow bar-on-letter notation.
|
|
100
|
-
*/
|
|
101
|
-
RomanNumber.fromRoman = function (roman, allowBar) {
|
|
102
|
-
if (allowBar === void 0) { allowBar = true; }
|
|
103
|
-
if (!roman) {
|
|
104
|
-
return 0;
|
|
105
|
-
}
|
|
106
|
-
var result = 0;
|
|
107
|
-
if (!allowBar) {
|
|
108
|
-
roman = roman.toUpperCase();
|
|
109
|
-
}
|
|
110
|
-
for (var index = 0; index < roman.length; index++) {
|
|
111
|
-
// if the previous value was a sub-digit, it had to be subtracted instead
|
|
112
|
-
// of added; thus, subtract it twice (once to compensate for the wrong addition,
|
|
113
|
-
// and once to subtract from this value) from the current digit value
|
|
114
|
-
result += this.getRomanDigitValue(roman[index]);
|
|
115
|
-
if (index > 0) {
|
|
116
|
-
var i = this._romanDigits.indexOf(roman[index]);
|
|
117
|
-
if (roman[index - 1].toUpperCase() ===
|
|
118
|
-
this._romanSubdigits[i].toUpperCase() &&
|
|
119
|
-
this.isCaseEqual(roman[index - 1], roman[index])) {
|
|
120
|
-
// tslint:disable-next-line:no-bitwise
|
|
121
|
-
result -= this.getRomanDigitValue(this._romanSubdigits[i]) << 1;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
};
|
|
127
|
-
return RomanNumber;
|
|
128
|
-
}());
|
|
129
|
-
RomanNumber._postVal = [
|
|
130
|
-
1000000,
|
|
131
|
-
500000,
|
|
132
|
-
100000,
|
|
133
|
-
50000,
|
|
134
|
-
10000,
|
|
135
|
-
5000,
|
|
136
|
-
1000,
|
|
137
|
-
500,
|
|
138
|
-
100,
|
|
139
|
-
50,
|
|
140
|
-
10,
|
|
141
|
-
5,
|
|
142
|
-
1,
|
|
143
|
-
];
|
|
144
|
-
RomanNumber._postAlpha = [
|
|
145
|
-
'm',
|
|
146
|
-
'd',
|
|
147
|
-
'c',
|
|
148
|
-
'l',
|
|
149
|
-
'x',
|
|
150
|
-
'v',
|
|
151
|
-
'M',
|
|
152
|
-
'D',
|
|
153
|
-
'C',
|
|
154
|
-
'L',
|
|
155
|
-
'X',
|
|
156
|
-
'V',
|
|
157
|
-
'I',
|
|
158
|
-
];
|
|
159
|
-
RomanNumber._preVal = [
|
|
160
|
-
900000,
|
|
161
|
-
400000,
|
|
162
|
-
90000,
|
|
163
|
-
40000,
|
|
164
|
-
9000,
|
|
165
|
-
4000,
|
|
166
|
-
900,
|
|
167
|
-
400,
|
|
168
|
-
90,
|
|
169
|
-
40,
|
|
170
|
-
9,
|
|
171
|
-
4,
|
|
172
|
-
1,
|
|
173
|
-
];
|
|
174
|
-
RomanNumber._preAlpha = [
|
|
175
|
-
'cm',
|
|
176
|
-
'cd',
|
|
177
|
-
'xc',
|
|
178
|
-
'xl',
|
|
179
|
-
'ix',
|
|
180
|
-
'iv',
|
|
181
|
-
'CM',
|
|
182
|
-
'CD',
|
|
183
|
-
'XC',
|
|
184
|
-
'XL',
|
|
185
|
-
'IX',
|
|
186
|
-
'IV',
|
|
187
|
-
'I',
|
|
188
|
-
];
|
|
189
|
-
RomanNumber._romanDigits = 'IVXLCDM';
|
|
190
|
-
RomanNumber._romanSubdigits = ' IIXXCC';
|
|
191
|
-
RomanNumber._romanValues = [1, 5, 10, 50, 100, 500, 1000];
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Default options for formatting a datation.
|
|
195
|
-
*/
|
|
196
|
-
var DATATION_FORMAT_OPTIONS = {
|
|
197
|
-
aboutText: 'c.',
|
|
198
|
-
bcText: 'BC',
|
|
199
|
-
adText: 'AD',
|
|
200
|
-
dayNames: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
|
|
201
|
-
monthNames: [
|
|
202
|
-
'jan',
|
|
203
|
-
'feb',
|
|
204
|
-
'mar',
|
|
205
|
-
'apr',
|
|
206
|
-
'may',
|
|
207
|
-
'jun',
|
|
208
|
-
'jul',
|
|
209
|
-
'aug',
|
|
210
|
-
'sep',
|
|
211
|
-
'oct',
|
|
212
|
-
'nov',
|
|
213
|
-
'dec',
|
|
214
|
-
],
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Single datation point in a historical date.
|
|
218
|
-
*/
|
|
219
|
-
// https://github.com/angular/angular/issues/18867#issuecomment-357484102
|
|
220
|
-
// @dynamic
|
|
221
|
-
var Datation = /** @class */ (function () {
|
|
222
|
-
/**
|
|
223
|
-
* Create a new datation, optionally setting its data.
|
|
224
|
-
* @param datation The optional data to be copied into the newly created datation.
|
|
225
|
-
*/
|
|
226
|
-
function Datation(datation) {
|
|
227
|
-
if (datation === void 0) { datation = null; }
|
|
228
|
-
if (datation) {
|
|
229
|
-
this.copyFrom(datation);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Sanitize the hint text representing a Datation's hint so that it does not
|
|
234
|
-
* include the reserved sequence -- (which gets replaced with Unicode EM
|
|
235
|
-
* space U+2014), nor the braces. This is because the double dashes are used
|
|
236
|
-
* to separate two datations, and braces to mark a hint in a datation.
|
|
237
|
-
* Also, the whitespaces are all flattened to simple spaces, and normalized
|
|
238
|
-
* (no whitespaces at start/end and no sequence of whitespaces).
|
|
239
|
-
* If the resulting sanitized string is empty, or it was null when received,
|
|
240
|
-
* null is returned.
|
|
241
|
-
* @param hint The hint or null/undefined.
|
|
242
|
-
* @returns The sanitized hint or undefined.
|
|
243
|
-
*/
|
|
244
|
-
Datation.sanitizeHint = function (hint) {
|
|
245
|
-
if (!hint || !hint.trim()) {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
// replace reserved characters
|
|
249
|
-
hint = hint.replace('--', '\u2014');
|
|
250
|
-
hint = hint.replace('{', '');
|
|
251
|
-
hint = hint.replace('}', '');
|
|
252
|
-
// flatten and normalize whitespaces
|
|
253
|
-
var s = hint.replace(/\s+/g, ' ').trim();
|
|
254
|
-
return s ? s : undefined;
|
|
255
|
-
};
|
|
256
|
-
Datation.regexEscape = function (text) {
|
|
257
|
-
// https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
|
|
258
|
-
return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
259
|
-
};
|
|
260
|
-
/**
|
|
261
|
-
* Get BC and AD patterns for matching.
|
|
262
|
-
* @param options The datation format options.
|
|
263
|
-
*/
|
|
264
|
-
Datation.getErasOptionsForRegex = function (options) {
|
|
265
|
-
if (options === void 0) { options = DATATION_FORMAT_OPTIONS; }
|
|
266
|
-
return [
|
|
267
|
-
options.bcText ? this.regexEscape(options.bcText) : 'BC',
|
|
268
|
-
options.adText ? this.regexEscape(options.adText) : 'AD',
|
|
269
|
-
];
|
|
270
|
-
};
|
|
271
|
-
Datation.getParserRegex = function (options) {
|
|
272
|
-
var bcad = this.getErasOptionsForRegex(options);
|
|
273
|
-
return new RegExp(
|
|
274
|
-
// about (1)
|
|
275
|
-
'(c\\.)?\\s*' +
|
|
276
|
-
// day (2)
|
|
277
|
-
'(?:([0123]?\\d)\\s+)?' +
|
|
278
|
-
// month (3)
|
|
279
|
-
'(?:([a-zA-Z]{3,})\\s+)?' +
|
|
280
|
-
// year/span (4,5)
|
|
281
|
-
'(?:' +
|
|
282
|
-
'(?:(\\d+)(?:\\s*/\\s*(\\d+))?)|' +
|
|
283
|
-
// century (6)
|
|
284
|
-
'([ivxIVX]+)' +
|
|
285
|
-
')\\s*' +
|
|
286
|
-
// era (7)
|
|
287
|
-
'(' +
|
|
288
|
-
bcad[0] +
|
|
289
|
-
'|' +
|
|
290
|
-
bcad[1] +
|
|
291
|
-
')?' +
|
|
292
|
-
// perhaps (8)
|
|
293
|
-
'(\\s*\\?)?' +
|
|
294
|
-
// hint (9)
|
|
295
|
-
'(?:\\s*\\{([^}]+)\\})?', 'i');
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Parse the specified text representing a datation.
|
|
299
|
-
* @param text The text to be parsed.
|
|
300
|
-
* @param options The formatter options.
|
|
301
|
-
* @returns The parsed datation, or undefined if invalid or empty.
|
|
302
|
-
* Note that here we return undefined to mean a non-existing point.
|
|
303
|
-
* We do not want a non-existing point to be represented as a null,
|
|
304
|
-
* as this would be included as in the JSON code when serializing.
|
|
305
|
-
*/
|
|
306
|
-
Datation.parse = function (text, options) {
|
|
307
|
-
if (options === void 0) { options = DATATION_FORMAT_OPTIONS; }
|
|
308
|
-
if (!text) {
|
|
309
|
-
return undefined;
|
|
310
|
-
}
|
|
311
|
-
var datation = new Datation();
|
|
312
|
-
var datationRegex = this.getParserRegex(options);
|
|
313
|
-
var m = datationRegex.exec(text);
|
|
314
|
-
if (!m) {
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
// about
|
|
318
|
-
if (m[1]) {
|
|
319
|
-
datation.isApproximate = true;
|
|
320
|
-
}
|
|
321
|
-
// day
|
|
322
|
-
if (m[2]) {
|
|
323
|
-
datation.day = parseInt(m[2], 10);
|
|
324
|
-
}
|
|
325
|
-
// month
|
|
326
|
-
if (m[3]) {
|
|
327
|
-
var lowerMonth_1 = m[3].toLowerCase();
|
|
328
|
-
var i = options.monthNames.findIndex(function (name) { return name.toLowerCase() === lowerMonth_1; });
|
|
329
|
-
if (i > -1) {
|
|
330
|
-
datation.month = i + 1;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
// year, span
|
|
334
|
-
if (m[4]) {
|
|
335
|
-
datation.value = parseInt(m[4], 10);
|
|
336
|
-
if (m[5]) {
|
|
337
|
-
datation.isSpan = true;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
datation.value = RomanNumber.fromRoman(m[6].toUpperCase());
|
|
342
|
-
datation.isCentury = true;
|
|
343
|
-
}
|
|
344
|
-
// era
|
|
345
|
-
if (m[7]) {
|
|
346
|
-
var era = m[7].replace(' ', '').toLowerCase();
|
|
347
|
-
if (era === options.bcText.toLowerCase()) {
|
|
348
|
-
datation.value = -datation.value;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
// dubious
|
|
352
|
-
if (m[8]) {
|
|
353
|
-
datation.isDubious = true;
|
|
354
|
-
}
|
|
355
|
-
// hint
|
|
356
|
-
if (m[9]) {
|
|
357
|
-
datation.hint = Datation.sanitizeHint(m[9]);
|
|
358
|
-
}
|
|
359
|
-
return datation;
|
|
360
|
-
};
|
|
361
|
-
/**
|
|
362
|
-
* Strip any era code from the specified datation format string.
|
|
363
|
-
* @param format The format string.
|
|
364
|
-
*/
|
|
365
|
-
Datation.stripFormatStringEra = function (format) {
|
|
366
|
-
if (!format) {
|
|
367
|
-
return 'i';
|
|
368
|
-
}
|
|
369
|
-
// convert ga gp Ga Gp into simple g G
|
|
370
|
-
format = format.replace(new RegExp('([gG])[ap]', 'gi'), '$1');
|
|
371
|
-
// replace g/G with i/I
|
|
372
|
-
format = format.replace('g', 'i');
|
|
373
|
-
format = format.replace('G', 'I');
|
|
374
|
-
// remove ea ep Ea Ep with preceding w/W if any
|
|
375
|
-
format = format.replace(new RegExp('[wW]?[eE][ap]?', 'gi'), '');
|
|
376
|
-
return format;
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* Reset this datation.
|
|
380
|
-
*/
|
|
381
|
-
Datation.prototype.reset = function () {
|
|
382
|
-
this.value = 0;
|
|
383
|
-
this.isCentury = false;
|
|
384
|
-
this.isSpan = false;
|
|
385
|
-
this.isApproximate = false;
|
|
386
|
-
this.day = 0;
|
|
387
|
-
this.month = 0;
|
|
388
|
-
this.hint = undefined;
|
|
389
|
-
};
|
|
390
|
-
/**
|
|
391
|
-
* Copy data from the specified source datatation.
|
|
392
|
-
* @param datation The source datation.
|
|
393
|
-
*/
|
|
394
|
-
Datation.prototype.copyFrom = function (datation) {
|
|
395
|
-
this.value = datation.value;
|
|
396
|
-
this.isCentury = datation.isCentury;
|
|
397
|
-
this.isSpan = datation.isSpan;
|
|
398
|
-
this.isApproximate = datation.isApproximate;
|
|
399
|
-
this.isDubious = datation.isDubious;
|
|
400
|
-
this.day = datation.day;
|
|
401
|
-
this.month = datation.month;
|
|
402
|
-
this.hint = datation.hint ? datation.hint : undefined;
|
|
403
|
-
};
|
|
404
|
-
/**
|
|
405
|
-
* True if this datation is undefined. A datation is undefined when
|
|
406
|
-
* its value is 0. Undefined datations are used as unknown points in a range
|
|
407
|
-
* for termini ante/post.
|
|
408
|
-
*/
|
|
409
|
-
Datation.prototype.isUndefined = function () {
|
|
410
|
-
return !this.value;
|
|
411
|
-
};
|
|
412
|
-
/**
|
|
413
|
-
* Get a sort value from this datation.
|
|
414
|
-
*/
|
|
415
|
-
Datation.prototype.getSortValue = function () {
|
|
416
|
-
var result;
|
|
417
|
-
if (this.isCentury) {
|
|
418
|
-
result = this.value * 100 + (this.value < 0 ? 50 : -50);
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
result = this.value;
|
|
422
|
-
}
|
|
423
|
-
if (this.isSpan) {
|
|
424
|
-
result += 0.5;
|
|
425
|
-
}
|
|
426
|
-
if (this.month > 0 && this.month <= 12) {
|
|
427
|
-
result += this.month / 12;
|
|
428
|
-
}
|
|
429
|
-
if (this.day > 0 && this.day <= 31) {
|
|
430
|
-
result += this.day / (12 * 31);
|
|
431
|
-
}
|
|
432
|
-
return result;
|
|
433
|
-
};
|
|
434
|
-
/**
|
|
435
|
-
* Get the 2-years span end value from this datation.
|
|
436
|
-
* A span year is always represented with its beginning year: e.g. -776/5
|
|
437
|
-
* is -776 with span, and 56/7 is 56 with span. This method returns the end year
|
|
438
|
-
* for a span, i.e. in the above samples -775 and 57 respectively. If this datation
|
|
439
|
-
* is not a span, the function just returns the unique year value.
|
|
440
|
-
*/
|
|
441
|
-
Datation.prototype.getSpanEnd = function () {
|
|
442
|
-
if (this.isCentury) {
|
|
443
|
-
return 0;
|
|
444
|
-
}
|
|
445
|
-
return this.isSpan ? this.value + 1 : this.value;
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* Get the century number corresponding this datation.
|
|
449
|
-
* This function returns 0 if the datation is null, or the century number,
|
|
450
|
-
* less than 0 if B.C. The result is based on the century value, if
|
|
451
|
-
* this is a century datation, or on the year, if this is not a century
|
|
452
|
-
* datation (e.g. -5 for 480 B.C., +1 for 31 A.D.).
|
|
453
|
-
*/
|
|
454
|
-
Datation.prototype.getCentury = function () {
|
|
455
|
-
if (this.value === 0) {
|
|
456
|
-
return 0;
|
|
457
|
-
}
|
|
458
|
-
return this.isCentury
|
|
459
|
-
? this.value
|
|
460
|
-
: Math.trunc(this.value / 100 + (this.value < 0 ? -1 : 1));
|
|
461
|
-
};
|
|
462
|
-
Datation.prototype.matchTokenAt = function (token, text, index) {
|
|
463
|
-
if (index + token.length > text.length) {
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
for (var i = 0; i < token.length; i++) {
|
|
467
|
-
if (token.charAt(i) !== text.charAt(i + index)) {
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return true;
|
|
472
|
-
};
|
|
473
|
-
Datation.prototype.parseFormatString = function (format) {
|
|
474
|
-
if (!format) {
|
|
475
|
-
return ['G'];
|
|
476
|
-
}
|
|
477
|
-
// expand macros
|
|
478
|
-
var macros = [
|
|
479
|
-
'ga',
|
|
480
|
-
'awdwMMMwvwepwpwh',
|
|
481
|
-
'Ga',
|
|
482
|
-
'awdwMMMwvwepwpwh',
|
|
483
|
-
'gp',
|
|
484
|
-
'awdwMMMwvweawpwh',
|
|
485
|
-
'Gp',
|
|
486
|
-
'awdwMMMwvweawpwh',
|
|
487
|
-
'g',
|
|
488
|
-
'awdwMMMwvwewpwh',
|
|
489
|
-
'G',
|
|
490
|
-
'AwdwMMMwVwewPwH',
|
|
491
|
-
'i',
|
|
492
|
-
'awdwMMMwvwpwh',
|
|
493
|
-
'I',
|
|
494
|
-
'AwdwMMMwVwPwH',
|
|
495
|
-
];
|
|
496
|
-
var sb = [];
|
|
497
|
-
var fi = 0;
|
|
498
|
-
var matched;
|
|
499
|
-
while (fi < format.length) {
|
|
500
|
-
matched = false;
|
|
501
|
-
for (var mi = 0; mi < macros.length; mi += 2) {
|
|
502
|
-
if (this.matchTokenAt(macros[mi], format, fi)) {
|
|
503
|
-
sb.push(macros[mi + 1]);
|
|
504
|
-
fi += macros[mi].length;
|
|
505
|
-
matched = true;
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
if (!matched) {
|
|
510
|
-
sb.push(format[fi]);
|
|
511
|
-
fi++;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
format = sb.join();
|
|
515
|
-
// split into tokens and literals
|
|
516
|
-
var tokens = [
|
|
517
|
-
'ddd',
|
|
518
|
-
'MMM',
|
|
519
|
-
'dd',
|
|
520
|
-
'ea',
|
|
521
|
-
'ep',
|
|
522
|
-
'Ea',
|
|
523
|
-
'Ep',
|
|
524
|
-
'ga',
|
|
525
|
-
'Ga',
|
|
526
|
-
'gp',
|
|
527
|
-
'Gp',
|
|
528
|
-
'MM',
|
|
529
|
-
];
|
|
530
|
-
fi = 0;
|
|
531
|
-
var results = [];
|
|
532
|
-
while (fi < format.length) {
|
|
533
|
-
matched = false;
|
|
534
|
-
for (var ti = 0; ti < tokens.length; ti++) {
|
|
535
|
-
if (this.matchTokenAt(tokens[ti], format, fi)) {
|
|
536
|
-
results.push(tokens[ti]);
|
|
537
|
-
fi += tokens[ti].length;
|
|
538
|
-
matched = true;
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
if (!matched) {
|
|
543
|
-
results.push(format.charAt(fi));
|
|
544
|
-
fi++;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return results;
|
|
548
|
-
};
|
|
549
|
-
/**
|
|
550
|
-
* Convert this datation to a string.
|
|
551
|
-
* @param format The format string, which can include any of the following:
|
|
552
|
-
* v = year or century value, lowercase
|
|
553
|
-
* V = year or century value, uppercase
|
|
554
|
-
* c = century, lowercase
|
|
555
|
-
* C = century, uppercase
|
|
556
|
-
* a or A = 'about' marker when present
|
|
557
|
-
* p or P = 'perhaps' marker when present
|
|
558
|
-
* d = day number when present
|
|
559
|
-
* dd = 2-digits (0-padded at left) day number when present
|
|
560
|
-
* ddd = weekday name when present
|
|
561
|
-
* M = month number when present
|
|
562
|
-
* MM = 2-digits (0-padded at left) month number when present
|
|
563
|
-
* MMM = month name when present
|
|
564
|
-
* e = era
|
|
565
|
-
* E = era, all uppercase
|
|
566
|
-
* ea = era, only if ante Christum natum
|
|
567
|
-
* ep = era, only if post Christum natum
|
|
568
|
-
* Ea = era all uppercase, only if ante Christum natum
|
|
569
|
-
* Ep = era all uppercase, only if post Christum natum
|
|
570
|
-
* h or H = hint when present
|
|
571
|
-
* w or W = smart whitespace (appended only when left char if any
|
|
572
|
-
* is not a whitespace)
|
|
573
|
-
* s or S = sort value
|
|
574
|
-
* g = generic: equal to awdwMMMwvwewpwh
|
|
575
|
-
* G = generic uppercase: equal to AwdwMMMwVwewPwH
|
|
576
|
-
* ga = generic ante Christum: era expressed only when post Christum
|
|
577
|
-
* natum. Equal to awdwMMMwvwepwpwh
|
|
578
|
-
* Ga = generic uppercase ante Christum: equal to awdwMMMwvwepwpwh
|
|
579
|
-
* gp = generic post Christum: era expressed only when ante Christum
|
|
580
|
-
* natum. Equal to awdwMMMwvweawpwh
|
|
581
|
-
* Gp = generic uppercase post Christum: equal to awdwMMMwvweawpwh
|
|
582
|
-
* i = generic with implicit (=not expressed) era: equal to awdwMMMwvwpwh
|
|
583
|
-
* I = generic uppercase with implicit (=not expressed) era: equal to
|
|
584
|
-
* AwdwMMMwVwPwH
|
|
585
|
-
* @param options The options.
|
|
586
|
-
*/
|
|
587
|
-
Datation.prototype.toString = function (format, options) {
|
|
588
|
-
var _this = this;
|
|
589
|
-
if (format === void 0) { format = 'G'; }
|
|
590
|
-
if (options === void 0) { options = DATATION_FORMAT_OPTIONS; }
|
|
591
|
-
if (this.isUndefined()) {
|
|
592
|
-
return '';
|
|
593
|
-
}
|
|
594
|
-
if (!format) {
|
|
595
|
-
format = 'G';
|
|
596
|
-
}
|
|
597
|
-
if (!options) {
|
|
598
|
-
options = DATATION_FORMAT_OPTIONS;
|
|
599
|
-
}
|
|
600
|
-
var sb = [];
|
|
601
|
-
var tokens = this.parseFormatString(format);
|
|
602
|
-
tokens.forEach(function (token) {
|
|
603
|
-
switch (token) {
|
|
604
|
-
case 'v':
|
|
605
|
-
case 'V':
|
|
606
|
-
// year or century
|
|
607
|
-
if (_this.isCentury) {
|
|
608
|
-
sb.push(token === 'v'
|
|
609
|
-
? RomanNumber.toRoman(Math.abs(_this.value)).toLowerCase()
|
|
610
|
-
: RomanNumber.toRoman(Math.abs(_this.value)).toUpperCase());
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
var year = Math.abs(_this.value);
|
|
614
|
-
sb.push(year.toString());
|
|
615
|
-
if (_this.isSpan) {
|
|
616
|
-
sb.push("/" + (year + (_this.value < 0 ? -1 : +1)));
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
break;
|
|
620
|
-
case 'c':
|
|
621
|
-
case 'C':
|
|
622
|
-
var century = Math.abs(_this.getCentury());
|
|
623
|
-
sb.push(token === 'c'
|
|
624
|
-
? RomanNumber.toRoman(century).toLowerCase()
|
|
625
|
-
: RomanNumber.toRoman(century).toUpperCase());
|
|
626
|
-
break;
|
|
627
|
-
case 'a':
|
|
628
|
-
case 'A':
|
|
629
|
-
if (_this.isApproximate) {
|
|
630
|
-
sb.push(options.aboutText);
|
|
631
|
-
}
|
|
632
|
-
break;
|
|
633
|
-
case 'p':
|
|
634
|
-
case 'P':
|
|
635
|
-
if (_this.isDubious) {
|
|
636
|
-
sb.push('?');
|
|
637
|
-
}
|
|
638
|
-
break;
|
|
639
|
-
case 'd':
|
|
640
|
-
if (_this.day > 0) {
|
|
641
|
-
sb.push(_this.day.toString());
|
|
642
|
-
}
|
|
643
|
-
break;
|
|
644
|
-
case 'dd':
|
|
645
|
-
if (_this.day > 0) {
|
|
646
|
-
sb.push(_this.day.toString().padStart(2, '0'));
|
|
647
|
-
}
|
|
648
|
-
break;
|
|
649
|
-
case 'ddd':
|
|
650
|
-
if (_this.day > 0) {
|
|
651
|
-
var date = new Date(_this.value, _this.month, _this.day);
|
|
652
|
-
var dow = date.getDay();
|
|
653
|
-
sb.push(options.dayNames[dow]);
|
|
654
|
-
}
|
|
655
|
-
break;
|
|
656
|
-
case 'M':
|
|
657
|
-
if (_this.month > 0) {
|
|
658
|
-
sb.push(_this.month.toString());
|
|
659
|
-
}
|
|
660
|
-
break;
|
|
661
|
-
case 'MM':
|
|
662
|
-
if (_this.month > 0) {
|
|
663
|
-
sb.push(_this.month.toString().padStart(2, '0'));
|
|
664
|
-
}
|
|
665
|
-
break;
|
|
666
|
-
case 'MMM':
|
|
667
|
-
if (_this.month > 0) {
|
|
668
|
-
sb.push(options.monthNames[_this.month - 1]);
|
|
669
|
-
}
|
|
670
|
-
break;
|
|
671
|
-
case 'e':
|
|
672
|
-
sb.push(_this.value < 0 ? options.bcText : options.adText);
|
|
673
|
-
break;
|
|
674
|
-
case 'E':
|
|
675
|
-
sb.push(_this.value < 0
|
|
676
|
-
? options.bcText.toUpperCase()
|
|
677
|
-
: options.adText.toUpperCase());
|
|
678
|
-
break;
|
|
679
|
-
case 'ea':
|
|
680
|
-
if (_this.value < 0) {
|
|
681
|
-
sb.push(options.bcText);
|
|
682
|
-
}
|
|
683
|
-
break;
|
|
684
|
-
case 'ep':
|
|
685
|
-
if (_this.value > 0) {
|
|
686
|
-
sb.push(options.adText);
|
|
687
|
-
}
|
|
688
|
-
break;
|
|
689
|
-
case 'h':
|
|
690
|
-
case 'H':
|
|
691
|
-
if (_this.hint) {
|
|
692
|
-
sb.push(" {" + _this.hint + "}");
|
|
693
|
-
}
|
|
694
|
-
break;
|
|
695
|
-
case 'w':
|
|
696
|
-
case 'W':
|
|
697
|
-
if (sb.length > 0) {
|
|
698
|
-
var last = sb[sb.length - 1];
|
|
699
|
-
if (!last.endsWith(' ')) {
|
|
700
|
-
sb.push(' ');
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
break;
|
|
704
|
-
case 's':
|
|
705
|
-
case 'S':
|
|
706
|
-
sb.push(_this.getSortValue().toString());
|
|
707
|
-
break;
|
|
708
|
-
default:
|
|
709
|
-
// literal
|
|
710
|
-
sb.push(token);
|
|
711
|
-
break;
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
return sb.join('').trim().replace(new RegExp('\\s+', 'g'), ' ');
|
|
715
|
-
};
|
|
716
|
-
return Datation;
|
|
717
|
-
}());
|
|
718
|
-
|
|
719
|
-
var APPROX_DELTA = 10;
|
|
720
|
-
/**
|
|
721
|
-
* Type of historical date.
|
|
722
|
-
*/
|
|
723
|
-
exports.HistoricalDateType = void 0;
|
|
724
|
-
(function (HistoricalDateType) {
|
|
725
|
-
HistoricalDateType[HistoricalDateType["undefined"] = 0] = "undefined";
|
|
726
|
-
HistoricalDateType[HistoricalDateType["point"] = 1] = "point";
|
|
727
|
-
HistoricalDateType[HistoricalDateType["range"] = 2] = "range";
|
|
728
|
-
})(exports.HistoricalDateType || (exports.HistoricalDateType = {}));
|
|
729
|
-
/**
|
|
730
|
-
* A historical date, including 0, 1, or 2 datation points.
|
|
731
|
-
*/
|
|
732
|
-
var HistoricalDate = /** @class */ (function () {
|
|
733
|
-
function HistoricalDate(date) {
|
|
734
|
-
if (date === void 0) { date = null; }
|
|
735
|
-
if (!date) {
|
|
736
|
-
this.a = new Datation();
|
|
737
|
-
// B=undefined for a single point
|
|
738
|
-
}
|
|
739
|
-
else {
|
|
740
|
-
this.a = new Datation(date.a);
|
|
741
|
-
if (date.b) {
|
|
742
|
-
this.b = new Datation(date.b);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* Parse the specified text representing a historical datation.
|
|
748
|
-
* @param text The text to be parsed.
|
|
749
|
-
* @param options The datation formatter options.
|
|
750
|
-
* @return The datation, or null if invalid.
|
|
751
|
-
*/
|
|
752
|
-
HistoricalDate.parse = function (text, options) {
|
|
753
|
-
if (options === void 0) { options = DATATION_FORMAT_OPTIONS; }
|
|
754
|
-
if (!text) {
|
|
755
|
-
return null;
|
|
756
|
-
}
|
|
757
|
-
var dates = text.split('--');
|
|
758
|
-
var s1 = dates[0].trim();
|
|
759
|
-
var s2 = dates.length > 1 ? dates[1].trim() : null;
|
|
760
|
-
var date = new HistoricalDate();
|
|
761
|
-
if (dates.length > 1) {
|
|
762
|
-
// if both terms are specified, integrate BC/AD indication in 1st if required
|
|
763
|
-
if (s1 && s2) {
|
|
764
|
-
var bcad = Datation.getErasOptionsForRegex(options);
|
|
765
|
-
var tailRegexp = new RegExp(
|
|
766
|
-
// era (1)
|
|
767
|
-
'(' +
|
|
768
|
-
bcad[0] +
|
|
769
|
-
'|' +
|
|
770
|
-
bcad[1] +
|
|
771
|
-
')?' +
|
|
772
|
-
// dubious (2)
|
|
773
|
-
'(\\s*\\?)?' +
|
|
774
|
-
// hint (3)
|
|
775
|
-
'(?:\\s*\\{?:([^)]+)\\})?\\s*$', 'gi');
|
|
776
|
-
var m1 = tailRegexp.exec(s1);
|
|
777
|
-
// if 1st has no era try integration from 2nd
|
|
778
|
-
if (m1 && m1[1]) {
|
|
779
|
-
// get era from 2nd (if 2nd hasn't it too, give up and AD will be assumed)
|
|
780
|
-
var m2 = tailRegexp.exec(s2);
|
|
781
|
-
if (m2 && m2[1]) {
|
|
782
|
-
var era = m2[1] || 'p.C.';
|
|
783
|
-
var sb1 = [];
|
|
784
|
-
if (m1.index > 0) {
|
|
785
|
-
sb1.push(s1.substr(0, m1.index));
|
|
786
|
-
}
|
|
787
|
-
sb1.push(' ' + era);
|
|
788
|
-
if (m1[2]) {
|
|
789
|
-
sb1.push('?');
|
|
790
|
-
}
|
|
791
|
-
if (m1[3]) {
|
|
792
|
-
sb1.push(" (" + m1[3] + ")");
|
|
793
|
-
}
|
|
794
|
-
s1 = sb1.join('');
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
date.setStartPoint(Datation.parse(s1, options));
|
|
799
|
-
date.setEndPoint(Datation.parse(s2, options));
|
|
800
|
-
}
|
|
801
|
-
else {
|
|
802
|
-
// here we have a s2, even if empty. When empty, it represents
|
|
803
|
-
// an unknown point in a terminus ante/post, and as such we
|
|
804
|
-
// must set B=null. When B=undefined, it's not a range but a point.
|
|
805
|
-
var d = Datation.parse(s1, options);
|
|
806
|
-
if (d && !d.isUndefined()) {
|
|
807
|
-
date.setSinglePoint(d);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
return date;
|
|
811
|
-
};
|
|
812
|
-
HistoricalDate.prototype.getStartPoint = function () {
|
|
813
|
-
return this.getDateType() === exports.HistoricalDateType.range ? this.a : undefined;
|
|
814
|
-
};
|
|
815
|
-
HistoricalDate.prototype.setStartPoint = function (value) {
|
|
816
|
-
this.a = new Datation(value);
|
|
817
|
-
// it's a range, ensure max is not null
|
|
818
|
-
if (!this.b) {
|
|
819
|
-
this.b = new Datation();
|
|
820
|
-
}
|
|
821
|
-
};
|
|
822
|
-
HistoricalDate.prototype.getEndPoint = function () {
|
|
823
|
-
return this.getDateType() === exports.HistoricalDateType.range ? this.b : undefined;
|
|
824
|
-
};
|
|
825
|
-
HistoricalDate.prototype.setEndPoint = function (value) {
|
|
826
|
-
this.b = new Datation(value);
|
|
827
|
-
};
|
|
828
|
-
HistoricalDate.prototype.getSinglePoint = function () {
|
|
829
|
-
return this.getDateType() === exports.HistoricalDateType.point ? this.a : undefined;
|
|
830
|
-
};
|
|
831
|
-
HistoricalDate.prototype.setSinglePoint = function (value) {
|
|
832
|
-
this.a = new Datation(value);
|
|
833
|
-
// it's a point, ensure max is undefined
|
|
834
|
-
this.b = undefined;
|
|
835
|
-
};
|
|
836
|
-
/**
|
|
837
|
-
* True if this date is undefined.
|
|
838
|
-
*/
|
|
839
|
-
HistoricalDate.prototype.isUndefined = function () {
|
|
840
|
-
return (!this.a || (this.a.isUndefined() && (!this.b || this.b.isUndefined())));
|
|
841
|
-
};
|
|
842
|
-
/**
|
|
843
|
-
* Get the type of this date.
|
|
844
|
-
*/
|
|
845
|
-
HistoricalDate.prototype.getDateType = function () {
|
|
846
|
-
if (this.isUndefined()) {
|
|
847
|
-
return exports.HistoricalDateType.undefined;
|
|
848
|
-
}
|
|
849
|
-
return this.b ? exports.HistoricalDateType.range : exports.HistoricalDateType.point;
|
|
850
|
-
};
|
|
851
|
-
/**
|
|
852
|
-
* Validate this date.
|
|
853
|
-
* @returns Error message if invalid, or null if valid.
|
|
854
|
-
*/
|
|
855
|
-
HistoricalDate.prototype.validate = function () {
|
|
856
|
-
if (!this.a) {
|
|
857
|
-
return 'Missing point A';
|
|
858
|
-
}
|
|
859
|
-
if (this.getDateType() === exports.HistoricalDateType.range) {
|
|
860
|
-
var av = this.a.getSortValue();
|
|
861
|
-
var bv = this.b.getSortValue();
|
|
862
|
-
if (av && bv && av >= bv) {
|
|
863
|
-
return 'Point A is past point B';
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
return null;
|
|
867
|
-
};
|
|
868
|
-
/**
|
|
869
|
-
* Get the sort value for this date.
|
|
870
|
-
*/
|
|
871
|
-
HistoricalDate.prototype.getSortValue = function () {
|
|
872
|
-
switch (this.getDateType()) {
|
|
873
|
-
case exports.HistoricalDateType.point:
|
|
874
|
-
return this.a.getSortValue();
|
|
875
|
-
case exports.HistoricalDateType.range:
|
|
876
|
-
if (this.a.isUndefined()) {
|
|
877
|
-
return this.b.getSortValue() - APPROX_DELTA;
|
|
878
|
-
}
|
|
879
|
-
if (this.b.isUndefined()) {
|
|
880
|
-
return this.a.getSortValue() + APPROX_DELTA;
|
|
881
|
-
}
|
|
882
|
-
return (this.a.getSortValue() + this.b.getSortValue()) / 2;
|
|
883
|
-
default:
|
|
884
|
-
return 0;
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
/**
|
|
888
|
-
* Build a textual representation of this date.
|
|
889
|
-
* @param format The format string.
|
|
890
|
-
* @param options The formatter options.
|
|
891
|
-
*/
|
|
892
|
-
HistoricalDate.prototype.toString = function (format, options) {
|
|
893
|
-
if (format === void 0) { format = 'G'; }
|
|
894
|
-
if (options === void 0) { options = DATATION_FORMAT_OPTIONS; }
|
|
895
|
-
var sb = [];
|
|
896
|
-
switch (this.getDateType()) {
|
|
897
|
-
case exports.HistoricalDateType.point:
|
|
898
|
-
sb.push(this.a.toString(format, options));
|
|
899
|
-
break;
|
|
900
|
-
case exports.HistoricalDateType.range:
|
|
901
|
-
// if both terms are present and belong to same era, omit it in 1st
|
|
902
|
-
if (!this.a.isUndefined() &&
|
|
903
|
-
this.b &&
|
|
904
|
-
!this.b.isUndefined() &&
|
|
905
|
-
this.a.value * this.b.value > 0) {
|
|
906
|
-
sb.push(this.a.toString(Datation.stripFormatStringEra(format), options));
|
|
907
|
-
sb.push(' -- ');
|
|
908
|
-
sb.push(this.b.toString(format, options));
|
|
909
|
-
break;
|
|
910
|
-
}
|
|
911
|
-
if (!this.a.isUndefined()) {
|
|
912
|
-
sb.push(this.a.toString(format, options) + ' ');
|
|
913
|
-
}
|
|
914
|
-
sb.push('--');
|
|
915
|
-
if (this.b && !this.b.isUndefined()) {
|
|
916
|
-
sb.push(this.b.toString(format, options));
|
|
917
|
-
}
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
return sb.join('');
|
|
921
|
-
};
|
|
922
|
-
/**
|
|
923
|
-
* Get the approximate year value from the specified century value.
|
|
924
|
-
* @param century The century number, negative if B.C.
|
|
925
|
-
*/
|
|
926
|
-
HistoricalDate.prototype.centuryToYear = function (century) {
|
|
927
|
-
return century * 100 + (century < 0 ? 50 : -50);
|
|
928
|
-
};
|
|
929
|
-
/**
|
|
930
|
-
* Convert this date into a single approximate year value.
|
|
931
|
-
* For centuries, the central century year is returned (e.g. -350 for IV B.C.
|
|
932
|
-
* and +350 for IV A.D.); when the date is a range with a single boundary only
|
|
933
|
-
* (max or min) the corresponding year minus or plus a predefined delta value
|
|
934
|
-
* (10) is returned; if it's a range with both boundaries (max and min),
|
|
935
|
-
* the middle year between them is returned.
|
|
936
|
-
* @param useTerminusSpan True to add or remove the predefined span from
|
|
937
|
-
* a terminus ante or post.
|
|
938
|
-
*/
|
|
939
|
-
HistoricalDate.prototype.toYear = function (useTerminusSpan) {
|
|
940
|
-
if (useTerminusSpan === void 0) { useTerminusSpan = true; }
|
|
941
|
-
var year = 0;
|
|
942
|
-
switch (this.getDateType()) {
|
|
943
|
-
case exports.HistoricalDateType.point:
|
|
944
|
-
year = Math.trunc(this.a.isCentury ? this.centuryToYear(this.a.value) : this.a.value);
|
|
945
|
-
break;
|
|
946
|
-
case exports.HistoricalDateType.range:
|
|
947
|
-
// min is missing: terminus ante
|
|
948
|
-
if (this.a.isUndefined()) {
|
|
949
|
-
year = Math.trunc((this.b.isCentury
|
|
950
|
-
? this.centuryToYear(this.b.value)
|
|
951
|
-
: this.b.value) - (useTerminusSpan ? APPROX_DELTA : 0));
|
|
952
|
-
break;
|
|
953
|
-
}
|
|
954
|
-
// max is missing: terminus post
|
|
955
|
-
if (!this.b || this.b.isUndefined()) {
|
|
956
|
-
year = Math.trunc((this.a.isCentury
|
|
957
|
-
? this.centuryToYear(this.a.value)
|
|
958
|
-
: this.a.value) + (useTerminusSpan ? APPROX_DELTA : 0));
|
|
959
|
-
break;
|
|
960
|
-
}
|
|
961
|
-
// both min and max
|
|
962
|
-
var min = this.a.isCentury
|
|
963
|
-
? this.centuryToYear(this.a.value)
|
|
964
|
-
: this.a.value;
|
|
965
|
-
var max = this.b.isCentury
|
|
966
|
-
? this.centuryToYear(this.b.value)
|
|
967
|
-
: this.b.value;
|
|
968
|
-
year = Math.trunc((max - min) / 2 + min);
|
|
969
|
-
if (year === 0) {
|
|
970
|
-
year = 1;
|
|
971
|
-
}
|
|
972
|
-
break;
|
|
973
|
-
}
|
|
974
|
-
return year;
|
|
975
|
-
};
|
|
976
|
-
/**
|
|
977
|
-
* True if any value (either in point or in range) has an about flag.
|
|
978
|
-
*/
|
|
979
|
-
HistoricalDate.prototype.isAbout = function () {
|
|
980
|
-
var about = false;
|
|
981
|
-
switch (this.getDateType()) {
|
|
982
|
-
case exports.HistoricalDateType.point:
|
|
983
|
-
about = this.a.isApproximate;
|
|
984
|
-
break;
|
|
985
|
-
case exports.HistoricalDateType.range:
|
|
986
|
-
if (!this.a.isUndefined()) {
|
|
987
|
-
about = this.a.isApproximate;
|
|
988
|
-
break;
|
|
989
|
-
}
|
|
990
|
-
if (!this.b.isUndefined()) {
|
|
991
|
-
about = this.b.isApproximate;
|
|
992
|
-
}
|
|
993
|
-
break;
|
|
994
|
-
}
|
|
995
|
-
return about;
|
|
996
|
-
};
|
|
997
|
-
/**
|
|
998
|
-
* True if any value (either in point or in range) has an about flag.
|
|
999
|
-
*/
|
|
1000
|
-
HistoricalDate.prototype.isDubious = function () {
|
|
1001
|
-
var dubious = false;
|
|
1002
|
-
switch (this.getDateType()) {
|
|
1003
|
-
case exports.HistoricalDateType.point:
|
|
1004
|
-
dubious = this.a.isDubious;
|
|
1005
|
-
break;
|
|
1006
|
-
case exports.HistoricalDateType.range:
|
|
1007
|
-
if (!this.a.isUndefined()) {
|
|
1008
|
-
dubious = this.a.isDubious;
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
if (!this.b.isUndefined()) {
|
|
1012
|
-
dubious = this.b.isDubious;
|
|
1013
|
-
}
|
|
1014
|
-
break;
|
|
1015
|
-
}
|
|
1016
|
-
return dubious;
|
|
1017
|
-
};
|
|
1018
|
-
return HistoricalDate;
|
|
1019
|
-
}());
|
|
1020
|
-
|
|
1021
|
-
/**
|
|
1022
|
-
* Data pin value type in a DataPinDefinition.
|
|
1023
|
-
*/
|
|
1024
|
-
exports.DataPinValueType = void 0;
|
|
1025
|
-
(function (DataPinValueType) {
|
|
1026
|
-
DataPinValueType[DataPinValueType["string"] = 0] = "string";
|
|
1027
|
-
DataPinValueType[DataPinValueType["boolean"] = 1] = "boolean";
|
|
1028
|
-
DataPinValueType[DataPinValueType["integer"] = 2] = "integer";
|
|
1029
|
-
DataPinValueType[DataPinValueType["decimal"] = 3] = "decimal";
|
|
1030
|
-
})(exports.DataPinValueType || (exports.DataPinValueType = {}));
|
|
1031
|
-
|
|
1032
|
-
/**
|
|
1033
|
-
* A simple text range, expressed as start character index and characters
|
|
1034
|
-
* length. This is used for misspellings operations.
|
|
1035
|
-
*/
|
|
1036
|
-
var TextRange = /** @class */ (function () {
|
|
1037
|
-
function TextRange(start, length) {
|
|
1038
|
-
if (start < 0)
|
|
1039
|
-
throw new RangeError('TextRange start less than 0');
|
|
1040
|
-
if (length < 0)
|
|
1041
|
-
throw new RangeError('TextRange length less than 0');
|
|
1042
|
-
this.start = start;
|
|
1043
|
-
this.length = length;
|
|
1044
|
-
}
|
|
1045
|
-
/**
|
|
1046
|
-
* Parse the specified text representing a range, in the form "startxlength"
|
|
1047
|
-
* or just "start" when length is 1.
|
|
1048
|
-
*
|
|
1049
|
-
* @param text The text.
|
|
1050
|
-
*/
|
|
1051
|
-
TextRange.parse = function (text) {
|
|
1052
|
-
if (!text) {
|
|
1053
|
-
return null;
|
|
1054
|
-
}
|
|
1055
|
-
// [1]=start, ([2]=length)
|
|
1056
|
-
var m = new RegExp('(\\d+)(?:[×x](\\d+))?', 'gm').exec(text);
|
|
1057
|
-
if (!m) {
|
|
1058
|
-
return null;
|
|
1059
|
-
}
|
|
1060
|
-
return new TextRange(parseInt(m[1], 10), m[2] ? parseInt(m[2], 10) : 1);
|
|
1061
|
-
};
|
|
1062
|
-
/**
|
|
1063
|
-
* Get the inclusive end of the range.
|
|
1064
|
-
*/
|
|
1065
|
-
TextRange.prototype.end = function () {
|
|
1066
|
-
var n = this.start + this.length;
|
|
1067
|
-
return n > 0 ? n - 1 : 0;
|
|
1068
|
-
};
|
|
1069
|
-
/**
|
|
1070
|
-
* True if this range value is equal to the other range value.
|
|
1071
|
-
* @param other The other range.
|
|
1072
|
-
*/
|
|
1073
|
-
TextRange.prototype.isEqual = function (other) {
|
|
1074
|
-
if (!other) {
|
|
1075
|
-
return false;
|
|
1076
|
-
}
|
|
1077
|
-
return this.start === other.start && this.length === other.length;
|
|
1078
|
-
};
|
|
1079
|
-
/**
|
|
1080
|
-
* Get a parsable textual representation of this range.
|
|
1081
|
-
* @returns Text.
|
|
1082
|
-
*/
|
|
1083
|
-
TextRange.prototype.toString = function () {
|
|
1084
|
-
return this.length === 1
|
|
1085
|
-
? this.start.toString()
|
|
1086
|
-
: this.start + "\u00D7" + this.length;
|
|
1087
|
-
};
|
|
1088
|
-
return TextRange;
|
|
1089
|
-
}());
|
|
1090
|
-
|
|
1091
|
-
/**
|
|
1092
|
-
* A single point in a token-based textual location.
|
|
1093
|
-
*/
|
|
1094
|
-
var TokenPoint = /** @class */ (function () {
|
|
1095
|
-
function TokenPoint(y, x, at, run) {
|
|
1096
|
-
if (at === void 0) { at = 0; }
|
|
1097
|
-
if (run === void 0) { run = 0; }
|
|
1098
|
-
this.y = y;
|
|
1099
|
-
this.x = x;
|
|
1100
|
-
this.at = at;
|
|
1101
|
-
this.run = run;
|
|
1102
|
-
}
|
|
1103
|
-
/**
|
|
1104
|
-
* Parse the specified text representing a token-based point location.
|
|
1105
|
-
* @param text The text to parse, in the forms Y.X or Y.X@AxR or
|
|
1106
|
-
* Y.X@A, where R=1.
|
|
1107
|
-
*/
|
|
1108
|
-
TokenPoint.parse = function (text) {
|
|
1109
|
-
var r = new RegExp('^(\\d+)\\.(\\d+)(?:@(\\d+)(?:x(\\d+))?)?$', 'g');
|
|
1110
|
-
var m = r.exec(text);
|
|
1111
|
-
if (!m) {
|
|
1112
|
-
return null;
|
|
1113
|
-
}
|
|
1114
|
-
var pt = new TokenPoint(parseInt(m[1], 10), parseInt(m[2], 10), m[3] ? parseInt(m[3], 10) : 0);
|
|
1115
|
-
if (m[3]) {
|
|
1116
|
-
if (m[4]) {
|
|
1117
|
-
pt.run = m[4] ? parseInt(m[4], 10) : 1;
|
|
1118
|
-
}
|
|
1119
|
-
else {
|
|
1120
|
-
pt.run = 1;
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
return pt;
|
|
1124
|
-
};
|
|
1125
|
-
TokenPoint.prototype.toString = function () {
|
|
1126
|
-
var s = this.y + "." + this.x;
|
|
1127
|
-
if (this.at > 0 && this.run > 0) {
|
|
1128
|
-
s += "@" + this.at;
|
|
1129
|
-
if (this.run !== 1) {
|
|
1130
|
-
s += "x" + this.run;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return s;
|
|
1134
|
-
};
|
|
1135
|
-
TokenPoint.prototype.compareTo = function (other) {
|
|
1136
|
-
if (this.y !== other.y) {
|
|
1137
|
-
return this.y - other.y;
|
|
1138
|
-
}
|
|
1139
|
-
if (this.x !== other.x) {
|
|
1140
|
-
return this.x - other.x;
|
|
1141
|
-
}
|
|
1142
|
-
if (this.at !== other.at) {
|
|
1143
|
-
return this.at - other.at;
|
|
1144
|
-
}
|
|
1145
|
-
return this.run - other.run;
|
|
1146
|
-
};
|
|
1147
|
-
TokenPoint.prototype.integralCompareTo = function (other) {
|
|
1148
|
-
if (this.y !== other.y) {
|
|
1149
|
-
return this.y - other.y;
|
|
1150
|
-
}
|
|
1151
|
-
if (this.x !== other.x) {
|
|
1152
|
-
return this.x - other.x;
|
|
1153
|
-
}
|
|
1154
|
-
return 0;
|
|
1155
|
-
};
|
|
1156
|
-
return TokenPoint;
|
|
1157
|
-
}());
|
|
1158
|
-
|
|
1159
|
-
var TokenLocation = /** @class */ (function () {
|
|
1160
|
-
function TokenLocation(primary, secondary) {
|
|
1161
|
-
if (secondary === void 0) { secondary = null; }
|
|
1162
|
-
this.primary = primary;
|
|
1163
|
-
this.secondary = secondary;
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* Parse the text representing a token-based location,
|
|
1167
|
-
* which has the form "primary-secondary", or just "primary",
|
|
1168
|
-
* where each of these points has the format required by
|
|
1169
|
-
* TokenPoint.parse (e.g. Y.X or Y.X@AxR or Y.X@A, where R=1).
|
|
1170
|
-
* @param text The text to parse.
|
|
1171
|
-
*/
|
|
1172
|
-
TokenLocation.parse = function (text) {
|
|
1173
|
-
if (!text) {
|
|
1174
|
-
return null;
|
|
1175
|
-
}
|
|
1176
|
-
var pair = text.split('-', 2);
|
|
1177
|
-
if (pair.length === 0) {
|
|
1178
|
-
return null;
|
|
1179
|
-
}
|
|
1180
|
-
return new TokenLocation(TokenPoint.parse(pair[0]), pair.length > 1 ? TokenPoint.parse(pair[1]) : null);
|
|
1181
|
-
};
|
|
1182
|
-
TokenLocation.prototype.isRange = function () {
|
|
1183
|
-
// note that != checks for both null and undefined, whereas !== does not
|
|
1184
|
-
return this.secondary != null;
|
|
1185
|
-
};
|
|
1186
|
-
TokenLocation.prototype.toString = function () {
|
|
1187
|
-
return this.secondary
|
|
1188
|
-
? this.primary.toString() + "-" + this.secondary.toString()
|
|
1189
|
-
: this.primary.toString();
|
|
1190
|
-
};
|
|
1191
|
-
TokenLocation.prototype.compareTo = function (other) {
|
|
1192
|
-
var n1 = this.primary.compareTo(other.primary);
|
|
1193
|
-
if (n1 !== 0) {
|
|
1194
|
-
return n1;
|
|
1195
|
-
}
|
|
1196
|
-
if (this.secondary && other.secondary) {
|
|
1197
|
-
return this.secondary.compareTo(other.secondary);
|
|
1198
|
-
}
|
|
1199
|
-
if (!this.secondary && !other.secondary) {
|
|
1200
|
-
return 0;
|
|
1201
|
-
}
|
|
1202
|
-
return this.secondary ? 1 : -1;
|
|
1203
|
-
};
|
|
1204
|
-
TokenLocation.prototype.overlaps = function (other) {
|
|
1205
|
-
// empty coords never overlaps
|
|
1206
|
-
if (!other.primary) {
|
|
1207
|
-
return false;
|
|
1208
|
-
}
|
|
1209
|
-
// (in the following comments A=this and B=other)
|
|
1210
|
-
// 1) if B is a point, cases are:
|
|
1211
|
-
// 1.1. A is a point: A overlaps with B (both points) if they're equal.
|
|
1212
|
-
// 1.2. A is a range: A (range) overlaps with B (point)
|
|
1213
|
-
// when A-left is <= B-left and A-right is >= B-right.
|
|
1214
|
-
if (other.secondary == null) {
|
|
1215
|
-
return !this.secondary
|
|
1216
|
-
? this.primary.integralCompareTo(other.primary) === 0
|
|
1217
|
-
: this.primary.compareTo(other.primary) <= 0 &&
|
|
1218
|
-
this.secondary.compareTo(other.primary) >= 0;
|
|
1219
|
-
}
|
|
1220
|
-
// 2) if B is a range, cases are:
|
|
1221
|
-
// 2.1. A is a point: A (point) overlaps with B (range) when B-left <= A and
|
|
1222
|
-
// B-right >= A
|
|
1223
|
-
// 2.2. A is a range: A (range) overlaps with B (range)
|
|
1224
|
-
// when B-right >= A-left and B-left <= A-right
|
|
1225
|
-
return !this.secondary
|
|
1226
|
-
? other.primary.compareTo(this.primary) <= 0 &&
|
|
1227
|
-
other.secondary.compareTo(this.primary) >= 0
|
|
1228
|
-
: other.secondary.compareTo(this.primary) >= 0 &&
|
|
1229
|
-
other.primary.compareTo(this.secondary) <= 0;
|
|
1230
|
-
};
|
|
1231
|
-
return TokenLocation;
|
|
1232
|
-
}());
|
|
1233
|
-
|
|
1234
|
-
/**
|
|
1235
|
-
* Deep-copy an object.
|
|
1236
|
-
*/
|
|
1237
|
-
function deepCopy(obj) {
|
|
1238
|
-
var copy;
|
|
1239
|
-
// handle the 3 simple types, and null or undefined
|
|
1240
|
-
if (null == obj || 'object' !== typeof obj) {
|
|
1241
|
-
return obj;
|
|
1242
|
-
}
|
|
1243
|
-
// handle date
|
|
1244
|
-
if (obj instanceof Date) {
|
|
1245
|
-
copy = new Date();
|
|
1246
|
-
copy.setTime(obj.getTime());
|
|
1247
|
-
return copy;
|
|
1248
|
-
}
|
|
1249
|
-
// handle array
|
|
1250
|
-
if (obj instanceof Array) {
|
|
1251
|
-
copy = [];
|
|
1252
|
-
for (var i = 0, len = obj.length; i < len; i++) {
|
|
1253
|
-
copy[i] = deepCopy(obj[i]);
|
|
1254
|
-
}
|
|
1255
|
-
return copy;
|
|
1256
|
-
}
|
|
1257
|
-
// handle object
|
|
1258
|
-
if (obj instanceof Object) {
|
|
1259
|
-
copy = {};
|
|
1260
|
-
for (var attr in obj) {
|
|
1261
|
-
if (obj.hasOwnProperty(attr)) {
|
|
1262
|
-
copy[attr] = deepCopy(obj[attr]);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
return copy;
|
|
1266
|
-
}
|
|
1267
|
-
throw new Error('Unable to copy object!');
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
var PendingChangesGuard = /** @class */ (function () {
|
|
1271
|
-
function PendingChangesGuard() {
|
|
1272
|
-
}
|
|
1273
|
-
PendingChangesGuard.prototype.canDeactivate = function (component) {
|
|
1274
|
-
// if there are no pending changes, just allow deactivation; else confirm first
|
|
1275
|
-
return !component || component.canDeactivate()
|
|
1276
|
-
? true
|
|
1277
|
-
: // NOTE: this warning message will only be shown when navigating
|
|
1278
|
-
// elsewhere within your angular app; when navigating away from your
|
|
1279
|
-
// angular app, the browser will show a generic warning message.
|
|
1280
|
-
// see http://stackoverflow.com/a/42207299/7307355
|
|
1281
|
-
confirm('Warning: your changes have not been saved. ' +
|
|
1282
|
-
'Press Cancel to go back and save, OK to continue.');
|
|
1283
|
-
};
|
|
1284
|
-
return PendingChangesGuard;
|
|
1285
|
-
}());
|
|
1286
|
-
PendingChangesGuard.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function PendingChangesGuard_Factory() { return new PendingChangesGuard(); }, token: PendingChangesGuard, providedIn: "root" });
|
|
1287
|
-
PendingChangesGuard.decorators = [
|
|
1288
|
-
{ type: i0.Injectable, args: [{
|
|
1289
|
-
providedIn: 'root'
|
|
1290
|
-
},] }
|
|
1291
|
-
];
|
|
1292
|
-
|
|
1293
|
-
/*! *****************************************************************************
|
|
1294
|
-
Copyright (c) Microsoft Corporation.
|
|
1295
|
-
|
|
1296
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
1297
|
-
purpose with or without fee is hereby granted.
|
|
1298
|
-
|
|
1299
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1300
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1301
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1302
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1303
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1304
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1305
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1306
|
-
***************************************************************************** */
|
|
1307
|
-
/* global Reflect, Promise */
|
|
1308
|
-
var extendStatics = function (d, b) {
|
|
1309
|
-
extendStatics = Object.setPrototypeOf ||
|
|
1310
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
1311
|
-
function (d, b) { for (var p in b)
|
|
1312
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
1313
|
-
d[p] = b[p]; };
|
|
1314
|
-
return extendStatics(d, b);
|
|
1315
|
-
};
|
|
1316
|
-
function __extends(d, b) {
|
|
1317
|
-
if (typeof b !== "function" && b !== null)
|
|
1318
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
1319
|
-
extendStatics(d, b);
|
|
1320
|
-
function __() { this.constructor = d; }
|
|
1321
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1322
|
-
}
|
|
1323
|
-
var __assign = function () {
|
|
1324
|
-
__assign = Object.assign || function __assign(t) {
|
|
1325
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1326
|
-
s = arguments[i];
|
|
1327
|
-
for (var p in s)
|
|
1328
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1329
|
-
t[p] = s[p];
|
|
1330
|
-
}
|
|
1331
|
-
return t;
|
|
1332
|
-
};
|
|
1333
|
-
return __assign.apply(this, arguments);
|
|
1334
|
-
};
|
|
1335
|
-
function __rest(s, e) {
|
|
1336
|
-
var t = {};
|
|
1337
|
-
for (var p in s)
|
|
1338
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1339
|
-
t[p] = s[p];
|
|
1340
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1341
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1342
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1343
|
-
t[p[i]] = s[p[i]];
|
|
1344
|
-
}
|
|
1345
|
-
return t;
|
|
1346
|
-
}
|
|
1347
|
-
function __decorate(decorators, target, key, desc) {
|
|
1348
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1349
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1350
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
1351
|
-
else
|
|
1352
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1353
|
-
if (d = decorators[i])
|
|
1354
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1355
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1356
|
-
}
|
|
1357
|
-
function __param(paramIndex, decorator) {
|
|
1358
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
1359
|
-
}
|
|
1360
|
-
function __metadata(metadataKey, metadataValue) {
|
|
1361
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1362
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
1363
|
-
}
|
|
1364
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1365
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1366
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1367
|
-
function fulfilled(value) { try {
|
|
1368
|
-
step(generator.next(value));
|
|
1369
|
-
}
|
|
1370
|
-
catch (e) {
|
|
1371
|
-
reject(e);
|
|
1372
|
-
} }
|
|
1373
|
-
function rejected(value) { try {
|
|
1374
|
-
step(generator["throw"](value));
|
|
1375
|
-
}
|
|
1376
|
-
catch (e) {
|
|
1377
|
-
reject(e);
|
|
1378
|
-
} }
|
|
1379
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1380
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
function __generator(thisArg, body) {
|
|
1384
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
1385
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
1386
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
1387
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
1388
|
-
function step(op) {
|
|
1389
|
-
if (f)
|
|
1390
|
-
throw new TypeError("Generator is already executing.");
|
|
1391
|
-
while (_)
|
|
1392
|
-
try {
|
|
1393
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
1394
|
-
return t;
|
|
1395
|
-
if (y = 0, t)
|
|
1396
|
-
op = [op[0] & 2, t.value];
|
|
1397
|
-
switch (op[0]) {
|
|
1398
|
-
case 0:
|
|
1399
|
-
case 1:
|
|
1400
|
-
t = op;
|
|
1401
|
-
break;
|
|
1402
|
-
case 4:
|
|
1403
|
-
_.label++;
|
|
1404
|
-
return { value: op[1], done: false };
|
|
1405
|
-
case 5:
|
|
1406
|
-
_.label++;
|
|
1407
|
-
y = op[1];
|
|
1408
|
-
op = [0];
|
|
1409
|
-
continue;
|
|
1410
|
-
case 7:
|
|
1411
|
-
op = _.ops.pop();
|
|
1412
|
-
_.trys.pop();
|
|
1413
|
-
continue;
|
|
1414
|
-
default:
|
|
1415
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1416
|
-
_ = 0;
|
|
1417
|
-
continue;
|
|
1418
|
-
}
|
|
1419
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
1420
|
-
_.label = op[1];
|
|
1421
|
-
break;
|
|
1422
|
-
}
|
|
1423
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
1424
|
-
_.label = t[1];
|
|
1425
|
-
t = op;
|
|
1426
|
-
break;
|
|
1427
|
-
}
|
|
1428
|
-
if (t && _.label < t[2]) {
|
|
1429
|
-
_.label = t[2];
|
|
1430
|
-
_.ops.push(op);
|
|
1431
|
-
break;
|
|
1432
|
-
}
|
|
1433
|
-
if (t[2])
|
|
1434
|
-
_.ops.pop();
|
|
1435
|
-
_.trys.pop();
|
|
1436
|
-
continue;
|
|
1437
|
-
}
|
|
1438
|
-
op = body.call(thisArg, _);
|
|
1439
|
-
}
|
|
1440
|
-
catch (e) {
|
|
1441
|
-
op = [6, e];
|
|
1442
|
-
y = 0;
|
|
1443
|
-
}
|
|
1444
|
-
finally {
|
|
1445
|
-
f = t = 0;
|
|
1446
|
-
}
|
|
1447
|
-
if (op[0] & 5)
|
|
1448
|
-
throw op[1];
|
|
1449
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
1453
|
-
if (k2 === undefined)
|
|
1454
|
-
k2 = k;
|
|
1455
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
1456
|
-
}) : (function (o, m, k, k2) {
|
|
1457
|
-
if (k2 === undefined)
|
|
1458
|
-
k2 = k;
|
|
1459
|
-
o[k2] = m[k];
|
|
1460
|
-
});
|
|
1461
|
-
function __exportStar(m, o) {
|
|
1462
|
-
for (var p in m)
|
|
1463
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
1464
|
-
__createBinding(o, m, p);
|
|
1465
|
-
}
|
|
1466
|
-
function __values(o) {
|
|
1467
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
1468
|
-
if (m)
|
|
1469
|
-
return m.call(o);
|
|
1470
|
-
if (o && typeof o.length === "number")
|
|
1471
|
-
return {
|
|
1472
|
-
next: function () {
|
|
1473
|
-
if (o && i >= o.length)
|
|
1474
|
-
o = void 0;
|
|
1475
|
-
return { value: o && o[i++], done: !o };
|
|
1476
|
-
}
|
|
1477
|
-
};
|
|
1478
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
1479
|
-
}
|
|
1480
|
-
function __read(o, n) {
|
|
1481
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
1482
|
-
if (!m)
|
|
1483
|
-
return o;
|
|
1484
|
-
var i = m.call(o), r, ar = [], e;
|
|
1485
|
-
try {
|
|
1486
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
1487
|
-
ar.push(r.value);
|
|
1488
|
-
}
|
|
1489
|
-
catch (error) {
|
|
1490
|
-
e = { error: error };
|
|
1491
|
-
}
|
|
1492
|
-
finally {
|
|
1493
|
-
try {
|
|
1494
|
-
if (r && !r.done && (m = i["return"]))
|
|
1495
|
-
m.call(i);
|
|
1496
|
-
}
|
|
1497
|
-
finally {
|
|
1498
|
-
if (e)
|
|
1499
|
-
throw e.error;
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
return ar;
|
|
1503
|
-
}
|
|
1504
|
-
/** @deprecated */
|
|
1505
|
-
function __spread() {
|
|
1506
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
1507
|
-
ar = ar.concat(__read(arguments[i]));
|
|
1508
|
-
return ar;
|
|
1509
|
-
}
|
|
1510
|
-
/** @deprecated */
|
|
1511
|
-
function __spreadArrays() {
|
|
1512
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
1513
|
-
s += arguments[i].length;
|
|
1514
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
1515
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
1516
|
-
r[k] = a[j];
|
|
1517
|
-
return r;
|
|
1518
|
-
}
|
|
1519
|
-
function __spreadArray(to, from) {
|
|
1520
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
1521
|
-
to[j] = from[i];
|
|
1522
|
-
return to;
|
|
1523
|
-
}
|
|
1524
|
-
function __await(v) {
|
|
1525
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
1526
|
-
}
|
|
1527
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
1528
|
-
if (!Symbol.asyncIterator)
|
|
1529
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
1530
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
1531
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
1532
|
-
function verb(n) { if (g[n])
|
|
1533
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
1534
|
-
function resume(n, v) { try {
|
|
1535
|
-
step(g[n](v));
|
|
1536
|
-
}
|
|
1537
|
-
catch (e) {
|
|
1538
|
-
settle(q[0][3], e);
|
|
1539
|
-
} }
|
|
1540
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
1541
|
-
function fulfill(value) { resume("next", value); }
|
|
1542
|
-
function reject(value) { resume("throw", value); }
|
|
1543
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
1544
|
-
resume(q[0][0], q[0][1]); }
|
|
1545
|
-
}
|
|
1546
|
-
function __asyncDelegator(o) {
|
|
1547
|
-
var i, p;
|
|
1548
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
1549
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
1550
|
-
}
|
|
1551
|
-
function __asyncValues(o) {
|
|
1552
|
-
if (!Symbol.asyncIterator)
|
|
1553
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
1554
|
-
var m = o[Symbol.asyncIterator], i;
|
|
1555
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
1556
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
1557
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
1558
|
-
}
|
|
1559
|
-
function __makeTemplateObject(cooked, raw) {
|
|
1560
|
-
if (Object.defineProperty) {
|
|
1561
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
|
1562
|
-
}
|
|
1563
|
-
else {
|
|
1564
|
-
cooked.raw = raw;
|
|
1565
|
-
}
|
|
1566
|
-
return cooked;
|
|
1567
|
-
}
|
|
1568
|
-
;
|
|
1569
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
1570
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1571
|
-
}) : function (o, v) {
|
|
1572
|
-
o["default"] = v;
|
|
1573
|
-
};
|
|
1574
|
-
function __importStar(mod) {
|
|
1575
|
-
if (mod && mod.__esModule)
|
|
1576
|
-
return mod;
|
|
1577
|
-
var result = {};
|
|
1578
|
-
if (mod != null)
|
|
1579
|
-
for (var k in mod)
|
|
1580
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
1581
|
-
__createBinding(result, mod, k);
|
|
1582
|
-
__setModuleDefault(result, mod);
|
|
1583
|
-
return result;
|
|
1584
|
-
}
|
|
1585
|
-
function __importDefault(mod) {
|
|
1586
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
1587
|
-
}
|
|
1588
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
1589
|
-
if (kind === "a" && !f)
|
|
1590
|
-
throw new TypeError("Private accessor was defined without a getter");
|
|
1591
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1592
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1593
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1594
|
-
}
|
|
1595
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
1596
|
-
if (kind === "m")
|
|
1597
|
-
throw new TypeError("Private method is not writable");
|
|
1598
|
-
if (kind === "a" && !f)
|
|
1599
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
1600
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1601
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1602
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
/**
|
|
1606
|
-
* Sort pipe. Use like *ngFor="let i of items | sort:'propname'".
|
|
1607
|
-
*/
|
|
1608
|
-
var SortPipe = /** @class */ (function () {
|
|
1609
|
-
function SortPipe() {
|
|
1610
|
-
}
|
|
1611
|
-
SortPipe.prototype.transform = function (value, propName) {
|
|
1612
|
-
if (!value || !Array.isArray(value)) {
|
|
1613
|
-
return value;
|
|
1614
|
-
}
|
|
1615
|
-
return __spreadArray([], __read(value)).sort(function (a, b) {
|
|
1616
|
-
if (!a && !b) {
|
|
1617
|
-
return 0;
|
|
1618
|
-
}
|
|
1619
|
-
if (!a && b) {
|
|
1620
|
-
return -1;
|
|
1621
|
-
}
|
|
1622
|
-
if (a && !b) {
|
|
1623
|
-
return 1;
|
|
1624
|
-
}
|
|
1625
|
-
if (a[propName] < b[propName]) {
|
|
1626
|
-
return -1;
|
|
1627
|
-
}
|
|
1628
|
-
else if (a[propName] === b[propName]) {
|
|
1629
|
-
return 0;
|
|
1630
|
-
}
|
|
1631
|
-
else if (a[propName] > b[propName]) {
|
|
1632
|
-
return 1;
|
|
1633
|
-
}
|
|
1634
|
-
});
|
|
1635
|
-
};
|
|
1636
|
-
return SortPipe;
|
|
1637
|
-
}());
|
|
1638
|
-
SortPipe.decorators = [
|
|
1639
|
-
{ type: i0.Pipe, args: [{
|
|
1640
|
-
name: 'sort',
|
|
1641
|
-
},] }
|
|
1642
|
-
];
|
|
1643
|
-
|
|
1644
|
-
/**
|
|
1645
|
-
* Environment variables service. This requires EnvServiceProvider.
|
|
1646
|
-
* See https://www.jvandemo.com/how-to-use-environment-variables-to-configure-your-angular-application-without-a-rebuild/.
|
|
1647
|
-
*
|
|
1648
|
-
* To use this service:
|
|
1649
|
-
* 1. ensure to add env.js from your app's src folder to the app's assets
|
|
1650
|
-
* ("src/env.js" under architect/build/options/assets);
|
|
1651
|
-
* 2. add the EnvServiceProvider to your app's providers array;
|
|
1652
|
-
* 3. ensure to include env.js in the head of your index.html:
|
|
1653
|
-
* <script src="env.js"></script>.
|
|
1654
|
-
*
|
|
1655
|
-
* The env.js file should include all your environment-dependent settings,
|
|
1656
|
-
* e.g.:
|
|
1657
|
-
*
|
|
1658
|
-
* (function (window) {
|
|
1659
|
-
* window.__env = window.__env || {};
|
|
1660
|
-
* window.__env.apiUrl = 'http://localhost:60200/api/';
|
|
1661
|
-
* }(this));
|
|
1662
|
-
*/
|
|
1663
|
-
var EnvService = /** @class */ (function () {
|
|
1664
|
-
function EnvService() {
|
|
1665
|
-
this._map = new Map();
|
|
1666
|
-
}
|
|
1667
|
-
/**
|
|
1668
|
-
* Get the value for the specified key. If the key is not found,
|
|
1669
|
-
* defValue will be returned.
|
|
1670
|
-
*
|
|
1671
|
-
* @param key The key.
|
|
1672
|
-
* @param defValue The default value to return if key is not found.
|
|
1673
|
-
*/
|
|
1674
|
-
EnvService.prototype.get = function (key, defValue) {
|
|
1675
|
-
if (this._map.has(key)) {
|
|
1676
|
-
return this._map.get(key);
|
|
1677
|
-
}
|
|
1678
|
-
return defValue;
|
|
1679
|
-
};
|
|
1680
|
-
/**
|
|
1681
|
-
* Enumerate all the keys in this store.
|
|
1682
|
-
*/
|
|
1683
|
-
EnvService.prototype.getKeys = function () {
|
|
1684
|
-
return this._map.keys();
|
|
1685
|
-
};
|
|
1686
|
-
/**
|
|
1687
|
-
* Set a value with the specified key.
|
|
1688
|
-
*
|
|
1689
|
-
* @param key The key.
|
|
1690
|
-
* @param value The value.
|
|
1691
|
-
*/
|
|
1692
|
-
EnvService.prototype.set = function (key, value) {
|
|
1693
|
-
this._map.set(key, value);
|
|
1694
|
-
};
|
|
1695
|
-
/**
|
|
1696
|
-
* Delete the value with the specified key, if any.
|
|
1697
|
-
*
|
|
1698
|
-
* @param key The key.
|
|
1699
|
-
*/
|
|
1700
|
-
EnvService.prototype.delete = function (key) {
|
|
1701
|
-
this._map.delete(key);
|
|
1702
|
-
};
|
|
1703
|
-
/**
|
|
1704
|
-
* Clear this store.
|
|
1705
|
-
*/
|
|
1706
|
-
EnvService.prototype.clear = function () {
|
|
1707
|
-
this._map.clear();
|
|
1708
|
-
};
|
|
1709
|
-
return EnvService;
|
|
1710
|
-
}());
|
|
1711
|
-
EnvService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function EnvService_Factory() { return new EnvService(); }, token: EnvService, providedIn: "root" });
|
|
1712
|
-
EnvService.decorators = [
|
|
1713
|
-
{ type: i0.Injectable, args: [{
|
|
1714
|
-
providedIn: 'root',
|
|
1715
|
-
},] }
|
|
1716
|
-
];
|
|
1717
|
-
EnvService.ctorParameters = function () { return []; };
|
|
1718
|
-
|
|
1719
|
-
// https://www.jvandemo.com/how-to-use-environment-variables-to-configure-your-angular-application-without-a-rebuild/
|
|
1720
|
-
/**
|
|
1721
|
-
* This function creates an instance of EnvService, and copies
|
|
1722
|
-
* all the properties from window.__env object into it.
|
|
1723
|
-
*/
|
|
1724
|
-
var EnvServiceFactory = function () {
|
|
1725
|
-
var env = new EnvService();
|
|
1726
|
-
// read environment variables from browser window
|
|
1727
|
-
var browserWindow = window || {};
|
|
1728
|
-
var browserWindowEnv = browserWindow['__env'] || {};
|
|
1729
|
-
// assign environment variables from browser window to env;
|
|
1730
|
-
// in the current implementation, properties from env.js
|
|
1731
|
-
// overwrite defaults (if any) from the EnvService.
|
|
1732
|
-
for (var key in browserWindowEnv) {
|
|
1733
|
-
if (browserWindowEnv.hasOwnProperty(key)) {
|
|
1734
|
-
env.set(key, browserWindowEnv[key]);
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
return env;
|
|
1738
|
-
};
|
|
1739
|
-
/**
|
|
1740
|
-
* A provider recipe for the EnvService.
|
|
1741
|
-
* This must be registered in the applications providers array.
|
|
1742
|
-
*/
|
|
1743
|
-
var EnvServiceProvider = {
|
|
1744
|
-
provide: EnvService,
|
|
1745
|
-
useFactory: EnvServiceFactory,
|
|
1746
|
-
deps: [],
|
|
1747
|
-
};
|
|
1748
|
-
|
|
1749
|
-
// https://angular.io/guide/http
|
|
1750
|
-
/**
|
|
1751
|
-
* Error handler for services. To use this in your service, pipe a catchError
|
|
1752
|
-
* operator with its argument equal to the handleError method of this service.
|
|
1753
|
-
* Note: pipe this method after retry, if using it.
|
|
1754
|
-
*/
|
|
1755
|
-
var ErrorService = /** @class */ (function () {
|
|
1756
|
-
function ErrorService() {
|
|
1757
|
-
}
|
|
1758
|
-
/**
|
|
1759
|
-
* Handle the specified error response.
|
|
1760
|
-
* @param error The error response.
|
|
1761
|
-
*/
|
|
1762
|
-
ErrorService.prototype.handleError = function (error) {
|
|
1763
|
-
if (error.error instanceof ErrorEvent) {
|
|
1764
|
-
// A client-side or network error occurred. Handle it accordingly.
|
|
1765
|
-
console.error('A client-side or network error occurred: ', error.error.message);
|
|
1766
|
-
}
|
|
1767
|
-
else {
|
|
1768
|
-
// The backend returned an unsuccessful response code.
|
|
1769
|
-
// The response body may contain clues as to what went wrong,
|
|
1770
|
-
console.error("Backend returned code " + error.status + ", " + ("body was: " + error.error));
|
|
1771
|
-
if (typeof error === 'object') {
|
|
1772
|
-
console.log(JSON.stringify(error));
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
// return an observable with a user-facing error message
|
|
1776
|
-
return rxjs.throwError('Something bad happened; please try again later.');
|
|
1777
|
-
};
|
|
1778
|
-
return ErrorService;
|
|
1779
|
-
}());
|
|
1780
|
-
ErrorService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function ErrorService_Factory() { return new ErrorService(); }, token: ErrorService, providedIn: "root" });
|
|
1781
|
-
ErrorService.decorators = [
|
|
1782
|
-
{ type: i0.Injectable, args: [{
|
|
1783
|
-
providedIn: 'root',
|
|
1784
|
-
},] }
|
|
1785
|
-
];
|
|
1786
|
-
|
|
1787
|
-
// npm i gravatar --save
|
|
1788
|
-
// npm i @types/gravatar --save
|
|
1789
|
-
var GravatarService = /** @class */ (function () {
|
|
1790
|
-
function GravatarService() {
|
|
1791
|
-
}
|
|
1792
|
-
/**
|
|
1793
|
-
* Builds the URL to the Gravatar avatar corresponding to the specified email
|
|
1794
|
-
* address.
|
|
1795
|
-
* @param email: The email address.
|
|
1796
|
-
* @param size The required size in pixels (1-512).
|
|
1797
|
-
*/
|
|
1798
|
-
GravatarService.prototype.buildGravatarUrl = function (email, size) {
|
|
1799
|
-
if (size === void 0) { size = 80; }
|
|
1800
|
-
if (!email) {
|
|
1801
|
-
return null;
|
|
1802
|
-
}
|
|
1803
|
-
return gravatar__namespace.url(email, { s: size.toString() });
|
|
1804
|
-
// const hash = this._hash.getMd5(email.trim().toLowerCase());
|
|
1805
|
-
// return this.buildGravatarUrlFromHash(hash, size);
|
|
1806
|
-
};
|
|
1807
|
-
return GravatarService;
|
|
1808
|
-
}());
|
|
1809
|
-
GravatarService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function GravatarService_Factory() { return new GravatarService(); }, token: GravatarService, providedIn: "root" });
|
|
1810
|
-
GravatarService.decorators = [
|
|
1811
|
-
{ type: i0.Injectable, args: [{
|
|
1812
|
-
providedIn: 'root'
|
|
1813
|
-
},] }
|
|
1814
|
-
];
|
|
1815
|
-
|
|
1816
|
-
/**
|
|
1817
|
-
* Library route service.
|
|
1818
|
-
* This service is used to build routes to part and fragment editors,
|
|
1819
|
-
* which are hosted in an open list of library modules in the Cadmus
|
|
1820
|
-
* application.
|
|
1821
|
-
* This architecture allows lazy-loading part- and fragment-editors
|
|
1822
|
-
* only when they are required.
|
|
1823
|
-
* Each part type with its dumb UI editor component is located in a
|
|
1824
|
-
* library, named after the name of the group the part belongs to. For
|
|
1825
|
-
* instance, the model and dumb UI editor component for a part belonging
|
|
1826
|
-
* to the "general" group are located in the "parts/general/general-ui"
|
|
1827
|
-
* library.
|
|
1828
|
-
* In turn, the feature UI editor component for the same part is located
|
|
1829
|
-
* in the "parts/general/general-feature" library. This library has
|
|
1830
|
-
* a route for each part editor. For instance, the NotePart editor
|
|
1831
|
-
* component route is "items/:iid/general/it.vedph.note/:pid", where
|
|
1832
|
-
* ":iid" is the item ID and ":pid" the part ID.
|
|
1833
|
-
*/
|
|
1834
|
-
var LibraryRouteService = /** @class */ (function () {
|
|
1835
|
-
function LibraryRouteService(_partEditorKeys) {
|
|
1836
|
-
this._partEditorKeys = _partEditorKeys;
|
|
1837
|
-
}
|
|
1838
|
-
/**
|
|
1839
|
-
* Strip the eventual fragment-role ID from the specified part's role ID.
|
|
1840
|
-
* For instance, a part's role ID like "fr.it.vedph.comment:scholarly"
|
|
1841
|
-
* becomes "fr.it.vedph.comment".
|
|
1842
|
-
*
|
|
1843
|
-
* @param roleId The part's role ID.
|
|
1844
|
-
*/
|
|
1845
|
-
LibraryRouteService.prototype.stripFragmentRoleId = function (roleId) {
|
|
1846
|
-
// remove the optional :fr-role from roleId
|
|
1847
|
-
var i = roleId.lastIndexOf(':');
|
|
1848
|
-
if (i > -1) {
|
|
1849
|
-
roleId = roleId.substring(0, i);
|
|
1850
|
-
}
|
|
1851
|
-
return roleId;
|
|
1852
|
-
};
|
|
1853
|
-
/**
|
|
1854
|
-
* Get the fragment type and role from the part's role ID. This starts
|
|
1855
|
-
* with "fr.", and might be followed by the role proper, introduced
|
|
1856
|
-
* by the first dot if any. For instance, "fr.it.vedph.comment" would just
|
|
1857
|
-
* return "fr.it.vedph.comment", while "fr.it.vedph.comment:scholarly"
|
|
1858
|
-
* would return "fr.it.vedph.comment". This is required to navigate to
|
|
1859
|
-
* the correct fragment editor, which is the same for each fragment type,
|
|
1860
|
-
* independently from its role.
|
|
1861
|
-
* @param role The part role ID.
|
|
1862
|
-
* @returns An object where frTypeId=fragment type ID and frRoleId=fragment role
|
|
1863
|
-
* ID, or null.
|
|
1864
|
-
*/
|
|
1865
|
-
LibraryRouteService.prototype.getFragmentTypeAndRole = function (roleId) {
|
|
1866
|
-
if (!roleId || !roleId.startsWith('fr.')) {
|
|
1867
|
-
return null;
|
|
1868
|
-
}
|
|
1869
|
-
var i = roleId.indexOf(':');
|
|
1870
|
-
if (i > -1) {
|
|
1871
|
-
return {
|
|
1872
|
-
frTypeId: roleId.substring(0, i),
|
|
1873
|
-
frRoleId: roleId.substring(i + 1)
|
|
1874
|
-
};
|
|
1875
|
-
}
|
|
1876
|
-
else {
|
|
1877
|
-
return {
|
|
1878
|
-
frTypeId: roleId,
|
|
1879
|
-
frRoleId: null
|
|
1880
|
-
};
|
|
1881
|
-
}
|
|
1882
|
-
};
|
|
1883
|
-
/**
|
|
1884
|
-
* Find among the specified parts definitions the one matching the specified
|
|
1885
|
-
* type ID, and eventually role ID when specified.
|
|
1886
|
-
*
|
|
1887
|
-
* @param partDefs The parts definitions.
|
|
1888
|
-
* @param typeId The type ID.
|
|
1889
|
-
* @param roleId The role ID or null.
|
|
1890
|
-
* @returns Part definition or null if not found.
|
|
1891
|
-
*/
|
|
1892
|
-
LibraryRouteService.prototype.findPartDefinition = function (partDefs, typeId, roleId) {
|
|
1893
|
-
var _this = this;
|
|
1894
|
-
if (roleId === void 0) { roleId = null; }
|
|
1895
|
-
if (!partDefs) {
|
|
1896
|
-
return null;
|
|
1897
|
-
}
|
|
1898
|
-
// if role ID is specified, find both type and role
|
|
1899
|
-
if (roleId) {
|
|
1900
|
-
var reqRoleId_1 = this.stripFragmentRoleId(roleId);
|
|
1901
|
-
return partDefs.find(function (d) {
|
|
1902
|
-
return (d.typeId === typeId &&
|
|
1903
|
-
_this.stripFragmentRoleId(d.roleId) === reqRoleId_1);
|
|
1904
|
-
});
|
|
1905
|
-
}
|
|
1906
|
-
// else just find type ID
|
|
1907
|
-
return partDefs.find(function (d) {
|
|
1908
|
-
return d.typeId === typeId;
|
|
1909
|
-
});
|
|
1910
|
-
};
|
|
1911
|
-
/**
|
|
1912
|
-
* Get the library editor key from the specified part type, looking up
|
|
1913
|
-
* the specified parts definitions.
|
|
1914
|
-
*
|
|
1915
|
-
* @param typeId The part's type ID.
|
|
1916
|
-
* @param roleId The part's role ID.
|
|
1917
|
-
*/
|
|
1918
|
-
LibraryRouteService.prototype.getEditorKeyFromPartType = function (typeId, roleId) {
|
|
1919
|
-
if (roleId === void 0) { roleId = null; }
|
|
1920
|
-
// find the part type ID
|
|
1921
|
-
var partGroupKey = this._partEditorKeys[typeId];
|
|
1922
|
-
if (!partGroupKey) {
|
|
1923
|
-
return {
|
|
1924
|
-
partKey: 'default'
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
// additionally find the role ID if specified
|
|
1928
|
-
if (roleId) {
|
|
1929
|
-
var reqRoleId = this.stripFragmentRoleId(roleId);
|
|
1930
|
-
return {
|
|
1931
|
-
partKey: partGroupKey.part,
|
|
1932
|
-
frKey: partGroupKey.fragments[reqRoleId]
|
|
1933
|
-
};
|
|
1934
|
-
}
|
|
1935
|
-
return {
|
|
1936
|
-
partKey: partGroupKey.part
|
|
1937
|
-
};
|
|
1938
|
-
};
|
|
1939
|
-
/**
|
|
1940
|
-
* Decompose the specified editor key into part and fragment.
|
|
1941
|
-
* A simple editor key will just provide the same value for both.
|
|
1942
|
-
*
|
|
1943
|
-
* @param key The editor key to decompose.
|
|
1944
|
-
*/
|
|
1945
|
-
LibraryRouteService.prototype.decomposeEditorKey = function (key) {
|
|
1946
|
-
var i = key.indexOf(' ');
|
|
1947
|
-
if (i > -1) {
|
|
1948
|
-
return {
|
|
1949
|
-
partKey: key.substr(0, i),
|
|
1950
|
-
frKey: key.substr(i + 1)
|
|
1951
|
-
};
|
|
1952
|
-
}
|
|
1953
|
-
else {
|
|
1954
|
-
return {
|
|
1955
|
-
partKey: key,
|
|
1956
|
-
frKey: key
|
|
1957
|
-
};
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
/**
|
|
1961
|
-
* Build the route to the part editor corresponding to the specified
|
|
1962
|
-
* part.
|
|
1963
|
-
*
|
|
1964
|
-
* A part editing route is like
|
|
1965
|
-
* "/items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>",
|
|
1966
|
-
* where the role ID is optional, and may include the fragment role ID
|
|
1967
|
-
* as a suffix preceded by a colon.
|
|
1968
|
-
*
|
|
1969
|
-
* A fragment editing route is like
|
|
1970
|
-
* "/items/<id>/<part-group>/fragment/<part-id>/<fr-typeid>/<loc>?rid=<role-id>",
|
|
1971
|
-
* where the role ID is as above, and the fragment's type ID is derived
|
|
1972
|
-
* from the part's role ID, stripping the eventual fragment's role ID out.
|
|
1973
|
-
*
|
|
1974
|
-
* @param itemId The ID of the item the parts belongs to.
|
|
1975
|
-
* @param partId The part's ID.
|
|
1976
|
-
* @param typeId The part's type ID.
|
|
1977
|
-
* @param roleId The optional part's role ID.
|
|
1978
|
-
* @returns Object with a route property and an optional rid property
|
|
1979
|
-
* representing the role ID, which will be rendered as a query parameter.
|
|
1980
|
-
*/
|
|
1981
|
-
LibraryRouteService.prototype.buildPartEditorRoute = function (itemId, partId, typeId, roleId) {
|
|
1982
|
-
var route;
|
|
1983
|
-
var editorKey = this.getEditorKeyFromPartType(typeId);
|
|
1984
|
-
// /items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>
|
|
1985
|
-
route = "/items/" + itemId + "/" + editorKey.partKey + "/" + typeId + "/" + partId;
|
|
1986
|
-
return {
|
|
1987
|
-
route: route,
|
|
1988
|
-
rid: roleId
|
|
1989
|
-
};
|
|
1990
|
-
};
|
|
1991
|
-
/**
|
|
1992
|
-
* Build the route to the fragment editor corresponding to the specified
|
|
1993
|
-
* layers part and location.
|
|
1994
|
-
*
|
|
1995
|
-
* @param partDefs The parts definitions.
|
|
1996
|
-
* @param itemId The ID of the item the parts belongs to.
|
|
1997
|
-
* @param partId The part's ID.
|
|
1998
|
-
* @param typeId The part's type ID.
|
|
1999
|
-
* @param roleId The part's role ID.
|
|
2000
|
-
* @param loc The fragment's location.
|
|
2001
|
-
* @returns Object with a route property and an optional rid property
|
|
2002
|
-
* representing the role ID, which will be rendered as a query parameter.
|
|
2003
|
-
*/
|
|
2004
|
-
LibraryRouteService.prototype.buildFragmentEditorRoute = function (partDefs, itemId, partId, typeId, roleId, loc) {
|
|
2005
|
-
var route;
|
|
2006
|
-
var editorKey = this.getEditorKeyFromPartType(typeId, roleId);
|
|
2007
|
-
var _a = this.getFragmentTypeAndRole(roleId), frTypeId = _a.frTypeId, frRoleId = _a.frRoleId;
|
|
2008
|
-
route = "/items/" + itemId + "/" + editorKey.frKey + "/fragment/" + partId + "/" + frTypeId + "/" + loc;
|
|
2009
|
-
return {
|
|
2010
|
-
route: route,
|
|
2011
|
-
rid: frRoleId
|
|
2012
|
-
};
|
|
2013
|
-
};
|
|
2014
|
-
return LibraryRouteService;
|
|
2015
|
-
}());
|
|
2016
|
-
LibraryRouteService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LibraryRouteService_Factory() { return new LibraryRouteService(i0__namespace.ɵɵinject("partEditorKeys")); }, token: LibraryRouteService, providedIn: "root" });
|
|
2017
|
-
LibraryRouteService.decorators = [
|
|
2018
|
-
{ type: i0.Injectable, args: [{
|
|
2019
|
-
providedIn: 'root'
|
|
2020
|
-
},] }
|
|
2021
|
-
];
|
|
2022
|
-
LibraryRouteService.ctorParameters = function () { return [
|
|
2023
|
-
{ type: undefined, decorators: [{ type: i0.Inject, args: ['partEditorKeys',] }] }
|
|
2024
|
-
]; };
|
|
2025
|
-
|
|
2026
|
-
var LocalStorageService = /** @class */ (function () {
|
|
2027
|
-
function LocalStorageService() {
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* Retrieve the object with the specified key from the specified storage.
|
|
2031
|
-
* @param key key.
|
|
2032
|
-
* @param session true to use session instead of local storage.
|
|
2033
|
-
*/
|
|
2034
|
-
LocalStorageService.prototype.retrieve = function (key, session) {
|
|
2035
|
-
if (session === void 0) { session = false; }
|
|
2036
|
-
var json = session
|
|
2037
|
-
? sessionStorage.getItem(key)
|
|
2038
|
-
: localStorage.getItem(key);
|
|
2039
|
-
if (!json) {
|
|
2040
|
-
return null;
|
|
2041
|
-
}
|
|
2042
|
-
return JSON.parse(json);
|
|
2043
|
-
};
|
|
2044
|
-
/**
|
|
2045
|
-
* Store the specified object with the specified key in the specified storage.
|
|
2046
|
-
* @param key key.
|
|
2047
|
-
* @param value object.
|
|
2048
|
-
* @param session true to use session instead of local storage.
|
|
2049
|
-
*/
|
|
2050
|
-
LocalStorageService.prototype.store = function (key, value, session) {
|
|
2051
|
-
if (session === void 0) { session = false; }
|
|
2052
|
-
if (session) {
|
|
2053
|
-
sessionStorage.setItem(key, JSON.stringify(value));
|
|
2054
|
-
}
|
|
2055
|
-
else {
|
|
2056
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
2057
|
-
}
|
|
2058
|
-
};
|
|
2059
|
-
/**
|
|
2060
|
-
* Remove the object with the specified key from the specified storage.
|
|
2061
|
-
* @param key key.
|
|
2062
|
-
* @param session true to use session instead of local storage.
|
|
2063
|
-
*/
|
|
2064
|
-
LocalStorageService.prototype.remove = function (key, session) {
|
|
2065
|
-
if (session === void 0) { session = false; }
|
|
2066
|
-
if (session) {
|
|
2067
|
-
sessionStorage.removeItem(key);
|
|
2068
|
-
}
|
|
2069
|
-
else {
|
|
2070
|
-
localStorage.removeItem(key);
|
|
2071
|
-
}
|
|
2072
|
-
};
|
|
2073
|
-
/**
|
|
2074
|
-
* Get all the stored entities keys starting with the specified prefix.
|
|
2075
|
-
* @param prefix key prefix.
|
|
2076
|
-
* @param session true to use session instead of local storage.
|
|
2077
|
-
*/
|
|
2078
|
-
LocalStorageService.prototype.getKeys = function (prefix, session) {
|
|
2079
|
-
if (session === void 0) { session = false; }
|
|
2080
|
-
var keys = [];
|
|
2081
|
-
if (session) {
|
|
2082
|
-
for (var i = 0, len = sessionStorage.length; i < len; i++) {
|
|
2083
|
-
var key = sessionStorage.key(i);
|
|
2084
|
-
if (key.startsWith(prefix)) {
|
|
2085
|
-
keys.push(key);
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
else {
|
|
2090
|
-
for (var i = 0, len = localStorage.length; i < len; i++) {
|
|
2091
|
-
var key = localStorage.key(i);
|
|
2092
|
-
if (key.startsWith(prefix)) {
|
|
2093
|
-
keys.push(key);
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
return keys;
|
|
2098
|
-
};
|
|
2099
|
-
/**
|
|
2100
|
-
* Remove all the entries whose key starts with the specified prefix.
|
|
2101
|
-
* @param prefix key prefix.
|
|
2102
|
-
*/
|
|
2103
|
-
LocalStorageService.prototype.clear = function (prefix, session) {
|
|
2104
|
-
if (session === void 0) { session = false; }
|
|
2105
|
-
if (session) {
|
|
2106
|
-
for (var i = 0, len = sessionStorage.length; i < len; i++) {
|
|
2107
|
-
var key = sessionStorage.key(i);
|
|
2108
|
-
if (key.startsWith(prefix)) {
|
|
2109
|
-
sessionStorage.removeItem(key);
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
else {
|
|
2114
|
-
for (var i = 0, len = localStorage.length; i < len; i++) {
|
|
2115
|
-
var key = localStorage.key(i);
|
|
2116
|
-
if (key.startsWith(prefix)) {
|
|
2117
|
-
localStorage.removeItem(key);
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
};
|
|
2122
|
-
return LocalStorageService;
|
|
2123
|
-
}());
|
|
2124
|
-
LocalStorageService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LocalStorageService_Factory() { return new LocalStorageService(); }, token: LocalStorageService, providedIn: "root" });
|
|
2125
|
-
LocalStorageService.decorators = [
|
|
2126
|
-
{ type: i0.Injectable, args: [{
|
|
2127
|
-
providedIn: 'root',
|
|
2128
|
-
},] }
|
|
2129
|
-
];
|
|
2130
|
-
|
|
2131
|
-
var TextLayerService = /** @class */ (function () {
|
|
2132
|
-
function TextLayerService() {
|
|
2133
|
-
this._wsRegex = new RegExp('^\\s$', 'g');
|
|
2134
|
-
}
|
|
2135
|
-
TextLayerService.prototype.isWhitespace = function (c) {
|
|
2136
|
-
if (!c) {
|
|
2137
|
-
return false;
|
|
2138
|
-
}
|
|
2139
|
-
if (c.length !== 1) {
|
|
2140
|
-
c = c.charAt(0);
|
|
2141
|
-
}
|
|
2142
|
-
return this._wsRegex.test(c);
|
|
2143
|
-
};
|
|
2144
|
-
/**
|
|
2145
|
-
* Extract the lines with their tokens from the specified text.
|
|
2146
|
-
* @param text the source text.
|
|
2147
|
-
* @returns lines.
|
|
2148
|
-
*/
|
|
2149
|
-
TextLayerService.prototype.getLines = function (text) {
|
|
2150
|
-
var results = [];
|
|
2151
|
-
if (!text) {
|
|
2152
|
-
return results;
|
|
2153
|
-
}
|
|
2154
|
-
var lines = text.split('\n');
|
|
2155
|
-
for (var y = 0; y < lines.length; y++) {
|
|
2156
|
-
var line = lines[y].trim();
|
|
2157
|
-
var l = {
|
|
2158
|
-
y: y + 1,
|
|
2159
|
-
tokens: [],
|
|
2160
|
-
};
|
|
2161
|
-
var x = 0;
|
|
2162
|
-
var xBeg = 0;
|
|
2163
|
-
while (x < line.length) {
|
|
2164
|
-
if (this.isWhitespace(line.charAt(x))) {
|
|
2165
|
-
l.tokens.push(line.substr(xBeg, x - xBeg));
|
|
2166
|
-
x++;
|
|
2167
|
-
while (x < line.length && this.isWhitespace(line.charAt(x))) {
|
|
2168
|
-
x++;
|
|
2169
|
-
}
|
|
2170
|
-
xBeg = x;
|
|
2171
|
-
}
|
|
2172
|
-
else {
|
|
2173
|
-
x++;
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
if (xBeg < x) {
|
|
2177
|
-
l.tokens.push(line.substr(xBeg));
|
|
2178
|
-
}
|
|
2179
|
-
results.push(l);
|
|
2180
|
-
}
|
|
2181
|
-
return results;
|
|
2182
|
-
};
|
|
2183
|
-
/*
|
|
2184
|
-
* Rendition: HTML rendering from a base text and a set of fragments locations.
|
|
2185
|
-
* Each line in the base text is rendered with p; each token in a line is
|
|
2186
|
-
* rendered with its text value, and tokens are separated by space. Layer
|
|
2187
|
-
* fragments are rendered inside a span, with an id equal to the fragment location
|
|
2188
|
-
* plus a suffix beginning with _, added only for the purpose of ensuring unique
|
|
2189
|
-
* IDs in the rendered HTML code. Example:
|
|
2190
|
-
* <div>
|
|
2191
|
-
* <p id="y1">this is line 1.</p>
|
|
2192
|
-
* <p id="y2">here's a <span id="f2.3_0">fragment</span>.</p>
|
|
2193
|
-
* </div>
|
|
2194
|
-
*/
|
|
2195
|
-
/**
|
|
2196
|
-
* Render the opening span for a layer fragment.
|
|
2197
|
-
* @param loc location.
|
|
2198
|
-
* @param locPortion the index of the token's portion (0-N). This is used
|
|
2199
|
-
* to build a unique ID for each HTML span rendering a layer fragment.
|
|
2200
|
-
* @param sb the target strings array.
|
|
2201
|
-
* @param isSelected true if selected.
|
|
2202
|
-
*/
|
|
2203
|
-
TextLayerService.prototype.renderOpeningSpan = function (loc, locPortion, sb, isSelected) {
|
|
2204
|
-
sb.push("<span id=\"f" + loc.toString() + "_" + locPortion + "\" class=\"fr" + (isSelected ? 'fr-sel' : '') + "\">");
|
|
2205
|
-
};
|
|
2206
|
-
/**
|
|
2207
|
-
* Render the specified token intersecting the specified end-fragment location.
|
|
2208
|
-
* @param pt The point.
|
|
2209
|
-
* @param token The token.
|
|
2210
|
-
* @param sb The target array.
|
|
2211
|
-
*/
|
|
2212
|
-
TextLayerService.prototype.renderTokenAtEnd = function (pt, token, sb) {
|
|
2213
|
-
if (pt.at > 0) {
|
|
2214
|
-
// ...to]
|
|
2215
|
-
sb.push(token.substr(pt.at - 1, pt.run));
|
|
2216
|
-
sb.push('</span>');
|
|
2217
|
-
// ...ken
|
|
2218
|
-
if (pt.at - 1 + pt.run < token.length) {
|
|
2219
|
-
sb.push(token.substr(pt.at - 1 + pt.run));
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
else {
|
|
2223
|
-
// ...token]
|
|
2224
|
-
sb.push(token);
|
|
2225
|
-
sb.push('</span>');
|
|
2226
|
-
}
|
|
2227
|
-
};
|
|
2228
|
-
/**
|
|
2229
|
-
* Render the specified token intersecting the specified single-point location.
|
|
2230
|
-
* The received token starts and ends a single-token range.
|
|
2231
|
-
* @param loc location.
|
|
2232
|
-
* @param token token.
|
|
2233
|
-
* @param sb target strings array.
|
|
2234
|
-
* @param isSelected True if the token is selected.
|
|
2235
|
-
*/
|
|
2236
|
-
TextLayerService.prototype.renderTokenAtPointStart = function (loc, token, sb, isSelected) {
|
|
2237
|
-
// 1.token's left-part
|
|
2238
|
-
if (loc.primary.at > 0) {
|
|
2239
|
-
// to...
|
|
2240
|
-
sb.push(token.substr(0, loc.primary.at - 1));
|
|
2241
|
-
}
|
|
2242
|
-
// 2.span: [
|
|
2243
|
-
this.renderOpeningSpan(loc, 0, sb, isSelected);
|
|
2244
|
-
// 3.token's right-part (...ken]/...ke]n or ...token])
|
|
2245
|
-
this.renderTokenAtEnd(loc.primary, token, sb);
|
|
2246
|
-
};
|
|
2247
|
-
/**
|
|
2248
|
-
* Render the specified token intersecting the specified range start location.
|
|
2249
|
-
* The received token starts a multi-tokens range.
|
|
2250
|
-
* @param loc location.
|
|
2251
|
-
* @param locPortion the index of the token's portion (0-N). This is used
|
|
2252
|
-
* to build a unique ID for each HTML span rendering a layer fragment.
|
|
2253
|
-
* @param token token.
|
|
2254
|
-
* @param sb target strings array.
|
|
2255
|
-
* @param isSelected True if the token is selected.
|
|
2256
|
-
*/
|
|
2257
|
-
TextLayerService.prototype.renderTokenAtRangeStart = function (loc, token, sb, isSelected) {
|
|
2258
|
-
// 1.token's left-part (=before at)
|
|
2259
|
-
if (loc.primary.at > 0) {
|
|
2260
|
-
// to...
|
|
2261
|
-
sb.push(token.substr(0, loc.primary.at - 1));
|
|
2262
|
-
}
|
|
2263
|
-
// 2.span: [
|
|
2264
|
-
this.renderOpeningSpan(loc, 0, sb, isSelected);
|
|
2265
|
-
// 3.token's right-part (...ken or ...token)
|
|
2266
|
-
if (loc.primary.at > 0) {
|
|
2267
|
-
// ...ken
|
|
2268
|
-
sb.push(token.substr(loc.primary.at - 1));
|
|
2269
|
-
}
|
|
2270
|
-
else {
|
|
2271
|
-
// ...token
|
|
2272
|
-
sb.push(token);
|
|
2273
|
-
}
|
|
2274
|
-
};
|
|
2275
|
-
TextLayerService.prototype.renderTokenAtStart = function (loc, token, sb, isSelected) {
|
|
2276
|
-
if (!loc.secondary) {
|
|
2277
|
-
// single
|
|
2278
|
-
this.renderTokenAtPointStart(loc, token, sb, isSelected);
|
|
2279
|
-
return false;
|
|
2280
|
-
}
|
|
2281
|
-
else {
|
|
2282
|
-
// range
|
|
2283
|
-
this.renderTokenAtRangeStart(loc, token, sb, isSelected);
|
|
2284
|
-
return true;
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
/**
|
|
2288
|
-
* Render to HTML the base text decorated with its layer fragments.
|
|
2289
|
-
* @param text The base text.
|
|
2290
|
-
* @param locations The locations of all the fragments
|
|
2291
|
-
* of the same type to be rendered on top of the base text.
|
|
2292
|
-
* @param selectedLoc The optional location of the selected
|
|
2293
|
-
* fragment if any. The selected fragment gets decorated with an additional
|
|
2294
|
-
* class value.
|
|
2295
|
-
*/
|
|
2296
|
-
TextLayerService.prototype.render = function (text, locations, selectedLoc) {
|
|
2297
|
-
if (selectedLoc === void 0) { selectedLoc = null; }
|
|
2298
|
-
if (!text) {
|
|
2299
|
-
return '<div></div>';
|
|
2300
|
-
}
|
|
2301
|
-
// get lines from text
|
|
2302
|
-
var sb = [];
|
|
2303
|
-
var lines = this.getLines(text);
|
|
2304
|
-
var loc = null;
|
|
2305
|
-
var tokenSelected = false;
|
|
2306
|
-
if (!locations) {
|
|
2307
|
-
locations = [];
|
|
2308
|
-
}
|
|
2309
|
-
// for each line in text
|
|
2310
|
-
sb.push('<div>');
|
|
2311
|
-
var _loop_1 = function (y) {
|
|
2312
|
-
sb.push("<p id=\"y" + (y + 1) + "\">");
|
|
2313
|
-
// reopen a span if continuing a fragment from prev line
|
|
2314
|
-
if (loc) {
|
|
2315
|
-
this_1.renderOpeningSpan(loc, y + 1 - loc.primary.y, sb, tokenSelected);
|
|
2316
|
-
}
|
|
2317
|
-
// for each token in line
|
|
2318
|
-
var line = lines[y];
|
|
2319
|
-
var _loop_2 = function (x) {
|
|
2320
|
-
// add separator if required
|
|
2321
|
-
if (x > 0) {
|
|
2322
|
-
sb.push(' ');
|
|
2323
|
-
}
|
|
2324
|
-
var token = line.tokens[x];
|
|
2325
|
-
// if inside a fragment, check if this token is the last
|
|
2326
|
-
if (loc && loc.secondary) {
|
|
2327
|
-
if (loc.secondary.y === y + 1 && loc.secondary.x === x + 1) {
|
|
2328
|
-
this_1.renderTokenAtEnd(loc.secondary, token, sb);
|
|
2329
|
-
loc = null;
|
|
2330
|
-
}
|
|
2331
|
-
else {
|
|
2332
|
-
sb.push(token);
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
else {
|
|
2336
|
-
// else, check if this token starts a fragment
|
|
2337
|
-
loc = locations.find(function (l) {
|
|
2338
|
-
return l.primary.y === y + 1 && l.primary.x === x + 1;
|
|
2339
|
-
});
|
|
2340
|
-
if (loc) {
|
|
2341
|
-
tokenSelected = selectedLoc ? loc.overlaps(selectedLoc) : false;
|
|
2342
|
-
if (!this_1.renderTokenAtStart(loc, token, sb, tokenSelected)) {
|
|
2343
|
-
loc = null;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
else {
|
|
2347
|
-
sb.push(token);
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
};
|
|
2351
|
-
for (var x = 0; x < line.tokens.length; x++) {
|
|
2352
|
-
_loop_2(x);
|
|
2353
|
-
}
|
|
2354
|
-
// close a span if pending at p end
|
|
2355
|
-
if (loc) {
|
|
2356
|
-
sb.push('</span>');
|
|
2357
|
-
}
|
|
2358
|
-
sb.push('</p>');
|
|
2359
|
-
};
|
|
2360
|
-
var this_1 = this;
|
|
2361
|
-
for (var y = 0; y < lines.length; y++) {
|
|
2362
|
-
_loop_1(y);
|
|
2363
|
-
}
|
|
2364
|
-
sb.push('</div>');
|
|
2365
|
-
return sb.join('');
|
|
2366
|
-
};
|
|
2367
|
-
/*
|
|
2368
|
-
Location: starting from user selection on a rendered text, get the corresponding
|
|
2369
|
-
layer fragment location. This differs according to the purpose of the location
|
|
2370
|
-
to be got: if getting a location for an existing fragment, at least 1 decorated
|
|
2371
|
-
text (span) should be included in the selection, which does not require to be
|
|
2372
|
-
exact; if getting a location for a new fragment, no decorated text (span) can be
|
|
2373
|
-
included in the selection (two fragments in the same layer can never overlap),
|
|
2374
|
-
which must be exact.
|
|
2375
|
-
*/
|
|
2376
|
-
/**
|
|
2377
|
-
* Get the Y bounds from the specified selection.
|
|
2378
|
-
* @param range The selection range.
|
|
2379
|
-
* @param forNew True if getting bounds for a new fragment.
|
|
2380
|
-
* @returns Range, inclusive.
|
|
2381
|
-
*/
|
|
2382
|
-
TextLayerService.prototype.getYBoundsFromRange = function (range, forNew) {
|
|
2383
|
-
var p = null;
|
|
2384
|
-
switch (range.commonAncestorContainer.nodeType) {
|
|
2385
|
-
case Node.TEXT_NODE:
|
|
2386
|
-
// single-p selection, parent=p
|
|
2387
|
-
p = range.commonAncestorContainer.parentElement;
|
|
2388
|
-
if (forNew && (p.nodeName !== 'P' || !p.hasAttribute('id'))) {
|
|
2389
|
-
return null;
|
|
2390
|
-
}
|
|
2391
|
-
if (p.nodeName === 'SPAN') {
|
|
2392
|
-
p = p.parentElement;
|
|
2393
|
-
}
|
|
2394
|
-
var y = parseInt(p.getAttribute('id').substr(1), 10);
|
|
2395
|
-
// return [y, y];
|
|
2396
|
-
return { start: y, end: y };
|
|
2397
|
-
case Node.ELEMENT_NODE:
|
|
2398
|
-
// div only is allowed; in this case, it's a multi-p range
|
|
2399
|
-
if (range.commonAncestorContainer.nodeName !== 'DIV') {
|
|
2400
|
-
return null;
|
|
2401
|
-
}
|
|
2402
|
-
// for each div's child p element:
|
|
2403
|
-
var yMin = 0;
|
|
2404
|
-
var yMax = 0;
|
|
2405
|
-
var inside = false;
|
|
2406
|
-
for (var i = 0; i < range.commonAncestorContainer.childNodes.length; i++) {
|
|
2407
|
-
var child = range.commonAncestorContainer.childNodes[i];
|
|
2408
|
-
if (child.nodeType !== Node.ELEMENT_NODE || child.nodeName !== 'P') {
|
|
2409
|
-
continue;
|
|
2410
|
-
}
|
|
2411
|
-
// check if we're entering the start-p
|
|
2412
|
-
if (!inside && child.contains(range.startContainer)) {
|
|
2413
|
-
inside = true;
|
|
2414
|
-
}
|
|
2415
|
-
// collect y if inside
|
|
2416
|
-
if (inside) {
|
|
2417
|
-
var iy = parseInt(child.getAttribute('id').substr(1), 10);
|
|
2418
|
-
if (!yMin || iy < yMin) {
|
|
2419
|
-
yMin = iy;
|
|
2420
|
-
}
|
|
2421
|
-
if (!yMax || iy > yMax) {
|
|
2422
|
-
yMax = iy;
|
|
2423
|
-
}
|
|
2424
|
-
// check if we have exited the last p
|
|
2425
|
-
if (child.contains(range.endContainer)) {
|
|
2426
|
-
break;
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
return {
|
|
2431
|
-
start: yMin,
|
|
2432
|
-
end: yMax,
|
|
2433
|
-
};
|
|
2434
|
-
}
|
|
2435
|
-
};
|
|
2436
|
-
TextLayerService.prototype.locatePrevSpace = function (line, index) {
|
|
2437
|
-
while (index > -1 && line.charAt(index) !== ' ') {
|
|
2438
|
-
index--;
|
|
2439
|
-
}
|
|
2440
|
-
return index;
|
|
2441
|
-
};
|
|
2442
|
-
TextLayerService.prototype.locateNextSpace = function (line, index) {
|
|
2443
|
-
while (index < line.length && line.charAt(index) !== ' ') {
|
|
2444
|
-
index++;
|
|
2445
|
-
}
|
|
2446
|
-
return index === line.length ? -1 : index;
|
|
2447
|
-
};
|
|
2448
|
-
/**
|
|
2449
|
-
* Get the bounds of the token any character of which is indexed
|
|
2450
|
-
* by index.
|
|
2451
|
-
* @param line The text line.
|
|
2452
|
-
* @param index The index to the text line to start from.
|
|
2453
|
-
* @returns Bounds where start=index of the first character of the token,
|
|
2454
|
-
* and end=index of the character past the token's last character;
|
|
2455
|
-
* or null if index was not valid.
|
|
2456
|
-
*/
|
|
2457
|
-
TextLayerService.prototype.getTokenBounds = function (line, index) {
|
|
2458
|
-
if (line.charAt(index) === ' ') {
|
|
2459
|
-
return null;
|
|
2460
|
-
}
|
|
2461
|
-
var start = this.locatePrevSpace(line, index);
|
|
2462
|
-
if (start === -1) {
|
|
2463
|
-
start = 0;
|
|
2464
|
-
}
|
|
2465
|
-
else {
|
|
2466
|
-
start++;
|
|
2467
|
-
}
|
|
2468
|
-
var end = this.locateNextSpace(line, index);
|
|
2469
|
-
if (end === -1) {
|
|
2470
|
-
end = line.length;
|
|
2471
|
-
}
|
|
2472
|
-
// return [start, end];
|
|
2473
|
-
return {
|
|
2474
|
-
start: start,
|
|
2475
|
-
end: end,
|
|
2476
|
-
};
|
|
2477
|
-
};
|
|
2478
|
-
/**
|
|
2479
|
-
* Return the received selection bounds, adjusted to exclude spaces.
|
|
2480
|
-
*/
|
|
2481
|
-
TextLayerService.prototype.getAdjustedSelectionBounds = function (selStart, selEnd, line) {
|
|
2482
|
-
// corner case: if on space, move to right
|
|
2483
|
-
if (line.charAt(selStart) === ' ') {
|
|
2484
|
-
selStart++;
|
|
2485
|
-
}
|
|
2486
|
-
// corner case: if included trailing space, move to left
|
|
2487
|
-
if (selEnd > 0 && line.charAt(selEnd - 1) === ' ') {
|
|
2488
|
-
selEnd--;
|
|
2489
|
-
}
|
|
2490
|
-
// return [selStart, selEnd];
|
|
2491
|
-
return {
|
|
2492
|
-
start: selStart,
|
|
2493
|
-
end: selEnd,
|
|
2494
|
-
};
|
|
2495
|
-
};
|
|
2496
|
-
/**
|
|
2497
|
-
* Get the start coordinates for the selected range and line.
|
|
2498
|
-
* @param range The selected range.
|
|
2499
|
-
* @param line The reference text line.
|
|
2500
|
-
*/
|
|
2501
|
-
TextLayerService.prototype.getStartCoordsFromRange = function (selStart, selEnd, line) {
|
|
2502
|
-
// get adjusted selection bounds
|
|
2503
|
-
var selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);
|
|
2504
|
-
// get the bounds of the first selected token
|
|
2505
|
-
var tokBounds = this.getTokenBounds(line, selBounds.start);
|
|
2506
|
-
// calculate x by counting the tokens before the target token
|
|
2507
|
-
var x = 1;
|
|
2508
|
-
var j = tokBounds.start - 1;
|
|
2509
|
-
while (j > -1) {
|
|
2510
|
-
if (line.charAt(j) === ' ') {
|
|
2511
|
-
x++;
|
|
2512
|
-
}
|
|
2513
|
-
j--;
|
|
2514
|
-
}
|
|
2515
|
-
// calculate at,run only when either of these is true:
|
|
2516
|
-
// (a) selection starts past the 1st char of the token (al[pha);
|
|
2517
|
-
// (b) selection ends before the last char of the token (al]pha);
|
|
2518
|
-
// run is calculated only if (b) is true.
|
|
2519
|
-
var at = 0;
|
|
2520
|
-
var run = 0;
|
|
2521
|
-
if (selBounds.start > tokBounds.start || selBounds.end < tokBounds.end) {
|
|
2522
|
-
at = 1 + selBounds.start - tokBounds.start;
|
|
2523
|
-
run =
|
|
2524
|
-
(selBounds.end < tokBounds.end
|
|
2525
|
-
? selBounds.end // al]pha
|
|
2526
|
-
: tokBounds.end) - // alpha]
|
|
2527
|
-
Math.max(tokBounds.start, selBounds.start);
|
|
2528
|
-
}
|
|
2529
|
-
return {
|
|
2530
|
-
y: 0,
|
|
2531
|
-
x: x,
|
|
2532
|
-
at: at,
|
|
2533
|
-
run: run,
|
|
2534
|
-
};
|
|
2535
|
-
};
|
|
2536
|
-
TextLayerService.prototype.getEndCoordsFromRange = function (selStart, selEnd, line) {
|
|
2537
|
-
// get adjusted selection bounds
|
|
2538
|
-
var selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);
|
|
2539
|
-
// get the bounds of the last selected token
|
|
2540
|
-
var tokBounds = this.getTokenBounds(line, selBounds.end - 1);
|
|
2541
|
-
// calculate x by counting the tokens before the target token
|
|
2542
|
-
var x = 1;
|
|
2543
|
-
var j = selBounds.end - 1;
|
|
2544
|
-
while (j > -1) {
|
|
2545
|
-
if (line.charAt(j) === ' ') {
|
|
2546
|
-
x++;
|
|
2547
|
-
}
|
|
2548
|
-
j--;
|
|
2549
|
-
}
|
|
2550
|
-
// calculate at,run only when selection ends before the 1st char of the token
|
|
2551
|
-
// (al]pha); run is calculated only if at is calculated.
|
|
2552
|
-
var at = 0;
|
|
2553
|
-
var run = 0;
|
|
2554
|
-
if (selBounds.end < tokBounds.end) {
|
|
2555
|
-
at =
|
|
2556
|
-
selBounds.start > tokBounds.start
|
|
2557
|
-
? 1 + selBounds.start - tokBounds.start
|
|
2558
|
-
: 1;
|
|
2559
|
-
run = selBounds.end - tokBounds.start;
|
|
2560
|
-
}
|
|
2561
|
-
return {
|
|
2562
|
-
y: 0,
|
|
2563
|
-
x: x,
|
|
2564
|
-
at: at,
|
|
2565
|
-
run: run,
|
|
2566
|
-
};
|
|
2567
|
-
};
|
|
2568
|
-
TextLayerService.prototype.getSpanLocFromId = function (id) {
|
|
2569
|
-
if (!id) {
|
|
2570
|
-
return null;
|
|
2571
|
-
}
|
|
2572
|
-
var r = new RegExp('^f([-\\d+.@x]+)', 'g');
|
|
2573
|
-
var m = r.exec(id);
|
|
2574
|
-
if (!m) {
|
|
2575
|
-
return null;
|
|
2576
|
-
}
|
|
2577
|
-
return TokenLocation.parse(m[1]);
|
|
2578
|
-
};
|
|
2579
|
-
TextLayerService.prototype.visitNodes = function (node, visitor) {
|
|
2580
|
-
if (!visitor(node)) {
|
|
2581
|
-
return;
|
|
2582
|
-
}
|
|
2583
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
2584
|
-
for (var i = 0; i < node.childNodes.length; i++) {
|
|
2585
|
-
var child = node.childNodes[i];
|
|
2586
|
-
this.visitNodes(child, visitor);
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
};
|
|
2590
|
-
TextLayerService.prototype.findFirstDescendantSpan = function (range) {
|
|
2591
|
-
var inside = false;
|
|
2592
|
-
var span = null;
|
|
2593
|
-
this.visitNodes(range.commonAncestorContainer, function (current) {
|
|
2594
|
-
if (current === range.startContainer) {
|
|
2595
|
-
inside = true;
|
|
2596
|
-
}
|
|
2597
|
-
if (current.nodeType === Node.ELEMENT_NODE &&
|
|
2598
|
-
current.nodeName === 'SPAN') {
|
|
2599
|
-
span = current;
|
|
2600
|
-
return false;
|
|
2601
|
-
}
|
|
2602
|
-
if (current === range.endContainer) {
|
|
2603
|
-
inside = false;
|
|
2604
|
-
}
|
|
2605
|
-
return true;
|
|
2606
|
-
});
|
|
2607
|
-
return span;
|
|
2608
|
-
};
|
|
2609
|
-
/**
|
|
2610
|
-
* Get the base offset for the specified node. This is used
|
|
2611
|
-
* when the start container of the selected range has any
|
|
2612
|
-
* preceding sibling node, which happens only when you have
|
|
2613
|
-
* any spans in the p element (=the line). In this case,
|
|
2614
|
-
* the selection offset starts from the start container node,
|
|
2615
|
-
* which is preceded by other nodes including other text.
|
|
2616
|
-
* As we must get the line-based offset, we have to start
|
|
2617
|
-
* from a base offset equal to the sum of the lengths of
|
|
2618
|
-
* all the preceding siblings.
|
|
2619
|
-
*/
|
|
2620
|
-
TextLayerService.prototype.getNodeBaseOffset = function (node) {
|
|
2621
|
-
var _a, _b;
|
|
2622
|
-
var offset = 0;
|
|
2623
|
-
node = node.previousSibling;
|
|
2624
|
-
while (node) {
|
|
2625
|
-
offset +=
|
|
2626
|
-
node.nodeType === Node.ELEMENT_NODE
|
|
2627
|
-
? ((_a = node.innerText) === null || _a === void 0 ? void 0 : _a.length) || 0
|
|
2628
|
-
: ((_b = node.textContent) === null || _b === void 0 ? void 0 : _b.length) || 0;
|
|
2629
|
-
node = node.previousSibling;
|
|
2630
|
-
}
|
|
2631
|
-
return offset;
|
|
2632
|
-
};
|
|
2633
|
-
/**
|
|
2634
|
-
* Get the location corresponding to the user selection,
|
|
2635
|
-
* for editing the first fragment included in it.
|
|
2636
|
-
* @param range The selected range. You can get it from the
|
|
2637
|
-
* current selection using getSelectedRange().
|
|
2638
|
-
* @returns The token location or null.
|
|
2639
|
-
*/
|
|
2640
|
-
TextLayerService.prototype.getSelectedLocationForEdit = function (range) {
|
|
2641
|
-
if (!range) {
|
|
2642
|
-
return null;
|
|
2643
|
-
}
|
|
2644
|
-
// just find the first descendant span in selection
|
|
2645
|
-
var span = null;
|
|
2646
|
-
switch (range.commonAncestorContainer.nodeType) {
|
|
2647
|
-
case Node.ELEMENT_NODE:
|
|
2648
|
-
span = range.commonAncestorContainer;
|
|
2649
|
-
if (span.nodeName !== 'SPAN') {
|
|
2650
|
-
span = this.findFirstDescendantSpan(range);
|
|
2651
|
-
}
|
|
2652
|
-
break;
|
|
2653
|
-
case Node.TEXT_NODE:
|
|
2654
|
-
span = range.commonAncestorContainer.parentElement;
|
|
2655
|
-
if (span &&
|
|
2656
|
-
(span.nodeType !== Node.ELEMENT_NODE || span.nodeName !== 'SPAN')) {
|
|
2657
|
-
span = null;
|
|
2658
|
-
}
|
|
2659
|
-
break;
|
|
2660
|
-
}
|
|
2661
|
-
return span ? this.getSpanLocFromId(span.getAttribute('id')) : null;
|
|
2662
|
-
};
|
|
2663
|
-
TextLayerService.prototype.textLineToString = function (line) {
|
|
2664
|
-
if (!line || !line.tokens) {
|
|
2665
|
-
return '';
|
|
2666
|
-
}
|
|
2667
|
-
return line.tokens.join(' ');
|
|
2668
|
-
};
|
|
2669
|
-
TextLayerService.prototype.buildCoords = function (start, end, singleToken) {
|
|
2670
|
-
var sb = [];
|
|
2671
|
-
// start: y.x
|
|
2672
|
-
sb.push(start.y + "." + start.x);
|
|
2673
|
-
if (singleToken) {
|
|
2674
|
-
// single token: check for at,run
|
|
2675
|
-
if (start.at) {
|
|
2676
|
-
sb.push("@" + start.at);
|
|
2677
|
-
if (start.run > 1) {
|
|
2678
|
-
sb.push("x" + start.run);
|
|
2679
|
-
}
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
else {
|
|
2683
|
-
// not a single token
|
|
2684
|
-
// first token
|
|
2685
|
-
if (start.at) {
|
|
2686
|
-
sb.push("@" + start.at + "x" + start.run);
|
|
2687
|
-
}
|
|
2688
|
-
// last token
|
|
2689
|
-
sb.push("-" + end.y + "." + end.x);
|
|
2690
|
-
if (end.at) {
|
|
2691
|
-
sb.push("@1x" + end.run);
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
return sb.join('');
|
|
2695
|
-
};
|
|
2696
|
-
/**
|
|
2697
|
-
* Recursively find the node matching the specified matcher
|
|
2698
|
-
* function, starting from the specified node (included).
|
|
2699
|
-
*
|
|
2700
|
-
* @param node The node to start from.
|
|
2701
|
-
* @param matcher The matcher function, which receives a node
|
|
2702
|
-
* to match, and returns 1=match, 0=no match, -1=stop the
|
|
2703
|
-
* find operation with a no match.
|
|
2704
|
-
*/
|
|
2705
|
-
TextLayerService.prototype.findNode = function (node, matcher) {
|
|
2706
|
-
// self
|
|
2707
|
-
var n = matcher(node);
|
|
2708
|
-
if (n === 1) {
|
|
2709
|
-
return node;
|
|
2710
|
-
}
|
|
2711
|
-
if (n === -1) {
|
|
2712
|
-
return null;
|
|
2713
|
-
}
|
|
2714
|
-
// children
|
|
2715
|
-
if (node.hasChildNodes()) {
|
|
2716
|
-
for (var i = 0; i < node.childNodes.length; i++) {
|
|
2717
|
-
var child = node.childNodes[i];
|
|
2718
|
-
var found = this.findNode(child, matcher);
|
|
2719
|
-
if (found) {
|
|
2720
|
-
return found;
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
return null;
|
|
2725
|
-
};
|
|
2726
|
-
TextLayerService.prototype.selHasAnySpan = function (range) {
|
|
2727
|
-
var inside = false;
|
|
2728
|
-
if (
|
|
2729
|
-
// the selected text node must not be child of a span
|
|
2730
|
-
range.startContainer.parentElement.tagName === 'SPAN' ||
|
|
2731
|
-
range.startContainer.parentElement.tagName === 'SPAN' ||
|
|
2732
|
-
// the nodes tree from the common ancestor, from the start node
|
|
2733
|
-
// up to the end node, must not include any span
|
|
2734
|
-
this.findNode(range.commonAncestorContainer, function (node) {
|
|
2735
|
-
// start checking only when start node reached
|
|
2736
|
-
if (node === range.startContainer) {
|
|
2737
|
-
inside = true;
|
|
2738
|
-
}
|
|
2739
|
-
if (!inside) {
|
|
2740
|
-
return 0;
|
|
2741
|
-
}
|
|
2742
|
-
// stop checking when end node reached
|
|
2743
|
-
if (node === range.endContainer) {
|
|
2744
|
-
return -1;
|
|
2745
|
-
}
|
|
2746
|
-
// node cannot be a span
|
|
2747
|
-
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
2748
|
-
node.tagName === 'SPAN') {
|
|
2749
|
-
return 1;
|
|
2750
|
-
}
|
|
2751
|
-
return 0;
|
|
2752
|
-
})) {
|
|
2753
|
-
return true;
|
|
2754
|
-
}
|
|
2755
|
-
return false;
|
|
2756
|
-
};
|
|
2757
|
-
/**
|
|
2758
|
-
* Get the location corresponding to the user selection,
|
|
2759
|
-
* for adding a new fragment with the same extension.
|
|
2760
|
-
* @param range The selected range. You can get it from the
|
|
2761
|
-
* current selection using getSelectedRange().
|
|
2762
|
-
* @param text The full base text.
|
|
2763
|
-
* @returns TokenLocation The token location or null.
|
|
2764
|
-
*/
|
|
2765
|
-
TextLayerService.prototype.getSelectedLocationForNew = function (range, text) {
|
|
2766
|
-
if (!range || this.selHasAnySpan(range)) {
|
|
2767
|
-
return null;
|
|
2768
|
-
}
|
|
2769
|
-
// get y bounds (min, max; equal if single-line)
|
|
2770
|
-
var yBounds = this.getYBoundsFromRange(range, true);
|
|
2771
|
-
if (!yBounds) {
|
|
2772
|
-
return null;
|
|
2773
|
-
}
|
|
2774
|
-
// get lines and calculate start/end coords
|
|
2775
|
-
var lines = this.getLines(text);
|
|
2776
|
-
var startLine = this.textLineToString(lines[yBounds.start - 1]);
|
|
2777
|
-
var endLine = this.textLineToString(lines[yBounds.end - 1]);
|
|
2778
|
-
// get the base offsets
|
|
2779
|
-
var startBaseOffset = this.getNodeBaseOffset(range.startContainer);
|
|
2780
|
-
var endBaseOffset = this.getNodeBaseOffset(range.endContainer);
|
|
2781
|
-
// get the start (including the base offset)
|
|
2782
|
-
var startLineEndOffset = yBounds.start !== yBounds.end
|
|
2783
|
-
? startLine.length
|
|
2784
|
-
: range.endOffset + startBaseOffset;
|
|
2785
|
-
var start = this.getStartCoordsFromRange(range.startOffset + startBaseOffset, startLineEndOffset, startLine);
|
|
2786
|
-
start.y = yBounds.start;
|
|
2787
|
-
// get the end (including the base offset)
|
|
2788
|
-
var end = yBounds.start !== yBounds.end
|
|
2789
|
-
? this.getEndCoordsFromRange(0, range.endOffset + endBaseOffset, endLine)
|
|
2790
|
-
: this.getEndCoordsFromRange(range.startOffset + endBaseOffset, range.endOffset + endBaseOffset, endLine);
|
|
2791
|
-
end.y = yBounds.end;
|
|
2792
|
-
var singleLine = start.y === end.y;
|
|
2793
|
-
var singleToken = singleLine && start.x === end.x;
|
|
2794
|
-
var coords = this.buildCoords(start, end, singleToken);
|
|
2795
|
-
return TokenLocation.parse(coords);
|
|
2796
|
-
};
|
|
2797
|
-
/**
|
|
2798
|
-
* Get the currently selected range in the browser's document.
|
|
2799
|
-
* This uses the rangy library.
|
|
2800
|
-
*/
|
|
2801
|
-
TextLayerService.prototype.getSelectedRange = function () {
|
|
2802
|
-
var sel = rangy__namespace.getSelection();
|
|
2803
|
-
if (sel.isCollapsed) {
|
|
2804
|
-
return null;
|
|
2805
|
-
}
|
|
2806
|
-
return sel.getRangeAt(0);
|
|
2807
|
-
};
|
|
2808
|
-
return TextLayerService;
|
|
2809
|
-
}());
|
|
2810
|
-
TextLayerService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function TextLayerService_Factory() { return new TextLayerService(); }, token: TextLayerService, providedIn: "root" });
|
|
2811
|
-
TextLayerService.decorators = [
|
|
2812
|
-
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
|
2813
|
-
];
|
|
2814
|
-
TextLayerService.ctorParameters = function () { return []; };
|
|
2815
|
-
|
|
2816
|
-
// https://github.com/angular/angular/blob/3b7d4ebbd6445364889d61b7b1b1c65206534d34/packages/forms/src/validators.ts
|
|
2817
|
-
// https://indepth.dev/posts/1319/the-best-way-to-implement-custom-validators
|
|
2818
|
-
/**
|
|
2819
|
-
* Cadmus general-purpose custom validators.
|
|
2820
|
-
*/
|
|
2821
|
-
// @dynamic
|
|
2822
|
-
var CadmusValidators = /** @class */ (function () {
|
|
2823
|
-
function CadmusValidators() {
|
|
2824
|
-
}
|
|
2825
|
-
CadmusValidators.hasValidLength = function (value) {
|
|
2826
|
-
// non-strict comparison is intentional,
|
|
2827
|
-
// to check for both `null` and `undefined` values
|
|
2828
|
-
return value != null && typeof value.length === 'number';
|
|
2829
|
-
};
|
|
2830
|
-
/**
|
|
2831
|
-
* Validate an array or string for a minimum required length.
|
|
2832
|
-
* Differently from the standard minLength validator, this does
|
|
2833
|
-
* not exclude 0 from the values to be checked. The standard
|
|
2834
|
-
* validator instead does not validate the value if this is 0.
|
|
2835
|
-
*
|
|
2836
|
-
* @param minLength Minimum length required.
|
|
2837
|
-
* @returns Null if valid, else an object with minlength with
|
|
2838
|
-
* requiredLength and actualLength.
|
|
2839
|
-
*/
|
|
2840
|
-
CadmusValidators.strictMinLengthValidator = function (minLength) {
|
|
2841
|
-
var _this = this;
|
|
2842
|
-
return function (control) {
|
|
2843
|
-
// don't validate values without `length` property
|
|
2844
|
-
if (!_this.hasValidLength(control.value)) {
|
|
2845
|
-
return null;
|
|
2846
|
-
}
|
|
2847
|
-
return control.value.length < minLength
|
|
2848
|
-
? {
|
|
2849
|
-
minlength: {
|
|
2850
|
-
requiredLength: minLength,
|
|
2851
|
-
actualLength: control.value.length,
|
|
2852
|
-
},
|
|
2853
|
-
}
|
|
2854
|
-
: null;
|
|
2855
|
-
};
|
|
2856
|
-
};
|
|
2857
|
-
return CadmusValidators;
|
|
2858
|
-
}());
|
|
2859
|
-
|
|
2860
|
-
var PasswordValidator = /** @class */ (function () {
|
|
2861
|
-
function PasswordValidator() {
|
|
2862
|
-
}
|
|
2863
|
-
PasswordValidator.isValidPassword = function (control) {
|
|
2864
|
-
if (!control.value) {
|
|
2865
|
-
return null;
|
|
2866
|
-
}
|
|
2867
|
-
if (control.value.length < 8) {
|
|
2868
|
-
return {
|
|
2869
|
-
passwordTooShort: true
|
|
2870
|
-
};
|
|
2871
|
-
}
|
|
2872
|
-
if (!/.*[A-Z].*/.test(control.value)) {
|
|
2873
|
-
return {
|
|
2874
|
-
noUpperInPassword: true
|
|
2875
|
-
};
|
|
2876
|
-
}
|
|
2877
|
-
if (!/.*[a-z].*/.test(control.value)) {
|
|
2878
|
-
return {
|
|
2879
|
-
noLowerInPassword: true
|
|
2880
|
-
};
|
|
2881
|
-
}
|
|
2882
|
-
if (!/.*[A-Z].*/.test(control.value)) {
|
|
2883
|
-
return {
|
|
2884
|
-
noUpperInPassword: true
|
|
2885
|
-
};
|
|
2886
|
-
}
|
|
2887
|
-
if (!/.*[-`~!@#$%^&*()_+=\[\]{};:'",.<>/?|\\].*/.test(control.value)) {
|
|
2888
|
-
return {
|
|
2889
|
-
noSymbolInPassword: true
|
|
2890
|
-
};
|
|
2891
|
-
}
|
|
2892
|
-
return null;
|
|
2893
|
-
};
|
|
2894
|
-
return PasswordValidator;
|
|
2895
|
-
}());
|
|
2896
|
-
|
|
2897
|
-
var CadmusCoreModule = /** @class */ (function () {
|
|
2898
|
-
function CadmusCoreModule() {
|
|
2899
|
-
}
|
|
2900
|
-
return CadmusCoreModule;
|
|
2901
|
-
}());
|
|
2902
|
-
CadmusCoreModule.decorators = [
|
|
2903
|
-
{ type: i0.NgModule, args: [{
|
|
2904
|
-
imports: [common.CommonModule, http.HttpClientModule],
|
|
2905
|
-
declarations: [SortPipe],
|
|
2906
|
-
exports: [SortPipe]
|
|
2907
|
-
},] }
|
|
2908
|
-
];
|
|
2909
|
-
|
|
2910
|
-
/*
|
|
2911
|
-
* Public API Surface of cadmus-core
|
|
2912
|
-
*/
|
|
2913
|
-
|
|
2914
|
-
/**
|
|
2915
|
-
* Generated bundle index. Do not edit.
|
|
2916
|
-
*/
|
|
2917
|
-
|
|
2918
|
-
exports.CadmusCoreModule = CadmusCoreModule;
|
|
2919
|
-
exports.CadmusValidators = CadmusValidators;
|
|
2920
|
-
exports.DATATION_FORMAT_OPTIONS = DATATION_FORMAT_OPTIONS;
|
|
2921
|
-
exports.Datation = Datation;
|
|
2922
|
-
exports.EnvService = EnvService;
|
|
2923
|
-
exports.EnvServiceFactory = EnvServiceFactory;
|
|
2924
|
-
exports.EnvServiceProvider = EnvServiceProvider;
|
|
2925
|
-
exports.ErrorService = ErrorService;
|
|
2926
|
-
exports.GravatarService = GravatarService;
|
|
2927
|
-
exports.HistoricalDate = HistoricalDate;
|
|
2928
|
-
exports.LibraryRouteService = LibraryRouteService;
|
|
2929
|
-
exports.LocalStorageService = LocalStorageService;
|
|
2930
|
-
exports.PasswordValidator = PasswordValidator;
|
|
2931
|
-
exports.PendingChangesGuard = PendingChangesGuard;
|
|
2932
|
-
exports.RomanNumber = RomanNumber;
|
|
2933
|
-
exports.SortPipe = SortPipe;
|
|
2934
|
-
exports.TextLayerService = TextLayerService;
|
|
2935
|
-
exports.TextRange = TextRange;
|
|
2936
|
-
exports.TokenLocation = TokenLocation;
|
|
2937
|
-
exports.TokenPoint = TokenPoint;
|
|
2938
|
-
exports.deepCopy = deepCopy;
|
|
2939
|
-
|
|
2940
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2941
|
-
|
|
2942
|
-
})));
|
|
2943
|
-
//# sourceMappingURL=myrmidon-cadmus-core.umd.js.map
|