@firetable/project-xiaochun 0.1.13 → 0.1.15
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-CN.md +144 -18
- package/README.md +144 -18
- package/dist/avatar-element.d.ts +23 -6
- package/dist/chunks/{chunk-UB2HFUBS.js → chunk-KKRZ3SUD.js} +50 -2
- package/dist/chunks/chunk-KKRZ3SUD.js.map +7 -0
- package/dist/chunks/chunk-KQSKHPVF.js +957 -0
- package/dist/chunks/chunk-KQSKHPVF.js.map +7 -0
- package/dist/chunks/{chunk-NKR4JG3C.js → chunk-T6EHFEEZ.js} +83 -9
- package/dist/chunks/chunk-T6EHFEEZ.js.map +7 -0
- package/dist/client.d.ts +134 -6
- package/dist/element.cjs +572 -71
- package/dist/element.cjs.map +4 -4
- package/dist/element.js +4 -4
- package/dist/gesture-box.d.ts +72 -0
- package/dist/index.cjs +599 -71
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/loader.global.js +2 -2
- package/dist/loader.global.js.map +4 -4
- package/dist/protocol.cjs +49 -1
- package/dist/protocol.cjs.map +2 -2
- package/dist/protocol.d.ts +180 -9
- package/dist/protocol.js +20 -2
- package/dist/react.cjs +540 -77
- package/dist/react.cjs.map +4 -4
- package/dist/react.d.ts +17 -1
- package/dist/react.js +50 -15
- package/dist/react.js.map +2 -2
- package/package.json +5 -3
- package/dist/chunks/chunk-NKR4JG3C.js.map +0 -7
- package/dist/chunks/chunk-UB2HFUBS.js.map +0 -7
- package/dist/chunks/chunk-XE2YKXRA.js +0 -544
- package/dist/chunks/chunk-XE2YKXRA.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createXiaochun } from './client';
|
|
2
|
-
export type { XiaochunOptions, XiaochunInstance, XiaochunEvents, XiaochunError, XiaochunErrorCode, XiaochunPosition, XiaochunLazy, XiaochunAudioOptions, XiaochunAudioSource, XiaochunAudioStream, } from './client';
|
|
2
|
+
export type { XiaochunOptions, XiaochunInstance, XiaochunEvents, XiaochunError, XiaochunErrorCode, XiaochunPosition, XiaochunLazy, XiaochunBoxEvent, XiaochunResizeLimits, XiaochunAudioOptions, XiaochunAudioSource, XiaochunAudioStream, } from './client';
|
|
3
3
|
export { defineXiaochunElement, XIAOCHUN_ELEMENT_TAG } from './avatar-element';
|
|
4
4
|
export type { XiaochunAvatarElement } from './avatar-element';
|
|
5
5
|
export * from './protocol';
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
/*! @firetable/project-xiaochun v0.1.
|
|
1
|
+
/*! @firetable/project-xiaochun v0.1.15 | MIT | https://github.com/FireTable/project-xiaochun */
|
|
2
2
|
import {
|
|
3
3
|
XIAOCHUN_ELEMENT_TAG,
|
|
4
4
|
defineXiaochunElement
|
|
5
|
-
} from "./chunks/chunk-
|
|
5
|
+
} from "./chunks/chunk-T6EHFEEZ.js";
|
|
6
6
|
import {
|
|
7
7
|
createXiaochun
|
|
8
|
-
} from "./chunks/chunk-
|
|
8
|
+
} from "./chunks/chunk-KQSKHPVF.js";
|
|
9
9
|
import {
|
|
10
10
|
XC_DEFAULT_ORIGIN,
|
|
11
11
|
XC_DEFAULT_SRC,
|
|
12
12
|
XC_FRAME_TO_HOST,
|
|
13
13
|
XC_HOST_TO_FRAME,
|
|
14
|
+
XC_ID_RE,
|
|
14
15
|
XC_IMPLEMENTED_COMMANDS,
|
|
15
16
|
XC_PROTOCOL_MAPPING,
|
|
16
17
|
XC_PROTOCOL_VERSION,
|
|
18
|
+
XC_UI_LEGACY_PARTS,
|
|
19
|
+
XC_UI_PARTS,
|
|
17
20
|
XC_UNSUPPORTED_COMMANDS,
|
|
21
|
+
XC_WINDOW_CORNER_RADIUS,
|
|
18
22
|
isXcEnvelope,
|
|
23
|
+
isXcId,
|
|
19
24
|
normalizeOrigin,
|
|
25
|
+
normalizeXcUiOption,
|
|
26
|
+
parseXcUiList,
|
|
27
|
+
parseXcUiParam,
|
|
28
|
+
xcHasOwn,
|
|
20
29
|
xcMessage
|
|
21
|
-
} from "./chunks/chunk-
|
|
30
|
+
} from "./chunks/chunk-KKRZ3SUD.js";
|
|
22
31
|
|
|
23
32
|
// src/protocol-url.ts
|
|
24
33
|
var XIAOCHUN_PROTOCOL_SCHEME = "xiaochun";
|
|
@@ -57,18 +66,27 @@ export {
|
|
|
57
66
|
XC_DEFAULT_SRC,
|
|
58
67
|
XC_FRAME_TO_HOST,
|
|
59
68
|
XC_HOST_TO_FRAME,
|
|
69
|
+
XC_ID_RE,
|
|
60
70
|
XC_IMPLEMENTED_COMMANDS,
|
|
61
71
|
XC_PROTOCOL_MAPPING,
|
|
62
72
|
XC_PROTOCOL_VERSION,
|
|
73
|
+
XC_UI_LEGACY_PARTS,
|
|
74
|
+
XC_UI_PARTS,
|
|
63
75
|
XC_UNSUPPORTED_COMMANDS,
|
|
76
|
+
XC_WINDOW_CORNER_RADIUS,
|
|
64
77
|
XIAOCHUN_ELEMENT_TAG,
|
|
65
78
|
XIAOCHUN_PROTOCOL_SCHEME,
|
|
66
79
|
createXiaochun,
|
|
67
80
|
defineXiaochunElement,
|
|
68
81
|
isXcEnvelope,
|
|
82
|
+
isXcId,
|
|
69
83
|
normalizeOrigin,
|
|
84
|
+
normalizeXcUiOption,
|
|
70
85
|
parseProtocolUrl,
|
|
86
|
+
parseXcUiList,
|
|
87
|
+
parseXcUiParam,
|
|
71
88
|
toProtocolUrl,
|
|
89
|
+
xcHasOwn,
|
|
72
90
|
xcMessage
|
|
73
91
|
};
|
|
74
92
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/protocol-url.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * protocol-url.ts \u2014 `xiaochun://` OS \u7EA7 deep link \u4E0E `xc.*` postMessage \u7684\u5BF9\u7167\u5DE5\u5177\u3002\n *\n * \u4E24\u8005\u662F\u300C\u540C\u4E00\u8BED\u4E49\u7684\u4E24\u4E2A\u4F20\u8F93\u5C42\u300D:\n * - xiaochun:// : \u53EA\u5728 Tauri \u684C\u9762\u58F3\u91CC\u7531 OS \u5206\u53D1 (open \"xiaochun://speak?text=\u2026\"), iframe / \u6D4F\u89C8\u5668\u91CC\u7684 /embed \u4E0D\u4F1A\u54CD\u5E94;\n * - xc.* : iframe \u4E0E\u5BBF\u4E3B\u9875\u4E4B\u95F4\u7684 postMessage, \u53EA\u5728 /embed \u91CC\u751F\u6548\u3002\n * \u4E24\u8FB9\u5728\u4E3B\u5E94\u7528\u91CC\u6700\u7EC8\u8FDB\u540C\u4E00\u4E2A handler (src/core/protocol/handler.ts), \u52A8\u4F5C\u5BF9\u8C61\u662F\u540C\u4E00\u5957 (speak / audio)\u3002\n * \u8FD9\u4E2A\u6587\u4EF6\u53EA\u63D0\u4F9B\u300C\u62FC / \u89E3\u6790 deep link \u5B57\u7B26\u4E32\u300D\u7684\u7EAF\u51FD\u6570 (\u7ED9\u684C\u9762\u7AEF\u811A\u672C\u3001\u6587\u6863\u793A\u4F8B\u3001<a href> \u7528), \u96F6\u8FD0\u884C\u65F6\u4F9D\u8D56\u3002\n */\n\n/** `xiaochun://speak` \u7684\u53C2\u6570\u3002\u81F3\u5C11\u7ED9 text / audioUrl / file \u4E4B\u4E00\u3002 */\nexport interface XiaochunSpeakAction {\n action: 'speak';\n /** \u53F0\u8BCD\u6587\u672C; \u4E0E audioUrl \u540C\u65F6\u7ED9\u65F6\u53EA\u4F5C\u6C14\u6CE1\u6587\u5B57, \u4E0D\u518D TTS\u3002URL \u91CC\u4F1A\u81EA\u52A8 encode\u3002practical \u4E0A\u9650\u7EA6 1000~3000 \u6C49\u5B57\u3002 */\n text?: string;\n /** \u9884\u5408\u6210\u97F3\u9891 URL (https), \u7ED5\u8FC7 TTS \u21D2 \u7B49\u4EF7\u4E8E `xc.audio` \u7684 URL \u5F62\u5F0F\u3002 */\n audioUrl?: string;\n /** \u672C\u673A\u6587\u672C\u6587\u4EF6\u8DEF\u5F84 (\u8D85\u957F\u6587\u672C)\u3002\u4EC5\u684C\u9762\u58F3\u53EF\u8BFB, \u5728 iframe \u91CC\u6CA1\u6709\u5BF9\u5E94\u7269\u3002 */\n file?: string;\n}\n\nexport const XIAOCHUN_PROTOCOL_SCHEME = 'xiaochun';\n\n/** \u62FC\u51FA `xiaochun://speak?...`\u3002\u53C2\u6570\u90FD\u7F3A\u65F6\u629B\u9519; audioUrl \u5FC5\u987B\u662F http(s)\u3002 */\nexport function toProtocolUrl(a: XiaochunSpeakAction): string {\n if (a.action !== 'speak') throw new Error(`[project-xiaochun] unsupported action: ${String(a.action)}`);\n if (!a.text && !a.audioUrl && !a.file) throw new Error('[project-xiaochun] speak needs text, audioUrl or file');\n if (a.audioUrl && !/^https?:\\/\\//i.test(a.audioUrl)) throw new Error('[project-xiaochun] audioUrl must be http(s)');\n const q = new URLSearchParams();\n if (a.text) q.set('text', a.text);\n if (a.audioUrl) q.set('audioUrl', a.audioUrl);\n if (a.file) q.set('file', a.file);\n // URLSearchParams \u628A\u7A7A\u683C\u7F16\u6210 '+', \u800C\u684C\u9762\u58F3\u6309 %20 \u89E3\u7801\u66F4\u7A33 \u2192 \u7EDF\u4E00\u6210 %20\n return `${XIAOCHUN_PROTOCOL_SCHEME}://speak?${q.toString().replace(/\\+/g, '%20')}`;\n}\n\n/** \u53CD\u5411\u89E3\u6790 (\u53EA\u8BA4 speak; \u4E0D\u8BA4\u8BC6\u7684\u8FD4\u56DE null)\u3002\u652F\u6301 `xiaochun://speak?\u2026`\u3001`xiaochun:///speak?\u2026`\u3001`xiaochun://action?action=speak&\u2026`\u3002 */\nexport function parseProtocolUrl(url: string): XiaochunSpeakAction | null {\n let u: URL;\n try { u = new URL(url); } catch { return null; }\n if (u.protocol !== `${XIAOCHUN_PROTOCOL_SCHEME}:`) return null;\n const name = u.hostname || u.pathname.replace(/^\\/+/, '');\n const action = name === 'action' ? u.searchParams.get('action') : name;\n if (action !== 'speak') return null;\n const out: XiaochunSpeakAction = { action: 'speak' };\n const text = u.searchParams.get('text');\n const audioUrl = u.searchParams.get('audioUrl');\n const file = u.searchParams.get('file');\n if (text) out.text = text;\n if (audioUrl) out.audioUrl = audioUrl;\n if (file) out.file = file;\n return out.text || out.audioUrl || out.file ? out : null;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBO,IAAM,2BAA2B;AAGjC,SAAS,cAAc,GAAgC;AAC5D,MAAI,EAAE,WAAW,QAAS,OAAM,IAAI,MAAM,0CAA0C,OAAO,EAAE,MAAM,CAAC,EAAE;AACtG,MAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,EAAE,KAAM,OAAM,IAAI,MAAM,uDAAuD;AAC9G,MAAI,EAAE,YAAY,CAAC,gBAAgB,KAAK,EAAE,QAAQ,EAAG,OAAM,IAAI,MAAM,6CAA6C;AAClH,QAAM,IAAI,IAAI,gBAAgB;AAC9B,MAAI,EAAE,KAAM,GAAE,IAAI,QAAQ,EAAE,IAAI;AAChC,MAAI,EAAE,SAAU,GAAE,IAAI,YAAY,EAAE,QAAQ;AAC5C,MAAI,EAAE,KAAM,GAAE,IAAI,QAAQ,EAAE,IAAI;AAEhC,SAAO,GAAG,wBAAwB,YAAY,EAAE,SAAS,EAAE,QAAQ,OAAO,KAAK,CAAC;AAClF;AAGO,SAAS,iBAAiB,KAAyC;AACxE,MAAI;AACJ,MAAI;AAAE,QAAI,IAAI,IAAI,GAAG;AAAA,EAAG,QAAQ;AAAE,WAAO;AAAA,EAAM;AAC/C,MAAI,EAAE,aAAa,GAAG,wBAAwB,IAAK,QAAO;AAC1D,QAAM,OAAO,EAAE,YAAY,EAAE,SAAS,QAAQ,QAAQ,EAAE;AACxD,QAAM,SAAS,SAAS,WAAW,EAAE,aAAa,IAAI,QAAQ,IAAI;AAClE,MAAI,WAAW,QAAS,QAAO;AAC/B,QAAM,MAA2B,EAAE,QAAQ,QAAQ;AACnD,QAAM,OAAO,EAAE,aAAa,IAAI,MAAM;AACtC,QAAM,WAAW,EAAE,aAAa,IAAI,UAAU;AAC9C,QAAM,OAAO,EAAE,aAAa,IAAI,MAAM;AACtC,MAAI,KAAM,KAAI,OAAO;AACrB,MAAI,SAAU,KAAI,WAAW;AAC7B,MAAI,KAAM,KAAI,OAAO;AACrB,SAAO,IAAI,QAAQ,IAAI,YAAY,IAAI,OAAO,MAAM;AACtD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/loader.global.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! @firetable/project-xiaochun v0.1.
|
|
2
|
-
"use strict";var Xiaochun=(()=>{var re=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var Te=(t,n)=>{for(var s in n)re(t,s,{get:n[s],enumerable:!0})},Re=(t,n,s,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Le(n))!Se.call(t,i)&&i!==s&&re(t,i,{get:()=>n[i],enumerable:!(a=Oe(n,i))||a.enumerable});return t};var He=t=>Re(re({},"__esModule",{value:!0}),t);var De={};Te(De,{XC_DEFAULT_ORIGIN:()=>ge,XC_DEFAULT_SRC:()=>ae,XC_FRAME_TO_HOST:()=>Ue,XC_HOST_TO_FRAME:()=>_e,XC_IMPLEMENTED_COMMANDS:()=>ze,XC_PROTOCOL_MAPPING:()=>Be,XC_PROTOCOL_VERSION:()=>Ie,XC_UNSUPPORTED_COMMANDS:()=>Fe,XIAOCHUN_ELEMENT_TAG:()=>ie,XIAOCHUN_PROTOCOL_SCHEME:()=>Y,createXiaochun:()=>G,defineXiaochunElement:()=>V,isXcEnvelope:()=>D,normalizeOrigin:()=>W,parseProtocolUrl:()=>ve,toProtocolUrl:()=>be,xcMessage:()=>C});var Ie=1,ge="https://xiaochun.firetable.tech",ae=`${ge}/embed`,_e=["xc.init","xc.say","xc.audio","xc.audio.chunk","xc.audio.end","xc.motion","xc.expression","xc.lookAt","xc.pointer","xc.setModel","xc.setConfig","xc.mic","xc.pause","xc.resume","xc.destroy"],Ue=["xc.ready","xc.load.progress","xc.loaded","xc.state","xc.stt","xc.utterance","xc.hit-region","xc.error"],ze=["xc.say","xc.audio","xc.audio.chunk","xc.audio.end","xc.motion","xc.expression","xc.pointer","xc.setModel","xc.setConfig","xc.mic","xc.pause","xc.resume","xc.destroy"],Fe=["xc.lookAt"],Be=[{xc:"xc.say",note:'mode:"speak" (\u9ED8\u8BA4)',action:"speak",url:"xiaochun://speak?text=\u2026"},{xc:"xc.say",note:'mode:"chat" (\u8D70 LLM)',action:null,url:null},{xc:"xc.audio",note:"source \u4E3A URL \u5B57\u7B26\u4E32",action:"speak",url:"xiaochun://speak?audioUrl=\u2026[&text=\u2026]"},{xc:"xc.audio",note:"source \u4E3A ArrayBuffer / Blob",action:"audio",url:null},{xc:"xc.audio.chunk / xc.audio.end",note:"\u6D41\u5F0F PCM",action:"audio",url:null}];function C(t,n,s){let a={type:t,v:1,payload:n};return s!==void 0&&(a.id=s),a}function D(t){if(!t||typeof t!="object")return!1;let n=t;return typeof n.type=="string"&&n.type.startsWith("xc.")&&n.v===1}function W(t){if(!t||t==="*"||t==="null")return null;try{let n=new URL(t);return n.protocol!=="https:"&&n.protocol!=="http:"?null:n.origin}catch{return null}}var je="data:image/svg+xml;utf8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 180"><defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#f6b8ae"/><stop offset="1" stop-color="#ea8377"/></linearGradient></defs><ellipse cx="60" cy="170" rx="34" ry="6" fill="#000" opacity=".12"/><circle cx="60" cy="48" r="26" fill="url(#g)" opacity=".75"/><path d="M26 160c2-40 18-62 34-62s32 22 34 62z" fill="url(#g)" opacity=".6"/></svg>'),Xe=(t,n)=>t===void 0?n:typeof t=="number"?`${t}px`:t;function G(t){if(typeof window>"u"||typeof document>"u")throw new Error("[project-xiaochun] createXiaochun must run in a browser");let n=typeof t.container=="string"?document.querySelector(t.container):t.container;if(!n)throw new Error(`[project-xiaochun] container not found: ${String(t.container)}`);let s=t.src??ae,a;try{a=new URL(s,window.location.href)}catch{throw new Error(`[project-xiaochun] invalid src: ${s}`)}let i=W(t.origin??a.origin);if(!i)throw new Error("[project-xiaochun] invalid origin (wildcards are not allowed)");let y=new Set([i]);for(let e of t.allowedOrigins??[]){let o=W(e);if(!o)throw new Error(`[project-xiaochun] invalid allowedOrigins entry: ${e} (wildcards are not allowed)`);y.add(o)}let h=t.transparent??!1,M=t.passthrough??h,U=t.lazy??!0,g=t.position??"inline",k=t.handshakeTimeout??2e4,p=document.createElement("div");p.setAttribute("data-xiaochun","");let l=p.style;l.position=g==="inline"?"relative":"fixed",l.width=Xe(t.width,"320px"),l.height=Xe(t.height,"480px"),l.maxWidth="100%",l.overflow="visible",l.contain="layout style",l.borderRadius="var(--xc-radius, 0)",l.boxShadow="var(--xc-shadow, none)",h||(l.background="var(--xc-bg, transparent)"),g==="bottom-right"&&(l.right="var(--xc-offset-x, 16px)",l.bottom="var(--xc-offset-y, 16px)"),g==="bottom-left"&&(l.left="var(--xc-offset-x, 16px)",l.bottom="var(--xc-offset-y, 16px)"),g!=="inline"&&(l.zIndex=`var(--xc-z-index, ${t.zIndex??2147483e3})`),l.pointerEvents="none",p.setAttribute("part","wrapper"),n.appendChild(p);let x=null;if(t.placeholder!==!1){if(t.placeholder instanceof HTMLElement)x=t.placeholder;else{let o=document.createElement("img");o.src=t.placeholder||je,o.alt="Project XiaoChun",o.decoding="async",o.width=320,o.height=480,x=o}let e=x.style;x.setAttribute("part","placeholder"),e.borderRadius="var(--xc-radius, 0)",e.position="absolute",e.inset="0",e.width="100%",e.height="100%",e.objectFit="contain",e.transition="opacity .25s ease",e.pointerEvents="auto",e.cursor=U===!1?"default":"pointer",x.addEventListener("click",()=>T()),p.appendChild(x)}let j=new Map,X=(e,o)=>{j.get(e)?.forEach(r=>{try{r(o)}catch(c){console.error("[project-xiaochun] listener error",c)}})},ce,le,de=new Promise((e,o)=>{ce=e,le=o});de.catch(()=>{});let u=null,m=null,P=!1,J=!1,ue=!1,Q=!1,$=!1,Z=[],L=new Map,ee=0,R=null,S=null,H=null,z=(e,o,r,c)=>{if(!m){Z.push({type:e,payload:o,id:r,transfer:c});return}m.postMessage(C(e,o,r),c??[])},b=(e,o,r=!1,c,I)=>{if(P)return Promise.reject(new Error("[project-xiaochun] instance destroyed"));u||T();let f=I??`c${++ee}`,d=r?new Promise((v,E)=>L.set(f,{resolve:v,reject:E,sawEnd:!1})):Promise.resolve();return z(e,o,f,c),d},pe=e=>e instanceof ArrayBuffer?e:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),fe=(e,o)=>{if(!e)return;let r=()=>{P||z("xc.audio.end",{abort:!0},o)};e.aborted?r():e.addEventListener("abort",r,{once:!0})},Pe=async(e,o={})=>{if(P)throw new Error("[project-xiaochun] instance destroyed");u||T();let{signal:r,transfer:c,fetch:I,...f}=o,d={...f},v=[];if(typeof e=="string")if(I==="frame")d.source=e;else{let A=await fetch(e);if(!A.ok)throw new Error(`[project-xiaochun] audio fetch failed: HTTP ${A.status}`);let oe=await A.arrayBuffer();d.source=oe,v.push(oe),d.mimeType??(d.mimeType=A.headers.get("content-type")??void 0)}else if(typeof Blob<"u"&&e instanceof Blob)d.source=e,d.mimeType??(d.mimeType=e.type||void 0);else{let A=pe(e);d.source=A,(!(e instanceof ArrayBuffer)||c!==!1)&&v.push(A)}if(P)throw new Error("[project-xiaochun] instance destroyed");let E=`c${++ee}`,_=b("xc.audio",d,!0,v,E);return fe(r,E),_},we=e=>{if(P)throw new Error("[project-xiaochun] instance destroyed");let{signal:o,transfer:r,fetch:c,mimeType:I,...f}=e,d=`c${++ee}`,v=!1,E=!1,_=f.format==="pcm16"||f.format==="float32"?f.format:null,A=Promise.resolve();return{write(K){if(E)throw new Error("[project-xiaochun] audio stream already ended");if(P)throw new Error("[project-xiaochun] instance destroyed");if(K instanceof Int16Array?_??(_="pcm16"):K instanceof Float32Array&&(_??(_="float32")),!_)throw new Error("[project-xiaochun] speakAudioStream: set opts.format when writing raw ArrayBuffers");let ne=pe(K),B={data:ne,format:_,sampleRate:f.sampleRate,channels:f.channels};v?z("xc.audio.chunk",B,d,!(K instanceof ArrayBuffer)||r!==!1?[ne]:[]):(v=!0,B.text=f.text,B.motion=f.motion,B.lipsync=f.lipsync,A=b("xc.audio.chunk",B,!0,[ne],d),fe(o,d))},end(){E||(E=!0,v&&z("xc.audio.end",{},d))},abort(){E&&!v||(E=!0,v&&z("xc.audio.end",{abort:!0},d))},get done(){return A}}};function Ee(){let e=new URL(a.href);return e.searchParams.set("host",window.location.origin),h&&e.searchParams.set("transparent","1"),t.ui&&e.searchParams.set("ui","1"),t.lang&&e.searchParams.set("lang",t.lang),t.heavy&&e.searchParams.set("heavy",t.heavy),t.controls&&e.searchParams.set("controls","1"),t.model&&e.searchParams.set("outfit",t.model),e.href}function T(){if(P||u)return;xe(),S?.disconnect(),S=null;let e=document.createElement("iframe");e.title="Project XiaoChun",e.loading="lazy",e.allow="microphone; autoplay",e.referrerPolicy="strict-origin-when-cross-origin",t.sandbox!==!1&&e.setAttribute("sandbox",t.sandbox??"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"),e.setAttribute("allowtransparency","true"),e.setAttribute("scrolling","no");let o=e.style;o.position="absolute",o.inset="0",o.width="100%",o.height="100%",o.border="0",o.background="transparent",o.colorScheme="normal",o.borderRadius="var(--xc-radius, 0)",e.setAttribute("part","iframe"),o.opacity="0",o.transition="opacity .25s ease",o.pointerEvents=M?"none":"auto",e.src=Ee(),u=e,p.appendChild(e),x&&(x.style.cursor="default"),R=setTimeout(()=>{m||X("error",{code:"timeout",message:`no xc.ready from ${i} within ${k}ms`})},k),ke(),Me()}let he=e=>{if(P||!u||e.source!==u.contentWindow)return;if(!y.has(e.origin)){X("error",{code:"origin_denied",message:`ignored message from untrusted origin ${e.origin}`});return}let o=e.data;if(!D(o)||o.type!=="xc.ready"||m)return;let r=new MessageChannel;m=r.port1,m.onmessage=Ae,u.contentWindow.postMessage(C("xc.init",{hostOrigin:window.location.origin}),e.origin,[r.port2]),R&&(clearTimeout(R),R=null),X("handshake",o.payload);for(let c of Z.splice(0))m.postMessage(C(c.type,c.payload,c.id),c.transfer??[]);q()};window.addEventListener("message",he);function Ae(e){let o=e.data;if(D(o))switch(o.type){case"xc.load.progress":X("progress",o.payload);break;case"xc.loaded":if(!Q){if(Q=!0,u&&(u.style.opacity="1"),x){let r=x;r.style.opacity="0",r.style.pointerEvents="none",setTimeout(()=>r.remove(),300),x=null}ce()}X("ready",o.payload);break;case"xc.state":X("state",o.payload);break;case"xc.stt":X("stt",o.payload);break;case"xc.utterance":{X("utterance",o.payload);let r=o.id?L.get(o.id):void 0;r&&o.payload.phase==="end"&&(L.delete(o.id),r.resolve());break}case"xc.hit-region":{let{hit:r}=o.payload;X("hit-region",o.payload),M&&u&&r!==$&&($=r,u.style.pointerEvents=r?"auto":"none");break}case"xc.error":{let{code:r,message:c,command:I}=o.payload;X("error",{code:r,message:c,command:I});let f=o.id?L.get(o.id):void 0;f&&o.id&&(L.delete(o.id),f.reject(new Error(`[${r}] ${c}`)));break}default:break}}let F=0,N=null,me=e=>{!u||!m||u.style.pointerEvents==="auto"||(N={x:e.clientX,y:e.clientY},!F&&(F=requestAnimationFrame(()=>{if(F=0,!u||!m||!N)return;let o=u.getBoundingClientRect(),r=N.x-o.left,c=N.y-o.top;if(r<0||c<0||r>o.width||c>o.height){$&&($=!1,u.style.pointerEvents="none");return}m.postMessage(C("xc.pointer",{x:r,y:c}))})))};function Me(){M&&window.addEventListener("pointermove",me,{passive:!0})}let te=null;function ke(){t.autoPause===!1||typeof IntersectionObserver>"u"||(te=new IntersectionObserver(e=>{ue=!(e[e.length-1]?.isIntersecting??!0),q()}),te.observe(p))}let ye=!1;function q(){if(!m)return;let e=J||ue;e!==ye&&(ye=e,m.postMessage(C(e?"xc.pause":"xc.resume")))}function xe(){if(H===null)return;let e=window;e.cancelIdleCallback?e.cancelIdleCallback(H):clearTimeout(H),H=null}function Ce(){if(U===!1){T();return}if(U==="click")return;let e=()=>{let o=window;H=o.requestIdleCallback?o.requestIdleCallback(()=>{H=null,T()},{timeout:3e3}):setTimeout(T,1200)};if(typeof IntersectionObserver>"u"){e();return}S=new IntersectionObserver(o=>{o.some(r=>r.isIntersecting)&&(S?.disconnect(),S=null,e())},{rootMargin:`${t.lazyMargin??200}px`}),S.observe(p)}let w=null;if(t.draggable&&g!=="inline"){w=document.createElement("div"),w.setAttribute("aria-label","drag"),Object.assign(w.style,{position:"absolute",left:"0",top:"0",width:"28px",height:"28px",cursor:"grab",pointerEvents:"auto",borderRadius:"8px",background:"rgba(0,0,0,.25)",color:"#fff",font:"14px/28px system-ui",textAlign:"center",userSelect:"none",touchAction:"none",zIndex:"2",opacity:"0.5"}),w.textContent="\u283F";let e=null;w.addEventListener("pointerdown",r=>{let c=p.getBoundingClientRect();e={dx:r.clientX-c.left,dy:r.clientY-c.top},w.setPointerCapture(r.pointerId)}),w.addEventListener("pointermove",r=>{e&&(l.left=`${Math.min(Math.max(0,r.clientX-e.dx),window.innerWidth-40)}px`,l.top=`${Math.min(Math.max(0,r.clientY-e.dy),window.innerHeight-40)}px`,l.right="auto",l.bottom="auto")});let o=()=>{e=null};w.addEventListener("pointerup",o),w.addEventListener("pointercancel",o),p.appendChild(w)}return Ce(),{element:p,get iframe(){return u},ready:de,activate:T,say:(e,o)=>b("xc.say",{text:e,mode:o?.mode},!0),speakAudio:Pe,speakAudioStream:we,motion:e=>b("xc.motion",typeof e=="string"?e.startsWith("http")||e.startsWith("/")?{url:e}:{name:e}:e),expression:e=>b("xc.expression",{name:e}),lookAt:(e,o)=>b("xc.lookAt",{x:e,y:o}),setModel:e=>b("xc.setModel",typeof e=="string"?/^(https?:)?\/|\.vrm/i.test(e)?{url:e}:{outfit:e}:e),setConfig:e=>b("xc.setConfig",e),startListening:()=>b("xc.mic",{enabled:!0}),stopListening:()=>b("xc.mic",{enabled:!1}),mic:e=>b("xc.mic",{enabled:e}),pause(){J=!0,q()},resume(){J=!1,q()},destroy(){if(!P){try{m?.postMessage(C("xc.destroy"))}catch{}P=!0,xe(),S?.disconnect(),te?.disconnect(),R&&clearTimeout(R),F&&cancelAnimationFrame(F),window.removeEventListener("message",he),window.removeEventListener("pointermove",me);try{m?.close()}catch{}m=null;for(let e of L.values())e.reject(new Error("[project-xiaochun] instance destroyed"));L.clear(),Z.length=0,Q||le(new Error("[project-xiaochun] destroyed before ready")),p.remove(),u=null,X("destroy",void 0),j.clear()}},on(e,o){let r=j.get(e);return r||(r=new Set,j.set(e,r)),r.add(o),()=>{r.delete(o)}}}}var $e=["src","model","lang","mic","transparent","draggable","position","size","lazy","paused","placeholder","heavy","ui","controls","allowed-origins"],Ne=new Set(["src","draggable","position","size","lazy","placeholder","heavy","ui","controls","allowed-origins","transparent"]);function O(t,n,s){let a=t.getAttribute(n);return a===null?s:a!=="false"}function qe(t){if(!t)return{width:"320px",height:"480px"};let n=t.trim().split(/x/i),s=i=>/^\d+(\.\d+)?$/.test(i)?`${i}px`:i;if(n.length>=2)return{width:s(n[0]),height:s(n[1])};let a=parseFloat(n[0]);return Number.isFinite(a)&&/^\d+(\.\d+)?$/.test(n[0])?{width:`${a}px`,height:`${Math.round(a*1.5)}px`}:{width:n[0],height:"480px"}}function Ke(){class t extends HTMLElement{constructor(){super(...arguments);this.client=null;this.mountEl=null;this.rebuildScheduled=!1}static get observedAttributes(){return[...$e]}connectedCallback(){if(!this.shadowRoot){let a=this.attachShadow({mode:"open"});a.innerHTML='<style>:host{display:inline-block;max-width:100%}:host([hidden]){display:none}</style><div part="mount"></div>'}this.mountEl=this.shadowRoot.querySelector("div"),this.build()}disconnectedCallback(){this.destroy()}attributeChangedCallback(a,i,y){if(!this.client||i===y)return;if(Ne.has(a)){this.rebuildScheduled||(this.rebuildScheduled=!0,queueMicrotask(()=>{this.rebuildScheduled=!1,this.isConnected&&(this.destroy(),this.build())}));return}let h=this.client;a==="model"&&y?h.setModel(y).catch(()=>{}):a==="lang"&&y?h.setConfig({lang:y}).catch(()=>{}):a==="mic"?h.mic(O(this,"mic",!1)).catch(()=>{}):a==="paused"&&(O(this,"paused",!1)?h.pause():h.resume())}build(){if(!this.mountEl||this.client)return;let{width:a,height:i}=qe(this.getAttribute("size")),y=this.getAttribute("placeholder"),h=this.getAttribute("allowed-origins"),M=this.getAttribute("lazy"),U=M==="click"?"click":M!=="false",g=G({container:this.mountEl,src:this.getAttribute("src")||void 0,allowedOrigins:h?h.split(",").map(p=>p.trim()).filter(Boolean):void 0,lazy:U,placeholder:y==="none"?!1:y||void 0,transparent:O(this,"transparent",!0),width:a,height:i,position:this.getAttribute("position")??"inline",draggable:O(this,"draggable",!1),lang:this.getAttribute("lang")??void 0,model:this.getAttribute("model")??void 0,heavy:this.getAttribute("heavy")??void 0,ui:O(this,"ui",!1),controls:O(this,"controls",!1)});this.client=g;let k=(p,l)=>g.on(p,x=>this.dispatchEvent(new CustomEvent(l,{detail:x,bubbles:!0,composed:!0})));k("ready","xc-ready"),k("progress","xc-progress"),k("state","xc-state"),k("stt","xc-stt"),k("utterance","xc-utterance"),k("error","xc-error"),O(this,"paused",!1)&&g.pause(),O(this,"mic",!1)&&g.ready.then(()=>g.mic(!0)).catch(()=>{})}say(a,i){return this.requireClient().say(a,i)}speakAudio(a,i){return this.requireClient().speakAudio(a,i)}speakAudioStream(a){return this.requireClient().speakAudioStream(a)}motion(a){return this.requireClient().motion(a)}expression(a){return this.requireClient().expression(a)}destroy(){this.client?.destroy(),this.client=null}requireClient(){if(!this.client)throw new Error("<xiaochun-avatar> is not connected");return this.client}}return t}var ie="xiaochun-avatar";function V(t=ie){if(typeof customElements>"u"||typeof HTMLElement>"u")return null;let n=customElements.get(t);if(n)return n;let s=Ke();return customElements.define(t,s),s}var Y="xiaochun";function be(t){if(t.action!=="speak")throw new Error(`[project-xiaochun] unsupported action: ${String(t.action)}`);if(!t.text&&!t.audioUrl&&!t.file)throw new Error("[project-xiaochun] speak needs text, audioUrl or file");if(t.audioUrl&&!/^https?:\/\//i.test(t.audioUrl))throw new Error("[project-xiaochun] audioUrl must be http(s)");let n=new URLSearchParams;return t.text&&n.set("text",t.text),t.audioUrl&&n.set("audioUrl",t.audioUrl),t.file&&n.set("file",t.file),`${Y}://speak?${n.toString().replace(/\+/g,"%20")}`}function ve(t){let n;try{n=new URL(t)}catch{return null}if(n.protocol!==`${Y}:`)return null;let s=n.hostname||n.pathname.replace(/^\/+/,"");if((s==="action"?n.searchParams.get("action"):s)!=="speak")return null;let i={action:"speak"},y=n.searchParams.get("text"),h=n.searchParams.get("audioUrl"),M=n.searchParams.get("file");return y&&(i.text=y),h&&(i.audioUrl=h),M&&(i.file=M),i.text||i.audioUrl||i.file?i:null}V();var se=document.currentScript;if(se&&se.hasAttribute("data-auto")){let t=()=>{let n=document.createElement("xiaochun-avatar");for(let s of Array.from(se.attributes))s.name.startsWith("data-")&&s.name!=="data-auto"&&n.setAttribute(s.name.slice(5),s.value);n.hasAttribute("position")||n.setAttribute("position","bottom-right"),document.body.appendChild(n)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}return He(De);})();
|
|
1
|
+
/*! @firetable/project-xiaochun v0.1.15 | MIT | https://github.com/FireTable/project-xiaochun */
|
|
2
|
+
"use strict";var Xiaochun=(()=>{var He=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Vt=Object.prototype.hasOwnProperty;var Jt=(t,r)=>{for(var s in r)He(t,s,{get:r[s],enumerable:!0})},Yt=(t,r,s,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of Kt(r))!Vt.call(t,a)&&a!==s&&He(t,a,{get:()=>r[a],enumerable:!(i=Dt(r,a))||i.enumerable});return t};var Zt=t=>Yt(He({},"__esModule",{value:!0}),t);var bn={};Jt(bn,{XC_DEFAULT_ORIGIN:()=>Et,XC_DEFAULT_SRC:()=>Ue,XC_FRAME_TO_HOST:()=>tn,XC_HOST_TO_FRAME:()=>en,XC_ID_RE:()=>At,XC_IMPLEMENTED_COMMANDS:()=>nn,XC_PROTOCOL_MAPPING:()=>on,XC_PROTOCOL_VERSION:()=>Qt,XC_UI_LEGACY_PARTS:()=>We,XC_UI_PARTS:()=>ie,XC_UNSUPPORTED_COMMANDS:()=>rn,XC_WINDOW_CORNER_RADIUS:()=>Be,XIAOCHUN_ELEMENT_TAG:()=>Ge,XIAOCHUN_PROTOCOL_SCHEME:()=>Ae,createXiaochun:()=>ve,defineXiaochunElement:()=>Ee,isXcEnvelope:()=>be,isXcId:()=>k,normalizeOrigin:()=>Xe,normalizeXcUiOption:()=>Ne,parseProtocolUrl:()=>_t,parseXcUiList:()=>je,parseXcUiParam:()=>an,toProtocolUrl:()=>Tt,xcHasOwn:()=>cn,xcMessage:()=>U});var Qt=1,Et="https://xiaochun.firetable.tech",Ue=`${Et}/embed`,en=["xc.init","xc.say","xc.audio","xc.audio.chunk","xc.audio.end","xc.motion","xc.expression","xc.lookAt","xc.pointer","xc.setModel","xc.setOutfit","xc.setScene","xc.prefetch","xc.setConfig","xc.mic","xc.pause","xc.resume","xc.destroy"],tn=["xc.ready","xc.load.progress","xc.loaded","xc.outfit-changed","xc.scene-changed","xc.prefetched","xc.state","xc.stt","xc.utterance","xc.hit-region","xc.gesture-move","xc.gesture-resize","xc.error"],nn=["xc.say","xc.audio","xc.audio.chunk","xc.audio.end","xc.motion","xc.expression","xc.pointer","xc.setModel","xc.setOutfit","xc.setScene","xc.prefetch","xc.setConfig","xc.mic","xc.pause","xc.resume","xc.destroy"],rn=["xc.lookAt"],on=[{xc:"xc.say",note:'mode:"speak" (\u9ED8\u8BA4)',action:"speak",url:"xiaochun://speak?text=\u2026"},{xc:"xc.say",note:'mode:"chat" (\u8D70 LLM)',action:null,url:null},{xc:"xc.audio",note:"source \u4E3A URL \u5B57\u7B26\u4E32",action:"speak",url:"xiaochun://speak?audioUrl=\u2026[&text=\u2026]"},{xc:"xc.audio",note:"source \u4E3A ArrayBuffer / Blob",action:"audio",url:null},{xc:"xc.audio.chunk / xc.audio.end",note:"\u6D41\u5F0F PCM",action:"audio",url:null}],Be=20,ie=["chat","bubble","outfit","scene"],sn=new Set(ie),We=["chat","bubble"];function je(t){let r=new Set,s=[];for(let i of t){let a=typeof i=="string"?i.trim().toLowerCase():"";sn.has(a)?r.add(a):s.push(typeof i=="string"?i.slice(0,40):typeof i)}return{parts:ie.filter(i=>r.has(i)),unknown:s,legacy:!1}}function an(t){let r=(t??"").trim().toLowerCase();return r===""||r==="0"||r==="false"?{parts:[],unknown:[],legacy:!1}:r==="1"||r==="true"?{parts:[...We],unknown:[],legacy:!0}:je(r.split(",").filter(s=>s.trim()!==""))}function Ne(t){return t===!0?{parts:[...We],unknown:[],legacy:!0}:Array.isArray(t)?je(t):{parts:[],unknown:[],legacy:!1}}var At=/^[a-z][a-z0-9_]{0,63}$/,k=t=>typeof t=="string"&&At.test(t),cn=(t,r)=>Object.prototype.hasOwnProperty.call(t,r);function U(t,r,s){let i={type:t,v:1,payload:r};return s!==void 0&&(i.id=s),i}function be(t){if(!t||typeof t!="object")return!1;let r=t;return typeof r.type=="string"&&r.type.startsWith("xc.")&&r.v===1}function Xe(t){if(!t||t==="*"||t==="null")return null;try{let r=new URL(t);return r.protocol!=="https:"&&r.protocol!=="http:"?null:r.origin}catch{return null}}var St=Object.freeze({minWidth:120,minHeight:180,maxWidth:1/0,maxHeight:1/0}),we=t=>typeof t=="number"&&Number.isFinite(t)&&t>0;function $e(t){if(!t)return null;let r=t===!0?{}:t,s=we(r.minWidth)?r.minWidth:St.minWidth,i=we(r.minHeight)?r.minHeight:St.minHeight,a=we(r.maxWidth)?Math.max(r.maxWidth,s):1/0,m=we(r.maxHeight)?Math.max(r.maxHeight,i):1/0;return{minWidth:s,minHeight:i,maxWidth:a,maxHeight:m}}var Z=(t,r,s)=>Math.min(Math.max(t,r),Math.max(r,s));function Ct(t,r,s,i){return{left:Z(t.left+r,0,i.width-t.width),top:Z(t.top+s,0,i.height-t.height),width:t.width,height:t.height}}function kt(t,r,s,i,a,m){let d=r==="NW"||r==="SW",g=r==="NW"||r==="NE",R=t.left+t.width,E=t.top+t.height,x=d?t.width-s:t.width+s,B=g?t.height-i:t.height+i,ce=d?R:m.width-t.left,F=g?E:m.height-t.top,I=Z(x,a.minWidth,Math.min(a.maxWidth,ce)),T=Z(B,a.minHeight,Math.min(a.maxHeight,F));return{left:d?R-I:t.left,top:g?E-T:t.top,width:I,height:T}}function Mt(t,r){let s=Math.min(t.width,Math.max(1,r.width)),i=Math.min(t.height,Math.max(1,r.height));return{left:Z(t.left,0,r.width-s),top:Z(t.top,0,r.height-i),width:s,height:i}}var un=new Set(["NW","NE","SW","SE"]),ln=new Set(["start","move","end"]),dn=new Set(["up","cancel","blur"]),fn=2e4,Pe=t=>typeof t=="number"&&Number.isFinite(t)&&Math.abs(t)<=fn,Ot=t=>typeof t=="number"&&Number.isSafeInteger(t)&&t>=0;function Rt(t,r){if(r===null||typeof r!="object")return null;let s=r;if(!Ot(s.gesture)||!Ot(s.seq)||typeof s.phase!="string"||!ln.has(s.phase)||!Pe(s.dx)||!Pe(s.dy)||!Pe(s.totalDx)||!Pe(s.totalDy)||s.reason!==void 0&&(typeof s.reason!="string"||!dn.has(s.reason)))return null;let i={gesture:s.gesture,seq:s.seq,phase:s.phase,totalDx:s.totalDx,totalDy:s.totalDy};if(t==="resize"){if(typeof s.corner!="string"||!un.has(s.corner))return null;i.corner=s.corner}return i}var se=class{constructor(){this.lastGesture=0;this.lastSeq=-1;this.open=!1}get active(){return this.open}accept(r){return r.phase==="start"?r.gesture<=this.lastGesture||r.seq!==0?!1:(this.lastGesture=r.gesture,this.lastSeq=0,this.open=!0,!0):!this.open||r.gesture!==this.lastGesture||r.seq<=this.lastSeq?!1:(this.lastSeq=r.seq,r.phase==="end"&&(this.open=!1),!0)}close(){this.open=!1}};var pn="data:image/svg+xml;utf8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 180"><defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#f6b8ae"/><stop offset="1" stop-color="#ea8377"/></linearGradient></defs><ellipse cx="60" cy="170" rx="34" ry="6" fill="#000" opacity=".12"/><circle cx="60" cy="48" r="26" fill="url(#g)" opacity=".75"/><path d="M26 160c2-40 18-62 34-62s32 22 34 62z" fill="url(#g)" opacity=".6"/></svg>'),ae=(t,r)=>t===void 0?r:typeof t=="number"?`${t}px`:t;function ve(t){if(typeof window>"u"||typeof document>"u")throw new Error("[project-xiaochun] createXiaochun must run in a browser");let r=typeof t.container=="string"?document.querySelector(t.container):t.container;if(!r)throw new Error(`[project-xiaochun] container not found: ${String(t.container)}`);let s=t.src??Ue,i;try{i=new URL(s,window.location.href)}catch{throw new Error(`[project-xiaochun] invalid src: ${s}`)}let a=Xe(t.origin??i.origin);if(!a)throw new Error("[project-xiaochun] invalid origin (wildcards are not allowed)");let m=new Set([a]);for(let e of t.allowedOrigins??[]){let n=Xe(e);if(!n)throw new Error(`[project-xiaochun] invalid allowedOrigins entry: ${e} (wildcards are not allowed)`);m.add(n)}let d=t.persist==="host"?"xiaochun:prefs":typeof t.persist=="string"&&t.persist?t.persist:null,g=()=>{if(!d)return{};try{let e=JSON.parse(window.localStorage.getItem(d)??"null"),n={};return e&&typeof e=="object"&&(k(e.outfit)&&(n.outfit=e.outfit),k(e.scene)&&(n.scene=e.scene)),n}catch{return{}}},R=e=>{if(d)try{let n={...g()};for(let[o,c]of Object.entries(e))c?n[o]=c:delete n[o];window.localStorage.setItem(d,JSON.stringify(n))}catch{}},E=g();t.model!==void 0&&t.outfit===void 0&&console.warn('[project-xiaochun] option "model" is deprecated, use "outfit" (built-in outfit id).');let x=Ne(t.ui),B=x.parts;x.legacy&&console.warn(`[project-xiaochun] option "ui: true" is deprecated, use an array of parts, e.g. ui: ['chat', 'bubble', 'outfit', 'scene'].`),x.unknown.length&&console.warn(`[project-xiaochun] ignoring unknown ui part(s): ${x.unknown.join(", ")} (known: ${ie.join(", ")})`);let F=t.outfit??(k(t.model)?t.model:void 0)??E.outfit,I=t.scene??E.scene??(t.transparent?"transparent":void 0),T=I==="transparent"||I!=="light"&&I!=="dark"&&(t.transparent??!1),D=t.passthrough??T,Se=t.lazy??!0,$=t.position??"inline",Fe=t.handshakeTimeout??2e4,A=document.createElement("div");A.setAttribute("data-xiaochun","");let f=A.style;f.position=$==="inline"?"relative":"fixed",f.width=ae(t.width,"320px"),f.height=ae(t.height,"480px"),f.maxWidth="100%",f.overflow="visible",f.contain="layout style",f.boxShadow="var(--xc-shadow, none)";let De=()=>{f.background=T?"":"var(--xc-bg, transparent)"};De();let Oe=t.borderRadius,ue=()=>Oe!==void 0?ae(Oe,"0px"):T?"0px":`${Be}px`,Ke=()=>{let e=`var(--xc-radius, ${ue()})`;f.borderRadius=e,v&&(v.style.borderRadius=e),u&&(u.style.borderRadius=e)};f.borderRadius=`var(--xc-radius, ${ue()})`,$==="bottom-right"&&(f.right="var(--xc-offset-x, 16px)",f.bottom="var(--xc-offset-y, 16px)"),$==="bottom-left"&&(f.left="var(--xc-offset-x, 16px)",f.bottom="var(--xc-offset-y, 16px)"),$!=="inline"&&(f.zIndex=`var(--xc-z-index, ${t.zIndex??2147483e3})`),f.pointerEvents="none",A.setAttribute("part","wrapper"),r.appendChild(A);let v=null;if(t.placeholder!==!1){if(t.placeholder instanceof HTMLElement)v=t.placeholder;else{let n=document.createElement("img");n.src=t.placeholder||pn,n.alt="Project XiaoChun",n.decoding="async",n.width=320,n.height=480,v=n}let e=v.style;v.setAttribute("part","placeholder"),e.borderRadius=`var(--xc-radius, ${ue()})`,e.position="absolute",e.inset="0",e.width="100%",e.height="100%",e.objectFit="contain",e.transition="opacity .25s ease",e.pointerEvents="auto",e.cursor=Se===!1?"default":"pointer",v.addEventListener("click",()=>_()),A.appendChild(v)}let le=new Map,y=(e,n)=>{le.get(e)?.forEach(o=>{try{o(n)}catch(c){console.error("[project-xiaochun] listener error",c)}})},Ve,Je,Ye=new Promise((e,n)=>{Ve=e,Je=n});Ye.catch(()=>{});let u=null,b=null,w=!1,Ce=!1,Ze=!1,ke=!1,Q=!1,X=null,Qe=null,et=null,Me=[],S=new Map,Re=0,K=null,G=null,V=null,ze,tt=new Promise(e=>{ze=e}),Ht=(e,n,o,c)=>{y("error",{code:o,message:c,command:e});let p=n?S.get(n):void 0;p&&n&&(S.delete(n),p.reject(new Error(`[${o}] ${c}`)))},nt=(e,n)=>Ht(e,n,"unsupported",`${e} is not supported by this /embed deployment (older version; its xc.ready has no capabilities for it)`),ee=(e,n,o,c,p)=>{if(!b){Me.push({type:e,payload:n,id:o,transfer:c,requires:p});return}if(p&&!X?.[p]){nt(e,o);return}b.postMessage(U(e,n,o),c??[])},P=(e,n,o=!1,c,p,l)=>{if(w)return Promise.reject(new Error("[project-xiaochun] instance destroyed"));u||_();let h=p??`c${++Re}`,C=o?new Promise((z,N)=>S.set(h,{resolve:z,reject:N,sawEnd:!1})):Promise.resolve();return ee(e,n,h,c,l),C},rt=e=>e instanceof ArrayBuffer?e:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),ot=(e,n)=>{if(!e)return;let o=()=>{w||ee("xc.audio.end",{abort:!0},n)};e.aborted?o():e.addEventListener("abort",o,{once:!0})},Ut=async(e,n={})=>{if(w)throw new Error("[project-xiaochun] instance destroyed");u||_();let{signal:o,transfer:c,fetch:p,...l}=n,h={...l},C=[];if(typeof e=="string")if(p==="frame")h.source=e;else{let L=await fetch(e);if(!L.ok)throw new Error(`[project-xiaochun] audio fetch failed: HTTP ${L.status}`);let Te=await L.arrayBuffer();h.source=Te,C.push(Te),h.mimeType??(h.mimeType=L.headers.get("content-type")??void 0)}else if(typeof Blob<"u"&&e instanceof Blob)h.source=e,h.mimeType??(h.mimeType=e.type||void 0);else{let L=rt(e);h.source=L,(!(e instanceof ArrayBuffer)||c!==!1)&&C.push(L)}if(w)throw new Error("[project-xiaochun] instance destroyed");let z=`c${++Re}`,N=P("xc.audio",h,!0,C,z);return ot(o,z),N},Bt=e=>{if(w)throw new Error("[project-xiaochun] instance destroyed");let{signal:n,transfer:o,fetch:c,mimeType:p,...l}=e,h=`c${++Re}`,C=!1,z=!1,N=l.format==="pcm16"||l.format==="float32"?l.format:null,L=Promise.resolve();return{write(xe){if(z)throw new Error("[project-xiaochun] audio stream already ended");if(w)throw new Error("[project-xiaochun] instance destroyed");if(xe instanceof Int16Array?N??(N="pcm16"):xe instanceof Float32Array&&(N??(N="float32")),!N)throw new Error("[project-xiaochun] speakAudioStream: set opts.format when writing raw ArrayBuffers");let _e=rt(xe),oe={data:_e,format:N,sampleRate:l.sampleRate,channels:l.channels};C?ee("xc.audio.chunk",oe,h,!(xe instanceof ArrayBuffer)||o!==!1?[_e]:[]):(C=!0,oe.text=l.text,oe.motion=l.motion,oe.lipsync=l.lipsync,L=P("xc.audio.chunk",oe,!0,[_e],h),ot(n,h))},end(){z||(z=!0,C&&ee("xc.audio.end",{},h))},abort(){z&&!C||(z=!0,C&&ee("xc.audio.end",{abort:!0},h))},get done(){return L}}};function Wt(){let e=new URL(i.href);return e.searchParams.set("host",window.location.origin),T&&e.searchParams.set("transparent","1"),B.length&&e.searchParams.set("ui",B.join(",")),t.lang&&e.searchParams.set("lang",t.lang),t.heavy&&e.searchParams.set("heavy",t.heavy),t.controls===!1&&e.searchParams.set("controls","0"),I&&k(I)&&e.searchParams.set("scene",I),F&&e.searchParams.set("outfit",F),e.href}function _(){if(w||u)return;dt(),G?.disconnect(),G=null;let e=document.createElement("iframe");e.title="Project XiaoChun",e.loading="lazy",e.allow=t.crossOriginIsolated===!0?"microphone; autoplay; cross-origin-isolated":"microphone; autoplay",e.referrerPolicy="strict-origin-when-cross-origin",t.sandbox!==!1&&e.setAttribute("sandbox",t.sandbox??"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"),e.setAttribute("allowtransparency","true"),e.setAttribute("scrolling","no");let n=e.style;n.position="absolute",n.inset="0",n.width="100%",n.height="100%",n.border="0",n.background="transparent",n.colorScheme="normal",n.borderRadius=`var(--xc-radius, ${ue()})`,e.setAttribute("part","iframe"),n.opacity="0",n.transition="opacity .25s ease",n.pointerEvents=D?"none":"auto",e.src=Wt(),u=e,A.appendChild(e),v&&(v.style.cursor="default"),K=setTimeout(()=>{b||y("error",{code:"timeout",message:`no xc.ready from ${a} within ${Fe}ms`})},Fe),qt(),D&&ct()}let it=e=>{if(w||!u||e.source!==u.contentWindow)return;if(!m.has(e.origin)){y("error",{code:"origin_denied",message:`ignored message from untrusted origin ${e.origin}`});return}let n=e.data;if(!be(n)||n.type!=="xc.ready"||b)return;let o=new MessageChannel;b=o.port1,b.onmessage=jt,X=n.payload?.capabilities??null;let c=gt();re=c;let p={...t.allowCustomModel?{allowCustomModel:!0}:{},...c.move||c.resize?{gestures:c}:{}};u.contentWindow.postMessage(U("xc.init",{hostOrigin:window.location.origin,...Object.keys(p).length?{config:p}:{}}),e.origin,[o.port2]),wt(),K&&(clearTimeout(K),K=null),y("handshake",n.payload),ze();for(let l of Me.splice(0))l.requires&&!X?.[l.requires]?nt(l.type,l.id):b.postMessage(U(l.type,l.payload,l.id),l.transfer??[]);he()};window.addEventListener("message",it);function Le(e,n){let o=e?S.get(e):void 0;o&&e&&(S.delete(e),o.resolve(n))}function jt(e){let n=e.data;if(be(n))switch(n.type){case"xc.load.progress":y("progress",n.payload);break;case"xc.loaded":if(!ke){if(ke=!0,t.prefetch&&t.heavy==="eager"&&X?.prefetch){let o=Array.isArray(t.prefetch)?t.prefetch:void 0;vt.prefetch(o).catch(()=>{})}if(u&&(u.style.opacity="1"),v){let o=v;o.style.opacity="0",o.style.pointerEvents="none",setTimeout(()=>o.remove(),300),v=null}Ve()}y("ready",n.payload);break;case"xc.outfit-changed":{let o=n.payload;o.noop||(Qe=o.id,y("outfit-changed",o),!o.initial&&o.id&&R({outfit:o.id})),Le(n.id);break}case"xc.scene-changed":{let o=n.payload;et=o.id,o.transparent!==T&&Gt(o.transparent),o.noop||(y("scene-changed",o),o.initial||R({scene:o.id})),Le(n.id);break}case"xc.prefetched":Le(n.id,n.payload);break;case"xc.state":y("state",n.payload);break;case"xc.stt":y("stt",n.payload);break;case"xc.utterance":{y("utterance",n.payload);let o=n.id?S.get(n.id):void 0;o&&n.payload.phase==="end"&&(S.delete(n.id),o.resolve());break}case"xc.hit-region":{let{hit:o}=n.payload;y("hit-region",n.payload),D&&u&&o!==Q&&(Q=o,u.style.pointerEvents=o?"auto":"none");break}case"xc.gesture-move":bt("move",n.payload);break;case"xc.gesture-resize":bt("resize",n.payload);break;case"xc.error":{let{code:o,message:c,command:p}=n.payload;y("error",{code:o,message:c,command:p}),o==="unknown_id"&&(p==="outfit"||p==="scene")&&R({[p]:null});let l=n.id?S.get(n.id):void 0;l&&n.id&&(S.delete(n.id),l.reject(new Error(`[${o}] ${c}`)));break}default:break}}let Nt=32,st=2,W=0,te=null,j=null,ne=null,de=null,at=0,q=()=>{ne=null},$t=()=>{if(!u)return null;let e=performance.now();return(!ne||e-at>400)&&(ne=u.getBoundingClientRect(),at=e),ne},fe=e=>{!u||!b||u.style.pointerEvents==="auto"||(te={x:e.clientX,y:e.clientY},!W&&(W=requestAnimationFrame(()=>{if(W=0,!u||!b||!te)return;let n=$t();if(!n)return;let o=te.x-n.left,c=te.y-n.top;if(o<0||c<0||o>n.width||c>n.height){j=null,Q&&(Q=!1,u.style.pointerEvents="none");return}let p=performance.now();j&&p-j.t<Nt||j&&Math.abs(o-j.x)<st&&Math.abs(c-j.y)<st||(j={x:o,y:c,t:p},b.postMessage(U("xc.pointer",{x:o,y:c})))})))},pe=!1;function ct(){pe||!u||(pe=!0,window.addEventListener("pointermove",fe,{passive:!0}),window.addEventListener("pointerdown",fe,{passive:!0}),window.addEventListener("scroll",q,{passive:!0,capture:!0}),window.addEventListener("resize",q,{passive:!0}),typeof ResizeObserver<"u"&&(de=new ResizeObserver(q),de.observe(u)))}function ut(){pe&&(pe=!1,window.removeEventListener("pointermove",fe),window.removeEventListener("pointerdown",fe),window.removeEventListener("scroll",q,!0),window.removeEventListener("resize",q),de?.disconnect(),de=null,W&&(cancelAnimationFrame(W),W=0),te=null)}function Gt(e){T=e,De(),Ke(),D=e?t.passthrough??!0:!1,Q=!1,j=null,ne=null,D?ct():ut(),u&&(u.style.pointerEvents=D?"none":"auto")}let Ie=null;function qt(){t.autoPause===!1||typeof IntersectionObserver>"u"||(Ie=new IntersectionObserver(e=>{Ze=!(e[e.length-1]?.isIntersecting??!0),he()}),Ie.observe(A))}let lt=!1;function he(){if(!b)return;let e=Ce||Ze;e!==lt&&(lt=e,b.postMessage(U(e?"xc.pause":"xc.resume")))}function dt(){if(V===null)return;let e=window;e.cancelIdleCallback?e.cancelIdleCallback(V):clearTimeout(V),V=null}function Ft(){if(Se===!1){_();return}if(Se==="click")return;let e=()=>{let n=window;V=n.requestIdleCallback?n.requestIdleCallback(()=>{V=null,_()},{timeout:3e3}):setTimeout(_,1200)};if(typeof IntersectionObserver>"u"){e();return}G=new IntersectionObserver(n=>{n.some(o=>o.isIntersecting)&&(G?.disconnect(),G=null,e())},{rootMargin:`${t.lazyMargin??200}px`}),G.observe(A)}let me=t.draggable===!0,J=$e(t.resizable),ft={move:new se,resize:new se},O=null,H={x:0,y:0},pt=!1,re=null,ht=!1,mt=()=>({width:document.documentElement.clientWidth||window.innerWidth,height:document.documentElement.clientHeight||window.innerHeight}),ge=()=>{let e=A.getBoundingClientRect();return{left:e.left,top:e.top,width:e.width,height:e.height}},gt=()=>({move:me&&X?.gestures?.move===!0,resize:J!==null&&X?.gestures?.resize===!0});function yt(e,n,o){if(o&&(f.width=`${e.width}px`,f.height=`${e.height}px`,f.maxWidth="none"),$==="inline"){let c=n??{left:e.left-H.x,top:e.top-H.y};H={x:e.left-c.left,y:e.top-c.top},f.setProperty("translate",`${H.x}px ${H.y}px`)}else f.left=`${e.left}px`,f.top=`${e.top}px`,f.right="auto",f.bottom="auto";pt=!0,q()}let Y=null;function ye(e){let n=document.documentElement;if(e&&!Y){Y={us:n.style.getPropertyValue("user-select"),wus:n.style.getPropertyValue("-webkit-user-select")},n.style.setProperty("user-select","none"),n.style.setProperty("-webkit-user-select","none");try{window.getSelection()?.removeAllRanges()}catch{}}else!e&&Y&&(n.style.setProperty("user-select",Y.us),n.style.setProperty("-webkit-user-select",Y.wus),Y=null)}function xt(e){if(!O||e&&O.kind!==e)return;ft[O.kind].close();let n=ge();y(O.kind,{phase:"end",...n}),O=null,ye(!1)}function bt(e,n){if(w||!X?.gestures||(e==="move"?!me:J===null))return;let o=Rt(e,n);if(!o||(o.phase==="start"?O!==null:O?.kind!==e)||!ft[e].accept(o))return;if(o.phase==="start"){let h=ge();O={kind:e,start:h,corner:o.corner,inlineBase:$==="inline"?{left:h.left-H.x,top:h.top-H.y}:null},ye(!0),y(e,{phase:"start",...h});return}let c=O,p=mt(),l=e==="move"?Ct(c.start,o.totalDx,o.totalDy,p):kt(c.start,c.corner,o.totalDx,o.totalDy,J,p);yt(l,c.inlineBase,e==="resize"),y(e,{phase:o.phase,...l}),o.phase==="end"&&(O=null,ye(!1))}function Xt(){if(w)return;let e=gt();e.move||xt("move"),e.resize||xt("resize"),!(!b||!X)&&(wt(),!(re&&re.move===e.move&&re.resize===e.resize)&&(re=e,X.gestures&&b.postMessage(U("xc.setConfig",{gestures:e}))))}function wt(){if(ht||!X||X.gestures)return;let e=me;if(!e&&J===null)return;ht=!0;let n=[e?"draggable":"",J!==null?"resizable":""].filter(Boolean).join(" / ");y("error",{code:"unsupported",message:`${n} needs gesture support (capabilities.gestures), which this /embed deployment does not advertise (older version)`,command:"gestures"})}let Pt=()=>{if(!pt||O||w)return;let e=ge(),n=Mt(e,mt());n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height||yt(n,$==="inline"?{left:e.left-H.x,top:e.top-H.y}:null,n.width!==e.width||n.height!==e.height)};window.addEventListener("resize",Pt,{passive:!0}),Ft();let vt={element:A,get iframe(){return u},ready:Ye,activate:_,say:(e,n)=>P("xc.say",{text:e,mode:n?.mode},!0),speakAudio:Ut,speakAudioStream:Bt,motion:e=>P("xc.motion",typeof e=="string"?e.startsWith("http")||e.startsWith("/")?{url:e}:{name:e}:e),expression:e=>P("xc.expression",{name:e}),lookAt:(e,n)=>P("xc.lookAt",{x:e,y:n}),setOutfit:e=>k(e)?P("xc.setOutfit",{id:e},!0,void 0,void 0,"outfits"):Promise.reject(new Error("[bad_request] invalid outfit id")),setScene:e=>k(e)?P("xc.setScene",{id:e},!0,void 0,void 0,"scenes"):Promise.reject(new Error("[bad_request] invalid scene id")),prefetch:e=>e!==void 0&&(!Array.isArray(e)||e.some(n=>!k(n)))?Promise.reject(new Error("[bad_request] prefetch ids must be an array of outfit ids")):P("xc.prefetch",e?{ids:e}:{},!0,void 0,void 0,"prefetch"),getOutfits:async()=>(u||_(),await tt,X?.outfits?X.outfits.slice():[]),getScenes:async()=>(u||_(),await tt,X?.scenes?X.scenes.slice():[]),get outfit(){return Qe},get scene(){return et},setModel:e=>{let n=typeof e=="string"?/^(https?:)?\/|\.vrm/i.test(e)?{url:e}:{outfit:e}:e;if(n.url!==void 0&&n.outfit===void 0&&!t.allowCustomModel){let o="custom model URLs are disabled; pass allowCustomModel: true to createXiaochun() (only for URLs you trust) or use setOutfit() with a built-in id";return y("error",{code:"unsupported",message:o,command:"xc.setModel"}),Promise.reject(new Error(`[unsupported] ${o}`))}return P("xc.setModel",n)},setConfig:e=>P("xc.setConfig",e),setSize(e,n){w||(f.width=ae(e,"320px"),f.height=ae(n,"480px"),q())},getBox:()=>ge(),setBorderRadius(e){Oe=e,Ke()},setDraggable(e){me=e===!0,Xt()},setResizable(e){J=$e(e),Xt()},startListening:()=>P("xc.mic",{enabled:!0}),stopListening:()=>P("xc.mic",{enabled:!1}),mic:e=>P("xc.mic",{enabled:e}),pause(){Ce=!0,he()},resume(){Ce=!1,he()},destroy(){if(!w){try{b?.postMessage(U("xc.destroy"))}catch{}w=!0,dt(),G?.disconnect(),Ie?.disconnect(),K&&clearTimeout(K),W&&cancelAnimationFrame(W),window.removeEventListener("message",it),window.removeEventListener("resize",Pt),ye(!1),ut(),ze();try{b?.close()}catch{}b=null;for(let e of S.values())e.reject(new Error("[project-xiaochun] instance destroyed"));S.clear(),Me.length=0,ke||Je(new Error("[project-xiaochun] destroyed before ready")),A.remove(),u=null,y("destroy",void 0),le.clear()}},on(e,n){let o=le.get(e);return o||(o=new Set,le.set(e,o)),o.add(n),()=>{o.delete(n)}}};return vt}var hn=["src","outfit","scene","model","lang","mic","transparent","draggable","resizable","min-size","max-size","border-radius","position","size","lazy","paused","placeholder","heavy","ui","controls","allowed-origins","cross-origin-isolated","persist","allow-custom-model","prefetch"],mn=new Set(["src","position","lazy","placeholder","heavy","ui","controls","allowed-origins","transparent","cross-origin-isolated","persist","allow-custom-model","prefetch"]);function zt(t){if(t===null||t.trim()==="")return;let r=t.trim();return/^\d+(\.\d+)?$/.test(r)?Number(r):r}function M(t,r,s){let i=t.getAttribute(r);return i===null?s:i!=="false"}function gn(t){return t===null||t==="false"?!1:t===""||t==="true"?!0:t.split(",").map(r=>r.trim()).filter(Boolean)}function yn(t){if(!(t===null||t==="false"||t==="0"))return t===""||t==="true"||t==="1"?!0:t.split(",").map(r=>r.trim()).filter(Boolean)}function Lt(t){let r=t?.trim().match(/^(\d+(?:\.\d+)?)\s*x\s*(\d+(?:\.\d+)?)$/i);return r?{w:Number(r[1]),h:Number(r[2])}:void 0}function It(t){if(!t)return{width:"320px",height:"480px"};let r=t.trim().split(/x/i),s=a=>/^\d+(\.\d+)?$/.test(a)?`${a}px`:a;if(r.length>=2)return{width:s(r[0]),height:s(r[1])};let i=parseFloat(r[0]);return Number.isFinite(i)&&/^\d+(\.\d+)?$/.test(r[0])?{width:`${i}px`,height:`${Math.round(i*1.5)}px`}:{width:r[0],height:"480px"}}function xn(){class t extends HTMLElement{constructor(){super(...arguments);this.client=null;this.mountEl=null;this.rebuildScheduled=!1}static get observedAttributes(){return[...hn]}connectedCallback(){if(!this.shadowRoot){let i=this.attachShadow({mode:"open"});i.innerHTML='<style>:host{display:inline-block;max-width:100%}:host([hidden]){display:none}</style><div part="mount"></div>'}this.mountEl=this.shadowRoot.querySelector("div"),this.build()}disconnectedCallback(){this.destroy()}attributeChangedCallback(i,a,m){if(!this.client||a===m)return;if(mn.has(i)){this.rebuildScheduled||(this.rebuildScheduled=!0,queueMicrotask(()=>{this.rebuildScheduled=!1,this.isConnected&&(this.destroy(),this.build())}));return}let d=this.client;if((i==="outfit"||i==="model")&&m){let g=i==="model"&&this.hasAttribute("outfit")?null:m;g&&(k(g)?d.setOutfit(g):d.setModel(g)).catch(()=>{})}else if(i==="scene"&&m)d.setScene(m).catch(()=>{});else if(i==="lang"&&m)d.setConfig({lang:m}).catch(()=>{});else if(i==="size"){let{width:g,height:R}=It(m);d.setSize(g,R)}else i==="border-radius"?d.setBorderRadius(zt(m)):i==="draggable"?d.setDraggable(M(this,"draggable",!1)):i==="resizable"||i==="min-size"||i==="max-size"?d.setResizable(this.resizableOption()):i==="mic"?d.mic(M(this,"mic",!1)).catch(()=>{}):i==="paused"&&(M(this,"paused",!1)?d.pause():d.resume())}build(){if(!this.mountEl||this.client)return;let{width:i,height:a}=It(this.getAttribute("size")),m=this.getAttribute("placeholder"),d=this.getAttribute("allowed-origins"),g=this.getAttribute("lazy"),R=g==="click"?"click":g!=="false",E=ve({container:this.mountEl,src:this.getAttribute("src")||void 0,allowedOrigins:d?d.split(",").map(B=>B.trim()).filter(Boolean):void 0,lazy:R,placeholder:m==="none"?!1:m||void 0,transparent:M(this,"transparent",!0),width:i,height:a,position:this.getAttribute("position")??"inline",draggable:M(this,"draggable",!1),resizable:this.resizableOption(),borderRadius:zt(this.getAttribute("border-radius")),lang:this.getAttribute("lang")??void 0,outfit:this.getAttribute("outfit")??this.getAttribute("model")??void 0,scene:this.getAttribute("scene")??void 0,persist:this.getAttribute("persist")||void 0,allowCustomModel:M(this,"allow-custom-model",!1),prefetch:gn(this.getAttribute("prefetch")),heavy:this.getAttribute("heavy")??void 0,ui:yn(this.getAttribute("ui")),controls:M(this,"controls",!0),crossOriginIsolated:M(this,"cross-origin-isolated",!1)});this.client=E;let x=(B,ce)=>E.on(B,F=>this.dispatchEvent(new CustomEvent(ce,{detail:F,bubbles:!0,composed:!0})));x("ready","xc-ready"),x("progress","xc-progress"),x("state","xc-state"),x("stt","xc-stt"),x("utterance","xc-utterance"),x("error","xc-error"),x("outfit-changed","xc-outfit-changed"),x("scene-changed","xc-scene-changed"),x("move","xc-move"),x("resize","xc-resize"),M(this,"paused",!1)&&E.pause(),M(this,"mic",!1)&&E.ready.then(()=>E.mic(!0)).catch(()=>{})}resizableOption(){if(!M(this,"resizable",!1))return!1;let i=Lt(this.getAttribute("min-size")),a=Lt(this.getAttribute("max-size"));return{minWidth:i?.w,minHeight:i?.h,maxWidth:a?.w,maxHeight:a?.h}}say(i,a){return this.requireClient().say(i,a)}speakAudio(i,a){return this.requireClient().speakAudio(i,a)}speakAudioStream(i){return this.requireClient().speakAudioStream(i)}motion(i){return this.requireClient().motion(i)}expression(i){return this.requireClient().expression(i)}setOutfit(i){return this.requireClient().setOutfit(i)}setScene(i){return this.requireClient().setScene(i)}getOutfits(){return this.requireClient().getOutfits()}getScenes(){return this.requireClient().getScenes()}prefetch(i){return this.requireClient().prefetch(i)}destroy(){this.client?.destroy(),this.client=null}requireClient(){if(!this.client)throw new Error("<xiaochun-avatar> is not connected");return this.client}}return t}var Ge="xiaochun-avatar";function Ee(t=Ge){if(typeof customElements>"u"||typeof HTMLElement>"u")return null;let r=customElements.get(t);if(r)return r;let s=xn();return customElements.define(t,s),s}var Ae="xiaochun";function Tt(t){if(t.action!=="speak")throw new Error(`[project-xiaochun] unsupported action: ${String(t.action)}`);if(!t.text&&!t.audioUrl&&!t.file)throw new Error("[project-xiaochun] speak needs text, audioUrl or file");if(t.audioUrl&&!/^https?:\/\//i.test(t.audioUrl))throw new Error("[project-xiaochun] audioUrl must be http(s)");let r=new URLSearchParams;return t.text&&r.set("text",t.text),t.audioUrl&&r.set("audioUrl",t.audioUrl),t.file&&r.set("file",t.file),`${Ae}://speak?${r.toString().replace(/\+/g,"%20")}`}function _t(t){let r;try{r=new URL(t)}catch{return null}if(r.protocol!==`${Ae}:`)return null;let s=r.hostname||r.pathname.replace(/^\/+/,"");if((s==="action"?r.searchParams.get("action"):s)!=="speak")return null;let a={action:"speak"},m=r.searchParams.get("text"),d=r.searchParams.get("audioUrl"),g=r.searchParams.get("file");return m&&(a.text=m),d&&(a.audioUrl=d),g&&(a.file=g),a.text||a.audioUrl||a.file?a:null}Ee();var qe=document.currentScript;if(qe&&qe.hasAttribute("data-auto")){let t=()=>{let r=document.createElement("xiaochun-avatar");for(let s of Array.from(qe.attributes))s.name.startsWith("data-")&&s.name!=="data-auto"&&r.setAttribute(s.name.slice(5),s.value);r.hasAttribute("position")||r.setAttribute("position","bottom-right"),document.body.appendChild(r)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}return Zt(bn);})();
|
|
3
3
|
//# sourceMappingURL=loader.global.js.map
|