@captiveorigins/onepedigree-react

中文文档
0.1.0-alpha.13发布于 2026/11/09PolyForm-Noncommercial-1.0.0TypeScriptES Module构建来源已验证近 30 天下载 1821

OnePedigree for React: server-renderable SVG pedigree views (all 13), an interactive explorer, headless hooks and CSS-variable styling.

原始使用文档
文档目录7 节
  1. Views
  2. Rearranging by drag
  3. Themes and colors
  4. Brand family
  5. Styling
  6. Accessibility
  7. License

@captiveorigins/onepedigree-react

Server-renderable SVG pedigree views for React, built on @captiveorigins/onepedigree-core.

import { layoutPedigree, projectPedigree } from '@captiveorigins/onepedigree-core'
import { PedigreeExplorer, PedigreeView } from '@captiveorigins/onepedigree-react'
import '@captiveorigins/onepedigree-react/styles.css'

// Static (server component, no client JavaScript; nodes are ordinary links):
export async function AnimalPedigree({ document, focalId }) {
  const projection = projectPedigree(document, { focalId, view: 'pedigree', ancestorDepth: 4, maxNodes: 500 })
  const layout = await layoutPedigree(projection, { orientation: 'vertical' })
  return <PedigreeView projection={projection} layout={layout} getIndividualHref={(a) => `/animals/${a.id}`} />
}

// Interactive (client): pan, zoom, fit, selection, highlighting, keyboard, quick view, SVG/print export.
<PedigreeExplorer projection={projection} layout={layout} height="32rem" />

Views

All 13 views of the core: pedigree, fan, ahnentafel, descendants, hourglass, cohort, relationship, timeline, inbreeding, population, compact, maternal, paternal. Repeated individuals follow the projection's merge, separate or hybrid mode; selecting one occurrence highlights every occurrence of that individual.

Rearranging by drag

In views where order is a choice (descendants, hourglass, cohort, population, relationship), people can drag a node sideways to reorder it among its siblings. Ancestor charts keep the father/mother convention. A node only moves within its own drawn groups (a clutch or litter frame) and among individuals with the same parents, so frames and family lines stay truthful. The data never changes: the order is a layout option you keep (and may save).

const [nodeOrder, setNodeOrder] = useState<string[]>([])
const layout = useMemo(() => layoutSync(projection, { nodeOrder }), [projection, nodeOrder])

<PedigreeExplorer projection={projection} layout={layout} nodeOrder={nodeOrder} onNodeOrderChange={setNodeOrder} />

dropNodeOrder(layout, occurrenceId, delta, current, groupOf) is exported for custom UIs.

Themes and colors

Seven presets, each with its own per-view accents (e.g. warm maternal and cool paternal lines, distinct highlights for the relationship and inbreeding views, fan ring shading): classic, midnight, forest, ocean, terracotta, high-contrast, print.

<PedigreeView projection={projection} layout={layout} theme="forest" />
<PedigreeExplorer projection={projection} layout={layout} theme="ocean" themeEditor onThemeChange={save} />

themeEditor adds a Colors button: choose a preset and adjust any color with a color picker or hex code, for all views or only the current one, with a warning when text contrast drops below WCAG AA. onThemeChange receives the edited theme (a plain object) to store; pass it back as theme. ThemeEditor is also exported for use in your own settings pages. Themes are rendered as inline custom properties, so they work in server rendering.

Brand family

OnePedigree and OneTaxonomy share a backbone (brand/README.md): the same line icons (Icon, ICON_PATHS), 32 px controls, a floating canvas toolbar and a Captive Origins orange focus ring, while each keeps its own views and character.

Styling

  • Default stylesheet styles.css (optional; leave it out for unstyled mode).
  • CSS custom properties: --op-node-background, --op-node-border, --op-connector, --op-selected-ring, --op-highlight, --op-focal-border, --op-label, …
  • Stable classes (.op-root, .op-node, .op-individual, .op-connector, .op-junction, .op-cohort, .op-fan-segment) and data attributes (data-individual, data-occurrence, data-repeated, data-generation, data-cohort, data-reproductive-mode, data-sex, data-focal, data-selected, data-highlighted).
  • classNames overrides, and render slots renderIndividual, renderCohortMarker, renderQuickView.
  • Headless: @captiveorigins/onepedigree-react/headless (hooks usePedigreeProjection, usePedigreeLayout, usePedigreeSelection, usePedigreeNavigation, useOccurrenceHighlighting, and describeProjection) for your own renderer.

Accessibility

Semantic SVG with <title>/<desc> summaries, accessible names per node, keyboard navigation (arrows between nodes, Enter to select, Escape to clear, +/−/0 to zoom, Shift+arrows to pan), visible focus, reduced-motion support, and non-color cues: junction shapes (circle = two-parent mode, diamond = single-parent mode, square = variable; hollow = incomplete), line patterns per reproductive mode, and a ↻ marker plus dashed border on repeated individuals.

License

PolyForm Noncommercial 1.0.0. Free for noncommercial use, with attribution; commercial use needs a separate license from Captive Origins. Versions published before this change remain under MIT.

版本与发布记录

@captiveorigins/onepedigree-react 共发布 11 个版本,首次发布于 2026/11/01;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0-alpha.13latest2026/11/09今天
0.1.0-alpha.152026/11/09今天
0.1.0-alpha.122026/11/063 天前
0.1.0-alpha.112026/11/036 天前
0.1.0-alpha.102026/11/036 天前
0.1.0-alpha.92026/11/036 天前

其他发布通道:alpha → 0.1.0-alpha.8。

关于 @captiveorigins/onepedigree-react 的常见问题

@captiveorigins/onepedigree-react 是什么?

OnePedigree for React: server-renderable SVG pedigree views (all 13), an interactive explorer, headless hooks and CSS-variable styling.

如何安装 @captiveorigins/onepedigree-react?

在项目目录运行 npm install @captiveorigins/onepedigree-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@captiveorigins/onepedigree-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@captiveorigins/onepedigree-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@captiveorigins/onepedigree-react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@captiveorigins/onepedigree-react 可以商用吗?

@captiveorigins/onepedigree-react 使用 PolyForm-Noncommercial-1.0.0 许可。声明的许可为 PolyForm-Noncommercial-1.0.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@captiveorigins/onepedigree-react 的下载量有多少?

根据 npm 官方下载统计,@captiveorigins/onepedigree-react 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,821 次,日均约 61 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@captiveorigins/onepedigree-react 还在维护吗?

最新版本 0.1.0-alpha.13 发布于 2026/11/09(今天);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。