busybits 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/build.json +2 -2
- package/dist/cli/busybits.js +45 -0
- package/dist/client/bundle/app-9Vl0ffKz.js +24 -0
- package/dist/client/bundle/{app-Cn3BvqjA.css → app-BvE-Y-Qm.css} +1 -1
- package/dist/client/bundle/{city-DKO2ZZPJ.js → city-D7fv4nex.js} +1 -1
- package/dist/client/bundle/{daystats-CqDMjh5a.js → daystats-CIfvcFQr.js} +1 -1
- package/dist/client/bundle/{dom-BnYE5zIh.js → dom-DTQ3fgr0.js} +1 -1
- package/dist/client/bundle/{en-BD-d_FWo.js → en-ChmFNZf9.js} +2 -2
- package/dist/client/bundle/{es-ZgMlZ_LY.js → es-Dxz3P98Y.js} +2 -2
- package/dist/client/bundle/{format-CnTSBxgP.js → format-Cq9YWBaH.js} +1 -1
- package/dist/client/bundle/{fr-DOSCFvER.js → fr-CINcBINu.js} +2 -2
- package/dist/client/bundle/{main-7JfOGPBD.js → main-CIX7XLHO.js} +2 -2
- package/dist/client/bundle/{ptypane-DBg26wgg.js → ptypane-BV4OJmMy.js} +1 -1
- package/dist/client/bundle/{room-name-Cb8-ffEK.js → room-name-DwJoEQRB.js} +1 -1
- package/dist/client/bundle/{simulator-DeHOlOye.js → simulator-mIkQohaY.js} +1 -1
- package/dist/client/bundle/world-model-BCuCi4WK.js +1 -0
- package/dist/client/bundle/world-stream-BJwcKXw_.js +1 -0
- package/dist/client/index.html +1 -1
- package/dist/server/index.js +113 -32
- package/mod/habblaud/.claude-plugin/plugin.json +1 -1
- package/mod/habblaud-mensagens/.claude-plugin/plugin.json +1 -1
- package/mod/habblaud-permissoes/.claude-plugin/plugin.json +1 -1
- package/mod/habblaud-pi/package.json +1 -1
- package/package.json +2 -1
- package/dist/client/bundle/app-B_jk_lPZ.js +0 -24
- package/dist/client/bundle/world-model-C3GVcyT7.js +0 -1
- package/dist/client/bundle/world-stream-DZkepWt9.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,s as t}from"./main-7JfOGPBD.js";import{c as n,l as r}from"./simulator-DeHOlOye.js";import{$ as i,Dt as a,K as o,Mt as s,Nt as c,Q as l,Tt as u,V as d,W as f,X as p,Xt as m,Z as h,Zt as g,ct as _,dt as v,et as y,ft as b,ht as x,it as S,kt as C,lt as w,nt as T,ot as E,pt as ee,q as D,rt as O,st as k,tt as A,ut as te,wt as j}from"./world-model-C3GVcyT7.js";import{l as M,r as N,s as P}from"./dom-BnYE5zIh.js";import{A as F,B as I,C as L,D as R,E as ne,F as re,G as ie,H as ae,I as oe,J as se,K as ce,L as le,M as ue,N as de,O as fe,P as pe,R as me,S as he,T as ge,U as _e,V as z,W as ve,Y as ye,a as be,b as xe,c as Se,d as Ce,i as we,j as Te,k as Ee,l as De,n as Oe,o as ke,q as Ae,r as je,s as Me,u as Ne,v as Pe,w as Fe,x as Ie,y as Le,z as Re}from"./app-B_jk_lPZ.js";function ze(e){if(!e||!/^[A-Za-z]{2}$/.test(e))return``;let t=e.toUpperCase();return String.fromCodePoint(127462+t.charCodeAt(0)-65,127462+t.charCodeAt(1)-65)}function Be(t){if(!t||!/^[A-Za-z]{2}$/.test(t))return``;try{return new Intl.DisplayNames([e()],{type:`region`}).of(t.toUpperCase())??t.toUpperCase()}catch{return t.toUpperCase()}}function Ve(t){let n=/^(\d{4})-(\d{2})$/.exec(t??``);if(!n)return``;let r=Number(n[1]),i=Number(n[2]);if(i<1||i>12)return``;try{return new Intl.DateTimeFormat(e(),{month:`long`,year:`numeric`}).format(new Date(r,i-1,1))}catch{return`${n[2]}/${n[1]}`}}function He(e){let n=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;return n===0?t(`só o térreo`):n>24?t(`{0} andares`,[`24+`]):n===1?t(`1 andar`):t(`{0} andares`,[n])}function Ue(n){let r=Number.isFinite(n)?Math.max(0,Math.floor(n)):0;return r===1?t(`1 curtida`):t(`{0} curtidas`,[r.toLocaleString(e())])}function We(e,n=null){let r=e.state===`online`;return{owner:e.owner.name,flag:ze(e.owner.country),country:Be(e.owner.country),online:r,state:t(r?`Luzes acesas`:`Luzes apagadas`),floors:He(e.floors),agents:e.agents?{working:e.agents.working,waiting:e.agents.waiting,idle:e.agents.idle}:null,likes:Ue(e.likes),since:Ve(e.sinceMonth),closed:e.closed===!0,mine:!!n&&e.id===n}}function Ge(e,t){return{name:e.name,flag:ze(e.country),country:Be(e.country),traits:(e.traits??[]).filter(u).map(e=>({emoji:j[e].emoji,label:j[e].label,desc:j[e].desc})),intro:e.intro?f(e.intro):``,likes:Ue(e.likesReceived),building:t?{id:t.id,floors:He(t.floors),online:t.state===`online`}:null,hasBuilding:!!e.buildingId}}var Ke=class{actions;el;title;flag;sub;body;avatar;closeBtn;kind=null;id=null;pinned=!1;sig=``;constructor(e){this.actions=e,this.avatar=N(`span`,{class:`ui-city-card__avatar`,hidden:!0,attrs:{"aria-hidden":`true`}}),this.flag=N(`span`,{class:`ui-city-card__flag`,attrs:{"aria-hidden":`true`}}),this.title=N(`strong`,{class:`ui-city-card__title`}),this.sub=N(`div`,{class:`ui-city-card__sub`}),this.body=N(`div`,{class:`ui-city-card__body`}),this.closeBtn=N(`button`,{class:`ui-city-card__close`,type:`button`,title:t(`Fechar`),attrs:{"aria-label":t(`Fechar`)},text:`×`,on:{click:()=>this.hide()}}),this.el=N(`section`,{class:`ui-city-card`,hidden:!0,role:`dialog`,attrs:{"aria-live":`polite`,"aria-label":t(`Cartão`)}},N(`div`,{class:`ui-city-card__head`},this.avatar,N(`div`,{class:`ui-city-card__names`},N(`div`,{class:`ui-city-card__line`},this.flag,this.title),this.sub),this.closeBtn),this.body)}get open(){return this.kind!==null}hide(){this.kind=null,this.id=null,this.pinned=!1,this.sig=``,this.el.hidden=!0}showBuilding(e,n,r,i){let a=We(e,n),o=`b|${e.id}|${JSON.stringify(a)}`;if(this.kind=`building`,this.id=e.id,this.pinned=i||this.pinned&&this.id===e.id,this.el.classList.toggle(`is-pinned`,this.pinned),o!==this.sig){this.sig=o,P(this.avatar,!0),M(this.flag,a.flag),this.flag.title=a.country,M(this.title,a.owner),M(this.sub,[a.mine?t(`Seu prédio`):``,a.country].filter(Boolean).join(` · `)),this.el.classList.toggle(`is-online`,a.online);let n=[];n.push(N(`div`,{class:`ui-city-card__row`},N(`span`,{class:`ui-city-card__dot ${a.online?`is-on`:`is-off`}`}),N(`span`,{text:a.state}),N(`span`,{class:`ui-city-card__sep`,text:`·`}),N(`span`,{text:a.floors}))),a.agents?n.push(N(`div`,{class:`ui-city-card__agents`},N(`span`,{class:`ui-city-card__agent is-working`,title:t(`Agentes trabalhando`)},N(`b`,{text:String(a.agents.working)}),` ${t(`trabalhando`)}`),N(`span`,{class:`ui-city-card__agent is-waiting`,title:t(`Agentes esperando o dono`)},N(`b`,{text:String(a.agents.waiting)}),` ${t(`esperando`)}`),N(`span`,{class:`ui-city-card__agent is-idle`,title:t(`Agentes à toa`)},N(`b`,{text:String(a.agents.idle)}),` ${t(`à toa`)}`))):n.push(N(`div`,{class:`ui-city-card__muted`,text:t(`Modo discreto: o dono não mostra os agentes.`)})),a.closed&&n.push(N(`div`,{class:`ui-city-card__muted`,text:`🔒 ${t(`Fechado a visitas`)}`})),n.push(N(`div`,{class:`ui-city-card__row ui-city-card__foot`},N(`span`,{text:`❤️ ${a.likes}`}),a.since?N(`span`,{class:`ui-city-card__since`,text:t(`No mundo desde {0}`,[a.since])}):null));let r=this.actions.enter;if(a.mine&&r){let i=e.id;n.push(N(`button`,{class:`ui-city-card__link`,type:`button`,text:`👁 ${t(`Ver como os outros veem`)}`,on:{click:()=>r(i)}}))}let i=this.actions.extras?.(`building`,e.id);i&&n.push(i),this.body.replaceChildren(...n)}this.place(r),this.el.hidden=!1}showPlayer(e,r,i){let a=Ge(e,r),o=`p|${e.id}|${JSON.stringify(a)}|${JSON.stringify(e.parts)}`;if(this.kind=`player`,this.id=e.id,this.pinned=!0,this.el.classList.add(`is-pinned`),this.el.classList.remove(`is-online`),o!==this.sig){this.sig=o,P(this.avatar,!1);try{let t=ye(n(e.id),{look:e.look,parts:e.parts,scale:2});t.className=`ui-city-card__avatar-img`,this.avatar.replaceChildren(t)}catch{this.avatar.replaceChildren()}M(this.flag,a.flag),this.flag.title=a.country,M(this.title,a.name),M(this.sub,a.country);let r=[];a.intro&&r.push(N(`div`,{class:`ui-city-card__intro`,text:`“${a.intro}”`})),a.traits.length&&r.push(N(`div`,{class:`ui-city-card__traits`},...a.traits.map(e=>N(`span`,{class:`ui-trait`,title:e.desc,text:`${e.emoji} ${e.label}`}))));let i=N(`div`,{class:`ui-city-card__row ui-city-card__foot`},N(`span`,{text:`❤️ ${t(`{0} recebidas`,[a.likes])}`}));if(a.building){let e=a.building;i.append(N(`button`,{class:`ui-city-card__link`,type:`button`,text:`🏢 ${t(`Ver o prédio`)} (${e.floors})`,on:{click:()=>this.actions.showBuilding(e.id)}}))}else i.append(N(`span`,{class:`ui-city-card__muted`,text:a.hasBuilding?t(`Prédio longe daqui`):t(`Ainda sem prédio`)}));r.push(i);let s=this.actions.extras?.(`player`,e.id);s&&r.push(s),this.body.replaceChildren(...r)}i&&this.place(i),this.el.hidden=!1}place(e){let t=window.innerWidth,n=window.innerHeight,r=this.el.offsetWidth||260,i=this.el.offsetHeight||140;if(t<=520){this.el.style.transform=``,this.el.classList.add(`is-docked`);return}this.el.classList.remove(`is-docked`);let a=this.actions.topInset()+8,o=e.x+16,s=e.y-i-12;o+r>t-8&&(o=e.x-r-16),s<a&&(s=e.y+18),o=Math.max(8,Math.min(t-r-8,o)),s=Math.max(a,Math.min(n-i-8,s)),this.el.style.transform=`translate(${Math.round(o)}px, ${Math.round(s)}px)`}},qe=6,Je={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],w:[0,-1],s:[0,1],a:[-1,0],d:[1,0]};function Ye(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``)||t.getAttribute?.(`role`)===`radio`)}function Xe(e,t){let n=0,r=0;for(let t of e){let e=Je[t];e&&(n+=e[0],r+=e[1])}return{dx:Math.sign(n),dy:Math.sign(r),run:t}}function Ze(e){if(Je[e.key])return e.key;let t=e.key.length===1?e.key.toLowerCase():e.key;return Je[t]?t:e.code===`KeyW`?`w`:e.code===`KeyA`?`a`:e.code===`KeyS`?`s`:e.code===`KeyD`?`d`:null}var Qe=class{canvas;camera;h;keys=new Set;shift=!1;pointers=new Map;downX=0;downY=0;dragging=!1;pinch=null;wheelAcc=0;wheelSettle=null;off=[];constructor(e,t,n){this.canvas=e,this.camera=t,this.h=n,e.style.touchAction=`none`;let r=(e,t,n,r)=>{e.addEventListener(t,n,r),this.off.push(()=>e.removeEventListener(t,n,r))};r(e,`pointerdown`,e=>this.onDown(e)),r(e,`pointermove`,e=>this.onMove(e)),r(e,`pointerup`,e=>this.onUp(e)),r(e,`pointercancel`,e=>this.onCancel(e)),r(e,`pointerleave`,()=>this.h.hover(0,0,!1)),r(e,`wheel`,e=>this.onWheel(e),{passive:!1}),r(window,`keydown`,e=>this.onKey(e,!0)),r(window,`keyup`,e=>this.onKey(e,!1)),r(window,`blur`,()=>this.clearKeys()),r(document,`visibilitychange`,()=>this.clearKeys())}intent(){return Xe(this.keys,this.shift)}clearKeys(){this.keys.clear(),this.shift=!1}destroy(){for(let e of this.off.splice(0))e();this.wheelSettle&&clearTimeout(this.wheelSettle),this.clearKeys()}local(e){let t=this.canvas.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}onKey(e,t){if(e.key===`Shift`?this.shift=t:typeof e.getModifierState==`function`&&(this.shift=e.getModifierState(`Shift`)),!t){let t=Ze(e);t&&this.keys.delete(t);return}if(!this.h.active()||e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||Ye(e.target)||ce(e.target))return;let n=Ze(e);if(n){e.preventDefault(),this.keys.add(n),this.h.moved();return}switch(e.key){case`e`:case`E`:case`Enter`:if(e.key===`Enter`&&e.target?.closest?.(`button, a`))return;e.preventDefault(),this.h.use();return;case`+`:case`=`:e.preventDefault(),this.h.zoomStep(1);return;case`-`:case`_`:e.preventDefault(),this.h.zoomStep(-1);return;case`0`:e.preventDefault(),this.h.recenter();return}}onDown(e){if(e.button!==0&&e.pointerType===`mouse`)return;let t=this.local(e);this.pointers.set(e.pointerId,t);try{this.canvas.setPointerCapture(e.pointerId)}catch{}if(this.pointers.size===1)this.downX=t.x,this.downY=t.y,this.dragging=!1;else if(this.pointers.size===2){let[e,t]=[...this.pointers.values()];this.pinch={dist:Math.hypot(e.x-t.x,e.y-t.y)||1,zoom:this.camera.zoom,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2},this.dragging=!0,this.h.interact()}}onMove(e){let t=this.local(e),n=this.pointers.get(e.pointerId);if(!n){e.pointerType===`mouse`&&this.h.hover(t.x,t.y,!0);return}if(this.pointers.set(e.pointerId,t),this.pinch&&this.pointers.size>=2){let[e,t]=[...this.pointers.values()],n=Math.hypot(e.x-t.x,e.y-t.y)||1,r=(e.x+t.x)/2,i=(e.y+t.y)/2;this.camera.panBy(r-this.pinch.cx,i-this.pinch.cy),this.camera.zoomAt(this.pinch.zoom*(n/this.pinch.dist),r,i,Date.now(),!1),this.pinch.cx=r,this.pinch.cy=i;return}!this.dragging&&Math.hypot(t.x-this.downX,t.y-this.downY)>qe&&(this.dragging=!0,this.canvas.style.cursor=`grabbing`,this.h.interact()),this.dragging&&this.camera.panBy(t.x-n.x,t.y-n.y)}onUp(e){let t=this.local(e);if(this.pointers.delete(e.pointerId)){if(this.pinch&&this.pointers.size<2){this.pinch=null,this.camera.settle(Date.now());return}if(!(this.pointers.size>0)){if(this.canvas.style.cursor=``,this.dragging){this.dragging=!1;return}this.h.click(t.x,t.y,{shift:e.shiftKey})}}}onCancel(e){this.pointers.delete(e.pointerId),this.pointers.size<2&&(this.pinch=null),this.pointers.size||(this.dragging=!1)}onWheel(e){e.preventDefault();let t=this.local(e),n=e.deltaMode===1?e.deltaY*33:e.deltaMode===2?e.deltaY*400:e.deltaY;if(e.ctrlKey){this.camera.zoomAt(this.camera.zoom*Math.exp(-n*.012),t.x,t.y,Date.now(),!1),this.wheelSettle&&clearTimeout(this.wheelSettle),this.wheelSettle=setTimeout(()=>this.camera.settle(Date.now()),180);return}this.wheelAcc+=n,Math.abs(this.wheelAcc)>=50&&(this.h.zoomStep(this.wheelAcc<0?1:-1,t.x,t.y),this.wheelAcc=0)}},$e={x:-2,y:-2,w:h.x,h:h.y};A.w-2;var B=e=>`${e.x},${e.y}`;function et(e){return n(`quarteirao:${e.x},${e.y}`)}function tt(e){return n(`lote:${e.x},${e.y}`)}function nt(e){return e.y-p.h*Math.floor(e.y/p.h)===0}function rt(e){if(te(e))return[];let t=[];for(let n=0;n<p.h;n++)for(let r=0;r<p.w;r++)t.push({x:e.x*p.w+r,y:e.y*p.h+n});return t}function it(e){let t=E(e);return{x:(t.x+$e.x)*16,y:(t.y+$e.y)*16,w:$e.w*16,h:$e.h*16}}function at(e,t=64){let n=h.x*16,r=h.y*16,i=$e.x*16,a=$e.y*16;return{bx0:Math.floor((e.x0-t-i)/n),by0:Math.floor((e.y0-t-a)/r),bx1:Math.floor((e.x1+t-i)/n),by1:Math.floor((e.y1+t-a)/r)}}function ot(){let e=l.w,t=l.h,n=e+4,r=t+4,i=[];for(let e=0;e<p.h;e++)for(let t=0;t<p.w;t++)i.push({x:2+t*A.w,y:2+e*A.h,w:A.w,h:A.h});let a=5/2;return{sidewalkOuter:{x:0,y:0,w:n,h:r},block:{x:2,y:2,w:e,h:t},streets:[{x:n,y:0,w:5,h:r},{x:0,y:r,w:n,h:5}],intersection:{x:n,y:r,w:5,h:5},crosswalks:[{rect:{x:0,y:r,w:2,h:5},across:`ns`},{rect:{x:n-2,y:r,w:2,h:5},across:`ns`},{rect:{x:n,y:0,w:5,h:2},across:`we`},{rect:{x:n,y:r-2,w:5,h:2},across:`we`}],laneMarks:[[3,r+a,n-2-1,r+a],[n+a,3,n+a,r-2-1]],lots:i}}var st=()=>!0;function ct(e){let t=Math.floor(e.x),n=Math.floor(e.y),r=Math.max(1,Math.ceil(e.w)),i=Math.max(1,Math.ceil(e.h)),a=new Ee(r,i);for(let e=0;e<i;e++)for(let i=0;i<r;i++)a.cells[e*r+i]=+!!v(t+i+.5,n+e+.5,st);return{grid:a,ox:t,oy:n}}function lt(e,t,n=Math.max(h.x,h.y)){let r=Math.floor(Math.min(e.x,t.x))-n,i=Math.floor(Math.min(e.y,t.y))-n,a=Math.ceil(Math.max(e.x,t.x))+n,o=Math.ceil(Math.max(e.y,t.y))+n;return{x:r,y:i,w:a-r,h:o-i}}function ut(e,t,n=16){let r=Math.floor(e),i=Math.floor(t);if(v(r+.5,i+.5,st))return{x:r,y:i};for(let a=1;a<=n;a++){let n=null,o=1/0;for(let s=-a;s<=a;s++)for(let c=-a;c<=a;c++){if(Math.max(Math.abs(c),Math.abs(s))!==a||!v(r+c+.5,i+s+.5,st))continue;let l=(r+c+.5-e)**2+(i+s+.5-t)**2;l<o&&(o=l,n={x:r+c,y:i+s})}if(n)return n}return null}function dt(e,t){return v(e,t,st)}function ft(e,t,n,r=1.6){let{x:i,y:a}=S(e,t),o=null,s=r*r;for(let r=a-1;r<=a+1;r++)for(let a=i-1;a<=i+1;a++)for(let i of rt({x:a,y:r})){let r=b(i),a=(r.front.x-e)**2+(r.front.y-t)**2;a<=s&&n(i)&&(s=a,o={lot:i,side:r.side,front:r.front})}return o}var pt=3;function mt(e){let t=E(e),n=et(e),a=r(n),o=[],s=e=>e*16,c=n&1,u=[0,1,2].map(e=>t.x+e*A.w+i.dx+i.w/2),d=e=>u.some(t=>Math.abs(e-t)<pt);for(let e of[`n`,`s`]){let r=e===`n`?t.y-2:t.y+l.h+2-1;if([0,A.w,2*A.w,3*A.w].forEach((i,l)=>{let u=t.x+i;d(u)||((l+c+ +(e===`s`))%2==0?o.push({kind:`lamp`,x:s(u)+(i===0?6:i===3*A.w?-6:0),y:s(r)+10,seed:n+l}):o.push({kind:a()<.22?`pine`:`tree`,x:s(u),y:s(r)+12,seed:Math.floor(a()*1e9)}))}),a()<.7){let e=Math.floor(a()*3),i=t.x+e*A.w+(a()<.5?2:A.w-3);if(!d(i+1)){let e=r;o.push({kind:`bench`,x:s(i+1),y:s(e)+13,seed:n+7,seat:{x:i+1,y:e+.85,dir:`down`}})}}}for(let e of[`w`,`e`]){let r=e===`w`?t.x-2:t.x+l.w+2-1;[3,Math.floor(l.h/2),l.h-3].forEach((e,i)=>{let c=t.y+e,l=s(r)+8;i===1?o.push({kind:`lamp`,x:l,y:s(c)+10,seed:n+20+i}):a()<.85?o.push({kind:a()<.25?`pine`:`tree`,x:l,y:s(c)+12,seed:Math.floor(a()*1e9)}):o.push({kind:`bush`,x:l,y:s(c)+12,seed:Math.floor(a()*1e9),small:!0})})}return o}var ht=[`park`,`pond`,`orchard`,`cafe`];function gt(e){return ht[tt(e)%ht.length]}function _t(e,t){let n=ee(e),a=tt(e),o=r(a^1540483477),s=[],c=e=>(n.x+e)*16,l=e=>(n.y+e)*16,u=()=>Math.floor(o()*1e9),d=nt(e);if(t){let e=d?l(A.h)-2:l(0)+12;for(let t=1;t<A.w-1;t+=2)s.push({kind:`hedge`,x:c(t)+16,y:e,seed:a+t,small:!0});let t=l(d?A.h-1.4:1.6);return o()<.8&&s.push({kind:o()<.3?`pine`:`tree`,x:c(1.2),y:t,seed:u()}),o()<.8&&s.push({kind:o()<.3?`pine`:`tree`,x:c(A.w-1.2),y:t,seed:u()}),s}let f=gt(e),p=d?l(0)+13:l(A.h)-2;for(let e=0;e<A.w;e+=2)e>=i.dx-1&&e<=i.dx+1||s.push({kind:e/2%3==1?`flowers`:`hedge`,x:c(e)+16,y:p,seed:a+e*3,small:!0});let m=A.w/2,h=A.h/2;switch(f){case`park`:s.push({kind:`tree`,x:c(2.5),y:l(d?4.5:3.5),seed:u()}),s.push({kind:o()<.5?`pine`:`tree`,x:c(11.5),y:l(d?3.8:4.2),seed:u()}),s.push({kind:`tree`,x:c(10.5),y:l(d?9.5:8.8),seed:u()}),s.push({kind:`bush`,x:c(3.5),y:l(d?9.2:8.4),seed:u(),small:!0}),s.push({kind:`flowers`,x:c(m),y:l(h+.6),seed:u(),small:!0}),s.push({kind:`bench`,x:c(m),y:l(h-1.2),seed:u(),seat:{x:n.x+m,y:n.y+h-1.35,dir:`down`}});break;case`pond`:s.push({kind:`rock`,x:c(3.2),y:l(h+2.2),seed:u(),small:!0}),s.push({kind:`rock`,x:c(10.4),y:l(h-1.8),seed:u(),small:!0}),s.push({kind:`tree`,x:c(1.8),y:l(d?10.6:3.2),seed:u()}),s.push({kind:`pine`,x:c(12.2),y:l(d?10.2:3.6),seed:u()}),s.push({kind:`bush`,x:c(4.6),y:l(h-2.6),seed:u(),small:!0}),s.push({kind:`bush`,x:c(9.5),y:l(h+2.8),seed:u(),small:!0});break;case`orchard`:for(let e=0;e<2;e++)for(let t=0;t<4;t++)s.push({kind:`tree`,x:c(2.2+t*3.2),y:l((d?4.6:3.6)+e*4.4),seed:u()});break;case`cafe`:s.push({kind:`parasol`,x:c(4),y:l(h+.5),seed:u()}),s.push({kind:`parasol`,x:c(10),y:l(h+.5),seed:u()}),s.push({kind:`planter`,x:c(m),y:l(h-2.5),seed:u(),small:!0}),s.push({kind:`tree`,x:c(1.6),y:l(d?10.4:2.6),seed:u()}),s.push({kind:`tree`,x:c(12.4),y:l(d?10.4:2.6),seed:u()})}return s}function vt(){let e=E({x:0,y:0}),t=t=>(e.x+t)*16,n=t=>(e.y+t)*16,r=[],i=y;r.push({kind:`fountain`,x:t(i.x+i.w/2),y:n(i.y+i.h),seed:1});for(let a of[-5,5])r.push({kind:`bench`,x:t(i.x+i.w/2+a),y:n(i.y-1)+13,seed:3+a,seat:{x:e.x+i.x+i.w/2+a,y:e.y+i.y-1+.85,dir:`down`}}),r.push({kind:`bench`,x:t(i.x+i.w/2+a),y:n(i.y+i.h+2)+13,seed:4+a,seat:{x:e.x+i.x+i.w/2+a,y:e.y+i.y+i.h+2+.85,dir:`down`}});[[6,5],[l.w-6,5],[6,l.h-4],[l.w-6,l.h-4]].forEach(([e,i],a)=>{r.push({kind:a%2?`pine`:`tree`,x:t(e-1.5),y:n(i),seed:100+a*7}),r.push({kind:`tree`,x:t(e+1.5),y:n(i+.4),seed:200+a*11}),r.push({kind:`flowers`,x:t(e),y:n(i+1.6),seed:300+a,small:!0}),r.push({kind:`bush`,x:t(e-3),y:n(i+1.4),seed:400+a,small:!0}),r.push({kind:`bush`,x:t(e+3),y:n(i+1.2),seed:500+a,small:!0})});for(let[e,i]of[[12,4],[l.w-12,4],[12,l.h-5],[l.w-12,l.h-5]])r.push({kind:`lamp`,x:t(e)+8,y:n(i)+10,seed:e*3+i});return r.push({kind:`totem`,x:t(O.x-3)+8,y:n(O.y)+4,seed:2}),r.push({kind:`planter`,x:t(O.x+3)+8,y:n(O.y)+6,seed:9,small:!0}),r}function yt(e){let t=mt(e);return te(e)&&t.push(...vt()),t}var bt=p.w*p.h;function xt(e){return e>0?Math.min(1,.35+.65*Math.min(e,bt)/bt):0}function St(e,t,n,r,i=4){let a=S(t.x,t.y),o=(2*i+1)*h.x,s=(2*i+1)*h.y,c=Math.min(r.w/o,r.h/s),u=a.x*h.x+l.w/2,d=a.y*h.y+l.h/2,f=e=>r.w/2+(e-u)*c,p=e=>r.h/2+(e-d)*c,m=new Map;for(let t of e)m.set(`${t.x},${t.y}`,t.lit);let g=[];for(let e=a.y-i-1;e<=a.y+i+1;e++)for(let t=a.x-i-1;t<=a.x+i+1;t++){let n=f(t*h.x),i=p(e*h.y),a=l.w*c,o=l.h*c;if(n+a<0||i+o<0||n>r.w||i>r.h)continue;let s=`${t},${e}`,u=m.get(s);g.push({bx:t,by:e,x:n,y:i,w:a,h:o,light:xt(u??0),occupied:u!==void 0,plaza:t===T.x&&e===T.y})}return{cells:g,me:{x:f(t.x),y:p(t.y)},view:{x:f(n.x),y:p(n.y),w:n.w*c,h:n.h*c},k:c,cx:u,cy:d}}function Ct(e,t,n,r){return{x:e.cx+(n-t.w/2)/e.k,y:e.cy+(r-t.h/2)/e.k}}var wt=class{el;canvas;ctx;model=null;size={w:176,h:116};sig=``;constructor(e){this.canvas=N(`canvas`,{class:`ui-city-minimap__canvas`,attrs:{"aria-hidden":`true`}}),this.ctx=this.canvas.getContext(`2d`),this.el=N(`nav`,{class:`ui-city-minimap`,attrs:{"aria-label":t(`Minimapa: clique para levar a câmera até lá`)},title:t(`Minimapa: clique para levar a câmera até lá`)},this.canvas),this.canvas.addEventListener(`pointerdown`,t=>{if(t.preventDefault(),t.stopPropagation(),!this.model)return;let n=this.canvas.getBoundingClientRect();e(Ct(this.model,this.size,t.clientX-n.left,t.clientY-n.top))})}draw(e,t,n,r){let i=this.canvas.clientWidth||this.size.w,a=this.canvas.clientHeight||this.size.h,o=Math.max(1,Math.min(3,window.devicePixelRatio||1)),s=`${t}|${Math.round(n.x*2)}|${Math.round(n.y*2)}|${Math.round(r.x)}|${Math.round(r.y)}|${Math.round(r.w)}|${i}|${a}|${o}`;if(s===this.sig)return;this.sig=s,this.size={w:i,h:a},(this.canvas.width!==Math.round(i*o)||this.canvas.height!==Math.round(a*o))&&(this.canvas.width=Math.round(i*o),this.canvas.height=Math.round(a*o));let c=this.model=St(e,n,r,this.size),l=this.ctx;l.setTransform(o,0,0,o,0,0),l.clearRect(0,0,i,a),l.fillStyle=`#2a2f3a`,l.fillRect(0,0,i,a);for(let e of c.cells){let t=Math.round(e.x),n=Math.round(e.y),r=Math.max(2,Math.round(e.w)),i=Math.max(2,Math.round(e.h));l.fillStyle=e.plaza?`#b9b2a4`:e.light>0?`rgba(255,206,110,${(.25+e.light*.75).toFixed(3)})`:e.occupied?`#55607a`:`#3a5a45`,l.fillRect(t,n,r,i),e.light>0&&(l.fillStyle=`rgba(255,240,200,${(e.light*.5).toFixed(3)})`,l.fillRect(t+1,n+1,Math.max(1,r-2),1)),e.plaza&&(l.fillStyle=`#5ea8d6`,l.fillRect(Math.round(t+r/2-1),Math.round(n+i/2-1),2,2))}l.strokeStyle=`rgba(232,236,245,0.75)`,l.lineWidth=1,l.strokeRect(Math.round(c.view.x)+.5,Math.round(c.view.y)+.5,Math.max(2,Math.round(c.view.w)),Math.max(2,Math.round(c.view.h))),l.fillStyle=`#12151d`,l.fillRect(Math.round(c.me.x)-3,Math.round(c.me.y)-3,6,6),l.fillStyle=`#7cc8ff`,l.fillRect(Math.round(c.me.x)-2,Math.round(c.me.y)-2,4,4)}};function Tt(e,n=`street`){switch(e){case`ignored`:case`invalid`:case`view_required`:return null;case`rate_limited`:return t(`Devagar: o mundo pediu um tempo entre as ações.`);case`not_found`:return t(n===`door`?`Este prédio não está no mundo agora.`:n===`inside`?`O prédio saiu do mundo: você voltou para a rua.`:`Essa pessoa não está mais por perto.`);case`street_left`:return t(`Você ficou um bom tempo parado e saiu da rua: ande para voltar.`);case`chunk_full`:return t(`A área está cheia: só os jogadores mais perto aparecem.`);case`afk`:return t(`Você ficou um tempo parado.`);case`server_restart`:return t(`O Habblaud World vai reiniciar: a conexão cai e volta sozinha.`);case`left`:return t(`Sua conta saiu do mundo: o prédio volta com "Voltar ao mundo", em Configurações.`);case`too_far`:return t(`Chegue mais perto da porta para entrar.`);case`closed`:return t(n===`inside`?`O prédio fechou a visitas: você voltou para a rua.`:`Este prédio está fechado a visitas.`);case`blocked`:return t(n===`inside`?`Você não pode mais ficar neste prédio: voltou para a rua.`:`Você não pode entrar neste prédio.`);case`full`:return t(`O prédio está lotado (20 visitantes). Tente daqui a pouco.`);case`daily_limit`:return t(`Limite do dia atingido: amanhã tem mais.`);case`already_done`:return t(`Você já fez isso hoje.`);case`reported`:return t(`Denúncia enviada. Obrigado: a moderação vai olhar.`);case`blocked_ok`:return t(`Bloqueio feito: vocês deixam de se ver.`);case`stamped`:return t(`Carimbo deixado na portaria.`);default:return t(`Aviso do Habblaud World.`)}}var Et=5e3,V=C;function Dt(e,t){let n=[];for(let r=0;r<e;r++){let i=-Math.PI/2+r/Math.max(1,e)*Math.PI*2;n.push({x:Math.round(Math.cos(i)*t),y:Math.round(Math.sin(i)*t),angle:i})}return n}function Ot(e){return e===9?`0`:String(e+1)}function kt(e){if(!/^[0-9]$/.test(e))return-1;let t=e===`0`?9:Number(e)-1;return t<V.length?t:-1}function At(e,t,n={}){let r=n.range??12,i=null,a=r*r,o=new Set;for(let n of t){o.add(n.id);let t=(n.x-e.x)**2+(n.y-e.y)**2;t<=a&&(a=t,i=n.id)}return n.replyTo&&o.has(n.replyTo)?n.replyTo:n.selected&&o.has(n.selected)?n.selected:i}var jt=class{map=new Map;add(e,t,n){this.map.set(e,{id:t,at:n})}get(e,t){let n=this.map.get(e);if(!n)return null;let r=t-n.at;return r>=5e3||r<0?(this.map.delete(e),null):{id:n.id,t:r/Et,age:r}}get size(){return this.map.size}ids(){return[...this.map.keys()]}clear(){this.map.clear()}},Mt=class{perMinute;gapMs;times=[];constructor(e,t=0){this.perMinute=e,this.gapMs=t}wait(e){for(;this.times.length&&e-this.times[0]>=6e4;)this.times.shift();let t=this.times[this.times.length-1],n=t===void 0?0:Math.max(0,t+this.gapMs-e);return this.times.length>=this.perMinute&&(n=Math.max(n,this.times[0]+6e4-e)),n}take(e){return this.wait(e)>0?!1:(this.times.push(e),!0)}};function Nt(e){switch(e){case`hello`:case`wave`:return`nice_to_meet`;case`nice_building`:case`congrats`:case`clap`:case`good_luck`:return`thanks`;case`coffee`:return`coffee`;case`bye`:return`bye`;case`thanks`:return`clap`;case`nice_to_meet`:return`wave`}}var Pt=class{el;ring;center;to;hint;arrow;buttons=[];target=null;focused=0;pick=null;constructor(){this.to=N(`strong`,{class:`ui-city-wheel__to`}),this.hint=N(`span`,{class:`ui-city-wheel__hint`}),this.arrow=N(`span`,{class:`ui-city-wheel__arrow`,attrs:{"aria-hidden":`true`}}),this.center=N(`div`,{class:`ui-city-wheel__center`},N(`span`,{class:`ui-city-wheel__label`,text:t(`Cumprimentar`)}),this.to,this.hint),this.ring=N(`div`,{class:`ui-city-wheel__ring`,role:`menu`,attrs:{"aria-label":t(`Cumprimentos`)}});let e=Dt(V.length,96);V.forEach((t,n)=>{let r=e[n],i=N(`button`,{class:`ui-city-wheel__item`,type:`button`,role:`menuitem`,style:`--x:${r.x}px;--y:${r.y}px;--i:${n}`,attrs:{"aria-label":`${Me(t)} (${Ot(n)})`,"data-greeting":t},on:{click:()=>this.choose(n),pointerenter:()=>this.focus(n,!1),focus:()=>this.focus(n,!1)}},N(`span`,{class:`ui-city-wheel__emoji`,text:ke(t),attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-wheel__key`,text:Ot(n),attrs:{"aria-hidden":`true`}}));this.buttons.push(i),this.ring.append(i)}),this.el=N(`div`,{class:`ui-city-wheel`,hidden:!0},this.arrow,this.ring,this.center),this.el.addEventListener(`pointerdown`,e=>{e.target===this.el&&this.close()})}get open(){return!this.el.hidden}get targetId(){return this.target?.id??null}show(e,t,n,r,i){this.target=e,this.pick=i,M(this.to,e.name);let a=window.innerWidth,o=window.innerHeight,s=Math.max(132,Math.min(a-132,t.x)),c=Math.max(172,Math.min(o-132,t.y));if(this.el.style.setProperty(`--cx`,`${Math.round(s)}px`),this.el.style.setProperty(`--cy`,`${Math.round(c)}px`),n){let e=Math.atan2(n.y-c,n.x-s);this.arrow.style.setProperty(`--a`,`${e}rad`),this.arrow.hidden=Math.hypot(n.x-s,n.y-c)<30}else this.arrow.hidden=!0;this.el.hidden=!1,this.el.classList.remove(`is-in`),this.el.offsetWidth,this.el.classList.add(`is-in`),this.focus(Math.max(0,r?V.indexOf(r):0),!0)}close(){this.el.hidden||(this.el.hidden=!0,this.target=null,this.pick=null)}key(e){if(!this.open)return!1;let t=kt(e.key);if(t>=0)return this.choose(t),!0;switch(e.key){case`Escape`:case`g`:case`G`:return this.close(),!0;case`ArrowRight`:case`ArrowDown`:return this.focus((this.focused+1)%V.length,!0),!0;case`ArrowLeft`:case`ArrowUp`:return this.focus((this.focused+V.length-1)%V.length,!0),!0;case`Enter`:case` `:return this.choose(this.focused),!0}return!1}focus(e,t){this.focused=e,this.buttons.forEach((t,n)=>t.classList.toggle(`is-focus`,n===e));let n=V[e];M(this.hint,`${Oe[n].icon} ${Me(n)}`),t&&this.buttons[e]?.focus({preventScroll:!0})}choose(e){let t=V[e],n=this.pick;t&&n&&(this.buttons[e]?.classList.add(`is-picked`),setTimeout(()=>this.buttons[e]?.classList.remove(`is-picked`),300),this.close(),n(t))}},Ft=4e3;function It(e){return new Date(e).toISOString().slice(0,10)}function Lt(e){return`habblaud:world-stamp:${e}`}function Rt(e,t){if(!e)return null;try{let n=JSON.parse(e);return n.day===t&&c.includes(n.stampId)?n.stampId:null}catch{return null}}function zt(e){return e===`stamped`?`ok`:e===`already_done`?`already`:`failed`}function Bt(e,t=0,n=8){let r=[...e].filter(e=>c.includes(e.stampId)).sort((e,t)=>Number(!!t.mine)-Number(!!e.mine)||(t.count??1)-(e.count??1)),i=Math.max(1,Math.ceil(Math.min(n,r.length)/4)),a=(t^2654435769)>>>0,o=()=>(a=Math.imul(a^a>>>15,2246822507)+1831565813>>>0,((a^a>>>13)>>>0)/4294967296);return r.slice(0,n).map((e,t)=>{let n=t%4,r=Math.floor(t/4);return{stampId:e.stampId,icon:De(e.stampId),label:Ne(e.stampId),count:Math.max(1,e.count??1),mine:!!e.mine,x:(n+.5+(o()-.5)*.35)/4,y:(r+.5+(o()-.5)*.3)/i,rot:Math.round((o()-.5)*24)}})}function Vt(e,n){let r=()=>n.now?.()??Date.now(),i=Le(),a=0,o=!1,s=``,l=null,u=new Mt(9,400),d=N(`button`,{class:`ui-visit-social__like`,type:`button`,on:{click:()=>b()}}),f=N(`button`,{class:`ui-visit-social__stamp`,type:`button`,attrs:{"aria-expanded":`false`},on:{click:()=>S()}}),p=N(`div`,{class:`ui-visit-social__picker`,role:`group`,hidden:!0,attrs:{"aria-label":t(`Escolha um carimbo para a portaria`)}},N(`p`,{class:`ui-visit-social__hint`,text:t(`Um carimbo por prédio por dia. O dono vê quantos de cada recebeu, nunca quem deixou.`)}),N(`div`,{class:`ui-visit-social__grid`},...c.map(e=>N(`button`,{class:`ui-visit-social__choice`,type:`button`,title:Ne(e),attrs:{"data-stamp":e},on:{click:()=>C(e)}},N(`span`,{class:`ui-visit-social__choice-icon`,text:je[e].icon,attrs:{"aria-hidden":`true`}}),N(`span`,{text:Ne(e)}))))),m=N(`div`,{class:`ui-visit-social`},N(`div`,{class:`ui-visit-social__row`},d,f),p);e.append(m);let h=()=>s?Rt(g(s),It(r())):null;function g(e){try{return i?.getItem(Lt(e))??null}catch{return null}}function _(e,t){try{t?i?.setItem(Lt(e),JSON.stringify({day:It(r()),stampId:t})):i?.removeItem?.(Lt(e))}catch{}}function v(){let e=n.building(),r=n.mine();if(P(m,!e||r),!e)return;d.replaceChildren(N(`span`,{text:o?`💔`:`❤️`,attrs:{"aria-hidden":`true`}}),` ${t(o?`Descurtir`:`Curtir`)}`,N(`b`,{class:`ui-visit-social__count`,text:String(a)})),d.classList.toggle(`is-liked`,o),d.title=t(o?`Desfazer o like no prédio de {0}`:`Curtir o prédio de {0}`,[e.owner.name]);let i=h();f.disabled=!!i,f.replaceChildren(N(`span`,{text:i?De(i):`📮`,attrs:{"aria-hidden":`true`}}),` ${i?t(`Carimbo de hoje: {0}`,[Ne(i)]):t(`Deixar um carimbo`)}`),i&&x()}function y(){let e=n.building();e&&e.id!==s&&(s=e.id,x()),e&&(a=e.likes,o=e.likedByMe===!0),v()}function b(){let e=n.building();if(!e||n.mine())return;if(!u.take(r())){n.toast(t(`Devagar com os likes: espere um pouquinho.`));return}let i=!o;n.send([{t:i?`like`:`unlike`,buildingId:e.id}]),l={kind:`like`,at:r()},o=i,a=Math.max(0,a+(i?1:-1)),d.classList.remove(`is-pop`),d.offsetWidth,i&&d.classList.add(`is-pop`),v()}function x(){P(p,!0),f.setAttribute(`aria-expanded`,`false`)}function S(){if(h())return;let e=p.hidden;P(p,!e),f.setAttribute(`aria-expanded`,String(e))}function C(e){let i=n.building();!i||n.mine()||h()||(n.send([{t:`stamp`,buildingId:i.id,stampId:e}]),l={kind:`stamp`,at:r(),stampId:e},_(i.id,e),n.toast(`${De(e)} ${t(`Carimbo deixado na portaria: {0}`,[Ne(e)])}`),v())}function w(e){if(!e||typeof e!=`object`)return!1;let i=e;if(i.t===`like.update`&&i.buildingId===s&&typeof i.likes==`number`)return a=i.likes,o=i.likedByMe===!0,l?.kind===`like`&&(l=null),v(),!1;if(i.t!==`notice`||typeof i.text!=`string`||!l||r()-l.at>Ft)return!1;let c=l;if(l=null,c.kind===`stamp`){let e=zt(i.text);return e===`ok`?!0:e===`already`?(n.toast(t(`Você já deixou um carimbo aqui hoje.`)),!0):(_(s,null),v(),n.toast(i.text===`too_far`?t(`Entre no prédio ou chegue mais perto da porta para carimbar.`):t(`O carimbo não foi deixado. Tente de novo.`)),!0)}if(i.text===`daily_limit`)n.toast(t(`Você já deu os 50 likes de hoje. Amanhã tem mais!`));else if(i.text===`rate_limited`)n.toast(t(`Devagar com os likes: espere um pouquinho.`));else return!1;return o=!o,a=Math.max(0,a+(o?1:-1)),v(),!0}return y(),{el:m,message:w,sync:y,stampedToday:h,destroy:()=>m.remove()}}function Ht(e){return e.count>1?`${e.label} ×${e.count}`:e.label}function Ut(e){return e.state===`away`?`away`:e.discreet===!0?`discreet`:`live`}function Wt(e){return e===1?t(`1 agente`):t(`{0} agentes`,[e])}function Gt(e){return e===1?t(`1 visitante agora`):t(`{0} visitantes agora`,[e])}function Kt(e){return Fe(e.building)?0:e.floors.reduce((e,t)=>e+(Array.isArray(t.agents)?t.agents.length:0),0)}function qt(e,n){let r=e.building,i=Ut(r),a=[He(e.floors.length)];return i===`live`?a.push(Wt(Kt(e))):a.push(t(i===`away`?`apagado`:`modo discreto`)),{title:n?t(`Seu prédio, como os outros veem`):t(`Prédio de {0}`,[r.owner.name]),details:a,mode:i===`live`?null:i}}var Jt=[`working`,`waiting`,`idle`,`shell`];function Yt(e){switch(e){case`working`:return t(`trabalhando`);case`waiting`:return t(`esperando o dono`);case`shell`:return t(`de olho no terminal`);default:return t(`à toa`)}}function Xt(e){let n=Jt.includes(e.status)?e.status:`idle`,r=e.provider===`codex`?`codex`:`claude`;return{id:ne(e.id),name:typeof e.name==`string`&&e.name?e.name:t(`Agente`),role:e.kind===`sub`?t(`Subagente`):t(`Agente principal`),tool:Ie[r].name,status:n,statusText:Yt(n)}}function Zt(e){let n=Fe(e.building),r=e.floors.map(e=>({id:e.id,name:R(typeof e.label==`string`?e.label:``),agents:n||!Array.isArray(e.agents)?[]:e.agents.map(Xt)})),i=Ut(e.building);return{rooms:r,empty:i===`away`?t(`Prédio apagado: o dono pausou ou não está com o Habblaud aberto. As salas ficam escuras e vazias.`):i===`discreet`?t(`Modo discreto: o dono não mostra os agentes. As salas aparecem vazias, com a luz acesa.`):null}}function Qt(e,t){if(Fe(e.building))return null;for(let n of e.floors)for(let e of Array.isArray(n.agents)?n.agents:[])if(ne(e.id)===t)return{...Xt(e),room:R(n.label)};return null}var $t=class{deps;id;rev;detail;snapshot;leaving=!1;resyncAt=-1/0;constructor(e,t){this.deps=t,this.id=e.id,this.rev=e.rev,this.detail=structuredClone(e.detail),this.snapshot=ge(this.detail,t.now(),{version:t.version}),t.push(this.snapshot)}get light(){return Ut(this.detail.building)}replace(e){let t=structuredClone(e.detail),n=he(this.snapshot,{rev:e.rev,floors:t.floors,building:t.building},this.deps.now());this.rev=e.rev,this.detail=t,this.resyncAt=-1/0,this.publish(n.snapshot)}patch(e){let t=L(this.rev,e.rev);if(t===`stale`)return t;if(t===`resync`){let e=this.deps.now();return e-this.resyncAt>=5e3&&(this.resyncAt=e,this.deps.send([{t:`resync`,building:this.id}])),t}let n=he(this.snapshot,e,this.deps.now(),this.detail.building);return this.rev=e.rev,e.floors&&(this.detail.floors=structuredClone(e.floors)),e.building&&(this.detail.building=structuredClone(e.building)),typeof e.visitors==`number`&&(this.detail.visitors=e.visitors),this.publish(n.snapshot),t}leave(){return!this.leaving&&(this.leaving=!0,this.deps.send([{t:`leave`}]),this.deps.changed?.(),!0)}publish(e){e!==this.snapshot&&(this.snapshot=e,this.deps.push(e)),this.deps.changed?.()}},en=8e3,tn=`(max-width: 760px)`;function nn(e){let r=document.createElement(`canvas`);r.id=`visit`,e.after.after(r);let i=new g({search:``}),a=Pe(r,i,{visit:!0}),o=typeof matchMedia==`function`?matchMedia(tn):null,s=()=>!!o?.matches,c=!s(),l=!1,u=null,d=0,f=``;a.visit.setLight(Ut(e.inside.detail.building));let p=new $t(e.inside,{push:e=>i.pushReplay(e),send:t=>e.send(t),now:()=>Date.now(),version:e.version,changed:()=>ae()});a.visit.setVisitor({name:e.me.name,look:e.me.look,parts:e.me.parts});let m=N(`strong`,{class:`ui-visit-bar__title`}),h=N(`span`,{class:`ui-visit-bar__details`}),_=N(`span`,{class:`ui-visit-bar__mode`,hidden:!0}),v=N(`span`,{class:`ui-visit-bar__visitors`}),y=N(`button`,{class:`ui-btn ui-visit-bar__panel`,type:`button`,attrs:{"aria-expanded":`false`,"aria-controls":`ui-visit-panel`},on:{click:()=>le(!c)}}),b=N(`button`,{class:`ui-btn ui-btn--primary ui-visit-bar__leave`,type:`button`,text:t(`Sair do prédio`),title:t(`Sair do prédio (Esc)`),on:{click:()=>Se()}}),x=N(`header`,{class:`ui-visit-bar`,attrs:{"aria-label":t(`Visita`)}},N(`div`,{class:`ui-visit-bar__text`},N(`div`,{class:`ui-visit-bar__line`},m,_),N(`div`,{class:`ui-visit-bar__line`},h,v)),N(`div`,{class:`ui-visit-bar__actions`},y,b)),S=N(`strong`,{class:`ui-visit-card__name`}),C=N(`span`,{class:`ui-visit-card__meta`}),w=N(`span`,{class:`ui-visit-card__status`}),T=N(`span`,{class:`ui-visit-card__room`}),E=N(`section`,{class:`ui-visit-card`,hidden:!0,attrs:{"aria-live":`polite`,"aria-label":t(`Agente`)}},N(`div`,{class:`ui-visit-card__head`},S,N(`button`,{class:`ui-visit-card__close`,type:`button`,text:`×`,title:t(`Fechar`),attrs:{"aria-label":t(`Fechar`)},on:{click:()=>a.select(null)}})),C,N(`div`,{class:`ui-visit-card__row`},w,T)),ee=N(`p`,{class:`ui-visit-panel__empty`,hidden:!0}),D=N(`ul`,{class:`ui-visit-panel__rooms`}),O=N(`div`,{class:`ui-visit-panel__social`}),k=N(`aside`,{class:`ui-visit-panel`,attrs:{id:`ui-visit-panel`,"aria-label":t(`Salas do prédio`)}},O,N(`h3`,{class:`ui-visit-panel__title`,text:t(`Salas`)}),E,ee,D,N(`p`,{class:`ui-visit-panel__hint`,text:t(`Só o nome, o papel, a ferramenta e o status de cada agente: o resto do escritório não sai do computador do dono.`)})),A=N(`button`,{class:`ui-visit-exit`,type:`button`,hidden:!0,on:{click:()=>be()}},N(`kbd`,{text:`E`}),t(`Sair pelo elevador`)),te=N(`div`,{class:`ui-visit-help`,attrs:{"aria-hidden":`true`}},N(`span`,{},N(`kbd`,{text:`WASD`}),` `,t(`andar`)),N(`span`,{},N(`kbd`,{text:`Shift`}),` `,t(`correr`)),N(`span`,{},N(`kbd`,{text:t(`clique`)}),` `,t(`ir até lá`)),N(`span`,{},N(`kbd`,{text:`E`}),` `,t(`elevador`)),N(`span`,{},N(`kbd`,{text:`Esc`}),` `,t(`sair`))),j=N(`div`,{class:`ui-visit-leaving`,hidden:!0,role:`status`,text:t(`Saindo do prédio…`)}),F=N(`div`,{class:`ui-visit-board__pins`}),I=N(`div`,{class:`ui-visit-board`,hidden:!0,role:`img`},F),L=N(`div`,{class:`ui-visit`},I,x,k,A,te,j);e.uiRoot.append(L),e.uiRoot.classList.add(`is-visit`);let R=Vt(O,{building:()=>l?null:p.detail.building,mine:()=>e.mine,send:t=>e.send(t),toast:t=>e.toast(t)}),ne=``;function re(){let r=R.stampedToday(),i=e.mine?(e.summaryStamps?.()??[]).map(e=>({stampId:e.stampId,count:e.count})):r?[{stampId:r,mine:!0}]:[],a=JSON.stringify(i);if(a===ne)return;ne=a;let o=Bt(i,n(p.id));F.replaceChildren(...o.map(e=>N(`span`,{class:`ui-visit-board__pin${e.mine?` is-mine`:``}`,text:e.icon,title:Ht(e),attrs:{style:`left:${(e.x*100).toFixed(1)}%;top:${(e.y*100).toFixed(1)}%;--rot:${e.rot}deg`}})));let s=o.length?`${t(`Carimbos da portaria`)}: ${o.map(Ht).join(`, `)}`:t(`Carimbos da portaria: nenhum ainda`);I.setAttribute(`aria-label`,s),I.title=s,I.classList.toggle(`is-empty`,!o.length)}let ie=``;function ae(){if(l)return;let n=p.detail,r=qt(n,e.mine);M(m,r.title),M(h,r.details.join(` · `)),P(_,!r.mode),M(_,r.mode===`away`?`🌙 ${t(`apagado`)}`:r.mode===`discreet`?`🙈 ${t(`discreto`)}`:``),_.className=`ui-visit-bar__mode${r.mode?` is-${r.mode}`:``}`,M(v,n.visitors>0?`👀 ${Gt(n.visitors)}`:``),P(j,!p.leaving),b.disabled=p.leaving,a.visit.setLight(p.light);let i=n.building.theme;i!==f&&(f=i,a.setOptions({...e.options(),theme:i===`halloween`||i===`christmas`?i:`none`}));let o=Zt(n);P(ee,!o.empty),M(ee,o.empty??``);let s=JSON.stringify(o.rooms);s!==ie&&(ie=s,D.replaceChildren(...o.rooms.map(e=>N(`li`,{class:`ui-visit-room`},N(`div`,{class:`ui-visit-room__head`},N(`span`,{class:`ui-visit-room__name`,text:e.name}),N(`span`,{class:`ui-visit-room__count`,text:String(e.agents.length)})),e.agents.length?N(`ul`,{class:`ui-visit-room__agents`},...e.agents.map(e=>N(`li`,{},N(`button`,{class:`ui-visit-agent is-${e.status}`,type:`button`,attrs:{"data-agent":e.id},on:{click:()=>se(e.id)}},N(`span`,{class:`ui-visit-agent__dot`,attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-visit-agent__name`,text:e.name}),N(`span`,{class:`ui-visit-agent__meta`,text:`${e.role} · ${e.tool}`}),N(`span`,{class:`ui-visit-agent__status`,text:e.statusText}))))):null)))),oe(),M(y,`${t(`Salas`)} (${n.floors.length})`),re(),y.setAttribute(`aria-expanded`,String(c)),L.classList.toggle(`has-panel`,c),ue()}function oe(){let e=a.getSelection(),t=e?.type===`agent`?Qt(p.detail,e.id):null;if(P(E,!t),t){M(S,t.name),M(C,`${t.role} · ${t.tool}`),M(w,t.statusText),w.className=`ui-visit-card__status is-${t.status}`,M(T,t.room);for(let e of D.querySelectorAll(`.ui-visit-agent`))e.classList.toggle(`is-selected`,e.dataset.agent===t.id)}}function se(e){if(!e)return a.select(null);a.select({type:`agent`,id:e},{focus:!0})}function le(e){c=e,ae()}function ue(){L.style.setProperty(`--ui-visit-top`,`${Math.round(e.topInset()+8)}px`);let t=x.getBoundingClientRect().bottom||e.topInset()+56,n=k.getBoundingClientRect();a.setViewInsets?.({top:t+4,right:c&&!s()?Math.max(0,window.innerWidth-n.left):0,bottom:c&&s()?Math.max(0,window.innerHeight-n.top):0,left:0})}let de=a.onSelect(()=>oe()),fe=new Set,pe=!1,me=()=>a.visit.setIntent(p.leaving?{dx:0,dy:0,run:!1}:Xe(fe,pe)),he=e=>{let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``))},ge=(e,t)=>{e.key===`Shift`?pe=t:typeof e.getModifierState==`function`&&(pe=e.getModifierState(`Shift`));let n=Ze(e);if(!t){n&&fe.delete(n),me();return}if(!(e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||he(e.target)||ce(e.target))){if(n){e.preventDefault(),fe.add(n),me();return}e.key===`e`||e.key===`E`||e.key===`Enter`&&!e.target?.closest?.(`button, a`)?(e.preventDefault(),be()):e.key===`+`||e.key===`=`?(e.preventDefault(),a.zoomBy(1.25)):e.key===`-`||e.key===`_`?(e.preventDefault(),a.zoomBy(1/1.25)):e.key===`0`&&(e.preventDefault(),a.overview())}},_e=e=>ge(e,!0),z=e=>ge(e,!1),ve=()=>{fe.clear(),pe=!1,me()};addEventListener(`keydown`,_e),addEventListener(`keyup`,z),addEventListener(`blur`,ve);let ye=()=>ue();addEventListener(`resize`,ye),o?.addEventListener(`change`,ye);function be(){p.leaving||a.visit.atExit()&&a.visit.exit(()=>Se())&&(fe.clear(),me())}function Se(){p.leave()&&(fe.clear(),me(),u=setTimeout(()=>{u=null,l||e.stuck()},en))}let Ce=()=>{d=requestAnimationFrame(Ce);let e=!p.leaving&&a.visit.atExit()?a.visit.visitorScreen():null;P(A,!e);let t=a.visit.boardScreen(),n=!!t&&t.h>=18;if(P(I,!n),t&&n&&(I.style.transform=`translate(${Math.round(t.x)}px, ${Math.round(t.y)}px)`,I.style.width=`${Math.round(t.w)}px`,I.style.height=`${Math.round(t.h)}px`,I.style.setProperty(`--pin`,`${Math.max(8,Math.round(t.h*.3))}px`)),e){let t=A.offsetWidth||150,n=Math.max(8,Math.min(window.innerWidth-t-8,e.x-t/2));A.style.transform=`translate(${Math.round(n)}px, ${Math.round(e.y-34)}px)`}};return d=requestAnimationFrame(Ce),ae(),requestAnimationFrame(()=>ue()),{id:p.id,controller:p,world:a,replace(e){p.replace(e),R.sync()},patch(e){p.patch(e),e.building&&R.sync()},message(e){if(l)return!1;let t=R.message(e);return re(),t},leave:Se,escape(){return a.getSelection()?(a.select(null),!0):s()&&c?(le(!1),!0):(Se(),!0)},openPanel(e=!0){le(e)},selectAgent:se,destroy(){l||(l=!0,u&&clearTimeout(u),cancelAnimationFrame(d),de(),R.destroy(),removeEventListener(`keydown`,_e),removeEventListener(`keyup`,z),removeEventListener(`blur`,ve),removeEventListener(`resize`,ye),o?.removeEventListener(`change`,ye),a.destroy(),r.remove(),L.remove(),e.uiRoot.classList.remove(`is-visit`),xe(Le()))}}}var rn=3.2,an=60,on=1e3,sn=4,cn=.5,ln=.25,un=10,dn={up:`n`,down:`s`,left:`w`,right:`e`},fn={n:`up`,s:`down`,w:`left`,e:`right`};function pn(e,t,n){return Math.abs(e)<1e-6&&Math.abs(t)<1e-6?n:Math.abs(e)>=Math.abs(t)?e>0?`right`:`left`:t>0?`down`:`up`}function mn(e,t){let n=e[e.length-1];n&&t.t<n.t&&(t={...t,t:n.t}),e.push(t),e.length>un&&e.splice(0,e.length-un)}function hn(e){let t=0,n=0;for(let r=e.length-1;r>0&&n<sn;r--){let i=e[r].t-e[r-1].t;i<=0||i>on||(t=Math.max(t,i),n++)}return Math.min(700,Math.max(150,t+an))}function gn(e,t,n){return t>e?Math.min(t,e+n*cn):Math.max(t,e-n*ln)}function _n(e,t){let n=e.length;if(!n)return null;let r=e[0];if(t<=r.t)return{x:r.x,y:r.y,dir:r.dir,moving:r.moving&&n>1,speed:0};for(let r=1;r<n;r++){let n=e[r];if(t>n.t)continue;let i=e[r-1],a=Math.max(1,n.t-i.t),o=Math.min(1,Math.max(0,(t-i.t)/a)),s=Math.hypot(n.x-i.x,n.y-i.y);return{x:i.x+(n.x-i.x)*o,y:i.y+(n.y-i.y)*o,dir:n.dir,moving:s>.001||n.moving,speed:s*1e3/a}}let i=e[n-1],a=t-i.t>400;return{x:i.x,y:i.y,dir:i.dir,moving:i.moving&&!a,speed:0}}function vn(e,t,n,r,i=dt){let a=Math.max(1,Math.ceil(Math.max(Math.abs(n),Math.abs(r))/.5)),o=!1;for(let s=0;s<a;s++){let s=e+n/a;i(s,t)?e=s:o=!0;let c=t+r/a;i(e,c)?t=c:o=!0}return{x:e,y:t,blocked:o}}var yn=class{can;x;y;dir=`down`;moving=!1;running=!1;path=[];pathI=0;pathRun=!1;animT=0;constructor(e,t,n=dt){this.can=n,this.x=e,this.y=t}get hasPath(){return this.pathI<this.path.length}follow(e,t){this.path=e,this.pathI=0,this.pathRun=t}stopPath(){this.path=[],this.pathI=0}correct(e,t){this.x=e,this.y=t,this.stopPath()}update(e,t){let n=this.moving,r=this.running;e=Math.min(.1,Math.max(0,e));let i=t.dx,a=t.dy;if(i||a){this.stopPath();let n=Math.hypot(i,a);i/=n,a/=n;let r=(t.run?6:rn)*e,o=vn(this.x,this.y,i*r,a*r,this.can);this.dir=pn(i,a,this.dir),this.moving=Math.hypot(o.x-this.x,o.y-this.y)>1e-4,this.running=t.run&&this.moving,this.x=o.x,this.y=o.y}else if(this.hasPath){let t=(this.pathRun?6:rn)*e;for(this.moving=!0,this.running=this.pathRun;t>0&&this.hasPath;){let e=this.path[this.pathI],n=this.path[this.pathI+1],r=e-this.x,i=n-this.y,a=Math.hypot(r,i);a<=t?(this.x=e,this.y=n,t-=a,this.pathI+=2,a>1e-6&&(this.dir=pn(r,i,this.dir))):(this.x+=r/a*t,this.y+=i/a*t,this.dir=pn(r,i,this.dir),t=0)}this.hasPath||(this.moving=!1,this.running=!1)}else this.moving=!1,this.running=!1;n!==this.moving||r!==this.running?this.animT=0:this.animT+=e*1e3}};function bn(e,t,n,r){let i=[];for(let r=0;r<e.length;r+=2)i.push(e[r]+t+.5,e[r+1]+n+.5);return r&&i.length>=2?(i[i.length-2]=r.x,i[i.length-1]=r.y):r&&!i.length&&i.push(r.x,r.y),i}function xn(e){return Math.floor(e*100)/100}var Sn=class{send;lastAt=-1/0;last=null;constructor(e){this.send=e}tick(e,t){if(e-this.lastAt<100)return!1;let n={x:xn(t.x),y:xn(t.y),dir:dn[t.dir],moving:t.moving},r=this.last;return r&&r.x===n.x&&r.y===n.y&&r.dir===n.dir&&r.moving===n.moving?!1:(this.lastAt=e,this.last=n,this.send({t:`move`,...n}),!0)}keepAlive(e){let t={x:xn(e.x),y:xn(e.y),dir:dn[e.dir],moving:!1};this.lastAt=-1/0,this.last=t,this.send({t:`move`,...t})}reset(){this.last=null,this.lastAt=-1/0}},H={w:192,shadow:6,roof:26,floor:11,ground:30,maxFloors:12,cols:11,winX:11,winPitch:16,winW:10,winH:7},Cn=[{name:`tijolo`,wall:[`#7c3a2c`,`#9c4935`,`#b45a42`,`#c87256`],pattern:`brick`,trim:[`#cfc3b0`,`#ece4d6`],roof:[`#5d6470`,`#7a828e`],accent:[`#2f6fa8`,`#4f93cf`],frame:`#3a2a26`},{name:`tijolo claro`,wall:[`#9a7656`,`#b48c66`,`#c9a27a`,`#dcb990`],pattern:`brick`,trim:[`#e6ddd0`,`#f6f1e8`],roof:[`#646a74`,`#848a94`],accent:[`#1f7f75`,`#2fa597`],frame:`#4a3a2c`},{name:`concreto`,wall:[`#6f7884`,`#87909c`,`#9ea7b2`,`#b9c1ca`],pattern:`panel`,trim:[`#d6dce3`,`#eef1f4`],roof:[`#4b525c`,`#666d78`],accent:[`#d98a2b`,`#f2a33a`],frame:`#2e3648`},{name:`reboco`,wall:[`#c9c0b0`,`#ddd5c6`,`#ece6da`,`#f8f4ec`],pattern:`stucco`,trim:[`#a8977c`,`#c4b49a`],roof:[`#6f665e`,`#8e857b`],accent:[`#a8322a`,`#cf4a3c`],frame:`#4a4038`},{name:`vidro`,wall:[`#3f6f96`,`#5587b0`,`#6fa3c9`,`#9cc6e4`],pattern:`glass`,trim:[`#cdd8e2`,`#eef3f7`],roof:[`#353d48`,`#4c5562`],accent:[`#7451b8`,`#9a78dc`],frame:`#e8eef4`},{name:`tijolo escuro`,wall:[`#3e3433`,`#4f4241`,`#5f5150`,`#73625f`],pattern:`brick`,trim:[`#bdae98`,`#d8ccb8`],roof:[`#383b42`,`#50545c`],accent:[`#c8902a`,`#e8b04a`],frame:`#1f1a1a`},{name:`painel verde`,wall:[`#3a6e6a`,`#467f7b`,`#559491`,`#6caba7`],pattern:`panel`,trim:[`#dfe9e7`,`#f3f8f7`],roof:[`#3f4a53`,`#58646e`],accent:[`#d8603f`,`#f07c5a`],frame:`#24403e`},{name:`arenito`,wall:[`#b39b74`,`#c6ae86`,`#d8c39d`,`#e8d6b4`],pattern:`stone`,trim:[`#7f6a4c`,`#9c8562`],roof:[`#675e52`,`#83796b`],accent:[`#2f66b8`,`#3f7fd8`],frame:`#4a3d2c`},{name:`marinho`,wall:[`#1f2c4a`,`#283a5e`,`#314870`,`#3d5884`],pattern:`panel`,trim:[`#d58a24`,`#f2a33a`],roof:[`#262b36`,`#3a404c`],accent:[`#d58a24`,`#f2a33a`],frame:`#141b30`},{name:`menta`,wall:[`#7fae96`,`#93bea8`,`#a9cdb8`,`#c3dfcd`],pattern:`stucco`,trim:[`#f0ece2`,`#fbf9f4`],roof:[`#5f6871`,`#7b848d`],accent:[`#c95e8e`,`#e47aa8`],frame:`#3d5a4c`}];function wn(e){let t=Math.max(0,Math.min(H.maxFloors,Math.floor(e)));return H.roof+t*H.floor+H.ground}function Tn(e,t){let n=Array.from({length:t},(e,t)=>t),i=r(e*2654435761>>>0);for(let e=t-1;e>0;e--){let t=Math.floor(i()*(e+1));[n[e],n[t]]=[n[t],n[e]]}return n}function En(e,t,n){let r=Number.isFinite(e.floors)?Math.max(0,Math.floor(e.floors)):0,i=Math.min(H.maxFloors,r),a=Math.max(0,r-H.maxFloors),o=(n>>>0)%40,s=i*H.cols,c=e.state===`online`?`online`:`away`,l=!e.agents,u=0,d=0;if(c===`online`){if(!e.agents)u=4;else{let t=Math.max(0,e.agents.total);if(t>0){let n=Math.max(0,Math.min(t,e.agents.working));u=Math.round(n/t*8),n>0&&u===0&&(u=1);let r=Math.max(0,Math.min(t,e.agents.waiting));r>0&&(d=Math.max(1,Math.round(r/t*s)))}}}let f=Tn(o,s),p=Math.round(s*u/8),m=f.slice(0,p),h=f.slice(p,Math.min(s,p+d)),g=e.theme===`halloween`||e.theme===`christmas`?e.theme:`none`;return{side:t,variant:o,style:o%Cn.length,drawn:i,plus:a,state:c,theme:g,discreet:l,litLevel:u,lit:m,waiting:h,height:wn(i)}}function Dn(e){return`${e.side}|${e.variant}|${e.drawn}|${Math.min(99,e.plus)}|${e.state}|${e.theme}|${e.litLevel}`}function On(e,t){let n=t%H.cols,r=Math.floor(t/H.cols),i=e.drawn-1-r;return{x:H.winX+n*H.winPitch,y:H.roof+i*H.floor+2,w:H.winW,h:H.winH}}function kn(e){return e.side===`front`?{x:34,y:e.height-H.ground+2,w:H.w-68,h:8}:{x:50,y:11,w:H.w-100,h:8}}var An=new Map,jn=600;function Mn(e){let t=Dn(e),n=An.get(t);return n||(An.size>=jn&&An.clear(),n=Rn(e),An.set(t,n),n)}function Nn(e){return An.has(Dn(e))}function Pn(e,t){let n=document.createElement(`canvas`);n.width=e,n.height=t;let r=n.getContext(`2d`);return r.imageSmoothingEnabled=!1,[n,r]}var U=`#2e3648`,W=[`#c98f3c`,`#f2c66b`,`#ffe3a0`,`#fff4d2`],G=[`#1f3550`,`#2b4868`,`#3c5f84`,`#7fa6cc`],Fn=new Map;function In(e){let t=Fn.get(e);if(!t){let{buf:n}=ue(e);t=document.createElement(`canvas`),t.width=n.w,t.height=n.h,t.getContext(`2d`).putImageData(new ImageData(n.data,n.w,n.h),0,0),Fn.set(e,t)}return t}function Ln(e,t,n,r){let i=In(t);e.drawImage(i,Math.round(n-20),Math.round(r-60))}function K(e,t,n,r,i,a){e.fillStyle=a,e.fillRect(t,n,r,i)}function Rn(e){let t=H.w+H.shadow,n=e.height,[i,a]=Pn(t,n),[o,s]=Pn(t,n),c=Cn[e.style],l=r((e.variant+1)*2654435761>>>0),u=e.state===`online`,d=H.roof,f=n-H.ground,p=H.w;a.fillStyle=`rgba(28,36,52,0.22)`,a.fillRect(p,6,H.shadow,n-6),a.fillStyle=`rgba(28,36,52,0.12)`,a.fillRect(p,10,2,n-10),zn(a,c,0,d,p,n-d,l);for(let t=0;t<=e.drawn;t++)K(a,0,d+t*H.floor-1,p,1,c.pattern===`glass`?c.trim[0]:q(c.wall[0],-.08));K(a,0,d,3,n-d,c.trim[0]),K(a,p-3,d,3,n-d,c.trim[0]),K(a,0,d,1,n-d,c.trim[1]);let m=new Set(e.lit),h=e.drawn*H.cols;for(let t=0;t<h;t++){let n=On(e,t);Bn(a,c,n.x,n.y,m.has(t),(e.variant*31+t)%7),m.has(t)&&Vn(s,n.x,n.y)}if(e.side===`back`&&e.drawn>0){Hn(a,e.variant%2==0?H.winX+H.winPitch-3:H.winX+(H.cols-2)*H.winPitch-3,d,e.drawn);for(let t=0;t<e.drawn;t++)if(l()<.45){let n=2+Math.floor(l()*(H.cols-4)),r=On(e,(e.drawn-1-t)*H.cols+n);Un(a,r.x+1,r.y+r.h+1)}}if(e.side===`front`?Wn(a,s,c,e,f,u,l):Gn(a,s,c,e,f,u,l),qn(a,s,c,e,l),Yn(a,s,e,f),e.side===`back`&&Jn(a,s,c,e),u||Kn(a,p/2,e.side===`front`?f+16:1),e.plus>0){let t=`+${Math.min(99,e.plus)}`,n=ie(t),r=e.side===`front`?p-n-18:16,i=e.side===`front`?6:13;K(a,r-3,i-3,n+6,11,U),K(a,r-2,i-2,n+4,9,u?c.accent[1]:`#5a6170`),K(a,r-2,i-2,n+4,1,u?$n(c.accent[1],.25):`#6d7483`),ve(a,t,r,i,`#ffffff`),K(a,r+n/2-1,i+8,2,3,U),u&&(s.fillStyle=`rgba(255,255,255,0.85)`,ve(s,t,r,i,`#fff6dc`))}return{canvas:i,glow:o,w:t,h:n}}function zn(e,t,n,r,i,a,o){let[s,c,l,u]=t.wall;switch(K(e,n,r,i,a,c),t.pattern){case`brick`:for(let t=r;t<r+a;t+=3){let a=(t-r)/3%2==0?0:3;K(e,n,t+2,i,1,s);for(let r=n+a;r<n+i;r+=6){K(e,r,t,1,2,s);let n=o();n<.18?K(e,r+1,t,5,2,l):n<.26&&K(e,r+1,t,5,2,q(c,-.06))}}break;case`panel`:for(let t=n;t<n+i;t+=24)K(e,t,r,1,a,s);for(let t=r+5;t<r+a;t+=11)K(e,n,t,i,1,q(c,-.05));K(e,n,r,i,1,l);break;case`stucco`:for(let t=0;t<i*a/40;t++)K(e,n+Math.floor(o()*i),r+Math.floor(o()*a),1,1,o()<.5?l:q(c,-.04));break;case`stone`:for(let t=r;t<r+a;t+=5){K(e,n,t+4,i,1,s);let a=(t-r)/5%2==0?0:7;for(let r=n+a;r<n+i;r+=14)K(e,r,t,1,4,s),o()<.3&&K(e,r+1,t,13,1,u)}break;case`glass`:K(e,n,r,i,a,t.wall[1]);for(let o=r;o<r+a;o++)(o-r)%11<3&&K(e,n,o,i,1,t.wall[2]);for(let o=n+3;o<n+i;o+=16)K(e,o,r,1,a,t.frame);e.fillStyle=`rgba(255,255,255,0.12)`;for(let t=0;t<a;t++)e.fillRect(n+(t*2+40)%(i+40)-20,r+t,10,1)}}function Bn(e,t,n,r,i,a){let o=H.winW,s=H.winH;t.pattern!==`glass`&&(K(e,n-1,r-1,o+2,s+2,t.frame),K(e,n-1,r+s+1,o+2,1,t.trim[1]),K(e,n-1,r+s+2,o+2,1,q(t.trim[0],-.15))),i?(K(e,n,r,o,s,W[2]),K(e,n,r,o,2,W[3]),K(e,n,r+s-2,o,2,W[1]),K(e,n+2+a%4,r+s-3,3,2,`#5fb8f0`),K(e,n+2+a%4,r+s-3,1,1,`#c8ecff`),(a===2||a===5)&&K(e,n+6-a%3,r+s-4,2,3,`#7a5a3a`)):(K(e,n,r,o,s,G[1]),K(e,n,r,o,2,G[0]),K(e,n,r+s-1,o,1,G[2]),K(e,n+1+a%3,r+2,1,3,G[3]),K(e,n+2+a%3,r+2,1,1,`#b8d2ea`),a===4&&K(e,n+1,r+1,o-2,2,`#c9cfd9`)),K(e,n+(o>>1),r,1,s,t.pattern===`glass`?t.frame:q(t.frame,.1))}function Vn(e,t,n){let r=H.winW,i=H.winH;e.fillStyle=W[2],e.fillRect(t,n,r,i),e.fillStyle=W[3],e.fillRect(t,n,r,2),e.fillStyle=`#5fb8f0`,e.fillRect(t+3,n+i-3,3,2),e.fillStyle=`rgba(255,214,140,0.35)`,e.fillRect(t-1,n-1,r+2,i+2)}function Hn(e,t,n,r){let i=`#2a2f3a`,a=`#5b6475`;for(let o=0;o<r;o++){let s=n+o*H.floor+H.floor-2;K(e,t-2,s,18,1,a),K(e,t-2,s+1,18,1,i),K(e,t-2,s-4,18,1,i);for(let n=0;n<18;n+=3)K(e,t-2+n,s-4,1,4,i);if(o<r-1){let n=o%2==0?1:-1;for(let r=0;r<H.floor;r++)K(e,t+7+n*(r-5),s+2+r,2,1,r%2?i:a)}}}function Un(e,t,n){K(e,t,n,7,4,U),K(e,t+1,n,5,3,`#c9d0d8`),K(e,t+1,n,5,1,`#e8edf2`),K(e,t+2,n+1,3,1,`#8b95a3`)}function Wn(e,t,n,r,i,a,o){let s=H.w,c=r.height-2;K(e,0,i,s,H.ground,n.trim[0]),K(e,0,i,s,1,n.trim[1]),K(e,0,i+1,s,1,q(n.trim[0],-.2));let l=kn(r);K(e,l.x-2,l.y-1,l.w+4,l.h+2,U),K(e,l.x-1,l.y,l.w+2,l.h,a?n.accent[0]:`#4a505c`),K(e,l.x-1,l.y,l.w+2,1,a?n.accent[1]:`#5b6270`),a&&(t.fillStyle=`rgba(255,240,200,0.55)`,t.fillRect(l.x-1,l.y,l.w+2,l.h));let u=s/2-16,d=s/2+16,f=i+12,p=c-f-2;for(let[r,i]of[[6,u-6],[d+6,s-6]]){if(K(e,r-1,f-1,i-r+2,p+2,U),a){K(e,r,f,i-r,p,W[2]),K(e,r,f,i-r,2,W[3]),K(e,r,f+p-3,i-r,3,W[1]);for(let t=r+4;t<i-4;t+=9+Math.floor(o()*5))K(e,t,f+p-6,5,3,`#8a6243`),o()<.5?K(e,t+1,f+p-9,3,3,`#4b8a45`):K(e,t+1,f+p-8,3,2,`#5fb8f0`);t.fillStyle=W[2],t.fillRect(r,f,i-r,p),t.fillStyle=`rgba(255,214,140,0.3)`,t.fillRect(r-2,f-2,i-r+4,p+4)}else{K(e,r,f,i-r,p,G[1]),K(e,r,f,i-r,2,G[0]);for(let t=r+3;t<i;t+=13)K(e,t,f+2,2,p-3,G[2])}for(let t=r+16;t<i-2;t+=16)K(e,t,f,1,p,n.frame===`#e8eef4`?`#cdd8e2`:U);K(e,r-1,f-4,i-r+2,3,n.accent[0]);for(let t=r;t<i;t+=4)K(e,t,f-4,2,3,n.accent[1]);K(e,r-1,f-1,i-r+2,1,q(n.accent[0],-.25))}let m=i+9;K(e,u-2,m-2,36,c-m+2,U),K(e,u-1,m-1,34,c-m+1,n.trim[1]);for(let n of[u,s/2+1])K(e,n,m,15,c-m,U),K(e,n+1,m+1,13,c-m-1,a?`#f6dd9a`:G[1]),K(e,n+1,m+1,13,2,a?W[3]:G[0]),K(e,n+2,m+3,1,c-m-6,a?`#fff6dc`:G[3]),K(e,n===u?n+12:n+2,m+9,1,4,`#c9cfd9`),a&&(t.fillStyle=`#f6dd9a`,t.fillRect(n+1,m+1,13,c-m-1));K(e,0,c,s,2,q(n.trim[0],-.25)),K(e,u-4,c-1,40,3,`#c9cdd3`),K(e,u-4,c-1,40,1,`#e4e7eb`);for(let n of[u-6,d+4])K(e,n,m+2,3,4,U),K(e,n+1,m+3,1,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.9)`,t.fillRect(n,m+2,3,4),t.fillStyle=`rgba(255,220,150,0.25)`,t.fillRect(n-3,m,9,10))}function Gn(e,t,n,r,i,a,o){let s=H.w,c=r.height-2;K(e,0,i,s,2,q(n.wall[0],-.1));for(let r=12;r<s-12;r+=22){if(Math.abs(r+5-s/2)<18)continue;K(e,r-1,i+5,12,6,n.frame);let c=a&&o()<.5;K(e,r,i+6,10,4,c?W[2]:G[1]),K(e,r,i+6,10,1,c?W[3]:G[0]),c&&(t.fillStyle=W[2],t.fillRect(r,i+6,10,4))}let l=s/2-7;K(e,l-1,i+9,16,c-i-9,U),K(e,l,i+10,14,c-i-10,`#7d8794`),K(e,l,i+10,14,1,`#a9b2bd`),K(e,l+11,i+18,1,3,`#d9dee4`),K(e,l+3,i+12,8,2,`#5f6875`),K(e,l+5,i+6,4,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.9)`,t.fillRect(l+5,i+6,4,2));for(let[t,n]of[[22,`#3f7f4f`],[32,`#2f5f9e`]])K(e,t-1,c-9,9,9,U),K(e,t,c-8,7,8,n),K(e,t,c-8,7,2,$n(n,.2));let u=s-40;for(let t=0;t<2;t++){let n=u+t*12;e.strokeStyle=`#2a2f3a`,e.lineWidth=1,e.beginPath(),e.arc(n+2.5,c-3.5,3,0,Math.PI*2),e.arc(n+10.5,c-3.5,3,0,Math.PI*2),e.stroke(),K(e,n+3,c-6,7,1,t?`#cf4a3c`:`#2fa597`)}K(e,0,c,s,2,q(n.trim[0],-.25))}function Kn(e,n,r){let i=t(`Fechado`),a=Math.min(40,ie(i)),o=a+6,s=Math.round(n-o/2);K(e,s+2,r-4,1,4,`#3a2a20`),K(e,s+o-3,r-4,1,4,`#3a2a20`),K(e,s-1,r-1,o+2,10,`#3a2a20`),K(e,s,r,o,8,`#c98f5a`),K(e,s,r,o,1,`#e3ad78`),e.save(),e.beginPath(),e.rect(s+3,r,a,8),e.clip(),ve(e,i,s+3,r+2,`#3a2a20`),e.restore()}function qn(e,t,n,r,i){let a=H.w,o=H.roof,s=r.state===`online`;K(e,0,0,a,o-5,U),K(e,1,1,a-2,o-6,n.roof[1]),K(e,3,3,a-6,o-10,n.roof[0]);for(let t=0;t<90;t++)K(e,3+Math.floor(i()*(a-6)),3+Math.floor(i()*(o-10)),1,1,i()<.5?n.roof[1]:q(n.roof[0],-.12));K(e,0,o-5,a,4,n.trim[0]),K(e,0,o-5,a,1,n.trim[1]),K(e,0,o-2,a,1,q(n.trim[0],-.3)),K(e,0,o-1,a,1,`rgba(28,36,52,0.35)`);let c=r.side===`back`?[14,150]:[14,60,120,160];for(let t of c){let n=i(),r=t+Math.floor(i()*10);n<.35?(K(e,r,4,12,12,U),K(e,r+1,5,10,10,`#9aa6b4`),K(e,r+1,5,10,3,`#c3ccd6`),K(e,r+3,6,6,1,`#e3e8ee`)):n<.7?(K(e,r,6,14,9,U),K(e,r+1,7,12,7,`#d4dae1`),K(e,r+1,7,12,2,`#eef1f4`),K(e,r+4,9,6,4,`#8b95a3`),K(e,r+6,10,2,2,`#5f6875`)):(K(e,r,6,16,9,U),K(e,r+1,7,14,7,s?`#9cc6e4`:`#3c5f84`),K(e,r+1,7,14,2,`#c8e2f4`),K(e,r+8,7,1,7,U))}if(i()<.5){let n=r.side===`back`?176:100+Math.floor(i()*40);K(e,n,1,1,9,`#4a5468`),K(e,n-2,3,5,1,`#4a5468`),K(e,n,1,1,1,s?`#ff5a4a`:`#8b95a3`),s&&(t.fillStyle=`#ff5a4a`,t.fillRect(n,1,1,1))}}function Jn(e,t,n,r){let i=H.w,a=r.state===`online`;{let o=kn(r);K(e,o.x-2,o.y-1,o.w+4,o.h+2,U),K(e,o.x-1,o.y,o.w+2,o.h,a?n.accent[0]:`#4a505c`),K(e,o.x-1,o.y,o.w+2,1,a?n.accent[1]:`#5b6270`),a&&(t.fillStyle=`rgba(255,240,200,0.55)`,t.fillRect(o.x-1,o.y,o.w+2,o.h));let s=i/2-22;K(e,s-1,0,46,10,U);for(let t=0;t<44;t++){let r=Math.floor(t/4)%2==0;K(e,s+t,0,1,9,r?n.accent[1]:`#f6efe2`)}K(e,s,0,44,2,`rgba(255,255,255,0.35)`),K(e,s,7,44,2,`rgba(28,36,52,0.25)`);for(let n of[s+3,s+39])K(e,n,1,2,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.95)`,t.fillRect(n,1,2,2))}}function Yn(e,t,n,r){if(n.theme===`none`){if(n.side===`front`){let t=H.w,r=n.height-2;for(let n of[t/2-26,t/2+20])K(e,n,r-6,6,6,U),K(e,n+1,r-5,4,5,`#c97a4a`),K(e,n-1,r-11,8,6,`#3f8550`),K(e,n,r-12,6,2,`#5aa45d`)}return}let i=H.w,a=H.roof,o=n.state===`online`,s=n.theme===`christmas`;if(s){e.fillStyle=`#f4f8fb`;for(let t=2;t<i-2;t+=1){let n=Math.sin(t*.35)+Math.sin(t*.11);n>-.4&&e.fillRect(t,2,1,2+ +(n>.8))}e.fillRect(0,a-6,i,2),e.fillStyle=`#dbe6ee`,e.fillRect(0,a-4,i,1);for(let t=6;t<i-6;t+=23)e.fillRect(t,6+t%7,6,2)}let c=s?[`#ff5a5a`,`#ffd76a`,`#6ad1ff`,`#7be07b`]:[`#b06ae6`,`#ff9a3c`];for(let n=4,r=0;n<i-2;n+=6,r++){let i=a+r%2;K(e,n,i-1,1,1,`#2e3648`),K(e,n,i,2,2,c[r%c.length]),o&&(t.fillStyle=c[r%c.length],t.fillRect(n,i,2,2),t.globalAlpha=.35,t.fillRect(n-1,i-1,4,4),t.globalAlpha=1)}if(!s){e.strokeStyle=`rgba(230,220,240,0.8)`,e.lineWidth=1;for(let t of[1,-1]){let n=t===1?3.5:i-3.5,r=a+.5;e.beginPath();for(let[i,a]of[[9,0],[7,5],[0,9]])e.moveTo(n,r),e.lineTo(n+t*i,r+a);e.moveTo(n+t*4,r),e.lineTo(n+t*3,r+3),e.lineTo(n,r+4),e.stroke()}for(let t of[40,132]){let n=a-9;K(e,t,n,3,2,`#47344f`),K(e,t-3,n-1,3,2,`#47344f`),K(e,t+3,n-1,3,2,`#47344f`),K(e,t+1,n,1,1,`#f5b95f`)}}let l=n.height-2;n.side===`front`?s?(Xn(e,t,i/2-19,r+6,38,o),Ln(e,`tree`,i-30,l+2),Ln(e,`gift`,i-52,l+2)):(Ln(e,`pumpkin`,i/2-28,l+2),Ln(e,`pumpkin`,i/2+28,l+2),n.drawn>0&&Ln(e,`ghost`,30,r+6)):s?(Xn(e,t,i/2-10,r+6,20,o),Ln(e,`tree`,i/2+30,l+2)):(Ln(e,`pumpkin`,i/2-22,l+2),Ln(e,`pumpkin`,i/2+22,l+2))}function Xn(e,t,n,r,i,a){for(let o=0;o<i;o++){let s=Math.round(Math.sin(o/i*Math.PI)*3);K(e,n+o,r+s,1,3,o%3==0?`#245644`:`#347653`),o%6==3&&(K(e,n+o,r+s+2,2,2,[`#ffd76a`,`#ff5a5a`,`#6ad1ff`][o/6%3|0]),a&&(t.fillStyle=`#ffe9a8`,t.fillRect(n+o,r+s+2,2,2)))}for(let t of[n-1,n+i-3])K(e,t,r-1,4,3,`#c93945`),K(e,t+1,r+2,1,3,`#a82d42`),K(e,t+2,r+2,1,2,`#a82d42`)}function Zn(e){let t=parseInt(e.slice(1,7),16);return[t>>16&255,t>>8&255,t&255]}function Qn(e,t,n){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function q(e,t){let[n,r,i]=Zn(e);return t<0?Qn(n*(1+t),r*(1+t),i*(1+t)):Qn(n+(255-n)*t,r+(255-r)*t,i+(255-i)*t)}function $n(e,t){return q(e,Math.abs(t))}function er(e,t){let n=document.createElement(`canvas`);n.width=e,n.height=t;let r=n.getContext(`2d`);return r.imageSmoothingEnabled=!1,[n,r]}var J=e=>e*16;function Y(e){try{e()}catch{}}function tr(e,t,n,r,i,a=.16){e.save();try{e.globalCompositeOperation=`saturation`,e.fillStyle=`rgba(128,128,128,${a})`,e.fillRect(t,n,r,i)}catch{}e.restore()}function nr(e,t,n,r,i,a){let o=`#e2dfd6`,s=`#8d8a82`,c=`#5f5c56`;a===`s`?(e.fillStyle=o,e.fillRect(t,n+i-3,r,1),e.fillStyle=s,e.fillRect(t,n+i-2,r,2),e.fillStyle=c,e.fillRect(t,n+i,r,1)):a===`n`?(e.fillStyle=c,e.fillRect(t,n,r,1),e.fillStyle=o,e.fillRect(t,n+1,r,1)):a===`e`?(e.fillStyle=o,e.fillRect(t+r-2,n,1,i),e.fillStyle=s,e.fillRect(t+r-1,n,1,i),e.fillStyle=`rgba(40,40,40,0.35)`,e.fillRect(t+r,n,1,i)):(e.fillStyle=`rgba(40,40,40,0.35)`,e.fillRect(t-1,n,1,i),e.fillStyle=s,e.fillRect(t,n,1,i),e.fillStyle=o,e.fillRect(t+1,n,1,i))}function rr(e,t,n){let i=ot();for(let n of[...i.streets,i.intersection])Y(()=>e.drawFloor(t,`street`,J(n.x),J(n.y),J(n.w),J(n.h),{seed:13}));t.fillStyle=`rgba(20,22,28,0.18)`;let a=J(i.sidewalkOuter.w),o=J(i.sidewalkOuter.h);t.fillRect(a,0,3,o),t.fillRect(0,o,a,3),t.fillStyle=`rgba(255,226,140,0.85)`;for(let[e,n,r,a]of i.laneMarks)if(n===a)for(let i=J(e);i<J(r)-8;i+=24)t.fillRect(i,J(n)-1,12,2);else for(let r=J(n);r<J(a)-8;r+=24)t.fillRect(J(e)-1,r,2,12);for(let e of i.crosswalks){let n=e.rect;if(t.fillStyle=`rgba(244,244,236,0.9)`,e.across===`ns`)for(let e=J(n.y)+4;e<J(n.y+n.h)-3;e+=6)t.fillRect(J(n.x)+3,e,J(n.w)-6,3);else for(let e=J(n.x)+4;e<J(n.x+n.w)-3;e+=6)t.fillRect(e,J(n.y)+3,3,J(n.h)-6)}t.fillStyle=`rgba(244,244,236,0.75)`,t.fillRect(a-2,o+2,2,J(2)-2),t.fillRect(a+J(3),o-2,J(2)-2,2);let s=r(n);for(let e=0;e<3;e++){let e=J(4+Math.floor(s()*36));t.fillStyle=`#3a3d44`,t.fillRect(e,o+4,10,3),t.fillStyle=`#2a2c31`;for(let n=1;n<10;n+=2)t.fillRect(e+n,o+4,1,3)}let c=a+J(2)+2,l=J(8+Math.floor(s()*10));t.fillStyle=`#3f4249`,t.beginPath(),t.ellipse(c+6,l+5,6,4.5,0,0,Math.PI*2),t.fill(),t.fillStyle=`#585c64`,t.fillRect(c+2,l+4,8,1),t.fillRect(c+3,l+6,6,1)}function ir(e,t){let n=ot().sidewalkOuter;Y(()=>e.drawFloor(t,`sidewalk`,J(n.x),J(n.y),J(n.w),J(n.h),{seed:12})),nr(t,0,0,J(n.w),2,`n`),nr(t,0,J(n.h)-3,J(n.w),3,`s`),nr(t,0,0,2,J(n.h),`w`),nr(t,J(n.w)-3,0,3,J(n.h),`e`)}function ar(e,t){let n=ot(),r=n.block;Y(()=>e.drawFloor(t,`grass`,J(r.x),J(r.y),J(r.w),J(r.h),{seed:11})),tr(t,J(r.x),J(r.y),J(r.w),J(r.h)),t.fillStyle=`rgba(40,70,40,0.18)`;for(let e of n.lots)t.fillRect(J(e.x+e.w)-1,J(e.y),1,J(e.h)),t.fillRect(J(e.x),J(e.y+e.h)-1,J(e.w),1);let a=J(r.x),o=J(r.y),s=J(r.w),c=J(r.h);t.fillStyle=`#9a968c`,t.fillRect(a,o,s,2),t.fillRect(a,o+c-2,s,2),t.fillRect(a,o,2,c),t.fillRect(a+s-2,o,2,c),t.fillStyle=`#c9c5bb`,t.fillRect(a,o,s,1),t.fillRect(a,o+c-2,s,1),t.fillRect(a,o,1,c),t.fillRect(a+s-2,o,1,c);for(let a of n.lots){let n=a.y===r.y,s=J(a.x+i.dx);Y(()=>e.drawFloor(t,`sidewalk`,s,n?o:o+c-2,J(i.w),2,{seed:12}))}}function or(e){let t=ot(),[n,r]=er(J(t.sidewalkOuter.w+t.streets[0].w),J(t.sidewalkOuter.h+t.streets[1].h));return rr(e,r,77),ir(e,r),ar(e,r),n}function sr(e){let t=ot(),[n,r]=er(J(t.sidewalkOuter.w+t.streets[0].w),J(t.sidewalkOuter.h+t.streets[1].h));rr(e,r,99),ir(e,r);let i=t.block,a=J(i.x),o=J(i.y),s=J(i.w),c=J(i.h);Y(()=>e.drawFloor(r,`sidewalk`,a,o,s,c,{seed:23})),r.fillStyle=`rgba(196,150,96,0.10)`,r.fillRect(a,o,s,c),r.fillStyle=`#9a8f80`,r.fillRect(a+J(1),o+J(1),s-J(2),3),r.fillRect(a+J(1),o+c-J(1)-3,s-J(2),3),r.fillRect(a+J(1),o+J(1),3,c-J(2)),r.fillRect(a+s-J(1)-3,o+J(1),3,c-J(2)),r.fillStyle=`rgba(255,248,232,0.5)`,r.fillRect(a+J(1),o+J(1),s-J(2),1);let l=a+J(y.x+y.w/2),u=o+J(y.y+y.h/2);r.fillStyle=`rgba(236,226,206,0.55)`,r.fillRect(l-J(1.5),o+J(1)+3,J(3),c-J(2)-6),r.fillRect(a+J(1)+3,u-J(1.5),s-J(2)-6,J(3)),r.fillStyle=`rgba(140,128,110,0.45)`;for(let e of[-1,1])r.fillRect(l+e*J(1.5)-+(e>0),o+J(1)+3,1,c-J(2)-6),r.fillRect(a+J(1)+3,u+e*J(1.5)-+(e>0),s-J(2)-6,1);let d=[[2,2,10,6],[i.w-12,2,10,6],[2,i.h-8,10,6],[i.w-12,i.h-8,10,6]];for(let[t,n,i,s]of d){let c=a+J(t),l=o+J(n);r.fillStyle=`#8d8a82`,r.fillRect(c-2,l-2,J(i)+4,J(s)+4),r.fillStyle=`#d8d4ca`,r.fillRect(c-2,l-2,J(i)+4,1),Y(()=>e.drawFloor(r,`grass`,c,l,J(i),J(s),{seed:31})),tr(r,c,l,J(i),J(s))}let f=y,p=a+J(f.x+f.w/2),m=o+J(f.y+f.h/2);r.save(),r.beginPath(),r.ellipse(p,m,J(7),J(5.2),0,0,Math.PI*2),r.clip(),Y(()=>e.drawFloor(r,`marble`,p-J(8),m-J(6),J(16),J(12),{seed:41})),r.restore(),r.strokeStyle=`#8f8676`,r.lineWidth=3,r.beginPath(),r.ellipse(p,m,J(7)-1,J(5.2)-1,0,0,Math.PI*2),r.stroke(),r.strokeStyle=`rgba(63,127,216,0.35)`,r.lineWidth=2,r.setLineDash([4,4]),r.beginPath(),r.ellipse(p,m+4,J(4.8),J(3.4),0,0,Math.PI*2),r.stroke(),r.setLineDash([]),r.strokeStyle=`rgba(255,255,255,0.5)`,r.lineWidth=1,r.beginPath(),r.ellipse(p,m-1,J(7)-2,J(5.2)-2,0,Math.PI,Math.PI*2),r.stroke();let h=a+J(21)+8,g=o+J(15)+8;return r.fillStyle=`#b9b2a4`,r.beginPath(),r.moveTo(h,g-12),r.lineTo(h+4,g),r.lineTo(h,g+12),r.lineTo(h-4,g),r.closePath(),r.fill(),r.beginPath(),r.moveTo(h-12,g),r.lineTo(h,g-4),r.lineTo(h+12,g),r.lineTo(h,g+4),r.closePath(),r.fill(),r.fillStyle=`#f2a33a`,r.fillRect(h-1,g-11,2,6),n}function cr(e,t,n,r){let[a,o]=er(J(A.w),J(A.h)),s=J(i.dx),c=(t,n,i,a)=>{o.fillStyle=`#9a968c`,o.fillRect(t-1,n-1,i+2,a+2),Y(()=>e.drawFloor(o,`sidewalk`,t,n,i,a,{seed:12+r%3}))},l=J(A.h/2);switch(t){case`park`:n?c(s,0,J(2),l+8):c(s,l-8,J(2),J(A.h)-l+8),c(J(2),l-8,J(10),J(1)),o.fillStyle=`#6a4b35`,o.beginPath(),o.ellipse(J(7),l+14,18,7,0,0,Math.PI*2),o.fill(),o.strokeStyle=`#b9b5aa`,o.lineWidth=2,o.stroke();break;case`pond`:{n?c(s,0,J(2),J(2)):c(s,J(A.h-2),J(2),J(2));let e=J(7),t=l+(n?4:-4);o.fillStyle=`#8d8a82`,o.beginPath(),o.ellipse(e,t,J(4.6),J(2.8),0,0,Math.PI*2),o.fill(),o.fillStyle=`#3f7fa8`,o.beginPath(),o.ellipse(e,t,J(4.6)-3,J(2.8)-3,0,0,Math.PI*2),o.fill(),o.fillStyle=`#5aa0c8`,o.beginPath(),o.ellipse(e-6,t-6,J(3),J(1.4),0,0,Math.PI*2),o.fill(),o.fillStyle=`rgba(255,255,255,0.55)`;for(let[n,r]of[[e-30,t-4],[e+12,t+6],[e+28,t-8]])o.fillRect(n,r,5,1);o.fillStyle=`#4b8a45`;for(let[n,r]of[[e+20,t+3],[e-22,t+8]])o.beginPath(),o.ellipse(n,r,4,2.5,0,0,Math.PI*2),o.fill();o.fillStyle=`#f28fb0`,o.fillRect(e+19,t+2,2,1);break}case`orchard`:o.fillStyle=`rgba(106,75,53,0.55)`;for(let e=0;e<2;e++)o.fillRect(J(1),J((n?3.4:2.4)+e*4.4),J(12),6);n?c(s,0,J(2),J(1.4)):c(s,J(A.h-1.4),J(2),J(1.4));break;case`cafe`:o.fillStyle=`#8d8a82`,o.fillRect(J(2)-2,l-J(2)-2,J(10)+4,J(4)+4),Y(()=>e.drawFloor(o,`wood`,J(2),l-J(2),J(10),J(4),{seed:8})),n?c(s,0,J(2),l-J(2)):c(s,l+J(2),J(2),J(A.h)-l-J(2))}return a}function lr(){let e=J(6),t=J(5),[n,r]=er(e,t),i=e/2,a=t-2,o=J(2.9),s=J(1.75),c=a-7-s,l=(e,t,n,i)=>{r.beginPath();for(let a=0;a<8;a++){let o=Math.PI/8+a*Math.PI/4,s=e+Math.cos(o)*n,c=t+Math.sin(o)*i;a===0?r.moveTo(s,c):r.lineTo(s,c)}r.closePath()};r.fillStyle=`rgba(28,36,52,0.22)`,l(i+4,c+7+3,o+2,s+1),r.fill(),r.fillStyle=`#6f6a62`,l(i,c+7,o,s),r.fill(),r.fillRect(i-o*.92,c,o*1.84,7),r.fillStyle=`#9a948a`,r.fillRect(i-o*.92,c+1,o*1.84,4),r.fillStyle=`rgba(255,255,255,0.18)`;for(let e=Math.round(i-o*.9);e<i+o*.9;e+=9)r.fillRect(e,c+2,1,3);r.fillStyle=`#c9c3b6`,l(i,c,o,s),r.fill(),r.fillStyle=`#e4dfd4`,l(i,c-1,o-2,s-1.5),r.fill(),r.fillStyle=`#2f75a8`,l(i,c+1,o-6,s-5),r.fill(),r.fillStyle=`#3f8bc2`,l(i,c,o-8,s-7),r.fill(),r.fillStyle=`rgba(160,214,245,0.55)`,r.beginPath(),r.ellipse(i-o*.35,c-s*.3,o*.32,s*.18,0,0,Math.PI*2),r.fill();let u=c-3;r.fillStyle=`#7d776d`,r.fillRect(i-4,u-10,8,12),r.fillStyle=`#c9c3b6`,r.fillRect(i-4,u-10,3,12);let d=(e,t)=>{r.fillStyle=`#6f6a62`,r.beginPath(),r.ellipse(i,e+2,t,t*.34,0,0,Math.PI*2),r.fill(),r.fillStyle=`#d8d2c6`,r.beginPath(),r.ellipse(i,e,t,t*.32,0,0,Math.PI*2),r.fill(),r.fillStyle=`#4b9ad0`,r.beginPath(),r.ellipse(i,e,t-3,t*.32-2,0,0,Math.PI*2),r.fill()};return d(u-11,15),r.fillStyle=`#7d776d`,r.fillRect(i-2,u-24,4,13),r.fillStyle=`#c9c3b6`,r.fillRect(i-2,u-24,2,13),d(u-25,8),r.fillStyle=`#d8d2c6`,r.fillRect(i-1,u-30,3,5),r.fillStyle=`#f2a33a`,r.fillRect(i,u-32,1,2),{canvas:n,ax:Math.round(i),ay:a,water:{x:i,y:c,rx:o-8,ry:s-7},jet:{x:i,y:u-31}}}function ur(e){let[t,n]=er(24,16),i=r(e);n.fillStyle=`rgba(28,36,52,0.2)`,n.fillRect(3,13,20,2),n.fillStyle=`#7d7a73`,n.fillRect(2,7,20,7),n.fillStyle=`#b9b5aa`,n.fillRect(2,7,20,2),n.fillStyle=`#5b3c25`,n.fillRect(3,6,18,2);let a=[`#e8574a`,`#f2c94c`,`#f08bb0`,`#ffffff`,`#9b7be0`];for(let e=0;e<14;e++){let e=3+Math.floor(i()*18),t=1+Math.floor(i()*6);n.fillStyle=`#3f8550`,n.fillRect(e,t+1,1,2),n.fillStyle=a[Math.floor(i()*a.length)],n.fillRect(e,t,1,1)}return{canvas:t,ax:12,ay:14}}J(l.w+4+5),J(l.h+4+5);var dr=`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif`,fr=`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`,pr=.6,mr=1.05,hr=.85,gr=1200,_r=8,vr=6,yr=2,br=null;function xr(){if(br)return br;br=document.createElement(`canvas`),br.width=64,br.height=64;let e=br.getContext(`2d`),t=e.createRadialGradient(32,32,0,32,32,32);return t.addColorStop(0,`rgba(255,226,170,1)`),t.addColorStop(.4,`rgba(255,214,150,0.75)`),t.addColorStop(1,`rgba(255,214,150,0)`),e.fillStyle=t,e.fillRect(0,0,64,64),br}var Sr=class{canvas;art;camera;state;ctx;buildingsDrawn=[];charsDrawn=[];nb=0;nc=0;bPool=[];cPool=[];ents=[];ePool=[];cell=null;plaza=null;gardens=new Map;blocks=new Map;lotDecors=new Map;facades=new Map;appearances=new Map;anims=new Map;fountain=null;planters=new Map;req={appearance:null,dir:`down`,pose:`stand`,frame:0,held:`none`,seated:!1};lamps=[];ambient=oe(12);target=this.ambient;ambientAt=-1e9;lastNow=0;mode=``;hourOverride=ae(typeof location>`u`?``:location.search);night=0;widths=new Map;signBoxes=[];labelBoxes=[];lastFrameMs=0;fx=null;constructor(e,t,n,r){this.canvas=e,this.art=t,this.camera=n,this.state=r,this.ctx=e.getContext(`2d`,{alpha:!1})}blockInfo(e,t){let n=(e+32768)*65536+(t+32768),r=this.blocks.get(n);if(!r){this.blocks.size>600&&this.blocks.clear();let i={x:e,y:t},a=rt(i);r={bx:e,by:t,cell:it(i),lots:a,keys:a.map(B),decor:yt(i),plaza:te(i)},this.blocks.set(n,r)}return r}lotDecor(e,t,n){let r=n?`${t}|p`:t,i=this.lotDecors.get(r);return i||(this.lotDecors.size>2e3&&this.lotDecors.clear(),i=_t(e,n),this.lotDecors.set(r,i)),i}garden(e){let t=gt(e),n=nt(e),r=`${t}|${n?`n`:`s`}`,i=this.gardens.get(r);return i||this.gardens.set(r,i=cr(this.art,t,n,tt(e))),i}facadeOf(e){let t=e.agents,n=`${e.floors}|${e.state}|${e.theme}|${t?`${t.total},${t.working},${t.waiting}`:`-`}|${e.lot.x},${e.lot.y}`,r=this.facades.get(e.id);return(!r||r.sig!==n)&&(this.facades.size>4e3&&this.facades.clear(),r={sig:n,m:En(e,nt(e.lot)?`back`:`front`,tt(e.lot))},this.facades.set(e.id,r)),r.m}appearanceOf(e,t,r){let i=`${t}|${m(r)}`,a=this.appearances.get(e);return(!a||a.key!==i)&&(this.appearances.size>500&&this.appearances.clear(),a={key:i,a:this.art.appearanceFromSeed(n(e),{look:t,parts:r})},this.appearances.set(e,a)),a.a}animOf(e,t,n){let r=this.anims.get(e);return r||this.anims.set(e,r={pose:t,t:0}),r.pose===t?r.t+=n*1e3:(r.pose=t,r.t=0),r.t}forget(e){this.anims.delete(e)}updateAmbient(e,t){let n=Re(t),r=`${n}|${this.hourOverride??``}`;if(r!==this.mode||e-this.ambientAt>4e3){let t=this.mode===``;this.mode=r,this.ambientAt=e,this.target=oe(I(n,this.hourOverride,new Date)),t&&(this.ambient=this.target)}let i=Math.max(0,Math.min(250,e-this.lastNow));this.lastNow=e,this.ambient!==this.target&&(this.ambient=me(this.ambient,this.target,i/gr*3),le(this.ambient,this.target)<3&&(this.ambient=this.target)),this.night=this.ambient.night}map=null;lightMap(e,t){let n=Math.max(1,Math.ceil(e/yr)),r=Math.max(1,Math.ceil(t/yr));try{return this.map||=document.createElement(`canvas`),(this.map.width!==n||this.map.height!==r)&&(this.map.width=n,this.map.height=r),this.map}catch{return null}}frame(e,t,n,r,i){let a=performance.now(),{ctx:o,camera:s}=this;this.cell||=or(this.art),this.plaza||=sr(this.art),this.updateAmbient(e,n);let c=this.canvas.width,l=this.canvas.height;o.setTransform(1,0,0,1,0,0),o.imageSmoothingEnabled=!1,o.globalAlpha=1,o.globalCompositeOperation=`source-over`,o.fillStyle=`#5e7f52`,o.fillRect(0,0,c,l);let{scale:u,ox:d,oy:f}=s.transform();o.setTransform(u,0,0,u,d,f);let p=-d/u,m=-f/u,h=p+c/u,g=m+l/u,_=(e,t,n,r)=>e<h&&e+n>p&&t<g&&t+r>m,v=s.zoom>=pr,y=at({x0:p,y0:m,x1:h,y1:g}),b=this.ents;b.length=0;let x=0,S=(e,t,n)=>{let r=this.ePool[x];r?(r.k=e,r.y=t,r.ref=n):this.ePool[x]=r={k:e,y:t,ref:n},x++,b.push(r)};this.nb=0,this.lamps.length=0;let C=0;for(let e=y.by0;e<=y.by1;e++)for(let t=y.bx0;t<=y.bx1;t++){let n=this.blockInfo(t,e),r=n.cell;if(_(r.x,r.y,r.w,r.h+32)){o.drawImage(n.plaza?this.plaza:this.cell,r.x,r.y);for(let e of n.decor)(!e.small||v)&&_(e.x-24,e.y-56,48,60)&&(S(0,e.y,e),e.kind===`lamp`&&this.lamps.push(e.x,e.y));for(let e=0;e<n.lots.length;e++){let t=n.lots[e],r=ee(t),i=r.x*16,a=r.y*16;if(!_(i,a,224,192))continue;let s=this.state.buildingAt(t);s||o.drawImage(this.garden(t),i,a);for(let r of this.lotDecor(t,n.keys[e],!!s))(!r.small||v)&&_(r.x-24,r.y-56,48,60)&&S(0,r.y,r);if(s){let e=this.facadeOf(s),t=e.side===`back`,n=i+16,r=t?a:a+192-e.height;if(!_(n,r,H.w+H.shadow,e.height))continue;let o=null;Nn(e)?o=Mn(e):C<_r&&(C++,o=Mn(e));let c=this.bPool[this.nb];c||(this.bPool[this.nb]=c={b:s,m:e,s:o,x:n,y:r,depth:0}),c.b=s,c.m=e,c.s=o,c.x=n,c.y=r,c.depth=r+e.height,this.buildingsDrawn[this.nb]=c,this.nb++,S(1,c.depth,c)}}}}this.buildingsDrawn.length=this.nb,this.nc=0;for(let[n,r]of this.state.players){let i=hn(r.samples);r.delay=r.delay===void 0?i:gn(r.delay,i,t*1e3);let a=this.charVis(n,r,e-r.delay,t,_);a&&S(2,a.y,a)}if(r){let e=r.player,n=!e.moving&&this.onBench(e.x,e.y),i=n?`sit`:e.moving?e.running?`run`:`walk`:`stand`,a=this.takeChar(r.self.id,r.self.name,!0,e.x*16,e.y*16,n?`down`:e.dir,i,this.animOf(r.self.id,i,t),this.appearanceOf(r.self.id,r.self.look,r.self.parts));_(a.x-24,a.y-48,48,56)?S(2,a.y+.25,a):a.visible=!1}this.charsDrawn.length=this.nc,this.fx?.props?.({x0:p,y0:m,x1:h,y1:g},e=>S(3,e.y,e)),b.sort((e,t)=>e.y-t.y||e.k-t.k);for(let t of b)t.k===0?this.drawDecor(t.ref,e):t.k===1?this.drawBuilding(t.ref,e,i.building===t.ref.b.id):t.k===3?t.ref.draw(o,e):this.drawChar(t.ref,i.player===t.ref.id);let w=this.ambient;if(!z(w)){let e=this.lightMap(c,l);if(e){let t=e.getContext(`2d`),n=yr;t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation=`source-over`,t.globalAlpha=1,t.fillStyle=_e(w.outside),t.fillRect(0,0,e.width,e.height);let r=w.night;if(r>.02){t.setTransform(u/n,0,0,u/n,d/n,f/n),t.globalCompositeOperation=`lighten`,t.globalAlpha=Math.min(1,r*1.3);for(let e=0;e<this.nb;e++){let n=this.buildingsDrawn[e];n.s&&t.drawImage(n.s.glow,n.x,n.y)}let e=xr();t.globalAlpha=Math.min(1,r*1.1);for(let n=0;n<this.lamps.length;n+=2)t.drawImage(e,this.lamps[n]-52,this.lamps[n+1]-46,104,70)}if(o.save(),o.setTransform(1,0,0,1,0,0),o.globalCompositeOperation=`multiply`,o.imageSmoothingEnabled=!0,o.drawImage(e,0,0,e.width,e.height,0,0,e.width*n,e.height*n),o.restore(),r>.02){o.save(),o.globalCompositeOperation=`lighter`;let e=de(`#fff1c8`,24);o.globalAlpha=r*.85;for(let t=0;t<this.lamps.length;t+=2)o.drawImage(e,this.lamps[t]-12,this.lamps[t+1]-42);o.restore()}}}this.drawWaiting(e),this.fx?.world?.(o,e,{x0:p,y0:m,x1:h,y1:g}),this.overlay(e,n,i),this.lastFrameMs=performance.now()-a}takeChar(e,t,n,r,i,a,o,s,c){let l=this.cPool[this.nc];return l||(this.cPool[this.nc]=l={id:e,name:t,me:n,x:r,y:i,dir:a,pose:o,animT:s,appearance:c,bx:0,by:0,bw:0,bh:0,headY:0,visible:!0}),l.id=e,l.name=t,l.me=n,l.x=r,l.y=i,l.dir=a,l.pose=o,l.animT=s,l.appearance=c,l.visible=!0,this.charsDrawn[this.nc]=l,this.nc++,l}charVis(e,t,n,r,i){let a=_n(t.samples,n);if(!a)return null;let o=a.x*16,s=a.y*16;if(!i(o-24,s-48,48,56))return null;let c=!a.moving&&this.onBench(a.x,a.y),l=c?`sit`:a.moving?a.speed>4.6?`run`:`walk`:`stand`,u=c?`down`:fn[a.dir]??`down`;return this.takeChar(e,t.info.name,!1,o,s,u,l,this.animOf(e,l,r),this.appearanceOf(e,t.info.look,t.info.parts))}seatsNear(e,t,n=[]){n.length=0;let r=S(e,t);for(let e=r.y-1;e<=r.y+1;e++)for(let t=r.x-1;t<=r.x+1;t++){let r=this.blockInfo(t,e);for(let e of r.decor)e.seat&&n.push(e);for(let e=0;e<r.lots.length;e++){let t=r.lots[e];if(!this.state.buildingAt(t))for(let i of this.lotDecor(t,r.keys[e],!1))i.seat&&n.push(i)}}return n}seatScratch=[];onBench(e,t){for(let n of this.seatsNear(e,t,this.seatScratch))if(n.seat&&Math.abs(n.seat.x-e)<.5&&Math.abs(n.seat.y-t)<.5)return!0;return!1}drawDecor(e,t){let{ctx:n}=this;if(e.kind===`fountain`){let r=this.fountain??=lr(),i=Math.round(e.x-r.ax),a=Math.round(e.y-r.ay);n.drawImage(r.canvas,i,a),this.drawFountainWater(i,a,r,t);return}if(e.kind===`planter`){let t=this.planters.get(e.seed%5);t||this.planters.set(e.seed%5,t=ur(e.seed%5)),n.drawImage(t.canvas,Math.round(e.x-t.ax),Math.round(e.y-t.ay));return}let r=pe({kind:e.kind,x:e.x,y:e.y,seed:e.seed});n.drawImage(r.canvas,Math.round(e.x-r.ax),Math.round(e.y-r.ay))}drawFountainWater(e,t,n,r){let{ctx:i}=this,a=r/1e3,o=e+n.jet.x,s=t+n.jet.y;i.fillStyle=`rgba(220,240,255,0.95)`,i.fillRect(Math.round(o),Math.round(s-8),1,8);for(let e=0;e<14;e++){let t=(a*1.3+e/14)%1,n=o+(e%2?1:-1)*t*(6+e%3*2),r=s-8-Math.sin(t*Math.PI)*6+t*t*12;i.fillRect(Math.round(n),Math.round(r),1,1+e%2)}i.fillStyle=`rgba(200,232,252,0.7)`;for(let[r,o,s]of[[8,n.jet.y+7,12],[15,n.jet.y+20,14]])for(let c=-1;c<=1;c+=2){let l=e+n.jet.x+c*r;for(let e=0;e<3;e++){let n=(a*22+e*5)%s;i.fillRect(Math.round(l+n*.15*c),Math.round(t+o+n),1,2)}}let c=n.water;i.strokeStyle=`rgba(214,238,255,0.55)`,i.lineWidth=1;for(let n=0;n<2;n++){let r=(a*.45+n*.5)%1;i.globalAlpha=1-r,i.beginPath(),i.ellipse(e+c.x,t+c.y+2,10+r*(c.rx-10),3+r*(c.ry-3),0,0,Math.PI*2),i.stroke()}i.globalAlpha=1,i.fillStyle=`rgba(255,255,255,0.85)`;for(let n=0;n<7;n++){if((Math.floor(a*3)+n*2)%5!=0)continue;let r=n*.9+.3;i.fillRect(Math.round(e+c.x+Math.cos(r)*c.rx*.8),Math.round(t+c.y+Math.sin(r)*c.ry*.7),2,1)}}drawBuilding(e,t,n){let{ctx:r}=this;if(e.s)r.drawImage(e.s.canvas,e.x,e.y);else{let t=Cn[e.m.style];r.fillStyle=t.roof[0],r.fillRect(e.x,e.y,H.w,H.roof),r.fillStyle=t.wall[1],r.fillRect(e.x,e.y+H.roof,H.w,e.m.height-H.roof)}n&&(r.save(),r.globalCompositeOperation=`lighter`,r.globalAlpha=.08+Math.sin(t/260)*.03,r.fillStyle=`#ffffff`,r.fillRect(e.x,e.y,H.w,e.m.height),r.restore()),this.fx?.building?.(r,e,t)}drawWaiting(e){let{ctx:t}=this,n=.5+.5*Math.sin(e/420);if(!(n<.08)){t.save();for(let e=0;e<this.nb;e++){let r=this.buildingsDrawn[e];if(r.m.waiting.length)for(let e of r.m.waiting){let i=On(r.m,e);t.globalAlpha=.35+n*.6,t.fillStyle=`#ffb547`,t.fillRect(r.x+i.x,r.y+i.y,i.w,i.h),t.globalAlpha=n*.9,t.fillStyle=`#fff2c4`,t.fillRect(r.x+i.x+1,r.y+i.y+1,i.w-2,2)}}t.restore()}}drawChar(e,t){let{ctx:n}=this,r=Math.round(e.x),i=Math.round(e.y)-(e.pose===`sit`?vr:0);if(e.pose!==`sit`){let e=re();n.drawImage(e.canvas,r-e.ax,i-e.ay)}(t||e.me)&&(n.save(),n.strokeStyle=e.me?`rgba(124,200,255,0.85)`:`rgba(255,255,255,0.85)`,n.lineWidth=1,n.beginPath(),n.ellipse(r,i,8,3,0,0,Math.PI*2),n.stroke(),n.restore());let a=null;try{let t=this.req;t.appearance=e.appearance,t.dir=e.dir,t.pose=e.pose,t.seated=e.pose===`sit`;let n=Math.max(1,this.art.poseFrameCount(e.pose)||1),r=Math.max(30,this.art.poseFrameDuration(e.pose)||500);t.frame=Math.floor(e.animT/r)%n,a=this.art.characterSprite(t)}catch{a=null}if(a){let t=r-a.ax,o=i-a.ay;n.drawImage(a.canvas,t,o),e.bx=t+2,e.by=o+2,e.bw=a.canvas.width-4,e.bh=a.canvas.height-2,e.headY=o+2}else e.bx=r-7,e.by=i-26,e.bw=14,e.bh=26,e.headY=i-26}measure(e,t){let n=`${e}|${t}`,r=this.widths.get(n);return r===void 0&&(this.widths.size>3e3&&this.widths.clear(),this.ctx.font=e,r=this.ctx.measureText(t).width,this.widths.set(n,r)),r}fit(e,t,n){if(this.measure(e,t)<=n)return t;let r=0,i=t.length;for(;r<i;){let a=r+i+1>>1;this.measure(e,`${t.slice(0,a).trimEnd()}…`)<=n?r=a:i=a-1}return r>0?`${t.slice(0,r).trimEnd()}…`:``}overlay(e,n,r){let{ctx:i,camera:a}=this,o=a.dpr,s=a.transform(),c=s.scale/o,l=e=>e*c+s.ox/o,u=e=>e*c+s.oy/o;i.setTransform(o,0,0,o,0,0),i.textBaseline=`middle`,i.textAlign=`left`;let d=a.zoom;this.night;let f=this.signBoxes;if(f.length=0,d>=mr)for(let e=0;e<this.nb;e++){let t=this.buildingsDrawn[e],n=kn(t.m),r=l(t.x+n.x),a=u(t.y+n.y),o=n.w*c,s=n.h*c;if(s<9)continue;f.push(r,a,o,s);let d=Math.max(8,Math.min(13,s*.78)),p=`700 ${d.toFixed(1)}px ${dr}`,m=ze(t.b.owner.country),h=`❤️ ${t.b.likes}`,g=this.measure(p,h),_=m?this.measure(`${d.toFixed(1)}px ${fr}`,m)+4:0,v=this.fit(p,t.b.owner.name,Math.max(0,o-g-_-14)),y=t.b.state===`online`;i.globalAlpha=y?1:.7;let b=r+5,x=a+s/2+.5;m&&(i.font=`${d.toFixed(1)}px ${fr}`,i.fillText(m,b,x),b+=_),i.font=p,i.fillStyle=`rgba(10,14,24,0.55)`,i.fillText(v,b+.5,x+1),i.fillStyle=y?`#fff8e6`:`#c4c9d4`,i.fillText(v,b,x),i.fillStyle=y?`#ffe2e6`:`#c4c9d4`,i.fillText(h,r+o-g-5,x),i.globalAlpha=1}if(d>=hr){let e=`600 10.5px ${dr}`;i.font=e;let t=this.labelBoxes;t.length=0;for(let a=0;a<this.nc;a++){let o=this.charsDrawn[a];if(!o.visible||!o.me&&!n.showNames&&r.player!==o.id)continue;let s=this.fit(e,o.name,140),c=this.measure(e,s)+10,d=l(o.x),p=u(o.headY)-17;for(let e=0;e<f.length;e+=4){let t=f[e],n=f[e+1];d+c/2>t&&d-c/2<t+f[e+2]&&p+14>n&&p<n+f[e+3]&&(p=n-16)}for(let e=0;e<4;e++){let e=!1;for(let n=0;n<t.length;n+=4)d+c/2>t[n]&&d-c/2<t[n]+t[n+2]&&p+14>t[n+1]&&p<t[n+1]+t[n+3]&&(p=t[n+1]-16,e=!0);if(!e)break}t.push(d-c/2,p,c,14),i.globalAlpha=.92,i.fillStyle=o.me?`rgba(24,52,84,0.88)`:`rgba(18,21,29,0.78)`,i.beginPath(),i.roundRect(Math.round(d-c/2),Math.round(p),Math.round(c),14,4),i.fill(),o.me&&(i.strokeStyle=`rgba(124,200,255,0.9)`,i.lineWidth=1,i.stroke()),i.globalAlpha=1,i.fillStyle=o.me?`#d6efff`:`#e8ecf5`,i.textAlign=`center`,i.fillText(s,Math.round(d),Math.round(p)+7.5),i.textAlign=`left`}}if(r.door&&r.me&&d>=.7){let n=l(r.me.x*16)+12+7*Math.min(2,d),a=u(r.me.y*16)-20*Math.min(2.2,Math.max(.8,d)),o=Math.round(Math.sin(e/240)*2),s=t(`Entrar (E)`);i.font=`700 11px ${dr}`;let c=Math.ceil(i.measureText(s).width)+16,f=Math.round(n-10),p=Math.round(a-10+o);i.fillStyle=`rgba(18,21,29,0.86)`,i.strokeStyle=`rgba(255,214,140,0.9)`,i.lineWidth=1.5,i.beginPath(),i.roundRect(f,p,c,20,5),i.fill(),i.stroke(),i.fillStyle=`#ffe3a0`,i.fillText(s,f+8,p+10.5)}this.fx?.screen?.(i,e,{sx:l,sy:u,k:c,zoom:d})}static doorFront(e){return b(e).front}};function Cr(e,t){return!e?.me||!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)?`fresh`:Math.hypot(t.x-e.me.x,t.y-e.me.y)<=.6?`keep`:`snap`}var wr=2e4;function Tr(e){if(!e)return 0;let t=a.indexOf(e.label);return t<0?0:t+ +(e.progress>=e.target)}function Er(e){let n=e?.goal;if(!n||!(n.target>0))return null;let r=Math.max(0,Math.min(1,n.progress/n.target));return{pct:r,pctText:`${Math.floor(r*100)}%`,label:we(n.label,n.target),progressText:t(`{0} de {1} h`,[be(Math.floor(n.progress)),be(n.target)]),reached:Tr(n)}}function Dr(e){let n=e.slice(e.lastIndexOf(`:`)+1),r=a.indexOf(n);return r<0?null:{pct:1,pctText:`100%`,label:we(n),progressText:t(`Meta batida!`),reached:r+1}}function Or(e){return e?{tokens:e.tokensBand===void 0?t(`A soma aparece com 10 prédios ou mais.`):t(`A cidade consumiu ≈ {0} esta semana`,[Ce(e.tokensBand)]),lit:e.lit===1?t(`1 prédio aceso agora`):t(`{0} prédios acesos agora`,[be(e.lit)])}:null}function kr(e){let t=e.getMonth();return t===9?`halloween`:t===10||t===11?`christmas`:`party`}var Ar=E(T),jr=e=>(Ar.x+e)*16,X=e=>(Ar.y+e)*16,Z={goal:{x:jr(15.5),y:X(7.6)},hall:{x:jr(26.5),y:X(7.6)},w:84,h:52,posts:12},Mr={x:jr(y.x+y.w/2),y:X(y.y+y.h/2)},Nr=[[jr(12)+8,X(4)-30,jr(30)+8,X(4)-30],[jr(12)+8,X(19)-30,jr(30)+8,X(19)-30]],Pr=[`#ff5d73`,`#ffd166`,`#7cf3ff`,`#b28dff`,`#6dff9e`,`#ff9f43`,`#ffffff`,`#ff7ad9`],Fr=6,Ir=class{random;cap=2400;n=0;x=new Float32Array(this.cap);y=new Float32Array(this.cap);vx=new Float32Array(this.cap);vy=new Float32Array(this.cap);age=new Float32Array(this.cap);life=new Float32Array(this.cap);color=new Uint8Array(this.cap);rockets=[];flashes=[];confetti=new Te(500);until=0;nextLaunch=0;started=0;clock=0;constructor(e=Math.random){this.random=e}get active(){return this.n>0||this.rockets.length>0||this.confetti.count>0||this.flashes.length>0}showing(e){return e<this.until}start(e,t=wr){this.started=e,this.until=e+t,this.nextLaunch=e+700;for(let e=0;e<4;e++)this.launch((e+.5)/4);for(let e=0;e<40;e++)this.confetti.confettiFall(Mr.x+(this.random()-.5)*560,Mr.y-200-this.random()*80,260+this.random()*80)}stop(){this.until=0,this.n=0,this.rockets.length=0,this.flashes.length=0,this.confetti.clear()}launch(e=this.random()){let t=Mr.x+(e-.5)*520,n=Mr.y-170-this.random()*120;this.rockets.push({x:t,y:Mr.y-6,vx:(this.random()-.5)*30,vy:-(250+this.random()*60),burstY:n,color:Math.floor(this.random()*Pr.length)})}spark(e,t,n,r,i,a){if(this.n>=this.cap)return;let o=this.n++;this.x[o]=e,this.y[o]=t,this.vx[o]=n,this.vy[o]=r,this.age[o]=0,this.life[o]=i,this.color[o]=a}burst(e){let t=this.random(),n=70+Math.floor(this.random()*40),r=120+this.random()*60,i=(e.color+1+Math.floor(this.random()*(Pr.length-1)))%Pr.length;for(let a=0;a<n;a++){let o=a/n*Math.PI*2+this.random()*.15,s=t<.3?r:r*Math.sqrt(.15+this.random()*.85),c=Math.cos(o),l=Math.sin(o);if(t>.85){let e=o;c=16*Math.sin(e)**3/17,l=-(13*Math.cos(e)-5*Math.cos(2*e)-2*Math.cos(3*e)-Math.cos(4*e))/17,s=r*.9}this.spark(e.x,e.y,c*s,l*s,1.3+this.random()*.8,t>.85?0:a%4==0?i:e.color)}this.flashes.push({x:e.x,y:e.y,color:e.color,at:this.clock})}update(e,t){let n=Math.min(.1,Math.max(0,t));if(this.clock=e,e<this.until&&e>=this.nextLaunch){this.launch(),this.random()<.45&&this.launch();let t=(e-this.started)/Math.max(1,this.until-this.started);this.nextLaunch=e+(t>.85?120:300+this.random()*380)}for(let e=this.rockets.length-1;e>=0;e--){let t=this.rockets[e];t.x+=t.vx*n,t.y+=t.vy*n,t.vy+=70*n,this.spark(t.x+(this.random()-.5)*2,t.y+3,(this.random()-.5)*10,14+this.random()*12,.45,Fr),(t.y<=t.burstY||t.vy>=-30)&&(this.burst(t),this.rockets.splice(e,1))}for(let t=this.flashes.length-1;t>=0;t--)e-this.flashes[t].at>320&&this.flashes.splice(t,1);let r=0;for(;r<this.n;){if(this.age[r]+=n,this.age[r]>=this.life[r]){let e=--this.n;this.x[r]=this.x[e],this.y[r]=this.y[e],this.vx[r]=this.vx[e],this.vy[r]=this.vy[e],this.age[r]=this.age[e],this.life[r]=this.life[e],this.color[r]=this.color[e];continue}this.vx[r]*=Math.max(0,1-1.15*n),this.vy[r]=this.vy[r]*Math.max(0,1-1.15*n)+52*n,this.x[r]+=this.vx[r]*n,this.y[r]+=this.vy[r]*n,r++}this.confetti.update(n)}draw(e,t,n,r){if(!this.active)return;e.save();let i=.35+r*.65;e.globalCompositeOperation=`lighter`;for(let n of this.flashes){let r=(t-n.at)/320;if(r<0||r>1)continue;let a=18+r*40,o=e.createRadialGradient(n.x,n.y,0,n.x,n.y,a);o.addColorStop(0,`rgba(255,255,255,${(.55*(1-r)*i).toFixed(3)})`),o.addColorStop(.4,`${Pr[n.color]}${Math.round(90*(1-r)*i).toString(16).padStart(2,`0`)}`),o.addColorStop(1,`rgba(0,0,0,0)`),e.fillStyle=o,e.fillRect(n.x-a,n.y-a,a*2,a*2)}for(let t=0;t<this.n;t+=2)e.globalAlpha=(1-this.age[t]/this.life[t])*.22*i,e.fillStyle=Pr[this.color[t]%Pr.length],e.fillRect(Math.round(this.x[t])-1,Math.round(this.y[t])-1,4,4);e.globalCompositeOperation=`source-over`;for(let t of this.rockets)e.globalAlpha=1,e.fillStyle=`#fff4c8`,e.fillRect(Math.round(t.x),Math.round(t.y),2,3);for(let r=0;r<this.n;r++){let i=Math.round(this.x[r]),a=Math.round(this.y[r]);if(i<n.x0-4||i>n.x1+4||a<n.y0-4||a>n.y1+4)continue;let o=1-this.age[r]/this.life[r];if(o<.35&&Math.sin(t/35+r*1.7)<0)continue;e.globalAlpha=Math.min(1,o*1.8),e.fillStyle=o>.75?`#fffbe8`:Pr[this.color[r]%Pr.length];let s=o>.45?2:1;e.fillRect(i,a,s,s)}e.globalAlpha=1,this.confetti.draw(e,n.x0,n.y0,n.x1,n.y1,t),e.restore()}};function Lr(e,t,n,r){let i=Z.w,a=Z.h,o=Math.round(t-i/2),s=Math.round(n-Z.posts-a);e.fillStyle=`rgba(30,36,48,0.22)`,e.fillRect(o+4,n-2,i-4,3);for(let t of[o+8,o+i-11])e.fillStyle=`#3b2a1f`,e.fillRect(t,s+a-2,3,Z.posts+2),e.fillStyle=`#6b4a33`,e.fillRect(t,s+a-2,1,Z.posts+2);return e.fillStyle=`#2a1d16`,e.fillRect(o,s,i,a),e.fillStyle=`#8a5f3f`,e.fillRect(o+1,s+1,i-2,a-2),e.fillStyle=`#a8784f`,e.fillRect(o+1,s+1,i-2,1),e.fillStyle=`#1b2233`,e.fillRect(o+3,s+3,i-6,a-6),e.fillStyle=r,e.fillRect(o+3,s+3,i-6,8),e.fillStyle=`rgba(255,255,255,0.25)`,e.fillRect(o+3,s+3,i-6,1),{x:o+3,y:s+3,w:i-6,h:a-6}}function Rr(e,t,n){let r=Lr(e,Z.goal.x,Z.goal.y,`#c8443c`),i=r.x+6,a=r.y+13,o=r.y+r.h-7;e.fillStyle=`#0d1018`,e.fillRect(i-1,a-1,6,o-a+2),e.fillStyle=`#d8e4f0`,e.fillRect(i,a,4,o-a),e.fillStyle=`#0d1018`,e.fillRect(i-2,o-1,8,6),e.fillStyle=`#e8473f`,e.fillRect(i-1,o,6,4);let s=t?.pct??0,c=Math.round((o-a)*s);c>0&&(e.fillStyle=`#e8473f`,e.fillRect(i+1,o-c,2,c),e.fillStyle=`#ff9c74`,e.fillRect(i+1,o-c,1,c),Math.sin(n/300)>0&&(e.fillStyle=`#ffd7a0`,e.fillRect(i+1,o-c,2,1))),e.fillStyle=`#7d8aa3`;for(let t=1;t<4;t++)e.fillRect(i+5,Math.round(o-(o-a)*t/4),2,1);e.fillStyle=`#ffd166`,e.fillRect(i+6,a-1,4,3),e.fillStyle=`#c9a24a`,e.fillRect(i+5,a-1,1,6)}function zr(e,t){let n=Lr(e,Z.hall.x,Z.hall.y,`#2f6fa8`),r=n.x+4,i=n.y+15;e.fillStyle=`#c9c2b2`,e.fillRect(r,i+5,14,11),e.fillStyle=`#e8e2d4`,e.fillRect(r-1,i+3,16,2),e.fillRect(r+2,i+1,10,2),e.fillRect(r+5,i,4,1),e.fillStyle=t?`#ffd27a`:`#4a5468`;for(let t of[r+2,r+6,r+10])e.fillRect(t,i+7,2,4);e.fillStyle=`#8f8676`,e.fillRect(r-1,i+16,16,1)}function Br(){let e=e=>e-Z.posts-Z.h+3;return{goal:{x:Z.goal.x-Z.w/2+3,y:e(Z.goal.y),w:Z.w-6},hall:{x:Z.hall.x-Z.w/2+3,y:e(Z.hall.y),w:Z.w-6}}}function Vr(e,t,n,r,i){return{x:e+(n-e)*i,y:t+(r-t)*i+Math.sin(i*Math.PI)*14}}function Hr(e,t,n,r,i,a){e.fillStyle=`#4a3b2e`;for(let a=0;a<=120;a++){let o=Vr(t,n,r,i,a/120);e.fillRect(Math.round(o.x),Math.round(o.y),1,1)}for(let o=1;o<24;o++){let s=Vr(t,n,r,i,o/24),c=Math.round(s.x),l=Math.round(s.y),u=+(Math.sin(a/380+o*.9)>.4),d=F[o%F.length];e.fillStyle=`rgba(20,24,33,0.35)`,e.fillRect(c-2,l+2,7,1),e.fillStyle=d;for(let t=0;t<6;t++)e.fillRect(c-3+Math.floor(t/2)+(t>2?u:0),l+1+t,7-Math.floor(t/2)*2,1);e.fillStyle=`rgba(255,255,255,0.45)`,e.fillRect(c-3,l+1,7,1)}}function Ur(e,t,n,r,i,a,o){if(!(o<.15)){for(let s=0;s<24;s++){let c=Vr(t,n,r,i,(s+.5)/24),l=.55+.45*Math.sin(a/520+s*1.3);e.globalAlpha=o*l,e.fillStyle=s%3==0?`#ffd27a`:s%3==1?`#ff9db0`:`#9ae7ff`,e.fillRect(Math.round(c.x),Math.round(c.y),2,2),e.globalAlpha=o*l*.25,e.fillRect(Math.round(c.x)-2,Math.round(c.y)-2,6,6)}e.globalAlpha=1}}var Wr=new Map;function Gr(e,t,n,r){let i=Wr.get(t);if(!i){let{buf:e}=ue(t);i=document.createElement(`canvas`),i.width=e.w,i.height=e.h,i.getContext(`2d`).putImageData(new ImageData(e.data,e.w,e.h),0,0),Wr.set(t,i)}e.drawImage(i,Math.round(n-20),Math.round(r-60))}function Kr(e){let t=y,n=[[t.x-2.5,t.y+1.2],[t.x+t.w+2.5,t.y+1.2],[t.x-1.2,t.y+t.h+1.1],[t.x+t.w+1.2,t.y+t.h+1.1]],r=e===`halloween`?[`pumpkin`,`pumpkin`,`ghost`,`pumpkin`]:e===`christmas`?[`tree`,`tree`,`gift`,`gift`]:[`gift`,`gift`,`gift`,`gift`];return n.map(([e,t],n)=>({kind:r[n],x:jr(e),y:X(t)}))}var qr=62e3;function Jr(e,t,n,r){let i=ft(e.x,e.y,e=>{let r=t(e);return!!r&&r.id!==n},r);if(!i)return null;let a=t(i.lot);return a?{building:a,front:i.front,dist:Math.hypot(i.front.x-e.x,i.front.y-e.y)}:null}function Yr(e,t){let n=b(t.lot).front;return Math.hypot(n.x-e.x,n.y-e.y)}function Xr(e,t,n){let r=!!n&&e.id===n,i=t?Yr(t,e):1/0;return{canLike:!r&&i<=4.000000001,canKnock:!r&&e.knocks===!0&&i<=2.000000001,liked:e.likedByMe===!0,mine:r}}var Zr=class{at=new Map;wait(e,t){let n=this.at.get(e);return n===void 0?0:Math.max(0,n+qr-t)}take(e,t){return this.wait(e,t)>0?!1:(this.at.set(e,t),!0)}};function Qr(e,t){let n=(t-e.start)/900;if(n<0||n>=1)return null;if(e.broken)return{x:e.to.x+Math.sin(n*9)*3,y:e.to.y+n*n*26,scale:1,alpha:1-n};let r=1-(1-n)*(1-n),i=Math.sin(n*Math.PI)*26;return{x:e.from.x+(e.to.x-e.from.x)*r,y:e.from.y+(e.to.y-e.from.y)*r-i,scale:n<.15?.6+n/.15*.8:n>.8?1.4-(n-.8)/.2*.6:1.4,alpha:n>.9?(1-n)*10:1}}var $r=[`.11.11.`,`1211111`,`1111111`,`.11111.`,`..111..`,`...1...`],ei=/^HB-[2-9A-HJKMNP-TV-Z]{4}$/;function ti(e){let t=e.trim().toUpperCase().replace(/[\s_]+/g,``),n=`HB-${t.startsWith(`HB-`)?t.slice(3):t.startsWith(`HB`)&&t.length===6?t.slice(2):t}`;return ei.test(n)?n:null}var ni={out:320,wait:5e3,in:520},ri=class{phase=`idle`;since=0;landed=!1;get busy(){return this.phase!==`idle`}start(e){this.phase=`out`,this.since=e,this.landed=!1}arrived(){(this.phase===`out`||this.phase===`wait`)&&(this.landed=!0)}failed(){this.arrived()}tick(e){let t=!1;this.phase===`out`&&e-this.since>=ni.out&&(this.phase=`wait`,this.since=e),this.phase===`wait`&&(this.landed||e-this.since>=ni.wait)&&(t=!this.landed,this.phase=`in`,this.since=e),this.phase===`in`&&e-this.since>=ni.in&&(this.phase=`idle`);let n=e-this.since,r=this.phase===`out`?Math.min(1,n/ni.out):this.phase===`wait`?1:this.phase===`in`?Math.max(0,1-n/ni.in):0;return{phase:this.phase,dark:r,timedOut:t}}},ii=class{actions;el;input;error;goBtn;diceBtn;constructor(e){this.actions=e,this.input=N(`input`,{class:`ui-city-tp__input`,type:`text`,attrs:{placeholder:`HB-XXXX`,maxlength:9,autocomplete:`off`,autocapitalize:`characters`,spellcheck:`false`,"aria-label":t(`Código do prédio`)}}),this.goBtn=N(`button`,{class:`ui-city-tp__go`,type:`submit`,text:t(`Ir`),title:t(`Ir até a porta deste prédio`)}),this.diceBtn=N(`button`,{class:`ui-city-tp__dice`,type:`button`,title:t(`Visitar um prédio aleatório`),attrs:{"aria-label":t(`Visitar um prédio aleatório`)},on:{click:()=>this.actions.random()}},N(`span`,{text:`🎲`,attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-tp__dice-text`,text:t(`Aleatório`)})),this.error=N(`p`,{class:`ui-city-tp__error`,role:`alert`,hidden:!0});let n=N(`form`,{class:`ui-city-tp__form`,attrs:{"aria-label":t(`Ir para um prédio pelo código`)}},N(`span`,{class:`ui-city-tp__label`,text:t(`Ir para`),attrs:{"aria-hidden":`true`}}),this.input,this.goBtn);n.addEventListener(`submit`,e=>{e.preventDefault(),this.submit()}),this.input.addEventListener(`input`,()=>P(this.error,!0)),this.input.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&this.input.blur()}),this.el=N(`div`,{class:`ui-city-tp`},n,this.diceBtn,this.error)}showError(e){M(this.error,e),P(this.error,!1)}setBusy(e){this.goBtn.disabled=e,this.diceBtn.disabled=e}clear(){this.input.value=``,P(this.error,!0)}submit(){let e=ti(this.input.value);if(!e){this.showError(t(`O código tem o formato HB-XXXX (letras e números, sem 0, O, 1, I, L e U).`));return}this.input.value=e,this.input.blur(),this.actions.go(e)}};function ai(e){return e===void 0||e<=0?0:e>=4?4:e}function oi(e){return e===void 0?0:Math.max(0,Math.min(5,Math.floor(e)))}function si(e){return e.side===`front`?{x:H.w/2-34,y:e.height-H.ground+12,w:11,h:15}:{x:H.w/2-37,y:0,w:11,h:15}}function ci(e,t){if(!e||!t||typeof t!=`object`)return!1;let n=t;return typeof n.working!=`number`||typeof n.idle!=`number`?!1:n.working<e.working&&n.idle>e.idle}var li=[`#4fd18b`,`#b7e05a`,`#ffd24a`,`#ff9a3c`,`#ff4f8b`];function ui(e,t,n,r,i,a,o){let s=Math.round(t),c=Math.round(n);e.fillStyle=`#1b1f28`,e.fillRect(s,c,11,15),e.fillStyle=`#5d6577`,e.fillRect(s+1,c+1,9,13),e.fillStyle=`#7d8699`,e.fillRect(s+1,c+1,9,1),e.fillStyle=o?`#efe6c8`:`#9aa3b2`,e.fillRect(s+2,c+2,7,4);let l=-Math.PI*.9+r/5*Math.PI*.8+Math.sin(i/60)*.55*a;e.fillStyle=`#c23a3a`,e.fillRect(s+5+Math.round(Math.cos(l)*2.4),c+5+Math.round(Math.sin(l)*2.4),1,1),e.fillStyle=`#20242e`,e.fillRect(s+5,c+5,1,1);for(let t=0;t<5;t++){let n=2+t;e.fillStyle=o&&t<r?li[t]:`#2c313d`,e.fillRect(s+1+t*2,c+13-n,1,n)}}function di(e,t,n,r,i){if(r<=0||i<.05)return;let a=Math.round(t),o=Math.round(n);e.globalAlpha=Math.min(1,i*1.1);for(let t=0;t<r;t++){let n=2+t;e.fillStyle=li[t],e.fillRect(a+1+t*2,o+13-n,1,n)}e.globalAlpha=Math.min(.35,i*.35),e.fillStyle=li[r-1],e.fillRect(a-2,o+5,15,11),e.globalAlpha=1}var fi=[``,`#ffd9a0`,`#ffe9b8`,`#7cf3ff`,`#ff6bd6`];function pi(e,t,n,r,i,a,o,s){if(i<=0)return;let c=kn(r),l=Math.round(t+c.x),u=Math.round(n+c.y),d=fi[i];if(i<=2){e.globalAlpha=(i===1?.18:.32)*(.35+o*.65),e.fillStyle=d,e.fillRect(l-4,u-3,c.w+8,c.h+6),e.globalAlpha=(i===1?.12:.22)*(.35+o*.65),e.fillRect(l-8,u-6,c.w+16,c.h+12),e.globalAlpha=1;return}let f=(Math.floor(a/90)+s)%47==0?.35:1,p=i===4?.8+Math.sin(a/180+s)*.2:1;if(e.globalAlpha=(.55+o*.45)*f*p,e.fillStyle=d,e.fillRect(l-3,u-3,c.w+6,1),e.fillRect(l-3,u+c.h+2,c.w+6,1),e.fillRect(l-3,u-3,1,c.h+6),e.fillRect(l+c.w+2,u-3,1,c.h+6),e.globalAlpha=(.16+o*.3)*f*p,e.fillRect(l-6,u-6,c.w+12,c.h+12),e.globalAlpha=1,!(i<4)){for(let t=0;t<6;t++){let n=((a/700+t*.37+s*.13)%1+1)%1,r=(t+s)%4,i=r%2==0?l-3:l+c.w+2,o=r<2?u-3:u+c.h+2,f=i+(r%2==0?-1:1)*n*7,p=o-Math.sin(n*Math.PI)*6+n*n*8;e.globalAlpha=1-n,e.fillStyle=t%2?`#fff6b0`:d,e.fillRect(Math.round(f),Math.round(p),1,1)}e.globalAlpha=1}}var mi=`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif`,hi=`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`,gi=4e3,_i=1600,vi=1100,yi=1.05;function bi(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``))}var xi=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Si=(e,t)=>{let n=_(S(e.x,e.y)),r=_(S(t.x,t.y));return n.x===r.x&&n.y===r.y},Ci=e=>typeof e==`number`&&Number.isFinite(e),wi=class{o;el;wheel=new Pt;balloons=new jt;greetGate=new Mt(18,3300);likeGate=new Mt(9,400);teleportGate=new Mt(9,1500);reports={day:``,n:0};knocks=new Zr;hearts=[];bumps=new Map;wiggles=new Map;pops=[];fireworks=new Ir;confetti=new Te(500);fade=new ri;fadeEl;panel;dock;testBtn=null;dockKey=``;city=null;celebrating=null;replyTo=null;pending=null;snapCamera=!1;heldPos=null;lastNow=0;reported=new Set;blocked=new Set;extras={building:null,player:null};propsPool=[];onKeyDown=e=>this.onKey(e);constructor(e){this.o=e,this.fadeEl=N(`div`,{class:`ui-city-fade`,hidden:!0,attrs:{"aria-hidden":`true`}}),this.panel=new ii({go:e=>this.teleport(e),random:()=>this.teleport()}),this.dock=N(`div`,{class:`ui-city-dock`,role:`toolbar`,attrs:{"aria-label":t(`Ações perto de você`)}});let n=typeof location>`u`?null:new URLSearchParams(location.search);if(e.testFireworks&&n?.has(`fireworks`)){let n=e.testFireworks;this.testBtn=N(`button`,{class:`ui-city-testfw`,type:`button`,text:`🎆 ${t(`Testar os fogos`)}`,on:{click:()=>n()}})}this.el=N(`div`,{class:`ui-city-social`},this.dock,this.panel.el,this.wheel.el,this.fadeEl,this.testBtn),window.addEventListener(`keydown`,this.onKeyDown,!0)}helpItems(){return[N(`span`,{},N(`kbd`,{text:`L`}),` `,t(`curtir`)),N(`span`,{},N(`kbd`,{text:`G`}),` `,t(`cumprimentar`)),N(`span`,{},N(`kbd`,{text:`K`}),` `,t(`bater`))]}reset(){this.wheel.close(),this.balloons.clear(),this.hearts.length=0,this.bumps.clear(),this.wiggles.clear(),this.pops.length=0,this.fireworks.stop(),this.confetti.clear(),this.pending=null,this.replyTo=null,this.city=null,this.celebrating=null,this.blocked.clear(),this.snapCamera=!1,this.heldPos=null,this.fadeEl.hidden=!0,this.panel.setBusy(!1)}hide(){this.wheel.close()}escape(){return this.wheel.open?(this.wheel.close(),!0):!1}destroy(){window.removeEventListener(`keydown`,this.onKeyDown,!0),this.el.remove()}snapshot(e){this.city=e.city?D(e.city)??null:null}message(e,n){if(!xi(e)||typeof e.t!=`string`)return!1;let r=this.o.state();switch(e.t){case`greeting`:return this.onGreeting(e,n),!1;case`player.join`:return xi(e.player)&&typeof e.player.id==`string`&&this.blocked.delete(e.player.id),!1;case`like.update`:{let t=e.buildingId,i=typeof t==`string`?r.buildings.get(t):void 0;return i&&Ci(e.likes)&&e.likes>i.likes&&this.bumps.set(i.id,n),this.pending&&(this.pending.kind===`like`||this.pending.kind===`unlike`)&&this.pending.buildingId===t&&(this.pending=null),!1}case`area.patch`:return this.onPatch(e,r,n),!1;case`city`:{let t=D(e);return t&&(this.city=t),!1}case`city.fireworks`:{this.fireworks.start(n);let r=typeof e.goalId==`string`?Dr(e.goalId):null;return r&&(this.celebrating={goal:r,until:n+wr}),this.o.toast(r?`🎆 ${t(`A cidade bateu a meta da semana: {0}!`,[r.label])}`:`🎆 ${t(`A cidade bateu a meta da semana!`)}`),!1}case`pos`:return this.pending?.kind===`teleport`&&(this.pending=null,this.fade.arrived(),this.heldPos=e,!0);case`notice`:return typeof e.text==`string`&&this.onNotice(e.text,n);default:return!1}}onGreeting(e,n){let r=e.from,i=e.greetingId;if(typeof r!=`string`||!(i in Oe))return;let a=this.o.state().me?.id;if(this.balloons.add(r,i,n),r===a){this.pending?.kind===`greet`&&(this.pending=null);return}if(e.to===a&&a){this.replyTo={id:r,at:n,got:i};let e=this.o.state().players.get(r)?.info.name??t(`Alguém`);this.o.toast(t(`{0}: {1} {2} — G para responder`,[e,ke(i),Me(i)]))}}onPatch(e,t,n){if(Array.isArray(e.changes))for(let r of e.changes){if(!xi(r)||typeof r.id!=`string`)continue;let e=t.buildings.get(r.id);if(!e)continue;Ci(r.likes)&&r.likes>e.likes&&this.bumps.set(r.id,n),ci(e.agents,r.agents)&&this.celebrateShift(r.id,n);let i=xi(r.tokens)&&Ci(r.tokens.day)?r.tokens.day:void 0;i!==void 0&&i!==e.tokens?.day&&this.wiggles.set(r.id,{band:i,at:n})}}celebrateShift(e,t){let n=this.drawn(e);if(!n)return;let r=kn(n.m),i=n.x+r.x+r.w/2,a=n.y+r.y;this.confetti.confetti(i,a,40),this.confetti.sparkle(i,a-4,10),this.pops.push({x:i,y:a-6,at:t,text:`🎉`})}onNotice(e,n){let r=this.pending;if(!r||n-r.at>gi)return!1;let i=null;switch(r.kind){case`like`:case`unlike`:e===`too_far`?i=t(`Chegue mais perto da porta para curtir (até 4 passos).`):e===`daily_limit`?i=t(`Você já deu os 50 likes de hoje. Amanhã tem mais!`):e===`invalid`?i=t(`Não dá para curtir o próprio prédio.`):e===`not_found`?i=t(`Este prédio não está mais aqui.`):e===`rate_limited`&&(i=t(`Devagar com os likes: espere um pouquinho.`));break;case`knock`:e===`too_far`?i=t(`Chegue mais perto da porta para bater (até 2 passos).`):e===`rate_limited`?i=t(`Você bateu nesta porta há pouco. Espere um minuto.`):e===`not_found`&&(i=t(`Este prédio não está mais aqui.`));break;case`stamp`:e===`already_done`?i=t(`Você já deixou um carimbo aqui hoje.`):e===`too_far`?i=t(`Chegue mais perto da porta para carimbar.`):e===`not_found`&&(i=t(`Este prédio não está mais aqui.`));break;case`teleport`:e===`not_found`?i=r.code?t(`Nenhum prédio com o código {0}.`,[r.code]):t(`Nenhum prédio aceso para visitar agora.`):e===`rate_limited`&&(i=t(`Devagar: espere um pouco antes de ir para outro prédio.`)),i&&(this.fade.failed(),r.code&&this.panel.showError(i));break;case`greet`:e===`not_found`?i=t(`Essa pessoa não está mais por perto.`):e===`rate_limited`&&(i=t(`Devagar: um cumprimento a cada 3 segundos.`));break;case`block`:case`report`:if(e===(r.kind===`block`?`blocked_ok`:`reported`))return this.pending=null,!0;e===`daily_limit`?i=t(`Você já mandou as 5 denúncias de hoje.`):e===`not_found`&&(i=t(`Essa pessoa não está mais por perto.`))}return i?(this.pending=null,this.o.toast(i),!0):!1}send(e,t){this.o.send([e]),t&&(this.pending=t)}likeNearest(e){let n=this.o.me(),r=this.o.state();if(!n)return;let i=Jr(n,e=>r.buildingAt(e),r.myBuildingId,4);if(!i){this.o.toast(t(`Chegue perto da porta de um prédio (até 4 passos) e aperte L para curtir.`));return}this.toggleLike(i.building,e)}toggleLike(e,n){let r=this.o.me(),i=this.o.state();if(!r||e.id===i.myBuildingId||this.fade.busy)return;if(!Xr(e,r,i.myBuildingId).canLike){this.o.toast(t(`Chegue mais perto da porta para curtir (até 4 passos).`));return}if(!this.likeGate.take(n)){this.o.toast(t(`Devagar com os likes: espere um pouquinho.`));return}let a=!e.likedByMe;this.send({t:a?`like`:`unlike`,buildingId:e.id},{kind:a?`like`:`unlike`,at:n,buildingId:e.id});let o=this.drawn(e.id),s=o?this.likeSpot(o):{x:b(e.lot).front.x*16,y:b(e.lot).front.y*16-40};this.hearts.push({from:{x:r.x*16,y:r.y*16-30},to:s,start:n,...a?{}:{broken:!0}})}knockNearest(e){let n=this.o.me(),r=this.o.state();if(!n)return;let i=Jr(n,e=>r.buildingAt(e),r.myBuildingId,2);if(!i){this.o.toast(t(`Chegue a 2 passos da porta de um prédio e aperte K para bater.`));return}this.knock(i.building,e)}knock(e,n){let r=this.o.me();if(!r||this.fade.busy)return;let i=Xr(e,r,this.o.state().myBuildingId);if(!e.knocks){this.o.toast(t(`O dono deste prédio não recebe batidas na porta.`));return}if(!i.canKnock){this.o.toast(t(`Chegue mais perto da porta para bater (até 2 passos).`));return}if(!this.knocks.take(e.id,n)){this.o.toast(t(`Você bateu nesta porta há pouco. Espere um minuto.`));return}this.send({t:`knock`,buildingId:e.id},{kind:`knock`,at:n,buildingId:e.id});let a=this.drawn(e.id);if(a){let t=b(e.lot).front;this.pops.push({x:t.x*16,y:a.m.side===`front`?a.y+a.m.height-26:a.y+8,at:n,text:`✊`})}this.o.toast(`🚪 ${t(`Toc, toc! Você bateu na porta de {0}.`,[e.owner.name])}`)}openWheel(e,n){let r=this.o.me(),i=this.o.state();if(!r||this.fade.busy)return;let a=[];for(let[e,t]of i.players)!this.blocked.has(e)&&Si(r,t.info.pos)&&a.push({id:e,x:t.info.pos.x,y:t.info.pos.y});let o=this.replyTo&&e-this.replyTo.at<1e4?this.replyTo:null,s=n??(this.o.cards.kind===`player`?this.o.cards.id:null),c=n&&i.players.has(n)?n:At(r,a,{selected:s,replyTo:o?.id??null});if(!c){this.o.toast(t(`Ninguém por perto para cumprimentar.`));return}let l=i.players.get(c);if(!l)return;let u={id:c,name:l.info.name},d=this.toWindow(r.x*16,r.y*16-24),f=this.toWindow(l.info.pos.x*16,l.info.pos.y*16-24),p=o&&o.id===c?Nt(o.got):null;this.wheel.show(u,d,f,p,e=>this.greet(c,e,performance.now()))}greet(e,n,r){if(this.fade.busy)return;if(this.greetGate.wait(r)>0){this.o.toast(t(`Devagar: um cumprimento a cada 3 segundos.`));return}this.greetGate.take(r),this.send({t:`greet`,playerId:e,greetingId:n},{kind:`greet`,at:r,playerId:e});let i=this.o.state().me?.id;i&&this.balloons.add(i,n,r),this.replyTo?.id===e&&(this.replyTo=null)}teleport(e){let n=performance.now();if(this.o.me()&&!this.fade.busy){if(!this.teleportGate.take(n)){this.o.toast(t(`Devagar: espere um pouco antes de ir para outro prédio.`));return}this.wheel.close(),this.o.cards.hide(),this.send(e?{t:`teleport`,code:e}:{t:`teleport`},e?{kind:`teleport`,at:n,code:e}:{kind:`teleport`,at:n}),this.fade.start(n),this.panel.setBusy(!0)}}block(e,n,r){this.fade.busy||(this.send({t:`block`,playerId:e},{kind:`block`,at:r,playerId:e}),this.blocked.add(e),this.o.cards.hide(),this.o.toast(t(`{0} bloqueado. Para desfazer: Configurações › Habblaud World › Bloqueados.`,[n])))}report(e,n,r){if(this.fade.busy)return!1;let i=new Date().toISOString().slice(0,10);return this.reports.day!==i&&(this.reports={day:i,n:0}),this.reports.n>=5?(this.o.toast(t(`Você já mandou as 5 denúncias de hoje.`)),!1):(this.reports.n++,this.send({t:`report`,playerId:e,reason:n},{kind:`report`,at:r,playerId:e}),this.reported.add(e),this.o.toast(t(`Denúncia enviada. Obrigado: a moderação vai olhar.`)),!0)}onKey(e){if(!this.o.active())return;if(this.wheel.open){this.wheel.key(e)&&(e.preventDefault(),e.stopPropagation());return}if(e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||e.repeat||bi(e.target)||ce(e.target)||this.fade.busy)return;let t=performance.now();switch(e.key){case`l`:case`L`:e.preventDefault(),this.likeNearest(t);return;case`g`:case`G`:e.preventDefault(),this.openWheel(t);return;case`k`:case`K`:e.preventDefault(),this.knockNearest(t);return}}frame(e,n){this.lastNow=e,this.fireworks.update(e,n),this.confetti.update(n);for(let t=this.hearts.length-1;t>=0;t--){let n=this.hearts[t];if(e-n.start>1e3&&(this.hearts.splice(t,1),!n.broken)){let t=this.findAt(n.to);t&&this.bumps.set(t.b.id,e)}}for(let t=this.pops.length-1;t>=0;t--)e-this.pops[t].at>1300&&this.pops.splice(t,1);let r=this.fade.tick(e);if(this.heldPos&&r.phase!==`out`){let e=this.heldPos;this.heldPos=null,this.o.replay(e),this.snapCamera=!0}this.fadeEl.hidden=r.phase===`idle`,r.phase!==`idle`&&(this.fadeEl.style.opacity=r.dark.toFixed(3)),(r.phase===`idle`||r.phase===`in`)&&this.panel.setBusy(!1),r.timedOut&&(this.pending=null,this.o.toast(t(`O mundo não respondeu a tempo. Tente de novo.`))),this.snapCamera&&this.o.me()&&(this.snapCamera=!1,this.o.teleported(),this.panel.clear()),this.syncDock(e),this.extras.building?.sync(),this.extras.player?.sync()}syncDock(e){let n=this.o.me(),r=this.o.state(),i=null,a=null,o=!1;if(n){i=Jr(n,e=>r.buildingAt(e),r.myBuildingId,4)?.building??null;let e=Jr(n,e=>r.buildingAt(e),r.myBuildingId,2)?.building??null;a=e?.knocks?e:null;for(let e of r.players.values())if((e.info.pos.x-n.x)**2+(e.info.pos.y-n.y)**2<=144&&!this.blocked.has(e.info.id)&&Si(n,e.info.pos)){o=!0;break}}let s=`${i?.id??``}|${+!!i?.likedByMe}|${a?.id??``}|${+!!o}|${+!!this.wheel.open}`;if(s===this.dockKey)return;this.dockKey=s;let c=[],l=(e,t,n,r,i,a=``)=>N(`button`,{class:`ui-city-dock__btn ${a}`.trim(),type:`button`,title:r,attrs:{"aria-label":r,"aria-keyshortcuts":n},on:{click:i}},N(`span`,{class:`ui-city-dock__icon`,text:e,attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-dock__text`,text:t}),N(`kbd`,{text:n}));if(i){let e=i;c.push(e.likedByMe?l(`💔`,t(`Descurtir`),`L`,t(`Desfazer o like no prédio de {0}`,[e.owner.name]),()=>this.toggleLike(this.o.state().buildings.get(e.id)??e,performance.now()),`is-liked`):l(`❤️`,t(`Curtir`),`L`,t(`Curtir o prédio de {0}`,[e.owner.name]),()=>this.toggleLike(this.o.state().buildings.get(e.id)??e,performance.now()),`is-like`))}if(a){let e=a;c.push(l(`🚪`,t(`Bater`),`K`,t(`Bater na porta de {0}`,[e.owner.name]),()=>this.knock(this.o.state().buildings.get(e.id)??e,performance.now())))}o&&c.push(l(`👋`,t(`Cumprimentar`),`G`,t(`Cumprimentar quem está perto`),()=>this.openWheel(performance.now()))),this.dock.replaceChildren(...c),P(this.dock,!c.length)}cardExtras(e,t){return e===`building`?(this.extras.building||(this.extras.building=new Ti(this)),this.extras.building.bind(t),this.extras.building.el):(this.extras.player||(this.extras.player=new Ei(this)),this.extras.player.bind(t),this.extras.player.el)}get ctx(){return{state:this.o.state(),me:this.o.me(),reported:this.reported}}act={like:e=>this.toggleLike(e,performance.now()),knock:e=>this.knock(e,performance.now()),greet:e=>this.openWheel(performance.now(),e),block:(e,t)=>this.block(e,t,performance.now()),report:(e,t)=>this.report(e,t,performance.now())};drawn(e){for(let t of this.o.renderer().buildingsDrawn)if(t.b.id===e)return t}findAt(e){for(let t of this.o.renderer().buildingsDrawn)if(e.x>=t.x&&e.x<=t.x+192&&e.y>=t.y-4&&e.y<=t.y+t.m.height)return t}likeSpot(e){let t=kn(e.m);return{x:e.x+t.x+t.w-10,y:e.y+t.y+t.h/2}}goal(e){return this.celebrating&&e<this.celebrating.until?this.celebrating.goal:Er(this.city)}toWindow(e,t){let n=this.o.camera.worldToScreen(e,t),r=this.o.canvas.getBoundingClientRect();return{x:r.left+n.x,y:r.top+n.y}}building(e,t,n){let r=t.b.tokens?.day;if(r===void 0||!t.s)return;let i=si(t.m),a=this.wiggles.get(t.b.id),o=a?Math.max(0,1-(n-a.at)/_i):0;ui(e,t.x+i.x,t.y+i.y,oi(r),n,o,t.b.state===`online`)}props(e,t){let n=this.propsPool,r=0,i=(e,i)=>{let a=n[r];a||(n[r]=a={y:e,draw:i}),a.y=e,a.draw=i,r++,t(a)},a=(t,n,r,i)=>t<e.x1&&t+r>e.x0&&n<e.y1&&n+i>e.y0,o=Z.w,s=Z.h+Z.posts;if(a(Z.goal.x-o/2,Z.goal.y-s,o,s)&&i(Z.goal.y,(e,t)=>Rr(e,this.goal(t),t)),a(Z.hall.x-o/2,Z.hall.y-s,o,s)&&i(Z.hall.y,e=>zr(e,(this.city?.lit??0)>0)),!((this.goal(this.lastNow)?.reached??0)<1)){for(let[e,t,n,r]of Nr)a(e,t-4,n-e,30)&&i(t+40,(i,a)=>Hr(i,e,t,n,r,a));for(let e of Kr(kr(new Date)))a(e.x-20,e.y-60,40,64)&&i(e.y,t=>Gr(t,e.kind,e.x,e.y))}}world(e,t,n){let r=this.o.renderer(),i=r.night;e.save(),e.globalCompositeOperation=`lighter`;for(let n of r.buildingsDrawn){let r=n.b.tokens;if(!r||!n.s)continue;let a=n.b.state===`online`;if(a&&pi(e,n.x,n.y,n.m,ai(r.week),t,i,n.b.lot.x*7+n.b.lot.y*13&15),a){let t=si(n.m);di(e,n.x+t.x,n.y+t.y,oi(r.day),i)}}e.restore();for(let n of this.hearts){let r=Qr(n,t);r&&this.drawHeart(e,r.x,r.y,r.scale,r.alpha,n.broken===!0,i)}i>.15&&this.plazaLights(e,t,n,i),this.confetti.draw(e,n.x0,n.y0,n.x1,n.y1,t),this.fireworks.draw(e,t,n,i)}plazaLights(e,t,n,r){let i=(e,t,r,i)=>e<n.x1&&e+r>n.x0&&t<n.y1&&t+i>n.y0;e.save(),e.globalCompositeOperation=`lighter`;for(let[t,n]of[[Z.goal,`rgba(255,150,110,`],[Z.hall,`rgba(130,180,255,`]]){let a=t.x-Z.w/2+3,o=t.y-Z.posts-Z.h+3;i(a,o,Z.w,Z.h)&&(e.fillStyle=`${n}${(.16*r).toFixed(3)})`,e.fillRect(a,o,Z.w-6,Z.h-6),e.fillStyle=`${n}${(.07*r).toFixed(3)})`,e.fillRect(a-6,o-6,Z.w+6,Z.h+6))}if((this.goal(t)?.reached??0)>=1){for(let[n,a,o,s]of Nr)i(n,a-4,o-n,34)&&Ur(e,n,a,o,s,t,r);if(kr(new Date)===`halloween`)for(let n of Kr(`halloween`)){if(n.kind!==`pumpkin`||!i(n.x-20,n.y-30,40,40))continue;let a=.75+.25*Math.sin(t/90+n.x),o=e.createRadialGradient(n.x,n.y-10,0,n.x,n.y-10,18);o.addColorStop(0,`rgba(255,150,40,${(.32*r*a).toFixed(3)})`),o.addColorStop(1,`rgba(255,150,40,0)`),e.fillStyle=o,e.fillRect(n.x-18,n.y-28,36,36)}}e.restore()}drawHeart(e,t,n,r,i,a,o){let s=Math.max(1,Math.round(r*1.5))/1.5,c=Math.max(1,s),l=7*c,u=6*c,d=Math.round(t-l/2),f=Math.round(n-u/2);e.save(),e.globalAlpha=i,o>.2&&(e.globalCompositeOperation=`lighter`,e.fillStyle=`rgba(255,90,120,0.25)`,e.fillRect(d-3,f-3,l+6,u+6),e.globalCompositeOperation=`source-over`),$r.forEach((t,n)=>{for(let r=0;r<t.length;r++){let i=t[r];if(i===`.`)continue;let o=a&&r>=4?1:0;e.fillStyle=i===`2`?`#ffd1da`:a?`#9a6b78`:`#ff4f6d`,e.fillRect(d+r*c,f+(n+o)*c,c,c)}}),e.restore()}screen(e,t,n){let r=this.o.renderer();for(let i of r.buildingsDrawn){let r=kn(i.m),a=n.sx(i.x+r.x),o=n.sy(i.y+r.y),s=r.w*n.k,c=r.h*n.k;i.b.unverified===!0&&n.zoom>=1.05&&c>=9&&this.drawSeal(e,a-2,o+c/2);let l=this.bumps.get(i.b.id);if(l!==void 0){let r=(t-l)/vi;r>=1?this.bumps.delete(i.b.id):this.drawBump(e,a+s-12*n.k,o+c/2,r)}}for(let r of this.pops){let i=(t-r.at)/1300;i<0||i>=1||(e.globalAlpha=i>.7?(1-i)/.3:1,e.font=`${Math.round(14+6*Math.sin(Math.min(1,i*3)*Math.PI*.5))}px ${hi}`,e.textAlign=`center`,e.fillText(r.text,n.sx(r.x),n.sy(r.y)-i*18),e.textAlign=`left`,e.globalAlpha=1)}n.zoom>=yi&&this.drawBoardTexts(e,n);let i=this.o.state().me?.id,a=this.placed;a.length=0;let o=[];for(let e of r.charsDrawn){if(!e.visible)continue;let r=e.me?i:e.id;if(!r)continue;let a=this.balloons.get(r,t);if(!a)continue;let s=n.zoom>=.85?20:4;o.push({x:n.sx(e.x),y:n.sy(e.headY)-s,id:a.id,age:a.age,me:e.me})}o.sort((e,t)=>t.y-e.y);for(let t of o){let r=this.balloonWidth(e,t.id,n.zoom),i=t.y;for(let e=0;e<6;e++){let e=!1;for(let n=0;n<a.length;n+=4)t.x+r/2>a[n]&&t.x-r/2<a[n]+a[n+2]&&i>a[n+1]&&i-30<a[n+1]+a[n+3]&&(i=a[n+1]-2,e=!0);if(!e)break}a.push(t.x-r/2,i-30,r,30),this.drawBalloon(e,t.x,i,t.id,t.age,t.me,n.zoom)}}placed=[];balloonWidth(e,t,n){return n<.85?28:(e.font=`700 11.5px ${mi}`,Math.round(22+Math.min(170,e.measureText(Me(t)).width)+6+6))}drawSeal(e,t,n){e.save(),e.fillStyle=`rgba(20,24,33,0.85)`,e.strokeStyle=`rgba(200,206,220,0.8)`,e.lineWidth=1,e.beginPath(),e.arc(Math.round(t),Math.round(n),6,0,Math.PI*2),e.fill(),e.stroke(),e.fillStyle=`#c8cedc`,e.font=`800 9px ${mi}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`?`,Math.round(t),Math.round(n)+.5),e.restore()}drawBump(e,t,n,r){e.save(),e.globalAlpha=(1-r)*.9,e.strokeStyle=`#ff7b93`,e.lineWidth=2,e.beginPath(),e.arc(t,n,6+r*16,0,Math.PI*2),e.stroke(),e.globalAlpha=r<.8?1:(1-r)/.2,e.font=`800 12px ${mi}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillStyle=`rgba(10,14,24,0.6)`,e.fillText(`+❤`,t+.5,n-12-r*16+1),e.fillStyle=`#ffd1da`,e.fillText(`+❤`,t,n-12-r*16),e.restore()}drawBalloon(e,t,n,r,i,a,o){let s=Math.min(1,i/180),c=s<1?.6+.4*(1-(1-s)*(1-s))+Math.sin(s*Math.PI)*.08:1,l=i>4600?Math.max(0,1-(i-4600)/400):1,u=ke(r),d=o<.85?``:Me(r);e.save(),e.globalAlpha=l,e.translate(Math.round(t),Math.round(n)),e.scale(c,c),e.font=`700 11.5px ${mi}`;let f=d?Math.min(170,e.measureText(d).width):0,p=Math.round(22+(d?f+6:0)+6),m=-p/2;if(e.fillStyle=`rgba(10,14,24,0.35)`,e.beginPath(),e.roundRect(m+1,-27,p,22,9),e.fill(),e.fillStyle=a?`#e6f4ff`:`#fffaf0`,e.strokeStyle=a?`#7cc8ff`:`#2a2f3a`,e.lineWidth=1.5,e.beginPath(),e.roundRect(m,-29,p,22,9),e.fill(),e.stroke(),e.beginPath(),e.moveTo(-5,-8),e.lineTo(0,-1),e.lineTo(5,-8),e.closePath(),e.fill(),e.beginPath(),e.moveTo(-5,-7),e.lineTo(0,-1),e.lineTo(5,-7),e.stroke(),e.fillStyle=a?`#e6f4ff`:`#fffaf0`,e.fillRect(-4,-9,8,2),e.textBaseline=`middle`,e.textAlign=`left`,e.font=`14px ${hi}`,e.fillText(u,m+6,-17),d){e.font=`700 11.5px ${mi}`,e.fillStyle=`#1b2030`;let t=d;for(;t.length>1&&e.measureText(t).width>170;)t=`${t.slice(0,-2).trimEnd()}…`;e.fillText(t,m+26,-17.5)}e.restore()}drawBoardTexts(e,n){let r=Br(),i=n.k,a=this.goal(this.lastNow),o=Or(this.city),s=(t,n,r,i,a,o,s=700,c=`left`)=>{e.font=`${s} ${a.toFixed(1)}px ${mi}`;let l=t;for(;l.length>1&&e.measureText(l).width>i;)l=`${l.slice(0,-2).trimEnd()}…`;e.textAlign=c,e.fillStyle=`rgba(5,8,14,0.6)`,e.fillText(l,n+.5,r+1),e.fillStyle=o,e.fillText(l,n,r)},c=(t,n,r,i=600)=>{e.font=`${i} ${r.toFixed(1)}px ${mi}`;let a=[],o=``;for(let r of t.split(` `)){let t=o?`${o} ${r}`:r;e.measureText(t).width<=n||!o?o=t:(a.push(o),o=r)}return o&&a.push(o),a};e.save(),e.textBaseline=`middle`;let l=Math.max(7,Math.min(11,4.2*i)),u=l*1.18;{let e=r.goal,o=n.sx(e.x),d=n.sy(e.y),f=e.w*i;s(t(`META DA CIDADE`),o+f/2,d+4*i,f-4,Math.max(7,Math.min(11,4.6*i)),`#fff1e0`,800,`center`);let p=o+16*i,m=f-19*i;if(a){let e=Math.max(10,Math.min(24,9.5*i));s(a.pctText,p,d+17*i,m,e,a.pct>=1?`#ffd166`:`#ff9c74`,800);let t=d+17*i+e*.75+u*.5;for(let e of c(a.label,m,l).slice(0,2))s(e,p,t,m,l,`#d6dcea`,600),t+=u;s(a.progressText,p,t,m,l*.92,`#9aa4b8`,600)}else{let e=d+17*i;for(let n of c(t(`A meta aparece com 10 prédios acesos.`),m,l).slice(0,4))s(n,p,e,m,l,`#9aa4b8`,600),e+=u}}{let e=r.hall,a=n.sx(e.x),d=n.sy(e.y),f=e.w*i;s(t(`PREFEITURA`),a+f/2,d+4*i,f-4,Math.max(7,Math.min(11,4.6*i)),`#e3f1ff`,800,`center`);let p=a+23*i,m=f-26*i;if(o){let e=d+15*i;for(let t of c(o.lit,m,l,700).slice(0,2))s(t,p,e,m,l,`#ffd27a`,700),e+=u;e+=u*.3;for(let t of c(o.tokens,m,l).slice(0,4))s(t,p,e,m,l,`#d6dcea`,600),e+=u}}e.restore()}},Ti=class{s;el;likeBtn;knockBtn;hint;code;seal;id=``;key=``;constructor(e){this.s=e,this.likeBtn=N(`button`,{class:`ui-city-x__btn`,type:`button`,on:{click:()=>this.like()}}),this.knockBtn=N(`button`,{class:`ui-city-x__btn`,type:`button`,on:{click:()=>this.knock()}},N(`span`,{text:`🚪`,attrs:{"aria-hidden":`true`}}),` ${t(`Bater`)}`),this.hint=N(`span`,{class:`ui-city-x__hint`}),this.code=N(`span`,{class:`ui-city-x__code`,title:t(`Código do prédio: "Ir para", no minimapa, leva até a porta`)}),this.seal=N(`div`,{class:`ui-city-x__seal`,text:`❔ ${t(`Não verificado: os dados deste prédio estão em revisão.`)}`}),this.el=N(`div`,{class:`ui-city-x`},N(`div`,{class:`ui-city-x__row`},this.likeBtn,this.knockBtn,this.code),this.hint,this.seal)}bind(e){this.id=e,this.key=``,this.sync()}building(){return this.s.ctx.state.buildings.get(this.id)}sync(){let e=this.building();if(!e||!this.el.isConnected)return;let{me:n,state:r}=this.s.ctx,i=Xr(e,n,r.myBuildingId),a=`${e.id}|${i.canLike}|${i.canKnock}|${i.liked}|${i.mine}|${+!!e.knocks}|${e.code??``}|${+!!e.unverified}`;if(a===this.key)return;this.key=a,P(this.likeBtn,i.mine),this.likeBtn.replaceChildren(N(`span`,{text:i.liked?`💔`:`❤️`,attrs:{"aria-hidden":`true`}}),` ${i.liked?t(`Descurtir`):t(`Curtir`)}`),this.likeBtn.classList.toggle(`is-liked`,i.liked),this.likeBtn.disabled=!i.canLike,P(this.knockBtn,i.mine||!e.knocks),this.knockBtn.disabled=!i.canKnock,M(this.code,e.code??``),P(this.code,!e.code);let o=i.mine?t(`Seu prédio: os likes de hoje aparecem na barra do escritório.`):i.canLike?e.knocks&&!i.canKnock?t(`Mais perto da porta, dá para bater (K).`):``:t(`Chegue perto da porta para curtir (L).`);M(this.hint,o),P(this.hint,!o),P(this.seal,e.unverified!==!0)}like(){let e=this.building();e&&this.s.act.like(e)}knock(){let e=this.building();e&&this.s.act.knock(e)}},Ei=class{s;el;greetBtn;blockBtn;reportBtn;reasons;done;id=``;confirming=!1;constructor(e){this.s=e,this.greetBtn=N(`button`,{class:`ui-city-x__btn is-primary`,type:`button`,on:{click:()=>this.s.act.greet(this.id)}},N(`span`,{text:`👋`,attrs:{"aria-hidden":`true`}}),` ${t(`Cumprimentar`)}`,N(`kbd`,{text:`G`})),this.blockBtn=N(`button`,{class:`ui-city-x__btn is-quiet`,type:`button`,on:{click:()=>this.block()}}),this.reportBtn=N(`button`,{class:`ui-city-x__btn is-quiet`,type:`button`,attrs:{"aria-expanded":`false`},on:{click:()=>this.toggleReasons()}}),this.reasons=N(`div`,{class:`ui-city-x__reasons`,hidden:!0,role:`group`,attrs:{"aria-label":t(`Motivo da denúncia`)}},N(`span`,{class:`ui-city-x__hint`,text:t(`Qual o motivo?`)}),...s.map(e=>N(`button`,{class:`ui-city-x__reason`,type:`button`,text:Se(e),on:{click:()=>this.report(e)}}))),this.done=N(`div`,{class:`ui-city-x__done`,hidden:!0,text:`✓ ${t(`Denúncia enviada.`)}`}),this.el=N(`div`,{class:`ui-city-x`},N(`div`,{class:`ui-city-x__row`},this.greetBtn,this.blockBtn,this.reportBtn),this.reasons,this.done)}bind(e){e!==this.id&&(this.confirming=!1,P(this.reasons,!0)),this.id=e,this.sync()}sync(){if(!this.el.isConnected)return;let e=this.s.ctx.reported.has(this.id);M(this.blockBtn,this.confirming?`🚫 ${t(`Confirmar: bloquear`)}`:`🚫 ${t(`Bloquear`)}`),this.blockBtn.classList.toggle(`is-danger`,this.confirming),this.blockBtn.title=t(`Vocês deixam de se ver: na rua, nos prédios, nos cumprimentos e nos carimbos.`),M(this.reportBtn,e?`✓ ${t(`Denunciado`)}`:`⚑ ${t(`Denunciar`)}`),this.reportBtn.disabled=e,P(this.done,!e),e&&P(this.reasons,!0)}block(){if(!this.confirming){this.confirming=!0,this.sync();return}this.confirming=!1;let e=this.s.ctx.state.players.get(this.id)?.info.name??``;this.s.act.block(this.id,e)}toggleReasons(){let e=this.reasons.hidden;P(this.reasons,!e),this.reportBtn.setAttribute(`aria-expanded`,String(e))}report(e){this.s.act.report(this.id,e)&&this.sync()}};function Q(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var $=e=>typeof e==`number`&&Number.isFinite(e);function Di(e){return Q(e)&&typeof e.id==`string`&&Q(e.lot)&&$(e.lot.x)&&$(e.lot.y)&&Q(e.owner)&&typeof e.owner.name==`string`}function Oi(e){return Q(e)&&typeof e.id==`string`&&typeof e.name==`string`&&Q(e.pos)&&$(e.pos.x)&&$(e.pos.y)}function ki(e){if(!Q(e)||!$(e.x)||!$(e.y))return null;let t=e.dir===`n`||e.dir===`s`||e.dir===`e`||e.dir===`w`?e.dir:`s`;return{x:e.x,y:e.y,dir:t,moving:e.moving===!0}}function Ai(e){return Q(e)&&typeof e.id==`string`&&$(e.rev)&&Q(e.detail)&&Di(e.detail.building)&&Array.isArray(e.detail.floors)}var ji=e=>Q(e)&&$(e.x)&&$(e.y)&&$(e.lit),Mi=class{me=null;startPos=null;myBuildingId=null;connected=!1;afk=!1;inside=null;district;buildings=new Map;lots=new Map;chunkIds=new Map;chunkRev=new Map;players=new Map;minimap=[];version=0;minimapVersion=0;buildingAt(e){let t=this.lots.get(B(e));return t?this.buildings.get(t):void 0}myBuilding(){return this.myBuildingId?this.buildings.get(this.myBuildingId):void 0}applySnapshot(e,t){this.buildings.clear(),this.lots.clear(),this.chunkIds.clear(),this.chunkRev.clear(),this.players.clear(),this.connected=e.connected!==!1,this.afk=e.afk===!0,this.inside=Ai(e.inside)?structuredClone(e.inside):null,this.district=typeof e.district==`string`?e.district:void 0,e.me&&(this.me=e.me,this.myBuildingId=e.me.buildingId??e.me.id);let n=ki(e.pos);n&&(this.startPos={x:n.x,y:n.y});for(let t of Array.isArray(e.chunks)?e.chunks:[])Q(t)&&typeof t.chunk==`string`&&Array.isArray(t.buildings)&&this.applyArea(t.chunk,$(t.rev)?t.rev:0,t.buildings.filter(Di));for(let n of Array.isArray(e.players)?e.players:[])Oi(n)&&this.join(n,t);this.minimap=[],Array.isArray(e.minimap)&&this.setMinimap(e.minimap.filter(ji)),this.minimapVersion++,this.version++}apply(e,t){if(!Q(e)||typeof e.t!=`string`)return null;switch(e.t){case`area`:return typeof e.chunk==`string`&&Array.isArray(e.buildings)&&(this.applyArea(e.chunk,$(e.rev)?e.rev:0,e.buildings.filter(Di)),this.version++),null;case`area.patch`:return typeof e.chunk==`string`&&this.applyPatch(e.chunk,e),null;case`players`:if(Array.isArray(e.players))for(let n of e.players){if(!Q(n)||typeof n.id!=`string`||n.id===this.me?.id)continue;let e=this.players.get(n.id),r=ki(n.pos);e&&r&&(e.info.pos=r,Q(n.greeting)&&(e.info.greeting=n.greeting),mn(e.samples,{t,...r}))}return null;case`player.join`:return Oi(e.player)&&this.join(e.player,t),null;case`player.leave`:return typeof e.id==`string`&&this.players.delete(e.id),null;case`profile`:if(Oi(e.player)){let t=this.players.get(e.player.id);return t&&(t.info={...t.info,...e.player,pos:t.info.pos}),{type:`profile`,player:e.player}}return null;case`minimap`:return Array.isArray(e.blocks)&&(this.setMinimap(e.blocks.filter(ji)),this.minimapVersion++),null;case`like.update`:{let t=typeof e.buildingId==`string`?this.buildings.get(e.buildingId):void 0;return t&&$(e.likes)&&(t.likes=e.likes,t.likedByMe=e.likedByMe===!0,this.version++),null}case`pos`:return $(e.x)&&$(e.y)?{type:`pos`,x:e.x,y:e.y}:null;case`afk`:return this.afk=!0,{type:`afk`};case`notice`:return typeof e.text==`string`?{type:`notice`,level:e.level===`warn`||e.level===`error`?e.level:`info`,text:e.text}:null;case`building`:{let t=e.detail;return!$(e.rev)||!Q(t)||!Di(t.building)||!Array.isArray(t.floors)?null:{type:`building`,inside:{id:t.building.id,rev:e.rev,detail:{building:t.building,floors:t.floors,visitors:$(t.visitors)?t.visitors:0}}}}case`building.patch`:return $(e.rev)?{type:`building.patch`,msg:e}:null;default:return null}}keepAround(e,t){let n=this.district;if(n===void 0){for(let e of this.chunkIds.keys())if(n=x(e)?.district,n!==void 0)break}if(n===void 0)return!1;let r=n,i=new Set(w(_(S(e,t))).map(e=>k(r,e))),a=!1;for(let[e,t]of[...this.chunkIds])if(!i.has(e)){for(let e of t)this.removeBuilding(e);this.chunkIds.delete(e),this.chunkRev.delete(e),a=!0}return a&&this.version++,a}join(e,t){if(e.id===this.me?.id)return;let n=this.players.get(e.id),r=n?.samples??[];mn(r,{t,...ki(e.pos)}),this.players.set(e.id,{info:{...e},samples:r,...n?.delay===void 0?{}:{delay:n.delay}})}setMinimap(e){this.minimap=e.map(e=>({x:Math.floor(e.x),y:Math.floor(e.y),lit:Math.max(0,Math.floor(e.lit))}))}putBuilding(e,t){let n=this.buildings.get(e.id);n&&B(n.lot)!==B(e.lot)&&this.lots.get(B(n.lot))===e.id&&this.lots.delete(B(n.lot)),this.buildings.set(e.id,e),this.lots.set(B(e.lot),e.id);for(let[n,r]of this.chunkIds)n!==t&&r.delete(e.id);let r=this.chunkIds.get(t);r||this.chunkIds.set(t,r=new Set),r.add(e.id)}removeBuilding(e){let t=this.buildings.get(e);if(t){this.lots.get(B(t.lot))===e&&this.lots.delete(B(t.lot)),this.buildings.delete(e);for(let t of this.chunkIds.values())t.delete(e)}}applyArea(e,t,n){let r=new Set(n.map(e=>e.id));for(let t of this.chunkIds.get(e)??[])r.has(t)||this.removeBuilding(t);this.chunkIds.set(e,new Set),this.chunkRev.set(e,t);for(let t of n)this.putBuilding({...t},e)}applyPatch(e,t){$(t.rev)&&this.chunkRev.set(e,t.rev);for(let n of Array.isArray(t.changes)?t.changes:[]){if(!Q(n)||typeof n.id!=`string`)continue;if(n.lot!==void 0){Di(n)&&this.putBuilding({...n},e);continue}let t=this.buildings.get(n.id);t&&this.putBuilding({...t,...n},e)}if(Array.isArray(t.removed))for(let e of t.removed)typeof e==`string`&&this.removeBuilding(e);this.version++}},Ni=se,Pi=.28,Fi=[.375,.5,.75],Ii=3e4,Li=2,Ri=5e3,zi=class extends Ae{levels(){let e=new Set(super.levels());for(let t of Fi)t>=this.minZoom-1e-6&&e.add(t);return e.add(this.minZoom),[...e].sort((e,t)=>e-t)}};function Bi(e){let n=new zi;n.minZoom=Pi,n.bounds={x:-1e7,y:-1e7,w:2e7,h:2e7};let r=new Mi,i=new Sr(e.canvas,Ni,n,r),a=null,s=null,c=null,l=!0,u=!1,f=0,p=0,m=null,h=null,g=``,v=null,y=null,x=!1,C=!1,w,T=null,E=!1,ee=new fe(ct({x:0,y:0,w:4,h:4}).grid),D=[],O=[],k=null,A=new Ke({showBuilding:e=>oe(e),topInset:()=>e.topInset(),enter:e=>ce(e),extras:(e,t)=>k?.cardExtras(e,t)??null}),te=new wt(e=>{l=!1;let t=n.zoom,r=n.centerFor(e.x*16,e.y*16,t);n.animateTo(r.x,r.y,t,Date.now(),380)}),j=N(`div`,{class:`ui-city-toast`,role:`status`,attrs:{"aria-live":`polite`},hidden:!0}),M=N(`div`,{class:`ui-city-loading`,text:t(`Entrando na cidade…`)}),P=N(`div`,{class:`ui-city-help`,attrs:{"aria-hidden":`true`}},N(`span`,{},N(`kbd`,{text:`WASD`}),` `,t(`andar`)),N(`span`,{},N(`kbd`,{text:`Shift`}),` `,t(`correr`)),N(`span`,{},N(`kbd`,{text:t(`clique`)}),` `,t(`ir até lá`)),N(`span`,{},N(`kbd`,{text:`E`}),` `,t(`entrar`)),N(`span`,{},N(`kbd`,{text:`Esc`}),` `,t(`escritório`))),F=N(`div`,{class:`ui-city`,hidden:!0},A.el,te.el,P,j,M);e.uiRoot.append(F),k=new wi({state:()=>r,renderer:()=>i,camera:n,canvas:e.canvas,send:e=>a?.send(e),me:()=>s?{x:s.x,y:s.y}:null,cards:A,toast:e=>L(e),active:()=>u,teleported:()=>{if(!s)return;l=!0,n.stop();let e=n.centerFor(s.x*16,s.y*16-12,n.zoom);n.x=e.x,n.y=e.y,g=``},replay:e=>{let t=r.apply(e,performance.now());t&&se(t)},testFireworks:()=>a?.celebrate?.()}),F.append(k.el),P.append(...k.helpItems());let I=null,L=e=>{j.textContent=e,j.hidden=!1,j.classList.remove(`is-in`),j.offsetWidth,j.classList.add(`is-in`),I&&clearTimeout(I),I=setTimeout(()=>j.hidden=!0,2600)},R=()=>{let t=Math.max(1,Math.min(3,window.devicePixelRatio||1)),r=e.canvas.clientWidth||window.innerWidth,i=e.canvas.clientHeight||window.innerHeight,a=Math.floor(r*t),o=Math.floor(i*t);(e.canvas.width!==a||e.canvas.height!==o)&&(e.canvas.width=a,e.canvas.height=o),n.setView(r,i,t),n.insets={top:e.topInset(),right:0,bottom:0,left:0}},ne=()=>{let e=r.me,t=r.startPos;if(!e||s||!t)return;if(r.startPos=null,!dt(t.x,t.y)){let e=ut(t.x,t.y);e&&(t={x:e.x+.5,y:e.y+.5})}s=new yn(t.x,t.y),c=new Sn(e=>a?.send([e])),l=!0;let i=n.zoom,o=n.centerFor(s.x*16,s.y*16-12,i);n.stop(),n.x=o.x,n.y=o.y,M.hidden=!0},re=()=>{if(!s)return;l=!0;let e=n.centerFor(s.x*16,s.y*16-12,n.zoom);n.stop(),n.x=e.x,n.y=e.y},ie=()=>{x=!1;let e=r.startPos;if(!e){C=!0;return}let t=Cr(y,e);if(y=null,t===`keep`){r.startPos=null,c?.reset();return}s=null,c=null},ae=(e,t,n)=>{if(!s)return!1;let r={x:e,y:t};if(!dt(e,t)){let n=ut(e,t,6);if(!n)return!1;r={x:n.x+.5,y:n.y+.5}}let i=ct(lt(s,r));ee.setGrid(i.grid);let a=Math.floor(s.x)-i.ox,o=Math.floor(s.y)-i.oy,c=Math.floor(r.x)-i.ox,u=Math.floor(r.y)-i.oy,d=[];return ee.find(a,o,c,u,d)?(s.follow(bn(d,i.ox,i.oy,r),n),l=!0,!0):!1},oe=e=>{let t=r.buildings.get(e);if(!t)return;l=!1;let i=b(t.lot),a=Math.max(n.zoom,1.5),o=n.centerFor(i.front.x*16,i.front.y*16-60,a);n.animateTo(o.x,o.y,a,Date.now(),420)},se=e=>{switch(e.type){case`building`:ue(e.inside);break;case`building.patch`:v?.patch(e.msg);break;case`pos`:if(v&&de(),s&&C){C=!1;let t=Cr(y,e);y=null,t!==`keep`&&(s.correct(e.x,e.y),re()),c?.reset()}else s?(s.correct(e.x,e.y),c?.reset()):(r.startPos={x:e.x,y:e.y},ne(),le());break;case`afk`:break;case`profile`:if(A.kind===`player`&&A.id===e.player.id){let t=r.players.get(e.player.id),n=t?t.info:e.player;A.showPlayer(n,n.buildingId?r.buildings.get(n.buildingId):void 0,null)}break;case`notice`:{let t=v?`inside`:T&&Date.now()-T.at<Ri?`door`:`street`;t===`door`&&(T=null);let n=Tt(e.text,t);n&&L(n);break}}},ce=e=>{if(v||!a||!s){!s&&e===r.myBuildingId&&(E=!0);return}T={id:e,at:Date.now()},a.send([{t:`enter`,buildingId:e}])},le=()=>{E&&s&&r.connected&&r.myBuildingId&&(E=!1,ce(r.myBuildingId))},ue=t=>{if(T=null,v&&v.id===t.id){v.replace(t);return}v&&de();let n=r.me;if(!n||!u)return;A.hide(),xe.clearKeys(),cancelAnimationFrame(f),e.canvas.hidden=!0,F.classList.add(`is-visiting`);let i=a;v=nn({uiRoot:e.uiRoot,after:e.canvas,inside:t,me:n,mine:t.id===r.myBuildingId,options:()=>e.options(),version:e.version?.()??``,topInset:()=>e.topInset(),send:e=>i?.send(e),toast:e=>L(e),summaryStamps:()=>w?.stamps??[],stuck:()=>{de(),a?.send([{t:`view`}])}})},de=()=>{if(!v)return;let t=v;v=null,t.destroy(),F.classList.remove(`is-visiting`),u&&(e.canvas.hidden=!1,p=0,cancelAnimationFrame(f),f=requestAnimationFrame(Ce),l=!0)},pe=()=>t(`Sem conexão com o Habblaud World agora; o Habblaud tenta de novo sozinho.`),me=e=>{switch(e.type){case`snapshot`:r.applySnapshot(e.snapshot,performance.now()),k?.snapshot(e.snapshot),w=e.snapshot.summary,x&&ie(),ne(),s&&(g=``),r.inside?ue(r.inside):v&&de(),le(),M.textContent=r.connected?t(`Entrando na cidade…`):pe(),M.hidden=r.connected&&!!s;return;case`message`:{if(v?.message(e.msg)||k?.message(e.msg,performance.now()))return;e.msg.t===`away.summary`&&(w=o(e.msg)??w);let t=r.apply(e.msg,performance.now());t&&se(t);return}case`status`:e.status===`retrying`&&(M.textContent=pe(),M.hidden=!1);return;case`error`:e.code===`not_connected`?(M.textContent=pe(),M.hidden=!1):e.code!==`no_stream`&&L(d(e.code,`scene`));return}},he=()=>{x=!!(y?.me&&s),C=!1,x||(y=null,r=new Mi,i=new Sr(e.canvas,Ni,n,r),i.fx=k,s=null,c=null,M.textContent=t(`Entrando na cidade…`),M.hidden=!1),k?.reset(),g=``,A.hide();let o=e.openStream();a=o,o.on(e=>{if(a===o)try{me(e)}catch(e){console.error(`[cidade] evento do stream ignorado`,e)}})},ge=()=>{a?.close(),a=null},_e=(e,t)=>{let r=n.screenToWorld(e,t),a=Math.max(1,3/n.zoom);for(let e=i.charsDrawn.length-1;e>=0;e--){let t=i.charsDrawn[e];if(t.visible&&!t.me&&r.x>=t.bx-a&&r.x<=t.bx+t.bw+a&&r.y>=t.by-a&&r.y<=t.by+t.bh+a)return{type:`player`,id:t.id}}let o=null,s=-1/0;for(let e of i.buildingsDrawn)r.x<e.x||r.x>e.x+192||r.y<e.y||r.y>e.y+e.m.height||e.depth>s&&(s=e.depth,o={type:`building`,id:e.b.id});return o},z=null,ve=(e,t,i)=>{let o=_e(e,t),s=ye(e,t);if(o?.type===`player`){let e=r.players.get(o.id);if(!e)return;A.showPlayer(e.info,e.info.buildingId?r.buildings.get(e.info.buildingId):void 0,s),a?.send([{t:`profile`,playerId:o.id}]);return}if(o?.type===`building`){let e=r.buildings.get(o.id);if(!e)return;A.showBuilding(e,r.myBuildingId,s,!0);let t=b(e.lot).front;ae(t.x,t.y+(b(e.lot).side===`s`?.3:-.3),i.shift);return}A.hide();let c=n.screenToWorld(e,t);ae(c.x/16,c.y/16,i.shift)},ye=(t,n)=>{let r=e.canvas.getBoundingClientRect();return{x:r.left+t,y:r.top+n}},be=()=>{if(!m){z&&A.kind===`building`&&!A.pinned&&A.hide(),z=null,e.canvas.style.cursor=``;return}let t=_e(m.x,m.y);if(z=t,e.canvas.style.cursor=t?`pointer`:`crosshair`,t?.type===`building`){let e=r.buildings.get(t.id);e&&(!A.pinned||A.id===e.id)&&A.showBuilding(e,r.myBuildingId,ye(m.x,m.y),!1)}else A.kind===`building`&&!A.pinned&&A.hide()},xe=new Qe(e.canvas,n,{active:()=>u&&!v,hover:(e,t,n)=>{m=n?{x:e,y:t}:null},click:ve,interact:()=>{l=!1,n.stop()},zoomStep:(e,t=n.viewW/2,r=n.viewH/2)=>n.zoomAt(n.stepZoom(e),t,r,Date.now(),!0),use:()=>{if(!s)return;let e=ft(s.x,s.y,e=>!!r.buildingAt(e),2),n=e?r.buildingAt(e.lot):void 0;if(!n){L(t(`Chegue perto da porta de um prédio e aperte E.`));return}ce(n.id)},recenter:()=>Se(),moved:()=>{l=!0}}),Se=()=>{if(v)return v.world.overview();if(l=!0,!s)return;let e=n.centerFor(s.x*16,s.y*16-12,n.zoom);n.animateTo(e.x,e.y,n.zoom,Date.now(),360)},Ce=t=>{f=requestAnimationFrame(Ce);let a=p?t-p:16.7,o=p?Math.min(.1,Math.max(0,a/1e3)):1/60;p=t,O.push(a),O.length>240&&O.shift();let u=performance.now();try{let t=Math.max(1,Math.min(3,window.devicePixelRatio||1));(e.canvas.clientWidth!==n.viewW||e.canvas.clientHeight!==n.viewH||t!==n.dpr)&&R();let a=r.me;if(s&&a&&!x){s.update(o,xe.intent()),c?.tick(u,s);let e=_(S(s.x,s.y)),t=`${e.x},${e.y}`;t!==g&&(g=t,r.keepAround(s.x,s.y))}k?.frame(u,o);let d=l&&s?n.centerFor(s.x*16,s.y*16-12,n.zoom):null;n.update(Date.now(),d,o);let f=s?ft(s.x,s.y,e=>!!r.buildingAt(e),2):null;if(i.frame(u,o,e.options(),s&&a?{player:s,self:a}:null,{building:z?.type===`building`?z.id:A.kind===`building`?A.id:null,player:z?.type===`player`?z.id:A.kind===`player`?A.id:null,door:f?f.front:null,me:s?{x:s.x,y:s.y}:null}),D.push(i.lastFrameMs),D.length>240&&D.shift(),be(),A.kind===`building`&&A.id&&!r.buildings.has(A.id)&&A.hide(),A.kind===`player`&&A.id&&!r.players.has(A.id)&&A.hide(),s){let e=n.screenToWorld(0,0),t=n.screenToWorld(n.viewW,n.viewH);te.draw(r.minimap,r.minimapVersion,s,{x:e.x/16,y:e.y/16,w:(t.x-e.x)/16,h:(t.y-e.y)/16})}}catch(e){console.error(`[cidade] erro no frame`,e)}},we=()=>{p=0,xe.clearKeys(),document.hidden||c?.reset()},Te={get visible(){return u},show(){u||(u=!0,e.canvas.hidden=!1,F.hidden=!1,R(),y?(n.stop(),n.zoom=y.zoom,n.x=y.camX,n.y=y.camY,l=y.following):n.animating||(n.zoom=n.viewW<600?1.5:2),he(),p=0,f=requestAnimationFrame(Ce),window.addEventListener(`resize`,R),document.addEventListener(`visibilitychange`,we),h=setInterval(()=>{document.hidden&&s&&c&&!v&&c.keepAlive(s)},Ii))},hide(){u&&(v&&de(),E=!1,y={camX:n.x,camY:n.y,zoom:n.zoom,following:l,me:s?{x:s.x,y:s.y}:null},u=!1,cancelAnimationFrame(f),e.canvas.hidden=!0,F.hidden=!0,A.hide(),k?.hide(),xe.clearKeys(),ge(),window.removeEventListener(`resize`,R),document.removeEventListener(`visibilitychange`,we),h&&clearInterval(h),h=null)},zoomBy(e){if(!(!Number.isFinite(e)||e<=0||e===1)){if(v)return v.world.zoomBy(e);n.zoomAt(n.stepZoom(e>1?1:-1),n.viewW/2,n.viewH/2,Date.now(),!0)}},recenter:Se,lookAt(e,t,r=n.zoom){l=!1,n.stop(),n.zoom=Math.max(Pi,Math.min(6,r));let i=n.centerFor(e*16,t*16,n.zoom);n.x=i.x,n.y=i.y},escape(){return v?v.escape():k?.escape()?!0:A.open?(A.hide(),!0):!1},destroy(){Te.hide(),xe.destroy(),k?.destroy(),F.remove()},perf(){let e=[...D].sort((e,t)=>e-t),t=D.reduce((e,t)=>e+t,0)/Math.max(1,D.length),r=e[Math.min(e.length-1,Math.floor(e.length*.95))]??0,a=O.reduce((e,t)=>e+t,0)/Math.max(1,O.length);return{frames:D.length,drawAvgMs:t,drawP95Ms:r,drawMaxMs:e[e.length-1]??0,fps:a?1e3/a:0,buildings:i.buildingsDrawn.length,zoom:n.zoom}},camera:n,get state(){return r},perfReset(){D.length=0,O.length=0},me:()=>s?{x:s.x,y:s.y,moving:s.moving,seated:!s.moving&&i.onBench(s.x,s.y)}:null,toScreen:(e,t)=>n.worldToScreen(e*16,t*16),enter:e=>ce(e),visitOwn(){let e=r.myBuildingId;s&&a&&e&&r.connected?ce(e):E=!0},visit:()=>v,walkTo:(e,t)=>ae(e,t,!1),doorOf(e){let t=r.buildings.get(e);return t?{...b(t.lot).front}:null}};return Te}export{Pi as CITY_MIN_ZOOM,Li as ENTER_RADIUS,Bi as createCityScene};
|
|
1
|
+
import{a as e,s as t}from"./main-CIX7XLHO.js";import{c as n,l as r}from"./simulator-mIkQohaY.js";import{$ as i,Dt as a,K as o,Mt as s,Nt as c,Q as l,Tt as u,V as d,W as f,X as p,Z as m,ct as h,dt as g,en as _,et as v,ft as y,ht as b,it as x,kt as S,lt as C,nn as w,nt as T,ot as E,pt as ee,q as D,rt as O,st as k,tt as A,ut as te,wt as j}from"./world-model-BCuCi4WK.js";import{l as M,r as N,s as P}from"./dom-DTQ3fgr0.js";import{A as F,B as I,C as L,D as R,E as ne,F as re,G as ie,H as ae,I as oe,J as se,K as ce,L as le,M as ue,N as de,O as fe,P as pe,R as me,S as he,T as ge,U as _e,V as z,W as ve,Y as ye,a as be,b as xe,c as Se,d as Ce,i as we,j as Te,k as Ee,l as De,n as Oe,o as ke,q as Ae,r as je,s as Me,u as Ne,v as Pe,w as Fe,x as Ie,y as Le,z as Re}from"./app-9Vl0ffKz.js";function ze(e){if(!e||!/^[A-Za-z]{2}$/.test(e))return``;let t=e.toUpperCase();return String.fromCodePoint(127462+t.charCodeAt(0)-65,127462+t.charCodeAt(1)-65)}function Be(t){if(!t||!/^[A-Za-z]{2}$/.test(t))return``;try{return new Intl.DisplayNames([e()],{type:`region`}).of(t.toUpperCase())??t.toUpperCase()}catch{return t.toUpperCase()}}function Ve(t){let n=/^(\d{4})-(\d{2})$/.exec(t??``);if(!n)return``;let r=Number(n[1]),i=Number(n[2]);if(i<1||i>12)return``;try{return new Intl.DateTimeFormat(e(),{month:`long`,year:`numeric`}).format(new Date(r,i-1,1))}catch{return`${n[2]}/${n[1]}`}}function He(e){let n=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;return n===0?t(`só o térreo`):n>24?t(`{0} andares`,[`24+`]):n===1?t(`1 andar`):t(`{0} andares`,[n])}function Ue(n){let r=Number.isFinite(n)?Math.max(0,Math.floor(n)):0;return r===1?t(`1 curtida`):t(`{0} curtidas`,[r.toLocaleString(e())])}function We(e,n=null){let r=e.state===`online`;return{owner:e.owner.name,flag:ze(e.owner.country),country:Be(e.owner.country),online:r,state:t(r?`Luzes acesas`:`Luzes apagadas`),floors:He(e.floors),agents:e.agents?{working:e.agents.working,waiting:e.agents.waiting,idle:e.agents.idle}:null,likes:Ue(e.likes),since:Ve(e.sinceMonth),closed:e.closed===!0,mine:!!n&&e.id===n}}function Ge(e,t){return{name:e.name,flag:ze(e.country),country:Be(e.country),traits:(e.traits??[]).filter(u).map(e=>({emoji:j[e].emoji,label:j[e].label,desc:j[e].desc})),intro:e.intro?f(e.intro):``,likes:Ue(e.likesReceived),building:t?{id:t.id,floors:He(t.floors),online:t.state===`online`}:null,hasBuilding:!!e.buildingId}}var Ke=class{actions;el;title;flag;sub;body;avatar;closeBtn;kind=null;id=null;pinned=!1;sig=``;constructor(e){this.actions=e,this.avatar=N(`span`,{class:`ui-city-card__avatar`,hidden:!0,attrs:{"aria-hidden":`true`}}),this.flag=N(`span`,{class:`ui-city-card__flag`,attrs:{"aria-hidden":`true`}}),this.title=N(`strong`,{class:`ui-city-card__title`}),this.sub=N(`div`,{class:`ui-city-card__sub`}),this.body=N(`div`,{class:`ui-city-card__body`}),this.closeBtn=N(`button`,{class:`ui-city-card__close`,type:`button`,title:t(`Fechar`),attrs:{"aria-label":t(`Fechar`)},text:`×`,on:{click:()=>this.hide()}}),this.el=N(`section`,{class:`ui-city-card`,hidden:!0,role:`dialog`,attrs:{"aria-live":`polite`,"aria-label":t(`Cartão`)}},N(`div`,{class:`ui-city-card__head`},this.avatar,N(`div`,{class:`ui-city-card__names`},N(`div`,{class:`ui-city-card__line`},this.flag,this.title),this.sub),this.closeBtn),this.body)}get open(){return this.kind!==null}hide(){this.kind=null,this.id=null,this.pinned=!1,this.sig=``,this.el.hidden=!0}showBuilding(e,n,r,i){let a=We(e,n),o=`b|${e.id}|${JSON.stringify(a)}`;if(this.kind=`building`,this.id=e.id,this.pinned=i||this.pinned&&this.id===e.id,this.el.classList.toggle(`is-pinned`,this.pinned),o!==this.sig){this.sig=o,P(this.avatar,!0),M(this.flag,a.flag),this.flag.title=a.country,M(this.title,a.owner),M(this.sub,[a.mine?t(`Seu prédio`):``,a.country].filter(Boolean).join(` · `)),this.el.classList.toggle(`is-online`,a.online);let n=[];n.push(N(`div`,{class:`ui-city-card__row`},N(`span`,{class:`ui-city-card__dot ${a.online?`is-on`:`is-off`}`}),N(`span`,{text:a.state}),N(`span`,{class:`ui-city-card__sep`,text:`·`}),N(`span`,{text:a.floors}))),a.agents?n.push(N(`div`,{class:`ui-city-card__agents`},N(`span`,{class:`ui-city-card__agent is-working`,title:t(`Agentes trabalhando`)},N(`b`,{text:String(a.agents.working)}),` ${t(`trabalhando`)}`),N(`span`,{class:`ui-city-card__agent is-waiting`,title:t(`Agentes esperando o dono`)},N(`b`,{text:String(a.agents.waiting)}),` ${t(`esperando`)}`),N(`span`,{class:`ui-city-card__agent is-idle`,title:t(`Agentes à toa`)},N(`b`,{text:String(a.agents.idle)}),` ${t(`à toa`)}`))):n.push(N(`div`,{class:`ui-city-card__muted`,text:t(`Modo discreto: o dono não mostra os agentes.`)})),a.closed&&n.push(N(`div`,{class:`ui-city-card__muted`,text:`🔒 ${t(`Fechado a visitas`)}`})),n.push(N(`div`,{class:`ui-city-card__row ui-city-card__foot`},N(`span`,{text:`❤️ ${a.likes}`}),a.since?N(`span`,{class:`ui-city-card__since`,text:t(`No mundo desde {0}`,[a.since])}):null));let r=this.actions.enter;if(a.mine&&r){let i=e.id;n.push(N(`button`,{class:`ui-city-card__link`,type:`button`,text:`👁 ${t(`Ver como os outros veem`)}`,on:{click:()=>r(i)}}))}let i=this.actions.extras?.(`building`,e.id);i&&n.push(i),this.body.replaceChildren(...n)}this.place(r),this.el.hidden=!1}showPlayer(e,r,i){let a=Ge(e,r),o=`p|${e.id}|${JSON.stringify(a)}|${JSON.stringify(e.parts)}`;if(this.kind=`player`,this.id=e.id,this.pinned=!0,this.el.classList.add(`is-pinned`),this.el.classList.remove(`is-online`),o!==this.sig){this.sig=o,P(this.avatar,!1);try{let t=ye(n(e.id),{look:e.look,parts:e.parts,scale:2});t.className=`ui-city-card__avatar-img`,this.avatar.replaceChildren(t)}catch{this.avatar.replaceChildren()}M(this.flag,a.flag),this.flag.title=a.country,M(this.title,a.name),M(this.sub,a.country);let r=[];a.intro&&r.push(N(`div`,{class:`ui-city-card__intro`,text:`“${a.intro}”`})),a.traits.length&&r.push(N(`div`,{class:`ui-city-card__traits`},...a.traits.map(e=>N(`span`,{class:`ui-trait`,title:e.desc,text:`${e.emoji} ${e.label}`}))));let i=N(`div`,{class:`ui-city-card__row ui-city-card__foot`},N(`span`,{text:`❤️ ${t(`{0} recebidas`,[a.likes])}`}));if(a.building){let e=a.building;i.append(N(`button`,{class:`ui-city-card__link`,type:`button`,text:`🏢 ${t(`Ver o prédio`)} (${e.floors})`,on:{click:()=>this.actions.showBuilding(e.id)}}))}else i.append(N(`span`,{class:`ui-city-card__muted`,text:a.hasBuilding?t(`Prédio longe daqui`):t(`Ainda sem prédio`)}));r.push(i);let s=this.actions.extras?.(`player`,e.id);s&&r.push(s),this.body.replaceChildren(...r)}i&&this.place(i),this.el.hidden=!1}place(e){let t=window.innerWidth,n=window.innerHeight,r=this.el.offsetWidth||260,i=this.el.offsetHeight||140;if(t<=520){this.el.style.transform=``,this.el.classList.add(`is-docked`);return}this.el.classList.remove(`is-docked`);let a=this.actions.topInset()+8,o=e.x+16,s=e.y-i-12;o+r>t-8&&(o=e.x-r-16),s<a&&(s=e.y+18),o=Math.max(8,Math.min(t-r-8,o)),s=Math.max(a,Math.min(n-i-8,s)),this.el.style.transform=`translate(${Math.round(o)}px, ${Math.round(s)}px)`}},qe=6,Je={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],w:[0,-1],s:[0,1],a:[-1,0],d:[1,0]};function Ye(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``)||t.getAttribute?.(`role`)===`radio`)}function Xe(e,t){let n=0,r=0;for(let t of e){let e=Je[t];e&&(n+=e[0],r+=e[1])}return{dx:Math.sign(n),dy:Math.sign(r),run:t}}function Ze(e){if(Je[e.key])return e.key;let t=e.key.length===1?e.key.toLowerCase():e.key;return Je[t]?t:e.code===`KeyW`?`w`:e.code===`KeyA`?`a`:e.code===`KeyS`?`s`:e.code===`KeyD`?`d`:null}var Qe=class{canvas;camera;h;keys=new Set;shift=!1;pointers=new Map;downX=0;downY=0;dragging=!1;pinch=null;wheelAcc=0;wheelSettle=null;off=[];constructor(e,t,n){this.canvas=e,this.camera=t,this.h=n,e.style.touchAction=`none`;let r=(e,t,n,r)=>{e.addEventListener(t,n,r),this.off.push(()=>e.removeEventListener(t,n,r))};r(e,`pointerdown`,e=>this.onDown(e)),r(e,`pointermove`,e=>this.onMove(e)),r(e,`pointerup`,e=>this.onUp(e)),r(e,`pointercancel`,e=>this.onCancel(e)),r(e,`pointerleave`,()=>this.h.hover(0,0,!1)),r(e,`wheel`,e=>this.onWheel(e),{passive:!1}),r(window,`keydown`,e=>this.onKey(e,!0)),r(window,`keyup`,e=>this.onKey(e,!1)),r(window,`blur`,()=>this.clearKeys()),r(document,`visibilitychange`,()=>this.clearKeys())}intent(){return Xe(this.keys,this.shift)}clearKeys(){this.keys.clear(),this.shift=!1}destroy(){for(let e of this.off.splice(0))e();this.wheelSettle&&clearTimeout(this.wheelSettle),this.clearKeys()}local(e){let t=this.canvas.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}onKey(e,t){if(e.key===`Shift`?this.shift=t:typeof e.getModifierState==`function`&&(this.shift=e.getModifierState(`Shift`)),!t){let t=Ze(e);t&&this.keys.delete(t);return}if(!this.h.active()||e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||Ye(e.target)||ce(e.target))return;let n=Ze(e);if(n){e.preventDefault(),this.keys.add(n),this.h.moved();return}switch(e.key){case`e`:case`E`:case`Enter`:if(e.key===`Enter`&&e.target?.closest?.(`button, a`))return;e.preventDefault(),this.h.use();return;case`+`:case`=`:e.preventDefault(),this.h.zoomStep(1);return;case`-`:case`_`:e.preventDefault(),this.h.zoomStep(-1);return;case`0`:e.preventDefault(),this.h.recenter();return}}onDown(e){if(e.button!==0&&e.pointerType===`mouse`)return;let t=this.local(e);this.pointers.set(e.pointerId,t);try{this.canvas.setPointerCapture(e.pointerId)}catch{}if(this.pointers.size===1)this.downX=t.x,this.downY=t.y,this.dragging=!1;else if(this.pointers.size===2){let[e,t]=[...this.pointers.values()];this.pinch={dist:Math.hypot(e.x-t.x,e.y-t.y)||1,zoom:this.camera.zoom,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2},this.dragging=!0,this.h.interact()}}onMove(e){let t=this.local(e),n=this.pointers.get(e.pointerId);if(!n){e.pointerType===`mouse`&&this.h.hover(t.x,t.y,!0);return}if(this.pointers.set(e.pointerId,t),this.pinch&&this.pointers.size>=2){let[e,t]=[...this.pointers.values()],n=Math.hypot(e.x-t.x,e.y-t.y)||1,r=(e.x+t.x)/2,i=(e.y+t.y)/2;this.camera.panBy(r-this.pinch.cx,i-this.pinch.cy),this.camera.zoomAt(this.pinch.zoom*(n/this.pinch.dist),r,i,Date.now(),!1),this.pinch.cx=r,this.pinch.cy=i;return}!this.dragging&&Math.hypot(t.x-this.downX,t.y-this.downY)>qe&&(this.dragging=!0,this.canvas.style.cursor=`grabbing`,this.h.interact()),this.dragging&&this.camera.panBy(t.x-n.x,t.y-n.y)}onUp(e){let t=this.local(e);if(this.pointers.delete(e.pointerId)){if(this.pinch&&this.pointers.size<2){this.pinch=null,this.camera.settle(Date.now());return}if(!(this.pointers.size>0)){if(this.canvas.style.cursor=``,this.dragging){this.dragging=!1;return}this.h.click(t.x,t.y,{shift:e.shiftKey})}}}onCancel(e){this.pointers.delete(e.pointerId),this.pointers.size<2&&(this.pinch=null),this.pointers.size||(this.dragging=!1)}onWheel(e){e.preventDefault();let t=this.local(e),n=e.deltaMode===1?e.deltaY*33:e.deltaMode===2?e.deltaY*400:e.deltaY;if(e.ctrlKey){this.camera.zoomAt(this.camera.zoom*Math.exp(-n*.012),t.x,t.y,Date.now(),!1),this.wheelSettle&&clearTimeout(this.wheelSettle),this.wheelSettle=setTimeout(()=>this.camera.settle(Date.now()),180);return}this.wheelAcc+=n,Math.abs(this.wheelAcc)>=50&&(this.h.zoomStep(this.wheelAcc<0?1:-1,t.x,t.y),this.wheelAcc=0)}},$e={x:-2,y:-2,w:m.x,h:m.y};A.w-2;var B=e=>`${e.x},${e.y}`;function et(e){return n(`quarteirao:${e.x},${e.y}`)}function tt(e){return n(`lote:${e.x},${e.y}`)}function nt(e){return e.y-p.h*Math.floor(e.y/p.h)===0}function rt(e){if(te(e))return[];let t=[];for(let n=0;n<p.h;n++)for(let r=0;r<p.w;r++)t.push({x:e.x*p.w+r,y:e.y*p.h+n});return t}function it(e){let t=E(e);return{x:(t.x+$e.x)*16,y:(t.y+$e.y)*16,w:$e.w*16,h:$e.h*16}}function at(e,t=64){let n=m.x*16,r=m.y*16,i=$e.x*16,a=$e.y*16;return{bx0:Math.floor((e.x0-t-i)/n),by0:Math.floor((e.y0-t-a)/r),bx1:Math.floor((e.x1+t-i)/n),by1:Math.floor((e.y1+t-a)/r)}}function ot(){let e=l.w,t=l.h,n=e+4,r=t+4,i=[];for(let e=0;e<p.h;e++)for(let t=0;t<p.w;t++)i.push({x:2+t*A.w,y:2+e*A.h,w:A.w,h:A.h});let a=5/2;return{sidewalkOuter:{x:0,y:0,w:n,h:r},block:{x:2,y:2,w:e,h:t},streets:[{x:n,y:0,w:5,h:r},{x:0,y:r,w:n,h:5}],intersection:{x:n,y:r,w:5,h:5},crosswalks:[{rect:{x:0,y:r,w:2,h:5},across:`ns`},{rect:{x:n-2,y:r,w:2,h:5},across:`ns`},{rect:{x:n,y:0,w:5,h:2},across:`we`},{rect:{x:n,y:r-2,w:5,h:2},across:`we`}],laneMarks:[[3,r+a,n-2-1,r+a],[n+a,3,n+a,r-2-1]],lots:i}}var st=()=>!0;function ct(e){let t=Math.floor(e.x),n=Math.floor(e.y),r=Math.max(1,Math.ceil(e.w)),i=Math.max(1,Math.ceil(e.h)),a=new Ee(r,i);for(let e=0;e<i;e++)for(let i=0;i<r;i++)a.cells[e*r+i]=+!!g(t+i+.5,n+e+.5,st);return{grid:a,ox:t,oy:n}}function lt(e,t,n=Math.max(m.x,m.y)){let r=Math.floor(Math.min(e.x,t.x))-n,i=Math.floor(Math.min(e.y,t.y))-n,a=Math.ceil(Math.max(e.x,t.x))+n,o=Math.ceil(Math.max(e.y,t.y))+n;return{x:r,y:i,w:a-r,h:o-i}}function ut(e,t,n=16){let r=Math.floor(e),i=Math.floor(t);if(g(r+.5,i+.5,st))return{x:r,y:i};for(let a=1;a<=n;a++){let n=null,o=1/0;for(let s=-a;s<=a;s++)for(let c=-a;c<=a;c++){if(Math.max(Math.abs(c),Math.abs(s))!==a||!g(r+c+.5,i+s+.5,st))continue;let l=(r+c+.5-e)**2+(i+s+.5-t)**2;l<o&&(o=l,n={x:r+c,y:i+s})}if(n)return n}return null}function dt(e,t){return g(e,t,st)}function ft(e,t,n,r=1.6){let{x:i,y:a}=x(e,t),o=null,s=r*r;for(let r=a-1;r<=a+1;r++)for(let a=i-1;a<=i+1;a++)for(let i of rt({x:a,y:r})){let r=y(i),a=(r.front.x-e)**2+(r.front.y-t)**2;a<=s&&n(i)&&(s=a,o={lot:i,side:r.side,front:r.front})}return o}var pt=3;function mt(e){let t=E(e),n=et(e),a=r(n),o=[],s=e=>e*16,c=n&1,u=[0,1,2].map(e=>t.x+e*A.w+i.dx+i.w/2),d=e=>u.some(t=>Math.abs(e-t)<pt);for(let e of[`n`,`s`]){let r=e===`n`?t.y-2:t.y+l.h+2-1;if([0,A.w,2*A.w,3*A.w].forEach((i,l)=>{let u=t.x+i;d(u)||((l+c+ +(e===`s`))%2==0?o.push({kind:`lamp`,x:s(u)+(i===0?6:i===3*A.w?-6:0),y:s(r)+10,seed:n+l}):o.push({kind:a()<.22?`pine`:`tree`,x:s(u),y:s(r)+12,seed:Math.floor(a()*1e9)}))}),a()<.7){let e=Math.floor(a()*3),i=t.x+e*A.w+(a()<.5?2:A.w-3);if(!d(i+1)){let e=r;o.push({kind:`bench`,x:s(i+1),y:s(e)+13,seed:n+7,seat:{x:i+1,y:e+.85,dir:`down`}})}}}for(let e of[`w`,`e`]){let r=e===`w`?t.x-2:t.x+l.w+2-1;[3,Math.floor(l.h/2),l.h-3].forEach((e,i)=>{let c=t.y+e,l=s(r)+8;i===1?o.push({kind:`lamp`,x:l,y:s(c)+10,seed:n+20+i}):a()<.85?o.push({kind:a()<.25?`pine`:`tree`,x:l,y:s(c)+12,seed:Math.floor(a()*1e9)}):o.push({kind:`bush`,x:l,y:s(c)+12,seed:Math.floor(a()*1e9),small:!0})})}return o}var ht=[`park`,`pond`,`orchard`,`cafe`];function gt(e){return ht[tt(e)%ht.length]}function _t(e,t){let n=ee(e),a=tt(e),o=r(a^1540483477),s=[],c=e=>(n.x+e)*16,l=e=>(n.y+e)*16,u=()=>Math.floor(o()*1e9),d=nt(e);if(t){let e=d?l(A.h)-2:l(0)+12;for(let t=1;t<A.w-1;t+=2)s.push({kind:`hedge`,x:c(t)+16,y:e,seed:a+t,small:!0});let t=l(d?A.h-1.4:1.6);return o()<.8&&s.push({kind:o()<.3?`pine`:`tree`,x:c(1.2),y:t,seed:u()}),o()<.8&&s.push({kind:o()<.3?`pine`:`tree`,x:c(A.w-1.2),y:t,seed:u()}),s}let f=gt(e),p=d?l(0)+13:l(A.h)-2;for(let e=0;e<A.w;e+=2)e>=i.dx-1&&e<=i.dx+1||s.push({kind:e/2%3==1?`flowers`:`hedge`,x:c(e)+16,y:p,seed:a+e*3,small:!0});let m=A.w/2,h=A.h/2;switch(f){case`park`:s.push({kind:`tree`,x:c(2.5),y:l(d?4.5:3.5),seed:u()}),s.push({kind:o()<.5?`pine`:`tree`,x:c(11.5),y:l(d?3.8:4.2),seed:u()}),s.push({kind:`tree`,x:c(10.5),y:l(d?9.5:8.8),seed:u()}),s.push({kind:`bush`,x:c(3.5),y:l(d?9.2:8.4),seed:u(),small:!0}),s.push({kind:`flowers`,x:c(m),y:l(h+.6),seed:u(),small:!0}),s.push({kind:`bench`,x:c(m),y:l(h-1.2),seed:u(),seat:{x:n.x+m,y:n.y+h-1.35,dir:`down`}});break;case`pond`:s.push({kind:`rock`,x:c(3.2),y:l(h+2.2),seed:u(),small:!0}),s.push({kind:`rock`,x:c(10.4),y:l(h-1.8),seed:u(),small:!0}),s.push({kind:`tree`,x:c(1.8),y:l(d?10.6:3.2),seed:u()}),s.push({kind:`pine`,x:c(12.2),y:l(d?10.2:3.6),seed:u()}),s.push({kind:`bush`,x:c(4.6),y:l(h-2.6),seed:u(),small:!0}),s.push({kind:`bush`,x:c(9.5),y:l(h+2.8),seed:u(),small:!0});break;case`orchard`:for(let e=0;e<2;e++)for(let t=0;t<4;t++)s.push({kind:`tree`,x:c(2.2+t*3.2),y:l((d?4.6:3.6)+e*4.4),seed:u()});break;case`cafe`:s.push({kind:`parasol`,x:c(4),y:l(h+.5),seed:u()}),s.push({kind:`parasol`,x:c(10),y:l(h+.5),seed:u()}),s.push({kind:`planter`,x:c(m),y:l(h-2.5),seed:u(),small:!0}),s.push({kind:`tree`,x:c(1.6),y:l(d?10.4:2.6),seed:u()}),s.push({kind:`tree`,x:c(12.4),y:l(d?10.4:2.6),seed:u()})}return s}function vt(){let e=E({x:0,y:0}),t=t=>(e.x+t)*16,n=t=>(e.y+t)*16,r=[],i=v;r.push({kind:`fountain`,x:t(i.x+i.w/2),y:n(i.y+i.h),seed:1});for(let a of[-5,5])r.push({kind:`bench`,x:t(i.x+i.w/2+a),y:n(i.y-1)+13,seed:3+a,seat:{x:e.x+i.x+i.w/2+a,y:e.y+i.y-1+.85,dir:`down`}}),r.push({kind:`bench`,x:t(i.x+i.w/2+a),y:n(i.y+i.h+2)+13,seed:4+a,seat:{x:e.x+i.x+i.w/2+a,y:e.y+i.y+i.h+2+.85,dir:`down`}});[[6,5],[l.w-6,5],[6,l.h-4],[l.w-6,l.h-4]].forEach(([e,i],a)=>{r.push({kind:a%2?`pine`:`tree`,x:t(e-1.5),y:n(i),seed:100+a*7}),r.push({kind:`tree`,x:t(e+1.5),y:n(i+.4),seed:200+a*11}),r.push({kind:`flowers`,x:t(e),y:n(i+1.6),seed:300+a,small:!0}),r.push({kind:`bush`,x:t(e-3),y:n(i+1.4),seed:400+a,small:!0}),r.push({kind:`bush`,x:t(e+3),y:n(i+1.2),seed:500+a,small:!0})});for(let[e,i]of[[12,4],[l.w-12,4],[12,l.h-5],[l.w-12,l.h-5]])r.push({kind:`lamp`,x:t(e)+8,y:n(i)+10,seed:e*3+i});return r.push({kind:`totem`,x:t(O.x-3)+8,y:n(O.y)+4,seed:2}),r.push({kind:`planter`,x:t(O.x+3)+8,y:n(O.y)+6,seed:9,small:!0}),r}function yt(e){let t=mt(e);return te(e)&&t.push(...vt()),t}var bt=p.w*p.h;function xt(e){return e>0?Math.min(1,.35+.65*Math.min(e,bt)/bt):0}function St(e,t,n,r,i=4){let a=x(t.x,t.y),o=(2*i+1)*m.x,s=(2*i+1)*m.y,c=Math.min(r.w/o,r.h/s),u=a.x*m.x+l.w/2,d=a.y*m.y+l.h/2,f=e=>r.w/2+(e-u)*c,p=e=>r.h/2+(e-d)*c,h=new Map;for(let t of e)h.set(`${t.x},${t.y}`,t.lit);let g=[];for(let e=a.y-i-1;e<=a.y+i+1;e++)for(let t=a.x-i-1;t<=a.x+i+1;t++){let n=f(t*m.x),i=p(e*m.y),a=l.w*c,o=l.h*c;if(n+a<0||i+o<0||n>r.w||i>r.h)continue;let s=`${t},${e}`,u=h.get(s);g.push({bx:t,by:e,x:n,y:i,w:a,h:o,light:xt(u??0),occupied:u!==void 0,plaza:t===T.x&&e===T.y})}return{cells:g,me:{x:f(t.x),y:p(t.y)},view:{x:f(n.x),y:p(n.y),w:n.w*c,h:n.h*c},k:c,cx:u,cy:d}}function Ct(e,t,n,r){return{x:e.cx+(n-t.w/2)/e.k,y:e.cy+(r-t.h/2)/e.k}}var wt=class{el;canvas;ctx;model=null;size={w:176,h:116};sig=``;constructor(e){this.canvas=N(`canvas`,{class:`ui-city-minimap__canvas`,attrs:{"aria-hidden":`true`}}),this.ctx=this.canvas.getContext(`2d`),this.el=N(`nav`,{class:`ui-city-minimap`,attrs:{"aria-label":t(`Minimapa: clique para levar a câmera até lá`)},title:t(`Minimapa: clique para levar a câmera até lá`)},this.canvas),this.canvas.addEventListener(`pointerdown`,t=>{if(t.preventDefault(),t.stopPropagation(),!this.model)return;let n=this.canvas.getBoundingClientRect();e(Ct(this.model,this.size,t.clientX-n.left,t.clientY-n.top))})}draw(e,t,n,r){let i=this.canvas.clientWidth||this.size.w,a=this.canvas.clientHeight||this.size.h,o=Math.max(1,Math.min(3,window.devicePixelRatio||1)),s=`${t}|${Math.round(n.x*2)}|${Math.round(n.y*2)}|${Math.round(r.x)}|${Math.round(r.y)}|${Math.round(r.w)}|${i}|${a}|${o}`;if(s===this.sig)return;this.sig=s,this.size={w:i,h:a},(this.canvas.width!==Math.round(i*o)||this.canvas.height!==Math.round(a*o))&&(this.canvas.width=Math.round(i*o),this.canvas.height=Math.round(a*o));let c=this.model=St(e,n,r,this.size),l=this.ctx;l.setTransform(o,0,0,o,0,0),l.clearRect(0,0,i,a),l.fillStyle=`#2a2f3a`,l.fillRect(0,0,i,a);for(let e of c.cells){let t=Math.round(e.x),n=Math.round(e.y),r=Math.max(2,Math.round(e.w)),i=Math.max(2,Math.round(e.h));l.fillStyle=e.plaza?`#b9b2a4`:e.light>0?`rgba(255,206,110,${(.25+e.light*.75).toFixed(3)})`:e.occupied?`#55607a`:`#3a5a45`,l.fillRect(t,n,r,i),e.light>0&&(l.fillStyle=`rgba(255,240,200,${(e.light*.5).toFixed(3)})`,l.fillRect(t+1,n+1,Math.max(1,r-2),1)),e.plaza&&(l.fillStyle=`#5ea8d6`,l.fillRect(Math.round(t+r/2-1),Math.round(n+i/2-1),2,2))}l.strokeStyle=`rgba(232,236,245,0.75)`,l.lineWidth=1,l.strokeRect(Math.round(c.view.x)+.5,Math.round(c.view.y)+.5,Math.max(2,Math.round(c.view.w)),Math.max(2,Math.round(c.view.h))),l.fillStyle=`#12151d`,l.fillRect(Math.round(c.me.x)-3,Math.round(c.me.y)-3,6,6),l.fillStyle=`#7cc8ff`,l.fillRect(Math.round(c.me.x)-2,Math.round(c.me.y)-2,4,4)}};function Tt(e,n=`street`){switch(e){case`ignored`:case`invalid`:case`view_required`:return null;case`rate_limited`:return t(`Devagar: o mundo pediu um tempo entre as ações.`);case`not_found`:return t(n===`door`?`Este prédio não está no mundo agora.`:n===`inside`?`O prédio saiu do mundo: você voltou para a rua.`:`Essa pessoa não está mais por perto.`);case`street_left`:return t(`Você ficou um bom tempo parado e saiu da rua: ande para voltar.`);case`chunk_full`:return t(`A área está cheia: só os jogadores mais perto aparecem.`);case`afk`:return t(`Você ficou um tempo parado.`);case`server_restart`:return t(`O Habblaud World vai reiniciar: a conexão cai e volta sozinha.`);case`left`:return t(`Sua conta saiu do mundo: o prédio volta com "Voltar ao mundo", em Configurações.`);case`too_far`:return t(`Chegue mais perto da porta para entrar.`);case`closed`:return t(n===`inside`?`O prédio fechou a visitas: você voltou para a rua.`:`Este prédio está fechado a visitas.`);case`blocked`:return t(n===`inside`?`Você não pode mais ficar neste prédio: voltou para a rua.`:`Você não pode entrar neste prédio.`);case`full`:return t(`O prédio está lotado (20 visitantes). Tente daqui a pouco.`);case`daily_limit`:return t(`Limite do dia atingido: amanhã tem mais.`);case`already_done`:return t(`Você já fez isso hoje.`);case`reported`:return t(`Denúncia enviada. Obrigado: a moderação vai olhar.`);case`blocked_ok`:return t(`Bloqueio feito: vocês deixam de se ver.`);case`stamped`:return t(`Carimbo deixado na portaria.`);default:return t(`Aviso do Habblaud World.`)}}var Et=5e3,V=S;function Dt(e,t){let n=[];for(let r=0;r<e;r++){let i=-Math.PI/2+r/Math.max(1,e)*Math.PI*2;n.push({x:Math.round(Math.cos(i)*t),y:Math.round(Math.sin(i)*t),angle:i})}return n}function Ot(e){return e===9?`0`:String(e+1)}function kt(e){if(!/^[0-9]$/.test(e))return-1;let t=e===`0`?9:Number(e)-1;return t<V.length?t:-1}function At(e,t,n={}){let r=n.range??12,i=null,a=r*r,o=new Set;for(let n of t){o.add(n.id);let t=(n.x-e.x)**2+(n.y-e.y)**2;t<=a&&(a=t,i=n.id)}return n.replyTo&&o.has(n.replyTo)?n.replyTo:n.selected&&o.has(n.selected)?n.selected:i}var jt=class{map=new Map;add(e,t,n){this.map.set(e,{id:t,at:n})}get(e,t){let n=this.map.get(e);if(!n)return null;let r=t-n.at;return r>=5e3||r<0?(this.map.delete(e),null):{id:n.id,t:r/Et,age:r}}get size(){return this.map.size}ids(){return[...this.map.keys()]}clear(){this.map.clear()}},Mt=class{perMinute;gapMs;times=[];constructor(e,t=0){this.perMinute=e,this.gapMs=t}wait(e){for(;this.times.length&&e-this.times[0]>=6e4;)this.times.shift();let t=this.times[this.times.length-1],n=t===void 0?0:Math.max(0,t+this.gapMs-e);return this.times.length>=this.perMinute&&(n=Math.max(n,this.times[0]+6e4-e)),n}take(e){return this.wait(e)>0?!1:(this.times.push(e),!0)}};function Nt(e){switch(e){case`hello`:case`wave`:return`nice_to_meet`;case`nice_building`:case`congrats`:case`clap`:case`good_luck`:return`thanks`;case`coffee`:return`coffee`;case`bye`:return`bye`;case`thanks`:return`clap`;case`nice_to_meet`:return`wave`}}var Pt=class{el;ring;center;to;hint;arrow;buttons=[];target=null;focused=0;pick=null;constructor(){this.to=N(`strong`,{class:`ui-city-wheel__to`}),this.hint=N(`span`,{class:`ui-city-wheel__hint`}),this.arrow=N(`span`,{class:`ui-city-wheel__arrow`,attrs:{"aria-hidden":`true`}}),this.center=N(`div`,{class:`ui-city-wheel__center`},N(`span`,{class:`ui-city-wheel__label`,text:t(`Cumprimentar`)}),this.to,this.hint),this.ring=N(`div`,{class:`ui-city-wheel__ring`,role:`menu`,attrs:{"aria-label":t(`Cumprimentos`)}});let e=Dt(V.length,96);V.forEach((t,n)=>{let r=e[n],i=N(`button`,{class:`ui-city-wheel__item`,type:`button`,role:`menuitem`,style:`--x:${r.x}px;--y:${r.y}px;--i:${n}`,attrs:{"aria-label":`${Me(t)} (${Ot(n)})`,"data-greeting":t},on:{click:()=>this.choose(n),pointerenter:()=>this.focus(n,!1),focus:()=>this.focus(n,!1)}},N(`span`,{class:`ui-city-wheel__emoji`,text:ke(t),attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-wheel__key`,text:Ot(n),attrs:{"aria-hidden":`true`}}));this.buttons.push(i),this.ring.append(i)}),this.el=N(`div`,{class:`ui-city-wheel`,hidden:!0},this.arrow,this.ring,this.center),this.el.addEventListener(`pointerdown`,e=>{e.target===this.el&&this.close()})}get open(){return!this.el.hidden}get targetId(){return this.target?.id??null}show(e,t,n,r,i){this.target=e,this.pick=i,M(this.to,e.name);let a=window.innerWidth,o=window.innerHeight,s=Math.max(132,Math.min(a-132,t.x)),c=Math.max(172,Math.min(o-132,t.y));if(this.el.style.setProperty(`--cx`,`${Math.round(s)}px`),this.el.style.setProperty(`--cy`,`${Math.round(c)}px`),n){let e=Math.atan2(n.y-c,n.x-s);this.arrow.style.setProperty(`--a`,`${e}rad`),this.arrow.hidden=Math.hypot(n.x-s,n.y-c)<30}else this.arrow.hidden=!0;this.el.hidden=!1,this.el.classList.remove(`is-in`),this.el.offsetWidth,this.el.classList.add(`is-in`),this.focus(Math.max(0,r?V.indexOf(r):0),!0)}close(){this.el.hidden||(this.el.hidden=!0,this.target=null,this.pick=null)}key(e){if(!this.open)return!1;let t=kt(e.key);if(t>=0)return this.choose(t),!0;switch(e.key){case`Escape`:case`g`:case`G`:return this.close(),!0;case`ArrowRight`:case`ArrowDown`:return this.focus((this.focused+1)%V.length,!0),!0;case`ArrowLeft`:case`ArrowUp`:return this.focus((this.focused+V.length-1)%V.length,!0),!0;case`Enter`:case` `:return this.choose(this.focused),!0}return!1}focus(e,t){this.focused=e,this.buttons.forEach((t,n)=>t.classList.toggle(`is-focus`,n===e));let n=V[e];M(this.hint,`${Oe[n].icon} ${Me(n)}`),t&&this.buttons[e]?.focus({preventScroll:!0})}choose(e){let t=V[e],n=this.pick;t&&n&&(this.buttons[e]?.classList.add(`is-picked`),setTimeout(()=>this.buttons[e]?.classList.remove(`is-picked`),300),this.close(),n(t))}},Ft=4e3;function It(e){return new Date(e).toISOString().slice(0,10)}function Lt(e){return`habblaud:world-stamp:${e}`}function Rt(e,t){if(!e)return null;try{let n=JSON.parse(e);return n.day===t&&c.includes(n.stampId)?n.stampId:null}catch{return null}}function zt(e){return e===`stamped`?`ok`:e===`already_done`?`already`:`failed`}function Bt(e,t=0,n=8){let r=[...e].filter(e=>c.includes(e.stampId)).sort((e,t)=>Number(!!t.mine)-Number(!!e.mine)||(t.count??1)-(e.count??1)),i=Math.max(1,Math.ceil(Math.min(n,r.length)/4)),a=(t^2654435769)>>>0,o=()=>(a=Math.imul(a^a>>>15,2246822507)+1831565813>>>0,((a^a>>>13)>>>0)/4294967296);return r.slice(0,n).map((e,t)=>{let n=t%4,r=Math.floor(t/4);return{stampId:e.stampId,icon:De(e.stampId),label:Ne(e.stampId),count:Math.max(1,e.count??1),mine:!!e.mine,x:(n+.5+(o()-.5)*.35)/4,y:(r+.5+(o()-.5)*.3)/i,rot:Math.round((o()-.5)*24)}})}function Vt(e,n){let r=()=>n.now?.()??Date.now(),i=Le(),a=0,o=!1,s=``,l=null,u=new Mt(9,400),d=N(`button`,{class:`ui-visit-social__like`,type:`button`,on:{click:()=>b()}}),f=N(`button`,{class:`ui-visit-social__stamp`,type:`button`,attrs:{"aria-expanded":`false`},on:{click:()=>S()}}),p=N(`div`,{class:`ui-visit-social__picker`,role:`group`,hidden:!0,attrs:{"aria-label":t(`Escolha um carimbo para a portaria`)}},N(`p`,{class:`ui-visit-social__hint`,text:t(`Um carimbo por prédio por dia. O dono vê quantos de cada recebeu, nunca quem deixou.`)}),N(`div`,{class:`ui-visit-social__grid`},...c.map(e=>N(`button`,{class:`ui-visit-social__choice`,type:`button`,title:Ne(e),attrs:{"data-stamp":e},on:{click:()=>C(e)}},N(`span`,{class:`ui-visit-social__choice-icon`,text:je[e].icon,attrs:{"aria-hidden":`true`}}),N(`span`,{text:Ne(e)}))))),m=N(`div`,{class:`ui-visit-social`},N(`div`,{class:`ui-visit-social__row`},d,f),p);e.append(m);let h=()=>s?Rt(g(s),It(r())):null;function g(e){try{return i?.getItem(Lt(e))??null}catch{return null}}function _(e,t){try{t?i?.setItem(Lt(e),JSON.stringify({day:It(r()),stampId:t})):i?.removeItem?.(Lt(e))}catch{}}function v(){let e=n.building(),r=n.mine();if(P(m,!e||r),!e)return;d.replaceChildren(N(`span`,{text:o?`💔`:`❤️`,attrs:{"aria-hidden":`true`}}),` ${t(o?`Descurtir`:`Curtir`)}`,N(`b`,{class:`ui-visit-social__count`,text:String(a)})),d.classList.toggle(`is-liked`,o),d.title=t(o?`Desfazer o like no prédio de {0}`:`Curtir o prédio de {0}`,[e.owner.name]);let i=h();f.disabled=!!i,f.replaceChildren(N(`span`,{text:i?De(i):`📮`,attrs:{"aria-hidden":`true`}}),` ${i?t(`Carimbo de hoje: {0}`,[Ne(i)]):t(`Deixar um carimbo`)}`),i&&x()}function y(){let e=n.building();e&&e.id!==s&&(s=e.id,x()),e&&(a=e.likes,o=e.likedByMe===!0),v()}function b(){let e=n.building();if(!e||n.mine())return;if(!u.take(r())){n.toast(t(`Devagar com os likes: espere um pouquinho.`));return}let i=!o;n.send([{t:i?`like`:`unlike`,buildingId:e.id}]),l={kind:`like`,at:r()},o=i,a=Math.max(0,a+(i?1:-1)),d.classList.remove(`is-pop`),d.offsetWidth,i&&d.classList.add(`is-pop`),v()}function x(){P(p,!0),f.setAttribute(`aria-expanded`,`false`)}function S(){if(h())return;let e=p.hidden;P(p,!e),f.setAttribute(`aria-expanded`,String(e))}function C(e){let i=n.building();!i||n.mine()||h()||(n.send([{t:`stamp`,buildingId:i.id,stampId:e}]),l={kind:`stamp`,at:r(),stampId:e},_(i.id,e),n.toast(`${De(e)} ${t(`Carimbo deixado na portaria: {0}`,[Ne(e)])}`),v())}function w(e){if(!e||typeof e!=`object`)return!1;let i=e;if(i.t===`like.update`&&i.buildingId===s&&typeof i.likes==`number`)return a=i.likes,o=i.likedByMe===!0,l?.kind===`like`&&(l=null),v(),!1;if(i.t!==`notice`||typeof i.text!=`string`||!l||r()-l.at>Ft)return!1;let c=l;if(l=null,c.kind===`stamp`){let e=zt(i.text);return e===`ok`?!0:e===`already`?(n.toast(t(`Você já deixou um carimbo aqui hoje.`)),!0):(_(s,null),v(),n.toast(i.text===`too_far`?t(`Entre no prédio ou chegue mais perto da porta para carimbar.`):t(`O carimbo não foi deixado. Tente de novo.`)),!0)}if(i.text===`daily_limit`)n.toast(t(`Você já deu os 50 likes de hoje. Amanhã tem mais!`));else if(i.text===`rate_limited`)n.toast(t(`Devagar com os likes: espere um pouquinho.`));else return!1;return o=!o,a=Math.max(0,a+(o?1:-1)),v(),!0}return y(),{el:m,message:w,sync:y,stampedToday:h,destroy:()=>m.remove()}}function Ht(e){return e.count>1?`${e.label} ×${e.count}`:e.label}function Ut(e){return e.state===`away`?`away`:e.discreet===!0?`discreet`:`live`}function Wt(e){return e===1?t(`1 agente`):t(`{0} agentes`,[e])}function Gt(e){return e===1?t(`1 visitante agora`):t(`{0} visitantes agora`,[e])}function Kt(e){return Fe(e.building)?0:e.floors.reduce((e,t)=>e+(Array.isArray(t.agents)?t.agents.length:0),0)}function qt(e,n){let r=e.building,i=Ut(r),a=[He(e.floors.length)];return i===`live`?a.push(Wt(Kt(e))):a.push(t(i===`away`?`apagado`:`modo discreto`)),{title:n?t(`Seu prédio, como os outros veem`):t(`Prédio de {0}`,[r.owner.name]),details:a,mode:i===`live`?null:i}}var Jt=[`working`,`waiting`,`idle`,`shell`];function Yt(e){switch(e){case`working`:return t(`trabalhando`);case`waiting`:return t(`esperando o dono`);case`shell`:return t(`de olho no terminal`);default:return t(`à toa`)}}function Xt(e){let n=Jt.includes(e.status)?e.status:`idle`,r=e.provider===`codex`?`codex`:`claude`;return{id:ne(e.id),name:typeof e.name==`string`&&e.name?e.name:t(`Agente`),role:e.kind===`sub`?t(`Subagente`):t(`Agente principal`),tool:Ie[r].name,status:n,statusText:Yt(n)}}function Zt(e){let n=Fe(e.building),r=e.floors.map(e=>({id:e.id,name:R(typeof e.label==`string`?e.label:``),agents:n||!Array.isArray(e.agents)?[]:e.agents.map(Xt)})),i=Ut(e.building);return{rooms:r,empty:i===`away`?t(`Prédio apagado: o dono pausou ou não está com o Habblaud aberto. As salas ficam escuras e vazias.`):i===`discreet`?t(`Modo discreto: o dono não mostra os agentes. As salas aparecem vazias, com a luz acesa.`):null}}function Qt(e,t){if(Fe(e.building))return null;for(let n of e.floors)for(let e of Array.isArray(n.agents)?n.agents:[])if(ne(e.id)===t)return{...Xt(e),room:R(n.label)};return null}var $t=class{deps;id;rev;detail;snapshot;leaving=!1;resyncAt=-1/0;constructor(e,t){this.deps=t,this.id=e.id,this.rev=e.rev,this.detail=structuredClone(e.detail),this.snapshot=ge(this.detail,t.now(),{version:t.version}),t.push(this.snapshot)}get light(){return Ut(this.detail.building)}replace(e){let t=structuredClone(e.detail),n=he(this.snapshot,{rev:e.rev,floors:t.floors,building:t.building},this.deps.now());this.rev=e.rev,this.detail=t,this.resyncAt=-1/0,this.publish(n.snapshot)}patch(e){let t=L(this.rev,e.rev);if(t===`stale`)return t;if(t===`resync`){let e=this.deps.now();return e-this.resyncAt>=5e3&&(this.resyncAt=e,this.deps.send([{t:`resync`,building:this.id}])),t}let n=he(this.snapshot,e,this.deps.now(),this.detail.building);return this.rev=e.rev,e.floors&&(this.detail.floors=structuredClone(e.floors)),e.building&&(this.detail.building=structuredClone(e.building)),typeof e.visitors==`number`&&(this.detail.visitors=e.visitors),this.publish(n.snapshot),t}leave(){return!this.leaving&&(this.leaving=!0,this.deps.send([{t:`leave`}]),this.deps.changed?.(),!0)}publish(e){e!==this.snapshot&&(this.snapshot=e,this.deps.push(e)),this.deps.changed?.()}},en=8e3,tn=`(max-width: 760px)`;function nn(e){let r=document.createElement(`canvas`);r.id=`visit`,e.after.after(r);let i=new w({search:``}),a=Pe(r,i,{visit:!0}),o=typeof matchMedia==`function`?matchMedia(tn):null,s=()=>!!o?.matches,c=!s(),l=!1,u=null,d=0,f=``;a.visit.setLight(Ut(e.inside.detail.building));let p=new $t(e.inside,{push:e=>i.pushReplay(e),send:t=>e.send(t),now:()=>Date.now(),version:e.version,changed:()=>ae()});a.visit.setVisitor({name:e.me.name,look:e.me.look,parts:e.me.parts});let m=N(`strong`,{class:`ui-visit-bar__title`}),h=N(`span`,{class:`ui-visit-bar__details`}),g=N(`span`,{class:`ui-visit-bar__mode`,hidden:!0}),_=N(`span`,{class:`ui-visit-bar__visitors`}),v=N(`button`,{class:`ui-btn ui-visit-bar__panel`,type:`button`,attrs:{"aria-expanded":`false`,"aria-controls":`ui-visit-panel`},on:{click:()=>le(!c)}}),y=N(`button`,{class:`ui-btn ui-btn--primary ui-visit-bar__leave`,type:`button`,text:t(`Sair do prédio`),title:t(`Sair do prédio (Esc)`),on:{click:()=>Se()}}),b=N(`header`,{class:`ui-visit-bar`,attrs:{"aria-label":t(`Visita`)}},N(`div`,{class:`ui-visit-bar__text`},N(`div`,{class:`ui-visit-bar__line`},m,g),N(`div`,{class:`ui-visit-bar__line`},h,_)),N(`div`,{class:`ui-visit-bar__actions`},v,y)),x=N(`strong`,{class:`ui-visit-card__name`}),S=N(`span`,{class:`ui-visit-card__meta`}),C=N(`span`,{class:`ui-visit-card__status`}),T=N(`span`,{class:`ui-visit-card__room`}),E=N(`section`,{class:`ui-visit-card`,hidden:!0,attrs:{"aria-live":`polite`,"aria-label":t(`Agente`)}},N(`div`,{class:`ui-visit-card__head`},x,N(`button`,{class:`ui-visit-card__close`,type:`button`,text:`×`,title:t(`Fechar`),attrs:{"aria-label":t(`Fechar`)},on:{click:()=>a.select(null)}})),S,N(`div`,{class:`ui-visit-card__row`},C,T)),ee=N(`p`,{class:`ui-visit-panel__empty`,hidden:!0}),D=N(`ul`,{class:`ui-visit-panel__rooms`}),O=N(`div`,{class:`ui-visit-panel__social`}),k=N(`aside`,{class:`ui-visit-panel`,attrs:{id:`ui-visit-panel`,"aria-label":t(`Salas do prédio`)}},O,N(`h3`,{class:`ui-visit-panel__title`,text:t(`Salas`)}),E,ee,D,N(`p`,{class:`ui-visit-panel__hint`,text:t(`Só o nome, o papel, a ferramenta e o status de cada agente: o resto do escritório não sai do computador do dono.`)})),A=N(`button`,{class:`ui-visit-exit`,type:`button`,hidden:!0,on:{click:()=>be()}},N(`kbd`,{text:`E`}),t(`Sair pelo elevador`)),te=N(`div`,{class:`ui-visit-help`,attrs:{"aria-hidden":`true`}},N(`span`,{},N(`kbd`,{text:`WASD`}),` `,t(`andar`)),N(`span`,{},N(`kbd`,{text:`Shift`}),` `,t(`correr`)),N(`span`,{},N(`kbd`,{text:t(`clique`)}),` `,t(`ir até lá`)),N(`span`,{},N(`kbd`,{text:`E`}),` `,t(`elevador`)),N(`span`,{},N(`kbd`,{text:`Esc`}),` `,t(`sair`))),j=N(`div`,{class:`ui-visit-leaving`,hidden:!0,role:`status`,text:t(`Saindo do prédio…`)}),F=N(`div`,{class:`ui-visit-board__pins`}),I=N(`div`,{class:`ui-visit-board`,hidden:!0,role:`img`},F),L=N(`div`,{class:`ui-visit`},I,b,k,A,te,j);e.uiRoot.append(L),e.uiRoot.classList.add(`is-visit`);let R=Vt(O,{building:()=>l?null:p.detail.building,mine:()=>e.mine,send:t=>e.send(t),toast:t=>e.toast(t)}),ne=``;function re(){let r=R.stampedToday(),i=e.mine?(e.summaryStamps?.()??[]).map(e=>({stampId:e.stampId,count:e.count})):r?[{stampId:r,mine:!0}]:[],a=JSON.stringify(i);if(a===ne)return;ne=a;let o=Bt(i,n(p.id));F.replaceChildren(...o.map(e=>N(`span`,{class:`ui-visit-board__pin${e.mine?` is-mine`:``}`,text:e.icon,title:Ht(e),attrs:{style:`left:${(e.x*100).toFixed(1)}%;top:${(e.y*100).toFixed(1)}%;--rot:${e.rot}deg`}})));let s=o.length?`${t(`Carimbos da portaria`)}: ${o.map(Ht).join(`, `)}`:t(`Carimbos da portaria: nenhum ainda`);I.setAttribute(`aria-label`,s),I.title=s,I.classList.toggle(`is-empty`,!o.length)}let ie=``;function ae(){if(l)return;let n=p.detail,r=qt(n,e.mine);M(m,r.title),M(h,r.details.join(` · `)),P(g,!r.mode),M(g,r.mode===`away`?`🌙 ${t(`apagado`)}`:r.mode===`discreet`?`🙈 ${t(`discreto`)}`:``),g.className=`ui-visit-bar__mode${r.mode?` is-${r.mode}`:``}`,M(_,n.visitors>0?`👀 ${Gt(n.visitors)}`:``),P(j,!p.leaving),y.disabled=p.leaving,a.visit.setLight(p.light);let i=n.building.theme;i!==f&&(f=i,a.setOptions({...e.options(),theme:i===`halloween`||i===`christmas`?i:`none`}));let o=Zt(n);P(ee,!o.empty),M(ee,o.empty??``);let s=JSON.stringify(o.rooms);s!==ie&&(ie=s,D.replaceChildren(...o.rooms.map(e=>N(`li`,{class:`ui-visit-room`},N(`div`,{class:`ui-visit-room__head`},N(`span`,{class:`ui-visit-room__name`,text:e.name}),N(`span`,{class:`ui-visit-room__count`,text:String(e.agents.length)})),e.agents.length?N(`ul`,{class:`ui-visit-room__agents`},...e.agents.map(e=>N(`li`,{},N(`button`,{class:`ui-visit-agent is-${e.status}`,type:`button`,attrs:{"data-agent":e.id},on:{click:()=>se(e.id)}},N(`span`,{class:`ui-visit-agent__dot`,attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-visit-agent__name`,text:e.name}),N(`span`,{class:`ui-visit-agent__meta`,text:`${e.role} · ${e.tool}`}),N(`span`,{class:`ui-visit-agent__status`,text:e.statusText}))))):null)))),oe(),M(v,`${t(`Salas`)} (${n.floors.length})`),re(),v.setAttribute(`aria-expanded`,String(c)),L.classList.toggle(`has-panel`,c),ue()}function oe(){let e=a.getSelection(),t=e?.type===`agent`?Qt(p.detail,e.id):null;if(P(E,!t),t){M(x,t.name),M(S,`${t.role} · ${t.tool}`),M(C,t.statusText),C.className=`ui-visit-card__status is-${t.status}`,M(T,t.room);for(let e of D.querySelectorAll(`.ui-visit-agent`))e.classList.toggle(`is-selected`,e.dataset.agent===t.id)}}function se(e){if(!e)return a.select(null);a.select({type:`agent`,id:e},{focus:!0})}function le(e){c=e,ae()}function ue(){L.style.setProperty(`--ui-visit-top`,`${Math.round(e.topInset()+8)}px`);let t=b.getBoundingClientRect().bottom||e.topInset()+56,n=k.getBoundingClientRect();a.setViewInsets?.({top:t+4,right:c&&!s()?Math.max(0,window.innerWidth-n.left):0,bottom:c&&s()?Math.max(0,window.innerHeight-n.top):0,left:0})}let de=a.onSelect(()=>oe()),fe=new Set,pe=!1,me=()=>a.visit.setIntent(p.leaving?{dx:0,dy:0,run:!1}:Xe(fe,pe)),he=e=>{let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``))},ge=(e,t)=>{e.key===`Shift`?pe=t:typeof e.getModifierState==`function`&&(pe=e.getModifierState(`Shift`));let n=Ze(e);if(!t){n&&fe.delete(n),me();return}if(!(e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||he(e.target)||ce(e.target))){if(n){e.preventDefault(),fe.add(n),me();return}e.key===`e`||e.key===`E`||e.key===`Enter`&&!e.target?.closest?.(`button, a`)?(e.preventDefault(),be()):e.key===`+`||e.key===`=`?(e.preventDefault(),a.zoomBy(1.25)):e.key===`-`||e.key===`_`?(e.preventDefault(),a.zoomBy(1/1.25)):e.key===`0`&&(e.preventDefault(),a.overview())}},_e=e=>ge(e,!0),z=e=>ge(e,!1),ve=()=>{fe.clear(),pe=!1,me()};addEventListener(`keydown`,_e),addEventListener(`keyup`,z),addEventListener(`blur`,ve);let ye=()=>ue();addEventListener(`resize`,ye),o?.addEventListener(`change`,ye);function be(){p.leaving||a.visit.atExit()&&a.visit.exit(()=>Se())&&(fe.clear(),me())}function Se(){p.leave()&&(fe.clear(),me(),u=setTimeout(()=>{u=null,l||e.stuck()},en))}let Ce=()=>{d=requestAnimationFrame(Ce);let e=!p.leaving&&a.visit.atExit()?a.visit.visitorScreen():null;P(A,!e);let t=a.visit.boardScreen(),n=!!t&&t.h>=18;if(P(I,!n),t&&n&&(I.style.transform=`translate(${Math.round(t.x)}px, ${Math.round(t.y)}px)`,I.style.width=`${Math.round(t.w)}px`,I.style.height=`${Math.round(t.h)}px`,I.style.setProperty(`--pin`,`${Math.max(8,Math.round(t.h*.3))}px`)),e){let t=A.offsetWidth||150,n=Math.max(8,Math.min(window.innerWidth-t-8,e.x-t/2));A.style.transform=`translate(${Math.round(n)}px, ${Math.round(e.y-34)}px)`}};return d=requestAnimationFrame(Ce),ae(),requestAnimationFrame(()=>ue()),{id:p.id,controller:p,world:a,replace(e){p.replace(e),R.sync()},patch(e){p.patch(e),e.building&&R.sync()},message(e){if(l)return!1;let t=R.message(e);return re(),t},leave:Se,escape(){return a.getSelection()?(a.select(null),!0):s()&&c?(le(!1),!0):(Se(),!0)},openPanel(e=!0){le(e)},selectAgent:se,destroy(){l||(l=!0,u&&clearTimeout(u),cancelAnimationFrame(d),de(),R.destroy(),removeEventListener(`keydown`,_e),removeEventListener(`keyup`,z),removeEventListener(`blur`,ve),removeEventListener(`resize`,ye),o?.removeEventListener(`change`,ye),a.destroy(),r.remove(),L.remove(),e.uiRoot.classList.remove(`is-visit`),xe(Le()))}}}var rn=3.2,an=60,on=1e3,sn=4,cn=.5,ln=.25,un=10,dn={up:`n`,down:`s`,left:`w`,right:`e`},fn={n:`up`,s:`down`,w:`left`,e:`right`};function pn(e,t,n){return Math.abs(e)<1e-6&&Math.abs(t)<1e-6?n:Math.abs(e)>=Math.abs(t)?e>0?`right`:`left`:t>0?`down`:`up`}function mn(e,t){let n=e[e.length-1];n&&t.t<n.t&&(t={...t,t:n.t}),e.push(t),e.length>un&&e.splice(0,e.length-un)}function hn(e){let t=0,n=0;for(let r=e.length-1;r>0&&n<sn;r--){let i=e[r].t-e[r-1].t;i<=0||i>on||(t=Math.max(t,i),n++)}return Math.min(700,Math.max(150,t+an))}function gn(e,t,n){return t>e?Math.min(t,e+n*cn):Math.max(t,e-n*ln)}function _n(e,t){let n=e.length;if(!n)return null;let r=e[0];if(t<=r.t)return{x:r.x,y:r.y,dir:r.dir,moving:r.moving&&n>1,speed:0};for(let r=1;r<n;r++){let n=e[r];if(t>n.t)continue;let i=e[r-1],a=Math.max(1,n.t-i.t),o=Math.min(1,Math.max(0,(t-i.t)/a)),s=Math.hypot(n.x-i.x,n.y-i.y);return{x:i.x+(n.x-i.x)*o,y:i.y+(n.y-i.y)*o,dir:n.dir,moving:s>.001||n.moving,speed:s*1e3/a}}let i=e[n-1],a=t-i.t>400;return{x:i.x,y:i.y,dir:i.dir,moving:i.moving&&!a,speed:0}}function vn(e,t,n,r,i=dt){let a=Math.max(1,Math.ceil(Math.max(Math.abs(n),Math.abs(r))/.5)),o=!1;for(let s=0;s<a;s++){let s=e+n/a;i(s,t)?e=s:o=!0;let c=t+r/a;i(e,c)?t=c:o=!0}return{x:e,y:t,blocked:o}}var yn=class{can;x;y;dir=`down`;moving=!1;running=!1;path=[];pathI=0;pathRun=!1;animT=0;constructor(e,t,n=dt){this.can=n,this.x=e,this.y=t}get hasPath(){return this.pathI<this.path.length}follow(e,t){this.path=e,this.pathI=0,this.pathRun=t}stopPath(){this.path=[],this.pathI=0}correct(e,t){this.x=e,this.y=t,this.stopPath()}update(e,t){let n=this.moving,r=this.running;e=Math.min(.1,Math.max(0,e));let i=t.dx,a=t.dy;if(i||a){this.stopPath();let n=Math.hypot(i,a);i/=n,a/=n;let r=(t.run?6:rn)*e,o=vn(this.x,this.y,i*r,a*r,this.can);this.dir=pn(i,a,this.dir),this.moving=Math.hypot(o.x-this.x,o.y-this.y)>1e-4,this.running=t.run&&this.moving,this.x=o.x,this.y=o.y}else if(this.hasPath){let t=(this.pathRun?6:rn)*e;for(this.moving=!0,this.running=this.pathRun;t>0&&this.hasPath;){let e=this.path[this.pathI],n=this.path[this.pathI+1],r=e-this.x,i=n-this.y,a=Math.hypot(r,i);a<=t?(this.x=e,this.y=n,t-=a,this.pathI+=2,a>1e-6&&(this.dir=pn(r,i,this.dir))):(this.x+=r/a*t,this.y+=i/a*t,this.dir=pn(r,i,this.dir),t=0)}this.hasPath||(this.moving=!1,this.running=!1)}else this.moving=!1,this.running=!1;n!==this.moving||r!==this.running?this.animT=0:this.animT+=e*1e3}};function bn(e,t,n,r){let i=[];for(let r=0;r<e.length;r+=2)i.push(e[r]+t+.5,e[r+1]+n+.5);return r&&i.length>=2?(i[i.length-2]=r.x,i[i.length-1]=r.y):r&&!i.length&&i.push(r.x,r.y),i}function xn(e){return Math.floor(e*100)/100}var Sn=class{send;lastAt=-1/0;last=null;constructor(e){this.send=e}tick(e,t){if(e-this.lastAt<100)return!1;let n={x:xn(t.x),y:xn(t.y),dir:dn[t.dir],moving:t.moving},r=this.last;return r&&r.x===n.x&&r.y===n.y&&r.dir===n.dir&&r.moving===n.moving?!1:(this.lastAt=e,this.last=n,this.send({t:`move`,...n}),!0)}keepAlive(e){let t={x:xn(e.x),y:xn(e.y),dir:dn[e.dir],moving:!1};this.lastAt=-1/0,this.last=t,this.send({t:`move`,...t})}reset(){this.last=null,this.lastAt=-1/0}},H={w:192,shadow:6,roof:26,floor:11,ground:30,maxFloors:12,cols:11,winX:11,winPitch:16,winW:10,winH:7},Cn=[{name:`tijolo`,wall:[`#7c3a2c`,`#9c4935`,`#b45a42`,`#c87256`],pattern:`brick`,trim:[`#cfc3b0`,`#ece4d6`],roof:[`#5d6470`,`#7a828e`],accent:[`#2f6fa8`,`#4f93cf`],frame:`#3a2a26`},{name:`tijolo claro`,wall:[`#9a7656`,`#b48c66`,`#c9a27a`,`#dcb990`],pattern:`brick`,trim:[`#e6ddd0`,`#f6f1e8`],roof:[`#646a74`,`#848a94`],accent:[`#1f7f75`,`#2fa597`],frame:`#4a3a2c`},{name:`concreto`,wall:[`#6f7884`,`#87909c`,`#9ea7b2`,`#b9c1ca`],pattern:`panel`,trim:[`#d6dce3`,`#eef1f4`],roof:[`#4b525c`,`#666d78`],accent:[`#d98a2b`,`#f2a33a`],frame:`#2e3648`},{name:`reboco`,wall:[`#c9c0b0`,`#ddd5c6`,`#ece6da`,`#f8f4ec`],pattern:`stucco`,trim:[`#a8977c`,`#c4b49a`],roof:[`#6f665e`,`#8e857b`],accent:[`#a8322a`,`#cf4a3c`],frame:`#4a4038`},{name:`vidro`,wall:[`#3f6f96`,`#5587b0`,`#6fa3c9`,`#9cc6e4`],pattern:`glass`,trim:[`#cdd8e2`,`#eef3f7`],roof:[`#353d48`,`#4c5562`],accent:[`#7451b8`,`#9a78dc`],frame:`#e8eef4`},{name:`tijolo escuro`,wall:[`#3e3433`,`#4f4241`,`#5f5150`,`#73625f`],pattern:`brick`,trim:[`#bdae98`,`#d8ccb8`],roof:[`#383b42`,`#50545c`],accent:[`#c8902a`,`#e8b04a`],frame:`#1f1a1a`},{name:`painel verde`,wall:[`#3a6e6a`,`#467f7b`,`#559491`,`#6caba7`],pattern:`panel`,trim:[`#dfe9e7`,`#f3f8f7`],roof:[`#3f4a53`,`#58646e`],accent:[`#d8603f`,`#f07c5a`],frame:`#24403e`},{name:`arenito`,wall:[`#b39b74`,`#c6ae86`,`#d8c39d`,`#e8d6b4`],pattern:`stone`,trim:[`#7f6a4c`,`#9c8562`],roof:[`#675e52`,`#83796b`],accent:[`#2f66b8`,`#3f7fd8`],frame:`#4a3d2c`},{name:`marinho`,wall:[`#1f2c4a`,`#283a5e`,`#314870`,`#3d5884`],pattern:`panel`,trim:[`#d58a24`,`#f2a33a`],roof:[`#262b36`,`#3a404c`],accent:[`#d58a24`,`#f2a33a`],frame:`#141b30`},{name:`menta`,wall:[`#7fae96`,`#93bea8`,`#a9cdb8`,`#c3dfcd`],pattern:`stucco`,trim:[`#f0ece2`,`#fbf9f4`],roof:[`#5f6871`,`#7b848d`],accent:[`#c95e8e`,`#e47aa8`],frame:`#3d5a4c`}];function wn(e){let t=Math.max(0,Math.min(H.maxFloors,Math.floor(e)));return H.roof+t*H.floor+H.ground}function Tn(e,t){let n=Array.from({length:t},(e,t)=>t),i=r(e*2654435761>>>0);for(let e=t-1;e>0;e--){let t=Math.floor(i()*(e+1));[n[e],n[t]]=[n[t],n[e]]}return n}function En(e,t,n){let r=Number.isFinite(e.floors)?Math.max(0,Math.floor(e.floors)):0,i=Math.min(H.maxFloors,r),a=Math.max(0,r-H.maxFloors),o=(n>>>0)%40,s=i*H.cols,c=e.state===`online`?`online`:`away`,l=!e.agents,u=0,d=0;if(c===`online`){if(!e.agents)u=4;else{let t=Math.max(0,e.agents.total);if(t>0){let n=Math.max(0,Math.min(t,e.agents.working));u=Math.round(n/t*8),n>0&&u===0&&(u=1);let r=Math.max(0,Math.min(t,e.agents.waiting));r>0&&(d=Math.max(1,Math.round(r/t*s)))}}}let f=Tn(o,s),p=Math.round(s*u/8),m=f.slice(0,p),h=f.slice(p,Math.min(s,p+d)),g=e.theme===`halloween`||e.theme===`christmas`?e.theme:`none`;return{side:t,variant:o,style:o%Cn.length,drawn:i,plus:a,state:c,theme:g,discreet:l,litLevel:u,lit:m,waiting:h,height:wn(i)}}function Dn(e){return`${e.side}|${e.variant}|${e.drawn}|${Math.min(99,e.plus)}|${e.state}|${e.theme}|${e.litLevel}`}function On(e,t){let n=t%H.cols,r=Math.floor(t/H.cols),i=e.drawn-1-r;return{x:H.winX+n*H.winPitch,y:H.roof+i*H.floor+2,w:H.winW,h:H.winH}}function kn(e){return e.side===`front`?{x:34,y:e.height-H.ground+2,w:H.w-68,h:8}:{x:50,y:11,w:H.w-100,h:8}}var An=new Map,jn=600;function Mn(e){let t=Dn(e),n=An.get(t);return n||(An.size>=jn&&An.clear(),n=Rn(e),An.set(t,n),n)}function Nn(e){return An.has(Dn(e))}function Pn(e,t){let n=document.createElement(`canvas`);n.width=e,n.height=t;let r=n.getContext(`2d`);return r.imageSmoothingEnabled=!1,[n,r]}var U=`#2e3648`,W=[`#c98f3c`,`#f2c66b`,`#ffe3a0`,`#fff4d2`],G=[`#1f3550`,`#2b4868`,`#3c5f84`,`#7fa6cc`],Fn=new Map;function In(e){let t=Fn.get(e);if(!t){let{buf:n}=ue(e);t=document.createElement(`canvas`),t.width=n.w,t.height=n.h,t.getContext(`2d`).putImageData(new ImageData(n.data,n.w,n.h),0,0),Fn.set(e,t)}return t}function Ln(e,t,n,r){let i=In(t);e.drawImage(i,Math.round(n-20),Math.round(r-60))}function K(e,t,n,r,i,a){e.fillStyle=a,e.fillRect(t,n,r,i)}function Rn(e){let t=H.w+H.shadow,n=e.height,[i,a]=Pn(t,n),[o,s]=Pn(t,n),c=Cn[e.style],l=r((e.variant+1)*2654435761>>>0),u=e.state===`online`,d=H.roof,f=n-H.ground,p=H.w;a.fillStyle=`rgba(28,36,52,0.22)`,a.fillRect(p,6,H.shadow,n-6),a.fillStyle=`rgba(28,36,52,0.12)`,a.fillRect(p,10,2,n-10),zn(a,c,0,d,p,n-d,l);for(let t=0;t<=e.drawn;t++)K(a,0,d+t*H.floor-1,p,1,c.pattern===`glass`?c.trim[0]:q(c.wall[0],-.08));K(a,0,d,3,n-d,c.trim[0]),K(a,p-3,d,3,n-d,c.trim[0]),K(a,0,d,1,n-d,c.trim[1]);let m=new Set(e.lit),h=e.drawn*H.cols;for(let t=0;t<h;t++){let n=On(e,t);Bn(a,c,n.x,n.y,m.has(t),(e.variant*31+t)%7),m.has(t)&&Vn(s,n.x,n.y)}if(e.side===`back`&&e.drawn>0){Hn(a,e.variant%2==0?H.winX+H.winPitch-3:H.winX+(H.cols-2)*H.winPitch-3,d,e.drawn);for(let t=0;t<e.drawn;t++)if(l()<.45){let n=2+Math.floor(l()*(H.cols-4)),r=On(e,(e.drawn-1-t)*H.cols+n);Un(a,r.x+1,r.y+r.h+1)}}if(e.side===`front`?Wn(a,s,c,e,f,u,l):Gn(a,s,c,e,f,u,l),qn(a,s,c,e,l),Yn(a,s,e,f),e.side===`back`&&Jn(a,s,c,e),u||Kn(a,p/2,e.side===`front`?f+16:1),e.plus>0){let t=`+${Math.min(99,e.plus)}`,n=ie(t),r=e.side===`front`?p-n-18:16,i=e.side===`front`?6:13;K(a,r-3,i-3,n+6,11,U),K(a,r-2,i-2,n+4,9,u?c.accent[1]:`#5a6170`),K(a,r-2,i-2,n+4,1,u?$n(c.accent[1],.25):`#6d7483`),ve(a,t,r,i,`#ffffff`),K(a,r+n/2-1,i+8,2,3,U),u&&(s.fillStyle=`rgba(255,255,255,0.85)`,ve(s,t,r,i,`#fff6dc`))}return{canvas:i,glow:o,w:t,h:n}}function zn(e,t,n,r,i,a,o){let[s,c,l,u]=t.wall;switch(K(e,n,r,i,a,c),t.pattern){case`brick`:for(let t=r;t<r+a;t+=3){let a=(t-r)/3%2==0?0:3;K(e,n,t+2,i,1,s);for(let r=n+a;r<n+i;r+=6){K(e,r,t,1,2,s);let n=o();n<.18?K(e,r+1,t,5,2,l):n<.26&&K(e,r+1,t,5,2,q(c,-.06))}}break;case`panel`:for(let t=n;t<n+i;t+=24)K(e,t,r,1,a,s);for(let t=r+5;t<r+a;t+=11)K(e,n,t,i,1,q(c,-.05));K(e,n,r,i,1,l);break;case`stucco`:for(let t=0;t<i*a/40;t++)K(e,n+Math.floor(o()*i),r+Math.floor(o()*a),1,1,o()<.5?l:q(c,-.04));break;case`stone`:for(let t=r;t<r+a;t+=5){K(e,n,t+4,i,1,s);let a=(t-r)/5%2==0?0:7;for(let r=n+a;r<n+i;r+=14)K(e,r,t,1,4,s),o()<.3&&K(e,r+1,t,13,1,u)}break;case`glass`:K(e,n,r,i,a,t.wall[1]);for(let o=r;o<r+a;o++)(o-r)%11<3&&K(e,n,o,i,1,t.wall[2]);for(let o=n+3;o<n+i;o+=16)K(e,o,r,1,a,t.frame);e.fillStyle=`rgba(255,255,255,0.12)`;for(let t=0;t<a;t++)e.fillRect(n+(t*2+40)%(i+40)-20,r+t,10,1)}}function Bn(e,t,n,r,i,a){let o=H.winW,s=H.winH;t.pattern!==`glass`&&(K(e,n-1,r-1,o+2,s+2,t.frame),K(e,n-1,r+s+1,o+2,1,t.trim[1]),K(e,n-1,r+s+2,o+2,1,q(t.trim[0],-.15))),i?(K(e,n,r,o,s,W[2]),K(e,n,r,o,2,W[3]),K(e,n,r+s-2,o,2,W[1]),K(e,n+2+a%4,r+s-3,3,2,`#5fb8f0`),K(e,n+2+a%4,r+s-3,1,1,`#c8ecff`),(a===2||a===5)&&K(e,n+6-a%3,r+s-4,2,3,`#7a5a3a`)):(K(e,n,r,o,s,G[1]),K(e,n,r,o,2,G[0]),K(e,n,r+s-1,o,1,G[2]),K(e,n+1+a%3,r+2,1,3,G[3]),K(e,n+2+a%3,r+2,1,1,`#b8d2ea`),a===4&&K(e,n+1,r+1,o-2,2,`#c9cfd9`)),K(e,n+(o>>1),r,1,s,t.pattern===`glass`?t.frame:q(t.frame,.1))}function Vn(e,t,n){let r=H.winW,i=H.winH;e.fillStyle=W[2],e.fillRect(t,n,r,i),e.fillStyle=W[3],e.fillRect(t,n,r,2),e.fillStyle=`#5fb8f0`,e.fillRect(t+3,n+i-3,3,2),e.fillStyle=`rgba(255,214,140,0.35)`,e.fillRect(t-1,n-1,r+2,i+2)}function Hn(e,t,n,r){let i=`#2a2f3a`,a=`#5b6475`;for(let o=0;o<r;o++){let s=n+o*H.floor+H.floor-2;K(e,t-2,s,18,1,a),K(e,t-2,s+1,18,1,i),K(e,t-2,s-4,18,1,i);for(let n=0;n<18;n+=3)K(e,t-2+n,s-4,1,4,i);if(o<r-1){let n=o%2==0?1:-1;for(let r=0;r<H.floor;r++)K(e,t+7+n*(r-5),s+2+r,2,1,r%2?i:a)}}}function Un(e,t,n){K(e,t,n,7,4,U),K(e,t+1,n,5,3,`#c9d0d8`),K(e,t+1,n,5,1,`#e8edf2`),K(e,t+2,n+1,3,1,`#8b95a3`)}function Wn(e,t,n,r,i,a,o){let s=H.w,c=r.height-2;K(e,0,i,s,H.ground,n.trim[0]),K(e,0,i,s,1,n.trim[1]),K(e,0,i+1,s,1,q(n.trim[0],-.2));let l=kn(r);K(e,l.x-2,l.y-1,l.w+4,l.h+2,U),K(e,l.x-1,l.y,l.w+2,l.h,a?n.accent[0]:`#4a505c`),K(e,l.x-1,l.y,l.w+2,1,a?n.accent[1]:`#5b6270`),a&&(t.fillStyle=`rgba(255,240,200,0.55)`,t.fillRect(l.x-1,l.y,l.w+2,l.h));let u=s/2-16,d=s/2+16,f=i+12,p=c-f-2;for(let[r,i]of[[6,u-6],[d+6,s-6]]){if(K(e,r-1,f-1,i-r+2,p+2,U),a){K(e,r,f,i-r,p,W[2]),K(e,r,f,i-r,2,W[3]),K(e,r,f+p-3,i-r,3,W[1]);for(let t=r+4;t<i-4;t+=9+Math.floor(o()*5))K(e,t,f+p-6,5,3,`#8a6243`),o()<.5?K(e,t+1,f+p-9,3,3,`#4b8a45`):K(e,t+1,f+p-8,3,2,`#5fb8f0`);t.fillStyle=W[2],t.fillRect(r,f,i-r,p),t.fillStyle=`rgba(255,214,140,0.3)`,t.fillRect(r-2,f-2,i-r+4,p+4)}else{K(e,r,f,i-r,p,G[1]),K(e,r,f,i-r,2,G[0]);for(let t=r+3;t<i;t+=13)K(e,t,f+2,2,p-3,G[2])}for(let t=r+16;t<i-2;t+=16)K(e,t,f,1,p,n.frame===`#e8eef4`?`#cdd8e2`:U);K(e,r-1,f-4,i-r+2,3,n.accent[0]);for(let t=r;t<i;t+=4)K(e,t,f-4,2,3,n.accent[1]);K(e,r-1,f-1,i-r+2,1,q(n.accent[0],-.25))}let m=i+9;K(e,u-2,m-2,36,c-m+2,U),K(e,u-1,m-1,34,c-m+1,n.trim[1]);for(let n of[u,s/2+1])K(e,n,m,15,c-m,U),K(e,n+1,m+1,13,c-m-1,a?`#f6dd9a`:G[1]),K(e,n+1,m+1,13,2,a?W[3]:G[0]),K(e,n+2,m+3,1,c-m-6,a?`#fff6dc`:G[3]),K(e,n===u?n+12:n+2,m+9,1,4,`#c9cfd9`),a&&(t.fillStyle=`#f6dd9a`,t.fillRect(n+1,m+1,13,c-m-1));K(e,0,c,s,2,q(n.trim[0],-.25)),K(e,u-4,c-1,40,3,`#c9cdd3`),K(e,u-4,c-1,40,1,`#e4e7eb`);for(let n of[u-6,d+4])K(e,n,m+2,3,4,U),K(e,n+1,m+3,1,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.9)`,t.fillRect(n,m+2,3,4),t.fillStyle=`rgba(255,220,150,0.25)`,t.fillRect(n-3,m,9,10))}function Gn(e,t,n,r,i,a,o){let s=H.w,c=r.height-2;K(e,0,i,s,2,q(n.wall[0],-.1));for(let r=12;r<s-12;r+=22){if(Math.abs(r+5-s/2)<18)continue;K(e,r-1,i+5,12,6,n.frame);let c=a&&o()<.5;K(e,r,i+6,10,4,c?W[2]:G[1]),K(e,r,i+6,10,1,c?W[3]:G[0]),c&&(t.fillStyle=W[2],t.fillRect(r,i+6,10,4))}let l=s/2-7;K(e,l-1,i+9,16,c-i-9,U),K(e,l,i+10,14,c-i-10,`#7d8794`),K(e,l,i+10,14,1,`#a9b2bd`),K(e,l+11,i+18,1,3,`#d9dee4`),K(e,l+3,i+12,8,2,`#5f6875`),K(e,l+5,i+6,4,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.9)`,t.fillRect(l+5,i+6,4,2));for(let[t,n]of[[22,`#3f7f4f`],[32,`#2f5f9e`]])K(e,t-1,c-9,9,9,U),K(e,t,c-8,7,8,n),K(e,t,c-8,7,2,$n(n,.2));let u=s-40;for(let t=0;t<2;t++){let n=u+t*12;e.strokeStyle=`#2a2f3a`,e.lineWidth=1,e.beginPath(),e.arc(n+2.5,c-3.5,3,0,Math.PI*2),e.arc(n+10.5,c-3.5,3,0,Math.PI*2),e.stroke(),K(e,n+3,c-6,7,1,t?`#cf4a3c`:`#2fa597`)}K(e,0,c,s,2,q(n.trim[0],-.25))}function Kn(e,n,r){let i=t(`Fechado`),a=Math.min(40,ie(i)),o=a+6,s=Math.round(n-o/2);K(e,s+2,r-4,1,4,`#3a2a20`),K(e,s+o-3,r-4,1,4,`#3a2a20`),K(e,s-1,r-1,o+2,10,`#3a2a20`),K(e,s,r,o,8,`#c98f5a`),K(e,s,r,o,1,`#e3ad78`),e.save(),e.beginPath(),e.rect(s+3,r,a,8),e.clip(),ve(e,i,s+3,r+2,`#3a2a20`),e.restore()}function qn(e,t,n,r,i){let a=H.w,o=H.roof,s=r.state===`online`;K(e,0,0,a,o-5,U),K(e,1,1,a-2,o-6,n.roof[1]),K(e,3,3,a-6,o-10,n.roof[0]);for(let t=0;t<90;t++)K(e,3+Math.floor(i()*(a-6)),3+Math.floor(i()*(o-10)),1,1,i()<.5?n.roof[1]:q(n.roof[0],-.12));K(e,0,o-5,a,4,n.trim[0]),K(e,0,o-5,a,1,n.trim[1]),K(e,0,o-2,a,1,q(n.trim[0],-.3)),K(e,0,o-1,a,1,`rgba(28,36,52,0.35)`);let c=r.side===`back`?[14,150]:[14,60,120,160];for(let t of c){let n=i(),r=t+Math.floor(i()*10);n<.35?(K(e,r,4,12,12,U),K(e,r+1,5,10,10,`#9aa6b4`),K(e,r+1,5,10,3,`#c3ccd6`),K(e,r+3,6,6,1,`#e3e8ee`)):n<.7?(K(e,r,6,14,9,U),K(e,r+1,7,12,7,`#d4dae1`),K(e,r+1,7,12,2,`#eef1f4`),K(e,r+4,9,6,4,`#8b95a3`),K(e,r+6,10,2,2,`#5f6875`)):(K(e,r,6,16,9,U),K(e,r+1,7,14,7,s?`#9cc6e4`:`#3c5f84`),K(e,r+1,7,14,2,`#c8e2f4`),K(e,r+8,7,1,7,U))}if(i()<.5){let n=r.side===`back`?176:100+Math.floor(i()*40);K(e,n,1,1,9,`#4a5468`),K(e,n-2,3,5,1,`#4a5468`),K(e,n,1,1,1,s?`#ff5a4a`:`#8b95a3`),s&&(t.fillStyle=`#ff5a4a`,t.fillRect(n,1,1,1))}}function Jn(e,t,n,r){let i=H.w,a=r.state===`online`;{let o=kn(r);K(e,o.x-2,o.y-1,o.w+4,o.h+2,U),K(e,o.x-1,o.y,o.w+2,o.h,a?n.accent[0]:`#4a505c`),K(e,o.x-1,o.y,o.w+2,1,a?n.accent[1]:`#5b6270`),a&&(t.fillStyle=`rgba(255,240,200,0.55)`,t.fillRect(o.x-1,o.y,o.w+2,o.h));let s=i/2-22;K(e,s-1,0,46,10,U);for(let t=0;t<44;t++){let r=Math.floor(t/4)%2==0;K(e,s+t,0,1,9,r?n.accent[1]:`#f6efe2`)}K(e,s,0,44,2,`rgba(255,255,255,0.35)`),K(e,s,7,44,2,`rgba(28,36,52,0.25)`);for(let n of[s+3,s+39])K(e,n,1,2,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.95)`,t.fillRect(n,1,2,2))}}function Yn(e,t,n,r){if(n.theme===`none`){if(n.side===`front`){let t=H.w,r=n.height-2;for(let n of[t/2-26,t/2+20])K(e,n,r-6,6,6,U),K(e,n+1,r-5,4,5,`#c97a4a`),K(e,n-1,r-11,8,6,`#3f8550`),K(e,n,r-12,6,2,`#5aa45d`)}return}let i=H.w,a=H.roof,o=n.state===`online`,s=n.theme===`christmas`;if(s){e.fillStyle=`#f4f8fb`;for(let t=2;t<i-2;t+=1){let n=Math.sin(t*.35)+Math.sin(t*.11);n>-.4&&e.fillRect(t,2,1,2+ +(n>.8))}e.fillRect(0,a-6,i,2),e.fillStyle=`#dbe6ee`,e.fillRect(0,a-4,i,1);for(let t=6;t<i-6;t+=23)e.fillRect(t,6+t%7,6,2)}let c=s?[`#ff5a5a`,`#ffd76a`,`#6ad1ff`,`#7be07b`]:[`#b06ae6`,`#ff9a3c`];for(let n=4,r=0;n<i-2;n+=6,r++){let i=a+r%2;K(e,n,i-1,1,1,`#2e3648`),K(e,n,i,2,2,c[r%c.length]),o&&(t.fillStyle=c[r%c.length],t.fillRect(n,i,2,2),t.globalAlpha=.35,t.fillRect(n-1,i-1,4,4),t.globalAlpha=1)}if(!s){e.strokeStyle=`rgba(230,220,240,0.8)`,e.lineWidth=1;for(let t of[1,-1]){let n=t===1?3.5:i-3.5,r=a+.5;e.beginPath();for(let[i,a]of[[9,0],[7,5],[0,9]])e.moveTo(n,r),e.lineTo(n+t*i,r+a);e.moveTo(n+t*4,r),e.lineTo(n+t*3,r+3),e.lineTo(n,r+4),e.stroke()}for(let t of[40,132]){let n=a-9;K(e,t,n,3,2,`#47344f`),K(e,t-3,n-1,3,2,`#47344f`),K(e,t+3,n-1,3,2,`#47344f`),K(e,t+1,n,1,1,`#f5b95f`)}}let l=n.height-2;n.side===`front`?s?(Xn(e,t,i/2-19,r+6,38,o),Ln(e,`tree`,i-30,l+2),Ln(e,`gift`,i-52,l+2)):(Ln(e,`pumpkin`,i/2-28,l+2),Ln(e,`pumpkin`,i/2+28,l+2),n.drawn>0&&Ln(e,`ghost`,30,r+6)):s?(Xn(e,t,i/2-10,r+6,20,o),Ln(e,`tree`,i/2+30,l+2)):(Ln(e,`pumpkin`,i/2-22,l+2),Ln(e,`pumpkin`,i/2+22,l+2))}function Xn(e,t,n,r,i,a){for(let o=0;o<i;o++){let s=Math.round(Math.sin(o/i*Math.PI)*3);K(e,n+o,r+s,1,3,o%3==0?`#245644`:`#347653`),o%6==3&&(K(e,n+o,r+s+2,2,2,[`#ffd76a`,`#ff5a5a`,`#6ad1ff`][o/6%3|0]),a&&(t.fillStyle=`#ffe9a8`,t.fillRect(n+o,r+s+2,2,2)))}for(let t of[n-1,n+i-3])K(e,t,r-1,4,3,`#c93945`),K(e,t+1,r+2,1,3,`#a82d42`),K(e,t+2,r+2,1,2,`#a82d42`)}function Zn(e){let t=parseInt(e.slice(1,7),16);return[t>>16&255,t>>8&255,t&255]}function Qn(e,t,n){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function q(e,t){let[n,r,i]=Zn(e);return t<0?Qn(n*(1+t),r*(1+t),i*(1+t)):Qn(n+(255-n)*t,r+(255-r)*t,i+(255-i)*t)}function $n(e,t){return q(e,Math.abs(t))}function er(e,t){let n=document.createElement(`canvas`);n.width=e,n.height=t;let r=n.getContext(`2d`);return r.imageSmoothingEnabled=!1,[n,r]}var J=e=>e*16;function Y(e){try{e()}catch{}}function tr(e,t,n,r,i,a=.16){e.save();try{e.globalCompositeOperation=`saturation`,e.fillStyle=`rgba(128,128,128,${a})`,e.fillRect(t,n,r,i)}catch{}e.restore()}function nr(e,t,n,r,i,a){let o=`#e2dfd6`,s=`#8d8a82`,c=`#5f5c56`;a===`s`?(e.fillStyle=o,e.fillRect(t,n+i-3,r,1),e.fillStyle=s,e.fillRect(t,n+i-2,r,2),e.fillStyle=c,e.fillRect(t,n+i,r,1)):a===`n`?(e.fillStyle=c,e.fillRect(t,n,r,1),e.fillStyle=o,e.fillRect(t,n+1,r,1)):a===`e`?(e.fillStyle=o,e.fillRect(t+r-2,n,1,i),e.fillStyle=s,e.fillRect(t+r-1,n,1,i),e.fillStyle=`rgba(40,40,40,0.35)`,e.fillRect(t+r,n,1,i)):(e.fillStyle=`rgba(40,40,40,0.35)`,e.fillRect(t-1,n,1,i),e.fillStyle=s,e.fillRect(t,n,1,i),e.fillStyle=o,e.fillRect(t+1,n,1,i))}function rr(e,t,n){let i=ot();for(let n of[...i.streets,i.intersection])Y(()=>e.drawFloor(t,`street`,J(n.x),J(n.y),J(n.w),J(n.h),{seed:13}));t.fillStyle=`rgba(20,22,28,0.18)`;let a=J(i.sidewalkOuter.w),o=J(i.sidewalkOuter.h);t.fillRect(a,0,3,o),t.fillRect(0,o,a,3),t.fillStyle=`rgba(255,226,140,0.85)`;for(let[e,n,r,a]of i.laneMarks)if(n===a)for(let i=J(e);i<J(r)-8;i+=24)t.fillRect(i,J(n)-1,12,2);else for(let r=J(n);r<J(a)-8;r+=24)t.fillRect(J(e)-1,r,2,12);for(let e of i.crosswalks){let n=e.rect;if(t.fillStyle=`rgba(244,244,236,0.9)`,e.across===`ns`)for(let e=J(n.y)+4;e<J(n.y+n.h)-3;e+=6)t.fillRect(J(n.x)+3,e,J(n.w)-6,3);else for(let e=J(n.x)+4;e<J(n.x+n.w)-3;e+=6)t.fillRect(e,J(n.y)+3,3,J(n.h)-6)}t.fillStyle=`rgba(244,244,236,0.75)`,t.fillRect(a-2,o+2,2,J(2)-2),t.fillRect(a+J(3),o-2,J(2)-2,2);let s=r(n);for(let e=0;e<3;e++){let e=J(4+Math.floor(s()*36));t.fillStyle=`#3a3d44`,t.fillRect(e,o+4,10,3),t.fillStyle=`#2a2c31`;for(let n=1;n<10;n+=2)t.fillRect(e+n,o+4,1,3)}let c=a+J(2)+2,l=J(8+Math.floor(s()*10));t.fillStyle=`#3f4249`,t.beginPath(),t.ellipse(c+6,l+5,6,4.5,0,0,Math.PI*2),t.fill(),t.fillStyle=`#585c64`,t.fillRect(c+2,l+4,8,1),t.fillRect(c+3,l+6,6,1)}function ir(e,t){let n=ot().sidewalkOuter;Y(()=>e.drawFloor(t,`sidewalk`,J(n.x),J(n.y),J(n.w),J(n.h),{seed:12})),nr(t,0,0,J(n.w),2,`n`),nr(t,0,J(n.h)-3,J(n.w),3,`s`),nr(t,0,0,2,J(n.h),`w`),nr(t,J(n.w)-3,0,3,J(n.h),`e`)}function ar(e,t){let n=ot(),r=n.block;Y(()=>e.drawFloor(t,`grass`,J(r.x),J(r.y),J(r.w),J(r.h),{seed:11})),tr(t,J(r.x),J(r.y),J(r.w),J(r.h)),t.fillStyle=`rgba(40,70,40,0.18)`;for(let e of n.lots)t.fillRect(J(e.x+e.w)-1,J(e.y),1,J(e.h)),t.fillRect(J(e.x),J(e.y+e.h)-1,J(e.w),1);let a=J(r.x),o=J(r.y),s=J(r.w),c=J(r.h);t.fillStyle=`#9a968c`,t.fillRect(a,o,s,2),t.fillRect(a,o+c-2,s,2),t.fillRect(a,o,2,c),t.fillRect(a+s-2,o,2,c),t.fillStyle=`#c9c5bb`,t.fillRect(a,o,s,1),t.fillRect(a,o+c-2,s,1),t.fillRect(a,o,1,c),t.fillRect(a+s-2,o,1,c);for(let a of n.lots){let n=a.y===r.y,s=J(a.x+i.dx);Y(()=>e.drawFloor(t,`sidewalk`,s,n?o:o+c-2,J(i.w),2,{seed:12}))}}function or(e){let t=ot(),[n,r]=er(J(t.sidewalkOuter.w+t.streets[0].w),J(t.sidewalkOuter.h+t.streets[1].h));return rr(e,r,77),ir(e,r),ar(e,r),n}function sr(e){let t=ot(),[n,r]=er(J(t.sidewalkOuter.w+t.streets[0].w),J(t.sidewalkOuter.h+t.streets[1].h));rr(e,r,99),ir(e,r);let i=t.block,a=J(i.x),o=J(i.y),s=J(i.w),c=J(i.h);Y(()=>e.drawFloor(r,`sidewalk`,a,o,s,c,{seed:23})),r.fillStyle=`rgba(196,150,96,0.10)`,r.fillRect(a,o,s,c),r.fillStyle=`#9a8f80`,r.fillRect(a+J(1),o+J(1),s-J(2),3),r.fillRect(a+J(1),o+c-J(1)-3,s-J(2),3),r.fillRect(a+J(1),o+J(1),3,c-J(2)),r.fillRect(a+s-J(1)-3,o+J(1),3,c-J(2)),r.fillStyle=`rgba(255,248,232,0.5)`,r.fillRect(a+J(1),o+J(1),s-J(2),1);let l=a+J(v.x+v.w/2),u=o+J(v.y+v.h/2);r.fillStyle=`rgba(236,226,206,0.55)`,r.fillRect(l-J(1.5),o+J(1)+3,J(3),c-J(2)-6),r.fillRect(a+J(1)+3,u-J(1.5),s-J(2)-6,J(3)),r.fillStyle=`rgba(140,128,110,0.45)`;for(let e of[-1,1])r.fillRect(l+e*J(1.5)-+(e>0),o+J(1)+3,1,c-J(2)-6),r.fillRect(a+J(1)+3,u+e*J(1.5)-+(e>0),s-J(2)-6,1);let d=[[2,2,10,6],[i.w-12,2,10,6],[2,i.h-8,10,6],[i.w-12,i.h-8,10,6]];for(let[t,n,i,s]of d){let c=a+J(t),l=o+J(n);r.fillStyle=`#8d8a82`,r.fillRect(c-2,l-2,J(i)+4,J(s)+4),r.fillStyle=`#d8d4ca`,r.fillRect(c-2,l-2,J(i)+4,1),Y(()=>e.drawFloor(r,`grass`,c,l,J(i),J(s),{seed:31})),tr(r,c,l,J(i),J(s))}let f=v,p=a+J(f.x+f.w/2),m=o+J(f.y+f.h/2);r.save(),r.beginPath(),r.ellipse(p,m,J(7),J(5.2),0,0,Math.PI*2),r.clip(),Y(()=>e.drawFloor(r,`marble`,p-J(8),m-J(6),J(16),J(12),{seed:41})),r.restore(),r.strokeStyle=`#8f8676`,r.lineWidth=3,r.beginPath(),r.ellipse(p,m,J(7)-1,J(5.2)-1,0,0,Math.PI*2),r.stroke(),r.strokeStyle=`rgba(63,127,216,0.35)`,r.lineWidth=2,r.setLineDash([4,4]),r.beginPath(),r.ellipse(p,m+4,J(4.8),J(3.4),0,0,Math.PI*2),r.stroke(),r.setLineDash([]),r.strokeStyle=`rgba(255,255,255,0.5)`,r.lineWidth=1,r.beginPath(),r.ellipse(p,m-1,J(7)-2,J(5.2)-2,0,Math.PI,Math.PI*2),r.stroke();let h=a+J(21)+8,g=o+J(15)+8;return r.fillStyle=`#b9b2a4`,r.beginPath(),r.moveTo(h,g-12),r.lineTo(h+4,g),r.lineTo(h,g+12),r.lineTo(h-4,g),r.closePath(),r.fill(),r.beginPath(),r.moveTo(h-12,g),r.lineTo(h,g-4),r.lineTo(h+12,g),r.lineTo(h,g+4),r.closePath(),r.fill(),r.fillStyle=`#f2a33a`,r.fillRect(h-1,g-11,2,6),n}function cr(e,t,n,r){let[a,o]=er(J(A.w),J(A.h)),s=J(i.dx),c=(t,n,i,a)=>{o.fillStyle=`#9a968c`,o.fillRect(t-1,n-1,i+2,a+2),Y(()=>e.drawFloor(o,`sidewalk`,t,n,i,a,{seed:12+r%3}))},l=J(A.h/2);switch(t){case`park`:n?c(s,0,J(2),l+8):c(s,l-8,J(2),J(A.h)-l+8),c(J(2),l-8,J(10),J(1)),o.fillStyle=`#6a4b35`,o.beginPath(),o.ellipse(J(7),l+14,18,7,0,0,Math.PI*2),o.fill(),o.strokeStyle=`#b9b5aa`,o.lineWidth=2,o.stroke();break;case`pond`:{n?c(s,0,J(2),J(2)):c(s,J(A.h-2),J(2),J(2));let e=J(7),t=l+(n?4:-4);o.fillStyle=`#8d8a82`,o.beginPath(),o.ellipse(e,t,J(4.6),J(2.8),0,0,Math.PI*2),o.fill(),o.fillStyle=`#3f7fa8`,o.beginPath(),o.ellipse(e,t,J(4.6)-3,J(2.8)-3,0,0,Math.PI*2),o.fill(),o.fillStyle=`#5aa0c8`,o.beginPath(),o.ellipse(e-6,t-6,J(3),J(1.4),0,0,Math.PI*2),o.fill(),o.fillStyle=`rgba(255,255,255,0.55)`;for(let[n,r]of[[e-30,t-4],[e+12,t+6],[e+28,t-8]])o.fillRect(n,r,5,1);o.fillStyle=`#4b8a45`;for(let[n,r]of[[e+20,t+3],[e-22,t+8]])o.beginPath(),o.ellipse(n,r,4,2.5,0,0,Math.PI*2),o.fill();o.fillStyle=`#f28fb0`,o.fillRect(e+19,t+2,2,1);break}case`orchard`:o.fillStyle=`rgba(106,75,53,0.55)`;for(let e=0;e<2;e++)o.fillRect(J(1),J((n?3.4:2.4)+e*4.4),J(12),6);n?c(s,0,J(2),J(1.4)):c(s,J(A.h-1.4),J(2),J(1.4));break;case`cafe`:o.fillStyle=`#8d8a82`,o.fillRect(J(2)-2,l-J(2)-2,J(10)+4,J(4)+4),Y(()=>e.drawFloor(o,`wood`,J(2),l-J(2),J(10),J(4),{seed:8})),n?c(s,0,J(2),l-J(2)):c(s,l+J(2),J(2),J(A.h)-l-J(2))}return a}function lr(){let e=J(6),t=J(5),[n,r]=er(e,t),i=e/2,a=t-2,o=J(2.9),s=J(1.75),c=a-7-s,l=(e,t,n,i)=>{r.beginPath();for(let a=0;a<8;a++){let o=Math.PI/8+a*Math.PI/4,s=e+Math.cos(o)*n,c=t+Math.sin(o)*i;a===0?r.moveTo(s,c):r.lineTo(s,c)}r.closePath()};r.fillStyle=`rgba(28,36,52,0.22)`,l(i+4,c+7+3,o+2,s+1),r.fill(),r.fillStyle=`#6f6a62`,l(i,c+7,o,s),r.fill(),r.fillRect(i-o*.92,c,o*1.84,7),r.fillStyle=`#9a948a`,r.fillRect(i-o*.92,c+1,o*1.84,4),r.fillStyle=`rgba(255,255,255,0.18)`;for(let e=Math.round(i-o*.9);e<i+o*.9;e+=9)r.fillRect(e,c+2,1,3);r.fillStyle=`#c9c3b6`,l(i,c,o,s),r.fill(),r.fillStyle=`#e4dfd4`,l(i,c-1,o-2,s-1.5),r.fill(),r.fillStyle=`#2f75a8`,l(i,c+1,o-6,s-5),r.fill(),r.fillStyle=`#3f8bc2`,l(i,c,o-8,s-7),r.fill(),r.fillStyle=`rgba(160,214,245,0.55)`,r.beginPath(),r.ellipse(i-o*.35,c-s*.3,o*.32,s*.18,0,0,Math.PI*2),r.fill();let u=c-3;r.fillStyle=`#7d776d`,r.fillRect(i-4,u-10,8,12),r.fillStyle=`#c9c3b6`,r.fillRect(i-4,u-10,3,12);let d=(e,t)=>{r.fillStyle=`#6f6a62`,r.beginPath(),r.ellipse(i,e+2,t,t*.34,0,0,Math.PI*2),r.fill(),r.fillStyle=`#d8d2c6`,r.beginPath(),r.ellipse(i,e,t,t*.32,0,0,Math.PI*2),r.fill(),r.fillStyle=`#4b9ad0`,r.beginPath(),r.ellipse(i,e,t-3,t*.32-2,0,0,Math.PI*2),r.fill()};return d(u-11,15),r.fillStyle=`#7d776d`,r.fillRect(i-2,u-24,4,13),r.fillStyle=`#c9c3b6`,r.fillRect(i-2,u-24,2,13),d(u-25,8),r.fillStyle=`#d8d2c6`,r.fillRect(i-1,u-30,3,5),r.fillStyle=`#f2a33a`,r.fillRect(i,u-32,1,2),{canvas:n,ax:Math.round(i),ay:a,water:{x:i,y:c,rx:o-8,ry:s-7},jet:{x:i,y:u-31}}}function ur(e){let[t,n]=er(24,16),i=r(e);n.fillStyle=`rgba(28,36,52,0.2)`,n.fillRect(3,13,20,2),n.fillStyle=`#7d7a73`,n.fillRect(2,7,20,7),n.fillStyle=`#b9b5aa`,n.fillRect(2,7,20,2),n.fillStyle=`#5b3c25`,n.fillRect(3,6,18,2);let a=[`#e8574a`,`#f2c94c`,`#f08bb0`,`#ffffff`,`#9b7be0`];for(let e=0;e<14;e++){let e=3+Math.floor(i()*18),t=1+Math.floor(i()*6);n.fillStyle=`#3f8550`,n.fillRect(e,t+1,1,2),n.fillStyle=a[Math.floor(i()*a.length)],n.fillRect(e,t,1,1)}return{canvas:t,ax:12,ay:14}}J(l.w+4+5),J(l.h+4+5);var dr=`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif`,fr=`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`,pr=.6,mr=1.05,hr=.85,gr=1200,_r=8,vr=6,yr=2,br=null;function xr(){if(br)return br;br=document.createElement(`canvas`),br.width=64,br.height=64;let e=br.getContext(`2d`),t=e.createRadialGradient(32,32,0,32,32,32);return t.addColorStop(0,`rgba(255,226,170,1)`),t.addColorStop(.4,`rgba(255,214,150,0.75)`),t.addColorStop(1,`rgba(255,214,150,0)`),e.fillStyle=t,e.fillRect(0,0,64,64),br}var Sr=class{canvas;art;camera;state;ctx;buildingsDrawn=[];charsDrawn=[];nb=0;nc=0;bPool=[];cPool=[];ents=[];ePool=[];cell=null;plaza=null;gardens=new Map;blocks=new Map;lotDecors=new Map;facades=new Map;appearances=new Map;anims=new Map;fountain=null;planters=new Map;req={appearance:null,dir:`down`,pose:`stand`,frame:0,held:`none`,seated:!1};lamps=[];ambient=oe(12);target=this.ambient;ambientAt=-1e9;lastNow=0;mode=``;hourOverride=ae(typeof location>`u`?``:location.search);night=0;widths=new Map;signBoxes=[];labelBoxes=[];lastFrameMs=0;fx=null;constructor(e,t,n,r){this.canvas=e,this.art=t,this.camera=n,this.state=r,this.ctx=e.getContext(`2d`,{alpha:!1})}blockInfo(e,t){let n=(e+32768)*65536+(t+32768),r=this.blocks.get(n);if(!r){this.blocks.size>600&&this.blocks.clear();let i={x:e,y:t},a=rt(i);r={bx:e,by:t,cell:it(i),lots:a,keys:a.map(B),decor:yt(i),plaza:te(i)},this.blocks.set(n,r)}return r}lotDecor(e,t,n){let r=n?`${t}|p`:t,i=this.lotDecors.get(r);return i||(this.lotDecors.size>2e3&&this.lotDecors.clear(),i=_t(e,n),this.lotDecors.set(r,i)),i}garden(e){let t=gt(e),n=nt(e),r=`${t}|${n?`n`:`s`}`,i=this.gardens.get(r);return i||this.gardens.set(r,i=cr(this.art,t,n,tt(e))),i}facadeOf(e){let t=e.agents,n=`${e.floors}|${e.state}|${e.theme}|${t?`${t.total},${t.working},${t.waiting}`:`-`}|${e.lot.x},${e.lot.y}`,r=this.facades.get(e.id);return(!r||r.sig!==n)&&(this.facades.size>4e3&&this.facades.clear(),r={sig:n,m:En(e,nt(e.lot)?`back`:`front`,tt(e.lot))},this.facades.set(e.id,r)),r.m}appearanceOf(e,t,r){let i=`${t}|${_(r)}`,a=this.appearances.get(e);return(!a||a.key!==i)&&(this.appearances.size>500&&this.appearances.clear(),a={key:i,a:this.art.appearanceFromSeed(n(e),{look:t,parts:r})},this.appearances.set(e,a)),a.a}animOf(e,t,n){let r=this.anims.get(e);return r||this.anims.set(e,r={pose:t,t:0}),r.pose===t?r.t+=n*1e3:(r.pose=t,r.t=0),r.t}forget(e){this.anims.delete(e)}updateAmbient(e,t){let n=Re(t),r=`${n}|${this.hourOverride??``}`;if(r!==this.mode||e-this.ambientAt>4e3){let t=this.mode===``;this.mode=r,this.ambientAt=e,this.target=oe(I(n,this.hourOverride,new Date)),t&&(this.ambient=this.target)}let i=Math.max(0,Math.min(250,e-this.lastNow));this.lastNow=e,this.ambient!==this.target&&(this.ambient=me(this.ambient,this.target,i/gr*3),le(this.ambient,this.target)<3&&(this.ambient=this.target)),this.night=this.ambient.night}map=null;lightMap(e,t){let n=Math.max(1,Math.ceil(e/yr)),r=Math.max(1,Math.ceil(t/yr));try{return this.map||=document.createElement(`canvas`),(this.map.width!==n||this.map.height!==r)&&(this.map.width=n,this.map.height=r),this.map}catch{return null}}frame(e,t,n,r,i){let a=performance.now(),{ctx:o,camera:s}=this;this.cell||=or(this.art),this.plaza||=sr(this.art),this.updateAmbient(e,n);let c=this.canvas.width,l=this.canvas.height;o.setTransform(1,0,0,1,0,0),o.imageSmoothingEnabled=!1,o.globalAlpha=1,o.globalCompositeOperation=`source-over`,o.fillStyle=`#5e7f52`,o.fillRect(0,0,c,l);let{scale:u,ox:d,oy:f}=s.transform();o.setTransform(u,0,0,u,d,f);let p=-d/u,m=-f/u,h=p+c/u,g=m+l/u,_=(e,t,n,r)=>e<h&&e+n>p&&t<g&&t+r>m,v=s.zoom>=pr,y=at({x0:p,y0:m,x1:h,y1:g}),b=this.ents;b.length=0;let x=0,S=(e,t,n)=>{let r=this.ePool[x];r?(r.k=e,r.y=t,r.ref=n):this.ePool[x]=r={k:e,y:t,ref:n},x++,b.push(r)};this.nb=0,this.lamps.length=0;let C=0;for(let e=y.by0;e<=y.by1;e++)for(let t=y.bx0;t<=y.bx1;t++){let n=this.blockInfo(t,e),r=n.cell;if(_(r.x,r.y,r.w,r.h+32)){o.drawImage(n.plaza?this.plaza:this.cell,r.x,r.y);for(let e of n.decor)(!e.small||v)&&_(e.x-24,e.y-56,48,60)&&(S(0,e.y,e),e.kind===`lamp`&&this.lamps.push(e.x,e.y));for(let e=0;e<n.lots.length;e++){let t=n.lots[e],r=ee(t),i=r.x*16,a=r.y*16;if(!_(i,a,224,192))continue;let s=this.state.buildingAt(t);s||o.drawImage(this.garden(t),i,a);for(let r of this.lotDecor(t,n.keys[e],!!s))(!r.small||v)&&_(r.x-24,r.y-56,48,60)&&S(0,r.y,r);if(s){let e=this.facadeOf(s),t=e.side===`back`,n=i+16,r=t?a:a+192-e.height;if(!_(n,r,H.w+H.shadow,e.height))continue;let o=null;Nn(e)?o=Mn(e):C<_r&&(C++,o=Mn(e));let c=this.bPool[this.nb];c||(this.bPool[this.nb]=c={b:s,m:e,s:o,x:n,y:r,depth:0}),c.b=s,c.m=e,c.s=o,c.x=n,c.y=r,c.depth=r+e.height,this.buildingsDrawn[this.nb]=c,this.nb++,S(1,c.depth,c)}}}}this.buildingsDrawn.length=this.nb,this.nc=0;for(let[n,r]of this.state.players){let i=hn(r.samples);r.delay=r.delay===void 0?i:gn(r.delay,i,t*1e3);let a=this.charVis(n,r,e-r.delay,t,_);a&&S(2,a.y,a)}if(r){let e=r.player,n=!e.moving&&this.onBench(e.x,e.y),i=n?`sit`:e.moving?e.running?`run`:`walk`:`stand`,a=this.takeChar(r.self.id,r.self.name,!0,e.x*16,e.y*16,n?`down`:e.dir,i,this.animOf(r.self.id,i,t),this.appearanceOf(r.self.id,r.self.look,r.self.parts));_(a.x-24,a.y-48,48,56)?S(2,a.y+.25,a):a.visible=!1}this.charsDrawn.length=this.nc,this.fx?.props?.({x0:p,y0:m,x1:h,y1:g},e=>S(3,e.y,e)),b.sort((e,t)=>e.y-t.y||e.k-t.k);for(let t of b)t.k===0?this.drawDecor(t.ref,e):t.k===1?this.drawBuilding(t.ref,e,i.building===t.ref.b.id):t.k===3?t.ref.draw(o,e):this.drawChar(t.ref,i.player===t.ref.id);let w=this.ambient;if(!z(w)){let e=this.lightMap(c,l);if(e){let t=e.getContext(`2d`),n=yr;t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation=`source-over`,t.globalAlpha=1,t.fillStyle=_e(w.outside),t.fillRect(0,0,e.width,e.height);let r=w.night;if(r>.02){t.setTransform(u/n,0,0,u/n,d/n,f/n),t.globalCompositeOperation=`lighten`,t.globalAlpha=Math.min(1,r*1.3);for(let e=0;e<this.nb;e++){let n=this.buildingsDrawn[e];n.s&&t.drawImage(n.s.glow,n.x,n.y)}let e=xr();t.globalAlpha=Math.min(1,r*1.1);for(let n=0;n<this.lamps.length;n+=2)t.drawImage(e,this.lamps[n]-52,this.lamps[n+1]-46,104,70)}if(o.save(),o.setTransform(1,0,0,1,0,0),o.globalCompositeOperation=`multiply`,o.imageSmoothingEnabled=!0,o.drawImage(e,0,0,e.width,e.height,0,0,e.width*n,e.height*n),o.restore(),r>.02){o.save(),o.globalCompositeOperation=`lighter`;let e=de(`#fff1c8`,24);o.globalAlpha=r*.85;for(let t=0;t<this.lamps.length;t+=2)o.drawImage(e,this.lamps[t]-12,this.lamps[t+1]-42);o.restore()}}}this.drawWaiting(e),this.fx?.world?.(o,e,{x0:p,y0:m,x1:h,y1:g}),this.overlay(e,n,i),this.lastFrameMs=performance.now()-a}takeChar(e,t,n,r,i,a,o,s,c){let l=this.cPool[this.nc];return l||(this.cPool[this.nc]=l={id:e,name:t,me:n,x:r,y:i,dir:a,pose:o,animT:s,appearance:c,bx:0,by:0,bw:0,bh:0,headY:0,visible:!0}),l.id=e,l.name=t,l.me=n,l.x=r,l.y=i,l.dir=a,l.pose=o,l.animT=s,l.appearance=c,l.visible=!0,this.charsDrawn[this.nc]=l,this.nc++,l}charVis(e,t,n,r,i){let a=_n(t.samples,n);if(!a)return null;let o=a.x*16,s=a.y*16;if(!i(o-24,s-48,48,56))return null;let c=!a.moving&&this.onBench(a.x,a.y),l=c?`sit`:a.moving?a.speed>4.6?`run`:`walk`:`stand`,u=c?`down`:fn[a.dir]??`down`;return this.takeChar(e,t.info.name,!1,o,s,u,l,this.animOf(e,l,r),this.appearanceOf(e,t.info.look,t.info.parts))}seatsNear(e,t,n=[]){n.length=0;let r=x(e,t);for(let e=r.y-1;e<=r.y+1;e++)for(let t=r.x-1;t<=r.x+1;t++){let r=this.blockInfo(t,e);for(let e of r.decor)e.seat&&n.push(e);for(let e=0;e<r.lots.length;e++){let t=r.lots[e];if(!this.state.buildingAt(t))for(let i of this.lotDecor(t,r.keys[e],!1))i.seat&&n.push(i)}}return n}seatScratch=[];onBench(e,t){for(let n of this.seatsNear(e,t,this.seatScratch))if(n.seat&&Math.abs(n.seat.x-e)<.5&&Math.abs(n.seat.y-t)<.5)return!0;return!1}drawDecor(e,t){let{ctx:n}=this;if(e.kind===`fountain`){let r=this.fountain??=lr(),i=Math.round(e.x-r.ax),a=Math.round(e.y-r.ay);n.drawImage(r.canvas,i,a),this.drawFountainWater(i,a,r,t);return}if(e.kind===`planter`){let t=this.planters.get(e.seed%5);t||this.planters.set(e.seed%5,t=ur(e.seed%5)),n.drawImage(t.canvas,Math.round(e.x-t.ax),Math.round(e.y-t.ay));return}let r=pe({kind:e.kind,x:e.x,y:e.y,seed:e.seed});n.drawImage(r.canvas,Math.round(e.x-r.ax),Math.round(e.y-r.ay))}drawFountainWater(e,t,n,r){let{ctx:i}=this,a=r/1e3,o=e+n.jet.x,s=t+n.jet.y;i.fillStyle=`rgba(220,240,255,0.95)`,i.fillRect(Math.round(o),Math.round(s-8),1,8);for(let e=0;e<14;e++){let t=(a*1.3+e/14)%1,n=o+(e%2?1:-1)*t*(6+e%3*2),r=s-8-Math.sin(t*Math.PI)*6+t*t*12;i.fillRect(Math.round(n),Math.round(r),1,1+e%2)}i.fillStyle=`rgba(200,232,252,0.7)`;for(let[r,o,s]of[[8,n.jet.y+7,12],[15,n.jet.y+20,14]])for(let c=-1;c<=1;c+=2){let l=e+n.jet.x+c*r;for(let e=0;e<3;e++){let n=(a*22+e*5)%s;i.fillRect(Math.round(l+n*.15*c),Math.round(t+o+n),1,2)}}let c=n.water;i.strokeStyle=`rgba(214,238,255,0.55)`,i.lineWidth=1;for(let n=0;n<2;n++){let r=(a*.45+n*.5)%1;i.globalAlpha=1-r,i.beginPath(),i.ellipse(e+c.x,t+c.y+2,10+r*(c.rx-10),3+r*(c.ry-3),0,0,Math.PI*2),i.stroke()}i.globalAlpha=1,i.fillStyle=`rgba(255,255,255,0.85)`;for(let n=0;n<7;n++){if((Math.floor(a*3)+n*2)%5!=0)continue;let r=n*.9+.3;i.fillRect(Math.round(e+c.x+Math.cos(r)*c.rx*.8),Math.round(t+c.y+Math.sin(r)*c.ry*.7),2,1)}}drawBuilding(e,t,n){let{ctx:r}=this;if(e.s)r.drawImage(e.s.canvas,e.x,e.y);else{let t=Cn[e.m.style];r.fillStyle=t.roof[0],r.fillRect(e.x,e.y,H.w,H.roof),r.fillStyle=t.wall[1],r.fillRect(e.x,e.y+H.roof,H.w,e.m.height-H.roof)}n&&(r.save(),r.globalCompositeOperation=`lighter`,r.globalAlpha=.08+Math.sin(t/260)*.03,r.fillStyle=`#ffffff`,r.fillRect(e.x,e.y,H.w,e.m.height),r.restore()),this.fx?.building?.(r,e,t)}drawWaiting(e){let{ctx:t}=this,n=.5+.5*Math.sin(e/420);if(!(n<.08)){t.save();for(let e=0;e<this.nb;e++){let r=this.buildingsDrawn[e];if(r.m.waiting.length)for(let e of r.m.waiting){let i=On(r.m,e);t.globalAlpha=.35+n*.6,t.fillStyle=`#ffb547`,t.fillRect(r.x+i.x,r.y+i.y,i.w,i.h),t.globalAlpha=n*.9,t.fillStyle=`#fff2c4`,t.fillRect(r.x+i.x+1,r.y+i.y+1,i.w-2,2)}}t.restore()}}drawChar(e,t){let{ctx:n}=this,r=Math.round(e.x),i=Math.round(e.y)-(e.pose===`sit`?vr:0);if(e.pose!==`sit`){let e=re();n.drawImage(e.canvas,r-e.ax,i-e.ay)}(t||e.me)&&(n.save(),n.strokeStyle=e.me?`rgba(124,200,255,0.85)`:`rgba(255,255,255,0.85)`,n.lineWidth=1,n.beginPath(),n.ellipse(r,i,8,3,0,0,Math.PI*2),n.stroke(),n.restore());let a=null;try{let t=this.req;t.appearance=e.appearance,t.dir=e.dir,t.pose=e.pose,t.seated=e.pose===`sit`;let n=Math.max(1,this.art.poseFrameCount(e.pose)||1),r=Math.max(30,this.art.poseFrameDuration(e.pose)||500);t.frame=Math.floor(e.animT/r)%n,a=this.art.characterSprite(t)}catch{a=null}if(a){let t=r-a.ax,o=i-a.ay;n.drawImage(a.canvas,t,o),e.bx=t+2,e.by=o+2,e.bw=a.canvas.width-4,e.bh=a.canvas.height-2,e.headY=o+2}else e.bx=r-7,e.by=i-26,e.bw=14,e.bh=26,e.headY=i-26}measure(e,t){let n=`${e}|${t}`,r=this.widths.get(n);return r===void 0&&(this.widths.size>3e3&&this.widths.clear(),this.ctx.font=e,r=this.ctx.measureText(t).width,this.widths.set(n,r)),r}fit(e,t,n){if(this.measure(e,t)<=n)return t;let r=0,i=t.length;for(;r<i;){let a=r+i+1>>1;this.measure(e,`${t.slice(0,a).trimEnd()}…`)<=n?r=a:i=a-1}return r>0?`${t.slice(0,r).trimEnd()}…`:``}overlay(e,n,r){let{ctx:i,camera:a}=this,o=a.dpr,s=a.transform(),c=s.scale/o,l=e=>e*c+s.ox/o,u=e=>e*c+s.oy/o;i.setTransform(o,0,0,o,0,0),i.textBaseline=`middle`,i.textAlign=`left`;let d=a.zoom;this.night;let f=this.signBoxes;if(f.length=0,d>=mr)for(let e=0;e<this.nb;e++){let t=this.buildingsDrawn[e],n=kn(t.m),r=l(t.x+n.x),a=u(t.y+n.y),o=n.w*c,s=n.h*c;if(s<9)continue;f.push(r,a,o,s);let d=Math.max(8,Math.min(13,s*.78)),p=`700 ${d.toFixed(1)}px ${dr}`,m=ze(t.b.owner.country),h=`❤️ ${t.b.likes}`,g=this.measure(p,h),_=m?this.measure(`${d.toFixed(1)}px ${fr}`,m)+4:0,v=this.fit(p,t.b.owner.name,Math.max(0,o-g-_-14)),y=t.b.state===`online`;i.globalAlpha=y?1:.7;let b=r+5,x=a+s/2+.5;m&&(i.font=`${d.toFixed(1)}px ${fr}`,i.fillText(m,b,x),b+=_),i.font=p,i.fillStyle=`rgba(10,14,24,0.55)`,i.fillText(v,b+.5,x+1),i.fillStyle=y?`#fff8e6`:`#c4c9d4`,i.fillText(v,b,x),i.fillStyle=y?`#ffe2e6`:`#c4c9d4`,i.fillText(h,r+o-g-5,x),i.globalAlpha=1}if(d>=hr){let e=`600 10.5px ${dr}`;i.font=e;let t=this.labelBoxes;t.length=0;for(let a=0;a<this.nc;a++){let o=this.charsDrawn[a];if(!o.visible||!o.me&&!n.showNames&&r.player!==o.id)continue;let s=this.fit(e,o.name,140),c=this.measure(e,s)+10,d=l(o.x),p=u(o.headY)-17;for(let e=0;e<f.length;e+=4){let t=f[e],n=f[e+1];d+c/2>t&&d-c/2<t+f[e+2]&&p+14>n&&p<n+f[e+3]&&(p=n-16)}for(let e=0;e<4;e++){let e=!1;for(let n=0;n<t.length;n+=4)d+c/2>t[n]&&d-c/2<t[n]+t[n+2]&&p+14>t[n+1]&&p<t[n+1]+t[n+3]&&(p=t[n+1]-16,e=!0);if(!e)break}t.push(d-c/2,p,c,14),i.globalAlpha=.92,i.fillStyle=o.me?`rgba(24,52,84,0.88)`:`rgba(18,21,29,0.78)`,i.beginPath(),i.roundRect(Math.round(d-c/2),Math.round(p),Math.round(c),14,4),i.fill(),o.me&&(i.strokeStyle=`rgba(124,200,255,0.9)`,i.lineWidth=1,i.stroke()),i.globalAlpha=1,i.fillStyle=o.me?`#d6efff`:`#e8ecf5`,i.textAlign=`center`,i.fillText(s,Math.round(d),Math.round(p)+7.5),i.textAlign=`left`}}if(r.door&&r.me&&d>=.7){let n=l(r.me.x*16)+12+7*Math.min(2,d),a=u(r.me.y*16)-20*Math.min(2.2,Math.max(.8,d)),o=Math.round(Math.sin(e/240)*2),s=t(`Entrar (E)`);i.font=`700 11px ${dr}`;let c=Math.ceil(i.measureText(s).width)+16,f=Math.round(n-10),p=Math.round(a-10+o);i.fillStyle=`rgba(18,21,29,0.86)`,i.strokeStyle=`rgba(255,214,140,0.9)`,i.lineWidth=1.5,i.beginPath(),i.roundRect(f,p,c,20,5),i.fill(),i.stroke(),i.fillStyle=`#ffe3a0`,i.fillText(s,f+8,p+10.5)}this.fx?.screen?.(i,e,{sx:l,sy:u,k:c,zoom:d})}static doorFront(e){return y(e).front}};function Cr(e,t){return!e?.me||!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)?`fresh`:Math.hypot(t.x-e.me.x,t.y-e.me.y)<=.6?`keep`:`snap`}var wr=2e4;function Tr(e){if(!e)return 0;let t=a.indexOf(e.label);return t<0?0:t+ +(e.progress>=e.target)}function Er(e){let n=e?.goal;if(!n||!(n.target>0))return null;let r=Math.max(0,Math.min(1,n.progress/n.target));return{pct:r,pctText:`${Math.floor(r*100)}%`,label:we(n.label,n.target),progressText:t(`{0} de {1} h`,[be(Math.floor(n.progress)),be(n.target)]),reached:Tr(n)}}function Dr(e){let n=e.slice(e.lastIndexOf(`:`)+1),r=a.indexOf(n);return r<0?null:{pct:1,pctText:`100%`,label:we(n),progressText:t(`Meta batida!`),reached:r+1}}function Or(e){return e?{tokens:e.tokensBand===void 0?t(`A soma aparece com 10 prédios ou mais.`):t(`A cidade consumiu ≈ {0} esta semana`,[Ce(e.tokensBand)]),lit:e.lit===1?t(`1 prédio aceso agora`):t(`{0} prédios acesos agora`,[be(e.lit)])}:null}function kr(e){let t=e.getMonth();return t===9?`halloween`:t===10||t===11?`christmas`:`party`}var Ar=E(T),jr=e=>(Ar.x+e)*16,X=e=>(Ar.y+e)*16,Z={goal:{x:jr(15.5),y:X(7.6)},hall:{x:jr(26.5),y:X(7.6)},w:84,h:52,posts:12},Mr={x:jr(v.x+v.w/2),y:X(v.y+v.h/2)},Nr=[[jr(12)+8,X(4)-30,jr(30)+8,X(4)-30],[jr(12)+8,X(19)-30,jr(30)+8,X(19)-30]],Pr=[`#ff5d73`,`#ffd166`,`#7cf3ff`,`#b28dff`,`#6dff9e`,`#ff9f43`,`#ffffff`,`#ff7ad9`],Fr=6,Ir=class{random;cap=2400;n=0;x=new Float32Array(this.cap);y=new Float32Array(this.cap);vx=new Float32Array(this.cap);vy=new Float32Array(this.cap);age=new Float32Array(this.cap);life=new Float32Array(this.cap);color=new Uint8Array(this.cap);rockets=[];flashes=[];confetti=new Te(500);until=0;nextLaunch=0;started=0;clock=0;constructor(e=Math.random){this.random=e}get active(){return this.n>0||this.rockets.length>0||this.confetti.count>0||this.flashes.length>0}showing(e){return e<this.until}start(e,t=wr){this.started=e,this.until=e+t,this.nextLaunch=e+700;for(let e=0;e<4;e++)this.launch((e+.5)/4);for(let e=0;e<40;e++)this.confetti.confettiFall(Mr.x+(this.random()-.5)*560,Mr.y-200-this.random()*80,260+this.random()*80)}stop(){this.until=0,this.n=0,this.rockets.length=0,this.flashes.length=0,this.confetti.clear()}launch(e=this.random()){let t=Mr.x+(e-.5)*520,n=Mr.y-170-this.random()*120;this.rockets.push({x:t,y:Mr.y-6,vx:(this.random()-.5)*30,vy:-(250+this.random()*60),burstY:n,color:Math.floor(this.random()*Pr.length)})}spark(e,t,n,r,i,a){if(this.n>=this.cap)return;let o=this.n++;this.x[o]=e,this.y[o]=t,this.vx[o]=n,this.vy[o]=r,this.age[o]=0,this.life[o]=i,this.color[o]=a}burst(e){let t=this.random(),n=70+Math.floor(this.random()*40),r=120+this.random()*60,i=(e.color+1+Math.floor(this.random()*(Pr.length-1)))%Pr.length;for(let a=0;a<n;a++){let o=a/n*Math.PI*2+this.random()*.15,s=t<.3?r:r*Math.sqrt(.15+this.random()*.85),c=Math.cos(o),l=Math.sin(o);if(t>.85){let e=o;c=16*Math.sin(e)**3/17,l=-(13*Math.cos(e)-5*Math.cos(2*e)-2*Math.cos(3*e)-Math.cos(4*e))/17,s=r*.9}this.spark(e.x,e.y,c*s,l*s,1.3+this.random()*.8,t>.85?0:a%4==0?i:e.color)}this.flashes.push({x:e.x,y:e.y,color:e.color,at:this.clock})}update(e,t){let n=Math.min(.1,Math.max(0,t));if(this.clock=e,e<this.until&&e>=this.nextLaunch){this.launch(),this.random()<.45&&this.launch();let t=(e-this.started)/Math.max(1,this.until-this.started);this.nextLaunch=e+(t>.85?120:300+this.random()*380)}for(let e=this.rockets.length-1;e>=0;e--){let t=this.rockets[e];t.x+=t.vx*n,t.y+=t.vy*n,t.vy+=70*n,this.spark(t.x+(this.random()-.5)*2,t.y+3,(this.random()-.5)*10,14+this.random()*12,.45,Fr),(t.y<=t.burstY||t.vy>=-30)&&(this.burst(t),this.rockets.splice(e,1))}for(let t=this.flashes.length-1;t>=0;t--)e-this.flashes[t].at>320&&this.flashes.splice(t,1);let r=0;for(;r<this.n;){if(this.age[r]+=n,this.age[r]>=this.life[r]){let e=--this.n;this.x[r]=this.x[e],this.y[r]=this.y[e],this.vx[r]=this.vx[e],this.vy[r]=this.vy[e],this.age[r]=this.age[e],this.life[r]=this.life[e],this.color[r]=this.color[e];continue}this.vx[r]*=Math.max(0,1-1.15*n),this.vy[r]=this.vy[r]*Math.max(0,1-1.15*n)+52*n,this.x[r]+=this.vx[r]*n,this.y[r]+=this.vy[r]*n,r++}this.confetti.update(n)}draw(e,t,n,r){if(!this.active)return;e.save();let i=.35+r*.65;e.globalCompositeOperation=`lighter`;for(let n of this.flashes){let r=(t-n.at)/320;if(r<0||r>1)continue;let a=18+r*40,o=e.createRadialGradient(n.x,n.y,0,n.x,n.y,a);o.addColorStop(0,`rgba(255,255,255,${(.55*(1-r)*i).toFixed(3)})`),o.addColorStop(.4,`${Pr[n.color]}${Math.round(90*(1-r)*i).toString(16).padStart(2,`0`)}`),o.addColorStop(1,`rgba(0,0,0,0)`),e.fillStyle=o,e.fillRect(n.x-a,n.y-a,a*2,a*2)}for(let t=0;t<this.n;t+=2)e.globalAlpha=(1-this.age[t]/this.life[t])*.22*i,e.fillStyle=Pr[this.color[t]%Pr.length],e.fillRect(Math.round(this.x[t])-1,Math.round(this.y[t])-1,4,4);e.globalCompositeOperation=`source-over`;for(let t of this.rockets)e.globalAlpha=1,e.fillStyle=`#fff4c8`,e.fillRect(Math.round(t.x),Math.round(t.y),2,3);for(let r=0;r<this.n;r++){let i=Math.round(this.x[r]),a=Math.round(this.y[r]);if(i<n.x0-4||i>n.x1+4||a<n.y0-4||a>n.y1+4)continue;let o=1-this.age[r]/this.life[r];if(o<.35&&Math.sin(t/35+r*1.7)<0)continue;e.globalAlpha=Math.min(1,o*1.8),e.fillStyle=o>.75?`#fffbe8`:Pr[this.color[r]%Pr.length];let s=o>.45?2:1;e.fillRect(i,a,s,s)}e.globalAlpha=1,this.confetti.draw(e,n.x0,n.y0,n.x1,n.y1,t),e.restore()}};function Lr(e,t,n,r){let i=Z.w,a=Z.h,o=Math.round(t-i/2),s=Math.round(n-Z.posts-a);e.fillStyle=`rgba(30,36,48,0.22)`,e.fillRect(o+4,n-2,i-4,3);for(let t of[o+8,o+i-11])e.fillStyle=`#3b2a1f`,e.fillRect(t,s+a-2,3,Z.posts+2),e.fillStyle=`#6b4a33`,e.fillRect(t,s+a-2,1,Z.posts+2);return e.fillStyle=`#2a1d16`,e.fillRect(o,s,i,a),e.fillStyle=`#8a5f3f`,e.fillRect(o+1,s+1,i-2,a-2),e.fillStyle=`#a8784f`,e.fillRect(o+1,s+1,i-2,1),e.fillStyle=`#1b2233`,e.fillRect(o+3,s+3,i-6,a-6),e.fillStyle=r,e.fillRect(o+3,s+3,i-6,8),e.fillStyle=`rgba(255,255,255,0.25)`,e.fillRect(o+3,s+3,i-6,1),{x:o+3,y:s+3,w:i-6,h:a-6}}function Rr(e,t,n){let r=Lr(e,Z.goal.x,Z.goal.y,`#c8443c`),i=r.x+6,a=r.y+13,o=r.y+r.h-7;e.fillStyle=`#0d1018`,e.fillRect(i-1,a-1,6,o-a+2),e.fillStyle=`#d8e4f0`,e.fillRect(i,a,4,o-a),e.fillStyle=`#0d1018`,e.fillRect(i-2,o-1,8,6),e.fillStyle=`#e8473f`,e.fillRect(i-1,o,6,4);let s=t?.pct??0,c=Math.round((o-a)*s);c>0&&(e.fillStyle=`#e8473f`,e.fillRect(i+1,o-c,2,c),e.fillStyle=`#ff9c74`,e.fillRect(i+1,o-c,1,c),Math.sin(n/300)>0&&(e.fillStyle=`#ffd7a0`,e.fillRect(i+1,o-c,2,1))),e.fillStyle=`#7d8aa3`;for(let t=1;t<4;t++)e.fillRect(i+5,Math.round(o-(o-a)*t/4),2,1);e.fillStyle=`#ffd166`,e.fillRect(i+6,a-1,4,3),e.fillStyle=`#c9a24a`,e.fillRect(i+5,a-1,1,6)}function zr(e,t){let n=Lr(e,Z.hall.x,Z.hall.y,`#2f6fa8`),r=n.x+4,i=n.y+15;e.fillStyle=`#c9c2b2`,e.fillRect(r,i+5,14,11),e.fillStyle=`#e8e2d4`,e.fillRect(r-1,i+3,16,2),e.fillRect(r+2,i+1,10,2),e.fillRect(r+5,i,4,1),e.fillStyle=t?`#ffd27a`:`#4a5468`;for(let t of[r+2,r+6,r+10])e.fillRect(t,i+7,2,4);e.fillStyle=`#8f8676`,e.fillRect(r-1,i+16,16,1)}function Br(){let e=e=>e-Z.posts-Z.h+3;return{goal:{x:Z.goal.x-Z.w/2+3,y:e(Z.goal.y),w:Z.w-6},hall:{x:Z.hall.x-Z.w/2+3,y:e(Z.hall.y),w:Z.w-6}}}function Vr(e,t,n,r,i){return{x:e+(n-e)*i,y:t+(r-t)*i+Math.sin(i*Math.PI)*14}}function Hr(e,t,n,r,i,a){e.fillStyle=`#4a3b2e`;for(let a=0;a<=120;a++){let o=Vr(t,n,r,i,a/120);e.fillRect(Math.round(o.x),Math.round(o.y),1,1)}for(let o=1;o<24;o++){let s=Vr(t,n,r,i,o/24),c=Math.round(s.x),l=Math.round(s.y),u=+(Math.sin(a/380+o*.9)>.4),d=F[o%F.length];e.fillStyle=`rgba(20,24,33,0.35)`,e.fillRect(c-2,l+2,7,1),e.fillStyle=d;for(let t=0;t<6;t++)e.fillRect(c-3+Math.floor(t/2)+(t>2?u:0),l+1+t,7-Math.floor(t/2)*2,1);e.fillStyle=`rgba(255,255,255,0.45)`,e.fillRect(c-3,l+1,7,1)}}function Ur(e,t,n,r,i,a,o){if(!(o<.15)){for(let s=0;s<24;s++){let c=Vr(t,n,r,i,(s+.5)/24),l=.55+.45*Math.sin(a/520+s*1.3);e.globalAlpha=o*l,e.fillStyle=s%3==0?`#ffd27a`:s%3==1?`#ff9db0`:`#9ae7ff`,e.fillRect(Math.round(c.x),Math.round(c.y),2,2),e.globalAlpha=o*l*.25,e.fillRect(Math.round(c.x)-2,Math.round(c.y)-2,6,6)}e.globalAlpha=1}}var Wr=new Map;function Gr(e,t,n,r){let i=Wr.get(t);if(!i){let{buf:e}=ue(t);i=document.createElement(`canvas`),i.width=e.w,i.height=e.h,i.getContext(`2d`).putImageData(new ImageData(e.data,e.w,e.h),0,0),Wr.set(t,i)}e.drawImage(i,Math.round(n-20),Math.round(r-60))}function Kr(e){let t=v,n=[[t.x-2.5,t.y+1.2],[t.x+t.w+2.5,t.y+1.2],[t.x-1.2,t.y+t.h+1.1],[t.x+t.w+1.2,t.y+t.h+1.1]],r=e===`halloween`?[`pumpkin`,`pumpkin`,`ghost`,`pumpkin`]:e===`christmas`?[`tree`,`tree`,`gift`,`gift`]:[`gift`,`gift`,`gift`,`gift`];return n.map(([e,t],n)=>({kind:r[n],x:jr(e),y:X(t)}))}var qr=62e3;function Jr(e,t,n,r){let i=ft(e.x,e.y,e=>{let r=t(e);return!!r&&r.id!==n},r);if(!i)return null;let a=t(i.lot);return a?{building:a,front:i.front,dist:Math.hypot(i.front.x-e.x,i.front.y-e.y)}:null}function Yr(e,t){let n=y(t.lot).front;return Math.hypot(n.x-e.x,n.y-e.y)}function Xr(e,t,n){let r=!!n&&e.id===n,i=t?Yr(t,e):1/0;return{canLike:!r&&i<=4.000000001,canKnock:!r&&e.knocks===!0&&i<=2.000000001,liked:e.likedByMe===!0,mine:r}}var Zr=class{at=new Map;wait(e,t){let n=this.at.get(e);return n===void 0?0:Math.max(0,n+qr-t)}take(e,t){return this.wait(e,t)>0?!1:(this.at.set(e,t),!0)}};function Qr(e,t){let n=(t-e.start)/900;if(n<0||n>=1)return null;if(e.broken)return{x:e.to.x+Math.sin(n*9)*3,y:e.to.y+n*n*26,scale:1,alpha:1-n};let r=1-(1-n)*(1-n),i=Math.sin(n*Math.PI)*26;return{x:e.from.x+(e.to.x-e.from.x)*r,y:e.from.y+(e.to.y-e.from.y)*r-i,scale:n<.15?.6+n/.15*.8:n>.8?1.4-(n-.8)/.2*.6:1.4,alpha:n>.9?(1-n)*10:1}}var $r=[`.11.11.`,`1211111`,`1111111`,`.11111.`,`..111..`,`...1...`],ei=/^HB-[2-9A-HJKMNP-TV-Z]{4}$/;function ti(e){let t=e.trim().toUpperCase().replace(/[\s_]+/g,``),n=`HB-${t.startsWith(`HB-`)?t.slice(3):t.startsWith(`HB`)&&t.length===6?t.slice(2):t}`;return ei.test(n)?n:null}var ni={out:320,wait:5e3,in:520},ri=class{phase=`idle`;since=0;landed=!1;get busy(){return this.phase!==`idle`}start(e){this.phase=`out`,this.since=e,this.landed=!1}arrived(){(this.phase===`out`||this.phase===`wait`)&&(this.landed=!0)}failed(){this.arrived()}tick(e){let t=!1;this.phase===`out`&&e-this.since>=ni.out&&(this.phase=`wait`,this.since=e),this.phase===`wait`&&(this.landed||e-this.since>=ni.wait)&&(t=!this.landed,this.phase=`in`,this.since=e),this.phase===`in`&&e-this.since>=ni.in&&(this.phase=`idle`);let n=e-this.since,r=this.phase===`out`?Math.min(1,n/ni.out):this.phase===`wait`?1:this.phase===`in`?Math.max(0,1-n/ni.in):0;return{phase:this.phase,dark:r,timedOut:t}}},ii=class{actions;el;input;error;goBtn;diceBtn;constructor(e){this.actions=e,this.input=N(`input`,{class:`ui-city-tp__input`,type:`text`,attrs:{placeholder:`HB-XXXX`,maxlength:9,autocomplete:`off`,autocapitalize:`characters`,spellcheck:`false`,"aria-label":t(`Código do prédio`)}}),this.goBtn=N(`button`,{class:`ui-city-tp__go`,type:`submit`,text:t(`Ir`),title:t(`Ir até a porta deste prédio`)}),this.diceBtn=N(`button`,{class:`ui-city-tp__dice`,type:`button`,title:t(`Visitar um prédio aleatório`),attrs:{"aria-label":t(`Visitar um prédio aleatório`)},on:{click:()=>this.actions.random()}},N(`span`,{text:`🎲`,attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-tp__dice-text`,text:t(`Aleatório`)})),this.error=N(`p`,{class:`ui-city-tp__error`,role:`alert`,hidden:!0});let n=N(`form`,{class:`ui-city-tp__form`,attrs:{"aria-label":t(`Ir para um prédio pelo código`)}},N(`span`,{class:`ui-city-tp__label`,text:t(`Ir para`),attrs:{"aria-hidden":`true`}}),this.input,this.goBtn);n.addEventListener(`submit`,e=>{e.preventDefault(),this.submit()}),this.input.addEventListener(`input`,()=>P(this.error,!0)),this.input.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&this.input.blur()}),this.el=N(`div`,{class:`ui-city-tp`},n,this.diceBtn,this.error)}showError(e){M(this.error,e),P(this.error,!1)}setBusy(e){this.goBtn.disabled=e,this.diceBtn.disabled=e}clear(){this.input.value=``,P(this.error,!0)}submit(){let e=ti(this.input.value);if(!e){this.showError(t(`O código tem o formato HB-XXXX (letras e números, sem 0, O, 1, I, L e U).`));return}this.input.value=e,this.input.blur(),this.actions.go(e)}};function ai(e){return e===void 0||e<=0?0:e>=4?4:e}function oi(e){return e===void 0?0:Math.max(0,Math.min(5,Math.floor(e)))}function si(e){return e.side===`front`?{x:H.w/2-34,y:e.height-H.ground+12,w:11,h:15}:{x:H.w/2-37,y:0,w:11,h:15}}function ci(e,t){if(!e||!t||typeof t!=`object`)return!1;let n=t;return typeof n.working!=`number`||typeof n.idle!=`number`?!1:n.working<e.working&&n.idle>e.idle}var li=[`#4fd18b`,`#b7e05a`,`#ffd24a`,`#ff9a3c`,`#ff4f8b`];function ui(e,t,n,r,i,a,o){let s=Math.round(t),c=Math.round(n);e.fillStyle=`#1b1f28`,e.fillRect(s,c,11,15),e.fillStyle=`#5d6577`,e.fillRect(s+1,c+1,9,13),e.fillStyle=`#7d8699`,e.fillRect(s+1,c+1,9,1),e.fillStyle=o?`#efe6c8`:`#9aa3b2`,e.fillRect(s+2,c+2,7,4);let l=-Math.PI*.9+r/5*Math.PI*.8+Math.sin(i/60)*.55*a;e.fillStyle=`#c23a3a`,e.fillRect(s+5+Math.round(Math.cos(l)*2.4),c+5+Math.round(Math.sin(l)*2.4),1,1),e.fillStyle=`#20242e`,e.fillRect(s+5,c+5,1,1);for(let t=0;t<5;t++){let n=2+t;e.fillStyle=o&&t<r?li[t]:`#2c313d`,e.fillRect(s+1+t*2,c+13-n,1,n)}}function di(e,t,n,r,i){if(r<=0||i<.05)return;let a=Math.round(t),o=Math.round(n);e.globalAlpha=Math.min(1,i*1.1);for(let t=0;t<r;t++){let n=2+t;e.fillStyle=li[t],e.fillRect(a+1+t*2,o+13-n,1,n)}e.globalAlpha=Math.min(.35,i*.35),e.fillStyle=li[r-1],e.fillRect(a-2,o+5,15,11),e.globalAlpha=1}var fi=[``,`#ffd9a0`,`#ffe9b8`,`#7cf3ff`,`#ff6bd6`];function pi(e,t,n,r,i,a,o,s){if(i<=0)return;let c=kn(r),l=Math.round(t+c.x),u=Math.round(n+c.y),d=fi[i];if(i<=2){e.globalAlpha=(i===1?.18:.32)*(.35+o*.65),e.fillStyle=d,e.fillRect(l-4,u-3,c.w+8,c.h+6),e.globalAlpha=(i===1?.12:.22)*(.35+o*.65),e.fillRect(l-8,u-6,c.w+16,c.h+12),e.globalAlpha=1;return}let f=(Math.floor(a/90)+s)%47==0?.35:1,p=i===4?.8+Math.sin(a/180+s)*.2:1;if(e.globalAlpha=(.55+o*.45)*f*p,e.fillStyle=d,e.fillRect(l-3,u-3,c.w+6,1),e.fillRect(l-3,u+c.h+2,c.w+6,1),e.fillRect(l-3,u-3,1,c.h+6),e.fillRect(l+c.w+2,u-3,1,c.h+6),e.globalAlpha=(.16+o*.3)*f*p,e.fillRect(l-6,u-6,c.w+12,c.h+12),e.globalAlpha=1,!(i<4)){for(let t=0;t<6;t++){let n=((a/700+t*.37+s*.13)%1+1)%1,r=(t+s)%4,i=r%2==0?l-3:l+c.w+2,o=r<2?u-3:u+c.h+2,f=i+(r%2==0?-1:1)*n*7,p=o-Math.sin(n*Math.PI)*6+n*n*8;e.globalAlpha=1-n,e.fillStyle=t%2?`#fff6b0`:d,e.fillRect(Math.round(f),Math.round(p),1,1)}e.globalAlpha=1}}var mi=`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif`,hi=`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`,gi=4e3,_i=1600,vi=1100,yi=1.05;function bi(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``))}var xi=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Si=(e,t)=>{let n=h(x(e.x,e.y)),r=h(x(t.x,t.y));return n.x===r.x&&n.y===r.y},Ci=e=>typeof e==`number`&&Number.isFinite(e),wi=class{o;el;wheel=new Pt;balloons=new jt;greetGate=new Mt(18,3300);likeGate=new Mt(9,400);teleportGate=new Mt(9,1500);reports={day:``,n:0};knocks=new Zr;hearts=[];bumps=new Map;wiggles=new Map;pops=[];fireworks=new Ir;confetti=new Te(500);fade=new ri;fadeEl;panel;dock;testBtn=null;dockKey=``;city=null;celebrating=null;replyTo=null;pending=null;snapCamera=!1;heldPos=null;lastNow=0;reported=new Set;blocked=new Set;extras={building:null,player:null};propsPool=[];onKeyDown=e=>this.onKey(e);constructor(e){this.o=e,this.fadeEl=N(`div`,{class:`ui-city-fade`,hidden:!0,attrs:{"aria-hidden":`true`}}),this.panel=new ii({go:e=>this.teleport(e),random:()=>this.teleport()}),this.dock=N(`div`,{class:`ui-city-dock`,role:`toolbar`,attrs:{"aria-label":t(`Ações perto de você`)}});let n=typeof location>`u`?null:new URLSearchParams(location.search);if(e.testFireworks&&n?.has(`fireworks`)){let n=e.testFireworks;this.testBtn=N(`button`,{class:`ui-city-testfw`,type:`button`,text:`🎆 ${t(`Testar os fogos`)}`,on:{click:()=>n()}})}this.el=N(`div`,{class:`ui-city-social`},this.dock,this.panel.el,this.wheel.el,this.fadeEl,this.testBtn),window.addEventListener(`keydown`,this.onKeyDown,!0)}helpItems(){return[N(`span`,{},N(`kbd`,{text:`L`}),` `,t(`curtir`)),N(`span`,{},N(`kbd`,{text:`G`}),` `,t(`cumprimentar`)),N(`span`,{},N(`kbd`,{text:`K`}),` `,t(`bater`))]}reset(){this.wheel.close(),this.balloons.clear(),this.hearts.length=0,this.bumps.clear(),this.wiggles.clear(),this.pops.length=0,this.fireworks.stop(),this.confetti.clear(),this.pending=null,this.replyTo=null,this.city=null,this.celebrating=null,this.blocked.clear(),this.snapCamera=!1,this.heldPos=null,this.fadeEl.hidden=!0,this.panel.setBusy(!1)}hide(){this.wheel.close()}escape(){return this.wheel.open?(this.wheel.close(),!0):!1}destroy(){window.removeEventListener(`keydown`,this.onKeyDown,!0),this.el.remove()}snapshot(e){this.city=e.city?D(e.city)??null:null}message(e,n){if(!xi(e)||typeof e.t!=`string`)return!1;let r=this.o.state();switch(e.t){case`greeting`:return this.onGreeting(e,n),!1;case`player.join`:return xi(e.player)&&typeof e.player.id==`string`&&this.blocked.delete(e.player.id),!1;case`like.update`:{let t=e.buildingId,i=typeof t==`string`?r.buildings.get(t):void 0;return i&&Ci(e.likes)&&e.likes>i.likes&&this.bumps.set(i.id,n),this.pending&&(this.pending.kind===`like`||this.pending.kind===`unlike`)&&this.pending.buildingId===t&&(this.pending=null),!1}case`area.patch`:return this.onPatch(e,r,n),!1;case`city`:{let t=D(e);return t&&(this.city=t),!1}case`city.fireworks`:{this.fireworks.start(n);let r=typeof e.goalId==`string`?Dr(e.goalId):null;return r&&(this.celebrating={goal:r,until:n+wr}),this.o.toast(r?`🎆 ${t(`A cidade bateu a meta da semana: {0}!`,[r.label])}`:`🎆 ${t(`A cidade bateu a meta da semana!`)}`),!1}case`pos`:return this.pending?.kind===`teleport`&&(this.pending=null,this.fade.arrived(),this.heldPos=e,!0);case`notice`:return typeof e.text==`string`&&this.onNotice(e.text,n);default:return!1}}onGreeting(e,n){let r=e.from,i=e.greetingId;if(typeof r!=`string`||!(i in Oe))return;let a=this.o.state().me?.id;if(this.balloons.add(r,i,n),r===a){this.pending?.kind===`greet`&&(this.pending=null);return}if(e.to===a&&a){this.replyTo={id:r,at:n,got:i};let e=this.o.state().players.get(r)?.info.name??t(`Alguém`);this.o.toast(t(`{0}: {1} {2} — G para responder`,[e,ke(i),Me(i)]))}}onPatch(e,t,n){if(Array.isArray(e.changes))for(let r of e.changes){if(!xi(r)||typeof r.id!=`string`)continue;let e=t.buildings.get(r.id);if(!e)continue;Ci(r.likes)&&r.likes>e.likes&&this.bumps.set(r.id,n),ci(e.agents,r.agents)&&this.celebrateShift(r.id,n);let i=xi(r.tokens)&&Ci(r.tokens.day)?r.tokens.day:void 0;i!==void 0&&i!==e.tokens?.day&&this.wiggles.set(r.id,{band:i,at:n})}}celebrateShift(e,t){let n=this.drawn(e);if(!n)return;let r=kn(n.m),i=n.x+r.x+r.w/2,a=n.y+r.y;this.confetti.confetti(i,a,40),this.confetti.sparkle(i,a-4,10),this.pops.push({x:i,y:a-6,at:t,text:`🎉`})}onNotice(e,n){let r=this.pending;if(!r||n-r.at>gi)return!1;let i=null;switch(r.kind){case`like`:case`unlike`:e===`too_far`?i=t(`Chegue mais perto da porta para curtir (até 4 passos).`):e===`daily_limit`?i=t(`Você já deu os 50 likes de hoje. Amanhã tem mais!`):e===`invalid`?i=t(`Não dá para curtir o próprio prédio.`):e===`not_found`?i=t(`Este prédio não está mais aqui.`):e===`rate_limited`&&(i=t(`Devagar com os likes: espere um pouquinho.`));break;case`knock`:e===`too_far`?i=t(`Chegue mais perto da porta para bater (até 2 passos).`):e===`rate_limited`?i=t(`Você bateu nesta porta há pouco. Espere um minuto.`):e===`not_found`&&(i=t(`Este prédio não está mais aqui.`));break;case`stamp`:e===`already_done`?i=t(`Você já deixou um carimbo aqui hoje.`):e===`too_far`?i=t(`Chegue mais perto da porta para carimbar.`):e===`not_found`&&(i=t(`Este prédio não está mais aqui.`));break;case`teleport`:e===`not_found`?i=r.code?t(`Nenhum prédio com o código {0}.`,[r.code]):t(`Nenhum prédio aceso para visitar agora.`):e===`rate_limited`&&(i=t(`Devagar: espere um pouco antes de ir para outro prédio.`)),i&&(this.fade.failed(),r.code&&this.panel.showError(i));break;case`greet`:e===`not_found`?i=t(`Essa pessoa não está mais por perto.`):e===`rate_limited`&&(i=t(`Devagar: um cumprimento a cada 3 segundos.`));break;case`block`:case`report`:if(e===(r.kind===`block`?`blocked_ok`:`reported`))return this.pending=null,!0;e===`daily_limit`?i=t(`Você já mandou as 5 denúncias de hoje.`):e===`not_found`&&(i=t(`Essa pessoa não está mais por perto.`))}return i?(this.pending=null,this.o.toast(i),!0):!1}send(e,t){this.o.send([e]),t&&(this.pending=t)}likeNearest(e){let n=this.o.me(),r=this.o.state();if(!n)return;let i=Jr(n,e=>r.buildingAt(e),r.myBuildingId,4);if(!i){this.o.toast(t(`Chegue perto da porta de um prédio (até 4 passos) e aperte L para curtir.`));return}this.toggleLike(i.building,e)}toggleLike(e,n){let r=this.o.me(),i=this.o.state();if(!r||e.id===i.myBuildingId||this.fade.busy)return;if(!Xr(e,r,i.myBuildingId).canLike){this.o.toast(t(`Chegue mais perto da porta para curtir (até 4 passos).`));return}if(!this.likeGate.take(n)){this.o.toast(t(`Devagar com os likes: espere um pouquinho.`));return}let a=!e.likedByMe;this.send({t:a?`like`:`unlike`,buildingId:e.id},{kind:a?`like`:`unlike`,at:n,buildingId:e.id});let o=this.drawn(e.id),s=o?this.likeSpot(o):{x:y(e.lot).front.x*16,y:y(e.lot).front.y*16-40};this.hearts.push({from:{x:r.x*16,y:r.y*16-30},to:s,start:n,...a?{}:{broken:!0}})}knockNearest(e){let n=this.o.me(),r=this.o.state();if(!n)return;let i=Jr(n,e=>r.buildingAt(e),r.myBuildingId,2);if(!i){this.o.toast(t(`Chegue a 2 passos da porta de um prédio e aperte K para bater.`));return}this.knock(i.building,e)}knock(e,n){let r=this.o.me();if(!r||this.fade.busy)return;let i=Xr(e,r,this.o.state().myBuildingId);if(!e.knocks){this.o.toast(t(`O dono deste prédio não recebe batidas na porta.`));return}if(!i.canKnock){this.o.toast(t(`Chegue mais perto da porta para bater (até 2 passos).`));return}if(!this.knocks.take(e.id,n)){this.o.toast(t(`Você bateu nesta porta há pouco. Espere um minuto.`));return}this.send({t:`knock`,buildingId:e.id},{kind:`knock`,at:n,buildingId:e.id});let a=this.drawn(e.id);if(a){let t=y(e.lot).front;this.pops.push({x:t.x*16,y:a.m.side===`front`?a.y+a.m.height-26:a.y+8,at:n,text:`✊`})}this.o.toast(`🚪 ${t(`Toc, toc! Você bateu na porta de {0}.`,[e.owner.name])}`)}openWheel(e,n){let r=this.o.me(),i=this.o.state();if(!r||this.fade.busy)return;let a=[];for(let[e,t]of i.players)!this.blocked.has(e)&&Si(r,t.info.pos)&&a.push({id:e,x:t.info.pos.x,y:t.info.pos.y});let o=this.replyTo&&e-this.replyTo.at<1e4?this.replyTo:null,s=n??(this.o.cards.kind===`player`?this.o.cards.id:null),c=n&&i.players.has(n)?n:At(r,a,{selected:s,replyTo:o?.id??null});if(!c){this.o.toast(t(`Ninguém por perto para cumprimentar.`));return}let l=i.players.get(c);if(!l)return;let u={id:c,name:l.info.name},d=this.toWindow(r.x*16,r.y*16-24),f=this.toWindow(l.info.pos.x*16,l.info.pos.y*16-24),p=o&&o.id===c?Nt(o.got):null;this.wheel.show(u,d,f,p,e=>this.greet(c,e,performance.now()))}greet(e,n,r){if(this.fade.busy)return;if(this.greetGate.wait(r)>0){this.o.toast(t(`Devagar: um cumprimento a cada 3 segundos.`));return}this.greetGate.take(r),this.send({t:`greet`,playerId:e,greetingId:n},{kind:`greet`,at:r,playerId:e});let i=this.o.state().me?.id;i&&this.balloons.add(i,n,r),this.replyTo?.id===e&&(this.replyTo=null)}teleport(e){let n=performance.now();if(this.o.me()&&!this.fade.busy){if(!this.teleportGate.take(n)){this.o.toast(t(`Devagar: espere um pouco antes de ir para outro prédio.`));return}this.wheel.close(),this.o.cards.hide(),this.send(e?{t:`teleport`,code:e}:{t:`teleport`},e?{kind:`teleport`,at:n,code:e}:{kind:`teleport`,at:n}),this.fade.start(n),this.panel.setBusy(!0)}}block(e,n,r){this.fade.busy||(this.send({t:`block`,playerId:e},{kind:`block`,at:r,playerId:e}),this.blocked.add(e),this.o.cards.hide(),this.o.toast(t(`{0} bloqueado. Para desfazer: Configurações › Habblaud World › Bloqueados.`,[n])))}report(e,n,r){if(this.fade.busy)return!1;let i=new Date().toISOString().slice(0,10);return this.reports.day!==i&&(this.reports={day:i,n:0}),this.reports.n>=5?(this.o.toast(t(`Você já mandou as 5 denúncias de hoje.`)),!1):(this.reports.n++,this.send({t:`report`,playerId:e,reason:n},{kind:`report`,at:r,playerId:e}),this.reported.add(e),this.o.toast(t(`Denúncia enviada. Obrigado: a moderação vai olhar.`)),!0)}onKey(e){if(!this.o.active())return;if(this.wheel.open){this.wheel.key(e)&&(e.preventDefault(),e.stopPropagation());return}if(e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||e.repeat||bi(e.target)||ce(e.target)||this.fade.busy)return;let t=performance.now();switch(e.key){case`l`:case`L`:e.preventDefault(),this.likeNearest(t);return;case`g`:case`G`:e.preventDefault(),this.openWheel(t);return;case`k`:case`K`:e.preventDefault(),this.knockNearest(t);return}}frame(e,n){this.lastNow=e,this.fireworks.update(e,n),this.confetti.update(n);for(let t=this.hearts.length-1;t>=0;t--){let n=this.hearts[t];if(e-n.start>1e3&&(this.hearts.splice(t,1),!n.broken)){let t=this.findAt(n.to);t&&this.bumps.set(t.b.id,e)}}for(let t=this.pops.length-1;t>=0;t--)e-this.pops[t].at>1300&&this.pops.splice(t,1);let r=this.fade.tick(e);if(this.heldPos&&r.phase!==`out`){let e=this.heldPos;this.heldPos=null,this.o.replay(e),this.snapCamera=!0}this.fadeEl.hidden=r.phase===`idle`,r.phase!==`idle`&&(this.fadeEl.style.opacity=r.dark.toFixed(3)),(r.phase===`idle`||r.phase===`in`)&&this.panel.setBusy(!1),r.timedOut&&(this.pending=null,this.o.toast(t(`O mundo não respondeu a tempo. Tente de novo.`))),this.snapCamera&&this.o.me()&&(this.snapCamera=!1,this.o.teleported(),this.panel.clear()),this.syncDock(e),this.extras.building?.sync(),this.extras.player?.sync()}syncDock(e){let n=this.o.me(),r=this.o.state(),i=null,a=null,o=!1;if(n){i=Jr(n,e=>r.buildingAt(e),r.myBuildingId,4)?.building??null;let e=Jr(n,e=>r.buildingAt(e),r.myBuildingId,2)?.building??null;a=e?.knocks?e:null;for(let e of r.players.values())if((e.info.pos.x-n.x)**2+(e.info.pos.y-n.y)**2<=144&&!this.blocked.has(e.info.id)&&Si(n,e.info.pos)){o=!0;break}}let s=`${i?.id??``}|${+!!i?.likedByMe}|${a?.id??``}|${+!!o}|${+!!this.wheel.open}`;if(s===this.dockKey)return;this.dockKey=s;let c=[],l=(e,t,n,r,i,a=``)=>N(`button`,{class:`ui-city-dock__btn ${a}`.trim(),type:`button`,title:r,attrs:{"aria-label":r,"aria-keyshortcuts":n},on:{click:i}},N(`span`,{class:`ui-city-dock__icon`,text:e,attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-dock__text`,text:t}),N(`kbd`,{text:n}));if(i){let e=i;c.push(e.likedByMe?l(`💔`,t(`Descurtir`),`L`,t(`Desfazer o like no prédio de {0}`,[e.owner.name]),()=>this.toggleLike(this.o.state().buildings.get(e.id)??e,performance.now()),`is-liked`):l(`❤️`,t(`Curtir`),`L`,t(`Curtir o prédio de {0}`,[e.owner.name]),()=>this.toggleLike(this.o.state().buildings.get(e.id)??e,performance.now()),`is-like`))}if(a){let e=a;c.push(l(`🚪`,t(`Bater`),`K`,t(`Bater na porta de {0}`,[e.owner.name]),()=>this.knock(this.o.state().buildings.get(e.id)??e,performance.now())))}o&&c.push(l(`👋`,t(`Cumprimentar`),`G`,t(`Cumprimentar quem está perto`),()=>this.openWheel(performance.now()))),this.dock.replaceChildren(...c),P(this.dock,!c.length)}cardExtras(e,t){return e===`building`?(this.extras.building||(this.extras.building=new Ti(this)),this.extras.building.bind(t),this.extras.building.el):(this.extras.player||(this.extras.player=new Ei(this)),this.extras.player.bind(t),this.extras.player.el)}get ctx(){return{state:this.o.state(),me:this.o.me(),reported:this.reported}}act={like:e=>this.toggleLike(e,performance.now()),knock:e=>this.knock(e,performance.now()),greet:e=>this.openWheel(performance.now(),e),block:(e,t)=>this.block(e,t,performance.now()),report:(e,t)=>this.report(e,t,performance.now())};drawn(e){for(let t of this.o.renderer().buildingsDrawn)if(t.b.id===e)return t}findAt(e){for(let t of this.o.renderer().buildingsDrawn)if(e.x>=t.x&&e.x<=t.x+192&&e.y>=t.y-4&&e.y<=t.y+t.m.height)return t}likeSpot(e){let t=kn(e.m);return{x:e.x+t.x+t.w-10,y:e.y+t.y+t.h/2}}goal(e){return this.celebrating&&e<this.celebrating.until?this.celebrating.goal:Er(this.city)}toWindow(e,t){let n=this.o.camera.worldToScreen(e,t),r=this.o.canvas.getBoundingClientRect();return{x:r.left+n.x,y:r.top+n.y}}building(e,t,n){let r=t.b.tokens?.day;if(r===void 0||!t.s)return;let i=si(t.m),a=this.wiggles.get(t.b.id),o=a?Math.max(0,1-(n-a.at)/_i):0;ui(e,t.x+i.x,t.y+i.y,oi(r),n,o,t.b.state===`online`)}props(e,t){let n=this.propsPool,r=0,i=(e,i)=>{let a=n[r];a||(n[r]=a={y:e,draw:i}),a.y=e,a.draw=i,r++,t(a)},a=(t,n,r,i)=>t<e.x1&&t+r>e.x0&&n<e.y1&&n+i>e.y0,o=Z.w,s=Z.h+Z.posts;if(a(Z.goal.x-o/2,Z.goal.y-s,o,s)&&i(Z.goal.y,(e,t)=>Rr(e,this.goal(t),t)),a(Z.hall.x-o/2,Z.hall.y-s,o,s)&&i(Z.hall.y,e=>zr(e,(this.city?.lit??0)>0)),!((this.goal(this.lastNow)?.reached??0)<1)){for(let[e,t,n,r]of Nr)a(e,t-4,n-e,30)&&i(t+40,(i,a)=>Hr(i,e,t,n,r,a));for(let e of Kr(kr(new Date)))a(e.x-20,e.y-60,40,64)&&i(e.y,t=>Gr(t,e.kind,e.x,e.y))}}world(e,t,n){let r=this.o.renderer(),i=r.night;e.save(),e.globalCompositeOperation=`lighter`;for(let n of r.buildingsDrawn){let r=n.b.tokens;if(!r||!n.s)continue;let a=n.b.state===`online`;if(a&&pi(e,n.x,n.y,n.m,ai(r.week),t,i,n.b.lot.x*7+n.b.lot.y*13&15),a){let t=si(n.m);di(e,n.x+t.x,n.y+t.y,oi(r.day),i)}}e.restore();for(let n of this.hearts){let r=Qr(n,t);r&&this.drawHeart(e,r.x,r.y,r.scale,r.alpha,n.broken===!0,i)}i>.15&&this.plazaLights(e,t,n,i),this.confetti.draw(e,n.x0,n.y0,n.x1,n.y1,t),this.fireworks.draw(e,t,n,i)}plazaLights(e,t,n,r){let i=(e,t,r,i)=>e<n.x1&&e+r>n.x0&&t<n.y1&&t+i>n.y0;e.save(),e.globalCompositeOperation=`lighter`;for(let[t,n]of[[Z.goal,`rgba(255,150,110,`],[Z.hall,`rgba(130,180,255,`]]){let a=t.x-Z.w/2+3,o=t.y-Z.posts-Z.h+3;i(a,o,Z.w,Z.h)&&(e.fillStyle=`${n}${(.16*r).toFixed(3)})`,e.fillRect(a,o,Z.w-6,Z.h-6),e.fillStyle=`${n}${(.07*r).toFixed(3)})`,e.fillRect(a-6,o-6,Z.w+6,Z.h+6))}if((this.goal(t)?.reached??0)>=1){for(let[n,a,o,s]of Nr)i(n,a-4,o-n,34)&&Ur(e,n,a,o,s,t,r);if(kr(new Date)===`halloween`)for(let n of Kr(`halloween`)){if(n.kind!==`pumpkin`||!i(n.x-20,n.y-30,40,40))continue;let a=.75+.25*Math.sin(t/90+n.x),o=e.createRadialGradient(n.x,n.y-10,0,n.x,n.y-10,18);o.addColorStop(0,`rgba(255,150,40,${(.32*r*a).toFixed(3)})`),o.addColorStop(1,`rgba(255,150,40,0)`),e.fillStyle=o,e.fillRect(n.x-18,n.y-28,36,36)}}e.restore()}drawHeart(e,t,n,r,i,a,o){let s=Math.max(1,Math.round(r*1.5))/1.5,c=Math.max(1,s),l=7*c,u=6*c,d=Math.round(t-l/2),f=Math.round(n-u/2);e.save(),e.globalAlpha=i,o>.2&&(e.globalCompositeOperation=`lighter`,e.fillStyle=`rgba(255,90,120,0.25)`,e.fillRect(d-3,f-3,l+6,u+6),e.globalCompositeOperation=`source-over`),$r.forEach((t,n)=>{for(let r=0;r<t.length;r++){let i=t[r];if(i===`.`)continue;let o=a&&r>=4?1:0;e.fillStyle=i===`2`?`#ffd1da`:a?`#9a6b78`:`#ff4f6d`,e.fillRect(d+r*c,f+(n+o)*c,c,c)}}),e.restore()}screen(e,t,n){let r=this.o.renderer();for(let i of r.buildingsDrawn){let r=kn(i.m),a=n.sx(i.x+r.x),o=n.sy(i.y+r.y),s=r.w*n.k,c=r.h*n.k;i.b.unverified===!0&&n.zoom>=1.05&&c>=9&&this.drawSeal(e,a-2,o+c/2);let l=this.bumps.get(i.b.id);if(l!==void 0){let r=(t-l)/vi;r>=1?this.bumps.delete(i.b.id):this.drawBump(e,a+s-12*n.k,o+c/2,r)}}for(let r of this.pops){let i=(t-r.at)/1300;i<0||i>=1||(e.globalAlpha=i>.7?(1-i)/.3:1,e.font=`${Math.round(14+6*Math.sin(Math.min(1,i*3)*Math.PI*.5))}px ${hi}`,e.textAlign=`center`,e.fillText(r.text,n.sx(r.x),n.sy(r.y)-i*18),e.textAlign=`left`,e.globalAlpha=1)}n.zoom>=yi&&this.drawBoardTexts(e,n);let i=this.o.state().me?.id,a=this.placed;a.length=0;let o=[];for(let e of r.charsDrawn){if(!e.visible)continue;let r=e.me?i:e.id;if(!r)continue;let a=this.balloons.get(r,t);if(!a)continue;let s=n.zoom>=.85?20:4;o.push({x:n.sx(e.x),y:n.sy(e.headY)-s,id:a.id,age:a.age,me:e.me})}o.sort((e,t)=>t.y-e.y);for(let t of o){let r=this.balloonWidth(e,t.id,n.zoom),i=t.y;for(let e=0;e<6;e++){let e=!1;for(let n=0;n<a.length;n+=4)t.x+r/2>a[n]&&t.x-r/2<a[n]+a[n+2]&&i>a[n+1]&&i-30<a[n+1]+a[n+3]&&(i=a[n+1]-2,e=!0);if(!e)break}a.push(t.x-r/2,i-30,r,30),this.drawBalloon(e,t.x,i,t.id,t.age,t.me,n.zoom)}}placed=[];balloonWidth(e,t,n){return n<.85?28:(e.font=`700 11.5px ${mi}`,Math.round(22+Math.min(170,e.measureText(Me(t)).width)+6+6))}drawSeal(e,t,n){e.save(),e.fillStyle=`rgba(20,24,33,0.85)`,e.strokeStyle=`rgba(200,206,220,0.8)`,e.lineWidth=1,e.beginPath(),e.arc(Math.round(t),Math.round(n),6,0,Math.PI*2),e.fill(),e.stroke(),e.fillStyle=`#c8cedc`,e.font=`800 9px ${mi}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`?`,Math.round(t),Math.round(n)+.5),e.restore()}drawBump(e,t,n,r){e.save(),e.globalAlpha=(1-r)*.9,e.strokeStyle=`#ff7b93`,e.lineWidth=2,e.beginPath(),e.arc(t,n,6+r*16,0,Math.PI*2),e.stroke(),e.globalAlpha=r<.8?1:(1-r)/.2,e.font=`800 12px ${mi}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillStyle=`rgba(10,14,24,0.6)`,e.fillText(`+❤`,t+.5,n-12-r*16+1),e.fillStyle=`#ffd1da`,e.fillText(`+❤`,t,n-12-r*16),e.restore()}drawBalloon(e,t,n,r,i,a,o){let s=Math.min(1,i/180),c=s<1?.6+.4*(1-(1-s)*(1-s))+Math.sin(s*Math.PI)*.08:1,l=i>4600?Math.max(0,1-(i-4600)/400):1,u=ke(r),d=o<.85?``:Me(r);e.save(),e.globalAlpha=l,e.translate(Math.round(t),Math.round(n)),e.scale(c,c),e.font=`700 11.5px ${mi}`;let f=d?Math.min(170,e.measureText(d).width):0,p=Math.round(22+(d?f+6:0)+6),m=-p/2;if(e.fillStyle=`rgba(10,14,24,0.35)`,e.beginPath(),e.roundRect(m+1,-27,p,22,9),e.fill(),e.fillStyle=a?`#e6f4ff`:`#fffaf0`,e.strokeStyle=a?`#7cc8ff`:`#2a2f3a`,e.lineWidth=1.5,e.beginPath(),e.roundRect(m,-29,p,22,9),e.fill(),e.stroke(),e.beginPath(),e.moveTo(-5,-8),e.lineTo(0,-1),e.lineTo(5,-8),e.closePath(),e.fill(),e.beginPath(),e.moveTo(-5,-7),e.lineTo(0,-1),e.lineTo(5,-7),e.stroke(),e.fillStyle=a?`#e6f4ff`:`#fffaf0`,e.fillRect(-4,-9,8,2),e.textBaseline=`middle`,e.textAlign=`left`,e.font=`14px ${hi}`,e.fillText(u,m+6,-17),d){e.font=`700 11.5px ${mi}`,e.fillStyle=`#1b2030`;let t=d;for(;t.length>1&&e.measureText(t).width>170;)t=`${t.slice(0,-2).trimEnd()}…`;e.fillText(t,m+26,-17.5)}e.restore()}drawBoardTexts(e,n){let r=Br(),i=n.k,a=this.goal(this.lastNow),o=Or(this.city),s=(t,n,r,i,a,o,s=700,c=`left`)=>{e.font=`${s} ${a.toFixed(1)}px ${mi}`;let l=t;for(;l.length>1&&e.measureText(l).width>i;)l=`${l.slice(0,-2).trimEnd()}…`;e.textAlign=c,e.fillStyle=`rgba(5,8,14,0.6)`,e.fillText(l,n+.5,r+1),e.fillStyle=o,e.fillText(l,n,r)},c=(t,n,r,i=600)=>{e.font=`${i} ${r.toFixed(1)}px ${mi}`;let a=[],o=``;for(let r of t.split(` `)){let t=o?`${o} ${r}`:r;e.measureText(t).width<=n||!o?o=t:(a.push(o),o=r)}return o&&a.push(o),a};e.save(),e.textBaseline=`middle`;let l=Math.max(7,Math.min(11,4.2*i)),u=l*1.18;{let e=r.goal,o=n.sx(e.x),d=n.sy(e.y),f=e.w*i;s(t(`META DA CIDADE`),o+f/2,d+4*i,f-4,Math.max(7,Math.min(11,4.6*i)),`#fff1e0`,800,`center`);let p=o+16*i,m=f-19*i;if(a){let e=Math.max(10,Math.min(24,9.5*i));s(a.pctText,p,d+17*i,m,e,a.pct>=1?`#ffd166`:`#ff9c74`,800);let t=d+17*i+e*.75+u*.5;for(let e of c(a.label,m,l).slice(0,2))s(e,p,t,m,l,`#d6dcea`,600),t+=u;s(a.progressText,p,t,m,l*.92,`#9aa4b8`,600)}else{let e=d+17*i;for(let n of c(t(`A meta aparece com 10 prédios acesos.`),m,l).slice(0,4))s(n,p,e,m,l,`#9aa4b8`,600),e+=u}}{let e=r.hall,a=n.sx(e.x),d=n.sy(e.y),f=e.w*i;s(t(`PREFEITURA`),a+f/2,d+4*i,f-4,Math.max(7,Math.min(11,4.6*i)),`#e3f1ff`,800,`center`);let p=a+23*i,m=f-26*i;if(o){let e=d+15*i;for(let t of c(o.lit,m,l,700).slice(0,2))s(t,p,e,m,l,`#ffd27a`,700),e+=u;e+=u*.3;for(let t of c(o.tokens,m,l).slice(0,4))s(t,p,e,m,l,`#d6dcea`,600),e+=u}}e.restore()}},Ti=class{s;el;likeBtn;knockBtn;hint;code;seal;id=``;key=``;constructor(e){this.s=e,this.likeBtn=N(`button`,{class:`ui-city-x__btn`,type:`button`,on:{click:()=>this.like()}}),this.knockBtn=N(`button`,{class:`ui-city-x__btn`,type:`button`,on:{click:()=>this.knock()}},N(`span`,{text:`🚪`,attrs:{"aria-hidden":`true`}}),` ${t(`Bater`)}`),this.hint=N(`span`,{class:`ui-city-x__hint`}),this.code=N(`span`,{class:`ui-city-x__code`,title:t(`Código do prédio: "Ir para", no minimapa, leva até a porta`)}),this.seal=N(`div`,{class:`ui-city-x__seal`,text:`❔ ${t(`Não verificado: os dados deste prédio estão em revisão.`)}`}),this.el=N(`div`,{class:`ui-city-x`},N(`div`,{class:`ui-city-x__row`},this.likeBtn,this.knockBtn,this.code),this.hint,this.seal)}bind(e){this.id=e,this.key=``,this.sync()}building(){return this.s.ctx.state.buildings.get(this.id)}sync(){let e=this.building();if(!e||!this.el.isConnected)return;let{me:n,state:r}=this.s.ctx,i=Xr(e,n,r.myBuildingId),a=`${e.id}|${i.canLike}|${i.canKnock}|${i.liked}|${i.mine}|${+!!e.knocks}|${e.code??``}|${+!!e.unverified}`;if(a===this.key)return;this.key=a,P(this.likeBtn,i.mine),this.likeBtn.replaceChildren(N(`span`,{text:i.liked?`💔`:`❤️`,attrs:{"aria-hidden":`true`}}),` ${i.liked?t(`Descurtir`):t(`Curtir`)}`),this.likeBtn.classList.toggle(`is-liked`,i.liked),this.likeBtn.disabled=!i.canLike,P(this.knockBtn,i.mine||!e.knocks),this.knockBtn.disabled=!i.canKnock,M(this.code,e.code??``),P(this.code,!e.code);let o=i.mine?t(`Seu prédio: os likes de hoje aparecem na barra do escritório.`):i.canLike?e.knocks&&!i.canKnock?t(`Mais perto da porta, dá para bater (K).`):``:t(`Chegue perto da porta para curtir (L).`);M(this.hint,o),P(this.hint,!o),P(this.seal,e.unverified!==!0)}like(){let e=this.building();e&&this.s.act.like(e)}knock(){let e=this.building();e&&this.s.act.knock(e)}},Ei=class{s;el;greetBtn;blockBtn;reportBtn;reasons;done;id=``;confirming=!1;constructor(e){this.s=e,this.greetBtn=N(`button`,{class:`ui-city-x__btn is-primary`,type:`button`,on:{click:()=>this.s.act.greet(this.id)}},N(`span`,{text:`👋`,attrs:{"aria-hidden":`true`}}),` ${t(`Cumprimentar`)}`,N(`kbd`,{text:`G`})),this.blockBtn=N(`button`,{class:`ui-city-x__btn is-quiet`,type:`button`,on:{click:()=>this.block()}}),this.reportBtn=N(`button`,{class:`ui-city-x__btn is-quiet`,type:`button`,attrs:{"aria-expanded":`false`},on:{click:()=>this.toggleReasons()}}),this.reasons=N(`div`,{class:`ui-city-x__reasons`,hidden:!0,role:`group`,attrs:{"aria-label":t(`Motivo da denúncia`)}},N(`span`,{class:`ui-city-x__hint`,text:t(`Qual o motivo?`)}),...s.map(e=>N(`button`,{class:`ui-city-x__reason`,type:`button`,text:Se(e),on:{click:()=>this.report(e)}}))),this.done=N(`div`,{class:`ui-city-x__done`,hidden:!0,text:`✓ ${t(`Denúncia enviada.`)}`}),this.el=N(`div`,{class:`ui-city-x`},N(`div`,{class:`ui-city-x__row`},this.greetBtn,this.blockBtn,this.reportBtn),this.reasons,this.done)}bind(e){e!==this.id&&(this.confirming=!1,P(this.reasons,!0)),this.id=e,this.sync()}sync(){if(!this.el.isConnected)return;let e=this.s.ctx.reported.has(this.id);M(this.blockBtn,this.confirming?`🚫 ${t(`Confirmar: bloquear`)}`:`🚫 ${t(`Bloquear`)}`),this.blockBtn.classList.toggle(`is-danger`,this.confirming),this.blockBtn.title=t(`Vocês deixam de se ver: na rua, nos prédios, nos cumprimentos e nos carimbos.`),M(this.reportBtn,e?`✓ ${t(`Denunciado`)}`:`⚑ ${t(`Denunciar`)}`),this.reportBtn.disabled=e,P(this.done,!e),e&&P(this.reasons,!0)}block(){if(!this.confirming){this.confirming=!0,this.sync();return}this.confirming=!1;let e=this.s.ctx.state.players.get(this.id)?.info.name??``;this.s.act.block(this.id,e)}toggleReasons(){let e=this.reasons.hidden;P(this.reasons,!e),this.reportBtn.setAttribute(`aria-expanded`,String(e))}report(e){this.s.act.report(this.id,e)&&this.sync()}};function Q(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var $=e=>typeof e==`number`&&Number.isFinite(e);function Di(e){return Q(e)&&typeof e.id==`string`&&Q(e.lot)&&$(e.lot.x)&&$(e.lot.y)&&Q(e.owner)&&typeof e.owner.name==`string`}function Oi(e){return Q(e)&&typeof e.id==`string`&&typeof e.name==`string`&&Q(e.pos)&&$(e.pos.x)&&$(e.pos.y)}function ki(e){if(!Q(e)||!$(e.x)||!$(e.y))return null;let t=e.dir===`n`||e.dir===`s`||e.dir===`e`||e.dir===`w`?e.dir:`s`;return{x:e.x,y:e.y,dir:t,moving:e.moving===!0}}function Ai(e){return Q(e)&&typeof e.id==`string`&&$(e.rev)&&Q(e.detail)&&Di(e.detail.building)&&Array.isArray(e.detail.floors)}var ji=e=>Q(e)&&$(e.x)&&$(e.y)&&$(e.lit),Mi=class{me=null;startPos=null;myBuildingId=null;connected=!1;afk=!1;inside=null;district;buildings=new Map;lots=new Map;chunkIds=new Map;chunkRev=new Map;players=new Map;minimap=[];version=0;minimapVersion=0;buildingAt(e){let t=this.lots.get(B(e));return t?this.buildings.get(t):void 0}myBuilding(){return this.myBuildingId?this.buildings.get(this.myBuildingId):void 0}applySnapshot(e,t){this.buildings.clear(),this.lots.clear(),this.chunkIds.clear(),this.chunkRev.clear(),this.players.clear(),this.connected=e.connected!==!1,this.afk=e.afk===!0,this.inside=Ai(e.inside)?structuredClone(e.inside):null,this.district=typeof e.district==`string`?e.district:void 0,e.me&&(this.me=e.me,this.myBuildingId=e.me.buildingId??e.me.id);let n=ki(e.pos);n&&(this.startPos={x:n.x,y:n.y});for(let t of Array.isArray(e.chunks)?e.chunks:[])Q(t)&&typeof t.chunk==`string`&&Array.isArray(t.buildings)&&this.applyArea(t.chunk,$(t.rev)?t.rev:0,t.buildings.filter(Di));for(let n of Array.isArray(e.players)?e.players:[])Oi(n)&&this.join(n,t);this.minimap=[],Array.isArray(e.minimap)&&this.setMinimap(e.minimap.filter(ji)),this.minimapVersion++,this.version++}apply(e,t){if(!Q(e)||typeof e.t!=`string`)return null;switch(e.t){case`area`:return typeof e.chunk==`string`&&Array.isArray(e.buildings)&&(this.applyArea(e.chunk,$(e.rev)?e.rev:0,e.buildings.filter(Di)),this.version++),null;case`area.patch`:return typeof e.chunk==`string`&&this.applyPatch(e.chunk,e),null;case`players`:if(Array.isArray(e.players))for(let n of e.players){if(!Q(n)||typeof n.id!=`string`||n.id===this.me?.id)continue;let e=this.players.get(n.id),r=ki(n.pos);e&&r&&(e.info.pos=r,Q(n.greeting)&&(e.info.greeting=n.greeting),mn(e.samples,{t,...r}))}return null;case`player.join`:return Oi(e.player)&&this.join(e.player,t),null;case`player.leave`:return typeof e.id==`string`&&this.players.delete(e.id),null;case`profile`:if(Oi(e.player)){let t=this.players.get(e.player.id);return t&&(t.info={...t.info,...e.player,pos:t.info.pos}),{type:`profile`,player:e.player}}return null;case`minimap`:return Array.isArray(e.blocks)&&(this.setMinimap(e.blocks.filter(ji)),this.minimapVersion++),null;case`like.update`:{let t=typeof e.buildingId==`string`?this.buildings.get(e.buildingId):void 0;return t&&$(e.likes)&&(t.likes=e.likes,t.likedByMe=e.likedByMe===!0,this.version++),null}case`pos`:return $(e.x)&&$(e.y)?{type:`pos`,x:e.x,y:e.y}:null;case`afk`:return this.afk=!0,{type:`afk`};case`notice`:return typeof e.text==`string`?{type:`notice`,level:e.level===`warn`||e.level===`error`?e.level:`info`,text:e.text}:null;case`building`:{let t=e.detail;return!$(e.rev)||!Q(t)||!Di(t.building)||!Array.isArray(t.floors)?null:{type:`building`,inside:{id:t.building.id,rev:e.rev,detail:{building:t.building,floors:t.floors,visitors:$(t.visitors)?t.visitors:0}}}}case`building.patch`:return $(e.rev)?{type:`building.patch`,msg:e}:null;default:return null}}keepAround(e,t){let n=this.district;if(n===void 0){for(let e of this.chunkIds.keys())if(n=b(e)?.district,n!==void 0)break}if(n===void 0)return!1;let r=n,i=new Set(C(h(x(e,t))).map(e=>k(r,e))),a=!1;for(let[e,t]of[...this.chunkIds])if(!i.has(e)){for(let e of t)this.removeBuilding(e);this.chunkIds.delete(e),this.chunkRev.delete(e),a=!0}return a&&this.version++,a}join(e,t){if(e.id===this.me?.id)return;let n=this.players.get(e.id),r=n?.samples??[];mn(r,{t,...ki(e.pos)}),this.players.set(e.id,{info:{...e},samples:r,...n?.delay===void 0?{}:{delay:n.delay}})}setMinimap(e){this.minimap=e.map(e=>({x:Math.floor(e.x),y:Math.floor(e.y),lit:Math.max(0,Math.floor(e.lit))}))}putBuilding(e,t){let n=this.buildings.get(e.id);n&&B(n.lot)!==B(e.lot)&&this.lots.get(B(n.lot))===e.id&&this.lots.delete(B(n.lot)),this.buildings.set(e.id,e),this.lots.set(B(e.lot),e.id);for(let[n,r]of this.chunkIds)n!==t&&r.delete(e.id);let r=this.chunkIds.get(t);r||this.chunkIds.set(t,r=new Set),r.add(e.id)}removeBuilding(e){let t=this.buildings.get(e);if(t){this.lots.get(B(t.lot))===e&&this.lots.delete(B(t.lot)),this.buildings.delete(e);for(let t of this.chunkIds.values())t.delete(e)}}applyArea(e,t,n){let r=new Set(n.map(e=>e.id));for(let t of this.chunkIds.get(e)??[])r.has(t)||this.removeBuilding(t);this.chunkIds.set(e,new Set),this.chunkRev.set(e,t);for(let t of n)this.putBuilding({...t},e)}applyPatch(e,t){$(t.rev)&&this.chunkRev.set(e,t.rev);for(let n of Array.isArray(t.changes)?t.changes:[]){if(!Q(n)||typeof n.id!=`string`)continue;if(n.lot!==void 0){Di(n)&&this.putBuilding({...n},e);continue}let t=this.buildings.get(n.id);t&&this.putBuilding({...t,...n},e)}if(Array.isArray(t.removed))for(let e of t.removed)typeof e==`string`&&this.removeBuilding(e);this.version++}},Ni=se,Pi=.28,Fi=[.375,.5,.75],Ii=3e4,Li=2,Ri=5e3,zi=class extends Ae{levels(){let e=new Set(super.levels());for(let t of Fi)t>=this.minZoom-1e-6&&e.add(t);return e.add(this.minZoom),[...e].sort((e,t)=>e-t)}};function Bi(e){let n=new zi;n.minZoom=Pi,n.bounds={x:-1e7,y:-1e7,w:2e7,h:2e7};let r=new Mi,i=new Sr(e.canvas,Ni,n,r),a=null,s=null,c=null,l=!0,u=!1,f=0,p=0,m=null,g=null,_=``,v=null,b=null,S=!1,C=!1,w,T=null,E=!1,ee=new fe(ct({x:0,y:0,w:4,h:4}).grid),D=[],O=[],k=null,A=new Ke({showBuilding:e=>oe(e),topInset:()=>e.topInset(),enter:e=>ce(e),extras:(e,t)=>k?.cardExtras(e,t)??null}),te=new wt(e=>{l=!1;let t=n.zoom,r=n.centerFor(e.x*16,e.y*16,t);n.animateTo(r.x,r.y,t,Date.now(),380)}),j=N(`div`,{class:`ui-city-toast`,role:`status`,attrs:{"aria-live":`polite`},hidden:!0}),M=N(`div`,{class:`ui-city-loading`,text:t(`Entrando na cidade…`)}),P=N(`div`,{class:`ui-city-help`,attrs:{"aria-hidden":`true`}},N(`span`,{},N(`kbd`,{text:`WASD`}),` `,t(`andar`)),N(`span`,{},N(`kbd`,{text:`Shift`}),` `,t(`correr`)),N(`span`,{},N(`kbd`,{text:t(`clique`)}),` `,t(`ir até lá`)),N(`span`,{},N(`kbd`,{text:`E`}),` `,t(`entrar`)),N(`span`,{},N(`kbd`,{text:`Esc`}),` `,t(`escritório`))),F=N(`div`,{class:`ui-city`,hidden:!0},A.el,te.el,P,j,M);e.uiRoot.append(F),k=new wi({state:()=>r,renderer:()=>i,camera:n,canvas:e.canvas,send:e=>a?.send(e),me:()=>s?{x:s.x,y:s.y}:null,cards:A,toast:e=>L(e),active:()=>u,teleported:()=>{if(!s)return;l=!0,n.stop();let e=n.centerFor(s.x*16,s.y*16-12,n.zoom);n.x=e.x,n.y=e.y,_=``},replay:e=>{let t=r.apply(e,performance.now());t&&se(t)},testFireworks:()=>a?.celebrate?.()}),F.append(k.el),P.append(...k.helpItems());let I=null,L=e=>{j.textContent=e,j.hidden=!1,j.classList.remove(`is-in`),j.offsetWidth,j.classList.add(`is-in`),I&&clearTimeout(I),I=setTimeout(()=>j.hidden=!0,2600)},R=()=>{let t=Math.max(1,Math.min(3,window.devicePixelRatio||1)),r=e.canvas.clientWidth||window.innerWidth,i=e.canvas.clientHeight||window.innerHeight,a=Math.floor(r*t),o=Math.floor(i*t);(e.canvas.width!==a||e.canvas.height!==o)&&(e.canvas.width=a,e.canvas.height=o),n.setView(r,i,t),n.insets={top:e.topInset(),right:0,bottom:0,left:0}},ne=()=>{let e=r.me,t=r.startPos;if(!e||s||!t)return;if(r.startPos=null,!dt(t.x,t.y)){let e=ut(t.x,t.y);e&&(t={x:e.x+.5,y:e.y+.5})}s=new yn(t.x,t.y),c=new Sn(e=>a?.send([e])),l=!0;let i=n.zoom,o=n.centerFor(s.x*16,s.y*16-12,i);n.stop(),n.x=o.x,n.y=o.y,M.hidden=!0},re=()=>{if(!s)return;l=!0;let e=n.centerFor(s.x*16,s.y*16-12,n.zoom);n.stop(),n.x=e.x,n.y=e.y},ie=()=>{S=!1;let e=r.startPos;if(!e){C=!0;return}let t=Cr(b,e);if(b=null,t===`keep`){r.startPos=null,c?.reset();return}s=null,c=null},ae=(e,t,n)=>{if(!s)return!1;let r={x:e,y:t};if(!dt(e,t)){let n=ut(e,t,6);if(!n)return!1;r={x:n.x+.5,y:n.y+.5}}let i=ct(lt(s,r));ee.setGrid(i.grid);let a=Math.floor(s.x)-i.ox,o=Math.floor(s.y)-i.oy,c=Math.floor(r.x)-i.ox,u=Math.floor(r.y)-i.oy,d=[];return ee.find(a,o,c,u,d)?(s.follow(bn(d,i.ox,i.oy,r),n),l=!0,!0):!1},oe=e=>{let t=r.buildings.get(e);if(!t)return;l=!1;let i=y(t.lot),a=Math.max(n.zoom,1.5),o=n.centerFor(i.front.x*16,i.front.y*16-60,a);n.animateTo(o.x,o.y,a,Date.now(),420)},se=e=>{switch(e.type){case`building`:ue(e.inside);break;case`building.patch`:v?.patch(e.msg);break;case`pos`:if(v&&de(),s&&C){C=!1;let t=Cr(b,e);b=null,t!==`keep`&&(s.correct(e.x,e.y),re()),c?.reset()}else s?(s.correct(e.x,e.y),c?.reset()):(r.startPos={x:e.x,y:e.y},ne(),le());break;case`afk`:break;case`profile`:if(A.kind===`player`&&A.id===e.player.id){let t=r.players.get(e.player.id),n=t?t.info:e.player;A.showPlayer(n,n.buildingId?r.buildings.get(n.buildingId):void 0,null)}break;case`notice`:{let t=v?`inside`:T&&Date.now()-T.at<Ri?`door`:`street`;t===`door`&&(T=null);let n=Tt(e.text,t);n&&L(n);break}}},ce=e=>{if(v||!a||!s){!s&&e===r.myBuildingId&&(E=!0);return}T={id:e,at:Date.now()},a.send([{t:`enter`,buildingId:e}])},le=()=>{E&&s&&r.connected&&r.myBuildingId&&(E=!1,ce(r.myBuildingId))},ue=t=>{if(T=null,v&&v.id===t.id){v.replace(t);return}v&&de();let n=r.me;if(!n||!u)return;A.hide(),xe.clearKeys(),cancelAnimationFrame(f),e.canvas.hidden=!0,F.classList.add(`is-visiting`);let i=a;v=nn({uiRoot:e.uiRoot,after:e.canvas,inside:t,me:n,mine:t.id===r.myBuildingId,options:()=>e.options(),version:e.version?.()??``,topInset:()=>e.topInset(),send:e=>i?.send(e),toast:e=>L(e),summaryStamps:()=>w?.stamps??[],stuck:()=>{de(),a?.send([{t:`view`}])}})},de=()=>{if(!v)return;let t=v;v=null,t.destroy(),F.classList.remove(`is-visiting`),u&&(e.canvas.hidden=!1,p=0,cancelAnimationFrame(f),f=requestAnimationFrame(Ce),l=!0)},pe=()=>t(`Sem conexão com o Habblaud World agora; o Habblaud tenta de novo sozinho.`),me=e=>{switch(e.type){case`snapshot`:r.applySnapshot(e.snapshot,performance.now()),k?.snapshot(e.snapshot),w=e.snapshot.summary,S&&ie(),ne(),s&&(_=``),r.inside?ue(r.inside):v&&de(),le(),M.textContent=r.connected?t(`Entrando na cidade…`):pe(),M.hidden=r.connected&&!!s;return;case`message`:{if(v?.message(e.msg)||k?.message(e.msg,performance.now()))return;e.msg.t===`away.summary`&&(w=o(e.msg)??w);let t=r.apply(e.msg,performance.now());t&&se(t);return}case`status`:e.status===`retrying`&&(M.textContent=pe(),M.hidden=!1);return;case`error`:e.code===`not_connected`?(M.textContent=pe(),M.hidden=!1):e.code!==`no_stream`&&L(d(e.code,`scene`));return}},he=()=>{S=!!(b?.me&&s),C=!1,S||(b=null,r=new Mi,i=new Sr(e.canvas,Ni,n,r),i.fx=k,s=null,c=null,M.textContent=t(`Entrando na cidade…`),M.hidden=!1),k?.reset(),_=``,A.hide();let o=e.openStream();a=o,o.on(e=>{if(a===o)try{me(e)}catch(e){console.error(`[cidade] evento do stream ignorado`,e)}})},ge=()=>{a?.close(),a=null},_e=(e,t)=>{let r=n.screenToWorld(e,t),a=Math.max(1,3/n.zoom);for(let e=i.charsDrawn.length-1;e>=0;e--){let t=i.charsDrawn[e];if(t.visible&&!t.me&&r.x>=t.bx-a&&r.x<=t.bx+t.bw+a&&r.y>=t.by-a&&r.y<=t.by+t.bh+a)return{type:`player`,id:t.id}}let o=null,s=-1/0;for(let e of i.buildingsDrawn)r.x<e.x||r.x>e.x+192||r.y<e.y||r.y>e.y+e.m.height||e.depth>s&&(s=e.depth,o={type:`building`,id:e.b.id});return o},z=null,ve=(e,t,i)=>{let o=_e(e,t),s=ye(e,t);if(o?.type===`player`){let e=r.players.get(o.id);if(!e)return;A.showPlayer(e.info,e.info.buildingId?r.buildings.get(e.info.buildingId):void 0,s),a?.send([{t:`profile`,playerId:o.id}]);return}if(o?.type===`building`){let e=r.buildings.get(o.id);if(!e)return;A.showBuilding(e,r.myBuildingId,s,!0);let t=y(e.lot).front;ae(t.x,t.y+(y(e.lot).side===`s`?.3:-.3),i.shift);return}A.hide();let c=n.screenToWorld(e,t);ae(c.x/16,c.y/16,i.shift)},ye=(t,n)=>{let r=e.canvas.getBoundingClientRect();return{x:r.left+t,y:r.top+n}},be=()=>{if(!m){z&&A.kind===`building`&&!A.pinned&&A.hide(),z=null,e.canvas.style.cursor=``;return}let t=_e(m.x,m.y);if(z=t,e.canvas.style.cursor=t?`pointer`:`crosshair`,t?.type===`building`){let e=r.buildings.get(t.id);e&&(!A.pinned||A.id===e.id)&&A.showBuilding(e,r.myBuildingId,ye(m.x,m.y),!1)}else A.kind===`building`&&!A.pinned&&A.hide()},xe=new Qe(e.canvas,n,{active:()=>u&&!v,hover:(e,t,n)=>{m=n?{x:e,y:t}:null},click:ve,interact:()=>{l=!1,n.stop()},zoomStep:(e,t=n.viewW/2,r=n.viewH/2)=>n.zoomAt(n.stepZoom(e),t,r,Date.now(),!0),use:()=>{if(!s)return;let e=ft(s.x,s.y,e=>!!r.buildingAt(e),2),n=e?r.buildingAt(e.lot):void 0;if(!n){L(t(`Chegue perto da porta de um prédio e aperte E.`));return}ce(n.id)},recenter:()=>Se(),moved:()=>{l=!0}}),Se=()=>{if(v)return v.world.overview();if(l=!0,!s)return;let e=n.centerFor(s.x*16,s.y*16-12,n.zoom);n.animateTo(e.x,e.y,n.zoom,Date.now(),360)},Ce=t=>{f=requestAnimationFrame(Ce);let a=p?t-p:16.7,o=p?Math.min(.1,Math.max(0,a/1e3)):1/60;p=t,O.push(a),O.length>240&&O.shift();let u=performance.now();try{let t=Math.max(1,Math.min(3,window.devicePixelRatio||1));(e.canvas.clientWidth!==n.viewW||e.canvas.clientHeight!==n.viewH||t!==n.dpr)&&R();let a=r.me;if(s&&a&&!S){s.update(o,xe.intent()),c?.tick(u,s);let e=h(x(s.x,s.y)),t=`${e.x},${e.y}`;t!==_&&(_=t,r.keepAround(s.x,s.y))}k?.frame(u,o);let d=l&&s?n.centerFor(s.x*16,s.y*16-12,n.zoom):null;n.update(Date.now(),d,o);let f=s?ft(s.x,s.y,e=>!!r.buildingAt(e),2):null;if(i.frame(u,o,e.options(),s&&a?{player:s,self:a}:null,{building:z?.type===`building`?z.id:A.kind===`building`?A.id:null,player:z?.type===`player`?z.id:A.kind===`player`?A.id:null,door:f?f.front:null,me:s?{x:s.x,y:s.y}:null}),D.push(i.lastFrameMs),D.length>240&&D.shift(),be(),A.kind===`building`&&A.id&&!r.buildings.has(A.id)&&A.hide(),A.kind===`player`&&A.id&&!r.players.has(A.id)&&A.hide(),s){let e=n.screenToWorld(0,0),t=n.screenToWorld(n.viewW,n.viewH);te.draw(r.minimap,r.minimapVersion,s,{x:e.x/16,y:e.y/16,w:(t.x-e.x)/16,h:(t.y-e.y)/16})}}catch(e){console.error(`[cidade] erro no frame`,e)}},we=()=>{p=0,xe.clearKeys(),document.hidden||c?.reset()},Te={get visible(){return u},show(){u||(u=!0,e.canvas.hidden=!1,F.hidden=!1,R(),b?(n.stop(),n.zoom=b.zoom,n.x=b.camX,n.y=b.camY,l=b.following):n.animating||(n.zoom=n.viewW<600?1.5:2),he(),p=0,f=requestAnimationFrame(Ce),window.addEventListener(`resize`,R),document.addEventListener(`visibilitychange`,we),g=setInterval(()=>{document.hidden&&s&&c&&!v&&c.keepAlive(s)},Ii))},hide(){u&&(v&&de(),E=!1,b={camX:n.x,camY:n.y,zoom:n.zoom,following:l,me:s?{x:s.x,y:s.y}:null},u=!1,cancelAnimationFrame(f),e.canvas.hidden=!0,F.hidden=!0,A.hide(),k?.hide(),xe.clearKeys(),ge(),window.removeEventListener(`resize`,R),document.removeEventListener(`visibilitychange`,we),g&&clearInterval(g),g=null)},zoomBy(e){if(!(!Number.isFinite(e)||e<=0||e===1)){if(v)return v.world.zoomBy(e);n.zoomAt(n.stepZoom(e>1?1:-1),n.viewW/2,n.viewH/2,Date.now(),!0)}},recenter:Se,lookAt(e,t,r=n.zoom){l=!1,n.stop(),n.zoom=Math.max(Pi,Math.min(6,r));let i=n.centerFor(e*16,t*16,n.zoom);n.x=i.x,n.y=i.y},escape(){return v?v.escape():k?.escape()?!0:A.open?(A.hide(),!0):!1},destroy(){Te.hide(),xe.destroy(),k?.destroy(),F.remove()},perf(){let e=[...D].sort((e,t)=>e-t),t=D.reduce((e,t)=>e+t,0)/Math.max(1,D.length),r=e[Math.min(e.length-1,Math.floor(e.length*.95))]??0,a=O.reduce((e,t)=>e+t,0)/Math.max(1,O.length);return{frames:D.length,drawAvgMs:t,drawP95Ms:r,drawMaxMs:e[e.length-1]??0,fps:a?1e3/a:0,buildings:i.buildingsDrawn.length,zoom:n.zoom}},camera:n,get state(){return r},perfReset(){D.length=0,O.length=0},me:()=>s?{x:s.x,y:s.y,moving:s.moving,seated:!s.moving&&i.onBench(s.x,s.y)}:null,toScreen:(e,t)=>n.worldToScreen(e*16,t*16),enter:e=>ce(e),visitOwn(){let e=r.myBuildingId;s&&a&&e&&r.connected?ce(e):E=!0},visit:()=>v,walkTo:(e,t)=>ae(e,t,!1),doorOf(e){let t=r.buildings.get(e);return t?{...y(t.lot).front}:null}};return Te}export{Pi as CITY_MIN_ZOOM,Li as ENTER_RADIUS,Bi as createCityScene};
|