@commentkit/comment-kit 1.0.0 → 1.5.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.
- package/CHANGELOG.md +133 -1
- package/README.md +12 -5
- package/SECURITY.md +3 -1
- package/dist/npm/THIRD_PARTY_NOTICES.txt +22 -23
- package/dist/npm/chunks/AgentSend-DyWxNQ0p.js +64 -0
- package/dist/npm/chunks/Checklist-VYkSl6Q9.js +259 -0
- package/dist/npm/chunks/Composer-CnsGQirF.js +679 -0
- package/dist/npm/chunks/Guest-DkIvY5zt.js +170 -0
- package/dist/npm/chunks/MarkupEditor-DxTI9nJH.js +334 -0
- package/dist/npm/chunks/Panel-riaMYxt-.js +863 -0
- package/dist/npm/chunks/Settings-CB4zxQAL.js +206 -0
- package/dist/npm/chunks/{Shortcuts-BSOKdMHt.js → Shortcuts-D1cbajg_.js} +21 -17
- package/dist/npm/chunks/StyleEditor-BtTv3I8_.js +44 -0
- package/dist/npm/chunks/StylePanel-BI-n5Me1.js +199 -0
- package/dist/npm/chunks/TaskFields-HwrD0FrH.js +272 -0
- package/dist/npm/chunks/ThreadCard-CjaC8BTa.js +1026 -0
- package/dist/npm/chunks/Viewer-BnWshSXb.js +110 -0
- package/dist/npm/chunks/agent-Cr6NB6We.js +146 -0
- package/dist/npm/chunks/anchor-OCQnjp_6.js +294 -0
- package/dist/npm/chunks/{ar-O7EPv0mI.js → ar-BQ9K9Oqf.js} +189 -8
- package/dist/npm/chunks/card-bits-CxteYiZ9.js +126 -0
- package/dist/npm/chunks/client-CJ1tpI62.js +754 -0
- package/dist/npm/chunks/colors-0Ied7PE2.js +101 -0
- package/dist/npm/chunks/confetti-DKeKR7-6.js +41 -0
- package/dist/npm/chunks/{de-PGyZVNHX.js → de-CcPi8xdC.js} +160 -8
- package/dist/npm/chunks/drafts-CpQdHhcK.js +51 -0
- package/dist/npm/chunks/{es-Bq1idl8M.js → es-DXgkjDCG.js} +160 -8
- package/dist/npm/chunks/extension-BIGfr4Gh.js +50 -0
- package/dist/npm/chunks/{extension-B7SelsS0.js → extension-DkDSW4qw.js} +2 -2
- package/dist/npm/chunks/{fr-BVB9GGco.js → fr-IjJaUbWh.js} +160 -8
- package/dist/npm/chunks/{hi-DyBvrjzQ.js → hi-BhKQK2MU.js} +160 -8
- package/dist/npm/chunks/html2canvas-pro.esm-lgs6tb4C.js +8378 -0
- package/dist/npm/chunks/i18n-DAJGndZ2.js +904 -0
- package/dist/npm/chunks/{it-BlMMMwZh.js → it-DKiSCkiD.js} +160 -8
- package/dist/npm/chunks/{ja-lAioBCJv.js → ja-BI1WagDg.js} +160 -8
- package/dist/npm/chunks/{live-YFyP1GnP.js → live-B-mo27Qq.js} +1 -1
- package/dist/npm/chunks/lock-C82sC17d.js +30 -0
- package/dist/npm/chunks/{nl-DR8mLHnn.js → nl-CJw3VUQ5.js} +160 -8
- package/dist/npm/chunks/pick-CYPkLLFJ.js +120 -0
- package/dist/npm/chunks/{pt-BR-D7j6aDPx.js → pt-BR-CjBolC5g.js} +160 -8
- package/dist/npm/chunks/{pusher-BSsQoE1K.js → realtime-D22tI_AS.js} +58 -4
- package/dist/npm/chunks/source-CTQmAh0Y.js +146 -0
- package/dist/npm/chunks/src-CgBEoWl0.js +150 -0
- package/dist/npm/chunks/start-DW9_DKmf.js +1783 -0
- package/dist/npm/chunks/upload-BmrpZE5G.js +42 -0
- package/dist/npm/chunks/uploads-CipONvCy.js +541 -0
- package/dist/npm/chunks/{zh-CN-tzYg9NPH.js → zh-CN-BrZGx2S0.js} +160 -8
- package/dist/npm/element.js +4 -5
- package/dist/npm/headless.js +3 -3
- package/dist/npm/index.js +2 -2
- package/dist/npm/react.js +1 -1
- package/dist/npm/svelte.js +1 -1
- package/dist/npm/types/adapters/vue.d.ts +14 -0
- package/dist/npm/types/anchor/index.d.ts +22 -1
- package/dist/npm/types/core/api.d.ts +3 -0
- package/dist/npm/types/core/auth.d.ts +11 -0
- package/dist/npm/types/core/client.d.ts +128 -6
- package/dist/npm/types/core/types.d.ts +78 -4
- package/dist/npm/types/headless.d.ts +1 -1
- package/dist/npm/types/index.d.ts +6 -1
- package/dist/npm/vue.js +5 -1
- package/package.json +7 -5
- package/dist/npm/chunks/Guest-VNoofLxw.js +0 -157
- package/dist/npm/chunks/MarkupEditor-DTXrS3DD.js +0 -199
- package/dist/npm/chunks/Panel-B88JYH52.js +0 -438
- package/dist/npm/chunks/ThreadCard-izybwXIC.js +0 -817
- package/dist/npm/chunks/anchor-DT-Ynhh1.js +0 -270
- package/dist/npm/chunks/art-DK1JwPIo.js +0 -155
- package/dist/npm/chunks/client-Iegfv6ZC.js +0 -620
- package/dist/npm/chunks/colors-CX-IPjvb.js +0 -86
- package/dist/npm/chunks/extension-DSA8S8Qz.js +0 -26
- package/dist/npm/chunks/format-B5tJGtPC.js +0 -524
- package/dist/npm/chunks/html2canvas-DfGb8yka.js +0 -4024
- package/dist/npm/chunks/mount-Dx_8NhX3.js +0 -1484
- package/dist/npm/chunks/privacy-DLhezjyi.js +0 -30
- package/dist/npm/chunks/realtime-CBRW9BB3.js +0 -34
- package/dist/npm/chunks/src-C1Qp94nr.js +0 -549
|
@@ -1,620 +0,0 @@
|
|
|
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 = 500, 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(() => {
|
|
232
|
-
if (Date.now() - a > g) return o(null);
|
|
233
|
-
e.closed && (c ?? (c = Date.now())), c !== null && Date.now() - c > 1e3 && o(null);
|
|
234
|
-
}, h);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
refresh() {
|
|
238
|
-
return this.refreshing ?? (this.refreshing = (async () => {
|
|
239
|
-
let e = this.readRefresh();
|
|
240
|
-
if (!e) return !1;
|
|
241
|
-
try {
|
|
242
|
-
let t = await this.post("/oauth/token", {
|
|
243
|
-
grant_type: "refresh_token",
|
|
244
|
-
client_id: this.projectKey,
|
|
245
|
-
refresh_token: e
|
|
246
|
-
});
|
|
247
|
-
return this.store(t), !0;
|
|
248
|
-
} catch (e) {
|
|
249
|
-
return e.status === 400 && this.clear(), !1;
|
|
250
|
-
} finally {
|
|
251
|
-
this.refreshing = null;
|
|
252
|
-
}
|
|
253
|
-
})()), this.refreshing;
|
|
254
|
-
}
|
|
255
|
-
configure(e) {
|
|
256
|
-
let t = this.readRefresh();
|
|
257
|
-
this.remember = e?.remember !== !1, t && this.write(t);
|
|
258
|
-
try {
|
|
259
|
-
let t = new URL(e?.authorize_url ?? "");
|
|
260
|
-
this.authorize = /^https?:$/.test(t.protocol) ? t.origin + t.pathname : null;
|
|
261
|
-
} catch {
|
|
262
|
-
this.authorize = null;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
pending() {
|
|
266
|
-
try {
|
|
267
|
-
let e = JSON.parse(sessionStorage.getItem(this.pendingKey) ?? "null");
|
|
268
|
-
return e && e.expiresAt > Date.now() ? e : null;
|
|
269
|
-
} catch {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
setPending(e) {
|
|
274
|
-
try {
|
|
275
|
-
e ? sessionStorage.setItem(this.pendingKey, JSON.stringify(e)) : sessionStorage.removeItem(this.pendingKey);
|
|
276
|
-
} catch {}
|
|
277
|
-
}
|
|
278
|
-
get pendingKey() {
|
|
279
|
-
return `commentkit:pending:${this.projectKey}`;
|
|
280
|
-
}
|
|
281
|
-
adopt(e) {
|
|
282
|
-
this.setPending(null), this.store(e);
|
|
283
|
-
}
|
|
284
|
-
store(e) {
|
|
285
|
-
let t = this.hasSession();
|
|
286
|
-
this.access = {
|
|
287
|
-
token: e.access_token,
|
|
288
|
-
expiresAt: Date.now() + e.expires_in * 1e3
|
|
289
|
-
}, this.write(e.refresh_token), t || this.emit(!0);
|
|
290
|
-
}
|
|
291
|
-
write(e) {
|
|
292
|
-
this.stores().forEach((t, n) => {
|
|
293
|
-
try {
|
|
294
|
-
e && !n ? t.setItem(this.storageKey, JSON.stringify({ refresh_token: e })) : t.removeItem(this.storageKey);
|
|
295
|
-
} catch {}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
stores() {
|
|
299
|
-
try {
|
|
300
|
-
return this.remember ? [localStorage, sessionStorage] : [sessionStorage, localStorage];
|
|
301
|
-
} catch {
|
|
302
|
-
return [];
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
clear() {
|
|
306
|
-
let e = this.hasSession();
|
|
307
|
-
this.access = null, this.write(null), e && this.emit(!1);
|
|
308
|
-
}
|
|
309
|
-
readRefresh() {
|
|
310
|
-
for (let e of this.stores()) try {
|
|
311
|
-
let t = JSON.parse(e.getItem(this.storageKey) ?? "null")?.refresh_token;
|
|
312
|
-
if (typeof t == "string") return t;
|
|
313
|
-
} catch {}
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
emit(e) {
|
|
317
|
-
for (let t of [...this.listeners]) t(e);
|
|
318
|
-
}
|
|
319
|
-
async post(e, t) {
|
|
320
|
-
let n = await fetch(new URL(`/api/v1${e}`, this.endpoint), {
|
|
321
|
-
method: "POST",
|
|
322
|
-
headers: {
|
|
323
|
-
"Content-Type": "application/json",
|
|
324
|
-
Accept: "application/json"
|
|
325
|
-
},
|
|
326
|
-
body: JSON.stringify(t),
|
|
327
|
-
credentials: "omit"
|
|
328
|
-
});
|
|
329
|
-
if (n.status === 204) return;
|
|
330
|
-
let r = await n.json().catch(() => null);
|
|
331
|
-
if (!n.ok) throw Object.assign(/* @__PURE__ */ Error("auth_failed"), {
|
|
332
|
-
status: n.status,
|
|
333
|
-
data: r
|
|
334
|
-
});
|
|
335
|
-
return r;
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/core/store.ts
|
|
340
|
-
function v(e) {
|
|
341
|
-
let t = e, n = /* @__PURE__ */ new Set();
|
|
342
|
-
return {
|
|
343
|
-
get: () => t,
|
|
344
|
-
set(e) {
|
|
345
|
-
let r = typeof e == "function" ? e(t) : e, i = !1;
|
|
346
|
-
for (let e in r) if (!Object.is(t[e], r[e])) {
|
|
347
|
-
i = !0;
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
if (i) {
|
|
351
|
-
t = {
|
|
352
|
-
...t,
|
|
353
|
-
...r
|
|
354
|
-
};
|
|
355
|
-
for (let e of [...n]) e(t);
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
subscribe(e) {
|
|
359
|
-
return n.add(e), () => n.delete(e);
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region src/core/client.ts
|
|
365
|
-
var y = "1.0.0", b = "https://commentkit.dev", x = class {
|
|
366
|
-
constructor(e) {
|
|
367
|
-
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), r(this, "reportNonce", void 0), this.options = e;
|
|
368
|
-
let t = (e.endpoint ?? b).replace(/\/+$/, "");
|
|
369
|
-
this.endpoint = t, this.auth = new _(t, e.project), this.api = new o(t, this.auth, y), this.state = v({
|
|
370
|
-
config: null,
|
|
371
|
-
session: null,
|
|
372
|
-
threads: [],
|
|
373
|
-
loadingThreads: !1,
|
|
374
|
-
allBranches: !1,
|
|
375
|
-
unread: 0,
|
|
376
|
-
online: typeof navigator > "u" || navigator.onLine,
|
|
377
|
-
error: null,
|
|
378
|
-
here: 0,
|
|
379
|
-
opening: null
|
|
380
|
-
}), this.auth.onChange((e) => {
|
|
381
|
-
e || this.state.set({
|
|
382
|
-
session: null,
|
|
383
|
-
threads: [],
|
|
384
|
-
unread: 0
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
reportCrash(e, t = "crash") {
|
|
389
|
-
import("./report-DoDVi1qT.js").then((n) => n.reportCrash(this.endpoint, this.options.project, y, e, t, this.reportNonce)).catch(() => void 0);
|
|
390
|
-
}
|
|
391
|
-
on(e, t) {
|
|
392
|
-
let n = this.listeners.get(e) ?? /* @__PURE__ */ new Set();
|
|
393
|
-
return n.add(t), this.listeners.set(e, n), () => n.delete(t);
|
|
394
|
-
}
|
|
395
|
-
emit(e, t) {
|
|
396
|
-
for (let n of this.listeners.get(e) ?? []) n(t);
|
|
397
|
-
}
|
|
398
|
-
async loadConfig() {
|
|
399
|
-
let e = this.configRead ? void 0 : { "X-CommentKit-Load": "1" }, t = await this.api.request("/widget/config", {
|
|
400
|
-
anonymous: !0,
|
|
401
|
-
query: { key: this.options.project },
|
|
402
|
-
headers: e
|
|
403
|
-
});
|
|
404
|
-
this.configRead = !0, t.reporting?.nonce && (this.reportNonce = t.reporting.nonce), delete t.reporting, this.auth.configure(t.auth);
|
|
405
|
-
let n = this.state.get().config;
|
|
406
|
-
return n && JSON.stringify(n) === JSON.stringify(t) ? n : (this.state.set({ config: t }), t);
|
|
407
|
-
}
|
|
408
|
-
async loadSession() {
|
|
409
|
-
if (!this.auth.hasSession()) return this.state.set({ session: null }), null;
|
|
410
|
-
try {
|
|
411
|
-
let e = await this.api.request("/me");
|
|
412
|
-
return this.state.set({ session: e }), this.emit("session:change", { session: e }), e;
|
|
413
|
-
} catch (e) {
|
|
414
|
-
if (e instanceof i && [401, 403].includes(e.status)) return this.state.set({ session: null }), null;
|
|
415
|
-
throw e;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
async signIn(e) {
|
|
419
|
-
let t = await this.auth.signIn({
|
|
420
|
-
share: e,
|
|
421
|
-
mode: this.options.auth
|
|
422
|
-
});
|
|
423
|
-
return t === "signed_in" && await this.loadSession(), t;
|
|
424
|
-
}
|
|
425
|
-
async signOut() {
|
|
426
|
-
await this.auth.signOut(), this.state.set({
|
|
427
|
-
session: null,
|
|
428
|
-
threads: []
|
|
429
|
-
}), this.emit("session:change", { session: null });
|
|
430
|
-
}
|
|
431
|
-
async loadPageThreads(e = S()) {
|
|
432
|
-
this.state.set({ loadingThreads: !0 });
|
|
433
|
-
try {
|
|
434
|
-
let t = await this.api.request("/threads", { query: {
|
|
435
|
-
page_url: e,
|
|
436
|
-
status: "active",
|
|
437
|
-
limit: 100,
|
|
438
|
-
branch: this.branchFilter()
|
|
439
|
-
} });
|
|
440
|
-
return this.state.set({
|
|
441
|
-
threads: t.data,
|
|
442
|
-
loadingThreads: !1
|
|
443
|
-
}), t.data;
|
|
444
|
-
} catch (e) {
|
|
445
|
-
throw this.state.set({ loadingThreads: !1 }), e;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
branchFilter() {
|
|
449
|
-
return this.state.get().allBranches ? void 0 : this.options.branch ?? void 0;
|
|
450
|
-
}
|
|
451
|
-
setAllBranches(e) {
|
|
452
|
-
return this.state.set({ allBranches: e }), this.loadPageThreads();
|
|
453
|
-
}
|
|
454
|
-
listThreads(e = {}) {
|
|
455
|
-
return this.api.request("/threads", { query: {
|
|
456
|
-
limit: 30,
|
|
457
|
-
...e
|
|
458
|
-
} });
|
|
459
|
-
}
|
|
460
|
-
getThread(e) {
|
|
461
|
-
return this.api.request(`/threads/${encodeURIComponent(e)}`).then((e) => e.data);
|
|
462
|
-
}
|
|
463
|
-
async createThread(e) {
|
|
464
|
-
let { data: t } = await this.api.request("/threads", {
|
|
465
|
-
method: "POST",
|
|
466
|
-
idempotent: !0,
|
|
467
|
-
idempotencyKey: e.idempotencyKey,
|
|
468
|
-
body: {
|
|
469
|
-
page: {
|
|
470
|
-
url: S(),
|
|
471
|
-
title: document.title.slice(0, 500) || null,
|
|
472
|
-
branch: this.options.branch ?? null,
|
|
473
|
-
commit_sha: this.options.commit ?? null,
|
|
474
|
-
deployment_url: this.options.deploymentUrl ?? null
|
|
475
|
-
},
|
|
476
|
-
anchor: e.anchor,
|
|
477
|
-
breakpoint: innerWidth,
|
|
478
|
-
body: e.body,
|
|
479
|
-
capture: e.capture ?? null,
|
|
480
|
-
attachment_ids: e.attachmentIds ?? [],
|
|
481
|
-
mention_ids: e.mentionIds ?? []
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
return this.upsert(t), this.emit("thread:created", { thread: t }), t;
|
|
485
|
-
}
|
|
486
|
-
async updateThread(e, t) {
|
|
487
|
-
let { data: n } = await this.api.request(`/threads/${encodeURIComponent(e)}`, {
|
|
488
|
-
method: "PATCH",
|
|
489
|
-
body: t
|
|
490
|
-
});
|
|
491
|
-
return this.upsert(n), this.emit("thread:updated", { thread: n }), n;
|
|
492
|
-
}
|
|
493
|
-
async deleteThread(e) {
|
|
494
|
-
await this.api.request(`/threads/${encodeURIComponent(e)}`, { method: "DELETE" }), this.state.set((t) => ({ threads: t.threads.filter((t) => t.id !== e) }));
|
|
495
|
-
}
|
|
496
|
-
messages(e, t) {
|
|
497
|
-
return this.api.request(`/threads/${encodeURIComponent(e)}/messages`, { query: {
|
|
498
|
-
cursor: t,
|
|
499
|
-
limit: 100
|
|
500
|
-
} });
|
|
501
|
-
}
|
|
502
|
-
async reply(e, t, n = {}) {
|
|
503
|
-
let { data: r } = await this.api.request(`/threads/${encodeURIComponent(e)}/messages`, {
|
|
504
|
-
method: "POST",
|
|
505
|
-
idempotent: !0,
|
|
506
|
-
idempotencyKey: n.idempotencyKey,
|
|
507
|
-
body: {
|
|
508
|
-
body: t,
|
|
509
|
-
reply_to_id: n.replyTo ?? null,
|
|
510
|
-
attachment_ids: n.attachmentIds ?? [],
|
|
511
|
-
mention_ids: n.mentionIds ?? []
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
return this.emit("message:created", { message: r }), this.refreshThread(e), r;
|
|
515
|
-
}
|
|
516
|
-
editMessage(e, t) {
|
|
517
|
-
return this.api.request(`/messages/${encodeURIComponent(e)}`, {
|
|
518
|
-
method: "PATCH",
|
|
519
|
-
body: { body: t }
|
|
520
|
-
}).then((e) => e.data);
|
|
521
|
-
}
|
|
522
|
-
deleteMessage(e) {
|
|
523
|
-
return this.api.request(`/messages/${encodeURIComponent(e)}`, { method: "DELETE" });
|
|
524
|
-
}
|
|
525
|
-
react(e, t, n) {
|
|
526
|
-
return this.api.request(`/messages/${encodeURIComponent(e)}/reactions`, {
|
|
527
|
-
method: n ? "PUT" : "DELETE",
|
|
528
|
-
body: { emoji: t }
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
watch(e, t) {
|
|
532
|
-
return this.api.request(`/threads/${encodeURIComponent(e)}/watch`, { method: t ? "PUT" : "DELETE" });
|
|
533
|
-
}
|
|
534
|
-
labels() {
|
|
535
|
-
return this.api.request("/labels").then((e) => e.data);
|
|
536
|
-
}
|
|
537
|
-
people() {
|
|
538
|
-
return this.api.request("/people").then((e) => e.data);
|
|
539
|
-
}
|
|
540
|
-
async inbox() {
|
|
541
|
-
let e = await this.api.request("/inbox");
|
|
542
|
-
return this.state.set({ unread: e.unread }), e.data;
|
|
543
|
-
}
|
|
544
|
-
async markRead(e) {
|
|
545
|
-
let t = await this.api.request("/inbox/read", {
|
|
546
|
-
method: "POST",
|
|
547
|
-
body: {
|
|
548
|
-
ids: e.ids,
|
|
549
|
-
thread_id: e.threadId,
|
|
550
|
-
all: e.all
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
this.state.set({ unread: t.unread });
|
|
554
|
-
}
|
|
555
|
-
async upload(e, t, n = "file") {
|
|
556
|
-
let r = await this.api.request("/uploads", {
|
|
557
|
-
method: "POST",
|
|
558
|
-
body: {
|
|
559
|
-
name: t,
|
|
560
|
-
mime: e.type || "application/octet-stream",
|
|
561
|
-
bytes: e.size,
|
|
562
|
-
kind: n
|
|
563
|
-
}
|
|
564
|
-
}), a = await fetch(r.upload.url, {
|
|
565
|
-
method: "PUT",
|
|
566
|
-
headers: r.upload.headers,
|
|
567
|
-
body: e,
|
|
568
|
-
credentials: "omit"
|
|
569
|
-
});
|
|
570
|
-
if (!a.ok) throw new i(a.status, "upload_failed", "The file could not be uploaded. Please try again.");
|
|
571
|
-
return this.api.request(`/uploads/${r.id}/complete`, { method: "POST" }).then((e) => e.data);
|
|
572
|
-
}
|
|
573
|
-
async connectRealtime(e) {
|
|
574
|
-
let t = this.state.get().config, n = this.state.get().session;
|
|
575
|
-
if (!t?.features.realtime || !t.realtime || !n || this.realtime) return;
|
|
576
|
-
let { connect: r } = await import("./realtime-CBRW9BB3.js");
|
|
577
|
-
this.realtime = await r({
|
|
578
|
-
...t.realtime,
|
|
579
|
-
projectId: n.project.id,
|
|
580
|
-
inbox: `${n.person.type === "guest" ? "guest" : "user"}.${n.person.id}`,
|
|
581
|
-
authorize: async (e, t) => this.api.request("/realtime/auth", {
|
|
582
|
-
method: "POST",
|
|
583
|
-
body: {
|
|
584
|
-
socket_id: e,
|
|
585
|
-
channel_name: t
|
|
586
|
-
}
|
|
587
|
-
}),
|
|
588
|
-
onFeedback: e,
|
|
589
|
-
onInbox: (e) => this.state.set({ unread: e }),
|
|
590
|
-
onPresence: (e) => this.state.set({ here: e })
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
async refreshThread(e) {
|
|
594
|
-
try {
|
|
595
|
-
this.upsert(await this.getThread(e));
|
|
596
|
-
} catch (t) {
|
|
597
|
-
t instanceof i && t.status === 404 && this.state.set((t) => ({ threads: t.threads.filter((t) => t.id !== e) }));
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
upsert(e) {
|
|
601
|
-
this.state.set((t) => {
|
|
602
|
-
let n = e.page.url === S() && !["resolved", "closed"].includes(e.status), r = t.threads.filter((t) => t.id !== e.id);
|
|
603
|
-
return { threads: n ? [e, ...r] : r };
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
destroy() {
|
|
607
|
-
this.realtime?.disconnect(), this.realtime = null, this.listeners.clear();
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
function S() {
|
|
611
|
-
let e = new URL(location.href);
|
|
612
|
-
for (let t of [
|
|
613
|
-
"ck_thread",
|
|
614
|
-
"ck",
|
|
615
|
-
"ck_invite"
|
|
616
|
-
]) e.searchParams.delete(t);
|
|
617
|
-
return e.hash && !e.hash.startsWith("#/") && !e.hash.startsWith("#!/") && (e.hash = ""), e.toString();
|
|
618
|
-
}
|
|
619
|
-
//#endregion
|
|
620
|
-
export { f as a, i as c, _ as i, r as l, y as n, d as o, S as r, o as s, x as t };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
//#region src/capture/colors.ts
|
|
2
|
-
var e = [
|
|
3
|
-
"background-color",
|
|
4
|
-
"background-image",
|
|
5
|
-
"color",
|
|
6
|
-
"border-top-color",
|
|
7
|
-
"border-right-color",
|
|
8
|
-
"border-bottom-color",
|
|
9
|
-
"border-left-color",
|
|
10
|
-
"box-shadow",
|
|
11
|
-
"text-shadow",
|
|
12
|
-
"text-decoration-color",
|
|
13
|
-
"-webkit-text-stroke-color",
|
|
14
|
-
"list-style-image",
|
|
15
|
-
"fill",
|
|
16
|
-
"stroke"
|
|
17
|
-
];
|
|
18
|
-
function t(e, t) {
|
|
19
|
-
let n = 1, r = "";
|
|
20
|
-
for (let i = t; i < e.length; i++) {
|
|
21
|
-
let t = e[i];
|
|
22
|
-
if (t === "\\") i++;
|
|
23
|
-
else if (r) t === r && (r = "");
|
|
24
|
-
else if (t === "\"" || t === "'") r = t;
|
|
25
|
-
else if (t === "(") n++;
|
|
26
|
-
else if (t === ")" && --n === 0) return i;
|
|
27
|
-
}
|
|
28
|
-
return -1;
|
|
29
|
-
}
|
|
30
|
-
function n(n) {
|
|
31
|
-
let r = n.defaultView;
|
|
32
|
-
if (!r) return;
|
|
33
|
-
let i = null, a = /* @__PURE__ */ new Map(), o = (e) => {
|
|
34
|
-
let t = a.get(e);
|
|
35
|
-
if (t) return t;
|
|
36
|
-
if (!i) {
|
|
37
|
-
let e = n.createElement("canvas");
|
|
38
|
-
if (e.width = e.height = 1, i = e.getContext("2d", {
|
|
39
|
-
colorSpace: "srgb",
|
|
40
|
-
willReadFrequently: !0
|
|
41
|
-
}), !i) throw Error("Screenshot color conversion is unavailable");
|
|
42
|
-
}
|
|
43
|
-
if (i.fillStyle = "#010203", i.fillStyle = e, i.fillStyle === "#010203" && (i.fillStyle = "#040506", i.fillStyle = e, i.fillStyle === "#040506")) throw Error("Unsupported screenshot color");
|
|
44
|
-
i.clearRect(0, 0, 1, 1), i.fillRect(0, 0, 1, 1);
|
|
45
|
-
let [r, o, s, c] = i.getImageData(0, 0, 1, 1).data, l = `rgba(${r}, ${o}, ${s}, ${c / 255})`;
|
|
46
|
-
return a.set(e, l), l;
|
|
47
|
-
}, s = (e) => {
|
|
48
|
-
let n = /\b(url|oklch|oklab|lch|lab|hwb|color|color-mix|light-dark|(?:repeating-)?(?:linear|radial)-gradient)\(/gi, r = "", i = 0;
|
|
49
|
-
for (let a = n.exec(e); a; a = n.exec(e)) {
|
|
50
|
-
let c = t(e, n.lastIndex);
|
|
51
|
-
if (c < 0) return e;
|
|
52
|
-
let l = e.slice(a.index, c + 1), u = a[1].toLowerCase(), d = l;
|
|
53
|
-
if (u.endsWith("gradient")) {
|
|
54
|
-
let t = s(e.slice(n.lastIndex, c)), r = t.indexOf(","), i = t.slice(0, r), a = i.replace(/\s*\bin\s+[\w-]+(?:\s+(?:shorter|longer|increasing|decreasing)\s+hue)?\s*/i, "").trim();
|
|
55
|
-
a !== i.trim() && (t = (a ? a + "," : "") + t.slice(r + 1)), d = `${u}(${t})`;
|
|
56
|
-
} else u !== "url" && (d = o(l));
|
|
57
|
-
r += e.slice(i, a.index) + d, i = n.lastIndex = c + 1;
|
|
58
|
-
}
|
|
59
|
-
return r + e.slice(i);
|
|
60
|
-
}, c = [], l = [];
|
|
61
|
-
for (let t of n.querySelectorAll("*")) {
|
|
62
|
-
if (!t.style) continue;
|
|
63
|
-
let n = r.getComputedStyle(t), i = n.getPropertyValue("transition-property"), a = n.getPropertyValue("animation-name");
|
|
64
|
-
i && i !== "none" && l.push([
|
|
65
|
-
t.style,
|
|
66
|
-
"transition-property",
|
|
67
|
-
"none"
|
|
68
|
-
]), a && a !== "none" && l.push([
|
|
69
|
-
t.style,
|
|
70
|
-
"animation-play-state",
|
|
71
|
-
"paused"
|
|
72
|
-
]);
|
|
73
|
-
for (let r of e) {
|
|
74
|
-
let e = n.getPropertyValue(r), i = s(e);
|
|
75
|
-
i !== e && c.push([
|
|
76
|
-
t.style,
|
|
77
|
-
r,
|
|
78
|
-
i
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for (let [e, t, n] of l) e.setProperty(t, n, "important");
|
|
83
|
-
for (let [e, t, n] of c) e.setProperty(t, n, "important");
|
|
84
|
-
}
|
|
85
|
-
//#endregion
|
|
86
|
-
export { n as normalizeCaptureColors };
|