octiqflow-linux-x64 0.3.33 → 0.3.35

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 (84) hide show
  1. package/bin/octiq-server +0 -0
  2. package/bin/v2/assets/{DiskPage-BHQ6vXWD.js → DiskPage-BhNnWXN4.js} +1 -1
  3. package/bin/v2/assets/DiskPage-BhNnWXN4.js.br +0 -0
  4. package/bin/v2/assets/DiskPage-BhNnWXN4.js.gz +0 -0
  5. package/bin/v2/assets/{IslandPage-Qq4QwLeF.js → IslandPage-GKoyJnW-.js} +1 -1
  6. package/bin/v2/assets/IslandPage-GKoyJnW-.js.br +0 -0
  7. package/bin/v2/assets/IslandPage-GKoyJnW-.js.gz +0 -0
  8. package/bin/v2/assets/{index-v7xV5kGw.js → index-8XtBp6iQ.js} +1 -1
  9. package/bin/v2/assets/index-8XtBp6iQ.js.br +0 -0
  10. package/bin/v2/assets/index-8XtBp6iQ.js.gz +0 -0
  11. package/bin/v2/assets/index-B3VCMQ9C.css +1 -0
  12. package/bin/v2/assets/index-B3VCMQ9C.css.br +0 -0
  13. package/bin/v2/assets/index-B3VCMQ9C.css.gz +0 -0
  14. package/bin/v2/assets/{index-cShCsMR4.js → index-B9H8pdFR.js} +1 -1
  15. package/bin/v2/assets/index-B9H8pdFR.js.br +0 -0
  16. package/bin/v2/assets/index-B9H8pdFR.js.gz +0 -0
  17. package/bin/v2/assets/{index-BtMUb1SW.js → index-BA8UQyOC.js} +1 -1
  18. package/bin/v2/assets/index-BA8UQyOC.js.br +0 -0
  19. package/bin/v2/assets/index-BA8UQyOC.js.gz +0 -0
  20. package/bin/v2/assets/{index-Brzuk1-3.js → index-BAPvmkfk.js} +1 -1
  21. package/bin/v2/assets/index-BAPvmkfk.js.br +0 -0
  22. package/bin/v2/assets/index-BAPvmkfk.js.gz +0 -0
  23. package/bin/v2/assets/{index-CzmdQnci.js → index-BaadIo09.js} +158 -158
  24. package/bin/v2/assets/index-BaadIo09.js.br +0 -0
  25. package/bin/v2/assets/index-BaadIo09.js.gz +0 -0
  26. package/bin/v2/assets/{index-DkCVJgWk.js → index-BrqVc_Lg.js} +1 -1
  27. package/bin/v2/assets/index-BrqVc_Lg.js.br +0 -0
  28. package/bin/v2/assets/index-BrqVc_Lg.js.gz +0 -0
  29. package/bin/v2/assets/{index-BEWqNsHw.js → index-Cob488jf.js} +1 -1
  30. package/bin/v2/assets/index-Cob488jf.js.br +0 -0
  31. package/bin/v2/assets/index-Cob488jf.js.gz +0 -0
  32. package/bin/v2/assets/{index-s-iKxzP8.js → index-DKRpiiKJ.js} +1 -1
  33. package/bin/v2/assets/index-DKRpiiKJ.js.br +0 -0
  34. package/bin/v2/assets/index-DKRpiiKJ.js.gz +0 -0
  35. package/bin/v2/assets/{index-Co3uxkEw.js → index-DPfJb017.js} +1 -1
  36. package/bin/v2/assets/index-DPfJb017.js.br +0 -0
  37. package/bin/v2/assets/index-DPfJb017.js.gz +0 -0
  38. package/bin/v2/assets/{index-DgipX4Jo.js → index-Dnd3lUIX.js} +1 -1
  39. package/bin/v2/assets/index-Dnd3lUIX.js.br +0 -0
  40. package/bin/v2/assets/index-Dnd3lUIX.js.gz +0 -0
  41. package/bin/v2/assets/{index-B3M2dqjT.js → index-DziHw0fD.js} +1 -1
  42. package/bin/v2/assets/index-DziHw0fD.js.br +0 -0
  43. package/bin/v2/assets/index-DziHw0fD.js.gz +0 -0
  44. package/bin/v2/assets/{index-Dcyibowf.js → index-KP3MSK6M.js} +1 -1
  45. package/bin/v2/assets/index-KP3MSK6M.js.br +0 -0
  46. package/bin/v2/assets/index-KP3MSK6M.js.gz +0 -0
  47. package/bin/v2/assets/{portrait-DEXFdiVX.js → portrait-D9FZaYW3.js} +1 -1
  48. package/bin/v2/assets/portrait-D9FZaYW3.js.br +0 -0
  49. package/bin/v2/assets/portrait-D9FZaYW3.js.gz +0 -0
  50. package/bin/v2/index.html +2 -2
  51. package/package.json +1 -1
  52. package/bin/v2/assets/DiskPage-BHQ6vXWD.js.br +0 -0
  53. package/bin/v2/assets/DiskPage-BHQ6vXWD.js.gz +0 -0
  54. package/bin/v2/assets/IslandPage-Qq4QwLeF.js.br +0 -0
  55. package/bin/v2/assets/IslandPage-Qq4QwLeF.js.gz +0 -0
  56. package/bin/v2/assets/index-B3M2dqjT.js.br +0 -0
  57. package/bin/v2/assets/index-B3M2dqjT.js.gz +0 -0
  58. package/bin/v2/assets/index-BEWqNsHw.js.br +0 -0
  59. package/bin/v2/assets/index-BEWqNsHw.js.gz +0 -0
  60. package/bin/v2/assets/index-Brzuk1-3.js.br +0 -0
  61. package/bin/v2/assets/index-Brzuk1-3.js.gz +0 -0
  62. package/bin/v2/assets/index-BtMUb1SW.js.br +0 -0
  63. package/bin/v2/assets/index-BtMUb1SW.js.gz +0 -0
  64. package/bin/v2/assets/index-Co3uxkEw.js.br +0 -0
  65. package/bin/v2/assets/index-Co3uxkEw.js.gz +0 -0
  66. package/bin/v2/assets/index-CzmdQnci.js.br +0 -0
  67. package/bin/v2/assets/index-CzmdQnci.js.gz +0 -0
  68. package/bin/v2/assets/index-DWMHLBXe.css +0 -1
  69. package/bin/v2/assets/index-DWMHLBXe.css.br +0 -0
  70. package/bin/v2/assets/index-DWMHLBXe.css.gz +0 -0
  71. package/bin/v2/assets/index-Dcyibowf.js.br +0 -0
  72. package/bin/v2/assets/index-Dcyibowf.js.gz +0 -0
  73. package/bin/v2/assets/index-DgipX4Jo.js.br +0 -0
  74. package/bin/v2/assets/index-DgipX4Jo.js.gz +0 -0
  75. package/bin/v2/assets/index-DkCVJgWk.js.br +0 -0
  76. package/bin/v2/assets/index-DkCVJgWk.js.gz +0 -0
  77. package/bin/v2/assets/index-cShCsMR4.js.br +0 -0
  78. package/bin/v2/assets/index-cShCsMR4.js.gz +0 -0
  79. package/bin/v2/assets/index-s-iKxzP8.js.br +0 -0
  80. package/bin/v2/assets/index-s-iKxzP8.js.gz +0 -0
  81. package/bin/v2/assets/index-v7xV5kGw.js.br +0 -0
  82. package/bin/v2/assets/index-v7xV5kGw.js.gz +0 -0
  83. package/bin/v2/assets/portrait-DEXFdiVX.js.br +0 -0
  84. package/bin/v2/assets/portrait-DEXFdiVX.js.gz +0 -0
package/bin/octiq-server CHANGED
Binary file
@@ -1,2 +1,2 @@
1
- import{r as k,b as A,l as s,W as re,m as ee,F as se,n as te}from"./index-CzmdQnci.js";const U=e=>e&&typeof e=="object"?e:{},N=(e,t="")=>typeof e=="string"?e:t,z=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,W=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:null;function oe(e){const t=U(e);if(!N(t.scanId))return null;const u=new Set,h=(Array.isArray(t.items)?t.items:[]).flatMap(r=>{const l=U(r),x=N(l.id);if(!x||u.has(x))return[];u.add(x);const m=l.worktree?U(l.worktree):null;return[{id:x,key:N(l.key,x),group:l.group==="clean"||l.group==="review"?l.group:"work",kind:N(l.kind),label:N(l.label,N(l.kind,"Folder")),path:N(l.path),bytes:z(l.bytes),effect:N(l.effect),note:N(l.note),notRecommended:l.notRecommended===!0,action:["tool","docker","worktree","rm","rmOlderThan"].includes(N(U(l.action).type))?l.action:null,previousBytes:W(l.previousBytes),grew:l.grew===!0,worktree:m?{repo:N(m.repo),branch:N(m.branch),clean:typeof m.clean=="boolean"?m.clean:void 0,merged:typeof m.merged=="boolean"?m.merged:void 0,mainline:typeof m.mainline=="boolean"?m.mainline:void 0,inUse:typeof m.inUse=="boolean"?m.inUse:void 0,eligible:typeof m.eligible=="boolean"?m.eligible:void 0,idleDays:W(m.idleDays)??void 0,ignoredBytes:z(m.ignoredBytes)}:void 0}]});return{scanId:N(t.scanId),scannedAt:z(t.scannedAt),platform:t.platform==="macos"||t.platform==="windows"||t.platform==="linux"?t.platform:"unknown",home:N(t.home),thresholdBytes:z(t.thresholdBytes),totalBytes:W(t.totalBytes)??h.reduce((r,l)=>r+l.bytes,0),items:h,skipped:(Array.isArray(t.skipped)?t.skipped:[]).map(r=>{const l=U(r);return{path:N(l.path),reason:N(l.reason,"Unknown reason")}}),previousScanAt:W(t.previousScanAt)}}function ne(e){const t=U(e);return N(t.scanId)?{scanId:N(t.scanId),startedAt:z(t.startedAt),phase:N(t.phase,"home"),entries:z(t.entries),bytes:z(t.bytes),path:N(t.path)}:null}function ce(e){const t=U(e);return{running:ne(t.running),report:oe(t.report)}}function de(e,t){return e.filter(u=>u.group===t).sort((u,h)=>h.bytes-u.bytes)}function L(e){return e.group!=="work"&&e.action!==null}function ue(e,t){const u=new Set(e),h=t.filter(L),r=h.every(l=>e.has(l.id));return h.forEach(l=>r?u.delete(l.id):u.add(l.id)),u}function he(e,t,u){const h=e.filter(r=>L(r)&&t.has(r.id));return{ids:h.map(r=>r.id),count:h.length,bytes:h.reduce((r,l)=>r+l.bytes,0),skippedCount:h.filter(r=>!u&&(!r.action||r.action.type==="rm"||r.action.type==="rmOlderThan")).length}}function B(e){const t=z(e);return t<1e6?`${(t/1e3).toLocaleString("en-US",{maximumFractionDigits:0})} KB`:t<1e9?`${(t/1e6).toLocaleString("en-US",{maximumFractionDigits:1})} MB`:`${(t/1e9).toLocaleString("en-US",{maximumFractionDigits:2})} GB`}function P(e){if(!e)return"an unknown date";const t=new Date(e<1e12?e*1e3:e);return Number.isNaN(t.getTime())?"an unknown date":t.toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"})}const F={clean:"Safe to clean",review:"Review first",work:"Your work"};function q(e,t,u){if(!(t>0&&u>0&&Number.isFinite(t*u)))return[];const h=e.filter(a=>a.bytes>0&&Number.isFinite(a.bytes)),r=h.reduce((a,b)=>Math.max(a,b.bytes),0),l=h.reduce((a,b)=>a+b.bytes/r,0),x=h.map(a=>({id:a.id,area:a.bytes/r/l*t*u})),m=[];let j=0,g=0,p=t,i=u,o=0;const f=(a,b)=>{const w=a.reduce((c,d)=>c+d.area,0),n=a.map(c=>c.area);return Math.max(b*b*Math.max(...n)/(w*w),w*w/(b*b*Math.min(...n)))};for(;o<x.length;){const a=[x[o++]],b=Math.min(p,i);for(;o<x.length&&f([...a,x[o]],b)<=f(a,b);)a.push(x[o++]);const w=a.reduce((y,v)=>y+v.area,0),n=p>=i,c=w/(n?i:p);let d=0;a.forEach((y,v)=>{const R=v===a.length-1?(n?i:p)-d:y.area/c;m.push({id:y.id,x:j+(n?0:d),y:g+(n?d:0),width:n?c:R,height:n?R:c}),d+=R}),n?(j+=c,p=Math.max(0,t-j)):(g+=c,i=Math.max(0,u-g))}return m}function pe(e,t,u=.015){const h=[];for(const r of["clean","review","work"]){const l=new Map;for(const i of e){if(i.group!==r||!(i.bytes>0&&Number.isFinite(i.bytes)))continue;const o=l.get(i.kind)??[];o.push(i),l.set(i.kind,o)}const x=(i,o,f)=>({id:i,group:r,label:o,items:[...f].sort((a,b)=>b.bytes-a.bytes),bytes:f.reduce((a,b)=>a+b.bytes,0),selectedCount:f.filter(a=>L(a)&&t.has(a.id)).length}),m=[...l].map(([i,o])=>{const f=o.length===1?o[0].label:i==="git-worktree"?"Linked Git worktrees":o.every(a=>a.label===o[0].label)?o[0].label:(i.replace(/[-_]/g," ")||"Folders").replace(/^./,a=>a.toUpperCase());return x(JSON.stringify([r,i]),f,o)}),j=m.reduce((i,o)=>i+o.bytes,0),g=m.filter(i=>i.bytes/j<u),p=m.filter(i=>i.bytes/j>=u);g.length&&p.push(x(JSON.stringify([r,null]),"Other",g.flatMap(i=>[...i.items]))),h.push(...p.sort((i,o)=>o.bytes-i.bytes||i.id.localeCompare(o.id)))}return h}const K=(e,t)=>t.bytes-e.bytes||e.id.localeCompare(t.id);function T(e,t,u){return{id:u,label:t,group:e[0].group,bytes:e.reduce((h,r)=>h+r.bytes,0),selectedCount:e.reduce((h,r)=>h+r.selectedCount,0),items:e.flatMap(h=>[...h.items]).sort((h,r)=>r.bytes-h.bytes)}}function me(e,t,u,h){const r=["clean","review","work"].flatMap(g=>{const p=e.filter(i=>i.group===g);return p.length?[T(p,F[g],JSON.stringify([g]))]:[]}),l=(g,p)=>{const i=h(p);return g.width>=i.width&&g.height>=i.height},x=[],m=new Map(r.map(g=>[g.id,e.filter(p=>p.group===g.group).sort(K)]));let j=r;for(;;){const g=q(j,t,u),p=[];let i=!1;for(const o of j){const f=g.find(d=>d.id===o.id);if(!f||!l(f,o)){x.push(o),m.delete(o.id),i=!0;continue}let a=m.get(o.id);const b=q(a,f.width,f.height),w=a.filter(d=>!l(b.find(y=>y.id===d.id),d));if(!w.length){p.push({box:f,tiles:b.map(d=>({...a.find(y=>y.id===d.id),...d}))});continue}if(i=!0,a.length===1){m.set(o.id,[o]);continue}const n=JSON.stringify([o.group,null]),c=a.find(d=>d.id===n);if(c&&w.every(d=>d===c))x.push(c),a=a.filter(d=>d!==c);else{const d=a.filter(v=>v!==c).at(-1);a=a.filter(v=>v!==d&&v!==c);const y=x.findIndex(v=>v.id===n);y>=0?x[y]=T([d,x[y]],"Other",n):(a.push(T(c?[d,c]:[d],"Other",n)),a.sort(K)),a.length===1&&(a=[T(a,o.label,o.id)])}m.set(o.id,a)}if(!i)return{regions:p,summaries:x};j=j.filter(o=>m.has(o.id)).map(o=>T(m.get(o.id),o.label,o.id))}}const V=e=>String(e?.message??e);function fe(e){const[t,u]=k.useState({running:null,report:null}),[h,r]=k.useState(null),[l,x]=k.useState(!1),[m,j]=k.useState(!0),g=k.useRef(0),p=k.useRef(!1),i=k.useRef(t),o=k.useRef(new Set),f=k.useCallback(w=>{i.current=w,u(w)},[]),a=k.useCallback(async()=>{const w=++g.current;try{const n=await A.invoke("disk_scan_state",{});if(!p.current||w!==g.current)return;const c=ce(n);c.running&&o.current.has(c.running.scanId)&&(c.running=null),f(c),r(null)}catch(n){p.current&&w===g.current&&r(V(n))}finally{p.current&&w===g.current&&j(!1)}},[f]);k.useEffect(()=>(p.current=!0,()=>{p.current=!1,++g.current}),[]),k.useEffect(()=>{if(!e){j(!1);return}const w=A.on("disk-scan-progress",c=>{const d=ne(c);!d||o.current.has(d.scanId)||i.current.running&&i.current.running.scanId!==d.scanId||(++g.current,f({...i.current,running:d}),j(!1))}),n=A.on("disk-scan-done",c=>{c?.scanId&&(o.current.add(c.scanId),i.current.running?.scanId===c.scanId&&f({...i.current,running:null}),a().then(()=>{p.current&&c.error&&r(String(c.error))}))});return a(),()=>{w(),n(),++g.current}},[e,a,f]);const b=k.useCallback(async()=>{if(!e||l)return;x(!0),r(null);const w=i.current.running;try{await A.invoke(w?"disk_scan_cancel":"disk_scan_start",w?{scanId:w.scanId}:{}),p.current&&await a()}catch(n){p.current&&r(V(n))}finally{p.current&&x(!1)}},[e,l,a]);return{...t,error:h,pending:l,loading:m,scan:b}}function Se({connected:e,onClose:t}){const u=fe(e);return s.jsx(ke,{...u,connected:e,onScan:()=>{u.scan()},onClose:t})}const ge=[],Q=new Set;function ke({report:e,running:t=null,error:u,pending:h=!1,loading:r=!1,connected:l=!0,onScan:x,onClose:m}){const[j,g]=k.useState({scanId:"",ids:Q}),[p,i]=k.useState(null),o=!!e&&p===e.scanId,[f,a]=k.useState(null),[b,w]=k.useState(null),[n,c]=k.useState(!1),d=k.useRef(e?.scanId);d.current=e?.scanId;const y=k.useRef(!0);k.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]),k.useEffect(()=>{a(null),w(null)},[e?.scanId]);const v=k.useRef(new Map),R=e?.items??ge,M=j.scanId===e?.scanId?j.ids:Q,D=he(R,M,o),G=S=>{e&&g({scanId:e.scanId,ids:S})},[Y,J]=k.useState(null),O=Y?.scanId===e?.scanId?Y:null,ae=S=>{J({scanId:e.scanId,ids:new Set(S.items.map(E=>E.id)),label:S.label});const I=v.current.get(S.items[0].id);I?.scrollIntoView({block:"center",behavior:"instant"}),I?.focus({preventScroll:!0})},_=l?t?"Wait for the scan to finish before downloading a script.":D.count?null:"Select at least one item to download a script.":"Connect to the host to download a script.",le=async()=>{if(!e||_||n)return;const S=e.scanId;c(!0),w(null);try{const I=await A.invoke("disk_cleanup_script",{scanId:S,itemIds:D.ids,allowRm:o});if(!y.current||d.current!==S)return;if(typeof I?.script!="string"||typeof I?.fileName!="string"||!I.fileName)throw new Error("The host did not return a cleanup script.");const E=I.fileName.split(/[\\/]/).pop()||(e.platform==="windows"?"disk-cleanup.ps1":"disk-cleanup.sh"),$=URL.createObjectURL(new Blob([I.script],{type:"text/plain;charset=utf-8"})),C=document.createElement("a");C.href=$,C.download=E,document.body.append(C),C.click(),C.remove(),window.setTimeout(()=>URL.revokeObjectURL($),1e3),a({scanId:S,fileName:E})}catch(I){y.current&&d.current===S&&w(String(I?.message??I))}finally{y.current&&c(!1)}},H=f?.scanId===e?.scanId?f?.fileName:e?.platform==="windows"?"disk-cleanup.ps1":"disk-cleanup.sh";return s.jsxs("section",{className:"disk-page","aria-label":"Disk report",children:[s.jsx(re,{root:!0,title:s.jsx("h1",{children:"Disk"}),back:{label:"Chat",onClick:m},actions:s.jsx("button",{className:`disk-button${t?" is-scanning":""}`,type:"button",disabled:!l||h||r,onClick:x,children:h?t?"Cancelling…":"Starting…":t?"Cancel scan":"Scan"})}),s.jsxs("div",{className:"disk-body",children:[s.jsxs("div",{className:"disk-intro",children:[s.jsxs("div",{children:[s.jsx("h2",{children:"Development leftovers"}),s.jsx("p",{children:"Manual scans of your home folder and system temp. Metadata, Git and open-file checks only."})]}),e&&s.jsxs("div",{className:"disk-total",children:[s.jsx("strong",{children:B(e.totalBytes)}),s.jsxs("span",{children:[e.platform==="macos"?"macOS":e.platform==="windows"?"Windows":e.platform==="linux"?"Linux":"Unknown platform"," · Last scanned ",P(e.scannedAt)]})]})]}),s.jsx("p",{className:"disk-promise",children:"OctiqFlow never deletes anything. You choose items, download a cleanup script and run it yourself."}),!l&&s.jsx("p",{className:"disk-message",role:"status",children:"Connect to the host to scan."}),u&&s.jsx("p",{className:"disk-error",role:"alert",children:u}),t&&s.jsxs("div",{className:"disk-progress",role:"status",children:[s.jsx("span",{className:"disk-progress-mark","aria-hidden":"true"}),s.jsxs("span",{children:["Scanning ",be(t.phase)," · ",t.entries.toLocaleString("en-US")," entries · ",B(t.bytes)," counted"]})]}),r&&!e&&s.jsx("p",{className:"disk-message",children:"Reading the last report…"}),!e&&!r&&s.jsxs("div",{className:"disk-empty",children:[s.jsx("h2",{children:"No scan yet"}),s.jsx("p",{children:"Scan when you want to review large development leftovers. Nothing is selected automatically."})]}),e&&s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"disk-threshold",children:["Items ≥ ",B(e.thresholdBytes)," · Size history: ",s.jsx("code",{children:"~/disk-report/sizes.csv"}),e.previousScanAt?` · Compared with ${P(e.previousScanAt)}`:" · First recorded scan"]}),s.jsxs("div",{className:"disk-layout",children:[s.jsxs("div",{className:"disk-map-column",children:[s.jsx(xe,{items:R,selected:M,onFocus:ae}),s.jsx("p",{className:"disk-map-help",children:"Area represents size. Choose a cleanup tile to highlight its rows. Your work is labelled only."})]}),s.jsxs("div",{className:"disk-list-column",children:[O&&s.jsxs("div",{className:"disk-found",role:"status",children:[O.label," · ",O.ids.size," ",O.ids.size===1?"row":"rows"," highlighted ",s.jsx("button",{type:"button",onClick:()=>J(null),children:"Clear highlight"})]}),["clean","review"].map(S=>{const I=de(R,S),E=I.filter(L);return s.jsxs("section",{className:`disk-section disk-${S}`,"aria-label":F[S],children:[s.jsxs("div",{className:"disk-section-heading",children:[s.jsxs("h2",{children:[F[S]," ",s.jsx("span",{children:I.length})]}),s.jsxs("label",{className:"disk-tick-all",children:[s.jsx("input",{type:"checkbox",checked:E.length>0&&E.every($=>M.has($.id)),disabled:!E.length,onChange:()=>G(ue(M,I))}),"Select all",s.jsxs("span",{className:"sr-only",children:[" ",F[S]]})]})]}),!I.length&&s.jsx("p",{className:"disk-message",children:"No items in this section."}),I.map($=>s.jsx(ye,{item:$,highlighted:O?.ids.has($.id),previousScanAt:e.previousScanAt,checked:M.has($.id),onTick:()=>{if(!L($))return;const C=new Set(M);C.has($.id)?C.delete($.id):C.add($.id),G(C)},rowRef:C=>{C?v.current.set($.id,C):v.current.delete($.id)}},`${e.scanId}:${$.id}`))]},S)}),s.jsx(ve,{report:e}),s.jsxs("section",{className:"disk-controls","aria-label":"Cleanup script",children:[s.jsxs("label",{className:"disk-rm-switch",children:[s.jsx("input",{type:"checkbox",role:"switch",checked:o,onChange:S=>i(S.target.checked?e.scanId:null)}),s.jsx("span",{children:"Use rm -rf for items with no tool command"})]}),s.jsx("p",{children:o?e.platform==="windows"?"The script can use PowerShell Remove-Item for these items.":"The script can use rm -rf for these items.":"Items with no tool command are printed as Skipped."}),s.jsxs("div",{className:"disk-download-row",children:[s.jsxs("strong",{children:[D.count," selected · ",B(D.bytes)]}),s.jsx("button",{className:"disk-button",type:"button",disabled:!!_||n,"aria-describedby":"disk-download-reason",onClick:()=>{le()},children:n?"Preparing script…":"Download cleanup script"})]}),D.skippedCount>0&&s.jsxs("p",{children:[D.skippedCount," selected ",D.skippedCount===1?"item will":"items will"," be printed as Skipped."]}),s.jsx("p",{id:"disk-download-reason",children:_??"Review the script before running it."}),b&&s.jsx("p",{className:"disk-error",role:"alert",children:b}),s.jsxs("p",{className:"disk-run-example",children:["Run it in your terminal, for example: ",s.jsx("code",{children:e.platform==="windows"?`powershell -File "$HOME\\Downloads\\${H}"`:`bash ~/Downloads/${H}`})]})]})]})]})]})]})]})}function be(e){return{home:"home folder",temp:"system temp",git:"Git worktrees",history:"size history"}[e]??e}function X(e,t,u){return{left:`${e.x/t*100}%`,top:`${e.y/u*100}%`,width:`${e.width/t*100}%`,height:`${e.height/u*100}%`}}function xe({items:e,selected:t,onFocus:u}){const h=k.useRef(null),[r,l]=k.useState(0),[x,m]=k.useState(null),[j,g]=we();k.useLayoutEffect(()=>{const n=h.current;if(!n)return;l(n.getBoundingClientRect().width);const c=new ResizeObserver(d=>{const y=d[0]?.contentRect.width;y>0&&l(y)});return c.observe(n),()=>c.disconnect()},[]);const p=Math.max(340,Math.min(520,r*1.1)),i=k.useMemo(()=>pe(e,t),[e,t]),o=k.useMemo(()=>["clean","review","work"].map(n=>({id:n,bytes:i.filter(c=>c.group===n).reduce((c,d)=>c+d.bytes,0)})),[i]),f=k.useMemo(()=>j?me(i,r,p,j):{regions:[],summaries:i},[i,r,p,j]),a=[...f.regions.flatMap(n=>n.tiles),...f.summaries],b=a.find(n=>n.id===x),w=(n,c)=>{const d=Z(n),y=!c,v=y?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"disk-tile-label",children:[n.label,n.label==="Other"?` in ${F[n.group]}`:""," · ",n.items.length," ",n.items.length===1?"item":"items"]}),s.jsx("span",{className:"disk-tile-size",children:ie(n)})]}):s.jsx(je,{entry:n}),R=`${d}
1
+ import{r as k,b as A,l as s,W as re,m as ee,F as se,n as te}from"./index-BaadIo09.js";const U=e=>e&&typeof e=="object"?e:{},N=(e,t="")=>typeof e=="string"?e:t,z=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,W=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:null;function oe(e){const t=U(e);if(!N(t.scanId))return null;const u=new Set,h=(Array.isArray(t.items)?t.items:[]).flatMap(r=>{const l=U(r),x=N(l.id);if(!x||u.has(x))return[];u.add(x);const m=l.worktree?U(l.worktree):null;return[{id:x,key:N(l.key,x),group:l.group==="clean"||l.group==="review"?l.group:"work",kind:N(l.kind),label:N(l.label,N(l.kind,"Folder")),path:N(l.path),bytes:z(l.bytes),effect:N(l.effect),note:N(l.note),notRecommended:l.notRecommended===!0,action:["tool","docker","worktree","rm","rmOlderThan"].includes(N(U(l.action).type))?l.action:null,previousBytes:W(l.previousBytes),grew:l.grew===!0,worktree:m?{repo:N(m.repo),branch:N(m.branch),clean:typeof m.clean=="boolean"?m.clean:void 0,merged:typeof m.merged=="boolean"?m.merged:void 0,mainline:typeof m.mainline=="boolean"?m.mainline:void 0,inUse:typeof m.inUse=="boolean"?m.inUse:void 0,eligible:typeof m.eligible=="boolean"?m.eligible:void 0,idleDays:W(m.idleDays)??void 0,ignoredBytes:z(m.ignoredBytes)}:void 0}]});return{scanId:N(t.scanId),scannedAt:z(t.scannedAt),platform:t.platform==="macos"||t.platform==="windows"||t.platform==="linux"?t.platform:"unknown",home:N(t.home),thresholdBytes:z(t.thresholdBytes),totalBytes:W(t.totalBytes)??h.reduce((r,l)=>r+l.bytes,0),items:h,skipped:(Array.isArray(t.skipped)?t.skipped:[]).map(r=>{const l=U(r);return{path:N(l.path),reason:N(l.reason,"Unknown reason")}}),previousScanAt:W(t.previousScanAt)}}function ne(e){const t=U(e);return N(t.scanId)?{scanId:N(t.scanId),startedAt:z(t.startedAt),phase:N(t.phase,"home"),entries:z(t.entries),bytes:z(t.bytes),path:N(t.path)}:null}function ce(e){const t=U(e);return{running:ne(t.running),report:oe(t.report)}}function de(e,t){return e.filter(u=>u.group===t).sort((u,h)=>h.bytes-u.bytes)}function L(e){return e.group!=="work"&&e.action!==null}function ue(e,t){const u=new Set(e),h=t.filter(L),r=h.every(l=>e.has(l.id));return h.forEach(l=>r?u.delete(l.id):u.add(l.id)),u}function he(e,t,u){const h=e.filter(r=>L(r)&&t.has(r.id));return{ids:h.map(r=>r.id),count:h.length,bytes:h.reduce((r,l)=>r+l.bytes,0),skippedCount:h.filter(r=>!u&&(!r.action||r.action.type==="rm"||r.action.type==="rmOlderThan")).length}}function B(e){const t=z(e);return t<1e6?`${(t/1e3).toLocaleString("en-US",{maximumFractionDigits:0})} KB`:t<1e9?`${(t/1e6).toLocaleString("en-US",{maximumFractionDigits:1})} MB`:`${(t/1e9).toLocaleString("en-US",{maximumFractionDigits:2})} GB`}function P(e){if(!e)return"an unknown date";const t=new Date(e<1e12?e*1e3:e);return Number.isNaN(t.getTime())?"an unknown date":t.toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"})}const F={clean:"Safe to clean",review:"Review first",work:"Your work"};function q(e,t,u){if(!(t>0&&u>0&&Number.isFinite(t*u)))return[];const h=e.filter(a=>a.bytes>0&&Number.isFinite(a.bytes)),r=h.reduce((a,b)=>Math.max(a,b.bytes),0),l=h.reduce((a,b)=>a+b.bytes/r,0),x=h.map(a=>({id:a.id,area:a.bytes/r/l*t*u})),m=[];let j=0,g=0,p=t,i=u,o=0;const f=(a,b)=>{const w=a.reduce((c,d)=>c+d.area,0),n=a.map(c=>c.area);return Math.max(b*b*Math.max(...n)/(w*w),w*w/(b*b*Math.min(...n)))};for(;o<x.length;){const a=[x[o++]],b=Math.min(p,i);for(;o<x.length&&f([...a,x[o]],b)<=f(a,b);)a.push(x[o++]);const w=a.reduce((y,v)=>y+v.area,0),n=p>=i,c=w/(n?i:p);let d=0;a.forEach((y,v)=>{const R=v===a.length-1?(n?i:p)-d:y.area/c;m.push({id:y.id,x:j+(n?0:d),y:g+(n?d:0),width:n?c:R,height:n?R:c}),d+=R}),n?(j+=c,p=Math.max(0,t-j)):(g+=c,i=Math.max(0,u-g))}return m}function pe(e,t,u=.015){const h=[];for(const r of["clean","review","work"]){const l=new Map;for(const i of e){if(i.group!==r||!(i.bytes>0&&Number.isFinite(i.bytes)))continue;const o=l.get(i.kind)??[];o.push(i),l.set(i.kind,o)}const x=(i,o,f)=>({id:i,group:r,label:o,items:[...f].sort((a,b)=>b.bytes-a.bytes),bytes:f.reduce((a,b)=>a+b.bytes,0),selectedCount:f.filter(a=>L(a)&&t.has(a.id)).length}),m=[...l].map(([i,o])=>{const f=o.length===1?o[0].label:i==="git-worktree"?"Linked Git worktrees":o.every(a=>a.label===o[0].label)?o[0].label:(i.replace(/[-_]/g," ")||"Folders").replace(/^./,a=>a.toUpperCase());return x(JSON.stringify([r,i]),f,o)}),j=m.reduce((i,o)=>i+o.bytes,0),g=m.filter(i=>i.bytes/j<u),p=m.filter(i=>i.bytes/j>=u);g.length&&p.push(x(JSON.stringify([r,null]),"Other",g.flatMap(i=>[...i.items]))),h.push(...p.sort((i,o)=>o.bytes-i.bytes||i.id.localeCompare(o.id)))}return h}const K=(e,t)=>t.bytes-e.bytes||e.id.localeCompare(t.id);function T(e,t,u){return{id:u,label:t,group:e[0].group,bytes:e.reduce((h,r)=>h+r.bytes,0),selectedCount:e.reduce((h,r)=>h+r.selectedCount,0),items:e.flatMap(h=>[...h.items]).sort((h,r)=>r.bytes-h.bytes)}}function me(e,t,u,h){const r=["clean","review","work"].flatMap(g=>{const p=e.filter(i=>i.group===g);return p.length?[T(p,F[g],JSON.stringify([g]))]:[]}),l=(g,p)=>{const i=h(p);return g.width>=i.width&&g.height>=i.height},x=[],m=new Map(r.map(g=>[g.id,e.filter(p=>p.group===g.group).sort(K)]));let j=r;for(;;){const g=q(j,t,u),p=[];let i=!1;for(const o of j){const f=g.find(d=>d.id===o.id);if(!f||!l(f,o)){x.push(o),m.delete(o.id),i=!0;continue}let a=m.get(o.id);const b=q(a,f.width,f.height),w=a.filter(d=>!l(b.find(y=>y.id===d.id),d));if(!w.length){p.push({box:f,tiles:b.map(d=>({...a.find(y=>y.id===d.id),...d}))});continue}if(i=!0,a.length===1){m.set(o.id,[o]);continue}const n=JSON.stringify([o.group,null]),c=a.find(d=>d.id===n);if(c&&w.every(d=>d===c))x.push(c),a=a.filter(d=>d!==c);else{const d=a.filter(v=>v!==c).at(-1);a=a.filter(v=>v!==d&&v!==c);const y=x.findIndex(v=>v.id===n);y>=0?x[y]=T([d,x[y]],"Other",n):(a.push(T(c?[d,c]:[d],"Other",n)),a.sort(K)),a.length===1&&(a=[T(a,o.label,o.id)])}m.set(o.id,a)}if(!i)return{regions:p,summaries:x};j=j.filter(o=>m.has(o.id)).map(o=>T(m.get(o.id),o.label,o.id))}}const V=e=>String(e?.message??e);function fe(e){const[t,u]=k.useState({running:null,report:null}),[h,r]=k.useState(null),[l,x]=k.useState(!1),[m,j]=k.useState(!0),g=k.useRef(0),p=k.useRef(!1),i=k.useRef(t),o=k.useRef(new Set),f=k.useCallback(w=>{i.current=w,u(w)},[]),a=k.useCallback(async()=>{const w=++g.current;try{const n=await A.invoke("disk_scan_state",{});if(!p.current||w!==g.current)return;const c=ce(n);c.running&&o.current.has(c.running.scanId)&&(c.running=null),f(c),r(null)}catch(n){p.current&&w===g.current&&r(V(n))}finally{p.current&&w===g.current&&j(!1)}},[f]);k.useEffect(()=>(p.current=!0,()=>{p.current=!1,++g.current}),[]),k.useEffect(()=>{if(!e){j(!1);return}const w=A.on("disk-scan-progress",c=>{const d=ne(c);!d||o.current.has(d.scanId)||i.current.running&&i.current.running.scanId!==d.scanId||(++g.current,f({...i.current,running:d}),j(!1))}),n=A.on("disk-scan-done",c=>{c?.scanId&&(o.current.add(c.scanId),i.current.running?.scanId===c.scanId&&f({...i.current,running:null}),a().then(()=>{p.current&&c.error&&r(String(c.error))}))});return a(),()=>{w(),n(),++g.current}},[e,a,f]);const b=k.useCallback(async()=>{if(!e||l)return;x(!0),r(null);const w=i.current.running;try{await A.invoke(w?"disk_scan_cancel":"disk_scan_start",w?{scanId:w.scanId}:{}),p.current&&await a()}catch(n){p.current&&r(V(n))}finally{p.current&&x(!1)}},[e,l,a]);return{...t,error:h,pending:l,loading:m,scan:b}}function Se({connected:e,onClose:t}){const u=fe(e);return s.jsx(ke,{...u,connected:e,onScan:()=>{u.scan()},onClose:t})}const ge=[],Q=new Set;function ke({report:e,running:t=null,error:u,pending:h=!1,loading:r=!1,connected:l=!0,onScan:x,onClose:m}){const[j,g]=k.useState({scanId:"",ids:Q}),[p,i]=k.useState(null),o=!!e&&p===e.scanId,[f,a]=k.useState(null),[b,w]=k.useState(null),[n,c]=k.useState(!1),d=k.useRef(e?.scanId);d.current=e?.scanId;const y=k.useRef(!0);k.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]),k.useEffect(()=>{a(null),w(null)},[e?.scanId]);const v=k.useRef(new Map),R=e?.items??ge,M=j.scanId===e?.scanId?j.ids:Q,D=he(R,M,o),G=S=>{e&&g({scanId:e.scanId,ids:S})},[Y,J]=k.useState(null),O=Y?.scanId===e?.scanId?Y:null,ae=S=>{J({scanId:e.scanId,ids:new Set(S.items.map(E=>E.id)),label:S.label});const I=v.current.get(S.items[0].id);I?.scrollIntoView({block:"center",behavior:"instant"}),I?.focus({preventScroll:!0})},_=l?t?"Wait for the scan to finish before downloading a script.":D.count?null:"Select at least one item to download a script.":"Connect to the host to download a script.",le=async()=>{if(!e||_||n)return;const S=e.scanId;c(!0),w(null);try{const I=await A.invoke("disk_cleanup_script",{scanId:S,itemIds:D.ids,allowRm:o});if(!y.current||d.current!==S)return;if(typeof I?.script!="string"||typeof I?.fileName!="string"||!I.fileName)throw new Error("The host did not return a cleanup script.");const E=I.fileName.split(/[\\/]/).pop()||(e.platform==="windows"?"disk-cleanup.ps1":"disk-cleanup.sh"),$=URL.createObjectURL(new Blob([I.script],{type:"text/plain;charset=utf-8"})),C=document.createElement("a");C.href=$,C.download=E,document.body.append(C),C.click(),C.remove(),window.setTimeout(()=>URL.revokeObjectURL($),1e3),a({scanId:S,fileName:E})}catch(I){y.current&&d.current===S&&w(String(I?.message??I))}finally{y.current&&c(!1)}},H=f?.scanId===e?.scanId?f?.fileName:e?.platform==="windows"?"disk-cleanup.ps1":"disk-cleanup.sh";return s.jsxs("section",{className:"disk-page","aria-label":"Disk report",children:[s.jsx(re,{root:!0,title:s.jsx("h1",{children:"Disk"}),back:{label:"Chat",onClick:m},actions:s.jsx("button",{className:`disk-button${t?" is-scanning":""}`,type:"button",disabled:!l||h||r,onClick:x,children:h?t?"Cancelling…":"Starting…":t?"Cancel scan":"Scan"})}),s.jsxs("div",{className:"disk-body",children:[s.jsxs("div",{className:"disk-intro",children:[s.jsxs("div",{children:[s.jsx("h2",{children:"Development leftovers"}),s.jsx("p",{children:"Manual scans of your home folder and system temp. Metadata, Git and open-file checks only."})]}),e&&s.jsxs("div",{className:"disk-total",children:[s.jsx("strong",{children:B(e.totalBytes)}),s.jsxs("span",{children:[e.platform==="macos"?"macOS":e.platform==="windows"?"Windows":e.platform==="linux"?"Linux":"Unknown platform"," · Last scanned ",P(e.scannedAt)]})]})]}),s.jsx("p",{className:"disk-promise",children:"OctiqFlow never deletes anything. You choose items, download a cleanup script and run it yourself."}),!l&&s.jsx("p",{className:"disk-message",role:"status",children:"Connect to the host to scan."}),u&&s.jsx("p",{className:"disk-error",role:"alert",children:u}),t&&s.jsxs("div",{className:"disk-progress",role:"status",children:[s.jsx("span",{className:"disk-progress-mark","aria-hidden":"true"}),s.jsxs("span",{children:["Scanning ",be(t.phase)," · ",t.entries.toLocaleString("en-US")," entries · ",B(t.bytes)," counted"]})]}),r&&!e&&s.jsx("p",{className:"disk-message",children:"Reading the last report…"}),!e&&!r&&s.jsxs("div",{className:"disk-empty",children:[s.jsx("h2",{children:"No scan yet"}),s.jsx("p",{children:"Scan when you want to review large development leftovers. Nothing is selected automatically."})]}),e&&s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"disk-threshold",children:["Items ≥ ",B(e.thresholdBytes)," · Size history: ",s.jsx("code",{children:"~/disk-report/sizes.csv"}),e.previousScanAt?` · Compared with ${P(e.previousScanAt)}`:" · First recorded scan"]}),s.jsxs("div",{className:"disk-layout",children:[s.jsxs("div",{className:"disk-map-column",children:[s.jsx(xe,{items:R,selected:M,onFocus:ae}),s.jsx("p",{className:"disk-map-help",children:"Area represents size. Choose a cleanup tile to highlight its rows. Your work is labelled only."})]}),s.jsxs("div",{className:"disk-list-column",children:[O&&s.jsxs("div",{className:"disk-found",role:"status",children:[O.label," · ",O.ids.size," ",O.ids.size===1?"row":"rows"," highlighted ",s.jsx("button",{type:"button",onClick:()=>J(null),children:"Clear highlight"})]}),["clean","review"].map(S=>{const I=de(R,S),E=I.filter(L);return s.jsxs("section",{className:`disk-section disk-${S}`,"aria-label":F[S],children:[s.jsxs("div",{className:"disk-section-heading",children:[s.jsxs("h2",{children:[F[S]," ",s.jsx("span",{children:I.length})]}),s.jsxs("label",{className:"disk-tick-all",children:[s.jsx("input",{type:"checkbox",checked:E.length>0&&E.every($=>M.has($.id)),disabled:!E.length,onChange:()=>G(ue(M,I))}),"Select all",s.jsxs("span",{className:"sr-only",children:[" ",F[S]]})]})]}),!I.length&&s.jsx("p",{className:"disk-message",children:"No items in this section."}),I.map($=>s.jsx(ye,{item:$,highlighted:O?.ids.has($.id),previousScanAt:e.previousScanAt,checked:M.has($.id),onTick:()=>{if(!L($))return;const C=new Set(M);C.has($.id)?C.delete($.id):C.add($.id),G(C)},rowRef:C=>{C?v.current.set($.id,C):v.current.delete($.id)}},`${e.scanId}:${$.id}`))]},S)}),s.jsx(ve,{report:e}),s.jsxs("section",{className:"disk-controls","aria-label":"Cleanup script",children:[s.jsxs("label",{className:"disk-rm-switch",children:[s.jsx("input",{type:"checkbox",role:"switch",checked:o,onChange:S=>i(S.target.checked?e.scanId:null)}),s.jsx("span",{children:"Use rm -rf for items with no tool command"})]}),s.jsx("p",{children:o?e.platform==="windows"?"The script can use PowerShell Remove-Item for these items.":"The script can use rm -rf for these items.":"Items with no tool command are printed as Skipped."}),s.jsxs("div",{className:"disk-download-row",children:[s.jsxs("strong",{children:[D.count," selected · ",B(D.bytes)]}),s.jsx("button",{className:"disk-button",type:"button",disabled:!!_||n,"aria-describedby":"disk-download-reason",onClick:()=>{le()},children:n?"Preparing script…":"Download cleanup script"})]}),D.skippedCount>0&&s.jsxs("p",{children:[D.skippedCount," selected ",D.skippedCount===1?"item will":"items will"," be printed as Skipped."]}),s.jsx("p",{id:"disk-download-reason",children:_??"Review the script before running it."}),b&&s.jsx("p",{className:"disk-error",role:"alert",children:b}),s.jsxs("p",{className:"disk-run-example",children:["Run it in your terminal, for example: ",s.jsx("code",{children:e.platform==="windows"?`powershell -File "$HOME\\Downloads\\${H}"`:`bash ~/Downloads/${H}`})]})]})]})]})]})]})]})}function be(e){return{home:"home folder",temp:"system temp",git:"Git worktrees",history:"size history"}[e]??e}function X(e,t,u){return{left:`${e.x/t*100}%`,top:`${e.y/u*100}%`,width:`${e.width/t*100}%`,height:`${e.height/u*100}%`}}function xe({items:e,selected:t,onFocus:u}){const h=k.useRef(null),[r,l]=k.useState(0),[x,m]=k.useState(null),[j,g]=we();k.useLayoutEffect(()=>{const n=h.current;if(!n)return;l(n.getBoundingClientRect().width);const c=new ResizeObserver(d=>{const y=d[0]?.contentRect.width;y>0&&l(y)});return c.observe(n),()=>c.disconnect()},[]);const p=Math.max(340,Math.min(520,r*1.1)),i=k.useMemo(()=>pe(e,t),[e,t]),o=k.useMemo(()=>["clean","review","work"].map(n=>({id:n,bytes:i.filter(c=>c.group===n).reduce((c,d)=>c+d.bytes,0)})),[i]),f=k.useMemo(()=>j?me(i,r,p,j):{regions:[],summaries:i},[i,r,p,j]),a=[...f.regions.flatMap(n=>n.tiles),...f.summaries],b=a.find(n=>n.id===x),w=(n,c)=>{const d=Z(n),y=!c,v=y?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"disk-tile-label",children:[n.label,n.label==="Other"?` in ${F[n.group]}`:""," · ",n.items.length," ",n.items.length===1?"item":"items"]}),s.jsx("span",{className:"disk-tile-size",children:ie(n)})]}):s.jsx(je,{entry:n}),R=`${d}
2
2
  ${n.items.length===1?n.items[0].path:`${n.items.length} items in ${F[n.group]}`}`,M={onMouseEnter:()=>{h.current?.parentElement?.contains(document.activeElement)||m(n.id)},onFocus:()=>m(n.id)},D=`${y?"disk-map-summary":"disk-tile"} disk-${n.group}${n.group==="work"?" is-work":""}${n.selectedCount?" is-selected":""}`;return n.group==="work"?s.jsx("div",{className:D,style:c,title:R,"aria-label":`${d}. Your work is labelled only.`,tabIndex:0,...M,children:v},n.id):s.jsx("button",{type:"button",className:D,style:c,title:R,"aria-label":`${d}. Find in ${F[n.group]}`,onClick:()=>u(n),...M,children:v},n.id)};return s.jsxs("section",{className:"disk-map-panel","aria-label":"Disk size treemap",children:[s.jsx("h2",{children:"Where the space goes"}),s.jsx("div",{className:"disk-map-legend",children:o.map(n=>s.jsxs("span",{className:`disk-${n.id}`,children:[s.jsx("i",{"aria-hidden":"true"}),F[n.id]," · ",B(n.bytes)]},n.id))}),g,s.jsx("div",{className:"disk-map",ref:h,style:{height:f.regions.length?p:0},children:f.regions.map(({box:n,tiles:c})=>s.jsx("div",{className:`disk-map-region disk-${c[0].group}`,style:X(n,r,p),"aria-label":F[c[0].group],children:c.map(d=>w(d,X(d,n.width,n.height)))},n.id))}),!i.length&&s.jsx("p",{className:"disk-message",children:"No large development leftovers found."}),!!f.summaries.length&&s.jsxs("div",{className:"disk-map-summaries","aria-label":"Groups summarized outside the map",children:[j&&s.jsx("p",{className:"disk-message",children:"Small items are summarized here. Map area represents only the items shown above."}),f.summaries.map(n=>w(n))]}),a.some(n=>n.selectedCount>0)&&s.jsx("p",{className:"disk-map-ticked","aria-live":"polite",children:a.filter(n=>n.selectedCount>0).map(n=>`${n.label} · ${n.selectedCount} ticked`).join("; ")}),s.jsx("div",{className:"disk-map-inspector","aria-live":"polite",children:b?s.jsxs(s.Fragment,{children:[s.jsx("strong",{children:Z(b)}),s.jsx("code",{children:b.items.length===1?b.items[0].path:`${b.items.length} items in ${F[b.group]}${b.group==="work"?" · Your work is labelled only.":" · Choose to highlight their rows."}`})]}):"Hover or focus a tile to see its full name, count and size."})]})}function Z(e){return`${e.label}, ${e.items.length} ${e.items.length===1?"item":"items"}, ${B(e.bytes)}${e.selectedCount?`, ${e.selectedCount} ticked`:""}`}function ie(e){return`${B(e.bytes)}${e.selectedCount?` · ${e.selectedCount} ticked`:""}`}function we(){const e=k.useRef(null),t=k.useRef(null),[u,h]=k.useState(null);return k.useLayoutEffect(()=>{const r=e.current,l=t.current;if(!r||!l)return;let x=!0,m="";const j=()=>{if(!x)return;const p=getComputedStyle(r),i=getComputedStyle(l),o=r.getBoundingClientRect(),f=l.getBoundingClientRect(),a=[p.font,i.font,p.letterSpacing,i.letterSpacing,o.width,o.height,f.width,f.height].join("|");if(a===m)return;m=a;const b=document.createElement("canvas").getContext("2d");if(!b)return;const w=(y,v)=>(b.font=v.font,b.measureText(y).width+(parseFloat(v.letterSpacing)||0)*y.length),n={font:p.font,letterSpacing:p.letterSpacing},c={font:i.font,letterSpacing:i.letterSpacing},d=Math.max(..."0123456789".split("").map(y=>w(y,c)));h(()=>y=>{const v=y.items.filter(L).length,R=w(B(y.bytes),c)+(v?w(" · ticked",c)+String(v).length*d:0),M=w(`${y.label.split(/\s+/)[0].slice(0,10)}…`,n);return{width:Math.ceil(Math.max(R,M))+26,height:Math.ceil(o.height+f.height)+6+26}})},g=new ResizeObserver(j);return g.observe(r),g.observe(l),j(),document.fonts.ready.then(j),()=>{x=!1,g.disconnect()}},[]),[u,s.jsxs("span",{className:"disk-map-probes","aria-hidden":"true",children:[s.jsx("span",{className:"disk-tile-label",ref:e,children:"Overview…"}),s.jsx("span",{className:"disk-tile-size",ref:t,children:"888.8 GB · 888 ticked"})]},"font-probes")]}function je({entry:e}){return s.jsxs("span",{className:"disk-tile-content","data-fit":"full","aria-hidden":"true",children:[s.jsxs("span",{className:"disk-tile-label disk-tile-visible-label",children:[e.label,e.items.length>1?` · ${e.items.length} items`:""]}),s.jsx("span",{className:"disk-tile-size disk-tile-visible-size",children:ie(e)})]})}function ye({item:e,checked:t,highlighted:u,onTick:h,previousScanAt:r,rowRef:l}){const x=ee(e.id),m=k.useId(),j=L(e),g=e.effect.length>200,p=(e.note?.length??0)>200,i=e.worktree,o=i?[{label:"Working tree clean",pass:i.clean},{label:"Merged to mainline",pass:i.merged},{label:"Not a mainline worktree",pass:i.mainline===void 0?void 0:!i.mainline},{label:"Not in use",pass:i.inUse===void 0?void 0:!i.inUse}]:[];return s.jsxs("article",{ref:l,tabIndex:-1,className:`disk-item${t?" is-selected":""}${u?" is-found":""}`,"aria-label":e.label,children:[s.jsxs("div",{className:"disk-item-heading",children:[s.jsxs("label",{children:[s.jsx("input",{type:"checkbox",checked:j&&t,"aria-disabled":!j||void 0,"aria-describedby":!j||e.notRecommended?m:void 0,onChange:()=>{j&&h()}}),s.jsx("strong",{children:e.label})]}),s.jsx("strong",{className:"disk-item-size",children:B(e.bytes)})]}),s.jsx("code",{className:"disk-path",title:e.path,children:e.path}),(!j||e.notRecommended)&&s.jsx("p",{id:m,className:"disk-not-recommended",children:e.notRecommended?"Not recommended to delete":"No safe cleanup command for this item"}),!g&&e.effect&&s.jsx("p",{children:e.effect}),!p&&e.note&&s.jsx("p",{className:"disk-note",children:e.note}),e.grew&&e.previousBytes!==null&&e.bytes>e.previousBytes&&s.jsxs("p",{className:"disk-growth",children:["+",((e.bytes-e.previousBytes)/1e6).toLocaleString("en-US",{maximumFractionDigits:1})," MB since ",P(r)]}),i&&s.jsxs(s.Fragment,{children:[s.jsx("ul",{className:"disk-worktree-facts",children:o.map(f=>s.jsxs("li",{className:f.pass===!0?"is-pass":"is-fail",children:[s.jsx("span",{children:f.pass===!0?"✓ Pass":f.pass===!1?"✕ Fail":"? Unknown"})," ",f.label]},f.label))}),!!i.ignoredBytes&&s.jsxs("p",{className:"disk-not-recommended",children:["Includes ",B(i.ignoredBytes)," of ignored files. Git does not protect these files."]})]}),s.jsx(se,{fold:x,labels:["Full path",g&&`Effect · ${e.effect.length} characters`,p&&`Note · ${e.note.length} characters`,i&&"Worktree details"],what:`details for ${e.label}`}),s.jsxs(te,{fold:x,bounded:!1,children:[s.jsx("code",{className:"disk-full-path",children:e.path}),g&&s.jsx("p",{children:e.effect}),p&&s.jsx("p",{children:e.note}),i&&s.jsxs("p",{children:["Repository: ",s.jsx("code",{children:i.repo||"Unknown"}),s.jsx("br",{}),"Branch: ",s.jsx("code",{children:i.branch||"Unknown"}),s.jsx("br",{}),"Idle: ",i.idleDays??"Unknown"," days · Eligible: ",i.eligible===void 0?"Unknown":i.eligible?"Yes":"No"]})]})]})}function ve({report:e}){const t=ee(`${e.scanId}:skipped`);return s.jsxs("div",{className:"disk-skipped",children:[s.jsx(se,{fold:t,labels:[`${e.skipped.length} folders skipped`],what:"skipped folders"}),s.jsxs(te,{fold:t,bounded:!1,children:[s.jsx("ul",{children:e.skipped.map((u,h)=>s.jsxs("li",{children:[s.jsx("code",{children:u.path}),s.jsx("p",{children:u.reason})]},h))}),!e.skipped.length&&s.jsx("p",{children:"No folders were skipped."})]})]})}export{xe as DiskMap,ke as DiskReportPage,Se as default};
@@ -1,4 +1,4 @@
1
- import{r as I,b as qe,a as Mt,T as Re,c as Ve,d as Is,p as Ce,e as ce,C as Pe,o as Lt,f as gs,P as wt,g as Os,S as Ht,h as Ws,u as $s,i as Us,j as Bs,k as Fs,w as Et,l as x,W as Gs,A as Ks}from"./index-CzmdQnci.js";import{G as he,B as ht,M as ze,a as O,c as ys,p as xs,C as Nt,b as ee,d as ct,A as It,S as lt,e as ws,R as zt,f as Ys,V as oe,g as Je,T as Ze,Q as qt,h as Zt,i as Me,j as Hs,P as qs,k as Zs,l as bs,m as H,N as Xs,n as Ot,o as Wt,q as Qs,r as Dt,s as Xe,t as Xt,I as Vs,u as Qt,D as Rt,v as ks,w as bt,x as Js,y as Ms,F as ei,z as ti,E as si,W as ii,H as ni,J as ai,K as oi,L as ri,O as ci,U as li,X as hi,Y as di,Z as ui,_ as Vt,$ as pi,a0 as fi,a1 as Jt,a2 as At,a3 as mi}from"./robot-CzDIvswk.js";const gi=o=>String(o?.message??o);function yi(o){const[e,t]=I.useState(null),[s,i]=I.useState(null),[n,a]=I.useState(null),r=I.useRef(null),l=I.useRef(0),h=I.useCallback(()=>{const p=++l.current;qe.invoke("island_get").then(c=>{if(p!==l.current||!c?.island)return;const d=c.island;r.current&&r.current.rev>d.rev||(r.current=d,t(d),i(null))}).catch(c=>{p===l.current&&i(gi(c))})},[]);I.useEffect(()=>{if(!o)return;h();const p=qe.on("island-changed",d=>{d&&(r.current&&d.rev<=r.current.rev||(a(d),h()))}),c=qe.on("chat-status",d=>{d?.key.startsWith("chat:island-wish-")&&h()});return()=>{p(),c()}},[o,h]);const m=I.useCallback(async(p,c={})=>{await qe.invoke(p,c),h()},[h]);return{island:e,error:s,change:n,reload:h,dismissWish:p=>m("island_wish_dismiss",{id:p}),grantWish:p=>m("island_wish_start",{id:p}),rollWish:()=>m("island_wish_roll"),inviteBot:()=>m("island_bot_invite"),farewell:p=>m("island_bot_farewell",{id:p}),setPace:p=>m("island_settings_set",{wishPace:p}),setBuildPace:p=>m("island_build_pace",{pace:p})}}function xi(o,e=Date.now()){const t=new Map;for(const s of o){const i=a=>s.activities.find(r=>r.state===a)?.title,n=s.state==="working"?{state:"working",label:i("working")}:s.state==="needs_you"?{state:"needs_you",label:i("needs_you")}:s.state==="failed"?{state:"failed",label:i("failed")}:{state:"free",...s.recent?{idleFor:Math.max(0,Math.round((e-s.recent.at)/6e4))}:{}};t.set(`agent:${s.id}`,n)}return t}function wi(o,e=Date.now()){const t=Math.max(0,Math.round((e-o)/6e4));if(t<1)return"just now";if(t<60)return`${t} min ago`;const s=Math.round(t/60);return s<24?`${s} h ago`:`${Math.round(s/24)} d ago`}function zs(o,e){const t=new Map;for(const c of[...e].sort((d,g)=>d.key.localeCompare(g.key))){const d=c.agent?.teamId?`team:${c.agent.teamId}`:"general";t.set(d,[...t.get(d)??[],c])}t.has("general")||t.set("general",[]);const s=[],i=o.assets.filter(c=>c.kind==="accessory"),n=[],a=[],r=new Map,l=o.plots.filter(c=>c.owner.kind==="home"&&c.owner.id.startsWith("public:")||o.placed.some(d=>d.plot===c.id&&o.assets.some(g=>g.id===d.asset&&g.kind==="building"&&g.name!=="Workshop"))),h=[];for(let c=1;h.length<t.size+l.length;c++)h.push(...Mt(c).filter(([d,g])=>(d!==-1||g!==0)&&(d!==0||g!==-1)));const m=(c,d,g)=>({shape:"box",size:c,at:d,color:g});for(const[c,[d,g]]of[...t].sort(([j],[b])=>j.localeCompare(b)).entries()){const[j,b]=h[c],k=Ve(j,b),f=`office:${d}`,E=d==="general"?"Agent Tower":`${g[0].agent?.teamName??"Team"} Office`,z={id:f,owner:{kind:"home",id:d},ring:Math.max(Math.abs(j),Math.abs(b),Math.abs(j+b)),slot:c,q:j,r:b,...k,facing:Math.atan2(-k.x,-k.z)*180/Math.PI,radius:Re,claimedAt:0,members:g.map(A=>A.owner.id),officeName:E};s.push(z);const _=Math.max(d==="general"?3:1,Math.ceil(g.length/6)),L=[];for(let A=0;A<_;A++){const S=A*2.3;L.push(m([8,.08,6],[0,S+.04,-.7],"#d6dce5")),L.push({...m([8,2,.14],[0,S+1,-3.6],"#b6c9dd"),finish:"glass"}),L.push({...m([.16,2.3,6],[-3.95,S+1.15,-.7],"#7a94b1"),finish:"glass"}),L.push({...m([.16,2.3,6],[3.95,S+1.15,-.7],"#7a94b1"),finish:"glass"});for(const N of[-2.7,0,2.7])L.push({...m([1.5,1,.025],[N,S+1.2,-3.51],"#b5e5fa"),finish:"glass"})}i.push({id:f,rev:_,name:E,kind:"building",parts:L,by:{name:"Island offices"},madeAt:0,updatedAt:0}),n.push({id:f,asset:f,plot:f,x:0,z:0,y:0,turn:0});for(const[A,S]of g.entries()){a.push({...S,plot:z});const N=`office-desk:${S.key}`,$=(A%3-1)*2.4,W=Math.floor(A%6/3)*2.5-2.4,X=Math.floor(A/6)*2.3;i.push({id:N,rev:Number.parseInt(S.look.trim.slice(1)+S.look.glow.slice(1),16),name:`${S.name}'s desk`,kind:"furniture",use:"desk",spot:{at:[0,0,.65],face:180},parts:[m([1.3,.08,.7],[0,.6,0],"#cfa783"),m([.12,.6,.12],[-.5,.3,0],S.look.trim),m([.12,.6,.12],[.5,.3,0],S.look.trim),m([.65,.42,.08],[0,.88,-.18],"#26354a"),{...m([.55,.32,.02],[0,.88,-.13],S.look.glow),finish:"glow"}],by:{name:S.name,agentId:S.owner.id},madeAt:0,updatedAt:0}),n.push({id:N,asset:N,plot:f,x:$,z:W,y:X,turn:0}),r.set(N,S.key);const Y=o.placed.filter(F=>F.plot===S.plot?.id).filter(F=>{const V=o.assets.find(ve=>ve.id===F.asset);return V&&V.kind!=="building"&&V.name!=="Workshop"&&V.name!=="Desk"&&V.use!=="bed"});for(const[F,V]of Y.entries()){const ve=o.assets.find(fe=>fe.id===V.asset);i.some(fe=>fe.id===ve.id)||i.push(ve);const ne=(A+F/Math.max(1,Y.length))/g.length*Math.PI*2;n.push({...V,plot:f,x:Math.sin(ne)*4.8,z:Math.cos(ne)*4.8,y:0})}}}for(const[c,d]of l.entries()){const[g,j]=h[t.size+c],b=Ve(g,j),k=o.placed.filter(z=>z.plot===d.id&&o.assets.some(_=>_.id===z.asset&&(d.owner.kind==="home"||_.kind==="building"&&_.name!=="Workshop"))),f=o.assets.find(z=>k.some(_=>_.asset===z.id)&&z.kind==="building"),E={...d,q:g,r:j,...b,ring:Math.max(Math.abs(g),Math.abs(j),Math.abs(g+j)),facing:Math.atan2(-b.x,-b.z)*180/Math.PI,officeName:f?.name??"Public project"};s.push(E),n.push(...k);for(const z of k){const _=o.assets.find(L=>L.id===z.asset);_&&!i.some(L=>L.id===_.id)&&i.push(_)}}const p=Math.max(30,o.radius,...s.map(c=>Math.hypot(c.x,c.z)+Re+4));return{island:{...o,plots:s,assets:i,placed:n,radius:p},residents:a,deskOwners:r}}function bi(){const o=new he;o.name="planted-seedlings";const e=new he;o.add(e);const t=new ht(1,1,1),s=new ze({color:"#88674b"}),i=new ze({color:"#64a856"}),n=new O(t,s);n.scale.set(.8,.035,.45),n.position.y=.02,o.add(n);for(const r of[-.26,0,.26]){const l=new O(t,i);l.scale.set(.025,.3,.025),l.position.set(r,.17,0),e.add(l);for(const h of[-1,1]){const m=new O(t,i);m.scale.set(.17,.045,.08),m.position.set(r+h*.07,.23,0),m.rotation.z=h*.4,e.add(m)}}let a=0;return{root:o,update(r,l){l&&(a=Math.min(1,a+r/12)),e.scale.setScalar(.12+a*.88),o.visible=a>0},dispose(){t.dispose(),s.dispose(),i.dispose()}}}const we=Ve(0,-1),ki={x:we.x,z:we.z-.8};function Mi(o){return{x:we.x+(o%4-1.5)*1.6,z:we.z+.6+Math.floor(o/4)*1}}function zi(){const o=new he;o.name="bot-society",o.position.set(we.x,.05,we.z);const e=new ht(1,1,1),t=new ze({color:"#ded8c9",roughness:.8}),s=new ze({color:"#caa45c",metalness:.5,roughness:.3}),i=new ze({color:"#b8e5f0",transparent:!0,opacity:.22,depthWrite:!1}),n=(c,d,g,j,b,k,f=t)=>{const E=new O(e,f);E.position.set(c,d,g),E.scale.set(j,b,k),o.add(E)};n(0,.05,0,8,.1,7),n(-3.9,1.2,0,.15,2.4,7,i),n(3.9,1.2,0,.15,2.4,7,i);for(const c of[-3.2,3.2])n(c,1.5,2.8,.45,3,.45),n(c,3.1,2.8,.75,.2,.75,s);n(0,3.15,2.8,6.8,.25,.35,s),n(0,.45,-1.6,3.2,.9,.65),n(0,.94,-1.6,3.5,.1,.9,s),n(0,.5,-3.7,2.4,1,1.8),n(0,1.07,-3.7,2.7,.15,2,s);const a=Is({id:"bot-society-statue",agent:"codex",model:"sol"}),r=ys({...a,shell:"#d7c592",trim:"#a98642",glow:"#fff2af",antenna:"crown"});xs(r,"raise",0,{calm:!0}),r.root.scale.setScalar(4.5),r.root.position.set(0,1.15,-3.7),o.add(r.root);const l=document.createElement("canvas");l.width=768,l.height=128;const h=l.getContext("2d");h.fillStyle="#f7e8bd",h.fillRect(0,0,768,128),h.fillStyle="#5d4828",h.font="bold 56px sans-serif",h.textAlign="center",h.fillText("BOT SOCIETY",384,80);const m=new Nt(l),p=new ee({map:m});return n(0,3.15,3.02,4.8,.8,.04,p),{root:o,solids:[{cx:we.x-3.9,cz:we.z,hx:.08,hz:3.5,yaw:0},{cx:we.x+3.9,cz:we.z,hx:.08,hz:3.5,yaw:0},{cx:we.x,cz:we.z-1.6,hx:1.7,hz:.45,yaw:0},{cx:we.x,cz:we.z-3.7,hx:1.4,hz:1.1,yaw:0}],dispose(){r.dispose(),e.dispose(),t.dispose(),s.dispose(),i.dispose(),m.dispose(),p.dispose()}}}function vi(o){if(o.kind==="accessory"||o.use==="none")return null;if(["read","paint","garden","perform","play","observe"].includes(o.use??""))return o.use;const e=o.name.toLowerCase();for(const[t,s]of[["garden",/garden|planter|greenhouse|seedling|herb|mint|花|种植|种子|盆栽|薄荷|温室|苗/],["paint",/easel|paint|画架|绘画|畫架/],["read",/library|bookshelf|bookcase|café|cafe|reading|书架|图书|書架|咖啡/],["perform",/music|concert|stage|piano|音乐|合奏|舞台|钢琴/],["play",/arcade|game|toy|游戏|玩具|游乐/],["observe",/lamp|light|灯|燈/]])if(s.test(e))return t;return/\b(chair|bench|stool|bed)\b|椅|凳|床/.test(e)&&!o.use?null:!o.use&&/\b(table|desk|workbench)\b|桌|工作台/.test(e)?/workbench|工作台/.test(e)?"play":"read":o.use==="desk"?/workbench|工作台/.test(e)?"play":"read":o.use==="seat"||o.use==="bed"?null:o.kind==="building"||o.kind==="furniture"||o.kind==="decor"?"observe":null}function _i(o,e,t){if(t.id.startsWith("office-desk:"))return null;const s=vi(o);if(!s||!o.parts.length)return null;const i=Math.max(...o.parts.map(c=>ct(c).max[2])),n=Math.max(0,...o.parts.map(c=>ct(c)).filter(c=>c.max[1]<=.35&&c.max[1]-c.min[1]<=.16).map(c=>c.max[1])),a=o.spot??(o.kind==="building"&&s!=="observe"?{at:[0,n,0],face:180}:{at:[0,0,i+.85],face:180}),r=t.turn*Math.PI/180,[l,h,m]=a.at,p=Ce(e,t.x+l*Math.cos(r)+m*Math.sin(r),t.z-l*Math.sin(r)+m*Math.cos(r));return{key:t.id,name:o.name,activity:s,...p,y:ce+t.y+h,face:(e.facing+t.turn+a.face)*Math.PI/180}}function es(o,e){const t={garden:"gardening",read:"reading",paint:"painting",perform:"music",play:"games"};return e==="observe"||!!o?.includes(t[e])}function Si(){const o=new he,e=new ht(1,1,1),t=["#f1e7cb","#6b86b6","#f5a14a","#76b9a5","#71c7ff"].map(m=>new ee({color:m})),s=(m,p,c)=>{const d=new he;d.name=m;const g=new O(e,t[c]);return g.scale.set(...p),d.add(g),o.add(d),d.visible=!1,d},i=s("read",[.32,.24,.05],1),n=s("paint",[.035,.32,.035],2),a=s("garden",[.22,.16,.17],3),r=s("register",[.24,.3,.02],0),l=s("play",[.25,.1,.1],1),h=new O(e,t[4]);return h.scale.set(.18,.035,.035),h.position.x=.16,a.add(h),{root:o,show(m){for(const p of[i,n,a,r,l])p.visible=p.name===m},dispose(){e.dispose(),t.forEach(m=>m.dispose())}}}function Pi(){const o=new he;o.name="concert-stage";const e=new ee({color:"#253044"}),t=new ee({color:"#9d8dff"}),s=new ee({color:"#c2a1ff",transparent:!0,opacity:.32,depthWrite:!1}),i=new ee({color:"#b997ff",transparent:!0,opacity:.13,depthWrite:!1,blending:It}),n=new lt(.75,20,12),a=new O(n,i);a.position.y=.65,o.add(a);const r=new ht(.5,.8,.4),l=new ws(.16,20),h=new zt(.7,1.25,40),m=new O(h,s);m.rotation.x=-Math.PI/2,m.position.y=.05,o.add(m);const p=[];for(const d of[-1,1]){const g=new he;g.position.set(d*1.2,.4,0),g.add(new O(r,e));for(const j of[-.19,.19]){const b=new O(l,t);b.position.set(0,j,.205),g.add(b)}o.add(g),p.push(g)}o.visible=!1;let c=0;return{root:o,update(d,g,j,b){c=Math.max(0,Math.min(1,c+(d?1:-1)*g*3)),o.visible=c>0;const k=b?1:1+Math.sin(j*8)*.09;o.scale.setScalar(Math.max(.001,c)),m.scale.setScalar(k),a.scale.setScalar(k),s.opacity=.24+(b?0:(Math.sin(j*8)+1)*.1),p.forEach(f=>f.scale.set(1,k,k))},dispose(){n.dispose(),i.dispose(),r.dispose(),l.dispose(),h.dispose(),e.dispose(),t.dispose(),s.dispose()}}}const ts={type:"change"},$t={type:"start"},vs={type:"end"},gt=new Hs,ss=new qs,ji=Math.cos(70*Zs.DEG2RAD),ae=new oe,xe=2*Math.PI,K={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Tt=1e-6;class Ei extends Ys{constructor(e,t=null){super(e,t),this.state=K.NONE,this.target=new oe,this.cursor=new oe,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Je.ROTATE,MIDDLE:Je.DOLLY,RIGHT:Je.PAN},this.touches={ONE:Ze.ROTATE,TWO:Ze.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new oe,this._lastQuaternion=new qt,this._lastTargetPosition=new oe,this._quat=new qt().setFromUnitVectors(e.up,new oe(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Zt,this._sphericalDelta=new Zt,this._scale=1,this._panOffset=new oe,this._rotateStart=new Me,this._rotateEnd=new Me,this._rotateDelta=new Me,this._panStart=new Me,this._panEnd=new Me,this._panDelta=new Me,this._dollyStart=new Me,this._dollyEnd=new Me,this._dollyDelta=new Me,this._dollyDirection=new oe,this._mouse=new Me,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Ti.bind(this),this._onPointerDown=Ai.bind(this),this._onPointerUp=Li.bind(this),this._onContextMenu=Wi.bind(this),this._onMouseWheel=Ci.bind(this),this._onKeyDown=Ni.bind(this),this._onTouchStart=Ii.bind(this),this._onTouchMove=Oi.bind(this),this._onMouseDown=Di.bind(this),this._onMouseMove=Ri.bind(this),this._interceptControlDown=$i.bind(this),this._interceptControlUp=Ui.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(ts),this.update(),this.state=K.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;ae.copy(t).sub(this.target),ae.applyQuaternion(this._quat),this._spherical.setFromVector3(ae),this.autoRotate&&this.state===K.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(s)&&isFinite(i)&&(s<-Math.PI?s+=xe:s>Math.PI&&(s-=xe),i<-Math.PI?i+=xe:i>Math.PI&&(i-=xe),s<=i?this._spherical.theta=Math.max(s,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+i)/2?Math.max(s,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let n=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const a=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),n=a!=this._spherical.radius}if(ae.setFromSpherical(this._spherical),ae.applyQuaternion(this._quatInverse),t.copy(this.target).add(ae),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let a=null;if(this.object.isPerspectiveCamera){const r=ae.length();a=this._clampDistance(r*this._scale);const l=r-a;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),n=!!l}else if(this.object.isOrthographicCamera){const r=new oe(this._mouse.x,this._mouse.y,0);r.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),n=l!==this.object.zoom;const h=new oe(this._mouse.x,this._mouse.y,0);h.unproject(this.object),this.object.position.sub(h).add(r),this.object.updateMatrixWorld(),a=ae.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;a!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position):(gt.origin.copy(this.object.position),gt.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(gt.direction))<ji?this.object.lookAt(this.target):(ss.setFromNormalAndCoplanarPoint(this.object.up,this.target),gt.intersectPlane(ss,this.target))))}else if(this.object.isOrthographicCamera){const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),a!==this.object.zoom&&(this.object.updateProjectionMatrix(),n=!0)}return this._scale=1,this._performCursorZoom=!1,n||this._lastPosition.distanceToSquared(this.object.position)>Tt||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Tt||this._lastTargetPosition.distanceToSquared(this.target)>Tt?(this.dispatchEvent(ts),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?xe/60*this.autoRotateSpeed*e:xe/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){ae.setFromMatrixColumn(t,0),ae.multiplyScalar(-e),this._panOffset.add(ae)}_panUp(e,t){this.screenSpacePanning===!0?ae.setFromMatrixColumn(t,1):(ae.setFromMatrixColumn(t,0),ae.crossVectors(this.object.up,ae)),ae.multiplyScalar(e),this._panOffset.add(ae)}_pan(e,t){const s=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;ae.copy(i).sub(this.target);let n=ae.length();n*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*n/s.clientHeight,this.object.matrix),this._panUp(2*t*n/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),i=e-s.left,n=t-s.top,a=s.width,r=s.height;this._mouse.x=i/a*2-1,this._mouse.y=-(n/r)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(xe*this._rotateDelta.x/t.clientHeight),this._rotateUp(xe*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._rotateStart.set(s,i)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panStart.set(s,i)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,i=e.pageY-t.y,n=Math.sqrt(s*s+i*i);this._dollyStart.set(0,n)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const s=this._getSecondPointerPosition(e),i=.5*(e.pageX+s.x),n=.5*(e.pageY+s.y);this._rotateEnd.set(i,n)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(xe*this._rotateDelta.x/t.clientHeight),this._rotateUp(xe*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panEnd.set(s,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,i=e.pageY-t.y,n=Math.sqrt(s*s+i*i);this._dollyEnd.set(0,n),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const a=(e.pageX+t.x)*.5,r=(e.pageY+t.y)*.5;this._updateZoomParameters(a,r)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new Me,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,s={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function Ai(o){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(o.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(o)&&(this._addPointer(o),o.pointerType==="touch"?this._onTouchStart(o):this._onMouseDown(o),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function Ti(o){this.enabled!==!1&&(o.pointerType==="touch"?this._onTouchMove(o):this._onMouseMove(o))}function Li(o){switch(this._removePointer(o),this._pointers.length){case 0:this.domElement.releasePointerCapture(o.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(vs),this.state=K.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function Di(o){let e;switch(o.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Je.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(o),this.state=K.DOLLY;break;case Je.ROTATE:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=K.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=K.ROTATE}break;case Je.PAN:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=K.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=K.PAN}break;default:this.state=K.NONE}this.state!==K.NONE&&this.dispatchEvent($t)}function Ri(o){switch(this.state){case K.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(o);break;case K.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(o);break;case K.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(o);break}}function Ci(o){this.enabled===!1||this.enableZoom===!1||this.state!==K.NONE||(o.preventDefault(),this.dispatchEvent($t),this._handleMouseWheel(this._customWheelEvent(o)),this.dispatchEvent(vs))}function Ni(o){this.enabled!==!1&&this._handleKeyDown(o)}function Ii(o){switch(this._trackPointer(o),this._pointers.length){case 1:switch(this.touches.ONE){case Ze.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(o),this.state=K.TOUCH_ROTATE;break;case Ze.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(o),this.state=K.TOUCH_PAN;break;default:this.state=K.NONE}break;case 2:switch(this.touches.TWO){case Ze.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(o),this.state=K.TOUCH_DOLLY_PAN;break;case Ze.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(o),this.state=K.TOUCH_DOLLY_ROTATE;break;default:this.state=K.NONE}break;default:this.state=K.NONE}this.state!==K.NONE&&this.dispatchEvent($t)}function Oi(o){switch(this._trackPointer(o),this.state){case K.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(o),this.update();break;case K.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(o),this.update();break;case K.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(o),this.update();break;case K.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(o),this.update();break;default:this.state=K.NONE}}function Wi(o){this.enabled!==!1&&o.preventDefault()}function $i(o){o.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Ui(o){o.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Bi(o){if(o.kind!=="building"||!o.parts.length)return[];const e=o.parts.map(ct).filter(({min:t,max:s})=>(s[1]<=1.2+1e-6||s[1]-t[1]<.3)&&s[0]-t[0]>1&&s[2]-t[2]>1);if(!e.length){const t=Qs(o);e.push({min:[t.min[0],0,t.min[2]],max:[t.max[0],0,t.max[2]]})}return e.map(({min:t,max:s})=>({x:(t[0]+s[0])/2,y:s[1]+.012,z:(t[2]+s[2])/2,width:(s[0]-t[0])*.96,depth:(s[2]-t[2])*.96}))}class _s{group=new he;material=new bs({uniforms:{night:{value:0},warmth:{value:new H("#ffb24d")},strength:{value:.34}},vertexShader:`varying vec2 lightUv;
1
+ import{r as I,b as qe,a as Mt,T as Re,c as Ve,d as Is,p as Ce,e as ce,C as Pe,o as Lt,f as gs,P as wt,g as Os,S as Ht,h as Ws,u as $s,i as Us,j as Bs,k as Fs,w as Et,l as x,W as Gs,A as Ks}from"./index-BaadIo09.js";import{G as he,B as ht,M as ze,a as O,c as ys,p as xs,C as Nt,b as ee,d as ct,A as It,S as lt,e as ws,R as zt,f as Ys,V as oe,g as Je,T as Ze,Q as qt,h as Zt,i as Me,j as Hs,P as qs,k as Zs,l as bs,m as H,N as Xs,n as Ot,o as Wt,q as Qs,r as Dt,s as Xe,t as Xt,I as Vs,u as Qt,D as Rt,v as ks,w as bt,x as Js,y as Ms,F as ei,z as ti,E as si,W as ii,H as ni,J as ai,K as oi,L as ri,O as ci,U as li,X as hi,Y as di,Z as ui,_ as Vt,$ as pi,a0 as fi,a1 as Jt,a2 as At,a3 as mi}from"./robot-CzDIvswk.js";const gi=o=>String(o?.message??o);function yi(o){const[e,t]=I.useState(null),[s,i]=I.useState(null),[n,a]=I.useState(null),r=I.useRef(null),l=I.useRef(0),h=I.useCallback(()=>{const p=++l.current;qe.invoke("island_get").then(c=>{if(p!==l.current||!c?.island)return;const d=c.island;r.current&&r.current.rev>d.rev||(r.current=d,t(d),i(null))}).catch(c=>{p===l.current&&i(gi(c))})},[]);I.useEffect(()=>{if(!o)return;h();const p=qe.on("island-changed",d=>{d&&(r.current&&d.rev<=r.current.rev||(a(d),h()))}),c=qe.on("chat-status",d=>{d?.key.startsWith("chat:island-wish-")&&h()});return()=>{p(),c()}},[o,h]);const m=I.useCallback(async(p,c={})=>{await qe.invoke(p,c),h()},[h]);return{island:e,error:s,change:n,reload:h,dismissWish:p=>m("island_wish_dismiss",{id:p}),grantWish:p=>m("island_wish_start",{id:p}),rollWish:()=>m("island_wish_roll"),inviteBot:()=>m("island_bot_invite"),farewell:p=>m("island_bot_farewell",{id:p}),setPace:p=>m("island_settings_set",{wishPace:p}),setBuildPace:p=>m("island_build_pace",{pace:p})}}function xi(o,e=Date.now()){const t=new Map;for(const s of o){const i=a=>s.activities.find(r=>r.state===a)?.title,n=s.state==="working"?{state:"working",label:i("working")}:s.state==="needs_you"?{state:"needs_you",label:i("needs_you")}:s.state==="failed"?{state:"failed",label:i("failed")}:{state:"free",...s.recent?{idleFor:Math.max(0,Math.round((e-s.recent.at)/6e4))}:{}};t.set(`agent:${s.id}`,n)}return t}function wi(o,e=Date.now()){const t=Math.max(0,Math.round((e-o)/6e4));if(t<1)return"just now";if(t<60)return`${t} min ago`;const s=Math.round(t/60);return s<24?`${s} h ago`:`${Math.round(s/24)} d ago`}function zs(o,e){const t=new Map;for(const c of[...e].sort((d,g)=>d.key.localeCompare(g.key))){const d=c.agent?.teamId?`team:${c.agent.teamId}`:"general";t.set(d,[...t.get(d)??[],c])}t.has("general")||t.set("general",[]);const s=[],i=o.assets.filter(c=>c.kind==="accessory"),n=[],a=[],r=new Map,l=o.plots.filter(c=>c.owner.kind==="home"&&c.owner.id.startsWith("public:")||o.placed.some(d=>d.plot===c.id&&o.assets.some(g=>g.id===d.asset&&g.kind==="building"&&g.name!=="Workshop"))),h=[];for(let c=1;h.length<t.size+l.length;c++)h.push(...Mt(c).filter(([d,g])=>(d!==-1||g!==0)&&(d!==0||g!==-1)));const m=(c,d,g)=>({shape:"box",size:c,at:d,color:g});for(const[c,[d,g]]of[...t].sort(([j],[b])=>j.localeCompare(b)).entries()){const[j,b]=h[c],k=Ve(j,b),f=`office:${d}`,E=d==="general"?"Agent Tower":`${g[0].agent?.teamName??"Team"} Office`,z={id:f,owner:{kind:"home",id:d},ring:Math.max(Math.abs(j),Math.abs(b),Math.abs(j+b)),slot:c,q:j,r:b,...k,facing:Math.atan2(-k.x,-k.z)*180/Math.PI,radius:Re,claimedAt:0,members:g.map(A=>A.owner.id),officeName:E};s.push(z);const _=Math.max(d==="general"?3:1,Math.ceil(g.length/6)),L=[];for(let A=0;A<_;A++){const S=A*2.3;L.push(m([8,.08,6],[0,S+.04,-.7],"#d6dce5")),L.push({...m([8,2,.14],[0,S+1,-3.6],"#b6c9dd"),finish:"glass"}),L.push({...m([.16,2.3,6],[-3.95,S+1.15,-.7],"#7a94b1"),finish:"glass"}),L.push({...m([.16,2.3,6],[3.95,S+1.15,-.7],"#7a94b1"),finish:"glass"});for(const N of[-2.7,0,2.7])L.push({...m([1.5,1,.025],[N,S+1.2,-3.51],"#b5e5fa"),finish:"glass"})}i.push({id:f,rev:_,name:E,kind:"building",parts:L,by:{name:"Island offices"},madeAt:0,updatedAt:0}),n.push({id:f,asset:f,plot:f,x:0,z:0,y:0,turn:0});for(const[A,S]of g.entries()){a.push({...S,plot:z});const N=`office-desk:${S.key}`,$=(A%3-1)*2.4,W=Math.floor(A%6/3)*2.5-2.4,X=Math.floor(A/6)*2.3;i.push({id:N,rev:Number.parseInt(S.look.trim.slice(1)+S.look.glow.slice(1),16),name:`${S.name}'s desk`,kind:"furniture",use:"desk",spot:{at:[0,0,.65],face:180},parts:[m([1.3,.08,.7],[0,.6,0],"#cfa783"),m([.12,.6,.12],[-.5,.3,0],S.look.trim),m([.12,.6,.12],[.5,.3,0],S.look.trim),m([.65,.42,.08],[0,.88,-.18],"#26354a"),{...m([.55,.32,.02],[0,.88,-.13],S.look.glow),finish:"glow"}],by:{name:S.name,agentId:S.owner.id},madeAt:0,updatedAt:0}),n.push({id:N,asset:N,plot:f,x:$,z:W,y:X,turn:0}),r.set(N,S.key);const Y=o.placed.filter(F=>F.plot===S.plot?.id).filter(F=>{const V=o.assets.find(ve=>ve.id===F.asset);return V&&V.kind!=="building"&&V.name!=="Workshop"&&V.name!=="Desk"&&V.use!=="bed"});for(const[F,V]of Y.entries()){const ve=o.assets.find(fe=>fe.id===V.asset);i.some(fe=>fe.id===ve.id)||i.push(ve);const ne=(A+F/Math.max(1,Y.length))/g.length*Math.PI*2;n.push({...V,plot:f,x:Math.sin(ne)*4.8,z:Math.cos(ne)*4.8,y:0})}}}for(const[c,d]of l.entries()){const[g,j]=h[t.size+c],b=Ve(g,j),k=o.placed.filter(z=>z.plot===d.id&&o.assets.some(_=>_.id===z.asset&&(d.owner.kind==="home"||_.kind==="building"&&_.name!=="Workshop"))),f=o.assets.find(z=>k.some(_=>_.asset===z.id)&&z.kind==="building"),E={...d,q:g,r:j,...b,ring:Math.max(Math.abs(g),Math.abs(j),Math.abs(g+j)),facing:Math.atan2(-b.x,-b.z)*180/Math.PI,officeName:f?.name??"Public project"};s.push(E),n.push(...k);for(const z of k){const _=o.assets.find(L=>L.id===z.asset);_&&!i.some(L=>L.id===_.id)&&i.push(_)}}const p=Math.max(30,o.radius,...s.map(c=>Math.hypot(c.x,c.z)+Re+4));return{island:{...o,plots:s,assets:i,placed:n,radius:p},residents:a,deskOwners:r}}function bi(){const o=new he;o.name="planted-seedlings";const e=new he;o.add(e);const t=new ht(1,1,1),s=new ze({color:"#88674b"}),i=new ze({color:"#64a856"}),n=new O(t,s);n.scale.set(.8,.035,.45),n.position.y=.02,o.add(n);for(const r of[-.26,0,.26]){const l=new O(t,i);l.scale.set(.025,.3,.025),l.position.set(r,.17,0),e.add(l);for(const h of[-1,1]){const m=new O(t,i);m.scale.set(.17,.045,.08),m.position.set(r+h*.07,.23,0),m.rotation.z=h*.4,e.add(m)}}let a=0;return{root:o,update(r,l){l&&(a=Math.min(1,a+r/12)),e.scale.setScalar(.12+a*.88),o.visible=a>0},dispose(){t.dispose(),s.dispose(),i.dispose()}}}const we=Ve(0,-1),ki={x:we.x,z:we.z-.8};function Mi(o){return{x:we.x+(o%4-1.5)*1.6,z:we.z+.6+Math.floor(o/4)*1}}function zi(){const o=new he;o.name="bot-society",o.position.set(we.x,.05,we.z);const e=new ht(1,1,1),t=new ze({color:"#ded8c9",roughness:.8}),s=new ze({color:"#caa45c",metalness:.5,roughness:.3}),i=new ze({color:"#b8e5f0",transparent:!0,opacity:.22,depthWrite:!1}),n=(c,d,g,j,b,k,f=t)=>{const E=new O(e,f);E.position.set(c,d,g),E.scale.set(j,b,k),o.add(E)};n(0,.05,0,8,.1,7),n(-3.9,1.2,0,.15,2.4,7,i),n(3.9,1.2,0,.15,2.4,7,i);for(const c of[-3.2,3.2])n(c,1.5,2.8,.45,3,.45),n(c,3.1,2.8,.75,.2,.75,s);n(0,3.15,2.8,6.8,.25,.35,s),n(0,.45,-1.6,3.2,.9,.65),n(0,.94,-1.6,3.5,.1,.9,s),n(0,.5,-3.7,2.4,1,1.8),n(0,1.07,-3.7,2.7,.15,2,s);const a=Is({id:"bot-society-statue",agent:"codex",model:"sol"}),r=ys({...a,shell:"#d7c592",trim:"#a98642",glow:"#fff2af",antenna:"crown"});xs(r,"raise",0,{calm:!0}),r.root.scale.setScalar(4.5),r.root.position.set(0,1.15,-3.7),o.add(r.root);const l=document.createElement("canvas");l.width=768,l.height=128;const h=l.getContext("2d");h.fillStyle="#f7e8bd",h.fillRect(0,0,768,128),h.fillStyle="#5d4828",h.font="bold 56px sans-serif",h.textAlign="center",h.fillText("BOT SOCIETY",384,80);const m=new Nt(l),p=new ee({map:m});return n(0,3.15,3.02,4.8,.8,.04,p),{root:o,solids:[{cx:we.x-3.9,cz:we.z,hx:.08,hz:3.5,yaw:0},{cx:we.x+3.9,cz:we.z,hx:.08,hz:3.5,yaw:0},{cx:we.x,cz:we.z-1.6,hx:1.7,hz:.45,yaw:0},{cx:we.x,cz:we.z-3.7,hx:1.4,hz:1.1,yaw:0}],dispose(){r.dispose(),e.dispose(),t.dispose(),s.dispose(),i.dispose(),m.dispose(),p.dispose()}}}function vi(o){if(o.kind==="accessory"||o.use==="none")return null;if(["read","paint","garden","perform","play","observe"].includes(o.use??""))return o.use;const e=o.name.toLowerCase();for(const[t,s]of[["garden",/garden|planter|greenhouse|seedling|herb|mint|花|种植|种子|盆栽|薄荷|温室|苗/],["paint",/easel|paint|画架|绘画|畫架/],["read",/library|bookshelf|bookcase|café|cafe|reading|书架|图书|書架|咖啡/],["perform",/music|concert|stage|piano|音乐|合奏|舞台|钢琴/],["play",/arcade|game|toy|游戏|玩具|游乐/],["observe",/lamp|light|灯|燈/]])if(s.test(e))return t;return/\b(chair|bench|stool|bed)\b|椅|凳|床/.test(e)&&!o.use?null:!o.use&&/\b(table|desk|workbench)\b|桌|工作台/.test(e)?/workbench|工作台/.test(e)?"play":"read":o.use==="desk"?/workbench|工作台/.test(e)?"play":"read":o.use==="seat"||o.use==="bed"?null:o.kind==="building"||o.kind==="furniture"||o.kind==="decor"?"observe":null}function _i(o,e,t){if(t.id.startsWith("office-desk:"))return null;const s=vi(o);if(!s||!o.parts.length)return null;const i=Math.max(...o.parts.map(c=>ct(c).max[2])),n=Math.max(0,...o.parts.map(c=>ct(c)).filter(c=>c.max[1]<=.35&&c.max[1]-c.min[1]<=.16).map(c=>c.max[1])),a=o.spot??(o.kind==="building"&&s!=="observe"?{at:[0,n,0],face:180}:{at:[0,0,i+.85],face:180}),r=t.turn*Math.PI/180,[l,h,m]=a.at,p=Ce(e,t.x+l*Math.cos(r)+m*Math.sin(r),t.z-l*Math.sin(r)+m*Math.cos(r));return{key:t.id,name:o.name,activity:s,...p,y:ce+t.y+h,face:(e.facing+t.turn+a.face)*Math.PI/180}}function es(o,e){const t={garden:"gardening",read:"reading",paint:"painting",perform:"music",play:"games"};return e==="observe"||!!o?.includes(t[e])}function Si(){const o=new he,e=new ht(1,1,1),t=["#f1e7cb","#6b86b6","#f5a14a","#76b9a5","#71c7ff"].map(m=>new ee({color:m})),s=(m,p,c)=>{const d=new he;d.name=m;const g=new O(e,t[c]);return g.scale.set(...p),d.add(g),o.add(d),d.visible=!1,d},i=s("read",[.32,.24,.05],1),n=s("paint",[.035,.32,.035],2),a=s("garden",[.22,.16,.17],3),r=s("register",[.24,.3,.02],0),l=s("play",[.25,.1,.1],1),h=new O(e,t[4]);return h.scale.set(.18,.035,.035),h.position.x=.16,a.add(h),{root:o,show(m){for(const p of[i,n,a,r,l])p.visible=p.name===m},dispose(){e.dispose(),t.forEach(m=>m.dispose())}}}function Pi(){const o=new he;o.name="concert-stage";const e=new ee({color:"#253044"}),t=new ee({color:"#9d8dff"}),s=new ee({color:"#c2a1ff",transparent:!0,opacity:.32,depthWrite:!1}),i=new ee({color:"#b997ff",transparent:!0,opacity:.13,depthWrite:!1,blending:It}),n=new lt(.75,20,12),a=new O(n,i);a.position.y=.65,o.add(a);const r=new ht(.5,.8,.4),l=new ws(.16,20),h=new zt(.7,1.25,40),m=new O(h,s);m.rotation.x=-Math.PI/2,m.position.y=.05,o.add(m);const p=[];for(const d of[-1,1]){const g=new he;g.position.set(d*1.2,.4,0),g.add(new O(r,e));for(const j of[-.19,.19]){const b=new O(l,t);b.position.set(0,j,.205),g.add(b)}o.add(g),p.push(g)}o.visible=!1;let c=0;return{root:o,update(d,g,j,b){c=Math.max(0,Math.min(1,c+(d?1:-1)*g*3)),o.visible=c>0;const k=b?1:1+Math.sin(j*8)*.09;o.scale.setScalar(Math.max(.001,c)),m.scale.setScalar(k),a.scale.setScalar(k),s.opacity=.24+(b?0:(Math.sin(j*8)+1)*.1),p.forEach(f=>f.scale.set(1,k,k))},dispose(){n.dispose(),i.dispose(),r.dispose(),l.dispose(),h.dispose(),e.dispose(),t.dispose(),s.dispose()}}}const ts={type:"change"},$t={type:"start"},vs={type:"end"},gt=new Hs,ss=new qs,ji=Math.cos(70*Zs.DEG2RAD),ae=new oe,xe=2*Math.PI,K={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Tt=1e-6;class Ei extends Ys{constructor(e,t=null){super(e,t),this.state=K.NONE,this.target=new oe,this.cursor=new oe,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Je.ROTATE,MIDDLE:Je.DOLLY,RIGHT:Je.PAN},this.touches={ONE:Ze.ROTATE,TWO:Ze.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new oe,this._lastQuaternion=new qt,this._lastTargetPosition=new oe,this._quat=new qt().setFromUnitVectors(e.up,new oe(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Zt,this._sphericalDelta=new Zt,this._scale=1,this._panOffset=new oe,this._rotateStart=new Me,this._rotateEnd=new Me,this._rotateDelta=new Me,this._panStart=new Me,this._panEnd=new Me,this._panDelta=new Me,this._dollyStart=new Me,this._dollyEnd=new Me,this._dollyDelta=new Me,this._dollyDirection=new oe,this._mouse=new Me,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Ti.bind(this),this._onPointerDown=Ai.bind(this),this._onPointerUp=Li.bind(this),this._onContextMenu=Wi.bind(this),this._onMouseWheel=Ci.bind(this),this._onKeyDown=Ni.bind(this),this._onTouchStart=Ii.bind(this),this._onTouchMove=Oi.bind(this),this._onMouseDown=Di.bind(this),this._onMouseMove=Ri.bind(this),this._interceptControlDown=$i.bind(this),this._interceptControlUp=Ui.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(ts),this.update(),this.state=K.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;ae.copy(t).sub(this.target),ae.applyQuaternion(this._quat),this._spherical.setFromVector3(ae),this.autoRotate&&this.state===K.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(s)&&isFinite(i)&&(s<-Math.PI?s+=xe:s>Math.PI&&(s-=xe),i<-Math.PI?i+=xe:i>Math.PI&&(i-=xe),s<=i?this._spherical.theta=Math.max(s,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+i)/2?Math.max(s,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let n=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const a=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),n=a!=this._spherical.radius}if(ae.setFromSpherical(this._spherical),ae.applyQuaternion(this._quatInverse),t.copy(this.target).add(ae),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let a=null;if(this.object.isPerspectiveCamera){const r=ae.length();a=this._clampDistance(r*this._scale);const l=r-a;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),n=!!l}else if(this.object.isOrthographicCamera){const r=new oe(this._mouse.x,this._mouse.y,0);r.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),n=l!==this.object.zoom;const h=new oe(this._mouse.x,this._mouse.y,0);h.unproject(this.object),this.object.position.sub(h).add(r),this.object.updateMatrixWorld(),a=ae.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;a!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position):(gt.origin.copy(this.object.position),gt.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(gt.direction))<ji?this.object.lookAt(this.target):(ss.setFromNormalAndCoplanarPoint(this.object.up,this.target),gt.intersectPlane(ss,this.target))))}else if(this.object.isOrthographicCamera){const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),a!==this.object.zoom&&(this.object.updateProjectionMatrix(),n=!0)}return this._scale=1,this._performCursorZoom=!1,n||this._lastPosition.distanceToSquared(this.object.position)>Tt||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Tt||this._lastTargetPosition.distanceToSquared(this.target)>Tt?(this.dispatchEvent(ts),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?xe/60*this.autoRotateSpeed*e:xe/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){ae.setFromMatrixColumn(t,0),ae.multiplyScalar(-e),this._panOffset.add(ae)}_panUp(e,t){this.screenSpacePanning===!0?ae.setFromMatrixColumn(t,1):(ae.setFromMatrixColumn(t,0),ae.crossVectors(this.object.up,ae)),ae.multiplyScalar(e),this._panOffset.add(ae)}_pan(e,t){const s=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;ae.copy(i).sub(this.target);let n=ae.length();n*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*n/s.clientHeight,this.object.matrix),this._panUp(2*t*n/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),i=e-s.left,n=t-s.top,a=s.width,r=s.height;this._mouse.x=i/a*2-1,this._mouse.y=-(n/r)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(xe*this._rotateDelta.x/t.clientHeight),this._rotateUp(xe*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-xe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._rotateStart.set(s,i)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panStart.set(s,i)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,i=e.pageY-t.y,n=Math.sqrt(s*s+i*i);this._dollyStart.set(0,n)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const s=this._getSecondPointerPosition(e),i=.5*(e.pageX+s.x),n=.5*(e.pageY+s.y);this._rotateEnd.set(i,n)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(xe*this._rotateDelta.x/t.clientHeight),this._rotateUp(xe*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panEnd.set(s,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,i=e.pageY-t.y,n=Math.sqrt(s*s+i*i);this._dollyEnd.set(0,n),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const a=(e.pageX+t.x)*.5,r=(e.pageY+t.y)*.5;this._updateZoomParameters(a,r)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new Me,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,s={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function Ai(o){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(o.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(o)&&(this._addPointer(o),o.pointerType==="touch"?this._onTouchStart(o):this._onMouseDown(o),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function Ti(o){this.enabled!==!1&&(o.pointerType==="touch"?this._onTouchMove(o):this._onMouseMove(o))}function Li(o){switch(this._removePointer(o),this._pointers.length){case 0:this.domElement.releasePointerCapture(o.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(vs),this.state=K.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function Di(o){let e;switch(o.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Je.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(o),this.state=K.DOLLY;break;case Je.ROTATE:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=K.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=K.ROTATE}break;case Je.PAN:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=K.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=K.PAN}break;default:this.state=K.NONE}this.state!==K.NONE&&this.dispatchEvent($t)}function Ri(o){switch(this.state){case K.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(o);break;case K.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(o);break;case K.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(o);break}}function Ci(o){this.enabled===!1||this.enableZoom===!1||this.state!==K.NONE||(o.preventDefault(),this.dispatchEvent($t),this._handleMouseWheel(this._customWheelEvent(o)),this.dispatchEvent(vs))}function Ni(o){this.enabled!==!1&&this._handleKeyDown(o)}function Ii(o){switch(this._trackPointer(o),this._pointers.length){case 1:switch(this.touches.ONE){case Ze.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(o),this.state=K.TOUCH_ROTATE;break;case Ze.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(o),this.state=K.TOUCH_PAN;break;default:this.state=K.NONE}break;case 2:switch(this.touches.TWO){case Ze.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(o),this.state=K.TOUCH_DOLLY_PAN;break;case Ze.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(o),this.state=K.TOUCH_DOLLY_ROTATE;break;default:this.state=K.NONE}break;default:this.state=K.NONE}this.state!==K.NONE&&this.dispatchEvent($t)}function Oi(o){switch(this._trackPointer(o),this.state){case K.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(o),this.update();break;case K.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(o),this.update();break;case K.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(o),this.update();break;case K.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(o),this.update();break;default:this.state=K.NONE}}function Wi(o){this.enabled!==!1&&o.preventDefault()}function $i(o){o.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Ui(o){o.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Bi(o){if(o.kind!=="building"||!o.parts.length)return[];const e=o.parts.map(ct).filter(({min:t,max:s})=>(s[1]<=1.2+1e-6||s[1]-t[1]<.3)&&s[0]-t[0]>1&&s[2]-t[2]>1);if(!e.length){const t=Qs(o);e.push({min:[t.min[0],0,t.min[2]],max:[t.max[0],0,t.max[2]]})}return e.map(({min:t,max:s})=>({x:(t[0]+s[0])/2,y:s[1]+.012,z:(t[2]+s[2])/2,width:(s[0]-t[0])*.96,depth:(s[2]-t[2])*.96}))}class _s{group=new he;material=new bs({uniforms:{night:{value:0},warmth:{value:new H("#ffb24d")},strength:{value:.34}},vertexShader:`varying vec2 lightUv;
2
2
  void main() { lightUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`,fragmentShader:`uniform float night; uniform vec3 warmth; uniform float strength; varying vec2 lightUv;
3
3
  void main() {
4
4
  vec2 p = lightUv * 2.0 - 1.0;
@@ -1 +1 @@
1
- import{B as L,G as $,N as E,ah as j,D as y,H as S,a6 as G}from"./index-CzmdQnci.js";var N={};class v{constructor(t,e,s,i,h,r,n,o,a,u=0,f){this.p=t,this.stack=e,this.state=s,this.reducePos=i,this.pos=h,this.score=r,this.buffer=n,this.bufferBase=o,this.curContext=a,this.lookAhead=u,this.parent=f}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let i=t.parser.context;return new v(t,[],e,s,s,0,[],0,i?new R(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,i=t&65535,{parser:h}=this.p,r=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),n=h.dynamicPrecedence(i);if(n&&(this.score+=n),s==0){i<h.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(h.getGoto(this.state,i,!0),this.reducePos),i<h.minRepeatTerm&&this.storeNode(i,this.reducePos,this.reducePos,r?8:4,!0),this.reduceContext(i,this.reducePos);return}let o=this.stack.length-(s-1)*3-(t&262144?6:0),a=o?this.stack[o-2]:this.p.ranges[0].from;i<h.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let u=this.reducePos-a;u>=2e3&&!(!((e=this.p.parser.nodeSet.types[i])===null||e===void 0)&&e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=u):this.p.lastBigReductionSize<u&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=u));let f=o?this.stack[o-1]:0,d=this.bufferBase+this.buffer.length-f;if(i<h.minRepeatTerm||t&131072){let c=h.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(i,a,c,d+4,!0)}if(t&262144)this.state=this.stack[o];else{let c=this.stack[o-3];this.state=h.getGoto(c,i,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(i,a)}storeNode(t,e,s,i=4,h=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let r=this.buffer.length;if(r>0&&this.buffer[r-4]==0&&this.buffer[r-1]>-1){if(e==s)return;if(this.buffer[r-2]>=e){this.buffer[r-2]=s;return}}}if(!h||this.pos==s)this.buffer.push(t,e,s,i);else{let r=this.buffer.length;if(r>0&&(this.buffer[r-4]!=0||this.buffer[r-1]<0)){let n=!1;for(let o=r;o>0&&this.buffer[o-2]>s;o-=4)if(this.buffer[o-1]>=0){n=!0;break}if(n)for(;r>0&&this.buffer[r-2]>s;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,i>4&&(i-=4)}this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=s,this.buffer[r+3]=i}}shift(t,e,s,i){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let h=t,{parser:r}=this.p;this.pos=i;let n=r.stateFlag(h,1);!n&&(i>s||e<=r.maxNode)&&(this.reducePos=i),this.pushState(h,n?s:Math.min(s,this.reducePos)),this.shiftContext(e,s),e<=r.maxNode&&this.buffer.push(e,s,i,4)}else this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4)}apply(t,e,s,i){t&65536?this.reduce(t):this.shift(t,e,s,i)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let i=this.pos;this.reducePos=this.pos=i+t.length,this.pushState(e,i),this.buffer.push(s,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),i=t.bufferBase+e;for(;t&&i==t.bufferBase;)t=t.parent;return new v(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,i,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new U(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(s==0)return!1;if((s&65536)==0)return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let h=0,r;h<e.length;h+=2)(r=e[h+1])!=this.state&&this.p.parser.hasAction(r,t)&&i.push(e[h],r);if(this.stack.length<120)for(let h=0;i.length<8&&h<e.length;h+=2){let r=e[h+1];i.some((n,o)=>o&1&&n==r)||i.push(e[h],r)}e=i}let s=[];for(let i=0;i<e.length&&s.length<4;i+=2){let h=e[i+1];if(h==this.state)continue;let r=this.split();r.pushState(h,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(e[i],this.pos),r.reducePos=this.pos,r.score-=200,s.push(r)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let s=e>>19,i=e&65535,h=this.stack.length-s*3;if(h<0||t.getGoto(this.stack[h],i,!1)<0){let r=this.findForcedReduction();if(r==null)return!1;e=r}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(i,h)=>{if(!e.includes(i))return e.push(i),t.allActions(i,r=>{if(!(r&393216))if(r&65536){let n=(r>>19)-h;if(n>1){let o=r&65535,a=this.stack.length-n*3;if(a>=0&&t.getGoto(this.stack[a],o,!1)>=0)return n<<19|65536|o}}else{let n=s(r,h+1);if(n!=null)return n}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new R(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class R{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class U{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,s=t>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=i}}class A{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new A(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new A(this.stack,this.pos,this.index)}}function x(l,t=Uint16Array){if(typeof l!="string")return l;let e=null;for(let s=0,i=0;s<l.length;){let h=0;for(;;){let r=l.charCodeAt(s++),n=!1;if(r==126){h=65535;break}r>=92&&r--,r>=34&&r--;let o=r-32;if(o>=46&&(o-=46,n=!0),h+=o,n)break;h*=46}e?e[i++]=h:e=new t(h)}return e}class P{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const z=new P;class H{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=z,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,i=this.rangeIndex,h=this.pos+t;for(;h<s.from;){if(!i)return null;let r=this.ranges[--i];h-=s.from-r.to,s=r}for(;e<0?h>s.to:h>=s.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];h+=r.from-s.to,s=r}return h}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,s,i;if(e>=0&&e<this.chunk.length)s=this.pos+t,i=this.chunk.charCodeAt(e);else{let h=this.resolveOffset(t,1);if(h==null)return-1;if(s=h,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let r=this.rangeIndex,n=this.range;for(;n.to<=s;)n=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>n.to&&(this.chunk2=this.chunk2.slice(0,n.to-s)),i=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),i}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=z,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let i of this.ranges){if(i.from>=e)break;i.to>t&&(s+=this.input.read(Math.max(i.from,t),Math.min(i.to,e)))}return s}}class m{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;O(this.data,t,e,this.id,s.data,s.tokenPrecTable)}}m.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class W{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?x(t):t}token(t,e){let s=t.pos,i=0;for(;;){let h=t.next<0,r=t.resolveOffset(1,1);if(O(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(h||i++,r==null)break;t.reset(r,t.token)}i&&(t.reset(s,t.token),t.acceptToken(this.elseToken,i))}}W.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class Z{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function O(l,t,e,s,i,h){let r=0,n=1<<s,{dialect:o}=e.p.parser;t:for(;(n&l[r])!=0;){let a=l[r+1];for(let c=r+3;c<a;c+=2)if((l[c+1]&n)>0){let p=l[c];if(o.allows(p)&&(t.token.value==-1||t.token.value==p||q(p,t.token.value,i,h))){t.acceptToken(p);break}}let u=t.next,f=0,d=l[r+2];if(t.next<0&&d>f&&l[a+d*3-3]==65535){r=l[a+d*3-1];continue t}for(;f<d;){let c=f+d>>1,p=a+c+(c<<1),b=l[p],M=l[p+1]||65536;if(u<b)d=c;else if(u>=M)f=c+1;else{r=l[p+2],t.advance();continue t}}break}}function I(l,t,e){for(let s=t,i;(i=l[s])!=65535;s++)if(i==e)return s-t;return-1}function q(l,t,e,s){let i=I(e,s,t);return i<0||I(e,s,l)<i}const g=typeof process<"u"&&N&&/\bparse\b/.test(N.LOG);let T=null;function D(l,t,e){let s=l.cursor(G.IncludeAnonymous);for(s.moveTo(t);;)if(!(e<0?s.childBefore(t):s.childAfter(t)))for(;;){if((e<0?s.to<t:s.from>t)&&!s.type.isError)return e<0?Math.max(0,Math.min(s.to-1,t-25)):Math.min(l.length,Math.max(s.from+1,t+25));if(e<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return e<0?0:l.length}}class J{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?D(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?D(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let s=this.trees[e],i=this.index[e];if(i==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let h=s.children[i],r=this.start[e]+s.positions[i];if(r>t)return this.nextStart=r,null;if(h instanceof S){if(r==t){if(r<this.safeFrom)return null;let n=r+h.length;if(n<=this.safeTo){let o=h.prop(y.lookAhead);if(!o||n+o<this.fragment.to)return h}}this.index[e]++,r+h.length>=Math.max(this.safeFrom,t)&&(this.trees.push(h),this.start.push(r),this.index.push(0))}else this.index[e]++,this.nextStart=r+h.length}}}class K{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new P)}getActions(t){let e=0,s=null,{parser:i}=t.p,{tokenizers:h}=i,r=i.stateSlot(t.state,3),n=t.curContext?t.curContext.hash:0,o=0;for(let a=0;a<h.length;a++){if((1<<a&r)==0)continue;let u=h[a],f=this.tokens[a];if(!(s&&!u.fallback)&&((u.contextual||f.start!=t.pos||f.mask!=r||f.context!=n)&&(this.updateCachedToken(f,u,t),f.mask=r,f.context=n),f.lookAhead>f.end+25&&(o=Math.max(f.lookAhead,o)),f.value!=0)){let d=e;if(f.extended>-1&&(e=this.addActions(t,f.extended,f.end,e)),e=this.addActions(t,f.value,f.end,e),!u.extend&&(s=f,e>d))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),!s&&t.pos==this.stream.end&&(s=new P,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new P,{pos:s,p:i}=t;return e.start=s,e.end=Math.min(s+1,i.stream.end),e.value=s==i.stream.end?i.parser.eofTerm:0,e}updateCachedToken(t,e,s){let i=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(i,t),s),t.value>-1){let{parser:h}=s.p;for(let r=0;r<h.specialized.length;r++)if(h.specialized[r]==t.value){let n=h.specializers[r](this.stream.read(t.start,t.end),s);if(n>=0&&s.p.parser.dialect.allows(n>>1)){(n&1)==0?t.value=n>>1:t.extended=n>>1;break}}}else t.value=0,t.end=this.stream.clipPos(i+1)}putAction(t,e,s,i){for(let h=0;h<i;h+=3)if(this.actions[h]==t)return i;return this.actions[i++]=t,this.actions[i++]=e,this.actions[i++]=s,i}addActions(t,e,s,i){let{state:h}=t,{parser:r}=t.p,{data:n}=r;for(let o=0;o<2;o++)for(let a=r.stateSlot(h,o?2:1);;a+=3){if(n[a]==65535)if(n[a+1]==1)a=k(n,a+2);else{i==0&&n[a+1]==2&&(i=this.putAction(k(n,a+2),e,s,i));break}n[a]==e&&(i=this.putAction(k(n,a+1),e,s,i))}return i}}class Q{constructor(t,e,s,i){this.parser=t,this.input=e,this.ranges=i,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new H(e,i),this.tokens=new K(t,this.stream),this.topTerm=t.top[1];let{from:h}=i[0];this.stacks=[v.start(this,t.top[0],h)],this.fragments=s.length&&this.stream.end-h>t.bufferLength*4?new J(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],i,h;if(this.bigReductionCount>300&&t.length==1){let[r]=t;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<t.length;r++){let n=t[r];for(;;){if(this.tokens.mainToken=null,n.pos>e)s.push(n);else{if(this.advanceStack(n,s,t))continue;{i||(i=[],h=[]),i.push(n);let o=this.tokens.getMainToken(n);h.push(o.value,o.end)}}break}}if(!s.length){let r=i&&X(i);if(r)return g&&console.log("Finish with "+this.stackID(r)),this.stackToTree(r);if(this.parser.strict)throw g&&i&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,h,s);if(r)return g&&console.log("Force-finish "+this.stackID(r)),this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(s.length>r)for(s.sort((n,o)=>o.score-n.score);s.length>r;)s.pop();s.some(n=>n.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let r=0;r<s.length-1;r++){let n=s[r];for(let o=r+1;o<s.length;o++){let a=s[o];if(n.sameState(a)||n.buffer.length>500&&a.buffer.length>500)if((n.score-a.score||n.buffer.length-a.buffer.length)>0)s.splice(o--,1);else{s.splice(r--,1);continue t}}}s.length>12&&(s.sort((r,n)=>n.score-r.score),s.splice(12,s.length-12))}this.minStackPos=s[0].pos;for(let r=1;r<s.length;r++)s[r].pos<this.minStackPos&&(this.minStackPos=s[r].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,s){let i=t.pos,{parser:h}=this,r=g?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,u=a?t.curContext.hash:0;for(let f=this.fragments.nodeAt(i);f;){let d=this.parser.nodeSet.types[f.type.id]==f.type?h.getGoto(t.state,f.type.id):-1;if(d>-1&&f.length&&(!a||(f.prop(y.contextHash)||0)==u))return t.useNode(f,d),g&&console.log(r+this.stackID(t)+` (via reuse of ${h.getName(f.type.id)})`),!0;if(!(f instanceof S)||f.children.length==0||f.positions[0]>0)break;let c=f.children[0];if(c instanceof S&&f.positions[0]==0)f=c;else break}}let n=h.stateSlot(t.state,4);if(n>0)return t.reduce(n),g&&console.log(r+this.stackID(t)+` (via always-reduce ${h.getName(n&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let o=this.tokens.getActions(t);for(let a=0;a<o.length;){let u=o[a++],f=o[a++],d=o[a++],c=a==o.length||!s,p=c?t:t.split(),b=this.tokens.mainToken;if(p.apply(u,f,b?b.start:p.pos,d),g&&console.log(r+this.stackID(p)+` (via ${(u&65536)==0?"shift":`reduce of ${h.getName(u&65535)}`} for ${h.getName(f)} @ ${i}${p==t?"":", split"})`),c)return!0;p.pos>i?e.push(p):s.push(p)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return B(t,e),!0}}runRecovery(t,e,s){let i=null,h=!1;for(let r=0;r<t.length;r++){let n=t[r],o=e[r<<1],a=e[(r<<1)+1],u=g?this.stackID(n)+" -> ":"";if(n.deadEnd&&(h||(h=!0,n.restart(),g&&console.log(u+this.stackID(n)+" (restarted)"),this.advanceFully(n,s))))continue;let f=n.split(),d=u;for(let c=0;c<10&&f.forceReduce()&&(g&&console.log(d+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,s));c++)g&&(d=this.stackID(f)+" -> ");for(let c of n.recoverByInsert(o))g&&console.log(u+this.stackID(c)+" (via recover-insert)"),this.advanceFully(c,s);this.stream.end>n.pos?(a==n.pos&&(a++,o=0),n.recoverByDelete(o,a),g&&console.log(u+this.stackID(n)+` (via recover-delete ${this.parser.getName(o)})`),B(n,s)):(!i||i.score<f.score)&&(i=f)}return i}stackToTree(t){return t.close(),S.build({buffer:A.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(T||(T=new WeakMap)).get(t);return e||T.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function B(l,t){for(let e=0;e<t.length;e++){let s=t[e];if(s.pos==l.pos&&s.sameState(l)){t[e].score<l.score&&(t[e]=l);return}}t.push(l)}class V{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}}const C=l=>l;class _{constructor(t){this.start=t.start,this.shift=t.shift||C,this.reduce=t.reduce||C,this.reuse=t.reuse||C,this.hash=t.hash||(()=>0),this.strict=t.strict!==!1}}class w extends L{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let n=0;n<t.repeatNodeCount;n++)e.push("");let s=Object.keys(t.topRules).map(n=>t.topRules[n][1]),i=[];for(let n=0;n<e.length;n++)i.push([]);function h(n,o,a){i[n].push([o,o.deserialize(String(a))])}if(t.nodeProps)for(let n of t.nodeProps){let o=n[0];typeof o=="string"&&(o=y[o]);for(let a=1;a<n.length;){let u=n[a++];if(u>=0)h(u,o,n[a++]);else{let f=n[a+-u];for(let d=-u;d>0;d--)h(n[a++],o,f);a++}}}this.nodeSet=new $(e.map((n,o)=>E.define({name:o>=this.minRepeatTerm?void 0:n,id:o,props:i[o],top:s.indexOf(o)>-1,error:o==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(o)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=j;let r=x(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let n=0;n<this.specializerSpecs.length;n++)this.specialized[n]=this.specializerSpecs[n].term;this.specializers=this.specializerSpecs.map(F),this.states=x(t.states,Uint32Array),this.data=x(t.stateData),this.goto=x(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(n=>typeof n=="number"?new m(r,n):n),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let i=new Q(this,t,e,s);for(let h of this.wrappers)i=h(i,t,e,s);return i}getGoto(t,e,s=!1){let i=this.goto;if(e>=i[0])return-1;for(let h=i[e+1];;){let r=i[h++],n=r&1,o=i[h++];if(n&&s)return o;for(let a=h+(r>>1);h<a;h++)if(i[h]==t)return o;if(n)return-1}}hasAction(t,e){let s=this.data;for(let i=0;i<2;i++)for(let h=this.stateSlot(t,i?2:1),r;;h+=3){if((r=s[h])==65535)if(s[h+1]==1)r=s[h=k(s,h+2)];else{if(s[h+1]==2)return k(s,h+2);break}if(r==e||r==0)return k(s,h+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,s=>s==e?!0:null)}allActions(t,e){let s=this.stateSlot(t,4),i=s?e(s):void 0;for(let h=this.stateSlot(t,1);i==null;h+=3){if(this.data[h]==65535)if(this.data[h+1]==1)h=k(this.data,h+2);else break;i=e(k(this.data,h+1))}return i}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=k(this.data,s+2);else break;if((this.data[s+2]&1)==0){let i=this.data[s+1];e.some((h,r)=>r&1&&h==i)||e.push(this.data[s],i)}}return e}configure(t){let e=Object.assign(Object.create(w.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(s=>{let i=t.tokenizers.find(h=>h.from==s);return i?i.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,i)=>{let h=t.specializers.find(n=>n.from==s.external);if(!h)return s;let r=Object.assign(Object.assign({},s),{external:h.to});return e.specializers[i]=F(r),r})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let h of t.split(" ")){let r=e.indexOf(h);r>=0&&(s[r]=!0)}let i=null;for(let h=0;h<e.length;h++)if(!s[h])for(let r=this.dialects[e[h]],n;(n=this.data[r++])!=65535;)(i||(i=new Uint8Array(this.maxTerm+1)))[n]=1;return new V(t,s,i)}static deserialize(t){return new w(t)}}function k(l,t){return l[t]|l[t+1]<<16}function X(l){let t=null;for(let e of l){let s=e.p.stoppedAt;(e.pos==e.p.stream.end||s!=null&&e.pos>s)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function F(l){if(l.external){let t=l.extend?1:0;return(e,s)=>l.external(e,s)<<1|t}return l.get}export{_ as C,Z as E,w as L,W as a};
1
+ import{B as L,G as $,N as E,ah as j,D as y,H as S,a6 as G}from"./index-BaadIo09.js";var N={};class v{constructor(t,e,s,i,h,r,n,o,a,u=0,f){this.p=t,this.stack=e,this.state=s,this.reducePos=i,this.pos=h,this.score=r,this.buffer=n,this.bufferBase=o,this.curContext=a,this.lookAhead=u,this.parent=f}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let i=t.parser.context;return new v(t,[],e,s,s,0,[],0,i?new R(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,i=t&65535,{parser:h}=this.p,r=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),n=h.dynamicPrecedence(i);if(n&&(this.score+=n),s==0){i<h.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(h.getGoto(this.state,i,!0),this.reducePos),i<h.minRepeatTerm&&this.storeNode(i,this.reducePos,this.reducePos,r?8:4,!0),this.reduceContext(i,this.reducePos);return}let o=this.stack.length-(s-1)*3-(t&262144?6:0),a=o?this.stack[o-2]:this.p.ranges[0].from;i<h.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let u=this.reducePos-a;u>=2e3&&!(!((e=this.p.parser.nodeSet.types[i])===null||e===void 0)&&e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=u):this.p.lastBigReductionSize<u&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=u));let f=o?this.stack[o-1]:0,d=this.bufferBase+this.buffer.length-f;if(i<h.minRepeatTerm||t&131072){let c=h.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(i,a,c,d+4,!0)}if(t&262144)this.state=this.stack[o];else{let c=this.stack[o-3];this.state=h.getGoto(c,i,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(i,a)}storeNode(t,e,s,i=4,h=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let r=this.buffer.length;if(r>0&&this.buffer[r-4]==0&&this.buffer[r-1]>-1){if(e==s)return;if(this.buffer[r-2]>=e){this.buffer[r-2]=s;return}}}if(!h||this.pos==s)this.buffer.push(t,e,s,i);else{let r=this.buffer.length;if(r>0&&(this.buffer[r-4]!=0||this.buffer[r-1]<0)){let n=!1;for(let o=r;o>0&&this.buffer[o-2]>s;o-=4)if(this.buffer[o-1]>=0){n=!0;break}if(n)for(;r>0&&this.buffer[r-2]>s;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,i>4&&(i-=4)}this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=s,this.buffer[r+3]=i}}shift(t,e,s,i){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let h=t,{parser:r}=this.p;this.pos=i;let n=r.stateFlag(h,1);!n&&(i>s||e<=r.maxNode)&&(this.reducePos=i),this.pushState(h,n?s:Math.min(s,this.reducePos)),this.shiftContext(e,s),e<=r.maxNode&&this.buffer.push(e,s,i,4)}else this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4)}apply(t,e,s,i){t&65536?this.reduce(t):this.shift(t,e,s,i)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let i=this.pos;this.reducePos=this.pos=i+t.length,this.pushState(e,i),this.buffer.push(s,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),i=t.bufferBase+e;for(;t&&i==t.bufferBase;)t=t.parent;return new v(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,i,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new U(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(s==0)return!1;if((s&65536)==0)return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let h=0,r;h<e.length;h+=2)(r=e[h+1])!=this.state&&this.p.parser.hasAction(r,t)&&i.push(e[h],r);if(this.stack.length<120)for(let h=0;i.length<8&&h<e.length;h+=2){let r=e[h+1];i.some((n,o)=>o&1&&n==r)||i.push(e[h],r)}e=i}let s=[];for(let i=0;i<e.length&&s.length<4;i+=2){let h=e[i+1];if(h==this.state)continue;let r=this.split();r.pushState(h,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(e[i],this.pos),r.reducePos=this.pos,r.score-=200,s.push(r)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let s=e>>19,i=e&65535,h=this.stack.length-s*3;if(h<0||t.getGoto(this.stack[h],i,!1)<0){let r=this.findForcedReduction();if(r==null)return!1;e=r}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(i,h)=>{if(!e.includes(i))return e.push(i),t.allActions(i,r=>{if(!(r&393216))if(r&65536){let n=(r>>19)-h;if(n>1){let o=r&65535,a=this.stack.length-n*3;if(a>=0&&t.getGoto(this.stack[a],o,!1)>=0)return n<<19|65536|o}}else{let n=s(r,h+1);if(n!=null)return n}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new R(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class R{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class U{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,s=t>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=i}}class A{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new A(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new A(this.stack,this.pos,this.index)}}function x(l,t=Uint16Array){if(typeof l!="string")return l;let e=null;for(let s=0,i=0;s<l.length;){let h=0;for(;;){let r=l.charCodeAt(s++),n=!1;if(r==126){h=65535;break}r>=92&&r--,r>=34&&r--;let o=r-32;if(o>=46&&(o-=46,n=!0),h+=o,n)break;h*=46}e?e[i++]=h:e=new t(h)}return e}class P{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const z=new P;class H{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=z,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,i=this.rangeIndex,h=this.pos+t;for(;h<s.from;){if(!i)return null;let r=this.ranges[--i];h-=s.from-r.to,s=r}for(;e<0?h>s.to:h>=s.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];h+=r.from-s.to,s=r}return h}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,s,i;if(e>=0&&e<this.chunk.length)s=this.pos+t,i=this.chunk.charCodeAt(e);else{let h=this.resolveOffset(t,1);if(h==null)return-1;if(s=h,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let r=this.rangeIndex,n=this.range;for(;n.to<=s;)n=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>n.to&&(this.chunk2=this.chunk2.slice(0,n.to-s)),i=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),i}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=z,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let i of this.ranges){if(i.from>=e)break;i.to>t&&(s+=this.input.read(Math.max(i.from,t),Math.min(i.to,e)))}return s}}class m{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;O(this.data,t,e,this.id,s.data,s.tokenPrecTable)}}m.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class W{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?x(t):t}token(t,e){let s=t.pos,i=0;for(;;){let h=t.next<0,r=t.resolveOffset(1,1);if(O(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(h||i++,r==null)break;t.reset(r,t.token)}i&&(t.reset(s,t.token),t.acceptToken(this.elseToken,i))}}W.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class Z{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function O(l,t,e,s,i,h){let r=0,n=1<<s,{dialect:o}=e.p.parser;t:for(;(n&l[r])!=0;){let a=l[r+1];for(let c=r+3;c<a;c+=2)if((l[c+1]&n)>0){let p=l[c];if(o.allows(p)&&(t.token.value==-1||t.token.value==p||q(p,t.token.value,i,h))){t.acceptToken(p);break}}let u=t.next,f=0,d=l[r+2];if(t.next<0&&d>f&&l[a+d*3-3]==65535){r=l[a+d*3-1];continue t}for(;f<d;){let c=f+d>>1,p=a+c+(c<<1),b=l[p],M=l[p+1]||65536;if(u<b)d=c;else if(u>=M)f=c+1;else{r=l[p+2],t.advance();continue t}}break}}function I(l,t,e){for(let s=t,i;(i=l[s])!=65535;s++)if(i==e)return s-t;return-1}function q(l,t,e,s){let i=I(e,s,t);return i<0||I(e,s,l)<i}const g=typeof process<"u"&&N&&/\bparse\b/.test(N.LOG);let T=null;function D(l,t,e){let s=l.cursor(G.IncludeAnonymous);for(s.moveTo(t);;)if(!(e<0?s.childBefore(t):s.childAfter(t)))for(;;){if((e<0?s.to<t:s.from>t)&&!s.type.isError)return e<0?Math.max(0,Math.min(s.to-1,t-25)):Math.min(l.length,Math.max(s.from+1,t+25));if(e<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return e<0?0:l.length}}class J{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?D(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?D(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let s=this.trees[e],i=this.index[e];if(i==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let h=s.children[i],r=this.start[e]+s.positions[i];if(r>t)return this.nextStart=r,null;if(h instanceof S){if(r==t){if(r<this.safeFrom)return null;let n=r+h.length;if(n<=this.safeTo){let o=h.prop(y.lookAhead);if(!o||n+o<this.fragment.to)return h}}this.index[e]++,r+h.length>=Math.max(this.safeFrom,t)&&(this.trees.push(h),this.start.push(r),this.index.push(0))}else this.index[e]++,this.nextStart=r+h.length}}}class K{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new P)}getActions(t){let e=0,s=null,{parser:i}=t.p,{tokenizers:h}=i,r=i.stateSlot(t.state,3),n=t.curContext?t.curContext.hash:0,o=0;for(let a=0;a<h.length;a++){if((1<<a&r)==0)continue;let u=h[a],f=this.tokens[a];if(!(s&&!u.fallback)&&((u.contextual||f.start!=t.pos||f.mask!=r||f.context!=n)&&(this.updateCachedToken(f,u,t),f.mask=r,f.context=n),f.lookAhead>f.end+25&&(o=Math.max(f.lookAhead,o)),f.value!=0)){let d=e;if(f.extended>-1&&(e=this.addActions(t,f.extended,f.end,e)),e=this.addActions(t,f.value,f.end,e),!u.extend&&(s=f,e>d))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),!s&&t.pos==this.stream.end&&(s=new P,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new P,{pos:s,p:i}=t;return e.start=s,e.end=Math.min(s+1,i.stream.end),e.value=s==i.stream.end?i.parser.eofTerm:0,e}updateCachedToken(t,e,s){let i=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(i,t),s),t.value>-1){let{parser:h}=s.p;for(let r=0;r<h.specialized.length;r++)if(h.specialized[r]==t.value){let n=h.specializers[r](this.stream.read(t.start,t.end),s);if(n>=0&&s.p.parser.dialect.allows(n>>1)){(n&1)==0?t.value=n>>1:t.extended=n>>1;break}}}else t.value=0,t.end=this.stream.clipPos(i+1)}putAction(t,e,s,i){for(let h=0;h<i;h+=3)if(this.actions[h]==t)return i;return this.actions[i++]=t,this.actions[i++]=e,this.actions[i++]=s,i}addActions(t,e,s,i){let{state:h}=t,{parser:r}=t.p,{data:n}=r;for(let o=0;o<2;o++)for(let a=r.stateSlot(h,o?2:1);;a+=3){if(n[a]==65535)if(n[a+1]==1)a=k(n,a+2);else{i==0&&n[a+1]==2&&(i=this.putAction(k(n,a+2),e,s,i));break}n[a]==e&&(i=this.putAction(k(n,a+1),e,s,i))}return i}}class Q{constructor(t,e,s,i){this.parser=t,this.input=e,this.ranges=i,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new H(e,i),this.tokens=new K(t,this.stream),this.topTerm=t.top[1];let{from:h}=i[0];this.stacks=[v.start(this,t.top[0],h)],this.fragments=s.length&&this.stream.end-h>t.bufferLength*4?new J(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],i,h;if(this.bigReductionCount>300&&t.length==1){let[r]=t;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<t.length;r++){let n=t[r];for(;;){if(this.tokens.mainToken=null,n.pos>e)s.push(n);else{if(this.advanceStack(n,s,t))continue;{i||(i=[],h=[]),i.push(n);let o=this.tokens.getMainToken(n);h.push(o.value,o.end)}}break}}if(!s.length){let r=i&&X(i);if(r)return g&&console.log("Finish with "+this.stackID(r)),this.stackToTree(r);if(this.parser.strict)throw g&&i&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,h,s);if(r)return g&&console.log("Force-finish "+this.stackID(r)),this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(s.length>r)for(s.sort((n,o)=>o.score-n.score);s.length>r;)s.pop();s.some(n=>n.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let r=0;r<s.length-1;r++){let n=s[r];for(let o=r+1;o<s.length;o++){let a=s[o];if(n.sameState(a)||n.buffer.length>500&&a.buffer.length>500)if((n.score-a.score||n.buffer.length-a.buffer.length)>0)s.splice(o--,1);else{s.splice(r--,1);continue t}}}s.length>12&&(s.sort((r,n)=>n.score-r.score),s.splice(12,s.length-12))}this.minStackPos=s[0].pos;for(let r=1;r<s.length;r++)s[r].pos<this.minStackPos&&(this.minStackPos=s[r].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,s){let i=t.pos,{parser:h}=this,r=g?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,u=a?t.curContext.hash:0;for(let f=this.fragments.nodeAt(i);f;){let d=this.parser.nodeSet.types[f.type.id]==f.type?h.getGoto(t.state,f.type.id):-1;if(d>-1&&f.length&&(!a||(f.prop(y.contextHash)||0)==u))return t.useNode(f,d),g&&console.log(r+this.stackID(t)+` (via reuse of ${h.getName(f.type.id)})`),!0;if(!(f instanceof S)||f.children.length==0||f.positions[0]>0)break;let c=f.children[0];if(c instanceof S&&f.positions[0]==0)f=c;else break}}let n=h.stateSlot(t.state,4);if(n>0)return t.reduce(n),g&&console.log(r+this.stackID(t)+` (via always-reduce ${h.getName(n&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let o=this.tokens.getActions(t);for(let a=0;a<o.length;){let u=o[a++],f=o[a++],d=o[a++],c=a==o.length||!s,p=c?t:t.split(),b=this.tokens.mainToken;if(p.apply(u,f,b?b.start:p.pos,d),g&&console.log(r+this.stackID(p)+` (via ${(u&65536)==0?"shift":`reduce of ${h.getName(u&65535)}`} for ${h.getName(f)} @ ${i}${p==t?"":", split"})`),c)return!0;p.pos>i?e.push(p):s.push(p)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return B(t,e),!0}}runRecovery(t,e,s){let i=null,h=!1;for(let r=0;r<t.length;r++){let n=t[r],o=e[r<<1],a=e[(r<<1)+1],u=g?this.stackID(n)+" -> ":"";if(n.deadEnd&&(h||(h=!0,n.restart(),g&&console.log(u+this.stackID(n)+" (restarted)"),this.advanceFully(n,s))))continue;let f=n.split(),d=u;for(let c=0;c<10&&f.forceReduce()&&(g&&console.log(d+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,s));c++)g&&(d=this.stackID(f)+" -> ");for(let c of n.recoverByInsert(o))g&&console.log(u+this.stackID(c)+" (via recover-insert)"),this.advanceFully(c,s);this.stream.end>n.pos?(a==n.pos&&(a++,o=0),n.recoverByDelete(o,a),g&&console.log(u+this.stackID(n)+` (via recover-delete ${this.parser.getName(o)})`),B(n,s)):(!i||i.score<f.score)&&(i=f)}return i}stackToTree(t){return t.close(),S.build({buffer:A.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(T||(T=new WeakMap)).get(t);return e||T.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function B(l,t){for(let e=0;e<t.length;e++){let s=t[e];if(s.pos==l.pos&&s.sameState(l)){t[e].score<l.score&&(t[e]=l);return}}t.push(l)}class V{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}}const C=l=>l;class _{constructor(t){this.start=t.start,this.shift=t.shift||C,this.reduce=t.reduce||C,this.reuse=t.reuse||C,this.hash=t.hash||(()=>0),this.strict=t.strict!==!1}}class w extends L{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let n=0;n<t.repeatNodeCount;n++)e.push("");let s=Object.keys(t.topRules).map(n=>t.topRules[n][1]),i=[];for(let n=0;n<e.length;n++)i.push([]);function h(n,o,a){i[n].push([o,o.deserialize(String(a))])}if(t.nodeProps)for(let n of t.nodeProps){let o=n[0];typeof o=="string"&&(o=y[o]);for(let a=1;a<n.length;){let u=n[a++];if(u>=0)h(u,o,n[a++]);else{let f=n[a+-u];for(let d=-u;d>0;d--)h(n[a++],o,f);a++}}}this.nodeSet=new $(e.map((n,o)=>E.define({name:o>=this.minRepeatTerm?void 0:n,id:o,props:i[o],top:s.indexOf(o)>-1,error:o==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(o)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=j;let r=x(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let n=0;n<this.specializerSpecs.length;n++)this.specialized[n]=this.specializerSpecs[n].term;this.specializers=this.specializerSpecs.map(F),this.states=x(t.states,Uint32Array),this.data=x(t.stateData),this.goto=x(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(n=>typeof n=="number"?new m(r,n):n),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let i=new Q(this,t,e,s);for(let h of this.wrappers)i=h(i,t,e,s);return i}getGoto(t,e,s=!1){let i=this.goto;if(e>=i[0])return-1;for(let h=i[e+1];;){let r=i[h++],n=r&1,o=i[h++];if(n&&s)return o;for(let a=h+(r>>1);h<a;h++)if(i[h]==t)return o;if(n)return-1}}hasAction(t,e){let s=this.data;for(let i=0;i<2;i++)for(let h=this.stateSlot(t,i?2:1),r;;h+=3){if((r=s[h])==65535)if(s[h+1]==1)r=s[h=k(s,h+2)];else{if(s[h+1]==2)return k(s,h+2);break}if(r==e||r==0)return k(s,h+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,s=>s==e?!0:null)}allActions(t,e){let s=this.stateSlot(t,4),i=s?e(s):void 0;for(let h=this.stateSlot(t,1);i==null;h+=3){if(this.data[h]==65535)if(this.data[h+1]==1)h=k(this.data,h+2);else break;i=e(k(this.data,h+1))}return i}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=k(this.data,s+2);else break;if((this.data[s+2]&1)==0){let i=this.data[s+1];e.some((h,r)=>r&1&&h==i)||e.push(this.data[s],i)}}return e}configure(t){let e=Object.assign(Object.create(w.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(s=>{let i=t.tokenizers.find(h=>h.from==s);return i?i.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,i)=>{let h=t.specializers.find(n=>n.from==s.external);if(!h)return s;let r=Object.assign(Object.assign({},s),{external:h.to});return e.specializers[i]=F(r),r})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let h of t.split(" ")){let r=e.indexOf(h);r>=0&&(s[r]=!0)}let i=null;for(let h=0;h<e.length;h++)if(!s[h])for(let r=this.dialects[e[h]],n;(n=this.data[r++])!=65535;)(i||(i=new Uint8Array(this.maxTerm+1)))[n]=1;return new V(t,s,i)}static deserialize(t){return new w(t)}}function k(l,t){return l[t]|l[t+1]<<16}function X(l){let t=null;for(let e of l){let s=e.p.stoppedAt;(e.pos==e.p.stream.end||s!=null&&e.pos>s)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function F(l){if(l.external){let t=l.extend?1:0;return(e,s)=>l.external(e,s)<<1|t}return l.get}export{_ as C,Z as E,w as L,W as a};