Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(spaces): a live tile shows its checkbox and power, and the selected ring isn't cut off (CUA-2477) (#6060)
ddupontc402291b1fb2
diff --git a/apps/cua-spaces-web/src/__tests__/space-tile-controls.test.tsx b/apps/cua-spaces-web/src/__tests__/space-tile-controls.test.tsxnew file mode 100644index 0000000000..50edcc5ade--- /dev/null+++ b/apps/cua-spaces-web/src/__tests__/space-tile-controls.test.tsx@@ -0,0 +1,119 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++// Every tile on the Spaces grid has the same controls: the checkbox (on+// hover, and always while something is picked), power and "⋯". A control+// you may not use stays, disabled, saying why. The controls over the picture+// are cut out of a live tile's native video (macOS draws the live desktop+// over the page), so a running tile with live video shows them too. The+// selected ring sits outside the picture, in room its grid cell keeps, so+// nothing clips it.++import { cleanup, fireEvent, waitFor } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++import { wasmBuilt } from "@/bridge/__tests__/testCore";+import { TILE_CELL } from "@/components/spaces/space-tile";+import { resetVideoSlotLoader } from "@/components/video/use-video-slot";+import type { StreamSurfaceMessage } from "@/lib/stream-surface";+import { resetVideoSlots } from "@/lib/video-slots";+import { mountApp, stubBrowserApis } from "./app-harness";++stubBrowserApis();++const HOST = { failsCreates: false, listsGhost: false };++/** One of each kind of tile in the demo. */+const KINDS = {+ localRunning: "local:design-review",+ remoteRunning: "relay:mac-mini/qa-windows",+ localStopped: "local:agent-sandbox",+ remoteSuspended: "relay:mac-mini/release-checks",+ sharedEditor: "relay:space-sam-qa-shared",+ sharedViewer: "relay:space-priya-checkout",+} as const;++type Win = typeof window & { webkit?: unknown };+let posted: StreamSurfaceMessage[] = [];++beforeEach(() => {+ // The macOS host's native video handler: running tiles register live video slots.+ posted = [];+ (window as Win).webkit = { messageHandlers: { cuaVideo: { postMessage: (m: StreamSurfaceMessage) => void posted.push(m) } } };+ resetVideoSlots();+ resetVideoSlotLoader();+});++afterEach(() => {+ cleanup();+ delete (window as Win).webkit;+ resetVideoSlots();+ resetVideoSlotLoader();+ vi.restoreAllMocks();+});++const tileOf = (id: string) =>+ waitFor(() => {+ const link = document.querySelector<HTMLElement>(`[data-space-id="${id}"]`);+ if (!link) throw new Error(`no tile ${id}`);+ return link.parentElement!;+ });++describe.skipIf(!wasmBuilt)("a Space tile's controls", () => {+ it("every kind of tile has its checkbox, power and ⋯, over the picture as video overlays", async () => {+ await mountApp("/spaces", HOST);+ // The running tiles register live video with the host.+ await waitFor(() => expect(posted.some((m) => m.type === "surfaces" && m.update.some((u) => u.spaceId === KINDS.localRunning))).toBe(true));+ for (const [kind, id] of Object.entries(KINDS)) {+ const tile = await tileOf(id);+ expect(tile.hasAttribute("data-video-hole-scope"), kind).toBe(true);+ const box = tile.querySelector<HTMLElement>(`[data-select="${id}"]`);+ expect(box, `${kind}: checkbox`).not.toBeNull();+ expect(box!.hasAttribute("data-video-hole"), `${kind}: checkbox cut out of video`).toBe(true);+ await waitFor(() => expect(tile.querySelector(`[data-space-more="${id}"]`), `${kind}: ⋯`).not.toBeNull());+ const power = tile.querySelector<HTMLElement>("[data-tile-power]");+ expect(power, `${kind}: power`).not.toBeNull();+ expect(power!.hasAttribute("data-video-hole"), `${kind}: power cut out of video`).toBe(true);+ }+ // The live tile's picture is the video slot.+ const live = await tileOf(KINDS.localRunning);+ expect(live.querySelector("[data-tile-picture]")?.hasAttribute("data-stream-state")).toBe(true);+ });++ it("a Space shared with you to watch shows power disabled, saying why, and turns nothing on", async () => {+ await mountApp("/spaces", HOST);+ const tile = await tileOf(KINDS.sharedViewer);+ const power = tile.querySelector<HTMLElement>("[data-tile-power]")!;+ expect(power.getAttribute("aria-disabled")).toBe("true");+ expect(power.title).toMatch(/can view this Space but not turn it on or off/);+ fireEvent.click(power);+ expect(tile.querySelector("[data-space-id]")?.getAttribute("data-state")).toBe("stopped");+ // One you may use is enabled.+ const editor = (await tileOf(KINDS.sharedEditor)).querySelector<HTMLElement>("[data-tile-power]")!;+ expect(editor.hasAttribute("aria-disabled")).toBe(false);+ });++ it("the selected ring is drawn outside the picture, and nothing around it clips it", async () => {+ await mountApp("/spaces", HOST);+ const tile = await tileOf(KINDS.localRunning);+ fireEvent.click(tile.querySelector<HTMLElement>(`[data-select="${KINDS.localRunning}"]`)!);+ await waitFor(() => expect(tile.querySelector("[data-space-id]")?.hasAttribute("data-selected")).toBe(true));+ const picture = tile.querySelector<HTMLElement>("[data-tile-picture]")!;+ const classes = picture.className.split(/\s+/);+ expect(classes).toContain("ring-2");+ expect(classes).toContain("ring-brand");+ expect(classes).toContain("ring-offset-2");+ // Inside the picture a live tile's native video would cover it.+ expect(classes).not.toContain("ring-inset");+ // Every ancestor that clips what it paints (overflow, content-visibility,+ // paint containment) keeps at least the ring's 4 px of room around it.+ const clips = /^(overflow(-[xy])?-(hidden|clip|auto|scroll)|\[content-visibility:auto\]|\[contain:.*paint.*\]|contain-paint)$/;+ const grid = tile.closest("ul")!;+ for (let a = tile.parentElement; a && a !== grid; a = a.parentElement) {+ const tokens = a.className.toString().split(/\s+/);+ if (!tokens.some((t) => clips.test(t))) continue;+ expect(tokens, `${a.tagName} clips the ring`).toEqual(expect.arrayContaining(["p-1", "-m-1"]));+ }+ expect(tile.closest("li")!.className).toBe(TILE_CELL);+ });+});diff --git a/apps/cua-spaces-web/src/components/spaces/selection.tsx b/apps/cua-spaces-web/src/components/spaces/selection.tsxindex e403d46577..52cc750393 100644--- a/apps/cua-spaces-web/src/components/spaces/selection.tsx+++ b/apps/cua-spaces-web/src/components/spaces/selection.tsx@@ -23,6 +23,14 @@ export function selectable(item: SpaceItem): boolean {return item.mine ? item.access.canDelete && canDelete(item.space) : item.access.canLeave;}+/** Why it can't be ticked (the checkbox still shows, dimmed, saying this); null when it can. */+export function unselectableReason(item: SpaceItem): string | null {+ if (selectable(item)) return null;+ if (item.state === "creating") return "It can be selected once it's created";+ if (item.state === "deleting") return "It's being deleted";+ return item.mine ? "This Space can't be deleted here" : "You can't leave this Space";+}+/** Stopped and yours to delete: what Select stopped picks. */export const stoppedDeletable = (item: SpaceItem) => item.state === "stopped" && item.mine && selectable(item);@@ -112,6 +120,7 @@ export function useSelection(shown: readonly SpaceItem[], paused: boolean): Seleexport function SelectBox({ item, selection, onPicture = false, className }: { item: SpaceItem; selection: Selection; onPicture?: boolean; className?: string }) {const on = selection.has(item.space.id);const can = selectable(item);+ const why = can || on ? null : unselectableReason(item);return (<buttontype="button"@@ -119,7 +128,11 @@ export function SelectBox({ item, selection, onPicture = false, className }: { iaria-checked={on}aria-label={`Select ${item.space.name}`}aria-disabled={!can || undefined}+ aria-description={why ?? undefined}+ title={why ?? undefined}data-select={item.space.id}+ // Over a tile's picture: cut out of a live tile's native video while it shows (`lib/video-slots.ts`).+ data-video-hole={onPicture ? "" : undefined}onClick={(e) => {e.preventDefault();e.stopPropagation();diff --git a/apps/cua-spaces-web/src/components/spaces/space-menu.tsx b/apps/cua-spaces-web/src/components/spaces/space-menu.tsxindex 604b979771..91593bcb8a 100644--- a/apps/cua-spaces-web/src/components/spaces/space-menu.tsx+++ b/apps/cua-spaces-web/src/components/spaces/space-menu.tsx@@ -94,20 +94,45 @@ function Items({ items, Item, Separator }: { items: ReturnType<typeof useSpaceMe));}-/** The "⋯" button, shown on hover (and while its menu is open). */+const MORE_BUTTON =+ "flex size-7 shrink-0 cursor-default items-center justify-center rounded-lg text-muted-foreground opacity-0 outline-none group-hover/row:opacity-100 group-hover/tile:opacity-100 group-focus-within/tile:opacity-100 hover:bg-tile hover:text-foreground focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/60 data-popup-open:bg-tile data-popup-open:text-foreground data-popup-open:opacity-100";++/**+ * The "⋯" button, shown on hover, while focus is in the tile and while its+ * menu is open. Without items (the app core still loading, or none here)+ * it still shows, disabled, saying why, so every tile has the same controls.+ */export function SpaceMoreMenu({ item, actions, className }: { item: SpaceItem; actions: MenuActions; className?: string }) {const items = useSpaceMenu(item, actions);- if (!items.length) return null;+ const { core } = useBridge();+ if (!items.length) {+ const why = core.status === "loading" ? "Still loading" : "This Space's actions aren't available here";+ return (+ <button+ type="button"+ aria-label={`More for ${item.space.name}`}+ aria-disabled+ aria-description={why}+ title={why}+ data-space-more={item.space.id}+ data-disabled=""+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ }}+ className={cn(MORE_BUTTON, "text-muted-foreground/50 hover:bg-transparent hover:text-muted-foreground/50", className)}+ >+ <MoreHorizontalIcon className="size-4" />+ </button>+ );+ }return (<MenuPrimitive.Root><MenuPrimitive.Triggeraria-label={`More for ${item.space.name}`}data-space-more={item.space.id}onClick={(e) => e.stopPropagation()}- className={cn(- "flex size-7 shrink-0 cursor-default items-center justify-center rounded-lg text-muted-foreground opacity-0 outline-none group-hover/row:opacity-100 group-hover/tile:opacity-100 hover:bg-tile hover:text-foreground focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/60 data-popup-open:bg-tile data-popup-open:text-foreground data-popup-open:opacity-100",- className,- )}+ className={cn(MORE_BUTTON, className)}><MoreHorizontalIcon className="size-4" /></MenuPrimitive.Trigger>diff --git a/apps/cua-spaces-web/src/components/spaces/space-tile.tsx b/apps/cua-spaces-web/src/components/spaces/space-tile.tsxindex d98845ebe3..a7e347add2 100644--- a/apps/cua-spaces-web/src/components/spaces/space-tile.tsx+++ b/apps/cua-spaces-web/src/components/spaces/space-tile.tsx@@ -7,20 +7,25 @@* state is a quiet dot and word at the end of the name row, as the card had* before the redesign; power shows on hover. Files dropped on a running tile go into it,* and a real window dragged over it is offered to it (macOS).+ *+ * The controls over the picture (checkbox, power, badges) are+ * `data-video-hole`: where the host draws the live desktop natively over+ * the page (macOS), it cuts them out of the video while they show, so a+ * live tile has them as any other does (`lib/video-slots.ts`).*/import { Link } from "@tanstack/react-router";import { ArrowDownCircleIcon, KeyRoundIcon, LoaderCircleIcon, PowerIcon } from "lucide-react";import { useEffect, useRef, useState, type DragEvent, type MouseEvent, type ReactNode } from "react";-import { useBridge, useSpaceFiles, useSpaces, useSpaceThumbnail, useTips, useWindowDropTarget, type Space } from "@/bridge";+import { useBridge, useSpaceFiles, useSpaces, useSpaceThumbnail, useTips, useWindowDropTarget, type Space, type SpaceAccess } from "@/bridge";import { OsIcon } from "@/components/os-icon";import { StateLabel } from "@/components/state-dot";import { toast, toastError } from "@/components/ui/toast";import { useTileVideo } from "@/components/video/tile-video";import { useInView } from "@/hooks/use-in-view";import { creatingLine } from "@/lib/host-labels";-import { createError, createProgress, powerButton, powerError } from "@/lib/spaces";+import { createError, createProgress, powerButton, powerError, type PowerButton } from "@/lib/spaces";import { cn } from "@/lib/utils";import { PeopleStack, SpaceMark } from "./avatars";@@ -42,15 +47,29 @@ export interface SpaceTileProps {onClick?: (e: MouseEvent) => void;}+/**+ * A tile's grid cell (`<li>`). Off-screen cells skip layout and paint+ * (`content-visibility`), which also clips what they paint to their box: the+ * cell keeps 4 px of room around the tile (padding, taken back by a negative+ * margin so the grid doesn't move) for the selected and focus rings drawn+ * just outside the picture.+ */+export const TILE_CELL = "-m-1 p-1 [content-visibility:auto] [contain-intrinsic-size:auto_240px]";+export function SpaceTile({ item, accessKey, selected = false, busy = false, topLeft, more, onClick }: SpaceTileProps) {const { space, state, access } = item;const drop = useTileDrop(space, state === "running");// A real window dragged over this tile (the host hit-tests the tiles' boxes and says which; macOS only).const windowOver = useWindowDropTarget() === space.id;const creating = state === "creating";+ const { core } = useBridge();+ // Shown wherever the Space has power at all; disabled, with why, where you may not use it.+ const power = powerButton(core, space);+ const hasPower = power !== null;return (<divclassName={cn("group/tile relative", (busy || state === "deleting") && "opacity-60")}+ data-video-hole-scope=""data-tile-drop={drop.over ?? undefined}data-drop-status={drop.status?.kind}data-window-drop={space.id}@@ -108,7 +127,7 @@ export function SpaceTile({ item, accessKey, selected = false, busy = false, top{drop.over ? <DropOverlay space={space} accepts={drop.over === "accept"} /> : null}{/* A drop on the tile still going in: the core's "Sending …" line. */}{drop.status?.kind === "working" && !drop.over ? (- <div className="pointer-events-none absolute top-2 left-2 z-20 flex max-w-[60%] items-center gap-1.5 rounded-[4px] bg-black/70 px-1.5 py-px text-[11px] font-medium text-white">+ <div data-video-hole="" className="pointer-events-none absolute top-2 left-2 z-20 flex max-w-[60%] items-center gap-1.5 rounded-[4px] bg-black/70 px-1.5 py-px text-[11px] font-medium text-white"><LoaderCircleIcon className="size-3 shrink-0 animate-spin" aria-hidden /><span className="truncate">{drop.status.text}</span></div>@@ -122,16 +141,21 @@ export function SpaceTile({ item, accessKey, selected = false, busy = false, topto="/keyvault"search={{ view: "access", focus: accessKey ?? undefined }}data-signed-in={space.id}+ data-video-hole=""title="A Keyvault sign-in is live in this Space. Open Access."className={cn("ml-auto inline-flex h-6 items-center gap-1 rounded-md bg-black/55 px-1.5 text-[11px] font-medium text-white/90 outline-none backdrop-blur-sm transition-[margin] hover:text-white focus-visible:ring-2 focus-visible:ring-ring/60",- access.canPower && "group-hover/tile:mr-7 group-focus-within/tile:mr-7",+ hasPower && "group-hover/tile:mr-7 group-focus-within/tile:mr-7",)}><KeyRoundIcon className="size-3" /> Signed in</Link>) : null}- {access.canPower ? <div className="absolute right-0 top-0"><TilePower space={space} /></div> : null}+ {hasPower ? (+ <div className="absolute right-0 top-0">+ <TilePower space={space} button={power} denied={access.canPower ? null : cantPower(access)} />+ </div>+ ) : null}</div>{more ? <div className="absolute top-[calc(100%-2.75rem)] right-0 z-10">{more}</div> : null}</div>@@ -151,11 +175,13 @@ function Picture({ item, ring, busy }: { item: SpaceItem; ring: boolean; busy: breturn (<divref={ref}+ data-tile-picture=""data-stream-state={video?.phase}className={cn(- "relative flex aspect-[16/10] items-center justify-center overflow-hidden rounded-lg bg-tile transition-shadow",+ "relative flex aspect-[16/10] items-center justify-center overflow-hidden rounded-lg bg-tile ring-offset-2 ring-offset-background transition-shadow",+ // Both rings sit just outside the picture (a live tile's video covers the inside), in the room `TILE_CELL` keeps."group-focus-visible/link:ring-2 group-focus-visible/link:ring-ring/60",- ring && "ring-2 ring-brand ring-offset-2 ring-offset-background",+ ring && "ring-2 ring-brand",)}>{thumbnail ? (@@ -171,7 +197,7 @@ function Picture({ item, ring, busy }: { item: SpaceItem; ring: boolean; busy: b</div>) : null}{busy || state === "deleting" ? (- <div data-tile-busy="" className="absolute inset-0 flex items-center justify-center bg-background/40">+ <div data-tile-busy="" data-video-hole="" className="absolute inset-0 z-10 flex items-center justify-center bg-background/40"><LoaderCircleIcon className="size-5 animate-spin text-muted-foreground" aria-hidden /></div>) : null}@@ -226,8 +252,9 @@ function DropOverlay({ space, accepts }: { space: Space; accepts: boolean }) {return (<divaria-hidden+ data-video-hole=""className={cn(- "pointer-events-none absolute inset-x-0 top-0 flex aspect-[16/10] flex-col items-center justify-center gap-1.5 rounded-lg text-center text-[13px] backdrop-blur-[2px]",+ "pointer-events-none absolute inset-x-0 top-0 z-20 flex aspect-[16/10] flex-col items-center justify-center gap-1.5 rounded-lg text-center text-[13px] backdrop-blur-[2px]",accepts ? "bg-brand/20 text-foreground ring-2 ring-brand" : "bg-background/75 text-muted-foreground",)}>@@ -237,18 +264,22 @@ function DropOverlay({ space, accepts }: { space: Space; accepts: boolean }) {);}+/** Why you can't turn a Space on or off that has power (shared with you to watch). */+function cantPower(access: SpaceAccess): string {+ return access.role === "viewer" ? "You can view this Space but not turn it on or off" : "You can't turn this Space on or off";+}+/*** The core's power button, while the pointer is on the tile or focus is in* it, and always while it runs (the SwiftUI sidebar row's, which shows on- * hover, on the selected row and while busy).+ * hover, on the selected row and while busy). `denied`: you may not use it+ * (a Space shared with you to watch); it shows disabled, saying why.*/-function TilePower({ space }: { space: Space }) {- const { core } = useBridge();+function TilePower({ space, button, denied }: { space: Space; button: PowerButton; denied: string | null }) {const { startSpace, stopSpace } = useSpaces();const tips = useTips();- const button = powerButton(core, space);- if (!button) return null;const press = () => {+ if (denied) return;const [act, word] = button.turnOn ? [startSpace, "start"] : [stopSpace, "stop"];void tips.send({ type: "powered" });void act(space.id).catch(toastError(`Couldn't ${word} ${space.name}`));@@ -258,13 +289,18 @@ function TilePower({ space }: { space: Space }) {type="button"data-tile-power={button.turnOn ? "on" : "off"}data-busy={button.busy || undefined}+ data-denied={denied ? "" : undefined}+ data-video-hole=""disabled={button.busy}- title={button.help}+ aria-disabled={denied ? true : undefined}+ title={denied ?? button.help}aria-label={`${button.help} ${space.name}`}+ aria-description={denied ?? undefined}onClick={press}className={cn("inline-flex size-6 items-center justify-center rounded-md bg-black/55 text-white/90 outline-none backdrop-blur-sm hover:bg-black/70 hover:text-white focus-visible:ring-2 focus-visible:ring-ring/60 disabled:cursor-default",!button.busy && "opacity-0 group-focus-within/tile:opacity-100 group-hover/tile:opacity-100",+ denied && "cursor-default text-white/45 hover:bg-black/55 hover:text-white/45",)}>{button.busy ? <LoaderCircleIcon className="size-3 animate-spin" aria-hidden /> : <PowerIcon className="size-3" aria-hidden />}diff --git a/apps/cua-spaces-web/src/lib/stream-surface.test.tsx b/apps/cua-spaces-web/src/lib/stream-surface.test.tsxindex b4ecdda631..9a91129c69 100644--- a/apps/cua-spaces-web/src/lib/stream-surface.test.tsx+++ b/apps/cua-spaces-web/src/lib/stream-surface.test.tsx@@ -168,6 +168,71 @@ describe("stream surface helpers", () => {expect(videoHoles(slot, { x: 0, y: 0, width: 400, height: 300 })).toEqual([{ x: 100, y: 260, width: 200, height: 30 }]);});+ it("cuts a tile's own checkbox and power out of its video while they show, never another tile's", () => {+ const tile = (name: string) => {+ const scope = document.createElement("div");+ scope.setAttribute("data-video-hole-scope", "");+ const picture = document.createElement("div");+ const check = document.createElement("button");+ check.setAttribute("data-video-hole", "");+ const power = document.createElement("button");+ power.setAttribute("data-video-hole", "");+ power.style.opacity = "0";+ scope.append(picture, check, power);+ scope.dataset.name = name;+ document.body.append(scope);+ return { picture, check, power };+ };+ const a = tile("a");+ const b = tile("b");+ const clip = { x: 0, y: 0, width: 320, height: 200 };+ box(a.picture, clip);+ box(a.check, { x: 8, y: 8, width: 16, height: 16 });+ box(a.power, { x: 288, y: 8, width: 24, height: 24 });+ // The next tile's controls overlap this clip here only to prove scope is what decides.+ box(b.check, { x: 40, y: 8, width: 16, height: 16 });+ // Power is hidden until hover (opacity 0): only the checkbox is cut.+ expect(videoHoles(a.picture, clip)).toEqual([{ x: 8, y: 8, width: 16, height: 16 }]);+ // Hover shows it.+ a.power.style.opacity = "1";+ expect(videoHoles(a.picture, clip)).toEqual([+ { x: 8, y: 8, width: 16, height: 16 },+ { x: 288, y: 8, width: 24, height: 24 },+ ]);+ // Hidden by an ancestor in the tile: no hole.+ a.check.parentElement!.style.opacity = "0";+ expect(videoHoles(a.picture, clip)).toEqual([]);+ // A tile's control is not something on top of its video.+ a.check.parentElement!.style.opacity = "1";+ document.elementsFromPoint = (x, y) => (x < 30 && y < 30 ? [a.check, a.picture] : [a.picture]);+ expect(isOccluded(a.picture, clip, document, 8)).toBe(false);+ });++ it("measures holes again on hover and focus, which change no DOM", () => {+ const sent: StreamSurfaceMessage[] = [];+ const frames: FrameRequestCallback[] = [];+ vi.spyOn(window, "requestAnimationFrame").mockImplementation((cb) => (frames.push(cb), frames.length));+ const reporter = new VideoSlotReporter({ postMessage: (m) => void sent.push(m) });+ const scope = document.createElement("div");+ scope.setAttribute("data-video-hole-scope", "");+ const picture = document.createElement("div");+ const power = document.createElement("button");+ power.setAttribute("data-video-hole", "");+ power.style.opacity = "0";+ scope.append(picture, power);+ document.body.append(scope);+ box(picture, { x: 0, y: 0, width: 320, height: 200 });+ box(power, { x: 288, y: 8, width: 24, height: 24 });+ const stop = reporter.register(picture, { spaceId: "a", tier: "tile", interactive: false, radius: 8 }, () => {});+ const last = () => (sent.at(-1) as Extract<StreamSurfaceMessage, { type: "surfaces" }>).update[0]!;+ expect(last().holes).toEqual([]);+ power.style.opacity = "1";+ window.dispatchEvent(new Event("pointerover"));+ frames.splice(0).forEach((f) => f(0));+ expect(last().holes).toEqual([{ x: 288, y: 8, width: 24, height: 24 }]);+ stop();+ });+it("calls a slot occluded when something else is on top of it (a backdrop)", () => {const slot = document.createElement("div");const inner = document.createElement("span");diff --git a/apps/cua-spaces-web/src/lib/stream-surface.ts b/apps/cua-spaces-web/src/lib/stream-surface.tsindex a8d7feb218..a9e7970f1f 100644--- a/apps/cua-spaces-web/src/lib/stream-surface.ts+++ b/apps/cua-spaces-web/src/lib/stream-surface.ts@@ -57,7 +57,7 @@ export interface SurfaceState {radius: number;/** A dialog (or anything else on top, but floating UI) covers part of the slot: the host hides the video. */occluded: boolean;- /** Floating page UI over the slot (a menu, a popover, a tooltip, a toast), in the same coordinates,+ /** Floating page UI over the slot (a menu, a popover, a tooltip, a toast, a tile's checkbox and power button while they show), in the same coordinates,* inside `clip`: the host cuts the video out there and keeps the rest playing. */holes?: SurfaceRect[];/** On screen at all: the page is visible, the slot is laid out and not clipped away. */diff --git a/apps/cua-spaces-web/src/lib/video-slots.ts b/apps/cua-spaces-web/src/lib/video-slots.tsindex bfa24bdb94..967172cdb2 100644--- a/apps/cua-spaces-web/src/lib/video-slots.ts+++ b/apps/cua-spaces-web/src/lib/video-slots.ts@@ -68,6 +68,11 @@ export const HOLE_SELECTOR = ["[data-toast]",].join(",");+/** Where a slot's own controls live (a Space tile): a `[data-video-hole]`+ * inside one counts only for the slot in the same scope, and only while it+ * shows (a hover control sits at `opacity: 0` until then). */+export const HOLE_SCOPE_SELECTOR = "[data-video-hole-scope]";+/** Transparent layers that only catch outside clicks (Base UI's* `InternalBackdrop` under an open menu or popover): they paint nothing, so* they never cover video. */@@ -128,6 +133,9 @@ interface Slot extends SlotOptions {listener: (status: SlotStatus) => void;}+/** Events after which a tile's hover controls may have shown or hidden. */+const POINTER_FOCUS = ["pointerover", "pointerout", "focusin", "focusout"] as const;+/** Frames to keep measuring after something changed (follows transitions). */const SETTLE_FRAMES = 20;const POLL_MS = 400;@@ -279,10 +287,13 @@ export class VideoSlotReporter {childList: true,subtree: true,attributes: true,- attributeFilter: ["data-open", "data-closed", "data-state", "open", "hidden", "style"],+ // `class`: a tile's controls (holes) show and hide by class (selection mode).+ attributeFilter: ["data-open", "data-closed", "data-state", "open", "hidden", "style", "class"],});}w.addEventListener("scroll", this.schedule, { capture: true, passive: true });+ // Hover and focus show a tile's controls by CSS alone (no DOM change): measure their holes.+ for (const type of POINTER_FOCUS) w.addEventListener(type, this.schedule, { passive: true });w.addEventListener("resize", this.schedule);w.addEventListener("cua:event", this.onHostEvent);w.document.addEventListener("visibilitychange", this.schedule);@@ -299,6 +310,7 @@ export class VideoSlotReporter {this.mutations?.disconnect();this.mutations = null;w.removeEventListener("scroll", this.schedule, { capture: true });+ for (const type of POINTER_FOCUS) w.removeEventListener(type, this.schedule);w.removeEventListener("resize", this.schedule);w.removeEventListener("cua:event", this.onHostEvent);w.document.removeEventListener("visibilitychange", this.schedule);@@ -372,13 +384,21 @@ function topmostPainted(doc: Document, x: number, y: number): Element | null {/*** The floating UI over `clip` (menus, popovers, tooltips, toasts, the- * viewer's key bar), each clipped to it: the host draws no video there.+ * viewer's key bar, a tile's checkbox and power button while they show),+ * each clipped to it: the host draws no video there.*/export function videoHoles(el: Element, clip: SurfaceRect, doc: Document = document): SurfaceRect[] {const holes: SurfaceRect[] = [];+ const win = doc.defaultView;for (const o of doc.querySelectorAll(HOLE_SELECTOR)) {// Floating UI inside the slot counts only when it asks (`data-video-hole`).if (o.contains(el) || (el.contains(o) && !o.hasAttribute("data-video-hole"))) continue;+ if (o.hasAttribute("data-video-hole")) {+ // Another tile's control, or one hidden until hover: no hole.+ const scope = o.closest(HOLE_SCOPE_SELECTOR);+ if (scope && !scope.contains(el)) continue;+ if (win && !showsNow(o, scope, win)) continue;+ }// One hole for a nested pair (a menu inside a marked popup).if (o.parentElement?.closest(HOLE_SELECTOR)) continue;const r = o.getBoundingClientRect();@@ -389,6 +409,17 @@ export function videoHoles(el: Element, clip: SurfaceRect, doc: Document = documreturn holes;}+/** Laid out, not hidden and not fully transparent (itself or an ancestor up to `scope`). */+function showsNow(o: Element, scope: Element | null, win: Window): boolean {+ if (win.getComputedStyle(o).visibility === "hidden") return false;+ const stop = scope?.parentElement ?? null;+ for (let a: Element | null = o; a && a !== stop; a = a.parentElement) {+ const style = win.getComputedStyle(a);+ if (style.display === "none" || Number.parseFloat(style.opacity) === 0) return false;+ }+ return true;+}+let shared: VideoSlotReporter | null | undefined;/** The page's reporter, or null when the host draws no native video. */diff --git a/apps/cua-spaces-web/src/routes/spaces/index.tsx b/apps/cua-spaces-web/src/routes/spaces/index.tsxindex f6ab8acfde..2fb546799e 100644--- a/apps/cua-spaces-web/src/routes/spaces/index.tsx+++ b/apps/cua-spaces-web/src/routes/spaces/index.tsx@@ -15,7 +15,7 @@ import { BulkConfirmDialog, useBulkRemove } from "@/components/spaces/bulk-removimport { SpaceList } from "@/components/spaces/space-list";import { SpaceContextMenu, SpaceMoreMenu, type MenuActions } from "@/components/spaces/space-menu";import { SelectAllBox, SelectBox, SelectionBar, stoppedDeletable, useSelection } from "@/components/spaces/selection";-import { SpaceTile } from "@/components/spaces/space-tile";+import { SpaceTile, TILE_CELL } from "@/components/spaces/space-tile";import { CreatingElsewhereTile } from "@/components/spaces/creating-elsewhere-tile";import { SpacesToolbar } from "@/components/spaces/spaces-toolbar";import { PageTip, useTipsLoaded } from "@/components/tips";@@ -247,8 +247,8 @@ function SpacesPage() {<ul className="grid grid-cols-[repeat(auto-fill,minmax(232px,1fr))] gap-x-5 gap-y-7">{elsewhereTiles}{shown.map((it) => (- // Off-screen tiles skip layout and paint until they scroll in.- <li key={it.space.id} className="[content-visibility:auto] [contain-intrinsic-size:auto_232px]">+ // Off-screen tiles skip layout and paint until they scroll in (with room for the selected ring).+ <li key={it.space.id} className={TILE_CELL}><SpaceContextMenu item={it} actions={actions}><SpaceTileitem={it}