diff --git a/.github/workflows/run_eslint.yml b/.github/workflows/run_eslint.yml index 66fde1d..4da3135 100644 --- a/.github/workflows/run_eslint.yml +++ b/.github/workflows/run_eslint.yml @@ -1,38 +1,47 @@ -name: Linting client code +name: CI on: pull_request: - branches: - - main - - development + branches: [master] push: - branches: - - main - - development + branches: [master] jobs: - run-linters: - name: Run linters + client: + name: Client (lint + build) runs-on: ubuntu-latest - + defaults: + run: + working-directory: ./client steps: - - name: Check out Git repository - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + cache-dependency-path: client/pnpm-lock.yaml + - run: pnpm install --frozen-lockfile + - run: pnpm run lint + - run: pnpm run build - - name: Set up Node.js - uses: actions/setup-node@v1 + server: + name: Server (build) + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./server + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 with: - node-version: 18 - - - uses: pnpm/action-setup@v2 + version: 8 + - uses: actions/setup-node@v4 with: - version: 8 - run_install: | - - recursive: true - args: [--frozen-lockfile, --strict-peer-dependencies] - - args: [--global, gulp, prettier, typescript] - - # ESLint and Prettier must be in `package.json` - - name: Run linters - working-directory: ./client - run : npm run lint \ No newline at end of file + node-version: 20 + cache: pnpm + cache-dependency-path: server/pnpm-lock.yaml + - run: pnpm install --frozen-lockfile + - run: pnpm run build diff --git a/README.md b/README.md index 7267bad..c97d96d 100644 --- a/README.md +++ b/README.md @@ -1 +1,71 @@ -# CollabLab \ No newline at end of file +# CollabLab + +A real-time collaborative whiteboard. Start a board, share the link, and draw together: shapes, freehand ink, +text and live cursors sync instantly between everyone on the board. + +## Features + +- **Live sync**: every create, move, resize, rotate, restyle and delete is broadcast to the board over Socket.IO. +- **Presence**: named, colored cursors and avatars for everyone on the board. +- **Tools**: select, pen, eraser, rectangle, ellipse, triangle, line and text, with colors, stroke widths and fills. +- **Shareable boards**: each board lives at `/board/`; late joiners receive the current drawing. +- **Export**: download the board as a PNG cropped to its content. +- **Optional accounts**: email/password sign-up and sign-in (bcrypt + JWT, stored in Postgres). Without a database, + everyone joins as a named guest. + +Keyboard shortcuts: `1`–`8` pick tools, `Del`/`Backspace` deletes the selection, `Esc` returns to select. + +## Project layout + +``` +client/ React + Vite + fabric.js front end +server/ Express + Socket.IO server (boards in memory, accounts in Postgres) +``` + +## Running locally + +Requires Node 18+ and [pnpm](https://pnpm.io) 8 (`npx pnpm@8 ...` works too). + +```bash +# terminal 1: server on http://localhost:5000 +cd server +pnpm install +pnpm dev + +# terminal 2: client on http://localhost:5173 +cd client +pnpm install +pnpm dev +``` + +Open http://localhost:5173, click **Start a new board**, and open the same board link in a second window to see it sync. + +## Configuration + +**Client** (`client/.env.local`, see `client/.env.example`) + +| Variable | Default | Purpose | +| --- | --- | --- | +| `VITE_SERVER_URL` | `http://localhost:5000` | Where the API and Socket.IO server live | + +**Server** (`server/.env`, see `server/.env.example`) + +| Variable | Default | Purpose | +| --- | --- | --- | +| `PORT` | `5000` | HTTP/WebSocket port | +| `CLIENT_ORIGIN` | any origin | Comma-separated list of allowed browser origins | +| `POSTGRES_URL` | unset | Postgres connection used for accounts | +| `SECRET_KEY` | unset | JWT signing secret; accounts are enabled only when this and `POSTGRES_URL` are set | +| `DATABASE_URL` | unset | Used by `pnpm migrate up` (node-pg-migrate) to create the `users` table | + +To enable accounts: create a Postgres database, set the three variables above in `server/.env`, then run +`pnpm migrate up` in `server/`. + +## Notes + +Boards are stored in server memory and discarded six hours after the last person leaves. A server restart +clears them, though a client that reconnects with a drawing still open re-uploads it. + +## License + +MIT diff --git a/client/.env.example b/client/.env.example new file mode 100644 index 0000000..f816ffd --- /dev/null +++ b/client/.env.example @@ -0,0 +1,2 @@ +# URL of the CollabLab server (API + Socket.IO). Defaults to http://localhost:5000. +VITE_SERVER_URL=http://localhost:5000 diff --git a/client/.prettierignore b/client/.prettierignore index 0bb2c1b..2374062 100644 --- a/client/.prettierignore +++ b/client/.prettierignore @@ -1,3 +1,3 @@ node_modules/ dist/ -.prettierrc.js \ No newline at end of file +pnpm-lock.yaml diff --git a/client/.prettierrc.json b/client/.prettierrc.json new file mode 100644 index 0000000..eb0c1ab --- /dev/null +++ b/client/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "printWidth": 120, + "endOfLine": "auto" +} diff --git a/client/README.md b/client/README.md deleted file mode 100644 index bb15685..0000000 --- a/client/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# React + TypeScript + Vite - -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. - -Currently, two official plugins are available: - -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh - -## Expanding the ESLint configuration - -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: - -- Configure the top-level `parserOptions` property like this: - -```js -export default { - // other rules... - parserOptions: { - ecmaVersion: "latest", - sourceType: "module", - project: ["./tsconfig.json", "./tsconfig.node.json"], - tsconfigRootDir: __dirname, - }, -}; -``` - -- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` -- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list diff --git a/client/index.html b/client/index.html index e4b78ea..65091c5 100644 --- a/client/index.html +++ b/client/index.html @@ -2,9 +2,14 @@ - + - Vite + React + TS + + + CollabLab · Real-time collaborative whiteboard
diff --git a/client/package.json b/client/package.json index 9b31914..aeb9791 100644 --- a/client/package.json +++ b/client/package.json @@ -10,13 +10,15 @@ "preview": "vite preview", "format": "prettier --write ." }, + "engines": { + "node": ">=20" + }, "dependencies": { "fabric": "^5.3.0", - "fabricjs-react": "^1.2.1", - "keycloak-js": "^23.0.3", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-router-dom": "^6.21.1" + "react-router-dom": "^6.21.1", + "socket.io-client": "^4" }, "devDependencies": { "@types/fabric": "^5.3.6", diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index cf9aaf6..38bdb77 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -8,12 +8,6 @@ dependencies: fabric: specifier: ^5.3.0 version: 5.3.0 - fabricjs-react: - specifier: ^1.2.1 - version: 1.2.1 - keycloak-js: - specifier: ^23.0.3 - version: 23.0.3 react: specifier: ^18.2.0 version: 18.2.0 @@ -23,6 +17,9 @@ dependencies: react-router-dom: specifier: ^6.21.1 version: 6.21.1(react-dom@18.2.0)(react@18.2.0) + socket.io-client: + specifier: ^4 + version: 4.8.4 devDependencies: '@types/fabric': @@ -748,6 +745,10 @@ packages: dev: true optional: true + /@socket.io/component-emitter@3.1.2: + resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==} + dev: false + /@tootallnate/once@2.0.0: resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==} engines: {node: '>= 10'} @@ -1091,10 +1092,6 @@ packages: /balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} - /base64-js@1.5.1: - resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - dev: false - /brace-expansion@1.1.11: resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} dependencies: @@ -1278,6 +1275,18 @@ packages: dependencies: ms: 2.1.2 + /debug@4.4.3: + resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.3 + dev: false + /decimal.js@10.4.3: resolution: {integrity: sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==} requiresBuild: true @@ -1351,6 +1360,25 @@ packages: dev: false optional: true + /engine.io-client@6.6.8: + resolution: {integrity: sha512-DPN6+2uNi3A2cbSR3gqJepLVOnSQmbaJT4USgU+TgGPczEqLQT0i6t05jHrf4TT6rcxABrGp/1As0FyqwIZlGg==} + dependencies: + '@socket.io/component-emitter': 3.1.2 + debug: 4.4.3 + engine.io-parser: 5.2.3 + ws: 8.21.3 + xmlhttprequest-ssl: 2.1.2 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + dev: false + + /engine.io-parser@5.2.3: + resolution: {integrity: sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==} + engines: {node: '>=10.0.0'} + dev: false + /esbuild@0.19.10: resolution: {integrity: sha512-S1Y27QGt/snkNYrRcswgRFqZjaTG5a5xM3EQo97uNBnH505pdzSNe/HLBq1v0RO7iK/ngdbhJB6mDAp0OK+iUA==} engines: {node: '>=12'} @@ -1570,19 +1598,6 @@ packages: - utf-8-validate dev: false - /fabricjs-react@1.2.1: - resolution: {integrity: sha512-XlN+U7pXfE5LFjOSSeq/kNTKoMqFwo6OXZ3Q4gFzSB5UxpJiAgvZqyUvstX8Z+pFZKPTrScFOzqIOfXPZNB8RA==} - dependencies: - fabric: 5.3.0 - react: 18.2.0 - react-dom: 18.2.0(react@18.2.0) - transitivePeerDependencies: - - bufferutil - - encoding - - supports-color - - utf-8-validate - dev: false - /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} dev: true @@ -1885,10 +1900,6 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /js-sha256@0.10.1: - resolution: {integrity: sha512-5obBtsz9301ULlsgggLg542s/jqtddfOpV5KJc4hajc9JV8GeY2gZHSVpYBn4nWqAUTJ9v+xwtbJ1mIBgIH5Vw==} - dev: false - /js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -1968,19 +1979,6 @@ packages: hasBin: true dev: true - /jwt-decode@4.0.0: - resolution: {integrity: sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==} - engines: {node: '>=18'} - dev: false - - /keycloak-js@23.0.3: - resolution: {integrity: sha512-T28rdeRgGdOvIUMl6Wo9IiHEGcDxZhUZxXBwk3EwDFWrn8uhWBngDFxdsdsv7qGGKAMKrkZVL2JN/h81sllN7A==} - dependencies: - base64-js: 1.5.1 - js-sha256: 0.10.1 - jwt-decode: 4.0.0 - dev: false - /keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} dependencies: @@ -2112,6 +2110,10 @@ packages: /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} + /ms@2.1.3: + resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + dev: false + /nan@2.18.0: resolution: {integrity: sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==} requiresBuild: true @@ -2489,6 +2491,30 @@ packages: engines: {node: '>=8'} dev: true + /socket.io-client@4.8.4: + resolution: {integrity: sha512-7wjKAvVXYOJsbmUgkWbnhPD4bFpkqrUR0++XOjpGFmqDqsqV1CI93VTraeExLxpjxEqrWgFoSRZu1ihjLWfkAA==} + engines: {node: '>=10.0.0'} + dependencies: + '@socket.io/component-emitter': 3.1.2 + debug: 4.4.3 + engine.io-client: 6.6.8 + socket.io-parser: 4.2.7 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + dev: false + + /socket.io-parser@4.2.7: + resolution: {integrity: sha512-IH/iSeO9T6gz1KkFleGDWkG9N3dl4jXVYUtMhIqH10Md0ttMer8nUNWiP1DKuNrybD2xBrixLJdCC9J6ECoYkg==} + engines: {node: '>=10.0.0'} + dependencies: + '@socket.io/component-emitter': 3.1.2 + debug: 4.4.3 + transitivePeerDependencies: + - supports-color + dev: false + /source-map-js@1.0.2: resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} engines: {node: '>=0.10.0'} @@ -2832,6 +2858,19 @@ packages: dev: false optional: true + /ws@8.21.3: + resolution: {integrity: sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: false + /xml-name-validator@4.0.0: resolution: {integrity: sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==} engines: {node: '>=12'} @@ -2845,6 +2884,11 @@ packages: dev: false optional: true + /xmlhttprequest-ssl@2.1.2: + resolution: {integrity: sha512-TEU+nJVUUnA4CYJFLvK5X9AOeH4KvDvhIfm0vV1GaQRtchnG0hgK5p8hw/xjv8cunWYCsiPCSDzObPyhEwq3KQ==} + engines: {node: '>=0.4.0'} + dev: false + /yallist@3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} dev: true diff --git a/client/prettierrc.json b/client/prettierrc.json deleted file mode 100644 index b0fa4a3..0000000 --- a/client/prettierrc.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "trailingComma": "all", - "tabWidth": 2, - "semi": true, - "singleQuote": true, - "printWidth": 120, - "bracketSpacing": true -} diff --git a/client/public/check-box.png b/client/public/check-box.png deleted file mode 100644 index b0a3f28..0000000 Binary files a/client/public/check-box.png and /dev/null differ diff --git a/client/public/circle.png b/client/public/circle.png deleted file mode 100644 index e51d7d2..0000000 Binary files a/client/public/circle.png and /dev/null differ diff --git a/client/public/clean.png b/client/public/clean.png deleted file mode 100644 index db3cb84..0000000 Binary files a/client/public/clean.png and /dev/null differ diff --git a/client/public/favicon.svg b/client/public/favicon.svg new file mode 100644 index 0000000..c49a0a4 --- /dev/null +++ b/client/public/favicon.svg @@ -0,0 +1 @@ + diff --git a/client/public/pen.png b/client/public/pen.png deleted file mode 100644 index 24e1445..0000000 Binary files a/client/public/pen.png and /dev/null differ diff --git a/client/public/text-box.png b/client/public/text-box.png deleted file mode 100644 index df5ccca..0000000 Binary files a/client/public/text-box.png and /dev/null differ diff --git a/client/public/trash-bin.png b/client/public/trash-bin.png deleted file mode 100644 index 0d1ac9e..0000000 Binary files a/client/public/trash-bin.png and /dev/null differ diff --git a/client/public/triangle.png b/client/public/triangle.png deleted file mode 100644 index 28d609a..0000000 Binary files a/client/public/triangle.png and /dev/null differ diff --git a/client/src/App.css b/client/src/App.css index 1d3710f..2b992c5 100644 --- a/client/src/App.css +++ b/client/src/App.css @@ -1,41 +1,817 @@ -.ToolArray { +/* ---------- shared controls ---------- */ + +.panel { + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius); + box-shadow: var(--shadow); +} + +.btn { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 6px; + height: 40px; + padding: 0 16px; + border-radius: 10px; + border: 1px solid transparent; + font-weight: 600; + font-size: 14px; + text-decoration: none; + white-space: nowrap; + transition: + background 0.15s, + border-color 0.15s, + color 0.15s; +} +.btn--sm { + height: 32px; + padding: 0 12px; + font-size: 13px; + border-radius: 8px; +} +.btn--lg { + height: 48px; + padding: 0 22px; + font-size: 15px; +} +.btn--primary { + background: var(--accent); + color: #fff; +} +.btn--primary:hover:not(:disabled) { + background: var(--accent-hover); +} +.btn--secondary { + background: var(--surface); + border-color: var(--border); +} +.btn--secondary:hover:not(:disabled) { + border-color: #c9c9d3; +} +.btn--ghost { + background: transparent; + color: var(--text); +} +.btn--ghost:hover { + background: #f0f0f4; +} +.btn:disabled { + opacity: 0.5; +} + +.link-btn { + border: 0; + padding: 0; + background: none; + color: var(--accent); + font-weight: 600; +} +.link-btn:hover { + text-decoration: underline; +} + +.input { + height: 40px; + padding: 0 12px; + border: 1px solid var(--border); + border-radius: 10px; + background: var(--surface); + min-width: 0; +} +.input:focus { + outline: none; + border-color: var(--accent); + box-shadow: 0 0 0 3px var(--accent-soft); +} +.input[aria-invalid="true"] { + border-color: var(--danger); +} + +.icon-btn { + display: inline-grid; + place-items: center; + width: 36px; + height: 36px; + border: 0; + border-radius: 8px; + background: transparent; + color: var(--text); +} +.icon-btn:hover { + background: #f0f0f4; +} + +/* Tooltips via data-tip */ +[data-tip] { + position: relative; +} +[data-tip]:hover::after, +[data-tip]:focus-visible::after { + content: attr(data-tip); + position: absolute; + z-index: 50; + white-space: pre; + background: #1c1d22; + color: #fff; + font-size: 12px; + font-weight: 500; + padding: 5px 8px; + border-radius: 6px; + pointer-events: none; +} +.toolbar [data-tip]:hover::after, +.toolbar [data-tip]:focus-visible::after { + left: calc(100% + 10px); + top: 50%; + transform: translateY(-50%); +} +.board-actions [data-tip]:hover::after, +.board-actions [data-tip]:focus-visible::after { + top: calc(100% + 8px); + left: 50%; + transform: translateX(-50%); +} + +/* ---------- landing ---------- */ + +.landing { + min-height: 100vh; display: flex; + flex-direction: column; + background: + radial-gradient(circle at 1px 1px, #d9d9e1 1px, transparent 0) 0 0 / 22px 22px, + var(--bg); +} + +.site-header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 20px clamp(20px, 5vw, 64px); +} + +.brand { + display: inline-flex; + align-items: center; gap: 10px; + font-weight: 700; + font-size: 18px; + text-decoration: none; +} + +.site-nav { + display: flex; + align-items: center; + gap: 16px; + font-size: 14px; +} +.site-nav a { + text-decoration: none; + color: var(--muted); + font-weight: 500; +} +.site-nav a:hover { + color: var(--text); } -html { - background-color: rgb(32, 62, 97); +.hero { + display: grid; + grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); + align-items: center; + gap: clamp(32px, 5vw, 72px); + max-width: 1200px; + width: 100%; + margin: 0 auto; + padding: clamp(24px, 6vh, 72px) clamp(20px, 5vw, 64px); +} + +.eyebrow { + display: inline-block; + padding: 5px 12px; + border-radius: 999px; + background: var(--accent-soft); + color: var(--accent); + font-size: 13px; + font-weight: 600; +} + +.hero h1 { + margin-top: 18px; + font-size: clamp(38px, 5.4vw, 64px); + line-height: 1.04; + letter-spacing: -0.03em; +} +.hl { + color: var(--accent); + background: linear-gradient(transparent 62%, #ffb22455 62%); +} + +.lede { + margin-top: 18px; + max-width: 34em; + font-size: 18px; + line-height: 1.55; + color: var(--muted); +} + +.hero-actions { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12px; + margin-top: 32px; +} + +.join-form { + display: flex; + gap: 8px; +} +.join-form .input { + height: 48px; + width: 220px; +} +.join-form .btn { + height: 48px; +} + +.form-error { + margin-top: 10px; + color: var(--danger); + font-size: 14px; +} + +.hero-art { + background: var(--surface); + border: 1px solid var(--border); + border-radius: 20px; + box-shadow: var(--shadow); + padding: 12px; +} +.hero-svg { + display: block; + width: 100%; + height: auto; +} +.art-text { + font: 600 20px var(--font); + fill: var(--text); +} +.art-label { + font: 600 11px var(--font); + fill: #fff; +} +.art-cursor--a { + animation: drift-a 7s ease-in-out infinite; +} +.art-cursor--b { + animation: drift-b 6s ease-in-out infinite; +} +.art-draw { + stroke-dasharray: 90; + animation: draw 6s ease-in-out infinite; +} +@keyframes drift-a { + 0%, + 100% { + transform: translate(220px, 170px); + } + 50% { + transform: translate(150px, 210px); + } +} +@keyframes drift-b { + 0%, + 100% { + transform: translate(358px, 246px); + } + 50% { + transform: translate(418px, 288px); + } +} +@keyframes draw { + 0%, + 10% { + stroke-dashoffset: 90; + } + 50%, + 100% { + stroke-dashoffset: 0; + } +} +@media (prefers-reduced-motion: reduce) { + .art-cursor--a, + .art-cursor--b, + .art-draw { + animation: none; + } + .art-cursor--a { + transform: translate(220px, 170px); + } + .art-cursor--b { + transform: translate(418px, 288px); + } +} + +.features { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 16px; + max-width: 1200px; + width: 100%; + margin: 0 auto; + padding: 8px clamp(20px, 5vw, 64px) 48px; +} +.feature { + padding: 20px; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius); +} +.feature h3 { + font-size: 15px; + margin-bottom: 6px; +} +.feature p { + font-size: 14px; + line-height: 1.5; +} + +.site-footer { + margin-top: auto; + padding: 24px; + text-align: center; + font-size: 13px; +} + +@media (max-width: 900px) { + .hero { + grid-template-columns: 1fr; + } + .features { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } +} +@media (max-width: 520px) { + .features { + grid-template-columns: 1fr; + } + .join-form, + .join-form .input { + width: 100%; + } +} + +/* ---------- board ---------- */ + +.board { + position: fixed; + inset: 0; overflow: hidden; + background: + radial-gradient(circle at 1px 1px, #d4d4dc 1px, transparent 0) 0 0 / 24px 24px, + #fafafb; + user-select: none; +} + +.board-canvas { + position: absolute; + inset: 0; +} + +.cursors { + position: absolute; + inset: 0; + pointer-events: none; + overflow: hidden; + z-index: 5; +} +.cursor { + position: absolute; + top: 0; + left: 0; + transition: transform 60ms linear; +} +.cursor svg { + display: block; +} +.cursor-label { + display: inline-block; + margin: 2px 0 0 12px; + padding: 2px 7px; + border-radius: 6px; + color: #fff; + font-size: 12px; + font-weight: 600; + white-space: nowrap; } -#Main-canvas { - background-color: white; +.board-header { + position: absolute; + top: 12px; + left: 12px; + right: 12px; + display: flex; + justify-content: space-between; + align-items: flex-start; + gap: 12px; + pointer-events: none; + z-index: 10; } -#Main { +.board-header > * { + pointer-events: auto; +} + +.board-title, +.board-actions { + display: flex; + align-items: center; + gap: 10px; + padding: 6px 8px 6px 10px; + min-height: 48px; +} + +.brand-link { + display: inline-flex; +} + +.board-meta { display: flex; flex-direction: column; - gap: 20px; - padding: 1%; + line-height: 1.15; +} +.board-name { + font-size: 11px; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.05em; + color: var(--muted); +} +.board-code { + font-size: 13px; + font-weight: 600; + user-select: all; +} + +.status { + display: inline-flex; align-items: center; + gap: 6px; + padding: 3px 9px; + border-radius: 999px; + background: #f0f0f4; + font-size: 12px; + font-weight: 600; + color: var(--muted); +} +.status-dot { + width: 7px; + height: 7px; + border-radius: 50%; + background: currentColor; +} +.status--connected { + background: #e9f6ef; + color: #18794e; +} +.status--reconnecting, +.status--connecting { + background: #fff6e5; + color: #ad5700; +} +.status--offline { + background: var(--danger-soft); + color: #ce2c31; } -#Brush-size { - accent-color: black; +.avatars { + display: flex; + padding-left: 6px; +} +.avatar { + display: inline-grid; + place-items: center; + width: 30px; + height: 30px; + margin-left: -6px; + border-radius: 50%; + border: 2px solid var(--surface); + color: #fff; + font-size: 11px; + font-weight: 700; +} +.avatar--more { + background: #e4e4ea; + color: var(--muted); } -#Brush-color { - margin-top: 6px; +/* left toolbar */ +.toolbar { + position: absolute; + left: 12px; + top: 50%; + transform: translateY(-50%); + display: flex; + flex-direction: column; + gap: 2px; + padding: 6px; + z-index: 10; +} +.tool-btn { + display: grid; + place-items: center; + width: 40px; + height: 40px; + border: 0; + border-radius: 9px; + background: transparent; + color: #3b3d45; + transition: + background 0.12s, + color 0.12s; +} +.tool-btn:hover { + background: #f0f0f4; +} +.tool-btn.is-active { + background: var(--accent-soft); + color: var(--accent); +} +.tool-btn--danger:hover, +.tool-btn--danger.is-confirming { + background: var(--danger-soft); + color: var(--danger); +} +.toolbar-divider { + height: 1px; + margin: 4px 6px; + background: var(--border); } -#Navbar { +/* bottom style panel */ +.style-panel { + position: absolute; + left: 50%; + bottom: 16px; + transform: translateX(-50%); display: flex; - justify-content: space-between; - padding-left: 10px; - padding-right: 10px; - color: white; + align-items: center; + gap: 10px; + padding: 8px 12px; + z-index: 10; + max-width: calc(100vw - 24px); + overflow-x: auto; +} +.style-group { + display: flex; + align-items: center; + gap: 4px; +} +.style-divider { + align-self: stretch; + width: 1px; + background: var(--border); } -a { - color: white; - text-decoration: none; +.swatch { + position: relative; + width: 26px; + height: 26px; + padding: 0; + border: 0; + border-radius: 50%; + background: var(--swatch); + box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); + flex: none; + cursor: pointer; +} +.swatch.is-active { + box-shadow: + 0 0 0 2px var(--surface), + 0 0 0 4px var(--accent); +} +.swatch--custom { + background: conic-gradient(#e5484d, #ffb224, #30a46c, #0090ff, #6e56cf, #d6409f, #e5484d) border-box; + overflow: hidden; +} +.swatch--custom::after { + content: ""; + position: absolute; + inset: 6px; + border-radius: 50%; + background: var(--swatch); +} +.swatch--custom input { + position: absolute; + inset: 0; + opacity: 0; + cursor: pointer; +} + +.chip { + display: grid; + place-items: center; + width: 32px; + height: 32px; + border: 1px solid transparent; + border-radius: 8px; + background: transparent; + color: var(--text); +} +.chip:hover { + background: #f0f0f4; +} +.chip.is-active { + background: var(--accent-soft); + border-color: #c7c9ff; +} +.chip--danger { + color: var(--danger); +} +.chip--danger:hover { + background: var(--danger-soft); +} + +.width-dot { + display: block; + border-radius: 50%; + background: var(--text); +} + +.fill-preview { + width: 18px; + height: 18px; + border-radius: 4px; + border: 2px solid var(--swatch); +} +.fill-preview--tint { + background: color-mix(in srgb, var(--swatch) 22%, transparent); +} +.fill-preview--solid { + background: var(--swatch); +} + +/* banners & toasts */ +.banner { + position: absolute; + top: 72px; + left: 50%; + transform: translateX(-50%); + max-width: min(640px, calc(100vw - 24px)); + padding: 10px 14px; + border-radius: 10px; + background: #fff6e5; + border: 1px solid #ffdc9c; + color: #7a3e00; + font-size: 14px; + line-height: 1.45; + z-index: 20; + user-select: text; +} +.banner--error { + background: var(--danger-soft); + border-color: #f9c6c6; + color: #9a1c20; +} + +.toast { + position: absolute; + bottom: 80px; + left: 50%; + transform: translateX(-50%); + padding: 9px 14px; + border-radius: 10px; + background: #1c1d22; + color: #fff; + font-size: 14px; + z-index: 20; + animation: toast-in 0.2s ease-out; +} +@keyframes toast-in { + from { + opacity: 0; + transform: translate(-50%, 8px); + } +} + +/* dialog */ +.dialog-backdrop { + position: fixed; + inset: 0; + display: grid; + place-items: center; + padding: 20px; + background: rgba(22, 23, 30, 0.35); + backdrop-filter: blur(3px); + z-index: 100; +} +.dialog { + display: flex; + flex-direction: column; + gap: 12px; + width: min(400px, 100%); + padding: 28px; + user-select: text; +} +.dialog h2 { + font-size: 20px; + margin-top: 4px; +} +.dialog p { + font-size: 14px; + line-height: 1.5; +} +.dialog-actions { + display: flex; + justify-content: flex-end; + gap: 8px; + margin-top: 4px; +} +.dialog-alt { + color: var(--muted); + text-align: center; +} + +/* 404 */ +.not-found { + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 14px; + padding: 24px; + text-align: center; +} +.not-found h1 { + font-size: 28px; +} + +@media (max-width: 640px) { + .board-meta, + .board-actions .btn--ghost { + display: none; + } + .toolbar { + top: 72px; + transform: none; + } +} + +/* ---------- auth pages ---------- */ + +.auth-page { + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 24px; + padding: 32px 20px; + background: + radial-gradient(circle at 1px 1px, #d9d9e1 1px, transparent 0) 0 0 / 22px 22px, + var(--bg); +} +.auth-card { + display: flex; + flex-direction: column; + gap: 14px; + width: min(400px, 100%); + padding: 32px; +} +.auth-card h1 { + font-size: 24px; + letter-spacing: -0.02em; +} +.auth-card > p { + font-size: 14px; + line-height: 1.5; +} +.auth-card .btn { + margin-top: 4px; +} +.auth-card .form-error { + margin: 0; +} +.field { + display: flex; + flex-direction: column; + gap: 6px; + font-size: 13px; + font-weight: 600; +} +.auth-switch { + text-align: center; + font-size: 14px; +} +.auth-switch a, +.banner a { + color: var(--accent); + font-weight: 600; +} +.banner--inline { + position: static; + transform: none; + max-width: none; } diff --git a/client/src/App.tsx b/client/src/App.tsx index 7f92324..d874290 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,36 +1,34 @@ -import Keycloak from "keycloak-js"; -import "./App.css"; -import { createBrowserRouter, RouterProvider } from "react-router-dom"; -import Whiteboard from "./pages/Whiteboard"; +import { useState } from "react"; +import { Navigate, RouterProvider, createBrowserRouter } from "react-router-dom"; +import AuthProvider from "./lib/AuthProvider"; +import { newBoardId } from "./lib/ids"; +import AuthPage from "./pages/AuthPage"; +import BoardPage from "./pages/BoardPage"; import LandingPage from "./pages/LandingPage"; +import NotFound from "./pages/NotFound"; +import "./App.css"; -const keycloak = new Keycloak({ - url: "http://localhost:8180", - realm: "test", - clientId: "ashmit", -}); +function NewBoard() { + const [id] = useState(newBoardId); + return ; +} const router = createBrowserRouter([ - { - errorElement:
PAGE NOT FOUND, 404
, - }, - { - path: "/whiteboard", - element: , - }, - { - path: "/", - element: , - }, + { path: "/", element: , errorElement: }, + { path: "/board/:roomId", element: , errorElement: }, + // Old links pointed at a single shared /whiteboard page; give them a fresh board instead. + { path: "/whiteboard", element: }, + { path: "/signin", element: }, + { path: "/signup", element: }, + // Old development-branch route for the signed-in home page. + { path: "/mainpage", element: }, + { path: "*", element: }, ]); -const user = keycloak.init({ onLoad: "login-required" }); - -function App() { - user.then((_data) => { - console.log(JSON.parse(JSON.stringify(keycloak.idTokenParsed))); - }); - return ; +export default function App() { + return ( + + + + ); } - -export default App; diff --git a/client/src/board/shapes.ts b/client/src/board/shapes.ts new file mode 100644 index 0000000..2e0e1a7 --- /dev/null +++ b/client/src/board/shapes.ts @@ -0,0 +1,117 @@ +import { fabric } from "fabric"; +import { newObjectId } from "../lib/ids"; +import type { BoardObject } from "../lib/protocol"; + +export type Tool = "select" | "pen" | "eraser" | "rect" | "ellipse" | "triangle" | "line" | "text"; +export type ShapeTool = "rect" | "ellipse" | "triangle" | "line"; +export type FillMode = "none" | "tint" | "solid"; + +export interface Style { + stroke: string; + fill: FillMode; + width: number; +} + +export const SHAPE_TOOLS: readonly Tool[] = ["rect", "ellipse", "triangle", "line"]; +export const isShapeTool = (tool: Tool): tool is ShapeTool => SHAPE_TOOLS.includes(tool); + +export const FONT_FAMILY = "ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif"; + +type WithId = fabric.Object & { id?: string }; + +export function getId(obj: fabric.Object): string | undefined { + return (obj as WithId).id; +} + +export function setId(obj: fabric.Object, id = newObjectId()) { + (obj as WithId).id = id; + return id; +} + +export function serialize(obj: fabric.Object): BoardObject { + return obj.toObject(["id"]) as BoardObject; +} + +export function fillColor(style: Style) { + if (style.fill === "solid") return style.stroke; + if (style.fill === "tint") return `${style.stroke}2e`; // ~18% alpha + return "transparent"; +} + +const common: fabric.IObjectOptions = { + strokeUniform: true, + strokeLineJoin: "round", + strokeLineCap: "round", + objectCaching: false, +}; + +export function createShape(tool: ShapeTool, x: number, y: number, style: Style): fabric.Object { + const base = { ...common, left: x, top: y, stroke: style.stroke, strokeWidth: style.width }; + let obj: fabric.Object; + switch (tool) { + case "rect": + obj = new fabric.Rect({ ...base, width: 0, height: 0, rx: 6, ry: 6, fill: fillColor(style) }); + break; + case "ellipse": + obj = new fabric.Ellipse({ ...base, rx: 0, ry: 0, fill: fillColor(style) }); + break; + case "triangle": + obj = new fabric.Triangle({ ...base, width: 0, height: 0, fill: fillColor(style) }); + break; + case "line": + obj = new fabric.Line([x, y, x, y], { ...base, fill: style.stroke, padding: 6 }); + break; + } + setId(obj); + return obj; +} + +/** Resizes a shape that is being dragged out from (x0, y0) to (x, y). */ +export function resizeShape(obj: fabric.Object, tool: ShapeTool, x0: number, y0: number, x: number, y: number) { + if (tool === "line") { + obj.set({ x2: x, y2: y } as Partial); + } else { + const left = Math.min(x0, x); + const top = Math.min(y0, y); + const width = Math.abs(x - x0); + const height = Math.abs(y - y0); + if (tool === "ellipse") { + obj.set({ left, top, rx: width / 2, ry: height / 2 } as Partial); + } else { + obj.set({ left, top, width, height }); + } + } + obj.setCoords(); +} + +/** Turns a click (no drag) into a reasonably sized default shape. */ +export function applyDefaultSize(obj: fabric.Object, tool: ShapeTool, x: number, y: number) { + if (tool === "line") resizeShape(obj, tool, x, y, x + 160, y); + else resizeShape(obj, tool, x - 70, y - 50, x + 70, y + 50); +} + +export function createText(x: number, y: number, style: Style) { + const text = new fabric.Textbox("", { + left: x, + top: y - 14, + width: 220, + fontSize: 24, + fontFamily: FONT_FAMILY, + fill: style.stroke, + objectCaching: false, + }); + setId(text); + return text; +} + +/** Applies a style to an existing object, respecting what each object type supports. */ +export function applyStyle(obj: fabric.Object, style: Style) { + if (obj.type === "textbox" || obj.type === "i-text" || obj.type === "text") { + obj.set({ fill: style.stroke }); + } else if (obj.type === "path" || obj.type === "line") { + obj.set({ stroke: style.stroke, strokeWidth: style.width }); + if (obj.type === "line") obj.set({ fill: style.stroke }); + } else { + obj.set({ stroke: style.stroke, strokeWidth: style.width, fill: fillColor(style) }); + } +} diff --git a/client/src/board/useBoard.ts b/client/src/board/useBoard.ts new file mode 100644 index 0000000..b621a8a --- /dev/null +++ b/client/src/board/useBoard.ts @@ -0,0 +1,491 @@ +import { fabric } from "fabric"; +import { useCallback, useEffect, useRef, useState } from "react"; +import type { BoardObject, Peer } from "../lib/protocol"; +import { BoardSocket, createSocket, throttle } from "../lib/socket"; +import { + ShapeTool, + Style, + Tool, + applyDefaultSize, + applyStyle, + createShape, + createText, + getId, + isShapeTool, + resizeShape, + serialize, + setId, +} from "./shapes"; + +export type ConnectionStatus = "connecting" | "connected" | "reconnecting" | "offline"; +export type Cursor = { x: number; y: number }; + +const DEFAULT_STYLE: Style = { stroke: "#1f2937", fill: "none", width: 4 }; + +/** + * Owns the fabric.js canvas and its real-time sync with the CollabLab server. + * Every object carries a stable `id`; local changes are sent as serialized objects, + * and remote changes are applied by id. + */ +export function useBoard(roomId: string, name: string | null, token: string | null = null) { + const hostRef = useRef(null); + const canvasRef = useRef(null); + const socketRef = useRef(null); + const toolRef = useRef("select"); + const styleRef = useRef