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