commit f1d0991a77e15bfb87b26ea667e096daf4f023c6 Author: ulve Date: Tue Mar 24 08:14:57 2026 +0100 Initial implementation of temporal progress page Seven particle-based progress cards (hour, day, week, month, year, summer, fall) with work-time mode toggle and bridge days support. Light elegant design with accumulating particle animation. Express server proxies dagsmart.se API. diff --git a/.claude/skills/robert/SKILL.md b/.claude/skills/robert/SKILL.md new file mode 100644 index 0000000..edb6bfd --- /dev/null +++ b/.claude/skills/robert/SKILL.md @@ -0,0 +1,8 @@ +--- +name: robert +description: Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "Robert". +--- + +Interview me relentlessly about every aspect of this plan until we reach a shared understanding. Walk down each branch of the design tree, resolving dependencies between decisions one-by-one. + +If a question can be answered by exploring the codebase, explore the codebase instead. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/PLAN.md b/PLAN.md new file mode 100644 index 0000000..0541a17 --- /dev/null +++ b/PLAN.md @@ -0,0 +1,58 @@ +# Aftersummer — Design Plan + +## Concept +A single-page web app showing temporal progress across multiple scales, with an optional work-time mode. Elegant, light, particle-based visuals. + +## Visual Design +- Light warm background (#f7f6f2) +- Particle accumulation: dark particles fill each card as time passes +- Elegant sans-serif typography (Inter) +- No raw percentages — contextual labels only ("42m remaining", "3 working days till summer") + +## Cards (7 total, stacked to fill viewport) +| Card | Normal mode | Work mode | +|---------|---------------------------------|----------------------------------------| +| Hour | 0–59 min of current hour | Same — inactive outside work hours | +| Day | 00:00–23:59 | 08:00–12:00 + 13:00–17:00 (8h) | +| Week | Mon 00:00 – Sun 23:59 | Mon–Fri, work hours only | +| Month | Calendar days | Working days in month | +| Year | Calendar days | Working days in year | +| Summer | Jan 1 → Midsommarafton progress | Working days — special state in summer | +| Fall | 1st Mon Aug → Dec 31 progress | Working days | + +## Card States +- **active**: dark particles accumulating +- **not-work-time**: muted grey particles, greyed label (outside work hours/days) +- **summer**: warm amber particles at 100% (Midsommarafton → 1st Mon Aug) +- **off-season**: cool grey-blue particles at 0% (fall card before fall starts) + +## Work Rules +- Hours: 08:00–12:00 + 13:00–17:00 (8 effective hours, lunch excluded) +- Days: Mon–Fri +- July: entirely off (covered by summer period) +- Holidays: from dagsmart.se API +- Bridge days: optional (separate toggle) + +## Summer / Fall Periods +- **Summer**: Midsommarafton (from API) → first Monday of August +- **Pre-summer**: Jan 1 → Midsommarafton +- **Fall**: first Monday of August → Dec 31 + +## API +- **Base URL**: `https://api.dagsmart.se` +- `GET /holidays?year=YEAR&weekends=false` → `[{ date, code, name: {en, sv} }]` + - Note: returns holidays that fall on weekends too (e.g. Easter Saturday) — must check weekends separately + - Midsommarafton code: `midsummerEve` +- `GET /bridge-days?year=YEAR` → `[{ date }]` (no code/name) +- Cached in localStorage per year, refreshed if stale (different year) +- Proxied through local server to avoid CORS + +## UI Controls +- **Work time** toggle: switches all cards to work-mode calculations +- **Bridge days** toggle: visible only when work mode is on; treats bridge days as non-work + +## Stack +- Vanilla JS (ES modules), no framework, no build step +- Single `public/index.html` + `public/style.css` + `public/app.js` +- Node.js + Express server: serves static files + proxies API calls +- `npm start` to run diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..aed932b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,827 @@ +{ + "name": "aftersummer", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "aftersummer", + "version": "1.0.0", + "dependencies": { + "express": "^4.18.2" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/body-parser": { + "version": "1.20.4", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", + "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.14.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz", + "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.3", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.14.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.14.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz", + "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..283e0d5 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "aftersummer", + "version": "1.0.0", + "type": "module", + "scripts": { + "start": "node server.js" + }, + "dependencies": { + "express": "^4.18.2" + } +} diff --git a/public/app.js b/public/app.js new file mode 100644 index 0000000..b03f681 --- /dev/null +++ b/public/app.js @@ -0,0 +1,554 @@ +// ───────────────────────────────────────────────────────────────────────────── +// Constants +// ───────────────────────────────────────────────────────────────────────────── + +const WORK_START = 8 * 60; // 08:00 in minutes from midnight +const LUNCH_START = 12 * 60; // 12:00 +const LUNCH_END = 13 * 60; // 13:00 +const WORK_END = 17 * 60; // 17:00 +const WORK_MINUTES = 8 * 60; // 480 min = 8 effective hours + +const CARDS = [ + { id: 'hour', label: 'Hour' }, + { id: 'day', label: 'Day' }, + { id: 'week', label: 'Week' }, + { id: 'month', label: 'Month' }, + { id: 'year', label: 'Year' }, + { id: 'summer', label: 'Summer' }, + { id: 'fall', label: 'Fall' }, +]; + +const PARTICLE_COLORS = { + active: [26, 26, 46 ], + 'not-work-time': [185, 180, 172], + summer: [196, 144, 42 ], + 'off-season': [160, 168, 184], +}; + +// ───────────────────────────────────────────────────────────────────────────── +// App State +// ───────────────────────────────────────────────────────────────────────────── + +const state = { + workMode: false, + includeBridgeDays: false, + holidaySet: new Set(), + bridgeDaySet: new Set(), + midsommar: null, // Date of midsommarafton + fallStart: null, // Date of first Monday of August + loaded: false, +}; + +// ───────────────────────────────────────────────────────────────────────────── +// Date Utilities +// ───────────────────────────────────────────────────────────────────────────── + +function formatDate(date) { + const y = date.getFullYear(); + const m = String(date.getMonth() + 1).padStart(2, '0'); + const d = String(date.getDate()).padStart(2, '0'); + return `${y}-${m}-${d}`; +} + +function startOfDay(date) { + const d = new Date(date); + d.setHours(0, 0, 0, 0); + return d; +} + +function firstMondayOfAugust(year) { + const d = new Date(year, 7, 1); // Aug 1 + const day = d.getDay(); // 0=Sun, 1=Mon, ... + const offset = day === 1 ? 0 : (8 - day) % 7; + return new Date(year, 7, 1 + offset); +} + +function seededRandom(seed) { + const x = Math.sin(seed + 1) * 10000; + return x - Math.floor(x); +} + +// ───────────────────────────────────────────────────────────────────────────── +// Work Time Utilities +// ───────────────────────────────────────────────────────────────────────────── + +function isWeekend(date) { + const d = date.getDay(); + return d === 0 || d === 6; +} + +function isJuly(date) { + return date.getMonth() === 6; +} + +function isWorkDay(date) { + if (isWeekend(date)) return false; + if (isJuly(date)) return false; + const ds = formatDate(date); + if (state.holidaySet.has(ds)) return false; + if (state.includeBridgeDays && state.bridgeDaySet.has(ds)) return false; + return true; +} + +// Returns elapsed work minutes today (0 to WORK_MINUTES) +function elapsedWorkMinutesToday(now) { + const mins = now.getHours() * 60 + now.getMinutes() + now.getSeconds() / 60; + if (mins < WORK_START) return 0; + if (mins >= WORK_END) return WORK_MINUTES; + if (mins >= LUNCH_START && mins < LUNCH_END) return LUNCH_START - WORK_START; + if (mins < LUNCH_START) return mins - WORK_START; + return (LUNCH_START - WORK_START) + (mins - LUNCH_END); +} + +function isCurrentlyWorkTime(now) { + if (!isWorkDay(now)) return false; + const mins = now.getHours() * 60 + now.getMinutes(); + if (mins < WORK_START || mins >= WORK_END) return false; + if (mins >= LUNCH_START && mins < LUNCH_END) return false; + return true; +} + +// Count work days in [start, end) — start inclusive, end exclusive +function countWorkDays(start, end) { + let count = 0; + const d = startOfDay(start); + const e = startOfDay(end); + while (d < e) { + if (isWorkDay(d)) count++; + d.setDate(d.getDate() + 1); + } + return count; +} + +// ───────────────────────────────────────────────────────────────────────────── +// Label Formatting +// ───────────────────────────────────────────────────────────────────────────── + +function fmtMinutes(min) { + const h = Math.floor(min / 60); + const m = Math.ceil(min % 60); + if (h === 0) return `${m}m`; + if (m === 0) return `${h}h`; + return `${h}h ${m}m`; +} + +function fmtDays(n, prefix = '', suffix = 'remaining') { + const d = n === 1 ? 'day' : 'days'; + return [prefix, `${n}`, d, suffix].filter(Boolean).join(' '); +} + +function fmtWorkDays(n, prefix = '', suffix = 'remaining') { + const d = n === 1 ? 'working day' : 'working days'; + return [prefix, `${n}`, d, suffix].filter(Boolean).join(' '); +} + +// ───────────────────────────────────────────────────────────────────────────── +// Progress Calculations +// Each returns { progress: 0–1, remainingLabel: string, cardState: string } +// cardState: 'active' | 'not-work-time' | 'summer' | 'off-season' +// ───────────────────────────────────────────────────────────────────────────── + +function getHourState(now) { + if (state.workMode && !isCurrentlyWorkTime(now)) { + const msg = isWorkDay(now) ? 'outside work hours' : 'not a work day'; + return { progress: 0, remainingLabel: msg, cardState: 'not-work-time' }; + } + const mins = now.getMinutes() + now.getSeconds() / 60; + const remaining = Math.ceil(60 - mins); + return { progress: mins / 60, remainingLabel: `${remaining}m remaining`, cardState: 'active' }; +} + +function getDayState(now) { + if (state.workMode) { + if (!isWorkDay(now)) { + return { progress: 0, remainingLabel: 'not a work day', cardState: 'not-work-time' }; + } + const mins = now.getHours() * 60 + now.getMinutes(); + if (mins < WORK_START) { + return { progress: 0, remainingLabel: 'work starts at 08:00', cardState: 'not-work-time' }; + } + if (mins >= LUNCH_START && mins < LUNCH_END) { + return { progress: (LUNCH_START - WORK_START) / WORK_MINUTES, remainingLabel: 'lunch break', cardState: 'not-work-time' }; + } + if (mins >= WORK_END) { + return { progress: 1, remainingLabel: 'work day done', cardState: 'not-work-time' }; + } + const elapsed = elapsedWorkMinutesToday(now); + const remaining = WORK_MINUTES - elapsed; + return { progress: elapsed / WORK_MINUTES, remainingLabel: fmtMinutes(remaining) + ' remaining', cardState: 'active' }; + } + const secs = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds(); + const remainSecs = 86400 - secs; + return { progress: secs / 86400, remainingLabel: fmtMinutes(remainSecs / 60) + ' remaining', cardState: 'active' }; +} + +function getWeekState(now) { + const dow = (now.getDay() + 6) % 7; // 0=Mon, 6=Sun + const monday = startOfDay(now); + monday.setDate(monday.getDate() - dow); + const nextMonday = new Date(monday); + nextMonday.setDate(monday.getDate() + 7); + + if (state.workMode) { + const friday = new Date(monday); + friday.setDate(monday.getDate() + 5); // exclusive end (Sat) + const totalWork = countWorkDays(monday, friday); + if (totalWork === 0) { + return { progress: 0, remainingLabel: 'no work days this week', cardState: 'not-work-time' }; + } + let elapsed = countWorkDays(monday, startOfDay(now)); + if (isWorkDay(now)) elapsed += elapsedWorkMinutesToday(now) / WORK_MINUTES; + const progress = Math.min(1, elapsed / totalWork); + const remaining = Math.ceil(totalWork - elapsed); + const label = remaining <= 0 ? 'week done' : fmtWorkDays(remaining); + return { progress, remainingLabel: label, cardState: 'active' }; + } + + const progress = (now - monday) / (nextMonday - monday); + const remainMs = nextMonday - now; + const remainDays = Math.ceil(remainMs / 86400000); + return { progress, remainingLabel: fmtDays(remainDays), cardState: 'active' }; +} + +function getMonthState(now) { + const year = now.getFullYear(); + const month = now.getMonth(); + const firstDay = new Date(year, month, 1); + const firstNextMonth = new Date(year, month + 1, 1); + + if (state.workMode) { + const totalWork = countWorkDays(firstDay, firstNextMonth); + if (totalWork === 0) { + return { progress: 1, remainingLabel: 'no work days this month', cardState: 'not-work-time' }; + } + let elapsed = countWorkDays(firstDay, startOfDay(now)); + if (isWorkDay(now)) elapsed += elapsedWorkMinutesToday(now) / WORK_MINUTES; + const progress = Math.min(1, elapsed / totalWork); + const remaining = Math.ceil(totalWork - elapsed); + const label = remaining <= 0 ? 'month done' : fmtWorkDays(remaining); + return { progress, remainingLabel: label, cardState: 'active' }; + } + + const progress = (now - firstDay) / (firstNextMonth - firstDay); + const remainDays = Math.ceil((firstNextMonth - now) / 86400000); + return { progress, remainingLabel: fmtDays(remainDays), cardState: 'active' }; +} + +function getYearState(now) { + const year = now.getFullYear(); + const firstDay = new Date(year, 0, 1); + const firstNextYear = new Date(year + 1, 0, 1); + + if (state.workMode) { + const totalWork = countWorkDays(firstDay, firstNextYear); + let elapsed = countWorkDays(firstDay, startOfDay(now)); + if (isWorkDay(now)) elapsed += elapsedWorkMinutesToday(now) / WORK_MINUTES; + const progress = Math.min(1, elapsed / totalWork); + const remaining = Math.ceil(totalWork - elapsed); + const label = remaining <= 0 ? 'year done' : fmtWorkDays(remaining); + return { progress, remainingLabel: label, cardState: 'active' }; + } + + const progress = (now - firstDay) / (firstNextYear - firstDay); + const remainDays = Math.ceil((firstNextYear - now) / 86400000); + return { progress, remainingLabel: fmtDays(remainDays), cardState: 'active' }; +} + +function getSummerState(now) { + const { midsommar, fallStart } = state; + if (!midsommar || !fallStart) return { progress: 0, remainingLabel: '…', cardState: 'active' }; + + const year = now.getFullYear(); + const janFirst = new Date(year, 0, 1); + + // Currently summer + if (now >= midsommar && now < fallStart) { + const backDate = fallStart.toLocaleDateString('sv-SE', { month: 'short', day: 'numeric' }); + return { progress: 1, remainingLabel: `back ${backDate}`, cardState: 'summer' }; + } + + // Pre-summer (before midsommar) + if (now < midsommar) { + if (state.workMode) { + const totalWork = countWorkDays(janFirst, midsommar); + let elapsed = countWorkDays(janFirst, startOfDay(now)); + if (isWorkDay(now)) elapsed += elapsedWorkMinutesToday(now) / WORK_MINUTES; + const progress = totalWork > 0 ? Math.min(1, elapsed / totalWork) : 0; + const remaining = Math.ceil(totalWork - elapsed); + const label = remaining <= 0 ? 'summer soon!' : fmtWorkDays(remaining, '', 'till summer'); + return { progress, remainingLabel: label, cardState: 'active' }; + } + const progress = (now - janFirst) / (midsommar - janFirst); + const remainDays = Math.ceil((midsommar - now) / 86400000); + return { progress, remainingLabel: fmtDays(remainDays, '', 'till summer'), cardState: 'active' }; + } + + // After summer (fall/end of year) — point to next year's summer + const nextYearStart = new Date(year + 1, 0, 1); + const remainDays = Math.ceil((nextYearStart - now) / 86400000); + return { progress: 1, remainingLabel: fmtDays(remainDays, '', 'till new year'), cardState: 'off-season' }; +} + +function getFallState(now) { + const { fallStart } = state; + if (!fallStart) return { progress: 0, remainingLabel: '…', cardState: 'off-season' }; + + const year = now.getFullYear(); + const yearEnd = new Date(year + 1, 0, 1); + + if (now < fallStart) { + const remainDays = Math.ceil((fallStart - now) / 86400000); + return { progress: 0, remainingLabel: fmtDays(remainDays, '', 'till fall'), cardState: 'off-season' }; + } + + if (state.workMode) { + const totalWork = countWorkDays(fallStart, yearEnd); + let elapsed = countWorkDays(fallStart, startOfDay(now)); + if (isWorkDay(now)) elapsed += elapsedWorkMinutesToday(now) / WORK_MINUTES; + const progress = totalWork > 0 ? Math.min(1, elapsed / totalWork) : 0; + const remaining = Math.ceil(totalWork - elapsed); + const label = remaining <= 0 ? 'year done!' : fmtWorkDays(remaining); + return { progress, remainingLabel: label, cardState: 'active' }; + } + + const progress = Math.min(1, (now - fallStart) / (yearEnd - fallStart)); + const remainDays = Math.ceil((yearEnd - now) / 86400000); + return { progress, remainingLabel: fmtDays(remainDays), cardState: 'active' }; +} + +function getCardState(id, now) { + switch (id) { + case 'hour': return getHourState(now); + case 'day': return getDayState(now); + case 'week': return getWeekState(now); + case 'month': return getMonthState(now); + case 'year': return getYearState(now); + case 'summer': return getSummerState(now); + case 'fall': return getFallState(now); + } +} + +// ───────────────────────────────────────────────────────────────────────────── +// Particle Field +// ───────────────────────────────────────────────────────────────────────────── + +class ParticleField { + constructor(canvas, seed) { + this.canvas = canvas; + this.ctx = canvas.getContext('2d'); + this.seed = seed; + this.particles = []; + this.N = 120; + this.targetProgress = 0; + this.currentProgress = 0; + this.cardState = 'active'; + + this._initParticles(); + + this._ro = new ResizeObserver(() => this._onResize()); + this._ro.observe(canvas.parentElement); + } + + _onResize() { + const rect = this.canvas.parentElement.getBoundingClientRect(); + this.canvas.width = rect.width * devicePixelRatio; + this.canvas.height = rect.height * devicePixelRatio; + this.canvas.style.width = rect.width + 'px'; + this.canvas.style.height = rect.height + 'px'; + this._initParticles(); + } + + _initParticles() { + const { N, seed } = this; + const w = this.canvas.width; + const h = this.canvas.height; + this.particles = Array.from({ length: N }, (_, i) => ({ + x: seededRandom(seed * 200 + i * 5 ) * w, + y: seededRandom(seed * 200 + i * 5 + 1) * h, + size: (1.5 + seededRandom(seed * 200 + i * 5 + 2) * 2.5) * devicePixelRatio, + phase: seededRandom(seed * 200 + i * 5 + 3) * Math.PI * 2, + speed: 0.3 + seededRandom(seed * 200 + i * 5 + 4) * 0.5, + opacity: 0, + })); + } + + update(progress, cardState) { + this.targetProgress = progress; + this.cardState = cardState; + } + + draw(ts) { + const { ctx, canvas, particles, N } = this; + ctx.clearRect(0, 0, canvas.width, canvas.height); + + // Smoothly interpolate progress + this.currentProgress += (this.targetProgress - this.currentProgress) * 0.025; + + const activeCount = Math.floor(this.currentProgress * N); + const color = PARTICLE_COLORS[this.cardState] || PARTICLE_COLORS.active; + const t = ts * 0.001; + + for (let i = 0; i < N; i++) { + const p = particles[i]; + const targetOpacity = i < activeCount + ? 0.35 + seededRandom(this.seed * 200 + i * 5 + 2) * 0.3 + : 0; + p.opacity += (targetOpacity - p.opacity) * 0.04; + if (p.opacity < 0.005) continue; + + const dx = Math.sin(t * p.speed + p.phase) * 3 * devicePixelRatio; + const dy = Math.cos(t * p.speed * 0.7 + p.phase + 1.3) * 2 * devicePixelRatio; + + ctx.beginPath(); + ctx.arc(p.x + dx, p.y + dy, p.size, 0, Math.PI * 2); + ctx.fillStyle = `rgba(${color[0]},${color[1]},${color[2]},${p.opacity})`; + ctx.fill(); + } + } + + destroy() { + this._ro.disconnect(); + } +} + +// ───────────────────────────────────────────────────────────────────────────── +// Data Loading & Caching +// ───────────────────────────────────────────────────────────────────────────── + +async function fetchWithCache(url, cacheKey) { + const cached = localStorage.getItem(cacheKey); + if (cached) { + try { + const { year, data } = JSON.parse(cached); + if (year === new Date().getFullYear()) return data; + } catch (_) {} + } + const res = await fetch(url); + const data = await res.json(); + localStorage.setItem(cacheKey, JSON.stringify({ year: new Date().getFullYear(), data })); + return data; +} + +async function loadData() { + const year = new Date().getFullYear(); + const [holidays, bridgeDays] = await Promise.all([ + fetchWithCache(`/api/holidays?year=${year}`, `holidays_${year}`), + fetchWithCache(`/api/bridge-days?year=${year}`, `bridgeDays_${year}`), + ]); + + state.holidaySet = new Set(holidays.map(h => h.date)); + state.bridgeDaySet = new Set(bridgeDays.map(h => h.date)); + + const midsommarEntry = holidays.find(h => h.code === 'midsummerEve'); + state.midsommar = midsommarEntry ? new Date(midsommarEntry.date + 'T00:00:00') : null; + state.fallStart = firstMondayOfAugust(year); + state.loaded = true; +} + +// ───────────────────────────────────────────────────────────────────────────── +// DOM & Animation +// ───────────────────────────────────────────────────────────────────────────── + +function buildDOM() { + const container = document.getElementById('cards'); + CARDS.forEach(({ id, label }) => { + const card = document.createElement('div'); + card.className = 'card'; + card.id = `card-${id}`; + + const canvas = document.createElement('canvas'); + card.appendChild(canvas); + + const content = document.createElement('div'); + content.className = 'card-content'; + content.innerHTML = ` + ${label} + + `; + card.appendChild(content); + container.appendChild(card); + }); +} + +function initParticleFields() { + const fields = {}; + CARDS.forEach(({ id }, i) => { + const card = document.getElementById(`card-${id}`); + const canvas = card.querySelector('canvas'); + // Trigger initial resize + const rect = card.getBoundingClientRect(); + canvas.width = rect.width * devicePixelRatio; + canvas.height = rect.height * devicePixelRatio; + canvas.style.width = rect.width + 'px'; + canvas.style.height = rect.height + 'px'; + fields[id] = new ParticleField(canvas, i + 1); + }); + return fields; +} + +let particleFields = null; + +function tick(ts) { + const now = new Date(); + CARDS.forEach(({ id, label }) => { + const { progress, remainingLabel, cardState } = getCardState(id, now); + const card = document.getElementById(`card-${id}`); + + // Update card state class + card.className = `card state-${cardState}`; + + // Update text + card.querySelector('.card-remaining').textContent = remainingLabel; + + // Update particles + particleFields[id].update(progress, cardState); + particleFields[id].draw(ts); + }); + + requestAnimationFrame(tick); +} + +function setupToggles() { + const workModeEl = document.getElementById('workMode'); + const bridgeDaysEl = document.getElementById('bridgeDays'); + const bridgeDaysLabel = document.getElementById('bridgeDaysLabel'); + + workModeEl.addEventListener('change', () => { + state.workMode = workModeEl.checked; + bridgeDaysLabel.classList.toggle('visible', state.workMode); + if (!state.workMode) { + bridgeDaysEl.checked = false; + state.includeBridgeDays = false; + } + }); + + bridgeDaysEl.addEventListener('change', () => { + state.includeBridgeDays = bridgeDaysEl.checked; + }); +} + +// ───────────────────────────────────────────────────────────────────────────── +// Init +// ───────────────────────────────────────────────────────────────────────────── + +async function init() { + // Show loading indicator + const loadingEl = document.createElement('div'); + loadingEl.id = 'loading'; + loadingEl.textContent = 'loading'; + document.body.appendChild(loadingEl); + + buildDOM(); + setupToggles(); + + await loadData(); + + particleFields = initParticleFields(); + + loadingEl.classList.add('hidden'); + setTimeout(() => loadingEl.remove(), 600); + + requestAnimationFrame(tick); +} + +init(); diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..7df397c --- /dev/null +++ b/public/index.html @@ -0,0 +1,30 @@ + + + + + + Aftersummer + + + + + + +
+
+ + +
+
+
+ + + diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..15c2209 --- /dev/null +++ b/public/style.css @@ -0,0 +1,190 @@ +*, *::before, *::after { + box-sizing: border-box; + margin: 0; + padding: 0; +} + +:root { + --bg: #f7f6f2; + --border: rgba(0, 0, 0, 0.07); + --text: #1a1a1a; + --text-muted: #aaa; + --text-secondary: #666; + --header-height: 52px; +} + +html, body { + height: 100%; + background: var(--bg); + font-family: 'Inter', system-ui, sans-serif; + font-weight: 300; + color: var(--text); + overflow: hidden; +} + +/* ── Header ─────────────────────────────────────── */ +header { + height: var(--header-height); + display: flex; + align-items: center; + justify-content: flex-end; + padding: 0 32px; + border-bottom: 1px solid var(--border); +} + +.toggles { + display: flex; + gap: 28px; + align-items: center; +} + +.toggle { + display: flex; + align-items: center; + gap: 10px; + cursor: pointer; + user-select: none; +} + +.toggle input { + display: none; +} + +.track { + position: relative; + width: 40px; + height: 22px; + background: #ddd; + border-radius: 11px; + transition: background 0.2s ease; + flex-shrink: 0; +} + +.track::after { + content: ''; + position: absolute; + width: 16px; + height: 16px; + background: white; + border-radius: 50%; + top: 3px; + left: 3px; + transition: left 0.2s ease; + box-shadow: 0 1px 3px rgba(0,0,0,0.15); +} + +.toggle input:checked + .track { + background: #1a1a1a; +} + +.toggle input:checked + .track::after { + left: 21px; +} + +.toggle-label { + font-size: 12px; + letter-spacing: 0.04em; + color: var(--text-secondary); +} + +#bridgeDaysLabel { + opacity: 0; + pointer-events: none; + transition: opacity 0.2s ease; +} + +#bridgeDaysLabel.visible { + opacity: 1; + pointer-events: all; +} + +/* ── Cards ───────────────────────────────────────── */ +#cards { + height: calc(100vh - var(--header-height)); + display: flex; + flex-direction: column; +} + +.card { + position: relative; + flex: 1; + border-bottom: 1px solid var(--border); + overflow: hidden; +} + +.card:last-child { + border-bottom: none; +} + +.card canvas { + position: absolute; + inset: 0; + width: 100%; + height: 100%; +} + +.card-content { + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 32px; + pointer-events: none; +} + +.card-name { + font-size: 11px; + font-weight: 400; + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--text-muted); + transition: color 0.4s ease; +} + +.card-remaining { + font-size: 13px; + font-weight: 300; + color: var(--text-secondary); + transition: color 0.4s ease; +} + +/* State variants */ +.card.state-not-work-time .card-name, +.card.state-not-work-time .card-remaining { + color: #ccc; +} + +.card.state-summer .card-name { + color: #c4902a; +} + +.card.state-summer .card-remaining { + color: #c4902a; + opacity: 0.8; +} + +.card.state-off-season .card-name, +.card.state-off-season .card-remaining { + color: #b0b8c8; +} + +/* Loading state */ +#loading { + position: fixed; + inset: 0; + background: var(--bg); + display: flex; + align-items: center; + justify-content: center; + font-size: 12px; + letter-spacing: 0.08em; + color: var(--text-muted); + z-index: 100; + transition: opacity 0.5s ease; +} + +#loading.hidden { + opacity: 0; + pointer-events: none; +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..7a6fa50 --- /dev/null +++ b/server.js @@ -0,0 +1,33 @@ +import express from 'express'; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const app = express(); + +app.use(express.static(join(__dirname, 'public'))); + +app.get('/api/holidays', async (req, res) => { + const { year } = req.query; + try { + const response = await fetch(`https://api.dagsmart.se/holidays?year=${year}&weekends=false`); + const data = await response.json(); + res.json(data); + } catch (err) { + res.status(500).json({ error: String(err) }); + } +}); + +app.get('/api/bridge-days', async (req, res) => { + const { year } = req.query; + try { + const response = await fetch(`https://api.dagsmart.se/bridge-days?year=${year}`); + const data = await response.json(); + res.json(data); + } catch (err) { + res.status(500).json({ error: String(err) }); + } +}); + +const PORT = process.env.PORT || 3000; +app.listen(PORT, () => console.log(`Aftersummer → http://localhost:${PORT}`));