@commentkit/comment-kit 0.0.0-stage → 0.6.2

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