diff --git a/README.md b/README.md index ea12eb5..824eec3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Lecture notes as a tree of pages ("comb") — live-preview markdown underneath, ```sh npm install npm run dev # http://localhost:5173 -npm test # unit tests (tree, markdown, selection, PDF round trip, sync against a fake GitHub) +npm test # unit tests (tree, markdown, PDF round trip, sync against a fake GitHub) npm run check # type-check npm run build # static PWA in build/ — serve it from any static host (HTTPS for PWA install) ``` @@ -22,13 +22,10 @@ The image builds the PWA and serves it with nginx. Put an HTTPS reverse proxy in ## Using it -- **Tools** (bottom bar): Text `T`, Select `S`, Pen `P`, Highlighter `H`, Eraser `E`, Import PDF, Insert image, Undo/Redo, zoom. The pen's eraser end erases too. -- **Selecting**: with Select, draw a loop around ink and images (only things entirely inside are picked) or tap one. Holding the pen's side button lassoes with any tool. Drag the box to move, a corner to resize; the bar above it copies, cuts, duplicates, deletes or recolours. `Ctrl+C/X/V/D`, `Delete` and arrow keys work too. -- **Images**: paste (`Ctrl+V`), drop an image file on a page, or use Insert image. Large images are scaled down to 2400 px. Images stay in their own colours in dark mode. Copying a selection also puts a PNG of it on the system clipboard. -- **Pages**: the "+" circles beside the active page add a page there (a quick finger flick toward a free side offers one there; turn it off under Settings → Pen & touch); `Alt+Arrow` moves to (or creates) the neighbour. Right-click a page or use its `⋯` button to insert, resize or delete it. -- **Grid**: the faint background grid has one cell per active page; Settings → Appearance can hide it or subdivide it. +- **Tools** (bottom bar): Text `T`, Pen `P`, Highlighter `H`, Eraser `E`, Import PDF, Undo/Redo, zoom. The pen's eraser end erases too. +- **Pages**: the grey "+" tiles next to the active page add a page there; `Alt+Arrow` moves to (or creates) the neighbour. Right-click a page or use its `⋯` button to insert, resize or delete it. - **Importing a PDF** into a non-empty canvas shows every free spot; click one to place the chain. Into a blank canvas it simply replaces the empty page. The Files panel can also import a PDF as a new canvas. -- **View**: wheel/trackpad pans, `Ctrl`+wheel or pinch zooms, `Ctrl+0` fits the page, `Ctrl+9` shows the whole tree, space-drag or middle-drag pans. A drag keeps gliding for a moment after you let go and slows to a stop (the zoom never changes); touching the canvas catches it. The drag strength is `GLIDE_TAU` in `src/lib/ink/fling.ts`. +- **View**: wheel/trackpad pans, `Ctrl`+wheel or pinch zooms, `Ctrl+0` fits the page, `Ctrl+9` shows the whole tree, space-drag or middle-drag pans. - **Sync**: Settings → Sync. Use a fine-grained token with *Contents: read & write* on the repo. Edits autosave locally; pushes happen every N minutes and on `Ctrl+S` / the sync button. Conflicts: newer wins. ## Layout @@ -36,8 +33,7 @@ The image builds the PWA and serves it with nginx. Put an HTTPS reverse proxy in - `src/lib/model` — page tree (pure functions: insert/remove/flatten/layout). - `src/lib/editor` — markdown analysis shared by the CodeMirror live preview and the PDF text layout. - `src/lib/pdf` — PDF writer (vector text, Ink annotations, embedded source-of-truth files) and reader. -- `src/lib/ink` — stroke recording/outlines, lasso selection and clipboard helpers, palm rejection (ported from `palm-rejection-test.html`). -- `src/lib/images` — pasted-image normalisation, asset storage/object URLs, PNG export of a selection. +- `src/lib/ink` — stroke recording/outlines and palm rejection (ported from `palm-rejection-test.html`). - `src/lib/storage`, `src/lib/sync` — IndexedDB vault and GitHub sync. Fonts in `static/fonts` are pre-subset (`scripts/subset-fonts.sh`) because pdf-lib's own subsetter drops glyphs. diff --git a/spec.md b/spec.md index ab8d018..5125de1 100644 --- a/spec.md +++ b/spec.md @@ -9,11 +9,10 @@ One canvas = one tree = one `.pdf` file. - A branch can only ever continue in the direction it started (strictly linear — no sub-branches off a branch). - A trunk page can have at most one left branch and one right branch. - **PDF import**: creates a chain of pages in whatever direction you pick when placing it (up/down = extends the trunk, left/right = becomes a branch off the trunk page you clicked). Only one trunk exists per canvas — additional imported PDFs must attach as a branch off some trunk page, or extend an existing branch further outward in its established direction. -- Each free side of the active page shows a small "+" circle just off its edge; tapping it (or `Alt+Arrow`) adds a blank page there. A quick finger fling toward a free side offers a page there for a few seconds: that side's "+" pulses, or, if it is off screen, an "Add page" button appears at that edge of the screen. The fling never adds a page by itself, and can be turned off in Settings. -- The canvas background is a faint grid with one cell per active page, aligned to its edges; Settings can hide it or subdivide it. +- Hidden/unopened neighbor pages render as a gray tile with a "+" in a circle; clicking (or a shortcut) instantiates them as real pages. - Deleting a page removes it (undo via Ctrl+Z); no permanent trash. - Default zoom: one page fills the screen. Zoom out reveals the tree. -- Pages default to A4, or auto-match the aspect ratio of an imported PDF page; resizable manually otherwise (page menu: presets, or a custom size in mm). +- Pages default to A4, or auto-match the aspect ratio of an imported PDF page; resizable manually otherwise. ## 2. Flatten Algorithm (tree → linear page order, e.g. for PDF page order / print) @@ -32,8 +31,8 @@ This is recomputed at export/save time (not creation order), since the trunk can One canvas = **one `.pdf` file**, dual-layer: -- **Visual layer** (any standard PDF viewer sees this): rendered markdown as real vector text, pasted images, ink drawn as PDF Ink annotations, original imported PDF content where applicable. Fully readable/printable by anyone, no app required. -- **Source-of-truth layer** (embedded file attachments, invisible in normal viewers): raw markdown source per page, full vector stroke data (points + pressure + tilt — richer than what Ink annotations can hold), placed images per page (`papure/pages/.images.json`) with each image's bytes stored once (`papure/assets/.png|jpg`), and grid metadata (each page's tree position, size, and which PDF import it originated from, for provenance search). +- **Visual layer** (any standard PDF viewer sees this): rendered markdown as real vector text, ink drawn as PDF Ink annotations, original imported PDF content where applicable. Fully readable/printable by anyone, no app required. +- **Source-of-truth layer** (embedded file attachments, invisible in normal viewers): raw markdown source per page, full vector stroke data (points + pressure + tilt — richer than what Ink annotations can hold), and grid metadata (each page's tree position, size, and which PDF import it originated from, for provenance search). - App reads the attachment layer first to reconstruct the live editable canvas; falls back to parsing visual content only if attachments are missing. **Libraries**: `pdf-lib` (write/edit/attach), `pdf.js` (render/import). @@ -46,7 +45,7 @@ Canvases (PDF files) live in a **file tree** you define, e.g. `school/english/le ## 5. Sync & Storage -- Repo-backed (GitHub for now; GitLab not implemented), one file per canvas. +- Repo-backed (GitHub/GitLab), one file per canvas. - PWA: offline-first, caches locally, explicit save/sync pushes to repo. - Multi-device: git pull/push is the sync mechanism (not real-time collab). @@ -55,13 +54,12 @@ Canvases (PDF files) live in a **file tree** you define, e.g. `school/english/le - **Frontend**: SvelteKit, deployed on your VPS, installable as PWA. - **Ink input**: Pointer Events + pressure (your existing artifact — pending). - **PDF read/write**: pdf.js + pdf-lib. -- **Storage**: IndexedDB locally; Git repo via the GitHub REST API (token in the browser, no proxy). +- **Storage**: Git repo via GitHub/GitLab API (or local backend proxy holding the token). ## 7. Confirmed Product Features - Live-rendered markdown (background layer) + vector ink (foreground layer), never converted to text. - Full ink toolset: colors, highlighter, eraser. -- Lasso selection of ink and images; pasted images (§10). - Search across typed markdown text. - Pages remember their PDF-import origin, searchable. - No export needed beyond the PDF itself (for now). @@ -81,45 +79,12 @@ Source: user-provided `palm-rejection-test.html` test harness. The acceptance po - A `touch` pointer is rejected if any of: a pen stroke is active or was active within the last ~5s, its contact ellipse (`width`/`height`) exceeds ~35px (palm heel vs. fingertip), it's within 150ms of the last pen activity, or a pen is currently hovering (armed lockout before it even touches down). - A touch stroke already in progress gets cut off mid-stroke if pen activity appears. -**How the app applies it** (`src/lib/ink/palm.ts`): -- Each touch is evaluated with an intent. `draw` (finger ink) gets the full policy above. `navigate` (pan, pinch, and taps on canvas buttons such as the add-page "+") skips the 5 s pen session and the hover lockout, so fingers can move around and tap between pen strokes; pen-down, wide contacts and the 150 ms window still reject it. -- Once a pen has been used, fingers only navigate. "Draw with finger" in Settings turns finger ink off entirely. -- Each rule (pen session, wide contact, timing, hover) can be switched off in Settings → Pen & touch. -- An interrupted pointer (`pointercancel`) drops the stroke or erase in progress instead of committing it. +**Gaps before this is the real ink engine** (currently a raster test, not vector): +- `draw()` writes straight to canvas via `ctx.lineTo`/`stroke` with pressure-scaled line width, and throws points away. Needs to become `recordPoint()`: push `{x, y, pressure, tiltX, tiltY, t}` into a `Stroke.points[]` array per stroke; rendering = replaying that array. This is what makes strokes resizable/erasable/undoable and exportable to both the PDF Ink-annotation layer and the JSON attachment layer. +- `tiltX`/`tiltY` exist on the pen's `PointerEvent` but aren't read anywhere yet — needed for tilt support. +- No smoothing yet (raw straight segments) — fine as a v1, can layer in curve smoothing later without changing point storage. +- No undo/redo, multi-color, eraser yet — needs a `Stroke[]` array per page's ink layer with add/remove, which undo/redo just pops/pushes. -**Ink engine (implemented)**: -- `StrokeRecorder.recordPoint()` stores `x, y, pressure, tiltX, tiltY, t` per sample in a flat `Stroke.points` array (stride 6); rendering replays it. Tilt is recorded but not yet used for rendering. -- Outlines are smoothed with `perfect-freehand`; mouse and finger strokes simulate pressure. -- Pen, highlighter (translucent, no thinning) and stroke eraser, with configurable colour palettes; the pen's eraser end erases too. -- Undo/redo covers ink, erasing and page-tree changes. -- Strokes are written to the PDF both as Ink annotations and as JSON attachments. +## 10. Open Items -## 10. Selection & Images - -**Page layers**, bottom to top: imported PDF → markdown → pasted images → ink. Ink can be written over an image. - -**Select tool** (`S`, lasso): -- Drag draws a lasso; an ink stroke is selected only when *all* of its samples are inside it, an image only when all four corners are. A tap selects the single object under it (ink before images). Shift adds to the selection; `Ctrl+A` selects everything on the active page. -- A selection lives on one page. It shows as a dashed box with corner handles and an action bar (copy, cut, duplicate, delete, recolour ink). -- Drag the box to move, a corner to scale uniformly (ink width scales too); arrow keys nudge by 1 pt (Shift: 10 pt). Each move/resize is one undo step; the drag itself is only a preview. -- `Delete`/`Backspace` deletes, `Ctrl+C`/`X`/`V`/`D` copy, cut, paste, duplicate. `Escape`, pressing elsewhere or switching tools clears the selection. -- Holding the pen's barrel button lassoes whatever tool is active (Settings → Pen & touch → "Pen button selects"); its context menu is suppressed. -- Palm rejection: lassoing with a finger counts as drawing; dragging the selection box or its handles counts as navigating, so fingers can move a selection between pen strokes. -- The eraser never erases images; delete them with the Select tool. - -**Clipboard**: copying keeps a vector copy in the app and writes a PNG of the selection to the system clipboard (for other apps). Pasting uses the vector copy while it's fresh (until the window loses focus or something else is copied); otherwise an image on the clipboard is pasted. Pastes land at the pointer if it's over a page, else in the middle of the visible part of the active page. - -**Images** come in by paste, drag-and-drop, the toolbar's "Insert image" button, or "Paste" in the page menu. -- Normalised on the way in: the long edge is capped at 2400 px; transparent images stay PNG, JPEGs stay JPEG (quality 0.85, EXIF rotation applied), other images use whichever of PNG/JPEG is smaller. A PNG that already fits is kept byte for byte. -- Stored by SHA-256 content hash in IndexedDB (`assets` store), so one image placed many times is stored once — also in the PDF. -- Placed at 96 dpi (1 px = 0.75 pt), shrunk to at most 80 % of the page, and selected so it can be moved/resized straight away. -- Dark mode ("match" page style) inverts each page layer except images, so images keep their true colours. The ink layer is screen-blended so the highlighter still reads like it does in light mode. - -## 11. Open Items - -- [ ] Conflict copies: sync currently lets the newer version win silently; keep the losing version as a separate file. -- [ ] Tell the user when a new version of the app has been deployed (the service worker updates, but the open tab keeps old code until reload). -- [ ] CI that runs `check`, `test` and `build` on every pull request. -- [ ] Use recorded tilt for rendering. -- [ ] GitLab sync. -- [ ] Selection: drag across pages, rotate; image crop; "paste as new page" for slide screenshots. +- [ ] Nothing blocking — ready to move into implementation planning (component breakdown, page-tree data structures in Svelte, PDF encode/decode module) diff --git a/src/app.css b/src/app.css index 912d602..76440c5 100644 --- a/src/app.css +++ b/src/app.css @@ -61,7 +61,6 @@ --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.08); --page-line: rgba(0, 0, 0, 0.18); --grid-line: rgba(0, 0, 0, 0.05); - --grid-line-minor: rgba(0, 0, 0, 0.028); --ghost: rgba(0, 0, 0, 0.045); --ghost-border: rgba(0, 0, 0, 0.12); --radius: 6px; @@ -89,7 +88,6 @@ --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35); --page-line: rgba(255, 255, 255, 0.16); --grid-line: rgba(255, 255, 255, 0.04); - --grid-line-minor: rgba(255, 255, 255, 0.022); --ghost: rgba(255, 255, 255, 0.04); --ghost-border: rgba(255, 255, 255, 0.14); color-scheme: dark; diff --git a/src/lib/components/CanvasView.svelte b/src/lib/components/CanvasView.svelte index 64f8156..f0ad3cb 100644 --- a/src/lib/components/CanvasView.svelte +++ b/src/lib/components/CanvasView.svelte @@ -1,15 +1,10 @@ - { - spaceDown = false; - clipFresh = false; - }} - oncopy={() => (clipFresh = false)} - onpaste={onPaste} -/> + (spaceDown = false)} />
@@ -1001,9 +557,8 @@ class:inking={tools.inking} class:panning class:erasing={tools.tool === 'eraser'} - class:moving={!!selPreview} bind:this={stage} - style={gridStyle} + style="background-size: {grid.w}px {grid.h}px; background-position: {grid.x}px {grid.y}px" onpointerdown={onPointerDown} onpointermove={onPointerMove} onpointerup={onPointerUp} @@ -1013,8 +568,6 @@ eraserAt = null; }} oncontextmenu={onContextMenu} - ondragover={onDragOver} - ondrop={onDrop} >
doc.touch()} onactivate={() => (doc.activeId = id)} /> {/if} {/each} - {#if lasso && doc.rects.get(lasso.pageId)} - {@const r = doc.rects.get(lasso.pageId)!} - - - - {/if} - - {#if selRect} -
- {#each CORNERS as c (c)} -
- {/each} - {/if} - {#each ghostSlots as slot (slot.anchor + slot.dir)} - {@const r = plusRect(slot)} + {@const r = barRect(slot)} {#if r} + > {/if} {/each} @@ -1109,35 +640,6 @@ {/if} - {#if offer && offerOffscreen} - - - {/if} - - {#if selBar && selected} - - {/if} - {#if eraserAt && tools.tool === 'eraser'}
{/if} @@ -1150,20 +652,7 @@ {/if}
- {#if sizing && doc.pages[sizing]} - {@const id = sizing} - (sizing = null)} - onapply={(w, h) => { - sizing = null; - keepAnchor(id, () => doc.resizePage(id, w, h)); - }} - /> - {/if} - - fitPage(doc.activeId)} onfitall={fitAll} onimages={(files) => void insertImages(files)} /> + fitPage(doc.activeId)} onfitall={fitAll} />
diff --git a/src/lib/components/InkLayer.svelte b/src/lib/components/InkLayer.svelte index a59e9fb..a16e94c 100644 --- a/src/lib/components/InkLayer.svelte +++ b/src/lib/components/InkLayer.svelte @@ -1,6 +1,5 @@ - - e.key === 'Escape' && onclose()} /> - - -
e.target === e.currentTarget && onclose()}> -
{ - e.preventDefault(); - apply(); - }} - > -

Page size

-
- {#each PAGE_PRESETS as p (p.label)} - - {/each} -
-
- - - - mm -
- {#if !valid} -

Sizes must be between {toMm(MIN_PT)} and {toMm(MAX_PT)} mm.

- {/if} -
- - -
-
-
- - diff --git a/src/lib/components/PageView.svelte b/src/lib/components/PageView.svelte index 67d0105..ad52f25 100644 --- a/src/lib/components/PageView.svelte +++ b/src/lib/components/PageView.svelte @@ -5,8 +5,6 @@ import MarkdownEditor from './MarkdownEditor.svelte'; import PdfBackground from './PdfBackground.svelte'; import InkLayer from './InkLayer.svelte'; - import ImageLayer from './ImageLayer.svelte'; - import type { Transform } from '$lib/ink/select'; interface Props { page: PageModel; @@ -17,12 +15,11 @@ live: Stroke | null; tick: number; erasing: Set; - moving: { ids: Set; t: Transform } | null; onchange: () => void; onactivate: () => void; } - let { page, rect, active, invert, scale, live, tick, erasing, moving, onchange, onactivate }: Props = $props(); + let { page, rect, active, invert, scale, live, tick, erasing, onchange, onactivate }: Props = $props();
{/if} - - +
{#if page.origin && active}
{page.origin.name} · p. {page.origin.pageIndex + 1}
@@ -56,18 +52,9 @@ /* Crisp 1 screen-px outline, no blur. */ box-shadow: 0 0 0 calc(1px / var(--s)) var(--page-line); } - /* Dark pages: every layer but pasted images is colour-inverted, so images keep their colours. - The background is what white becomes under the filter. */ .paper.invert { - background: #1f1f1f; - } - .paper.invert > :global(:not(.images)) { filter: invert(0.88) hue-rotate(180deg); } - /* Highlighter multiplies against the text in light mode; inverted, that is roughly a screen. */ - .paper.invert > :global(.ink) { - mix-blend-mode: screen; - } .page.active::after { content: ''; position: absolute; diff --git a/src/lib/components/SettingsModal.svelte b/src/lib/components/SettingsModal.svelte index fe45d40..6b92676 100644 --- a/src/lib/components/SettingsModal.svelte +++ b/src/lib/components/SettingsModal.svelte @@ -83,34 +83,12 @@ -
-
Background grid
Faint lines behind the pages, one cell per active page.
- -
-
-
Grid subdivisions
Split each page-sized cell into a finer grid for sketching and lining things up.
- -
{:else if tab === 'input'}

Pen & touch

Draw with finger
When off, a single finger always pans; only pen and mouse draw. Once you use a pen, fingers only pan and zoom.
-
-
Swipe to add pages
A quick one-finger flick toward a free side of the active page offers to add a page there.
- -
-
-
Pen button selects
Hold the button on the side of the pen and draw a loop to select, whatever tool is active.
- -

Palm rejection

Pen session lockout
Ignore touches while the pen is writing, and finger ink for 5 seconds after it was used.
diff --git a/src/lib/components/Toolbar.svelte b/src/lib/components/Toolbar.svelte index 2872fed..7f5915a 100644 --- a/src/lib/components/Toolbar.svelte +++ b/src/lib/components/Toolbar.svelte @@ -1,7 +1,5 @@