A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor(editor): shared UI primitives + tilemap dedupe + editable dimension fields
esengine3cf9f0b05351
diff --git a/desktop/src/components/Button.tsx b/desktop/src/components/Button.tsxnew file mode 100644index 000000000..14af3e459--- /dev/null+++ b/desktop/src/components/Button.tsx@@ -0,0 +1,41 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Button.tsx+ * @brief The shared text button (with an optional leading icon) — one recipe+ * behind dialog actions, toolbar commands, and empty-state CTAs.+ * Variants: soft (default), primary (accent fill), danger (error fill).+ * Styled by the `.btn-soft` recipe in theme/app.css.+ */+import type { ReactNode, MouseEvent } from 'react';++export function Button({+ children,+ onClick,+ variant = 'soft',+ disabled,+ title,+ type = 'button',+ className,+}: {+ children: ReactNode;+ onClick?: (e: MouseEvent) => void;+ variant?: 'soft' | 'primary' | 'danger';+ disabled?: boolean;+ title?: string;+ type?: 'button' | 'submit';+ className?: string;+}) {+ const mod = variant === 'primary' ? ' is-primary' : variant === 'danger' ? ' is-danger' : '';+ return (+ <button+ type={type}+ className={`btn-soft${mod}${className ? ` ${className}` : ''}`}+ disabled={disabled}+ title={title}+ onClick={onClick}+ >+ {children}+ </button>+ );+}diff --git a/desktop/src/components/IconButton.tsx b/desktop/src/components/IconButton.tsxnew file mode 100644index 000000000..4f2858a6b--- /dev/null+++ b/desktop/src/components/IconButton.tsx@@ -0,0 +1,58 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file IconButton.tsx+ * @brief The shared square icon button — one recipe behind every panel-chrome+ * glyph button (toolbars, panel headers, dialog close, filter toggles).+ * Replaces the dozen hand-rolled `.pbtn`/`.cb-ico`/`.filt-btn`/… classes+ * that all re-implemented the same "square, centered glyph, mute→text on+ * hover" recipe. Styled by the `.icon-btn` block in theme/controls.css.+ */+import type { ReactNode, MouseEvent, KeyboardEvent } from 'react';++export function IconButton({+ children,+ title,+ onClick,+ active,+ disabled,+ size = 'md',+ variant = 'ghost',+ className,+ tabIndex,+ onKeyDown,+ ariaLabel,+}: {+ children: ReactNode;+ /** Tooltip; also the accessible name (these buttons are icon-only). */+ title?: string;+ onClick?: (e: MouseEvent) => void;+ /** Accent-colored "current mode / on" state (aria-pressed). */+ active?: boolean;+ disabled?: boolean;+ /** 22 / 24 / 28px square — matches the three sizes found across the panels. */+ size?: 'sm' | 'md' | 'lg';+ /** ghost = bare glyph (panel headers/toolbars); outline = bordered chip. */+ variant?: 'ghost' | 'outline';+ className?: string;+ tabIndex?: number;+ onKeyDown?: (e: KeyboardEvent) => void;+ /** Override the accessible name when it should differ from `title`. */+ ariaLabel?: string;+}) {+ return (+ <button+ type="button"+ className={`icon-btn icon-btn--${size}${variant === 'outline' ? ' icon-btn--outline' : ''}${active ? ' on' : ''}${className ? ` ${className}` : ''}`}+ title={title}+ aria-label={ariaLabel ?? title}+ aria-pressed={active}+ disabled={disabled}+ tabIndex={tabIndex}+ onClick={onClick}+ onKeyDown={onKeyDown}+ >+ {children}+ </button>+ );+}diff --git a/desktop/src/components/Modal.tsx b/desktop/src/components/Modal.tsxindex f108bda64..50a85a1c8 100644--- a/desktop/src/components/Modal.tsx+++ b/desktop/src/components/Modal.tsx@@ -8,6 +8,7 @@import { useEffect, useRef, type ReactNode } from 'react';import { createPortal } from 'react-dom';import { X } from 'lucide-react';+import { IconButton } from './IconButton';import { useDialogFocus } from './dialogFocus';export function Modal({@@ -48,9 +49,9 @@ export function Modal({><div className="modal__head"><span className="modal__title">{title}</span>- <button type="button" className="modal__x" title="Close" onClick={onClose}>+ <IconButton size="lg" title="Close" onClick={onClose}><X size={15} strokeWidth={2} />- </button>+ </IconButton></div><div className="modal__body">{children}</div>{footer && <div className="modal__foot">{footer}</div>}diff --git a/desktop/src/components/Popover.tsx b/desktop/src/components/Popover.tsxindex 409b32c5c..96bbeded0 100644--- a/desktop/src/components/Popover.tsx+++ b/desktop/src/components/Popover.tsx@@ -18,13 +18,17 @@ export function Popover({width,onClose,children,+ className,}: {/** The trigger's bounding rect, captured at open time. */anchor: DOMRect;- /** Panel width; defaults to the anchor's width (so a dropdown lines up). */- width?: number;+ /** Panel width: a number pins it, `'auto'` sizes to content, omitted = the+ * anchor's width (so a field dropdown lines up under its trigger). */+ width?: number | 'auto';onClose: () => void;children: ReactNode;+ /** Extra class on the `.popover` shell — e.g. a glass variant for overlays. */+ className?: string;}) {const ref = useRef<HTMLDivElement>(null);const [pos, setPos] = useState<{ left: number; top: number }>({ left: anchor.left, top: anchor.bottom + 2 });@@ -76,8 +80,8 @@ export function Popover({return createPortal(<divref={ref}- className="popover"- style={{ left: pos.left, top: pos.top, width: width ?? anchor.width }}+ className={`popover${className ? ` ${className}` : ''}`}+ style={{ left: pos.left, top: pos.top, width: width === 'auto' ? undefined : (width ?? anchor.width) }}onMouseDown={(e) => e.stopPropagation()}>{children}diff --git a/desktop/src/components/SettingsDialog.tsx b/desktop/src/components/SettingsDialog.tsxindex d15ba49a1..18b256e1b 100644--- a/desktop/src/components/SettingsDialog.tsx+++ b/desktop/src/components/SettingsDialog.tsx@@ -17,6 +17,7 @@ import { useSettings } from '@/store/settingsStore';import { settingsRegistry } from '@/settings/registry';import { eventToChord, formatKeybinding } from '@/commands/keybinding';import { useDialogFocus } from '@/components/dialogFocus';+import { IconButton } from '@/components/IconButton';import { SearchField } from '@/components/SearchField';import { Segmented } from '@/components/Segmented';import { Select } from '@/components/Select';@@ -385,9 +386,9 @@ export function SettingsDialog() {</span><span className="set-head-sp" /><SearchField className="set-search" iconSize={12} autoFocus placeholder="Search settings…" value={query} onChange={setQuery} />- <button type="button" className="set-x" title="Close (Esc)" onClick={close}>+ <IconButton size="lg" title="Close (Esc)" onClick={close}><X size={14} strokeWidth={2} />- </button>+ </IconButton></div><div className="set-body">diff --git a/desktop/src/engine/schema.ts b/desktop/src/engine/schema.tsindex ad4154f3b..51412d944 100644--- a/desktop/src/engine/schema.ts+++ b/desktop/src/engine/schema.ts@@ -167,6 +167,8 @@ export function inferField(key: string, v: unknown, isColor: boolean): Inspectorreturn { key, label, type: 'angle', value: quatToAngleZ(o as { z: number; w: number }) };if ('z' in o && 'x' in o && 'y' in o) return { key, label, type: 'vec3', value: [o.x, o.y, o.z] };if ('x' in o && 'y' in o) return { key, label, type: 'vec2', value: [o.x, o.y] };+ // CSS-length shape ({ value, unit }) — the UINode Dimension (width/height/inset/margin).+ if ('value' in o && 'unit' in o) return { key, label, type: 'dimension', value: { value: o.value, unit: o.unit } };}return null; // unknown shape — not editable here}diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsxindex 0c11e87f3..e245a268e 100644--- a/desktop/src/panels/ContentBrowser.tsx+++ b/desktop/src/panels/ContentBrowser.tsx@@ -3,6 +3,7 @@import { Fragment, useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';import { ChevronRight, LayoutGrid, List, Import, FolderOpen, FolderPlus, ArrowLeft, ArrowRight, ArrowUp, ArrowDownUp, Play, EyeOff } from 'lucide-react';import { AssetIcon, assetTint } from '@/components/icons';+import { IconButton } from '@/components/IconButton';import { ConfirmDialog } from '@/components/ConfirmDialog';import { SearchField } from '@/components/SearchField';import { ContextMenu, type MenuItem } from '@/components/Menu';@@ -940,14 +941,14 @@ export function ContentBrowser() {))}</div><SearchField className="cb-search" placeholder="Search (type:texture …)" value={query} onChange={setQuery} />- <button- type="button"- className="cb-ghost"+ <IconButton+ size="lg"+ variant="outline"title={`Sort by ${sort === 'name' ? 'name' : 'type'} — click to sort by ${sort === 'name' ? 'type' : 'name'}`}onClick={() => setSort((s) => (s === 'name' ? 'type' : 'name'))}><ArrowDownUp size={14} strokeWidth={2} />- </button>+ </IconButton><Segmentedvalue={view}onChange={setView}@@ -957,9 +958,9 @@ export function ContentBrowser() {{ value: 'list', icon: <List size={13} strokeWidth={1.9} />, title: 'List view' },]}/>- <button type="button" className="cb-ghost" title="New Folder" onClick={() => void newFolder()}>+ <IconButton size="lg" variant="outline" title="New Folder" onClick={() => void newFolder()}><FolderPlus size={13} strokeWidth={1.9} />- </button>+ </IconButton><button type="button" className="cb-add" title="Import assets" onClick={() => void importAssets()}><Import size={13} strokeWidth={1.9} /> Import</button>diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsxindex 58574a3e4..9d150b451 100644--- a/desktop/src/panels/Details.tsx+++ b/desktop/src/panels/Details.tsx@@ -43,6 +43,7 @@ import { SceneModel } from '@/engine/SceneModel';import { InspectorClipboard } from '@/engine/inspectorClipboard';import { SceneCommands, toModelValue } from '@/engine/SceneCommands';import { PlayInspect } from '@/engine/PlayInspect';+import { DimensionUnit } from 'esengine';import type { SceneData, InputMapAsset, ActionType, Binding } from 'esengine';import { modelAddableComponentEntries, subscribeSchemas, getSchemaRevision, prettyLabel, hexToRgba, dynamicEnumOptions } from '@/engine/schema';import * as imap from '@/project/inputMapDoc';@@ -407,6 +408,48 @@ export function BoolControl({);}+// A CSS-length: a number well + a px/%/auto unit picker. `auto` drops the number+// (Yoga ignores its value), so the well collapses to a static "auto" label.+export function DimControl({+ value,+ mixed,+ onBegin,+ onEnd,+ onChange,+}: ControlGesture & { value: DimensionValue; mixed?: boolean; onChange: (v: DimensionValue) => void }) {+ const setUnit = (unit: number) => {+ onBegin?.();+ onChange({ value: value.value, unit });+ onEnd?.();+ };+ return (+ <div className="dim">+ {value.unit === DimensionUnit.Auto ? (+ <span className="field dim-auto">auto</span>+ ) : (+ <NumField+ value={value.value}+ mixed={mixed}+ onBegin={onBegin}+ onEnd={onEnd}+ onCommit={(n) => onChange({ value: n, unit: value.unit })}+ />+ )}+ <Select+ variant="field"+ value={String(value.unit)}+ ariaLabel="unit"+ options={[+ { value: String(DimensionUnit.Px), label: 'px' },+ { value: String(DimensionUnit.Percent), label: '%' },+ { value: String(DimensionUnit.Auto), label: 'auto' },+ ]}+ onChange={(v) => setUnit(Number(v))}+ />+ </div>+ );+}+function StringControl({value,mixed,@@ -883,6 +926,9 @@ function FieldRow({ entities, comp, field, write }: { entities: EntityId[]; compcase 'vec3':control = <VecControl value={field.value as number[]} mixed={mixed} onBegin={begin} onEnd={end} onChange={apply} />;break;+ case 'dimension':+ control = <DimControl value={field.value as DimensionValue} mixed={mixed} onBegin={begin} onEnd={end} onChange={apply} />;+ break;case 'bool':control = <BoolControl value={field.value as boolean} mixed={mixed} onBegin={begin} onEnd={end} onChange={apply} />;break;diff --git a/desktop/src/panels/Sequencer.tsx b/desktop/src/panels/Sequencer.tsxindex 02a5f615f..5d95322df 100644--- a/desktop/src/panels/Sequencer.tsx+++ b/desktop/src/panels/Sequencer.tsx@@ -27,6 +27,7 @@ import { useSelection } from '@/store/selectionStore';import { SceneModel } from '@/engine/SceneModel';import { ContextMenu, type MenuItem } from '@/components/Menu';import { DirtyDot } from '@/components/DirtyDot';+import { IconButton } from '@/components/IconButton';import { NumField } from '@/components/NumField';import { SequencerCurve } from '@/panels/SequencerCurve';import {@@ -366,8 +367,8 @@ function SequencerBody() {<Circle size={12} fill="currentColor" /></button><span className="seq-div" />- <button type="button" className="seq-btn" title="Jump to start" onClick={() => setTime(0)}><ChevronFirst size={15} /></button>- <button type="button" className="seq-btn" title="Previous keyframe" onClick={() => jumpKey(-1)}><ChevronLeft size={15} /></button>+ <IconButton size="md" title="Jump to start" onClick={() => setTime(0)}><ChevronFirst size={15} /></IconButton>+ <IconButton size="md" title="Previous keyframe" onClick={() => jumpKey(-1)}><ChevronLeft size={15} /></IconButton><buttontype="button"className="seq-btn seq-btn--play"@@ -376,16 +377,16 @@ function SequencerBody() {>{playing ? <Pause size={14} fill="currentColor" /> : <Play size={14} fill="currentColor" />}</button>- <button type="button" className="seq-btn" title="Next keyframe" onClick={() => jumpKey(1)}><ChevronRight size={15} /></button>- <button type="button" className="seq-btn" title="Jump to end" onClick={() => setTime(duration)}><ChevronLast size={15} /></button>- <button- type="button"- className={`seq-btn${loop ? ' on' : ''}`}+ <IconButton size="md" title="Next keyframe" onClick={() => jumpKey(1)}><ChevronRight size={15} /></IconButton>+ <IconButton size="md" title="Jump to end" onClick={() => setTime(duration)}><ChevronLast size={15} /></IconButton>+ <IconButton+ size="md"+ active={loop}title="Loop"onClick={() => useSequencerStore.getState().toggleLoop()}><Repeat size={14} />- </button>+ </IconButton><span className="seq-div" /><span className="seq-frame">Frame <strong>{frame}</strong> / {totalFrames}</span><span className="seq-spacer" />@@ -393,22 +394,21 @@ function SequencerBody() {<button type="button" className={`seq-tab${view === 'sheet' ? ' active' : ''}`} onClick={() => useSequencerStore.getState().setView('sheet')}>Sheet</button><button type="button" className={`seq-tab${view === 'curve' ? ' active' : ''}`} onClick={() => useSequencerStore.getState().setView('curve')}>Curves</button></div>- <button- type="button"- className={`seq-btn${snap ? ' on' : ''}`}+ <IconButton+ size="md"+ active={snap}title="Snap to frame"onClick={() => useSequencerStore.getState().toggleSnap()}><Magnet size={14} />- </button>- <button- type="button"- className="seq-btn"+ </IconButton>+ <IconButton+ size="md"title="Clip settings (duration / fps / loop)"onClick={(e) => setSettingsOpen(popoverAt(e))}><Settings2 size={14} />- </button>+ </IconButton><buttontype="button"className="seq-btn seq-btn--text"diff --git a/desktop/src/panels/TilemapPainter.tsx b/desktop/src/panels/TilemapPainter.tsxindex 3c274ad6d..abea3071e 100644--- a/desktop/src/panels/TilemapPainter.tsx+++ b/desktop/src/panels/TilemapPainter.tsx@@ -15,7 +15,7 @@ import {FlipHorizontal, FlipVertical, RotateCw, Mountain, Plus, X, MousePointer2, Dices,ZoomIn, ZoomOut, Maximize2, Eye, EyeOff, Lock, Unlock,} from 'lucide-react';-import { parseTileset, encodeTile, type TilesetAsset, type TileStamp } from 'esengine';+import { encodeTile, type TilesetAsset, type TileStamp } from 'esengine';import { useTilemapPaint, type PaintTool, type PaletteTileset, type AtlasInfo } from '@/store/tilemapPaintStore';import { useSelection } from '@/store/selectionStore';import { SceneModel } from '@/engine/SceneModel';@@ -24,15 +24,9 @@ import { ProjectStore } from '@/project/ProjectStore';import { TILE_TOOL_KEY, exitTilePaint } from '@/tools/tileMode';import { MOD_LABEL } from '@/commands/keybinding';import { buildStampGhost } from '@/tools/tileStampGhost';--function colsFor(width: number, tileW: number, margin: number, spacing: number): number {- const stride = tileW + spacing;- return stride > 0 ? Math.max(1, Math.floor((width - margin + spacing) / stride)) : 1;-}-function rowsFor(height: number, tileH: number, margin: number, spacing: number): number {- const stride = tileH + spacing;- return stride > 0 ? Math.max(0, Math.floor((height - margin + spacing) / stride)) : 0;-}+import { colsFor, rowsFor, TERRAIN_COLORS } from '@/tools/tileMath';+import { loadTilesetAsset } from '@/tileset/loadTileset';+import { IconButton } from '@/components/IconButton';const TOOLS: { id: PaintTool; icon: typeof Brush; label: string }[] = [{ id: 'brush', icon: Brush, label: 'Brush' },@@ -45,8 +39,6 @@ const TOOLS: { id: PaintTool; icon: typeof Brush; label: string }[] = [{ id: 'terrain', icon: Mountain, label: 'Terrain' },];-const TERRAIN_COLORS = ['#4caf50', '#d6884c', '#4c8fd6', '#b14cd6', '#d6c64c', '#d64c6e'];-/** Resolve the .estileset ref(s) a selected TilemapLayer references — the `tilesetAssets`* list (multi-tileset) or the singular `tilesetAsset` — as @uuid refs (not yet paths). */function selectedTilemapTilesetRefs(selectedId: number | null): string[] {@@ -127,7 +119,7 @@ export function TilemapPainter() {let firstId = 1;for (const path of paths) {try {- const a = parseTileset(JSON.parse(await window.estella.fs.read(path)));+ const a = await loadTilesetAsset(path);entries.push({ path, asset: a, firstId });let count = a.tileCount ?? 0;if (count <= 0) {@@ -149,7 +141,7 @@ export function TilemapPainter() {if (!tilesetPath) { setAsset(null); setTilesetAsset(null); return; }void (async () => {try {- const a = parseTileset(JSON.parse(await window.estella.fs.read(tilesetPath)));+ const a = await loadTilesetAsset(tilesetPath);if (alive) { setAsset(a); setTilesetAsset(a); }} catch { if (alive) { setAsset(null); setTilesetAsset(null); } }})();@@ -368,45 +360,47 @@ export function TilemapPainter() {</div>)}<div className="tp-tools">- <button- type="button"- className={'tp-tool' + (tool === null ? ' is-active' : '')}+ <IconButton+ variant="outline"+ size="lg"+ active={tool === null}title="Select / transform (Q · Esc to exit painting)"onClick={() => exitTilePaint('select')}><MousePointer2 size={15} />- </button>+ </IconButton><span className="tp-sep" />{TOOLS.map((t) => (- <button+ <IconButtonkey={t.id}- type="button"- className={'tp-tool' + (tool === t.id ? ' is-active' : '')}+ variant="outline"+ size="lg"+ active={tool === t.id}title={`${t.label} (${TILE_TOOL_KEY[t.id]})`}onClick={() => setTool(t.id)}><t.icon size={15} />- </button>+ </IconButton>))}<span className="tp-sep" />- <button type="button" className="tp-tool" title="Flip horizontal (H)" onClick={() => flipH()}>+ <IconButton variant="outline" size="lg" title="Flip horizontal (H)" onClick={() => flipH()}><FlipHorizontal size={15} />- </button>- <button type="button" className="tp-tool" title="Flip vertical (V)" onClick={() => flipV()}>+ </IconButton>+ <IconButton variant="outline" size="lg" title="Flip vertical (V)" onClick={() => flipV()}><FlipVertical size={15} />- </button>- <button type="button" className="tp-tool" title="Rotate 90° (R)" onClick={() => rotateCW()}>+ </IconButton>+ <IconButton variant="outline" size="lg" title="Rotate 90° (R)" onClick={() => rotateCW()}><RotateCw size={15} />- </button>- <button- type="button"- className={'tp-tool' + (randomBrush ? ' is-active' : '')}+ </IconButton>+ <IconButton+ variant="outline"+ size="lg"+ active={randomBrush}title="Random: each painted cell samples one tile from the selection"- aria-pressed={randomBrush}onClick={() => toggleRandomBrush()}><Dices size={15} />- </button>+ </IconButton><span className="tp-grow" /><span className="tp-brush">{tool === 'terrain' ? 'Terrain brush' : (diff --git a/desktop/src/panels/TilesetEditor.tsx b/desktop/src/panels/TilesetEditor.tsxindex 9f2a50e1f..ef10ea71c 100644--- a/desktop/src/panels/TilesetEditor.tsx+++ b/desktop/src/panels/TilesetEditor.tsx@@ -28,17 +28,7 @@ import { DirtyDot } from '@/components/DirtyDot';import { TilesetDocument } from '@/tileset/TilesetDocument';import { TilesetCommands } from '@/tileset/TilesetCommands';import { ProjectStore } from '@/project/ProjectStore';--function colsFor(width: number, tileW: number, margin: number, spacing: number): number {- const stride = tileW + spacing;- return stride > 0 ? Math.max(1, Math.floor((width - margin + spacing) / stride)) : 1;-}-function rowsFor(height: number, tileH: number, margin: number, spacing: number): number {- const stride = tileH + spacing;- return stride > 0 ? Math.max(0, Math.floor((height - margin + spacing) / stride)) : 0;-}--const TERRAIN_COLORS = ['#4caf50', '#d6884c', '#4c8fd6', '#b14cd6', '#d6c64c', '#d64c6e'];+import { colsFor, rowsFor, TERRAIN_COLORS } from '@/tools/tileMath';/** Loops the frame strip at each frame's own duration; falls back to the target tile. */function AnimPreview({ frames, fallback, thumb }: {diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex e1e30566e..b242b0785 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -27,6 +27,7 @@ import { StatsStore } from '@/engine/StatsStore';import { PerfMonitor } from '@/engine/PerfMonitor';import { PerfOverlay } from '@/components/PerfOverlay';import { Perf } from '@/components/Perf';+import { Popover, usePopover } from '@/components/Popover';import type { ToolMode } from '@/types';import { resolveActiveTool, type EditorTool, type ToolContext, type PointerInput } from '@/tools';import { cursorTile } from '@/tools/tileTools';@@ -257,58 +258,53 @@ function OvTool({);}-// A viewport overlay dropdown (UE5 "show flags" / "snap" menus): an .ovbtn-// trigger with an icon, a label, and a chevron, plus a floating .dd-menu.-// Closes on outside-click or after an item is chosen (the menu's onClick).+// A viewport overlay dropdown (the "show flags" / "snap" menus): an .ovbtn+// trigger with an icon, a label, and a chevron, over a glass <Popover> holding+// the check/radio rows. Closes on item-click, outside press, scroll, or Escape.function OvDropdown({icon: Icon,label,- align,title,children,}: {icon: LucideIcon;label: ReactNode;- align?: 'r';title?: string;children: ReactNode;}) {- const [open, setOpen] = useState(false);- const ref = useRef<HTMLDivElement>(null);- useEffect(() => {- if (!open) return;- const onDown = (e: MouseEvent) => {- if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);- };- window.addEventListener('mousedown', onDown);- return () => window.removeEventListener('mousedown', onDown);- }, [open]);+ const pop = usePopover();+ const btnRef = useRef<HTMLButtonElement>(null);return (- <div className={`dd${open ? ' open' : ''}`} ref={ref}>+ <><button+ ref={btnRef}type="button"- className={`ovbtn${open ? ' open' : ''}`}+ className={`ovbtn${pop.isOpen ? ' open' : ''}`}title={title}aria-haspopup="menu"- aria-expanded={open}- onClick={() => setOpen((o) => !o)}+ aria-expanded={pop.isOpen}+ onClick={() => (pop.isOpen ? pop.close() : pop.open(btnRef.current))}><Icon className="ic" size={13} strokeWidth={1.9} />{label}<ChevronDown className="cv" size={9} strokeWidth={2.5} /></button>- {/* Item clicks bubble here to dismiss; each item runs its own handler. */}- <div className={`dd-menu${align === 'r' ? ' r' : ''}`} role="menu" onClick={() => setOpen(false)}>- {children}- </div>- </div>+ {/* Item clicks bubble to the menu to dismiss; each runs its own handler. */}+ {pop.isOpen && pop.anchor && (+ <Popover anchor={pop.anchor} width="auto" className="popover--glass" onClose={pop.close}>+ <div role="menu" onClick={pop.close}>+ {children}+ </div>+ </Popover>+ )}+ </>);}// Multi-toggle menu row (checkbox box) — for the Show Flags menu.function DdCheck({ on, label, onClick }: { on: boolean; label: string; onClick: () => void }) {return (- <div className={`dd-item${on ? ' on' : ''}`} role="menuitemcheckbox" aria-checked={on} onClick={onClick}>+ <div className={`ovmenu-item${on ? ' on' : ''}`} role="menuitemcheckbox" aria-checked={on} onClick={onClick}><span className="chk">{on && <Check size={8} strokeWidth={3.5} />}</span><span className="l">{label}</span></div>@@ -318,7 +314,7 @@ function DdCheck({ on, label, onClick }: { on: boolean; label: string; onClick:// Single-select menu row (tick mark, shown when active) — for the Snap menu.function DdRadio({ on, label, onClick }: { on: boolean; label: string; onClick: () => void }) {return (- <div className={`dd-item${on ? ' on' : ''}`} role="menuitemradio" aria-checked={on} onClick={onClick}>+ <div className={`ovmenu-item${on ? ' on' : ''}`} role="menuitemradio" aria-checked={on} onClick={onClick}><span className="tk"><Check size={11} strokeWidth={3} /></span><span className="l">{label}</span></div>@@ -1036,7 +1032,7 @@ export function Viewport() {<div className="ov ov-tl"><div className="ov-cluster"><OvDropdown icon={Eye} label="Show" title="Show Flags">- <div className="dd-lbl">Show Flags</div>+ <div className="ovmenu-lbl">Show Flags</div><DdCheck on={showGrid} label="Grid" onClick={() => commands.run('view.toggleGrid')} /><DdCheck on={showGizmos} label="Gizmos" onClick={() => commands.run('view.toggleGizmos')} /><DdCheck on={showColliders} label="Colliders" onClick={() => commands.run('view.toggleColliders')} />@@ -1083,11 +1079,10 @@ export function Viewport() {<OvDropdownicon={Grid3x3}label={<span className="val">{snapping ? snapStep : 'Off'}</span>}- align="r"title="Grid Snap"><DdRadio on={!snapping} label="Off" onClick={() => useEditorStore.setState({ snapping: false })} />- <div className="dd-lbl">Move (units)</div>+ <div className="ovmenu-lbl">Move (units)</div>{SNAP_STEPS.map((s) => (<DdRadiokey={s}@@ -1096,7 +1091,7 @@ export function Viewport() {onClick={() => useEditorStore.getState().setSnapStep(s)}/>))}- <div className="dd-lbl">Rotate (°)</div>+ <div className="ovmenu-lbl">Rotate (°)</div>{SNAP_ANGLES.map((a) => (<DdRadiokey={a}@@ -1105,7 +1100,7 @@ export function Viewport() {onClick={() => useEditorStore.setState({ snapping: true, snapAngle: a })}/>))}- <div className="dd-lbl">Scale (×)</div>+ <div className="ovmenu-lbl">Scale (×)</div>{SNAP_SCALES.map((s) => (<DdRadiokey={s}diff --git a/desktop/src/theme/content.css b/desktop/src/theme/content.cssindex fe0d10c89..707e2f754 100644--- a/desktop/src/theme/content.css+++ b/desktop/src/theme/content.css@@ -12,9 +12,6 @@.cb-head { height: 30px; padding: 0 6px 0 10px; background: var(--srf-3); }.cb-head .pt { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }.cb-head .sp { flex: 1; }-.cb-ico { width: 22px; height: 22px; display: grid; place-items: center; color: var(--text-mute); border-radius: var(--r-sm); transition: color var(--t-fast), background var(--t-fast); }-.cb-ico:hover { color: var(--text); background: var(--srf-4); }-.cb-ico:active { background: var(--srf-5); }/* ── Sources (left) ── */.cb-src { width: 168px; flex-shrink: 0; border-right: 1px solid var(--border); }@@ -51,9 +48,6 @@.cb-add { height: 26px; display: inline-flex; align-items: center; gap: 5px; padding: 0 10px; background: var(--srf-3); color: var(--star-hi); border: 1px solid var(--star-line); font-weight: 600; font-size: var(--fs-xs); border-radius: var(--r-sm); transition: background var(--t-fast); flex-shrink: 0; }.cb-add:hover { background: var(--star-dim); }.cb-add:disabled { opacity: 0.45; }-.cb-ghost { width: 26px; height: 26px; display: grid; place-items: center; color: var(--text-dim); background: var(--srf-3); border: 1px solid var(--border-line); border-radius: var(--r-sm); flex-shrink: 0; transition: color var(--t-fast), background var(--t-fast); }-.cb-ghost:hover { color: var(--text); background: var(--srf-4); }-.cb-ghost:active { background: var(--srf-5); }/* Inline rename editor (tiles + list rows). */.cb-rename { width: 100%; min-width: 0; font: inherit; color: var(--text); background: var(--inset); border: 1px solid var(--acc); border-radius: var(--r-xs); padding: 1px 4px; outline: none; text-align: center; }diff --git a/desktop/src/theme/controls.css b/desktop/src/theme/controls.cssindex 99b8200e3..b3471f090 100644--- a/desktop/src/theme/controls.css+++ b/desktop/src/theme/controls.css@@ -83,6 +83,32 @@.pbtn.on { color: var(--acc); }.pbody { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }+/* — Icon button (components/IconButton.tsx): the canonical square glyph button.+ `.pbtn` above and the per-panel `.cb-ico`/`.filt-btn`/`.modal__x`/`.set-x`/+ `.tbtn` classes are the same recipe at 22/24/28px — they fold into this as+ call sites migrate to <IconButton>. — */+.icon-btn {+ display: grid;+ place-items: center;+ color: var(--text-mute);+ border-radius: var(--r-sm);+ flex-shrink: 0;+ transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);+}+.icon-btn--sm { width: 22px; height: 22px; }+.icon-btn--md { width: 24px; height: 24px; }+.icon-btn--lg { width: 28px; height: 28px; }+.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--srf-4); }+.icon-btn:active:not(:disabled) { background: var(--srf-5); }+.icon-btn:disabled { opacity: 0.4; cursor: default; }+/* Active = accent fill — the same "current / selected" signal as Segmented's .on,+ so a toggled toolbar button and a chosen segment read alike across the editor. */+.icon-btn.on { background: var(--acc); color: var(--on-accent); }+.icon-btn.on:hover:not(:disabled) { background: var(--acc); color: var(--on-accent); }+.icon-btn--outline { border: 1px solid var(--border-line); background: var(--srf-3); color: var(--text-dim); }+.icon-btn--outline:hover:not(:disabled) { color: var(--text); border-color: var(--text-mute); background: var(--srf-4); }+.icon-btn--outline.on { border-color: var(--acc); }+/* — Input well (components/NumField.tsx + the inspector's dropdown trigger):a bordered inset the actual control sits in, focus ring on the well. — */.field { height: 22px; flex: 1; min-width: 0; display: flex; align-items: center; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); transition: border-color var(--t-fast), box-shadow var(--t-fast); }@@ -91,6 +117,13 @@.field select { width: 100%; background: none; border: none; outline: none; padding: 0 6px; font-size: var(--fs-sm); color: var(--text); appearance: none; cursor: pointer; }.field.dropdown { padding: 0; overflow: hidden; }+/* — Dimension (Details/DimControl): a number well + a compact px/%/auto unit+ picker. `auto` collapses the well to a static label (Yoga ignores value). — */+.dim { display: flex; gap: 4px; flex: 1; min-width: 0; }+.dim .field { flex: 1; }+.dim .sel-trigger { flex: 0 0 auto; }+.dim-auto { justify-content: center; color: var(--text-mute); font-family: var(--mono); font-size: var(--fs-sm); }+/* — Search/filter field (components/SearchField.tsx). One recipe for everypanel filter; usage sites keep only layout deltas (width/height/margin).The flush variant is the popover-internal border-bottom row. — */diff --git a/desktop/src/theme/inspector.css b/desktop/src/theme/inspector.cssindex 9545b77e2..68c6f5933 100644--- a/desktop/src/theme/inspector.css+++ b/desktop/src/theme/inspector.css@@ -86,9 +86,9 @@.prop.modified .prop-label { color: var(--text); }.prop.modified .prop-label::before { content: ''; position: absolute; left: -6px; top: 50%; transform: translateY(-50%); width: 3px; height: 13px; border-radius: 2px; background: var(--warn); }/* Required field left empty — a soft flag: red label + asterisk + input outline. */-.prop.invalid .prop-label { color: var(--danger, #e5484d); }-.prop.invalid .prop-label::after { content: ' *'; color: var(--danger, #e5484d); font-weight: 700; }-.prop.invalid .assetref, .prop.invalid .field { border-color: var(--danger, #e5484d); }+.prop.invalid .prop-label { color: var(--error); }+.prop.invalid .prop-label::after { content: ' *'; color: var(--error); font-weight: 700; }+.prop.invalid .assetref, .prop.invalid .field { border-color: var(--error); }.prop-value { display: flex; align-items: center; gap: 4px; min-width: 0; }.prop-reset { width: 16px; height: 16px; display: grid; place-items: center; color: var(--warn); opacity: 0; transition: opacity var(--t-fast); justify-self: center; }.prop:hover .prop-reset.show, .prop.modified .prop-reset.show { opacity: .85; }diff --git a/desktop/src/theme/menus.css b/desktop/src/theme/menus.cssindex 518189f43..7b46b0078 100644--- a/desktop/src/theme/menus.css+++ b/desktop/src/theme/menus.css@@ -127,8 +127,6 @@}.modal__head { display: flex; align-items: center; height: 38px; padding: 0 8px 0 14px; background: var(--srf-3); border-bottom: 1px solid var(--border); flex-shrink: 0; }.modal__title { flex: 1; font-size: var(--fs-md); font-weight: 600; color: var(--text); }-.modal__x { width: 26px; height: 26px; display: grid; place-items: center; color: var(--text-mute); border-radius: var(--r-sm); }-.modal__x:hover { color: var(--text); background: var(--srf-4); }.modal__body { padding: 14px; overflow-y: auto; }.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--srf-2); flex-shrink: 0; }/* ConfirmDialog body — pre-line keeps multi-paragraph warnings readable */diff --git a/desktop/src/theme/settings.css b/desktop/src/theme/settings.cssindex 93eb7709a..2b927e096 100644--- a/desktop/src/theme/settings.css+++ b/desktop/src/theme/settings.css@@ -50,8 +50,6 @@.set-head-sp { flex: 1; }/* shared SearchField, sized for the dialog header */.set-search { flex: none; width: 220px; height: 28px; }-.set-x { width: 28px; height: 28px; display: grid; place-items: center; color: var(--text-mute); border-radius: var(--r-sm); }-.set-x:hover { color: var(--text); background: var(--srf-4); }.set-body { flex: 1; min-height: 0; display: flex; }.set-nav {diff --git a/desktop/src/theme/tilemap.css b/desktop/src/theme/tilemap.cssindex c8ff367b8..8d7dc05f4 100644--- a/desktop/src/theme/tilemap.css+++ b/desktop/src/theme/tilemap.css@@ -93,26 +93,7 @@}.tp-brushthumb-in { position: absolute; top: 0; left: 0; transform-origin: 0 0; }-.tp-tool {- display: inline-flex;- align-items: center;- justify-content: center;- width: 28px;- height: 26px;- background: var(--srf-3);- border: 1px solid var(--line);- border-radius: var(--r-sm);- color: var(--text-dim);- cursor: pointer;-}-.tp-tool:not(:disabled):hover { color: var(--text); background: var(--srf-4); }-.tp-tool:not(:disabled):active { background: var(--srf-5); }-.tp-tool:disabled { opacity: 0.4; cursor: default; }-.tp-tool.is-active {- background: var(--star);- border-color: var(--star);- color: var(--on-accent);-}+/* Tool buttons are the shared <IconButton variant="outline"> (controls.css). *//* Palette zoom bar — small tilesets are unclickable at 1:1, so − / + / fit. */.tp-palbar {diff --git a/desktop/src/theme/tileset.css b/desktop/src/theme/tileset.cssindex b725c5834..e5247056c 100644--- a/desktop/src/theme/tileset.css+++ b/desktop/src/theme/tileset.css@@ -154,7 +154,7 @@padding: 3px 5px;cursor: pointer;}-.ts-trm:hover { color: #f0645a; border-color: #f0645a; }+.ts-trm:hover { color: var(--error-hi); border-color: var(--error-hi); }/* Terrain peering cell: member highlight + clickable 3×3 zones */.ts-tcell.is-member { background: color-mix(in srgb, var(--tcolor) 26%, transparent); border-color: var(--tcolor); }@@ -216,7 +216,7 @@.ts-pe-svg { position: absolute; left: 0; top: 0; pointer-events: none; }.ts-pe-poly { fill: color-mix(in srgb, var(--gizmo-tile) 30%, transparent); stroke: var(--gizmo-tile); stroke-width: 0.5; }.ts-pe-pt { fill: #fff; stroke: var(--gizmo-tile); stroke-width: 0.5; pointer-events: auto; cursor: pointer; }-.ts-pe-pt:hover { fill: #f0645a; }+.ts-pe-pt:hover { fill: var(--error-hi); }.ts-pe-hint { color: var(--text-faint); font-size: var(--fs-xs); text-align: center; }/* Animation mode: the frame strip under the toolbar + atlas cell markers. */diff --git a/desktop/src/theme/viewport.css b/desktop/src/theme/viewport.cssindex 18d98ec5e..fbed84236 100644--- a/desktop/src/theme/viewport.css+++ b/desktop/src/theme/viewport.css@@ -57,29 +57,19 @@.ov-tool:hover kbd { opacity: 1; }.ov-divider { width: 1px; height: 16px; background: var(--border-line); margin: 0 3px; }-/* overlay dropdown (view-menu / snap) — adopted from ue5/shell.css (.dd block) */-.dd { position: relative; }-.dd-menu {- position: absolute;- top: calc(100% + 6px);+/* overlay dropdown (view-menu / snap): the shared <Popover> shell in a glass+ variant (backdrop blur over the live viewport), holding UE-style check/radio+ rows. Popover owns the float + dismiss; these classes are just the contents. */+.popover--glass {min-width: 188px;+ padding: 4px;+ max-height: none;background: rgba(var(--glass-rgb), 0.96);-webkit-backdrop-filter: blur(20px);backdrop-filter: blur(20px);- border: 1px solid var(--border-line);border-radius: var(--r-lg);- box-shadow: var(--shadow-3);- padding: 4px;- z-index: 8;- opacity: 0;- transform: translateY(-6px) scale(0.98);- transform-origin: top;- pointer-events: none;- transition: opacity var(--t-fast) var(--e-out), transform var(--t-fast) var(--e-out);}-.dd.open .dd-menu { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }-.dd-menu.r { right: 0; }-.dd-lbl {+.ovmenu-lbl {font-size: var(--fs-2xs);text-transform: uppercase;letter-spacing: 0.6px;@@ -87,7 +77,7 @@font-weight: 700;padding: 6px 8px 4px;}-.dd-item {+.ovmenu-item {display: flex;align-items: center;gap: 8px;@@ -99,11 +89,11 @@cursor: pointer;transition: color var(--t-fast), background var(--t-fast);}-.dd-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }-.dd-item .tk { width: 14px; display: inline-flex; color: var(--acc); opacity: 0; }-.dd-item.on { color: var(--text); }-.dd-item.on .tk { opacity: 1; }-.dd-item .chk {+.ovmenu-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }+.ovmenu-item .tk { width: 14px; display: inline-flex; color: var(--acc); opacity: 0; }+.ovmenu-item.on { color: var(--text); }+.ovmenu-item.on .tk { opacity: 1; }+.ovmenu-item .chk {width: 13px;height: 13px;border: 1px solid var(--border-line);@@ -112,17 +102,8 @@place-items: center;color: transparent;}-.dd-item.on .chk { background: var(--acc); border-color: var(--acc); color: var(--on-accent); }-.dd-item .l { flex: 1; }-.dd-item .k {- margin-left: auto;- font-size: var(--fs-2xs);- color: var(--text-mute);- border: 1px solid var(--border-line);- border-radius: 2px;- padding: 1px 4px;-}-.dd-sep { height: 1px; background: var(--border-line); margin: 4px 6px; }+.ovmenu-item.on .chk { background: var(--acc); border-color: var(--acc); color: var(--on-accent); }+.ovmenu-item .l { flex: 1; }/* perf widget (bottom-right) */.vp-perf {diff --git a/desktop/src/tileset/loadTileset.ts b/desktop/src/tileset/loadTileset.tsnew file mode 100644index 000000000..7acb612c3--- /dev/null+++ b/desktop/src/tileset/loadTileset.ts@@ -0,0 +1,14 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file loadTileset.ts+ * @brief Read + parse an `.estileset` from disk into a `TilesetAsset`. The one+ * place the fs.read → JSON.parse → parseTileset chain lives, so the+ * painter's palette loader isn't a second, drifting copy of it.+ */+import { parseTileset, type TilesetAsset } from 'esengine';++/** Load and parse an `.estileset` at `path` (throws on unreadable/invalid JSON). */+export async function loadTilesetAsset(path: string): Promise<TilesetAsset> {+ return parseTileset(JSON.parse(await window.estella.fs.read(path)));+}diff --git a/desktop/src/tools/tileMath.ts b/desktop/src/tools/tileMath.tsnew file mode 100644index 000000000..cdeeb6e8a--- /dev/null+++ b/desktop/src/tools/tileMath.ts@@ -0,0 +1,26 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file tileMath.ts+ * @brief Shared tileset-atlas grid math + terrain palette — used by both the+ * Tilemap painter and the Tileset editor, which each carried a verbatim+ * copy before.+ */++/** Columns an atlas grid fits: floor over the tile stride, honoring the outer+ * margin and inter-tile spacing. At least 1. */+export function colsFor(width: number, tileW: number, margin: number, spacing: number): number {+ const stride = tileW + spacing;+ return stride > 0 ? Math.max(1, Math.floor((width - margin + spacing) / stride)) : 1;+}++/** Rows an atlas grid fits (0 when the image is shorter than a single tile). */+export function rowsFor(height: number, tileH: number, margin: number, spacing: number): number {+ const stride = tileH + spacing;+ return stride > 0 ? Math.max(0, Math.floor((height - margin + spacing) / stride)) : 0;+}++/** Swatch color per terrain/autotile set — set identity in the tileset editor's+ * peering overlay and the painter's terrain chips. Category colors (like other+ * data-viz palettes), not theme surfaces, so kept as literals. */+export const TERRAIN_COLORS = ['#4caf50', '#d6884c', '#4c8fd6', '#b14cd6', '#d6c64c', '#d64c6e'];