rmapi-js 11.1.2 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rm6.d.ts ADDED
@@ -0,0 +1,334 @@
1
+ /**
2
+ * Parse (and re-serialize) reMarkable `.rm` version 6 "scene tree" files.
3
+ *
4
+ * Version 6 is a CRDT scene tree, not a flat struct: a header then a sequence
5
+ * of length-prefixed, tagged blocks. This module reads every block faithfully
6
+ * — preserving `CrdtId`s, `LwwValue` wrappers, and each block's unread tail —
7
+ * into an {@link RmScene | `RmScene`}, whose methods resolve the CRDT into
8
+ * ordered layers, strokes, and text. Because nothing is dropped, the blocks
9
+ * round-trip back to bytes.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ /**
14
+ * a CRDT identifier: an `(authorId, counter)` pair, unique across replicas
15
+ *
16
+ * The wire encodes it positionally — a single author byte then a varuint
17
+ * counter — with no field names; the `rmscene` reference calls these `part1`
18
+ * and `part2`.
19
+ */
20
+ export interface CrdtId {
21
+ /** the author (device/replica) that minted this id, the leading wire byte */
22
+ authorId: number;
23
+ /** the author's monotonic counter (a varuint, may exceed 32 bits) */
24
+ counter: number;
25
+ }
26
+ /** the scene-tree root node id */
27
+ export declare const ROOT_ID: CrdtId;
28
+ /** the CRDT sequence end marker / unset id */
29
+ export declare const END_MARKER: CrdtId;
30
+ /** a stable string key for a {@link CrdtId | `CrdtId`} */
31
+ export declare function crdtKey(id: CrdtId): string;
32
+ /** a last-writer-wins value, a `value` stamped with a `timestamp` id */
33
+ export interface LwwValue<T> {
34
+ /** the id of the writer that last set this value */
35
+ timestamp: CrdtId;
36
+ /** the stored value */
37
+ value: T;
38
+ }
39
+ /** a single sampled point of a version 6 stroke, in native (v2) units */
40
+ export interface RmV6Point {
41
+ /** horizontal position in device pixels (centered origin, may be negative) */
42
+ x: number;
43
+ /** vertical position in device pixels (centered origin) */
44
+ y: number;
45
+ /** pen speed */
46
+ speed: number;
47
+ /** stroke width */
48
+ width: number;
49
+ /** pen direction, 0–255 mapping onto 0–2π */
50
+ direction: number;
51
+ /** pen pressure, 0–255 */
52
+ pressure: number;
53
+ }
54
+ /** a version 6 stroke */
55
+ export interface RmV6Line {
56
+ /** the raw pen/tool code */
57
+ tool: number;
58
+ /** the raw color code */
59
+ color: number;
60
+ /** the stroke thickness scale */
61
+ thicknessScale: number;
62
+ /** the length at which the stroke starts */
63
+ startingLength: number;
64
+ /** the sampled points */
65
+ points: RmV6Point[];
66
+ /**
67
+ * a packed little-endian uint32 color, only present for highlighter strokes
68
+ *
69
+ * Logical channels are RGBA, stored in BGRA byte order (the integer is
70
+ * `0xAARRGGBB`): `r = (v >> 16) & 0xff`, `g = (v >> 8) & 0xff`, `b = v &
71
+ * 0xff`, `a = (v >> 24) & 0xff`. Kept as the raw packed value.
72
+ */
73
+ colorRgba?: number;
74
+ }
75
+ /** an axis-aligned rectangle */
76
+ export interface Rectangle {
77
+ /** the left edge */
78
+ x: number;
79
+ /** the top edge */
80
+ y: number;
81
+ /** the width */
82
+ w: number;
83
+ /** the height */
84
+ h: number;
85
+ }
86
+ /** a highlighted run of underlying text */
87
+ export interface GlyphRange {
88
+ /** the start offset into the underlying text, if present */
89
+ start?: number;
90
+ /** the length of the range */
91
+ length: number;
92
+ /** the raw color code */
93
+ color: number;
94
+ /** the highlighted text */
95
+ text: string;
96
+ /** the bounding rectangles of the highlight */
97
+ rectangles: Rectangle[];
98
+ /** a packed little-endian uint32 color (RGBA channels, BGRA byte order), if present */
99
+ colorRgba?: number;
100
+ }
101
+ /** the CRDT-sequence envelope shared by every scene item */
102
+ export interface SceneItem<V> {
103
+ /** this item's own id */
104
+ itemId: CrdtId;
105
+ /** the id of the left sibling in the CRDT sequence */
106
+ leftId: CrdtId;
107
+ /** the id of the right sibling */
108
+ rightId: CrdtId;
109
+ /** how many following items this deletes */
110
+ deletedLength: number;
111
+ /** the item's value, or `undefined` if it carries none (e.g. a tombstone) */
112
+ value: V | undefined;
113
+ }
114
+ /** a text run or an inline format code within {@link RmV6Text | `RmV6Text`} */
115
+ export type RmV6TextValue = string | number;
116
+ /** the parsed document text of a page (from the root text block) */
117
+ export interface RmV6Text {
118
+ /** the text runs / inline formats as a CRDT sequence of items */
119
+ items: SceneItem<RmV6TextValue>[];
120
+ /** paragraph styles keyed by the char id they attach to */
121
+ styles: Map<string, LwwValue<number>>;
122
+ /** the text block's horizontal position */
123
+ posX: number;
124
+ /** the text block's vertical position */
125
+ posY: number;
126
+ /** the text block's width */
127
+ width: number;
128
+ }
129
+ /** fields carried by every block */
130
+ interface BlockCommon {
131
+ /** the block's minimum reader version */
132
+ minVersion: number;
133
+ /** the block's current version (selects the point encoding for lines) */
134
+ currentVersion: number;
135
+ /** the unread tail of the block, preserved for round-tripping */
136
+ extraData: Uint8Array;
137
+ }
138
+ /** the `0x00` migration info block */
139
+ export interface MigrationInfoBlock extends BlockCommon {
140
+ /** the block-type discriminant */
141
+ type: "migrationInfo";
142
+ /** the migration's crdt id */
143
+ migrationId: CrdtId;
144
+ /** whether the migration ran on the device */
145
+ isDevice: boolean;
146
+ }
147
+ /** the `0x01` scene tree block — a node/parent edge */
148
+ export interface SceneTreeBlock extends BlockCommon {
149
+ /** the block-type discriminant */
150
+ type: "sceneTree";
151
+ /** the tree entry's crdt id */
152
+ treeId: CrdtId;
153
+ /** the node this entry describes */
154
+ nodeId: CrdtId;
155
+ /** whether this is an update to an existing entry */
156
+ isUpdate: boolean;
157
+ /** the parent node's crdt id */
158
+ parentId: CrdtId;
159
+ }
160
+ /** the `0x02` tree node block — a group's metadata (layer name/visibility) */
161
+ export interface TreeNodeBlock extends BlockCommon {
162
+ /** the block-type discriminant */
163
+ type: "treeNode";
164
+ /** the node's crdt id */
165
+ nodeId: CrdtId;
166
+ /** the layer name */
167
+ label: LwwValue<string>;
168
+ /** whether the layer is visible */
169
+ visible: LwwValue<boolean>;
170
+ /** the anchor node's crdt id, if anchored */
171
+ anchorId?: LwwValue<CrdtId>;
172
+ /** the anchor type, if anchored */
173
+ anchorType?: LwwValue<number>;
174
+ /** the anchor threshold, if anchored */
175
+ anchorThreshold?: LwwValue<number>;
176
+ /** the anchor's horizontal origin, if anchored */
177
+ anchorOriginX?: LwwValue<number>;
178
+ }
179
+ /** the `0x05` scene line item block — a stroke */
180
+ export interface SceneLineItemBlock extends BlockCommon {
181
+ /** the block-type discriminant */
182
+ type: "sceneLineItem";
183
+ /** the parent group's crdt id */
184
+ parentId: CrdtId;
185
+ /** the stroke, in its crdt-sequence envelope */
186
+ item: SceneItem<RmV6Line>;
187
+ }
188
+ /** the `0x03` scene glyph item block — a text highlight */
189
+ export interface SceneGlyphItemBlock extends BlockCommon {
190
+ /** the block-type discriminant */
191
+ type: "sceneGlyphItem";
192
+ /** the parent group's crdt id */
193
+ parentId: CrdtId;
194
+ /** the highlight, in its crdt-sequence envelope */
195
+ item: SceneItem<GlyphRange>;
196
+ }
197
+ /** the `0x04` scene group item block — attaches a child node to a parent */
198
+ export interface SceneGroupItemBlock extends BlockCommon {
199
+ /** the block-type discriminant */
200
+ type: "sceneGroupItem";
201
+ /** the parent group's crdt id */
202
+ parentId: CrdtId;
203
+ /** the child node's crdt id, in its crdt-sequence envelope */
204
+ item: SceneItem<CrdtId>;
205
+ }
206
+ /** the `0x06` scene text item block — carries no parsed value */
207
+ export interface SceneTextItemBlock extends BlockCommon {
208
+ /** the block-type discriminant */
209
+ type: "sceneTextItem";
210
+ /** the parent group's crdt id */
211
+ parentId: CrdtId;
212
+ /** the (unparsed) item, in its crdt-sequence envelope */
213
+ item: SceneItem<undefined>;
214
+ }
215
+ /** the `0x08` scene tombstone item block — a deleted-item marker */
216
+ export interface SceneTombstoneItemBlock extends BlockCommon {
217
+ /** the block-type discriminant */
218
+ type: "sceneTombstone";
219
+ /** the parent group's crdt id */
220
+ parentId: CrdtId;
221
+ /** the deleted item's envelope (no value) */
222
+ item: SceneItem<undefined>;
223
+ }
224
+ /** the `0x07` root text block — the page's document text */
225
+ export interface RootTextBlock extends BlockCommon {
226
+ /** the block-type discriminant */
227
+ type: "rootText";
228
+ /** the text block's crdt id */
229
+ blockId: CrdtId;
230
+ /** the parsed document text */
231
+ text: RmV6Text;
232
+ }
233
+ /** the `0x0a` page info block */
234
+ export interface PageInfoBlock extends BlockCommon {
235
+ /** the block-type discriminant */
236
+ type: "pageInfo";
237
+ /** how many times the page has been loaded */
238
+ loadsCount: number;
239
+ /** how many times the page has been merged */
240
+ mergesCount: number;
241
+ /** the number of text characters on the page */
242
+ textCharsCount: number;
243
+ /** the number of text lines on the page */
244
+ textLinesCount: number;
245
+ /** the type-folio use count */
246
+ typeFolioUseCount: number;
247
+ }
248
+ /** the `0x09` author ids block — the author-id to uuid table */
249
+ export interface AuthorIdsBlock extends BlockCommon {
250
+ /** the block-type discriminant */
251
+ type: "authorIds";
252
+ /** the author-id to uuid table */
253
+ authors: Map<number, string>;
254
+ }
255
+ /** the `0x0d` scene info block */
256
+ export interface SceneInfoBlock extends BlockCommon {
257
+ /** the block-type discriminant */
258
+ type: "sceneInfo";
259
+ /** the currently-selected layer's crdt id */
260
+ currentLayer: LwwValue<CrdtId>;
261
+ /** whether the background is visible */
262
+ backgroundVisible?: LwwValue<boolean>;
263
+ /** whether the underlying document is visible */
264
+ rootDocumentVisible?: LwwValue<boolean>;
265
+ /** the page size in device pixels, if present */
266
+ paperSize?: [number, number];
267
+ }
268
+ /** a block whose type we don't parse, kept verbatim for round-tripping */
269
+ export interface UnknownBlock extends BlockCommon {
270
+ /** the block-type discriminant */
271
+ type: "unknown";
272
+ /** the raw numeric block type */
273
+ blockType: number;
274
+ /** the raw block body bytes */
275
+ data: Uint8Array;
276
+ }
277
+ /** any parsed version 6 block */
278
+ export type RmBlock = MigrationInfoBlock | SceneTreeBlock | TreeNodeBlock | SceneLineItemBlock | SceneGlyphItemBlock | SceneGroupItemBlock | SceneTextItemBlock | SceneTombstoneItemBlock | RootTextBlock | PageInfoBlock | AuthorIdsBlock | SceneInfoBlock | UnknownBlock;
279
+ /** a resolved item within a layer, in CRDT order */
280
+ export type RmSceneItem = {
281
+ /** the item discriminant */
282
+ kind: "layer";
283
+ /** a nested layer (scene-tree group) */
284
+ layer: RmSceneLayer;
285
+ } | {
286
+ /** the item discriminant */
287
+ kind: "line";
288
+ /** a stroke */
289
+ line: RmV6Line;
290
+ } | {
291
+ /** the item discriminant */
292
+ kind: "glyph";
293
+ /** a text highlight */
294
+ glyph: GlyphRange;
295
+ };
296
+ /** a resolved drawing layer (a scene-tree group) */
297
+ export interface RmSceneLayer {
298
+ /** the group's crdt id */
299
+ id: CrdtId;
300
+ /** the layer name, if set */
301
+ label?: string;
302
+ /** whether the layer is visible, if set */
303
+ visible?: boolean;
304
+ /** the layer's items (nested layers, strokes, glyphs) in CRDT order */
305
+ items: RmSceneItem[];
306
+ }
307
+ /**
308
+ * a parsed version 6 scene
309
+ *
310
+ * The raw {@link RmBlock | `blocks`} are the faithful source of truth (they
311
+ * preserve the CRDT ids and re-serialize); the methods resolve them into
312
+ * ordered layers, strokes, and text.
313
+ */
314
+ export declare class RmScene {
315
+ #private;
316
+ /** the discriminant for the {@link RmPage} union */
317
+ readonly version: 6;
318
+ /** every parsed block, in file order */
319
+ readonly blocks: readonly RmBlock[];
320
+ /** the author-id to uuid table */
321
+ readonly authors: Map<number, string>;
322
+ /** the page size, if the scene info block carried one */
323
+ readonly paperSize?: [number, number];
324
+ constructor(blocks: readonly RmBlock[]);
325
+ /** the drawing layers, in order, each with its items */
326
+ layers(): RmSceneLayer[];
327
+ /** every stroke on the page, in draw order, flattened across layers */
328
+ strokes(): RmV6Line[];
329
+ /** the page's document text, if any */
330
+ text(): RmV6Text | undefined;
331
+ }
332
+ /** parse a version 6 `.rm` file into a resolvable scene */
333
+ export declare function parseRmScene(data: Uint8Array): RmScene;
334
+ export {};