@commentkit/comment-kit 0.6.8 → 0.7.0

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