@7ots/cli 0.1.37 → 0.1.38
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/.env.example +9 -4
- package/README.md +3 -0
- package/cli/lib/account.mjs +2 -2
- package/cli/lib/assistant.mjs +6 -4
- package/cli/lib/integrations.mjs +1 -0
- package/cli/lib/pet-server.mjs +7 -4
- package/cli/pet/electron/main.cjs +43 -23
- package/cli/pet/pet.html +5 -4
- package/dist/7ots.esm.js +2 -2
- package/dist/7ots.esm.js.map +2 -2
- package/dist/7ots.iife.js +2 -2
- package/dist/7ots.iife.js.map +2 -2
- package/package.json +1 -1
- package/server/server.mjs +1 -1
- package/src/avatar/AvatarStage.js +1 -1
- package/src/character3d/room.js +1 -1
package/dist/7ots.iife.js
CHANGED
|
@@ -344,7 +344,7 @@ uniform vec3 uGravity;`,qc=`vec3 dN = normal;
|
|
|
344
344
|
</div>
|
|
345
345
|
<p class="otr-keys" data-keys hidden>${Sa(a("room.keys"))}</p>
|
|
346
346
|
<p class="otr-prompt" data-prompt hidden></p>
|
|
347
|
-
<div class="otr-pad" data-pad hidden>${["up","left","use","right","down"].map(I=>`<button type="button" data-d="${I}" aria-label="${Sa(a(`room.pad.${I}`))}">${{up:"\u25B2",left:"\u25C0",use:"E",right:"\u25B6",down:"\u25BC"}[I]}</button>`).join("")}</div>`;let l=I=>n.querySelector(I);l("[data-name]").textContent=s;let h=document.createElement("canvas");h.setAttribute("aria-label",a("room.inRoom")),e.append(h,n);let f=new Te.WebGLRenderer({canvas:h,antialias:!0,powerPreference:"high-performance"});f.setPixelRatio(Math.min(o.maxDpr||1.5,devicePixelRatio||1)),f.outputColorSpace=Te.SRGBColorSpace,f.toneMapping=Te.NeutralToneMapping,f.toneMappingExposure=1.05;let c=new Te.PMREMGenerator(f),d=c.fromScene(new b0.RoomEnvironment,.04);c.dispose();let p=new Te.Scene;p.background=new Te.Color("#2a1f55"),p.environment=d.texture,p.environmentIntensity=.45;let u=new Te.HemisphereLight(15265023,4206670,.56),g=new Te.DirectionalLight(16773600,2.4*.55);g.position.set(2.2,3.4,3.2);let m=new Te.DirectionalLight(13623551,2.2*.55);m.position.set(-2.6,2.2,-3);let w=new Te.DirectionalLight(16770804,.5*.55);w.position.set(-3,.5,2);let k=new Te.AmbientLight("#ffe9d6",.25);p.add(u,g,m,w,k);let b=null,x=I=>{b&&(p.remove(b.group),y0(b.group)),b=m0(p,I);let K=b.look;p.background.set(K.bg),e.style.background=K.bg,p.environmentIntensity=K.env,f.toneMappingExposure=K.exposure,u.color.set(K.hemi[0]),u.groundColor.set(K.hemi[1]),u.intensity=K.hemi[2],k.color.set(K.amb[0]),k.intensity=K.amb[1],g.intensity=2.4*.55*K.key,m.intensity=2.2*.55*K.key,w.intensity=.5*.55*K.key};x(o.theme||gi);let E=new Te.PerspectiveCamera(36,1,.1,80),T=null,v=new Te.Vector3(.9,0,2),_=.2,C=.2,L=0,z=0,N=0,Q=1,F=null,A=null,B=null,W="auto",ae=new Set,Me=new Te.Vector3(-.4,.6,-.6),te=l("[data-bubble]"),ue=0,be=(I,K=2600)=>{te.textContent=I,te.hidden=!1,ue=performance.now()+K},fe=I=>{l("[data-doing]").textContent=I},Fe=I=>{T&&(p.remove(T.root),T.dispose()),T=new la(I,{quality:"high",material:o.material||"plush"}),T.root.scale.setScalar(Ou/T.H),p.add(T.root)},Y=(I,K,ie)=>{let Pe=(K-I+Math.PI)%(Math.PI*2)-Math.PI;return Pe<-Math.PI&&(Pe+=Math.PI*2),I+Pe*ie},$e=(I,K)=>I<yi[0]||I>yi[1]||K<yi[2]||K>yi[3]||qu.some(([ie,Pe,Re,Ye])=>I>ie-bi&&I<Re+bi&&K>Pe-bi&&K<Ye+bi),Oe=(I,K,ie=1)=>new Promise(Pe=>{F={x:I,z:K,sp:ie,res:Pe}}),Ge=(I,K=520)=>new Promise(ie=>{A={from:new Te.Vector3(v.x,L,v.z),to:new Te.Vector3(...I),t0:performance.now(),ms:K,res:ie}}),qe=async()=>{if(!B)return;let I=B;B=null,T.moodName==="sleep"&&T.mood("neutral"),await Ge([I.at[0],0,I.at[1]])},We=0,lo=new Set,Ue=I=>new Promise(K=>{let ie=setTimeout(()=>{lo.delete(ie),K()},I);lo.add(ie)}),st=I=>{let K=++We;F=null,I(()=>K!==We).catch(()=>{})},Ne=I=>async K=>{let ie=await K;if(I())throw 0;return ie};async function Qt(I,K,{hurry:ie=!1,line:Pe=null}={}){let Re=Ne(K),Ye=Lr[I];if(await Re(qe()),T.mood("neutral"),fe(a(ie?"room.run":"room.walk")),await Re(Oe(Ye.at[0],Ye.at[1],ie?2.2:1)),C=Ye.face,fe(a(`room.doing.${I}`)),await Re(Ue(350)),Ye.seat&&(B=Ye,await Re(Ge(Ye.seat)),C=Ye.face),I==="window")T.gesture("think"),be(a("room.say.window")),await Re(Ue(3200)),T.effect("sparkles"),await Re(Ue(2400));else if(I==="sofa")T.mood("happy"),await Re(Ue(2200)),T.gesture("yawn"),be(a("room.say.sofa")),await Re(Ue(4200));else if(I==="rug")for(let Mt of["dance","groove","disco"].sort(()=>Math.random()-.5).slice(0,2))T.gesture(Mt),T.effect("notes"),await Re(Ue(2600));else if(I==="bed"){T.mood("sleep"),be("zzz\u2026",1800);for(let Mt=0;Mt<4;Mt++)T.effect("zzz"),await Re(Ue(2200));T.mood("neutral"),T.gesture("yawn"),await Re(Ue(1600))}else I==="desk"?(T.gesture("think"),T.effect("thought"),be(Pe||a("room.say.desk")),await Re(Ue(3400)),T.gesture("nod"),await Re(Ue(1600))):I==="plant"?(T.gesture("point"),be(a("room.say.plant")),await Re(Ue(2800)),T.effect("hearts"),await Re(Ue(1400))):I==="front"&&(T.gesture("wave"),be(a("room.say.hello",{name:s})),await Re(Ue(2600)))}let co="front",Lo=I=>st(async K=>{let ie=Ne(K);for(I||await ie(Qt("front",K));;){let Pe=Object.keys(Lr).filter(Re=>Re!==co);co=Pe[Math.floor(Math.random()*Pe.length)],await ie(Qt(co,K)),T.mood("neutral"),await ie(Ue(600+Math.random()*1200))}}),qr=()=>{W==="auto"?Lo(!0):fe(a("room.you"))},Ka=I=>st(async K=>{let ie=Ne(K);T.effect("exclaim"),T.gesture("surprise"),be(a("room.say.gotMsg"),2200),await ie(Ue(900)),await ie(Qt("desk",K,{hurry:!0,line:I?`\xAB${String(I).slice(0,90)}\xBB`:null})),T.mood("happy"),T.gesture("thumbsup"),be(a("room.say.replied")),await ie(Ue(2400)),qr()}),ys=(I,K)=>{if(I==="message")return Ka(K);if(I==="plaza")return st(async ie=>{await Ne(ie)(Qt("desk",ie,{line:K||null})),qr()});if(I==="poke")return T.gesture("wave"),T.effect("hearts"),be(K||a("room.say.hello",{name:s}));T.effect(I),K&&be(K)},Xa=()=>{let I=null,K=1.3;for(let[ie,Pe]of Object.entries(Lr)){let Re=Math.hypot(v.x-Pe.at[0],v.z-Pe.at[1]);Re<K&&(K=Re,I=ie)}return I},Ha=()=>{if(W!=="ctl")return;if(B)return st(async K=>{await Ne(K)(qe()),T.mood("neutral")});let I=Xa();I?st(K=>Qt(I,K)):T.gesture("jump")},Pa=I=>{!r&&I==="ctl"||(W=I,n.querySelectorAll("[data-mode]").forEach(K=>K.setAttribute("aria-pressed",K.dataset.mode===I)),l("[data-keys]").hidden=I!=="ctl"||i,l("[data-pad]").hidden=I!=="ctl"||!(i||e.clientWidth<640),I==="auto"?(l("[data-prompt]").hidden=!0,Lo(!0)):(We++,F=null,fe(a("room.you")),be(a("room.say.takeMe"),1600),e.focus({preventScroll:!0})))},Ja={KeyW:"up",ArrowUp:"up",KeyS:"down",ArrowDown:"down",KeyA:"left",ArrowLeft:"left",KeyD:"right",ArrowRight:"right"},er=!1,ea=I=>{if(!r||I.target.closest?.("input,textarea,select,[contenteditable]"))return;let K=Ja[I.code];if(I.type==="keyup"){K&&ae.delete(K);return}(er||e.contains(document.activeElement))&&(W==="auto"&&(K||I.code==="Space")&&Pa("ctl"),K&&(I.preventDefault(),ae.add(K)),I.code==="Space"&&(I.preventDefault(),T.gesture("jump")),I.code==="KeyE"&&Ha())},tr=()=>ae.clear();addEventListener("keydown",ea),addEventListener("keyup",ea),addEventListener("blur",tr),e.addEventListener("pointerenter",()=>{er=!0}),e.addEventListener("pointerleave",()=>{er=!1});let or=l("[data-pad]");or.addEventListener("pointerdown",I=>{let K=I.target.closest("[data-d]")?.dataset.d;K&&(I.preventDefault(),K==="use"?Ha():ae.add(K))});let bs=I=>{let K=I.target.closest?.("[data-d]")?.dataset.d;K&&ae.delete(K)};or.addEventListener("pointerup",bs),or.addEventListener("pointercancel",bs),or.addEventListener("pointerleave",tr);let za=new Te.Raycaster,ar=new Te.Vector2;h.addEventListener("pointerdown",I=>{let K=h.getBoundingClientRect();if(ar.set((I.clientX-K.left)/K.width*2-1,-((I.clientY-K.top)/K.height)*2+1),za.setFromCamera(ar,E),!r){za.intersectObject(T.root,!0).length&&ys("poke");return}let ie=za.intersectObject(b.floor)[0];if(!ie)return;W==="auto"&&Pa("ctl");let{x:Pe,z:Re}=ie.point;if(Math.hypot(Pe-v.x,Re-v.z)<.25){T.gesture("jump");return}let Ye=Object.keys(Lr).find(Mt=>{let ha=Lr[Mt];return Math.hypot(Pe-(ha.seat?.[0]??ha.at[0]),Re-(ha.seat?.[2]??ha.at[1]))<.9});if(Ye&&(Lr[Ye].seat||$e(Pe,Re)))return st(Mt=>Qt(Ye,Mt));$e(Pe,Re)||st(async Mt=>{await Ne(Mt)(qe()),fe(a("room.walk")),await Ne(Mt)(Oe(Pe,Re,1.3)),fe(a("room.you"))})}),n.addEventListener("click",I=>{let K=I.target.closest("button");K&&(K.dataset.mode?Pa(K.dataset.mode):K.dataset.msg!=null?Ka():K.dataset.edit!=null&&o.onEdit?.())});let q=0,D=0,J=()=>{let I=Math.max(1,e.clientWidth),K=Math.max(1,e.clientHeight);if(I===q&&K===D)return;q=I,D=K,f.setSize(I,K,!1);let ie=I/K;E.aspect=ie,E.fov=ie<1?50:36,E.updateProjectionMatrix(),W==="ctl"&&(l("[data-pad]").hidden=!(i||I<640))},ee=new ResizeObserver(J);ee.observe(e);let ne=new Te.Vector3,we=new Te.Vector3,Le=new Te.Vector3,lt=new Te.Vector3;function Ee(I,K){let ie=K/1e3,Pe=E.aspect;b.tick(I,K);let Re=!1;if(W==="ctl"&&ae.size&&!A&&(B?st(async ct=>{await Ne(ct)(qe())}):(E.getWorldDirection(ne),ne.y=0,ne.normalize(),we.crossVectors(ne,E.up).normalize(),Le.set(0,0,0),ae.has("up")&&Le.add(ne),ae.has("down")&&Le.sub(ne),ae.has("right")&&Le.add(we),ae.has("left")&&Le.sub(we),Le.lengthSq()>0&&(We&&F&&(We++,F=null,T.mood("neutral"),fe(a("room.you"))),Le.normalize().multiplyScalar(2.1*ie),$e(v.x+Le.x,v.z)||(v.x+=Le.x),$e(v.x,v.z+Le.z)||(v.z+=Le.z),C=Math.atan2(Le.x,Le.z),Re=!0,Q=1.4))),A){let ct=Math.min(1,(performance.now()-A.t0)/A.ms),zt=ct<.5?2*ct*ct:1-(-2*ct+2)**2/2;if(v.x=Te.MathUtils.lerp(A.from.x,A.to.x,zt),v.z=Te.MathUtils.lerp(A.from.z,A.to.z,zt),L=Te.MathUtils.lerp(A.from.y,A.to.y,zt)+Math.sin(Math.PI*ct)*.55,ct>.05&&ct<.6&&(C=Math.atan2(A.to.x-A.from.x,A.to.z-A.from.z)||C),ct>=1){let Se=A.res;L=A.to.y,A=null,Se()}}else if(F&&!Re){let ct=F.x-v.x,zt=F.z-v.z,Se=Math.hypot(ct,zt),oe=Math.min(Se,1.5*F.sp*ie);if(Se<.04){let ot=F.res;F=null,ot()}else v.x+=ct/Se*oe,v.z+=zt/Se*oe,C=Math.atan2(ct,zt),Re=!0,Q=F.sp}N+=((Re?1:0)-N)*Math.min(1,ie*10),z+=ie*11*Q,_=Y(_,C,Math.min(1,ie*9));let Ye=Math.abs(Math.sin(z))*.08*N;T.root.position.set(v.x,L+Ye,v.z),T.root.rotation.set(0,_,Math.sin(z)*.07*N),T.shadow&&(T.shadow.position.y=.002-Ye/T.root.scale.y,T.shadow.material.opacity=1-Math.min(.7,Ye*4)),T.tick(I,K),T.lod(Math.min(320,D*.35));let Mt=Pe<1?.75:.3,ha=Le.set(Te.MathUtils.lerp(-.3,v.x,Mt),.5,Te.MathUtils.lerp(-.6,v.z,Mt));Me.lerp(ha,Math.min(1,ie*2.5));let rr=Pe<1?10.5:o.compact?11.4:12.6;if(E.position.set(Me.x+rr*.42,Me.y+rr*.62,Me.z+rr*.66),E.lookAt(Me),f.render(p,E),te.hidden||(performance.now()>ue&&(te.hidden=!0),lt.set(0,T.H*1.12,0).applyMatrix4(T.root.matrixWorld).project(E),te.style.left=`${(lt.x+1)/2*q}px`,te.style.top=`${(1-lt.y)/2*D}px`),W==="ctl"){let ct=!F&&!A&&Xa(),zt=B?a("room.getOff"):ct?a("room.use",{label:a(`room.places.${ct}`)}):"",Se=l("[data-prompt]");Se.textContent!==zt&&(Se.textContent=zt),Se.hidden=!zt}}let se=0,tt=0,Jt=!0,ho=!1,Ho=I=>{if(se=0,ho||!Jt||document.hidden)return;let K=Math.min(100,tt?I-tt:16);tt=I,J(),Ee(I,K),se=requestAnimationFrame(Ho)},vt=()=>{!se&&!ho&&Jt&&!document.hidden&&(tt=0,se=requestAnimationFrame(Ho))},ta=new IntersectionObserver(([I])=>{Jt=I.isIntersecting,vt()},{rootMargin:"64px"});return ta.observe(e),document.addEventListener("visibilitychange",vt),Fe(t),J(),Lo(!1),vt(),{el:e,say:be,message:Ka,react:ys,setMode:Pa,get mode(){return W},setName(I){s=I||"ot",l("[data-name]").textContent=s},setSpec(I){let K=T.moodName;Fe(I),T.mood(K||"neutral"),T.gesture("celebrate")},setTheme(I){ho||(x(I),vt())},get theme(){return b.id},destroy(){ho=!0,We++,cancelAnimationFrame(se);for(let I of lo)clearTimeout(I);ta.disconnect(),ee.disconnect(),removeEventListener("keydown",ea),removeEventListener("keyup",ea),removeEventListener("blur",tr),document.removeEventListener("visibilitychange",vt),T.dispose(),p.remove(T.root),y0(p),d.dispose(),f.dispose(),f.forceContextLoss?.(),h.remove(),n.remove(),e.classList.remove("otr","compact")}}}var Te,b0,Sa,Ou,Lr,qu,yi,bi,Gu,g0,Nu,y0,x0=Ke(()=>{Te=_t(Zo(),1),b0=_t(gn(),1);An();$0();Pn();Qe();Sa=e=>String(e??"").replace(/[&<>"]/g,t=>({"&":"&","<":"<",">":">",'"':"""})[t]),Ou=1.3,Lr={window:{at:[-1.2,-3],face:Math.PI},sofa:{at:[-3.2,.5],seat:[-4.15,.66,.5],face:Math.PI/2},rug:{at:[.6,.9],face:.35},bed:{at:[1.9,-2.2],seat:[3.55,.68,-2.3],face:.3},desk:{at:[.95,-2.75],face:Math.PI},plant:{at:[-3.5,-2.6],face:-2.3},front:{at:[.9,2],face:.25}},qu=[[-5,-.95,-3.7,1.95],[-4.75,-1.85,-3.85,-1.05],[2.45,-4,4.65,-.95],[0,-4,2.05,-3],[-4.8,-3.85,-3.9,-2.95]],yi=[-4.6,4.6,-3.6,3.6],bi=.32,Gu=`
|
|
347
|
+
<div class="otr-pad" data-pad hidden>${["up","left","use","right","down"].map(I=>`<button type="button" data-d="${I}" aria-label="${Sa(a(`room.pad.${I}`))}">${{up:"\u25B2",left:"\u25C0",use:"E",right:"\u25B6",down:"\u25BC"}[I]}</button>`).join("")}</div>`;let l=I=>n.querySelector(I);l("[data-name]").textContent=s;let h=document.createElement("canvas");h.setAttribute("aria-label",a("room.inRoom")),e.append(h,n);let f=new Te.WebGLRenderer({canvas:h,antialias:!0,powerPreference:"high-performance"});f.setPixelRatio(Math.min(o.maxDpr||1.5,devicePixelRatio||1)),f.outputColorSpace=Te.SRGBColorSpace,f.toneMapping=Te.NeutralToneMapping,f.toneMappingExposure=1.05;let c=new Te.PMREMGenerator(f),d=c.fromScene(new b0.RoomEnvironment,.04);c.dispose();let p=new Te.Scene;p.background=new Te.Color("#2a1f55"),p.environment=d.texture,p.environmentIntensity=.45;let u=new Te.HemisphereLight(15265023,4206670,.56),g=new Te.DirectionalLight(16773600,2.4*.55);g.position.set(2.2,3.4,3.2);let m=new Te.DirectionalLight(13623551,2.2*.55);m.position.set(-2.6,2.2,-3);let w=new Te.DirectionalLight(16770804,.5*.55);w.position.set(-3,.5,2);let k=new Te.AmbientLight("#ffe9d6",.25);p.add(u,g,m,w,k);let b=null,x=I=>{b&&(p.remove(b.group),y0(b.group)),b=m0(p,I);let K=b.look;p.background.set(K.bg),e.style.background=K.bg,p.environmentIntensity=K.env,f.toneMappingExposure=K.exposure,u.color.set(K.hemi[0]),u.groundColor.set(K.hemi[1]),u.intensity=K.hemi[2],k.color.set(K.amb[0]),k.intensity=K.amb[1],g.intensity=2.4*.55*K.key,m.intensity=2.2*.55*K.key,w.intensity=.5*.55*K.key};x(o.theme||gi);let E=new Te.PerspectiveCamera(36,1,.1,80),T=null,v=new Te.Vector3(.9,0,2),_=.2,C=.2,L=0,z=0,N=0,Q=1,F=null,A=null,B=null,W="auto",ae=new Set,Me=new Te.Vector3(-.4,.6,-.6),te=l("[data-bubble]"),ue=0,be=(I,K=2600)=>{te.textContent=I,te.hidden=!1,ue=performance.now()+K},fe=I=>{l("[data-doing]").textContent=I},Fe=I=>{T&&(p.remove(T.root),T.dispose()),T=new la(I,{quality:"high",material:o.material||"plush"}),T.root.scale.setScalar(Ou/T.H),p.add(T.root)},Y=(I,K,ie)=>{let Pe=(K-I+Math.PI)%(Math.PI*2)-Math.PI;return Pe<-Math.PI&&(Pe+=Math.PI*2),I+Pe*ie},$e=(I,K)=>I<yi[0]||I>yi[1]||K<yi[2]||K>yi[3]||qu.some(([ie,Pe,Re,Ye])=>I>ie-bi&&I<Re+bi&&K>Pe-bi&&K<Ye+bi),Oe=(I,K,ie=1)=>new Promise(Pe=>{F={x:I,z:K,sp:ie,res:Pe}}),Ge=(I,K=520)=>new Promise(ie=>{A={from:new Te.Vector3(v.x,L,v.z),to:new Te.Vector3(...I),t0:performance.now(),ms:K,res:ie}}),qe=async()=>{if(!B)return;let I=B;B=null,T.moodName==="sleep"&&T.mood("neutral"),await Ge([I.at[0],0,I.at[1]])},We=0,lo=new Set,Ue=I=>new Promise(K=>{let ie=setTimeout(()=>{lo.delete(ie),K()},I);lo.add(ie)}),st=I=>{let K=++We;F=null,I(()=>K!==We).catch(()=>{})},Ne=I=>async K=>{let ie=await K;if(I())throw 0;return ie};async function Qt(I,K,{hurry:ie=!1,line:Pe=null}={}){let Re=Ne(K),Ye=Lr[I];if(await Re(qe()),T.mood("neutral"),fe(a(ie?"room.run":"room.walk")),await Re(Oe(Ye.at[0],Ye.at[1],ie?2.2:1)),C=Ye.face,fe(a(`room.doing.${I}`)),await Re(Ue(350)),Ye.seat&&(B=Ye,await Re(Ge(Ye.seat)),C=Ye.face),I==="window")T.gesture("think"),be(a("room.say.window")),await Re(Ue(3200)),T.effect("sparkles"),await Re(Ue(2400));else if(I==="sofa")T.mood("happy"),await Re(Ue(2200)),T.gesture("yawn"),be(a("room.say.sofa")),await Re(Ue(4200));else if(I==="rug")for(let Mt of["dance","groove","disco"].sort(()=>Math.random()-.5).slice(0,2))T.gesture(Mt),T.effect("notes"),await Re(Ue(2600));else if(I==="bed"){T.mood("sleep"),be("zzz\u2026",1800);for(let Mt=0;Mt<4;Mt++)T.effect("zzz"),await Re(Ue(2200));T.mood("neutral"),T.gesture("yawn"),await Re(Ue(1600))}else I==="desk"?(T.gesture("think"),T.effect("thought"),be(Pe||a("room.say.desk")),await Re(Ue(3400)),T.gesture("nod"),await Re(Ue(1600))):I==="plant"?(T.gesture("point"),be(a("room.say.plant")),await Re(Ue(2800)),T.effect("hearts"),await Re(Ue(1400))):I==="front"&&(T.gesture("wave"),be(a("room.say.hello",{name:s})),await Re(Ue(2600)))}let co="front",Lo=I=>st(async K=>{let ie=Ne(K);for(I||await ie(Qt("front",K));;){let Pe=Object.keys(Lr).filter(Re=>Re!==co);co=Pe[Math.floor(Math.random()*Pe.length)],await ie(Qt(co,K)),T.mood("neutral"),await ie(Ue(600+Math.random()*1200))}}),qr=()=>{W==="auto"?Lo(!0):fe(a("room.you"))},Ka=I=>st(async K=>{let ie=Ne(K);T.effect("exclaim"),T.gesture("surprise"),be(a("room.say.gotMsg"),2200),await ie(Ue(900)),await ie(Qt("desk",K,{hurry:!0,line:I?`\xAB${String(I).slice(0,90)}\xBB`:null})),T.mood("happy"),T.gesture("thumbsup"),be(a("room.say.replied")),await ie(Ue(2400)),qr()}),ys=(I,K)=>{if(I==="message")return Ka(K);if(I==="plaza")return st(async ie=>{await Ne(ie)(Qt("desk",ie,{line:K||null})),qr()});if(I==="poke")return T.gesture("wave"),T.effect("hearts"),be(K||a("room.say.hello",{name:s}));T.effect(I),K&&be(K)},Xa=()=>{let I=null,K=1.3;for(let[ie,Pe]of Object.entries(Lr)){let Re=Math.hypot(v.x-Pe.at[0],v.z-Pe.at[1]);Re<K&&(K=Re,I=ie)}return I},Ha=()=>{if(W!=="ctl")return;if(B)return st(async K=>{await Ne(K)(qe()),T.mood("neutral")});let I=Xa();I?st(K=>Qt(I,K)):T.gesture("jump")},Pa=I=>{!r&&I==="ctl"||(W=I,n.querySelectorAll("[data-mode]").forEach(K=>K.setAttribute("aria-pressed",K.dataset.mode===I)),l("[data-keys]").hidden=I!=="ctl"||i,l("[data-pad]").hidden=I!=="ctl"||!(i||e.clientWidth<640),I==="auto"?(l("[data-prompt]").hidden=!0,Lo(!0)):(We++,F=null,fe(a("room.you")),be(a("room.say.takeMe"),1600),e.focus({preventScroll:!0})))},Ja={KeyW:"up",ArrowUp:"up",KeyS:"down",ArrowDown:"down",KeyA:"left",ArrowLeft:"left",KeyD:"right",ArrowRight:"right"},er=!1,ea=I=>{if(!r||I.target.closest?.("input,textarea,select,[contenteditable]"))return;let K=Ja[I.code];if(I.type==="keyup"){K&&ae.delete(K);return}(er||e.contains(document.activeElement))&&(W==="auto"&&(K||I.code==="Space")&&Pa("ctl"),K&&(I.preventDefault(),ae.add(K)),I.code==="Space"&&(I.preventDefault(),T.gesture("jump")),I.code==="KeyE"&&Ha())},tr=()=>ae.clear();addEventListener("keydown",ea),addEventListener("keyup",ea),addEventListener("blur",tr),e.addEventListener("pointerenter",()=>{er=!0}),e.addEventListener("pointerleave",()=>{er=!1});let or=l("[data-pad]");or.addEventListener("pointerdown",I=>{let K=I.target.closest("[data-d]")?.dataset.d;K&&(I.preventDefault(),K==="use"?Ha():ae.add(K))});let bs=I=>{let K=I.target.closest?.("[data-d]")?.dataset.d;K&&ae.delete(K)};or.addEventListener("pointerup",bs),or.addEventListener("pointercancel",bs),or.addEventListener("pointerleave",tr);let za=new Te.Raycaster,ar=new Te.Vector2;h.addEventListener("pointerdown",I=>{let K=h.getBoundingClientRect();if(ar.set((I.clientX-K.left)/K.width*2-1,-((I.clientY-K.top)/K.height)*2+1),za.setFromCamera(ar,E),!r){za.intersectObject(T.root,!0).length&&ys("poke");return}let ie=za.intersectObject(b.floor)[0];if(!ie)return;W==="auto"&&Pa("ctl");let{x:Pe,z:Re}=ie.point;if(Math.hypot(Pe-v.x,Re-v.z)<.25){T.gesture("jump");return}let Ye=Object.keys(Lr).find(Mt=>{let ha=Lr[Mt];return Math.hypot(Pe-(ha.seat?.[0]??ha.at[0]),Re-(ha.seat?.[2]??ha.at[1]))<.9});if(Ye&&(Lr[Ye].seat||$e(Pe,Re)))return st(Mt=>Qt(Ye,Mt));$e(Pe,Re)||st(async Mt=>{await Ne(Mt)(qe()),fe(a("room.walk")),await Ne(Mt)(Oe(Pe,Re,1.3)),fe(a("room.you")),e.focus({preventScroll:!0})})}),n.addEventListener("click",I=>{let K=I.target.closest("button");K&&(K.dataset.mode?Pa(K.dataset.mode):K.dataset.msg!=null?Ka():K.dataset.edit!=null&&o.onEdit?.())});let q=0,D=0,J=()=>{let I=Math.max(1,e.clientWidth),K=Math.max(1,e.clientHeight);if(I===q&&K===D)return;q=I,D=K,f.setSize(I,K,!1);let ie=I/K;E.aspect=ie,E.fov=ie<1?50:36,E.updateProjectionMatrix(),W==="ctl"&&(l("[data-pad]").hidden=!(i||I<640))},ee=new ResizeObserver(J);ee.observe(e);let ne=new Te.Vector3,we=new Te.Vector3,Le=new Te.Vector3,lt=new Te.Vector3;function Ee(I,K){let ie=K/1e3,Pe=E.aspect;b.tick(I,K);let Re=!1;if(W==="ctl"&&ae.size&&!A&&(B?st(async ct=>{await Ne(ct)(qe())}):(E.getWorldDirection(ne),ne.y=0,ne.normalize(),we.crossVectors(ne,E.up).normalize(),Le.set(0,0,0),ae.has("up")&&Le.add(ne),ae.has("down")&&Le.sub(ne),ae.has("right")&&Le.add(we),ae.has("left")&&Le.sub(we),Le.lengthSq()>0&&(We&&F&&(We++,F=null,T.mood("neutral"),fe(a("room.you"))),Le.normalize().multiplyScalar(2.1*ie),$e(v.x+Le.x,v.z)||(v.x+=Le.x),$e(v.x,v.z+Le.z)||(v.z+=Le.z),C=Math.atan2(Le.x,Le.z),Re=!0,Q=1.4))),A){let ct=Math.min(1,(performance.now()-A.t0)/A.ms),zt=ct<.5?2*ct*ct:1-(-2*ct+2)**2/2;if(v.x=Te.MathUtils.lerp(A.from.x,A.to.x,zt),v.z=Te.MathUtils.lerp(A.from.z,A.to.z,zt),L=Te.MathUtils.lerp(A.from.y,A.to.y,zt)+Math.sin(Math.PI*ct)*.55,ct>.05&&ct<.6&&(C=Math.atan2(A.to.x-A.from.x,A.to.z-A.from.z)||C),ct>=1){let Se=A.res;L=A.to.y,A=null,Se()}}else if(F&&!Re){let ct=F.x-v.x,zt=F.z-v.z,Se=Math.hypot(ct,zt),oe=Math.min(Se,1.5*F.sp*ie);if(Se<.04){let ot=F.res;F=null,ot()}else v.x+=ct/Se*oe,v.z+=zt/Se*oe,C=Math.atan2(ct,zt),Re=!0,Q=F.sp}N+=((Re?1:0)-N)*Math.min(1,ie*10),z+=ie*11*Q,_=Y(_,C,Math.min(1,ie*9));let Ye=Math.abs(Math.sin(z))*.08*N;T.root.position.set(v.x,L+Ye,v.z),T.root.rotation.set(0,_,Math.sin(z)*.07*N),T.shadow&&(T.shadow.position.y=.002-Ye/T.root.scale.y,T.shadow.material.opacity=1-Math.min(.7,Ye*4)),T.tick(I,K),T.lod(Math.min(320,D*.35));let Mt=Pe<1?.75:.3,ha=Le.set(Te.MathUtils.lerp(-.3,v.x,Mt),.5,Te.MathUtils.lerp(-.6,v.z,Mt));Me.lerp(ha,Math.min(1,ie*2.5));let rr=Pe<1?10.5:o.compact?11.4:12.6;if(E.position.set(Me.x+rr*.42,Me.y+rr*.62,Me.z+rr*.66),E.lookAt(Me),f.render(p,E),te.hidden||(performance.now()>ue&&(te.hidden=!0),lt.set(0,T.H*1.12,0).applyMatrix4(T.root.matrixWorld).project(E),te.style.left=`${(lt.x+1)/2*q}px`,te.style.top=`${(1-lt.y)/2*D}px`),W==="ctl"){let ct=!F&&!A&&Xa(),zt=B?a("room.getOff"):ct?a("room.use",{label:a(`room.places.${ct}`)}):"",Se=l("[data-prompt]");Se.textContent!==zt&&(Se.textContent=zt),Se.hidden=!zt}}let se=0,tt=0,Jt=!0,ho=!1,Ho=I=>{if(se=0,ho||!Jt||document.hidden)return;let K=Math.min(100,tt?I-tt:16);tt=I,J(),Ee(I,K),se=requestAnimationFrame(Ho)},vt=()=>{!se&&!ho&&Jt&&!document.hidden&&(tt=0,se=requestAnimationFrame(Ho))},ta=new IntersectionObserver(([I])=>{Jt=I.isIntersecting,vt()},{rootMargin:"64px"});return ta.observe(e),document.addEventListener("visibilitychange",vt),Fe(t),J(),Lo(!1),vt(),{el:e,say:be,message:Ka,react:ys,setMode:Pa,get mode(){return W},setName(I){s=I||"ot",l("[data-name]").textContent=s},setSpec(I){let K=T.moodName;Fe(I),T.mood(K||"neutral"),T.gesture("celebrate")},setTheme(I){ho||(x(I),vt())},get theme(){return b.id},destroy(){ho=!0,We++,cancelAnimationFrame(se);for(let I of lo)clearTimeout(I);ta.disconnect(),ee.disconnect(),removeEventListener("keydown",ea),removeEventListener("keyup",ea),removeEventListener("blur",tr),document.removeEventListener("visibilitychange",vt),T.dispose(),p.remove(T.root),y0(p),d.dispose(),f.dispose(),f.forceContextLoss?.(),h.remove(),n.remove(),e.classList.remove("otr","compact")}}}var Te,b0,Sa,Ou,Lr,qu,yi,bi,Gu,g0,Nu,y0,x0=Ke(()=>{Te=_t(Zo(),1),b0=_t(gn(),1);An();$0();Pn();Qe();Sa=e=>String(e??"").replace(/[&<>"]/g,t=>({"&":"&","<":"<",">":">",'"':"""})[t]),Ou=1.3,Lr={window:{at:[-1.2,-3],face:Math.PI},sofa:{at:[-3.2,.5],seat:[-4.15,.66,.5],face:Math.PI/2},rug:{at:[.6,.9],face:.35},bed:{at:[1.9,-2.2],seat:[3.55,.68,-2.3],face:.3},desk:{at:[.95,-2.75],face:Math.PI},plant:{at:[-3.5,-2.6],face:-2.3},front:{at:[.9,2],face:.25}},qu=[[-5,-.95,-3.7,1.95],[-4.75,-1.85,-3.85,-1.05],[2.45,-4,4.65,-.95],[0,-4,2.05,-3],[-4.8,-3.85,-3.9,-2.95]],yi=[-4.6,4.6,-3.6,3.6],bi=.32,Gu=`
|
|
348
348
|
.otr{position:relative;overflow:hidden;border-radius:inherit;min-height:260px;background:#2a1f55;outline:none;--otr-glass:rgb(10 7 32 / .62);--otr-line:rgb(255 255 255 / .14);--otr-accent:#ffd23f;--otr-accent-ink:#1a1240;color:#f4f1ff}
|
|
349
349
|
.otr canvas{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:crosshair}
|
|
350
350
|
.otr button{font:inherit;color:inherit;cursor:pointer}
|
|
@@ -541,7 +541,7 @@ ${vd(this.brain?.persona?.locale||this.brain?.persona?.language)}`;await this.br
|
|
|
541
541
|
fill="${this.color}" stroke="#fff" stroke-width="1.6" stroke-linejoin="round"/></svg>
|
|
542
542
|
<div class="tag"><span class="n"></span><small class="s"></small></div>
|
|
543
543
|
</div>`,o.querySelector(".n").textContent=this.name,o.querySelector(".s").textContent=this.t("widget.pointer.hint"),document.documentElement.appendChild(t),this._host=t,this._place(this.x,this.y)}_show(){this.visible&&(this._mount(),this._host.shadowRoot.querySelector(".n").textContent=this.name,clearTimeout(this._hideTimer),this._raise(),this._host.classList.add("on"))}_raise(){let t=this._host;if(t?.showPopover)try{if(t.matches(":popover-open")){if(!document.querySelector("dialog:modal"))return;t.hidePopover()}t.showPopover()}catch{}}_scheduleHide(){clearTimeout(this._hideTimer),this._hideTimer=setTimeout(()=>this._host?.classList.remove("on"),2500)}_label(t){let o=this._host?.shadowRoot.querySelector(".s");o&&(o.textContent=t||this.t("widget.pointer.hint"))}_ripple(){let t=this._host?.shadowRoot.querySelector(".ring");t&&(t.classList.remove("go"),t.offsetWidth,t.classList.add("go"))}},Yi=(e,t,o)=>Math.max(t,Math.min(o,e));async function qd(e,t){let o=e.getBoundingClientRect();if(t)return o;for(let a=0;a<30;a++){await Rs(40);let s=e.getBoundingClientRect();if(Math.abs(s.top-o.top)<1&&Math.abs(s.left-o.left)<1)return s;o=s}return o}function Gd(e){let t=e.getBoundingClientRect();return(t.width<2||t.height<2||getComputedStyle(e).opacity==="0")&&e.labels?.length?e.labels[0]:e}function Nd(e){return e.closest?.("label")?.control||null}function ml(e){let t=[];for(let o=e;o&&o.nodeType===1;o=o.parentElement||o.getRootNode()?.host)t.push(o);return t}function Bd(e){let t=(e.getAttribute?.("aria-label")||e.innerText||"").trim().replace(/\s+/g," ").slice(0,50),o=e.id?`#${e.id}`:"";return`${e.tagName.toLowerCase()}${o}${t?` \xAB${t}\xBB`:""}`}function qa(){let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;return e}function Zi(e){let t=e.closest?.(Wi)||(e.matches?.(Wi)?e:null);t&&qa()!==t&&t.focus({preventScroll:!0})}function yl(e){return e.isContentEditable?!0:e.tagName==="TEXTAREA"?!e.readOnly&&!e.disabled:e.tagName!=="INPUT"?!1:!e.readOnly&&!e.disabled&&/^(text|search|email|url|tel|number|password|date|time|datetime-local|month|week)?$/.test(e.type==="text"?"":e.type)}function bl(e){if(e.select)e.select();else if(e.isContentEditable){let t=document.createRange();t.selectNodeContents(e);let o=getSelection();o.removeAllRanges(),o.addRange(t)}}function As(e,t){let o=e.value??e.textContent,a=!1;try{a=document.execCommand("insertText",!1,t)}catch{}let s=e.value??e.textContent;if(a&&s!==o)return;if(e.isContentEditable){e.textContent+=t,e.dispatchEvent(new InputEvent("input",{bubbles:!0,inputType:"insertText",data:t}));return}let r=null;try{r=e.selectionStart}catch{}let i=e.value;if(r==null)Ls(e,i+t);else{let n=e.selectionEnd;Ls(e,i.slice(0,r)+t+i.slice(n));try{e.setSelectionRange(r+t.length,r+t.length)}catch{}}e.dispatchEvent(new InputEvent("input",{bubbles:!0,inputType:"insertText",data:t}))}function Ls(e,t){let o=e.tagName==="TEXTAREA"?HTMLTextAreaElement.prototype:e.tagName==="SELECT"?HTMLSelectElement.prototype:HTMLInputElement.prototype;Object.getOwnPropertyDescriptor(o,"value").set.call(e,t)}function Dd(){return[...document.querySelectorAll(Wi)].filter(e=>{if(e.closest("[data-ots-root], [inert], [hidden]"))return!1;let t=e.getBoundingClientRect();return t.width>0&&t.height>0&&getComputedStyle(e).visibility!=="hidden"})}function Qd(e,t){for(let o=e;o&&o!==document.body&&o!==document.documentElement;o=o.parentElement){let a=getComputedStyle(o),s=t==="x"?a.overflowX:a.overflowY;if((t==="x"?o.scrollWidth>o.clientWidth:o.scrollHeight>o.clientHeight)&&/(auto|scroll|overlay)/.test(s))return o}return document.scrollingElement||document.documentElement}var Id={enter:"Enter",return:"Enter",tab:"Tab",esc:"Escape",escape:"Escape",space:" ",spacebar:" ",backspace:"Backspace",delete:"Delete",supr:"Delete",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",arrowup:"ArrowUp",arrowdown:"ArrowDown",arrowleft:"ArrowLeft",arrowright:"ArrowRight",home:"Home",end:"End",pageup:"PageUp",pagedown:"PageDown"};function Vd(e){return Id[e.toLowerCase()]||(e.length===1?e:e[0].toUpperCase()+e.slice(1))}function Fd(e){return/^[a-z]$/i.test(e)?`Key${e.toUpperCase()}`:/^\d$/.test(e)?`Digit${e}`:e===" "?"Space":e.length>1?e:""}function Zd(e,t,o){let a=e.tagName,s=yl(e);if((o.ctrlKey||o.metaKey)&&t.toLowerCase()==="a")return bl(e);if(!(o.ctrlKey||o.metaKey||o.altKey))switch(t){case"Enter":return a==="TEXTAREA"||e.isContentEditable?As(e,`
|
|
544
|
-
`):a==="INPUT"&&e.form&&!/^(checkbox|radio|button|submit|reset)$/.test(e.type)?e.form.requestSubmit?e.form.requestSubmit():e.form.submit():e.matches("a[href], button, summary, [role=button], [role=link], [role=tab], [role=menuitem], input[type=submit], input[type=button]")?e.click():void 0;case" ":return s?As(e," "):e.matches("button, summary, [role=button], [role=checkbox], [role=switch], [role=tab], input[type=checkbox], input[type=radio]")?e.click():window.scrollBy({top:window.innerHeight*.8});case"Tab":{let r=Dd(),i=r.indexOf(e);return r[(i+(o.shiftKey?-1:1)+r.length)%r.length]?.focus()}case"Backspace":return s?document.execCommand("delete")||$l(e,-1):void 0;case"Delete":return s?document.execCommand("forwardDelete")||$l(e,1):void 0;case"ArrowUp":case"ArrowDown":{let r=t==="ArrowDown"?1:-1;if(a==="SELECT"){let i=Yi(e.selectedIndex+r,0,e.options.length-1);i!==e.selectedIndex&&(e.selectedIndex=i,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})));return}return a==="INPUT"&&(e.type==="number"||e.type==="range")?gl(e,r):s?void 0:window.scrollBy({top:r*60})}case"ArrowLeft":case"ArrowRight":return a==="INPUT"&&e.type==="range"?gl(e,t==="ArrowRight"?1:-1):void 0;case"PageDown":case"PageUp":s||window.scrollBy({top:(t==="PageDown"?1:-1)*window.innerHeight*.85});return;case"Home":case"End":s||window.scrollTo({top:t==="Home"?0:document.documentElement.scrollHeight});return;default:t.length===1&&s&&As(e,t)}}function $l(e,t){if(e.value==null)return;let o=e.selectionStart??e.value.length,a=e.selectionEnd??o;o===a&&(t<0?o=Math.max(0,o-1):a=Math.min(e.value.length,a+1)),Ls(e,e.value.slice(0,o)+e.value.slice(a)),e.setSelectionRange?.(o,o),e.dispatchEvent(new InputEvent("input",{bubbles:!0,inputType:t<0?"deleteContentBackward":"deleteContentForward"}))}function gl(e,t){try{t>0?e.stepUp():e.stepDown()}catch{return}e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}Qe();var Ml="input[type=password], [autocomplete^=cc-], [autocomplete=one-time-code], [data-ots-private], [data-ots-private] *",Wd=1500,gr=class{constructor({actions:t,context:o,bus:a,pointer:s=null,t:r=pe()}){this.t=r,this.actions=t,this.context=o,this.bus=a,this.pointer=s,this._tools=new Map,this._offs=[],this._timer=null}start(){let t=()=>{clearTimeout(this._timer),this._timer=setTimeout(()=>this.scan(),250)};this._offs.push(this.bus.on("context:mutation",t),this.bus.on("context:route",t)),this.scan()}stop(){clearTimeout(this._timer),this._offs.forEach(t=>t?.()),this._offs=[];for(let t of this._tools.keys())this.actions.unregister(t);this._tools.clear()}scan(){let t=new Map;for(let o of document.querySelectorAll("[data-ots-tool]")){if(o.closest("[data-ots-ignore], [data-ots-root]"))continue;let a=String(o.dataset.otsTool).trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"_").slice(0,64);if(!(!a||t.has(a))){if(this.actions.has(a)&&!this._tools.has(a)){console.warn(`[7ots] data-ots-tool="${a}" choca con una acci\xF3n existente; se ignora.`);continue}t.set(a,o)}}for(let[o,a]of this._tools)t.get(o)!==a&&(this.actions.unregister(o),this._tools.delete(o));for(let[o,a]of t)this._tools.get(o)!==a&&(this.actions.register(a.tagName==="FORM"?this._formTool(o,a):this._buttonTool(o,a)),this._tools.set(o,a))}list(){return[...this._tools.keys()]}_formTool(t,o){let a=Ud(o),s={},r=[];for(let n of a)s[n.name]=n.schema,n.required&&r.push(n.name);let i=[...o.querySelectorAll(Ml)].some(n=>n.required);return{name:t,category:"page",title:o.dataset.otsTitle||t,description:`[p\xE1gina] ${o.dataset.otsDescription||o.getAttribute("aria-label")||o.querySelector("legend, h2, h3")?.textContent?.trim()||t}`+(i?" (tiene campos privados que el usuario debe escribir antes)":""),parameters:{type:"object",properties:s,required:r},requiresAuth:o.hasAttribute("data-ots-auth"),confirm:wl(o,this.t),timeoutMs:6e4,handler:async(n,{ui:l})=>{if(!o.isConnected)return{ok:!1,error:"El formulario ya no est\xE1 en la p\xE1gina."};let h=Hs(o);for(let d of a){if(!(d.name in n))continue;let p=n[d.name],u=d.pick(p);if(!u)return{ok:!1,error:`Valor no v\xE1lido para ${d.name}: ${p}`};if(this.pointer&&h&&Hs(u))if(d.kind==="text")await this.pointer.type(u,String(p),{clear:!0}),u.dispatchEvent(new Event("change",{bubbles:!0}));else if(d.kind==="check"||d.kind==="radio"){let g=d.kind==="radio"?!0:p===!0||p==="true";u.checked!==g&&await this.pointer.click(u)}else await this.pointer.moveTo(u),pr(u,d.kind==="number"?String(p):p);else pr(u,String(p))}if(!o.checkValidity()){let d=[...o.elements].filter(p=>p.willValidate&&!p.validity.valid);return h&&o.reportValidity(),{ok:!1,error:`El formulario no es v\xE1lido: ${d.map(p=>`${p.name||p.id}: ${p.validationMessage}`).join("; ")}`}}let f=o.querySelector("[type=submit], button:not([type])");this.pointer&&h&&f&&Hs(f)&&await this.pointer.moveTo(f);let c=xl(o);return o.requestSubmit?o.requestSubmit(f||void 0):o.submit(),h||l?.toast?.({message:this.t("widget.pageTools.done",{title:o.dataset.otsTitle||t.replace(/_/g," ")}),type:"success"}),{ok:!0,data:await c??"Enviado."}}}}_buttonTool(t,o){return{name:t,category:"page",title:o.dataset.otsTitle||t,description:`[p\xE1gina] ${o.dataset.otsDescription||o.getAttribute("aria-label")||o.textContent.trim().slice(0,80)||t}`,parameters:{type:"object",properties:{}},requiresAuth:o.hasAttribute("data-ots-auth"),confirm:wl(o,this.t),handler:async()=>{if(!o.isConnected)return{ok:!1,error:"El bot\xF3n ya no est\xE1 en la p\xE1gina."};let a=xl(o);return this.pointer&&Hs(o)?await this.pointer.click(o):o.click(),{ok:!0,data:await a??"Hecho."}}}}};function Ud(e){let t=new Map;for(let a of e.elements)!a.name||a.disabled||a.matches(Ml)||a.closest("[data-ots-ignore]")||/^(hidden|submit|button|reset|file|image)$/.test(a.type)||(t.has(a.name)||t.set(a.name,[]),t.get(a.name).push(a));let o=[];for(let[a,s]of t){let r=s[0],i=r.dataset.otsDescription||vl(r)||r.placeholder||a,n,l="text",h=()=>r;r.type==="radio"?(l="radio",n={type:"string",enum:s.map(c=>c.value),description:`${vl(r.closest("fieldset")?.querySelector("legend"))||i}`},h=c=>s.find(d=>d.value===c)||null):r.type==="checkbox"?(l="check",n={type:"boolean",description:i}):r.tagName==="SELECT"?(l="select",n={type:"string",enum:[...r.options].filter(f=>!f.disabled&&f.value!=="").map(f=>f.value),description:i}):r.type==="number"||r.type==="range"?(l="number",n={type:"number",description:[i,r.min&&`m\xEDn. ${r.min}`,r.max&&`m\xE1x. ${r.max}`].filter(Boolean).join(", ")}):n={type:"string",description:i+(r.type&&r.type!=="text"&&r.tagName==="INPUT"?` (${r.type})`:"")},o.push({name:a,schema:n,kind:l,pick:h,required:s.some(f=>f.required)})}return o}function wl(e,t=pe()){let o=e.dataset.otsConfirm;if(o==="false")return!1;let a=e.dataset.otsTitle||e.dataset.otsTool.replace(/_/g," ");return s=>{if(o&&o!=="true")return o.replace(/\{(\w+)\}/g,(i,n)=>String(s?.[n]??""));let r=Object.entries(s||{}).map(([i,n])=>`${i}: **${n}**`).join(", ");return r?t("widget.confirm.pageToolWith",{title:a,detail:r}):t("widget.confirm.pageTool",{title:a})}}function xl(e){let t=e.closest("form, [role=dialog], section, main")||document.body,o=kl(t);return new Promise(a=>{let s=n=>{clearTimeout(i),e.removeEventListener("ots-result",r),a(n)},r=n=>s(n.detail??"Hecho."),i=setTimeout(()=>{let n=kl(t.isConnected?t:document.body);s(n&&n!==o?n:null)},Wd);e.addEventListener("ots-result",r)})}function kl(e){return[...e.querySelectorAll("[role=status], [role=alert], [aria-live]")].map(t=>t.innerText?.trim()).filter(Boolean).join(" \xB7 ").slice(0,500)}function vl(e){if(!e)return"";let t=e.labels?.[0]||(e.tagName==="LEGEND"?e:null);return(t?[...t.childNodes].filter(a=>a.nodeType===3).map(a=>a.textContent).join(" "):e.getAttribute?.("aria-label")||"").replace(/\s+/g," ").trim().slice(0,80)}function Hs(e){if(!e.isConnected||e.closest("[hidden], [inert]"))return!1;let t=e.getBoundingClientRect();return t.width>0&&t.height>0}var yr=class{constructor({endpoint:t,siteKey:o=null,timeoutMs:a=6e4,locale:s=null}={}){if(!t)throw new Error("[7ots] llm.endpoint es obligatorio");this.endpoint=t.replace(/\/$/,""),this.siteKey=o,this.timeoutMs=a,this.locale=s,this.session=Yd()}async step({system:t,messages:o,tools:a,signal:s}){let r=new AbortController,i=setTimeout(()=>r.abort(),this.timeoutMs);s?.addEventListener("abort",()=>r.abort(),{once:!0});try{let n=await fetch(`${this.endpoint}/chat`,{method:"POST",headers:{"Content-Type":"application/json",...this.siteKey?{"X-Site-Key":this.siteKey}:{},...jo(this.locale)},body:JSON.stringify({system:t,messages:o,tools:a,session:this.session}),signal:r.signal});if(!n.ok){let l=await n.text().catch(()=>"");throw new Error(`LLM proxy ${n.status}: ${l.slice(0,200)}`)}return await n.json()}finally{clearTimeout(i)}}};function jo(e){let t=typeof e=="function"?e():e;return t?{"Accept-Language":String(t)}:{}}function Yd(){let e=sr("llm"),t=e.get("session");if(!t){let o=new Uint8Array(12);globalThis.crypto?.getRandomValues?.(o),t=[...o].map(a=>(a||Math.floor(Math.random()*256)).toString(16).padStart(2,"0")).join(""),e.set("session",t)}return t}mo();var Iu="0.170.0",Vu=`https://cdn.jsdelivr.net/npm/three@${Iu}`,ki=()=>String(globalThis.OTS_THREE_BASE||Vu).replace(/\/$/,"");function Fu(){return{imports:{three:`${ki()}/build/three.module.js`,"three/addons/":`${ki()}/examples/jsm/`}}}function jn(){if(typeof document>"u")return!1;for(let t of document.querySelectorAll('script[type="importmap"]'))try{if(JSON.parse(t.textContent||"{}").imports?.three)return!0}catch{}let e=document.createElement("script");return e.type="importmap",e.textContent=JSON.stringify(Fu()),(document.head||document.documentElement).prepend(e),!0}var xi=null;function Zu(){return xi??=(async()=>{if(globalThis.__OTS_THREE__?.three)return globalThis.__OTS_THREE__;let e=i=>`${ki()}/${i}/+esm`,[t,o,a,s,r]=await Promise.all([import(`${ki()}/+esm`),import(e("examples/jsm/utils/BufferGeometryUtils.js")),import(e("examples/jsm/environments/RoomEnvironment.js")),import(e("examples/jsm/loaders/GLTFLoader.js")),import(e("examples/jsm/geometries/RoundedBoxGeometry.js"))]);return globalThis.__OTS_THREE__={three:t,BufferGeometryUtils:o,RoomEnvironment:a,GLTFLoader:s,RoundedBoxGeometry:r}})(),xi.catch(()=>{xi=null}),xi}async function Ko(){return jn(),await Zu(),Promise.resolve().then(()=>(_0(),E0))}var Wu="https://cdn.jsdelivr.net/gh/met4citizen/TalkingHead@1.7.0/modules/talkinghead.mjs",Uu="https://cdn.jsdelivr.net/gh/met4citizen/TalkingHead@1.7.0/avatars/brunette.glb",vi=["neutral","happy","angry","sad","fear","disgust","love","sleep"],Mi=["handup","index","ok","thumbup","thumbdown","side","shrug","namaste"],Ei=[...vi,"surprised"],_i=[...new Set([...Mi,...Mr,...Object.keys(wa)])],On={wave:"handup",hi:"handup",hello:"handup",celebrate:"thumbup",thumbsup:"thumbup",thumbsdown:"thumbdown",point:"index",nod:"ok",yes:"ok",shrug:"shrug",bow:"namaste",wiggle:"side",think:"index",clap:"thumbup",cheer:"thumbup"},Yu={es:"fi",it:"fi",pt:"fi",ca:"fi",en:"en",de:"de",fr:"fr",fi:"fi",lt:"lt"},Ca=class{constructor({container:t,config:o={},language:a=document.documentElement.lang||"es"}){this.container=t,this.cfg=o===!1?!1:{url:Uu,body:"F",mood:"neutral",cameraView:"upper",module:Wu,...o},this.lang=this.cfg&&this.cfg.lipsyncLang||Yu[a.slice(0,2).toLowerCase()]||"en",this.head=null,this.mode="none",this._ctx=null,this._src=null,this._mimicTimer=null,this._speakTimer=null,this._resolveSpeak=null}async load(t){if(this.cfg&&this.cfg.mode==="3d-plush"&&this.cfg.character&&!this.cfg.image)return this._loadPlush();if(this.cfg===!1||this.cfg.mode==="2d"||this.cfg.mode==="3d-plush"||this.cfg.character&&!this.cfg.url&&this.cfg.mode!=="3d")return this._load2D();if(!S0())return console.info("[7ots] el navegador no tiene WebGL: avatar 2D"),this._load2D();try{jn();let{TalkingHead:o}=await import(this.cfg.module);this.head=new o(this.container,{ttsEndpoint:"",lipsyncModules:[this.lang],lipsyncLang:this.lang,cameraView:this.cfg.cameraView,avatarMood:this.cfg.mood,modelFPS:30}),await this.head.showAvatar({url:this.cfg.url,body:this.cfg.body,avatarMood:this.cfg.mood,lipsyncLang:this.lang},a=>t?.(a.lengthComputable?a.loaded/a.total:null)),this.mode="3d",this._vis=()=>document.hidden?this.head?.stop():this.head?.start(),document.addEventListener("visibilitychange",this._vis)}catch(o){console.warn("[7ots] avatar 3D no disponible, uso 2D:",o?.message||o);try{this.head?.dispose?.()}catch{}this.head=null,this.container.replaceChildren(),this._load2D()}return this.mode}async _loadPlush(){let t=this._plushToken={};if(!S0())return this._load2D();try{let o=await Ko();if(this._plushToken!==t||!this.cfg)return this.mode;this._ch?.destroy(),this.container.replaceChildren(),this._mouth=null,this._face=null;let a=o.createCharacter3D(this.container,this.cfg.character,{material:this.cfg.material||"plush",orbit:this.cfg.orbit===!0,quality:this.cfg.quality||"high",stage:{key:"overlay",zIndex:2147483001,maxDpr:1.5}});this._ch=a,this.mode=a.fallback?"2d":"3d-plush",this.cfg.mood&&a.mood(this.cfg.mood,{fx:!1})}catch(o){console.warn("[7ots] ot 3D no disponible, uso 2D:",o?.message||o),this._ch?.destroy?.(),this._ch=null,this.container.replaceChildren(),this._load2D()}return this.mode}_load2D(){this.mode="2d",this._ch?.destroy(),this._ch=null;let t=this.cfg&&this.cfg.character;if(t&&!this.cfg.image)return this.container.replaceChildren(),this._mouth=null,this._face=null,this._ch=Bt(this.container,t,{title:""}),this.cfg.mood&&this._ch.mood(this.cfg.mood),this.mode;let o=this.cfg&&this.cfg.image;if(o){this.container.innerHTML='<div class="ots-portrait"><img alt="" referrerpolicy="no-referrer"></div>';let a=this.container.querySelector("img");return a.onerror=()=>this._drawFace(),a.src=o,this._mouth=null,this._face=this.container.querySelector(".ots-portrait"),this.mode}return this._drawFace()}_drawFace(){this.mode="2d";let t=this.cfg&&this.cfg.face||{},o=[t.skin&&`--face-bg:${t.skin}`,t.eyes&&`--face-fg:${t.eyes}`].filter(Boolean).join(";");return this.container.innerHTML=`
|
|
544
|
+
`):a==="INPUT"&&e.form&&!/^(checkbox|radio|button|submit|reset)$/.test(e.type)?e.form.requestSubmit?e.form.requestSubmit():e.form.submit():e.matches("a[href], button, summary, [role=button], [role=link], [role=tab], [role=menuitem], input[type=submit], input[type=button]")?e.click():void 0;case" ":return s?As(e," "):e.matches("button, summary, [role=button], [role=checkbox], [role=switch], [role=tab], input[type=checkbox], input[type=radio]")?e.click():window.scrollBy({top:window.innerHeight*.8});case"Tab":{let r=Dd(),i=r.indexOf(e);return r[(i+(o.shiftKey?-1:1)+r.length)%r.length]?.focus()}case"Backspace":return s?document.execCommand("delete")||$l(e,-1):void 0;case"Delete":return s?document.execCommand("forwardDelete")||$l(e,1):void 0;case"ArrowUp":case"ArrowDown":{let r=t==="ArrowDown"?1:-1;if(a==="SELECT"){let i=Yi(e.selectedIndex+r,0,e.options.length-1);i!==e.selectedIndex&&(e.selectedIndex=i,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})));return}return a==="INPUT"&&(e.type==="number"||e.type==="range")?gl(e,r):s?void 0:window.scrollBy({top:r*60})}case"ArrowLeft":case"ArrowRight":return a==="INPUT"&&e.type==="range"?gl(e,t==="ArrowRight"?1:-1):void 0;case"PageDown":case"PageUp":s||window.scrollBy({top:(t==="PageDown"?1:-1)*window.innerHeight*.85});return;case"Home":case"End":s||window.scrollTo({top:t==="Home"?0:document.documentElement.scrollHeight});return;default:t.length===1&&s&&As(e,t)}}function $l(e,t){if(e.value==null)return;let o=e.selectionStart??e.value.length,a=e.selectionEnd??o;o===a&&(t<0?o=Math.max(0,o-1):a=Math.min(e.value.length,a+1)),Ls(e,e.value.slice(0,o)+e.value.slice(a)),e.setSelectionRange?.(o,o),e.dispatchEvent(new InputEvent("input",{bubbles:!0,inputType:t<0?"deleteContentBackward":"deleteContentForward"}))}function gl(e,t){try{t>0?e.stepUp():e.stepDown()}catch{return}e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}Qe();var Ml="input[type=password], [autocomplete^=cc-], [autocomplete=one-time-code], [data-ots-private], [data-ots-private] *",Wd=1500,gr=class{constructor({actions:t,context:o,bus:a,pointer:s=null,t:r=pe()}){this.t=r,this.actions=t,this.context=o,this.bus=a,this.pointer=s,this._tools=new Map,this._offs=[],this._timer=null}start(){let t=()=>{clearTimeout(this._timer),this._timer=setTimeout(()=>this.scan(),250)};this._offs.push(this.bus.on("context:mutation",t),this.bus.on("context:route",t)),this.scan()}stop(){clearTimeout(this._timer),this._offs.forEach(t=>t?.()),this._offs=[];for(let t of this._tools.keys())this.actions.unregister(t);this._tools.clear()}scan(){let t=new Map;for(let o of document.querySelectorAll("[data-ots-tool]")){if(o.closest("[data-ots-ignore], [data-ots-root]"))continue;let a=String(o.dataset.otsTool).trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"_").slice(0,64);if(!(!a||t.has(a))){if(this.actions.has(a)&&!this._tools.has(a)){console.warn(`[7ots] data-ots-tool="${a}" choca con una acci\xF3n existente; se ignora.`);continue}t.set(a,o)}}for(let[o,a]of this._tools)t.get(o)!==a&&(this.actions.unregister(o),this._tools.delete(o));for(let[o,a]of t)this._tools.get(o)!==a&&(this.actions.register(a.tagName==="FORM"?this._formTool(o,a):this._buttonTool(o,a)),this._tools.set(o,a))}list(){return[...this._tools.keys()]}_formTool(t,o){let a=Ud(o),s={},r=[];for(let n of a)s[n.name]=n.schema,n.required&&r.push(n.name);let i=[...o.querySelectorAll(Ml)].some(n=>n.required);return{name:t,category:"page",title:o.dataset.otsTitle||t,description:`[p\xE1gina] ${o.dataset.otsDescription||o.getAttribute("aria-label")||o.querySelector("legend, h2, h3")?.textContent?.trim()||t}`+(i?" (tiene campos privados que el usuario debe escribir antes)":""),parameters:{type:"object",properties:s,required:r},requiresAuth:o.hasAttribute("data-ots-auth"),confirm:wl(o,this.t),timeoutMs:6e4,handler:async(n,{ui:l})=>{if(!o.isConnected)return{ok:!1,error:"El formulario ya no est\xE1 en la p\xE1gina."};let h=Hs(o);for(let d of a){if(!(d.name in n))continue;let p=n[d.name],u=d.pick(p);if(!u)return{ok:!1,error:`Valor no v\xE1lido para ${d.name}: ${p}`};if(this.pointer&&h&&Hs(u))if(d.kind==="text")await this.pointer.type(u,String(p),{clear:!0}),u.dispatchEvent(new Event("change",{bubbles:!0}));else if(d.kind==="check"||d.kind==="radio"){let g=d.kind==="radio"?!0:p===!0||p==="true";u.checked!==g&&await this.pointer.click(u)}else await this.pointer.moveTo(u),pr(u,d.kind==="number"?String(p):p);else pr(u,String(p))}if(!o.checkValidity()){let d=[...o.elements].filter(p=>p.willValidate&&!p.validity.valid);return h&&o.reportValidity(),{ok:!1,error:`El formulario no es v\xE1lido: ${d.map(p=>`${p.name||p.id}: ${p.validationMessage}`).join("; ")}`}}let f=o.querySelector("[type=submit], button:not([type])");this.pointer&&h&&f&&Hs(f)&&await this.pointer.moveTo(f);let c=xl(o);return o.requestSubmit?o.requestSubmit(f||void 0):o.submit(),h||l?.toast?.({message:this.t("widget.pageTools.done",{title:o.dataset.otsTitle||t.replace(/_/g," ")}),type:"success"}),{ok:!0,data:await c??"Enviado."}}}}_buttonTool(t,o){return{name:t,category:"page",title:o.dataset.otsTitle||t,description:`[p\xE1gina] ${o.dataset.otsDescription||o.getAttribute("aria-label")||o.textContent.trim().slice(0,80)||t}`,parameters:{type:"object",properties:{}},requiresAuth:o.hasAttribute("data-ots-auth"),confirm:wl(o,this.t),handler:async()=>{if(!o.isConnected)return{ok:!1,error:"El bot\xF3n ya no est\xE1 en la p\xE1gina."};let a=xl(o);return this.pointer&&Hs(o)?await this.pointer.click(o):o.click(),{ok:!0,data:await a??"Hecho."}}}}};function Ud(e){let t=new Map;for(let a of e.elements)!a.name||a.disabled||a.matches(Ml)||a.closest("[data-ots-ignore]")||/^(hidden|submit|button|reset|file|image)$/.test(a.type)||(t.has(a.name)||t.set(a.name,[]),t.get(a.name).push(a));let o=[];for(let[a,s]of t){let r=s[0],i=r.dataset.otsDescription||vl(r)||r.placeholder||a,n,l="text",h=()=>r;r.type==="radio"?(l="radio",n={type:"string",enum:s.map(c=>c.value),description:`${vl(r.closest("fieldset")?.querySelector("legend"))||i}`},h=c=>s.find(d=>d.value===c)||null):r.type==="checkbox"?(l="check",n={type:"boolean",description:i}):r.tagName==="SELECT"?(l="select",n={type:"string",enum:[...r.options].filter(f=>!f.disabled&&f.value!=="").map(f=>f.value),description:i}):r.type==="number"||r.type==="range"?(l="number",n={type:"number",description:[i,r.min&&`m\xEDn. ${r.min}`,r.max&&`m\xE1x. ${r.max}`].filter(Boolean).join(", ")}):n={type:"string",description:i+(r.type&&r.type!=="text"&&r.tagName==="INPUT"?` (${r.type})`:"")},o.push({name:a,schema:n,kind:l,pick:h,required:s.some(f=>f.required)})}return o}function wl(e,t=pe()){let o=e.dataset.otsConfirm;if(o==="false")return!1;let a=e.dataset.otsTitle||e.dataset.otsTool.replace(/_/g," ");return s=>{if(o&&o!=="true")return o.replace(/\{(\w+)\}/g,(i,n)=>String(s?.[n]??""));let r=Object.entries(s||{}).map(([i,n])=>`${i}: **${n}**`).join(", ");return r?t("widget.confirm.pageToolWith",{title:a,detail:r}):t("widget.confirm.pageTool",{title:a})}}function xl(e){let t=e.closest("form, [role=dialog], section, main")||document.body,o=kl(t);return new Promise(a=>{let s=n=>{clearTimeout(i),e.removeEventListener("ots-result",r),a(n)},r=n=>s(n.detail??"Hecho."),i=setTimeout(()=>{let n=kl(t.isConnected?t:document.body);s(n&&n!==o?n:null)},Wd);e.addEventListener("ots-result",r)})}function kl(e){return[...e.querySelectorAll("[role=status], [role=alert], [aria-live]")].map(t=>t.innerText?.trim()).filter(Boolean).join(" \xB7 ").slice(0,500)}function vl(e){if(!e)return"";let t=e.labels?.[0]||(e.tagName==="LEGEND"?e:null);return(t?[...t.childNodes].filter(a=>a.nodeType===3).map(a=>a.textContent).join(" "):e.getAttribute?.("aria-label")||"").replace(/\s+/g," ").trim().slice(0,80)}function Hs(e){if(!e.isConnected||e.closest("[hidden], [inert]"))return!1;let t=e.getBoundingClientRect();return t.width>0&&t.height>0}var yr=class{constructor({endpoint:t,siteKey:o=null,timeoutMs:a=6e4,locale:s=null}={}){if(!t)throw new Error("[7ots] llm.endpoint es obligatorio");this.endpoint=t.replace(/\/$/,""),this.siteKey=o,this.timeoutMs=a,this.locale=s,this.session=Yd()}async step({system:t,messages:o,tools:a,signal:s}){let r=new AbortController,i=setTimeout(()=>r.abort(),this.timeoutMs);s?.addEventListener("abort",()=>r.abort(),{once:!0});try{let n=await fetch(`${this.endpoint}/chat`,{method:"POST",headers:{"Content-Type":"application/json",...this.siteKey?{"X-Site-Key":this.siteKey}:{},...jo(this.locale)},body:JSON.stringify({system:t,messages:o,tools:a,session:this.session}),signal:r.signal});if(!n.ok){let l=await n.text().catch(()=>"");throw new Error(`LLM proxy ${n.status}: ${l.slice(0,200)}`)}return await n.json()}finally{clearTimeout(i)}}};function jo(e){let t=typeof e=="function"?e():e;return t?{"Accept-Language":String(t)}:{}}function Yd(){let e=sr("llm"),t=e.get("session");if(!t){let o=new Uint8Array(12);globalThis.crypto?.getRandomValues?.(o),t=[...o].map(a=>(a||Math.floor(Math.random()*256)).toString(16).padStart(2,"0")).join(""),e.set("session",t)}return t}mo();var Iu="0.170.0",Vu=`https://cdn.jsdelivr.net/npm/three@${Iu}`,ki=()=>String(globalThis.OTS_THREE_BASE||Vu).replace(/\/$/,"");function Fu(){return{imports:{three:`${ki()}/build/three.module.js`,"three/addons/":`${ki()}/examples/jsm/`}}}function jn(){if(typeof document>"u")return!1;for(let t of document.querySelectorAll('script[type="importmap"]'))try{if(JSON.parse(t.textContent||"{}").imports?.three)return!0}catch{}let e=document.createElement("script");return e.type="importmap",e.textContent=JSON.stringify(Fu()),(document.head||document.documentElement).prepend(e),!0}var xi=null;function Zu(){return xi??=(async()=>{if(globalThis.__OTS_THREE__?.three)return globalThis.__OTS_THREE__;let e=i=>`${ki()}/${i}/+esm`,[t,o,a,s,r]=await Promise.all([import(`${ki()}/+esm`),import(e("examples/jsm/utils/BufferGeometryUtils.js")),import(e("examples/jsm/environments/RoomEnvironment.js")),import(e("examples/jsm/loaders/GLTFLoader.js")),import(e("examples/jsm/geometries/RoundedBoxGeometry.js"))]);return globalThis.__OTS_THREE__={three:t,BufferGeometryUtils:o,RoomEnvironment:a,GLTFLoader:s,RoundedBoxGeometry:r}})(),xi.catch(()=>{xi=null}),xi}async function Ko(){return jn(),await Zu(),Promise.resolve().then(()=>(_0(),E0))}var Wu="https://cdn.jsdelivr.net/gh/met4citizen/TalkingHead@1.7.0/modules/talkinghead.mjs",Uu="https://cdn.jsdelivr.net/gh/met4citizen/TalkingHead@1.7.0/avatars/brunette.glb",vi=["neutral","happy","angry","sad","fear","disgust","love","sleep"],Mi=["handup","index","ok","thumbup","thumbdown","side","shrug","namaste"],Ei=[...vi,"surprised"],_i=[...new Set([...Mi,...Mr,...Object.keys(wa)])],On={wave:"handup",hi:"handup",hello:"handup",celebrate:"thumbup",thumbsup:"thumbup",thumbsdown:"thumbdown",point:"index",nod:"ok",yes:"ok",shrug:"shrug",bow:"namaste",wiggle:"side",think:"index",clap:"thumbup",cheer:"thumbup"},Yu={es:"fi",it:"fi",pt:"fi",ca:"fi",en:"en",de:"de",fr:"fr",fi:"fi",lt:"lt"},Ca=class{constructor({container:t,config:o={},language:a=document.documentElement.lang||"es"}){this.container=t,this.cfg=o===!1?!1:{url:Uu,body:"F",mood:"neutral",cameraView:"upper",module:Wu,...o},this.lang=this.cfg&&this.cfg.lipsyncLang||Yu[a.slice(0,2).toLowerCase()]||"en",this.head=null,this.mode="none",this._ctx=null,this._src=null,this._mimicTimer=null,this._speakTimer=null,this._resolveSpeak=null}async load(t){if(this.cfg&&this.cfg.mode==="3d-plush"&&this.cfg.character&&!this.cfg.image)return this._loadPlush();if(this.cfg===!1||this.cfg.mode==="2d"||this.cfg.mode==="3d-plush"||this.cfg.character&&!this.cfg.url&&this.cfg.mode!=="3d")return this._load2D();if(!S0())return console.info("[7ots] el navegador no tiene WebGL: avatar 2D"),this._load2D();try{jn();let{TalkingHead:o}=await import(this.cfg.module);this.head=new o(this.container,{ttsEndpoint:"",lipsyncModules:[this.lang],lipsyncLang:this.lang,cameraView:this.cfg.cameraView,avatarMood:this.cfg.mood,modelFPS:30}),await this.head.showAvatar({url:this.cfg.url,body:this.cfg.body,avatarMood:this.cfg.mood,lipsyncLang:this.lang},a=>t?.(a.lengthComputable?a.loaded/a.total:null)),this.mode="3d",this._vis=()=>document.hidden?this.head?.stop():this.head?.start(),document.addEventListener("visibilitychange",this._vis)}catch(o){console.warn("[7ots] avatar 3D no disponible, uso 2D:",o?.message||o);try{this.head?.dispose?.()}catch{}this.head=null,this.container.replaceChildren(),this._load2D()}return this.mode}async _loadPlush(){let t=this._plushToken={};if(!S0())return this._load2D();try{let o=await Ko();if(this._plushToken!==t||!this.cfg)return this.mode;this._ch?.destroy(),this.container.replaceChildren(),this._mouth=null,this._face=null;let a=o.createCharacter3D(this.container,this.cfg.character,{material:this.cfg.material||"plush",orbit:this.cfg.orbit===!0,quality:this.cfg.quality||"high",stage:{key:"overlay",zIndex:2147483001,maxDpr:2}});this._ch=a,this.mode=a.fallback?"2d":"3d-plush",this.cfg.mood&&a.mood(this.cfg.mood,{fx:!1})}catch(o){console.warn("[7ots] ot 3D no disponible, uso 2D:",o?.message||o),this._ch?.destroy?.(),this._ch=null,this.container.replaceChildren(),this._load2D()}return this.mode}_load2D(){this.mode="2d",this._ch?.destroy(),this._ch=null;let t=this.cfg&&this.cfg.character;if(t&&!this.cfg.image)return this.container.replaceChildren(),this._mouth=null,this._face=null,this._ch=Bt(this.container,t,{title:""}),this.cfg.mood&&this._ch.mood(this.cfg.mood),this.mode;let o=this.cfg&&this.cfg.image;if(o){this.container.innerHTML='<div class="ots-portrait"><img alt="" referrerpolicy="no-referrer"></div>';let a=this.container.querySelector("img");return a.onerror=()=>this._drawFace(),a.src=o,this._mouth=null,this._face=this.container.querySelector(".ots-portrait"),this.mode}return this._drawFace()}_drawFace(){this.mode="2d";let t=this.cfg&&this.cfg.face||{},o=[t.skin&&`--face-bg:${t.skin}`,t.eyes&&`--face-fg:${t.eyes}`].filter(Boolean).join(";");return this.container.innerHTML=`
|
|
545
545
|
<svg class="ots-face" viewBox="0 0 120 120" aria-hidden="true"${o?` style="${o}"`:""}>
|
|
546
546
|
<circle cx="60" cy="60" r="54" class="ots-face-bg"/>
|
|
547
547
|
<g class="ots-eyes"><ellipse cx="42" cy="50" rx="6" ry="8"/><ellipse cx="78" cy="50" rx="6" ry="8"/></g>
|