|
| 1 | +# New Design — creation flow, document model, and native format |
| 2 | + |
| 3 | +Adopted 2026-08-04. Supersedes the "New File" preset-as-document-size model. |
| 4 | + |
| 5 | +## Product model |
| 6 | + |
| 7 | +- **A new Varve document is an untitled infinite-canvas document.** It never |
| 8 | + carries a width, height, page, or color mode of its own. |
| 9 | +- **Width/height belong to frames, pages, and print layouts.** Device, social, |
| 10 | + photo, print, and presentation presets define *frame* properties. |
| 11 | +- **Three starting points**, mutually exclusive: |
| 12 | + |
| 13 | + | Start | Result | |
| 14 | + |---|---| |
| 15 | + | Empty document | Flat, page-less document. No frame. | |
| 16 | + | Start with a frame | Flat document + exactly one frame node at the origin with the preset/custom dimensions. | |
| 17 | + | Template | Document decoded from `templateJson` through the versioned migration pipeline. | |
| 18 | + |
| 19 | +- **Templates are separate from frame presets**: they carry actual design |
| 20 | + content, styles, components, and possibly multiple frames. |
| 21 | +- **Print and advanced settings are document-level metadata**, collapsed behind |
| 22 | + an "Advanced settings" disclosure and auto-revealed by print presets: |
| 23 | + color mode (RGB/CMYK/grayscale — soft-proofed intent, preview always RGB), |
| 24 | + DPI, and bleed. 16-bit rendering is not exposed because the renderer is |
| 25 | + uint8 end-to-end. |
| 26 | +- **Screen documents use defaults**: RGB, 8-bit, no bleed/DPI. |
| 27 | + |
| 28 | +## Canonical creation service |
| 29 | + |
| 30 | +`createNewDocument(request)` in `packages/scene/src/newDocument.ts` is the single |
| 31 | +entry point. Request shape: |
| 32 | + |
| 33 | +```ts |
| 34 | +{ |
| 35 | + documentName?: string; // display name; defaults to 'Untitled' |
| 36 | + startMode?: 'empty' | 'framePreset' | 'customFrame' | 'template'; |
| 37 | + preset?: Preset; // framePreset |
| 38 | + customFrame?: { width; height; unit }; // customFrame |
| 39 | + templateJson?: string; // template — decoded via DocumentCodec |
| 40 | + colorMode?: ColorMode; // advanced |
| 41 | + bitDepth?: 8 | 16; |
| 42 | + bleed?: PresetBleed; |
| 43 | + dpi?: number; |
| 44 | + colorProfileId?: string; |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +It returns `{ ok, result: { document, initialFrameId, warnings? } }` or a typed |
| 49 | +error. Creation is atomic: a failed template decode never leaves a half-created |
| 50 | +document behind. |
| 51 | + |
| 52 | +Callers (all wired to the service): |
| 53 | + |
| 54 | +- Home screen "New" button and empty states → `NewDesignDialog` |
| 55 | +- File → New / Ctrl+N / command palette / QuickActions → `usePersistence.newDocument` |
| 56 | +- Template creation (home Templates section and dialog) |
| 57 | +- `createDocumentFromPreset` in `presetToDocument.ts` remains for legacy |
| 58 | + print-first flows that genuinely need a fixed-size page document |
| 59 | + (import/export/print paths depend on `physicalWidth`/`physicalHeight`). |
| 60 | + |
| 61 | +Naming helpers live in `@varve/shared/src/untitledName.ts`: |
| 62 | + |
| 63 | +- `nextUntitledName(usedNames)` — collision-free "Untitled N" |
| 64 | +- `sanitizeFileName(name)` — strips filesystem-invalid characters, preserves |
| 65 | + Unicode, never appends an extension |
| 66 | +- Duplicate names are resolved at save time, not at creation time. |
| 67 | + |
| 68 | +## Dependency map |
| 69 | + |
| 70 | +``` |
| 71 | +UI action (New button / empty state / Ctrl+N / palette) |
| 72 | + → NewDesignDialog (home) or usePersistence.newDocument (editor) |
| 73 | + → createNewDocument(request) [@varve/scene] |
| 74 | + → Document (schema CURRENT_DOCUMENT_VERSION) [flat, optional frame] |
| 75 | + → serializeDocument → platform.upsertFile [store + recents + thumbnail] |
| 76 | + → editor opens via handleOpenFile → session with fileId/filePath |
| 77 | + → Save: filePath ? writeDocumentToPath(path) : saveAsImpl → platform.saveDocumentToDisk |
| 78 | +``` |
| 79 | + |
| 80 | +## Native format: `.varve` with `.strata` compatibility |
| 81 | + |
| 82 | +- `DOCUMENT_EXT = 'varve'`, `LEGACY_DOCUMENT_EXT = 'strata'` (platform `pure.ts`). |
| 83 | +- Both extensions map to the same persisted `FileKind` (`'strata'` is kept as |
| 84 | + the storage value — SQLite `files.kind DEFAULT 'strata'` is a compatibility |
| 85 | + identifier and must not be renamed). |
| 86 | +- The document schema version (`CURRENT_DOCUMENT_VERSION`) is independent of |
| 87 | + both the extension and the product version. `.strata` files run through the |
| 88 | + same migration pipeline as `.varve`. |
| 89 | +- Open/Save filters offer both extensions; the save dialog defaults to `.varve`. |
| 90 | +- Legacy files are never destructively rewritten on open; Save As defaults to |
| 91 | + `.varve` and offers `.strata` only when needed. |
| 92 | +- File → Save for a document opened from disk writes back to the original path |
| 93 | + (`platform.writeDocumentToPath`; Tauri writes atomically via |
| 94 | + `home_write_text_file`, web falls back to the picker, memory is a no-op). |
| 95 | +- Persisted identifiers with rename migrations: version-history localStorage |
| 96 | + keys (`varve-versions` with `strata-versions` read fallback), recovery |
| 97 | + IndexedDB (`varve-recovery` with one-time idempotent copy from |
| 98 | + `strata-recovery`, never deleted). |
| 99 | +- Platform metadata: `application/x-varve` + legacy `application/x-strata` MIME |
| 100 | + types registered in `tauri.conf.json`, `linux/dev.varve.desktop.xml`, and the |
| 101 | + AUR PKGBUILD; the home-directory watcher and import accept lists cover both |
| 102 | + extensions. |
| 103 | + |
| 104 | +## Responsive top bar |
| 105 | + |
| 106 | +The menubar is a flex chain — `[home][menus][title][workspace tabs][undo/redo/zoom]` — |
| 107 | +so items can never overlap. The title truncates with an ellipsis (`min-width: 0`). |
| 108 | +Workspace tabs are data-driven: |
| 109 | + |
| 110 | +- `WORKSPACE_OVERFLOW_ORDER` (display order): Design, Draw, Photo, Print, Motion, |
| 111 | + Codegen & Audit, Logo. |
| 112 | +- `WORKSPACE_OVERFLOW_PRIORITY`: Design never overflows; Logo/Codegen overflow |
| 113 | + first. |
| 114 | +- `computeWorkspaceLayout` (pure, unit-tested) decides visible vs. overflow |
| 115 | + tabs from measured widths; the active mode is always visible (a lower-priority |
| 116 | + tab is evicted to the "More" menu if needed). |
| 117 | +- Below 900px tabs become icon-only; at very narrow widths only the active tab |
| 118 | + stays on screen — every mode remains reachable via the overflow menu, |
| 119 | + keyboard shortcuts, and the command palette. |
| 120 | + |
| 121 | +## Accessibility notes |
| 122 | + |
| 123 | +- The dialog: native `<dialog>` focus trap, focus restored to the trigger on |
| 124 | + close, Enter creates (never while a text input or the preset listbox owns |
| 125 | + Enter), Escape closes, radios carry accessible names including icon-only |
| 126 | + workspace tabs. |
| 127 | +- Dark/light/high-contrast all trace to semantic tokens; the modal overlay fix |
| 128 | + (display:flex scoped to `[open]`) also restored correct closed-dialog |
| 129 | + behavior. |
0 commit comments