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