annotate-kit 0.1.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.
@@ -0,0 +1,290 @@
1
+ import * as react from 'react';
2
+
3
+ type AnnType = 'change' | 'add' | 'remove' | 'bug' | 'style' | 'question';
4
+ type AnnPriority = 'low' | 'med' | 'high';
5
+ type AnnStatus = 'open' | 'in_progress' | 'done' | 'dismissed';
6
+ type AnnKind = 'pin' | 'shape';
7
+ type AnnShape = 'rect' | 'arrow' | 'circle' | 'freehand';
8
+ type AnnVisibility = 'public' | 'private';
9
+ type AnnReply = {
10
+ note: string;
11
+ author?: string;
12
+ at?: string;
13
+ };
14
+ type AnnPoint = {
15
+ x: number;
16
+ y: number;
17
+ };
18
+ type AnnMeta = {
19
+ browser?: string;
20
+ os?: string;
21
+ device?: string;
22
+ viewport?: string;
23
+ screen?: string;
24
+ dpr?: number;
25
+ url?: string;
26
+ ua?: string;
27
+ };
28
+ type AnnLog = {
29
+ level: string;
30
+ text: string;
31
+ at?: string;
32
+ };
33
+ type AnnNetLog = {
34
+ method: string;
35
+ url: string;
36
+ status?: number;
37
+ ms?: number;
38
+ ok?: boolean;
39
+ at?: string;
40
+ };
41
+ type Annotation = {
42
+ id: number;
43
+ page_route: string;
44
+ page_title: string;
45
+ target_selector: string;
46
+ target_text: string;
47
+ pos_x: number;
48
+ pos_y: number;
49
+ viewport_w: number;
50
+ viewport_h: number;
51
+ note: string;
52
+ type: AnnType;
53
+ priority: AnnPriority;
54
+ status: AnnStatus;
55
+ screenshot_path?: string | null;
56
+ screenshot_url?: string | null;
57
+ replies?: AnnReply[];
58
+ created_by?: string;
59
+ created_at?: string;
60
+ updated_at?: string;
61
+ kind?: AnnKind;
62
+ shape_type?: AnnShape | null;
63
+ x2?: number | null;
64
+ y2?: number | null;
65
+ points?: AnnPoint[] | null;
66
+ color?: string | null;
67
+ visibility?: AnnVisibility;
68
+ created_by_role?: string | null;
69
+ created_by_name?: string | null;
70
+ styles?: Record<string, string> | null;
71
+ el_context?: string[] | null;
72
+ meta?: AnnMeta | null;
73
+ console_logs?: AnnLog[] | null;
74
+ network_logs?: AnnNetLog[] | null;
75
+ dom_snapshot?: string | null;
76
+ };
77
+ type NewAnnotation = Omit<Annotation, 'id' | 'status' | 'created_at' | 'updated_at' | 'screenshot_url' | 'created_by' | 'created_by_role' | 'created_by_name'> & {
78
+ screenshot_path?: string | null;
79
+ };
80
+ type AnnotationPatch = {
81
+ id: number;
82
+ } & Partial<Pick<Annotation, 'note' | 'status' | 'type' | 'priority'>>;
83
+ type AnnotateAccess = {
84
+ enabled: boolean;
85
+ isAdmin: boolean;
86
+ canUse: boolean;
87
+ seeAll: boolean;
88
+ me?: {
89
+ email?: string;
90
+ name?: string;
91
+ role?: string;
92
+ };
93
+ };
94
+
95
+ interface StorageAdapter {
96
+ /** Who is looking + what they may do. Called on mount (and after toggling access). */
97
+ getAccess(): Promise<AnnotateAccess>;
98
+ /** Flip the global "visible to all users" toggle (ADMIN only). */
99
+ setAccess(enabled: boolean): Promise<{
100
+ message?: string;
101
+ }>;
102
+ /** All marks the viewer may see, each with `screenshot_url` resolved for display. */
103
+ list(): Promise<Annotation[]>;
104
+ /** Persist a new mark; returns its new id. */
105
+ save(input: NewAnnotation): Promise<{
106
+ id: number;
107
+ }>;
108
+ /** Patch a mark (status/note/type/priority) by id. */
109
+ update(patch: AnnotationPatch): Promise<void>;
110
+ /** Delete a mark (and its screenshot) by id. */
111
+ remove(id: number): Promise<void>;
112
+ /** Append a follow-up reply to a mark. */
113
+ addReply(id: number, note: string): Promise<void>;
114
+ /** Delete every done/dismissed mark (ADMIN/see-all cleanup). */
115
+ clearResolved(): Promise<{
116
+ message?: string;
117
+ }>;
118
+ /** Upload a screenshot; returns the storage path stored on the row (list() turns it into a URL).
119
+ * `visibility` decides where the file lives: a 'public' mark's screenshot is readable by any
120
+ * authenticated user, a 'private' one only by its owner/admin. Defaults to 'private'. */
121
+ uploadScreenshot(file: File, opts?: {
122
+ visibility?: AnnVisibility;
123
+ }): Promise<{
124
+ path: string;
125
+ }>;
126
+ /** Optional: subscribe to live changes and call `onChange` when marks may have changed.
127
+ * Return an unsubscribe function. When present, the overlay updates in real time (with a slow
128
+ * poll as a safety net) instead of polling only while open. */
129
+ subscribe?(onChange: () => void): () => void;
130
+ }
131
+
132
+ type Delivery = {
133
+ /** Button label shown in the Send panel. */
134
+ label: string;
135
+ /** URL target — opens a prefilled page in a new tab (no token needed). */
136
+ href?: (items: Annotation[]) => string;
137
+ /** POST target — invoked on click (webhook / Slack / your API). */
138
+ run?: (items: Annotation[]) => Promise<void> | void;
139
+ };
140
+ /** Zero-config: open a prefilled "New issue" page for a GitHub repo. No token required. */
141
+ declare function githubIssueDelivery(opts: {
142
+ repo: string;
143
+ label?: string;
144
+ titlePrefix?: string;
145
+ }): Delivery;
146
+ /** POST the markdown prompt + structured context to any HTTP endpoint you control. */
147
+ declare function createWebhookDelivery(opts: {
148
+ url: string;
149
+ label?: string;
150
+ headers?: Record<string, string>;
151
+ fetch?: typeof fetch;
152
+ }): Delivery;
153
+ /** POST the prompt to a Slack Incoming Webhook URL (the integrator creates it). */
154
+ declare function createSlackDelivery(opts: {
155
+ webhookUrl: string;
156
+ label?: string;
157
+ fetch?: typeof fetch;
158
+ }): Delivery;
159
+
160
+ type AnnotateProps = {
161
+ /** Your backend binding — see `annotate-kit/supabase` and `annotate-kit/firebase`, or write your own. */
162
+ adapter: StorageAdapter;
163
+ /** Current route path. Pass your router's pathname so marks are page-aware in an SPA.
164
+ * Omit to read `window.location.pathname` (updates on browser back/forward only). */
165
+ route?: string;
166
+ /** Navigate to a path (used by "find on page" across routes). Default: full-page `window.location.assign`.
167
+ * Pass your router's navigate for smooth SPA jumps. */
168
+ onNavigate?: (path: string) => void;
169
+ /** Override the current user (else taken from the adapter's access.me). Used for author attribution. */
170
+ user?: {
171
+ email?: string;
172
+ name?: string;
173
+ role?: string;
174
+ };
175
+ /** Hook the widget's toasts into your app's notifications. Omit for a built-in mini-toast. */
176
+ onToast?: (kind: 'success' | 'error', message: string) => void;
177
+ /** How often (ms) to refresh marks while the tool/panel is open. Default 15000. */
178
+ pollMs?: number;
179
+ /** Capture a rolling console/JS-error buffer with each mark (secrets may appear in logs).
180
+ * Default false — opt in only if your team needs console context for bug reports. */
181
+ captureConsole?: boolean;
182
+ /** Store the full URL (incl. query string + hash) instead of just origin + pathname.
183
+ * Default false — query strings often carry tokens/PII. */
184
+ captureFullUrl?: boolean;
185
+ /** Capture on-screen element text (target text + surrounding labels) with each mark.
186
+ * Default true; set false for apps that display sensitive data. */
187
+ captureText?: boolean;
188
+ /** Enable bare single-key tool shortcuts (P/B/A/C/D). Default true. Set false to avoid
189
+ * collisions with the host app's own single-key shortcuts. */
190
+ singleKeyShortcuts?: boolean;
191
+ /** Capture a rolling buffer of failed/slow network requests (fetch + XHR) with each mark.
192
+ * Default false — URLs are trimmed + redacted, but opt in deliberately. */
193
+ captureNetwork?: boolean;
194
+ /** Capture a sanitised HTML snapshot of the marked element (scripts/handlers stripped, password
195
+ * values blanked, truncated). Default false — the DOM can contain sensitive content. */
196
+ captureDomSnapshot?: boolean;
197
+ /** Blur password fields and any `[data-annot-redact]` element in screenshots. Default true. */
198
+ redactScreenshots?: boolean;
199
+ /** Colour theme for the widget's own panels/dock: 'light' (default), 'dark', or 'auto'
200
+ * (follows the OS via prefers-color-scheme). Does not affect the host page. */
201
+ theme?: 'light' | 'dark' | 'auto';
202
+ /** Override the brand accent colour (any valid CSS colour, e.g. '#0ea5e9'). Themes buttons, active
203
+ * tools, links, and highlights. Invalid values are ignored. */
204
+ accent?: string;
205
+ /** Redact secrets/PII from captured text + console before it is stored. Return the cleaned
206
+ * string. Default masks JWTs, bearer tokens, emails, and long digit runs (cards/SSNs). */
207
+ redact?: (text: string) => string;
208
+ /** Optional "send to…" targets shown in the Send panel (GitHub issue / webhook / Slack / your own).
209
+ * Off by default — see the `githubIssueDelivery` / `createWebhookDelivery` / `createSlackDelivery` helpers. */
210
+ deliveries?: Delivery[];
211
+ };
212
+ declare function Annotate({ adapter, route, onNavigate, user, onToast, pollMs, captureConsole, captureFullUrl, captureText, singleKeyShortcuts, captureNetwork, captureDomSnapshot, redactScreenshots, theme, accent, redact, deliveries }: AnnotateProps): react.ReactPortal | null;
213
+
214
+ declare function buildDevPrompt(items: Annotation[], opts?: {
215
+ title?: string;
216
+ includeConsole?: boolean;
217
+ includeNetwork?: boolean;
218
+ }): string;
219
+ declare function buildDevContext(items: Annotation[]): {
220
+ total: number;
221
+ items: {
222
+ id: number;
223
+ page_route: string;
224
+ page_title: string;
225
+ kind: AnnKind;
226
+ shape_type: AnnShape | null;
227
+ type: AnnType;
228
+ priority: AnnPriority;
229
+ status: AnnStatus;
230
+ visibility: AnnVisibility;
231
+ element: {
232
+ selector: string | null;
233
+ text: string | null;
234
+ };
235
+ where: string[];
236
+ note: string;
237
+ author: string | null;
238
+ env: {
239
+ browser: string | null;
240
+ os: string | null;
241
+ device: string | null;
242
+ viewport: string | null;
243
+ url: string | null;
244
+ } | null;
245
+ replies: {
246
+ note: string;
247
+ author: string | null;
248
+ at: string | null;
249
+ }[];
250
+ console: {
251
+ level: string;
252
+ text: string;
253
+ }[];
254
+ network: {
255
+ method: string;
256
+ url: string;
257
+ status: number | null;
258
+ ms: number | null;
259
+ }[];
260
+ domSnapshot: string | null;
261
+ hasScreenshot: boolean;
262
+ }[];
263
+ };
264
+
265
+ declare const ANN_MODES: {
266
+ key: 'pin' | AnnShape;
267
+ label: string;
268
+ kbd: string;
269
+ }[];
270
+ declare const ANN_COLORS: string[];
271
+ declare const annShapeLabel: (s?: string | null) => string;
272
+ declare const ANN_TYPES: {
273
+ key: AnnType;
274
+ label: string;
275
+ dot: string;
276
+ }[];
277
+ declare const ANN_PRIORITIES: {
278
+ key: AnnPriority;
279
+ label: string;
280
+ }[];
281
+ declare const ANN_STATUSES: {
282
+ key: AnnStatus;
283
+ label: string;
284
+ }[];
285
+ declare const OPEN_STATUSES: AnnStatus[];
286
+ declare const annDot: (t?: string) => string;
287
+ declare const annTypeLabel: (t?: string) => string;
288
+ declare const annStatusLabel: (s?: string) => string;
289
+
290
+ export { ANN_COLORS, ANN_MODES, ANN_PRIORITIES, ANN_STATUSES, ANN_TYPES, type AnnKind, type AnnLog, type AnnMeta, type AnnNetLog, type AnnPoint, type AnnPriority, type AnnReply, type AnnShape, type AnnStatus, type AnnType, type AnnVisibility, Annotate, type AnnotateAccess, type AnnotateProps, type Annotation, type AnnotationPatch, type Delivery, type NewAnnotation, OPEN_STATUSES, type StorageAdapter, annDot, annShapeLabel, annStatusLabel, annTypeLabel, buildDevContext, buildDevPrompt, createSlackDelivery, createWebhookDelivery, githubIssueDelivery };