Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 78 additions & 39 deletions src/lib/Toolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
let { onundo, onclear, onexit }: Props = $props();

// --- Draggable toolbar state ---
// Start centered vertically on the right edge of the screen.
let position = $state<Point>({ x: 0, y: 0 });
let positioned = $state(false);
let dragging = $state(false);
Expand All @@ -34,16 +33,15 @@
// Place toolbar at right-center on first layout.
function initPosition(): void {
if (positioned) return;
const tbW = 52; // approx toolbar width
const tbH = 380; // approx toolbar height
const tbW = 52;
const tbH = 520;
position = {
x: Math.max(16, window.innerWidth - tbW - 24),
y: Math.max(16, Math.round((window.innerHeight - tbH) / 2))
};
positioned = true;
}

// Start auto-fade + initial position on mount
$effect(() => {
initPosition();
resetFade();
Expand All @@ -54,7 +52,6 @@

// --- Dragging ---
function onPointerDown(e: PointerEvent): void {
// Only start drag from the toolbar background, not from buttons
if ((e.target as HTMLElement).closest('[data-btn]')) return;
dragging = true;
dragOffset = { x: e.clientX - position.x, y: e.clientY - position.y };
Expand All @@ -76,27 +73,34 @@
}

// --- Tool selection ---
function selectTool(tool: Tool): void {
currentTool.set(tool);
function selectTool(t: Tool): void {
currentTool.set(t);
resetFade();
}

function selectColor(color: string): void {
currentColor.set(color);
// If eraser was selected, switch back to pen when choosing a color
currentTool.update((t) => (t === 'eraser' ? 'pen' : t));
resetFade();
}

// Auto-subscribe to stores (Svelte 5 $store syntax in template)
// --- Thickness slider ---
function changeThickness(delta: number): void {
currentThickness.update((t) => Math.max(2, Math.min(20, t + delta)));
resetFade();
}

const tools: { id: Tool; icon: string; label: string }[] = [
{ id: 'pen', icon: '✏️', label: 'Pen' },
{ id: 'highlighter', icon: '🖍️', label: 'Highlighter' },
{ id: 'eraser', icon: '⌫', label: 'Eraser' }
const tools: { id: Tool; icon: string; label: string; key: string }[] = [
{ id: 'pen', icon: '✏️', label: 'Pen', key: 'P' },
{ id: 'highlighter', icon: '🖍️', label: 'Highlighter', key: 'H' },
{ id: 'line', icon: '╱', label: 'Line', key: 'L' },
{ id: 'arrow', icon: '→', label: 'Arrow', key: 'A' },
{ id: 'rectangle', icon: '▭', label: 'Rectangle', key: 'R' },
{ id: 'ellipse', icon: '◯', label: 'Ellipse', key: 'O' },
{ id: 'eraser', icon: '⌫', label: 'Eraser', key: 'E' }
];

const colors = ['#ef4444', '#facc15', '#22c55e', '#ffffff'];
const colors = ['#ef4444', '#f97316', '#facc15', '#22c55e', '#3b82f6', '#a855f7', '#ffffff'];
</script>

<svelte:window onpointermove={onPointerMove} />
Expand All @@ -113,18 +117,18 @@
role="toolbar"
aria-label="DrawOver toolbar"
>
<!-- Tool buttons -->
{#each tools as tool (tool.id)}
<!-- Drawing tools -->
{#each tools as t (t.id)}
<button
data-btn
class="btn tool-btn"
class:active={$currentTool === tool.id}
onclick={() => selectTool(tool.id)}
aria-label={tool.label}
aria-pressed={$currentTool === tool.id}
title={tool.label}
class:active={$currentTool === t.id}
onclick={() => selectTool(t.id)}
aria-label={t.label}
aria-pressed={$currentTool === t.id}
title="{t.label} ({t.key})"
>
{tool.icon}
{t.icon}
</button>
{/each}

Expand All @@ -150,18 +154,32 @@
<!-- Divider -->
<div class="divider"></div>

<!-- Brush size controls -->
<div class="size-row">
<button data-btn class="btn size-btn" onclick={() => changeThickness(-2)} aria-label="Thinner" title="Thinner (−)">
</button>
<span class="size-display">{$currentThickness}</span>
<button data-btn class="btn size-btn" onclick={() => changeThickness(2)} aria-label="Thicker" title="Thicker (+)">
+
</button>
</div>

<!-- Divider -->
<div class="divider"></div>

<!-- Undo -->
<button data-btn class="btn" onclick={onundo} aria-label="Undo" title="Undo">
<button data-btn class="btn" onclick={onundo} aria-label="Undo" title="Undo (⌘Z)">
</button>

<!-- Clear all -->
<button data-btn class="btn" onclick={onclear} aria-label="Clear all" title="Clear all">
<button data-btn class="btn" onclick={onclear} aria-label="Clear all" title="Clear all (⌘K)">
🗑
</button>

<!-- Exit -->
<button data-btn class="btn exit-btn" onclick={onexit} aria-label="Exit draw mode" title="Exit">
<button data-btn class="btn exit-btn" onclick={onexit} aria-label="Exit draw mode" title="Exit (Alt+Shift+D)">
</button>
</div>
Expand All @@ -175,11 +193,11 @@
gap: 4px;
padding: 8px 6px;
border-radius: 16px;
background: rgba(30, 30, 36, 0.72);
background: rgba(26, 26, 31, 0.82);
backdrop-filter: blur(20px) saturate(180%);
-webkit-backdrop-filter: blur(20px) saturate(180%);
border: 1px solid rgba(255, 255, 255, 0.12);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
z-index: 9999;
opacity: 0.25;
transition: opacity 0.3s ease;
Expand All @@ -202,13 +220,13 @@
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
width: 36px;
height: 36px;
border-radius: 10px;
border: none;
background: transparent;
color: rgba(255, 255, 255, 0.8);
font-size: 15px;
font-size: 16px;
cursor: pointer;
transition: background 0.15s ease, transform 0.1s ease;
padding: 0;
Expand All @@ -223,9 +241,9 @@
}

.tool-btn.active {
background: rgba(99, 162, 255, 0.3);
background: rgba(239, 89, 63, 0.25);
color: #fff;
box-shadow: inset 0 0 0 1px rgba(99, 162, 255, 0.5);
box-shadow: inset 0 0 0 1px rgba(239, 89, 63, 0.5);
}

.color-btn {
Expand All @@ -234,8 +252,8 @@

.color-btn .dot {
display: block;
width: 16px;
height: 16px;
width: 18px;
height: 18px;
border-radius: 50%;
border: 1.5px solid rgba(255, 255, 255, 0.3);
transition: transform 0.1s ease;
Expand All @@ -244,21 +262,42 @@
.color-btn.active .dot {
transform: scale(1.15);
border-color: rgba(255, 255, 255, 0.9);
box-shadow: 0 0 0 2px rgba(99, 162, 255, 0.4);
box-shadow: 0 0 0 2px rgba(239, 89, 63, 0.4);
}

.color-btn.active {
background: rgba(255, 255, 255, 0.1);
background: rgba(255, 255, 255, 0.08);
}

.divider {
width: 22px;
width: 28px;
height: 1px;
background: rgba(255, 255, 255, 0.15);
background: rgba(255, 255, 255, 0.12);
margin: 2px 0;
flex-shrink: 0;
}

.size-row {
display: flex;
align-items: center;
gap: 2px;
}

.size-btn {
width: 28px;
height: 28px;
font-size: 14px;
font-weight: 600;
}

.size-display {
font-size: 12px;
font-family: monospace;
color: rgba(255, 255, 255, 0.6);
min-width: 20px;
text-align: center;
}

.exit-btn {
color: rgba(255, 100, 100, 0.9);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Tool = 'pen' | 'highlighter' | 'eraser';
export type Tool = 'pen' | 'highlighter' | 'eraser' | 'line' | 'arrow' | 'rectangle' | 'ellipse';

export interface Point {
x: number;
Expand Down
Loading
Loading