Installation

npm install family-tree-viewer

Or via CDN (UMD bundle, no build step required):

<script src="https://unpkg.com/family-tree-viewer"></script>

Quick start

import { FamilyTreeViewer } from 'family-tree-viewer';

const viewer = new FamilyTreeViewer('#container', {
  theme: 'light',
  readonly: false,
  onSave: (gedcom) => localStorage.setItem('tree', gedcom),
});

// Load a GEDCOM file
const text = await fetch('family.ged').then(r => r.text());
viewer.loadGedcom(text);

// — or — load ancestors from WikiTree
await viewer.loadWikiTree('Einstein-1', { depth: 3 });

Constructor options

new FamilyTreeViewer(container, options?) — container is a CSS selector string or HTMLElement.

OptionTypeDefaultDescription
gedcomstring—Initial GEDCOM text to load on construction.
rootIdstringautoGEDCOM @I…@ id of the root person for layout.
theme'light' | 'dark''light'Visual theme.
readonlybooleanfalseHides all editing controls when true.
onSave(gedcom: string) => void—Called after any edit with the serialised GEDCOM string.

Public methods

MethodDescription
loadGedcom(text: string) Parse and render a GEDCOM string. Replaces any previously loaded tree.
loadWikiTree(id, opts?) async Fetch ancestors from WikiTree by profile key (e.g. 'Washington-1'). opts.depth (1–4, default 3) controls how many ancestor generations to retrieve.
getGedcom(): string Serialise the current in-memory tree to a GEDCOM 5.5.1 string.
fitToScreen() Pan and zoom to fit the entire tree in the container.
selectPerson(id: string) Programmatically select a person by their GEDCOM id and open the side panel.
destroy() Remove all event listeners and DOM nodes. Call before removing the container.

WikiTree integration

loadWikiTree calls the public WikiTree API (getAncestors action) directly from the browser — no server proxy required, as WikiTree supports CORS for public profiles.

try {
  await viewer.loadWikiTree('Darwin-15', { depth: 2 });
} catch (err) {
  if (err.name === 'WikiTreeError') {
    console.error('WikiTree error:', err.message);
  }
}

GEDCOM support

Parser targets GEDCOM 5.5.1. Supported features:

Not currently parsed: sources (SOUR), repositories, multimedia, custom tags (_XXX).

TypeScript types

All public types are re-exported from the package entry point:

import type { Individual, Family, EventRecord, Sex } from 'family-tree-viewer';
TypeKey fields
Individualid, givenName, surname, sex, birth?, death?, familyAsChild?, familiesAsSpouse[]
Familyid, husbandId?, wifeId?, childIds[], marriage?
EventRecordtype, date?, year?, place?
Sex'M' | 'F' | 'U'

License

Released under the AGPL-3.0 license. If you deploy this library as part of a network service, you must make the complete source code available to users of that service. See the LICENSE file for details.