🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Premirror

Premirror is a library for building Word-class page-layout editors on the web. It layers deterministic pagination and composition on top of ProseMirror, giving you paper-style page breaks, widow/orphan control, and fragment-level text positioning β€” all while keeping ProseMirror as the single source of truth for document content and editing.

Live demo β€” samwillis.uk/premirror

How It Works

ProseMirror owns the document model and all editing operations. Premirror's composer takes a measured snapshot of the document and produces a deterministic layout: pages, frames, line boxes, and placed runs. A React rendering layer then projects those fragments into absolute positions inside page-chrome viewports, producing a word-processor-style paged view with a single contenteditable surface.

EditorState ──► snapshot ──► measure (pretext) ──► compose ──► LayoutOutput
                                                                   β”‚
                                                    decorations β—„β”€β”€β”˜
                                                        β”‚
                                              PremirrorPageViewport

Text measurement is handled by @chenglou/pretext, which provides segment-aware width calculation and line fitting.

Packages

This is a Bun workspace monorepo. All packages expose TypeScript sources directly.

Package Path Description
@premirror/core packages/core Shared types, page specs, layout contracts, and configuration defaults
@premirror/composer packages/composer Pagination and composition engine β€” line breaking, page flow, widow/orphan policies
@premirror/prosemirror-adapter packages/prosemirror-adapter ProseMirror bridge: snapshot extraction, mark-aware measurement, invalidation plugin, commands
@premirror/react packages/react React hooks and components: usePremirrorEngine, PremirrorPageViewport, selection projection
@premirror/demo-app apps/demo Reference app demonstrating paged editing with toolbar, debug overlays, and timing readout

Development

Requires Bun β‰₯ 1.3.

bun install
bun dev        # starts the Vite dev server for the demo app

Build and checks

bun run build      # typecheck + build all packages and the demo app
bun run typecheck  # typecheck only
bun run lint       # tsc --noEmit across all workspaces
bun run test       # bun test across all workspaces
bun run benchmark  # run composer benchmark

Tech Stack

  • Runtime / package manager β€” Bun
  • Language β€” TypeScript (strict)
  • Editor β€” ProseMirror, with @handlewithcare/react-prosemirror for React integration
  • Text measurement β€” @chenglou/pretext
  • UI β€” React 19, Base UI, Vite
  • Testing β€” Bun test runner

Documentation

License

MIT

About

Premirror is a library for building Word-class page-layout editors on the web

Resources

Stars

76 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages