@bendyline/gezel-service 1.1.1 → 1.1.2

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 (185) hide show
  1. package/dist/NOTICE.md +3 -3
  2. package/dist/bin/gezeld.js +8471 -5311
  3. package/dist/handboek-content/technical/building-connected-apps-with-gezel-app-sdk.md +78 -0
  4. package/dist/handboek-content/whats-new/{1.26250.md → 1.26251.md} +5 -5
  5. package/dist/index-store/static-index-worker.js +160 -51
  6. package/dist/index.d.ts +416 -71
  7. package/dist/index.js +8465 -5305
  8. package/dist/memory/embed-worker.js +132 -4
  9. package/dist/memory/image-embed-worker.js +14 -5
  10. package/dist/providers/mlx/python/cache_persist.py +52 -8
  11. package/dist/providers/mlx/python/gezel_mlx_server.py +44 -1
  12. package/dist/providers/mlx/python/qwen4_ple.py +159 -0
  13. package/dist/providers/mlx/python/spec_decode.py +73 -31
  14. package/dist/providers/mlx/python/tool_call_stream.py +10 -2
  15. package/dist/providers/mlx/python/tool_grammar.py +16 -0
  16. package/dist/ui/assets/{AmbientDashboardCard-DcVHxEdC.js → AmbientDashboardCard-_xnAQGnk.js} +1 -1
  17. package/dist/ui/assets/{AudioEngineSettings-BFM2S1mm.js → AudioEngineSettings-CgXgbX0i.js} +1 -1
  18. package/dist/ui/assets/{BenchmarksView-84-YeULA.js → BenchmarksView-BlExZpYA.js} +1 -1
  19. package/dist/ui/assets/CatalogBrowser-DYXUZQ_t.js +1 -0
  20. package/dist/ui/assets/{ChannelsSettings-7NAVUk4k.js → ChannelsSettings-EH27HcqZ.js} +1 -1
  21. package/dist/ui/assets/ChatTimelineView-Dn1TNyVn.js +7 -0
  22. package/dist/ui/assets/{ConnectedAppsPanel-CIgF4Q3R.js → ConnectedAppsPanel-BROry-Y0.js} +1 -1
  23. package/dist/ui/assets/CraftbookEditor-B2RNJnFf.js +1 -0
  24. package/dist/ui/assets/{CraftbookScriptEditorView-Ck5tzj3Y.js → CraftbookScriptEditorView-B-vySmHP.js} +1 -1
  25. package/dist/ui/assets/{CraftbookTabContent-BWg7FhK_.js → CraftbookTabContent-BW_2KC89.js} +1 -1
  26. package/dist/ui/assets/{CraftbookToolsetSetup-EuFOiUzR.js → CraftbookToolsetSetup-J7rEa835.js} +1 -1
  27. package/dist/ui/assets/{CraftbooksView-BIzQ1VVn.js → CraftbooksView-BjBUWPGF.js} +1 -1
  28. package/dist/ui/assets/DiffpackReviewView-CD4qJmgT.js +1 -0
  29. package/dist/ui/assets/DocumentDetail-SYozruTJ.js +1 -0
  30. package/dist/ui/assets/DocumentsView-DE7eL49Z.js +1 -0
  31. package/dist/ui/assets/{Ds4Settings-9soZCSeO.js → Ds4Settings-DGzc7JcD.js} +1 -1
  32. package/dist/ui/assets/{EmbeddedChat-Cce7nxXT.js → EmbeddedChat-D92TaJQ8.js} +1 -1
  33. package/dist/ui/assets/{FaceRecognitionCard-BVZyOwB8.js → FaceRecognitionCard-CB1Dt9X4.js} +1 -1
  34. package/dist/ui/assets/FileMapView-kVBG22FU.js +1 -0
  35. package/dist/ui/assets/FoldersSettings-BWFQU5B4.js +1 -0
  36. package/dist/ui/assets/GezelDetail-Br4v42Nv.js +1 -0
  37. package/dist/ui/assets/{GezelJsonEditor-DXXt165-.js → GezelJsonEditor-B9XEiW5Y.js} +1 -1
  38. package/dist/ui/assets/GezellenView-DheEBAy4.js +1 -0
  39. package/dist/ui/assets/{GildeUpdatesCard-CtY8mUTA.js → GildeUpdatesCard-BeIYv09f.js} +1 -1
  40. package/dist/ui/assets/{GithubSignInChip-DT3l6E0Q.js → GithubSignInChip-eEGCe9ar.js} +1 -1
  41. package/dist/ui/assets/{HandboekMediaProvider-ByJ4NAzz.js → HandboekMediaProvider-D0zcbbpf.js} +1 -1
  42. package/dist/ui/assets/HandboekView-p0BZT1rH.js +1 -0
  43. package/dist/ui/assets/{HistoryView-CkinzFEC.js → HistoryView-CKWcWW-Y.js} +1 -1
  44. package/dist/ui/assets/{HomeView-DNBrQnwy.js → HomeView-b_TT5oV3.js} +1 -1
  45. package/dist/ui/assets/{ImageEngineSettings-BfM9HSd_.js → ImageEngineSettings-CJfk4OJ4.js} +1 -1
  46. package/dist/ui/assets/{ImageRecognitionSettings-CaSQu5Br.js → ImageRecognitionSettings-DzbvZk5S.js} +1 -1
  47. package/dist/ui/assets/{IncompleteDownloads-C36lTCMG.js → IncompleteDownloads-C8_XyP8O.js} +1 -1
  48. package/dist/ui/assets/{KnowledgeCatalogsCard-CK9bqdf6.js → KnowledgeCatalogsCard-CHopG_j-.js} +1 -1
  49. package/dist/ui/assets/KnowledgeView-CXNKZUJq.js +1 -0
  50. package/dist/ui/assets/{LlamaCppSettings-CdNMHBbp.js → LlamaCppSettings-ohcM7kes.js} +1 -1
  51. package/dist/ui/assets/{MarkdownField-Dugmfr_e.js → MarkdownField-BX0qsaFq.js} +1 -1
  52. package/dist/ui/assets/{MemoriesTree-CgFqUNEr.js → MemoriesTree-BPj5Rod8.js} +1 -1
  53. package/dist/ui/assets/{MicrophoneSettings-DzDe9y1q.js → MicrophoneSettings-CWjeYnfI.js} +1 -1
  54. package/dist/ui/assets/MlxSettings-Dq6dRpcl.js +1 -0
  55. package/dist/ui/assets/{ModelPicker-BVkJhNAH.js → ModelPicker-0Ue-eEKj.js} +1 -1
  56. package/dist/ui/assets/NewPathDialog-BhAZm9dp.js +1 -0
  57. package/dist/ui/assets/{NewScriptDialog-TEAd0KLl.js → NewScriptDialog-DuryIe50.js} +1 -1
  58. package/dist/ui/assets/NewTaskDialog-BX24flMY.js +2 -0
  59. package/dist/ui/assets/{OllamaSettings-CPy2vxyZ.js → OllamaSettings-Boj8Nd1G.js} +1 -1
  60. package/dist/ui/assets/ProjectChat-Dhw_M5bq.js +5 -0
  61. package/dist/ui/assets/ProjectConnectionsTab-BwpMQNrg.js +1 -0
  62. package/dist/ui/assets/{ProjectGitStatusBar-BgHZ2ijN.js → ProjectGitStatusBar-BORGYx5l.js} +1 -1
  63. package/dist/ui/assets/{ProjectGithubView-BV2uTNU0.js → ProjectGithubView-CTP1BOMv.js} +1 -1
  64. package/dist/ui/assets/{ProjectMailTab-DLtJdXSL.js → ProjectMailTab-qFmAeV3M.js} +1 -1
  65. package/dist/ui/assets/{ProjectOverviewView-ZMs9nL5N.js → ProjectOverviewView-Cq1FsoaT.js} +1 -1
  66. package/dist/ui/assets/{ProjectTimeline-CTPcn4Kc.js → ProjectTimeline-Cqae2Z92.js} +1 -1
  67. package/dist/ui/assets/ProjectsView-D0uJjUB-.js +7 -0
  68. package/dist/ui/assets/{RecommendedBadge-iUoisQBi.js → RecommendedBadge-CN1jEmSn.js} +1 -1
  69. package/dist/ui/assets/{RemoteServersPanel-CTVJ0IRh.js → RemoteServersPanel-CMakvCCM.js} +1 -1
  70. package/dist/ui/assets/{ScriptEditorTabs-CCDFZjdC.js → ScriptEditorTabs-st6dJePd.js} +2 -2
  71. package/dist/ui/assets/{ScriptEditorView-CergLqKj.js → ScriptEditorView-BkySh57_.js} +2 -2
  72. package/dist/ui/assets/{ScriptsView-v7ckdhDi.js → ScriptsView-7uPKwjDB.js} +1 -1
  73. package/dist/ui/assets/{SecurityComplianceSettings-Bd0-66Gs.js → SecurityComplianceSettings-Tsv_pXfy.js} +1 -1
  74. package/dist/ui/assets/SessionSwitcher-D0fSeeHO.js +1 -0
  75. package/dist/ui/assets/SettingsView-cli_z8ZW.js +3 -0
  76. package/dist/ui/assets/{SquisqIntegration-C5l_OPvD.js → SquisqIntegration-BTZ1kBlg.js} +1 -1
  77. package/dist/ui/assets/{StorageCleanupDialog-3kv9-2mT.js → StorageCleanupDialog-CDBjl8JQ.js} +1 -1
  78. package/dist/ui/assets/{StorageUsageCard-7sWTrZFa.js → StorageUsageCard-DXY1j0dZ.js} +1 -1
  79. package/dist/ui/assets/TaskTabContent-C0P681SL.js +1 -0
  80. package/dist/ui/assets/TasksView-Ddwz10ri.js +1 -0
  81. package/dist/ui/assets/{TerminalCodeEditor-ChmdzmCz.js → TerminalCodeEditor-BkNQ6QoQ.js} +2 -2
  82. package/dist/ui/assets/ToolsetsEditor-KVigemfL.js +8 -0
  83. package/dist/ui/assets/{TransformToolbarButton-gzIxUBH7.js → TransformToolbarButton-8wfJR1bO.js} +2 -2
  84. package/dist/ui/assets/{UnrecognizedModels-0hptopv6.js → UnrecognizedModels-BzdU1clO.js} +1 -1
  85. package/dist/ui/assets/{VideoEngineSettings-BdNzCEdR.js → VideoEngineSettings-f79ff57u.js} +1 -1
  86. package/dist/ui/assets/{WorkspaceIndexPane-DnsOO916.js → WorkspaceIndexPane-fu5V6o1W.js} +1 -1
  87. package/dist/ui/assets/{api-C0I7spBl.js → api-CmrgM5Rf.js} +1 -1
  88. package/dist/ui/assets/chat-thread-memory-8MCtb17Q.js +1 -0
  89. package/dist/ui/assets/{chunk-6ECMNUIP-BvCy0HUI.js → chunk-6ECMNUIP-D5AA6ozp.js} +1 -1
  90. package/dist/ui/assets/{chunk-A6N6IN3I-ofeM4l8g.js → chunk-A6N6IN3I-BpxihS5H.js} +1 -1
  91. package/dist/ui/assets/{chunk-ATWVNF7D-CYuW1Yc6.js → chunk-ATWVNF7D-CKIWh7bN.js} +1 -1
  92. package/dist/ui/assets/{chunk-UBFT2CDQ-FexGDigd.js → chunk-CW24CH7I-BD0FIooX.js} +1 -1
  93. package/dist/ui/assets/{chunk-DXYWKZ52-zxe8pjH4.js → chunk-DXYWKZ52-DMKPZnpo.js} +1 -1
  94. package/dist/ui/assets/chunk-IIQYS2YH-BtDJt4Xr.js +1 -0
  95. package/dist/ui/assets/{chunk-KGWT454C-v5-l6U5m.js → chunk-KGWT454C-DsQOBuLg.js} +1 -1
  96. package/dist/ui/assets/{chunk-Q77KNJIN-BLuPdsQF.js → chunk-Q77KNJIN-BdWizq9s.js} +1 -1
  97. package/dist/ui/assets/{chunk-USU6HTKB-B_p-YcDp.js → chunk-USU6HTKB-DyGZplh4.js} +1 -1
  98. package/dist/ui/assets/{chunk-UXEANVBI-Bt0kX-0Z.js → chunk-UXEANVBI-BUBXvqyE.js} +1 -1
  99. package/dist/ui/assets/{chunk-O7JILDEF-CqcO1qaI.js → chunk-X7BNDUNI-D14WIvlD.js} +2 -2
  100. package/dist/ui/assets/{chunk-AE3IUKMM-mZjzzO8Z.js → chunk-ZSU5DJLX-CrjQf-vs.js} +1 -1
  101. package/dist/ui/assets/{container-BI8hxN1N.js → container-iFj1r6Hk.js} +1 -1
  102. package/dist/ui/assets/csv-Di411Mv-.js +1 -0
  103. package/dist/ui/assets/data-Q05qqAp4.js +1 -0
  104. package/dist/ui/assets/{dist-APSIK7H3.js → dist-1FNFiksd.js} +3 -3
  105. package/dist/ui/assets/dist-BMZhqfv7.js +2 -0
  106. package/dist/ui/assets/dist-CE5CbmDb.js +225 -0
  107. package/dist/ui/assets/doc-BHcGsJZd.js +587 -0
  108. package/dist/ui/assets/{document-import-DPK4r8Am.js → document-import-B2Ya6sbf.js} +1 -1
  109. package/dist/ui/assets/{docx-DRLuCTaC.js → docx-B8Pwz5Ih.js} +1 -1
  110. package/dist/ui/assets/{epub-a0p2Xb1b.js → epub-BQ4g8Q9j.js} +1 -1
  111. package/dist/ui/assets/{export-options-BqYFyzWx.js → export-options-Dylv69b3.js} +1 -1
  112. package/dist/ui/assets/file-browser-BLOPfnS0.js +5 -0
  113. package/dist/ui/assets/{html-BbQNmJ5X.js → html-BnA7qFwq.js} +1 -1
  114. package/dist/ui/assets/icons-CyM7Cg4E.js +1 -0
  115. package/dist/ui/assets/index-DW6qHqhU.css +1 -0
  116. package/dist/ui/assets/index-DivKnJyx.js +36 -0
  117. package/dist/ui/assets/{mail-link-CWfsP5Aq.js → mail-link-NtlcX5OE.js} +1 -1
  118. package/dist/ui/assets/{markdown-ryKA_OmY.js → markdown-CLKH_zzl.js} +1 -1
  119. package/dist/ui/assets/markdown-baseline-0dqv9qbV.js +1 -0
  120. package/dist/ui/assets/materialize-G4WC5UG3-xq2dcwS8.js +1 -0
  121. package/dist/ui/assets/{monaco-base-C0VTMpv-.js → monaco-base-BSvdAweA.js} +1 -1
  122. package/dist/ui/assets/{monaco-setup-CX8q88c5.js → monaco-setup-CT7LZ0o_.js} +1 -1
  123. package/dist/ui/assets/{new-project-meta-ZmDPGYzC.js → new-project-meta-5Y9Blozr.js} +1 -1
  124. package/dist/ui/assets/outside-in-Msmhxf_U.js +3 -0
  125. package/dist/ui/assets/{pdf-BHrygJa5.js → pdf-C4BhW3zg.js} +1 -1
  126. package/dist/ui/assets/{pending-drafts-27ujtQxX.js → pending-drafts-BD227X9H.js} +1 -1
  127. package/dist/ui/assets/{poppetje-CfaAvFkE.js → poppetje-DvCJO36y.js} +3 -3
  128. package/dist/ui/assets/{pptx-nDW64jAN.js → pptx-B6uaM2s7.js} +3 -3
  129. package/dist/ui/assets/{run-export-86KzLZ7R.js → run-export-TscWwR6y.js} +2 -2
  130. package/dist/ui/assets/{standalone-source-7QdiNsDW.js → standalone-source-Cw9SF7Zk.js} +1 -1
  131. package/dist/ui/assets/storage-Cmhlwx70.js +1 -0
  132. package/dist/ui/assets/styles-BjDaWeMA.css +1 -0
  133. package/dist/ui/assets/styles-CqO-rmOt.js +554 -0
  134. package/dist/ui/assets/{terminal-monaco-setup-Bar-sYKd.js → terminal-monaco-setup-me523-j-.js} +1 -1
  135. package/dist/ui/assets/{transform-CmAXy0Ck.js → transform-DxJCwK68.js} +1 -1
  136. package/dist/ui/assets/{use-local-model-manager-D1yiurrC.js → use-local-model-manager-8wvk-I-y.js} +1 -1
  137. package/dist/ui/assets/{useCompactLayout-BDtPQcDh.js → useCompactLayout-cm4E9Vja.js} +0 -0
  138. package/dist/ui/assets/{useCopilotAvailability-BHOfHrfT.js → useCopilotAvailability-D9hglSH_.js} +1 -1
  139. package/dist/ui/assets/{useDiffpacks-B0kYhlWQ.js → useDiffpacks-1BN2XJWg.js} +1 -1
  140. package/dist/ui/assets/{useGitSync-DOt-ODiw.js → useGitSync-7m9YA7h5.js} +1 -1
  141. package/dist/ui/assets/{useShowWorkInProgressFeatures-BtpredG7.js → useShowWorkInProgressFeatures-D6QOaTUT.js} +1 -1
  142. package/dist/ui/assets/{useTotalRamBytes-B8NFM27w.js → useTotalRamBytes-Durk383U.js} +1 -1
  143. package/dist/ui/assets/{xlsx-B_pu1ZvY.js → xlsx-BbHA9bxA.js} +1 -1
  144. package/dist/ui/index.html +15 -15
  145. package/package.json +12 -11
  146. package/dist/ui/assets/CatalogBrowser-7_jHy5Q3.js +0 -1
  147. package/dist/ui/assets/ChatTimelineView-Cg_kLK_U.js +0 -7
  148. package/dist/ui/assets/CraftbookEditor-BKAIsnXv.js +0 -1
  149. package/dist/ui/assets/DiffpackReviewView-B2a3zgE-.js +0 -1
  150. package/dist/ui/assets/DocumentDetail-GCYhwQqV.js +0 -1
  151. package/dist/ui/assets/DocumentsView-Cm3RaQ5N.js +0 -1
  152. package/dist/ui/assets/FileMapView-BKJovLcL.js +0 -1
  153. package/dist/ui/assets/FoldersSettings-CuJd2JdE.js +0 -1
  154. package/dist/ui/assets/GezelDetail-D_KIPDhQ.js +0 -1
  155. package/dist/ui/assets/GezellenView-BOOW1QQU.js +0 -1
  156. package/dist/ui/assets/HandboekView-gRzJcIbJ.js +0 -1
  157. package/dist/ui/assets/KnowledgeView-DJ3cJVHA.js +0 -1
  158. package/dist/ui/assets/MlxSettings-45mBFHbA.js +0 -1
  159. package/dist/ui/assets/NewTaskDialog-CIXVunZn.js +0 -2
  160. package/dist/ui/assets/ProjectChat-BiJRweob.js +0 -5
  161. package/dist/ui/assets/ProjectConnectionsTab-CQgaIzuv.js +0 -1
  162. package/dist/ui/assets/ProjectsView-BUdR76n6.js +0 -7
  163. package/dist/ui/assets/SessionSwitcher-BgZqyiRn.js +0 -1
  164. package/dist/ui/assets/SettingsView-DLhOYiR5.js +0 -3
  165. package/dist/ui/assets/TaskTabContent-CG2KmfwV.js +0 -1
  166. package/dist/ui/assets/TasksView-Dy5Ue4zS.js +0 -1
  167. package/dist/ui/assets/ToolsetsEditor-J9XxQ5Ms.js +0 -8
  168. package/dist/ui/assets/chat-thread-memory-CI2-giEq.js +0 -1
  169. package/dist/ui/assets/chunk-IIQYS2YH-DEkyBlHg.js +0 -1
  170. package/dist/ui/assets/csv-B0D9jJG2.js +0 -1
  171. package/dist/ui/assets/data-BIL84EaT.js +0 -1
  172. package/dist/ui/assets/dist-CJqyWK6E.js +0 -2
  173. package/dist/ui/assets/dist-DOqbRmFj.js +0 -225
  174. package/dist/ui/assets/doc-C2Ph2FWI.js +0 -584
  175. package/dist/ui/assets/document-companion-aDThLOwl.js +0 -1
  176. package/dist/ui/assets/file-browser-DVyWN0LD.js +0 -5
  177. package/dist/ui/assets/icons-DWaUNQbT.js +0 -1
  178. package/dist/ui/assets/index-DDu8nyO6.js +0 -34
  179. package/dist/ui/assets/index-DEDUSiCx.css +0 -1
  180. package/dist/ui/assets/markdown-baseline-9B52XlX2.js +0 -1
  181. package/dist/ui/assets/materialize-G4WC5UG3-BlZQe-88.js +0 -1
  182. package/dist/ui/assets/outside-in-BmIIeMid.js +0 -3
  183. package/dist/ui/assets/storage-B-vhjyV2.js +0 -1
  184. package/dist/ui/assets/styles-BvkZd-EV.js +0 -550
  185. package/dist/ui/assets/styles-IQ4adxWr.css +0 -1
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-C0I7spBl.js";import{t as i}from"./ToolsetConfigForm-gUVMTPR_.js";var a=e(t(),1),o=n();function s({missing:e,onAllInstalled:t,onCancel:n}){let[s,c]=(0,a.useState)(new Set),[l,u]=(0,a.useState)(null),[d,f]=(0,a.useState)(null),[p,m]=(0,a.useState)(null),h=n=>{let r=new Set(s);r.add(n),c(r),e.every(e=>r.has(e.toolsetId))&&t()},g=async(e,t,n)=>{u(e),f(null);try{let i=await r.getCatalogItem(`toolset`,e,{...t?{source:t}:{},...n?{version:n}:{}});if(i.manifest.kind!==`toolset`)throw Error(`catalog item is not a toolset`);let a=i.manifest;(a.config??[]).length===0?(await r.installToolset(e,{scope:{kind:`shared`},...n?{version:n}:{}}),h(e)):m(a)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}};return p?(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsxs)(`h4`,{className:`small`,children:[`Configure `,p.name]}),(0,o.jsx)(i,{fields:p.config??[],submitLabel:`Install`,busy:l===p.id,onSubmit:async e=>{if(!p)return;let t=p.id;u(t),f(null);try{let n={};for(let[t,r]of Object.entries(e.secrets))typeof r==`string`&&(n[t]=r);await r.installToolset(t,{scope:{kind:`shared`},values:e.values,secrets:n}),m(null),h(t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}},onCancel:()=>m(null)}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d})]}):(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsx)(`h4`,{className:`small`,children:`This craftbook needs:`}),(0,o.jsx)(`ul`,{className:`commands-panel-list`,children:e.map(e=>{let t=s.has(e.toolsetId);return(0,o.jsx)(`li`,{children:(0,o.jsxs)(`div`,{className:`commands-panel-item`,title:e.reason??e.toolsetId,children:[(0,o.jsx)(`span`,{className:`commands-panel-item-name`,children:e.toolsetId}),e.reason&&(0,o.jsx)(`span`,{className:`commands-panel-item-desc muted small`,children:e.reason}),(0,o.jsx)(`span`,{className:`commands-panel-item-actions`,children:t?(0,o.jsx)(`span`,{className:`muted small`,children:`installed ✓`}):(0,o.jsx)(`button`,{type:`button`,className:`commands-panel-mini`,disabled:l===e.toolsetId,onClick:()=>void g(e.toolsetId,e.sourceId,e.minVersion),children:l===e.toolsetId?`…`:`Install`})})]})},`need:${e.toolsetId}`)})}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d}),(0,o.jsx)(`div`,{className:`toolset-config-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:n,children:`Cancel`})})]})}export{s as t};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-CmrgM5Rf.js";import{t as i}from"./ToolsetConfigForm-gUVMTPR_.js";var a=e(t(),1),o=n();function s({missing:e,onAllInstalled:t,onCancel:n}){let[s,c]=(0,a.useState)(new Set),[l,u]=(0,a.useState)(null),[d,f]=(0,a.useState)(null),[p,m]=(0,a.useState)(null),h=n=>{let r=new Set(s);r.add(n),c(r),e.every(e=>r.has(e.toolsetId))&&t()},g=async(e,t,n)=>{u(e),f(null);try{let i=await r.getCatalogItem(`toolset`,e,{...t?{source:t}:{},...n?{version:n}:{}});if(i.manifest.kind!==`toolset`)throw Error(`catalog item is not a toolset`);let a=i.manifest;(a.config??[]).length===0?(await r.installToolset(e,{scope:{kind:`shared`},...n?{version:n}:{}}),h(e)):m(a)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}};return p?(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsxs)(`h4`,{className:`small`,children:[`Configure `,p.name]}),(0,o.jsx)(i,{fields:p.config??[],submitLabel:`Install`,busy:l===p.id,onSubmit:async e=>{if(!p)return;let t=p.id;u(t),f(null);try{let n={};for(let[t,r]of Object.entries(e.secrets))typeof r==`string`&&(n[t]=r);await r.installToolset(t,{scope:{kind:`shared`},values:e.values,secrets:n}),m(null),h(t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}},onCancel:()=>m(null)}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d})]}):(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsx)(`h4`,{className:`small`,children:`This craftbook needs:`}),(0,o.jsx)(`ul`,{className:`commands-panel-list`,children:e.map(e=>{let t=s.has(e.toolsetId);return(0,o.jsx)(`li`,{children:(0,o.jsxs)(`div`,{className:`commands-panel-item`,title:e.reason??e.toolsetId,children:[(0,o.jsx)(`span`,{className:`commands-panel-item-name`,children:e.toolsetId}),e.reason&&(0,o.jsx)(`span`,{className:`commands-panel-item-desc muted small`,children:e.reason}),(0,o.jsx)(`span`,{className:`commands-panel-item-actions`,children:t?(0,o.jsx)(`span`,{className:`muted small`,children:`installed ✓`}):(0,o.jsx)(`button`,{type:`button`,className:`commands-panel-mini`,disabled:l===e.toolsetId,onClick:()=>void g(e.toolsetId,e.sourceId,e.minVersion),children:l===e.toolsetId?`…`:`Install`})})]})},`need:${e.toolsetId}`)})}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d}),(0,o.jsx)(`div`,{className:`toolset-config-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:n,children:`Cancel`})})]})}export{s as t};
@@ -1,3 +1,3 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-C0I7spBl.js";import{H as i,J as a,K as o,W as s,Y as c,q as l}from"./primitives-CWrGZpPI.js";import{t as u}from"./CraftbookEditor-BKAIsnXv.js";var d=e(t(),1),f=n(),p=[{source:`local`,label:`My craftbooks`,hint:`editable`},{source:`project`,label:`Project`,hint:`read-only`},{source:`bundled`,label:`Gilde catalog`,hint:`read-only — copy to edit`}];function m(){let[e,t]=(0,d.useState)([]),[n,i]=(0,d.useState)(``),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(!1),[l,m]=(0,d.useState)(null),g=(0,d.useCallback)(async()=>{try{let e=await r.listCraftbooks({source:`all`});t(e.craftbooks)}catch(e){m(e.message)}},[]);(0,d.useEffect)(()=>{g()},[g]);let _=(0,d.useMemo)(()=>{let t=n.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)):e},[e,n]),v=(0,d.useCallback)((e,t)=>{c(!1),o({id:e,source:t})},[]);(0,d.useEffect)(()=>{if(a||e.length===0)return;let t=p.map(t=>e.find(e=>e.source===t.source)).find(Boolean)??e[0];t&&o({id:t.id,source:t.source})},[a,e]);let y=(0,d.useCallback)(async e=>{c(!1),await g(),v(e,`local`)},[g,v]),b=(0,d.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return(0,f.jsxs)(`div`,{className:`tasks-view craftbooks-view`,"data-testid":`craftbooks-view`,children:[(0,f.jsxs)(`div`,{className:`tasks-layout craftbooks-layout`,children:[(0,f.jsxs)(`aside`,{className:`craftbooks-sidebar`,"aria-label":`Craftbook library`,children:[(0,f.jsxs)(`div`,{className:`craftbooks-toolbar`,children:[(0,f.jsxs)(`label`,{className:`craftbooks-search-field`,children:[(0,f.jsx)(`span`,{className:`sr-only`,children:`Search craftbooks`}),(0,f.jsx)(`input`,{type:`search`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:n,onChange:e=>i(e.target.value)})]}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>c(!0),children:`+ New craftbook`})]}),l&&(0,f.jsx)(`p`,{className:`error craftbooks-list-error`,children:l}),(0,f.jsxs)(`div`,{className:`tasks-list craftbooks-list`,children:[p.map(e=>{let t=_.filter(t=>t.source===e.source);return t.length===0?null:(0,f.jsxs)(`div`,{className:`craftbook-group`,children:[(0,f.jsxs)(`div`,{className:`craftbook-group-header small muted`,children:[e.label,` `,(0,f.jsxs)(`span`,{className:`craftbook-group-hint`,children:[`· `,e.hint]})]}),(0,f.jsx)(`ul`,{children:t.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`button`,{type:`button`,className:`task-row${a?.id===e.id&&a?.source===e.source?` task-row-selected`:``}`,onClick:()=>v(e.id,e.source),children:(0,f.jsxs)(`span`,{className:`task-row-body`,children:[(0,f.jsx)(`span`,{className:`task-title`,children:e.name}),(0,f.jsxs)(`span`,{className:`task-row-meta`,children:[(0,f.jsx)(`span`,{className:`task-ref`,children:e.id}),(0,f.jsxs)(`span`,{className:`task-assignee`,children:[e.stepCount,` step`,e.stepCount===1?``:`s`]})]})]})})},`${e.source}:${e.id}`))})]},e.source)}),_.length===0&&(0,f.jsxs)(`p`,{className:`muted craftbooks-empty`,children:[`No craftbooks`,n?` match your search`:` yet`,`.`]})]})]}),(0,f.jsx)(`section`,{className:`task-detail-panel craftbooks-detail`,"aria-label":`Craftbook editor`,children:a?(0,f.jsx)(u,{craftbookId:a.id,source:a.source,onChanged:()=>void g()},`${a.source}:${a.id}`):(0,f.jsx)(`p`,{className:`placeholder`,children:`Select a craftbook to edit it, or start a new one. Gilde books open read-only — make a copy to edit them.`})})]}),(0,f.jsx)(h,{open:s,cloneSources:b,onClose:()=>c(!1),onCreated:y})]})}function h({open:e,cloneSources:t,onClose:n,onCreated:u}){let[p,m]=(0,d.useState)(`blank`),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(`Build
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-CmrgM5Rf.js";import{H as i,J as a,K as o,W as s,Y as c,q as l}from"./primitives-CWrGZpPI.js";import{t as u}from"./CraftbookEditor-B2RNJnFf.js";var d=e(t(),1),f=n(),p=[{source:`local`,label:`My craftbooks`,hint:`editable`},{source:`project`,label:`Project`,hint:`read-only`},{source:`bundled`,label:`Gilde catalog`,hint:`read-only — copy to edit`}];function m(){let[e,t]=(0,d.useState)([]),[n,i]=(0,d.useState)(``),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(!1),[l,m]=(0,d.useState)(null),g=(0,d.useCallback)(async()=>{try{let e=await r.listCraftbooks({source:`all`});t(e.craftbooks)}catch(e){m(e.message)}},[]);(0,d.useEffect)(()=>{g()},[g]);let _=(0,d.useMemo)(()=>{let t=n.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)):e},[e,n]),v=(0,d.useCallback)((e,t)=>{c(!1),o({id:e,source:t})},[]);(0,d.useEffect)(()=>{if(a||e.length===0)return;let t=p.map(t=>e.find(e=>e.source===t.source)).find(Boolean)??e[0];t&&o({id:t.id,source:t.source})},[a,e]);let y=(0,d.useCallback)(async e=>{c(!1),await g(),v(e,`local`)},[g,v]),b=(0,d.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return(0,f.jsxs)(`div`,{className:`tasks-view craftbooks-view`,"data-testid":`craftbooks-view`,children:[(0,f.jsxs)(`div`,{className:`tasks-layout craftbooks-layout`,children:[(0,f.jsxs)(`aside`,{className:`craftbooks-sidebar`,"aria-label":`Craftbook library`,children:[(0,f.jsxs)(`div`,{className:`craftbooks-toolbar`,children:[(0,f.jsxs)(`label`,{className:`craftbooks-search-field`,children:[(0,f.jsx)(`span`,{className:`sr-only`,children:`Search craftbooks`}),(0,f.jsx)(`input`,{type:`search`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:n,onChange:e=>i(e.target.value)})]}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>c(!0),children:`+ New craftbook`})]}),l&&(0,f.jsx)(`p`,{className:`error craftbooks-list-error`,children:l}),(0,f.jsxs)(`div`,{className:`tasks-list craftbooks-list`,children:[p.map(e=>{let t=_.filter(t=>t.source===e.source);return t.length===0?null:(0,f.jsxs)(`div`,{className:`craftbook-group`,children:[(0,f.jsxs)(`div`,{className:`craftbook-group-header small muted`,children:[e.label,` `,(0,f.jsxs)(`span`,{className:`craftbook-group-hint`,children:[`· `,e.hint]})]}),(0,f.jsx)(`ul`,{children:t.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`button`,{type:`button`,className:`task-row${a?.id===e.id&&a?.source===e.source?` task-row-selected`:``}`,onClick:()=>v(e.id,e.source),children:(0,f.jsxs)(`span`,{className:`task-row-body`,children:[(0,f.jsx)(`span`,{className:`task-title`,children:e.name}),(0,f.jsxs)(`span`,{className:`task-row-meta`,children:[(0,f.jsx)(`span`,{className:`task-ref`,children:e.id}),(0,f.jsxs)(`span`,{className:`task-assignee`,children:[e.stepCount,` step`,e.stepCount===1?``:`s`]})]})]})})},`${e.source}:${e.id}`))})]},e.source)}),_.length===0&&(0,f.jsxs)(`p`,{className:`muted craftbooks-empty`,children:[`No craftbooks`,n?` match your search`:` yet`,`.`]})]})]}),(0,f.jsx)(`section`,{className:`task-detail-panel craftbooks-detail`,"aria-label":`Craftbook editor`,children:a?(0,f.jsx)(u,{craftbookId:a.id,source:a.source,onChanged:()=>void g()},`${a.source}:${a.id}`):(0,f.jsx)(`p`,{className:`placeholder`,children:`Select a craftbook to edit it, or start a new one. Gilde books open read-only — make a copy to edit them.`})})]}),(0,f.jsx)(h,{open:s,cloneSources:b,onClose:()=>c(!1),onCreated:y})]})}function h({open:e,cloneSources:t,onClose:n,onCreated:u}){let[p,m]=(0,d.useState)(`blank`),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(`Build
2
2
  Review`),[C,w]=(0,d.useState)(``),[T,E]=(0,d.useState)(null),[D,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(null);(0,d.useEffect)(()=>{e&&(m(`blank`),g(``),v(!1),b(``),S(`Build
3
3
  Review`),w(``),E(null),O(!1),A(null))},[e]);let j=(0,d.useMemo)(()=>{let e=C.trim().toLowerCase();return e?t.filter(t=>t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)):t},[t,C]),M=e=>{E(e),_||g(`${e.name} copy`)},N=!D&&h.trim().length>0&&(p===`blank`||T!==null),P=async()=>{if(h.trim()){O(!0),A(null);try{let e;if(p===`existing`){if(!T){A(`Pick a craftbook to base this on.`),O(!1);return}let{craftbook:t}=await r.getCraftbook(T.id,{source:T.source}),n=t.steps.map(e=>({...e}));e={name:h.trim(),...y.trim()?{description:y.trim()}:t.description?{description:t.description}:{},steps:n,entryStepId:t.entryStepId,...t.plan?{plan:t.plan}:{},...t.defaultAssignee?{defaultAssignee:t.defaultAssignee}:{},...t.paramSchema?{paramSchema:t.paramSchema}:{},...t.requirements?{requirements:t.requirements}:{},...t.recommends?{recommends:t.recommends}:{},...t.toolsets?{toolsets:t.toolsets}:{}}}else{let t=x.split(/\n|,/).map(e=>e.trim()).filter(Boolean).map(e=>({name:e}));if(t.length===0){A(`A craftbook needs at least one step.`),O(!1);return}e={name:h.trim(),...y.trim()?{description:y.trim()}:{},steps:t}}u((await r.createCraftbook(e)).craftbook.id)}catch(e){A(e.message)}finally{O(!1)}}};return(0,f.jsx)(a,{open:e,onOpenChange:e=>{!e&&!D&&n()},children:(0,f.jsxs)(l,{children:[(0,f.jsx)(o,{}),(0,f.jsxs)(s,{className:`new-craftbook-dialog`,children:[(0,f.jsx)(c,{asChild:!0,children:(0,f.jsx)(`h3`,{children:`New craftbook`})}),(0,f.jsxs)(`div`,{className:`new-craftbook-modes`,role:`radiogroup`,"aria-label":`How to start the craftbook`,children:[(0,f.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p===`blank`,className:`new-craftbook-mode${p===`blank`?` active`:``}`,onClick:()=>m(`blank`),disabled:D,children:[(0,f.jsx)(`strong`,{children:`Blank`}),(0,f.jsx)(`span`,{className:`muted small`,children:`Start from a fresh list of steps.`})]}),(0,f.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p===`existing`,className:`new-craftbook-mode${p===`existing`?` active`:``}`,onClick:()=>m(`existing`),disabled:D,children:[(0,f.jsx)(`strong`,{children:`Based on existing`}),(0,f.jsx)(`span`,{className:`muted small`,children:`Copy another craftbook's steps, then edit.`})]})]}),p===`existing`&&(0,f.jsxs)(`div`,{className:`new-craftbook-picker`,children:[(0,f.jsx)(`span`,{className:`new-craftbook-field-label`,children:`Base craftbook`}),(0,f.jsx)(`input`,{type:`text`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:C,onChange:e=>w(e.target.value),disabled:D}),(0,f.jsxs)(`ul`,{className:`new-craftbook-picker-list`,"aria-label":`Pick a craftbook to copy`,children:[j.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{type:`button`,"aria-pressed":T?.id===e.id&&T?.source===e.source,className:`new-craftbook-picker-row${T?.id===e.id&&T?.source===e.source?` active`:``}`,onClick:()=>M(e),disabled:D,children:[(0,f.jsx)(`span`,{className:`new-craftbook-picker-name`,children:e.name}),(0,f.jsxs)(`span`,{className:`muted small`,children:[e.source,` · `,e.stepCount,` step`,e.stepCount===1?``:`s`]})]})},`${e.source}:${e.id}`)),j.length===0&&(0,f.jsx)(`li`,{className:`muted small new-craftbook-picker-empty`,children:`No craftbooks match.`})]})]}),(0,f.jsxs)(`label`,{children:[`Name`,(0,f.jsx)(`input`,{type:`text`,value:h,onChange:e=>{g(e.target.value),v(!0)},disabled:D})]}),(0,f.jsxs)(`label`,{children:[`Description`,(0,f.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:2,placeholder:p===`existing`?`Leave blank to keep the original's description.`:`What this craftbook is for.`,disabled:D})]}),p===`blank`&&(0,f.jsxs)(`label`,{children:[`Steps (one per line)`,(0,f.jsx)(`textarea`,{value:x,onChange:e=>S(e.target.value),rows:4,disabled:D})]}),k&&(0,f.jsx)(`p`,{className:`gz-dialog-error`,children:k}),(0,f.jsxs)(i,{children:[(0,f.jsx)(`button`,{type:`button`,onClick:n,disabled:D,children:`Cancel`}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,disabled:!N,onClick:()=>void P(),children:D?`Creating…`:`Create`})]})]})]})})}export{m as CraftbooksView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{et as r}from"./dist-CE5CbmDb.js";import{t as i}from"./api-CmrgM5Rf.js";import{t as a}from"./relative-time-B2kBaekd.js";import{t as o}from"./ConfirmDialog-Dt1ed4Fh.js";import{t as s}from"./GitDiffView-DrDrSeBb.js";import{a as c}from"./gitCopy-Dcjz17cJ.js";import{t as l}from"./MarkdownField-BX0qsaFq.js";import{n as u}from"./useDiffpacks-1BN2XJWg.js";var d=e(t(),1),f=n();function p({paths:e,onConfirm:t,onCancel:n}){return(0,f.jsx)(o,{open:!0,danger:!0,title:`These files changed since the proposal was written`,confirmLabel:`Apply anyway`,message:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`p`,{children:e.length===1?`This file has been edited since the gezel drafted its change:`:`These files have been edited since the gezel drafted its change:`}),(0,f.jsx)(`ul`,{children:e.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`code`,{children:e})},e))}),(0,f.jsx)(`p`,{children:`The change may no longer do what was intended. Anything that plainly doesn’t fit will still be refused.`})]}),onConfirm:t,onCancel:n})}var m=()=>{};function h(e){switch(e.status){case`drafting`:return`Being written`;case`ready`:return`Ready to review`;case`applied`:return`Applied`;case`partially-applied`:return`Partly applied`;case`dismissed`:return`Dismissed`;case`failed`:return`Didn’t work out`}}function g(e){return e.change===`add`?`New file`:e.change===`delete`?`Delete`:`Edit`}function _({projectId:e}){let{diffpacks:t,loaded:n,busy:o,apply:_,dismiss:v}=u(e),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)({}),[T,E]=(0,d.useState)(null),[D,O]=(0,d.useState)(null),k=(0,d.useMemo)(()=>t.find(e=>e.packId===y)??t[0]??null,[t,y]);(0,d.useEffect)(()=>{if(!k)return;let t=!1;S(null),w({}),i.getDiffpack(e,k.packId).then(e=>{t||S({packId:k.packId,text:e.notes})}).catch(()=>{t||S({packId:k.packId,text:``})});for(let n of k.files)n.diffArtifact&&i.readProjectArtifact(e,n.diffArtifact).then(e=>{t||w(t=>({...t,[n.path]:e.content}))}).catch(()=>{});return()=>{t=!0}},[e,k]);let A=async(e={})=>{if(!k)return;let t=await _(k.packId,e);if(!t.ok&&t.drifted.length>0&&!e.allowDrifted){O({paths:t.drifted,...e.paths?{subset:e.paths}:{}});return}E(t.message)},j=async()=>{if(k)try{let t=await i.exportDiffpack(e,k.packId),n=URL.createObjectURL(t),a=document.createElement(`a`);a.href=n,a.download=`${r(k.packId)}.zip`,a.click(),URL.revokeObjectURL(n)}catch(e){E(e instanceof Error?e.message:String(e))}};return n&&t.length===0?(0,f.jsx)(`div`,{className:`dp-empty`,children:(0,f.jsx)(`p`,{className:`placeholder`,children:`No change proposals yet. When a gezel fixes something here, the change lands as a proposal you read and apply — your files aren’t touched until you say so.`})}):(0,f.jsxs)(`div`,{className:`dp-layout`,children:[(0,f.jsx)(`div`,{className:`dp-list`,children:t.map(e=>(0,f.jsxs)(`button`,{type:`button`,className:`dp-list-item${e.packId===k?.packId?` dp-list-item-active`:``}`,onClick:()=>b(e.packId),children:[(0,f.jsxs)(`span`,{className:`dp-list-head`,children:[(0,f.jsx)(`code`,{className:`dp-ref`,children:r(e.packId)}),(0,f.jsx)(`span`,{className:`dp-status dp-status-${e.status}`,children:h(e)})]}),(0,f.jsx)(`span`,{className:`dp-list-title`,children:e.title}),(0,f.jsxs)(`span`,{className:`muted small`,children:[c(e.files.length,`file`),` · +`,e.additions,` −`,e.deletions,e.origin.kind===`boekwachter-issue`?` · ${e.origin.issueRefs.join(`, `)}`:``]}),(e.drifted.length>0||e.overlaps.length>0)&&(0,f.jsxs)(`span`,{className:`dp-list-flags`,children:[e.drifted.length>0&&(0,f.jsx)(`span`,{className:`dp-flag dp-flag-drift`,children:`Out of date`}),e.overlaps.length>0&&(0,f.jsxs)(`span`,{className:`dp-flag`,children:[`Overlaps`,` `,[...new Set(e.overlaps.flatMap(e=>e.packIds))].map(r).join(`, `)]})]})]},e.packId))}),(0,f.jsx)(`div`,{className:`dp-detail`,children:k?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`dp-detail-head`,children:[(0,f.jsx)(`h3`,{children:k.title}),(0,f.jsxs)(`p`,{className:`muted small`,children:[k.gezelName?`Drafted by ${k.gezelName}`:`Drafted`,k.sealedAt?` · ${a(k.sealedAt)}`:``]})]}),k.drifted.length>0&&(0,f.jsxs)(`output`,{className:`dp-notice`,children:[k.drifted.join(`, `),` changed since this was written, so the proposal may no longer fit. Read the diff before applying.`]}),k.overlaps.length>0&&(0,f.jsxs)(`output`,{className:`dp-notice`,children:[`Another proposal touches`,` `,[...new Set(k.overlaps.map(e=>e.path))].join(`, `),`. Applying one will put the other out of date.`]}),x?.packId===k.packId&&x.text?(0,f.jsx)(l,{value:x.text,readOnly:!0,onCommit:m},k.packId):k.status===`drafting`?(0,f.jsx)(`p`,{className:`muted`,children:`Still being written…`}):null,(0,f.jsx)(`div`,{className:`dp-files`,children:k.files.map(e=>(0,f.jsxs)(`section`,{className:`dp-file`,children:[(0,f.jsxs)(`header`,{className:`dp-file-head`,children:[(0,f.jsx)(`code`,{className:`dp-file-path`,title:e.path,children:e.path}),(0,f.jsxs)(`span`,{className:`muted small`,children:[g(e),` · +`,e.additions,` −`,e.deletions]}),k.status===`ready`&&e.change!==`delete`&&(0,f.jsx)(`button`,{type:`button`,className:`small`,disabled:o===k.packId,onClick:()=>void A({paths:[e.path]}),children:`Apply this file`})]}),e.change===`delete`?(0,f.jsx)(`p`,{className:`git-diff-placeholder muted`,children:`This proposal suggests deleting the file.`}):(0,f.jsx)(s,{diff:C[e.path]})]},e.path))}),T&&(0,f.jsx)(`output`,{className:`dp-toast`,children:T}),(0,f.jsxs)(`div`,{className:`gz-tray dp-actions`,role:`toolbar`,"aria-label":`Actions for ${r(k.packId)}`,children:[(0,f.jsx)(`button`,{type:`button`,className:`gz-key dp-key-apply`,disabled:k.status!==`ready`||o===k.packId,onClick:()=>void A(),children:o===k.packId?`Applying…`:`Apply all`}),(0,f.jsx)(`button`,{type:`button`,className:`gz-key`,onClick:()=>void j(),children:`Export`}),(0,f.jsx)(`button`,{type:`button`,className:`gz-key`,disabled:o===k.packId,onClick:()=>{v(k.packId).then(e=>e&&E(e))},children:`Dismiss`})]})]}):(0,f.jsx)(`p`,{className:`placeholder`,children:`Pick a proposal to read it.`})}),D&&k&&(0,f.jsx)(p,{paths:D.paths,onCancel:()=>O(null),onConfirm:()=>{let e=D.subset;O(null),A({allowDrifted:!0,...e?{paths:e}:{}})}})]})}export{_ as DiffpackReviewView};
@@ -0,0 +1 @@
1
+ import{i as e,n as t}from"./rolldown-runtime-aKtaBQYM.js";import{n,t as r}from"./jsx-runtime-CEpd2cAX.js";import{t as i}from"./api-CmrgM5Rf.js";import{t as a}from"./preload-helper-Czpn1I53.js";import{t as o}from"./styles-CqO-rmOt.js";import{Ct as s,O as c,d as l,q as u,s as d,u as f}from"./index-DivKnJyx.js";import"./storage-Cmhlwx70.js";import{a as p,c as m,n as h,o as g,s as _,t as v}from"./SquisqIntegration-BTZ1kBlg.js";import{c as y,d as b,f as x,h as S,i as C,m as w,p as T,s as E}from"./file-browser-BLOPfnS0.js";import{a as D,c as O,d as k,f as A,l as j,n as M,r as N,s as P,t as F,u as I}from"./outside-in-Msmhxf_U.js";import{t as L}from"./markdown-baseline-0dqv9qbV.js";import{t as R}from"./TransformToolbarButton-8wfJR1bO.js";var z=e(n(),1),B=r();function V(e){let t=e.lastIndexOf(`/`);return t<0?e:e.slice(t+1)}async function H(e,t){let n=F(t,(await i.listDocuments(``,!0)).files.filter(e=>!e.isDirectory).map(e=>e.path)),r;if(n)r=(await i.readDocument(n)).content;else{let a=await M(await(await i.fetchDocumentBlob(e)).arrayBuffer(),t),o=_({root:t.companionDirectory,client:i,primaryDocumentFilename:t.markdownFilename});for(let t of await a.container.listFiles()){if(/\.md$/i.test(t.path)||!t.path.includes(`/`)&&V(t.path).toLocaleLowerCase(`en-US`)===V(e).toLocaleLowerCase(`en-US`))continue;let n=await a.container.readFile(t.path);n&&await o.writeFile(t.path,n,t.mimeType)}r=A(a.markdown,t),await o.writeDocument(r,t.markdownFilename),n=t.markdownPath}let a=A(r,t);return a!==r&&(await i.writeDocument(n,a),r=a),{sourcePath:n,content:r,editingEnabled:I(t.format)&&N(r)}}function U({path:e,layout:t}){let[n,r]=(0,z.useState)(null),[a,o]=(0,z.useState)(null),[s,c]=(0,z.useState)(null),[l,u]=(0,z.useState)(!1);(0,z.useEffect)(()=>{let n=!1;return r(null),o(null),c(null),H(e,t).then(e=>{n||r(e)}).catch(e=>{n||o(e instanceof Error?e.message:String(e))}),()=>{n=!0}},[t,e]);let d=(0,z.useCallback)(async()=>{if(!(!n||l)){if(!I(t.format)){c(`CSV data previews are read-only.`);return}u(!0),c(null);try{if(!(await i.listDocuments(``,!0)).files.some(e=>e.path===t.backupPath)){let e=await i.fetchDocumentBlob(t.targetPath);await i.writeDocumentBinary(t.backupPath,e,e.type||`application/octet-stream`)}let e=k(n.content,t);await i.writeDocument(n.sourcePath,e),r({...n,content:e,editingEnabled:!0})}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[l,t,n]);return a?(0,B.jsx)(`div`,{className:`placeholder`,children:(0,B.jsxs)(`p`,{children:[`Couldn't open `,(0,B.jsx)(`code`,{children:e}),`: `,a]})}):n?(0,B.jsx)(W,{path:e,layout:t,prepared:n,enabling:l,enableError:s,onEnableEditing:d},`${n.sourcePath}:${n.editingEnabled?`editable`:`readonly`}`):(0,B.jsxs)(`p`,{className:`placeholder`,children:[`Importing `,e,` for viewing…`]})}function W({path:e,layout:t,prepared:n,enabling:r,enableError:f,onEnableEditing:g}){let y=s(),x=v(),C=(0,z.useMemo)(()=>_({root:t.companionDirectory,client:i,primaryDocumentFilename:V(n.sourcePath)}),[t.companionDirectory,n.sourcePath]),E=(0,z.useMemo)(()=>S(C),[C]),O=(0,z.useMemo)(()=>w({client:i,currentDocumentPath:n.sourcePath}),[n.sourcePath]),k=(0,z.useMemo)(()=>l(n.sourcePath),[n.sourcePath]),M=(0,z.useMemo)(()=>p(E,k),[E,k]),N=(0,z.useMemo)(()=>u(E),[E]),F=(0,z.useCallback)(async r=>{let o=A(r,t),s=await i.listDocuments(``,!0),c=t.format===`html`?j(t.targetPath,new Set(s.files.filter(e=>e.isDirectory).map(e=>e.path.replace(/^\/+/,``)))):void 0,l=await P(o,t,E,c?D(t.parentDirectory,c):void 0);if(await i.writeDocument(n.sourcePath,o),c){let{PLAYER_BUNDLE:e}=await a(async()=>{let{PLAYER_BUNDLE:e}=await import(`./standalone-source-Cw9SF7Zk.js`);return{PLAYER_BUNDLE:e}},[]);await i.writeDocument(c,e)}await i.writeDocumentBinary(t.targetPath,l.bytes,l.mimeType),d(e)},[E,t,e,n.sourcePath]),H=(0,z.useMemo)(()=>L(n.content),[n.content]),U=c({resourceKey:`outside-in:documents:${n.sourcePath}`,initialValue:H,save:F});(0,z.useEffect)(()=>()=>N.dispose(),[N]);let W=(0,z.useCallback)(e=>{U.update(e)},[U.update]);return(0,B.jsxs)(`section`,{className:`document-detail`,"data-testid":`document-detail`,children:[!n.editingEnabled&&(0,B.jsxs)(`output`,{className:`outside-in-readonly-banner`,children:[I(t.format)?(0,B.jsxs)(`span`,{children:[(0,B.jsxs)(`strong`,{children:[t.format.toUpperCase(),` preview · read-only.`]}),` If you enable editing via markdown, the structure of your `,t.format.toUpperCase(),` will not be fully preserved.`]}):(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:`CSV data preview · source preserved.`}),` Large datasets stay in a sidecar and open as a virtualized grid.`]}),f&&(0,B.jsxs)(`span`,{className:`error`,children:[`Could not enable editing: `,f]}),I(t.format)&&(0,B.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>void g(),children:r?`Preparing…`:`Enable editing`})]}),(0,B.jsx)(`div`,{className:`editor-wrap`,children:(0,B.jsx)(o,{initialMarkdown:U.desiredValue(),fileName:n.sourcePath,initialView:`wysiwyg`,readOnly:!n.editingEnabled,onChange:n.editingEnabled?W:void 0,height:`100%`,colorScheme:y,fullWidth:!0,workspaceContainer:M,mediaProvider:N,documentLinkProvider:O,calcEngineFactory:n.editingEnabled?T:void 0,proofing:x,proofingIgnoreStore:h,allowVersioning:n.editingEnabled,versionBasename:k,toolbarSlotAfterActions:(0,B.jsxs)(B.Fragment,{children:[n.editingEnabled&&(0,B.jsx)(R,{context:`generic`}),(0,B.jsx)(b,{fileName:e})]}),statusBarSlotRight:n.editingEnabled?(0,B.jsx)(m,{autosave:U}):void 0})})]})}var G=t({DocumentDetail:()=>q});function K(e){let t=e.slice(e.lastIndexOf(`/`)+1);return!t.includes(`.`)||/\.(md|markdown|mdx)$/i.test(t)}function q({path:e}){let t=(0,z.useMemo)(()=>O(e),[e]);return t?(0,B.jsx)(U,{path:e,layout:t}):(0,B.jsx)(Y,{path:e})}var J=e=>i.fetchDocumentBlob(e);function Y({path:e}){let t=s(),n=v(),[r,a]=(0,z.useState)(null),[u,S]=(0,z.useState)(void 0),[D,O]=(0,z.useState)(null),k=(0,z.useCallback)(async t=>{await i.writeDocument(e,t),d(e)},[e]),A=c({resourceKey:`document:${e}`,initialValue:r??``,save:k}),{root:j,parentDirectory:M,companionName:N,primaryDocumentFilename:P}=(0,z.useMemo)(()=>f(e),[e]),F=(0,z.useMemo)(()=>_({root:j,client:i,referencePrefix:N}),[N,j]),I=(0,z.useMemo)(()=>_({root:M,client:i,primaryDocumentFilename:P}),[M,P]),V=(0,z.useMemo)(()=>g(F,N,I),[N,F,I]),H=(0,z.useMemo)(()=>l(e),[e]),U=(0,z.useMemo)(()=>p(F,H,[{container:I,basenames:[P,H]}],I),[F,I,P,H]),W=(0,z.useMemo)(()=>w({client:i,currentDocumentPath:e}),[e]);(0,z.useEffect)(()=>()=>V.dispose(),[V]),(0,z.useEffect)(()=>{let t=!1;return a(null),S(void 0),O(null),(async()=>{try{let n=await i.readDocument(e);if(t)return;S(n.size);let r=K(e)?L(n.content):n.content;a(A.hydrate(r))}catch(e){t||O(e.message)}})(),()=>{t=!0}},[e,A.hydrate]);let G=(0,z.useCallback)(e=>{A.update(e)},[A.update]);if(D)return(0,B.jsx)(`div`,{className:`placeholder`,children:(0,B.jsxs)(`p`,{children:[`Couldn't open `,(0,B.jsx)(`code`,{children:e}),`: `,D]})});if(r===null)return(0,B.jsxs)(`p`,{className:`placeholder`,children:[`Loading `,e,`…`]});if(y(r))return(0,B.jsx)(E,{content:C,path:e,fetchBlob:J,...u===void 0?{}:{sizeBytes:u}});let q=K(e);return(0,B.jsx)(`section`,{className:`document-detail`,"data-testid":`document-detail`,children:(0,B.jsx)(`div`,{className:`editor-wrap`,children:(0,B.jsx)(o,{initialMarkdown:r,fileName:e,onChange:G,height:`100%`,colorScheme:t,fullWidth:!0,workspaceContainer:q?U:null,mediaProvider:q?V:null,documentLinkProvider:q?W:null,calcEngineFactory:q?T:void 0,proofing:q?n:null,proofingIgnoreStore:h,allowVersioning:q,versionBasename:H,toolbarSlotAfterActions:q?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(R,{context:`generic`}),(0,B.jsx)(b,{fileName:e})]}):void 0,toolbarSlotRight:q?(0,B.jsx)(x,{selectedFile:e,mediaContainer:I,mediaSource:{kind:`documents`}}):void 0,statusBarSlotRight:(0,B.jsx)(m,{autosave:A})})})})}export{G as n,q as t};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{St as r,yt as i}from"./dist-CE5CbmDb.js";import{t as a}from"./api-CmrgM5Rf.js";import{a as o,o as s,s as c,u as l}from"./NewPathDialog-BhAZm9dp.js";import"./schemas-BvLZUsGm.js";import{A as u,Ct as d,c as ee,k as f,l as p}from"./index-DivKnJyx.js";import"./SquisqIntegration-BTZ1kBlg.js";import{l as te,n as m,s as h,t as g,u as _}from"./file-browser-BLOPfnS0.js";import{t as v}from"./ProjectGitStatusBar-BORGYx5l.js";import{t as y}from"./DocumentDetail-SYozruTJ.js";var b=n(),x=e(t(),1);function S({name:e,entries:t,onOpenFile:n,onOpenFolder:r,onNewDocument:i,onNewFolder:a,theme:o=`light`,height:s=`100%`,iconFor:c=w}){let l=[...t].sort((e,t)=>e.isDirectory===t.isDirectory?e.name.localeCompare(t.name,void 0,{sensitivity:`base`}):e.isDirectory?-1:1);return(0,b.jsxs)(`div`,{className:`squisq-folder-view`,"data-theme":o,style:{height:s},children:[(0,b.jsxs)(`div`,{className:`squisq-folder-view-header`,children:[(0,b.jsx)(`i`,{className:`fa-regular fa-folder-open squisq-folder-view-header-icon`,"aria-hidden":`true`}),(0,b.jsx)(`span`,{className:`squisq-folder-view-title`,children:e}),(0,b.jsxs)(`span`,{className:`squisq-folder-view-count`,children:[t.length,` `,t.length===1?`item`:`items`]})]}),(0,b.jsx)(`div`,{className:`squisq-folder-view-body`,children:l.length===0?(0,b.jsx)(`p`,{className:`squisq-folder-view-empty`,children:`This folder is empty.`}):(0,b.jsx)(`ul`,{className:`squisq-folder-view-list`,children:l.map(e=>(0,b.jsx)(`li`,{children:(0,b.jsxs)(`button`,{type:`button`,className:`squisq-folder-view-item`,onClick:()=>e.isDirectory?r(e):n(e),children:[(0,b.jsx)(`span`,{className:`squisq-folder-view-item-icon`,children:c(e)}),(0,b.jsx)(`span`,{className:`squisq-folder-view-item-name`,children:e.name}),e.isDirectory&&(0,b.jsx)(`i`,{className:`fa-solid fa-chevron-right squisq-folder-view-item-chevron`,"aria-hidden":`true`})]})},e.path))})}),(0,b.jsxs)(`div`,{className:`squisq-folder-view-actions`,children:[(0,b.jsxs)(`button`,{type:`button`,className:`squisq-folder-view-new`,onClick:i,children:[(0,b.jsx)(`i`,{className:`fa-solid fa-plus`,"aria-hidden":`true`}),` New document`]}),a&&(0,b.jsxs)(`button`,{type:`button`,className:`squisq-folder-view-new-folder`,onClick:a,children:[(0,b.jsx)(`i`,{className:`fa-regular fa-folder`,"aria-hidden":`true`}),` New folder`]})]})]})}var C=/\.(png|jpe?g|gif|svg|webp|bmp|avif)$/i;function w(e){return e.isDirectory?(0,b.jsx)(`i`,{className:`fa-regular fa-folder fa-fw`,"aria-hidden":`true`}):C.test(e.name)?(0,b.jsx)(`i`,{className:`fa-regular fa-file-image fa-fw`,"aria-hidden":`true`}):(0,b.jsx)(`i`,{className:`fa-regular fa-file-lines fa-fw`,"aria-hidden":`true`})}var T=2,E=200;function ne(){let[e,t]=(0,x.useState)(``),[n,r]=(0,x.useState)(null),[i,o]=(0,x.useState)(``),[s,c]=(0,x.useState)(!1),[l,u]=(0,x.useState)(!1);return(0,x.useEffect)(()=>{let t=e.trim();if(t.length<T){r(null),o(``),c(!1),u(!1);return}let n=!1;c(!0);let i=window.setTimeout(()=>{a.searchDocuments({q:t}).then(e=>{n||(u(e.engine===`unavailable`),o(t),r(e.results.map(e=>({entry:{name:e.path.split(`/`).pop()??e.path,path:e.path,isDirectory:!1},snippet:e.snippet,line:e.lineStart,related:e.source===`vector`}))))}).catch(()=>{n||(o(t),r([]))}).finally(()=>{n||c(!1)})},E);return()=>{n=!0,window.clearTimeout(i)}},[e]),{query:e,setQuery:t,hits:n,matchedQuery:i,searching:s,unavailable:l,clear:()=>t(``)}}var D=`gezel:documents:selectedPath`;function re(){try{return window.localStorage.getItem(D)}catch{return null}}function O(e){try{e?window.localStorage.setItem(D,e):window.localStorage.removeItem(D)}catch{}}function k(e){try{return window.localStorage.getItem(e)}catch{return null}}function A(e,t){try{window.localStorage.setItem(e,t)}catch{}}function j(){let e=d(),t=(0,x.useMemo)(()=>m(),[]),n=ne(),[C,w]=(0,x.useState)([]),[T,E]=(0,x.useState)(!1),[D,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(null),[P,F]=(0,x.useState)(()=>l(k(s),`documents`)),[I,L]=(0,x.useState)(()=>k(o)===`1`),R=ee(),[z,B]=(0,x.useState)(()=>re()),[V,H]=(0,x.useState)(null);(0,x.useEffect)(()=>{let e=!1;return a.listProjects().then(t=>{if(e)return;let n=t.projects.find(e=>r(e));H(n?.id??null)}).catch(()=>{}),()=>{e=!0}},[]);let U=(0,x.useCallback)(e=>{B(e),O(e),e&&R.noteUsed(e)},[R.noteUsed]),W=(0,x.useCallback)(e=>{F(e),A(s,e)},[]),G=(0,x.useCallback)(e=>{L(e),A(o,e?`1`:`0`)},[]),K=(0,x.useCallback)(async()=>{try{let e=await t.list({hidden:I});w(e.files),E(e.truncated===!0),j(!0)}catch(e){N(e.message)}},[I,t]);(0,x.useEffect)(()=>{K()},[K]);let q=(0,x.useMemo)(()=>I?C:C.filter(e=>!i(e.path)),[C,I]),J=g({source:t,entries:C,selectedPath:z,onSelectPath:U,refresh:K}),Y=(0,x.useCallback)(e=>{if(e.isDirectory)return[];let t=R.pinnedPaths.has(e.path);return[{label:t?`Unpin from Documents list`:`Pin to Documents list`,onSelect:()=>t?R.unpin(e.path):R.pin(e.path)}]},[R.pin,R.pinnedPaths,R.unpin]);(0,x.useEffect)(()=>{if(q.length===0)return;let e=q.find(e=>!e.isDirectory)??q[0];e&&B(t=>t&&q.some(e=>e.path===t)?t:e.path)},[q]);let X=(0,x.useMemo)(()=>z?q.find(e=>e.path===z)??null:null,[q,z]),Z=X?.isDirectory??!1,ie=z?z.slice(z.lastIndexOf(`/`)+1):``,ae=(0,x.useMemo)(()=>{if(!z||!Z)return[];let e=`${z}/`;return q.filter(t=>t.path.startsWith(e)&&!t.path.slice(e.length).includes(`/`))},[q,z,Z]),Q=z&&!Z?te(z):null,$;$=z?Z?(0,b.jsx)(S,{name:ie,entries:ae,theme:e,onOpenFile:e=>U(e.path),onOpenFolder:e=>U(e.path),onNewDocument:()=>J.newFile?.(z),onNewFolder:()=>J.newFolder?.(`${z}/`)}):Q?(0,b.jsx)(h,{content:Q,path:z,fetchBlob:t.fetchBlob}):X?(0,b.jsx)(y,{path:z},z):D?(0,b.jsx)(`p`,{className:`placeholder`,children:`Select a document or folder on the left to view it.`}):(0,b.jsx)(`p`,{className:`placeholder`,children:`Loading…`}):(0,b.jsx)(`p`,{className:`placeholder`,children:`Select a document or folder on the left to view it.`});let oe=n.hits?{entries:n.hits.map(e=>e.entry),emptyMessage:n.unavailable?`The library is still being indexed — search will work shortly.`:`Nothing in the library mentions “${n.query.trim()}”.`,detailForEntry:e=>{let t=n.hits?.find(t=>t.entry.path===e.path);return t?(0,b.jsxs)(`span`,{className:`documents-search-snippet`,children:[t.related&&(0,b.jsx)(`span`,{className:`documents-search-related`,children:`related`}),(0,b.jsx)(f,{markdown:t.snippet,query:n.matchedQuery,formatMarkdown:u(`content`,e.path)})]}):null}}:null;return(0,b.jsxs)(`div`,{className:`documents-listing`,"data-testid":`documents-view`,children:[(0,b.jsx)(_,{source:t,titleReplacement:(0,b.jsxs)(`div`,{className:`documents-search`,children:[(0,b.jsx)(`input`,{type:`search`,className:`documents-search-input`,placeholder:`${t.title} - search`,"aria-label":`Search document contents`,value:n.query,onChange:e=>n.setQuery(e.target.value),onKeyDown:e=>{e.key===`Escape`&&n.clear()}}),n.searching&&(0,b.jsx)(`span`,{className:`muted documents-search-status`,children:`searching…`})]}),customList:oe,layoutClassName:`project-files-layout-documents`,entries:q,truncated:T,viewMode:P,modes:c,onViewModeChange:W,showHidden:I,onShowHiddenChange:G,selectedPath:z??void 0,onSelect:e=>U(e.path),selectableFolders:!0,labelFor:e=>p(e.name),trailingForEntry:e=>R.pinnedPaths.has(e.path)?(0,b.jsx)(`span`,{className:`document-pin-marker`,title:`Pinned`,"aria-label":`Pinned`,children:(0,b.jsx)(`i`,{className:`fa-solid fa-thumbtack`})}):null,actionsForEntry:Y,emptyMessage:`No documents yet. Create a mission statement, coding guidelines, or any shared reference.`,mutations:J,viewer:$}),M&&(0,b.jsx)(`p`,{className:`error`,children:M}),V?(0,b.jsx)(v,{projectId:V}):null]})}export{j as DocumentsView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{bt as r,f as i}from"./dist-DOqbRmFj.js";import{t as a}from"./api-C0I7spBl.js";import{t as o}from"./model-context-DBqdK0PS.js";import{n as s,r as c,t as l}from"./model-memory-copy-Ds9w1uJE.js";import{t as u}from"./ConfirmDialog-Dt1ed4Fh.js";import{a as d,r as f,t as p}from"./model-inventory-ykSm_IT5.js";import{wt as m}from"./index-DDu8nyO6.js";import{t as h}from"./IncompleteDownloads-C36lTCMG.js";import{a as ee,i as te,n as g,o as ne,r as re,t as _}from"./UnrecognizedModels-0hptopv6.js";import{t as v}from"./useTotalRamBytes-B8NFM27w.js";import{t as y}from"./ds4-availability-TaGRbP_O.js";import{t as ie}from"./local-engine-label-BR-PGVFE.js";var b=e(t(),1),x=n();function S(e){return e.kind!==`chat-model`||!e.ds4?null:e}function C({onModelsChanged:e}){let[t,n]=(0,b.useState)(null),[v,y]=(0,b.useState)(new Set),[ie,C]=(0,b.useState)(new Map),[w,T]=(0,b.useState)(new Set),[E,D]=(0,b.useState)(new Map),[O,k]=(0,b.useState)(null),[A,j]=(0,b.useState)(!1),[M,ae]=(0,b.useState)(null),[oe,N]=(0,b.useState)(null),[se,P]=(0,b.useState)(!1),[F,I]=(0,b.useState)(new Map),[L,R]=(0,b.useState)(null),[z,B]=(0,b.useState)([]),[V,H]=(0,b.useState)([]),[U,W]=(0,b.useState)(null),[G,ce]=(0,b.useState)(new Map),[K,le]=(0,b.useState)([]),q=(0,b.useRef)([]),J=(0,b.useCallback)(async()=>{try{let e=await a.listModelFitness();ce(new Map(e.records.map(e=>[e.key,e]))),le(e.probing),q.current=e.probing}catch{}},[]),Y=(0,b.useCallback)(async()=>{try{let e=await a.listIncompleteDs4Models();B(e.incomplete??[])}catch{}},[]),X=(0,b.useCallback)(async()=>{try{let e=await a.listDs4Models();y(new Set(e.models.map(e=>e.id))),C(new Map(e.models.map(e=>[e.id,e]))),T(new Set(e.models.filter(e=>e.readOnly).map(e=>e.id))),H(e.unrecognized??[])}catch{}try{let e=await a.listDs4ContextPlans();D(new Map(Object.entries(e.plans??{})))}catch{}Y()},[Y]),ue=(0,b.useCallback)(async(e,t)=>{N(e);try{let n=await a.getConfig();await a.updateConfig({nativeVision:{...n.nativeVision??{},[e]:t}}),await X()}catch{}finally{N(null)}},[X]),Z=(0,b.useCallback)(async()=>{R(null);try{let[e,t]=await Promise.all([a.listCatalogItems(`chat-model`),a.getMemoryProfile()]);n(e.items),k({totalRamBytes:t.totalRamBytes,usableBytes:t.usableBytes})}catch(e){R(e instanceof Error?e.message:String(e))}},[]);(0,b.useEffect)(()=>{Z(),X(),a.getModelContextOverrides(`ds4`).then(()=>P(!0)).catch(()=>P(!1))},[Z,X]),(0,b.useEffect)(()=>{let e=e=>{d(e)===`ds4`&&X()};return window.addEventListener(p,e),()=>window.removeEventListener(p,e)},[X]),(0,b.useEffect)(()=>{let e=!1,t,n=async()=>{await J(),!e&&(t=setTimeout(()=>void n(),q.current.length>0?2e3:15e3))};return n(),()=>{e=!0,t&&clearTimeout(t)}},[J]),(0,b.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await a.listDs4ActiveInstalls();if(e)return;I(e=>{let n=new Map(e),r=new Set;for(let e of t.installs){r.add(e.catalogId);let t=n.get(e.catalogId);t?.origin===`local`&&!t.error||n.set(e.catalogId,{bytesWritten:e.bytesWritten,totalBytes:e.totalBytes,phase:e.phase===`extracting-metadata`?`finalizing`:e.phase,origin:`remote`})}for(let[e,t]of n)t.origin===`remote`&&!r.has(e)&&n.delete(e);return n}),t.installs.length===0&&X()}catch{}};t();let n=setInterval(()=>void t(),2e3);return()=>{e=!0,clearInterval(n)}},[X]);let Q=(0,b.useCallback)(t=>{I(e=>new Map(e).set(t,{bytesWritten:0,totalBytes:0,phase:`downloading`,origin:`local`})),(async()=>{try{await a.installDs4Model(t,e=>{I(n=>{let r=new Map(n),i=r.get(t)??{bytesWritten:0,totalBytes:0,phase:`downloading`,origin:`local`};return e.type===`progress`?r.set(t,{...i,bytesWritten:e.bytesWritten,totalBytes:e.totalBytes,phase:`downloading`}):e.type===`verifying`?r.set(t,{...i,phase:`verifying`}):e.type===`extracting-metadata`?r.set(t,{...i,phase:`finalizing`}):e.type===`error`&&r.set(t,{...i,error:e.error}),r})}),f(`ds4`)}catch(e){I(n=>{let r=new Map(n),i=r.get(t);return i&&r.set(t,{...i,error:e instanceof Error?e.message:String(e)}),r});return}finally{I(e=>{let n=new Map(e);return n.get(t)?.error||n.delete(t),n}),await X(),e?.()}})()},[X,e]),de=(0,b.useCallback)(async t=>{R(null),y(e=>{let n=new Set(e);return n.delete(t),n}),B(e=>e.filter(e=>e.id!==t)),H(e=>e.filter(e=>e.id!==t));try{await a.deleteDs4Model(t),f(`ds4`),await X(),e?.()}catch(e){R(`delete failed: ${e instanceof Error?e.message:String(e)}`),X()}},[X,e]),fe=(0,b.useMemo)(()=>(t??[]).map(e=>({it:e,m:S(e.manifest)})).filter(e=>e.m!==null),[t]);if(L)return(0,x.jsxs)(`div`,{className:`new-row`,style:{alignItems:`center`,gap:`0.6rem`},children:[(0,x.jsxs)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:[`Couldn't load models: `,L]}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>void Z(),children:`Retry`})]});if(t===null)return(0,x.jsx)(`p`,{className:`muted small`,children:`Loading models…`});if(fe.length===0)return(0,x.jsx)(`p`,{className:`muted small`,children:`No DwarfStar models in the catalog.`});let pe=new Set(V.map(e=>e.id)),me=fe.filter(({m:e})=>!pe.has(e.id)||F.has(e.id)).filter(({m:e})=>A||v.has(e.id)||!r(e)).map((e,t)=>({entry:e,index:t})).sort((e,t)=>{let n=Number(v.has(t.entry.m.id))-Number(v.has(e.entry.m.id));return n===0?e.index-t.index:n}).map(({entry:e})=>e),$=e=>E.get(e.id)?.projectedResidentBytes??e.ds4.residentBytes,he=Math.min(...me.map(({m:e})=>$(e)??1/0));return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(g,{engine:`ds4`,onModelsChanged:e}),(0,x.jsx)(_,{items:V.filter(e=>!F.has(e.id)),onUpdate:Q,onRemove:W}),(0,x.jsx)(h,{items:z.filter(e=>!F.has(e.id)),onResume:e=>Q(e),onDelete:W}),(0,x.jsxs)(`div`,{className:`ollama-section`,children:[(0,x.jsxs)(`p`,{className:`muted small`,style:{marginTop:0},children:[`Retired models are hidden by default.`,` `,(0,x.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>j(e=>!e),children:A?`Hide retired models`:`Show all models`})]}),(0,x.jsx)(`div`,{className:`ollama-model-table-wrap`,children:(0,x.jsxs)(`table`,{className:`ollama-model-table ds4-model-table`,children:[(0,x.jsxs)(`colgroup`,{children:[(0,x.jsx)(`col`,{className:`model-name-column`}),(0,x.jsx)(`col`,{}),(0,x.jsx)(`col`,{}),(0,x.jsx)(`col`,{}),(0,x.jsx)(`col`,{})]}),(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{children:`Name`}),(0,x.jsx)(`th`,{title:`Download size, and the memory working set this device would run the model at. A streaming engine keeps far less resident than it downloads.`,children:`Size`}),(0,x.jsx)(`th`,{title:`Effective per-turn context size after Gezel's settings and memory limits`,children:`Context size`}),(0,x.jsx)(`th`,{title:`Reading and writing speed, measured against an approximately 20K-token prompt`,children:`Fitness`}),(0,x.jsx)(`th`,{})]})}),(0,x.jsx)(`tbody`,{children:me.map(({m:e})=>{let t=E.get(e.id),n=$(e),u=e.ds4.cacheExpertsBytes??0,d=O?Math.max(0,O.totalRamBytes-i):0,f=O&&n?n<=d:!0,p=n?Math.max(0,n-u):0,m=!O||p+1024**3<=d,h=n===he,g=v.has(e.id),_=r(e),y=F.get(e.id),S=y&&y.totalBytes>0?Math.floor(y.bytesWritten/y.totalBytes*100):0,C=t?.fullyResident===!0,T=C?(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--ok ds4-model-fit`,title:`This device holds the whole model in memory — no expert streaming from SSD. That is roughly ten times faster to generate than the streaming fallback${n?`, and costs about ${c(e.ds4.approxSizeBytes)} of memory while loaded`:``}.`,children:`runs fully in memory · fastest`}):n?f?(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--info ds4-model-fit`,title:`Too large to hold in memory on this device, so DwarfStar keeps about ${c(n)} resident and reads the remaining experts from SSD as it goes. That works, but generates roughly ten times slower than a model that fits in memory. A smaller quant that fits will be much faster.`,children:h?`streams from SSD · lightest option`:`streams from SSD · slower`}):m?(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn ds4-model-fit`,title:`Gezel will reduce this model's expert cache below its ${c(n)} target to preserve ${c(i)} for the system and other apps. It should run, but will read from SSD even more often than a normal streaming launch.`,children:`reduced cache · much slower`}):(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn ds4-model-fit`,title:`The model's fixed memory requirement leaves too little room for the system, even with the expert cache reduced.`,children:`needs more memory`}):null,D=e.name,k=ie.get(e.id),A=k?{...k,...t?.effectiveContextWindow!==void 0&&!k.effectiveContextWindow?{effectiveContextWindow:t.effectiveContextWindow}:{},...t?.contextCeilingTokens!==void 0&&k.contextCeilingTokens===void 0?{contextCeilingTokens:t.contextCeilingTokens}:{},...t?.kvBytesPerToken!==void 0&&k.kvBytesPerTokenPerSlot===void 0?{kvBytesPerTokenPerSlot:t.kvBytesPerToken,kvFixedBytesPerSlot:0}:{},...t?.contextFreeResidentBytes!==void 0&&k.weightsResidentBytes===void 0?{weightsResidentBytes:t.contextFreeResidentBytes}:{}}:void 0,j=A?.effectiveContextWindow??t?.effectiveContextWindow,N=A?.overrideContextTokens??t?.overrideContextTokens,P=A?.contextSizingStatus===`restart-required`,I={approxSizeBytes:e.ds4.approxSizeBytes,residentBytes:n,...t?.kvBytesPerToken!==void 0&&t.contextFreeResidentBytes!==void 0&&j!==void 0?{contextFreeBytes:t.contextFreeResidentBytes}:{},...j===void 0?{}:{effectiveContextWindow:j},...C?{fullyResident:!0}:{}},L=l(I),R=A?.updateAvailable===!0,z=`ds4:${e.id}`;return(0,x.jsxs)(b.Fragment,{children:[(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`td`,{className:`model-name-table-cell`,children:(0,x.jsxs)(`div`,{className:`model-name-cell`,children:[(0,x.jsx)(`strong`,{className:`ds4-model-name`,children:D}),(0,x.jsxs)(`div`,{className:`model-name-meta`,children:[(0,x.jsx)(`span`,{className:`muted small`,children:e.parameterSize}),g&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--ok`,children:`on device`}),_&&(0,x.jsx)(`span`,{className:`catalog-item-tag catalog-item-tag--retired`,title:`This model is kept for compatibility but is no longer recommended for new downloads.`,children:`retired`}),R&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:A?.updateReason??(A?.availableVersion?`A newer build is available in the catalog (→ v${A.availableVersion}). Updating downloads only the files that differ.`:`A newer build is available in the catalog. Updating downloads only the files that differ.`),children:`update available`})]}),T]})}),(0,x.jsx)(`td`,{children:(0,x.jsxs)(`span`,{className:`model-size-cell`,title:`${s(I)}${e.ds4.visionEncoder?` The ${c(e.ds4.visionEncoder.sizeBytes,2)} vision encoder is installed separately, loaded by default, and can be turned off under Advanced to save runtime memory.`:``}`,children:[c(e.ds4.approxSizeBytes),e.ds4.visionEncoder?(0,x.jsxs)(`span`,{className:`muted small model-memory-headline`,children:[`+`,c(e.ds4.visionEncoder.sizeBytes,2),` vision encoder`]}):null,L?(0,x.jsx)(`span`,{className:`muted small model-memory-headline`,children:L}):null]})}),(0,x.jsx)(`td`,{title:P?`This model is running with a different context window than the current sizing settings resolve to. Restart the local engine (or let it go idle) so Gezel can re-admit it — no memory change needed.`:j===void 0?void 0:N===void 0?`Gezel will grant up to ${j.toLocaleString()} tokens per turn.`:`You've set this model to ${N.toLocaleString()} tokens per turn.`,children:P?`Restart needed`:j===void 0?(0,x.jsx)(`span`,{className:`muted`,children:`—`}):(0,x.jsxs)(x.Fragment,{children:[o(j),N!==void 0&&(0,x.jsx)(`span`,{className:`gz-budget-tag gz-budget-tag-custom model-context-custom-tag`,children:`custom`})]})}),g?(0,x.jsx)(re,{entry:G.get(z),probing:K.includes(z)}):(0,x.jsx)(`td`,{className:`model-fitness-table-cell`,children:(0,x.jsx)(`span`,{className:`muted small`,title:`The fitness check measures this model on THIS machine, so it runs once the download lands.`,children:`after download`})}),(0,x.jsx)(`td`,{className:`model-actions-table-cell`,children:y?y.error?(0,x.jsxs)(`div`,{className:`ds4-model-progress`,children:[(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:y.error}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>Q(e.id),children:`Retry`})]}):(0,x.jsx)(`span`,{className:`muted small ds4-model-progress-label`,children:y.phase===`downloading`?`downloading… ${S}%`:y.phase===`verifying`?`verifying sha256…`:`finalizing…`}):g?(0,x.jsxs)(`div`,{className:`model-actions-cell`,children:[(0,x.jsx)(`div`,{className:`model-action-status`,children:w.has(e.id)&&(0,x.jsx)(`span`,{className:`muted small`,title:`Provided by the machine-wide install (shared asset store). It can't be removed from here — manage it with the machine installer, or install a user-owned copy to shadow it.`,children:`Machine model`})}),(0,x.jsx)(`div`,{className:`model-action-links`,children:(0,x.jsx)(ee,{engine:`ds4`,model:A??{id:e.id,approxSizeBytes:e.ds4.approxSizeBytes,readOnly:w.has(e.id)},contextSupported:se,contextEditorOpen:M===e.id,onToggleContextEditor:()=>ae(t=>t===e.id?null:e.id),...A?.nativeVisionEnabled===void 0?{}:{visionAction:{enabled:A.nativeVisionEnabled,busy:oe===e.id,sidecarSizeBytes:A.visionEncoderSizeBytes??e.ds4.visionEncoder?.sizeBytes,onToggle:()=>void ue(e.id,!A.nativeVisionEnabled)}},fitnessAction:te(G.get(z),K.includes(z),()=>{a.runModelFitnessProbe(`ds4`,e.id).then(()=>J()).catch(()=>{})}),onUpdate:()=>Q(e.id),onDelete:w.has(e.id)?void 0:()=>W(e.id)})})]}):m?(0,x.jsx)(`button`,{type:`button`,onClick:()=>Q(e.id),children:`Download`}):null})]}),M===e.id&&A&&(0,x.jsx)(`tr`,{className:`model-context-editor-row`,children:(0,x.jsx)(`td`,{colSpan:5,children:(0,x.jsx)(ne,{engine:`ds4`,model:A,onSaved:X})})})]},e.id)})})]})})]}),(0,x.jsxs)(`div`,{style:{marginTop:`1.25rem`},children:[(0,x.jsx)(m,{}),(0,x.jsx)(`span`,{className:`muted small`,style:{marginLeft:`0.75rem`},children:`Import from a gezel local model package`})]}),(0,x.jsx)(u,{open:U!==null,title:`Remove ${U??`model`}?`,message:`This permanently removes the model files from this device. The model stays available in the catalog, so you can download a current build later.`,confirmLabel:`Remove`,danger:!0,onConfirm:()=>{let e=U;W(null),e&&de(e)},onCancel:()=>W(null)})]})}function w({config:e,onConfigChanged:t,health:n,title:r}){let i=v(),[o,s]=(0,b.useState)([]),[c,l]=(0,b.useState)(`idle`),u=(0,b.useCallback)(async()=>{try{let e=await a.listDs4Models();s(e.models)}catch{}},[]);(0,b.useEffect)(()=>{u()},[u]);let d=(0,b.useCallback)(async n=>{l(`saving`);try{t(await a.updateConfig({defaultModel:{...e?.defaultModel,ds4:n??void 0}})),l(`saved`),setTimeout(()=>l(`idle`),1200)}catch{l(`idle`)}},[e?.defaultModel,t]),f=(0,b.useCallback)(async e=>{l(`saving`);try{t(await a.updateConfig({ds4SsdStreaming:e?!0:void 0})),l(`saved`),setTimeout(()=>l(`idle`),1200)}catch{l(`idle`)}},[t]),p=e?.ds4SsdStreaming===!0,m=y({externalBaseUrl:e?.ds4BaseUrl,totalRamBytes:i??void 0,ds4ServerBundled:n?.ds4ServerBundled,serverPlatform:n?.platform,detectedBackend:n?.llamaCppDetectedBackend,gpuVendor:n?.llamaCppDetectedVendor});return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h3`,{children:r??ie(`ds4`,n?.platform)}),(0,x.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:`DwarfStar (ds4) is an inference engine built for a handful of very large mixture-of-experts models — DeepSeek V4 and GLM 5.2/5.3. They may not fit in memory; DwarfStar keeps a bounded expert cache in RAM and reads the other experts from SSD as they are needed.`}),(0,x.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`,alignItems:`center`},children:[(0,x.jsx)(`span`,{className:`muted small`,children:`Status:`}),m.status===`available`&&(0,x.jsxs)(`span`,{className:`gz-status-pill gz-status-pill--ok`,children:[`engine available · `,m.backend]}),m.status===`external`&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:`Using an external ds4-server at: ${e?.ds4BaseUrl}`,children:`using external DwarfStar server`}),m.status===`requires-cuda`&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:`requires NVIDIA / CUDA`}),m.status===`unavailable`&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:`unavailable on this device`}),c===`saved`&&(0,x.jsx)(`span`,{className:`muted small`,children:`saved ✓`})]}),m.status===`available`&&(0,x.jsxs)(`p`,{className:`muted small`,style:{marginTop:`0.4rem`},children:[`This means the engine can launch on this`,` `,m.backend===`metal`?`Mac`:`machine`,`. Each model below still has its own disk and memory requirements.`]}),(m.status===`unavailable`||m.status===`requires-cuda`)&&(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:`0.4rem`},children:m.reason})]}),m.status!==`unavailable`&&m.status!==`external`&&o.length>1&&(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h4`,{children:`Default model`}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`Which DwarfStar model new chat sessions use when a gezel doesn't pin one.`}),(0,x.jsx)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`},children:(0,x.jsxs)(`select`,{"aria-label":`Default model`,value:e?.defaultModel?.ds4??``,onChange:e=>void d(e.target.value||void 0),children:[(0,x.jsx)(`option`,{value:``,children:`First local model`}),o.map(e=>(0,x.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.id,`)`]},e.id))]})})]}),m.status!==`unavailable`&&m.status!==`external`&&(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h4`,{children:`DwarfStar models`}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`Lower quantizations (Q2) start faster and need less disk and memory; higher ones (Q4) keep more model detail but can need several times the disk space and a larger memory working set. Check the size on each row before starting — these downloads run to hundreds of gigabytes.`}),(0,x.jsx)(C,{onModelsChanged:u}),(0,x.jsx)(T,{})]}),m.status!==`unavailable`&&m.status!==`external`&&(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h4`,{children:`Memory use`}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`A model held entirely in memory generates roughly ten times faster than one whose experts are read from SSD as they're needed. Gezel keeps a model in memory whenever this machine has room for it, and falls back to streaming when it doesn't — the model list shows which each one will do.`}),(0,x.jsxs)(`div`,{className:`gz-tray`,role:`radiogroup`,"aria-label":`Memory use`,style:{marginTop:`0.6rem`},children:[(0,x.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":!p,className:`gz-key gz-key--stacked${p?``:` gz-key-active`}`,onClick:()=>void f(!1),children:[(0,x.jsx)(`span`,{className:`gz-key-label`,children:`Keep in memory when it fits`}),(0,x.jsx)(`span`,{className:`gz-key-hint`,children:`Fastest. Falls back to streaming automatically.`})]}),(0,x.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p,className:`gz-key gz-key--stacked${p?` gz-key-active`:``}`,onClick:()=>void f(!0),children:[(0,x.jsx)(`span`,{className:`gz-key-label`,children:`Always stream from SSD`}),(0,x.jsx)(`span`,{className:`gz-key-hint`,children:`Much slower, but leaves memory free for other apps.`})]})]}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:`0.6rem`},children:`Gezel never holds a model in memory that wouldn't leave enough for the system and your other apps — a model too large for this machine streams regardless of this setting.`})]}),m.status===`external`&&(0,x.jsx)(`p`,{className:`muted small`,children:`This external DwarfStar server manages its own model files and memory settings. Local downloads are not used while the external server is configured.`})]})}function T(){let[e,t]=(0,b.useState)({kind:`idle`}),n=(0,b.useCallback)(async()=>{t({kind:`loading`});try{t({kind:`loaded`,...await a.getDs4Log(4096)})}catch(e){t({kind:`error`,message:e instanceof Error?e.message:String(e)})}},[]);return(0,x.jsxs)(`details`,{style:{marginTop:`1rem`},children:[(0,x.jsxs)(`summary`,{style:{cursor:`pointer`,userSelect:`none`},children:[`Diagnostics`,` `,(0,x.jsx)(`span`,{className:`muted small`,children:`— DwarfStar engine output retained for troubleshooting.`})]}),(0,x.jsxs)(`div`,{style:{marginTop:`0.5rem`},children:[(0,x.jsxs)(`div`,{className:`new-row`,style:{alignItems:`center`,gap:`0.5rem`},children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>void n(),disabled:e.kind===`loading`,children:e.kind===`loading`?`Loading…`:`Refresh engine log`}),e.kind===`loaded`&&e.path&&(0,x.jsx)(`span`,{className:`muted small`,title:e.path,children:e.path}),e.kind===`loaded`&&!e.path&&(0,x.jsx)(`span`,{className:`muted small`,children:`No DwarfStar engine log yet.`})]}),e.kind===`error`&&(0,x.jsxs)(`div`,{className:`muted small`,style:{marginTop:`0.5rem`,color:`#ff9b9b`},children:[`Couldn't load log: `,e.message]}),e.kind===`loaded`&&e.tail&&(0,x.jsx)(`pre`,{style:{marginTop:`0.5rem`,padding:`0.5rem`,background:`rgba(255,255,255,0.04)`,border:`1px solid rgba(255,255,255,0.1)`,borderRadius:4,maxHeight:`18rem`,overflow:`auto`,fontSize:`0.75rem`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:e.tail}),e.kind===`loaded`&&e.path&&!e.tail&&(0,x.jsx)(`div`,{className:`muted small`,style:{marginTop:`0.5rem`},children:`The log exists but is empty. Start a DwarfStar chat, then refresh.`})]})]})}export{w as Ds4Settings};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{f as r,xt as i}from"./dist-CE5CbmDb.js";import{t as a}from"./api-CmrgM5Rf.js";import{t as o}from"./model-context-DBqdK0PS.js";import{n as s,r as c,t as l}from"./model-memory-copy-Ds9w1uJE.js";import{t as u}from"./ConfirmDialog-Dt1ed4Fh.js";import{a as d,r as f,t as p}from"./model-inventory-ykSm_IT5.js";import{Mt as m}from"./index-DivKnJyx.js";import{t as h}from"./IncompleteDownloads-C8_XyP8O.js";import{a as ee,i as te,n as g,o as ne,r as re,t as _}from"./UnrecognizedModels-BzdU1clO.js";import{t as v}from"./useTotalRamBytes-Durk383U.js";import{t as y}from"./ds4-availability-TaGRbP_O.js";import{t as ie}from"./local-engine-label-BR-PGVFE.js";var b=e(t(),1),x=n();function S(e){return e.kind!==`chat-model`||!e.ds4?null:e}function C({onModelsChanged:e}){let[t,n]=(0,b.useState)(null),[v,y]=(0,b.useState)(new Set),[ie,C]=(0,b.useState)(new Map),[w,T]=(0,b.useState)(new Set),[E,D]=(0,b.useState)(new Map),[O,k]=(0,b.useState)(null),[A,j]=(0,b.useState)(!1),[M,ae]=(0,b.useState)(null),[oe,N]=(0,b.useState)(null),[se,P]=(0,b.useState)(!1),[F,I]=(0,b.useState)(new Map),[L,R]=(0,b.useState)(null),[z,B]=(0,b.useState)([]),[V,H]=(0,b.useState)([]),[U,W]=(0,b.useState)(null),[G,ce]=(0,b.useState)(new Map),[K,le]=(0,b.useState)([]),q=(0,b.useRef)([]),J=(0,b.useCallback)(async()=>{try{let e=await a.listModelFitness();ce(new Map(e.records.map(e=>[e.key,e]))),le(e.probing),q.current=e.probing}catch{}},[]),Y=(0,b.useCallback)(async()=>{try{let e=await a.listIncompleteDs4Models();B(e.incomplete??[])}catch{}},[]),X=(0,b.useCallback)(async()=>{try{let e=await a.listDs4Models();y(new Set(e.models.map(e=>e.id))),C(new Map(e.models.map(e=>[e.id,e]))),T(new Set(e.models.filter(e=>e.readOnly).map(e=>e.id))),H(e.unrecognized??[])}catch{}try{let e=await a.listDs4ContextPlans();D(new Map(Object.entries(e.plans??{})))}catch{}Y()},[Y]),ue=(0,b.useCallback)(async(e,t)=>{N(e);try{let n=await a.getConfig();await a.updateConfig({nativeVision:{...n.nativeVision??{},[e]:t}}),await X()}catch{}finally{N(null)}},[X]),Z=(0,b.useCallback)(async()=>{R(null);try{let[e,t]=await Promise.all([a.listCatalogItems(`chat-model`),a.getMemoryProfile()]);n(e.items),k({totalRamBytes:t.totalRamBytes,usableBytes:t.usableBytes})}catch(e){R(e instanceof Error?e.message:String(e))}},[]);(0,b.useEffect)(()=>{Z(),X(),a.getModelContextOverrides(`ds4`).then(()=>P(!0)).catch(()=>P(!1))},[Z,X]),(0,b.useEffect)(()=>{let e=e=>{d(e)===`ds4`&&X()};return window.addEventListener(p,e),()=>window.removeEventListener(p,e)},[X]),(0,b.useEffect)(()=>{let e=!1,t,n=async()=>{await J(),!e&&(t=setTimeout(()=>void n(),q.current.length>0?2e3:15e3))};return n(),()=>{e=!0,t&&clearTimeout(t)}},[J]),(0,b.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await a.listDs4ActiveInstalls();if(e)return;I(e=>{let n=new Map(e),r=new Set;for(let e of t.installs){r.add(e.catalogId);let t=n.get(e.catalogId);t?.origin===`local`&&!t.error||n.set(e.catalogId,{bytesWritten:e.bytesWritten,totalBytes:e.totalBytes,phase:e.phase===`extracting-metadata`?`finalizing`:e.phase,origin:`remote`})}for(let[e,t]of n)t.origin===`remote`&&!r.has(e)&&n.delete(e);return n}),t.installs.length===0&&X()}catch{}};t();let n=setInterval(()=>void t(),2e3);return()=>{e=!0,clearInterval(n)}},[X]);let Q=(0,b.useCallback)(t=>{I(e=>new Map(e).set(t,{bytesWritten:0,totalBytes:0,phase:`downloading`,origin:`local`})),(async()=>{try{await a.installDs4Model(t,e=>{I(n=>{let r=new Map(n),i=r.get(t)??{bytesWritten:0,totalBytes:0,phase:`downloading`,origin:`local`};return e.type===`progress`?r.set(t,{...i,bytesWritten:e.bytesWritten,totalBytes:e.totalBytes,phase:`downloading`}):e.type===`verifying`?r.set(t,{...i,phase:`verifying`}):e.type===`extracting-metadata`?r.set(t,{...i,phase:`finalizing`}):e.type===`error`&&r.set(t,{...i,error:e.error}),r})}),f(`ds4`)}catch(e){I(n=>{let r=new Map(n),i=r.get(t);return i&&r.set(t,{...i,error:e instanceof Error?e.message:String(e)}),r});return}finally{I(e=>{let n=new Map(e);return n.get(t)?.error||n.delete(t),n}),await X(),e?.()}})()},[X,e]),de=(0,b.useCallback)(async t=>{R(null),y(e=>{let n=new Set(e);return n.delete(t),n}),B(e=>e.filter(e=>e.id!==t)),H(e=>e.filter(e=>e.id!==t));try{await a.deleteDs4Model(t),f(`ds4`),await X(),e?.()}catch(e){R(`delete failed: ${e instanceof Error?e.message:String(e)}`),X()}},[X,e]),fe=(0,b.useMemo)(()=>(t??[]).map(e=>({it:e,m:S(e.manifest)})).filter(e=>e.m!==null),[t]);if(L)return(0,x.jsxs)(`div`,{className:`new-row`,style:{alignItems:`center`,gap:`0.6rem`},children:[(0,x.jsxs)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:[`Couldn't load models: `,L]}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>void Z(),children:`Retry`})]});if(t===null)return(0,x.jsx)(`p`,{className:`muted small`,children:`Loading models…`});if(fe.length===0)return(0,x.jsx)(`p`,{className:`muted small`,children:`No DwarfStar models in the catalog.`});let pe=new Set(V.map(e=>e.id)),me=fe.filter(({m:e})=>!pe.has(e.id)||F.has(e.id)).filter(({m:e})=>A||v.has(e.id)||!i(e)).map((e,t)=>({entry:e,index:t})).sort((e,t)=>{let n=Number(v.has(t.entry.m.id))-Number(v.has(e.entry.m.id));return n===0?e.index-t.index:n}).map(({entry:e})=>e),$=e=>E.get(e.id)?.projectedResidentBytes??e.ds4.residentBytes,he=Math.min(...me.map(({m:e})=>$(e)??1/0));return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(g,{engine:`ds4`,onModelsChanged:e}),(0,x.jsx)(_,{items:V.filter(e=>!F.has(e.id)),onUpdate:Q,onRemove:W}),(0,x.jsx)(h,{items:z.filter(e=>!F.has(e.id)),onResume:e=>Q(e),onDelete:W}),(0,x.jsxs)(`div`,{className:`ollama-section`,children:[(0,x.jsxs)(`p`,{className:`muted small`,style:{marginTop:0},children:[`Retired models are hidden by default.`,` `,(0,x.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>j(e=>!e),children:A?`Hide retired models`:`Show all models`})]}),(0,x.jsx)(`div`,{className:`ollama-model-table-wrap`,children:(0,x.jsxs)(`table`,{className:`ollama-model-table ds4-model-table`,children:[(0,x.jsxs)(`colgroup`,{children:[(0,x.jsx)(`col`,{className:`model-name-column`}),(0,x.jsx)(`col`,{}),(0,x.jsx)(`col`,{}),(0,x.jsx)(`col`,{}),(0,x.jsx)(`col`,{})]}),(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`th`,{children:`Name`}),(0,x.jsx)(`th`,{title:`Download size, and the memory working set this device would run the model at. A streaming engine keeps far less resident than it downloads.`,children:`Size`}),(0,x.jsx)(`th`,{title:`Effective per-turn context size after Gezel's settings and memory limits`,children:`Context size`}),(0,x.jsx)(`th`,{title:`Reading and writing speed, measured against an approximately 20K-token prompt`,children:`Fitness`}),(0,x.jsx)(`th`,{})]})}),(0,x.jsx)(`tbody`,{children:me.map(({m:e})=>{let t=E.get(e.id),n=$(e),u=e.ds4.cacheExpertsBytes??0,d=O?Math.max(0,O.totalRamBytes-r):0,f=O&&n?n<=d:!0,p=n?Math.max(0,n-u):0,m=!O||p+1024**3<=d,h=n===he,g=v.has(e.id),_=i(e),y=F.get(e.id),S=y&&y.totalBytes>0?Math.floor(y.bytesWritten/y.totalBytes*100):0,C=t?.fullyResident===!0,T=C?(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--ok ds4-model-fit`,title:`This device holds the whole model in memory — no expert streaming from SSD. That is roughly ten times faster to generate than the streaming fallback${n?`, and costs about ${c(e.ds4.approxSizeBytes)} of memory while loaded`:``}.`,children:`runs fully in memory · fastest`}):n?f?(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--info ds4-model-fit`,title:`Too large to hold in memory on this device, so DwarfStar keeps about ${c(n)} resident and reads the remaining experts from SSD as it goes. That works, but generates roughly ten times slower than a model that fits in memory. A smaller quant that fits will be much faster.`,children:h?`streams from SSD · lightest option`:`streams from SSD · slower`}):m?(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn ds4-model-fit`,title:`Gezel will reduce this model's expert cache below its ${c(n)} target to preserve ${c(r)} for the system and other apps. It should run, but will read from SSD even more often than a normal streaming launch.`,children:`reduced cache · much slower`}):(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn ds4-model-fit`,title:`The model's fixed memory requirement leaves too little room for the system, even with the expert cache reduced.`,children:`needs more memory`}):null,D=e.name,k=ie.get(e.id),A=k?{...k,...t?.effectiveContextWindow!==void 0&&!k.effectiveContextWindow?{effectiveContextWindow:t.effectiveContextWindow}:{},...t?.contextCeilingTokens!==void 0&&k.contextCeilingTokens===void 0?{contextCeilingTokens:t.contextCeilingTokens}:{},...t?.kvBytesPerToken!==void 0&&k.kvBytesPerTokenPerSlot===void 0?{kvBytesPerTokenPerSlot:t.kvBytesPerToken,kvFixedBytesPerSlot:0}:{},...t?.contextFreeResidentBytes!==void 0&&k.weightsResidentBytes===void 0?{weightsResidentBytes:t.contextFreeResidentBytes}:{}}:void 0,j=A?.effectiveContextWindow??t?.effectiveContextWindow,N=A?.overrideContextTokens??t?.overrideContextTokens,P=A?.contextSizingStatus===`restart-required`,I={approxSizeBytes:e.ds4.approxSizeBytes,residentBytes:n,...t?.kvBytesPerToken!==void 0&&t.contextFreeResidentBytes!==void 0&&j!==void 0?{contextFreeBytes:t.contextFreeResidentBytes}:{},...j===void 0?{}:{effectiveContextWindow:j},...C?{fullyResident:!0}:{}},L=l(I),R=A?.updateAvailable===!0,z=`ds4:${e.id}`;return(0,x.jsxs)(b.Fragment,{children:[(0,x.jsxs)(`tr`,{children:[(0,x.jsx)(`td`,{className:`model-name-table-cell`,children:(0,x.jsxs)(`div`,{className:`model-name-cell`,children:[(0,x.jsx)(`strong`,{className:`ds4-model-name`,children:D}),(0,x.jsxs)(`div`,{className:`model-name-meta`,children:[(0,x.jsx)(`span`,{className:`muted small`,children:e.parameterSize}),g&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--ok`,children:`on device`}),_&&(0,x.jsx)(`span`,{className:`catalog-item-tag catalog-item-tag--retired`,title:`This model is kept for compatibility but is no longer recommended for new downloads.`,children:`retired`}),R&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:A?.updateReason??(A?.availableVersion?`A newer build is available in the catalog (→ v${A.availableVersion}). Updating downloads only the files that differ.`:`A newer build is available in the catalog. Updating downloads only the files that differ.`),children:`update available`})]}),T]})}),(0,x.jsx)(`td`,{children:(0,x.jsxs)(`span`,{className:`model-size-cell`,title:`${s(I)}${e.ds4.visionEncoder?` The ${c(e.ds4.visionEncoder.sizeBytes,2)} vision encoder is installed separately, loaded by default, and can be turned off under Advanced to save runtime memory.`:``}`,children:[c(e.ds4.approxSizeBytes),e.ds4.visionEncoder?(0,x.jsxs)(`span`,{className:`muted small model-memory-headline`,children:[`+`,c(e.ds4.visionEncoder.sizeBytes,2),` vision encoder`]}):null,L?(0,x.jsx)(`span`,{className:`muted small model-memory-headline`,children:L}):null]})}),(0,x.jsx)(`td`,{title:P?`This model is running with a different context window than the current sizing settings resolve to. Restart the local engine (or let it go idle) so Gezel can re-admit it — no memory change needed.`:j===void 0?void 0:N===void 0?`Gezel will grant up to ${j.toLocaleString()} tokens per turn.`:`You've set this model to ${N.toLocaleString()} tokens per turn.`,children:P?`Restart needed`:j===void 0?(0,x.jsx)(`span`,{className:`muted`,children:`—`}):(0,x.jsxs)(x.Fragment,{children:[o(j),N!==void 0&&(0,x.jsx)(`span`,{className:`gz-budget-tag gz-budget-tag-custom model-context-custom-tag`,children:`custom`})]})}),g?(0,x.jsx)(re,{entry:G.get(z),probing:K.includes(z)}):(0,x.jsx)(`td`,{className:`model-fitness-table-cell`,children:(0,x.jsx)(`span`,{className:`muted small`,title:`The fitness check measures this model on THIS machine, so it runs once the download lands.`,children:`after download`})}),(0,x.jsx)(`td`,{className:`model-actions-table-cell`,children:y?y.error?(0,x.jsxs)(`div`,{className:`ds4-model-progress`,children:[(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:y.error}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>Q(e.id),children:`Retry`})]}):(0,x.jsx)(`span`,{className:`muted small ds4-model-progress-label`,children:y.phase===`downloading`?`downloading… ${S}%`:y.phase===`verifying`?`verifying sha256…`:`finalizing…`}):g?(0,x.jsxs)(`div`,{className:`model-actions-cell`,children:[(0,x.jsx)(`div`,{className:`model-action-status`,children:w.has(e.id)&&(0,x.jsx)(`span`,{className:`muted small`,title:`Provided by the machine-wide install (shared asset store). It can't be removed from here — manage it with the machine installer, or install a user-owned copy to shadow it.`,children:`Machine model`})}),(0,x.jsx)(`div`,{className:`model-action-links`,children:(0,x.jsx)(ee,{engine:`ds4`,model:A??{id:e.id,approxSizeBytes:e.ds4.approxSizeBytes,readOnly:w.has(e.id)},contextSupported:se,contextEditorOpen:M===e.id,onToggleContextEditor:()=>ae(t=>t===e.id?null:e.id),...A?.nativeVisionEnabled===void 0?{}:{visionAction:{enabled:A.nativeVisionEnabled,busy:oe===e.id,sidecarSizeBytes:A.visionEncoderSizeBytes??e.ds4.visionEncoder?.sizeBytes,onToggle:()=>void ue(e.id,!A.nativeVisionEnabled)}},fitnessAction:te(G.get(z),K.includes(z),()=>{a.runModelFitnessProbe(`ds4`,e.id).then(()=>J()).catch(()=>{})}),onUpdate:()=>Q(e.id),onDelete:w.has(e.id)?void 0:()=>W(e.id)})})]}):m?(0,x.jsx)(`button`,{type:`button`,onClick:()=>Q(e.id),children:`Download`}):null})]}),M===e.id&&A&&(0,x.jsx)(`tr`,{className:`model-context-editor-row`,children:(0,x.jsx)(`td`,{colSpan:5,children:(0,x.jsx)(ne,{engine:`ds4`,model:A,onSaved:X})})})]},e.id)})})]})})]}),(0,x.jsxs)(`div`,{style:{marginTop:`1.25rem`},children:[(0,x.jsx)(m,{}),(0,x.jsx)(`span`,{className:`muted small`,style:{marginLeft:`0.75rem`},children:`Import from a gezel local model package`})]}),(0,x.jsx)(u,{open:U!==null,title:`Remove ${U??`model`}?`,message:`This permanently removes the model files from this device. The model stays available in the catalog, so you can download a current build later.`,confirmLabel:`Remove`,danger:!0,onConfirm:()=>{let e=U;W(null),e&&de(e)},onCancel:()=>W(null)})]})}function w({config:e,onConfigChanged:t,health:n,title:r}){let i=v(),[o,s]=(0,b.useState)([]),[c,l]=(0,b.useState)(`idle`),u=(0,b.useCallback)(async()=>{try{let e=await a.listDs4Models();s(e.models)}catch{}},[]);(0,b.useEffect)(()=>{u()},[u]);let d=(0,b.useCallback)(async n=>{l(`saving`);try{t(await a.updateConfig({defaultModel:{...e?.defaultModel,ds4:n??void 0}})),l(`saved`),setTimeout(()=>l(`idle`),1200)}catch{l(`idle`)}},[e?.defaultModel,t]),f=(0,b.useCallback)(async e=>{l(`saving`);try{t(await a.updateConfig({ds4SsdStreaming:e?!0:void 0})),l(`saved`),setTimeout(()=>l(`idle`),1200)}catch{l(`idle`)}},[t]),p=e?.ds4SsdStreaming===!0,m=y({externalBaseUrl:e?.ds4BaseUrl,totalRamBytes:i??void 0,ds4ServerBundled:n?.ds4ServerBundled,serverPlatform:n?.platform,detectedBackend:n?.llamaCppDetectedBackend,gpuVendor:n?.llamaCppDetectedVendor});return(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h3`,{children:r??ie(`ds4`,n?.platform)}),(0,x.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:`DwarfStar (ds4) is an inference engine built for a handful of very large mixture-of-experts models — DeepSeek V4 and GLM 5.2/5.3. They may not fit in memory; DwarfStar keeps a bounded expert cache in RAM and reads the other experts from SSD as they are needed.`}),(0,x.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`,alignItems:`center`},children:[(0,x.jsx)(`span`,{className:`muted small`,children:`Status:`}),m.status===`available`&&(0,x.jsxs)(`span`,{className:`gz-status-pill gz-status-pill--ok`,children:[`engine available · `,m.backend]}),m.status===`external`&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:`Using an external ds4-server at: ${e?.ds4BaseUrl}`,children:`using external DwarfStar server`}),m.status===`requires-cuda`&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:`requires NVIDIA / CUDA`}),m.status===`unavailable`&&(0,x.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,children:`unavailable on this device`}),c===`saved`&&(0,x.jsx)(`span`,{className:`muted small`,children:`saved ✓`})]}),m.status===`available`&&(0,x.jsxs)(`p`,{className:`muted small`,style:{marginTop:`0.4rem`},children:[`This means the engine can launch on this`,` `,m.backend===`metal`?`Mac`:`machine`,`. Each model below still has its own disk and memory requirements.`]}),(m.status===`unavailable`||m.status===`requires-cuda`)&&(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:`0.4rem`},children:m.reason})]}),m.status!==`unavailable`&&m.status!==`external`&&o.length>1&&(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h4`,{children:`Default model`}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`Which DwarfStar model new chat sessions use when a gezel doesn't pin one.`}),(0,x.jsx)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`},children:(0,x.jsxs)(`select`,{"aria-label":`Default model`,value:e?.defaultModel?.ds4??``,onChange:e=>void d(e.target.value||void 0),children:[(0,x.jsx)(`option`,{value:``,children:`First local model`}),o.map(e=>(0,x.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.id,`)`]},e.id))]})})]}),m.status!==`unavailable`&&m.status!==`external`&&(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h4`,{children:`DwarfStar models`}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`Lower quantizations (Q2) start faster and need less disk and memory; higher ones (Q4) keep more model detail but can need several times the disk space and a larger memory working set. Check the size on each row before starting — these downloads run to hundreds of gigabytes.`}),(0,x.jsx)(C,{onModelsChanged:u}),(0,x.jsx)(T,{})]}),m.status!==`unavailable`&&m.status!==`external`&&(0,x.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,x.jsx)(`h4`,{children:`Memory use`}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`A model held entirely in memory generates roughly ten times faster than one whose experts are read from SSD as they're needed. Gezel keeps a model in memory whenever this machine has room for it, and falls back to streaming when it doesn't — the model list shows which each one will do.`}),(0,x.jsxs)(`div`,{className:`gz-tray`,role:`radiogroup`,"aria-label":`Memory use`,style:{marginTop:`0.6rem`},children:[(0,x.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":!p,className:`gz-key gz-key--stacked${p?``:` gz-key-active`}`,onClick:()=>void f(!1),children:[(0,x.jsx)(`span`,{className:`gz-key-label`,children:`Keep in memory when it fits`}),(0,x.jsx)(`span`,{className:`gz-key-hint`,children:`Fastest. Falls back to streaming automatically.`})]}),(0,x.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p,className:`gz-key gz-key--stacked${p?` gz-key-active`:``}`,onClick:()=>void f(!0),children:[(0,x.jsx)(`span`,{className:`gz-key-label`,children:`Always stream from SSD`}),(0,x.jsx)(`span`,{className:`gz-key-hint`,children:`Much slower, but leaves memory free for other apps.`})]})]}),(0,x.jsx)(`p`,{className:`muted small`,style:{marginTop:`0.6rem`},children:`Gezel never holds a model in memory that wouldn't leave enough for the system and your other apps — a model too large for this machine streams regardless of this setting.`})]}),m.status===`external`&&(0,x.jsx)(`p`,{className:`muted small`,children:`This external DwarfStar server manages its own model files and memory settings. Local downloads are not used while the external server is configured.`})]})}function T(){let[e,t]=(0,b.useState)({kind:`idle`}),n=(0,b.useCallback)(async()=>{t({kind:`loading`});try{t({kind:`loaded`,...await a.getDs4Log(4096)})}catch(e){t({kind:`error`,message:e instanceof Error?e.message:String(e)})}},[]);return(0,x.jsxs)(`details`,{style:{marginTop:`1rem`},children:[(0,x.jsxs)(`summary`,{style:{cursor:`pointer`,userSelect:`none`},children:[`Diagnostics`,` `,(0,x.jsx)(`span`,{className:`muted small`,children:`— DwarfStar engine output retained for troubleshooting.`})]}),(0,x.jsxs)(`div`,{style:{marginTop:`0.5rem`},children:[(0,x.jsxs)(`div`,{className:`new-row`,style:{alignItems:`center`,gap:`0.5rem`},children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>void n(),disabled:e.kind===`loading`,children:e.kind===`loading`?`Loading…`:`Refresh engine log`}),e.kind===`loaded`&&e.path&&(0,x.jsx)(`span`,{className:`muted small`,title:e.path,children:e.path}),e.kind===`loaded`&&!e.path&&(0,x.jsx)(`span`,{className:`muted small`,children:`No DwarfStar engine log yet.`})]}),e.kind===`error`&&(0,x.jsxs)(`div`,{className:`muted small`,style:{marginTop:`0.5rem`,color:`#ff9b9b`},children:[`Couldn't load log: `,e.message]}),e.kind===`loaded`&&e.tail&&(0,x.jsx)(`pre`,{style:{marginTop:`0.5rem`,padding:`0.5rem`,background:`rgba(255,255,255,0.04)`,border:`1px solid rgba(255,255,255,0.1)`,borderRadius:4,maxHeight:`18rem`,overflow:`auto`,fontSize:`0.75rem`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:e.tail}),e.kind===`loaded`&&e.path&&!e.tail&&(0,x.jsx)(`div`,{className:`muted small`,style:{marginTop:`0.5rem`},children:`The log exists but is empty. Start a DwarfStar chat, then refresh.`})]})]})}export{w as Ds4Settings};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{ProjectDetailView as r}from"./ProjectsView-BUdR76n6.js";var i=e(t(),1),a=n();function o({projectId:e,theme:t,accent:n,bg:o,fg:s,fontFamily:c,compact:l=!1}){return(0,i.useEffect)(()=>{let e=document.documentElement;return n&&e.style.setProperty(`--accent`,n),o&&e.style.setProperty(`--bg`,o),s&&e.style.setProperty(`--fg`,s),c&&e.style.setProperty(`--font-ui`,c),t&&e.setAttribute(`data-host-theme`,t),e.classList.add(`embedded-chat`),()=>{e.classList.remove(`embedded-chat`),e.removeAttribute(`data-host-theme`)}},[t,n,o,s,c]),(0,a.jsx)(`div`,{className:`embedded-chat-root`,children:(0,a.jsx)(r,{projectId:e,compact:l})})}export{o as EmbeddedChat};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{ProjectDetailView as r}from"./ProjectsView-D0uJjUB-.js";var i=e(t(),1),a=n();function o({projectId:e,theme:t,accent:n,bg:o,fg:s,fontFamily:c,compact:l=!1}){return(0,i.useEffect)(()=>{let e=document.documentElement;return n&&e.style.setProperty(`--accent`,n),o&&e.style.setProperty(`--bg`,o),s&&e.style.setProperty(`--fg`,s),c&&e.style.setProperty(`--font-ui`,c),t&&e.setAttribute(`data-host-theme`,t),e.classList.add(`embedded-chat`),()=>{e.classList.remove(`embedded-chat`),e.removeAttribute(`data-host-theme`)}},[t,n,o,s,c]),(0,a.jsx)(`div`,{className:`embedded-chat-root`,children:(0,a.jsx)(r,{projectId:e,compact:l})})}export{o as EmbeddedChat};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-C0I7spBl.js";import{t as i}from"./ConfirmDialog-Dt1ed4Fh.js";var a=e(t(),1),o=n();function s(){let[e,t]=(0,a.useState)(!1),[n,s]=(0,a.useState)(!1),[c,l]=(0,a.useState)(!1),[u,d]=(0,a.useState)(null),[f,p]=(0,a.useState)(null);(0,a.useEffect)(()=>{(async()=>{try{let e=await r.getConfig();t(e.faceRecognition?.enabled===!0)}catch{}finally{s(!0)}})()},[]);let m=(0,a.useCallback)(async n=>{let i=e;t(n),p(null),d(null);try{await r.updateConfig({faceRecognition:{enabled:n}})}catch(e){t(i),p(e instanceof Error?e.message:String(e))}},[e]),h=(0,a.useCallback)(async()=>{p(null);try{let e=await r.wipeFaceData();t(!1),l(!1),d(e.projects>0?`Face data erased across ${e.projects} project${e.projects===1?``:`s`}.`:`No face data was stored.`)}catch(e){p(e instanceof Error?e.message:String(e))}},[]);return(0,o.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,o.jsx)(`h3`,{children:`People in photos`}),(0,o.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:`When on, Gezel looks for faces in indexed photos and groups the same person across them, so you can name someone once and find them anywhere. Everything runs on this device — photos and face data never leave it. Turning this on downloads the face models once (about 260 MB).`}),(0,o.jsxs)(`label`,{className:`debug-toggle`,children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:e,disabled:!n,onChange:e=>void m(e.target.checked)}),(0,o.jsx)(`span`,{children:`Recognize people in photos`})]}),(0,o.jsx)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`},children:(0,o.jsx)(`button`,{type:`button`,className:`danger`,onClick:()=>l(!0),children:`Turn off and erase face data`})}),u&&(0,o.jsx)(`p`,{className:`muted small`,children:u}),f&&(0,o.jsx)(`p`,{className:`error small`,children:f}),(0,o.jsx)(i,{open:c,title:`Erase all face data?`,message:`Deletes every stored face signature, person, and name across all projects, and turns face recognition off. Photos themselves are not touched. This cannot be undone.`,confirmLabel:`Erase face data`,danger:!0,onConfirm:h,onCancel:()=>l(!1)})]})}export{s as FaceRecognitionCard};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-CmrgM5Rf.js";import{t as i}from"./ConfirmDialog-Dt1ed4Fh.js";var a=e(t(),1),o=n();function s(){let[e,t]=(0,a.useState)(!1),[n,s]=(0,a.useState)(!1),[c,l]=(0,a.useState)(!1),[u,d]=(0,a.useState)(null),[f,p]=(0,a.useState)(null);(0,a.useEffect)(()=>{(async()=>{try{let e=await r.getConfig();t(e.faceRecognition?.enabled===!0)}catch{}finally{s(!0)}})()},[]);let m=(0,a.useCallback)(async n=>{let i=e;t(n),p(null),d(null);try{await r.updateConfig({faceRecognition:{enabled:n}})}catch(e){t(i),p(e instanceof Error?e.message:String(e))}},[e]),h=(0,a.useCallback)(async()=>{p(null);try{let e=await r.wipeFaceData();t(!1),l(!1),d(e.projects>0?`Face data erased across ${e.projects} project${e.projects===1?``:`s`}.`:`No face data was stored.`)}catch(e){p(e instanceof Error?e.message:String(e))}},[]);return(0,o.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,o.jsx)(`h3`,{children:`People in photos`}),(0,o.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:`When on, Gezel looks for faces in indexed photos and groups the same person across them, so you can name someone once and find them anywhere. Everything runs on this device — photos and face data never leave it. Turning this on downloads the face models once (about 260 MB).`}),(0,o.jsxs)(`label`,{className:`debug-toggle`,children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:e,disabled:!n,onChange:e=>void m(e.target.checked)}),(0,o.jsx)(`span`,{children:`Recognize people in photos`})]}),(0,o.jsx)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`},children:(0,o.jsx)(`button`,{type:`button`,className:`danger`,onClick:()=>l(!0),children:`Turn off and erase face data`})}),u&&(0,o.jsx)(`p`,{className:`muted small`,children:u}),f&&(0,o.jsx)(`p`,{className:`error small`,children:f}),(0,o.jsx)(i,{open:c,title:`Erase all face data?`,message:`Deletes every stored face signature, person, and name across all projects, and turns face recognition off. Photos themselves are not touched. This cannot be undone.`,confirmLabel:`Erase face data`,danger:!0,onConfirm:h,onCancel:()=>l(!1)})]})}export{s as FaceRecognitionCard};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{F as r,Ft as i,X as a,rt as o,z as s}from"./dist-CE5CbmDb.js";import{t as c}from"./api-CmrgM5Rf.js";import{y as l}from"./primitives-CWrGZpPI.js";import{l as u,t as d}from"./styles-CqO-rmOt.js";import{Ct as f,Z as p}from"./index-DivKnJyx.js";import{t as m}from"./MarkdownField-BX0qsaFq.js";var h=e(t(),1),g=.05;function _(e){return Math.max(g,Math.min(12,e))}function v(e){return e<.45?`city`:e<1.3?`district`:`street`}function y(e,t){return(t-e.offsetX)*e.scale}function b(e,t){return(t-e.offsetY)*e.scale}function ee(e,t){return t/e.scale+e.offsetX}function te(e,t){return t/e.scale+e.offsetY}function ne(e,t,n,r=32){if(e.w<=0||e.h<=0||t<=0||n<=0)return{scale:1,offsetX:0,offsetY:0};let i=_(Math.min((t-r*2)/e.w,(n-r*2)/e.h)),a=e.x+e.w/2,o=e.y+e.h/2;return{scale:i,offsetX:a-t/2/i,offsetY:o-n/2/i}}function re(e,t,n,r){let i=_(e.scale*t);if(i===e.scale)return e;let a=ee(e,n),o=te(e,r);return{scale:i,offsetX:a-n/i,offsetY:o-r/i}}function x(e,t,n,r){let i=y(e,t.x),a=b(e,t.y),o=t.w*e.scale,s=t.h*e.scale;return i+o>=0&&a+s>=0&&i<=n&&a<=r}function S(e){return a(e.id,e.lang)}function ie(e){return e.buildingCount>0&&S(e)===`code`}function C(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function w(e){let t=e>>>0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function ae(e){let t=0;for(let n=0;n<e.length;n++)t=(t*31+e.charCodeAt(n))%360;return t}var T={brick:{satMul:.9,litDelta:-4,hue:14},stucco:{satMul:.62,litDelta:6,hue:42},timber:{satMul:.7,litDelta:-2,hue:28},stone:{satMul:.34,litDelta:2,hue:40},slate:{satMul:.34,litDelta:-8,hue:220},tile:{satMul:.72,litDelta:-1,hue:18},thatch:{satMul:.5,litDelta:4,hue:44},glass:{satMul:.55,litDelta:10,hue:196},iron:{satMul:.35,litDelta:-10,hue:210}},E={village:[`timber`,`stucco`,`brick`,`stone`],town:[`brick`,`stucco`,`stone`],city:[`brick`,`stone`]},oe={village:[`tile`,`slate`,`thatch`],town:[`tile`,`slate`],city:[`slate`,`tile`]};function se(e,t,n){let r=w(e),i=E[t],a=oe[t],o=r();return{wall:t===`village`?o<.34?`timber`:o<.62?`stucco`:o<.88?`brick`:`stone`:i[Math.min(i.length-1,Math.floor(o*i.length))],roof:n?r()<.5?`iron`:`glass`:t===`village`?(e=>e<.5?`tile`:e<.9?`slate`:`thatch`)(r()):a[Math.min(a.length-1,Math.floor(r()*a.length))]}}function ce(e,t,n){let r=(t-e+540)%360-180;return r*=n,((e+r)%360+360)%360}var D=4;function le(e,t){let n=T[t].litDelta,r=T[e].litDelta-n;return n+Math.max(-4,Math.min(D,r))}function O(e,t,n,r=T[t].litDelta){let i=T[t],a=Math.max(0,Math.min(1,n)),o=a===1?0:1-a*.12;return{h:ce(e.h,i.hue,o),s:Math.max(0,Math.min(100,e.s*i.satMul)),l:Math.max(0,Math.min(100,e.l+r))}}function ue({h:e,s:t,l:n}){return`hsl(${Math.round(e)} ${Math.round(t)}% ${Math.round(n)}%)`}function de(e){return .38+-.2*Math.max(0,Math.min(1,e))}function fe(e){return e?{dark:!0,ground:`hsl(130 10% 12%)`,districtFill:`hsl(40 7% 15%)`,districtStroke:`#3a3733`,curb:`hsl(40 10% 36%)`,sidewalk:`hsl(40 8% 30%)`,districtLabel:`#8b8f99`,label:`#c9ccd4`,road:`#4a4d56`,roadMutual:`#6b7280`,blockStroke:`#15161a`,shadow:`rgba(0, 0, 0, 0.38)`,building:`#11141a`,buildingFacade:`#04060a`,earth:`hsl(35 20% 22%)`,rubble:`hsl(30 6% 30%)`,crane:`hsl(38 80% 55%)`,newBlock:`#3f7d4f`,tombstone:`#55504a`,selected:`#e0a062`,hover:`#9aa0ad`,domeAccent:`hsl(42 60% 55%)`,window:`hsl(214 24% 16%)`,windowLit:`hsl(41 72% 61%)`,masonry:`hsl(18 24% 28%)`,awning:`hsl(8 48% 48%)`,pavementAvenue:`hsl(36 8% 25%)`,pavementStreet:`hsl(36 8% 22%)`,pavementLane:`hsl(36 7% 19%)`,avenueDash:`hsl(45 45% 48%)`,labelPlate:`hsl(228 10% 10% / 0.85)`,labelPlateStroke:`hsl(228 10% 34%)`,hedge:`hsl(128 22% 22%)`,fence:`hsl(36 16% 38%)`,orchard:`hsl(120 18% 20%)`,dirtLane:`hsl(32 16% 20%)`,cobble:`hsl(30 9% 23%)`,stall:`hsl(12 42% 42%)`,districtFillVillage:`hsl(120 9% 14%)`,districtFillCity:`hsl(40 5% 16%)`,street:{verge:`hsl(110 12% 15%)`,rail:`hsl(40 10% 42%)`,wire:`hsl(40 10% 50%)`,lampPost:`hsl(36 12% 40%)`,lampGlow:`hsl(41 80% 62%)`,pole:`hsl(30 14% 34%)`,cart:{top:`hsl(28 30% 42%)`,wallL:`hsl(28 30% 32%)`,wallR:`hsl(28 28% 25%)`},horse:{top:`hsl(24 22% 30%)`,wallL:`hsl(24 22% 22%)`,wallR:`hsl(24 20% 17%)`},trolley:{top:`hsl(150 16% 28%)`,wallL:`hsl(46 50% 60%)`,wallR:`hsl(46 40% 46%)`},trolleyRoof:`hsl(150 16% 28%)`,walker:`hsl(40 10% 62%)`,smoke:`hsl(40 6% 58%)`,water:`hsl(200 30% 36%)`,basin:`hsl(40 10% 34%)`},farm:{crops:[`hsl(44 40% 34%)`,`hsl(96 26% 24%)`,`hsl(30 22% 22%)`,`hsl(58 30% 30%)`],furrow:`hsl(30 20% 12%)`,shed:{top:`hsl(24 26% 30%)`,wallL:`hsl(24 24% 24%)`,wallR:`hsl(24 22% 18%)`}},park:{lawn:`hsl(118 18% 20%)`,path:`hsl(40 12% 34%)`}}:{dark:!1,ground:`hsl(80 24% 86%)`,districtFill:`hsl(46 28% 89%)`,districtStroke:`hsl(44 16% 76%)`,curb:`hsl(44 14% 70%)`,sidewalk:`hsl(46 24% 92%)`,districtLabel:`#7a715c`,label:`#473f30`,road:`#b3a98f`,roadMutual:`#8a7f64`,blockStroke:`#d8d0bd`,shadow:`rgba(70, 60, 35, 0.2)`,building:`#ffffff`,buildingFacade:`#d6cfbd`,earth:`hsl(36 35% 78%)`,rubble:`hsl(40 12% 72%)`,crane:`hsl(38 85% 55%)`,newBlock:`#7bb98a`,tombstone:`#c3bba9`,selected:`#c9722e`,hover:`#6f6651`,domeAccent:`hsl(42 65% 52%)`,window:`hsl(205 24% 39%)`,windowLit:`hsl(42 88% 70%)`,masonry:`hsl(18 26% 48%)`,awning:`hsl(8 52% 52%)`,pavementAvenue:`hsl(46 10% 72%)`,pavementStreet:`hsl(46 12% 78%)`,pavementLane:`hsl(46 14% 82%)`,avenueDash:`hsl(46 40% 94%)`,labelPlate:`hsl(46 30% 96% / 0.88)`,labelPlateStroke:`hsl(44 16% 72%)`,hedge:`hsl(122 26% 42%)`,fence:`hsl(38 20% 62%)`,orchard:`hsl(104 28% 68%)`,dirtLane:`hsl(34 24% 70%)`,cobble:`hsl(44 8% 74%)`,stall:`hsl(10 48% 58%)`,districtFillVillage:`hsl(92 22% 84%)`,districtFillCity:`hsl(44 14% 85%)`,street:{verge:`hsl(88 30% 80%)`,rail:`hsl(40 8% 52%)`,wire:`hsl(40 8% 45%)`,lampPost:`hsl(36 14% 42%)`,lampGlow:`hsl(42 90% 70%)`,pole:`hsl(30 16% 40%)`,cart:{top:`hsl(28 36% 52%)`,wallL:`hsl(28 34% 42%)`,wallR:`hsl(28 32% 34%)`},horse:{top:`hsl(24 26% 38%)`,wallL:`hsl(24 26% 30%)`,wallR:`hsl(24 24% 24%)`},trolley:{top:`hsl(150 20% 36%)`,wallL:`hsl(46 62% 70%)`,wallR:`hsl(46 48% 56%)`},trolleyRoof:`hsl(150 20% 36%)`,walker:`hsl(30 18% 32%)`,smoke:`hsl(40 8% 62%)`,water:`hsl(200 42% 62%)`,basin:`hsl(40 12% 62%)`},farm:{crops:[`hsl(46 62% 66%)`,`hsl(96 36% 52%)`,`hsl(30 30% 58%)`,`hsl(58 48% 72%)`],furrow:`hsl(30 30% 40%)`,shed:{top:`hsl(24 30% 46%)`,wallL:`hsl(24 28% 38%)`,wallR:`hsl(24 26% 30%)`}},park:{lawn:`hsl(112 34% 62%)`,path:`hsl(42 30% 86%)`}}}function pe(e,t){if(!e)return null;let n=Date.parse(e);if(Number.isNaN(n))return null;let r=Math.max(0,(t-n)/864e5);return r<=7?0:r<=30?1:r<=90?2:3}var k=[`hsl(28 92% 58%)`,`hsl(28 70% 46%)`,`hsl(28 42% 35%)`,`hsl(28 16% 27%)`],me=[`hsl(28 92% 44%)`,`hsl(28 70% 34%)`,`hsl(28 42% 26%)`,`hsl(28 16% 20%)`],he=[`hsl(28 92% 68%)`,`hsl(28 70% 56%)`,`hsl(28 42% 44%)`,`hsl(28 16% 35%)`],ge=[`hsl(28 95% 55%)`,`hsl(28 82% 66%)`,`hsl(28 55% 77%)`,`hsl(28 25% 86%)`],_e=[`hsl(28 95% 42%)`,`hsl(28 82% 52%)`,`hsl(28 55% 63%)`,`hsl(28 25% 72%)`],ve=[`hsl(28 95% 66%)`,`hsl(28 82% 76%)`,`hsl(28 55% 85%)`,`hsl(28 25% 92%)`],ye={typescript:210,tsx:210,javascript:48,jsx:48,python:160,rust:20,go:190,css:280,html:15,markdown:90};function be(e){let t=ye[e.toLowerCase()];return t===void 0?Math.round(ae(e)/30)*30%360:t}function xe(e,t,n){if(n!=null)return t.dark?{roof:k[n],facade:me[n],edge:he[n]}:{roof:ge[n],facade:_e[n],edge:ve[n]};if(!e)return t.dark?{roof:`hsl(220 6% 40%)`,facade:`hsl(220 7% 27%)`,edge:`hsl(220 8% 50%)`}:{roof:`hsl(46 12% 72%)`,facade:`hsl(46 12% 56%)`,edge:`hsl(46 16% 82%)`};let r=be(e);return t.dark?{roof:`hsl(${r} 34% 42%)`,facade:`hsl(${r} 36% 28%)`,edge:`hsl(${r} 40% 52%)`}:{roof:`hsl(${r} 48% 70%)`,facade:`hsl(${r} 42% 54%)`,edge:`hsl(${r} 55% 80%)`}}var Se=5,Ce=[`hsl(28 92% 37%)`,`hsl(28 70% 28%)`,`hsl(28 42% 21%)`,`hsl(28 16% 16%)`],A=[`hsl(28 95% 35%)`,`hsl(28 82% 45%)`,`hsl(28 55% 56%)`,`hsl(28 25% 65%)`];function we(e,t,n,r){let i=xe(e,t,n);if(n!=null){let e=t.dark?Ce[n]:A[n];return{top:i.roof,wallL:i.facade,wallR:e,edge:i.edge}}if(!e)return{top:i.roof,wallL:i.facade,wallR:t.dark?`hsl(220 7% 20%)`:`hsl(46 12% 46%)`,edge:i.edge};let a=be(e);if(!r)return{top:i.roof,wallL:i.facade,wallR:t.dark?`hsl(${a} 36% 21%)`:`hsl(${a} 42% 44%)`,edge:i.edge};let o=t.dark?{top:34,wall:36,edge:40}:{top:48,wall:42,edge:55},s=t.dark?{top:42,wallL:28,wallR:21,edge:52}:{top:70,wallL:54,wallR:44,edge:80},c=de(r.urbanity),l=le(r.wall,r.roof),u=Math.max(-1,Math.min(1,r.variance??0))*Se;return{top:ue(O({h:a,s:o.top,l:s.top+u},r.roof,1)),wallL:ue(O({h:a,s:o.wall,l:s.wallL+u},r.wall,c,l)),wallR:ue(O({h:a,s:o.wall,l:s.wallR+u},r.wall,c,l)),edge:ue(O({h:a,s:o.edge,l:s.edge+u},r.roof,1))}}function j(e){return e.urbanity??.5}function M(e){switch(e.settlement){case`hamlet`:case`village`:return`village`;case`city`:return`city`;default:return`town`}}var Te=new WeakMap;function Ee(e){let t=Te.get(e);if(t)return t;let n=new Map;for(let t of e.blocks){if(t.state===`tombstoned`||t.phantom)continue;let e=n.get(t.districtId)??{total:0,count:0};e.total+=j(t),e.count+=1,n.set(t.districtId,e)}let r=new Map;for(let[e,{total:t,count:i}]of n){let n=t/Math.max(1,i);r.set(e,n>=.74?`city`:n>=.52?`town`:`village`)}return Te.set(e,r),r}var De={kind:`none`,u0:0,v0:0,u1:0,v1:0,height:0,behind:!1},N={FACADE:2710517197,ROOF_FURNITURE:1640531527,MASSING:2654435769,MATERIAL:2246822507,TRIM:3266489909,GROUND:668265263,FRONTAGE:374761393};function Oe(e,t){let n=w(e^N.FRONTAGE)();return t===`cart-door`||t===`arcade`?`sash`:t===`portico`?`pediment`:t===`shopfront`?n<.35?`stepped`:n<.65?`pediment`:`sash`:n<.38?`shutters`:n<.7?`bay`:`sash`}var ke={village:{residential:[`cottage`,`cottage-row`,`farmhouse`],commercial:[`village-shop`,`smithy`,`market-cross`],civic:[`chapel`,`schoolhouse`,`parish-hall`],industrial:[`barn`,`mill`,`kiln`]},town:{residential:[`cottage`,`townhouse`,`boarding-house`],commercial:[`corner-shop`,`inn`,`market-hall`],civic:[`library`,`schoolhouse`,`guildhall`],industrial:[`workshop`,`rail-depot`,`foundry`]},city:{residential:[`terrace-house`,`tenement`,`mansion-flat`],commercial:[`shopfront-block`,`hotel`,`arcade`],civic:[`bank`,`institute`,`town-hall`],industrial:[`warehouse`,`works`,`terminus`]}},Ae={cornice:!1,parapet:!1,stringCourse:!1,quoins:!1};function je(e,t,n,r=1){let i=e===`conical`?2.1:e===`pyramid`?1.35:1,a=Math.max(r,i);return n>0&&(a=Math.max(a,i+.68)),a=Math.max(a,i+({cupola:.78,bellcote:.62,"clock-tower":.78,finial:.4,lantern:.56}[t]??0)),a}function Me(e,t,n,r){let i=se(e^N.MATERIAL,t,n);return r===`thatch`?i.roof=`thatch`:r===`conical`?i.roof=`brick`:r===`barrel`&&(i.roof=`glass`),i}var Ne={cottage:{roofs:[`gable`],eaves:`gable`,ground:`plain`,cap:`none`,trim:{}},"cottage-row":{roofs:[`thatch`,`gable`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{}},farmhouse:{roofs:[`catslide`,`half-hip`],eaves:`gable`,ground:`plain`,cap:`finial`,trim:{}},"village-shop":{roofs:[`gable`,`catslide`],eaves:`gable`,ground:`shopfront`,cap:`none`,trim:{}},smithy:{roofs:[`shed`,`catslide`],eaves:`eave`,ground:`cart-door`,cap:`none`,trim:{}},"market-cross":{roofs:[`pyramid`],eaves:`gable`,ground:`arcade`,cap:`finial`,trim:{}},chapel:{roofs:[`gable`],eaves:`gable`,ground:`plain`,cap:`bellcote`,trim:{}},"parish-hall":{roofs:[`half-hip`,`gable`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{}},barn:{roofs:[`gable`,`catslide`],eaves:`gable`,ground:`cart-door`,cap:`none`,trim:{}},mill:{roofs:[`monitor`,`gable`],eaves:`eave`,ground:`cart-door`,cap:`none`,trim:{}},kiln:{roofs:[`conical`],eaves:`gable`,ground:`cart-door`,cap:`none`,trim:{},roofFactor:1.6},"boarding-house":{roofs:[`hip`,`mansard`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{cornice:!0}},townhouse:{roofs:[`mansard`,`gable`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{cornice:!0,stringCourse:!0}},"corner-shop":{roofs:[`mansard`,`gable`],eaves:`eave`,ground:`shopfront`,cap:`none`,trim:{cornice:!0}},"market-hall":{roofs:[`gable`,`hip`],eaves:`eave`,ground:`arcade`,cap:`none`,trim:{cornice:!0}},inn:{roofs:[`hip`,`mansard`],eaves:`eave`,ground:`shopfront`,cap:`none`,trim:{cornice:!0}},guildhall:{roofs:[`hip`,`mansard`],eaves:`eave`,ground:`portico`,cap:`cupola`,trim:{cornice:!0,quoins:!0}},library:{roofs:[`hip`,`mansard`],eaves:`eave`,ground:`portico`,cap:`cupola`,trim:{cornice:!0,quoins:!0}},schoolhouse:{roofs:[`gable`],eaves:`gable`,ground:`plain`,cap:`bellcote`,trim:{}},foundry:{roofs:[`sawtooth`],eaves:`eave`,ground:`cart-door`,cap:`none`,trim:{}},"rail-depot":{roofs:[`gable`],eaves:`eave`,ground:`arcade`,cap:`none`,trim:{}},workshop:{roofs:[`sawtooth`],eaves:`eave`,ground:`cart-door`,cap:`none`,trim:{}},"terrace-house":{roofs:[`parapet`,`mansard`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{cornice:!0,parapet:!0,stringCourse:!0}},tenement:{roofs:[`mansard`,`parapet`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{cornice:!0,stringCourse:!0}},"mansion-flat":{roofs:[`mansard`,`hip`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{cornice:!0,stringCourse:!0,quoins:!0}},"shopfront-block":{roofs:[`parapet`,`mansard`],eaves:`eave`,ground:`shopfront`,cap:`none`,trim:{cornice:!0,parapet:!0,stringCourse:!0}},hotel:{roofs:[`mansard`,`hip`],eaves:`eave`,ground:`shopfront`,cap:`lantern`,trim:{cornice:!0,stringCourse:!0,quoins:!0},roofFactor:1.3},arcade:{roofs:[`barrel`,`monitor`],eaves:`eave`,ground:`arcade`,cap:`none`,trim:{cornice:!0,parapet:!0}},bank:{roofs:[`parapet`,`hip`],eaves:`eave`,ground:`portico`,cap:`none`,trim:{cornice:!0,parapet:!0,quoins:!0}},institute:{roofs:[`hip`,`parapet`],eaves:`eave`,ground:`portico`,cap:`cupola`,trim:{cornice:!0,quoins:!0}},"town-hall":{roofs:[`hip`,`mansard`],eaves:`eave`,ground:`portico`,cap:`clock-tower`,trim:{cornice:!0,quoins:!0,stringCourse:!0},roofFactor:1.6},warehouse:{roofs:[`monitor`,`gable`],eaves:`eave`,ground:`cart-door`,cap:`none`,trim:{cornice:!0,parapet:!0}},works:{roofs:[`sawtooth`],eaves:`eave`,ground:`cart-door`,cap:`none`,trim:{parapet:!0}},terminus:{roofs:[`barrel`,`monitor`],eaves:`eave`,ground:`arcade`,cap:`none`,trim:{cornice:!0,parapet:!0}},field:{roofs:[`shed`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{},roofFactor:1.4},park:{roofs:[`hip`],eaves:`eave`,ground:`plain`,cap:`none`,trim:{},roofFactor:2.2},"signal-tower":{roofs:[`parapet`],eaves:`eave`,ground:`portico`,cap:`lantern`,trim:{cornice:!0,parapet:!0,quoins:!0},roofFactor:1.9}},Pe={data:`field`,style:`park`,config:`signal-tower`},Fe={farmhouse:`ell`,"parish-hall":`ell`,barn:`ell`,mill:`ell`,smithy:`ell`,guildhall:`ell`,library:`ell`,inn:`ell`,"rail-depot":`ell`,"mansion-flat":`setback`,tenement:`setback`,hotel:`setback`,bank:`setback`,institute:`setback`,"town-hall":`setback`,warehouse:`setback`};function Ie(e,t,n){let r=Fe[e];if(!r)return De;let i=w(t^N.MASSING);if(r===`setback`)return n<3?De:{kind:r,u0:.12,v0:.12,u1:.88,v1:.88,height:1.22,behind:!1};let a=Math.floor(i()*4),o=.46+i()*.12,s=a===0||a===3;return{kind:r,...a===0?{u0:.04,v0:.04,u1:.04+o,v1:.52}:a===1?{u0:.96-o,v0:.04,u1:.96,v1:.52}:a===2?{u0:.96-o,v0:.48,u1:.96,v1:.96}:{u0:.04,v0:.48,u1:.04+o,v1:.96},height:n<=1?.72:(n-1)/n,behind:s}}function Le(e,t){return e[Math.min(e.length-1,Math.floor(t()*e.length))]}function Re(e,t){let{w:n,h:r}=e.rect;return n>r*1.18?`x`:r>n*1.18?`y`:t()<.5?`x`:`y`}function ze(e,t){let n=Ne[e].roofs;return n.length===1||t()<Be[e]?n[0]:n[1]}var Be={townhouse:.55,"corner-shop":.55,"boarding-house":.7,inn:.7,library:.7,guildhall:.7,"market-hall":.65,"cottage-row":.6,farmhouse:.55,"village-shop":.65,smithy:.6,"parish-hall":.6,barn:.7,mill:.6,"terrace-house":.6,tenement:.55,"mansion-flat":.6,"shopfront-block":.65,hotel:.6,arcade:.7,bank:.6,institute:.6,"town-hall":.6,warehouse:.6,terminus:.65};function Ve(e){return/(?:^|[/_.-])(?:test|tests|spec|specs)(?:[/_.-]|$)/i.test(e)}var He={village:`parish-hall`,town:`guildhall`,city:`town-hall`};function Ue(e){let t=C(`town-1910:v1:${e.id}`),n=w(t),r=e.health?.zone??`residential`,i=M(e),a=ke[i],o=S(e),s;s=Pe[o]||(e.landmark?He[i]:Ve(e.id)&&r!==`industrial`?`schoolhouse`:Le(a[r],n));let c=Math.max(1,Math.min(5,e.levels??1)),l=Math.ceil(Math.sqrt(Math.max(1,e.buildingCount))),u=Math.max(1,Math.min(5,l+ +(n()<.45))),d=r===`industrial`,f=r===`commercial`,p=r===`civic`||e.landmark===!0,m=e.health?.churn??0,h=ze(s,n),g=Re(e,n),_=Ne[s],v=i===`city`?Math.max(1,Math.min(6,Math.round(u*1.4))):i===`village`?Math.min(3,u):u,y=d?1+Math.min(2,Math.floor(m/8)+ +(n()<.5)):s===`cottage`||s===`inn`||s===`boarding-house`||i===`village`&&!p?1+ +(n()<.25):0,b=p&&(e.landmark===!0||n()<.5),ee=_.cap===`cupola`&&!b?`none`:_.cap,te=y===0&&i===`city`&&!d&&c>=3?Math.max(1,Math.min(3,Math.floor(v/2))):y,ne=je(h,ee,te,_.roofFactor);return{archetype:s,use:o,frontage:Oe(t,_.ground),roof:h,ridge:g,storeys:c,bays:v,chimneys:te,dormers:h===`mansard`||h===`gable`&&c>=3?Math.min(3,Math.max(1,Math.floor(v/2))):0,awning:f&&s!==`market-hall`,cupola:b,clock:e.landmark===!0,sawteeth:h===`sawtooth`?Math.max(2,Math.min(5,v)):0,seed:t,band:i,eaves:_.eaves,ground:_.ground,cap:ee,trim:{...Ae,..._.trim},material:Me(t,i,d,h),massing:Ie(s,t,c),...ne===1?{}:{roofFactor:ne}}}function We(e,t){let n=C(`town-1910:symbol:v1:${e.id}`),r=w(n),i=e.kind.toLowerCase(),a=/class|interface|struct|enum|trait|type/.test(i),o=/module|namespace|package/.test(i),s=t.health?.zone===`industrial`,c=M(t),l=s?`industrial`:o?`civic`:a?`residential`:`commercial`,u=ke[c][l],d=e.height<.4?0:e.height<.72?1:2,f=u[Math.min(u.length-1,d)],p=ze(f,r),m=Math.max(1,Math.min(3,1+Math.round(e.height*2))),h=Math.max(1,Math.min(3,Math.ceil(Math.sqrt(Math.max(1,e.lines??1))/3))),g=Ne[f],_=g.cap===`clock-tower`?`cupola`:g.cap,v=Re(e,r),y=s||f===`cottage`||f===`farmhouse`||f===`inn`?1+ +(r()<.3):0,b=p===`sawtooth`?2+ +(r()<.4):0,ee=je(p,_,y,g.roofFactor);return{archetype:f,use:`code`,frontage:Oe(n,g.ground),roof:p,ridge:v,storeys:m,bays:h,chimneys:y,dormers:+(p===`mansard`&&e.height>.55),awning:g.ground===`shopfront`&&w(n^N.FRONTAGE)()<.6,cupola:_===`cupola`,clock:!1,sawteeth:b,seed:n,band:c,eaves:g.eaves,ground:g.ground,cap:_,trim:{...Ae,...g.trim},material:Me(n,c,s,p),massing:De,...ee===1?{}:{roofFactor:ee}}}function Ge(e){return e.archetype.replace(/-/g,` `)}function Ke(e){return`${e.band} ${Ge(e)}`}var qe=new WeakMap;function Je(e){let t=qe.get(e);if(t)return t;let n=new Map;for(let t of e.blocks)t.state!==`tombstoned`&&n.set(t.id,Ue(t));return qe.set(e,n),n}function Ye(e,t){let n=Je(e).get(t.id);if(n)return n;let r=Ue(t);return Je(e).set(t.id,r),r}function P(e,t){return{x:y(e,t.x),y:b(e,t.y),w:t.w*e.scale,h:t.h*e.scale}}function F(e,t,n,r,i,a){let o=Math.max(0,Math.min(a,r/2,i/2));e.beginPath(),e.moveTo(t+o,n),e.arcTo(t+r,n,t+r,n+i,o),e.arcTo(t+r,n+i,t,n+i,o),e.arcTo(t,n+i,t,n,o),e.arcTo(t,n,t+r,n,o),e.closePath()}var Xe=new Map;function Ze(e,t){let n=Xe.get(t);if(n!==void 0)return n;let r=null;try{let n=document.createElement(`canvas`);n.width=8,n.height=8;let i=n.getContext(`2d`);i&&(i.strokeStyle=t,i.lineWidth=1.2,i.beginPath(),i.moveTo(-2,10),i.lineTo(10,-2),i.stroke(),r=e.createPattern(n,`repeat`)??null)}catch{r=null}return Xe.set(t,r),r}var Qe=1.5,$e=2.5,et=6;function tt(e,t){return e.tier===`street`&&ie(t)}function nt(e,t){let n=t.palette,r=t.now??Date.now(),i=[];for(let e of t.model.blocks)x(t.cam,e.rect,t.viewW,t.viewH)&&i.push({b:e,r:P(t.cam,e.rect),age:t.ageLens?pe(e.lastTouchedAt??e.placedAt,r):void 0});if(t.tier!==`city`&&!t.ageLens)for(let n of i)rt(e,t,n);if(t.tier!==`city`){e.fillStyle=n.shadow;for(let{b:n,r}of i)n.state!==`live`&&!t.ageLens||n.phantom||r.w<et||tt(t,n)||(F(e,r.x+Qe,r.y+$e,r.w,r.h,Math.min(3,r.w/6)),e.fill())}for(let n of i)at(e,t,n)}function rt(e,t,n){let{b:r}=n,i=t.palette;if(r.state!==`live`||r.phantom||!r.lot||!r.health)return;let a=P(t.cam,r.lot);if(a.w<10)return;it(e,t,r,a);let{vibe:o,zone:s,maxSeverity:c}=r.health;s===`civic`?(e.fillStyle=i.sidewalk,F(e,a.x,a.y,a.w,a.h,3),e.fill(),e.strokeStyle=i.domeAccent,e.globalAlpha=.55,e.lineWidth=1,F(e,a.x+1.5,a.y+1.5,a.w-3,a.h-3,2),e.stroke(),e.globalAlpha=1):(o===`scruffy`||o===`blighted`)&&(e.fillStyle=i.earth,e.globalAlpha=o===`blighted`?.45:.3,F(e,a.x,a.y,a.w,a.h,3),e.fill(),e.globalAlpha=1,o===`blighted`&&c===`critical`&&(e.strokeStyle=i.crane,e.globalAlpha=.8,e.lineWidth=1,F(e,a.x,a.y,a.w,a.h,3),e.stroke(),e.globalAlpha=1))}function it(e,t,n,r){let i=t.palette,a=j(n);e.globalAlpha=.4,e.fillStyle=a<.25?i.orchard:a<.5?i.ground:i.sidewalk,F(e,r.x,r.y,r.w,r.h,3),e.fill(),e.globalAlpha=1;let o=M(n);if(!(o===`city`&&a>.78)){if(o===`village`){e.strokeStyle=i.hedge,e.lineWidth=1.6,e.lineCap=`round`,e.beginPath();for(let[t,n,i,a]of[[r.x,r.y,r.x+r.w,r.y],[r.x+r.w,r.y,r.x+r.w,r.y+r.h],[r.x+r.w,r.y+r.h,r.x,r.y+r.h],[r.x,r.y+r.h,r.x,r.y]]){let r=Math.max(1,Math.floor(Math.hypot(i-t,a-n)/5));for(let o=0;o<r;o++){let s=(o+.15)/r,c=(o+.85)/r;e.moveTo(t+(i-t)*s,n+(a-n)*s),e.lineTo(t+(i-t)*c,n+(a-n)*c)}}e.stroke(),e.lineCap=`butt`;return}e.strokeStyle=o===`town`?i.fence:i.curb,e.lineWidth=1,o===`town`&&e.setLineDash([2,2]),F(e,r.x,r.y,r.w,r.h,3),e.stroke(),e.setLineDash([])}}function at(e,t,n){let{b:r,r:i,age:a}=n,o=t.palette;if(r.state===`tombstoned`){lt(e,t,n);return}if(r.phantom){dt(e,t,n);return}if(r.state===`new`&&!t.ageLens){ut(e,t,n);return}let s=xe(r.lang,o,a),c=Math.min(3,i.w/6),l=Ye(t.model,r);if(!t.ageLens&&(l.archetype===`field`||l.archetype===`park`)){ot(e,t,n,l,s.roof);return}if(t.tier===`city`||i.w<et){e.fillStyle=s.roof,F(e,i.x,i.y,i.w,i.h,c),e.fill(),i.w>3&&(e.strokeStyle=o.blockStroke,e.lineWidth=.5,F(e,i.x,i.y,i.w,i.h,c),e.stroke());return}if(tt(t,r)){e.fillStyle=o.sidewalk,F(e,i.x,i.y,i.w,i.h,c),e.fill(),e.fillStyle=s.roof,e.globalAlpha=.28,F(e,i.x,i.y,i.w,i.h,c),e.fill(),e.globalAlpha=1,e.strokeStyle=o.blockStroke,e.lineWidth=.5,F(e,i.x,i.y,i.w,i.h,c),e.stroke();return}let u=Math.min(Math.max(2,Math.sqrt(Math.max(1,r.weight))*.15*t.cam.scale),8,i.h*.35);e.fillStyle=s.facade,F(e,i.x,i.y,i.w,i.h,c),e.fill(),e.fillStyle=s.roof,F(e,i.x,i.y,i.w,i.h-u,c),e.fill(),e.strokeStyle=s.edge,e.lineWidth=1,e.beginPath(),e.moveTo(i.x+c,i.y+.5),e.lineTo(i.x+i.w-c,i.y+.5),e.stroke(),t.ageLens||st(e,t,n,i.h-u,s,l)}function ot(e,t,n,r,i){let{r:a}=n,o=t.palette,s=Math.min(3,a.w/6);if(r.archetype===`field`){if(e.fillStyle=o.farm.crops[(r.seed>>>4)%4],F(e,a.x,a.y,a.w,a.h,s),e.fill(),t.tier!==`city`&&a.w>=10){let n=Math.max(3,1.6*t.cam.scale),i=r.ridge===`x`;e.strokeStyle=o.farm.furrow,e.globalAlpha=.35,e.lineWidth=.8,e.beginPath();let s=i?a.h:a.w;for(let t=n/2;t<s;t+=n)i?(e.moveTo(a.x+1,a.y+t),e.lineTo(a.x+a.w-1,a.y+t)):(e.moveTo(a.x+t,a.y+1),e.lineTo(a.x+t,a.y+a.h-1));e.stroke(),e.globalAlpha=1}return}if(e.fillStyle=o.park.lawn,F(e,a.x,a.y,a.w,a.h,s),e.fill(),t.tier===`city`||a.w<10)return;let c=Math.max(1,Math.min(a.w,a.h)*.1);e.fillStyle=o.park.path,e.fillRect(a.x,a.y+a.h/2-c/2,a.w,c),e.fillRect(a.x+a.w/2-c/2,a.y,c,a.h);let l=Math.min(a.w,a.h)*.3;e.fillStyle=i,e.globalAlpha=.85,e.fillRect(a.x+a.w/2-l/2,a.y+a.h/2-l/2,l,l),e.globalAlpha=1}function st(e,t,n,r,i,a){let{r:o}=n;if(a.roof===`sawtooth`&&r>=12){ct(e,t,n,r,i.facade,i.edge);return}if(o.w<14||r<10)return;let s=a.ridge===`x`?o.w>=r:o.w<r,c=o.x+o.w/2,l=o.y+r/2,u=(t,n,r,a,o=1)=>{e.strokeStyle=i.edge,e.lineWidth=o,e.beginPath(),e.moveTo(t,n),e.lineTo(r,a),e.stroke()},d=t=>{e.globalAlpha=.22,s?(e.fillStyle=i.edge,e.fillRect(o.x+1,o.y+1,o.w-2,r*t-1),e.fillStyle=i.facade,e.fillRect(o.x+1,o.y+r*t,o.w-2,r*(1-t)-1)):(e.fillStyle=i.edge,e.fillRect(o.x+1,o.y+1,o.w*t-1,r-2),e.fillStyle=i.facade,e.fillRect(o.x+o.w*t,o.y+1,o.w*(1-t)-1,r-2)),e.globalAlpha=1},f=(e=1)=>{let t=(1-e)/2;s?u(o.x+1+(o.w-2)*t,l,o.x+o.w-1-(o.w-2)*t,l):u(c,o.y+1+(r-2)*t,c,o.y+r-1-(r-2)*t)},p=e=>{let t=(1-e)/2,[n,i]=s?[{x:o.x+1+(o.w-2)*t,y:l},{x:o.x+o.w-1-(o.w-2)*t,y:l}]:[{x:c,y:o.y+1+(r-2)*t},{x:c,y:o.y+r-1-(r-2)*t}];u(n.x,n.y,o.x+1,o.y+1,.7),u(n.x,n.y,s?o.x+1:o.x+o.w-1,s?o.y+r-1:o.y+1,.7),u(i.x,i.y,o.x+o.w-1,o.y+r-1,.7),u(i.x,i.y,s?o.x+o.w-1:o.x+1,s?o.y+1:o.y+r-1,.7)},m=t=>{e.globalAlpha=.3,e.fillStyle=i.edge,e.fillRect(o.x+o.w*t,o.y+r*t,o.w*(1-t*2),r*(1-t*2)),e.globalAlpha=1};switch(a.roof){case`gable`:d(.5),f();break;case`catslide`:d(.34),s?u(o.x+1,o.y+r*.34,o.x+o.w-1,o.y+r*.34):u(o.x+o.w*.34,o.y+1,o.x+o.w*.34,o.y+r-1);break;case`thatch`:d(.5),f(.8),e.strokeStyle=i.facade,e.globalAlpha=.5,e.lineWidth=Math.max(2,Math.min(4,r*.16)),F(e,o.x+1.5,o.y+1.5,o.w-3,r-3,Math.min(r,o.w)/2),e.stroke(),e.globalAlpha=1;break;case`hip`:d(.5),f(.5),p(.5);break;case`half-hip`:d(.5),f(.76),p(.76);break;case`shed`:d(.82);break;case`mansard`:m(.24),p(.5);break;case`parapet`:e.strokeStyle=i.edge,e.lineWidth=1,e.strokeRect(o.x+1.5,o.y+1.5,o.w-3,r-3),m(.18);break;case`monitor`:{d(.5);let t=Math.max(2,r*.22);e.globalAlpha=.4,e.fillStyle=i.edge,s?e.fillRect(o.x+2,l-t/2,o.w-4,t):e.fillRect(c-t/2,o.y+2,t,r-4),e.globalAlpha=1,f();break}case`pyramid`:u(o.x+1,o.y+1,o.x+o.w-1,o.y+r-1,.8),u(o.x+o.w-1,o.y+1,o.x+1,o.y+r-1,.8);break;case`conical`:{let t=Math.min(o.w,r)*.42;e.strokeStyle=i.edge,e.lineWidth=.9;for(let n of[1,.45])e.beginPath(),e.arc(c,l,t*n,0,Math.PI*2),e.stroke();break}case`barrel`:e.strokeStyle=i.edge,e.lineWidth=.9,e.beginPath();for(let t of[.3,.5,.7])s?(e.moveTo(o.x+2,o.y+r*t),e.lineTo(o.x+o.w-2,o.y+r*t)):(e.moveTo(o.x+o.w*t,o.y+2),e.lineTo(o.x+o.w*t,o.y+r-2));e.stroke();break;default:d(.5),f();break}if(a.band===`city`&&a.bays>1&&o.w>=20){e.strokeStyle=i.facade,e.globalAlpha=.55,e.lineWidth=.7,e.beginPath();for(let t=1;t<Math.min(5,a.bays);t++){let n=t/a.bays;s?(e.moveTo(o.x+o.w*n,o.y+1),e.lineTo(o.x+o.w*n,o.y+r-1)):(e.moveTo(o.x+1,o.y+r*n),e.lineTo(o.x+o.w-1,o.y+r*n))}e.stroke(),e.globalAlpha=1}if(a.chimneys>0&&r>=12){e.fillStyle=t.palette.masonry;for(let t=0;t<Math.min(3,a.chimneys);t++){let n=a.chimneys===1?.5:.3+t/(a.chimneys-1)*.4,i=s?o.x+o.w*n:c,u=s?l:o.y+r*n;e.fillRect(i-1,u-1,2.2,2.2)}}if(a.cupola&&r>=12){let n=Math.min(o.w,r)*.16;e.fillStyle=t.palette.domeAccent,e.beginPath(),e.arc(c,l,n,0,Math.PI*2),e.fill(),e.strokeStyle=i.facade,e.lineWidth=1,e.stroke()}}function ct(e,t,n,r,i,a){let{b:o,r:s}=n;e.fillStyle=i,e.globalAlpha=.3;for(let t=1;t<=3;t++){let n=s.y+r*t/4;e.fillRect(s.x+1,n,s.w-2,Math.max(1.5,r*.1))}e.globalAlpha=1;let c=w(C(o.id));e.fillStyle=a;for(let t=0;t<2;t++){let t=2+c()*2,n=s.x+2+c()*Math.max(1,s.w-t-4),i=s.y+2+c()*Math.max(1,r-t-4);e.fillRect(n,i,t,t)}}function lt(e,t,n){let{b:r,r:i}=n,a=t.palette,o=Math.min(3,i.w/6);if(e.fillStyle=t.ageLens?a.tombstone:a.earth,e.globalAlpha=t.ageLens?.4:.7,F(e,i.x,i.y,i.w,i.h,o),e.fill(),e.globalAlpha=1,t.tier!==`city`&&i.w>=10&&!t.ageLens){let t=w(C(r.id)),n=4+Math.floor(t()*4);e.fillStyle=a.rubble;for(let r=0;r<n;r++){let n=Math.min(5,Math.max(1,(.06+.08*t())*Math.min(i.w,i.h))),r=i.x+i.w*(.12+.76*t()),a=i.y+i.h*(.12+.76*t());e.fillRect(r,a,n,n)}e.strokeStyle=a.blockStroke,e.globalAlpha=.6,e.setLineDash([3,3]),F(e,i.x,i.y,i.w,i.h,o),e.stroke(),e.setLineDash([]),e.globalAlpha=1}}function ut(e,t,n){let{b:r,r:i}=n,a=t.palette,o=Math.min(3,i.w/6);if(t.tier===`city`||i.w<et){e.fillStyle=a.newBlock,F(e,i.x,i.y,i.w,i.h,o),e.fill();return}if(e.fillStyle=a.earth,F(e,i.x,i.y,i.w,i.h,o),e.fill(),e.strokeStyle=a.newBlock,e.lineWidth=1.5,e.setLineDash([4,3]),F(e,i.x,i.y,i.w,i.h,o),e.stroke(),e.setLineDash([]),t.tier===`street`&&i.w>=14){let t=w(C(r.id)),n=i.x+i.w*(.25+.5*t()),o=i.y+i.h*.85,s=i.y+i.h*.2,c=i.w*.4*(t()<.5?-1:1);e.strokeStyle=a.crane,e.lineWidth=1.5,e.beginPath(),e.moveTo(n,o),e.lineTo(n,s),e.lineTo(n+c,s),e.moveTo(n+c*.8,s),e.lineTo(n+c*.8,s+i.h*.15),e.stroke()}}function dt(e,t,n){let{b:r,r:i}=n,a=t.palette,o=Math.min(3,i.w/6);e.fillStyle=xe(r.lang,a).roof,e.globalAlpha=.25,F(e,i.x,i.y,i.w,i.h,o),e.fill(),e.globalAlpha=1;let s=Ze(e,a.dark?`#8b8f99`:`#8a7f64`);s&&(e.fillStyle=s,F(e,i.x,i.y,i.w,i.h,o),e.fill()),e.strokeStyle=a.blockStroke,e.setLineDash([4,3]),F(e,i.x,i.y,i.w,i.h,o),e.stroke(),e.setLineDash([])}function ft(e,t){let n=t.palette,r=(n,r,i)=>{let a=t.model.blocks.find(e=>e.id===n);if(!a||!x(t.cam,a.rect,t.viewW,t.viewH))return;let o=P(t.cam,a.rect);e.strokeStyle=r,e.lineWidth=i,F(e,o.x,o.y,o.w,o.h,Math.min(3,o.w/6)),e.stroke()};t.hoverId&&t.hoverId!==t.selectedId&&r(t.hoverId,n.hover,1.5),t.selectedId&&r(t.selectedId,n.selected,2)}function pt(e,t){if(t.tier!==`street`)return;let n=t.palette;for(let r of t.model.buildings){if(!x(t.cam,r.rect,t.viewW,t.viewH))continue;let i=P(t.cam,r.rect);if(i.w<1.5||i.h<1.5)continue;if(i.w<4||i.h<6){e.fillStyle=n.building,e.globalAlpha=.35+.55*r.height,e.fillRect(i.x,i.y,i.w,i.h);continue}let a=Math.min(Math.max(1.5,r.height*.35*i.h),6);e.globalAlpha=.5+.45*r.height,e.fillStyle=n.buildingFacade,e.fillRect(i.x,i.y,i.w,i.h),e.fillStyle=n.building,e.fillRect(i.x,i.y,i.w,i.h-a);let o=i.h-a;if(i.w>10&&o>8){let t=w(C(r.id));if(r.kind===`class`||r.kind===`interface`||r.kind===`struct`){e.strokeStyle=n.buildingFacade,e.lineWidth=1;let r=i.y+o*(.35+.3*t());e.beginPath(),e.moveTo(i.x+1,r),e.lineTo(i.x+i.w-1,r),e.stroke()}else if(r.kind===`function`||r.kind===`method`){let r=1+ +(t()<.4);e.fillStyle=n.buildingFacade;for(let n=0;n<r;n++){let n=2+t()*2,r=i.x+2+t()*Math.max(1,i.w-n-4),a=i.y+2+t()*Math.max(1,o-n-4);e.fillRect(r,a,n,n)}}}}e.globalAlpha=1}var mt=[`tree1`,`tree2`,`tree3`];function ht(e){let t=e.lot;if(!t||e.phantom||e.state===`tombstoned`)return[];let n=e.health?.vibe??`plain`;if(n===`plain`)return[];let r=w(C(e.id)),i=e.rect,a=[],o=()=>{let e=r(),n=t.x+1+r()*Math.max(.5,t.w-2),a=t.y+1+r()*Math.max(.5,t.h-2);return e<.45?{x:n,y:(i.y+i.h+t.y+t.h)/2}:e<.6?{x:n,y:(t.y+i.y)/2}:e<.8?{x:(t.x+i.x)/2,y:a}:{x:(i.x+i.w+t.x+t.w)/2,y:a}},s=(e,t,n)=>{let{x:i,y:s}=o();a.push({sprite:e,x:i,y:s,size:t+r()*(n-t)})},c=()=>s(mt[Math.floor(r()*mt.length)],2.2,3.4);switch(n){case`lush`:{let e=3+Math.floor(r()*3);for(let t=0;t<e;t++)c();let t=1+ +(r()<.5);for(let e=0;e<t;e++)s(`shrub`,1.5,2.2);break}case`tidy`:{let e=1+ +(r()<.5);for(let t=0;t<e;t++)c();break}case`scruffy`:{s(`dryPatch`,2.5,4);let e=1+ +(r()<.5);for(let t=0;t<e;t++)s(`weed`,1.6,2.4);break}case`blighted`:{s(`dryPatch`,2.5,4),s(`deadTree`,2.6,3.6);let e=1+ +(r()<.5);for(let t=0;t<e;t++)s(`weed`,1.6,2.4);break}}return a}var gt=new WeakMap;function _t(e){let t=gt.get(e);if(t)return t;let n=new Map;for(let t of e.blocks){let e=ht(t);e.length&&n.set(t.id,e)}return gt.set(e,n),n}var vt=3e3,yt=6e3,bt=14;function xt(e,t,n){if(!n||t.tier===`city`||t.ageLens||t.tier===`district`&&t.model.blocks.length>yt)return;let r=_t(t.model);if(r.size===0)return;let i=vt;for(let a of t.model.blocks){let o=r.get(a.id);if(!o||o.length===0)continue;let s=a.lot??a.rect;if(x(t.cam,s,t.viewW,t.viewH)&&!(t.tier===`district`&&s.w*t.cam.scale<=bt))for(let r of o){let a=r.size*t.cam.scale;if(a<2.5)continue;if(i--<=0)return;let o=n.index[r.sprite]*n.cell;e.drawImage(n.canvas,o,0,n.cell,n.cell,y(t.cam,r.x)-a/2,b(t.cam,r.y)-a/2,a,a)}}}var St=[{carriageway:.55,sidewalk:0,surface:`dirt`,verge:!0,lamps:!1,trees:!1,trolley:!1,carts:0,walkers:!1},{carriageway:.55,sidewalk:0,surface:`cobble`,verge:!0,lamps:!1,trees:!1,trolley:!1,carts:0,walkers:!1},{carriageway:.55,sidewalk:0,surface:`paved`,verge:!0,lamps:!1,trees:!1,trolley:!1,carts:0,walkers:!1},{carriageway:.8,sidewalk:0,surface:`dirt`,verge:!0,lamps:!1,trees:!1,trolley:!1,carts:1,walkers:!1},{carriageway:.8,sidewalk:0,surface:`paved`,verge:!1,lamps:!1,trees:!1,trolley:!1,carts:1,walkers:!1},{carriageway:.64,sidewalk:.16,surface:`paved`,verge:!1,lamps:!0,trees:!1,trolley:!1,carts:1.5,walkers:!0},{carriageway:.72,sidewalk:.14,surface:`paved`,verge:!1,lamps:!0,trees:!0,trolley:!1,carts:2,walkers:!0},{carriageway:.72,sidewalk:.14,surface:`paved`,verge:!1,lamps:!0,trees:!0,trolley:!0,carts:2,walkers:!0}],Ct=[5,4,2,1];function wt(e){return e.grade===void 0?Ct[Math.max(0,Math.min(3,e.tier))]:Math.max(0,Math.min(7,e.grade))}var Tt=22,Et=34,Dt=18,Ot=26,kt=48,At=[`tree1`,`tree2`],jt=.0055,Mt=.012,Nt=.0022;function Pt(e,t,n){let r=t-e,i=Math.min(kt,Math.floor(r/n));if(i<=0)return[];let a=r/i,o=[];for(let t=0;t<i;t++)o.push(e+a*(t+.5));return o}function Ft(e){let t=e.rect,n=t.w>=t.h,r=n?t.x:t.y,i=n?t.x+t.w:t.y+t.h,a=n?t.h:t.w,o=n?t.y+t.h/2:t.x+t.w/2,s=wt(e),c=St[s];return{street:e,grade:s,spec:c,horizontal:n,a0:r,a1:i,center:o,width:a,carriagewayWidth:a*c.carriageway,sidewalkWidth:a*c.sidewalk,c0:r,c1:i,r0:r,r1:i}}var It=20,Lt=.3;function Rt(e){let t=e.filter(e=>e.horizontal),n=e.filter(e=>!e.horizontal);for(let r of e){let e=r.horizontal?n:t;for(let t of[-1,1]){let n=null,i=t===1?r.a1:r.a0,a=It+r.width/2;for(let o of e){if(r.center<o.a0-a||r.center>o.a1+a)continue;let e=o.center-t*(o.width/2),s=t===1?e-i:i-e;s<-o.width||s>It||(!n||s<n.gap)&&(n={p:o,gap:s})}if(!n)continue;let{p:o}=n,s=r.center<o.a0+r.width||r.center>o.a1-r.width,c=o.carriagewayWidth/2,l=s?o.center+t*c:o.center-t*c+t*Lt,u=s?o.center+t*(o.width/2):o.center-t*(o.width/2);t===1?(r.c1=Math.max(r.c1,l),r.r1=Math.max(r.r1,u)):(r.c0=Math.min(r.c0,l),r.r0=Math.min(r.r0,u))}}}function zt(e){let{street:t,grade:n,spec:r,horizontal:i,center:a,width:o,carriagewayWidth:s,sidewalkWidth:c}=e,l=e.c0,u=e.c1,d=(e,t)=>i?{x:e,y:a+t}:{x:a+t,y:e},f=(e,t,n,r)=>i?{x:e,y:a+n,w:t-e,h:r-n}:{x:a+n,y:e,w:r-n,h:t-e},p=s/2,m=f(l,u,-p,p),h=f(e.r0,e.r1,-o/2,o/2),g=c>0?[f(e.r0,e.r1,-p-c,-p),f(e.r0,e.r1,p,p+c)]:null,_=Math.min(1.6,s*.45),v=r.trolley?[{a:d(l,-_/2),b:d(u,-_/2)},{a:d(l,_/2),b:d(u,_/2)}]:null,y=w(C(`street-life:${t.id}`)),b=p+c,ee=r.lamps?Pt(e.r0,e.r1,Tt).map((e,t)=>d(e,(t%2==0?-1:1)*b*.9)):[],te=r.trolley?Pt(e.r0,e.r1,Et).map(e=>d(e,b*.85)):[],ne=r.trees?Pt(e.r0,e.r1,Dt).map((e,t)=>({...d(e+(y()-.5)*3,(t%2==0?1:-1)*b*.6),size:2+y()*.8,sprite:At[Math.floor(y()*At.length)]})):[],re=[],x=u-l;if(r.trolley&&x>=40){let e=1+Math.floor(x/260);for(let t=0;t<e;t++)re.push({kind:`trolley`,phase:y(),speed:Mt*(.9+y()*.2),dir:t%2==0?1:-1,cross:0})}if(r.carts>0&&x>=24){let e=Math.min(5,Math.round(x/80*r.carts));for(let t=0;t<e;t++){let e=y()<.5?1:-1;re.push({kind:`cart`,phase:y(),speed:jt*(.8+y()*.4),dir:e,cross:e*p*.45})}}if(r.walkers&&g&&x>=Ot){let e=Math.min(8,Math.floor(x/Ot));for(let t=0;t<e;t++){let e=y()<.5?-1:1;re.push({kind:`walker`,phase:y(),speed:Nt*(.7+y()*.6),dir:y()<.5?1:-1,cross:e*(p+c/2)})}}return{street:t,grade:n,spec:r,horizontal:i,a0:l,a1:u,length:x,center:a,width:o,carriagewayWidth:s,sidewalkWidth:c,reservation:h,carriageway:m,sidewalks:g,rails:v,gauge:_,lamps:ee,poles:te,trees:ne,vehicles:re}}var Bt=new WeakMap;function Vt(e){let t=Bt.get(e);if(t)return t;let n=(e.streets??[]).map(Ft);Rt(n);let r=n.map(zt),i={streets:r,animated:r.filter(e=>e.vehicles.length>0)};return Bt.set(e,i),i}function Ht(e,t){switch(e.spec.surface){case`dirt`:return t.dirtLane;case`cobble`:return t.cobble;default:return e.grade>=5?t.pavementAvenue:e.grade>=3?t.pavementStreet:t.pavementLane}}function Ut(e,t,n){let r=((n*t.speed+t.phase*e.length)%e.length%e.length+e.length)%e.length;return t.dir===1?e.a0+r:e.a1-r}function Wt(e,t,n){return e.horizontal?{x:t,y:e.center+n}:{x:e.center+n,y:t}}function Gt(e,t){let{model:n,palette:r,viewW:i,viewH:a}=t;e.fillStyle=r.ground,e.fillRect(0,0,i,a);let o=new Set;for(let e of n.districts)e.parentId&&o.add(e.parentId);Kt(e,t,o),qt(e,t),Jt(e,t,o)}function Kt(e,t,n){let{cam:r,model:i,palette:a,viewW:o,viewH:s}=t;e.fillStyle=a.districtFill;for(let t of i.districts){if(n.has(t.id)||!x(r,t.rect,o,s))continue;let{x:i,y:a,w:c,h:l}=P(r,t.rect);c<6||l<6||(e.globalAlpha=.9,F(e,i,a,c,l,6),e.fill())}e.globalAlpha=1}function qt(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t,s=Vt(r);if(s.streets.length===0)return;let c=s.streets.filter(e=>x(n,e.reservation,a,o)),l=t=>{let r=P(n,t);e.fillRect(r.x,r.y,r.w,r.h)};if(t.tier===`city`){for(let t of c)t.street.tier>1||(e.fillStyle=Ht(t,i),l(t.carriageway));return}let u=Ee(r),d=e=>e.sidewalks!==null&&e.sidewalkWidth*n.scale>=1.2;e.fillStyle=i.street.verge;for(let e of c){let t=e.street.districtId?u.get(e.street.districtId):void 0;!e.spec.verge||t===`city`||l(e.reservation)}e.fillStyle=i.sidewalk;for(let e of c)!e.sidewalks||!d(e)||(l(e.sidewalks[0]),l(e.sidewalks[1]));let f=[...c].sort((e,t)=>e.grade-t.grade||t.street.tier-e.street.tier);for(let t of f)e.fillStyle=Ht(t,i),l(t.sidewalks&&!d(t)?t.reservation:t.carriageway);e.strokeStyle=i.street.rail,e.beginPath();for(let t of c){if(!t.rails)continue;let r=t.gauge*n.scale>=2.4;e.lineWidth=r?Math.max(.7,.26*n.scale):1;let i=r?t.rails:[{a:Wt(t,t.a0,0),b:Wt(t,t.a1,0)}];for(let t of i)e.moveTo(y(n,t.a.x),b(n,t.a.y)),e.lineTo(y(n,t.b.x),b(n,t.b.y))}e.stroke()}function Jt(e,t,n){let{cam:r,model:i,palette:a,tier:o,viewW:s,viewH:c}=t;for(let t of i.districts){if(!x(r,t.rect,s,c))continue;let{x:i,y:l,w:u,h:d}=P(r,t.rect);u<6||d<6||(n.has(t.id)?(e.strokeStyle=a.districtStroke,e.lineWidth=Math.max(.5,Math.min(2,3-t.depth*.4)),F(e,i,l,u,d,6),e.stroke()):(o!==`city`&&u>18&&d>18&&(e.strokeStyle=a.sidewalk,e.lineWidth=3,F(e,i+2,l+2,u-4,d-4,5),e.stroke()),e.strokeStyle=a.curb,e.lineWidth=1,F(e,i,l,u,d,6),e.stroke()))}}var Yt={info:.78,low:.86,medium:.96,high:1.08,critical:1.18};function Xt(e){let t=Math.max(0,Math.log2(Math.max(1,e)))*.52;return .82+Math.min(1.25,t)}function Zt(e){let t=e.health?.findings??0;if(e.state!==`live`||e.phantom||t<=0)return null;let n=e.health?.maxSeverity??`info`;return{findings:t,severity:n,flameCount:Math.min(3,1+Math.floor(Math.log2(t))),smokeCount:Math.min(7,3+Math.floor(Math.log2(t+1))),scale:Yt[n]+Math.min(.22,Math.log2(t)*.07),severe:n===`critical`||n===`high`}}function Qt(e){let t=null,n=-1;for(let r of e){let e=r.lines??r.height*1e3;e>n&&(t=r,n=e)}return t}function $t(e,t,n,r,i,a,o=1,s=0){let c=n.scale*o,l=w(C(`${a}:issue-marker`)),u=10*c,d=i+.5;e.save(),e.lineJoin=`round`,e.fillStyle=t.districtLabel;for(let t=n.smokeCount-1;t>=0;t--){let t=l(),i=tn(s*(16e-5+l()*55e-6)+t),a=(2.1+i*2.7+l()*.45)*c,o=(l()-.5)*4.5*c,f=Math.sin(s*.00125+t*Math.PI*2)*(1.4+i*3.2)*c,p=r+o+f,m=d-u-(3.5+i*22)*c,h=Math.sin(i*Math.PI),g=(n.severe?.38:.3)*h,_=l()*Math.PI*2;for(let t=0;t<3;t++){let n=_+t*Math.PI*2/3,r=a*(.62+l()*.15);e.globalAlpha=g*(.78+t*.08),e.beginPath(),e.arc(p+Math.cos(n)*a*.42,m+Math.sin(n)*a*.3,r,0,Math.PI*2),e.fill()}}let f=4.2*c;for(let i=0;i<n.flameCount;i++){let a=r+(i-(n.flameCount-1)/2)*f+(l()-.5)*1.3*c,o=l()*Math.PI*2,p=.008+l()*.005,m=Math.sin(s*p+o),h=Math.sin(s*p*1.9+o*.7),g=u*(.82+l()*.18+m*.1),_=(3.3+l()*1.1)*c,v=(m*.34+h*.14)*_;e.globalAlpha=n.severe?.96:.86,e.fillStyle=t.awning,en(e,a,d,_,g,v),e.fill(),e.globalAlpha=.96,e.fillStyle=t.crane,en(e,a,d-.25*c,_*.66,g*.72,v*.68),e.fill(),e.globalAlpha=.98,e.fillStyle=t.windowLit,en(e,a,d-.45*c,_*.34,g*.44,v*.42),e.fill()}e.restore()}function en(e,t,n,r,i,a){e.beginPath(),e.moveTo(t-r/2,n),e.bezierCurveTo(t-r*.62,n-i*.35,t-r*.16+a*.3,n-i*.7,t+a,n-i),e.bezierCurveTo(t+r*.15+a*.35,n-i*.62,t+r*.62,n-i*.3,t+r/2,n),e.closePath()}function tn(e){return e-Math.floor(e)}function nn(e,t){if(t.tier===`city`||t.ageLens)return;let n=new Map;if(t.tier===`street`)for(let e of t.model.buildings){let t=n.get(e.blockId);t?t.push(e):n.set(e.blockId,[e])}for(let r of t.model.blocks){if(!x(t.cam,r.rect,t.viewW,t.viewH))continue;let i=Zt(r);if(!i)continue;let a=Qt(n.get(r.id)??[]),o=P(t.cam,a?.rect??r.rect);$t(e,t.palette,i,o.x+o.w/2,o.y,r.id,Xt(t.cam.scale),t.animationTime??0)}}function rn(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t,s=r.districts.some(e=>e.displayLabel!==void 0);for(let t of r.districts){if(s&&t.displayLabel===void 0||!x(n,t.rect,a,o))continue;let{x:r,y:c,w:l,h:u}=P(n,t.rect);if(l<=60||u<=24)continue;let d=t.displayLabel??t.label;if(e.fillStyle=i.districtLabel,e.font=`${t.depth<=1?13:11}px ui-sans-serif, system-ui, sans-serif`,e.textBaseline=`top`,t.labelPlate){let r=P(n,t.labelPlate);e.fillText(d,r.x+2,r.y+1,Math.max(20,r.w))}else e.fillText(d,r+6,c+5,l-12)}if(t.tier===`street`){e.fillStyle=i.label,e.font=`11px ui-sans-serif, system-ui, sans-serif`,e.textBaseline=`bottom`;for(let t of r.blocks){if(t.state===`tombstoned`)continue;let r=t.rect.w*n.scale;if(r<44||!x(n,t.rect,a,o))continue;let{x:i,y:s}=P(n,t.rect);e.fillText(t.label,i+2,s-2,r)}}}var an={added:`#3fb950`,modified:`#d29922`,deleted:`#f85149`,renamed:`#a371f7`},on=`#58a6ff`;function sn(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t;if(!r.overlay||r.overlay.changedBlocks.length===0)return;let s=new Map(r.overlay.changedBlocks.map(e=>[e.blockId,e])),c=t.affectedIds,l=new Map(r.blocks.map(e=>[e.id,e]));if(e.fillStyle=i.ground,e.globalAlpha=.62,e.fillRect(0,0,a,o),e.globalAlpha=1,c&&c.size>0)for(let t of c){if(s.has(t))continue;let r=l.get(t);if(!r||!x(n,r.rect,a,o))continue;let i=P(n,r.rect),c=i.x,u=i.y,d=Math.max(3,i.w),f=Math.max(3,i.h),p=Math.min(3,d/6);e.fillStyle=on,e.globalAlpha=.18,F(e,c,u,d,f,p),e.fill(),e.globalAlpha=.7,e.strokeStyle=on,e.lineWidth=1,F(e,c,u,d,f,p),e.stroke(),e.globalAlpha=1}for(let t of r.blocks){let r=s.get(t.id);if(!r||!x(n,t.rect,a,o))continue;let i=an[r.change]??`#888888`,c=P(n,t.rect),l=c.x,u=c.y,d=Math.max(3,c.w),f=Math.max(3,c.h),p=Math.min(3,d/6);e.fillStyle=i,e.globalAlpha=t.phantom?.45:.85,F(e,l,u,d,f,p),e.fill(),e.globalAlpha=1,e.save(),e.shadowColor=i,e.shadowBlur=8,e.strokeStyle=i,e.lineWidth=2,t.phantom&&e.setLineDash([4,3]),F(e,l-1,u-1,d+2,f+2,p+1),e.stroke(),e.restore()}}var cn=[1,1.15,1.35,1.6],ln=.5,un=6e3,dn=80,fn=(e,t,n)=>e<t?t:e>n?n:e,pn=(e,t)=>`${Math.round(e*10)/10},${Math.round(t*10)/10}`,mn=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),hn=e=>cn[e]??1,gn=(e,t)=>e.axis===`h`?{x:t,y:e.line}:{x:e.line,y:t},_n=20;function vn(e){let t=e.streets;if(!t||t.length===0||t.length>un)return null;let n=[];for(let e of t){let{x:t,y:r,w:i,h:a}=e.rect;i>=a?n.push({axis:`h`,line:r+a/2,min:t,max:t+i,tier:e.tier}):n.push({axis:`v`,line:t+i/2,min:r,max:r+a,tier:e.tier})}let r=n.map(e=>new Set([e.min,e.max])),i=[],a=[];n.forEach((e,t)=>(e.axis===`h`?i:a).push(t));for(let e of i){let t=n[e];for(let i of a){let a=n[i];a.line>=t.min-ln&&a.line<=t.max+ln&&t.line>=a.min-ln&&t.line<=a.max+ln&&(r[e].add(fn(a.line,t.min,t.max)),r[i].add(fn(t.line,a.min,a.max)))}}let o=[],s=(e,t)=>{let s=n[e],c=gn(s,t),l=s.axis===`h`?a:i,u=null;for(let e of l){let r=n[e],i=s.axis===`h`?c.y:c.x;if(i<r.min-ln||i>r.max+ln)continue;let a=Math.abs(r.line-t);a<=ln||a>_n||(!u||a<u.w)&&(u={proj:s.axis===`h`?{x:r.line,y:c.y}:{x:c.x,y:r.line},w:a,ti:e})}if(u){let e=n[u.ti],t=e.axis===`h`?u.proj.x:u.proj.y;r[u.ti].add(fn(t,e.min,e.max)),o.push({a:c,b:u.proj,w:u.w*hn(Math.max(s.tier,e.tier))})}};n.forEach((e,t)=>{e.max-e.min<.1||(s(t,e.min),s(t,e.max))});let c=new Map,l=new Map,u=[],d=(e,t,n)=>{(c.get(e)??c.set(e,[]).get(e)).push({to:t,w:n}),(c.get(t)??c.set(t,[]).get(t)).push({to:e,w:n})};n.forEach((e,t)=>{let n=[...r[t]].sort((e,t)=>e-t);if(e.max-e.min<.1){u.push({seg:e,pts:n});return}for(let t of n){let n=gn(e,t);l.set(pn(n.x,n.y),n)}let i=hn(e.tier);for(let t=0;t<n.length-1;t++){let r=gn(e,n[t]),a=gn(e,n[t+1]),o=(n[t+1]-n[t])*i;o>0&&d(pn(r.x,r.y),pn(a.x,a.y),o)}u.push({seg:e,pts:n})});for(let e of o)d(pn(e.a.x,e.a.y),pn(e.b.x,e.b.y),e.w);return{adj:c,coord:l,segs:u}}function yn(e,t){let n=null,r=1/0;return e.segs.forEach((e,i)=>{let a=e.seg;if(a.max-a.min<.1)return;let o=fn(a.axis===`h`?t.x:t.y,a.min,a.max),s=a.axis===`h`?{x:o,y:a.line}:{x:a.line,y:o},c=Math.hypot(t.x-s.x,t.y-s.y);c<r&&(r=c,n={segIndex:i,seg:a,along:o,point:s})}),n}function bn(e,t){let{seg:n,pts:r}=e,i=hn(n.tier),a=0;for(;a<r.length-2&&r[a+1]<t;)a++;let o=r[a],s=r[a+1]??o,c=e=>n.axis===`h`?pn(e,n.line):pn(n.line,e),l=[{key:c(o),w:Math.abs(t-o)*i}];return s!==o&&l.push({key:c(s),w:Math.abs(s-t)*i}),l}var xn=class{a=[];get size(){return this.a.length}push(e,t){let n=this.a;n.push([e,t]);let r=n.length-1;for(;r>0;){let e=r-1>>1;if(n[e][0]<=n[r][0])break;[n[e],n[r]]=[n[r],n[e]],r=e}}pop(){let e=this.a,t=e[0],n=e.pop();if(e.length>0){e[0]=n;let t=0;for(;;){let n=2*t+1,r=n+1,i=t;if(n<e.length&&e[n][0]<e[i][0]&&(i=n),r<e.length&&e[r][0]<e[i][0]&&(i=r),i===t)break;[e[i],e[t]]=[e[t],e[i]],t=i}}return t}};function Sn(e,t,n){let r=new Map([[t,0]]),i=new Map,a=new Set,o=new xn;for(o.push(0,t);o.size>0;){let[t,s]=o.pop();if(!a.has(s)){if(a.add(s),s===n)break;for(let{to:n,w:a}of e(s)){let e=t+a;e<(r.get(n)??1/0)&&(r.set(n,e),i.set(n,s),o.push(e,n))}}}if(!r.has(n))return null;let s=[],c=n;for(;c!==void 0&&(s.push(c),c!==t);)c=i.get(c);return s[s.length-1]===t?s.reverse():null}function Cn(e,t){return{x:fn(t.x,e.x,e.x+e.w),y:fn(t.y,e.y,e.y+e.h)}}function wn(e){if(e.length<=2)return e;let t=[e[0]];for(let n=1;n<e.length-1;n++){let r=t[t.length-1],i=e[n],a=e[n+1];!(Math.abs(r.x-i.x)<.1&&Math.abs(i.x-a.x)<.1||Math.abs(r.y-i.y)<.1&&Math.abs(i.y-a.y)<.1)&&(Math.abs(r.x-i.x)>.1||Math.abs(r.y-i.y)>.1)&&t.push(i)}return t.push(e[e.length-1]),t}function Tn(e,t,n){let r=yn(e,mn(t)),i=yn(e,mn(n));if(!r||!i)return null;let a=new Map,o=(e,t)=>{(a.get(e)??a.set(e,[]).get(e)).push(t)};for(let t of bn(e.segs[r.segIndex],r.along))o(`\0A`,{to:t.key,w:t.w});for(let t of bn(e.segs[i.segIndex],i.along))o(t.key,{to:`\0B`,w:t.w});r.segIndex===i.segIndex&&o(`\0A`,{to:`\0B`,w:Math.abs(r.along-i.along)*hn(r.seg.tier)});let s=Sn(t=>[...e.adj.get(t)??[],...a.get(t)??[]],`\0A`,`\0B`);if(!s)return null;let c=s.map(t=>t===`\0A`?r.point:t===`\0B`?i.point:e.coord.get(t)),l=Cn(t,c[0]),u=Cn(n,c[c.length-1]);return wn([l,...c,u])}function En(e,t){let n=mn(e),r=mn(t);return Math.abs(r.x-n.x)>=Math.abs(r.y-n.y)?[{x:r.x>n.x?e.x+e.w:e.x,y:n.y},{x:r.x,y:n.y},{x:r.x,y:r.y>n.y?t.y:t.y+t.h}]:[{x:n.x,y:r.y>n.y?e.y+e.h:e.y},{x:n.x,y:r.y},{x:r.x>n.x?t.x:t.x+t.w,y:r.y}]}var Dn=new WeakMap,On=new WeakMap;function kn(e){if(Dn.has(e))return Dn.get(e)??null;let t=vn(e);return Dn.set(e,t),t}function An(e,t,n){let r=kn(e);if(!r)return null;let i=On.get(e);if(i||(i=new Map,On.set(e,i)),i.has(t))return i.get(t)??null;let a=[],o=0;for(let i of e.roads){if(i.a!==t&&i.b!==t)continue;let e=n.get(i.a),s=n.get(i.b);if(!e||!s)continue;let c=null;o<dn&&(c=Tn(r,e,s),o++),c||=En(e,s),a.push({points:c,bidirectional:i.bidirectional,affinity:i.affinity})}return i.set(t,a),a}function jn(e,t){let n=e.x+e.w/2,r=e.y+e.h/2,i=t.x+t.w/2,a=t.y+t.h/2,o=i-n,s=a-r;if(Math.abs(o)<1||Math.abs(s)<1)return[{x:n,y:r},{x:i,y:a}];if(Math.abs(o)>Math.abs(s)){let n=o>0?e.x+e.w:e.x,a=s>0?t.y:t.y+t.h;return[{x:n,y:r},{x:i,y:r},{x:i,y:a}]}let c=s>0?e.y+e.h:e.y,l=o>0?t.x:t.x+t.w;return[{x:n,y:c},{x:n,y:a},{x:l,y:a}]}function Mn(e,t,n){let{cam:r,model:i,palette:a,tier:o,viewW:s,viewH:c}=t;if(o===`city`||i.roads.length===0||n===`selected`&&!t.selectedId)return;let l=new Map;for(let e of i.blocks)l.set(e.id,e.rect);if(n===`selected`&&t.selectedId){let n=An(i,t.selectedId,l);if(n){Nn(e,t,n);return}}let u=Math.max(2,Math.min(8,4*r.scale));for(let o of i.roads){if(n===`selected`&&o.a!==t.selectedId&&o.b!==t.selectedId)continue;let i=l.get(o.a),d=l.get(o.b);if(!i||!d)continue;let f=jn(i,d).map(e=>({x:y(r,e.x),y:b(r,e.y)})),p=1/0,m=1/0,h=-1/0,g=-1/0;for(let e of f)e.x<p&&(p=e.x),e.y<m&&(m=e.y),e.x>h&&(h=e.x),e.y>g&&(g=e.y);h<0||g<0||p>s||m>c||(n===`selected`?(e.strokeStyle=a.selected,e.globalAlpha=.9,e.lineWidth=2):(e.strokeStyle=o.bidirectional?a.roadMutual:a.road,e.globalAlpha=.25+.2*Math.min(1,o.affinity),e.lineWidth=o.bidirectional?1.5:1),e.beginPath(),e.moveTo(f[0].x,f[0].y),f.length===2?e.lineTo(f[1].x,f[1].y):(e.arcTo(f[1].x,f[1].y,f[2].x,f[2].y,u),e.lineTo(f[2].x,f[2].y)),e.stroke())}e.globalAlpha=1}function Nn(e,t,n){let{cam:r,palette:i,viewW:a,viewH:o}=t,s=Math.max(2,Math.min(6,3*r.scale));e.strokeStyle=i.selected,e.globalAlpha=.9,e.lineJoin=`round`;for(let t of n){if(t.points.length<2)continue;let n=t.points.map(e=>({x:y(r,e.x),y:b(r,e.y)})),i=1/0,c=1/0,l=-1/0,u=-1/0;for(let e of n)e.x<i&&(i=e.x),e.y<c&&(c=e.y),e.x>l&&(l=e.x),e.y>u&&(u=e.y);if(!(l<0||u<0||i>a||c>o)){e.lineWidth=t.bidirectional?2.4:2,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length-1;t++)e.arcTo(n[t].x,n[t].y,n[t+1].x,n[t+1].y,s);e.lineTo(n[n.length-1].x,n[n.length-1].y),e.stroke()}}e.globalAlpha=1}function Pn(e,t){e.save(),Gt(e,t),Mn(e,t,`under`),nt(e,t),pt(e,t),xt(e,t,t.atlas),nn(e,t),ft(e,t),Mn(e,t,`selected`),rn(e,t),sn(e,t),e.restore()}var Fn=.01;function In(e,t){return e.x+e.w<=t.x+Fn||e.y+e.h<=t.y+Fn}function Ln(e){let t=e.length;if(t<=1)return e.map((e,t)=>t);let n=t=>{let n=e[t].rect;return n.x+n.w+n.y+n.h},r=(t,r)=>{let i=e[t].rect,a=e[r].rect;return(n(t)-n(r)||i.x-a.x||i.y-a.y||i.w-a.w||i.h-a.h||t-r)<0},i=e.map((e,t)=>t).sort((t,n)=>e[t].u0-e[n].u0),a=Array.from({length:t},()=>[]),o=Array(t).fill(0),s=[];for(let t of i){let n=e[t];for(let i=s.length-1;i>=0;i--){let c=s[i];if(e[c].u1<n.u0){s.splice(i,1);continue}let l=e[t].rect,u=e[c].rect,d=In(l,u),f=In(u,l);d&&!f?(a[t].push(c),o[c]+=1):f&&!d?(a[c].push(t),o[t]+=1):d&&f&&(r(t,c)?(a[t].push(c),o[c]+=1):(a[c].push(t),o[t]+=1))}s.push(t)}let c=e=>{let t=0;for(let n=1;n<e.length;n++)r(e[n],e[t])&&(t=n);return t},l=[],u=[],d=o.slice();for(let e=0;e<t;e++)d[e]===0&&u.push(e);let f=Array(t).fill(!1);for(;l.length<t;){if(u.length===0){let e=-1;for(let r=0;r<t;r++)f[r]||(e<0||n(r)<n(e))&&(e=r);u.push(e),d[e]=0}let e=c(u),r=u.splice(e,1)[0];if(!f[r]){f[r]=!0,l.push(r);for(let e of a[r])--d[e],d[e]===0&&!f[e]&&u.push(e)}}return l}var I=.6;function L(e,t){return{u:e-t,v:(e+t)/2}}function Rn(e){return e*3}var zn=3*I*.18;function Bn(e){return(1.5+Math.max(0,Math.min(1,e))*3.5)*3*I}function Vn(e,t,n=!1){let r=Math.max(.001,t),i=(e.w+e.h)*r;return Math.max(n?2:3,Math.min(n?28:34,i*.17))/r}function Hn(e){return{n:L(e.x,e.y),e:L(e.x+e.w,e.y),s:L(e.x+e.w,e.y+e.h),w:L(e.x,e.y+e.h)}}function Un(e,t,n,r){let i=(t.x-(t.y+t.h)-e.offsetX)*e.scale,a=(t.x+t.w-t.y-e.offsetX)*e.scale,o=((t.x+t.y)/2-e.offsetY)*e.scale,s=((t.x+t.w+t.y+t.h)/2-e.offsetY)*e.scale;return a>=0&&s>=0&&i<=n&&o<=r}function Wn(e,t){return{u0:e.x-(e.y+e.h),u1:e.x+e.w-e.y,v0:(e.x+e.y)/2-t,v1:(e.x+e.w+e.y+e.h)/2}}function Gn(e,t,n,r){return Math.max(0,n.x-e/2-t,n.y+e/2-t)<=Math.min(r,n.x+n.w-e/2-t,n.y+n.h+e/2-t)}function Kn(e,t,n,r,i=32){if(e.w<=0||e.h<=0||n<=0||r<=0)return{scale:1,offsetX:0,offsetY:0};let a=Wn(e,t),o=a.u1-a.u0,s=a.v1-a.v0,c=_(Math.min((n-i*2)/o,(r-i*2)/s)),l=a.u0+o/2,u=a.v0+s/2;return{scale:c,offsetX:l-n/2/c,offsetY:u-r/2/c}}function qn(e){return e.levels===void 0?Math.max(1,Math.min(5,1+Math.round(Math.sqrt(Math.max(1,e.weight))/15))):e.levels}function Jn(e){let t=Je(e),n=e.blocks.map(n=>{let r=t.get(n.id),i=n.state===`tombstoned`||r?.archetype===`field`||r?.archetype===`park`?0:Rn(qn(n)),a=i*I,o=n.state===`live`&&!n.phantom&&ie(n)?tr(e,n.id).map(e=>({building:e,roofFactor:We(e,n).roofFactor??1})):[];return{...o.length?{campus:o}:{},block:n,hWorld:i,hIso:a,aabb:Wn(n.rect,a),...r?{style:r}:{},roofFactor:r?.roofFactor??1}}),r=Ln(n.map(e=>({rect:e.block.rect,u0:e.aabb.u0,u1:e.aabb.u1}))),i=0;for(let e of n){i=Math.max(i,e.hIso);for(let t of e.campus??[])i=Math.max(i,zn+Bn(t.building.height))}return{geoms:n,order:r,maxHIso:i}}var Yn=new WeakMap;function Xn(e){let t=Yn.get(e);if(t)return t;let n=Jn(e);return Yn.set(e,n),n}function Zn(e,t){return e.block.state!==`live`||e.block.phantom?0:Vn(e.block.rect,t)*e.roofFactor}function Qn(e,t,n,r){let i=Zn(t,e.scale);for(let n of t.campus??[])i=Math.max(i,zn+Bn(n.building.height)-t.hIso+Vn(n.building.rect,e.scale,!0)*n.roofFactor);let a=(t.aabb.u0-e.offsetX)*e.scale,o=(t.aabb.u1-e.offsetX)*e.scale,s=(t.aabb.v0-i-e.offsetY)*e.scale,c=(t.aabb.v1-e.offsetY)*e.scale;return o>=0&&c>=0&&a<=n&&s<=r}function $n(e,t){let n=t.rect.x+t.rect.w/2,r=t.rect.y+t.rect.h/2,i=n-r,a=(n+r)/2-zn-Bn(t.height)-Vn(t.rect,e.scale,!0);return{x:(i-e.offsetX)*e.scale,y:(a-e.offsetY)*e.scale}}var er=new WeakMap;function tr(e,t){let n=er.get(e);if(!n){n=new Map;for(let t of e.buildings){let e=n.get(t.blockId);e?e.push(t):n.set(t.blockId,[t])}er.set(e,n)}return n.get(t)??nr}var nr=[];function rr(e,t,n,r,i){let a=r/n.scale+n.offsetX,o=i/n.scale+n.offsetY+zn,s=tr(e,t),c=e.blocks?.find(e=>e.id===t);for(let e=s.length-1;e>=0;e--){let t=s[e],r=c?We(t,c).roofFactor??1:1;if(Gn(a,o,t.rect,Bn(t.height)+Vn(t.rect,n.scale,!0)*r))return t}return null}function ir(e,t,n,r,i=!0){let a=n/t.scale+t.offsetX,o=r/t.scale+t.offsetY;for(let n=e.order.length-1;n>=0;n--){let r=e.geoms[e.order[n]];if(i&&r.campus?.length){for(let e=r.campus.length-1;e>=0;e--){let n=r.campus[e];if(Gn(a,o+.32399999999999995,n.building.rect,Bn(n.building.height)+Vn(n.building.rect,t.scale,!0)*n.roofFactor))return r.block}if(Gn(a,o,r.block.rect,.32399999999999995))return r.block;continue}if(Gn(a,o,r.block.rect,r.hIso+Zn(r,t.scale)))return r.block}return null}function R(e,t,n){return{x:(t-e.offsetX)*e.scale,y:(n-e.offsetY)*e.scale}}function z(e,t,n){let r=Hn(t),i=R(e,r.n.u,r.n.v),a=R(e,r.e.u,r.e.v),o=R(e,r.s.u,r.s.v),s=R(e,r.w.u,r.w.v),c=n*e.scale;return{gn:i,ge:a,gs:o,gw:s,tn:{x:i.x,y:i.y-c},te:{x:a.x,y:a.y-c},ts:{x:o.x,y:o.y-c},tw:{x:s.x,y:s.y-c},liftPx:c}}function B(e,t,n){let r=Hn(n),i=R(t,r.n.u,r.n.v),a=R(t,r.e.u,r.e.v),o=R(t,r.s.u,r.s.v),s=R(t,r.w.u,r.w.v);e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.lineTo(o.x,o.y),e.lineTo(s.x,s.y),e.closePath()}function V(e,t,n,r,i){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.lineTo(r.x,r.y),e.lineTo(i.x,i.y),e.closePath()}function H(e,t,n,r,i,a){e.fillStyle=t,V(e,n,r,i,a),e.fill()}function ar(e,t){e.beginPath(),e.moveTo(t.tn.x,t.tn.y),e.lineTo(t.te.x,t.te.y),e.lineTo(t.ge.x,t.ge.y),e.lineTo(t.gs.x,t.gs.y),e.lineTo(t.gw.x,t.gw.y),e.lineTo(t.tw.x,t.tw.y),e.closePath()}function or(e,t,n){t.liftPx>=.5&&(H(e,n.wallL,t.tw,t.ts,t.gs,t.gw),H(e,n.wallR,t.ts,t.te,t.ge,t.gs)),H(e,n.top,t.tn,t.te,t.ts,t.tw)}var sr=class{buckets=new Map;add(e,t,n,r,i){let a=this.buckets.get(e);a||(a=[],this.buckets.set(e,a)),a.push(t.x,t.y,n.x,n.y,r.x,r.y,i.x,i.y)}flush(e){for(let[t,n]of this.buckets){e.fillStyle=t,e.beginPath();for(let t=0;t<n.length;t+=8)e.moveTo(n[t],n[t+1]),e.lineTo(n[t+2],n[t+3]),e.lineTo(n[t+4],n[t+5]),e.lineTo(n[t+6],n[t+7]),e.closePath();e.fill()}this.buckets.clear()}};function cr(e,t,n,r){let i=M(n)===`village`;if(or(e,r,{top:i?t.palette.park.path:t.palette.districtFill,wallL:t.palette.curb,wallR:t.palette.fence}),t.tier!==`street`||r.te.x-r.tw.x<40)return;let a=(e,t)=>({x:r.tn.x+(r.te.x-r.tn.x)*e+(r.tw.x-r.tn.x)*t,y:r.tn.y+(r.te.y-r.tn.y)*e+(r.tw.y-r.tn.y)*t});e.save(),V(e,r.tn,r.te,r.ts,r.tw),e.clip(),e.strokeStyle=t.palette.curb,e.globalAlpha=i?.25:.36,e.lineWidth=.6,e.beginPath();let o=Math.min(64,Math.ceil(n.rect.h/2.8)),s=Math.min(64,Math.ceil(n.rect.w/4.2));for(let t=1;t<o;t++){let n=a(0,t/o),r=a(1,t/o);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y);for(let n=0;n<s;n++){let r=(n+t%2*.5)/s,i=a(r,(t-1)/o),c=a(r,t/o);e.moveTo(i.x,i.y),e.lineTo(c.x,c.y)}}e.stroke(),e.globalAlpha=.7,e.strokeStyle=t.palette.sidewalk,e.lineWidth=Math.max(1,t.cam.scale*.3),V(e,r.tn,r.te,r.ts,r.tw),e.stroke(),e.restore()}var lr=2/Math.sqrt(5),ur=Math.sqrt(5)/2,dr=1.2,fr=4,pr=2.4,mr=2.6,hr=4,gr=400,_r={length:5.5,width:1.9,height:2.4},vr={length:2.4,width:1.2,height:1.1},yr={length:1.4,width:.6,height:1.2,lead:2.1},br=2.5,xr=2.2;function Sr(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t,s=Vt(r);if(s.streets.length===0)return;let c=s.streets.filter(e=>Un(n,e.reservation,a,o));if(c.length===0)return;let l=n.scale;if(t.tier===`city`){let t=new Map;for(let e of c){if(e.street.tier>1)continue;let n=Ht(e,i),r=t.get(n);r?r.push(e):t.set(n,[e])}for(let[r,i]of t){e.fillStyle=r;for(let t of i)B(e,n,t.carriageway),e.fill()}return}let u=Ee(r),d=e=>e.street.districtId?u.get(e.street.districtId):void 0,f=e=>e.sidewalks!==null&&e.sidewalkWidth*lr*l>=dr;e.fillStyle=i.street.verge;for(let t of c)!t.spec.verge||d(t)===`city`||(B(e,n,t.reservation),e.fill());e.fillStyle=i.sidewalk;for(let t of c)if(!(!t.sidewalks||!f(t)))for(let r of t.sidewalks)B(e,n,r),e.fill();let p=t.tier===`street`&&!t.ageLens,m=[...c].sort((e,t)=>e.grade-t.grade||t.street.tier-e.street.tier);for(let r of m){let a=r.sidewalks&&!f(r)?r.reservation:r.carriageway;e.fillStyle=Ht(r,i),B(e,n,a),e.fill(),p&&r.carriagewayWidth*lr*l>=fr&&wr(e,t,r,f(r))}for(let n of c)n.rails&&Tr(e,t,n);if(p){for(let n of c)Er(e,t,n);for(let n of c)Or(e,t,n)}}function U(e,t,n){let r=L(t,n);return R(e.cam,r.u,r.v)}function Cr(e,t,n=40){return t.x>=-n&&t.x<=e.viewW+n&&t.y>=-n&&t.y<=e.viewH+n}function W(e,t,n,r){e.moveTo(n.x,n.y),e.lineTo(r.x,r.y)}function wr(e,t,n,r){let i=t.cam.scale,a=n.carriagewayWidth/2,o=(e,r)=>{let i=Wt(n,e,r);return U(t,i.x,i.y)};switch(n.spec.surface){case`dirt`:e.strokeStyle=`rgba(0, 0, 0, 0.24)`,e.lineWidth=Math.max(.6,.32*i),e.setLineDash([3.2*ur*i,2.4*ur*i]),e.beginPath();for(let r of[-a*.42,a*.42])W(e,t,o(n.a0+1,r),o(n.a1-1,r));e.stroke(),e.setLineDash([]);break;case`cobble`:{e.strokeStyle=t.palette.curb,e.globalAlpha=.46,e.lineWidth=Math.max(.5,.12*i),e.beginPath();let r=Math.max(2,Math.min(6,Math.floor(n.carriagewayWidth/.9))),s=Math.min(Math.floor(gr/r),Math.floor(n.length/mr));for(let i=0;i<r;i++){let c=-a+n.carriagewayWidth*i/r,l=c+n.carriagewayWidth/r;i>0&&W(e,t,o(n.a0,c),o(n.a1,c));for(let r=0;r<s;r++){let a=n.a0+mr*(r+.25+i%2*.5);W(e,t,o(a,c),o(a,l))}}e.stroke(),e.globalAlpha=1,e.strokeStyle=t.palette.sidewalk,e.globalAlpha=.5,e.lineWidth=Math.max(.6,.12*i),e.beginPath(),W(e,t,o(n.a0,-a+.3),o(n.a1,-a+.3)),W(e,t,o(n.a0,a-.3),o(n.a1,a-.3)),e.stroke(),e.globalAlpha=1;break}case`paved`:if(n.grade<4)break;e.strokeStyle=t.palette.curb,e.globalAlpha=r?.85:.55,e.lineWidth=Math.max(.6,.26*i),e.beginPath(),W(e,t,o(n.a0,-a),o(n.a1,-a)),W(e,t,o(n.a0,a),o(n.a1,a)),e.stroke(),e.globalAlpha=1;break}if(r&&n.sidewalkWidth*lr*i>=3){e.strokeStyle=`rgba(0, 0, 0, 0.12)`,e.lineWidth=Math.max(.5,.18*i),e.beginPath();let r=Math.min(gr,Math.floor(n.length/hr)),s=a+n.sidewalkWidth;for(let i=0;i<r;i++){let r=n.a0+hr*(i+.5);W(e,t,o(r,-s),o(r,-a)),W(e,t,o(r,a),o(r,s))}e.stroke()}}function Tr(e,t,n){if(!n.rails)return;let r=t.cam.scale;if(e.strokeStyle=t.palette.street.rail,e.beginPath(),n.gauge*lr*r>=pr){e.lineWidth=Math.max(.7,.26*r);for(let r of n.rails)W(e,t,U(t,r.a.x,r.a.y),U(t,r.b.x,r.b.y))}else{e.lineWidth=1;let r=Wt(n,n.a0,0),i=Wt(n,n.a1,0);W(e,t,U(t,r.x,r.y),U(t,i.x,i.y))}e.stroke()}function Er(e,t,n){let r=t.cam.scale,i=t.palette;if(n.lamps.length>0){let a=br*r,o=Math.max(.8,.25*r),s=[];for(let e of n.lamps){let n=U(t,e.x,e.y);Cr(t,n)&&s.push(n)}if(s.length>0){if(i.dark){e.fillStyle=i.street.lampGlow,e.globalAlpha=.1;for(let t of s)e.beginPath(),e.arc(t.x,t.y-a,1.3*r,0,Math.PI*2),e.fill();e.globalAlpha=1}e.strokeStyle=i.street.lampPost,e.lineWidth=Math.max(.6,.22*r),e.beginPath();for(let t of s)e.moveTo(t.x,t.y),e.lineTo(t.x,t.y-a);e.stroke(),e.fillStyle=i.street.lampGlow;for(let t of s){let n=t.y-a;e.fillRect(t.x-o,n-o,o*2,o*2.2),e.strokeRect(t.x-o,n-o,o*2,o*2.2),e.fillStyle=i.street.lampPost,e.beginPath(),e.moveTo(t.x-o*1.4,n-o),e.lineTo(t.x,n-o*2),e.lineTo(t.x+o*1.4,n-o),e.closePath(),e.fill(),e.fillRect(t.x-o*.6,t.y-o,o*1.2,o),e.fillStyle=i.street.lampGlow}}}if(n.poles.length>0){let a=xr*r,o=.7*r*(n.horizontal?-1:1),s=[];e.strokeStyle=i.street.pole,e.lineWidth=Math.max(.7,.24*r),e.beginPath();for(let i of n.poles){let n=U(t,i.x,i.y),c={x:n.x,y:n.y-a};s.push(c),Cr(t,n)&&(e.moveTo(n.x,n.y),e.lineTo(c.x,c.y),e.moveTo(c.x,c.y+.3*r),e.lineTo(c.x+o,c.y+.3*r))}e.stroke(),e.strokeStyle=i.street.wire,e.globalAlpha=.55,e.lineWidth=Math.max(.5,.14*r),e.beginPath();for(let n=1;n<s.length;n++){let i=s[n-1],a=s[n];!Cr(t,i,200)&&!Cr(t,a,200)||(e.moveTo(i.x+o,i.y+.3*r),e.quadraticCurveTo((i.x+a.x)/2+o,(i.y+a.y)/2+.3*r+.35*r,a.x+o,a.y+.3*r))}e.stroke(),e.globalAlpha=1}if(n.trees.length>0&&t.atlas)for(let i of n.trees){let n=U(t,i.x,i.y);if(!Cr(t,n))continue;let a=i.size*r*2.8,o=t.atlas.index[i.sprite]*t.atlas.cell;e.drawImage(t.atlas.canvas,o,0,t.atlas.cell,t.atlas.cell,n.x-a/2,n.y-a,a,a)}}function Dr(e,t,n,r,i){let a=Wt(e,t,n);return e.horizontal?{x:a.x-r/2,y:a.y-i/2,w:r,h:i}:{x:a.x-i/2,y:a.y-r/2,w:i,h:r}}function Or(e,t,n){if(n.vehicles.length===0)return;let r=t.animationTime??0,i=t.palette;for(let a of n.vehicles){let o=Ut(n,a,r);switch(a.kind){case`trolley`:kr(e,t,n,o);break;case`cart`:{let r=Dr(n,o,a.cross,vr.length,vr.width);if(!Cr(t,U(t,r.x+r.w/2,r.y+r.h/2)))break;let s=Dr(n,o+a.dir*yr.lead,a.cross,yr.length,yr.width),c=a.dir===-1;c&&or(e,z(t.cam,s,yr.height*I),i.street.horse),or(e,z(t.cam,r,vr.height*I),i.street.cart),c||or(e,z(t.cam,s,yr.height*I),i.street.horse);break}case`walker`:{let r=Wt(n,o,a.cross),s=U(t,r.x,r.y);if(!Cr(t,s))break;let c=Math.max(1,.32*t.cam.scale),l=Math.max(2,.95*t.cam.scale);e.fillStyle=i.street.walker,e.fillRect(s.x-c/2,s.y-l,c,l);break}}}}function kr(e,t,n,r){let i=t.palette,a=Dr(n,r,0,_r.length,_r.width),o=U(t,a.x+a.w/2,a.y+a.h/2);if(!Cr(t,o,60))return;let s=z(t.cam,a,_r.height*I);if(or(e,s,i.street.trolley),s.liftPx>=5){let[r,a,c,l]=n.horizontal?[s.tw,s.ts,s.gs,s.gw]:[s.ts,s.te,s.ge,s.gs];e.fillStyle=i.dark?i.windowLit:i.window;for(let t=0;t<4;t++){let n=(t+.2)/4,i=(t+.8)/4,o=G(r,a,n),s=G(r,a,i),u=G(l,c,n),d=G(l,c,i);e.beginPath(),e.moveTo(G(o,u,.2).x,G(o,u,.2).y),e.lineTo(G(s,d,.2).x,G(s,d,.2).y),e.lineTo(G(s,d,.6).x,G(s,d,.6).y),e.lineTo(G(o,u,.6).x,G(o,u,.6).y),e.closePath(),e.fill()}let u={x:o.x,y:o.y-s.liftPx};e.strokeStyle=i.street.pole,e.lineWidth=Math.max(.6,.18*t.cam.scale),e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(u.x+(n.horizontal?-.7:.7)*t.cam.scale,o.y-xr*t.cam.scale),e.stroke()}}function G(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}var Ar=14,jr=6;function Mr(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t;e.fillStyle=i.ground,e.fillRect(0,0,a,o);let s=new Set;for(let e of r.districts)e.parentId&&s.add(e.parentId);let c=t.tier===`city`?null:Ee(r);for(let l of r.districts){if(!Un(n,l.rect,a,o))continue;if(s.has(l.id)){e.strokeStyle=i.districtStroke,e.lineWidth=Math.max(.5,Math.min(2,3-l.depth*.4)),B(e,n,l.rect),e.stroke();continue}let r=c?.get(l.id);e.globalAlpha=.9,e.fillStyle=r===`village`?i.districtFillVillage:r===`city`?i.districtFillCity:i.districtFill,B(e,n,l.rect),e.fill(),e.globalAlpha=1,t.tier!==`city`&&(e.strokeStyle=i.curb,e.lineWidth=1,B(e,n,l.rect),e.stroke())}for(let s of r.plazas??[])Un(n,s.rect,a,o)&&(s.kind===`plaza`?(e.fillStyle=i.sidewalk,B(e,n,s.rect),e.fill(),t.tier===`street`&&!t.ageLens&&(e.strokeStyle=i.domeAccent,e.globalAlpha=.55,e.lineWidth=1,B(e,n,s.rect),e.stroke(),e.globalAlpha=1,Nr(e,t,s))):(e.fillStyle=i.dark?`hsl(130 12% 15%)`:`hsl(90 26% 80%)`,B(e,n,s.rect),e.fill(),t.tier===`street`&&!t.ageLens&&Fr(e,t,s)));Sr(e,t)}function Nr(e,t,n){let{cam:r}=t,i=Math.min(n.rect.w,n.rect.h)*.22*Math.SQRT2*r.scale;if(i<Ar/2)return;let a=L(n.rect.x+n.rect.w/2,n.rect.y+n.rect.h/2);Pr(e,t,R(r,a.u,a.v),i)}function Pr(e,t,n,r){let{cam:i,palette:a}=t,o=r/2,s=Math.max(1,.28*i.scale);e.fillStyle=a.street.basin,e.beginPath(),e.ellipse(n.x,n.y,r,o,0,0,Math.PI*2),e.fill(),e.fillStyle=a.street.water,e.beginPath(),e.ellipse(n.x,n.y,r-s,o-s/2,0,0,Math.PI*2),e.fill(),e.strokeStyle=a.street.water,e.globalAlpha=.7,e.lineWidth=Math.max(.6,.2*i.scale),e.beginPath(),e.ellipse(n.x,n.y,r*.45,o*.45,0,0,Math.PI*2),e.stroke(),e.globalAlpha=1;let c=Math.max(2,1.1*i.scale);e.strokeStyle=a.sidewalk,e.lineWidth=Math.max(.8,.3*i.scale),e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x,n.y-c),e.stroke(),e.fillStyle=a.sidewalk,e.beginPath(),e.arc(n.x,n.y-c,Math.max(.8,.28*i.scale),0,Math.PI*2),e.fill()}function Fr(e,t,n){let r=t.atlas;if(!r)return;let{cam:i}=t,a=n.rect.w*n.rect.h,o=Math.max(1,Math.min(jr,Math.floor(a/500))),s=w(C(`green:${n.id}`));for(let t=0;t<o;t++){let t=n.rect.x+2+s()*Math.max(.5,n.rect.w-4),a=n.rect.y+2+s()*Math.max(.5,n.rect.h-4),o=(2+s()*1.2)*i.scale*2,c=s()<.7?`tree1`:`tree3`,l=L(t,a),u=R(i,l.u,l.v),d=r.index[c]*r.cell;e.drawImage(r.canvas,d,0,r.cell,r.cell,u.x-o/2,u.y-o,o,o)}}var Ir=12,Lr=5,Rr=.78;function zr(e,t,n){if(t.tier===`city`||t.ageLens)return;let r=n.lot;if(!r||n.state===`tombstoned`||n.phantom||(r.w+r.h)*t.cam.scale<Ir)return;let i=Hn(r),a=[R(t.cam,i.n.u,i.n.v),R(t.cam,i.e.u,i.e.v),R(t.cam,i.s.u,i.s.v),R(t.cam,i.w.u,i.w.v)],o=j(n),s=t.palette;e.globalAlpha=.55,e.fillStyle=o<.25?s.orchard:o<.5?s.ground:s.sidewalk,Vr(e,a),e.fill(),e.globalAlpha=1;let c=M(n);if(!(c===`city`&&o>Rr)){if(c===`village`){Br(e,t,a);return}e.strokeStyle=c===`town`?s.fence:s.curb,e.lineWidth=1,c===`town`&&e.setLineDash([2,2]),Vr(e,a),e.stroke(),e.setLineDash([])}}function Br(e,t,n){e.strokeStyle=t.palette.hedge,e.lineWidth=1.6,e.lineCap=`round`,e.beginPath();for(let t=0;t<4;t++){let r=n[t],i=n[(t+1)%4],a=Math.max(1,Math.floor(Math.hypot(i.x-r.x,i.y-r.y)/Lr));for(let t=0;t<a;t++){let n=(t+.15)/a,o=(t+.85)/a;e.moveTo(r.x+(i.x-r.x)*n,r.y+(i.y-r.y)*n-1),e.lineTo(r.x+(i.x-r.x)*o,r.y+(i.y-r.y)*o-1)}}e.stroke(),e.lineCap=`butt`}function Vr(e,[t,n,r,i]){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.lineTo(r.x,r.y),e.lineTo(i.x,i.y),e.closePath()}var Hr=3,Ur=2;function Wr(e,t,n,r,i,a){if(n.length===0)return;let o=w(C(`${r}:chimney-smoke`)),s=Math.max(.6,.34*i);e.save(),e.fillStyle=t.street.smoke;for(let t of n.slice(0,Ur))for(let n=0;n<Hr;n++){let n=o(),r=Gr(a*(11e-5+o()*5e-5)+n),i=(1.1+r*2.8+o()*.4)*s,c=Math.sin(a*9e-4+n*Math.PI*2)*.8*s,l=t.x+r*10*s+c,u=t.y-.5*s-r*15*s;e.globalAlpha=.24*Math.sin(r*Math.PI),e.beginPath(),e.arc(l,u,i,0,Math.PI*2),e.fill()}e.restore()}function Gr(e){return e-Math.floor(e)}function Kr(e,t,n,r,i,a){let o=.72/n,s=.12+i*o,c=Math.min(.86,s+o*.58),l=.82/r,u=.09+(a+.5)*l,d=Math.min(l*.46,t*(c-s)*.82/Math.max(1,e));return{u0:u-d/2,u1:u+d/2,v0:s,v1:c,span:l}}function qr(e){let t=t=>e.top.replace(/(\d+)%\)$/,(e,n)=>`${Math.max(0,Number(n)-t)}%)`);return{...e,wallL:t(9),wallR:t(17)}}function Jr(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function Yr(e,t,n,r){let i=e=>Jr(Jr(n.ts,n.te,e),Jr(n.gs,n.ge,e),.58),a=Math.max(1.5,Math.min(4.5,n.liftPx*.14)),o=e=>{let t=i(e);return{x:t.x+a,y:t.y+a}},s=[t.palette.awning,t.palette.hedge,t.palette.window][r.seed%3];for(let n=0;n<8;n++){let r=.07+n*.1075,c=r+.1075,l=o(r),u=o(c),d=n%2?t.palette.sidewalk:s;H(e,d,i(r),i(c),u,l),H(e,d,l,u,{x:u.x,y:u.y+a*.4},{x:l.x,y:l.y+a*.4})}}function Xr(e,t,n,r){if(n.te.x-n.tw.x<42||n.liftPx<10)return;let i=(e,t)=>Jr(Jr(n.tw,n.ts,e),Jr(n.gw,n.gs,e),t),a=(t,n,r,a,o)=>H(e,t,i(n,a),i(r,a),i(r,o),i(n,o)),o=t.palette.dark?`#4f625a`:[`#526c62`,`#795e50`,`#656b7d`][r.seed%3];if(r.frontage===`shutters`){let e=Math.max(1,Math.min(3,r.bays)),t=Math.min(3,r.storeys);for(let r=0;r<t;r++)for(let i=0;i<e;i++){let{u0:s,u1:c,v0:l,v1:u,span:d}=Kr(Math.abs(n.ts.x-n.tw.x),n.liftPx,t,e,r,i);a(o,s-d*.17,s-d*.025,l,u),a(o,c+d*.025,c+d*.17,l,u)}}else if(r.frontage===`bay`){let r=Math.min(4,n.liftPx*.12),a=(e,t)=>{let n=i(e,t);return{x:n.x-r,y:n.y+r*.5}};H(e,o,i(.4,.35),a(.46,.35),a(.46,.85),i(.4,.9)),H(e,t.palette.sidewalk,a(.46,.35),a(.76,.35),a(.76,.87),a(.46,.87)),H(e,t.palette.window,a(.49,.39),a(.73,.39),a(.73,.75),a(.49,.75)),H(e,o,i(.4,.32),i(.8,.32),a(.76,.35),a(.46,.35)),e.strokeStyle=t.palette.sidewalk,e.lineWidth=1,e.beginPath();for(let t of[.57,.65]){let n=a(t,.39),r=a(t,.75);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y)}e.stroke()}}function Zr(e,t,n,r,i,a,o){if(![`gable`,`half-hip`,`catslide`,`thatch`].includes(r.roof))return;let s=r.ridge===`x`?n.ts:n.tw,c=r.ridge===`x`?n.te:n.ts,l=a.b,u=r.ridge===`x`?i.wallR:i.wallL,d=r.frontage===`stepped`||r.frontage===`pediment`;if(r.roof!==`gable`&&r.roof!==`thatch`)return;let f=[s];if(d&&n.te.x-n.tw.x>=38)for(let[e,t]of r.frontage===`stepped`?[[.12,0],[.12,.28],[.29,.28],[.29,.6],[.42,.6],[.42,.93],[.58,.93],[.58,.6],[.71,.6],[.71,.28],[.88,.28],[.88,0]]:[[.12,0],[.5,.94],[.88,0]]){let n=Jr(s,c,e);f.push({x:n.x,y:n.y-o*t})}else f.push(l);f.push(c),e.fillStyle=u,e.beginPath(),e.moveTo(s.x,s.y);for(let t of f.slice(1))e.lineTo(t.x,t.y);if(e.closePath(),e.fill(),e.strokeStyle=t.palette.sidewalk,e.lineWidth=d?1.7:1,e.stroke(),o<9)return;let p=Jr(s,c,.5),m=Math.min(2.5,o*.1);e.fillStyle=t.palette.window,e.beginPath(),e.ellipse(p.x,p.y-o*.37,m,m*1.2,0,0,Math.PI*2),e.fill()}var Qr=20,$r={"clock-tower":2.4,cupola:1.85,lantern:1.35,bellcote:1.5,finial:1.05};function ei(e,t,n,r,i,a={}){let o={stacks:[]};or(e,n,i);let s=a.compact===!0,c=Vn({x:0,y:0,w:Math.max(0,(n.te.x-n.tn.x)/t.cam.scale),h:Math.max(0,(n.tn.x-n.tw.x)/t.cam.scale)},t.cam.scale,s)*t.cam.scale;!a.suppressDetails&&t.tier===`street`&&n.liftPx>=5&&(xi(e,t,n,r,s),Xr(e,t,n,r)),!a.suppressDetails&&n.te.x-n.tw.x>=Qr&&Ci(e,t,n,r,i);let l=ti(e,t,n,r,c,qr(i));if(!a.suppressDetails&&t.tier===`street`){ri(e,n,r,l,i,s),ii(e,n,r,l,i,s),Zr(e,t,n,r,i,l,c);let a=c*(r.roofFactor??1),u=Math.min(l.a.y,l.b.y,l.apex.y);Oi(e,t,n,r,l,c,Math.max(0,a-(n.tn.y-u)),s,o.stacks)}return o}function ti(e,t,n,r,i,a){let o=r.ridge;switch(r.roof){case`gable`:return oi(e,n,o,i,a);case`hip`:return ui(e,n,o,i,a);case`mansard`:return di(e,n,o,i,a);case`sawtooth`:return fi(e,n,o,i,r.sawteeth,a);case`shed`:return pi(e,n,o,i,a);case`thatch`:return si(e,n,o,i,a);case`half-hip`:return ci(e,n,o,i,a);case`catslide`:return li(e,n,o,i,a);case`parapet`:return mi(e,n,i,a);case`monitor`:return hi(e,n,o,i,a);case`pyramid`:return gi(e,n,i,a);case`barrel`:return _i(e,t,n,o,i,a);case`conical`:return vi(e,n,i,a)}}function ni(e,t,n){return n===`x`?[{ridgeA:t.a,ridgeB:t.b,eaveA:e.tn,eaveB:e.te},{ridgeA:t.a,ridgeB:t.b,eaveA:e.tw,eaveB:e.ts}]:[{ridgeA:t.a,ridgeB:t.b,eaveA:e.tn,eaveB:e.tw},{ridgeA:t.a,ridgeB:t.b,eaveA:e.te,eaveB:e.ts}]}function ri(e,t,n,r,i,a){let o=t.te.x-t.tw.x;if(o<(a?24:30)||n.roof===`sawtooth`||n.roof===`monitor`||n.roof===`pyramid`||n.roof===`barrel`||n.roof===`conical`||n.roof===`parapet`)return;let s=ni(t,r,n.ridge),c=n.roof===`thatch`?`thatch`:n.material.roof,l=(t,n)=>{e.moveTo(t.x,t.y),e.lineTo(n.x,n.y)};e.strokeStyle=i.wallR,e.lineWidth=c===`iron`?.75:.6,e.globalAlpha=c===`thatch`?.34:.26,e.beginPath();for(let e of s)if(c===`slate`||c===`tile`){let t=c===`slate`?[.28,.48,.66,.82]:[.34,.6,.82],n=.08;for(let r=0;r<t.length;r++){let i=t[r];if(l(Z(e.ridgeA,e.eaveA,i),Z(e.ridgeB,e.eaveB,i)),o>=38){let t=a?3:5;for(let a=1;a<t;a++){let o=(a+(r%2==0?.28:-.18))/t;if(o<=0||o>=1)continue;let s=Z(e.ridgeA,e.ridgeB,o),c=Z(e.eaveA,e.eaveB,o);l(Z(s,c,n),Z(s,c,i))}}n=i}}else if(c===`thatch`){let t=a?4:7;for(let n=1;n<t;n++){let r=n/t,i=Z(e.ridgeA,e.ridgeB,r),a=Z(e.eaveA,e.eaveB,r);l(Z(i,a,.12),Z(i,a,.94))}}else if(c===`iron`||c===`glass`){let t=a?4:7;for(let n=1;n<t;n++){let r=n/t;l(Z(e.ridgeA,e.ridgeB,r),Z(e.eaveA,e.eaveB,r))}c===`glass`&&l(Z(e.ridgeA,e.eaveA,.55),Z(e.ridgeB,e.eaveB,.55))}e.stroke(),e.globalAlpha=1}function ii(e,t,n,r,i,a){if(n.roof===`parapet`||n.roof===`conical`||n.roof===`pyramid`)return;let o=t.te.x-t.tw.x,s=Math.max(1,Math.min(a?1.7:2.2,o*.024));e.strokeStyle=i.wallR,e.globalAlpha=.55,e.lineWidth=s+.8,e.lineJoin=`round`,e.beginPath(),e.moveTo(t.tw.x,t.tw.y+1),e.lineTo(t.ts.x,t.ts.y+1),e.lineTo(t.te.x,t.te.y+1),e.stroke(),e.strokeStyle=i.edge,e.globalAlpha=.72,e.lineWidth=s,e.beginPath(),e.moveTo(t.tw.x,t.tw.y),e.lineTo(t.ts.x,t.ts.y),e.lineTo(t.te.x,t.te.y),(n.roof===`gable`||n.roof===`thatch`||n.roof===`catslide`||n.roof===`half-hip`)&&(n.ridge===`x`?(e.moveTo(t.te.x,t.te.y),e.lineTo(r.b.x,r.b.y),e.lineTo(t.ts.x,t.ts.y)):(e.moveTo(t.tw.x,t.tw.y),e.lineTo(r.b.x,r.b.y),e.lineTo(t.ts.x,t.ts.y))),e.stroke(),e.lineJoin=`miter`,e.globalAlpha=1}function ai(e,t){return t===`x`?[X(e.tn,e.tw),X(e.te,e.ts)]:[X(e.tn,e.te),X(e.tw,e.ts)]}function K(e,t){return{a:e,b:t,apex:X(e,t)}}function oi(e,t,n,r,i){if(n===`x`){let n=Q(X(t.tn,t.tw),r),a=Q(X(t.te,t.ts),r);return q(e,i.wallL,t.tn,t.tw,n),q(e,i.wallR,t.te,a,t.ts),H(e,i.top,t.tn,t.te,a,n),H(e,i.wallL,n,a,t.ts,t.tw),J(e,i.edge,n,a),K(n,a)}let a=Q(X(t.tn,t.te),r),o=Q(X(t.tw,t.ts),r);return q(e,i.wallR,t.tn,a,t.te),q(e,i.wallL,t.tw,t.ts,o),H(e,i.top,t.tn,a,o,t.tw),H(e,i.wallL,a,t.te,t.ts,o),J(e,i.edge,a,o),K(a,o)}function si(e,t,n,r,i){let a=oi(e,t,n,r*1.12,i),o=Math.max(1.2,r*.16);e.fillStyle=i.wallR,e.globalAlpha=.55;for(let[r,i]of n===`x`?[[t.tn,t.te],[t.tw,t.ts]]:[[t.tn,t.tw],[t.te,t.ts]])Y(e,[r,i,{x:i.x,y:i.y+o},{x:r.x,y:r.y+o}],!0),e.fill();return e.globalAlpha=1,e.strokeStyle=i.top,e.lineWidth=Math.max(1.5,r*.22),e.lineCap=`round`,e.beginPath(),e.moveTo(a.a.x,a.a.y),e.lineTo(a.b.x,a.b.y),e.stroke(),e.lineCap=`butt`,a}function ci(e,t,n,r,i){let[a,o]=ai(t,n),s=Q(Z(a,o,.12),r),c=Q(Z(a,o,.88),r),l=.66;if(n===`x`){let n=Q(X(t.tn,t.tw),r*l),a=Q(X(t.te,t.ts),r*l);H(e,i.wallL,t.tn,t.tw,n,s),H(e,i.wallR,t.te,c,a,t.ts),H(e,i.top,t.tn,t.te,c,s),H(e,i.wallL,s,c,t.ts,t.tw)}else{let n=Q(X(t.tn,t.te),r*l),a=Q(X(t.tw,t.ts),r*l);H(e,i.wallR,t.tn,s,n,t.te),H(e,i.wallL,t.tw,t.ts,a,c),H(e,i.top,t.tn,s,c,t.tw),H(e,i.wallL,s,t.te,t.ts,c)}return J(e,i.edge,s,c),K(s,c)}function li(e,t,n,r,i){let a=.34;if(n===`x`){let n=Q(Z(t.tw,t.tn,a),r),o=Q(Z(t.ts,t.te,a),r);return q(e,i.wallL,t.tn,t.tw,n),q(e,i.wallR,t.te,o,t.ts),H(e,i.top,t.tn,t.te,o,n),H(e,i.wallL,n,o,t.ts,t.tw),J(e,i.edge,n,o),K(n,o)}let o=Q(Z(t.te,t.tn,a),r),s=Q(Z(t.ts,t.tw,a),r);return q(e,i.wallR,t.tn,o,t.te),q(e,i.wallL,t.tw,t.ts,s),H(e,i.top,t.tn,o,s,t.tw),H(e,i.wallL,o,t.te,t.ts,s),J(e,i.edge,o,s),K(o,s)}function ui(e,t,n,r,i){let[a,o]=ai(t,n),s=Q(Z(a,o,.24),r),c=Q(Z(a,o,.76),r);return n===`x`?(H(e,i.top,t.tn,t.te,c,s),q(e,i.wallR,t.te,t.ts,c),H(e,i.wallL,s,c,t.ts,t.tw),q(e,i.top,t.tn,s,t.tw)):(H(e,i.top,t.tn,s,c,t.tw),q(e,i.top,t.tn,t.te,s),H(e,i.wallR,s,t.te,t.ts,c),q(e,i.wallL,t.tw,c,t.ts)),J(e,i.edge,s,c),K(s,c)}function di(e,t,n,r,i){let a=Wi(t.tn,t.te,t.ts,t.tw),o=Q(Ui(t.tn,a,.32),r),s=Q(Ui(t.te,a,.32),r),c=Q(Ui(t.ts,a,.32),r),l=Q(Ui(t.tw,a,.32),r);return H(e,i.top,t.tn,t.te,s,o),H(e,i.wallR,t.te,t.ts,c,s),H(e,i.wallL,l,c,t.ts,t.tw),H(e,i.top,t.tn,o,l,t.tw),H(e,i.top,o,s,c,l),e.strokeStyle=i.edge,e.lineWidth=.8,Y(e,[o,s,c,l],!0),e.stroke(),n===`x`?K(X(o,l),X(s,c)):K(X(o,s),X(l,c))}function fi(e,t,n,r,i,a){let o=Math.max(2,Math.min(5,i||3)),s=n===`x`?t.tn:t.tw,c=n===`x`?t.tw:t.ts,l=n===`x`?t.te:t.tn,u=n===`x`?t.ts:t.te;for(let t=0;t<o;t++){let n=t/o,i=(t+.68)/o,d=(t+1)/o,f=Z(s,c,n),p=Z(l,u,n),m=Q(Z(s,c,i),r*.72),h=Q(Z(l,u,i),r*.72),g=Z(s,c,d),_=Z(l,u,d);H(e,a.top,f,p,h,m),H(e,a.wallL,m,h,_,g),J(e,a.edge,m,h,.65)}return K(Q(Z(s,c,.68/o),r*.72),Q(Z(l,u,.68/o),r*.72))}function pi(e,t,n,r,i){if(n===`x`){let n=Q(t.tn,r),a=Q(t.te,r);return q(e,i.wallL,t.tn,t.tw,n),q(e,i.wallR,t.te,a,t.ts),H(e,i.top,n,a,t.ts,t.tw),J(e,i.edge,n,a),K(n,a)}let a=Q(t.tn,r),o=Q(t.tw,r);return q(e,i.wallR,t.tn,a,t.te),q(e,i.wallL,t.tw,t.ts,o),H(e,i.top,a,t.te,t.ts,o),J(e,i.edge,a,o),K(a,o)}function mi(e,t,n,r){let i=Math.max(1.5,n*.42),a=Q(t.tn,i),o=Q(t.te,i),s=Q(t.ts,i),c=Q(t.tw,i);H(e,r.wallL,c,s,t.ts,t.tw),H(e,r.wallR,s,o,t.te,t.ts),H(e,r.top,a,o,s,c);let l=Wi(a,o,s,c),u=[Z(a,l,.2),Z(o,l,.2),Z(s,l,.2),Z(c,l,.2)];return H(e,r.wallL,...u),e.strokeStyle=r.edge,e.lineWidth=.8,Y(e,[a,o,s,c],!0),e.stroke(),K(u[0],u[2])}function hi(e,t,n,r,i){let a=oi(e,t,n,r*.6,i),o=r*.42,s=Math.abs(t.te.x-t.tw.x)*.1,c={x:a.a.x+s*.35,y:a.a.y},l={x:a.b.x-s*.35,y:a.b.y},u=Q(c,o),d=Q(l,o);return H(e,i.wallR,c,l,d,u),H(e,i.top,u,d,Q(d,1.5),Q(u,1.5)),J(e,i.edge,Q(u,1.5),Q(d,1.5)),K(Q(u,1.5),Q(d,1.5))}function gi(e,t,n,r){let i=Q(Wi(t.tn,t.te,t.ts,t.tw),n*1.35);return q(e,r.top,t.tw,t.tn,i),q(e,r.top,t.tn,t.te,i),q(e,r.wallL,t.tw,i,t.ts),q(e,r.wallR,t.ts,i,t.te),J(e,r.edge,t.tn,i,.7),{a:i,b:i,apex:i}}function _i(e,t,n,r,i,a){let[o,s]=ai(n,r),[c,l,u,d]=r===`x`?[n.tn,n.te,n.ts,n.tw]:[n.te,n.ts,n.tw,n.tn],f=Q(o,i),p=Q(s,i),m=Q(Z(d,o,.5),i*.86),h=Q(Z(u,s,.5),i*.86),g=Q(Z(c,o,.5),i*.86),_=Q(Z(l,s,.5),i*.86);return H(e,a.wallL,d,u,h,m),H(e,a.top,m,h,p,f),H(e,t.palette.windowLit,f,p,_,g),H(e,a.wallR,g,_,l,c),J(e,a.edge,f,p,.7),K(f,p)}function vi(e,t,n,r){let i=Wi(t.tn,t.te,t.ts,t.tw),a=Q(i,n*2.1),o=.42,s=Q(Z(t.tn,i,o),n*1.05),c=Q(Z(t.te,i,o),n*1.05),l=Q(Z(t.ts,i,o),n*1.05),u=Q(Z(t.tw,i,o),n*1.05);return H(e,r.top,t.tn,t.te,c,s),H(e,r.wallR,t.te,t.ts,l,c),H(e,r.wallL,u,l,t.ts,t.tw),H(e,r.top,t.tn,s,u,t.tw),q(e,r.top,s,c,a),q(e,r.wallR,c,l,a),q(e,r.wallL,l,u,a),q(e,r.top,u,s,a),{a,b:a,apex:a}}var yi=34;function bi(e,t,n,r,i,a){if(!i)return;let o=(e,t,r,i)=>Hi(n.ta,n.tb,n.ga,n.gb,e,t,r,i),s=(t,n,r,i)=>{let a=o(t,t,n,n)[0],s=o(r,r,i,i)[0];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)},c=w(r.seed^1327217884^a*2654435769);switch(e.strokeStyle=t.palette.masonry,e.lineWidth=.55,e.globalAlpha=t.palette.dark?.3:.22,e.beginPath(),r.material.wall){case`brick`:for(let e=1;e<=6;e++){let t=.08+e*.86/7;s(.02,t,.98,t);let n=e%2==0?.2:.36;for(let e=n;e<.96;e+=.42){let n=.86/7/2;s(e,t-n,e,t+n)}}break;case`stone`:for(let e=1;e<=4;e++){let t=.1+e*.82/5;s(.02,t,.98,t);let n=.18+c()*.22,r=.58+c()*.24,i=.82/5/2;s(n,t-i,n,t+i),s(r,t-i,r,t+i)}break;case`timber`:for(let e=1;e<=7;e++){let t=.06+e*.88/8;s(.02,t,.98,t)}break;case`stucco`:for(let e=0;e<6;e++){let e=.1+c()*.76,t=.12+c()*.72;s(e,t,Math.min(.94,e+.06+c()*.08),t+(c()-.5)*.03)}break;case`iron`:case`glass`:for(let e=1;e<=6;e++){let t=e/7;s(t,.05,t,.95)}break;default:break}e.stroke(),e.globalAlpha=1}function xi(e,t,n,r,i){let a=w(r.seed^N.FACADE),o=Math.max(1,Math.min(3,r.storeys)),s=Math.max(1,Math.min(i?3:4,r.bays)),c=n.te.x-n.tw.x>=yi,l=[{q:{ta:n.tw,tb:n.ts,ga:n.gw,gb:n.gs},bays:s},{q:{ta:n.ts,tb:n.te,ga:n.gs,gb:n.ge},bays:Math.max(1,s-1)}];for(let n=0;n<l.length;n++){let{q:i,bays:s}=l[n];bi(e,t,i,r,c,n),wi(e,t,i,r,c,s),Ti(e,i,o,s,c,()=>a()<.24?t.palette.windowLit:t.palette.window)}Si(e,t,n,r),r.awning&&Yr(e,t,n,r)}function Si(e,t,n,r){let i=(e,t,r,i)=>Hi(n.ts,n.te,n.gs,n.ge,e,t,r,i),a=(e,t)=>i(e,e,t,t)[0];switch(r.ground){case`shopfront`:H(e,t.palette.sidewalk,...i(.05,.95,.5,.59)),H(e,t.palette.dark?t.palette.windowLit:t.palette.window,...i(.06,.43,.61,.88)),H(e,t.palette.dark?t.palette.windowLit:t.palette.window,...i(.63,.94,.61,.88)),H(e,t.palette.window,...i(.46,.6,.64,.98)),H(e,t.palette.windowLit,...i(.46,.6,.59,.68)),H(e,t.palette.masonry,...i(.06,.94,.88,.98)),e.strokeStyle=t.palette.masonry,e.lineWidth=.8,e.beginPath();for(let t of[.24,.43,.63,.79]){let n=a(t,.61),r=a(t,.88);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y)}e.stroke();break;case`arcade`:{let n=Math.max(2,Math.min(4,r.bays));for(let r=0;r<n;r++){let a=.88/n,o=.06+r*a+a*.16,s=.06+(r+1)*a-a*.16;H(e,t.palette.window,...i(o,s,.58,.98))}break}case`cart-door`:{H(e,t.palette.window,...i(.24,.74,.5,.98)),e.strokeStyle=t.palette.masonry,e.lineWidth=.8,e.beginPath();let n=a(.24,.5),r=a(.74,.5),o=a(.24,.98),s=a(.74,.98);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.moveTo(n.x,n.y),e.lineTo(s.x,s.y),e.moveTo(r.x,r.y),e.lineTo(o.x,o.y),e.stroke();break}case`portico`:{for(let n of[.2,.42,.64])H(e,t.palette.sidewalk,...i(n,n+.08,.55,.98));let n=i(.14,.78,.44,.55);H(e,t.palette.sidewalk,...n);let r=a(.14,.44),o=a(.78,.44),s=X(r,o);q(e,t.palette.sidewalk,r,{x:s.x,y:s.y-Math.max(2,(o.x-r.x)*.08)},o),e.strokeStyle=t.palette.masonry,e.lineWidth=.7,e.beginPath(),e.moveTo(n[0].x,n[0].y),e.lineTo(n[1].x,n[1].y),e.stroke();break}default:{H(e,t.palette.sidewalk,...i(.09,.32,.54,.99)),H(e,t.palette.window,...i(.125,.285,.64,.99)),H(e,t.palette.windowLit,...i(.125,.285,.55,.65)),e.strokeStyle=t.palette.masonry,e.globalAlpha=.72,e.lineWidth=.65,e.beginPath();let o=a(.135,.82),s=a(.275,.82);e.moveTo(o.x,o.y),e.lineTo(s.x,s.y),e.stroke(),e.globalAlpha=1;let c=a(.075,.98),l=a(.335,.98);if(H(e,t.palette.sidewalk,c,l,{x:l.x+1.2,y:l.y+2.5},{x:c.x+1.2,y:c.y+2.5}),n.te.x-n.tw.x>=38&&(r.archetype===`cottage`||r.archetype===`farmhouse`||r.archetype===`cottage-row`||r.archetype===`boarding-house`)){let n=i(.055,.355,.47,.54);H(e,t.palette.masonry,...n),e.strokeStyle=t.palette.sidewalk,e.lineWidth=.75,e.beginPath();for(let t of[.08,.33]){let n=a(t,.53),r=a(t,.96);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y)}e.stroke()}break}}}function Ci(e,t,n,r,i){let a=r.trim;if(!a.cornice&&!a.stringCourse&&!a.parapet&&!a.quoins)return;let o=(t,r,i)=>{e.strokeStyle=r,e.lineWidth=i,e.beginPath();for(let[r,i,a,o]of[[n.tw,n.ts,n.gw,n.gs],[n.ts,n.te,n.gs,n.ge]]){let n=Hi(r,i,a,o,0,1,t,t);e.moveTo(n[0].x,n[0].y),e.lineTo(n[1].x,n[1].y)}e.stroke()};if(a.cornice&&o(.06,i.edge,1.1),a.parapet&&o(.14,i.edge,.7),a.stringCourse&&r.storeys>=3){let e=Math.min(3,r.storeys-1);for(let t=1;t<=e;t++)o(.12+t*.74/(e+1),i.wallR,.7)}if(a.quoins){e.fillStyle=i.edge,e.globalAlpha=.7;for(let t=0;t<4;t++){let r=.12+t*.2;H(e,i.edge,...Hi(n.ts,n.te,n.gs,n.ge,0,.07,r,r+.1))}e.globalAlpha=1}}function wi(e,t,n,r,i,a){let o=(e,t,r,i)=>Hi(n.ta,n.tb,n.ga,n.gb,e,t,r,i);if(e.globalAlpha=.5,H(e,t.palette.masonry,...o(0,1,.93,1)),e.globalAlpha=1,e.globalAlpha=.45,H(e,t.palette.sidewalk,...o(0,1,.02,.07)),e.globalAlpha=1,!i)return;let s=r.band!==`village`;if(e.globalAlpha=.3,s&&a>1)for(let n=1;n<a;n++){let r=.09+.82*n/a;H(e,t.palette.sidewalk,...o(r-.012,r+.012,.07,.93))}if(H(e,t.palette.sidewalk,...o(0,.035,.07,.93)),H(e,t.palette.sidewalk,...o(.965,1,.07,.93)),e.globalAlpha=1,r.material.wall===`timber`&&(r.archetype===`farmhouse`||r.archetype===`barn`||r.archetype===`smithy`||r.archetype===`mill`)){e.strokeStyle=t.palette.masonry,e.globalAlpha=.55,e.lineWidth=1,e.beginPath();let n=.5,r=o(.03,.03,n,n)[0],i=o(.97,.97,n,n)[0];e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);for(let t=0;t<=a;t++){let n=.06+.88*t/Math.max(1,a),r=o(n,n,.08,.08)[0],i=o(n,n,.92,.92)[0];e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}for(let t=0;t<a;t++){let n=.06+.88*t/Math.max(1,a),r=.06+.88*(t+1)/Math.max(1,a),i=o(n,n,.5,.5)[0],s=o(r,r,.88,.88)[0];e.moveTo(i.x,i.y),e.lineTo(s.x,s.y)}e.stroke(),e.globalAlpha=1}}function Ti(e,t,n,r,i,a){let o=(e,n,r,i)=>Hi(t.ta,t.tb,t.ga,t.gb,e,n,r,i);for(let s=0;s<n;s++)for(let c=0;c<r;c++){let{u0:l,u1:u,v0:d,v1:f}=Kr(Math.abs(t.tb.x-t.ta.x),Math.abs(t.ga.y-t.ta.y),n,r,s,c),p=a();if(i&&(e.globalAlpha=.55,H(e,Di,...o(l-.008,u+.008,d-.022,d)),e.globalAlpha=.8,H(e,Ei,...o(l-.016,u+.016,f,f+.022)),e.globalAlpha=1),H(e,p,...o(l,u,d,f)),i){e.strokeStyle=Di,e.globalAlpha=.5,e.lineWidth=.7,e.beginPath();let t=(l+u)/2,n=o(t,t,d,d)[0],r=o(t,t,f,f)[0];e.moveTo(n.x,n.y),e.lineTo(r.x,r.y);let i=d+(f-d)*.42,a=o(l,l,i,i)[0],s=o(u,u,i,i)[0];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y),e.stroke(),e.globalAlpha=1}}}var Ei=`#cfc6b4`,Di=`#3a342c`;function Oi(e,t,n,r,i,a,o,s,c){let l=w(r.seed^N.ROOF_FURNITURE),u=n.te.x-n.tw.x,d=Math.max(2,u*(s?.055:.07)),f=(e,t)=>Math.max(0,Math.min(e,o/t));for(let n=0;n<r.chimneys;n++){let a=r.chimneys===1?.5:.27+n/(r.chimneys-1)*.46,o=Z(i.a,i.b,a),s=f(d,1.9);if(s<1.5)continue;let u=o.x+(l()-.5)*s*.6;zi(e,u,o.y,s,s*1.9,t.palette.masonry),c.push({x:u,y:o.y-s*1.9})}if(r.cupola&&r.cap!==`clock-tower`){let n=f(u*.15,$r.cupola);n>=3&&Bi(e,i.apex.x,i.apex.y,n,r.clock,t)}switch(r.cap){case`bellcote`:{let n=f(d*2,$r.bellcote);n>=2.5&&Pi(e,Z(i.a,i.b,.14),n,t);break}case`finial`:{let n=f(d*1.8,$r.finial);n>=2&&Fi(e,i.a,n,t.palette.masonry);break}case`clock-tower`:{let r=f((n.te.x-n.tw.x)*.16,$r[`clock-tower`]);r>=3&&Ii(e,i.apex,r,t);break}case`lantern`:{let n=f(r.archetype===`signal-tower`?u*.34:d*2.2,$r.lantern);n>=3&&Ri(e,i.apex,n,t);break}default:break}if(r.dormers>0&&u>=28){let n=Math.min(3,r.dormers);for(let r=0;r<n;r++){let o=Z(i.a,i.b,n===1?.5:.25+r/(n-1)*.5),s=o.y+a*.45,c=Math.min(d*.9,a*.28);c>=2.4&&Vi(e,o.x,s,c,t.palette.window,t.palette.masonry)}}}function ki(e,t){let n=t/2,r=t/4;return{n:{x:e.x,y:e.y-r},e:{x:e.x+n,y:e.y},s:{x:e.x,y:e.y+r},w:{x:e.x-n,y:e.y},c:e}}var Ai=`rgba(0, 0, 0, 0.3)`;function ji(e,t,n,r,i=1){let a=ki(Q(t.c,n),t.e.x-t.w.x);return e.globalAlpha=i,e.fillStyle=r,Y(e,[a.w,a.s,t.s,t.w],!0),e.fill(),Y(e,[a.s,a.e,t.e,t.s],!0),e.fill(),e.fillStyle=Ai,Y(e,[a.s,a.e,t.e,t.s],!0),e.fill(),e.globalAlpha=1,a}function Mi(e,t,n,r){let i=Q(t.c,n);q(e,r,t.w,t.n,i),q(e,r,t.n,t.e,i),e.fillStyle=Ai,Y(e,[t.n,t.e,i],!0),e.fill(),q(e,r,t.w,t.s,i),q(e,r,t.s,t.e,i),e.fillStyle=Ai,Y(e,[t.s,t.e,i],!0),e.fill()}function Ni(e,t,n,r,i){let a=X(X(n.w,n.s),X(t.w,t.s));e.fillStyle=i.palette.windowLit,e.beginPath(),e.arc(a.x,a.y,r,0,Math.PI*2),e.fill(),e.strokeStyle=i.palette.window,e.lineWidth=.7,e.stroke()}function Pi(e,t,n,r){let i=ki(t,n*.64),a=ji(e,i,n,r.palette.masonry),o=X(X(a.w,a.s),X(i.w,i.s));e.fillStyle=r.palette.window,e.fillRect(o.x-n*.12,o.y-n*.28,n*.24,n*.5),Mi(e,a,n*.5,r.palette.domeAccent)}function Fi(e,t,n,r){e.strokeStyle=r,e.lineWidth=1;let i=t.y-n*.68;e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(t.x,t.y-n),e.moveTo(t.x-n*.2,i),e.lineTo(t.x+n*.38,i),e.stroke(),q(e,r,{x:t.x+n*.38,y:i},{x:t.x+n*.18,y:i-n*.12},{x:t.x+n*.18,y:i+n*.12})}function Ii(e,t,n,r){let i=ki(t,n),a=n*1.5,o=ji(e,i,a,r.palette.sidewalk),s=ki(Q(i.c,a*.86),n);e.strokeStyle=r.palette.masonry,e.lineWidth=.7,Y(e,[s.w,s.s,s.e],!1),e.stroke(),Mi(e,o,n*.88,r.palette.domeAccent),Ni(e,i,o,Math.max(1.6,n*.2),r)}function Li(e,t,n,r,i,a){if(a===`bandstand`){let a=Math.min(r,i/.95);if(a<4)return;Mi(e,ji(e,ji(e,ki(n,a),a*.12,t.palette.park.path),a*.38,t.palette.sidewalk,.55),a*.45,t.palette.domeAccent);return}let o=Math.min(r*.32,i/1.9);o<2||Mi(e,ji(e,ki(n,o),o*1.6,t.palette.masonry),o*.3,t.palette.masonry)}function Ri(e,t,n,r){let i=ki(t,n),a=ji(e,i,n*.7,r.palette.windowLit,.85);e.strokeStyle=r.palette.masonry,e.lineWidth=.6,e.globalAlpha=.5,Y(e,[X(a.w,a.s),X(i.w,i.s)],!1),e.stroke(),Y(e,[X(a.s,a.e),X(i.s,i.e)],!1),e.stroke(),e.globalAlpha=1,Mi(e,ji(e,a,n*.1,r.palette.masonry),n*.55,r.palette.domeAccent)}function zi(e,t,n,r,i,a){let o=r/2,s=n-i+.45,c=Math.max(.8,r*.34),l=s+c;e.fillStyle=a,Y(e,[{x:t-o,y:l},{x:t,y:l+o*.45},{x:t,y:n+o*.45},{x:t-o,y:n}],!0),e.fill(),e.globalAlpha=.72,Y(e,[{x:t,y:l+o*.45},{x:t+o,y:l},{x:t+o,y:n},{x:t,y:n+o*.45}],!0),e.fill(),e.globalAlpha=1,e.fillStyle=Di,e.fillRect(t-o-.5,l-1,r+1,Math.max(1,r*.16));let u=r>=4.5?2:1,d=Math.max(.8,r*(u===2?.27:.34));for(let n=0;n<u;n++){let i=u===1?t:t+(n===0?-r*.23:r*.23);e.fillRect(i-d/2,s,d,c+.4),e.fillRect(i-d*.62,s-.45,d*1.24,.7)}}function Bi(e,t,n,r,i,a){let o=ki({x:t,y:n},r*.72),s=r*.85,c=ji(e,o,s,a.palette.sidewalk);Mi(e,ki(c.c,r),r*.65,a.palette.domeAccent),i&&Ni(e,o,c,Math.max(1.4,r*.12),a),e.strokeStyle=a.palette.masonry,e.lineWidth=.8,e.beginPath(),e.moveTo(t,n-s-r*.62),e.lineTo(t,n-s-r*.95),e.stroke()}function Vi(e,t,n,r,i,a){let o=Math.max(2.4,r),s=o*.94;e.fillStyle=i,e.fillRect(t-o/2,n-s,o,s),q(e,a,{x:t-o*.72,y:n-s},{x:t,y:n-s-o*.66},{x:t+o*.72,y:n-s})}function Hi(e,t,n,r,i,a,o,s){let c=(i,a)=>Z(Z(e,t,i),Z(n,r,i),a);return[c(i,o),c(a,o),c(a,s),c(i,s)]}function q(e,t,n,r,i){e.fillStyle=t,Y(e,[n,r,i],!0),e.fill()}function J(e,t,n,r,i=.85){e.strokeStyle=t,e.lineWidth=i,e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.stroke()}function Y(e,t,n){let r=t[0];if(r){e.beginPath(),e.moveTo(r.x,r.y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);n&&e.closePath()}}function X(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Z(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function Ui(e,t,n){return Z(e,t,n)}function Q(e,t){return{x:e.x,y:e.y-t}}function Wi(e,t,n,r){return{x:(e.x+t.x+n.x+r.x)/4,y:(e.y+t.y+n.y+r.y)/4}}var Gi=14;function Ki(e,t,n,r){return e!==`city`&&t!==!0&&n>0&&ie(r)}function qi(e,t){let n=t.now??Date.now(),r=t.tier===`street`&&!t.ageLens&&t.atlas?_t(t.model):null;if(t.tier===`city`){let r=new sr,i=[];for(let e of t.geom.order){let a=t.geom.geoms[e];if(!Qn(t.cam,a,t.viewW,t.viewH))continue;let o=a.block,s=t.ageLens?pe(o.lastTouchedAt??o.placedAt,n):void 0;if(o.state===`tombstoned`){r.add(t.ageLens?t.palette.tombstone:t.palette.earth,...Xi(t,o));continue}if(o.state===`new`&&!t.ageLens&&!o.phantom){r.add(t.palette.newBlock,...Xi(t,o));continue}let c=we(o.lang,t.palette,s),l=t.ageLens?c.top:a.style?.archetype===`field`?ea(a.style,t.palette):a.style?.archetype===`park`?t.palette.park.lawn:c.top;r.add(l,...Xi(t,o)),o.landmark&&i.push(a)}r.flush(e),e.fillStyle=t.palette.domeAccent;for(let n of i){let r=Zi(t,n);e.beginPath(),e.arc(r.x,r.y-3,2,0,Math.PI*2),e.fill()}return}for(let i of t.geom.order){let a=t.geom.geoms[i];if(Qn(t.cam,a,t.viewW,t.viewH)){if(zr(e,t,a.block),Qi(e,t,a,n),r){let n=r.get(a.block.id);if(n&&t.atlas)for(let r of n){let n=L(r.x,r.y),i=R(t.cam,n.u,n.v),a=r.size*t.cam.scale*(r.sprite.startsWith(`tree`)?2.6:2),o=t.atlas.index[r.sprite]*t.atlas.cell;e.drawImage(t.atlas.canvas,o,0,t.atlas.cell,t.atlas.cell,i.x-a/2,i.y-a,a,a)}}Ji(e,t,a)}}}function Ji(e,t,n){if(t.ageLens)return;let r=Zt(n.block);if(!r)return;let i=tr(t.model,n.block.id),a=Ki(t.tier,t.ageLens,i.length,n.block)?Qt(i):null,o=a?$n(t.cam,a):Yi(t,n);$t(e,t.palette,r,o.x,o.y,n.block.id,Xt(t.cam.scale),t.animationTime??0)}function Yi(e,t){let n=Zi(e,t);return{x:n.x,y:n.y-Zn(t,e.cam.scale)*e.cam.scale}}function Xi(e,t){let n=Hn(t.rect);return[R(e.cam,n.n.u,n.n.v),R(e.cam,n.e.u,n.e.v),R(e.cam,n.s.u,n.s.v),R(e.cam,n.w.u,n.w.v)]}function Zi(e,t){let n=t.block.rect,r=L(n.x+n.w/2,n.y+n.h/2),i=R(e.cam,r.u,r.v);return{x:i.x,y:i.y-t.hIso*e.cam.scale}}function Qi(e,t,n,r){let i=n.block,a=t.palette,[o,s,c,l]=Xi(t,i),u=s.x-l.x;if(i.state===`tombstoned`){if(e.fillStyle=t.ageLens?a.tombstone:a.earth,e.globalAlpha=t.ageLens?.4:.7,V(e,o,s,c,l),e.fill(),e.globalAlpha=1,u>=10&&!t.ageLens){let n=w(C(i.id));e.fillStyle=a.rubble;let r=4+Math.floor(n()*4);for(let a=0;a<r;a++){let r=L(i.rect.x+i.rect.w*(.12+.76*n()),i.rect.y+i.rect.h*(.12+.76*n())),a=R(t.cam,r.u,r.v),o=Math.min(4,Math.max(1,.1*u*n()));e.fillRect(a.x,a.y-o/2,o,o/2+1)}e.strokeStyle=a.blockStroke,e.globalAlpha=.6,e.setLineDash([3,3]),V(e,o,s,c,l),e.stroke(),e.setLineDash([]),e.globalAlpha=1}return}let d=z(t.cam,i.rect,n.hIso);if(i.phantom){let n=t.ageLens?pe(i.lastTouchedAt??i.placedAt,r):void 0,u=we(i.lang,a,n);e.globalAlpha=.3,or(e,z(t.cam,i.rect,3*I),u),e.globalAlpha=1;let d=Ze(e,a.dark?`#8b8f99`:`#8a7f64`);d&&(e.fillStyle=d,V(e,o,s,c,l),e.fill()),e.strokeStyle=a.blockStroke,e.setLineDash([4,3]),V(e,o,s,c,l),e.stroke(),e.setLineDash([]);return}if(i.state===`new`&&!t.ageLens){if(e.fillStyle=a.earth,V(e,o,s,c,l),e.fill(),e.strokeStyle=a.newBlock,e.lineWidth=1.5,e.setLineDash([4,3]),V(e,o,s,c,l),e.stroke(),e.setLineDash([]),t.tier===`street`&&u>=Gi){let t=w(C(i.id)),n=(l.x+s.x)/2+(t()-.5)*u*.3,r=(o.y+c.y)/2+(c.y-o.y)*.2,d=r-Math.max(12,u*.5),f=u*.35*(t()<.5?-1:1);e.strokeStyle=a.crane,e.lineWidth=1.5,e.beginPath(),e.moveTo(n,r),e.lineTo(n,d),e.lineTo(n+f,d),e.moveTo(n+f*.8,d),e.lineTo(n+f*.8,d+Math.max(6,u*.15)),e.stroke()}return}let f=t.ageLens?pe(i.lastTouchedAt??i.placedAt,r):void 0,p=n.style&&!t.ageLens&&t.tier!==`city`?{...n.style.material,urbanity:j(i),variance:(n.style.seed>>>8)%200/100-1}:void 0,m=we(i.lang,a,f,p),h=i.buildingCount>0?tr(t.model,i.id):$i,g=Ki(t.tier,t.ageLens,h.length,i)?h:$i;if(g.length>0){let n=z(t.cam,i.rect,zn);cr(e,t,i,n),aa(e,t,i,la(e,t,g,n.liftPx,i,m));return}let _=n.style??Ue(i);if(!t.ageLens&&_.archetype===`field`){ra(e,t,n,_);return}if(!t.ageLens&&_.archetype===`park`){ia(e,t,n,_,m);return}let v=t.ageLens?null:sa(t,i,n,_);v?.behind&&ca(e,t,v.prism,_,m);let y=ei(e,t,d,_,m,{suppressDetails:t.ageLens===!0});v&&!v.behind&&ca(e,t,v.prism,_,m),e.strokeStyle=m.edge,e.lineWidth=1,e.beginPath(),e.moveTo(d.tw.x,d.tw.y),e.lineTo(d.tn.x,d.tn.y),e.lineTo(d.te.x,d.te.y),e.stroke(),aa(e,t,i,y.stacks)}var $i=[];function ea(e,t){return t.farm.crops[(e.seed>>>4)%4]}var ta={district:3.2,street:1.6},na=80;function ra(e,t,n,r){let i=n.block,a=t.palette,o=i.rect,[s,c,l,u]=Xi(t,i),d=c.x-u.x;if(e.fillStyle=ea(r,a),V(e,s,c,l,u),e.fill(),d>=16){let n=ta[t.tier===`street`?`street`:`district`],i=r.ridge===`x`,s=i?o.h:o.w,c=Math.min(na,Math.floor(s/n));e.strokeStyle=a.farm.furrow,e.globalAlpha=.38,e.lineWidth=Math.max(.5,.22*t.cam.scale),e.beginPath();for(let r=1;r<=c;r++){let a=(r-.5)*n,s=i?L(o.x+.6,o.y+a):L(o.x+a,o.y+.6),c=i?L(o.x+o.w-.6,o.y+a):L(o.x+a,o.y+o.h-.6),l=R(t.cam,s.u,s.v),u=R(t.cam,c.u,c.v);e.moveTo(l.x,l.y),e.lineTo(u.x,u.y)}e.stroke(),e.globalAlpha=1}if(d>=24){let n=Math.max(2,Math.min(o.w,o.h)*.22),r={x:o.x+o.w-n-.8,y:o.y+o.h-n-.8,w:n,h:n*.8};or(e,z(t.cam,r,3*I*.55),a.farm.shed)}}function ia(e,t,n,r,i){let a=n.block,o=t.palette,s=a.rect,[c,l,u,d]=Xi(t,a),f=l.x-d.x;if(e.fillStyle=o.park.lawn,V(e,c,l,u,d),e.fill(),f<14)return;let p=s.x+s.w/2,m=s.y+s.h/2,h=Math.min(1.4,Math.min(s.w,s.h)*.12);e.fillStyle=o.park.path;for(let n of[{x:s.x,y:m-h/2,w:s.w,h},{x:p-h/2,y:s.y,w:h,h:s.h}]){let r=Hn(n);V(e,R(t.cam,r.n.u,r.n.v),R(t.cam,r.e.u,r.e.v),R(t.cam,r.s.u,r.s.v),R(t.cam,r.w.u,r.w.v)),e.fill()}let g=Math.min(s.w,s.h)*.34,_=Hn({x:p-g/2,y:m-g/2,w:g,h:g});if(e.fillStyle=i.top,e.globalAlpha=.85,V(e,R(t.cam,_.n.u,_.n.v),R(t.cam,_.e.u,_.e.v),R(t.cam,_.s.u,_.s.v),R(t.cam,_.w.u,_.w.v)),e.fill(),e.globalAlpha=1,f>=30){let i=R(t.cam,L(p,m).u,L(p,m).v),a=Zn(n,t.cam.scale)*t.cam.scale,o=Math.min(s.w,s.h)*.3*t.cam.scale,c=(r.seed>>>6)%3;c===0?Li(e,t,i,o,a,`bandstand`):c===1?Pr(e,t,i,o*.6):Li(e,t,i,o,a,`obelisk`)}if(t.tier===`street`&&t.atlas){let n=w(r.seed^1374496523),i=2+Math.floor(n()*3);for(let r=0;r<i;r++){let i=r%2==0?.2:.8,a=r<2?.2:.8,o=s.x+s.w*(i+(n()-.5)*.14),c=s.y+s.h*(a+(n()-.5)*.14),l=(1.8+n()*1.2)*t.cam.scale*2,u=n()<.75?`tree1`:`tree2`,d=R(t.cam,L(o,c).u,L(o,c).v),f=t.atlas.index[u]*t.atlas.cell;e.drawImage(t.atlas.canvas,f,0,t.atlas.cell,t.atlas.cell,d.x-l/2,d.y-l,l,l)}}}function aa(e,t,n,r){t.tier!==`street`||t.ageLens||r.length===0||n.health?.zone===`industrial`&&Wr(e,t.palette,r,n.id,t.cam.scale,t.animationTime??0)}var oa=26;function sa(e,t,n,r){let i=r.massing;if(i.kind===`none`||e.tier===`city`||(t.rect.w+t.rect.h)*e.cam.scale<oa)return null;let a={x:t.rect.x+t.rect.w*i.u0,y:t.rect.y+t.rect.h*i.v0,w:t.rect.w*(i.u1-i.u0),h:t.rect.h*(i.v1-i.v0)};return{prism:z(e.cam,a,n.hIso*i.height),behind:i.behind}}function ca(e,t,n,r,i){ei(e,t,n,{...r,chimneys:0,dormers:0,awning:!1,cupola:!1,clock:!1,cap:`none`},i,{compact:!0,suppressDetails:t.ageLens===!0}),e.strokeStyle=i.edge,e.lineWidth=.8,e.beginPath(),e.moveTo(n.tw.x,n.tw.y),e.lineTo(n.tn.x,n.tn.y),e.lineTo(n.te.x,n.te.y),e.stroke()}function la(e,t,n,r,i,a){let o=[];for(let s=0;s<n.length;s++){let c=n[s],l=z(t.cam,c.rect,Bn(c.height)),u=-r,d={gn:da(l.gn,u),ge:da(l.ge,u),gs:da(l.gs,u),gw:da(l.gw,u),tn:da(l.tn,u),te:da(l.te,u),ts:da(l.ts,u),tw:da(l.tw,u),liftPx:l.liftPx},f=We(c,i);i.landmark&&s===n.length-1&&(f.roof=`hip`,f.cupola=!0,f.clock=!0);let p=t.ageLens||t.tier===`city`?a:we(i.lang,t.palette,void 0,{...f.material,urbanity:j(i),variance:(f.seed>>>8)%200/100-1});e.globalAlpha=.5+.45*c.height;let m=ei(e,t,d,f,p,{compact:!0,suppressDetails:t.ageLens===!0});e.globalAlpha=1,o.unshift(...m.stacks)}return o}function ua(e,t){let n=(n,r,i)=>{let a=t.geom.geoms.find(e=>e.block.id===n);if(!a||!Qn(t.cam,a,t.viewW,t.viewH))return;let o=z(t.cam,a.block.rect,a.hIso);e.strokeStyle=r,e.lineWidth=i,ar(e,o),e.stroke()};t.hoverId&&t.hoverId!==t.selectedId&&n(t.hoverId,t.palette.hover,1.5),t.selectedId&&n(t.selectedId,t.palette.selected,2)}function da(e,t){return{x:e.x,y:e.y+t}}function fa(){return{accepted:new Set,measure:new Map}}var pa=`12px ui-sans-serif, system-ui, sans-serif`,ma=`13px ui-sans-serif, system-ui, sans-serif`,ha=`11px ui-sans-serif, system-ui, sans-serif`,ga=`10px ui-sans-serif, system-ui, sans-serif`,_a=16,va=2.35,ya=2.75,ba=18,xa=28;function Sa(e,t,n,r){let i=`${n}|${r}`,a=t?.measure.get(i);if(a!==void 0)return a;e.font=n;let o=0;try{o=e.measureText(r).width}catch{o=r.length*6}return t&&(t.measure.size>8192&&t.measure.clear(),t.measure.set(i,o)),o}function Ca(e,t,n){return e<=t?0:e>=n?1:(e-t)/(n-t)}function wa(e,t){let{cam:n,model:r,palette:i}=t,a=t.labels,o=[];for(let t of r.districts){if(t.displayLabel===void 0||(t.rect.w+t.rect.h)*n.scale<40)continue;let r=t.depth<=1?1-.85*Ca(n.scale,1.6,2.6):1-.85*Ca(n.scale,2,3.2);if(r<=.05)continue;let i=t.depth<=1?ma:pa,s=Sa(e,a,i,t.displayLabel),c=t.labelPlate?{x:t.labelPlate.x,y:t.labelPlate.y}:{x:t.rect.x,y:t.rect.y},l=R(n,L(c.x,c.y).u,L(c.x,c.y).v);o.push({id:`d:${t.id}`,text:t.displayLabel,priority:3+t.depth,x:l.x,y:l.y-8,w:s+12,h:17,alpha:r,kind:`district`,font:i})}for(let r of t.geom.order){let i=t.geom.geoms[r],s=i.block;if(s.state===`tombstoned`||!Qn(n,i,t.viewW,t.viewH))continue;let c=s.id===t.selectedId,l=s.id===t.hoverId,u=s.landmark===!0;if(!c&&!l&&!u){if(t.tier!==`street`||s.rect.w*n.scale*2<44)continue;let r=.9*Ca(n.scale,1.2,1.6);if(r<=.05)continue;let i=Sa(e,a,ha,s.label),c=R(n,L(s.rect.x+s.rect.w,s.rect.y+s.rect.h).u,L(s.rect.x+s.rect.w,s.rect.y+s.rect.h).v);o.push({id:`b:${s.id}`,text:s.label,priority:10,x:c.x-i/2,y:c.y+2,w:i,h:12,alpha:r,kind:`block`,font:ha});continue}let d=ha,f=Sa(e,a,d,s.label),p=L(s.rect.x+s.rect.w/2,s.rect.y+s.rect.h/2),m=R(n,p.u,p.v);o.push({id:`b:${s.id}`,text:s.label,priority:c?0:l?1:2,x:m.x-f/2,y:m.y-i.hIso*n.scale-18,w:f,h:13,alpha:1,kind:`landmark`,font:d})}let s=t.ageLens?0:Ca(n.scale,va,ya);if(s>.05){let i=new Set(r.blocks.filter(e=>e.state===`live`&&!e.phantom&&ie(e)).map(e=>e.id));for(let c of r.buildings){if(!i.has(c.blockId)||(c.rect.w+c.rect.h)*n.scale<ba)continue;let r=$n(n,c);if(r.x<-80||r.x>t.viewW+80||r.y<-40||r.y>t.viewH+40)continue;let l=Ta(c.label),u=Sa(e,a,ga,l),d=Math.min(180,Math.max(20,u+10)),f=Math.max(2,Math.min(t.viewW-d-2,r.x-d/2));o.push({id:`s:${c.id}`,text:l,priority:Ea(c.kind,c.lines),x:f,y:r.y-_a-5,w:d,h:_a,alpha:s,kind:`symbol`,font:ga,anchorX:r.x,anchorY:r.y})}}let c=e=>a?.accepted.has(e.id)?e.priority-.5:e.priority;o.sort((e,t)=>c(e)-c(t)||(e.id<t.id?-1:1));let l=[],u=new Set;for(let e of o){let t=a?.accepted.has(e.id)?2:0,n=!1;for(let r of l)if(e.x+t<r.x+r.w&&e.x+e.w-t>r.x&&e.y+t<r.y+r.h&&e.y+e.h-t>r.y){n=!0;break}n||(l.push(e),u.add(e.id))}a&&(a.accepted=u),e.textBaseline=`top`;for(let t of l)e.globalAlpha=t.alpha,e.font=t.font,t.kind===`district`?(e.fillStyle=i.labelPlate,F(e,t.x,t.y,t.w,t.h,3),e.fill(),e.strokeStyle=i.labelPlateStroke,e.lineWidth=1,F(e,t.x,t.y,t.w,t.h,3),e.stroke(),e.fillStyle=i.districtLabel,e.fillText(t.text,t.x+6,t.y+3,t.w-12)):t.kind===`symbol`?(e.strokeStyle=i.labelPlateStroke,e.lineWidth=.8,e.beginPath(),e.moveTo(Math.max(t.x+4,Math.min(t.x+t.w-4,t.anchorX??t.x+t.w/2)),t.y+t.h),e.lineTo(t.anchorX??t.x+t.w/2,t.anchorY??t.y+t.h+5),e.stroke(),e.fillStyle=i.labelPlate,F(e,t.x,t.y,t.w,t.h,3),e.fill(),e.strokeStyle=i.labelPlateStroke,F(e,t.x,t.y,t.w,t.h,3),e.stroke(),e.fillStyle=i.label,e.fillText(t.text,t.x+5,t.y+2,t.w-10)):t.kind===`landmark`?(e.strokeStyle=i.ground,e.lineWidth=3,e.strokeText(t.text,t.x,t.y,t.w+4),e.fillStyle=i.label,e.fillText(t.text,t.x,t.y,t.w+4),e.strokeStyle=i.districtLabel,e.lineWidth=1,e.beginPath(),e.moveTo(t.x+t.w/2,t.y+t.h+1),e.lineTo(t.x+t.w/2,t.y+t.h+5),e.stroke()):(e.strokeStyle=i.ground,e.lineWidth=3,e.strokeText(t.text,t.x,t.y,t.w+4),e.fillStyle=i.label,e.fillText(t.text,t.x,t.y,t.w+4));e.globalAlpha=1}function Ta(e){return e.length<=xa?e:`${e.slice(0,xa-1)}…`}function Ea(e,t){let n=e.toLowerCase(),r=/function|method|constructor|procedure/.test(n)?0:/class|interface|struct|enum|trait|type/.test(n)?1:2,i=Math.min(.2,Math.max(0,t??0)/2e3);return 20+r-i}var Da={added:`#3fb950`,modified:`#d29922`,deleted:`#f85149`,renamed:`#a371f7`},Oa=`#58a6ff`;function ka(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t;if(!r.overlay||r.overlay.changedBlocks.length===0)return;let s=new Map(r.overlay.changedBlocks.map(e=>[e.blockId,e])),c=new Map(t.geom.geoms.map(e=>[e.block.id,e]));if(e.fillStyle=i.ground,e.globalAlpha=.62,e.fillRect(0,0,a,o),e.globalAlpha=1,t.affectedIds&&t.affectedIds.size>0)for(let r of t.affectedIds){if(s.has(r))continue;let t=c.get(r);if(!t||!Qn(n,t,a,o))continue;let i=Hn(t.block.rect),l=t.hIso*n.scale,u=[i.n,i.e,i.s,i.w].map(e=>{let t=R(n,e.u,e.v);return{x:t.x,y:t.y-l}});e.fillStyle=Oa,e.globalAlpha=.18,Aa(e,u),e.fill(),e.globalAlpha=.7,e.strokeStyle=Oa,e.lineWidth=1,Aa(e,u),e.stroke(),e.globalAlpha=1}for(let r of t.geom.geoms){let t=s.get(r.block.id);if(!t||!Qn(n,r,a,o))continue;let i=Da[t.change]??`#888888`,c=z(n,r.block.rect,r.hIso);e.fillStyle=i,e.globalAlpha=r.block.phantom?.45:.85,ar(e,c),e.fill(),e.globalAlpha=1,e.save(),e.shadowColor=i,e.shadowBlur=8,e.strokeStyle=i,e.lineWidth=2,r.block.phantom&&e.setLineDash([4,3]),ar(e,c),e.stroke(),e.restore()}}function Aa(e,t){e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);e.closePath()}var ja=40;function Ma(e,t){let{cam:n,model:r,palette:i}=t;if(t.tier===`city`||r.roads.length===0)return;let a=new Map;for(let e of r.blocks)a.set(e.id,e.rect);if(t.selectedId){let o=An(r,t.selectedId,a);if(e.strokeStyle=i.selected,e.globalAlpha=.9,e.lineJoin=`round`,o){for(let t of o)if(!(t.points.length<2)){e.lineWidth=t.bidirectional?2.4:2,e.beginPath();for(let r=0;r<t.points.length;r++){let i=t.points[r],a=L(i.x,i.y),o=R(n,a.u,a.v);r===0?e.moveTo(o.x,o.y):e.lineTo(o.x,o.y)}e.stroke()}}else Na(e,t,t.selectedId,a,2,.9);e.globalAlpha=1}t.hoverId&&t.hoverId!==t.selectedId&&Na(e,t,t.hoverId,a,1.5,.35)}function Na(e,t,n,r,i,a){let{cam:o,model:s,palette:c}=t;e.strokeStyle=c.selected,e.globalAlpha=a,e.lineWidth=i;let l=0;e.beginPath();for(let t of s.roads){if(t.a!==n&&t.b!==n)continue;if(l>=ja)break;let i=r.get(t.a),a=r.get(t.b);if(!i||!a)continue;let s=L(i.x+i.w/2,i.y+i.h/2),c=L(a.x+a.w/2,a.y+a.h/2),u=R(o,s.u,s.v),d=R(o,c.u,c.v);e.moveTo(u.x,u.y),e.lineTo(d.x,d.y),l+=1}e.stroke(),e.globalAlpha=1}function Pa(e,t){e.save(),Mr(e,t),qi(e,t),ua(e,t),Ma(e,t),wa(e,t),ka(e,t),e.restore()}var Fa=[`tree1`,`tree2`,`tree3`,`shrub`,`weed`,`dryPatch`,`deadTree`,`rubble1`,`rubble2`],Ia=24,La=new Map;function Ra(e,t){let n=t>1.5?2:1,r=`${e.dark?`dark`:`light`}|${n}`,i=La.get(r);if(i!==void 0)return i;let a=za(e,n*2);return La.set(r,a),a}function za(e,t){let n=Ia*t,r,i;try{r=document.createElement(`canvas`),r.width=n*Fa.length,r.height=n,i=r.getContext(`2d`)}catch{return null}if(!i)return null;let a=e.dark?`hsl(138 22% 29%)`:`hsl(106 25% 40%)`,o=e.dark?`hsl(152 24% 23%)`:`hsl(142 22% 32%)`,s=e.dark?`#566d47`:`#8f9f61`,c=e.dark?`hsl(140 24% 27%)`:`hsl(108 22% 48%)`,l=e.dark?`hsl(30 25% 25%)`:`hsl(30 35% 40%)`,u=e.dark?`hsl(60 20% 28%)`:`hsl(65 35% 55%)`,d=e.dark?`hsl(38 25% 30%)`:`hsl(42 45% 70%)`,f=e.dark?`hsl(30 12% 32%)`:`hsl(30 15% 45%)`,p={};Fa.forEach((e,t)=>{p[e]=t});let m=(e,r)=>{i.save(),i.translate(e*n+n/2,n/2),i.scale(t,t),r(i),i.restore()},h=(e,t,n,r)=>{e.beginPath(),e.arc(t,n,r,0,Math.PI*2),e.fill()},g=(t,n)=>{t.fillStyle=e.dark?`rgba(0,0,0,0.22)`:`rgba(62,67,39,0.16)`,t.beginPath(),t.ellipse(1,9,n?3.8:7.5,1.7,0,0,Math.PI*2),t.fill(),t.fillStyle=l,t.fillRect(-.8,1,1.6,8),t.strokeStyle=l,t.lineWidth=.9,t.beginPath(),t.moveTo(0,5),t.lineTo(-3.5,-1),t.moveTo(0,4),t.lineTo(4,-2),t.stroke();let r=n?[[0,-7.5,3],[-1.8,-4.5,3.3],[1.5,-3.8,3.2],[-1.5,-.5,3.5],[1.5,.8,3.5]]:[[-5.2,-.5,4],[3.8,0,4.5],[.4,-5.5,4.7],[-4,-5,4.2],[4.8,-4.2,3.4],[0,.5,5]];t.fillStyle=o;for(let[e,n,i]of r)h(t,e,n,i);t.fillStyle=a;for(let[e,n,i]of r)h(t,e-.6,n-1,i*.82);t.fillStyle=s,t.globalAlpha=.5;for(let[e,n,i]of r.slice(0,4))h(t,e-1.2,n-1.9,i*.64);t.globalAlpha=1};m(p.tree1,e=>g(e,!1)),m(p.tree2,e=>g(e,!0)),m(p.tree3,e=>{e.fillStyle=l,e.fillRect(-1,5,2,4);for(let[t,n]of[[7,5],[5.5,1],[4,-3]])e.fillStyle=o,e.beginPath(),e.moveTo(0,n-6),e.lineTo(-t*.6,n-2),e.lineTo(-t*.48,n-1.7),e.lineTo(-t,n+.4),e.quadraticCurveTo(0,n+2,t,n+.4),e.lineTo(t*.52,n-2),e.closePath(),e.fill(),e.fillStyle=a,e.beginPath(),e.moveTo(0,n-6),e.lineTo(-t,n+.4),e.lineTo(-.8,n),e.closePath(),e.fill()}),m(p.shrub,e=>{e.fillStyle=c,h(e,-2.5,2,3.5),h(e,2.5,2,3),h(e,0,-1,3.5)}),m(p.weed,e=>{e.strokeStyle=u,e.lineWidth=1.2,e.beginPath();for(let[t,n]of[[-3,-1.5],[0,.5],[3,2]])e.moveTo(t,6),e.quadraticCurveTo(t+n,0,t+n*1.6,-4);e.stroke()}),m(p.dryPatch,e=>{e.fillStyle=d,e.beginPath(),e.ellipse(0,0,9,6,.4,0,Math.PI*2),e.fill(),e.fillStyle=`rgba(0, 0, 0, 0.08)`,e.beginPath(),e.ellipse(2,1,4,2.5,.2,0,Math.PI*2),e.fill()}),m(p.deadTree,e=>{e.strokeStyle=f,e.lineWidth=1.6,e.beginPath(),e.moveTo(0,8),e.lineTo(0,-2),e.moveTo(0,0),e.lineTo(-4,-5),e.moveTo(0,-2),e.lineTo(3,-7),e.moveTo(0,3),e.lineTo(4,-1),e.stroke()});let _=(t,n)=>{t.fillStyle=e.rubble;for(let[e,r,i]of n)t.fillRect(e,r,i,i)};return m(p.rubble1,e=>_(e,[[-6,-2,4],[-1,2,3],[3,-4,3.5],[4,3,2.5]])),m(p.rubble2,e=>_(e,[[-5,3,3],[-4,-5,2.5],[1,-1,4],[6,-4,2]])),{canvas:r,cell:n,index:p}}var $=n();function Ba(){try{return window.localStorage.getItem(`gezel.mapRenderer`)===`flat`?`flat`:`iso`}catch{return`iso`}}function Va(e){return e.closest(`[data-theme="dark"]`)!=null||!e.closest(`[data-theme="light"]`)&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches}function Ha({model:e,selectedId:t,onSelect:n,affectedIds:r,ageLens:i,renderer:a}){let o=(0,h.useRef)(null),s=(0,h.useRef)(null),c=(0,h.useRef)({scale:1,offsetX:0,offsetY:0}),l=(0,h.useRef)({w:0,h:0}),u=(0,h.useRef)(0),d=(0,h.useRef)(0),f=(0,h.useRef)(-1/0),p=(0,h.useRef)(!1),m=(0,h.useRef)(()=>!1),g=(0,h.useRef)(()=>{}),_=(0,h.useRef)(null),[y,b]=(0,h.useState)(null),[S,C]=(0,h.useState)(null),w=(0,h.useRef)(()=>{}),ae=(0,h.useRef)(fa()),T=a??Ba(),E=(0,h.useMemo)(()=>e.blocks.filter(e=>Zt(e)!==null),[e]),oe=(0,h.useMemo)(()=>new Set(E.map(e=>e.id)),[E]),se=(0,h.useMemo)(()=>Vt(e).animated,[e]),ce=(0,h.useMemo)(()=>{let t=Je(e);return new Set(e.blocks.filter(e=>e.state===`live`&&!e.phantom&&e.health?.zone===`industrial`&&(t.get(e.id)?.chimneys??0)>0).map(e=>e.id))},[e]);w.current=()=>{let n=s.current,a=n?.getContext(`2d`);if(!n||!a)return;let{w:o,h:u}=l.current,f=window.devicePixelRatio||1;a.setTransform(f,0,0,f,0,0);let p=fe(Va(n)),m={cam:c.current,model:e,palette:p,tier:v(c.current.scale),viewW:o,viewH:u,selectedId:t,hoverId:y,atlas:Ra(p,f),animationTime:d.current,...r?{affectedIds:r}:{},...i?{ageLens:i}:{}};T===`iso`?Pa(a,{...m,geom:Xn(e),labels:ae.current}):Pn(a,m)},m.current=()=>{if(p.current||document.visibilityState!==`visible`||i)return!1;let t=v(c.current.scale);if(t===`city`)return!1;let{w:n,h:r}=l.current,a=c.current;return E.length>0&&(T===`iso`?Xn(e).geoms.some(e=>oe.has(e.block.id)&&Qn(a,e,n,r)):E.some(e=>x(a,e.rect,n,r)))?!0:T!==`iso`||t!==`street`?!1:se.some(e=>Un(a,e.reservation,n,r))?!0:ce.size>0&&Xn(e).geoms.some(e=>ce.has(e.block.id)&&Qn(a,e,n,r))},g.current=e=>{if(u.current=0,m.current()&&e-f.current<1e3/30){u.current=requestAnimationFrame(e=>g.current(e));return}f.current=e,d.current=p.current?0:e,w.current(),m.current()&&(u.current=requestAnimationFrame(e=>g.current(e)))};let D=(0,h.useCallback)(()=>{u.current||=requestAnimationFrame(e=>g.current(e))},[]);(0,h.useEffect)(()=>{let e=window.matchMedia?.(`(prefers-reduced-motion: reduce)`),t=()=>{p.current=e?.matches??!1,D()},n=()=>D();return t(),e?.addEventListener(`change`,t),document.addEventListener(`visibilitychange`,n),()=>{e?.removeEventListener(`change`,t),document.removeEventListener(`visibilitychange`,n)}},[D]),(0,h.useEffect)(()=>()=>{u.current&&cancelAnimationFrame(u.current),u.current=0},[]),(0,h.useEffect)(()=>{let e=o.current,t=s.current;if(!e||!t)return;let n=()=>{let n=e.getBoundingClientRect(),r=window.devicePixelRatio||1;l.current={w:n.width,h:n.height},t.width=Math.max(1,Math.round(n.width*r)),t.height=Math.max(1,Math.round(n.height*r)),t.style.width=`${n.width}px`,t.style.height=`${n.height}px`,D()};n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[D]),(0,h.useEffect)(()=>{let{w:t,h:n}=l.current;c.current=T===`iso`?Kn(e.bounds,Xn(e).maxHIso,t||800,n||600):ne(e.bounds,t||800,n||600),C(null),D()},[e,T,D]),(0,h.useEffect)(()=>{D()},[t,y,i,D]);let le=(0,h.useCallback)((t,n)=>{let r=c.current;if(T===`iso`)return ir(Xn(e),r,t,n,!i&&v(r.scale)!==`city`);let a=ee(r,t),o=te(r,n);for(let t=e.blocks.length-1;t>=0;t--){let n=e.blocks[t];if(a>=n.rect.x&&a<=n.rect.x+n.rect.w&&o>=n.rect.y&&o<=n.rect.y+n.rect.h)return n}return null},[e,T,i]),O=(0,h.useCallback)((t,n,r)=>!t||T!==`iso`||t.state===`tombstoned`||!ie(t)||v(c.current.scale)!==`street`?null:rr(e,t.id,c.current,n,r),[e,T]);return(0,h.useEffect)(()=>{let e=s.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect(),r=Math.exp(-t.deltaY*.0015);c.current=re(c.current,r,t.clientX-n.left,t.clientY-n.top),C(null),D()};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[D]),(0,$.jsxs)(`div`,{ref:o,className:`filemap-canvas-wrap`,children:[(0,$.jsx)(`canvas`,{ref:s,className:`filemap-canvas`,onPointerDown:e=>{e.target.setPointerCapture(e.pointerId),_.current={x:e.clientX,y:e.clientY},C(null)},onPointerMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(_.current){let t=e.clientX-_.current.x,n=e.clientY-_.current.y;_.current={x:e.clientX,y:e.clientY};let r=c.current;c.current={...r,offsetX:r.offsetX-t/r.scale,offsetY:r.offsetY-n/r.scale},D();return}let n=e.clientX-t.left,r=e.clientY-t.top,i=le(n,r);b(i?.id??null);let a=O(i,n,r);C(e=>{if(!a)return e===null?e:null;if(e?.building===a)return e;let t=$n(c.current,a);return{building:a,x:t.x,y:t.y}})},onPointerUp:e=>{let t=_.current;_.current=null;let r=e.currentTarget.getBoundingClientRect();if(t){let t=e.clientX-r.left,i=e.clientY-r.top,a=le(t,i);n(a,O(a,t,i))}},onPointerLeave:()=>{b(null),C(null)},style:{cursor:_.current?`grabbing`:y?`pointer`:`grab`,touchAction:`none`}}),S&&(0,$.jsxs)(`div`,{className:`filemap-symtip`,style:{left:S.x,top:S.y},children:[(0,$.jsx)(`strong`,{children:S.building.label}),(0,$.jsxs)(`span`,{children:[S.building.kind,S.building.lines===void 0?``:` · ${S.building.lines} ${S.building.lines===1?`line`:`lines`}`]})]})]})}var Ua={tsx:`typescript`,jsx:`javascript`,c:`cpp`,c_sharp:`csharp`,bash:`shell`,text:`plaintext`,toml:`ini`,properties:`ini`,yml:`yaml`};function Wa(e){let t=e?.trim().toLowerCase();if(t)return Ua[t]??t}var Ga=s(`filemap`),Ka=()=>void 0;function qa(e){let t=e.line==null?``:` (Line ${e.line})`;return`[${e.severity}] ${e.category} — ${e.message}${t}`}function Ja(e){let t=e.slice(0,4096);if(!t)return!1;let n=0;for(let e=0;e<t.length;e++){let r=t.charCodeAt(e);(r===65533||r<9||r>13&&r<32)&&n++}return n/t.length>.1}var Ya={added:`added`,modified:`modified`,deleted:`deleted`,renamed:`renamed`},Xa={residential:`residential`,commercial:`commercial`,civic:`civic landmark`,industrial:`industrial`},Za={lush:`lush`,tidy:`tidy`,plain:`plain`,scruffy:`scruffy`,blighted:`blighted`},Qa=[{value:`core`,label:`Code`},{value:`tests`,label:`Tests`},{value:`all`,label:`All`}];function $a({projectId:e}){let[t,n]=(0,h.useState)(null),[a,s]=(0,h.useState)(!1),[u,d]=(0,h.useState)(null),[f,g]=(0,h.useState)(null),[_,v]=(0,h.useState)(null),[y,b]=(0,h.useState)(`core`),[ee,te]=(0,h.useState)([]),[ne,re]=(0,h.useState)(null),[x,S]=(0,h.useState)(!1),[ie,C]=(0,h.useState)(()=>Ba()),[w,ae]=(0,h.useState)(null),[T,E]=(0,h.useState)([]),[oe,se]=(0,h.useState)(!1),[ce,D]=(0,h.useState)(null),[le,O]=(0,h.useState)(null),[ue,de]=(0,h.useState)(null),[fe,pe]=(0,h.useState)(0),[k,me]=(0,h.useState)(null),[he,ge]=(0,h.useState)(!1),[_e,ve]=(0,h.useState)(!1),[ye,be]=(0,h.useState)(!1),[xe,Se]=(0,h.useState)(null),Ce=(0,h.useRef)(new Map),A=(0,h.useCallback)((e,t=1)=>{if(e&&window.__GEZEL__?.openWorkspaceFile){window.__GEZEL__.openWorkspaceFile(e.id,Math.max(1,t));return}g(e),v(e?{path:e.id,line:Math.max(1,t)}:null)},[]),we=(0,h.useCallback)((e,t)=>{A(e,t?.lineStart??1)},[A]),j=f?.id??null;(0,h.useEffect)(()=>{if(be(!1),!j){ae(null);return}let t=!1;return ae({path:j,kind:`loading`}),c.readProjectWorkspaceFile(e,j).then(e=>{t||ae(Ja(e.content)?{path:j,kind:`binary`}:{path:j,kind:`ready`,content:e.content})}).catch(e=>{t||ae({path:j,kind:`error`,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[j,e]),(0,h.useEffect)(()=>{if(!j){E([]),D(null),de(null);return}let t=!1;return se(!0),de(null),c.toolScanFindings(e,{path:j,maxResults:100}).then(e=>{if(t)return;let n=e.findings.filter(e=>e.path===j);E(n),D(e=>e&&n.some(t=>t.fingerprint===e)?e:n[0]?.fingerprint??null);let r=n.find(e=>e.line!=null)?.line;r&&v({path:j,line:r})}).catch(e=>{t||(E([]),de(e instanceof Error?e.message:String(e)))}).finally(()=>{t||se(!1)}),()=>{t=!0}},[j,e,fe]),(0,h.useEffect)(()=>{if(!j){me(null),ge(!1),ve(!1);return}let t=!1;return me(null),ge(!1),ve(!1),c.toolFileReview(e,{path:j}).then(e=>{t||(me(e.review??null),ge(e.pending===!0),ve(e.eligible===!1))}).catch(e=>{t||Ga.debug(`file-review unavailable`,e)}),()=>{t=!0}},[j,e]),(0,h.useEffect)(()=>{if(!j){Se(null);return}let t=Ce.current.get(j);if(t){Se({path:j,value:t});return}let n=!1;return Se(null),c.toolFileContext(e,{path:j}).then(e=>{if(n)return;let t=r(e);if(Ce.current.size>=20){let e=Ce.current.keys().next().value;e!==void 0&&Ce.current.delete(e)}Ce.current.set(j,t),Se({path:j,value:t})}).catch(e=>{n||Ga.debug(`file-context unavailable`,e)}),()=>{n=!0}},[j,e,fe]);let M=(0,h.useCallback)(()=>{s(!0),d(null),Ce.current.clear(),c.toolFileMap(e,{scope:y,...ne?{pr:ne}:{}}).then(e=>{n(e),g(t=>t?e.blocks.find(e=>e.id===t.id)??null:null)}).catch(e=>d(e instanceof Error?e.message:String(e))).finally(()=>s(!1))},[e,y,ne]);(0,h.useEffect)(()=>{A(null),M()},[M,A]),(0,h.useEffect)(()=>{let t=!1;return c.listProjectGitHubPulls(e).then(e=>{t||te(e.pulls)}).catch(()=>{t||te([])}),()=>{t=!0}},[e]);let Te=(0,h.useMemo)(()=>new Map((t?.overlay?.changedBlocks??[]).map(e=>[e.blockId,e])),[t]),Ee=(0,h.useMemo)(()=>{let e=t?.overlay;if(!t||!e||e.changedBlocks.length===0)return;let n=new Map,r=(e,t)=>{let r=n.get(e);r?r.push(t):n.set(e,[t])};for(let e of t.roads)r(e.b,e.a),e.bidirectional&&r(e.a,e.b);let i=new Set(e.changedBlocks.map(e=>e.blockId)),a=new Set,o=[...i];for(let e=0;e<3&&o.length>0;e++){let e=[];for(let t of o)for(let r of n.get(t)??[])i.has(r)||a.has(r)||(a.add(r),e.push(r));o=e}return a.size>0?a:void 0},[t]),De=(0,h.useMemo)(()=>{if(!t)return null;let e=t.blocks.filter(e=>e.state!==`tombstoned`&&!e.phantom);return{files:e.length,folders:t.districts.length,roads:t.roads.length,symbols:e.reduce((e,t)=>e+t.buildingCount,0)}},[t]),N=(0,h.useMemo)(()=>{if(!f||!t)return[];let e=new Set;for(let n of t.roads)n.a===f.id?e.add(n.b):n.b===f.id&&e.add(n.a);let n=new Map(t.blocks.map(e=>[e.id,e]));return[...e].sort().map(e=>n.get(e)).filter(e=>!!e)},[f,t]),Oe=(0,h.useCallback)(e=>{let n=i(e);if(n?.kind!==`file`||!t)return!1;let r=t.blocks.find(e=>e.id===n.path);return r&&A(r,n.line),!0},[t,A]),ke=(0,h.useCallback)(e=>{D(e.fingerprint),e.line!=null&&v({path:e.path,line:e.line})},[]),Ae=(0,h.useCallback)(async t=>{O({fingerprint:t.fingerprint,kind:`resolve`}),de(null);try{await c.resolveSecurityFinding(e,{fingerprint:t.fingerprint}),E(e=>e.filter(e=>e.fingerprint!==t.fingerprint)),D(null),Ce.current.delete(t.path),pe(e=>e+1),M()}catch(e){de(e instanceof Error?e.message:String(e))}finally{O(null)}},[M,e]),je=(0,h.useCallback)(async t=>{O({fingerprint:t.fingerprint,kind:`delegate`}),de(null);try{let n=await c.delegateSecurityFinding(e,{fingerprint:t.fingerprint});E(e=>e.map(e=>e.fingerprint===t.fingerprint?n.finding:e)),D(t.fingerprint)}catch(e){de(e instanceof Error?e.message:String(e))}finally{O(null)}},[e]);(0,h.useEffect)(()=>{let e=[...new Set(T.flatMap(e=>e.taskRef?[e.taskRef]:[]))];if(e.length===0)return;let t=!1,n=async()=>{let n=await Promise.all(e.map(e=>c.getTaskByRef(e).catch(()=>null)));t||n.some(e=>e?.status===`complete`||e?.status===`canceled`)&&(Ce.current.clear(),pe(e=>e+1),M())},r=window.setInterval(()=>void n(),5e3);return n(),()=>{t=!0,window.clearInterval(r)}},[T,M]);let Me=k?o(k):null;return(0,$.jsxs)(`section`,{className:`filemap-view`,children:[(0,$.jsxs)(`header`,{className:`filemap-header`,children:[(0,$.jsxs)(`div`,{className:`filemap-title`,children:[(0,$.jsx)(`strong`,{children:`Village`}),De&&(0,$.jsxs)(`span`,{className:`filemap-stats`,children:[De.files,` files · `,De.folders,` neighborhoods · `,De.roads,` roads ·`,` `,De.symbols,` symbols`]}),t?.overlay&&(0,$.jsxs)(`span`,{className:`filemap-overlay-stat`,children:[`PR #`,t.overlay.prNumber,` · `,t.overlay.changedBlocks.length,` changed`,Ee?` · ${Ee.size} affected`:``]})]}),(0,$.jsxs)(`div`,{className:`filemap-actions`,children:[ee.length>0&&(0,$.jsxs)(`select`,{className:`filemap-pr`,"aria-label":`Overlay a pull request`,value:ne??``,onChange:e=>re(e.target.value?Number(e.target.value):null),children:[(0,$.jsx)(`option`,{value:``,children:`No PR overlay`}),ee.map(e=>(0,$.jsxs)(`option`,{value:e.number,children:[`#`,e.number,` `,e.title]},e.number))]}),(0,$.jsx)(`fieldset`,{className:`filemap-scope`,"aria-label":`Village scope`,children:Qa.map(e=>(0,$.jsx)(`button`,{type:`button`,className:y===e.value?`active`:``,"aria-pressed":y===e.value,onClick:()=>b(e.value),children:e.label},e.value))}),(0,$.jsx)(`fieldset`,{className:`filemap-scope`,"aria-label":`Color lens`,children:(0,$.jsx)(`button`,{type:`button`,className:x?`active`:``,"aria-pressed":x,title:`Color blocks by how recently they were added — the evolution lens`,onClick:()=>S(e=>!e),children:`Age`})}),(0,$.jsx)(`fieldset`,{className:`filemap-scope`,"aria-label":`Renderer`,children:(0,$.jsx)(`button`,{type:`button`,className:ie===`iso`?`active`:``,"aria-pressed":ie===`iso`,title:`Isometric village view; toggle off for the flat top-down plan`,onClick:()=>C(e=>{let t=e===`iso`?`flat`:`iso`;try{window.localStorage.setItem(`gezel.mapRenderer`,t)}catch{}return t}),children:`3D`})}),(0,$.jsx)(`button`,{type:`button`,className:`filemap-refresh`,onClick:M,disabled:a,children:a?`Building…`:`Rebuild`})]})]}),(0,$.jsx)(`div`,{className:`filemap-body`,children:u?(0,$.jsxs)(`div`,{className:`filemap-empty`,children:[`Couldn’t build the village: `,u]}):t&&!t.indexed?(0,$.jsx)(`div`,{className:`filemap-empty`,children:`This project hasn’t been indexed yet. The village appears once the workspace has been scanned.`}):t&&t.blocks.length===0&&!a?(0,$.jsx)(`div`,{className:`filemap-empty`,children:y===`tests`?`No test files found.`:`No files to build a village from yet.`}):t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ha,{model:t,selectedId:f?.id??null,onSelect:we,...Ee?{affectedIds:Ee}:{},renderer:ie,ageLens:x}),f?(0,$.jsxs)(`aside`,{className:`filemap-inspector filemap-fileview open`,children:[(0,$.jsxs)(`header`,{className:`filemap-fileview-head`,children:[(0,$.jsxs)(`div`,{className:`filemap-fileview-titlerow`,children:[(0,$.jsx)(`span`,{className:`filemap-fileview-name`,title:f.id,children:f.label}),(0,$.jsxs)(`div`,{className:`filemap-fileview-actions`,children:[N.length>0&&(0,$.jsxs)(`button`,{type:`button`,className:`filemap-fileview-connected-btn`,"aria-expanded":ye,onClick:()=>be(e=>!e),children:[(0,$.jsxs)(`span`,{children:[`Connected (`,N.length,`)`]}),(0,$.jsx)(l,{})]}),(0,$.jsx)(`button`,{type:`button`,className:`filemap-fileview-close`,onClick:()=>A(null),"aria-label":`Close`,children:`×`})]}),ye&&N.length>0&&(0,$.jsx)(`div`,{className:`filemap-fileview-menu`,children:(0,$.jsx)(`ul`,{children:N.slice(0,60).map(e=>(0,$.jsx)(`li`,{children:(0,$.jsx)(`button`,{type:`button`,title:e.id,onClick:()=>{A(e),be(!1)},children:e.label})},e.id))})})]}),(0,$.jsxs)(`div`,{className:`filemap-fileview-stats`,children:[(0,$.jsx)(`span`,{className:`filemap-fileview-path`,children:f.id}),(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[Math.round(f.weight),` lines`]}),(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[f.buildingCount,` symbols`]}),f.lang&&(0,$.jsx)(`span`,{className:`filemap-chip`,children:f.lang}),ie===`iso`&&(0,$.jsx)(`span`,{className:`filemap-chip`,children:Ke(Ue(f))}),f.health&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[Xa[f.health.zone],` · `,Za[f.health.vibe]]}),f.health&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`↓`,f.health.fanIn,` imported`]}),f.health&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`↑`,f.health.fanOut,` imports`]}),f.health&&f.health.findings>0&&(0,$.jsxs)(`span`,{className:`filemap-chip filemap-chip-warn`,children:[f.health.findings,` finding`,f.health.findings>1?`s`:``,f.health.maxSeverity?` (max ${f.health.maxSeverity})`:``]}),f.placedAt&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`since `,f.placedAt.slice(0,10)]}),Te.get(f.id)&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`PR: `,Ya[Te.get(f.id).change],` `,(0,$.jsxs)(`span`,{className:`filemap-add`,children:[`+`,Te.get(f.id).additions]}),` `,(0,$.jsxs)(`span`,{className:`filemap-del`,children:[`−`,Te.get(f.id).deletions]})]})]})]}),(oe||T.length>0||ue)&&(0,$.jsxs)(`section`,{className:`filemap-findings`,"aria-label":`Findings in this file`,children:[(0,$.jsxs)(`div`,{className:`filemap-findings-heading`,children:[(0,$.jsxs)(`strong`,{children:[T.length,` open finding`,T.length===1?``:`s`]}),oe&&(0,$.jsx)(`span`,{children:`Checking…`})]}),T.map(e=>{let t=e.fingerprint===ce,n=le?.fingerprint===e.fingerprint&&le.kind===`resolve`,r=le?.fingerprint===e.fingerprint&&le.kind===`delegate`;return(0,$.jsxs)(`article`,{className:`filemap-finding-card${t?` active`:``}`,"data-severity":e.severity,children:[(0,$.jsxs)(`button`,{type:`button`,className:`filemap-finding-summary`,"aria-pressed":t,onClick:()=>ke(e),children:[(0,$.jsx)(`span`,{className:`filemap-finding-severity`,children:e.severity}),(0,$.jsx)(`strong`,{children:e.title}),(0,$.jsx)(`span`,{className:`filemap-finding-location`,children:e.line==null?`Whole file`:`Line ${e.line}`})]}),t&&(0,$.jsxs)(`div`,{className:`filemap-finding-detail`,children:[e.evidence&&(0,$.jsx)(`code`,{children:e.evidence}),(0,$.jsxs)(`span`,{children:[e.source,` · `,e.ruleId,` · `,e.category]}),e.taskRef&&(0,$.jsxs)(`span`,{className:`filemap-finding-task`,children:[`Developer gezel working ·`,` `,(0,$.jsx)(`button`,{type:`button`,className:`link-button filemap-finding-task-link`,"aria-label":`Open task ${e.taskRef}`,onClick:()=>p({kind:`task`,ref:e.taskRef}),children:e.taskRef})]}),(0,$.jsxs)(`div`,{className:`filemap-finding-actions`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Ae(e),disabled:le!=null,children:n?`Resolving…`:`Mark resolved`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void je(e),disabled:le!=null||e.status===`in_progress`,children:r?`Finding a developer…`:e.status===`in_progress`?`Developer working`:`Ask a developer gezel`})]})]})]},e.fingerprint)}),ue&&(0,$.jsx)(`p`,{className:`filemap-finding-error error`,children:ue})]}),(k||he||_e)&&(0,$.jsx)(`section`,{className:`filemap-review`,"aria-label":`Boekwachter review`,children:k?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`filemap-review-heading`,children:[(0,$.jsxs)(`strong`,{children:[`Boekwachter review · `,k.health,`/10`]}),(0,$.jsx)(`span`,{className:`filemap-review-reason`,children:k.healthReason})]}),k.notesMd&&(0,$.jsx)(`div`,{className:`filemap-review-notes`,children:(0,$.jsx)(m,{value:k.notesMd,readOnly:!0,minHeight:`0`,onCommit:Ka},`${f.id}:review-notes`)}),k.issues.length>0&&(0,$.jsx)(`ul`,{className:`filemap-review-issues`,children:k.issues.map((e,t)=>{let n=e.line;return(0,$.jsx)(`li`,{children:n==null?(0,$.jsx)(`span`,{className:`filemap-review-issue`,children:qa(e)}):(0,$.jsx)(`button`,{type:`button`,className:`filemap-review-issue`,onClick:()=>v({path:f.id,line:n}),children:qa(e)})},`${e.category}:${e.message}:${t}`)})}),(0,$.jsx)(`p`,{className:`filemap-review-advice`,children:`Leads from a background model pass — its opinion, not a verdict.`}),Me&&(0,$.jsx)(`p`,{className:`filemap-review-provenance`,children:Me})]}):_e?(0,$.jsx)(`p`,{className:`filemap-review-pending`,children:`This file type isn’t reviewed.`}):(0,$.jsx)(`p`,{className:`filemap-review-pending`,children:`Not reviewed yet — the boekwachter studies files when idle or during Night Shift.`})}),(0,$.jsx)(`div`,{className:`filemap-fileview-body`,children:!w||w.kind===`loading`?(0,$.jsxs)(`div`,{className:`filemap-empty`,children:[`Loading `,f.label,`…`]}):w.kind===`error`?(0,$.jsxs)(`div`,{className:`filemap-empty`,children:[`Couldn’t read this file: `,w.error]}):w.kind===`binary`?(0,$.jsx)(`div`,{className:`filemap-empty`,children:`Binary file — no preview.`}):(0,$.jsx)(eo,{path:w.path,content:w.content,language:Wa(f.lang),sourceReveal:_?.path===w.path?_:void 0,findings:T,activeFinding:ce,codeContext:xe?.path===w.path?xe.value:null,onContextLink:Oe})})]}):(0,$.jsx)(`p`,{className:`filemap-hint filemap-hint-float`,children:`Scroll to zoom, drag to pan. Each building is a file; click one to open it.`})]}):(0,$.jsx)(`div`,{className:`filemap-empty`,children:a?`Building the village…`:``})})]})}function eo({path:e,content:t,language:n,sourceReveal:r,findings:i,activeFinding:a,codeContext:o,onContextLink:s}){let c=f(),l=(0,h.useMemo)(()=>{if(!(!o||o.sections.length===0&&!o.fileTop))return{...o.fileTop?{fileTop:o.fileTop}:{},sections:o.sections,linkSchemes:[`gezel-nav`],onLinkClick:e=>s(e)}},[o,s]);return(0,$.jsx)(d,{initialMarkdown:t,fileName:e,language:n,height:`100%`,colorScheme:c,showPlayTab:!1,showStatusBar:!1,toolbarSlotLeft:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(to,{request:r}),(0,$.jsx)(no,{findings:i,activeFinding:a})]}),fullWidth:!0,readOnly:!0,...l?{codeContext:l}:{}},e)}function to({request:e}){let{monacoEditor:t}=u();return(0,h.useEffect)(()=>{if(!t||!e)return;let n=t.getModel();if(!n)return;let r=Math.min(e.line,n.getLineCount());t.setPosition({lineNumber:r,column:1}),t.revealLineInCenter(r)},[t,e]),null}function no({findings:e,activeFinding:t}){let{monacoEditor:n}=u(),r=(0,h.useRef)([]);return(0,h.useEffect)(()=>{if(!n)return;let i=n.getModel();if(!i)return;let a=new Map;for(let n of e){if(n.line==null)continue;let e=Math.min(n.line,i.getLineCount());a.set(e,a.get(e)===!0||n.fingerprint===t)}return r.current=n.deltaDecorations(r.current,[...a].map(([e,t])=>({range:{startLineNumber:e,startColumn:1,endLineNumber:e,endColumn:i.getLineMaxColumn(e)},options:{isWholeLine:!0,className:t?`filemap-finding-line-active`:`filemap-finding-line`,linesDecorationsClassName:t?`filemap-finding-gutter-active`:`filemap-finding-gutter`}}))),()=>{r.current=n.deltaDecorations(r.current,[])}},[t,e,n]),null}export{$a as FileMapView,qa as reviewIssueLabel};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-CmrgM5Rf.js";import{t as i}from"./ConfirmDialog-Dt1ed4Fh.js";import{o as a}from"./index-DivKnJyx.js";var o=e(t(),1),s=n(),c=[{id:`documents`,label:`Documents library`,help:`The shared documents folder gezellen read and write across projects.`},{id:`gezels`,label:`Gezellen`,help:`Each gezel’s about, threads, memories, and icons. Installed toolsets (npm packages) stay on this device.`},{id:`projects`,label:`Projects (artifacts, tasks, memories, documents)`,help:`Working files (workspace, git checkout, scripts) and history stay on this device.`}];function l(){let[e,t]=(0,o.useState)(null),[n,l]=(0,o.useState)(null),[f,p]=(0,o.useState)(null),[g,_]=(0,o.useState)(null),y=(0,o.useRef)(null),b=a(window.__GEZEL__?.platform),x=(0,o.useCallback)(async()=>{try{let e=await r.getFolders();t(e),e.job&&_(e.job),l(null)}catch(e){l(e.message)}},[]);(0,o.useEffect)(()=>{x()},[x]),(0,o.useEffect)(()=>{if(!g||g.status===`done`||g.status===`error`||g.status===`cancelled`){y.current&&=(clearInterval(y.current),null);return}if(!y.current)return y.current=setInterval(async()=>{try{let e=await r.getFolderMoveStatus(g.id);_(e),(e.status===`done`||e.status===`error`||e.status===`cancelled`)&&await x()}catch(e){l(e.message)}},1e3),()=>{y.current&&=(clearInterval(y.current),null)}},[g,x]);let S=(0,o.useCallback)(async(e,t)=>{let n=window.__GEZEL__?.selectDirectory;if(!n){l(`Folder picker is only available in the desktop app.`);return}let i=await n({title:`Pick external location for ${t}`});if(i)try{let t=await r.planFolderMove({scope:e,destPath:i});if(!t.validation.ok){l(t.validation.reason??`destination is not valid`);return}p({scope:e,destPath:i,plan:t,conflictPolicy:`overwrite-all`})}catch(e){l(e.message)}},[]),C=(0,o.useCallback)(async()=>{if(f)try{let{jobId:e}=await r.startFolderMove({scope:f.scope,destPath:f.destPath,conflictPolicy:f.conflictPolicy});p(null),_({id:e,scope:f.scope,sourcePath:f.plan.sourcePath,destPath:f.destPath,conflictPolicy:f.conflictPolicy,status:`queued`,filesDone:0,totalFiles:f.plan.files,bytesDone:0,totalBytes:f.plan.bytes,restartRequired:!1,startedAt:new Date().toISOString()})}catch(e){l(e.message)}},[f]),w=(0,o.useCallback)(async t=>{try{let{jobId:n}=await r.resetFolder(t);_({id:n,scope:t,sourcePath:e?.current[t]??``,destPath:e?.defaults[t]??``,conflictPolicy:`overwrite-all`,status:`queued`,filesDone:0,totalFiles:0,bytesDone:0,totalBytes:0,restartRequired:!1,startedAt:new Date().toISOString()})}catch(e){l(e.message)}},[e]),T=(0,o.useCallback)(async e=>{let t=window.__GEZEL__?.openPath;if(!t){l(`Opening folders is only available in the desktop app.`);return}let n=await t(e);n&&l(n)},[]),E=(0,o.useCallback)(async()=>{let e=window.__GEZEL__?.restartService;if(!e){l(`Restart is only available in the desktop app.`);return}try{let t=await e(`folders-changed`);t.ok||l(t.error)}catch(e){l(e.message)}},[]);if(!e)return(0,s.jsxs)(`section`,{className:`settings-section`,children:[(0,s.jsx)(`h2`,{children:`Folders`}),(0,s.jsx)(`p`,{className:`muted small`,children:`Loading…`})]});let D=g?.status===`queued`||g?.status===`running`||e.activeJob,O=g?.status===`done`&&g.restartRequired?g:null,k={...e.current},A={...e.externalized};return O&&(k[O.scope]=O.destPath,A[O.scope]=O.destPath===e.defaults[O.scope]?null:O.destPath),(0,s.jsxs)(`section`,{className:`settings-section`,children:[(0,s.jsx)(`h2`,{children:`Folders`}),(0,s.jsxs)(`p`,{className:`muted small`,children:[`Move parts of your gezel data to a folder of your choosing — for example a OneDrive, iCloud Drive, or Dropbox folder so it syncs across machines and gets backed up. Before any move that copies files, a snapshot of the source is written to `,(0,s.jsx)(`code`,{children:e.backups.path}),` `,`so the move can be undone by hand if something goes wrong.`]}),n&&(0,s.jsxs)(`p`,{className:`error small`,role:`alert`,children:[n,` `,(0,s.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>l(null),children:`dismiss`})]}),g&&(0,s.jsx)(h,{job:g,onRestart:E}),(0,s.jsx)(`div`,{className:`folders-rows`,children:c.map(e=>(0,s.jsx)(u,{label:e.label,help:e.help,currentPath:k[e.id],externalized:A[e.id],restartRequired:O?.scope===e.id,disabled:D||O!==null,onPick:()=>S(e.id,e.label),onReset:()=>w(e.id),onOpen:()=>T(k[e.id]),openLabel:b},e.id))}),e.backups.count>0&&(0,s.jsx)(d,{backups:e.backups,onOpen:T,openLabel:b}),(0,s.jsx)(i,{open:f!==null,title:f?f.conflictPolicy===`use-destination`?`Use this folder without moving files?`:`Move ${f.plan.files} files?`:``,message:f&&(0,s.jsxs)(`span`,{className:`folders-move-dialog-copy`,children:[(0,s.jsxs)(`span`,{className:`folders-move-dialog-line`,children:[(0,s.jsx)(`strong`,{children:`From:`}),` `,(0,s.jsx)(`code`,{children:f.plan.sourcePath})]}),(0,s.jsxs)(`span`,{className:`folders-move-dialog-line`,children:[(0,s.jsx)(`strong`,{children:`To:`}),` `,(0,s.jsx)(`code`,{children:f.destPath})]}),(0,s.jsx)(`span`,{className:`folders-move-dialog-line`,children:f.conflictPolicy===`use-destination`?(0,s.jsxs)(s.Fragment,{children:[f.plan.files.toLocaleString(),` files (`,v(f.plan.bytes),`) will stay in the current folder. Nothing will be copied, overwritten, or deleted.`]}):(0,s.jsxs)(s.Fragment,{children:[f.plan.files.toLocaleString(),` files (`,v(f.plan.bytes),`) will be copied. A backup snapshot will be saved before the move.`]})}),f.plan.conflicts>0&&(0,s.jsxs)(`span`,{className:`folders-move-dialog-line`,children:[(0,s.jsx)(`strong`,{children:f.plan.conflicts}),` file`,f.plan.conflicts===1?``:`s`,` already exist at the destination.`]}),(0,s.jsx)(m,{value:f.conflictPolicy,onChange:e=>p(t=>t&&{...t,conflictPolicy:e})}),(0,s.jsx)(`span`,{className:`folders-move-dialog-line`,children:f.conflictPolicy===`use-destination`?`After restart, Gezel will use only the selected folder. Files left in the current folder will remain on disk, but won’t be available in Gezel from this location.`:`When the move finishes, you’ll be asked to restart Gezel so it can start using the new location. Sessions on disk are preserved.`})]}),confirmLabel:f?.conflictPolicy===`use-destination`?`Use this folder`:`Start move`,cancelLabel:`Cancel`,onConfirm:C,onCancel:()=>p(null)})]})}function u({label:e,help:t,currentPath:n,externalized:r,restartRequired:i,disabled:a,onPick:o,onReset:c,onOpen:l,openLabel:u}){return(0,s.jsxs)(`div`,{className:`folders-row`,style:{marginTop:24},children:[(0,s.jsx)(`div`,{className:`folders-row-head`,children:(0,s.jsx)(`strong`,{children:e})}),(0,s.jsx)(`p`,{className:`muted small`,children:t}),(0,s.jsxs)(`div`,{className:`muted small`,children:[r?`External`:`Default location`,i?` — restart required`:``]}),(0,s.jsx)(`code`,{className:`folders-row-path`,children:n}),(0,s.jsxs)(`div`,{className:`folders-row-actions`,style:{marginTop:16},children:[(0,s.jsx)(`button`,{type:`button`,className:`primary`,onClick:o,disabled:a,children:`Move to other folder…`}),window.__GEZEL__?.openPath&&(0,s.jsx)(`button`,{type:`button`,onClick:l,children:u}),r&&(0,s.jsx)(`button`,{type:`button`,onClick:c,disabled:a,children:`Reset to default`})]})]})}function d({backups:e,onOpen:t,openLabel:n}){return(0,s.jsxs)(`div`,{className:`folders-snapshots`,style:{marginTop:24},children:[(0,s.jsx)(`h3`,{children:`Move snapshots`}),(0,s.jsx)(`p`,{className:`muted small`,children:`Copies of the source taken before each move, newest first. The last 10 are kept; older ones are removed automatically. Nothing here is used by gezel — they exist so you can restore a move by hand.`}),(0,s.jsx)(`ul`,{className:`folders-snapshot-list`,children:e.snapshots.map(e=>(0,s.jsxs)(`li`,{className:`folders-snapshot`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`div`,{children:f(e)}),(0,s.jsxs)(`div`,{className:`muted small`,children:[p(e.scopes),` · `,v(e.bytes)]})]}),window.__GEZEL__?.openPath&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>t(e.path),children:n})]},e.id))}),(0,s.jsxs)(`p`,{className:`muted small`,children:[v(e.totalBytes),` total in `,(0,s.jsx)(`code`,{children:e.path})]})]})}function f(e){return e.createdAt?new Date(e.createdAt).toLocaleString():e.id}function p(e){return e.length===0?`empty`:e.map(e=>c.find(t=>t.id===e)?.label??e).join(`, `)}function m({value:e,onChange:t}){return(0,s.jsxs)(`span`,{className:`folders-conflict-policy`,role:`radiogroup`,"aria-label":`How to use the selected folder`,children:[(0,s.jsxs)(`label`,{className:`folders-conflict-policy-option`,children:[(0,s.jsx)(`input`,{type:`radio`,name:`conflictPolicy`,checked:e===`overwrite-all`,onChange:()=>t(`overwrite-all`)}),(0,s.jsx)(`span`,{children:`Move files, replacing destination conflicts`})]}),(0,s.jsxs)(`label`,{className:`folders-conflict-policy-option`,children:[(0,s.jsx)(`input`,{type:`radio`,name:`conflictPolicy`,checked:e===`skip-all`,onChange:()=>t(`skip-all`)}),(0,s.jsx)(`span`,{children:`Move files, keeping destination conflicts`})]}),(0,s.jsxs)(`label`,{className:`folders-conflict-policy-option`,children:[(0,s.jsx)(`input`,{type:`radio`,name:`conflictPolicy`,checked:e===`use-destination`,onChange:()=>t(`use-destination`)}),(0,s.jsx)(`span`,{children:`Don’t move files (use destination as-is)`})]})]})}function h({job:e,onRestart:t}){let n=e.totalFiles>0?Math.min(100,Math.round(e.filesDone/e.totalFiles*100)):0,r=_(e),i=e.status===`running`||e.status===`queued`,a=e.phase===`copy`&&e.totalFiles>0&&e.filesDone>0,o=e.conflictPolicy===`use-destination`;return(0,s.jsxs)(`section`,{className:`folders-progress folders-progress-${e.status}`,"aria-live":`polite`,children:[(0,s.jsxs)(`div`,{className:`folders-progress-head`,children:[(0,s.jsx)(`strong`,{children:e.status===`done`?o?`Location updated`:`Move complete`:o?`Updating ${g(e.scope)} location`:`Moving ${g(e.scope)}`}),(0,s.jsx)(`span`,{className:`muted small`,children:r})]}),(0,s.jsx)(`code`,{className:`folders-progress-path`,children:e.destPath}),i?(0,s.jsxs)(`div`,{className:`ollama-pull-bar${a?``:` ollama-pull-bar-indeterminate`}`,"aria-hidden":`true`,children:[(0,s.jsx)(`div`,{className:`ollama-pull-bar-fill`,style:a?{width:`${n}%`}:{}}),a&&(0,s.jsxs)(`span`,{className:`ollama-pull-bar-label`,children:[n,`%`]})]}):null,e.status===`error`&&(0,s.jsxs)(`p`,{className:`error small`,children:[`Error: `,e.error??`unknown`]}),e.status===`done`&&e.restartRequired&&(0,s.jsxs)(`div`,{className:`folders-progress-complete`,children:[(0,s.jsx)(`p`,{className:`small`,children:o?`Restart Gezel to use this location. Files in the previous folder were left untouched.`:`Restart Gezel to start using this location. Your sessions are preserved.`}),(0,s.jsx)(`button`,{type:`button`,className:`primary`,onClick:t,children:`Restart now`})]}),e.status===`cancelled`&&(0,s.jsx)(`p`,{className:`muted small`,children:`Cancelled.`})]})}function g(e){return c.find(t=>t.id===e)?.label??e}function _(e){if(e.status===`queued`)return`Queued`;if(e.status===`done`)return`Done`;if(e.status===`error`)return`Failed`;if(e.status===`cancelled`)return`Cancelled`;switch(e.phase){case`scan`:return`Scanning…`;case`backup`:return`Creating backup…`;case`copy`:return`Copying ${e.filesDone.toLocaleString()} of ${e.totalFiles.toLocaleString()} files (${v(e.bytesDone)} of ${v(e.totalBytes)})`;case`verify`:return`Verifying…`;case`swap`:return`Updating configuration…`;case`cleanup`:return`Cleaning up source…`;case`prune`:return`Pruning old backups…`;default:return`Working…`}}function v(e){if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t.toFixed(1)} KB`;let n=t/1024;return n<1024?`${n.toFixed(1)} MB`:`${(n/1024).toFixed(2)} GB`}export{l as FoldersSettings};