Spaces:
Paused
Paused
Savestate: Add scroll wheel zooming to detective board and fix SVG path z-fighting issue
Browse files- index.html +1 -1
- src/ai/research-canvas.js +20 -6
- src/styles/detective-board.css +3 -2
index.html
CHANGED
|
@@ -65,7 +65,7 @@
|
|
| 65 |
</head>
|
| 66 |
<body class="dark-theme in-chat-view" data-bg-style="fluid-dark">
|
| 67 |
|
| 68 |
-
<div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.
|
| 69 |
|
| 70 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 71 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
|
|
|
| 65 |
</head>
|
| 66 |
<body class="dark-theme in-chat-view" data-bg-style="fluid-dark">
|
| 67 |
|
| 68 |
+
<div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.176</div>
|
| 69 |
|
| 70 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 71 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
src/ai/research-canvas.js
CHANGED
|
@@ -6,6 +6,7 @@ let nodesMap = new Map();
|
|
| 6 |
let currentY = 150; // Starting Y position
|
| 7 |
let currentPanX = 0;
|
| 8 |
let currentPanY = 0;
|
|
|
|
| 9 |
// We offset everything to the top center because the center of the screen is (0,0) in our new DOM structure
|
| 10 |
const originOffsetY = -500;
|
| 11 |
|
|
@@ -15,8 +16,8 @@ let latestNodeId = null;
|
|
| 15 |
|
| 16 |
// Mathematical projection to convert screen pixels to canvas panning
|
| 17 |
function unprojectFromScreen(sx, sy) {
|
| 18 |
-
const px = sx /
|
| 19 |
-
const py = sy /
|
| 20 |
const rx = px;
|
| 21 |
const ry = py / 0.5; // Undo rotateX(60deg) -> cos(60)=0.5
|
| 22 |
const cos45 = 0.70710678, sin45 = 0.70710678;
|
|
@@ -34,7 +35,7 @@ function projectToScreen(cx, cy) {
|
|
| 34 |
const ry = cx * (-sin45) + cy * cos45;
|
| 35 |
const px = rx;
|
| 36 |
const py = ry * 0.5; // Apply rotateX(60deg)
|
| 37 |
-
return { x: px *
|
| 38 |
}
|
| 39 |
|
| 40 |
function scrollToLatestNode() {
|
|
@@ -92,11 +93,13 @@ export async function initCanvas() {
|
|
| 92 |
currentY = 150;
|
| 93 |
currentPanX = 0;
|
| 94 |
currentPanY = 0;
|
|
|
|
| 95 |
latestNodeId = null;
|
| 96 |
isUserScrolled = false;
|
| 97 |
|
| 98 |
canvas.style.setProperty('--pan-x', '0px');
|
| 99 |
canvas.style.setProperty('--pan-y', '0px');
|
|
|
|
| 100 |
panLayer.style.setProperty('--pan-x', '0px');
|
| 101 |
panLayer.style.setProperty('--pan-y', '0px');
|
| 102 |
|
|
@@ -110,12 +113,23 @@ export async function initCanvas() {
|
|
| 110 |
};
|
| 111 |
}
|
| 112 |
|
| 113 |
-
// Setup drag
|
| 114 |
if (!scene.dataset.dragInitialized) {
|
| 115 |
scene.dataset.dragInitialized = 'true';
|
| 116 |
let isDragging = false;
|
| 117 |
let startX, startY, startPanX, startPanY;
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
scene.addEventListener('mousedown', (e) => {
|
| 120 |
if (e.target === scrollBottomBtn || e.target.closest('#db-scroll-bottom-btn')) return;
|
| 121 |
isDragging = true;
|
|
@@ -123,14 +137,14 @@ export async function initCanvas() {
|
|
| 123 |
startY = e.pageY;
|
| 124 |
startPanX = currentPanX;
|
| 125 |
startPanY = currentPanY;
|
| 126 |
-
if (canvas) canvas.style.transition = '
|
| 127 |
if (panLayer) panLayer.style.transition = 'none';
|
| 128 |
});
|
| 129 |
|
| 130 |
const stopDrag = () => {
|
| 131 |
if (!isDragging) return;
|
| 132 |
isDragging = false;
|
| 133 |
-
if (canvas) canvas.style.transition = 'background-position 0.5s ease-out';
|
| 134 |
if (panLayer) panLayer.style.transition = 'transform 0.5s ease-out';
|
| 135 |
};
|
| 136 |
scene.addEventListener('mouseleave', stopDrag);
|
|
|
|
| 6 |
let currentY = 150; // Starting Y position
|
| 7 |
let currentPanX = 0;
|
| 8 |
let currentPanY = 0;
|
| 9 |
+
let currentZoom = 0.65;
|
| 10 |
// We offset everything to the top center because the center of the screen is (0,0) in our new DOM structure
|
| 11 |
const originOffsetY = -500;
|
| 12 |
|
|
|
|
| 16 |
|
| 17 |
// Mathematical projection to convert screen pixels to canvas panning
|
| 18 |
function unprojectFromScreen(sx, sy) {
|
| 19 |
+
const px = sx / currentZoom;
|
| 20 |
+
const py = sy / currentZoom;
|
| 21 |
const rx = px;
|
| 22 |
const ry = py / 0.5; // Undo rotateX(60deg) -> cos(60)=0.5
|
| 23 |
const cos45 = 0.70710678, sin45 = 0.70710678;
|
|
|
|
| 35 |
const ry = cx * (-sin45) + cy * cos45;
|
| 36 |
const px = rx;
|
| 37 |
const py = ry * 0.5; // Apply rotateX(60deg)
|
| 38 |
+
return { x: px * currentZoom, y: py * currentZoom };
|
| 39 |
}
|
| 40 |
|
| 41 |
function scrollToLatestNode() {
|
|
|
|
| 93 |
currentY = 150;
|
| 94 |
currentPanX = 0;
|
| 95 |
currentPanY = 0;
|
| 96 |
+
currentZoom = 0.65;
|
| 97 |
latestNodeId = null;
|
| 98 |
isUserScrolled = false;
|
| 99 |
|
| 100 |
canvas.style.setProperty('--pan-x', '0px');
|
| 101 |
canvas.style.setProperty('--pan-y', '0px');
|
| 102 |
+
canvas.style.setProperty('--zoom', currentZoom);
|
| 103 |
panLayer.style.setProperty('--pan-x', '0px');
|
| 104 |
panLayer.style.setProperty('--pan-y', '0px');
|
| 105 |
|
|
|
|
| 113 |
};
|
| 114 |
}
|
| 115 |
|
| 116 |
+
// Setup drag and zoom (only once)
|
| 117 |
if (!scene.dataset.dragInitialized) {
|
| 118 |
scene.dataset.dragInitialized = 'true';
|
| 119 |
let isDragging = false;
|
| 120 |
let startX, startY, startPanX, startPanY;
|
| 121 |
|
| 122 |
+
scene.addEventListener('wheel', (e) => {
|
| 123 |
+
e.preventDefault();
|
| 124 |
+
// Optional: center zoom around mouse position would be complex with pan adjustment,
|
| 125 |
+
// so we simply scale the entire scene from center for now.
|
| 126 |
+
const zoomDelta = e.deltaY > 0 ? 0.9 : 1.1; // zoom out or in
|
| 127 |
+
currentZoom = Math.min(Math.max(0.2, currentZoom * zoomDelta), 2.5);
|
| 128 |
+
if (canvas) canvas.style.setProperty('--zoom', currentZoom);
|
| 129 |
+
// Hide tooltip if active
|
| 130 |
+
if (tooltip && tooltip.classList.contains('visible')) tooltip.classList.remove('visible');
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
scene.addEventListener('mousedown', (e) => {
|
| 134 |
if (e.target === scrollBottomBtn || e.target.closest('#db-scroll-bottom-btn')) return;
|
| 135 |
isDragging = true;
|
|
|
|
| 137 |
startY = e.pageY;
|
| 138 |
startPanX = currentPanX;
|
| 139 |
startPanY = currentPanY;
|
| 140 |
+
if (canvas) canvas.style.transition = 'transform 0.1s ease-out'; // keep zoom transition, disable bg pan transition
|
| 141 |
if (panLayer) panLayer.style.transition = 'none';
|
| 142 |
});
|
| 143 |
|
| 144 |
const stopDrag = () => {
|
| 145 |
if (!isDragging) return;
|
| 146 |
isDragging = false;
|
| 147 |
+
if (canvas) canvas.style.transition = 'background-position 0.5s ease-out, transform 0.1s ease-out';
|
| 148 |
if (panLayer) panLayer.style.transition = 'transform 0.5s ease-out';
|
| 149 |
};
|
| 150 |
scene.addEventListener('mouseleave', stopDrag);
|
src/styles/detective-board.css
CHANGED
|
@@ -60,20 +60,21 @@
|
|
| 60 |
top: -50vh; left: -50vw;
|
| 61 |
width: 200vw; height: 200vh; /* large enough to cover screen when rotated */
|
| 62 |
transform-origin: center center;
|
| 63 |
-
transform: scale(0.65) rotateX(60deg) rotateZ(-45deg);
|
| 64 |
transform-style: preserve-3d;
|
| 65 |
background-image:
|
| 66 |
linear-gradient(rgba(0, 229, 255, 0.05) 1px, transparent 1px),
|
| 67 |
linear-gradient(90deg, rgba(0, 229, 255, 0.05) 1px, transparent 1px);
|
| 68 |
background-size: 60px 60px;
|
| 69 |
background-position: var(--pan-x, 0px) var(--pan-y, 0px);
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
.db-pan-layer {
|
| 73 |
position: absolute;
|
| 74 |
top: 50%; left: 50%;
|
| 75 |
width: 0; height: 0;
|
| 76 |
-
transform:
|
| 77 |
transform-style: preserve-3d;
|
| 78 |
}
|
| 79 |
|
|
|
|
| 60 |
top: -50vh; left: -50vw;
|
| 61 |
width: 200vw; height: 200vh; /* large enough to cover screen when rotated */
|
| 62 |
transform-origin: center center;
|
| 63 |
+
transform: scale(var(--zoom, 0.65)) rotateX(60deg) rotateZ(-45deg);
|
| 64 |
transform-style: preserve-3d;
|
| 65 |
background-image:
|
| 66 |
linear-gradient(rgba(0, 229, 255, 0.05) 1px, transparent 1px),
|
| 67 |
linear-gradient(90deg, rgba(0, 229, 255, 0.05) 1px, transparent 1px);
|
| 68 |
background-size: 60px 60px;
|
| 69 |
background-position: var(--pan-x, 0px) var(--pan-y, 0px);
|
| 70 |
+
transition: transform 0.1s ease-out; /* For smooth zooming */
|
| 71 |
}
|
| 72 |
|
| 73 |
.db-pan-layer {
|
| 74 |
position: absolute;
|
| 75 |
top: 50%; left: 50%;
|
| 76 |
width: 0; height: 0;
|
| 77 |
+
transform: translate3d(var(--pan-x, 0px), var(--pan-y, 0px), 1px);
|
| 78 |
transform-style: preserve-3d;
|
| 79 |
}
|
| 80 |
|