@viceme-ai/sdk 0.3.0 → 0.4.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/README.md +70 -45
- package/dist/browser-events.d.ts +49 -0
- package/dist/browser-events.d.ts.map +1 -0
- package/dist/capability-mount.d.ts +15 -0
- package/dist/capability-mount.d.ts.map +1 -0
- package/dist/chunks/{client-DKsaEtwq.js → client-Cbldd7F2.js} +321 -313
- package/dist/chunks/client-Cbldd7F2.js.map +1 -0
- package/dist/chunks/{version-C3KVoLNb.js → errors-B-Qv_azy.js} +4 -7
- package/dist/chunks/errors-B-Qv_azy.js.map +1 -0
- package/dist/chunks/version-C8DeBm39.js +6 -0
- package/dist/chunks/version-C8DeBm39.js.map +1 -0
- package/dist/core/build-endpoints.d.ts +2 -0
- package/dist/core/build-endpoints.d.ts.map +1 -1
- package/dist/core/capabilities.d.ts +2 -2
- package/dist/core/capabilities.d.ts.map +1 -1
- package/dist/core/client.d.ts +4 -2
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/lifecycle.d.ts +2 -4
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/core/presentation.d.ts +7 -2
- package/dist/core/presentation.d.ts.map +1 -1
- package/dist/danmaku/index.d.ts +1 -0
- package/dist/danmaku/index.d.ts.map +1 -1
- package/dist/danmaku/mount.d.ts +1 -1
- package/dist/danmaku/mount.d.ts.map +1 -1
- package/dist/danmaku.js +127 -121
- package/dist/danmaku.js.map +1 -1
- package/dist/generated/public-contract.d.ts +54 -410
- package/dist/generated/public-contract.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -21
- package/dist/index.js.map +1 -1
- package/dist/loader/attributes.d.ts +3 -2
- package/dist/loader/attributes.d.ts.map +1 -1
- package/dist/loader/auto-loader.d.ts +1 -1
- package/dist/loader/auto-loader.d.ts.map +1 -1
- package/dist/loader/events.d.ts +1 -44
- package/dist/loader/events.d.ts.map +1 -1
- package/dist/loader/registry.d.ts +2 -1
- package/dist/loader/registry.d.ts.map +1 -1
- package/dist/manifest.json +41 -28
- package/dist/session/session.d.ts +7 -6
- package/dist/session/session.d.ts.map +1 -1
- package/dist/testing/test-adapter.d.ts +1 -1
- package/dist/testing/test-adapter.d.ts.map +1 -1
- package/dist/testing.js +7 -6
- package/dist/testing.js.map +1 -1
- package/dist/tip/index.d.ts +22 -0
- package/dist/tip/index.d.ts.map +1 -0
- package/dist/tip/mount.d.ts +5 -0
- package/dist/tip/mount.d.ts.map +1 -0
- package/dist/tip.js +137 -0
- package/dist/tip.js.map +1 -0
- package/dist/transport/transport.d.ts +3 -1
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/viceme.min.js +2 -22
- package/dist/viceme.min.js.map +1 -1
- package/package.json +6 -2
- package/dist/chunks/client-DKsaEtwq.js.map +0 -1
- package/dist/chunks/version-C3KVoLNb.js.map +0 -1
- package/dist/loader/mount-handle.d.ts +0 -25
- package/dist/loader/mount-handle.d.ts.map +0 -1
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { b as M, a as T, V as w, c as C, i as G, B as W } from "./errors-B-Qv_azy.js";
|
|
2
|
+
import { S as z, A as H } from "./version-C8DeBm39.js";
|
|
3
|
+
const V = /* @__PURE__ */ new Set(["cn", "global"]), j = {
|
|
4
|
+
cn: M.cn,
|
|
5
|
+
global: M.global
|
|
5
6
|
};
|
|
6
|
-
function
|
|
7
|
-
return
|
|
7
|
+
function fe(t) {
|
|
8
|
+
return j[t];
|
|
8
9
|
}
|
|
9
10
|
function B(t) {
|
|
10
11
|
return typeof t == "string" && /^wrk_[A-Za-z0-9_-]{4,124}$/.test(t);
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
return typeof t == "string" &&
|
|
13
|
+
function Y(t) {
|
|
14
|
+
return typeof t == "string" && V.has(t);
|
|
14
15
|
}
|
|
15
16
|
function me(t) {
|
|
16
17
|
if (typeof t != "object" || t === null)
|
|
17
|
-
throw
|
|
18
|
+
throw T("createViceMe expects a configuration object.");
|
|
18
19
|
const e = t, i = /* @__PURE__ */ new Set(["workKey", "region", "signal"]);
|
|
19
20
|
for (const a of Object.keys(e))
|
|
20
21
|
if (!i.has(a))
|
|
21
|
-
throw
|
|
22
|
+
throw T(`Unknown configuration field "${a}".`);
|
|
22
23
|
if (!B(e.workKey))
|
|
23
|
-
throw
|
|
24
|
-
if (!
|
|
25
|
-
throw
|
|
24
|
+
throw T('Configuration field "workKey" must be a public work key ("wrk_…").');
|
|
25
|
+
if (!Y(e.region))
|
|
26
|
+
throw T('Configuration field "region" must be "cn" or "global".');
|
|
26
27
|
if (e.signal !== void 0 && !(e.signal instanceof AbortSignal))
|
|
27
|
-
throw
|
|
28
|
+
throw T('Configuration field "signal" must be an AbortSignal.');
|
|
28
29
|
return {
|
|
29
30
|
workKey: e.workKey,
|
|
30
31
|
region: e.region,
|
|
31
32
|
signal: e.signal
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
-
CREATED: ["
|
|
36
|
-
INITIALIZING: ["READY", "FAILED", "DESTROYED"],
|
|
35
|
+
const $ = {
|
|
36
|
+
CREATED: ["READY", "DESTROYED"],
|
|
37
37
|
READY: ["DEGRADED", "DESTROYED"],
|
|
38
38
|
DEGRADED: ["DESTROYED"],
|
|
39
|
-
FAILED: ["INITIALIZING", "DESTROYED"],
|
|
40
39
|
DESTROYED: []
|
|
41
40
|
};
|
|
42
|
-
class
|
|
41
|
+
class Q {
|
|
43
42
|
#e = "CREATED";
|
|
44
43
|
#t = /* @__PURE__ */ new Set();
|
|
45
44
|
get state() {
|
|
@@ -50,8 +49,8 @@ class X {
|
|
|
50
49
|
}
|
|
51
50
|
transition(e) {
|
|
52
51
|
if (e !== this.#e) {
|
|
53
|
-
if (
|
|
54
|
-
throw new
|
|
52
|
+
if (!$[this.#e].includes(e))
|
|
53
|
+
throw new w({
|
|
55
54
|
code: "INTERNAL_ERROR",
|
|
56
55
|
message: `Illegal lifecycle transition ${this.#e} -> ${e}.`,
|
|
57
56
|
retryable: !1
|
|
@@ -62,7 +61,7 @@ class X {
|
|
|
62
61
|
}
|
|
63
62
|
/** Any operation on a destroyed client must fail closed with this guard. */
|
|
64
63
|
assertAlive() {
|
|
65
|
-
if (this.destroyed) throw
|
|
64
|
+
if (this.destroyed) throw C();
|
|
66
65
|
}
|
|
67
66
|
subscribe(e) {
|
|
68
67
|
return this.#t.add(e), () => {
|
|
@@ -73,34 +72,38 @@ class X {
|
|
|
73
72
|
this.#t.clear();
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
function
|
|
75
|
+
function X(t, e) {
|
|
77
76
|
if (typeof t != "object" || t === null)
|
|
78
|
-
throw
|
|
79
|
-
const i = t
|
|
80
|
-
if (typeof
|
|
81
|
-
throw
|
|
82
|
-
if (
|
|
83
|
-
throw new
|
|
77
|
+
throw R();
|
|
78
|
+
const i = t;
|
|
79
|
+
if (typeof i.workKey != "string" || !Array.isArray(i.capabilities) || !i.capabilities.every((c) => typeof c == "string"))
|
|
80
|
+
throw R();
|
|
81
|
+
if (i.workKey !== e)
|
|
82
|
+
throw new w({
|
|
84
83
|
code: "WORK_NOT_FOUND",
|
|
85
84
|
message: "Work-session response did not match the requested work key.",
|
|
86
85
|
retryable: !1
|
|
87
86
|
});
|
|
88
|
-
const
|
|
87
|
+
const a = {
|
|
89
88
|
work: {
|
|
90
|
-
key:
|
|
91
|
-
capabilities:
|
|
89
|
+
key: i.workKey,
|
|
90
|
+
capabilities: i.capabilities
|
|
92
91
|
}
|
|
93
92
|
};
|
|
94
|
-
|
|
93
|
+
if (typeof i.token == "string" && (a.token = i.token), typeof i.expiresAt == "string") {
|
|
94
|
+
const c = new Date(i.expiresAt).getTime();
|
|
95
|
+
Number.isNaN(c) || (a.expiresAt = c);
|
|
96
|
+
}
|
|
97
|
+
return a;
|
|
95
98
|
}
|
|
96
|
-
function
|
|
97
|
-
return new
|
|
99
|
+
function R() {
|
|
100
|
+
return new w({
|
|
98
101
|
code: "INTERNAL_ERROR",
|
|
99
102
|
message: "Malformed work-session response.",
|
|
100
103
|
retryable: !0
|
|
101
104
|
});
|
|
102
105
|
}
|
|
103
|
-
class
|
|
106
|
+
class J {
|
|
104
107
|
#e;
|
|
105
108
|
#t;
|
|
106
109
|
#i;
|
|
@@ -130,12 +133,12 @@ class ee {
|
|
|
130
133
|
}
|
|
131
134
|
return this.#a ??= this.#e.transport.request({
|
|
132
135
|
method: "POST",
|
|
133
|
-
path: "/v1/public/
|
|
136
|
+
path: "/v1/public/work-sdk/sessions",
|
|
134
137
|
body: { workKey: this.#e.workKey },
|
|
135
138
|
signal: this.#e.signal,
|
|
136
139
|
timeoutMs: this.#e.timeoutMs
|
|
137
140
|
}).then((e) => {
|
|
138
|
-
const i =
|
|
141
|
+
const i = X(e.body, this.#e.workKey);
|
|
139
142
|
return this.#i = i, i;
|
|
140
143
|
}).finally(() => {
|
|
141
144
|
this.#a = void 0;
|
|
@@ -143,31 +146,32 @@ class ee {
|
|
|
143
146
|
}
|
|
144
147
|
async request(e) {
|
|
145
148
|
const i = await this.establish();
|
|
146
|
-
if (!i.token) throw
|
|
149
|
+
if (!i.token) throw R();
|
|
147
150
|
try {
|
|
148
151
|
return await this.#e.transport.request({
|
|
149
152
|
...e,
|
|
150
153
|
authorization: i.token,
|
|
154
|
+
userAuthorization: i.userToken,
|
|
151
155
|
signal: this.#e.signal
|
|
152
156
|
});
|
|
153
157
|
} catch (a) {
|
|
154
|
-
if (!(a instanceof
|
|
158
|
+
if (!(a instanceof w) || a.code !== "SESSION_EXPIRED") throw a;
|
|
155
159
|
this.#i === i && this.invalidate();
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
160
|
+
const c = await this.establish();
|
|
161
|
+
if (!c.token) throw R();
|
|
158
162
|
return this.#e.transport.request({
|
|
159
163
|
...e,
|
|
160
|
-
authorization:
|
|
164
|
+
authorization: c.token,
|
|
165
|
+
userAuthorization: c.userToken,
|
|
161
166
|
signal: this.#e.signal
|
|
162
167
|
});
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
authenticate(e) {
|
|
166
|
-
if (!this.#i) throw
|
|
171
|
+
if (!this.#i) throw R();
|
|
167
172
|
this.#i = {
|
|
168
173
|
...this.#i,
|
|
169
|
-
|
|
170
|
-
expiresAt: e.expiresAt,
|
|
174
|
+
userToken: e.userToken,
|
|
171
175
|
user: e.user
|
|
172
176
|
};
|
|
173
177
|
}
|
|
@@ -183,23 +187,28 @@ class ee {
|
|
|
183
187
|
this.invalidate(), this.#a = void 0;
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
|
-
const
|
|
187
|
-
function
|
|
190
|
+
const _ = "viceme-access-layer", D = 50;
|
|
191
|
+
function Z(t) {
|
|
188
192
|
switch (t) {
|
|
189
193
|
case "SIGN_IN":
|
|
190
194
|
return {
|
|
191
195
|
description: "",
|
|
192
196
|
label: "授权"
|
|
193
197
|
};
|
|
198
|
+
case "FOLLOW":
|
|
199
|
+
return {
|
|
200
|
+
description: "",
|
|
201
|
+
label: "关注"
|
|
202
|
+
};
|
|
194
203
|
case "CHECKOUT":
|
|
195
204
|
return {
|
|
196
205
|
description: "",
|
|
197
|
-
label: "
|
|
206
|
+
label: "打开支付"
|
|
198
207
|
};
|
|
199
208
|
}
|
|
200
209
|
}
|
|
201
|
-
function
|
|
202
|
-
if (!
|
|
210
|
+
function ee(t) {
|
|
211
|
+
if (!G(t)) return "操作未完成,请重试。";
|
|
203
212
|
switch (t.code) {
|
|
204
213
|
case "CONFIG_INVALID":
|
|
205
214
|
return "微信授权配置无效,请稍后重试。";
|
|
@@ -213,12 +222,12 @@ function ie(t) {
|
|
|
213
222
|
return t.requestId ? `操作未完成,请重试。请求 ID:${t.requestId}` : "操作未完成,请重试。";
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
|
-
function
|
|
217
|
-
if (customElements.get(
|
|
225
|
+
function te() {
|
|
226
|
+
if (customElements.get(_)) return;
|
|
218
227
|
class t extends HTMLElement {
|
|
219
228
|
interaction;
|
|
220
229
|
connectedCallback() {
|
|
221
|
-
const i =
|
|
230
|
+
const i = Z(this.interaction.action), a = this.attachShadow({ mode: "open" });
|
|
222
231
|
a.innerHTML = `
|
|
223
232
|
<style>
|
|
224
233
|
:host {
|
|
@@ -325,25 +334,6 @@ function ae() {
|
|
|
325
334
|
font-size: 0.875rem;
|
|
326
335
|
}
|
|
327
336
|
[data-viceme='profile-header'] { min-width: 0; }
|
|
328
|
-
[data-viceme='profile-covers'] {
|
|
329
|
-
display: none;
|
|
330
|
-
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
331
|
-
gap: 0.75rem;
|
|
332
|
-
margin-top: 1.25rem;
|
|
333
|
-
border-radius: 0.875rem;
|
|
334
|
-
padding: 0.75rem;
|
|
335
|
-
background: #f4f4f5;
|
|
336
|
-
}
|
|
337
|
-
[data-viceme='profile-covers'][data-visible='true'] { display: grid; }
|
|
338
|
-
[data-viceme='profile-cover'] {
|
|
339
|
-
display: block;
|
|
340
|
-
width: 100%;
|
|
341
|
-
aspect-ratio: 16 / 9;
|
|
342
|
-
border: 1px solid #e4e4e7;
|
|
343
|
-
border-radius: 0.625rem;
|
|
344
|
-
object-fit: cover;
|
|
345
|
-
background: #ffffff;
|
|
346
|
-
}
|
|
347
337
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='description'] { display: none; }
|
|
348
338
|
[data-viceme='panel'][data-action='SIGN_IN'] [data-viceme='profile'][data-visible='true'] {
|
|
349
339
|
display: block;
|
|
@@ -441,7 +431,6 @@ function ae() {
|
|
|
441
431
|
</div>
|
|
442
432
|
</div>
|
|
443
433
|
<p data-viceme="profile-description"></p>
|
|
444
|
-
<div data-viceme="profile-covers" aria-label="作品封面"></div>
|
|
445
434
|
</section>
|
|
446
435
|
<p data-viceme="error" role="alert" aria-live="polite"></p>
|
|
447
436
|
<div data-viceme="actions">
|
|
@@ -451,88 +440,70 @@ function ae() {
|
|
|
451
440
|
<iframe data-viceme="frame" title="" referrerpolicy="no-referrer" allow="payment"></iframe>
|
|
452
441
|
</section>
|
|
453
442
|
`;
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
const
|
|
443
|
+
const c = a.querySelector("[data-viceme='panel']");
|
|
444
|
+
c.dataset.action = this.interaction.action, c.dataset.frame = "false";
|
|
445
|
+
const S = a.querySelector("[data-viceme='description']");
|
|
446
|
+
S.textContent = i.description;
|
|
447
|
+
const u = a.querySelector("[data-viceme='action']"), A = u.parentElement, E = a.querySelector("[data-viceme='close']"), L = a.querySelector("[data-viceme='backdrop']"), N = a.querySelector("[data-viceme='error']"), I = a.querySelector("[data-viceme='frame']"), U = a.querySelector("[data-viceme='profile']"), r = a.querySelector("[data-viceme='avatar']"), o = a.querySelector("[data-viceme='avatar-fallback']"), l = a.querySelector("[data-viceme='profile-name']"), n = a.querySelector(
|
|
459
448
|
"[data-viceme='profile-description']"
|
|
460
|
-
),
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
I.title = this.interaction.action === "SIGN_IN" ? "
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
|
|
449
|
+
), f = a.querySelector("[data-viceme='profile-stats']");
|
|
450
|
+
u.textContent = i.label, u.hidden = !1, A.dataset.single = "true";
|
|
451
|
+
const b = i.label;
|
|
452
|
+
I.title = this.interaction.action === "SIGN_IN" ? "登录授权" : "支付";
|
|
453
|
+
const d = this.interaction.followTarget;
|
|
454
|
+
if (d) {
|
|
455
|
+
c.setAttribute(
|
|
467
456
|
"aria-label",
|
|
468
|
-
this.interaction.action === "SIGN_IN" ? `授权 ${
|
|
469
|
-
),
|
|
470
|
-
const s = [...
|
|
471
|
-
|
|
472
|
-
p.remove();
|
|
473
|
-
else {
|
|
474
|
-
for (const [O, k] of u.coverUrls.entries()) {
|
|
475
|
-
const A = document.createElement("img");
|
|
476
|
-
A.dataset.viceme = "profile-cover", A.src = k, A.alt = `${u.displayName}的作品封面 ${O + 1}`, p.append(A);
|
|
477
|
-
}
|
|
478
|
-
p.dataset.visible = "true";
|
|
479
|
-
}
|
|
480
|
-
n.textContent = u.displayName.trim().slice(0, 1) || "V", u.avatarUrl && (r.src = u.avatarUrl, r.alt = `${u.displayName}的头像`, r.hidden = !1, n.hidden = !0);
|
|
457
|
+
this.interaction.action === "SIGN_IN" ? `授权 ${d.displayName}` : `关注 ${d.displayName}`
|
|
458
|
+
), U.dataset.visible = "true", l.textContent = d.displayName;
|
|
459
|
+
const s = [...d.description ?? ""];
|
|
460
|
+
n.textContent = s.length > D ? `${s.slice(0, D).join("")}…` : s.join(""), s.length > D && (n.title = d.description), f.textContent = `${d.workCount} 个作品`, o.textContent = d.displayName.trim().slice(0, 1) || "V", d.avatarUrl && (r.src = d.avatarUrl, r.alt = `${d.displayName}的头像`, r.hidden = !1, o.hidden = !0);
|
|
481
461
|
}
|
|
482
|
-
let
|
|
483
|
-
const
|
|
462
|
+
let y = null;
|
|
463
|
+
const k = (s) => {
|
|
484
464
|
this.dispatchEvent(new CustomEvent("viceme:access-layer-close", { detail: s }));
|
|
485
|
-
},
|
|
486
|
-
|
|
465
|
+
}, h = () => {
|
|
466
|
+
y?.cancel(), k("dismissed");
|
|
487
467
|
};
|
|
488
|
-
|
|
489
|
-
if (s.key === "Escape" &&
|
|
490
|
-
if (s.preventDefault(),
|
|
468
|
+
L.addEventListener("click", h), E.addEventListener("click", h), this.addEventListener("keydown", (s) => {
|
|
469
|
+
if (s.key === "Escape" && h(), s.key === "Tab") {
|
|
470
|
+
if (s.preventDefault(), y?.type === "frame") {
|
|
491
471
|
I.focus();
|
|
492
472
|
return;
|
|
493
473
|
}
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
const
|
|
497
|
-
|
|
474
|
+
const p = [E, ...u.hidden ? [] : [u]].filter((K) => !K.disabled && !K.hidden);
|
|
475
|
+
if (p.length === 0) return;
|
|
476
|
+
const q = p.indexOf(a.activeElement), F = s.shiftKey ? -1 : 1;
|
|
477
|
+
p[(q + F + p.length) % p.length]?.focus();
|
|
498
478
|
}
|
|
499
479
|
});
|
|
500
|
-
const
|
|
501
|
-
|
|
480
|
+
const O = async () => {
|
|
481
|
+
u.disabled = !0, u.setAttribute("aria-busy", "true"), u.textContent = "正在打开…", N.textContent = "";
|
|
502
482
|
try {
|
|
503
483
|
const s = await this.interaction.perform();
|
|
504
|
-
|
|
505
|
-
if (w = s, this.interaction.action === "SIGN_IN") {
|
|
506
|
-
const O = l.getBoundingClientRect().height;
|
|
507
|
-
O > 0 && (l.style.height = `${O}px`);
|
|
508
|
-
}
|
|
509
|
-
l.dataset.frame = "true", I.src = s.url, I.focus(), await s.completion;
|
|
510
|
-
}
|
|
511
|
-
D("acted");
|
|
484
|
+
s.type === "frame" ? (y = s, c.dataset.frame = "true", I.src = s.url, I.focus(), await s.completion) : s.type === "external" && (y = s, await s.completion), k("acted");
|
|
512
485
|
} catch (s) {
|
|
513
|
-
|
|
486
|
+
y?.cancel(), y = null, c.dataset.frame = "false", I.removeAttribute("src"), N.textContent = ee(s), u.hidden = !1, u.disabled = !1, u.removeAttribute("aria-busy"), u.textContent = b, u.focus();
|
|
514
487
|
}
|
|
515
488
|
};
|
|
516
|
-
|
|
517
|
-
g();
|
|
518
|
-
}) : queueMicrotask(() => f.focus());
|
|
489
|
+
u.addEventListener("click", O), queueMicrotask(() => u.focus());
|
|
519
490
|
}
|
|
520
491
|
}
|
|
521
|
-
customElements.define(
|
|
492
|
+
customElements.define(_, t);
|
|
522
493
|
}
|
|
523
|
-
const
|
|
494
|
+
const x = async (t) => {
|
|
524
495
|
if (typeof document > "u" || typeof customElements > "u")
|
|
525
496
|
return "dismissed";
|
|
526
|
-
|
|
527
|
-
const e = document.createElement(
|
|
497
|
+
te();
|
|
498
|
+
const e = document.createElement(_);
|
|
528
499
|
e.interaction = t;
|
|
529
500
|
const i = document.documentElement.style.overflow, a = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
530
501
|
document.documentElement.style.overflow = "hidden", document.body.append(e);
|
|
531
502
|
try {
|
|
532
|
-
return await new Promise((
|
|
503
|
+
return await new Promise((c) => {
|
|
533
504
|
e.addEventListener(
|
|
534
505
|
"viceme:access-layer-close",
|
|
535
|
-
(
|
|
506
|
+
(S) => c(S.detail),
|
|
536
507
|
{ once: !0 }
|
|
537
508
|
);
|
|
538
509
|
});
|
|
@@ -540,59 +511,57 @@ const _ = async (t) => {
|
|
|
540
511
|
e.remove(), document.documentElement.style.overflow = i, a?.focus();
|
|
541
512
|
}
|
|
542
513
|
};
|
|
543
|
-
function
|
|
514
|
+
function v(t) {
|
|
544
515
|
if (typeof t != "object" || t === null) throw m();
|
|
545
516
|
return t;
|
|
546
517
|
}
|
|
547
518
|
function m() {
|
|
548
|
-
return new
|
|
519
|
+
return new w({
|
|
549
520
|
code: "INTERNAL_ERROR",
|
|
550
521
|
message: "Malformed public API response.",
|
|
551
522
|
retryable: !0
|
|
552
523
|
});
|
|
553
524
|
}
|
|
554
|
-
function
|
|
555
|
-
const e =
|
|
556
|
-
if (typeof e.
|
|
525
|
+
function ie(t) {
|
|
526
|
+
const e = v(t);
|
|
527
|
+
if (typeof e.id != "string" || !(typeof e.displayName == "string" || e.displayName === null) || !(typeof e.avatarUrl == "string" || e.avatarUrl === null))
|
|
557
528
|
throw m();
|
|
558
529
|
return {
|
|
559
|
-
subject: e.
|
|
560
|
-
nickname: e.
|
|
530
|
+
subject: e.id,
|
|
531
|
+
nickname: e.displayName,
|
|
561
532
|
avatarUrl: e.avatarUrl
|
|
562
533
|
};
|
|
563
534
|
}
|
|
564
|
-
function
|
|
565
|
-
const e =
|
|
535
|
+
function P(t) {
|
|
536
|
+
const e = v(t);
|
|
566
537
|
if (typeof e.following != "boolean" || !(typeof e.followedAt == "string" || e.followedAt === null))
|
|
567
538
|
throw m();
|
|
568
|
-
const i =
|
|
569
|
-
if (
|
|
539
|
+
const i = v(e.creator);
|
|
540
|
+
if (typeof i.displayName != "string" || !(typeof i.avatarUrl == "string" || i.avatarUrl === null) || !(typeof i.description == "string" || i.description === null) || !Number.isInteger(i.publishedWorkCount) || i.publishedWorkCount < 0)
|
|
570
541
|
throw m();
|
|
571
542
|
return {
|
|
572
543
|
following: e.following,
|
|
573
544
|
followedAt: e.followedAt,
|
|
574
545
|
target: {
|
|
575
|
-
kind:
|
|
546
|
+
kind: "CREATOR",
|
|
576
547
|
displayName: i.displayName,
|
|
577
548
|
avatarUrl: i.avatarUrl,
|
|
578
549
|
description: i.description,
|
|
579
|
-
workCount: i.
|
|
580
|
-
coverUrls: i.coverUrls
|
|
550
|
+
workCount: i.publishedWorkCount
|
|
581
551
|
}
|
|
582
552
|
};
|
|
583
553
|
}
|
|
584
|
-
function
|
|
585
|
-
const e =
|
|
554
|
+
function ae(t) {
|
|
555
|
+
const e = v(t), i = /* @__PURE__ */ new Set([
|
|
556
|
+
"PUBLIC",
|
|
586
557
|
"OWNER",
|
|
587
558
|
"FOLLOWING",
|
|
588
|
-
"PURCHASED",
|
|
589
559
|
"ENTITLED",
|
|
590
560
|
"AUTH_REQUIRED",
|
|
591
561
|
"FOLLOW_REQUIRED",
|
|
592
562
|
"PURCHASE_REQUIRED",
|
|
593
563
|
"FEATURE_NOT_FOUND",
|
|
594
|
-
"FEATURE_DISABLED"
|
|
595
|
-
"POLICY_UNSUPPORTED"
|
|
564
|
+
"FEATURE_DISABLED"
|
|
596
565
|
]), a = /* @__PURE__ */ new Set([null, "SIGN_IN", "FOLLOW", "CHECKOUT"]);
|
|
597
566
|
if (typeof e.allowed != "boolean" || typeof e.reason != "string" || !i.has(e.reason) || !a.has(e.nextAction))
|
|
598
567
|
throw m();
|
|
@@ -602,247 +571,286 @@ function ne(t) {
|
|
|
602
571
|
nextAction: e.nextAction
|
|
603
572
|
};
|
|
604
573
|
}
|
|
605
|
-
function
|
|
606
|
-
const e =
|
|
607
|
-
if (typeof e.featureKey != "string" || !/^[a-z][a-z0-9_-]{1,63}$/.test(e.featureKey) || typeof e.title != "string" || e.title.trim().length === 0 || e.title.length > 120 || !(
|
|
574
|
+
function re(t) {
|
|
575
|
+
const e = v(t);
|
|
576
|
+
if (typeof e.featureKey != "string" || !/^[a-z][a-z0-9_-]{1,63}$/.test(e.featureKey) || typeof e.title != "string" || e.title.trim().length === 0 || e.title.length > 120 || !(e.policyType === "PUBLIC" || e.policyType === "FOLLOW_OWNER" || e.policyType === "WORK_ENTITLEMENT"))
|
|
608
577
|
throw m();
|
|
609
|
-
const
|
|
610
|
-
if (
|
|
578
|
+
const i = e.price === null ? null : v(e.price);
|
|
579
|
+
if (i !== null && (!Number.isInteger(i.amountCents) || i.amountCents <= 0 || i.currency !== "CNY") || e.policyType === "WORK_ENTITLEMENT" != (i !== null))
|
|
611
580
|
throw m();
|
|
612
581
|
return {
|
|
613
582
|
featureKey: e.featureKey,
|
|
614
583
|
title: e.title,
|
|
615
|
-
policy: { type:
|
|
616
|
-
price:
|
|
584
|
+
policy: { type: e.policyType },
|
|
585
|
+
price: i === null ? null : { amountCents: i.amountCents, currency: "CNY" }
|
|
617
586
|
};
|
|
618
587
|
}
|
|
619
|
-
function
|
|
620
|
-
if (typeof t != "string") throw m();
|
|
621
|
-
try {
|
|
622
|
-
const e = new URL(t).origin;
|
|
623
|
-
if (e !== t) throw m();
|
|
624
|
-
return e;
|
|
625
|
-
} catch (e) {
|
|
626
|
-
throw e instanceof b ? e : m();
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
function j() {
|
|
588
|
+
function oe() {
|
|
630
589
|
const t = crypto.getRandomValues(new Uint8Array(32));
|
|
631
|
-
return
|
|
590
|
+
return ne(t);
|
|
632
591
|
}
|
|
633
|
-
function
|
|
592
|
+
function ne(t) {
|
|
634
593
|
let e = "";
|
|
635
594
|
for (const i of t) e += String.fromCharCode(i);
|
|
636
595
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
637
596
|
}
|
|
638
|
-
function
|
|
597
|
+
function se() {
|
|
639
598
|
return typeof document < "u" && document.documentElement.lang.toLowerCase() === "en-us" ? "en-US" : "zh-CN";
|
|
640
599
|
}
|
|
641
|
-
function
|
|
642
|
-
const e =
|
|
643
|
-
const o = h(
|
|
644
|
-
(await t.session.request({
|
|
645
|
-
method: "POST",
|
|
646
|
-
path: "/v1/public/v1/auth/exchange",
|
|
647
|
-
body: { code: r, codeVerifier: n }
|
|
648
|
-
})).body
|
|
649
|
-
);
|
|
650
|
-
if (typeof o.token != "string" || typeof o.expiresAt != "number")
|
|
651
|
-
throw m();
|
|
652
|
-
const d = re(o.user);
|
|
653
|
-
return t.session.authenticate({ token: o.token, expiresAt: o.expiresAt, user: d }), { authenticated: !0, user: d };
|
|
654
|
-
}, i = () => new b({
|
|
600
|
+
function ce(t) {
|
|
601
|
+
const e = () => new w({
|
|
655
602
|
code: "AUTH_CANCELLED",
|
|
656
603
|
message: "The interactive action was cancelled.",
|
|
657
604
|
retryable: !1
|
|
658
|
-
}),
|
|
605
|
+
}), i = (r, o, l, n, f, b) => {
|
|
659
606
|
if (typeof window > "u")
|
|
660
|
-
throw new
|
|
607
|
+
throw new w({
|
|
661
608
|
code: "CONFIG_INVALID",
|
|
662
609
|
message: "Interactive access requires a browser window.",
|
|
663
610
|
retryable: !1
|
|
664
611
|
});
|
|
665
|
-
let
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
},
|
|
669
|
-
y = g,
|
|
670
|
-
}),
|
|
671
|
-
if (!
|
|
672
|
-
const
|
|
673
|
-
if (!(
|
|
674
|
-
if (
|
|
675
|
-
|
|
612
|
+
let d = !0, y, k;
|
|
613
|
+
const h = () => {
|
|
614
|
+
d && (d = !1, window.removeEventListener("message", s));
|
|
615
|
+
}, O = new Promise((g, p) => {
|
|
616
|
+
y = g, k = p;
|
|
617
|
+
}), s = (g) => {
|
|
618
|
+
if (!d || g.origin !== o || typeof g.data != "object" || g.data === null) return;
|
|
619
|
+
const p = g.data;
|
|
620
|
+
if (!(p.workKey !== t.workKey || p.channel !== l)) {
|
|
621
|
+
if (p.type === `viceme:${n}:ready`) {
|
|
622
|
+
g.source && "postMessage" in g.source && g.source.postMessage(
|
|
623
|
+
{
|
|
624
|
+
type: `viceme:${n}:init`,
|
|
625
|
+
workKey: t.workKey,
|
|
626
|
+
channel: l,
|
|
627
|
+
...f
|
|
628
|
+
},
|
|
629
|
+
o
|
|
630
|
+
);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (p.type === `viceme:${n}:cancelled`) {
|
|
634
|
+
h(), k(e());
|
|
676
635
|
return;
|
|
677
636
|
}
|
|
678
|
-
|
|
637
|
+
p.type === `viceme:${n}:complete` && (h(), b(p).then(y, k));
|
|
679
638
|
}
|
|
680
639
|
};
|
|
681
|
-
return window.addEventListener("message",
|
|
640
|
+
return window.addEventListener("message", s), {
|
|
682
641
|
type: "frame",
|
|
683
642
|
url: r,
|
|
684
|
-
completion:
|
|
643
|
+
completion: O,
|
|
685
644
|
cancel() {
|
|
686
|
-
|
|
645
|
+
h(), y();
|
|
687
646
|
}
|
|
688
647
|
};
|
|
689
|
-
},
|
|
690
|
-
await t.ready()
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
648
|
+
}, a = async () => {
|
|
649
|
+
if (await t.ready(), typeof window > "u")
|
|
650
|
+
throw new w({
|
|
651
|
+
code: "CONFIG_INVALID",
|
|
652
|
+
message: "Interactive access requires a browser window.",
|
|
653
|
+
retryable: !1
|
|
654
|
+
});
|
|
655
|
+
const r = oe(), o = new URL("/sdk/login", t.widgetOrigin);
|
|
656
|
+
o.search = new URLSearchParams({
|
|
657
|
+
workKey: t.workKey,
|
|
658
|
+
channel: r,
|
|
659
|
+
parentOrigin: window.location.origin,
|
|
660
|
+
locale: se()
|
|
661
|
+
}).toString();
|
|
662
|
+
const l = t.session.snapshot?.token;
|
|
663
|
+
if (!l) throw m();
|
|
664
|
+
return i(
|
|
665
|
+
o.toString(),
|
|
666
|
+
t.widgetOrigin,
|
|
667
|
+
r,
|
|
706
668
|
"auth",
|
|
707
|
-
|
|
708
|
-
|
|
669
|
+
{ workSessionToken: l },
|
|
670
|
+
async (n) => {
|
|
671
|
+
if (typeof n.userToken != "string")
|
|
709
672
|
throw m();
|
|
710
|
-
|
|
673
|
+
t.session.authenticate({ userToken: n.userToken, user: ie(n.user) });
|
|
711
674
|
}
|
|
712
675
|
);
|
|
713
|
-
},
|
|
714
|
-
(await t.session.request({ method: "GET", path: "/v1/public/
|
|
715
|
-
)),
|
|
716
|
-
(await t.session.request({ method:
|
|
717
|
-
)),
|
|
676
|
+
}, c = async () => (await t.ready(), P(
|
|
677
|
+
(await t.session.request({ method: "GET", path: "/v1/public/work-sdk/follow" })).body
|
|
678
|
+
)), S = async () => (await t.ready(), P(
|
|
679
|
+
(await t.session.request({ method: "PUT", path: "/v1/public/work-sdk/follow" })).body
|
|
680
|
+
)), u = {
|
|
718
681
|
async getState() {
|
|
719
682
|
await t.ready();
|
|
720
683
|
const r = t.session.snapshot?.user ?? null;
|
|
721
684
|
return { authenticated: r !== null, user: r };
|
|
722
685
|
},
|
|
723
686
|
async signIn() {
|
|
724
|
-
|
|
725
|
-
if (await r({
|
|
687
|
+
if (await (t.presenter ?? x)({
|
|
726
688
|
featureKey: "auth",
|
|
727
689
|
reason: "AUTH_REQUIRED",
|
|
728
690
|
action: "SIGN_IN",
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
await f("PUT");
|
|
732
|
-
})
|
|
733
|
-
}) === "dismissed") throw i();
|
|
691
|
+
perform: a
|
|
692
|
+
}) === "dismissed") throw e();
|
|
734
693
|
return this.getState();
|
|
735
694
|
},
|
|
736
695
|
async signOut() {
|
|
737
696
|
await t.ready(), await t.session.signOut();
|
|
738
697
|
}
|
|
739
|
-
},
|
|
740
|
-
getState:
|
|
741
|
-
follow:
|
|
742
|
-
unfollow: () =>
|
|
743
|
-
|
|
698
|
+
}, A = {
|
|
699
|
+
getState: c,
|
|
700
|
+
follow: S,
|
|
701
|
+
unfollow: async () => {
|
|
702
|
+
throw new w({
|
|
703
|
+
code: "CAPABILITY_DISABLED",
|
|
704
|
+
message: "Unfollow is not exposed by website access.",
|
|
705
|
+
retryable: !1
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}, E = async (r) => {
|
|
744
709
|
await t.ready();
|
|
745
|
-
const
|
|
710
|
+
const o = v(
|
|
746
711
|
(await t.session.request({
|
|
747
712
|
method: "POST",
|
|
748
|
-
path: "/v1/public/
|
|
713
|
+
path: "/v1/public/work-sdk/access/check",
|
|
749
714
|
body: { featureKeys: r }
|
|
750
715
|
})).body
|
|
751
|
-
),
|
|
716
|
+
), l = v(o.decisions);
|
|
752
717
|
return Object.fromEntries(
|
|
753
|
-
Object.entries(
|
|
718
|
+
Object.entries(l).map(([n, f]) => [n, ae(f)])
|
|
754
719
|
);
|
|
755
|
-
},
|
|
720
|
+
}, L = async (r, o = {}) => {
|
|
756
721
|
await t.ready();
|
|
757
|
-
const
|
|
722
|
+
const l = {
|
|
758
723
|
featureKey: r,
|
|
759
|
-
locale:
|
|
760
|
-
|
|
761
|
-
}, c = h(
|
|
724
|
+
locale: o.locale ?? "zh-CN"
|
|
725
|
+
}, n = v(
|
|
762
726
|
(await t.session.request({
|
|
763
727
|
method: "POST",
|
|
764
|
-
path: "/v1/public/
|
|
765
|
-
body:
|
|
728
|
+
path: "/v1/public/work-sdk/checkout",
|
|
729
|
+
body: l
|
|
766
730
|
})).body
|
|
767
731
|
);
|
|
768
|
-
if (typeof
|
|
732
|
+
if (typeof n.checkoutUrl != "string" || typeof n.alreadyOwned != "boolean")
|
|
769
733
|
throw m();
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
734
|
+
try {
|
|
735
|
+
new URL(n.checkoutUrl);
|
|
736
|
+
} catch {
|
|
737
|
+
throw m();
|
|
738
|
+
}
|
|
774
739
|
return {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
740
|
+
checkoutUrl: n.checkoutUrl,
|
|
741
|
+
alreadyOwned: n.alreadyOwned
|
|
742
|
+
};
|
|
743
|
+
}, N = (r, o) => {
|
|
744
|
+
if (r.alreadyOwned) return { type: "completed" };
|
|
745
|
+
if (typeof window > "u")
|
|
746
|
+
throw new w({
|
|
747
|
+
code: "CONFIG_INVALID",
|
|
748
|
+
message: "Hosted checkout requires a browser window.",
|
|
749
|
+
retryable: !1
|
|
750
|
+
});
|
|
751
|
+
const l = window.open(r.checkoutUrl, "_blank", "popup,width=520,height=760");
|
|
752
|
+
if (!l)
|
|
753
|
+
throw new w({
|
|
754
|
+
code: "AUTH_CANCELLED",
|
|
755
|
+
message: "The hosted checkout window was blocked.",
|
|
756
|
+
retryable: !1
|
|
757
|
+
});
|
|
758
|
+
let n = !0, f, b, d;
|
|
759
|
+
const y = new Promise((h, O) => {
|
|
760
|
+
b = h, d = O;
|
|
761
|
+
}), k = async () => {
|
|
762
|
+
if (n)
|
|
763
|
+
try {
|
|
764
|
+
const h = (await E([o]))[o];
|
|
765
|
+
if (!h) throw m();
|
|
766
|
+
if (h.allowed) {
|
|
767
|
+
n = !1, l.close(), b();
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (l.closed) {
|
|
771
|
+
n = !1, d(e());
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
f = setTimeout(() => {
|
|
775
|
+
k();
|
|
776
|
+
}, 1500);
|
|
777
|
+
} catch (h) {
|
|
778
|
+
n = !1, d(h);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
return f = setTimeout(() => {
|
|
782
|
+
k();
|
|
783
|
+
}, 1500), {
|
|
784
|
+
type: "external",
|
|
785
|
+
completion: y,
|
|
786
|
+
cancel() {
|
|
787
|
+
n && (n = !1, f && clearTimeout(f), l.close(), b());
|
|
788
|
+
}
|
|
778
789
|
};
|
|
779
790
|
};
|
|
780
|
-
return { auth:
|
|
791
|
+
return { auth: u, follow: A, access: {
|
|
781
792
|
async getFeatures() {
|
|
782
793
|
await t.ready();
|
|
783
|
-
const r =
|
|
784
|
-
(await t.session.request({
|
|
794
|
+
const r = v(
|
|
795
|
+
(await t.session.request({
|
|
796
|
+
method: "GET",
|
|
797
|
+
path: "/v1/public/work-sdk/access/features"
|
|
798
|
+
})).body
|
|
785
799
|
);
|
|
786
800
|
if (!Array.isArray(r.features) || r.features.length > 100)
|
|
787
801
|
throw m();
|
|
788
|
-
return r.features.map(
|
|
802
|
+
return r.features.map(re);
|
|
789
803
|
},
|
|
790
804
|
async check(r) {
|
|
791
|
-
const
|
|
792
|
-
if (!
|
|
793
|
-
return
|
|
805
|
+
const l = (await E([r]))[r];
|
|
806
|
+
if (!l) throw m();
|
|
807
|
+
return l;
|
|
794
808
|
},
|
|
795
|
-
checkMany:
|
|
809
|
+
checkMany: E,
|
|
796
810
|
async require(r) {
|
|
797
|
-
let
|
|
798
|
-
const
|
|
799
|
-
for (let
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
|
|
811
|
+
let o = await this.check(r);
|
|
812
|
+
const l = t.presenter ?? x;
|
|
813
|
+
for (let n = 0; !o.allowed && o.nextAction && n < 3; n += 1) {
|
|
814
|
+
const f = o.nextAction, b = f === "FOLLOW" ? (await A.getState()).target : void 0, d = f === "CHECKOUT" ? await L(r) : void 0;
|
|
815
|
+
if (d?.alreadyOwned) {
|
|
816
|
+
o = await this.check(r);
|
|
803
817
|
continue;
|
|
804
818
|
}
|
|
805
|
-
|
|
806
|
-
if (await o({
|
|
819
|
+
if (await l({
|
|
807
820
|
featureKey: r,
|
|
808
|
-
reason:
|
|
809
|
-
action:
|
|
810
|
-
...
|
|
811
|
-
perform: async () =>
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}) === "dismissed") return n;
|
|
815
|
-
n = await this.check(r);
|
|
821
|
+
reason: o.reason,
|
|
822
|
+
action: f,
|
|
823
|
+
...b ? { followTarget: b } : {},
|
|
824
|
+
perform: async () => f === "SIGN_IN" ? a() : f === "FOLLOW" ? (await A.follow(), { type: "completed" }) : N(d, r)
|
|
825
|
+
}) === "dismissed") return o;
|
|
826
|
+
o = await this.check(r);
|
|
816
827
|
}
|
|
817
|
-
return
|
|
828
|
+
return o;
|
|
818
829
|
},
|
|
819
830
|
async refresh() {
|
|
820
831
|
await t.ready();
|
|
821
832
|
}
|
|
822
833
|
}, checkout: {
|
|
823
834
|
async open(r) {
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
if (await
|
|
835
|
+
const o = await L(r.featureKey, r);
|
|
836
|
+
if (o.alreadyOwned) return o;
|
|
837
|
+
if (await (t.presenter ?? x)({
|
|
827
838
|
featureKey: r.featureKey,
|
|
828
839
|
reason: "PURCHASE_REQUIRED",
|
|
829
840
|
action: "CHECKOUT",
|
|
830
|
-
perform: async () =>
|
|
831
|
-
|
|
832
|
-
return o = c.result, c.action;
|
|
833
|
-
}
|
|
834
|
-
}) === "dismissed" || !o) throw i();
|
|
841
|
+
perform: async () => N(o, r.featureKey)
|
|
842
|
+
}) === "dismissed") throw e();
|
|
835
843
|
return o;
|
|
836
844
|
}
|
|
837
845
|
} };
|
|
838
846
|
}
|
|
839
|
-
class
|
|
847
|
+
class le extends DOMException {
|
|
840
848
|
constructor() {
|
|
841
849
|
super("ViceMe client destroyed.", "AbortError");
|
|
842
850
|
}
|
|
843
851
|
}
|
|
844
852
|
class he {
|
|
845
|
-
#e = new
|
|
853
|
+
#e = new Q();
|
|
846
854
|
#t;
|
|
847
855
|
#i;
|
|
848
856
|
#a = new AbortController();
|
|
@@ -851,35 +859,36 @@ class he {
|
|
|
851
859
|
access;
|
|
852
860
|
checkout;
|
|
853
861
|
/** Detaches the caller-signal listener; undefined when none was attached. */
|
|
854
|
-
#
|
|
862
|
+
#o;
|
|
855
863
|
constructor(e) {
|
|
856
|
-
this.#i = e.config, this.#t = new
|
|
864
|
+
this.#i = e.config, this.#t = new J({
|
|
857
865
|
workKey: e.config.workKey,
|
|
858
866
|
transport: e.transport,
|
|
859
867
|
signal: this.#a.signal,
|
|
860
868
|
...e.now !== void 0 ? { now: e.now } : {}
|
|
861
869
|
});
|
|
862
|
-
const i =
|
|
870
|
+
const i = ce({
|
|
863
871
|
session: this.#t,
|
|
864
872
|
workKey: e.config.workKey,
|
|
873
|
+
widgetOrigin: W[e.config.region],
|
|
865
874
|
presenter: e.presenter,
|
|
866
|
-
ready: () => this
|
|
875
|
+
ready: () => this.#n()
|
|
867
876
|
});
|
|
868
877
|
this.auth = i.auth, this.access = i.access, this.checkout = i.checkout;
|
|
869
878
|
const a = e.config.signal;
|
|
870
879
|
if (a) {
|
|
871
|
-
const
|
|
880
|
+
const c = () => {
|
|
872
881
|
this.#a.abort(
|
|
873
882
|
a.reason instanceof Error ? a.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
874
883
|
);
|
|
875
884
|
};
|
|
876
|
-
a.aborted ?
|
|
877
|
-
a.removeEventListener("abort",
|
|
885
|
+
a.aborted ? c() : (a.addEventListener("abort", c, { once: !0 }), this.#o = () => {
|
|
886
|
+
a.removeEventListener("abort", c);
|
|
878
887
|
});
|
|
879
888
|
}
|
|
880
889
|
}
|
|
881
890
|
get version() {
|
|
882
|
-
return
|
|
891
|
+
return z;
|
|
883
892
|
}
|
|
884
893
|
get workKey() {
|
|
885
894
|
return this.#i.workKey;
|
|
@@ -892,25 +901,24 @@ class he {
|
|
|
892
901
|
}
|
|
893
902
|
/** Internal: public API major, used by the loader registry namespace. */
|
|
894
903
|
get apiMajor() {
|
|
895
|
-
return
|
|
904
|
+
return H;
|
|
896
905
|
}
|
|
897
906
|
ready() {
|
|
898
|
-
return this.#e.destroyed ? Promise.reject(
|
|
907
|
+
return this.#e.destroyed ? Promise.reject(C()) : (this.#r || (this.#e.transition("READY"), this.#r = Promise.resolve()), this.#r);
|
|
899
908
|
}
|
|
900
|
-
async #
|
|
901
|
-
if (this.#e.destroyed) throw
|
|
902
|
-
this
|
|
909
|
+
async #n() {
|
|
910
|
+
if (this.#e.destroyed) throw C();
|
|
911
|
+
await this.ready();
|
|
903
912
|
try {
|
|
904
|
-
if (await this.#t.establish(), this.#e.destroyed) throw
|
|
905
|
-
this.#e.transition("READY");
|
|
913
|
+
if (await this.#t.establish(), this.#e.destroyed) throw C();
|
|
906
914
|
} catch (e) {
|
|
907
|
-
throw this.#e.destroyed ?
|
|
915
|
+
throw this.#e.destroyed ? C() : (this.#t.invalidate(), e);
|
|
908
916
|
}
|
|
909
917
|
}
|
|
910
918
|
hasCapability(e) {
|
|
911
919
|
if (this.#e.destroyed) return !1;
|
|
912
920
|
const i = this.#t.snapshot?.work.capabilities;
|
|
913
|
-
return
|
|
921
|
+
return e === "danmaku" || e === "tip" || i?.includes(e) === !0;
|
|
914
922
|
}
|
|
915
923
|
/** Names of capabilities enabled for this work (empty before `ready()`). */
|
|
916
924
|
get capabilities() {
|
|
@@ -928,14 +936,14 @@ class he {
|
|
|
928
936
|
return this.#t.snapshot;
|
|
929
937
|
}
|
|
930
938
|
destroy() {
|
|
931
|
-
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#a.abort(new
|
|
939
|
+
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#a.abort(new le()), this.#t.destroy(), this.#e.clearListeners(), this.#r = void 0, this.#o?.(), this.#o = void 0);
|
|
932
940
|
}
|
|
933
941
|
}
|
|
934
942
|
export {
|
|
935
943
|
he as V,
|
|
936
|
-
|
|
944
|
+
Y as a,
|
|
937
945
|
B as i,
|
|
938
|
-
|
|
946
|
+
fe as r,
|
|
939
947
|
me as v
|
|
940
948
|
};
|
|
941
|
-
//# sourceMappingURL=client-
|
|
949
|
+
//# sourceMappingURL=client-Cbldd7F2.js.map
|