@kinloom/ui 0.0.0-stage → 0.1.1
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/KinloomApp.d.ts +22 -0
- package/dist/KinloomApp.d.ts.map +1 -0
- package/dist/KinloomApp.js +88 -0
- package/dist/KinloomApp.js.map +1 -0
- package/dist/adapters/httpWikiDataSource.d.ts +151 -0
- package/dist/adapters/httpWikiDataSource.d.ts.map +1 -0
- package/dist/adapters/httpWikiDataSource.js +361 -0
- package/dist/adapters/httpWikiDataSource.js.map +1 -0
- package/dist/adapters/staticDemoDataSource.d.ts +22 -0
- package/dist/adapters/staticDemoDataSource.d.ts.map +1 -0
- package/dist/adapters/staticDemoDataSource.js +81 -0
- package/dist/adapters/staticDemoDataSource.js.map +1 -0
- package/dist/components/AppErrorBoundary.d.ts +20 -0
- package/dist/components/AppErrorBoundary.d.ts.map +1 -0
- package/dist/components/AppErrorBoundary.js +61 -0
- package/dist/components/AppErrorBoundary.js.map +1 -0
- package/dist/components/ArchivalMarkdown.d.ts +25 -0
- package/dist/components/ArchivalMarkdown.d.ts.map +1 -0
- package/dist/components/ArchivalMarkdown.js +159 -0
- package/dist/components/ArchivalMarkdown.js.map +1 -0
- package/dist/components/Atoms.d.ts +35 -0
- package/dist/components/Atoms.d.ts.map +1 -0
- package/dist/components/Atoms.js +265 -0
- package/dist/components/Atoms.js.map +1 -0
- package/dist/components/BlankScreenWatchdog.d.ts +3 -0
- package/dist/components/BlankScreenWatchdog.d.ts.map +1 -0
- package/dist/components/BlankScreenWatchdog.js +46 -0
- package/dist/components/BlankScreenWatchdog.js.map +1 -0
- package/dist/components/ExplorerTopBar.d.ts +3 -0
- package/dist/components/ExplorerTopBar.d.ts.map +1 -0
- package/dist/components/ExplorerTopBar.js +76 -0
- package/dist/components/ExplorerTopBar.js.map +1 -0
- package/dist/components/GlobalSearchModal.d.ts +3 -0
- package/dist/components/GlobalSearchModal.d.ts.map +1 -0
- package/dist/components/GlobalSearchModal.js +146 -0
- package/dist/components/GlobalSearchModal.js.map +1 -0
- package/dist/components/KinloomFooter.d.ts +6 -0
- package/dist/components/KinloomFooter.d.ts.map +1 -0
- package/dist/components/KinloomFooter.js +10 -0
- package/dist/components/KinloomFooter.js.map +1 -0
- package/dist/components/LocalSurveyMap.d.ts +11 -0
- package/dist/components/LocalSurveyMap.d.ts.map +1 -0
- package/dist/components/LocalSurveyMap.js +115 -0
- package/dist/components/LocalSurveyMap.js.map +1 -0
- package/dist/components/MediaPlayer.d.ts +15 -0
- package/dist/components/MediaPlayer.d.ts.map +1 -0
- package/dist/components/MediaPlayer.js +85 -0
- package/dist/components/MediaPlayer.js.map +1 -0
- package/dist/components/MilestoneStoryCard.d.ts +13 -0
- package/dist/components/MilestoneStoryCard.d.ts.map +1 -0
- package/dist/components/MilestoneStoryCard.js +21 -0
- package/dist/components/MilestoneStoryCard.js.map +1 -0
- package/dist/components/ScrollMemory.d.ts +3 -0
- package/dist/components/ScrollMemory.d.ts.map +1 -0
- package/dist/components/ScrollMemory.js +25 -0
- package/dist/components/ScrollMemory.js.map +1 -0
- package/dist/components/SourceInspectorDrawer.d.ts +3 -0
- package/dist/components/SourceInspectorDrawer.d.ts.map +1 -0
- package/dist/components/SourceInspectorDrawer.js +77 -0
- package/dist/components/SourceInspectorDrawer.js.map +1 -0
- package/dist/components/SourceReaderDrawer.d.ts +3 -0
- package/dist/components/SourceReaderDrawer.d.ts.map +1 -0
- package/dist/components/SourceReaderDrawer.js +221 -0
- package/dist/components/SourceReaderDrawer.js.map +1 -0
- package/dist/components/wiki/AuthStatusBanner.d.ts +8 -0
- package/dist/components/wiki/AuthStatusBanner.d.ts.map +1 -0
- package/dist/components/wiki/AuthStatusBanner.js +22 -0
- package/dist/components/wiki/AuthStatusBanner.js.map +1 -0
- package/dist/components/wiki/ConflictMergeDialog.d.ts +17 -0
- package/dist/components/wiki/ConflictMergeDialog.d.ts.map +1 -0
- package/dist/components/wiki/ConflictMergeDialog.js +10 -0
- package/dist/components/wiki/ConflictMergeDialog.js.map +1 -0
- package/dist/components/wiki/CreateEntityModal.d.ts +12 -0
- package/dist/components/wiki/CreateEntityModal.d.ts.map +1 -0
- package/dist/components/wiki/CreateEntityModal.js +201 -0
- package/dist/components/wiki/CreateEntityModal.js.map +1 -0
- package/dist/components/wiki/EntityEditDrawer.d.ts +16 -0
- package/dist/components/wiki/EntityEditDrawer.d.ts.map +1 -0
- package/dist/components/wiki/EntityEditDrawer.js +284 -0
- package/dist/components/wiki/EntityEditDrawer.js.map +1 -0
- package/dist/components/wiki/MediaUploaderModal.d.ts +11 -0
- package/dist/components/wiki/MediaUploaderModal.d.ts.map +1 -0
- package/dist/components/wiki/MediaUploaderModal.js +107 -0
- package/dist/components/wiki/MediaUploaderModal.js.map +1 -0
- package/dist/components/wiki/PrivateArchiveGate.d.ts +7 -0
- package/dist/components/wiki/PrivateArchiveGate.d.ts.map +1 -0
- package/dist/components/wiki/PrivateArchiveGate.js +45 -0
- package/dist/components/wiki/PrivateArchiveGate.js.map +1 -0
- package/dist/components/wiki/RevisionDiffView.d.ts +16 -0
- package/dist/components/wiki/RevisionDiffView.d.ts.map +1 -0
- package/dist/components/wiki/RevisionDiffView.js +42 -0
- package/dist/components/wiki/RevisionDiffView.js.map +1 -0
- package/dist/components/wiki/RevisionHistoryPanel.d.ts +10 -0
- package/dist/components/wiki/RevisionHistoryPanel.d.ts.map +1 -0
- package/dist/components/wiki/RevisionHistoryPanel.js +76 -0
- package/dist/components/wiki/RevisionHistoryPanel.js.map +1 -0
- package/dist/components/wiki/SignInModal.d.ts +8 -0
- package/dist/components/wiki/SignInModal.d.ts.map +1 -0
- package/dist/components/wiki/SignInModal.js +45 -0
- package/dist/components/wiki/SignInModal.js.map +1 -0
- package/dist/components/wiki/TalkPanel.d.ts +10 -0
- package/dist/components/wiki/TalkPanel.d.ts.map +1 -0
- package/dist/components/wiki/TalkPanel.js +87 -0
- package/dist/components/wiki/TalkPanel.js.map +1 -0
- package/dist/components/wiki/WikiActionBar.d.ts +18 -0
- package/dist/components/wiki/WikiActionBar.d.ts.map +1 -0
- package/dist/components/wiki/WikiActionBar.js +29 -0
- package/dist/components/wiki/WikiActionBar.js.map +1 -0
- package/dist/components/wiki/WikiBadges.d.ts +29 -0
- package/dist/components/wiki/WikiBadges.d.ts.map +1 -0
- package/dist/components/wiki/WikiBadges.js +34 -0
- package/dist/components/wiki/WikiBadges.js.map +1 -0
- package/dist/context/ArchiveDataContext.d.ts +68 -0
- package/dist/context/ArchiveDataContext.d.ts.map +1 -0
- package/dist/context/ArchiveDataContext.js +363 -0
- package/dist/context/ArchiveDataContext.js.map +1 -0
- package/dist/context/ArchiveProvider.d.ts +8 -0
- package/dist/context/ArchiveProvider.d.ts.map +1 -0
- package/dist/context/ArchiveProvider.js +7 -0
- package/dist/context/ArchiveProvider.js.map +1 -0
- package/dist/context/ArchiveUiContext.d.ts +27 -0
- package/dist/context/ArchiveUiContext.d.ts.map +1 -0
- package/dist/context/ArchiveUiContext.js +104 -0
- package/dist/context/ArchiveUiContext.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/clientTelemetry.d.ts +21 -0
- package/dist/lib/clientTelemetry.d.ts.map +1 -0
- package/dist/lib/clientTelemetry.js +268 -0
- package/dist/lib/clientTelemetry.js.map +1 -0
- package/dist/lib/ohmStyle.d.ts +13 -0
- package/dist/lib/ohmStyle.d.ts.map +1 -0
- package/dist/lib/ohmStyle.js +158 -0
- package/dist/lib/ohmStyle.js.map +1 -0
- package/dist/lib/scrollMemory.d.ts +2 -0
- package/dist/lib/scrollMemory.d.ts.map +1 -0
- package/dist/lib/scrollMemory.js +7 -0
- package/dist/lib/scrollMemory.js.map +1 -0
- package/dist/lib/searchNavigation.d.ts +5 -0
- package/dist/lib/searchNavigation.d.ts.map +1 -0
- package/dist/lib/searchNavigation.js +16 -0
- package/dist/lib/searchNavigation.js.map +1 -0
- package/dist/lib/sourceReaderNav.d.ts +6 -0
- package/dist/lib/sourceReaderNav.d.ts.map +1 -0
- package/dist/lib/sourceReaderNav.js +17 -0
- package/dist/lib/sourceReaderNav.js.map +1 -0
- package/dist/lib/timelineScroll.d.ts +20 -0
- package/dist/lib/timelineScroll.d.ts.map +1 -0
- package/dist/lib/timelineScroll.js +60 -0
- package/dist/lib/timelineScroll.js.map +1 -0
- package/dist/lib/treeGestures.d.ts +55 -0
- package/dist/lib/treeGestures.d.ts.map +1 -0
- package/dist/lib/treeGestures.js +96 -0
- package/dist/lib/treeGestures.js.map +1 -0
- package/dist/lib/treeNodeDisplay.d.ts +8 -0
- package/dist/lib/treeNodeDisplay.d.ts.map +1 -0
- package/dist/lib/treeNodeDisplay.js +66 -0
- package/dist/lib/treeNodeDisplay.js.map +1 -0
- package/dist/machines/authSessionMachine.d.ts +665 -0
- package/dist/machines/authSessionMachine.d.ts.map +1 -0
- package/dist/machines/authSessionMachine.js +620 -0
- package/dist/machines/authSessionMachine.js.map +1 -0
- package/dist/machines/entityEditorMachine.d.ts +334 -0
- package/dist/machines/entityEditorMachine.d.ts.map +1 -0
- package/dist/machines/entityEditorMachine.js +534 -0
- package/dist/machines/entityEditorMachine.js.map +1 -0
- package/dist/machines/index.d.ts +7 -0
- package/dist/machines/index.d.ts.map +1 -0
- package/dist/machines/index.js +4 -0
- package/dist/machines/index.js.map +1 -0
- package/dist/machines/mediaUploadMachine.d.ts +161 -0
- package/dist/machines/mediaUploadMachine.d.ts.map +1 -0
- package/dist/machines/mediaUploadMachine.js +473 -0
- package/dist/machines/mediaUploadMachine.js.map +1 -0
- package/dist/pages/AdminPage.d.ts +26 -0
- package/dist/pages/AdminPage.d.ts.map +1 -0
- package/dist/pages/AdminPage.js +165 -0
- package/dist/pages/AdminPage.js.map +1 -0
- package/dist/pages/EvidencePage.d.ts +3 -0
- package/dist/pages/EvidencePage.d.ts.map +1 -0
- package/dist/pages/EvidencePage.js +304 -0
- package/dist/pages/EvidencePage.js.map +1 -0
- package/dist/pages/IndexPage.d.ts +3 -0
- package/dist/pages/IndexPage.d.ts.map +1 -0
- package/dist/pages/IndexPage.js +173 -0
- package/dist/pages/IndexPage.js.map +1 -0
- package/dist/pages/KinshipPage.d.ts +3 -0
- package/dist/pages/KinshipPage.d.ts.map +1 -0
- package/dist/pages/KinshipPage.js +101 -0
- package/dist/pages/KinshipPage.js.map +1 -0
- package/dist/pages/MapPage.d.ts +4 -0
- package/dist/pages/MapPage.d.ts.map +1 -0
- package/dist/pages/MapPage.js +885 -0
- package/dist/pages/MapPage.js.map +1 -0
- package/dist/pages/PersonPage.d.ts +3 -0
- package/dist/pages/PersonPage.d.ts.map +1 -0
- package/dist/pages/PersonPage.js +524 -0
- package/dist/pages/PersonPage.js.map +1 -0
- package/dist/pages/PlacePage.d.ts +3 -0
- package/dist/pages/PlacePage.d.ts.map +1 -0
- package/dist/pages/PlacePage.js +227 -0
- package/dist/pages/PlacePage.js.map +1 -0
- package/dist/pages/PlacesIndexPage.d.ts +3 -0
- package/dist/pages/PlacesIndexPage.d.ts.map +1 -0
- package/dist/pages/PlacesIndexPage.js +76 -0
- package/dist/pages/PlacesIndexPage.js.map +1 -0
- package/dist/pages/RecentChangesPage.d.ts +7 -0
- package/dist/pages/RecentChangesPage.d.ts.map +1 -0
- package/dist/pages/RecentChangesPage.js +154 -0
- package/dist/pages/RecentChangesPage.js.map +1 -0
- package/dist/pages/TimePage.d.ts +3 -0
- package/dist/pages/TimePage.d.ts.map +1 -0
- package/dist/pages/TimePage.js +148 -0
- package/dist/pages/TimePage.js.map +1 -0
- package/dist/pages/TreePage.d.ts +3 -0
- package/dist/pages/TreePage.d.ts.map +1 -0
- package/dist/pages/TreePage.js +698 -0
- package/dist/pages/TreePage.js.map +1 -0
- package/dist/plugins/PluginContext.d.ts +28 -0
- package/dist/plugins/PluginContext.d.ts.map +1 -0
- package/dist/plugins/PluginContext.js +65 -0
- package/dist/plugins/PluginContext.js.map +1 -0
- package/dist/plugins/types.d.ts +40 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/styles/archival.css +6127 -0
- package/package.json +44 -4
- package/README.md +0 -3
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { TREE_NODE_H as NODE_H, TREE_NODE_W as NODE_W, buildPersonThumbMap, computeTreeLayout, emptyTreeLayout, resolveDefaultBranchId, } from '@kinloom/core';
|
|
3
|
+
import { clampPan, computeDoubleTapZoom, computePinchTransform, computeWheelTargetZoom, computeZoomAroundPoint, distanceBetween, isDragMovement, midpointBetween, stepInertia, } from '../lib/treeGestures.js';
|
|
4
|
+
import { Link, useSearchParams } from 'react-router-dom';
|
|
5
|
+
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { formatLineageGroupLabel, formatTreeCardName, formatTreeCardPlace, } from '../lib/treeNodeDisplay.js';
|
|
7
|
+
import { initialsOf, resolveAssetUrl } from '../components/Atoms.js';
|
|
8
|
+
import { ExplorerTopBar } from '../components/ExplorerTopBar.js';
|
|
9
|
+
import { useArchiveData } from '../context/ArchiveDataContext.js';
|
|
10
|
+
const INITIAL_TRANSFORM = {
|
|
11
|
+
pan: { x: 40, y: 40 },
|
|
12
|
+
zoom: 0.75,
|
|
13
|
+
};
|
|
14
|
+
const TreeGenBandsImpl = ({ genBands, maxX, }) => (_jsx("g", { children: genBands.map((b) => (_jsxs("g", { children: [_jsx("line", { x1: 16, y1: b.y + NODE_H / 2, x2: maxX - 16, y2: b.y + NODE_H / 2, stroke: "#D6CEBE", strokeWidth: "1", strokeDasharray: "4 4" }), _jsx("rect", { x: 12, y: b.y + 10, width: 110, height: 28, rx: 3, fill: "#FCF9F2", stroke: "#827A6A" }), _jsxs("text", { x: 67, y: b.y + 28, textAnchor: "middle", fontSize: "10", fontWeight: "600", fontFamily: "IBM Plex Mono, monospace", fill: "#4E4A42", children: ["G", b.gen + 1, " \u00B7 ", b.yearRange] })] }, b.gen))) }));
|
|
15
|
+
const TreeGenBands = React.memo(TreeGenBandsImpl);
|
|
16
|
+
const TreeEdgeItemImpl = ({ d, isDirect, isLit, }) => {
|
|
17
|
+
const cls = `tree-edge${isDirect ? ' is-direct' : ''}${isLit ? ' is-lit' : ''}`;
|
|
18
|
+
return (_jsx("path", { className: cls, d: d, fill: "none", stroke: isDirect ? '#1B2A41' : '#827A6A', strokeWidth: isDirect ? 2.1 : 1.15 }));
|
|
19
|
+
};
|
|
20
|
+
const TreeEdgeItem = React.memo(TreeEdgeItemImpl);
|
|
21
|
+
const TreeCoupleItemImpl = ({ couple, isLit, }) => (_jsxs("g", { className: `tree-couple${isLit ? ' is-lit' : ''}`, children: [_jsx("line", { x1: couple.a.x + NODE_W, y1: couple.midY, x2: couple.b.x, y2: couple.midY, stroke: "#7A4612", strokeWidth: "2.2" }), _jsx("line", { x1: couple.midX, y1: couple.midY, x2: couple.midX, y2: couple.a.y + NODE_H, stroke: "#7A4612", strokeWidth: "1.6" })] }));
|
|
22
|
+
const TreeCoupleItem = React.memo(TreeCoupleItemImpl);
|
|
23
|
+
const TreeNodeItemImpl = ({ prepared, isSelected, isLit, onSelect }) => {
|
|
24
|
+
const { node, displayName, lifespanPlace, thumbUrl, initials } = prepared;
|
|
25
|
+
const p = node.person;
|
|
26
|
+
let nodeStroke = '#827A6A';
|
|
27
|
+
let nodeStrokeWidth = 1.1;
|
|
28
|
+
if (isSelected) {
|
|
29
|
+
nodeStroke = '#7A4612';
|
|
30
|
+
nodeStrokeWidth = 2.4;
|
|
31
|
+
}
|
|
32
|
+
else if (node.isDirect) {
|
|
33
|
+
nodeStroke = '#1B2A41';
|
|
34
|
+
nodeStrokeWidth = 1.8;
|
|
35
|
+
}
|
|
36
|
+
return (_jsxs("g", { role: "button", className: `tree-node-card${isLit ? ' is-lit' : ''}`, tabIndex: 0, "aria-label": `Inspect ${p.full_name}`, transform: `translate(${node.x}, ${node.y})`, onClick: (e) => {
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
onSelect(p, false);
|
|
39
|
+
}, onKeyDown: (e) => {
|
|
40
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
onSelect(p, true);
|
|
43
|
+
}
|
|
44
|
+
}, children: [_jsx("rect", { width: NODE_W, height: NODE_H, rx: 3, fill: isSelected ? '#1B2A41' : '#FCF9F2', stroke: nodeStroke, strokeWidth: nodeStrokeWidth, strokeDasharray: node.isDirect ? undefined : '4 2' }), _jsx("circle", { cx: 20, cy: 24, r: 12, fill: isSelected ? '#7A4612' : '#EAE1CE', stroke: node.isDirect ? '#7A4612' : '#827A6A' }), thumbUrl ? (_jsx("image", { href: thumbUrl, x: 8, y: 12, width: 24, height: 24, preserveAspectRatio: "xMidYMid slice", clipPath: "url(#tree-node-avatar-clip)" })) : (_jsx("text", { x: 20, y: 27, textAnchor: "middle", fontSize: "8.8", fontWeight: "700", fontFamily: "IBM Plex Mono, monospace", fill: isSelected ? '#FCF9F2' : '#7A4612', children: initials })), _jsx("title", { children: p.full_name }), _jsx("text", { x: 38, y: 19, fontSize: "10", fontWeight: "700", fontFamily: "Newsreader, Georgia, serif", fill: isSelected ? '#FCF9F2' : '#1B2A41', children: displayName }), _jsx("text", { x: 38, y: 33, fontSize: "8.2", fontFamily: "IBM Plex Mono, monospace", fill: isSelected ? '#EAE1CE' : '#4E4A42', children: lifespanPlace })] }));
|
|
45
|
+
};
|
|
46
|
+
const TreeNodeItem = React.memo(TreeNodeItemImpl);
|
|
47
|
+
const TreeMinimapImpl = ({ bounds, nodes, familyName, onFit }) => (_jsxs("button", { type: "button", className: "tree-minimap", onMouseDown: (e) => {
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
}, onClick: (e) => {
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
onFit();
|
|
52
|
+
}, title: `Click minimap to recenter and fit the ${familyName} tree`, children: [_jsx("div", { style: { fontFamily: 'var(--font-mono)', fontSize: '0.75rem', marginBottom: 4, textAlign: 'left', color: 'var(--surface-header)' }, children: "MINIMAP \u00B7 CLICK TO FIT" }), _jsx("svg", { viewBox: `0 0 ${bounds.maxX} ${bounds.maxY}`, width: "100%", height: "68", style: { background: '#F5EFE2', border: '1px solid #D6CEBE' }, children: nodes.map((n) => (_jsx("rect", { x: n.x, y: n.y, width: NODE_W, height: NODE_H, fill: n.isDirect ? '#1B2A41' : '#7A4612', opacity: n.isDirect ? 0.9 : 0.55 }, n.person.id))) })] }));
|
|
53
|
+
const TreeMinimap = React.memo(TreeMinimapImpl);
|
|
54
|
+
export const TreePage = () => {
|
|
55
|
+
const { siteConfig, baseUrl, bundle, placesById, loading } = useArchiveData();
|
|
56
|
+
const personThumbMap = useMemo(() => (bundle ? buildPersonThumbMap(bundle) : new Map()), [bundle]);
|
|
57
|
+
const [searchParams] = useSearchParams();
|
|
58
|
+
const containerRef = useRef(null);
|
|
59
|
+
const stageRef = useRef(null);
|
|
60
|
+
const appliedFocusSlugRef = useRef(null);
|
|
61
|
+
const transformRef = useRef(INITIAL_TRANSFORM);
|
|
62
|
+
const animationTargetRef = useRef(null);
|
|
63
|
+
const pendingTransformRef = useRef(null);
|
|
64
|
+
const rafIdRef = useRef(null);
|
|
65
|
+
const motionRafRef = useRef(null);
|
|
66
|
+
const inertiaSpeedRef = useRef(0);
|
|
67
|
+
const zoomSettleTimerRef = useRef(null);
|
|
68
|
+
const containerRectRef = useRef({
|
|
69
|
+
left: 0,
|
|
70
|
+
top: 0,
|
|
71
|
+
width: 1200,
|
|
72
|
+
height: 760,
|
|
73
|
+
ts: 0,
|
|
74
|
+
});
|
|
75
|
+
const activePointersRef = useRef(new Map());
|
|
76
|
+
const dragStartRef = useRef(null);
|
|
77
|
+
const pinchStartRef = useRef(null);
|
|
78
|
+
const velocitySamplesRef = useRef([]);
|
|
79
|
+
const pinchReleaseAtRef = useRef(0);
|
|
80
|
+
const lastCanvasTapRef = useRef(null);
|
|
81
|
+
const didDragMoveRef = useRef(false);
|
|
82
|
+
const defaultBranchId = useMemo(() => resolveDefaultBranchId(siteConfig), [siteConfig]);
|
|
83
|
+
const [selectedPerson, setSelectedPerson] = useState(null);
|
|
84
|
+
const [branchFilter, setBranchFilter] = useState('all');
|
|
85
|
+
const [mode, setMode] = useState('full');
|
|
86
|
+
const markZooming = useCallback(() => {
|
|
87
|
+
stageRef.current?.classList.add('is-zooming');
|
|
88
|
+
if (zoomSettleTimerRef.current !== null) {
|
|
89
|
+
window.clearTimeout(zoomSettleTimerRef.current);
|
|
90
|
+
}
|
|
91
|
+
zoomSettleTimerRef.current = window.setTimeout(() => {
|
|
92
|
+
zoomSettleTimerRef.current = null;
|
|
93
|
+
stageRef.current?.classList.remove('is-zooming');
|
|
94
|
+
}, 150);
|
|
95
|
+
}, []);
|
|
96
|
+
const cancelMotion = useCallback(() => {
|
|
97
|
+
if (motionRafRef.current !== null) {
|
|
98
|
+
window.cancelAnimationFrame(motionRafRef.current);
|
|
99
|
+
motionRafRef.current = null;
|
|
100
|
+
}
|
|
101
|
+
animationTargetRef.current = null;
|
|
102
|
+
inertiaSpeedRef.current = 0;
|
|
103
|
+
}, []);
|
|
104
|
+
const writeTransformToDom = useCallback((next) => {
|
|
105
|
+
const stage = stageRef.current;
|
|
106
|
+
if (stage) {
|
|
107
|
+
stage.style.transform = `translate3d(${next.pan.x}px, ${next.pan.y}px, 0) scale(${next.zoom})`;
|
|
108
|
+
}
|
|
109
|
+
const container = containerRef.current;
|
|
110
|
+
if (container) {
|
|
111
|
+
container.dataset.zoom = String(next.zoom);
|
|
112
|
+
container.dataset.panX = String(next.pan.x);
|
|
113
|
+
container.dataset.panY = String(next.pan.y);
|
|
114
|
+
}
|
|
115
|
+
}, []);
|
|
116
|
+
const applyTransformNow = useCallback((next) => {
|
|
117
|
+
cancelMotion();
|
|
118
|
+
if (rafIdRef.current !== null) {
|
|
119
|
+
window.cancelAnimationFrame(rafIdRef.current);
|
|
120
|
+
rafIdRef.current = null;
|
|
121
|
+
}
|
|
122
|
+
pendingTransformRef.current = null;
|
|
123
|
+
transformRef.current = next;
|
|
124
|
+
writeTransformToDom(next);
|
|
125
|
+
}, [cancelMotion, writeTransformToDom]);
|
|
126
|
+
const scheduleTransform = useCallback((next) => {
|
|
127
|
+
transformRef.current = next;
|
|
128
|
+
pendingTransformRef.current = next;
|
|
129
|
+
if (rafIdRef.current !== null) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
rafIdRef.current = window.requestAnimationFrame(() => {
|
|
133
|
+
rafIdRef.current = null;
|
|
134
|
+
const latest = pendingTransformRef.current;
|
|
135
|
+
if (latest) {
|
|
136
|
+
pendingTransformRef.current = null;
|
|
137
|
+
writeTransformToDom(latest);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}, [writeTransformToDom]);
|
|
141
|
+
useEffect(() => () => {
|
|
142
|
+
if (rafIdRef.current !== null) {
|
|
143
|
+
window.cancelAnimationFrame(rafIdRef.current);
|
|
144
|
+
rafIdRef.current = null;
|
|
145
|
+
}
|
|
146
|
+
if (motionRafRef.current !== null) {
|
|
147
|
+
window.cancelAnimationFrame(motionRafRef.current);
|
|
148
|
+
motionRafRef.current = null;
|
|
149
|
+
}
|
|
150
|
+
if (zoomSettleTimerRef.current !== null) {
|
|
151
|
+
window.clearTimeout(zoomSettleTimerRef.current);
|
|
152
|
+
zoomSettleTimerRef.current = null;
|
|
153
|
+
}
|
|
154
|
+
}, []);
|
|
155
|
+
const readContainerOffset = useCallback((forceRefresh) => {
|
|
156
|
+
const now = performance.now();
|
|
157
|
+
if (!forceRefresh && now - containerRectRef.current.ts < 250) {
|
|
158
|
+
return containerRectRef.current;
|
|
159
|
+
}
|
|
160
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
161
|
+
const next = {
|
|
162
|
+
left: rect?.left ?? 0,
|
|
163
|
+
top: rect?.top ?? 0,
|
|
164
|
+
width: rect?.width || 1200,
|
|
165
|
+
height: rect?.height || 760,
|
|
166
|
+
ts: now,
|
|
167
|
+
};
|
|
168
|
+
containerRectRef.current = next;
|
|
169
|
+
return next;
|
|
170
|
+
}, []);
|
|
171
|
+
const branchCounts = useMemo(() => {
|
|
172
|
+
const counts = { all: 0 };
|
|
173
|
+
if (!bundle) {
|
|
174
|
+
return counts;
|
|
175
|
+
}
|
|
176
|
+
for (const p of bundle.people) {
|
|
177
|
+
if (p.is_living && p.full_name === 'Living') {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
counts.all += 1;
|
|
181
|
+
const b = p.branch || defaultBranchId;
|
|
182
|
+
counts[b] = (counts[b] || 0) + 1;
|
|
183
|
+
}
|
|
184
|
+
return counts;
|
|
185
|
+
}, [bundle, defaultBranchId]);
|
|
186
|
+
const populatedBranches = useMemo(() => siteConfig.branches.filter((b) => (branchCounts[b.id] || 0) > 0), [siteConfig.branches, branchCounts]);
|
|
187
|
+
const directModeBranchIds = useMemo(() => siteConfig.branches.filter((b) => b.supportsDirectMode).map((b) => b.id), [siteConfig.branches]);
|
|
188
|
+
const activeBranchConfig = useMemo(() => siteConfig.branches.find((b) => b.id === branchFilter), [siteConfig.branches, branchFilter]);
|
|
189
|
+
const activeBranchLabel = branchFilter === 'all'
|
|
190
|
+
? siteConfig.site.familyName
|
|
191
|
+
: (activeBranchConfig?.label ?? branchFilter);
|
|
192
|
+
const showDirectToggle = branchFilter === 'all' || (activeBranchConfig?.supportsDirectMode ?? true);
|
|
193
|
+
const graph = useMemo(() => {
|
|
194
|
+
if (!bundle) {
|
|
195
|
+
return emptyTreeLayout();
|
|
196
|
+
}
|
|
197
|
+
return computeTreeLayout({
|
|
198
|
+
people: bundle.people,
|
|
199
|
+
kinship: bundle.kinship,
|
|
200
|
+
branchFilter: branchFilter === 'all' ? null : branchFilter,
|
|
201
|
+
defaultBranchId,
|
|
202
|
+
directModeBranchIds: directModeBranchIds.length > 0 ? directModeBranchIds : undefined,
|
|
203
|
+
mode,
|
|
204
|
+
});
|
|
205
|
+
}, [bundle, mode, branchFilter, defaultBranchId, directModeBranchIds]);
|
|
206
|
+
const preparedEdges = useMemo(() => graph.edges.map((ed) => {
|
|
207
|
+
const midY = (ed.fromY + ed.toY) / 2;
|
|
208
|
+
return {
|
|
209
|
+
key: `${ed.childId}-${ed.parentIds.join('+')}`,
|
|
210
|
+
d: `M ${ed.fromX} ${ed.fromY} C ${ed.fromX} ${midY}, ${ed.toX} ${midY}, ${ed.toX} ${ed.toY}`,
|
|
211
|
+
childId: ed.childId,
|
|
212
|
+
parentIds: ed.parentIds,
|
|
213
|
+
isDirect: ed.isDirect,
|
|
214
|
+
};
|
|
215
|
+
}), [graph.edges]);
|
|
216
|
+
const preparedNodes = useMemo(() => graph.nodes.map((node) => {
|
|
217
|
+
const p = node.person;
|
|
218
|
+
const pl = p.primary_place_id ? placesById.get(p.primary_place_id) : undefined;
|
|
219
|
+
const rawThumb = personThumbMap.get(p.id) || p.portrait_url;
|
|
220
|
+
const cardPlace = formatTreeCardPlace(pl, placesById);
|
|
221
|
+
return {
|
|
222
|
+
node,
|
|
223
|
+
displayName: formatTreeCardName(p.full_name),
|
|
224
|
+
lifespanPlace: `${p.birth_year || '?'}–${p.death_year || '?'}${cardPlace ? ` · ${cardPlace}` : ''}`,
|
|
225
|
+
thumbUrl: rawThumb ? resolveAssetUrl(rawThumb, baseUrl) : null,
|
|
226
|
+
initials: initialsOf(p.full_name),
|
|
227
|
+
};
|
|
228
|
+
}), [graph.nodes, placesById, personThumbMap, baseUrl]);
|
|
229
|
+
const clampTransform = useCallback((next) => {
|
|
230
|
+
const el = containerRef.current;
|
|
231
|
+
const viewport = {
|
|
232
|
+
width: el ? el.clientWidth : containerRectRef.current.width,
|
|
233
|
+
height: el ? el.clientHeight : containerRectRef.current.height,
|
|
234
|
+
};
|
|
235
|
+
return {
|
|
236
|
+
zoom: next.zoom,
|
|
237
|
+
pan: clampPan(next.pan, next.zoom, graph.bounds, viewport),
|
|
238
|
+
};
|
|
239
|
+
}, [graph.bounds]);
|
|
240
|
+
const animateToTransform = useCallback((target, durationMs = 200) => {
|
|
241
|
+
const clampedTarget = clampTransform(target);
|
|
242
|
+
if (durationMs <= 0 ||
|
|
243
|
+
(typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches)) {
|
|
244
|
+
applyTransformNow(clampedTarget);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
cancelMotion();
|
|
248
|
+
if (rafIdRef.current !== null) {
|
|
249
|
+
window.cancelAnimationFrame(rafIdRef.current);
|
|
250
|
+
rafIdRef.current = null;
|
|
251
|
+
}
|
|
252
|
+
pendingTransformRef.current = null;
|
|
253
|
+
const { current: start } = transformRef;
|
|
254
|
+
animationTargetRef.current = clampedTarget;
|
|
255
|
+
const startTime = performance.now();
|
|
256
|
+
const isScaleChanging = Math.abs(clampedTarget.zoom - start.zoom) > 0.001;
|
|
257
|
+
if (isScaleChanging) {
|
|
258
|
+
markZooming();
|
|
259
|
+
}
|
|
260
|
+
const tick = (now) => {
|
|
261
|
+
const progress = Math.min(1, (now - startTime) / durationMs);
|
|
262
|
+
const eased = 1 - (1 - progress) ** 3;
|
|
263
|
+
const frame = {
|
|
264
|
+
zoom: Number((start.zoom + (clampedTarget.zoom - start.zoom) * eased).toFixed(3)),
|
|
265
|
+
pan: {
|
|
266
|
+
x: Number((start.pan.x + (clampedTarget.pan.x - start.pan.x) * eased).toFixed(2)),
|
|
267
|
+
y: Number((start.pan.y + (clampedTarget.pan.y - start.pan.y) * eased).toFixed(2)),
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
transformRef.current = frame;
|
|
271
|
+
writeTransformToDom(frame);
|
|
272
|
+
if (isScaleChanging) {
|
|
273
|
+
markZooming();
|
|
274
|
+
}
|
|
275
|
+
if (progress < 1) {
|
|
276
|
+
motionRafRef.current = window.requestAnimationFrame(tick);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
motionRafRef.current = null;
|
|
280
|
+
animationTargetRef.current = null;
|
|
281
|
+
transformRef.current = clampedTarget;
|
|
282
|
+
writeTransformToDom(clampedTarget);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
motionRafRef.current = window.requestAnimationFrame(tick);
|
|
286
|
+
}, [applyTransformNow, cancelMotion, clampTransform, markZooming, writeTransformToDom]);
|
|
287
|
+
const startInertia = useCallback((initialVx, initialVy) => {
|
|
288
|
+
cancelMotion();
|
|
289
|
+
let vx = initialVx;
|
|
290
|
+
let vy = initialVy;
|
|
291
|
+
let lastTime = performance.now();
|
|
292
|
+
inertiaSpeedRef.current = Math.hypot(vx, vy);
|
|
293
|
+
const tick = (now) => {
|
|
294
|
+
const dt = now - lastTime;
|
|
295
|
+
lastTime = now;
|
|
296
|
+
const { current } = transformRef;
|
|
297
|
+
const { next, done } = stepInertia({ pan: current.pan, vx, vy }, dt);
|
|
298
|
+
const clamped = clampTransform({ zoom: current.zoom, pan: next.pan });
|
|
299
|
+
vx = Math.abs(clamped.pan.x - next.pan.x) > 0.5 ? 0 : next.vx;
|
|
300
|
+
vy = Math.abs(clamped.pan.y - next.pan.y) > 0.5 ? 0 : next.vy;
|
|
301
|
+
const speed = Math.hypot(vx, vy);
|
|
302
|
+
inertiaSpeedRef.current = speed;
|
|
303
|
+
transformRef.current = clamped;
|
|
304
|
+
writeTransformToDom(clamped);
|
|
305
|
+
if (done || speed < 0.025) {
|
|
306
|
+
motionRafRef.current = null;
|
|
307
|
+
inertiaSpeedRef.current = 0;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
motionRafRef.current = window.requestAnimationFrame(tick);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
motionRafRef.current = window.requestAnimationFrame(tick);
|
|
314
|
+
}, [cancelMotion, clampTransform, writeTransformToDom]);
|
|
315
|
+
const computeFitTransform = useCallback(() => {
|
|
316
|
+
const el = containerRef.current;
|
|
317
|
+
const vw = el ? el.clientWidth : 1200;
|
|
318
|
+
const vh = el ? el.clientHeight : 760;
|
|
319
|
+
const gw = Math.max(400, graph.bounds.maxX - graph.bounds.minX);
|
|
320
|
+
const gh = Math.max(400, graph.bounds.maxY - graph.bounds.minY);
|
|
321
|
+
const padX = vw < 640 ? 24 : 60;
|
|
322
|
+
const padY = vw < 640 ? 96 : 112;
|
|
323
|
+
const nextZoom = Math.max(0.24, Math.min(1, Math.min((vw - padX) / gw, (vh - padY) / gh)));
|
|
324
|
+
const nextX = (vw - gw * nextZoom) / 2;
|
|
325
|
+
const nextY = Math.max(vw < 640 ? 64 : 68, (vh - gh * nextZoom) / 2);
|
|
326
|
+
return {
|
|
327
|
+
zoom: Number(nextZoom.toFixed(2)),
|
|
328
|
+
pan: { x: Math.round(nextX), y: Math.round(nextY) },
|
|
329
|
+
};
|
|
330
|
+
}, [graph.bounds.maxX, graph.bounds.minX, graph.bounds.maxY, graph.bounds.minY]);
|
|
331
|
+
const fitToViewport = useCallback(() => {
|
|
332
|
+
applyTransformNow(computeFitTransform());
|
|
333
|
+
}, [applyTransformNow, computeFitTransform]);
|
|
334
|
+
const animateFitToViewport = useCallback(() => {
|
|
335
|
+
animateToTransform(computeFitTransform(), 210);
|
|
336
|
+
}, [animateToTransform, computeFitTransform]);
|
|
337
|
+
useLayoutEffect(() => {
|
|
338
|
+
if (graph.nodes.length === 0) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const focusSlug = searchParams.get('focus');
|
|
342
|
+
if (focusSlug && appliedFocusSlugRef.current !== focusSlug) {
|
|
343
|
+
const targetNode = graph.nodes.find((n) => n.person.slug === focusSlug);
|
|
344
|
+
if (targetNode) {
|
|
345
|
+
appliedFocusSlugRef.current = focusSlug;
|
|
346
|
+
setSelectedPerson(targetNode.person);
|
|
347
|
+
const el = containerRef.current;
|
|
348
|
+
const vw = el ? el.clientWidth : 1200;
|
|
349
|
+
const vh = el ? el.clientHeight : 760;
|
|
350
|
+
const nextZoom = 0.85;
|
|
351
|
+
const cx = targetNode.x + NODE_W / 2;
|
|
352
|
+
const cy = targetNode.y + NODE_H / 2;
|
|
353
|
+
applyTransformNow({
|
|
354
|
+
zoom: nextZoom,
|
|
355
|
+
pan: {
|
|
356
|
+
x: Math.round(vw / 2 - cx * nextZoom),
|
|
357
|
+
y: Math.round(vh / 2 - cy * nextZoom),
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
fitToViewport();
|
|
364
|
+
}, [fitToViewport, searchParams, graph.nodes, applyTransformNow]);
|
|
365
|
+
const isReady = !loading && Boolean(bundle);
|
|
366
|
+
useEffect(() => {
|
|
367
|
+
const el = containerRef.current;
|
|
368
|
+
if (!isReady || !el) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
const onWheel = (e) => {
|
|
372
|
+
e.preventDefault();
|
|
373
|
+
cancelMotion();
|
|
374
|
+
const offset = readContainerOffset(false);
|
|
375
|
+
const focalPoint = { x: e.clientX - offset.left, y: e.clientY - offset.top };
|
|
376
|
+
const { current } = transformRef;
|
|
377
|
+
const targetZoom = computeWheelTargetZoom(current.zoom, e.deltaY, e.ctrlKey);
|
|
378
|
+
const next = clampTransform(computeZoomAroundPoint({
|
|
379
|
+
currentPan: current.pan,
|
|
380
|
+
currentZoom: current.zoom,
|
|
381
|
+
targetZoom,
|
|
382
|
+
focalPoint,
|
|
383
|
+
}));
|
|
384
|
+
markZooming();
|
|
385
|
+
scheduleTransform(next);
|
|
386
|
+
};
|
|
387
|
+
el.addEventListener('wheel', onWheel, { passive: false });
|
|
388
|
+
return () => {
|
|
389
|
+
el.removeEventListener('wheel', onWheel);
|
|
390
|
+
};
|
|
391
|
+
}, [isReady, cancelMotion, clampTransform, markZooming, readContainerOffset, scheduleTransform]);
|
|
392
|
+
const setDraggingClass = useCallback((active) => {
|
|
393
|
+
containerRef.current?.classList.toggle('is-dragging', active);
|
|
394
|
+
}, []);
|
|
395
|
+
useEffect(() => {
|
|
396
|
+
document.documentElement.classList.add('tree-viewport-lock');
|
|
397
|
+
return () => {
|
|
398
|
+
document.documentElement.classList.remove('tree-viewport-lock');
|
|
399
|
+
};
|
|
400
|
+
}, []);
|
|
401
|
+
const handlePointerDown = useCallback((e) => {
|
|
402
|
+
if (e.target instanceof Element && e.target.closest('button, a, .tree-toolbar, .tree-popover, .tree-controls, .tree-minimap')) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const wasFastCoasting = inertiaSpeedRef.current > 0.15;
|
|
406
|
+
cancelMotion();
|
|
407
|
+
const offset = readContainerOffset(true);
|
|
408
|
+
const localPt = {
|
|
409
|
+
x: e.clientX - offset.left,
|
|
410
|
+
y: e.clientY - offset.top,
|
|
411
|
+
};
|
|
412
|
+
activePointersRef.current.set(e.pointerId, localPt);
|
|
413
|
+
const { current } = transformRef;
|
|
414
|
+
if (activePointersRef.current.size === 1) {
|
|
415
|
+
didDragMoveRef.current = wasFastCoasting;
|
|
416
|
+
velocitySamplesRef.current = [{ x: localPt.x, y: localPt.y, t: performance.now() }];
|
|
417
|
+
setDraggingClass(true);
|
|
418
|
+
dragStartRef.current = {
|
|
419
|
+
x: localPt.x,
|
|
420
|
+
y: localPt.y,
|
|
421
|
+
panX: current.pan.x,
|
|
422
|
+
panY: current.pan.y,
|
|
423
|
+
pointerType: e.pointerType,
|
|
424
|
+
};
|
|
425
|
+
pinchStartRef.current = null;
|
|
426
|
+
}
|
|
427
|
+
else if (activePointersRef.current.size === 2) {
|
|
428
|
+
didDragMoveRef.current = true;
|
|
429
|
+
lastCanvasTapRef.current = null;
|
|
430
|
+
velocitySamplesRef.current = [];
|
|
431
|
+
const [p1, p2] = [...activePointersRef.current.values()];
|
|
432
|
+
setDraggingClass(false);
|
|
433
|
+
dragStartRef.current = null;
|
|
434
|
+
pinchStartRef.current = {
|
|
435
|
+
startDist: distanceBetween(p1, p2),
|
|
436
|
+
startZoom: current.zoom,
|
|
437
|
+
startPan: { ...current.pan },
|
|
438
|
+
startMidpoint: midpointBetween(p1, p2),
|
|
439
|
+
};
|
|
440
|
+
markZooming();
|
|
441
|
+
}
|
|
442
|
+
}, [cancelMotion, markZooming, readContainerOffset, setDraggingClass]);
|
|
443
|
+
const handlePointerMoveNative = useCallback((e) => {
|
|
444
|
+
if (!activePointersRef.current.has(e.pointerId)) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const offset = containerRectRef.current;
|
|
448
|
+
const localPt = {
|
|
449
|
+
x: e.clientX - offset.left,
|
|
450
|
+
y: e.clientY - offset.top,
|
|
451
|
+
};
|
|
452
|
+
activePointersRef.current.set(e.pointerId, localPt);
|
|
453
|
+
if (activePointersRef.current.size === 2 && pinchStartRef.current) {
|
|
454
|
+
const [p1, p2] = [...activePointersRef.current.values()];
|
|
455
|
+
didDragMoveRef.current = true;
|
|
456
|
+
const next = clampTransform(computePinchTransform({
|
|
457
|
+
startDist: pinchStartRef.current.startDist,
|
|
458
|
+
currentDist: distanceBetween(p1, p2),
|
|
459
|
+
startZoom: pinchStartRef.current.startZoom,
|
|
460
|
+
startPan: pinchStartRef.current.startPan,
|
|
461
|
+
startMidpoint: pinchStartRef.current.startMidpoint,
|
|
462
|
+
currentMidpoint: midpointBetween(p1, p2),
|
|
463
|
+
}));
|
|
464
|
+
markZooming();
|
|
465
|
+
scheduleTransform(next);
|
|
466
|
+
}
|
|
467
|
+
else if (activePointersRef.current.size === 1 && dragStartRef.current) {
|
|
468
|
+
const now = performance.now();
|
|
469
|
+
if (now - pinchReleaseAtRef.current < 80) {
|
|
470
|
+
const { current } = transformRef;
|
|
471
|
+
dragStartRef.current = {
|
|
472
|
+
...dragStartRef.current,
|
|
473
|
+
x: localPt.x,
|
|
474
|
+
y: localPt.y,
|
|
475
|
+
panX: current.pan.x,
|
|
476
|
+
panY: current.pan.y,
|
|
477
|
+
};
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const dx = localPt.x - dragStartRef.current.x;
|
|
481
|
+
const dy = localPt.y - dragStartRef.current.y;
|
|
482
|
+
const threshold = dragStartRef.current.pointerType === 'touch' ? 8 : 6;
|
|
483
|
+
if (!didDragMoveRef.current && isDragMovement(dx, dy, threshold)) {
|
|
484
|
+
didDragMoveRef.current = true;
|
|
485
|
+
}
|
|
486
|
+
const samples = velocitySamplesRef.current;
|
|
487
|
+
samples.push({ x: localPt.x, y: localPt.y, t: now });
|
|
488
|
+
while (samples.length > 8 || (samples.length > 2 && now - samples[0].t > 95)) {
|
|
489
|
+
samples.shift();
|
|
490
|
+
}
|
|
491
|
+
const next = clampTransform({
|
|
492
|
+
zoom: transformRef.current.zoom,
|
|
493
|
+
pan: {
|
|
494
|
+
x: Number((dragStartRef.current.panX + dx).toFixed(2)),
|
|
495
|
+
y: Number((dragStartRef.current.panY + dy).toFixed(2)),
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
scheduleTransform(next);
|
|
499
|
+
}
|
|
500
|
+
}, [clampTransform, markZooming, scheduleTransform]);
|
|
501
|
+
const handlePointerUpNative = useCallback((e) => {
|
|
502
|
+
if (!activePointersRef.current.has(e.pointerId)) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const wasPinch = activePointersRef.current.size >= 2;
|
|
506
|
+
const releasePt = activePointersRef.current.get(e.pointerId);
|
|
507
|
+
const isCancel = e.type === 'pointercancel';
|
|
508
|
+
activePointersRef.current.delete(e.pointerId);
|
|
509
|
+
if (activePointersRef.current.size < 2) {
|
|
510
|
+
pinchStartRef.current = null;
|
|
511
|
+
}
|
|
512
|
+
if (activePointersRef.current.size === 1) {
|
|
513
|
+
if (wasPinch) {
|
|
514
|
+
pinchReleaseAtRef.current = performance.now();
|
|
515
|
+
}
|
|
516
|
+
const [remaining] = [...activePointersRef.current.values()];
|
|
517
|
+
const { current } = transformRef;
|
|
518
|
+
velocitySamplesRef.current = [{ x: remaining.x, y: remaining.y, t: performance.now() }];
|
|
519
|
+
dragStartRef.current = {
|
|
520
|
+
x: remaining.x,
|
|
521
|
+
y: remaining.y,
|
|
522
|
+
panX: current.pan.x,
|
|
523
|
+
panY: current.pan.y,
|
|
524
|
+
pointerType: e.pointerType,
|
|
525
|
+
};
|
|
526
|
+
setDraggingClass(true);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
const moved = didDragMoveRef.current;
|
|
530
|
+
const samples = velocitySamplesRef.current;
|
|
531
|
+
const now = performance.now();
|
|
532
|
+
dragStartRef.current = null;
|
|
533
|
+
velocitySamplesRef.current = [];
|
|
534
|
+
setDraggingClass(false);
|
|
535
|
+
if (!isCancel && moved && now - pinchReleaseAtRef.current > 140 && samples.length >= 2) {
|
|
536
|
+
const newest = samples.at(-1);
|
|
537
|
+
const [oldest] = samples;
|
|
538
|
+
const dt = newest ? newest.t - oldest.t : 0;
|
|
539
|
+
if (newest && now - newest.t < 65 && dt >= 8) {
|
|
540
|
+
const rawVx = (newest.x - oldest.x) / dt;
|
|
541
|
+
const rawVy = (newest.y - oldest.y) / dt;
|
|
542
|
+
const speed = Math.hypot(rawVx, rawVy);
|
|
543
|
+
if (speed > 0.12) {
|
|
544
|
+
const maxSpeed = 2.6;
|
|
545
|
+
const scale = speed > maxSpeed ? maxSpeed / speed : 1;
|
|
546
|
+
startInertia(rawVx * scale, rawVy * scale);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
else if (!isCancel && !moved && e.pointerType === 'touch' && releasePt) {
|
|
551
|
+
const isOnNode = e.target instanceof Element && Boolean(e.target.closest('.tree-node-card'));
|
|
552
|
+
const prevTap = lastCanvasTapRef.current;
|
|
553
|
+
if (!isOnNode && prevTap && now - prevTap.t < 300 && distanceBetween(prevTap, releasePt) < 34) {
|
|
554
|
+
lastCanvasTapRef.current = null;
|
|
555
|
+
didDragMoveRef.current = true;
|
|
556
|
+
const { current } = transformRef;
|
|
557
|
+
const fit = computeFitTransform();
|
|
558
|
+
const targetZoom = computeDoubleTapZoom(current.zoom, fit.zoom);
|
|
559
|
+
if (Math.abs(targetZoom - fit.zoom) < 0.01) {
|
|
560
|
+
animateToTransform(fit, 210);
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
animateToTransform(computeZoomAroundPoint({
|
|
564
|
+
currentPan: current.pan,
|
|
565
|
+
currentZoom: current.zoom,
|
|
566
|
+
targetZoom,
|
|
567
|
+
focalPoint: releasePt,
|
|
568
|
+
}), 210);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
else if (isOnNode) {
|
|
572
|
+
lastCanvasTapRef.current = null;
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
lastCanvasTapRef.current = { x: releasePt.x, y: releasePt.y, t: now };
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
window.setTimeout(() => {
|
|
579
|
+
didDragMoveRef.current = false;
|
|
580
|
+
}, 0);
|
|
581
|
+
}
|
|
582
|
+
}, [animateToTransform, computeFitTransform, setDraggingClass, startInertia]);
|
|
583
|
+
useEffect(() => {
|
|
584
|
+
const onWindowBlur = () => {
|
|
585
|
+
activePointersRef.current.clear();
|
|
586
|
+
dragStartRef.current = null;
|
|
587
|
+
pinchStartRef.current = null;
|
|
588
|
+
velocitySamplesRef.current = [];
|
|
589
|
+
setDraggingClass(false);
|
|
590
|
+
};
|
|
591
|
+
window.addEventListener('pointermove', handlePointerMoveNative);
|
|
592
|
+
window.addEventListener('pointerup', handlePointerUpNative);
|
|
593
|
+
window.addEventListener('pointercancel', handlePointerUpNative);
|
|
594
|
+
window.addEventListener('blur', onWindowBlur);
|
|
595
|
+
return () => {
|
|
596
|
+
window.removeEventListener('pointermove', handlePointerMoveNative);
|
|
597
|
+
window.removeEventListener('pointerup', handlePointerUpNative);
|
|
598
|
+
window.removeEventListener('pointercancel', handlePointerUpNative);
|
|
599
|
+
window.removeEventListener('blur', onWindowBlur);
|
|
600
|
+
};
|
|
601
|
+
}, [handlePointerMoveNative, handlePointerUpNative, setDraggingClass]);
|
|
602
|
+
const handleSelectPerson = useCallback((person, fromKeyboard) => {
|
|
603
|
+
if (!fromKeyboard && didDragMoveRef.current) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
setSelectedPerson(person);
|
|
607
|
+
}, []);
|
|
608
|
+
const highlightedIds = useMemo(() => {
|
|
609
|
+
if (!selectedPerson) {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
const set = new Set([selectedPerson.id]);
|
|
613
|
+
const walkUp = (id) => {
|
|
614
|
+
for (const pid of graph.parentMap.get(id) || []) {
|
|
615
|
+
if (!set.has(pid)) {
|
|
616
|
+
set.add(pid);
|
|
617
|
+
walkUp(pid);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
const walkDown = (id) => {
|
|
622
|
+
for (const cid of graph.childMap.get(id) || []) {
|
|
623
|
+
if (!set.has(cid)) {
|
|
624
|
+
set.add(cid);
|
|
625
|
+
walkDown(cid);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
walkUp(selectedPerson.id);
|
|
630
|
+
walkDown(selectedPerson.id);
|
|
631
|
+
return set;
|
|
632
|
+
}, [selectedPerson, graph.parentMap, graph.childMap]);
|
|
633
|
+
const stageStyle = useMemo(() => ({
|
|
634
|
+
width: graph.bounds.maxX,
|
|
635
|
+
height: graph.bounds.maxY,
|
|
636
|
+
}), [graph.bounds.maxX, graph.bounds.maxY]);
|
|
637
|
+
if (loading || !bundle) {
|
|
638
|
+
return (_jsxs("div", { children: [_jsx(ExplorerTopBar, {}), _jsx("main", { className: "index-page", children: "Loading 2D spatial-temporal canvas\u2026" })] }));
|
|
639
|
+
}
|
|
640
|
+
const hasSelection = highlightedIds !== null;
|
|
641
|
+
const activeCount = branchCounts[branchFilter] ?? graph.nodes.length;
|
|
642
|
+
return (_jsxs("div", { className: "tree-shell", children: [_jsx(ExplorerTopBar, {}), _jsxs("main", { ref: containerRef, className: "tree-page", onPointerDown: handlePointerDown, onClick: (e) => {
|
|
643
|
+
if (e.target instanceof Element && e.target.closest('button, a, .tree-toolbar, .tree-popover, .tree-controls, .tree-minimap')) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (!didDragMoveRef.current) {
|
|
647
|
+
setSelectedPerson(null);
|
|
648
|
+
}
|
|
649
|
+
}, children: [_jsxs("div", { className: "tree-toolbar", children: [populatedBranches.length > 1 && (_jsxs("select", { className: "pill-btn tree-branch-select", "aria-label": "Select family branch for 2D Tree", value: branchFilter, onChange: (e) => {
|
|
650
|
+
setBranchFilter(e.target.value);
|
|
651
|
+
setSelectedPerson(null);
|
|
652
|
+
}, children: [_jsxs("option", { value: "all", children: ["All Branches (", branchCounts.all || 0, ")"] }), populatedBranches.map((b) => (_jsxs("option", { value: b.id, children: [b.label, " (", branchCounts[b.id] || 0, ")"] }, b.id)))] })), showDirectToggle && (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", className: `pill-btn ${mode === 'full' ? 'active' : ''}`, onClick: () => {
|
|
653
|
+
setMode('full');
|
|
654
|
+
}, children: ["Full Tree (", activeCount, ")"] }), _jsx("button", { type: "button", className: `pill-btn ${mode === 'direct' ? 'active' : ''}`, onClick: () => {
|
|
655
|
+
setMode('direct');
|
|
656
|
+
}, children: "Direct Spine" })] }))] }), _jsx("div", { ref: stageRef, className: "tree-stage", style: stageStyle, children: _jsxs("svg", { className: `tree-canvas${hasSelection ? ' has-selection' : ''}`, width: graph.bounds.maxX, height: graph.bounds.maxY, viewBox: `0 0 ${graph.bounds.maxX} ${graph.bounds.maxY}`, role: "img", "aria-label": `Hierarchical 2D ${activeBranchLabel} family tree canvas`, children: [_jsx("defs", { children: _jsx("clipPath", { id: "tree-node-avatar-clip", children: _jsx("circle", { cx: "20", cy: "24", r: "12" }) }) }), _jsx(TreeGenBands, { genBands: graph.genBands, maxX: graph.bounds.maxX }), _jsx("g", { children: preparedEdges.map((ed) => {
|
|
657
|
+
const isLit = Boolean(highlightedIds &&
|
|
658
|
+
highlightedIds.has(ed.childId) &&
|
|
659
|
+
ed.parentIds.some((pid) => highlightedIds.has(pid)));
|
|
660
|
+
return (_jsx(TreeEdgeItem, { d: ed.d, isDirect: ed.isDirect, isLit: isLit }, ed.key));
|
|
661
|
+
}) }), _jsx("g", { children: graph.couples.map((c) => {
|
|
662
|
+
const isLit = Boolean(highlightedIds &&
|
|
663
|
+
(highlightedIds.has(c.a.person.id) || highlightedIds.has(c.b.person.id)));
|
|
664
|
+
return (_jsx(TreeCoupleItem, { couple: c, isLit: isLit }, `${c.a.person.id}-${c.b.person.id}`));
|
|
665
|
+
}) }), _jsx("g", { children: preparedNodes.map((prepared) => {
|
|
666
|
+
const pid = prepared.node.person.id;
|
|
667
|
+
const isSelected = selectedPerson?.id === pid;
|
|
668
|
+
const isLit = Boolean(highlightedIds?.has(pid));
|
|
669
|
+
return (_jsx(TreeNodeItem, { prepared: prepared, isSelected: isSelected, isLit: isLit, onSelect: handleSelectPerson }, pid));
|
|
670
|
+
}) })] }) }), selectedPerson && (_jsxs("div", { className: "tree-popover", children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [_jsx("span", { style: { fontFamily: 'var(--font-mono)', fontSize: '0.78rem', color: 'var(--radar-copresence)' }, children: formatLineageGroupLabel(selectedPerson.lineage_group) }), _jsx("button", { type: "button", className: "pill-btn", style: { padding: '2px 7px', fontSize: '0.78rem' }, onClick: () => {
|
|
671
|
+
setSelectedPerson(null);
|
|
672
|
+
}, children: "\u2715" })] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 10, margin: '6px 0' }, children: [(personThumbMap.get(selectedPerson.id) || selectedPerson.portrait_url) && (_jsx("img", { src: resolveAssetUrl(personThumbMap.get(selectedPerson.id) || selectedPerson.portrait_url || '', baseUrl), alt: selectedPerson.full_name, style: { width: 46, height: 56, objectFit: 'cover', borderRadius: 2, border: '1px solid var(--border-control)', flexShrink: 0 } })), _jsxs("div", { children: [_jsx("h2", { style: { fontFamily: 'var(--font-serif)', margin: '0 0 2px', color: 'var(--surface-header)', fontSize: '1.18rem' }, children: selectedPerson.full_name }), _jsxs("div", { style: { fontFamily: 'var(--font-mono)', fontSize: '0.8rem', color: 'var(--radar-copresence)' }, children: [selectedPerson.birth_edtf || '?', " \u2014 ", selectedPerson.death_edtf || '?'] })] })] }), _jsxs("div", { style: { fontSize: '0.82rem', color: 'var(--text-secondary)', marginBottom: 10 }, children: ["Primary place:", ' ', selectedPerson.primary_place_id
|
|
673
|
+
? placesById.get(selectedPerson.primary_place_id)?.full_name
|
|
674
|
+
: 'Unrecorded', (selectedPerson.media_count || 0) > 0 && (_jsxs("div", { style: { fontFamily: 'var(--font-mono)', fontSize: '0.74rem', marginTop: 4, color: 'var(--surface-header)' }, children: [selectedPerson.media_count, " archival ", selectedPerson.media_count === 1 ? 'photo/scan' : 'photos & scans', " attached"] }))] }), _jsx(Link, { to: `/person/${selectedPerson.slug}`, className: "pill-btn active", style: { display: 'inline-block', textDecoration: 'none' }, children: "Open Timeline \u2192" })] })), _jsx(TreeMinimap, { bounds: graph.bounds, nodes: graph.nodes, familyName: siteConfig.site.familyName, onFit: animateFitToViewport }), _jsxs("div", { className: "tree-controls", children: [_jsx("button", { type: "button", className: "pill-btn", "aria-label": "Zoom in", onClick: () => {
|
|
675
|
+
const el = containerRef.current;
|
|
676
|
+
const focal = { x: (el?.clientWidth ?? 800) / 2, y: (el?.clientHeight ?? 600) / 2 };
|
|
677
|
+
const base = animationTargetRef.current ?? transformRef.current;
|
|
678
|
+
const next = computeZoomAroundPoint({
|
|
679
|
+
currentPan: base.pan,
|
|
680
|
+
currentZoom: base.zoom,
|
|
681
|
+
targetZoom: base.zoom * 1.28,
|
|
682
|
+
focalPoint: focal,
|
|
683
|
+
});
|
|
684
|
+
animateToTransform(next, 180);
|
|
685
|
+
}, children: "+" }), _jsx("button", { type: "button", className: "pill-btn", "aria-label": "Zoom out", onClick: () => {
|
|
686
|
+
const el = containerRef.current;
|
|
687
|
+
const focal = { x: (el?.clientWidth ?? 800) / 2, y: (el?.clientHeight ?? 600) / 2 };
|
|
688
|
+
const base = animationTargetRef.current ?? transformRef.current;
|
|
689
|
+
const next = computeZoomAroundPoint({
|
|
690
|
+
currentPan: base.pan,
|
|
691
|
+
currentZoom: base.zoom,
|
|
692
|
+
targetZoom: base.zoom / 1.28,
|
|
693
|
+
focalPoint: focal,
|
|
694
|
+
});
|
|
695
|
+
animateToTransform(next, 180);
|
|
696
|
+
}, children: "\u2212" }), _jsx("button", { type: "button", className: "pill-btn", onClick: animateFitToViewport, children: "Fit" })] })] })] }));
|
|
697
|
+
};
|
|
698
|
+
//# sourceMappingURL=TreePage.js.map
|