@myrmidon/cadmus-core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,7 +39,8 @@ class Datation {
39
39
  * Create a new datation, optionally setting its data.
40
40
  * @param datation The optional data to be copied into the newly created datation.
41
41
  */
42
- constructor(datation = null) {
42
+ constructor(datation) {
43
+ this.value = 0;
43
44
  if (datation) {
44
45
  this.copyFrom(datation);
45
46
  }
@@ -119,13 +120,13 @@ class Datation {
119
120
  */
120
121
  static parse(text, options = DATATION_FORMAT_OPTIONS) {
121
122
  if (!text) {
122
- return undefined;
123
+ return null;
123
124
  }
124
125
  const datation = new Datation();
125
126
  const datationRegex = this.getParserRegex(options);
126
127
  const m = datationRegex.exec(text);
127
128
  if (!m) {
128
- return undefined;
129
+ return null;
129
130
  }
130
131
  // about
131
132
  if (m[1]) {
@@ -236,10 +237,10 @@ class Datation {
236
237
  if (this.isSpan) {
237
238
  result += 0.5;
238
239
  }
239
- if (this.month > 0 && this.month <= 12) {
240
+ if (this.month && this.month > 0 && this.month <= 12) {
240
241
  result += this.month / 12;
241
242
  }
242
- if (this.day > 0 && this.day <= 31) {
243
+ if (this.day && this.day > 0 && this.day <= 31) {
243
244
  result += this.day / (12 * 31);
244
245
  }
245
246
  return result;
@@ -447,34 +448,34 @@ class Datation {
447
448
  }
448
449
  break;
449
450
  case 'd':
450
- if (this.day > 0) {
451
+ if (this.day) {
451
452
  sb.push(this.day.toString());
452
453
  }
453
454
  break;
454
455
  case 'dd':
455
- if (this.day > 0) {
456
+ if (this.day) {
456
457
  sb.push(this.day.toString().padStart(2, '0'));
457
458
  }
458
459
  break;
459
460
  case 'ddd':
460
- if (this.day > 0) {
461
+ if (this.month && this.day) {
461
462
  const date = new Date(this.value, this.month, this.day);
462
463
  const dow = date.getDay();
463
464
  sb.push(options.dayNames[dow]);
464
465
  }
465
466
  break;
466
467
  case 'M':
467
- if (this.month > 0) {
468
+ if (this.month) {
468
469
  sb.push(this.month.toString());
469
470
  }
470
471
  break;
471
472
  case 'MM':
472
- if (this.month > 0) {
473
+ if (this.month) {
473
474
  sb.push(this.month.toString().padStart(2, '0'));
474
475
  }
475
476
  break;
476
477
  case 'MMM':
477
- if (this.month > 0) {
478
+ if (this.month) {
478
479
  sb.push(options.monthNames[this.month - 1]);
479
480
  }
480
481
  break;
@@ -539,7 +540,7 @@ var HistoricalDateType;
539
540
  * A historical date, including 0, 1, or 2 datation points.
540
541
  */
541
542
  class HistoricalDate {
542
- constructor(date = null) {
543
+ constructor(date) {
543
544
  if (!date) {
544
545
  this.a = new Datation();
545
546
  // B=undefined for a single point
@@ -555,7 +556,7 @@ class HistoricalDate {
555
556
  * Parse the specified text representing a historical datation.
556
557
  * @param text The text to be parsed.
557
558
  * @param options The datation formatter options.
558
- * @return The datation, or null if invalid.
559
+ * @return The datation, or undefined if invalid.
559
560
  */
560
561
  static parse(text, options = DATATION_FORMAT_OPTIONS) {
561
562
  if (!text) {
@@ -582,7 +583,7 @@ class HistoricalDate {
582
583
  '(?:\\s*\\{?:([^)]+)\\})?\\s*$', 'gi');
583
584
  const m1 = tailRegexp.exec(s1);
584
585
  // if 1st has no era try integration from 2nd
585
- if (m1 && m1[1]) {
586
+ if (m1 && m1[1] && s2) {
586
587
  // get era from 2nd (if 2nd hasn't it too, give up and AD will be assumed)
587
588
  const m2 = tailRegexp.exec(s2);
588
589
  if (m2 && m2[1]) {
@@ -603,7 +604,9 @@ class HistoricalDate {
603
604
  }
604
605
  }
605
606
  date.setStartPoint(Datation.parse(s1, options));
606
- date.setEndPoint(Datation.parse(s2, options));
607
+ if (s2) {
608
+ date.setEndPoint(Datation.parse(s2, options));
609
+ }
607
610
  }
608
611
  else {
609
612
  // here we have a s2, even if empty. When empty, it represents
@@ -660,12 +663,13 @@ class HistoricalDate {
660
663
  * @returns Error message if invalid, or null if valid.
661
664
  */
662
665
  validate() {
666
+ var _a;
663
667
  if (!this.a) {
664
668
  return 'Missing point A';
665
669
  }
666
670
  if (this.getDateType() === HistoricalDateType.range) {
667
671
  const av = this.a.getSortValue();
668
- const bv = this.b.getSortValue();
672
+ const bv = ((_a = this.b) === null || _a === void 0 ? void 0 : _a.getSortValue()) || 0;
669
673
  if (av && bv && av >= bv) {
670
674
  return 'Point A is past point B';
671
675
  }
@@ -683,7 +687,7 @@ class HistoricalDate {
683
687
  if (this.a.isUndefined()) {
684
688
  return this.b.getSortValue() - APPROX_DELTA;
685
689
  }
686
- if (this.b.isUndefined()) {
690
+ if (!this.b || this.b.isUndefined()) {
687
691
  return this.a.getSortValue() + APPROX_DELTA;
688
692
  }
689
693
  return (this.a.getSortValue() + this.b.getSortValue()) / 2;
@@ -749,7 +753,7 @@ class HistoricalDate {
749
753
  break;
750
754
  case HistoricalDateType.range:
751
755
  // min is missing: terminus ante
752
- if (this.a.isUndefined()) {
756
+ if (this.a.isUndefined() && this.b) {
753
757
  year = Math.trunc((this.b.isCentury
754
758
  ? this.centuryToYear(this.b.value)
755
759
  : this.b.value) - (useTerminusSpan ? APPROX_DELTA : 0));
@@ -791,12 +795,12 @@ class HistoricalDate {
791
795
  about = this.a.isApproximate;
792
796
  break;
793
797
  }
794
- if (!this.b.isUndefined()) {
798
+ if (this.b && !this.b.isUndefined()) {
795
799
  about = this.b.isApproximate;
796
800
  }
797
801
  break;
798
802
  }
799
- return about;
803
+ return about ? true : false;
800
804
  }
801
805
  /**
802
806
  * True if any value (either in point or in range) has an about flag.
@@ -812,12 +816,12 @@ class HistoricalDate {
812
816
  dubious = this.a.isDubious;
813
817
  break;
814
818
  }
815
- if (!this.b.isUndefined()) {
819
+ if (this.b && !this.b.isUndefined()) {
816
820
  dubious = this.b.isDubious;
817
821
  }
818
822
  break;
819
823
  }
820
- return dubious;
824
+ return dubious ? true : false;
821
825
  }
822
826
  }
823
827
 
@@ -924,7 +928,7 @@ class TokenPoint {
924
928
  }
925
929
  toString() {
926
930
  let s = `${this.y}.${this.x}`;
927
- if (this.at > 0 && this.run > 0) {
931
+ if (this.at && this.run) {
928
932
  s += `@${this.at}`;
929
933
  if (this.run !== 1) {
930
934
  s += `x${this.run}`;
@@ -956,7 +960,7 @@ class TokenPoint {
956
960
  }
957
961
 
958
962
  class TokenLocation {
959
- constructor(primary, secondary = null) {
963
+ constructor(primary, secondary) {
960
964
  this.primary = primary;
961
965
  this.secondary = secondary;
962
966
  }
@@ -975,7 +979,7 @@ class TokenLocation {
975
979
  if (pair.length === 0) {
976
980
  return null;
977
981
  }
978
- return new TokenLocation(TokenPoint.parse(pair[0]), pair.length > 1 ? TokenPoint.parse(pair[1]) : null);
982
+ return new TokenLocation(TokenPoint.parse(pair[0]), pair.length > 1 ? TokenPoint.parse(pair[1]) || undefined : undefined);
979
983
  }
980
984
  isRange() {
981
985
  // note that != checks for both null and undefined, whereas !== does not
@@ -1046,7 +1050,7 @@ PendingChangesGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0",
1046
1050
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: PendingChangesGuard, decorators: [{
1047
1051
  type: Injectable,
1048
1052
  args: [{
1049
- providedIn: 'root'
1053
+ providedIn: 'root',
1050
1054
  }]
1051
1055
  }] });
1052
1056
 
@@ -1077,6 +1081,7 @@ class SortPipe {
1077
1081
  else if (a[propName] > b[propName]) {
1078
1082
  return 1;
1079
1083
  }
1084
+ return 0;
1080
1085
  });
1081
1086
  }
1082
1087
  }
@@ -1100,7 +1105,7 @@ class GravatarService {
1100
1105
  */
1101
1106
  buildGravatarUrl(email, size = 80) {
1102
1107
  if (!email) {
1103
- return null;
1108
+ return '';
1104
1109
  }
1105
1110
  return gravatar.url(email, { s: size.toString() });
1106
1111
  // const hash = this._hash.getMd5(email.trim().toLowerCase());
@@ -1173,13 +1178,13 @@ class LibraryRouteService {
1173
1178
  if (i > -1) {
1174
1179
  return {
1175
1180
  frTypeId: roleId.substring(0, i),
1176
- frRoleId: roleId.substring(i + 1)
1181
+ frRoleId: roleId.substring(i + 1),
1177
1182
  };
1178
1183
  }
1179
1184
  else {
1180
1185
  return {
1181
1186
  frTypeId: roleId,
1182
- frRoleId: null
1187
+ frRoleId: undefined,
1183
1188
  };
1184
1189
  }
1185
1190
  }
@@ -1190,22 +1195,23 @@ class LibraryRouteService {
1190
1195
  * @param partDefs The parts definitions.
1191
1196
  * @param typeId The type ID.
1192
1197
  * @param roleId The role ID or null.
1193
- * @returns Part definition or null if not found.
1198
+ * @returns Part definition or undefined if not found.
1194
1199
  */
1195
1200
  findPartDefinition(partDefs, typeId, roleId = null) {
1196
1201
  if (!partDefs) {
1197
- return null;
1202
+ return undefined;
1198
1203
  }
1199
1204
  // if role ID is specified, find both type and role
1200
1205
  if (roleId) {
1201
1206
  const reqRoleId = this.stripFragmentRoleId(roleId);
1202
- return partDefs.find(d => {
1207
+ return partDefs.find((d) => {
1203
1208
  return (d.typeId === typeId &&
1209
+ d.roleId &&
1204
1210
  this.stripFragmentRoleId(d.roleId) === reqRoleId);
1205
1211
  });
1206
1212
  }
1207
1213
  // else just find type ID
1208
- return partDefs.find(d => {
1214
+ return partDefs.find((d) => {
1209
1215
  return d.typeId === typeId;
1210
1216
  });
1211
1217
  }
@@ -1216,12 +1222,12 @@ class LibraryRouteService {
1216
1222
  * @param typeId The part's type ID.
1217
1223
  * @param roleId The part's role ID.
1218
1224
  */
1219
- getEditorKeyFromPartType(typeId, roleId = null) {
1225
+ getEditorKeyFromPartType(typeId, roleId) {
1220
1226
  // find the part type ID
1221
1227
  const partGroupKey = this._partEditorKeys[typeId];
1222
1228
  if (!partGroupKey) {
1223
1229
  return {
1224
- partKey: 'default'
1230
+ partKey: 'default',
1225
1231
  };
1226
1232
  }
1227
1233
  // additionally find the role ID if specified
@@ -1229,11 +1235,11 @@ class LibraryRouteService {
1229
1235
  const reqRoleId = this.stripFragmentRoleId(roleId);
1230
1236
  return {
1231
1237
  partKey: partGroupKey.part,
1232
- frKey: partGroupKey.fragments[reqRoleId]
1238
+ frKey: partGroupKey.fragments[reqRoleId],
1233
1239
  };
1234
1240
  }
1235
1241
  return {
1236
- partKey: partGroupKey.part
1242
+ partKey: partGroupKey.part,
1237
1243
  };
1238
1244
  }
1239
1245
  /**
@@ -1247,13 +1253,13 @@ class LibraryRouteService {
1247
1253
  if (i > -1) {
1248
1254
  return {
1249
1255
  partKey: key.substr(0, i),
1250
- frKey: key.substr(i + 1)
1256
+ frKey: key.substr(i + 1),
1251
1257
  };
1252
1258
  }
1253
1259
  else {
1254
1260
  return {
1255
1261
  partKey: key,
1256
- frKey: key
1262
+ frKey: key,
1257
1263
  };
1258
1264
  }
1259
1265
  }
@@ -1285,7 +1291,7 @@ class LibraryRouteService {
1285
1291
  route = `/items/${itemId}/${editorKey.partKey}/${typeId}/${partId}`;
1286
1292
  return {
1287
1293
  route: route,
1288
- rid: roleId
1294
+ rid: roleId,
1289
1295
  };
1290
1296
  }
1291
1297
  /**
@@ -1308,7 +1314,7 @@ class LibraryRouteService {
1308
1314
  route = `/items/${itemId}/${editorKey.frKey}/fragment/${partId}/${frTypeId}/${loc}`;
1309
1315
  return {
1310
1316
  route: route,
1311
- rid: frRoleId
1317
+ rid: frRoleId,
1312
1318
  };
1313
1319
  }
1314
1320
  }
@@ -1317,7 +1323,7 @@ LibraryRouteService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0",
1317
1323
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: LibraryRouteService, decorators: [{
1318
1324
  type: Injectable,
1319
1325
  args: [{
1320
- providedIn: 'root'
1326
+ providedIn: 'root',
1321
1327
  }]
1322
1328
  }], ctorParameters: function () {
1323
1329
  return [{ type: undefined, decorators: [{
@@ -1408,13 +1414,13 @@ class TextLayerService {
1408
1414
  * @param sb The target array.
1409
1415
  */
1410
1416
  renderTokenAtEnd(pt, token, sb) {
1411
- if (pt.at > 0) {
1417
+ if (pt.at) {
1412
1418
  // ...to]
1413
1419
  sb.push(token.substr(pt.at - 1, pt.run));
1414
1420
  sb.push('</span>');
1415
1421
  // ...ken
1416
- if (pt.at - 1 + pt.run < token.length) {
1417
- sb.push(token.substr(pt.at - 1 + pt.run));
1422
+ if (pt.at - 1 + (pt.run || 0) < token.length) {
1423
+ sb.push(token.substr(pt.at - 1 + (pt.run || 0)));
1418
1424
  }
1419
1425
  }
1420
1426
  else {
@@ -1433,7 +1439,7 @@ class TextLayerService {
1433
1439
  */
1434
1440
  renderTokenAtPointStart(loc, token, sb, isSelected) {
1435
1441
  // 1.token's left-part
1436
- if (loc.primary.at > 0) {
1442
+ if (loc.primary.at) {
1437
1443
  // to...
1438
1444
  sb.push(token.substr(0, loc.primary.at - 1));
1439
1445
  }
@@ -1454,14 +1460,14 @@ class TextLayerService {
1454
1460
  */
1455
1461
  renderTokenAtRangeStart(loc, token, sb, isSelected) {
1456
1462
  // 1.token's left-part (=before at)
1457
- if (loc.primary.at > 0) {
1463
+ if (loc.primary.at) {
1458
1464
  // to...
1459
1465
  sb.push(token.substr(0, loc.primary.at - 1));
1460
1466
  }
1461
1467
  // 2.span: [
1462
1468
  this.renderOpeningSpan(loc, 0, sb, isSelected);
1463
1469
  // 3.token's right-part (...ken or ...token)
1464
- if (loc.primary.at > 0) {
1470
+ if (loc.primary.at) {
1465
1471
  // ...ken
1466
1472
  sb.push(token.substr(loc.primary.at - 1));
1467
1473
  }
@@ -1491,14 +1497,14 @@ class TextLayerService {
1491
1497
  * fragment if any. The selected fragment gets decorated with an additional
1492
1498
  * class value.
1493
1499
  */
1494
- render(text, locations, selectedLoc = null) {
1500
+ render(text, locations, selectedLoc) {
1495
1501
  if (!text) {
1496
1502
  return '<div></div>';
1497
1503
  }
1498
1504
  // get lines from text
1499
1505
  const sb = [];
1500
1506
  const lines = this.getLines(text);
1501
- let loc = null;
1507
+ let loc = undefined;
1502
1508
  let tokenSelected = false;
1503
1509
  if (!locations) {
1504
1510
  locations = [];
@@ -1523,7 +1529,7 @@ class TextLayerService {
1523
1529
  if (loc && loc.secondary) {
1524
1530
  if (loc.secondary.y === y + 1 && loc.secondary.x === x + 1) {
1525
1531
  this.renderTokenAtEnd(loc.secondary, token, sb);
1526
- loc = null;
1532
+ loc = undefined;
1527
1533
  }
1528
1534
  else {
1529
1535
  sb.push(token);
@@ -1537,7 +1543,7 @@ class TextLayerService {
1537
1543
  if (loc) {
1538
1544
  tokenSelected = selectedLoc ? loc.overlaps(selectedLoc) : false;
1539
1545
  if (!this.renderTokenAtStart(loc, token, sb, tokenSelected)) {
1540
- loc = null;
1546
+ loc = undefined;
1541
1547
  }
1542
1548
  }
1543
1549
  else {
@@ -1567,7 +1573,7 @@ class TextLayerService {
1567
1573
  * Get the Y bounds from the specified selection.
1568
1574
  * @param range The selection range.
1569
1575
  * @param forNew True if getting bounds for a new fragment.
1570
- * @returns Range, inclusive.
1576
+ * @returns Range, inclusive, or undefined.
1571
1577
  */
1572
1578
  getYBoundsFromRange(range, forNew) {
1573
1579
  let p = null;
@@ -1575,10 +1581,10 @@ class TextLayerService {
1575
1581
  case Node.TEXT_NODE:
1576
1582
  // single-p selection, parent=p
1577
1583
  p = range.commonAncestorContainer.parentElement;
1578
- if (forNew && (p.nodeName !== 'P' || !p.hasAttribute('id'))) {
1584
+ if (forNew && ((p === null || p === void 0 ? void 0 : p.nodeName) !== 'P' || !p.hasAttribute('id'))) {
1579
1585
  return null;
1580
1586
  }
1581
- if (p.nodeName === 'SPAN') {
1587
+ if ((p === null || p === void 0 ? void 0 : p.nodeName) === 'SPAN') {
1582
1588
  p = p.parentElement;
1583
1589
  }
1584
1590
  const y = parseInt(p.getAttribute('id').substr(1), 10);
@@ -1622,6 +1628,7 @@ class TextLayerService {
1622
1628
  end: yMax,
1623
1629
  };
1624
1630
  }
1631
+ return null;
1625
1632
  }
1626
1633
  locatePrevSpace(line, index) {
1627
1634
  while (index > -1 && line.charAt(index) !== ' ') {
@@ -1810,13 +1817,14 @@ class TextLayerService {
1810
1817
  getNodeBaseOffset(node) {
1811
1818
  var _a, _b;
1812
1819
  let offset = 0;
1813
- node = node.previousSibling;
1814
- while (node) {
1820
+ let n = node;
1821
+ n = node.previousSibling;
1822
+ while (n) {
1815
1823
  offset +=
1816
- node.nodeType === Node.ELEMENT_NODE
1817
- ? ((_a = node.innerText) === null || _a === void 0 ? void 0 : _a.length) || 0
1818
- : ((_b = node.textContent) === null || _b === void 0 ? void 0 : _b.length) || 0;
1819
- node = node.previousSibling;
1824
+ n.nodeType === Node.ELEMENT_NODE
1825
+ ? ((_a = n.innerText) === null || _a === void 0 ? void 0 : _a.length) || 0
1826
+ : ((_b = n.textContent) === null || _b === void 0 ? void 0 : _b.length) || 0;
1827
+ n = n.previousSibling;
1820
1828
  }
1821
1829
  return offset;
1822
1830
  }
@@ -1864,7 +1872,7 @@ class TextLayerService {
1864
1872
  // single token: check for at,run
1865
1873
  if (start.at) {
1866
1874
  sb.push(`@${start.at}`);
1867
- if (start.run > 1) {
1875
+ if (start.run && start.run > 1) {
1868
1876
  sb.push(`x${start.run}`);
1869
1877
  }
1870
1878
  }
@@ -1914,11 +1922,12 @@ class TextLayerService {
1914
1922
  return null;
1915
1923
  }
1916
1924
  selHasAnySpan(range) {
1925
+ var _a, _b;
1917
1926
  let inside = false;
1918
1927
  if (
1919
1928
  // the selected text node must not be child of a span
1920
- range.startContainer.parentElement.tagName === 'SPAN' ||
1921
- range.startContainer.parentElement.tagName === 'SPAN' ||
1929
+ ((_a = range.startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === 'SPAN' ||
1930
+ ((_b = range.startContainer.parentElement) === null || _b === void 0 ? void 0 : _b.tagName) === 'SPAN' ||
1922
1931
  // the nodes tree from the common ancestor, from the start node
1923
1932
  // up to the end node, must not include any span
1924
1933
  this.findNode(range.commonAncestorContainer, (node) => {
@@ -1950,7 +1959,7 @@ class TextLayerService {
1950
1959
  * @param range The selected range. You can get it from the
1951
1960
  * current selection using getSelectedRange().
1952
1961
  * @param text The full base text.
1953
- * @returns TokenLocation The token location or null.
1962
+ * @returns TokenLocation The token location or undefined.
1954
1963
  */
1955
1964
  getSelectedLocationForNew(range, text) {
1956
1965
  if (!range || this.selHasAnySpan(range)) {
@@ -2071,27 +2080,27 @@ class PasswordValidator {
2071
2080
  }
2072
2081
  if (control.value.length < 8) {
2073
2082
  return {
2074
- passwordTooShort: true
2083
+ passwordTooShort: true,
2075
2084
  };
2076
2085
  }
2077
2086
  if (!/.*[A-Z].*/.test(control.value)) {
2078
2087
  return {
2079
- noUpperInPassword: true
2088
+ noUpperInPassword: true,
2080
2089
  };
2081
2090
  }
2082
2091
  if (!/.*[a-z].*/.test(control.value)) {
2083
2092
  return {
2084
- noLowerInPassword: true
2093
+ noLowerInPassword: true,
2085
2094
  };
2086
2095
  }
2087
2096
  if (!/.*[A-Z].*/.test(control.value)) {
2088
2097
  return {
2089
- noUpperInPassword: true
2098
+ noUpperInPassword: true,
2090
2099
  };
2091
2100
  }
2092
2101
  if (!/.*[-`~!@#$%^&*()_+=\[\]{};:'",.<>/?|\\].*/.test(control.value)) {
2093
2102
  return {
2094
- noSymbolInPassword: true
2103
+ noSymbolInPassword: true,
2095
2104
  };
2096
2105
  }
2097
2106
  return null;