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