@firetable/project-xiaochun 0.1.15 → 0.1.16
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 +24 -14
- package/README.md +24 -14
- package/dist/avatar-element.d.ts +10 -4
- package/dist/chunks/{chunk-T6EHFEEZ.js → chunk-HZ2ADKG7.js} +39 -8
- package/dist/chunks/chunk-HZ2ADKG7.js.map +7 -0
- package/dist/chunks/{chunk-KKRZ3SUD.js → chunk-RHQW4QZH.js} +86 -3
- package/dist/chunks/chunk-RHQW4QZH.js.map +7 -0
- package/dist/chunks/{chunk-KQSKHPVF.js → chunk-UWL65W7D.js} +136 -10
- package/dist/chunks/chunk-UWL65W7D.js.map +7 -0
- package/dist/client.d.ts +64 -5
- package/dist/element.cjs +206 -12
- package/dist/element.cjs.map +2 -2
- package/dist/element.js +4 -4
- package/dist/index.cjs +247 -13
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/dist/loader.global.js +2 -2
- package/dist/loader.global.js.map +3 -3
- package/dist/protocol.cjs +86 -3
- package/dist/protocol.cjs.map +2 -2
- package/dist/protocol.d.ts +104 -3
- package/dist/protocol.js +18 -4
- package/dist/react.cjs +190 -14
- package/dist/react.cjs.map +2 -2
- package/dist/react.d.ts +6 -0
- package/dist/react.js +23 -9
- package/dist/react.js.map +2 -2
- package/package.json +2 -2
- package/dist/chunks/chunk-KKRZ3SUD.js.map +0 -7
- package/dist/chunks/chunk-KQSKHPVF.js.map +0 -7
- package/dist/chunks/chunk-T6EHFEEZ.js.map +0 -7
package/dist/index.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
/*! @firetable/project-xiaochun v0.1.
|
|
1
|
+
/*! @firetable/project-xiaochun v0.1.16 | 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-HZ2ADKG7.js";
|
|
6
6
|
import {
|
|
7
7
|
createXiaochun
|
|
8
|
-
} from "./chunks/chunk-
|
|
8
|
+
} from "./chunks/chunk-UWL65W7D.js";
|
|
9
9
|
import {
|
|
10
|
+
XC_CAMERA_RANGES,
|
|
10
11
|
XC_DEFAULT_ORIGIN,
|
|
11
12
|
XC_DEFAULT_SRC,
|
|
12
13
|
XC_FRAME_TO_HOST,
|
|
13
14
|
XC_HOST_TO_FRAME,
|
|
14
15
|
XC_ID_RE,
|
|
15
16
|
XC_IMPLEMENTED_COMMANDS,
|
|
17
|
+
XC_LANGS,
|
|
16
18
|
XC_PROTOCOL_MAPPING,
|
|
17
19
|
XC_PROTOCOL_VERSION,
|
|
20
|
+
XC_UI_AUTOHIDE_DEFAULT,
|
|
18
21
|
XC_UI_LEGACY_PARTS,
|
|
19
22
|
XC_UI_PARTS,
|
|
20
23
|
XC_UNSUPPORTED_COMMANDS,
|
|
@@ -22,12 +25,16 @@ import {
|
|
|
22
25
|
isXcEnvelope,
|
|
23
26
|
isXcId,
|
|
24
27
|
normalizeOrigin,
|
|
28
|
+
normalizeXcCamera,
|
|
25
29
|
normalizeXcUiOption,
|
|
30
|
+
parseXcCameraParams,
|
|
31
|
+
parseXcUiAutoHide,
|
|
26
32
|
parseXcUiList,
|
|
27
33
|
parseXcUiParam,
|
|
28
34
|
xcHasOwn,
|
|
29
|
-
xcMessage
|
|
30
|
-
|
|
35
|
+
xcMessage,
|
|
36
|
+
xcUiAutoHideActive
|
|
37
|
+
} from "./chunks/chunk-RHQW4QZH.js";
|
|
31
38
|
|
|
32
39
|
// src/protocol-url.ts
|
|
33
40
|
var XIAOCHUN_PROTOCOL_SCHEME = "xiaochun";
|
|
@@ -62,14 +69,17 @@ function parseProtocolUrl(url) {
|
|
|
62
69
|
return out.text || out.audioUrl || out.file ? out : null;
|
|
63
70
|
}
|
|
64
71
|
export {
|
|
72
|
+
XC_CAMERA_RANGES,
|
|
65
73
|
XC_DEFAULT_ORIGIN,
|
|
66
74
|
XC_DEFAULT_SRC,
|
|
67
75
|
XC_FRAME_TO_HOST,
|
|
68
76
|
XC_HOST_TO_FRAME,
|
|
69
77
|
XC_ID_RE,
|
|
70
78
|
XC_IMPLEMENTED_COMMANDS,
|
|
79
|
+
XC_LANGS,
|
|
71
80
|
XC_PROTOCOL_MAPPING,
|
|
72
81
|
XC_PROTOCOL_VERSION,
|
|
82
|
+
XC_UI_AUTOHIDE_DEFAULT,
|
|
73
83
|
XC_UI_LEGACY_PARTS,
|
|
74
84
|
XC_UI_PARTS,
|
|
75
85
|
XC_UNSUPPORTED_COMMANDS,
|
|
@@ -81,12 +91,16 @@ export {
|
|
|
81
91
|
isXcEnvelope,
|
|
82
92
|
isXcId,
|
|
83
93
|
normalizeOrigin,
|
|
94
|
+
normalizeXcCamera,
|
|
84
95
|
normalizeXcUiOption,
|
|
85
96
|
parseProtocolUrl,
|
|
97
|
+
parseXcCameraParams,
|
|
98
|
+
parseXcUiAutoHide,
|
|
86
99
|
parseXcUiList,
|
|
87
100
|
parseXcUiParam,
|
|
88
101
|
toProtocolUrl,
|
|
89
102
|
xcHasOwn,
|
|
90
|
-
xcMessage
|
|
103
|
+
xcMessage,
|
|
104
|
+
xcUiAutoHideActive
|
|
91
105
|
};
|
|
92
106
|
//# 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 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);})();
|
|
1
|
+
/*! @firetable/project-xiaochun v0.1.16 | MIT | https://github.com/FireTable/project-xiaochun */
|
|
2
|
+
"use strict";var Xiaochun=(()=>{var Ke=Object.defineProperty;var dn=Object.getOwnPropertyDescriptor;var fn=Object.getOwnPropertyNames;var pn=Object.prototype.hasOwnProperty;var hn=(t,r)=>{for(var a in r)Ke(t,a,{get:r[a],enumerable:!0})},mn=(t,r,a,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of fn(r))!pn.call(t,s)&&s!==a&&Ke(t,s,{get:()=>r[s],enumerable:!(i=dn(r,s))||i.enumerable});return t};var gn=t=>mn(Ke({},"__esModule",{value:!0}),t);var Nn={};hn(Nn,{XC_CAMERA_RANGES:()=>V,XC_DEFAULT_ORIGIN:()=>Bt,XC_DEFAULT_SRC:()=>Ve,XC_FRAME_TO_HOST:()=>bn,XC_HOST_TO_FRAME:()=>xn,XC_ID_RE:()=>Nt,XC_IMPLEMENTED_COMMANDS:()=>Xn,XC_LANGS:()=>Mn,XC_PROTOCOL_MAPPING:()=>vn,XC_PROTOCOL_VERSION:()=>yn,XC_UI_AUTOHIDE_DEFAULT:()=>En,XC_UI_LEGACY_PARTS:()=>Je,XC_UI_PARTS:()=>pe,XC_UNSUPPORTED_COMMANDS:()=>wn,XC_WINDOW_CORNER_RADIUS:()=>Ye,XIAOCHUN_ELEMENT_TAG:()=>st,XIAOCHUN_PROTOCOL_SCHEME:()=>ze,createXiaochun:()=>Re,defineXiaochunElement:()=>Le,isXcEnvelope:()=>Ee,isXcId:()=>T,normalizeOrigin:()=>Se,normalizeXcCamera:()=>et,normalizeXcUiOption:()=>Qe,parseProtocolUrl:()=>Jt,parseXcCameraParams:()=>Cn,parseXcUiAutoHide:()=>he,parseXcUiList:()=>Ze,parseXcUiParam:()=>An,toProtocolUrl:()=>Yt,xcHasOwn:()=>kn,xcMessage:()=>N,xcUiAutoHideActive:()=>Sn});var yn=1,Bt="https://xiaochun.firetable.tech",Ve=`${Bt}/embed`,xn=["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"],bn=["xc.ready","xc.load.progress","xc.loaded","xc.outfit-changed","xc.scene-changed","xc.lang-changed","xc.prefetched","xc.state","xc.stt","xc.utterance","xc.hit-region","xc.gesture-move","xc.gesture-resize","xc.error"],Xn=["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"],wn=["xc.lookAt"],vn=[{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}],Ye=20,pe=["chat","bubble","outfit","scene","lang","github"],Pn=new Set(pe),Je=["chat","bubble"];function Ze(t){let r=new Set,a=[];for(let i of t){let s=typeof i=="string"?i.trim().toLowerCase():"";Pn.has(s)?r.add(s):a.push(typeof i=="string"?i.slice(0,40):typeof i)}return{parts:pe.filter(i=>r.has(i)),unknown:a,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:[...Je],unknown:[],legacy:!0}:Ze(r.split(",").filter(a=>a.trim()!==""))}function Qe(t){return t===!0?{parts:[...Je],unknown:[],legacy:!0}:Array.isArray(t)?Ze(t):{parts:[],unknown:[],legacy:!1}}var En="transparent";function he(t){if(t===!0||t===!1||t==="transparent")return t;if(typeof t!="string")return;let r=t.trim().toLowerCase();if(r==="1"||r==="true")return!0;if(r==="0"||r==="false")return!1;if(r==="transparent")return"transparent"}function Sn(t,r){return t==="transparent"?r:t}var V={fov:[15,60],distance:[1,15],height:[-1,1]},$t=["fov","distance","height"],Ut=["fov","distance","height","intro"];function et(t){if(t===null||typeof t!="object"||Array.isArray(t))return{ok:!1,error:"camera must be an object"};let r=t;for(let s of Object.keys(r))if(!Ut.includes(s))return{ok:!1,error:`unknown camera key: ${s} (expected ${Ut.join(" | ")})`};let a={},i=[];for(let s of $t){let u=r[s];if(u===void 0)continue;if(u===null){a[s]=null;continue}if(typeof u!="number"||!Number.isFinite(u))return{ok:!1,error:`camera.${s} must be a finite number or null`};let[d,g]=V[s],X=Math.min(g,Math.max(d,u));X!==u&&i.push(s),a[s]=X}if(r.intro!==void 0){if(r.intro!==null&&typeof r.intro!="boolean")return{ok:!1,error:"camera.intro must be a boolean or null"};a.intro=r.intro}return{ok:!0,camera:a,clamped:i}}function Cn(t){let r={},a=[],i={fov:"cameraFov",distance:"cameraDistance",height:"cameraHeight"};for(let u of $t){let d=t(i[u]);if(d===null)continue;let g=d.trim(),X=g===""?NaN:Number(g);if(!Number.isFinite(X)){a.push(`ignoring invalid ?${i[u]}=${d}`);continue}let[S,y]=V[u],z=Math.min(y,Math.max(S,X));z!==X&&a.push(`?${i[u]}=${d} is out of range [${S}, ${y}], clamped to ${z}`),r[u]=z}let s=t("cameraIntro");if(s!==null){let u=s.trim().toLowerCase();u==="1"||u==="true"?r.intro=!0:u==="0"||u==="false"?r.intro=!1:a.push(`ignoring invalid ?cameraIntro=${s}`)}return{camera:r,warnings:a}}var Nt=/^[a-z][a-z0-9_]{0,63}$/,T=t=>typeof t=="string"&&Nt.test(t),kn=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),Mn=["zh-CN","en","ja"];function N(t,r,a){let i={type:t,v:1,payload:r};return a!==void 0&&(i.id=a),i}function Ee(t){if(!t||typeof t!="object")return!1;let r=t;return typeof r.type=="string"&&r.type.startsWith("xc.")&&r.v===1}function Se(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 Me=Object.freeze({minWidth:120,minHeight:180,maxWidth:1/0,maxHeight:1/0}),Ce=t=>typeof t=="number"&&Number.isFinite(t)&&t>0;function tt(t){if(!t)return null;let r=t===!0?{}:t,a=Ce(r.minWidth)?r.minWidth:Me.minWidth,i=Ce(r.minHeight)?r.minHeight:Me.minHeight,s=Ce(r.maxWidth)?Math.max(r.maxWidth,a):1/0,u=Ce(r.maxHeight)?Math.max(r.maxHeight,i):1/0;return{minWidth:a,minHeight:i,maxWidth:s,maxHeight:u}}var oe=(t,r,a)=>Math.min(Math.max(t,r),Math.max(r,a));function Wt(t,r,a,i){return{left:oe(t.left+r,0,i.width-t.width),top:oe(t.top+a,0,i.height-t.height),width:t.width,height:t.height}}function Ft(t,r,a,i,s,u){let d=r==="NW"||r==="SW",g=r==="NW"||r==="NE",X=t.left+t.width,S=t.top+t.height,y=d?t.width-a:t.width+a,z=g?t.height-i:t.height+i,D=d?X:u.width-t.left,M=g?S:u.height-t.top,Ie=oe(y,s.minWidth,Math.min(s.maxWidth,D)),ie=oe(z,s.minHeight,Math.min(s.maxHeight,M));return{left:d?X-Ie:t.left,top:g?S-ie:t.top,width:Ie,height:ie}}function Oe(t,r){let a=Math.min(t.width,Math.max(1,r.width)),i=Math.min(t.height,Math.max(1,r.height));return{left:oe(t.left,0,r.width-a),top:oe(t.top,0,r.height-i),width:a,height:i}}var On=new Set(["NW","NE","SW","SE"]),Rn=new Set(["start","move","end"]),Ln=new Set(["up","cancel","blur"]),zn=2e4,ke=t=>typeof t=="number"&&Number.isFinite(t)&&Math.abs(t)<=zn,jt=t=>typeof t=="number"&&Number.isSafeInteger(t)&&t>=0;function Gt(t,r){if(r===null||typeof r!="object")return null;let a=r;if(!jt(a.gesture)||!jt(a.seq)||typeof a.phase!="string"||!Rn.has(a.phase)||!ke(a.dx)||!ke(a.dy)||!ke(a.totalDx)||!ke(a.totalDy)||a.reason!==void 0&&(typeof a.reason!="string"||!Ln.has(a.reason)))return null;let i={gesture:a.gesture,seq:a.seq,phase:a.phase,totalDx:a.totalDx,totalDy:a.totalDy};if(t==="resize"){if(typeof a.corner!="string"||!On.has(a.corner))return null;i.corner=a.corner}return i}var me=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 In="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>'),nt=t=>{t.setProperty("user-select","none"),t.setProperty("-webkit-user-select","none"),t.setProperty("-webkit-touch-callout","none"),t.setProperty("-webkit-tap-highlight-color","transparent")},Y=(t,r)=>t===void 0?r:typeof t=="number"?`${t}px`:t,it=600,at=1080,rt=(t=!1)=>t?`min(${it}px, calc(100vw - 2 * var(--xc-offset-x, 16px)))`:`min(${it}px, 100vw)`,ot=(t=!1)=>{let r=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("height","1svh")?"svh":"vh";return t?`min(${at}px, calc(100${r} - 2 * var(--xc-offset-y, 16px)))`:`min(${at}px, 100${r})`};function Re(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 a=t.src??Ve,i;try{i=new URL(a,window.location.href)}catch{throw new Error(`[project-xiaochun] invalid src: ${a}`)}let s=Se(t.origin??i.origin);if(!s)throw new Error("[project-xiaochun] invalid origin (wildcards are not allowed)");let u=new Set([s]);for(let e of t.allowedOrigins??[]){let n=Se(e);if(!n)throw new Error(`[project-xiaochun] invalid allowedOrigins entry: ${e} (wildcards are not allowed)`);u.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"&&(T(e.outfit)&&(n.outfit=e.outfit),T(e.scene)&&(n.scene=e.scene)),n}catch{return{}}},X=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{}},S=g();t.model!==void 0&&t.outfit===void 0&&console.warn('[project-xiaochun] option "model" is deprecated, use "outfit" (built-in outfit id).');let y=Qe(t.ui),z=y.parts,D=he(t.uiAutoHide);t.uiAutoHide!==void 0&&D===void 0&&console.warn(`[project-xiaochun] ignoring invalid uiAutoHide: ${String(t.uiAutoHide)} (use true | false | 'transparent')`);let M={};if(t.camera!==void 0){let e=et(t.camera);e.ok?(M=e.camera,e.clamped.length&&console.warn(`[project-xiaochun] camera.${e.clamped.join(", camera.")} out of range, clamped (fov ${V.fov.join("\u2013")}, distance ${V.distance.join("\u2013")}, height ${V.height.join("\u2013")})`)):console.warn(`[project-xiaochun] ignoring invalid camera option: ${e.error}`)}y.legacy&&console.warn(`[project-xiaochun] option "ui: true" is deprecated, use an array of parts, e.g. ui: ['chat', 'bubble', 'outfit', 'scene'].`),y.unknown.length&&console.warn(`[project-xiaochun] ignoring unknown ui part(s): ${y.unknown.join(", ")} (known: ${pe.join(", ")})`);let ie=t.outfit??(T(t.model)?t.model:void 0)??S.outfit,J=t.scene??S.scene??(t.transparent?"transparent":void 0),Z=J==="transparent"||J!=="light"&&J!=="dark"&&(t.transparent??!1),Q=t.passthrough??Z,He=t.lazy??!0,x=t.position??"inline",ut=t.handshakeTimeout??2e4,I=document.createElement("div");I.setAttribute("data-xiaochun","");let l=I.style;l.position=x==="inline"?"relative":"fixed",l.width=Y(t.width,rt(x!=="inline")),l.height=Y(t.height,ot(x!=="inline")),l.maxWidth="100%",l.overflow="visible",l.contain="layout style",nt(l),l.boxShadow="var(--xc-shadow, none)";let lt=()=>{l.background=Z?"":"var(--xc-bg, transparent)"};lt();let _e=t.borderRadius,ge=()=>_e!==void 0?Y(_e,"0px"):Z?"0px":`${Ye}px`,dt=()=>{let e=`var(--xc-radius, ${ge()})`;l.borderRadius=e,O&&(O.style.borderRadius=e),m&&(m.style.borderRadius=e)};l.borderRadius=`var(--xc-radius, ${ge()})`,x==="bottom-right"&&(l.right="var(--xc-offset-x, 16px)",l.bottom="var(--xc-offset-y, 16px)"),x==="bottom-left"&&(l.left="var(--xc-offset-x, 16px)",l.bottom="var(--xc-offset-y, 16px)"),x!=="inline"&&(l.zIndex=`var(--xc-z-index, ${t.zIndex??2147483e3})`),l.pointerEvents="none",I.setAttribute("part","wrapper"),r.appendChild(I);let O=null;if(t.placeholder!==!1){if(t.placeholder instanceof HTMLElement)O=t.placeholder;else{let n=document.createElement("img");n.src=t.placeholder||In,n.alt="Project XiaoChun",n.decoding="async",n.width=it,n.height=at,O=n}let e=O.style;O.setAttribute("part","placeholder"),e.borderRadius=`var(--xc-radius, ${ge()})`,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=He===!1?"default":"pointer",nt(e),O.addEventListener("click",()=>$()),I.appendChild(O)}let ye=new Map,b=(e,n)=>{ye.get(e)?.forEach(o=>{try{o(n)}catch(c){console.error("[project-xiaochun] listener error",c)}})},ft,pt,ht=new Promise((e,n)=>{ft=e,pt=n});ht.catch(()=>{});let m=null,w=null,v=!1,Te=!1,mt=!1,Ue=!1,ae=!1,P=null,gt=null,yt=null,Be=[],H=new Map,$e=0,ee=null,q=null,te=null,Ne,xt=new Promise(e=>{Ne=e}),Zt=(e,n,o,c)=>{b("error",{code:o,message:c,command:e});let p=n?H.get(n):void 0;p&&n&&(H.delete(n),p.reject(new Error(`[${o}] ${c}`)))},bt=(e,n)=>Zt(e,n,"unsupported",`${e} is not supported by this /embed deployment (older version; its xc.ready has no capabilities for it)`),se=(e,n,o,c,p)=>{if(!w){Be.push({type:e,payload:n,id:o,transfer:c,requires:p});return}if(p&&!P?.[p]){bt(e,o);return}w.postMessage(N(e,n,o),c??[])},C=(e,n,o=!1,c,p,f)=>{if(v)return Promise.reject(new Error("[project-xiaochun] instance destroyed"));m||$();let h=p??`c${++$e}`,A=o?new Promise((L,k)=>H.set(h,{resolve:L,reject:k,sawEnd:!1})):Promise.resolve();return se(e,n,h,c,f),A},Xt=e=>e instanceof ArrayBuffer?e:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),wt=(e,n)=>{if(!e)return;let o=()=>{v||se("xc.audio.end",{abort:!0},n)};e.aborted?o():e.addEventListener("abort",o,{once:!0})},Qt=async(e,n={})=>{if(v)throw new Error("[project-xiaochun] instance destroyed");m||$();let{signal:o,transfer:c,fetch:p,...f}=n,h={...f},A=[];if(typeof e=="string")if(p==="frame")h.source=e;else{let E=await fetch(e);if(!E.ok)throw new Error(`[project-xiaochun] audio fetch failed: HTTP ${E.status}`);let K=await E.arrayBuffer();h.source=K,A.push(K),h.mimeType??(h.mimeType=E.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 E=Xt(e);h.source=E,(!(e instanceof ArrayBuffer)||c!==!1)&&A.push(E)}if(v)throw new Error("[project-xiaochun] instance destroyed");let L=`c${++$e}`,k=C("xc.audio",h,!0,A,L);return wt(o,L),k},en=e=>{if(v)throw new Error("[project-xiaochun] instance destroyed");let{signal:n,transfer:o,fetch:c,mimeType:p,...f}=e,h=`c${++$e}`,A=!1,L=!1,k=f.format==="pcm16"||f.format==="float32"?f.format:null,E=Promise.resolve();return{write(Ae){if(L)throw new Error("[project-xiaochun] audio stream already ended");if(v)throw new Error("[project-xiaochun] instance destroyed");if(Ae instanceof Int16Array?k??(k="pcm16"):Ae instanceof Float32Array&&(k??(k="float32")),!k)throw new Error("[project-xiaochun] speakAudioStream: set opts.format when writing raw ArrayBuffers");let qe=Xt(Ae),fe={data:qe,format:k,sampleRate:f.sampleRate,channels:f.channels};A?se("xc.audio.chunk",fe,h,!(Ae instanceof ArrayBuffer)||o!==!1?[qe]:[]):(A=!0,fe.text=f.text,fe.motion=f.motion,fe.lipsync=f.lipsync,E=C("xc.audio.chunk",fe,!0,[qe],h),wt(n,h))},end(){L||(L=!0,A&&se("xc.audio.end",{},h))},abort(){L&&!A||(L=!0,A&&se("xc.audio.end",{abort:!0},h))},get done(){return E}}};function tn(){let e=new URL(i.href);return e.searchParams.set("host",window.location.origin),Z&&e.searchParams.set("transparent","1"),z.length&&e.searchParams.set("ui",z.join(",")),t.lang&&e.searchParams.set("lang",t.lang),D!==void 0&&e.searchParams.set("uiAutoHide",String(D)),typeof M.fov=="number"&&e.searchParams.set("cameraFov",String(M.fov)),typeof M.distance=="number"&&e.searchParams.set("cameraDistance",String(M.distance)),typeof M.height=="number"&&e.searchParams.set("cameraHeight",String(M.height)),typeof M.intro=="boolean"&&e.searchParams.set("cameraIntro",M.intro?"1":"0"),t.heavy&&e.searchParams.set("heavy",t.heavy),t.controls===!1&&e.searchParams.set("controls","0"),J&&T(J)&&e.searchParams.set("scene",J),ie&&e.searchParams.set("outfit",ie),e.href}function $(){if(v||m)return;kt(),q?.disconnect(),q=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, ${ge()})`,e.setAttribute("part","iframe"),nt(n),n.opacity="0",n.transition="opacity .25s ease",n.pointerEvents=Q?"none":"auto",e.src=tn(),m=e,I.appendChild(e),O&&(O.style.cursor="default"),ee=setTimeout(()=>{w||b("error",{code:"timeout",message:`no xc.ready from ${s} within ${ut}ms`})},ut),sn(),Q&&Et()}let vt=e=>{if(v||!m||e.source!==m.contentWindow)return;if(!u.has(e.origin)){b("error",{code:"origin_denied",message:`ignored message from untrusted origin ${e.origin}`});return}let n=e.data;if(!Ee(n)||n.type!=="xc.ready"||w)return;let o=new MessageChannel;w=o.port1,w.onmessage=nn,P=n.payload?.capabilities??null;let c=Rt();de=c;let p={...t.allowCustomModel?{allowCustomModel:!0}:{},...c.move||c.resize?{gestures:c}:{}};m.contentWindow.postMessage(N("xc.init",{hostOrigin:window.location.origin,...Object.keys(p).length?{config:p}:{}}),e.origin,[o.port2]),It(),ee&&(clearTimeout(ee),ee=null),b("handshake",n.payload),Ne();for(let f of Be.splice(0))f.requires&&!P?.[f.requires]?bt(f.type,f.id):w.postMessage(N(f.type,f.payload,f.id),f.transfer??[]);we()};window.addEventListener("message",vt);function je(e,n){let o=e?H.get(e):void 0;o&&e&&(H.delete(e),o.resolve(n))}function nn(e){let n=e.data;if(Ee(n))switch(n.type){case"xc.load.progress":b("progress",n.payload);break;case"xc.loaded":if(!Ue){if(Ue=!0,t.prefetch&&t.heavy==="eager"&&P?.prefetch){let o=Array.isArray(t.prefetch)?t.prefetch:void 0;Tt.prefetch(o).catch(()=>{})}if(m&&(m.style.opacity="1"),O){let o=O;o.style.opacity="0",o.style.pointerEvents="none",setTimeout(()=>o.remove(),300),O=null}ft()}b("ready",n.payload);break;case"xc.outfit-changed":{let o=n.payload;o.noop||(gt=o.id,b("outfit-changed",o),!o.initial&&o.id&&X({outfit:o.id})),je(n.id);break}case"xc.scene-changed":{let o=n.payload;yt=o.id,o.transparent!==Z&&an(o.transparent),o.noop||(b("scene-changed",o),o.initial||X({scene:o.id})),je(n.id);break}case"xc.lang-changed":b("lang-changed",n.payload);break;case"xc.prefetched":je(n.id,n.payload);break;case"xc.state":b("state",n.payload);break;case"xc.stt":b("stt",n.payload);break;case"xc.utterance":{b("utterance",n.payload);let o=n.id?H.get(n.id):void 0;o&&n.payload.phase==="end"&&(H.delete(n.id),o.resolve());break}case"xc.hit-region":{let{hit:o}=n.payload;b("hit-region",n.payload),Q&&m&&o!==ae&&(ae=o,m.style.pointerEvents=o?"auto":"none");break}case"xc.gesture-move":Lt("move",n.payload);break;case"xc.gesture-resize":Lt("resize",n.payload);break;case"xc.error":{let{code:o,message:c,command:p}=n.payload;b("error",{code:o,message:c,command:p}),o==="unknown_id"&&(p==="outfit"||p==="scene")&&X({[p]:null});let f=n.id?H.get(n.id):void 0;f&&n.id&&(H.delete(n.id),f.reject(new Error(`[${o}] ${c}`)));break}default:break}}let rn=32,Pt=2,j=0,ce=null,W=null,ue=null,xe=null,At=0,F=()=>{ue=null},on=()=>{if(!m)return null;let e=performance.now();return(!ue||e-At>400)&&(ue=m.getBoundingClientRect(),At=e),ue},be=e=>{!m||!w||m.style.pointerEvents==="auto"||(ce={x:e.clientX,y:e.clientY},!j&&(j=requestAnimationFrame(()=>{if(j=0,!m||!w||!ce)return;let n=on();if(!n)return;let o=ce.x-n.left,c=ce.y-n.top;if(o<0||c<0||o>n.width||c>n.height){W=null,ae&&(ae=!1,m.style.pointerEvents="none");return}let p=performance.now();W&&p-W.t<rn||W&&Math.abs(o-W.x)<Pt&&Math.abs(c-W.y)<Pt||(W={x:o,y:c,t:p},w.postMessage(N("xc.pointer",{x:o,y:c})))})))},Xe=!1;function Et(){Xe||!m||(Xe=!0,window.addEventListener("pointermove",be,{passive:!0}),window.addEventListener("pointerdown",be,{passive:!0}),window.addEventListener("scroll",F,{passive:!0,capture:!0}),window.addEventListener("resize",F,{passive:!0}),typeof ResizeObserver<"u"&&(xe=new ResizeObserver(F),xe.observe(m)))}function St(){Xe&&(Xe=!1,window.removeEventListener("pointermove",be),window.removeEventListener("pointerdown",be),window.removeEventListener("scroll",F,!0),window.removeEventListener("resize",F),xe?.disconnect(),xe=null,j&&(cancelAnimationFrame(j),j=0),ce=null)}function an(e){Z=e,lt(),dt(),Q=e?t.passthrough??!0:!1,ae=!1,W=null,ue=null,Q?Et():St(),m&&(m.style.pointerEvents=Q?"none":"auto")}let We=null;function sn(){t.autoPause===!1||typeof IntersectionObserver>"u"||(We=new IntersectionObserver(e=>{mt=!(e[e.length-1]?.isIntersecting??!0),we()}),We.observe(I))}let Ct=!1;function we(){if(!w)return;let e=Te||mt;e!==Ct&&(Ct=e,w.postMessage(N(e?"xc.pause":"xc.resume")))}function kt(){if(te===null)return;let e=window;e.cancelIdleCallback?e.cancelIdleCallback(te):clearTimeout(te),te=null}function cn(){if(He===!1){$();return}if(He==="click")return;let e=()=>{let n=window;te=n.requestIdleCallback?n.requestIdleCallback(()=>{te=null,$()},{timeout:3e3}):setTimeout($,1200)};if(typeof IntersectionObserver>"u"){e();return}q=new IntersectionObserver(n=>{n.some(o=>o.isIntersecting)&&(q?.disconnect(),q=null,e())},{rootMargin:`${t.lazyMargin??200}px`}),q.observe(I)}let le=t.draggable===!0,B=tt(t.resizable),Mt={move:new me,resize:new me},_=null,R={x:0,y:0},Fe=!1,de=null,Ot=!1,Ge=()=>({width:document.documentElement.clientWidth||window.innerWidth,height:document.documentElement.clientHeight||window.innerHeight}),ne=()=>{let e=I.getBoundingClientRect();return{left:e.left,top:e.top,width:e.width,height:e.height}},Rt=()=>({move:le&&P?.gestures?.move===!0,resize:B!==null&&P?.gestures?.resize===!0});function ve(e,n,o){if(o&&(l.width=`${e.width}px`,l.height=`${e.height}px`,l.maxWidth="none"),x==="inline"){let c=n??{left:e.left-R.x,top:e.top-R.y};R={x:e.left-c.left,y:e.top-c.top},l.setProperty("translate",`${R.x}px ${R.y}px`)}else l.left=`${e.left}px`,l.top=`${e.top}px`,l.right="auto",l.bottom="auto";Fe=!0,F()}let re=null;function Pe(e){let n=document.documentElement;if(e&&!re){re={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&&re&&(n.style.setProperty("user-select",re.us),n.style.setProperty("-webkit-user-select",re.wus),re=null)}function De(e){if(!_||e&&_.kind!==e)return;Mt[_.kind].close();let n=ne();b(_.kind,{phase:"end",...n}),_=null,Pe(!1),_t()}function Lt(e,n){if(v||!P?.gestures||(e==="move"?!le:B===null))return;let o=Gt(e,n);if(!o||(o.phase==="start"?_!==null:_?.kind!==e)||!Mt[e].accept(o))return;if(o.phase==="start"){let h=ne();_={kind:e,start:h,corner:o.corner,inlineBase:x==="inline"?{left:h.left-R.x,top:h.top-R.y}:null},Pe(!0),b(e,{phase:"start",...h});return}let c=_,p=Ge(),f=e==="move"?Wt(c.start,o.totalDx,o.totalDy,p):Ft(c.start,c.corner,o.totalDx,o.totalDy,B,p);ve(f,c.inlineBase,e==="resize"),b(e,{phase:o.phase,...f}),o.phase==="end"&&(_=null,Pe(!1),_t())}function zt(){if(v)return;let e=Rt();e.move||De("move"),e.resize||De("resize"),!(!w||!P)&&(It(),!(de&&de.move===e.move&&de.resize===e.resize)&&(de=e,P.gestures&&w.postMessage(N("xc.setConfig",{gestures:e}))))}function It(){if(Ot||!P||P.gestures)return;let e=le;if(!e&&B===null)return;Ot=!0;let n=[e?"draggable":"",B!==null?"resizable":""].filter(Boolean).join(" / ");b("error",{code:"unsupported",message:`${n} needs gesture support (capabilities.gestures), which this /embed deployment does not advertise (older version)`,command:"gestures"})}let Ht=()=>{if(!Fe||_||v)return;let e=ne(),n=Ge(),o=x==="inline"?{...Oe({...e,top:0},{width:n.width,height:Number.MAX_SAFE_INTEGER}),top:Math.max(e.top,-window.scrollY)}:Oe(e,n);o.left===e.left&&o.top===e.top&&o.width===e.width&&o.height===e.height||ve(o,x==="inline"?{left:e.left-R.x,top:e.top-R.y}:null,o.width!==e.width||o.height!==e.height)};window.addEventListener("resize",Ht,{passive:!0});let G=t.persistBox===!0?"xiaochun:box":typeof t.persistBox=="string"&&t.persistBox?`xiaochun:box:${t.persistBox}`:null,_t=()=>{if(G)try{let e=ne(),n=x==="inline"?R:{x:e.left,y:e.top};window.localStorage.setItem(G,JSON.stringify({v:1,mode:x,x:Math.round(n.x),y:Math.round(n.y),width:Math.round(e.width),height:Math.round(e.height)}))}catch{}},un=()=>{if(!G)return null;try{let e=window.localStorage.getItem(G);if(e===null)return null;let n=null;try{n=JSON.parse(e)}catch{}let o=(c,p,f)=>typeof c=="number"&&Number.isFinite(c)&&c>=p&&c<=f;if(n&&n.v===1&&n.mode===x&&o(n.x,-1e5,1e5)&&o(n.y,-1e5,1e5)&&o(n.width,1,1e5)&&o(n.height,1,1e5))return{x:n.x,y:n.y,width:n.width,height:n.height};window.localStorage.removeItem(G)}catch{}return null};function ln(){if(!G||!le&&B===null)return;let e=un();if(!e)return;let n=Ge(),o=B??Me,c=ne(),p=B!==null&&t.width===void 0,f=B!==null&&t.height===void 0,h=(k,E,K)=>Math.min(Math.max(k,E),Math.max(E,K)),A=p?h(e.width,o.minWidth,Math.min(o.maxWidth,n.width)):c.width,L=f?h(e.height,o.minHeight,Math.min(o.maxHeight,n.height)):c.height;if(x==="inline"){let k={left:c.left-R.x,top:c.top-R.y},E=h(k.left+e.x,0,n.width-A),K=Math.max(k.top+e.y,-window.scrollY);ve({left:E,top:K,width:A,height:L},k,p||f)}else ve(Oe({left:e.x,top:e.y,width:A,height:L},n),null,p||f)}ln(),cn();let Tt={element:I,get iframe(){return m},ready:ht,activate:$,say:(e,n)=>C("xc.say",{text:e,mode:n?.mode},!0),speakAudio:Qt,speakAudioStream:en,motion:e=>C("xc.motion",typeof e=="string"?e.startsWith("http")||e.startsWith("/")?{url:e}:{name:e}:e),expression:e=>C("xc.expression",{name:e}),lookAt:(e,n)=>C("xc.lookAt",{x:e,y:n}),setOutfit:e=>T(e)?C("xc.setOutfit",{id:e},!0,void 0,void 0,"outfits"):Promise.reject(new Error("[bad_request] invalid outfit id")),setScene:e=>T(e)?C("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=>!T(n)))?Promise.reject(new Error("[bad_request] prefetch ids must be an array of outfit ids")):C("xc.prefetch",e?{ids:e}:{},!0,void 0,void 0,"prefetch"),getOutfits:async()=>(m||$(),await xt,P?.outfits?P.outfits.slice():[]),getScenes:async()=>(m||$(),await xt,P?.scenes?P.scenes.slice():[]),get outfit(){return gt},get scene(){return yt},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 b("error",{code:"unsupported",message:o,command:"xc.setModel"}),Promise.reject(new Error(`[unsupported] ${o}`))}return C("xc.setModel",n)},setConfig:e=>C("xc.setConfig",e),setSize(e,n){v||(l.width=Y(e,rt(x!=="inline")),l.height=Y(n,ot(x!=="inline")),l.maxWidth==="none"&&(l.maxWidth="100%"),F())},getBox:()=>ne(),clearPersistedBox(e){if(G)try{window.localStorage.removeItem(G)}catch{}v||e?.reset!==!0||(De(),l.width=Y(t.width,rt(x!=="inline")),l.height=Y(t.height,ot(x!=="inline")),l.maxWidth="100%",x==="inline"?(R={x:0,y:0},l.removeProperty("translate")):(l.left="",l.top="",l.right="",l.bottom="",x==="bottom-right"&&(l.right="var(--xc-offset-x, 16px)",l.bottom="var(--xc-offset-y, 16px)"),x==="bottom-left"&&(l.left="var(--xc-offset-x, 16px)",l.bottom="var(--xc-offset-y, 16px)")),Fe=!1,F())},setBorderRadius(e){_e=e,dt()},setDraggable(e){le=e===!0,zt()},setResizable(e){B=tt(e),zt()},startListening:()=>C("xc.mic",{enabled:!0}),stopListening:()=>C("xc.mic",{enabled:!1}),mic:e=>C("xc.mic",{enabled:e}),pause(){Te=!0,we()},resume(){Te=!1,we()},destroy(){if(!v){try{w?.postMessage(N("xc.destroy"))}catch{}v=!0,kt(),q?.disconnect(),We?.disconnect(),ee&&clearTimeout(ee),j&&cancelAnimationFrame(j),window.removeEventListener("message",vt),window.removeEventListener("resize",Ht),Pe(!1),St(),Ne();try{w?.close()}catch{}w=null;for(let e of H.values())e.reject(new Error("[project-xiaochun] instance destroyed"));H.clear(),Be.length=0,Ue||pt(new Error("[project-xiaochun] destroyed before ready")),I.remove(),m=null,b("destroy",void 0),ye.clear()}},on(e,n){let o=ye.get(e);return o||(o=new Set,ye.set(e,o)),o.add(n),()=>{o.delete(n)}}};return Tt}var Hn=["src","outfit","scene","model","lang","mic","transparent","draggable","resizable","min-size","max-size","border-radius","position","size","lazy","paused","placeholder","heavy","ui","ui-autohide","camera-fov","camera-distance","camera-height","camera-intro","controls","allowed-origins","cross-origin-isolated","persist","persist-box","allow-custom-model","prefetch"],_n=new Set(["src","position","lazy","placeholder","heavy","ui","ui-autohide","controls","allowed-origins","transparent","cross-origin-isolated","persist","persist-box","allow-custom-model","prefetch"]);function Dt(t){if(t===null||t.trim()==="")return;let r=t.trim();return/^\d+(\.\d+)?$/.test(r)?Number(r):r}function U(t,r,a){let i=t.getAttribute(r);return i===null?a:i!=="false"}function Tn(t){return t===null||t==="false"?!1:t===""||t==="true"?!0:t.split(",").map(r=>r.trim()).filter(Boolean)}function Un(t){if(!(t===null||t==="false"||t==="0"))return t===""||t==="true"||t==="1"?!0:t}function Bn(t){if(!(t===null||t==="false"||t==="0"))return t===""||t==="true"||t==="1"?!0:t.split(",").map(r=>r.trim()).filter(Boolean)}function qt(t){let r=i=>{let s=t.getAttribute(i);if(s===null||s.trim()==="")return null;let u=Number(s);return Number.isFinite(u)?u:null},a=t.getAttribute("camera-intro");return{fov:r("camera-fov"),distance:r("camera-distance"),height:r("camera-height"),intro:a===null?null:a!=="false"&&a!=="0"}}function Kt(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 Vt(t){if(!t)return{width:void 0,height:void 0};let r=t.trim().split(/x/i),a=s=>/^\d+(\.\d+)?$/.test(s)?`${s}px`:s;if(r.length>=2)return{width:a(r[0]),height:a(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:void 0}}function $n(){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,s,u){if(!this.client||s===u)return;if(_n.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")&&u){let g=i==="model"&&this.hasAttribute("outfit")?null:u;g&&(T(g)?d.setOutfit(g):d.setModel(g)).catch(()=>{})}else if(i==="scene"&&u)d.setScene(u).catch(()=>{});else if(i==="lang"&&u)d.setConfig({lang:u}).catch(()=>{});else if(i==="size"){let{width:g,height:X}=Vt(u);d.setSize(g,X)}else i==="border-radius"?d.setBorderRadius(Dt(u)):i==="draggable"?d.setDraggable(U(this,"draggable",!1)):i==="resizable"||i==="min-size"||i==="max-size"?d.setResizable(this.resizableOption()):i.startsWith("camera-")?d.setConfig({camera:qt(this)}).catch(()=>{}):i==="mic"?d.mic(U(this,"mic",!1)).catch(()=>{}):i==="paused"&&(U(this,"paused",!1)?d.pause():d.resume())}build(){if(!this.mountEl||this.client)return;let{width:i,height:s}=Vt(this.getAttribute("size")),u=this.getAttribute("placeholder"),d=this.getAttribute("allowed-origins"),g=this.getAttribute("lazy"),X=g==="click"?"click":g!=="false",S=Re({container:this.mountEl,src:this.getAttribute("src")||void 0,allowedOrigins:d?d.split(",").map(z=>z.trim()).filter(Boolean):void 0,lazy:X,placeholder:u==="none"?!1:u||void 0,transparent:U(this,"transparent",!0),width:i,height:s,position:this.getAttribute("position")??"inline",draggable:U(this,"draggable",!1),resizable:this.resizableOption(),borderRadius:Dt(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,persistBox:Un(this.getAttribute("persist-box")),allowCustomModel:U(this,"allow-custom-model",!1),prefetch:Tn(this.getAttribute("prefetch")),heavy:this.getAttribute("heavy")??void 0,ui:Bn(this.getAttribute("ui")),uiAutoHide:he(this.getAttribute("ui-autohide")),camera:qt(this),controls:U(this,"controls",!0),crossOriginIsolated:U(this,"cross-origin-isolated",!1)});this.client=S;let y=(z,D)=>S.on(z,M=>this.dispatchEvent(new CustomEvent(D,{detail:M,bubbles:!0,composed:!0})));y("ready","xc-ready"),y("progress","xc-progress"),y("state","xc-state"),y("stt","xc-stt"),y("utterance","xc-utterance"),y("error","xc-error"),y("outfit-changed","xc-outfit-changed"),y("scene-changed","xc-scene-changed"),y("lang-changed","xc-lang-changed"),y("move","xc-move"),y("resize","xc-resize"),U(this,"paused",!1)&&S.pause(),U(this,"mic",!1)&&S.ready.then(()=>S.mic(!0)).catch(()=>{})}resizableOption(){if(!U(this,"resizable",!1))return!1;let i=Kt(this.getAttribute("min-size")),s=Kt(this.getAttribute("max-size"));return{minWidth:i?.w,minHeight:i?.h,maxWidth:s?.w,maxHeight:s?.h}}say(i,s){return this.requireClient().say(i,s)}speakAudio(i,s){return this.requireClient().speakAudio(i,s)}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()}clearPersistedBox(i){this.client?.clearPersistedBox(i)}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 st="xiaochun-avatar";function Le(t=st){if(typeof customElements>"u"||typeof HTMLElement>"u")return null;let r=customElements.get(t);if(r)return r;let a=$n();return customElements.define(t,a),a}var ze="xiaochun";function Yt(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),`${ze}://speak?${r.toString().replace(/\+/g,"%20")}`}function Jt(t){let r;try{r=new URL(t)}catch{return null}if(r.protocol!==`${ze}:`)return null;let a=r.hostname||r.pathname.replace(/^\/+/,"");if((a==="action"?r.searchParams.get("action"):a)!=="speak")return null;let s={action:"speak"},u=r.searchParams.get("text"),d=r.searchParams.get("audioUrl"),g=r.searchParams.get("file");return u&&(s.text=u),d&&(s.audioUrl=d),g&&(s.file=g),s.text||s.audioUrl||s.file?s:null}Le();var ct=document.currentScript;if(ct&&ct.hasAttribute("data-auto")){let t=()=>{let r=document.createElement("xiaochun-avatar");for(let a of Array.from(ct.attributes))a.name.startsWith("data-")&&a.name!=="data-auto"&&r.setAttribute(a.name.slice(5),a.value);r.hasAttribute("position")||r.setAttribute("position","bottom-right"),document.body.appendChild(r)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}return gn(Nn);})();
|
|
3
3
|
//# sourceMappingURL=loader.global.js.map
|