Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 71 additions & 60 deletions examples/map-server/mcp-app.html
Original file line number Diff line number Diff line change
@@ -1,72 +1,83 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CesiumJS Globe</title>
<!-- CesiumJS is loaded dynamically from CDN in mcp-app.ts because static
<script src=""> tags don't work in srcdoc iframes -->
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: transparent;
}
#cesiumContainer {
width: 100%;
height: 100%;
}
#fullscreen-btn {
position: absolute;
top: 10px;
right: 10px;
width: 36px;
height: 36px;
background: rgba(0, 0, 0, 0.7);
border: none;
border-radius: 6px;
cursor: pointer;
z-index: 1000;
display: none;
align-items: center;
justify-content: center;
transition: background 0.2s;
}
#fullscreen-btn:hover {
background: rgba(0, 0, 0, 0.85);
}
#fullscreen-btn svg {
width: 20px;
height: 20px;
fill: white;
}
#loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 20px 30px;
border-radius: 8px;
font-size: 16px;
z-index: 1001;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: transparent;
}
#cesiumContainer {
width: 100%;
height: 100%;
touch-action: none;
}
#fullscreen-btn {
position: absolute;
top: 10px;
right: 10px;
width: 36px;
height: 36px;
background: rgba(0, 0, 0, 0.7);
border: none;
border-radius: 6px;
cursor: pointer;
z-index: 1000;
display: none;
align-items: center;
justify-content: center;
transition: background 0.2s;
}
#fullscreen-btn:hover {
background: rgba(0, 0, 0, 0.85);
}
#fullscreen-btn svg {
width: 20px;
height: 20px;
fill: white;
}
#loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 20px 30px;
border-radius: 8px;
font-size: 16px;
z-index: 1001;
}
</style>
</head>
<body>
</head>
<body>
<div id="cesiumContainer"></div>
<button id="fullscreen-btn" title="Toggle fullscreen">
<!-- Expand icon (shown when inline) -->
<svg id="expand-icon" viewBox="0 0 24 24"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>
<!-- Compress icon (shown when fullscreen) -->
<svg id="compress-icon" style="display:none" viewBox="0 0 24 24"><path d="M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"/></svg>
<!-- Expand icon (shown when inline) -->
<svg id="expand-icon" viewBox="0 0 24 24">
<path
d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"
/>
</svg>
<!-- Compress icon (shown when fullscreen) -->
<svg id="compress-icon" style="display: none" viewBox="0 0 24 24">
<path
d="M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"
/>
</svg>
</button>
<div id="loading">Loading globe...</div>
<script type="module" src="/src/mcp-app.ts"></script>
</body>
</body>
</html>
11 changes: 11 additions & 0 deletions examples/map-server/src/mcp-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ async function initCesium(): Promise<any> {
// CesiumJS sets image-rendering: pixelated by default which looks bad on scaled displays
// Setting to "auto" allows the browser to apply smooth interpolation
cesiumViewer.canvas.style.imageRendering = "auto";
// Prevent touch events from propagating to the parent scroll view.
// CesiumJS uses pointer events internally, which don't suppress native
// scroll gesture recognition on touch devices. Explicit non-passive touch
// listeners with preventDefault() are needed.
for (const eventName of ["touchstart", "touchmove"] as const) {
cesiumViewer.canvas.addEventListener(
eventName,
(e: TouchEvent) => e.preventDefault(),
{ passive: false },
);
}
// Note: DO NOT set resolutionScale = devicePixelRatio here!
// When useBrowserRecommendedResolution: false, Cesium already uses devicePixelRatio.
// Setting resolutionScale = devicePixelRatio would double the scaling (e.g., 2x2=4x on Retina)
Expand Down
8 changes: 6 additions & 2 deletions examples/shadertoy-server/src/mcp-app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
html, body {
html,
body {
margin: 0;
width: 100%;
height: 100%;
Expand All @@ -23,6 +24,7 @@ html, body {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}

#canvas.hidden {
Expand Down Expand Up @@ -68,7 +70,9 @@ html, body {
display: none; /* Hidden by default, shown when fullscreen available */
align-items: center;
justify-content: center;
transition: background 0.2s, opacity 0.2s;
transition:
background 0.2s,
opacity 0.2s;
opacity: 0; /* Initially invisible, shown on View hover */
z-index: 100;
}
Expand Down
16 changes: 15 additions & 1 deletion examples/threejs-server/src/threejs-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function LoadingShimmer({ height, code }: { height: number; code?: string }) {
display: "flex",
flexDirection: "column",
overflow: "hidden",
touchAction: "none",
background:
"linear-gradient(135deg, var(--color-background-secondary, light-dark(#f0f0f5, #2a2a3c)) 0%, var(--color-background-tertiary, light-dark(#e5e5ed, #1e1e2e)) 100%)",
}}
Expand Down Expand Up @@ -275,6 +276,14 @@ export default function ThreeJSApp({
useEffect(() => {
if (!code || !canvasRef.current || !containerRef.current) return;

// Prevent touch events from propagating to the parent scroll view.
// Three.js OrbitControls uses pointer events, which don't suppress native
// scroll gesture recognition on touch devices.
const canvas = canvasRef.current;
const preventDefault = (e: TouchEvent) => e.preventDefault();
canvas.addEventListener("touchstart", preventDefault, { passive: false });
canvas.addEventListener("touchmove", preventDefault, { passive: false });

// Cleanup previous animation
animControllerRef.current?.cleanup();
animControllerRef.current = createAnimationController();
Expand All @@ -289,7 +298,11 @@ export default function ThreeJSApp({
animControllerRef.current.visibilityAwareRAF,
).catch((e) => setError(e instanceof Error ? e.message : "Unknown error"));

return () => animControllerRef.current?.cleanup();
return () => {
canvas.removeEventListener("touchstart", preventDefault);
canvas.removeEventListener("touchmove", preventDefault);
animControllerRef.current?.cleanup();
};
}, [code, height]);

if (isStreaming || !code) {
Expand All @@ -314,6 +327,7 @@ export default function ThreeJSApp({
height,
borderRadius: "var(--border-radius-lg, 8px)",
display: "block",
touchAction: "none",
}}
/>
{error && <div className="error-overlay">Error: {error}</div>}
Expand Down
1 change: 1 addition & 0 deletions examples/wiki-explorer-server/src/mcp-app.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#graph {
width: 100%;
height: 100vh;
touch-action: none;
}

#popup {
Expand Down
12 changes: 12 additions & 0 deletions examples/wiki-explorer-server/src/mcp-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ const graph = new ForceGraph<NodeData, LinkData>(container)
})
.graphData(graphData);

// Prevent touch events from propagating to the parent scroll view.
// force-graph uses pointer events, which don't suppress native scroll gesture
// recognition on touch devices.
const graphCanvas = container.querySelector("canvas");
if (graphCanvas) {
for (const eventName of ["touchstart", "touchmove"] as const) {
graphCanvas.addEventListener(eventName, (e) => e.preventDefault(), {
passive: false,
});
}
}

// Handle window resize
function handleResize() {
const { width, height } = container.getBoundingClientRect();
Expand Down
Loading