433 lines
87 KiB
HTML
433 lines
87 KiB
HTML
<!doctype html>
|
|
<html><head><meta charset="utf-8" />
|
|
<!-- Generated by build.sh from ui/src/ — edit those, not this. -->
|
|
<style>html,body{margin:0;background:transparent;overflow:hidden}</style>
|
|
</head><body>
|
|
<script>
|
|
var PetPet=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=(e,t)=>Math.max(e.left,Math.min(e.right,t)),n=(e,n,r,i)=>{let{u:a}=r,o=e.top-n.top;if(o>r.maxUp)return null;let s=o>=0?r.maxReach:r.maxReach*(1+Math.min(1,-o/(4*a))*.6),c=Math.min(a*.45,(n.right-n.left)/2),l=i??(e.left+e.right)/2,u,d;if(n.left>=e.right)u=e.right-a*.15,d=n.left+c;else if(n.right<=e.left)u=e.left+a*.15,d=n.right-c;else if(o>a*.3){let t=n.left-e.left,r=e.right-n.right,i=Math.abs(l-n.left)<=Math.abs(l-n.right);t>a*.8&&(i||r<=a*.8)?(u=n.left-a*.55,d=n.left+c):r>a*.8?(u=n.right+a*.55,d=n.right-c):(u=Math.max(n.left+c,Math.min(n.right-c,l)),d=u)}else if(o<-a*.3){if(n.left<e.left-a*.5&&(l-e.left<e.right-l||n.right<=e.right+a*.5))u=e.left+a*.15,d=Math.max(n.left+c,e.left-a*.6);else if(n.right>e.right+a*.5)u=e.right-a*.15,d=Math.min(n.right-c,e.right+a*.6);else return null}else u=Math.max(Math.max(e.left,n.left),Math.min(Math.min(e.right,n.right),l)),d=u;u=t(e,u),d=t(n,d);let f=Math.abs(d-u);return f>s?null:{takeoff:u,land:d,cost:f+Math.abs(o)*.6+a*2}},r=(e,t,r,i,a,o=160)=>{let s=e.slice(0,o),c=s.findIndex(e=>e.id===t),l=s.findIndex(e=>e.id===i);if(c<0||l<0)return null;if(c===l)return[];let u=s.length,d=Array(u).fill(1/0),f=Array(u).fill(null),p=Array(u).fill(0),m=Array(u).fill(!1);for(d[c]=0,p[c]=r;;){let e=-1;for(let t=0;t<u;t++)!m[t]&&d[t]<1/0&&(e<0||d[t]<d[e])&&(e=t);if(e<0||e===l)break;m[e]=!0;let t=s[e];for(let r=0;r<u;r++){if(r===e||m[r])continue;let i=n(t,s[r],a,p[e]);if(!i)continue;let o=d[e]+Math.abs(i.takeoff-p[e])*.5+i.cost;o<d[r]&&(d[r]=o,p[r]=i.land,f[r]={node:e,edge:{to:r,...i}})}}if(d[l]===1/0)return null;let h=[];for(let e=l;e!==c;){let t=f[e];if(!t)return null;h.unshift({from:s[t.node],to:s[e],takeoff:t.edge.takeoff,land:t.edge.land}),e=t.node}return h},i=(e,t,n,r)=>{let i=Math.max(0,-t)+r,a=-Math.sqrt(2*n*i),o=-a/n,s=Math.max(i+t,.01),c=o+Math.sqrt(2*s/n);return{vx:e/c,vy:a,time:c}};function*a(e){let t=0;for(;t<e;)t+=yield}function*o(e,t,n=1){for(e.anim.play(t,!0,n);!e.anim.done;)yield}function*s(e,t,n){e.anim.play(t,!0),yield*a(n)}var c=e=>({u:e.u,maxUp:e.cfg.physics.jumpHeight*e.u*.92,maxReach:e.cfg.physics.jumpReach*e.u});function*l(e,t,n=!1){let r=e.body;if(!r.grounded)return!1;let i=r.surface,a=Math.max(i.left,Math.min(i.right,t));if(Math.abs(a-r.x)<1)return Math.abs(a-t)<2;let o=e.cfg.physics;for(r.walk(a,(n?o.runSpeed:o.walkSpeed)*e.u),e.anim.play(n?`run`:`walk`);!r.arrived;){if(!r.grounded)return!1;yield}return Math.abs(a-t)<2}function*u(e){let t=e.landing;e.landing=null,t?.kind===`ledge`?yield*o(e,`climb`):(t?.height??0)>e.u*3.5?yield*o(e,`landHard`):yield*o(e,`land`)}function*d(e){for(;!e.body.grounded;)e.anim.play(`fall`),yield;yield*u(e)}function*f(e,t){let n=e.body;if(n.face(t.land-n.x),yield*o(e,`crouch`),!n.grounded)return!1;let r=e.world.byId(t.to.id);if(!r)return!1;let a=Math.max(r.left,Math.min(r.right,t.land+(r.ex-t.to.ex)))-n.x,{vx:s,vy:c}=i(a,r.top-n.y,e.cfg.physics.gravity*e.u,e.u*(.3+Math.min(.7,Math.abs(a)/(e.u*7))));for(Math.random()<e.cfg.behavior.clumsiness&&(s*=.86,c*=.92),n.launch(s,c,r);!n.grounded;)e.anim.play(n.vy<0?`jumpUp`:`jumpDown`),yield;yield*u(e);let l=n.surface;return!!l&&(l.id===r.id||l.el!==null&&l.el===r.el)}function*p(e,t){for(let n of t){let t=e.body.surface;if(!t)return!1;let r=n.takeoff+(t.el===n.from.el?t.ex-n.from.ex:0);if(!(yield*l(e,r,Math.abs(r-e.body.x)>e.u*4))&&!e.body.grounded||!(yield*f(e,n)))return!1}return!0}function*m(e,t,n,i=!1){for(let a=0;a<3;a++){e.body.grounded||(yield*d(e));let a=e.body.surface;if(!a)return!1;if(a.id!==t){let n=r(e.world.surfaces,a.id,e.body.x,t,c(e));if(!n)return!1;if(!(yield*p(e,n)))continue}let o=e.body.surface;if(!o||o.id!==t){if(o&&e.world.byId(t)?.el===o.el)return!0}else return n!==null&&(yield*l(e,n,i)),!0}return!1}var h={hips:[-.3,.33,-.38,.2],legW:.12,cap:.06,bodyH:.58,gap:.1,halfW:.5},g=e=>{let t=-h.gap*e.legLength,n=t-h.bodyH*e.chubby;return{yb:t,yt:n,h:t-n,cy:(t+n)/2}},_=()=>({bx:0,by:0,rot:0,piv:0,sx:1,sy:1,lean:0,fbx:0,fby:0,ffx:0,ffy:0,nbx:0,nby:0,nfx:0,nfy:0,float:0,grip:0,arm:0,back:!1,feet:null,fx:0,fy:0,tilt:0,upright:0,earF:0,earN:0,earDown:0,eye:`dot`,eyeOpen:1,lookX:0,lookY:0,mouth:`w`,mouthOpen:0,cheek:0,blush:0,tail:0,phase:0,prop:`none`}),v=e=>({..._(),...e}),y=Math.PI*2,b=(e,t,n)=>Math.max(t,Math.min(n,e)),x=(e,t,n)=>e+(t-e)*n,S=(e,t=1,n=0)=>Math.sin((e*t+n)*y),C=(e,t=1,n=0)=>.5-.5*Math.cos((e*t+n)*y),w=e=>1-(1-e)*(1-e),ee=e=>e<.5?2*e*e:1-(-2*e+2)**2/2,T=(e,t,n)=>b((e-t)/(n-t),0,1),E=(e,t,n)=>Math.sin(T(e,t,n)*Math.PI),te=e=>e<=0?0:e>=1?1:2**(-8*e)*Math.sin((e*6-.75)*(2*Math.PI/3))+1,ne=-.85,D=e=>({rot:ne*e,piv:-1,arm:Math.min(1,e*1.6),upright:.85,fbx:.03*e,nbx:.05*e}),O=(e,t)=>e===t?.1:e===t+1?.55:1,re=(e,t,n,r)=>({nfx:n*e,fbx:n*e,ffx:-n*e,nbx:-n*e,nfy:-r*Math.max(0,t),fby:-r*Math.max(0,t),ffy:-r*Math.max(0,-t),nby:-r*Math.max(0,-t)}),k=(e,t,n=2)=>{let r=r=>Math.sin((e*n+r)*Math.PI*2)*t;return{fbx:r(0),fby:r(.25),ffx:r(.5),ffy:r(.75),nbx:r(.33),nby:r(.58),nfx:r(.83),nfy:r(.08)}},A={w:1.7,up:1.4},j={up:1.5},M={by:.07,sy:.96},ie={sit:{frames:16,fps:6,loop:!0,pose:(e,t)=>({...M,sy:.96+.02*S(e),eyeOpen:t>=8&&t<12?.45:O(t,14),tail:.3*S(e)})},groom:{frames:20,fps:10,loop:!1,box:A,pose:e=>{let t=E(e,0,1)**.5,n=S(e,4);return{...D(.8*t),nfx:(.05+.04*n)*t,nfy:(-.1-.05*S(e,4,.25))*t,ffx:(.04-.03*n)*t,ffy:-.08*t,tilt:.08*n*t,eye:t>.5?`happy`:`dot`,earDown:.3*t}}},stretch:{frames:16,fps:8,loop:!1,pose:e=>{let t=E(e,0,.55),n=E(e,.45,1);return{sx:1+.12*t+.06*n,sy:1-.1*t,rot:.14*t-.08*n,piv:t>n?-1:1,ffx:.14*t,nfx:.16*t,fbx:-.1*n,nbx:-.12*n,eye:t+n>.4?`closed`:`dot`,mouth:t>.5?`o`:`w`,mouthOpen:t,earDown:.5*(t+n)}}},yawn:{frames:16,fps:10,loop:!1,box:A,pose:e=>{let t=E(e,.05,.95);return{...D(.3*t),mouth:t>.25?`open`:`w`,mouthOpen:t,eye:t>.3?`closed`:`dot`,earDown:.5*t,sy:1+.04*t}}},look:{frames:20,fps:8,loop:!1,pose:(e,t)=>{let n=T(e,.1,.35)-T(e,.55,.8)*2+T(e,.85,1);return{lookX:n,fx:.02*n,tilt:.08*n,earF:-.15*n,eyeOpen:O(t,9)}}},sniff:{frames:16,fps:12,loop:!1,pose:(e,t)=>{let n=E(e,0,1)**.6;return{rot:.1*n,piv:-1,ffx:.04*n,nfx:.05*n,fy:.006*S(e,8)*n,lookY:.5*n,mouth:t%4<2?`w`:`o`,mouthOpen:.2,earN:.08*S(e,4)}}},curious:{frames:12,fps:8,loop:!0,box:A,pose:e=>({...D(.55),lookY:-.6,lookX:.2,tilt:-.12+.08*S(e),earN:.15,earF:.1*S(e,2),nfy:-.02*C(e,2)})},curiousDown:{frames:12,fps:8,loop:!0,pose:e=>({rot:.18,piv:1,lean:.06,ffx:.06,nfx:.08,lookY:.6,lookX:.3,tilt:.14+.06*S(e),earN:.12*S(e,2)})},sleep:{frames:16,fps:4,loop:!0,pose:e=>({...M,sy:.94+.03*S(e),sx:1+.015*S(e),eye:`closed`,mouth:`w`,earDown:.55,blush:.3,phase:e})},fallAsleep:{frames:12,fps:8,loop:!1,pose:(e,t)=>{let n=ee(e);return{by:M.by*n,sy:x(1,.94,n),eyeOpen:t<4?1-.15*t:t<6?.9:.2,eye:e>.85?`closed`:`dot`,earDown:.55*n}}},wake:{frames:12,fps:10,loop:!1,box:A,pose:e=>{let t=E(e,.1,.8);return{by:M.by*(1-w(T(e,0,.3))),...D(.35*t),eye:e<.5?`closed`:`dot`,mouth:t>.4?`open`:`w`,mouthOpen:t,earN:.2*S(e,3)*T(e,.6,1),earF:.2*S(e,3,.2)*T(e,.6,1)}}},eat:{frames:24,fps:12,loop:!1,box:A,pose:(e,t)=>{let n=w(T(e,0,.15))*(1-w(T(e,.85,1))),r=t%4<2;return{...D(.7*n),nfx:.06*n,nfy:-.12*n,ffx:.05*n,ffy:-.1*n,prop:e>.08&&e<.7?`seed`:`none`,cheek:w(T(e,.15,.7)),mouth:r?`w`:`o`,mouthOpen:.3,fy:r?.006:-.004,eye:e>.7?`happy`:`dot`,blush:.4}}}},ae=(e,t,n)=>{let r=T(e,t,n);return{back:r>.5,sy:Math.max(.12,Math.abs(1-2*r))}},oe={happy:{ease:0,frames:16,fps:14,loop:!1,box:j,pose:e=>{let t=E(e,0,.45)+.6*E(e,.45,.8);return{by:-.14*t,float:Math.min(1,t*2),sy:1+.06*t-.08*E(e,.8,1),ffy:-.04*t,nfy:-.05*t,eye:`happy`,mouth:`smile`,blush:.8,earN:.2*t,earF:.15*t,tail:S(e,3)}}},purr:{frames:16,fps:8,loop:!0,pose:e=>({by:.04,sy:.97+.02*S(e,2),sx:1+.01*S(e,2),tilt:.08*S(e),eye:`happy`,mouth:`w`,blush:1,earDown:.4,tail:S(e,2)})},roll:{frames:18,fps:14,loop:!1,pose:e=>{let t=T(e,0,.25),n=T(e,.75,1),r=t>.5&&n<.5,i=t>=1&&n<=0;return{...r?k(e,.06,3):{},back:r,sy:e<.25?Math.max(.12,Math.abs(1-2*t)):e>.75?Math.max(.12,Math.abs(1-2*n)):1,bx:i?.04*S(e,2):0,eye:`happy`,mouth:i?`open`:`w`,mouthOpen:.6,blush:1,tail:S(e,4)}}},squish:{ease:0,frames:8,fps:10,loop:!0,pose:e=>({sy:.78+.015*S(e),sx:1.12-.01*S(e),eye:`closed`,mouth:`w`,blush:.9,earDown:.8})},unsquish:{frames:8,fps:16,loop:!1,pose:e=>{let t=te(e);return{sy:x(.78,1,t),sx:x(1.12,1,t),earDown:.8*(1-e),eye:e<.4?`closed`:`dot`,blush:.6}}},startle:{ease:0,frames:10,fps:16,loop:!1,box:j,pose:e=>{let t=E(e,0,.6);return{by:-.25*t,float:Math.min(1,t*2),sy:1+.08*t-.1*E(e,.6,1),fby:.04*t,nby:.04*t,ffy:-.04*t,nfy:-.05*t,eye:`wide`,mouth:`o`,mouthOpen:.8,earN:.3*t,earF:.3*t,tail:1}}},dizzy:{frames:16,fps:8,loop:!0,pose:e=>({rot:.07*S(e),piv:S(e)>0?1:-1,bx:.03*S(e),tilt:.2*S(e,1,.25),eye:`spiral`,mouth:`flat`,earDown:.4,phase:e})},dizzyBack:{frames:16,fps:8,loop:!0,pose:e=>({...k(e,.04,1),back:!0,bx:.02*S(e),tilt:.15*S(e,1,.25),eye:`spiral`,mouth:`w`,phase:e})},getup:{frames:12,fps:14,loop:!1,pose:e=>({rot:.45*(1-w(T(e,0,.6))),piv:1,sy:1-.08*E(e,.5,.8),bx:.015*S(e,3)*T(e,.6,1),eye:e<.5?`squint`:`dot`,earN:.2*S(e,3)*T(e,.6,1),earF:.2*S(e,3,.3)*T(e,.6,1)})},getupBack:{frames:16,fps:14,loop:!1,pose:e=>{let t=T(e,0,.4),n=ae(e,.4,.6),r=T(e,.6,1);return{...n.back?k(e,.07*(1-t*.5),3):{},back:n.back,sy:e<.4?1:e<.6?n.sy:x(.12,1,te(r)),by:e>.45&&e<.65?-.08:0,eye:e<.6?`squint`:`dot`,mouth:e<.6?`flat`:`w`,earN:.2*C(e,3)*r,earF:.2*C(e,3,.3)*r}}}},se={idle:{frames:24,fps:8,loop:!0,pose:(e,t)=>({sy:1+.02*S(e,2),sx:1-.01*S(e,2),eyeOpen:O(t,20),earN:t===12||t===13?-.3:0,tail:.4*S(e,1)})},walk:{ease:.14,frames:8,fps:12,loop:!0,pose:e=>({...re(S(e),S(e,1,.25),.06,.045),by:-.018*C(e,2),rot:.015*S(e,2),earN:.06*S(e,2),earF:.06*S(e,2,.2),tail:S(e)})},run:{ease:.14,frames:6,fps:16,loop:!0,pose:e=>{let t=S(e),n=S(e,1,.25);return{sx:1+.06*t,sy:1-.05*t,by:-.06*C(e),rot:.05*n,lean:.08,float:.3,fbx:-.1*t,nbx:-.12*t,ffx:.1*S(e,1,.5),nfx:.12*S(e,1,.5),fby:-.06*Math.max(0,n),nby:-.06*Math.max(0,n),ffy:-.06*Math.max(0,-n),nfy:-.06*Math.max(0,-n),earDown:.5,tail:t}}},crouch:{ease:0,frames:6,fps:20,loop:!1,pose:e=>{let t=w(e);return{sy:1-.16*t,sx:1+.07*t,lean:-.05*t,earDown:.35*t,eyeOpen:1-.3*t}}},jumpUp:{ease:0,frames:4,fps:12,loop:!1,box:{up:1.2,down:.3},pose:e=>{let t=w(e);return{sy:1.08-.06*t,sx:.95+.03*t,rot:-.16*(1-t*.5),float:1,fbx:-.08,fby:.06,nbx:-.1,nby:.07,ffx:.08,ffy:-.05,nfx:.1,nfy:-.06,earDown:.6,tail:-1}}},jumpDown:{ease:0,frames:4,fps:12,loop:!1,box:{up:1.2,down:.3},pose:e=>{let t=w(e);return{rot:.14*t,float:1,ffx:.06+.04*t,ffy:.05*t,nfx:.08+.04*t,nfy:.05*t,fbx:-.08,fby:-.03,nbx:-.08,nby:-.03,earN:-.25*t,earF:-.2*t,eye:`wide`,tail:1}}},fall:{ease:0,frames:4,fps:10,loop:!0,box:{up:1.2,down:.3},pose:e=>({...k(e,.05,1),float:1,eye:`wide`,mouth:`o`,mouthOpen:.5,earN:.25*S(e),earF:.25*S(e,1,.3),tail:S(e)})},land:{ease:0,frames:6,fps:18,loop:!1,pose:e=>{let t=(1-e)*(1-e);return{sy:1-.15*t,sx:1+.08*t,earDown:.5*t}}},landHard:{ease:0,frames:12,fps:16,loop:!1,pose:e=>{let t=1-w(T(e,.3,1));return{sy:1-.3*t,sx:1+.16*t,earDown:t,eye:e<.6?`squint`:`dot`,mouth:e<.6?`flat`:`w`,bx:.015*S(e,4)*t}}},climb:{ease:0,frames:10,fps:14,loop:!1,box:{down:.75},pose:e=>{let t=w(T(e,0,.6)),n=w(T(e,.6,1));return{...k(e,.05,2),ffx:.06,nfx:.08,ffy:0,nfy:0,by:x(x(.55,.1,t),0,n),rot:x(x(-.7,-.2,t),0,n),float:1-n,grip:1,eye:e<.6?`squint`:`dot`,mouth:e<.6?`flat`:`w`,earDown:.4*(1-n)}}},hang:{ease:0,frames:4,fps:8,loop:!0,box:{down:.75},pose:e=>({...k(e,.05,1),ffx:.06,nfx:.08,ffy:0,nfy:0,by:.55+.02*E(e,0,1),rot:-.7,float:1,grip:1,eye:`wide`,mouth:`o`,mouthOpen:.4})}},ce={w:1.8,up:1.6},le={approve:{frames:16,fps:14,loop:!1,box:A,pose:e=>{let t=w(T(e,0,.25))*(1-w(T(e,.85,1))),n=E(e,.3,.5)+E(e,.5,.7);return{...D(.6*t),tilt:.18*n,fy:.02*n,nfx:.1*t,nfy:-.2*E(e,.35,.95),eye:`happy`,mouth:`smile`,blush:.5,tail:S(e,2)}}},cancel:{frames:16,fps:14,loop:!1,pose:e=>{let t=S(e,3)*E(e,.05,.9);return{tilt:.14*t,fx:.025*t,lookX:-t,eye:`squint`,mouth:`flat`,earDown:.5,earN:.1*t}}},delete:{frames:18,fps:16,loop:!1,box:{...A,w:2},pose:e=>{let t=w(T(e,0,.2))*(1-w(T(e,.8,1))),n=E(e,.2,.45);return{...D(.4*t),nfx:.06*t+.22*n,ffx:.05*t+.2*n,nfy:-.06*t,ffy:-.05*t,lean:.1*n,eye:e<.45?`squint`:`happy`,mouth:e<.45?`flat`:`smile`}}},error:{frames:16,fps:12,loop:!1,pose:e=>{let t=E(e,0,.3);return{sy:1-.1*t,sx:1+.05*t,bx:-.04*t+.012*S(e,5)*T(e,.2,1),earDown:1,eye:e<.5?`x`:`teary`,mouth:`frown`,phase:e}}},success:{frames:20,fps:14,loop:!1,box:ce,pose:e=>{let t=E(e,.15,.65),n=w(T(e,0,.2))*(1-w(T(e,.75,1)));return{...D(.75*n),by:-.32*t,sy:1-.1*E(e,0,.15)-.08*E(e,.65,.8),float:Math.min(1,t*2),nfx:.1*n,nfy:-.3*n,ffx:.02*n,ffy:-.28*n,eye:`happy`,mouth:`open`,mouthOpen:.8,blush:.7,tail:S(e,3)}}},warning:{frames:16,fps:12,loop:!1,box:A,pose:e=>{let t=w(T(e,0,.2))*(1-w(T(e,.85,1)));return{...D(.7*t),bx:.006*S(e,8)*t,nfx:.12*t,nfy:-.28*t,eye:`wide`,mouth:`o`,mouthOpen:.5,earN:.25*t,earF:.25*t}}},thinking:{frames:24,fps:6,loop:!0,box:A,pose:(e,t)=>({...D(.5),nfx:.12,nfy:-.17+.01*S(e,2),ffy:-.04,lookY:-.5,lookX:.3+.2*S(e),tilt:.12,eyeOpen:O(t,16),mouth:`flat`,earF:.08*S(e,2)})},love:{frames:24,fps:10,loop:!0,box:A,pose:e=>({...D(.6),nfx:.12,ffx:.1,nfy:-.06,ffy:-.06,tilt:.1*S(e,2),sy:1+.03*C(e,2),eye:`happy`,mouth:`w`,blush:1,tail:S(e,3)})},wave:{frames:16,fps:12,loop:!0,box:A,pose:e=>({...D(.65),nfx:.05+.07*S(e,2),nfy:-.32,tilt:.06*S(e,2),eye:S(e,2)>.4?`happy`:`dot`,mouth:`smile`,blush:.4,tail:S(e,2)})},surprised:{ease:0,frames:12,fps:14,loop:!1,box:j,pose:e=>{let t=E(e,0,.5),n=w(T(e,0,.5));return{bx:-.1*n,by:-.14*t,float:Math.min(1,t*2),sy:1+.1*t-.06*E(e,.5,.75),rot:-.1*t,eye:`wide`,mouth:`o`,mouthOpen:1,earN:.3*n,earF:.3*n}}},confused:{frames:20,fps:8,loop:!0,pose:(e,t)=>{let n=e<.5?1:-1;return{tilt:.24*n*E(e<.5?e*2:e*2-1,0,1)**.4,lookX:.6*n,lookY:-.3,eyeOpen:O(t,8),mouth:`flat`,earN:-.3*n,earF:.2*n}}},sad:{frames:24,fps:6,loop:!0,pose:e=>({by:.05,sy:.95+.015*S(e),earDown:1,eye:`teary`,mouth:`frown`,lookY:.4,phase:e})}},ue={hello:`wave`,celebrate:`success`,loading:`thinking`,ok:`approve`,no:`cancel`},N={...se,...ie,...oe,...le};Object.keys(N);var de={approve:[[.45,`check`,.15,-1.05],[.5,`sparkle`,.55,-.7]],cancel:[[.05,`cross`,.15,-1.05]],delete:[[.3,`poof`,.85,-.3]],error:[[.05,`sweat`,.05,-.85],[.12,`cross`,.15,-1.1]],success:[[.42,`confetti`,0,-1.3],[.45,`star`,.1,-1.4]],warning:[[.1,`bang`,.15,-1.1]],thinking:[[.02,`dots`,.35,-1.05]],love:[[.15,`heart`,.2,-.9],[.35,`heart`,.45,-.8],[.55,`heart`,-.05,-.85]],wave:[[.25,`sparkle`,.6,-.95]],surprised:[[.05,`bang`,.15,-1.1]],confused:[[.15,`question`,.15,-1.1]],sad:[[.2,`sweat`,.1,-.8]]};function*fe(e,t,n){e.body.stop(),n.say&&e.say(n.say,Math.max(1800,n.say.length*70));let r=de[t];if(e.anim.play(t,!0),N[t].loop){let t=n.hold?1/0:n.duration??2.6,i=0,a=-1;for(;i<t;){if(e.anim.loops!==a){a=e.anim.loops;for(let[,t,n,i]of r)e.spawn(t,n,i)}i+=yield}}else{let t=new Set;for(;!e.anim.done;){let n=e.anim.progress;r.forEach(([r,i,a,o],s)=>{n>=r&&!t.has(s)&&(t.add(s),e.spawn(i,a,o))}),yield}}e.emit(`react`,{name:t})}function*pe(e,t){if(e.body.stop(),e.emit(`pet`,{count:t}),e.spawn(`heart`,.25,-.95),t>=4){yield*o(e,`roll`);for(let t of[-.1,.25,.6])e.spawn(`heart`,t,-.9)}yield*o(e,`happy`)}function*me(e){e.body.stop(),yield*o(e,`wake`),e.spawn(`heart`,.25,-.95),yield*o(e,`happy`)}function*he(e,t){for(e.body.stop(),e.anim.play(`squish`,!0);t();)yield;yield*o(e,`unsquish`),e.spawn(`heart`,.25,-.95),yield*o(e,`happy`)}function*ge(e,t){e.body.stop(),e.anim.play(`purr`,!0);let n=0;for(;t()>.2;)n+=yield,n>.75&&(n=0,e.spawn(`heart`,.1+Math.random()*.4,-.85));yield*o(e,`happy`)}function*_e(e,t){t.claimed=!0;try{let n=0;for(;!t.surface&&n<3;)n+=yield;if(!t.surface||t.eaten)return;let r=Math.sign(t.x-e.body.x)||1;if(!(yield*m(e,t.surface.id,t.x-r*e.u*.62,Math.abs(t.x-e.body.x)>e.u*4))||t.eaten||!t.surface||Math.abs(t.x-e.body.x)>e.u*1.2&&!(yield*l(e,t.x-r*e.u*.62)))return;for(e.body.face(t.x-e.body.x),e.anim.play(`eat`,!0);!e.anim.done;)e.anim.progress>.12&&!t.eaten&&(t.remove(!0),e.emit(`eat`,{x:t.x,y:t.y})),yield;e.spawn(`heart`,.25,-.95),yield*o(e,`happy`)}finally{t.claimed=!1}}function*ve(e,t,n){let r=t.getBoundingClientRect(),i=(r.left+r.right)/2,o=e.world.surfaceFor(t),c=o?yield*m(e,o.id,Math.max(o.left,Math.min(o.right,i-e.u*.6))):!1;for(c||(yield*l(e,i-e.u*.8)),e.body.face(i-e.body.x),e.anim.play(c?`curiousDown`:`curious`,!0),yield*a(1.2);n();)yield;yield*s(e,`idle`,.6)}function*ye(e,t){if(e.body.grounded||(yield*d(e)),t.dizzy){e.anim.play(t.back?`dizzyBack`:`dizzy`,!0);let n=0,r=0;for(;n<2;){let i=yield;n+=i,r+=i,r>.5&&(r=0,e.spawn(`star`,(Math.random()-.5)*.6,t.back?-.6:-1))}}t.back?yield*o(e,`getupBack`):t.tilted?yield*o(e,`getup`):yield*o(e,`land`)}var P=e=>{let t=e.reduce((e,[,t])=>e+Math.max(0,t),0),n=Math.random()*t;for(let[t,r]of e)if(n-=Math.max(0,r),n<=0)return t;return e[e.length-1][0]};function*be(e,t){e.body.stop(),yield*s(e,`idle`,t)}function*xe(e){let t=e.body.surface;if(!t)return;let n=Math.random()<.5?-1:1,r=e.u*(1.2+Math.random()*4),i=e.body.x+n*r;(i<t.left||i>t.right)&&(i=e.body.x-n*r),yield*l(e,i,Math.random()<.2)}var Se=(e,t)=>{let n=e.body,r=n.surface;if(!r)return null;let i=[];for(let a of e.world.surfaces){if(a.id===r.id||r.el&&a.el===r.el||t.includes(a.id)||a.right-a.left<e.u*.8)continue;let o=(a.left+a.right)/2,s=1/(1+Math.hypot(o-n.x,a.top-n.y)/(e.u*6))*(a.id===`floor`?.35:1)*(a.top<n.y?1.3:1);i.push([a,s*(.5+Math.random())])}return i.length?P(i):null};function*Ce(e,t){let n=t.slice(-2);for(let i=0;i<5;i++){let i=Se(e,n),a=e.body.surface;if(!i||!a)break;if(n.push(i.id),!r(e.world.surfaces,a.id,e.body.x,i.id,c(e)))continue;let s=i.left+Math.random()*(i.right-i.left);(yield*m(e,i.id,s))&&(t.push(i.id),t.length>6&&t.shift(),Math.random()<.45&&(yield*o(e,`look`)));return}yield*xe(e)}var we=[[`groom`,3],[`stretch`,2],[`yawn`,1.5],[`look`,3],[`sniff`,2],[`sit`,2.5]];function*Te(e){e.body.stop();let t=P(we);t===`sit`?yield*s(e,`sit`,2.5+Math.random()*3):t===`sniff`?yield*s(e,`sniff`,1.2+Math.random()):yield*o(e,t)}function*Ee(e,t){e.body.stop(),t.sleeping=!0,e.emit(`sleep`,{});try{yield*o(e,`fallAsleep`),e.anim.play(`sleep`);let n=20+Math.random()*30,r=0,i=1;for(;r<n;){let t=yield;r+=t,i+=t,i>1.5&&(i=0,e.spawn(`zzz`,.35,-.75))}t.fatigue=0,yield*o(e,`wake`)}finally{t.sleeping=!1,e.emit(`wake`,{})}}function*De(e){let t=0,n=e.cfg.physics;for(;;){let r=yield,i=e.cursor,a=e.body;if(!a.grounded)return;let o=a.surface,s=Math.hypot(i.x-a.x,i.y-(a.y-e.u*.4));if(s>e.cfg.behavior.followRadius*1.3||performance.now()-i.lastMove>5e3)return;let c=i.x-a.x,l=Math.max(o.left,Math.min(o.right,i.x-Math.sign(c)*e.u*.75));if(Math.abs(l-a.x)>e.u*.45&&Math.abs(c)>e.u*.6){let r=Math.abs(l-a.x)>e.u*3;a.walk(l,(r?n.runSpeed:n.walkSpeed*1.5)*e.u),e.anim.play(r?`run`:`walk`),t=0;continue}a.stop(),Math.abs(c)>e.u*.3&&a.face(c);let u=e.anim.name,d=i.y<a.y-e.u*(u===`curious`?.9:1.1),f=i.y>a.y+e.u*(u===`curiousDown`?0:.15),p=s<e.u*(u===`sniff`?1.1:.9);if(e.anim.play(p?`sniff`:d?`curious`:f?`curiousDown`:`idle`),t+=r,t>1.4&&d){t=0;let n=e.world.below(i.x,i.y);n&&n.id!==o.id&&n.top<a.y-e.u*.5&&(yield*m(e,n.id,i.x))}}}function*Oe(e){let t=e.body;t.stop(),t.face(e.cursor.x-t.x),e.spawn(`bang`,.3,-1),yield*o(e,`startle`),yield*l(e,t.x-Math.sign(e.cursor.x-t.x||1)*e.u*3,!0),yield*a(.2)}var F={auto:0,follow:1,page:2,user:3,fall:4},ke=class{cur=null;state={sleeping:!1,fatigue:0};stroke=0;squishing=!1;c;queue=[];cool=new Map;visited=[];lastTyping=0;paused=!1;constructor(e){this.c=e}get task(){return this.cur?.name??`none`}get sleeping(){return this.state.sleeping}pause(e){this.paused=e,e&&this.stop()}run(e){return this.cur&&this.cur.prio>e.prio?(e.done?.(!1),!1):!this.c.body.grounded&&!e.air?(this.queue=this.queue.filter(t=>t.name!==e.name),this.queue.push(e),!0):(this.start(e),!0)}stop(){let e=this.cur;this.cur=null,e&&(e.co.return(void 0),e.done?.(!1)),this.c.body.stop()}start(e){this.stop(),this.cur={...e,co:e.make()}}ready(e,t){let n=this.cool.get(e)??0;return this.c.now<n?!1:(this.cool.set(e,this.c.now+t),!0)}update(e){if(this.paused)return;let t=this.c;if(this.state.fatigue=Math.min(1,this.state.fatigue+e*t.cfg.behavior.sleepiness/150),this.stroke=Math.max(0,this.stroke-e*1.4),this.sense(),!this.cur){let e=this.queue.findIndex(e=>e.air||t.body.grounded);e>=0?this.start(this.queue.splice(e,1)[0]):t.body.grounded?this.start(this.choose()):this.start({name:`fall`,make:()=>d(t),prio:F.fall,air:!0})}let n=this.cur,r=n.co.next(e);r.done&&this.cur===n&&(this.cur=null,n.done?.(r.value!==!1))}sense(){let e=this.c,t=e.body,n=this.cur?.prio??-1;if(!t.grounded&&!this.cur?.air){this.start({name:`fall`,make:()=>d(e),prio:F.fall,air:!0});return}if(!t.grounded||this.squishing)return;let r=e.cfg.behavior,i=e.cursor,a=Math.hypot(i.x-t.x,i.y-(t.y-e.u*.4));if(r.startle&&i.speed>e.u*40&&a<e.u*1.8&&n<F.user&&this.ready(`startle`,4)){this.run({name:`startle`,make:()=>Oe(e),prio:F.user,air:!1});return}if(this.state.sleeping)return;if(r.stroke&&this.stroke>1&&n<F.page){this.run({name:`purr`,make:()=>ge(e,()=>this.stroke),prio:F.page,air:!1});return}let o=e.seeds.find(e=>!e.claimed&&!e.eaten);if(o&&n<F.page&&this.ready(`eat`,1)){this.run({name:`eat`,make:()=>_e(e,o),prio:F.page,air:!1});return}let s=performance.now()-i.lastMove<1200;r.followCursor&&s&&a<r.followRadius&&n<F.follow&&this.ready(`follow`,1.5)&&this.run({name:`follow`,make:()=>De(e),prio:F.follow,air:!1})}choose(){let e=this.c,t=e.cfg.behavior.activity,n=this.state.fatigue,r=P([[`idle`,2.2*(1.3-t)],[`wander`,2.5*t],[`explore`,4*t*e.cfg.behavior.explore],[`extra`,2],[`sleep`,n>.45?n*n*10:0]]),i=(e,t)=>({name:e,make:t,prio:F.auto,air:!1});switch(r){case`wander`:return i(`wander`,()=>xe(e));case`explore`:return i(`explore`,()=>Ce(e,this.visited));case`extra`:return i(`extra`,()=>Te(e));case`sleep`:return i(`sleep`,()=>Ee(e,this.state));default:return i(`idle`,()=>be(e,(1.2+Math.random()*3)*(1.6-t)))}}onClick(e){let t=this.c;t.cfg.behavior.petting&&t.body.grounded&&(this.state.sleeping?this.run({name:`wake`,make:()=>me(t),prio:F.user,air:!1}):this.run({name:`pet`,make:()=>pe(t,e),prio:F.user,air:!1}))}onLongPress(e){let t=this.c;t.cfg.behavior.petting&&t.body.grounded&&(this.squishing=!0,this.run({name:`squish`,make:()=>he(t,e),prio:F.user,air:!1,done:()=>{this.squishing=!1}}))}onStroke(e){this.stroke=Math.min(3,this.stroke+e/(this.c.u*5))}onTyping(e){this.lastTyping=performance.now();let t=this.c;t.cfg.behavior.watchTyping&&!this.state.sleeping&&((this.cur?.prio??-1)>=F.page||!this.ready(`watch`,8)||this.run({name:`watch`,make:()=>ve(t,e,()=>performance.now()-this.lastTyping<2500),prio:F.page,air:!1}))}react(e,t,n){this.run({name:`react:${e}`,make:()=>fe(this.c,e,t),prio:F.page,air:!1,done:n})}goTo(e,t,n){this.run({name:`goto`,make:()=>m(this.c,e,t,!0),prio:F.page,air:!1,done:n})}afterRagdoll(e){this.start({name:`recover`,make:()=>ye(this.c,e),prio:F.user,air:!0})}sleepNow(){this.run({name:`sleep`,make:()=>Ee(this.c,this.state),prio:F.page,air:!1})}wake(){this.state.sleeping&&this.run({name:`wake`,make:()=>me(this.c),prio:F.user,air:!1})}},Ae=e=>({x:e.body.x+e.body.facing*e.u*.3,y:e.body.y-e.u*.78}),I={golden:{fur:`#f4b66a`,belly:`#fff4e3`,line:`#5b3a29`,paws:`#f7a6b0`,inner:`#f7a6b0`,blush:`#ff8fa3`,eyes:`#2b1d16`,nose:`#f27b8c`},grey:{fur:`#bdb6b0`,belly:`#fbf8f5`,line:`#4a4440`,paws:`#f3b3bb`,inner:`#efb0b8`,blush:`#ff9fb0`,eyes:`#231e1b`,nose:`#ee8a98`},cream:{fur:`#fff3e6`,belly:`#ffffff`,line:`#7a6252`,paws:`#f9b8c0`,inner:`#f9b8c0`,blush:`#ff9fb2`,eyes:`#2b1d16`,nose:`#f28e9c`},choco:{fur:`#9a6a4a`,belly:`#f3dcc4`,line:`#3d2618`,paws:`#eaa3a5`,inner:`#e59a9f`,blush:`#ff8f9c`,eyes:`#1d120c`,nose:`#e8798a`}},L={roundness:.28,chubby:1,legLength:1,headBump:0,stripe:!1,bellyStyle:`patch`,bellyWidth:.3},R={...L,roundness:.43,bellyStyle:`band`},je={soft:L,loaf:R,head:{...R,headBump:1},stripe:{...R,stripe:!0},block:{...L,roundness:.14,bellyStyle:`none`}},Me={size:`10vh`,maxDpr:2,zIndex:2147483e3,appearance:{...I.golden,...L,face:`mochi`,earSize:1,eyeSize:1,cheekSize:1,whiskers:!1},physics:{gravity:38,jumpHeight:4,jumpReach:5,walkSpeed:1.1,runSpeed:3.4,bounce:.55,friction:.35,airDrag:.04,dragStiffness:.5,limbStiffness:.35,dizzyImpact:26},behavior:{followCursor:!0,followRadius:220,startle:!0,petting:!0,stroke:!0,activity:.5,explore:.6,sleepiness:.35,clumsiness:.15,watchTyping:!0},motion:{blend:1,turnTime:.18},platforms:{auto:!0,selector:`[data-pet-platform]`,ignore:`[data-pet-ignore]`,minWidth:.9,cull:0},debug:{surfaces:!1,state:!1}},z=(e,t)=>({size:t.size??e.size,maxDpr:t.maxDpr??e.maxDpr,zIndex:t.zIndex??e.zIndex,appearance:{...e.appearance,...t.preset?I[t.preset]:{},...t.shape?je[t.shape]:{},...t.appearance},physics:{...e.physics,...t.physics},behavior:{...e.behavior,...t.behavior},motion:{...e.motion,...t.motion},platforms:{...e.platforms,...t.platforms},debug:{...e.debug,...t.debug}}),Ne=class{canvas;ctx;key=``;constructor(e){this.canvas=document.createElement(`canvas`),this.canvas.style.cssText=`position:absolute;left:0;top:0;pointer-events:none`,this.ctx=this.canvas.getContext(`2d`),e.prepend(this.canvas)}draw(e,t,n,r){let i=`${e}|${r}|${window.innerWidth}x${window.innerHeight}`;if(i===this.key)return;this.key=i;let a=window.innerWidth,o=window.innerHeight,s=Math.min(2,window.devicePixelRatio||1);(this.canvas.width!==a*s||this.canvas.height!==o*s)&&(this.canvas.width=a*s,this.canvas.height=o*s,this.canvas.style.width=`${a}px`,this.canvas.style.height=`${o}px`);let c=this.ctx;c.setTransform(s,0,0,s,0,0),c.clearRect(0,0,a,o),c.setLineDash([6,4]),c.strokeStyle=`rgba(124,140,255,0.8)`,c.lineWidth=1,c.strokeRect(n.left+.5,n.top+.5,n.right-n.left-1,n.bottom-n.top-1),c.setLineDash([]);for(let e of t){let t=e.id===r;c.strokeStyle=t?`#ff7a93`:e.id===`floor`?`rgba(76,195,138,0.5)`:`#4cc38a`,c.lineWidth=t?4:2.5,c.beginPath(),c.moveTo(e.left,e.top),c.lineTo(e.right,e.top),c.stroke()}}destroy(){this.canvas.remove()}},Pe=[`approve`,`cancel`,`delete`,`error`,`success`,`warning`,`thinking`,`love`,`wave`,`surprised`,`confused`,`sad`],Fe=class{map=new Map;emit=(e,t)=>{this.map.get(e)?.forEach(e=>e(t))};on(e,t){let n=this.map.get(e);return n||this.map.set(e,n=new Set),n.add(t),()=>this.off(e,t)}off(e,t){this.map.get(e)?.delete(t)}clear(){this.map.clear()}},Ie=e=>{let t=ue[e]??e;return Pe.includes(t)?t:null},Le=e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable,Re=e=>{let t=t=>!e.container||e.container.contains(t),n=n=>{let r=(n.target instanceof Element?n.target:null)?.closest(`[data-pet-react],[data-pet-say]`);if(!r||!t(r))return;let{petReact:i,petSay:a}=r.dataset;i?e.react(i,a):a&&e.say(a)},r=n=>{let r=n.target;Le(r)&&t(r)&&!r.closest(e.ignore())&&(r instanceof HTMLInputElement&&/^(checkbox|radio|range|color|file|button|submit)$/.test(r.type)||e.typing(r))};return document.addEventListener(`click`,n),document.addEventListener(`input`,r,!0),()=>{document.removeEventListener(`click`,n),document.removeEventListener(`input`,r,!0)}},ze=class{outer;inner;text;until=0;visible=!1;lastKey=``;width=0;height=0;constructor(e){this.outer=document.createElement(`div`),this.outer.style.cssText=`position:absolute;left:0;top:0;will-change:transform;display:none`,this.inner=document.createElement(`div`),this.inner.style.cssText=`position:relative;transform-origin:50% 100%;background:#fff;color:#4a3426;border:1.5px solid #eadfd5;border-radius:14px;padding:5px 11px;font:600 13px/1.25 ui-rounded,system-ui,sans-serif;max-width:220px;box-shadow:0 3px 0 rgba(74,52,38,0.08);white-space:pre-wrap;text-align:center`,this.text=document.createElement(`span`);let t=document.createElement(`div`);t.style.cssText=`position:absolute;left:50%;bottom:-6px;width:10px;height:10px;background:#fff;border-right:1.5px solid #eadfd5;border-bottom:1.5px solid #eadfd5;transform:translateX(-50%) rotate(45deg)`,this.inner.append(this.text,t),this.outer.append(this.inner),e.append(this.outer)}say(e,t,n){this.text.textContent=e,this.until=n+t,this.outer.style.display=`block`,this.width=this.inner.offsetWidth,this.height=this.inner.offsetHeight,this.lastKey=``,this.visible||this.inner.animate([{transform:`scale(0.4)`,opacity:0},{transform:`scale(1.06)`,opacity:1,offset:.7},{transform:`scale(1)`,opacity:1}],{duration:220,easing:`ease-out`}),this.visible=!0}hide(){if(!this.visible)return;this.visible=!1;let e=this.inner.animate([{opacity:1},{opacity:0,transform:`scale(0.8)`}],{duration:160,easing:`ease-in`});e.onfinish=()=>{this.visible||(this.outer.style.display=`none`)}}update(e,t,n,r){if(!this.visible)return;if(e>this.until)return this.hide();let i=this.width,a=Math.max(r.left+4,Math.min(r.right-i-4,t-i/2)),o=Math.max(r.top+4,n-this.height-10),s=`${a.toFixed(0)},${o.toFixed(0)}`;s!==this.lastKey&&(this.lastKey=s,this.outer.style.transform=`translate3d(${a.toFixed(0)}px,${o.toFixed(0)}px,0)`)}get shown(){return this.visible}},B=e=>`<svg viewBox="0 0 24 24" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">${e}</svg>`,V=(e,t)=>B(`<circle cx="12" cy="12" r="11" fill="${e}"/>${t}`),Be={heart:B(`<path d="M12 21s-8-5.2-8-11a4.6 4.6 0 0 1 8-3.1A4.6 4.6 0 0 1 20 10c0 5.8-8 11-8 11z" fill="#ff7a93"/>`),star:B(`<path d="M12 2.5l2.8 6 6.5.7-4.9 4.4 1.4 6.4L12 16.7 6.2 20l1.4-6.4L2.7 9.2l6.5-.7z" fill="#ffc94d"/>`),sparkle:B(`<path d="M12 1c1 6 5 10 11 11-6 1-10 5-11 11-1-6-5-10-11-11 6-1 10-5 11-11z" fill="#ffd166"/>`),check:V(`#4cc38a`,`<path d="M7 12.5l3.2 3.2L17.5 8.5" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>`),cross:V(`#ff6b6b`,`<path d="M8 8l8 8M16 8l-8 8" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round"/>`),bang:V(`#f5a524`,`<path d="M12 6v8" stroke="#fff" stroke-width="3" stroke-linecap="round"/><circle cx="12" cy="18" r="1.7" fill="#fff"/>`),question:V(`#7c8cff`,`<path d="M9 9.2a3 3 0 1 1 4.3 2.7c-.9.5-1.3 1-1.3 2v.6" fill="none" stroke="#fff" stroke-width="2.4" stroke-linecap="round"/><circle cx="12" cy="18" r="1.5" fill="#fff"/>`),zzz:B(`<path d="M6 6h11L6 18h12" fill="none" stroke="#8aa0c8" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round"/>`),dots:B(`<rect x="1" y="5" width="22" height="14" rx="7" fill="#fff" stroke="#d9cfc6" stroke-width="1.2"/><circle cx="7" cy="12" r="1.8" fill="#9b8d80"/><circle cx="12" cy="12" r="1.8" fill="#9b8d80"/><circle cx="17" cy="12" r="1.8" fill="#9b8d80"/>`),sweat:B(`<path d="M12 2C9 7 6.5 10.5 6.5 14a5.5 5.5 0 0 0 11 0C17.5 10.5 15 7 12 2z" fill="#8fd3ff"/><ellipse cx="10" cy="14" rx="1.4" ry="2.2" fill="#fff" opacity=".7"/>`),bonk:B(`<path d="M12 1l2.6 6.1 6.6-1.9-3.9 5.6 5.7 3.6-6.6.9.6 6.7L12 17l-5 4.9.6-6.7-6.6-.9 5.7-3.6-3.9-5.6 6.6 1.9z" fill="#ffd166" stroke="#fff" stroke-width="1.2"/>`)},Ve=[`#ff7a93`,`#ffc94d`,`#4cc38a`,`#7c8cff`,`#8fd3ff`,`#f4b66a`],He=60,Ue=class{layer;unit;live=0;constructor(e,t){this.layer=e,this.unit=t}spawn(e,t,n,r={}){if(e===`confetti`)return this.confetti(t,n,r.count??16);if(e===`poof`)return this.poof(t,n,r.size??this.unit()*.45);let i=this.unit(),a=r.size??i*(e===`dots`?.42:e===`zzz`?.22:.3),o=this.node(a);if(!o)return;o.innerHTML=Be[e];let s=r.dx??(Math.random()-.5)*i*.5,c=(e,r,i,o=0)=>`translate3d(${(t+e-a/2).toFixed(1)}px,${(n+r-a/2).toFixed(1)}px,0) scale(${i}) rotate(${o}deg)`,l,u=r.duration??1100;switch(e){case`bonk`:l=[{transform:c(0,0,.3,0),opacity:1},{transform:c(0,0,1.25,25),opacity:1,offset:.35},{transform:c(0,0,.2,60),opacity:0}],u=r.duration??420;break;case`sweat`:l=[{transform:c(0,0,.4),opacity:0},{transform:c(0,0,1),opacity:1,offset:.2},{transform:c(s*.2,i*.25,.9),opacity:0}],u=r.duration??900;break;case`zzz`:l=[{transform:c(0,0,.4,-10),opacity:0},{transform:c(i*.12,-i*.2,.9,5),opacity:1,offset:.3},{transform:c(i*.35,-i*.6,1.3,-8),opacity:0}],u=r.duration??1800;break;case`dots`:case`check`:case`cross`:case`bang`:case`question`:l=[{transform:c(0,0,.2),opacity:0},{transform:c(0,-i*.15,1.15),opacity:1,offset:.18},{transform:c(0,-i*.18,1),opacity:1,offset:.3},{transform:c(0,-i*.22,1),opacity:1,offset:.8},{transform:c(0,-i*.35,.8),opacity:0}],u=r.duration??1300;break;default:l=[{transform:c(0,0,.3),opacity:0},{transform:c(s*.3,-i*.2,1),opacity:1,offset:.25},{transform:c(s,-i*.75,.85),opacity:0}]}this.play(o,l,u,e===`bonk`?`cubic-bezier(.2,.9,.3,1)`:`ease-out`)}node(e){if(this.live>=He)return null;let t=document.createElement(`div`);return t.style.cssText=`position:absolute;left:0;top:0;width:${e}px;height:${e}px;will-change:transform,opacity;opacity:0`,this.layer.append(t),this.live++,t}play(e,t,n,r,i=0){let a=e.animate(t,{duration:n,easing:r,delay:i,fill:`both`});a.onfinish=a.oncancel=()=>{e.remove(),this.live--}}poof(e,t,n){for(let r=0;r<6;r++){let i=n*(.5+Math.random()*.4),a=this.node(i);if(!a)return;a.style.borderRadius=`50%`,a.style.background=r%2?`#f3eee9`:`#ffffff`,a.style.boxShadow=`inset 0 -3px 0 rgba(0,0,0,0.06)`;let o=r/6*Math.PI*2+Math.random(),s=n*.9,c=(n,r)=>`translate3d(${(e+Math.cos(o)*s*n-i/2).toFixed(1)}px,${(t+Math.sin(o)*s*n*.6-i/2).toFixed(1)}px,0) scale(${r})`;this.play(a,[{transform:c(0,.3),opacity:1},{transform:c(.7,1.1),opacity:1,offset:.4},{transform:c(1,.4),opacity:0}],650,`ease-out`)}}confetti(e,t,n){let r=this.unit();for(let i=0;i<n;i++){let n=r*(.06+Math.random()*.05),a=this.node(n);if(!a)return;a.style.height=`${n*.55}px`,a.style.borderRadius=`2px`,a.style.background=Ve[i%Ve.length];let o=(Math.random()-.5)*r*3,s=r*(1+Math.random()*1.2),c=(Math.random()-.5)*900,l=[];for(let n=0;n<=6;n++){let i=n/6,a=-s*4*i*(1-i)+r*1.2*i*i;l.push({transform:`translate3d(${(e+o*i).toFixed(1)}px,${(t+a).toFixed(1)}px,0) rotate(${(c*i).toFixed(0)}deg)`,opacity:i>.8?(1-i)*5:1})}this.play(a,l,1200+Math.random()*400,`linear`,Math.random()*80)}}},We=`<svg viewBox="0 0 24 24" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><g transform="rotate(30 12 12)"><ellipse cx="12" cy="12" rx="6" ry="10" fill="#4b4039"/><path d="M10 4.5v15M14 5v14" stroke="#efe6dc" stroke-width="1.3" stroke-linecap="round"/></g></svg>`,Ge=class{x;y;vy=0;surface=null;age=0;eaten=!1;claimed=!1;el;size;constructor(e,t,n,r){this.x=t,this.y=n,this.size=r,this.el=document.createElement(`div`),this.el.style.cssText=`position:absolute;left:0;top:0;width:${r}px;height:${r}px;will-change:transform`,this.el.innerHTML=We,e.append(this.el),this.el.animate([{opacity:0,transform:this.tf(.3)},{opacity:1,transform:this.tf(1)}],{duration:180})}tf(e=1){return`translate3d(${(this.x-this.size/2).toFixed(1)}px,${(this.y-this.size).toFixed(1)}px,0) scale(${e})`}update(e,t,n){if(this.age+=e,this.surface){let e=t.refresh(this.surface,this.x);e?(e.el&&e.el===this.surface.el&&(this.x+=e.ex-this.surface.ex),this.surface=e,this.y=e.top):this.surface=null}else{let r=this.y;this.vy=Math.min(this.vy+n*e,n),this.y+=this.vy*e;let i=t.landing(this.x,r,this.y);i?(this.surface=i,this.y=i.top,this.vy=0):this.y>=t.bounds.bottom&&(this.surface=t.floor,this.y=t.bounds.bottom)}this.el.style.transform=this.tf()}remove(e=!1){this.eaten=e;let t=this.el.animate([{opacity:1},{opacity:0,transform:this.tf(.2)}],{duration:220,fill:`forwards`});t.onfinish=()=>this.el.remove()}},Ke=6,qe=450,Je=1600,Ye=class{cursor={x:-9999,y:-9999,vx:0,vy:0,speed:0,lastMove:0,known:!1};h;target;down=null;dragging=!1;longFired=!1;longTimer=0;clicks=[];hover=!1;lastHover={x:0,y:0};constructor(e,t){this.target=e,this.h=t,window.addEventListener(`pointermove`,this.onMove,{passive:!0}),e.addEventListener(`pointerdown`,this.onDown),e.addEventListener(`pointermove`,this.onTargetMove),e.addEventListener(`pointerup`,this.onUp),e.addEventListener(`pointercancel`,this.onCancel),e.addEventListener(`pointerenter`,this.onEnter),e.addEventListener(`pointerleave`,this.onLeave),e.addEventListener(`contextmenu`,this.onContext)}get isDragging(){return this.dragging}onMove=e=>{let t=this.cursor,n=performance.now(),r=Math.max(1,n-t.lastMove)/1e3;if(t.known){let n=Math.min(1,r*12);t.vx+=((e.clientX-t.x)/r-t.vx)*n,t.vy+=((e.clientY-t.y)/r-t.vy)*n,t.speed=Math.hypot(t.vx,t.vy)}t.x=e.clientX,t.y=e.clientY,t.lastMove=n,t.known=!0};onDown=e=>{e.button!==0||this.down||(e.preventDefault(),this.target.setPointerCapture(e.pointerId),this.down={id:e.pointerId,x:e.clientX,y:e.clientY,t:performance.now()},this.dragging=!1,this.longFired=!1,this.target.style.cursor=`grabbing`,this.h.press(),this.longTimer=window.setTimeout(()=>{this.down&&!this.dragging&&(this.longFired=!0,this.h.longPress())},qe))};onTargetMove=e=>{if(this.down&&e.pointerId===this.down.id)!this.dragging&&Math.hypot(e.clientX-this.down.x,e.clientY-this.down.y)>Ke&&(this.dragging=!0,clearTimeout(this.longTimer),this.longFired&&this.h.longRelease(),this.h.dragStart(e.clientX,e.clientY)),this.dragging&&this.h.dragMove(e.clientX,e.clientY);else if(this.hover&&e.pointerType===`mouse`){let t=Math.hypot(e.clientX-this.lastHover.x,e.clientY-this.lastHover.y);this.lastHover={x:e.clientX,y:e.clientY},t>0&&t<80&&this.h.stroke(t)}};finish(e,t){if(this.down&&e.pointerId===this.down.id){if(clearTimeout(this.longTimer),this.target.hasPointerCapture(e.pointerId)&&this.target.releasePointerCapture(e.pointerId),this.target.style.cursor=`grab`,this.dragging)this.h.dragEnd(e.clientX,e.clientY);else if(this.longFired)this.h.longRelease();else if(!t){let e=performance.now();this.clicks=this.clicks.filter(t=>e-t<Je),this.clicks.push(e),this.h.click(this.clicks.length)}this.down=null,this.dragging=!1,this.longFired=!1}}onUp=e=>this.finish(e,!1);onCancel=e=>this.finish(e,!0);onEnter=e=>{this.hover=!0,this.lastHover={x:e.clientX,y:e.clientY}};onLeave=()=>{this.hover=!1};onContext=e=>e.preventDefault();resetClicks(){this.clicks=[]}destroy(){clearTimeout(this.longTimer),window.removeEventListener(`pointermove`,this.onMove);let e=this.target;e.removeEventListener(`pointerdown`,this.onDown),e.removeEventListener(`pointermove`,this.onTargetMove),e.removeEventListener(`pointerup`,this.onUp),e.removeEventListener(`pointercancel`,this.onCancel),e.removeEventListener(`pointerenter`,this.onEnter),e.removeEventListener(`pointerleave`,this.onLeave),e.removeEventListener(`contextmenu`,this.onContext)}},Xe=class{x=0;y=0;vx=0;vy=0;facing=1;surface=null;jumping=!1;target=null;walkTarget=null;speed=0;apexY=0;airTime=0;ev;constructor(e){this.ev=e}get grounded(){return this.surface!==null}get arrived(){return this.walkTarget===null}place(e,t,n){this.x=e,this.y=t,this.vx=0,this.vy=0,this.surface=n,this.jumping=!1,this.target=null,this.walkTarget=null,this.apexY=t}walk(e,t){this.walkTarget=e,this.speed=t,Math.abs(e-this.x)>.5&&(this.facing=e>this.x?1:-1)}stop(){this.walkTarget=null}face(e){e!==0&&(this.facing=e>0?1:-1)}launch(e,t,n){this.surface=null,this.jumping=!0,this.target=n,this.walkTarget=null,this.vx=e,this.vy=t,this.apexY=this.y,this.airTime=0,Math.abs(e)>1&&(this.facing=e>0?1:-1)}drop(e=0,t=0){this.surface=null,this.jumping=!1,this.target=null,this.walkTarget=null,this.vx=e,this.vy=t,this.apexY=this.y,this.airTime=0}update(e,t,n,r){this.surface?this.ground(e,t,n):this.air(e,t,n,r)}ground(e,t,n){let r=this.surface,i=t.refresh(r,this.x);if(!i){this.drop(),this.ev.leave();return}if(i.el&&i.el===r.el&&(this.x+=i.ex-r.ex),this.surface=i,this.y=i.top,this.walkTarget!==null){let t=this.walkTarget-this.x,n=this.speed*e;Math.abs(t)<=n?(this.x=this.walkTarget,this.walkTarget=null):(this.x+=Math.sign(t)*n,this.facing=t>0?1:-1)}let a=t.bounds;this.x=Math.max(a.left+n*.5,Math.min(a.right-n*.5,this.x)),this.x<i.left-n*.35||this.x>i.right+n*.35?(this.drop(this.walkTarget===null?0:this.facing*this.speed),this.ev.leave()):(this.x<i.left||this.x>i.right)&&(this.x=Math.max(i.left,Math.min(i.right,this.x)),this.walkTarget!==null&&(this.walkTarget<i.left||this.walkTarget>i.right)&&(this.walkTarget=null))}air(e,t,n,r){let i=r.gravity*n,a=this.y;this.airTime+=e,this.vy=Math.min(this.vy+i*e,n*30),this.vx*=1-Math.min(1,r.airDrag*e),this.x+=this.vx*e,this.y+=this.vy*e,this.apexY=Math.min(this.apexY,this.y);let o=t.bounds;if(this.x<o.left+n*.5?(this.x=o.left+n*.5,this.vx=Math.abs(this.vx)*.3):this.x>o.right-n*.5&&(this.x=o.right-n*.5,this.vx=-Math.abs(this.vx)*.3),this.y-n*.8<o.top&&(this.y=o.top+n*.8,this.vy=Math.max(this.vy,0)),this.vy>=0){let e=t.landing(this.x,a,this.y);if(e)return this.land(e);if(this.y>=o.bottom)return this.land(t.floor)}let s=this.target;if(s&&this.vy>-n*3){let e=t.byId(s.id)??s,r=this.y>e.top+2&&this.y-n*.6<=e.top,i=this.x>=e.left-n*.45&&this.x<=e.right+n*.45;r&&i&&(this.place(Math.max(e.left+n*.1,Math.min(e.right-n*.1,this.x)),e.top,e),this.ev.ledge(e))}}land(e){let t=e.top-this.apexY,n=this.vy;this.place(this.x,e.top,e),this.ev.land(e,t,n)}},H=[{x:-.3,y:.36,attach:0},{x:.31,y:.36,attach:1},{x:-.37,y:.38,attach:0},{x:.2,y:.38,attach:1}],U=.3,W=1/240,G=.38,Ze=class{p;facing;belly=1;grab=null;squash=0;restTime=0;time=0;u;acc=0;impactCd=0;constructor(e,t,n,r,i,a){this.u=e,this.facing=a;let o=(e,t,n,a)=>({x:e,y:t,px:e-r*W,py:t-i*W,r:n,im:a});this.p=[o(t-a*U*e,n,.27*e,1/3),o(t+a*U*e,n,.27*e,1/3),...H.map(r=>o(t+a*r.x*e,n+r.y*e,.06*e,1/.4))]}get center(){return{x:(this.p[0].x+this.p[1].x)/2,y:(this.p[0].y+this.p[1].y)/2}}get axis(){let e=this.p[1].x-this.p[0].x,t=this.p[1].y-this.p[0].y,n=Math.hypot(e,t)||1;return{x:e/n,y:t/n}}get normal(){let e=this.axis;return{x:-e.y*this.facing,y:e.x*this.facing}}get angle(){let e=this.axis;return Math.atan2(e.y,e.x)}get speed(){let e=0;for(let t of this.p)e=Math.max(e,Math.hypot(t.x-t.px,t.y-t.py)/W);return e}toLocal(e,t){let n=this.center,r=this.axis,i=this.normal,a=e-n.x,o=t-n.y;return{x:(a*r.x+o*r.y)/this.u,y:(a*i.x+o*i.y)/this.u}}legTarget(e){let t=this.center,n=this.axis,r=this.normal,i=H[e],a=this.grab?Math.sin(this.time*14+e*1.7)*.07:0,o=(i.y+a)*this.belly,s=i.x+(this.grab?Math.cos(this.time*14+e*1.7)*.04:0);return{x:t.x+(n.x*s+r.x*o)*this.u,y:t.y+(n.y*s+r.y*o)*this.u}}startGrab(e,t){let n=this.toLocal(e,t);this.grab={t:Math.max(-.5,Math.min(.5,n.x)),n:Math.max(-.3,Math.min(.3,n.y)),x:e,y:t},this.belly=-1}moveGrab(e,t){this.grab&&(this.grab.x=e,this.grab.y=t)}release(){this.grab=null}step(e,t,n,r){for(this.acc=Math.min(this.acc+e,W*10);this.acc>=W;)this.acc-=W,this.sub(t,n,r);this.squash=Math.max(0,this.squash-e*4),this.impactCd=Math.max(0,this.impactCd-e),this.restTime=this.grab||this.speed>this.u*.6?0:this.restTime+e}sub(e,t,n){let r=this.u,i=t.gravity*r;this.time+=W;let a=1-Math.min(.5,t.airDrag*W*4);for(let e of this.p){let t=(e.x-e.px)*a,n=(e.y-e.py)*a;e.px=e.x,e.py=e.y,e.x+=t,e.y+=n+i*W*W}this.grab&&this.pullGrab(t);let o=Math.min(.6,t.limbStiffness*.25);for(let e=0;e<4;e++){let t=this.p[e+2],n=this.legTarget(e),r=this.p[H[e].attach],i=t.im/(t.im+r.im)*o,a=(n.x-t.x)*i,s=(n.y-t.y)*i;t.x+=a,t.y+=s,this.impulse(t.x,t.y,-a/t.im,-s/t.im)}for(let e=0;e<3;e++){this.link(0,1,U*2*r,U*2*r);for(let e=0;e<4;e++){let t=H[e],n=Math.hypot((t.x-(t.attach?U:-.3))*r,t.y*r);this.link(t.attach,e+2,n*.75,n*1.25)}}for(let r=0;r<this.p.length;r++)this.collide(this.p[r],r<2,e,t,n)}pullGrab(e){let t=this.grab,n=this.axis,r=this.normal,i=this.center,a=i.x+(n.x*t.t+r.x*t.n)*this.u,o=i.y+(n.y*t.t+r.y*t.n)*this.u,s=Math.min(.8,(.05+e.dragStiffness*.3)*1.6),c=(t.x-a)*s,l=(t.y-o)*s,[u,d]=this.p,f=a-i.x,p=o-i.y,m=u.im/2,h=u.im/(2*(U*this.u)**2),g=m+p*p*h,_=m+f*f*h,v=-f*p*h,y=g*_-v*v;if(this.impulse(a,o,(_*c-v*l)/y,(g*l-v*c)/y),Math.abs(t.t)<.25){let e=(u.y+d.y)/2;u.y+=(e-u.y)*.03,d.y+=(e-d.y)*.03}}impulse(e,t,n,r){let[i,a]=this.p,o=U*this.u,s=(a.x-i.x)/(2*o),c=(a.y-i.y)/(2*o),l=((e-(i.x+a.x)/2)*r-(t-(i.y+a.y)/2)*n)*i.im/(2*o),u=n*i.im/2,d=r*i.im/2;i.x+=u+c*l,i.y+=d-s*l,a.x+=u-c*l,a.y+=d+s*l}link(e,t,n,r){let i=this.p[e],a=this.p[t],o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s)||1e-4,l=c<n?n:c>r?r:c;if(l===c)return;let u=(c-l)/c/(i.im+a.im);i.x+=o*u*i.im,i.y+=s*u*i.im,a.x-=o*u*a.im,a.y-=s*u*a.im}collide(e,t,n,r,i){let a=n.bounds,o=r.bounce,s=r.friction,c=0,l=e.x,u=e.y,d=e.x-e.px,f=e.y-e.py;if(e.x-e.r<a.left&&d<0?(e.x=a.left+e.r,e.px=e.x+d*o,e.py=e.y-f*(1-s),c=Math.abs(d),l=a.left):e.x+e.r>a.right&&d>0&&(e.x=a.right-e.r,e.px=e.x+d*o,e.py=e.y-f*(1-s),c=Math.abs(d),l=a.right),e.y-e.r<a.top&&f<0)e.y=a.top+e.r,e.py=e.y+f*o,c=Math.max(c,Math.abs(f)),u=a.top;else if(f>=0){let t=e.y+e.r>a.bottom?a.bottom:1/0;for(let r of n.surfaces)r.id===`floor`||e.x<r.left-e.r*.5||e.x>r.right+e.r*.5||e.py+e.r<=r.top+1&&e.y+e.r>r.top&&r.top<t&&(t=r.top);t!==1/0&&(e.y=t-e.r,e.py=e.y+f*o,e.px=e.x-d*(1-s),(f>Math.abs(d)*.2||c)&&(c=Math.max(c,f),u=t))}if(t&&c>0){let e=c/W;e>this.u*7&&this.impactCd<=0&&(this.impactCd=.12,this.squash=Math.min(1,e/(this.u*30)),i({speed:e/this.u,x:l,y:u}))}}},Qe=.03,$e=.3,et={bx:1,by:1,rot:.6,piv:0,sx:.6,sy:.6,lean:.6,fbx:1,fby:1,ffx:1,ffy:1,nbx:1,nby:1,nfx:1,nfy:1,float:.3,grip:.3,arm:.3,fx:1,fy:1,tilt:.4,upright:0,earF:.1,earN:.1,earDown:.1,eyeOpen:.05,lookX:.1,lookY:.1,mouthOpen:.05,cheek:.05,blush:.05,tail:.02},tt=Object.keys(et),nt=(e,t)=>e.loop?t/e.frames:e.frames>1?t/(e.frames-1):1,rt=(e,t)=>v(e.pose(nt(e,t),t)),it=e=>e.tilt-e.rot*e.upright,at=(e,t)=>{let n=Math.abs(it(e)-it(t))*.4;for(let r of tt)n=Math.max(n,Math.abs(e[r]-t[r])*et[r]);return n},ot=(e,t,n)=>{let r={...n<.5?e:t};for(let i of tt)r[i]=x(e[i],t[i],n);return r},st=(e,t,n,r)=>{let i=Math.min(e.ease??.24,t.ease??.24);if(i<=0||n.back!==r.back||n.feet||r.feet)return 0;let a=at(n,r);return a<Qe?0:i*b(a/$e,.5,1)},ct=class{name=`idle`;t=0;frame=0;done=!1;loops=0;speed=1;blendScale=1;from=null;bt=0;bd=0;cut=!0;play(e,t=!1,n=1){this.speed=n,(e!==this.name||t)&&(e!==this.name&&this.blendTo(e),this.name=e,this.t=0,this.frame=0,this.done=!1,this.loops=0)}snap(){this.from=null,this.cut=!0}get blending(){return this.from!==null}pose(){let e=rt(N[this.name],this.frame);return this.from?ot(this.from,e,ee(Math.min(1,this.bt/this.bd))):e}get progress(){let e=N[this.name];return Math.min(1,this.t*e.fps/e.frames)}update(e){let t=N[this.name];this.t+=e*this.speed;let n=Math.floor(this.t*t.fps);t.loop?(this.loops=Math.floor(n/t.frames),this.frame=n%t.frames):(this.frame=Math.min(n,t.frames-1),this.done=n>=t.frames),this.from&&(this.bt+=e)>=this.bd&&(this.from=null)}blendTo(e){let t=this.cut||this.blendScale<=0?null:this.pose();if(this.cut=!1,this.from=null,!t)return;let n=st(N[this.name],N[e],t,rt(N[e],0))*this.blendScale;n<=0||(this.from=t,this.bt=0,this.bd=n)}},lt=`#8fd3ff`,ut=`#ff8a9a`,dt=(e,t,n,r,i,a,o,s)=>{let c=o.eyes;e.fillStyle=c,e.strokeStyle=c,e.lineWidth=s*1.25;let l=a.lookX*r*.35,u=a.lookY*r*.3,d=(r,i,a)=>{i<.22?(e.beginPath(),e.moveTo(t-r,n),e.lineTo(t+r,n),e.stroke()):(e.beginPath(),e.ellipse(t+l,n+u,r,r*i,0,0,y),e.fill(),i>.5&&(e.beginPath(),e.arc(t+l+r*.36,n+u-r*.36*i,r*a,0,y),e.fillStyle=`#fff`,e.fill(),e.beginPath(),e.arc(t+l-r*.32,n+u+r*.4*i,r*a*.45,0,y),e.globalAlpha=.8,e.fill(),e.globalAlpha=1,e.fillStyle=c))};switch(a.eye){case`dot`:d(r,b(a.eyeOpen,0,1),.34);break;case`wide`:d(r*1.3,1,.4),e.beginPath(),e.arc(t+l-r*.45,n+u+r*.45,r*.16,0,y),e.fillStyle=`#fff`,e.fill();break;case`teary`:d(r*1.18,1,.42),e.beginPath(),e.arc(t+l-r*.4,n+u+r*.42,r*.2,0,y),e.fillStyle=`#fff`,e.fill(),e.beginPath(),e.ellipse(t+i*r*.5,n+r*(1.8+a.phase*1.2),r*.32,r*.45,0,0,y),e.fillStyle=lt,e.fill();break;case`happy`:e.beginPath(),e.arc(t,n+r*.55,r*.95,Math.PI*1.15,Math.PI*1.85),e.stroke();break;case`closed`:e.beginPath(),e.arc(t,n-r*.45,r*.95,Math.PI*.15,Math.PI*.85),e.stroke();break;case`squint`:{let a=i<0?1:-1;e.beginPath(),e.moveTo(t-a*r,n-r*.85),e.lineTo(t+a*r*.75,n),e.lineTo(t-a*r,n+r*.85),e.stroke();break}case`x`:e.beginPath(),e.moveTo(t-r*.85,n-r*.85),e.lineTo(t+r*.85,n+r*.85),e.moveTo(t+r*.85,n-r*.85),e.lineTo(t-r*.85,n+r*.85),e.stroke();break;case`spiral`:e.beginPath();for(let o=0;o<=40;o++){let s=o/40,c=s*2.2*y+a.phase*y*i,l=r*1.15*s,u=t+Math.cos(c)*l,d=n+Math.sin(c)*l;o===0?e.moveTo(u,d):e.lineTo(u,d)}e.lineWidth=s,e.stroke();break;case`star`:e.beginPath();for(let i=0;i<10;i++){let a=i/10*y-Math.PI/2,o=i%2?r*.55:r*1.35;e.lineTo(t+Math.cos(a)*o,n+Math.sin(a)*o)}e.closePath(),e.fill();break;case`angry`:d(r,1,.3),e.beginPath(),e.moveTo(t-i*r*1.25,n-r*1.55),e.lineTo(t+i*r*1.1,n-r*.95),e.lineWidth=s*1.2,e.stroke()}},ft=(e,t,n,r,i,a)=>{e.strokeStyle=i.eyes,e.fillStyle=i.eyes,e.lineWidth=a;let o=.048,s=b(r.mouthOpen,0,1);switch(r.mouth){case`w`:case`tongue`:r.mouth===`tongue`&&(e.beginPath(),e.ellipse(t,n+.024,.02,.022,0,0,y),e.fillStyle=ut,e.fill()),e.beginPath(),e.moveTo(t-o,n),e.quadraticCurveTo(t-o/2,n+.032,t,n),e.quadraticCurveTo(t+o/2,n+.032,t+o,n),e.stroke();break;case`smile`:e.beginPath(),e.arc(t,n-.012,.042,Math.PI*.18,Math.PI*.82),e.stroke();break;case`o`:e.beginPath(),e.ellipse(t,n+.024,.016+.014*s,.018+.018*s,0,0,y),e.fill();break;case`open`:{let r=.03+.03*s;e.beginPath(),e.moveTo(t-.045,n),e.ellipse(t,n,.045,r,0,0,Math.PI),e.closePath(),e.fill(),e.beginPath(),e.ellipse(t,n+r*.72,.022,r*.32,0,0,y),e.fillStyle=ut,e.fill();break}case`flat`:e.beginPath(),e.moveTo(t-.032,n+.014),e.lineTo(t+.032,n+.014),e.stroke();break;case`frown`:e.beginPath(),e.arc(t,n+.055,.036,Math.PI*1.22,Math.PI*1.78),e.stroke()}},pt={mochi:{muzzle:{x:.43,y:.32,rx:.085,ry:.062},pouch:!1,blush:{x:.16,y:.325,rx:.055,ry:.03},eyeN:{x:.23,y:.24,rx:.046,ry:.058},eyeF:{x:.43,y:.235,rx:.032,ry:.052},nose:{x:.478,y:.295,rx:.021,ry:.015},mouth:{x:.462,y:.33,s:.52}},classic:{muzzle:{x:.34,y:.33,rx:.17,ry:.13},pouch:!1,blush:{x:.14,y:.31,rx:.06,ry:.035},eyeN:{x:.2,y:.21,rx:.045,ry:.045},eyeF:{x:.42,y:.205,rx:.032,ry:.037},nose:{x:.475,y:.29,rx:.026,ry:.019},mouth:{x:.445,y:.33,s:.62}},pouch:{muzzle:{x:.36,y:.37,rx:.17,ry:.15},pouch:!0,blush:{x:.27,y:.35,rx:.05,ry:.03},eyeN:{x:.22,y:.18,rx:.04,ry:.044},eyeF:{x:.43,y:.175,rx:.03,ry:.04},nose:{x:.49,y:.25,rx:.024,ry:.018},mouth:{x:.465,y:.29,s:.52}}},K={x:.32,y:.3},mt={x:.02,y:-.13},q=(e,t,n,r,i,a)=>{e.beginPath(),e.ellipse(t,n,r,i,0,0,y),e.fillStyle=a,e.fill()},ht=(e,t,n,r=1)=>{e.save(),e.translate(t,n),e.rotate(.5),e.scale(r,r),q(e,0,0,.042,.07,`#4b4039`),e.beginPath(),e.moveTo(-.014,-.05),e.lineTo(-.014,.05),e.moveTo(.016,-.045),e.lineTo(.016,.045),e.lineWidth=.008,e.strokeStyle=`#efe6dc`,e.stroke(),e.restore()},gt=(e,t,n,r,i,a,o)=>{e.save(),e.translate(t.x,t.y),e.scale(1,t.ry/t.rx),dt(e,0,0,t.rx*n,r,i,a,o*t.rx/t.ry),e.restore()},_t=(e,t,n,r,i,a)=>{let o=pt[n.face]??pt.mochi,s=.016,c=t.tilt-i*t.upright,l=n.headBump,u=()=>{e.translate(t.fx+mt.x*l,r+t.fy+mt.y*l),c&&(e.translate(K.x,K.y),e.rotate(c),e.translate(-K.x,-K.y))},d=o.muzzle,f=1+t.cheek*.28;e.save(),o.pouch&&a&&e.clip(a),u(),q(e,d.x-t.cheek*.02,d.y+t.cheek*.015,d.rx*f,d.ry*f,n.belly),e.restore(),e.save(),u();let p=o.blush,m=n.cheekSize*(1+.3*t.blush);if(e.globalAlpha=b(.5+t.blush*.5,0,1),q(e,p.x-t.cheek*.03,p.y,p.rx*m,p.ry*m,n.blush),e.globalAlpha=1,gt(e,o.eyeN,n.eyeSize,-1,t,n,s),gt(e,o.eyeF,n.eyeSize,1,t,n,s),q(e,o.nose.x,o.nose.y,o.nose.rx,o.nose.ry,n.nose),e.save(),e.translate(o.mouth.x,o.mouth.y),e.scale(o.mouth.s,o.mouth.s),ft(e,0,0,t,n,s/o.mouth.s),e.restore(),n.whiskers){let t=o.nose.x-.01;e.beginPath(),e.moveTo(t,o.mouth.y-.02),e.lineTo(t+.14,o.mouth.y-.05),e.moveTo(t,o.mouth.y+.01),e.lineTo(t+.14,o.mouth.y+.02),e.lineWidth=s*.6,e.strokeStyle=n.line,e.globalAlpha=.45,e.stroke(),e.globalAlpha=1}t.prop===`seed`&&ht(e,.5,d.y+.1,1.1),e.restore()},J=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],Y=(e,t)=>[1,0,0,1,e,t],X=(e,t,n)=>({x:e[0]*t+e[2]*n+e[4],y:e[1]*t+e[3]*n+e[5]}),vt=(e,t,n)=>({x:x(e.x,t.x,n),y:x(e.y,t.y,n)}),yt=e=>{let t=e.replace(`#`,``),n=t.length===3?t.replace(/./g,`$&$&`):t,r=parseInt(n.slice(0,6),16)||0;return[r>>16&255,r>>8&255,r&255]},bt=(e,t,n)=>{let r=yt(e),i=yt(t);return`rgb(${r.map((e,t)=>Math.round(x(e,i[t],n))).join(`,`)})`},xt=new WeakMap,St=e=>{let t=xt.get(e);return t||(t={shade:bt(e.fur,e.line,.12),stripe:bt(e.fur,e.line,.32)},xt.set(e,t)),t},Ct=(e,t)=>{let n=e.piv*.45,r=Math.cos(e.rot),i=Math.sin(e.rot),a=Y(e.bx+n,e.by+t);return a=J(a,[r,i,-i,r,0,0]),a=J(a,Y(-n,0)),a=J(a,[e.sx,0,-e.lean*e.sx,e.sy,0,0]),J(a,Y(0,-t))},wt=(e,t,n,r,i)=>{e.beginPath(),e.arc(t,n,r,0,y),e.fillStyle=i,e.fill()},Tt=(e,t,n,r,i,a,o)=>{let s=[t.fbx,t.fby,t.ffx,t.ffy,t.nbx,t.nby,t.nfx,t.nfy];e.lineCap=`round`,e.lineWidth=h.legW;for(let c of a?[2,3]:[0,1]){let a=h.hips[c],l=s[c*2],u=s[c*2+1],d=c%2==1,f=X(r,a,i-.07),p;t.feet?p={x:t.feet[c*2],y:t.feet[c*2+1]}:t.back?p=X(r,a+l,.06+u):(p=vt({x:a+l,y:-h.cap+u},X(r,a+l,-h.cap+u),d?t.float*(1-t.grip):t.float),d&&t.arm>0&&(p=vt(p,X(r,a+.08+l,i+.02+u),t.arm))),e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(p.x,p.y+1e-4),e.strokeStyle=o,e.stroke();let m=p.x-f.x,g=p.y-f.y,_=Math.hypot(m,g)||1;e.beginPath(),e.ellipse(p.x+m/_*.042,p.y+g/_*.042,.054,.021,Math.atan2(g,m)-Math.PI/2,0,y),e.fillStyle=n.paws,e.fill()}},Et=(e,t,n,r,i,a)=>{e.save(),e.translate(t,n+r*.6),e.rotate(i),wt(e,0,-r*.6,r,a.fur),wt(e,0,-r*.6+.01,r*.5,a.inner),e.restore()},Dt=(e,t)=>({x:.28+.06*e,y:t+.2-.1*e,r:.2+.1*e}),Ot=new WeakMap,kt=(e,t,n)=>{let r=Ot.get(e);if(!r){let i=n-t;if(r=new Path2D,r.roundRect(-h.halfW,t,h.halfW*2,i,Math.min(i/2,e.roundness*i)),e.headBump>.01){let n=Dt(e.headBump,t);r.moveTo(n.x+n.r,n.y),r.arc(n.x,n.y,n.r,0,y)}Ot.set(e,r)}return r},At=(e,t,n,r,i)=>{let a=St(n),o=h.halfW,s=i-r,c=s/h.bodyH,l=n.headBump;t.back||(Et(e,.36+l*.08,r-.005-l*.145,.075*n.earSize,t.earF-t.earDown*.8,n),Et(e,.1+l*.12,r+.02-l*.165,.085*n.earSize,t.earN-t.earDown*.8,n)),e.beginPath(),e.ellipse(-.53,r+.34*c+t.tail*.02,.045,.04,0,0,y),e.fillStyle=n.fur,e.fill();let u=kt(n,r,i);e.fillStyle=n.fur,e.fill(u),n.bellyStyle!==`none`&&(e.save(),e.clip(u),e.fillStyle=n.belly,n.bellyStyle===`band`?e.fillRect(-o-.1,r+s*.655,o*2+.2,s):(e.beginPath(),e.ellipse(.02,i+.02,n.bellyWidth,.2*c,0,0,y),e.fill()),e.restore()),n.stripe&&(e.beginPath(),e.moveTo(-.44,r+.07),e.quadraticCurveTo(-.08,r-.03,.26-l*.06,r+.05),e.lineWidth=.035,e.lineCap=`round`,e.strokeStyle=a.stripe,e.stroke()),e.beginPath(),e.ellipse(-.2,r+.12,.2,.06,0,0,y),e.globalAlpha=.18,e.fillStyle=`#fff`,e.fill(),e.globalAlpha=1},jt=(e,t,n,r)=>{let{yb:i,yt:a}=g(n),o=St(n),s=Ct(t,i),c=t.back?J(s,[1,0,0,-1,0,a]):s;e.save(),e.scale(r,r),Tt(e,t,n,c,i,!1,o.shade),e.save(),e.transform(...c),At(e,t,n,a,i),e.restore(),e.save(),e.transform(...t.back?J(s,Y(0,-i+.06)):s),_t(e,t,n,a,t.rot,t.back?null:kt(n,a,i)),e.restore(),Tt(e,t,n,c,i,!0,n.fur),e.restore()},Mt=new WeakMap,Nt=e=>Mt.get(e)?.back??e.belly<0,Pt=(e,t,n,r)=>{let i=t.axis,a=t.center,o=Mt.get(t)??{mirror:i.x>=0?1:-1,back:t.belly<0};i.x*o.mirror<-.25&&(o.mirror=-o.mirror);let s=-i.y*o.mirror,c=i.x*o.mirror,l=[],u=0;for(let e=2;e<t.p.length;e++){let n=t.p[e].x-a.x,o=t.p[e].y-a.y,d=(n*s+o*c)/r;l.push((n*i.x+o*i.y)/r,d),u+=d}u/=t.p.length-2,o.back=o.back?u<.08:u<-.08,Mt.set(t,o);let{cy:d,h:f}=g(n),p=o.back?-f/2:d;for(let e=1;e<l.length;e+=2)l[e]+=p;let m=!!t.grab,h=t.speed>r*6,_=v({back:o.back,feet:l,sx:1+.12*t.squash,sy:1-.18*t.squash,eye:m?`wide`:h?`squint`:`dot`,mouth:m?`o`:h?`open`:`w`,mouthOpen:.6,blush:m?.6:.2,tail:Math.sin(t.time*12),earDown:h?.6:.15,phase:t.time*1.5%1});e.rotate(Math.atan2(i.y,i.x)),e.scale(1,o.mirror),e.translate(0,-p*r),jt(e,_,n,r)},Ft={w:1.5,up:1.05,down:.1},It=e=>({...Ft,...e.box}),Lt=new Set([`idle`,`walk`,`run`,`crouch`,`jumpUp`,`jumpDown`,`fall`,`land`]),Rt=(e,t,n,r)=>{let i=N[e],a=It(i),o=Math.ceil(a.w*n*r),s=Math.ceil((a.up+a.down)*n*r),c=Math.round(o/2),l=Math.round(a.up*n*r),u=document.createElement(`canvas`);u.width=o*i.frames,u.height=s;let d=u.getContext(`2d`);if(!d)throw Error(`pet-pet: 2d context unavailable`);for(let e=0;e<i.frames;e++)d.setTransform(1,0,0,1,0,0),d.save(),d.beginPath(),d.rect(e*o,0,o,s),d.clip(),d.setTransform(r,0,0,r,e*o+c,l),jt(d,rt(i,e),t,n),d.restore();return{name:e,canvas:u,frames:i.frames,fw:o,fh:s,ax:c,ay:l}},zt=class{cache=new Map;pixels=0;look;u;dpr;budget;key;constructor(e,t,n,r=12e6){this.look=e,this.u=t,this.dpr=n,this.budget=r,this.key=JSON.stringify([e,t,n])}configure(e,t,n){let r=JSON.stringify([e,t,n]);return r!==this.key&&(this.key=r,this.look=e,this.u=t,this.dpr=n,this.clear(),!0)}clear(){for(let e of this.cache.values())e.canvas.width=0;this.cache.clear(),this.pixels=0}get(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=Rt(e,this.look,this.u,this.dpr);return this.cache.set(e,n),this.pixels+=n.canvas.width*n.canvas.height,this.evict(),n}prewarm(e=Lt){for(let t of e)this.get(t)}get size(){return{strips:this.cache.size,pixels:this.pixels}}evict(){for(let[e,t]of this.cache){if(this.pixels<=this.budget)return;Lt.has(e)||(this.cache.delete(e),this.pixels-=t.canvas.width*t.canvas.height,t.canvas.width=0)}}},Z={w:2,h:2.45,ax:1,ay:1.68,cy:1.22},Bt=.14,Q=(e,t)=>Object.assign(e.style,t),Vt=class{layer;wrap;canvas;ctx;hitbox;shadow;label=null;u=64;dpr=1;mode=`anim`;turnTime=.18;turn=0;snapTurn=!0;turnKey=``;lastKey=``;lastPos=``;lastShadow=``;constructor(e){this.layer=document.createElement(`div`),this.layer.setAttribute(`data-pet-layer`,``),this.layer.setAttribute(`data-pet-ignore`,``),this.layer.setAttribute(`aria-hidden`,`true`),Q(this.layer,{position:`fixed`,left:`0`,top:`0`,width:`0`,height:`0`,zIndex:String(e),pointerEvents:`none`}),this.shadow=document.createElement(`div`),Q(this.shadow,{position:`absolute`,left:`0`,top:`0`,borderRadius:`50%`,background:`radial-gradient(closest-side, rgba(70,45,30,0.22), rgba(70,45,30,0))`,willChange:`transform, opacity`}),this.wrap=document.createElement(`div`),Q(this.wrap,{position:`absolute`,left:`0`,top:`0`,willChange:`transform`}),this.canvas=document.createElement(`canvas`),Q(this.canvas,{position:`absolute`,display:`block`});let t=this.canvas.getContext(`2d`);if(!t)throw Error(`pet-pet: 2d context unavailable`);this.ctx=t,this.hitbox=document.createElement(`div`),Q(this.hitbox,{position:`absolute`,borderRadius:`40%`,pointerEvents:`auto`,cursor:`grab`,touchAction:`none`,userSelect:`none`,webkitUserSelect:`none`}),this.wrap.append(this.canvas,this.hitbox),this.layer.append(this.shadow,this.wrap),document.body.append(this.layer)}resize(e,t){e===this.u&&t===this.dpr&&this.canvas.width||(this.u=e,this.dpr=t,this.canvas.width=Math.ceil(Z.w*e*t),this.canvas.height=Math.ceil(Z.h*e*t),Q(this.canvas,{width:`${Z.w*e}px`,height:`${Z.h*e}px`}),Q(this.shadow,{width:`${e*1.05}px`,height:`${e*.16}px`}),Q(this.hitbox,{width:`${e*1.05}px`,height:`${e*.72}px`}),this.setMode(this.mode,!0),this.lastKey=``)}setMode(e,t=!1){if(e===this.mode&&!t)return;e!==this.mode&&(this.snapTurn=!0),this.mode=e;let n=this.u,r=e===`anim`?Z.ay:Z.cy;Q(this.canvas,{left:`${-Z.ax*n}px`,top:`${-r*n}px`,transformOrigin:`${Z.ax*n}px ${r*n}px`});let i=e===`anim`?-.74:-.36;Q(this.hitbox,{left:`${-.525*n}px`,top:`${i*n}px`}),this.turnKey=``,this.applyTurn(),this.lastKey=``}setFacing(e,t){let n=e>0?0:Math.PI;if(this.snapTurn||this.turnTime<=0)this.turn=n;else if(this.turn!==n){let e=Math.PI*t/this.turnTime,r=n-this.turn;this.turn=Math.abs(r)<=e?n:this.turn+Math.sign(r)*e}this.snapTurn=!1,this.applyTurn()}applyTurn(){let e=`none`;if(this.mode===`anim`){let t=Math.cos(this.turn),n=Math.sin(this.turn);if(n>.01){let r=(t<0?-1:1)*Math.max(Bt,Math.abs(t));e=`translateY(${(-.05*n*this.u).toFixed(2)}px) scaleX(${r.toFixed(3)})`}else t<0&&(e=`scaleX(-1)`)}e!==this.turnKey&&(this.turnKey=e,this.canvas.style.transform=e)}place(e,t){let n=`${e.toFixed(1)},${t.toFixed(1)}`;n!==this.lastPos&&(this.lastPos=n,this.wrap.style.transform=`translate3d(${e.toFixed(2)}px,${t.toFixed(2)}px,0)`,this.label&&(this.label.style.transform=`translate3d(${e.toFixed(1)}px,${(t-this.u*1.35).toFixed(1)}px,0) translateX(-50%)`))}placeShadow(e,t,n,r){let i=`${e.toFixed(1)},${t.toFixed(1)},${n.toFixed(2)},${r.toFixed(2)}`;if(i===this.lastShadow)return;this.lastShadow=i;let a=this.u*1.05,o=this.u*.16;this.shadow.style.transform=`translate3d(${(e-a/2).toFixed(1)}px,${(t-o/2).toFixed(1)}px,0) scale(${n.toFixed(3)})`,this.shadow.style.opacity=r.toFixed(2)}invalidate(){this.lastKey=``}drawStrip(e,t){let n=`${e.name}:${t}:${e.fw}`;if(n===this.lastKey)return;this.lastKey=n;let{ctx:r}=this,i=Math.round(Z.ax*this.u*this.dpr-e.ax),a=Math.round(Z.ay*this.u*this.dpr-e.ay);r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,this.canvas.width,this.canvas.height),r.drawImage(e.canvas,t*e.fw,0,e.fw,e.fh,i,a,e.fw,e.fh)}drawLive(e){this.paint(Z.cy,e)}drawPose(e,t){this.paint(Z.ay,n=>jt(n,e,t,this.u))}paint(e,t){this.lastKey=``;let{ctx:n,u:r,dpr:i}=this;n.setTransform(1,0,0,1,0,0),n.clearRect(0,0,this.canvas.width,this.canvas.height),n.setTransform(i,0,0,i,Math.round(Z.ax*r*i),Math.round(e*r*i)),t(n)}setLabel(e){e===null?(this.label?.remove(),this.label=null):(this.label||(this.label=document.createElement(`div`),Q(this.label,{position:`absolute`,left:`0`,top:`0`,font:`11px ui-monospace, monospace`,padding:`1px 6px`,borderRadius:`6px`,background:`rgba(30,20,15,0.75)`,color:`#fff`,whiteSpace:`nowrap`}),this.layer.append(this.label)),this.label.textContent!==e&&(this.label.textContent=e))}destroy(){this.layer.remove()}},Ht=(e,t,n)=>{if(typeof e==`number`)return e;let r=/^(-?\d*\.?\d+)(px|vh|vw|vmin)$/.exec(e.trim());if(!r)return 64;let i=parseFloat(r[1]);switch(r[2]){case`vh`:return i/100*n;case`vw`:return i/100*t;case`vmin`:return i/100*Math.min(t,n);default:return i}},Ut=()=>({left:0,top:0,right:document.documentElement.clientWidth||window.innerWidth,bottom:window.innerHeight}),Wt=e=>{let t=Ut();if(!e)return t;let n=e.getBoundingClientRect(),r=n.left+e.clientLeft,i=n.top+e.clientTop;return{left:Math.max(t.left,r),top:Math.max(t.top,i),right:Math.min(t.right,r+e.clientWidth),bottom:Math.min(t.bottom,i+e.clientHeight)}},Gt=new Set([`BUTTON`,`INPUT`,`TEXTAREA`,`SELECT`,`IMG`,`VIDEO`,`CANVAS`,`IFRAME`,`PRE`,`TABLE`,`PICTURE`]),Kt=new Set([`SCRIPT`,`STYLE`,`LINK`,`META`,`TEMPLATE`,`NOSCRIPT`,`BR`,`HTML`,`HEAD`]),qt=new WeakMap,Jt=1,Yt=e=>{let t=qt.get(e);return t||(t=Jt++,qt.set(e,t)),t},Xt=e=>e===`transparent`||e===`rgba(0, 0, 0, 0)`||/,\s*0\)$/.test(e),Zt=e=>!Xt(e.backgroundColor)||e.backgroundImage!==`none`||e.boxShadow!==`none`||parseFloat(e.borderTopWidth)>0&&e.borderTopStyle!==`none`&&!Xt(e.borderTopColor),Qt=(e,t)=>{let n=e.getBoundingClientRect();return!n.width&&!n.height?!1:n.bottom<t.top||n.top>t.bottom||n.right<t.left||n.left>t.right},$t=(e,t,n=2500,r)=>{let i=[],a=new Map,o=e instanceof Document?e.body:e;if(!o)return i;let s=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let n=e;return Kt.has(n.tagName)||t.ignore&&n.matches(t.ignore)||r&&n!==o&&Qt(n,r)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),c=0,l=r?n*8:n;for(let r=s.currentNode;r&&c<l&&i.length<n;r=s.nextNode()){c++;let n=r;if(n===o&&!(e instanceof Document))continue;let s=t.selector?n.matches(t.selector):!1;if(!s&&!t.auto)continue;let l=getComputedStyle(n);if(l.display===`none`||l.display===`contents`||l.visibility===`hidden`||parseFloat(l.opacity)<.05||!s&&!Gt.has(n.tagName)&&!Zt(l))continue;let u={id:Yt(n),el:n,ancestors:new Set};for(let e=n.parentElement;e;e=e.parentElement){let t=a.get(e);if(t){u.ancestors.add(t.id);for(let e of t.ancestors)u.ancestors.add(e);break}}a.set(n,u),i.push(u)}return i},en=(e,t,n)=>{let r=[];for(let[i,a]of e)n<=i||t>=a?r.push([i,a]):(t>i&&r.push([i,t]),n<a&&r.push([n,a]));return r},tn=(e,t)=>{let{bounds:n,u:r}=t,i=[{id:`floor`,el:null,top:n.bottom,left:n.left+t.pad,right:n.right-t.pad,ex:n.left}],a=n.right-n.left,o=n.bottom-n.top;e=e.filter(e=>e.rect.bottom>n.top&&e.rect.top<n.bottom);for(let s of e){let c=s.rect,l=c.right-c.left;if(l<t.minWidth||c.bottom-c.top<4||c.top<n.top+t.headroom||c.top>n.bottom-2||c.right<n.left||c.left>n.right||l>a*.92&&c.bottom-c.top>o*.7)continue;let u=[[Math.max(c.left,n.left)+t.pad,Math.min(c.right,n.right)-t.pad]],d=c.top-t.headroom,f=c.top-1;for(let t of e){if(t===s||s.ancestors.has(t.id))continue;let e=t.rect;if(!(e.bottom<=d||e.top>=f)&&(u=en(u,e.left-r*.25,e.right+r*.25),!u.length))break}let p=0;for(let[e,t]of u)t-e<r*.5||i.push({id:`${s.id}:${p++}`,el:s.el,top:c.top,left:e,right:t,ex:c.left})}return i},nn=(e,t,n)=>{let r=null;for(let i of e)t<i.left||t>i.right||i.top<n-1||(!r||i.top<r.top)&&(r=i);return r},rn=(e,t,n,r,i=0)=>{let a=null;for(let o of e)t<o.left-i||t>o.right+i||o.top<n-1||o.top>r||(!a||o.top<a.top)&&(a=o);return a},an=.25,on=.35,sn=class{bounds;surfaces=[];version=0;o;candidates=[];scanDirty=!0;scanTimer=0;rectDirty=!0;sinceMeasure=0;measuredThisFrame=!1;mo=null;onScroll=()=>{this.rectDirty=!0,this.o.platforms().cull>0&&(this.scanDirty=!0,this.scanTimer=0)};constructor(e){this.o=e,this.bounds=Wt(e.container),window.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0}),window.addEventListener(`resize`,this.onScroll,{passive:!0});let t=e.root instanceof Document?e.root.body:e.root;t&&`MutationObserver`in window&&(this.mo=new MutationObserver(t=>{for(let n of t)if(!e.layer.contains(n.target)){this.scanDirty=!0,this.scanTimer=0;return}}),this.mo.observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`class`,`hidden`,`open`,`data-pet-platform`,`data-pet-ignore`]}))}invalidate(e=!1){this.rectDirty=!0,e&&(this.scanDirty=!0,this.scanTimer=on)}update(e){if(this.measuredThisFrame=!1,this.sinceMeasure+=e,this.scanDirty&&(this.scanTimer+=e,this.scanTimer>=on||!this.candidates.length)){let e=this.o.platforms(),t=e.cull*this.o.unit(),n=Wt(this.o.container),r=e.cull>0?{left:n.left-t,top:n.top-t,right:n.right+t,bottom:n.bottom+t}:void 0;this.candidates=$t(this.o.root,e,2500,r),this.scanDirty=!1,this.scanTimer=0,this.rectDirty=!0}(this.rectDirty||this.sinceMeasure>=an)&&this.measure()}measure(){let e=this.o.unit(),t=this.o.platforms();this.bounds=Wt(this.o.container);let n=[];for(let e of this.candidates)e.el.isConnected&&n.push({id:e.id,el:e.el,rect:e.el.getBoundingClientRect(),ancestors:e.ancestors});this.surfaces=tn(n,{bounds:this.bounds,u:e,minWidth:t.minWidth*e,headroom:e*.85,pad:e*.3}),this.rectDirty=!1,this.sinceMeasure=0,this.measuredThisFrame=!0,this.version++}get floor(){return this.surfaces[0]??{id:`floor`,el:null,top:this.bounds.bottom,left:this.bounds.left,right:this.bounds.right,ex:this.bounds.left}}byId(e){for(let t of this.surfaces)if(t.id===e)return t;return null}refresh(e,t){if(e.id===`floor`)return this.floor;if(!e.el||!e.el.isConnected)return null;if(this.measuredThisFrame){let n=this.byId(e.id);if(n&&t>=n.left-2&&t<=n.right+2)return n;let r=null;for(let n of this.surfaces)if(n.el===e.el){if(t>=n.left-2&&t<=n.right+2)return n;(!r||Math.abs(n.left-t)<Math.abs(r.left-t))&&(r=n)}return r&&Math.abs(r.top-e.top)<1?r:n}let n=e.el.getBoundingClientRect();if(n.top===e.top&&n.left===e.ex)return e;let r=n.left-e.ex;this.rectDirty=!0;let i={...e,top:n.top,left:e.left+r,right:e.right+r,ex:n.left},a=this.surfaces.findIndex(t=>t.id===e.id);return a>=0&&(this.surfaces[a]=i),i}landing(e,t,n,r=0){return rn(this.surfaces,e,t,n,r)}below(e,t){return nn(this.surfaces,e,t)}surfaceFor(e){let t=this.surfaces.filter(t=>t.el===e);if(t.length)return t.reduce((e,t)=>t.right-t.left>e.right-e.left?t:e);let n=null,r=e.getBoundingClientRect();for(let t of this.surfaces)t.el&&e.contains(t.el)&&(!n||t.top<n.top)&&(n=t);if(n)return n;for(let t of this.surfaces)t.el&&t.el.contains(e)&&t.top<=r.top+1&&(!n||t.top>n.top)&&(n=t);return n}destroy(){window.removeEventListener(`scroll`,this.onScroll,{capture:!0}),window.removeEventListener(`resize`,this.onScroll),this.mo?.disconnect()}},$=(e,t,n)=>Math.max(t,Math.min(n,e)),cn=class{cfg;u;view;bank;world;body;anim=new ct;brain;fx;bubble;input;ctx;rag=null;seeds=[];debug=null;events=new Fe;unbind;raf=0;last=0;resizeAt=-1;maxImpact=0;held=!1;stateKey=``;root;constructor(e={}){this.cfg=z(Me,e),this.root=e.root??document,this.u=this.measureUnit(),this.view=new Vt(this.cfg.zIndex),this.view.resize(this.u,this.dpr),this.bank=new zt(this.cfg.appearance,this.u,this.dpr),this.world=new sn({container:e.container??null,root:this.root,layer:this.view.layer,platforms:()=>this.cfg.platforms,unit:()=>this.u}),this.fx=new Ue(this.view.layer,()=>this.u),this.bubble=new ze(this.view.layer),this.body=new Xe({land:(e,t)=>{this.ctx.landing={kind:`land`,surface:e,height:t},this.emit(`land`,{surface:e,height:t})},ledge:e=>{this.ctx.landing={kind:`ledge`,surface:e,height:0}},leave:()=>{}}),this.input=new Ye(this.view.hitbox,{press:()=>{},click:e=>!this.rag&&this.brain.onClick(e),longPress:()=>{this.rag||(this.held=!0,this.brain.onLongPress(()=>this.held))},longRelease:()=>{this.held=!1},dragStart:(e,t)=>this.grab(e,t),dragMove:(e,t)=>this.rag?.moveGrab(e,t),dragEnd:()=>this.release(),stroke:e=>this.cfg.behavior.stroke&&!this.rag&&this.brain.onStroke(e)}),this.ctx={cfg:this.cfg,u:this.u,now:performance.now()/1e3,body:this.body,world:this.world,anim:this.anim,fx:this.fx,cursor:this.input.cursor,seeds:this.seeds,landing:null,emit:this.emit,say:(e,t)=>this.say(e,t),spawn:(e,t=0,n=-1)=>this.fx.spawn(e,this.body.x+this.body.facing*t*this.u,this.body.y+n*this.u)},this.brain=new ke(this.ctx),this.unbind=Re({container:e.container??null,ignore:()=>this.cfg.platforms.ignore,react:(e,t)=>void this.react(e,{say:t}),say:e=>this.say(e),typing:e=>!this.rag&&this.brain.onTyping(e)}),window.addEventListener(`resize`,this.onResize);let t=this.world.bounds;this.body.place(e.spawn?.x??t.left+(t.right-t.left)*(.25+Math.random()*.5),e.spawn?.y??t.top+this.u,null),this.applyConfig(),(window.requestIdleCallback?.bind(window)??(e=>window.setTimeout(e,300)))(()=>this.bank.prewarm()),this.raf=requestAnimationFrame(this.frame)}get dpr(){return Math.min(this.cfg.maxDpr,window.devicePixelRatio||1)}measureUnit(){return Math.max(12,Ht(this.cfg.size,window.innerWidth,window.innerHeight))}onResize=()=>{this.resizeAt=performance.now()};applySize(){this.resizeAt=-1,this.u=this.ctx.u=this.measureUnit(),this.view.resize(this.u,this.dpr),this.bank.configure(this.cfg.appearance,this.u,this.dpr)&&this.view.invalidate(),this.world.invalidate()}frame=e=>{this.raf=requestAnimationFrame(this.frame);let t=this.last?Math.min(.05,(e-this.last)/1e3):1/60;this.last=e,this.ctx.now=e/1e3,this.resizeAt>=0&&e-this.resizeAt>180&&!this.rag&&this.applySize(),this.world.update(t),this.rag?this.stepRagdoll(t):(this.brain.update(t),this.body.update(t,this.world,this.u,this.cfg.physics),this.anim.update(t)),this.updateSeeds(t),this.render(e,t)};grab(e,t){if(this.held=!1,this.maxImpact=0,!this.rag){let e=this.body;this.brain.pause(!0),this.anim.snap(),this.rag=new Ze(this.u,e.x,e.y-G*this.u,e.vx,e.vy,e.facing),e.place(e.x,e.y,null),this.view.setMode(`ragdoll`)}this.rag.startGrab(e,t);let n=this.rag.toLocal(e,t).x;this.emit(`grab`,{part:n>.2?`head`:n<-.2?`bottom`:`body`})}release(){this.rag&&(this.rag.release(),this.emit(`throw`,{speed:this.rag.speed/this.u}))}onImpact=e=>{this.maxImpact=Math.max(this.maxImpact,e.speed),this.emit(`impact`,e),e.speed>16&&this.fx.spawn(`bonk`,e.x,e.y)};stepRagdoll(e){let t=this.rag;t.step(e,this.world,this.cfg.physics,this.onImpact);let n=t.center;this.body.x=n.x,this.body.y=n.y+G*this.u,!t.grab&&t.restTime>.35&&this.settle(t)}settle(e){let t=e.center,n=this.world.below(t.x,t.y-this.u*.2)??this.world.floor,r=Nt(e),i=!r&&Math.abs(e.axis.y)>.45,a=this.maxImpact>this.cfg.physics.dizzyImpact;this.rag=null,this.body.place($(t.x,n.left+1,n.right-1),n.top,n),this.body.face(e.axis.x||e.facing),this.view.setMode(`anim`),this.brain.pause(!1),this.brain.afterRagdoll({back:r,dizzy:a,tilted:i})}updateSeeds(e){let t=this.cfg.physics.gravity*this.u;for(let n=this.seeds.length-1;n>=0;n--){let r=this.seeds[n];r.eaten||r.age>45&&!r.claimed?(r.eaten||r.remove(),this.seeds.splice(n,1)):r.update(e,this.world,t)}}placeShadow(e,t){let n=(!this.rag&&this.body.grounded?this.body.surface:this.world.below(e,t))?.top??this.world.bounds.bottom,r=$(1-(n-t)/(this.u*5),0,1);this.view.placeShadow(e,n,.45+.55*r,r)}render(e,t){let n=this.view,r=this.u,i=this.body;if(this.rag){let t=this.rag,i=t.center;n.place(i.x,i.y),n.drawLive(e=>Pt(e,t,this.cfg.appearance,r)),this.placeShadow(i.x,i.y+r*G),this.bubble.update(e,i.x,i.y-r*.55,this.world.bounds)}else{n.setFacing(i.facing,t),n.place(i.x,i.y);let r=this.bank.get(this.anim.name);this.anim.blending?n.drawPose(this.anim.pose(),this.cfg.appearance):n.drawStrip(r,this.anim.frame),this.placeShadow(i.x,i.y);let a=Ae(this.ctx);this.bubble.update(e,a.x,a.y,this.world.bounds)}let a=this.brain.task,o=this.rag?`ragdoll`:this.anim.name,s=`${a}|${o}`;s!==this.stateKey&&(this.stateKey=s,this.emit(`state`,{task:a,anim:o})),this.cfg.debug.state&&n.setLabel(`${a} · ${o}`),this.debug?.draw(this.world.version,this.world.surfaces,this.world.bounds,i.surface?.id??null)}applyConfig(){this.anim.blendScale=this.cfg.motion.blend,this.view.turnTime=this.cfg.motion.turnTime;let e=this.cfg.debug.surfaces;e&&!this.debug?this.debug=new Ne(this.view.layer):!e&&this.debug&&(this.debug.destroy(),this.debug=null),this.cfg.debug.state||this.view.setLabel(null)}emit=this.events.emit;on(e,t){return this.events.on(e,t)}off(e,t){this.events.off(e,t)}react(e,t={}){let n=Ie(e);return!n||this.rag?Promise.resolve(!1):new Promise(e=>this.brain.react(n,t,e))}say(e,t){this.bubble.say(e,t??Math.max(1800,e.length*70),performance.now())}goTo(e){let t=typeof e==`string`?this.root.querySelector(e):e,n=t&&this.world.surfaceFor(t);if(!t||!n||this.rag)return Promise.resolve(!1);let r=t.getBoundingClientRect();return new Promise(e=>this.brain.goTo(n.id,$((r.left+r.right)/2,n.left,n.right),e))}goNear(e,t){let n=this.world.below(e,t-this.u*.2)??this.world.floor;return this.rag?Promise.resolve(!1):new Promise(t=>this.brain.goTo(n.id,$(e,n.left,n.right),t))}feed(e){if(this.seeds.length>=6)return;let t=this.world.bounds,n=e??t.left+this.u+Math.random()*Math.max(0,t.right-t.left-2*this.u);this.seeds.push(new Ge(this.view.layer,$(n,t.left,t.right),t.top+this.u*.3,this.u*.26))}sleep(){this.rag||this.brain.sleepNow()}wake(){this.brain.wake()}idle(){this.rag||this.brain.stop()}get hidden(){return this.view.layer.style.visibility===`hidden`}set hidden(e){this.view.layer.style.visibility=e?`hidden`:``}set(e){let t=this.cfg;this.cfg=this.ctx.cfg=z(t,e),this.cfg.zIndex!==t.zIndex&&(this.view.layer.style.zIndex=String(this.cfg.zIndex)),this.cfg.size!==t.size||this.cfg.maxDpr!==t.maxDpr?this.resizeAt=0:this.bank.configure(this.cfg.appearance,this.u,this.dpr)&&this.view.invalidate(),e.platforms&&this.world.invalidate(!0),this.applyConfig()}refresh(){this.world.invalidate(!0)}get state(){return{mode:this.rag?`ragdoll`:`anim`,task:this.brain.task,anim:this.rag?`ragdoll`:this.anim.name,sleeping:this.brain.sleeping,x:this.body.x,y:this.body.y,unit:this.u}}destroy(){cancelAnimationFrame(this.raf),window.removeEventListener(`resize`,this.onResize),this.unbind(),this.brain.stop(),this.input.destroy(),this.world.destroy();for(let e of this.seeds)e.remove();this.seeds.length=0,this.bank.clear(),this.debug?.destroy(),this.view.destroy(),this.events.clear()}};return e.DEFAULT_CONFIG=Me,e.PRESETS=I,e.Pet=cn,e.REACTION_ALIASES=ue,e.REACTION_NAMES=Pe,e.SHAPES=je,e.createPet=e=>new cn(e),e.mergeConfig=z,e.resolveReaction=Ie,e})({});
|
|
</script>
|
|
<script>
|
|
/*
|
|
* What a pet does for its conversation's mood and news — plain functions,
|
|
* shared by the overlay (pets.js) and the tests (tests/mood.test.mjs).
|
|
*
|
|
* | mood | the pet |
|
|
* | --------- | ------------------------------ |
|
|
* | busy | `thinking`, held |
|
|
* | waiting | `confused` + "?", held |
|
|
* | error | `sad`, once |
|
|
* | done | sleeps |
|
|
* | free | its own business |
|
|
*
|
|
* Stamps: commit / push → approve, merge / deploy → success (confetti),
|
|
* notify → wave, each with a bubble. A new Claude message → a little hop
|
|
* (`surprised`), at most every 15 s.
|
|
*/
|
|
(function (root) {
|
|
var HELD = {
|
|
busy: { reaction: "thinking" },
|
|
waiting: { reaction: "confused", say: "?" },
|
|
};
|
|
var STAMPS = {
|
|
committed: ["approve", { en: "Committed", fr: "Commité" }],
|
|
pushed: ["approve", { en: "Pushed", fr: "Poussé" }],
|
|
merged: ["success", { en: "Merged!", fr: "Fusionné !" }],
|
|
deployed: ["success", { en: "Deployed!", fr: "Déployé !" }],
|
|
notified: ["wave", { en: "Done — check your phone", fr: "Fini — regarde ton téléphone" }],
|
|
};
|
|
var HOP_EVERY_MS = 15000;
|
|
|
|
/** The held reaction a mood plays, or null. */
|
|
function held(mood) {
|
|
return HELD[mood] || null;
|
|
}
|
|
|
|
/** What to do when the mood turns to `mood`. */
|
|
function onMood(mood) {
|
|
if (HELD[mood]) return { kind: "hold", reaction: HELD[mood].reaction, say: HELD[mood].say };
|
|
if (mood === "done") return { kind: "sleep" };
|
|
if (mood === "error") return { kind: "react", reaction: "sad", duration: 3.5 };
|
|
return { kind: "idle" };
|
|
}
|
|
|
|
/** The one-shot for a stamp, in the person's language. */
|
|
function stampCue(stamp, lang) {
|
|
var s = STAMPS[stamp];
|
|
if (!s) return null;
|
|
return { reaction: s[0], say: s[1][lang === "fr" ? "fr" : "en"] };
|
|
}
|
|
|
|
/** A new message hops, unless the last hop was under 15 s ago. */
|
|
function hopDue(lastHopAt, now) {
|
|
return !lastHopAt || now - lastHopAt >= HOP_EVERY_MS;
|
|
}
|
|
|
|
/** How a run that just left the rail ended. */
|
|
function endingCue(ending) {
|
|
return ending === "finished" || ending === "review" ? "success" : "sad";
|
|
}
|
|
|
|
/** `#rrggbb` → the hamster's fur, belly and outline. */
|
|
function appearance(hex) {
|
|
var m = /^#([0-9a-f]{6})$/i.exec(hex || "");
|
|
var n = m ? parseInt(m[1], 16) : 0xf4b66a;
|
|
var base = [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
function mix(to, k) {
|
|
return base.map(function (c, i) { return c + (to[i] - c) * k; });
|
|
}
|
|
function h(c) {
|
|
return "#" + c.map(function (v) { return Math.round(v).toString(16).padStart(2, "0"); }).join("");
|
|
}
|
|
return { fur: h(base), belly: h(mix([255, 255, 255], 0.82)), line: h(mix([0, 0, 0], 0.62)) };
|
|
}
|
|
|
|
/** A pet's touch box (its hitbox element's rect), a little wider: the
|
|
* box the host lets the frame take the pointer in. */
|
|
function hitBox(r, pad) {
|
|
return { x: r.left - pad, y: r.top - pad, w: r.width + 2 * pad, h: r.height + 2 * pad };
|
|
}
|
|
|
|
root.PetsMood = { held: held, onMood: onMood, stampCue: stampCue, hopDue: hopDue, endingCue: endingCue, appearance: appearance, hitBox: hitBox };
|
|
})(typeof window !== "undefined" ? window : globalThis);
|
|
|
|
</script>
|
|
<script>
|
|
/*
|
|
* The pets overlay: pet-pet hamsters in a transparent frame over the page
|
|
* (the ai-agent's `ui.overlays` point — docs/plugins.md → "Overlays").
|
|
*
|
|
* The frame can't see the page. The host sends the outlines of its solid
|
|
* boxes (`layout`: cards, code blocks, the composer…); we lay an invisible
|
|
* platform at each, and the hamsters walk, hop and climb them as they did in
|
|
* the page. A home card's outline carries its conversation's id (`anchor`):
|
|
* that run's hamster lives on it.
|
|
*
|
|
* - conversation page: one hamster in the conversation's colour, playing its
|
|
* mood (mood.js);
|
|
* - home page: a colony — your own hamster (Preferences colour) plus one per
|
|
* running conversation. They visit each other (hearts), wave at a newcomer,
|
|
* are sad when one leaves; a rail pet walks back to its card after 25 s
|
|
* away and drops back onto it after 50 s.
|
|
*/
|
|
(function () {
|
|
"use strict";
|
|
var api = window.aiAgentPlugin;
|
|
var ov = api.overlay;
|
|
var M = window.PetsMood;
|
|
var where = api.init.where;
|
|
var lang = api.init.lang;
|
|
var createPet = window.PetPet.createPet;
|
|
|
|
var CULL = 2;
|
|
var SETTLE_MS = 4000;
|
|
var PLAY_EVERY_MS = 7000;
|
|
var TOGETHER_U = 3;
|
|
var HOMESICK_S = 25;
|
|
var GIVE_UP_S = 50;
|
|
var TICK_S = 2;
|
|
var bornAt = Date.now();
|
|
|
|
var prefs = { enabled: true, size: 46, color: "#f4b66a" };
|
|
var layout = { w: innerWidth, h: innerHeight, surfaces: [], anchors: {} };
|
|
var members = [];
|
|
|
|
// ── platforms ──────────────────────────────────────────────────────────────
|
|
var floor = document.createElement("div");
|
|
floor.style.cssText = "position:fixed;left:0;top:0;width:0;height:0;pointer-events:none";
|
|
document.body.appendChild(floor);
|
|
var divs = new Map();
|
|
function applyLayout(l) {
|
|
layout = l;
|
|
var keep = new Set();
|
|
for (var i = 0; i < l.surfaces.length; i++) {
|
|
var s = l.surfaces[i];
|
|
var d = divs.get(s.id);
|
|
if (!d) {
|
|
d = document.createElement("div");
|
|
d.setAttribute("data-pet-platform", "");
|
|
d.style.position = "fixed";
|
|
floor.appendChild(d);
|
|
divs.set(s.id, d);
|
|
}
|
|
d.style.left = s.x + "px";
|
|
d.style.top = s.y + "px";
|
|
d.style.width = s.w + "px";
|
|
d.style.height = s.h + "px";
|
|
if (s.anchor) d.dataset.anchor = s.anchor;
|
|
else delete d.dataset.anchor;
|
|
keep.add(s.id);
|
|
}
|
|
divs.forEach(function (d, id) {
|
|
if (!keep.has(id)) {
|
|
d.remove();
|
|
divs.delete(id);
|
|
}
|
|
});
|
|
}
|
|
function anchorEl(id) {
|
|
var found = null;
|
|
divs.forEach(function (d) {
|
|
if (d.dataset.anchor === id) found = d;
|
|
});
|
|
return found;
|
|
}
|
|
|
|
// ── one pet ────────────────────────────────────────────────────────────────
|
|
/** A hamster that plays a conversation's mood; `id` null = your own. */
|
|
function Buddy(id, color, opts) {
|
|
this.id = id;
|
|
this.color = color;
|
|
this.mood = "free";
|
|
this.cueing = false;
|
|
this.lastHop = 0;
|
|
this.away = 0;
|
|
this.walking = false;
|
|
this.ended = false;
|
|
this.opts = opts || {};
|
|
this.make();
|
|
}
|
|
Buddy.prototype.make = function () {
|
|
var spawn = this.opts.spawn ? this.opts.spawn() : undefined;
|
|
this.pet = createPet({
|
|
zIndex: 30,
|
|
container: null,
|
|
root: document,
|
|
size: prefs.size,
|
|
spawn: spawn,
|
|
appearance: M.appearance(this.color),
|
|
behavior: this.opts.behavior,
|
|
platforms: { auto: false, selector: "[data-pet-platform]", cull: CULL },
|
|
});
|
|
this.away = 0;
|
|
this.play(this.mood, true);
|
|
};
|
|
Buddy.prototype.respawn = function () {
|
|
this.pet.destroy();
|
|
this.make();
|
|
};
|
|
Buddy.prototype.set = function (color) {
|
|
if (color === this.color) return;
|
|
this.color = color;
|
|
this.pet.set({ appearance: M.appearance(color) });
|
|
};
|
|
Buddy.prototype.play = function (mood, force) {
|
|
if (mood === this.mood && !force) return;
|
|
this.mood = mood;
|
|
var p = this.pet;
|
|
var a = M.onMood(mood);
|
|
if (a.kind === "hold") {
|
|
p.wake();
|
|
p.react(a.reaction, { hold: true, say: a.say });
|
|
} else if (a.kind === "sleep") p.sleep();
|
|
else if (a.kind === "react") {
|
|
p.wake();
|
|
p.react(a.reaction, { duration: a.duration });
|
|
} else if (p.state.task.indexOf("react:") === 0) p.idle();
|
|
};
|
|
/** Put a held mood back if something knocked it off (a pat, a throw). */
|
|
Buddy.prototype.reassert = function () {
|
|
var h = M.held(this.mood);
|
|
var s = this.pet.state;
|
|
if (!h || this.cueing || s.mode === "ragdoll" || s.task === "goto") return;
|
|
if (s.task !== "react:" + h.reaction) this.pet.react(h.reaction, { hold: true });
|
|
};
|
|
Buddy.prototype.cue = function (reaction, say, duration) {
|
|
var self = this;
|
|
var p = this.pet;
|
|
p.wake();
|
|
this.cueing = true;
|
|
p.react(reaction, { say: say, duration: duration }).finally(function () {
|
|
self.cueing = false;
|
|
var h = M.held(self.mood);
|
|
if (h) p.react(h.reaction, { hold: true });
|
|
});
|
|
};
|
|
Buddy.prototype.destroy = function () {
|
|
this.pet.destroy();
|
|
};
|
|
function isFree(p) {
|
|
var s = p.state;
|
|
return !s.sleeping && s.mode === "anim" && s.task !== "goto" && s.task.indexOf("react:") !== 0;
|
|
}
|
|
|
|
// ── the page's pets ────────────────────────────────────────────────────────
|
|
var pets = new Map(); // conversation id → Buddy
|
|
var own = null; // your hamster (home)
|
|
|
|
function railSpawn(id) {
|
|
return function () {
|
|
var a = layout.anchors[id];
|
|
if (!a) return undefined;
|
|
var pad = Math.min(48, a.w / 3);
|
|
return { x: a.x + pad + Math.random() * (a.w - 2 * pad), y: a.y - prefs.size * 1.6 };
|
|
};
|
|
}
|
|
|
|
function sync() {
|
|
if (!prefs.enabled) {
|
|
pets.forEach(function (b) { b.destroy(); });
|
|
pets.clear();
|
|
if (own) own.destroy(), (own = null);
|
|
return;
|
|
}
|
|
var want = where === "conversation" ? members.slice(0, 1) : members;
|
|
var ids = new Set();
|
|
want.forEach(function (m) {
|
|
ids.add(m.id);
|
|
var b = pets.get(m.id);
|
|
if (!b) {
|
|
b = new Buddy(m.id, m.color, where === "home" ? { spawn: railSpawn(m.id), behavior: { explore: 0.3 } } : {});
|
|
pets.set(m.id, b);
|
|
if (where === "home") greet(b);
|
|
}
|
|
b.set(m.color);
|
|
b.play(m.mood);
|
|
if (m.ending && !b.ended) {
|
|
b.ended = true;
|
|
b.pet.wake();
|
|
b.pet.react(M.endingCue(m.ending));
|
|
}
|
|
});
|
|
var left = false;
|
|
pets.forEach(function (b, id) {
|
|
if (!ids.has(id)) {
|
|
b.destroy();
|
|
pets.delete(id);
|
|
left = true;
|
|
}
|
|
});
|
|
if (left) goodbye();
|
|
if (where === "home" && !own) {
|
|
own = new Buddy(null, prefs.color, {
|
|
spawn: function () {
|
|
return { x: layout.w * (0.2 + Math.random() * 0.6), y: prefs.size };
|
|
},
|
|
});
|
|
}
|
|
if (own) own.set(prefs.color);
|
|
}
|
|
|
|
function all() {
|
|
var out = [];
|
|
pets.forEach(function (b) { out.push(b); });
|
|
if (own) out.push(own);
|
|
return out;
|
|
}
|
|
|
|
// ── colony (home) ──────────────────────────────────────────────────────────
|
|
function greet(newcomer) {
|
|
if (Date.now() - bornAt < SETTLE_MS) return;
|
|
setTimeout(function () {
|
|
all().forEach(function (b) {
|
|
if (b !== newcomer && isFree(b.pet)) b.pet.react("wave");
|
|
});
|
|
newcomer.pet.react("love");
|
|
}, 1600);
|
|
}
|
|
function goodbye() {
|
|
all().forEach(function (b) {
|
|
if (b.pet.state.mode === "ragdoll") return;
|
|
b.pet.wake();
|
|
b.pet.react("sad", { duration: 3 });
|
|
});
|
|
}
|
|
function playtime() {
|
|
var everyone = all();
|
|
if (everyone.length < 2) return;
|
|
var free = everyone.filter(function (b) { return isFree(b.pet); });
|
|
if (!free.length) return;
|
|
var visitor = own && free.indexOf(own) >= 0 && Math.random() < 0.6 ? own : free[Math.floor(Math.random() * free.length)];
|
|
var others = everyone.filter(function (b) { return b !== visitor; });
|
|
var friend = others[Math.floor(Math.random() * others.length)];
|
|
var v = visitor.pet.state;
|
|
var f = friend.pet.state;
|
|
function play() {
|
|
var a = visitor.pet.state;
|
|
var b = friend.pet.state;
|
|
if (Math.hypot(a.x - b.x, a.y - b.y) > TOGETHER_U * a.unit) return;
|
|
visitor.pet.react("love");
|
|
if (isFree(friend.pet)) friend.pet.react("love");
|
|
}
|
|
if (Math.hypot(v.x - f.x, v.y - f.y) < 1.5 * v.unit) play();
|
|
else {
|
|
var side = v.x < f.x ? -1 : 1;
|
|
visitor.pet.goNear(f.x + side * 0.9 * f.unit, f.y).then(function (ok) { if (ok) play(); });
|
|
}
|
|
}
|
|
|
|
/** A rail pet away from its card walks home, then drops back onto it. */
|
|
function homesick() {
|
|
pets.forEach(function (b, id) {
|
|
var a = layout.anchors[id];
|
|
var s = b.pet.state;
|
|
if (!a || s.mode === "ragdoll") return;
|
|
var home = Math.abs(s.y - a.y) < 6 && s.x >= a.x && s.x <= a.x + a.w;
|
|
if (home) {
|
|
b.away = 0;
|
|
return;
|
|
}
|
|
b.away += TICK_S;
|
|
// Its card is out of sight: nowhere to go back to yet.
|
|
if (a.y < 0 || a.y > layout.h) return;
|
|
if (b.away >= GIVE_UP_S) return b.respawn();
|
|
if (b.away >= HOMESICK_S && !b.walking) {
|
|
var el = anchorEl(id);
|
|
if (!el) return;
|
|
b.walking = true;
|
|
b.pet.goTo(el).finally(function () { b.walking = false; });
|
|
}
|
|
});
|
|
}
|
|
|
|
// ── touch boxes: where the host lets us take the pointer ───────────────────
|
|
var lastHits = "";
|
|
function reportHits() {
|
|
var u = prefs.size;
|
|
var boxes = [];
|
|
document.querySelectorAll("[data-pet-layer] canvas + div").forEach(function (el) {
|
|
var r = el.getBoundingClientRect();
|
|
if (r.width) boxes.push(M.hitBox(r, u * 0.15));
|
|
});
|
|
var key = JSON.stringify(boxes.map(function (b) { return [Math.round(b.x), Math.round(b.y)]; }));
|
|
if (key === lastHits) return;
|
|
lastHits = key;
|
|
ov.setHits(boxes);
|
|
}
|
|
|
|
// ── wiring ─────────────────────────────────────────────────────────────────
|
|
ov.on("prefs", function (p) {
|
|
var sizeChanged = p.size !== prefs.size;
|
|
prefs = { enabled: p.enabled !== false, size: Number(p.size) || 46, color: p.color || "#f4b66a" };
|
|
if (sizeChanged) all().forEach(function (b) { b.pet.set({ size: prefs.size }); });
|
|
sync();
|
|
});
|
|
ov.on("layout", function (l) {
|
|
applyLayout(l);
|
|
sync();
|
|
});
|
|
ov.on("members", function (list) {
|
|
members = Array.isArray(list) ? list : [];
|
|
sync();
|
|
});
|
|
ov.on("event", function (e) {
|
|
var b = pets.get(e.id);
|
|
if (!b) return;
|
|
if (e.type === "stamp") {
|
|
var c = M.stampCue(e.stamp, lang);
|
|
if (c) b.cue(c.reaction, c.say);
|
|
} else if (e.type === "message" && M.hopDue(b.lastHop, Date.now()) && !b.cueing && !b.pet.state.sleeping) {
|
|
b.lastHop = Date.now();
|
|
b.cue("surprised", undefined, 0.7);
|
|
}
|
|
});
|
|
setInterval(function () { all().forEach(function (b) { b.reassert(); }); }, 5000);
|
|
setInterval(reportHits, 120);
|
|
if (where === "home") {
|
|
setInterval(playtime, PLAY_EVERY_MS);
|
|
setInterval(homesick, TICK_S * 1000);
|
|
}
|
|
})();
|
|
|
|
</script>
|
|
</body></html>
|