@viceme-ai/sdk 0.3.0 → 0.6.1

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