@famtree/core 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +84 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @famtree/core
2
+
3
+ [![npm](https://img.shields.io/npm/v/@famtree/core.svg)](https://www.npmjs.com/package/@famtree/core)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/felipeplets/famtree/blob/main/LICENSE)
5
+
6
+ The runtime-agnostic **domain graph and layout engine** for
7
+ [famtree](https://github.com/felipeplets/famtree) genograms. It turns a document
8
+ compliant with [`@famtree/schema`](https://www.npmjs.com/package/@famtree/schema) into a
9
+ queryable family graph and computes 2D positions for each person — with **no SVG or DOM
10
+ knowledge**.
11
+
12
+ > This is an internal building block. Most users want
13
+ > [`@famtree/cli`](https://www.npmjs.com/package/@famtree/cli) or
14
+ > [`@famtree/renderer`](https://www.npmjs.com/package/@famtree/renderer). Reach for
15
+ > `@famtree/core` when you're building a **custom renderer** or your own layout on top of
16
+ > the genogram model.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @famtree/core
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import { GenogramGraph, GenerationalLayout } from "@famtree/core"
28
+ import type { Genogram } from "@famtree/schema"
29
+
30
+ const doc: Genogram = /* ... */ ({} as Genogram)
31
+
32
+ // 1. Build the domain graph (resolves generations, parents, unions, siblings).
33
+ const graph = new GenogramGraph(doc)
34
+
35
+ // 2. Compute positions with the default generational layout.
36
+ const positions = new GenerationalLayout().layout(graph)
37
+
38
+ const { width, height } = positions.bounds()
39
+ for (const person of graph.roster) {
40
+ const x = positions.cx(person.id)
41
+ const y = positions.cy(person.id)
42
+ // feed (x, y) into your own renderer
43
+ }
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `GenogramGraph`
49
+
50
+ Wraps a `Genogram` document and answers structural queries:
51
+
52
+ - `roster` — all people.
53
+ - `parentsOf(id)`, `parentLinkOf(id)` — a person's parents / parent-child link.
54
+ - `unionHeadedBy(id)`, `childrenOfUnion(unionId)`, `singleChildrenOf(id)`.
55
+ - `sortByBirth(ids)` — order sibling ids by birth order.
56
+ - `generationOf(id)` — computed generation index.
57
+
58
+ ### `GenerationalLayout` (implements `LayoutEngine`)
59
+
60
+ `layout(graph): Positions` — assigns coordinates by generation, centering parents over
61
+ their children and spacing siblings.
62
+
63
+ ### `Positions`
64
+
65
+ - `cx(id)` / `cy(id)` — center x / y for a person.
66
+ - `bounds()` — `{ width, height }` of the laid-out diagram.
67
+
68
+ ### Layout constants
69
+
70
+ Geometry defaults are exported for reuse/inspection: `NODE`, `R`, `GEN_SPACING`,
71
+ `SIB_STEP`, `SPOUSE_HALF`, `MARGIN`, `LABEL_WRAP`, `LABEL_LINE_H`.
72
+
73
+ ## Related packages
74
+
75
+ | Package | Description |
76
+ |---------|-------------|
77
+ | [`@famtree/cli`](https://www.npmjs.com/package/@famtree/cli) | `famtree` command-line renderer |
78
+ | [`@famtree/schema`](https://www.npmjs.com/package/@famtree/schema) | JSON Schema + TypeScript types |
79
+ | [`@famtree/renderer`](https://www.npmjs.com/package/@famtree/renderer) | SVG renderer |
80
+ | [`@famtree/validate`](https://www.npmjs.com/package/@famtree/validate) | Optional Ajv-backed schema validation |
81
+
82
+ ## License
83
+
84
+ MIT © Felipe Plets
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@famtree/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Runtime-agnostic genogram engine: domain graph and layout.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,10 +26,11 @@
26
26
  }
27
27
  },
28
28
  "files": [
29
+ "README.md",
29
30
  "dist"
30
31
  ],
31
32
  "dependencies": {
32
- "@famtree/schema": "0.1.1"
33
+ "@famtree/schema": "0.1.3"
33
34
  },
34
35
  "scripts": {
35
36
  "build": "tsup && tsc -p tsconfig.build.json",