The Best Simplest Opinionated Whiteboard

This commit is contained in:
matthieu42morin 2023-06-08 00:11:51 +02:00
commit e5c488edcd
25 changed files with 4268 additions and 0 deletions

13
.eslintignore Normal file
View File

@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

30
.eslintrc.cjs Normal file
View File

@ -0,0 +1,30 @@
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

2
.npmrc Normal file
View File

@ -0,0 +1,2 @@
engine-strict=true
resolution-mode=highest

13
.prettierignore Normal file
View File

@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

9
.prettierrc Normal file
View File

@ -0,0 +1,9 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

38
README.md Normal file
View File

@ -0,0 +1,38 @@
# create-svelte
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm create svelte@latest
# create a new project in my-app
npm create svelte@latest my-app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```bash
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.

4
RunOnLinuxMac.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
cd "$(dirname "$0")"
npm install
vite build && vite preview

3667
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

36
package.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "simplewhiteboard",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"start": "npm install && vite build && vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test:unit": "vitest",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.5.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.26.0",
"postcss": "^8.4.24",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"tailwindcss": "^3.3.2",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.3.0",
"vitest": "^0.25.3"
},
"type": "module"
}

6
postcss.config.js Normal file
View File

@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

3
run.bat Normal file
View File

@ -0,0 +1,3 @@
@echo off
cd /d %~dp0
npm run start

3
src/app.css Normal file
View File

@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

12
src/app.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}
export {};

15
src/app.html Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon64.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents" class="flex justify-center w-[100vw] h-[100vh]">
%sveltekit.body%
</div>
</body>
</html>

7
src/index.test.ts Normal file
View File

@ -0,0 +1,7 @@
import { describe, it, expect } from 'vitest';
describe('sum test', () => {
it('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
});

View File

@ -0,0 +1,9 @@
<script lang="ts">
import '../app.css';
</script>
<slot>
</slot>

108
src/routes/+page.svelte Normal file
View File

@ -0,0 +1,108 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import type { SvelteComponent } from 'svelte';
import { browser } from '$app/environment';
let canvas: HTMLCanvasElement;
let context: CanvasRenderingContext2D;
let isDrawing = false;
let brushSize = 10;
let eraserMode = false;
let canvasWidth = 800; // fallback value
let canvasHeight = 600; // fallback value
let drawColor = "black";
onMount(() => {
if (browser) {
const ctx = canvas.getContext('2d');
if (!ctx) {
throw new Error('Failed to get 2D context');
}
context = ctx;
window.addEventListener("resize", resizeCanvas);
resizeCanvas();
canvas.addEventListener("mousedown", startDrawing);
canvas.addEventListener("mouseup", stopDrawing);
canvas.addEventListener("mousemove", draw);
}
});
onDestroy(() => {
if (browser) {
window.removeEventListener("resize", resizeCanvas);
canvas.removeEventListener("mousedown", startDrawing);
canvas.removeEventListener("mouseup", stopDrawing);
canvas.removeEventListener("mousemove", draw);
}
});
function startDrawing(e: MouseEvent) {
isDrawing = true;
draw(e);
}
function stopDrawing() {
isDrawing = false;
context.beginPath();
}
function draw(e: MouseEvent) {
if (!isDrawing) return;
context.lineWidth = brushSize;
context.lineCap = "round";
context.strokeStyle = drawColor;
context.lineTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
context.stroke();
context.beginPath();
context.moveTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
}
function saveDrawingToFile() {
const dataUrl = canvas.toDataURL('image/png');
const a = document.createElement('a');
a.href = dataUrl;
a.download = 'drawing.png';
a.click();
}
function resizeCanvas() {
if (browser) {
canvasWidth = window.innerWidth;
canvasHeight = window.innerHeight;
}
}
function clearCanvas() {
context.clearRect(0, 0, canvas.width, canvas.height);
}
function setEraser() {
eraserMode = !eraserMode;
drawColor = eraserMode ? 'white' : 'black';
}
</script>
<div class="absolute top-0 left-0 p-4 space-y-2 bg-off-white shadow-lg">
<button class="px-4 py-2 text-sm font-semibold text-blue-dark bg-green-500 rounded hover:bg-green-600" on:click={saveDrawingToFile}>
Save to File
</button>
<button class="px-4 py-2 text-sm font-semibold text-blue-dark bg-red-500 rounded hover:bg-red-600" on:click={clearCanvas}>
Clear Canvas
</button>
<div class="space-y-1">
<p class="text-sm font-semibold">Brush Size</p>
<input type="range" min="1" max="100" bind:value={brushSize} class="w-full cursor-pointer" />
</div>
<div class="space-y-1">
<p class="text-sm font-semibold">Brush Color</p>
<input type="color" bind:value={drawColor} class="w-full cursor-pointer" />
</div>
<button class={`px-4 py-2 text-sm font-semibold rounded ${eraserMode ? 'bg-gray-500 hover:bg-gray-600' : 'bg-blue-500 hover:bg-blue-600'} text-blue-dark`} on:click={setEraser}>
{eraserMode ? 'Drawing Mode' : 'Eraser Mode'}
</button>
</div>
<canvas bind:this={canvas} width={canvasWidth} height={canvasHeight}></canvas>

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
static/favicon64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

23
static/manifest.json Normal file
View File

@ -0,0 +1,23 @@
{
"background_color": "#ffffff",
"description": "A simple whiteboard for drawing and sharing ideas",
"dir": "ltr",
"display": "fullscreen",
"name": "simplewhiteboard",
"orientation": "any",
"scope": "/",
"icons": [
{
"src": "/favicon.png",
"purpose": "any",
"type": "png",
"sizes": "1024x1024"
},
{
"src": "/favicon64.png",
"purpose": "any",
"type": "png",
"sizes": "64x64"
},
]
}

18
svelte.config.js Normal file
View File

@ -0,0 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;

204
tailwind.config.js Normal file
View File

@ -0,0 +1,204 @@
import plugin from 'tailwindcss/plugin';
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./index.html',
'./src/**/*.{html,svelte,js,ts}',
],
theme: {
screens: {
sm: '480px',
md: '768px',
lg: '976px',
xl: '1440px'
},
extend: {
spacing: {
128: '32rem',
144: '36rem'
},
borderRadius: {
'4xl': '2rem'
}
},
colors: {
'primary-yellow': '#FFBF00',
'yellow-secondary': '#FFE066',
'blue-dark': '#110042',
'blue-primary': '#4263EB',
'blue-light': '#96DDFF',
black: '#000000',
white: '#FFFFFF',
'off-white': '#F7F7F7',
'grey-dark': '#8E8E93',
'grey-primary': '#C7C7CC',
'grey-light': '#E5E5EA'
},
fontFamily: {
sans: ['Source Sans Pro', 'sans-serif'],
redacted: ['Redacted Script', 'redacted']
}
},
plugins: [
plugin(function ({ addComponents, addUtilities }) {
addComponents({});
addUtilities({
'.display-1': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '64px',
lineHeight: '72px',
letterSpacing: '-0.25px'
},
'.display-2': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '48px',
lineHeight: '56px'
},
'.display-3': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '40px',
lineHeight: '48px'
},
'.h-2': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '28px',
lineHeight: '36px'
},
'.h-3': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '24px',
lineHeight: '32px'
},
'.title-1': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '24px',
lineHeight: '30px',
letterSpacing: '0.5px'
},
'.title-2': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '16px',
lineHeight: '24px',
letterSpacing: '0.2px'
},
'.title-3': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.16px'
},
'.label-1': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '18px',
lineHeight: '28px',
letterSpacing: '0.2px'
},
'.label-2': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '16px',
lineHeight: '24px',
letterSpacing: '0.4px'
},
'.label-3': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.6px'
},
'.body-1': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '16px',
lineHeight: '24px'
},
'.body-2': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.08px'
},
'.body-3': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '12px',
lineHeight: '16px',
letterSpacing: '0.2px'
},
'.overline': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '12px',
lineHeight: '16px',
letterSpacing: '0.8px',
textTransform: 'uppercase'
},
'.caption': {
fontFamily: 'Source Sans Pro',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '12px',
lineHeight: '16px',
letterSpacing: '0.5px'
},
'.redacted-1': {
fontFamily: 'Redacted Script',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '16px',
lineHeight: '24px'
},
'.redacted-2': {
fontFamily: 'Redacted Script',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.08px'
},
'.redacted-3': {
fontFamily: 'Redacted Script',
fontStyle: 'normal',
fontWeight: 400,
fontSize: '12px',
lineHeight: '16px',
letterSpacing: '0.2px'
}
});
})
],
darkMode: 'class'
};

26
tsconfig.json Normal file
View File

@ -0,0 +1,26 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"useUnknownInCatchVariables": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"preserveValueImports": false,
"noImplicitAny": true,
"noEmitOnError": false,
"ignoreDeprecations": "5.0",
"importsNotUsedAsValues": "preserve"
},
"exclude": ["tests"],
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

12
vite.config.ts Normal file
View File

@ -0,0 +1,12 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
export default defineConfig({
server: {
open: true
},
plugins: [sveltekit()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
}
});