@commentkit/comment-kit 0.7.4 → 0.7.6

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 (52) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +3 -3
  3. package/SECURITY.md +1 -1
  4. package/dist/angular.es.js +2 -2
  5. package/dist/comment-kit.es.js +3 -3
  6. package/dist/demo.es.js +24 -15
  7. package/dist/headless.es.js +2 -2
  8. package/dist/preact.es.js +2 -2
  9. package/dist/qwik.qwik.mjs +2 -2
  10. package/dist/react.es.js +2 -2
  11. package/dist/shared/ShadowRootContext-DD6a0QaI.js +11 -0
  12. package/dist/shared/annotation-toolbar-RSrb0Nku.js +1086 -0
  13. package/dist/shared/{attachment-refresh-DmVkfPtl.js → attachment-refresh-CSTYwRW-.js} +3 -3
  14. package/dist/shared/{button-By0hGrJK.js → button-D4GHW6oZ.js} +133 -164
  15. package/dist/shared/{button-group-C285iSkZ.js → button-group-BVR7iT-S.js} +13 -13
  16. package/dist/shared/{comment-drawing-canvas-zIPS1dnW.js → comment-drawing-canvas-DbuXP54N.js} +2 -2
  17. package/dist/shared/{comment-icon-4SQd3nlz.js → comment-icon-D8JTCEJ7.js} +109 -110
  18. package/dist/shared/{comment-image-lightbox-CdMNf0_y.js → comment-image-lightbox-zlIGEVA-.js} +7 -7
  19. package/dist/shared/{comment-images-content-DqeqmQnb.js → comment-images-content-aYbJb79_.js} +38 -38
  20. package/dist/shared/{comment-kit-core-C-0JJS2i.js → comment-kit-core-B0k7XsMz.js} +742 -746
  21. package/dist/shared/{comment-kit-ui-CBaz7L3u.js → comment-kit-ui-BXLJcZYQ.js} +5310 -5718
  22. package/dist/shared/{comment-screenshot-annotator-CuYmKafz.js → comment-screenshot-annotator-ChWwYJzO.js} +2 -2
  23. package/dist/shared/{comment-screenshot-overlay-Dw81osel.js → comment-screenshot-overlay-Bufg3rHz.js} +6 -6
  24. package/dist/shared/{dev-export-panel-D08M2LKD.js → dev-export-panel-DAZenvgD.js} +6 -6
  25. package/dist/shared/{dev-grab-BJLZZ2xU.js → dev-grab-O8q25zar.js} +48 -47
  26. package/dist/shared/dist-D9A5k-N4.js +617 -0
  27. package/dist/shared/{element-selector-Biyn2cpR.js → element-selector-CYkwzfEr.js} +349 -347
  28. package/dist/shared/input-UPtAj0M6.js +111 -0
  29. package/dist/shared/{mount-ui-DXdL3p9b.js → mount-ui-BKaWBhKq.js} +4 -4
  30. package/dist/shared/{pusher-D4M5K6Dk.js → pusher-BUaiCkDJ.js} +1 -1
  31. package/dist/shared/{realtime-BTqYEy8s.js → realtime-C0Z8dXXH.js} +41 -28
  32. package/dist/shared/{realtime-recovery-BSVMwsXJ.js → realtime-recovery-BjlV-ewc.js} +57 -30
  33. package/dist/shared/screenshot-B-ZfFItT.js +199 -0
  34. package/dist/shared/{separator-aphZiRoJ.js → separator-UhJb0Row.js} +1222 -1288
  35. package/dist/shared/{shadow-root-C58Ap5Nu.js → shadow-root-Cd3SLHyj.js} +3 -5
  36. package/dist/shared/{token-session-D0Y_HZw0.js → token-session-DplW5QDx.js} +2 -2
  37. package/dist/shared/useLabelableId-8n0QmH8N.js +154 -0
  38. package/dist/shared/{useRender-D1z_X_BY.js → useRender-Uxk1OPK-.js} +1 -1
  39. package/dist/shared/{useValueChanged-CrzfD8l-.js → useValueChanged-DKq5cMot.js} +13 -13
  40. package/dist/shared/{websocket-manager-BFKa95TO.js → websocket-manager-798cRDyL.js} +2 -2
  41. package/dist/solid.es.js +2 -2
  42. package/dist/svelte.es.js +2 -2
  43. package/dist/types/core/api-client.d.ts +19 -9
  44. package/dist/types/core/comment-kit-core.d.ts +8 -4
  45. package/dist/types/core/types.d.ts +49 -9
  46. package/dist/types/core/write-access.d.ts +2 -0
  47. package/dist/vue.es.js +2 -2
  48. package/docs/api-reference.md +30 -18
  49. package/package.json +1 -1
  50. package/dist/shared/ShadowRootContext-CjciYxVN.js +0 -13
  51. package/dist/shared/annotation-toolbar-CpPKy0oq.js +0 -1094
  52. package/dist/shared/dist-De294MVF.js +0 -623
@@ -31,6 +31,9 @@ var b = "https://api.commentkit.dev/api", te = 3e4, ne = 10485760, re = 10, ie =
31
31
  auth_failed: "Sign-in failed. Please check your email and try again.",
32
32
  otp_cooldown: "A code was sent recently — please wait a minute before requesting another.",
33
33
  otp_not_found: "No verification code found. Request a new one.",
34
+ mfa_invalid: "Incorrect authenticator or recovery code. Try again.",
35
+ mfa_expired: "This sign-in attempt expired. Start again with your email.",
36
+ mfa_max_attempts: "Too many incorrect codes. Start again with your email.",
34
37
  otp_expired: "That verification code has expired. Request a new one.",
35
38
  otp_max_attempts: "Too many incorrect attempts. Request a new code.",
36
39
  otp_invalid: "Incorrect verification code. Please try again.",
@@ -40,7 +43,7 @@ var b = "https://api.commentkit.dev/api", te = 3e4, ne = 10485760, re = 10, ie =
40
43
  };
41
44
  function fe(e, t) {
42
45
  let n = {};
43
- 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) => ({
46
+ 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.checklistPatch !== void 0 && (n.checklist_patch = e.checklistPatch), e.checklist !== void 0 && (n.checklist = e.checklist.map((e) => ({
44
47
  ...e,
45
48
  id: /^\d+$/.test(e.id) ? Number(e.id) : null
46
49
  }))), 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;
@@ -56,40 +59,40 @@ function me(e) {
56
59
  if (e.protocol !== "https:" && e.protocol !== "http:") throw Error("unsupported protocol");
57
60
  if (e.protocol === "http:" && !pe(e.hostname)) throw Error("insecure protocol");
58
61
  } catch {
59
- throw new T("invalid_base_url", "Invalid API base URL", 400);
62
+ throw new E("invalid_base_url", "Invalid API base URL", 400);
60
63
  }
61
64
  return t;
62
65
  }
63
66
  function S(e) {
64
67
  let t = String(e).trim();
65
- if (!t || a(t)) throw new T("invalid_id", "Invalid identifier", 400);
68
+ if (!t || a(t)) throw new E("invalid_id", "Invalid identifier", 400);
66
69
  return encodeURIComponent(t);
67
70
  }
68
- function he(e) {
69
- if (typeof e != "string" || a(e)) throw new T("invalid_email", "A valid email address is required", 400);
71
+ function C(e) {
72
+ if (typeof e != "string" || a(e)) throw new E("invalid_email", "A valid email address is required", 400);
70
73
  let t = e.trim();
71
- if (!s(t, oe)) throw new T("invalid_email", "A valid email address is required", 400);
74
+ if (!s(t, oe)) throw new E("invalid_email", "A valid email address is required", 400);
72
75
  return t;
73
76
  }
74
- function ge(e) {
75
- if (a(e)) throw new T("invalid_otp", "A valid OTP code is required", 400);
77
+ function he(e) {
78
+ if (a(e)) throw new E("invalid_otp", "A valid OTP code is required", 400);
76
79
  let t = e.trim();
77
- if (t.length !== se || /\s/.test(t)) throw new T("invalid_otp", "A valid OTP code is required", 400);
80
+ if (t.length !== se || /\s/.test(t)) throw new E("invalid_otp", "A valid OTP code is required", 400);
78
81
  return t;
79
82
  }
80
- function _e(e) {
81
- if (a(e)) throw new T("invalid_token", "A valid invite token is required", 400);
83
+ function ge(e) {
84
+ if (a(e)) throw new E("invalid_token", "A valid invite token is required", 400);
82
85
  let t = e.trim();
83
- if (t.length !== 64 || !/^[\w-]+$/.test(t)) throw new T("invalid_token", "A valid invite token is required", 400);
86
+ if (t.length !== 64 || !/^[\w-]+$/.test(t)) throw new E("invalid_token", "A valid invite token is required", 400);
84
87
  return t;
85
88
  }
86
- function C(e, t, n = ie) {
89
+ function w(e, t, n = ie) {
87
90
  let r = e.trim();
88
- if (!r) throw new T("invalid_content", `${t} cannot be empty`, 400);
89
- if (r.length > n) throw new T("content_too_long", `${t} exceeds maximum length of ${n} characters`, 400);
91
+ if (!r) throw new E("invalid_content", `${t} cannot be empty`, 400);
92
+ if (r.length > n) throw new E("content_too_long", `${t} exceeds maximum length of ${n} characters`, 400);
90
93
  return r;
91
94
  }
92
- function ve(e, t) {
95
+ function _e(e, t) {
93
96
  let n = {};
94
97
  for (let [t, r] of Object.entries(o(e) ? e : {}).slice(0, 20)) /^[\w.-]{1,64}$/.test(t) && t !== "__proto__" && t !== "constructor" && t !== "prototype" && (typeof r == "string" ? n[t] = r.slice(0, 200) : typeof r == "number" || typeof r == "boolean" || r === null ? n[t] = r : Array.isArray(r) && (n[t] = 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)));
95
98
  if (o(t)) {
@@ -105,20 +108,20 @@ function ve(e, t) {
105
108
  }
106
109
  return Object.keys(n).length > 0 ? n : void 0;
107
110
  }
108
- var ye = class {
111
+ var ve = class {
109
112
  constructor(e) {
110
- this.projectId = null, this.channelProjectId = null, this.userEmail = null, this.authToken = null, this.authRevision = 0, this.environment = null, this.onAuthExpired = null, this.baseUrl = me(e.baseUrl), this.apiKey = e.apiKey, this.projectId = e.projectId || null, this.channelProjectId = this.projectId, this.environment = e.environment || null;
113
+ this.projectId = null, this.channelProjectId = null, this.userEmail = null, this.authToken = null, this.authRevision = 0, this.pendingInvite = null, this.inviteRevision = 0, this.environment = null, this.onAuthExpired = null, this.baseUrl = me(e.baseUrl), this.apiKey = e.apiKey, this.projectId = e.projectId || null, this.channelProjectId = this.projectId, this.environment = e.environment || null;
111
114
  }
112
115
  setProject(e, t = e) {
113
- this.projectId = String(e).trim(), this.channelProjectId = String(t).trim();
116
+ this.projectId !== String(e).trim() && (this.pendingInvite = null, this.inviteRevision++), this.projectId = String(e).trim(), this.channelProjectId = String(t).trim();
114
117
  }
115
118
  setUserEmail(e) {
116
- this.userEmail = e ? he(e) : null;
119
+ this.userEmail = e ? C(e) : null;
117
120
  }
118
121
  setAuthToken(e) {
119
- if (e && (a(e) || e.length > ce)) throw new T("invalid_token", "A valid auth token is required", 400);
122
+ if (e && (a(e) || e.length > ce)) throw new E("invalid_token", "A valid auth token is required", 400);
120
123
  let t = e?.trim() || null;
121
- this.authToken = t, this.authRevision++;
124
+ this.authToken = t, this.pendingInvite = null, this.inviteRevision++, this.authRevision++;
122
125
  }
123
126
  setEnvironment(e) {
124
127
  this.environment = e;
@@ -127,7 +130,7 @@ var ye = class {
127
130
  this.onAuthExpired = e;
128
131
  }
129
132
  buildHeaders(e) {
130
- if (typeof this.apiKey != "string" || a(this.apiKey)) throw new T("invalid_api_key", "Authentication failed. Please check your API key.", 401);
133
+ if (typeof this.apiKey != "string" || a(this.apiKey)) throw new E("invalid_api_key", "Authentication failed. Please check your API key.", 401);
131
134
  return {
132
135
  "X-API-Key": this.apiKey,
133
136
  ...this.userEmail ? { "X-User-Email": this.userEmail } : {},
@@ -145,19 +148,19 @@ var ye = class {
145
148
  referrerPolicy: "no-referrer",
146
149
  signal: c.signal
147
150
  });
148
- if (s.type === "opaqueredirect" || s.status >= 300 && s.status < 400) throw new T("unexpected_redirect", "The API endpoint redirected. Check the configured API URL before retrying.", 400);
151
+ if (s.type === "opaqueredirect" || s.status >= 300 && s.status < 400) throw new E("unexpected_redirect", "The API endpoint redirected. Check the configured API URL before retrying.", 400);
149
152
  let l = await this.parseResponseBody(s);
150
153
  if (!s.ok) {
151
154
  s.status === 401 && a && i === this.authRevision && (this.setAuthToken(null), this.onAuthExpired?.());
152
155
  let e = o(l) ? l : {}, t = typeof e.error == "string" ? e.error : s.status === 403 ? "unauthorized" : n;
153
- throw new T(t, x[t] ?? r, s.status, ve(e.details, e.quota));
156
+ throw new E(t, x[t] ?? r, s.status, _e(e.details, e.quota));
154
157
  }
155
158
  return l;
156
159
  } catch (e) {
157
- if (e instanceof T) throw e;
158
- if (e instanceof DOMException && e.name === "AbortError") throw new T("timeout", "Request timed out. Please try again.", 408);
159
- if (e instanceof TypeError) throw new T("network_error", "Unable to connect to servers. Please check your connection.", 0);
160
- let t = new T("unknown_error", "An unexpected error occurred", 500);
160
+ if (e instanceof E) throw e;
161
+ if (e instanceof DOMException && e.name === "AbortError") throw new E("timeout", "Request timed out. Please try again.", 408);
162
+ if (e instanceof TypeError) throw new E("network_error", "Unable to connect to servers. Please check your connection.", 0);
163
+ let t = new E("unknown_error", "An unexpected error occurred", 500);
161
164
  throw t.cause = e, t;
162
165
  } finally {
163
166
  clearTimeout(l), s?.();
@@ -170,20 +173,20 @@ var ye = class {
170
173
  let n = await e.text();
171
174
  if (!n) return {};
172
175
  if (t && !t.toLowerCase().includes("application/json")) {
173
- if (e.ok) throw new T("invalid_response", "Invalid server response", 502);
176
+ if (e.ok) throw new E("invalid_response", "Invalid server response", 502);
174
177
  return {};
175
178
  }
176
179
  try {
177
180
  return JSON.parse(n);
178
181
  } catch {
179
- if (e.ok) throw new T("invalid_response", "Invalid server response", 502);
182
+ if (e.ok) throw new E("invalid_response", "Invalid server response", 502);
180
183
  return {};
181
184
  }
182
185
  }
183
186
  if (typeof e.json == "function") try {
184
187
  return await e.json();
185
188
  } catch {
186
- if (e.ok) throw new T("invalid_response", "Invalid server response", 502);
189
+ if (e.ok) throw new E("invalid_response", "Invalid server response", 502);
187
190
  }
188
191
  return {};
189
192
  }
@@ -197,16 +200,16 @@ var ye = class {
197
200
  headers: r
198
201
  }, "request_failed", "An error occurred");
199
202
  }
200
- async requestFormData(e, t) {
201
- let n = `${this.baseUrl}${e}`, r = this.buildHeaders();
202
- return this.executeRequest(n, {
203
+ async requestFormData(e, t, n) {
204
+ let r = `${this.baseUrl}${e}`, i = this.buildHeaders(n);
205
+ return this.executeRequest(r, {
203
206
  method: "POST",
204
- headers: r,
207
+ headers: i,
205
208
  body: t
206
209
  }, "upload_failed", "Upload failed");
207
210
  }
208
211
  requireProjectId() {
209
- if (!this.projectId) throw new T("missing_project_id", "Project ID is required", 400);
212
+ if (!this.projectId) throw new E("missing_project_id", "Project ID is required", 400);
210
213
  return this.projectId;
211
214
  }
212
215
  async validateApiKey() {
@@ -219,8 +222,8 @@ var ye = class {
219
222
  return this.request("/auth/me");
220
223
  }
221
224
  async authorizeChannel(e, t) {
222
- if (!this.authToken) throw new T("unauthorized", x.unauthorized, 401);
223
- if (!/^\d+\.\d+$/.test(e) || a(e) || e.length > 128 || !this.channelProjectId || t !== `presence-project.${this.channelProjectId}`) throw new T("invalid_channel", "Invalid realtime channel request.", 400);
225
+ if (!this.authToken) throw new E("unauthorized", x.unauthorized, 401);
226
+ if (!/^\d+\.\d+$/.test(e) || a(e) || e.length > 128 || !this.channelProjectId || t !== `presence-project.${this.channelProjectId}`) throw new E("invalid_channel", "Invalid realtime channel request.", 400);
224
227
  let n = this.authRevision, r = await this.request("/broadcasting/auth", {
225
228
  method: "POST",
226
229
  body: JSON.stringify({
@@ -228,29 +231,32 @@ var ye = class {
228
231
  channel_name: t
229
232
  })
230
233
  });
231
- if (n !== this.authRevision) throw new T("unauthorized", x.unauthorized, 401);
232
- if (!o(r) || typeof r.auth != "string" || !r.auth || typeof r.channel_data != "string") throw new T("invalid_response", x.invalid_response, 502);
234
+ if (n !== this.authRevision) throw new E("unauthorized", x.unauthorized, 401);
235
+ if (!o(r) || typeof r.auth != "string" || !r.auth || typeof r.channel_data != "string") throw new E("invalid_response", x.invalid_response, 502);
233
236
  let i;
234
237
  try {
235
238
  i = JSON.parse(r.channel_data);
236
239
  } catch {
237
- throw new T("invalid_response", x.invalid_response, 502);
240
+ throw new E("invalid_response", x.invalid_response, 502);
238
241
  }
239
- if (!o(i) || !i.user_id) throw new T("invalid_response", x.invalid_response, 502);
242
+ if (!o(i) || !i.user_id) throw new E("invalid_response", x.invalid_response, 502);
240
243
  return {
241
244
  auth: r.auth,
242
245
  channel_data: r.channel_data
243
246
  };
244
247
  }
245
248
  async requestOtp(e) {
246
- let t = he(e);
249
+ let t = C(e);
247
250
  return this.request("/auth/otp/request", {
248
251
  method: "POST",
249
- body: JSON.stringify({ email: t })
252
+ body: JSON.stringify({
253
+ email: t,
254
+ ...this.pendingInvite?.email === t ? { invitation_challenge: this.pendingInvite.challenge } : {}
255
+ })
250
256
  });
251
257
  }
252
258
  async verifyOtp(e, t) {
253
- let n = he(e), r = ge(t);
259
+ let n = C(e), r = he(t);
254
260
  return this.request("/auth/otp/verify", {
255
261
  method: "POST",
256
262
  body: JSON.stringify({
@@ -259,41 +265,58 @@ var ye = class {
259
265
  })
260
266
  });
261
267
  }
268
+ async verifyMfa(e, t) {
269
+ if (typeof e != "string" || !/^[0-9]+\|[A-Za-z0-9]{64}$/.test(e) || typeof t != "string" || t.trim().length < 6 || t.trim().length > 100 || a(t)) throw new E("mfa_invalid", "A valid authenticator or recovery code is required.", 400);
270
+ return this.request("/auth/mfa/verify", {
271
+ method: "POST",
272
+ body: JSON.stringify({
273
+ challenge: e,
274
+ code: t.trim()
275
+ })
276
+ });
277
+ }
262
278
  async validateInvite(e, t) {
263
- let n = _e(e), r = he(t);
264
- return this.request("/auth/validate-invite", {
279
+ let n = ge(e), r = C(t);
280
+ this.pendingInvite = null;
281
+ let i = ++this.inviteRevision, a = await this.request("/auth/validate-invite", {
265
282
  method: "POST",
266
283
  body: JSON.stringify({
267
284
  token: n,
268
285
  email: r
269
286
  })
270
287
  });
271
- }
272
- async getComments(e, t = "all", n = 1, r = 50, i, a) {
273
- let o = this.requireProjectId(), s = new URLSearchParams();
274
- e && s.append("page_path", e), t !== "all" && s.append("status", t), i && s.append("environment", i), a && s.append("branch", a);
275
- 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;
276
- s.append("page", String(c)), s.append("limit", String(l));
277
- let u = s.toString(), d = `/projects/${S(o)}/comments${u ? `?${u}` : ""}`, f = await this.request(d), p = f.comments ?? [];
288
+ return i === this.inviteRevision && a.success && a.invitationChallenge && (this.pendingInvite = {
289
+ email: r,
290
+ challenge: a.invitationChallenge
291
+ }), a;
292
+ }
293
+ async getComments(e, t = "all", n = 1, r = 50, i, a, o) {
294
+ let s = this.requireProjectId(), c = new URLSearchParams();
295
+ e && c.append("page_path", e), t !== "all" && c.append("status", t), i && c.append("environment", i), a && c.append("branch", a);
296
+ let l = Number.isFinite(n) ? Math.max(1, Math.floor(n)) : 1, u = Number.isFinite(r) ? Math.min(100, Math.max(1, Math.floor(r))) : 50;
297
+ c.append("page", String(l)), c.append("limit", String(u)), o?.pagination && c.set("pagination", o.pagination), o?.view && c.set("view", o.view), o?.cursor && c.set("cursor", o.cursor), o?.search?.trim() && c.set("search", o.search.trim().slice(0, 200)), o?.priority && o.priority !== "all" && c.set("priority", o.priority), o?.user && c.set("user", o.user), o?.assignee && o.assignee !== "all" && c.set("assignee", o.assignee), o?.sort && c.set("sort", o.sort), o?.excludeComplete && c.set("exclude_complete", "1");
298
+ let d = c.toString(), f = `/projects/${S(s)}/comments${d ? `?${d}` : ""}`, p = await this.request(f), m = p.comments ?? [];
278
299
  return {
279
- comments: p,
280
- pagination: f.pagination ?? {
281
- total: p.length,
282
- hasMore: p.length >= l,
283
- page: c,
284
- limit: l
300
+ comments: m,
301
+ pagination: p.pagination ?? {
302
+ total: m.length,
303
+ hasMore: m.length >= u,
304
+ page: l,
305
+ limit: u
285
306
  }
286
307
  };
287
308
  }
288
- async getComment(e) {
289
- let t = this.requireProjectId();
290
- return (await this.request(`/projects/${S(t)}/comments/${S(e)}`)).comment;
309
+ async getComment(e, t) {
310
+ let n = this.requireProjectId(), r = new URLSearchParams();
311
+ t?.repliesLimit && r.set("replies_limit", String(Math.min(100, Math.max(1, Math.floor(t.repliesLimit))))), t?.repliesBefore && r.set("replies_before", t.repliesBefore);
312
+ let i = r.size ? `?${r}` : "";
313
+ return (await this.request(`/projects/${S(n)}/comments/${S(e)}${i}`)).comment;
291
314
  }
292
315
  idempotencyHeaders(e) {
293
316
  return typeof e == "string" && e.length > 0 && e.length <= 256 && !a(e) ? { "Idempotency-Key": e } : {};
294
317
  }
295
318
  async createComment(e, t, n, r, i = "medium", a, o, s, c) {
296
- let l = C(t, "Comment content"), u = this.requireProjectId(), d = s?.mentions ?? w(l);
319
+ let l = w(t, "Comment content"), u = this.requireProjectId(), d = s?.mentions ?? T(l);
297
320
  return (await this.request(`/projects/${S(u)}/comments`, {
298
321
  method: "POST",
299
322
  headers: this.idempotencyHeaders(c),
@@ -320,7 +343,7 @@ var ye = class {
320
343
  })).comment;
321
344
  }
322
345
  async updateComment(e, t) {
323
- let n = this.requireProjectId(), r = t.content === void 0 ? void 0 : C(t.content, "Comment content"), i = t.mentions ?? (r ? w(r) : void 0), a = fe({
346
+ 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 = fe({
324
347
  ...t,
325
348
  ...r === void 0 ? {} : { content: r }
326
349
  }, i);
@@ -334,7 +357,7 @@ var ye = class {
334
357
  await this.request(`/projects/${S(t)}/comments/${S(e)}`, { method: "DELETE" });
335
358
  }
336
359
  async addReply(e, t, n, r) {
337
- let i = this.requireProjectId(), a = C(t, "Reply content", ae), o = r?.mentions ?? w(a);
360
+ let i = this.requireProjectId(), a = w(t, "Reply content", ae), o = r?.mentions ?? T(a);
338
361
  return (await this.request(`/projects/${S(i)}/comments/${S(e)}/replies`, {
339
362
  method: "POST",
340
363
  headers: this.idempotencyHeaders(n),
@@ -347,7 +370,7 @@ var ye = class {
347
370
  })).reply;
348
371
  }
349
372
  async updateReply(e, t, n, r) {
350
- let i = this.requireProjectId(), a = C(n, "Reply content", ae);
373
+ let i = this.requireProjectId(), a = w(n, "Reply content", ae);
351
374
  return (await this.request(`/projects/${S(i)}/comments/${S(e)}/replies/${S(t)}`, {
352
375
  method: "PUT",
353
376
  body: JSON.stringify({
@@ -411,15 +434,15 @@ var ye = class {
411
434
  return this.createComment("drawing", e, n, r, "medium", void 0, t, a, i);
412
435
  }
413
436
  validateFile(e, t = !1) {
414
- if (e.size > ne) throw new T("file_too_large", `File size (${Math.round(e.size / 1024 / 1024)}MB) exceeds maximum of ${ne / 1024 / 1024}MB`, 400);
415
- if (a(e.name) || e.name.includes("/") || e.name.includes("\\")) throw new T("invalid_filename", "Filename contains invalid characters", 400);
437
+ if (e.size > ne) throw new E("file_too_large", `File size (${Math.round(e.size / 1024 / 1024)}MB) exceeds maximum of ${ne / 1024 / 1024}MB`, 400);
438
+ if (a(e.name) || e.name.includes("/") || e.name.includes("\\")) throw new E("invalid_filename", "Filename contains invalid characters", 400);
416
439
  if (t) {
417
440
  /* v8 ignore next -- pop() always returns a value since file has a name */
418
441
  let t = "." + (e.name.split(".").pop()?.toLowerCase() ?? "");
419
- if ((e.name.match(/\./g) || []).length > 1) throw new T("invalid_filename", "Filenames with multiple extensions are not allowed", 400);
420
- if (!ue.includes(e.type) || !le.includes(t)) throw new T("invalid_file_type", `Only image files are allowed (${le.join(", ")})`, 400);
442
+ if ((e.name.match(/\./g) || []).length > 1) throw new E("invalid_filename", "Filenames with multiple extensions are not allowed", 400);
443
+ if (!ue.includes(e.type) || !le.includes(t)) throw new E("invalid_file_type", `Only image files are allowed (${le.join(", ")})`, 400);
421
444
  }
422
- if (u(e.name)) throw new T("invalid_file_type", "This file type is not allowed", 400);
445
+ if (u(e.name)) throw new E("invalid_file_type", "This file type is not allowed", 400);
423
446
  }
424
447
  async uploadFile(e, t, n) {
425
448
  this.validateFile(e, t === "screenshot" || t === "drawing");
@@ -438,12 +461,12 @@ var ye = class {
438
461
  }
439
462
  async uploadScreenshot(e, t) {
440
463
  this.validateFile(e, !0);
441
- let n = C(t.content, "Screenshot comment"), r = this.requireProjectId(), i = new FormData();
464
+ let n = w(t.content, "Screenshot comment"), r = this.requireProjectId(), i = new FormData();
442
465
  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));
443
- return (await this.requestFormData(`/projects/${S(r)}/screenshots`, i)).comment;
466
+ return (await this.requestFormData(`/projects/${S(r)}/screenshots`, i, this.idempotencyHeaders(t.idempotencyKey))).comment;
444
467
  }
445
468
  async uploadFiles(e, t) {
446
- if (e.length > re) throw new T("too_many_files", `Cannot upload more than ${re} files at once`, 400);
469
+ if (e.length > re) throw new E("too_many_files", `Cannot upload more than ${re} files at once`, 400);
447
470
  let n = await Promise.allSettled(e.map((e) => {
448
471
  /* v8 ignore next -- pop() always returns a value since file has a name */
449
472
  let n = "." + (e.name.split(".").pop()?.toLowerCase() ?? ""), r = ue.includes(e.type) && le.includes(n);
@@ -451,10 +474,10 @@ var ye = class {
451
474
  })), r = n.filter((e) => e.status === "fulfilled").map((e) => e.value.id), i = n.find((e) => e.status === "rejected");
452
475
  if (i) {
453
476
  let e = i.reason;
454
- throw e instanceof T ? new T(e.error, e.message, e.code, {
477
+ throw e instanceof E ? new E(e.error, e.message, e.code, {
455
478
  ...e.details,
456
479
  uploadedIds: r
457
- }) : new T("upload_failed", "Upload failed", 0, { uploadedIds: r });
480
+ }) : new E("upload_failed", "Upload failed", 0, { uploadedIds: r });
458
481
  }
459
482
  return r;
460
483
  }
@@ -467,7 +490,7 @@ var ye = class {
467
490
  return (await this.request(`/projects/${S(e)}/members`)).members ?? [];
468
491
  }
469
492
  };
470
- function w(e) {
493
+ function T(e) {
471
494
  let t = [], n;
472
495
  for (de.lastIndex = 0; (n = de.exec(e)) !== null;) {
473
496
  let e = n[1]?.trim(), r = n[2]?.trim();
@@ -479,13 +502,13 @@ function w(e) {
479
502
  }
480
503
  return t;
481
504
  }
482
- function be(e) {
505
+ function ye(e) {
483
506
  return `@[${e.name.replace(/\]/g, "")}](${e.id.replace(/\)/g, "")})`;
484
507
  }
485
- function xe(e) {
508
+ function be(e) {
486
509
  return e.replace(de, "@$1");
487
510
  }
488
- var T = class extends Error {
511
+ var E = class extends Error {
489
512
  constructor(e, t, n, r) {
490
513
  super(t), this.name = "ApiClientError", this.error = e, this.code = n, this.details = r;
491
514
  }
@@ -501,19 +524,19 @@ var T = class extends Error {
501
524
  isPremiumFeatureError() {
502
525
  return this.code === 402;
503
526
  }
504
- }, E = null, Se = 0, Ce = 3;
505
- function we() {
506
- return E || (E = (async () => {
527
+ }, D = null, xe = 0, Se = 3;
528
+ function Ce() {
529
+ return D || (D = (async () => {
507
530
  try {
508
531
  let e = await import("element-source");
509
532
  return typeof e?.resolveElementInfo == "function" ? e : null;
510
533
  } catch {
511
- return Se += 1, Se < Ce && (E = null), null;
534
+ return xe += 1, xe < Se && (D = null), null;
512
535
  }
513
- })(), E);
536
+ })(), D);
514
537
  }
515
- async function Te(e) {
516
- let t = await we();
538
+ async function we(e) {
539
+ let t = await Ce();
517
540
  if (!t) return null;
518
541
  try {
519
542
  return await t.resolveElementInfo(e);
@@ -521,27 +544,27 @@ async function Te(e) {
521
544
  return null;
522
545
  }
523
546
  }
524
- var Ee = 200, De = 500, Oe = 500, ke = 2e3, Ae = "application/x-commentkit-agent-context", je = "Address the UI feedback in this context.";
525
- function Me(e) {
547
+ var Te = 200, Ee = 500, De = 500, Oe = 2e3, ke = "application/x-commentkit-agent-context", Ae = "Address the UI feedback in this context.";
548
+ function je(e) {
526
549
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
527
550
  }
528
- function Ne(e) {
529
- return e === void 0 ? Ee : !Number.isFinite(e) || e <= 0 ? 0 : Math.min(De, Math.floor(e));
551
+ function Me(e) {
552
+ return e === void 0 ? Te : !Number.isFinite(e) || e <= 0 ? 0 : Math.min(Ee, Math.floor(e));
530
553
  }
531
- function Pe(e) {
554
+ function Ne(e) {
532
555
  return {
533
556
  id: e.id,
534
557
  name: e.name,
535
558
  email: e.email
536
559
  };
537
560
  }
538
- function Fe(e, t) {
561
+ function Pe(e, t) {
539
562
  return e.page.path === t.path || e.page.url === t.url;
540
563
  }
541
- function Ie(e, t, n, r) {
542
- return !(!n.includeResolved && e.status !== "open" || n.currentPageOnly && !Fe(e, t) || r && !r.has(e.id));
564
+ function Fe(e, t, n, r) {
565
+ return !(!n.includeResolved && e.status !== "open" || n.currentPageOnly && !Pe(e, t) || r && !r.has(e.id));
543
566
  }
544
- function Le(e) {
567
+ function Ie(e) {
545
568
  let t = e.getBoundingClientRect();
546
569
  return {
547
570
  top: t.top,
@@ -550,7 +573,7 @@ function Le(e) {
550
573
  height: t.height
551
574
  };
552
575
  }
553
- function Re(e, t, n) {
576
+ function Le(e, t, n) {
554
577
  let r = n ? p(e.element ?? "", e.xpath) : null, i = {
555
578
  ...e.element ? { selector: e.element } : {},
556
579
  ...e.xpath ? { xpath: e.xpath } : {}
@@ -559,7 +582,7 @@ function Re(e, t, n) {
559
582
  ...i,
560
583
  found: !1
561
584
  };
562
- let a = h(r), o = y(a.text, Oe), s = t ? y(a.html, ke) : "", c = r.getAttribute("class"), l = r.getAttribute("role"), u = r.getAttribute("aria-label");
585
+ let a = h(r), o = y(a.text, De), s = t ? y(a.html, Oe) : "", c = r.getAttribute("class"), l = r.getAttribute("role"), u = r.getAttribute("aria-label");
563
586
  return {
564
587
  ...i,
565
588
  found: !0,
@@ -569,28 +592,28 @@ function Re(e, t, n) {
569
592
  ...l ? { role: l } : {},
570
593
  ...u ? { ariaLabel: u } : {},
571
594
  ...o ? { text: o } : {},
572
- rect: Le(r),
595
+ rect: Ie(r),
573
596
  ...s ? { htmlPreview: s } : {}
574
597
  };
575
598
  }
576
- function ze(e) {
599
+ function Re(e) {
577
600
  return {
578
601
  id: e.id,
579
602
  content: e.content,
580
- author: Pe(e.author),
603
+ author: Ne(e.author),
581
604
  createdAt: e.createdAt,
582
605
  isEdited: e.isEdited,
583
606
  replyTo: e.replyTo,
584
607
  mentions: e.mentions,
585
608
  reactions: e.reactions,
586
- attachments: e.attachments?.map(D)
609
+ attachments: e.attachments?.map(O)
587
610
  };
588
611
  }
589
- function Be(e) {
612
+ function ze(e) {
590
613
  return e && e.length <= 4096 && !/[?#]/.test(e) && /^https?:\/\//i.test(e) && d(e) ? e : void 0;
591
614
  }
592
- function D(e) {
593
- let { id: t, type: n, filename: r, mimeType: i, size: a } = e, o = Be(e.url);
615
+ function O(e) {
616
+ let { id: t, type: n, filename: r, mimeType: i, size: a } = e, o = ze(e.url);
594
617
  return {
595
618
  id: t,
596
619
  type: n,
@@ -600,22 +623,22 @@ function D(e) {
600
623
  ...o ? { url: o } : { inlineContentOmitted: !0 }
601
624
  };
602
625
  }
603
- function Ve(e, t, n) {
604
- let r = e.attachments.map(D), i = r.find((e) => e.type === "screenshot" && e.url)?.url;
626
+ function Be(e, t, n) {
627
+ let r = e.attachments.map(O), i = r.find((e) => e.type === "screenshot" && e.url)?.url;
605
628
  return {
606
629
  id: e.id,
607
630
  type: e.type,
608
631
  status: e.status,
609
632
  priority: e.priority,
610
633
  content: e.content,
611
- author: Pe(e.author),
634
+ author: Ne(e.author),
612
635
  createdAt: e.createdAt,
613
636
  updatedAt: e.updatedAt,
614
637
  environment: e.environment,
615
638
  branch: e.branch,
616
639
  deviceInfo: e.deviceInfo,
617
640
  description: e.description,
618
- assignees: e.assignees?.map(Pe),
641
+ assignees: e.assignees?.map(Ne),
619
642
  mentions: e.mentions,
620
643
  checklist: e.checklist,
621
644
  reactions: e.reactions,
@@ -631,12 +654,13 @@ function Ve(e, t, n) {
631
654
  textSelection: e.textSelection,
632
655
  drawingData: e.drawingData,
633
656
  attachments: r,
634
- element: Re(e.position, t.includeHtml === !0, Fe(e, n)),
657
+ element: Le(e.position, t.includeHtml === !0, Pe(e, n)),
635
658
  ...i ? { screenshotUrl: i } : {},
636
- replies: e.replies.map(ze)
659
+ repliesCount: e.repliesCount ?? e.replies.length,
660
+ replies: e.replies.map(Re)
637
661
  };
638
662
  }
639
- function He(e) {
663
+ function Ve(e) {
640
664
  return {
641
665
  filePath: e.filePath,
642
666
  lineNumber: e.lineNumber,
@@ -644,16 +668,16 @@ function He(e) {
644
668
  componentName: e.componentName
645
669
  };
646
670
  }
647
- function O(e, t = {}) {
671
+ function k(e, t = {}) {
648
672
  let n = m(), r = {
649
673
  url: n.url,
650
674
  path: n.path,
651
675
  title: n.title
652
- }, i = t.commentIds?.length ? new Set(t.commentIds) : null, a = Ne(t.maxComments), o = e.comments.filter((e) => Ie(e, r, t, i)), s = o.slice(0, a).map((e) => Ve(e, t, r));
676
+ }, i = t.commentIds?.length ? new Set(t.commentIds) : null, a = Me(t.maxComments), o = e.comments.filter((e) => Fe(e, r, t, i)), s = o.slice(0, a).map((e) => Be(e, t, r));
653
677
  return {
654
678
  version: 1,
655
679
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
656
- instructions: v(t.instructions, 2e3) || je,
680
+ instructions: v(t.instructions, 2e3) || Ae,
657
681
  page: {
658
682
  ...r,
659
683
  url: _(r.url),
@@ -678,15 +702,15 @@ function O(e, t = {}) {
678
702
  sourceResolved: !1
679
703
  };
680
704
  }
681
- async function Ue(e) {
705
+ async function He(e) {
682
706
  let t = !1, n = await Promise.all(e.comments.map(async (e) => {
683
707
  if (!e.element.found) return e;
684
708
  let n = p(e.element.selector ?? "", e.element.xpath);
685
709
  if (!n || g(n)) return e;
686
- let r = await Te(n);
710
+ let r = await we(n);
687
711
  if (!r || !r.source) return e;
688
712
  t = !0;
689
- let i = He(r.source), a = r.stack.map(He), o = r.componentName ?? void 0;
713
+ let i = Ve(r.source), a = r.stack.map(Ve), o = r.componentName ?? void 0;
690
714
  return {
691
715
  ...e,
692
716
  element: {
@@ -703,8 +727,8 @@ async function Ue(e) {
703
727
  sourceResolved: t
704
728
  };
705
729
  }
706
- function k(e) {
707
- let t = We(e);
730
+ function A(e) {
731
+ let t = Ue(e);
708
732
  return [
709
733
  "# CommentKit Agent Context",
710
734
  "",
@@ -720,7 +744,7 @@ function k(e) {
720
744
  "```"
721
745
  ].join("\n");
722
746
  }
723
- function We(e) {
747
+ function Ue(e) {
724
748
  let t = 2e3, n = (e) => e.length > t ? `${e.slice(0, t)}… [clipped]` : e;
725
749
  return {
726
750
  version: e.version,
@@ -769,7 +793,7 @@ function We(e) {
769
793
  width: e.width,
770
794
  height: e.height,
771
795
  ...e.text ? { text: y(e.text, 200) } : {},
772
- ...e.d ? { bounds: Ge(e.d) } : {}
796
+ ...e.d ? { bounds: We(e.d) } : {}
773
797
  })),
774
798
  ...e.drawingData.paths.length > 12 ? { omittedPaths: e.drawingData.paths.length - 12 } : {}
775
799
  } } : {},
@@ -778,9 +802,9 @@ function We(e) {
778
802
  label: e,
779
803
  done: t
780
804
  })) } : {},
781
- ...e.attachments?.length ? { attachments: e.attachments.map(D) } : {},
782
- replyCount: e.replies.length,
783
- ...e.replies.length > 12 ? { omittedReplies: e.replies.length - 12 } : {},
805
+ ...e.attachments?.length ? { attachments: e.attachments.map(O) } : {},
806
+ replyCount: e.repliesCount ?? e.replies.length,
807
+ ...(e.repliesCount ?? e.replies.length) > Math.min(12, e.replies.length) ? { omittedReplies: (e.repliesCount ?? e.replies.length) - Math.min(12, e.replies.length) } : {},
784
808
  replies: e.replies.slice(-12).map((e) => ({
785
809
  id: e.id,
786
810
  content: n(e.content),
@@ -790,12 +814,12 @@ function We(e) {
790
814
  type: e.replyTo.type,
791
815
  body: e.replyTo.body
792
816
  } } : {},
793
- ...e.attachments?.length ? { attachments: e.attachments.map(D) } : {}
817
+ ...e.attachments?.length ? { attachments: e.attachments.map(O) } : {}
794
818
  }))
795
819
  }))
796
820
  };
797
821
  }
798
- function Ge(e) {
822
+ function We(e) {
799
823
  let t = [...e.matchAll(/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/gi)];
800
824
  if (!t.length) return null;
801
825
  let n = t.map((e) => Number(e[1])), r = t.map((e) => Number(e[2]));
@@ -806,18 +830,18 @@ function Ge(e) {
806
830
  height: Math.max(...r) - Math.min(...r)
807
831
  };
808
832
  }
809
- function Ke(e) {
833
+ function Ge(e) {
810
834
  return {
811
835
  version: e?.version ?? 1,
812
836
  generatedAt: e?.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
813
837
  commentCount: e?.comments.length ?? 0,
814
- context: e ? We(e) : null
838
+ context: e ? Ue(e) : null
815
839
  };
816
840
  }
817
- function qe(e, t) {
841
+ function Ke(e, t) {
818
842
  if (typeof document > "u" || !document.body || typeof document.execCommand != "function") return !1;
819
843
  let n = JSON.stringify(t), r = (t) => {
820
- t.preventDefault(), t.clipboardData?.setData("text/plain", e), t.clipboardData?.setData("text/html", `<meta charset="utf-8"><pre><code>${Me(e)}</code></pre>`), t.clipboardData?.setData(Ae, n);
844
+ t.preventDefault(), t.clipboardData?.setData("text/plain", e), t.clipboardData?.setData("text/html", `<meta charset="utf-8"><pre><code>${je(e)}</code></pre>`), t.clipboardData?.setData(ke, n);
821
845
  }, i = document.createElement("textarea");
822
846
  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();
823
847
  try {
@@ -826,10 +850,10 @@ function qe(e, t) {
826
850
  document.removeEventListener("copy", r), i.remove();
827
851
  }
828
852
  }
829
- async function Je(e, t) {
853
+ async function qe(e, t) {
830
854
  if (typeof navigator > "u" || typeof navigator.clipboard?.write != "function" || typeof ClipboardItem > "u") return !1;
831
855
  try {
832
- let n = new Blob([`<meta charset="utf-8"><pre><code>${Me(e)}</code></pre>`], { type: "text/html" }), r = new Blob([e], { type: "text/plain" }), i = t.type && t.type.startsWith("image/") ? t.type : "image/png";
856
+ let n = new Blob([`<meta charset="utf-8"><pre><code>${je(e)}</code></pre>`], { type: "text/html" }), r = new Blob([e], { type: "text/plain" }), i = t.type && t.type.startsWith("image/") ? t.type : "image/png";
833
857
  return await navigator.clipboard.write([new ClipboardItem({
834
858
  "text/plain": r,
835
859
  "text/html": n,
@@ -839,43 +863,45 @@ async function Je(e, t) {
839
863
  return !1;
840
864
  }
841
865
  }
842
- async function Ye(e, t) {
843
- return t && await Je(e, t) ? !0 : (await Xe(e), !1);
866
+ async function Je(e, t) {
867
+ return t && await qe(e, t) ? !0 : (await Ye(e), !1);
844
868
  }
845
- async function Xe(e, t = null) {
846
- if (!qe(e, Ke(t))) {
869
+ async function Ye(e, t = null) {
870
+ if (!Ke(e, Ge(t))) {
847
871
  if (typeof navigator < "u" && typeof navigator.clipboard?.writeText == "function") await navigator.clipboard.writeText(e);
848
872
  else throw Error("Clipboard is unavailable");
849
873
  }
850
874
  }
851
- function Ze(e, t, n = null) {
875
+ function Xe(e, t, n = null) {
852
876
  let r = t.projectContext, i = n ?? (r?.permissions.canWriteComments === !1 ? r.permissions.writeRestriction ?? (r.organization?.plan === "none" ? "plan_required" : "feature_disabled") : null), a = i === "plan_required", o = !i && e.features?.comments !== !1;
853
877
  return {
854
878
  canWrite: o,
855
879
  canManageComments: o && (r?.permissions.canManageComments ?? !1),
880
+ canTriage: o ? r?.permissions.canTriage : !1,
881
+ canComplete: o && r?.permissions.canComplete !== !1,
856
882
  planRequired: a,
857
883
  message: o ? "" : a ? "This workspace is read-only. An active plan is required to add or change feedback. You can still read and export comments." : "Comment changes are disabled for this project. You can still read and export comments."
858
884
  };
859
885
  }
860
- function A() {
886
+ function j() {
861
887
  for (let e of document.querySelectorAll("dialog:modal,[aria-modal=true]:is(dialog,[role$=dialog])")) if (e.getClientRects().length && getComputedStyle(e).visibility === "visible") return !0;
862
888
  return !1;
863
889
  }
864
- var Qe = 100, $e = () => {};
865
- function et(e) {
890
+ var Ze = 100, Qe = () => {};
891
+ function $e(e) {
866
892
  return typeof e == "function";
867
893
  }
868
- var tt = class {
894
+ var et = class {
869
895
  constructor() {
870
896
  this.listeners = /* @__PURE__ */ new Map(), this.onceWrappers = /* @__PURE__ */ new Map();
871
897
  }
872
898
  on(e, t) {
873
- if (!et(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), $e;
899
+ if (!$e(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), Qe;
874
900
  let n = this.listeners.get(e);
875
- return n || (n = /* @__PURE__ */ new Set(), this.listeners.set(e, n)), !n.has(t) && n.size >= Qe && console.warn(`[CommentKit] Max listeners (${Qe}) reached for '${String(e)}' - possible memory leak`), n.add(t), () => this.off(e, t);
901
+ 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);
876
902
  }
877
903
  off(e, t) {
878
- if (!et(t)) return;
904
+ if (!$e(t)) return;
879
905
  let n = this.listeners.get(e);
880
906
  if (n) {
881
907
  n.delete(t);
@@ -892,7 +918,7 @@ var tt = class {
892
918
  }
893
919
  }
894
920
  once(e, t) {
895
- if (!et(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), $e;
921
+ if (!$e(t)) return console.warn(`[CommentKit] Ignoring non-function listener for '${String(e)}'`), Qe;
896
922
  let n = (n) => {
897
923
  this.off(e, t), t(n);
898
924
  }, r = this.onceWrappers.get(e);
@@ -904,7 +930,7 @@ var tt = class {
904
930
  listenerCount(e) {
905
931
  return this.listeners.get(e)?.size ?? 0;
906
932
  }
907
- }, nt = Symbol(), j = Object.freeze({
933
+ }, tt = Symbol(), M = Object.freeze({
908
934
  ID: 256,
909
935
  CONTENT: 1e4,
910
936
  REPLY_CONTENT: 5e3,
@@ -929,39 +955,39 @@ var tt = class {
929
955
  REACTION_COUNT: 1e6,
930
956
  PENDING_MUTATIONS: 1e3,
931
957
  RETRY_DELAY: 3e4
932
- }), rt = "commentkit:session:", it = 4096;
933
- function at() {
958
+ }), nt = "commentkit:session:", rt = 4096;
959
+ function it() {
934
960
  try {
935
961
  return typeof sessionStorage > "u" ? null : sessionStorage;
936
962
  } catch {
937
963
  return null;
938
964
  }
939
965
  }
940
- function M(e) {
941
- return `${rt}${e}`;
966
+ function N(e) {
967
+ return `${nt}${e}`;
942
968
  }
943
- function ot(e) {
944
- return o(e) && r(e.id, j.ID) && r(e.name, j.NAME) && typeof e.email == "string" && s(e.email, j.EMAIL);
969
+ function at(e) {
970
+ return o(e) && r(e.id, M.ID) && r(e.name, M.NAME) && typeof e.email == "string" && s(e.email, M.EMAIL);
945
971
  }
946
- function st(e) {
947
- return o(e) && r(e.token, it) && typeof e.email == "string" && s(e.email, j.EMAIL) && ot(e.user);
972
+ function ot(e) {
973
+ return o(e) && r(e.token, rt) && typeof e.email == "string" && s(e.email, M.EMAIL) && at(e.user);
948
974
  }
949
- function ct(e, t) {
975
+ function st(e, t) {
950
976
  if (!e) return;
951
- let n = at();
977
+ let n = it();
952
978
  if (n) try {
953
- n.setItem(M(e), JSON.stringify(t));
979
+ n.setItem(N(e), JSON.stringify(t));
954
980
  } catch {}
955
981
  }
956
- function lt(e) {
982
+ function ct(e) {
957
983
  if (!e) return null;
958
- let t = at();
984
+ let t = it();
959
985
  if (!t) return null;
960
986
  try {
961
- let n = t.getItem(M(e));
987
+ let n = t.getItem(N(e));
962
988
  if (!n) return null;
963
989
  let r = JSON.parse(n);
964
- return st(r) ? {
990
+ return ot(r) ? {
965
991
  token: r.token.trim(),
966
992
  email: r.email.trim(),
967
993
  user: {
@@ -970,19 +996,19 @@ function lt(e) {
970
996
  email: r.user.email.trim(),
971
997
  ...r.user.avatar ? { avatar: r.user.avatar } : {}
972
998
  }
973
- } : (t.removeItem(M(e)), null);
999
+ } : (t.removeItem(N(e)), null);
974
1000
  } catch {
975
1001
  return null;
976
1002
  }
977
1003
  }
978
- function ut(e) {
1004
+ function lt(e) {
979
1005
  if (!e) return;
980
- let t = at();
1006
+ let t = it();
981
1007
  if (t) try {
982
- t.removeItem(M(e));
1008
+ t.removeItem(N(e));
983
1009
  } catch {}
984
1010
  }
985
- function dt(e, t) {
1011
+ function ut(e, t) {
986
1012
  for (let n of e.getState().pendingMutations) e.emit("offline:failed", {
987
1013
  id: n.id,
988
1014
  error: {
@@ -992,41 +1018,43 @@ function dt(e, t) {
992
1018
  }
993
1019
  });
994
1020
  }
995
- var ft = j.EMAIL, pt = j.NAME, mt = j.ID, ht = 4096, gt = 6;
996
- function _t(e) {
1021
+ var dt = M.EMAIL, ft = M.NAME, pt = M.ID, mt = 4096, ht = 6;
1022
+ function gt(e) {
997
1023
  if (typeof e != "string") return null;
998
1024
  let t = e.trim();
999
- return s(t, ft) ? t : null;
1025
+ return s(t, dt) ? t : null;
1026
+ }
1027
+ function _t(e) {
1028
+ return !a(e) && e.trim().length === ht;
1000
1029
  }
1001
1030
  function vt(e) {
1002
- return !a(e) && e.trim().length === gt;
1031
+ return o(e) && r(e.id, pt) && r(e.name, ft) && typeof e.email == "string" && gt(e.email) !== null;
1003
1032
  }
1004
1033
  function yt(e) {
1005
- return o(e) && r(e.id, mt) && r(e.name, pt) && typeof e.email == "string" && _t(e.email) !== null;
1006
- }
1007
- function bt(e) {
1008
- return o(e) && r(e.id, mt);
1034
+ return o(e) && r(e.id, pt);
1009
1035
  }
1010
- function N(e, t, n) {
1036
+ function P(e, t, n) {
1011
1037
  return {
1012
1038
  error: e,
1013
1039
  message: t,
1014
1040
  code: n
1015
1041
  };
1016
1042
  }
1017
- async function xt(e, t, n = () => !0) {
1018
- let r = _t(t);
1043
+ async function bt(e, t, n = () => !0) {
1044
+ let r = gt(t);
1019
1045
  if (!r) e.setState({
1020
1046
  isLoading: !1,
1021
1047
  otpStep: "idle",
1022
- otpEmail: null
1023
- }), e.handleError(N("invalid_email", "A valid email address is required", 400));
1048
+ otpEmail: null,
1049
+ otpMfaChallenge: null
1050
+ }), e.handleError(P("invalid_email", "A valid email address is required", 400));
1024
1051
  else try {
1025
1052
  e.setState({
1026
1053
  isLoading: !0,
1027
1054
  error: null,
1028
1055
  otpStep: "requesting",
1029
- otpEmail: r
1056
+ otpEmail: r,
1057
+ otpMfaChallenge: null
1030
1058
  });
1031
1059
  let t = await e.apiClient.requestOtp(r);
1032
1060
  if (!n()) return;
@@ -1039,30 +1067,45 @@ async function xt(e, t, n = () => !0) {
1039
1067
  })) : (e.setState({
1040
1068
  isLoading: !1,
1041
1069
  otpStep: "idle",
1042
- otpEmail: null
1043
- }), e.handleError(N("otp_failed", "Failed to send OTP. Please try again.", 500)));
1070
+ otpEmail: null,
1071
+ otpMfaChallenge: null
1072
+ }), e.handleError(P("otp_failed", "Failed to send OTP. Please try again.", 500)));
1044
1073
  } catch (t) {
1045
1074
  if (!n()) return;
1046
1075
  e.setState({
1047
1076
  isLoading: !1,
1048
1077
  otpStep: "idle",
1049
- otpEmail: null
1078
+ otpEmail: null,
1079
+ otpMfaChallenge: null
1050
1080
  }), e.handleError(t);
1051
1081
  }
1052
1082
  }
1053
- async function St(e, t, n) {
1054
- let { onAuthenticated: i, onWrongOtp: a, onSuccess: o, isCurrent: s = () => !0 } = typeof n == "function" ? { onAuthenticated: n } : n, c = e.getState().otpEmail;
1055
- if (!c) e.handleError(N("no_email", "No OTP request in progress", 400));
1056
- else if (!vt(t)) e.setState({ isLoading: !1 }), e.handleError(N("invalid_otp", "Invalid or expired OTP code", 401));
1083
+ async function xt(e, t, n) {
1084
+ let { onAuthenticated: i, onWrongOtp: o, onSuccess: s, isCurrent: c = () => !0 } = typeof n == "function" ? { onAuthenticated: n } : n, { otpEmail: l, otpMfaChallenge: u, otpStep: d } = e.getState();
1085
+ if (!l) {
1086
+ e.handleError(P("no_email", "No OTP request in progress", 400));
1087
+ return;
1088
+ }
1089
+ let f = d === "mfa";
1090
+ if (!(f ? typeof t == "string" && !a(t) && t.trim().length >= 6 && t.trim().length <= 100 : _t(t)) || f && !u) e.setState({ isLoading: !1 }), e.handleError(P("invalid_otp", "Invalid or expired OTP code", 401));
1057
1091
  else try {
1058
1092
  e.setState({
1059
1093
  isLoading: !0,
1060
1094
  error: null
1061
1095
  });
1062
- let n = await e.apiClient.verifyOtp(c, t);
1063
- if (!s()) return;
1064
- if (n.verified && r(n.token, ht) && yt(n.user) && bt(n.project)) {
1065
- if (e.apiClient.setAuthToken(n.token), e.apiClient.setUserEmail(n.user.email), e.config.persistence !== "memory" && ct(e.config.projectId, {
1096
+ let n = f && u ? await e.apiClient.verifyMfa(u, t.trim()) : await e.apiClient.verifyOtp(l, t);
1097
+ if (!c()) return;
1098
+ if (!f && n.success && n.verified === !1 && n.mfaRequired === !0 && typeof n.challenge == "string" && /^[0-9]+\|[A-Za-z0-9]{64}$/.test(n.challenge)) {
1099
+ e.setState({
1100
+ otpStep: "mfa",
1101
+ otpMfaChallenge: n.challenge,
1102
+ isLoading: !1,
1103
+ error: null
1104
+ });
1105
+ return;
1106
+ }
1107
+ if (n.verified && r(n.token, mt) && vt(n.user) && yt(n.project)) {
1108
+ if (e.apiClient.setAuthToken(n.token), e.apiClient.setUserEmail(n.user.email), e.config.persistence !== "memory" && st(e.config.projectId, {
1066
1109
  token: n.token,
1067
1110
  email: n.user.email,
1068
1111
  user: n.user
@@ -1074,29 +1117,31 @@ async function St(e, t, n) {
1074
1117
  isOverlayVisible: !0,
1075
1118
  isLoading: !1,
1076
1119
  otpStep: "idle",
1077
- otpEmail: null
1078
- }), o?.(), e.emit("auth:otp-verified", n.user), !s() || (e.emit("auth:login", n.user), !s())) return;
1120
+ otpEmail: null,
1121
+ otpMfaChallenge: null
1122
+ }), s?.(), e.emit("auth:otp-verified", n.user), !c() || (e.emit("auth:login", n.user), !c())) return;
1079
1123
  await i();
1080
- } else e.setState({ isLoading: !1 }), a?.(), e.handleError(N("invalid_otp", "Invalid or expired OTP code", 401));
1124
+ } else e.setState({ isLoading: !1 }), o?.(), e.handleError(P("invalid_otp", "Invalid or expired OTP code", 401));
1081
1125
  } catch (t) {
1082
- if (!s()) return;
1126
+ if (!c()) return;
1083
1127
  e.setState({ isLoading: !1 }), e.handleError(t);
1084
1128
  }
1085
1129
  }
1086
- function Ct(e) {
1130
+ function St(e) {
1087
1131
  e.setState({
1088
1132
  otpStep: "idle",
1089
1133
  otpEmail: null,
1134
+ otpMfaChallenge: null,
1090
1135
  error: null,
1091
1136
  isLoading: !1
1092
1137
  });
1093
1138
  }
1094
- async function wt(e, t = () => !0) {
1139
+ async function Ct(e, t = () => !0) {
1095
1140
  let n = e.getState().otpEmail;
1096
- n && await xt(e, n, t);
1141
+ n && await bt(e, n, t);
1097
1142
  }
1098
- function Tt(e, t) {
1099
- dt(e, "Pending offline changes were discarded on logout"), ut(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), t(), e.setState({
1143
+ function wt(e, t) {
1144
+ ut(e, "Pending offline changes were discarded on logout"), lt(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), t(), e.setState({
1100
1145
  isAuthenticated: !1,
1101
1146
  currentUser: null,
1102
1147
  comments: [],
@@ -1114,6 +1159,7 @@ function Tt(e, t) {
1114
1159
  isSidebarVisible: !1,
1115
1160
  otpStep: "idle",
1116
1161
  otpEmail: null,
1162
+ otpMfaChallenge: null,
1117
1163
  pagination: null,
1118
1164
  pendingMutations: [],
1119
1165
  activities: [],
@@ -1124,8 +1170,8 @@ function Tt(e, t) {
1124
1170
  isLoading: !1
1125
1171
  }), e.emit("auth:logout", void 0);
1126
1172
  }
1127
- function Et(e) {
1128
- dt(e, "Pending offline changes were discarded because the session expired"), ut(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), e.setState({
1173
+ function Tt(e) {
1174
+ ut(e, "Pending offline changes were discarded because the session expired"), lt(e.config.projectId), e.apiClient.setUserEmail(null), e.apiClient.setAuthToken(null), e.setState({
1129
1175
  isAuthenticated: !1,
1130
1176
  currentUser: null,
1131
1177
  comments: [],
@@ -1140,6 +1186,9 @@ function Et(e) {
1140
1186
  panelView: "list",
1141
1187
  connectionStatus: "disconnected",
1142
1188
  isLoginModalVisible: !0,
1189
+ otpStep: "idle",
1190
+ otpEmail: null,
1191
+ otpMfaChallenge: null,
1143
1192
  error: "Your session has expired. Please sign in again.",
1144
1193
  isLoading: !1
1145
1194
  }), e.emit("error", {
@@ -1148,44 +1197,45 @@ function Et(e) {
1148
1197
  code: 401
1149
1198
  });
1150
1199
  }
1151
- function Dt(e) {
1200
+ function Et(e) {
1152
1201
  e.setState({ isLoginModalVisible: !e.getState().isLoginModalVisible });
1153
1202
  }
1154
- async function Ot(e, t, n, r = () => !0) {
1203
+ async function Dt(e, t, n, r = () => !0) {
1155
1204
  let i = e.config.inviteToken;
1156
1205
  if (!i) {
1157
- e.handleError(N("no_invite", "No invite token found", 400));
1206
+ e.handleError(P("no_invite", "No invite token found", 400));
1158
1207
  return;
1159
1208
  }
1160
- let a = _t(t);
1161
- if (!a) e.setState({ isLoading: !1 }), e.handleError(N("invalid_email", "A valid email address is required", 400));
1209
+ let a = gt(t);
1210
+ if (!a) e.setState({ isLoading: !1 }), e.handleError(P("invalid_email", "A valid email address is required", 400));
1162
1211
  else try {
1163
1212
  e.setState({
1164
1213
  isLoading: !0,
1165
1214
  error: null
1166
1215
  });
1167
1216
  let t = await e.apiClient.validateInvite(i, a);
1168
- if (!r()) return;
1169
- t.success ? await n(a) : (e.setState({ isLoading: !1 }), e.handleError(N("invite_invalid", "Invite validation failed", 400)));
1217
+ if (t.success && t.accessScope !== "project" && e.config.inviteToken === i && (e.config.inviteToken = void 0), !r()) return;
1218
+ t.success ? await n(a) : (e.setState({ isLoading: !1 }), e.handleError(P("invite_invalid", "Invite validation failed", 400)));
1170
1219
  } catch (t) {
1171
1220
  if (!r()) return;
1172
1221
  e.setState({ isLoading: !1 }), e.handleError(t);
1173
1222
  }
1174
1223
  }
1175
- function P(e) {
1224
+ function F(e) {
1176
1225
  return Object.freeze(e);
1177
1226
  }
1178
- var kt = Object.freeze({
1179
- auth: P([
1227
+ var Ot = Object.freeze({
1228
+ auth: F([
1180
1229
  "isAuthenticated",
1181
1230
  "currentUser",
1182
1231
  "project",
1183
1232
  "projectContext",
1184
1233
  "isLoginModalVisible",
1185
1234
  "otpStep",
1186
- "otpEmail"
1235
+ "otpEmail",
1236
+ "otpMfaChallenge"
1187
1237
  ]),
1188
- ui: P([
1238
+ ui: F([
1189
1239
  "isOverlayVisible",
1190
1240
  "isSidebarVisible",
1191
1241
  "isShortcutsOverlayVisible",
@@ -1203,24 +1253,26 @@ var kt = Object.freeze({
1203
1253
  "isLoading",
1204
1254
  "error"
1205
1255
  ]),
1206
- comments: P([
1256
+ comments: F([
1207
1257
  "comments",
1208
1258
  "pagination",
1209
1259
  "seenThreadIds",
1210
- "activeBranch"
1260
+ "activeBranch",
1261
+ "commentQuery",
1262
+ "loadingThreadId"
1211
1263
  ]),
1212
- realtime: P([
1264
+ realtime: F([
1213
1265
  "onlineUsers",
1214
1266
  "connectionStatus",
1215
1267
  "pendingMutations",
1216
1268
  "isOnline"
1217
1269
  ])
1218
1270
  });
1219
- function At() {
1271
+ function kt() {
1220
1272
  return typeof navigator < "u" && typeof navigator.onLine == "boolean" ? navigator.onLine : !0;
1221
1273
  }
1222
- var jt = 2e3;
1223
- function Mt() {
1274
+ var At = 2e3;
1275
+ function jt() {
1224
1276
  return {
1225
1277
  isAuthenticated: !1,
1226
1278
  isOverlayVisible: !0,
@@ -1236,6 +1288,8 @@ function Mt() {
1236
1288
  projectContext: null,
1237
1289
  activeBranch: null,
1238
1290
  comments: [],
1291
+ commentQuery: void 0,
1292
+ loadingThreadId: null,
1239
1293
  activeTool: null,
1240
1294
  selectedComment: null,
1241
1295
  activeComment: null,
@@ -1250,61 +1304,62 @@ function Mt() {
1250
1304
  error: null,
1251
1305
  otpStep: "idle",
1252
1306
  otpEmail: null,
1307
+ otpMfaChallenge: null,
1253
1308
  pagination: null,
1254
1309
  pendingMutations: [],
1255
- isOnline: At()
1310
+ isOnline: kt()
1256
1311
  };
1257
1312
  }
1258
- function F(e) {
1313
+ function I(e) {
1259
1314
  let t = e.config.branch ?? e.getState().activeBranch;
1260
1315
  if (!(typeof t != "string" || t.length > 255 || a(t))) return t.trim() || void 0;
1261
1316
  }
1262
- var I = j.ID, Nt = j.CONTENT, Pt = j.REPLY_CONTENT, Ft = j.SELECTOR, It = j.TEXT_SELECTION, Lt = j.DESCRIPTION, Rt = j.ASSIGNEES, zt = j.CHECKLIST_ITEMS, Bt = j.CHECKLIST_LABEL, Vt = j.DRAWING_PATHS, Ht = j.DRAWING_PATH_DATA, Ut = j.DRAWING_TEXT, Wt = j.REACTION_COUNT, Gt = j.EMOJI, Kt = /* @__PURE__ */ new Set([
1317
+ var L = M.ID, Mt = M.CONTENT, Nt = M.REPLY_CONTENT, Pt = M.SELECTOR, Ft = M.TEXT_SELECTION, It = M.DESCRIPTION, Lt = M.ASSIGNEES, Rt = M.CHECKLIST_ITEMS, zt = M.CHECKLIST_LABEL, Bt = M.DRAWING_PATHS, Vt = M.DRAWING_PATH_DATA, Ht = M.DRAWING_TEXT, Ut = M.REACTION_COUNT, Wt = M.EMOJI, Gt = /* @__PURE__ */ new Set([
1263
1318
  "pin",
1264
1319
  "highlight",
1265
1320
  "drawing"
1266
- ]), qt = /* @__PURE__ */ new Set([
1321
+ ]), Kt = /* @__PURE__ */ new Set([
1267
1322
  "low",
1268
1323
  "medium",
1269
1324
  "high",
1270
1325
  "urgent"
1271
- ]), Jt = /* @__PURE__ */ new Set([
1326
+ ]), qt = /* @__PURE__ */ new Set([
1272
1327
  "open",
1273
1328
  "resolved",
1274
1329
  "complete"
1275
- ]), Yt = /* @__PURE__ */ new Set([
1330
+ ]), Jt = /* @__PURE__ */ new Set([
1276
1331
  "path",
1277
1332
  "line",
1278
1333
  "rectangle",
1279
1334
  "circle",
1280
1335
  "text"
1281
1336
  ]);
1282
- function L(e, t, n) {
1283
- e.handleError(new T(t, n, 400));
1337
+ function R(e, t, n) {
1338
+ e.handleError(new E(t, n, 400));
1284
1339
  }
1285
- function R(e) {
1286
- return r(e, I);
1340
+ function z(e) {
1341
+ return r(e, L);
1287
1342
  }
1288
- function z(e, t = Nt) {
1343
+ function B(e, t = Mt) {
1289
1344
  if (typeof e != "string") return null;
1290
1345
  let n = e.trim();
1291
1346
  return !n || n.length > t || c(n) ? null : n;
1292
1347
  }
1293
- function B(e, t) {
1348
+ function V(e, t) {
1294
1349
  if (e === void 0) return;
1295
1350
  if (typeof e != "string") return null;
1296
1351
  let n = e.trim();
1297
1352
  return n.length > t || c(n) ? null : n;
1298
1353
  }
1299
- function V(e) {
1354
+ function H(e) {
1300
1355
  if (e === void 0) return;
1301
1356
  if (typeof e != "string") return null;
1302
1357
  let t = e.trim();
1303
- return !t || t.length > Ft || c(t) ? null : t;
1358
+ return !t || t.length > Pt || c(t) ? null : t;
1304
1359
  }
1305
- function Xt(t) {
1360
+ function Yt(t) {
1306
1361
  if (!o(t) || !e(t.x) || !e(t.y)) return null;
1307
- let n = V(t.element), r = V(t.xpath);
1362
+ let n = H(t.element), r = H(t.xpath);
1308
1363
  return n === null || r === null ? null : {
1309
1364
  x: t.x,
1310
1365
  y: t.y,
@@ -1312,10 +1367,10 @@ function Xt(t) {
1312
1367
  ...r === void 0 ? {} : { xpath: r }
1313
1368
  };
1314
1369
  }
1315
- function Zt(e) {
1370
+ function Xt(e) {
1316
1371
  if (!o(e)) return null;
1317
- let t = B(e.avatar, Ft), n = B(e.organizationId, I);
1318
- return !R(e.id) || typeof e.name != "string" || !e.name.trim() || e.name.length > j.NAME || c(e.name) || typeof e.email != "string" || !e.email.trim() || e.email.length > j.EMAIL || /\s/.test(e.email.trim()) || c(e.email) || t === null || n === null ? null : {
1372
+ let t = V(e.avatar, Pt), n = V(e.organizationId, L);
1373
+ return !z(e.id) || typeof e.name != "string" || !e.name.trim() || e.name.length > M.NAME || c(e.name) || typeof e.email != "string" || !e.email.trim() || e.email.length > M.EMAIL || /\s/.test(e.email.trim()) || c(e.email) || t === null || n === null ? null : {
1319
1374
  id: e.id.trim(),
1320
1375
  name: e.name.trim(),
1321
1376
  email: e.email.trim(),
@@ -1323,25 +1378,25 @@ function Zt(e) {
1323
1378
  ...n === void 0 ? {} : { organizationId: n }
1324
1379
  };
1325
1380
  }
1326
- function Qt(e) {
1381
+ function Zt(e) {
1327
1382
  if (e === void 0) return;
1328
- if (!Array.isArray(e) || e.length > Rt) return null;
1383
+ if (!Array.isArray(e) || e.length > Lt) return null;
1329
1384
  let t = [];
1330
1385
  for (let n of e) {
1331
- let e = Zt(n);
1386
+ let e = Xt(n);
1332
1387
  if (!e) return null;
1333
1388
  t.push(e);
1334
1389
  }
1335
1390
  return t;
1336
1391
  }
1337
- function $t(e) {
1392
+ function Qt(e) {
1338
1393
  if (e === void 0) return;
1339
- if (!Array.isArray(e) || e.length > zt) return null;
1394
+ if (!Array.isArray(e) || e.length > Rt) return null;
1340
1395
  let t = [];
1341
1396
  for (let n of e) {
1342
1397
  if (!o(n)) return null;
1343
- let e = z(n.label);
1344
- if (!R(n.id) || !e || typeof n.done != "boolean" || n.sortOrder !== void 0 && (typeof n.sortOrder != "number" || !Number.isFinite(n.sortOrder)) || e.length > Bt) return null;
1398
+ let e = B(n.label);
1399
+ if (!z(n.id) || !e || typeof n.done != "boolean" || n.sortOrder !== void 0 && (typeof n.sortOrder != "number" || !Number.isFinite(n.sortOrder)) || e.length > zt) return null;
1345
1400
  t.push({
1346
1401
  id: n.id.trim(),
1347
1402
  label: e,
@@ -1351,11 +1406,11 @@ function $t(e) {
1351
1406
  }
1352
1407
  return t;
1353
1408
  }
1354
- function en(e) {
1409
+ function $t(e) {
1355
1410
  if (e === void 0) return;
1356
1411
  if (!o(e) || typeof e.text != "string") return null;
1357
- let t = e.text.trim(), n = V(e.element), r = V(e.xpath);
1358
- return !t || t.length > It || c(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 : {
1412
+ let t = e.text.trim(), n = H(e.element), r = H(e.xpath);
1413
+ return !t || t.length > Ft || c(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 : {
1359
1414
  text: t,
1360
1415
  startOffset: e.startOffset,
1361
1416
  endOffset: e.endOffset,
@@ -1363,20 +1418,20 @@ function en(e) {
1363
1418
  xpath: r
1364
1419
  };
1365
1420
  }
1366
- function tn(e) {
1367
- return typeof e == "string" && e.length > 0 && e.length <= j.COLOR && t(e);
1421
+ function en(e) {
1422
+ return typeof e == "string" && e.length > 0 && e.length <= M.COLOR && t(e);
1368
1423
  }
1369
- function H(e) {
1424
+ function U(e) {
1370
1425
  return e === void 0 || typeof e == "number" && Number.isFinite(e);
1371
1426
  }
1372
- function nn(e) {
1427
+ function tn(e) {
1373
1428
  if (e === void 0) return;
1374
- if (!o(e) || e.type !== "svg" || !Array.isArray(e.paths) || e.paths.length > Vt || !o(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;
1429
+ if (!o(e) || e.type !== "svg" || !Array.isArray(e.paths) || e.paths.length > Bt || !o(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;
1375
1430
  let t = [];
1376
1431
  for (let n of e.paths) {
1377
- if (!o(n) || !Yt.has(String(n.type))) return null;
1378
- let e = B(n.text, Ut);
1379
- if (!tn(n.stroke) || !tn(n.fill) || typeof n.strokeWidth != "number" || !Number.isFinite(n.strokeWidth) || n.strokeWidth < 0 || n.d !== void 0 && (typeof n.d != "string" || n.d.length > Ht || c(n.d)) || !H(n.x) || !H(n.y) || !H(n.width) || !H(n.height) || e === null) return null;
1432
+ if (!o(n) || !Jt.has(String(n.type))) return null;
1433
+ let e = V(n.text, Ht);
1434
+ if (!en(n.stroke) || !en(n.fill) || typeof n.strokeWidth != "number" || !Number.isFinite(n.strokeWidth) || n.strokeWidth < 0 || n.d !== void 0 && (typeof n.d != "string" || n.d.length > Vt || c(n.d)) || !U(n.x) || !U(n.y) || !U(n.width) || !U(n.height) || e === null) return null;
1380
1435
  t.push({
1381
1436
  type: n.type,
1382
1437
  stroke: n.stroke,
@@ -1399,19 +1454,19 @@ function nn(e) {
1399
1454
  }
1400
1455
  };
1401
1456
  }
1402
- function rn(e) {
1457
+ function nn(e) {
1403
1458
  return o(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);
1404
1459
  }
1405
- function an(e) {
1460
+ function rn(e) {
1406
1461
  if (e === void 0) return;
1407
1462
  if (!o(e)) return null;
1408
- let t = B(e.description, Lt), n = Qt(e.assignees), r = $t(e.checklist);
1463
+ let t = V(e.description, It), n = Zt(e.assignees), r = Qt(e.checklist);
1409
1464
  if (t === null || n === null || r === null) return null;
1410
- let i = Array.isArray(e.files) ? e.files.filter((e) => typeof File < "u" && e instanceof File) : void 0, a = Array.isArray(e.attachmentIds) ? e.attachmentIds.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= I).slice(0, 20) : void 0;
1465
+ let i = Array.isArray(e.files) ? e.files.filter((e) => typeof File < "u" && e instanceof File) : void 0, a = Array.isArray(e.attachmentIds) ? e.attachmentIds.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= L).slice(0, 20) : void 0;
1411
1466
  return {
1412
- ...Array.isArray(e.mentions) ? { mentions: e.mentions.filter((e) => o(e) && R(e.userId) && typeof e.name == "string").slice(0, 100) } : {},
1467
+ ...Array.isArray(e.mentions) ? { mentions: e.mentions.filter((e) => o(e) && z(e.userId) && typeof e.name == "string").slice(0, 100) } : {},
1413
1468
  ...typeof e.branch == "string" && e.branch.trim() && e.branch.length <= 255 && !c(e.branch) ? { branch: e.branch.trim() } : {},
1414
- ...rn(e.deviceInfo) ? { deviceInfo: e.deviceInfo } : {},
1469
+ ...nn(e.deviceInfo) ? { deviceInfo: e.deviceInfo } : {},
1415
1470
  ...t === void 0 ? {} : { description: t },
1416
1471
  ...n === void 0 ? {} : { assignees: n },
1417
1472
  ...r === void 0 ? {} : { checklist: r },
@@ -1419,61 +1474,69 @@ function an(e) {
1419
1474
  ...a && a.length > 0 ? { attachmentIds: a } : {}
1420
1475
  };
1421
1476
  }
1422
- function on(e) {
1477
+ function an(e) {
1423
1478
  if (!o(e)) return null;
1424
1479
  let t = {};
1425
1480
  if ("content" in e) {
1426
- let n = z(e.content);
1481
+ let n = B(e.content);
1427
1482
  if (!n) return null;
1428
1483
  t.content = n;
1429
1484
  }
1430
1485
  if ("status" in e) {
1431
- if (!Jt.has(e.status)) return null;
1486
+ if (!qt.has(e.status)) return null;
1432
1487
  t.status = e.status;
1433
1488
  }
1434
1489
  if ("priority" in e) {
1435
- if (!qt.has(e.priority)) return null;
1490
+ if (!Kt.has(e.priority)) return null;
1436
1491
  t.priority = e.priority;
1437
1492
  }
1438
1493
  if ("description" in e) {
1439
- let n = B(e.description, Lt);
1494
+ let n = V(e.description, It);
1440
1495
  if (n === null) return null;
1441
1496
  t.description = n;
1442
1497
  }
1443
- if (Array.isArray(e.mentions) && (t.mentions = e.mentions.filter((e) => o(e) && R(e.userId) && typeof e.name == "string").slice(0, 100)), "assignees" in e) {
1444
- let n = Qt(e.assignees);
1498
+ if (Array.isArray(e.mentions) && (t.mentions = e.mentions.filter((e) => o(e) && z(e.userId) && typeof e.name == "string").slice(0, 100)), "assignees" in e) {
1499
+ let n = Zt(e.assignees);
1445
1500
  if (n === null) return null;
1446
1501
  t.assignees = n;
1447
1502
  }
1503
+ if ("checklistPatch" in e) {
1504
+ let n = e.checklistPatch;
1505
+ if ("checklist" in e || !o(n) || !z(n.id) || typeof n.done != "boolean") return null;
1506
+ t.checklistPatch = {
1507
+ id: n.id,
1508
+ done: n.done
1509
+ };
1510
+ }
1448
1511
  if ("checklist" in e) {
1449
- let n = $t(e.checklist);
1512
+ let n = Qt(e.checklist);
1450
1513
  if (n === null) return null;
1451
1514
  t.checklist = n;
1452
1515
  }
1453
1516
  if ("textSelection" in e) {
1454
- let n = en(e.textSelection);
1517
+ let n = $t(e.textSelection);
1455
1518
  if (n === null) return null;
1456
1519
  t.textSelection = n;
1457
1520
  }
1458
1521
  if ("drawingData" in e) {
1459
- let n = nn(e.drawingData);
1522
+ let n = tn(e.drawingData);
1460
1523
  if (n === null) return null;
1461
1524
  t.drawingData = n;
1462
1525
  }
1463
1526
  if ("attachmentIds" in e) {
1464
1527
  let n = e.attachmentIds;
1465
1528
  if (!Array.isArray(n)) return null;
1466
- t.attachmentIds = n.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= I).slice(0, 20);
1529
+ t.attachmentIds = n.map((e) => String(e).trim()).filter((e) => e.length > 0 && e.length <= L).slice(0, 20);
1467
1530
  }
1468
1531
  return Object.keys(t).length > 0 ? t : void 0;
1469
1532
  }
1470
- function U(e) {
1533
+ function W(e) {
1471
1534
  return `${e}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
1472
1535
  }
1473
- function W(e, t) {
1536
+ function G(e, t) {
1474
1537
  return e.getState().comments.some((e) => e.id === t);
1475
1538
  }
1476
- function G(e, t, n) {
1539
+ function K(e, t, n) {
1477
1540
  if (e.getState().activeBranch && n.branch !== e.getState().activeBranch) {
1478
1541
  e.setState({ comments: e.getState().comments.filter((e) => e.id !== t) });
1479
1542
  return;
@@ -1481,7 +1544,7 @@ function G(e, t, n) {
1481
1544
  let r = e.getState().comments.filter((e) => e.id !== n.id), i = r.some((e) => e.id === t);
1482
1545
  e.setState({ comments: i ? r.map((e) => e.id === t ? n : e) : [...r, n] });
1483
1546
  }
1484
- function sn(e, t, n, r) {
1547
+ function on(e, t, n, r) {
1485
1548
  e.setState({ comments: e.getState().comments.map((e) => {
1486
1549
  if (e.id !== t) return e;
1487
1550
  let i = e.replies.filter((e) => e.id !== r.id), a = i.some((e) => e.id === n);
@@ -1494,7 +1557,7 @@ function sn(e, t, n, r) {
1494
1557
  };
1495
1558
  }) });
1496
1559
  }
1497
- function K(e, t) {
1560
+ function q(e, t) {
1498
1561
  return !t || t === e.status ? e : {
1499
1562
  ...e,
1500
1563
  status: t,
@@ -1502,18 +1565,28 @@ function K(e, t) {
1502
1565
  ...t === "complete" ? {} : { resolvedAt: void 0 }
1503
1566
  };
1504
1567
  }
1505
- function cn(e, t, n) {
1568
+ function sn(e, t, n) {
1506
1569
  return e.getState().comments.some((e) => e.id === t && e.replies.some((e) => e.id === n));
1507
1570
  }
1508
- async function ln(e) {
1509
- let t = e.getState().activeBranch;
1571
+ async function cn(e) {
1572
+ let t = e.getState().activeBranch, n = e.getState().commentQuery;
1510
1573
  e.setState({ isLoading: !0 });
1511
1574
  try {
1512
- let n = await e.apiClient.getComments(void 0, "all", 1, 50, void 0, t);
1513
- if (t !== e.getState().activeBranch) return;
1575
+ let r = await e.apiClient.getComments(n?.pagePath, n?.status ?? "all", 1, 50, void 0, t, {
1576
+ ...n,
1577
+ pagination: "cursor",
1578
+ view: "summary"
1579
+ });
1580
+ if (t !== e.getState().activeBranch || e.isCurrent?.() === !1) return;
1581
+ let i = e.getState().selectedComment?.id, a = i && r.comments.find((e) => e.id === i);
1582
+ if (a && a.detailLoaded === !1) {
1583
+ let n = await e.apiClient.getComment(a.id, { repliesLimit: 50 });
1584
+ if (e.isCurrent?.() === !1 || t !== e.getState().activeBranch) return;
1585
+ r.comments = r.comments.map((e) => e.id === n.id ? n : e);
1586
+ }
1514
1587
  e.setState({
1515
- comments: n.comments,
1516
- pagination: n.pagination
1588
+ comments: r.comments,
1589
+ pagination: r.pagination
1517
1590
  });
1518
1591
  } catch (t) {
1519
1592
  e.handleError(t);
@@ -1521,17 +1594,22 @@ async function ln(e) {
1521
1594
  e.setState({ isLoading: !1 });
1522
1595
  }
1523
1596
  }
1524
- async function un(e, t) {
1525
- let n = e.getState().activeBranch, r = e.getState().pagination;
1597
+ async function ln(e, t) {
1598
+ let n = e.getState().activeBranch, r = e.getState().pagination, i = e.getState().commentQuery;
1526
1599
  if (r && r.hasMore && !t.current) {
1527
1600
  t.current = !0;
1528
1601
  try {
1529
1602
  e.setState({ isLoading: !0 });
1530
- let t = await e.apiClient.getComments(void 0, "all", r.page + 1, r.limit, void 0, n);
1531
- if (n !== e.getState().activeBranch) return;
1532
- let i = new Set(e.getState().comments.map((e) => e.id)), a = t.comments.filter((e) => !i.has(e.id));
1603
+ let t = await e.apiClient.getComments(i?.pagePath, i?.status ?? "all", r.page + 1, r.limit, void 0, n, {
1604
+ ...i,
1605
+ pagination: "cursor",
1606
+ view: "summary",
1607
+ cursor: r.nextCursor
1608
+ });
1609
+ if (n !== e.getState().activeBranch || i !== e.getState().commentQuery || e.isCurrent?.() === !1) return;
1610
+ let a = new Set(e.getState().comments.map((e) => e.id)), o = t.comments.filter((e) => !a.has(e.id));
1533
1611
  e.setState({
1534
- comments: [...e.getState().comments, ...a],
1612
+ comments: [...e.getState().comments, ...o],
1535
1613
  pagination: t.pagination,
1536
1614
  isLoading: !1
1537
1615
  });
@@ -1542,24 +1620,55 @@ async function un(e, t) {
1542
1620
  }
1543
1621
  }
1544
1622
  }
1623
+ async function un(e, t, n) {
1624
+ if (z(t)) {
1625
+ e.setState({ loadingThreadId: t });
1626
+ try {
1627
+ let r = await e.apiClient.getComment(t, {
1628
+ repliesLimit: 50,
1629
+ ...n ? { repliesBefore: n } : {}
1630
+ });
1631
+ if (e.isCurrent?.() === !1 || e.getState().selectedComment?.id !== t) return;
1632
+ let i = e.getState().comments.find((e) => e.id === t), a = n && i ? [...new Map([...r.replies, ...i.replies].map((e) => [e.id, e])).values()] : r.replies, o = n && i ? {
1633
+ ...i,
1634
+ detailLoaded: !0,
1635
+ replies: a,
1636
+ repliesPagination: r.repliesPagination,
1637
+ repliesCount: Math.max(i.repliesCount ?? i.replies.length, r.repliesCount ?? r.replies.length)
1638
+ } : {
1639
+ ...r,
1640
+ detailLoaded: !0,
1641
+ replies: a
1642
+ };
1643
+ e.setState({
1644
+ comments: e.getState().comments.map((e) => e.id === t ? o : e),
1645
+ selectedComment: o
1646
+ });
1647
+ } catch (t) {
1648
+ e.handleError(t);
1649
+ } finally {
1650
+ e.getState().loadingThreadId === t && e.setState({ loadingThreadId: null });
1651
+ }
1652
+ }
1653
+ }
1545
1654
  async function dn(e, t, n, r, i, a, o = "medium", s, c, l) {
1546
1655
  let u = e.getState().currentUser;
1547
1656
  if (!u) return;
1548
- let d = z(i), f = Xt(a), p = en(s), h = nn(c), g = an(l);
1549
- if (!Kt.has(r) || !d || !f || !qt.has(o) || p === null || h === null || g === null) {
1550
- L(e, "invalid_comment", "Comment data is invalid");
1657
+ let d = B(i), f = Yt(a), p = $t(s), h = tn(c), g = rn(l);
1658
+ if (!Gt.has(r) || !d || !f || !Kt.has(o) || p === null || h === null || g === null) {
1659
+ R(e, "invalid_comment", "Comment data is invalid");
1551
1660
  return;
1552
1661
  }
1553
1662
  let _ = `create:${r}:${d.slice(0, 50)}:${f.x}:${f.y}`;
1554
1663
  if (n.has(_)) return;
1555
1664
  n.add(_);
1556
1665
  let v = m(), y = g?.files ?? [], ee = y.map((e, t) => ({
1557
- id: U(`pending-att-${t}`),
1666
+ id: W(`pending-att-${t}`),
1558
1667
  type: e.type.startsWith("image/") ? "screenshot" : "file",
1559
1668
  url: "",
1560
1669
  filename: e.name,
1561
1670
  size: e.size
1562
- })), b = U("temp"), te = {
1671
+ })), b = W("temp"), te = {
1563
1672
  id: b,
1564
1673
  type: r,
1565
1674
  content: d,
@@ -1624,7 +1733,7 @@ async function dn(e, t, n, r, i, a, o = "medium", s, c, l) {
1624
1733
  attachments: a.attachments ?? []
1625
1734
  };
1626
1735
  }
1627
- G(e, b, s), e.emit("comment:created", s), t.addActivity({
1736
+ K(e, b, s), e.emit("comment:created", s), t.addActivity({
1628
1737
  type: "comment_created",
1629
1738
  threadId: s.id,
1630
1739
  message: "created a new comment"
@@ -1657,29 +1766,33 @@ async function dn(e, t, n, r, i, a, o = "medium", s, c, l) {
1657
1766
  }
1658
1767
  }
1659
1768
  async function fn(e, t, n, r) {
1660
- if (!R(n)) return;
1661
- let i = on(r);
1769
+ if (!z(n)) return;
1770
+ let i = an(r);
1662
1771
  if (i === null) {
1663
- L(e, "invalid_comment_update", "Comment update data is invalid");
1772
+ R(e, "invalid_comment_update", "Comment update data is invalid");
1664
1773
  return;
1665
1774
  }
1666
1775
  if (i === void 0) return;
1667
1776
  let a = e.getState().comments, o = a.find((e) => e.id === n);
1668
- if (o) {
1669
- e.setState({ comments: a.map((e) => e.id === n ? {
1670
- ...K(e, i.status),
1671
- ...i
1672
- } : e) });
1673
- try {
1674
- let t = await e.apiClient.updateComment(n, i);
1675
- e.setState({ comments: e.getState().comments.map((e) => e.id === n ? t : e) }), e.emit("comment:updated", t);
1676
- } catch (r) {
1677
- t.shouldQueueMutation(r) && t.queueMutation("updateComment", [n, i]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? o : e) }), e.handleError(r));
1678
- }
1777
+ if (!o) return;
1778
+ let { checklistPatch: s, ...c } = i;
1779
+ e.setState({ comments: a.map((e) => e.id === n ? {
1780
+ ...q(e, i.status),
1781
+ ...c,
1782
+ ...s ? { checklist: e.checklist?.map((e) => e.id === s.id ? {
1783
+ ...e,
1784
+ done: s.done
1785
+ } : e) } : {}
1786
+ } : e) });
1787
+ try {
1788
+ let t = await e.apiClient.updateComment(n, i);
1789
+ e.setState({ comments: e.getState().comments.map((e) => e.id === n ? t : e) }), e.emit("comment:updated", t);
1790
+ } catch (r) {
1791
+ t.shouldQueueMutation(r) && t.queueMutation("updateComment", [n, i]) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? o : e) }), e.handleError(r));
1679
1792
  }
1680
1793
  }
1681
1794
  async function pn(e, t, n) {
1682
- if (!R(n)) return;
1795
+ if (!z(n)) return;
1683
1796
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1684
1797
  if (!i) return;
1685
1798
  let a = e.getState().selectedComment;
@@ -1701,17 +1814,17 @@ async function pn(e, t, n) {
1701
1814
  }
1702
1815
  async function mn(e, t, n, r, i) {
1703
1816
  let a = e.getState().currentUser;
1704
- if (!a || !R(n) || !W(e, n)) return;
1705
- let o = z(r, Pt);
1817
+ if (!a || !z(n) || !G(e, n)) return;
1818
+ let o = B(r, Nt);
1706
1819
  if (!o) {
1707
- L(e, "invalid_reply", "Reply content is invalid");
1820
+ R(e, "invalid_reply", "Reply content is invalid");
1708
1821
  return;
1709
1822
  }
1710
- if (i?.replyTo && (!R(i.replyTo.id) || i.replyTo.id.startsWith("temp_") || !["comment", "reply"].includes(i.replyTo.type) || (i.replyTo.type === "comment" ? i.replyTo.id !== n : !cn(e, n, i.replyTo.id)))) {
1711
- L(e, "invalid_reply", "Reply target must belong to this thread");
1823
+ if (i?.replyTo && (!z(i.replyTo.id) || i.replyTo.id.startsWith("temp_") || !["comment", "reply"].includes(i.replyTo.type) || (i.replyTo.type === "comment" ? i.replyTo.id !== n : !sn(e, n, i.replyTo.id)))) {
1824
+ R(e, "invalid_reply", "Reply target must belong to this thread");
1712
1825
  return;
1713
1826
  }
1714
- 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 = U("temp_reply"), u = {
1827
+ 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 = W("temp_reply"), u = {
1715
1828
  ...c && i?.replyTo ? { replyTo: {
1716
1829
  ...i.replyTo,
1717
1830
  authorName: c.author.name,
@@ -1725,10 +1838,11 @@ async function mn(e, t, n, r, i) {
1725
1838
  };
1726
1839
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? {
1727
1840
  ...e,
1841
+ repliesCount: (e.repliesCount ?? e.replies.length) + 1,
1728
1842
  replies: [...e.replies, u]
1729
1843
  } : e) });
1730
1844
  try {
1731
- sn(e, n, l, await e.apiClient.addReply(n, o, l, ...i ? [i] : []));
1845
+ on(e, n, l, await e.apiClient.addReply(n, o, l, ...i ? [i] : []));
1732
1846
  let t = e.getState().comments.find((e) => e.id === n);
1733
1847
  t && e.emit("comment:updated", t);
1734
1848
  } catch (r) {
@@ -1738,15 +1852,16 @@ async function mn(e, t, n, r, i) {
1738
1852
  i
1739
1853
  ] : [n, o], l) || (e.setState({ comments: e.getState().comments.map((e) => e.id === n ? {
1740
1854
  ...e,
1855
+ repliesCount: Math.max(0, (e.repliesCount ?? e.replies.length) - 1),
1741
1856
  replies: e.replies.filter((e) => e.id !== l)
1742
1857
  } : e) }), e.handleError(r));
1743
1858
  }
1744
1859
  }
1745
1860
  async function hn(e, t, n, r, i) {
1746
- if (!R(t) || !R(n) || !cn(e, t, n)) return;
1747
- let a = z(r, Pt);
1861
+ if (!z(t) || !z(n) || !sn(e, t, n)) return;
1862
+ let a = B(r, Nt);
1748
1863
  if (!a) {
1749
- L(e, "invalid_reply", "Reply content is invalid");
1864
+ R(e, "invalid_reply", "Reply content is invalid");
1750
1865
  return;
1751
1866
  }
1752
1867
  let o = e.getState().comments, s = o.find((e) => e.id === t)?.replies.find((e) => e.id === n);
@@ -1774,10 +1889,11 @@ async function hn(e, t, n, r, i) {
1774
1889
  }
1775
1890
  }
1776
1891
  async function gn(e, t, n) {
1777
- if (!R(t) || !R(n) || !cn(e, t, n)) return;
1892
+ if (!z(t) || !z(n) || !sn(e, t, n)) return;
1778
1893
  let r = e.getState().comments, i = r.find((e) => e.id === t)?.replies.find((e) => e.id === n);
1779
1894
  e.setState({ comments: r.map((e) => e.id === t ? {
1780
1895
  ...e,
1896
+ repliesCount: Math.max(0, (e.repliesCount ?? e.replies.length) - 1),
1781
1897
  replies: e.replies.filter((e) => e.id !== n)
1782
1898
  } : e) });
1783
1899
  try {
@@ -1787,14 +1903,15 @@ async function gn(e, t, n) {
1787
1903
  } catch (r) {
1788
1904
  e.setState({ comments: e.getState().comments.map((e) => e.id === t && i && !e.replies.some((e) => e.id === n) ? {
1789
1905
  ...e,
1906
+ repliesCount: (e.repliesCount ?? e.replies.length) + 1,
1790
1907
  replies: [...e.replies, i]
1791
1908
  } : e) }), e.handleError(r);
1792
1909
  }
1793
1910
  }
1794
1911
  async function _n(e, t, n) {
1795
- if (!R(n) || !W(e, n)) return;
1912
+ if (!z(n) || !G(e, n)) return;
1796
1913
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1797
- e.setState({ comments: r.map((e) => e.id === n ? K(e, "resolved") : e) });
1914
+ e.setState({ comments: r.map((e) => e.id === n ? q(e, "resolved") : e) });
1798
1915
  try {
1799
1916
  let r = await e.apiClient.resolveComment(n);
1800
1917
  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({
@@ -1807,9 +1924,9 @@ async function _n(e, t, n) {
1807
1924
  }
1808
1925
  }
1809
1926
  async function vn(e, t, n) {
1810
- if (!R(n) || !W(e, n)) return;
1927
+ if (!z(n) || !G(e, n)) return;
1811
1928
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1812
- e.setState({ comments: r.map((e) => e.id === n ? K(e, "open") : e) });
1929
+ e.setState({ comments: r.map((e) => e.id === n ? q(e, "open") : e) });
1813
1930
  try {
1814
1931
  let t = await e.apiClient.unresolveComment(n);
1815
1932
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? t : e) }), e.emit("comment:updated", t);
@@ -1818,9 +1935,9 @@ async function vn(e, t, n) {
1818
1935
  }
1819
1936
  }
1820
1937
  async function yn(e, t, n) {
1821
- if (!R(n) || !W(e, n)) return;
1938
+ if (!z(n) || !G(e, n)) return;
1822
1939
  let r = e.getState().comments, i = r.find((e) => e.id === n);
1823
- e.setState({ comments: r.map((e) => e.id === n ? K(e, "complete") : e) });
1940
+ e.setState({ comments: r.map((e) => e.id === n ? q(e, "complete") : e) });
1824
1941
  try {
1825
1942
  let r = await e.apiClient.markComplete(n);
1826
1943
  e.setState({ comments: e.getState().comments.map((e) => e.id === n ? r : e) }), e.emit("comment:completed", r), t.addActivity({
@@ -1833,14 +1950,14 @@ async function yn(e, t, n) {
1833
1950
  }
1834
1951
  }
1835
1952
  async function bn(e, t, n, r, i) {
1836
- if (!R(n) || typeof r != "string") return;
1953
+ if (!z(n) || typeof r != "string") return;
1837
1954
  let a = r.trim();
1838
- if (!a || a.length > Gt || c(a)) return;
1955
+ if (!a || a.length > Wt || c(a)) return;
1839
1956
  let o = e.getState().comments.find((e) => e.id === n);
1840
1957
  if (!o) return;
1841
1958
  let s = i ? o.replies.find((e) => e.id === i) : o;
1842
1959
  if (!s) return;
1843
- let l = (s.reactions ?? []).filter((e) => typeof e.emoji == "string" && e.emoji.length > 0 && e.emoji.length <= Gt && !c(e.emoji) && typeof e.count == "number" && Number.isInteger(e.count) && e.count >= 0 && e.count <= Wt), u = l.find((e) => e.emoji === a)?.reacted, d = [...l];
1960
+ let l = (s.reactions ?? []).filter((e) => typeof e.emoji == "string" && e.emoji.length > 0 && e.emoji.length <= Wt && !c(e.emoji) && typeof e.count == "number" && Number.isInteger(e.count) && e.count >= 0 && e.count <= Ut), u = l.find((e) => e.emoji === a)?.reacted, d = [...l];
1844
1961
  if (u) {
1845
1962
  let e = d.findIndex((e) => e.emoji === a), t = d[e];
1846
1963
  t.count <= 1 ? d.splice(e, 1) : d[e] = {
@@ -1852,7 +1969,7 @@ async function bn(e, t, n, r, i) {
1852
1969
  let e = d.findIndex((e) => e.emoji === a), t = e === -1 ? void 0 : d[e];
1853
1970
  t ? d[e] = {
1854
1971
  ...t,
1855
- count: Math.min(t.count + 1, Wt),
1972
+ count: Math.min(t.count + 1, Ut),
1856
1973
  reacted: !0
1857
1974
  } : d.push({
1858
1975
  emoji: a,
@@ -1898,13 +2015,13 @@ async function bn(e, t, n, r, i) {
1898
2015
  }
1899
2016
  }
1900
2017
  async function xn(e, t, n, r, i) {
1901
- if (!R(n) || !W(e, n)) return;
1902
- let a = Xt({
2018
+ if (!z(n) || !G(e, n)) return;
2019
+ let a = Yt({
1903
2020
  x: r,
1904
2021
  y: i
1905
2022
  });
1906
2023
  if (!a) {
1907
- L(e, "invalid_position", "Comment position is invalid");
2024
+ R(e, "invalid_position", "Comment position is invalid");
1908
2025
  return;
1909
2026
  }
1910
2027
  let o = e.getState().comments, s = o.find((e) => e.id === n);
@@ -1931,15 +2048,15 @@ function Sn(e, t) {
1931
2048
  async function Cn(e, t, n, r, i) {
1932
2049
  let a = e.getState().currentUser;
1933
2050
  if (!a) return;
1934
- let o = z(i), s = en(r);
2051
+ let o = B(i), s = $t(r);
1935
2052
  if (!o || s == null) {
1936
- L(e, "invalid_highlight", "Highlight data is invalid");
2053
+ R(e, "invalid_highlight", "Highlight data is invalid");
1937
2054
  return;
1938
2055
  }
1939
2056
  let c = `highlight:${s.xpath}:${s.startOffset}:${o.slice(0, 50)}`;
1940
2057
  if (n.has(c)) return;
1941
2058
  n.add(c);
1942
- let l = m(), u = F(e), d = u ? { branch: u } : void 0, f = U("temp"), p = {
2059
+ let l = m(), u = I(e), d = u ? { branch: u } : void 0, f = W("temp"), p = {
1943
2060
  id: f,
1944
2061
  type: "highlight",
1945
2062
  ...u ? { branch: u } : {},
@@ -1966,7 +2083,7 @@ async function Cn(e, t, n, r, i) {
1966
2083
  e.setState({ comments: [...e.getState().comments, p] });
1967
2084
  try {
1968
2085
  let t = await e.apiClient.createHighlight(o, s, l, "medium", f, ...d ? [d] : []);
1969
- G(e, f, t), e.emit("comment:created", t);
2086
+ K(e, f, t), e.emit("comment:created", t);
1970
2087
  } catch (n) {
1971
2088
  t.shouldQueueMutation(n) && t.queueMutation("createHighlight", [
1972
2089
  o,
@@ -1985,15 +2102,15 @@ async function Cn(e, t, n, r, i) {
1985
2102
  async function wn(e, t, n, r, i, a) {
1986
2103
  let o = e.getState().currentUser;
1987
2104
  if (!o) return;
1988
- let s = z(a), c = Xt(i), l = nn(r);
2105
+ let s = B(a), c = Yt(i), l = tn(r);
1989
2106
  if (!s || !c || l == null) {
1990
- L(e, "invalid_drawing", "Drawing comment data is invalid");
2107
+ R(e, "invalid_drawing", "Drawing comment data is invalid");
1991
2108
  return;
1992
2109
  }
1993
2110
  let u = `drawing:${c.x}:${c.y}:${s.slice(0, 50)}`;
1994
2111
  if (n.has(u)) return;
1995
2112
  n.add(u);
1996
- let d = m(), f = F(e), p = f ? { branch: f } : void 0, h = U("temp"), g = {
2113
+ let d = m(), f = I(e), p = f ? { branch: f } : void 0, h = W("temp"), g = {
1997
2114
  id: h,
1998
2115
  type: "drawing",
1999
2116
  ...f ? { branch: f } : {},
@@ -2017,7 +2134,7 @@ async function wn(e, t, n, r, i, a) {
2017
2134
  e.setState({ comments: [...e.getState().comments, g] });
2018
2135
  try {
2019
2136
  let t = await e.apiClient.createDrawing(s, l, c, d, h, ...p ? [p] : []);
2020
- G(e, h, t), e.emit("comment:created", t);
2137
+ K(e, h, t), e.emit("comment:created", t);
2021
2138
  } catch (n) {
2022
2139
  t.shouldQueueMutation(n) && t.queueMutation("createDrawing", [
2023
2140
  s,
@@ -2044,26 +2161,26 @@ var Tn = {
2044
2161
  function En(e) {
2045
2162
  return typeof e.composedPath == "function" ? e.composedPath() : e.target ? [e.target] : [];
2046
2163
  }
2047
- function Dn(e) {
2164
+ function J(e) {
2048
2165
  return typeof Element < "u" && e instanceof Element;
2049
2166
  }
2050
- function On(e) {
2051
- if (!Dn(e)) return !1;
2167
+ function Dn(e) {
2168
+ if (!J(e)) return !1;
2052
2169
  let t = e.tagName.toLowerCase();
2053
2170
  return t === "input" || t === "textarea" || t === "select" || e.isContentEditable || e.getAttribute("role") === "textbox";
2054
2171
  }
2055
- function kn(e) {
2172
+ function On(e) {
2056
2173
  let t = e.activeElement;
2057
2174
  for (; t?.shadowRoot?.activeElement;) t = t.shadowRoot.activeElement;
2058
2175
  return t;
2059
2176
  }
2060
- function An(e) {
2061
- return En(e).some(On) ? !0 : typeof document > "u" ? !1 : On(kn(document));
2177
+ function kn(e) {
2178
+ return En(e).some(Dn) ? !0 : typeof document > "u" ? !1 : Dn(On(document));
2062
2179
  }
2063
- function jn(e) {
2064
- return En(e).some((e) => Dn(e) && (e.hasAttribute("data-commentkit") || e.hasAttribute("data-commentkit-ui") || e.hasAttribute("data-commentkit-host")));
2180
+ function An(e) {
2181
+ return En(e).some((e) => J(e) && (e.hasAttribute("data-commentkit") || e.hasAttribute("data-commentkit-ui") || e.hasAttribute("data-commentkit-host")));
2065
2182
  }
2066
- var Mn = [
2183
+ var jn = [
2067
2184
  "popover",
2068
2185
  "dialog",
2069
2186
  "alert-dialog",
@@ -2073,26 +2190,26 @@ var Mn = [
2073
2190
  "select",
2074
2191
  "combobox"
2075
2192
  ].map((e) => `[data-slot="${e}-content"][data-open]`).join(",");
2076
- function Nn(e) {
2077
- let t = En(e), n = t.find((e) => Dn(e) && e.hasAttribute("data-commentkit-host"));
2078
- if (Dn(n)) return !!n.shadowRoot?.querySelector(Mn);
2193
+ function Mn(e) {
2194
+ let t = En(e), n = t.find((e) => J(e) && e.hasAttribute("data-commentkit-host"));
2195
+ if (J(n)) return !!n.shadowRoot?.querySelector(jn);
2079
2196
  if (typeof document < "u" && (t[0] === document.body || t[0] === document.documentElement)) {
2080
2197
  let e = document.querySelectorAll("[data-commentkit-host]");
2081
- return e.length === 1 && !!e[0]?.shadowRoot?.querySelector(Mn);
2198
+ return e.length === 1 && !!e[0]?.shadowRoot?.querySelector(jn);
2082
2199
  }
2083
2200
  return !1;
2084
2201
  }
2085
- function Pn(e) {
2202
+ function Nn(e) {
2086
2203
  return (e.ctrlKey || e.metaKey) && e.shiftKey && (e.key === "K" || e.key === "k" || e.code === "KeyK");
2087
2204
  }
2088
- function Fn(e) {
2205
+ function Pn(e) {
2089
2206
  let t = e.key.toLowerCase(), n = e.code.startsWith("Key") ? e.code.slice(3).toLowerCase() : "";
2090
2207
  return Tn[t] ?? Tn[n] ?? null;
2091
2208
  }
2092
- function In(e) {
2209
+ function Fn(e) {
2093
2210
  e.preventDefault(), e.stopPropagation();
2094
2211
  }
2095
- function Ln(e, t) {
2212
+ function In(e, t) {
2096
2213
  if (e.isLoginModalVisible) t.toggleLoginModal();
2097
2214
  else if (e.isShortcutsOverlayVisible) t.toggleShortcutsOverlay();
2098
2215
  else if (e.activeComment) t.setState({ activeComment: null });
@@ -2103,28 +2220,28 @@ function Ln(e, t) {
2103
2220
  else return !1;
2104
2221
  return !0;
2105
2222
  }
2106
- function Rn(e, t) {
2223
+ function Ln(e, t) {
2107
2224
  e.isAuthenticated ? t.toggleOverlay() : t.toggleLoginModal();
2108
2225
  }
2109
- function zn(e, t, n) {
2226
+ function Rn(e, t, n) {
2110
2227
  if (e.defaultPrevented || e.repeat || e.isComposing) return;
2111
- let r = An(e), i = jn(e);
2112
- if (Pn(e)) {
2228
+ let r = kn(e), i = An(e);
2229
+ if (Nn(e)) {
2113
2230
  if (r) return;
2114
- In(e), Rn(t, n);
2231
+ Fn(e), Ln(t, n);
2115
2232
  } else if (e.key === "Escape") {
2116
- if (Nn(e) || r && !i) return;
2117
- Ln(t, n) && In(e);
2233
+ if (Mn(e) || r && !i) return;
2234
+ In(t, n) && Fn(e);
2118
2235
  } else if (t.isAuthenticated && (t.isOverlayVisible || t.activeTool !== null) && !r && !e.ctrlKey && !e.metaKey && !e.altKey) {
2119
2236
  if (e.key === "?") {
2120
- In(e), n.toggleShortcutsOverlay();
2237
+ Fn(e), n.toggleShortcutsOverlay();
2121
2238
  return;
2122
2239
  }
2123
- let r = Fn(e);
2124
- r && (In(e), n.setTool(t.activeTool === r ? null : r));
2240
+ let r = Pn(e);
2241
+ r && (Fn(e), n.setTool(t.activeTool === r ? null : r));
2125
2242
  }
2126
2243
  }
2127
- var Bn = j.PENDING_MUTATIONS, Vn = j.RETRY_DELAY, q = j.ID, Hn = j.CONTENT, Un = j.REPLY_CONTENT, Wn = j.SELECTOR, Gn = j.EMOJI, Kn = /* @__PURE__ */ new Set([
2244
+ var zn = M.PENDING_MUTATIONS, Bn = M.RETRY_DELAY, Y = M.ID, Vn = M.CONTENT, Hn = M.REPLY_CONTENT, Un = M.SELECTOR, Wn = M.EMOJI, Gn = /* @__PURE__ */ new Set([
2128
2245
  "createComment",
2129
2246
  "createHighlight",
2130
2247
  "createDrawing",
@@ -2136,42 +2253,42 @@ var Bn = j.PENDING_MUTATIONS, Vn = j.RETRY_DELAY, q = j.ID, Hn = j.CONTENT, Un =
2136
2253
  "addReply",
2137
2254
  "reactToComment",
2138
2255
  "updatePosition"
2139
- ]), qn = /* @__PURE__ */ new Set([
2256
+ ]), Kn = /* @__PURE__ */ new Set([
2140
2257
  "pin",
2141
2258
  "highlight",
2142
2259
  "drawing"
2143
- ]), Jn = /* @__PURE__ */ new Set([
2260
+ ]), qn = /* @__PURE__ */ new Set([
2144
2261
  "low",
2145
2262
  "medium",
2146
2263
  "high",
2147
2264
  "urgent"
2148
- ]), Yn = /* @__PURE__ */ new Set(["add", "remove"]);
2149
- function Xn(t) {
2150
- return o(t) && e(t.x) && e(t.y) && n(t.element, Wn) && n(t.xpath, Wn);
2265
+ ]), Jn = /* @__PURE__ */ new Set(["add", "remove"]);
2266
+ function Yn(t) {
2267
+ return o(t) && e(t.x) && e(t.y) && n(t.element, Un) && n(t.xpath, Un);
2268
+ }
2269
+ function Xn(e) {
2270
+ return typeof e == "string" && e.length <= M.PAGE && !a(e);
2151
2271
  }
2152
2272
  function Zn(e) {
2153
- return typeof e == "string" && e.length <= j.PAGE && !a(e);
2273
+ return e === void 0 || o(e) && Xn(e.url) && Xn(e.path) && Xn(e.title);
2154
2274
  }
2155
2275
  function Qn(e) {
2156
- return e === void 0 || o(e) && Zn(e.url) && Zn(e.path) && Zn(e.title);
2276
+ return typeof e == "string" && Gn.has(e);
2157
2277
  }
2158
2278
  function $n(e) {
2159
- return typeof e == "string" && Kn.has(e);
2279
+ return Number.isInteger(e) && Number(e) >= 0;
2160
2280
  }
2161
2281
  function er(e) {
2162
- return Number.isInteger(e) && Number(e) >= 0;
2282
+ return $n(e) ? Math.min(e, 5) : 0;
2163
2283
  }
2164
2284
  function tr(e) {
2165
- return er(e) ? Math.min(e, 5) : 0;
2285
+ return e.isNetworkError() || e.code === 408 || e.isRateLimitError();
2166
2286
  }
2167
2287
  function nr(e) {
2168
- return e.isNetworkError() || e.code === 408 || e.isRateLimitError();
2288
+ return e instanceof E ? tr(e) : !0;
2169
2289
  }
2170
2290
  function rr(e) {
2171
- return e instanceof T ? nr(e) : !0;
2172
- }
2173
- function ir(e) {
2174
- return e instanceof T ? {
2291
+ return e instanceof E ? {
2175
2292
  error: e.error,
2176
2293
  message: e.message,
2177
2294
  code: e.code,
@@ -2182,93 +2299,98 @@ function ir(e) {
2182
2299
  code: 0
2183
2300
  };
2184
2301
  }
2185
- function ar(e = Date.now()) {
2302
+ function ir(e = Date.now()) {
2186
2303
  return `mutation_${e}_${typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : Math.random().toString(36).slice(2, 12)}`;
2187
2304
  }
2188
- function or(e) {
2189
- return Array.isArray(e) ? e.map((e) => or(e)) : o(e) ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, or(t)])) : e;
2305
+ function ar(e) {
2306
+ return Array.isArray(e) ? e.map((e) => ar(e)) : o(e) ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, ar(t)])) : e;
2190
2307
  }
2191
- function sr(e) {
2308
+ function or(e) {
2192
2309
  try {
2193
2310
  if (typeof structuredClone == "function") return structuredClone(e);
2194
2311
  } catch {}
2195
- return or(e);
2312
+ return ar(e);
2196
2313
  }
2197
- function cr(e, t) {
2314
+ function sr(e, t) {
2198
2315
  switch (e) {
2199
2316
  case "createComment": {
2200
2317
  let [e, n, r, a, s, c, l, u] = t;
2201
- return t.length >= 3 && t.length <= 8 && qn.has(String(e)) && i(n, Hn) && Xn(r) && (a === void 0 || Jn.has(String(a))) && (s === void 0 || o(s)) && (c === void 0 || o(c)) && (l === void 0 || o(l)) && Qn(u);
2318
+ return t.length >= 3 && t.length <= 8 && Kn.has(String(e)) && i(n, Vn) && Yn(r) && (a === void 0 || qn.has(String(a))) && (s === void 0 || o(s)) && (c === void 0 || o(c)) && (l === void 0 || o(l)) && Zn(u);
2202
2319
  }
2203
2320
  case "createHighlight": {
2204
2321
  let [e, n, r, a] = t;
2205
- return t.length >= 2 && t.length <= 4 && i(e, Hn) && o(n) && (a === void 0 || o(a)) && Qn(r);
2322
+ return t.length >= 2 && t.length <= 4 && i(e, Vn) && o(n) && (a === void 0 || o(a)) && Zn(r);
2206
2323
  }
2207
2324
  case "createDrawing": {
2208
2325
  let [e, n, r, a, s] = t;
2209
- return t.length >= 3 && t.length <= 5 && i(e, Hn) && o(n) && Xn(r) && (s === void 0 || o(s)) && Qn(a);
2326
+ return t.length >= 3 && t.length <= 5 && i(e, Vn) && o(n) && Yn(r) && (s === void 0 || o(s)) && Zn(a);
2210
2327
  }
2211
- case "updateComment": return t.length === 2 && r(t[0], q) && o(t[1]);
2328
+ case "updateComment": return t.length === 2 && r(t[0], Y) && o(t[1]);
2212
2329
  case "deleteComment":
2213
2330
  case "resolveComment":
2214
2331
  case "unresolveComment":
2215
- case "completeComment": return t.length === 1 && r(t[0], q);
2216
- case "addReply": return (t.length === 2 || t.length === 3) && r(t[0], q) && i(t[1], Un) && (t[2] === void 0 || o(t[2]));
2217
- case "reactToComment": return t.length >= 2 && t.length <= 4 && r(t[0], q) && r(t[1], Gn) && (t[2] === void 0 || Yn.has(String(t[2]))) && (t[3] === void 0 || r(t[3], q));
2218
- case "updatePosition": return t.length === 2 && r(t[0], q) && Xn(t[1]);
2332
+ case "completeComment": return t.length === 1 && r(t[0], Y);
2333
+ case "addReply": return (t.length === 2 || t.length === 3) && r(t[0], Y) && i(t[1], Hn) && (t[2] === void 0 || o(t[2]));
2334
+ case "reactToComment": return t.length >= 2 && t.length <= 4 && r(t[0], Y) && r(t[1], Wn) && (t[2] === void 0 || Jn.has(String(t[2]))) && (t[3] === void 0 || r(t[3], Y));
2335
+ case "updatePosition": return t.length === 2 && r(t[0], Y) && Yn(t[1]);
2219
2336
  }
2220
2337
  }
2221
- function lr(e) {
2222
- return o(e) ? r(e.id, q) ? e.ownerId !== void 0 && !r(e.ownerId, q) ? "Queued mutation has an invalid owner id" : $n(e.type) ? Array.isArray(e.args) ? Number.isFinite(e.timestamp) ? er(e.retries) ? n(e.tempId, q) ? cr(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";
2338
+ function cr(e) {
2339
+ return o(e) ? r(e.id, Y) ? e.ownerId !== void 0 && !r(e.ownerId, Y) ? "Queued mutation has an invalid owner id" : Qn(e.type) ? Array.isArray(e.args) ? Number.isFinite(e.timestamp) ? $n(e.retries) ? n(e.tempId, Y) ? sr(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";
2223
2340
  }
2224
- function ur(e) {
2225
- let t = lr(e);
2226
- if (t) throw new T("invalid_mutation", t, 400);
2341
+ function lr(e) {
2342
+ let t = cr(e);
2343
+ if (t) throw new E("invalid_mutation", t, 400);
2227
2344
  }
2228
- var dr = "commentkit:offline-queue:";
2229
- function fr() {
2345
+ var ur = "commentkit:offline-queue:";
2346
+ function dr() {
2230
2347
  try {
2231
2348
  return typeof localStorage > "u" ? null : localStorage;
2232
2349
  } catch {
2233
2350
  return null;
2234
2351
  }
2235
2352
  }
2236
- function pr(e) {
2237
- return `${dr}${e}`;
2353
+ function fr(e) {
2354
+ return `${ur}${e}`;
2238
2355
  }
2239
- function mr(e, t) {
2356
+ function pr(e, t) {
2240
2357
  if (!e) return;
2241
- let n = fr();
2358
+ let n = dr();
2242
2359
  if (n) try {
2243
- t.length === 0 ? n.removeItem(pr(e)) : n.setItem(pr(e), JSON.stringify(t));
2360
+ t.length === 0 ? n.removeItem(fr(e)) : n.setItem(fr(e), JSON.stringify(t));
2244
2361
  } catch {}
2245
2362
  }
2246
- function hr(e) {
2363
+ function mr(e) {
2247
2364
  if (!e) return [];
2248
- let t = fr();
2365
+ let t = dr();
2249
2366
  if (!t) return [];
2250
2367
  try {
2251
- let n = t.getItem(pr(e));
2368
+ let n = t.getItem(fr(e));
2252
2369
  if (!n) return [];
2253
2370
  let r = JSON.parse(n);
2254
2371
  if (!Array.isArray(r)) return [];
2255
2372
  let i = [];
2256
2373
  for (let e of r) {
2257
- if (i.length >= Bn) break;
2258
- lr(e) === null && i.push(e);
2374
+ if (i.length >= zn) break;
2375
+ cr(e) === null && i.push(e);
2259
2376
  }
2260
2377
  return i;
2261
2378
  } catch {
2262
2379
  return [];
2263
2380
  }
2264
2381
  }
2265
- function J(e) {
2382
+ function X(e) {
2266
2383
  Promise.resolve().then(e);
2267
2384
  }
2268
- function gr(e, t) {
2269
- return e.type !== t.type || e.ownerId !== t.ownerId ? !1 : (t.type === "updatePosition" || t.type === "updateComment") && e.args[0] === t.args[0];
2385
+ function hr(e, t) {
2386
+ if (e.type !== t.type || e.ownerId !== t.ownerId) return !1;
2387
+ if (t.type === "updateComment") {
2388
+ let n = e.args[1]?.checklistPatch, r = t.args[1]?.checklistPatch;
2389
+ if ((n || r) && n?.id !== r?.id) return !1;
2390
+ }
2391
+ return (t.type === "updatePosition" || t.type === "updateComment") && e.args[0] === t.args[0];
2270
2392
  }
2271
- function _r(e, t) {
2393
+ function gr(e, t) {
2272
2394
  return t.type === "updateComment" && o(e.args[1]) ? {
2273
2395
  ...t,
2274
2396
  args: [t.args[0], {
@@ -2277,32 +2399,32 @@ function _r(e, t) {
2277
2399
  }]
2278
2400
  } : t;
2279
2401
  }
2280
- function vr(e, t) {
2281
- let n = e.findIndex((e) => gr(e, t));
2402
+ function _r(e, t) {
2403
+ let n = e.findIndex((e) => hr(e, t));
2282
2404
  if (n !== -1) {
2283
2405
  let r = [...e];
2284
- return r[n] = _r(r[n], t), r;
2406
+ return r[n] = gr(r[n], t), r;
2285
2407
  }
2286
- return e.length >= Bn ? null : [...e, t];
2408
+ return e.length >= zn ? null : [...e, t];
2287
2409
  }
2288
- function Y(e, t, n) {
2410
+ function Z(e, t, n) {
2289
2411
  e.emit("offline:failed", {
2290
2412
  id: t,
2291
2413
  error: n
2292
2414
  });
2293
2415
  }
2294
- function yr(e, t) {
2416
+ function vr(e, t) {
2295
2417
  return t.isAuthenticated && e.ownerId && e.ownerId === t.currentUser?.id ? null : {
2296
2418
  error: "offline_identity_mismatch",
2297
2419
  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.",
2298
2420
  code: 403
2299
2421
  };
2300
2422
  }
2301
- function br(e) {
2423
+ function yr(e) {
2302
2424
  let t = e.getState();
2303
2425
  if (!t.isAuthenticated) return;
2304
2426
  let n = t.pendingMutations.flatMap((e) => {
2305
- let n = yr(e, t);
2427
+ let n = vr(e, t);
2306
2428
  return n ? [{
2307
2429
  mutation: e,
2308
2430
  error: n
@@ -2311,19 +2433,19 @@ function br(e) {
2311
2433
  if (n.length === 0) return;
2312
2434
  let r = new Set(n.map(({ mutation: e }) => e.id));
2313
2435
  e.setState({ pendingMutations: t.pendingMutations.filter((e) => !r.has(e.id)) });
2314
- for (let { mutation: t, error: r } of n) Y(e, t.id, r);
2436
+ for (let { mutation: t, error: r } of n) Z(e, t.id, r);
2315
2437
  }
2316
- function xr(e, t) {
2317
- return !e.isOnline || t instanceof T && nr(t);
2438
+ function br(e, t) {
2439
+ return !e.isOnline || t instanceof E && tr(t);
2318
2440
  }
2319
- function Sr(e, t, i, a, o) {
2320
- let s = ar(), c = e.getState(), l = c.currentUser?.id;
2321
- if (!c.isAuthenticated || !r(l, q)) return Y(e, s, {
2441
+ function xr(e, t, i, a, o) {
2442
+ let s = ir(), c = e.getState(), l = c.currentUser?.id;
2443
+ if (!c.isAuthenticated || !r(l, Y)) return Z(e, s, {
2322
2444
  error: "unauthenticated",
2323
2445
  message: "Sign in before saving changes for offline replay.",
2324
2446
  code: 401
2325
2447
  }), !1;
2326
- if (!$n(i) || !Array.isArray(a) || !cr(i, a) || !n(o, q)) return Y(e, s, {
2448
+ if (!Qn(i) || !Array.isArray(a) || !sr(i, a) || !n(o, Y)) return Z(e, s, {
2327
2449
  error: "invalid_mutation",
2328
2450
  message: "Queued mutation args are invalid",
2329
2451
  code: 400
@@ -2332,27 +2454,27 @@ function Sr(e, t, i, a, o) {
2332
2454
  id: s,
2333
2455
  ownerId: l,
2334
2456
  type: i,
2335
- args: sr(a),
2457
+ args: or(a),
2336
2458
  timestamp: Date.now(),
2337
2459
  retries: 0,
2338
2460
  ...o === void 0 ? {} : { tempId: o }
2339
- }, d = vr(e.getState().pendingMutations, u);
2340
- return d ? (e.setState({ pendingMutations: d }), e.emit("offline:queued", u), e.getState().isOnline && J(t), !0) : (Y(e, s, {
2461
+ }, d = _r(e.getState().pendingMutations, u);
2462
+ return d ? (e.setState({ pendingMutations: d }), e.emit("offline:queued", u), e.getState().isOnline && X(t), !0) : (Z(e, s, {
2341
2463
  error: "queue_full",
2342
2464
  message: "Offline mutation queue is full",
2343
2465
  code: 0
2344
2466
  }), !1);
2345
2467
  }
2346
- function Cr(e, t, n) {
2468
+ function Sr(e, t, n) {
2347
2469
  if (t.current || e.getState().pendingMutations.length === 0) return;
2348
2470
  let r = e.getState().pendingMutations[0];
2349
2471
  if (!r) return;
2350
- let i = tr(r.retries), a = Math.min(Vn, jt * 2 ** i);
2472
+ let i = er(r.retries), a = Math.min(Bn, At * 2 ** i);
2351
2473
  t.current = setTimeout(() => {
2352
2474
  t.current = null, n();
2353
2475
  }, a);
2354
2476
  }
2355
- async function wr(e, t, n, i) {
2477
+ async function Cr(e, t, n, i) {
2356
2478
  let a = e.getState();
2357
2479
  if (!a.isOnline || a.pendingMutations.length === 0 || !a.isAuthenticated || t.current) return;
2358
2480
  t.current = !0;
@@ -2361,49 +2483,49 @@ async function wr(e, t, n, i) {
2361
2483
  t.current = !1;
2362
2484
  return;
2363
2485
  }
2364
- let s = lr(o), c = s ? {
2486
+ let s = cr(o), c = s ? {
2365
2487
  error: "invalid_mutation",
2366
2488
  message: s,
2367
2489
  code: 400
2368
- } : yr(o, e.getState());
2490
+ } : vr(o, e.getState());
2369
2491
  if (c) {
2370
2492
  let i = e.getState().pendingMutations.filter((e) => e !== o);
2371
- e.setState({ pendingMutations: i }), Y(e, r(o.id, q) ? o.id : "invalid", c), i.length > 0 && J(n), t.current = !1;
2493
+ e.setState({ pendingMutations: i }), Z(e, r(o.id, Y) ? o.id : "invalid", c), i.length > 0 && X(n), t.current = !1;
2372
2494
  return;
2373
2495
  }
2374
2496
  e.emit("offline:retrying", {
2375
2497
  id: o.id,
2376
2498
  attempt: o.retries + 1
2377
2499
  });
2378
- let l = i ?? ((t) => Or(e, t));
2500
+ let l = i ?? ((t) => Dr(e, t));
2379
2501
  try {
2380
2502
  await l(o);
2381
2503
  let r = e.getState().pendingMutations.filter((e) => e.id !== o.id);
2382
- e.setState({ pendingMutations: r }), e.emit("offline:completed", { id: o.id }), r.length > 0 ? J(n) : t.reconcileAfterDrain && (t.reconcileAfterDrain = !1, ln(e));
2504
+ e.setState({ pendingMutations: r }), e.emit("offline:completed", { id: o.id }), r.length > 0 ? X(n) : t.reconcileAfterDrain && (t.reconcileAfterDrain = !1, cn(e));
2383
2505
  } catch (r) {
2384
2506
  let i = {
2385
2507
  ...o,
2386
- retries: tr(o.retries) + 1
2508
+ retries: er(o.retries) + 1
2387
2509
  };
2388
- if (rr(r) && i.retries < 5) {
2510
+ if (nr(r) && i.retries < 5) {
2389
2511
  let t = e.getState().pendingMutations.map((e) => e.id === o.id ? i : e);
2390
- e.setState({ pendingMutations: t }), J(n);
2512
+ e.setState({ pendingMutations: t }), X(n);
2391
2513
  } else {
2392
2514
  let i = e.getState().pendingMutations.filter((e) => e.id !== o.id);
2393
- e.setState({ pendingMutations: i }), Y(e, o.id, ir(r)), i.length > 0 ? (t.reconcileAfterDrain = !0, J(n)) : (t.reconcileAfterDrain = !1, ln(e));
2515
+ e.setState({ pendingMutations: i }), Z(e, o.id, rr(r)), i.length > 0 ? (t.reconcileAfterDrain = !0, X(n)) : (t.reconcileAfterDrain = !1, cn(e));
2394
2516
  }
2395
2517
  } finally {
2396
2518
  t.current = !1;
2397
2519
  }
2398
2520
  }
2399
- function Tr(e, t, n) {
2521
+ function wr(e, t, n) {
2400
2522
  let r = !1, i = e.getState().pendingMutations.map((e) => e.type !== "createComment" && e.type !== "createHighlight" && e.type !== "createDrawing" && e.args[0] === t ? (r = !0, {
2401
2523
  ...e,
2402
2524
  args: [n, ...e.args.slice(1)]
2403
2525
  }) : e);
2404
2526
  r && e.setState({ pendingMutations: i });
2405
2527
  }
2406
- function Er(e, t, n) {
2528
+ function Tr(e, t, n) {
2407
2529
  let r = e.getState(), i = (e) => e === t || e === n;
2408
2530
  e.setState({
2409
2531
  comments: r.comments.filter((e) => !i(e.id)),
@@ -2411,7 +2533,7 @@ function Er(e, t, n) {
2411
2533
  activeComment: r.activeComment && i(r.activeComment.id) ? null : r.activeComment
2412
2534
  });
2413
2535
  }
2414
- function X(e, t, n, r, i = !1) {
2536
+ function Q(e, t, n, r, i = !1) {
2415
2537
  let a = e.getState(), o = a.comments.find((e) => e.id === r || e.id === n.id), s = n, c = (e) => {
2416
2538
  s.status !== e && (s = {
2417
2539
  ...s,
@@ -2422,13 +2544,20 @@ function X(e, t, n, r, i = !1) {
2422
2544
  };
2423
2545
  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) {
2424
2546
  case "deleteComment":
2425
- Er(e, n.id, r);
2547
+ Tr(e, n.id, r);
2426
2548
  return;
2427
2549
  case "updateComment":
2428
- i.args[1].status && c(i.args[1].status), s = {
2429
- ...s,
2430
- ...i.args[1]
2431
- };
2550
+ i.args[1].status && c(i.args[1].status);
2551
+ {
2552
+ let { checklistPatch: e, ...t } = i.args[1];
2553
+ s = {
2554
+ ...s,
2555
+ ...t
2556
+ }, e && (s.checklist = s.checklist?.map((t) => t.id === e.id ? {
2557
+ ...t,
2558
+ done: e.done
2559
+ } : t));
2560
+ }
2432
2561
  break;
2433
2562
  case "resolveComment":
2434
2563
  c("resolved");
@@ -2458,69 +2587,69 @@ function X(e, t, n, r, i = !1) {
2458
2587
  reactions: o.reactions
2459
2588
  });
2460
2589
  }
2461
- i ? G(e, r, s) : e.setState({ comments: a.comments.map((e) => e.id === r ? s : e) });
2590
+ i ? K(e, r, s) : e.setState({ comments: a.comments.map((e) => e.id === r ? s : e) });
2462
2591
  }
2463
- function Dr(e, t, n, r) {
2592
+ function Er(e, t, n, r) {
2464
2593
  e.setState({ pendingMutations: e.getState().pendingMutations.map((e) => e.type === "reactToComment" && e.args[0] === t && e.args[3] === n ? {
2465
2594
  ...e,
2466
2595
  args: [...e.args.slice(0, 3), r]
2467
2596
  } : e) });
2468
2597
  }
2469
- async function Or(e, t) {
2470
- ur(t);
2471
- let n = yr(t, e.getState());
2472
- if (n) throw new T(n.error, n.message, n.code);
2598
+ async function Dr(e, t) {
2599
+ lr(t);
2600
+ let n = vr(t, e.getState());
2601
+ if (n) throw new E(n.error, n.message, n.code);
2473
2602
  switch (t.type) {
2474
2603
  case "createComment": {
2475
2604
  let [n, r, i, a, o, s, c, l] = t.args, u = await e.apiClient.createComment(n, r, i, l ?? m(), a, o, s, c, t.tempId);
2476
- u && t.tempId && (X(e, t, u, t.tempId, !0), Tr(e, t.tempId, u.id));
2605
+ u && t.tempId && (Q(e, t, u, t.tempId, !0), wr(e, t.tempId, u.id));
2477
2606
  break;
2478
2607
  }
2479
2608
  case "createHighlight": {
2480
2609
  let [n, r, i, a] = t.args, o = await e.apiClient.createHighlight(n, r, i ?? m(), "medium", t.tempId, ...a ? [a] : []);
2481
- o && t.tempId && (X(e, t, o, t.tempId, !0), Tr(e, t.tempId, o.id));
2610
+ o && t.tempId && (Q(e, t, o, t.tempId, !0), wr(e, t.tempId, o.id));
2482
2611
  break;
2483
2612
  }
2484
2613
  case "createDrawing": {
2485
2614
  let [n, r, i, a, o] = t.args, s = await e.apiClient.createDrawing(n, r, i, a ?? m(), t.tempId, ...o ? [o] : []);
2486
- s && t.tempId && (X(e, t, s, t.tempId, !0), Tr(e, t.tempId, s.id));
2615
+ s && t.tempId && (Q(e, t, s, t.tempId, !0), wr(e, t.tempId, s.id));
2487
2616
  break;
2488
2617
  }
2489
2618
  case "updateComment": {
2490
2619
  let [n, r] = t.args, i = await e.apiClient.updateComment(n, r);
2491
- i && X(e, t, i, n);
2620
+ i && Q(e, t, i, n);
2492
2621
  break;
2493
2622
  }
2494
2623
  case "deleteComment": {
2495
2624
  let [n] = t.args;
2496
- await e.apiClient.deleteComment(n), Er(e, n);
2625
+ await e.apiClient.deleteComment(n), Tr(e, n);
2497
2626
  break;
2498
2627
  }
2499
2628
  case "resolveComment": {
2500
2629
  let [n] = t.args, r = await e.apiClient.resolveComment(n);
2501
- r && X(e, t, r, n);
2630
+ r && Q(e, t, r, n);
2502
2631
  break;
2503
2632
  }
2504
2633
  case "unresolveComment": {
2505
2634
  let [n] = t.args, r = await e.apiClient.unresolveComment(n);
2506
- r && X(e, t, r, n);
2635
+ r && Q(e, t, r, n);
2507
2636
  break;
2508
2637
  }
2509
2638
  case "completeComment": {
2510
2639
  let [n] = t.args, r = await e.apiClient.markComplete(n);
2511
- r && X(e, t, r, n);
2640
+ r && Q(e, t, r, n);
2512
2641
  break;
2513
2642
  }
2514
2643
  case "addReply": {
2515
2644
  let [n, r, i] = t.args, a = await e.apiClient.addReply(n, r, t.tempId, ...i ? [i] : []);
2516
2645
  if (a && t.tempId) {
2517
2646
  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);
2518
- sn(e, n, t.tempId, i && o ? {
2647
+ on(e, n, t.tempId, i && o ? {
2519
2648
  ...a,
2520
2649
  reactions: o.reactions
2521
- } : a), Dr(e, n, t.tempId, a.id);
2650
+ } : a), Er(e, n, t.tempId, a.id);
2522
2651
  let s = e.getState().comments.find((e) => e.id === n);
2523
- s && X(e, t, s, n);
2652
+ s && Q(e, t, s, n);
2524
2653
  }
2525
2654
  break;
2526
2655
  }
@@ -2531,221 +2660,30 @@ async function Or(e, t) {
2531
2660
  }
2532
2661
  case "updatePosition": {
2533
2662
  let [n, r] = t.args, i = await e.apiClient.updatePosition(n, r);
2534
- i && X(e, t, i, n);
2663
+ i && Q(e, t, i, n);
2535
2664
  break;
2536
2665
  }
2537
2666
  }
2538
2667
  }
2539
- var kr = 1e4, Ar = 2048, jr = 10485760, Mr = 20971520, Z = 16384, Nr = 32e6, Pr = 10, Fr = 10485760, Ir = 26214400, Lr = /* @__PURE__ */ new Set([
2540
- "jpg",
2541
- "jpeg",
2542
- "png",
2543
- "gif",
2544
- "webp",
2545
- "pdf",
2546
- "doc",
2547
- "docx",
2548
- "txt",
2549
- "csv"
2550
- ]), Rr = 15e3, zr = 1e4, Br = {
2551
- "image/gif": "gif",
2552
- "image/jpeg": "jpg",
2553
- "image/png": "png",
2554
- "image/webp": "webp"
2555
- };
2556
- function Q(e, t) {
2557
- let n = Error(t);
2558
- return n.error = e, n.code = 400, n;
2559
- }
2560
- function Vr(e) {
2561
- if (typeof e != "string") throw Q("invalid_position", "Invalid position");
2562
- let t = e.trim();
2563
- if (!t || t.length > Ar || a(t)) throw Q("invalid_position", "Invalid position");
2564
- return t;
2565
- }
2566
- function Hr(t) {
2567
- if (!o(t) || !e(t.x) || !e(t.y)) throw Q("invalid_position", "Invalid position");
2568
- return {
2569
- x: t.x,
2570
- y: t.y,
2571
- ...t.element === void 0 ? {} : { element: Vr(t.element) },
2572
- ...t.xpath === void 0 ? {} : { xpath: Vr(t.xpath) }
2573
- };
2574
- }
2575
- function Ur(e) {
2576
- if (typeof e != "string") throw Q("invalid_content", "Screenshot comment is required");
2577
- let t = e.trim();
2578
- if (!t || t.length > kr || a(t)) throw Q("invalid_content", "Screenshot comment is required");
2579
- return t;
2580
- }
2581
- function Wr(e) {
2582
- return typeof Blob < "u" && e instanceof Blob;
2583
- }
2584
- function Gr(e) {
2585
- return typeof File < "u" && e instanceof File;
2586
- }
2587
- function Kr(e) {
2588
- return typeof HTMLElement < "u" && e instanceof HTMLElement;
2589
- }
2590
- function qr(e) {
2591
- if (e !== void 0) {
2592
- if (!Kr(e)) throw Q("invalid_element", "Invalid screenshot target");
2593
- return e;
2594
- }
2595
- if (typeof document > "u" || !document.body) throw Q("invalid_element", "A browser document is required to capture screenshots");
2596
- return document.body;
2597
- }
2598
- function Jr(e) {
2599
- let t = /^data:(image\/(?:png|jpeg|gif|webp));base64,/i.exec(e)?.[1];
2600
- return t ? t.toLowerCase() : null;
2601
- }
2602
- function Yr(e) {
2603
- if (!o(e)) throw Q("invalid_screenshot", "Invalid screenshot result");
2604
- let t = typeof e.dataUrl == "string" ? e.dataUrl.trim() : "", n = e.blob, r = e.dimensions;
2605
- if (!Jr(t) || t.length > Mr || !Wr(n) || n.size <= 0 || n.size > jr || n.type && !Object.prototype.hasOwnProperty.call(Br, n.type)) throw Q("invalid_screenshot", "Invalid screenshot result");
2606
- if (!o(r)) throw Q("invalid_screenshot", "Invalid screenshot dimensions");
2607
- let { width: i, height: a } = r;
2608
- if (typeof i != "number" || typeof a != "number" || !Number.isFinite(i) || !Number.isFinite(a) || i <= 0 || a <= 0 || i > Z || a > Z) throw Q("invalid_screenshot", "Invalid screenshot dimensions");
2609
- return {
2610
- dataUrl: t,
2611
- blob: n,
2612
- dimensions: {
2613
- width: i,
2614
- height: a
2615
- }
2616
- };
2617
- }
2618
- function Xr(e) {
2619
- let t = Jr(e.dataUrl);
2620
- return e.blob.type || t;
2621
- }
2622
- function Zr(e) {
2623
- return `screenshot.${Br[Xr(e)]}`;
2624
- }
2625
- function Qr(e, t, n) {
2626
- let r = null;
2627
- return new Promise((i, a) => {
2628
- r = setTimeout(() => {
2629
- r = null, a(Error(n));
2630
- }, t), e.then((e) => {
2631
- r && clearTimeout(r), r = null, i(e);
2632
- }, (e) => {
2633
- r && clearTimeout(r), r = null, a(e);
2634
- });
2635
- });
2636
- }
2637
- function $r(e) {
2638
- return new Promise((t, n) => {
2639
- let r = !1, i = setTimeout(() => {
2640
- r = !0, n(/* @__PURE__ */ Error("toBlob timed out"));
2641
- }, zr);
2642
- e.toBlob((e) => {
2643
- r || (r = !0, clearTimeout(i), e ? t(e) : n(/* @__PURE__ */ Error("toBlob returned null")));
2644
- }, "image/png");
2645
- });
2646
- }
2647
- function ei(e) {
2648
- let t = e.lastIndexOf(".");
2649
- return t >= 0 ? e.slice(t + 1).toLowerCase() : "";
2650
- }
2651
- function ti(e) {
2652
- if (!Array.isArray(e)) throw Q("invalid_files", "Files must be an array");
2653
- if (e.length > Pr) throw Q("too_many_files", `Cannot upload more than ${Pr} files at once`);
2654
- let t = 0;
2655
- for (let n of e) {
2656
- if (!Gr(n)) throw Q("invalid_files", "Invalid file upload");
2657
- if (n.size > Fr) throw Q("file_too_large", `File "${n.name}" exceeds the ${Fr / 1024 / 1024}MB limit`);
2658
- if (t += n.size, t > Ir) throw Q("upload_too_large", `Total upload size exceeds the ${Ir / 1024 / 1024}MB limit`);
2659
- if (a(n.name) || n.name.includes("/") || n.name.includes("\\")) throw Q("invalid_filename", "Filename contains invalid characters");
2660
- if (u(n.name)) throw Q("invalid_file_type", `File type ".${ei(n.name)}" is not allowed`);
2661
- if (!Lr.has(ei(n.name))) throw Q("invalid_file_type", `File type ".${ei(n.name)}" is not supported. Allowed: ${[...Lr].map((e) => `.${e}`).join(", ")}`);
2662
- }
2663
- return e;
2664
- }
2665
- async function ni(e, t, n, r = {}) {
2666
- if (e.isLocalDemo) return null;
2667
- try {
2668
- let e = qr(n);
2669
- if (g(e)) return null;
2670
- if (t) return Yr(await t(e));
2671
- let r;
2672
- try {
2673
- r = (await import("html2canvas")).default;
2674
- } catch {
2675
- /* v8 ignore next 3 -- dynamic import() can't be intercepted by vi.mock */
2676
- throw Error("Screenshot requires either a custom screenshotProvider in config or html2canvas installed. Install html2canvas: npm install html2canvas — or provide config.screenshotProvider.");
2677
- }
2678
- let i = await Qr(r(e, {
2679
- useCORS: !0,
2680
- allowTaint: !1,
2681
- scale: 2,
2682
- logging: !1,
2683
- ignoreElements: g,
2684
- onclone: (e) => import("./capture-colors-D0uLr-vZ.js").then(({ normalizeCaptureColors: t }) => t(e))
2685
- }), Rr, "html2canvas timed out after 15s");
2686
- if (i.width > Z || i.height > Z || i.width * i.height > Nr) throw Q("screenshot_too_large", "Captured area is too large to screenshot");
2687
- return Yr({
2688
- dataUrl: i.toDataURL("image/png"),
2689
- blob: await $r(i),
2690
- dimensions: {
2691
- width: i.width,
2692
- height: i.height
2693
- }
2694
- });
2695
- } catch (t) {
2696
- return r.reportErrors !== !1 && (console.error("[CommentKit] Screenshot failed:", t), e.handleError({
2697
- error: "screenshot_failed",
2698
- message: "Failed to capture screenshot",
2699
- code: 500
2700
- })), null;
2701
- }
2702
- }
2703
- async function ri(e, t, n, r) {
2704
- try {
2705
- let i = Yr(t), a = Ur(n), o = Hr(r);
2706
- e.setState({ isLoading: !0 });
2707
- let s = new File([i.blob], Zr(i), { type: Xr(i) }), c = m(), l = F(e), u = await e.apiClient.uploadScreenshot(s, {
2708
- content: a,
2709
- position: o,
2710
- page: c,
2711
- ...l ? { branch: l } : {}
2712
- });
2713
- return e.setState({
2714
- comments: !e.getState().activeBranch || e.getState().activeBranch === u.branch ? [...e.getState().comments, u] : e.getState().comments,
2715
- isLoading: !1,
2716
- activeScreenshot: null
2717
- }), e.emit("comment:created", u), u;
2718
- } catch (t) {
2719
- return e.setState({ isLoading: !1 }), e.handleError(t), null;
2720
- }
2721
- }
2722
- async function ii(e, t, n) {
2723
- try {
2724
- let r = ti(t);
2725
- return r.length === 0 ? [] : await e.apiClient.uploadFiles(r, n);
2726
- } catch (t) {
2727
- return e.handleError(t), [];
2728
- }
2729
- }
2730
2668
  var $ = null;
2731
- async function ai() {
2732
- return $ || ($ = await import("./realtime-BTqYEy8s.js"), $);
2669
+ async function Or() {
2670
+ return $ || ($ = await import("./realtime-C0Z8dXXH.js"), $);
2733
2671
  }
2734
- var oi = typeof window < "u", si = /* @__PURE__ */ new Set([
2672
+ var kr = typeof window < "u", Ar = /* @__PURE__ */ new Set([
2735
2673
  "list",
2736
2674
  "detail",
2737
2675
  "settings",
2738
2676
  "activity",
2739
2677
  "dev-export"
2740
- ]), ci = /* @__PURE__ */ new Set([
2678
+ ]), jr = /* @__PURE__ */ new Set([
2741
2679
  "comment",
2742
2680
  "draw",
2743
2681
  "highlight",
2744
2682
  "screenshot",
2745
2683
  "select",
2746
2684
  null
2747
- ]), li = 256, ui = "0.7.4";
2748
- function di(e) {
2685
+ ]), Mr = 256, Nr = "0.7.6";
2686
+ function Pr(e) {
2749
2687
  let t = e.trim().match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);
2750
2688
  return t ? [
2751
2689
  Number(t[1]),
@@ -2753,12 +2691,12 @@ function di(e) {
2753
2691
  Number(t[3] ?? 0)
2754
2692
  ] : null;
2755
2693
  }
2756
- function fi(e) {
2694
+ function Fr(e) {
2757
2695
  return /^v?\d+(?:\.\d+)?(?:\.\d+)?-/.test(e.trim());
2758
2696
  }
2759
- function pi(e, t) {
2760
- if (fi(e)) return !1;
2761
- let n = di(e), r = di(t);
2697
+ function Ir(e, t) {
2698
+ if (Fr(e)) return !1;
2699
+ let n = Pr(e), r = Pr(t);
2762
2700
  if (!n || !r) return !1;
2763
2701
  for (let e = 0; e < 3; e++) {
2764
2702
  let t = n[e] ?? 0, i = r[e] ?? 0;
@@ -2767,7 +2705,7 @@ function pi(e, t) {
2767
2705
  }
2768
2706
  return !1;
2769
2707
  }
2770
- var mi = class extends tt {
2708
+ var Lr = class extends et {
2771
2709
  get isProcessingQueue() {
2772
2710
  return this.queueGuard.current;
2773
2711
  }
@@ -2798,7 +2736,7 @@ var mi = class extends tt {
2798
2736
  }, this.config.ui = {
2799
2737
  ...this.config.ui,
2800
2738
  loadRemoteFonts: !1
2801
- }), oi && !this.config.environment && (this.config.environment = this.detectEnvironment()), this.apiClient = this.localDemo?.client ?? new ye(this.config), this.apiClient.setOnAuthExpired(() => this.handleAuthExpired()), this.state = Mt(), this.state.activeBranch = typeof e.branch == "string" && e.branch.trim().length <= 255 && !a(e.branch) && e.branch.trim() || null, this.requiresShortcut() && (this.state.isOverlayVisible = !1), this.screenshotProvider = e.screenshotProvider || null, this.ctx = {
2739
+ }), kr && !this.config.environment && (this.config.environment = this.detectEnvironment()), this.apiClient = this.localDemo?.client ?? new ve(this.config), this.apiClient.setOnAuthExpired(() => this.handleAuthExpired()), this.state = jt(), this.state.activeBranch = typeof e.branch == "string" && e.branch.trim().length <= 255 && !a(e.branch) && e.branch.trim() || null, this.requiresShortcut() && (this.state.isOverlayVisible = !1), this.screenshotProvider = e.screenshotProvider || null, this.ctx = {
2802
2740
  getState: () => this.getInternalState(),
2803
2741
  setState: (e) => this.setState(e),
2804
2742
  apiClient: this.apiClient,
@@ -2826,7 +2764,7 @@ var mi = class extends tt {
2826
2764
  mouseMoveHandler: this.mouseMoveHandler
2827
2765
  }, this.localDemo && (this.restoreDemoState(), this.localDemo.subscribe((e) => {
2828
2766
  e !== "persist" && this.restoreDemoState();
2829
- })), e.enabled !== !1 && oi && Promise.resolve().then(() => this.boot()).catch((e) => this.handleError(e));
2767
+ })), e.enabled !== !1 && kr && Promise.resolve().then(() => this.boot()).catch((e) => this.handleError(e));
2830
2768
  /* v8 ignore stop */
2831
2769
  }
2832
2770
  isLocalDemo() {
@@ -2836,7 +2774,7 @@ var mi = class extends tt {
2836
2774
  if (!this.localDemo || this.destroyed) return;
2837
2775
  let e = this.localDemo.getSession().expired, t = this.getInternalState().activeBranch ?? null;
2838
2776
  this.overlayBeforeTool = null, this.setState({
2839
- ...Mt(),
2777
+ ...jt(),
2840
2778
  currentUser: e ? null : { ...this.localDemo.user },
2841
2779
  isAuthenticated: !e,
2842
2780
  isOverlayVisible: !e,
@@ -2881,7 +2819,7 @@ var mi = class extends tt {
2881
2819
  e?.mode === "hold" && e.key && (this.holdActivationHandler = (e) => {
2882
2820
  if (this.destroyed || !this.matchesHoldKey(e)) return;
2883
2821
  let t = this.getInternalState().activeTool;
2884
- e.type === "keydown" && !t && !A() ? this.setTool("select") : e.type === "keyup" && t === "select" && this.setTool(null);
2822
+ e.type === "keydown" && !t && !j() ? this.setTool("select") : e.type === "keyup" && t === "select" && this.setTool(null);
2885
2823
  }, window.addEventListener("keydown", this.holdActivationHandler), window.addEventListener("keyup", this.holdActivationHandler), this.holdBlurHandler = () => {
2886
2824
  this.destroyed || this.getInternalState().activeTool === "select" && this.setTool(null);
2887
2825
  }, window.addEventListener("blur", this.holdBlurHandler)), this.toggleHandler = () => this.handleToggleRequest(), window.addEventListener("commentkit:toggle-overlay", this.toggleHandler), this.hashChangeHandler = () => this.handleDeepLink(), window.addEventListener("hashchange", this.hashChangeHandler), this.handleDeepLink(), !this.localDemo && (this.onlineHandler = () => {
@@ -2929,8 +2867,8 @@ var mi = class extends tt {
2929
2867
  };
2930
2868
  }
2931
2869
  let n = e.project?.sdkLatestVersion;
2932
- n && pi(n, "0.7.4") && (console.warn(`[CommentKit] You are using v${ui}. Update to v${n}: npm update @commentkit/comment-kit`), this.emit("sdk:outdated", {
2933
- current: ui,
2870
+ n && Ir(n, "0.7.6") && (console.warn(`[CommentKit] You are using v${Nr}. Update to v${n}: npm update @commentkit/comment-kit`), this.emit("sdk:outdated", {
2871
+ current: Nr,
2934
2872
  latest: n
2935
2873
  })), this.setState({
2936
2874
  project: e.project,
@@ -2965,6 +2903,7 @@ var mi = class extends tt {
2965
2903
  project: e.project ? structuredClone(e.project) : null,
2966
2904
  projectContext: e.projectContext ? structuredClone(e.projectContext) : null,
2967
2905
  comments: structuredClone(e.comments),
2906
+ commentQuery: e.commentQuery ? { ...e.commentQuery } : void 0,
2968
2907
  selectedComment: e.selectedComment ? structuredClone(e.selectedComment) : null,
2969
2908
  activeComment: e.activeComment ? structuredClone(e.activeComment) : null,
2970
2909
  activeDrawing: e.activeDrawing ? structuredClone(e.activeDrawing) : null,
@@ -3005,7 +2944,7 @@ var mi = class extends tt {
3005
2944
  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);
3006
2945
  let n = Object.keys(e);
3007
2946
  for (let [e, t] of this.sliceSubscribers) {
3008
- let r = kt[e];
2947
+ let r = Ot[e];
3009
2948
  if (n.some((e) => r.includes(e))) for (let n of t) try {
3010
2949
  n(this.state);
3011
2950
  } catch (t) {
@@ -3034,7 +2973,7 @@ var mi = class extends tt {
3034
2973
  return this.getWriteAccess().canWrite;
3035
2974
  }
3036
2975
  getWriteAccess() {
3037
- return Ze(this.config, this.getInternalState(), this.writeRestriction);
2976
+ return Xe(this.config, this.getInternalState(), this.writeRestriction);
3038
2977
  }
3039
2978
  requireCommentWrite() {
3040
2979
  let e = this.getWriteAccess();
@@ -3057,10 +2996,12 @@ var mi = class extends tt {
3057
2996
  };
3058
2997
  }
3059
2998
  async validateInvite(e) {
3060
- if (!(this.destroyed || this.localDemo)) return Ot(this.ctx, e, (e) => this.login(e), this.beginAuthRequest());
2999
+ if (this.destroyed || this.localDemo) return;
3000
+ let t = this.beginAuthRequest();
3001
+ return Dt(this.ctx, e, (e) => bt(this.ctx, e, t), t);
3061
3002
  }
3062
3003
  onSlice(e, t) {
3063
- if (!kt[e] || typeof t != "function" || this.destroyed) return () => {};
3004
+ if (!Ot[e] || typeof t != "function" || this.destroyed) return () => {};
3064
3005
  let n = this.sliceSubscribers.get(e);
3065
3006
  return n || (n = /* @__PURE__ */ new Set(), this.sliceSubscribers.set(e, n)), n.add(t), () => n.delete(t);
3066
3007
  }
@@ -3110,12 +3051,12 @@ var mi = class extends tt {
3110
3051
  }), this.emit("error", r);
3111
3052
  }
3112
3053
  async restorePersistedSession() {
3113
- this.config.persistence === "memory" && ut(this.config.projectId);
3114
- let e = this.initialAuthToken === void 0 ? this.config.persistence === "memory" ? void 0 : lt(this.config.projectId)?.token : this.initialAuthToken;
3054
+ this.config.persistence === "memory" && lt(this.config.projectId);
3055
+ let e = this.initialAuthToken === void 0 ? this.config.persistence === "memory" ? void 0 : ct(this.config.projectId)?.token : this.initialAuthToken;
3115
3056
  if (this.initialAuthToken = void 0, e === void 0) return;
3116
3057
  let t = () => !this.destroyed && this.authRequestRevision === 0;
3117
3058
  try {
3118
- let { verifyAndRestoreToken: n } = await import("./token-session-D0Y_HZw0.js");
3059
+ let { verifyAndRestoreToken: n } = await import("./token-session-DplW5QDx.js");
3119
3060
  await n(this.ctx, e, t, this.config.persistence !== "memory") && await this.afterAuthenticated();
3120
3061
  } catch {
3121
3062
  t() && this.handleAuthExpired();
@@ -3128,14 +3069,14 @@ var mi = class extends tt {
3128
3069
  projectContext: null,
3129
3070
  activities: [],
3130
3071
  seenThreadIds: /* @__PURE__ */ new Set()
3131
- }), br(this.ctx), this.getFeatures().realtime && this.initializeWebSocket(), await Promise.all([this.loadComments(), this.reloadProjectContext()]), this.handleDeepLink(), this.getInternalState().pendingMutations.length > 0 && this.scheduleRetry());
3072
+ }), yr(this.ctx), this.getFeatures().realtime && this.initializeWebSocket(), await Promise.all([this.loadComments(), this.reloadProjectContext()]), this.handleDeepLink(), this.getInternalState().pendingMutations.length > 0 && this.scheduleRetry());
3132
3073
  }
3133
3074
  beginAuthRequest() {
3134
3075
  let e = ++this.authRequestRevision;
3135
3076
  return () => !this.destroyed && e === this.authRequestRevision;
3136
3077
  }
3137
3078
  async login(e) {
3138
- if (!(this.destroyed || this.localDemo)) return xt(this.ctx, e, this.beginAuthRequest());
3079
+ if (!(this.destroyed || this.localDemo)) return this.config.inviteToken ? this.validateInvite(e) : bt(this.ctx, e, this.beginAuthRequest());
3139
3080
  }
3140
3081
  async verifyOtp(e) {
3141
3082
  if (this.destroyed || this.localDemo) return;
@@ -3150,13 +3091,13 @@ var mi = class extends tt {
3150
3091
  return;
3151
3092
  }
3152
3093
  let n = this.getInternalState().currentUser?.id;
3153
- return St(this.ctx, e, {
3094
+ return xt(this.ctx, e, {
3154
3095
  isCurrent: this.beginAuthRequest(),
3155
3096
  onAuthenticated: async () => {
3156
3097
  await this.afterAuthenticated(n);
3157
3098
  },
3158
3099
  onSuccess: () => {
3159
- this.otpFailedAttempts = 0, this.otpCooldownUntil = 0;
3100
+ this.config.inviteToken = void 0, this.otpFailedAttempts = 0, this.otpCooldownUntil = 0;
3160
3101
  },
3161
3102
  onWrongOtp: () => {
3162
3103
  if (this.otpFailedAttempts += 1, this.otpFailedAttempts >= 3) {
@@ -3167,24 +3108,26 @@ var mi = class extends tt {
3167
3108
  });
3168
3109
  }
3169
3110
  cancelOtp() {
3170
- this.destroyed || (this.authRequestRevision++, Ct(this.ctx));
3111
+ this.destroyed || (this.authRequestRevision++, St(this.ctx));
3171
3112
  }
3172
3113
  async resendOtp() {
3173
- if (!(this.destroyed || this.localDemo)) return wt(this.ctx, this.beginAuthRequest());
3114
+ if (this.destroyed || this.localDemo) return;
3115
+ let e = this.getInternalState().otpEmail;
3116
+ return this.config.inviteToken && e ? this.validateInvite(e) : Ct(this.ctx, this.beginAuthRequest());
3174
3117
  }
3175
3118
  logout() {
3176
3119
  this.destroyed || (this.authRequestRevision++, this.localDemo ? (this.setTool(null), this.setState({
3177
3120
  isOverlayVisible: !1,
3178
3121
  isSidebarVisible: !1
3179
- })) : (this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), this.writeRestriction = null, this.setState({ projectContext: null }), this.overlayBeforeTool = null, Tt(this.ctx, () => {
3122
+ })) : (this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), this.writeRestriction = null, this.setState({ projectContext: null }), this.overlayBeforeTool = null, wt(this.ctx, () => {
3180
3123
  this.disconnectRealtime(!0);
3181
3124
  })));
3182
3125
  }
3183
3126
  handleAuthExpired() {
3184
- this.destroyed || (this.authRequestRevision++, this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), this.writeRestriction = null, this.setState({ projectContext: null }), this.overlayBeforeTool = null, this.disconnectRealtime(!0), Et(this.ctx));
3127
+ this.destroyed || (this.authRequestRevision++, this.sessionRevision++, this.draftUploads = /* @__PURE__ */ new WeakMap(), this.writeRestriction = null, this.setState({ projectContext: null }), this.overlayBeforeTool = null, this.disconnectRealtime(!0), Tt(this.ctx));
3185
3128
  }
3186
3129
  toggleLoginModal() {
3187
- this.destroyed || this.localDemo || Dt(this.ctx);
3130
+ this.destroyed || this.localDemo || (this.getInternalState().isLoginModalVisible && this.cancelOtp(), Et(this.ctx));
3188
3131
  }
3189
3132
  requiresShortcut() {
3190
3133
  return this.localDemo ? !0 : this.config.environment !== "development";
@@ -3204,7 +3147,7 @@ var mi = class extends tt {
3204
3147
  this.destroyed || this.setState({ isSidebarVisible: !this.getInternalState().isSidebarVisible });
3205
3148
  }
3206
3149
  setTool(e) {
3207
- if (this.destroyed || !ci.has(e) || this.localDemo && e !== null && e !== "comment" && e !== "select") return;
3150
+ if (this.destroyed || !jr.has(e) || this.localDemo && e !== null && e !== "comment" && e !== "select") return;
3208
3151
  let t = this.getInternalState();
3209
3152
  if (e !== null && e !== "select" && !this.requireCommentWrite()) return;
3210
3153
  if (!t.isAuthenticated && e !== "select" && e !== null) {
@@ -3275,10 +3218,26 @@ var mi = class extends tt {
3275
3218
  };
3276
3219
  }
3277
3220
  async loadComments() {
3278
- return ln(this.commentsRequestContext(++this.commentsFetchRevision));
3221
+ return cn(this.commentsRequestContext(++this.commentsFetchRevision));
3279
3222
  }
3280
3223
  async loadMoreComments() {
3281
- this.destroyed || await un(this.commentsRequestContext(this.commentsFetchRevision), this.loadMoreGuard);
3224
+ this.destroyed || await ln(this.commentsRequestContext(this.commentsFetchRevision), this.loadMoreGuard);
3225
+ }
3226
+ async setCommentQuery(e) {
3227
+ if (this.destroyed || !this.getInternalState().isAuthenticated || this.localDemo) return;
3228
+ let t = {
3229
+ ...e,
3230
+ search: e.search?.trim().slice(0, 200) || void 0
3231
+ };
3232
+ if (JSON.stringify(t) !== JSON.stringify(this.getInternalState().commentQuery)) return this.setState({
3233
+ commentQuery: t,
3234
+ pagination: null,
3235
+ selectedComment: null
3236
+ }), this.loadComments();
3237
+ }
3238
+ async loadEarlierReplies() {
3239
+ let e = this.getInternalState(), t = e.comments.find((t) => t.id === e.selectedComment?.id);
3240
+ if (!(this.destroyed || e.loadingThreadId || !t?.repliesPagination?.nextCursor)) return un(this.operationContext(), t.id, t.repliesPagination.nextCursor);
3282
3241
  }
3283
3242
  async reloadComments() {
3284
3243
  if (!this.destroyed) return this.loadComments();
@@ -3382,10 +3341,10 @@ var mi = class extends tt {
3382
3341
  });
3383
3342
  return;
3384
3343
  }
3385
- let s = o?.[nt];
3344
+ let s = o?.[tt];
3386
3345
  return dn(this.operationContext(s), this.operationCallbacks(s), this.activeMutations, e, t, n, r, i, a, {
3387
3346
  ...o,
3388
- branch: o?.branch ?? F(this.ctx)
3347
+ branch: o?.branch ?? I(this.ctx)
3389
3348
  });
3390
3349
  }
3391
3350
  async updateComment(e, t) {
@@ -3396,7 +3355,7 @@ var mi = class extends tt {
3396
3355
  }
3397
3356
  async addReply(e, t, n) {
3398
3357
  if (this.destroyed || !this.requireCommentWrite()) return;
3399
- let { [nt]: r, ...i } = n ?? {};
3358
+ let { [tt]: r, ...i } = n ?? {};
3400
3359
  return mn(this.operationContext(r), this.operationCallbacks(r), e, t, n ? i : void 0);
3401
3360
  }
3402
3361
  async updateReply(e, t, n, r) {
@@ -3405,17 +3364,27 @@ var mi = class extends tt {
3405
3364
  async deleteReply(e, t) {
3406
3365
  if (!this.destroyed && this.requireCommentWrite()) return gn(this.operationContext(), e, t);
3407
3366
  }
3367
+ requireThreadStatus(e, t = !1) {
3368
+ let n = this.getInternalState();
3369
+ if (n.projectContext?.permissions?.accessScope !== "project") return !0;
3370
+ let r = n.comments.find((t) => t.id === e)?.author.id === n.currentUser?.id;
3371
+ return !t && r ? !0 : (this.handleError({
3372
+ error: "forbidden",
3373
+ message: t ? "Only workspace members can mark feedback complete." : "You can only resolve or reopen your own feedback.",
3374
+ code: 403
3375
+ }), !1);
3376
+ }
3408
3377
  async resolveComment(e) {
3409
- if (!this.destroyed && this.requireCommentWrite()) return _n(this.operationContext(), this.operationCallbacks(), e);
3378
+ if (!this.destroyed && this.requireCommentWrite() && this.requireThreadStatus(e)) return _n(this.operationContext(), this.operationCallbacks(), e);
3410
3379
  }
3411
3380
  async unresolveComment(e) {
3412
- if (!this.destroyed && this.requireCommentWrite()) return vn(this.operationContext(), this.operationCallbacks(), e);
3381
+ if (!this.destroyed && this.requireCommentWrite() && this.requireThreadStatus(e)) return vn(this.operationContext(), this.operationCallbacks(), e);
3413
3382
  }
3414
3383
  selectComment(e) {
3415
- this.destroyed || Sn(this.operationContext(), e);
3384
+ this.destroyed || (Sn(this.operationContext(), e), e?.detailLoaded === !1 && !this.localDemo && un(this.operationContext(), e.id));
3416
3385
  }
3417
3386
  async completeComment(e) {
3418
- if (!this.destroyed && this.requireCommentWrite()) return yn(this.operationContext(), this.operationCallbacks(), e);
3387
+ if (!this.destroyed && this.requireCommentWrite() && this.requireThreadStatus(e, !0)) return yn(this.operationContext(), this.operationCallbacks(), e);
3419
3388
  }
3420
3389
  async reactToComment(e, t, n) {
3421
3390
  if (this.destroyed || !this.requireCommentWrite()) return;
@@ -3434,31 +3403,31 @@ var mi = class extends tt {
3434
3403
  }
3435
3404
  hydrateOfflineQueue() {
3436
3405
  if (this.config.persistence === "memory") return;
3437
- let e = hr(this.config.projectId);
3406
+ let e = mr(this.config.projectId);
3438
3407
  if (e.length > 0) {
3439
3408
  let t = this.getInternalState().pendingMutations, n = new Set(t.map((e) => e.id)), r = [...t, ...e.filter((e) => !n.has(e.id))];
3440
- this.setState({ pendingMutations: r }), br(this.ctx), this.getInternalState().isOnline && this.scheduleRetry();
3409
+ this.setState({ pendingMutations: r }), yr(this.ctx), this.getInternalState().isOnline && this.scheduleRetry();
3441
3410
  }
3442
- this.offlinePersistUnsub?.(), this.offlinePersistUnsub = this.select((e) => e.pendingMutations, (e) => mr(this.config.projectId, e));
3411
+ this.offlinePersistUnsub?.(), this.offlinePersistUnsub = this.select((e) => e.pendingMutations, (e) => pr(this.config.projectId, e));
3443
3412
  }
3444
3413
  shouldQueueMutation(e) {
3445
- return !this.localDemo && xr(this.getInternalState(), e);
3414
+ return !this.localDemo && br(this.getInternalState(), e);
3446
3415
  }
3447
3416
  queueMutation(e, t, n) {
3448
- return Sr(this.ctx, () => this.scheduleRetry(), e, t, n);
3417
+ return xr(this.ctx, () => this.scheduleRetry(), e, t, n);
3449
3418
  }
3450
3419
  scheduleRetry() {
3451
- Cr(this.ctx, this.retryTimerRef, () => this.processOfflineQueue());
3420
+ Sr(this.ctx, this.retryTimerRef, () => this.processOfflineQueue());
3452
3421
  }
3453
3422
  async processOfflineQueue() {
3454
- this.canWriteComments() && await wr(this.operationContext(), this.queueGuard, () => this.scheduleRetry(), (e) => this.executeMutation(e));
3423
+ this.canWriteComments() && await Cr(this.operationContext(), this.queueGuard, () => this.scheduleRetry(), (e) => this.executeMutation(e));
3455
3424
  }
3456
3425
  async executeMutation(e) {
3457
3426
  let t = this.operationContext();
3458
3427
  try {
3459
- await Or(t, e);
3428
+ await Dr(t, e);
3460
3429
  } catch (e) {
3461
- throw e instanceof T && e.code === 402 && t.handleError(e), e;
3430
+ throw e instanceof E && e.code === 402 && t.handleError(e), e;
3462
3431
  }
3463
3432
  }
3464
3433
  getPendingMutationCount() {
@@ -3471,7 +3440,7 @@ var mi = class extends tt {
3471
3440
  !this.destroyed && this.getInternalState().isAuthenticated && (this.wsManager ? this.wsManager.reconnect() : this.initializeWebSocket());
3472
3441
  }
3473
3442
  markThreadSeen(e) {
3474
- if (this.destroyed || typeof e != "string" || !e.trim() || e.length > li) return;
3443
+ if (this.destroyed || typeof e != "string" || !e.trim() || e.length > Mr) return;
3475
3444
  let t = new Set(this.getInternalState().seenThreadIds);
3476
3445
  if (t.add(e), t.size > 1e3) {
3477
3446
  let e = Array.from(t);
@@ -3484,7 +3453,7 @@ var mi = class extends tt {
3484
3453
  return typeof e != "string" || !e.trim() ? !1 : !this.getInternalState().seenThreadIds.has(e);
3485
3454
  }
3486
3455
  setPanelView(e) {
3487
- !this.destroyed && si.has(e) && this.setState({ panelView: e });
3456
+ !this.destroyed && Ar.has(e) && this.setState({ panelView: e });
3488
3457
  }
3489
3458
  toggleShortcutsOverlay() {
3490
3459
  this.destroyed || this.setState({ isShortcutsOverlayVisible: !this.getInternalState().isShortcutsOverlayVisible });
@@ -3531,7 +3500,7 @@ var mi = class extends tt {
3531
3500
  else if (this.getInternalState().isAuthenticated && n.length <= 256 && this.deepLinkRequest !== e) {
3532
3501
  this.deepLinkRequest = e;
3533
3502
  let t = this.sessionRevision;
3534
- this.apiClient.getComment(n).then(async (r) => {
3503
+ this.apiClient.getComment(n, { repliesLimit: 50 }).then(async (r) => {
3535
3504
  if (this.destroyed || t !== this.sessionRevision || window.location.hash !== e || r.id !== n) return;
3536
3505
  let i = this.getInternalState().activeBranch;
3537
3506
  i && i !== r.branch && await this.setBranch(r.branch ?? null), !(this.destroyed || t !== this.sessionRevision || window.location.hash !== e) && (this.setState({
@@ -3560,42 +3529,67 @@ var mi = class extends tt {
3560
3529
  !this.destroyed && this.requireCommentWrite() && this.wsManager?.sendDrawingStroke(e);
3561
3530
  }
3562
3531
  async captureScreenshot(e) {
3563
- return this.destroyed ? null : ni(this.ctx, this.screenshotProvider, e);
3532
+ if (this.destroyed) return null;
3533
+ let { captureScreenshot: t } = await import("./screenshot-B-ZfFItT.js");
3534
+ return this.destroyed ? null : t(this.ctx, this.screenshotProvider, e);
3564
3535
  }
3565
3536
  async uploadScreenshot(e, t, n) {
3566
- return this.destroyed || !this.requireCommentWrite() ? null : ri(this.operationContext(), e, t, n);
3537
+ if (this.destroyed || !this.requireCommentWrite()) return null;
3538
+ let r = this.operationContext(), { uploadScreenshot: i } = await import("./screenshot-B-ZfFItT.js");
3539
+ return this.destroyed || r.isCurrent?.() === !1 || !this.requireCommentWrite() ? null : i(r, e, t, n);
3567
3540
  }
3568
3541
  setActiveScreenshot(e) {
3569
3542
  this.destroyed || this.setState({ activeScreenshot: e });
3570
3543
  }
3571
3544
  async uploadFiles(e, t) {
3572
- return this.destroyed || !this.requireCommentWrite() ? [] : ii(this.ctx, e, t);
3545
+ if (this.destroyed || !this.requireCommentWrite()) return [];
3546
+ let n = this.operationContext(), { uploadFiles: r } = await import("./screenshot-B-ZfFItT.js");
3547
+ return this.destroyed || n.isCurrent?.() === !1 || !this.requireCommentWrite() ? [] : r(n, e, t);
3548
+ }
3549
+ requireAgentExport() {
3550
+ if (this.getInternalState().projectContext?.permissions.canExportAgentContext === !1) throw new E("forbidden", "Agent handoff is available to workspace members.", 403);
3573
3551
  }
3574
3552
  getAgentContext(e) {
3575
- return O(this.getInternalState(), e);
3553
+ return this.requireAgentExport(), k(this.getInternalState(), e);
3576
3554
  }
3577
3555
  async getAgentContextAsync(e) {
3578
- let t = O(this.getInternalState(), e), n = this.localDemo?.getRevision(), r = await Ue(t);
3579
- return this.localDemo?.checkExpiry(), this.localDemo && n !== this.localDemo.getRevision() ? O(this.getInternalState(), e) : r;
3556
+ this.requireAgentExport();
3557
+ let t = this.getInternalState(), n = k(t, e);
3558
+ if (!this.localDemo && t.isAuthenticated) {
3559
+ let r = new Set(n.comments.map((e) => e.id)), i = t.comments.filter((e) => r.has(e.id) && e.detailLoaded === !1), a = /* @__PURE__ */ new Map(), o = this.sessionRevision;
3560
+ for (let e = 0; e < i.length; e += 4) {
3561
+ let t = await Promise.all(i.slice(e, e + 4).map((e) => this.apiClient.getComment(e.id, { repliesLimit: 12 })));
3562
+ if (this.destroyed || o !== this.sessionRevision || !this.getInternalState().isAuthenticated) throw new E("unauthorized", "Sign in again to copy feedback.", 401);
3563
+ for (let e of t) a.set(e.id, e);
3564
+ }
3565
+ a.size && (n = k({
3566
+ ...t,
3567
+ comments: t.comments.map((e) => a.get(e.id) ?? e)
3568
+ }, e));
3569
+ }
3570
+ let r = this.localDemo?.getRevision(), i = await He(n);
3571
+ return this.localDemo?.checkExpiry(), this.localDemo && r !== this.localDemo.getRevision() ? k(this.getInternalState(), e) : i;
3580
3572
  }
3581
3573
  formatAgentContext(e) {
3582
- return k(this.getAgentContext(e));
3574
+ return A(this.getAgentContext(e));
3583
3575
  }
3584
3576
  async formatAgentContextAsync(e) {
3585
- return k(await this.getAgentContextAsync(e));
3577
+ return A(await this.getAgentContextAsync(e));
3586
3578
  }
3587
3579
  async copyAgentContext(e) {
3588
3580
  if (this.destroyed) return "";
3589
- let t = await this.getAgentContextAsync(e), n = k(t);
3590
- return await Xe(n, t), this.emit("agent:context-copied", {
3581
+ let t = await this.getAgentContextAsync(e), n = A(t);
3582
+ return await Ye(n, t), this.emit("agent:context-copied", {
3591
3583
  commentCount: t.comments.length,
3592
3584
  sourceResolved: t.sourceResolved
3593
3585
  }), n;
3594
3586
  }
3595
3587
  async grabElement(e, t) {
3596
3588
  if (this.destroyed) return null;
3597
- let { grabElement: n } = await import("./dev-grab-BJLZZ2xU.js");
3589
+ this.requireAgentExport();
3590
+ let { grabElement: n } = await import("./dev-grab-O8q25zar.js");
3598
3591
  if (this.destroyed) return null;
3592
+ this.requireAgentExport();
3599
3593
  let r = await n(e, this.ctx, this.screenshotProvider, t);
3600
3594
  return this.destroyed ? null : (r && this.emit("agent:element-grabbed", {
3601
3595
  source: r.element.source?.filePath ?? null,
@@ -3604,8 +3598,10 @@ var mi = class extends tt {
3604
3598
  }
3605
3599
  async grabElements(e, t) {
3606
3600
  if (this.destroyed) return null;
3607
- let { grabElements: n } = await import("./dev-grab-BJLZZ2xU.js");
3601
+ this.requireAgentExport();
3602
+ let { grabElements: n } = await import("./dev-grab-O8q25zar.js");
3608
3603
  if (this.destroyed) return null;
3604
+ this.requireAgentExport();
3609
3605
  let r = await n(e, this.ctx, this.screenshotProvider, t);
3610
3606
  return this.destroyed ? null : (r && this.emit("agent:elements-grabbed", { count: r.results.length }), r);
3611
3607
  }
@@ -3618,16 +3614,16 @@ var mi = class extends tt {
3618
3614
  }
3619
3615
  }
3620
3616
  handleToggleRequest() {
3621
- this.destroyed || A() || Rn(this.getInternalState(), this.kbdCallbacks);
3617
+ this.destroyed || j() || Ln(this.getInternalState(), this.kbdCallbacks);
3622
3618
  }
3623
3619
  handleKeyboardShortcuts(e) {
3624
- if (!(this.destroyed || A())) {
3620
+ if (!(this.destroyed || j())) {
3625
3621
  if (e.key === "Escape") {
3626
3622
  if (this.escapeBlockers.size > 0) return;
3627
3623
  let t = e.composedPath()[0];
3628
3624
  if (t instanceof Element && t.getRootNode() === document && t.closest("[data-commentkit-ui], [data-commentkit-ignore]")) return;
3629
3625
  }
3630
- zn(e, this.getInternalState(), this.kbdCallbacks);
3626
+ Rn(e, this.getInternalState(), this.kbdCallbacks);
3631
3627
  }
3632
3628
  }
3633
3629
  matchesHoldKey(e) {
@@ -3641,7 +3637,7 @@ var mi = class extends tt {
3641
3637
  };
3642
3638
  }
3643
3639
  initializeWebSocket() {
3644
- this.destroyed || this.localDemo || ai().then((e) => {
3640
+ this.destroyed || this.localDemo || Or().then((e) => {
3645
3641
  this.destroyed || this.getInternalState().isAuthenticated && (this.syncRealtimeRefs(), e.initializeWebSocket(this.ctx, this.realtimeRefs, {
3646
3642
  capture: () => this.commentsRequestContext(this.commentsFetchRevision),
3647
3643
  subscribe: (e) => this.on("state:changed", e)
@@ -3678,7 +3674,7 @@ var mi = class extends tt {
3678
3674
  this.removeMouseMoveListener(), this.syncRealtimeRefs();
3679
3675
  }
3680
3676
  destroy() {
3681
- this.destroyed || (this.destroyed = !0, this.initialAuthToken = void 0, oi && (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());
3677
+ this.destroyed || (this.destroyed = !0, this.initialAuthToken = void 0, kr && (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());
3682
3678
  }
3683
3679
  };
3684
- export { ye as _, yt as a, w as b, nt as c, Ze as d, Ye as f, Te as g, k as h, bt as i, tt as l, O as m, ui as n, ct as o, Xe as p, ni as r, j as s, mi as t, A as u, T as v, xe as x, be as y };
3680
+ export { ve as _, vt as a, T as b, tt as c, Xe as d, Je as f, we as g, A as h, yt as i, et as l, k as m, Nr as n, st as o, Ye as p, I as r, M as s, Lr as t, j as u, E as v, be as x, ye as y };