Frontend
Native ES modules without a build, hash router, central state, offline via the service worker, strict CSP.
The frontend lives in web/ and is served unchanged by the app. There is no build step, no framework and no runtime dependency apart from pdf.js.
Structure
web/
├── index.html entry, loads theme-boot.js and main.js
├── sw.js service worker: offline, share target
├── manifest.webmanifest PWA: name, icons, share target
├── assets/css/ tokens, base, layout, components, views, features
├── assets/js/
│ ├── main.js start, routes, sign-in
│ ├── router.js hash router (#/path/:param)
│ ├── store.js central state with subscriptions
│ ├── api.js fetch wrapper: CSRF header, language, errors
│ ├── lib/ dom (html templates), format, i18n, icons, webauthn
│ ├── ui/ building blocks: shell, importer, viewer, codepicker, bell, groups, vault …
│ └── views/ pages: dashboard, tickets, ticket, stack, present, settings, login, welcome, join
├── assets/i18n/en.json translation catalogue
└── vendor/pdfjs/ PDF display
Principles
- Templates:
lib/dom.jsprovideshtml\…``. Inserted values are escaped; HTML from data is never inserted raw. - Router: hash routes (
#/t/42,#/settings/postfach) work without a server fallback and offline. - State:
store.jsholds account, settings and ticket list; views subscribe to changes. - Views export
render(el, ctx)and clean up viasetCleanup. - Strict CSP: no inline scripts and no inline styles. Dynamic sizes are set through CSSOM (
el.style.width = …), which the CSP allows. - Design tokens: colours, spacing and fonts come from
tokens.css(light and dark). The wiki and the website use the same file.
Offline and service worker
sw.js uses three caches:
| Cache | Contents | Strategy |
|---|---|---|
clipr-shell-vNN |
App files (HTML, CSS, JS, fonts, pdf.js) | Network first, offline from cache |
clipr-data-v1 |
Ticket list, ticket details, files, code images, account, settings | Network first, offline from cache |
clipr-share |
Files received via “Share → Clipr” | Until imported after opening |
Everything else under /api/ and everything under /sso/ is never cached. On sign-out, on every new sign-in (shared devices), on locking the vault and on a 401 response the data cache is deleted.
Raise the version number in SHELL_CACHE with every change to app shell files – otherwise installed apps keep old files. New files also belong in the SHELL list.
Sharing to Clipr (Web Share Target)
The manifest registers Clipr as a target for PDFs and images. The service worker intercepts POST /share-target, stores the files in the clipr-share cache and opens the app, which imports them through the signed-in session. Without a service worker the server does not read the content but redirects back into the app with a notice (share_target_fallback).
Document display
ui/viewer.js shows PDFs with pdf.js and lays an invisible text layer over them – for photos and scans from OCR (/api/tickets/{tid}/ocr-layer). This makes text selectable and copyable. ui/codepicker.js uses the same display for Choose code in document.