dsh-plugin-memory 0.15.2 → 0.16.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/CHANGELOG.md +25 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/client.js +535 -253
- package/lib/graph-3d.js +159 -0
- package/lib/recall-nudge.js +33 -9
- package/lib/soul.js +2 -2
- package/lib/tone.js +2 -2
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -110,9 +110,9 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
soulFromChat: '已铸魂(对话生成):下面是 SOUL.md 里的当前值,保存后由面板接管',
|
|
111
111
|
soulManaged: '已设置 · 保存后下一次会话生效',
|
|
112
112
|
soulAgentName: '我的名字',
|
|
113
|
-
soulAgentPlaceholder: '
|
|
113
|
+
soulAgentPlaceholder: '例如:小助手',
|
|
114
114
|
soulUserName: '你的称呼',
|
|
115
|
-
soulUserPlaceholder: '
|
|
115
|
+
soulUserPlaceholder: '例如:小明',
|
|
116
116
|
soulSummary: '基础人格描述',
|
|
117
117
|
soulSummaryPlaceholder: '例如:直接、诚实、先结论后细节;不确定时明说,不编造。',
|
|
118
118
|
soulSave: '保存人格',
|
|
@@ -164,17 +164,18 @@ window.__ModuleLoader__.load({
|
|
|
164
164
|
graphLoading: '正在构建记忆图谱…',
|
|
165
165
|
graphTitle: '记忆图谱',
|
|
166
166
|
graphResetView: '重置视图',
|
|
167
|
+
graph3dSpin: '自动旋转',
|
|
168
|
+
graph3dHint: '拖空白旋转 · 滚轮缩放 · 拖节点整理布局 · 悬停/点击节点高亮邻居 · 双击空白重置;只读、实时。',
|
|
169
|
+
graph3dNeighbours: '邻居 {count} 个',
|
|
167
170
|
graphStats: '{pages} 页 · {links} 条页间互链 · {tagEdges} 条共享 tag',
|
|
168
171
|
graphIndexRoutes: '{count} 条索引路由(虚线)',
|
|
169
172
|
graphIsolated: '{count} 页暂时孤立',
|
|
170
173
|
graphUpdatedAt: '更新于 {time}',
|
|
171
|
-
graphRelations: '{count} 条关系',
|
|
172
174
|
graphNoLinks: '页面之间还没有互相引用——图谱目前只靠共享 tag 连接。写下「见 [某页](path)」会让关系变实。',
|
|
173
175
|
graphIsolatedHint: '这 {count} 页还没和别的记忆连上:{list}{more}',
|
|
174
176
|
graphMore: ' 等',
|
|
175
177
|
legendLinks: '━ 页间互链',
|
|
176
178
|
legendIndexRoutes: '┄ 索引路由',
|
|
177
|
-
graphHint: '细线=共享 tag。滚轮缩放 · 拖空白处平移 · 拖节点整理视图 · 悬停高亮关系;只读、实时。',
|
|
178
179
|
typeIdentity: '自我',
|
|
179
180
|
typeUser: '关于你',
|
|
180
181
|
typeUserPreference: '偏好',
|
|
@@ -256,9 +257,9 @@ window.__ModuleLoader__.load({
|
|
|
256
257
|
soulFromChat: 'Soul forged in chat: values below are parsed from SOUL.md; saving hands it to the panel',
|
|
257
258
|
soulManaged: 'Set · saving applies from the next session',
|
|
258
259
|
soulAgentName: 'My name',
|
|
259
|
-
soulAgentPlaceholder: 'e.g.
|
|
260
|
+
soulAgentPlaceholder: 'e.g. Assistant',
|
|
260
261
|
soulUserName: 'What I call you',
|
|
261
|
-
soulUserPlaceholder: 'e.g.
|
|
262
|
+
soulUserPlaceholder: 'e.g. Alex',
|
|
262
263
|
soulSummary: 'Baseline persona',
|
|
263
264
|
soulSummaryPlaceholder: 'e.g. Direct, honest, conclusion first; say when unsure, never fabricate.',
|
|
264
265
|
soulSave: 'Save soul',
|
|
@@ -310,17 +311,18 @@ window.__ModuleLoader__.load({
|
|
|
310
311
|
graphLoading: 'Building the memory graph…',
|
|
311
312
|
graphTitle: 'Memory graph',
|
|
312
313
|
graphResetView: 'Reset view',
|
|
314
|
+
graph3dSpin: 'Auto-spin',
|
|
315
|
+
graph3dHint: 'Drag empty space to rotate · wheel to zoom · drag nodes to tidy the layout · hover or click a node to light up its neighbours · double-click empty space to reset; read-only, live.',
|
|
316
|
+
graph3dNeighbours: 'Neighbours: {count}',
|
|
313
317
|
graphStats: '{pages} pages · {links} page links · {tagEdges} shared tags',
|
|
314
318
|
graphIndexRoutes: '{count} index routes (dashed)',
|
|
315
319
|
graphIsolated: '{count} pages isolated',
|
|
316
320
|
graphUpdatedAt: 'updated {time}',
|
|
317
|
-
graphRelations: '{count} relations',
|
|
318
321
|
graphNoLinks: 'Pages do not reference each other yet — the graph currently connects them only through shared tags. Writing "see [some page](path)" makes the relation real.',
|
|
319
322
|
graphIsolatedHint: 'These {count} pages are not connected to any other memory yet: {list}{more}',
|
|
320
323
|
graphMore: ' and more',
|
|
321
324
|
legendLinks: '━ page links',
|
|
322
325
|
legendIndexRoutes: '┄ index routes',
|
|
323
|
-
graphHint: 'Thin line = shared tag. Wheel to zoom · drag empty space to pan · drag a node to tidy the view · hover to highlight relations; read-only, live.',
|
|
324
326
|
typeIdentity: 'identity',
|
|
325
327
|
typeUser: 'about you',
|
|
326
328
|
typeUserPreference: 'preference',
|
|
@@ -1583,257 +1585,486 @@ window.__ModuleLoader__.load({
|
|
|
1583
1585
|
* 图谱视图:拿到 nodes/edges 就画(纯渲染,无副作用)。拖动与悬停是它
|
|
1584
1586
|
* 自己维护的临时状态;`memo` 隔断父级重渲染带来的 hooks 调用。
|
|
1585
1587
|
*/
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
}, [graph])
|
|
1588
|
+
// ---------------- 记忆图谱(3D canvas,方案 B) ----------------
|
|
1589
|
+
//
|
|
1590
|
+
// 球面布局 + 透视投影,Canvas 绘制。交互:拖空白旋转、滚轮缩放、拖节点
|
|
1591
|
+
// 整理布局、悬停/点击高亮邻居、双击空白重置。
|
|
1592
|
+
//
|
|
1593
|
+
// 点击 vs 拖拽用「位移 + 时长」双阈值:demo 里只靠 3px 位移判定太急,
|
|
1594
|
+
// 轻点一下手指抖两像素就变成拖拽、选中不生效——也就是用户反馈的
|
|
1595
|
+
// 「选择节点不能及时显示出关联的点」。悬停也即时高亮,不等点击。
|
|
1596
|
+
const GRAPH3D = {
|
|
1597
|
+
width: 560,
|
|
1598
|
+
height: 400,
|
|
1599
|
+
radius: 250,
|
|
1600
|
+
focal: 900,
|
|
1601
|
+
camera: 340,
|
|
1602
|
+
zoomMin: 0.5,
|
|
1603
|
+
zoomMax: 2.4,
|
|
1604
|
+
clickSlop: 5,
|
|
1605
|
+
clickMs: 350,
|
|
1606
|
+
}
|
|
1606
1607
|
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1608
|
+
// 以下数学内联自 lib/graph-3d.js(客户端只能 require 平台种子)。
|
|
1609
|
+
const GRAPH3D_GOLDEN = Math.PI * (3 - Math.sqrt(5))
|
|
1610
|
+
|
|
1611
|
+
function graph3dSphere(nodes, radius) {
|
|
1612
|
+
const sorted = [...nodes].sort((a, b) => {
|
|
1613
|
+
const byType = String(a.type ?? '').localeCompare(String(b.type ?? ''))
|
|
1614
|
+
return byType !== 0 ? byType : String(a.id).localeCompare(String(b.id))
|
|
1615
|
+
})
|
|
1616
|
+
const count = sorted.length
|
|
1617
|
+
return sorted.map((node, index) => {
|
|
1618
|
+
const y = 1 - ((index + 0.5) * 2) / count
|
|
1619
|
+
const ring = Math.sqrt(Math.max(0, 1 - y * y))
|
|
1620
|
+
const angle = index * GRAPH3D_GOLDEN
|
|
1621
|
+
return {
|
|
1622
|
+
id: node.id,
|
|
1623
|
+
x: Math.cos(angle) * ring * radius,
|
|
1624
|
+
y: y * radius,
|
|
1625
|
+
z: Math.sin(angle) * ring * radius,
|
|
1620
1626
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (fn) => setTimeout(fn, 16)
|
|
1624
|
-
raf(() => {
|
|
1625
|
-
el.classList.remove('anim-off')
|
|
1626
|
-
el.classList.remove('entering')
|
|
1627
|
-
})
|
|
1628
|
-
return () => { el.classList.remove('anim-off', 'entering') }
|
|
1629
|
-
}, [graph])
|
|
1627
|
+
})
|
|
1628
|
+
}
|
|
1630
1629
|
|
|
1631
|
-
|
|
1632
|
-
const
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1630
|
+
function graph3dRotate(point, yaw, pitch) {
|
|
1631
|
+
const cy = Math.cos(yaw)
|
|
1632
|
+
const sy = Math.sin(yaw)
|
|
1633
|
+
const cp = Math.cos(pitch)
|
|
1634
|
+
const sp = Math.sin(pitch)
|
|
1635
|
+
const x1 = point.x * cy - point.z * sy
|
|
1636
|
+
const z1 = point.x * sy + point.z * cy
|
|
1637
|
+
return { id: point.id, x: x1, y: point.y * cp - z1 * sp, z: point.y * sp + z1 * cp }
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
function graph3dUnrotate(point, yaw, pitch) {
|
|
1641
|
+
const cy = Math.cos(-yaw)
|
|
1642
|
+
const sy = Math.sin(-yaw)
|
|
1643
|
+
const cp = Math.cos(-pitch)
|
|
1644
|
+
const sp = Math.sin(-pitch)
|
|
1645
|
+
const y1 = point.y * cp - point.z * sp
|
|
1646
|
+
const z1 = point.y * sp + point.z * cp
|
|
1647
|
+
return { id: point.id, x: point.x * cy - z1 * sy, y: y1, z: point.x * sy + z1 * cy }
|
|
1648
|
+
}
|
|
1635
1649
|
|
|
1636
|
-
|
|
1637
|
-
const
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1650
|
+
function graph3dProject(node, view) {
|
|
1651
|
+
const rotated = graph3dRotate(node, view.yaw, view.pitch)
|
|
1652
|
+
const scale = (GRAPH3D.focal / Math.max(60, GRAPH3D.focal + rotated.z + GRAPH3D.camera)) * view.zoom
|
|
1653
|
+
// 1 = nearest the camera, 0 = far pole.
|
|
1654
|
+
const depth = Math.max(0, Math.min(1, (GRAPH3D.radius - rotated.z) / (2 * GRAPH3D.radius)))
|
|
1655
|
+
return {
|
|
1656
|
+
id: node.id,
|
|
1657
|
+
x: GRAPH3D.width / 2 + rotated.x * scale,
|
|
1658
|
+
y: GRAPH3D.height / 2 + rotated.y * scale,
|
|
1659
|
+
z: rotated.z,
|
|
1660
|
+
scale,
|
|
1661
|
+
depth,
|
|
1643
1662
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
const
|
|
1650
|
-
const
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function graph3dHit(points, x, y, radiusOf) {
|
|
1666
|
+
let best = null
|
|
1667
|
+
let bestDistance = Infinity
|
|
1668
|
+
for (const point of points) {
|
|
1669
|
+
const distance = Math.hypot(point.x - x, point.y - y)
|
|
1670
|
+
if (distance <= radiusOf(point) && distance < bestDistance) {
|
|
1671
|
+
best = point
|
|
1672
|
+
bestDistance = distance
|
|
1654
1673
|
}
|
|
1655
|
-
return toGraphPointIn(viewRef.current, rect, event.clientX, event.clientY)
|
|
1656
1674
|
}
|
|
1675
|
+
return best
|
|
1676
|
+
}
|
|
1657
1677
|
|
|
1658
|
-
|
|
1659
|
-
const
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
const resetView = () => applyView(resetViewState())
|
|
1678
|
+
function graph3dHexToRgba(hex, alpha) {
|
|
1679
|
+
const value = String(hex ?? '#8b8f96').replace('#', '')
|
|
1680
|
+
const full = value.length === 3 ? value.split('').map((c) => c + c).join('') : value
|
|
1681
|
+
const num = Number.parseInt(full, 16)
|
|
1682
|
+
if (!Number.isFinite(num)) return `rgba(139,143,150,${alpha})`
|
|
1683
|
+
return `rgba(${(num >> 16) & 255},${(num >> 8) & 255},${num & 255},${alpha})`
|
|
1684
|
+
}
|
|
1666
1685
|
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1686
|
+
/** 一帧 3D 场景:边按深度淡出、节点发光、选中置顶、标签按 LOD 显示。
|
|
1687
|
+
* 浅色主题不画发光——浅底上发光会把节点晕成一片灰白,看着「颜色奇怪」。 */
|
|
1688
|
+
function drawGraph3D(ctx, model, state, dpr, theme) {
|
|
1689
|
+
const view = state.view
|
|
1690
|
+
const selected = state.selected
|
|
1691
|
+
const hovered = state.hovered
|
|
1692
|
+
const projected = model.nodes.map((node) => graph3dProject(node, view))
|
|
1693
|
+
const byIdProj = new Map(projected.map((p) => [p.id, p]))
|
|
1694
|
+
projected.sort((a, b) => a.z - b.z) // far first
|
|
1695
|
+
const isNeighbour = (id) => selected !== undefined && (model.adjacency.get(selected)?.has(id) ?? false)
|
|
1696
|
+
const lit = (id) => selected === undefined || id === selected || isNeighbour(id)
|
|
1697
|
+
const selectedPoint = selected !== undefined ? byIdProj.get(selected) : undefined
|
|
1698
|
+
const light = theme.light
|
|
1699
|
+
|
|
1700
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
|
1701
|
+
ctx.clearRect(0, 0, GRAPH3D.width, GRAPH3D.height)
|
|
1702
|
+
|
|
1703
|
+
for (const edge of model.edges) {
|
|
1704
|
+
const a = byIdProj.get(edge.source)
|
|
1705
|
+
const b = byIdProj.get(edge.target)
|
|
1706
|
+
if (a === undefined || b === undefined) continue
|
|
1707
|
+
const on = selected !== undefined && (edge.source === selected || edge.target === selected)
|
|
1708
|
+
const hot = hovered !== undefined && (edge.source === hovered || edge.target === hovered)
|
|
1709
|
+
// 浅色背景上边要更实一点;深色背景可以淡,靠发光补层次。
|
|
1710
|
+
const base = light
|
|
1711
|
+
? (edge.kind === 'index' ? 0.32 : edge.kind === 'tag' ? 0.36 : 0.68)
|
|
1712
|
+
: (edge.kind === 'index' ? 0.16 : edge.kind === 'tag' ? 0.2 : 0.45)
|
|
1713
|
+
const depthFactor = light
|
|
1714
|
+
? 0.75 + 0.25 * ((a.depth + b.depth) / 2)
|
|
1715
|
+
: 0.4 + 0.6 * ((a.depth + b.depth) / 2)
|
|
1716
|
+
const alpha = (on || hot ? 0.9 : lit(edge.source) && lit(edge.target) ? base : 0.05) * depthFactor
|
|
1717
|
+
ctx.strokeStyle = theme.edges[edge.kind] ?? theme.edges.link
|
|
1718
|
+
ctx.globalAlpha = Math.max(0.02, Math.min(1, alpha))
|
|
1719
|
+
ctx.lineWidth = edge.kind === 'link' ? 1.2 : 0.8
|
|
1720
|
+
ctx.setLineDash(edge.kind === 'index' ? [3, 4] : [])
|
|
1721
|
+
ctx.beginPath()
|
|
1722
|
+
ctx.moveTo(a.x, a.y)
|
|
1723
|
+
ctx.lineTo(b.x, b.y)
|
|
1724
|
+
ctx.stroke()
|
|
1725
|
+
}
|
|
1726
|
+
ctx.setLineDash([])
|
|
1727
|
+
|
|
1728
|
+
// 选中节点最后画:它永远不该被别的节点盖住。
|
|
1729
|
+
const order = projected.filter((p) => p.id !== selected)
|
|
1730
|
+
if (selectedPoint !== undefined) order.push(selectedPoint)
|
|
1731
|
+
for (const p of order) {
|
|
1732
|
+
const node = model.byId.get(p.id)
|
|
1733
|
+
if (node === undefined) continue
|
|
1734
|
+
const r = Math.max(1.5, node.baseR * p.scale)
|
|
1735
|
+
const alpha = lit(p.id)
|
|
1736
|
+
? (light ? 0.9 + 0.1 * p.depth : 0.3 + 0.7 * p.depth)
|
|
1737
|
+
: (light ? 0.28 : 0.16)
|
|
1738
|
+
const isSelected = p.id === selected
|
|
1739
|
+
const isHovered = p.id === hovered
|
|
1740
|
+
const color = node.color ?? '#8b8f96'
|
|
1741
|
+
ctx.globalAlpha = Math.max(0.12, Math.min(1, alpha))
|
|
1742
|
+
if (light) {
|
|
1743
|
+
// 浅色主题:实心圆 + 白描边,绝不发光(发光在浅底上变成脏灰白)。
|
|
1744
|
+
ctx.fillStyle = color
|
|
1745
|
+
ctx.beginPath()
|
|
1746
|
+
ctx.arc(p.x, p.y, r, 0, Math.PI * 2)
|
|
1747
|
+
ctx.fill()
|
|
1748
|
+
ctx.strokeStyle = 'rgba(255,255,255,0.95)'
|
|
1749
|
+
ctx.lineWidth = 1.2
|
|
1750
|
+
ctx.stroke()
|
|
1751
|
+
} else {
|
|
1752
|
+
const glow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, r * 2.6)
|
|
1753
|
+
glow.addColorStop(0, graph3dHexToRgba(color, 0.9))
|
|
1754
|
+
glow.addColorStop(0.5, graph3dHexToRgba(color, 0.3))
|
|
1755
|
+
glow.addColorStop(1, graph3dHexToRgba(color, 0))
|
|
1756
|
+
ctx.fillStyle = glow
|
|
1757
|
+
ctx.beginPath()
|
|
1758
|
+
ctx.arc(p.x, p.y, r * 2.6, 0, Math.PI * 2)
|
|
1759
|
+
ctx.fill()
|
|
1760
|
+
ctx.globalAlpha = Math.min(1, (isSelected ? 1 : alpha) + 0.1)
|
|
1761
|
+
ctx.fillStyle = color
|
|
1762
|
+
ctx.beginPath()
|
|
1763
|
+
ctx.arc(p.x, p.y, r, 0, Math.PI * 2)
|
|
1764
|
+
ctx.fill()
|
|
1677
1765
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1766
|
+
if (isSelected || isHovered) {
|
|
1767
|
+
ctx.globalAlpha = 1
|
|
1768
|
+
ctx.strokeStyle = isSelected
|
|
1769
|
+
? (light ? '#1f2328' : '#ffffff')
|
|
1770
|
+
: (light ? 'rgba(31,35,40,0.65)' : 'rgba(255,255,255,0.7)')
|
|
1771
|
+
ctx.lineWidth = 1.6
|
|
1772
|
+
ctx.beginPath()
|
|
1773
|
+
ctx.arc(p.x, p.y, r + 4, 0, Math.PI * 2)
|
|
1774
|
+
ctx.stroke()
|
|
1775
|
+
}
|
|
1776
|
+
const showLabel = isSelected || isHovered || isNeighbour(p.id) || (p.depth > 0.72 && p.scale > 0.9)
|
|
1777
|
+
if (showLabel) {
|
|
1778
|
+
const label = String(node.label).length > 18 ? `${String(node.label).slice(0, 17)}…` : String(node.label)
|
|
1779
|
+
ctx.globalAlpha = isSelected || isHovered ? 1 : 0.88
|
|
1780
|
+
ctx.font = '11px -apple-system, "PingFang SC", sans-serif'
|
|
1781
|
+
ctx.textAlign = 'center'
|
|
1782
|
+
ctx.textBaseline = 'bottom'
|
|
1783
|
+
ctx.lineWidth = 3
|
|
1784
|
+
ctx.strokeStyle = light ? 'rgba(255,255,255,0.9)' : 'rgba(0,0,0,0.35)'
|
|
1785
|
+
ctx.strokeText(label, p.x, p.y - r - 4)
|
|
1786
|
+
ctx.fillStyle = isSelected || isHovered ? theme.labelStrong : theme.label
|
|
1787
|
+
ctx.fillText(label, p.x, p.y - r - 4)
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
ctx.globalAlpha = 1
|
|
1791
|
+
}
|
|
1681
1792
|
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1793
|
+
/** 从真实渲染背景判断明暗主题;CSS 变量读不到时一路向上找实际背景色。 */
|
|
1794
|
+
function graphCanvasTheme(canvas) {
|
|
1795
|
+
const style = typeof getComputedStyle === 'function' ? getComputedStyle(canvas) : undefined
|
|
1796
|
+
const cssVar = (name) => (style?.getPropertyValue?.(name) || '').trim()
|
|
1797
|
+
let background = ''
|
|
1798
|
+
if (typeof getComputedStyle === 'function' && typeof document !== 'undefined') {
|
|
1799
|
+
let node = canvas
|
|
1800
|
+
while (node && node !== document.documentElement) {
|
|
1801
|
+
const bg = getComputedStyle(node).backgroundColor
|
|
1802
|
+
if (bg && bg !== 'rgba(0, 0, 0, 0)' && bg !== 'transparent') {
|
|
1803
|
+
background = bg
|
|
1804
|
+
break
|
|
1805
|
+
}
|
|
1806
|
+
node = node.parentElement
|
|
1696
1807
|
}
|
|
1808
|
+
if (background === '' && document.body) background = getComputedStyle(document.body).backgroundColor
|
|
1809
|
+
}
|
|
1810
|
+
const light = isLightColor(background)
|
|
1811
|
+
return {
|
|
1812
|
+
light,
|
|
1813
|
+
label: light ? '#3d4451' : '#e8ecf7',
|
|
1814
|
+
labelStrong: light ? '#1f2328' : '#ffffff',
|
|
1815
|
+
edges: light
|
|
1816
|
+
? { link: '#2563eb', index: '#6b7280', tag: '#7c3aed' }
|
|
1817
|
+
: {
|
|
1818
|
+
link: cssVar('--dsw-alias-brand-primary') || '#4c8bf5',
|
|
1819
|
+
index: cssVar('--dsw-alias-label-secondary') || '#8b8f96',
|
|
1820
|
+
tag: '#8b7bf5',
|
|
1821
|
+
},
|
|
1697
1822
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
function isLightColor(value) {
|
|
1826
|
+
if (typeof value !== 'string' || value.length === 0) return false
|
|
1827
|
+
const text = value.trim().toLowerCase()
|
|
1828
|
+
const rgb = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(text)
|
|
1829
|
+
if (rgb !== null) {
|
|
1830
|
+
const lum = (0.299 * Number(rgb[1]) + 0.587 * Number(rgb[2]) + 0.114 * Number(rgb[3])) / 255
|
|
1831
|
+
return lum > 0.55
|
|
1704
1832
|
}
|
|
1705
|
-
const
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
setDragging(false)
|
|
1711
|
-
setDragPositions(undefined) // CSS transition glides everything back
|
|
1712
|
-
setDropAnim(false)
|
|
1833
|
+
const hex = /^#([0-9a-f]{3,8})$/.exec(text)
|
|
1834
|
+
if (hex !== null) {
|
|
1835
|
+
const digits = hex[1].length === 3 ? hex[1].split('').map((c) => c + c).join('') : hex[1].slice(0, 6)
|
|
1836
|
+
const num = Number.parseInt(digits, 16)
|
|
1837
|
+
return (0.299 * ((num >> 16) & 255) + 0.587 * ((num >> 8) & 255) + 0.114 * (num & 255)) / 255 > 0.55
|
|
1713
1838
|
}
|
|
1839
|
+
return false
|
|
1840
|
+
}
|
|
1714
1841
|
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1842
|
+
const GraphView = React.memo(function GraphView(props) {
|
|
1843
|
+
const { graph, fetchedAt } = props
|
|
1844
|
+
const t = useT(props)
|
|
1845
|
+
const nodes = graph.nodes ?? []
|
|
1846
|
+
const edges = graph.edges ?? []
|
|
1847
|
+
const stats = graph.stats ?? {}
|
|
1848
|
+
const canvasRef = React.useRef(null)
|
|
1849
|
+
// 尊重系统的「减少动态效果」:默认不自动转,但仍可手动旋转。
|
|
1850
|
+
const reducedMotion = typeof window !== 'undefined'
|
|
1851
|
+
&& typeof window.matchMedia === 'function'
|
|
1852
|
+
&& window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
1853
|
+
const stateRef = React.useRef({
|
|
1854
|
+
view: { yaw: 0.55, pitch: -0.2, zoom: 1 },
|
|
1855
|
+
selected: undefined,
|
|
1856
|
+
hovered: undefined,
|
|
1857
|
+
drag: undefined,
|
|
1858
|
+
spin: !reducedMotion,
|
|
1859
|
+
})
|
|
1860
|
+
const [selected, setSelected] = React.useState(undefined)
|
|
1861
|
+
const [spin, setSpin] = React.useState(!reducedMotion)
|
|
1862
|
+
// 用户拖过的节点位置:轮询刷新时保留,别把布局打回原形。
|
|
1863
|
+
const draggedRef = React.useRef(new Map())
|
|
1864
|
+
|
|
1865
|
+
const model = React.useMemo(() => {
|
|
1866
|
+
const list = nodes.map((n) => ({
|
|
1867
|
+
id: n.id,
|
|
1868
|
+
label: n.label,
|
|
1869
|
+
type: n.type,
|
|
1870
|
+
color: n.color,
|
|
1871
|
+
degree: n.degree ?? 0,
|
|
1872
|
+
hub: n.hub === true,
|
|
1873
|
+
x: 0,
|
|
1874
|
+
y: 0,
|
|
1875
|
+
z: 0,
|
|
1876
|
+
baseR: 4.5 + Math.min(9, (n.degree ?? 0) * 0.6),
|
|
1877
|
+
}))
|
|
1878
|
+
const positions = graph3dSphere(list, GRAPH3D.radius)
|
|
1879
|
+
const byPos = new Map(positions.map((p) => [p.id, p]))
|
|
1880
|
+
for (const node of list) {
|
|
1881
|
+
const pos = byPos.get(node.id)
|
|
1882
|
+
node.x = pos.x
|
|
1883
|
+
node.y = pos.y
|
|
1884
|
+
node.z = pos.z
|
|
1724
1885
|
}
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1886
|
+
for (const [id, pos] of draggedRef.current) {
|
|
1887
|
+
const node = list.find((n) => n.id === id)
|
|
1888
|
+
if (node !== undefined) {
|
|
1889
|
+
node.x = pos.x
|
|
1890
|
+
node.y = pos.y
|
|
1891
|
+
node.z = pos.z
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
const byId = new Map(list.map((n) => [n.id, n]))
|
|
1895
|
+
const adjacency = new Map(list.map((n) => [n.id, new Set()]))
|
|
1896
|
+
const edgeList = edges.filter((e) => byId.has(e.source) && byId.has(e.target))
|
|
1897
|
+
for (const edge of edgeList) {
|
|
1898
|
+
adjacency.get(edge.source).add(edge.target)
|
|
1899
|
+
adjacency.get(edge.target).add(edge.source)
|
|
1900
|
+
}
|
|
1901
|
+
return { nodes: list, byId, edges: edgeList, adjacency }
|
|
1902
|
+
}, [graph])
|
|
1729
1903
|
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
if (drag === undefined) return
|
|
1733
|
-
event.preventDefault?.()
|
|
1734
|
-
setDragPositions(applyDrag(basePositions, drag.id, toGraphPoint(event), edges,
|
|
1735
|
-
{ width: GRAPH_W, height: GRAPH_H }))
|
|
1736
|
-
}
|
|
1904
|
+
React.useEffect(() => { stateRef.current.selected = selected }, [selected])
|
|
1905
|
+
React.useEffect(() => { stateRef.current.spin = spin }, [spin])
|
|
1737
1906
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1907
|
+
// 渲染循环:空闲时球体慢转;画布颜色每年主题切换一次即可。
|
|
1908
|
+
React.useEffect(() => {
|
|
1909
|
+
const canvas = canvasRef.current
|
|
1910
|
+
if (canvas === null || typeof canvas.getContext !== 'function') return undefined
|
|
1911
|
+
const ctx = canvas.getContext('2d')
|
|
1912
|
+
if (ctx === null) return undefined
|
|
1913
|
+
const dpr = Math.min(2, (typeof window !== 'undefined' && window.devicePixelRatio) || 1)
|
|
1914
|
+
canvas.width = Math.floor(GRAPH3D.width * dpr)
|
|
1915
|
+
canvas.height = Math.floor(GRAPH3D.height * dpr)
|
|
1916
|
+
const theme = graphCanvasTheme(canvas)
|
|
1917
|
+
let raf = 0
|
|
1918
|
+
const render = () => {
|
|
1919
|
+
const state = stateRef.current
|
|
1920
|
+
if (state.spin && state.drag === undefined) state.view.yaw += 0.0028
|
|
1921
|
+
drawGraph3D(ctx, model, state, dpr, theme)
|
|
1922
|
+
raf = requestAnimationFrame(render)
|
|
1745
1923
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
}
|
|
1924
|
+
raf = requestAnimationFrame(render)
|
|
1925
|
+
return () => { if (raf !== 0) cancelAnimationFrame(raf) }
|
|
1926
|
+
}, [model])
|
|
1749
1927
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
const
|
|
1754
|
-
|
|
1755
|
-
const
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1928
|
+
// 交互:hover 即时高亮;点击用「位移 + 时长」双阈值判定(demo 的单阈值
|
|
1929
|
+
// 会让轻点变成拖拽,选中不生效)。
|
|
1930
|
+
React.useEffect(() => {
|
|
1931
|
+
const canvas = canvasRef.current
|
|
1932
|
+
if (canvas === null || typeof canvas.addEventListener !== 'function') return undefined
|
|
1933
|
+
const localPoint = (event) => {
|
|
1934
|
+
const rect = canvas.getBoundingClientRect()
|
|
1935
|
+
if (rect.width === 0 || rect.height === 0) return { x: event.clientX, y: event.clientY }
|
|
1936
|
+
return {
|
|
1937
|
+
x: ((event.clientX - rect.left) / rect.width) * GRAPH3D.width,
|
|
1938
|
+
y: ((event.clientY - rect.top) / rect.height) * GRAPH3D.height,
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
const projectedNow = () => model.nodes.map((node) => graph3dProject(node, stateRef.current.view))
|
|
1942
|
+
const radiusOf = (point) => {
|
|
1943
|
+
const node = model.byId.get(point.id)
|
|
1944
|
+
return Math.max(6, (node?.baseR ?? 6) * point.scale + 5)
|
|
1945
|
+
}
|
|
1946
|
+
const hoverAt = (point) => {
|
|
1947
|
+
const hit = graph3dHit(projectedNow(), point.x, point.y, radiusOf)
|
|
1948
|
+
stateRef.current.hovered = hit?.id ?? undefined
|
|
1949
|
+
}
|
|
1950
|
+
const onDown = (event) => {
|
|
1951
|
+
if (event.button !== undefined && event.button !== 0) return
|
|
1952
|
+
const point = localPoint(event)
|
|
1953
|
+
const hit = graph3dHit(projectedNow(), point.x, point.y, radiusOf)
|
|
1954
|
+
stateRef.current.drag = {
|
|
1955
|
+
kind: hit !== null ? 'node' : 'rotate',
|
|
1956
|
+
id: hit?.id,
|
|
1957
|
+
pointerId: event.pointerId,
|
|
1958
|
+
startClientX: event.clientX,
|
|
1959
|
+
startClientY: event.clientY,
|
|
1960
|
+
lastX: point.x,
|
|
1961
|
+
lastY: point.y,
|
|
1962
|
+
startAt: Date.now(),
|
|
1963
|
+
moved: false,
|
|
1964
|
+
}
|
|
1965
|
+
try { canvas.setPointerCapture?.(event.pointerId) } catch { /* synthetic events have no capture */ }
|
|
1966
|
+
}
|
|
1967
|
+
const onMove = (event) => {
|
|
1968
|
+
const point = localPoint(event)
|
|
1969
|
+
const drag = stateRef.current.drag
|
|
1970
|
+
if (drag === undefined) {
|
|
1971
|
+
hoverAt(point)
|
|
1972
|
+
return
|
|
1973
|
+
}
|
|
1974
|
+
if (drag.pointerId !== undefined && event.pointerId !== drag.pointerId) return
|
|
1975
|
+
if (drag.kind === 'node') {
|
|
1976
|
+
const node = model.byId.get(drag.id)
|
|
1977
|
+
if (node === undefined) return
|
|
1978
|
+
const view = stateRef.current.view
|
|
1979
|
+
const projection = graph3dProject(node, view)
|
|
1980
|
+
const dx = (point.x - drag.lastX) / Math.max(0.05, projection.scale)
|
|
1981
|
+
const dy = (point.y - drag.lastY) / Math.max(0.05, projection.scale)
|
|
1982
|
+
const rotated = graph3dRotate(node, view.yaw, view.pitch)
|
|
1983
|
+
const world = graph3dUnrotate(
|
|
1984
|
+
{ x: rotated.x + dx, y: rotated.y + dy, z: rotated.z },
|
|
1985
|
+
view.yaw,
|
|
1986
|
+
view.pitch,
|
|
1987
|
+
)
|
|
1988
|
+
node.x = world.x
|
|
1989
|
+
node.y = world.y
|
|
1990
|
+
node.z = world.z
|
|
1991
|
+
draggedRef.current.set(node.id, { x: node.x, y: node.y, z: node.z })
|
|
1992
|
+
drag.lastX = point.x
|
|
1993
|
+
drag.lastY = point.y
|
|
1994
|
+
drag.moved = true
|
|
1995
|
+
} else {
|
|
1996
|
+
const moved = Math.hypot(event.clientX - drag.startClientX, event.clientY - drag.startClientY)
|
|
1997
|
+
if (moved > 2) drag.moved = true
|
|
1998
|
+
if (drag.moved) {
|
|
1999
|
+
stateRef.current.view.yaw += (event.clientX - drag.startClientX) * 0.006
|
|
2000
|
+
stateRef.current.view.pitch = Math.max(
|
|
2001
|
+
-1.2,
|
|
2002
|
+
Math.min(1.2, stateRef.current.view.pitch - (event.clientY - drag.startClientY) * 0.006),
|
|
2003
|
+
)
|
|
2004
|
+
drag.startClientX = event.clientX
|
|
2005
|
+
drag.startClientY = event.clientY
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
hoverAt(point)
|
|
2009
|
+
}
|
|
2010
|
+
const onUp = (event) => {
|
|
2011
|
+
const drag = stateRef.current.drag
|
|
2012
|
+
stateRef.current.drag = undefined
|
|
2013
|
+
if (drag === undefined) return
|
|
2014
|
+
const duration = Date.now() - drag.startAt
|
|
2015
|
+
const moved = Math.hypot(event.clientX - drag.startClientX, event.clientY - drag.startClientY)
|
|
2016
|
+
const isClick = !drag.moved && duration <= GRAPH3D.clickMs && moved <= GRAPH3D.clickSlop
|
|
2017
|
+
if (!isClick) return
|
|
2018
|
+
if (drag.kind === 'node') {
|
|
2019
|
+
const next = stateRef.current.selected === drag.id ? undefined : drag.id
|
|
2020
|
+
stateRef.current.selected = next
|
|
2021
|
+
setSelected(next)
|
|
2022
|
+
} else {
|
|
2023
|
+
stateRef.current.selected = undefined
|
|
2024
|
+
setSelected(undefined)
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
const onWheel = (event) => {
|
|
2028
|
+
event.preventDefault()
|
|
2029
|
+
const factor = event.deltaY < 0 ? 1.08 : 0.92
|
|
2030
|
+
stateRef.current.view.zoom = Math.max(
|
|
2031
|
+
GRAPH3D.zoomMin,
|
|
2032
|
+
Math.min(GRAPH3D.zoomMax, stateRef.current.view.zoom * factor),
|
|
2033
|
+
)
|
|
2034
|
+
}
|
|
2035
|
+
const onDouble = (event) => {
|
|
2036
|
+
const point = localPoint(event)
|
|
2037
|
+
const hit = graph3dHit(projectedNow(), point.x, point.y, radiusOf)
|
|
2038
|
+
if (hit !== null) return
|
|
2039
|
+
stateRef.current.view = { yaw: 0.55, pitch: -0.2, zoom: 1 }
|
|
2040
|
+
stateRef.current.selected = undefined
|
|
2041
|
+
setSelected(undefined)
|
|
2042
|
+
}
|
|
2043
|
+
const onLeave = () => {
|
|
2044
|
+
stateRef.current.hovered = undefined
|
|
2045
|
+
stateRef.current.drag = undefined
|
|
2046
|
+
}
|
|
2047
|
+
canvas.addEventListener('pointerdown', onDown)
|
|
2048
|
+
canvas.addEventListener('pointermove', onMove)
|
|
2049
|
+
canvas.addEventListener('pointerup', onUp)
|
|
2050
|
+
canvas.addEventListener('pointercancel', onUp)
|
|
2051
|
+
canvas.addEventListener('pointerleave', onLeave)
|
|
2052
|
+
canvas.addEventListener('wheel', onWheel, { passive: false })
|
|
2053
|
+
canvas.addEventListener('dblclick', onDouble)
|
|
2054
|
+
return () => {
|
|
2055
|
+
canvas.removeEventListener('pointerdown', onDown)
|
|
2056
|
+
canvas.removeEventListener('pointermove', onMove)
|
|
2057
|
+
canvas.removeEventListener('pointerup', onUp)
|
|
2058
|
+
canvas.removeEventListener('pointercancel', onUp)
|
|
2059
|
+
canvas.removeEventListener('pointerleave', onLeave)
|
|
2060
|
+
canvas.removeEventListener('wheel', onWheel)
|
|
2061
|
+
canvas.removeEventListener('dblclick', onDouble)
|
|
2062
|
+
}
|
|
2063
|
+
}, [model])
|
|
1793
2064
|
|
|
1794
|
-
|
|
1795
|
-
.filter(Boolean).join(' ')
|
|
1796
|
-
const svg = React.createElement('svg', {
|
|
1797
|
-
ref: svgRef,
|
|
1798
|
-
viewBox: `${view.x} ${view.y} ${view.w} ${view.h}`,
|
|
1799
|
-
width: '100%',
|
|
1800
|
-
className: svgClass,
|
|
1801
|
-
style: {
|
|
1802
|
-
display: 'block',
|
|
1803
|
-
borderRadius: '8px',
|
|
1804
|
-
background: 'var(--dsw-alias-bg-layer-1, transparent)',
|
|
1805
|
-
touchAction: 'none',
|
|
1806
|
-
cursor: zoomed ? 'grab' : 'default',
|
|
1807
|
-
},
|
|
1808
|
-
role: 'img',
|
|
1809
|
-
'aria-label': t('graphTitle'),
|
|
1810
|
-
onPointerDown: panStart,
|
|
1811
|
-
onPointerMove: panMove,
|
|
1812
|
-
onPointerUp: panEnd,
|
|
1813
|
-
onPointerLeave: panEnd,
|
|
1814
|
-
},
|
|
1815
|
-
edges.map((e, index) => {
|
|
1816
|
-
const a = byId.get(e.source)
|
|
1817
|
-
const b = byId.get(e.target)
|
|
1818
|
-
if (a === undefined || b === undefined) return null
|
|
1819
|
-
const pa = posOf(a)
|
|
1820
|
-
const pb = posOf(b)
|
|
1821
|
-
return React.createElement('line', {
|
|
1822
|
-
key: `e${index}`,
|
|
1823
|
-
x1: pa.x, y1: pa.y, x2: pb.x, y2: pb.y,
|
|
1824
|
-
stroke: e.kind === 'link'
|
|
1825
|
-
? 'var(--dsw-alias-brand-primary, #4c8bf5)'
|
|
1826
|
-
: e.kind === 'index'
|
|
1827
|
-
? 'var(--dsw-alias-label-secondary, #8b8f96)'
|
|
1828
|
-
: 'var(--dsw-alias-border-l2, rgba(128,128,128,0.45))',
|
|
1829
|
-
strokeWidth: e.kind === 'link' ? 1.4 : 0.7,
|
|
1830
|
-
strokeDasharray: e.kind === 'index' ? '2 3' : undefined,
|
|
1831
|
-
strokeOpacity: litEdge(e) ? (e.kind === 'index' ? 0.5 : 0.9) : (e.kind === 'index' ? 0.08 : 0.12),
|
|
1832
|
-
})
|
|
1833
|
-
}),
|
|
1834
|
-
nodes.map(renderNode),
|
|
1835
|
-
)
|
|
2065
|
+
if (nodes.length === 0) return null
|
|
1836
2066
|
|
|
2067
|
+
const byId = model.byId
|
|
1837
2068
|
const colourOf = (type) => (nodes.find((n) => n.type === type)?.color) ?? '#8b8f96'
|
|
1838
2069
|
const chips = [...new Set(nodes.map((n) => n.type))]
|
|
1839
2070
|
.filter((type) => type !== 'unknown')
|
|
@@ -1844,26 +2075,38 @@ window.__ModuleLoader__.load({
|
|
|
1844
2075
|
React.createElement('span', { style: { width: '7px', height: '7px', borderRadius: '4px', background: colourOf(type), display: 'inline-block' } }),
|
|
1845
2076
|
typeLabel(type, t),
|
|
1846
2077
|
))
|
|
1847
|
-
|
|
1848
2078
|
const isolated = stats.isolated ?? []
|
|
2079
|
+
const selectedNode = selected !== undefined ? byId.get(selected) : undefined
|
|
2080
|
+
const selectedNeighbours = selected !== undefined ? (model.adjacency.get(selected)?.size ?? 0) : 0
|
|
2081
|
+
const smallButtonStyle = {
|
|
2082
|
+
fontSize: '11px',
|
|
2083
|
+
padding: '2px 8px',
|
|
2084
|
+
borderRadius: '6px',
|
|
2085
|
+
cursor: 'pointer',
|
|
2086
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))',
|
|
2087
|
+
background: 'transparent',
|
|
2088
|
+
color: 'var(--dsw-alias-label-secondary, #999)',
|
|
2089
|
+
}
|
|
2090
|
+
|
|
1849
2091
|
return React.createElement('div', { style: cardStyle },
|
|
1850
2092
|
React.createElement('div', { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: '8px' } },
|
|
1851
2093
|
React.createElement('div', { style: cardTitleStyle }, t('graphTitle')),
|
|
1852
|
-
|
|
1853
|
-
|
|
2094
|
+
React.createElement('div', { style: { display: 'flex', gap: '6px' } },
|
|
2095
|
+
React.createElement('button', {
|
|
1854
2096
|
type: 'button',
|
|
1855
|
-
onClick:
|
|
1856
|
-
style:
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
2097
|
+
onClick: () => setSpin((value) => !value),
|
|
2098
|
+
style: smallButtonStyle,
|
|
2099
|
+
}, `${t('graph3dSpin')}${spin ? ' ✓' : ''}`),
|
|
2100
|
+
React.createElement('button', {
|
|
2101
|
+
type: 'button',
|
|
2102
|
+
onClick: () => {
|
|
2103
|
+
stateRef.current.view = { yaw: 0.55, pitch: -0.2, zoom: 1 }
|
|
2104
|
+
stateRef.current.selected = undefined
|
|
2105
|
+
setSelected(undefined)
|
|
1864
2106
|
},
|
|
1865
|
-
|
|
1866
|
-
|
|
2107
|
+
style: smallButtonStyle,
|
|
2108
|
+
}, t('graphResetView')),
|
|
2109
|
+
),
|
|
1867
2110
|
),
|
|
1868
2111
|
React.createElement('div', { style: cardSubStyle },
|
|
1869
2112
|
fill(t('graphStats'), { pages: stats.pages ?? nodes.length, links: stats.links ?? 0, tagEdges: stats.tagEdges ?? 0 })
|
|
@@ -1871,7 +2114,41 @@ window.__ModuleLoader__.load({
|
|
|
1871
2114
|
+ (isolated.length > 0 ? ` · ${fill(t('graphIsolated'), { count: isolated.length })}` : '')
|
|
1872
2115
|
+ (fetchedAt instanceof Date ? ` · ${fill(t('graphUpdatedAt'), { time: fetchedAt.toLocaleTimeString() })}` : ''),
|
|
1873
2116
|
),
|
|
1874
|
-
|
|
2117
|
+
React.createElement('canvas', {
|
|
2118
|
+
ref: canvasRef,
|
|
2119
|
+
'aria-label': t('graphTitle'),
|
|
2120
|
+
role: 'img',
|
|
2121
|
+
style: {
|
|
2122
|
+
display: 'block',
|
|
2123
|
+
width: '100%',
|
|
2124
|
+
height: 'auto',
|
|
2125
|
+
aspectRatio: `${GRAPH3D.width} / ${GRAPH3D.height}`,
|
|
2126
|
+
borderRadius: '8px',
|
|
2127
|
+
touchAction: 'none',
|
|
2128
|
+
cursor: 'grab',
|
|
2129
|
+
},
|
|
2130
|
+
}),
|
|
2131
|
+
React.createElement('div', { style: { marginTop: '8px', fontSize: '11px', lineHeight: '17px', color: 'var(--dsw-alias-label-secondary, #888)' } },
|
|
2132
|
+
t('graph3dHint'),
|
|
2133
|
+
),
|
|
2134
|
+
selectedNode !== undefined
|
|
2135
|
+
? React.createElement('div', {
|
|
2136
|
+
role: 'status',
|
|
2137
|
+
style: {
|
|
2138
|
+
marginTop: '6px',
|
|
2139
|
+
padding: '6px 8px',
|
|
2140
|
+
borderRadius: '6px',
|
|
2141
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))',
|
|
2142
|
+
fontSize: '11px',
|
|
2143
|
+
lineHeight: '17px',
|
|
2144
|
+
},
|
|
2145
|
+
},
|
|
2146
|
+
React.createElement('b', null, selectedNode.label),
|
|
2147
|
+
` · ${typeLabel(selectedNode.type, t)} · degree ${selectedNode.degree} · `,
|
|
2148
|
+
fill(t('graph3dNeighbours'), { count: selectedNeighbours }),
|
|
2149
|
+
React.createElement('div', { style: { color: 'var(--dsw-alias-label-secondary, #888)' } }, selectedNode.id),
|
|
2150
|
+
)
|
|
2151
|
+
: null,
|
|
1875
2152
|
React.createElement('div', { style: { marginTop: '8px' } }, ...chips),
|
|
1876
2153
|
((stats.links ?? 0) === 0 || isolated.length > 0)
|
|
1877
2154
|
? React.createElement('div', { style: { fontSize: '11px', lineHeight: '17px', color: 'var(--dsw-alias-label-secondary, #888)', marginTop: '6px' } },
|
|
@@ -1888,8 +2165,6 @@ window.__ModuleLoader__.load({
|
|
|
1888
2165
|
React.createElement('span', { style: { color: 'var(--dsw-alias-brand-primary, #4c8bf5)' } }, t('legendLinks')),
|
|
1889
2166
|
' · ',
|
|
1890
2167
|
React.createElement('span', { style: { color: '#8b8f96' } }, t('legendIndexRoutes')),
|
|
1891
|
-
' · ',
|
|
1892
|
-
t('graphHint'),
|
|
1893
2168
|
),
|
|
1894
2169
|
)
|
|
1895
2170
|
})
|
|
@@ -2100,6 +2375,13 @@ window.__ModuleLoader__.load({
|
|
|
2100
2375
|
MAX_VIEW_SCALE,
|
|
2101
2376
|
GRAPH_W,
|
|
2102
2377
|
GRAPH_H,
|
|
2378
|
+
GRAPH3D,
|
|
2379
|
+
graph3dSphere,
|
|
2380
|
+
graph3dRotate,
|
|
2381
|
+
graph3dUnrotate,
|
|
2382
|
+
graph3dProject,
|
|
2383
|
+
graph3dHit,
|
|
2384
|
+
isLightColor,
|
|
2103
2385
|
}
|
|
2104
2386
|
return module.exports
|
|
2105
2387
|
},
|