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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(corner-stack): step the corner stack aside on phones instead of stranding its chips mid-page
nirholasa7e66c175f03
diff --git a/public/corner-stack.js b/public/corner-stack.jsindex 87b37fd7f..c4876e30f 100644--- a/public/corner-stack.js+++ b/public/corner-stack.js@@ -26,11 +26,19 @@* many pixels of corner height", and the stack lifts itself clear of it. Keys* are independent and the tallest wins, so two reservations never fight.*+ * Lifting is the right answer on a wide viewport and the wrong one on a phone:+ * the stack goes full-width below 640px, so a 220px companion pushed a couple+ * of small chips into the middle of the screen, on top of the page's content+ * (seen on /create). When a reservation also declares a WIDTH and the narrow+ * layout leaves a usable column beside it, the stack steps sideways instead+ * and stays pinned to the bottom, where a helper widget belongs.+ ** API (window.twsCornerStack):* mount(el, { priority }) — move `el` into the stack (sets priority if given)* unmount(el) — remove `el` from the stack* ensure() — create/return the container element- * reserve(key, px) — keep `px` of corner height clear for `key`+ * reserve(key, px) — keep `px` of corner height clear for `key`;+ * pass { height, width } to declare both* release(key) — drop that reservation* reserved() — current reserved height in px*/@@ -54,14 +62,15 @@'--z-overlay-modal:2147483600;','}','#' + STACK_ID + '{',- 'position:fixed;right:18px;bottom:calc(18px + var(--tws-corner-reserve,0px));',+ 'position:fixed;right:calc(18px + var(--tws-corner-reserve-w,0px));',+ 'bottom:calc(18px + var(--tws-corner-reserve,0px));','z-index:var(--z-corner-stack,2147482500);','display:flex;flex-direction:column;align-items:flex-end;','gap:12px;max-width:min(380px,calc(100vw - 24px));','max-height:calc(100dvh - 36px - var(--tws-corner-reserve,0px));overflow:visible;',/* Clicks fall through the gaps; members re-enable pointer events. */'pointer-events:none;',- 'transition:bottom .35s cubic-bezier(.22,1,.36,1);',+ 'transition:bottom .35s cubic-bezier(.22,1,.36,1),right .35s cubic-bezier(.22,1,.36,1);','}','@media (prefers-reduced-motion:reduce){#' + STACK_ID + '{transition:none;}}','#' + STACK_ID + ':empty{display:none;}',@@ -74,7 +83,7 @@'@media (max-width:640px){','#' +STACK_ID +- '{right:12px;bottom:calc(12px + var(--tws-corner-reserve,0px));left:12px;align-items:stretch;gap:10px;max-width:none;}',+ '{right:calc(12px + var(--tws-corner-reserve-w,0px));bottom:calc(12px + var(--tws-corner-reserve,0px));left:12px;align-items:stretch;gap:10px;max-width:none;}','}'].join('');@@ -137,24 +146,52 @@does — order independence is the whole point of this module. */var reservations = Object.create(null);+ /* Narrow layout only: below this viewport width the stack stretches+ edge-to-edge, so lifting it over a corner widget parks it mid-screen. */+ var SIDE_BY_SIDE_MAX_VW = 640;+ /* A column narrower than this is not worth stepping aside for: the chips+ would wrap into taller blocks than the lift they replaced. */+ var SIDE_BY_SIDE_MIN_COL = 160;+ var NARROW_GUTTERS = 24; /* the 12px inset on each side of the narrow rule */+function applyReserve() {- var max = 0;+ var maxH = 0;+ var maxW = 0;for (var key in reservations) {- if (reservations[key] > max) max = reservations[key];+ var r = reservations[key];+ if (r.height > maxH) maxH = r.height;+ if (r.width > maxW) maxW = r.width;}+ var vw = typeof window !== 'undefined' ? window.innerWidth || 0 : 0;+ var beside =+ maxW > 0 &&+ vw > 0 &&+ vw <= SIDE_BY_SIDE_MAX_VW &&+ vw - NARROW_GUTTERS - maxW >= SIDE_BY_SIDE_MIN_COL;+ var lift = beside ? 0 : maxH;+ var inset = beside ? maxW : 0;var root = document.documentElement;- if (max > 0) root.style.setProperty('--tws-corner-reserve', max + 'px');+ if (lift > 0) root.style.setProperty('--tws-corner-reserve', lift + 'px');else root.style.removeProperty('--tws-corner-reserve');- return max;+ if (inset > 0) root.style.setProperty('--tws-corner-reserve-w', inset + 'px');+ else root.style.removeProperty('--tws-corner-reserve-w');+ return maxH;}+ /* px: a height in pixels, or { height, width } for a widget that can also be+ stepped around horizontally. */function reserve(key, px) {if (!key) return reservedHeight();- var n = Number(px);+ var spec = px && typeof px === 'object' ? px : { height: px };+ var h = Number(spec.height);+ var w = Number(spec.width);/* Guard against a mid-transition measurement of 0 (the companion mountsat opacity 0 and animates in) collapsing the stack back onto it. */- if (!Number.isFinite(n) || n <= 0) return release(key);- reservations[key] = Math.round(n);+ if (!Number.isFinite(h) || h <= 0) return release(key);+ reservations[key] = {+ height: Math.round(h),+ width: Number.isFinite(w) && w > 0 ? Math.round(w) : 0+ };return applyReserve();}@@ -186,6 +223,13 @@if (document.body) adoptOrphans();else document.addEventListener('DOMContentLoaded', adoptOrphans);+ /* Lift-vs-step-aside is a function of viewport width, so re-decide whenever+ that changes (rotation, a resized window, a phone's URL bar collapsing). */+ if (typeof window.addEventListener === 'function') {+ window.addEventListener('resize', applyReserve);+ window.addEventListener('orientationchange', applyReserve);+ }+/* Announce ourselves so a widget that mounted first can (re)claim itsreservation. Orphan adoption already covers stack MEMBERS; this coversnon-members like the Walk Companion, whose module is loaded separatelydiff --git a/tests/corner-stack.test.js b/tests/corner-stack.test.jsindex 44c61627f..c808fb666 100644--- a/tests/corner-stack.test.js+++ b/tests/corner-stack.test.js@@ -45,6 +45,17 @@ function reserveVar(win) {return win.document.documentElement.style.getPropertyValue('--tws-corner-reserve');}+/** The custom property the stack's `right` calc() reads. */+function reserveWidthVar(win) {+ return win.document.documentElement.style.getPropertyValue('--tws-corner-reserve-w');+}++/** JSDOM reports a fixed 1024x768 viewport unless it is told otherwise. */+function setViewport(win, width) {+ Object.defineProperty(win, 'innerWidth', { value: width, configurable: true });+ win.dispatchEvent(new win.Event('resize'));+}+describe('corner stack — membership', () => {let win;beforeEach(() => {@@ -132,6 +143,53 @@ describe('corner stack — reservations', () => {expect(win.twsCornerStack.reserved()).toBe(0);});+ it('accepts a width alongside the height without changing what it returns', () => {+ expect(win.twsCornerStack.reserve('walk-companion', { height: 296, width: 160 })).toBe(296);+ });++ it('steps aside instead of lifting when a phone leaves room beside the widget', () => {+ // The failure this prevents: on a 390px viewport the stack is full-width,+ // so a 218px lift parked its chips halfway up the page, on top of the+ // content. Beside the companion they stay pinned to the bottom.+ setViewport(win, 390);+ win.twsCornerStack.reserve('walk-companion', { height: 218, width: 160 });+ expect(reserveVar(win)).toBe('');+ expect(reserveWidthVar(win)).toBe('160px');+ });++ it('falls back to lifting when the leftover column would be unusable', () => {+ setViewport(win, 390);+ win.twsCornerStack.reserve('walk-companion', { height: 218, width: 300 });+ expect(reserveVar(win)).toBe('218px');+ expect(reserveWidthVar(win)).toBe('');+ });++ it('keeps lifting on a wide viewport, where the corner has room above it', () => {+ setViewport(win, 1440);+ win.twsCornerStack.reserve('walk-companion', { height: 296, width: 160 });+ expect(reserveVar(win)).toBe('296px');+ expect(reserveWidthVar(win)).toBe('');+ });++ it('re-decides when the viewport changes under a live reservation', () => {+ setViewport(win, 1440);+ win.twsCornerStack.reserve('walk-companion', { height: 296, width: 160 });+ setViewport(win, 390);+ expect(reserveVar(win)).toBe('');+ expect(reserveWidthVar(win)).toBe('160px');+ setViewport(win, 1440);+ expect(reserveVar(win)).toBe('296px');+ expect(reserveWidthVar(win)).toBe('');+ });++ it('drops the horizontal inset when the reservation is released', () => {+ setViewport(win, 390);+ win.twsCornerStack.reserve('walk-companion', { height: 218, width: 160 });+ win.twsCornerStack.release('walk-companion');+ expect(reserveWidthVar(win)).toBe('');+ expect(reserveVar(win)).toBe('');+ });+it('announces itself so a widget that booted first can claim the corner', () => {// The companion module is injected separately by public/nav.js and can win// the load race. Without this event it would find no stack and silently@@ -161,6 +219,11 @@ describe('corner stack — stylesheet contract', () => {expect(SOURCE).toContain('max-height:calc(100dvh - 36px - var(--tws-corner-reserve,0px))');});+ it('offsets both rules horizontally too, so stepping aside works at any width', () => {+ const rights = SOURCE.match(/right:calc\([^)]*var\(--tws-corner-reserve-w[^)]*\)[^)]*\)/g) || [];+ expect(rights.length).toBe(2);+ });+it('honours prefers-reduced-motion for the lift', () => {expect(SOURCE).toContain('@media (prefers-reduced-motion:reduce)');});diff --git a/walk-sdk/src/companion.js b/walk-sdk/src/companion.jsindex 1993e8b15..ee44dc3e2 100644--- a/walk-sdk/src/companion.js+++ b/walk-sdk/src/companion.js@@ -145,7 +145,16 @@ class WalkCompanion {const bottom = parseFloat(cs.bottom) || 0;const height = parseFloat(cs.height) || 0;if (height <= 0) return;- stack.reserve(CORNER_RESERVE_KEY, bottom + height);+ // Width as well as height: on a phone the stack goes full-width, and a+ // lift tall enough to clear the companion would strand its chips in the+ // middle of the page. With the width declared, the stack can step aside+ // and stay at the bottom instead.+ const right = parseFloat(cs.right) || 0;+ const width = parseFloat(cs.width) || 0;+ stack.reserve(CORNER_RESERVE_KEY, {+ height: bottom + height,+ width: width > 0 ? right + width : 0,+ });}async mount() {