@myrmidon/cadmus-core 0.3.0 → 1.1.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.
@@ -1,829 +1,9 @@
1
- import { RomanNumber, NgToolsModule } from '@myrmidon/ng-tools';
2
1
  import * as i0 from '@angular/core';
3
2
  import { Injectable, Pipe, Inject, NgModule } from '@angular/core';
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
- * Default options for formatting a datation.
11
- */
12
- const DATATION_FORMAT_OPTIONS = {
13
- aboutText: 'c.',
14
- bcText: 'BC',
15
- adText: 'AD',
16
- dayNames: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
17
- monthNames: [
18
- 'jan',
19
- 'feb',
20
- 'mar',
21
- 'apr',
22
- 'may',
23
- 'jun',
24
- 'jul',
25
- 'aug',
26
- 'sep',
27
- 'oct',
28
- 'nov',
29
- 'dec',
30
- ],
31
- };
32
- /**
33
- * Single datation point in a historical date.
34
- */
35
- // https://github.com/angular/angular/issues/18867#issuecomment-357484102
36
- // @dynamic
37
- class Datation {
38
- /**
39
- * Create a new datation, optionally setting its data.
40
- * @param datation The optional data to be copied into the newly created datation.
41
- */
42
- constructor(datation) {
43
- this.value = 0;
44
- if (datation) {
45
- this.copyFrom(datation);
46
- }
47
- }
48
- /**
49
- * Sanitize the hint text representing a Datation's hint so that it does not
50
- * include the reserved sequence -- (which gets replaced with Unicode EM
51
- * space U+2014), nor the braces. This is because the double dashes are used
52
- * to separate two datations, and braces to mark a hint in a datation.
53
- * Also, the whitespaces are all flattened to simple spaces, and normalized
54
- * (no whitespaces at start/end and no sequence of whitespaces).
55
- * If the resulting sanitized string is empty, or it was null when received,
56
- * null is returned.
57
- * @param hint The hint or null/undefined.
58
- * @returns The sanitized hint or undefined.
59
- */
60
- static sanitizeHint(hint) {
61
- if (!hint || !hint.trim()) {
62
- return undefined;
63
- }
64
- // replace reserved characters
65
- hint = hint.replace('--', '\u2014');
66
- hint = hint.replace('{', '');
67
- hint = hint.replace('}', '');
68
- // flatten and normalize whitespaces
69
- const s = hint.replace(/\s+/g, ' ').trim();
70
- return s ? s : undefined;
71
- }
72
- static regexEscape(text) {
73
- // https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
74
- return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
75
- }
76
- /**
77
- * Get BC and AD patterns for matching.
78
- * @param options The datation format options.
79
- */
80
- static getErasOptionsForRegex(options = DATATION_FORMAT_OPTIONS) {
81
- return [
82
- options.bcText ? this.regexEscape(options.bcText) : 'BC',
83
- options.adText ? this.regexEscape(options.adText) : 'AD',
84
- ];
85
- }
86
- static getParserRegex(options) {
87
- const bcad = this.getErasOptionsForRegex(options);
88
- return new RegExp(
89
- // about (1)
90
- '(c\\.)?\\s*' +
91
- // day (2)
92
- '(?:([0123]?\\d)\\s+)?' +
93
- // month (3)
94
- '(?:([a-zA-Z]{3,})\\s+)?' +
95
- // year/span (4,5)
96
- '(?:' +
97
- '(?:(\\d+)(?:\\s*/\\s*(\\d+))?)|' +
98
- // century (6)
99
- '([ivxIVX]+)' +
100
- ')\\s*' +
101
- // era (7)
102
- '(' +
103
- bcad[0] +
104
- '|' +
105
- bcad[1] +
106
- ')?' +
107
- // perhaps (8)
108
- '(\\s*\\?)?' +
109
- // hint (9)
110
- '(?:\\s*\\{([^}]+)\\})?', 'i');
111
- }
112
- /**
113
- * Parse the specified text representing a datation.
114
- * @param text The text to be parsed.
115
- * @param options The formatter options.
116
- * @returns The parsed datation, or undefined if invalid or empty.
117
- * Note that here we return undefined to mean a non-existing point.
118
- * We do not want a non-existing point to be represented as a null,
119
- * as this would be included as in the JSON code when serializing.
120
- */
121
- static parse(text, options = DATATION_FORMAT_OPTIONS) {
122
- if (!text) {
123
- return null;
124
- }
125
- const datation = new Datation();
126
- const datationRegex = this.getParserRegex(options);
127
- const m = datationRegex.exec(text);
128
- if (!m) {
129
- return null;
130
- }
131
- // about
132
- if (m[1]) {
133
- datation.isApproximate = true;
134
- }
135
- // day
136
- if (m[2]) {
137
- datation.day = parseInt(m[2], 10);
138
- }
139
- // month
140
- if (m[3]) {
141
- const lowerMonth = m[3].toLowerCase();
142
- const i = options.monthNames.findIndex((name) => name.toLowerCase() === lowerMonth);
143
- if (i > -1) {
144
- datation.month = i + 1;
145
- }
146
- }
147
- // year, span
148
- if (m[4]) {
149
- datation.value = parseInt(m[4], 10);
150
- if (m[5]) {
151
- datation.isSpan = true;
152
- }
153
- }
154
- else {
155
- datation.value = RomanNumber.fromRoman(m[6].toUpperCase());
156
- datation.isCentury = true;
157
- }
158
- // era
159
- if (m[7]) {
160
- const era = m[7].replace(' ', '').toLowerCase();
161
- if (era === options.bcText.toLowerCase()) {
162
- datation.value = -datation.value;
163
- }
164
- }
165
- // dubious
166
- if (m[8]) {
167
- datation.isDubious = true;
168
- }
169
- // hint
170
- if (m[9]) {
171
- datation.hint = Datation.sanitizeHint(m[9]);
172
- }
173
- return datation;
174
- }
175
- /**
176
- * Strip any era code from the specified datation format string.
177
- * @param format The format string.
178
- */
179
- static stripFormatStringEra(format) {
180
- if (!format) {
181
- return 'i';
182
- }
183
- // convert ga gp Ga Gp into simple g G
184
- format = format.replace(new RegExp('([gG])[ap]', 'gi'), '$1');
185
- // replace g/G with i/I
186
- format = format.replace('g', 'i');
187
- format = format.replace('G', 'I');
188
- // remove ea ep Ea Ep with preceding w/W if any
189
- format = format.replace(new RegExp('[wW]?[eE][ap]?', 'gi'), '');
190
- return format;
191
- }
192
- /**
193
- * Reset this datation.
194
- */
195
- reset() {
196
- this.value = 0;
197
- this.isCentury = false;
198
- this.isSpan = false;
199
- this.isApproximate = false;
200
- this.day = 0;
201
- this.month = 0;
202
- this.hint = undefined;
203
- }
204
- /**
205
- * Copy data from the specified source datatation.
206
- * @param datation The source datation.
207
- */
208
- copyFrom(datation) {
209
- this.value = datation.value;
210
- this.isCentury = datation.isCentury;
211
- this.isSpan = datation.isSpan;
212
- this.isApproximate = datation.isApproximate;
213
- this.isDubious = datation.isDubious;
214
- this.day = datation.day;
215
- this.month = datation.month;
216
- this.hint = datation.hint ? datation.hint : undefined;
217
- }
218
- /**
219
- * True if this datation is undefined. A datation is undefined when
220
- * its value is 0. Undefined datations are used as unknown points in a range
221
- * for termini ante/post.
222
- */
223
- isUndefined() {
224
- return !this.value;
225
- }
226
- /**
227
- * Get a sort value from this datation.
228
- */
229
- getSortValue() {
230
- let result;
231
- if (this.isCentury) {
232
- result = this.value * 100 + (this.value < 0 ? 50 : -50);
233
- }
234
- else {
235
- result = this.value;
236
- }
237
- if (this.isSpan) {
238
- result += 0.5;
239
- }
240
- if (this.month && this.month > 0 && this.month <= 12) {
241
- result += this.month / 12;
242
- }
243
- if (this.day && this.day > 0 && this.day <= 31) {
244
- result += this.day / (12 * 31);
245
- }
246
- return result;
247
- }
248
- /**
249
- * Get the 2-years span end value from this datation.
250
- * A span year is always represented with its beginning year: e.g. -776/5
251
- * is -776 with span, and 56/7 is 56 with span. This method returns the end year
252
- * for a span, i.e. in the above samples -775 and 57 respectively. If this datation
253
- * is not a span, the function just returns the unique year value.
254
- */
255
- getSpanEnd() {
256
- if (this.isCentury) {
257
- return 0;
258
- }
259
- return this.isSpan ? this.value + 1 : this.value;
260
- }
261
- /**
262
- * Get the century number corresponding this datation.
263
- * This function returns 0 if the datation is null, or the century number,
264
- * less than 0 if B.C. The result is based on the century value, if
265
- * this is a century datation, or on the year, if this is not a century
266
- * datation (e.g. -5 for 480 B.C., +1 for 31 A.D.).
267
- */
268
- getCentury() {
269
- if (this.value === 0) {
270
- return 0;
271
- }
272
- return this.isCentury
273
- ? this.value
274
- : Math.trunc(this.value / 100 + (this.value < 0 ? -1 : 1));
275
- }
276
- matchTokenAt(token, text, index) {
277
- if (index + token.length > text.length) {
278
- return false;
279
- }
280
- for (let i = 0; i < token.length; i++) {
281
- if (token.charAt(i) !== text.charAt(i + index)) {
282
- return false;
283
- }
284
- }
285
- return true;
286
- }
287
- parseFormatString(format) {
288
- if (!format) {
289
- return ['G'];
290
- }
291
- // expand macros
292
- const macros = [
293
- 'ga',
294
- 'awdwMMMwvwepwpwh',
295
- 'Ga',
296
- 'awdwMMMwvwepwpwh',
297
- 'gp',
298
- 'awdwMMMwvweawpwh',
299
- 'Gp',
300
- 'awdwMMMwvweawpwh',
301
- 'g',
302
- 'awdwMMMwvwewpwh',
303
- 'G',
304
- 'AwdwMMMwVwewPwH',
305
- 'i',
306
- 'awdwMMMwvwpwh',
307
- 'I',
308
- 'AwdwMMMwVwPwH',
309
- ];
310
- const sb = [];
311
- let fi = 0;
312
- let matched;
313
- while (fi < format.length) {
314
- matched = false;
315
- for (let mi = 0; mi < macros.length; mi += 2) {
316
- if (this.matchTokenAt(macros[mi], format, fi)) {
317
- sb.push(macros[mi + 1]);
318
- fi += macros[mi].length;
319
- matched = true;
320
- break;
321
- }
322
- }
323
- if (!matched) {
324
- sb.push(format[fi]);
325
- fi++;
326
- }
327
- }
328
- format = sb.join();
329
- // split into tokens and literals
330
- const tokens = [
331
- 'ddd',
332
- 'MMM',
333
- 'dd',
334
- 'ea',
335
- 'ep',
336
- 'Ea',
337
- 'Ep',
338
- 'ga',
339
- 'Ga',
340
- 'gp',
341
- 'Gp',
342
- 'MM',
343
- ];
344
- fi = 0;
345
- const results = [];
346
- while (fi < format.length) {
347
- matched = false;
348
- for (let ti = 0; ti < tokens.length; ti++) {
349
- if (this.matchTokenAt(tokens[ti], format, fi)) {
350
- results.push(tokens[ti]);
351
- fi += tokens[ti].length;
352
- matched = true;
353
- break;
354
- }
355
- }
356
- if (!matched) {
357
- results.push(format.charAt(fi));
358
- fi++;
359
- }
360
- }
361
- return results;
362
- }
363
- /**
364
- * Convert this datation to a string.
365
- * @param format The format string, which can include any of the following:
366
- * v = year or century value, lowercase
367
- * V = year or century value, uppercase
368
- * c = century, lowercase
369
- * C = century, uppercase
370
- * a or A = 'about' marker when present
371
- * p or P = 'perhaps' marker when present
372
- * d = day number when present
373
- * dd = 2-digits (0-padded at left) day number when present
374
- * ddd = weekday name when present
375
- * M = month number when present
376
- * MM = 2-digits (0-padded at left) month number when present
377
- * MMM = month name when present
378
- * e = era
379
- * E = era, all uppercase
380
- * ea = era, only if ante Christum natum
381
- * ep = era, only if post Christum natum
382
- * Ea = era all uppercase, only if ante Christum natum
383
- * Ep = era all uppercase, only if post Christum natum
384
- * h or H = hint when present
385
- * w or W = smart whitespace (appended only when left char if any
386
- * is not a whitespace)
387
- * s or S = sort value
388
- * g = generic: equal to awdwMMMwvwewpwh
389
- * G = generic uppercase: equal to AwdwMMMwVwewPwH
390
- * ga = generic ante Christum: era expressed only when post Christum
391
- * natum. Equal to awdwMMMwvwepwpwh
392
- * Ga = generic uppercase ante Christum: equal to awdwMMMwvwepwpwh
393
- * gp = generic post Christum: era expressed only when ante Christum
394
- * natum. Equal to awdwMMMwvweawpwh
395
- * Gp = generic uppercase post Christum: equal to awdwMMMwvweawpwh
396
- * i = generic with implicit (=not expressed) era: equal to awdwMMMwvwpwh
397
- * I = generic uppercase with implicit (=not expressed) era: equal to
398
- * AwdwMMMwVwPwH
399
- * @param options The options.
400
- */
401
- toString(format = 'G', options = DATATION_FORMAT_OPTIONS) {
402
- if (this.isUndefined()) {
403
- return '';
404
- }
405
- if (!format) {
406
- format = 'G';
407
- }
408
- if (!options) {
409
- options = DATATION_FORMAT_OPTIONS;
410
- }
411
- const sb = [];
412
- const tokens = this.parseFormatString(format);
413
- tokens.forEach((token) => {
414
- switch (token) {
415
- case 'v':
416
- case 'V':
417
- // year or century
418
- if (this.isCentury) {
419
- sb.push(token === 'v'
420
- ? RomanNumber.toRoman(Math.abs(this.value)).toLowerCase()
421
- : RomanNumber.toRoman(Math.abs(this.value)).toUpperCase());
422
- }
423
- else {
424
- const year = Math.abs(this.value);
425
- sb.push(year.toString());
426
- if (this.isSpan) {
427
- sb.push(`/${year + (this.value < 0 ? -1 : +1)}`);
428
- }
429
- }
430
- break;
431
- case 'c':
432
- case 'C':
433
- const century = Math.abs(this.getCentury());
434
- sb.push(token === 'c'
435
- ? RomanNumber.toRoman(century).toLowerCase()
436
- : RomanNumber.toRoman(century).toUpperCase());
437
- break;
438
- case 'a':
439
- case 'A':
440
- if (this.isApproximate) {
441
- sb.push(options.aboutText);
442
- }
443
- break;
444
- case 'p':
445
- case 'P':
446
- if (this.isDubious) {
447
- sb.push('?');
448
- }
449
- break;
450
- case 'd':
451
- if (this.day) {
452
- sb.push(this.day.toString());
453
- }
454
- break;
455
- case 'dd':
456
- if (this.day) {
457
- sb.push(this.day.toString().padStart(2, '0'));
458
- }
459
- break;
460
- case 'ddd':
461
- if (this.month && this.day) {
462
- const date = new Date(this.value, this.month, this.day);
463
- const dow = date.getDay();
464
- sb.push(options.dayNames[dow]);
465
- }
466
- break;
467
- case 'M':
468
- if (this.month) {
469
- sb.push(this.month.toString());
470
- }
471
- break;
472
- case 'MM':
473
- if (this.month) {
474
- sb.push(this.month.toString().padStart(2, '0'));
475
- }
476
- break;
477
- case 'MMM':
478
- if (this.month) {
479
- sb.push(options.monthNames[this.month - 1]);
480
- }
481
- break;
482
- case 'e':
483
- sb.push(this.value < 0 ? options.bcText : options.adText);
484
- break;
485
- case 'E':
486
- sb.push(this.value < 0
487
- ? options.bcText.toUpperCase()
488
- : options.adText.toUpperCase());
489
- break;
490
- case 'ea':
491
- if (this.value < 0) {
492
- sb.push(options.bcText);
493
- }
494
- break;
495
- case 'ep':
496
- if (this.value > 0) {
497
- sb.push(options.adText);
498
- }
499
- break;
500
- case 'h':
501
- case 'H':
502
- if (this.hint) {
503
- sb.push(` {${this.hint}}`);
504
- }
505
- break;
506
- case 'w':
507
- case 'W':
508
- if (sb.length > 0) {
509
- const last = sb[sb.length - 1];
510
- if (!last.endsWith(' ')) {
511
- sb.push(' ');
512
- }
513
- }
514
- break;
515
- case 's':
516
- case 'S':
517
- sb.push(this.getSortValue().toString());
518
- break;
519
- default:
520
- // literal
521
- sb.push(token);
522
- break;
523
- }
524
- });
525
- return sb.join('').trim().replace(new RegExp('\\s+', 'g'), ' ');
526
- }
527
- }
528
-
529
- const APPROX_DELTA = 10;
530
- /**
531
- * Type of historical date.
532
- */
533
- var HistoricalDateType;
534
- (function (HistoricalDateType) {
535
- HistoricalDateType[HistoricalDateType["undefined"] = 0] = "undefined";
536
- HistoricalDateType[HistoricalDateType["point"] = 1] = "point";
537
- HistoricalDateType[HistoricalDateType["range"] = 2] = "range";
538
- })(HistoricalDateType || (HistoricalDateType = {}));
539
- /**
540
- * A historical date, including 0, 1, or 2 datation points.
541
- */
542
- class HistoricalDate {
543
- constructor(date) {
544
- if (!date) {
545
- this.a = new Datation();
546
- // B=undefined for a single point
547
- }
548
- else {
549
- this.a = new Datation(date.a);
550
- if (date.b) {
551
- this.b = new Datation(date.b);
552
- }
553
- }
554
- }
555
- /**
556
- * Parse the specified text representing a historical datation.
557
- * @param text The text to be parsed.
558
- * @param options The datation formatter options.
559
- * @return The datation, or undefined if invalid.
560
- */
561
- static parse(text, options = DATATION_FORMAT_OPTIONS) {
562
- if (!text) {
563
- return null;
564
- }
565
- const dates = text.split('--');
566
- let s1 = dates[0].trim();
567
- const s2 = dates.length > 1 ? dates[1].trim() : null;
568
- const date = new HistoricalDate();
569
- if (dates.length > 1) {
570
- // if both terms are specified, integrate BC/AD indication in 1st if required
571
- if (s1 && s2) {
572
- const bcad = Datation.getErasOptionsForRegex(options);
573
- const tailRegexp = new RegExp(
574
- // era (1)
575
- '(' +
576
- bcad[0] +
577
- '|' +
578
- bcad[1] +
579
- ')?' +
580
- // dubious (2)
581
- '(\\s*\\?)?' +
582
- // hint (3)
583
- '(?:\\s*\\{?:([^)]+)\\})?\\s*$', 'gi');
584
- const m1 = tailRegexp.exec(s1);
585
- // if 1st has no era try integration from 2nd
586
- if (m1 && m1[1] && s2) {
587
- // get era from 2nd (if 2nd hasn't it too, give up and AD will be assumed)
588
- const m2 = tailRegexp.exec(s2);
589
- if (m2 && m2[1]) {
590
- const era = m2[1] || 'p.C.';
591
- const sb1 = [];
592
- if (m1.index > 0) {
593
- sb1.push(s1.substr(0, m1.index));
594
- }
595
- sb1.push(' ' + era);
596
- if (m1[2]) {
597
- sb1.push('?');
598
- }
599
- if (m1[3]) {
600
- sb1.push(` (${m1[3]})`);
601
- }
602
- s1 = sb1.join('');
603
- }
604
- }
605
- }
606
- date.setStartPoint(Datation.parse(s1, options));
607
- if (s2) {
608
- date.setEndPoint(Datation.parse(s2, options));
609
- }
610
- }
611
- else {
612
- // here we have a s2, even if empty. When empty, it represents
613
- // an unknown point in a terminus ante/post, and as such we
614
- // must set B=null. When B=undefined, it's not a range but a point.
615
- const d = Datation.parse(s1, options);
616
- if (d && !d.isUndefined()) {
617
- date.setSinglePoint(d);
618
- }
619
- }
620
- return date;
621
- }
622
- getStartPoint() {
623
- return this.getDateType() === HistoricalDateType.range ? this.a : undefined;
624
- }
625
- setStartPoint(value) {
626
- this.a = new Datation(value);
627
- // it's a range, ensure max is not null
628
- if (!this.b) {
629
- this.b = new Datation();
630
- }
631
- }
632
- getEndPoint() {
633
- return this.getDateType() === HistoricalDateType.range ? this.b : undefined;
634
- }
635
- setEndPoint(value) {
636
- this.b = new Datation(value);
637
- }
638
- getSinglePoint() {
639
- return this.getDateType() === HistoricalDateType.point ? this.a : undefined;
640
- }
641
- setSinglePoint(value) {
642
- this.a = new Datation(value);
643
- // it's a point, ensure max is undefined
644
- this.b = undefined;
645
- }
646
- /**
647
- * True if this date is undefined.
648
- */
649
- isUndefined() {
650
- return (!this.a || (this.a.isUndefined() && (!this.b || this.b.isUndefined())));
651
- }
652
- /**
653
- * Get the type of this date.
654
- */
655
- getDateType() {
656
- if (this.isUndefined()) {
657
- return HistoricalDateType.undefined;
658
- }
659
- return this.b ? HistoricalDateType.range : HistoricalDateType.point;
660
- }
661
- /**
662
- * Validate this date.
663
- * @returns Error message if invalid, or null if valid.
664
- */
665
- validate() {
666
- var _a;
667
- if (!this.a) {
668
- return 'Missing point A';
669
- }
670
- if (this.getDateType() === HistoricalDateType.range) {
671
- const av = this.a.getSortValue();
672
- const bv = ((_a = this.b) === null || _a === void 0 ? void 0 : _a.getSortValue()) || 0;
673
- if (av && bv && av >= bv) {
674
- return 'Point A is past point B';
675
- }
676
- }
677
- return null;
678
- }
679
- /**
680
- * Get the sort value for this date.
681
- */
682
- getSortValue() {
683
- switch (this.getDateType()) {
684
- case HistoricalDateType.point:
685
- return this.a.getSortValue();
686
- case HistoricalDateType.range:
687
- if (this.a.isUndefined()) {
688
- return this.b.getSortValue() - APPROX_DELTA;
689
- }
690
- if (!this.b || this.b.isUndefined()) {
691
- return this.a.getSortValue() + APPROX_DELTA;
692
- }
693
- return (this.a.getSortValue() + this.b.getSortValue()) / 2;
694
- default:
695
- return 0;
696
- }
697
- }
698
- /**
699
- * Build a textual representation of this date.
700
- * @param format The format string.
701
- * @param options The formatter options.
702
- */
703
- toString(format = 'G', options = DATATION_FORMAT_OPTIONS) {
704
- const sb = [];
705
- switch (this.getDateType()) {
706
- case HistoricalDateType.point:
707
- sb.push(this.a.toString(format, options));
708
- break;
709
- case HistoricalDateType.range:
710
- // if both terms are present and belong to same era, omit it in 1st
711
- if (!this.a.isUndefined() &&
712
- this.b &&
713
- !this.b.isUndefined() &&
714
- this.a.value * this.b.value > 0) {
715
- sb.push(this.a.toString(Datation.stripFormatStringEra(format), options));
716
- sb.push(' -- ');
717
- sb.push(this.b.toString(format, options));
718
- break;
719
- }
720
- if (!this.a.isUndefined()) {
721
- sb.push(this.a.toString(format, options) + ' ');
722
- }
723
- sb.push('--');
724
- if (this.b && !this.b.isUndefined()) {
725
- sb.push(this.b.toString(format, options));
726
- }
727
- break;
728
- }
729
- return sb.join('');
730
- }
731
- /**
732
- * Get the approximate year value from the specified century value.
733
- * @param century The century number, negative if B.C.
734
- */
735
- centuryToYear(century) {
736
- return century * 100 + (century < 0 ? 50 : -50);
737
- }
738
- /**
739
- * Convert this date into a single approximate year value.
740
- * For centuries, the central century year is returned (e.g. -350 for IV B.C.
741
- * and +350 for IV A.D.); when the date is a range with a single boundary only
742
- * (max or min) the corresponding year minus or plus a predefined delta value
743
- * (10) is returned; if it's a range with both boundaries (max and min),
744
- * the middle year between them is returned.
745
- * @param useTerminusSpan True to add or remove the predefined span from
746
- * a terminus ante or post.
747
- */
748
- toYear(useTerminusSpan = true) {
749
- let year = 0;
750
- switch (this.getDateType()) {
751
- case HistoricalDateType.point:
752
- year = Math.trunc(this.a.isCentury ? this.centuryToYear(this.a.value) : this.a.value);
753
- break;
754
- case HistoricalDateType.range:
755
- // min is missing: terminus ante
756
- if (this.a.isUndefined() && this.b) {
757
- year = Math.trunc((this.b.isCentury
758
- ? this.centuryToYear(this.b.value)
759
- : this.b.value) - (useTerminusSpan ? APPROX_DELTA : 0));
760
- break;
761
- }
762
- // max is missing: terminus post
763
- if (!this.b || this.b.isUndefined()) {
764
- year = Math.trunc((this.a.isCentury
765
- ? this.centuryToYear(this.a.value)
766
- : this.a.value) + (useTerminusSpan ? APPROX_DELTA : 0));
767
- break;
768
- }
769
- // both min and max
770
- const min = this.a.isCentury
771
- ? this.centuryToYear(this.a.value)
772
- : this.a.value;
773
- const max = this.b.isCentury
774
- ? this.centuryToYear(this.b.value)
775
- : this.b.value;
776
- year = Math.trunc((max - min) / 2 + min);
777
- if (year === 0) {
778
- year = 1;
779
- }
780
- break;
781
- }
782
- return year;
783
- }
784
- /**
785
- * True if any value (either in point or in range) has an about flag.
786
- */
787
- isAbout() {
788
- let about = false;
789
- switch (this.getDateType()) {
790
- case HistoricalDateType.point:
791
- about = this.a.isApproximate;
792
- break;
793
- case HistoricalDateType.range:
794
- if (!this.a.isUndefined()) {
795
- about = this.a.isApproximate;
796
- break;
797
- }
798
- if (this.b && !this.b.isUndefined()) {
799
- about = this.b.isApproximate;
800
- }
801
- break;
802
- }
803
- return about ? true : false;
804
- }
805
- /**
806
- * True if any value (either in point or in range) has an about flag.
807
- */
808
- isDubious() {
809
- let dubious = false;
810
- switch (this.getDateType()) {
811
- case HistoricalDateType.point:
812
- dubious = this.a.isDubious;
813
- break;
814
- case HistoricalDateType.range:
815
- if (!this.a.isUndefined()) {
816
- dubious = this.a.isDubious;
817
- break;
818
- }
819
- if (this.b && !this.b.isUndefined()) {
820
- dubious = this.b.isDubious;
821
- }
822
- break;
823
- }
824
- return dubious ? true : false;
825
- }
826
- }
6
+ import { NgToolsModule } from '@myrmidon/ng-tools';
827
7
 
828
8
  /**
829
9
  * Data pin value type in a DataPinDefinition.
@@ -1045,9 +225,9 @@ class PendingChangesGuard {
1045
225
  'Press Cancel to go back and save, OK to continue.');
1046
226
  }
1047
227
  }
1048
- PendingChangesGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: PendingChangesGuard, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1049
- PendingChangesGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: PendingChangesGuard, providedIn: 'root' });
1050
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: PendingChangesGuard, decorators: [{
228
+ PendingChangesGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: PendingChangesGuard, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
229
+ PendingChangesGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: PendingChangesGuard, providedIn: 'root' });
230
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: PendingChangesGuard, decorators: [{
1051
231
  type: Injectable,
1052
232
  args: [{
1053
233
  providedIn: 'root',
@@ -1085,42 +265,15 @@ class SortPipe {
1085
265
  });
1086
266
  }
1087
267
  }
1088
- SortPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: SortPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1089
- SortPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: SortPipe, name: "sort" });
1090
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: SortPipe, decorators: [{
268
+ SortPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: SortPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
269
+ SortPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: SortPipe, name: "sort" });
270
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: SortPipe, decorators: [{
1091
271
  type: Pipe,
1092
272
  args: [{
1093
273
  name: 'sort',
1094
274
  }]
1095
275
  }] });
1096
276
 
1097
- // npm i gravatar --save
1098
- // npm i @types/gravatar --save
1099
- class GravatarService {
1100
- /**
1101
- * Builds the URL to the Gravatar avatar corresponding to the specified email
1102
- * address.
1103
- * @param email: The email address.
1104
- * @param size The required size in pixels (1-512).
1105
- */
1106
- buildGravatarUrl(email, size = 80) {
1107
- if (!email) {
1108
- return '';
1109
- }
1110
- return gravatar.url(email, { s: size.toString() });
1111
- // const hash = this._hash.getMd5(email.trim().toLowerCase());
1112
- // return this.buildGravatarUrlFromHash(hash, size);
1113
- }
1114
- }
1115
- GravatarService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: GravatarService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1116
- GravatarService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: GravatarService, providedIn: 'root' });
1117
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: GravatarService, decorators: [{
1118
- type: Injectable,
1119
- args: [{
1120
- providedIn: 'root'
1121
- }]
1122
- }] });
1123
-
1124
277
  /**
1125
278
  * Library route service.
1126
279
  * This service is used to build routes to part and fragment editors,
@@ -1318,9 +471,9 @@ class LibraryRouteService {
1318
471
  };
1319
472
  }
1320
473
  }
1321
- LibraryRouteService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: LibraryRouteService, deps: [{ token: 'partEditorKeys' }], target: i0.ɵɵFactoryTarget.Injectable });
1322
- LibraryRouteService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: LibraryRouteService, providedIn: 'root' });
1323
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: LibraryRouteService, decorators: [{
474
+ LibraryRouteService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: LibraryRouteService, deps: [{ token: 'partEditorKeys' }], target: i0.ɵɵFactoryTarget.Injectable });
475
+ LibraryRouteService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: LibraryRouteService, providedIn: 'root' });
476
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: LibraryRouteService, decorators: [{
1324
477
  type: Injectable,
1325
478
  args: [{
1326
479
  providedIn: 'root',
@@ -2005,9 +1158,9 @@ class TextLayerService {
2005
1158
  return sel.getRangeAt(0);
2006
1159
  }
2007
1160
  }
2008
- TextLayerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TextLayerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2009
- TextLayerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TextLayerService, providedIn: 'root' });
2010
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TextLayerService, decorators: [{
1161
+ TextLayerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: TextLayerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1162
+ TextLayerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: TextLayerService, providedIn: 'root' });
1163
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: TextLayerService, decorators: [{
2011
1164
  type: Injectable,
2012
1165
  args: [{ providedIn: 'root' }]
2013
1166
  }], ctorParameters: function () { return []; } });
@@ -2073,46 +1226,12 @@ class CadmusValidators {
2073
1226
  }
2074
1227
  }
2075
1228
 
2076
- class PasswordValidator {
2077
- static isValidPassword(control) {
2078
- if (!control.value) {
2079
- return null;
2080
- }
2081
- if (control.value.length < 8) {
2082
- return {
2083
- passwordTooShort: true,
2084
- };
2085
- }
2086
- if (!/.*[A-Z].*/.test(control.value)) {
2087
- return {
2088
- noUpperInPassword: true,
2089
- };
2090
- }
2091
- if (!/.*[a-z].*/.test(control.value)) {
2092
- return {
2093
- noLowerInPassword: true,
2094
- };
2095
- }
2096
- if (!/.*[A-Z].*/.test(control.value)) {
2097
- return {
2098
- noUpperInPassword: true,
2099
- };
2100
- }
2101
- if (!/.*[-`~!@#$%^&*()_+=\[\]{};:'",.<>/?|\\].*/.test(control.value)) {
2102
- return {
2103
- noSymbolInPassword: true,
2104
- };
2105
- }
2106
- return null;
2107
- }
2108
- }
2109
-
2110
1229
  class CadmusCoreModule {
2111
1230
  }
2112
- CadmusCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: CadmusCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2113
- CadmusCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: CadmusCoreModule, declarations: [SortPipe], imports: [CommonModule, HttpClientModule, NgToolsModule], exports: [SortPipe] });
2114
- CadmusCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: CadmusCoreModule, imports: [[CommonModule, HttpClientModule, NgToolsModule]] });
2115
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: CadmusCoreModule, decorators: [{
1231
+ CadmusCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CadmusCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1232
+ CadmusCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: CadmusCoreModule, declarations: [SortPipe], imports: [CommonModule, HttpClientModule, NgToolsModule], exports: [SortPipe] });
1233
+ CadmusCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CadmusCoreModule, imports: [CommonModule, HttpClientModule, NgToolsModule] });
1234
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CadmusCoreModule, decorators: [{
2116
1235
  type: NgModule,
2117
1236
  args: [{
2118
1237
  imports: [CommonModule, HttpClientModule, NgToolsModule],
@@ -2129,4 +1248,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
2129
1248
  * Generated bundle index. Do not edit.
2130
1249
  */
2131
1250
 
2132
- export { CadmusCoreModule, CadmusValidators, DATATION_FORMAT_OPTIONS, DataPinValueType, Datation, GravatarService, HistoricalDate, HistoricalDateType, LibraryRouteService, PasswordValidator, PendingChangesGuard, SortPipe, TextLayerService, TextRange, TokenLocation, TokenPoint };
1251
+ export { CadmusCoreModule, CadmusValidators, DataPinValueType, LibraryRouteService, PendingChangesGuard, SortPipe, TextLayerService, TextRange, TokenLocation, TokenPoint };
1252
+ //# sourceMappingURL=myrmidon-cadmus-core.mjs.map