@commentkit/comment-kit 0.6.7 → 0.6.9

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