43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import type { PageData } from '$lib/model/types';
|
|
import { settings } from './settings.svelte';
|
|
|
|
export type Tool = 'text' | 'pen' | 'highlighter' | 'eraser';
|
|
|
|
export const PEN_WIDTHS = [1.2, 2, 3.5];
|
|
export const HIGHLIGHTER_WIDTHS = [10, 16, 24];
|
|
|
|
class Tools {
|
|
tool = $state<Tool>('text');
|
|
penColor = $state(settings.data.penColors[0]);
|
|
penWidth = $state(PEN_WIDTHS[1]);
|
|
highlighterColor = $state(settings.data.highlighterColors[0]);
|
|
highlighterWidth = $state(HIGHLIGHTER_WIDTHS[1]);
|
|
eraserRadius = $state(8);
|
|
|
|
/** Pages of an imported PDF waiting to be placed on the canvas. */
|
|
placing = $state.raw<{ name: string; pages: PageData[] } | null>(null);
|
|
|
|
get inking() {
|
|
return this.tool !== 'text';
|
|
}
|
|
|
|
get color() {
|
|
return this.tool === 'highlighter' ? this.highlighterColor : this.penColor;
|
|
}
|
|
|
|
set color(c: string) {
|
|
if (this.tool === 'highlighter') this.highlighterColor = c;
|
|
else this.penColor = c;
|
|
}
|
|
|
|
get width() {
|
|
return this.tool === 'highlighter' ? this.highlighterWidth : this.penWidth;
|
|
}
|
|
|
|
set width(w: number) {
|
|
if (this.tool === 'highlighter') this.highlighterWidth = w;
|
|
else this.penWidth = w;
|
|
}
|
|
}
|
|
|
|
export const tools = new Tools();
|