@treeviz/gedcom-parser 2.1.22 → 2.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1300,6 +1300,68 @@ var idGetter = (id) => {
1300
1300
  return newId;
1301
1301
  };
1302
1302
 
1303
+ // src/factories/cache-factory.ts
1304
+ var defaultCacheFactory = () => {
1305
+ let cache = null;
1306
+ return {
1307
+ getItem: async () => cache,
1308
+ setItem: async (value) => {
1309
+ cache = value;
1310
+ }
1311
+ };
1312
+ };
1313
+ var cacheFactory = defaultCacheFactory;
1314
+ var setCacheManagerFactory = (factory) => {
1315
+ cacheFactory = factory;
1316
+ };
1317
+ var getCacheManagerFactory = () => {
1318
+ return cacheFactory;
1319
+ };
1320
+ var resetCacheManagerFactory = () => {
1321
+ cacheFactory = defaultCacheFactory;
1322
+ };
1323
+
1324
+ // src/factories/date-locale-factory.ts
1325
+ var dateLocaleProvider = () => void 0;
1326
+ var setDateLocaleProvider = (provider) => {
1327
+ dateLocaleProvider = provider;
1328
+ };
1329
+ var getDateLocale = () => {
1330
+ const result = dateLocaleProvider();
1331
+ return result;
1332
+ };
1333
+ var resetDateLocaleProvider = () => {
1334
+ dateLocaleProvider = () => void 0;
1335
+ };
1336
+
1337
+ // src/factories/i18n-factory.ts
1338
+ var i18nProvider = (key) => key;
1339
+ var setI18nProvider = (provider) => {
1340
+ i18nProvider = provider;
1341
+ };
1342
+ var getI18n = () => {
1343
+ return i18nProvider;
1344
+ };
1345
+ var resetI18nProvider = () => {
1346
+ i18nProvider = (key) => key;
1347
+ };
1348
+ var i18n = {
1349
+ t: (key, options) => i18nProvider(key, options)
1350
+ };
1351
+
1352
+ // src/kinship-translator/translators.ts
1353
+ var translators_exports = {};
1354
+ __export(translators_exports, {
1355
+ de: () => KinshipTranslatorDe,
1356
+ en: () => KinshipTranslatorEn,
1357
+ es: () => KinshipTranslatorEs,
1358
+ fr: () => KinshipTranslatorFr,
1359
+ hu: () => KinshipTranslatorHU,
1360
+ ja: () => KinshipTranslatorJa,
1361
+ ru: () => KinshipTranslatorRu,
1362
+ zh: () => KinshipTranslatorZh
1363
+ });
1364
+
1303
1365
  // src/types/types.ts
1304
1366
  var RelationType = /* @__PURE__ */ ((RelationType2) => {
1305
1367
  RelationType2["BIOLOGICAL"] = "biological";
@@ -1328,996 +1390,92 @@ var Range = /* @__PURE__ */ ((Range2) => {
1328
1390
  return Range2;
1329
1391
  })(Range || {});
1330
1392
 
1331
- // src/factories/cache-factory.ts
1332
- var defaultCacheFactory = () => {
1333
- let cache = null;
1334
- return {
1335
- getItem: async () => cache,
1336
- setItem: async (value) => {
1337
- cache = value;
1338
- }
1339
- };
1393
+ // src/constants/filters.ts
1394
+ var EVERY = {};
1395
+ var FEMALE = {
1396
+ SEX: "F"
1340
1397
  };
1341
- var cacheFactory = defaultCacheFactory;
1342
- var setCacheManagerFactory = (factory) => {
1343
- cacheFactory = factory;
1398
+ var MALE = {
1399
+ SEX: "M"
1344
1400
  };
1345
- var getCacheManagerFactory = () => {
1346
- return cacheFactory;
1401
+ var ADOPTED = {
1402
+ PEDI: "adopted" /* ADOPTED */
1347
1403
  };
1348
- var resetCacheManagerFactory = () => {
1349
- cacheFactory = defaultCacheFactory;
1404
+ var BIRTH = {
1405
+ PEDI: "birth" /* BIRTH */
1350
1406
  };
1351
-
1352
- // src/utils/cache.ts
1353
- var getGedcomId = (gedcom) => {
1354
- if (!gedcom) {
1355
- return "unknown";
1356
- }
1357
- const treeId = gedcom.getTreeId?.() || "";
1358
- const treeName = gedcom.getTreeName?.() || "";
1359
- const sanitizedName = treeName.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
1360
- if (treeId && sanitizedName) {
1361
- return `${treeId}_${sanitizedName}`;
1362
- } else if (treeId) {
1363
- return treeId;
1364
- } else if (sanitizedName) {
1365
- return sanitizedName;
1366
- }
1367
- return `gedcom_${gedcom.refcount}`;
1407
+ var FOSTER = {
1408
+ PEDI: "foster" /* FOSTER */
1368
1409
  };
1369
- var caches = {
1370
- pathCache: {},
1371
- relativesOnDegreeCache: {},
1372
- relativesOnLevelCache: {},
1373
- profilePictureCache: {}
1410
+ var SEALING = {
1411
+ PEDI: "sealing" /* SEALING */
1374
1412
  };
1375
- var cacheDbs;
1376
- var getCacheDbs = () => {
1377
- if (!cacheDbs) {
1378
- const getInstance = getCacheManagerFactory();
1379
- cacheDbs = {
1380
- pathCache: getInstance(
1381
- "ftv",
1382
- "Main",
1383
- "path",
1384
- true
1385
- ),
1386
- relativesOnDegreeCache: getInstance("ftv", "Main", "path", true),
1387
- relativesOnLevelCache: getInstance(
1388
- "ftv",
1389
- "Main",
1390
- "path",
1391
- true
1392
- ),
1393
- profilePictureCache: getInstance(
1394
- "ftv",
1395
- "Main",
1396
- "images",
1397
- false
1398
- )
1399
- };
1400
- }
1401
- return cacheDbs;
1413
+ var STEP = {
1414
+ PEDI: "step" /* STEP */
1402
1415
  };
1403
- var storeCache = {
1404
- // NOTE: pathCache, relativesOnLevelCache, and relativesOnDegreeCache are intentionally
1405
- // kept in memory only. These debounced functions exist to satisfy the type system
1406
- // but are never called.
1407
- pathCache: debounce((value) => {
1408
- if (value) {
1409
- getCacheDbs().pathCache.setItem(value);
1410
- }
1411
- }, 50),
1412
- relativesOnLevelCache: debounce((value) => {
1413
- if (value) {
1414
- getCacheDbs().relativesOnLevelCache.setItem(value);
1415
- }
1416
- }, 50),
1417
- relativesOnDegreeCache: debounce((value) => {
1418
- if (value) {
1419
- getCacheDbs().relativesOnDegreeCache.setItem(value);
1420
- }
1421
- }, 50),
1422
- // Image bytes are stored as one IndexedDB record per photo.
1423
- profilePictureCache: debounce((value) => {
1424
- }, 100)
1416
+ var BIOLOGICAL = {
1417
+ PEDI: "biological" /* BIOLOGICAL */
1425
1418
  };
1426
- var cacheInitialized = false;
1427
- var initializeCache = async () => {
1428
- if (cacheInitialized) {
1429
- return;
1430
- }
1431
- cacheInitialized = true;
1419
+ var FRIEND = {
1420
+ PART: "friend" /* FRIEND */
1432
1421
  };
1433
- var resetRelativesCache = () => {
1434
- caches.relativesOnDegreeCache = {};
1435
- caches.relativesOnLevelCache = {};
1422
+ var OTHER = {
1423
+ PART: "other" /* OTHER */
1436
1424
  };
1437
- var relativesCache = (cacheKey) => (gedcom, key, subKey, value) => {
1438
- const gedcomId = getGedcomId(gedcom);
1439
- const fullKey = `${gedcomId}:${key}`;
1440
- const cache = caches[cacheKey];
1441
- if (!cache) {
1442
- caches[cacheKey] = {};
1443
- }
1444
- if (value) {
1445
- const typedCache2 = caches[cacheKey];
1446
- if (!typedCache2[fullKey]) {
1447
- typedCache2[fullKey] = {};
1425
+ var PARTNER = {
1426
+ PART: "partner" /* PARTNER */
1427
+ };
1428
+ var SINGLE = {
1429
+ PART: "single" /* SINGLE */
1430
+ };
1431
+ var SPOUSE = {
1432
+ PART: "spouse" /* SPOUSE */
1433
+ };
1434
+ var UNKOWN = {
1435
+ PART: "unknown" /* UNKOWN */
1436
+ };
1437
+
1438
+ // src/utils/get-family-with.ts
1439
+ var getFamilyWith = (person1, person2, famType = "FAMS") => {
1440
+ return person1?.get(famType)?.toValueList().find((fam) => {
1441
+ const family = fam;
1442
+ return famType === "FAMC" || family?.HUSB?.value === person2 || family?.WIFE?.value === person2;
1443
+ });
1444
+ };
1445
+
1446
+ // src/constants/orders.ts
1447
+ var DEFAULT = {};
1448
+ var BIRTH_ASC = {
1449
+ "BIRT.DATE": {
1450
+ direction: "ASC",
1451
+ getter: (value, raw) => {
1452
+ if (isCommonDate(raw) && raw.rawValue) {
1453
+ return raw.rawValue.getTime();
1454
+ }
1455
+ return new Date(value).getTime();
1448
1456
  }
1449
- typedCache2[fullKey][subKey] = value;
1450
- return typedCache2[fullKey][subKey];
1451
1457
  }
1452
- const typedCache = caches[cacheKey];
1453
- return typedCache?.[fullKey]?.[subKey];
1454
1458
  };
1455
- var pathCache = (gedcom, key, value) => {
1456
- const gedcomId = getGedcomId(gedcom);
1457
- const fullKey = `${gedcomId}:${key}`;
1458
- if (!caches.pathCache) {
1459
- caches.pathCache = {};
1459
+ var BIRTH_DESC = {
1460
+ "BIRT.DATE": {
1461
+ direction: "DESC",
1462
+ getter: (value, raw) => {
1463
+ if (isCommonDate(raw) && raw.rawValue) {
1464
+ return raw.rawValue.getTime();
1465
+ }
1466
+ return new Date(value).getTime();
1467
+ }
1460
1468
  }
1461
- if (value && caches.pathCache) {
1462
- caches.pathCache[fullKey] = value;
1463
- return caches.pathCache[fullKey];
1464
- }
1465
- return caches.pathCache?.[fullKey];
1466
- };
1467
- var profilePictureCache = (gedcom, key, value) => {
1468
- const gedcomId = getGedcomId(gedcom);
1469
- const fullKey = `${gedcomId}:${key}`;
1470
- if (!caches.profilePictureCache) {
1471
- caches.profilePictureCache = {};
1472
- }
1473
- if (value && caches.profilePictureCache) {
1474
- caches.profilePictureCache[fullKey] = value;
1475
- storeCache.profilePictureCache(caches.profilePictureCache);
1476
- return caches.profilePictureCache[fullKey];
1477
- }
1478
- const cached = caches.profilePictureCache?.[fullKey];
1479
- return cached;
1480
- };
1481
- var isNonBiologicalPath = (path) => path.some(
1482
- (item) => item.relation && item.relation !== "biological" /* BIOLOGICAL */
1483
- );
1484
- var invertHop = (kinship) => {
1485
- if (kinship === "parent") {
1486
- return "child";
1487
- }
1488
- if (kinship === "child") {
1489
- return "parent";
1490
- }
1491
- return kinship;
1492
- };
1493
- var hopRelation = (from, toIndi, kinship, inherited) => {
1494
- if (kinship === "parent" || kinship === "child") {
1495
- const parent = kinship === "parent" ? toIndi : from.indi;
1496
- const child = kinship === "parent" ? from.indi : toIndi;
1497
- const currentRelation = child.getParentType(parent);
1498
- if (currentRelation && currentRelation !== "biological" /* BIOLOGICAL */) {
1499
- return currentRelation;
1500
- }
1501
- }
1502
- if (inherited && inherited !== "biological" /* BIOLOGICAL */) {
1503
- return inherited;
1504
- }
1505
- return void 0;
1506
- };
1507
- var rebuildPathFromHops = (hops, skipRelation = false) => {
1508
- if (hops.length === 0) {
1509
- return [];
1510
- }
1511
- const path = [
1512
- {
1513
- indi: hops[0].indi,
1514
- kinship: "self",
1515
- level: 0,
1516
- levelUp: 0,
1517
- levelDown: 0,
1518
- degree: 0
1519
- }
1520
- ];
1521
- for (let i = 1; i < hops.length; i++) {
1522
- const prev = path[i - 1];
1523
- const { indi, kinship } = hops[i];
1524
- const relation = skipRelation ? void 0 : hopRelation(prev, indi, kinship, prev.relation);
1525
- if (kinship === "parent") {
1526
- path.push({
1527
- indi,
1528
- kinship,
1529
- relation,
1530
- level: prev.level + 1,
1531
- levelUp: prev.levelUp + 1,
1532
- levelDown: prev.levelDown,
1533
- degree: prev.degree
1534
- });
1535
- continue;
1536
- }
1537
- if (kinship === "child") {
1538
- path.push({
1539
- indi,
1540
- kinship,
1541
- relation,
1542
- level: prev.level - 1,
1543
- levelUp: prev.levelUp,
1544
- levelDown: prev.levelDown + 1,
1545
- degree: prev.levelUp ? prev.level > 0 ? prev.levelUp - prev.level + 1 : prev.levelDown - Math.abs(prev.level) : 0
1546
- });
1547
- continue;
1548
- }
1549
- path.push({
1550
- indi,
1551
- kinship,
1552
- relation,
1553
- level: prev.level,
1554
- levelUp: prev.levelUp,
1555
- levelDown: prev.levelDown,
1556
- degree: prev.degree
1557
- });
1558
- }
1559
- return path;
1560
- };
1561
- var storePathIfBetter = (gedcom, fromId, toId, path) => {
1562
- const key = `${fromId}|${toId}`;
1563
- const existing = pathCache(gedcom, key);
1564
- if (existing && (!isNonBiologicalPath(existing) || isNonBiologicalPath(path))) {
1565
- return;
1566
- }
1567
- pathCache(gedcom, key, path);
1568
- };
1569
- var cacheDiscoveredPath = (gedcom, path) => {
1570
- const n = path.length;
1571
- if (n < 2) {
1572
- return;
1573
- }
1574
- for (let i = 0; i < n; i++) {
1575
- const fromId = path[i].indi.id;
1576
- if (!fromId) {
1577
- continue;
1578
- }
1579
- for (let j = i + 1; j < n; j++) {
1580
- const toId = path[j].indi.id;
1581
- if (!toId) {
1582
- continue;
1583
- }
1584
- const isOriginalPair = i === 0 && j === n - 1;
1585
- const isDirectHop = j === i + 1;
1586
- const slice = path.slice(i, j + 1);
1587
- const sliceMixed = isNonBiologicalPath(slice);
1588
- if (!isOriginalPair && !isDirectHop && sliceMixed) {
1589
- continue;
1590
- }
1591
- const forward = i === 0 ? slice : rebuildPathFromHops(slice, !sliceMixed);
1592
- const reverseHops = [
1593
- {
1594
- indi: slice[slice.length - 1].indi,
1595
- kinship: "self"
1596
- }
1597
- ];
1598
- for (let k = slice.length - 2; k >= 0; k--) {
1599
- reverseHops.push({
1600
- indi: slice[k].indi,
1601
- kinship: invertHop(slice[k + 1].kinship)
1602
- });
1603
- }
1604
- const reverse = rebuildPathFromHops(reverseHops, !sliceMixed);
1605
- storePathIfBetter(gedcom, fromId, toId, forward);
1606
- storePathIfBetter(gedcom, toId, fromId, reverse);
1607
- }
1608
- }
1609
- };
1610
-
1611
- // src/utils/family-edit.ts
1612
- var refTypeForTag = (tag) => {
1613
- if (tag === "FAMS" || tag === "FAMC") return "FAM";
1614
- return "INDI";
1615
- };
1616
- var normalizeSinglePointer = (owner, tag) => {
1617
- const node = owner.get(tag);
1618
- if (!node) return;
1619
- if (node instanceof List && node.length === 1) {
1620
- const only = node.index(0);
1621
- if (only) {
1622
- owner.set(tag, only);
1623
- return;
1624
- }
1625
- const raw = node.values()[0];
1626
- if (typeof raw === "string") {
1627
- const gedcom = owner.getGedcom?.();
1628
- if (gedcom) {
1629
- owner.set(tag, makePointer(gedcom, owner, raw, refTypeForTag(tag)));
1630
- }
1631
- }
1632
- }
1633
- };
1634
- var PEDIGREE_VALUES = [
1635
- "birth" /* BIRTH */,
1636
- "adopted" /* ADOPTED */,
1637
- "foster" /* FOSTER */,
1638
- "step" /* STEP */,
1639
- "sealing" /* SEALING */
1640
- ];
1641
- var toGedcomPedigree = (value) => {
1642
- const normalized = String(value || "birth" /* BIRTH */).toLowerCase();
1643
- if (normalized === "biological" /* BIOLOGICAL */ || normalized === "birth" /* BIRTH */) {
1644
- return "birth" /* BIRTH */;
1645
- }
1646
- const match = PEDIGREE_VALUES.find((item) => item === normalized);
1647
- return match ?? "birth" /* BIRTH */;
1648
- };
1649
- var pointerIds = (tag) => {
1650
- if (!tag) {
1651
- return [];
1652
- }
1653
- if (tag instanceof List) {
1654
- return tag.values().map((item) => item?.toValue?.()).filter((value2) => !!value2);
1655
- }
1656
- const value = tag.toValue?.();
1657
- return value ? [String(value)] : [];
1658
- };
1659
- var firstPointerId = (tag) => pointerIds(tag)[0];
1660
- var makePointer = (gedcom, parent, value, refType) => {
1661
- const pointer = createCommon(gedcom, void 0, parent);
1662
- pointer.value = value;
1663
- pointer.refType = refType;
1664
- return pointer;
1665
- };
1666
- var nextRecordId = (ids, prefix) => {
1667
- let max = 0;
1668
- ids.forEach((id) => {
1669
- const match = String(id).match(/(\d+)/);
1670
- const n = match ? Number.parseInt(match[1], 10) : 0;
1671
- if (n > max) {
1672
- max = n;
1673
- }
1674
- });
1675
- return `@${prefix}${max + 1}@`;
1676
- };
1677
- var familyHasParent = (fam, indiId) => pointerIds(fam.get("HUSB")).includes(indiId) || pointerIds(fam.get("WIFE")).includes(indiId);
1678
- var familyHasChild = (fam, indiId) => pointerIds(fam.get("CHIL")).includes(indiId);
1679
- var spouseTagFor = (indi, fam) => {
1680
- const husbId = firstPointerId(fam.get("HUSB"));
1681
- const wifeId = firstPointerId(fam.get("WIFE"));
1682
- if (husbId === indi.id) {
1683
- return "HUSB";
1684
- }
1685
- if (wifeId === indi.id) {
1686
- return "WIFE";
1687
- }
1688
- if (indi.isFemale()) {
1689
- return wifeId && wifeId !== indi.id ? "HUSB" : "WIFE";
1690
- }
1691
- if (indi.isMale()) {
1692
- return husbId && husbId !== indi.id ? "WIFE" : "HUSB";
1693
- }
1694
- return husbId ? "WIFE" : "HUSB";
1695
- };
1696
- var canAttachAsSpouse = (fam, indi) => {
1697
- if (!indi.id) {
1698
- return false;
1699
- }
1700
- if (familyHasParent(fam, indi.id)) {
1701
- return true;
1702
- }
1703
- const tag = spouseTagFor(indi, fam);
1704
- const occupied = firstPointerId(fam.get(tag));
1705
- return !occupied || occupied === indi.id;
1706
- };
1707
- var pointerByValue = (tag, id) => {
1708
- if (!tag) {
1709
- return void 0;
1710
- }
1711
- const fromValues = tag.toValueList?.().item(id);
1712
- if (fromValues) {
1713
- return fromValues;
1714
- }
1715
- return tag.toList()?.values().find((item) => item?.toValue?.() === id);
1716
- };
1717
- var setChildPedigree = (fam, child, pedigree, parent) => {
1718
- if (!fam.id || !child.id) {
1719
- return;
1720
- }
1721
- const pedi = toGedcomPedigree(pedigree);
1722
- const famc = pointerByValue(child.get("FAMC"), fam.id);
1723
- if (famc) {
1724
- famc.set("PEDI", pedi);
1725
- }
1726
- const chil = pointerByValue(fam.get("CHIL"), child.id);
1727
- if (!chil) {
1728
- return;
1729
- }
1730
- const setFather = !parent || parent.isMale() || parent.isUnknownSex();
1731
- const setMother = !parent || parent.isFemale() || parent.isUnknownSex();
1732
- if (setFather) {
1733
- chil.set("_FREL", pedi);
1734
- }
1735
- if (setMother) {
1736
- chil.set("_MREL", pedi);
1737
- }
1738
- };
1739
- var attachSpouseToFamily = (fam, indi) => {
1740
- const gedcom = fam.getGedcom() ?? indi.getGedcom();
1741
- if (!indi.id || !fam.id || !gedcom) {
1742
- return false;
1743
- }
1744
- if (!canAttachAsSpouse(fam, indi)) {
1745
- return false;
1746
- }
1747
- const tag = spouseTagFor(indi, fam);
1748
- if (firstPointerId(fam.get(tag)) !== indi.id) {
1749
- fam.set(tag, makePointer(gedcom, fam, indi.id, "INDI"));
1750
- }
1751
- indi.assign("FAMS", makePointer(gedcom, indi, fam.id, "FAM"), true);
1752
- normalizeSinglePointer(indi, "FAMS");
1753
- normalizeSinglePointer(fam, spouseTagFor(indi, fam));
1754
- resetRelativesCache();
1755
- return true;
1756
- };
1757
- var attachChildToFamily = (fam, child, pedigree, parent) => {
1758
- const gedcom = fam.getGedcom() ?? child.getGedcom();
1759
- if (!child.id || !fam.id || !gedcom) {
1760
- return false;
1761
- }
1762
- if (!familyHasChild(fam, child.id)) {
1763
- fam.assign("CHIL", makePointer(gedcom, fam, child.id, "INDI"), true);
1764
- }
1765
- const existingFamc = pointerByValue(child.get("FAMC"), fam.id);
1766
- if (!existingFamc) {
1767
- child.assign("FAMC", makePointer(gedcom, child, fam.id, "FAM"), true);
1768
- }
1769
- setChildPedigree(fam, child, pedigree, parent);
1770
- normalizeSinglePointer(child, "FAMC");
1771
- normalizeSinglePointer(fam, "CHIL");
1772
- resetRelativesCache();
1773
- return true;
1774
- };
1775
- var removePointerByValue = (owner, tag, targetId) => {
1776
- const node = owner.get(tag);
1777
- if (!node) {
1778
- return false;
1779
- }
1780
- if (node instanceof List) {
1781
- const keysToRemove = [];
1782
- node.entries().forEach(([key, item]) => {
1783
- if (item?.toValue?.() === targetId || item?.id === targetId || String(key) === targetId) {
1784
- keysToRemove.push(key);
1785
- }
1786
- });
1787
- keysToRemove.forEach((key) => {
1788
- node.removeItem(key);
1789
- });
1790
- if (node.length === 0) {
1791
- owner.remove(tag);
1792
- }
1793
- return keysToRemove.length > 0;
1794
- }
1795
- if (node.toValue?.() === targetId) {
1796
- owner.remove(tag);
1797
- return true;
1798
- }
1799
- const asList = node.toList?.();
1800
- if (asList && asList.length > 0) {
1801
- const keysToRemove = [];
1802
- asList.entries().forEach(([key, item]) => {
1803
- if (item?.toValue?.() === targetId || item?.id === targetId) {
1804
- keysToRemove.push(key);
1805
- }
1806
- });
1807
- if (keysToRemove.length === asList.length) {
1808
- owner.remove(tag);
1809
- return true;
1810
- }
1811
- if (keysToRemove.length > 0) {
1812
- const remaining = asList.values().filter((item) => item?.toValue?.() !== targetId);
1813
- if (remaining.length === 1 && remaining[0]) {
1814
- owner.set(tag, remaining[0]);
1815
- } else {
1816
- owner.set(tag, new List(remaining));
1817
- }
1818
- return true;
1819
- }
1820
- }
1821
- return false;
1822
- };
1823
- var familyMemberCount = (fam) => {
1824
- let count = 0;
1825
- if (firstPointerId(fam.get("HUSB"))) {
1826
- count += 1;
1827
- }
1828
- if (firstPointerId(fam.get("WIFE"))) {
1829
- count += 1;
1830
- }
1831
- count += pointerIds(fam.get("CHIL")).length;
1832
- return count;
1833
- };
1834
- var isDegenerateFamily = (fam) => familyMemberCount(fam) <= 1;
1835
- var pruneEmptyFamilies = (gedcom) => {
1836
- const emptyIds = [];
1837
- gedcom.fams()?.forEach((fam, id) => {
1838
- if (fam && isDegenerateFamily(fam) && id) {
1839
- emptyIds.push(id);
1840
- }
1841
- });
1842
- if (emptyIds.length === 0) {
1843
- return [];
1844
- }
1845
- gedcom.indis()?.forEach((indi) => {
1846
- if (!indi) {
1847
- return;
1848
- }
1849
- emptyIds.forEach((famId) => {
1850
- removePointerByValue(indi, "FAMS", famId);
1851
- removePointerByValue(indi, "FAMC", famId);
1852
- });
1853
- });
1854
- emptyIds.forEach((famId) => {
1855
- gedcom.fams()?.removeItem(famId);
1856
- });
1857
- return emptyIds;
1858
- };
1859
- var findDegenerateFamiliesForIndi = (indi) => {
1860
- const found = [];
1861
- const seen = /* @__PURE__ */ new Set();
1862
- ["FAMC", "FAMS"].forEach((pointer) => {
1863
- indi.getFamilies(pointer)?.forEach((fam) => {
1864
- if (!fam?.id || seen.has(fam.id) || !isDegenerateFamily(fam)) {
1865
- return;
1866
- }
1867
- seen.add(fam.id);
1868
- found.push(fam);
1869
- });
1870
- });
1871
- return found;
1872
- };
1873
- var coupleKeyForFam = (fam) => {
1874
- const husb = firstPointerId(fam.get("HUSB"));
1875
- const wife = firstPointerId(fam.get("WIFE"));
1876
- if (!husb || !wife) {
1877
- return void 0;
1878
- }
1879
- return husb < wife ? `${husb}|${wife}` : `${wife}|${husb}`;
1880
- };
1881
- var findDuplicateCoupleFamiliesForIndi = (indi) => {
1882
- const gedcom = indi.getGedcom();
1883
- if (!gedcom) {
1884
- return [];
1885
- }
1886
- const relevantKeys = /* @__PURE__ */ new Set();
1887
- ["FAMC", "FAMS"].forEach((pointer) => {
1888
- indi.getFamilies(pointer)?.forEach((fam) => {
1889
- const key = fam ? coupleKeyForFam(fam) : void 0;
1890
- if (key) {
1891
- relevantKeys.add(key);
1892
- }
1893
- });
1894
- });
1895
- if (relevantKeys.size === 0) {
1896
- return [];
1897
- }
1898
- const byKey = /* @__PURE__ */ new Map();
1899
- gedcom.fams()?.forEach((fam) => {
1900
- if (!fam?.id) {
1901
- return;
1902
- }
1903
- const key = coupleKeyForFam(fam);
1904
- if (!key || !relevantKeys.has(key)) {
1905
- return;
1906
- }
1907
- const list = byKey.get(key) ?? [];
1908
- list.push(fam);
1909
- byKey.set(key, list);
1910
- });
1911
- return [...byKey.entries()].filter(([, families]) => families.length > 1).map(([key, families]) => ({ key, families }));
1912
- };
1913
- var mergeDuplicateCoupleFamilies = (gedcom, families) => {
1914
- const usable = families.filter((fam) => !!fam?.id);
1915
- if (usable.length === 0) {
1916
- return void 0;
1917
- }
1918
- if (usable.length === 1) {
1919
- return usable[0];
1920
- }
1921
- const sorted = [...usable].sort((a, b) => {
1922
- const childDiff = pointerIds(b.get("CHIL")).length - pointerIds(a.get("CHIL")).length;
1923
- if (childDiff !== 0) {
1924
- return childDiff;
1925
- }
1926
- return String(a.id).localeCompare(String(b.id));
1927
- });
1928
- const keep = sorted[0];
1929
- const drops = sorted.slice(1);
1930
- if (!keep?.id) {
1931
- return void 0;
1932
- }
1933
- drops.forEach((drop) => {
1934
- if (!drop?.id || drop.id === keep.id) {
1935
- return;
1936
- }
1937
- pointerIds(drop.get("CHIL")).forEach((childId) => {
1938
- const child = gedcom.indi(childId);
1939
- if (!child) {
1940
- return;
1941
- }
1942
- attachChildToFamily(keep, child);
1943
- removePointerByValue(drop, "CHIL", childId);
1944
- normalizeSinglePointer(drop, "CHIL");
1945
- removePointerByValue(child, "FAMC", drop.id);
1946
- normalizeSinglePointer(child, "FAMC");
1947
- });
1948
- const husbId = firstPointerId(drop.get("HUSB"));
1949
- const wifeId = firstPointerId(drop.get("WIFE"));
1950
- [husbId, wifeId].forEach((parentId) => {
1951
- if (!parentId) {
1952
- return;
1953
- }
1954
- const parent = gedcom.indi(parentId);
1955
- if (parent) {
1956
- removePointerByValue(parent, "FAMS", drop.id);
1957
- normalizeSinglePointer(parent, "FAMS");
1958
- }
1959
- });
1960
- gedcom.fams()?.removeItem(drop.id);
1961
- });
1962
- resetRelativesCache();
1963
- return keep;
1964
- };
1965
- var pruneFamiliesByIds = (gedcom, famIds) => {
1966
- const unique = [...new Set(famIds.filter(Boolean))];
1967
- if (unique.length === 0) {
1968
- return 0;
1969
- }
1970
- gedcom.indis()?.forEach((indi) => {
1971
- if (!indi) {
1972
- return;
1973
- }
1974
- unique.forEach((famId) => {
1975
- removePointerByValue(indi, "FAMS", famId);
1976
- removePointerByValue(indi, "FAMC", famId);
1977
- });
1978
- });
1979
- unique.forEach((famId) => {
1980
- gedcom.fams()?.removeItem(famId);
1981
- });
1982
- return unique.length;
1983
- };
1984
- var findSharedSpouseFamily = (parent, coParentId) => {
1985
- let found;
1986
- parent.getFamilies("FAMS")?.forEach((fam) => {
1987
- if (!found && fam && familyHasParent(fam, coParentId)) {
1988
- found = fam;
1989
- }
1990
- });
1991
- return found;
1992
- };
1993
- var unlinkRelative = (anchor, relative, kind) => {
1994
- if (!anchor.id || !relative.id || anchor.id === relative.id) {
1995
- return false;
1996
- }
1997
- let changed = false;
1998
- if (kind === "spouse") {
1999
- anchor.getFamilies("FAMS")?.forEach((fam) => {
2000
- if (!fam?.id || !familyHasParent(fam, relative.id)) {
2001
- return;
2002
- }
2003
- if (firstPointerId(fam.get("HUSB")) === relative.id) {
2004
- fam.remove("HUSB");
2005
- changed = true;
2006
- }
2007
- if (firstPointerId(fam.get("WIFE")) === relative.id) {
2008
- fam.remove("WIFE");
2009
- changed = true;
2010
- }
2011
- changed = removePointerByValue(relative, "FAMS", fam.id) || changed;
2012
- });
2013
- } else if (kind === "parent") {
2014
- anchor.getFamilies("FAMC")?.forEach((fam) => {
2015
- if (!fam?.id || !familyHasParent(fam, relative.id)) {
2016
- return;
2017
- }
2018
- if (firstPointerId(fam.get("HUSB")) === relative.id) {
2019
- fam.remove("HUSB");
2020
- changed = true;
2021
- }
2022
- if (firstPointerId(fam.get("WIFE")) === relative.id) {
2023
- fam.remove("WIFE");
2024
- changed = true;
2025
- }
2026
- changed = removePointerByValue(relative, "FAMS", fam.id) || changed;
2027
- });
2028
- } else if (kind === "sibling") {
2029
- anchor.getFamilies("FAMC")?.forEach((fam) => {
2030
- if (!fam?.id || !familyHasChild(fam, relative.id)) {
2031
- return;
2032
- }
2033
- changed = removePointerByValue(fam, "CHIL", relative.id) || changed;
2034
- changed = removePointerByValue(relative, "FAMC", fam.id) || changed;
2035
- });
2036
- } else {
2037
- anchor.getFamilies("FAMS")?.forEach((fam) => {
2038
- if (!fam?.id || !familyHasChild(fam, relative.id)) {
2039
- return;
2040
- }
2041
- changed = removePointerByValue(fam, "CHIL", relative.id) || changed;
2042
- changed = removePointerByValue(relative, "FAMC", fam.id) || changed;
2043
- });
2044
- }
2045
- if (changed) {
2046
- const gedcom = anchor.getGedcom() ?? relative.getGedcom();
2047
- if (gedcom) {
2048
- pruneEmptyFamilies(gedcom);
2049
- }
2050
- resetRelativesCache();
2051
- }
2052
- return changed;
2053
- };
2054
- var deleteIndividual = (gedcom, indiId) => {
2055
- const indi = gedcom.indi(indiId);
2056
- if (!indi?.id) {
2057
- return false;
2058
- }
2059
- const famsIds = pointerIds(indi.get("FAMS"));
2060
- const famcIds = pointerIds(indi.get("FAMC"));
2061
- famsIds.forEach((famId) => {
2062
- const fam = gedcom.fam(famId);
2063
- if (!fam) {
2064
- return;
2065
- }
2066
- if (firstPointerId(fam.get("HUSB")) === indiId) {
2067
- fam.remove("HUSB");
2068
- }
2069
- if (firstPointerId(fam.get("WIFE")) === indiId) {
2070
- fam.remove("WIFE");
2071
- }
2072
- });
2073
- famcIds.forEach((famId) => {
2074
- const fam = gedcom.fam(famId);
2075
- if (fam) {
2076
- removePointerByValue(fam, "CHIL", indiId);
2077
- }
2078
- });
2079
- gedcom.fams()?.forEach((fam) => {
2080
- if (fam && familyHasChild(fam, indiId)) {
2081
- removePointerByValue(fam, "CHIL", indiId);
2082
- }
2083
- if (fam && familyHasParent(fam, indiId)) {
2084
- if (firstPointerId(fam.get("HUSB")) === indiId) {
2085
- fam.remove("HUSB");
2086
- }
2087
- if (firstPointerId(fam.get("WIFE")) === indiId) {
2088
- fam.remove("WIFE");
2089
- }
2090
- }
2091
- });
2092
- gedcom.indis()?.removeItem(indiId);
2093
- pruneEmptyFamilies(gedcom);
2094
- resetRelativesCache();
2095
- return true;
2096
- };
2097
- var findReusableParentChildFamily = (parent, child, options) => {
2098
- if (!parent.id || !child.id) {
2099
- return void 0;
2100
- }
2101
- const reuseParentFamilies = options?.reuseParentFamilies !== false;
2102
- const gedcom = parent.getGedcom() ?? child.getGedcom();
2103
- let reusableFamc;
2104
- let coupleFam;
2105
- let already = false;
2106
- const noteCoupleWith = (coParentId) => {
2107
- if (!coParentId || coParentId === parent.id || coupleFam || !parent.id) {
2108
- return;
2109
- }
2110
- const shared = findSharedSpouseFamily(parent, coParentId);
2111
- if (shared) {
2112
- coupleFam = shared;
2113
- }
2114
- };
2115
- child.getFamilies("FAMC")?.forEach((fam) => {
2116
- if (!fam) {
2117
- return;
2118
- }
2119
- if (familyHasParent(fam, parent.id) && familyHasChild(fam, child.id)) {
2120
- already = true;
2121
- return;
2122
- }
2123
- pointerIds(fam.get("HUSB")).forEach(noteCoupleWith);
2124
- pointerIds(fam.get("WIFE")).forEach(noteCoupleWith);
2125
- if (!reusableFamc && canAttachAsSpouse(fam, parent)) {
2126
- reusableFamc = fam;
2127
- }
2128
- });
2129
- if (already) {
2130
- return "already";
2131
- }
2132
- if (coupleFam) {
2133
- return coupleFam;
2134
- }
2135
- if (reusableFamc) {
2136
- return reusableFamc;
2137
- }
2138
- if (options?.targetFamilyId && gedcom) {
2139
- const target = gedcom.fam(options.targetFamilyId);
2140
- if (target && (familyHasParent(target, parent.id) || canAttachAsSpouse(target, parent))) {
2141
- return target;
2142
- }
2143
- }
2144
- if (!reuseParentFamilies) {
2145
- return void 0;
2146
- }
2147
- const parentFams = [];
2148
- parent.getFamilies("FAMS")?.forEach((fam) => {
2149
- if (fam) {
2150
- parentFams.push(fam);
2151
- }
2152
- });
2153
- if (parentFams.length === 1) {
2154
- return parentFams[0];
2155
- }
2156
- return void 0;
2157
- };
2158
- var consolidateChildIntoFamily = (child, keep) => {
2159
- if (!child.id || !keep.id) {
2160
- return [];
2161
- }
2162
- const keepParentIds = /* @__PURE__ */ new Set([
2163
- ...pointerIds(keep.get("HUSB")),
2164
- ...pointerIds(keep.get("WIFE"))
2165
- ]);
2166
- const removed = [];
2167
- child.getFamilies("FAMC")?.forEach((fam) => {
2168
- if (!fam?.id || fam.id === keep.id) {
2169
- return;
2170
- }
2171
- const famParentIds = [
2172
- ...pointerIds(fam.get("HUSB")),
2173
- ...pointerIds(fam.get("WIFE"))
2174
- ];
2175
- if (famParentIds.length === 0 || !famParentIds.every((id) => keepParentIds.has(id))) {
2176
- return;
2177
- }
2178
- removePointerByValue(fam, "CHIL", child.id);
2179
- normalizeSinglePointer(fam, "CHIL");
2180
- removePointerByValue(child, "FAMC", fam.id);
2181
- normalizeSinglePointer(child, "FAMC");
2182
- removed.push(fam.id);
2183
- });
2184
- const gedcom = child.getGedcom() ?? keep.getGedcom();
2185
- if (gedcom && removed.length > 0) {
2186
- pruneEmptyFamilies(gedcom);
2187
- }
2188
- if (removed.length > 0) {
2189
- resetRelativesCache();
2190
- }
2191
- return removed;
2192
- };
2193
-
2194
- // src/factories/date-locale-factory.ts
2195
- var dateLocaleProvider = () => void 0;
2196
- var setDateLocaleProvider = (provider) => {
2197
- dateLocaleProvider = provider;
2198
- };
2199
- var getDateLocale = () => {
2200
- const result = dateLocaleProvider();
2201
- return result;
2202
- };
2203
- var resetDateLocaleProvider = () => {
2204
- dateLocaleProvider = () => void 0;
2205
- };
2206
-
2207
- // src/factories/i18n-factory.ts
2208
- var i18nProvider = (key) => key;
2209
- var setI18nProvider = (provider) => {
2210
- i18nProvider = provider;
2211
- };
2212
- var getI18n = () => {
2213
- return i18nProvider;
2214
- };
2215
- var resetI18nProvider = () => {
2216
- i18nProvider = (key) => key;
2217
- };
2218
- var i18n = {
2219
- t: (key, options) => i18nProvider(key, options)
2220
- };
2221
-
2222
- // src/kinship-translator/translators.ts
2223
- var translators_exports = {};
2224
- __export(translators_exports, {
2225
- de: () => KinshipTranslatorDe,
2226
- en: () => KinshipTranslatorEn,
2227
- es: () => KinshipTranslatorEs,
2228
- fr: () => KinshipTranslatorFr,
2229
- hu: () => KinshipTranslatorHU,
2230
- ja: () => KinshipTranslatorJa,
2231
- ru: () => KinshipTranslatorRu,
2232
- zh: () => KinshipTranslatorZh
2233
- });
2234
-
2235
- // src/constants/filters.ts
2236
- var EVERY = {};
2237
- var FEMALE = {
2238
- SEX: "F"
2239
- };
2240
- var MALE = {
2241
- SEX: "M"
2242
- };
2243
- var ADOPTED = {
2244
- PEDI: "adopted" /* ADOPTED */
2245
- };
2246
- var BIRTH = {
2247
- PEDI: "birth" /* BIRTH */
2248
- };
2249
- var FOSTER = {
2250
- PEDI: "foster" /* FOSTER */
2251
- };
2252
- var SEALING = {
2253
- PEDI: "sealing" /* SEALING */
2254
- };
2255
- var STEP = {
2256
- PEDI: "step" /* STEP */
2257
- };
2258
- var BIOLOGICAL = {
2259
- PEDI: "biological" /* BIOLOGICAL */
2260
- };
2261
- var FRIEND = {
2262
- PART: "friend" /* FRIEND */
2263
- };
2264
- var OTHER = {
2265
- PART: "other" /* OTHER */
2266
- };
2267
- var PARTNER = {
2268
- PART: "partner" /* PARTNER */
2269
- };
2270
- var SINGLE = {
2271
- PART: "single" /* SINGLE */
2272
- };
2273
- var SPOUSE = {
2274
- PART: "spouse" /* SPOUSE */
2275
- };
2276
- var UNKOWN = {
2277
- PART: "unknown" /* UNKOWN */
2278
- };
2279
-
2280
- // src/utils/get-family-with.ts
2281
- var getFamilyWith = (person1, person2, famType = "FAMS") => {
2282
- return person1?.get(famType)?.toValueList().find((fam) => {
2283
- const family = fam;
2284
- return famType === "FAMC" || family?.HUSB?.value === person2 || family?.WIFE?.value === person2;
2285
- });
2286
- };
2287
-
2288
- // src/constants/orders.ts
2289
- var DEFAULT = {};
2290
- var BIRTH_ASC = {
2291
- "BIRT.DATE": {
2292
- direction: "ASC",
2293
- getter: (value, raw) => {
2294
- if (isCommonDate(raw) && raw.rawValue) {
2295
- return raw.rawValue.getTime();
2296
- }
2297
- return new Date(value).getTime();
2298
- }
2299
- }
2300
- };
2301
- var BIRTH_DESC = {
2302
- "BIRT.DATE": {
2303
- direction: "DESC",
2304
- getter: (value, raw) => {
2305
- if (isCommonDate(raw) && raw.rawValue) {
2306
- return raw.rawValue.getTime();
2307
- }
2308
- return new Date(value).getTime();
2309
- }
2310
- }
2311
- };
2312
- var DEATH_ASC = {
2313
- "DEAT.DATE": {
2314
- direction: "ASC",
2315
- getter: (value, raw) => {
2316
- if (isCommonDate(raw) && raw.rawValue) {
2317
- return raw.rawValue.getTime();
2318
- }
2319
- return new Date(value).getTime();
2320
- }
1469
+ };
1470
+ var DEATH_ASC = {
1471
+ "DEAT.DATE": {
1472
+ direction: "ASC",
1473
+ getter: (value, raw) => {
1474
+ if (isCommonDate(raw) && raw.rawValue) {
1475
+ return raw.rawValue.getTime();
1476
+ }
1477
+ return new Date(value).getTime();
1478
+ }
2321
1479
  }
2322
1480
  };
2323
1481
  var DEATH_DESC = {
@@ -2482,46 +1640,303 @@ var getNameAscAndBirth = (nameOrder = "first-last") => (itemA, keyA, itemB, keyB
2482
1640
  if (nameSort !== 0) {
2483
1641
  return nameSort;
2484
1642
  }
2485
- return getBirthAsc(itemA, keyA, itemB);
1643
+ return getBirthAsc(itemA, keyA, itemB);
1644
+ };
1645
+ var getMarriageAsc = (person, famType = "FAMS") => (itemA, _keyA, itemB, _keyB) => {
1646
+ if (!person && famType === "FAMS") {
1647
+ return 0;
1648
+ }
1649
+ const familyA = getFamilyWith(itemA, person);
1650
+ const familyB = getFamilyWith(itemB, person);
1651
+ const marriageA = familyA?.MARR?.DATE?.rawValue;
1652
+ const marriageB = familyB?.MARR?.DATE?.rawValue;
1653
+ if (marriageA?.getTime() === marriageB?.getTime()) {
1654
+ return 0;
1655
+ }
1656
+ if (!marriageA || marriageB && marriageA > marriageB) {
1657
+ return 1;
1658
+ }
1659
+ return -1;
1660
+ };
1661
+ var getMarriageAscAndChildBirth = (person) => (itemA, keyA, itemB, keyB) => {
1662
+ const marriageSort = getMarriageAsc(person)(itemA, keyA, itemB, keyB);
1663
+ if (marriageSort !== 0) {
1664
+ return marriageSort;
1665
+ }
1666
+ const familyA = getFamilyWith(itemA, person);
1667
+ const familyB = getFamilyWith(itemB, person);
1668
+ const childA = familyA?.getChildren().orderBy(BIRTH_ASC).index(0);
1669
+ const childB = familyB?.getChildren().orderBy(BIRTH_ASC).index(0);
1670
+ return getBirthAsc(childA, keyA, childB);
1671
+ };
1672
+ var getMarriageAscAndBirth = (person) => (itemA, keyA, itemB, keyB) => {
1673
+ const marriageSort = getMarriageAsc(person, "FAMC")(
1674
+ itemA,
1675
+ keyA,
1676
+ itemB,
1677
+ keyB
1678
+ );
1679
+ if (marriageSort !== 0) {
1680
+ return marriageSort;
1681
+ }
1682
+ return getBirthAsc(itemA, keyA, itemB);
1683
+ };
1684
+ var getGedcomId = (gedcom) => {
1685
+ if (!gedcom) {
1686
+ return "unknown";
1687
+ }
1688
+ const treeId = gedcom.getTreeId?.() || "";
1689
+ const treeName = gedcom.getTreeName?.() || "";
1690
+ const sanitizedName = treeName.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
1691
+ if (treeId && sanitizedName) {
1692
+ return `${treeId}_${sanitizedName}`;
1693
+ } else if (treeId) {
1694
+ return treeId;
1695
+ } else if (sanitizedName) {
1696
+ return sanitizedName;
1697
+ }
1698
+ return `gedcom_${gedcom.refcount}`;
1699
+ };
1700
+ var caches = {
1701
+ pathCache: {},
1702
+ relativesOnDegreeCache: {},
1703
+ relativesOnLevelCache: {},
1704
+ profilePictureCache: {}
1705
+ };
1706
+ var cacheDbs;
1707
+ var getCacheDbs = () => {
1708
+ if (!cacheDbs) {
1709
+ const getInstance = getCacheManagerFactory();
1710
+ cacheDbs = {
1711
+ pathCache: getInstance(
1712
+ "ftv",
1713
+ "Main",
1714
+ "path",
1715
+ true
1716
+ ),
1717
+ relativesOnDegreeCache: getInstance("ftv", "Main", "path", true),
1718
+ relativesOnLevelCache: getInstance(
1719
+ "ftv",
1720
+ "Main",
1721
+ "path",
1722
+ true
1723
+ ),
1724
+ profilePictureCache: getInstance(
1725
+ "ftv",
1726
+ "Main",
1727
+ "images",
1728
+ false
1729
+ )
1730
+ };
1731
+ }
1732
+ return cacheDbs;
1733
+ };
1734
+ var storeCache = {
1735
+ // NOTE: pathCache, relativesOnLevelCache, and relativesOnDegreeCache are intentionally
1736
+ // kept in memory only. These debounced functions exist to satisfy the type system
1737
+ // but are never called.
1738
+ pathCache: debounce((value) => {
1739
+ if (value) {
1740
+ getCacheDbs().pathCache.setItem(value);
1741
+ }
1742
+ }, 50),
1743
+ relativesOnLevelCache: debounce((value) => {
1744
+ if (value) {
1745
+ getCacheDbs().relativesOnLevelCache.setItem(value);
1746
+ }
1747
+ }, 50),
1748
+ relativesOnDegreeCache: debounce((value) => {
1749
+ if (value) {
1750
+ getCacheDbs().relativesOnDegreeCache.setItem(value);
1751
+ }
1752
+ }, 50),
1753
+ // Image bytes are stored as one IndexedDB record per photo.
1754
+ profilePictureCache: debounce((value) => {
1755
+ }, 100)
1756
+ };
1757
+ var cacheInitialized = false;
1758
+ var initializeCache = async () => {
1759
+ if (cacheInitialized) {
1760
+ return;
1761
+ }
1762
+ cacheInitialized = true;
1763
+ };
1764
+ var resetRelativesCache = () => {
1765
+ caches.relativesOnDegreeCache = {};
1766
+ caches.relativesOnLevelCache = {};
1767
+ };
1768
+ var relativesCache = (cacheKey) => (gedcom, key, subKey, value) => {
1769
+ const gedcomId = getGedcomId(gedcom);
1770
+ const fullKey = `${gedcomId}:${key}`;
1771
+ const cache = caches[cacheKey];
1772
+ if (!cache) {
1773
+ caches[cacheKey] = {};
1774
+ }
1775
+ if (value) {
1776
+ const typedCache2 = caches[cacheKey];
1777
+ if (!typedCache2[fullKey]) {
1778
+ typedCache2[fullKey] = {};
1779
+ }
1780
+ typedCache2[fullKey][subKey] = value;
1781
+ return typedCache2[fullKey][subKey];
1782
+ }
1783
+ const typedCache = caches[cacheKey];
1784
+ return typedCache?.[fullKey]?.[subKey];
1785
+ };
1786
+ var pathCache = (gedcom, key, value) => {
1787
+ const gedcomId = getGedcomId(gedcom);
1788
+ const fullKey = `${gedcomId}:${key}`;
1789
+ if (!caches.pathCache) {
1790
+ caches.pathCache = {};
1791
+ }
1792
+ if (value && caches.pathCache) {
1793
+ caches.pathCache[fullKey] = value;
1794
+ return caches.pathCache[fullKey];
1795
+ }
1796
+ return caches.pathCache?.[fullKey];
1797
+ };
1798
+ var profilePictureCache = (gedcom, key, value) => {
1799
+ const gedcomId = getGedcomId(gedcom);
1800
+ const fullKey = `${gedcomId}:${key}`;
1801
+ if (!caches.profilePictureCache) {
1802
+ caches.profilePictureCache = {};
1803
+ }
1804
+ if (value && caches.profilePictureCache) {
1805
+ caches.profilePictureCache[fullKey] = value;
1806
+ storeCache.profilePictureCache(caches.profilePictureCache);
1807
+ return caches.profilePictureCache[fullKey];
1808
+ }
1809
+ const cached = caches.profilePictureCache?.[fullKey];
1810
+ return cached;
1811
+ };
1812
+ var isNonBiologicalPath = (path) => path.some(
1813
+ (item) => item.relation && item.relation !== "biological" /* BIOLOGICAL */
1814
+ );
1815
+ var invertHop = (kinship) => {
1816
+ if (kinship === "parent") {
1817
+ return "child";
1818
+ }
1819
+ if (kinship === "child") {
1820
+ return "parent";
1821
+ }
1822
+ return kinship;
1823
+ };
1824
+ var hopRelation = (from, toIndi, kinship, inherited) => {
1825
+ if (kinship === "parent" || kinship === "child") {
1826
+ const parent = kinship === "parent" ? toIndi : from.indi;
1827
+ const child = kinship === "parent" ? from.indi : toIndi;
1828
+ const currentRelation = child.getParentType(parent);
1829
+ if (currentRelation && currentRelation !== "biological" /* BIOLOGICAL */) {
1830
+ return currentRelation;
1831
+ }
1832
+ }
1833
+ if (inherited && inherited !== "biological" /* BIOLOGICAL */) {
1834
+ return inherited;
1835
+ }
1836
+ return void 0;
1837
+ };
1838
+ var rebuildPathFromHops = (hops, skipRelation = false) => {
1839
+ if (hops.length === 0) {
1840
+ return [];
1841
+ }
1842
+ const path = [
1843
+ {
1844
+ indi: hops[0].indi,
1845
+ kinship: "self",
1846
+ level: 0,
1847
+ levelUp: 0,
1848
+ levelDown: 0,
1849
+ degree: 0
1850
+ }
1851
+ ];
1852
+ for (let i = 1; i < hops.length; i++) {
1853
+ const prev = path[i - 1];
1854
+ const { indi, kinship } = hops[i];
1855
+ const relation = skipRelation ? void 0 : hopRelation(prev, indi, kinship, prev.relation);
1856
+ if (kinship === "parent") {
1857
+ path.push({
1858
+ indi,
1859
+ kinship,
1860
+ relation,
1861
+ level: prev.level + 1,
1862
+ levelUp: prev.levelUp + 1,
1863
+ levelDown: prev.levelDown,
1864
+ degree: prev.degree
1865
+ });
1866
+ continue;
1867
+ }
1868
+ if (kinship === "child") {
1869
+ path.push({
1870
+ indi,
1871
+ kinship,
1872
+ relation,
1873
+ level: prev.level - 1,
1874
+ levelUp: prev.levelUp,
1875
+ levelDown: prev.levelDown + 1,
1876
+ degree: prev.levelUp ? prev.level > 0 ? prev.levelUp - prev.level + 1 : prev.levelDown - Math.abs(prev.level) : 0
1877
+ });
1878
+ continue;
1879
+ }
1880
+ path.push({
1881
+ indi,
1882
+ kinship,
1883
+ relation,
1884
+ level: prev.level,
1885
+ levelUp: prev.levelUp,
1886
+ levelDown: prev.levelDown,
1887
+ degree: prev.degree
1888
+ });
1889
+ }
1890
+ return path;
2486
1891
  };
2487
- var getMarriageAsc = (person, famType = "FAMS") => (itemA, _keyA, itemB, _keyB) => {
2488
- if (!person && famType === "FAMS") {
2489
- return 0;
2490
- }
2491
- const familyA = getFamilyWith(itemA, person);
2492
- const familyB = getFamilyWith(itemB, person);
2493
- const marriageA = familyA?.MARR?.DATE?.rawValue;
2494
- const marriageB = familyB?.MARR?.DATE?.rawValue;
2495
- if (marriageA?.getTime() === marriageB?.getTime()) {
2496
- return 0;
2497
- }
2498
- if (!marriageA || marriageB && marriageA > marriageB) {
2499
- return 1;
1892
+ var storePathIfBetter = (gedcom, fromId, toId, path) => {
1893
+ const key = `${fromId}|${toId}`;
1894
+ const existing = pathCache(gedcom, key);
1895
+ if (existing && (!isNonBiologicalPath(existing) || isNonBiologicalPath(path))) {
1896
+ return;
2500
1897
  }
2501
- return -1;
1898
+ pathCache(gedcom, key, path);
2502
1899
  };
2503
- var getMarriageAscAndChildBirth = (person) => (itemA, keyA, itemB, keyB) => {
2504
- const marriageSort = getMarriageAsc(person)(itemA, keyA, itemB, keyB);
2505
- if (marriageSort !== 0) {
2506
- return marriageSort;
1900
+ var cacheDiscoveredPath = (gedcom, path) => {
1901
+ const n = path.length;
1902
+ if (n < 2) {
1903
+ return;
2507
1904
  }
2508
- const familyA = getFamilyWith(itemA, person);
2509
- const familyB = getFamilyWith(itemB, person);
2510
- const childA = familyA?.getChildren().orderBy(BIRTH_ASC).index(0);
2511
- const childB = familyB?.getChildren().orderBy(BIRTH_ASC).index(0);
2512
- return getBirthAsc(childA, keyA, childB);
2513
- };
2514
- var getMarriageAscAndBirth = (person) => (itemA, keyA, itemB, keyB) => {
2515
- const marriageSort = getMarriageAsc(person, "FAMC")(
2516
- itemA,
2517
- keyA,
2518
- itemB,
2519
- keyB
2520
- );
2521
- if (marriageSort !== 0) {
2522
- return marriageSort;
1905
+ for (let i = 0; i < n; i++) {
1906
+ const fromId = path[i].indi.id;
1907
+ if (!fromId) {
1908
+ continue;
1909
+ }
1910
+ for (let j = i + 1; j < n; j++) {
1911
+ const toId = path[j].indi.id;
1912
+ if (!toId) {
1913
+ continue;
1914
+ }
1915
+ const isOriginalPair = i === 0 && j === n - 1;
1916
+ const isDirectHop = j === i + 1;
1917
+ const slice = path.slice(i, j + 1);
1918
+ const sliceMixed = isNonBiologicalPath(slice);
1919
+ if (!isOriginalPair && !isDirectHop && sliceMixed) {
1920
+ continue;
1921
+ }
1922
+ const forward = i === 0 ? slice : rebuildPathFromHops(slice, !sliceMixed);
1923
+ const reverseHops = [
1924
+ {
1925
+ indi: slice[slice.length - 1].indi,
1926
+ kinship: "self"
1927
+ }
1928
+ ];
1929
+ for (let k = slice.length - 2; k >= 0; k--) {
1930
+ reverseHops.push({
1931
+ indi: slice[k].indi,
1932
+ kinship: invertHop(slice[k + 1].kinship)
1933
+ });
1934
+ }
1935
+ const reverse = rebuildPathFromHops(reverseHops, !sliceMixed);
1936
+ storePathIfBetter(gedcom, fromId, toId, forward);
1937
+ storePathIfBetter(gedcom, toId, fromId, reverse);
1938
+ }
2523
1939
  }
2524
- return getBirthAsc(itemA, keyA, itemB);
2525
1940
  };
2526
1941
 
2527
1942
  // src/utils/get-all-prop.ts
@@ -2757,6 +2172,180 @@ var dateFormatter = (indi, showMarriages = false, showDays = false, showPlaces =
2757
2172
  };
2758
2173
  };
2759
2174
 
2175
+ // src/utils/fact-edit.ts
2176
+ var SINGLETON_TAGS = /* @__PURE__ */ new Set(["BIRT", "DEAT", "SSN", "SEX", "DSCR"]);
2177
+ var firstRecord = (node) => {
2178
+ if (!node) {
2179
+ return void 0;
2180
+ }
2181
+ if (node instanceof List) {
2182
+ return node.index(0);
2183
+ }
2184
+ return node.index(0) ?? node;
2185
+ };
2186
+ var setDateOn = (gedcom, owner, parent, date) => {
2187
+ const trimmed = date.trim();
2188
+ if (!trimmed) {
2189
+ return;
2190
+ }
2191
+ let dateNode = parent.get("DATE");
2192
+ if (!dateNode || dateNode instanceof List) {
2193
+ dateNode = createCommonDate(gedcom, void 0, owner, parent);
2194
+ dateNode.type = "DATE";
2195
+ parent.set("DATE", dateNode);
2196
+ }
2197
+ dateNode.value = trimmed;
2198
+ };
2199
+ var fillFact = (gedcom, owner, event, input) => {
2200
+ if (input.value?.trim()) {
2201
+ event.value = input.value.trim();
2202
+ }
2203
+ if (input.type?.trim()) {
2204
+ event.set("TYPE", input.type.trim());
2205
+ }
2206
+ if (input.date) {
2207
+ setDateOn(gedcom, owner, event, input.date);
2208
+ }
2209
+ if (input.place?.trim()) {
2210
+ event.set("PLAC", input.place.trim());
2211
+ }
2212
+ if (input.note?.trim()) {
2213
+ event.set("NOTE", input.note.trim());
2214
+ }
2215
+ };
2216
+ var updateFactRecord = (owner, event, input) => {
2217
+ const gedcom = owner.getGedcom();
2218
+ if (!gedcom) {
2219
+ return event;
2220
+ }
2221
+ const asOwner = owner;
2222
+ if (input.value !== void 0) {
2223
+ const trimmed = input.value.trim();
2224
+ if (trimmed) {
2225
+ event.value = trimmed;
2226
+ } else {
2227
+ event.removeValue();
2228
+ }
2229
+ }
2230
+ if (input.type !== void 0) {
2231
+ const trimmed = input.type.trim();
2232
+ if (trimmed) {
2233
+ event.set("TYPE", trimmed);
2234
+ } else {
2235
+ event.remove("TYPE");
2236
+ }
2237
+ }
2238
+ if (input.date !== void 0) {
2239
+ const trimmed = input.date.trim();
2240
+ if (trimmed) {
2241
+ setDateOn(gedcom, asOwner, event, trimmed);
2242
+ } else {
2243
+ event.remove("DATE");
2244
+ }
2245
+ }
2246
+ if (input.place !== void 0) {
2247
+ const trimmed = input.place.trim();
2248
+ if (trimmed) {
2249
+ event.set("PLAC", trimmed);
2250
+ } else {
2251
+ event.remove("PLAC");
2252
+ }
2253
+ }
2254
+ if (input.note !== void 0) {
2255
+ const trimmed = input.note.trim();
2256
+ if (trimmed) {
2257
+ event.set("NOTE", trimmed);
2258
+ } else {
2259
+ event.remove("NOTE");
2260
+ }
2261
+ }
2262
+ return event;
2263
+ };
2264
+ var setFamilyMarriage = (fam, input) => {
2265
+ const existing = firstRecord(fam.get("MARR"));
2266
+ if (existing) {
2267
+ return updateFactRecord(fam, existing, {
2268
+ date: input.date,
2269
+ place: input.place
2270
+ });
2271
+ }
2272
+ return addFamilyFact(fam, {
2273
+ tag: "MARR",
2274
+ date: input.date,
2275
+ place: input.place
2276
+ });
2277
+ };
2278
+ var addIndividualFact = (indi, input) => {
2279
+ const gedcom = indi.getGedcom();
2280
+ if (!gedcom) {
2281
+ return void 0;
2282
+ }
2283
+ const tag = input.tag;
2284
+ let event = SINGLETON_TAGS.has(tag) ? firstRecord(indi.get(tag)) : void 0;
2285
+ if (!event) {
2286
+ event = createCommon(gedcom, void 0, indi);
2287
+ event.type = tag;
2288
+ if (SINGLETON_TAGS.has(tag)) {
2289
+ indi.set(tag, event);
2290
+ } else {
2291
+ indi.assign(tag, event);
2292
+ }
2293
+ }
2294
+ fillFact(gedcom, indi, event, input);
2295
+ return event;
2296
+ };
2297
+ var addFamilyFact = (fam, input) => {
2298
+ const gedcom = fam.getGedcom();
2299
+ if (!gedcom) {
2300
+ return void 0;
2301
+ }
2302
+ const event = createCommon(gedcom, void 0, fam);
2303
+ event.type = input.tag;
2304
+ fam.assign(input.tag, event);
2305
+ fillFact(gedcom, fam, event, input);
2306
+ return event;
2307
+ };
2308
+ var setCauseOfDeath = (indi, text) => {
2309
+ const trimmed = text.trim();
2310
+ if (!trimmed) {
2311
+ return void 0;
2312
+ }
2313
+ const death = firstRecord(indi.get("DEAT")) || addIndividualFact(indi, { tag: "DEAT", value: "Y" });
2314
+ if (!death) {
2315
+ return void 0;
2316
+ }
2317
+ death.set("CAUS", trimmed);
2318
+ return death;
2319
+ };
2320
+ var setDeceased = (indi, deceased) => {
2321
+ if (!deceased) {
2322
+ indi.remove("DEAT");
2323
+ return;
2324
+ }
2325
+ if (firstRecord(indi.get("DEAT"))) {
2326
+ return;
2327
+ }
2328
+ addIndividualFact(indi, { tag: "DEAT", value: "Y" });
2329
+ };
2330
+ var addNonEvent = (owner, input) => {
2331
+ const gedcom = owner.getGedcom();
2332
+ const eventType = input.event?.trim().toUpperCase();
2333
+ if (!gedcom || !eventType) {
2334
+ return void 0;
2335
+ }
2336
+ const no = createCommon(gedcom, void 0, owner);
2337
+ no.type = "NO";
2338
+ no.value = eventType;
2339
+ if (input.date?.trim()) {
2340
+ setDateOn(gedcom, owner, no, input.date);
2341
+ }
2342
+ if (input.note?.trim()) {
2343
+ no.set("NOTE", input.note.trim());
2344
+ }
2345
+ owner.assign("NO", no);
2346
+ return no;
2347
+ };
2348
+
2760
2349
  // src/utils/get-places.ts
2761
2350
  var PlaceType = /* @__PURE__ */ ((PlaceType2) => {
2762
2351
  PlaceType2["All"] = "ALL";
@@ -9125,209 +8714,643 @@ var CommonDate = class extends Common {
9125
8714
  if (!formatted) {
9126
8715
  return formatted;
9127
8716
  }
9128
- const note = this.NOTE?.value?.trim();
9129
- const qualifier = note ? EXPORT_QUALIFIERS[note] : void 0;
9130
- const standardized = qualifier ? formatted.replace(note, qualifier) : formatted;
9131
- const withMonths = standardized.replace(
9132
- GEDCOM_MONTHS,
9133
- (month) => month.toUpperCase()
9134
- );
9135
- if (this._calendar && this._calendar !== "GREGORIAN") {
9136
- return `${this._calendar} ${withMonths}`;
8717
+ const note = this.NOTE?.value?.trim();
8718
+ const qualifier = note ? EXPORT_QUALIFIERS[note] : void 0;
8719
+ const standardized = qualifier ? formatted.replace(note, qualifier) : formatted;
8720
+ const withMonths = standardized.replace(
8721
+ GEDCOM_MONTHS,
8722
+ (month) => month.toUpperCase()
8723
+ );
8724
+ if (this._calendar && this._calendar !== "GREGORIAN") {
8725
+ return `${this._calendar} ${withMonths}`;
8726
+ }
8727
+ return withMonths;
8728
+ }
8729
+ toGedcomLines(tag, level = 0, options) {
8730
+ const internal = new RegExp(
8731
+ `^${level} (DAY|MONTH|YEAR)( |$)|^${level} NOTE (Abt\\.|Bef\\.|Aft\\.)$`
8732
+ );
8733
+ return super.toGedcomLines(tag, level, options).filter((line) => !internal.test(line));
8734
+ }
8735
+ inRange(range, trueIfNoYear = false) {
8736
+ return inRange(this.YEAR?.value, range, trueIfNoYear);
8737
+ }
8738
+ };
8739
+ var createCommonDate = (gedcom, id, main, parent) => {
8740
+ return createProxy(
8741
+ new CommonDate(gedcom, id, main, parent)
8742
+ );
8743
+ };
8744
+ var isCommonDate = (value) => {
8745
+ return !!value && value !== null && typeof value === "object" && "_date" in value;
8746
+ };
8747
+
8748
+ // src/utils/family-edit.ts
8749
+ var GEDCOM_MONTHS2 = [
8750
+ "JAN",
8751
+ "FEB",
8752
+ "MAR",
8753
+ "APR",
8754
+ "MAY",
8755
+ "JUN",
8756
+ "JUL",
8757
+ "AUG",
8758
+ "SEP",
8759
+ "OCT",
8760
+ "NOV",
8761
+ "DEC"
8762
+ ];
8763
+ var CREATED_AT_TAG = "_CREATED_AT";
8764
+ var stampCreatedAt = (gedcom, indi, when = /* @__PURE__ */ new Date()) => {
8765
+ const existing = indi.get(CREATED_AT_TAG);
8766
+ if (isCommonDate(existing) && existing.rawValue instanceof Date && !Number.isNaN(existing.rawValue.getTime())) {
8767
+ return;
8768
+ }
8769
+ const dateNode = createCommonDate(gedcom, void 0, indi, indi);
8770
+ dateNode.type = CREATED_AT_TAG;
8771
+ dateNode.value = `${when.getDate()} ${GEDCOM_MONTHS2[when.getMonth()]} ${when.getFullYear()}`;
8772
+ indi.set(CREATED_AT_TAG, dateNode);
8773
+ };
8774
+ var refTypeForTag = (tag) => {
8775
+ if (tag === "FAMS" || tag === "FAMC") return "FAM";
8776
+ return "INDI";
8777
+ };
8778
+ var normalizeSinglePointer = (owner, tag) => {
8779
+ const node = owner.get(tag);
8780
+ if (!node) return;
8781
+ if (node instanceof List && node.length === 1) {
8782
+ const only = node.index(0);
8783
+ if (only) {
8784
+ owner.set(tag, only);
8785
+ return;
8786
+ }
8787
+ const raw = node.values()[0];
8788
+ if (typeof raw === "string") {
8789
+ const gedcom = owner.getGedcom?.();
8790
+ if (gedcom) {
8791
+ owner.set(tag, makePointer(gedcom, owner, raw, refTypeForTag(tag)));
8792
+ }
8793
+ }
8794
+ }
8795
+ };
8796
+ var PEDIGREE_VALUES = [
8797
+ "birth" /* BIRTH */,
8798
+ "adopted" /* ADOPTED */,
8799
+ "foster" /* FOSTER */,
8800
+ "step" /* STEP */,
8801
+ "sealing" /* SEALING */
8802
+ ];
8803
+ var toGedcomPedigree = (value) => {
8804
+ const normalized = String(value || "birth" /* BIRTH */).toLowerCase();
8805
+ if (normalized === "biological" /* BIOLOGICAL */ || normalized === "birth" /* BIRTH */) {
8806
+ return "birth" /* BIRTH */;
8807
+ }
8808
+ const match = PEDIGREE_VALUES.find((item) => item === normalized);
8809
+ return match ?? "birth" /* BIRTH */;
8810
+ };
8811
+ var pointerIds = (tag) => {
8812
+ if (!tag) {
8813
+ return [];
8814
+ }
8815
+ if (tag instanceof List) {
8816
+ return tag.values().map((item) => item?.toValue?.()).filter((value2) => !!value2);
8817
+ }
8818
+ const value = tag.toValue?.();
8819
+ return value ? [String(value)] : [];
8820
+ };
8821
+ var firstPointerId = (tag) => pointerIds(tag)[0];
8822
+ var makePointer = (gedcom, parent, value, refType) => {
8823
+ const pointer = createCommon(gedcom, void 0, parent);
8824
+ pointer.value = value;
8825
+ pointer.refType = refType;
8826
+ return pointer;
8827
+ };
8828
+ var nextRecordId = (ids, prefix) => {
8829
+ let max = 0;
8830
+ ids.forEach((id) => {
8831
+ const match = String(id).match(/(\d+)/);
8832
+ const n = match ? Number.parseInt(match[1], 10) : 0;
8833
+ if (n > max) {
8834
+ max = n;
8835
+ }
8836
+ });
8837
+ return `@${prefix}${max + 1}@`;
8838
+ };
8839
+ var familyHasParent = (fam, indiId) => pointerIds(fam.get("HUSB")).includes(indiId) || pointerIds(fam.get("WIFE")).includes(indiId);
8840
+ var familyHasChild = (fam, indiId) => pointerIds(fam.get("CHIL")).includes(indiId);
8841
+ var spouseTagFor = (indi, fam) => {
8842
+ const husbId = firstPointerId(fam.get("HUSB"));
8843
+ const wifeId = firstPointerId(fam.get("WIFE"));
8844
+ if (husbId === indi.id) {
8845
+ return "HUSB";
8846
+ }
8847
+ if (wifeId === indi.id) {
8848
+ return "WIFE";
8849
+ }
8850
+ if (indi.isFemale()) {
8851
+ return wifeId && wifeId !== indi.id ? "HUSB" : "WIFE";
8852
+ }
8853
+ if (indi.isMale()) {
8854
+ return husbId && husbId !== indi.id ? "WIFE" : "HUSB";
8855
+ }
8856
+ return husbId ? "WIFE" : "HUSB";
8857
+ };
8858
+ var canAttachAsSpouse = (fam, indi) => {
8859
+ if (!indi.id) {
8860
+ return false;
8861
+ }
8862
+ if (familyHasParent(fam, indi.id)) {
8863
+ return true;
8864
+ }
8865
+ const tag = spouseTagFor(indi, fam);
8866
+ const occupied = firstPointerId(fam.get(tag));
8867
+ return !occupied || occupied === indi.id;
8868
+ };
8869
+ var pointerByValue = (tag, id) => {
8870
+ if (!tag) {
8871
+ return void 0;
8872
+ }
8873
+ const fromValues = tag.toValueList?.().item(id);
8874
+ if (fromValues) {
8875
+ return fromValues;
8876
+ }
8877
+ return tag.toList()?.values().find((item) => item?.toValue?.() === id);
8878
+ };
8879
+ var setChildPedigree = (fam, child, pedigree, parent) => {
8880
+ if (!fam.id || !child.id) {
8881
+ return;
8882
+ }
8883
+ const pedi = toGedcomPedigree(pedigree);
8884
+ const famc = pointerByValue(child.get("FAMC"), fam.id);
8885
+ if (famc) {
8886
+ famc.set("PEDI", pedi);
8887
+ }
8888
+ const chil = pointerByValue(fam.get("CHIL"), child.id);
8889
+ if (!chil) {
8890
+ return;
8891
+ }
8892
+ const setFather = !parent || parent.isMale() || parent.isUnknownSex();
8893
+ const setMother = !parent || parent.isFemale() || parent.isUnknownSex();
8894
+ if (setFather) {
8895
+ chil.set("_FREL", pedi);
8896
+ }
8897
+ if (setMother) {
8898
+ chil.set("_MREL", pedi);
8899
+ }
8900
+ };
8901
+ var attachSpouseToFamily = (fam, indi) => {
8902
+ const gedcom = fam.getGedcom() ?? indi.getGedcom();
8903
+ if (!indi.id || !fam.id || !gedcom) {
8904
+ return false;
8905
+ }
8906
+ if (!canAttachAsSpouse(fam, indi)) {
8907
+ return false;
8908
+ }
8909
+ const tag = spouseTagFor(indi, fam);
8910
+ if (firstPointerId(fam.get(tag)) !== indi.id) {
8911
+ fam.set(tag, makePointer(gedcom, fam, indi.id, "INDI"));
8912
+ }
8913
+ indi.assign("FAMS", makePointer(gedcom, indi, fam.id, "FAM"), true);
8914
+ normalizeSinglePointer(indi, "FAMS");
8915
+ normalizeSinglePointer(fam, spouseTagFor(indi, fam));
8916
+ resetRelativesCache();
8917
+ return true;
8918
+ };
8919
+ var attachChildToFamily = (fam, child, pedigree, parent) => {
8920
+ const gedcom = fam.getGedcom() ?? child.getGedcom();
8921
+ if (!child.id || !fam.id || !gedcom) {
8922
+ return false;
8923
+ }
8924
+ if (!familyHasChild(fam, child.id)) {
8925
+ fam.assign("CHIL", makePointer(gedcom, fam, child.id, "INDI"), true);
8926
+ }
8927
+ const existingFamc = pointerByValue(child.get("FAMC"), fam.id);
8928
+ if (!existingFamc) {
8929
+ child.assign("FAMC", makePointer(gedcom, child, fam.id, "FAM"), true);
8930
+ }
8931
+ setChildPedigree(fam, child, pedigree, parent);
8932
+ normalizeSinglePointer(child, "FAMC");
8933
+ normalizeSinglePointer(fam, "CHIL");
8934
+ resetRelativesCache();
8935
+ return true;
8936
+ };
8937
+ var removePointerByValue = (owner, tag, targetId) => {
8938
+ const node = owner.get(tag);
8939
+ if (!node) {
8940
+ return false;
8941
+ }
8942
+ if (node instanceof List) {
8943
+ const keysToRemove = [];
8944
+ node.entries().forEach(([key, item]) => {
8945
+ if (item?.toValue?.() === targetId || item?.id === targetId || String(key) === targetId) {
8946
+ keysToRemove.push(key);
8947
+ }
8948
+ });
8949
+ keysToRemove.forEach((key) => {
8950
+ node.removeItem(key);
8951
+ });
8952
+ if (node.length === 0) {
8953
+ owner.remove(tag);
8954
+ }
8955
+ return keysToRemove.length > 0;
8956
+ }
8957
+ if (node.toValue?.() === targetId) {
8958
+ owner.remove(tag);
8959
+ return true;
8960
+ }
8961
+ const asList = node.toList?.();
8962
+ if (asList && asList.length > 0) {
8963
+ const keysToRemove = [];
8964
+ asList.entries().forEach(([key, item]) => {
8965
+ if (item?.toValue?.() === targetId || item?.id === targetId) {
8966
+ keysToRemove.push(key);
8967
+ }
8968
+ });
8969
+ if (keysToRemove.length === asList.length) {
8970
+ owner.remove(tag);
8971
+ return true;
8972
+ }
8973
+ if (keysToRemove.length > 0) {
8974
+ const remaining = asList.values().filter((item) => item?.toValue?.() !== targetId);
8975
+ if (remaining.length === 1 && remaining[0]) {
8976
+ owner.set(tag, remaining[0]);
8977
+ } else {
8978
+ owner.set(tag, new List(remaining));
8979
+ }
8980
+ return true;
9137
8981
  }
9138
- return withMonths;
9139
8982
  }
9140
- toGedcomLines(tag, level = 0, options) {
9141
- const internal = new RegExp(
9142
- `^${level} (DAY|MONTH|YEAR)( |$)|^${level} NOTE (Abt\\.|Bef\\.|Aft\\.)$`
9143
- );
9144
- return super.toGedcomLines(tag, level, options).filter((line) => !internal.test(line));
8983
+ return false;
8984
+ };
8985
+ var familyMemberCount = (fam) => {
8986
+ let count = 0;
8987
+ if (firstPointerId(fam.get("HUSB"))) {
8988
+ count += 1;
9145
8989
  }
9146
- inRange(range, trueIfNoYear = false) {
9147
- return inRange(this.YEAR?.value, range, trueIfNoYear);
8990
+ if (firstPointerId(fam.get("WIFE"))) {
8991
+ count += 1;
9148
8992
  }
8993
+ count += pointerIds(fam.get("CHIL")).length;
8994
+ return count;
9149
8995
  };
9150
- var createCommonDate = (gedcom, id, main, parent) => {
9151
- return createProxy(
9152
- new CommonDate(gedcom, id, main, parent)
9153
- );
8996
+ var isDegenerateFamily = (fam) => familyMemberCount(fam) <= 1;
8997
+ var pruneEmptyFamilies = (gedcom) => {
8998
+ const emptyIds = [];
8999
+ gedcom.fams()?.forEach((fam, id) => {
9000
+ if (fam && isDegenerateFamily(fam) && id) {
9001
+ emptyIds.push(id);
9002
+ }
9003
+ });
9004
+ if (emptyIds.length === 0) {
9005
+ return [];
9006
+ }
9007
+ gedcom.indis()?.forEach((indi) => {
9008
+ if (!indi) {
9009
+ return;
9010
+ }
9011
+ emptyIds.forEach((famId) => {
9012
+ removePointerByValue(indi, "FAMS", famId);
9013
+ removePointerByValue(indi, "FAMC", famId);
9014
+ });
9015
+ });
9016
+ emptyIds.forEach((famId) => {
9017
+ gedcom.fams()?.removeItem(famId);
9018
+ });
9019
+ return emptyIds;
9154
9020
  };
9155
- var isCommonDate = (value) => {
9156
- return !!value && value !== null && typeof value === "object" && "_date" in value;
9021
+ var findDegenerateFamiliesForIndi = (indi) => {
9022
+ const found = [];
9023
+ const seen = /* @__PURE__ */ new Set();
9024
+ ["FAMC", "FAMS"].forEach((pointer) => {
9025
+ indi.getFamilies(pointer)?.forEach((fam) => {
9026
+ if (!fam?.id || seen.has(fam.id) || !isDegenerateFamily(fam)) {
9027
+ return;
9028
+ }
9029
+ seen.add(fam.id);
9030
+ found.push(fam);
9031
+ });
9032
+ });
9033
+ return found;
9157
9034
  };
9158
-
9159
- // src/utils/fact-edit.ts
9160
- var SINGLETON_TAGS = /* @__PURE__ */ new Set(["BIRT", "DEAT", "SSN", "SEX", "DSCR"]);
9161
- var firstRecord = (node) => {
9162
- if (!node) {
9035
+ var coupleKeyForFam = (fam) => {
9036
+ const husb = firstPointerId(fam.get("HUSB"));
9037
+ const wife = firstPointerId(fam.get("WIFE"));
9038
+ if (!husb || !wife) {
9163
9039
  return void 0;
9164
9040
  }
9165
- if (node instanceof List) {
9166
- return node.index(0);
9167
- }
9168
- return node.index(0) ?? node;
9041
+ return husb < wife ? `${husb}|${wife}` : `${wife}|${husb}`;
9169
9042
  };
9170
- var setDateOn = (gedcom, owner, parent, date) => {
9171
- const trimmed = date.trim();
9172
- if (!trimmed) {
9173
- return;
9043
+ var findDuplicateCoupleFamiliesForIndi = (indi) => {
9044
+ const gedcom = indi.getGedcom();
9045
+ if (!gedcom) {
9046
+ return [];
9174
9047
  }
9175
- let dateNode = parent.get("DATE");
9176
- if (!dateNode || dateNode instanceof List) {
9177
- dateNode = createCommonDate(gedcom, void 0, owner, parent);
9178
- dateNode.type = "DATE";
9179
- parent.set("DATE", dateNode);
9048
+ const relevantKeys = /* @__PURE__ */ new Set();
9049
+ ["FAMC", "FAMS"].forEach((pointer) => {
9050
+ indi.getFamilies(pointer)?.forEach((fam) => {
9051
+ const key = fam ? coupleKeyForFam(fam) : void 0;
9052
+ if (key) {
9053
+ relevantKeys.add(key);
9054
+ }
9055
+ });
9056
+ });
9057
+ if (relevantKeys.size === 0) {
9058
+ return [];
9180
9059
  }
9181
- dateNode.value = trimmed;
9060
+ const byKey = /* @__PURE__ */ new Map();
9061
+ gedcom.fams()?.forEach((fam) => {
9062
+ if (!fam?.id) {
9063
+ return;
9064
+ }
9065
+ const key = coupleKeyForFam(fam);
9066
+ if (!key || !relevantKeys.has(key)) {
9067
+ return;
9068
+ }
9069
+ const list = byKey.get(key) ?? [];
9070
+ list.push(fam);
9071
+ byKey.set(key, list);
9072
+ });
9073
+ return [...byKey.entries()].filter(([, families]) => families.length > 1).map(([key, families]) => ({ key, families }));
9182
9074
  };
9183
- var fillFact = (gedcom, owner, event, input) => {
9184
- if (input.value?.trim()) {
9185
- event.value = input.value.trim();
9075
+ var mergeDuplicateCoupleFamilies = (gedcom, families) => {
9076
+ const usable = families.filter((fam) => !!fam?.id);
9077
+ if (usable.length === 0) {
9078
+ return void 0;
9186
9079
  }
9187
- if (input.type?.trim()) {
9188
- event.set("TYPE", input.type.trim());
9080
+ if (usable.length === 1) {
9081
+ return usable[0];
9189
9082
  }
9190
- if (input.date) {
9191
- setDateOn(gedcom, owner, event, input.date);
9083
+ const sorted = [...usable].sort((a, b) => {
9084
+ const childDiff = pointerIds(b.get("CHIL")).length - pointerIds(a.get("CHIL")).length;
9085
+ if (childDiff !== 0) {
9086
+ return childDiff;
9087
+ }
9088
+ return String(a.id).localeCompare(String(b.id));
9089
+ });
9090
+ const keep = sorted[0];
9091
+ const drops = sorted.slice(1);
9092
+ if (!keep?.id) {
9093
+ return void 0;
9192
9094
  }
9193
- if (input.place?.trim()) {
9194
- event.set("PLAC", input.place.trim());
9095
+ drops.forEach((drop) => {
9096
+ if (!drop?.id || drop.id === keep.id) {
9097
+ return;
9098
+ }
9099
+ pointerIds(drop.get("CHIL")).forEach((childId) => {
9100
+ const child = gedcom.indi(childId);
9101
+ if (!child) {
9102
+ return;
9103
+ }
9104
+ attachChildToFamily(keep, child);
9105
+ removePointerByValue(drop, "CHIL", childId);
9106
+ normalizeSinglePointer(drop, "CHIL");
9107
+ removePointerByValue(child, "FAMC", drop.id);
9108
+ normalizeSinglePointer(child, "FAMC");
9109
+ });
9110
+ const husbId = firstPointerId(drop.get("HUSB"));
9111
+ const wifeId = firstPointerId(drop.get("WIFE"));
9112
+ [husbId, wifeId].forEach((parentId) => {
9113
+ if (!parentId) {
9114
+ return;
9115
+ }
9116
+ const parent = gedcom.indi(parentId);
9117
+ if (parent) {
9118
+ removePointerByValue(parent, "FAMS", drop.id);
9119
+ normalizeSinglePointer(parent, "FAMS");
9120
+ }
9121
+ });
9122
+ gedcom.fams()?.removeItem(drop.id);
9123
+ });
9124
+ resetRelativesCache();
9125
+ return keep;
9126
+ };
9127
+ var pruneFamiliesByIds = (gedcom, famIds) => {
9128
+ const unique = [...new Set(famIds.filter(Boolean))];
9129
+ if (unique.length === 0) {
9130
+ return 0;
9131
+ }
9132
+ gedcom.indis()?.forEach((indi) => {
9133
+ if (!indi) {
9134
+ return;
9135
+ }
9136
+ unique.forEach((famId) => {
9137
+ removePointerByValue(indi, "FAMS", famId);
9138
+ removePointerByValue(indi, "FAMC", famId);
9139
+ });
9140
+ });
9141
+ unique.forEach((famId) => {
9142
+ gedcom.fams()?.removeItem(famId);
9143
+ });
9144
+ return unique.length;
9145
+ };
9146
+ var findSharedSpouseFamily = (parent, coParentId) => {
9147
+ let found;
9148
+ parent.getFamilies("FAMS")?.forEach((fam) => {
9149
+ if (!found && fam && familyHasParent(fam, coParentId)) {
9150
+ found = fam;
9151
+ }
9152
+ });
9153
+ return found;
9154
+ };
9155
+ var unlinkRelative = (anchor, relative, kind) => {
9156
+ if (!anchor.id || !relative.id || anchor.id === relative.id) {
9157
+ return false;
9158
+ }
9159
+ let changed = false;
9160
+ if (kind === "spouse") {
9161
+ anchor.getFamilies("FAMS")?.forEach((fam) => {
9162
+ if (!fam?.id || !familyHasParent(fam, relative.id)) {
9163
+ return;
9164
+ }
9165
+ if (firstPointerId(fam.get("HUSB")) === relative.id) {
9166
+ fam.remove("HUSB");
9167
+ changed = true;
9168
+ }
9169
+ if (firstPointerId(fam.get("WIFE")) === relative.id) {
9170
+ fam.remove("WIFE");
9171
+ changed = true;
9172
+ }
9173
+ changed = removePointerByValue(relative, "FAMS", fam.id) || changed;
9174
+ });
9175
+ } else if (kind === "parent") {
9176
+ anchor.getFamilies("FAMC")?.forEach((fam) => {
9177
+ if (!fam?.id || !familyHasParent(fam, relative.id)) {
9178
+ return;
9179
+ }
9180
+ if (firstPointerId(fam.get("HUSB")) === relative.id) {
9181
+ fam.remove("HUSB");
9182
+ changed = true;
9183
+ }
9184
+ if (firstPointerId(fam.get("WIFE")) === relative.id) {
9185
+ fam.remove("WIFE");
9186
+ changed = true;
9187
+ }
9188
+ changed = removePointerByValue(relative, "FAMS", fam.id) || changed;
9189
+ });
9190
+ } else if (kind === "sibling") {
9191
+ anchor.getFamilies("FAMC")?.forEach((fam) => {
9192
+ if (!fam?.id || !familyHasChild(fam, relative.id)) {
9193
+ return;
9194
+ }
9195
+ changed = removePointerByValue(fam, "CHIL", relative.id) || changed;
9196
+ changed = removePointerByValue(relative, "FAMC", fam.id) || changed;
9197
+ });
9198
+ } else {
9199
+ anchor.getFamilies("FAMS")?.forEach((fam) => {
9200
+ if (!fam?.id || !familyHasChild(fam, relative.id)) {
9201
+ return;
9202
+ }
9203
+ changed = removePointerByValue(fam, "CHIL", relative.id) || changed;
9204
+ changed = removePointerByValue(relative, "FAMC", fam.id) || changed;
9205
+ });
9195
9206
  }
9196
- if (input.note?.trim()) {
9197
- event.set("NOTE", input.note.trim());
9207
+ if (changed) {
9208
+ const gedcom = anchor.getGedcom() ?? relative.getGedcom();
9209
+ if (gedcom) {
9210
+ pruneEmptyFamilies(gedcom);
9211
+ }
9212
+ resetRelativesCache();
9198
9213
  }
9214
+ return changed;
9199
9215
  };
9200
- var updateFactRecord = (owner, event, input) => {
9201
- const gedcom = owner.getGedcom();
9202
- if (!gedcom) {
9203
- return event;
9216
+ var deleteIndividual = (gedcom, indiId) => {
9217
+ const indi = gedcom.indi(indiId);
9218
+ if (!indi?.id) {
9219
+ return false;
9204
9220
  }
9205
- const asOwner = owner;
9206
- if (input.value !== void 0) {
9207
- const trimmed = input.value.trim();
9208
- if (trimmed) {
9209
- event.value = trimmed;
9210
- } else {
9211
- event.removeValue();
9221
+ const famsIds = pointerIds(indi.get("FAMS"));
9222
+ const famcIds = pointerIds(indi.get("FAMC"));
9223
+ famsIds.forEach((famId) => {
9224
+ const fam = gedcom.fam(famId);
9225
+ if (!fam) {
9226
+ return;
9212
9227
  }
9213
- }
9214
- if (input.type !== void 0) {
9215
- const trimmed = input.type.trim();
9216
- if (trimmed) {
9217
- event.set("TYPE", trimmed);
9218
- } else {
9219
- event.remove("TYPE");
9228
+ if (firstPointerId(fam.get("HUSB")) === indiId) {
9229
+ fam.remove("HUSB");
9220
9230
  }
9221
- }
9222
- if (input.date !== void 0) {
9223
- const trimmed = input.date.trim();
9224
- if (trimmed) {
9225
- setDateOn(gedcom, asOwner, event, trimmed);
9226
- } else {
9227
- event.remove("DATE");
9231
+ if (firstPointerId(fam.get("WIFE")) === indiId) {
9232
+ fam.remove("WIFE");
9228
9233
  }
9229
- }
9230
- if (input.place !== void 0) {
9231
- const trimmed = input.place.trim();
9232
- if (trimmed) {
9233
- event.set("PLAC", trimmed);
9234
- } else {
9235
- event.remove("PLAC");
9234
+ });
9235
+ famcIds.forEach((famId) => {
9236
+ const fam = gedcom.fam(famId);
9237
+ if (fam) {
9238
+ removePointerByValue(fam, "CHIL", indiId);
9236
9239
  }
9237
- }
9238
- if (input.note !== void 0) {
9239
- const trimmed = input.note.trim();
9240
- if (trimmed) {
9241
- event.set("NOTE", trimmed);
9242
- } else {
9243
- event.remove("NOTE");
9240
+ });
9241
+ gedcom.fams()?.forEach((fam) => {
9242
+ if (fam && familyHasChild(fam, indiId)) {
9243
+ removePointerByValue(fam, "CHIL", indiId);
9244
+ }
9245
+ if (fam && familyHasParent(fam, indiId)) {
9246
+ if (firstPointerId(fam.get("HUSB")) === indiId) {
9247
+ fam.remove("HUSB");
9248
+ }
9249
+ if (firstPointerId(fam.get("WIFE")) === indiId) {
9250
+ fam.remove("WIFE");
9251
+ }
9244
9252
  }
9245
- }
9246
- return event;
9247
- };
9248
- var setFamilyMarriage = (fam, input) => {
9249
- const existing = firstRecord(fam.get("MARR"));
9250
- if (existing) {
9251
- return updateFactRecord(fam, existing, {
9252
- date: input.date,
9253
- place: input.place
9254
- });
9255
- }
9256
- return addFamilyFact(fam, {
9257
- tag: "MARR",
9258
- date: input.date,
9259
- place: input.place
9260
9253
  });
9254
+ gedcom.indis()?.removeItem(indiId);
9255
+ pruneEmptyFamilies(gedcom);
9256
+ resetRelativesCache();
9257
+ return true;
9261
9258
  };
9262
- var addIndividualFact = (indi, input) => {
9263
- const gedcom = indi.getGedcom();
9264
- if (!gedcom) {
9259
+ var findReusableParentChildFamily = (parent, child, options) => {
9260
+ if (!parent.id || !child.id) {
9265
9261
  return void 0;
9266
9262
  }
9267
- const tag = input.tag;
9268
- let event = SINGLETON_TAGS.has(tag) ? firstRecord(indi.get(tag)) : void 0;
9269
- if (!event) {
9270
- event = createCommon(gedcom, void 0, indi);
9271
- event.type = tag;
9272
- if (SINGLETON_TAGS.has(tag)) {
9273
- indi.set(tag, event);
9274
- } else {
9275
- indi.assign(tag, event);
9263
+ const reuseParentFamilies = options?.reuseParentFamilies !== false;
9264
+ const gedcom = parent.getGedcom() ?? child.getGedcom();
9265
+ let reusableFamc;
9266
+ let coupleFam;
9267
+ let already = false;
9268
+ const noteCoupleWith = (coParentId) => {
9269
+ if (!coParentId || coParentId === parent.id || coupleFam || !parent.id) {
9270
+ return;
9271
+ }
9272
+ const shared = findSharedSpouseFamily(parent, coParentId);
9273
+ if (shared) {
9274
+ coupleFam = shared;
9275
+ }
9276
+ };
9277
+ child.getFamilies("FAMC")?.forEach((fam) => {
9278
+ if (!fam) {
9279
+ return;
9280
+ }
9281
+ if (familyHasParent(fam, parent.id) && familyHasChild(fam, child.id)) {
9282
+ already = true;
9283
+ return;
9276
9284
  }
9285
+ pointerIds(fam.get("HUSB")).forEach(noteCoupleWith);
9286
+ pointerIds(fam.get("WIFE")).forEach(noteCoupleWith);
9287
+ if (!reusableFamc && canAttachAsSpouse(fam, parent)) {
9288
+ reusableFamc = fam;
9289
+ }
9290
+ });
9291
+ if (already) {
9292
+ return "already";
9277
9293
  }
9278
- fillFact(gedcom, indi, event, input);
9279
- return event;
9280
- };
9281
- var addFamilyFact = (fam, input) => {
9282
- const gedcom = fam.getGedcom();
9283
- if (!gedcom) {
9284
- return void 0;
9294
+ if (coupleFam) {
9295
+ return coupleFam;
9285
9296
  }
9286
- const event = createCommon(gedcom, void 0, fam);
9287
- event.type = input.tag;
9288
- fam.assign(input.tag, event);
9289
- fillFact(gedcom, fam, event, input);
9290
- return event;
9291
- };
9292
- var setCauseOfDeath = (indi, text) => {
9293
- const trimmed = text.trim();
9294
- if (!trimmed) {
9295
- return void 0;
9297
+ if (reusableFamc) {
9298
+ return reusableFamc;
9296
9299
  }
9297
- const death = firstRecord(indi.get("DEAT")) || addIndividualFact(indi, { tag: "DEAT", value: "Y" });
9298
- if (!death) {
9299
- return void 0;
9300
+ if (options?.targetFamilyId && gedcom) {
9301
+ const target = gedcom.fam(options.targetFamilyId);
9302
+ if (target && (familyHasParent(target, parent.id) || canAttachAsSpouse(target, parent))) {
9303
+ return target;
9304
+ }
9300
9305
  }
9301
- death.set("CAUS", trimmed);
9302
- return death;
9303
- };
9304
- var setDeceased = (indi, deceased) => {
9305
- if (!deceased) {
9306
- indi.remove("DEAT");
9307
- return;
9306
+ if (!reuseParentFamilies) {
9307
+ return void 0;
9308
9308
  }
9309
- if (firstRecord(indi.get("DEAT"))) {
9310
- return;
9309
+ const parentFams = [];
9310
+ parent.getFamilies("FAMS")?.forEach((fam) => {
9311
+ if (fam) {
9312
+ parentFams.push(fam);
9313
+ }
9314
+ });
9315
+ if (parentFams.length === 1) {
9316
+ return parentFams[0];
9311
9317
  }
9312
- addIndividualFact(indi, { tag: "DEAT", value: "Y" });
9318
+ return void 0;
9313
9319
  };
9314
- var addNonEvent = (owner, input) => {
9315
- const gedcom = owner.getGedcom();
9316
- const eventType = input.event?.trim().toUpperCase();
9317
- if (!gedcom || !eventType) {
9318
- return void 0;
9320
+ var consolidateChildIntoFamily = (child, keep) => {
9321
+ if (!child.id || !keep.id) {
9322
+ return [];
9319
9323
  }
9320
- const no = createCommon(gedcom, void 0, owner);
9321
- no.type = "NO";
9322
- no.value = eventType;
9323
- if (input.date?.trim()) {
9324
- setDateOn(gedcom, owner, no, input.date);
9324
+ const keepParentIds = /* @__PURE__ */ new Set([
9325
+ ...pointerIds(keep.get("HUSB")),
9326
+ ...pointerIds(keep.get("WIFE"))
9327
+ ]);
9328
+ const removed = [];
9329
+ child.getFamilies("FAMC")?.forEach((fam) => {
9330
+ if (!fam?.id || fam.id === keep.id) {
9331
+ return;
9332
+ }
9333
+ const famParentIds = [
9334
+ ...pointerIds(fam.get("HUSB")),
9335
+ ...pointerIds(fam.get("WIFE"))
9336
+ ];
9337
+ if (famParentIds.length === 0 || !famParentIds.every((id) => keepParentIds.has(id))) {
9338
+ return;
9339
+ }
9340
+ removePointerByValue(fam, "CHIL", child.id);
9341
+ normalizeSinglePointer(fam, "CHIL");
9342
+ removePointerByValue(child, "FAMC", fam.id);
9343
+ normalizeSinglePointer(child, "FAMC");
9344
+ removed.push(fam.id);
9345
+ });
9346
+ const gedcom = child.getGedcom() ?? keep.getGedcom();
9347
+ if (gedcom && removed.length > 0) {
9348
+ pruneEmptyFamilies(gedcom);
9325
9349
  }
9326
- if (input.note?.trim()) {
9327
- no.set("NOTE", input.note.trim());
9350
+ if (removed.length > 0) {
9351
+ resetRelativesCache();
9328
9352
  }
9329
- owner.assign("NO", no);
9330
- return no;
9353
+ return removed;
9331
9354
  };
9332
9355
 
9333
9356
  // src/classes/fam.ts
@@ -9902,7 +9925,7 @@ var createGedcomUid = () => {
9902
9925
  };
9903
9926
 
9904
9927
  // src/utils/gedcom7-metadata.ts
9905
- var GEDCOM_MONTHS2 = [
9928
+ var GEDCOM_MONTHS3 = [
9906
9929
  "JAN",
9907
9930
  "FEB",
9908
9931
  "MAR",
@@ -9918,7 +9941,7 @@ var GEDCOM_MONTHS2 = [
9918
9941
  ];
9919
9942
  var formatGedcom7Timestamp = (date = /* @__PURE__ */ new Date()) => {
9920
9943
  const day = String(date.getUTCDate());
9921
- const month = GEDCOM_MONTHS2[date.getUTCMonth()];
9944
+ const month = GEDCOM_MONTHS3[date.getUTCMonth()];
9922
9945
  const year = String(date.getUTCFullYear());
9923
9946
  const hh = String(date.getUTCHours()).padStart(2, "0");
9924
9947
  const mm = String(date.getUTCMinutes()).padStart(2, "0");
@@ -9996,6 +10019,7 @@ var TREEVIZ_EXTENSION_URIS = {
9996
10019
  _MTTAG: `${TREEVIZ_EXTENSION_BASE_URI}#_MTTAG`,
9997
10020
  _MTCAT: `${TREEVIZ_EXTENSION_BASE_URI}#_MTCAT`,
9998
10021
  _CLON: `${TREEVIZ_EXTENSION_BASE_URI}#_CLON`,
10022
+ _CREATED_AT: `${TREEVIZ_EXTENSION_BASE_URI}#_CREATED_AT`,
9999
10023
  _MSER: `${TREEVIZ_EXTENSION_BASE_URI}#_MSER`,
10000
10024
  _OID: `${TREEVIZ_EXTENSION_BASE_URI}#_OID`,
10001
10025
  _LKID: `${TREEVIZ_EXTENSION_BASE_URI}#_LKID`,
@@ -10151,7 +10175,7 @@ var collectExtensionTagsFrom = (node, into = /* @__PURE__ */ new Set()) => {
10151
10175
  // package.json
10152
10176
  var package_default = {
10153
10177
  name: "@treeviz/gedcom-parser",
10154
- version: "2.1.22"};
10178
+ version: "2.1.23"};
10155
10179
 
10156
10180
  // src/utils/get-product-details.ts
10157
10181
  var isDevelopment = () => {
@@ -11414,6 +11438,7 @@ var mergeGedcoms = (targetGedcom, sourceGedcom, strategy = "id") => {
11414
11438
  }
11415
11439
  } else {
11416
11440
  if (clonedIndi.id) {
11441
+ stampCreatedAt(mergedGedcom, clonedIndi);
11417
11442
  mergedGedcom.indis()?.item(clonedIndi.id, clonedIndi);
11418
11443
  }
11419
11444
  }
@@ -11538,7 +11563,7 @@ var create = (gedcom, type, id, nodes) => {
11538
11563
  prevNode = createSour(gedcom, void 0, mainNode, curNode);
11539
11564
  } else if (type === "OBJE") {
11540
11565
  prevNode = createObje(gedcom, void 0, mainNode, curNode);
11541
- } else if (type === "DATE") {
11566
+ } else if (type === "DATE" || type === "_CREATED_AT") {
11542
11567
  prevNode = createCommonDate(gedcom, void 0, mainNode, curNode);
11543
11568
  } else if (type === "NOTE" || type === "SNOTE" || type === "_TREEVIZ_LIFE_STORY" || type === "_TREEVIZ_FAMILY_STORY") {
11544
11569
  prevNode = createCommonNote(gedcom, void 0, mainNode, curNode);
@@ -11829,4 +11854,4 @@ var createEmptyGedcom = (options) => {
11829
11854
  return gedcom;
11830
11855
  };
11831
11856
 
11832
- export { ACCEPTED_DATE_FORMATS, ACCEPTED_DATE_FORMATS_REGEX, ADOPTED, ANCESTRY_MEDIA_RETRIEVAL_PREFIX, ANCESTRY_TREE_MEDIA_NAMESPACE, APP_BRANDING, BIOLOGICAL, BIRTH, BIRTH_ASC, BIRTH_DESC, Common, CommonDate, CommonName, CommonNote, CustomTags, DATE_ASC, DATE_DESC, DEATH_ASC, DEATH_DESC, DEFAULT, DEFAULT_GEDCOM_EXPORT_VERSION, EVERY, Existed, FEMALE, FOSTER, FRIEND, Fam, Families, GEDCOM7_CALENDARS, GEDCOM7_PEDI_VALUES, GEDCOM7_RESN_VALUES, GEDCOM7_ROLE_VALUES, GEDCOM7_SEX_VALUES, GEDCOM_EXPORT_VERSIONS, GEDZIP_EXTENSION, GEDZIP_GEDCOM_ENTRY, GEDZIP_MIME, GedCom, parser_default as GedcomTree, ID_GETTER_REG, ID_REG, ID_SPLIT_REG, Indi, Individuals, KinshipTranslator, KinshipTranslatorBasic, KinshipTranslatorDe as KinshipTranslatorDE, KinshipTranslatorEn as KinshipTranslatorEN, KinshipTranslatorEs as KinshipTranslatorES, KinshipTranslatorFr as KinshipTranslatorFR, KinshipTranslatorHU, KinshipTranslatorJa as KinshipTranslatorJA, KinshipTranslatorRu as KinshipTranslatorRU, KinshipTranslatorZh as KinshipTranslatorZH, LINE_REG, List, MALE, MAX_FILE_SIZE_TO_SYNC, ORIG_HEAD_TAG, OTHER, Obje, Objects, PARTNER, PEDIGREE_VALUES, PartnerType, PlaceType, REF_LINE_REG, Range, RelationType, Repo, Repositories, SEALING, SINGLE, SPOUSE, STEP, Sour, Sources, Subm, Submitters, TREEVIZ_EXTENSION_BASE_URI, TREEVIZ_EXTENSION_URIS, UNKOWN, addFamilyFact, addIndividualFact, addNonEvent, ancestryMediaFileUrl, applyGedcom7DatePhrases, applyGedcom7Enumerations, applyGedcom7RecordMetadata, attachChildToFamily, attachSpouseToFamily, buildGedzip, buildGedzipBlob, bytesToDataUrl, cacheDiscoveredPath, canAttachAsSpouse, collectExtensionTagsFrom, commonDateFormatter, consolidateChildIntoFamily, coupleKeyForFam, create, createCommon, createCommonDate, createCommonName, createCommonNote, createEmptyGedcom, createFam, createGedCom, createGedcomUid, createIndi, createObje, createProxy, createRepo, createSour, createSubm, dateFormatter, parser_default as default, deleteIndividual, downloadGedzipMedia, ensureExtensionSchema, extractGedzip, extractGedzipGedcom, extractSeparationYears, extractSplitPoints, familyHasChild, familyHasParent, findDegenerateFamiliesForIndi, findDuplicateCoupleFamiliesForIndi, findMatchingRangeForSplitRange, findReusableParentChildFamily, firstPointerId, formatGedcom7Timestamp, fromTuple, generateSplitRanges, getAllProp, getBirthAsc, getCacheManagerFactory, getDateLocale, getExtensionSchema, getFamilyWith, getFileExtension, getI18n, getKinshipTranslatorClass, getListTag, getMarriageAsc, getMarriageAscAndBirth, getMarriageAscAndChildBirth, getName, getNameAsc, getNameAscAndBirth, getNameDesc, getPlaceParserProvider, getPlaceParts, getPlaceTranslatorProvider, getPlaces, getRawSize, getValidKey, getValidKeys, getValidTag, getVersion, hungarianOrdinalize, i18n, idGetter, implemented, inRange, inferMediaForm, initializeCache, isAncestryOriginObje, isCommonDate, isDegenerateFamily, isDevelopment, isGedcom7, isGedcomString, isGedzipContainer, isId, isImageFormat, isIntersectedRange, isObjePointer, isOnlyMainProp, isRangeContained, isRemoteOrEmbeddedMediaUrl, isValidKey, makePointer, marriageDateFormatter, mergeDuplicateCoupleFamilies, mergeGedcoms, mergeMediaLists, mergeMediaListsByObjeKey, nameFormatter, nextRecordId, normalizeGedcomVersion, notImplemented, noteDateFormatter, objeNoteValue, objeXrefKey, ordinalize, parseAncestryNamespaceFromUrl, parseGedcom7CalendarPrefix, parseRangeBounds, pathCache, placeTranslator, pointerIds, profilePictureCache, pruneEmptyFamilies, pruneFamiliesByIds, registerExtensionTag, relativesCache, remountGedzipMediaAsDataUrls, removePointerByValue, resetCacheManagerFactory, resetDateLocaleProvider, resetI18nProvider, resetKinshipTranslatorClass, resetPlaceParserProvider, resetPlaceTranslatorProvider, resetRelativesCache, resolveLocalMediaUrl, resolveMediaContent, resolveObjeForm, resolveObjeMediaId, rewriteGedcomFilePaths, setCacheManagerFactory, setCauseOfDeath, setChildPedigree, setDateLocaleProvider, setDeceased, setFamilyMarriage, setI18nProvider, setKinshipTranslatorClass, setLocalMediaResolver, setMediaContentResolver, setNestedGroup, setPlaceParserProvider, setPlaceTranslatorProvider, splitOverlappingRanges, splitRange, spouseTagFor, toGedcomPedigree, translators_exports as translators, unlinkRelative, updateFactRecord, validateGedcomContent, withGedcom7Calendar };
11857
+ export { ACCEPTED_DATE_FORMATS, ACCEPTED_DATE_FORMATS_REGEX, ADOPTED, ANCESTRY_MEDIA_RETRIEVAL_PREFIX, ANCESTRY_TREE_MEDIA_NAMESPACE, APP_BRANDING, BIOLOGICAL, BIRTH, BIRTH_ASC, BIRTH_DESC, CREATED_AT_TAG, Common, CommonDate, CommonName, CommonNote, CustomTags, DATE_ASC, DATE_DESC, DEATH_ASC, DEATH_DESC, DEFAULT, DEFAULT_GEDCOM_EXPORT_VERSION, EVERY, Existed, FEMALE, FOSTER, FRIEND, Fam, Families, GEDCOM7_CALENDARS, GEDCOM7_PEDI_VALUES, GEDCOM7_RESN_VALUES, GEDCOM7_ROLE_VALUES, GEDCOM7_SEX_VALUES, GEDCOM_EXPORT_VERSIONS, GEDZIP_EXTENSION, GEDZIP_GEDCOM_ENTRY, GEDZIP_MIME, GedCom, parser_default as GedcomTree, ID_GETTER_REG, ID_REG, ID_SPLIT_REG, Indi, Individuals, KinshipTranslator, KinshipTranslatorBasic, KinshipTranslatorDe as KinshipTranslatorDE, KinshipTranslatorEn as KinshipTranslatorEN, KinshipTranslatorEs as KinshipTranslatorES, KinshipTranslatorFr as KinshipTranslatorFR, KinshipTranslatorHU, KinshipTranslatorJa as KinshipTranslatorJA, KinshipTranslatorRu as KinshipTranslatorRU, KinshipTranslatorZh as KinshipTranslatorZH, LINE_REG, List, MALE, MAX_FILE_SIZE_TO_SYNC, ORIG_HEAD_TAG, OTHER, Obje, Objects, PARTNER, PEDIGREE_VALUES, PartnerType, PlaceType, REF_LINE_REG, Range, RelationType, Repo, Repositories, SEALING, SINGLE, SPOUSE, STEP, Sour, Sources, Subm, Submitters, TREEVIZ_EXTENSION_BASE_URI, TREEVIZ_EXTENSION_URIS, UNKOWN, addFamilyFact, addIndividualFact, addNonEvent, ancestryMediaFileUrl, applyGedcom7DatePhrases, applyGedcom7Enumerations, applyGedcom7RecordMetadata, attachChildToFamily, attachSpouseToFamily, buildGedzip, buildGedzipBlob, bytesToDataUrl, cacheDiscoveredPath, canAttachAsSpouse, collectExtensionTagsFrom, commonDateFormatter, consolidateChildIntoFamily, coupleKeyForFam, create, createCommon, createCommonDate, createCommonName, createCommonNote, createEmptyGedcom, createFam, createGedCom, createGedcomUid, createIndi, createObje, createProxy, createRepo, createSour, createSubm, dateFormatter, parser_default as default, deleteIndividual, downloadGedzipMedia, ensureExtensionSchema, extractGedzip, extractGedzipGedcom, extractSeparationYears, extractSplitPoints, familyHasChild, familyHasParent, findDegenerateFamiliesForIndi, findDuplicateCoupleFamiliesForIndi, findMatchingRangeForSplitRange, findReusableParentChildFamily, firstPointerId, formatGedcom7Timestamp, fromTuple, generateSplitRanges, getAllProp, getBirthAsc, getCacheManagerFactory, getDateLocale, getExtensionSchema, getFamilyWith, getFileExtension, getI18n, getKinshipTranslatorClass, getListTag, getMarriageAsc, getMarriageAscAndBirth, getMarriageAscAndChildBirth, getName, getNameAsc, getNameAscAndBirth, getNameDesc, getPlaceParserProvider, getPlaceParts, getPlaceTranslatorProvider, getPlaces, getRawSize, getValidKey, getValidKeys, getValidTag, getVersion, hungarianOrdinalize, i18n, idGetter, implemented, inRange, inferMediaForm, initializeCache, isAncestryOriginObje, isCommonDate, isDegenerateFamily, isDevelopment, isGedcom7, isGedcomString, isGedzipContainer, isId, isImageFormat, isIntersectedRange, isObjePointer, isOnlyMainProp, isRangeContained, isRemoteOrEmbeddedMediaUrl, isValidKey, makePointer, marriageDateFormatter, mergeDuplicateCoupleFamilies, mergeGedcoms, mergeMediaLists, mergeMediaListsByObjeKey, nameFormatter, nextRecordId, normalizeGedcomVersion, notImplemented, noteDateFormatter, objeNoteValue, objeXrefKey, ordinalize, parseAncestryNamespaceFromUrl, parseGedcom7CalendarPrefix, parseRangeBounds, pathCache, placeTranslator, pointerIds, profilePictureCache, pruneEmptyFamilies, pruneFamiliesByIds, registerExtensionTag, relativesCache, remountGedzipMediaAsDataUrls, removePointerByValue, resetCacheManagerFactory, resetDateLocaleProvider, resetI18nProvider, resetKinshipTranslatorClass, resetPlaceParserProvider, resetPlaceTranslatorProvider, resetRelativesCache, resolveLocalMediaUrl, resolveMediaContent, resolveObjeForm, resolveObjeMediaId, rewriteGedcomFilePaths, setCacheManagerFactory, setCauseOfDeath, setChildPedigree, setDateLocaleProvider, setDeceased, setFamilyMarriage, setI18nProvider, setKinshipTranslatorClass, setLocalMediaResolver, setMediaContentResolver, setNestedGroup, setPlaceParserProvider, setPlaceTranslatorProvider, splitOverlappingRanges, splitRange, spouseTagFor, stampCreatedAt, toGedcomPedigree, translators_exports as translators, unlinkRelative, updateFactRecord, validateGedcomContent, withGedcom7Calendar };