@andespindola/brainlink 0.1.0-beta.67 → 0.1.0-beta.69

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.
@@ -17,7 +17,7 @@ const worldCoordinateLimit = 5_000_000
17
17
  const transformCoordinateLimit = 20_000_000
18
18
  const hoverHitTestIntervalMs = 64
19
19
  const overviewClusterMaxCount = 1400
20
- const zoomRecoveryGuardMs = 1500
20
+ const zoomRecoveryGuardMs = 4200
21
21
  const zoomCapTargetViewportShare = 0.72
22
22
  const meshEdgeScaleThreshold = 0.09
23
23
  const meshEdgeMinBudget = 140
@@ -684,6 +684,38 @@ const mergeUniqueNodes = (leftNodes, rightNodes, limit) => {
684
684
  return merged
685
685
  }
686
686
 
687
+ const selectStableSampleNodes = (sourceNodes, limit) => {
688
+ if (sourceNodes.length <= limit) {
689
+ return sourceNodes
690
+ }
691
+
692
+ const now = performance.now()
693
+ const recentZoomFocus =
694
+ now - state.lastZoomFocus.at <= 1500
695
+ ? { x: state.lastZoomFocus.x, y: state.lastZoomFocus.y }
696
+ : null
697
+ const anchor = recentZoomFocus ?? viewportCenterWorldPoint()
698
+ const previousIds = new Set(state.renderNodes.map((node) => node.id))
699
+
700
+ return [...sourceNodes]
701
+ .sort((left, right) => {
702
+ const leftWasVisible = previousIds.has(left.id) ? 1 : 0
703
+ const rightWasVisible = previousIds.has(right.id) ? 1 : 0
704
+ if (leftWasVisible !== rightWasVisible) return rightWasVisible - leftWasVisible
705
+
706
+ const leftDistance = Math.hypot(left.x - anchor.x, left.y - anchor.y)
707
+ const rightDistance = Math.hypot(right.x - anchor.x, right.y - anchor.y)
708
+ if (leftDistance !== rightDistance) return leftDistance - rightDistance
709
+
710
+ const leftDegree = state.nodeDegrees.get(left.id) ?? 0
711
+ const rightDegree = state.nodeDegrees.get(right.id) ?? 0
712
+ if (leftDegree !== rightDegree) return rightDegree - leftDegree
713
+
714
+ return left.id.localeCompare(right.id)
715
+ })
716
+ .slice(0, limit)
717
+ }
718
+
687
719
  const selectAccessBridgeNodes = (sourceNodes, limit) => {
688
720
  if (limit <= 0 || sourceNodes.length === 0) {
689
721
  return []
@@ -1741,9 +1773,10 @@ const computeRenderVisibility = () => {
1741
1773
  selectAccessBridgeNodes(sourceNodes, bridgeLimit),
1742
1774
  Math.min(renderNodeBudget, sampleLimit + bridgeLimit)
1743
1775
  )
1744
- const sampled = bridgedNodes.length > sampleLimit
1745
- ? sampleVisibleNodes(Math.min(sampleLimit, renderNodeBudget), bridgedNodes)
1746
- : bridgedNodes.slice(0, Math.min(bridgedNodes.length, renderNodeBudget))
1776
+ const sampled = selectStableSampleNodes(
1777
+ bridgedNodes,
1778
+ Math.min(sampleLimit, renderNodeBudget)
1779
+ )
1747
1780
  const sampledIds = new Set(sampled.map((node) => node.id))
1748
1781
  let sampledEdges = state.transform.scale >= 0.035 ? collectVisibleEdgesForNodes(sampledIds) : []
1749
1782
  let sampledNodes = ensureHubNodesInRenderedSet(sampled)
@@ -1901,9 +1934,10 @@ const render = now => {
1901
1934
  tick(delta)
1902
1935
  const hasVisibleNodeOnScreen = state.renderNodes.some((node) => isNodeVisibleOnScreen(node, width, height))
1903
1936
  const manualZoomGuardActive = now - state.lastManualZoomAt < zoomRecoveryGuardMs
1904
- if (!hasVisibleNodeOnScreen && state.renderNodes.length > 0 && !manualZoomGuardActive) {
1937
+ const allowViewportAutoRecovery = state.nodes.length <= massiveGraphNodeThreshold
1938
+ if (allowViewportAutoRecovery && !hasVisibleNodeOnScreen && state.renderNodes.length > 0 && !manualZoomGuardActive) {
1905
1939
  state.offscreenFrameCount += 1
1906
- if (state.offscreenFrameCount >= 6 && !state.recoveringViewport) {
1940
+ if (state.offscreenFrameCount >= 22 && !state.recoveringViewport) {
1907
1941
  state.recoveringViewport = true
1908
1942
  fitView({ useFiltered: true })
1909
1943
  state.offscreenFrameCount = 0
@@ -2104,9 +2138,7 @@ const selectNodeById = id => {
2104
2138
  }
2105
2139
 
2106
2140
  const zoomAtPoint = (screenX, screenY, factor, source = 'generic') => {
2107
- if (source === 'wheel') {
2108
- state.lastManualZoomAt = performance.now()
2109
- }
2141
+ state.lastManualZoomAt = performance.now()
2110
2142
  const nextScale = clampScale(state.transform.scale * factor)
2111
2143
  if (nextScale === state.transform.scale) {
2112
2144
  return
@@ -2134,7 +2166,7 @@ const wheelZoomFactor = event => {
2134
2166
  return 1
2135
2167
  }
2136
2168
 
2137
- const baseStep = Math.max(0.03, Math.min(0.2, absoluteDelta / 680))
2169
+ const baseStep = Math.max(0.012, Math.min(0.11, absoluteDelta / 980))
2138
2170
  const adjustedStep = baseStep * (isModifierZoom ? 1.24 : 1)
2139
2171
 
2140
2172
  return event.deltaY < 0 ? 1 + adjustedStep : 1 / (1 + adjustedStep)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andespindola/brainlink",
3
- "version": "0.1.0-beta.67",
3
+ "version": "0.1.0-beta.69",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",