busybits 0.0.0-stage → 2.0.1

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.
Files changed (111) hide show
  1. package/.claude-plugin/marketplace.json +26 -0
  2. package/CHANGELOG.md +692 -0
  3. package/LICENSE +21 -0
  4. package/README.es.md +1457 -0
  5. package/README.fr.md +1435 -0
  6. package/README.md +1623 -2
  7. package/README.pt-BR.md +1373 -0
  8. package/dist/build.json +5 -0
  9. package/dist/cli/busybits.js +14724 -0
  10. package/dist/client/assets/art/framed/painting-abstract.png +0 -0
  11. package/dist/client/assets/art/framed/painting-beach.png +0 -0
  12. package/dist/client/assets/art/framed/painting-cat.png +0 -0
  13. package/dist/client/assets/art/framed/painting-city-night.png +0 -0
  14. package/dist/client/assets/art/framed/painting-mountains.png +0 -0
  15. package/dist/client/assets/art/framed/painting-rio.png +0 -0
  16. package/dist/client/assets/art/framed/painting-sunflowers.png +0 -0
  17. package/dist/client/assets/art/framed/painting-wave.png +0 -0
  18. package/dist/client/assets/art/framed/painting-wide-aurora.png +0 -0
  19. package/dist/client/assets/art/framed/painting-wide-color-fields.png +0 -0
  20. package/dist/client/assets/art/framed/painting-wide-forest-lake.png +0 -0
  21. package/dist/client/assets/art/painting-abstract.png +0 -0
  22. package/dist/client/assets/art/painting-beach.png +0 -0
  23. package/dist/client/assets/art/painting-cat.png +0 -0
  24. package/dist/client/assets/art/painting-city-night.png +0 -0
  25. package/dist/client/assets/art/painting-mountains.png +0 -0
  26. package/dist/client/assets/art/painting-rio.png +0 -0
  27. package/dist/client/assets/art/painting-sunflowers.png +0 -0
  28. package/dist/client/assets/art/painting-wave.png +0 -0
  29. package/dist/client/assets/art/painting-wide-aurora.png +0 -0
  30. package/dist/client/assets/art/painting-wide-color-fields.png +0 -0
  31. package/dist/client/assets/art/painting-wide-forest-lake.png +0 -0
  32. package/dist/client/assets/art/poster-bug.png +0 -0
  33. package/dist/client/assets/art/poster-cat.png +0 -0
  34. package/dist/client/assets/art/poster-code.png +0 -0
  35. package/dist/client/assets/art/poster-coffee.png +0 -0
  36. package/dist/client/assets/art/poster-rocket.png +0 -0
  37. package/dist/client/assets/art/poster-ship-it.png +0 -0
  38. package/dist/client/assets/brand/apple-touch-icon.png +0 -0
  39. package/dist/client/assets/brand/favicon-16.png +0 -0
  40. package/dist/client/assets/brand/favicon-32.png +0 -0
  41. package/dist/client/assets/brand/icon-192.png +0 -0
  42. package/dist/client/assets/brand/icon-512.png +0 -0
  43. package/dist/client/assets/brand/logo-detailed.png +0 -0
  44. package/dist/client/assets/brand/logo-mark.png +0 -0
  45. package/dist/client/assets/brand/logo-mark@4x.png +0 -0
  46. package/dist/client/assets/brand/signage.png +0 -0
  47. package/dist/client/assets/brand/signage@4x.png +0 -0
  48. package/dist/client/assets/emoji/LICENSE-SerenityOS.txt +28 -0
  49. package/dist/client/assets/emoji/sheet.png +0 -0
  50. package/dist/client/assets/illustrations/empty-office.png +0 -0
  51. package/dist/client/assets/manifest.json +260 -0
  52. package/dist/client/assets/og-image.png +0 -0
  53. package/dist/client/bundle/app-CoDOLwxe.css +1 -0
  54. package/dist/client/bundle/app-QYGBa260.js +24 -0
  55. package/dist/client/bundle/city-DPTwQLdi.css +1 -0
  56. package/dist/client/bundle/city-UYDbxWIy.js +1 -0
  57. package/dist/client/bundle/daystats-CJyNq6hu.js +1 -0
  58. package/dist/client/bundle/dom-slmnBOjx.js +1 -0
  59. package/dist/client/bundle/en-BQQEHqmG.js +169 -0
  60. package/dist/client/bundle/es-BgBoKwEe.js +169 -0
  61. package/dist/client/bundle/format-CvlPqloO.js +1 -0
  62. package/dist/client/bundle/fr-PI_gjIFq.js +169 -0
  63. package/dist/client/bundle/main-DTHUta25.js +2 -0
  64. package/dist/client/bundle/pixelify-sans-cyrillic-400-normal-Ckz2YJkH.woff2 +0 -0
  65. package/dist/client/bundle/pixelify-sans-cyrillic-400-normal-DfOZNMlW.woff +0 -0
  66. package/dist/client/bundle/pixelify-sans-cyrillic-500-normal--wrb4dVK.woff2 +0 -0
  67. package/dist/client/bundle/pixelify-sans-cyrillic-500-normal-CR9SIKMr.woff +0 -0
  68. package/dist/client/bundle/pixelify-sans-cyrillic-600-normal-B3EuUOZG.woff +0 -0
  69. package/dist/client/bundle/pixelify-sans-cyrillic-600-normal-BhqNJYOZ.woff2 +0 -0
  70. package/dist/client/bundle/pixelify-sans-cyrillic-700-normal-BrZTw8tu.woff +0 -0
  71. package/dist/client/bundle/pixelify-sans-cyrillic-700-normal-CYtG5Rfp.woff2 +0 -0
  72. package/dist/client/bundle/pixelify-sans-latin-400-normal-DLrIX9QE.woff2 +0 -0
  73. package/dist/client/bundle/pixelify-sans-latin-400-normal-JapMNN6Z.woff +0 -0
  74. package/dist/client/bundle/pixelify-sans-latin-500-normal-Bq6pAlou.woff +0 -0
  75. package/dist/client/bundle/pixelify-sans-latin-500-normal-DC052d-m.woff2 +0 -0
  76. package/dist/client/bundle/pixelify-sans-latin-600-normal-BNlgYbDL.woff +0 -0
  77. package/dist/client/bundle/pixelify-sans-latin-600-normal-Dd_Dy7u5.woff2 +0 -0
  78. package/dist/client/bundle/pixelify-sans-latin-700-normal-BctWAS0u.woff +0 -0
  79. package/dist/client/bundle/pixelify-sans-latin-700-normal-D3Xxx3QE.woff2 +0 -0
  80. package/dist/client/bundle/pixelify-sans-latin-ext-400-normal-BkfTUL4s.woff +0 -0
  81. package/dist/client/bundle/pixelify-sans-latin-ext-400-normal-DdH6zlBQ.woff2 +0 -0
  82. package/dist/client/bundle/pixelify-sans-latin-ext-500-normal-BHT4w5qI.woff2 +0 -0
  83. package/dist/client/bundle/pixelify-sans-latin-ext-500-normal-Bkr-oq6R.woff +0 -0
  84. package/dist/client/bundle/pixelify-sans-latin-ext-600-normal-CDaIumwU.woff +0 -0
  85. package/dist/client/bundle/pixelify-sans-latin-ext-600-normal-Dha6RiOG.woff2 +0 -0
  86. package/dist/client/bundle/pixelify-sans-latin-ext-700-normal-BadXkHzZ.woff +0 -0
  87. package/dist/client/bundle/pixelify-sans-latin-ext-700-normal-ClyJstAh.woff2 +0 -0
  88. package/dist/client/bundle/ptypane-9pL54zR0.js +16 -0
  89. package/dist/client/bundle/ptypane-BrP-ENHg.css +1 -0
  90. package/dist/client/bundle/room-name-Bv6N672f.js +1 -0
  91. package/dist/client/bundle/simulator-B45JPgSp.js +7 -0
  92. package/dist/client/bundle/world-model-BgjMjmrp.js +1 -0
  93. package/dist/client/bundle/world-stream-CUfry7aL.js +1 -0
  94. package/dist/client/index.html +41 -0
  95. package/dist/client/manifest.webmanifest +17 -0
  96. package/dist/server/index.js +40342 -0
  97. package/mod/README.md +193 -0
  98. package/mod/habblaud/.claude-plugin/plugin.json +11 -0
  99. package/mod/habblaud/hooks/hooks.json +4 -0
  100. package/mod/habblaud/hooks/register.ts +517 -0
  101. package/mod/habblaud-codex/hook.mjs +274 -0
  102. package/mod/habblaud-mensagens/.claude-plugin/plugin.json +11 -0
  103. package/mod/habblaud-mensagens/hooks/hooks.json +4 -0
  104. package/mod/habblaud-mensagens/hooks/register.ts +384 -0
  105. package/mod/habblaud-permissoes/.claude-plugin/plugin.json +11 -0
  106. package/mod/habblaud-permissoes/hooks/hooks.json +18 -0
  107. package/mod/habblaud-permissoes/hooks/permission-hook.mjs +265 -0
  108. package/mod/habblaud-pi/core.ts +325 -0
  109. package/mod/habblaud-pi/extension.ts +119 -0
  110. package/mod/habblaud-pi/package.json +12 -0
  111. package/package.json +100 -4
@@ -0,0 +1 @@
1
+ .ui-visit-social{flex-direction:column;gap:8px;display:flex}.ui-visit-social[hidden]{display:none}.ui-visit-social__row{flex-wrap:wrap;gap:6px;display:flex}.ui-visit-social__like,.ui-visit-social__stamp{background:var(--ui-bg-soft);border:1px solid var(--ui-line-strong);min-height:32px;color:var(--ui-text);font:700 12px/1 var(--font-ui);border-radius:9px;align-items:center;gap:6px;padding:0 11px;display:inline-flex}.ui-visit-social__like{background:#ff50781a;border-color:#ff6e8c73}.ui-visit-social__like.is-liked{background:#ff507833}.ui-visit-social__like.is-pop{animation:.45s cubic-bezier(.2,1.6,.4,1) ui-visit-pop}@keyframes ui-visit-pop{40%{transform:scale(1.12)}}.ui-visit-social__count{color:#ffc7d2;font-variant-numeric:tabular-nums;background:#00000040;border-radius:999px;padding:1px 6px}.ui-visit-social__stamp:disabled{opacity:.8;cursor:default;border-style:dashed}.ui-visit-social__picker{background:var(--ui-bg-solid);border:1px solid var(--ui-line-strong);border-radius:10px;flex-direction:column;gap:6px;padding:8px;display:flex}.ui-visit-social__picker[hidden]{display:none}.ui-visit-social__hint{color:var(--ui-muted);margin:0;font-size:11px}.ui-visit-social__grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;display:grid}.ui-visit-social__choice{color:var(--ui-text);font:600 11.5px/1.2 var(--font-ui);text-align:left;background:#ff8fa30f;border:1.5px dashed #ff8fa373;border-radius:8px;align-items:center;gap:6px;padding:6px 8px;display:flex}.ui-visit-social__choice:hover{background:#ff8fa329;transform:rotate(-2deg)}.ui-visit-social__choice-icon{font-size:16px;line-height:1}.ui-visit-panel__social:has(>.ui-visit-social[hidden]){display:none}.ui-visit-panel__social{border-bottom:1px solid var(--ui-line);padding-bottom:8px}.ui-visit-board{box-sizing:border-box;background:radial-gradient(circle at 20% 30%,#50301459 0 1px,#0000 1.5px) 0 0/7px 6px,radial-gradient(circle at 70% 60%,#ffecc840 0 1px,#0000 1.5px) 0 0/9px 8px,#b98a55;border:2px solid #6b4a2b;border-radius:2px;position:fixed;top:0;left:0;box-shadow:inset 0 0 0 1px #ffe6be59,1px 2px #1e223440;pointer-events:none!important}.ui-visit-board[hidden]{display:none}.ui-visit-board__pins{position:absolute;inset:6%}.ui-visit-board__pin{transform:translate(-50%, -50%) rotate(var(--rot,0deg));font-size:var(--pin,12px);filter:drop-shadow(0 1px #1e140a73);line-height:1;position:absolute}.ui-visit-board__pin.is-mine{outline-offset:1px;border-radius:3px;outline:1.5px dashed #fff0c8d9}@media (prefers-reduced-motion:reduce){.ui-visit-social__like.is-pop{animation:none}.ui-visit-social__choice:hover{transform:none}}.ui-root.is-city .ui-toasts{bottom:calc(226px + env(safe-area-inset-bottom))}.ui-city-dock{left:50%;bottom:calc(52px + env(safe-area-inset-bottom));background:var(--ui-bg);border:1px solid var(--ui-line-strong);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);animation:ui-city-dock-in .22s var(--ease);border-radius:14px;gap:8px;padding:5px;display:flex;position:fixed;transform:translate(-50%);box-shadow:0 10px 26px #05070c73}.ui-city-dock[hidden]{display:none}@keyframes ui-city-dock-in{0%{opacity:0;transform:translate(-50%,8px)}}.ui-city-dock__btn{background:var(--ui-bg-soft);border:1px solid var(--ui-line);min-height:36px;color:var(--ui-text);font:700 12.5px/1 var(--font-ui);white-space:nowrap;border-radius:10px;align-items:center;gap:6px;padding:0 10px 0 8px;transition:background .15s,transform .1s;display:inline-flex}.ui-city-dock__btn:hover{background:var(--ui-bg-hover)}.ui-city-dock__btn:active{transform:scale(.96)}.ui-city-dock__btn.is-like{background:#ff50781f;border-color:#ff6e8c73}.ui-city-dock__btn.is-like .ui-city-dock__icon{animation:1.4s ease-in-out infinite ui-city-heartbeat}@keyframes ui-city-heartbeat{0%,60%,to{transform:none}70%{transform:scale(1.25)}80%{transform:scale(1)}90%{transform:scale(1.18)}}.ui-city-dock__icon{font-size:16px;line-height:1}.ui-city-dock__btn kbd,.ui-city-x__btn kbd{border:1px solid var(--ui-line-strong);color:var(--ui-muted);font:600 10px/15px var(--font-ui);background:#0003;border-radius:4px;padding:0 4px}.ui-city-wheel{z-index:3;position:fixed;inset:0}.ui-city-wheel[hidden]{display:none}.ui-city-wheel__ring,.ui-city-wheel__center,.ui-city-wheel__arrow{left:var(--cx);top:var(--cy);position:absolute}.ui-city-wheel__ring{width:0;height:0}.ui-city-wheel__center{pointer-events:none;text-align:center;background:radial-gradient(circle,#141821f2 58%,#1418218c 72%,#0000 73%);border-radius:50%;flex-direction:column;justify-content:center;align-items:center;gap:1px;width:128px;height:128px;display:flex;transform:translate(-50%,-50%)}.ui-city-wheel__label{color:var(--ui-muted);text-transform:uppercase;letter-spacing:.06em;font-size:10.5px}.ui-city-wheel__to{text-overflow:ellipsis;white-space:nowrap;color:#ffe2b8;max-width:100px;font:700 13px/1.25 var(--font-ui);overflow:hidden}.ui-city-wheel__hint{max-width:104px;color:var(--ui-text);font:600 11px/1.25 var(--font-ui)}.ui-city-wheel__item{background:var(--ui-bg-solid);border:2px solid var(--ui-line-strong);width:46px;height:46px;transform:translate(var(--x), var(--y));transition:transform .14s var(--ease), border-color .14s, background .14s;border-radius:50%;place-items:center;margin:-23px 0 0 -23px;display:grid;position:absolute;top:0;left:0;box-shadow:0 6px 16px #05070c80}.ui-city-wheel.is-in .ui-city-wheel__item{animation:ui-city-wheel-in .26s var(--ease) both;animation-delay:calc(var(--i) * 18ms)}@keyframes ui-city-wheel-in{0%{opacity:0;transform:translate(0)scale(.4)}}.ui-city-wheel__item.is-focus,.ui-city-wheel__item:hover{transform:translate(var(--x), var(--y)) scale(1.16);background:#2a2232;border-color:#ffd27a}.ui-city-wheel__item.is-picked{transform:translate(var(--x), var(--y)) scale(1.35)}.ui-city-wheel__emoji{font-size:22px;line-height:1}.ui-city-wheel__key{border:1px solid var(--ui-line-strong);min-width:15px;height:15px;color:var(--ui-muted);font:700 9.5px/13px var(--font-ui);text-align:center;background:#1b2030;border-radius:5px;padding:0 3px;position:absolute;bottom:-3px;right:-3px}.ui-city-wheel__arrow{width:0;height:0;transform:rotate(var(--a,0deg));pointer-events:none}.ui-city-wheel__arrow:before{content:"";filter:drop-shadow(0 0 1px #1b2030)drop-shadow(0 0 1px #1b2030)drop-shadow(0 3px 4px #05070c99);border-top:11px solid #0000;border-bottom:11px solid #0000;border-left:18px solid #ffd27a;animation:.9s ease-in-out infinite ui-city-arrow;position:absolute;top:-11px;left:134px}.ui-city-wheel__arrow[hidden]{display:none}@keyframes ui-city-arrow{50%{transform:translate(5px)}}.ui-city-tp{right:calc(12px + env(safe-area-inset-right));bottom:calc(146px + env(safe-area-inset-bottom));flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:5px;width:186px;display:flex;position:fixed}.ui-city-tp__form{background:var(--ui-bg);border:1px solid var(--ui-line-strong);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border-radius:9px;flex:auto;align-items:center;gap:4px;min-width:0;padding:3px 3px 3px 7px;display:flex}.ui-city-tp__label{color:var(--ui-muted);white-space:nowrap;font-size:11px}.ui-city-tp__input{color:#cfeaff;width:0;min-width:0;font:700 12px/1.3 var(--font-mono);letter-spacing:.05em;text-transform:uppercase;background:#00000040;border:0;border-radius:6px;flex:auto;padding:3px 4px}.ui-city-tp__input::placeholder{color:var(--ui-faint);letter-spacing:.05em}.ui-city-tp__go,.ui-city-tp__dice{color:#d6efff;height:24px;font:700 11.5px/1 var(--font-ui);background:#7cc8ff24;border:1px solid #7cc8ff66;border-radius:7px;flex:none;padding:0 8px}.ui-city-tp__dice{background:var(--ui-bg);border-color:var(--ui-line-strong);width:100%;height:28px;color:var(--ui-text);justify-content:center;align-items:center;gap:5px;display:inline-flex}.ui-city-tp__dice:hover,.ui-city-tp__go:hover{background:#7cc8ff38}.ui-city-tp__dice:disabled,.ui-city-tp__go:disabled{opacity:.55}.ui-city-tp__error{background:var(--ui-bg-solid);color:#ffc9c9;border:1px solid #ff6b6b66;border-radius:7px;width:100%;margin:0;padding:5px 8px;font-size:11px}.ui-city-tp__error[hidden]{display:none}.ui-city-fade{z-index:4;background:radial-gradient(circle,#141028eb 0%,#060810 70%);position:fixed;inset:0;pointer-events:none!important}.ui-city-fade[hidden]{display:none}.ui-city-testfw{left:50%;top:calc(var(--top-h,64px) + 12px);color:#f1e6ff;font:700 12.5px/1 var(--font-ui);background:#3a2350;border:1px solid #b28dff;border-radius:10px;padding:7px 12px;position:fixed;transform:translate(-50%);box-shadow:0 8px 20px #05070c73}.ui-city-x{border-top:1px solid var(--ui-line);flex-direction:column;gap:6px;padding-top:8px;display:flex}.ui-city-x__row{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.ui-city-x__btn{background:var(--ui-bg-soft);border:1px solid var(--ui-line-strong);min-height:28px;color:var(--ui-text);font:700 11.5px/1 var(--font-ui);border-radius:8px;align-items:center;gap:5px;padding:0 9px;display:inline-flex}.ui-city-x__btn[hidden]{display:none}.ui-city-x__btn:hover:not(:disabled){background:var(--ui-bg-hover)}.ui-city-x__btn:disabled{opacity:.45;cursor:not-allowed}.ui-city-x__btn.is-primary{background:#ffd27a1f;border-color:#ffd27a80}.ui-city-x__btn.is-liked{border-color:#ff6e8c80}.ui-city-x__btn.is-quiet{color:var(--ui-muted);font-weight:600}.ui-city-x__btn.is-danger{color:#ffc9c9;background:#ff6b6b24;border-color:#ff6b6b99}.ui-city-x__code{color:#cfeaff;font:700 11px/1.3 var(--font-mono);letter-spacing:.05em;border:1px solid #7cc8ff4d;border-radius:6px;margin-left:auto;padding:2px 6px}.ui-city-x__code[hidden],.ui-city-x__hint[hidden],.ui-city-x__seal[hidden],.ui-city-x__reasons[hidden],.ui-city-x__done[hidden]{display:none}.ui-city-x__hint{color:var(--ui-muted);font-size:11px}.ui-city-x__seal{color:var(--ui-muted);background:#c8cedc14;border:1px dashed #c8cedc59;border-radius:6px;padding:4px 7px;font-size:11px}.ui-city-x__reasons{flex-wrap:wrap;gap:5px;display:flex}.ui-city-x__reasons>.ui-city-x__hint{width:100%}.ui-city-x__reason{background:var(--ui-bg-soft);border:1px solid var(--ui-line-strong);color:var(--ui-text);font:600 11px/1.2 var(--font-ui);border-radius:7px;padding:4px 8px}.ui-city-x__reason:hover{background:#ffb3471a;border-color:#ffb34799}.ui-city-x__done{color:var(--st-working);font-size:11.5px;font-weight:600}@media (prefers-reduced-motion:reduce){.ui-city-dock,.ui-city-dock__btn.is-like .ui-city-dock__icon,.ui-city-wheel.is-in .ui-city-wheel__item,.ui-city-wheel__arrow:before{animation:none}}@media (width<=600px){.ui-city-dock{left:calc(8px + env(safe-area-inset-left));bottom:calc(12px + env(safe-area-inset-bottom));animation:none;transform:none}.ui-city-dock__btn{justify-content:center;min-width:44px;min-height:44px;padding:0 8px}.ui-city-dock__text{display:none}.ui-city-dock__icon{font-size:20px}.ui-city-dock__btn kbd,.ui-city-x__btn kbd,.ui-city-wheel__key{display:none}.ui-city-tp{bottom:calc(112px + env(safe-area-inset-bottom));width:142px}.ui-city-tp__label,.ui-city-tp__dice-text{display:none}.ui-root.is-city .ui-toasts{bottom:calc(176px + env(safe-area-inset-bottom))}}
@@ -0,0 +1 @@
1
+ import{a as e,s as t}from"./main-DTHUta25.js";import{c as n,l as r}from"./simulator-B45JPgSp.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-BgjMjmrp.js";import{l as M,r as N,s as P}from"./dom-slmnBOjx.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,K as se,L as z,M as ce,N as le,O as ue,P as B,R as V,S as de,T as fe,U as pe,V as me,W as H,a as he,b as ge,c as _e,d as ve,i as ye,j as be,k as xe,l as Se,n as Ce,o as we,q as Te,r as Ee,s as De,u as Oe,v as ke,w as Ae,x as je,y as Me,z as Ne}from"./app-QYGBa260.js";function Pe(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 Fe(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 Ie(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 Le(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 Re(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 ze(e,n=null){let r=e.state===`online`;return{owner:e.owner.name,flag:Pe(e.owner.country),country:Fe(e.owner.country),online:r,state:t(r?`Luzes acesas`:`Luzes apagadas`),floors:Le(e.floors),agents:e.agents?{working:e.agents.working,waiting:e.agents.waiting,idle:e.agents.idle}:null,likes:Re(e.likes),since:Ie(e.sinceMonth),closed:e.closed===!0,mine:!!n&&e.id===n}}function Be(e,t){return{name:e.name,flag:Pe(e.country),country:Fe(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:Re(e.likesReceived),building:t?{id:t.id,floors:Le(t.floors),online:t.state===`online`}:null,hasBuilding:!!e.buildingId}}var Ve=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=ze(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=Be(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=Te(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)`}},He=6,Ue={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 We(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``)||t.getAttribute?.(`role`)===`radio`)}function Ge(e,t){let n=0,r=0;for(let t of e){let e=Ue[t];e&&(n+=e[0],r+=e[1])}return{dx:Math.sign(n),dy:Math.sign(r),run:t}}function Ke(e){if(Ue[e.key])return e.key;let t=e.key.length===1?e.key.toLowerCase():e.key;return Ue[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 Ge(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=Ke(e);t&&this.keys.delete(t);return}if(!this.h.active()||e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||We(e.target)||H(e.target))return;let n=Ke(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)>He&&(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)}},Je={x:-2,y:-2,w:h.x,h:h.y};A.w-2;var U=e=>`${e.x},${e.y}`;function Ye(e){return n(`quarteirao:${e.x},${e.y}`)}function Xe(e){return n(`lote:${e.x},${e.y}`)}function Ze(e){return e.y-p.h*Math.floor(e.y/p.h)===0}function Qe(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 $e(e){let t=E(e);return{x:(t.x+Je.x)*16,y:(t.y+Je.y)*16,w:Je.w*16,h:Je.h*16}}function et(e,t=64){let n=h.x*16,r=h.y*16,i=Je.x*16,a=Je.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 tt(){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 nt=()=>!0;function rt(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 xe(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,nt);return{grid:a,ox:t,oy:n}}function it(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 at(e,t,n=16){let r=Math.floor(e),i=Math.floor(t);if(v(r+.5,i+.5,nt))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,nt))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 ot(e,t){return v(e,t,nt)}function st(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 Qe({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 ct=3;function lt(e){let t=E(e),n=Ye(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)<ct);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 ut=[`park`,`pond`,`orchard`,`cafe`];function dt(e){return ut[Xe(e)%ut.length]}function ft(e,t){let n=ee(e),a=Xe(e),o=r(a^1540483477),s=[],c=e=>(n.x+e)*16,l=e=>(n.y+e)*16,u=()=>Math.floor(o()*1e9),d=Ze(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=dt(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 pt(){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 mt(e){let t=lt(e);return te(e)&&t.push(...pt()),t}var ht=p.w*p.h;function gt(e){return e>0?Math.min(1,.35+.65*Math.min(e,ht)/ht):0}function _t(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:gt(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 vt(e,t,n,r){return{x:e.cx+(n-t.w/2)/e.k,y:e.cy+(r-t.h/2)/e.k}}var yt=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(vt(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=_t(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 bt(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 xt=5e3,St=C;function Ct(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 wt(e){return e===9?`0`:String(e+1)}function Tt(e){if(!/^[0-9]$/.test(e))return-1;let t=e===`0`?9:Number(e)-1;return t<St.length?t:-1}function Et(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 Dt=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/xt,age:r}}get size(){return this.map.size}ids(){return[...this.map.keys()]}clear(){this.map.clear()}},Ot=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 kt(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 At=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=Ct(St.length,96);St.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":`${De(t)} (${wt(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:we(t),attrs:{"aria-hidden":`true`}}),N(`span`,{class:`ui-city-wheel__key`,text:wt(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?St.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=Tt(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)%St.length,!0),!0;case`ArrowLeft`:case`ArrowUp`:return this.focus((this.focused+St.length-1)%St.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=St[e];M(this.hint,`${Ce[n].icon} ${De(n)}`),t&&this.buttons[e]?.focus({preventScroll:!0})}choose(e){let t=St[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))}},jt=4e3;function Mt(e){return new Date(e).toISOString().slice(0,10)}function Nt(e){return`habblaud:world-stamp:${e}`}function Pt(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 Ft(e){return e===`stamped`?`ok`:e===`already_done`?`already`:`failed`}function It(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:Se(e.stampId),label:Oe(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 Lt(e,n){let r=()=>n.now?.()??Date.now(),i=Me(),a=0,o=!1,s=``,l=null,u=new Ot(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:Oe(e),attrs:{"data-stamp":e},on:{click:()=>C(e)}},N(`span`,{class:`ui-visit-social__choice-icon`,text:Ee[e].icon,attrs:{"aria-hidden":`true`}}),N(`span`,{text:Oe(e)}))))),m=N(`div`,{class:`ui-visit-social`},N(`div`,{class:`ui-visit-social__row`},d,f),p);e.append(m);let h=()=>s?Pt(g(s),Mt(r())):null;function g(e){try{return i?.getItem(Nt(e))??null}catch{return null}}function _(e,t){try{t?i?.setItem(Nt(e),JSON.stringify({day:Mt(r()),stampId:t})):i?.removeItem?.(Nt(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?Se(i):`📮`,attrs:{"aria-hidden":`true`}}),` ${i?t(`Carimbo de hoje: {0}`,[Oe(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(`${Se(e)} ${t(`Carimbo deixado na portaria: {0}`,[Oe(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>jt)return!1;let c=l;if(l=null,c.kind===`stamp`){let e=Ft(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 Rt(e){return e.count>1?`${e.label} ×${e.count}`:e.label}function zt(e){return e.state===`away`?`away`:e.discreet===!0?`discreet`:`live`}function Bt(e){return e===1?t(`1 agente`):t(`{0} agentes`,[e])}function Vt(e){return e===1?t(`1 visitante agora`):t(`{0} visitantes agora`,[e])}function Ht(e){return Ae(e.building)?0:e.floors.reduce((e,t)=>e+(Array.isArray(t.agents)?t.agents.length:0),0)}function Ut(e,n){let r=e.building,i=zt(r),a=[Le(e.floors.length)];return i===`live`?a.push(Bt(Ht(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 Wt=[`working`,`waiting`,`idle`,`shell`];function Gt(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 Kt(e){let n=Wt.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:je[r].name,status:n,statusText:Gt(n)}}function qt(e){let n=Ae(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(Kt)})),i=zt(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 Jt(e,t){if(Ae(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{...Kt(e),room:R(n.label)};return null}var Yt=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=fe(this.detail,t.now(),{version:t.version}),t.push(this.snapshot)}get light(){return zt(this.detail.building)}replace(e){let t=structuredClone(e.detail),n=de(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=de(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?.()}},Xt=8e3,Zt=`(max-width: 760px)`;function Qt(e){let r=document.createElement(`canvas`);r.id=`visit`,e.after.after(r);let i=new g({search:``}),a=ke(r,i,{visit:!0}),o=typeof matchMedia==`function`?matchMedia(Zt):null,s=()=>!!o?.matches,c=!s(),l=!1,u=null,d=0,f=``;a.visit.setLight(zt(e.inside.detail.building));let p=new Yt(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:()=>z(!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:()=>ye()}}),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:()=>ve()}},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=Lt(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=It(i,n(p.id));F.replaceChildren(...o.map(e=>N(`span`,{class:`ui-visit-board__pin${e.mine?` is-mine`:``}`,text:e.icon,title:Rt(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(Rt).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=Ut(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?`👀 ${Vt(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=qt(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),ce()}function oe(){let e=a.getSelection(),t=e?.type===`agent`?Jt(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 z(e){c=e,ae()}function ce(){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 le=a.onSelect(()=>oe()),ue=new Set,B=!1,V=()=>a.visit.setIntent(p.leaving?{dx:0,dy:0,run:!1}:Ge(ue,B)),de=e=>{let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``))},fe=(e,t)=>{e.key===`Shift`?B=t:typeof e.getModifierState==`function`&&(B=e.getModifierState(`Shift`));let n=Ke(e);if(!t){n&&ue.delete(n),V();return}if(!(e.defaultPrevented||e.ctrlKey||e.metaKey||e.altKey||de(e.target)||H(e.target))){if(n){e.preventDefault(),ue.add(n),V();return}e.key===`e`||e.key===`E`||e.key===`Enter`&&!e.target?.closest?.(`button, a`)?(e.preventDefault(),ve()):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())}},pe=e=>fe(e,!0),me=e=>fe(e,!1),he=()=>{ue.clear(),B=!1,V()};addEventListener(`keydown`,pe),addEventListener(`keyup`,me),addEventListener(`blur`,he);let _e=()=>ce();addEventListener(`resize`,_e),o?.addEventListener(`change`,_e);function ve(){p.leaving||a.visit.atExit()&&a.visit.exit(()=>ye())&&(ue.clear(),V())}function ye(){p.leave()&&(ue.clear(),V(),u=setTimeout(()=>{u=null,l||e.stuck()},Xt))}let be=()=>{d=requestAnimationFrame(be);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(be),ae(),requestAnimationFrame(()=>ce()),{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:ye,escape(){return a.getSelection()?(a.select(null),!0):s()&&c?(z(!1),!0):(ye(),!0)},openPanel(e=!0){z(e)},selectAgent:se,destroy(){l||(l=!0,u&&clearTimeout(u),cancelAnimationFrame(d),le(),R.destroy(),removeEventListener(`keydown`,pe),removeEventListener(`keyup`,me),removeEventListener(`blur`,he),removeEventListener(`resize`,_e),o?.removeEventListener(`change`,_e),a.destroy(),r.remove(),L.remove(),e.uiRoot.classList.remove(`is-visit`),ge(Me()))}}}var $t=3.2,en=60,tn=1e3,nn=4,rn=.5,an=.25,on=10,sn={up:`n`,down:`s`,left:`w`,right:`e`},cn={n:`up`,s:`down`,w:`left`,e:`right`};function ln(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 un(e,t){let n=e[e.length-1];n&&t.t<n.t&&(t={...t,t:n.t}),e.push(t),e.length>on&&e.splice(0,e.length-on)}function dn(e){let t=0,n=0;for(let r=e.length-1;r>0&&n<nn;r--){let i=e[r].t-e[r-1].t;i<=0||i>tn||(t=Math.max(t,i),n++)}return Math.min(700,Math.max(150,t+en))}function fn(e,t,n){return t>e?Math.min(t,e+n*rn):Math.max(t,e-n*an)}function pn(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 mn(e,t,n,r,i=ot){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 hn=class{can;x;y;dir=`down`;moving=!1;running=!1;path=[];pathI=0;pathRun=!1;animT=0;constructor(e,t,n=ot){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:$t)*e,o=mn(this.x,this.y,i*r,a*r,this.can);this.dir=ln(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:$t)*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=ln(r,i,this.dir))):(this.x+=r/a*t,this.y+=i/a*t,this.dir=ln(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 gn(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 _n(e){return Math.floor(e*100)/100}var vn=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:_n(t.x),y:_n(t.y),dir:sn[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:_n(e.x),y:_n(e.y),dir:sn[e.dir],moving:!1};this.lastAt=-1/0,this.last=t,this.send({t:`move`,...t})}reset(){this.last=null,this.lastAt=-1/0}},yn={a:`010101111101101`,b:`110101110101110`,c:`011100100100011`,d:`110101101101110`,e:`111100110100111`,f:`111100110100100`,g:`011100101101011`,h:`101101111101101`,i:`111010010010111`,j:`001001001101010`,k:`101101110101101`,l:`100100100100111`,m:`101111111101101`,n:`110101101101101`,o:`010101101101010`,p:`110101110100100`,q:`010101101110011`,r:`110101110101101`,s:`011100010001110`,t:`111010010010010`,u:`101101101101111`,v:`101101101101010`,w:`101101111111101`,x:`101101010101101`,y:`101101010010010`,z:`111001010100111`,0:`111101101101111`,1:`010110010010111`,2:`110001010100111`,3:`110001010001110`,4:`101101111001001`,5:`111100110001110`,6:`011100111101111`,7:`111001010010010`,8:`111101111101111`,9:`111101111001110`,_:`000000000000111`,"-":`000000111000000`,"#":`101111101111101`,".":`000000000000010`,"(":`010100100100010`,")":`010001001001010`,"/":`001001010100100`," ":`000000000000000`,":":`000010000010000`,",":`000000000010100`,"×":`000101010101000`,"—":`000000111000000`,">":`100010001010100`,"<":`001010100010001`,"+":`000010111010000`},bn={acute:{dy:-3,rows:[`001`,`010`]},grave:{dy:-3,rows:[`100`,`010`]},circ:{dy:-3,rows:[`010`,`101`]},tilde:{dy:-3,rows:[`011`,`110`]},cedilla:{dy:5,rows:[`010`,`110`]}},xn={á:[`a`,`acute`],à:[`a`,`grave`],â:[`a`,`circ`],ã:[`a`,`tilde`],é:[`e`,`acute`],ê:[`e`,`circ`],í:[`i`,`acute`],ó:[`o`,`acute`],ô:[`o`,`circ`],õ:[`o`,`tilde`],ú:[`u`,`acute`],ç:[`c`,`cedilla`]};function Sn(e){return Math.max(0,[...e].length*4-1)}function Cn(e,t,n,r,i){e.fillStyle=i;let a=n;for(let n of t.toLowerCase()){let t=xn[n],i=yn[t?t[0]:n]??yn[` `];for(let t=0;t<15;t++)i[t]===`1`&&e.fillRect(a+t%3,r+Math.floor(t/3),1,1);if(t){let n=bn[t[1]];n.rows.forEach((t,i)=>{for(let o=0;o<3;o++)t[o]===`1`&&e.fillRect(a+o,r+n.dy+i,1,1)})}a+=4}return a-n}var W={w:192,shadow:6,roof:26,floor:11,ground:30,maxFloors:12,cols:11,winX:11,winPitch:16,winW:10,winH:7},wn=[{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 Tn(e){let t=Math.max(0,Math.min(W.maxFloors,Math.floor(e)));return W.roof+t*W.floor+W.ground}function En(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 Dn(e,t,n){let r=Number.isFinite(e.floors)?Math.max(0,Math.floor(e.floors)):0,i=Math.min(W.maxFloors,r),a=Math.max(0,r-W.maxFloors),o=(n>>>0)%40,s=i*W.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=En(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%wn.length,drawn:i,plus:a,state:c,theme:g,discreet:l,litLevel:u,lit:m,waiting:h,height:Tn(i)}}function On(e){return`${e.side}|${e.variant}|${e.drawn}|${Math.min(99,e.plus)}|${e.state}|${e.theme}|${e.litLevel}`}function kn(e,t){let n=t%W.cols,r=Math.floor(t/W.cols),i=e.drawn-1-r;return{x:W.winX+n*W.winPitch,y:W.roof+i*W.floor+2,w:W.winW,h:W.winH}}function An(e){return e.side===`front`?{x:34,y:e.height-W.ground+2,w:W.w-68,h:8}:{x:50,y:11,w:W.w-100,h:8}}var jn=new Map,Mn=600;function Nn(e){let t=On(e),n=jn.get(t);return n||(jn.size>=Mn&&jn.clear(),n=zn(e),jn.set(t,n),n)}function Pn(e){return jn.has(On(e))}function Fn(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 G=`#2e3648`,K=[`#c98f3c`,`#f2c66b`,`#ffe3a0`,`#fff4d2`],q=[`#1f3550`,`#2b4868`,`#3c5f84`,`#7fa6cc`],In=new Map;function Ln(e){let t=In.get(e);if(!t){let{buf:n}=ce(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),In.set(e,t)}return t}function Rn(e,t,n,r){let i=Ln(t);e.drawImage(i,Math.round(n-20),Math.round(r-60))}function J(e,t,n,r,i,a){e.fillStyle=a,e.fillRect(t,n,r,i)}function zn(e){let t=W.w+W.shadow,n=e.height,[i,a]=Fn(t,n),[o,s]=Fn(t,n),c=wn[e.style],l=r((e.variant+1)*2654435761>>>0),u=e.state===`online`,d=W.roof,f=n-W.ground,p=W.w;a.fillStyle=`rgba(28,36,52,0.22)`,a.fillRect(p,6,W.shadow,n-6),a.fillStyle=`rgba(28,36,52,0.12)`,a.fillRect(p,10,2,n-10),Bn(a,c,0,d,p,n-d,l);for(let t=0;t<=e.drawn;t++)J(a,0,d+t*W.floor-1,p,1,c.pattern===`glass`?c.trim[0]:Y(c.wall[0],-.08));J(a,0,d,3,n-d,c.trim[0]),J(a,p-3,d,3,n-d,c.trim[0]),J(a,0,d,1,n-d,c.trim[1]);let m=new Set(e.lit),h=e.drawn*W.cols;for(let t=0;t<h;t++){let n=kn(e,t);Vn(a,c,n.x,n.y,m.has(t),(e.variant*31+t)%7),m.has(t)&&Hn(s,n.x,n.y)}if(e.side===`back`&&e.drawn>0){Un(a,e.variant%2==0?W.winX+W.winPitch-3:W.winX+(W.cols-2)*W.winPitch-3,d,e.drawn);for(let t=0;t<e.drawn;t++)if(l()<.45){let n=2+Math.floor(l()*(W.cols-4)),r=kn(e,(e.drawn-1-t)*W.cols+n);Wn(a,r.x+1,r.y+r.h+1)}}if(e.side===`front`?Gn(a,s,c,e,f,u,l):Kn(a,s,c,e,f,u,l),Jn(a,s,c,e,l),Xn(a,s,e,f),e.side===`back`&&Yn(a,s,c,e),u||qn(a,p/2,e.side===`front`?f+16:1),e.plus>0){let t=`+${Math.min(99,e.plus)}`,n=Sn(t),r=e.side===`front`?p-n-18:16,i=e.side===`front`?6:13;J(a,r-3,i-3,n+6,11,G),J(a,r-2,i-2,n+4,9,u?c.accent[1]:`#5a6170`),J(a,r-2,i-2,n+4,1,u?er(c.accent[1],.25):`#6d7483`),Cn(a,t,r,i,`#ffffff`),J(a,r+n/2-1,i+8,2,3,G),u&&(s.fillStyle=`rgba(255,255,255,0.85)`,Cn(s,t,r,i,`#fff6dc`))}return{canvas:i,glow:o,w:t,h:n}}function Bn(e,t,n,r,i,a,o){let[s,c,l,u]=t.wall;switch(J(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;J(e,n,t+2,i,1,s);for(let r=n+a;r<n+i;r+=6){J(e,r,t,1,2,s);let n=o();n<.18?J(e,r+1,t,5,2,l):n<.26&&J(e,r+1,t,5,2,Y(c,-.06))}}break;case`panel`:for(let t=n;t<n+i;t+=24)J(e,t,r,1,a,s);for(let t=r+5;t<r+a;t+=11)J(e,n,t,i,1,Y(c,-.05));J(e,n,r,i,1,l);break;case`stucco`:for(let t=0;t<i*a/40;t++)J(e,n+Math.floor(o()*i),r+Math.floor(o()*a),1,1,o()<.5?l:Y(c,-.04));break;case`stone`:for(let t=r;t<r+a;t+=5){J(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)J(e,r,t,1,4,s),o()<.3&&J(e,r+1,t,13,1,u)}break;case`glass`:J(e,n,r,i,a,t.wall[1]);for(let o=r;o<r+a;o++)(o-r)%11<3&&J(e,n,o,i,1,t.wall[2]);for(let o=n+3;o<n+i;o+=16)J(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 Vn(e,t,n,r,i,a){let o=W.winW,s=W.winH;t.pattern!==`glass`&&(J(e,n-1,r-1,o+2,s+2,t.frame),J(e,n-1,r+s+1,o+2,1,t.trim[1]),J(e,n-1,r+s+2,o+2,1,Y(t.trim[0],-.15))),i?(J(e,n,r,o,s,K[2]),J(e,n,r,o,2,K[3]),J(e,n,r+s-2,o,2,K[1]),J(e,n+2+a%4,r+s-3,3,2,`#5fb8f0`),J(e,n+2+a%4,r+s-3,1,1,`#c8ecff`),(a===2||a===5)&&J(e,n+6-a%3,r+s-4,2,3,`#7a5a3a`)):(J(e,n,r,o,s,q[1]),J(e,n,r,o,2,q[0]),J(e,n,r+s-1,o,1,q[2]),J(e,n+1+a%3,r+2,1,3,q[3]),J(e,n+2+a%3,r+2,1,1,`#b8d2ea`),a===4&&J(e,n+1,r+1,o-2,2,`#c9cfd9`)),J(e,n+(o>>1),r,1,s,t.pattern===`glass`?t.frame:Y(t.frame,.1))}function Hn(e,t,n){let r=W.winW,i=W.winH;e.fillStyle=K[2],e.fillRect(t,n,r,i),e.fillStyle=K[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 Un(e,t,n,r){let i=`#2a2f3a`,a=`#5b6475`;for(let o=0;o<r;o++){let s=n+o*W.floor+W.floor-2;J(e,t-2,s,18,1,a),J(e,t-2,s+1,18,1,i),J(e,t-2,s-4,18,1,i);for(let n=0;n<18;n+=3)J(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<W.floor;r++)J(e,t+7+n*(r-5),s+2+r,2,1,r%2?i:a)}}}function Wn(e,t,n){J(e,t,n,7,4,G),J(e,t+1,n,5,3,`#c9d0d8`),J(e,t+1,n,5,1,`#e8edf2`),J(e,t+2,n+1,3,1,`#8b95a3`)}function Gn(e,t,n,r,i,a,o){let s=W.w,c=r.height-2;J(e,0,i,s,W.ground,n.trim[0]),J(e,0,i,s,1,n.trim[1]),J(e,0,i+1,s,1,Y(n.trim[0],-.2));let l=An(r);J(e,l.x-2,l.y-1,l.w+4,l.h+2,G),J(e,l.x-1,l.y,l.w+2,l.h,a?n.accent[0]:`#4a505c`),J(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(J(e,r-1,f-1,i-r+2,p+2,G),a){J(e,r,f,i-r,p,K[2]),J(e,r,f,i-r,2,K[3]),J(e,r,f+p-3,i-r,3,K[1]);for(let t=r+4;t<i-4;t+=9+Math.floor(o()*5))J(e,t,f+p-6,5,3,`#8a6243`),o()<.5?J(e,t+1,f+p-9,3,3,`#4b8a45`):J(e,t+1,f+p-8,3,2,`#5fb8f0`);t.fillStyle=K[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{J(e,r,f,i-r,p,q[1]),J(e,r,f,i-r,2,q[0]);for(let t=r+3;t<i;t+=13)J(e,t,f+2,2,p-3,q[2])}for(let t=r+16;t<i-2;t+=16)J(e,t,f,1,p,n.frame===`#e8eef4`?`#cdd8e2`:G);J(e,r-1,f-4,i-r+2,3,n.accent[0]);for(let t=r;t<i;t+=4)J(e,t,f-4,2,3,n.accent[1]);J(e,r-1,f-1,i-r+2,1,Y(n.accent[0],-.25))}let m=i+9;J(e,u-2,m-2,36,c-m+2,G),J(e,u-1,m-1,34,c-m+1,n.trim[1]);for(let n of[u,s/2+1])J(e,n,m,15,c-m,G),J(e,n+1,m+1,13,c-m-1,a?`#f6dd9a`:q[1]),J(e,n+1,m+1,13,2,a?K[3]:q[0]),J(e,n+2,m+3,1,c-m-6,a?`#fff6dc`:q[3]),J(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));J(e,0,c,s,2,Y(n.trim[0],-.25)),J(e,u-4,c-1,40,3,`#c9cdd3`),J(e,u-4,c-1,40,1,`#e4e7eb`);for(let n of[u-6,d+4])J(e,n,m+2,3,4,G),J(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 Kn(e,t,n,r,i,a,o){let s=W.w,c=r.height-2;J(e,0,i,s,2,Y(n.wall[0],-.1));for(let r=12;r<s-12;r+=22){if(Math.abs(r+5-s/2)<18)continue;J(e,r-1,i+5,12,6,n.frame);let c=a&&o()<.5;J(e,r,i+6,10,4,c?K[2]:q[1]),J(e,r,i+6,10,1,c?K[3]:q[0]),c&&(t.fillStyle=K[2],t.fillRect(r,i+6,10,4))}let l=s/2-7;J(e,l-1,i+9,16,c-i-9,G),J(e,l,i+10,14,c-i-10,`#7d8794`),J(e,l,i+10,14,1,`#a9b2bd`),J(e,l+11,i+18,1,3,`#d9dee4`),J(e,l+3,i+12,8,2,`#5f6875`),J(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`]])J(e,t-1,c-9,9,9,G),J(e,t,c-8,7,8,n),J(e,t,c-8,7,2,er(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(),J(e,n+3,c-6,7,1,t?`#cf4a3c`:`#2fa597`)}J(e,0,c,s,2,Y(n.trim[0],-.25))}function qn(e,n,r){let i=t(`Fechado`),a=Math.min(40,Sn(i)),o=a+6,s=Math.round(n-o/2);J(e,s+2,r-4,1,4,`#3a2a20`),J(e,s+o-3,r-4,1,4,`#3a2a20`),J(e,s-1,r-1,o+2,10,`#3a2a20`),J(e,s,r,o,8,`#c98f5a`),J(e,s,r,o,1,`#e3ad78`),e.save(),e.beginPath(),e.rect(s+3,r,a,8),e.clip(),Cn(e,i,s+3,r+2,`#3a2a20`),e.restore()}function Jn(e,t,n,r,i){let a=W.w,o=W.roof,s=r.state===`online`;J(e,0,0,a,o-5,G),J(e,1,1,a-2,o-6,n.roof[1]),J(e,3,3,a-6,o-10,n.roof[0]);for(let t=0;t<90;t++)J(e,3+Math.floor(i()*(a-6)),3+Math.floor(i()*(o-10)),1,1,i()<.5?n.roof[1]:Y(n.roof[0],-.12));J(e,0,o-5,a,4,n.trim[0]),J(e,0,o-5,a,1,n.trim[1]),J(e,0,o-2,a,1,Y(n.trim[0],-.3)),J(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?(J(e,r,4,12,12,G),J(e,r+1,5,10,10,`#9aa6b4`),J(e,r+1,5,10,3,`#c3ccd6`),J(e,r+3,6,6,1,`#e3e8ee`)):n<.7?(J(e,r,6,14,9,G),J(e,r+1,7,12,7,`#d4dae1`),J(e,r+1,7,12,2,`#eef1f4`),J(e,r+4,9,6,4,`#8b95a3`),J(e,r+6,10,2,2,`#5f6875`)):(J(e,r,6,16,9,G),J(e,r+1,7,14,7,s?`#9cc6e4`:`#3c5f84`),J(e,r+1,7,14,2,`#c8e2f4`),J(e,r+8,7,1,7,G))}if(i()<.5){let n=r.side===`back`?176:100+Math.floor(i()*40);J(e,n,1,1,9,`#4a5468`),J(e,n-2,3,5,1,`#4a5468`),J(e,n,1,1,1,s?`#ff5a4a`:`#8b95a3`),s&&(t.fillStyle=`#ff5a4a`,t.fillRect(n,1,1,1))}}function Yn(e,t,n,r){let i=W.w,a=r.state===`online`;{let o=An(r);J(e,o.x-2,o.y-1,o.w+4,o.h+2,G),J(e,o.x-1,o.y,o.w+2,o.h,a?n.accent[0]:`#4a505c`),J(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;J(e,s-1,0,46,10,G);for(let t=0;t<44;t++){let r=Math.floor(t/4)%2==0;J(e,s+t,0,1,9,r?n.accent[1]:`#f6efe2`)}J(e,s,0,44,2,`rgba(255,255,255,0.35)`),J(e,s,7,44,2,`rgba(28,36,52,0.25)`);for(let n of[s+3,s+39])J(e,n,1,2,2,a?`#fff1b8`:`#8b95a3`),a&&(t.fillStyle=`rgba(255,230,160,0.95)`,t.fillRect(n,1,2,2))}}function Xn(e,t,n,r){if(n.theme===`none`){if(n.side===`front`){let t=W.w,r=n.height-2;for(let n of[t/2-26,t/2+20])J(e,n,r-6,6,6,G),J(e,n+1,r-5,4,5,`#c97a4a`),J(e,n-1,r-11,8,6,`#3f8550`),J(e,n,r-12,6,2,`#5aa45d`)}return}let i=W.w,a=W.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;J(e,n,i-1,1,1,`#2e3648`),J(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;J(e,t,n,3,2,`#47344f`),J(e,t-3,n-1,3,2,`#47344f`),J(e,t+3,n-1,3,2,`#47344f`),J(e,t+1,n,1,1,`#f5b95f`)}}let l=n.height-2;n.side===`front`?s?(Zn(e,t,i/2-19,r+6,38,o),Rn(e,`tree`,i-30,l+2),Rn(e,`gift`,i-52,l+2)):(Rn(e,`pumpkin`,i/2-28,l+2),Rn(e,`pumpkin`,i/2+28,l+2),n.drawn>0&&Rn(e,`ghost`,30,r+6)):s?(Zn(e,t,i/2-10,r+6,20,o),Rn(e,`tree`,i/2+30,l+2)):(Rn(e,`pumpkin`,i/2-22,l+2),Rn(e,`pumpkin`,i/2+22,l+2))}function Zn(e,t,n,r,i,a){for(let o=0;o<i;o++){let s=Math.round(Math.sin(o/i*Math.PI)*3);J(e,n+o,r+s,1,3,o%3==0?`#245644`:`#347653`),o%6==3&&(J(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])J(e,t,r-1,4,3,`#c93945`),J(e,t+1,r+2,1,3,`#a82d42`),J(e,t+2,r+2,1,2,`#a82d42`)}function Qn(e){let t=parseInt(e.slice(1,7),16);return[t>>16&255,t>>8&255,t&255]}function $n(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 Y(e,t){let[n,r,i]=Qn(e);return t<0?$n(n*(1+t),r*(1+t),i*(1+t)):$n(n+(255-n)*t,r+(255-r)*t,i+(255-i)*t)}function er(e,t){return Y(e,Math.abs(t))}function tr(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 X=e=>e*16;function nr(e){try{e()}catch{}}function rr(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 ir(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 ar(e,t,n){let i=tt();for(let n of[...i.streets,i.intersection])nr(()=>e.drawFloor(t,`street`,X(n.x),X(n.y),X(n.w),X(n.h),{seed:13}));t.fillStyle=`rgba(20,22,28,0.18)`;let a=X(i.sidewalkOuter.w),o=X(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=X(e);i<X(r)-8;i+=24)t.fillRect(i,X(n)-1,12,2);else for(let r=X(n);r<X(a)-8;r+=24)t.fillRect(X(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=X(n.y)+4;e<X(n.y+n.h)-3;e+=6)t.fillRect(X(n.x)+3,e,X(n.w)-6,3);else for(let e=X(n.x)+4;e<X(n.x+n.w)-3;e+=6)t.fillRect(e,X(n.y)+3,3,X(n.h)-6)}t.fillStyle=`rgba(244,244,236,0.75)`,t.fillRect(a-2,o+2,2,X(2)-2),t.fillRect(a+X(3),o-2,X(2)-2,2);let s=r(n);for(let e=0;e<3;e++){let e=X(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+X(2)+2,l=X(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 or(e,t){let n=tt().sidewalkOuter;nr(()=>e.drawFloor(t,`sidewalk`,X(n.x),X(n.y),X(n.w),X(n.h),{seed:12})),ir(t,0,0,X(n.w),2,`n`),ir(t,0,X(n.h)-3,X(n.w),3,`s`),ir(t,0,0,2,X(n.h),`w`),ir(t,X(n.w)-3,0,3,X(n.h),`e`)}function sr(e,t){let n=tt(),r=n.block;nr(()=>e.drawFloor(t,`grass`,X(r.x),X(r.y),X(r.w),X(r.h),{seed:11})),rr(t,X(r.x),X(r.y),X(r.w),X(r.h)),t.fillStyle=`rgba(40,70,40,0.18)`;for(let e of n.lots)t.fillRect(X(e.x+e.w)-1,X(e.y),1,X(e.h)),t.fillRect(X(e.x),X(e.y+e.h)-1,X(e.w),1);let a=X(r.x),o=X(r.y),s=X(r.w),c=X(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=X(a.x+i.dx);nr(()=>e.drawFloor(t,`sidewalk`,s,n?o:o+c-2,X(i.w),2,{seed:12}))}}function cr(e){let t=tt(),[n,r]=tr(X(t.sidewalkOuter.w+t.streets[0].w),X(t.sidewalkOuter.h+t.streets[1].h));return ar(e,r,77),or(e,r),sr(e,r),n}function lr(e){let t=tt(),[n,r]=tr(X(t.sidewalkOuter.w+t.streets[0].w),X(t.sidewalkOuter.h+t.streets[1].h));ar(e,r,99),or(e,r);let i=t.block,a=X(i.x),o=X(i.y),s=X(i.w),c=X(i.h);nr(()=>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+X(1),o+X(1),s-X(2),3),r.fillRect(a+X(1),o+c-X(1)-3,s-X(2),3),r.fillRect(a+X(1),o+X(1),3,c-X(2)),r.fillRect(a+s-X(1)-3,o+X(1),3,c-X(2)),r.fillStyle=`rgba(255,248,232,0.5)`,r.fillRect(a+X(1),o+X(1),s-X(2),1);let l=a+X(y.x+y.w/2),u=o+X(y.y+y.h/2);r.fillStyle=`rgba(236,226,206,0.55)`,r.fillRect(l-X(1.5),o+X(1)+3,X(3),c-X(2)-6),r.fillRect(a+X(1)+3,u-X(1.5),s-X(2)-6,X(3)),r.fillStyle=`rgba(140,128,110,0.45)`;for(let e of[-1,1])r.fillRect(l+e*X(1.5)-+(e>0),o+X(1)+3,1,c-X(2)-6),r.fillRect(a+X(1)+3,u+e*X(1.5)-+(e>0),s-X(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+X(t),l=o+X(n);r.fillStyle=`#8d8a82`,r.fillRect(c-2,l-2,X(i)+4,X(s)+4),r.fillStyle=`#d8d4ca`,r.fillRect(c-2,l-2,X(i)+4,1),nr(()=>e.drawFloor(r,`grass`,c,l,X(i),X(s),{seed:31})),rr(r,c,l,X(i),X(s))}let f=y,p=a+X(f.x+f.w/2),m=o+X(f.y+f.h/2);r.save(),r.beginPath(),r.ellipse(p,m,X(7),X(5.2),0,0,Math.PI*2),r.clip(),nr(()=>e.drawFloor(r,`marble`,p-X(8),m-X(6),X(16),X(12),{seed:41})),r.restore(),r.strokeStyle=`#8f8676`,r.lineWidth=3,r.beginPath(),r.ellipse(p,m,X(7)-1,X(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,X(4.8),X(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,X(7)-2,X(5.2)-2,0,Math.PI,Math.PI*2),r.stroke();let h=a+X(21)+8,g=o+X(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 ur(e,t,n,r){let[a,o]=tr(X(A.w),X(A.h)),s=X(i.dx),c=(t,n,i,a)=>{o.fillStyle=`#9a968c`,o.fillRect(t-1,n-1,i+2,a+2),nr(()=>e.drawFloor(o,`sidewalk`,t,n,i,a,{seed:12+r%3}))},l=X(A.h/2);switch(t){case`park`:n?c(s,0,X(2),l+8):c(s,l-8,X(2),X(A.h)-l+8),c(X(2),l-8,X(10),X(1)),o.fillStyle=`#6a4b35`,o.beginPath(),o.ellipse(X(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,X(2),X(2)):c(s,X(A.h-2),X(2),X(2));let e=X(7),t=l+(n?4:-4);o.fillStyle=`#8d8a82`,o.beginPath(),o.ellipse(e,t,X(4.6),X(2.8),0,0,Math.PI*2),o.fill(),o.fillStyle=`#3f7fa8`,o.beginPath(),o.ellipse(e,t,X(4.6)-3,X(2.8)-3,0,0,Math.PI*2),o.fill(),o.fillStyle=`#5aa0c8`,o.beginPath(),o.ellipse(e-6,t-6,X(3),X(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(X(1),X((n?3.4:2.4)+e*4.4),X(12),6);n?c(s,0,X(2),X(1.4)):c(s,X(A.h-1.4),X(2),X(1.4));break;case`cafe`:o.fillStyle=`#8d8a82`,o.fillRect(X(2)-2,l-X(2)-2,X(10)+4,X(4)+4),nr(()=>e.drawFloor(o,`wood`,X(2),l-X(2),X(10),X(4),{seed:8})),n?c(s,0,X(2),l-X(2)):c(s,l+X(2),X(2),X(A.h)-l-X(2))}return a}function dr(){let e=X(6),t=X(5),[n,r]=tr(e,t),i=e/2,a=t-2,o=X(2.9),s=X(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 fr(e){let[t,n]=tr(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}}X(l.w+4+5),X(l.h+4+5);var pr=`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif`,mr=`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`,hr=.6,gr=1.05,_r=.85,vr=1200,yr=8,br=6,xr=2,Sr=null;function Cr(){if(Sr)return Sr;Sr=document.createElement(`canvas`),Sr.width=64,Sr.height=64;let e=Sr.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),Sr}var wr=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=Qe(i);r={bx:e,by:t,cell:$e(i),lots:a,keys:a.map(U),decor:mt(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=ft(e,n),this.lotDecors.set(r,i)),i}garden(e){let t=dt(e),n=Ze(e),r=`${t}|${n?`n`:`s`}`,i=this.gardens.get(r);return i||this.gardens.set(r,i=ur(this.art,t,n,Xe(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:Dn(e,Ze(e.lot)?`back`:`front`,Xe(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=Ne(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=V(this.ambient,this.target,i/vr*3),z(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/xr)),r=Math.max(1,Math.ceil(t/xr));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||=cr(this.art),this.plaza||=lr(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>=hr,y=et({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,W.w+W.shadow,e.height))continue;let o=null;Pn(e)?o=Nn(e):C<yr&&(C++,o=Nn(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=dn(r.samples);r.delay=r.delay===void 0?i:fn(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(!me(w)){let e=this.lightMap(c,l);if(e){let t=e.getContext(`2d`),n=xr;t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation=`source-over`,t.globalAlpha=1,t.fillStyle=pe(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=Cr();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=le(`#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=pn(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`:cn[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??=dr(),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=fr(e.seed%5)),n.drawImage(t.canvas,Math.round(e.x-t.ax),Math.round(e.y-t.ay));return}let r=B({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=wn[e.m.style];r.fillStyle=t.roof[0],r.fillRect(e.x,e.y,W.w,W.roof),r.fillStyle=t.wall[1],r.fillRect(e.x,e.y+W.roof,W.w,e.m.height-W.roof)}n&&(r.save(),r.globalCompositeOperation=`lighter`,r.globalAlpha=.08+Math.sin(t/260)*.03,r.fillStyle=`#ffffff`,r.fillRect(e.x,e.y,W.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=kn(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`?br: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>=gr)for(let e=0;e<this.nb;e++){let t=this.buildingsDrawn[e],n=An(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 ${pr}`,m=Pe(t.b.owner.country),h=`❤️ ${t.b.likes}`,g=this.measure(p,h),_=m?this.measure(`${d.toFixed(1)}px ${mr}`,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 ${mr}`,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>=_r){let e=`600 10.5px ${pr}`;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 ${pr}`;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 Tr(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 Er=2e4;function Dr(e){if(!e)return 0;let t=a.indexOf(e.label);return t<0?0:t+ +(e.progress>=e.target)}function Or(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:ye(n.label,n.target),progressText:t(`{0} de {1} h`,[he(Math.floor(n.progress)),he(n.target)]),reached:Dr(n)}}function kr(e){let n=e.slice(e.lastIndexOf(`:`)+1),r=a.indexOf(n);return r<0?null:{pct:1,pctText:`100%`,label:ye(n),progressText:t(`Meta batida!`),reached:r+1}}function Ar(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`,[ve(e.tokensBand)]),lit:e.lit===1?t(`1 prédio aceso agora`):t(`{0} prédios acesos agora`,[he(e.lit)])}:null}function jr(e){let t=e.getMonth();return t===9?`halloween`:t===10||t===11?`christmas`:`party`}var Mr=E(T),Nr=e=>(Mr.x+e)*16,Pr=e=>(Mr.y+e)*16,Z={goal:{x:Nr(15.5),y:Pr(7.6)},hall:{x:Nr(26.5),y:Pr(7.6)},w:84,h:52,posts:12},Fr={x:Nr(y.x+y.w/2),y:Pr(y.y+y.h/2)},Ir=[[Nr(12)+8,Pr(4)-30,Nr(30)+8,Pr(4)-30],[Nr(12)+8,Pr(19)-30,Nr(30)+8,Pr(19)-30]],Lr=[`#ff5d73`,`#ffd166`,`#7cf3ff`,`#b28dff`,`#6dff9e`,`#ff9f43`,`#ffffff`,`#ff7ad9`],Rr=6,zr=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 be(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=Er){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(Fr.x+(this.random()-.5)*560,Fr.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=Fr.x+(e-.5)*520,n=Fr.y-170-this.random()*120;this.rockets.push({x:t,y:Fr.y-6,vx:(this.random()-.5)*30,vy:-(250+this.random()*60),burstY:n,color:Math.floor(this.random()*Lr.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()*(Lr.length-1)))%Lr.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,Rr),(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,`${Lr[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=Lr[this.color[t]%Lr.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`:Lr[this.color[r]%Lr.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 Br(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 Vr(e,t,n){let r=Br(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 Hr(e,t){let n=Br(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 Ur(){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 Wr(e,t,n,r,i){return{x:e+(n-e)*i,y:t+(r-t)*i+Math.sin(i*Math.PI)*14}}function Gr(e,t,n,r,i,a){e.fillStyle=`#4a3b2e`;for(let a=0;a<=120;a++){let o=Wr(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=Wr(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 Kr(e,t,n,r,i,a,o){if(!(o<.15)){for(let s=0;s<24;s++){let c=Wr(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 qr=new Map;function Jr(e,t,n,r){let i=qr.get(t);if(!i){let{buf:e}=ce(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),qr.set(t,i)}e.drawImage(i,Math.round(n-20),Math.round(r-60))}function Yr(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:Nr(e),y:Pr(t)}))}var Xr=62e3;function Zr(e,t,n,r){let i=st(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 Qr(e,t){let n=b(t.lot).front;return Math.hypot(n.x-e.x,n.y-e.y)}function $r(e,t,n){let r=!!n&&e.id===n,i=t?Qr(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 ei=class{at=new Map;wait(e,t){let n=this.at.get(e);return n===void 0?0:Math.max(0,n+Xr-t)}take(e,t){return this.wait(e,t)>0?!1:(this.at.set(e,t),!0)}};function ti(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 ni=[`.11.11.`,`1211111`,`1111111`,`.11111.`,`..111..`,`...1...`],ri=/^HB-[2-9A-HJKMNP-TV-Z]{4}$/;function ii(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 ri.test(n)?n:null}var ai={out:320,wait:5e3,in:520},oi=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>=ai.out&&(this.phase=`wait`,this.since=e),this.phase===`wait`&&(this.landed||e-this.since>=ai.wait)&&(t=!this.landed,this.phase=`in`,this.since=e),this.phase===`in`&&e-this.since>=ai.in&&(this.phase=`idle`);let n=e-this.since,r=this.phase===`out`?Math.min(1,n/ai.out):this.phase===`wait`?1:this.phase===`in`?Math.max(0,1-n/ai.in):0;return{phase:this.phase,dark:r,timedOut:t}}},si=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=ii(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 ci(e){return e===void 0||e<=0?0:e>=4?4:e}function li(e){return e===void 0?0:Math.max(0,Math.min(5,Math.floor(e)))}function ui(e){return e.side===`front`?{x:W.w/2-34,y:e.height-W.ground+12,w:11,h:15}:{x:W.w/2-37,y:0,w:11,h:15}}function di(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 fi=[`#4fd18b`,`#b7e05a`,`#ffd24a`,`#ff9a3c`,`#ff4f8b`];function pi(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?fi[t]:`#2c313d`,e.fillRect(s+1+t*2,c+13-n,1,n)}}function mi(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=fi[t],e.fillRect(a+1+t*2,o+13-n,1,n)}e.globalAlpha=Math.min(.35,i*.35),e.fillStyle=fi[r-1],e.fillRect(a-2,o+5,15,11),e.globalAlpha=1}var hi=[``,`#ffd9a0`,`#ffe9b8`,`#7cf3ff`,`#ff6bd6`];function gi(e,t,n,r,i,a,o,s){if(i<=0)return;let c=An(r),l=Math.round(t+c.x),u=Math.round(n+c.y),d=hi[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 _i=`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif`,vi=`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif`,yi=4e3,bi=1600,xi=1100,Si=1.05;function Ci(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName??``))}var wi=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Ti=(e,t)=>{let n=_(S(e.x,e.y)),r=_(S(t.x,t.y));return n.x===r.x&&n.y===r.y},Ei=e=>typeof e==`number`&&Number.isFinite(e),Di=class{o;el;wheel=new At;balloons=new Dt;greetGate=new Ot(18,3300);likeGate=new Ot(9,400);teleportGate=new Ot(9,1500);reports={day:``,n:0};knocks=new ei;hearts=[];bumps=new Map;wiggles=new Map;pops=[];fireworks=new zr;confetti=new be(500);fade=new oi;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 si({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(!wi(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 wi(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&&Ei(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`?kr(e.goalId):null;return r&&(this.celebrating={goal:r,until:n+Er}),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 Ce))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,we(i),De(i)]))}}onPatch(e,t,n){if(Array.isArray(e.changes))for(let r of e.changes){if(!wi(r)||typeof r.id!=`string`)continue;let e=t.buildings.get(r.id);if(!e)continue;Ei(r.likes)&&r.likes>e.likes&&this.bumps.set(r.id,n),di(e.agents,r.agents)&&this.celebrateShift(r.id,n);let i=wi(r.tokens)&&Ei(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=An(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>yi)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=Zr(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(!$r(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=Zr(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=$r(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)&&Ti(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:Et(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?kt(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||Ci(e.target)||H(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=Zr(n,e=>r.buildingAt(e),r.myBuildingId,4)?.building??null;let e=Zr(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)&&Ti(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 Oi(this)),this.extras.building.bind(t),this.extras.building.el):(this.extras.player||(this.extras.player=new ki(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=An(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:Or(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=ui(t.m),a=this.wiggles.get(t.b.id),o=a?Math.max(0,1-(n-a.at)/bi):0;pi(e,t.x+i.x,t.y+i.y,li(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)=>Vr(e,this.goal(t),t)),a(Z.hall.x-o/2,Z.hall.y-s,o,s)&&i(Z.hall.y,e=>Hr(e,(this.city?.lit??0)>0)),!((this.goal(this.lastNow)?.reached??0)<1)){for(let[e,t,n,r]of Ir)a(e,t-4,n-e,30)&&i(t+40,(i,a)=>Gr(i,e,t,n,r,a));for(let e of Yr(jr(new Date)))a(e.x-20,e.y-60,40,64)&&i(e.y,t=>Jr(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&&gi(e,n.x,n.y,n.m,ci(r.week),t,i,n.b.lot.x*7+n.b.lot.y*13&15),a){let t=ui(n.m);mi(e,n.x+t.x,n.y+t.y,li(r.day),i)}}e.restore();for(let n of this.hearts){let r=ti(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 Ir)i(n,a-4,o-n,34)&&Kr(e,n,a,o,s,t,r);if(jr(new Date)===`halloween`)for(let n of Yr(`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`),ni.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=An(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)/xi;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 ${vi}`,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>=Si&&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 ${_i}`,Math.round(22+Math.min(170,e.measureText(De(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 ${_i}`,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 ${_i}`,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=we(r),d=o<.85?``:De(r);e.save(),e.globalAlpha=l,e.translate(Math.round(t),Math.round(n)),e.scale(c,c),e.font=`700 11.5px ${_i}`;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 ${vi}`,e.fillText(u,m+6,-17),d){e.font=`700 11.5px ${_i}`,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=Ur(),i=n.k,a=this.goal(this.lastNow),o=Ar(this.city),s=(t,n,r,i,a,o,s=700,c=`left`)=>{e.font=`${s} ${a.toFixed(1)}px ${_i}`;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 ${_i}`;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()}},Oi=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=$r(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)}},ki=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:_e(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 Ai(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 ji(e){return Q(e)&&typeof e.id==`string`&&typeof e.name==`string`&&Q(e.pos)&&$(e.pos.x)&&$(e.pos.y)}function Mi(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 Ni(e){return Q(e)&&typeof e.id==`string`&&$(e.rev)&&Q(e.detail)&&Ai(e.detail.building)&&Array.isArray(e.detail.floors)}var Pi=e=>Q(e)&&$(e.x)&&$(e.y)&&$(e.lit),Fi=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(U(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=Ni(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=Mi(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(Ai));for(let n of Array.isArray(e.players)?e.players:[])ji(n)&&this.join(n,t);this.minimap=[],Array.isArray(e.minimap)&&this.setMinimap(e.minimap.filter(Pi)),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(Ai)),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=Mi(n.pos);e&&r&&(e.info.pos=r,Q(n.greeting)&&(e.info.greeting=n.greeting),un(e.samples,{t,...r}))}return null;case`player.join`:return ji(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(ji(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(Pi)),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)||!Ai(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??[];un(r,{t,...Mi(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&&U(n.lot)!==U(e.lot)&&this.lots.get(U(n.lot))===e.id&&this.lots.delete(U(n.lot)),this.buildings.set(e.id,e),this.lots.set(U(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(U(t.lot))===e&&this.lots.delete(U(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){Ai(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++}},Ii=se,Li=.28,Ri=[.375,.5,.75],zi=3e4,Bi=2,Vi=5e3,Hi=class extends ie{levels(){let e=new Set(super.levels());for(let t of Ri)t>=this.minZoom-1e-6&&e.add(t);return e.add(this.minZoom),[...e].sort((e,t)=>e-t)}};function Ui(e){let n=new Hi;n.minZoom=Li,n.bounds={x:-1e7,y:-1e7,w:2e7,h:2e7};let r=new Fi,i=new wr(e.canvas,Ii,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 ue(rt({x:0,y:0,w:4,h:4}).grid),D=[],O=[],k=null,A=new Ve({showBuilding:e=>oe(e),topInset:()=>e.topInset(),enter:e=>z(e),extras:(e,t)=>k?.cardExtras(e,t)??null}),te=new yt(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 Di({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,!ot(t.x,t.y)){let e=at(t.x,t.y);e&&(t={x:e.x+.5,y:e.y+.5})}s=new hn(t.x,t.y),c=new vn(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=Tr(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(!ot(e,t)){let n=at(e,t,6);if(!n)return!1;r={x:n.x+.5,y:n.y+.5}}let i=rt(it(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(gn(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`:le(e.inside);break;case`building.patch`:v?.patch(e.msg);break;case`pos`:if(v&&B(),s&&C){C=!1;let t=Tr(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(),ce());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<Vi?`door`:`street`;t===`door`&&(T=null);let n=bt(e.text,t);n&&L(n);break}}},z=e=>{if(v||!a||!s){!s&&e===r.myBuildingId&&(E=!0);return}T={id:e,at:Date.now()},a.send([{t:`enter`,buildingId:e}])},ce=()=>{E&&s&&r.connected&&r.myBuildingId&&(E=!1,z(r.myBuildingId))},le=t=>{if(T=null,v&&v.id===t.id){v.replace(t);return}v&&B();let n=r.me;if(!n||!u)return;A.hide(),ve.clearKeys(),cancelAnimationFrame(f),e.canvas.hidden=!0,F.classList.add(`is-visiting`);let i=a;v=Qt({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:()=>{B(),a?.send([{t:`view`}])}})},B=()=>{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(be),l=!0)},V=()=>t(`Sem conexão com o Habblaud World agora; o Habblaud tenta de novo sozinho.`),de=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?le(r.inside):v&&B(),ce(),M.textContent=r.connected?t(`Entrando na cidade…`):V(),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=V(),M.hidden=!1);return;case`error`:e.code===`not_connected`?(M.textContent=V(),M.hidden=!1):e.code!==`no_stream`&&L(d(e.code,`scene`));return}},fe=()=>{x=!!(y?.me&&s),C=!1,x||(y=null,r=new Fi,i=new wr(e.canvas,Ii,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{de(e)}catch(e){console.error(`[cidade] evento do stream ignorado`,e)}})},pe=()=>{a?.close(),a=null},me=(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},H=null,he=(e,t,i)=>{let o=me(e,t),s=ge(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)},ge=(t,n)=>{let r=e.canvas.getBoundingClientRect();return{x:r.left+t,y:r.top+n}},_e=()=>{if(!m){H&&A.kind===`building`&&!A.pinned&&A.hide(),H=null,e.canvas.style.cursor=``;return}let t=me(m.x,m.y);if(H=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,ge(m.x,m.y),!1)}else A.kind===`building`&&!A.pinned&&A.hide()},ve=new qe(e.canvas,n,{active:()=>u&&!v,hover:(e,t,n)=>{m=n?{x:e,y:t}:null},click:he,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=st(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}z(n.id)},recenter:()=>ye(),moved:()=>{l=!0}}),ye=()=>{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)},be=t=>{f=requestAnimationFrame(be);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,ve.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?st(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:H?.type===`building`?H.id:A.kind===`building`?A.id:null,player:H?.type===`player`?H.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(),_e(),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)}},xe=()=>{p=0,ve.clearKeys(),document.hidden||c?.reset()},Se={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),fe(),p=0,f=requestAnimationFrame(be),window.addEventListener(`resize`,R),document.addEventListener(`visibilitychange`,xe),h=setInterval(()=>{document.hidden&&s&&c&&!v&&c.keepAlive(s)},zi))},hide(){u&&(v&&B(),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(),ve.clearKeys(),pe(),window.removeEventListener(`resize`,R),document.removeEventListener(`visibilitychange`,xe),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:ye,lookAt(e,t,r=n.zoom){l=!1,n.stop(),n.zoom=Math.max(Li,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(){Se.hide(),ve.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=>z(e),visitOwn(){let e=r.myBuildingId;s&&a&&e&&r.connected?z(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 Se}export{Li as CITY_MIN_ZOOM,Bi as ENTER_RADIUS,Ui as createCityScene};
@@ -0,0 +1 @@
1
+ import{a as e,s as t}from"./main-DTHUta25.js";import{c as n,l as r,r as i,t as a}from"./simulator-B45JPgSp.js";import{_ as o,c as s,i as c,l,r as u,s as d,v as f}from"./dom-slmnBOjx.js";import{c as p,d as m,i as h,l as g}from"./format-CvlPqloO.js";import{_,g as v,h as y,m as b}from"./app-QYGBa260.js";var x=36e5;24*x;var S=12e4,C=2e4,w=9e4;6*x;var T=1e4,E={toolCalls:60,tokensIn:5e6,tokensOut:5e5,costUSD:50},D=1500,O=[`waiting`,`working`,`idle`,`shell`],ee=[`prompts`,`toolCalls`,`tasksDone`,`tokensIn`,`tokensOut`,`costUSD`];function k(){return{waiting:0,working:0,idle:0,shell:0}}function A(){return{prompts:0,toolCalls:0,tasksDone:0,tokensIn:0,tokensOut:0,costUSD:0}}function j(e){return e.waiting+e.working+e.idle+e.shell}function te(e){return e===`waiting`||e===`working`||e===`idle`||e===`shell`}function M(e){return{waiting:Math.round(e.waiting),working:Math.round(e.working),idle:Math.round(e.idle),shell:Math.round(e.shell)}}function N(e,t){for(let n of O)e[n]+=t[n]}function P(e,t){for(let n of ee)e[n]+=t[n]}function F(e){return Math.floor(e/x)*x}function I(e,t,n){let r=e;for(;r<t;){let e=F(r),i=Math.min(t,e+x);n(e,i-r),r=i}}function ne(e){let t=e.filter(([e,t])=>t>e).sort((e,t)=>e[0]-t[0]),n=[];for(let[e,r]of t){let t=n[n.length-1];t&&e<=t[1]?t[1]=Math.max(t[1],r):n.push([e,r])}return n}var re=/^(\d{4})-(\d{2})-(\d{2})$/,ie=/^[A-Za-z][A-Za-z0-9_+-]*(?:\/[A-Za-z0-9_+-]+){0,2}$/,L=new Map,ae=64;function oe(e){let t=L.get(e);return t||(L.size>=ae&&L.clear(),t=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),L.set(e,t)),t}function R(e,t){let n={y:1970,mo:1,d:1,h:0,mi:0,s:0};for(let r of oe(t).formatToParts(e)){let e=Number(r.value);r.type===`year`?n.y=e:r.type===`month`?n.mo=e:r.type===`day`?n.d=e:r.type===`hour`?n.h=e%24:r.type===`minute`?n.mi=e:r.type===`second`&&(n.s=e)}return n}function se(e){if(e.length>64||!ie.test(e))return null;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}catch{return null}}function ce(e){return se(e)!==null}function le(){try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return e&&ce(e)?e:`UTC`}catch{return`UTC`}}var z=e=>String(e).padStart(2,`0`);function B(e,t){let n=R(e,t);return`${n.y}-${z(n.mo)}-${z(n.d)}`}function V(e,t){return R(e,t).h}function H(e){let t=re.exec(e);if(!t)return null;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);if(n<1970||r<1||r>12||i<1||i>31)return null;let a=new Date(Date.UTC(n,r-1,i));return a.getUTCFullYear()!==n||a.getUTCMonth()!==r-1||a.getUTCDate()!==i?null:{y:n,m:r,d:i}}function U(e,t){let n=H(e);if(!n)return e;let r=new Date(Date.UTC(n.y,n.m-1,n.d+t));return`${r.getUTCFullYear()}-${z(r.getUTCMonth()+1)}-${z(r.getUTCDate())}`}function W(e,t){let n=R(e,t);return Date.UTC(n.y,n.mo-1,n.d,n.h,n.mi,n.s)-Math.floor(e/1e3)*1e3}function G(e,n){let r=H(e);if(!r)throw RangeError(t(`dia inválido: {0}`,[e]));let i=Date.UTC(r.y,r.m-1,r.d),a=i-W(i,n);a=i-W(a,n);let o=9e5;for(let t=0;t<16&&B(a,n)<e;t++)a+=o;for(let t=0;t<16&&B(a-o,n)===e;t++)a-=o;return a}function ue(e,t){return{start:G(e,t),end:G(U(e,1),t)}}function K(e,t,n){let r=e+x/2;return r>=t&&r<n}function de(e){return{t:e,ms:k(),waitWallMs:0,counts:A(),rooms:new Map,accounts:new Map,agents:new Map}}function q(e,t){let n=e.get(t);return n||e.set(t,n={ms:k(),counts:A()}),n}function fe(e){return j(e.ms)>0||e.counts.prompts>0||e.counts.toolCalls>0||e.counts.tokensIn>0||e.counts.tokensOut>0}var pe=class{key;hours=new Map;rooms=new Map;accounts=new Map;waits=[];dirty=!1;updatedAt=0;constructor(e){this.key=e}hour(e){let t=this.hours.get(e);return t||this.hours.set(e,t=de(e)),t}hoursWithData(){return[...this.hours.values()].filter(fe).map(e=>e.t)}toFile(){let e=e=>[...e].map(([e,t])=>[e,{ms:{...t.ms},counts:{...t.counts}}]);return{version:1,day:this.key,updatedAt:this.updatedAt,hours:[...this.hours.values()].sort((e,t)=>e.t-t.t).map(t=>({t:t.t,ms:{...t.ms},waitWallMs:t.waitWallMs,counts:{...t.counts},rooms:e(t.rooms),accounts:e(t.accounts),agents:[...t.agents].map(([e,[t,n]])=>[e,t,n])})),rooms:[...this.rooms],accounts:[...this.accounts].map(([e,t])=>[e,{...t}]),waits:this.waits.map(e=>({...e}))}}};function J(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0?e:0}var me=class{fileDayOf;loader;days=new Map;idx=new Map;constructor(e,t){this.fileDayOf=e,this.loader=t}day(e){let t=this.days.get(e);if(!t){t=this.loader?.(e)??new pe(e),this.days.set(e,t);for(let e of t.hours.values())this.idx.set(e.t,{day:t,b:e})}return t}peek(e){return this.days.get(e)}list(){return[...this.days.values()]}evictBefore(e){for(let[t,n]of this.days)if(!(t>=e||n.dirty)){this.days.delete(t);for(let e of n.hours.keys())this.idx.delete(e)}}slot(e){let t=F(e),n=this.idx.get(t);if(!n){let e=this.day(this.fileDayOf(t));n={day:e,b:e.hour(t)},this.idx.set(t,n)}return n}touch(e,t){e.dirty=!0,t>e.updatedAt&&(e.updatedAt=t)}note(e,t){t.roomName&&e.rooms.get(t.room)!==t.roomName&&e.rooms.set(t.room,t.roomName);let n=t.accountMeta,r=e.accounts.get(t.account);n&&(!r||r.name!==n.name||r.short!==n.short||r.color!==n.color)&&e.accounts.set(t.account,{...n})}addMsAt(e,t,n,r,i=n){if(!(r>0))return;let{day:a,b:o}=this.slot(n);o.ms[t]+=r,q(o.rooms,e.room).ms[t]+=r,q(o.accounts,e.account).ms[t]+=r,o.agents.has(e.key)||o.agents.set(e.key,[e.room,e.account]),this.note(a,e),this.touch(a,i)}markPresent(e,t){let{day:n,b:r}=this.slot(t);r.agents.has(e.key)||(r.agents.set(e.key,[e.room,e.account]),this.note(n,e),this.touch(n,t))}addTime(e,t,n,r){I(n,r,(n,i)=>this.addMsAt(e,t,n,i,r))}addCount(e,t,n,r){if(!(n>0))return;let{day:i,b:a}=this.slot(r);a.counts[t]+=n,q(a.rooms,e.room).counts[t]+=n,q(a.accounts,e.account).counts[t]+=n,this.note(i,e),this.touch(i,r)}addWaitWallAt(e,t,n=e){if(!(t>0))return;let{day:r,b:i}=this.slot(e);i.waitWallMs+=t,this.touch(r,n)}addWaitWall(e,t){I(e,t,(e,n)=>this.addWaitWallAt(e,n,t))}addWait(e){let{day:t}=this.slot(e.start);if(t.waits.push(e),t.waits.length>1e3){let n=e=>t.waits[e].end-t.waits[e].start,r=-1;if(t.waits.forEach((t,i)=>{t.open||t===e||(r<0||n(i)<n(r))&&(r=i)}),r<0)for(let e=0;e<t.waits.length;e++)(r<0||n(e)<n(r))&&(r=e);t.waits.splice(r,1)}this.touch(t,e.end)}touchWait(e){this.touch(this.slot(e.start).day,e.end)}removeWait(e){let{day:t}=this.slot(e.start),n=t.waits.indexOf(e);n>=0&&(t.waits.splice(n,1),this.touch(t,e.end))}findOpenWait(e,t){for(let n of this.days.values())for(let r=n.waits.length-1;r>=0;r--){let i=n.waits[r];if(i.open&&i.agentId===e&&i.end>=t)return i}}};function he(){return{ms:k(),counts:A(),sessions:0,subagents:0,waits:0,longestWaitMs:0,agents:new Set}}function Y(e){let t=0,n=0;for(let r of e.agents)r.startsWith(`m:`)?t++:r.startsWith(`s:`)&&n++;let r={...e.counts,costUSD:Math.round(e.counts.costUSD*1e4)/1e4};return{ms:M(e.ms),counts:r,sessions:t,subagents:n,waits:e.waits,longestWaitMs:Math.round(e.longestWaitMs)}}function X(e,t){let n=e.get(t);return n||e.set(t,n=he()),n}function ge(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function _e(e,t,n,r,i={}){let{start:a,end:o}=ue(t,n),s=[...e].sort((e,t)=>e.key.localeCompare(t.key)),c=new Map,l=new Map,u=new Map,d=0;for(let e of s){for(let[t,n]of e.rooms)c.set(t,n);for(let[t,n]of e.accounts)l.set(t,n);for(let[t,n]of e.hours)K(t,a,o)&&u.set(t,n)}let f=he(),p=0,m=new Map,h=new Map;for(let e of u.values()){N(f.ms,e.ms),P(f.counts,e.counts),p+=e.waitWallMs;for(let[t,n]of e.rooms){let e=X(m,t);N(e.ms,n.ms),P(e.counts,n.counts)}for(let[t,n]of e.accounts){let e=X(h,t);N(e.ms,n.ms),P(e.counts,n.counts)}for(let[t,[n,r]]of e.agents)f.agents.add(t),X(m,n).agents.add(t),X(h,r).agents.add(t);for(let t of s)t.hours.get(e.t)===e&&t.updatedAt>d&&(d=t.updatedAt)}let g=new Set,_=[];for(let e of s)for(let t of e.waits){if(t.end<=a||t.start>=o||t.end-t.start<3e3)continue;let e=`${t.agentId}|${t.start}`;g.has(e)||(g.add(e),_.push(t))}for(let e of _){let t=e.end-e.start;for(let n of[f,X(m,e.roomId),X(h,e.account)])n.waits++,t>n.longestWaitMs&&(n.longestWaitMs=t)}let v=[..._].sort((e,t)=>t.end-t.start-(e.end-e.start)||e.start-t.start).slice(0,i.top??10),y=[];for(let e=F(a);e<o;e+=x)K(e,a,o)&&y.push({t:e,hour:V(Math.max(e,a),n),ms:M(u.get(e)?.ms??k())});let b=e=>c.get(e)??ge(e),S=[...m].map(([e,t])=>({id:e,name:b(e),...Y(t)})).sort((e,t)=>t.ms.waiting-e.ms.waiting||j(t.ms)-j(e.ms)||e.name.localeCompare(t.name)),C=[...h].map(([e,t])=>{let n=l.get(e);return{id:e,name:n?.name??e,short:n?.short??`?`,color:n?.color??`#8b98b3`,...Y(t)}}).sort((e,t)=>t.ms.working-e.ms.working||j(t.ms)-j(e.ms)||e.name.localeCompare(t.name)),w={day:t,tz:n,start:a,end:o,totals:{...Y(f),waitWallMs:Math.round(p)},rooms:S,accounts:C,hours:y,waits:v.map(e=>{let t={agentId:e.agentId,agentName:e.agentName,roomId:e.roomId,roomName:b(e.roomId),account:e.account,start:e.start,end:e.end,ms:e.end-e.start};return e.reason&&(t.reason=e.reason),e.open&&r-e.end<1e4&&(t.ongoing=!0),t})};return d&&(w.updatedAt=d),w}function ve(e,t){let n=new Set;for(let r of e)n.add(B(r+x/2,t));return n}function ye(e){let t=e.stats;return{toolCalls:J(t.toolCalls),tokensIn:J(t.tokensIn),tokensOut:J(t.tokensOut),costUSD:J(t.costUSD)}}function be(e,t){return{toolCalls:Math.max(e.toolCalls,t.toolCalls),tokensIn:Math.max(e.tokensIn,t.tokensIn),tokensOut:Math.max(e.tokensOut,t.tokensOut),costUSD:Math.max(e.costUSD,t.costUSD)}}var xe={toolCalls:0,tokensIn:0,tokensOut:0,costUSD:0};function Se(e){return e.toolCalls===0&&e.tokensIn===0&&e.tokensOut===0}function Ce(e){return e.tasks.reduce((e,t)=>e+ +(t.status===`completed`),0)}var we=class{book;tracks=new Map;lastSample;startedAt;constructor(e,t){this.book=e,this.startedAt=t.startedAt}get size(){return this.tracks.size}observe(e,t){let n=this.lastSample===void 0?1/0:t-this.lastSample;this.lastSample=t;let r=new Map(e.rooms.map(e=>[e.id,e.name])),i=new Map(e.accounts.map(e=>[e.id,{name:e.name,short:e.short,color:e.color}])),a=[],o=new Set;for(let s of e.agents){o.add(s.id);let e={key:s.kind===`main`?`m:${s.sessionId}`:`s:${s.id}`,room:s.roomId,roomName:r.get(s.roomId)??ge(s.roomId),account:s.account},c=i.get(s.account);c&&(e.accountMeta=c);let l=this.tracks.get(s.id),u=n;l?this.integrate(l,s,e,t,a):(l=this.begin(s,t),this.tracks.set(s.id,l),u=0,(te(s.status)||l.fresh)&&this.book.markPresent(e,t)),l.seenAt=t,l.status=s.status,this.countPrompts(l,s,e,t),this.countDeltas(l,s,e,t,u)}for(let[e,n]of this.tracks)o.has(e)||(t-n.seenAt>12e4&&this.closeWait(n),t-n.seenAt>216e5&&this.tracks.delete(e));for(let[e,t]of ne(a))this.book.addWaitWall(e,t)}begin(e,t){let n=ye(e),r=e.startedAt>=this.startedAt&&(e.kind===`sub`||Se(n));return{sessionId:e.sessionId,status:e.status,lastAt:t,seenAt:t,hw:r?{...xe}:n,costKnown:r||e.stats.costUSD!==void 0,fresh:r,tasksDone:r?0:Ce(e),settleUntil:r?0:t+Math.max(C,this.startedAt+w-t),prompts:[]}}integrate(e,t,n,r,i){let a=e.lastAt;if(e.lastAt=r,r<=a)return;if(r-a>12e4){this.closeWait(e);return}let o=t.statusSince>a&&t.statusSince<r?t.statusSince:void 0;o!==void 0&&e.status!==t.status?(this.segment(e,t,n,e.status,a,o,i),this.segment(e,t,n,t.status,o,r,i)):this.segment(e,t,n,t.status,a,r,i)}segment(e,t,n,r,i,a,o){if(a<=i)return;if(!te(r)){this.closeWait(e);return}if(this.book.addTime(n,r,i,a),r!==`waiting`){this.closeWait(e);return}if(o.push([i,a]),e.wait&&i-e.wait.end<=D){e.wait.end=a,this.book.touchWait(e.wait);return}this.closeWait(e);let s=this.book.findOpenWait(t.id,i-S);if(s){s.end=a,this.book.touchWait(s),e.wait=s;return}let c={agentId:t.id,agentName:t.name,roomId:t.roomId,account:t.account,start:i,end:a,open:!0};t.waitingFor&&(c.reason=t.waitingFor),this.book.addWait(c),e.wait=c}closeWait(e){let t=e.wait;t&&(e.wait=void 0,delete t.open,t.end-t.start<3e3?this.book.removeWait(t):this.book.touchWait(t))}countPrompts(e,t,n,r){for(let i of t.recent)i.kind!==`prompt`||i.at<this.startedAt||e.prompts.includes(i.id)||(e.prompts.push(i.id),e.prompts.length>64&&e.prompts.shift(),this.book.addCount(n,`prompts`,1,Math.min(i.at,r)))}countDeltas(e,t,n,r,i){let a=ye(t),o=Ce(t);if(t.sessionId!==e.sessionId){e.sessionId=t.sessionId,e.fresh=Se(a),e.hw=e.fresh?{...xe}:a,e.costKnown=e.fresh||t.stats.costUSD!==void 0,e.tasksDone=e.fresh?0:o,e.settleUntil=e.fresh?0:r+C,e.prompts=[];return}if(t.stats.costUSD!==void 0&&!e.costKnown&&(e.costKnown=!0,e.fresh||(e.hw.costUSD=Math.max(e.hw.costUSD,a.costUSD))),r<e.settleUntil){e.hw=be(e.hw,a),e.tasksDone=o;return}let s={toolCalls:Math.max(0,a.toolCalls-e.hw.toolCalls),tokensIn:Math.max(0,a.tokensIn-e.hw.tokensIn),tokensOut:Math.max(0,a.tokensOut-e.hw.tokensOut),costUSD:Math.max(0,a.costUSD-e.hw.costUSD)};e.hw=be(e.hw,a);let c=s.toolCalls>E.toolCalls||s.tokensIn>E.tokensIn||s.tokensOut>E.tokensOut||s.costUSD>E.costUSD;if(i<=T&&c){e.tasksDone=o;return}this.book.addCount(n,`toolCalls`,s.toolCalls,r),this.book.addCount(n,`tokensIn`,s.tokensIn,r),this.book.addCount(n,`tokensOut`,s.tokensOut,r),this.book.addCount(n,`costUSD`,s.costUSD,r),o>e.tasksDone&&this.book.addCount(n,`tasksDone`,o-e.tasksDone,r),e.tasksDone=o}},Te=[.03,.01,0,0,0,0,.02,.1,.4,.75,.95,.85,.4,.55,.9,1,.95,.8,.55,.35,.3,.25,.15,.06],Ee=[t(`aprovar uma permissão`),t(`responder uma pergunta`),t(`escolher uma opção`),t(`aprovar o plano`)];function De(e,o,s,c,l=n(`meu-dia:${F(s)}`)){let u=r(l),d=(e,t)=>e+u()*(t-e),f=o.accounts.map(e=>({id:e.id,codex:`provider`in e&&e.provider===`codex`,meta:{name:e.name,short:e.short,color:e.color}})),p=f.filter(e=>!e.codex),m=f.find(e=>e.codex),h=e=>m&&p.length?e<.5?p[0]:e<.8?p[p.length-1]:m:f[e<.6?0:f.length-1],g=new Map(o.rooms.map(e=>[e.id,e.name])),_=new Set(o.agents.map(e=>e.name)),v=new Map;for(let e of o.agents){let t=v.get(e.roomId)??new Map;t.set(e.account,(t.get(e.account)??0)+1),v.set(e.roomId,t)}let y=[...v.keys()][0];if(!y||!f.length)return;let b=y.slice(0,y.lastIndexOf(`/`)),S=[];for(let e of a){let t=`${b}/${e}`;v.has(t)||(v.set(t,new Map([[h(u()).id,1]])),S.push(t))}let C=S.some(e=>v.get(e).has(m?.id??``));m&&S.length&&!C&&v.set(S[S.length-1],new Map([[m.id,1]]));let w=[...v].map(([e,t])=>{let n=[...t].sort((e,t)=>t[1]-e[1])[0]?.[0]??f[0].id,r=[0,1,2].map(t=>{let n=i(`${e}:${t}:${l}`,_);return _.add(n.name),n.name}),a={id:e,name:g.get(e)??e.split(`/`).pop()??e,account:n,codex:!!f.find(e=>e.id===n)?.codex,weight:d(.35,1.1),waitiness:d(.05,.3),people:r},o=f.find(e=>e.id===n)?.meta;return o&&(a.accountMeta=o),a}),T=F(s),E=F(G(U(B(s,c),-1),c));for(let n=E;n<=T;n+=x){let r=Math.min(x,s-n);if(r<=0)continue;let i=r/x,a=Te[V(n,c)]??0,o=0;w.forEach((c,l)=>{let f=a*c.weight*d(.7,1.3);if(f<.04)return;let p=f>.6?2:1,m=e=>{let t={key:e,room:c.id,roomName:c.name,account:c.account};return c.accountMeta&&(t.accountMeta=c.accountMeta),t},h=Array.from({length:p},(e,t)=>m(`m:demo-dia-${l}-${t}`)),g=Math.min(.92,f*d(.55,.85))*x*i,_=g*c.waitiness*d(.5,1.4),v=g*d(0,.12),y=Math.max(0,p*x*i*.9-g-_-v)*d(.3,.7),b=[[`working`,g],[`waiting`,_],[`shell`,v],[`idle`,y]];for(let[t,i]of b)for(let a of h)e.addMsAt(a,t,n,i/p,Math.min(s,n+r));let S=Math.round(f*d(0,2.2));for(let t=0;t<S;t++)e.addMsAt(m(`s:demo-dia-${l}-${n}-${t}`),`working`,n,g*d(.15,.45),Math.min(s,n+r));let C=g/6e4,w=n+r/2,T=h[0];e.addCount(T,`prompts`,Math.round(C/7*d(.6,1.4)),w),e.addCount(T,`toolCalls`,Math.round(C*d(1.5,3)),w),e.addCount(T,`tasksDone`,Math.round(C/12*d(.4,1.2)),w);let E=Math.round(C*d(9e4,16e4)),D=Math.round(C*d(1e3,2200));if(e.addCount(T,`tokensIn`,E,w),e.addCount(T,`tokensOut`,D,w),c.codex||e.addCount(T,`costUSD`,Math.round((E*3e-7+D*15e-6)*1e4)/1e4,w),_>=3e4){let i=1+Math.floor(u()*Math.min(3,_/6e4)),a=_;for(let o=0;o<i&&a>=5e3;o++){let s=o===i-1?a:a*d(.3,.7);a-=s;let f=n+u()*Math.max(0,r-s),p=c.people[Math.floor(u()*c.people.length)],m=Ee[Math.floor(u()*Ee.length)];e.addWait({agentId:`demo-dia:${l}:${p}`,agentName:p,roomId:c.id,account:c.account,start:Math.round(f),end:Math.round(f+s),reason:c.codex?t(`aprovar um comando`):m})}o+=_*d(.75,.95)}}),e.addWaitWallAt(n,Math.min(o,r),Math.min(s,n+r))}}var Z={waiting:t(`Esperando você`),working:t(`Trabalhando`),idle:t(`Ocioso`),shell:t(`Esperando o shell`)};function Q(e){let t=Number.isFinite(e)?Math.max(0,e):0;if(t<6e4)return`${Math.floor(t/1e3)} s`;if(t<36e5)return`${Math.floor(t/6e4)} min`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return r?`${n} h ${r} min`:`${n} h`}var Oe=new Set(O);function $(e,t){return O.reduce((n,r)=>n+(t.has(r)?e[r]:0),0)}function ke(e,t,n){return n>0?O.filter(n=>t.has(n)&&e[n]>0).map(t=>({status:t,ms:e[t],pct:e[t]/n*100})):[]}function Ae(e,n=Oe){let r=O.filter(t=>n.has(t)&&e[t]>0).map(t=>`${Z[t].toLowerCase()} ${Q(e[t])}`);return r.length?r.join(`, `):t(`sem tempo registrado`)}function je(e,n,r=!1,i){let a=e.totals,s=a.counts,c=e.waits[0],l=(e,t,n)=>`${p(e)} ${e===1?t:n}`;return{waiting:Q(a.ms.waiting),waitingMs:a.ms.waiting,longest:c?t(`{0} · {1} em {2}, às {3}{4}`,[Q(c.ms),o(c.agentId,c.agentName,i),c.roomName,n(c.start),c.ongoing?t(` (ainda esperando)`):``]):``,wall:a.waitWallMs>0?t(`Alguém esperou por você durante {0} do dia`,[Q(a.waitWallMs)]):``,waits:a.waits?l(a.waits,t(`espera`),t(`esperas`)):a.ms.waiting>0?t(`só esperas de poucos segundos`):t(`nenhuma espera`),working:Q(a.ms.working),sessions:p(a.sessions),subagents:l(a.subagents,t(`subagente`),t(`subagentes`)),tokens:g(s.tokensIn+s.tokensOut),tokensDetail:t(`{0} entrada · {1} saída`,[g(s.tokensIn),g(s.tokensOut)]),cost:s.costUSD>0?m(s.costUSD):`—`,costHint:s.costUSD>0?t(r?`Só do Claude Code: o Codex não grava custo, só tokens`:`Custo calculado pelo próprio Claude Code`):s.tokensIn+s.tokensOut>0?t(r?`O Codex não grava custo, só tokens`:`Os transcripts não trouxeram o custo`):t(`Nenhum gasto registrado`),prompts:p(s.prompts),activity:`${l(s.toolCalls,t(`ferramenta`),t(`ferramentas`))} · ${l(s.tasksDone,t(`tarefa concluída`),t(`tarefas concluídas`))}`}}function Me(e,n){let r=Math.max(0,...e.map(e=>$(e.ms,n)));return e.filter(e=>j(e.ms)>0).map(e=>{let i=$(e.ms,n);return{id:e.id,name:e.name,ms:e.ms,total:i,segments:ke(e.ms,n,r),waiting:t(`{0} esperando você`,[Q(e.ms.waiting)]),totalText:t(`{0} no total`,[Q(i)]),label:`${e.name}: ${Ae(e.ms,n)}`}})}var Ne=[5,10,15,20,30,45,60,90,120,180,240,300,360,480,600,720,960,1200,1440];function Pe(e){let t=Math.max(1,e/6e4),n=Ne.find(e=>e>=t)??Math.ceil(t/1440)*1440,r=n>=120?[60,30]:[5],i=1;for(let e of r){let t=[4,3,2].find(t=>Number.isInteger(n/t)&&n/t%e===0);if(t){i=t;break}}let a=n/i;return{max:n*6e4,ticks:Array.from({length:i},(e,t)=>(t+1)*a*6e4)}}function Fe(e){let t=Math.round(e/6e4);if(t<60)return`${t} min`;let n=Math.floor(t/60),r=t%60;return r?`${n} h ${String(r).padStart(2,`0`)}`:`${n} h`}function Ie(e,t,n,r=3){let i=Pe(Math.max(0,...e.map(e=>$(e.ms,t))));return{columns:e.map((a,o)=>{let s=$(a.ms,t),c=(a.hour+1)%24,l=`${a.hour}h–${c}h`;return{t:a.t,hour:a.hour,ms:a.ms,total:s,segments:ke(a.ms,t,i.max),range:l,label:`${l}: ${Ae(a.ms,t)}`,now:n>=a.t&&n<(e[o+1]?.t??a.t+36e5),future:a.t>n,tick:a.hour%r===0}}),axis:i}}function Le(e,n=()=>!1){let r=e.reduce((e,t)=>e+t.ms.working,0);return e.filter(e=>j(e.ms)>0||e.counts.tokensIn>0).map(e=>{let i=r>0?Math.round(e.ms.working/r*100):0,a=n(e.id);return{id:e.id,name:e.name,short:e.short,color:e.color,share:i,shareText:t(`{0}% do trabalho do dia`,[i]),working:Q(e.ms.working),waiting:Q(e.ms.waiting),sessions:`${p(e.sessions)} ${e.sessions===1?t(`sessão`):t(`sessões`)}${e.subagents?` · ${p(e.subagents)} sub`:``}`,tokens:g(e.counts.tokensIn+e.counts.tokensOut),cost:a?null:e.counts.costUSD>0?m(e.counts.costUSD):`—`,codex:a}})}function Re(e,n,r){let i=Math.max(1,...e.map(e=>e.ms));return e.map((e,a)=>{let s=e.ongoing?t(`desde {0}`,[n(e.start)]):`${n(e.start)}–${n(e.end)}`,c=o(e.agentId,e.agentName,r),l={key:`${e.agentId}|${e.start}`,rank:a+1,duration:Q(e.ms),pct:Math.max(2,e.ms/i*100),agentName:c,roomName:e.roomName,account:e.account,when:s,ongoing:!!e.ongoing,label:`${a+1}º: ${Q(e.ms)}, ${c} em ${e.roomName}, ${s}${e.reason?t(`, para {0}`,[e.reason]):``}${e.ongoing?t(`, ainda esperando`):``}`};return e.reason&&(l.reason=e.reason),l})}function ze(e,t,n){let r=O.filter(e=>n.has(e));return{head:[...r.map(e=>Z[e]),`Total`],rows:e.map(e=>[t(e),...r.map(t=>e.ms[t]>0?Q(e.ms[t]):`—`),Q($(e.ms,n))])}}var Be=new Intl.DateTimeFormat(e(),{weekday:`short`,day:`2-digit`,month:`2-digit`,timeZone:`UTC`});function Ve(e,n){if(e===n)return t(`Hoje`);let[r,i,a]=e.split(`-`).map(Number),o=Date.UTC(r,i-1,a),[s,c,l]=n.split(`-`).map(Number);return Date.UTC(s,c-1,l)-o===864e5?t(`Ontem`):Be.format(o)}function He(e,t,n){let r=new URLSearchParams({day:e,tz:t});return n&&r.set(`source`,n),`/api/stats?${r}`}function Ue(e){return`/api/stats/days?${new URLSearchParams({tz:e})}`}function We(e,t,n){return e&&t===n}function Ge(e){return j(e.totals.ms)===0&&e.totals.counts.tokensIn===0&&e.waits.length===0}var Ke=3e4,qe=t(`Tempo de agentes é a soma de todos eles: dois agentes trabalhando por 1 hora contam 2 horas. `)+t(`“Esperando você” é o tempo de mão levantada no escritório (permissão, pergunta ou escolha). `)+t(`O Habblaud só conta o que acontece enquanto ele está rodando.`);async function Je(e){let n=await fetch(e,{cache:`no-store`}),r=await n.json().catch(()=>null);if(!n.ok||!r)throw Error(r?.error??t(`erro {0}`,[n.status]));return r}var Ye={days:e=>Je(Ue(e)),day:(e,t,n)=>Je(He(e,t,n))},Xe=class{tz=le();book=new me(e=>B(e,this.tz));tracker=new we(this.book,{startedAt:Date.now()});seeded=!1;last=0;constructor(e){e.on(`snapshot`,e=>{let t=Date.now();t-this.last<1e3||(this.last=t,this.seeded||=(De(this.book,e,t,this.tz),!0),this.tracker.observe(e,t))})}async days(e){let t=B(Date.now(),e),n=new Set([t]);for(let t of this.book.list())for(let r of ve(t.hoursWithData(),e))n.add(r);return{tz:e,today:t,days:[...n].sort().reverse(),demoAvailable:!1}}async day(e,t){let n=Date.now();return{source:`demo`,demoAvailable:!1,today:B(n,t),serverTime:n,stats:_e(this.book.list(),e,t,n)}}},Ze=class{ctx;button;el;source;tz=le();days=null;data=null;day=null;sourcePref;visible=new Set(Oe);tables=new Set;loading=!1;error=null;seq=0;timer=null;demoSeen;opener=null;select;seg;badge;status;statusText;retry;content;tip;constructor(e,n){this.ctx=e,this.button=n,this.source=e.store.mock?new Xe(e.store):Ye,this.select=new v({label:t(`Dia`),className:`ui-day__select`,onChange:e=>this.pickDay(e)}),this.seg=new y({label:t(`Dados exibidos`),options:[{value:`demo`,label:t(`Demonstração`),className:`ui-seg__opt`},{value:`real`,label:t(`Dados reais`),className:`ui-seg__opt`}],indicator:!1,className:`ui-seg ui-day__source`,onChange:e=>this.pickSource(e)}),this.seg.el.hidden=!0,this.badge=u(`span`,{class:`ui-day__badge`,text:t(`demonstração`),title:t(`Números fictícios do modo demonstração`),hidden:!0});let r=c(_.close,t(`Fechar (Esc)`),()=>this.close(),`ui-icon-btn--sm`);this.statusText=u(`span`,{}),this.retry=u(`button`,{class:`ui-link-btn`,type:`button`,text:t(`Tentar de novo`),hidden:!0,on:{click:()=>void this.load(!0)}}),this.status=u(`p`,{class:`ui-day__status`},this.statusText,this.retry),this.content=u(`div`,{class:`ui-day__content`}),this.tip=u(`div`,{class:`ui-day__tip`,role:`tooltip`,hidden:!0,attrs:{"aria-hidden":`true`}}),this.el=u(`dialog`,{class:`ui-dialog ui-day`,attrs:{"aria-labelledby":`ui-day-title`}},u(`div`,{class:`ui-dialog__head ui-day__head`},u(`div`,{class:`ui-day__title`},u(`h2`,{text:t(`Meu dia`),attrs:{id:`ui-day-title`}}),this.badge),u(`div`,{class:`ui-day__controls`},this.select.el,this.seg.el),r),u(`div`,{class:`ui-day__body`},this.status,this.content,u(`p`,{class:`ui-day__note`,text:qe})),this.tip),this.el.addEventListener(`click`,e=>{e.target===this.el&&this.close()}),this.el.addEventListener(`keydown`,e=>e.stopPropagation()),this.el.addEventListener(`close`,()=>this.onClosed()),this.el.addEventListener(`scroll`,()=>this.hideTip(),!0)}get isOpen(){return this.el.open}open(){this.el.open||(this.opener=document.activeElement instanceof HTMLElement?document.activeElement:null,this.day=null,this.el.showModal(),this.button.setAttribute(`aria-expanded`,`true`),this.load(!0))}close(){this.el.open&&this.el.close()}toggle(){this.el.open?this.close():this.open()}render(){let e=this.ctx.store.snapshot?.meta.demo;if(e===this.demoSeen)return;let t=this.demoSeen!==void 0;this.demoSeen=e,t&&this.el.open&&!this.ctx.store.mock&&this.load(!0)}onClosed(){this.seq++,this.stopTimer(),this.hideTip(),this.button.setAttribute(`aria-expanded`,`false`),this.opener?.isConnected&&this.opener.focus({preventScroll:!0}),this.opener=null}pickDay(e){this.day=e,this.sourcePref??=this.data?.source,this.load(!1)}pickSource(e){if(this.data?.source===e)return;this.sourcePref=e;let t=e===`demo`?this.days?.demoDays:this.days?.days;this.day&&t&&!t.includes(this.day)&&(this.day=null),this.load(!1)}async load(e){let n=++this.seq;this.stopTimer(),this.loading=!0,this.renderStatus();try{if(e||!this.days){let e=await this.source.days(this.tz);if(n!==this.seq)return;this.days=e,this.sourcePref===`demo`&&!e.demoAvailable&&(this.sourcePref=void 0)}let t=this.day??this.days.today,r=await this.source.day(t,this.tz,this.sourcePref);if(n!==this.seq)return;this.data=r,this.day=r.stats.day,this.error=null,this.renderAll()}catch(e){if(n!==this.seq)return;this.error=e instanceof Error?e.message:String(e),this.ctx.announce(t(`Não foi possível carregar as estatísticas do dia.`)),this.data&&(this.day=this.data.stats.day,this.renderControls(this.data))}finally{n===this.seq&&(this.loading=!1,this.renderStatus(),We(this.el.open,this.day??``,this.data?.today??``)&&(this.timer=setTimeout(()=>void this.load(!0),Ke)))}}stopTimer(){this.timer&&clearTimeout(this.timer),this.timer=null}renderStatus(){if(this.el.classList.toggle(`is-loading`,this.loading&&!!this.data),d(this.retry,!this.error),this.error)l(this.statusText,t(`Não foi possível carregar as estatísticas ({0}).`,[this.error]));else if(this.loading&&!this.data)l(this.statusText,t(`Carregando…`));else if(this.data){let e=this.data.stats.day===this.data.today?t(`Atualizado às {0} · atualiza a cada 30 s`,[h(this.data.serverTime)]):``;l(this.statusText,[e,f(this.data,this.ctx.store.snapshot?.machines)].filter(Boolean).join(` · `))}}renderAll(){let e=this.data;if(!e)return;this.renderControls(e);let t=document.activeElement?.closest(`[data-focus-key]`)?.dataset.focusKey;this.hideTip(),this.content.replaceChildren(...this.sections(e)),t&&this.content.querySelector(`[data-focus-key="${CSS.escape(t)}"]`)?.focus({preventScroll:!0})}renderControls(e){let t=e.source===`demo`;d(this.badge,!t),d(this.seg.el,!e.demoAvailable),this.seg.value=t?`demo`:`real`;let n=(t?this.days?.demoDays:this.days?.days)??[e.today],r=n.includes(e.stats.day)?n:[e.stats.day,...n];this.select.setOptions(r.map(t=>({value:t,label:Ve(t,e.today)})),e.stats.day),this.select.value=e.stats.day,this.select.disabled=r.length<2}sections(e){let n=e.stats,r=e=>h(e,!1),i=je(n,r,n.accounts.some(e=>this.isCodexAccount(e.id)&&e.counts.tokensIn+e.counts.tokensOut>0),this.ctx.store.snapshot?.machines),a=[this.kpis(i)];if(Ge(n)){let r=n.day===e.today;return a.push(u(`p`,{class:`ui-day__empty`,text:t(r?`Ainda não há tempo registrado hoje. Os números aparecem assim que algum agente trabalhar com o Habblaud aberto.`:`Nada registrado neste dia.`)})),a}return a.push(this.legend()),a.push(this.hoursCard(e)),a.push(this.roomsCard(Me(n.rooms,this.visible))),a.push(this.waitsCard(Re(n.waits,r,this.ctx.store.snapshot?.machines),e)),a.push(this.accountsCard(e)),a}kpis(e){let n=u(`span`,{class:`ui-day__swatch is-waiting`,attrs:{"aria-hidden":`true`}}),r=u(`div`,{class:`ui-day__hero`},u(`p`,{class:`ui-day__kpi-label`},n,u(`span`,{text:t(`Esperando você`)})),u(`p`,{class:`ui-day__hero-value`,text:e.waiting}),u(`p`,{class:`ui-day__kpi-sub`,text:e.waits}),e.longest?u(`p`,{class:`ui-day__kpi-sub`},u(`span`,{class:`ui-day__muted`,text:t(`Maior espera: `)}),u(`strong`,{text:e.longest})):null,e.wall?u(`p`,{class:`ui-day__kpi-sub`,text:e.wall}):null),i=(e,t,n,r,i)=>u(`div`,{class:`ui-day__kpi`,title:r},u(`p`,{class:`ui-day__kpi-label`},i?u(`span`,{class:`ui-day__swatch is-${i}`,attrs:{"aria-hidden":`true`}}):null,u(`span`,{text:e})),u(`p`,{class:`ui-day__kpi-value`,text:t}),u(`p`,{class:`ui-day__kpi-sub`,text:n}));return u(`section`,{class:`ui-day__kpis`,attrs:{"aria-label":t(`Destaques do dia`)}},r,i(t(`Trabalhando`),e.working,t(`soma do tempo de todos os agentes`),void 0,`working`),i(t(`Sessões`),e.sessions,e.subagents),i(t(`Pedidos`),e.prompts,e.activity),i(`Tokens`,e.tokens,e.tokensDetail),i(t(`Custo`),e.cost,e.costHint,e.costHint))}legend(){let e=O.map(e=>{let n=this.visible.has(e);return u(`button`,{class:`ui-day__key${n?``:` is-off`}`,type:`button`,title:t(n?`Esconder “{0}” dos gráficos`:`Mostrar “{0}” nos gráficos`,[Z[e]]),attrs:{"aria-pressed":String(n),"data-focus-key":`key:${e}`},on:{click:()=>this.toggleStatus(e)}},u(`span`,{class:`ui-day__swatch is-${e}`,attrs:{"aria-hidden":`true`}}),u(`span`,{text:Z[e]}))});return u(`div`,{class:`ui-day__legend`,role:`group`,attrs:{"aria-label":t(`Status nos gráficos (clique para mostrar ou esconder)`)}},...e)}toggleStatus(e){if(this.visible.has(e)){if(this.visible.size===1)return;this.visible.delete(e)}else this.visible.add(e);this.renderAll()}card(e,n,r,i){let a=!!i&&this.tables.has(i),o=i?u(`button`,{class:`ui-link-btn ui-day__table-btn`,type:`button`,text:t(a?`Ver gráfico`:`Ver tabela`),attrs:{"aria-pressed":String(a),"data-focus-key":`table:${i}`},on:{click:()=>{this.tables.has(i)?this.tables.delete(i):this.tables.add(i),this.renderAll()}}}):null,s=u(`div`,{class:`ui-day__card-body`});return{el:u(`section`,{class:`ui-day__card ui-day__card--${e}`,attrs:{"aria-labelledby":`ui-day-${e}`}},u(`div`,{class:`ui-day__card-head`},u(`div`,{},u(`h3`,{text:n,attrs:{id:`ui-day-${e}`}}),u(`p`,{class:`ui-day__card-sub`,text:r})),o),s),body:s,showTable:a}}table(e,t,n){return u(`div`,{class:`ui-day__table-wrap`},u(`table`,{class:`ui-day__table`},u(`caption`,{class:`ui-sr`,text:n}),u(`thead`,{},u(`tr`,{},...e.map((e,t)=>u(`th`,{text:e,attrs:{scope:`col`,class:t?`is-num`:void 0}})))),u(`tbody`,{},...t.map(e=>u(`tr`,{},...e.map((e,t)=>t?u(`td`,{class:`is-num`,text:e}):u(`th`,{text:e,attrs:{scope:`row`}})))))))}hoursCard(e){let n=this.ctx.isNarrow(),{columns:r,axis:i}=Ie(e.stats.hours,this.visible,e.serverTime,n?6:3),a=this.card(`hours`,t(`Por hora`),t(`Tempo de agentes em cada hora do dia`),`hours`);if(a.showTable){let e=ze(r,e=>e.range,this.visible);return a.body.append(this.table([t(`Hora`),...e.head],e.rows,t(`Tempo de agentes por hora`))),a.el}let o=u(`div`,{class:`ui-day__grid`,attrs:{"aria-hidden":`true`}},...i.ticks.map(e=>u(`span`,{class:`ui-day__gridline`,style:`bottom:${e/i.max*100}%`},u(`span`,{class:`ui-day__tick`,text:Fe(e)})))),s=u(`div`,{class:`ui-day__cols`,role:`list`,attrs:{"aria-label":t(`Tempo de agentes por hora (setas para navegar)`)}}),c=r.findIndex(e=>e.now);c<0&&(c=0),r.forEach((e,t)=>s.append(this.column(e,t===c))),s.addEventListener(`keydown`,e=>this.moveFocus(e,s));let l=u(`div`,{class:`ui-day__xaxis`,attrs:{"aria-hidden":`true`}},...r.map(e=>u(`span`,{class:`ui-day__xlabel${e.now?` is-now`:``}`,text:e.tick||e.now&&!n?`${e.hour}h`:``})));return a.body.append(u(`div`,{class:`ui-day__plot`},o,s),l),a.el}column(e,n){let r=u(`span`,{class:`ui-day__stack`},...e.segments.map(e=>u(`span`,{class:`ui-day__seg is-${e.status}`,style:`height:${e.pct}%`,attrs:{"data-status":e.status}}))),i=u(`div`,{class:`ui-day__col${e.now?` is-now`:``}`,role:`listitem`,tabIndex:n?0:-1,attrs:{"aria-label":`${e.label}${e.now?t(` (agora)`):``}`,"data-focus-key":`hour:${e.t}`}},r);return this.bindTip(i,()=>`${e.range}${e.now?t(` · agora`):e.future?t(` · ainda não chegou`):``}`,()=>e.future?[]:[...O.filter(t=>this.visible.has(t)&&e.ms[t]>0).map(t=>({status:t,label:Z[t],value:Q(e.ms[t])})),{label:`Total`,value:Q(e.total)}],()=>r.lastElementChild??r),i}moveFocus(e,t){let n=[...t.children],r=n.indexOf(document.activeElement);if(r<0)return;let i=e.key===`ArrowRight`?r+1:e.key===`ArrowLeft`?r-1:e.key===`Home`?0:e.key===`End`?n.length-1:-2;if(i===-2)return;e.preventDefault();let a=n[Math.max(0,Math.min(n.length-1,i))];n.forEach(e=>e.tabIndex=e===a?0:-1),a.focus()}roomsCard(e){let n=this.card(`rooms`,t(`Por projeto`),t(`Ordenado pelo tempo esperando você`),`rooms`);if(!e.length)return n.body.append(u(`p`,{class:`ui-day__muted`,text:t(`Nenhum projeto com tempo neste dia.`)})),n.el;if(n.showTable){let r=ze(e,e=>e.name,this.visible);return n.body.append(this.table([t(`Projeto`),...r.head],r.rows,t(`Tempo de agentes por projeto`))),n.el}let r=u(`ul`,{class:`ui-day__bars`});for(let t of e){let e=u(`span`,{class:`ui-day__track`},...t.segments.map(e=>u(`span`,{class:`ui-day__seg is-${e.status}`,style:`width:${e.pct}%`,attrs:{"data-status":e.status}}))),n=u(`li`,{class:`ui-day__bar`,tabIndex:0,attrs:{"aria-label":t.label,"data-focus-key":`room:${t.id}`}},u(`span`,{class:`ui-day__bar-head`},u(`span`,{class:`ui-day__bar-name`,text:t.name,title:t.id}),u(`span`,{class:`ui-day__bar-value`},this.visible.has(`waiting`)?u(`strong`,{text:t.waiting}):null,u(`span`,{class:`ui-day__muted`,text:t.totalText}))),e);this.bindTip(n,()=>t.name,()=>[...O.filter(e=>this.visible.has(e)&&t.ms[e]>0).map(e=>({status:e,label:Z[e],value:Q(t.ms[e])})),{label:`Total`,value:Q($(t.ms,this.visible))}]),r.append(n)}return n.body.append(r),n.el}waitsCard(e,n){let r=this.card(`waits`,t(`Maiores esperas`),t(`Quanto tempo cada agente ficou de mão levantada esperando você`));if(!e.length)return r.body.append(u(`p`,{class:`ui-day__muted`,text:t(`Nenhuma espera por você neste dia.`)})),r.el;let i=new Map(n.stats.accounts.map(e=>[e.id,e])),a=u(`ol`,{class:`ui-day__waits`});for(let n of e){let e=i.get(n.account),r=u(`span`,{class:`ui-acc-chip`,text:e?.short??`?`,title:e?.name??n.account});s(r,`--acc`,e?.color??`#8b98b3`),this.isCodexAccount(n.account)&&(r.dataset.provider=`codex`),a.append(u(`li`,{class:`ui-day__wait${n.ongoing?` is-ongoing`:``}`,attrs:{"aria-label":n.label}},u(`span`,{class:`ui-day__rank`,text:`${n.rank}`,attrs:{"aria-hidden":`true`}}),u(`span`,{class:`ui-day__wait-main`,attrs:{"aria-hidden":`true`}},u(`span`,{class:`ui-day__wait-top`},u(`strong`,{class:`ui-day__wait-dur`,text:n.duration}),u(`span`,{class:`ui-day__wait-bar`},u(`span`,{class:`ui-day__seg is-waiting`,style:`width:${n.pct}%`})),n.ongoing?u(`span`,{class:`ui-day__now`,text:t(`esperando agora`)}):null),u(`span`,{class:`ui-day__wait-who`},r,u(`span`,{class:`ui-day__wait-name`,text:n.agentName}),u(`span`,{class:`ui-day__muted`,text:`${t(`em {0}`,[n.roomName])} · ${n.when}${n.reason?` · ${n.reason}`:``}`})))))}return r.body.append(a),r.el}accountsCard(e){let n=Le(e.stats.accounts,e=>this.isCodexAccount(e)),r=this.card(`accounts`,t(`Por conta`),t(`Cada conta na cor dela, com a fatia do tempo de trabalho do dia`));if(!n.length)return r.body.append(u(`p`,{class:`ui-day__muted`,text:t(`Nenhuma conta com tempo neste dia.`)})),r.el;let i=u(`div`,{class:`ui-day__accounts`});for(let e of n){let n=u(`span`,{class:`ui-acc-chip ui-acc-chip--md`,text:e.short,attrs:{"aria-hidden":`true`,...e.codex?{"data-provider":`codex`}:{}}});s(n,`--acc`,e.color);let r=u(`span`,{class:`ui-day__meter`,role:`img`,attrs:{"aria-label":e.shareText}},u(`span`,{class:`ui-day__meter-fill`,style:`width:${e.share}%`})),a=(e,t)=>[u(`dt`,{text:e}),u(`dd`,{text:t})],o=u(`article`,{class:`ui-day__account`,attrs:{"aria-label":e.name}},u(`div`,{class:`ui-day__account-head`},n,u(`strong`,{class:`ui-day__account-name`,text:e.name}),u(`span`,{class:`ui-day__muted`,text:e.sessions})),r,u(`p`,{class:`ui-day__kpi-sub`,text:e.shareText}),u(`dl`,{class:`ui-day__account-stats`},...a(t(`Trabalhando`),e.working),...a(t(`Esperando você`),e.waiting),...a(`Tokens`,e.tokens),...e.cost===null?[u(`dt`,{text:t(`Custo`)}),u(`dd`,{text:t(`só tokens`),title:t(`O Codex não grava custo, só tokens`)})]:a(t(`Custo`),e.cost)));s(o,`--acc`,e.color),i.append(o)}return r.body.append(i),r.el}isCodexAccount(e){return b(this.ctx.account(e),e)===`codex`}bindTip(e,t,n,r=()=>e){let i=e=>this.showTip(r(),t(),n(),e);e.addEventListener(`pointerenter`,e=>i(Qe(e.target))),e.addEventListener(`pointermove`,e=>i(Qe(e.target))),e.addEventListener(`pointerleave`,()=>this.hideTip()),e.addEventListener(`focus`,()=>i()),e.addEventListener(`blur`,()=>this.hideTip())}showTip(e,t,n,r){this.tip.replaceChildren(u(`p`,{class:`ui-day__tip-title`,text:t}),...n.map(e=>u(`p`,{class:`ui-day__tip-row${e.status&&e.status===r?` is-hl`:``}${e.status?``:` is-total`}`},u(`span`,{class:`ui-day__tip-key${e.status?` is-${e.status}`:``}`,attrs:{"aria-hidden":`true`}}),u(`strong`,{text:e.value}),u(`span`,{text:e.label})))),this.tip.hidden=!1;let i=this.el.getBoundingClientRect(),a=e.getBoundingClientRect(),o=this.tip.getBoundingClientRect(),s=Math.min(Math.max(8,a.left-i.left+a.width/2-o.width/2),i.width-o.width-8),c=a.top-i.top-o.height-8;c<8&&(c=a.bottom-i.top+8),this.tip.style.left=`${Math.round(s)}px`,this.tip.style.top=`${Math.round(c)}px`}hideTip(){this.tip.hidden=!0}};function Qe(e){let t=e instanceof HTMLElement?e.dataset.status:void 0;return t&&O.includes(t)?t:void 0}export{Ze as DayPanel};
@@ -0,0 +1 @@
1
+ import{s as e}from"./main-DTHUta25.js";import{i as t,n,r}from"./room-name-Bv6N672f.js";function i(e,t){if(!e||!t)return;let n=t.find(t=>t.id===e)?.label;return n===void 0?void 0:r(n)}function a(e,t){let n=i(e.machine,t);return n?`${n} · ${e.name}`:e.name}function o(e,n,r,i){let o=i?.machine??(e?t(e)?.machine:void 0);return a({name:i?.name??n,machine:o},r)}function s(e,t,n){return o(t,n,e.store.snapshot?.machines,t?e.agent(t):void 0)}function c(t,i){let a=t.custom&&t.id?n({...t,id:t.id}):t.name,o=t.machine?i?.find(e=>e.id===t.machine):void 0;if(!o)return{text:a,dim:!1};let s=`${r(o.label)} · ${a}`;return o.state===`offline`?{text:s,dim:!0,tag:e(`offline`)}:{text:s,dim:!1}}function l(t,n){let r=t;if(!r||r.partial!==!0)return``;let a=Array.isArray(r.unavailable)?r.unavailable.filter(e=>typeof e==`string`):[];if(!a.length)return e(`Algumas máquinas não responderam agora: a lista pode estar incompleta.`);let o=a.map(e=>i(e,n)??e).join(`, `);return e(`Algumas máquinas não responderam agora ({0}): a lista pode estar incompleta.`,[o])}function u(e,n){let r=t(e);if(!r||!n)return!0;let i=n.find(e=>e.id===r.machine);return!i||!(i.state===`offline`||i.pty&&!i.pty.enabled)}function d(n,r){let i=t(n);if(!i||!r)return{disabled:!1};let a=r.find(e=>e.id===i.machine);return a?a.state===`offline`?{disabled:!0,tooltip:e(`a máquina deste agente está offline`)}:a.pty&&!a.pty.enabled?{disabled:!0,tooltip:a.pty.reason??e(`desligado nesta máquina`)}:{disabled:!1}:{disabled:!1}}var f=(e,t)=>{e.textContent=t};function p(e){f=e}function m(e,t={},...n){let r=document.createElement(e);if(t.class&&(r.className=t.class),t.text!==void 0&&f(r,t.text),t.title&&(e===`iframe`||e===`option`?r.title=t.title:r.setAttribute(`data-tip`,t.title)),t.style&&r.setAttribute(`style`,t.style),t.role&&r.setAttribute(`role`,t.role),t.tabIndex!==void 0&&(r.tabIndex=t.tabIndex),t.hidden&&(r.hidden=!0),t.type&&r.setAttribute(`type`,t.type),t.attrs)for(let[n,i]of Object.entries(t.attrs))i!==void 0&&i!==!1&&(n===`title`&&e!==`iframe`&&e!==`option`?r.setAttribute(`data-tip`,i===!0?``:String(i)):r.setAttribute(n,i===!0?``:String(i)));if(t.on)for(let[e,n]of Object.entries(t.on))r.addEventListener(e,n);for(let e of n)e!=null&&e!==!1&&r.append(e);return r}function h(e,t,n,r=``){let i=m(`button`,{class:`ui-icon-btn ${r}`.trim(),type:`button`,title:t,attrs:{"aria-label":t},on:{click:n}});return i.innerHTML=e,i}function g(e,t){let n=typeof document<`u`&&document.documentElement?.clientWidth||(typeof window<`u`?window.innerWidth:0),r=typeof document<`u`&&document.documentElement?.clientHeight||(typeof window<`u`?window.innerHeight:0);e.style&&(e.style.left=`${Math.max(8,t.x)}px`,e.style.top=`${Math.max(8,t.y)}px`),e.showPopover?.();let i=e.getBoundingClientRect?.()??{width:0,height:0};e.style&&(e.style.left=`${Math.max(8,Math.min(t.x,n-i.width-8))}px`,e.style.top=`${Math.max(8,Math.min(t.y,r-i.height-8))}px`)}function _(e,t){e.textContent!==t&&f(e,t)}function v(e,t,n){n==null?e.hasAttribute(t)&&e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function y(e,t){if(e){if(e.tagName===`IFRAME`||e.tagName===`OPTION`){e.title!==t&&(e.title=t);return}typeof e.getAttribute==`function`&&(t?e.getAttribute(`data-tip`)!==t&&typeof e.setAttribute==`function`&&e.setAttribute(`data-tip`,t):e.getAttribute(`data-tip`)!==null&&typeof e.removeAttribute==`function`&&e.removeAttribute(`data-tip`),e.getAttribute(`title`)!==null&&typeof e.removeAttribute==`function`&&e.removeAttribute(`title`)),`title`in e&&e.title&&(e.title=``)}}function b(e,t,n){e.style.getPropertyValue(t)!==n&&e.style.setProperty(t,n)}function x(e,t){e.hidden!==t&&(e.hidden=t)}function S(e,t,n){let r=`__variant_${t}`,i=e,a=i[r];a!==n&&(a&&e.classList.remove(`${t}${a}`),e.classList.add(`${t}${n}`),i[r]=n)}function C(){return typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function w(e,t,n=260){if(C()||typeof e.animate!=`function`||!e.isConnected){t();return}let r=e.offsetHeight;e.style.overflow=`hidden`,e.style.pointerEvents=`none`;let i=e.animate([{opacity:1,height:`${r}px`,transform:`translateX(0)`},{opacity:0,height:`${r}px`,transform:`translateX(-10px)`,offset:.55},{opacity:0,height:`0px`,marginTop:`0px`,marginBottom:`0px`,paddingTop:`0px`,paddingBottom:`0px`,transform:`translateX(-10px)`}],{duration:n,easing:`cubic-bezier(.4,0,.2,1)`,fill:`forwards`});i.onfinish=t,i.oncancel=t}function T(e){C()||(e.classList.add(`is-entering`),e.addEventListener(`animationend`,()=>e.classList.remove(`is-entering`),{once:!0}))}var E=class{container;opts;nodes=new Map;leaving=new Map;initialized=!1;constructor(e,t){this.container=e,this.opts=t}get size(){return this.nodes.size}get(e){return this.nodes.get(e)}keys(){return this.nodes.keys()}sync(e){let t=this.opts.animate!==!1&&this.initialized,n=new Set,r=new Set(e.map(e=>this.opts.key(e))),i=this.container.firstChild,a=()=>{for(;i&&(this.isLeaving(i)||!r.has(i.dataset?.key??``));)i=i.nextSibling};for(let r of e){let e=this.opts.key(r);if(n.has(e))continue;n.add(e);let o=this.nodes.get(e);if(!o){let n=this.leaving.get(e);n&&(n.getAnimations?.().forEach(e=>e.cancel()),n.remove(),this.leaving.delete(e)),o=this.opts.create(r),o.dataset.key=e,this.nodes.set(e,o),t&&T(o)}this.opts.update(o,r),a(),i===o?i=o.nextSibling:this.container.insertBefore(o,i)}for(let[e,r]of this.nodes)if(!n.has(e)){if(this.nodes.delete(e),!t){r.remove();continue}this.leaving.set(e,r),r.classList.add(`is-leaving`),w(r,()=>{this.leaving.get(e)===r&&this.leaving.delete(e),r.remove()})}this.initialized=!0}clear(){for(let e of this.nodes.values())e.remove();for(let e of this.leaving.values())e.remove();this.nodes.clear(),this.leaving.clear(),this.initialized=!1}isLeaving(e){return e instanceof HTMLElement&&e.classList.contains(`is-leaving`)}};function D(e){return typeof e?.clipboard?.writeText==`function`?`api-then-legacy`:`legacy`}async function O(e){if(D(typeof navigator>`u`?void 0:navigator)===`api-then-legacy`)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=m(`textarea`,{style:`position:fixed;opacity:0;pointer-events:none`});t.value=e;let n=document.activeElement instanceof HTMLElement?document.activeElement:null;(n?.closest(`dialog[open]`)??document.body).append(t),t.select();let r=!1;try{r=document.execCommand(`copy`)}catch{r=!1}return t.remove(),n?.focus(),r}export{o as _,C as a,d as b,b as c,y as d,S as f,s as g,u as h,h as i,_ as l,a as m,O as n,v as o,g as p,m as r,x as s,E as t,p as u,l as v,c as y};