canvu-react 0.3.5

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/camera-BwQjm5oh.d.cts +50 -0
  4. package/dist/camera-KwCYYPhm.d.ts +50 -0
  5. package/dist/chatbot.cjs +221 -0
  6. package/dist/chatbot.cjs.map +1 -0
  7. package/dist/chatbot.d.cts +36 -0
  8. package/dist/chatbot.d.ts +36 -0
  9. package/dist/chatbot.js +218 -0
  10. package/dist/chatbot.js.map +1 -0
  11. package/dist/index.cjs +1920 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +276 -0
  14. package/dist/index.d.ts +276 -0
  15. package/dist/index.js +1867 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/native.cjs +2572 -0
  18. package/dist/native.cjs.map +1 -0
  19. package/dist/native.d.cts +217 -0
  20. package/dist/native.d.ts +217 -0
  21. package/dist/native.js +2562 -0
  22. package/dist/native.js.map +1 -0
  23. package/dist/react.cjs +8540 -0
  24. package/dist/react.cjs.map +1 -0
  25. package/dist/react.d.cts +481 -0
  26. package/dist/react.d.ts +481 -0
  27. package/dist/react.js +8492 -0
  28. package/dist/react.js.map +1 -0
  29. package/dist/realtime.cjs +2338 -0
  30. package/dist/realtime.cjs.map +1 -0
  31. package/dist/realtime.d.cts +309 -0
  32. package/dist/realtime.d.ts +309 -0
  33. package/dist/realtime.js +2317 -0
  34. package/dist/realtime.js.map +1 -0
  35. package/dist/shape-builders-DTYvub8W.d.ts +93 -0
  36. package/dist/shape-builders-DxPoOecg.d.cts +93 -0
  37. package/dist/tldraw.cjs +1948 -0
  38. package/dist/tldraw.cjs.map +1 -0
  39. package/dist/tldraw.d.cts +98 -0
  40. package/dist/tldraw.d.ts +98 -0
  41. package/dist/tldraw.js +1941 -0
  42. package/dist/tldraw.js.map +1 -0
  43. package/dist/types--ALu1mF-.d.ts +356 -0
  44. package/dist/types-B58i5k-u.d.cts +35 -0
  45. package/dist/types-CB0TZZuk.d.cts +157 -0
  46. package/dist/types-CB0TZZuk.d.ts +157 -0
  47. package/dist/types-D1ftVsOQ.d.cts +356 -0
  48. package/dist/types-DgEArHkA.d.ts +35 -0
  49. package/package.json +103 -0
@@ -0,0 +1,309 @@
1
+ import { P as PlacementPreview, R as RemotePresenceMarkupStroke, q as RemotePresencePeer, r as RealtimeConnectionState, j as VectorViewportHandle, V as VectorToolDefinition, k as VectorViewportProps, C as CanvasPlugin, d as CanvasPluginRenderContext } from './types-D1ftVsOQ.cjs';
2
+ export { s as PresenceOverlayRenderContext } from './types-D1ftVsOQ.cjs';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { C as Camera2D } from './camera-BwQjm5oh.cjs';
5
+ import { V as VectorSceneItem, R as Rect } from './types-CB0TZZuk.cjs';
6
+ import { ReactNode, RefObject } from 'react';
7
+ import { a as VectorCanvasRemoteAdapter } from './types-B58i5k-u.cjs';
8
+
9
+ /**
10
+ * Maps a local {@link PlacementPreview} stroke to {@link RemotePresenceMarkupStroke} for broadcasting.
11
+ * Returns `null` when there is no in-progress stroke.
12
+ */
13
+ declare function remoteMarkupStrokeFromPlacementPreview(preview: PlacementPreview | null): RemotePresenceMarkupStroke | null;
14
+
15
+ type PresenceRemoteLayerProps = {
16
+ camera: Camera2D;
17
+ /** Bump when camera changes (same as {@link InteractionOverlay}). */
18
+ cameraVersion: number;
19
+ peers: readonly RemotePresencePeer[];
20
+ };
21
+ /**
22
+ * World-space SVG overlay: remote cursors + in-progress markup strokes.
23
+ * Usually passed via {@link VectorViewport} `remotePresence` or `presenceOverlay`.
24
+ */
25
+ declare function PresenceRemoteLayer({ camera, cameraVersion: _cameraVersion, peers, }: PresenceRemoteLayerProps): react_jsx_runtime.JSX.Element;
26
+
27
+ /**
28
+ * Deterministic accent from a peer id when `color` is not provided.
29
+ */
30
+ declare function defaultPresenceColorForId(id: string): string;
31
+
32
+ type RealtimeSessionPeer = RemotePresencePeer & {
33
+ readonly clientId: string;
34
+ readonly peerId: string;
35
+ readonly roomId: string;
36
+ readonly joinedAt: number;
37
+ readonly lastSeenAt: number;
38
+ readonly isSelf: boolean;
39
+ readonly connectionState?: RealtimeConnectionState;
40
+ };
41
+ type RealtimeDocumentSnapshot = {
42
+ readonly revision: number;
43
+ readonly items: VectorSceneItem[];
44
+ readonly updatedAt: number;
45
+ readonly updatedByClientId?: string;
46
+ };
47
+ type RealtimeConnectionInfo = {
48
+ readonly state: RealtimeConnectionState;
49
+ readonly connected: boolean;
50
+ readonly roomId: string;
51
+ readonly clientId: string | null;
52
+ readonly retryCount: number;
53
+ readonly lastConnectedAt: number | null;
54
+ readonly lastMessageAt: number | null;
55
+ readonly lastPongAt: number | null;
56
+ readonly lastError: string | null;
57
+ };
58
+ type RealtimePresencePayload = {
59
+ readonly cursor: {
60
+ readonly x: number;
61
+ readonly y: number;
62
+ } | null;
63
+ readonly markupStroke?: RemotePresenceMarkupStroke | null;
64
+ readonly activeTool?: string;
65
+ };
66
+ type RealtimeClientPeer = {
67
+ readonly clientId: string;
68
+ readonly peerId: string;
69
+ readonly displayName?: string;
70
+ readonly color?: string;
71
+ readonly image?: string;
72
+ };
73
+ type RealtimeClientMessage = {
74
+ readonly type: "session:join";
75
+ readonly roomId: string;
76
+ readonly peer: RealtimeClientPeer;
77
+ } | {
78
+ readonly type: "session:leave";
79
+ readonly roomId: string;
80
+ readonly clientId: string;
81
+ } | {
82
+ readonly type: "session:ping";
83
+ readonly roomId: string;
84
+ readonly clientId: string;
85
+ readonly sentAt: number;
86
+ } | {
87
+ readonly type: "presence:update";
88
+ readonly roomId: string;
89
+ readonly clientId: string;
90
+ readonly presence: RealtimePresencePayload;
91
+ } | {
92
+ readonly type: "document:update";
93
+ readonly roomId: string;
94
+ readonly clientId: string;
95
+ readonly baseRevision: number;
96
+ readonly items: VectorSceneItem[];
97
+ };
98
+ type RealtimeServerMessage = {
99
+ readonly type: "session:welcome";
100
+ readonly roomId: string;
101
+ readonly clientId: string;
102
+ readonly serverTime: number;
103
+ readonly document: RealtimeDocumentSnapshot;
104
+ readonly peers: RealtimeSessionPeer[];
105
+ } | {
106
+ readonly type: "session:peer-joined";
107
+ readonly roomId: string;
108
+ readonly peer: RealtimeSessionPeer;
109
+ } | {
110
+ readonly type: "session:peer-left";
111
+ readonly roomId: string;
112
+ readonly clientId: string;
113
+ } | {
114
+ readonly type: "session:pong";
115
+ readonly roomId: string;
116
+ readonly clientId: string;
117
+ readonly sentAt: number;
118
+ readonly serverTime: number;
119
+ } | {
120
+ readonly type: "session:error";
121
+ readonly roomId?: string;
122
+ readonly code: string;
123
+ readonly message: string;
124
+ } | {
125
+ readonly type: "presence:sync";
126
+ readonly roomId: string;
127
+ readonly peers: RealtimeSessionPeer[];
128
+ readonly serverTime: number;
129
+ } | {
130
+ readonly type: "document:sync";
131
+ readonly roomId: string;
132
+ readonly document: RealtimeDocumentSnapshot;
133
+ } | {
134
+ readonly type: "document:resync-required";
135
+ readonly roomId: string;
136
+ readonly reason: string;
137
+ readonly document: RealtimeDocumentSnapshot;
138
+ };
139
+ declare function parseRealtimeClientMessage(value: unknown): RealtimeClientMessage | undefined;
140
+ declare function parseRealtimeServerMessage(value: unknown): RealtimeServerMessage | undefined;
141
+
142
+ type RealtimeSessionPanelProps = {
143
+ /** @default "Session" */
144
+ title?: string;
145
+ /** Shown in the participant list (ids + optional display names from your presence layer). */
146
+ peers: readonly (RealtimeSessionPeer | {
147
+ id: string;
148
+ displayName?: string;
149
+ color?: string;
150
+ image?: string;
151
+ isSelf?: boolean;
152
+ })[];
153
+ /** @default true */
154
+ connected?: boolean;
155
+ connectionState?: RealtimeConnectionState;
156
+ roomId?: string;
157
+ children?: ReactNode;
158
+ };
159
+ /**
160
+ * Minimal roster + connection status, top-center above the viewport.
161
+ * Pair with {@link realtimeSessionPlugin} and {@link VectorViewport} presence props.
162
+ */
163
+ declare function RealtimeSessionPanel({ title, peers, connected, connectionState, roomId, children, }: RealtimeSessionPanelProps): react_jsx_runtime.JSX.Element;
164
+
165
+ type RealtimeCommentsAuthor = {
166
+ peerId: string;
167
+ displayName: string;
168
+ color: string;
169
+ image?: string;
170
+ };
171
+ type UseRealtimeCommentsOptions = {
172
+ items: readonly VectorSceneItem[];
173
+ onItemsChange: (items: VectorSceneItem[]) => void;
174
+ author: RealtimeCommentsAuthor;
175
+ viewportRef?: RefObject<VectorViewportHandle | null>;
176
+ activeToolId?: string;
177
+ roomId?: string;
178
+ setToolId?: (toolId: string) => void;
179
+ toolAfterDraft?: string;
180
+ tools?: readonly VectorToolDefinition[];
181
+ composerTitle?: string;
182
+ composerDescription?: string;
183
+ composerPlaceholder?: string;
184
+ cancelLabel?: string;
185
+ submitLabel?: string;
186
+ submitHint?: string;
187
+ };
188
+ type RealtimeCommentsViewportBindings = Pick<VectorViewportProps, "customPlacement" | "onItemsChange" | "onCameraChange">;
189
+ type UseRealtimeCommentsResult = {
190
+ tools: VectorToolDefinition[];
191
+ overlay: ReactNode;
192
+ viewport: RealtimeCommentsViewportBindings;
193
+ isComposerOpen: boolean;
194
+ closeComposer: () => void;
195
+ };
196
+ declare function useRealtimeComments({ items, onItemsChange, author, viewportRef, activeToolId, roomId, setToolId, toolAfterDraft, tools: providedTools, composerTitle, composerDescription, composerPlaceholder, cancelLabel, submitLabel, submitHint, }: UseRealtimeCommentsOptions): UseRealtimeCommentsResult;
197
+
198
+ type RealtimeSessionPeerInput = {
199
+ id: string;
200
+ displayName?: string;
201
+ color?: string;
202
+ image?: string;
203
+ clientId?: string;
204
+ };
205
+ type UseRealtimeSessionOptions = {
206
+ url: string;
207
+ roomId: string;
208
+ peer: RealtimeSessionPeerInput;
209
+ enabled?: boolean;
210
+ reconnect?: boolean;
211
+ heartbeatMs?: number;
212
+ maxReconnectDelayMs?: number;
213
+ initialReconnectDelayMs?: number;
214
+ connectTimeoutMs?: number;
215
+ onError?: (message: string) => void;
216
+ };
217
+ type RealtimeViewportPresenceBindings = Pick<VectorViewportProps, "remotePresence" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange">;
218
+ type UseRealtimeSessionResult = {
219
+ connection: RealtimeConnectionInfo;
220
+ sessionPeers: RealtimeSessionPeer[];
221
+ remotePresence: RealtimeSessionPeer[];
222
+ remoteAdapter: VectorCanvasRemoteAdapter;
223
+ document: RealtimeDocumentSnapshot | null;
224
+ bindViewportPresence: (options?: {
225
+ activeTool?: string;
226
+ }) => RealtimeViewportPresenceBindings;
227
+ disconnect: () => void;
228
+ reconnectNow: () => void;
229
+ };
230
+ declare function useRealtimeSession(options: UseRealtimeSessionOptions): UseRealtimeSessionResult;
231
+
232
+ type RealtimeCollaborationPluginOptions = UseRealtimeSessionOptions & {
233
+ /** Enable or disable the built-in session panel. Default: `true`. */
234
+ showSessionPanel?: boolean;
235
+ /** Optional visual customization for the built-in session panel. */
236
+ sessionPanel?: Partial<Omit<RealtimeSessionPanelProps, "peers" | "connected" | "connectionState" | "roomId">>;
237
+ /**
238
+ * Enable or configure the built-in collaborative comments experience.
239
+ *
240
+ * Pass `false` to disable comments entirely. When omitted, comments are enabled.
241
+ */
242
+ comments?: false | Omit<UseRealtimeCommentsOptions, "items" | "onItemsChange" | "author" | "viewportRef" | "roomId" | "setToolId">;
243
+ };
244
+ /**
245
+ * High-level plug and play collaboration plugin for `VectorViewport`.
246
+ *
247
+ * Use this when you want realtime presence, session UI, collaborative comments, and document sync
248
+ * without manually wiring `useRealtimeSession`, `useRealtimeComments`, or extra viewport props.
249
+ *
250
+ * For advanced customizations and bespoke UIs, use `useRealtimeSession(...)` and
251
+ * `useRealtimeComments(...)` directly.
252
+ */
253
+ declare function realtimeCollaborationPlugin(options: RealtimeCollaborationPluginOptions): CanvasPlugin;
254
+
255
+ type RealtimeCommentData = {
256
+ body: string;
257
+ createdAt: number;
258
+ authorPeerId: string;
259
+ authorDisplayName: string;
260
+ authorColor: string;
261
+ authorImage: string;
262
+ };
263
+ type RealtimeCommentsOverlayProps = {
264
+ items: readonly VectorSceneItem[];
265
+ onItemsChange?: (items: VectorSceneItem[]) => void;
266
+ isDragEnabled?: boolean;
267
+ cameraVersion: number;
268
+ viewportRef?: CanvasPluginRenderContext["viewportRef"];
269
+ };
270
+ type RealtimeCommentsPluginOptions = Omit<RealtimeCommentsOverlayProps, "viewportRef">;
271
+ /** Dedicated collaboration tool; unlike `text`, this opens a comment composer flow. */
272
+ declare const REALTIME_COMMENT_TOOL: VectorToolDefinition;
273
+ /**
274
+ * Generates a tiny inline avatar so comments carry a portable visual identity even without a user photo API.
275
+ */
276
+ declare function createRealtimeCommentAvatarDataUrl(displayName: string, color: string): string;
277
+ declare function createRealtimeCommentDraftItem(id: string, bounds: Rect, seedColor?: string): VectorSceneItem;
278
+ declare function createRealtimeCommentItem(id: string, bounds: Rect, comment: RealtimeCommentData): VectorSceneItem;
279
+ declare function isRealtimeCommentDraftItem(item: VectorSceneItem): boolean;
280
+ declare function isRealtimeCommentItem(item: VectorSceneItem): boolean;
281
+ declare function getRealtimeCommentData(item: VectorSceneItem): RealtimeCommentData | null;
282
+ /**
283
+ * Adds the comment tool without replacing the native text tool.
284
+ * By default it is inserted right after `text`, or appended when `text` is absent.
285
+ */
286
+ declare function withRealtimeCommentTool(tools: readonly VectorToolDefinition[]): VectorToolDefinition[];
287
+ declare function RealtimeCommentsOverlay({ items, onItemsChange, isDragEnabled, cameraVersion, viewportRef, }: RealtimeCommentsOverlayProps): react_jsx_runtime.JSX.Element | null;
288
+ declare function realtimeCommentsPlugin(options: RealtimeCommentsPluginOptions): CanvasPlugin;
289
+
290
+ type RealtimeSessionPluginOptions = RealtimeSessionPanelProps;
291
+ /**
292
+ * Optional UI roster for who is in the session (your WebSocket layer fills `peers`).
293
+ * World-space cursors and strokes use {@link VectorViewport} `remotePresence` and
294
+ * `onWorldPointerMove` — this plugin only renders a small panel in the viewport plugin layer.
295
+ *
296
+ * @example
297
+ * ```tsx
298
+ * <VectorViewport
299
+ * items={doc.items}
300
+ * onItemsChange={doc.onItemsChange}
301
+ * plugins={[
302
+ * realtimeSessionPlugin({ peers: presenceRoster, connected: wsOpen }),
303
+ * ]}
304
+ * />
305
+ * ```
306
+ */
307
+ declare function realtimeSessionPlugin(options: RealtimeSessionPluginOptions): CanvasPlugin;
308
+
309
+ export { PresenceRemoteLayer, type PresenceRemoteLayerProps, REALTIME_COMMENT_TOOL, type RealtimeClientMessage, type RealtimeCollaborationPluginOptions, type RealtimeCommentData, type RealtimeCommentsAuthor, RealtimeCommentsOverlay, type RealtimeCommentsOverlayProps, type RealtimeCommentsPluginOptions, type RealtimeCommentsViewportBindings, type RealtimeConnectionInfo, RealtimeConnectionState, type RealtimeDocumentSnapshot, type RealtimePresencePayload, type RealtimeServerMessage, RealtimeSessionPanel, type RealtimeSessionPanelProps, type RealtimeSessionPeer, type RealtimeSessionPluginOptions, type RealtimeViewportPresenceBindings, RemotePresenceMarkupStroke, RemotePresencePeer, type UseRealtimeCommentsOptions, type UseRealtimeCommentsResult, type UseRealtimeSessionOptions, type UseRealtimeSessionResult, createRealtimeCommentAvatarDataUrl, createRealtimeCommentDraftItem, createRealtimeCommentItem, defaultPresenceColorForId, getRealtimeCommentData, isRealtimeCommentDraftItem, isRealtimeCommentItem, parseRealtimeClientMessage, parseRealtimeServerMessage, realtimeCollaborationPlugin, realtimeCommentsPlugin, realtimeSessionPlugin, remoteMarkupStrokeFromPlacementPreview, useRealtimeComments, useRealtimeSession, withRealtimeCommentTool };
@@ -0,0 +1,309 @@
1
+ import { P as PlacementPreview, R as RemotePresenceMarkupStroke, q as RemotePresencePeer, r as RealtimeConnectionState, j as VectorViewportHandle, V as VectorToolDefinition, k as VectorViewportProps, C as CanvasPlugin, d as CanvasPluginRenderContext } from './types--ALu1mF-.js';
2
+ export { s as PresenceOverlayRenderContext } from './types--ALu1mF-.js';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { C as Camera2D } from './camera-KwCYYPhm.js';
5
+ import { V as VectorSceneItem, R as Rect } from './types-CB0TZZuk.js';
6
+ import { ReactNode, RefObject } from 'react';
7
+ import { a as VectorCanvasRemoteAdapter } from './types-DgEArHkA.js';
8
+
9
+ /**
10
+ * Maps a local {@link PlacementPreview} stroke to {@link RemotePresenceMarkupStroke} for broadcasting.
11
+ * Returns `null` when there is no in-progress stroke.
12
+ */
13
+ declare function remoteMarkupStrokeFromPlacementPreview(preview: PlacementPreview | null): RemotePresenceMarkupStroke | null;
14
+
15
+ type PresenceRemoteLayerProps = {
16
+ camera: Camera2D;
17
+ /** Bump when camera changes (same as {@link InteractionOverlay}). */
18
+ cameraVersion: number;
19
+ peers: readonly RemotePresencePeer[];
20
+ };
21
+ /**
22
+ * World-space SVG overlay: remote cursors + in-progress markup strokes.
23
+ * Usually passed via {@link VectorViewport} `remotePresence` or `presenceOverlay`.
24
+ */
25
+ declare function PresenceRemoteLayer({ camera, cameraVersion: _cameraVersion, peers, }: PresenceRemoteLayerProps): react_jsx_runtime.JSX.Element;
26
+
27
+ /**
28
+ * Deterministic accent from a peer id when `color` is not provided.
29
+ */
30
+ declare function defaultPresenceColorForId(id: string): string;
31
+
32
+ type RealtimeSessionPeer = RemotePresencePeer & {
33
+ readonly clientId: string;
34
+ readonly peerId: string;
35
+ readonly roomId: string;
36
+ readonly joinedAt: number;
37
+ readonly lastSeenAt: number;
38
+ readonly isSelf: boolean;
39
+ readonly connectionState?: RealtimeConnectionState;
40
+ };
41
+ type RealtimeDocumentSnapshot = {
42
+ readonly revision: number;
43
+ readonly items: VectorSceneItem[];
44
+ readonly updatedAt: number;
45
+ readonly updatedByClientId?: string;
46
+ };
47
+ type RealtimeConnectionInfo = {
48
+ readonly state: RealtimeConnectionState;
49
+ readonly connected: boolean;
50
+ readonly roomId: string;
51
+ readonly clientId: string | null;
52
+ readonly retryCount: number;
53
+ readonly lastConnectedAt: number | null;
54
+ readonly lastMessageAt: number | null;
55
+ readonly lastPongAt: number | null;
56
+ readonly lastError: string | null;
57
+ };
58
+ type RealtimePresencePayload = {
59
+ readonly cursor: {
60
+ readonly x: number;
61
+ readonly y: number;
62
+ } | null;
63
+ readonly markupStroke?: RemotePresenceMarkupStroke | null;
64
+ readonly activeTool?: string;
65
+ };
66
+ type RealtimeClientPeer = {
67
+ readonly clientId: string;
68
+ readonly peerId: string;
69
+ readonly displayName?: string;
70
+ readonly color?: string;
71
+ readonly image?: string;
72
+ };
73
+ type RealtimeClientMessage = {
74
+ readonly type: "session:join";
75
+ readonly roomId: string;
76
+ readonly peer: RealtimeClientPeer;
77
+ } | {
78
+ readonly type: "session:leave";
79
+ readonly roomId: string;
80
+ readonly clientId: string;
81
+ } | {
82
+ readonly type: "session:ping";
83
+ readonly roomId: string;
84
+ readonly clientId: string;
85
+ readonly sentAt: number;
86
+ } | {
87
+ readonly type: "presence:update";
88
+ readonly roomId: string;
89
+ readonly clientId: string;
90
+ readonly presence: RealtimePresencePayload;
91
+ } | {
92
+ readonly type: "document:update";
93
+ readonly roomId: string;
94
+ readonly clientId: string;
95
+ readonly baseRevision: number;
96
+ readonly items: VectorSceneItem[];
97
+ };
98
+ type RealtimeServerMessage = {
99
+ readonly type: "session:welcome";
100
+ readonly roomId: string;
101
+ readonly clientId: string;
102
+ readonly serverTime: number;
103
+ readonly document: RealtimeDocumentSnapshot;
104
+ readonly peers: RealtimeSessionPeer[];
105
+ } | {
106
+ readonly type: "session:peer-joined";
107
+ readonly roomId: string;
108
+ readonly peer: RealtimeSessionPeer;
109
+ } | {
110
+ readonly type: "session:peer-left";
111
+ readonly roomId: string;
112
+ readonly clientId: string;
113
+ } | {
114
+ readonly type: "session:pong";
115
+ readonly roomId: string;
116
+ readonly clientId: string;
117
+ readonly sentAt: number;
118
+ readonly serverTime: number;
119
+ } | {
120
+ readonly type: "session:error";
121
+ readonly roomId?: string;
122
+ readonly code: string;
123
+ readonly message: string;
124
+ } | {
125
+ readonly type: "presence:sync";
126
+ readonly roomId: string;
127
+ readonly peers: RealtimeSessionPeer[];
128
+ readonly serverTime: number;
129
+ } | {
130
+ readonly type: "document:sync";
131
+ readonly roomId: string;
132
+ readonly document: RealtimeDocumentSnapshot;
133
+ } | {
134
+ readonly type: "document:resync-required";
135
+ readonly roomId: string;
136
+ readonly reason: string;
137
+ readonly document: RealtimeDocumentSnapshot;
138
+ };
139
+ declare function parseRealtimeClientMessage(value: unknown): RealtimeClientMessage | undefined;
140
+ declare function parseRealtimeServerMessage(value: unknown): RealtimeServerMessage | undefined;
141
+
142
+ type RealtimeSessionPanelProps = {
143
+ /** @default "Session" */
144
+ title?: string;
145
+ /** Shown in the participant list (ids + optional display names from your presence layer). */
146
+ peers: readonly (RealtimeSessionPeer | {
147
+ id: string;
148
+ displayName?: string;
149
+ color?: string;
150
+ image?: string;
151
+ isSelf?: boolean;
152
+ })[];
153
+ /** @default true */
154
+ connected?: boolean;
155
+ connectionState?: RealtimeConnectionState;
156
+ roomId?: string;
157
+ children?: ReactNode;
158
+ };
159
+ /**
160
+ * Minimal roster + connection status, top-center above the viewport.
161
+ * Pair with {@link realtimeSessionPlugin} and {@link VectorViewport} presence props.
162
+ */
163
+ declare function RealtimeSessionPanel({ title, peers, connected, connectionState, roomId, children, }: RealtimeSessionPanelProps): react_jsx_runtime.JSX.Element;
164
+
165
+ type RealtimeCommentsAuthor = {
166
+ peerId: string;
167
+ displayName: string;
168
+ color: string;
169
+ image?: string;
170
+ };
171
+ type UseRealtimeCommentsOptions = {
172
+ items: readonly VectorSceneItem[];
173
+ onItemsChange: (items: VectorSceneItem[]) => void;
174
+ author: RealtimeCommentsAuthor;
175
+ viewportRef?: RefObject<VectorViewportHandle | null>;
176
+ activeToolId?: string;
177
+ roomId?: string;
178
+ setToolId?: (toolId: string) => void;
179
+ toolAfterDraft?: string;
180
+ tools?: readonly VectorToolDefinition[];
181
+ composerTitle?: string;
182
+ composerDescription?: string;
183
+ composerPlaceholder?: string;
184
+ cancelLabel?: string;
185
+ submitLabel?: string;
186
+ submitHint?: string;
187
+ };
188
+ type RealtimeCommentsViewportBindings = Pick<VectorViewportProps, "customPlacement" | "onItemsChange" | "onCameraChange">;
189
+ type UseRealtimeCommentsResult = {
190
+ tools: VectorToolDefinition[];
191
+ overlay: ReactNode;
192
+ viewport: RealtimeCommentsViewportBindings;
193
+ isComposerOpen: boolean;
194
+ closeComposer: () => void;
195
+ };
196
+ declare function useRealtimeComments({ items, onItemsChange, author, viewportRef, activeToolId, roomId, setToolId, toolAfterDraft, tools: providedTools, composerTitle, composerDescription, composerPlaceholder, cancelLabel, submitLabel, submitHint, }: UseRealtimeCommentsOptions): UseRealtimeCommentsResult;
197
+
198
+ type RealtimeSessionPeerInput = {
199
+ id: string;
200
+ displayName?: string;
201
+ color?: string;
202
+ image?: string;
203
+ clientId?: string;
204
+ };
205
+ type UseRealtimeSessionOptions = {
206
+ url: string;
207
+ roomId: string;
208
+ peer: RealtimeSessionPeerInput;
209
+ enabled?: boolean;
210
+ reconnect?: boolean;
211
+ heartbeatMs?: number;
212
+ maxReconnectDelayMs?: number;
213
+ initialReconnectDelayMs?: number;
214
+ connectTimeoutMs?: number;
215
+ onError?: (message: string) => void;
216
+ };
217
+ type RealtimeViewportPresenceBindings = Pick<VectorViewportProps, "remotePresence" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange">;
218
+ type UseRealtimeSessionResult = {
219
+ connection: RealtimeConnectionInfo;
220
+ sessionPeers: RealtimeSessionPeer[];
221
+ remotePresence: RealtimeSessionPeer[];
222
+ remoteAdapter: VectorCanvasRemoteAdapter;
223
+ document: RealtimeDocumentSnapshot | null;
224
+ bindViewportPresence: (options?: {
225
+ activeTool?: string;
226
+ }) => RealtimeViewportPresenceBindings;
227
+ disconnect: () => void;
228
+ reconnectNow: () => void;
229
+ };
230
+ declare function useRealtimeSession(options: UseRealtimeSessionOptions): UseRealtimeSessionResult;
231
+
232
+ type RealtimeCollaborationPluginOptions = UseRealtimeSessionOptions & {
233
+ /** Enable or disable the built-in session panel. Default: `true`. */
234
+ showSessionPanel?: boolean;
235
+ /** Optional visual customization for the built-in session panel. */
236
+ sessionPanel?: Partial<Omit<RealtimeSessionPanelProps, "peers" | "connected" | "connectionState" | "roomId">>;
237
+ /**
238
+ * Enable or configure the built-in collaborative comments experience.
239
+ *
240
+ * Pass `false` to disable comments entirely. When omitted, comments are enabled.
241
+ */
242
+ comments?: false | Omit<UseRealtimeCommentsOptions, "items" | "onItemsChange" | "author" | "viewportRef" | "roomId" | "setToolId">;
243
+ };
244
+ /**
245
+ * High-level plug and play collaboration plugin for `VectorViewport`.
246
+ *
247
+ * Use this when you want realtime presence, session UI, collaborative comments, and document sync
248
+ * without manually wiring `useRealtimeSession`, `useRealtimeComments`, or extra viewport props.
249
+ *
250
+ * For advanced customizations and bespoke UIs, use `useRealtimeSession(...)` and
251
+ * `useRealtimeComments(...)` directly.
252
+ */
253
+ declare function realtimeCollaborationPlugin(options: RealtimeCollaborationPluginOptions): CanvasPlugin;
254
+
255
+ type RealtimeCommentData = {
256
+ body: string;
257
+ createdAt: number;
258
+ authorPeerId: string;
259
+ authorDisplayName: string;
260
+ authorColor: string;
261
+ authorImage: string;
262
+ };
263
+ type RealtimeCommentsOverlayProps = {
264
+ items: readonly VectorSceneItem[];
265
+ onItemsChange?: (items: VectorSceneItem[]) => void;
266
+ isDragEnabled?: boolean;
267
+ cameraVersion: number;
268
+ viewportRef?: CanvasPluginRenderContext["viewportRef"];
269
+ };
270
+ type RealtimeCommentsPluginOptions = Omit<RealtimeCommentsOverlayProps, "viewportRef">;
271
+ /** Dedicated collaboration tool; unlike `text`, this opens a comment composer flow. */
272
+ declare const REALTIME_COMMENT_TOOL: VectorToolDefinition;
273
+ /**
274
+ * Generates a tiny inline avatar so comments carry a portable visual identity even without a user photo API.
275
+ */
276
+ declare function createRealtimeCommentAvatarDataUrl(displayName: string, color: string): string;
277
+ declare function createRealtimeCommentDraftItem(id: string, bounds: Rect, seedColor?: string): VectorSceneItem;
278
+ declare function createRealtimeCommentItem(id: string, bounds: Rect, comment: RealtimeCommentData): VectorSceneItem;
279
+ declare function isRealtimeCommentDraftItem(item: VectorSceneItem): boolean;
280
+ declare function isRealtimeCommentItem(item: VectorSceneItem): boolean;
281
+ declare function getRealtimeCommentData(item: VectorSceneItem): RealtimeCommentData | null;
282
+ /**
283
+ * Adds the comment tool without replacing the native text tool.
284
+ * By default it is inserted right after `text`, or appended when `text` is absent.
285
+ */
286
+ declare function withRealtimeCommentTool(tools: readonly VectorToolDefinition[]): VectorToolDefinition[];
287
+ declare function RealtimeCommentsOverlay({ items, onItemsChange, isDragEnabled, cameraVersion, viewportRef, }: RealtimeCommentsOverlayProps): react_jsx_runtime.JSX.Element | null;
288
+ declare function realtimeCommentsPlugin(options: RealtimeCommentsPluginOptions): CanvasPlugin;
289
+
290
+ type RealtimeSessionPluginOptions = RealtimeSessionPanelProps;
291
+ /**
292
+ * Optional UI roster for who is in the session (your WebSocket layer fills `peers`).
293
+ * World-space cursors and strokes use {@link VectorViewport} `remotePresence` and
294
+ * `onWorldPointerMove` — this plugin only renders a small panel in the viewport plugin layer.
295
+ *
296
+ * @example
297
+ * ```tsx
298
+ * <VectorViewport
299
+ * items={doc.items}
300
+ * onItemsChange={doc.onItemsChange}
301
+ * plugins={[
302
+ * realtimeSessionPlugin({ peers: presenceRoster, connected: wsOpen }),
303
+ * ]}
304
+ * />
305
+ * ```
306
+ */
307
+ declare function realtimeSessionPlugin(options: RealtimeSessionPluginOptions): CanvasPlugin;
308
+
309
+ export { PresenceRemoteLayer, type PresenceRemoteLayerProps, REALTIME_COMMENT_TOOL, type RealtimeClientMessage, type RealtimeCollaborationPluginOptions, type RealtimeCommentData, type RealtimeCommentsAuthor, RealtimeCommentsOverlay, type RealtimeCommentsOverlayProps, type RealtimeCommentsPluginOptions, type RealtimeCommentsViewportBindings, type RealtimeConnectionInfo, RealtimeConnectionState, type RealtimeDocumentSnapshot, type RealtimePresencePayload, type RealtimeServerMessage, RealtimeSessionPanel, type RealtimeSessionPanelProps, type RealtimeSessionPeer, type RealtimeSessionPluginOptions, type RealtimeViewportPresenceBindings, RemotePresenceMarkupStroke, RemotePresencePeer, type UseRealtimeCommentsOptions, type UseRealtimeCommentsResult, type UseRealtimeSessionOptions, type UseRealtimeSessionResult, createRealtimeCommentAvatarDataUrl, createRealtimeCommentDraftItem, createRealtimeCommentItem, defaultPresenceColorForId, getRealtimeCommentData, isRealtimeCommentDraftItem, isRealtimeCommentItem, parseRealtimeClientMessage, parseRealtimeServerMessage, realtimeCollaborationPlugin, realtimeCommentsPlugin, realtimeSessionPlugin, remoteMarkupStrokeFromPlacementPreview, useRealtimeComments, useRealtimeSession, withRealtimeCommentTool };