@aiworker/web 1.23.0 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-B1Gizi3a.js → CodeMirrorCommentWidgets-teB3HmBT.js} +1 -1
  2. package/dist/assets/DiffView-DC9RX3MF.js +4 -0
  3. package/dist/assets/{DirtyBranchSwitchDialog-aig6zJjg.js → DirtyBranchSwitchDialog-DwPkzXsS.js} +1 -1
  4. package/dist/assets/FilesView-BFZkuu4O.js +13 -0
  5. package/dist/assets/{GitView-BXsS3jG6.js → GitView-B_x52MHY.js} +4 -4
  6. package/dist/assets/{JsonTreeView-D_hpXBnF.js → JsonTreeView-cmAzUTiw.js} +1 -1
  7. package/dist/assets/{LinearIssuesView-BoUiLQG1.js → LinearIssuesView-Dehh5afm.js} +1 -1
  8. package/dist/assets/{MarkdownImageGallery-B_B_a9KS.js → MarkdownImageGallery-DgNOqqhE.js} +1 -1
  9. package/dist/assets/{MarkdownRendererImpl-xgyyLiBM.js → MarkdownRendererImpl-DusmMZ_p.js} +2 -2
  10. package/dist/assets/{OnboardingScreen-DIp84OWt.js → OnboardingScreen-B8fm1H4m.js} +1 -1
  11. package/dist/assets/{PatchDiff-8p6nLJaU.js → PatchDiff-BVr7gJU0.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-DjC8nTk9.js → PierreDiffViewer-DzLt-nel.js} +1 -1
  13. package/dist/assets/PlanView-BmQUYT_z.js +5 -0
  14. package/dist/assets/SettingsView-ChWmAcZT.js +28 -0
  15. package/dist/assets/{SettingsWindow-Cpb4hM6q.js → SettingsWindow-Dy3M6ZB9.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-DfaKZXNU.js → ToolOutputDialog-cTl_eLIH.js} +6 -6
  17. package/dist/assets/{ToolPartDiffPreview-DtZLzrSK.js → ToolPartDiffPreview-C_3iYNJQ.js} +2 -2
  18. package/dist/assets/{VirtualizedFileDiff-C8i9HpTB.js → VirtualizedFileDiff-CAWthkoy.js} +4 -4
  19. package/dist/assets/WalkthroughView-C7AHOpCA.js +4 -0
  20. package/dist/assets/{computeVirtualFileMetrics-BBI7ZwrC.js → computeVirtualFileMetrics-BkiDSlTW.js} +2 -2
  21. package/dist/assets/de-DJsQr-p7.js +10 -0
  22. package/dist/assets/es-BuYMlA9g.js +16 -0
  23. package/dist/assets/fr-ePDay33C.js +14 -0
  24. package/dist/assets/index-BD8ILbxF.js +40 -0
  25. package/dist/assets/{index-jXSK5RrB.js → index-n6O3hklM.js} +1 -1
  26. package/dist/assets/index-zhgg-SDz.css +1 -0
  27. package/dist/assets/{isDiffPlainText-B_x_rVon.js → isDiffPlainText-GMdPz-71.js} +1 -1
  28. package/dist/assets/{isFilePlainText-DW_xMer1.js → isFilePlainText-BVuH1zH9.js} +1 -1
  29. package/dist/assets/ja-BzR9xOY_.js +16 -0
  30. package/dist/assets/{ko-idhXGF8j.js → ko-BEjHAm14.js} +3 -3
  31. package/dist/assets/main-BydQ1tr_.js +930 -0
  32. package/dist/assets/{main-CzdPuL0s.js → main-D3ZDQglc.js} +2 -2
  33. package/dist/assets/{markdownCore-Cn4Tyejo.js → markdownCore-Cb2MdZnV.js} +3 -3
  34. package/dist/assets/{miniChat-CCkqKOLp.js → miniChat-d01k801U.js} +2 -2
  35. package/dist/assets/{mobile-mvxTo055.js → mobile-D7VV-Ufz.js} +2 -2
  36. package/dist/assets/patchFileDiff-CdztVMz0.js +13 -0
  37. package/dist/assets/{pl-CGZWUqZJ.js → pl-rQmpxNIF.js} +3 -3
  38. package/dist/assets/pt-BR-CorbsSW-.js +16 -0
  39. package/dist/assets/renderElectronMiniChatApp-BGG9UIlh.js +2 -0
  40. package/dist/assets/renderMobileApp-BRP3J1iv.js +25 -0
  41. package/dist/assets/runtimeEndpointReset-BhT_-c52.js +41 -0
  42. package/dist/assets/scheduledTasksApi-BEuUF_cj.js +1 -0
  43. package/dist/assets/{shikiHighlight-CRl0SUC9.js → shikiHighlight-BzXUjlby.js} +1 -1
  44. package/dist/assets/surface-COKb77Ua.js +1 -0
  45. package/dist/assets/tr-CoAMXPtI.js +7 -0
  46. package/dist/assets/uk-YlAX0rRU.js +16 -0
  47. package/dist/assets/{useAppFontEffects-CPKeOpUo.js → useAppFontEffects-Cwyhjfl5.js} +153 -155
  48. package/dist/assets/useGitComparison-BCZVefdE.js +1 -0
  49. package/dist/assets/{useInlineCommentController-BiWz4AVb.js → useInlineCommentController-DDkpBEU8.js} +2 -2
  50. package/dist/assets/{useRootScrollLock-BS4-kr7P.js → useRootScrollLock-CwjoWuC4.js} +1 -1
  51. package/dist/assets/{vendor-base-ui-DdV8vhHn.js → vendor-base-ui-BY_5qla_.js} +1 -1
  52. package/dist/assets/{vendor-codemirror-language-data-Bg4AEeCr.js → vendor-codemirror-language-data-Cb1YnICj.js} +2 -2
  53. package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
  54. package/dist/assets/{vendor-zod-BPAANqvH.js → vendor-zod-B6551dwG.js} +2 -2
  55. package/dist/assets/{web-components-z7hfnS8n.js → web-components-LV3vjTxy.js} +1 -1
  56. package/dist/assets/zh-CN-DDYg0Jl7.js +16 -0
  57. package/dist/assets/zh-TW-CQKaCayr.js +16 -0
  58. package/dist/index.html +4 -4
  59. package/dist/mini-chat.html +4 -4
  60. package/dist/mobile.html +4 -4
  61. package/package.json +1 -1
  62. package/server/index.js +3 -13
  63. package/server/lib/agent-memory/runtime.js +7 -2
  64. package/server/lib/agent-memory/runtime.test.js +22 -0
  65. package/server/lib/event-stream/DOCUMENTATION.md +3 -0
  66. package/server/lib/event-stream/global-hub.js +29 -4
  67. package/server/lib/event-stream/global-hub.test.js +22 -0
  68. package/server/lib/event-stream/global-ws-bridge.js +15 -18
  69. package/server/lib/event-stream/protocol.js +21 -7
  70. package/server/lib/event-stream/runtime.js +9 -6
  71. package/server/lib/event-stream/runtime.test.js +60 -0
  72. package/server/lib/git/DOCUMENTATION.md +10 -1
  73. package/server/lib/git/routes.js +21 -8
  74. package/server/lib/git/routes.test.js +78 -0
  75. package/server/lib/git/service.js +159 -4
  76. package/server/lib/git/service.test.js +74 -0
  77. package/server/lib/github/DOCUMENTATION.md +5 -0
  78. package/server/lib/github/routes.js +2 -2
  79. package/server/lib/message-queue/DOCUMENTATION.md +7 -0
  80. package/server/lib/message-queue/runtime.js +13 -0
  81. package/server/lib/message-queue/runtime.test.js +31 -1
  82. package/server/lib/notifications/DOCUMENTATION.md +1 -1
  83. package/server/lib/notifications/emitter-runtime.js +4 -3
  84. package/server/lib/opencode/DOCUMENTATION.md +18 -4
  85. package/server/lib/opencode/env-runtime.js +5 -1
  86. package/server/lib/opencode/env-runtime.test.js +72 -0
  87. package/server/lib/opencode/feature-routes-runtime.js +15 -1
  88. package/server/lib/opencode/lifecycle.js +4 -3
  89. package/server/lib/opencode/lifecycle.test.js +29 -0
  90. package/server/lib/opencode/managed-plugin-config.js +1 -1
  91. package/server/lib/opencode/proxy.js +33 -0
  92. package/server/lib/opencode/settings-helpers.js +3 -0
  93. package/server/lib/opencode/settings-helpers.test.js +11 -1
  94. package/server/lib/opencode/settings-registry.json +3 -0
  95. package/server/lib/opencode/settings-runtime.js +36 -9
  96. package/server/lib/opencode/settings-runtime.test.js +158 -2
  97. package/server/lib/project-context/DOCUMENTATION.md +13 -3
  98. package/server/lib/project-context/runtime.js +8 -2
  99. package/server/lib/project-context/runtime.test.js +54 -0
  100. package/server/lib/projects/DOCUMENTATION.md +2 -1
  101. package/server/lib/projects/project-config.js +38 -9
  102. package/server/lib/projects/project-config.test.js +97 -0
  103. package/server/lib/projects/project-id.js +26 -0
  104. package/server/lib/relay/DOCUMENTATION.md +20 -0
  105. package/server/lib/relay/host-client.js +7 -0
  106. package/server/lib/relay/host-client.test.js +14 -0
  107. package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
  108. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
  109. package/server/lib/scheduled-tasks/runtime.js +12 -2
  110. package/server/lib/scheduled-tasks/runtime.test.js +53 -0
  111. package/server/lib/session-assist/DOCUMENTATION.md +131 -66
  112. package/server/lib/session-assist/context.js +127 -0
  113. package/server/lib/session-assist/context.test.js +132 -0
  114. package/server/lib/session-assist/prompt.js +54 -0
  115. package/server/lib/session-assist/runtime.js +111 -257
  116. package/server/lib/session-assist/runtime.test.js +203 -0
  117. package/server/lib/walkthrough/DOCUMENTATION.md +15 -5
  118. package/server/lib/walkthrough/pr-source.test.js +21 -0
  119. package/server/lib/walkthrough/pull-request.js +7 -4
  120. package/server/lib/walkthrough/pull-request.test.js +16 -0
  121. package/server/lib/walkthrough/routes.js +19 -0
  122. package/server/lib/walkthrough/routes.test.js +26 -0
  123. package/server/lib/walkthrough/sources.js +13 -2
  124. package/server/opencode-worktree-readiness.test.js +130 -0
  125. package/dist/assets/DiffView-DXjVsEOw.js +0 -4
  126. package/dist/assets/FilesView-CJdG0-wk.js +0 -17
  127. package/dist/assets/PlanView-CJTmOF6I.js +0 -5
  128. package/dist/assets/SettingsView-DD-JqIJx.js +0 -28
  129. package/dist/assets/WalkthroughView-DeKMvZlL.js +0 -4
  130. package/dist/assets/de-DCrsQ5zS.js +0 -10
  131. package/dist/assets/es-Dwv4YfH6.js +0 -16
  132. package/dist/assets/fr-BCWg4Cnx.js +0 -14
  133. package/dist/assets/index-B68h5S5B.css +0 -1
  134. package/dist/assets/index-DVwMarHI.js +0 -39
  135. package/dist/assets/ja-Bruw3RYC.js +0 -16
  136. package/dist/assets/main-BkyaQhJX.js +0 -930
  137. package/dist/assets/patchFileDiff-Csk4iNUi.js +0 -13
  138. package/dist/assets/pt-BR-B8V7u7tA.js +0 -16
  139. package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +0 -2
  140. package/dist/assets/renderMobileApp-B48CsP4r.js +0 -25
  141. package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +0 -17
  142. package/dist/assets/scheduledTasksApi-BW0Etzwz.js +0 -1
  143. package/dist/assets/surface-oMvhsog3.js +0 -1
  144. package/dist/assets/tr-BK_KiO2V.js +0 -7
  145. package/dist/assets/uk-CG74xV8N.js +0 -16
  146. package/dist/assets/useGitComparison-DH220WmO.js +0 -1
  147. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
  148. package/dist/assets/zh-CN-T4AXofZI.js +0 -16
  149. package/dist/assets/zh-TW-Dte40sxp.js +0 -16
  150. package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
  151. package/server/lib/mcp-reconnect/runtime.js +0 -122
  152. package/server/lib/mcp-reconnect/runtime.test.js +0 -140
@@ -0,0 +1 @@
1
+ import{q as M,D as j,E as R,dA as L,h as I}from"./index-BD8ILbxF.js";import{c as U}from"./vendor-zustand-BAGL70zf.js";const A=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"vscode-insiders",label:"VS Code Insiders",appName:"Visual Studio Code - Insiders"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],_="finder",v=new Set(["finder","terminal"]),D=e=>{if(typeof window>"u")return e;const a=window.__AIWORKER_PLATFORM__;if(e.id==="finder"){if(a==="win32")return{...e,label:"Explorer",appName:"File Explorer"};if(a==="linux")return{...e,label:"File Manager"}}return e},T=e=>{if(!e)return null;const a=A.find(t=>t.id===e)??null;return a?D(a):null},N=()=>A.filter(e=>v.has(e.id)).map(e=>({...D(e)})),V=()=>{if(typeof window>"u")return _;const e=window.localStorage.getItem("openInAppId");return e&&T(e)?e:_};let E=!1,y=!1,m=!1,h=0,S=null;const x=()=>{S&&(clearTimeout(S),S=null)},K=U()((e,a)=>({selectedAppId:V(),availableApps:N(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(E||typeof window>"u")return;E=!0;const t=(o,d=!0)=>{if(!Array.isArray(o)||o.length===0){e({availableApps:N(),hasLoadedApps:d});return}const f=new Set(o.map(l=>l.name)),u=new Map(o.map(l=>[l.name,l.iconDataUrl??void 0])),b=A.filter(l=>f.has(l.appName)||v.has(l.id)).map(l=>({...D(l),iconDataUrl:u.get(l.appName)}));e({availableApps:b,hasLoadedApps:!0})},s=async o=>{if(!j()||!R()||y||a().hasLoadedApps&&!o)return;const f=A.map(u=>u.appName);x(),y=!0,m=!1,e({isScanning:!0});try{const{apps:u,success:r,hasCache:b,isCacheStale:l}=await L(f,o),P=r&&!b&&u.length===0&&h<3;if(e({isCacheStale:b?l:!1}),t(u,r?!P:!1),r){if(P){const k=[800,1600,3200][h]??3200;h+=1,m=!0,S=setTimeout(()=>{s()},k);return}h=0,m=!1;return}if(h<3){const k=[1e3,3e3,7e3][h]??7e3;h+=1,m=!0,S=setTimeout(()=>{s()},k)}}finally{y=!1,m||e({isScanning:!1})}};s();const n=o=>{const d=o.detail?.settings,f=d&&typeof d.openInAppId=="string"&&d.openInAppId.length>0&&T(d.openInAppId)?d.openInAppId:null;f&&(window.localStorage.setItem("openInAppId",f),e({selectedAppId:f}))},i=()=>{s()},p=o=>{const d=o.detail;Array.isArray(d)&&(h=3,m=!1,e({isScanning:!1,isCacheStale:!1}),t(d))};window.addEventListener("aiworker:settings-synced",n),window.addEventListener("aiworker:app-ready",i),window.addEventListener("aiworker:installed-apps-updated",p),window.__aiworkerAppReady&&s(),window.setTimeout(()=>{a().hasLoadedApps||s()},5e3)},loadInstalledApps:async t=>{if(E||a().initialize(),!j()||!R()||y||a().hasLoadedApps&&!t)return;const n=A.map(i=>i.appName);x(),t&&e({hasLoadedApps:!1}),y=!0,m=!1,e({isScanning:!0});try{const{apps:i,hasCache:p,isCacheStale:c}=await L(n,t),o=new Set(i.map(r=>r.name)),d=new Map(i.map(r=>[r.name,r.iconDataUrl??void 0])),u=A.filter(r=>o.has(r.appName)||v.has(r.id)).map(r=>({...r,iconDataUrl:d.get(r.appName)}));e({availableApps:u.length>0?u:N(),hasLoadedApps:u.length>0,isCacheStale:p?c:!1})}finally{y=!1,m||e({isScanning:!1})}},selectApp:async t=>{T(t)&&(e({selectedAppId:t}),typeof window<"u"&&window.localStorage.setItem("openInAppId",t),await M({openInAppId:t}))}}));class q{pending=new Map;has(a){return this.pending.has(a)}clear(){this.pending.clear()}run(a,t,s=!1){const n=this.pending.get(a);if(n&&!s)return n;const i=()=>this.pending.get(a)===p,p=Promise.resolve().then(()=>i()?t(i):void 0).finally(()=>{i()&&this.pending.delete(a)});return this.pending.set(a,p),p}}const z=(e,a)=>e===a||e.length===a.length&&e.every((t,s)=>{const n=a[s];return t.name===n.name&&t.path===n.path&&t.type===n.type&&t.extension===n.extension&&t.relativePath===n.relativePath}),H=e=>{const a=new Map,t=new Map;for(const s of e){a.has(s.path)||a.set(s.path,s.index==="A"||s.working_dir==="?"?"git-added":s.index==="D"?"git-deleted":s.index==="M"||s.working_dir==="M"?"git-modified":null);const n=+(s.index==="M"||s.working_dir==="M"),i=+(s.index==="A"||s.working_dir==="?");if(!n&&!i)continue;const p=[""];for(let c=s.path.indexOf("/");c!==-1;c=s.path.indexOf("/",c+1))p.push(s.path.slice(0,c));for(const c of p){const o=t.get(c)??{modified:0,added:0};o.modified+=n,o.added+=i,t.set(c,o)}}return{statusByPath:a,badgeByDir:t}},C=new Set,J=e=>{const a=e.runtimeKey.trim(),t=Array.from(new Set(e.paths.map(s=>s.trim()).filter(Boolean)));if(!(!a||t.length===0))for(const s of C)s({runtimeKey:a,paths:t})},G=e=>(C.add(e),()=>C.delete(e)),g=async(e,a)=>{try{const t=await e.json();if(t&&typeof t.error=="string"&&t.error.trim().length>0)return t.error}catch{return a}return a},w=e=>{const a=typeof e=="string"?e.trim():"";if(!a)throw new Error("projectId is required");return a},$=async e=>{const a=w(e),t=await I(`/api/projects/${encodeURIComponent(a)}/scheduled-tasks`);if(!t.ok)throw new Error(await g(t,"Failed to load scheduled tasks"));const s=await t.json().catch(()=>null);return!s||!Array.isArray(s.tasks)?[]:s.tasks},X=async(e,a)=>{const t=w(e),s=await I(`/api/projects/${encodeURIComponent(t)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:a})});if(!s.ok)throw new Error(await g(s,"Failed to save scheduled task"));const n=await s.json().catch(()=>null);return!n||!Array.isArray(n.tasks)?[]:n.tasks},Z=async(e,a)=>{const t=w(e),s=w(a),n=await I(`/api/projects/${encodeURIComponent(t)}/scheduled-tasks/${encodeURIComponent(s)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!n.ok)throw new Error(await g(n,"Failed to delete scheduled task"));const i=await n.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},F=(e,a)=>{const t=w(e),s=w(a);return`/api/projects/${encodeURIComponent(t)}/scheduled-tasks/${encodeURIComponent(s)}/loop-file`},Y=async(e,a,t)=>{const s=await I(F(e,a),{method:"PATCH",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({enabled:t})});if(!s.ok)throw new Error(await g(s,"Failed to update loop task"))},Q=async(e,a)=>{const t=await I(F(e,a),{method:"DELETE",headers:{accept:"application/json"}});if(!t.ok)throw new Error(await g(t,"Failed to delete loop file"))},ee=async e=>{await $(e)},te=async(e,a)=>{const t=w(e),s=w(a),n=await I(`/api/projects/${encodeURIComponent(t)}/scheduled-tasks/${encodeURIComponent(s)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!n.ok)throw new Error(await g(n,"Failed to run scheduled task"));const i=await n.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0,persistError:typeof i?.persistError=="string"&&i.persistError.trim().length>0?i.persistError.trim():void 0}};export{_ as D,A as O,q as a,z as b,X as c,Q as d,Z as e,$ as f,ee as g,G as h,H as i,J as n,te as r,Y as s,K as u};
@@ -1 +1 @@
1
- import{R as d,j as v,c as ge,f as be}from"./vendor-react-BUCujlKS.js";import{E as he,o as S,k as H,i as de,S as xe}from"./vendor-codemirror-state-C9awkmn-.js";import{s as ye,d as ve,E as w,e as ke,f as V,k as B,V as me,D as M,W as we}from"./vendor-codemirror-view-CiLROUVV.js";import{h as Ce,k as Se,l as Ne,j as Ee}from"./vendor-codemirror-commands-B7H_j0iU.js";import{i as Re,y as Te,H as G,x as F,z as Oe}from"./vendor-codemirror-language-BgPj_McA.js";import{a as U,g as P,b as Y,c as Q,o as Fe,d as Pe}from"./vendor-codemirror-search-BmS-GmcX.js";import{v as Me,g as ze}from"./vendor-replit-codemirror-vim-B2DJlAhT.js";import{h as qe,I as Z,a8 as We,B as Be,a9 as Le,a7 as _e,h9 as He}from"./useAppFontEffects-CPKeOpUo.js";import{a as e,c as $e}from"./vendor-lezer-highlight-CDMHUZ74.js";const Ie=t=>t!==null&&typeof t=="object"&&"updateStatus"in t&&typeof t.updateStatus=="function",je=t=>{const o=document.createElement("div");o.className="cm-vim-panel";const a=ze(t);if(!a)return{top:!1,dom:o};a.state.statusbar=o;const n=a.state.vimPlugin;return Ie(n)&&n.updateStatus(),{top:!1,dom:o,destroy(){a.state.statusbar===o&&(a.state.statusbar=null)}}};function J(t){return t?[Me(),ye.of(je),ve()]:[]}const Ae={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Ke={case:"Match case",re:"Regular expression",word:"Match whole word"};function De(t){const o=t.querySelector(".cm-search");if(o){for(const[a,n]of Object.entries(Ae)){const c=o.querySelector(`button[name="${a}"]`);c&&!c.title&&(c.title=n)}for(const[a,n]of Object.entries(Ke)){const r=o.querySelector(`input[name="${a}"]`)?.parentElement;r&&!r.title&&(r.title=n)}}}const L=new WeakMap;function Ve(t,o){const a=P(t.state);if(!a.valid)return L.delete(t),0;const n=L.get(t);if(!o&&n?.doc===t.state.doc&&n.query.eq(a))return n.total;const c=a.getCursor(t.state);let r=0;for(let l=c.next();!l.done;l=c.next())r+=1;return L.set(t,{query:a,doc:t.state.doc,total:r}),r}function Ge(t){const o=P(t.state);if(!o.valid)return 0;const a=t.state.selection.main,n=o.getCursor(t.state);let c=0,r=0;for(let l=n.next();!l.done;l=n.next()){const u=l.value;if(c+=1,r===0&&(r=c),a.from===u.from&&a.to===u.to||a.from<u.to&&a.to>u.from||u.from>=a.head)return c}return r}function X(t,o,a=!1){const n=t.querySelector(".cm-search");if(!n)return;let c=n.querySelector(".cm-search-message");if(!c){c=document.createElement("span"),c.className="cm-search-message",c.setAttribute("aria-live","polite");const u=n.querySelector('button[name="next"]'),f=u?.parentNode===n?u:n.firstChild;n.insertBefore(c,f)}const r=Ve(o,a),l=r===0?0:Ge(o);c.textContent=r===0?"":`${l}/${r}`}const ee=new S,te=new S,oe=new S,re=new S,ne=new S,ae=new S,ce=new S,se=t=>t,_=Te,Ue=Fe,Ye=Pe;class Qe extends we{constructor(o,a){super(),this.id=o,this.containerMap=a}toDOM(){let o=this.containerMap.get(this.id);return o||(o=document.createElement("div"),o.className="oc-block-widget",o.dataset.widgetId=this.id,this.containerMap.set(this.id,o)),o}eq(o){return o.id===this.id}destroy(){}}const ie=(t,o)=>!t||t.length===0?[]:de.define({create(a){const n=new H,c=[...t].sort((r,l)=>r.afterLine-l.afterLine);for(const r of c){const l=a.doc.lines;if(r.afterLine>l)continue;const u=a.doc.line(r.afterLine);n.add(u.to,u.to,M.widget({widget:new Qe(r.id,o),block:!0,side:1}))}return n.finish()},update(a,n){return a.map(n.changes)},provide:a=>w.decorations.from(a)}),le=t=>{if(!t)return[];const o=Math.max(1,t.start),a=Math.max(o,t.end);return me.fromClass(class{decorations;constructor(n){this.decorations=this.build(n)}update(n){(n.docChanged||n.viewportChanged)&&(this.decorations=this.build(n.view))}build(n){const c=new H;for(let r=o;r<=a&&r<=n.state.doc.lines;r+=1){const l=n.state.doc.line(r);c.add(l.from,l.from,M.line({class:"oc-cm-selected-line"}))}return c.finish()}},{decorations:n=>n.decorations})};function pt({value:t,onChange:o,extensions:a,className:n,readOnly:c,lineNumbersConfig:r,highlightLines:l,onViewReady:u,onViewDestroy:f,blockWidgets:m,enableSearch:b,searchOpen:T,onSearchOpenChange:N,vimMode:x}){const O=d.useRef(null),g=d.useRef(null),z=d.useRef(t),$=d.useRef(o),I=d.useRef(u),j=d.useRef(f),A=d.useRef(N),E=d.useRef(m),q=d.useRef(x),W=d.useRef(new Map),[pe,K]=d.useState([]),k=d.useCallback(s=>{const h=(s??[]).map(i=>{const p=W.current.get(i.id);return p?{id:i.id,content:i.content,container:p}:null}).filter(i=>i!==null);K(i=>i.length===h.length&&i.every((p,y)=>{const R=h[y];return p.id===R.id&&p.content===R.content&&p.container===R.container})?i:h)},[]),C=d.useCallback(s=>{const h=O.current,i=s??g.current;if(!h||!i)return;const p=i.dom.querySelector(".cm-gutters"),y=p instanceof HTMLElement?p.getBoundingClientRect().width:0;h.style.setProperty("--oc-editor-gutter-width",`${y}px`)},[]);return d.useEffect(()=>{z.current=t},[t]),d.useEffect(()=>{$.current=o},[o]),d.useEffect(()=>{I.current=u,j.current=f},[u,f]),d.useEffect(()=>{A.current=N},[N]),d.useEffect(()=>{E.current=m,k(m)},[m,k]),d.useEffect(()=>{if(!O.current)return;const s=(()=>{if(typeof document>"u")return null;const i=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(i)return i;const p=window.__AIWORKER_CSP_NONCE__;return typeof p=="string"&&p.length>0?p:null})(),h=he.create({doc:z.current,extensions:[...s?[w.cspNonce.of(s)]:[],ke({fixed:!0}),ee.of(V(r)),Ce(),Re.of(" "),ce.of(J(x)),B.of([Se,...Ne,...Ee]),w.updateListener.of(i=>{C(i.view),(i.viewportChanged||i.geometryChanged)&&k(E.current);const p=U(i.startState),y=U(i.state);p!==y&&A.current?.(y);const R=!P(i.startState).eq(P(i.state));if(y&&(p!==y||R||i.docChanged||i.selectionSet)&&X(i.view.dom,i.view,p!==y||R||i.docChanged),!i.docChanged)return;const D=i.state.doc.toString();z.current=D,$.current(D),k(E.current)}),te.of(w.editable.of(!c)),oe.of(a??[]),re.of(le(l)),ne.of(ie(m,W.current)),ae.of(b?[Y({top:!0}),B.of(se(Q))]:[])]});return g.current=new w({state:h,parent:O.current}),_(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{C(g.current),k(E.current)}),g.current&&I.current?.(g.current),()=>{j.current?.(),g.current?.destroy(),g.current=null,K([])}},[E,C,k]),d.useEffect(()=>{const s=g.current;s&&(s.dispatch({effects:[ee.reconfigure(V(r)),te.reconfigure(w.editable.of(!c)),oe.reconfigure(a??[]),re.reconfigure(le(l)),ne.reconfigure(ie(m,W.current)),ae.reconfigure(b?[Y({top:!0}),B.of(se(Q))]:[])]}),_(s,s.state.doc.length,200),s.requestMeasure(),requestAnimationFrame(()=>{C(s),k(E.current)}))},[a,l,r,c,m,b,C,k]),d.useEffect(()=>{const s=g.current;if(!s){q.current=x;return}q.current!==x&&(q.current=x,s.dispatch({effects:ce.reconfigure(J(x))}))},[x]),d.useEffect(()=>{const s=g.current;!s||b===!1||(T?(Ue(s),requestAnimationFrame(()=>{De(s.dom),X(s.dom,s,!0)})):Ye(s))},[T,b]),d.useEffect(()=>{const s=g.current;if(!s)return;const h=s.state.doc.toString();h!==t&&(s.dispatch({changes:{from:0,to:h.length,insert:t}}),_(s,s.state.doc.length,300),s.requestMeasure(),requestAnimationFrame(()=>C(s)))},[t,C]),v.jsxs(v.Fragment,{children:[v.jsx("div",{ref:O,className:qe("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",n)}),pe.map(s=>ge.createPortal(s.content,s.container,s.id))]})}const gt=t=>{const o=be.c(11),{currentMode:a,onToggle:n}=t,c=a==="preview",r=c?"Switch to edit mode":"Switch to preview mode",l=c?"Edit":"Preview";let u;o[0]!==c?(u=c?v.jsx(Z,{name:"eye",className:"size-4","aria-hidden":"true"}):v.jsx(Z,{name:"eye-off",className:"size-4","aria-hidden":"true"}),o[0]=c,o[1]=u):u=o[1];let f;o[2]!==r||o[3]!==n||o[4]!==u?(f=v.jsx(We,{asChild:!0,children:v.jsx(Be,{variant:"ghost",size:"sm",onClick:n,"aria-label":r,className:"h-5 w-5 p-0",children:u})}),o[2]=r,o[3]=n,o[4]=u,o[5]=f):f=o[5];let m;o[6]!==l?(m=v.jsx(Le,{sideOffset:8,children:l}),o[6]=l,o[7]=m):m=o[7];let b;return o[8]!==f||o[9]!==m?(b=v.jsxs(_e,{children:[f,m]}),o[8]=f,o[9]=m,o[10]=b):b=o[10],b};function bt(t,o){const a=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",c=t.colors.syntax.highlights||{},r=t.colors.syntax.tokens||{},l=o?.fontSize?`${o.fontSize}px`:"var(--text-code)",u=w.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:l,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:r.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:r.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:r.boolean||t.colors.syntax.base.number},".cm-builtin":{color:r.functionCall||t.colors.syntax.base.function},".cm-def":{color:r.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:r.variableOther||r.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:r.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:r.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:r.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:r.tag||t.colors.syntax.base.keyword},".cm-link":{color:r.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:c.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:c.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.elevated,color:t.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:a}),f=G.define([{tag:[e.comment,e.docComment,e.meta,e.documentMeta],class:"cm-comment"},{tag:[e.keyword,e.controlKeyword,e.moduleKeyword,e.definitionKeyword,e.modifier],class:"cm-keyword"},{tag:[e.operatorKeyword,e.operator,e.derefOperator,e.updateOperator,e.definitionOperator,e.typeOperator,e.controlOperator,e.logicOperator,e.bitwiseOperator,e.arithmeticOperator,e.compareOperator],class:"cm-operator"},{tag:[e.punctuation,e.separator,e.bracket,e.paren,e.brace,e.squareBracket,e.angleBracket],class:"cm-punctuation"},{tag:[e.string,e.regexp,e.attributeValue,e.special(e.string),e.monospace],class:"cm-string"},{tag:e.escape,class:"cm-string-2"},{tag:[e.number,e.bool,e.atom,e.null,e.self],class:"cm-number"},{tag:[e.function(e.variableName),e.function(e.definition(e.variableName)),e.function(e.propertyName),e.standard(e.variableName),e.special(e.variableName)],class:"cm-builtin"},{tag:e.definition(e.variableName),class:"cm-def"},{tag:[e.variableName,e.local(e.variableName),e.constant(e.variableName),e.literal],class:"cm-variable"},{tag:e.propertyName,class:"cm-property"},{tag:e.attributeName,class:"cm-attribute"},{tag:[e.className,e.typeName,e.namespace],class:"cm-variable-3"},{tag:[e.tagName,e.labelName,e.annotation,e.macroName],class:"cm-tag"},{tag:e.link,class:"cm-link"},{tag:[e.heading,e.heading1,e.heading2,e.heading3,e.heading4,e.heading5,e.heading6],class:"cm-keyword"}]),m=G.define([{tag:[e.comment,e.docComment,e.meta,e.documentMeta],color:t.colors.syntax.base.comment},{tag:[e.keyword,e.controlKeyword,e.moduleKeyword,e.definitionKeyword,e.modifier],color:t.colors.syntax.base.keyword},{tag:[e.operatorKeyword,e.operator,e.derefOperator,e.updateOperator,e.definitionOperator,e.typeOperator,e.controlOperator,e.logicOperator,e.bitwiseOperator,e.arithmeticOperator,e.compareOperator],color:t.colors.syntax.base.operator},{tag:[e.string,e.regexp,e.attributeValue,e.special(e.string),e.monospace],color:t.colors.syntax.base.string},{tag:e.escape,color:r.stringEscape||t.colors.syntax.base.string},{tag:[e.number,e.bool,e.atom,e.null,e.self],color:t.colors.syntax.base.number},{tag:[e.function(e.variableName),e.function(e.definition(e.variableName)),e.function(e.propertyName),e.standard(e.variableName),e.special(e.variableName)],color:t.colors.syntax.base.function},{tag:e.definition(e.variableName),color:r.variableGlobal||t.colors.syntax.base.variable},{tag:[e.variableName,e.local(e.variableName),e.constant(e.variableName),e.literal],color:t.colors.syntax.base.variable},{tag:e.propertyName,color:r.variableProperty||t.colors.syntax.base.variable},{tag:e.attributeName,color:r.variableOther||t.colors.syntax.base.variable},{tag:[e.className,e.typeName,e.namespace],color:t.colors.syntax.base.type},{tag:[e.tagName,e.labelName,e.annotation,e.macroName],color:r.tag||t.colors.syntax.base.keyword},{tag:e.link,color:r.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[e.punctuation,e.separator,e.bracket,e.paren,e.brace,e.squareBracket,e.angleBracket],color:r.punctuation||t.colors.syntax.base.comment}]);return o?.syntaxColors===!1?[u]:[u,F(Oe,{fallback:!0}),F($e),F(f),F(m)]}const Ze=180,fe=xe.define(),Je=1,Xe=2,et=4,ue=new Map,tt=(t,o)=>{const a=`${t}|${o}`,n=ue.get(a);if(n)return n;let c="";t&&(c+=`color:${t};`),o&Je&&(c+="font-style:italic;"),o&Xe&&(c+="font-weight:bold;"),o&et&&(c+="text-decoration:underline;");const r=M.mark({attributes:{style:c}});return ue.set(a,r),r},ot=(t,o)=>{const a=new H,n=t.state.doc,c=Math.min(o.length,n.lines);for(let r=0;r<c;r+=1){const l=o[r];if(!l||l.length===0)continue;const u=n.line(r+1);let f=u.from;for(const[m,b,T]of l){if(m<=0)continue;const N=f,x=Math.min(f+m,u.to);f+=m,!(x<=N)&&(!b&&!T||a.add(N,x,tt(b,T)))}}return a.finish()},rt=de.define({create(){return M.none},update(t,o){let a=t.map(o.changes);for(const n of o.effects)n.is(fe)&&(a=n.value);return a},provide:t=>w.decorations.from(t)}),nt=t=>me.fromClass(class{timer;generation=0;constructor(o){this.tokenize(o)}update(o){o.docChanged&&this.schedule(o.view)}schedule(o){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(o)},Ze)}async tokenize(o){const a=++this.generation,n=o.state.doc.toString(),c=await He(n,t.language,t.themeName,t.theme);c&&a===this.generation&&o.state.doc.length===n.length&&o.dispatch({effects:fe.of(ot(o,c))})}destroy(){this.timer&&clearTimeout(this.timer)}}),ht=t=>[rt,nt(t)];export{pt as C,gt as P,bt as c,ht as s};
1
+ import{R as d,j as v,c as ge,f as be}from"./vendor-react-BUCujlKS.js";import{E as he,o as S,k as H,i as de,S as xe}from"./vendor-codemirror-state-C9awkmn-.js";import{s as ye,d as ve,E as w,e as ke,f as V,k as B,V as me,D as M,W as we}from"./vendor-codemirror-view-CiLROUVV.js";import{h as Ce,k as Se,l as Ne,j as Ee}from"./vendor-codemirror-commands-B7H_j0iU.js";import{i as Re,y as Te,H as G,x as F,z as Oe}from"./vendor-codemirror-language-BgPj_McA.js";import{a as U,g as P,b as Y,c as Q,o as Fe,d as Pe}from"./vendor-codemirror-search-BmS-GmcX.js";import{v as Me,g as ze}from"./vendor-replit-codemirror-vim-B2DJlAhT.js";import{h as qe,I as Z,aa as We,B as Be,ab as Le,a9 as _e,hk as He}from"./useAppFontEffects-Cwyhjfl5.js";import{a as e,c as $e}from"./vendor-lezer-highlight-CDMHUZ74.js";const Ie=t=>t!==null&&typeof t=="object"&&"updateStatus"in t&&typeof t.updateStatus=="function",je=t=>{const o=document.createElement("div");o.className="cm-vim-panel";const a=ze(t);if(!a)return{top:!1,dom:o};a.state.statusbar=o;const n=a.state.vimPlugin;return Ie(n)&&n.updateStatus(),{top:!1,dom:o,destroy(){a.state.statusbar===o&&(a.state.statusbar=null)}}};function J(t){return t?[Me(),ye.of(je),ve()]:[]}const Ae={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Ke={case:"Match case",re:"Regular expression",word:"Match whole word"};function De(t){const o=t.querySelector(".cm-search");if(o){for(const[a,n]of Object.entries(Ae)){const c=o.querySelector(`button[name="${a}"]`);c&&!c.title&&(c.title=n)}for(const[a,n]of Object.entries(Ke)){const r=o.querySelector(`input[name="${a}"]`)?.parentElement;r&&!r.title&&(r.title=n)}}}const L=new WeakMap;function Ve(t,o){const a=P(t.state);if(!a.valid)return L.delete(t),0;const n=L.get(t);if(!o&&n?.doc===t.state.doc&&n.query.eq(a))return n.total;const c=a.getCursor(t.state);let r=0;for(let l=c.next();!l.done;l=c.next())r+=1;return L.set(t,{query:a,doc:t.state.doc,total:r}),r}function Ge(t){const o=P(t.state);if(!o.valid)return 0;const a=t.state.selection.main,n=o.getCursor(t.state);let c=0,r=0;for(let l=n.next();!l.done;l=n.next()){const u=l.value;if(c+=1,r===0&&(r=c),a.from===u.from&&a.to===u.to||a.from<u.to&&a.to>u.from||u.from>=a.head)return c}return r}function X(t,o,a=!1){const n=t.querySelector(".cm-search");if(!n)return;let c=n.querySelector(".cm-search-message");if(!c){c=document.createElement("span"),c.className="cm-search-message",c.setAttribute("aria-live","polite");const u=n.querySelector('button[name="next"]'),f=u?.parentNode===n?u:n.firstChild;n.insertBefore(c,f)}const r=Ve(o,a),l=r===0?0:Ge(o);c.textContent=r===0?"":`${l}/${r}`}const ee=new S,te=new S,oe=new S,re=new S,ne=new S,ae=new S,ce=new S,se=t=>t,_=Te,Ue=Fe,Ye=Pe;class Qe extends we{constructor(o,a){super(),this.id=o,this.containerMap=a}toDOM(){let o=this.containerMap.get(this.id);return o||(o=document.createElement("div"),o.className="oc-block-widget",o.dataset.widgetId=this.id,this.containerMap.set(this.id,o)),o}eq(o){return o.id===this.id}destroy(){}}const ie=(t,o)=>!t||t.length===0?[]:de.define({create(a){const n=new H,c=[...t].sort((r,l)=>r.afterLine-l.afterLine);for(const r of c){const l=a.doc.lines;if(r.afterLine>l)continue;const u=a.doc.line(r.afterLine);n.add(u.to,u.to,M.widget({widget:new Qe(r.id,o),block:!0,side:1}))}return n.finish()},update(a,n){return a.map(n.changes)},provide:a=>w.decorations.from(a)}),le=t=>{if(!t)return[];const o=Math.max(1,t.start),a=Math.max(o,t.end);return me.fromClass(class{decorations;constructor(n){this.decorations=this.build(n)}update(n){(n.docChanged||n.viewportChanged)&&(this.decorations=this.build(n.view))}build(n){const c=new H;for(let r=o;r<=a&&r<=n.state.doc.lines;r+=1){const l=n.state.doc.line(r);c.add(l.from,l.from,M.line({class:"oc-cm-selected-line"}))}return c.finish()}},{decorations:n=>n.decorations})};function pt({value:t,onChange:o,extensions:a,className:n,readOnly:c,lineNumbersConfig:r,highlightLines:l,onViewReady:u,onViewDestroy:f,blockWidgets:m,enableSearch:b,searchOpen:T,onSearchOpenChange:N,vimMode:x}){const O=d.useRef(null),g=d.useRef(null),z=d.useRef(t),$=d.useRef(o),I=d.useRef(u),j=d.useRef(f),A=d.useRef(N),E=d.useRef(m),q=d.useRef(x),W=d.useRef(new Map),[pe,K]=d.useState([]),k=d.useCallback(s=>{const h=(s??[]).map(i=>{const p=W.current.get(i.id);return p?{id:i.id,content:i.content,container:p}:null}).filter(i=>i!==null);K(i=>i.length===h.length&&i.every((p,y)=>{const R=h[y];return p.id===R.id&&p.content===R.content&&p.container===R.container})?i:h)},[]),C=d.useCallback(s=>{const h=O.current,i=s??g.current;if(!h||!i)return;const p=i.dom.querySelector(".cm-gutters"),y=p instanceof HTMLElement?p.getBoundingClientRect().width:0;h.style.setProperty("--oc-editor-gutter-width",`${y}px`)},[]);return d.useEffect(()=>{z.current=t},[t]),d.useEffect(()=>{$.current=o},[o]),d.useEffect(()=>{I.current=u,j.current=f},[u,f]),d.useEffect(()=>{A.current=N},[N]),d.useEffect(()=>{E.current=m,k(m)},[m,k]),d.useEffect(()=>{if(!O.current)return;const s=(()=>{if(typeof document>"u")return null;const i=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(i)return i;const p=window.__AIWORKER_CSP_NONCE__;return typeof p=="string"&&p.length>0?p:null})(),h=he.create({doc:z.current,extensions:[...s?[w.cspNonce.of(s)]:[],ke({fixed:!0}),ee.of(V(r)),Ce(),Re.of(" "),ce.of(J(x)),B.of([Se,...Ne,...Ee]),w.updateListener.of(i=>{C(i.view),(i.viewportChanged||i.geometryChanged)&&k(E.current);const p=U(i.startState),y=U(i.state);p!==y&&A.current?.(y);const R=!P(i.startState).eq(P(i.state));if(y&&(p!==y||R||i.docChanged||i.selectionSet)&&X(i.view.dom,i.view,p!==y||R||i.docChanged),!i.docChanged)return;const D=i.state.doc.toString();z.current=D,$.current(D),k(E.current)}),te.of(w.editable.of(!c)),oe.of(a??[]),re.of(le(l)),ne.of(ie(m,W.current)),ae.of(b?[Y({top:!0}),B.of(se(Q))]:[])]});return g.current=new w({state:h,parent:O.current}),_(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{C(g.current),k(E.current)}),g.current&&I.current?.(g.current),()=>{j.current?.(),g.current?.destroy(),g.current=null,K([])}},[E,C,k]),d.useEffect(()=>{const s=g.current;s&&(s.dispatch({effects:[ee.reconfigure(V(r)),te.reconfigure(w.editable.of(!c)),oe.reconfigure(a??[]),re.reconfigure(le(l)),ne.reconfigure(ie(m,W.current)),ae.reconfigure(b?[Y({top:!0}),B.of(se(Q))]:[])]}),_(s,s.state.doc.length,200),s.requestMeasure(),requestAnimationFrame(()=>{C(s),k(E.current)}))},[a,l,r,c,m,b,C,k]),d.useEffect(()=>{const s=g.current;if(!s){q.current=x;return}q.current!==x&&(q.current=x,s.dispatch({effects:ce.reconfigure(J(x))}))},[x]),d.useEffect(()=>{const s=g.current;!s||b===!1||(T?(Ue(s),requestAnimationFrame(()=>{De(s.dom),X(s.dom,s,!0)})):Ye(s))},[T,b]),d.useEffect(()=>{const s=g.current;if(!s)return;const h=s.state.doc.toString();h!==t&&(s.dispatch({changes:{from:0,to:h.length,insert:t}}),_(s,s.state.doc.length,300),s.requestMeasure(),requestAnimationFrame(()=>C(s)))},[t,C]),v.jsxs(v.Fragment,{children:[v.jsx("div",{ref:O,className:qe("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",n)}),pe.map(s=>ge.createPortal(s.content,s.container,s.id))]})}const gt=t=>{const o=be.c(11),{currentMode:a,onToggle:n}=t,c=a==="preview",r=c?"Switch to edit mode":"Switch to preview mode",l=c?"Edit":"Preview";let u;o[0]!==c?(u=c?v.jsx(Z,{name:"eye",className:"size-4","aria-hidden":"true"}):v.jsx(Z,{name:"eye-off",className:"size-4","aria-hidden":"true"}),o[0]=c,o[1]=u):u=o[1];let f;o[2]!==r||o[3]!==n||o[4]!==u?(f=v.jsx(We,{asChild:!0,children:v.jsx(Be,{variant:"ghost",size:"sm",onClick:n,"aria-label":r,className:"h-5 w-5 p-0",children:u})}),o[2]=r,o[3]=n,o[4]=u,o[5]=f):f=o[5];let m;o[6]!==l?(m=v.jsx(Le,{sideOffset:8,children:l}),o[6]=l,o[7]=m):m=o[7];let b;return o[8]!==f||o[9]!==m?(b=v.jsxs(_e,{children:[f,m]}),o[8]=f,o[9]=m,o[10]=b):b=o[10],b};function bt(t,o){const a=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",c=t.colors.syntax.highlights||{},r=t.colors.syntax.tokens||{},l=o?.fontSize?`${o.fontSize}px`:"var(--text-code)",u=w.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:l,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:r.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:r.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:r.boolean||t.colors.syntax.base.number},".cm-builtin":{color:r.functionCall||t.colors.syntax.base.function},".cm-def":{color:r.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:r.variableOther||r.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:r.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:r.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:r.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:r.tag||t.colors.syntax.base.keyword},".cm-link":{color:r.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:c.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:c.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.elevated,color:t.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:a}),f=G.define([{tag:[e.comment,e.docComment,e.meta,e.documentMeta],class:"cm-comment"},{tag:[e.keyword,e.controlKeyword,e.moduleKeyword,e.definitionKeyword,e.modifier],class:"cm-keyword"},{tag:[e.operatorKeyword,e.operator,e.derefOperator,e.updateOperator,e.definitionOperator,e.typeOperator,e.controlOperator,e.logicOperator,e.bitwiseOperator,e.arithmeticOperator,e.compareOperator],class:"cm-operator"},{tag:[e.punctuation,e.separator,e.bracket,e.paren,e.brace,e.squareBracket,e.angleBracket],class:"cm-punctuation"},{tag:[e.string,e.regexp,e.attributeValue,e.special(e.string),e.monospace],class:"cm-string"},{tag:e.escape,class:"cm-string-2"},{tag:[e.number,e.bool,e.atom,e.null,e.self],class:"cm-number"},{tag:[e.function(e.variableName),e.function(e.definition(e.variableName)),e.function(e.propertyName),e.standard(e.variableName),e.special(e.variableName)],class:"cm-builtin"},{tag:e.definition(e.variableName),class:"cm-def"},{tag:[e.variableName,e.local(e.variableName),e.constant(e.variableName),e.literal],class:"cm-variable"},{tag:e.propertyName,class:"cm-property"},{tag:e.attributeName,class:"cm-attribute"},{tag:[e.className,e.typeName,e.namespace],class:"cm-variable-3"},{tag:[e.tagName,e.labelName,e.annotation,e.macroName],class:"cm-tag"},{tag:e.link,class:"cm-link"},{tag:[e.heading,e.heading1,e.heading2,e.heading3,e.heading4,e.heading5,e.heading6],class:"cm-keyword"}]),m=G.define([{tag:[e.comment,e.docComment,e.meta,e.documentMeta],color:t.colors.syntax.base.comment},{tag:[e.keyword,e.controlKeyword,e.moduleKeyword,e.definitionKeyword,e.modifier],color:t.colors.syntax.base.keyword},{tag:[e.operatorKeyword,e.operator,e.derefOperator,e.updateOperator,e.definitionOperator,e.typeOperator,e.controlOperator,e.logicOperator,e.bitwiseOperator,e.arithmeticOperator,e.compareOperator],color:t.colors.syntax.base.operator},{tag:[e.string,e.regexp,e.attributeValue,e.special(e.string),e.monospace],color:t.colors.syntax.base.string},{tag:e.escape,color:r.stringEscape||t.colors.syntax.base.string},{tag:[e.number,e.bool,e.atom,e.null,e.self],color:t.colors.syntax.base.number},{tag:[e.function(e.variableName),e.function(e.definition(e.variableName)),e.function(e.propertyName),e.standard(e.variableName),e.special(e.variableName)],color:t.colors.syntax.base.function},{tag:e.definition(e.variableName),color:r.variableGlobal||t.colors.syntax.base.variable},{tag:[e.variableName,e.local(e.variableName),e.constant(e.variableName),e.literal],color:t.colors.syntax.base.variable},{tag:e.propertyName,color:r.variableProperty||t.colors.syntax.base.variable},{tag:e.attributeName,color:r.variableOther||t.colors.syntax.base.variable},{tag:[e.className,e.typeName,e.namespace],color:t.colors.syntax.base.type},{tag:[e.tagName,e.labelName,e.annotation,e.macroName],color:r.tag||t.colors.syntax.base.keyword},{tag:e.link,color:r.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[e.punctuation,e.separator,e.bracket,e.paren,e.brace,e.squareBracket,e.angleBracket],color:r.punctuation||t.colors.syntax.base.comment}]);return o?.syntaxColors===!1?[u]:[u,F(Oe,{fallback:!0}),F($e),F(f),F(m)]}const Ze=180,fe=xe.define(),Je=1,Xe=2,et=4,ue=new Map,tt=(t,o)=>{const a=`${t}|${o}`,n=ue.get(a);if(n)return n;let c="";t&&(c+=`color:${t};`),o&Je&&(c+="font-style:italic;"),o&Xe&&(c+="font-weight:bold;"),o&et&&(c+="text-decoration:underline;");const r=M.mark({attributes:{style:c}});return ue.set(a,r),r},ot=(t,o)=>{const a=new H,n=t.state.doc,c=Math.min(o.length,n.lines);for(let r=0;r<c;r+=1){const l=o[r];if(!l||l.length===0)continue;const u=n.line(r+1);let f=u.from;for(const[m,b,T]of l){if(m<=0)continue;const N=f,x=Math.min(f+m,u.to);f+=m,!(x<=N)&&(!b&&!T||a.add(N,x,tt(b,T)))}}return a.finish()},rt=de.define({create(){return M.none},update(t,o){let a=t.map(o.changes);for(const n of o.effects)n.is(fe)&&(a=n.value);return a},provide:t=>w.decorations.from(t)}),nt=t=>me.fromClass(class{timer;generation=0;constructor(o){this.tokenize(o)}update(o){o.docChanged&&this.schedule(o.view)}schedule(o){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(o)},Ze)}async tokenize(o){const a=++this.generation,n=o.state.doc.toString(),c=await He(n,t.language,t.themeName,t.theme);c&&a===this.generation&&o.state.doc.length===n.length&&o.dispatch({effects:fe.of(ot(o,c))})}destroy(){this.timer&&clearTimeout(this.timer)}}),ht=t=>[rt,nt(t)];export{pt as C,gt as P,bt as c,ht as s};
@@ -0,0 +1 @@
1
+ const et=/https?:\/\/[^\s"'`<>]+/giu,bt=/[.,;!?]+$/;function St(s){let t=s.replace(bt,"");if(t.length===0)return t;const e=(i,r)=>{for(;t.endsWith(r);){const n=t.split(i).length-1,o=t.split(r).length-1;if(n>=o)return;t=t.slice(0,-1)}};return e("(",")"),e("[","]"),e("{","}"),t}function vt(s){const t=[];et.lastIndex=0;for(const e of s.matchAll(et)){const i=e[0],r=e.index??-1;if(r<0||i.length===0)continue;const n=St(i);n.length!==0&&t.push({text:n,start:r,end:r+n.length})}return t}function Mt(s,t){const e=t(s-1);if(!e)return null;let i=s,r=e;for(;i>1&&r.isWrapped;){const h=t(i-2);if(!h)return null;i-=1,r=h}const n=[];let o=0,l=i;for(;;){const h=t(l-1);if(!h)break;const c=t(l)?.isWrapped===!0,u=h.translateToString(!c);if(n.push({bufferLineNumber:l,text:u,startIndex:o,endIndex:o+u.length}),o+=u.length,!c)break;l+=1}return{text:n.map(h=>h.text).join(""),segments:n}}const Tt=["normal 400","normal 700","italic 400","italic 700"],Et=["i","M","W","0","@","#","."," "],kt=.01,At=/^(ui-monospace|ui-sans-serif|ui-serif|system-ui)$/i;function Ct(s){const t=s.trim();return t.length===0?"":/^(['"]).*\1$/.test(t)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(t)?t:`"${t.replaceAll('"',"")}"`}function J(s){const t=s.split(",").map(Ct).filter(e=>e.length>0&&!At.test(e));return t.length>0?t.join(", "):null}function xt(s){const t=s[0];return t===void 0||t<=0||s.some(e=>!Number.isFinite(e)||e<=0)?!0:s.every(e=>Math.abs(e-t)<kt)}let I;function Pt(s){const t=J(s);if(t===null)return!0;try{if(I===void 0&&(I=document.createElement("canvas").getContext("2d")),I===null)return!0;const e=I;for(const i of Tt){e.font=`${i} 32px ${t}, monospace`;const r=Et.map(n=>e.measureText(n).width);if(!xt(r))return!1}return!0}catch{return!0}}const Lt=["Unidentified","Backquote","Backslash","BracketLeft","BracketRight","Comma","Digit0","Digit1","Digit2","Digit3","Digit4","Digit5","Digit6","Digit7","Digit8","Digit9","Equal","IntlBackslash","IntlRo","IntlYen","KeyA","KeyB","KeyC","KeyD","KeyE","KeyF","KeyG","KeyH","KeyI","KeyJ","KeyK","KeyL","KeyM","KeyN","KeyO","KeyP","KeyQ","KeyR","KeyS","KeyT","KeyU","KeyV","KeyW","KeyX","KeyY","KeyZ","Minus","Period","Quote","Semicolon","Slash","AltLeft","AltRight","Backspace","CapsLock","ContextMenu","ControlLeft","ControlRight","Enter","MetaLeft","MetaRight","ShiftLeft","ShiftRight","Space","Tab","Convert","KanaMode","NonConvert","Delete","End","Help","Home","Insert","PageDown","PageUp","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","NumLock","Numpad0","Numpad1","Numpad2","Numpad3","Numpad4","Numpad5","Numpad6","Numpad7","Numpad8","Numpad9","NumpadAdd","NumpadBackspace","NumpadClear","NumpadClearEntry","NumpadComma","NumpadDecimal","NumpadDivide","NumpadEnter","NumpadEqual","NumpadMemoryAdd","NumpadMemoryClear","NumpadMemoryRecall","NumpadMemoryStore","NumpadMemorySubtract","NumpadMultiply","NumpadParenLeft","NumpadParenRight","NumpadSubtract","NumpadSeparator","NumpadArrowUp","NumpadArrowDown","NumpadArrowRight","NumpadArrowLeft","NumpadBegin","NumpadHome","NumpadEnd","NumpadInsert","NumpadDelete","NumpadPageUp","NumpadPageDown","Escape","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24","F25","Fn","FnLock","PrintScreen","ScrollLock","Pause","BrowserBack","BrowserFavorites","BrowserForward","BrowserHome","BrowserRefresh","BrowserSearch","BrowserStop","Eject","LaunchApp1","LaunchApp2","LaunchMail","MediaPlayPause","MediaSelect","MediaStop","MediaTrackNext","MediaTrackPrevious","Power","Sleep","AudioVolumeDown","AudioVolumeMute","AudioVolumeUp","WakeUp","Copy","Cut","Paste"],Rt=new Map(Lt.map((s,t)=>[s,t]));function Ft(s){return Rt.get(s)??0}const Dt=new Map([["!","1"],["@","2"],["#","3"],["$","4"],["%","5"],["^","6"],["&","7"],["*","8"],["(","9"],[")","0"],["~","`"],["_","-"],["+","="],["{","["],["}","]"],["|","\\"],[":",";"],['"',"'"],["<",","],[">","."],["?","/"]]);let Y;function It(){if(Y)return Y;const t=globalThis.navigator?.keyboard?.getLayoutMap().catch(()=>{})??Promise.resolve(void 0);return Y=t,t}function Nt(s){return!s.shiftKey||s.ctrlKey||s.altKey||s.metaKey?0:[...s.key].length===1?1:0}function zt(s,t){if([...s.key].length!==1)return 0;const e=t?.get(s.code);if(e&&[...e].length===1)return e.codePointAt(0)??0;if(/^[A-Z]$/u.test(s.key))return s.key.charCodeAt(0)+32;if(s.shiftKey){const i=Dt.get(s.key);if(i)return i.codePointAt(0)??0;const r=s.key.toLowerCase();return r!==s.key&&[...r].length===1?r.codePointAt(0)??0:0}return s.key.codePointAt(0)??0}const V=new TextDecoder,Bt=new URL("/assets/ghostty-vt-DdA0Zryv.wasm",import.meta.url),Ut=Uint8Array.from([0,97,115,109,1,0,0,0,1,8,1,96,4,127,127,127,127,0,2,29,1,3,101,110,118,21,111,112,101,110,99,104,97,109,98,101,114,95,119,114,105,116,101,95,112,116,121,0,0,3,2,1,0,5,3,1,0,16,6,9,1,127,1,65,128,128,192,0,11,7,30,2,6,109,101,109,111,114,121,2,0,17,103,104,111,115,116,116,121,95,119,114,105,116,101,95,112,116,121,0,1,10,18,1,16,0,32,0,32,1,32,2,32,3,16,128,128,128,128,0,11]);class Q{memory;layouts;exports;memoryView;ptyWriters=new Map;nextPtyWriterId=1;writePtyFunctionIndex=0;constructor(t){this.exports=t.exports;const e=t.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("libghostty-vt did not export WebAssembly memory");this.memory=e,this.memoryView=new DataView(e.buffer);const i=this.call("ghostty_type_json"),r=new Uint8Array(e.buffer);let n=i;for(;n<r.length&&r[n]!==0;)n+=1;this.layouts=JSON.parse(V.decode(r.subarray(i,n)))}static async load(t){const e=t??await Ot(),i={current:null},r={env:{log:(l,h)=>{const a=i.current?.exports.memory;if(!(a instanceof WebAssembly.Memory))return;const c=V.decode(new Uint8Array(a.buffer,l,h));console.debug("[libghostty-vt]",c)}}},n=await WebAssembly.instantiate(e,r);i.current=n.instance;const o=new Q(n.instance);return await o.installWritePtyTrampoline(),o}call(t,...e){const i=this.exports[t];if(!(i instanceof Function))throw new Error(`libghostty-vt export is unavailable: ${t}`);return i(...e)}layout(t){const e=this.layouts[t];if(!e)throw new Error(`libghostty-vt type layout is unavailable: ${t}`);return e}alloc(t){const e=this.call("ghostty_wasm_alloc_u8_array",t);if(e===0)throw new Error(`libghostty-vt failed to allocate ${t} bytes`);return new Uint8Array(this.memory.buffer,e,t).fill(0),e}free(t,e){t!==0&&this.call("ghostty_wasm_free_u8_array",t,e)}allocOpaque(){const t=this.call("ghostty_wasm_alloc_opaque");if(t===0)throw new Error("libghostty-vt failed to allocate an opaque pointer");return new DataView(this.memory.buffer).setUint32(t,0,!0),t}freeOpaque(t){t!==0&&this.call("ghostty_wasm_free_opaque",t)}readPointer(t){return this.currentMemoryView().getUint32(t,!0)}attachPtyWriter(t,e){if(this.writePtyFunctionIndex===0)throw new Error("libghostty-vt PTY callback trampoline is unavailable");const i=this.nextPtyWriterId++;return this.ptyWriters.set(i,e),this.call("ghostty_terminal_set",t,0,i),this.call("ghostty_terminal_set",t,1,this.writePtyFunctionIndex),i}detachPtyWriter(t,e){this.call("ghostty_terminal_set",t,1,0),this.call("ghostty_terminal_set",t,0,0),this.ptyWriters.delete(e)}view(t,e){return new DataView(this.memory.buffer,t,e)}bytes(t,e){return new Uint8Array(this.memory.buffer,t,e)}currentMemoryView(){return this.memoryView.buffer!==this.memory.buffer&&(this.memoryView=new DataView(this.memory.buffer)),this.memoryView}setField(t,e,i,r){const n=this.layout(e).fields[i];if(!n)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const o=this.currentMemoryView(),l=t+n.offset;switch(n.type){case"bool":case"u8":o.setUint8(l,r);return;case"u16":o.setUint16(l,r,!0);return;case"i32":o.setInt32(l,r,!0);return;case"u32":case"enum":o.setUint32(l,r,!0);return;case"u64":o.setBigUint64(l,BigInt(r),!0);return;default:throw new Error(`Unsupported libghostty-vt field type: ${n.type}`)}}readField(t,e,i){const r=this.layout(e).fields[i];if(!r)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const n=this.currentMemoryView(),o=t+r.offset;switch(r.type){case"bool":case"u8":return n.getUint8(o);case"u16":return n.getUint16(o,!0);case"i32":return n.getInt32(o,!0);case"u32":case"enum":return n.getUint32(o,!0);case"u64":return Number(n.getBigUint64(o,!0));default:throw new Error(`Unsupported libghostty-vt field type: ${r.type}`)}}async installWritePtyTrampoline(){const e=(await WebAssembly.instantiate(Ut,{env:{aiworker_write_pty:(n,o,l,h)=>{const a=this.ptyWriters.get(o);!a||h===0||a(V.decode(new Uint8Array(this.memory.buffer,l,h)))}}})).instance.exports.ghostty_write_pty,i=this.exports.__indirect_function_table;if(!(e instanceof Function)||!(i instanceof WebAssembly.Table))throw new Error("libghostty-vt did not expose its callback table");const r=i.length;i.grow(1),i.set(r,e),this.writePtyFunctionIndex=r}}async function Ot(){const s=await fetch(Bt);if(!s.ok)throw new Error(`Unable to load libghostty-vt (${s.status})`);return s.arrayBuffer()}let H=null;function Kt(){return H??=Q.load().catch(s=>{throw H=null,s}),H}const S=0,N=-3,Wt=1e4,z=16,E={cols:1,rows:2,dirty:3,rowIterator:4,background:5,foreground:6,cursor:7,cursorHasValue:8,cursorStyle:10,cursorVisible:11,cursorBlinking:12,cursorInViewport:14,cursorX:15,cursorY:16},q={dirty:1,raw:2,cells:3},P={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},Gt={wide:3},Yt={spacerTail:2},it=256;function Vt(s){const t=new Uint8Array(it*3),e=(r,n)=>{t[r*3]=n.r,t[r*3+1]=n.g,t[r*3+2]=n.b},i=[0,95,135,175,215,255];for(let r=16;r<232;r+=1){const n=r-16;e(r,{r:i[Math.floor(n/36)%6]??0,g:i[Math.floor(n/6)%6]??0,b:i[n%6]??0})}for(let r=232;r<it;r+=1){const n=8+(r-232)*10;e(r,{r:n,g:n,b:n})}return s.slice(0,16).forEach((r,n)=>e(n,r)),t}const B=new TextDecoder,$=new TextEncoder;function Ht(s,t){const e=(i,r)=>Math.floor((i*155+r*100)/255);return{r:e(s.r,t.r),g:e(s.g,t.g),b:e(s.b,t.b)}}function qt(s,t){return s.r===t.r&&s.g===t.g&&s.b===t.b}function $t(s,t){if(t===1)return String.fromCodePoint(s.getUint32(0,!0));const e=4096;let i="";for(let r=0;r<t;r+=e){const n=Math.min(e,t-r),o=new Array(n);for(let l=0;l<n;l+=1)o[l]=s.getUint32((r+l)*4,!0);i+=String.fromCodePoint(...o)}return i}class tt{runtime;terminalSlot=0;terminal=0;renderStateSlot=0;renderState=0;rowIteratorSlot=0;rowCellsSlot=0;keyEncoderSlot=0;keyEncoder=0;keyEventSlot=0;keyEvent=0;mouseEncoderSlot=0;mouseEncoder=0;mouseEventSlot=0;mouseEvent=0;ptyWriterId=0;ptyWriter=null;scratch=0;graphemes=0;graphemeCapacity=0;style=0;scrollbar=0;rows=[];disposed=!1;keyboardLayoutMap;constructor(t){this.runtime=t,It().then(e=>{this.disposed||(this.keyboardLayoutMap=e)})}static async create(t,e,i,r,n,o){const l=new tt(await Kt());try{return l.initialize(t,e,i,r,n,o),l}catch(h){throw l.dispose(),h}}initialize(t,e,i,r,n,o){const l=this.runtime.layout("GhosttyTerminalOptions").size,h=this.runtime.alloc(l);this.runtime.setField(h,"GhosttyTerminalOptions","cols",t),this.runtime.setField(h,"GhosttyTerminalOptions","rows",e),this.runtime.setField(h,"GhosttyTerminalOptions","max_scrollback",Wt),this.terminalSlot=this.runtime.allocOpaque();const a=this.runtime.call("ghostty_terminal_new",0,this.terminalSlot,h);this.runtime.free(h,l),this.assertSuccess("ghostty_terminal_new",a),this.terminal=this.runtime.readPointer(this.terminalSlot),this.applyDefaultCursorBlink(),this.ptyWriter=o,this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,o),this.renderStateSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_new",this.runtime.call("ghostty_render_state_new",0,this.renderStateSlot)),this.renderState=this.runtime.readPointer(this.renderStateSlot),this.rowIteratorSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_iterator_new",this.runtime.call("ghostty_render_state_row_iterator_new",0,this.rowIteratorSlot)),this.rowCellsSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_cells_new",this.runtime.call("ghostty_render_state_row_cells_new",0,this.rowCellsSlot)),this.keyEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_encoder_new",this.runtime.call("ghostty_key_encoder_new",0,this.keyEncoderSlot)),this.keyEncoder=this.runtime.readPointer(this.keyEncoderSlot),this.keyEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_event_new",this.runtime.call("ghostty_key_event_new",0,this.keyEventSlot)),this.keyEvent=this.runtime.readPointer(this.keyEventSlot),this.mouseEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_encoder_new",this.runtime.call("ghostty_mouse_encoder_new",0,this.mouseEncoderSlot)),this.mouseEncoder=this.runtime.readPointer(this.mouseEncoderSlot),this.mouseEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_event_new",this.runtime.call("ghostty_mouse_event_new",0,this.mouseEventSlot)),this.mouseEvent=this.runtime.readPointer(this.mouseEventSlot),this.scratch=this.runtime.alloc(16);const c=this.runtime.layout("GhosttyStyle").size;this.style=this.runtime.alloc(c),this.runtime.setField(this.style,"GhosttyStyle","size",c),this.scrollbar=this.runtime.alloc(this.runtime.layout("GhosttyTerminalScrollbar").size),this.setTheme(n),this.resize(t,e,i,r)}write(t){this.ensureActive();const e=t instanceof Uint8Array?t:$.encode(t);if(e.length===0)return;const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.call("ghostty_terminal_vt_write",this.terminal,i,e.length),this.runtime.free(i,e.length)}resetAndWrite(t){if(this.ensureActive(),this.runtime.call("ghostty_terminal_reset",this.terminal),this.applyDefaultCursorBlink(),this.rows=[],t.length===0)return;const e=this.ptyWriter;this.ptyWriterId!==0&&(this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.ptyWriterId=0);try{this.write(t)}finally{e!==null&&!this.disposed&&(this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,e))}}resize(t,e,i,r){this.ensureActive(),this.assertSuccess("ghostty_terminal_resize",this.runtime.call("ghostty_terminal_resize",this.terminal,Math.max(1,Math.min(65535,t)),Math.max(1,Math.min(65535,e)),Math.max(1,Math.round(i)),Math.max(1,Math.round(r))))}applyDefaultCursorBlink(){const t=this.runtime.alloc(1);this.runtime.bytes(t,1)[0]=1,this.runtime.call("ghostty_terminal_set",this.terminal,23,t),this.runtime.free(t,1)}setTheme(t){this.ensureActive();const e=this.runtime.alloc(3);for(const[n,o]of[[11,t.foreground],[12,t.background],[13,t.cursor]])this.runtime.bytes(e,3).set([o.r,o.g,o.b]),this.runtime.call("ghostty_terminal_set",this.terminal,n,e);if(this.runtime.free(e,3),t.palette===void 0){this.runtime.call("ghostty_terminal_set",this.terminal,14,0);return}const i=Vt(t.palette),r=this.runtime.alloc(i.length);this.runtime.bytes(r,i.length).set(i),this.runtime.call("ghostty_terminal_set",this.terminal,14,r),this.runtime.free(r,i.length)}scroll(t){this.ensureActive();const e=this.runtime.layout("GhosttyTerminalScrollViewport"),i=this.runtime.alloc(e.size);this.runtime.setField(i,"GhosttyTerminalScrollViewport","tag",2);const r=e.fields.value;this.runtime.view(i+r.offset,r.size).setInt32(0,t,!0),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,i),this.runtime.free(i,e.size)}scrollToBottom(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollViewport"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttyTerminalScrollViewport","tag",1),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,e),this.runtime.free(e,t.size)}isViewportActive(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,32,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}scrollbarState(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollbar");return this.runtime.bytes(this.scrollbar,t.size).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,9,this.scrollbar)!==S?null:{total:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","total"),offset:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","offset"),len:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","len")}}isMouseTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,11,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}isMouseAnyEventTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1003,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}isAlternateScreen(){return this.ensureActive(),this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,6,this.scratch)===S&&this.runtime.view(this.scratch,4).getUint32(0,!0)===1}isApplicationCursorKeys(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}encodeMacWordShortcut(t,e){if(this.ensureActive(),!t.altKey||t.ctrlKey||t.metaKey||t.shiftKey||t.isComposing)return null;let i;switch(t.key){case"ArrowLeft":i="\x1Bb";break;case"ArrowRight":i="\x1Bf";break;case"Backspace":i="";break;default:return null}return!/mac/i.test(e)||this.isAlternateScreen()||this.runtime.call("ghostty_terminal_get",this.terminal,8,this.scratch)!==S||this.runtime.bytes(this.scratch,1)[0]!==0?null:i}encodeKey(t,e="press"){this.ensureActive(),this.runtime.call("ghostty_key_encoder_setopt_from_terminal",this.keyEncoder,this.terminal),this.runtime.call("ghostty_key_event_set_action",this.keyEvent,e==="release"?0:t.repeat?2:1),this.runtime.call("ghostty_key_event_set_key",this.keyEvent,Ft(t.code));const i=(t.shiftKey?1:0)|(t.ctrlKey?2:0)|(t.altKey?4:0)|(t.metaKey?8:0)|(t.getModifierState("CapsLock")?16:0)|(t.getModifierState("NumLock")?32:0);this.runtime.call("ghostty_key_event_set_mods",this.keyEvent,i),this.runtime.call("ghostty_key_event_set_consumed_mods",this.keyEvent,Nt(t)),this.runtime.call("ghostty_key_event_set_composing",this.keyEvent,t.isComposing?1:0),this.runtime.call("ghostty_key_event_set_unshifted_codepoint",this.keyEvent,zt(t,this.keyboardLayoutMap));const r=t.key.length===1?t.key:"",n=$.encode(r),o=n.length===0?0:this.runtime.alloc(n.length);o!==0&&this.runtime.bytes(o,n.length).set(n),this.runtime.call("ghostty_key_event_set_utf8",this.keyEvent,o,n.length);const l=this.runtime.call("ghostty_wasm_alloc_usize"),h=this.encodeOutput(l,(a,c)=>this.runtime.call("ghostty_key_encoder_encode",this.keyEncoder,this.keyEvent,a,c,l));return this.runtime.call("ghostty_wasm_free_usize",l),o!==0&&this.runtime.free(o,n.length),h}encodePaste(t){this.ensureActive();const e=$.encode(t);if(e.length===0)return"";const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.bytes(this.scratch,1)[0]=0;const r=this.runtime.call("ghostty_terminal_mode_get",this.terminal,2004,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0,n=this.runtime.call("ghostty_wasm_alloc_usize");let o="";const l=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,0,0,n),h=this.runtime.view(n,4).getUint32(0,!0);if(l===N&&h>0){const a=this.runtime.alloc(h),c=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,a,h,n),u=this.runtime.view(n,4).getUint32(0,!0);o=c===S?B.decode(this.runtime.bytes(a,u)):"",this.runtime.free(a,h)}return this.runtime.call("ghostty_wasm_free_usize",n),this.runtime.free(i,e.length),o}encodeMouse(t){this.ensureActive(),this.runtime.call("ghostty_mouse_encoder_setopt_from_terminal",this.mouseEncoder,this.terminal);const e=this.runtime.layout("GhosttyMouseEncoderSize"),i=this.runtime.alloc(e.size);for(const[a,c]of[["size",e.size],["screen_width",t.screenWidth],["screen_height",t.screenHeight],["cell_width",t.cellWidth],["cell_height",t.cellHeight],["padding_top",t.paddingTop],["padding_bottom",t.paddingBottom],["padding_right",t.paddingRight],["padding_left",t.paddingLeft]])this.runtime.setField(i,"GhosttyMouseEncoderSize",a,Math.max(0,Math.round(c)));this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,2,i),this.runtime.free(i,e.size),this.runtime.bytes(this.scratch,1)[0]=t.anyButtonPressed?1:0,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,3,this.scratch),this.runtime.bytes(this.scratch,1)[0]=1,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,4,this.scratch),this.runtime.call("ghostty_mouse_event_set_action",this.mouseEvent,t.action==="press"?0:t.action==="release"?1:2),t.button===null?this.runtime.call("ghostty_mouse_event_clear_button",this.mouseEvent):this.runtime.call("ghostty_mouse_event_set_button",this.mouseEvent,t.button),this.runtime.call("ghostty_mouse_event_set_mods",this.mouseEvent,t.mods);const r=this.runtime.layout("GhosttyMousePosition"),n=this.runtime.alloc(r.size),o=this.runtime.view(n,r.size);o.setFloat32(r.fields.x.offset,t.x,!0),o.setFloat32(r.fields.y.offset,t.y,!0),this.runtime.call("ghostty_mouse_event_set_position",this.mouseEvent,n),this.runtime.free(n,r.size);const l=this.runtime.call("ghostty_wasm_alloc_usize"),h=this.encodeOutput(l,(a,c)=>this.runtime.call("ghostty_mouse_encoder_encode",this.mouseEncoder,this.mouseEvent,a,c,l));return this.runtime.call("ghostty_wasm_free_usize",l),h}setSelection(t,e){this.ensureActive();const i=this.runtime.layout("GhosttySelection"),r=this.runtime.layout("GhosttyGridRef").size,n=this.runtime.alloc(i.size);let o=0,l=0;try{this.runtime.setField(n,"GhosttySelection","size",i.size),o=this.gridRef(t.x,t.y,t.tag??1),l=this.gridRef(e.x,e.y,e.tag??1);const h=i.fields.start,a=i.fields.end;this.runtime.bytes(n+h.offset,h.size).set(this.runtime.bytes(o,h.size)),this.runtime.bytes(n+a.offset,a.size).set(this.runtime.bytes(l,a.size)),this.runtime.call("ghostty_terminal_set",this.terminal,21,n)}finally{this.runtime.free(o,r),this.runtime.free(l,r),this.runtime.free(n,i.size)}}selectAll(){this.ensureActive();const t=this.runtime.layout("GhosttySelection"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttySelection","size",t.size),this.runtime.call("ghostty_terminal_select_all",this.terminal,e)===S&&this.runtime.call("ghostty_terminal_set",this.terminal,21,e),this.runtime.free(e,t.size)}selectWord(t,e){return this.selectAt("GhosttyTerminalSelectWordOptions","ghostty_terminal_select_word",t,e)}selectLine(t,e){return this.selectAt("GhosttyTerminalSelectLineOptions","ghostty_terminal_select_line",t,e)}hyperlinkAt(t,e){this.ensureActive();const i=this.gridRef(t,e),r=this.runtime.call("ghostty_wasm_alloc_usize"),n=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,0,0,r),o=this.runtime.view(r,4).getUint32(0,!0);let l=null;if(n===N&&o>0){const h=this.runtime.alloc(o),a=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,h,o,r),c=this.runtime.view(r,4).getUint32(0,!0);a===S&&c>0&&(l=B.decode(this.runtime.bytes(h,c))),this.runtime.free(h,o)}return this.runtime.call("ghostty_wasm_free_usize",r),this.runtime.free(i,this.runtime.layout("GhosttyGridRef").size),l}clearSelection(){this.ensureActive(),this.runtime.call("ghostty_terminal_set",this.terminal,21,0)}snapshot(){this.ensureActive(),this.assertSuccess("ghostty_render_state_update",this.runtime.call("ghostty_render_state_update",this.renderState,this.terminal));const t=this.getU16(E.cols),e=this.getU16(E.rows),i=this.getU32(E.dirty),r=this.getColor(E.foreground,{r:229,g:231,b:235}),n=this.getColor(E.background,{r:0,g:0,b:0}),l=this.getBool(E.cursorHasValue)?this.getColor(E.cursor,r):r,h=this.getBool(E.cursorInViewport),a=this.getBool(E.cursorVisible)&&h,c=h?this.getU16(E.cursorX):-1,u=h?this.getU16(E.cursorY):-1;(this.rows.length!==e||this.rows.some(m=>m.cells.length!==t))&&(this.rows=Array.from({length:e},()=>({cells:Array.from({length:t},()=>this.emptyCell(r,n)),text:"",isWrapContinuation:!1,wrapsToNext:!1})));const d=new Set;if(i!==0){this.assertSuccess("ghostty_render_state_get(row iterator)",this.runtime.call("ghostty_render_state_get",this.renderState,E.rowIterator,this.rowIteratorSlot));const m=this.runtime.readPointer(this.rowIteratorSlot);let g=0;for(;g<e&&this.runtime.call("ghostty_render_state_row_iterator_next",m)!==0;)(i===2||this.getRowBool(m,q.dirty))&&(this.rows[g]=this.readRow(m,t,r,n),d.add(g),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_set",m,0,this.scratch)),g+=1;this.runtime.view(this.scratch,4).setUint32(0,0,!0),this.runtime.call("ghostty_render_state_set",this.renderState,0,this.scratch)}return{cols:t,rows:e,foreground:r,background:n,cursor:l,cursorX:c,cursorY:u,cursorVisible:a,cursorBlinking:this.getBool(E.cursorBlinking),cursorStyle:this.getU32(E.cursorStyle),dirtyRows:d,rowData:this.rows}}selectionText(){this.ensureActive();const t=this.runtime.alloc(z),e=this.runtime.view(t,z);e.setUint32(0,z,!0),e.setUint32(4,0,!0),e.setUint8(8,1),e.setUint8(9,1),e.setUint32(12,0,!0);const i=this.runtime.call("ghostty_wasm_alloc_usize"),r=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,0,0,i),n=this.runtime.view(i,4).getUint32(0,!0);let o="";if(r===N&&n>0){const l=this.runtime.alloc(n),h=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,l,n,i),a=this.runtime.view(i,4).getUint32(0,!0);h===S&&(o=B.decode(this.runtime.bytes(l,a))),this.runtime.free(l,n)}return this.runtime.call("ghostty_wasm_free_usize",i),this.runtime.free(t,z),o}viewportPointToScreen(t,e){return this.convertPoint(t,e,1,2)}screenPointToViewport(t,e){return this.convertPoint(t,e,2,1)}convertPoint(t,e,i,r){this.ensureActive();const n=this.gridRef(t,e,i),o=this.pointFromGridRef(n,r);return this.runtime.free(n,this.runtime.layout("GhosttyGridRef").size),o}dispose(){if(!this.disposed){if(this.disposed=!0,this.mouseEvent&&this.runtime.call("ghostty_mouse_event_free",this.mouseEvent),this.mouseEncoder&&this.runtime.call("ghostty_mouse_encoder_free",this.mouseEncoder),this.keyEvent&&this.runtime.call("ghostty_key_event_free",this.keyEvent),this.keyEncoder&&this.runtime.call("ghostty_key_encoder_free",this.keyEncoder),this.rowCellsSlot){const t=this.runtime.readPointer(this.rowCellsSlot);t&&this.runtime.call("ghostty_render_state_row_cells_free",t)}if(this.rowIteratorSlot){const t=this.runtime.readPointer(this.rowIteratorSlot);t&&this.runtime.call("ghostty_render_state_row_iterator_free",t)}this.renderState&&this.runtime.call("ghostty_render_state_free",this.renderState),this.terminal&&(this.ptyWriterId&&this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.runtime.call("ghostty_terminal_free",this.terminal)),this.style&&this.runtime.free(this.style,this.runtime.layout("GhosttyStyle").size),this.scrollbar&&this.runtime.free(this.scrollbar,this.runtime.layout("GhosttyTerminalScrollbar").size),this.scratch&&this.runtime.free(this.scratch,16),this.graphemes&&this.runtime.free(this.graphemes,this.graphemeCapacity);for(const t of[this.mouseEventSlot,this.mouseEncoderSlot,this.keyEventSlot,this.keyEncoderSlot,this.rowCellsSlot,this.rowIteratorSlot,this.renderStateSlot,this.terminalSlot])this.runtime.freeOpaque(t)}}encodeOutput(t,e){const i=e(0,0),r=this.runtime.view(t,4).getUint32(0,!0);if(i===S&&r===0||i!==N||r===0)return"";const n=this.runtime.alloc(r),o=e(n,r),l=this.runtime.view(t,4).getUint32(0,!0),h=o===S?B.decode(this.runtime.bytes(n,l)):"";return this.runtime.free(n,r),h}readRow(t,e,i,r){this.assertSuccess("ghostty_render_state_row_get(raw)",this.runtime.call("ghostty_render_state_row_get",t,q.raw,this.scratch));const n=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap continuation)",this.runtime.call("ghostty_row_get",n,2,this.scratch+8));const o=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap)",this.runtime.call("ghostty_row_get",n,1,this.scratch+8));const l=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.assertSuccess("ghostty_render_state_row_get(cells)",this.runtime.call("ghostty_render_state_row_get",t,q.cells,this.rowCellsSlot));const h=this.runtime.readPointer(this.rowCellsSlot),{size:a,fields:c}=this.runtime.layout("GhosttyStyle"),u=[];for(;u.length<e&&this.runtime.call("ghostty_render_state_row_cells_next",h)!==0;){let d=this.getCellColor(h,P.foreground,i),m=this.getCellColor(h,P.background,r);this.runtime.bytes(this.style,a).fill(0),this.runtime.setField(this.style,"GhosttyStyle","size",a),this.runtime.call("ghostty_render_state_row_cells_get",h,P.style,this.style);const g=this.getCellU32(h,P.graphemesLength);let y="";if(g>0){const v=g*4;if(v>this.graphemeCapacity){const p=Math.max(v,this.graphemeCapacity*2),w=this.runtime.alloc(p);this.runtime.free(this.graphemes,this.graphemeCapacity),this.graphemes=w,this.graphemeCapacity=p}if(this.runtime.call("ghostty_render_state_row_cells_get",h,P.graphemes,this.graphemes)===S){const p=this.runtime.view(this.graphemes,v);y=$t(p,g)}}let f=0;if(y.length===0&&u.at(-1)?.text.length){this.assertSuccess("ghostty_render_state_row_cells_get(raw)",this.runtime.call("ghostty_render_state_row_cells_get",h,P.raw,this.scratch));const v=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.view(this.scratch+8,4).setUint32(0,0,!0),this.assertSuccess("ghostty_cell_get(wide)",this.runtime.call("ghostty_cell_get",v,Gt.wide,this.scratch+8)),f=this.runtime.view(this.scratch+8,4).getUint32(0,!0)}const _=this.getCellBool(h,P.selected),b=this.runtime.view(this.style,a);b.getUint8(c.inverse.offset)!==0&&([d,m]=[m,d]),b.getUint8(c.faint.offset)!==0&&(d=Ht(d,m)),u.push({text:y,wide:f,foreground:d,background:m,bold:b.getUint8(c.bold.offset)!==0,italic:b.getUint8(c.italic.offset)!==0,invisible:b.getUint8(c.invisible.offset)!==0,strikethrough:b.getUint8(c.strikethrough.offset)!==0,overline:b.getUint8(c.overline.offset)!==0,underline:b.getInt32(c.underline.offset,!0)!==0,selected:_})}for(;u.length<e;)u.push(this.emptyCell(i,r));return{cells:u,text:u.map(d=>d.text||" ").join("").trimEnd(),isWrapContinuation:o,wrapsToNext:l}}gridRef(t,e,i=1){const r=this.runtime.layout("GhosttyPoint"),n=this.runtime.alloc(r.size);this.runtime.setField(n,"GhosttyPoint","tag",i);const o=r.fields.value,l=o.offset,h=this.runtime.view(n+l,o.size);h.setUint16(0,Math.max(0,t),!0),h.setUint32(4,Math.max(0,e),!0);const a=this.runtime.layout("GhosttyGridRef").size,c=this.runtime.alloc(a);this.runtime.setField(c,"GhosttyGridRef","size",a);const u=this.runtime.call("ghostty_terminal_grid_ref",this.terminal,n,c);return this.runtime.free(n,r.size),u!==S&&(this.runtime.free(c,a),this.assertSuccess("ghostty_terminal_grid_ref",u)),c}selectAt(t,e,i,r){this.ensureActive();const n=this.runtime.layout(t),o=this.runtime.layout("GhosttySelection"),l=this.runtime.alloc(n.size);let h=0,a=0,c=null;try{this.runtime.setField(l,t,"size",n.size),h=this.gridRef(i,r);const u=n.fields.ref;if(this.runtime.bytes(l+u.offset,u.size).set(this.runtime.bytes(h,u.size)),a=this.runtime.alloc(o.size),this.runtime.setField(a,"GhosttySelection","size",o.size),this.runtime.call(e,this.terminal,l,a)===S){const m=a+o.fields.start.offset,g=a+o.fields.end.offset,y=this.pointFromGridRef(m,1),f=this.pointFromGridRef(g,1),_=this.pointFromGridRef(m,2),b=this.pointFromGridRef(g,2);y&&f&&_&&b&&(c={viewport:{start:y,end:f},screen:{start:_,end:b}}),this.runtime.call("ghostty_terminal_set",this.terminal,21,a)}}finally{this.runtime.free(a,o.size),this.runtime.free(h,this.runtime.layout("GhosttyGridRef").size),this.runtime.free(l,n.size)}return c}pointFromGridRef(t,e){const i=this.runtime.layout("GhosttyPointCoordinate"),r=this.runtime.alloc(i.size),o=this.runtime.call("ghostty_terminal_point_from_grid_ref",this.terminal,t,e,r)===S?{x:this.runtime.readField(r,"GhosttyPointCoordinate","x"),y:this.runtime.readField(r,"GhosttyPointCoordinate","y")}:null;return this.runtime.free(r,i.size),o}getU16(t){return this.runtime.bytes(this.scratch,2).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,2).getUint16(0,!0)}getU32(t){return this.runtime.bytes(this.scratch,4).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,4).getUint32(0,!0)}getBool(t){return this.runtime.bytes(this.scratch,1)[0]=0,this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.bytes(this.scratch,1)[0]!==0}getColor(t,e){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)===S?this.readColor(this.scratch):e}getRowBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_get",t,e,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellU32(t,e){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S?this.runtime.view(this.scratch,4).getUint32(0,!0):0}getCellBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellColor(t,e,i){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S?this.readColor(this.scratch):i}readColor(t){const e=this.runtime.bytes(t,3);return{r:e[0]??0,g:e[1]??0,b:e[2]??0}}emptyCell(t,e){return{text:"",wide:0,foreground:t,background:e,bold:!1,italic:!1,invisible:!1,strikethrough:!1,overline:!1,underline:!1,selected:!1}}assertSuccess(t,e){if(e!==S)throw new Error(`${t} failed with result ${e}`)}ensureActive(){if(this.disposed)throw new Error("libghostty-vt terminal has been disposed")}}function K(s,t){return qt(s,t)}const ct=9472,Xt=9599,ut=9600,dt=9631,mt=57520,ft=57523,Zt=1,pt=2,A=3,jt="0011 0022 1100 2200 0011 0022 1100 2200 0011 0022 1100 2200 0101 0102 0201 0202 0110 0120 0210 0220 1001 1002 2001 2002 1010 1020 2010 2020 1101 1102 2101 1201 2201 2102 1202 2202 1110 1120 2110 1210 2210 2120 1220 2220 0111 0121 0112 0122 0211 0221 0212 0222 1011 1021 1012 1022 2011 2021 2012 2022 1111 1121 1112 1122 2111 1211 2211 2121 2112 1221 1212 2122 1222 2221 2212 2222 0011 0022 1100 2200 0033 3300 0103 0301 0303 0130 0310 0330 1003 3001 3003 1030 3010 3030 1103 3301 3303 1130 3310 3330 0133 0311 0333 1033 3011 3033 1133 3311 3333 0101 0110 1010 1001 0000 0000 0000 0010 1000 0001 0100 0020 2000 0002 0200 0012 1200 0021 2100",Jt=jt.split(" "),Qt=new Set([9476,9477,9478,9479]),te=new Set([9480,9481,9482,9483]),ee=new Set([9548,9549,9550,9551]),ie=new Map([[9600,[[0,0,1,1/2]]],[9601,[[0,7/8,1,1/8]]],[9602,[[0,6/8,1,2/8]]],[9603,[[0,5/8,1,3/8]]],[9604,[[0,1/2,1,1/2]]],[9605,[[0,3/8,1,5/8]]],[9606,[[0,2/8,1,6/8]]],[9607,[[0,1/8,1,7/8]]],[9608,[[0,0,1,1]]],[9609,[[0,0,7/8,1]]],[9610,[[0,0,6/8,1]]],[9611,[[0,0,5/8,1]]],[9612,[[0,0,1/2,1]]],[9613,[[0,0,3/8,1]]],[9614,[[0,0,2/8,1]]],[9615,[[0,0,1/8,1]]],[9616,[[1/2,0,1/2,1]]],[9620,[[0,0,1,1/8]]],[9621,[[7/8,0,1/8,1]]],[9622,[[0,1/2,1/2,1/2]]],[9623,[[1/2,1/2,1/2,1/2]]],[9624,[[0,0,1/2,1/2]]],[9625,[[0,0,1/2,1],[1/2,1/2,1/2,1/2]]],[9626,[[0,0,1/2,1/2],[1/2,1/2,1/2,1/2]]],[9627,[[0,0,1,1/2],[0,1/2,1/2,1/2]]],[9628,[[0,0,1,1/2],[1/2,1/2,1/2,1/2]]],[9629,[[1/2,0,1/2,1/2]]],[9630,[[1/2,0,1/2,1/2],[0,1/2,1/2,1/2]]],[9631,[[1/2,0,1/2,1/2],[0,1/2,1,1/2]]]]),se=new Map([[9617,.25],[9618,.5],[9619,.75]]);function W(s){if(s.length===0||s.length>2)return!1;const t=s.codePointAt(0);return t===void 0||String.fromCodePoint(t)!==s?!1:t>=ct&&t<=Xt||t>=ut&&t<=dt||t>=mt&&t<=ft}function st(s,t){return`rgba(${s.r}, ${s.g}, ${s.b}, ${t})`}function re(s){const t=Math.round(s.x),e=Math.round(s.x+s.width),i=Math.round(s.y),r=Math.round(s.y+s.height),n=Math.max(1,Math.round(s.width/8));return{left:t,right:e,top:i,bottom:r,centerX:Math.round(s.x+s.width/2),centerY:Math.round(s.y+s.height/2),stroke:n,gap:n+1}}function x(s,t){return s===pt?t*3:t}function L(s,t,e,i,r){e<=t||s.fillRect(t,i-Math.floor(r/2),e-t,r)}function R(s,t,e,i,r){e<=t||s.fillRect(i-Math.floor(r/2),t,r,e-t)}function ne(s,t,e,i,r){const n=x(i,t.stroke),o=e?t.left:t.top,l=e?t.right:t.bottom,h=t.stroke,a=l-o,c=Math.max(1,Math.floor((a-h*(r-1))/r));for(let u=0;u<r;u+=1){const d=o+u*(c+h),m=u===r-1?l:d+c;e?L(s,d,m,t.centerY,n):R(s,d,m,t.centerX,n)}}function oe(s,t,e){const i=Number(e[0]),r=Number(e[1]),n=Number(e[2]),o=Number(e[3]),{centerX:l,centerY:h,stroke:a,gap:c}=t,u=M=>M===Zt||M===pt,d=Math.max(x(i,a),x(r,a),a),m=Math.max(x(n,a),x(o,a),a),g=l-Math.floor(d/2),y=g+d,f=h-Math.floor(m/2),_=f+m,b=i===A||r===A,v=n===A||o===A;u(n)&&L(s,t.left,b?l-c:y,h,x(n,a)),u(o)&&L(s,b?l+c:g,t.right,h,x(o,a)),u(i)&&R(s,t.top,v?h-c:_,l,x(i,a)),u(r)&&R(s,v?h+c:f,t.bottom,l,x(r,a));const p=(M,T)=>M===A?l-T*c:u(M)?l:l+T*c,w=(M,T)=>M===A?h-T*c:u(M)?h:h+T*c;n===A&&(L(s,t.left,p(i,1),h-c,a),L(s,t.left,p(r,1),h+c,a)),o===A&&(L(s,p(i,-1),t.right,h-c,a),L(s,p(r,-1),t.right,h+c,a)),i===A&&(R(s,t.top,w(n,1),l-c,a),R(s,t.top,w(o,1),l+c,a)),r===A&&(R(s,w(n,-1),t.bottom,l-c,a),R(s,w(o,-1),t.bottom,l+c,a))}function le(s,t,e){const{centerX:i,centerY:r,stroke:n}=t,o=e===9581||e===9584,l=e===9581||e===9582,h=o?t.right:t.left,a=l?t.bottom:t.top,c=Math.min(Math.abs(h-i),Math.abs(a-r)),u=o?1:-1,d=l?1:-1,m=n%2/2,g=i+m,y=r+m;s.beginPath(),s.moveTo(h,y),s.lineTo(g+u*c,y),s.quadraticCurveTo(g,y,g,y+d*c),s.lineTo(g,a),s.lineWidth=n,s.lineCap="butt",s.stroke()}function he(s,t,e){s.lineWidth=t.stroke,s.lineCap="butt",s.beginPath(),(e===9585||e===9587)&&(s.moveTo(t.right,t.top),s.lineTo(t.left,t.bottom)),(e===9586||e===9587)&&(s.moveTo(t.left,t.top),s.lineTo(t.right,t.bottom)),s.stroke()}function ae(s,t,e){const{left:i,right:r,top:n,bottom:o,centerY:l}=t,h=e===57520||e===57521,a=h?r:i,c=h?i:r;if(s.beginPath(),s.moveTo(c,n),s.lineTo(a,l),s.lineTo(c,o),e===57520||e===57522){s.closePath(),s.fill();return}s.lineWidth=t.stroke,s.lineCap="butt",s.stroke()}function rt(s,t,e,i){if(!W(t))return!1;const r=t.codePointAt(0)??0,n=re(e),o=st(i,1);if(s.fillStyle=o,s.strokeStyle=o,r>=ut&&r<=dt){const a=se.get(r);if(a!==void 0)return s.fillStyle=st(i,a),s.fillRect(n.left,n.top,n.right-n.left,n.bottom-n.top),!0;const c=n.right-n.left,u=n.bottom-n.top;for(const[d,m,g,y]of ie.get(r)??[]){const f=n.left+Math.round(d*c),_=n.left+Math.round((d+g)*c),b=n.top+Math.round(m*u),v=n.top+Math.round((m+y)*u);s.fillRect(f,b,Math.max(1,_-f),Math.max(1,v-b))}return!0}if(r>=mt&&r<=ft)return ae(s,n,r),!0;if(r>=9581&&r<=9584)return le(s,n,r),!0;if(r>=9585&&r<=9587)return he(s,n,r),!0;const l=Jt[r-ct]??"0000",h=Qt.has(r)?3:te.has(r)?4:ee.has(r)?2:0;if(h>0){const a=l[2]!=="0";return ne(s,n,a,Number(a?l[2]:l[0]),h),!0}return oe(s,n,l),!0}const ce="rgba(72, 122, 191, 0.35)";function C(s){return`rgb(${s.r}, ${s.g}, ${s.b})`}function ue(s,t){return K(s.foreground,t.foreground)&&s.bold===t.bold&&s.italic===t.italic&&s.invisible===t.invisible}function de(s,t,e){let i=t+1;for(;i<s.length;){const r=s[i];if(!r)break;if(r.wide===Yt.spacerTail){i+=1;continue}if(r.text.length===0||!e(r))break;i+=1}return i}function nt(s,t,e){const i=s.italic?"italic":"normal",r=s.bold?"700":"400";return`${i} ${r} ${t}px ${e}`}function X(s,t,e){s.font=`normal 400 ${t}px ${e}`;const i=s.measureText("M"),r=s.measureText("Mg"),n=r.actualBoundingBoxAscent||t,o=r.actualBoundingBoxDescent,l=n+o,h=Math.max(1,Math.round(t*1.35),Math.ceil(l));return{width:Math.max(1,i.width),height:h,baseline:Math.round((h-l)/2+n)}}function ot(s,t,e,i){return{cols:Math.max(1,Math.floor((s-i*2)/e.width)),rows:Math.max(1,Math.floor((t-i*2)/e.height))}}function me(s){const{context:t,snapshot:e,metrics:i,fontSize:r,fontFamily:n,padding:o,forceFull:l,cursorOn:h,previousCursorY:a}=s,c=s.focused??!0,u=s.selectionBackground??ce,d=s.hoveredLinkRange??null,m=s.originY??o,g=l?Array.from({length:e.rows},(y,f)=>f):[...e.dirtyRows];a!=null&&a>=0&&!g.includes(a)&&g.push(a),e.cursorVisible&&e.cursorY>=0&&!g.includes(e.cursorY)&&g.push(e.cursorY),l&&(t.save(),t.resetTransform(),t.fillStyle=C(e.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore()),t.textBaseline="alphabetic";for(const y of g){const f=e.rowData[y];if(!f)continue;const _=m+y*i.height;t.fillStyle=C(e.background),t.fillRect(o,_,e.cols*i.width,i.height);let b=0;for(;b<f.cells.length;){const p=f.cells[b];if(!p)break;let w=b+1;for(;w<f.cells.length;){const M=f.cells[w];if(!M||M.selected!==p.selected||!K(M.background,p.background))break;w+=1}if(p.selected||!K(p.background,e.background)){const M=o+b*i.width,T=(w-b)*i.width;K(p.background,e.background)||(t.fillStyle=C(p.background),t.fillRect(M,_,T,i.height)),p.selected&&(t.fillStyle=u,t.fillRect(M,_,T,i.height))}b=w}let v=0;for(;v<f.cells.length;){const p=f.cells[v];if(!p)break;if(p.text.length===0){v+=1;continue}if(W(p.text)){p.invisible||rt(t,p.text,{x:o+v*i.width,y:_,width:i.width,height:i.height},p.foreground),v+=1;continue}const w=de(f.cells,v,T=>ue(T,p)&&!W(T.text)),M=f.cells.slice(v,w).map(T=>T.text).join("");!p.invisible&&M.trim().length>0&&(t.save(),t.beginPath(),t.rect(o+v*i.width,_,(w-v)*i.width,i.height),t.clip(),t.font=nt(p,r,n),t.fillStyle=C(p.foreground),t.fillText(M,o+v*i.width,_+i.baseline,(w-v)*i.width),t.restore()),v=w}for(let p=0;p<f.cells.length;p+=1){const w=f.cells[p],M=d!==null&&y>=d.start.y&&y<=d.end.y&&(y>d.start.y||p>=d.start.x)&&(y<d.end.y||p<=d.end.x);if(!w||!w.underline&&!w.strikethrough&&!w.overline&&!M)continue;t.fillStyle=C(w.foreground);const T=o+p*i.width;(w.underline||M)&&t.fillRect(T,_+i.height-2,i.width,1),w.strikethrough&&t.fillRect(T,_+Math.floor(i.height*.55),i.width,1),w.overline&&t.fillRect(T,_+1,i.width,1)}}if(h&&e.cursorVisible&&e.cursorX>=0&&e.cursorY>=0){const y=o+e.cursorX*i.width,f=m+e.cursorY*i.height;if(t.fillStyle=C(e.cursor),!c)t.strokeStyle=C(e.cursor),t.strokeRect(y+.5,f+.5,i.width-1,i.height-1);else if(e.cursorStyle===0)t.fillRect(y,f,2,i.height);else if(e.cursorStyle===2)t.fillRect(y,f+i.height-2,i.width,2);else if(e.cursorStyle===3)t.strokeStyle=C(e.cursor),t.strokeRect(y+.5,f+.5,i.width-1,i.height-1);else{t.fillRect(y,f,i.width,i.height);const _=e.rowData[e.cursorY]?.cells[e.cursorX];_?.text&&W(_.text)?rt(t,_.text,{x:y,y:f,width:i.width,height:i.height},e.background):_?.text&&(t.font=nt(_,r,n),t.fillStyle=C(e.background),t.fillText(_.text,y,f+i.baseline,i.width))}}}const fe=new URL("/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2",import.meta.url).href,pe=13,ye=6,ge=32,we=500,_e=1e3,D=s=>/mac|iphone|ipad|ipod/i.test(s),be='"Symbols Nerd Font Mono", "Symbols Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "FiraCode Nerd Font", "Hack Nerd Font", "MesloLGS NF", "CaskaydiaCove Nerd Font", "PowerlineSymbols", monospace',G='"SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", '+be,k=4,Se=18,ve=500,Me="iMW0@# .",Te=["normal 400","normal 700","italic 400","italic 700"];let U=null;function Ee(){return U!==null||(U=(async()=>{try{const s=new FontFace("Symbols Nerd Font Mono",`url(${fe})`);document.fonts.add(await s.load())}catch{}})()),U}function yt(s){const t=s===void 0?null:J(s);return t===null?G:`${t}, ${G}`}function gt(s){const t=s===void 0?null:J(s);return t===null||!Pt(t)?G:yt(t)}async function lt(s,t,e){const i=yt(s),r=((n,o)=>document.fonts.load(n,o).then(()=>{}));try{await Promise.all(Te.map(n=>r(`${n} ${t}px ${i}`,Me)))}catch{}return(e?.resolve??gt)(s)}function Z(s){return s===void 0||!Number.isFinite(s)?pe:Math.max(ye,Math.min(ge,Math.round(s)))}function ke(s){return s.focused&&s.cursorBlinking&&s.cursorVisible&&!s.reducedMotion}function Ae(s,t,e,i,r){if(!r)return t;const n=s-t*2-e*i;return t+Math.max(0,n)}function j(s,t){const e=Math.max(0,s.total),i=Math.max(0,Math.min(s.len,e)),r=Math.max(0,e-i);if(t<=0||i<=0||r===0)return null;const n=Math.min(t,Math.max(Se,t*i/e)),o=Math.max(0,t-n),l=Math.max(0,Math.min(s.offset,r));return{thumbHeight:n,thumbTop:o*(l/r),maxOffset:r}}function Ce(s,t,e,i){const r=j(s,t);if(r===null)return 0;const n=Math.max(0,t-r.thumbHeight);if(n===0)return 0;const o=Math.max(0,Math.min(e-i,n));return Math.round(o/n*r.maxOffset)}function xe(s){const{bounds:t,clientX:e,clientY:i,cols:r,rows:n,metrics:o,padding:l,originY:h}=s,a=e-t.left-l,c=i-t.top-h;return a<0||c<0||a>=r*o.width||c>=n*o.height?null:{x:Math.floor(a/o.width),y:Math.floor(c/o.height)}}function Pe(s,t){const e=s.cells.map(i=>i.text||" ").join("");return t?e.trimEnd():e}function wt(s,t){let e=0;for(let i=0;i<t;i+=1)e+=s.cells[i]?.text.length||1;return e}function ht(s,t){for(let e=0;e<s.cells.length;e+=1){const i=wt(s,e+1);if(t<i)return e}return Math.max(0,s.cells.length-1)}function Le(s,t,e){const i=Mt(t+1,u=>{const d=s[u];return d?{isWrapped:d.isWrapContinuation,translateToString:(m=!1)=>Pe(d,m)}:null});if(!i)return null;const r=i.segments[0];if(r&&s[r.bufferLineNumber-1]?.isWrapContinuation)return null;const n=i.segments.find(u=>u.bufferLineNumber===t+1),o=s[t];if(!n||!o)return null;const l=i.segments.at(-1),h=l?s[l.bufferLineNumber-1]:void 0,a=h!==void 0&&h.wrapsToNext,c=n.startIndex+wt(o,e);for(const u of vt(i.text))if(c>=u.start&&c<u.end){if(u.end===i.text.length&&a)return null;const d=i.segments.find(f=>u.start>=f.startIndex&&u.start<f.endIndex),m=i.segments.find(f=>u.end-1>=f.startIndex&&u.end-1<f.endIndex),g=d?s[d.bufferLineNumber-1]:void 0,y=m?s[m.bufferLineNumber-1]:void 0;return!d||!m||!g||!y?null:{text:u.text,range:{start:{x:ht(g,u.start-d.startIndex),y:d.bufferLineNumber-1},end:{x:ht(y,u.end-1-m.startIndex),y:m.bufferLineNumber-1}}}}return null}function Re(s,t=navigator.platform){return s.key.toLowerCase()!=="c"?!1:D(t)?s.metaKey:s.ctrlKey}function Fe(s,t){s.value=t,t.length!==0&&s.select()}function De(s,t){t.length===0||s.value!==t||(s.value="")}function Ie(s,t){return s.length===0||!t?{preventDefault:!1,claimWriteFallback:!1}:(t.setData("text/plain",s),{preventDefault:!0,claimWriteFallback:!0})}function Ne(s,t=navigator.platform){const e=s.key.toLowerCase();return e==="insert"&&!D(t)?s.shiftKey&&!s.ctrlKey&&!s.metaKey:e!=="v"?!1:D(t)?s.metaKey:s.ctrlKey&&s.shiftKey}function ze(s){return s.inputType===""||s.inputType==="insertCompositionText"||s.inputType==="insertFromComposition"}function at(s,t){return s.isComposing||t||s.key==="Process"||s.keyCode===229}function Be(s){return s.getModifierState("AltGraph")&&[...s.key].length===1}function O(s,t){return s&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey}function Ue(s,t,e){const i=s==="motion"?t:"";return{send:t.length>0&&(s!=="motion"||t!==e),nextMotionData:i}}function Oe(s,t,e){return{tracking:t,motionData:s===t?e:""}}function Ke(s,t,e,i){const r=s.deltaMode===1?s.deltaY*t:s.deltaMode===2?s.deltaY*e*t:s.deltaY,n=i+r/t,o=Math.trunc(n);return{rows:o,remainder:n-o}}function We(s,t){return s===0?"":(s<0?t?"\x1BOA":"\x1B[A":t?"\x1BOB":"\x1B[B").repeat(Math.abs(s))}function F(s,t=navigator.platform){return D(t)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey}function Ge(s){switch(s){case 0:return 1;case 1:return 3;case 2:return 2;case 3:return 4;case 4:return 5;default:return null}}function Ye(s,t){return{count:s!==null&&t.timeStamp-s.time<=we&&Math.hypot(t.clientX-s.x,t.clientY-s.y)<=4?s.count>=3?1:s.count+1:1,time:t.timeStamp,x:t.clientX,y:t.clientY}}class _t{canvas;input;scrollbar;cols=1;rows=1;mount;context;core;options;visible;hasSize=!1;metrics;fontFamily;requestedFontFamily;fontSize;fontEpoch=0;pendingFontEpoch=null;resizeObserver;scrollbarThumb;snapshot=null;frame=0;cursorTimer=null;compositionInputToSuppress=null;compositionSuppressionTimer=null;cursorOn=!0;renderedCursorY=null;forceFullRender=!0;scrollbarDirty=!0;scrollbarState=null;scrollbarPointerId=null;scrollbarPointerOffset=0;disposed=!1;resizeNotifyTimer=null;originY=k;mountHeight=0;selectionEnd=null;selectionAnchorScreen=null;selectionEndScreen=null;selectionMode="cell";selectionBase=null;selectionScrollTimer=null;selectionScrollDelta=0;selectionPointer=null;mouseReportingPointerId=null;mouseReportingButton=null;linkActivationPointerId=null;hoveredLink=null;hoverPointer=null;linkModifierActive=!1;selectionClickSequence=null;selectionMoved=!1;composing=!1;focused=!1;resizeNotified=!1;canvasConfigured=!1;theme;suppressedKeyCodes=new Set;pasteShortcutToken=0;copyShortcutToken=0;clearSelectionAfterCopy=!1;primedCopySelection="";wheelRemainder=0;lastMouseMotionData="";mouseAnyEventTracking=!1;dprMedia=null;reducedMotionMedia=window.matchMedia?.("(prefers-reduced-motion: reduce)");inputLeft=-1;inputTop=-1;lastTouchPointerAt=Number.NEGATIVE_INFINITY;constructor(t,e,i,r,n,o,l,h,a,c){this.mount=t,this.canvas=e,this.input=i,this.scrollbar=r,this.scrollbarThumb=n,this.context=o,this.core=l,this.mouseAnyEventTracking=l.isMouseAnyEventTracking(),this.metrics=h,this.options=c,this.visible=c.visible??!0,this.theme=c.theme,this.fontFamily=a,this.requestedFontFamily=c.font?.family,this.fontSize=Z(c.font?.size),this.resizeObserver=new ResizeObserver(()=>this.fit()),this.installEvents(),this.watchDevicePixelRatio(),this.reducedMotionMedia?.addEventListener("change",this.onReducedMotionChange),document.fonts.addEventListener("loadingdone",this.onFontsLoaded),this.resizeObserver.observe(t)}static async create(t,e){const i=document.createElement("canvas");i.className="oc-terminal-canvas",i.setAttribute("aria-hidden","true");const r=document.createElement("textarea");r.className="oc-terminal-input",r.setAttribute("aria-label",e.labels.input),r.setAttribute("autocorrect","off"),r.autocapitalize="off",r.autocomplete="off",r.spellcheck=!1;const n=document.createElement("div");n.className="oc-terminal-scrollbar",n.setAttribute("role","scrollbar"),n.setAttribute("aria-label",e.labels.scrollbar),n.setAttribute("aria-orientation","vertical"),n.tabIndex=-1,n.hidden=!0;const o=document.createElement("div");o.className="oc-terminal-scrollbar-thumb",n.append(o),t.replaceChildren(i,r,n);const l=window.devicePixelRatio||1;t.clientWidth>0&&t.clientHeight>0&&(i.width=Math.max(1,Math.round(t.clientWidth*l)),i.height=Math.max(1,Math.round(t.clientHeight*l)));const h=i.getContext("2d",{alpha:!1,willReadFrequently:!0});if(!h)throw new Error("Canvas 2D is unavailable");h.fillStyle=`rgb(${e.theme.background.r}, ${e.theme.background.g}, ${e.theme.background.b})`,h.fillRect(0,0,i.width,i.height);const a=Z(e.font?.size);try{await Ee()}catch{}const c=await lt(e.font?.family,a),u=X(h,a,c),d=ot(t.clientWidth,t.clientHeight,u,k),m=await tt.create(d.cols,d.rows,u.width,u.height,e.theme,e.onData),g=new _t(t,i,r,n,o,h,m,u,c,e);return g.fit(),g}setVisible(t){if(!(this.disposed||this.visible===t)){if(this.visible=t,this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,!t){this.cancelRender(),this.setSelectionAutoscroll(0);return}this.fit()}}write(t){this.disposed||(this.core.write(t),this.synchronizeMouseTrackingState(),this.cursorOn=!0,this.scrollbarDirty=!0,this.requestRender())}resetAndWrite(t,e){if(this.disposed)return;this.lastMouseMotionData="";const i=e!==void 0&&(e.cols!==this.cols||e.rows!==this.rows);i&&this.core.resize(e.cols,e.rows,this.metrics.width,this.metrics.height);try{this.core.resetAndWrite(t)}finally{i&&this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height)}this.synchronizeMouseTrackingState(),this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}setTheme(t){this.disposed||(this.theme=t,this.core.setTheme(t),this.forceFullRender=!0,this.requestRender())}async setFont(t){if(this.disposed)return;const e=Z(t.size),i=++this.fontEpoch;this.pendingFontEpoch=i;const r=await lt(t.family,e);this.disposed||i!==this.fontEpoch||(this.pendingFontEpoch=null,this.fontFamily=r,this.requestedFontFamily=t.family,this.fontSize=e,this.applyFontMetrics())}applyFontMetrics(){this.metrics=X(this.context,this.fontSize,this.fontFamily),this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height),this.inputLeft=-1,this.inputTop=-1,this.forceFullRender=!0,this.scrollbarDirty=!0,this.fit(),this.requestRender()}onReducedMotionChange=()=>{this.disposed||(this.cursorOn=!0,this.requestRender())};onFontsLoaded=()=>{if(this.disposed||this.pendingFontEpoch!==null)return;const t=gt(this.requestedFontFamily);if(t!==this.fontFamily){this.fontFamily=t,this.applyFontMetrics();return}const e=X(this.context,this.fontSize,this.fontFamily);e.width===this.metrics.width&&e.height===this.metrics.height&&e.baseline===this.metrics.baseline||this.applyFontMetrics()};fit(){if(this.disposed||!this.visible)return!1;const t=this.mount.clientWidth,e=this.mount.clientHeight;if(t<=0||e<=0)return this.hasSize=!1,this.forceFullRender=!0,this.cancelRender(),!1;this.hasSize=!0;const i=window.devicePixelRatio||1,r=Math.max(1,Math.round(t*i)),n=Math.max(1,Math.round(e*i));let o=!1;(this.canvas.width!==r||this.canvas.height!==n||!this.canvasConfigured)&&(this.canvas.width=r,this.canvas.height=n,this.context.setTransform(i,0,0,i,0,0),this.canvasConfigured=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,o=!0);const l=ot(t,e,this.metrics,k);return this.mountHeight=e,(l.cols!==this.cols||l.rows!==this.rows||!this.resizeNotified)&&(this.cols=l.cols,this.rows=l.rows,this.core.resize(l.cols,l.rows,this.metrics.width,this.metrics.height),this.notifyResize(),this.forceFullRender=!0,this.scrollbarDirty=!0,o=!0),(o||this.forceFullRender)&&this.renderFrame(),!0}notifyResize(){this.resizeNotified=!0,this.resizeNotifyTimer!==null&&window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=window.setTimeout(()=>{this.resizeNotifyTimer=null,this.disposed||this.options.onResize(this.cols,this.rows)},150)}focus(){this.disposed||!this.visible||this.input.focus({preventScroll:!0})}async pasteFromClipboard(t,e=()=>!0){const i=++this.pasteShortcutToken,r=await t();if(this.disposed||this.pasteShortcutToken!==i||!e()||(this.pasteShortcutToken+=1,r.length===0))return;const n=this.core.encodePaste(r);n.length>0&&this.options.onData(n)}hasSelection(){return this.core.selectionText().length>0}getSelection(){return this.core.selectionText()}getSelectionPosition(){return!this.selectionAnchorScreen||!this.selectionEndScreen||!this.hasSelection()?null:this.selectionAnchorScreen.y<this.selectionEndScreen.y||this.selectionAnchorScreen.y===this.selectionEndScreen.y&&this.selectionAnchorScreen.x<=this.selectionEndScreen.x?{start:this.selectionAnchorScreen,end:this.selectionEndScreen}:{start:this.selectionEndScreen,end:this.selectionAnchorScreen}}getSelectionEndClientRect(){const t=this.getSelectionPosition();if(!t)return null;const e=this.core.screenPointToViewport(t.end.x,t.end.y);if(!e)return null;const i=this.canvas.getBoundingClientRect();return{right:i.left+k+(e.x+1)*this.metrics.width,bottom:i.top+this.originY+(e.y+1)*this.metrics.height}}clearSelection(){this.clearPrimedCopy(),this.core.clearSelection(),this.selectionEnd=null,this.selectionAnchorScreen=null,this.selectionEndScreen=null,this.selectionMode="cell",this.selectionBase=null,this.setSelectionAutoscroll(0),this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender()}scrollToBottom(){this.core.scrollToBottom(),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}isAtBottom(){return this.core.isViewportActive()}refresh(){this.disposed||(this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollLines(t){this.disposed||this.scrollViewport(t)}selectWordAt(t,e){if(this.disposed)return!1;const i=this.cellAt(t,e),r=this.core.selectWord(i.x,i.y);return r?(this.selectionMode="word",this.selectionMoved=!1,this.selectionBase=r.screen,this.selectionEnd=r.viewport.end,this.selectionAnchorScreen=r.screen.start,this.selectionEndScreen=r.screen.end,this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender(),!0):!1}extendSelectionTo(t,e){if(this.disposed||this.selectionAnchorScreen===null)return;const i=this.cellAt(t,e);i.x===this.selectionEnd?.x&&i.y===this.selectionEnd.y||this.extendSelectionToPoint(t,e)}dispose(){this.disposed||(this.disposed=!0,this.resizeObserver.disconnect(),document.fonts.removeEventListener("loadingdone",this.onFontsLoaded),this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=null,this.reducedMotionMedia?.removeEventListener("change",this.onReducedMotionChange),this.selectionScrollTimer!==null&&window.clearInterval(this.selectionScrollTimer),this.resizeNotifyTimer!==null&&(window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=null,this.options.onResize(this.cols,this.rows)),this.cancelRender(),this.compositionSuppressionTimer!==null&&window.clearTimeout(this.compositionSuppressionTimer),this.removeEvents(),this.core.dispose(),(this.canvas.parentElement===this.mount||this.input.parentElement===this.mount||this.scrollbar.parentElement===this.mount)&&(this.canvas.remove(),this.input.remove(),this.scrollbar.remove()))}onKeyDown=t=>{if(this.updateLinkModifier(t),Be(t)||this.options.beforeKey?.(t)===!1){this.suppressedKeyCodes.add(t.code);return}if(Re(t)&&this.hasSelection()){const r=this.getSelection();if(this.primeCopy(r),t.shiftKey)t.preventDefault(),document.execCommand("copy");else{this.clearSelectionAfterCopy=!t.shiftKey&&!D(navigator.platform);const n=navigator.clipboard;if(n){const o=++this.copyShortcutToken;Promise.resolve().then(()=>{this.disposed||this.copyShortcutToken!==o||n.writeText(r).then(()=>{this.disposed||this.copyShortcutToken!==o||this.clearSelectionAfterCopy&&(this.clearSelectionAfterCopy=!1,this.clearSelection())},()=>{this.copyShortcutToken===o&&(this.clearSelectionAfterCopy=!1)})})}}this.suppressedKeyCodes.add(t.code);return}if(Ne(t)){this.suppressedKeyCodes.add(t.code);const r=navigator.clipboard;if(r){const n=++this.pasteShortcutToken;r.readText().then(o=>{this.disposed||this.pasteShortcutToken!==n||(this.pasteShortcutToken+=1,o.length>0&&this.options.onData(this.core.encodePaste(o)))},()=>{})}return}if(at(t,this.composing))return;this.clearPrimedCopy();const e=this.core.encodeMacWordShortcut(t,navigator.platform),i=e??this.core.encodeKey(t);i.length!==0&&(e!==null?this.suppressedKeyCodes.add(t.code):this.suppressedKeyCodes.delete(t.code),t.preventDefault(),t.stopPropagation(),this.options.onData(i))};onKeyUp=t=>{if(this.updateLinkModifier(t),this.suppressedKeyCodes.delete(t.code)||at(t,this.composing))return;const e=this.core.encodeKey(t,"release");e.length!==0&&(t.preventDefault(),t.stopPropagation(),this.options.onData(e))};onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender()};onBlur=()=>{this.focused=!1,this.linkModifierActive=!1,this.refreshHoveredLink(),this.cursorOn=!0,this.requestRender()};onDevicePixelRatioChange=()=>{this.watchDevicePixelRatio(),this.fit()};watchDevicePixelRatio(){this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDevicePixelRatioChange)}primeCopy(t){this.primedCopySelection=t,Fe(this.input,t)}clearPrimedCopy(){De(this.input,this.primedCopySelection),this.primedCopySelection=""}onCopyEvent=t=>{const e=this.hasSelection()?this.getSelection():this.input.value;this.primeCopy(e);const i=Ie(e,t.clipboardData);i.preventDefault&&t.preventDefault(),i.claimWriteFallback&&(this.copyShortcutToken+=1,this.clearSelectionAfterCopy&&(this.clearSelectionAfterCopy=!1,this.clearSelection()))};onPaste=t=>{t.preventDefault();const e=t.clipboardData?.getData("text/plain")??"";e.length!==0&&(this.pasteShortcutToken+=1,this.options.onData(this.core.encodePaste(e)))};onCompositionStart=()=>{this.clearPrimedCopy(),this.clearCompositionInputSuppression(),this.composing=!0};onCompositionEnd=t=>{this.composing=!1;const e=this.input.value||t.data;e.length>0&&this.options.onData(e),this.input.value="",this.compositionInputToSuppress=e,this.compositionSuppressionTimer=window.setTimeout(()=>{this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null},100)};onInput=t=>{const e=t;if(this.composing||e.isComposing)return;const i=this.input.value||e.data||"";if(i===this.compositionInputToSuppress&&ze(e)){this.clearCompositionInputSuppression(),this.input.value="";return}this.clearCompositionInputSuppression(),i.length>0&&this.options.onData(i),this.input.value=""};clearCompositionInputSuppression(){this.compositionSuppressionTimer!==null&&(window.clearTimeout(this.compositionSuppressionTimer),this.compositionSuppressionTimer=null),this.compositionInputToSuppress=null}ignoresTouchPointer(t){return t.pointerType!=="touch"||this.options.handleTouchPointer!==!1?!1:(this.lastTouchPointerAt=t.timeStamp,!0)}onPointerDown=t=>{if(this.ignoresTouchPointer(t))return;if(this.focus(),O(this.core.isMouseTracking(),t)){const n=Ge(t.button);if(n===null)return;t.preventDefault(),t.stopPropagation(),this.clearHoveredLink("default"),this.mouseReportingPointerId=t.pointerId,this.mouseReportingButton=n,this.sendMouse("press",n,t),this.canvas.setPointerCapture(t.pointerId);return}if(t.button!==0)return;if(F(t)){t.preventDefault(),t.stopPropagation(),this.linkActivationPointerId=t.pointerId,this.canvas.setPointerCapture(t.pointerId);return}this.clearHoveredLink();const e=this.cellAt(t.clientX,t.clientY);this.selectionMoved=!1,this.selectionClickSequence=Ye(this.selectionClickSequence,t);const i=this.selectionClickSequence.count;this.selectionMode=i>=3?"line":i===2?"word":"cell";const r=this.selectionMode==="line"?this.core.selectLine(e.x,e.y):this.selectionMode==="word"?this.core.selectWord(e.x,e.y):null;if(r)this.selectionBase=r.screen,this.selectionEnd=r.viewport.end,this.selectionAnchorScreen=r.screen.start,this.selectionEndScreen=r.screen.end,this.options.onSelectionChange?.();else{this.selectionMode="cell",this.selectionBase=null,this.selectionEnd=e;const n=this.core.viewportPointToScreen(e.x,e.y);this.selectionAnchorScreen=n,this.selectionEndScreen=n,n?this.core.setSelection({...n,tag:2},{...n,tag:2}):this.core.setSelection(e,e)}this.forceFullRender=!0,this.canvas.setPointerCapture(t.pointerId),this.requestRender()};onPointerMove=t=>{if(this.ignoresTouchPointer(t)||this.linkActivationPointerId===t.pointerId)return;const e=this.synchronizeMouseTrackingState();if(this.mouseReportingPointerId===t.pointerId||O(e,t)){t.preventDefault(),this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.setHoveredLink(null),this.canvas.style.cursor="default",this.sendMouse("motion",this.buttonFromButtons(t.buttons),t);return}if(this.lastMouseMotionData="",!this.selectionAnchorScreen||!this.canvas.hasPointerCapture(t.pointerId)){this.updateHoverCursor(t);return}this.clearHoveredLink(),this.selectionPointer={x:t.clientX,y:t.clientY};const i=this.canvas.getBoundingClientRect();this.setSelectionAutoscroll(t.clientY<i.top?-1:t.clientY>i.bottom?1:0);const r=this.cellAt(t.clientX,t.clientY);r.x===this.selectionEnd?.x&&r.y===this.selectionEnd.y||this.extendSelectionToPoint(t.clientX,t.clientY)};extendSelectionToPoint(t,e){const i=this.selectionAnchorScreen;if(i===null)return;const r=this.cellAt(t,e);this.selectionMoved=!0,this.selectionEnd=r;const n=this.selectionMode==="line"?this.core.selectLine(r.x,r.y):this.selectionMode==="word"?this.core.selectWord(r.x,r.y):null,o=this.core.viewportPointToScreen(r.x,r.y);if(o===null)return;const l=this.selectionBase,h=l!==null&&(o.y<l.start.y||o.y===l.start.y&&o.x<l.start.x),a=l===null?i:h?l.end:l.start,c=n===null?o:h?n.screen.start:n.screen.end;this.selectionAnchorScreen=a,this.selectionEndScreen=c,this.core.setSelection({...a,tag:2},{...c,tag:2}),this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender()}setSelectionAutoscroll(t){if(this.selectionScrollDelta=t,t===0){this.selectionScrollTimer!==null&&(window.clearInterval(this.selectionScrollTimer),this.selectionScrollTimer=null);return}this.selectionScrollTimer===null&&(this.selectionScrollTimer=window.setInterval(()=>{if(this.disposed||this.selectionScrollDelta===0)return;this.scrollViewport(this.selectionScrollDelta);const e=this.selectionPointer;e&&this.extendSelectionToPoint(e.x,e.y)},80))}updateHoverCursor(t){this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.refreshHoveredLink()}updateLinkModifier(t){const e=F(t);e!==this.linkModifierActive&&(this.linkModifierActive=e,this.refreshHoveredLink())}onPointerLeave=()=>{this.lastMouseMotionData="",this.clearHoveredLink()};clearHoveredLink(t=""){this.hoverPointer=null,this.setHoveredLink(null),this.canvas.style.cursor=t}refreshHoveredLink(){const t=this.hoverPointer,e=t&&this.linkModifierActive?this.linkAt(t.x,t.y):null;this.setHoveredLink(e)}setHoveredLink(t){const e=this.hoveredLink,i=e?.text===t?.text&&e?.range.start.x===t?.range.start.x&&e?.range.start.y===t?.range.start.y&&e?.range.end.x===t?.range.end.x&&e?.range.end.y===t?.range.end.y;this.canvas.style.cursor=t?"pointer":"",!i&&(this.hoveredLink=t,this.forceFullRender=!0,this.requestRender())}onPointerUp=t=>{if(!this.ignoresTouchPointer(t)){if(this.setSelectionAutoscroll(0),this.linkActivationPointerId===t.pointerId){if(t.preventDefault(),t.stopPropagation(),this.linkActivationPointerId=null,this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.type!=="pointercancel"){const e=this.linkAt(t.clientX,t.clientY);e&&this.options.onLinkActivate?.(e.text,t)}return}if(this.mouseReportingPointerId===t.pointerId){t.preventDefault(),t.stopPropagation(),this.sendMouse("release",this.mouseReportingButton,t),this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.type==="pointercancel"?this.clearHoveredLink():(this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.refreshHoveredLink());return}this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.button===0&&(!this.selectionMoved&&this.selectionMode==="cell"&&this.clearSelection(),this.options.onSelectionChange?.())}};onWheel=t=>{if(t.deltaY===0)return;t.preventDefault();const e=Ke(t,this.metrics.height,this.rows,this.wheelRemainder);if(this.wheelRemainder=e.remainder,e.rows===0)return;const i=Math.abs(e.rows);if(O(this.core.isMouseTracking(),t)){const r=e.rows<0?4:5;for(let n=0;n<i;n+=1)this.sendMouse("press",r,t);return}if(this.core.isAlternateScreen()){this.options.onData(We(e.rows,this.core.isApplicationCursorKeys()));return}this.scrollViewport(e.rows)};onMouseDown=t=>{t.button===0&&t.preventDefault(),!(t.timeStamp-this.lastTouchPointerAt<_e)&&this.focus()};onContextMenu=t=>{if(O(this.core.isMouseTracking(),t)){t.preventDefault();return}this.options.onContextMenu?.(t)};onScrollbarPointerDown=t=>{if(t.button!==0)return;const e=this.readScrollbarState();if(e===null)return;const i=this.scrollbar.getBoundingClientRect(),r=j(e,i.height);r!==null&&(t.preventDefault(),t.stopPropagation(),this.scrollbarPointerId=t.pointerId,this.scrollbarPointerOffset=t.target===this.scrollbarThumb?t.clientY-i.top-r.thumbTop:r.thumbHeight/2,this.scrollbar.setPointerCapture(t.pointerId),this.scrollbarToPointer(t.clientY,i))};onScrollbarPointerMove=t=>{t.pointerId!==this.scrollbarPointerId||this.scrollbarState===null||(t.preventDefault(),this.scrollbarToPointer(t.clientY,this.scrollbar.getBoundingClientRect()))};onScrollbarPointerUp=t=>{t.pointerId===this.scrollbarPointerId&&(t.preventDefault(),this.scrollbarPointerId=null,this.scrollbar.hasPointerCapture(t.pointerId)&&this.scrollbar.releasePointerCapture(t.pointerId))};onScrollbarKeyDown=t=>{const e=this.readScrollbarState();if(e===null)return;let i=0;switch(t.key){case"ArrowUp":i=-1;break;case"ArrowDown":i=1;break;case"PageUp":i=-Math.max(1,e.len);break;case"PageDown":i=Math.max(1,e.len);break;case"Home":i=-e.offset;break;case"End":i=e.total-e.len-e.offset;break;default:return}t.preventDefault(),t.stopPropagation(),this.scrollViewport(i)};installEvents(){this.input.addEventListener("keydown",this.onKeyDown),this.input.addEventListener("keyup",this.onKeyUp),this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("blur",this.onBlur),this.input.addEventListener("input",this.onInput),this.input.addEventListener("paste",this.onPaste),this.input.addEventListener("copy",this.onCopyEvent),this.input.addEventListener("compositionstart",this.onCompositionStart),this.input.addEventListener("compositionend",this.onCompositionEnd),this.canvas.addEventListener("pointerdown",this.onPointerDown),this.canvas.addEventListener("pointermove",this.onPointerMove),this.canvas.addEventListener("pointerleave",this.onPointerLeave),this.canvas.addEventListener("pointerup",this.onPointerUp),this.canvas.addEventListener("pointercancel",this.onPointerUp),this.canvas.addEventListener("wheel",this.onWheel,{passive:!1}),this.canvas.addEventListener("mousedown",this.onMouseDown),this.canvas.addEventListener("contextmenu",this.onContextMenu),this.scrollbar.addEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.addEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.addEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.addEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.addEventListener("keydown",this.onScrollbarKeyDown)}removeEvents(){this.input.removeEventListener("keydown",this.onKeyDown),this.input.removeEventListener("keyup",this.onKeyUp),this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("blur",this.onBlur),this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("paste",this.onPaste),this.input.removeEventListener("copy",this.onCopyEvent),this.input.removeEventListener("compositionstart",this.onCompositionStart),this.input.removeEventListener("compositionend",this.onCompositionEnd),this.canvas.removeEventListener("pointerdown",this.onPointerDown),this.canvas.removeEventListener("pointermove",this.onPointerMove),this.canvas.removeEventListener("pointerleave",this.onPointerLeave),this.canvas.removeEventListener("pointerup",this.onPointerUp),this.canvas.removeEventListener("pointercancel",this.onPointerUp),this.canvas.removeEventListener("wheel",this.onWheel),this.canvas.removeEventListener("mousedown",this.onMouseDown),this.canvas.removeEventListener("contextmenu",this.onContextMenu),this.scrollbar.removeEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.removeEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.removeEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("keydown",this.onScrollbarKeyDown)}scrollViewport(t){let e=Math.trunc(t);const i=this.readScrollbarState();if(i!==null){const r=Math.max(0,i.total-i.len),n=Math.max(0,Math.min(i.offset+e,r));e=n-i.offset,this.scrollbarState={...i,offset:n}}e!==0&&(this.core.scroll(e),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollbarToPointer(t,e){const i=this.scrollbarState;if(i===null)return;const r=Ce(i,e.height,t-e.top,this.scrollbarPointerOffset);this.scrollViewport(r-i.offset)}updateScrollbar(){const t=this.readScrollbarState(),e=t===null?null:j(t,Math.max(0,this.mount.clientHeight-k*2));this.scrollbar.hidden=e===null,!(t===null||e===null)&&(this.scrollbar.setAttribute("aria-valuemin","0"),this.scrollbar.setAttribute("aria-valuemax",String(e.maxOffset)),this.scrollbar.setAttribute("aria-valuenow",String(Math.max(0,Math.min(t.offset,e.maxOffset)))),this.scrollbarThumb.style.height=`${e.thumbHeight}px`,this.scrollbarThumb.style.transform=`translateY(${e.thumbTop}px)`)}readScrollbarState(){const t=this.core.scrollbarState();return this.scrollbarState=t,t}requestRender(){this.disposed||!this.visible||!this.hasSize||this.frame!==0||(this.frame=window.requestAnimationFrame(()=>{this.frame=0,this.renderFrame()}))}cancelRender(){this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.cursorTimer!==null&&(window.clearTimeout(this.cursorTimer),this.cursorTimer=null)}renderFrame(){if(this.disposed||!this.visible)return;if(this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.mount.clientWidth===0||this.mount.clientHeight===0){this.hasSize=!1,this.forceFullRender=!0,this.cancelRender();return}this.snapshot=this.core.snapshot(),this.blinkEnabled()||(this.cursorOn=!0);const t=this.readScrollbarState(),e=t!==null&&t.total>t.len,i=Ae(this.mountHeight,k,this.rows,this.metrics.height,e);i!==this.originY&&(this.originY=i,this.forceFullRender=!0),this.refreshHoveredLink(),me({context:this.context,snapshot:this.snapshot,metrics:this.metrics,fontSize:this.fontSize,fontFamily:this.fontFamily,padding:k,originY:this.originY,forceFull:this.forceFullRender,cursorOn:this.cursorOn,previousCursorY:this.renderedCursorY,focused:this.focused,hoveredLinkRange:this.hoveredLink?.range??null,selectionBackground:this.theme.selectionBackground}),this.positionInput(),this.renderedCursorY=this.cursorOn&&this.snapshot.cursorVisible&&this.snapshot.cursorY>=0?this.snapshot.cursorY:null,this.scrollbarDirty&&(this.scrollbarDirty=!1,this.updateScrollbar()),this.forceFullRender=!1,this.scheduleCursorBlink()}scheduleCursorBlink(){this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,this.blinkEnabled()&&(this.cursorTimer=window.setTimeout(()=>{this.cursorTimer=null,this.cursorOn=!this.cursorOn,this.requestRender()},ve))}blinkEnabled(){const t=this.snapshot;return!t||!this.visible||!this.hasSize?!1:ke({focused:this.focused,cursorBlinking:t.cursorBlinking,cursorVisible:t.cursorVisible,reducedMotion:this.reducedMotionMedia?.matches??!1})}positionInput(){const t=this.snapshot;if(!t||!t.cursorVisible||t.cursorX<0||t.cursorY<0)return;const e=k+t.cursorX*this.metrics.width,i=this.originY+t.cursorY*this.metrics.height;e===this.inputLeft&&i===this.inputTop||(this.inputLeft=e,this.inputTop=i,this.input.style.left=`${e}px`,this.input.style.top=`${i}px`,this.input.style.height=`${this.metrics.height}px`)}cellAt(t,e){const i=this.canvas.getBoundingClientRect();return{x:Math.max(0,Math.min(this.cols-1,Math.floor((t-i.left-k)/this.metrics.width))),y:Math.max(0,Math.min(this.rows-1,Math.floor((e-i.top-this.originY)/this.metrics.height)))}}linkAt(t,e){if(!this.snapshot)return null;const i=xe({bounds:this.canvas.getBoundingClientRect(),clientX:t,clientY:e,cols:this.cols,rows:this.rows,metrics:this.metrics,padding:k,originY:this.originY});if(!i)return null;const r=this.core.hyperlinkAt(i.x,i.y);if(r){const n={...i},o={...i};for(;;){const l=n.x>0?{x:n.x-1,y:n.y}:n.y>0&&this.snapshot.rowData[n.y]?.isWrapContinuation?{x:this.cols-1,y:n.y-1}:null;if(!l||this.core.hyperlinkAt(l.x,l.y)!==r)break;n.x=l.x,n.y=l.y}for(;;){const l=o.x+1<this.cols?{x:o.x+1,y:o.y}:o.y+1<this.rows&&this.snapshot.rowData[o.y]?.wrapsToNext?{x:0,y:o.y+1}:null;if(!l||this.core.hyperlinkAt(l.x,l.y)!==r)break;o.x=l.x,o.y=l.y}return{text:r,range:{start:n,end:o}}}return Le(this.snapshot.rowData,i.y,i.x)}sendMouse(t,e,i){const r=this.canvas.getBoundingClientRect(),n=this.core.encodeMouse({action:t,button:e,mods:(i.shiftKey?1:0)|(i.ctrlKey?2:0)|(i.altKey?4:0)|(i.metaKey?8:0),x:Math.max(0,i.clientX-r.left),y:Math.max(0,i.clientY-r.top),screenWidth:r.width,screenHeight:r.height,cellWidth:this.metrics.width,cellHeight:this.metrics.height,paddingLeft:k,paddingRight:k,paddingTop:this.originY,paddingBottom:Math.max(0,r.height-this.originY-this.rows*this.metrics.height),anyButtonPressed:i.buttons!==0}),o=Ue(t,n,this.lastMouseMotionData);this.lastMouseMotionData=o.nextMotionData,o.send&&this.options.onData(n)}synchronizeMouseTrackingState(){const t=this.core.isMouseAnyEventTracking(),e=Oe(this.mouseAnyEventTracking,t,this.lastMouseMotionData);return this.mouseAnyEventTracking=e.tracking,this.lastMouseMotionData=e.motionData,t}buttonFromButtons(t){return(t&1)!==0?1:(t&4)!==0?3:(t&2)!==0?2:(t&8)!==0?4:(t&16)!==0?5:null}}export{G as DEFAULT_TERMINAL_FONT_FAMILY,_t as GhosttyTerminalSurface,Ye as advanceTerminalSelectionClickSequence,Re as isTerminalCopyShortcut,F as isTerminalLinkPointerGesture,Ne as isTerminalPasteShortcut,lt as loadTerminalFontFamily,Ue as resolveTerminalMouseData,ke as shouldBlinkTerminalCursor,Ae as terminalContentOriginY,Z as terminalFontSize,xe as terminalGridCellAt,Le as terminalLinkAtPositionWithRange,j as terminalScrollbarGeometry,Ce as terminalScrollbarOffsetAtPointer,We as terminalWheelArrowData,Ke as terminalWheelDeltaRows};