AI-native design editor. Open-source Figma alternative.
Merge hover-highlight, implement sections
Danila Poyarkovcadbd1330e50
diff --git a/src/components/LayersPanel.vue b/src/components/LayersPanel.vueindex 8fb76e760..14754adca 100644--- a/src/components/LayersPanel.vue+++ b/src/components/LayersPanel.vue@@ -8,6 +8,7 @@ import IconFrame from '~icons/lucide/frame'import IconGroup from '~icons/lucide/group'import IconMinus from '~icons/lucide/minus'import IconPenTool from '~icons/lucide/pen-tool'+import IconSection from '~icons/lucide/layout-grid'import IconSquare from '~icons/lucide/square'import IconType from '~icons/lucide/type'@@ -25,6 +26,7 @@ interface LayerNode {}const nodeIcons: Record<string, typeof IconSquare> = {+ SECTION: IconSection,ELLIPSE: IconCircle,FRAME: IconFrame,GROUP: IconGroup,diff --git a/src/components/Toolbar.vue b/src/components/Toolbar.vueindex ab8ddff13..b73babf4b 100644--- a/src/components/Toolbar.vue+++ b/src/components/Toolbar.vue@@ -1,10 +1,16 @@<script setup lang="ts">+import { DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuPortal } from 'reka-ui'+import IconMousePointer from '~icons/lucide/mouse-pointer'import IconFrame from '~icons/lucide/frame'+import IconLayoutGrid from '~icons/lucide/layout-grid'import IconSquare from '~icons/lucide/square'+import IconCircle from '~icons/lucide/circle'+import IconMinus from '~icons/lucide/minus'import IconPenTool from '~icons/lucide/pen-tool'import IconType from '~icons/lucide/type'import IconHand from '~icons/lucide/hand'+import IconChevronDown from '~icons/lucide/chevron-down'import { TOOLS, useEditorStore } from '../stores/editor'@@ -15,30 +21,104 @@ const store = useEditorStore()const toolIcons: Record<Tool, typeof IconSquare> = {SELECT: IconMousePointer,FRAME: IconFrame,+ SECTION: IconLayoutGrid,RECTANGLE: IconSquare,- ELLIPSE: IconSquare,- LINE: IconSquare,+ ELLIPSE: IconCircle,+ LINE: IconMinus,PEN: IconPenTool,TEXT: IconType,HAND: IconHand}++const toolLabels: Record<Tool, string> = {+ SELECT: 'Move',+ FRAME: 'Frame',+ SECTION: 'Section',+ RECTANGLE: 'Rectangle',+ ELLIPSE: 'Ellipse',+ LINE: 'Line',+ PEN: 'Pen',+ TEXT: 'Text',+ HAND: 'Hand'+}++function isActive(tool: typeof TOOLS[number]): boolean {+ if (tool.key === store.state.activeTool) return true+ return tool.flyout?.includes(store.state.activeTool) ?? false+}++function activeKeyForTool(tool: typeof TOOLS[number]): Tool {+ if (tool.flyout?.includes(store.state.activeTool)) return store.state.activeTool+ return tool.key+}</script><template><div class="absolute bottom-4 left-1/2 z-10 flex -translate-x-1/2 items-center"><div class="flex gap-0.5 rounded-xl border border-border bg-panel p-1 shadow-lg">- <button- v-for="tool in TOOLS"- :key="tool.key"- class="flex size-8 cursor-pointer items-center justify-center rounded-lg border-none transition-colors"- :class="tool.key === store.state.activeTool- ? 'bg-accent text-white'- : 'bg-transparent text-muted hover:bg-hover hover:text-surface'"- :title="`${tool.label} (${tool.shortcut})`"- @click="store.setTool(tool.key)"- >- <component :is="toolIcons[tool.key]" class="size-4" />- </button>+ <template v-for="tool in TOOLS" :key="tool.key">+ <!-- Tool with flyout: split button + chevron -->+ <div v-if="tool.flyout && tool.flyout.length > 1" class="flex items-center">+ <button+ class="flex size-8 cursor-pointer items-center justify-center rounded-lg border-none transition-colors"+ :class="isActive(tool)+ ? 'bg-accent text-white'+ : 'bg-transparent text-muted hover:bg-hover hover:text-surface'"+ :title="`${toolLabels[activeKeyForTool(tool)]} (${tool.shortcut})`"+ @click="store.setTool(activeKeyForTool(tool))"+ >+ <component :is="toolIcons[activeKeyForTool(tool)]" class="size-4" />+ </button>++ <DropdownMenuRoot>+ <DropdownMenuTrigger as-child>+ <button+ class="flex h-8 w-3 cursor-pointer items-center justify-center rounded-lg border-none transition-colors"+ :class="isActive(tool)+ ? 'bg-accent text-white'+ : 'bg-transparent text-muted hover:bg-hover hover:text-surface'"+ >+ <IconChevronDown class="size-2.5" />+ </button>+ </DropdownMenuTrigger>++ <DropdownMenuPortal>+ <DropdownMenuContent+ side="top"+ :side-offset="8"+ align="start"+ class="min-w-32 rounded-lg border border-border bg-panel p-1 shadow-lg"+ >+ <DropdownMenuItem+ v-for="sub in tool.flyout"+ :key="sub"+ class="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-xs outline-none transition-colors"+ :class="store.state.activeTool === sub+ ? 'bg-accent text-white'+ : 'text-surface hover:bg-hover'"+ @select="store.setTool(sub)"+ >+ <component :is="toolIcons[sub]" class="size-3.5" />+ {{ toolLabels[sub] }}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenuPortal>+ </DropdownMenuRoot>+ </div>++ <!-- Simple tool button -->+ <button+ v-else+ class="flex size-8 cursor-pointer items-center justify-center rounded-lg border-none transition-colors"+ :class="isActive(tool)+ ? 'bg-accent text-white'+ : 'bg-transparent text-muted hover:bg-hover hover:text-surface'"+ :title="`${toolLabels[tool.key]} (${tool.shortcut})`"+ @click="store.setTool(tool.key)"+ >+ <component :is="toolIcons[tool.key]" class="size-4" />+ </button>+ </template></div></div></template>diff --git a/src/composables/use-canvas-input.ts b/src/composables/use-canvas-input.tsindex 0f4e430f2..cb595b07c 100644--- a/src/composables/use-canvas-input.ts+++ b/src/composables/use-canvas-input.ts@@ -72,6 +72,7 @@ type DragState = DragDraw | DragMove | DragPan | DragResize | DragMarquee | Dragconst TOOL_TO_NODE: Partial<Record<Tool, NodeType>> = {FRAME: 'FRAME',+ SECTION: 'SECTION',RECTANGLE: 'RECTANGLE',ELLIPSE: 'ELLIPSE',LINE: 'LINE',@@ -751,7 +752,7 @@ export function useCanvasInput(canvasRef: Ref<HTMLCanvasElement | null>, store:const node = store.graph.getNode(id)if (!node?.parentId || store.isTopLevel(node.parentId)) continueconst parent = store.graph.getNode(node.parentId)- if (!parent || parent.type !== 'FRAME') continue+ if (!parent || (parent.type !== 'FRAME' && parent.type !== 'SECTION')) continueconst outsideX = node.x + node.width < 0 || node.x > parent.widthconst outsideY = node.y + node.height < 0 || node.y > parent.heightif (outsideX || outsideY) {diff --git a/src/constants.ts b/src/constants.tsindex 62b04ce2c..6a8b06bbb 100644--- a/src/constants.ts+++ b/src/constants.ts@@ -1,5 +1,5 @@import type { Color } from './types'-import type { Fill } from './engine/scene-graph'+import type { Fill, Stroke } from './engine/scene-graph'export const SELECTION_COLOR = { r: 0.23, g: 0.51, b: 0.96, a: 1 } satisfies Colorexport const SNAP_COLOR = { r: 1.0, g: 0.0, b: 0.56, a: 1 } satisfies Color@@ -77,5 +77,25 @@ export const ROTATION_HIT_RADIUS = 8export const ZOOM_SENSITIVITY = 0.99+export const SECTION_CORNER_RADIUS = 5+export const SECTION_TITLE_HEIGHT = 24+export const SECTION_TITLE_PADDING_X = 8+export const SECTION_TITLE_RADIUS = 5+export const SECTION_TITLE_FONT_SIZE = 12+export const SECTION_TITLE_GAP = 6+export const SECTION_DEFAULT_FILL: Fill = {+ type: 'SOLID',+ color: { r: 0.37, g: 0.37, b: 0.37, a: 1 },+ opacity: 1,+ visible: true+}+export const SECTION_DEFAULT_STROKE: Stroke = {+ color: { r: 0.55, g: 0.55, b: 0.55, a: 1 },+ weight: 1,+ opacity: 1,+ visible: true,+ align: 'INSIDE'+}+export const RULER_TARGET_PIXEL_SPACING = 100export const RULER_MAJOR_TOLERANCE = 0.01diff --git a/src/engine/renderer.ts b/src/engine/renderer.tsindex c4b85651b..1c9afc780 100644--- a/src/engine/renderer.ts+++ b/src/engine/renderer.ts@@ -11,6 +11,8 @@ import {SIZE_PILL_RADIUS, SIZE_PILL_TEXT_OFFSET_Y,MARQUEE_FILL_ALPHA, SELECTION_DASH_ALPHA, DROP_HIGHLIGHT_ALPHA, DROP_HIGHLIGHT_STROKE,LAYOUT_INDICATOR_STROKE,+ SECTION_CORNER_RADIUS, SECTION_TITLE_HEIGHT, SECTION_TITLE_PADDING_X,+ SECTION_TITLE_RADIUS, SECTION_TITLE_FONT_SIZE, SECTION_TITLE_GAP,RULER_TARGET_PIXEL_SPACING, RULER_MAJOR_TOLERANCE} from '../constants'import type { SceneNode, SceneGraph, Fill } from './scene-graph'@@ -61,6 +63,7 @@ export class SkiaRenderer {private textFont: Font | null = nullprivate labelFont: Font | null = nullprivate sizeFont: Font | null = null+ private sectionTitleFont: Font | null = nullprivate fontMgr: FontMgr | null = nullprivate fontProvider: TypefaceFontProvider | null = nullprivate fontsLoaded = false@@ -126,9 +129,11 @@ export class SkiaRenderer {this.textFont?.delete()this.labelFont?.delete()this.sizeFont?.delete()+ this.sectionTitleFont?.delete()this.textFont = new this.ck.Font(typeface, DEFAULT_FONT_SIZE)this.labelFont = new this.ck.Font(typeface, LABEL_FONT_SIZE)this.sizeFont = new this.ck.Font(typeface, SIZE_FONT_SIZE)+ this.sectionTitleFont = new this.ck.Font(typeface, SECTION_TITLE_FONT_SIZE)}this.fontMgr = this.ck.FontMgr.FromData(fontData) ?? null}@@ -586,7 +591,9 @@ export class SkiaRenderer {canvas.rotate(rotation, node.width / 2, node.height / 2)}- if (overlays.editingTextId !== nodeId) {+ if (node.type === 'SECTION') {+ this.renderSection(canvas, node)+ } else if (overlays.editingTextId !== nodeId) {this.renderShape(canvas, node)}@@ -681,6 +688,67 @@ export class SkiaRenderer {}}+ private renderSection(canvas: Canvas, node: SceneNode): void {+ const rect = this.ck.LTRBRect(0, 0, node.width, node.height)+ const rrect = this.ck.RRectXY(rect, SECTION_CORNER_RADIUS, SECTION_CORNER_RADIUS)++ // Fill+ for (const fill of node.fills) {+ if (!fill.visible) continue+ this.applyFill(fill)+ this.fillPaint.setAlphaf(fill.opacity)+ canvas.drawRRect(rrect, this.fillPaint)+ }++ // Stroke+ for (const stroke of node.strokes) {+ if (!stroke.visible) continue+ this.strokePaint.setColor(+ this.ck.Color4f(stroke.color.r, stroke.color.g, stroke.color.b, stroke.color.a)+ )+ this.strokePaint.setStrokeWidth(stroke.weight)+ this.strokePaint.setAlphaf(stroke.opacity)+ canvas.drawRRect(rrect, this.strokePaint)+ }++ // Title pill above the section+ if (this.sectionTitleFont) {+ const name = node.name+ const glyphIds = this.sectionTitleFont.getGlyphIDs(name)+ const widths = this.sectionTitleFont.getGlyphWidths(glyphIds)+ let textWidth = 0+ for (const w of widths) textWidth += w++ const pillW = textWidth + SECTION_TITLE_PADDING_X * 2+ const pillH = SECTION_TITLE_HEIGHT+ const pillX = 0+ const pillY = -pillH - SECTION_TITLE_GAP++ // Pill background — same as first fill or muted+ const pillPaint = new this.ck.Paint()+ pillPaint.setStyle(this.ck.PaintStyle.Fill)+ if (node.fills.length > 0 && node.fills[0].visible) {+ const c = node.fills[0].color+ pillPaint.setColor(this.ck.Color4f(c.r, c.g, c.b, node.fills[0].opacity))+ } else {+ pillPaint.setColor(this.ck.Color4f(0.37, 0.37, 0.37, 1))+ }+ pillPaint.setAntiAlias(true)+ const pillRect = this.ck.LTRBRect(pillX, pillY, pillX + pillW, pillY + pillH)+ canvas.drawRRect(this.ck.RRectXY(pillRect, SECTION_TITLE_RADIUS, SECTION_TITLE_RADIUS), pillPaint)+ pillPaint.delete()++ // Title text+ const textPaint = new this.ck.Paint()+ textPaint.setStyle(this.ck.PaintStyle.Fill)+ textPaint.setColor(this.ck.WHITE)+ textPaint.setAntiAlias(true)+ const textY = pillY + pillH * 0.7+ canvas.drawText(name, pillX + SECTION_TITLE_PADDING_X, textY, textPaint, this.sectionTitleFont)+ textPaint.delete()+ }+ }+private renderShape(canvas: Canvas, node: SceneNode): void {const rect = this.ck.LTRBRect(0, 0, node.width, node.height)diff --git a/src/stores/editor.ts b/src/stores/editor.tsindex 38eb4a6fd..bc9c34045 100644--- a/src/stores/editor.ts+++ b/src/stores/editor.ts@@ -1,6 +1,6 @@import { reactive, shallowRef, computed } from 'vue'-import { DEFAULT_SHAPE_FILL, DEFAULT_FRAME_FILL, CANVAS_BG_COLOR, ZOOM_SENSITIVITY } from '../constants'+import { DEFAULT_SHAPE_FILL, DEFAULT_FRAME_FILL, SECTION_DEFAULT_FILL, SECTION_DEFAULT_STROKE, CANVAS_BG_COLOR, ZOOM_SENSITIVITY } from '../constants'import type { Color } from '../types'import {parseFigmaClipboard,@@ -19,7 +19,7 @@ import { computeVectorBounds } from '../engine/vector'import type { SceneNode, NodeType, Fill, LayoutMode, VectorVertex, VectorSegment, VectorRegion, VectorNetwork } from '../engine/scene-graph'import type { SnapGuide } from '../engine/snap'-export type Tool = 'SELECT' | 'FRAME' | 'RECTANGLE' | 'ELLIPSE' | 'LINE' | 'TEXT' | 'PEN' | 'HAND'+export type Tool = 'SELECT' | 'FRAME' | 'SECTION' | 'RECTANGLE' | 'ELLIPSE' | 'LINE' | 'TEXT' | 'PEN' | 'HAND'export interface ToolDef {key: Tool@@ -30,7 +30,7 @@ export interface ToolDef {export const TOOLS: ToolDef[] = [{ key: 'SELECT', label: 'Move', shortcut: 'V' },- { key: 'FRAME', label: 'Frame', shortcut: 'F' },+ { key: 'FRAME', label: 'Frame', shortcut: 'F', flyout: ['FRAME', 'SECTION'] },{ key: 'RECTANGLE', label: 'Rectangle', shortcut: 'R', flyout: ['RECTANGLE', 'ELLIPSE', 'LINE'] },{ key: 'PEN', label: 'Pen', shortcut: 'P' },{ key: 'TEXT', label: 'Text', shortcut: 'T' },@@ -40,6 +40,7 @@ export const TOOLS: ToolDef[] = [export const TOOL_SHORTCUTS: Record<string, Tool> = {v: 'SELECT',f: 'FRAME',+ s: 'SECTION',r: 'RECTANGLE',o: 'ELLIPSE',l: 'LINE',@@ -52,6 +53,7 @@ const BLACK_FILL: Fill = { type: 'SOLID', color: { r: 0, g: 0, b: 0, a: 1 }, opaconst DEFAULT_FILLS: Record<string, Fill> = {FRAME: DEFAULT_FRAME_FILL,+ SECTION: SECTION_DEFAULT_FILL,RECTANGLE: DEFAULT_SHAPE_FILL,ELLIPSE: DEFAULT_SHAPE_FILL,LINE: BLACK_FILL,@@ -768,13 +770,18 @@ export function createEditorStore() {): string {const fill = DEFAULT_FILLS[type] ?? DEFAULT_FILLS.RECTANGLEconst pid = parentId ?? state.currentPageId- const node = graph.createNode(type, pid, {+ const overrides: Partial<SceneNode> = {x,y,width: w,height: h,fills: [{ ...fill }]- })+ }+ if (type === 'SECTION') {+ overrides.strokes = [{ ...SECTION_DEFAULT_STROKE }]+ overrides.cornerRadius = 5+ }+ const node = graph.createNode(type, pid, overrides)const id = node.idconst snapshot = { ...node }undo.push({