@commentkit/comment-kit 0.7.3 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +2 -2
  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-DgqxkHy8.js +1085 -0
  13. package/dist/shared/{attachment-refresh-agUheZPF.js → attachment-refresh-DRX7dKDI.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/{capture-colors-CxSLsU5-.js → capture-colors-D0uLr-vZ.js} +12 -2
  17. package/dist/shared/{comment-drawing-canvas-B3zqdIZH.js → comment-drawing-canvas-hSdcLShI.js} +2 -2
  18. package/dist/shared/{comment-icon-4SQd3nlz.js → comment-icon-D8JTCEJ7.js} +109 -110
  19. package/dist/shared/{comment-image-lightbox-j9y3Klh6.js → comment-image-lightbox-4zroOCCG.js} +7 -7
  20. package/dist/shared/{comment-images-content-aJrMaOi9.js → comment-images-content-D4hTya6e.js} +28 -28
  21. package/dist/shared/{comment-kit-core-Bsyydwpk.js → comment-kit-core-D068rcdY.js} +467 -503
  22. package/dist/shared/{comment-kit-ui-qKjCHHOy.js → comment-kit-ui-BDzNt0jv.js} +5078 -5254
  23. package/dist/shared/{comment-screenshot-annotator-aDtgMbBF.js → comment-screenshot-annotator-BGnu_NgP.js} +2 -2
  24. package/dist/shared/{comment-screenshot-overlay-B-rAubia.js → comment-screenshot-overlay-BCRmojWB.js} +17 -14
  25. package/dist/shared/{dev-export-panel-mrxmtzei.js → dev-export-panel-CYmUKmIV.js} +3 -3
  26. package/dist/shared/{dev-grab-Cc-lJYBv.js → dev-grab-BYsCpsGI.js} +48 -47
  27. package/dist/shared/dist-D9A5k-N4.js +617 -0
  28. package/dist/shared/{element-selector-4TxTAXHK.js → element-selector-79Oo5pit.js} +4 -4
  29. package/dist/shared/{mount-ui-Dbqe5VsO.js → mount-ui-DuHk132g.js} +4 -4
  30. package/dist/shared/{pusher-zAMukOay.js → pusher-3jyUauYd.js} +1 -1
  31. package/dist/shared/{realtime-t5o6fk6w.js → realtime-DspH16g5.js} +41 -28
  32. package/dist/shared/{realtime-recovery-BSVMwsXJ.js → realtime-recovery-BjlV-ewc.js} +57 -30
  33. package/dist/shared/screenshot-BIuEaRiu.js +199 -0
  34. package/dist/shared/{separator-aphZiRoJ.js → separator-UhJb0Row.js} +1222 -1288
  35. package/dist/shared/{shadow-root-DlfbvZF9.js → shadow-root-3-yGIhMs.js} +3 -5
  36. package/dist/shared/{token-session-ZzSO1tEl.js → token-session-_Pi4fOEi.js} +1 -1
  37. package/dist/shared/{useRender-D1z_X_BY.js → useRender-Uxk1OPK-.js} +1 -1
  38. package/dist/shared/{useValueChanged-CrzfD8l-.js → useValueChanged-DKq5cMot.js} +13 -13
  39. package/dist/shared/{websocket-manager-DGN8T9mq.js → websocket-manager-CvgZSo_L.js} +2 -2
  40. package/dist/solid.es.js +2 -2
  41. package/dist/svelte.es.js +2 -2
  42. package/dist/types/core/api-client.d.ts +17 -9
  43. package/dist/types/core/comment-kit-core.d.ts +4 -2
  44. package/dist/types/core/types.d.ts +37 -4
  45. package/dist/vue.es.js +2 -2
  46. package/docs/api-reference.md +29 -17
  47. package/package.json +1 -1
  48. package/dist/shared/ShadowRootContext-CjciYxVN.js +0 -13
  49. package/dist/shared/annotation-toolbar-XpqojzM2.js +0 -1094
  50. package/dist/shared/dist-De294MVF.js +0 -623
@@ -1,6 +1,6 @@
1
- import { i as e, n as t, r as n, t as r } from "./websocket-manager-DGN8T9mq.js";
1
+ import { i as e, n as t, r as n, t as r } from "./websocket-manager-CvgZSo_L.js";
2
2
  import { a as i, d as a, i as o, l as s, o as c } from "./validation-3wbbbuX0.js";
3
- import { s as l } from "./comment-kit-core-Bsyydwpk.js";
3
+ import { s as l } from "./comment-kit-core-D068rcdY.js";
4
4
  import { o as u } from "./dom-Bhf4WFtY.js";
5
5
  import { i as d } from "./text-B4HHZNaa.js";
6
6
  var f = l.ID, p = l.CONTENT, m = l.NAME, h = l.EMAIL, g = l.PAGE, _ = l.EMOJI, v = l.ONLINE_USERS, y = l.REACTION_COUNT, b = 33, x = 1e3, S = l.CURSOR_EMITS_PER_SEC;
@@ -165,11 +165,18 @@ function q(t, n, i) {
165
165
  t.setState({ connectionStatus: "error" }), t.handleError(e);
166
166
  return;
167
167
  }
168
- let l = n.wsUnsubscribers, f = n.wsManager, p, m, h = !1, g = () => m ??= import("./realtime-recovery-BSVMwsXJ.js").then((e) => {
168
+ let l = n.wsUnsubscribers, f = n.wsManager, p, m, h = !1, g = () => m ??= import("./realtime-recovery-BjlV-ewc.js").then((e) => {
169
169
  if (!h && i && G(n, f)) return p = e.createRealtimeRecovery(t, i, () => G(n, f), z), p;
170
170
  }).catch((e) => {
171
171
  m = void 0, h || t.handleError(e);
172
- });
172
+ }), _ = (e, n) => {
173
+ g().then((r) => {
174
+ t.getState().commentQuery ? r?.refreshWindow() : r?.refreshThread({
175
+ commentId: e,
176
+ event: n
177
+ });
178
+ });
179
+ };
173
180
  l.push(() => {
174
181
  h = !0, p?.dispose();
175
182
  }), l.push(f.on("subscribed", () => {
@@ -187,21 +194,25 @@ function q(t, n, i) {
187
194
  })), l.push(f.on("comment:resolved", (e) => {
188
195
  if (!G(n, f)) return;
189
196
  let r = z(e, t.getState().currentUser?.id);
190
- r && (K(t, r), t.emit("comment:resolved", r));
197
+ r && (i ? _(r.id, "comment:updated") : (K(t, r), t.emit("comment:resolved", r)));
191
198
  })), l.push(f.on("comment:completed", (e) => {
192
199
  if (!G(n, f)) return;
193
200
  let r = z(e, t.getState().currentUser?.id);
194
- r && (K(t, r), t.emit("comment:completed", r));
201
+ r && (i ? _(r.id, "comment:updated") : (K(t, r), t.emit("comment:completed", r)));
195
202
  })), l.push(f.on("comment:created", (e) => {
196
203
  if (!G(n, f)) return;
197
204
  let r = z(e, t.getState().currentUser?.id);
198
205
  if (!r) return;
199
- let i = t.getState().activeBranch;
200
- i && r.branch !== i || t.getState().comments.find((e) => e.id === r.id) || (t.setState({ comments: [...t.getState().comments, r] }), t.emit("comment:created", r));
206
+ if (i) {
207
+ _(r.id, "comment:created");
208
+ return;
209
+ }
210
+ let a = t.getState().activeBranch;
211
+ a && r.branch !== a || t.getState().comments.find((e) => e.id === r.id) || (t.setState({ comments: [...t.getState().comments, r] }), t.emit("comment:created", r));
201
212
  })), l.push(f.on("comment:updated", (e) => {
202
213
  if (!G(n, f)) return;
203
214
  let r = z(e, t.getState().currentUser?.id);
204
- r && (K(t, r), t.emit("comment:updated", r));
215
+ r && (i ? _(r.id, "comment:updated") : (K(t, r), t.emit("comment:updated", r)));
205
216
  })), l.push(f.on("comment:deleted", (e) => {
206
217
  if (!G(n, f) || !c(e) || !k(e.id)) return;
207
218
  let r = e.id.trim();
@@ -213,18 +224,23 @@ function q(t, n, i) {
213
224
  if (!G(n, f) || !c(e) || !k(e.commentId)) return;
214
225
  let r = B(e.reply, t.getState().currentUser?.id);
215
226
  if (!r) return;
216
- let i = e.commentId.trim(), a = t.getState().comments.map((e) => e.id !== i || e.replies.some((e) => e.id === r.id) ? e : {
227
+ let a = e.commentId.trim();
228
+ if (i) {
229
+ _(a, "comment:updated");
230
+ return;
231
+ }
232
+ let o = t.getState().comments.map((e) => e.id !== a || e.replies.some((e) => e.id === r.id) ? e : {
217
233
  ...e,
218
234
  status: "open",
219
235
  resolvedAt: void 0,
220
236
  completedAt: void 0,
221
237
  replies: [...e.replies, r]
222
238
  });
223
- t.setState({ comments: a });
224
- let o = a.find((e) => e.id === i);
225
- o && t.emit("comment:updated", o);
239
+ t.setState({ comments: o });
240
+ let s = o.find((e) => e.id === a);
241
+ s && t.emit("comment:updated", s);
226
242
  }));
227
- let _ = (e, t, n) => {
243
+ let v = (e, t, n) => {
228
244
  let r = (e ?? []).filter((e) => U(e.emoji) && Number.isInteger(e.count) && e.count >= 0 && e.count <= y), i = r.findIndex((e) => e.emoji === t);
229
245
  if (i !== -1) {
230
246
  let e = r[i];
@@ -242,17 +258,14 @@ function q(t, n, i) {
242
258
  reacted: n
243
259
  });
244
260
  return r;
245
- }, v = (e, t, n) => (e ?? []).filter((e) => U(e.emoji) && Number.isInteger(e.count) && e.count > 0 && e.count <= y).map((e) => e.emoji === t ? {
261
+ }, w = (e, t, n) => (e ?? []).filter((e) => U(e.emoji) && Number.isInteger(e.count) && e.count > 0 && e.count <= y).map((e) => e.emoji === t ? {
246
262
  ...e,
247
263
  count: n ? e.count : e.count - 1,
248
264
  reacted: !n && e.reacted
249
- } : e).filter((e) => e.count > 0), w = (e, r) => {
265
+ } : e).filter((e) => e.count > 0), T = (e, r) => {
250
266
  if (!G(n, f) || !c(e) || !k(e.commentId) || !U(e.emoji) || !k(e.userId)) return;
251
267
  let a = e.commentId.trim(), o = k(e.replyId) ? e.replyId.trim() : null, s = e.emoji.trim(), l = e.userId.trim() === t.getState().currentUser?.id;
252
- l && i ? g().then((e) => e?.refreshThread({
253
- commentId: a,
254
- event: "comment:updated"
255
- })) : t.setState({ comments: t.getState().comments.map((e) => e.id === a ? o === null ? {
268
+ i ? _(a, "comment:updated") : t.setState({ comments: t.getState().comments.map((e) => e.id === a ? o === null ? {
256
269
  ...e,
257
270
  reactions: r(e.reactions, s, l)
258
271
  } : {
@@ -263,22 +276,22 @@ function q(t, n, i) {
263
276
  } : e)
264
277
  } : e) });
265
278
  };
266
- l.push(f.on("reaction:added", (e) => w(e, _))), l.push(f.on("reaction:removed", (e) => w(e, v)));
267
- let T = /* @__PURE__ */ new Map(), E = 0, D = 0;
279
+ l.push(f.on("reaction:added", (e) => T(e, v))), l.push(f.on("reaction:removed", (e) => T(e, w)));
280
+ let E = /* @__PURE__ */ new Map(), D = 0, O = 0;
268
281
  l.push(f.on("cursor:move", (e) => {
269
282
  if (!G(n, f) || !s.cursors) return;
270
283
  let r = V(e);
271
284
  if (!r) return;
272
- let i = Date.now(), a = r.user.id, o = T.get(a);
273
- if (o === void 0 && T.size >= s.maxRenderedCursors) {
285
+ let i = Date.now(), a = r.user.id, o = E.get(a);
286
+ if (o === void 0 && E.size >= s.maxRenderedCursors) {
274
287
  let e, t = Infinity;
275
- for (let [n, r] of T) r < t && (t = r, e = n);
276
- if (e !== void 0 && i - t >= b) T.delete(e);
288
+ for (let [n, r] of E) r < t && (t = r, e = n);
289
+ if (e !== void 0 && i - t >= b) E.delete(e);
277
290
  else return;
278
291
  }
279
- o !== void 0 && i - o < b || (i - E >= x && (E = i, D = 0), !(D >= S) && (D++, T.set(a, i), t.emit("cursor:move", r)));
292
+ o !== void 0 && i - o < b || (i - D >= x && (D = i, O = 0), !(O >= S) && (O++, E.set(a, i), t.emit("cursor:move", r)));
280
293
  })), l.push(f.on("cursor:leave", (e) => {
281
- G(n, f) && c(e) && k(e.userId) && (T.delete(e.userId.trim()), t.emit("cursor:leave", { userId: e.userId.trim() }));
294
+ G(n, f) && c(e) && k(e.userId) && (E.delete(e.userId.trim()), t.emit("cursor:leave", { userId: e.userId.trim() }));
282
295
  })), l.push(f.on("user:joined", (r) => {
283
296
  let i = e(r);
284
297
  G(n, f) && j(i) && t.emit("user:joined", M(i));
@@ -3,7 +3,7 @@ function t(t, n, r, i) {
3
3
  let a = !1, o = !1, s = !1, c = !1, l, u, d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = () => !a && r() && t.getState().isAuthenticated, m = () => {
4
4
  let n = t.getState();
5
5
  return n.isLoading || n.pendingMutations.length > 0 || e(t.apiClient);
6
- }, h = (e, n) => p() && e.isCurrent?.() !== !1 && n.activeBranch === t.getState().activeBranch, g = (e) => {
6
+ }, h = (e, n) => p() && e.isCurrent?.() !== !1 && n.activeBranch === t.getState().activeBranch && JSON.stringify(n.commentQuery) === JSON.stringify(t.getState().commentQuery), g = (e) => {
7
7
  let n = t.getState();
8
8
  return !m() && e.comments === n.comments && e.pagination === n.pagination && e.selectedComment?.id === n.selectedComment?.id;
9
9
  }, _ = (e, t) => {
@@ -14,10 +14,37 @@ function t(t, n, r, i) {
14
14
  let t = typeof e == "object" && e && "code" in e ? e.code : null;
15
15
  return typeof t == "number" && (t === 0 || t === 408 || t === 429 || t >= 500 && t <= 599);
16
16
  };
17
- async function x(e, n) {
18
- let r = Math.max(1, n.pagination?.page ?? 1), i = n.pagination?.limit ?? 50, a = /* @__PURE__ */ new Map(), o = n.pagination;
17
+ async function x(e, t, n) {
18
+ let r = t.comments.find((e) => e.id === n), i = r?.detailLoaded === !1 && t.selectedComment?.id !== n, a = i ? 1 : Math.max(50, r?.replies.length ?? 0), o = _(await e.apiClient.getComment(n, { repliesLimit: Math.min(100, a) }), t), s = o.repliesPagination?.nextCursor;
19
+ for (; !i && s && o.replies.length < a && h(e, t);) {
20
+ let r = _(await e.apiClient.getComment(n, {
21
+ repliesLimit: Math.min(100, a - o.replies.length),
22
+ repliesBefore: s
23
+ }), t);
24
+ o = {
25
+ ...o,
26
+ replies: [...r.replies, ...o.replies],
27
+ repliesPagination: r.repliesPagination
28
+ };
29
+ let i = r.repliesPagination?.nextCursor;
30
+ if (i === s) break;
31
+ s = i;
32
+ }
33
+ return i ? {
34
+ ...o,
35
+ detailLoaded: !1,
36
+ replies: []
37
+ } : o;
38
+ }
39
+ async function S(e, n) {
40
+ let r = Math.max(1, n.pagination?.page ?? 1), i = n.pagination?.limit ?? 50, a = /* @__PURE__ */ new Map(), o = n.pagination, s, l = n.commentQuery;
19
41
  for (let t = 1; t <= r; t++) {
20
- let r = await e.apiClient.getComments(void 0, "all", t, i, void 0, n.activeBranch);
42
+ let r = await e.apiClient.getComments(l?.pagePath, l?.status ?? "all", t, i, void 0, n.activeBranch, {
43
+ ...l,
44
+ pagination: "cursor",
45
+ view: "summary",
46
+ cursor: s
47
+ });
21
48
  if (!h(e, n)) return;
22
49
  if (!g(n)) {
23
50
  c = !0;
@@ -27,13 +54,13 @@ function t(t, n, r, i) {
27
54
  let t = _(e, n);
28
55
  v(t, n) && a.set(t.id, t);
29
56
  }
30
- if (o = r.pagination, !o.hasMore) break;
57
+ if (o = r.pagination, s = r.pagination.nextCursor, !o.hasMore) break;
31
58
  }
32
- let s = n.selectedComment?.id, l = s ? a.get(s) ?? null : null;
33
- if (s && !l) try {
34
- let t = _(await e.apiClient.getComment(s), n);
35
- if (t.id !== s) throw Error("Invalid comment refresh response");
36
- v(t, n) && (l = t, a.set(t.id, t));
59
+ let u = n.selectedComment?.id, d = u ? a.get(u) ?? null : null;
60
+ if (u && (!d || d.detailLoaded === !1)) try {
61
+ let t = await x(e, n, u);
62
+ if (t.id !== u) throw Error("Invalid comment refresh response");
63
+ v(t, n) && (d = t, a.set(t.id, t));
37
64
  } catch (e) {
38
65
  if (!y(e)) throw e;
39
66
  }
@@ -42,24 +69,24 @@ function t(t, n, r, i) {
42
69
  c = !0;
43
70
  return;
44
71
  }
45
- let u = t.getState();
72
+ let f = t.getState();
46
73
  e.setState({
47
74
  comments: [...a.values()],
48
75
  pagination: o,
49
- ...u.selectedComment?.id === s ? { selectedComment: l } : {}
76
+ ...f.selectedComment?.id === u ? { selectedComment: d } : {}
50
77
  });
51
78
  }
52
- async function S(e, n, r, i) {
79
+ async function C(e, n, r, i) {
53
80
  let a;
54
81
  try {
55
- if (a = _(await e.apiClient.getComment(r), n), a.id !== r) throw Error("Invalid comment refresh response");
82
+ if (a = await x(e, n, r), a.id !== r) throw Error("Invalid comment refresh response");
56
83
  } catch (e) {
57
84
  if (!y(e)) throw e;
58
85
  a = null;
59
86
  }
60
87
  if (!h(e, n)) return;
61
88
  if (!g(n)) {
62
- for (let e of i) T({
89
+ for (let e of i) E({
63
90
  commentId: r,
64
91
  event: e
65
92
  });
@@ -78,21 +105,21 @@ function t(t, n, r, i) {
78
105
  }), !a) s && e.emit("comment:deleted", { id: r });
79
106
  else for (let t of i) (t !== "comment:created" || !s) && e.emit(t, a);
80
107
  }
81
- async function C() {
108
+ async function w() {
82
109
  if (s = !1, !p() || o || !c && !f.size) return;
83
110
  if (m()) {
84
111
  e(t.apiClient) && !l && (l = setTimeout(() => {
85
- l = void 0, w();
112
+ l = void 0, T();
86
113
  }, 100));
87
114
  return;
88
115
  }
89
116
  o = !0;
90
117
  let r = n.capture(), i = t.getState(), a = c, g = a ? void 0 : f.entries().next().value, _ = a ? "window" : `thread:${g?.[0]}`;
91
118
  try {
92
- if (a) c = !1, await x(r, i);
119
+ if (a) c = !1, await S(r, i);
93
120
  else if (g) {
94
121
  let [e, t] = g;
95
- f.delete(e), await S(r, i, e, t);
122
+ f.delete(e), await C(r, i, e, t);
96
123
  }
97
124
  d.delete(_);
98
125
  } catch (e) {
@@ -101,34 +128,34 @@ function t(t, n, r, i) {
101
128
  b(e) && t < 2 ? (d.set(_, t + 1), u = setTimeout(() => {
102
129
  if (u = void 0, h(r, i)) {
103
130
  if (a) c = !0;
104
- else if (g) for (let e of g[1]) T({
131
+ else if (g) for (let e of g[1]) E({
105
132
  commentId: g[0],
106
133
  event: e
107
134
  });
108
135
  } else d.delete(_);
109
- w();
136
+ T();
110
137
  }, 1e3 * 2 ** t)) : (d.delete(_), r.handleError(e));
111
138
  }
112
139
  } finally {
113
- o = !1, w();
140
+ o = !1, T();
114
141
  }
115
142
  }
116
- function w() {
117
- !p() || s || o || u || !c && !f.size || (s = !0, Promise.resolve().then(C));
143
+ function T() {
144
+ !p() || s || o || u || !c && !f.size || (s = !0, Promise.resolve().then(w));
118
145
  }
119
- function T({ commentId: e, event: t }) {
146
+ function E({ commentId: e, event: t }) {
120
147
  if (!p()) return;
121
148
  let n = f.get(e) ?? /* @__PURE__ */ new Set();
122
- n.add(t), f.size < 256 || f.has(e) ? f.set(e, n) : c = !0, w();
149
+ n.add(t), f.size < 256 || f.has(e) ? f.set(e, n) : c = !0, T();
123
150
  }
124
- let E = n.subscribe(w);
151
+ let D = n.subscribe(T);
125
152
  return {
126
- refreshThread: T,
153
+ refreshThread: E,
127
154
  refreshWindow() {
128
- p() && (c = !0, w());
155
+ p() && (c = !0, T());
129
156
  },
130
157
  dispose() {
131
- a = !0, l && clearTimeout(l), u && clearTimeout(u), d.clear(), f.clear(), E();
158
+ a = !0, l && clearTimeout(l), u && clearTimeout(u), d.clear(), f.clear(), D();
132
159
  }
133
160
  };
134
161
  }
@@ -0,0 +1,199 @@
1
+ import { a as e, n as t, o as n, t as r } from "./validation-3wbbbuX0.js";
2
+ import { r as i } from "./comment-kit-core-D068rcdY.js";
3
+ import { o as a, r as o } from "./dom-Bhf4WFtY.js";
4
+ import { t as s } from "./capture-privacy-DUROnio5.js";
5
+ var c = /* @__PURE__ */ new WeakMap(), l = 1e4, u = 2048, d = 10485760, f = 20971520, p = 16384, m = 32e6, h = 10, g = 10485760, _ = 26214400, v = /* @__PURE__ */ new Set([
6
+ "jpg",
7
+ "jpeg",
8
+ "png",
9
+ "gif",
10
+ "webp",
11
+ "pdf",
12
+ "doc",
13
+ "docx",
14
+ "txt",
15
+ "csv"
16
+ ]), y = 15e3, b = 1e4, x = {
17
+ "image/gif": "gif",
18
+ "image/jpeg": "jpg",
19
+ "image/png": "png",
20
+ "image/webp": "webp"
21
+ };
22
+ function S(e, t) {
23
+ let n = Error(t);
24
+ return n.error = e, n.code = 400, n;
25
+ }
26
+ function C(e) {
27
+ if (typeof e != "string") throw S("invalid_position", "Invalid position");
28
+ let n = e.trim();
29
+ if (!n || n.length > u || t(n)) throw S("invalid_position", "Invalid position");
30
+ return n;
31
+ }
32
+ function w(t) {
33
+ if (!n(t) || !e(t.x) || !e(t.y)) throw S("invalid_position", "Invalid position");
34
+ return {
35
+ x: t.x,
36
+ y: t.y,
37
+ ...t.element === void 0 ? {} : { element: C(t.element) },
38
+ ...t.xpath === void 0 ? {} : { xpath: C(t.xpath) }
39
+ };
40
+ }
41
+ function T(e) {
42
+ if (typeof e != "string") throw S("invalid_content", "Screenshot comment is required");
43
+ let n = e.trim();
44
+ if (!n || n.length > l || t(n)) throw S("invalid_content", "Screenshot comment is required");
45
+ return n;
46
+ }
47
+ function E(e) {
48
+ return typeof Blob < "u" && e instanceof Blob;
49
+ }
50
+ function D(e) {
51
+ return typeof File < "u" && e instanceof File;
52
+ }
53
+ function O(e) {
54
+ return typeof HTMLElement < "u" && e instanceof HTMLElement;
55
+ }
56
+ function k(e) {
57
+ if (e !== void 0) {
58
+ if (!O(e)) throw S("invalid_element", "Invalid screenshot target");
59
+ return e;
60
+ }
61
+ if (typeof document > "u" || !document.body) throw S("invalid_element", "A browser document is required to capture screenshots");
62
+ return document.body;
63
+ }
64
+ function A(e) {
65
+ let t = /^data:(image\/(?:png|jpeg|gif|webp));base64,/i.exec(e)?.[1];
66
+ return t ? t.toLowerCase() : null;
67
+ }
68
+ function j(e) {
69
+ if (!n(e)) throw S("invalid_screenshot", "Invalid screenshot result");
70
+ let t = typeof e.dataUrl == "string" ? e.dataUrl.trim() : "", r = e.blob, i = e.dimensions;
71
+ if (!A(t) || t.length > f || !E(r) || r.size <= 0 || r.size > d || r.type && !Object.prototype.hasOwnProperty.call(x, r.type)) throw S("invalid_screenshot", "Invalid screenshot result");
72
+ if (!n(i)) throw S("invalid_screenshot", "Invalid screenshot dimensions");
73
+ let { width: a, height: o } = i;
74
+ if (typeof a != "number" || typeof o != "number" || !Number.isFinite(a) || !Number.isFinite(o) || a <= 0 || o <= 0 || a > p || o > p) throw S("invalid_screenshot", "Invalid screenshot dimensions");
75
+ return {
76
+ dataUrl: t,
77
+ blob: r,
78
+ dimensions: {
79
+ width: a,
80
+ height: o
81
+ }
82
+ };
83
+ }
84
+ function M(e) {
85
+ let t = A(e.dataUrl);
86
+ return e.blob.type || t;
87
+ }
88
+ function N(e) {
89
+ return `screenshot.${x[M(e)]}`;
90
+ }
91
+ function P(e, t, n) {
92
+ let r = null;
93
+ return new Promise((i, a) => {
94
+ r = setTimeout(() => {
95
+ r = null, a(Error(n));
96
+ }, t), e.then((e) => {
97
+ r && clearTimeout(r), r = null, i(e);
98
+ }, (e) => {
99
+ r && clearTimeout(r), r = null, a(e);
100
+ });
101
+ });
102
+ }
103
+ function F(e) {
104
+ return new Promise((t, n) => {
105
+ let r = !1, i = setTimeout(() => {
106
+ r = !0, n(/* @__PURE__ */ Error("toBlob timed out"));
107
+ }, b);
108
+ e.toBlob((e) => {
109
+ r || (r = !0, clearTimeout(i), e ? t(e) : n(/* @__PURE__ */ Error("toBlob returned null")));
110
+ }, "image/png");
111
+ });
112
+ }
113
+ function I(e) {
114
+ let t = e.lastIndexOf(".");
115
+ return t >= 0 ? e.slice(t + 1).toLowerCase() : "";
116
+ }
117
+ function L(e) {
118
+ if (!Array.isArray(e)) throw S("invalid_files", "Files must be an array");
119
+ if (e.length > h) throw S("too_many_files", `Cannot upload more than ${h} files at once`);
120
+ let n = 0;
121
+ for (let i of e) {
122
+ if (!D(i)) throw S("invalid_files", "Invalid file upload");
123
+ if (i.size > g) throw S("file_too_large", `File "${i.name}" exceeds the ${g / 1024 / 1024}MB limit`);
124
+ if (n += i.size, n > _) throw S("upload_too_large", `Total upload size exceeds the ${_ / 1024 / 1024}MB limit`);
125
+ if (t(i.name) || i.name.includes("/") || i.name.includes("\\")) throw S("invalid_filename", "Filename contains invalid characters");
126
+ if (r(i.name)) throw S("invalid_file_type", `File type ".${I(i.name)}" is not allowed`);
127
+ if (!v.has(I(i.name))) throw S("invalid_file_type", `File type ".${I(i.name)}" is not supported. Allowed: ${[...v].map((e) => `.${e}`).join(", ")}`);
128
+ }
129
+ return e;
130
+ }
131
+ async function R(e, t, n, r = {}) {
132
+ if (e.isLocalDemo) return null;
133
+ try {
134
+ let e = k(n);
135
+ if (s(e)) return null;
136
+ if (t) return j(await t(e));
137
+ let r;
138
+ try {
139
+ r = (await import("html2canvas")).default;
140
+ } catch {
141
+ /* v8 ignore next 3 -- dynamic import() can't be intercepted by vi.mock */
142
+ throw Error("Screenshot requires either a custom screenshotProvider in config or html2canvas installed. Install html2canvas: npm install html2canvas — or provide config.screenshotProvider.");
143
+ }
144
+ let i = await P(r(e, {
145
+ useCORS: !0,
146
+ allowTaint: !1,
147
+ scale: 2,
148
+ logging: !1,
149
+ ignoreElements: s,
150
+ onclone: (e) => import("./capture-colors-D0uLr-vZ.js").then(({ normalizeCaptureColors: t }) => t(e))
151
+ }), y, "html2canvas timed out after 15s");
152
+ if (i.width > p || i.height > p || i.width * i.height > m) throw S("screenshot_too_large", "Captured area is too large to screenshot");
153
+ return j({
154
+ dataUrl: i.toDataURL("image/png"),
155
+ blob: await F(i),
156
+ dimensions: {
157
+ width: i.width,
158
+ height: i.height
159
+ }
160
+ });
161
+ } catch (t) {
162
+ return r.reportErrors !== !1 && (console.error("[CommentKit] Screenshot failed:", t), e.handleError({
163
+ error: "screenshot_failed",
164
+ message: "Failed to capture screenshot",
165
+ code: 500
166
+ })), null;
167
+ }
168
+ }
169
+ async function z(e, t, n, r) {
170
+ try {
171
+ let s = j(t), l = T(n), u = w(r);
172
+ e.setState({ isLoading: !0 });
173
+ let d = new File([s.blob], N(s), { type: M(s) }), f = a(), p = i(e), m = c.get(s.blob) ?? o("screenshot");
174
+ c.set(s.blob, m);
175
+ let h = await e.apiClient.uploadScreenshot(d, {
176
+ content: l,
177
+ idempotencyKey: m,
178
+ position: u,
179
+ page: f,
180
+ ...p ? { branch: p } : {}
181
+ });
182
+ return e.setState({
183
+ comments: !e.getState().activeBranch || e.getState().activeBranch === h.branch ? [...e.getState().comments.filter((e) => e.id !== h.id), h] : e.getState().comments,
184
+ isLoading: !1,
185
+ activeScreenshot: null
186
+ }), e.emit("comment:created", h), c.delete(s.blob), h;
187
+ } catch (t) {
188
+ return e.setState({ isLoading: !1 }), e.handleError(t), null;
189
+ }
190
+ }
191
+ async function B(e, t, n) {
192
+ try {
193
+ let r = L(t);
194
+ return r.length === 0 ? [] : await e.apiClient.uploadFiles(r, n);
195
+ } catch (t) {
196
+ return e.handleError(t), [];
197
+ }
198
+ }
199
+ export { R as captureScreenshot, B as uploadFiles, z as uploadScreenshot };