@myrmidon/cadmus-core 0.1.0 → 1.0.1
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 +2 -2
- package/esm2020/lib/cadmus-core.module.mjs +8 -7
- package/esm2020/lib/guards/pending-changes.guard.mjs +5 -5
- package/esm2020/lib/models.mjs +1 -1
- package/esm2020/lib/pipes/sort.pipe.mjs +5 -4
- package/esm2020/lib/services/library-route.service.mjs +20 -19
- package/esm2020/lib/services/text-layer.service.mjs +30 -28
- package/esm2020/lib/text-range.mjs +1 -1
- package/esm2020/lib/token-location.mjs +3 -3
- package/esm2020/lib/token-point.mjs +2 -2
- package/esm2020/public-api.mjs +1 -12
- package/fesm2015/myrmidon-cadmus-core.mjs +68 -1371
- package/fesm2015/myrmidon-cadmus-core.mjs.map +1 -1
- package/fesm2020/myrmidon-cadmus-core.mjs +67 -1371
- package/fesm2020/myrmidon-cadmus-core.mjs.map +1 -1
- package/lib/cadmus-core.module.d.ts +2 -1
- package/lib/models.d.ts +1 -94
- package/lib/services/library-route.service.d.ts +7 -7
- package/lib/services/text-layer.service.d.ts +6 -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/package.json +5 -5
- package/public-api.d.ts +0 -10
- package/esm2020/lib/datation.mjs +0 -520
- package/esm2020/lib/historical-date.mjs +0 -297
- package/esm2020/lib/roman-number.mjs +0 -155
- package/esm2020/lib/services/env.service.mjs +0 -77
- package/esm2020/lib/services/env.service.provider.mjs +0 -31
- package/esm2020/lib/services/error.service.mjs +0 -40
- package/esm2020/lib/services/gravatar.service.mjs +0 -30
- package/esm2020/lib/services/local-storage.service.mjs +0 -101
- package/esm2020/lib/utils.mjs +0 -36
- package/esm2020/lib/validators/password.validator.mjs +0 -34
- package/lib/datation.d.ts +0 -157
- package/lib/historical-date.d.ts +0 -84
- package/lib/roman-number.d.ts +0 -34
- package/lib/services/env.service.d.ts +0 -55
- package/lib/services/env.service.provider.d.ts +0 -15
- package/lib/services/error.service.d.ts +0 -16
- package/lib/services/gravatar.service.d.ts +0 -12
- package/lib/services/local-storage.service.d.ts +0 -35
- package/lib/utils.d.ts +0 -4
- package/lib/validators/password.validator.d.ts +0 -6
|
@@ -1,980 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable, Pipe, Inject, NgModule } from '@angular/core';
|
|
3
|
-
import { throwError } from 'rxjs';
|
|
4
|
-
import * as gravatar from 'gravatar';
|
|
5
3
|
import * as rangy from 'rangy';
|
|
6
4
|
import { CommonModule } from '@angular/common';
|
|
7
5
|
import { HttpClientModule } from '@angular/common/http';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Roman number converter.
|
|
11
|
-
*/
|
|
12
|
-
class RomanNumber {
|
|
13
|
-
/**
|
|
14
|
-
* Convert the specified numeric value to a Roman number.
|
|
15
|
-
*
|
|
16
|
-
* @param value The value.
|
|
17
|
-
* @param allowBar True to allow bar on letters. A bar on a letter
|
|
18
|
-
* multiplies its value by 1000.
|
|
19
|
-
* @param allowPrefix True to allow prefix notation.
|
|
20
|
-
* @param ancient True to use the ancient preferred notation, i.e.
|
|
21
|
-
* the preferred epigraphical notation (IIII instead of IV, VIIII instead of IX).
|
|
22
|
-
*/
|
|
23
|
-
static toRoman(value, allowBar = true, allowPrefix = true, ancient = false) {
|
|
24
|
-
if (value <= 0) {
|
|
25
|
-
return '';
|
|
26
|
-
}
|
|
27
|
-
let place = allowBar ? 0 : 6;
|
|
28
|
-
const sb = [];
|
|
29
|
-
while (value > 0) {
|
|
30
|
-
while (value >= this._postVal[place]) {
|
|
31
|
-
sb.push(this._postAlpha[place]);
|
|
32
|
-
value -= this._postVal[place];
|
|
33
|
-
}
|
|
34
|
-
if (allowPrefix) {
|
|
35
|
-
if (value >= this._preVal[place]) {
|
|
36
|
-
sb.push(this._preAlpha[place]);
|
|
37
|
-
value -= this._preVal[place];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
place++;
|
|
41
|
-
}
|
|
42
|
-
if (ancient) {
|
|
43
|
-
let s = sb.join('');
|
|
44
|
-
s = s.replace('IV', 'IIII');
|
|
45
|
-
return s.replace('IX', 'VIII');
|
|
46
|
-
}
|
|
47
|
-
return sb.join('');
|
|
48
|
-
}
|
|
49
|
-
static isLower(c) {
|
|
50
|
-
return c.toLowerCase() === c;
|
|
51
|
-
}
|
|
52
|
-
static isUpper(c) {
|
|
53
|
-
return c.toUpperCase() === c;
|
|
54
|
-
}
|
|
55
|
-
static isCaseEqual(c1, c2) {
|
|
56
|
-
return ((this.isLower(c1) && this.isLower(c2)) ||
|
|
57
|
-
(this.isUpper(c1) && this.isUpper(c2)));
|
|
58
|
-
}
|
|
59
|
-
static getRomanDigitValue(digit) {
|
|
60
|
-
const i = this._romanDigits.indexOf(digit.toUpperCase());
|
|
61
|
-
if (i === -1) {
|
|
62
|
-
return 0;
|
|
63
|
-
}
|
|
64
|
-
return this.isLower(digit)
|
|
65
|
-
? this._romanValues[i] * 1000
|
|
66
|
-
: this._romanValues[i];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Convert the specified Roman number to a numeric value.
|
|
70
|
-
*
|
|
71
|
-
* @param roman: The Roman number.
|
|
72
|
-
* @param allowBar: True to allow bar-on-letter notation.
|
|
73
|
-
*/
|
|
74
|
-
static fromRoman(roman, allowBar = true) {
|
|
75
|
-
if (!roman) {
|
|
76
|
-
return 0;
|
|
77
|
-
}
|
|
78
|
-
let result = 0;
|
|
79
|
-
if (!allowBar) {
|
|
80
|
-
roman = roman.toUpperCase();
|
|
81
|
-
}
|
|
82
|
-
for (let index = 0; index < roman.length; index++) {
|
|
83
|
-
// if the previous value was a sub-digit, it had to be subtracted instead
|
|
84
|
-
// of added; thus, subtract it twice (once to compensate for the wrong addition,
|
|
85
|
-
// and once to subtract from this value) from the current digit value
|
|
86
|
-
result += this.getRomanDigitValue(roman[index]);
|
|
87
|
-
if (index > 0) {
|
|
88
|
-
const i = this._romanDigits.indexOf(roman[index]);
|
|
89
|
-
if (roman[index - 1].toUpperCase() ===
|
|
90
|
-
this._romanSubdigits[i].toUpperCase() &&
|
|
91
|
-
this.isCaseEqual(roman[index - 1], roman[index])) {
|
|
92
|
-
// tslint:disable-next-line:no-bitwise
|
|
93
|
-
result -= this.getRomanDigitValue(this._romanSubdigits[i]) << 1;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
RomanNumber._postVal = [
|
|
101
|
-
1000000,
|
|
102
|
-
500000,
|
|
103
|
-
100000,
|
|
104
|
-
50000,
|
|
105
|
-
10000,
|
|
106
|
-
5000,
|
|
107
|
-
1000,
|
|
108
|
-
500,
|
|
109
|
-
100,
|
|
110
|
-
50,
|
|
111
|
-
10,
|
|
112
|
-
5,
|
|
113
|
-
1,
|
|
114
|
-
];
|
|
115
|
-
RomanNumber._postAlpha = [
|
|
116
|
-
'm',
|
|
117
|
-
'd',
|
|
118
|
-
'c',
|
|
119
|
-
'l',
|
|
120
|
-
'x',
|
|
121
|
-
'v',
|
|
122
|
-
'M',
|
|
123
|
-
'D',
|
|
124
|
-
'C',
|
|
125
|
-
'L',
|
|
126
|
-
'X',
|
|
127
|
-
'V',
|
|
128
|
-
'I',
|
|
129
|
-
];
|
|
130
|
-
RomanNumber._preVal = [
|
|
131
|
-
900000,
|
|
132
|
-
400000,
|
|
133
|
-
90000,
|
|
134
|
-
40000,
|
|
135
|
-
9000,
|
|
136
|
-
4000,
|
|
137
|
-
900,
|
|
138
|
-
400,
|
|
139
|
-
90,
|
|
140
|
-
40,
|
|
141
|
-
9,
|
|
142
|
-
4,
|
|
143
|
-
1,
|
|
144
|
-
];
|
|
145
|
-
RomanNumber._preAlpha = [
|
|
146
|
-
'cm',
|
|
147
|
-
'cd',
|
|
148
|
-
'xc',
|
|
149
|
-
'xl',
|
|
150
|
-
'ix',
|
|
151
|
-
'iv',
|
|
152
|
-
'CM',
|
|
153
|
-
'CD',
|
|
154
|
-
'XC',
|
|
155
|
-
'XL',
|
|
156
|
-
'IX',
|
|
157
|
-
'IV',
|
|
158
|
-
'I',
|
|
159
|
-
];
|
|
160
|
-
RomanNumber._romanDigits = 'IVXLCDM';
|
|
161
|
-
RomanNumber._romanSubdigits = ' IIXXCC';
|
|
162
|
-
RomanNumber._romanValues = [1, 5, 10, 50, 100, 500, 1000];
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Default options for formatting a datation.
|
|
166
|
-
*/
|
|
167
|
-
const DATATION_FORMAT_OPTIONS = {
|
|
168
|
-
aboutText: 'c.',
|
|
169
|
-
bcText: 'BC',
|
|
170
|
-
adText: 'AD',
|
|
171
|
-
dayNames: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
|
|
172
|
-
monthNames: [
|
|
173
|
-
'jan',
|
|
174
|
-
'feb',
|
|
175
|
-
'mar',
|
|
176
|
-
'apr',
|
|
177
|
-
'may',
|
|
178
|
-
'jun',
|
|
179
|
-
'jul',
|
|
180
|
-
'aug',
|
|
181
|
-
'sep',
|
|
182
|
-
'oct',
|
|
183
|
-
'nov',
|
|
184
|
-
'dec',
|
|
185
|
-
],
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Single datation point in a historical date.
|
|
189
|
-
*/
|
|
190
|
-
// https://github.com/angular/angular/issues/18867#issuecomment-357484102
|
|
191
|
-
// @dynamic
|
|
192
|
-
class Datation {
|
|
193
|
-
/**
|
|
194
|
-
* Create a new datation, optionally setting its data.
|
|
195
|
-
* @param datation The optional data to be copied into the newly created datation.
|
|
196
|
-
*/
|
|
197
|
-
constructor(datation = null) {
|
|
198
|
-
if (datation) {
|
|
199
|
-
this.copyFrom(datation);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Sanitize the hint text representing a Datation's hint so that it does not
|
|
204
|
-
* include the reserved sequence -- (which gets replaced with Unicode EM
|
|
205
|
-
* space U+2014), nor the braces. This is because the double dashes are used
|
|
206
|
-
* to separate two datations, and braces to mark a hint in a datation.
|
|
207
|
-
* Also, the whitespaces are all flattened to simple spaces, and normalized
|
|
208
|
-
* (no whitespaces at start/end and no sequence of whitespaces).
|
|
209
|
-
* If the resulting sanitized string is empty, or it was null when received,
|
|
210
|
-
* null is returned.
|
|
211
|
-
* @param hint The hint or null/undefined.
|
|
212
|
-
* @returns The sanitized hint or undefined.
|
|
213
|
-
*/
|
|
214
|
-
static sanitizeHint(hint) {
|
|
215
|
-
if (!hint || !hint.trim()) {
|
|
216
|
-
return undefined;
|
|
217
|
-
}
|
|
218
|
-
// replace reserved characters
|
|
219
|
-
hint = hint.replace('--', '\u2014');
|
|
220
|
-
hint = hint.replace('{', '');
|
|
221
|
-
hint = hint.replace('}', '');
|
|
222
|
-
// flatten and normalize whitespaces
|
|
223
|
-
const s = hint.replace(/\s+/g, ' ').trim();
|
|
224
|
-
return s ? s : undefined;
|
|
225
|
-
}
|
|
226
|
-
static regexEscape(text) {
|
|
227
|
-
// https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
|
|
228
|
-
return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Get BC and AD patterns for matching.
|
|
232
|
-
* @param options The datation format options.
|
|
233
|
-
*/
|
|
234
|
-
static getErasOptionsForRegex(options = DATATION_FORMAT_OPTIONS) {
|
|
235
|
-
return [
|
|
236
|
-
options.bcText ? this.regexEscape(options.bcText) : 'BC',
|
|
237
|
-
options.adText ? this.regexEscape(options.adText) : 'AD',
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
static getParserRegex(options) {
|
|
241
|
-
const bcad = this.getErasOptionsForRegex(options);
|
|
242
|
-
return new RegExp(
|
|
243
|
-
// about (1)
|
|
244
|
-
'(c\\.)?\\s*' +
|
|
245
|
-
// day (2)
|
|
246
|
-
'(?:([0123]?\\d)\\s+)?' +
|
|
247
|
-
// month (3)
|
|
248
|
-
'(?:([a-zA-Z]{3,})\\s+)?' +
|
|
249
|
-
// year/span (4,5)
|
|
250
|
-
'(?:' +
|
|
251
|
-
'(?:(\\d+)(?:\\s*/\\s*(\\d+))?)|' +
|
|
252
|
-
// century (6)
|
|
253
|
-
'([ivxIVX]+)' +
|
|
254
|
-
')\\s*' +
|
|
255
|
-
// era (7)
|
|
256
|
-
'(' +
|
|
257
|
-
bcad[0] +
|
|
258
|
-
'|' +
|
|
259
|
-
bcad[1] +
|
|
260
|
-
')?' +
|
|
261
|
-
// perhaps (8)
|
|
262
|
-
'(\\s*\\?)?' +
|
|
263
|
-
// hint (9)
|
|
264
|
-
'(?:\\s*\\{([^}]+)\\})?', 'i');
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Parse the specified text representing a datation.
|
|
268
|
-
* @param text The text to be parsed.
|
|
269
|
-
* @param options The formatter options.
|
|
270
|
-
* @returns The parsed datation, or undefined if invalid or empty.
|
|
271
|
-
* Note that here we return undefined to mean a non-existing point.
|
|
272
|
-
* We do not want a non-existing point to be represented as a null,
|
|
273
|
-
* as this would be included as in the JSON code when serializing.
|
|
274
|
-
*/
|
|
275
|
-
static parse(text, options = DATATION_FORMAT_OPTIONS) {
|
|
276
|
-
if (!text) {
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
|
-
const datation = new Datation();
|
|
280
|
-
const datationRegex = this.getParserRegex(options);
|
|
281
|
-
const m = datationRegex.exec(text);
|
|
282
|
-
if (!m) {
|
|
283
|
-
return undefined;
|
|
284
|
-
}
|
|
285
|
-
// about
|
|
286
|
-
if (m[1]) {
|
|
287
|
-
datation.isApproximate = true;
|
|
288
|
-
}
|
|
289
|
-
// day
|
|
290
|
-
if (m[2]) {
|
|
291
|
-
datation.day = parseInt(m[2], 10);
|
|
292
|
-
}
|
|
293
|
-
// month
|
|
294
|
-
if (m[3]) {
|
|
295
|
-
const lowerMonth = m[3].toLowerCase();
|
|
296
|
-
const i = options.monthNames.findIndex((name) => name.toLowerCase() === lowerMonth);
|
|
297
|
-
if (i > -1) {
|
|
298
|
-
datation.month = i + 1;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
// year, span
|
|
302
|
-
if (m[4]) {
|
|
303
|
-
datation.value = parseInt(m[4], 10);
|
|
304
|
-
if (m[5]) {
|
|
305
|
-
datation.isSpan = true;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
datation.value = RomanNumber.fromRoman(m[6].toUpperCase());
|
|
310
|
-
datation.isCentury = true;
|
|
311
|
-
}
|
|
312
|
-
// era
|
|
313
|
-
if (m[7]) {
|
|
314
|
-
const era = m[7].replace(' ', '').toLowerCase();
|
|
315
|
-
if (era === options.bcText.toLowerCase()) {
|
|
316
|
-
datation.value = -datation.value;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
// dubious
|
|
320
|
-
if (m[8]) {
|
|
321
|
-
datation.isDubious = true;
|
|
322
|
-
}
|
|
323
|
-
// hint
|
|
324
|
-
if (m[9]) {
|
|
325
|
-
datation.hint = Datation.sanitizeHint(m[9]);
|
|
326
|
-
}
|
|
327
|
-
return datation;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Strip any era code from the specified datation format string.
|
|
331
|
-
* @param format The format string.
|
|
332
|
-
*/
|
|
333
|
-
static stripFormatStringEra(format) {
|
|
334
|
-
if (!format) {
|
|
335
|
-
return 'i';
|
|
336
|
-
}
|
|
337
|
-
// convert ga gp Ga Gp into simple g G
|
|
338
|
-
format = format.replace(new RegExp('([gG])[ap]', 'gi'), '$1');
|
|
339
|
-
// replace g/G with i/I
|
|
340
|
-
format = format.replace('g', 'i');
|
|
341
|
-
format = format.replace('G', 'I');
|
|
342
|
-
// remove ea ep Ea Ep with preceding w/W if any
|
|
343
|
-
format = format.replace(new RegExp('[wW]?[eE][ap]?', 'gi'), '');
|
|
344
|
-
return format;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Reset this datation.
|
|
348
|
-
*/
|
|
349
|
-
reset() {
|
|
350
|
-
this.value = 0;
|
|
351
|
-
this.isCentury = false;
|
|
352
|
-
this.isSpan = false;
|
|
353
|
-
this.isApproximate = false;
|
|
354
|
-
this.day = 0;
|
|
355
|
-
this.month = 0;
|
|
356
|
-
this.hint = undefined;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Copy data from the specified source datatation.
|
|
360
|
-
* @param datation The source datation.
|
|
361
|
-
*/
|
|
362
|
-
copyFrom(datation) {
|
|
363
|
-
this.value = datation.value;
|
|
364
|
-
this.isCentury = datation.isCentury;
|
|
365
|
-
this.isSpan = datation.isSpan;
|
|
366
|
-
this.isApproximate = datation.isApproximate;
|
|
367
|
-
this.isDubious = datation.isDubious;
|
|
368
|
-
this.day = datation.day;
|
|
369
|
-
this.month = datation.month;
|
|
370
|
-
this.hint = datation.hint ? datation.hint : undefined;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* True if this datation is undefined. A datation is undefined when
|
|
374
|
-
* its value is 0. Undefined datations are used as unknown points in a range
|
|
375
|
-
* for termini ante/post.
|
|
376
|
-
*/
|
|
377
|
-
isUndefined() {
|
|
378
|
-
return !this.value;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Get a sort value from this datation.
|
|
382
|
-
*/
|
|
383
|
-
getSortValue() {
|
|
384
|
-
let result;
|
|
385
|
-
if (this.isCentury) {
|
|
386
|
-
result = this.value * 100 + (this.value < 0 ? 50 : -50);
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
result = this.value;
|
|
390
|
-
}
|
|
391
|
-
if (this.isSpan) {
|
|
392
|
-
result += 0.5;
|
|
393
|
-
}
|
|
394
|
-
if (this.month > 0 && this.month <= 12) {
|
|
395
|
-
result += this.month / 12;
|
|
396
|
-
}
|
|
397
|
-
if (this.day > 0 && this.day <= 31) {
|
|
398
|
-
result += this.day / (12 * 31);
|
|
399
|
-
}
|
|
400
|
-
return result;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Get the 2-years span end value from this datation.
|
|
404
|
-
* A span year is always represented with its beginning year: e.g. -776/5
|
|
405
|
-
* is -776 with span, and 56/7 is 56 with span. This method returns the end year
|
|
406
|
-
* for a span, i.e. in the above samples -775 and 57 respectively. If this datation
|
|
407
|
-
* is not a span, the function just returns the unique year value.
|
|
408
|
-
*/
|
|
409
|
-
getSpanEnd() {
|
|
410
|
-
if (this.isCentury) {
|
|
411
|
-
return 0;
|
|
412
|
-
}
|
|
413
|
-
return this.isSpan ? this.value + 1 : this.value;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Get the century number corresponding this datation.
|
|
417
|
-
* This function returns 0 if the datation is null, or the century number,
|
|
418
|
-
* less than 0 if B.C. The result is based on the century value, if
|
|
419
|
-
* this is a century datation, or on the year, if this is not a century
|
|
420
|
-
* datation (e.g. -5 for 480 B.C., +1 for 31 A.D.).
|
|
421
|
-
*/
|
|
422
|
-
getCentury() {
|
|
423
|
-
if (this.value === 0) {
|
|
424
|
-
return 0;
|
|
425
|
-
}
|
|
426
|
-
return this.isCentury
|
|
427
|
-
? this.value
|
|
428
|
-
: Math.trunc(this.value / 100 + (this.value < 0 ? -1 : 1));
|
|
429
|
-
}
|
|
430
|
-
matchTokenAt(token, text, index) {
|
|
431
|
-
if (index + token.length > text.length) {
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
for (let i = 0; i < token.length; i++) {
|
|
435
|
-
if (token.charAt(i) !== text.charAt(i + index)) {
|
|
436
|
-
return false;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
parseFormatString(format) {
|
|
442
|
-
if (!format) {
|
|
443
|
-
return ['G'];
|
|
444
|
-
}
|
|
445
|
-
// expand macros
|
|
446
|
-
const macros = [
|
|
447
|
-
'ga',
|
|
448
|
-
'awdwMMMwvwepwpwh',
|
|
449
|
-
'Ga',
|
|
450
|
-
'awdwMMMwvwepwpwh',
|
|
451
|
-
'gp',
|
|
452
|
-
'awdwMMMwvweawpwh',
|
|
453
|
-
'Gp',
|
|
454
|
-
'awdwMMMwvweawpwh',
|
|
455
|
-
'g',
|
|
456
|
-
'awdwMMMwvwewpwh',
|
|
457
|
-
'G',
|
|
458
|
-
'AwdwMMMwVwewPwH',
|
|
459
|
-
'i',
|
|
460
|
-
'awdwMMMwvwpwh',
|
|
461
|
-
'I',
|
|
462
|
-
'AwdwMMMwVwPwH',
|
|
463
|
-
];
|
|
464
|
-
const sb = [];
|
|
465
|
-
let fi = 0;
|
|
466
|
-
let matched;
|
|
467
|
-
while (fi < format.length) {
|
|
468
|
-
matched = false;
|
|
469
|
-
for (let mi = 0; mi < macros.length; mi += 2) {
|
|
470
|
-
if (this.matchTokenAt(macros[mi], format, fi)) {
|
|
471
|
-
sb.push(macros[mi + 1]);
|
|
472
|
-
fi += macros[mi].length;
|
|
473
|
-
matched = true;
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (!matched) {
|
|
478
|
-
sb.push(format[fi]);
|
|
479
|
-
fi++;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
format = sb.join();
|
|
483
|
-
// split into tokens and literals
|
|
484
|
-
const tokens = [
|
|
485
|
-
'ddd',
|
|
486
|
-
'MMM',
|
|
487
|
-
'dd',
|
|
488
|
-
'ea',
|
|
489
|
-
'ep',
|
|
490
|
-
'Ea',
|
|
491
|
-
'Ep',
|
|
492
|
-
'ga',
|
|
493
|
-
'Ga',
|
|
494
|
-
'gp',
|
|
495
|
-
'Gp',
|
|
496
|
-
'MM',
|
|
497
|
-
];
|
|
498
|
-
fi = 0;
|
|
499
|
-
const results = [];
|
|
500
|
-
while (fi < format.length) {
|
|
501
|
-
matched = false;
|
|
502
|
-
for (let ti = 0; ti < tokens.length; ti++) {
|
|
503
|
-
if (this.matchTokenAt(tokens[ti], format, fi)) {
|
|
504
|
-
results.push(tokens[ti]);
|
|
505
|
-
fi += tokens[ti].length;
|
|
506
|
-
matched = true;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (!matched) {
|
|
511
|
-
results.push(format.charAt(fi));
|
|
512
|
-
fi++;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
return results;
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Convert this datation to a string.
|
|
519
|
-
* @param format The format string, which can include any of the following:
|
|
520
|
-
* v = year or century value, lowercase
|
|
521
|
-
* V = year or century value, uppercase
|
|
522
|
-
* c = century, lowercase
|
|
523
|
-
* C = century, uppercase
|
|
524
|
-
* a or A = 'about' marker when present
|
|
525
|
-
* p or P = 'perhaps' marker when present
|
|
526
|
-
* d = day number when present
|
|
527
|
-
* dd = 2-digits (0-padded at left) day number when present
|
|
528
|
-
* ddd = weekday name when present
|
|
529
|
-
* M = month number when present
|
|
530
|
-
* MM = 2-digits (0-padded at left) month number when present
|
|
531
|
-
* MMM = month name when present
|
|
532
|
-
* e = era
|
|
533
|
-
* E = era, all uppercase
|
|
534
|
-
* ea = era, only if ante Christum natum
|
|
535
|
-
* ep = era, only if post Christum natum
|
|
536
|
-
* Ea = era all uppercase, only if ante Christum natum
|
|
537
|
-
* Ep = era all uppercase, only if post Christum natum
|
|
538
|
-
* h or H = hint when present
|
|
539
|
-
* w or W = smart whitespace (appended only when left char if any
|
|
540
|
-
* is not a whitespace)
|
|
541
|
-
* s or S = sort value
|
|
542
|
-
* g = generic: equal to awdwMMMwvwewpwh
|
|
543
|
-
* G = generic uppercase: equal to AwdwMMMwVwewPwH
|
|
544
|
-
* ga = generic ante Christum: era expressed only when post Christum
|
|
545
|
-
* natum. Equal to awdwMMMwvwepwpwh
|
|
546
|
-
* Ga = generic uppercase ante Christum: equal to awdwMMMwvwepwpwh
|
|
547
|
-
* gp = generic post Christum: era expressed only when ante Christum
|
|
548
|
-
* natum. Equal to awdwMMMwvweawpwh
|
|
549
|
-
* Gp = generic uppercase post Christum: equal to awdwMMMwvweawpwh
|
|
550
|
-
* i = generic with implicit (=not expressed) era: equal to awdwMMMwvwpwh
|
|
551
|
-
* I = generic uppercase with implicit (=not expressed) era: equal to
|
|
552
|
-
* AwdwMMMwVwPwH
|
|
553
|
-
* @param options The options.
|
|
554
|
-
*/
|
|
555
|
-
toString(format = 'G', options = DATATION_FORMAT_OPTIONS) {
|
|
556
|
-
if (this.isUndefined()) {
|
|
557
|
-
return '';
|
|
558
|
-
}
|
|
559
|
-
if (!format) {
|
|
560
|
-
format = 'G';
|
|
561
|
-
}
|
|
562
|
-
if (!options) {
|
|
563
|
-
options = DATATION_FORMAT_OPTIONS;
|
|
564
|
-
}
|
|
565
|
-
const sb = [];
|
|
566
|
-
const tokens = this.parseFormatString(format);
|
|
567
|
-
tokens.forEach((token) => {
|
|
568
|
-
switch (token) {
|
|
569
|
-
case 'v':
|
|
570
|
-
case 'V':
|
|
571
|
-
// year or century
|
|
572
|
-
if (this.isCentury) {
|
|
573
|
-
sb.push(token === 'v'
|
|
574
|
-
? RomanNumber.toRoman(Math.abs(this.value)).toLowerCase()
|
|
575
|
-
: RomanNumber.toRoman(Math.abs(this.value)).toUpperCase());
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
const year = Math.abs(this.value);
|
|
579
|
-
sb.push(year.toString());
|
|
580
|
-
if (this.isSpan) {
|
|
581
|
-
sb.push(`/${year + (this.value < 0 ? -1 : +1)}`);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
break;
|
|
585
|
-
case 'c':
|
|
586
|
-
case 'C':
|
|
587
|
-
const century = Math.abs(this.getCentury());
|
|
588
|
-
sb.push(token === 'c'
|
|
589
|
-
? RomanNumber.toRoman(century).toLowerCase()
|
|
590
|
-
: RomanNumber.toRoman(century).toUpperCase());
|
|
591
|
-
break;
|
|
592
|
-
case 'a':
|
|
593
|
-
case 'A':
|
|
594
|
-
if (this.isApproximate) {
|
|
595
|
-
sb.push(options.aboutText);
|
|
596
|
-
}
|
|
597
|
-
break;
|
|
598
|
-
case 'p':
|
|
599
|
-
case 'P':
|
|
600
|
-
if (this.isDubious) {
|
|
601
|
-
sb.push('?');
|
|
602
|
-
}
|
|
603
|
-
break;
|
|
604
|
-
case 'd':
|
|
605
|
-
if (this.day > 0) {
|
|
606
|
-
sb.push(this.day.toString());
|
|
607
|
-
}
|
|
608
|
-
break;
|
|
609
|
-
case 'dd':
|
|
610
|
-
if (this.day > 0) {
|
|
611
|
-
sb.push(this.day.toString().padStart(2, '0'));
|
|
612
|
-
}
|
|
613
|
-
break;
|
|
614
|
-
case 'ddd':
|
|
615
|
-
if (this.day > 0) {
|
|
616
|
-
const date = new Date(this.value, this.month, this.day);
|
|
617
|
-
const dow = date.getDay();
|
|
618
|
-
sb.push(options.dayNames[dow]);
|
|
619
|
-
}
|
|
620
|
-
break;
|
|
621
|
-
case 'M':
|
|
622
|
-
if (this.month > 0) {
|
|
623
|
-
sb.push(this.month.toString());
|
|
624
|
-
}
|
|
625
|
-
break;
|
|
626
|
-
case 'MM':
|
|
627
|
-
if (this.month > 0) {
|
|
628
|
-
sb.push(this.month.toString().padStart(2, '0'));
|
|
629
|
-
}
|
|
630
|
-
break;
|
|
631
|
-
case 'MMM':
|
|
632
|
-
if (this.month > 0) {
|
|
633
|
-
sb.push(options.monthNames[this.month - 1]);
|
|
634
|
-
}
|
|
635
|
-
break;
|
|
636
|
-
case 'e':
|
|
637
|
-
sb.push(this.value < 0 ? options.bcText : options.adText);
|
|
638
|
-
break;
|
|
639
|
-
case 'E':
|
|
640
|
-
sb.push(this.value < 0
|
|
641
|
-
? options.bcText.toUpperCase()
|
|
642
|
-
: options.adText.toUpperCase());
|
|
643
|
-
break;
|
|
644
|
-
case 'ea':
|
|
645
|
-
if (this.value < 0) {
|
|
646
|
-
sb.push(options.bcText);
|
|
647
|
-
}
|
|
648
|
-
break;
|
|
649
|
-
case 'ep':
|
|
650
|
-
if (this.value > 0) {
|
|
651
|
-
sb.push(options.adText);
|
|
652
|
-
}
|
|
653
|
-
break;
|
|
654
|
-
case 'h':
|
|
655
|
-
case 'H':
|
|
656
|
-
if (this.hint) {
|
|
657
|
-
sb.push(` {${this.hint}}`);
|
|
658
|
-
}
|
|
659
|
-
break;
|
|
660
|
-
case 'w':
|
|
661
|
-
case 'W':
|
|
662
|
-
if (sb.length > 0) {
|
|
663
|
-
const last = sb[sb.length - 1];
|
|
664
|
-
if (!last.endsWith(' ')) {
|
|
665
|
-
sb.push(' ');
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
break;
|
|
669
|
-
case 's':
|
|
670
|
-
case 'S':
|
|
671
|
-
sb.push(this.getSortValue().toString());
|
|
672
|
-
break;
|
|
673
|
-
default:
|
|
674
|
-
// literal
|
|
675
|
-
sb.push(token);
|
|
676
|
-
break;
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
return sb.join('').trim().replace(new RegExp('\\s+', 'g'), ' ');
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
const APPROX_DELTA = 10;
|
|
684
|
-
/**
|
|
685
|
-
* Type of historical date.
|
|
686
|
-
*/
|
|
687
|
-
var HistoricalDateType;
|
|
688
|
-
(function (HistoricalDateType) {
|
|
689
|
-
HistoricalDateType[HistoricalDateType["undefined"] = 0] = "undefined";
|
|
690
|
-
HistoricalDateType[HistoricalDateType["point"] = 1] = "point";
|
|
691
|
-
HistoricalDateType[HistoricalDateType["range"] = 2] = "range";
|
|
692
|
-
})(HistoricalDateType || (HistoricalDateType = {}));
|
|
693
|
-
/**
|
|
694
|
-
* A historical date, including 0, 1, or 2 datation points.
|
|
695
|
-
*/
|
|
696
|
-
class HistoricalDate {
|
|
697
|
-
constructor(date = null) {
|
|
698
|
-
if (!date) {
|
|
699
|
-
this.a = new Datation();
|
|
700
|
-
// B=undefined for a single point
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
this.a = new Datation(date.a);
|
|
704
|
-
if (date.b) {
|
|
705
|
-
this.b = new Datation(date.b);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Parse the specified text representing a historical datation.
|
|
711
|
-
* @param text The text to be parsed.
|
|
712
|
-
* @param options The datation formatter options.
|
|
713
|
-
* @return The datation, or null if invalid.
|
|
714
|
-
*/
|
|
715
|
-
static parse(text, options = DATATION_FORMAT_OPTIONS) {
|
|
716
|
-
if (!text) {
|
|
717
|
-
return null;
|
|
718
|
-
}
|
|
719
|
-
const dates = text.split('--');
|
|
720
|
-
let s1 = dates[0].trim();
|
|
721
|
-
const s2 = dates.length > 1 ? dates[1].trim() : null;
|
|
722
|
-
const date = new HistoricalDate();
|
|
723
|
-
if (dates.length > 1) {
|
|
724
|
-
// if both terms are specified, integrate BC/AD indication in 1st if required
|
|
725
|
-
if (s1 && s2) {
|
|
726
|
-
const bcad = Datation.getErasOptionsForRegex(options);
|
|
727
|
-
const tailRegexp = new RegExp(
|
|
728
|
-
// era (1)
|
|
729
|
-
'(' +
|
|
730
|
-
bcad[0] +
|
|
731
|
-
'|' +
|
|
732
|
-
bcad[1] +
|
|
733
|
-
')?' +
|
|
734
|
-
// dubious (2)
|
|
735
|
-
'(\\s*\\?)?' +
|
|
736
|
-
// hint (3)
|
|
737
|
-
'(?:\\s*\\{?:([^)]+)\\})?\\s*$', 'gi');
|
|
738
|
-
const m1 = tailRegexp.exec(s1);
|
|
739
|
-
// if 1st has no era try integration from 2nd
|
|
740
|
-
if (m1 && m1[1]) {
|
|
741
|
-
// get era from 2nd (if 2nd hasn't it too, give up and AD will be assumed)
|
|
742
|
-
const m2 = tailRegexp.exec(s2);
|
|
743
|
-
if (m2 && m2[1]) {
|
|
744
|
-
const era = m2[1] || 'p.C.';
|
|
745
|
-
const sb1 = [];
|
|
746
|
-
if (m1.index > 0) {
|
|
747
|
-
sb1.push(s1.substr(0, m1.index));
|
|
748
|
-
}
|
|
749
|
-
sb1.push(' ' + era);
|
|
750
|
-
if (m1[2]) {
|
|
751
|
-
sb1.push('?');
|
|
752
|
-
}
|
|
753
|
-
if (m1[3]) {
|
|
754
|
-
sb1.push(` (${m1[3]})`);
|
|
755
|
-
}
|
|
756
|
-
s1 = sb1.join('');
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
date.setStartPoint(Datation.parse(s1, options));
|
|
761
|
-
date.setEndPoint(Datation.parse(s2, options));
|
|
762
|
-
}
|
|
763
|
-
else {
|
|
764
|
-
// here we have a s2, even if empty. When empty, it represents
|
|
765
|
-
// an unknown point in a terminus ante/post, and as such we
|
|
766
|
-
// must set B=null. When B=undefined, it's not a range but a point.
|
|
767
|
-
const d = Datation.parse(s1, options);
|
|
768
|
-
if (d && !d.isUndefined()) {
|
|
769
|
-
date.setSinglePoint(d);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
return date;
|
|
773
|
-
}
|
|
774
|
-
getStartPoint() {
|
|
775
|
-
return this.getDateType() === HistoricalDateType.range ? this.a : undefined;
|
|
776
|
-
}
|
|
777
|
-
setStartPoint(value) {
|
|
778
|
-
this.a = new Datation(value);
|
|
779
|
-
// it's a range, ensure max is not null
|
|
780
|
-
if (!this.b) {
|
|
781
|
-
this.b = new Datation();
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
getEndPoint() {
|
|
785
|
-
return this.getDateType() === HistoricalDateType.range ? this.b : undefined;
|
|
786
|
-
}
|
|
787
|
-
setEndPoint(value) {
|
|
788
|
-
this.b = new Datation(value);
|
|
789
|
-
}
|
|
790
|
-
getSinglePoint() {
|
|
791
|
-
return this.getDateType() === HistoricalDateType.point ? this.a : undefined;
|
|
792
|
-
}
|
|
793
|
-
setSinglePoint(value) {
|
|
794
|
-
this.a = new Datation(value);
|
|
795
|
-
// it's a point, ensure max is undefined
|
|
796
|
-
this.b = undefined;
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* True if this date is undefined.
|
|
800
|
-
*/
|
|
801
|
-
isUndefined() {
|
|
802
|
-
return (!this.a || (this.a.isUndefined() && (!this.b || this.b.isUndefined())));
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Get the type of this date.
|
|
806
|
-
*/
|
|
807
|
-
getDateType() {
|
|
808
|
-
if (this.isUndefined()) {
|
|
809
|
-
return HistoricalDateType.undefined;
|
|
810
|
-
}
|
|
811
|
-
return this.b ? HistoricalDateType.range : HistoricalDateType.point;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Validate this date.
|
|
815
|
-
* @returns Error message if invalid, or null if valid.
|
|
816
|
-
*/
|
|
817
|
-
validate() {
|
|
818
|
-
if (!this.a) {
|
|
819
|
-
return 'Missing point A';
|
|
820
|
-
}
|
|
821
|
-
if (this.getDateType() === HistoricalDateType.range) {
|
|
822
|
-
const av = this.a.getSortValue();
|
|
823
|
-
const bv = this.b.getSortValue();
|
|
824
|
-
if (av && bv && av >= bv) {
|
|
825
|
-
return 'Point A is past point B';
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
return null;
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Get the sort value for this date.
|
|
832
|
-
*/
|
|
833
|
-
getSortValue() {
|
|
834
|
-
switch (this.getDateType()) {
|
|
835
|
-
case HistoricalDateType.point:
|
|
836
|
-
return this.a.getSortValue();
|
|
837
|
-
case HistoricalDateType.range:
|
|
838
|
-
if (this.a.isUndefined()) {
|
|
839
|
-
return this.b.getSortValue() - APPROX_DELTA;
|
|
840
|
-
}
|
|
841
|
-
if (this.b.isUndefined()) {
|
|
842
|
-
return this.a.getSortValue() + APPROX_DELTA;
|
|
843
|
-
}
|
|
844
|
-
return (this.a.getSortValue() + this.b.getSortValue()) / 2;
|
|
845
|
-
default:
|
|
846
|
-
return 0;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Build a textual representation of this date.
|
|
851
|
-
* @param format The format string.
|
|
852
|
-
* @param options The formatter options.
|
|
853
|
-
*/
|
|
854
|
-
toString(format = 'G', options = DATATION_FORMAT_OPTIONS) {
|
|
855
|
-
const sb = [];
|
|
856
|
-
switch (this.getDateType()) {
|
|
857
|
-
case HistoricalDateType.point:
|
|
858
|
-
sb.push(this.a.toString(format, options));
|
|
859
|
-
break;
|
|
860
|
-
case HistoricalDateType.range:
|
|
861
|
-
// if both terms are present and belong to same era, omit it in 1st
|
|
862
|
-
if (!this.a.isUndefined() &&
|
|
863
|
-
this.b &&
|
|
864
|
-
!this.b.isUndefined() &&
|
|
865
|
-
this.a.value * this.b.value > 0) {
|
|
866
|
-
sb.push(this.a.toString(Datation.stripFormatStringEra(format), options));
|
|
867
|
-
sb.push(' -- ');
|
|
868
|
-
sb.push(this.b.toString(format, options));
|
|
869
|
-
break;
|
|
870
|
-
}
|
|
871
|
-
if (!this.a.isUndefined()) {
|
|
872
|
-
sb.push(this.a.toString(format, options) + ' ');
|
|
873
|
-
}
|
|
874
|
-
sb.push('--');
|
|
875
|
-
if (this.b && !this.b.isUndefined()) {
|
|
876
|
-
sb.push(this.b.toString(format, options));
|
|
877
|
-
}
|
|
878
|
-
break;
|
|
879
|
-
}
|
|
880
|
-
return sb.join('');
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Get the approximate year value from the specified century value.
|
|
884
|
-
* @param century The century number, negative if B.C.
|
|
885
|
-
*/
|
|
886
|
-
centuryToYear(century) {
|
|
887
|
-
return century * 100 + (century < 0 ? 50 : -50);
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Convert this date into a single approximate year value.
|
|
891
|
-
* For centuries, the central century year is returned (e.g. -350 for IV B.C.
|
|
892
|
-
* and +350 for IV A.D.); when the date is a range with a single boundary only
|
|
893
|
-
* (max or min) the corresponding year minus or plus a predefined delta value
|
|
894
|
-
* (10) is returned; if it's a range with both boundaries (max and min),
|
|
895
|
-
* the middle year between them is returned.
|
|
896
|
-
* @param useTerminusSpan True to add or remove the predefined span from
|
|
897
|
-
* a terminus ante or post.
|
|
898
|
-
*/
|
|
899
|
-
toYear(useTerminusSpan = true) {
|
|
900
|
-
let year = 0;
|
|
901
|
-
switch (this.getDateType()) {
|
|
902
|
-
case HistoricalDateType.point:
|
|
903
|
-
year = Math.trunc(this.a.isCentury ? this.centuryToYear(this.a.value) : this.a.value);
|
|
904
|
-
break;
|
|
905
|
-
case HistoricalDateType.range:
|
|
906
|
-
// min is missing: terminus ante
|
|
907
|
-
if (this.a.isUndefined()) {
|
|
908
|
-
year = Math.trunc((this.b.isCentury
|
|
909
|
-
? this.centuryToYear(this.b.value)
|
|
910
|
-
: this.b.value) - (useTerminusSpan ? APPROX_DELTA : 0));
|
|
911
|
-
break;
|
|
912
|
-
}
|
|
913
|
-
// max is missing: terminus post
|
|
914
|
-
if (!this.b || this.b.isUndefined()) {
|
|
915
|
-
year = Math.trunc((this.a.isCentury
|
|
916
|
-
? this.centuryToYear(this.a.value)
|
|
917
|
-
: this.a.value) + (useTerminusSpan ? APPROX_DELTA : 0));
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
// both min and max
|
|
921
|
-
const min = this.a.isCentury
|
|
922
|
-
? this.centuryToYear(this.a.value)
|
|
923
|
-
: this.a.value;
|
|
924
|
-
const max = this.b.isCentury
|
|
925
|
-
? this.centuryToYear(this.b.value)
|
|
926
|
-
: this.b.value;
|
|
927
|
-
year = Math.trunc((max - min) / 2 + min);
|
|
928
|
-
if (year === 0) {
|
|
929
|
-
year = 1;
|
|
930
|
-
}
|
|
931
|
-
break;
|
|
932
|
-
}
|
|
933
|
-
return year;
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* True if any value (either in point or in range) has an about flag.
|
|
937
|
-
*/
|
|
938
|
-
isAbout() {
|
|
939
|
-
let about = false;
|
|
940
|
-
switch (this.getDateType()) {
|
|
941
|
-
case HistoricalDateType.point:
|
|
942
|
-
about = this.a.isApproximate;
|
|
943
|
-
break;
|
|
944
|
-
case HistoricalDateType.range:
|
|
945
|
-
if (!this.a.isUndefined()) {
|
|
946
|
-
about = this.a.isApproximate;
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
if (!this.b.isUndefined()) {
|
|
950
|
-
about = this.b.isApproximate;
|
|
951
|
-
}
|
|
952
|
-
break;
|
|
953
|
-
}
|
|
954
|
-
return about;
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* True if any value (either in point or in range) has an about flag.
|
|
958
|
-
*/
|
|
959
|
-
isDubious() {
|
|
960
|
-
let dubious = false;
|
|
961
|
-
switch (this.getDateType()) {
|
|
962
|
-
case HistoricalDateType.point:
|
|
963
|
-
dubious = this.a.isDubious;
|
|
964
|
-
break;
|
|
965
|
-
case HistoricalDateType.range:
|
|
966
|
-
if (!this.a.isUndefined()) {
|
|
967
|
-
dubious = this.a.isDubious;
|
|
968
|
-
break;
|
|
969
|
-
}
|
|
970
|
-
if (!this.b.isUndefined()) {
|
|
971
|
-
dubious = this.b.isDubious;
|
|
972
|
-
}
|
|
973
|
-
break;
|
|
974
|
-
}
|
|
975
|
-
return dubious;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
6
|
+
import { NgToolsModule } from '@myrmidon/ng-tools';
|
|
978
7
|
|
|
979
8
|
/**
|
|
980
9
|
* Data pin value type in a DataPinDefinition.
|
|
@@ -1079,7 +108,7 @@ class TokenPoint {
|
|
|
1079
108
|
}
|
|
1080
109
|
toString() {
|
|
1081
110
|
let s = `${this.y}.${this.x}`;
|
|
1082
|
-
if (this.at
|
|
111
|
+
if (this.at && this.run) {
|
|
1083
112
|
s += `@${this.at}`;
|
|
1084
113
|
if (this.run !== 1) {
|
|
1085
114
|
s += `x${this.run}`;
|
|
@@ -1111,7 +140,7 @@ class TokenPoint {
|
|
|
1111
140
|
}
|
|
1112
141
|
|
|
1113
142
|
class TokenLocation {
|
|
1114
|
-
constructor(primary, secondary
|
|
143
|
+
constructor(primary, secondary) {
|
|
1115
144
|
this.primary = primary;
|
|
1116
145
|
this.secondary = secondary;
|
|
1117
146
|
}
|
|
@@ -1130,7 +159,7 @@ class TokenLocation {
|
|
|
1130
159
|
if (pair.length === 0) {
|
|
1131
160
|
return null;
|
|
1132
161
|
}
|
|
1133
|
-
return new TokenLocation(TokenPoint.parse(pair[0]), pair.length > 1 ? TokenPoint.parse(pair[1]) :
|
|
162
|
+
return new TokenLocation(TokenPoint.parse(pair[0]), pair.length > 1 ? TokenPoint.parse(pair[1]) || undefined : undefined);
|
|
1134
163
|
}
|
|
1135
164
|
isRange() {
|
|
1136
165
|
// note that != checks for both null and undefined, whereas !== does not
|
|
@@ -1183,42 +212,6 @@ class TokenLocation {
|
|
|
1183
212
|
}
|
|
1184
213
|
}
|
|
1185
214
|
|
|
1186
|
-
/**
|
|
1187
|
-
* Deep-copy an object.
|
|
1188
|
-
*/
|
|
1189
|
-
function deepCopy(obj) {
|
|
1190
|
-
let copy;
|
|
1191
|
-
// handle the 3 simple types, and null or undefined
|
|
1192
|
-
if (null == obj || 'object' !== typeof obj) {
|
|
1193
|
-
return obj;
|
|
1194
|
-
}
|
|
1195
|
-
// handle date
|
|
1196
|
-
if (obj instanceof Date) {
|
|
1197
|
-
copy = new Date();
|
|
1198
|
-
copy.setTime(obj.getTime());
|
|
1199
|
-
return copy;
|
|
1200
|
-
}
|
|
1201
|
-
// handle array
|
|
1202
|
-
if (obj instanceof Array) {
|
|
1203
|
-
copy = [];
|
|
1204
|
-
for (let i = 0, len = obj.length; i < len; i++) {
|
|
1205
|
-
copy[i] = deepCopy(obj[i]);
|
|
1206
|
-
}
|
|
1207
|
-
return copy;
|
|
1208
|
-
}
|
|
1209
|
-
// handle object
|
|
1210
|
-
if (obj instanceof Object) {
|
|
1211
|
-
copy = {};
|
|
1212
|
-
for (const attr in obj) {
|
|
1213
|
-
if (obj.hasOwnProperty(attr)) {
|
|
1214
|
-
copy[attr] = deepCopy(obj[attr]);
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
return copy;
|
|
1218
|
-
}
|
|
1219
|
-
throw new Error('Unable to copy object!');
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
215
|
class PendingChangesGuard {
|
|
1223
216
|
canDeactivate(component) {
|
|
1224
217
|
// if there are no pending changes, just allow deactivation; else confirm first
|
|
@@ -1232,12 +225,12 @@ class PendingChangesGuard {
|
|
|
1232
225
|
'Press Cancel to go back and save, OK to continue.');
|
|
1233
226
|
}
|
|
1234
227
|
}
|
|
1235
|
-
PendingChangesGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
1236
|
-
PendingChangesGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
1237
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
228
|
+
PendingChangesGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: PendingChangesGuard, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
229
|
+
PendingChangesGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: PendingChangesGuard, providedIn: 'root' });
|
|
230
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: PendingChangesGuard, decorators: [{
|
|
1238
231
|
type: Injectable,
|
|
1239
232
|
args: [{
|
|
1240
|
-
providedIn: 'root'
|
|
233
|
+
providedIn: 'root',
|
|
1241
234
|
}]
|
|
1242
235
|
}] });
|
|
1243
236
|
|
|
@@ -1268,187 +261,19 @@ class SortPipe {
|
|
|
1268
261
|
else if (a[propName] > b[propName]) {
|
|
1269
262
|
return 1;
|
|
1270
263
|
}
|
|
264
|
+
return 0;
|
|
1271
265
|
});
|
|
1272
266
|
}
|
|
1273
267
|
}
|
|
1274
|
-
SortPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
1275
|
-
SortPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0
|
|
1276
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
268
|
+
SortPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: SortPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
269
|
+
SortPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: SortPipe, name: "sort" });
|
|
270
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: SortPipe, decorators: [{
|
|
1277
271
|
type: Pipe,
|
|
1278
272
|
args: [{
|
|
1279
273
|
name: 'sort',
|
|
1280
274
|
}]
|
|
1281
275
|
}] });
|
|
1282
276
|
|
|
1283
|
-
/**
|
|
1284
|
-
* Environment variables service. This requires EnvServiceProvider.
|
|
1285
|
-
* See https://www.jvandemo.com/how-to-use-environment-variables-to-configure-your-angular-application-without-a-rebuild/.
|
|
1286
|
-
*
|
|
1287
|
-
* To use this service:
|
|
1288
|
-
* 1. ensure to add env.js from your app's src folder to the app's assets
|
|
1289
|
-
* ("src/env.js" under architect/build/options/assets);
|
|
1290
|
-
* 2. add the EnvServiceProvider to your app's providers array;
|
|
1291
|
-
* 3. ensure to include env.js in the head of your index.html:
|
|
1292
|
-
* <script src="env.js"></script>.
|
|
1293
|
-
*
|
|
1294
|
-
* The env.js file should include all your environment-dependent settings,
|
|
1295
|
-
* e.g.:
|
|
1296
|
-
*
|
|
1297
|
-
* (function (window) {
|
|
1298
|
-
* window.__env = window.__env || {};
|
|
1299
|
-
* window.__env.apiUrl = 'http://localhost:60200/api/';
|
|
1300
|
-
* }(this));
|
|
1301
|
-
*/
|
|
1302
|
-
class EnvService {
|
|
1303
|
-
constructor() {
|
|
1304
|
-
this._map = new Map();
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Get the value for the specified key. If the key is not found,
|
|
1308
|
-
* defValue will be returned.
|
|
1309
|
-
*
|
|
1310
|
-
* @param key The key.
|
|
1311
|
-
* @param defValue The default value to return if key is not found.
|
|
1312
|
-
*/
|
|
1313
|
-
get(key, defValue) {
|
|
1314
|
-
if (this._map.has(key)) {
|
|
1315
|
-
return this._map.get(key);
|
|
1316
|
-
}
|
|
1317
|
-
return defValue;
|
|
1318
|
-
}
|
|
1319
|
-
/**
|
|
1320
|
-
* Enumerate all the keys in this store.
|
|
1321
|
-
*/
|
|
1322
|
-
getKeys() {
|
|
1323
|
-
return this._map.keys();
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* Set a value with the specified key.
|
|
1327
|
-
*
|
|
1328
|
-
* @param key The key.
|
|
1329
|
-
* @param value The value.
|
|
1330
|
-
*/
|
|
1331
|
-
set(key, value) {
|
|
1332
|
-
this._map.set(key, value);
|
|
1333
|
-
}
|
|
1334
|
-
/**
|
|
1335
|
-
* Delete the value with the specified key, if any.
|
|
1336
|
-
*
|
|
1337
|
-
* @param key The key.
|
|
1338
|
-
*/
|
|
1339
|
-
delete(key) {
|
|
1340
|
-
this._map.delete(key);
|
|
1341
|
-
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Clear this store.
|
|
1344
|
-
*/
|
|
1345
|
-
clear() {
|
|
1346
|
-
this._map.clear();
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
EnvService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: EnvService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1350
|
-
EnvService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: EnvService, providedIn: 'root' });
|
|
1351
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: EnvService, decorators: [{
|
|
1352
|
-
type: Injectable,
|
|
1353
|
-
args: [{
|
|
1354
|
-
providedIn: 'root',
|
|
1355
|
-
}]
|
|
1356
|
-
}], ctorParameters: function () { return []; } });
|
|
1357
|
-
|
|
1358
|
-
// https://www.jvandemo.com/how-to-use-environment-variables-to-configure-your-angular-application-without-a-rebuild/
|
|
1359
|
-
/**
|
|
1360
|
-
* This function creates an instance of EnvService, and copies
|
|
1361
|
-
* all the properties from window.__env object into it.
|
|
1362
|
-
*/
|
|
1363
|
-
const EnvServiceFactory = () => {
|
|
1364
|
-
const env = new EnvService();
|
|
1365
|
-
// read environment variables from browser window
|
|
1366
|
-
const browserWindow = window || {};
|
|
1367
|
-
const browserWindowEnv = browserWindow['__env'] || {};
|
|
1368
|
-
// assign environment variables from browser window to env;
|
|
1369
|
-
// in the current implementation, properties from env.js
|
|
1370
|
-
// overwrite defaults (if any) from the EnvService.
|
|
1371
|
-
for (const key in browserWindowEnv) {
|
|
1372
|
-
if (browserWindowEnv.hasOwnProperty(key)) {
|
|
1373
|
-
env.set(key, browserWindowEnv[key]);
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
return env;
|
|
1377
|
-
};
|
|
1378
|
-
/**
|
|
1379
|
-
* A provider recipe for the EnvService.
|
|
1380
|
-
* This must be registered in the applications providers array.
|
|
1381
|
-
*/
|
|
1382
|
-
const EnvServiceProvider = {
|
|
1383
|
-
provide: EnvService,
|
|
1384
|
-
useFactory: EnvServiceFactory,
|
|
1385
|
-
deps: [],
|
|
1386
|
-
};
|
|
1387
|
-
|
|
1388
|
-
// https://angular.io/guide/http
|
|
1389
|
-
/**
|
|
1390
|
-
* Error handler for services. To use this in your service, pipe a catchError
|
|
1391
|
-
* operator with its argument equal to the handleError method of this service.
|
|
1392
|
-
* Note: pipe this method after retry, if using it.
|
|
1393
|
-
*/
|
|
1394
|
-
class ErrorService {
|
|
1395
|
-
/**
|
|
1396
|
-
* Handle the specified error response.
|
|
1397
|
-
* @param error The error response.
|
|
1398
|
-
*/
|
|
1399
|
-
handleError(error) {
|
|
1400
|
-
if (error.error instanceof ErrorEvent) {
|
|
1401
|
-
// A client-side or network error occurred. Handle it accordingly.
|
|
1402
|
-
console.error('A client-side or network error occurred: ', error.error.message);
|
|
1403
|
-
}
|
|
1404
|
-
else {
|
|
1405
|
-
// The backend returned an unsuccessful response code.
|
|
1406
|
-
// The response body may contain clues as to what went wrong,
|
|
1407
|
-
console.error(`Backend returned code ${error.status}, ` + `body was: ${error.error}`);
|
|
1408
|
-
if (typeof error === 'object') {
|
|
1409
|
-
console.log(JSON.stringify(error));
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
// return an observable with a user-facing error message
|
|
1413
|
-
return throwError('Something bad happened; please try again later.');
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
ErrorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: ErrorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1417
|
-
ErrorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: ErrorService, providedIn: 'root' });
|
|
1418
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: ErrorService, decorators: [{
|
|
1419
|
-
type: Injectable,
|
|
1420
|
-
args: [{
|
|
1421
|
-
providedIn: 'root',
|
|
1422
|
-
}]
|
|
1423
|
-
}] });
|
|
1424
|
-
|
|
1425
|
-
// npm i gravatar --save
|
|
1426
|
-
// npm i @types/gravatar --save
|
|
1427
|
-
class GravatarService {
|
|
1428
|
-
/**
|
|
1429
|
-
* Builds the URL to the Gravatar avatar corresponding to the specified email
|
|
1430
|
-
* address.
|
|
1431
|
-
* @param email: The email address.
|
|
1432
|
-
* @param size The required size in pixels (1-512).
|
|
1433
|
-
*/
|
|
1434
|
-
buildGravatarUrl(email, size = 80) {
|
|
1435
|
-
if (!email) {
|
|
1436
|
-
return null;
|
|
1437
|
-
}
|
|
1438
|
-
return gravatar.url(email, { s: size.toString() });
|
|
1439
|
-
// const hash = this._hash.getMd5(email.trim().toLowerCase());
|
|
1440
|
-
// return this.buildGravatarUrlFromHash(hash, size);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
GravatarService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: GravatarService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1444
|
-
GravatarService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: GravatarService, providedIn: 'root' });
|
|
1445
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: GravatarService, decorators: [{
|
|
1446
|
-
type: Injectable,
|
|
1447
|
-
args: [{
|
|
1448
|
-
providedIn: 'root'
|
|
1449
|
-
}]
|
|
1450
|
-
}] });
|
|
1451
|
-
|
|
1452
277
|
/**
|
|
1453
278
|
* Library route service.
|
|
1454
279
|
* This service is used to build routes to part and fragment editors,
|
|
@@ -1506,13 +331,13 @@ class LibraryRouteService {
|
|
|
1506
331
|
if (i > -1) {
|
|
1507
332
|
return {
|
|
1508
333
|
frTypeId: roleId.substring(0, i),
|
|
1509
|
-
frRoleId: roleId.substring(i + 1)
|
|
334
|
+
frRoleId: roleId.substring(i + 1),
|
|
1510
335
|
};
|
|
1511
336
|
}
|
|
1512
337
|
else {
|
|
1513
338
|
return {
|
|
1514
339
|
frTypeId: roleId,
|
|
1515
|
-
frRoleId:
|
|
340
|
+
frRoleId: undefined,
|
|
1516
341
|
};
|
|
1517
342
|
}
|
|
1518
343
|
}
|
|
@@ -1523,22 +348,23 @@ class LibraryRouteService {
|
|
|
1523
348
|
* @param partDefs The parts definitions.
|
|
1524
349
|
* @param typeId The type ID.
|
|
1525
350
|
* @param roleId The role ID or null.
|
|
1526
|
-
* @returns Part definition or
|
|
351
|
+
* @returns Part definition or undefined if not found.
|
|
1527
352
|
*/
|
|
1528
353
|
findPartDefinition(partDefs, typeId, roleId = null) {
|
|
1529
354
|
if (!partDefs) {
|
|
1530
|
-
return
|
|
355
|
+
return undefined;
|
|
1531
356
|
}
|
|
1532
357
|
// if role ID is specified, find both type and role
|
|
1533
358
|
if (roleId) {
|
|
1534
359
|
const reqRoleId = this.stripFragmentRoleId(roleId);
|
|
1535
|
-
return partDefs.find(d => {
|
|
360
|
+
return partDefs.find((d) => {
|
|
1536
361
|
return (d.typeId === typeId &&
|
|
362
|
+
d.roleId &&
|
|
1537
363
|
this.stripFragmentRoleId(d.roleId) === reqRoleId);
|
|
1538
364
|
});
|
|
1539
365
|
}
|
|
1540
366
|
// else just find type ID
|
|
1541
|
-
return partDefs.find(d => {
|
|
367
|
+
return partDefs.find((d) => {
|
|
1542
368
|
return d.typeId === typeId;
|
|
1543
369
|
});
|
|
1544
370
|
}
|
|
@@ -1549,12 +375,12 @@ class LibraryRouteService {
|
|
|
1549
375
|
* @param typeId The part's type ID.
|
|
1550
376
|
* @param roleId The part's role ID.
|
|
1551
377
|
*/
|
|
1552
|
-
getEditorKeyFromPartType(typeId, roleId
|
|
378
|
+
getEditorKeyFromPartType(typeId, roleId) {
|
|
1553
379
|
// find the part type ID
|
|
1554
380
|
const partGroupKey = this._partEditorKeys[typeId];
|
|
1555
381
|
if (!partGroupKey) {
|
|
1556
382
|
return {
|
|
1557
|
-
partKey: 'default'
|
|
383
|
+
partKey: 'default',
|
|
1558
384
|
};
|
|
1559
385
|
}
|
|
1560
386
|
// additionally find the role ID if specified
|
|
@@ -1562,11 +388,11 @@ class LibraryRouteService {
|
|
|
1562
388
|
const reqRoleId = this.stripFragmentRoleId(roleId);
|
|
1563
389
|
return {
|
|
1564
390
|
partKey: partGroupKey.part,
|
|
1565
|
-
frKey: partGroupKey.fragments[reqRoleId]
|
|
391
|
+
frKey: partGroupKey.fragments[reqRoleId],
|
|
1566
392
|
};
|
|
1567
393
|
}
|
|
1568
394
|
return {
|
|
1569
|
-
partKey: partGroupKey.part
|
|
395
|
+
partKey: partGroupKey.part,
|
|
1570
396
|
};
|
|
1571
397
|
}
|
|
1572
398
|
/**
|
|
@@ -1580,13 +406,13 @@ class LibraryRouteService {
|
|
|
1580
406
|
if (i > -1) {
|
|
1581
407
|
return {
|
|
1582
408
|
partKey: key.substr(0, i),
|
|
1583
|
-
frKey: key.substr(i + 1)
|
|
409
|
+
frKey: key.substr(i + 1),
|
|
1584
410
|
};
|
|
1585
411
|
}
|
|
1586
412
|
else {
|
|
1587
413
|
return {
|
|
1588
414
|
partKey: key,
|
|
1589
|
-
frKey: key
|
|
415
|
+
frKey: key,
|
|
1590
416
|
};
|
|
1591
417
|
}
|
|
1592
418
|
}
|
|
@@ -1618,7 +444,7 @@ class LibraryRouteService {
|
|
|
1618
444
|
route = `/items/${itemId}/${editorKey.partKey}/${typeId}/${partId}`;
|
|
1619
445
|
return {
|
|
1620
446
|
route: route,
|
|
1621
|
-
rid: roleId
|
|
447
|
+
rid: roleId,
|
|
1622
448
|
};
|
|
1623
449
|
}
|
|
1624
450
|
/**
|
|
@@ -1641,121 +467,22 @@ class LibraryRouteService {
|
|
|
1641
467
|
route = `/items/${itemId}/${editorKey.frKey}/fragment/${partId}/${frTypeId}/${loc}`;
|
|
1642
468
|
return {
|
|
1643
469
|
route: route,
|
|
1644
|
-
rid: frRoleId
|
|
470
|
+
rid: frRoleId,
|
|
1645
471
|
};
|
|
1646
472
|
}
|
|
1647
473
|
}
|
|
1648
|
-
LibraryRouteService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
1649
|
-
LibraryRouteService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
1650
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
474
|
+
LibraryRouteService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: LibraryRouteService, deps: [{ token: 'partEditorKeys' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
475
|
+
LibraryRouteService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: LibraryRouteService, providedIn: 'root' });
|
|
476
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: LibraryRouteService, decorators: [{
|
|
1651
477
|
type: Injectable,
|
|
1652
478
|
args: [{
|
|
1653
|
-
providedIn: 'root'
|
|
479
|
+
providedIn: 'root',
|
|
1654
480
|
}]
|
|
1655
481
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1656
482
|
type: Inject,
|
|
1657
483
|
args: ['partEditorKeys']
|
|
1658
484
|
}] }]; } });
|
|
1659
485
|
|
|
1660
|
-
class LocalStorageService {
|
|
1661
|
-
/**
|
|
1662
|
-
* Retrieve the object with the specified key from the specified storage.
|
|
1663
|
-
* @param key key.
|
|
1664
|
-
* @param session true to use session instead of local storage.
|
|
1665
|
-
*/
|
|
1666
|
-
retrieve(key, session = false) {
|
|
1667
|
-
const json = session
|
|
1668
|
-
? sessionStorage.getItem(key)
|
|
1669
|
-
: localStorage.getItem(key);
|
|
1670
|
-
if (!json) {
|
|
1671
|
-
return null;
|
|
1672
|
-
}
|
|
1673
|
-
return JSON.parse(json);
|
|
1674
|
-
}
|
|
1675
|
-
/**
|
|
1676
|
-
* Store the specified object with the specified key in the specified storage.
|
|
1677
|
-
* @param key key.
|
|
1678
|
-
* @param value object.
|
|
1679
|
-
* @param session true to use session instead of local storage.
|
|
1680
|
-
*/
|
|
1681
|
-
store(key, value, session = false) {
|
|
1682
|
-
if (session) {
|
|
1683
|
-
sessionStorage.setItem(key, JSON.stringify(value));
|
|
1684
|
-
}
|
|
1685
|
-
else {
|
|
1686
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
/**
|
|
1690
|
-
* Remove the object with the specified key from the specified storage.
|
|
1691
|
-
* @param key key.
|
|
1692
|
-
* @param session true to use session instead of local storage.
|
|
1693
|
-
*/
|
|
1694
|
-
remove(key, session = false) {
|
|
1695
|
-
if (session) {
|
|
1696
|
-
sessionStorage.removeItem(key);
|
|
1697
|
-
}
|
|
1698
|
-
else {
|
|
1699
|
-
localStorage.removeItem(key);
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
/**
|
|
1703
|
-
* Get all the stored entities keys starting with the specified prefix.
|
|
1704
|
-
* @param prefix key prefix.
|
|
1705
|
-
* @param session true to use session instead of local storage.
|
|
1706
|
-
*/
|
|
1707
|
-
getKeys(prefix, session = false) {
|
|
1708
|
-
const keys = [];
|
|
1709
|
-
if (session) {
|
|
1710
|
-
for (let i = 0, len = sessionStorage.length; i < len; i++) {
|
|
1711
|
-
const key = sessionStorage.key(i);
|
|
1712
|
-
if (key.startsWith(prefix)) {
|
|
1713
|
-
keys.push(key);
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
else {
|
|
1718
|
-
for (let i = 0, len = localStorage.length; i < len; i++) {
|
|
1719
|
-
const key = localStorage.key(i);
|
|
1720
|
-
if (key.startsWith(prefix)) {
|
|
1721
|
-
keys.push(key);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
return keys;
|
|
1726
|
-
}
|
|
1727
|
-
/**
|
|
1728
|
-
* Remove all the entries whose key starts with the specified prefix.
|
|
1729
|
-
* @param prefix key prefix.
|
|
1730
|
-
*/
|
|
1731
|
-
clear(prefix, session = false) {
|
|
1732
|
-
if (session) {
|
|
1733
|
-
for (let i = 0, len = sessionStorage.length; i < len; i++) {
|
|
1734
|
-
const key = sessionStorage.key(i);
|
|
1735
|
-
if (key.startsWith(prefix)) {
|
|
1736
|
-
sessionStorage.removeItem(key);
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
else {
|
|
1741
|
-
for (let i = 0, len = localStorage.length; i < len; i++) {
|
|
1742
|
-
const key = localStorage.key(i);
|
|
1743
|
-
if (key.startsWith(prefix)) {
|
|
1744
|
-
localStorage.removeItem(key);
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
LocalStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: LocalStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1751
|
-
LocalStorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: LocalStorageService, providedIn: 'root' });
|
|
1752
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: LocalStorageService, decorators: [{
|
|
1753
|
-
type: Injectable,
|
|
1754
|
-
args: [{
|
|
1755
|
-
providedIn: 'root',
|
|
1756
|
-
}]
|
|
1757
|
-
}] });
|
|
1758
|
-
|
|
1759
486
|
class TextLayerService {
|
|
1760
487
|
constructor() {
|
|
1761
488
|
this._wsRegex = new RegExp('^\\s$', 'g');
|
|
@@ -1838,13 +565,13 @@ class TextLayerService {
|
|
|
1838
565
|
* @param sb The target array.
|
|
1839
566
|
*/
|
|
1840
567
|
renderTokenAtEnd(pt, token, sb) {
|
|
1841
|
-
if (pt.at
|
|
568
|
+
if (pt.at) {
|
|
1842
569
|
// ...to]
|
|
1843
570
|
sb.push(token.substr(pt.at - 1, pt.run));
|
|
1844
571
|
sb.push('</span>');
|
|
1845
572
|
// ...ken
|
|
1846
|
-
if (pt.at - 1 + pt.run < token.length) {
|
|
1847
|
-
sb.push(token.substr(pt.at - 1 + pt.run));
|
|
573
|
+
if (pt.at - 1 + (pt.run || 0) < token.length) {
|
|
574
|
+
sb.push(token.substr(pt.at - 1 + (pt.run || 0)));
|
|
1848
575
|
}
|
|
1849
576
|
}
|
|
1850
577
|
else {
|
|
@@ -1863,7 +590,7 @@ class TextLayerService {
|
|
|
1863
590
|
*/
|
|
1864
591
|
renderTokenAtPointStart(loc, token, sb, isSelected) {
|
|
1865
592
|
// 1.token's left-part
|
|
1866
|
-
if (loc.primary.at
|
|
593
|
+
if (loc.primary.at) {
|
|
1867
594
|
// to...
|
|
1868
595
|
sb.push(token.substr(0, loc.primary.at - 1));
|
|
1869
596
|
}
|
|
@@ -1884,14 +611,14 @@ class TextLayerService {
|
|
|
1884
611
|
*/
|
|
1885
612
|
renderTokenAtRangeStart(loc, token, sb, isSelected) {
|
|
1886
613
|
// 1.token's left-part (=before at)
|
|
1887
|
-
if (loc.primary.at
|
|
614
|
+
if (loc.primary.at) {
|
|
1888
615
|
// to...
|
|
1889
616
|
sb.push(token.substr(0, loc.primary.at - 1));
|
|
1890
617
|
}
|
|
1891
618
|
// 2.span: [
|
|
1892
619
|
this.renderOpeningSpan(loc, 0, sb, isSelected);
|
|
1893
620
|
// 3.token's right-part (...ken or ...token)
|
|
1894
|
-
if (loc.primary.at
|
|
621
|
+
if (loc.primary.at) {
|
|
1895
622
|
// ...ken
|
|
1896
623
|
sb.push(token.substr(loc.primary.at - 1));
|
|
1897
624
|
}
|
|
@@ -1921,14 +648,14 @@ class TextLayerService {
|
|
|
1921
648
|
* fragment if any. The selected fragment gets decorated with an additional
|
|
1922
649
|
* class value.
|
|
1923
650
|
*/
|
|
1924
|
-
render(text, locations, selectedLoc
|
|
651
|
+
render(text, locations, selectedLoc) {
|
|
1925
652
|
if (!text) {
|
|
1926
653
|
return '<div></div>';
|
|
1927
654
|
}
|
|
1928
655
|
// get lines from text
|
|
1929
656
|
const sb = [];
|
|
1930
657
|
const lines = this.getLines(text);
|
|
1931
|
-
let loc =
|
|
658
|
+
let loc = undefined;
|
|
1932
659
|
let tokenSelected = false;
|
|
1933
660
|
if (!locations) {
|
|
1934
661
|
locations = [];
|
|
@@ -1953,7 +680,7 @@ class TextLayerService {
|
|
|
1953
680
|
if (loc && loc.secondary) {
|
|
1954
681
|
if (loc.secondary.y === y + 1 && loc.secondary.x === x + 1) {
|
|
1955
682
|
this.renderTokenAtEnd(loc.secondary, token, sb);
|
|
1956
|
-
loc =
|
|
683
|
+
loc = undefined;
|
|
1957
684
|
}
|
|
1958
685
|
else {
|
|
1959
686
|
sb.push(token);
|
|
@@ -1967,7 +694,7 @@ class TextLayerService {
|
|
|
1967
694
|
if (loc) {
|
|
1968
695
|
tokenSelected = selectedLoc ? loc.overlaps(selectedLoc) : false;
|
|
1969
696
|
if (!this.renderTokenAtStart(loc, token, sb, tokenSelected)) {
|
|
1970
|
-
loc =
|
|
697
|
+
loc = undefined;
|
|
1971
698
|
}
|
|
1972
699
|
}
|
|
1973
700
|
else {
|
|
@@ -1997,7 +724,7 @@ class TextLayerService {
|
|
|
1997
724
|
* Get the Y bounds from the specified selection.
|
|
1998
725
|
* @param range The selection range.
|
|
1999
726
|
* @param forNew True if getting bounds for a new fragment.
|
|
2000
|
-
* @returns Range, inclusive.
|
|
727
|
+
* @returns Range, inclusive, or undefined.
|
|
2001
728
|
*/
|
|
2002
729
|
getYBoundsFromRange(range, forNew) {
|
|
2003
730
|
let p = null;
|
|
@@ -2005,10 +732,10 @@ class TextLayerService {
|
|
|
2005
732
|
case Node.TEXT_NODE:
|
|
2006
733
|
// single-p selection, parent=p
|
|
2007
734
|
p = range.commonAncestorContainer.parentElement;
|
|
2008
|
-
if (forNew && (p
|
|
735
|
+
if (forNew && (p?.nodeName !== 'P' || !p.hasAttribute('id'))) {
|
|
2009
736
|
return null;
|
|
2010
737
|
}
|
|
2011
|
-
if (p
|
|
738
|
+
if (p?.nodeName === 'SPAN') {
|
|
2012
739
|
p = p.parentElement;
|
|
2013
740
|
}
|
|
2014
741
|
const y = parseInt(p.getAttribute('id').substr(1), 10);
|
|
@@ -2052,6 +779,7 @@ class TextLayerService {
|
|
|
2052
779
|
end: yMax,
|
|
2053
780
|
};
|
|
2054
781
|
}
|
|
782
|
+
return null;
|
|
2055
783
|
}
|
|
2056
784
|
locatePrevSpace(line, index) {
|
|
2057
785
|
while (index > -1 && line.charAt(index) !== ' ') {
|
|
@@ -2239,13 +967,14 @@ class TextLayerService {
|
|
|
2239
967
|
*/
|
|
2240
968
|
getNodeBaseOffset(node) {
|
|
2241
969
|
let offset = 0;
|
|
2242
|
-
|
|
2243
|
-
|
|
970
|
+
let n = node;
|
|
971
|
+
n = node.previousSibling;
|
|
972
|
+
while (n) {
|
|
2244
973
|
offset +=
|
|
2245
|
-
|
|
2246
|
-
?
|
|
2247
|
-
:
|
|
2248
|
-
|
|
974
|
+
n.nodeType === Node.ELEMENT_NODE
|
|
975
|
+
? n.innerText?.length || 0
|
|
976
|
+
: n.textContent?.length || 0;
|
|
977
|
+
n = n.previousSibling;
|
|
2249
978
|
}
|
|
2250
979
|
return offset;
|
|
2251
980
|
}
|
|
@@ -2293,7 +1022,7 @@ class TextLayerService {
|
|
|
2293
1022
|
// single token: check for at,run
|
|
2294
1023
|
if (start.at) {
|
|
2295
1024
|
sb.push(`@${start.at}`);
|
|
2296
|
-
if (start.run > 1) {
|
|
1025
|
+
if (start.run && start.run > 1) {
|
|
2297
1026
|
sb.push(`x${start.run}`);
|
|
2298
1027
|
}
|
|
2299
1028
|
}
|
|
@@ -2346,8 +1075,8 @@ class TextLayerService {
|
|
|
2346
1075
|
let inside = false;
|
|
2347
1076
|
if (
|
|
2348
1077
|
// the selected text node must not be child of a span
|
|
2349
|
-
range.startContainer.parentElement
|
|
2350
|
-
range.startContainer.parentElement
|
|
1078
|
+
range.startContainer.parentElement?.tagName === 'SPAN' ||
|
|
1079
|
+
range.startContainer.parentElement?.tagName === 'SPAN' ||
|
|
2351
1080
|
// the nodes tree from the common ancestor, from the start node
|
|
2352
1081
|
// up to the end node, must not include any span
|
|
2353
1082
|
this.findNode(range.commonAncestorContainer, (node) => {
|
|
@@ -2379,7 +1108,7 @@ class TextLayerService {
|
|
|
2379
1108
|
* @param range The selected range. You can get it from the
|
|
2380
1109
|
* current selection using getSelectedRange().
|
|
2381
1110
|
* @param text The full base text.
|
|
2382
|
-
* @returns TokenLocation The token location or
|
|
1111
|
+
* @returns TokenLocation The token location or undefined.
|
|
2383
1112
|
*/
|
|
2384
1113
|
getSelectedLocationForNew(range, text) {
|
|
2385
1114
|
if (!range || this.selHasAnySpan(range)) {
|
|
@@ -2425,9 +1154,9 @@ class TextLayerService {
|
|
|
2425
1154
|
return sel.getRangeAt(0);
|
|
2426
1155
|
}
|
|
2427
1156
|
}
|
|
2428
|
-
TextLayerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
2429
|
-
TextLayerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
2430
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
1157
|
+
TextLayerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TextLayerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1158
|
+
TextLayerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TextLayerService, providedIn: 'root' });
|
|
1159
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TextLayerService, decorators: [{
|
|
2431
1160
|
type: Injectable,
|
|
2432
1161
|
args: [{ providedIn: 'root' }]
|
|
2433
1162
|
}], ctorParameters: function () { return []; } });
|
|
@@ -2493,51 +1222,17 @@ class CadmusValidators {
|
|
|
2493
1222
|
}
|
|
2494
1223
|
}
|
|
2495
1224
|
|
|
2496
|
-
class PasswordValidator {
|
|
2497
|
-
static isValidPassword(control) {
|
|
2498
|
-
if (!control.value) {
|
|
2499
|
-
return null;
|
|
2500
|
-
}
|
|
2501
|
-
if (control.value.length < 8) {
|
|
2502
|
-
return {
|
|
2503
|
-
passwordTooShort: true
|
|
2504
|
-
};
|
|
2505
|
-
}
|
|
2506
|
-
if (!/.*[A-Z].*/.test(control.value)) {
|
|
2507
|
-
return {
|
|
2508
|
-
noUpperInPassword: true
|
|
2509
|
-
};
|
|
2510
|
-
}
|
|
2511
|
-
if (!/.*[a-z].*/.test(control.value)) {
|
|
2512
|
-
return {
|
|
2513
|
-
noLowerInPassword: true
|
|
2514
|
-
};
|
|
2515
|
-
}
|
|
2516
|
-
if (!/.*[A-Z].*/.test(control.value)) {
|
|
2517
|
-
return {
|
|
2518
|
-
noUpperInPassword: true
|
|
2519
|
-
};
|
|
2520
|
-
}
|
|
2521
|
-
if (!/.*[-`~!@#$%^&*()_+=\[\]{};:'",.<>/?|\\].*/.test(control.value)) {
|
|
2522
|
-
return {
|
|
2523
|
-
noSymbolInPassword: true
|
|
2524
|
-
};
|
|
2525
|
-
}
|
|
2526
|
-
return null;
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
|
|
2530
1225
|
class CadmusCoreModule {
|
|
2531
1226
|
}
|
|
2532
|
-
CadmusCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
2533
|
-
CadmusCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0
|
|
2534
|
-
CadmusCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0
|
|
2535
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
1227
|
+
CadmusCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CadmusCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1228
|
+
CadmusCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CadmusCoreModule, declarations: [SortPipe], imports: [CommonModule, HttpClientModule, NgToolsModule], exports: [SortPipe] });
|
|
1229
|
+
CadmusCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CadmusCoreModule, imports: [[CommonModule, HttpClientModule, NgToolsModule]] });
|
|
1230
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CadmusCoreModule, decorators: [{
|
|
2536
1231
|
type: NgModule,
|
|
2537
1232
|
args: [{
|
|
2538
|
-
imports: [CommonModule, HttpClientModule],
|
|
1233
|
+
imports: [CommonModule, HttpClientModule, NgToolsModule],
|
|
2539
1234
|
declarations: [SortPipe],
|
|
2540
|
-
exports: [SortPipe]
|
|
1235
|
+
exports: [SortPipe],
|
|
2541
1236
|
}]
|
|
2542
1237
|
}] });
|
|
2543
1238
|
|
|
@@ -2549,4 +1244,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImpor
|
|
|
2549
1244
|
* Generated bundle index. Do not edit.
|
|
2550
1245
|
*/
|
|
2551
1246
|
|
|
2552
|
-
export { CadmusCoreModule, CadmusValidators,
|
|
1247
|
+
export { CadmusCoreModule, CadmusValidators, DataPinValueType, LibraryRouteService, PendingChangesGuard, SortPipe, TextLayerService, TextRange, TokenLocation, TokenPoint };
|
|
1248
|
+
//# sourceMappingURL=myrmidon-cadmus-core.mjs.map
|