# RCWeb Notepad Pro App

The **RCWeb Notepad Pro App** (`app/notepad-pro`) is a heavy-duty, professionally engineered collaborative text editor. Utilizing an advanced implementation of the **Symmetric Pattern**, it brings robust Operational Transformation (OT) mechanics, real-time cursor presence, and file uploading into the standard Notepad infrastructure.

![icon](pwa-512x512.png "Notepad Pro App Icon")

## Screenshot
![screenshot](screenshot.png "Notepad Pro App")

## What it does

- **Conflict-Free Multiplayer Editing**: Supports dozens of users typing simultaneously on the exact same line. The editor mathematically analyzes concurrent keystrokes and merges them gracefully in real-time without wiping out another user's progress.
- **Live Collaborative Presence**: Visually maps and highlights exactly where every participant's text cursor is currently situated within the document, rendering user-colored carats and real-time multiplayer text highlighting strings directly over the native `textarea`.
- **Intelligent Offline Recovery**: Maintains highly detailed local change logs. If network conditions stutter or sever momentarily, the system synchronizes historical data payloads and surgically inserts lost packets gracefully rather than forcefully rewriting the text box.
- **Import & Export Tooling**: Includes integrated file I/O capabilities. Users can instantly export their current remote collaborative session as a local `.txt` file, or upload their own `.txt` templates natively via the local device OS picker window.

## How it works

The Pro version replaces the raw string-blasting behavior of the basic Notepad app with highly orchestrated Operational Transformation (OT) calculus inside `script.js`.

- **Splice Calculus Engine**: Instead of sending the full text block (which crashes when two people edit simultaneously), `computeSplice` structurally analyzes the difference before and after an `input` event. It strips out only the precise `deleteCount` and `insertText` coordinates, transmitting incredibly small payload operations (`rc.sendFunctionCall`) targeting an exact `baseRevision` ledger state.
- **Mathematical Transformation**: When receiving simultaneous edits, `transformIncomingOperation` intercepts the data. It shifts index pointers dynamically based on the log structure (`getOperationsSince`) to algorithmically "slide" inbound operations forward or backward up the character chain so they land accurately despite lag.
- **Cursor Tracking**: Fires aggressive throttle timers (`queueCursorBroadcast` / `queueSelectionBroadcast`) binding to browser `keyup`, `click`, `select`, and `scroll`. It broadcasts X/Y scrolling values and exact DOM selection ranges, enabling remote `renderRemoteCursors()` loops to structurally overlay highly customized `div` tags containing distinct `clientPresence` colors identically over the raw text matrix.
- **History Heartbeats**: Establishes a synchronized `PERIODIC_SNAPSHOT_MS` maintenance loop sending robust state ledger hashes (`hashText`). The peer verification system evaluates these cryptographic states, instantly auto-requesting emergency backfill logs (`scheduleResync`) if desynchronization anomalies trigger.
