@commentkit/comment-kit 0.7.6 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +108 -762
  3. package/SECURITY.md +19 -14
  4. package/dist/npm/THIRD_PARTY_NOTICES.txt +73 -0
  5. package/dist/npm/chunks/anchor-DT-Ynhh1.js +270 -0
  6. package/dist/npm/chunks/client-D1vrh_5G.js +590 -0
  7. package/dist/{shared/capture-colors-D0uLr-vZ.js → npm/chunks/colors-CX-IPjvb.js} +2 -0
  8. package/dist/npm/chunks/html2canvas-_mjSRP3G.js +4011 -0
  9. package/dist/npm/chunks/mount-Ce1MZrcm.js +2485 -0
  10. package/dist/{shared/pusher-BUaiCkDJ.js → npm/chunks/pusher-DRKlokR8.js} +224 -222
  11. package/dist/npm/chunks/realtime-5SvAvTUU.js +23 -0
  12. package/dist/npm/chunks/rolldown-runtime-VHNaYcLd.js +13 -0
  13. package/dist/npm/chunks/src-DJjfvVsa.js +330 -0
  14. package/dist/npm/element.js +24 -0
  15. package/dist/npm/headless.js +3 -0
  16. package/dist/npm/index.js +3 -0
  17. package/dist/npm/react.js +17 -0
  18. package/dist/npm/svelte.js +8 -0
  19. package/dist/npm/types/adapters/react.d.ts +9 -0
  20. package/dist/npm/types/adapters/svelte.d.ts +9 -0
  21. package/dist/npm/types/adapters/vue.d.ts +46 -0
  22. package/dist/npm/types/anchor/index.d.ts +49 -0
  23. package/dist/npm/types/core/api.d.ts +29 -0
  24. package/dist/npm/types/core/auth.d.ts +48 -0
  25. package/dist/npm/types/core/client.d.ts +100 -0
  26. package/dist/npm/types/core/store.d.ts +7 -0
  27. package/dist/npm/types/core/types.d.ts +278 -0
  28. package/dist/npm/types/element.d.ts +10 -0
  29. package/dist/npm/types/headless.d.ts +7 -0
  30. package/dist/npm/types/index.d.ts +30 -0
  31. package/dist/npm/vue.js +32 -0
  32. package/package.json +65 -173
  33. package/dist/THIRD_PARTY_NOTICES.txt +0 -284
  34. package/dist/angular.es.js +0 -321
  35. package/dist/comment-kit.es.js +0 -218
  36. package/dist/demo.es.js +0 -483
  37. package/dist/headless.es.js +0 -4
  38. package/dist/preact.es.js +0 -117
  39. package/dist/qwik.es.js +0 -1
  40. package/dist/qwik.qwik.mjs +0 -114
  41. package/dist/react.es.js +0 -98
  42. package/dist/shared/ShadowRootContext-DD6a0QaI.js +0 -11
  43. package/dist/shared/annotation-icons-Dh-bmNYK.js +0 -172
  44. package/dist/shared/annotation-toolbar-RSrb0Nku.js +0 -1086
  45. package/dist/shared/attachment-refresh-CSTYwRW-.js +0 -94
  46. package/dist/shared/bridge-CJoGYngu.js +0 -177
  47. package/dist/shared/button-D4GHW6oZ.js +0 -474
  48. package/dist/shared/button-group-BVR7iT-S.js +0 -91
  49. package/dist/shared/capture-privacy-DUROnio5.js +0 -77
  50. package/dist/shared/comment-drawing-canvas-DbuXP54N.js +0 -124
  51. package/dist/shared/comment-icon-D8JTCEJ7.js +0 -607
  52. package/dist/shared/comment-image-lightbox-zlIGEVA-.js +0 -190
  53. package/dist/shared/comment-images-content-aYbJb79_.js +0 -214
  54. package/dist/shared/comment-kit-core-B0k7XsMz.js +0 -3680
  55. package/dist/shared/comment-kit-ui-BXLJcZYQ.js +0 -19391
  56. package/dist/shared/comment-screenshot-annotator-ChWwYJzO.js +0 -151
  57. package/dist/shared/comment-screenshot-overlay-Bufg3rHz.js +0 -205
  58. package/dist/shared/comment-shortcut-groups-CfEmkitU.js +0 -153
  59. package/dist/shared/createReactComponent-BZHeRbD0.js +0 -45
  60. package/dist/shared/dev-export-panel-DAZenvgD.js +0 -207
  61. package/dist/shared/dev-grab-O8q25zar.js +0 -197
  62. package/dist/shared/dist-D9A5k-N4.js +0 -617
  63. package/dist/shared/dom-Bhf4WFtY.js +0 -223
  64. package/dist/shared/element-selector-CYkwzfEr.js +0 -902
  65. package/dist/shared/error-boundary-D3PD74vI.js +0 -21
  66. package/dist/shared/errors-Bu5ajEmB.js +0 -22
  67. package/dist/shared/icons-nzMOLzrm.js +0 -266
  68. package/dist/shared/input-UPtAj0M6.js +0 -111
  69. package/dist/shared/mount-ui-BKaWBhKq.js +0 -208
  70. package/dist/shared/realtime-C0Z8dXXH.js +0 -334
  71. package/dist/shared/realtime-recovery-BjlV-ewc.js +0 -162
  72. package/dist/shared/request-activity-DQrAUwfA.js +0 -11
  73. package/dist/shared/screenshot-B-ZfFItT.js +0 -199
  74. package/dist/shared/separator-UhJb0Row.js +0 -3955
  75. package/dist/shared/shadow-root-Cd3SLHyj.js +0 -133
  76. package/dist/shared/styles-CnYsLS2f.js +0 -2
  77. package/dist/shared/text-B4HHZNaa.js +0 -23
  78. package/dist/shared/token-session-DplW5QDx.js +0 -25
  79. package/dist/shared/useLabelableId-8n0QmH8N.js +0 -154
  80. package/dist/shared/useRender-Uxk1OPK-.js +0 -5
  81. package/dist/shared/useValueChanged-DKq5cMot.js +0 -92
  82. package/dist/shared/validation-3wbbbuX0.js +0 -70
  83. package/dist/shared/websocket-manager-798cRDyL.js +0 -381
  84. package/dist/solid.es.js +0 -98
  85. package/dist/svelte.es.js +0 -130
  86. package/dist/types/adapters/bridge.d.ts +0 -122
  87. package/dist/types/angular/index.d.ts +0 -145
  88. package/dist/types/core/agent-context.d.ts +0 -17
  89. package/dist/types/core/api-client.d.ts +0 -155
  90. package/dist/types/core/comment-kit-core.d.ts +0 -254
  91. package/dist/types/core/local-demo.d.ts +0 -60
  92. package/dist/types/core/types.d.ts +0 -770
  93. package/dist/types/core/websocket-manager.d.ts +0 -125
  94. package/dist/types/core/write-access.d.ts +0 -11
  95. package/dist/types/demo.d.ts +0 -17
  96. package/dist/types/headless.d.ts +0 -8
  97. package/dist/types/index.d.ts +0 -87
  98. package/dist/types/preact/index.d.ts +0 -25
  99. package/dist/types/qwik/index.d.ts +0 -73
  100. package/dist/types/react/client.d.ts +0 -31
  101. package/dist/types/react/index.d.ts +0 -4
  102. package/dist/types/solid/index.d.ts +0 -37
  103. package/dist/types/svelte/index.d.ts +0 -55
  104. package/dist/types/utils/dom.d.ts +0 -59
  105. package/dist/types/utils/event-emitter.d.ts +0 -11
  106. package/dist/types/vue/index.d.ts +0 -87
  107. package/dist/vue.es.js +0 -148
  108. package/docs/api-reference.md +0 -405
  109. package/docs/local-demo.md +0 -60
@@ -0,0 +1,590 @@
1
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/typeof.js
2
+ function e(t) {
3
+ "@babel/helpers - typeof";
4
+ return e = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
5
+ return typeof e;
6
+ } : function(e) {
7
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
8
+ }, e(t);
9
+ }
10
+ //#endregion
11
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPrimitive.js
12
+ function t(t, n) {
13
+ if (e(t) != "object" || !t) return t;
14
+ var r = t[Symbol.toPrimitive];
15
+ if (r !== void 0) {
16
+ var i = r.call(t, n || "default");
17
+ if (e(i) != "object") return i;
18
+ throw TypeError("@@toPrimitive must return a primitive value.");
19
+ }
20
+ return (n === "string" ? String : Number)(t);
21
+ }
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPropertyKey.js
24
+ function n(n) {
25
+ var r = t(n, "string");
26
+ return e(r) == "symbol" ? r : r + "";
27
+ }
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/defineProperty.js
30
+ function r(e, t, r) {
31
+ return (t = n(t)) in e ? Object.defineProperty(e, t, {
32
+ value: r,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }) : e[t] = r, e;
37
+ }
38
+ //#endregion
39
+ //#region src/core/types.ts
40
+ var i = class extends Error {
41
+ constructor(e, t, n, i) {
42
+ super(n), r(this, "status", void 0), r(this, "code", void 0), r(this, "errors", void 0), this.status = e, this.code = t, this.errors = i, this.name = "CommentKitError";
43
+ }
44
+ }, a = /* @__PURE__ */ new Set([
45
+ 408,
46
+ 425,
47
+ 429,
48
+ 500,
49
+ 502,
50
+ 503,
51
+ 504
52
+ ]), o = class {
53
+ constructor(e, t, n) {
54
+ r(this, "baseUrl", void 0), r(this, "tokens", void 0), r(this, "sdkVersion", void 0), this.baseUrl = e, this.tokens = t, this.sdkVersion = n;
55
+ }
56
+ async request(e, t = {}) {
57
+ let n = t.method ?? "GET", r = t.idempotent ? crypto.randomUUID() : null, o = !1;
58
+ for (let u = 0;; u++) {
59
+ let d = {
60
+ Accept: "application/json",
61
+ "X-CommentKit-SDK": this.sdkVersion,
62
+ ...t.headers
63
+ };
64
+ if (t.body !== void 0 && (d["Content-Type"] = "application/json"), r && (d["Idempotency-Key"] = r), !t.anonymous) {
65
+ let e = await this.tokens.accessToken();
66
+ e && (d.Authorization = `Bearer ${e}`);
67
+ }
68
+ let f;
69
+ try {
70
+ f = await fetch(this.url(e, t.query), {
71
+ method: n,
72
+ headers: d,
73
+ body: t.body === void 0 ? void 0 : JSON.stringify(t.body),
74
+ credentials: "omit",
75
+ signal: t.signal
76
+ });
77
+ } catch (e) {
78
+ if (t.signal?.aborted) throw e;
79
+ if (u < 3 && (n === "GET" || r)) {
80
+ await c(s(u));
81
+ continue;
82
+ }
83
+ throw new i(0, "network_error", "You appear to be offline. Your draft is saved; try again in a moment.");
84
+ }
85
+ if (f.status === 401 && !t.anonymous && !o && (o = !0, await this.tokens.recover())) continue;
86
+ if (a.has(f.status) && u < 3 && (n === "GET" || r)) {
87
+ let e = Number(f.headers.get("Retry-After"));
88
+ await c(Number.isFinite(e) && e > 0 ? Math.min(e, 30) * 1e3 : s(u));
89
+ continue;
90
+ }
91
+ if (f.status === 204) return;
92
+ let p = await f.text(), m = p ? l(p) : null;
93
+ if (!f.ok) {
94
+ let e = m ?? {};
95
+ throw new i(f.status, e.code ?? `http_${f.status}`, e.detail ?? e.title ?? "Something went wrong. Please try again.", e.errors);
96
+ }
97
+ return m;
98
+ }
99
+ }
100
+ url(e, t) {
101
+ let n = new URL(`/api/v1${e}`, this.baseUrl);
102
+ for (let [e, r] of Object.entries(t ?? {})) r != null && r !== "" && n.searchParams.set(e, String(r));
103
+ return n.toString();
104
+ }
105
+ };
106
+ function s(e) {
107
+ return Math.min(8e3, 400 * 2 ** e) + Math.random() * 250;
108
+ }
109
+ function c(e) {
110
+ return new Promise((t) => setTimeout(t, e));
111
+ }
112
+ function l(e) {
113
+ try {
114
+ return JSON.parse(e);
115
+ } catch {
116
+ return null;
117
+ }
118
+ }
119
+ //#endregion
120
+ //#region src/core/pkce.ts
121
+ function u(e) {
122
+ let t = "";
123
+ for (let n of e) t += String.fromCharCode(n);
124
+ return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
125
+ }
126
+ function d(e = 32) {
127
+ let t = new Uint8Array(e);
128
+ return crypto.getRandomValues(t), u(t);
129
+ }
130
+ async function f(e) {
131
+ let t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
132
+ return u(new Uint8Array(t));
133
+ }
134
+ //#endregion
135
+ //#region src/core/auth.ts
136
+ function p(e = navigator.userAgent) {
137
+ return /FBAN|FBAV|Instagram|Line\/|WhatsApp|Snapchat|LinkedInApp|Slack|Twitter|MicroMessenger|; wv\)|GSA\//i.test(e);
138
+ }
139
+ var m = "popup=yes,width=460,height=680,left=120,top=80", h = 1500, g = 6e5, _ = class {
140
+ constructor(e, t, n = location.origin) {
141
+ r(this, "endpoint", void 0), r(this, "projectKey", void 0), r(this, "origin", void 0), r(this, "access", null), r(this, "refreshing", null), r(this, "listeners", /* @__PURE__ */ new Set()), this.endpoint = e, this.projectKey = t, this.origin = n;
142
+ }
143
+ get storageKey() {
144
+ return `commentkit:v1:${this.projectKey}`;
145
+ }
146
+ hasSession() {
147
+ return this.access !== null || this.readRefresh() !== null;
148
+ }
149
+ onChange(e) {
150
+ return this.listeners.add(e), () => this.listeners.delete(e);
151
+ }
152
+ async accessToken() {
153
+ return this.access && this.access.expiresAt - 3e4 > Date.now() ? this.access.token : this.readRefresh() && await this.refresh() ? this.access?.token ?? null : null;
154
+ }
155
+ async recover() {
156
+ return this.access = null, this.refresh();
157
+ }
158
+ async signIn(e = {}) {
159
+ let t = d(48), n = d(24), r = await f(t), i = e.mode ?? "auto", a = i === "redirect" || i === "auto" && p(), o = this.authorizeUrl(r, n, e.share ?? null, a ? location.href : null);
160
+ if (a) return this.redirect(o, t, n);
161
+ let s = window.open(o.toString(), "commentkit-signin", m);
162
+ if (!s) return i === "auto" ? this.redirect(this.authorizeUrl(r, n, e.share ?? null, location.href), t, n) : "popup_blocked";
163
+ let c = await this.awaitCode(s, n);
164
+ if (!c) return "cancelled";
165
+ try {
166
+ let e = await this.post("/oauth/token", {
167
+ grant_type: "authorization_code",
168
+ client_id: this.projectKey,
169
+ code: c,
170
+ code_verifier: t
171
+ });
172
+ return this.store(e), "signed_in";
173
+ } catch {
174
+ return "failed";
175
+ }
176
+ }
177
+ async completeRedirect() {
178
+ let e = new URL(location.href), t = e.searchParams.get("ck_code"), n = e.searchParams.get("ck_state");
179
+ if (!t || !n) return !1;
180
+ e.searchParams.delete("ck_code"), e.searchParams.delete("ck_state"), history.replaceState(history.state, "", e.toString());
181
+ let r = null;
182
+ try {
183
+ r = JSON.parse(sessionStorage.getItem(this.pkceKey) ?? "null"), sessionStorage.removeItem(this.pkceKey);
184
+ } catch {
185
+ return !1;
186
+ }
187
+ if (!r?.verifier || r.state !== n) return !1;
188
+ try {
189
+ let e = await this.post("/oauth/token", {
190
+ grant_type: "authorization_code",
191
+ client_id: this.projectKey,
192
+ code: t,
193
+ code_verifier: r.verifier
194
+ });
195
+ return this.store(e), !0;
196
+ } catch {
197
+ return !1;
198
+ }
199
+ }
200
+ get pkceKey() {
201
+ return `commentkit:pkce:${this.projectKey}`;
202
+ }
203
+ authorizeUrl(e, t, n, r) {
204
+ let i = new URL("/widget/connect", this.endpoint);
205
+ return i.search = new URLSearchParams({
206
+ key: this.projectKey,
207
+ origin: this.origin,
208
+ code_challenge: e,
209
+ code_challenge_method: "S256",
210
+ state: t,
211
+ ...n ? { share: n } : {},
212
+ ...r ? { return_to: r } : {}
213
+ }).toString(), i;
214
+ }
215
+ redirect(e, t, n) {
216
+ try {
217
+ sessionStorage.setItem(this.pkceKey, JSON.stringify({
218
+ verifier: t,
219
+ state: n
220
+ }));
221
+ } catch {
222
+ return "failed";
223
+ }
224
+ return location.assign(e.toString()), "redirecting";
225
+ }
226
+ async signOut() {
227
+ let e = this.readRefresh();
228
+ this.clear(), e && await this.post("/oauth/revoke", { refresh_token: e }).catch(() => void 0);
229
+ }
230
+ awaitCode(e, t) {
231
+ let n = new URL(this.endpoint).origin;
232
+ return new Promise((r) => {
233
+ let i = !1, a = Date.now(), o = (e) => {
234
+ i || (i = !0, window.removeEventListener("message", s), clearInterval(l), r(e));
235
+ }, s = (e) => {
236
+ if (e.origin !== n) return;
237
+ let r = e.data;
238
+ r?.type === "commentkit:auth" && r.state === t && typeof r.code == "string" && o(r.code);
239
+ };
240
+ window.addEventListener("message", s);
241
+ let c = null, l = setInterval(async () => {
242
+ if (Date.now() - a > g) return o(null);
243
+ e.closed && (c ?? (c = Date.now()));
244
+ try {
245
+ let e = await this.post("/oauth/poll", {
246
+ client_id: this.projectKey,
247
+ state: t
248
+ });
249
+ if (e?.status === "complete" && e.code) return o(e.code);
250
+ } catch {}
251
+ c !== null && Date.now() - c > 6e3 && o(null);
252
+ }, h);
253
+ });
254
+ }
255
+ refresh() {
256
+ return this.refreshing ?? (this.refreshing = (async () => {
257
+ let e = this.readRefresh();
258
+ if (!e) return !1;
259
+ try {
260
+ let t = await this.post("/oauth/token", {
261
+ grant_type: "refresh_token",
262
+ client_id: this.projectKey,
263
+ refresh_token: e
264
+ });
265
+ return this.store(t), !0;
266
+ } catch (e) {
267
+ return e.status === 400 && this.clear(), !1;
268
+ } finally {
269
+ this.refreshing = null;
270
+ }
271
+ })()), this.refreshing;
272
+ }
273
+ store(e) {
274
+ let t = this.hasSession();
275
+ this.access = {
276
+ token: e.access_token,
277
+ expiresAt: Date.now() + e.expires_in * 1e3
278
+ };
279
+ try {
280
+ localStorage.setItem(this.storageKey, JSON.stringify({ refresh_token: e.refresh_token }));
281
+ } catch {}
282
+ t || this.emit(!0);
283
+ }
284
+ clear() {
285
+ let e = this.hasSession();
286
+ this.access = null;
287
+ try {
288
+ localStorage.removeItem(this.storageKey);
289
+ } catch {}
290
+ e && this.emit(!1);
291
+ }
292
+ readRefresh() {
293
+ try {
294
+ let e = localStorage.getItem(this.storageKey), t = e ? JSON.parse(e).refresh_token : null;
295
+ return typeof t == "string" ? t : null;
296
+ } catch {
297
+ return null;
298
+ }
299
+ }
300
+ emit(e) {
301
+ for (let t of [...this.listeners]) t(e);
302
+ }
303
+ async post(e, t) {
304
+ let n = await fetch(new URL(`/api/v1${e}`, this.endpoint), {
305
+ method: "POST",
306
+ headers: {
307
+ "Content-Type": "application/json",
308
+ Accept: "application/json"
309
+ },
310
+ body: JSON.stringify(t),
311
+ credentials: "omit"
312
+ });
313
+ if (n.status === 204) return;
314
+ let r = await n.json().catch(() => null);
315
+ if (!n.ok) throw Object.assign(/* @__PURE__ */ Error("auth_failed"), {
316
+ status: n.status,
317
+ data: r
318
+ });
319
+ return r;
320
+ }
321
+ };
322
+ //#endregion
323
+ //#region src/core/store.ts
324
+ function v(e) {
325
+ let t = e, n = /* @__PURE__ */ new Set();
326
+ return {
327
+ get: () => t,
328
+ set(e) {
329
+ let r = typeof e == "function" ? e(t) : e, i = !1;
330
+ for (let e in r) if (!Object.is(t[e], r[e])) {
331
+ i = !0;
332
+ break;
333
+ }
334
+ if (i) {
335
+ t = {
336
+ ...t,
337
+ ...r
338
+ };
339
+ for (let e of [...n]) e(t);
340
+ }
341
+ },
342
+ subscribe(e) {
343
+ return n.add(e), () => n.delete(e);
344
+ }
345
+ };
346
+ }
347
+ //#endregion
348
+ //#region src/core/client.ts
349
+ var y = "1.0.0-beta.0", b = class {
350
+ constructor(e) {
351
+ r(this, "options", void 0), r(this, "auth", void 0), r(this, "api", void 0), r(this, "state", void 0), r(this, "listeners", /* @__PURE__ */ new Map()), r(this, "realtime", null), this.options = e;
352
+ let t = (e.endpoint ?? "https://commentkit.dev").replace(/\/+$/, "");
353
+ this.auth = new _(t, e.project), this.api = new o(t, this.auth, y), this.state = v({
354
+ config: null,
355
+ session: null,
356
+ threads: [],
357
+ loadingThreads: !1,
358
+ allBranches: !1,
359
+ unread: 0,
360
+ online: typeof navigator > "u" || navigator.onLine,
361
+ error: null
362
+ }), this.auth.onChange((e) => {
363
+ e || this.state.set({
364
+ session: null,
365
+ threads: [],
366
+ unread: 0
367
+ });
368
+ });
369
+ }
370
+ on(e, t) {
371
+ let n = this.listeners.get(e) ?? /* @__PURE__ */ new Set();
372
+ return n.add(t), this.listeners.set(e, n), () => n.delete(t);
373
+ }
374
+ emit(e, t) {
375
+ for (let n of this.listeners.get(e) ?? []) n(t);
376
+ }
377
+ async loadConfig() {
378
+ let e = await this.api.request("/widget/config", {
379
+ anonymous: !0,
380
+ query: { key: this.options.project }
381
+ });
382
+ return this.state.set({ config: e }), e;
383
+ }
384
+ async loadSession() {
385
+ if (!this.auth.hasSession()) return this.state.set({ session: null }), null;
386
+ try {
387
+ let e = await this.api.request("/me");
388
+ return this.state.set({ session: e }), this.emit("session:change", { session: e }), e;
389
+ } catch (e) {
390
+ if (e instanceof i && [401, 403].includes(e.status)) return this.state.set({ session: null }), null;
391
+ throw e;
392
+ }
393
+ }
394
+ async signIn(e) {
395
+ let t = await this.auth.signIn({
396
+ share: e,
397
+ mode: this.options.auth
398
+ });
399
+ return t === "signed_in" && await this.loadSession(), t;
400
+ }
401
+ async signOut() {
402
+ await this.auth.signOut(), this.state.set({
403
+ session: null,
404
+ threads: []
405
+ }), this.emit("session:change", { session: null });
406
+ }
407
+ async loadPageThreads(e = x()) {
408
+ this.state.set({ loadingThreads: !0 });
409
+ try {
410
+ let t = await this.api.request("/threads", { query: {
411
+ page_url: e,
412
+ status: "active",
413
+ limit: 100,
414
+ branch: this.branchFilter()
415
+ } });
416
+ return this.state.set({
417
+ threads: t.data,
418
+ loadingThreads: !1
419
+ }), t.data;
420
+ } catch (e) {
421
+ throw this.state.set({ loadingThreads: !1 }), e;
422
+ }
423
+ }
424
+ branchFilter() {
425
+ return this.state.get().allBranches ? void 0 : this.options.branch ?? void 0;
426
+ }
427
+ setAllBranches(e) {
428
+ return this.state.set({ allBranches: e }), this.loadPageThreads();
429
+ }
430
+ listThreads(e = {}) {
431
+ return this.api.request("/threads", { query: {
432
+ limit: 30,
433
+ ...e
434
+ } });
435
+ }
436
+ getThread(e) {
437
+ return this.api.request(`/threads/${encodeURIComponent(e)}`).then((e) => e.data);
438
+ }
439
+ async createThread(e) {
440
+ let { data: t } = await this.api.request("/threads", {
441
+ method: "POST",
442
+ idempotent: !0,
443
+ body: {
444
+ page: {
445
+ url: x(),
446
+ title: document.title.slice(0, 500) || null,
447
+ branch: this.options.branch ?? null,
448
+ commit_sha: this.options.commit ?? null,
449
+ deployment_url: this.options.deploymentUrl ?? null
450
+ },
451
+ anchor: e.anchor,
452
+ breakpoint: innerWidth,
453
+ body: e.body,
454
+ capture: e.capture ?? null,
455
+ attachment_ids: e.attachmentIds ?? [],
456
+ mention_ids: e.mentionIds ?? []
457
+ }
458
+ });
459
+ return this.upsert(t), this.emit("thread:created", { thread: t }), t;
460
+ }
461
+ async updateThread(e, t) {
462
+ let { data: n } = await this.api.request(`/threads/${encodeURIComponent(e)}`, {
463
+ method: "PATCH",
464
+ body: t
465
+ });
466
+ return this.upsert(n), this.emit("thread:updated", { thread: n }), n;
467
+ }
468
+ async deleteThread(e) {
469
+ await this.api.request(`/threads/${encodeURIComponent(e)}`, { method: "DELETE" }), this.state.set((t) => ({ threads: t.threads.filter((t) => t.id !== e) }));
470
+ }
471
+ messages(e, t) {
472
+ return this.api.request(`/threads/${encodeURIComponent(e)}/messages`, { query: {
473
+ cursor: t,
474
+ limit: 100
475
+ } });
476
+ }
477
+ async reply(e, t, n = {}) {
478
+ let { data: r } = await this.api.request(`/threads/${encodeURIComponent(e)}/messages`, {
479
+ method: "POST",
480
+ idempotent: !0,
481
+ body: {
482
+ body: t,
483
+ reply_to_id: n.replyTo ?? null,
484
+ attachment_ids: n.attachmentIds ?? [],
485
+ mention_ids: n.mentionIds ?? []
486
+ }
487
+ });
488
+ return this.emit("message:created", { message: r }), this.refreshThread(e), r;
489
+ }
490
+ editMessage(e, t) {
491
+ return this.api.request(`/messages/${encodeURIComponent(e)}`, {
492
+ method: "PATCH",
493
+ body: { body: t }
494
+ }).then((e) => e.data);
495
+ }
496
+ deleteMessage(e) {
497
+ return this.api.request(`/messages/${encodeURIComponent(e)}`, { method: "DELETE" });
498
+ }
499
+ react(e, t, n) {
500
+ return this.api.request(`/messages/${encodeURIComponent(e)}/reactions`, {
501
+ method: n ? "PUT" : "DELETE",
502
+ body: { emoji: t }
503
+ });
504
+ }
505
+ watch(e, t) {
506
+ return this.api.request(`/threads/${encodeURIComponent(e)}/watch`, { method: t ? "PUT" : "DELETE" });
507
+ }
508
+ people() {
509
+ return this.api.request("/people").then((e) => e.data);
510
+ }
511
+ async inbox() {
512
+ let e = await this.api.request("/inbox");
513
+ return this.state.set({ unread: e.unread }), e.data;
514
+ }
515
+ async markRead(e) {
516
+ let t = await this.api.request("/inbox/read", {
517
+ method: "POST",
518
+ body: {
519
+ ids: e.ids,
520
+ thread_id: e.threadId,
521
+ all: e.all
522
+ }
523
+ });
524
+ this.state.set({ unread: t.unread });
525
+ }
526
+ async upload(e, t, n = "file") {
527
+ let r = await this.api.request("/uploads", {
528
+ method: "POST",
529
+ body: {
530
+ name: t,
531
+ mime: e.type || "application/octet-stream",
532
+ bytes: e.size,
533
+ kind: n
534
+ }
535
+ }), a = await fetch(r.upload.url, {
536
+ method: "PUT",
537
+ headers: r.upload.headers,
538
+ body: e,
539
+ credentials: "omit"
540
+ });
541
+ if (!a.ok) throw new i(a.status, "upload_failed", "The file could not be uploaded. Please try again.");
542
+ return this.api.request(`/uploads/${r.id}/complete`, { method: "POST" }).then((e) => e.data);
543
+ }
544
+ async connectRealtime(e) {
545
+ let t = this.state.get().config, n = this.state.get().session;
546
+ if (!t?.features.realtime || !t.realtime || !n || this.realtime) return;
547
+ let { connect: r } = await import("./realtime-5SvAvTUU.js");
548
+ this.realtime = await r({
549
+ ...t.realtime,
550
+ projectId: n.project.id,
551
+ inbox: `${n.person.type === "guest" ? "guest" : "user"}.${n.person.id}`,
552
+ authorize: async (e, t) => this.api.request("/realtime/auth", {
553
+ method: "POST",
554
+ body: {
555
+ socket_id: e,
556
+ channel_name: t
557
+ }
558
+ }),
559
+ onFeedback: e,
560
+ onInbox: (e) => this.state.set({ unread: e })
561
+ });
562
+ }
563
+ async refreshThread(e) {
564
+ try {
565
+ this.upsert(await this.getThread(e));
566
+ } catch (t) {
567
+ t instanceof i && t.status === 404 && this.state.set((t) => ({ threads: t.threads.filter((t) => t.id !== e) }));
568
+ }
569
+ }
570
+ upsert(e) {
571
+ this.state.set((t) => {
572
+ let n = e.page.url === x() && !["resolved", "closed"].includes(e.status), r = t.threads.filter((t) => t.id !== e.id);
573
+ return { threads: n ? [e, ...r] : r };
574
+ });
575
+ }
576
+ destroy() {
577
+ this.realtime?.disconnect(), this.realtime = null, this.listeners.clear();
578
+ }
579
+ };
580
+ function x() {
581
+ let e = new URL(location.href);
582
+ for (let t of [
583
+ "ck_thread",
584
+ "ck",
585
+ "ck_invite"
586
+ ]) e.searchParams.delete(t);
587
+ return e.hash && !e.hash.startsWith("#/") && !e.hash.startsWith("#!/") && (e.hash = ""), e.toString();
588
+ }
589
+ //#endregion
590
+ export { o as a, _ as i, y as n, i as o, x as r, r as s, b as t };
@@ -1,3 +1,4 @@
1
+ //#region src/capture/colors.ts
1
2
  var e = [
2
3
  "background-color",
3
4
  "background-image",
@@ -81,4 +82,5 @@ function n(n) {
81
82
  for (let [e, t, n] of l) e.setProperty(t, n, "important");
82
83
  for (let [e, t, n] of c) e.setProperty(t, n, "important");
83
84
  }
85
+ //#endregion
84
86
  export { n as normalizeCaptureColors };