feat(web): workbench Outliner matches the desktop Layout geometry

The desktop golden comes from Blender's own laid-out screen data
(tools/web/measure-outliner-desktop.py, blender 5.2.0 LTS, factory
Layout at 1920x1080): right column 339 px, Outliner area 339x189 under
a 26 px header, 20 px rows, 14 px per-level indent (0.7 * UI_UNIT_X).
The workbench derives the right width and the Outliner/timeline split
from those ratios so it reproduces the area at the reference size and
scales elsewhere.

The headed suite grows outliner-metrics-web with +-1 px assertions,
and the runner now materializes inline base64 attachments so the
checker can compare the measured boxes against the golden.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-30 04:21:08 +08:00
parent 721acdad4f
commit 5ce5625f2e
8 changed files with 416 additions and 24 deletions

View File

@@ -2712,6 +2712,7 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
};
return <div {...nodeProps} ref={attachRow} key={row.id} aria-label={row.label}
data-node-id={row.objectId ?? ''} data-active={row.active}
style={{paddingLeft: 4 + 14 * Math.min(row.depth, 32)}}
className={`tree-row child${row.selected ? ' selected' : ''}`}
draggable={Boolean(row.objectId) || Boolean(collectionRows.find(item => item.name === row.label && !item.sourceLibrary && !item.isMaster))}
onDragStart={event => {
@@ -2814,7 +2815,6 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
event.preventDefault(); onToggleExpand?.(row.id, event.altKey, nativeArea.id);
}
}}>
<span className="tree-depth" aria-hidden="true">{'\u00a0\u00a0'.repeat(row.depth)}</span>
{row.hasChildren ? <button type="button" className="tree-expand"
aria-label={`${row.expanded ? '折叠' : '展开'} ${row.label}`}
onClick={event => { event.stopPropagation(); onToggleExpand?.(row.id, event.altKey, nativeArea.id); }}>
@@ -2928,9 +2928,9 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
const node = row.objectId ? nodeById.get(row.objectId) : undefined;
if (!node) return null;
return <div {...nodeProps} ref={attachRow} key={row.id} aria-label={row.label} data-node-id={node.id} data-parent-id={node.parentId ?? ''} data-data-id={node.dataId ?? ''}
style={{paddingLeft: 4 + 14 * Math.min(row.depth, 32)}}
className={`tree-row child${row.selected ? ' selected' : ''}`}
onClick={(event) => { onSelect(node.id, event.ctrlKey || event.metaKey, event.shiftKey); }}>
<span className="tree-depth" aria-hidden="true">{'  '.repeat(Math.min(Math.max(row.depth - 1, 0), 32))}</span>
{row.hasChildren ? <button type="button" className="tree-expand" aria-label={`${row.expanded ? '折叠' : '展开'} ${row.label}`}
onClick={(event) => { event.stopPropagation(); setCollapsed((current) => { const next = new Set(current); if (next.has(node.id)) next.delete(node.id); else next.add(node.id); return next; }); }}>
{row.expanded ? '▾' : '▸'}</button> : <span>·</span>}

View File

@@ -89,13 +89,13 @@ button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-
.area-type-switch { position: absolute; top: 2px; right: 3px; z-index: 6; display: flex; align-items: center; gap: 2px; max-width: calc(100% - 6px); padding: 1px 3px; border-radius: 3px; background: #1d1d1dcc; color: #c9c9c9; font-size: 10px; opacity: 0; pointer-events: none; transition: opacity .12s; }
.area-frame:hover > .area-type-switch, .area-frame:focus-within > .area-type-switch { opacity: .9; pointer-events: auto; }
/* Areas with a visible header carry the switcher inside it instead. */
.editor-header > .area-type-switch { position: relative; z-index: 3; flex: 0 0 auto; min-width: 0; max-width: none; opacity: 1; pointer-events: auto; background: transparent; }
.editor-header > .area-type-switch { position: relative; z-index: 3; flex: 0 0 auto; min-width: 0; max-width: none; padding: 0 3px; opacity: 1; pointer-events: auto; background: transparent; }
.area-type-switch:hover, .area-type-switch:focus-within { opacity: 1; }
@media (hover: none) { .area-type-switch { opacity: .6; pointer-events: auto; } }
.area-type-switch select { min-width: 0; max-width: 160px; padding: 1px 2px; border: 1px solid #4a4a4a; border-radius: 2px; background: #2a2a2a; color: #ddd; font-size: 10px; }
.area-type-switch select { min-width: 0; max-width: 160px; height: 22px; padding: 0 2px; border: 1px solid #4a4a4a; border-radius: 2px; background: #2a2a2a; color: #ddd; font-size: 10px; }
.area-type-switch span { flex: none; }
.editor-header { position: relative; z-index: 2; display: flex; align-items: center; gap: 2px; flex: none; min-width: 0; min-height: 27px; padding: 0 4px; background: #292929; border-bottom: 1px solid #151515; box-shadow: inset 0 -1px #333; }
.editor-selector, .icon-button { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 24px; min-height: 24px; padding: 4px 6px; background: transparent; color: #e1e3e7; border-radius: 3px; }
.editor-header { position: relative; z-index: 2; display: flex; align-items: center; gap: 2px; flex: none; min-width: 0; min-height: 26px; padding: 0 4px; background: #292929; border-bottom: 1px solid #151515; box-shadow: inset 0 -1px #333; }
.editor-selector, .icon-button { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 24px; min-height: 24px; padding: 0 6px; background: transparent; color: #e1e3e7; border-radius: 3px; }
/* A narrow area must squeeze the label, not push the ⋮ switcher out of the header. */
.editor-selector > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-selector:hover, .icon-button:hover { background: #414141; }
@@ -160,12 +160,11 @@ button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-
.viewport-sidebar-tabs label { display: flex; align-items: center; gap: 4px; }
.viewport-sidebar-tabs label > input { flex: 1; min-width: 0; padding: 1px 3px; color: #ddd; background: #1d1d1d; border: 1px solid #3c3c3c; border-radius: 2px; }
.outliner-content { padding: 3px 2px; color: #d0d0d0; }
.tree-expand { width:16px;min-width:16px;height:22px;padding:0;background:transparent;color:inherit;border:0; }
.tree-depth { white-space:pre;flex-shrink:0; }
.tree-expand { width:16px;min-width:16px;height:20px;padding:0;background:transparent;color:inherit;border:0; }
.tree-node-name { min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.properties-content { position: relative; display: flex; flex-direction: column; min-height: 100%; padding: 4px 7px 12px 40px; color: #d0d0d0; background: #303030; }
.outliner-tools { display: flex; gap: 3px; margin: 0 2px 4px; }.outliner-tools input { min-width: 0; height: 23px; flex: 1; padding: 3px 7px; color: #e4e4e4; background: #181818; border: 1px solid #454545; border-radius: 3px; outline: none; }.outliner-tools button { width: 27px; background: #383838; border-radius: 2px; }
.tree-row { display: flex; align-items: center; gap: 5px; min-height: 24px; padding: 1px 4px; border-radius: 0; }.tree-row:hover { background: #353535; }.tree-row.child { padding-left: 26px; }.tree-row.selected { color: #fff; background: #4775a3; }.tree-icon { color: #d59b44; }.tree-icon.mesh { color: #6999c8; }.tree-action { width: 24px; min-width: 24px; height: 24px; margin-left: auto; padding: 1px 3px; color: #a6a6a6; background: transparent; border: 0; border-radius: 2px; }.tree-action:hover { color: #fff; background: #4a4a4a; }
.tree-row { display: flex; align-items: center; gap: 5px; min-height: 20px; padding: 0 4px; border-radius: 0; }.tree-row:hover { background: #353535; }.tree-row.selected { color: #fff; background: #4775a3; }.tree-icon { height:20px;min-width:16px;padding:0;border:0;background:transparent;color: #d59b44; }.tree-icon.mesh { color: #6999c8; }.tree-action { width: 20px; min-width: 20px; height: 20px; margin-left: auto; padding: 0 2px; color: #a6a6a6; background: transparent; border: 0; border-radius: 2px; }.tree-action:hover { color: #fff; background: #4a4a4a; }
.property-tabs { position: absolute; left: 0; top: 0; bottom: 0; display: flex; flex-direction: column; gap: 1px; width: 34px; overflow-y: auto; scrollbar-width: thin; margin: 0; padding: 4px 3px; background: #242424; border-right: 1px solid #151515; }.property-tab { display: grid; place-items: center; width: 27px; height: 27px; padding: 0; color: #aaa; background: transparent; border-radius: 2px; }.property-tab:hover { color: #fff; background: #404040; }.property-tab.active { color: #fff; background: #4775a3; }.property-tab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }.property-section { padding: 7px 3px 9px; border-bottom: 1px solid #454545; }.property-section h3 { margin: 0 0 7px; padding: 4px 6px; color: #eee; background: #383838; border-radius: 2px; font-size: 11px; font-weight: 600; }.property-section label { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; min-width: 0; min-height: 23px; color: #b5b5b5; }
/* A narrow properties column must not push its controls outside the panel. */
.property-section label > select, .property-section label > input, .property-section label > span { min-width: 0; max-width: 100%; }.property-transform-row { display: flex; align-items: center; gap: 3px; margin-bottom: 3px; }.property-transform-row > span { flex: 0 1 26px; min-width: 16px; overflow: hidden; color: #b5b5b5; text-overflow: ellipsis; white-space: nowrap; }.property-transform-row > input { flex: 1 1 0; min-width: 0; width: auto; padding: 2px 3px; color: #e0e2e6; background: #26282c; border: 1px solid #484c53; border-radius: 2px; font-variant-numeric: tabular-nums; }.property-transform-row > input:disabled { color: #7a7d82; background: #202124; }

View File

@@ -26,13 +26,28 @@ export interface WorkspaceLayoutState {
floating: Record<string, FloatingRect>;
}
export const DEFAULT_SPLITS: WorkspaceSplits = { rightWidth: 320, timelineHeight: 108, outlinerShare: 1 / 3 };
/** Mid-size windows start with the 290px right column the CSS used to force. */
function initialRightWidth(): number {
return typeof window !== "undefined" && window.innerWidth <= 1280 ? 290 : DEFAULT_SPLITS.rightWidth;
}
/* Desktop reference (blender 5.2.0 LTS, factory Layout screen, 1920x1080): the
* right column is 339 px, the Outliner 189 px tall below a 26 px header
* (tests/golden/OUTLINER-DESKTOP-METRICS/outliner-metrics.json). The workbench
* keeps that ratio so the area matches Blender's at any window size. */
export const DESKTOP_RIGHT_RATIO = 339 / 1920;
/* At 1920x1080 the workbench chrome takes 28 (topbar) + 65 (toolbar row, 30 +
* the 35 px quick-tools row) + 20 (status bar), leaving a 967 px grid; minus the
* 108 px timeline and two 1 px gaps that is 857 px of fr space. The desktop
* Outliner is 189 px of it, so 189 / 857 reproduces the area height. */
export const DESKTOP_OUTLINER_SHARE = 189 / 857;
const MIN_RIGHT = 240;
const MIN_TIMELINE = 48;
export const DEFAULT_SPLITS: WorkspaceSplits = { rightWidth: Math.round(1920 * DESKTOP_RIGHT_RATIO), timelineHeight: 108, outlinerShare: DESKTOP_OUTLINER_SHARE };
/** Mid-size windows start with the 290px right column the CSS used to force. */
function initialRightWidth(): number {
if (typeof window === "undefined") return DEFAULT_SPLITS.rightWidth;
if (window.innerWidth <= 1280) return 290;
return Math.max(MIN_RIGHT, Math.round(window.innerWidth * DESKTOP_RIGHT_RATIO));
}
function defaultSplits(): WorkspaceSplits {
return { ...DEFAULT_SPLITS, rightWidth: initialRightWidth() };
}
const MIN_FLOATING = { width: 240, height: 160 };
function readState(): WorkspaceLayoutState {
@@ -57,7 +72,7 @@ function readState(): WorkspaceLayoutState {
floating,
};
}
catch { return { splits: { ...DEFAULT_SPLITS }, floating: {} }; }
catch { return { splits: defaultSplits(), floating: {} }; }
}
export function resetWorkspaceLayout(): void {
@@ -87,7 +102,7 @@ export function WorkspaceLayoutProvider({ children }: { children: ReactNode }) {
}, [state]);
useEffect(() => {
const onReset = () => setState({ splits: { ...DEFAULT_SPLITS }, floating: {} });
const onReset = () => setState({ splits: defaultSplits(), floating: {} });
window.addEventListener(WORKSPACE_LAYOUT_RESET_EVENT, onReset);
return () => window.removeEventListener(WORKSPACE_LAYOUT_RESET_EVENT, onReset);
}, []);
@@ -104,7 +119,7 @@ export function WorkspaceLayoutProvider({ children }: { children: ReactNode }) {
return { ...current, floating };
}),
dockAll: () => setState((current) => ({ ...current, floating: {} })),
resetAll: () => setState({ splits: { ...DEFAULT_SPLITS }, floating: {} }),
resetAll: () => setState({ splits: defaultSplits(), floating: {} }),
}), [state]);
return <LayoutContext.Provider value={api}>{children}</LayoutContext.Provider>;
@@ -251,12 +266,12 @@ export function WorkspaceSplitters() {
role="separator" tabIndex={0} title={`${labels[bar.kind]}(双击复位)`} aria-label={labels[bar.kind]}
aria-orientation={bar.kind === "right" ? "vertical" : "horizontal"} data-splitter={bar.kind}
onPointerDown={begin(bar.kind)} onPointerMove={move} onPointerUp={end} onPointerCancel={end}
onDoubleClick={() => setSplits({ ...DEFAULT_SPLITS })}
onDoubleClick={() => setSplits(defaultSplits())}
onKeyDown={(event) => {
const step = event.shiftKey ? 48 : 16;
if (event.key === "ArrowLeft" || event.key === "ArrowUp") { event.preventDefault(); nudge(bar.kind, -step); }
else if (event.key === "ArrowRight" || event.key === "ArrowDown") { event.preventDefault(); nudge(bar.kind, step); }
else if (event.key === "Home") { event.preventDefault(); setSplits({ ...DEFAULT_SPLITS }); }
else if (event.key === "Home") { event.preventDefault(); setSplits(defaultSplits()); }
}} />
))}
</div>

View File

@@ -1,9 +1,13 @@
import { expect, test, type Page } from "@playwright/test";
import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const BASIC_SCENE = path.resolve(HERE, "../../../tests/files/web/basic_scene.blend");
/* Desktop geometry measured from Blender's own Layout screen
* (tools/web/measure-outliner-desktop.py, blender 5.2.0 LTS, factory startup). */
const DESKTOP_METRICS = path.resolve(HERE, "../../../tests/golden/OUTLINER-DESKTOP-METRICS/outliner-metrics.json");
/* Shared entry for the web workbench: open the fixture through the product
* input, wait for the engine to own the project, and expose the native tools
@@ -88,6 +92,46 @@ test.describe("Outliner headed baseline", () => {
await expect.poll(async () => page.locator(`.outliner-tree button[aria-label="隐藏 ${name}"]`).count(), { timeout: 15_000 }).toBe(1);
});
test("[outliner-metrics-web] the workbench Outliner matches the desktop Layout geometry", async ({ page }, testInfo) => {
test.setTimeout(150_000);
await openWorkbench(page);
await expect.poll(async () => page.getByRole("treeitem").count(), { timeout: 20_000 }).toBeGreaterThan(1);
const golden = (JSON.parse(readFileSync(DESKTOP_METRICS, "utf8")) as { outliner: { width: number; height: number; headerHeight: number; rowHeight: number; indentPerLevel: number } }).outliner;
const measured = await page.evaluate(() => {
const rect = (element: Element | null) => {
if (!element) return null;
const box = element.getBoundingClientRect();
return { x: box.x, y: box.y, width: box.width, height: box.height };
};
const area = document.querySelector(".outliner-area");
const header = area?.querySelector(":scope > .editor-header") ?? null;
const rows = Array.from(document.querySelectorAll<HTMLElement>(".outliner-tree .tree-row"));
const paddingLevels = [...new Set(rows.map((row) => Math.round(parseFloat(getComputedStyle(row).paddingLeft))))].sort((a, b) => a - b);
const steps = paddingLevels.slice(1).map((value, index) => value - paddingLevels[index]);
return {
viewport: { width: window.innerWidth, height: window.innerHeight },
outliner: rect(area),
header: rect(header),
rowHeights: rows.map((row) => row.getBoundingClientRect().height),
paddingLevels,
indentPerLevel: steps.length ? Math.min(...steps) : null,
};
});
await testInfo.attach("outliner-metrics-web", { body: JSON.stringify({ golden, measured }, null, 2), contentType: "application/json" });
expect(measured.viewport).toEqual({ width: 1920, height: 1080 });
expect(measured.outliner).not.toBeNull();
expect(measured.header).not.toBeNull();
/* The desktop Layout at 1920x1080: Outliner area 339x189, header 26,
* row 20, indent 14 (UI_TREEVIEW_INDENT = 0.7 * UI_UNIT_X). */
expect(Math.abs(measured.outliner!.width - golden.width)).toBeLessThanOrEqual(1);
expect(Math.abs(measured.outliner!.height - golden.height)).toBeLessThanOrEqual(1);
expect(Math.abs(measured.header!.height - golden.headerHeight)).toBeLessThanOrEqual(1);
expect(measured.rowHeights.length).toBeGreaterThan(0);
for (const height of measured.rowHeights) expect(Math.abs(height - golden.rowHeight)).toBeLessThanOrEqual(1);
expect(measured.indentPerLevel).not.toBeNull();
expect(Math.abs(measured.indentPerLevel! - golden.indentPerLevel)).toBeLessThanOrEqual(1);
});
test("[outliner-mirror-baseline-web] the desktop mirror hands the Outliner to the DOM workspace", async ({ page }) => {
test.setTimeout(120_000);
await page.goto("/");