@andespindola/brainlink 0.1.0-beta.145 → 0.1.0-beta.146
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.
|
@@ -32,8 +32,11 @@ const state = {
|
|
|
32
32
|
pointer: {
|
|
33
33
|
down: false,
|
|
34
34
|
moved: false,
|
|
35
|
+
dragging: false,
|
|
35
36
|
x: 0,
|
|
36
37
|
y: 0,
|
|
38
|
+
startX: 0,
|
|
39
|
+
startY: 0,
|
|
37
40
|
worldAnchorX: 0,
|
|
38
41
|
worldAnchorY: 0
|
|
39
42
|
},
|
|
@@ -56,6 +59,8 @@ const state = {
|
|
|
56
59
|
searchToken: 0,
|
|
57
60
|
fetchToken: 0,
|
|
58
61
|
fetchTimer: null,
|
|
62
|
+
cameraSyncScheduled: false,
|
|
63
|
+
lastDragFetchAt: 0,
|
|
59
64
|
lastVisibleNodes: 0,
|
|
60
65
|
lastVisibleEdges: 0,
|
|
61
66
|
totals: {
|
|
@@ -242,9 +247,19 @@ const updateWorkerCamera = () => {
|
|
|
242
247
|
if (!state.renderWorker || !state.workerReady) {
|
|
243
248
|
return
|
|
244
249
|
}
|
|
245
|
-
state.
|
|
246
|
-
|
|
247
|
-
|
|
250
|
+
if (state.cameraSyncScheduled) {
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
state.cameraSyncScheduled = true
|
|
254
|
+
requestAnimationFrame(() => {
|
|
255
|
+
state.cameraSyncScheduled = false
|
|
256
|
+
if (!state.renderWorker || !state.workerReady) {
|
|
257
|
+
return
|
|
258
|
+
}
|
|
259
|
+
state.renderWorker.postMessage({
|
|
260
|
+
type: 'camera',
|
|
261
|
+
camera: state.camera
|
|
262
|
+
})
|
|
248
263
|
})
|
|
249
264
|
}
|
|
250
265
|
|
|
@@ -575,6 +590,8 @@ const resolvePointer = (event) => {
|
|
|
575
590
|
}
|
|
576
591
|
|
|
577
592
|
const setupInput = () => {
|
|
593
|
+
const dragActivationDistance = 6
|
|
594
|
+
|
|
578
595
|
canvas.addEventListener('wheel', (event) => {
|
|
579
596
|
event.preventDefault()
|
|
580
597
|
const pointer = resolvePointer(event)
|
|
@@ -586,8 +603,11 @@ const setupInput = () => {
|
|
|
586
603
|
const pointer = resolvePointer(event)
|
|
587
604
|
state.pointer.down = true
|
|
588
605
|
state.pointer.moved = false
|
|
606
|
+
state.pointer.dragging = false
|
|
589
607
|
state.pointer.x = pointer.x
|
|
590
608
|
state.pointer.y = pointer.y
|
|
609
|
+
state.pointer.startX = pointer.x
|
|
610
|
+
state.pointer.startY = pointer.y
|
|
591
611
|
const world = screenToWorld(pointer.x, pointer.y)
|
|
592
612
|
state.pointer.worldAnchorX = world.x
|
|
593
613
|
state.pointer.worldAnchorY = world.y
|
|
@@ -600,15 +620,26 @@ const setupInput = () => {
|
|
|
600
620
|
if (state.pointer.down) {
|
|
601
621
|
const dx = pointer.x - state.pointer.x
|
|
602
622
|
const dy = pointer.y - state.pointer.y
|
|
603
|
-
|
|
623
|
+
const distanceFromStart = Math.hypot(pointer.x - state.pointer.startX, pointer.y - state.pointer.startY)
|
|
624
|
+
if (distanceFromStart >= dragActivationDistance) {
|
|
604
625
|
state.pointer.moved = true
|
|
626
|
+
state.pointer.dragging = true
|
|
627
|
+
}
|
|
628
|
+
if (!state.pointer.dragging) {
|
|
629
|
+
state.pointer.x = pointer.x
|
|
630
|
+
state.pointer.y = pointer.y
|
|
631
|
+
return
|
|
605
632
|
}
|
|
606
633
|
state.camera.x += dx
|
|
607
634
|
state.camera.y += dy
|
|
608
635
|
state.pointer.x = pointer.x
|
|
609
636
|
state.pointer.y = pointer.y
|
|
610
637
|
updateWorkerCamera()
|
|
611
|
-
|
|
638
|
+
const now = performance.now()
|
|
639
|
+
if (now - state.lastDragFetchAt > 180) {
|
|
640
|
+
state.lastDragFetchAt = now
|
|
641
|
+
scheduleChunkFetch()
|
|
642
|
+
}
|
|
612
643
|
drawFallback()
|
|
613
644
|
return
|
|
614
645
|
}
|
|
@@ -624,12 +655,19 @@ const setupInput = () => {
|
|
|
624
655
|
|
|
625
656
|
canvas.addEventListener('pointerup', (event) => {
|
|
626
657
|
const pointer = resolvePointer(event)
|
|
627
|
-
const
|
|
658
|
+
const distanceFromStart = Math.hypot(pointer.x - state.pointer.startX, pointer.y - state.pointer.startY)
|
|
659
|
+
const shouldPick = !state.pointer.dragging && distanceFromStart < dragActivationDistance
|
|
660
|
+
const shouldRefreshAfterDrag = state.pointer.dragging
|
|
628
661
|
state.pointer.down = false
|
|
662
|
+
state.pointer.dragging = false
|
|
629
663
|
canvas.releasePointerCapture(event.pointerId)
|
|
630
664
|
|
|
631
665
|
if (shouldPick) {
|
|
632
666
|
pickAt(pointer.x, pointer.y)
|
|
667
|
+
return
|
|
668
|
+
}
|
|
669
|
+
if (shouldRefreshAfterDrag) {
|
|
670
|
+
scheduleChunkFetch()
|
|
633
671
|
}
|
|
634
672
|
})
|
|
635
673
|
|
package/package.json
CHANGED