@commentkit/comment-kit 0.7.7 → 1.0.0-beta.2
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.
- package/CHANGELOG.md +87 -0
- package/README.md +172 -732
- package/SECURITY.md +24 -14
- package/dist/npm/THIRD_PARTY_NOTICES.txt +73 -0
- package/dist/npm/chunks/Guest-CKoV6pEK.js +157 -0
- package/dist/npm/chunks/MarkupEditor-DAo4qppg.js +199 -0
- package/dist/npm/chunks/Panel-BRBDHlGg.js +399 -0
- package/dist/npm/chunks/Shortcuts-CHMcrjAM.js +56 -0
- package/dist/npm/chunks/ThreadCard-D8FzIxbs.js +570 -0
- package/dist/npm/chunks/anchor-DT-Ynhh1.js +270 -0
- package/dist/npm/chunks/ar-D3SPpN1T.js +195 -0
- package/dist/npm/chunks/client-D1NizpDK.js +627 -0
- package/dist/{shared/capture-colors-D0uLr-vZ.js → npm/chunks/colors-CX-IPjvb.js} +2 -0
- package/dist/npm/chunks/de-C8eC6c6f.js +187 -0
- package/dist/npm/chunks/es-Bczf42tm.js +187 -0
- package/dist/npm/chunks/extension--it1LAj-.js +54 -0
- package/dist/npm/chunks/extension-XfuRGu2o.js +26 -0
- package/dist/npm/chunks/format-Bw_tNOh9.js +524 -0
- package/dist/npm/chunks/fr-BaQw-v2e.js +187 -0
- package/dist/npm/chunks/hi-BamV-yXv.js +187 -0
- package/dist/npm/chunks/html2canvas-DfGb8yka.js +4024 -0
- package/dist/npm/chunks/it-DC14_EjN.js +187 -0
- package/dist/npm/chunks/ja-B1mmTN7Y.js +187 -0
- package/dist/npm/chunks/mount-5fFig0k6.js +1447 -0
- package/dist/npm/chunks/nl-BfhqUsmX.js +187 -0
- package/dist/npm/chunks/privacy-DLhezjyi.js +30 -0
- package/dist/npm/chunks/pt-BR-CEPu4W5U.js +187 -0
- package/dist/{shared/pusher-CnhQgAvF.js → npm/chunks/pusher-BSsQoE1K.js} +224 -222
- package/dist/npm/chunks/realtime-CBRW9BB3.js +34 -0
- package/dist/npm/chunks/report-Dh4fxd4J.js +27 -0
- package/dist/npm/chunks/rolldown-runtime-Y_bBpyJl.js +20 -0
- package/dist/npm/chunks/src-DujplxfI.js +517 -0
- package/dist/npm/chunks/zh-CN-kgqjYwHQ.js +187 -0
- package/dist/npm/element.js +41 -0
- package/dist/npm/headless.js +3 -0
- package/dist/npm/index.js +3 -0
- package/dist/npm/react.js +26 -0
- package/dist/npm/svelte.js +17 -0
- package/dist/npm/types/adapters/react.d.ts +11 -0
- package/dist/npm/types/adapters/svelte.d.ts +9 -0
- package/dist/npm/types/adapters/vue.d.ts +118 -0
- package/dist/npm/types/anchor/index.d.ts +49 -0
- package/dist/npm/types/core/api.d.ts +31 -0
- package/dist/npm/types/core/auth.d.ts +87 -0
- package/dist/npm/types/core/client.d.ts +114 -0
- package/dist/npm/types/core/store.d.ts +7 -0
- package/dist/npm/types/core/types.d.ts +303 -0
- package/dist/npm/types/element.d.ts +13 -0
- package/dist/npm/types/headless.d.ts +7 -0
- package/dist/npm/types/index.d.ts +32 -0
- package/dist/npm/vue.js +71 -0
- package/package.json +71 -173
- package/dist/THIRD_PARTY_NOTICES.txt +0 -284
- package/dist/angular.es.js +0 -321
- package/dist/comment-kit.es.js +0 -218
- package/dist/demo.es.js +0 -483
- package/dist/headless.es.js +0 -4
- package/dist/preact.es.js +0 -117
- package/dist/qwik.es.js +0 -1
- package/dist/qwik.qwik.mjs +0 -114
- package/dist/react.es.js +0 -98
- package/dist/shared/ShadowRootContext-DD6a0QaI.js +0 -11
- package/dist/shared/annotation-icons-Dh-bmNYK.js +0 -172
- package/dist/shared/annotation-toolbar-zeiCmKIr.js +0 -1086
- package/dist/shared/attachment-refresh-DAacLaRu.js +0 -94
- package/dist/shared/bridge-CJoGYngu.js +0 -177
- package/dist/shared/button-D4GHW6oZ.js +0 -474
- package/dist/shared/button-group-BVR7iT-S.js +0 -91
- package/dist/shared/capture-privacy-CiOrcAlt.js +0 -101
- package/dist/shared/comment-drawing-canvas-Btc12IsS.js +0 -124
- package/dist/shared/comment-icon-D8JTCEJ7.js +0 -607
- package/dist/shared/comment-image-lightbox--QpbcAtH.js +0 -190
- package/dist/shared/comment-images-content-C_r4SHM-.js +0 -214
- package/dist/shared/comment-kit-core-CmLUFujd.js +0 -3682
- package/dist/shared/comment-kit-ui-BHwYuSIi.js +0 -19391
- package/dist/shared/comment-screenshot-annotator-zJZyO-XM.js +0 -151
- package/dist/shared/comment-screenshot-overlay-CoKTYB0J.js +0 -205
- package/dist/shared/comment-shortcut-groups-CfEmkitU.js +0 -153
- package/dist/shared/createReactComponent-BZHeRbD0.js +0 -45
- package/dist/shared/dev-export-panel-Cnt6oCZU.js +0 -207
- package/dist/shared/dev-grab-B85jo9AS.js +0 -197
- package/dist/shared/dist-D9A5k-N4.js +0 -617
- package/dist/shared/dom-Bhf4WFtY.js +0 -223
- package/dist/shared/element-selector-Cng84xC7.js +0 -902
- package/dist/shared/error-boundary-D3PD74vI.js +0 -21
- package/dist/shared/errors-Bu5ajEmB.js +0 -22
- package/dist/shared/icons-nzMOLzrm.js +0 -266
- package/dist/shared/input-UPtAj0M6.js +0 -111
- package/dist/shared/mount-ui-Dz7FB_Ak.js +0 -208
- package/dist/shared/realtime-recovery-BjlV-ewc.js +0 -162
- package/dist/shared/realtime-yGLX4wMK.js +0 -334
- package/dist/shared/request-activity-DQrAUwfA.js +0 -11
- package/dist/shared/screenshot-B5-hwpmt.js +0 -199
- package/dist/shared/separator-UhJb0Row.js +0 -3955
- package/dist/shared/shadow-root-B58ZI2yz.js +0 -133
- package/dist/shared/styles-CnYsLS2f.js +0 -2
- package/dist/shared/text-B4HHZNaa.js +0 -23
- package/dist/shared/token-session-D92MYbNu.js +0 -25
- package/dist/shared/useLabelableId-8n0QmH8N.js +0 -154
- package/dist/shared/useRender-Uxk1OPK-.js +0 -5
- package/dist/shared/useValueChanged-DKq5cMot.js +0 -92
- package/dist/shared/validation-3wbbbuX0.js +0 -70
- package/dist/shared/websocket-manager-KhH4hL0Q.js +0 -381
- package/dist/solid.es.js +0 -98
- package/dist/svelte.es.js +0 -130
- package/dist/types/adapters/bridge.d.ts +0 -122
- package/dist/types/angular/index.d.ts +0 -145
- package/dist/types/core/agent-context.d.ts +0 -17
- package/dist/types/core/api-client.d.ts +0 -155
- package/dist/types/core/comment-kit-core.d.ts +0 -254
- package/dist/types/core/local-demo.d.ts +0 -60
- package/dist/types/core/types.d.ts +0 -770
- package/dist/types/core/websocket-manager.d.ts +0 -125
- package/dist/types/core/write-access.d.ts +0 -11
- package/dist/types/demo.d.ts +0 -17
- package/dist/types/headless.d.ts +0 -8
- package/dist/types/index.d.ts +0 -87
- package/dist/types/preact/index.d.ts +0 -25
- package/dist/types/qwik/index.d.ts +0 -73
- package/dist/types/react/client.d.ts +0 -31
- package/dist/types/react/index.d.ts +0 -4
- package/dist/types/solid/index.d.ts +0 -37
- package/dist/types/svelte/index.d.ts +0 -55
- package/dist/types/utils/dom.d.ts +0 -59
- package/dist/types/utils/event-emitter.d.ts +0 -11
- package/dist/types/vue/index.d.ts +0 -87
- package/dist/vue.es.js +0 -148
- package/docs/api-reference.md +0 -405
- package/docs/local-demo.md +0 -60
|
@@ -0,0 +1,627 @@
|
|
|
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.idempotencyKey ?? (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()), r(this, "remember", !0), r(this, "authorize", null), 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 : this.pending()?.token ?? 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
|
+
return c ? await this.exchange(c, t) ? "signed_in" : "failed" : "cancelled";
|
|
165
|
+
}
|
|
166
|
+
async exchange(e, t) {
|
|
167
|
+
try {
|
|
168
|
+
return this.store(await this.post("/oauth/token", {
|
|
169
|
+
grant_type: "authorization_code",
|
|
170
|
+
client_id: this.projectKey,
|
|
171
|
+
code: e,
|
|
172
|
+
code_verifier: t
|
|
173
|
+
})), !0;
|
|
174
|
+
} catch {
|
|
175
|
+
return !1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async completeRedirect() {
|
|
179
|
+
let e = new URL(location.href), t = e.searchParams.get("ck_code"), n = e.searchParams.get("ck_state");
|
|
180
|
+
if (!t || !n) return !1;
|
|
181
|
+
e.searchParams.delete("ck_code"), e.searchParams.delete("ck_state"), history.replaceState(history.state, "", e.toString());
|
|
182
|
+
let r = null;
|
|
183
|
+
try {
|
|
184
|
+
r = JSON.parse(sessionStorage.getItem(this.pkceKey) ?? "null"), sessionStorage.removeItem(this.pkceKey);
|
|
185
|
+
} catch {
|
|
186
|
+
return !1;
|
|
187
|
+
}
|
|
188
|
+
return !r?.verifier || r.state !== n ? !1 : this.exchange(t, r.verifier);
|
|
189
|
+
}
|
|
190
|
+
get pkceKey() {
|
|
191
|
+
return `commentkit:pkce:${this.projectKey}`;
|
|
192
|
+
}
|
|
193
|
+
authorizeUrl(e, t, n, r) {
|
|
194
|
+
let i = new URL(this.authorize ?? "/widget/connect", this.endpoint);
|
|
195
|
+
return i.search = new URLSearchParams({
|
|
196
|
+
key: this.projectKey,
|
|
197
|
+
origin: this.origin,
|
|
198
|
+
code_challenge: e,
|
|
199
|
+
code_challenge_method: "S256",
|
|
200
|
+
state: t,
|
|
201
|
+
...n ? { share: n } : {},
|
|
202
|
+
...r ? { return_to: r } : {}
|
|
203
|
+
}).toString(), i;
|
|
204
|
+
}
|
|
205
|
+
redirect(e, t, n) {
|
|
206
|
+
try {
|
|
207
|
+
sessionStorage.setItem(this.pkceKey, JSON.stringify({
|
|
208
|
+
verifier: t,
|
|
209
|
+
state: n
|
|
210
|
+
}));
|
|
211
|
+
} catch {
|
|
212
|
+
return "failed";
|
|
213
|
+
}
|
|
214
|
+
return location.assign(e.toString()), "redirecting";
|
|
215
|
+
}
|
|
216
|
+
async signOut() {
|
|
217
|
+
let e = this.readRefresh();
|
|
218
|
+
this.clear(), e && await this.post("/oauth/revoke", { refresh_token: e }).catch(() => void 0);
|
|
219
|
+
}
|
|
220
|
+
awaitCode(e, t) {
|
|
221
|
+
let n = [new URL(this.endpoint).origin, new URL(this.authorize ?? this.endpoint).origin];
|
|
222
|
+
return new Promise((r) => {
|
|
223
|
+
let i = !1, a = Date.now(), o = (e) => {
|
|
224
|
+
i || (i = !0, window.removeEventListener("message", s), clearInterval(l), r(e));
|
|
225
|
+
}, s = (e) => {
|
|
226
|
+
if (!n.includes(e.origin)) return;
|
|
227
|
+
let r = e.data;
|
|
228
|
+
r?.type === "commentkit:auth" && r.state === t && typeof r.code == "string" && o(r.code);
|
|
229
|
+
};
|
|
230
|
+
window.addEventListener("message", s);
|
|
231
|
+
let c = null, l = setInterval(async () => {
|
|
232
|
+
if (Date.now() - a > g) return o(null);
|
|
233
|
+
e.closed && (c ?? (c = Date.now()));
|
|
234
|
+
try {
|
|
235
|
+
let e = await this.post("/oauth/poll", {
|
|
236
|
+
client_id: this.projectKey,
|
|
237
|
+
state: t
|
|
238
|
+
});
|
|
239
|
+
if (e?.status === "complete" && e.code) return o(e.code);
|
|
240
|
+
} catch {}
|
|
241
|
+
c !== null && Date.now() - c > 6e3 && o(null);
|
|
242
|
+
}, h);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
refresh() {
|
|
246
|
+
return this.refreshing ?? (this.refreshing = (async () => {
|
|
247
|
+
let e = this.readRefresh();
|
|
248
|
+
if (!e) return !1;
|
|
249
|
+
try {
|
|
250
|
+
let t = await this.post("/oauth/token", {
|
|
251
|
+
grant_type: "refresh_token",
|
|
252
|
+
client_id: this.projectKey,
|
|
253
|
+
refresh_token: e
|
|
254
|
+
});
|
|
255
|
+
return this.store(t), !0;
|
|
256
|
+
} catch (e) {
|
|
257
|
+
return e.status === 400 && this.clear(), !1;
|
|
258
|
+
} finally {
|
|
259
|
+
this.refreshing = null;
|
|
260
|
+
}
|
|
261
|
+
})()), this.refreshing;
|
|
262
|
+
}
|
|
263
|
+
configure(e) {
|
|
264
|
+
let t = this.readRefresh();
|
|
265
|
+
this.remember = e?.remember !== !1, t && this.write(t);
|
|
266
|
+
try {
|
|
267
|
+
let t = new URL(e?.authorize_url ?? "");
|
|
268
|
+
this.authorize = /^https?:$/.test(t.protocol) ? t.origin + t.pathname : null;
|
|
269
|
+
} catch {
|
|
270
|
+
this.authorize = null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
pending() {
|
|
274
|
+
try {
|
|
275
|
+
let e = JSON.parse(sessionStorage.getItem(this.pendingKey) ?? "null");
|
|
276
|
+
return e && e.expiresAt > Date.now() ? e : null;
|
|
277
|
+
} catch {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
setPending(e) {
|
|
282
|
+
try {
|
|
283
|
+
e ? sessionStorage.setItem(this.pendingKey, JSON.stringify(e)) : sessionStorage.removeItem(this.pendingKey);
|
|
284
|
+
} catch {}
|
|
285
|
+
}
|
|
286
|
+
get pendingKey() {
|
|
287
|
+
return `commentkit:pending:${this.projectKey}`;
|
|
288
|
+
}
|
|
289
|
+
adopt(e) {
|
|
290
|
+
this.setPending(null), this.store(e);
|
|
291
|
+
}
|
|
292
|
+
store(e) {
|
|
293
|
+
let t = this.hasSession();
|
|
294
|
+
this.access = {
|
|
295
|
+
token: e.access_token,
|
|
296
|
+
expiresAt: Date.now() + e.expires_in * 1e3
|
|
297
|
+
}, this.write(e.refresh_token), t || this.emit(!0);
|
|
298
|
+
}
|
|
299
|
+
write(e) {
|
|
300
|
+
this.stores().forEach((t, n) => {
|
|
301
|
+
try {
|
|
302
|
+
e && !n ? t.setItem(this.storageKey, JSON.stringify({ refresh_token: e })) : t.removeItem(this.storageKey);
|
|
303
|
+
} catch {}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
stores() {
|
|
307
|
+
try {
|
|
308
|
+
return this.remember ? [localStorage, sessionStorage] : [sessionStorage, localStorage];
|
|
309
|
+
} catch {
|
|
310
|
+
return [];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
clear() {
|
|
314
|
+
let e = this.hasSession();
|
|
315
|
+
this.access = null, this.write(null), e && this.emit(!1);
|
|
316
|
+
}
|
|
317
|
+
readRefresh() {
|
|
318
|
+
for (let e of this.stores()) try {
|
|
319
|
+
let t = JSON.parse(e.getItem(this.storageKey) ?? "null")?.refresh_token;
|
|
320
|
+
if (typeof t == "string") return t;
|
|
321
|
+
} catch {}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
emit(e) {
|
|
325
|
+
for (let t of [...this.listeners]) t(e);
|
|
326
|
+
}
|
|
327
|
+
async post(e, t) {
|
|
328
|
+
let n = await fetch(new URL(`/api/v1${e}`, this.endpoint), {
|
|
329
|
+
method: "POST",
|
|
330
|
+
headers: {
|
|
331
|
+
"Content-Type": "application/json",
|
|
332
|
+
Accept: "application/json"
|
|
333
|
+
},
|
|
334
|
+
body: JSON.stringify(t),
|
|
335
|
+
credentials: "omit"
|
|
336
|
+
});
|
|
337
|
+
if (n.status === 204) return;
|
|
338
|
+
let r = await n.json().catch(() => null);
|
|
339
|
+
if (!n.ok) throw Object.assign(/* @__PURE__ */ Error("auth_failed"), {
|
|
340
|
+
status: n.status,
|
|
341
|
+
data: r
|
|
342
|
+
});
|
|
343
|
+
return r;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/core/store.ts
|
|
348
|
+
function v(e) {
|
|
349
|
+
let t = e, n = /* @__PURE__ */ new Set();
|
|
350
|
+
return {
|
|
351
|
+
get: () => t,
|
|
352
|
+
set(e) {
|
|
353
|
+
let r = typeof e == "function" ? e(t) : e, i = !1;
|
|
354
|
+
for (let e in r) if (!Object.is(t[e], r[e])) {
|
|
355
|
+
i = !0;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
if (i) {
|
|
359
|
+
t = {
|
|
360
|
+
...t,
|
|
361
|
+
...r
|
|
362
|
+
};
|
|
363
|
+
for (let e of [...n]) e(t);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
subscribe(e) {
|
|
367
|
+
return n.add(e), () => n.delete(e);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/core/client.ts
|
|
373
|
+
var y = "1.0.0-beta.2", b = class {
|
|
374
|
+
constructor(e) {
|
|
375
|
+
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), r(this, "endpoint", void 0), r(this, "configRead", !1), this.options = e;
|
|
376
|
+
let t = (e.endpoint ?? "https://commentkit.dev").replace(/\/+$/, "");
|
|
377
|
+
this.endpoint = t, this.auth = new _(t, e.project), this.api = new o(t, this.auth, y), this.state = v({
|
|
378
|
+
config: null,
|
|
379
|
+
session: null,
|
|
380
|
+
threads: [],
|
|
381
|
+
loadingThreads: !1,
|
|
382
|
+
allBranches: !1,
|
|
383
|
+
unread: 0,
|
|
384
|
+
online: typeof navigator > "u" || navigator.onLine,
|
|
385
|
+
error: null,
|
|
386
|
+
here: 0,
|
|
387
|
+
opening: null
|
|
388
|
+
}), this.auth.onChange((e) => {
|
|
389
|
+
e || this.state.set({
|
|
390
|
+
session: null,
|
|
391
|
+
threads: [],
|
|
392
|
+
unread: 0
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
reportCrash(e, t = "crash") {
|
|
397
|
+
import("./report-Dh4fxd4J.js").then((n) => n.reportCrash(this.endpoint, this.options.project, y, e, t)).catch(() => void 0);
|
|
398
|
+
}
|
|
399
|
+
on(e, t) {
|
|
400
|
+
let n = this.listeners.get(e) ?? /* @__PURE__ */ new Set();
|
|
401
|
+
return n.add(t), this.listeners.set(e, n), () => n.delete(t);
|
|
402
|
+
}
|
|
403
|
+
emit(e, t) {
|
|
404
|
+
for (let n of this.listeners.get(e) ?? []) n(t);
|
|
405
|
+
}
|
|
406
|
+
async loadConfig() {
|
|
407
|
+
let e = this.configRead ? void 0 : { "X-CommentKit-Load": "1" }, t = await this.api.request("/widget/config", {
|
|
408
|
+
anonymous: !0,
|
|
409
|
+
query: { key: this.options.project },
|
|
410
|
+
headers: e
|
|
411
|
+
});
|
|
412
|
+
this.configRead = !0, this.auth.configure(t.auth);
|
|
413
|
+
let n = this.state.get().config;
|
|
414
|
+
return n && JSON.stringify(n) === JSON.stringify(t) ? n : (this.state.set({ config: t }), t);
|
|
415
|
+
}
|
|
416
|
+
async loadSession() {
|
|
417
|
+
if (!this.auth.hasSession()) return this.state.set({ session: null }), null;
|
|
418
|
+
try {
|
|
419
|
+
let e = await this.api.request("/me");
|
|
420
|
+
return this.state.set({ session: e }), this.emit("session:change", { session: e }), e;
|
|
421
|
+
} catch (e) {
|
|
422
|
+
if (e instanceof i && [401, 403].includes(e.status)) return this.state.set({ session: null }), null;
|
|
423
|
+
throw e;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
async signIn(e) {
|
|
427
|
+
let t = await this.auth.signIn({
|
|
428
|
+
share: e,
|
|
429
|
+
mode: this.options.auth
|
|
430
|
+
});
|
|
431
|
+
return t === "signed_in" && await this.loadSession(), t;
|
|
432
|
+
}
|
|
433
|
+
async signOut() {
|
|
434
|
+
await this.auth.signOut(), this.state.set({
|
|
435
|
+
session: null,
|
|
436
|
+
threads: []
|
|
437
|
+
}), this.emit("session:change", { session: null });
|
|
438
|
+
}
|
|
439
|
+
async loadPageThreads(e = x()) {
|
|
440
|
+
this.state.set({ loadingThreads: !0 });
|
|
441
|
+
try {
|
|
442
|
+
let t = await this.api.request("/threads", { query: {
|
|
443
|
+
page_url: e,
|
|
444
|
+
status: "active",
|
|
445
|
+
limit: 100,
|
|
446
|
+
branch: this.branchFilter()
|
|
447
|
+
} });
|
|
448
|
+
return this.state.set({
|
|
449
|
+
threads: t.data,
|
|
450
|
+
loadingThreads: !1
|
|
451
|
+
}), t.data;
|
|
452
|
+
} catch (e) {
|
|
453
|
+
throw this.state.set({ loadingThreads: !1 }), e;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
branchFilter() {
|
|
457
|
+
return this.state.get().allBranches ? void 0 : this.options.branch ?? void 0;
|
|
458
|
+
}
|
|
459
|
+
setAllBranches(e) {
|
|
460
|
+
return this.state.set({ allBranches: e }), this.loadPageThreads();
|
|
461
|
+
}
|
|
462
|
+
listThreads(e = {}) {
|
|
463
|
+
return this.api.request("/threads", { query: {
|
|
464
|
+
limit: 30,
|
|
465
|
+
...e
|
|
466
|
+
} });
|
|
467
|
+
}
|
|
468
|
+
getThread(e) {
|
|
469
|
+
return this.api.request(`/threads/${encodeURIComponent(e)}`).then((e) => e.data);
|
|
470
|
+
}
|
|
471
|
+
async createThread(e) {
|
|
472
|
+
let { data: t } = await this.api.request("/threads", {
|
|
473
|
+
method: "POST",
|
|
474
|
+
idempotent: !0,
|
|
475
|
+
idempotencyKey: e.idempotencyKey,
|
|
476
|
+
body: {
|
|
477
|
+
page: {
|
|
478
|
+
url: x(),
|
|
479
|
+
title: document.title.slice(0, 500) || null,
|
|
480
|
+
branch: this.options.branch ?? null,
|
|
481
|
+
commit_sha: this.options.commit ?? null,
|
|
482
|
+
deployment_url: this.options.deploymentUrl ?? null
|
|
483
|
+
},
|
|
484
|
+
anchor: e.anchor,
|
|
485
|
+
breakpoint: innerWidth,
|
|
486
|
+
body: e.body,
|
|
487
|
+
capture: e.capture ?? null,
|
|
488
|
+
attachment_ids: e.attachmentIds ?? [],
|
|
489
|
+
mention_ids: e.mentionIds ?? []
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
return this.upsert(t), this.emit("thread:created", { thread: t }), t;
|
|
493
|
+
}
|
|
494
|
+
async updateThread(e, t) {
|
|
495
|
+
let { data: n } = await this.api.request(`/threads/${encodeURIComponent(e)}`, {
|
|
496
|
+
method: "PATCH",
|
|
497
|
+
body: t
|
|
498
|
+
});
|
|
499
|
+
return this.upsert(n), this.emit("thread:updated", { thread: n }), n;
|
|
500
|
+
}
|
|
501
|
+
async deleteThread(e) {
|
|
502
|
+
await this.api.request(`/threads/${encodeURIComponent(e)}`, { method: "DELETE" }), this.state.set((t) => ({ threads: t.threads.filter((t) => t.id !== e) }));
|
|
503
|
+
}
|
|
504
|
+
messages(e, t) {
|
|
505
|
+
return this.api.request(`/threads/${encodeURIComponent(e)}/messages`, { query: {
|
|
506
|
+
cursor: t,
|
|
507
|
+
limit: 100
|
|
508
|
+
} });
|
|
509
|
+
}
|
|
510
|
+
async reply(e, t, n = {}) {
|
|
511
|
+
let { data: r } = await this.api.request(`/threads/${encodeURIComponent(e)}/messages`, {
|
|
512
|
+
method: "POST",
|
|
513
|
+
idempotent: !0,
|
|
514
|
+
body: {
|
|
515
|
+
body: t,
|
|
516
|
+
reply_to_id: n.replyTo ?? null,
|
|
517
|
+
attachment_ids: n.attachmentIds ?? [],
|
|
518
|
+
mention_ids: n.mentionIds ?? []
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
return this.emit("message:created", { message: r }), this.refreshThread(e), r;
|
|
522
|
+
}
|
|
523
|
+
editMessage(e, t) {
|
|
524
|
+
return this.api.request(`/messages/${encodeURIComponent(e)}`, {
|
|
525
|
+
method: "PATCH",
|
|
526
|
+
body: { body: t }
|
|
527
|
+
}).then((e) => e.data);
|
|
528
|
+
}
|
|
529
|
+
deleteMessage(e) {
|
|
530
|
+
return this.api.request(`/messages/${encodeURIComponent(e)}`, { method: "DELETE" });
|
|
531
|
+
}
|
|
532
|
+
react(e, t, n) {
|
|
533
|
+
return this.api.request(`/messages/${encodeURIComponent(e)}/reactions`, {
|
|
534
|
+
method: n ? "PUT" : "DELETE",
|
|
535
|
+
body: { emoji: t }
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
watch(e, t) {
|
|
539
|
+
return this.api.request(`/threads/${encodeURIComponent(e)}/watch`, { method: t ? "PUT" : "DELETE" });
|
|
540
|
+
}
|
|
541
|
+
labels() {
|
|
542
|
+
return this.api.request("/labels").then((e) => e.data);
|
|
543
|
+
}
|
|
544
|
+
people() {
|
|
545
|
+
return this.api.request("/people").then((e) => e.data);
|
|
546
|
+
}
|
|
547
|
+
async inbox() {
|
|
548
|
+
let e = await this.api.request("/inbox");
|
|
549
|
+
return this.state.set({ unread: e.unread }), e.data;
|
|
550
|
+
}
|
|
551
|
+
async markRead(e) {
|
|
552
|
+
let t = await this.api.request("/inbox/read", {
|
|
553
|
+
method: "POST",
|
|
554
|
+
body: {
|
|
555
|
+
ids: e.ids,
|
|
556
|
+
thread_id: e.threadId,
|
|
557
|
+
all: e.all
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
this.state.set({ unread: t.unread });
|
|
561
|
+
}
|
|
562
|
+
async upload(e, t, n = "file") {
|
|
563
|
+
let r = await this.api.request("/uploads", {
|
|
564
|
+
method: "POST",
|
|
565
|
+
body: {
|
|
566
|
+
name: t,
|
|
567
|
+
mime: e.type || "application/octet-stream",
|
|
568
|
+
bytes: e.size,
|
|
569
|
+
kind: n
|
|
570
|
+
}
|
|
571
|
+
}), a = await fetch(r.upload.url, {
|
|
572
|
+
method: "PUT",
|
|
573
|
+
headers: r.upload.headers,
|
|
574
|
+
body: e,
|
|
575
|
+
credentials: "omit"
|
|
576
|
+
});
|
|
577
|
+
if (!a.ok) throw new i(a.status, "upload_failed", "The file could not be uploaded. Please try again.");
|
|
578
|
+
return this.api.request(`/uploads/${r.id}/complete`, { method: "POST" }).then((e) => e.data);
|
|
579
|
+
}
|
|
580
|
+
async connectRealtime(e) {
|
|
581
|
+
let t = this.state.get().config, n = this.state.get().session;
|
|
582
|
+
if (!t?.features.realtime || !t.realtime || !n || this.realtime) return;
|
|
583
|
+
let { connect: r } = await import("./realtime-CBRW9BB3.js");
|
|
584
|
+
this.realtime = await r({
|
|
585
|
+
...t.realtime,
|
|
586
|
+
projectId: n.project.id,
|
|
587
|
+
inbox: `${n.person.type === "guest" ? "guest" : "user"}.${n.person.id}`,
|
|
588
|
+
authorize: async (e, t) => this.api.request("/realtime/auth", {
|
|
589
|
+
method: "POST",
|
|
590
|
+
body: {
|
|
591
|
+
socket_id: e,
|
|
592
|
+
channel_name: t
|
|
593
|
+
}
|
|
594
|
+
}),
|
|
595
|
+
onFeedback: e,
|
|
596
|
+
onInbox: (e) => this.state.set({ unread: e }),
|
|
597
|
+
onPresence: (e) => this.state.set({ here: e })
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
async refreshThread(e) {
|
|
601
|
+
try {
|
|
602
|
+
this.upsert(await this.getThread(e));
|
|
603
|
+
} catch (t) {
|
|
604
|
+
t instanceof i && t.status === 404 && this.state.set((t) => ({ threads: t.threads.filter((t) => t.id !== e) }));
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
upsert(e) {
|
|
608
|
+
this.state.set((t) => {
|
|
609
|
+
let n = e.page.url === x() && !["resolved", "closed"].includes(e.status), r = t.threads.filter((t) => t.id !== e.id);
|
|
610
|
+
return { threads: n ? [e, ...r] : r };
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
destroy() {
|
|
614
|
+
this.realtime?.disconnect(), this.realtime = null, this.listeners.clear();
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
function x() {
|
|
618
|
+
let e = new URL(location.href);
|
|
619
|
+
for (let t of [
|
|
620
|
+
"ck_thread",
|
|
621
|
+
"ck",
|
|
622
|
+
"ck_invite"
|
|
623
|
+
]) e.searchParams.delete(t);
|
|
624
|
+
return e.hash && !e.hash.startsWith("#/") && !e.hash.startsWith("#!/") && (e.hash = ""), e.toString();
|
|
625
|
+
}
|
|
626
|
+
//#endregion
|
|
627
|
+
export { f as a, i as c, _ as i, r as l, y as n, d as o, x as r, o 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 };
|