@treeviz/gedcom-parser 2.1.12 → 2.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import type { IndiType } from "../classes/indi";
2
2
  import type { Language } from "../kinship-translator/types";
3
- import type { IndiKey } from "../types/types";
3
+ import type { IndiKey, NameOrder } from "../types/types";
4
4
  /**
5
5
  * Kinship translator class constructor type
6
6
  */
7
- export type KinshipTranslatorConstructor = new (person1: IndiType, person2?: IndiType | IndiKey, lang?: Language, entirePath?: boolean, displayName?: "none" | "givenname" | "surname" | "all") => {
7
+ export type KinshipTranslatorConstructor = new (person1: IndiType, person2?: IndiType | IndiKey, lang?: Language, entirePath?: boolean, displayName?: "none" | "givenname" | "surname" | "all", nameOrder?: NameOrder) => {
8
8
  translate: <T extends boolean | undefined>(showMainPerson: boolean) => (T extends false | undefined ? string : Array<{
9
9
  id?: IndiKey;
10
10
  gen: number;
@@ -1 +1 @@
1
- {"version":3,"file":"kinship-factory.d.ts","sourceRoot":"","sources":["../../src/factories/kinship-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,KAC1C,OAAO,EAAE,QAAQ,EACjB,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,EAC5B,IAAI,CAAC,EAAE,QAAQ,EACf,UAAU,CAAC,EAAE,OAAO,EACpB,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,KAAK,KAClD;IACJ,SAAS,EAAE,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS,EACxC,cAAc,EAAE,OAAO,KAErB,CAAC,CAAC,SAAS,KAA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ClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC,GACJ,SAAS,CAAC;CACb,CAAC;AAQF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,GACrC,iBAAiB,4BAA4B,SAG7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QAAO,4BAE5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,YAGvC,CAAC"}
package/dist/index.js CHANGED
@@ -814,7 +814,11 @@ var Common = class _Common {
814
814
  const current = this.get(validKey);
815
815
  const mergeValue = other.get(validKey);
816
816
  if (mergeValue) {
817
- if (current instanceof _Common || current instanceof List) {
817
+ if (current instanceof _Common && !current.isListable) {
818
+ if (override) {
819
+ this.set(validKey, mergeValue);
820
+ }
821
+ } else if (current instanceof _Common || current instanceof List) {
818
822
  this.assign(validKey, mergeValue, true);
819
823
  } else if (!current || override && validKey !== "id" && validKey !== "_id") {
820
824
  this.set(validKey, mergeValue);
@@ -2438,19 +2442,41 @@ var ACCEPTED_DATE_FORMATS_REGEX = new RegExp(
2438
2442
  ).join("|")})`,
2439
2443
  "gi"
2440
2444
  );
2445
+ var firstDate = (date) => {
2446
+ if (!date) return void 0;
2447
+ if (isCommonDate(date)) return date;
2448
+ if (date instanceof List) {
2449
+ return firstDate(
2450
+ date.index(0)
2451
+ );
2452
+ }
2453
+ const node = date;
2454
+ if (typeof node.toValue === "function") {
2455
+ return node;
2456
+ }
2457
+ return void 0;
2458
+ };
2459
+ var dateNote = (date, shortNote = true) => {
2460
+ if (date && typeof date.toNote === "function") {
2461
+ return date.toNote(shortNote) ?? "";
2462
+ }
2463
+ return "";
2464
+ };
2441
2465
  var commonDateFormatter = (date, format2 = "yyyy", prefix = "") => {
2442
- const formattedDate = date?.toValue(format2);
2466
+ const used = firstDate(date);
2467
+ const formattedDate = used?.toValue(format2);
2443
2468
  if (!formattedDate) {
2444
2469
  return void 0;
2445
2470
  }
2446
2471
  return `${prefix}${formattedDate}`.trim();
2447
2472
  };
2448
2473
  var noteDateFormatter = (date, format2 = "yyyy", prefix = "", shortNote = true, showNote = true) => {
2449
- const rawDate = commonDateFormatter(date, format2, "");
2474
+ const used = firstDate(date);
2475
+ const rawDate = commonDateFormatter(used, format2, "");
2450
2476
  if (!rawDate) {
2451
2477
  return void 0;
2452
2478
  }
2453
- const note = date?.toNote(shortNote) ?? "";
2479
+ const note = dateNote(used, shortNote);
2454
2480
  return `${prefix}${note && showNote ? i18n.t(`${note} {{date}}`, { date: rawDate }) : rawDate}`;
2455
2481
  };
2456
2482
  var marriageDateFormatter = (fam, showDays = false, showPlaces = false, shortNote = true, showNote = true, showDisplayTextIfNoDate = true, showAllEvents = false, dateFormatPattern) => {
@@ -2568,11 +2594,12 @@ var dateFormatter = (indi, showMarriages = false, showDays = false, showPlaces =
2568
2594
  const birthPlaces = [];
2569
2595
  const eventsToProcess = showAllEvents ? birthEvents : birthEvents.slice(0, 1);
2570
2596
  eventsToProcess.forEach((birthEvent) => {
2597
+ const birthDateNode = firstDate(birthEvent?.DATE);
2571
2598
  const birthDate = commonDateFormatter(
2572
- birthEvent?.DATE,
2599
+ birthDateNode,
2573
2600
  showDays ? fullDateFormat : "yyyy"
2574
2601
  );
2575
- const birthEventNote = birthEvent?.DATE?.toNote(shortNote) ?? "";
2602
+ const birthEventNote = dateNote(birthDateNode, shortNote);
2576
2603
  const birthEventPlace = showPlaces ? birthEvent?.PLAC?.value : void 0;
2577
2604
  if (birthDate) {
2578
2605
  birthStrings.push(
@@ -2587,11 +2614,12 @@ var dateFormatter = (indi, showMarriages = false, showDays = false, showPlaces =
2587
2614
  const deathPlaces = [];
2588
2615
  const deathEventsToProcess = showAllEvents ? deathEvents : deathEvents.slice(0, 1);
2589
2616
  deathEventsToProcess.forEach((deathEvent) => {
2617
+ const deathDateNode = firstDate(deathEvent?.DATE);
2590
2618
  const deathDate = commonDateFormatter(
2591
- deathEvent?.DATE,
2619
+ deathDateNode,
2592
2620
  showDays ? fullDateFormat : "yyyy"
2593
2621
  );
2594
- const deathEventNote = deathEvent?.DATE?.toNote(shortNote) ?? "";
2622
+ const deathEventNote = dateNote(deathDateNode, shortNote);
2595
2623
  const deathEventPlace = showPlaces ? deathEvent?.PLAC?.value : void 0;
2596
2624
  if (deathDate) {
2597
2625
  deathStrings.push(
@@ -5098,14 +5126,15 @@ var Indi = class extends Common {
5098
5126
  }
5099
5127
  return foundPath;
5100
5128
  }
5101
- kinship(other, showMainPerson, lang = "en", entirePath, displayName = "givenname") {
5129
+ kinship(other, showMainPerson, lang = "en", entirePath, displayName = "givenname", nameOrder) {
5102
5130
  const KinshipTranslatorClass2 = getKinshipTranslatorClass();
5103
5131
  const translator = new KinshipTranslatorClass2(
5104
5132
  this,
5105
5133
  other,
5106
5134
  lang,
5107
5135
  entirePath,
5108
- showMainPerson ? displayName : void 0
5136
+ showMainPerson ? displayName : void 0,
5137
+ nameOrder
5109
5138
  );
5110
5139
  return translator.translate(!!showMainPerson);
5111
5140
  }
@@ -6036,11 +6065,12 @@ var hungarianOrdinalize = (n) => {
6036
6065
 
6037
6066
  // src/kinship-translator/kinship-translator.basic.ts
6038
6067
  var KinshipTranslatorBasic = class {
6039
- constructor(path, displayName = "givenname") {
6068
+ constructor(path, displayName = "givenname", nameOrder = "first-last") {
6040
6069
  this.isOfSpouse = false;
6041
6070
  this.isSpouseOf = false;
6042
6071
  this._path = path;
6043
6072
  this.displayName = displayName;
6073
+ this.nameOrder = nameOrder;
6044
6074
  }
6045
6075
  get path() {
6046
6076
  return this._path;
@@ -6463,7 +6493,7 @@ var KinshipTranslatorHU = class extends KinshipTranslatorBasic {
6463
6493
  }
6464
6494
  of(relation) {
6465
6495
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
6466
- nameOrder: "last-first"
6496
+ nameOrder: this.nameOrder
6467
6497
  });
6468
6498
  let name = formattedName.inOrder.filter(Boolean).join(" ");
6469
6499
  if (this.displayName === "none") {
@@ -6677,7 +6707,7 @@ var KinshipTranslatorEn = class extends KinshipTranslatorBasic {
6677
6707
  }
6678
6708
  of(relation) {
6679
6709
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
6680
- nameOrder: "first-last"
6710
+ nameOrder: this.nameOrder
6681
6711
  });
6682
6712
  let name = formattedName.inOrder.filter(Boolean).join(" ");
6683
6713
  if (this.displayName === "none") {
@@ -6893,7 +6923,7 @@ var KinshipTranslatorDe = class extends KinshipTranslatorBasic {
6893
6923
  }
6894
6924
  of(relation) {
6895
6925
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
6896
- nameOrder: "first-last"
6926
+ nameOrder: this.nameOrder
6897
6927
  });
6898
6928
  let name = formattedName.inOrder.filter(Boolean).join(" ");
6899
6929
  if (this.displayName === "none") {
@@ -7110,7 +7140,7 @@ var KinshipTranslatorFr = class extends KinshipTranslatorBasic {
7110
7140
  }
7111
7141
  of(relation) {
7112
7142
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
7113
- nameOrder: "first-last"
7143
+ nameOrder: this.nameOrder
7114
7144
  });
7115
7145
  let name = formattedName.inOrder.filter(Boolean).join(" ");
7116
7146
  if (this.displayName === "none") {
@@ -7448,7 +7478,7 @@ var KinshipTranslatorEs = class extends KinshipTranslatorBasic {
7448
7478
  }
7449
7479
  of(relation) {
7450
7480
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
7451
- nameOrder: "first-last"
7481
+ nameOrder: this.nameOrder
7452
7482
  });
7453
7483
  let name = formattedName.inOrder.filter(Boolean).join(" ");
7454
7484
  if (this.displayName === "none") {
@@ -7755,7 +7785,7 @@ var KinshipTranslatorRu = class extends KinshipTranslatorBasic {
7755
7785
  }
7756
7786
  of(relation) {
7757
7787
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
7758
- nameOrder: "first-last"
7788
+ nameOrder: this.nameOrder
7759
7789
  });
7760
7790
  let name = formattedName.inOrder.filter(Boolean).join(" ");
7761
7791
  if (this.displayName === "none") {
@@ -7991,7 +8021,7 @@ var KinshipTranslatorJa = class extends KinshipTranslatorBasic {
7991
8021
  }
7992
8022
  of(relation) {
7993
8023
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
7994
- nameOrder: "last-first"
8024
+ nameOrder: this.nameOrder
7995
8025
  });
7996
8026
  let name = formattedName.inOrder.filter(Boolean).join(" ");
7997
8027
  if (this.displayName === "none") {
@@ -8240,7 +8270,7 @@ var KinshipTranslatorZh = class extends KinshipTranslatorBasic {
8240
8270
  }
8241
8271
  of(relation) {
8242
8272
  const formattedName = nameFormatter(this.path?.[0]?.indi, {
8243
- nameOrder: "last-first"
8273
+ nameOrder: this.nameOrder
8244
8274
  });
8245
8275
  let name = formattedName.inOrder.filter(Boolean).join(" ");
8246
8276
  if (this.displayName === "none") {
@@ -8309,22 +8339,30 @@ var KinshipTranslatorZh = class extends KinshipTranslatorBasic {
8309
8339
  };
8310
8340
 
8311
8341
  // src/kinship-translator/kinship-translator.ts
8342
+ var nameOrderForLang = (lang) => lang === "hu" || lang === "ja" || lang === "zh" ? "last-first" : "first-last";
8312
8343
  var KinshipTranslator = class {
8313
- constructor(person1, person2, lang = "en", entirePath, displayName = "givenname") {
8344
+ constructor(person1, person2, lang = "en", entirePath, displayName = "givenname", nameOrder) {
8314
8345
  this.displayName = displayName;
8315
8346
  this.lang = lang;
8316
8347
  this.entirePath = entirePath;
8317
8348
  this.person1 = person1;
8318
8349
  this.person2 = typeof person2 === "string" ? this.person1.getGedcom()?.indi(person2) : person2;
8319
8350
  this.path = this.person1.path(this.person2);
8351
+ const order = nameOrder ?? nameOrderForLang(lang);
8352
+ this.nameOrder = order;
8320
8353
  if (translators_exports[lang]) {
8321
8354
  this.translator = new translators_exports[lang](
8322
8355
  this.path ?? [],
8323
- displayName
8356
+ displayName,
8357
+ order
8324
8358
  );
8325
8359
  }
8326
8360
  if (!this.translator) {
8327
- this.translator = new KinshipTranslatorEn(this.path ?? [], displayName);
8361
+ this.translator = new KinshipTranslatorEn(
8362
+ this.path ?? [],
8363
+ displayName,
8364
+ order
8365
+ );
8328
8366
  }
8329
8367
  }
8330
8368
  get path0() {
@@ -8369,14 +8407,16 @@ var KinshipTranslator = class {
8369
8407
  showMainPerson,
8370
8408
  this.lang,
8371
8409
  false,
8372
- this.displayName
8410
+ this.displayName,
8411
+ this.nameOrder
8373
8412
  ),
8374
8413
  relative: this.path?.[index - 1]?.indi.kinship(
8375
8414
  path2.indi.id,
8376
8415
  showMainPerson,
8377
8416
  this.lang,
8378
8417
  false,
8379
- this.displayName
8418
+ this.displayName,
8419
+ this.nameOrder
8380
8420
  )
8381
8421
  }));
8382
8422
  return path;
@@ -8716,6 +8756,8 @@ var formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, base
8716
8756
  var CommonDate = class extends Common {
8717
8757
  constructor(gedcom, id, main, parent) {
8718
8758
  super(gedcom, id, main, parent);
8759
+ /** One DATE per event — merge must not turn this into a List. */
8760
+ this.isListable = false;
8719
8761
  delete this.id;
8720
8762
  }
8721
8763
  get calendar() {
@@ -9762,7 +9804,8 @@ var TREEVIZ_EXTENSION_URIS = {
9762
9804
  _TREEVIZ_SETTINGS: `${TREEVIZ_EXTENSION_BASE_URI}#_TREEVIZ_SETTINGS`,
9763
9805
  _TREEVIZ_VIEW: `${TREEVIZ_EXTENSION_BASE_URI}#_TREEVIZ_VIEW`,
9764
9806
  _TREEVIZ_DETECTIVE: `${TREEVIZ_EXTENSION_BASE_URI}#_TREEVIZ_DETECTIVE`,
9765
- _TREEVIZ_DETECTIVE_STATE: `${TREEVIZ_EXTENSION_BASE_URI}#_TREEVIZ_DETECTIVE_STATE`
9807
+ _TREEVIZ_DETECTIVE_STATE: `${TREEVIZ_EXTENSION_BASE_URI}#_TREEVIZ_DETECTIVE_STATE`,
9808
+ _TREEVIZ_FS_IGNORE: `${TREEVIZ_EXTENSION_BASE_URI}#_TREEVIZ_FS_IGNORE`
9766
9809
  };
9767
9810
  var parseTagDefinition = (payload) => {
9768
9811
  const trimmed = payload.trim();
@@ -9896,7 +9939,7 @@ var collectExtensionTagsFrom = (node, into = /* @__PURE__ */ new Set()) => {
9896
9939
  // package.json
9897
9940
  var package_default = {
9898
9941
  name: "@treeviz/gedcom-parser",
9899
- version: "2.1.12"};
9942
+ version: "2.1.16"};
9900
9943
 
9901
9944
  // src/utils/get-product-details.ts
9902
9945
  var isDevelopment = () => {
@@ -11300,7 +11343,7 @@ var create = (gedcom, type, id, nodes) => {
11300
11343
  prevNode = createObje(gedcom, void 0, mainNode, curNode);
11301
11344
  } else if (type === "DATE") {
11302
11345
  prevNode = createCommonDate(gedcom, void 0, mainNode, curNode);
11303
- } else if (type === "NOTE" || type === "SNOTE") {
11346
+ } else if (type === "NOTE" || type === "SNOTE" || type === "_TREEVIZ_LIFE_STORY" || type === "_TREEVIZ_FAMILY_STORY") {
11304
11347
  prevNode = createCommonNote(gedcom, void 0, mainNode, curNode);
11305
11348
  } else if (type === "NAME" && mainNode instanceof Indi) {
11306
11349
  prevNode = createCommonName(gedcom, void 0, mainNode, curNode);