--- license: mit pretty_name: tldraw snapshot history datasets size_categories: - n<1K tags: - tldraw - whiteboard - canvas - snapshots - diagrams - vector-graphics configs: - config_name: default data_files: - split: train path: data/train-* dataset_info: features: - name: filename dtype: string - name: jsonl list: - name: kind dtype: string - name: ts dtype: string - name: prev dtype: string - name: clock dtype: int64 - name: documentClock dtype: int64 - name: tombstoneHistoryStartsAtClock dtype: int64 - name: schemaJson dtype: large_string - name: documents list: large_string - name: tombstones list: - name: id dtype: string - name: clock dtype: int64 - name: documentsAdded list: large_string - name: documentsModified list: large_string - name: documentsRemoved list: string - name: tombstonesAdded list: - name: id dtype: string - name: clock dtype: int64 - name: tombstonesRemoved list: string - name: images list: image splits: - name: train num_bytes: 271866378 num_examples: 1 download_size: 542341375 dataset_size: 271866378 --- # tldraw-datasets Snapshot history datasets from [tldraw](https://tldraw.com) rooms. Each row is a single editing session (a "trajectory") from one room, captured as a sequence of periodic JSON snapshots with matching rendered PNGs. **Source and tooling:** ## Schema One row per room. Each row has three columns: | column | type | description | | ---------- | ------------------- | ----------------------------------------------------------------------------------------------------- | | `filename` | `string` | e.g. `1dUMRx3oRxs33vPdsy2uY.jsonl`. | | `jsonl` | `Sequence[struct]` | Row 0 is the initial full snapshot; rows 1..N are per-change diffs. | | `images` | `Sequence[Image]` | 1:1 with `jsonl`. `images[0]` is the initial snapshot PNG; `images[i>0]` is the state *after* diff i. | Rows where the diff has no document changes (idle periods) are dropped from both `jsonl` and `images`, so each kept frame corresponds to a real edit. ### `jsonl` item schema Each element of `jsonl` is a struct. Fields that only apply to snapshots or diffs are empty on the other kind. | field | type | notes | | --------------------------------- | ----------------- | --------------------------------------------------------------------- | | `kind` | `string` | `"snapshot"` on row 0, `"diff"` on rows 1.. | | `ts` | `string` | ISO timestamp with `:` → `-` (lex sort = chronological). | | `prev` | `string \| null` | Previous snapshot's `ts`. `null` on row 0. | | `clock` | `int64` | | | `documentClock` | `int64` | | | `tombstoneHistoryStartsAtClock` | `int64` | | | `schemaJson` | `string` | JSON-encoded tldraw schema block. | | `documents` *(snapshot only)* | `Sequence[string]`| JSON-encoded `{state, lastChangedClock}` records. | | `tombstones` *(snapshot only)* | `Sequence[struct]`| `{id, clock}`. | | `documentsAdded` *(diff only)* | `Sequence[string]`| JSON-encoded records. | | `documentsModified` *(diff only)* | `Sequence[string]`| JSON-encoded records. | | `documentsRemoved` *(diff only)* | `Sequence[string]`| Record IDs. | | `tombstonesAdded` *(diff only)* | `Sequence[struct]`| `{id, clock}`. | | `tombstonesRemoved` *(diff only)* | `Sequence[string]`| Record IDs. | > **Why JSON strings for `documents` / `schema`?** tldraw shape types have widely varying schemas (`geo`, `draw`, `arrow`, `image`, `embed`, …). Unioning all their props into one struct produces a combinatorial schema that breaks parquet. The record payloads are stored as JSON strings; call `json.loads(...)` to recover the original tldraw record. See the [`RoomSnapshot` type](https://github.com/tldraw/tldraw/blob/main/packages/sync-core/src/lib/server-types.ts) for the deserialized shape. ## Usage ```python from datasets import load_dataset ds = load_dataset("steveruizoktldraw/tldraw-datasets", split="train") row = ds[0] print(row["filename"]) # 1dUMRx3oRxs33vPdsy2uY.jsonl print(len(row["jsonl"])) # number of keyframes in the trajectory print(row["jsonl"][0]["kind"]) # 'snapshot' print(row["images"][0]) # PIL.Image of the initial state # Reconstruct the nth intermediate tldraw state: import json initial_docs = [json.loads(d) for d in row["jsonl"][0]["documents"]] ``` ## Reconstructing a full `RoomSnapshot` Replay semantics (apply diffs in order onto the initial snapshot state): ```python import json def reconstruct(jsonl, up_to: int): initial = jsonl[0] docs = {json.loads(d)["state"]["id"]: json.loads(d) for d in initial["documents"]} tombs = {t["id"]: t["clock"] for t in initial["tombstones"]} schema = json.loads(initial["schemaJson"]) for step in jsonl[1 : up_to + 1]: for s in step["documentsAdded"] + step["documentsModified"]: r = json.loads(s) docs[r["state"]["id"]] = r for rid in step["documentsRemoved"]: docs.pop(rid, None) for t in step["tombstonesAdded"]: tombs[t["id"]] = t["clock"] for rid in step["tombstonesRemoved"]: tombs.pop(rid, None) schema = json.loads(step["schemaJson"]) last = jsonl[up_to] return { "clock": last["clock"], "documentClock": last["documentClock"], "tombstoneHistoryStartsAtClock": last["tombstoneHistoryStartsAtClock"], "schema": schema, "tombstones": tombs, "documents": list(docs.values()), } ``` ## License MIT — see `LICENSE`.