@commentkit/comment-kit 0.6.9 → 0.7.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +36 -4
  2. package/LICENSE +18 -2
  3. package/README.md +133 -88
  4. package/SECURITY.md +48 -0
  5. package/dist/THIRD_PARTY_NOTICES.txt +284 -0
  6. package/dist/angular.es.js +25 -12
  7. package/dist/comment-kit.es.js +23 -11
  8. package/dist/demo.es.js +146 -69
  9. package/dist/headless.es.js +2 -2
  10. package/dist/preact.es.js +3 -3
  11. package/dist/qwik.es.js +1 -110
  12. package/dist/qwik.qwik.mjs +114 -0
  13. package/dist/react.es.js +3 -3
  14. package/dist/shared/annotation-icons-Dh-bmNYK.js +172 -0
  15. package/dist/shared/annotation-toolbar-B9SxYqoF.js +1093 -0
  16. package/dist/shared/{bridge-DRE03N9X.js → bridge-CJoGYngu.js} +6 -3
  17. package/dist/shared/{button-group-CHfMRXyA.js → button-group-Cl9CrvvU.js} +1 -1
  18. package/dist/shared/comment-drawing-canvas-Dzb5YoFw.js +124 -0
  19. package/dist/shared/{comment-image-lightbox-0VdAs2iT.js → comment-image-lightbox-BPYJT1sB.js} +62 -57
  20. package/dist/shared/{comment-kit-core-D0kY00St.js → comment-kit-core-BaSuMzp9.js} +1027 -729
  21. package/dist/shared/comment-kit-ui-CzfdAZs2.js +20181 -0
  22. package/dist/shared/comment-screenshot-annotator-C7X-_bm6.js +151 -0
  23. package/dist/shared/comment-screenshot-overlay-wIrZrcRy.js +206 -0
  24. package/dist/shared/comment-utils-BycYTSxA.js +602 -0
  25. package/dist/shared/{dev-export-panel-BLngcr5q.js → dev-export-panel-FwFVdady.js} +8 -8
  26. package/dist/shared/{dev-grab-pDAfH2lr.js → dev-grab-DDqg0LQf.js} +1 -1
  27. package/dist/shared/dist-De294MVF.js +623 -0
  28. package/dist/shared/{element-selector-CtFzgHvq.js → element-selector-BhJm-NSs.js} +294 -288
  29. package/dist/shared/{icons-BSHCWYO1.js → icons-nzMOLzrm.js} +2 -3
  30. package/dist/shared/{mount-ui-CVivB_eQ.js → mount-ui--ijs8pWT.js} +4 -4
  31. package/dist/shared/{pusher-BEl7Qn-8.js → pusher-ipHMJnO_.js} +1 -1
  32. package/dist/shared/{realtime-BG_t_ze7.js → realtime-Dk41VwKg.js} +71 -50
  33. package/dist/shared/{separator-DusFNTs-.js → separator-XDBsaWyw.js} +891 -785
  34. package/dist/shared/{shadow-root-CmYXiSRR.js → shadow-root-C5v-T8lQ.js} +1 -1
  35. package/dist/shared/styles-D3yMtaec.js +2 -0
  36. package/dist/shared/{useValueChanged-DQXLia-2.js → useValueChanged-CrzfD8l-.js} +15 -15
  37. package/dist/shared/{websocket-manager-BTRqNTB7.js → websocket-manager-DhLWh3Jr.js} +2 -2
  38. package/dist/solid.es.js +3 -3
  39. package/dist/svelte.es.js +3 -3
  40. package/dist/types/adapters/bridge.d.ts +9 -12
  41. package/dist/types/angular/index.d.ts +15 -5
  42. package/dist/types/core/api-client.d.ts +16 -17
  43. package/dist/types/core/comment-kit-core.d.ts +19 -11
  44. package/dist/types/core/local-demo.d.ts +1 -0
  45. package/dist/types/core/types.d.ts +68 -0
  46. package/dist/types/headless.d.ts +1 -1
  47. package/dist/types/index.d.ts +8 -4
  48. package/dist/types/qwik/index.d.ts +4 -1
  49. package/dist/vue.es.js +3 -3
  50. package/docs/api-reference.md +372 -0
  51. package/docs/local-demo.md +60 -0
  52. package/package.json +16 -6
  53. package/dist/shared/annotation-toolbar-pX17NLmJ.js +0 -1104
  54. package/dist/shared/clamp-CcFVX0vC.js +0 -55
  55. package/dist/shared/comment-drawing-canvas-CYu5SwRf.js +0 -126
  56. package/dist/shared/comment-kit-ui-D2j2gvnm.js +0 -16685
  57. package/dist/shared/comment-screenshot-annotator-BuojwviY.js +0 -137
  58. package/dist/shared/comment-screenshot-overlay-BZX0Vcb8.js +0 -144
  59. package/dist/shared/local-demo-context-BohlYbHt.js +0 -6
  60. package/dist/shared/resolveAriaLabelledBy-CIKpnjNJ.js +0 -669
  61. package/dist/shared/styles-D_FEJZ9G.js +0 -2
  62. package/dist/shared/useLabelableId-DGbfdMi_.js +0 -155
@@ -1,17 +1,17 @@
1
1
  import { a as e, c as t, l as n, n as r, o as i, r as a, s as o, t as s, u as c } from "./validation-C7QG8j7Z.js";
2
2
  import { n as l, o as u } from "./dom-Bhf4WFtY.js";
3
- var d = "https://api.commentkit.dev/api", f = 3e4, p = 10485760, m = 10, h = 1e4, g = 5e3, _ = 254, v = 6, y = 4096, b = [
3
+ var d = "https://api.commentkit.dev/api", f = 3e4, p = 10485760, m = 10, h = 1e4, g = 5e3, _ = 254, v = 6, ee = 4096, y = [
4
4
  ".png",
5
5
  ".jpg",
6
6
  ".jpeg",
7
7
  ".gif",
8
8
  ".webp"
9
- ], x = [
9
+ ], b = [
10
10
  "image/png",
11
11
  "image/jpeg",
12
12
  "image/gif",
13
13
  "image/webp"
14
- ], S = /@\[([^\]]+)\]\(([^)]+)\)/g, ee = {
14
+ ], x = /@\[([^\]]+)\]\(([^)]+)\)/g, te = {
15
15
  invalid_api_key: "Authentication failed. Please check your API key.",
16
16
  missing_api_key: "Authentication failed. Please check your API key.",
17
17
  origin_not_allowed: "This domain is not allowed to use this project's API key.",
@@ -35,76 +35,76 @@ var d = "https://api.commentkit.dev/api", f = 3e4, p = 10485760, m = 10, h = 1e4
35
35
  email_mismatch: "This invite was issued for a different email address.",
36
36
  quota_exceeded: "This project has reached its plan limit."
37
37
  };
38
- function te(e, t) {
38
+ function ne(e, t) {
39
39
  let n = {};
40
40
  return e.content !== void 0 && (n.content = e.content), e.status !== void 0 && (n.status = e.status), e.priority !== void 0 && (n.priority = e.priority), e.description !== void 0 && (n.description = e.description), e.assignees !== void 0 && (n.assignees = e.assignees.map((e) => e.id)), e.checklist !== void 0 && (n.checklist = e.checklist.map((e) => ({
41
41
  ...e,
42
42
  id: /^\d+$/.test(e.id) ? Number(e.id) : null
43
43
  }))), e.textSelection !== void 0 && (n.text_selection = e.textSelection), e.drawingData !== void 0 && (n.drawing_data = e.drawingData), e.attachmentIds !== void 0 && (n.attachment_ids = e.attachmentIds.map((e) => typeof e == "number" ? e : Number(e)).filter((e) => Number.isInteger(e) && e > 0).slice(0, 20)), t && t.length > 0 && (n.mentions = t), n;
44
44
  }
45
- function ne(e) {
45
+ function re(e) {
46
46
  return e === "localhost" || e === "127.0.0.1" || e === "[::1]" || e.endsWith(".localhost");
47
47
  }
48
- function re(e) {
48
+ function ie(e) {
49
49
  let t = (e || d).trim().replace(/\/+$/, "");
50
50
  try {
51
51
  let e = new URL(t);
52
52
  if (e.protocol !== "https:" && e.protocol !== "http:") throw Error("unsupported protocol");
53
- if (e.protocol === "http:" && !ne(e.hostname)) throw Error("insecure protocol");
53
+ if (e.protocol === "http:" && !re(e.hostname)) throw Error("insecure protocol");
54
54
  } catch {
55
- throw new D("invalid_base_url", "Invalid API base URL", 400);
55
+ throw new E("invalid_base_url", "Invalid API base URL", 400);
56
56
  }
57
57
  return t;
58
58
  }
59
- function C(e) {
59
+ function S(e) {
60
60
  let t = String(e).trim();
61
- if (!t || r(t)) throw new D("invalid_id", "Invalid identifier", 400);
61
+ if (!t || r(t)) throw new E("invalid_id", "Invalid identifier", 400);
62
62
  return encodeURIComponent(t);
63
63
  }
64
- function w(e) {
65
- if (typeof e != "string" || r(e)) throw new D("invalid_email", "A valid email address is required", 400);
64
+ function C(e) {
65
+ if (typeof e != "string" || r(e)) throw new E("invalid_email", "A valid email address is required", 400);
66
66
  let t = e.trim();
67
- if (!c(t, _)) throw new D("invalid_email", "A valid email address is required", 400);
67
+ if (!c(t, _)) throw new E("invalid_email", "A valid email address is required", 400);
68
68
  return t;
69
69
  }
70
- function ie(e) {
71
- if (r(e)) throw new D("invalid_otp", "A valid OTP code is required", 400);
70
+ function ae(e) {
71
+ if (r(e)) throw new E("invalid_otp", "A valid OTP code is required", 400);
72
72
  let t = e.trim();
73
- if (t.length !== v || /\s/.test(t)) throw new D("invalid_otp", "A valid OTP code is required", 400);
73
+ if (t.length !== v || /\s/.test(t)) throw new E("invalid_otp", "A valid OTP code is required", 400);
74
74
  return t;
75
75
  }
76
- function ae(e) {
77
- if (r(e)) throw new D("invalid_token", "A valid invite token is required", 400);
76
+ function oe(e) {
77
+ if (r(e)) throw new E("invalid_token", "A valid invite token is required", 400);
78
78
  let t = e.trim();
79
- if (t.length !== 64 || !/^[\w-]+$/.test(t)) throw new D("invalid_token", "A valid invite token is required", 400);
79
+ if (t.length !== 64 || !/^[\w-]+$/.test(t)) throw new E("invalid_token", "A valid invite token is required", 400);
80
80
  return t;
81
81
  }
82
- function T(e, t, n = h) {
82
+ function w(e, t, n = h) {
83
83
  let r = e.trim();
84
- if (!r) throw new D("invalid_content", `${t} cannot be empty`, 400);
85
- if (r.length > n) throw new D("content_too_long", `${t} exceeds maximum length of ${n} characters`, 400);
84
+ if (!r) throw new E("invalid_content", `${t} cannot be empty`, 400);
85
+ if (r.length > n) throw new E("content_too_long", `${t} exceeds maximum length of ${n} characters`, 400);
86
86
  return r;
87
87
  }
88
- function oe(e) {
88
+ function se(e) {
89
89
  if (!i(e)) return;
90
90
  let t = {};
91
91
  for (let [n, r] of Object.entries(e).slice(0, 20)) /^[\w.-]{1,64}$/.test(n) && n !== "__proto__" && n !== "constructor" && n !== "prototype" && (typeof r == "string" ? t[n] = r.slice(0, 200) : typeof r == "number" || typeof r == "boolean" || r === null ? t[n] = r : Array.isArray(r) && (t[n] = r.filter((e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null).slice(0, 10).map((e) => typeof e == "string" ? e.slice(0, 200) : e)));
92
92
  return Object.keys(t).length > 0 ? t : void 0;
93
93
  }
94
- var se = class {
94
+ var ce = class {
95
95
  constructor(e) {
96
- this.projectId = null, this.userEmail = null, this.authToken = null, this.environment = null, this.onAuthExpired = null, this.baseUrl = re(e.baseUrl), this.apiKey = e.apiKey, this.projectId = e.projectId || null, this.environment = e.environment || null;
96
+ this.projectId = null, this.userEmail = null, this.authToken = null, this.authRevision = 0, this.environment = null, this.onAuthExpired = null, this.baseUrl = ie(e.baseUrl), this.apiKey = e.apiKey, this.projectId = e.projectId || null, this.environment = e.environment || null;
97
97
  }
98
98
  setProject(e) {
99
99
  this.projectId = String(e).trim();
100
100
  }
101
101
  setUserEmail(e) {
102
- this.userEmail = e ? w(e) : null;
102
+ this.userEmail = e ? C(e) : null;
103
103
  }
104
104
  setAuthToken(e) {
105
- if (e && (r(e) || e.length > y)) throw new D("invalid_token", "A valid auth token is required", 400);
105
+ if (e && (r(e) || e.length > ee)) throw new E("invalid_token", "A valid auth token is required", 400);
106
106
  let t = e?.trim() || null;
107
- this.authToken = t;
107
+ this.authToken = t, this.authRevision++;
108
108
  }
109
109
  setEnvironment(e) {
110
110
  this.environment = e;
@@ -113,7 +113,7 @@ var se = class {
113
113
  this.onAuthExpired = e;
114
114
  }
115
115
  buildHeaders(e) {
116
- if (typeof this.apiKey != "string" || r(this.apiKey)) throw new D("invalid_api_key", "Authentication failed. Please check your API key.", 401);
116
+ if (typeof this.apiKey != "string" || r(this.apiKey)) throw new E("invalid_api_key", "Authentication failed. Please check your API key.", 401);
117
117
  return {
118
118
  "X-API-Key": this.apiKey,
119
119
  ...this.userEmail ? { "X-User-Email": this.userEmail } : {},
@@ -122,26 +122,26 @@ var se = class {
122
122
  };
123
123
  }
124
124
  async executeRequest(e, t, n, r) {
125
- let a = new AbortController(), o = setTimeout(() => a.abort(), f);
125
+ let a = this.authRevision, o = this.authToken, s = new AbortController(), c = setTimeout(() => s.abort(), f);
126
126
  try {
127
- let o = await fetch(e, {
127
+ let c = await fetch(e, {
128
128
  ...t,
129
- signal: a.signal
130
- }), s = await this.parseResponseBody(o);
131
- if (!o.ok) {
132
- o.status === 401 && this.authToken && (this.authToken = null, this.onAuthExpired?.());
133
- let e = i(s) ? s : {}, t = typeof e.error == "string" ? e.error : n;
134
- throw new D(t, ee[t] ?? r, o.status, oe(e.details));
129
+ signal: s.signal
130
+ }), l = await this.parseResponseBody(c);
131
+ if (!c.ok) {
132
+ c.status === 401 && o && a === this.authRevision && (this.setAuthToken(null), this.onAuthExpired?.());
133
+ let e = i(l) ? l : {}, t = typeof e.error == "string" ? e.error : n;
134
+ throw new E(t, te[t] ?? r, c.status, se(e.details));
135
135
  }
136
- return s;
136
+ return l;
137
137
  } catch (e) {
138
- if (e instanceof D) throw e;
139
- if (e instanceof DOMException && e.name === "AbortError") throw new D("timeout", "Request timed out. Please try again.", 408);
140
- if (e instanceof TypeError) throw new D("network_error", "Unable to connect to servers. Please check your connection.", 0);
141
- let t = new D("unknown_error", "An unexpected error occurred", 500);
138
+ if (e instanceof E) throw e;
139
+ if (e instanceof DOMException && e.name === "AbortError") throw new E("timeout", "Request timed out. Please try again.", 408);
140
+ if (e instanceof TypeError) throw new E("network_error", "Unable to connect to servers. Please check your connection.", 0);
141
+ let t = new E("unknown_error", "An unexpected error occurred", 500);
142
142
  throw t.cause = e, t;
143
143
  } finally {
144
- clearTimeout(o);
144
+ clearTimeout(c);
145
145
  }
146
146
  }
147
147
  async parseResponseBody(e) {
@@ -151,20 +151,20 @@ var se = class {
151
151
  let n = await e.text();
152
152
  if (!n) return {};
153
153
  if (t && !t.toLowerCase().includes("application/json")) {
154
- if (e.ok) throw new D("invalid_response", "Invalid server response", 502);
154
+ if (e.ok) throw new E("invalid_response", "Invalid server response", 502);
155
155
  return {};
156
156
  }
157
157
  try {
158
158
  return JSON.parse(n);
159
159
  } catch {
160
- if (e.ok) throw new D("invalid_response", "Invalid server response", 502);
160
+ if (e.ok) throw new E("invalid_response", "Invalid server response", 502);
161
161
  return {};
162
162
  }
163
163
  }
164
164
  if (typeof e.json == "function") try {
165
165
  return await e.json();
166
166
  } catch {
167
- if (e.ok) throw new D("invalid_response", "Invalid server response", 502);
167
+ if (e.ok) throw new E("invalid_response", "Invalid server response", 502);
168
168
  }
169
169
  return {};
170
170
  }
@@ -187,7 +187,7 @@ var se = class {
187
187
  }, "upload_failed", "Upload failed");
188
188
  }
189
189
  requireProjectId() {
190
- if (!this.projectId) throw new D("missing_project_id", "Project ID is required", 400);
190
+ if (!this.projectId) throw new E("missing_project_id", "Project ID is required", 400);
191
191
  return this.projectId;
192
192
  }
193
193
  async validateApiKey() {
@@ -197,14 +197,14 @@ var se = class {
197
197
  });
198
198
  }
199
199
  async requestOtp(e) {
200
- let t = w(e);
200
+ let t = C(e);
201
201
  return this.request("/auth/otp/request", {
202
202
  method: "POST",
203
203
  body: JSON.stringify({ email: t })
204
204
  });
205
205
  }
206
206
  async verifyOtp(e, t) {
207
- let n = w(e), r = ie(t);
207
+ let n = C(e), r = ae(t);
208
208
  return this.request("/auth/otp/verify", {
209
209
  method: "POST",
210
210
  body: JSON.stringify({
@@ -214,7 +214,7 @@ var se = class {
214
214
  });
215
215
  }
216
216
  async validateInvite(e, t) {
217
- let n = ae(e), r = w(t);
217
+ let n = oe(e), r = C(t);
218
218
  return this.request("/auth/validate-invite", {
219
219
  method: "POST",
220
220
  body: JSON.stringify({
@@ -223,28 +223,32 @@ var se = class {
223
223
  })
224
224
  });
225
225
  }
226
- async getComments(e, t = "all", n = 1, r = 50, i) {
227
- let a = this.requireProjectId(), o = new URLSearchParams();
228
- e && o.append("page_path", e), t !== "all" && o.append("status", t), i && o.append("environment", i);
229
- let s = Number.isFinite(n) ? Math.max(1, Math.floor(n)) : 1, c = Number.isFinite(r) ? Math.min(100, Math.max(1, Math.floor(r))) : 50;
230
- o.append("page", String(s)), o.append("limit", String(c));
231
- let l = o.toString(), u = `/projects/${C(a)}/comments${l ? `?${l}` : ""}`, d = await this.request(u), f = d.comments ?? [];
226
+ async getComments(e, t = "all", n = 1, r = 50, i, a) {
227
+ let o = this.requireProjectId(), s = new URLSearchParams();
228
+ e && s.append("page_path", e), t !== "all" && s.append("status", t), i && s.append("environment", i), a && s.append("branch", a);
229
+ let c = Number.isFinite(n) ? Math.max(1, Math.floor(n)) : 1, l = Number.isFinite(r) ? Math.min(100, Math.max(1, Math.floor(r))) : 50;
230
+ s.append("page", String(c)), s.append("limit", String(l));
231
+ let u = s.toString(), d = `/projects/${S(o)}/comments${u ? `?${u}` : ""}`, f = await this.request(d), p = f.comments ?? [];
232
232
  return {
233
- comments: f,
234
- pagination: d.pagination ?? {
235
- total: f.length,
236
- hasMore: f.length >= c,
237
- page: s,
238
- limit: c
233
+ comments: p,
234
+ pagination: f.pagination ?? {
235
+ total: p.length,
236
+ hasMore: p.length >= l,
237
+ page: c,
238
+ limit: l
239
239
  }
240
240
  };
241
241
  }
242
+ async getComment(e) {
243
+ let t = this.requireProjectId();
244
+ return (await this.request(`/projects/${S(t)}/comments/${S(e)}`)).comment;
245
+ }
242
246
  idempotencyHeaders(e) {
243
247
  return typeof e == "string" && e.length > 0 && e.length <= 256 && !r(e) ? { "Idempotency-Key": e } : {};
244
248
  }
245
249
  async createComment(e, t, n, r, i = "medium", a, o, s, c) {
246
- let l = T(t, "Comment content"), u = this.requireProjectId(), d = s?.mentions ?? E(l);
247
- return (await this.request(`/projects/${C(u)}/comments`, {
250
+ let l = w(t, "Comment content"), u = this.requireProjectId(), d = s?.mentions ?? T(l);
251
+ return (await this.request(`/projects/${S(u)}/comments`, {
248
252
  method: "POST",
249
253
  headers: this.idempotencyHeaders(c),
250
254
  body: JSON.stringify({
@@ -254,7 +258,9 @@ var se = class {
254
258
  page_path: r.path,
255
259
  page_title: r.title,
256
260
  environment: this.environment || void 0,
257
- ...te({
261
+ branch: s?.branch,
262
+ device_info: s?.deviceInfo,
263
+ ...ne({
258
264
  content: l,
259
265
  priority: i,
260
266
  description: s?.description,
@@ -268,137 +274,156 @@ var se = class {
268
274
  })).comment;
269
275
  }
270
276
  async updateComment(e, t) {
271
- let n = this.requireProjectId(), r = t.content === void 0 ? void 0 : T(t.content, "Comment content"), i = r ? E(r) : void 0, a = te({
277
+ let n = this.requireProjectId(), r = t.content === void 0 ? void 0 : w(t.content, "Comment content"), i = t.mentions ?? (r ? T(r) : void 0), a = ne({
272
278
  ...t,
273
279
  ...r === void 0 ? {} : { content: r }
274
280
  }, i);
275
- return (await this.request(`/projects/${C(n)}/comments/${C(e)}`, {
281
+ return (await this.request(`/projects/${S(n)}/comments/${S(e)}`, {
276
282
  method: "PUT",
277
283
  body: JSON.stringify(a)
278
284
  })).comment;
279
285
  }
280
286
  async deleteComment(e) {
281
287
  let t = this.requireProjectId();
282
- await this.request(`/projects/${C(t)}/comments/${C(e)}`, { method: "DELETE" });
288
+ await this.request(`/projects/${S(t)}/comments/${S(e)}`, { method: "DELETE" });
283
289
  }
284
- async addReply(e, t, n) {
285
- let r = this.requireProjectId(), i = T(t, "Reply content", g), a = E(i);
286
- return (await this.request(`/projects/${C(r)}/comments/${C(e)}/replies`, {
290
+ async addReply(e, t, n, r) {
291
+ let i = this.requireProjectId(), a = w(t, "Reply content", g), o = r?.mentions ?? T(a);
292
+ return (await this.request(`/projects/${S(i)}/comments/${S(e)}/replies`, {
287
293
  method: "POST",
288
294
  headers: this.idempotencyHeaders(n),
289
295
  body: JSON.stringify({
290
- content: i,
291
- ...a.length > 0 ? { mentions: a } : {}
296
+ content: a,
297
+ attachment_ids: r?.attachmentIds,
298
+ reply_to: r?.replyTo,
299
+ ...o.length > 0 ? { mentions: o } : {}
292
300
  })
293
301
  })).reply;
294
302
  }
295
- async updateReply(e, t, n) {
296
- let r = this.requireProjectId(), i = T(n, "Reply content", g);
297
- return (await this.request(`/projects/${C(r)}/comments/${C(e)}/replies/${C(t)}`, {
303
+ async updateReply(e, t, n, r) {
304
+ let i = this.requireProjectId(), a = w(n, "Reply content", g);
305
+ return (await this.request(`/projects/${S(i)}/comments/${S(e)}/replies/${S(t)}`, {
298
306
  method: "PUT",
299
- body: JSON.stringify({ content: i })
307
+ body: JSON.stringify({
308
+ content: a,
309
+ attachment_ids: r?.attachmentIds,
310
+ mentions: r?.mentions,
311
+ reply_to: r?.replyTo
312
+ })
300
313
  })).reply;
301
314
  }
302
315
  async deleteReply(e, t) {
303
316
  let n = this.requireProjectId();
304
- await this.request(`/projects/${C(n)}/comments/${C(e)}/replies/${C(t)}`, { method: "DELETE" });
317
+ await this.request(`/projects/${S(n)}/comments/${S(e)}/replies/${S(t)}`, { method: "DELETE" });
305
318
  }
306
319
  async resolveComment(e) {
307
320
  let t = this.requireProjectId();
308
- return (await this.request(`/projects/${C(t)}/comments/${C(e)}/resolve`, { method: "POST" })).comment;
321
+ return (await this.request(`/projects/${S(t)}/comments/${S(e)}/resolve`, { method: "POST" })).comment;
309
322
  }
310
323
  async unresolveComment(e) {
311
324
  let t = this.requireProjectId();
312
- return (await this.request(`/projects/${C(t)}/comments/${C(e)}/unresolve`, { method: "POST" })).comment;
325
+ return (await this.request(`/projects/${S(t)}/comments/${S(e)}/unresolve`, { method: "POST" })).comment;
313
326
  }
314
327
  async markComplete(e) {
315
328
  let t = this.requireProjectId();
316
- return (await this.request(`/projects/${C(t)}/comments/${C(e)}/complete`, { method: "POST" })).comment;
329
+ return (await this.request(`/projects/${S(t)}/comments/${S(e)}/complete`, { method: "POST" })).comment;
317
330
  }
318
- async addReaction(e, t) {
319
- let n = this.requireProjectId();
320
- await this.request(`/projects/${C(n)}/comments/${C(e)}/reactions`, {
331
+ async addReaction(e, t, n) {
332
+ let r = this.requireProjectId();
333
+ await this.request(`/projects/${S(r)}/comments/${S(e)}/reactions`, {
321
334
  method: "POST",
322
- body: JSON.stringify({ emoji: t })
335
+ body: JSON.stringify({
336
+ emoji: t,
337
+ ...n ? { reply_id: n } : {}
338
+ })
323
339
  });
324
340
  }
325
- async removeReaction(e, t) {
326
- let n = this.requireProjectId();
327
- await this.request(`/projects/${C(n)}/comments/${C(e)}/reactions`, {
341
+ async removeReaction(e, t, n) {
342
+ let r = this.requireProjectId();
343
+ await this.request(`/projects/${S(r)}/comments/${S(e)}/reactions`, {
328
344
  method: "DELETE",
329
- body: JSON.stringify({ emoji: t })
345
+ body: JSON.stringify({
346
+ emoji: t,
347
+ ...n ? { reply_id: n } : {}
348
+ })
330
349
  });
331
350
  }
332
351
  async updatePosition(e, t) {
333
352
  let n = this.requireProjectId();
334
- return (await this.request(`/projects/${C(n)}/comments/${C(e)}/position`, {
353
+ return (await this.request(`/projects/${S(n)}/comments/${S(e)}/position`, {
335
354
  method: "PUT",
336
355
  body: JSON.stringify({ position: t })
337
356
  })).comment;
338
357
  }
339
- async createHighlight(e, t, n, r = "medium", i) {
358
+ async createHighlight(e, t, n, r = "medium", i, a) {
340
359
  return this.createComment("highlight", e, {
341
360
  x: 0,
342
361
  y: 0
343
- }, n, r, t, void 0, void 0, i);
362
+ }, n, r, t, void 0, a, i);
344
363
  }
345
- async createDrawing(e, t, n, r, i) {
346
- return this.createComment("drawing", e, n, r, "medium", void 0, t, void 0, i);
364
+ async createDrawing(e, t, n, r, i, a) {
365
+ return this.createComment("drawing", e, n, r, "medium", void 0, t, a, i);
347
366
  }
348
367
  validateFile(e, t = !1) {
349
- if (e.size > p) throw new D("file_too_large", `File size (${Math.round(e.size / 1024 / 1024)}MB) exceeds maximum of ${p / 1024 / 1024}MB`, 400);
350
- if (r(e.name) || e.name.includes("/") || e.name.includes("\\")) throw new D("invalid_filename", "Filename contains invalid characters", 400);
368
+ if (e.size > p) throw new E("file_too_large", `File size (${Math.round(e.size / 1024 / 1024)}MB) exceeds maximum of ${p / 1024 / 1024}MB`, 400);
369
+ if (r(e.name) || e.name.includes("/") || e.name.includes("\\")) throw new E("invalid_filename", "Filename contains invalid characters", 400);
351
370
  if (t) {
352
371
  /* v8 ignore next -- pop() always returns a value since file has a name */
353
372
  let t = "." + (e.name.split(".").pop()?.toLowerCase() ?? "");
354
- if ((e.name.match(/\./g) || []).length > 1) throw new D("invalid_filename", "Filenames with multiple extensions are not allowed", 400);
355
- if (!x.includes(e.type) || !b.includes(t)) throw new D("invalid_file_type", `Only image files are allowed (${b.join(", ")})`, 400);
373
+ if ((e.name.match(/\./g) || []).length > 1) throw new E("invalid_filename", "Filenames with multiple extensions are not allowed", 400);
374
+ if (!b.includes(e.type) || !y.includes(t)) throw new E("invalid_file_type", `Only image files are allowed (${y.join(", ")})`, 400);
356
375
  }
357
- if (s(e.name)) throw new D("invalid_file_type", "This file type is not allowed", 400);
376
+ if (s(e.name)) throw new E("invalid_file_type", "This file type is not allowed", 400);
358
377
  }
359
378
  async uploadFile(e, t, n) {
360
379
  this.validateFile(e, t === "screenshot" || t === "drawing");
361
380
  let r = this.requireProjectId(), i = new FormData();
362
381
  i.append("file", e), i.append("type", t === "attachment" ? "file" : t), n?.commentId && i.append("comment_id", n.commentId), n?.replyId && i.append("reply_id", n.replyId);
363
- let a = await this.requestFormData(`/projects/${C(r)}/files`, i);
382
+ let a = await this.requestFormData(`/projects/${S(r)}/files`, i);
364
383
  return {
365
384
  id: String(a.attachment.id),
366
385
  type: a.attachment.type,
367
386
  url: a.attachment.url,
368
387
  thumbnail: a.attachment.thumbnail,
369
388
  filename: a.attachment.filename,
389
+ mimeType: a.attachment.mimeType,
370
390
  size: a.attachment.size
371
391
  };
372
392
  }
373
393
  async uploadScreenshot(e, t) {
374
394
  this.validateFile(e, !0);
375
- let n = T(t.content, "Screenshot comment"), r = this.requireProjectId(), i = new FormData();
376
- return i.append("file", e), i.append("content", n), i.append("position_x", String(t.position.x)), i.append("position_y", String(t.position.y)), i.append("page_url", t.page.url), i.append("page_path", t.page.path), i.append("page_title", t.page.title), (await this.requestFormData(`/projects/${C(r)}/screenshots`, i)).comment;
395
+ let n = w(t.content, "Screenshot comment"), r = this.requireProjectId(), i = new FormData();
396
+ if (i.append("file", e), i.append("content", n), i.append("position_x", String(t.position.x)), i.append("position_y", String(t.position.y)), i.append("page_url", t.page.url), i.append("page_path", t.page.path), i.append("page_title", t.page.title), t.branch && i.append("branch", t.branch), t.deviceInfo) for (let [e, n] of Object.entries(t.deviceInfo)) n !== void 0 && i.append(`device_info[${e}]`, String(n));
397
+ return (await this.requestFormData(`/projects/${S(r)}/screenshots`, i)).comment;
377
398
  }
378
399
  async uploadFiles(e, t) {
379
- if (e.length > m) throw new D("too_many_files", `Cannot upload more than ${m} files at once`, 400);
400
+ if (e.length > m) throw new E("too_many_files", `Cannot upload more than ${m} files at once`, 400);
380
401
  let n = await Promise.allSettled(e.map((e) => {
381
402
  /* v8 ignore next -- pop() always returns a value since file has a name */
382
- let n = "." + (e.name.split(".").pop()?.toLowerCase() ?? ""), r = x.includes(e.type) && b.includes(n);
403
+ let n = "." + (e.name.split(".").pop()?.toLowerCase() ?? ""), r = b.includes(e.type) && y.includes(n);
383
404
  return this.uploadFile(e, r ? "screenshot" : "attachment", t);
384
405
  })), r = n.filter((e) => e.status === "fulfilled").map((e) => e.value.id), i = n.find((e) => e.status === "rejected");
385
406
  if (i) {
386
407
  let e = i.reason;
387
- throw e instanceof D ? new D(e.error, e.message, e.code, {
408
+ throw e instanceof E ? new E(e.error, e.message, e.code, {
388
409
  ...e.details,
389
410
  uploadedIds: r
390
- }) : new D("upload_failed", "Upload failed", 0, { uploadedIds: r });
411
+ }) : new E("upload_failed", "Upload failed", 0, { uploadedIds: r });
391
412
  }
392
413
  return r;
393
414
  }
415
+ async getProjectContext() {
416
+ let e = this.requireProjectId();
417
+ return (await this.request(`/projects/${S(e)}/context`)).context;
418
+ }
394
419
  async getProjectMembers() {
395
420
  let e = this.requireProjectId();
396
- return (await this.request(`/projects/${C(e)}/members`)).members ?? [];
421
+ return (await this.request(`/projects/${S(e)}/members`)).members ?? [];
397
422
  }
398
423
  };
399
- function E(e) {
424
+ function T(e) {
400
425
  let t = [], n;
401
- for (S.lastIndex = 0; (n = S.exec(e)) !== null;) {
426
+ for (x.lastIndex = 0; (n = x.exec(e)) !== null;) {
402
427
  let e = n[1]?.trim(), r = n[2]?.trim();
403
428
  e && r && /^[\w-]+$/.test(r) && t.push({
404
429
  name: e,
@@ -408,13 +433,13 @@ function E(e) {
408
433
  }
409
434
  return t;
410
435
  }
411
- function ce(e) {
436
+ function le(e) {
412
437
  return `@[${e.name.replace(/\]/g, "")}](${e.id.replace(/\)/g, "")})`;
413
438
  }
414
- function le(e) {
415
- return e.replace(S, "@$1");
439
+ function ue(e) {
440
+ return e.replace(x, "@$1");
416
441
  }
417
- var D = class extends Error {
442
+ var E = class extends Error {
418
443
  constructor(e, t, n, r) {
419
444
  super(t), this.name = "ApiClientError", this.error = e, this.code = n, this.details = r;
420
445
  }
@@ -431,25 +456,25 @@ var D = class extends Error {
431
456
  return this.code === 402;
432
457
  }
433
458
  };
434
- function ue(e, t) {
459
+ function de(e, t) {
435
460
  return (e ?? "").replace(/\s+/g, " ").trim().slice(0, t);
436
461
  }
437
- function O(e, t) {
462
+ function D(e, t) {
438
463
  return (e ?? "").replace(/\s+/g, " ").replace(/`/g, "'").trim().slice(0, t);
439
464
  }
440
- var k = null, de = 0, fe = 3;
441
- function pe() {
442
- return k || (k = (async () => {
465
+ var O = null, fe = 0, pe = 3;
466
+ function me() {
467
+ return O || (O = (async () => {
443
468
  try {
444
469
  let e = await import("element-source");
445
470
  return typeof e?.resolveElementInfo == "function" ? e : null;
446
471
  } catch {
447
- return de += 1, de < fe && (k = null), null;
472
+ return fe += 1, fe < pe && (O = null), null;
448
473
  }
449
- })(), k);
474
+ })(), O);
450
475
  }
451
- async function me(e) {
452
- let t = await pe();
476
+ async function he(e) {
477
+ let t = await me();
453
478
  if (!t) return null;
454
479
  try {
455
480
  return await t.resolveElementInfo(e);
@@ -457,27 +482,27 @@ async function me(e) {
457
482
  return null;
458
483
  }
459
484
  }
460
- var he = 200, ge = 500, _e = 500, ve = 2e3, ye = "application/x-commentkit-agent-context", be = "Use this CommentKit context to understand unresolved UI feedback. Each comment includes page, selector/XPath, viewport position, resolved DOM metadata when available, and thread replies.";
461
- function xe(e) {
462
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
463
- }
485
+ var ge = 200, _e = 500, ve = 500, ye = 2e3, be = "application/x-commentkit-agent-context", xe = "Use this CommentKit context to understand unresolved UI feedback. Each comment includes page, selector/XPath, viewport position, resolved DOM metadata when available, and thread replies.";
464
486
  function Se(e) {
465
- return e === void 0 ? he : !Number.isFinite(e) || e <= 0 ? 0 : Math.min(ge, Math.floor(e));
487
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
466
488
  }
467
489
  function Ce(e) {
490
+ return e === void 0 ? ge : !Number.isFinite(e) || e <= 0 ? 0 : Math.min(_e, Math.floor(e));
491
+ }
492
+ function we(e) {
468
493
  return {
469
494
  id: e.id,
470
495
  name: e.name,
471
496
  email: e.email
472
497
  };
473
498
  }
474
- function we(e, t) {
499
+ function Te(e, t) {
475
500
  return e.page.path === t.path || e.page.url === t.url;
476
501
  }
477
- function Te(e, t, n, r) {
478
- return !(!n.includeResolved && e.status !== "open" || n.currentPageOnly && !we(e, t) || r && !r.has(e.id));
502
+ function Ee(e, t, n, r) {
503
+ return !(!n.includeResolved && e.status !== "open" || n.currentPageOnly && !Te(e, t) || r && !r.has(e.id));
479
504
  }
480
- function Ee(e) {
505
+ function De(e) {
481
506
  let t = e.getBoundingClientRect();
482
507
  return {
483
508
  top: t.top,
@@ -486,7 +511,7 @@ function Ee(e) {
486
511
  height: t.height
487
512
  };
488
513
  }
489
- function De(e, t) {
514
+ function Oe(e, t) {
490
515
  let n = l(e.element ?? "", e.xpath), r = {
491
516
  ...e.element ? { selector: e.element } : {},
492
517
  ...e.xpath ? { xpath: e.xpath } : {}
@@ -495,7 +520,7 @@ function De(e, t) {
495
520
  ...r,
496
521
  found: !1
497
522
  };
498
- let i = ue(n.textContent, _e), a = t ? ue(n.outerHTML, ve) : "", o = n.getAttribute("class"), s = n.getAttribute("role"), c = n.getAttribute("aria-label");
523
+ let i = de(n.textContent, ve), a = t ? de(n.outerHTML, ye) : "", o = n.getAttribute("class"), s = n.getAttribute("role"), c = n.getAttribute("aria-label");
499
524
  return {
500
525
  ...r,
501
526
  found: !0,
@@ -505,40 +530,40 @@ function De(e, t) {
505
530
  ...s ? { role: s } : {},
506
531
  ...c ? { ariaLabel: c } : {},
507
532
  ...i ? { text: i } : {},
508
- rect: Ee(n),
533
+ rect: De(n),
509
534
  ...a ? { htmlPreview: a } : {}
510
535
  };
511
536
  }
512
- function Oe(e) {
537
+ function ke(e) {
513
538
  return {
514
539
  id: e.id,
515
540
  content: e.content,
516
- author: Ce(e.author),
541
+ author: we(e.author),
517
542
  createdAt: e.createdAt
518
543
  };
519
544
  }
520
- function ke(e) {
545
+ function Ae(e) {
521
546
  return e.attachments?.find((e) => e.url && e.type === "screenshot")?.url;
522
547
  }
523
- function Ae(e, t) {
524
- let n = ke(e);
548
+ function je(e, t) {
549
+ let n = Ae(e);
525
550
  return {
526
551
  id: e.id,
527
552
  type: e.type,
528
553
  status: e.status,
529
554
  priority: e.priority,
530
555
  content: e.content,
531
- author: Ce(e.author),
556
+ author: we(e.author),
532
557
  createdAt: e.createdAt,
533
558
  updatedAt: e.updatedAt,
534
559
  page: e.page,
535
560
  position: e.position,
536
- element: De(e.position, t.includeHtml === !0),
561
+ element: Oe(e.position, t.includeHtml === !0),
537
562
  ...n ? { screenshotUrl: n } : {},
538
- replies: e.replies.map(Oe)
563
+ replies: e.replies.map(ke)
539
564
  };
540
565
  }
541
- function je(e) {
566
+ function Me(e) {
542
567
  return {
543
568
  filePath: e.filePath,
544
569
  lineNumber: e.lineNumber,
@@ -546,30 +571,30 @@ function je(e) {
546
571
  componentName: e.componentName
547
572
  };
548
573
  }
549
- function A(e, t = {}) {
574
+ function k(e, t = {}) {
550
575
  let n = u(), r = {
551
576
  url: n.url,
552
577
  path: n.path,
553
578
  title: n.title
554
- }, i = t.commentIds?.length ? new Set(t.commentIds) : null, a = Se(t.maxComments), o = e.comments.filter((e) => Te(e, r, t, i)).slice(0, a).map((e) => Ae(e, t));
579
+ }, i = t.commentIds?.length ? new Set(t.commentIds) : null, a = Ce(t.maxComments), o = e.comments.filter((e) => Ee(e, r, t, i)).slice(0, a).map((e) => je(e, t));
555
580
  return {
556
581
  version: 1,
557
582
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
558
- instructions: O(t.instructions, 2e3) || be,
583
+ instructions: D(t.instructions, 2e3) || xe,
559
584
  page: r,
560
585
  comments: o,
561
586
  sourceResolved: !1
562
587
  };
563
588
  }
564
- async function Me(e) {
589
+ async function Ne(e) {
565
590
  let t = !1, n = await Promise.all(e.comments.map(async (e) => {
566
591
  if (!e.element.found) return e;
567
592
  let n = l(e.element.selector ?? "", e.element.xpath);
568
593
  if (!n) return e;
569
- let r = await me(n);
594
+ let r = await he(n);
570
595
  if (!r || !r.source) return e;
571
596
  t = !0;
572
- let i = je(r.source), a = r.stack.map(je), o = r.componentName ?? void 0;
597
+ let i = Me(r.source), a = r.stack.map(Me), o = r.componentName ?? void 0;
573
598
  return {
574
599
  ...e,
575
600
  element: {
@@ -586,36 +611,36 @@ async function Me(e) {
586
611
  sourceResolved: t
587
612
  };
588
613
  }
589
- function Ne(e) {
614
+ function Pe(e) {
590
615
  let t = `${e.filePath}${e.lineNumber === null ? "" : `:${e.lineNumber}`}${e.columnNumber === null ? "" : `:${e.columnNumber}`}`;
591
616
  return e.componentName ? `${e.componentName} (${t})` : t;
592
617
  }
593
- function j(e) {
618
+ function A(e) {
594
619
  return [
595
620
  "# CommentKit Agent Context",
596
621
  "",
597
622
  e.instructions,
598
623
  "",
599
- `Current page: ${O(e.page.title, 300) || "Untitled"} (${e.page.url || e.page.path || "unknown"})`,
624
+ `Current page: ${D(e.page.title, 300) || "Untitled"} (${e.page.url || e.page.path || "unknown"})`,
600
625
  `Comments: ${e.comments.length}${e.sourceResolved ? " (source-resolved)" : ""}`,
601
626
  "",
602
627
  ...e.comments.map((e, t) => {
603
628
  let n = e.element.found ? `${e.element.tagName}${e.element.id ? `#${e.element.id}` : ""}` : "not found", r = [
604
- `## ${t + 1}. ${O(e.content, 300)}`,
629
+ `## ${t + 1}. ${D(e.content, 300)}`,
605
630
  `- Status: ${e.status}`,
606
631
  `- Priority: ${e.priority}`,
607
632
  `- Author: ${e.author.name} <${e.author.email}>`,
608
633
  `- Page: ${e.page.url}`,
609
634
  `- Element: ${n}`
610
635
  ];
611
- return e.element.source && r.push(`- Source: ${Ne(e.element.source)}`), e.element.stack && e.element.stack.length > 0 && r.push("- Stack:", ...e.element.stack.map((e) => ` - ${Ne(e)}`)), e.element.source || r.push(`- Selector: ${e.element.selector ?? "none"}`, `- XPath: ${e.element.xpath ?? "none"}`), e.screenshotUrl && r.push(`- Screenshot: ${e.screenshotUrl}`), r.push(e.replies.length > 0 ? `- Replies: ${e.replies.length}` : "- Replies: 0", ""), r.join("\n");
636
+ return e.element.source && r.push(`- Source: ${Pe(e.element.source)}`), e.element.stack && e.element.stack.length > 0 && r.push("- Stack:", ...e.element.stack.map((e) => ` - ${Pe(e)}`)), e.element.source || r.push(`- Selector: ${e.element.selector ?? "none"}`, `- XPath: ${e.element.xpath ?? "none"}`), e.screenshotUrl && r.push(`- Screenshot: ${e.screenshotUrl}`), r.push(e.replies.length > 0 ? `- Replies: ${e.replies.length}` : "- Replies: 0", ""), r.join("\n");
612
637
  }),
613
638
  "```json",
614
639
  JSON.stringify(e, null, 2),
615
640
  "```"
616
641
  ].join("\n");
617
642
  }
618
- function Pe(e) {
643
+ function Fe(e) {
619
644
  return {
620
645
  version: e?.version ?? 1,
621
646
  generatedAt: e?.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
@@ -623,10 +648,10 @@ function Pe(e) {
623
648
  context: e
624
649
  };
625
650
  }
626
- function Fe(e, t) {
651
+ function Ie(e, t) {
627
652
  if (typeof document > "u" || !document.body || typeof document.execCommand != "function") return !1;
628
653
  let n = JSON.stringify(t), r = (t) => {
629
- t.preventDefault(), t.clipboardData?.setData("text/plain", e), t.clipboardData?.setData("text/html", `<meta charset="utf-8"><pre><code>${xe(e)}</code></pre>`), t.clipboardData?.setData(ye, n);
654
+ t.preventDefault(), t.clipboardData?.setData("text/plain", e), t.clipboardData?.setData("text/html", `<meta charset="utf-8"><pre><code>${Se(e)}</code></pre>`), t.clipboardData?.setData(be, n);
630
655
  }, i = document.createElement("textarea");
631
656
  i.value = e, i.setAttribute("readonly", ""), i.setAttribute("aria-hidden", "true"), i.style.position = "fixed", i.style.left = "-9999px", document.addEventListener("copy", r), document.body.appendChild(i), i.select();
632
657
  try {
@@ -635,10 +660,10 @@ function Fe(e, t) {
635
660
  document.removeEventListener("copy", r), i.remove();
636
661
  }
637
662
  }
638
- async function Ie(e, t) {
663
+ async function Le(e, t) {
639
664
  if (typeof navigator > "u" || typeof navigator.clipboard?.write != "function" || typeof ClipboardItem > "u") return !1;
640
665
  try {
641
- let n = new Blob([`<meta charset="utf-8"><pre><code>${xe(e)}</code></pre>`], { type: "text/html" }), r = new Blob([e], { type: "text/plain" }), i = t.type && t.type.startsWith("image/") ? t.type : "image/png";
666
+ let n = new Blob([`<meta charset="utf-8"><pre><code>${Se(e)}</code></pre>`], { type: "text/html" }), r = new Blob([e], { type: "text/plain" }), i = t.type && t.type.startsWith("image/") ? t.type : "image/png";
642
667
  return await navigator.clipboard.write([new ClipboardItem({
643
668
  "text/plain": r,
644
669
  "text/html": n,
@@ -648,30 +673,30 @@ async function Ie(e, t) {
648
673
  return !1;
649
674
  }
650
675
  }
651
- async function Le(e, t) {
652
- return t && await Ie(e, t) ? !0 : (await Re(e), !1);
676
+ async function Re(e, t) {
677
+ return t && await Le(e, t) ? !0 : (await ze(e), !1);
653
678
  }
654
- async function Re(e, t = null) {
655
- if (!Fe(e, Pe(t))) {
679
+ async function ze(e, t = null) {
680
+ if (!Ie(e, Fe(t))) {
656
681
  if (typeof navigator < "u" && typeof navigator.clipboard?.writeText == "function") await navigator.clipboard.writeText(e);
657
682
  else throw Error("Clipboard is unavailable");
658
683
  }
659
684
  }
660
- var ze = 100, Be = () => {};
661
- function Ve(e) {
685
+ var Be = 100, Ve = () => {};
686
+ function He(e) {
662
687
  return typeof e == "function";
663
688
  }
664
- var He = class {
689
+ var Ue = class {
665
690
  constructor() {
666
691
  this.listeners = /* @__PURE__ */ new Map(), this.onceWrappers = /* @__PURE__ */ new Map();
667
692
  }
668
693
  on(e, t) {
669
- if (!Ve(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), Be;
694
+ if (!He(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), Ve;
670
695
  let n = this.listeners.get(e);
671
- return n || (n = /* @__PURE__ */ new Set(), this.listeners.set(e, n)), !n.has(t) && n.size >= ze && console.warn(`[CommentKit] Max listeners (${ze}) reached for '${String(e)}' - possible memory leak`), n.add(t), () => this.off(e, t);
696
+ return n || (n = /* @__PURE__ */ new Set(), this.listeners.set(e, n)), !n.has(t) && n.size >= Be && console.warn(`[CommentKit] Max listeners (${Be}) reached for '${String(e)}' - possible memory leak`), n.add(t), () => this.off(e, t);
672
697
  }
673
698
  off(e, t) {
674
- if (!Ve(t)) return;
699
+ if (!He(t)) return;
675
700
  let n = this.listeners.get(e);
676
701
  if (n) {
677
702
  n.delete(t);
@@ -688,7 +713,7 @@ var He = class {
688
713
  }
689
714
  }
690
715
  once(e, t) {
691
- if (!Ve(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), Be;
716
+ if (!He(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), Ve;
692
717
  let n = (n) => {
693
718
  this.off(e, t), t(n);
694
719
  }, r = this.onceWrappers.get(e);
@@ -700,7 +725,7 @@ var He = class {
700
725
  listenerCount(e) {
701
726
  return this.listeners.get(e)?.size ?? 0;
702
727
  }
703
- }, M = Object.freeze({
728
+ }, j = Object.freeze({
704
729
  ID: 256,
705
730
  CONTENT: 1e4,
706
731
  REPLY_CONTENT: 5e3,
@@ -725,39 +750,39 @@ var He = class {
725
750
  REACTION_COUNT: 1e6,
726
751
  PENDING_MUTATIONS: 1e3,
727
752
  RETRY_DELAY: 3e4
728
- }), Ue = "commentkit:session:", We = 4096;
729
- function Ge() {
753
+ }), We = "commentkit:session:", Ge = 4096;
754
+ function Ke() {
730
755
  try {
731
756
  return typeof sessionStorage > "u" ? null : sessionStorage;
732
757
  } catch {
733
758
  return null;
734
759
  }
735
760
  }
736
- function N(e) {
737
- return `${Ue}${e}`;
738
- }
739
- function Ke(e) {
740
- return i(e) && n(e.id, M.ID) && n(e.name, M.NAME) && typeof e.email == "string" && c(e.email, M.EMAIL);
761
+ function M(e) {
762
+ return `${We}${e}`;
741
763
  }
742
764
  function qe(e) {
743
- return i(e) && n(e.token, We) && typeof e.email == "string" && c(e.email, M.EMAIL) && Ke(e.user);
765
+ return i(e) && n(e.id, j.ID) && n(e.name, j.NAME) && typeof e.email == "string" && c(e.email, j.EMAIL);
744
766
  }
745
- function Je(e, t) {
767
+ function Je(e) {
768
+ return i(e) && n(e.token, Ge) && typeof e.email == "string" && c(e.email, j.EMAIL) && qe(e.user);
769
+ }
770
+ function Ye(e, t) {
746
771
  if (!e) return;
747
- let n = Ge();
772
+ let n = Ke();
748
773
  if (n) try {
749
- n.setItem(N(e), JSON.stringify(t));
774
+ n.setItem(M(e), JSON.stringify(t));
750
775
  } catch {}
751
776
  }
752
- function Ye(e) {
777
+ function Xe(e) {
753
778
  if (!e) return null;
754
- let t = Ge();
779
+ let t = Ke();
755
780
  if (!t) return null;
756
781
  try {
757
- let n = t.getItem(N(e));
782
+ let n = t.getItem(M(e));
758
783
  if (!n) return null;
759
784
  let r = JSON.parse(n);
760
- return qe(r) ? {
785
+ return Je(r) ? {
761
786
  token: r.token.trim(),
762
787
  email: r.email.trim(),
763
788
  user: {
@@ -766,19 +791,19 @@ function Ye(e) {
766
791
  email: r.user.email.trim(),
767
792
  ...r.user.avatar ? { avatar: r.user.avatar } : {}
768
793
  }
769
- } : (t.removeItem(N(e)), null);
794
+ } : (t.removeItem(M(e)), null);
770
795
  } catch {
771
796
  return null;
772
797
  }
773
798
  }
774
- function Xe(e) {
799
+ function Ze(e) {
775
800
  if (!e) return;
776
- let t = Ge();
801
+ let t = Ke();
777
802
  if (t) try {
778
- t.removeItem(N(e));
803
+ t.removeItem(M(e));
779
804
  } catch {}
780
805
  }
781
- function Ze(e, t) {
806
+ function Qe(e, t) {
782
807
  for (let n of e.getState().pendingMutations) e.emit("offline:failed", {
783
808
  id: n.id,
784
809
  error: {
@@ -788,55 +813,57 @@ function Ze(e, t) {
788
813
  }
789
814
  });
790
815
  }
791
- var Qe = M.EMAIL, $e = M.NAME, et = M.ID, tt = 4096, nt = 6;
792
- function rt(e) {
816
+ var $e = j.EMAIL, et = j.NAME, tt = j.ID, nt = 4096, rt = 6;
817
+ function it(e) {
793
818
  if (typeof e != "string") return null;
794
819
  let t = e.trim();
795
- return c(t, Qe) ? t : null;
796
- }
797
- function it(e) {
798
- return !r(e) && e.trim().length === nt;
820
+ return c(t, $e) ? t : null;
799
821
  }
800
822
  function at(e) {
801
- return i(e) && n(e.id, et) && n(e.name, $e) && typeof e.email == "string" && rt(e.email) !== null;
823
+ return !r(e) && e.trim().length === rt;
802
824
  }
803
825
  function ot(e) {
804
- return i(e) && n(e.id, et);
826
+ return i(e) && n(e.id, tt) && n(e.name, et) && typeof e.email == "string" && it(e.email) !== null;
805
827
  }
806
- function P(e, t, n) {
828
+ function st(e) {
829
+ return i(e) && n(e.id, tt);
830
+ }
831
+ function N(e, t, n) {
807
832
  return {
808
833
  error: e,
809
834
  message: t,
810
835
  code: n
811
836
  };
812
837
  }
813
- async function st(e, t) {
814
- let n = rt(t);
815
- if (!n) e.setState({
838
+ async function ct(e, t, n = () => !0) {
839
+ let r = it(t);
840
+ if (!r) e.setState({
816
841
  isLoading: !1,
817
842
  otpStep: "idle",
818
843
  otpEmail: null
819
- }), e.handleError(P("invalid_email", "A valid email address is required", 400));
844
+ }), e.handleError(N("invalid_email", "A valid email address is required", 400));
820
845
  else try {
821
846
  e.setState({
822
847
  isLoading: !0,
823
848
  error: null,
824
849
  otpStep: "requesting",
825
- otpEmail: n
850
+ otpEmail: r
826
851
  });
827
- let t = await e.apiClient.requestOtp(n);
852
+ let t = await e.apiClient.requestOtp(r);
853
+ if (!n()) return;
828
854
  t.success ? (e.setState({
829
855
  otpStep: "verifying",
830
856
  isLoading: !1
831
857
  }), e.emit("auth:otp-requested", {
832
- email: n,
858
+ email: r,
833
859
  expiresIn: t.expiresIn
834
860
  })) : (e.setState({
835
861
  isLoading: !1,
836
862
  otpStep: "idle",
837
863
  otpEmail: null
838
- }), e.handleError(P("otp_failed", "Failed to send OTP. Please try again.", 500)));
864
+ }), e.handleError(N("otp_failed", "Failed to send OTP. Please try again.", 500)));
839
865
  } catch (t) {
866
+ if (!n()) return;
840
867
  e.setState({
841
868
  isLoading: !1,
842
869
  otpStep: "idle",
@@ -844,35 +871,40 @@ async function st(e, t) {
844
871
  }), e.handleError(t);
845
872
  }
846
873
  }
847
- async function ct(e, t, r) {
848
- let { onAuthenticated: i, onWrongOtp: a, onSuccess: o } = typeof r == "function" ? { onAuthenticated: r } : r, s = e.getState().otpEmail;
849
- if (!s) e.handleError(P("no_email", "No OTP request in progress", 400));
850
- else if (!it(t)) e.setState({ isLoading: !1 }), e.handleError(P("invalid_otp", "Invalid or expired OTP code", 401));
874
+ async function lt(e, t, r) {
875
+ let { onAuthenticated: i, onWrongOtp: a, onSuccess: o, isCurrent: s = () => !0 } = typeof r == "function" ? { onAuthenticated: r } : r, c = e.getState().otpEmail;
876
+ if (!c) e.handleError(N("no_email", "No OTP request in progress", 400));
877
+ else if (!at(t)) e.setState({ isLoading: !1 }), e.handleError(N("invalid_otp", "Invalid or expired OTP code", 401));
851
878
  else try {
852
879
  e.setState({
853
880
  isLoading: !0,
854
881
  error: null
855
882
  });
856
- let r = await e.apiClient.verifyOtp(s, t);
857
- r.verified && n(r.token, tt) && at(r.user) && ot(r.project) ? (e.apiClient.setAuthToken(r.token), e.apiClient.setUserEmail(r.user.email), Je(e.config.projectId, {
858
- token: r.token,
859
- email: r.user.email,
860
- user: r.user
861
- }), e.setState({
862
- currentUser: r.user,
863
- project: r.project,
864
- isAuthenticated: !0,
865
- isLoginModalVisible: !1,
866
- isOverlayVisible: !0,
867
- isLoading: !1,
868
- otpStep: "idle",
869
- otpEmail: null
870
- }), o?.(), e.emit("auth:otp-verified", r.user), e.emit("auth:login", r.user), await i()) : (e.setState({ isLoading: !1 }), a?.(), e.handleError(P("invalid_otp", "Invalid or expired OTP code", 401)));
883
+ let r = await e.apiClient.verifyOtp(c, t);
884
+ if (!s()) return;
885
+ if (r.verified && n(r.token, nt) && ot(r.user) && st(r.project)) {
886
+ if (e.apiClient.setAuthToken(r.token), e.apiClient.setUserEmail(r.user.email), Ye(e.config.projectId, {
887
+ token: r.token,
888
+ email: r.user.email,
889
+ user: r.user
890
+ }), e.setState({
891
+ currentUser: r.user,
892
+ project: r.project,
893
+ isAuthenticated: !0,
894
+ isLoginModalVisible: !1,
895
+ isOverlayVisible: !0,
896
+ isLoading: !1,
897
+ otpStep: "idle",
898
+ otpEmail: null
899
+ }), o?.(), e.emit("auth:otp-verified", r.user), !s() || (e.emit("auth:login", r.user), !s())) return;
900
+ await i();
901
+ } else e.setState({ isLoading: !1 }), a?.(), e.handleError(N("invalid_otp", "Invalid or expired OTP code", 401));
871
902
  } catch (t) {
903
+ if (!s()) return;
872
904
  e.setState({ isLoading: !1 }), e.handleError(t);
873
905
  }
874
906
  }
875
- function lt(e) {
907
+ function ut(e) {
876
908
  e.setState({
877
909
  otpStep: "idle",
878
910
  otpEmail: null,
@@ -880,12 +912,12 @@ function lt(e) {
880
912
  isLoading: !1
881
913
  });
882
914
  }
883
- async function ut(e) {
884
- let t = e.getState().otpEmail;
885
- t && await st(e, t);
915
+ async function dt(e, t = () => !0) {
916
+ let n = e.getState().otpEmail;
917
+ n && await ct(e, n, t);
886
918
  }
887
- function dt(e, t) {
888
- Ze(e, "Pending offline changes were discarded on logout"), Xe(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), t(), e.setState({
919
+ function ft(e, t) {
920
+ Qe(e, "Pending offline changes were discarded on logout"), Ze(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), t(), e.setState({
889
921
  isAuthenticated: !1,
890
922
  currentUser: null,
891
923
  comments: [],
@@ -913,8 +945,8 @@ function dt(e, t) {
913
945
  isLoading: !1
914
946
  }), e.emit("auth:logout", void 0);
915
947
  }
916
- function ft(e) {
917
- Ze(e, "Pending offline changes were discarded because the session expired"), Xe(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), e.setState({
948
+ function pt(e) {
949
+ Qe(e, "Pending offline changes were discarded because the session expired"), Ze(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), e.setState({
918
950
  isAuthenticated: !1,
919
951
  currentUser: null,
920
952
  comments: [],
@@ -937,72 +969,76 @@ function ft(e) {
937
969
  code: 401
938
970
  });
939
971
  }
940
- function pt(e) {
972
+ function mt(e) {
941
973
  e.setState({ isLoginModalVisible: !e.getState().isLoginModalVisible });
942
974
  }
943
- async function mt(e, t, n) {
944
- let r = e.config.inviteToken;
945
- if (!r) {
946
- e.handleError(P("no_invite", "No invite token found", 400));
975
+ async function ht(e, t, n, r = () => !0) {
976
+ let i = e.config.inviteToken;
977
+ if (!i) {
978
+ e.handleError(N("no_invite", "No invite token found", 400));
947
979
  return;
948
980
  }
949
- let i = rt(t);
950
- if (!i) e.setState({ isLoading: !1 }), e.handleError(P("invalid_email", "A valid email address is required", 400));
981
+ let a = it(t);
982
+ if (!a) e.setState({ isLoading: !1 }), e.handleError(N("invalid_email", "A valid email address is required", 400));
951
983
  else try {
952
984
  e.setState({
953
985
  isLoading: !0,
954
986
  error: null
955
- }), (await e.apiClient.validateInvite(r, i)).success ? await n(i) : (e.setState({ isLoading: !1 }), e.handleError(P("invite_invalid", "Invite validation failed", 400)));
987
+ });
988
+ let t = await e.apiClient.validateInvite(i, a);
989
+ if (!r()) return;
990
+ t.success ? await n(a) : (e.setState({ isLoading: !1 }), e.handleError(N("invite_invalid", "Invite validation failed", 400)));
956
991
  } catch (t) {
992
+ if (!r()) return;
957
993
  e.setState({ isLoading: !1 }), e.handleError(t);
958
994
  }
959
995
  }
960
- var F = M.ID, ht = M.CONTENT, gt = M.REPLY_CONTENT, _t = M.SELECTOR, vt = M.TEXT_SELECTION, yt = M.DESCRIPTION, bt = M.ASSIGNEES, xt = M.CHECKLIST_ITEMS, St = M.CHECKLIST_LABEL, Ct = M.DRAWING_PATHS, wt = M.DRAWING_PATH_DATA, Tt = M.DRAWING_TEXT, Et = M.REACTION_COUNT, Dt = M.EMOJI, Ot = /* @__PURE__ */ new Set([
996
+ var P = j.ID, gt = j.CONTENT, _t = j.REPLY_CONTENT, vt = j.SELECTOR, yt = j.TEXT_SELECTION, bt = j.DESCRIPTION, xt = j.ASSIGNEES, St = j.CHECKLIST_ITEMS, Ct = j.CHECKLIST_LABEL, wt = j.DRAWING_PATHS, Tt = j.DRAWING_PATH_DATA, Et = j.DRAWING_TEXT, Dt = j.REACTION_COUNT, Ot = j.EMOJI, kt = /* @__PURE__ */ new Set([
961
997
  "pin",
962
998
  "highlight",
963
999
  "drawing"
964
- ]), kt = /* @__PURE__ */ new Set([
1000
+ ]), At = /* @__PURE__ */ new Set([
965
1001
  "low",
966
1002
  "medium",
967
1003
  "high",
968
1004
  "urgent"
969
- ]), At = /* @__PURE__ */ new Set([
1005
+ ]), jt = /* @__PURE__ */ new Set([
970
1006
  "open",
971
1007
  "resolved",
972
1008
  "complete"
973
- ]), jt = /* @__PURE__ */ new Set([
1009
+ ]), Mt = /* @__PURE__ */ new Set([
974
1010
  "path",
975
1011
  "line",
976
1012
  "rectangle",
977
1013
  "circle",
978
1014
  "text"
979
1015
  ]);
980
- function I(e, t, n) {
981
- e.handleError(new D(t, n, 400));
1016
+ function F(e, t, n) {
1017
+ e.handleError(new E(t, n, 400));
982
1018
  }
983
- function L(e) {
984
- return n(e, F);
1019
+ function I(e) {
1020
+ return n(e, P);
985
1021
  }
986
- function R(e, t = ht) {
1022
+ function L(e, t = gt) {
987
1023
  if (typeof e != "string") return null;
988
1024
  let n = e.trim();
989
1025
  return !n || n.length > t || a(n) ? null : n;
990
1026
  }
991
- function z(e, t) {
1027
+ function R(e, t) {
992
1028
  if (e === void 0) return;
993
1029
  if (typeof e != "string") return null;
994
1030
  let n = e.trim();
995
1031
  return n.length > t || a(n) ? null : n;
996
1032
  }
997
- function B(e) {
1033
+ function z(e) {
998
1034
  if (e === void 0) return;
999
1035
  if (typeof e != "string") return null;
1000
1036
  let t = e.trim();
1001
- return !t || t.length > _t || a(t) ? null : t;
1037
+ return !t || t.length > vt || a(t) ? null : t;
1002
1038
  }
1003
- function Mt(t) {
1039
+ function Nt(t) {
1004
1040
  if (!i(t) || !e(t.x) || !e(t.y)) return null;
1005
- let n = B(t.element), r = B(t.xpath);
1041
+ let n = z(t.element), r = z(t.xpath);
1006
1042
  return n === null || r === null ? null : {
1007
1043
  x: t.x,
1008
1044
  y: t.y,
@@ -1010,10 +1046,10 @@ function Mt(t) {
1010
1046
  ...r === void 0 ? {} : { xpath: r }
1011
1047
  };
1012
1048
  }
1013
- function Nt(e) {
1049
+ function Pt(e) {
1014
1050
  if (!i(e)) return null;
1015
- let t = z(e.avatar, _t), n = z(e.organizationId, F);
1016
- return !L(e.id) || typeof e.name != "string" || !e.name.trim() || e.name.length > M.NAME || a(e.name) || typeof e.email != "string" || !e.email.trim() || e.email.length > M.EMAIL || /\s/.test(e.email.trim()) || a(e.email) || t === null || n === null ? null : {
1051
+ let t = R(e.avatar, vt), n = R(e.organizationId, P);
1052
+ return !I(e.id) || typeof e.name != "string" || !e.name.trim() || e.name.length > j.NAME || a(e.name) || typeof e.email != "string" || !e.email.trim() || e.email.length > j.EMAIL || /\s/.test(e.email.trim()) || a(e.email) || t === null || n === null ? null : {
1017
1053
  id: e.id.trim(),
1018
1054
  name: e.name.trim(),
1019
1055
  email: e.email.trim(),
@@ -1021,25 +1057,25 @@ function Nt(e) {
1021
1057
  ...n === void 0 ? {} : { organizationId: n }
1022
1058
  };
1023
1059
  }
1024
- function Pt(e) {
1060
+ function Ft(e) {
1025
1061
  if (e === void 0) return;
1026
- if (!Array.isArray(e) || e.length > bt) return null;
1062
+ if (!Array.isArray(e) || e.length > xt) return null;
1027
1063
  let t = [];
1028
1064
  for (let n of e) {
1029
- let e = Nt(n);
1065
+ let e = Pt(n);
1030
1066
  if (!e) return null;
1031
1067
  t.push(e);
1032
1068
  }
1033
1069
  return t;
1034
1070
  }
1035
- function Ft(e) {
1071
+ function It(e) {
1036
1072
  if (e === void 0) return;
1037
- if (!Array.isArray(e) || e.length > xt) return null;
1073
+ if (!Array.isArray(e) || e.length > St) return null;
1038
1074
  let t = [];
1039
1075
  for (let n of e) {
1040
1076
  if (!i(n)) return null;
1041
- let e = R(n.label);
1042
- if (!L(n.id) || !e || typeof n.done != "boolean" || n.sortOrder !== void 0 && (typeof n.sortOrder != "number" || !Number.isFinite(n.sortOrder)) || e.length > St) return null;
1077
+ let e = L(n.label);
1078
+ if (!I(n.id) || !e || typeof n.done != "boolean" || n.sortOrder !== void 0 && (typeof n.sortOrder != "number" || !Number.isFinite(n.sortOrder)) || e.length > Ct) return null;
1043
1079
  t.push({
1044
1080
  id: n.id.trim(),
1045
1081
  label: e,
@@ -1049,11 +1085,11 @@ function Ft(e) {
1049
1085
  }
1050
1086
  return t;
1051
1087
  }
1052
- function It(e) {
1088
+ function Lt(e) {
1053
1089
  if (e === void 0) return;
1054
1090
  if (!i(e) || typeof e.text != "string") return null;
1055
- let t = e.text.trim(), n = B(e.element), r = B(e.xpath);
1056
- return !t || t.length > vt || a(t) || typeof e.startOffset != "number" || typeof e.endOffset != "number" || !Number.isInteger(e.startOffset) || !Number.isInteger(e.endOffset) || e.startOffset < 0 || e.endOffset < e.startOffset || n === null || r === null || n === void 0 || r === void 0 ? null : {
1091
+ let t = e.text.trim(), n = z(e.element), r = z(e.xpath);
1092
+ return !t || t.length > yt || a(t) || typeof e.startOffset != "number" || typeof e.endOffset != "number" || !Number.isInteger(e.startOffset) || !Number.isInteger(e.endOffset) || e.startOffset < 0 || e.endOffset < e.startOffset || n === null || r === null || n === void 0 || r === void 0 ? null : {
1057
1093
  text: t,
1058
1094
  startOffset: e.startOffset,
1059
1095
  endOffset: e.endOffset,
@@ -1061,20 +1097,20 @@ function It(e) {
1061
1097
  xpath: r
1062
1098
  };
1063
1099
  }
1064
- function Lt(e) {
1065
- return typeof e == "string" && e.length > 0 && e.length <= M.COLOR && !a(e);
1100
+ function Rt(e) {
1101
+ return typeof e == "string" && e.length > 0 && e.length <= j.COLOR && !a(e);
1066
1102
  }
1067
- function V(e) {
1103
+ function B(e) {
1068
1104
  return e === void 0 || typeof e == "number" && Number.isFinite(e);
1069
1105
  }
1070
- function Rt(e) {
1106
+ function zt(e) {
1071
1107
  if (e === void 0) return;
1072
- if (!i(e) || e.type !== "svg" || !Array.isArray(e.paths) || e.paths.length > Ct || !i(e.viewport) || typeof e.viewport.width != "number" || typeof e.viewport.height != "number" || !Number.isFinite(e.viewport.width) || !Number.isFinite(e.viewport.height) || e.viewport.width <= 0 || e.viewport.height <= 0) return null;
1108
+ if (!i(e) || e.type !== "svg" || !Array.isArray(e.paths) || e.paths.length > wt || !i(e.viewport) || typeof e.viewport.width != "number" || typeof e.viewport.height != "number" || !Number.isFinite(e.viewport.width) || !Number.isFinite(e.viewport.height) || e.viewport.width <= 0 || e.viewport.height <= 0) return null;
1073
1109
  let t = [];
1074
1110
  for (let n of e.paths) {
1075
- if (!i(n) || !jt.has(String(n.type))) return null;
1076
- let e = z(n.text, Tt);
1077
- if (!Lt(n.stroke) || !Lt(n.fill) || typeof n.strokeWidth != "number" || !Number.isFinite(n.strokeWidth) || n.strokeWidth < 0 || n.d !== void 0 && (typeof n.d != "string" || n.d.length > wt || a(n.d)) || !V(n.x) || !V(n.y) || !V(n.width) || !V(n.height) || e === null) return null;
1111
+ if (!i(n) || !Mt.has(String(n.type))) return null;
1112
+ let e = R(n.text, Et);
1113
+ if (!Rt(n.stroke) || !Rt(n.fill) || typeof n.strokeWidth != "number" || !Number.isFinite(n.strokeWidth) || n.strokeWidth < 0 || n.d !== void 0 && (typeof n.d != "string" || n.d.length > Tt || a(n.d)) || !B(n.x) || !B(n.y) || !B(n.width) || !B(n.height) || e === null) return null;
1078
1114
  t.push({
1079
1115
  type: n.type,
1080
1116
  stroke: n.stroke,
@@ -1097,112 +1133,140 @@ function Rt(e) {
1097
1133
  }
1098
1134
  };
1099
1135
  }
1100
- function zt(e) {
1136
+ function Bt(e) {
1137
+ return i(e) && typeof e.browser == "string" && e.browser.length <= 255 && typeof e.os == "string" && e.os.length <= 255 && typeof e.windowSize == "string" && e.windowSize.length <= 64 && typeof e.devicePixelRatio == "number" && e.devicePixelRatio > 0 && e.devicePixelRatio <= 16 && (e.type === "desktop" || e.type === "mobile") && (e.deployment === void 0 || typeof e.deployment == "string" && e.deployment.length <= 255);
1138
+ }
1139
+ function Vt(e) {
1101
1140
  if (e === void 0) return;
1102
1141
  if (!i(e)) return null;
1103
- let t = z(e.description, yt), n = Pt(e.assignees), r = Ft(e.checklist);
1142
+ let t = R(e.description, bt), n = Ft(e.assignees), r = It(e.checklist);
1104
1143
  if (t === null || n === null || r === null) return null;
1105
- let a = Array.isArray(e.files) ? e.files.filter((e) => typeof File < "u" && e instanceof File) : void 0, o = Array.isArray(e.attachmentIds) ? e.attachmentIds.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= F).slice(0, 20) : void 0;
1144
+ let o = Array.isArray(e.files) ? e.files.filter((e) => typeof File < "u" && e instanceof File) : void 0, s = Array.isArray(e.attachmentIds) ? e.attachmentIds.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= P).slice(0, 20) : void 0;
1106
1145
  return {
1146
+ ...Array.isArray(e.mentions) ? { mentions: e.mentions.filter((e) => i(e) && I(e.userId) && typeof e.name == "string").slice(0, 100) } : {},
1147
+ ...typeof e.branch == "string" && e.branch.trim() && e.branch.length <= 255 && !a(e.branch) ? { branch: e.branch.trim() } : {},
1148
+ ...Bt(e.deviceInfo) ? { deviceInfo: e.deviceInfo } : {},
1107
1149
  ...t === void 0 ? {} : { description: t },
1108
1150
  ...n === void 0 ? {} : { assignees: n },
1109
1151
  ...r === void 0 ? {} : { checklist: r },
1110
- ...a && a.length > 0 ? { files: a } : {},
1111
- ...o && o.length > 0 ? { attachmentIds: o } : {}
1152
+ ...o && o.length > 0 ? { files: o } : {},
1153
+ ...s && s.length > 0 ? { attachmentIds: s } : {}
1112
1154
  };
1113
1155
  }
1114
- function Bt(e) {
1156
+ function Ht(e) {
1115
1157
  if (!i(e)) return null;
1116
1158
  let t = {};
1117
1159
  if ("content" in e) {
1118
- let n = R(e.content);
1160
+ let n = L(e.content);
1119
1161
  if (!n) return null;
1120
1162
  t.content = n;
1121
1163
  }
1122
1164
  if ("status" in e) {
1123
- if (!At.has(e.status)) return null;
1165
+ if (!jt.has(e.status)) return null;
1124
1166
  t.status = e.status;
1125
1167
  }
1126
1168
  if ("priority" in e) {
1127
- if (!kt.has(e.priority)) return null;
1169
+ if (!At.has(e.priority)) return null;
1128
1170
  t.priority = e.priority;
1129
1171
  }
1130
1172
  if ("description" in e) {
1131
- let n = z(e.description, yt);
1173
+ let n = R(e.description, bt);
1132
1174
  if (n === null) return null;
1133
1175
  t.description = n;
1134
1176
  }
1135
- if ("assignees" in e) {
1136
- let n = Pt(e.assignees);
1177
+ if (Array.isArray(e.mentions) && (t.mentions = e.mentions.filter((e) => i(e) && I(e.userId) && typeof e.name == "string").slice(0, 100)), "assignees" in e) {
1178
+ let n = Ft(e.assignees);
1137
1179
  if (n === null) return null;
1138
1180
  t.assignees = n;
1139
1181
  }
1140
1182
  if ("checklist" in e) {
1141
- let n = Ft(e.checklist);
1183
+ let n = It(e.checklist);
1142
1184
  if (n === null) return null;
1143
1185
  t.checklist = n;
1144
1186
  }
1145
1187
  if ("textSelection" in e) {
1146
- let n = It(e.textSelection);
1188
+ let n = Lt(e.textSelection);
1147
1189
  if (n === null) return null;
1148
1190
  t.textSelection = n;
1149
1191
  }
1150
1192
  if ("drawingData" in e) {
1151
- let n = Rt(e.drawingData);
1193
+ let n = zt(e.drawingData);
1152
1194
  if (n === null) return null;
1153
1195
  t.drawingData = n;
1154
1196
  }
1155
1197
  if ("attachmentIds" in e) {
1156
1198
  let n = e.attachmentIds;
1157
1199
  if (!Array.isArray(n)) return null;
1158
- t.attachmentIds = n.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= F).slice(0, 20);
1200
+ t.attachmentIds = n.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= P).slice(0, 20);
1159
1201
  }
1160
1202
  return Object.keys(t).length > 0 ? t : void 0;
1161
1203
  }
1162
- function H(e) {
1204
+ function V(e) {
1163
1205
  return `${e}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
1164
1206
  }
1165
- function U(e, t) {
1207
+ function H(e, t) {
1166
1208
  return e.getState().comments.some((e) => e.id === t);
1167
1209
  }
1168
- function W(e, t, n) {
1210
+ function U(e, t, n) {
1211
+ if (e.getState().activeBranch && n.branch !== e.getState().activeBranch) {
1212
+ e.setState({ comments: e.getState().comments.filter((e) => e.id !== t) });
1213
+ return;
1214
+ }
1169
1215
  let r = e.getState().comments.filter((e) => e.id !== n.id), i = r.some((e) => e.id === t);
1170
1216
  e.setState({ comments: i ? r.map((e) => e.id === t ? n : e) : [...r, n] });
1171
1217
  }
1172
- function Vt(e, t, n, r) {
1218
+ function Ut(e, t, n, r) {
1173
1219
  e.setState({ comments: e.getState().comments.map((e) => {
1174
1220
  if (e.id !== t) return e;
1175
1221
  let i = e.replies.filter((e) => e.id !== r.id), a = i.some((e) => e.id === n);
1176
1222
  return {
1177
1223
  ...e,
1224
+ status: "open",
1225
+ resolvedAt: void 0,
1226
+ completedAt: void 0,
1178
1227
  replies: a ? i.map((e) => e.id === n ? r : e) : [...i, r]
1179
1228
  };
1180
1229
  }) });
1181
1230
  }
1182
- function Ht(e, t, n) {
1231
+ function W(e, t) {
1232
+ return !t || t === e.status ? e : {
1233
+ ...e,
1234
+ status: t,
1235
+ completedAt: void 0,
1236
+ ...t === "complete" ? {} : { resolvedAt: void 0 }
1237
+ };
1238
+ }
1239
+ function Wt(e, t, n) {
1183
1240
  return e.getState().comments.some((e) => e.id === t && e.replies.some((e) => e.id === n));
1184
1241
  }
1185
- async function G(e) {
1242
+ async function Gt(e) {
1243
+ let t = e.getState().activeBranch;
1244
+ e.setState({ isLoading: !0 });
1186
1245
  try {
1187
- let t = u(), n = await e.apiClient.getComments(t.path);
1246
+ let n = await e.apiClient.getComments(void 0, "all", 1, 50, void 0, t);
1247
+ if (t !== e.getState().activeBranch) return;
1188
1248
  e.setState({
1189
1249
  comments: n.comments,
1190
1250
  pagination: n.pagination
1191
1251
  });
1192
1252
  } catch (t) {
1193
1253
  e.handleError(t);
1254
+ } finally {
1255
+ e.setState({ isLoading: !1 });
1194
1256
  }
1195
1257
  }
1196
- async function Ut(e, t) {
1197
- let n = e.getState().pagination;
1198
- if (n && n.hasMore && !t.current) {
1258
+ async function Kt(e, t) {
1259
+ let n = e.getState().activeBranch, r = e.getState().pagination;
1260
+ if (r && r.hasMore && !t.current) {
1199
1261
  t.current = !0;
1200
1262
  try {
1201
1263
  e.setState({ isLoading: !0 });
1202
- let t = u(), r = await e.apiClient.getComments(t.path, "all", n.page + 1, n.limit), i = new Set(e.getState().comments.map((e) => e.id)), a = r.comments.filter((e) => !i.has(e.id));
1264
+ let t = await e.apiClient.getComments(void 0, "all", r.page + 1, r.limit, void 0, n);
1265
+ if (n !== e.getState().activeBranch) return;
1266
+ let i = new Set(e.getState().comments.map((e) => e.id)), a = t.comments.filter((e) => !i.has(e.id));
1203
1267
  e.setState({
1204
1268
  comments: [...e.getState().comments, ...a],
1205
- pagination: r.pagination,
1269
+ pagination: t.pagination,
1206
1270
  isLoading: !1
1207
1271
  });
1208
1272
  } catch (t) {
@@ -1212,25 +1276,25 @@ async function Ut(e, t) {
1212
1276
  }
1213
1277
  }
1214
1278
  }
1215
- async function Wt(e, t, n, r, i, a, o = "medium", s, c, l) {
1279
+ async function qt(e, t, n, r, i, a, o = "medium", s, c, l) {
1216
1280
  let d = e.getState().currentUser;
1217
1281
  if (!d) return;
1218
- let f = R(i), p = Mt(a), m = It(s), h = Rt(c), g = zt(l);
1219
- if (!Ot.has(r) || !f || !p || !kt.has(o) || m === null || h === null || g === null) {
1220
- I(e, "invalid_comment", "Comment data is invalid");
1282
+ let f = L(i), p = Nt(a), m = Lt(s), h = zt(c), g = Vt(l);
1283
+ if (!kt.has(r) || !f || !p || !At.has(o) || m === null || h === null || g === null) {
1284
+ F(e, "invalid_comment", "Comment data is invalid");
1221
1285
  return;
1222
1286
  }
1223
1287
  let _ = `create:${r}:${f.slice(0, 50)}:${p.x}:${p.y}`;
1224
1288
  if (n.has(_)) return;
1225
1289
  n.add(_);
1226
- let v = u(), y = g?.files ?? [], b = y.map((e, t) => ({
1227
- id: H(`pending-att-${t}`),
1290
+ let v = u(), ee = g?.files ?? [], y = ee.map((e, t) => ({
1291
+ id: V(`pending-att-${t}`),
1228
1292
  type: e.type.startsWith("image/") ? "screenshot" : "file",
1229
1293
  url: "",
1230
1294
  filename: e.name,
1231
1295
  size: e.size
1232
- })), x = H("temp"), S = {
1233
- id: x,
1296
+ })), b = V("temp"), x = {
1297
+ id: b,
1234
1298
  type: r,
1235
1299
  content: f,
1236
1300
  position: p,
@@ -1245,16 +1309,19 @@ async function Wt(e, t, n, r, i, a, o = "medium", s, c, l) {
1245
1309
  path: v.path,
1246
1310
  title: v.title
1247
1311
  },
1312
+ branch: g?.branch,
1313
+ deviceInfo: g?.deviceInfo,
1314
+ mentions: g?.mentions,
1248
1315
  description: g?.description,
1249
1316
  assignees: g?.assignees,
1250
1317
  checklist: g?.checklist,
1251
1318
  replies: [],
1252
- attachments: b,
1319
+ attachments: y,
1253
1320
  textSelection: m,
1254
1321
  drawingData: h
1255
1322
  };
1256
1323
  e.setState({
1257
- comments: [...e.getState().comments, S],
1324
+ comments: [...e.getState().comments, x],
1258
1325
  activeComment: null,
1259
1326
  activeTool: null,
1260
1327
  isCommentModeActive: !1,
@@ -1262,9 +1329,9 @@ async function Wt(e, t, n, r, i, a, o = "medium", s, c, l) {
1262
1329
  isHighlightModeActive: !1
1263
1330
  });
1264
1331
  try {
1265
- let { files: n, ...i } = g ?? {}, a = await e.apiClient.createComment(r, f, p, v, o, m, h, i, x), s = a;
1266
- if (y.length > 0) try {
1267
- let t = (await Promise.all(y.map(async (t) => {
1332
+ let { files: n, ...i } = g ?? {}, a = await e.apiClient.createComment(r, f, p, v, o, m, h, i, b), s = a;
1333
+ if (ee.length > 0) try {
1334
+ let t = (await Promise.all(ee.map(async (t) => {
1268
1335
  let n = "." + (t.name.split(".").pop()?.toLowerCase() ?? ""), r = t.type.startsWith("image/") && [
1269
1336
  ".jpg",
1270
1337
  ".jpeg",
@@ -1291,7 +1358,7 @@ async function Wt(e, t, n, r, i, a, o = "medium", s, c, l) {
1291
1358
  attachments: a.attachments ?? []
1292
1359
  };
1293
1360
  }
1294
- W(e, x, s), e.emit("comment:created", s), t.addActivity({
1361
+ U(e, b, s), e.emit("comment:created", s), t.addActivity({
1295
1362
  type: "comment_created",
1296
1363
  threadId: s.id,
1297
1364
  message: "created a new comment"
@@ -1307,6 +1374,9 @@ async function Wt(e, t, n, r, i, a, o = "medium", s, c, l) {
1307
1374
  g ? {
1308
1375
  description: g.description,
1309
1376
  assignees: g.assignees,
1377
+ mentions: g.mentions,
1378
+ branch: g.branch,
1379
+ deviceInfo: g.deviceInfo,
1310
1380
  checklist: g.checklist,
1311
1381
  attachmentIds: g.attachmentIds
1312
1382
  } : void 0,
@@ -1315,23 +1385,23 @@ async function Wt(e, t, n, r, i, a, o = "medium", s, c, l) {
1315
1385
  path: v.path,
1316
1386
  title: v.title
1317
1387
  }
1318
- ], x) || (e.setState({ comments: e.getState().comments.filter((e) => e.id !== x) }), e.handleError(n));
1388
+ ], b) || (e.setState({ comments: e.getState().comments.filter((e) => e.id !== b) }), e.handleError(n));
1319
1389
  } finally {
1320
1390
  n.delete(_);
1321
1391
  }
1322
1392
  }
1323
- async function Gt(e, t, n, r) {
1324
- if (!L(n)) return;
1325
- let i = Bt(r);
1393
+ async function Jt(e, t, n, r) {
1394
+ if (!I(n)) return;
1395
+ let i = Ht(r);
1326
1396
  if (i === null) {
1327
- I(e, "invalid_comment_update", "Comment update data is invalid");
1397
+ F(e, "invalid_comment_update", "Comment update data is invalid");
1328
1398
  return;
1329
1399
  }
1330
1400
  if (i === void 0) return;
1331
1401
  let a = e.getState().comments, o = a.find((e) => e.id === n);
1332
1402
  if (o) {
1333
1403
  e.setState({ comments: a.map((e) => e.id === n ? {
1334
- ...e,
1404
+ ...W(e, i.status),
1335
1405
  ...i
1336
1406
  } : e) });
1337
1407
  try {
@@ -1342,8 +1412,8 @@ async function Gt(e, t, n, r) {
1342
1412
  }
1343
1413
  }
1344
1414
  }
1345
- async function Kt(e, t, n) {
1346
- if (!L(n)) return;
1415
+ async function Yt(e, t, n) {
1416
+ if (!I(n)) return;
1347
1417
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1348
1418
  if (!i) return;
1349
1419
  let a = e.getState().selectedComment;
@@ -1355,76 +1425,90 @@ async function Kt(e, t, n) {
1355
1425
  await e.apiClient.deleteComment(n), e.emit("comment:deleted", { id: n });
1356
1426
  } catch (r) {
1357
1427
  if (!(t.shouldQueueMutation(r) && t.queueMutation("deleteComment", [n]))) {
1358
- let t = e.getState().comments;
1359
- e.setState({
1360
- comments: t.some((e) => e.id === n) ? t : [...t, i],
1361
- selectedComment: a
1428
+ let t = e.getState(), o = t.comments;
1429
+ (!t.activeBranch || i.branch === t.activeBranch) && e.setState({
1430
+ comments: o.some((e) => e.id === n) ? o : [...o, i],
1431
+ selectedComment: t.selectedComment ?? a
1362
1432
  }), e.handleError(r);
1363
1433
  }
1364
1434
  }
1365
1435
  }
1366
- async function qt(e, t, n, r) {
1367
- let i = e.getState().currentUser;
1368
- if (!i || !L(n) || !U(e, n)) return;
1369
- let a = R(r, gt);
1370
- if (!a) {
1371
- I(e, "invalid_reply", "Reply content is invalid");
1436
+ async function Xt(e, t, n, r, i) {
1437
+ let a = e.getState().currentUser;
1438
+ if (!a || !I(n) || !H(e, n)) return;
1439
+ let o = L(r, _t);
1440
+ if (!o) {
1441
+ F(e, "invalid_reply", "Reply content is invalid");
1442
+ return;
1443
+ }
1444
+ if (i?.replyTo && (!I(i.replyTo.id) || i.replyTo.id.startsWith("temp_") || !["comment", "reply"].includes(i.replyTo.type) || (i.replyTo.type === "comment" ? i.replyTo.id !== n : !Wt(e, n, i.replyTo.id)))) {
1445
+ F(e, "invalid_reply", "Reply target must belong to this thread");
1372
1446
  return;
1373
1447
  }
1374
- let o = H("temp_reply"), s = {
1375
- id: o,
1376
- content: a,
1377
- author: i,
1448
+ let s = e.getState().comments.find((e) => e.id === n), c = i?.replyTo?.type === "comment" ? s : s?.replies.find((e) => e.id === i?.replyTo?.id), l = V("temp_reply"), u = {
1449
+ ...c && i?.replyTo ? { replyTo: {
1450
+ ...i.replyTo,
1451
+ authorName: c.author.name,
1452
+ body: c.content
1453
+ } } : {},
1454
+ ...i?.mentions ? { mentions: i.mentions } : {},
1455
+ id: l,
1456
+ content: o,
1457
+ author: a,
1378
1458
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
1379
1459
  };
1380
1460
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? {
1381
1461
  ...e,
1382
- replies: [...e.replies, s]
1462
+ replies: [...e.replies, u]
1383
1463
  } : e) });
1384
1464
  try {
1385
- Vt(e, n, o, await e.apiClient.addReply(n, a, o));
1465
+ Ut(e, n, l, await e.apiClient.addReply(n, o, l, ...i ? [i] : []));
1386
1466
  let t = e.getState().comments.find((e) => e.id === n);
1387
1467
  t && e.emit("comment:updated", t);
1388
1468
  } catch (r) {
1389
- t.shouldQueueMutation(r) && t.queueMutation("addReply", [n, a], o) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? {
1469
+ t.shouldQueueMutation(r) && t.queueMutation("addReply", i ? [
1470
+ n,
1471
+ o,
1472
+ i
1473
+ ] : [n, o], l) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? {
1390
1474
  ...e,
1391
- replies: e.replies.filter((e) => e.id !== o)
1475
+ replies: e.replies.filter((e) => e.id !== l)
1392
1476
  } : e) }), e.handleError(r));
1393
1477
  }
1394
1478
  }
1395
- async function Jt(e, t, n, r) {
1396
- if (!L(t) || !L(n) || !Ht(e, t, n)) return;
1397
- let i = R(r, gt);
1398
- if (!i) {
1399
- I(e, "invalid_reply", "Reply content is invalid");
1479
+ async function Zt(e, t, n, r, i) {
1480
+ if (!I(t) || !I(n) || !Wt(e, t, n)) return;
1481
+ let a = L(r, _t);
1482
+ if (!a) {
1483
+ F(e, "invalid_reply", "Reply content is invalid");
1400
1484
  return;
1401
1485
  }
1402
- let a = e.getState().comments, o = a.find((e) => e.id === t)?.replies.find((e) => e.id === n);
1403
- e.setState({ comments: a.map((e) => e.id === t ? {
1486
+ let o = e.getState().comments, s = o.find((e) => e.id === t)?.replies.find((e) => e.id === n);
1487
+ e.setState({ comments: o.map((e) => e.id === t ? {
1404
1488
  ...e,
1405
1489
  replies: e.replies.map((e) => e.id === n ? {
1406
1490
  ...e,
1407
- content: i,
1491
+ content: a,
1408
1492
  isEdited: !0
1409
1493
  } : e)
1410
1494
  } : e) });
1411
1495
  try {
1412
- let r = await e.apiClient.updateReply(t, n, i);
1496
+ let r = await e.apiClient.updateReply(t, n, a, ...i ? [i] : []);
1413
1497
  e.setState({ comments: e.getState().comments.map((e) => e.id === t ? {
1414
1498
  ...e,
1415
1499
  replies: e.replies.map((e) => e.id === n ? r : e)
1416
1500
  } : e) });
1417
- let a = e.getState().comments.find((e) => e.id === t);
1418
- a && e.emit("comment:updated", a);
1501
+ let o = e.getState().comments.find((e) => e.id === t);
1502
+ o && e.emit("comment:updated", o);
1419
1503
  } catch (r) {
1420
- e.setState({ comments: e.getState().comments.map((e) => e.id === t && o ? {
1504
+ e.setState({ comments: e.getState().comments.map((e) => e.id === t && s ? {
1421
1505
  ...e,
1422
- replies: e.replies.map((e) => e.id === n ? o : e)
1506
+ replies: e.replies.map((e) => e.id === n ? s : e)
1423
1507
  } : e) }), e.handleError(r);
1424
1508
  }
1425
1509
  }
1426
- async function Yt(e, t, n) {
1427
- if (!L(t) || !L(n) || !Ht(e, t, n)) return;
1510
+ async function Qt(e, t, n) {
1511
+ if (!I(t) || !I(n) || !Wt(e, t, n)) return;
1428
1512
  let r = e.getState().comments, i = r.find((e) => e.id === t)?.replies.find((e) => e.id === n);
1429
1513
  e.setState({ comments: r.map((e) => e.id === t ? {
1430
1514
  ...e,
@@ -1441,13 +1525,10 @@ async function Yt(e, t, n) {
1441
1525
  } : e) }), e.handleError(r);
1442
1526
  }
1443
1527
  }
1444
- async function Xt(e, t, n) {
1445
- if (!L(n) || !U(e, n)) return;
1528
+ async function $t(e, t, n) {
1529
+ if (!I(n) || !H(e, n)) return;
1446
1530
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1447
- e.setState({ comments: r.map((e) => e.id === n ? {
1448
- ...e,
1449
- status: "resolved"
1450
- } : e) });
1531
+ e.setState({ comments: r.map((e) => e.id === n ? W(e, "resolved") : e) });
1451
1532
  try {
1452
1533
  let r = await e.apiClient.resolveComment(n);
1453
1534
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? r : e) }), e.emit("comment:resolved", r), e.emit("comment:updated", r), t.addActivity({
@@ -1459,13 +1540,10 @@ async function Xt(e, t, n) {
1459
1540
  t.shouldQueueMutation(r) && t.queueMutation("resolveComment", [n]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n && i ? i : e) }), e.handleError(r));
1460
1541
  }
1461
1542
  }
1462
- async function Zt(e, t, n) {
1463
- if (!L(n) || !U(e, n)) return;
1543
+ async function en(e, t, n) {
1544
+ if (!I(n) || !H(e, n)) return;
1464
1545
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1465
- e.setState({ comments: r.map((e) => e.id === n ? {
1466
- ...e,
1467
- status: "open"
1468
- } : e) });
1546
+ e.setState({ comments: r.map((e) => e.id === n ? W(e, "open") : e) });
1469
1547
  try {
1470
1548
  let t = await e.apiClient.unresolveComment(n);
1471
1549
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? t : e) }), e.emit("comment:updated", t);
@@ -1473,13 +1551,10 @@ async function Zt(e, t, n) {
1473
1551
  t.shouldQueueMutation(r) && t.queueMutation("unresolveComment", [n]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n && i ? i : e) }), e.handleError(r));
1474
1552
  }
1475
1553
  }
1476
- async function Qt(e, t, n) {
1477
- if (!L(n) || !U(e, n)) return;
1554
+ async function tn(e, t, n) {
1555
+ if (!I(n) || !H(e, n)) return;
1478
1556
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1479
- e.setState({ comments: r.map((e) => e.id === n ? {
1480
- ...e,
1481
- status: "complete"
1482
- } : e) });
1557
+ e.setState({ comments: r.map((e) => e.id === n ? W(e, "complete") : e) });
1483
1558
  try {
1484
1559
  let r = await e.apiClient.markComplete(n);
1485
1560
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? r : e) }), e.emit("comment:completed", r), t.addActivity({
@@ -1491,64 +1566,79 @@ async function Qt(e, t, n) {
1491
1566
  t.shouldQueueMutation(r) && t.queueMutation("completeComment", [n]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n && i ? i : e) }), e.handleError(r));
1492
1567
  }
1493
1568
  }
1494
- async function $t(e, t, n, r) {
1495
- if (!L(n) || typeof r != "string") return;
1496
- let i = r.trim();
1497
- if (!i || i.length > Dt || a(i)) return;
1498
- let o = e.getState().comments.find((e) => e.id === n);
1499
- if (!o) return;
1500
- let s = (o.reactions ?? []).filter((e) => typeof e.emoji == "string" && e.emoji.length > 0 && e.emoji.length <= Dt && !a(e.emoji) && typeof e.count == "number" && Number.isInteger(e.count) && e.count >= 0 && e.count <= Et), c = s.find((e) => e.emoji === i)?.reacted, l = [...s];
1501
- if (c) {
1502
- let e = l.findIndex((e) => e.emoji === i), t = l[e];
1503
- t.count <= 1 ? l.splice(e, 1) : l[e] = {
1569
+ async function nn(e, t, n, r, i) {
1570
+ if (!I(n) || typeof r != "string") return;
1571
+ let o = r.trim();
1572
+ if (!o || o.length > Ot || a(o)) return;
1573
+ let s = e.getState().comments.find((e) => e.id === n);
1574
+ if (!s) return;
1575
+ let c = i ? s.replies.find((e) => e.id === i) : s;
1576
+ if (!c) return;
1577
+ let l = (c.reactions ?? []).filter((e) => typeof e.emoji == "string" && e.emoji.length > 0 && e.emoji.length <= Ot && !a(e.emoji) && typeof e.count == "number" && Number.isInteger(e.count) && e.count >= 0 && e.count <= Dt), u = l.find((e) => e.emoji === o)?.reacted, d = [...l];
1578
+ if (u) {
1579
+ let e = d.findIndex((e) => e.emoji === o), t = d[e];
1580
+ t.count <= 1 ? d.splice(e, 1) : d[e] = {
1504
1581
  ...t,
1505
1582
  count: t.count - 1,
1506
1583
  reacted: !1
1507
1584
  };
1508
1585
  } else {
1509
- let e = l.findIndex((e) => e.emoji === i), t = e === -1 ? void 0 : l[e];
1510
- t ? l[e] = {
1586
+ let e = d.findIndex((e) => e.emoji === o), t = e === -1 ? void 0 : d[e];
1587
+ t ? d[e] = {
1511
1588
  ...t,
1512
- count: Math.min(t.count + 1, Et),
1589
+ count: Math.min(t.count + 1, Dt),
1513
1590
  reacted: !0
1514
- } : l.push({
1515
- emoji: i,
1591
+ } : d.push({
1592
+ emoji: o,
1516
1593
  count: 1,
1517
1594
  reacted: !0
1518
1595
  });
1519
1596
  }
1520
- let u = e.getState().comments;
1521
- e.setState({ comments: u.map((e) => e.id === n ? {
1597
+ let f = e.getState().comments;
1598
+ e.setState({ comments: f.map((e) => e.id === n ? i ? {
1599
+ ...e,
1600
+ replies: e.replies.map((e) => e.id === i ? {
1601
+ ...e,
1602
+ reactions: d
1603
+ } : e)
1604
+ } : {
1522
1605
  ...e,
1523
- reactions: l
1606
+ reactions: d
1524
1607
  } : e) });
1525
1608
  try {
1526
- c ? await e.apiClient.removeReaction(n, i) : await e.apiClient.addReaction(n, i);
1609
+ u ? await e.apiClient.removeReaction(n, o, ...i ? [i] : []) : await e.apiClient.addReaction(n, o, ...i ? [i] : []);
1527
1610
  let t = e.getState().comments.find((e) => e.id === n);
1528
1611
  t && e.emit("comment:reaction", {
1529
1612
  commentId: n,
1530
- emoji: i,
1613
+ emoji: o,
1531
1614
  comment: t
1532
1615
  });
1533
1616
  } catch (r) {
1534
1617
  t.shouldQueueMutation(r) && t.queueMutation("reactToComment", [
1535
1618
  n,
1536
- i,
1537
- c ? "remove" : "add"
1538
- ]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? {
1619
+ o,
1620
+ u ? "remove" : "add",
1621
+ ...i ? [i] : []
1622
+ ]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? i ? {
1623
+ ...e,
1624
+ replies: e.replies.map((e) => e.id === i ? {
1625
+ ...e,
1626
+ reactions: l
1627
+ } : e)
1628
+ } : {
1539
1629
  ...e,
1540
- reactions: s
1630
+ reactions: l
1541
1631
  } : e) }), e.handleError(r));
1542
1632
  }
1543
1633
  }
1544
- async function en(e, t, n, r, i) {
1545
- if (!L(n) || !U(e, n)) return;
1546
- let a = Mt({
1634
+ async function rn(e, t, n, r, i) {
1635
+ if (!I(n) || !H(e, n)) return;
1636
+ let a = Nt({
1547
1637
  x: r,
1548
1638
  y: i
1549
1639
  });
1550
1640
  if (!a) {
1551
- I(e, "invalid_position", "Comment position is invalid");
1641
+ F(e, "invalid_position", "Comment position is invalid");
1552
1642
  return;
1553
1643
  }
1554
1644
  let o = e.getState().comments, s = o.find((e) => e.id === n);
@@ -1569,23 +1659,24 @@ async function en(e, t, n, r, i) {
1569
1659
  } : e) }), e.handleError(r));
1570
1660
  }
1571
1661
  }
1572
- function tn(e, t) {
1662
+ function an(e, t) {
1573
1663
  e.setState({ selectedComment: t });
1574
1664
  }
1575
- async function nn(e, t, n, r, i) {
1665
+ async function on(e, t, n, r, i) {
1576
1666
  let a = e.getState().currentUser;
1577
1667
  if (!a) return;
1578
- let o = R(i), s = It(r);
1668
+ let o = L(i), s = Lt(r);
1579
1669
  if (!o || s == null) {
1580
- I(e, "invalid_highlight", "Highlight data is invalid");
1670
+ F(e, "invalid_highlight", "Highlight data is invalid");
1581
1671
  return;
1582
1672
  }
1583
1673
  let c = `highlight:${s.xpath}:${s.startOffset}:${o.slice(0, 50)}`;
1584
1674
  if (n.has(c)) return;
1585
1675
  n.add(c);
1586
- let l = u(), d = H("temp"), f = {
1587
- id: d,
1676
+ let l = u(), d = e.getState().activeBranch ?? void 0, f = d ? { branch: d } : void 0, p = V("temp"), m = {
1677
+ id: p,
1588
1678
  type: "highlight",
1679
+ ...d ? { branch: d } : {},
1589
1680
  content: o,
1590
1681
  position: {
1591
1682
  x: 0,
@@ -1606,10 +1697,10 @@ async function nn(e, t, n, r, i) {
1606
1697
  attachments: [],
1607
1698
  textSelection: s
1608
1699
  };
1609
- e.setState({ comments: [...e.getState().comments, f] });
1700
+ e.setState({ comments: [...e.getState().comments, m] });
1610
1701
  try {
1611
- let t = await e.apiClient.createHighlight(o, s, l, "medium", d);
1612
- W(e, d, t), e.emit("comment:created", t);
1702
+ let t = await e.apiClient.createHighlight(o, s, l, "medium", p, ...f ? [f] : []);
1703
+ U(e, p, t), e.emit("comment:created", t);
1613
1704
  } catch (n) {
1614
1705
  t.shouldQueueMutation(n) && t.queueMutation("createHighlight", [
1615
1706
  o,
@@ -1618,26 +1709,28 @@ async function nn(e, t, n, r, i) {
1618
1709
  url: l.url,
1619
1710
  path: l.path,
1620
1711
  title: l.title
1621
- }
1622
- ], d) || (e.setState({ comments: e.getState().comments.filter((e) => e.id !== d) }), e.handleError(n));
1712
+ },
1713
+ ...f ? [f] : []
1714
+ ], p) || (e.setState({ comments: e.getState().comments.filter((e) => e.id !== p) }), e.handleError(n));
1623
1715
  } finally {
1624
1716
  n.delete(c);
1625
1717
  }
1626
1718
  }
1627
- async function rn(e, t, n, r, i, a) {
1719
+ async function sn(e, t, n, r, i, a) {
1628
1720
  let o = e.getState().currentUser;
1629
1721
  if (!o) return;
1630
- let s = R(a), c = Mt(i), l = Rt(r);
1722
+ let s = L(a), c = Nt(i), l = zt(r);
1631
1723
  if (!s || !c || l == null) {
1632
- I(e, "invalid_drawing", "Drawing comment data is invalid");
1724
+ F(e, "invalid_drawing", "Drawing comment data is invalid");
1633
1725
  return;
1634
1726
  }
1635
1727
  let d = `drawing:${c.x}:${c.y}:${s.slice(0, 50)}`;
1636
1728
  if (n.has(d)) return;
1637
1729
  n.add(d);
1638
- let f = u(), p = H("temp"), m = {
1639
- id: p,
1730
+ let f = u(), p = e.getState().activeBranch ?? void 0, m = p ? { branch: p } : void 0, h = V("temp"), g = {
1731
+ id: h,
1640
1732
  type: "drawing",
1733
+ ...p ? { branch: p } : {},
1641
1734
  content: s,
1642
1735
  position: c,
1643
1736
  status: "open",
@@ -1655,10 +1748,10 @@ async function rn(e, t, n, r, i, a) {
1655
1748
  attachments: [],
1656
1749
  drawingData: l
1657
1750
  };
1658
- e.setState({ comments: [...e.getState().comments, m] });
1751
+ e.setState({ comments: [...e.getState().comments, g] });
1659
1752
  try {
1660
- let t = await e.apiClient.createDrawing(s, l, c, f, p);
1661
- W(e, p, t), e.emit("comment:created", t);
1753
+ let t = await e.apiClient.createDrawing(s, l, c, f, h, ...m ? [m] : []);
1754
+ U(e, h, t), e.emit("comment:created", t);
1662
1755
  } catch (n) {
1663
1756
  t.shouldQueueMutation(n) && t.queueMutation("createDrawing", [
1664
1757
  s,
@@ -1668,52 +1761,53 @@ async function rn(e, t, n, r, i, a) {
1668
1761
  url: f.url,
1669
1762
  path: f.path,
1670
1763
  title: f.title
1671
- }
1672
- ], p) || (e.setState({ comments: e.getState().comments.filter((e) => e.id !== p) }), e.handleError(n));
1764
+ },
1765
+ ...m ? [m] : []
1766
+ ], h) || (e.setState({ comments: e.getState().comments.filter((e) => e.id !== h) }), e.handleError(n));
1673
1767
  } finally {
1674
1768
  n.delete(d);
1675
1769
  }
1676
1770
  }
1677
- var an = {
1771
+ var cn = {
1678
1772
  c: "comment",
1679
1773
  e: "select",
1680
1774
  d: "draw",
1681
1775
  h: "highlight",
1682
1776
  s: "screenshot"
1683
1777
  };
1684
- function on(e) {
1778
+ function ln(e) {
1685
1779
  return typeof e.composedPath == "function" ? e.composedPath() : e.target ? [e.target] : [];
1686
1780
  }
1687
- function sn(e) {
1781
+ function un(e) {
1688
1782
  return typeof Element < "u" && e instanceof Element;
1689
1783
  }
1690
- function cn(e) {
1691
- if (!sn(e)) return !1;
1784
+ function dn(e) {
1785
+ if (!un(e)) return !1;
1692
1786
  let t = e.tagName.toLowerCase();
1693
1787
  return t === "input" || t === "textarea" || t === "select" || e.isContentEditable || e.getAttribute("role") === "textbox";
1694
1788
  }
1695
- function ln(e) {
1789
+ function fn(e) {
1696
1790
  let t = e.activeElement;
1697
1791
  for (; t?.shadowRoot?.activeElement;) t = t.shadowRoot.activeElement;
1698
1792
  return t;
1699
1793
  }
1700
- function un(e) {
1701
- return on(e).some(cn) ? !0 : typeof document > "u" ? !1 : cn(ln(document));
1794
+ function pn(e) {
1795
+ return ln(e).some(dn) ? !0 : typeof document > "u" ? !1 : dn(fn(document));
1702
1796
  }
1703
- function dn(e) {
1704
- return on(e).some((e) => sn(e) && (e.hasAttribute("data-commentkit") || e.hasAttribute("data-commentkit-ui") || e.hasAttribute("data-commentkit-host")));
1797
+ function mn(e) {
1798
+ return ln(e).some((e) => un(e) && (e.hasAttribute("data-commentkit") || e.hasAttribute("data-commentkit-ui") || e.hasAttribute("data-commentkit-host")));
1705
1799
  }
1706
- function fn(e) {
1800
+ function hn(e) {
1707
1801
  return (e.ctrlKey || e.metaKey) && e.shiftKey && (e.key === "K" || e.key === "k" || e.code === "KeyK");
1708
1802
  }
1709
- function pn(e) {
1803
+ function gn(e) {
1710
1804
  let t = e.key.toLowerCase(), n = e.code.startsWith("Key") ? e.code.slice(3).toLowerCase() : "";
1711
- return an[t] ?? an[n] ?? null;
1805
+ return cn[t] ?? cn[n] ?? null;
1712
1806
  }
1713
- function K(e) {
1807
+ function G(e) {
1714
1808
  e.preventDefault(), e.stopPropagation();
1715
1809
  }
1716
- function mn(e, t) {
1810
+ function _n(e, t) {
1717
1811
  if (e.isLoginModalVisible) t.toggleLoginModal();
1718
1812
  else if (e.isShortcutsOverlayVisible) t.toggleShortcutsOverlay();
1719
1813
  else if (e.activeComment) t.setState({ activeComment: null });
@@ -1724,40 +1818,41 @@ function mn(e, t) {
1724
1818
  else return !1;
1725
1819
  return !0;
1726
1820
  }
1727
- function hn(e, t) {
1821
+ function vn(e, t) {
1728
1822
  e.isAuthenticated ? t.toggleOverlay() : t.toggleLoginModal();
1729
1823
  }
1730
- function gn(e, t, n) {
1824
+ function yn(e, t, n) {
1731
1825
  if (e.defaultPrevented || e.repeat || e.isComposing) return;
1732
- let r = un(e), i = dn(e);
1733
- if (fn(e)) {
1826
+ let r = pn(e), i = mn(e);
1827
+ if (hn(e)) {
1734
1828
  if (r) return;
1735
- K(e), hn(t, n);
1829
+ G(e), vn(t, n);
1736
1830
  } else if (e.key === "Escape") {
1737
1831
  if (r && !i) return;
1738
- mn(t, n) && K(e);
1832
+ _n(t, n) && G(e);
1739
1833
  } else if (t.isAuthenticated && (t.isOverlayVisible || t.activeTool !== null) && !r && !e.ctrlKey && !e.metaKey && !e.altKey) {
1740
1834
  if (e.key === "?") {
1741
- K(e), n.toggleShortcutsOverlay();
1835
+ G(e), n.toggleShortcutsOverlay();
1742
1836
  return;
1743
1837
  }
1744
- let r = pn(e);
1745
- r && (K(e), n.setTool(t.activeTool === r ? null : r));
1838
+ let r = gn(e);
1839
+ r && (G(e), n.setTool(t.activeTool === r ? null : r));
1746
1840
  }
1747
1841
  }
1748
- function q(e) {
1842
+ function K(e) {
1749
1843
  return Object.freeze(e);
1750
1844
  }
1751
- var _n = Object.freeze({
1752
- auth: q([
1845
+ var bn = Object.freeze({
1846
+ auth: K([
1753
1847
  "isAuthenticated",
1754
1848
  "currentUser",
1755
1849
  "project",
1850
+ "projectContext",
1756
1851
  "isLoginModalVisible",
1757
1852
  "otpStep",
1758
1853
  "otpEmail"
1759
1854
  ]),
1760
- ui: q([
1855
+ ui: K([
1761
1856
  "isOverlayVisible",
1762
1857
  "isSidebarVisible",
1763
1858
  "isShortcutsOverlayVisible",
@@ -1775,23 +1870,24 @@ var _n = Object.freeze({
1775
1870
  "isLoading",
1776
1871
  "error"
1777
1872
  ]),
1778
- comments: q([
1873
+ comments: K([
1779
1874
  "comments",
1780
1875
  "pagination",
1781
- "seenThreadIds"
1876
+ "seenThreadIds",
1877
+ "activeBranch"
1782
1878
  ]),
1783
- realtime: q([
1879
+ realtime: K([
1784
1880
  "onlineUsers",
1785
1881
  "connectionStatus",
1786
1882
  "pendingMutations",
1787
1883
  "isOnline"
1788
1884
  ])
1789
1885
  });
1790
- function vn() {
1886
+ function xn() {
1791
1887
  return typeof navigator < "u" && typeof navigator.onLine == "boolean" ? navigator.onLine : !0;
1792
1888
  }
1793
- var yn = 2e3;
1794
- function bn() {
1889
+ var Sn = 2e3;
1890
+ function Cn() {
1795
1891
  return {
1796
1892
  isAuthenticated: !1,
1797
1893
  isOverlayVisible: !0,
@@ -1804,6 +1900,8 @@ function bn() {
1804
1900
  isShortcutsOverlayVisible: !1,
1805
1901
  currentUser: null,
1806
1902
  project: null,
1903
+ projectContext: null,
1904
+ activeBranch: null,
1807
1905
  comments: [],
1808
1906
  activeTool: null,
1809
1907
  selectedComment: null,
@@ -1821,10 +1919,10 @@ function bn() {
1821
1919
  otpEmail: null,
1822
1920
  pagination: null,
1823
1921
  pendingMutations: [],
1824
- isOnline: vn()
1922
+ isOnline: xn()
1825
1923
  };
1826
1924
  }
1827
- var xn = M.PENDING_MUTATIONS, Sn = M.RETRY_DELAY, J = M.ID, Cn = M.CONTENT, wn = M.REPLY_CONTENT, Tn = M.SELECTOR, En = M.EMOJI, Dn = /* @__PURE__ */ new Set([
1925
+ var wn = j.PENDING_MUTATIONS, Tn = j.RETRY_DELAY, q = j.ID, En = j.CONTENT, Dn = j.REPLY_CONTENT, On = j.SELECTOR, kn = j.EMOJI, An = /* @__PURE__ */ new Set([
1828
1926
  "createComment",
1829
1927
  "createHighlight",
1830
1928
  "createDrawing",
@@ -1836,42 +1934,42 @@ var xn = M.PENDING_MUTATIONS, Sn = M.RETRY_DELAY, J = M.ID, Cn = M.CONTENT, wn =
1836
1934
  "addReply",
1837
1935
  "reactToComment",
1838
1936
  "updatePosition"
1839
- ]), On = /* @__PURE__ */ new Set([
1937
+ ]), jn = /* @__PURE__ */ new Set([
1840
1938
  "pin",
1841
1939
  "highlight",
1842
1940
  "drawing"
1843
- ]), kn = /* @__PURE__ */ new Set([
1941
+ ]), Mn = /* @__PURE__ */ new Set([
1844
1942
  "low",
1845
1943
  "medium",
1846
1944
  "high",
1847
1945
  "urgent"
1848
- ]), An = /* @__PURE__ */ new Set(["add", "remove"]);
1849
- function jn(n) {
1850
- return i(n) && e(n.x) && e(n.y) && t(n.element, Tn) && t(n.xpath, Tn);
1851
- }
1852
- function Mn(e) {
1853
- return typeof e == "string" && e.length <= M.PAGE && !r(e);
1854
- }
1855
- function Nn(e) {
1856
- return e === void 0 || i(e) && Mn(e.url) && Mn(e.path) && Mn(e.title);
1857
- }
1858
- function Pn(e) {
1859
- return typeof e == "string" && Dn.has(e);
1946
+ ]), Nn = /* @__PURE__ */ new Set(["add", "remove"]);
1947
+ function Pn(n) {
1948
+ return i(n) && e(n.x) && e(n.y) && t(n.element, On) && t(n.xpath, On);
1860
1949
  }
1861
1950
  function Fn(e) {
1862
- return Number.isInteger(e) && Number(e) >= 0;
1951
+ return typeof e == "string" && e.length <= j.PAGE && !r(e);
1863
1952
  }
1864
1953
  function In(e) {
1865
- return Fn(e) ? Math.min(e, 5) : 0;
1954
+ return e === void 0 || i(e) && Fn(e.url) && Fn(e.path) && Fn(e.title);
1866
1955
  }
1867
1956
  function Ln(e) {
1868
- return e.isNetworkError() || e.code === 408 || e.isRateLimitError();
1957
+ return typeof e == "string" && An.has(e);
1869
1958
  }
1870
1959
  function Rn(e) {
1871
- return e instanceof D ? Ln(e) : !0;
1960
+ return Number.isInteger(e) && Number(e) >= 0;
1872
1961
  }
1873
1962
  function zn(e) {
1874
- return e instanceof D ? {
1963
+ return Rn(e) ? Math.min(e, 5) : 0;
1964
+ }
1965
+ function Bn(e) {
1966
+ return e.isNetworkError() || e.code === 408 || e.isRateLimitError();
1967
+ }
1968
+ function Vn(e) {
1969
+ return e instanceof E ? Bn(e) : !0;
1970
+ }
1971
+ function Hn(e) {
1972
+ return e instanceof E ? {
1875
1973
  error: e.error,
1876
1974
  message: e.message,
1877
1975
  code: e.code,
@@ -1882,93 +1980,93 @@ function zn(e) {
1882
1980
  code: 0
1883
1981
  };
1884
1982
  }
1885
- function Bn(e = Date.now()) {
1983
+ function Un(e = Date.now()) {
1886
1984
  return `mutation_${e}_${typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : Math.random().toString(36).slice(2, 12)}`;
1887
1985
  }
1888
- function Vn(e) {
1889
- return Array.isArray(e) ? e.map((e) => Vn(e)) : i(e) ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Vn(t)])) : e;
1986
+ function Wn(e) {
1987
+ return Array.isArray(e) ? e.map((e) => Wn(e)) : i(e) ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Wn(t)])) : e;
1890
1988
  }
1891
- function Hn(e) {
1989
+ function Gn(e) {
1892
1990
  try {
1893
1991
  if (typeof structuredClone == "function") return structuredClone(e);
1894
1992
  } catch {}
1895
- return Vn(e);
1993
+ return Wn(e);
1896
1994
  }
1897
- function Un(e, t) {
1995
+ function Kn(e, t) {
1898
1996
  switch (e) {
1899
1997
  case "createComment": {
1900
1998
  let [e, n, r, a, s, c, l, u] = t;
1901
- return t.length >= 3 && t.length <= 8 && On.has(String(e)) && o(n, Cn) && jn(r) && (a === void 0 || kn.has(String(a))) && (s === void 0 || i(s)) && (c === void 0 || i(c)) && (l === void 0 || i(l)) && Nn(u);
1999
+ return t.length >= 3 && t.length <= 8 && jn.has(String(e)) && o(n, En) && Pn(r) && (a === void 0 || Mn.has(String(a))) && (s === void 0 || i(s)) && (c === void 0 || i(c)) && (l === void 0 || i(l)) && In(u);
1902
2000
  }
1903
2001
  case "createHighlight": {
1904
- let [e, n, r] = t;
1905
- return t.length >= 2 && t.length <= 3 && o(e, Cn) && i(n) && Nn(r);
2002
+ let [e, n, r, a] = t;
2003
+ return t.length >= 2 && t.length <= 4 && o(e, En) && i(n) && (a === void 0 || i(a)) && In(r);
1906
2004
  }
1907
2005
  case "createDrawing": {
1908
- let [e, n, r, a] = t;
1909
- return t.length >= 3 && t.length <= 4 && o(e, Cn) && i(n) && jn(r) && Nn(a);
2006
+ let [e, n, r, a, s] = t;
2007
+ return t.length >= 3 && t.length <= 5 && o(e, En) && i(n) && Pn(r) && (s === void 0 || i(s)) && In(a);
1910
2008
  }
1911
- case "updateComment": return t.length === 2 && n(t[0], J) && i(t[1]);
2009
+ case "updateComment": return t.length === 2 && n(t[0], q) && i(t[1]);
1912
2010
  case "deleteComment":
1913
2011
  case "resolveComment":
1914
2012
  case "unresolveComment":
1915
- case "completeComment": return t.length === 1 && n(t[0], J);
1916
- case "addReply": return t.length === 2 && n(t[0], J) && o(t[1], wn);
1917
- case "reactToComment": return t.length >= 2 && t.length <= 3 && n(t[0], J) && n(t[1], En) && (t[2] === void 0 || An.has(String(t[2])));
1918
- case "updatePosition": return t.length === 2 && n(t[0], J) && jn(t[1]);
2013
+ case "completeComment": return t.length === 1 && n(t[0], q);
2014
+ case "addReply": return (t.length === 2 || t.length === 3) && n(t[0], q) && o(t[1], Dn) && (t[2] === void 0 || i(t[2]));
2015
+ case "reactToComment": return t.length >= 2 && t.length <= 4 && n(t[0], q) && n(t[1], kn) && (t[2] === void 0 || Nn.has(String(t[2]))) && (t[3] === void 0 || n(t[3], q));
2016
+ case "updatePosition": return t.length === 2 && n(t[0], q) && Pn(t[1]);
1919
2017
  }
1920
2018
  }
1921
- function Wn(e) {
1922
- return i(e) ? n(e.id, J) ? Pn(e.type) ? Array.isArray(e.args) ? Number.isFinite(e.timestamp) ? Fn(e.retries) ? t(e.tempId, J) ? Un(e.type, e.args) ? null : "Queued mutation args are invalid" : "Queued mutation has an invalid temp id" : "Queued mutation has an invalid retry count" : "Queued mutation has an invalid timestamp" : "Queued mutation args must be an array" : "Queued mutation has an unsupported type" : "Queued mutation has an invalid id" : "Queued mutation must be an object";
2019
+ function qn(e) {
2020
+ return i(e) ? n(e.id, q) ? e.ownerId !== void 0 && !n(e.ownerId, q) ? "Queued mutation has an invalid owner id" : Ln(e.type) ? Array.isArray(e.args) ? Number.isFinite(e.timestamp) ? Rn(e.retries) ? t(e.tempId, q) ? Kn(e.type, e.args) ? null : "Queued mutation args are invalid" : "Queued mutation has an invalid temp id" : "Queued mutation has an invalid retry count" : "Queued mutation has an invalid timestamp" : "Queued mutation args must be an array" : "Queued mutation has an unsupported type" : "Queued mutation has an invalid id" : "Queued mutation must be an object";
1923
2021
  }
1924
- function Gn(e) {
1925
- let t = Wn(e);
1926
- if (t) throw new D("invalid_mutation", t, 400);
2022
+ function Jn(e) {
2023
+ let t = qn(e);
2024
+ if (t) throw new E("invalid_mutation", t, 400);
1927
2025
  }
1928
- var Kn = "commentkit:offline-queue:";
1929
- function qn() {
2026
+ var Yn = "commentkit:offline-queue:";
2027
+ function Xn() {
1930
2028
  try {
1931
2029
  return typeof localStorage > "u" ? null : localStorage;
1932
2030
  } catch {
1933
2031
  return null;
1934
2032
  }
1935
2033
  }
1936
- function Jn(e) {
1937
- return `${Kn}${e}`;
2034
+ function Zn(e) {
2035
+ return `${Yn}${e}`;
1938
2036
  }
1939
- function Yn(e, t) {
2037
+ function Qn(e, t) {
1940
2038
  if (!e) return;
1941
- let n = qn();
2039
+ let n = Xn();
1942
2040
  if (n) try {
1943
- t.length === 0 ? n.removeItem(Jn(e)) : n.setItem(Jn(e), JSON.stringify(t));
2041
+ t.length === 0 ? n.removeItem(Zn(e)) : n.setItem(Zn(e), JSON.stringify(t));
1944
2042
  } catch {}
1945
2043
  }
1946
- function Xn(e) {
2044
+ function $n(e) {
1947
2045
  if (!e) return [];
1948
- let t = qn();
2046
+ let t = Xn();
1949
2047
  if (!t) return [];
1950
2048
  try {
1951
- let n = t.getItem(Jn(e));
2049
+ let n = t.getItem(Zn(e));
1952
2050
  if (!n) return [];
1953
2051
  let r = JSON.parse(n);
1954
2052
  if (!Array.isArray(r)) return [];
1955
2053
  let i = [];
1956
2054
  for (let e of r) {
1957
- if (i.length >= xn) break;
1958
- Wn(e) === null && i.push(e);
2055
+ if (i.length >= wn) break;
2056
+ qn(e) === null && i.push(e);
1959
2057
  }
1960
2058
  return i;
1961
2059
  } catch {
1962
2060
  return [];
1963
2061
  }
1964
2062
  }
1965
- function Y(e) {
2063
+ function J(e) {
1966
2064
  Promise.resolve().then(e);
1967
2065
  }
1968
- function Zn(e, t) {
1969
- return e.type === t.type && (t.type === "updatePosition" || t.type === "updateComment") && e.args[0] === t.args[0];
2066
+ function er(e, t) {
2067
+ return e.type !== t.type || e.ownerId !== t.ownerId ? !1 : (t.type === "updatePosition" || t.type === "updateComment") && e.args[0] === t.args[0];
1970
2068
  }
1971
- function Qn(e, t) {
2069
+ function tr(e, t) {
1972
2070
  return t.type === "updateComment" && i(e.args[1]) ? {
1973
2071
  ...t,
1974
2072
  args: [t.args[0], {
@@ -1977,54 +2075,82 @@ function Qn(e, t) {
1977
2075
  }]
1978
2076
  } : t;
1979
2077
  }
1980
- function $n(e, t) {
1981
- let n = e.findIndex((e) => Zn(e, t));
2078
+ function nr(e, t) {
2079
+ let n = e.findIndex((e) => er(e, t));
1982
2080
  if (n !== -1) {
1983
2081
  let r = [...e];
1984
- return r[n] = Qn(r[n], t), r;
2082
+ return r[n] = tr(r[n], t), r;
1985
2083
  }
1986
- return e.length >= xn ? null : [...e, t];
2084
+ return e.length >= wn ? null : [...e, t];
1987
2085
  }
1988
- function X(e, t, n) {
2086
+ function Y(e, t, n) {
1989
2087
  e.emit("offline:failed", {
1990
2088
  id: t,
1991
2089
  error: n
1992
2090
  });
1993
2091
  }
1994
- function er(e, t) {
1995
- return !e.isOnline || t instanceof D && Ln(t);
2092
+ function rr(e, t) {
2093
+ return t.isAuthenticated && e.ownerId && e.ownerId === t.currentUser?.id ? null : {
2094
+ error: "offline_identity_mismatch",
2095
+ message: e.ownerId ? "Offline change belongs to a different signed-in user and was discarded." : "Offline change has no verified author and was discarded. Please submit it again.",
2096
+ code: 403
2097
+ };
1996
2098
  }
1997
- function tr(e, n, r, i, a) {
1998
- let o = Bn();
1999
- if (!Pn(r) || !Array.isArray(i) || !Un(r, i) || !t(a, J)) return X(e, o, {
2099
+ function ir(e) {
2100
+ let t = e.getState();
2101
+ if (!t.isAuthenticated) return;
2102
+ let n = t.pendingMutations.flatMap((e) => {
2103
+ let n = rr(e, t);
2104
+ return n ? [{
2105
+ mutation: e,
2106
+ error: n
2107
+ }] : [];
2108
+ });
2109
+ if (n.length === 0) return;
2110
+ let r = new Set(n.map(({ mutation: e }) => e.id));
2111
+ e.setState({ pendingMutations: t.pendingMutations.filter((e) => !r.has(e.id)) });
2112
+ for (let { mutation: t, error: r } of n) Y(e, t.id, r);
2113
+ }
2114
+ function ar(e, t) {
2115
+ return !e.isOnline || t instanceof E && Bn(t);
2116
+ }
2117
+ function or(e, r, i, a, o) {
2118
+ let s = Un(), c = e.getState(), l = c.currentUser?.id;
2119
+ if (!c.isAuthenticated || !n(l, q)) return Y(e, s, {
2120
+ error: "unauthenticated",
2121
+ message: "Sign in before saving changes for offline replay.",
2122
+ code: 401
2123
+ }), !1;
2124
+ if (!Ln(i) || !Array.isArray(a) || !Kn(i, a) || !t(o, q)) return Y(e, s, {
2000
2125
  error: "invalid_mutation",
2001
2126
  message: "Queued mutation args are invalid",
2002
2127
  code: 400
2003
2128
  }), !1;
2004
- let s = {
2005
- id: o,
2006
- type: r,
2007
- args: Hn(i),
2129
+ let u = {
2130
+ id: s,
2131
+ ownerId: l,
2132
+ type: i,
2133
+ args: Gn(a),
2008
2134
  timestamp: Date.now(),
2009
2135
  retries: 0,
2010
- ...a === void 0 ? {} : { tempId: a }
2011
- }, c = $n(e.getState().pendingMutations, s);
2012
- return c ? (e.setState({ pendingMutations: c }), e.emit("offline:queued", s), e.getState().isOnline && Y(n), !0) : (X(e, o, {
2136
+ ...o === void 0 ? {} : { tempId: o }
2137
+ }, d = nr(e.getState().pendingMutations, u);
2138
+ return d ? (e.setState({ pendingMutations: d }), e.emit("offline:queued", u), e.getState().isOnline && J(r), !0) : (Y(e, s, {
2013
2139
  error: "queue_full",
2014
2140
  message: "Offline mutation queue is full",
2015
2141
  code: 0
2016
2142
  }), !1);
2017
2143
  }
2018
- function nr(e, t, n) {
2144
+ function sr(e, t, n) {
2019
2145
  if (t.current || e.getState().pendingMutations.length === 0) return;
2020
2146
  let r = e.getState().pendingMutations[0];
2021
2147
  if (!r) return;
2022
- let i = In(r.retries), a = Math.min(Sn, yn * 2 ** i);
2148
+ let i = zn(r.retries), a = Math.min(Tn, Sn * 2 ** i);
2023
2149
  t.current = setTimeout(() => {
2024
2150
  t.current = null, n();
2025
2151
  }, a);
2026
2152
  }
2027
- async function rr(e, t, r, i) {
2153
+ async function cr(e, t, r, i) {
2028
2154
  let a = e.getState();
2029
2155
  if (!a.isOnline || a.pendingMutations.length === 0 || !a.isAuthenticated || t.current) return;
2030
2156
  t.current = !0;
@@ -2033,108 +2159,182 @@ async function rr(e, t, r, i) {
2033
2159
  t.current = !1;
2034
2160
  return;
2035
2161
  }
2036
- let s = Wn(o);
2037
- if (s) {
2162
+ let s = qn(o), c = s ? {
2163
+ error: "invalid_mutation",
2164
+ message: s,
2165
+ code: 400
2166
+ } : rr(o, e.getState());
2167
+ if (c) {
2038
2168
  let i = e.getState().pendingMutations.filter((e) => e !== o);
2039
- e.setState({ pendingMutations: i }), X(e, n(o.id, J) ? o.id : "invalid", {
2040
- error: "invalid_mutation",
2041
- message: s,
2042
- code: 400
2043
- }), i.length > 0 && Y(r), t.current = !1;
2169
+ e.setState({ pendingMutations: i }), Y(e, n(o.id, q) ? o.id : "invalid", c), i.length > 0 && J(r), t.current = !1;
2044
2170
  return;
2045
2171
  }
2046
2172
  e.emit("offline:retrying", {
2047
2173
  id: o.id,
2048
2174
  attempt: o.retries + 1
2049
2175
  });
2050
- let c = i ?? ((t) => ar(e, t));
2176
+ let l = i ?? ((t) => fr(e, t));
2051
2177
  try {
2052
- await c(o);
2178
+ await l(o);
2053
2179
  let n = e.getState().pendingMutations.filter((e) => e.id !== o.id);
2054
- e.setState({ pendingMutations: n }), e.emit("offline:completed", { id: o.id }), n.length > 0 ? Y(r) : t.reconcileAfterDrain && (t.reconcileAfterDrain = !1, G(e));
2180
+ e.setState({ pendingMutations: n }), e.emit("offline:completed", { id: o.id }), n.length > 0 ? J(r) : t.reconcileAfterDrain && (t.reconcileAfterDrain = !1, Gt(e));
2055
2181
  } catch (n) {
2056
2182
  let i = {
2057
2183
  ...o,
2058
- retries: In(o.retries) + 1
2184
+ retries: zn(o.retries) + 1
2059
2185
  };
2060
- if (Rn(n) && i.retries < 5) {
2186
+ if (Vn(n) && i.retries < 5) {
2061
2187
  let t = e.getState().pendingMutations.map((e) => e.id === o.id ? i : e);
2062
- e.setState({ pendingMutations: t }), Y(r);
2188
+ e.setState({ pendingMutations: t }), J(r);
2063
2189
  } else {
2064
2190
  let i = e.getState().pendingMutations.filter((e) => e.id !== o.id);
2065
- e.setState({ pendingMutations: i }), X(e, o.id, zn(n)), i.length > 0 ? (t.reconcileAfterDrain = !0, Y(r)) : (t.reconcileAfterDrain = !1, G(e));
2191
+ e.setState({ pendingMutations: i }), Y(e, o.id, Hn(n)), i.length > 0 ? (t.reconcileAfterDrain = !0, J(r)) : (t.reconcileAfterDrain = !1, Gt(e));
2066
2192
  }
2067
2193
  } finally {
2068
2194
  t.current = !1;
2069
2195
  }
2070
2196
  }
2071
- function ir(e, t, n) {
2072
- let r = !1, i = e.getState().pendingMutations.map((e) => e.type !== "createComment" && e.args[0] === t ? (r = !0, {
2197
+ function lr(e, t, n) {
2198
+ let r = !1, i = e.getState().pendingMutations.map((e) => e.type !== "createComment" && e.type !== "createHighlight" && e.type !== "createDrawing" && e.args[0] === t ? (r = !0, {
2073
2199
  ...e,
2074
2200
  args: [n, ...e.args.slice(1)]
2075
2201
  }) : e);
2076
2202
  r && e.setState({ pendingMutations: i });
2077
2203
  }
2078
- async function ar(e, t) {
2079
- switch (Gn(t), t.type) {
2204
+ function ur(e, t, n) {
2205
+ let r = e.getState(), i = (e) => e === t || e === n;
2206
+ e.setState({
2207
+ comments: r.comments.filter((e) => !i(e.id)),
2208
+ selectedComment: r.selectedComment && i(r.selectedComment.id) ? null : r.selectedComment,
2209
+ activeComment: r.activeComment && i(r.activeComment.id) ? null : r.activeComment
2210
+ });
2211
+ }
2212
+ function X(e, t, n, r, i = !1) {
2213
+ let a = e.getState(), o = a.comments.find((e) => e.id === r || e.id === n.id), s = n, c = (e) => {
2214
+ s.status !== e && (s = {
2215
+ ...s,
2216
+ status: e,
2217
+ completedAt: void 0,
2218
+ ...e === "complete" ? {} : { resolvedAt: void 0 }
2219
+ });
2220
+ };
2221
+ for (let i of a.pendingMutations) if (!(i.id === t.id || i.ownerId !== t.ownerId || i.args[0] !== r && i.args[0] !== n.id)) switch (i.type) {
2222
+ case "deleteComment":
2223
+ ur(e, n.id, r);
2224
+ return;
2225
+ case "updateComment":
2226
+ i.args[1].status && c(i.args[1].status), s = {
2227
+ ...s,
2228
+ ...i.args[1]
2229
+ };
2230
+ break;
2231
+ case "resolveComment":
2232
+ c("resolved");
2233
+ break;
2234
+ case "unresolveComment":
2235
+ c("open");
2236
+ break;
2237
+ case "completeComment":
2238
+ c("complete");
2239
+ break;
2240
+ case "updatePosition":
2241
+ s = {
2242
+ ...s,
2243
+ position: i.args[1]
2244
+ };
2245
+ break;
2246
+ case "addReply": {
2247
+ let e = o?.replies.find((e) => e.id === i.tempId);
2248
+ e && !s.replies.some((t) => t.id === e.id) && (s = {
2249
+ ...s,
2250
+ replies: [...s.replies, e]
2251
+ }), c("open");
2252
+ break;
2253
+ }
2254
+ case "reactToComment": !i.args[3] && o && (s = {
2255
+ ...s,
2256
+ reactions: o.reactions
2257
+ });
2258
+ }
2259
+ i ? U(e, r, s) : e.setState({ comments: a.comments.map((e) => e.id === r ? s : e) });
2260
+ }
2261
+ function dr(e, t, n, r) {
2262
+ e.setState({ pendingMutations: e.getState().pendingMutations.map((e) => e.type === "reactToComment" && e.args[0] === t && e.args[3] === n ? {
2263
+ ...e,
2264
+ args: [...e.args.slice(0, 3), r]
2265
+ } : e) });
2266
+ }
2267
+ async function fr(e, t) {
2268
+ Jn(t);
2269
+ let n = rr(t, e.getState());
2270
+ if (n) throw new E(n.error, n.message, n.code);
2271
+ switch (t.type) {
2080
2272
  case "createComment": {
2081
2273
  let [n, r, i, a, o, s, c, l] = t.args, d = await e.apiClient.createComment(n, r, i, l ?? u(), a, o, s, c, t.tempId);
2082
- d && t.tempId && (W(e, t.tempId, d), ir(e, t.tempId, d.id));
2274
+ d && t.tempId && (X(e, t, d, t.tempId, !0), lr(e, t.tempId, d.id));
2083
2275
  break;
2084
2276
  }
2085
2277
  case "createHighlight": {
2086
- let [n, r, i] = t.args, a = await e.apiClient.createHighlight(n, r, i ?? u(), "medium", t.tempId);
2087
- a && t.tempId && (W(e, t.tempId, a), ir(e, t.tempId, a.id));
2278
+ let [n, r, i, a] = t.args, o = await e.apiClient.createHighlight(n, r, i ?? u(), "medium", t.tempId, ...a ? [a] : []);
2279
+ o && t.tempId && (X(e, t, o, t.tempId, !0), lr(e, t.tempId, o.id));
2088
2280
  break;
2089
2281
  }
2090
2282
  case "createDrawing": {
2091
- let [n, r, i, a] = t.args, o = await e.apiClient.createDrawing(n, r, i, a ?? u(), t.tempId);
2092
- o && t.tempId && (W(e, t.tempId, o), ir(e, t.tempId, o.id));
2283
+ let [n, r, i, a, o] = t.args, s = await e.apiClient.createDrawing(n, r, i, a ?? u(), t.tempId, ...o ? [o] : []);
2284
+ s && t.tempId && (X(e, t, s, t.tempId, !0), lr(e, t.tempId, s.id));
2093
2285
  break;
2094
2286
  }
2095
2287
  case "updateComment": {
2096
- let [n, r] = t.args;
2097
- await e.apiClient.updateComment(n, r);
2288
+ let [n, r] = t.args, i = await e.apiClient.updateComment(n, r);
2289
+ i && X(e, t, i, n);
2098
2290
  break;
2099
2291
  }
2100
2292
  case "deleteComment": {
2101
2293
  let [n] = t.args;
2102
- await e.apiClient.deleteComment(n);
2294
+ await e.apiClient.deleteComment(n), ur(e, n);
2103
2295
  break;
2104
2296
  }
2105
2297
  case "resolveComment": {
2106
- let [n] = t.args;
2107
- await e.apiClient.resolveComment(n);
2298
+ let [n] = t.args, r = await e.apiClient.resolveComment(n);
2299
+ r && X(e, t, r, n);
2108
2300
  break;
2109
2301
  }
2110
2302
  case "unresolveComment": {
2111
- let [n] = t.args;
2112
- await e.apiClient.unresolveComment(n);
2303
+ let [n] = t.args, r = await e.apiClient.unresolveComment(n);
2304
+ r && X(e, t, r, n);
2113
2305
  break;
2114
2306
  }
2115
2307
  case "completeComment": {
2116
- let [n] = t.args;
2117
- await e.apiClient.markComplete(n);
2308
+ let [n] = t.args, r = await e.apiClient.markComplete(n);
2309
+ r && X(e, t, r, n);
2118
2310
  break;
2119
2311
  }
2120
2312
  case "addReply": {
2121
- let [n, r] = t.args, i = await e.apiClient.addReply(n, r, t.tempId);
2122
- i && t.tempId && Vt(e, n, t.tempId, i);
2313
+ let [n, r, i] = t.args, a = await e.apiClient.addReply(n, r, t.tempId, ...i ? [i] : []);
2314
+ if (a && t.tempId) {
2315
+ let r = e.getState().comments.find((e) => e.id === n), i = e.getState().pendingMutations.some((e) => e.type === "reactToComment" && e.ownerId === t.ownerId && e.args[0] === n && e.args[3] === t.tempId), o = r?.replies.find((e) => e.id === t.tempId);
2316
+ Ut(e, n, t.tempId, i && o ? {
2317
+ ...a,
2318
+ reactions: o.reactions
2319
+ } : a), dr(e, n, t.tempId, a.id);
2320
+ let s = e.getState().comments.find((e) => e.id === n);
2321
+ s && X(e, t, s, n);
2322
+ }
2123
2323
  break;
2124
2324
  }
2125
2325
  case "reactToComment": {
2126
- let [n, r, i] = t.args, a;
2127
- a = i === "add" || i === "remove" ? i === "remove" : e.getState().comments.find((e) => e.id === n)?.reactions?.find((e) => e.emoji === r)?.reacted === !0, a ? await e.apiClient.removeReaction(n, r) : await e.apiClient.addReaction(n, r);
2326
+ let [n, r, i, a] = t.args, o;
2327
+ o = i === "add" || i === "remove" ? i === "remove" : e.getState().comments.find((e) => e.id === n)?.reactions?.find((e) => e.emoji === r)?.reacted === !0, o ? await e.apiClient.removeReaction(n, r, ...a ? [a] : []) : await e.apiClient.addReaction(n, r, ...a ? [a] : []);
2128
2328
  break;
2129
2329
  }
2130
2330
  case "updatePosition": {
2131
- let [n, r] = t.args;
2132
- await e.apiClient.updatePosition(n, r);
2331
+ let [n, r] = t.args, i = await e.apiClient.updatePosition(n, r);
2332
+ i && X(e, t, i, n);
2133
2333
  break;
2134
2334
  }
2135
2335
  }
2136
2336
  }
2137
- var or = 1e4, sr = 2048, cr = 10485760, lr = 20971520, Z = 16384, ur = 32e6, dr = 10, fr = 10485760, pr = 26214400, mr = /* @__PURE__ */ new Set([
2337
+ var pr = 1e4, mr = 2048, hr = 10485760, gr = 20971520, Z = 16384, _r = 32e6, vr = 10, yr = 10485760, br = 26214400, xr = /* @__PURE__ */ new Set([
2138
2338
  "jpg",
2139
2339
  "jpeg",
2140
2340
  "png",
@@ -2145,7 +2345,7 @@ var or = 1e4, sr = 2048, cr = 10485760, lr = 20971520, Z = 16384, ur = 32e6, dr
2145
2345
  "docx",
2146
2346
  "txt",
2147
2347
  "csv"
2148
- ]), hr = 15e3, gr = 1e4, _r = {
2348
+ ]), Sr = 15e3, Cr = 1e4, wr = {
2149
2349
  "image/gif": "gif",
2150
2350
  "image/jpeg": "jpg",
2151
2351
  "image/png": "png",
@@ -2155,52 +2355,52 @@ function Q(e, t) {
2155
2355
  let n = Error(t);
2156
2356
  return n.error = e, n.code = 400, n;
2157
2357
  }
2158
- function vr(e) {
2358
+ function Tr(e) {
2159
2359
  if (typeof e != "string") throw Q("invalid_position", "Invalid position");
2160
2360
  let t = e.trim();
2161
- if (!t || t.length > sr || r(t)) throw Q("invalid_position", "Invalid position");
2361
+ if (!t || t.length > mr || r(t)) throw Q("invalid_position", "Invalid position");
2162
2362
  return t;
2163
2363
  }
2164
- function yr(t) {
2364
+ function Er(t) {
2165
2365
  if (!i(t) || !e(t.x) || !e(t.y)) throw Q("invalid_position", "Invalid position");
2166
2366
  return {
2167
2367
  x: t.x,
2168
2368
  y: t.y,
2169
- ...t.element === void 0 ? {} : { element: vr(t.element) },
2170
- ...t.xpath === void 0 ? {} : { xpath: vr(t.xpath) }
2369
+ ...t.element === void 0 ? {} : { element: Tr(t.element) },
2370
+ ...t.xpath === void 0 ? {} : { xpath: Tr(t.xpath) }
2171
2371
  };
2172
2372
  }
2173
- function br(e) {
2373
+ function Dr(e) {
2174
2374
  if (typeof e != "string") throw Q("invalid_content", "Screenshot comment is required");
2175
2375
  let t = e.trim();
2176
- if (!t || t.length > or || r(t)) throw Q("invalid_content", "Screenshot comment is required");
2376
+ if (!t || t.length > pr || r(t)) throw Q("invalid_content", "Screenshot comment is required");
2177
2377
  return t;
2178
2378
  }
2179
- function xr(e) {
2379
+ function Or(e) {
2180
2380
  return typeof Blob < "u" && e instanceof Blob;
2181
2381
  }
2182
- function Sr(e) {
2382
+ function kr(e) {
2183
2383
  return typeof File < "u" && e instanceof File;
2184
2384
  }
2185
- function Cr(e) {
2385
+ function Ar(e) {
2186
2386
  return typeof HTMLElement < "u" && e instanceof HTMLElement;
2187
2387
  }
2188
- function wr(e) {
2388
+ function jr(e) {
2189
2389
  if (e !== void 0) {
2190
- if (!Cr(e)) throw Q("invalid_element", "Invalid screenshot target");
2390
+ if (!Ar(e)) throw Q("invalid_element", "Invalid screenshot target");
2191
2391
  return e;
2192
2392
  }
2193
2393
  if (typeof document > "u" || !document.body) throw Q("invalid_element", "A browser document is required to capture screenshots");
2194
2394
  return document.body;
2195
2395
  }
2196
- function Tr(e) {
2396
+ function Mr(e) {
2197
2397
  let t = /^data:(image\/(?:png|jpeg|gif|webp));base64,/i.exec(e)?.[1];
2198
2398
  return t ? t.toLowerCase() : null;
2199
2399
  }
2200
- function Er(e) {
2400
+ function Nr(e) {
2201
2401
  if (!i(e)) throw Q("invalid_screenshot", "Invalid screenshot result");
2202
2402
  let t = typeof e.dataUrl == "string" ? e.dataUrl.trim() : "", n = e.blob, r = e.dimensions;
2203
- if (!Tr(t) || t.length > lr || !xr(n) || n.size <= 0 || n.size > cr || n.type && !Object.prototype.hasOwnProperty.call(_r, n.type)) throw Q("invalid_screenshot", "Invalid screenshot result");
2403
+ if (!Mr(t) || t.length > gr || !Or(n) || n.size <= 0 || n.size > hr || n.type && !Object.prototype.hasOwnProperty.call(wr, n.type)) throw Q("invalid_screenshot", "Invalid screenshot result");
2204
2404
  if (!i(r)) throw Q("invalid_screenshot", "Invalid screenshot dimensions");
2205
2405
  let { width: a, height: o } = r;
2206
2406
  if (typeof a != "number" || typeof o != "number" || !Number.isFinite(a) || !Number.isFinite(o) || a <= 0 || o <= 0 || a > Z || o > Z) throw Q("invalid_screenshot", "Invalid screenshot dimensions");
@@ -2213,14 +2413,14 @@ function Er(e) {
2213
2413
  }
2214
2414
  };
2215
2415
  }
2216
- function Dr(e) {
2217
- let t = Tr(e.dataUrl);
2416
+ function Pr(e) {
2417
+ let t = Mr(e.dataUrl);
2218
2418
  return e.blob.type || t;
2219
2419
  }
2220
- function Or(e) {
2221
- return `screenshot.${_r[Dr(e)]}`;
2420
+ function Fr(e) {
2421
+ return `screenshot.${wr[Pr(e)]}`;
2222
2422
  }
2223
- function kr(e, t, n) {
2423
+ function Ir(e, t, n) {
2224
2424
  let r = null;
2225
2425
  return new Promise((i, a) => {
2226
2426
  r = setTimeout(() => {
@@ -2232,46 +2432,46 @@ function kr(e, t, n) {
2232
2432
  });
2233
2433
  });
2234
2434
  }
2235
- function Ar(e) {
2435
+ function Lr(e) {
2236
2436
  return new Promise((t, n) => {
2237
2437
  let r = !1, i = setTimeout(() => {
2238
2438
  r = !0, n(/* @__PURE__ */ Error("toBlob timed out"));
2239
- }, gr);
2439
+ }, Cr);
2240
2440
  e.toBlob((e) => {
2241
2441
  r || (r = !0, clearTimeout(i), e ? t(e) : n(/* @__PURE__ */ Error("toBlob returned null")));
2242
2442
  }, "image/png");
2243
2443
  });
2244
2444
  }
2245
- function jr(e) {
2445
+ function Rr(e) {
2246
2446
  let t = e.lastIndexOf(".");
2247
2447
  return t >= 0 ? e.slice(t + 1).toLowerCase() : "";
2248
2448
  }
2249
- function Mr(e) {
2449
+ function zr(e) {
2250
2450
  if (!Array.isArray(e)) throw Q("invalid_files", "Files must be an array");
2251
- if (e.length > dr) throw Q("too_many_files", `Cannot upload more than ${dr} files at once`);
2451
+ if (e.length > vr) throw Q("too_many_files", `Cannot upload more than ${vr} files at once`);
2252
2452
  let t = 0;
2253
2453
  for (let n of e) {
2254
- if (!Sr(n)) throw Q("invalid_files", "Invalid file upload");
2255
- if (n.size > fr) throw Q("file_too_large", `File "${n.name}" exceeds the ${fr / 1024 / 1024}MB limit`);
2256
- if (t += n.size, t > pr) throw Q("upload_too_large", `Total upload size exceeds the ${pr / 1024 / 1024}MB limit`);
2454
+ if (!kr(n)) throw Q("invalid_files", "Invalid file upload");
2455
+ if (n.size > yr) throw Q("file_too_large", `File "${n.name}" exceeds the ${yr / 1024 / 1024}MB limit`);
2456
+ if (t += n.size, t > br) throw Q("upload_too_large", `Total upload size exceeds the ${br / 1024 / 1024}MB limit`);
2257
2457
  if (r(n.name) || n.name.includes("/") || n.name.includes("\\")) throw Q("invalid_filename", "Filename contains invalid characters");
2258
- if (s(n.name)) throw Q("invalid_file_type", `File type ".${jr(n.name)}" is not allowed`);
2259
- if (!mr.has(jr(n.name))) throw Q("invalid_file_type", `File type ".${jr(n.name)}" is not supported. Allowed: ${[...mr].map((e) => `.${e}`).join(", ")}`);
2458
+ if (s(n.name)) throw Q("invalid_file_type", `File type ".${Rr(n.name)}" is not allowed`);
2459
+ if (!xr.has(Rr(n.name))) throw Q("invalid_file_type", `File type ".${Rr(n.name)}" is not supported. Allowed: ${[...xr].map((e) => `.${e}`).join(", ")}`);
2260
2460
  }
2261
2461
  return e;
2262
2462
  }
2263
- function Nr(e) {
2463
+ function Br(e) {
2264
2464
  try {
2265
- return e.matches?.("input[type=\"password\"],[data-commentkit-redact],[data-html2canvas-ignore],[autocomplete*=\"cc-\"],[autocomplete=\"current-password\"],[autocomplete=\"new-password\"]") ?? !1;
2465
+ return e.matches?.("input[type=\"password\"],[data-commentkit],[data-commentkit-host],[data-commentkit-ui],[data-commentkit-panel],[data-commentkit-redact],[data-html2canvas-ignore],[autocomplete*=\"cc-\"],[autocomplete=\"current-password\"],[autocomplete=\"new-password\"]") ?? !1;
2266
2466
  } catch {
2267
2467
  return !1;
2268
2468
  }
2269
2469
  }
2270
- async function Pr(e, t, n, r = {}) {
2470
+ async function Vr(e, t, n, r = {}) {
2271
2471
  if (e.isLocalDemo) return null;
2272
2472
  try {
2273
- let e = wr(n);
2274
- if (t) return Er(await t(e));
2473
+ let e = jr(n);
2474
+ if (t) return Nr(await t(e));
2275
2475
  let r;
2276
2476
  try {
2277
2477
  r = (await import("html2canvas")).default;
@@ -2279,17 +2479,17 @@ async function Pr(e, t, n, r = {}) {
2279
2479
  /* v8 ignore next 3 -- dynamic import() can't be intercepted by vi.mock */
2280
2480
  throw Error("Screenshot requires either a custom screenshotProvider in config or html2canvas installed. Install html2canvas: npm install html2canvas — or provide config.screenshotProvider.");
2281
2481
  }
2282
- let i = await kr(r(e, {
2482
+ let i = await Ir(r(e, {
2283
2483
  useCORS: !0,
2284
2484
  allowTaint: !1,
2285
2485
  scale: 2,
2286
2486
  logging: !1,
2287
- ignoreElements: Nr
2288
- }), hr, "html2canvas timed out after 15s");
2289
- if (i.width > Z || i.height > Z || i.width * i.height > ur) throw Q("screenshot_too_large", "Captured area is too large to screenshot");
2290
- return Er({
2487
+ ignoreElements: Br
2488
+ }), Sr, "html2canvas timed out after 15s");
2489
+ if (i.width > Z || i.height > Z || i.width * i.height > _r) throw Q("screenshot_too_large", "Captured area is too large to screenshot");
2490
+ return Nr({
2291
2491
  dataUrl: i.toDataURL("image/png"),
2292
- blob: await Ar(i),
2492
+ blob: await Lr(i),
2293
2493
  dimensions: {
2294
2494
  width: i.width,
2295
2495
  height: i.height
@@ -2303,51 +2503,52 @@ async function Pr(e, t, n, r = {}) {
2303
2503
  })), null;
2304
2504
  }
2305
2505
  }
2306
- async function Fr(e, t, n, r) {
2506
+ async function Hr(e, t, n, r) {
2307
2507
  try {
2308
- let i = Er(t), a = br(n), o = yr(r);
2508
+ let i = Nr(t), a = Dr(n), o = Er(r);
2309
2509
  e.setState({ isLoading: !0 });
2310
- let s = new File([i.blob], Or(i), { type: Dr(i) }), c = u(), l = await e.apiClient.uploadScreenshot(s, {
2510
+ let s = new File([i.blob], Fr(i), { type: Pr(i) }), c = u(), l = e.getState().activeBranch ?? void 0, d = await e.apiClient.uploadScreenshot(s, {
2311
2511
  content: a,
2312
2512
  position: o,
2313
- page: c
2513
+ page: c,
2514
+ ...l ? { branch: l } : {}
2314
2515
  });
2315
2516
  return e.setState({
2316
- comments: [...e.getState().comments, l],
2517
+ comments: !e.getState().activeBranch || e.getState().activeBranch === d.branch ? [...e.getState().comments, d] : e.getState().comments,
2317
2518
  isLoading: !1,
2318
2519
  activeScreenshot: null
2319
- }), e.emit("comment:created", l), l;
2520
+ }), e.emit("comment:created", d), d;
2320
2521
  } catch (t) {
2321
2522
  return e.setState({ isLoading: !1 }), e.handleError(t), null;
2322
2523
  }
2323
2524
  }
2324
- async function Ir(e, t, n) {
2525
+ async function Ur(e, t, n) {
2325
2526
  try {
2326
- let r = Mr(t);
2527
+ let r = zr(t);
2327
2528
  return r.length === 0 ? [] : await e.apiClient.uploadFiles(r, n);
2328
2529
  } catch (t) {
2329
2530
  return e.handleError(t), [];
2330
2531
  }
2331
2532
  }
2332
2533
  var $ = null;
2333
- async function Lr() {
2334
- return $ || ($ = await import("./realtime-BG_t_ze7.js"), $);
2534
+ async function Wr() {
2535
+ return $ || ($ = await import("./realtime-Dk41VwKg.js"), $);
2335
2536
  }
2336
- var Rr = typeof window < "u", zr = /* @__PURE__ */ new Set([
2537
+ var Gr = typeof window < "u", Kr = /* @__PURE__ */ new Set([
2337
2538
  "list",
2338
2539
  "detail",
2339
2540
  "settings",
2340
2541
  "activity",
2341
2542
  "dev-export"
2342
- ]), Br = /* @__PURE__ */ new Set([
2543
+ ]), qr = /* @__PURE__ */ new Set([
2343
2544
  "comment",
2344
2545
  "draw",
2345
2546
  "highlight",
2346
2547
  "screenshot",
2347
2548
  "select",
2348
2549
  null
2349
- ]), Vr = 256, Hr = "0.6.9";
2350
- function Ur(e) {
2550
+ ]), Jr = 256, Yr = "0.7.0";
2551
+ function Xr(e) {
2351
2552
  let t = e.trim().match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);
2352
2553
  return t ? [
2353
2554
  Number(t[1]),
@@ -2355,12 +2556,12 @@ function Ur(e) {
2355
2556
  Number(t[3] ?? 0)
2356
2557
  ] : null;
2357
2558
  }
2358
- function Wr(e) {
2559
+ function Zr(e) {
2359
2560
  return /^v?\d+(?:\.\d+)?(?:\.\d+)?-/.test(e.trim());
2360
2561
  }
2361
- function Gr(e, t) {
2362
- if (Wr(e)) return !1;
2363
- let n = Ur(e), r = Ur(t);
2562
+ function Qr(e, t) {
2563
+ if (Zr(e)) return !1;
2564
+ let n = Xr(e), r = Xr(t);
2364
2565
  if (!n || !r) return !1;
2365
2566
  for (let e = 0; e < 3; e++) {
2366
2567
  let t = n[e] ?? 0, i = r[e] ?? 0;
@@ -2369,7 +2570,7 @@ function Gr(e, t) {
2369
2570
  }
2370
2571
  return !1;
2371
2572
  }
2372
- var Kr = class extends He {
2573
+ var $r = class extends Ue {
2373
2574
  get isProcessingQueue() {
2374
2575
  return this.queueGuard.current;
2375
2576
  }
@@ -2389,7 +2590,7 @@ var Kr = class extends He {
2389
2590
  this.retryTimerRef.current = e;
2390
2591
  }
2391
2592
  constructor(e, t) {
2392
- super(), this.wsManager = null, this.wsUnsubscribers = [], this.keyboardHandler = null, this.holdActivationHandler = null, this.holdBlurHandler = null, this.toggleHandler = null, this.mouseMoveHandler = null, this.hashChangeHandler = null, this.onlineHandler = null, this.offlineHandler = null, this.initialized = !1, this.destroyed = !1, this.screenshotProvider = null, this.bootRetryTimer = null, this.bootAttempts = 0, this.pendingStateUpdates = null, this.flushScheduled = !1, this.isFlushing = !1, this.queueGuard = { current: !1 }, this.activeMutations = /* @__PURE__ */ new Set(), this.sliceSubscribers = /* @__PURE__ */ new Map(), this.retryTimerRef = { current: null }, this.otpFailedAttempts = 0, this.otpCooldownUntil = 0, this.overlayBeforeTool = null, this.loadMoreGuard = { current: !1 }, this.offlinePersistUnsub = null, this.escapeBlockers = /* @__PURE__ */ new Set(), this.config = { ...e }, this.localDemo = t ?? null, this.localDemo && (this.config.features = {
2593
+ super(), this.wsManager = null, this.wsUnsubscribers = [], this.keyboardHandler = null, this.holdActivationHandler = null, this.holdBlurHandler = null, this.toggleHandler = null, this.mouseMoveHandler = null, this.hashChangeHandler = null, this.onlineHandler = null, this.offlineHandler = null, this.initialized = !1, this.destroyed = !1, this.sessionRevision = 0, this.authRequestRevision = 0, this.commentsFetchRevision = 0, this.contextFetchRevision = 0, this.deepLinkRequest = null, this.reactionRequests = /* @__PURE__ */ new Map(), this.draftUploads = /* @__PURE__ */ new WeakMap(), this.screenshotProvider = null, this.bootRetryTimer = null, this.bootAttempts = 0, this.pendingStateUpdates = null, this.flushScheduled = !1, this.isFlushing = !1, this.queueGuard = { current: !1 }, this.activeMutations = /* @__PURE__ */ new Set(), this.sliceSubscribers = /* @__PURE__ */ new Map(), this.retryTimerRef = { current: null }, this.otpFailedAttempts = 0, this.otpCooldownUntil = 0, this.overlayBeforeTool = null, this.loadMoreGuard = { current: !1 }, this.offlinePersistUnsub = null, this.escapeBlockers = /* @__PURE__ */ new Set(), this.config = { ...e }, this.localDemo = t ?? null, this.localDemo && (this.config.features = {
2393
2594
  comments: !0,
2394
2595
  drawing: !1,
2395
2596
  highlighting: !1,
@@ -2398,7 +2599,7 @@ var Kr = class extends He {
2398
2599
  }, this.config.ui = {
2399
2600
  ...this.config.ui,
2400
2601
  loadRemoteFonts: !1
2401
- }), Rr && !this.config.environment && (this.config.environment = this.detectEnvironment()), this.apiClient = this.localDemo?.client ?? new se(this.config), this.apiClient.setOnAuthExpired(() => this.handleAuthExpired()), this.state = bn(), this.requiresShortcut() && (this.state.isOverlayVisible = !1), this.screenshotProvider = e.screenshotProvider || null, this.ctx = {
2602
+ }), Gr && !this.config.environment && (this.config.environment = this.detectEnvironment()), this.apiClient = this.localDemo?.client ?? new ce(this.config), this.apiClient.setOnAuthExpired(() => this.handleAuthExpired()), this.state = Cn(), this.state.activeBranch = typeof e.branch == "string" && e.branch.trim().length <= 255 && !r(e.branch) && e.branch.trim() || null, this.requiresShortcut() && (this.state.isOverlayVisible = !1), this.screenshotProvider = e.screenshotProvider || null, this.ctx = {
2402
2603
  getState: () => this.getInternalState(),
2403
2604
  setState: (e) => this.setState(e),
2404
2605
  apiClient: this.apiClient,
@@ -2426,7 +2627,7 @@ var Kr = class extends He {
2426
2627
  mouseMoveHandler: this.mouseMoveHandler
2427
2628
  }, this.localDemo && (this.restoreDemoState(), this.localDemo.subscribe((e) => {
2428
2629
  e !== "persist" && this.restoreDemoState();
2429
- })), e.enabled !== !1 && Rr && Promise.resolve().then(() => this.boot()).catch((e) => this.handleError(e));
2630
+ })), e.enabled !== !1 && Gr && Promise.resolve().then(() => this.boot()).catch((e) => this.handleError(e));
2430
2631
  /* v8 ignore stop */
2431
2632
  }
2432
2633
  isLocalDemo() {
@@ -2434,14 +2635,15 @@ var Kr = class extends He {
2434
2635
  }
2435
2636
  restoreDemoState() {
2436
2637
  if (!this.localDemo || this.destroyed) return;
2437
- let e = this.localDemo.getSession().expired;
2638
+ let e = this.localDemo.getSession().expired, t = this.getInternalState().activeBranch ?? null;
2438
2639
  this.overlayBeforeTool = null, this.setState({
2439
- ...bn(),
2640
+ ...Cn(),
2440
2641
  currentUser: e ? null : { ...this.localDemo.user },
2441
2642
  isAuthenticated: !e,
2442
2643
  isOverlayVisible: !e,
2443
2644
  isOnline: !0,
2444
- comments: this.localDemo.getComments(),
2645
+ activeBranch: t,
2646
+ comments: this.localDemo.getComments().filter((e) => !t || e.branch === t),
2445
2647
  project: {
2446
2648
  id: "local-demo",
2447
2649
  slug: "local-demo",
@@ -2528,8 +2730,8 @@ var Kr = class extends He {
2528
2730
  };
2529
2731
  }
2530
2732
  let n = e.project?.sdkLatestVersion;
2531
- n && Gr(n, "0.6.9") && (console.warn(`[CommentKit] You are using v${Hr}. Update to v${n}: npm update @commentkit/comment-kit`), this.emit("sdk:outdated", {
2532
- current: Hr,
2733
+ n && Qr(n, "0.7.0") && (console.warn(`[CommentKit] You are using v${Yr}. Update to v${n}: npm update @commentkit/comment-kit`), this.emit("sdk:outdated", {
2734
+ current: Yr,
2533
2735
  latest: n
2534
2736
  })), this.setState({
2535
2737
  project: e.project,
@@ -2562,6 +2764,7 @@ var Kr = class extends He {
2562
2764
  ...e,
2563
2765
  currentUser: e.currentUser ? structuredClone(e.currentUser) : null,
2564
2766
  project: e.project ? structuredClone(e.project) : null,
2767
+ projectContext: e.projectContext ? structuredClone(e.projectContext) : null,
2565
2768
  comments: structuredClone(e.comments),
2566
2769
  selectedComment: e.selectedComment ? structuredClone(e.selectedComment) : null,
2567
2770
  activeComment: e.activeComment ? structuredClone(e.activeComment) : null,
@@ -2603,7 +2806,7 @@ var Kr = class extends He {
2603
2806
  e.activeTool !== void 0 && e.activeTool !== t.activeTool && this.emit("tool:changed", e.activeTool), e.isOverlayVisible !== void 0 && e.isOverlayVisible !== t.isOverlayVisible && this.emit("overlay:toggled", e.isOverlayVisible), e.isSidebarVisible !== void 0 && e.isSidebarVisible !== t.isSidebarVisible && this.emit("sidebar:toggled", e.isSidebarVisible), e.isLoginModalVisible !== void 0 && e.isLoginModalVisible !== t.isLoginModalVisible && this.emit("loginmodal:toggled", e.isLoginModalVisible), e.isShortcutsOverlayVisible !== void 0 && e.isShortcutsOverlayVisible !== t.isShortcutsOverlayVisible && this.emit("shortcuts:toggled", e.isShortcutsOverlayVisible), e.connectionStatus !== void 0 && e.connectionStatus !== t.connectionStatus && this.emit("connection:changed", e.connectionStatus);
2604
2807
  let n = Object.keys(e);
2605
2808
  for (let [e, t] of this.sliceSubscribers) {
2606
- let r = _n[e];
2809
+ let r = bn[e];
2607
2810
  if (n.some((e) => r.includes(e))) for (let n of t) try {
2608
2811
  n(this.state);
2609
2812
  } catch (t) {
@@ -2633,14 +2836,16 @@ var Kr = class extends He {
2633
2836
  ...this.config.baseUrl !== void 0 && { baseUrl: this.config.baseUrl },
2634
2837
  ...this.config.enabled !== void 0 && { enabled: this.config.enabled },
2635
2838
  screenshotProvider: this.config.screenshotProvider,
2839
+ branch: this.config.branch,
2840
+ realtime: this.config.realtime ? { ...this.config.realtime } : void 0,
2636
2841
  ui: this.config.ui ? { ...this.config.ui } : void 0
2637
2842
  };
2638
2843
  }
2639
2844
  async validateInvite(e) {
2640
- if (!(this.destroyed || this.localDemo)) return mt(this.ctx, e, (e) => this.login(e));
2845
+ if (!(this.destroyed || this.localDemo)) return ht(this.ctx, e, (e) => this.login(e), this.beginAuthRequest());
2641
2846
  }
2642
2847
  onSlice(e, t) {
2643
- if (!_n[e] || typeof t != "function" || this.destroyed) return () => {};
2848
+ if (!bn[e] || typeof t != "function" || this.destroyed) return () => {};
2644
2849
  let n = this.sliceSubscribers.get(e);
2645
2850
  return n || (n = /* @__PURE__ */ new Set(), this.sliceSubscribers.set(e, n)), n.add(t), () => n.delete(t);
2646
2851
  }
@@ -2676,7 +2881,7 @@ var Kr = class extends He {
2676
2881
  }
2677
2882
  async restorePersistedSession() {
2678
2883
  if (this.destroyed) return;
2679
- let e = Ye(this.config.projectId);
2884
+ let e = Xe(this.config.projectId);
2680
2885
  if (e) try {
2681
2886
  this.apiClient.setAuthToken(e.token), this.apiClient.setUserEmail(e.email), this.setState({
2682
2887
  currentUser: e.user,
@@ -2690,11 +2895,21 @@ var Kr = class extends He {
2690
2895
  this.handleAuthExpired();
2691
2896
  }
2692
2897
  }
2693
- async afterAuthenticated() {
2694
- this.destroyed || (this.getFeatures().realtime && this.initializeWebSocket(), await this.loadComments(), this.handleDeepLink(), this.getInternalState().pendingMutations.length > 0 && this.scheduleRetry());
2898
+ async afterAuthenticated(e) {
2899
+ this.destroyed || (this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), e && e !== this.getInternalState().currentUser?.id && this.setState({
2900
+ comments: [],
2901
+ selectedComment: null,
2902
+ projectContext: null,
2903
+ activities: [],
2904
+ seenThreadIds: /* @__PURE__ */ new Set()
2905
+ }), ir(this.ctx), this.getFeatures().realtime && this.initializeWebSocket(), await Promise.all([this.loadComments(), this.reloadProjectContext()]), this.handleDeepLink(), this.getInternalState().pendingMutations.length > 0 && this.scheduleRetry());
2906
+ }
2907
+ beginAuthRequest() {
2908
+ let e = ++this.authRequestRevision;
2909
+ return () => !this.destroyed && e === this.authRequestRevision;
2695
2910
  }
2696
2911
  async login(e) {
2697
- if (!(this.destroyed || this.localDemo)) return st(this.ctx, e);
2912
+ if (!(this.destroyed || this.localDemo)) return ct(this.ctx, e, this.beginAuthRequest());
2698
2913
  }
2699
2914
  async verifyOtp(e) {
2700
2915
  if (this.destroyed || this.localDemo) return;
@@ -2706,9 +2921,13 @@ var Kr = class extends He {
2706
2921
  message: `Too many attempts. Please wait ${e}s and try again.`,
2707
2922
  code: 429
2708
2923
  });
2709
- } else return ct(this.ctx, e, {
2924
+ return;
2925
+ }
2926
+ let n = this.getInternalState().currentUser?.id;
2927
+ return lt(this.ctx, e, {
2928
+ isCurrent: this.beginAuthRequest(),
2710
2929
  onAuthenticated: async () => {
2711
- await this.afterAuthenticated();
2930
+ await this.afterAuthenticated(n);
2712
2931
  },
2713
2932
  onSuccess: () => {
2714
2933
  this.otpFailedAttempts = 0, this.otpCooldownUntil = 0;
@@ -2722,24 +2941,24 @@ var Kr = class extends He {
2722
2941
  });
2723
2942
  }
2724
2943
  cancelOtp() {
2725
- this.destroyed || lt(this.ctx);
2944
+ this.destroyed || (this.authRequestRevision++, ut(this.ctx));
2726
2945
  }
2727
2946
  async resendOtp() {
2728
- if (!(this.destroyed || this.localDemo)) return ut(this.ctx);
2947
+ if (!(this.destroyed || this.localDemo)) return dt(this.ctx, this.beginAuthRequest());
2729
2948
  }
2730
2949
  logout() {
2731
- this.destroyed || (this.localDemo ? (this.setTool(null), this.setState({
2950
+ this.destroyed || (this.authRequestRevision++, this.localDemo ? (this.setTool(null), this.setState({
2732
2951
  isOverlayVisible: !1,
2733
2952
  isSidebarVisible: !1
2734
- })) : (this.overlayBeforeTool = null, dt(this.ctx, () => {
2953
+ })) : (this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), this.setState({ projectContext: null }), this.overlayBeforeTool = null, ft(this.ctx, () => {
2735
2954
  this.disconnectRealtime(!0);
2736
2955
  })));
2737
2956
  }
2738
2957
  handleAuthExpired() {
2739
- this.overlayBeforeTool = null, this.disconnectRealtime(!0), ft(this.ctx);
2958
+ this.destroyed || (this.authRequestRevision++, this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), this.setState({ projectContext: null }), this.overlayBeforeTool = null, this.disconnectRealtime(!0), pt(this.ctx));
2740
2959
  }
2741
2960
  toggleLoginModal() {
2742
- this.destroyed || this.localDemo || pt(this.ctx);
2961
+ this.destroyed || this.localDemo || mt(this.ctx);
2743
2962
  }
2744
2963
  requiresShortcut() {
2745
2964
  return this.localDemo ? !0 : this.config.environment !== "development";
@@ -2759,7 +2978,7 @@ var Kr = class extends He {
2759
2978
  this.destroyed || this.setState({ isSidebarVisible: !this.getInternalState().isSidebarVisible });
2760
2979
  }
2761
2980
  setTool(e) {
2762
- if (this.destroyed || !Br.has(e) || this.localDemo && e !== null && e !== "comment" && e !== "select") return;
2981
+ if (this.destroyed || !qr.has(e) || this.localDemo && e !== null && e !== "comment" && e !== "select") return;
2763
2982
  let t = this.getInternalState();
2764
2983
  if (!t.isAuthenticated && e !== "select" && e !== null) {
2765
2984
  this.toggleLoginModal();
@@ -2780,40 +2999,89 @@ var Kr = class extends He {
2780
2999
  });
2781
3000
  }
2782
3001
  operationContext() {
2783
- if (!this.localDemo) return this.ctx;
2784
- this.localDemo.refresh();
2785
- let e = this.localDemo.getRevision(), t = () => !this.destroyed && e === this.localDemo?.getRevision();
3002
+ this.localDemo?.refresh();
3003
+ let e = this.localDemo?.getRevision(), t = this.sessionRevision, n = () => !this.destroyed && t === this.sessionRevision && e === this.localDemo?.getRevision();
2786
3004
  return {
2787
3005
  ...this.ctx,
2788
3006
  setState: (e) => {
2789
- t() && this.ctx.setState(e);
3007
+ n() && this.ctx.setState(e);
2790
3008
  },
2791
- emit: (e, n) => {
2792
- t() && this.ctx.emit(e, n);
3009
+ emit: (e, t) => {
3010
+ n() && this.ctx.emit(e, t);
2793
3011
  },
2794
3012
  handleError: (e) => {
2795
- t() && this.ctx.handleError(e);
3013
+ n() && this.ctx.handleError(e);
2796
3014
  }
2797
3015
  };
2798
3016
  }
2799
3017
  operationCallbacks() {
2800
- if (!this.localDemo) return this.commentCb;
2801
- let e = this.localDemo.getRevision();
3018
+ let e = this.localDemo?.getRevision(), t = this.sessionRevision, n = () => !this.destroyed && t === this.sessionRevision && e === this.localDemo?.getRevision();
2802
3019
  return {
2803
3020
  ...this.commentCb,
2804
- addActivity: (t) => {
2805
- e === this.localDemo?.getRevision() && this.commentCb.addActivity(t);
3021
+ queueMutation: (...e) => n() && this.commentCb.queueMutation(...e),
3022
+ addActivity: (e) => {
3023
+ n() && this.commentCb.addActivity(e);
3024
+ }
3025
+ };
3026
+ }
3027
+ commentsRequestContext(e) {
3028
+ let t = this.operationContext();
3029
+ return {
3030
+ ...t,
3031
+ setState: (n) => {
3032
+ e === this.commentsFetchRevision && t.setState(n);
3033
+ },
3034
+ handleError: (n) => {
3035
+ e === this.commentsFetchRevision && t.handleError(n);
2806
3036
  }
2807
3037
  };
2808
3038
  }
2809
3039
  async loadComments() {
2810
- return G(this.operationContext());
3040
+ return Gt(this.commentsRequestContext(++this.commentsFetchRevision));
2811
3041
  }
2812
3042
  async loadMoreComments() {
2813
- this.destroyed || await Ut(this.operationContext(), this.loadMoreGuard);
3043
+ this.destroyed || await Kt(this.commentsRequestContext(this.commentsFetchRevision), this.loadMoreGuard);
2814
3044
  }
2815
3045
  async reloadComments() {
2816
- if (!this.destroyed) return G(this.operationContext());
3046
+ if (!this.destroyed) return this.loadComments();
3047
+ }
3048
+ async reloadProjectContext() {
3049
+ if (this.destroyed || this.localDemo || !this.getInternalState().isAuthenticated) return;
3050
+ let e = this.operationContext(), t = ++this.contextFetchRevision;
3051
+ try {
3052
+ let n = await this.apiClient.getProjectContext();
3053
+ if (t !== this.contextFetchRevision) return;
3054
+ n?.project && Array.isArray(n.members) && e.setState({ projectContext: n });
3055
+ } catch (n) {
3056
+ t === this.contextFetchRevision && n.code !== 404 && e.handleError(n);
3057
+ }
3058
+ }
3059
+ async setBranch(e) {
3060
+ if (this.destroyed || e !== null && (typeof e != "string" || !e.trim() || e.length > 255 || r(e))) return;
3061
+ let t = e?.trim() ?? null;
3062
+ (this.getInternalState().activeBranch ?? null) !== t && (this.setState({
3063
+ activeBranch: t,
3064
+ selectedComment: null,
3065
+ panelView: "list",
3066
+ comments: [],
3067
+ pagination: null
3068
+ }), await this.loadComments());
3069
+ }
3070
+ async uploadDraftFiles(e) {
3071
+ if (this.destroyed || this.localDemo || !this.getInternalState().isAuthenticated) throw Error("Sign in to attach files.");
3072
+ if (!Array.isArray(e) || e.length > 10) throw Error("Attach up to 10 files.");
3073
+ let t = this.sessionRevision, n = [], r = this.draftUploads;
3074
+ for (let i of e) {
3075
+ let e = r.get(i);
3076
+ e || (e = this.apiClient.uploadFile(i, /^image\/(jpeg|png|gif|webp)$/.test(i.type) ? "screenshot" : "attachment").then((e) => e.id), r.set(i, e));
3077
+ try {
3078
+ n.push(await e);
3079
+ } catch (e) {
3080
+ throw r.delete(i), e;
3081
+ }
3082
+ if (this.destroyed || t !== this.sessionRevision) throw Error("Your session changed. Please sign in again.");
3083
+ }
3084
+ return n;
2817
3085
  }
2818
3086
  async createComment(e, t, n, r = "medium", i, a, o) {
2819
3087
  if (!this.destroyed) {
@@ -2822,64 +3090,76 @@ var Kr = class extends He {
2822
3090
  message: "Files and drawings are unavailable in the private browser demo.",
2823
3091
  code: 400
2824
3092
  });
2825
- else return Wt(this.operationContext(), this.operationCallbacks(), this.activeMutations, e, t, n, r, i, a, o);
3093
+ else return qt(this.operationContext(), this.operationCallbacks(), this.activeMutations, e, t, n, r, i, a, {
3094
+ ...o,
3095
+ branch: o?.branch ?? this.getInternalState().activeBranch ?? void 0
3096
+ });
2826
3097
  }
2827
3098
  }
2828
3099
  async updateComment(e, t) {
2829
- if (!this.destroyed) return Gt(this.operationContext(), this.operationCallbacks(), e, t);
3100
+ if (!this.destroyed) return Jt(this.operationContext(), this.operationCallbacks(), e, t);
2830
3101
  }
2831
3102
  async deleteComment(e) {
2832
- if (!this.destroyed) return Kt(this.operationContext(), this.operationCallbacks(), e);
3103
+ if (!this.destroyed) return Yt(this.operationContext(), this.operationCallbacks(), e);
2833
3104
  }
2834
- async addReply(e, t) {
2835
- if (!this.destroyed) return qt(this.operationContext(), this.operationCallbacks(), e, t);
3105
+ async addReply(e, t, n) {
3106
+ if (!this.destroyed) return Xt(this.operationContext(), this.operationCallbacks(), e, t, n);
2836
3107
  }
2837
- async updateReply(e, t, n) {
2838
- if (!this.destroyed) return Jt(this.operationContext(), e, t, n);
3108
+ async updateReply(e, t, n, r) {
3109
+ if (!this.destroyed) return Zt(this.operationContext(), e, t, n, r);
2839
3110
  }
2840
3111
  async deleteReply(e, t) {
2841
- if (!this.destroyed) return Yt(this.operationContext(), e, t);
3112
+ if (!this.destroyed) return Qt(this.operationContext(), e, t);
2842
3113
  }
2843
3114
  async resolveComment(e) {
2844
- if (!this.destroyed) return Xt(this.operationContext(), this.operationCallbacks(), e);
3115
+ if (!this.destroyed) return $t(this.operationContext(), this.operationCallbacks(), e);
2845
3116
  }
2846
3117
  async unresolveComment(e) {
2847
- if (!this.destroyed) return Zt(this.operationContext(), this.operationCallbacks(), e);
3118
+ if (!this.destroyed) return en(this.operationContext(), this.operationCallbacks(), e);
2848
3119
  }
2849
3120
  selectComment(e) {
2850
- this.destroyed || tn(this.operationContext(), e);
3121
+ this.destroyed || an(this.operationContext(), e);
2851
3122
  }
2852
3123
  async completeComment(e) {
2853
- if (!this.destroyed) return Qt(this.operationContext(), this.operationCallbacks(), e);
3124
+ if (!this.destroyed) return tn(this.operationContext(), this.operationCallbacks(), e);
2854
3125
  }
2855
- async reactToComment(e, t) {
2856
- if (!this.destroyed) return $t(this.operationContext(), this.operationCallbacks(), e, t);
3126
+ async reactToComment(e, t, n) {
3127
+ if (this.destroyed) return;
3128
+ let r = `${e}:${n ?? "parent"}`, i = this.sessionRevision, a = async () => {
3129
+ this.destroyed || i !== this.sessionRevision || await nn(this.operationContext(), this.operationCallbacks(), e, t, n);
3130
+ }, o = this.reactionRequests.get(r), s = o ? o.then(a, a) : a();
3131
+ this.reactionRequests.set(r, s);
3132
+ try {
3133
+ await s;
3134
+ } finally {
3135
+ this.reactionRequests.get(r) === s && this.reactionRequests.delete(r);
3136
+ }
2857
3137
  }
2858
3138
  async updateCommentPosition(e, t, n) {
2859
- if (!this.destroyed) return en(this.operationContext(), this.operationCallbacks(), e, t, n);
3139
+ if (!this.destroyed) return rn(this.operationContext(), this.operationCallbacks(), e, t, n);
2860
3140
  }
2861
3141
  hydrateOfflineQueue() {
2862
- let e = Xn(this.config.projectId);
3142
+ let e = $n(this.config.projectId);
2863
3143
  if (e.length > 0) {
2864
3144
  let t = this.getInternalState().pendingMutations, n = new Set(t.map((e) => e.id)), r = [...t, ...e.filter((e) => !n.has(e.id))];
2865
- this.setState({ pendingMutations: r }), this.getInternalState().isOnline && this.scheduleRetry();
3145
+ this.setState({ pendingMutations: r }), ir(this.ctx), this.getInternalState().isOnline && this.scheduleRetry();
2866
3146
  }
2867
- this.offlinePersistUnsub?.(), this.offlinePersistUnsub = this.select((e) => e.pendingMutations, (e) => Yn(this.config.projectId, e));
3147
+ this.offlinePersistUnsub?.(), this.offlinePersistUnsub = this.select((e) => e.pendingMutations, (e) => Qn(this.config.projectId, e));
2868
3148
  }
2869
3149
  shouldQueueMutation(e) {
2870
- return !this.localDemo && er(this.getInternalState(), e);
3150
+ return !this.localDemo && ar(this.getInternalState(), e);
2871
3151
  }
2872
3152
  queueMutation(e, t, n) {
2873
- return tr(this.ctx, () => this.scheduleRetry(), e, t, n);
3153
+ return or(this.ctx, () => this.scheduleRetry(), e, t, n);
2874
3154
  }
2875
3155
  scheduleRetry() {
2876
- nr(this.ctx, this.retryTimerRef, () => this.processOfflineQueue());
3156
+ sr(this.ctx, this.retryTimerRef, () => this.processOfflineQueue());
2877
3157
  }
2878
3158
  async processOfflineQueue() {
2879
- await rr(this.ctx, this.queueGuard, () => this.scheduleRetry(), (e) => this.executeMutation(e));
3159
+ await cr(this.operationContext(), this.queueGuard, () => this.scheduleRetry(), (e) => this.executeMutation(e));
2880
3160
  }
2881
3161
  async executeMutation(e) {
2882
- return ar(this.ctx, e);
3162
+ return fr(this.operationContext(), e);
2883
3163
  }
2884
3164
  getPendingMutationCount() {
2885
3165
  return this.getInternalState().pendingMutations.length;
@@ -2891,7 +3171,7 @@ var Kr = class extends He {
2891
3171
  !this.destroyed && this.getInternalState().isAuthenticated && (this.wsManager ? this.wsManager.reconnect() : this.initializeWebSocket());
2892
3172
  }
2893
3173
  markThreadSeen(e) {
2894
- if (this.destroyed || typeof e != "string" || !e.trim() || e.length > Vr) return;
3174
+ if (this.destroyed || typeof e != "string" || !e.trim() || e.length > Jr) return;
2895
3175
  let t = new Set(this.getInternalState().seenThreadIds);
2896
3176
  if (t.add(e), t.size > 1e3) {
2897
3177
  let e = Array.from(t);
@@ -2904,7 +3184,7 @@ var Kr = class extends He {
2904
3184
  return typeof e != "string" || !e.trim() ? !1 : !this.getInternalState().seenThreadIds.has(e);
2905
3185
  }
2906
3186
  setPanelView(e) {
2907
- !this.destroyed && zr.has(e) && this.setState({ panelView: e });
3187
+ !this.destroyed && Kr.has(e) && this.setState({ panelView: e });
2908
3188
  }
2909
3189
  toggleShortcutsOverlay() {
2910
3190
  this.destroyed || this.setState({ isShortcutsOverlayVisible: !this.getInternalState().isShortcutsOverlayVisible });
@@ -2939,21 +3219,39 @@ var Kr = class extends He {
2939
3219
  }
2940
3220
  handleDeepLink() {
2941
3221
  if (this.destroyed) return;
2942
- let e = window.location.hash.match(/^#comment-(.+)$/);
2943
- if (!e?.[1]) return;
2944
- let t = e[1];
2945
- this.emit("deeplink:navigate", { commentId: t });
2946
- let n = this.getInternalState().comments.find((e) => e.id === t);
2947
- n && (this.selectComment(n), this.setState({
3222
+ let e = window.location.hash, t = e.match(/^#comment-(.+)$/);
3223
+ if (!t?.[1]) return;
3224
+ let n = t[1];
3225
+ this.emit("deeplink:navigate", { commentId: n });
3226
+ let r = this.getInternalState().comments.find((e) => e.id === n);
3227
+ if (r) this.selectComment(r), this.setState({
2948
3228
  isSidebarVisible: !0,
2949
3229
  panelView: "detail"
2950
- }));
3230
+ });
3231
+ else if (this.getInternalState().isAuthenticated && n.length <= 256 && this.deepLinkRequest !== e) {
3232
+ this.deepLinkRequest = e;
3233
+ let t = this.sessionRevision;
3234
+ this.apiClient.getComment(n).then(async (r) => {
3235
+ if (this.destroyed || t !== this.sessionRevision || window.location.hash !== e || r.id !== n) return;
3236
+ let i = this.getInternalState().activeBranch;
3237
+ i && i !== r.branch && await this.setBranch(r.branch ?? null), !(this.destroyed || t !== this.sessionRevision || window.location.hash !== e) && (this.setState({
3238
+ comments: [...this.getInternalState().comments.filter((e) => e.id !== r.id), r],
3239
+ selectedComment: r,
3240
+ isSidebarVisible: !0,
3241
+ panelView: "detail"
3242
+ }), this.markThreadSeen(r.id));
3243
+ }).catch((n) => {
3244
+ !this.destroyed && t === this.sessionRevision && window.location.hash === e && this.handleError(n);
3245
+ }).finally(() => {
3246
+ this.deepLinkRequest === e && (this.deepLinkRequest = null);
3247
+ });
3248
+ }
2951
3249
  }
2952
3250
  async createHighlight(e, t) {
2953
- if (!this.destroyed) return nn(this.ctx, this.commentCb, this.activeMutations, e, t);
3251
+ if (!this.destroyed) return on(this.operationContext(), this.operationCallbacks(), this.activeMutations, e, t);
2954
3252
  }
2955
3253
  async createDrawing(e, t, n) {
2956
- if (!this.destroyed) return rn(this.ctx, this.commentCb, this.activeMutations, e, t, n);
3254
+ if (!this.destroyed) return sn(this.operationContext(), this.operationCallbacks(), this.activeMutations, e, t, n);
2957
3255
  }
2958
3256
  setActiveDrawing(e) {
2959
3257
  this.destroyed || this.setState({ activeDrawing: e });
@@ -2962,41 +3260,41 @@ var Kr = class extends He {
2962
3260
  this.destroyed || this.wsManager?.sendDrawingStroke(e);
2963
3261
  }
2964
3262
  async captureScreenshot(e) {
2965
- return this.destroyed ? null : Pr(this.ctx, this.screenshotProvider, e);
3263
+ return this.destroyed ? null : Vr(this.ctx, this.screenshotProvider, e);
2966
3264
  }
2967
3265
  async uploadScreenshot(e, t, n) {
2968
- return this.destroyed ? null : Fr(this.ctx, e, t, n);
3266
+ return this.destroyed ? null : Hr(this.operationContext(), e, t, n);
2969
3267
  }
2970
3268
  setActiveScreenshot(e) {
2971
3269
  this.destroyed || this.setState({ activeScreenshot: e });
2972
3270
  }
2973
3271
  async uploadFiles(e, t) {
2974
- return this.destroyed ? [] : Ir(this.ctx, e, t);
3272
+ return this.destroyed ? [] : Ur(this.ctx, e, t);
2975
3273
  }
2976
3274
  getAgentContext(e) {
2977
- return A(this.getInternalState(), e);
3275
+ return k(this.getInternalState(), e);
2978
3276
  }
2979
3277
  async getAgentContextAsync(e) {
2980
- let t = A(this.getInternalState(), e), n = this.localDemo?.getRevision(), r = await Me(t);
2981
- return this.localDemo?.checkExpiry(), this.localDemo && n !== this.localDemo.getRevision() ? A(this.getInternalState(), e) : r;
3278
+ let t = k(this.getInternalState(), e), n = this.localDemo?.getRevision(), r = await Ne(t);
3279
+ return this.localDemo?.checkExpiry(), this.localDemo && n !== this.localDemo.getRevision() ? k(this.getInternalState(), e) : r;
2982
3280
  }
2983
3281
  formatAgentContext(e) {
2984
- return j(this.getAgentContext(e));
3282
+ return A(this.getAgentContext(e));
2985
3283
  }
2986
3284
  async formatAgentContextAsync(e) {
2987
- return j(await this.getAgentContextAsync(e));
3285
+ return A(await this.getAgentContextAsync(e));
2988
3286
  }
2989
3287
  async copyAgentContext(e) {
2990
3288
  if (this.destroyed) return "";
2991
- let t = await this.getAgentContextAsync(e), n = j(t);
2992
- return await Re(n, t), this.emit("agent:context-copied", {
3289
+ let t = await this.getAgentContextAsync(e), n = A(t);
3290
+ return await ze(n, t), this.emit("agent:context-copied", {
2993
3291
  commentCount: t.comments.length,
2994
3292
  sourceResolved: t.sourceResolved
2995
3293
  }), n;
2996
3294
  }
2997
3295
  async grabElement(e, t) {
2998
3296
  if (this.destroyed) return null;
2999
- let { grabElement: n } = await import("./dev-grab-pDAfH2lr.js");
3297
+ let { grabElement: n } = await import("./dev-grab-DDqg0LQf.js");
3000
3298
  if (this.destroyed) return null;
3001
3299
  let r = await n(e, this.ctx, this.screenshotProvider, t);
3002
3300
  return this.destroyed ? null : (r && this.emit("agent:element-grabbed", {
@@ -3006,7 +3304,7 @@ var Kr = class extends He {
3006
3304
  }
3007
3305
  async grabElements(e, t) {
3008
3306
  if (this.destroyed) return null;
3009
- let { grabElements: n } = await import("./dev-grab-pDAfH2lr.js");
3307
+ let { grabElements: n } = await import("./dev-grab-DDqg0LQf.js");
3010
3308
  if (this.destroyed) return null;
3011
3309
  let r = await n(e, this.ctx, this.screenshotProvider, t);
3012
3310
  return this.destroyed ? null : (r && this.emit("agent:elements-grabbed", { count: r.results.length }), r);
@@ -3020,7 +3318,7 @@ var Kr = class extends He {
3020
3318
  }
3021
3319
  }
3022
3320
  handleToggleRequest() {
3023
- this.destroyed || hn(this.getInternalState(), this.kbdCallbacks);
3321
+ this.destroyed || vn(this.getInternalState(), this.kbdCallbacks);
3024
3322
  }
3025
3323
  handleKeyboardShortcuts(e) {
3026
3324
  if (!this.destroyed) {
@@ -3029,7 +3327,7 @@ var Kr = class extends He {
3029
3327
  let t = e.composedPath()[0];
3030
3328
  if (t instanceof Element && t.getRootNode() === document && t.closest("[data-commentkit-ui], [data-commentkit-ignore]")) return;
3031
3329
  }
3032
- gn(e, this.getInternalState(), this.kbdCallbacks);
3330
+ yn(e, this.getInternalState(), this.kbdCallbacks);
3033
3331
  }
3034
3332
  }
3035
3333
  matchesHoldKey(e) {
@@ -3043,7 +3341,7 @@ var Kr = class extends He {
3043
3341
  };
3044
3342
  }
3045
3343
  initializeWebSocket() {
3046
- this.destroyed || this.localDemo || Lr().then((e) => {
3344
+ this.destroyed || this.localDemo || Wr().then((e) => {
3047
3345
  this.destroyed || this.getInternalState().isAuthenticated && (this.syncRealtimeRefs(), e.initializeWebSocket(this.ctx, this.realtimeRefs), this.syncFromRealtimeRefs());
3048
3346
  }).catch((e) => {
3049
3347
  this.ctx.handleError(e);
@@ -3077,7 +3375,7 @@ var Kr = class extends He {
3077
3375
  this.removeMouseMoveListener(), this.syncRealtimeRefs();
3078
3376
  }
3079
3377
  destroy() {
3080
- this.destroyed || (this.destroyed = !0, Rr && (this.keyboardHandler && window.removeEventListener("keydown", this.keyboardHandler, !0), this.holdActivationHandler && (window.removeEventListener("keydown", this.holdActivationHandler), window.removeEventListener("keyup", this.holdActivationHandler)), this.holdBlurHandler && window.removeEventListener("blur", this.holdBlurHandler), this.toggleHandler && window.removeEventListener("commentkit:toggle-overlay", this.toggleHandler), this.hashChangeHandler && window.removeEventListener("hashchange", this.hashChangeHandler), this.onlineHandler && window.removeEventListener("online", this.onlineHandler), this.offlineHandler && window.removeEventListener("offline", this.offlineHandler)), this.pendingStateUpdates = null, this.flushScheduled = !1, this.activeMutations.clear(), this.offlinePersistUnsub?.(), this.offlinePersistUnsub = null, this.retryTimer &&= (clearTimeout(this.retryTimer), null), this.bootRetryTimer &&= (clearTimeout(this.bootRetryTimer), null), this.disconnectRealtime(!0), this.localDemo?.destroy(), this.sliceSubscribers.clear(), this.removeAllListeners());
3378
+ this.destroyed || (this.destroyed = !0, Gr && (this.keyboardHandler && window.removeEventListener("keydown", this.keyboardHandler, !0), this.holdActivationHandler && (window.removeEventListener("keydown", this.holdActivationHandler), window.removeEventListener("keyup", this.holdActivationHandler)), this.holdBlurHandler && window.removeEventListener("blur", this.holdBlurHandler), this.toggleHandler && window.removeEventListener("commentkit:toggle-overlay", this.toggleHandler), this.hashChangeHandler && window.removeEventListener("hashchange", this.hashChangeHandler), this.onlineHandler && window.removeEventListener("online", this.onlineHandler), this.offlineHandler && window.removeEventListener("offline", this.offlineHandler)), this.pendingStateUpdates = null, this.flushScheduled = !1, this.activeMutations.clear(), this.offlinePersistUnsub?.(), this.offlinePersistUnsub = null, this.retryTimer &&= (clearTimeout(this.retryTimer), null), this.bootRetryTimer &&= (clearTimeout(this.bootRetryTimer), null), this.disconnectRealtime(!0), this.localDemo?.destroy(), this.sliceSubscribers.clear(), this.removeAllListeners());
3081
3379
  }
3082
3380
  };
3083
- export { He as a, A as c, O as d, se as f, le as g, E as h, M as i, j as l, ce as m, Hr as n, Le as o, D as p, Pr as r, Re as s, Kr as t, me as u };
3381
+ export { Ue as a, k as c, D as d, ce as f, ue as g, T as h, j as i, A as l, le as m, Yr as n, Re as o, E as p, Vr as r, ze as s, $r as t, he as u };