Skip to content

Latest commit

 

History

History
138 lines (99 loc) · 10.3 KB

pages-layers-frames-shapes-system.md

File metadata and controls

138 lines (99 loc) · 10.3 KB

Pages, Layers, Frames, and Shapes System

Last updated: 2026-07-14

Current Architecture

The shared document model lives in @varve/scene and is target-agnostic. The editor, renderer, layers tree, hit tester, export code, recovery, and platform adapters all consume the same Document object.

Page Model v2.0

The page model uses stable fractional-indexing for page ordering:

  • Document.pages: ordered Page[], each with stable Page.id, dimensions, backgrounds, and a contentRoot.
  • Page.order: stable fractional-indexing key (PageOrder type) via generateKeyBetween. Pages are sorted by order.localeCompare(), not array index.
  • Document.activePageId: canonical active page id. This must point to a Page.id, not a content root node id.
  • Page.contentRoot: a GroupNode that owns the page's layer tree.
  • Document.globalChildren: shared nodes shown on every page.
  • activePageNodes(doc): the active renderer/hit-test traversal entry point, returning globals plus the active page content root's children.
  • activePageNodesWithMaster(doc, pageId): returns visible nodes including applied master content with override filtering.

Design Canvas Model v2.22

Design workspace organization is represented separately from Publishing Pages:

  • Document.designCanvases: ordered named DesignCanvas[] surfaces.
  • Document.activeDesignCanvasId: the active Design workspace surface.
  • DesignCanvas.contentRoot: an internal transparent group that owns the canvas's authored nodes; it is not a user-facing layer.
  • designCanvasChildren(doc, canvasId): the direct artwork roots used by rendering, hit testing, filtering, and layer reordering.

The Design Canvas navigator is exposed above Layers in Design workspace. The Layers tree receives only the active canvas's authored descendants, so the canvas itself never appears as a layer row. Print workspace instead resolves the active Publishing Page and exposes page navigation, trim, spreads, masters, and page-aware output controls.

Master Pages

Master pages provide reusable layout templates:

  • Document.masters: Record<NodeId, MasterPage> — master page definitions keyed by id.
  • MasterPage: id, name, width, height, contentRoot (GroupNode), appliesTo ('all'|'left'|'right').
  • Page.masterPageId: which master is applied to this page.
  • Page.masterOverrides: Record<NodeId, MasterOverride> — per-node overrides against the applied master.
  • MasterOverride: type ('modified'|'hidden'|'deleted'), optional localNodeId for modified nodes.

Master content propagation: activePageNodesWithMaster returns globals → master content (filtered by overrides) → page-local content. Modified overrides replace the master node with a local copy. Hidden/deleted overrides filter the master node.

Facing Pages & Spreads

Editorial spreads for print layout:

  • Document.facingPages: FacingPagesConfig with enabled, startOnRight, autoInsertBlank.
  • Document.spreads: Spread[] — each spread has one or two page IDs.
  • rebuildSpreads(doc, config?): sorts pages by order, pairs into spreads. startOnRight puts first page alone.
  • getPageSide(doc, pageId, config): returns 'left', 'right', or 'none' based on spread position.
  • PageSection: section-aware numbering with styles (decimal/upperRoman/lowerRoman/upperAlpha/lowerAlpha) and optional prefix.

Page Numbering

  • getPageNumber(doc, pageId): returns 1-indexed number within section.
  • getFormattedPageNumber(doc, pageId): returns formatted string using section style and prefix.

Target I/O Boundary

Shared model behavior should not diverge between desktop and web. The I/O adapters do diverge:

  • Web target: @varve/platform/src/web.ts stores home files in IndexedDB, uses File System Access API when available, and falls back to <input type=file> or Blob downloads.
  • Tauri target: @varve/platform/src/tauri.ts persists through Tauri IPC into the native SQLite store, uses tauri-plugin-dialog for native open/save dialogs, and uses native file writes.
  • Drag and drop: browser code uses HTML5 DataTransfer; Tauri config currently does not set dragDropEnabled, so Tauri's default native file-drop handling can differ from browser drop behavior.
  • Clipboard: editor clipboard uses a validated Varve fragment, synchronously snapshotted DOM paste events, async browser reads, and a narrow Tauri image fallback. The canonical command, fidelity, and limitation contract is in clipboard-system.md.
  • Multi-document: current product behavior is in-app sessions/tabs in one JS heap. Browser cross-tab and Tauri multi-window shared-state semantics are not yet implemented.
  • Context menus: current editor/page/layer menus are custom in-app UI, not native Tauri menus.

Research Notes

Access date for all links: 2026-07-12.

Shipped In This Slice

  • removePage now removes the page record before deleting its content root, so development validation never observes a transient page pointing at deleted nodes.
  • Removing the active page now retargets activePageId to a surviving neighboring page.
  • setActivePage rejects ids that do not exist in Document.pages.
  • validateDocument now reports stale activePageId values.
  • DocumentCodec.normalize repairs persisted page metadata by creating an empty content-root group for pages whose root is missing, filtering missing page background references, restoring content roots into rootChildren, and selecting a valid active page.
  • Page navigation now reads document.activePageId as canonical, calls setActivePage on click/keyboard activation, and keeps currentPageId only as UI mirror state.

Prioritized Backlog

High:

  • Add a Tauri file-drop adapter or explicitly set dragDropEnabled per intended behavior, then test OS file drop on Linux/Wayland, Windows, and macOS.
  • Exercise the documented browser/Tauri clipboard matrix for custom Varve JSON, SVG, PNG, and permission-denied paths; the transport and editor integration contract is now implemented and covered by focused tests.
  • Extend codec repair to detect duplicate parentage and cycles in untrusted documents before editor state consumes them.
  • Add Playwright page-workflow coverage: create page, switch page, create shape, delete active page, save/reopen, and assert rendered/layer state.

Medium:

  • Decide and implement cross-tab or multi-window coordination. Browser likely needs BroadcastChannel or equivalent; Tauri multi-window needs explicit backend coordination.
  • Clarify page background ownership in rendering/export so background ids are either owned by page metadata or normal layer-tree nodes, not both by accident.
  • Add page export/print ordering contract tests for multi-page documents.
  • Add large-page-count performance fixtures for PageNav and LayersPanel.

Lower:

  • Native Tauri context menus for desktop if product direction requires OS-native menus.
  • Visual regression fixtures for nested frames/groups, page switching, clipping, and exported output.

Verification Notes

Directly executed this session:

  • pnpm vitest run packages/scene/src/documentCodec.test.ts packages/scene/src/__tests__/page.test.ts packages/editor/src/components/PageNav/PageNav.test.tsx packages/editor/src/__tests__/pageConfig.test.tsx packages/layout/src/__tests__/cycleDetection.test.ts packages/editor/src/startup/bootManager.test.ts packages/editor/src/startup/startupTimer.test.ts --reporter=verbose
  • pnpm --filter @varve/scene typecheck
  • pnpm --filter @varve/editor typecheck
  • pnpm typecheck
  • pnpm exec biome check on touched implementation and test files
  • pnpm test
  • pnpm audit:emoji
  • pnpm audit:tokens

Blocked by existing dirty-tree issues:

  • just format-check stops on untracked Rust formatting drift in crates/varve-bridge/tests/wgsl_validation.rs.
  • pnpm lint stops on six existing Biome error-level diagnostics outside the page-model slice: one settings tab-panel tabIndex, one NumberInput dependency warning promoted to error, and four duplicate generated custom properties in packages/ui/src/tokens/tokens.css.