@viceme-ai/sdk 0.1.5 → 0.2.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 +45 -25
- package/dist/bootstrap.min.js +1 -1
- package/dist/bootstrap.min.js.map +1 -1
- package/dist/chunks/version-BbUa2jZV.js +38 -0
- package/dist/chunks/version-BbUa2jZV.js.map +1 -0
- package/dist/core/build-endpoints.d.ts +6 -0
- package/dist/core/build-endpoints.d.ts.map +1 -0
- package/dist/core/client.d.ts +9 -23
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +4 -14
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/lifecycle.d.ts +2 -4
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/danmaku/anchor.d.ts +14 -0
- package/dist/danmaku/anchor.d.ts.map +1 -0
- package/dist/danmaku/index.d.ts +12 -0
- package/dist/danmaku/index.d.ts.map +1 -0
- package/dist/danmaku/mount.d.ts +5 -0
- package/dist/danmaku/mount.d.ts.map +1 -0
- package/dist/danmaku.js +202 -0
- package/dist/danmaku.js.map +1 -0
- package/dist/generated/public-contract.d.ts +68 -56
- package/dist/generated/public-contract.d.ts.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +96 -111
- package/dist/index.js.map +1 -1
- package/dist/loader/attributes.d.ts +1 -1
- package/dist/loader/attributes.d.ts.map +1 -1
- package/dist/loader/auto-loader.d.ts +6 -6
- package/dist/loader/auto-loader.d.ts.map +1 -1
- package/dist/loader/mount-handle.d.ts +2 -2
- package/dist/loader/mount-handle.d.ts.map +1 -1
- package/dist/loader/registry.d.ts +2 -2
- package/dist/manifest.json +27 -25
- package/dist/version.d.ts +1 -1
- package/dist/viceme.min.js +1 -1
- package/dist/viceme.min.js.map +1 -1
- package/package.json +7 -8
- package/dist/chunks/client-CfKmb4Lm.js +0 -275
- package/dist/chunks/client-CfKmb4Lm.js.map +0 -1
- package/dist/session/session.d.ts +0 -54
- package/dist/session/session.d.ts.map +0 -1
- package/dist/testing/test-adapter.d.ts +0 -57
- package/dist/testing/test-adapter.d.ts.map +0 -1
- package/dist/testing.d.ts +0 -9
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -69
- package/dist/testing.js.map +0 -1
- package/dist/transport/transport.d.ts +0 -42
- package/dist/transport/transport.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# @viceme-ai/sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
subpaths for static HTML, browser-native ESM, React/Next.js, and
|
|
5
|
-
Agent-generated sites.
|
|
3
|
+
PUBLIC-only ViceMe browser SDK for the Shop-hosted danmaku overlay.
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
@@ -10,39 +8,61 @@ Agent-generated sites.
|
|
|
10
8
|
pnpm add @viceme-ai/sdk
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
##
|
|
11
|
+
## Static HTML
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script
|
|
15
|
+
defer
|
|
16
|
+
src="https://viceme.cn/viceme-sdk/v1/viceme.min.js"
|
|
17
|
+
data-viceme-work="wrk_public_xxx"
|
|
18
|
+
data-viceme-region="cn"
|
|
19
|
+
data-viceme-features="danmaku"
|
|
20
|
+
data-viceme-target="body"
|
|
21
|
+
data-viceme-theme="auto"
|
|
22
|
+
></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The feature declaration must be exactly `danmaku`.
|
|
26
|
+
|
|
27
|
+
The `viceme.cn/viceme-sdk/v1/*` Shop proxy directly exposes one configured
|
|
28
|
+
exact release, including the loader, manifest, danmaku entry, and hashed
|
|
29
|
+
chunks. It is distinct from the direct S3 `v1/viceme.min.js` alias, whose fixed
|
|
30
|
+
bootstrap reads `-/aliases/v1` before loading an exact-version directory.
|
|
31
|
+
|
|
32
|
+
With CSP, allow the exact regional Shop origin in `script-src`, `connect-src`,
|
|
33
|
+
and `frame-src`, and keep `object-src 'none'`. A nonce with `'strict-dynamic'`
|
|
34
|
+
may authorize dynamic scripts, but `connect-src` and `frame-src` still need the
|
|
35
|
+
exact origin. Do not use `*` or a ViceMe subdomain wildcard.
|
|
36
|
+
|
|
37
|
+
## ESM
|
|
14
38
|
|
|
15
39
|
```ts
|
|
16
40
|
import { createViceMe } from '@viceme-ai/sdk';
|
|
41
|
+
import { mountDanmaku } from '@viceme-ai/sdk/danmaku';
|
|
17
42
|
|
|
18
43
|
const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
|
|
19
44
|
await client.ready();
|
|
20
45
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
46
|
+
const mounted = await mountDanmaku(client, {
|
|
47
|
+
target: document.body,
|
|
48
|
+
theme: 'auto',
|
|
49
|
+
});
|
|
24
50
|
|
|
51
|
+
mounted.destroy();
|
|
25
52
|
client.destroy();
|
|
26
53
|
```
|
|
27
54
|
|
|
28
|
-
|
|
29
|
-
|
|
55
|
+
Run those cleanup calls from the owning component's unmount path or another
|
|
56
|
+
explicit lifecycle boundary, not from `pagehide` (which also covers bfcache).
|
|
30
57
|
|
|
31
|
-
|
|
58
|
+
`createViceMe` is purely local and never contacts Shop. A live client reports
|
|
59
|
+
only the `danmaku` capability. The hosted `/embed/danmaku` iframe uses Shop's
|
|
60
|
+
internal SDK to read and create anonymous messages through
|
|
61
|
+
`/v1/danmaku/messages`.
|
|
32
62
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const client = createTestViceMe({
|
|
37
|
-
workKey: 'wrk_test',
|
|
38
|
-
region: 'cn',
|
|
39
|
-
transport: createMemoryTransport({
|
|
40
|
-
work: { key: 'wrk_test', capabilities: ['fixture'] },
|
|
41
|
-
}),
|
|
42
|
-
});
|
|
43
|
-
await client.ready();
|
|
44
|
-
```
|
|
63
|
+
There is no public SDK Session, Bearer token, auth, follow, access, purchase,
|
|
64
|
+
or checkout surface, and no `@viceme-ai/sdk/testing` subpath.
|
|
45
65
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
66
|
+
The danmaku mount hashes the canonical page URL locally, combines it with a 10%
|
|
67
|
+
scroll bucket, and sends only the opaque anchor to the hosted iframe. Destroying
|
|
68
|
+
the mount removes its nodes, listeners, debounce timer, and location poll.
|
package/dist/bootstrap.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){"use strict";(()=>{const t=document.currentScript;if(!(t instanceof HTMLScriptElement)||!t.src)return;const c=typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?AbortSignal.timeout(8e3):void 0;fetch(new URL("/viceme-sdk/-/aliases/v1",t.src),{credentials:"omit",signal:c}).then(e=>{if(!e.ok)throw new Error(`pointer HTTP ${e.status}`);return e.text()}).then(e=>{const i=e.trim();if(!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(i))throw new Error("invalid pointer");const r=document.createElement("script");for(const n of t.getAttributeNames())n==="src"||n==="integrity"||r.setAttribute(n,t.getAttribute(n)??"");r.src=new URL(`/viceme-sdk/${i}/viceme.min.js`,t.src).href,(document.head??document.documentElement).append(r)}).catch(()=>{document.dispatchEvent(new CustomEvent("viceme:error",{detail:{code:"CONFIG_INVALID",retryable:!1},bubbles:!0,composed:!0}))})})()})();
|
|
1
|
+
(function(){"use strict";(()=>{const t=document.currentScript;if(!(t instanceof HTMLScriptElement)||!t.src)return;const c=typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?AbortSignal.timeout(8e3):void 0;fetch(new URL("/viceme-sdk/-/aliases/v1",t.src),{credentials:"omit",signal:c}).then(e=>{if(!e.ok)throw new Error(`pointer HTTP ${e.status}`);return e.text()}).then(e=>{const i=e.trim();if(!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(i))throw new Error("invalid pointer");const r=document.createElement("script");for(const n of t.getAttributeNames())n==="src"||n==="integrity"||n==="nonce"||r.setAttribute(n,t.getAttribute(n)??"");r.nonce=t.nonce,r.src=new URL(`/viceme-sdk/${i}/viceme.min.js`,t.src).href,(document.head??document.documentElement).append(r)}).catch(()=>{document.dispatchEvent(new CustomEvent("viceme:error",{detail:{code:"CONFIG_INVALID",retryable:!1},bubbles:!0,composed:!0}))})})()})();
|
|
2
2
|
//# sourceMappingURL=bootstrap.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.min.js","sources":["../src/loader/bootstrap.ts"],"sourcesContent":["/**\n * FIXED alias bootstrap — the ONLY object under /viceme-sdk/v1/.\n *\n * Byte-stable for the whole API major (this file must not grow feature\n * logic): it reads the version pointer at /viceme-sdk/-/aliases/v1 and\n * injects the full versioned auto-loader at\n * /viceme-sdk/<version>/viceme.min.js with the same data-viceme-*\n * attributes. The full loader (and every future fix to it) lives in the\n * immutable exact-version directory, so the alias bytes never need to\n * change when releases ship.\n */\n(() => {\n const script = document.currentScript;\n if (!(script instanceof HTMLScriptElement) || !script.src) return;\n\n const signal =\n typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function'\n ? AbortSignal.timeout(8_000)\n : undefined;\n\n fetch(new URL('/viceme-sdk/-/aliases/v1', script.src), {\n credentials: 'omit',\n signal,\n })\n .then((response) => {\n if (!response.ok) throw new Error(`pointer HTTP ${response.status}`);\n return response.text();\n })\n .then((text) => {\n const version = text.trim();\n if (!/^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {\n throw new Error('invalid pointer');\n }\n const loader = document.createElement('script');\n for (const name of script.getAttributeNames()) {\n // The loader gets its own src; integrity pins are not transferable.\n if (name === 'src' || name === 'integrity') continue;\n loader.setAttribute(name, script.getAttribute(name) ?? '');\n }\n loader.src = new URL(`/viceme-sdk/${version}/viceme.min.js`, script.src).href;\n (document.head ?? document.documentElement).append(loader);\n })\n .catch(() => {\n document.dispatchEvent(\n new CustomEvent('viceme:error', {\n detail: { code: 'CONFIG_INVALID', retryable: false },\n bubbles: true,\n composed: true,\n }),\n );\n });\n})();\n"],"names":["script","signal","response","text","version","loader","name"],"mappings":"0BAWC,IAAM,CACL,MAAMA,EAAS,SAAS,cACxB,GAAI,EAAEA,aAAkB,oBAAsB,CAACA,EAAO,IAAK,OAE3D,MAAMC,EACJ,OAAO,YAAgB,KAAe,OAAO,YAAY,SAAY,WACjE,YAAY,QAAQ,GAAK,EACzB,OAEN,MAAM,IAAI,IAAI,2BAA4BD,EAAO,GAAG,EAAG,CACrD,YAAa,OACb,OAAAC,CAAA,CACD,EACE,KAAMC,GAAa,CAClB,GAAI,CAACA,EAAS,GAAI,MAAM,IAAI,MAAM,gBAAgBA,EAAS,MAAM,EAAE,EACnE,OAAOA,EAAS,KAAA,CAClB,CAAC,EACA,KAAMC,GAAS,CACd,MAAMC,EAAUD,EAAK,KAAA,EACrB,GAAI,CAAC,sCAAsC,KAAKC,CAAO,EACrD,MAAM,IAAI,MAAM,iBAAiB,EAEnC,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAC9C,UAAWC,KAAQN,EAAO,oBAEpBM,IAAS,OAASA,IAAS,
|
|
1
|
+
{"version":3,"file":"bootstrap.min.js","sources":["../src/loader/bootstrap.ts"],"sourcesContent":["/**\n * FIXED alias bootstrap — the ONLY object under /viceme-sdk/v1/.\n *\n * Byte-stable for the whole API major (this file must not grow feature\n * logic): it reads the version pointer at /viceme-sdk/-/aliases/v1 and\n * injects the full versioned auto-loader at\n * /viceme-sdk/<version>/viceme.min.js with the same data-viceme-*\n * attributes. The full loader (and every future fix to it) lives in the\n * immutable exact-version directory, so the alias bytes never need to\n * change when releases ship.\n */\n(() => {\n const script = document.currentScript;\n if (!(script instanceof HTMLScriptElement) || !script.src) return;\n\n const signal =\n typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function'\n ? AbortSignal.timeout(8_000)\n : undefined;\n\n fetch(new URL('/viceme-sdk/-/aliases/v1', script.src), {\n credentials: 'omit',\n signal,\n })\n .then((response) => {\n if (!response.ok) throw new Error(`pointer HTTP ${response.status}`);\n return response.text();\n })\n .then((text) => {\n const version = text.trim();\n if (!/^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {\n throw new Error('invalid pointer');\n }\n const loader = document.createElement('script');\n for (const name of script.getAttributeNames()) {\n // The loader gets its own src; integrity pins are not transferable.\n if (name === 'src' || name === 'integrity' || name === 'nonce') continue;\n loader.setAttribute(name, script.getAttribute(name) ?? '');\n }\n loader.nonce = script.nonce;\n loader.src = new URL(`/viceme-sdk/${version}/viceme.min.js`, script.src).href;\n (document.head ?? document.documentElement).append(loader);\n })\n .catch(() => {\n document.dispatchEvent(\n new CustomEvent('viceme:error', {\n detail: { code: 'CONFIG_INVALID', retryable: false },\n bubbles: true,\n composed: true,\n }),\n );\n });\n})();\n"],"names":["script","signal","response","text","version","loader","name"],"mappings":"0BAWC,IAAM,CACL,MAAMA,EAAS,SAAS,cACxB,GAAI,EAAEA,aAAkB,oBAAsB,CAACA,EAAO,IAAK,OAE3D,MAAMC,EACJ,OAAO,YAAgB,KAAe,OAAO,YAAY,SAAY,WACjE,YAAY,QAAQ,GAAK,EACzB,OAEN,MAAM,IAAI,IAAI,2BAA4BD,EAAO,GAAG,EAAG,CACrD,YAAa,OACb,OAAAC,CAAA,CACD,EACE,KAAMC,GAAa,CAClB,GAAI,CAACA,EAAS,GAAI,MAAM,IAAI,MAAM,gBAAgBA,EAAS,MAAM,EAAE,EACnE,OAAOA,EAAS,KAAA,CAClB,CAAC,EACA,KAAMC,GAAS,CACd,MAAMC,EAAUD,EAAK,KAAA,EACrB,GAAI,CAAC,sCAAsC,KAAKC,CAAO,EACrD,MAAM,IAAI,MAAM,iBAAiB,EAEnC,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAC9C,UAAWC,KAAQN,EAAO,oBAEpBM,IAAS,OAASA,IAAS,aAAeA,IAAS,SACvDD,EAAO,aAAaC,EAAMN,EAAO,aAAaM,CAAI,GAAK,EAAE,EAE3DD,EAAO,MAAQL,EAAO,MACtBK,EAAO,IAAM,IAAI,IAAI,eAAeD,CAAO,iBAAkBJ,EAAO,GAAG,EAAE,MACxE,SAAS,MAAQ,SAAS,iBAAiB,OAAOK,CAAM,CAC3D,CAAC,EACA,MAAM,IAAM,CACX,SAAS,cACP,IAAI,YAAY,eAAgB,CAC9B,OAAQ,CAAE,KAAM,iBAAkB,UAAW,EAAA,EAC7C,QAAS,GACT,SAAU,EAAA,CACX,CAAA,CAEL,CAAC,CACL,GAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const s = /* @__PURE__ */ new Set(["INTERNAL_ERROR"]);
|
|
2
|
+
class r extends Error {
|
|
3
|
+
code;
|
|
4
|
+
retryable;
|
|
5
|
+
requestId;
|
|
6
|
+
capability;
|
|
7
|
+
constructor(e) {
|
|
8
|
+
super(e.message), this.name = "ViceMeError", this.code = e.code, this.retryable = e.retryable ?? s.has(e.code), this.requestId = e.requestId, this.capability = e.capability;
|
|
9
|
+
}
|
|
10
|
+
/** Safe, stable-shape serialization for logs and `viceme:error` events. */
|
|
11
|
+
toJSON() {
|
|
12
|
+
const e = { code: this.code, retryable: this.retryable };
|
|
13
|
+
return this.requestId !== void 0 && (e.requestId = this.requestId), this.capability !== void 0 && (e.capability = this.capability), e;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function a(t) {
|
|
17
|
+
return t instanceof r;
|
|
18
|
+
}
|
|
19
|
+
function c(t) {
|
|
20
|
+
return new r({ code: "CONFIG_INVALID", message: t, retryable: !1 });
|
|
21
|
+
}
|
|
22
|
+
function i() {
|
|
23
|
+
return new r({
|
|
24
|
+
code: "CLIENT_DESTROYED",
|
|
25
|
+
message: "ViceMe client has been destroyed.",
|
|
26
|
+
retryable: !1
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const o = "0.2.0", n = 1;
|
|
30
|
+
export {
|
|
31
|
+
n as A,
|
|
32
|
+
o as S,
|
|
33
|
+
r as V,
|
|
34
|
+
i as a,
|
|
35
|
+
c,
|
|
36
|
+
a as i
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=version-BbUa2jZV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-BbUa2jZV.js","sources":["../../src/core/errors.ts","../../src/version.ts"],"sourcesContent":["/**\n * Public error model.\n *\n * Consumers branch on the stable `code` only — never on `message` text.\n * Error payloads must never contain provider responses, tokens, cookies, or\n * internal stack traces; `toJSON()` exposes the safe diagnostic subset.\n */\n\nexport type ViceMeErrorCode =\n 'CONFIG_INVALID' | 'CAPABILITY_DISABLED' | 'CLIENT_DESTROYED' | 'INTERNAL_ERROR';\n\nexport interface ViceMeErrorInit {\n code: ViceMeErrorCode;\n message: string;\n retryable?: boolean;\n /** Server-assigned request id echoed back for support correlation. */\n requestId?: string;\n /** Capability the error belongs to, when scoped to one. */\n capability?: string;\n}\n\nconst RETRYABLE_BY_DEFAULT: ReadonlySet<ViceMeErrorCode> = new Set(['INTERNAL_ERROR']);\n\nexport class ViceMeError extends Error {\n readonly code: ViceMeErrorCode;\n readonly retryable: boolean;\n readonly requestId?: string;\n readonly capability?: string;\n\n constructor(init: ViceMeErrorInit) {\n super(init.message);\n this.name = 'ViceMeError';\n this.code = init.code;\n this.retryable = init.retryable ?? RETRYABLE_BY_DEFAULT.has(init.code);\n this.requestId = init.requestId;\n this.capability = init.capability;\n }\n\n /** Safe, stable-shape serialization for logs and `viceme:error` events. */\n toJSON(): {\n code: ViceMeErrorCode;\n retryable: boolean;\n requestId?: string;\n capability?: string;\n } {\n const json: {\n code: ViceMeErrorCode;\n retryable: boolean;\n requestId?: string;\n capability?: string;\n } = { code: this.code, retryable: this.retryable };\n if (this.requestId !== undefined) json.requestId = this.requestId;\n if (this.capability !== undefined) json.capability = this.capability;\n return json;\n }\n}\n\nexport function isViceMeError(value: unknown): value is ViceMeError {\n return value instanceof ViceMeError;\n}\n\n/** Build a CONFIG_INVALID error with a stable, non-sensitive message. */\nexport function configInvalid(message: string): ViceMeError {\n return new ViceMeError({ code: 'CONFIG_INVALID', message, retryable: false });\n}\n\n/** Build a CLIENT_DESTROYED error for post-destroy calls. */\nexport function clientDestroyed(): ViceMeError {\n return new ViceMeError({\n code: 'CLIENT_DESTROYED',\n message: 'ViceMe client has been destroyed.',\n retryable: false,\n });\n}\n","/**\n * Single source of truth for the SDK runtime version.\n *\n * Kept in sync with `packages/sdk/package.json#version`; a unit test enforces\n * the match so the loader, release manifest, and npm metadata can never drift.\n */\nexport const SDK_VERSION = '0.2.0';\n\n/** Public API major carried by this build (loader namespace `v1`). */\nexport const API_MAJOR = 1;\n"],"names":["RETRYABLE_BY_DEFAULT","ViceMeError","init","json","isViceMeError","value","configInvalid","message","clientDestroyed","SDK_VERSION","API_MAJOR"],"mappings":"AAqBA,MAAMA,IAAqD,oBAAI,IAAI,CAAC,gBAAgB,CAAC;AAE9E,MAAMC,UAAoB,MAAM;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAYC,GAAuB;AACjC,UAAMA,EAAK,OAAO,GAClB,KAAK,OAAO,eACZ,KAAK,OAAOA,EAAK,MACjB,KAAK,YAAYA,EAAK,aAAaF,EAAqB,IAAIE,EAAK,IAAI,GACrE,KAAK,YAAYA,EAAK,WACtB,KAAK,aAAaA,EAAK;AAAA,EACzB;AAAA;AAAA,EAGA,SAKE;AACA,UAAMC,IAKF,EAAE,MAAM,KAAK,MAAM,WAAW,KAAK,UAAA;AACvC,WAAI,KAAK,cAAc,WAAWA,EAAK,YAAY,KAAK,YACpD,KAAK,eAAe,WAAWA,EAAK,aAAa,KAAK,aACnDA;AAAA,EACT;AACF;AAEO,SAASC,EAAcC,GAAsC;AAClE,SAAOA,aAAiBJ;AAC1B;AAGO,SAASK,EAAcC,GAA8B;AAC1D,SAAO,IAAIN,EAAY,EAAE,MAAM,kBAAkB,SAAAM,GAAS,WAAW,IAAO;AAC9E;AAGO,SAASC,IAA+B;AAC7C,SAAO,IAAIP,EAAY;AAAA,IACrB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,WAAW;AAAA,EAAA,CACZ;AACH;ACnEO,MAAMQ,IAAc,SAGdC,IAAY;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-endpoints.d.ts","sourceRoot":"","sources":["../../src/core/build-endpoints.ts"],"names":[],"mappings":"AAGA,kEAAkE;AAClE,eAAO,MAAM,oBAAoB;;;CASvB,CAAC"}
|
package/dist/core/client.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Local ViceMe client for the public hosted danmaku capability.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* idempotent per instance (shares one promise), `destroy()` is idempotent and
|
|
7
|
-
* synchronously cancels requests and subscriptions; every business method on a
|
|
8
|
-
* destroyed client fails with `CLIENT_DESTROYED`.
|
|
4
|
+
* Initialization performs no network request. The static loader owns release
|
|
5
|
+
* manifest/chunk loading, while the hosted iframe owns Shop API calls.
|
|
9
6
|
*/
|
|
10
7
|
import { type ViceMeClientState } from './lifecycle.ts';
|
|
11
8
|
import type { ViceMeConfig, ViceMeRegion } from './config.ts';
|
|
12
|
-
|
|
9
|
+
declare const MARK_DEGRADED: unique symbol;
|
|
13
10
|
export interface ViceMeClient {
|
|
14
|
-
readonly version: string;
|
|
15
11
|
readonly workKey: string;
|
|
16
12
|
readonly region: ViceMeRegion;
|
|
17
13
|
readonly state: ViceMeClientState;
|
|
@@ -24,32 +20,22 @@ export interface ViceMeMountedInstance {
|
|
|
24
20
|
readonly capability: string;
|
|
25
21
|
destroy(): void;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
transport: Transport;
|
|
30
|
-
/** Injectable clock (testing only). */
|
|
31
|
-
now?: () => number;
|
|
32
|
-
}
|
|
23
|
+
/** Internal loader hook; not part of the client object's string-keyed surface. */
|
|
24
|
+
export declare function markClientDegraded(client: ViceMeClient): void;
|
|
33
25
|
export declare class ViceMeClientImpl implements ViceMeClient {
|
|
34
26
|
#private;
|
|
35
|
-
constructor(
|
|
36
|
-
get version(): string;
|
|
27
|
+
constructor(config: ViceMeConfig);
|
|
37
28
|
get workKey(): string;
|
|
38
29
|
get region(): ViceMeRegion;
|
|
39
30
|
get state(): ViceMeClientState;
|
|
40
|
-
/** Internal: public API major, used by the loader registry namespace. */
|
|
41
|
-
get apiMajor(): number;
|
|
42
31
|
ready(): Promise<void>;
|
|
43
32
|
hasCapability(name: string): boolean;
|
|
44
|
-
/** Names of capabilities enabled for this work (empty before `ready()`). */
|
|
45
|
-
get capabilities(): readonly string[];
|
|
46
33
|
/**
|
|
47
34
|
* Internal: mark one capability unavailable without taking down the client
|
|
48
35
|
* (loader uses this when a feature chunk fails after the core is READY).
|
|
49
36
|
*/
|
|
50
|
-
|
|
51
|
-
/** Internal: session snapshot access for capability modules. */
|
|
52
|
-
get sessionSnapshot(): import("../session/session.ts").WorkSessionSnapshot | undefined;
|
|
37
|
+
[MARK_DEGRADED](): void;
|
|
53
38
|
destroy(): void;
|
|
54
39
|
}
|
|
40
|
+
export {};
|
|
55
41
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9D,QAAA,MAAM,aAAa,eAAsC,CAAC;AAM1D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACrC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAI7D;AAED,qBAAa,gBAAiB,YAAW,YAAY;;gBAKvC,MAAM,EAAE,YAAY;IAIhC,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED,IAAI,KAAK,IAAI,iBAAiB,CAE7B;IAED,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC;;;OAGG;IACH,CAAC,aAAa,CAAC,IAAI,IAAI;IAIvB,OAAO,IAAI,IAAI;CAMhB"}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public client configuration.
|
|
3
3
|
*
|
|
4
|
-
* Production `createViceMe()` accepts exactly `workKey
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* never bake temporary or internal endpoints into user projects.
|
|
4
|
+
* Production `createViceMe()` accepts exactly `workKey` and `region`.
|
|
5
|
+
* Endpoints, credentials, access policy, and provider state are not client
|
|
6
|
+
* configuration: the hosted Shop runtime owns those concerns.
|
|
8
7
|
*/
|
|
9
8
|
export type ViceMeRegion = 'cn' | 'global';
|
|
10
9
|
export interface ViceMeConfig {
|
|
11
10
|
/** Public opaque work key (`wrk_…`). Locates a Work; it is not a secret. */
|
|
12
11
|
workKey: string;
|
|
13
|
-
/**
|
|
12
|
+
/** Selects the hosted Shop region. */
|
|
14
13
|
region: ViceMeRegion;
|
|
15
|
-
/** Optional abort signal owned by the host page. */
|
|
16
|
-
signal?: AbortSignal;
|
|
17
14
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Public API origins per region. These are the only production endpoints the
|
|
20
|
-
* SDK may contact; B1 confirms final hostnames and any change happens here in
|
|
21
|
-
* one place (never via a public `apiBaseUrl` option).
|
|
22
|
-
*/
|
|
23
|
-
export declare const PUBLIC_API_BASE_URLS: Readonly<Record<ViceMeRegion, string>>;
|
|
24
|
-
export declare function resolveApiBaseUrl(region: ViceMeRegion): string;
|
|
25
15
|
export declare function isValidWorkKey(value: unknown): value is string;
|
|
26
16
|
export declare function isValidRegion(value: unknown): value is ViceMeRegion;
|
|
27
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,QAAQ,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,MAAM,EAAE,YAAY,CAAC;CACtB;AAID,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEnE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAsBjE"}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Error payloads must never contain provider responses, tokens, cookies, or
|
|
6
6
|
* internal stack traces; `toJSON()` exposes the safe diagnostic subset.
|
|
7
7
|
*/
|
|
8
|
-
export type ViceMeErrorCode = 'CONFIG_INVALID' | '
|
|
8
|
+
export type ViceMeErrorCode = 'CONFIG_INVALID' | 'CAPABILITY_DISABLED' | 'CLIENT_DESTROYED' | 'INTERNAL_ERROR';
|
|
9
9
|
export interface ViceMeErrorInit {
|
|
10
10
|
code: ViceMeErrorCode;
|
|
11
11
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,eAAe,GACzB,gBAAgB,GAAG,qBAAqB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEnF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,eAAe;IASjC,2EAA2E;IAC3E,MAAM,IAAI;QACR,IAAI,EAAE,eAAe,CAAC;QACtB,SAAS,EAAE,OAAO,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CAWF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAE1D;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,IAAI,WAAW,CAM7C"}
|
package/dist/core/lifecycle.d.ts
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
* Client lifecycle state machine.
|
|
3
3
|
*
|
|
4
4
|
* ```text
|
|
5
|
-
* CREATED ->
|
|
6
|
-
* INITIALIZING -> FAILED (retryable: FAILED -> INITIALIZING)
|
|
5
|
+
* CREATED -> READY -> DESTROYED
|
|
7
6
|
* READY -> DEGRADED (single capability unavailable; host page keeps working)
|
|
8
|
-
* DEGRADED -> READY (when all capabilities recover is a B1+ concern)
|
|
9
7
|
* ```
|
|
10
8
|
*
|
|
11
9
|
* State is exposed read-only; consumers can never assign it directly.
|
|
12
10
|
*/
|
|
13
|
-
export type ViceMeClientState = 'CREATED' | '
|
|
11
|
+
export type ViceMeClientState = 'CREATED' | 'READY' | 'DEGRADED' | 'DESTROYED';
|
|
14
12
|
export type LifecycleListener = (state: ViceMeClientState) => void;
|
|
15
13
|
export declare class Lifecycle {
|
|
16
14
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/core/lifecycle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/core/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAC;AAS/E,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEnE,qBAAa,SAAS;;IAIpB,IAAI,KAAK,IAAI,iBAAiB,CAE7B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAazC,4EAA4E;IAC5E,WAAW,IAAI,IAAI;IAInB,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAOlD,cAAc,IAAI,IAAI;CAGvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DanmakuPageAnchor {
|
|
2
|
+
/** Stable page-and-position key sent to the hosted danmaku runtime. */
|
|
3
|
+
anchorKey: string;
|
|
4
|
+
/** Human-readable 10% scroll bucket, useful for diagnostics. */
|
|
5
|
+
scrollBucket: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Build a stable page-position anchor without exposing the page URL.
|
|
9
|
+
*
|
|
10
|
+
* Canonical URLs and SPA hash routes participate in the local hash. Only the
|
|
11
|
+
* resulting opaque key leaves the host page.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readDanmakuPageAnchor(windowObject?: Window, documentObject?: Document): DanmakuPageAnchor;
|
|
14
|
+
//# sourceMappingURL=anchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../src/danmaku/anchor.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,GAAE,MAAe,EAC7B,cAAc,GAAE,QAAmB,GAClC,iBAAiB,CAOnB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ViceMeClient } from '../core/client.ts';
|
|
2
|
+
export interface DanmakuMountOptions {
|
|
3
|
+
target: Element;
|
|
4
|
+
theme: 'light' | 'dark' | 'auto';
|
|
5
|
+
}
|
|
6
|
+
export interface DanmakuMountHandle {
|
|
7
|
+
readonly capability: 'danmaku';
|
|
8
|
+
destroy(): void;
|
|
9
|
+
}
|
|
10
|
+
/** Explicit ESM/npm entry point; the CDN loader calls the same mount function. */
|
|
11
|
+
export declare function mountDanmaku(client: ViceMeClient, options: DanmakuMountOptions): Promise<DanmakuMountHandle>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/danmaku/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,OAAO,IAAI,IAAI,CAAC;CACjB;AAID,kFAAkF;AAClF,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CA4B7B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ViceMeClient } from '../core/client.ts';
|
|
2
|
+
import type { CapabilityMountHandle, CapabilityMountOptions } from '../loader/mount-handle.ts';
|
|
3
|
+
export declare const FRAME_READY_TIMEOUT_MS = 8000;
|
|
4
|
+
export declare function mount(client: ViceMeClient, options: CapabilityMountOptions): Promise<CapabilityMountHandle>;
|
|
5
|
+
//# sourceMappingURL=mount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/danmaku/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAqB/F,eAAO,MAAM,sBAAsB,OAAQ,CAAC;AAE5C,wBAAsB,KAAK,CACzB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAiUhC"}
|
package/dist/danmaku.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { V as H, S as j } from "./chunks/version-BbUa2jZV.js";
|
|
2
|
+
const ee = {
|
|
3
|
+
cn: "https://viceme.cn",
|
|
4
|
+
global: "https://viceme.ai"
|
|
5
|
+
};
|
|
6
|
+
function G(n = window, a = document) {
|
|
7
|
+
const t = te(n, a), e = ae(n, a);
|
|
8
|
+
return {
|
|
9
|
+
anchorKey: `page:${ne(t)}:scroll:${e}`,
|
|
10
|
+
scrollBucket: e
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function te(n, a) {
|
|
14
|
+
const t = a.querySelector('link[rel="canonical"][href]'), e = t?.href || n.location.href;
|
|
15
|
+
try {
|
|
16
|
+
const i = new URL(e, n.location.href);
|
|
17
|
+
return i.username = "", i.password = "", t && !i.hash && n.location.hash && (i.hash = n.location.hash), i.toString();
|
|
18
|
+
} catch {
|
|
19
|
+
return n.location.href;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function ae(n, a) {
|
|
23
|
+
const t = a.documentElement, e = a.body, i = n.scrollY || n.pageYOffset || t.scrollTop || e?.scrollTop || 0, m = Math.max(
|
|
24
|
+
t.scrollHeight,
|
|
25
|
+
t.offsetHeight,
|
|
26
|
+
t.clientHeight,
|
|
27
|
+
e?.scrollHeight ?? 0,
|
|
28
|
+
e?.offsetHeight ?? 0
|
|
29
|
+
), p = Math.max(0, m - n.innerHeight);
|
|
30
|
+
if (p <= 1) return "0-100";
|
|
31
|
+
const w = Math.max(0, Math.min(99, i / p * 100)), y = Math.min(90, Math.floor(w / 10) * 10);
|
|
32
|
+
return `${y}-${y + 10}`;
|
|
33
|
+
}
|
|
34
|
+
function ne(n) {
|
|
35
|
+
let a = 3735928559 ^ n.length, t = 1103547991 ^ n.length;
|
|
36
|
+
for (let e = 0; e < n.length; e += 1) {
|
|
37
|
+
const i = n.charCodeAt(e);
|
|
38
|
+
a = Math.imul(a ^ i, 2654435761), t = Math.imul(t ^ i, 1597334677);
|
|
39
|
+
}
|
|
40
|
+
return a = Math.imul(a ^ a >>> 16, 2246822507), a ^= Math.imul(t ^ t >>> 13, 3266489909), t = Math.imul(t ^ t >>> 16, 2246822507), t ^= Math.imul(a ^ a >>> 13, 3266489909), ((t >>> 0).toString(36).padStart(7, "0") + (a >>> 0).toString(36).padStart(7, "0")).slice(0, 16);
|
|
41
|
+
}
|
|
42
|
+
const C = 32, oe = 56, re = 360, L = 480, se = 120, ie = 1e3, Y = 8e3;
|
|
43
|
+
async function le(n, a) {
|
|
44
|
+
if (await n.ready(), !n.hasCapability("danmaku"))
|
|
45
|
+
throw new H({
|
|
46
|
+
code: "CAPABILITY_DISABLED",
|
|
47
|
+
message: "Danmaku is not available in this SDK build.",
|
|
48
|
+
retryable: !1,
|
|
49
|
+
capability: "danmaku"
|
|
50
|
+
});
|
|
51
|
+
const t = a.target.ownerDocument, e = t.defaultView;
|
|
52
|
+
if (!e)
|
|
53
|
+
throw new H({
|
|
54
|
+
code: "CONFIG_INVALID",
|
|
55
|
+
message: "Danmaku requires a browser document.",
|
|
56
|
+
retryable: !1,
|
|
57
|
+
capability: "danmaku"
|
|
58
|
+
});
|
|
59
|
+
const i = ee[n.region];
|
|
60
|
+
let m = G(e, t);
|
|
61
|
+
const p = t.documentElement.lang.trim() || e.navigator.language || "en";
|
|
62
|
+
let w = !1, y, b, u, A = !1, P = 0, S = "", M = !1;
|
|
63
|
+
const I = /* @__PURE__ */ new WeakSet(), x = /* @__PURE__ */ new Set(), h = t.createElement("div");
|
|
64
|
+
h.dataset.vicemeDanmaku = "mounted", h.style.all = "initial", h.style.position = "fixed", h.style.inset = "0", h.style.width = "100%", h.style.height = "100%", h.style.pointerEvents = "none", h.style.zIndex = "2147483000", h.style.contain = "layout style size";
|
|
65
|
+
const Z = h.attachShadow({ mode: "open" }), g = t.createElement("div");
|
|
66
|
+
g.style.boxSizing = "border-box", g.style.position = "fixed", g.style.inset = "0", g.style.width = "100%", g.style.height = "100%", g.style.pointerEvents = "none", Z.append(g);
|
|
67
|
+
const R = (o) => {
|
|
68
|
+
const l = new URL("/embed/danmaku", i);
|
|
69
|
+
return l.searchParams.set("mode", o), l.searchParams.set("workKey", n.workKey), l.searchParams.set("theme", a.theme), l.searchParams.set("locale", p), l.searchParams.set("sdk", j), l.searchParams.set("anchorKey", m.anchorKey), l;
|
|
70
|
+
}, _ = (o, l, k) => {
|
|
71
|
+
const s = t.createElement("iframe");
|
|
72
|
+
return s.title = l, s.src = k, s.loading = "eager", s.referrerPolicy = "no-referrer", s.setAttribute("allowtransparency", "true"), s.setAttribute(
|
|
73
|
+
"sandbox",
|
|
74
|
+
"allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
|
|
75
|
+
), s.dataset.mode = o, s.style.boxSizing = "border-box", s.style.colorScheme = "normal", s.style.position = "fixed", s.style.margin = "0", s.style.border = "0", s.style.background = "transparent", s.style.width = "100%", s.style.zIndex = "2147483000", s;
|
|
76
|
+
}, f = _("stage", "ViceMe Danmaku", R("stage").toString());
|
|
77
|
+
f.setAttribute("aria-hidden", "true"), f.style.inset = "0", f.style.height = "100%", f.style.pointerEvents = "none";
|
|
78
|
+
const d = _(
|
|
79
|
+
"controls",
|
|
80
|
+
"ViceMe Danmaku controls",
|
|
81
|
+
R("controls").toString()
|
|
82
|
+
);
|
|
83
|
+
d.style.left = "50%", d.style.bottom = "env(safe-area-inset-bottom, 0px)", d.style.maxWidth = `${L}px`, d.style.transform = "translateX(-50%)";
|
|
84
|
+
let W = L, O = oe;
|
|
85
|
+
const D = () => {
|
|
86
|
+
const o = Math.max(
|
|
87
|
+
C,
|
|
88
|
+
Math.floor(e.innerWidth || L)
|
|
89
|
+
);
|
|
90
|
+
d.style.width = `${Math.min(W, o)}px`, d.style.height = `${O}px`;
|
|
91
|
+
};
|
|
92
|
+
D(), d.style.pointerEvents = "none";
|
|
93
|
+
const r = _("modal", "ViceMe Danmaku dialog", "about:blank");
|
|
94
|
+
r.dataset.src = R("modal").toString(), r.style.inset = "0", r.style.height = "100%", r.style.display = "none", r.style.pointerEvents = "none", g.append(f, d, r);
|
|
95
|
+
const T = (o) => {
|
|
96
|
+
I.has(o) && o.contentWindow?.postMessage(
|
|
97
|
+
{
|
|
98
|
+
source: "viceme-danmaku",
|
|
99
|
+
action: "anchor-change",
|
|
100
|
+
anchorKey: m.anchorKey
|
|
101
|
+
},
|
|
102
|
+
i
|
|
103
|
+
);
|
|
104
|
+
}, K = () => {
|
|
105
|
+
T(f), T(d), r.getAttribute("src") !== "about:blank" && T(r);
|
|
106
|
+
}, U = () => {
|
|
107
|
+
if (w) return m;
|
|
108
|
+
const o = G(e, t);
|
|
109
|
+
return o.anchorKey !== m.anchorKey && (m = o, K()), m;
|
|
110
|
+
}, v = () => {
|
|
111
|
+
y !== void 0 && e.clearTimeout(y), y = e.setTimeout(U, se);
|
|
112
|
+
}, z = () => {
|
|
113
|
+
D(), v();
|
|
114
|
+
}, E = (o) => {
|
|
115
|
+
const l = o.currentTarget;
|
|
116
|
+
l.getAttribute("src") !== "about:blank" && (I.add(l), T(l));
|
|
117
|
+
};
|
|
118
|
+
f.addEventListener("load", E), d.addEventListener("load", E), r.addEventListener("load", E);
|
|
119
|
+
const F = (o = !1) => {
|
|
120
|
+
u !== void 0 && (e.clearTimeout(u), u = void 0), r.style.display = "none", r.style.pointerEvents = "none", o && (S = "", M = !1, I.delete(r), r.src = "about:blank");
|
|
121
|
+
};
|
|
122
|
+
let V;
|
|
123
|
+
const J = new Promise((o, l) => {
|
|
124
|
+
V = o, b = e.setTimeout(() => {
|
|
125
|
+
l(
|
|
126
|
+
new H({
|
|
127
|
+
code: "INTERNAL_ERROR",
|
|
128
|
+
message: "Hosted danmaku frames did not become ready in time.",
|
|
129
|
+
retryable: !0,
|
|
130
|
+
capability: "danmaku"
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}, Y);
|
|
134
|
+
}), B = (o) => {
|
|
135
|
+
if (o.origin !== i) return;
|
|
136
|
+
const l = o.source === f.contentWindow, k = o.source === d.contentWindow, s = o.source === r.contentWindow;
|
|
137
|
+
if (!l && !k && !s) return;
|
|
138
|
+
const c = o.data;
|
|
139
|
+
if (!c || c.source !== "viceme-danmaku") return;
|
|
140
|
+
const N = s ? "modal" : l ? "stage" : "controls";
|
|
141
|
+
if (c.action === "frame-ready") {
|
|
142
|
+
if (c.mode !== N) return;
|
|
143
|
+
if (N === "modal") {
|
|
144
|
+
if (c.frameToken !== S) return;
|
|
145
|
+
M = !0, u !== void 0 && (e.clearTimeout(u), u = void 0), r.style.display === "block" && (r.style.pointerEvents = "auto");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
x.add(N), x.has("stage") && x.has("controls") && !A && (A = !0, b !== void 0 && (e.clearTimeout(b), b = void 0), d.style.pointerEvents = "auto", V?.());
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (c.action === "resize-controls" && k) {
|
|
152
|
+
if (typeof c.width != "number" || !Number.isInteger(c.width) || c.width < C || c.width > L || typeof c.height != "number" || !Number.isInteger(c.height) || c.height < C || c.height > re)
|
|
153
|
+
return;
|
|
154
|
+
W = c.width, O = c.height, D();
|
|
155
|
+
}
|
|
156
|
+
if (c.action === "request-anchor" && T(s ? r : l ? f : d), c.action === "open-modal" && k) {
|
|
157
|
+
if (!A) return;
|
|
158
|
+
if (r.getAttribute("src") === "about:blank") {
|
|
159
|
+
P += 1, S = String(P);
|
|
160
|
+
const q = new URL(r.dataset.src ?? "about:blank");
|
|
161
|
+
q.searchParams.set("frameToken", S), r.src = q.toString();
|
|
162
|
+
}
|
|
163
|
+
r.style.display = "block", r.style.pointerEvents = M ? "auto" : "none", M || (u !== void 0 && e.clearTimeout(u), u = e.setTimeout(() => F(!0), Y));
|
|
164
|
+
}
|
|
165
|
+
c.action === "close-modal" && (s || k) && F(!M);
|
|
166
|
+
}, Q = e.setInterval(U, ie), $ = () => {
|
|
167
|
+
w || (w = !0, y !== void 0 && e.clearTimeout(y), b !== void 0 && e.clearTimeout(b), u !== void 0 && e.clearTimeout(u), e.clearInterval(Q), e.removeEventListener("message", B), e.removeEventListener("scroll", v), e.removeEventListener("resize", z), e.removeEventListener("popstate", v), e.removeEventListener("hashchange", v), f.removeEventListener("load", E), d.removeEventListener("load", E), r.removeEventListener("load", E), h.remove());
|
|
168
|
+
};
|
|
169
|
+
e.addEventListener("message", B), e.addEventListener("scroll", v, { passive: !0 }), e.addEventListener("resize", z), e.addEventListener("popstate", v), e.addEventListener("hashchange", v);
|
|
170
|
+
try {
|
|
171
|
+
a.target.appendChild(h), K(), await J;
|
|
172
|
+
} catch (o) {
|
|
173
|
+
throw $(), o;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
capability: "danmaku",
|
|
177
|
+
destroy: $
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const X = /* @__PURE__ */ new WeakMap();
|
|
181
|
+
function de(n, a) {
|
|
182
|
+
let t = X.get(n);
|
|
183
|
+
t || (t = /* @__PURE__ */ new WeakMap(), X.set(n, t));
|
|
184
|
+
const e = t.get(a.target);
|
|
185
|
+
if (e) return e;
|
|
186
|
+
const i = le(n, a).then((m) => {
|
|
187
|
+
let p = !1;
|
|
188
|
+
return {
|
|
189
|
+
capability: "danmaku",
|
|
190
|
+
destroy() {
|
|
191
|
+
p || (p = !0, t.get(a.target) === i && t.delete(a.target), m.destroy());
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}).catch((m) => {
|
|
195
|
+
throw t.get(a.target) === i && t.delete(a.target), m;
|
|
196
|
+
});
|
|
197
|
+
return t.set(a.target, i), i;
|
|
198
|
+
}
|
|
199
|
+
export {
|
|
200
|
+
de as mountDanmaku
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=danmaku.js.map
|