rooms-kit / types / board / index.d.ts
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
 * Hand-authored declarations for the "./board" export of ardegazu-rooms-kit —
 * the compiled dist/board/index.js (ClojureScript). Mirrors the v1.0.0
 * TypeScript API surface exactly.
 */
import { EventEmitter } from "node:events";
import type { Identity } from "ardegazu-id-kit";
import type { Net, RoomLog, RelayConfig } from "../index.js";

export const BOARD_SALT: "board.ardegazu.ro/v1";

/** 32 random bytes, base64url unpadded (43 chars) — the room capability. */
export declare function newRoomSecret(): string;

/** Board element spec; `stroke` is what the pen tool (and the bot) produces. */
export interface StrokeSpec {
  id: string;
  k: "stroke";
  x: number;
  y: number;
  /** Flat [dx0,dy0,…] fixed-point ints (world*100), delta-encoded from (x,y). */
  pts: number[];
  prs?: number[];
  w: number;
  c: number;
}

export type BoardElement = Record<string, unknown> & { id: string; k: string };

export interface BoardOptions {
  roomSecret: string;
  name: string;
  dataDir: string;
  identity?: Identity | null;
  appSalt?: string;
  origin?: string;
  relay?: Partial<RelayConfig>;
}

export interface BoardEvents {
  /**
   * A logged `add` landed. A duplicate add for a live element id folds to the
   * EARLIEST (clock, hash) — the same rule the browser applies — so an add
   * that loses the fold changes nothing and does NOT emit.
   */
  element: [el: BoardElement, from: string];
  /**
   * A logged `edit` landed. Racing edits fold per (element id, field), so a
   * patch may be applied only in part; when every field of it loses the fold
   * nothing is emitted at all. The patch reported is the one on the wire —
   * `elements()` is the authority on what actually landed.
   */
  edited: [id: string, patch: Record<string, unknown>];
  deleted: [ids: string[]];
  peer: [id: string, name: string | undefined];
  peerGone: [id: string];
  ready: [];
  status: [up: boolean];
}

export declare class BoardClient extends EventEmitter<BoardEvents> {
  readonly net: Net;
  readonly log: RoomLog;
  readonly roomId: string;

  static join(opts: BoardOptions): Promise<BoardClient>;

  elements(): BoardElement[];
  /**
   * Draw a stroke: stream live preview segments at the pen cadence, then commit
   * the add op. `points` are absolute world coordinates.
   */
  drawStroke(points: { x: number; y: number }[], style?: { width?: number; color?: number }): Promise<string>;
  addText(x: number, y: number, text: string, opts?: { size?: number; color?: number }): Promise<string>;
  erase(ids: string[]): Promise<void>;
  close(): Promise<void>;
  private constructor();
}

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/rooms-kit.git