Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

8.6 KB
Raw Blame
<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<title data-i18n="widget.meta_title">three.ws widget</title>
		<meta
			name="viewport"
			content="width=device-width, initial-scale=1, viewport-fit=cover"
		/>
		<meta name="robots" content="noindex" />
		<meta name="theme-color" content="#000000" />
		<link rel="icon" href="/favicon.ico" sizes="any" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
		<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
		<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
		<link rel="manifest" href="/manifest.webmanifest" />
		<link rel="stylesheet" href="/style.css" />
		<link rel="stylesheet" href="/fonts/fonts.css" />
		<style>
			/* Slim widget shell — no nav, no footer, no auth chrome.
			   Held invisible until the viewer fires its first frame so the
			   parent iframe never sees a chrome flash. */
			html,
			body {
				margin: 0;
				padding: 0;
				height: 100%;
				width: 100%;
				background: #000;
				color: #eee;
				font-family: 'Inter', system-ui, -apple-system, sans-serif;
				overflow: hidden;
			}
			body {
				visibility: hidden;
			}
			body.widget-ready {
				visibility: visible;
			}
			.wrap {
				position: absolute;
				inset: 0;
				width: 100%;
				height: 100%;
			}
			.viewer-container {
				position: absolute;
				inset: 0;
				width: 100%;
				height: 100%;
			}
			/* Poster image shown until the model's first frame. Hides on the
			   `widget-ready` body flip with a soft cross-fade. */
			.widget-poster {
				position: fixed;
				inset: 0;
				background-color: #000;
				background-position: center;
				background-repeat: no-repeat;
				background-size: contain;
				z-index: 1;
				pointer-events: none;
				transition: opacity var(--duration-slow) var(--ease-standard);
			}
			body.widget-ready .widget-poster {
				opacity: 0;
			}
			/* Reveal-on-interaction: tap-to-load overlay shown when the widget
			   was embedded with reveal=interaction. Stays visible — and
			   interactive — until the user clicks. WebGL doesn't init at all
			   before that click, so a page with 12 widgets only pays the cost
			   of the ones the user opens. */
			.widget-reveal-gate {
				position: fixed;
				inset: 0;
				display: flex;
				align-items: center;
				justify-content: center;
				background: rgba(0, 0, 0, 0.55);
				z-index: 3;
				cursor: pointer;
				transition: opacity var(--duration-base) var(--ease-standard);
			}
			.widget-reveal-btn {
				width: 78px;
				height: 78px;
				border-radius: 50%;
				background: rgba(255, 255, 255, 0.9);
				color: #111;
				display: flex;
				align-items: center;
				justify-content: center;
				box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
				pointer-events: none;
			}
			.widget-reveal-btn svg {
				width: 32px;
				height: 32px;
				transform: translateX(2px);
			}
			.widget-reveal-gate[data-dismissing] {
				opacity: 0;
				pointer-events: none;
			}
			/* Spinner — same look as the rest of the app, centred. Hidden
			   until the reveal gate is dismissed (in interaction mode) so
			   visitors see "tap to play," not "loading." */
			.spinner {
				position: fixed;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				width: 32px;
				height: 32px;
				border: 2px solid rgba(255, 255, 255, 0.12);
				border-top-color: rgba(255, 255, 255, 0.72);
				border-radius: 50%;
				animation: widget-spin 0.9s linear infinite;
				z-index: 2;
				pointer-events: none;
				display: none;
			}
			body.widget-loading .spinner {
				display: block;
			}
			body.widget-ready .spinner {
				display: none;
			}
			@keyframes widget-spin {
				to {
					transform: translate(-50%, -50%) rotate(360deg);
				}
			}
			/* Force-hide anything the app accidentally injects (e.g. Footer())
			   despite the guard — defence-in-depth in case a future code path
			   re-introduces injection without checking the flag. */
			body > header,
			body > footer,
			body > .auth-gate,
			body > .agent-onboarding,
			body > .agent-presence-sidebar,
			body > .dropzone {
				display: none !important;
			}
		</style>
		<script>
			// Signal to /src/app.js that this is the slim widget shell BEFORE the
			// module parses — module-level chrome injection and main-mode-only
			// setup short-circuit when this flag is set.
			window.__WIDGET_SHELL = true;
		</script>
		<script type="module">
			// Static import so Vite rewrites it to the hashed bundle; dynamic script injection at runtime was invisible to the build graph.
			window.__loadWidgetApp = () => import('/src/app.js');
		</script>
		<script>
			(function () {
				var qs = new URLSearchParams(location.search);
				var hash = location.hash || '';
				var hashParams = new URLSearchParams(hash.replace(/^#/, ''));
				function param(name) {
					return hashParams.get(name) || qs.get(name);
				}

				// Poster: ?poster=... or #poster=... — encoded URL of a static
				// preview shown until first frame (or used as the reveal-gate bg).
				var poster = param('poster');
				if (poster) {
					document.addEventListener('DOMContentLoaded', function () {
						var el = document.createElement('div');
						el.className = 'widget-poster';
						el.style.backgroundImage = 'url(' + JSON.stringify(poster).slice(1, -1) + ')';
						document.body.appendChild(el);
					});
				}

				// Reveal mode: 'auto' (default — boots on load) or 'interaction'
				// (deferred — boots only after the visitor clicks the play button).
				// On a gallery page with N embeds, interaction mode means WebGL
				// only spins up for the one(s) the visitor actually opens.
				var reveal = param('reveal') === 'interaction' ? 'interaction' : 'auto';

				function bootApp() {
					if (window.__WIDGET_BOOTED) return;
					window.__WIDGET_BOOTED = true;
					document.body.classList.add('widget-loading');
					window.__loadWidgetApp();
					// Notify the parent that the visitor revealed this widget —
					// lets a host page track engagement without our analytics.
					try {
						window.parent.postMessage(
							{ jsonrpc: '2.0', method: 'widget.revealed', params: { mode: reveal } },
							'*',
						);
					} catch (_) {
						/* not in an iframe — ignore */
					}
				}

				function setupRevealGate() {
					var gate = document.createElement('button');
					gate.type = 'button';
					gate.className = 'widget-reveal-gate';
					gate.setAttribute('aria-label', 'Play widget');
					gate.innerHTML =
						'<span class="widget-reveal-btn" aria-hidden="true">' +
						'<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>' +
						'</span>';
					gate.addEventListener('click', function () {
						gate.setAttribute('data-dismissing', '');
						bootApp();
						setTimeout(function () {
							if (gate.parentNode) gate.parentNode.removeChild(gate);
						}, 280);
					});
					document.body.appendChild(gate);
					// In interaction mode the body has nothing to hide — make it
					// visible so the play button is interactable.
					document.body.classList.add('widget-ready');
				}

				if (reveal === 'interaction') {
					document.addEventListener('DOMContentLoaded', setupRevealGate);
				} else {
					// Auto mode: boot now, no gate.
					document.addEventListener('DOMContentLoaded', bootApp);
				}

				// Reveal the body on the viewer's first successful frame. App.js
				// fires a 'three-ws:first-frame' event after LOAD_END(success).
				// 6s fallback guards against a hung load so visitors don't stare
				// at a black box. In interaction mode the body was already shown
				// for the gate; this re-firing is harmless (class already set).
				var revealed = false;
				var revealBody = function () {
					if (revealed) return;
					revealed = true;
					document.body.classList.remove('widget-loading');
					document.body.classList.add('widget-ready');
				};
				window.addEventListener('three-ws:first-frame', revealBody, { once: true });
				// Only arm the 6s fallback after the boot actually starts, so the
				// idle interaction-mode poster doesn't reveal itself.
				var armFallback = function () {
					setTimeout(revealBody, 6000);
				};
				if (reveal === 'interaction') {
					window.addEventListener('three-ws:boot-started', armFallback, { once: true });
				} else {
					armFallback();
				}
			})();
		</script>
	</head>
	<body data-viewer-mode="embed">
		<main class="wrap">
			<div class="viewer-container" id="viewer-container"></div>
		</main>
		<div class="spinner" aria-label="Loading"></div>
		<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
	<script type="module" src="/i18n.js"></script>
</body>
</html>