@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.
- package/dist/NOTICE.md +3 -3
- package/dist/bin/gezeld.js +8471 -5311
- package/dist/handboek-content/technical/building-connected-apps-with-gezel-app-sdk.md +78 -0
- package/dist/handboek-content/whats-new/{1.26250.md → 1.26251.md} +5 -5
- package/dist/index-store/static-index-worker.js +160 -51
- package/dist/index.d.ts +416 -71
- package/dist/index.js +8465 -5305
- package/dist/memory/embed-worker.js +132 -4
- package/dist/memory/image-embed-worker.js +14 -5
- package/dist/providers/mlx/python/cache_persist.py +52 -8
- package/dist/providers/mlx/python/gezel_mlx_server.py +44 -1
- package/dist/providers/mlx/python/qwen4_ple.py +159 -0
- package/dist/providers/mlx/python/spec_decode.py +73 -31
- package/dist/providers/mlx/python/tool_call_stream.py +10 -2
- package/dist/providers/mlx/python/tool_grammar.py +16 -0
- package/dist/ui/assets/{AmbientDashboardCard-DcVHxEdC.js → AmbientDashboardCard-_xnAQGnk.js} +1 -1
- package/dist/ui/assets/{AudioEngineSettings-BFM2S1mm.js → AudioEngineSettings-CgXgbX0i.js} +1 -1
- package/dist/ui/assets/{BenchmarksView-84-YeULA.js → BenchmarksView-BlExZpYA.js} +1 -1
- package/dist/ui/assets/CatalogBrowser-DYXUZQ_t.js +1 -0
- package/dist/ui/assets/{ChannelsSettings-7NAVUk4k.js → ChannelsSettings-EH27HcqZ.js} +1 -1
- package/dist/ui/assets/ChatTimelineView-Dn1TNyVn.js +7 -0
- package/dist/ui/assets/{ConnectedAppsPanel-CIgF4Q3R.js → ConnectedAppsPanel-BROry-Y0.js} +1 -1
- package/dist/ui/assets/CraftbookEditor-B2RNJnFf.js +1 -0
- package/dist/ui/assets/{CraftbookScriptEditorView-Ck5tzj3Y.js → CraftbookScriptEditorView-B-vySmHP.js} +1 -1
- package/dist/ui/assets/{CraftbookTabContent-BWg7FhK_.js → CraftbookTabContent-BW_2KC89.js} +1 -1
- package/dist/ui/assets/{CraftbookToolsetSetup-EuFOiUzR.js → CraftbookToolsetSetup-J7rEa835.js} +1 -1
- package/dist/ui/assets/{CraftbooksView-BIzQ1VVn.js → CraftbooksView-BjBUWPGF.js} +1 -1
- package/dist/ui/assets/DiffpackReviewView-CD4qJmgT.js +1 -0
- package/dist/ui/assets/DocumentDetail-SYozruTJ.js +1 -0
- package/dist/ui/assets/DocumentsView-DE7eL49Z.js +1 -0
- package/dist/ui/assets/{Ds4Settings-9soZCSeO.js → Ds4Settings-DGzc7JcD.js} +1 -1
- package/dist/ui/assets/{EmbeddedChat-Cce7nxXT.js → EmbeddedChat-D92TaJQ8.js} +1 -1
- package/dist/ui/assets/{FaceRecognitionCard-BVZyOwB8.js → FaceRecognitionCard-CB1Dt9X4.js} +1 -1
- package/dist/ui/assets/FileMapView-kVBG22FU.js +1 -0
- package/dist/ui/assets/FoldersSettings-BWFQU5B4.js +1 -0
- package/dist/ui/assets/GezelDetail-Br4v42Nv.js +1 -0
- package/dist/ui/assets/{GezelJsonEditor-DXXt165-.js → GezelJsonEditor-B9XEiW5Y.js} +1 -1
- package/dist/ui/assets/GezellenView-DheEBAy4.js +1 -0
- package/dist/ui/assets/{GildeUpdatesCard-CtY8mUTA.js → GildeUpdatesCard-BeIYv09f.js} +1 -1
- package/dist/ui/assets/{GithubSignInChip-DT3l6E0Q.js → GithubSignInChip-eEGCe9ar.js} +1 -1
- package/dist/ui/assets/{HandboekMediaProvider-ByJ4NAzz.js → HandboekMediaProvider-D0zcbbpf.js} +1 -1
- package/dist/ui/assets/HandboekView-p0BZT1rH.js +1 -0
- package/dist/ui/assets/{HistoryView-CkinzFEC.js → HistoryView-CKWcWW-Y.js} +1 -1
- package/dist/ui/assets/{HomeView-DNBrQnwy.js → HomeView-b_TT5oV3.js} +1 -1
- package/dist/ui/assets/{ImageEngineSettings-BfM9HSd_.js → ImageEngineSettings-CJfk4OJ4.js} +1 -1
- package/dist/ui/assets/{ImageRecognitionSettings-CaSQu5Br.js → ImageRecognitionSettings-DzbvZk5S.js} +1 -1
- package/dist/ui/assets/{IncompleteDownloads-C36lTCMG.js → IncompleteDownloads-C8_XyP8O.js} +1 -1
- package/dist/ui/assets/{KnowledgeCatalogsCard-CK9bqdf6.js → KnowledgeCatalogsCard-CHopG_j-.js} +1 -1
- package/dist/ui/assets/KnowledgeView-CXNKZUJq.js +1 -0
- package/dist/ui/assets/{LlamaCppSettings-CdNMHBbp.js → LlamaCppSettings-ohcM7kes.js} +1 -1
- package/dist/ui/assets/{MarkdownField-Dugmfr_e.js → MarkdownField-BX0qsaFq.js} +1 -1
- package/dist/ui/assets/{MemoriesTree-CgFqUNEr.js → MemoriesTree-BPj5Rod8.js} +1 -1
- package/dist/ui/assets/{MicrophoneSettings-DzDe9y1q.js → MicrophoneSettings-CWjeYnfI.js} +1 -1
- package/dist/ui/assets/MlxSettings-Dq6dRpcl.js +1 -0
- package/dist/ui/assets/{ModelPicker-BVkJhNAH.js → ModelPicker-0Ue-eEKj.js} +1 -1
- package/dist/ui/assets/NewPathDialog-BhAZm9dp.js +1 -0
- package/dist/ui/assets/{NewScriptDialog-TEAd0KLl.js → NewScriptDialog-DuryIe50.js} +1 -1
- package/dist/ui/assets/NewTaskDialog-BX24flMY.js +2 -0
- package/dist/ui/assets/{OllamaSettings-CPy2vxyZ.js → OllamaSettings-Boj8Nd1G.js} +1 -1
- package/dist/ui/assets/ProjectChat-Dhw_M5bq.js +5 -0
- package/dist/ui/assets/ProjectConnectionsTab-BwpMQNrg.js +1 -0
- package/dist/ui/assets/{ProjectGitStatusBar-BgHZ2ijN.js → ProjectGitStatusBar-BORGYx5l.js} +1 -1
- package/dist/ui/assets/{ProjectGithubView-BV2uTNU0.js → ProjectGithubView-CTP1BOMv.js} +1 -1
- package/dist/ui/assets/{ProjectMailTab-DLtJdXSL.js → ProjectMailTab-qFmAeV3M.js} +1 -1
- package/dist/ui/assets/{ProjectOverviewView-ZMs9nL5N.js → ProjectOverviewView-Cq1FsoaT.js} +1 -1
- package/dist/ui/assets/{ProjectTimeline-CTPcn4Kc.js → ProjectTimeline-Cqae2Z92.js} +1 -1
- package/dist/ui/assets/ProjectsView-D0uJjUB-.js +7 -0
- package/dist/ui/assets/{RecommendedBadge-iUoisQBi.js → RecommendedBadge-CN1jEmSn.js} +1 -1
- package/dist/ui/assets/{RemoteServersPanel-CTVJ0IRh.js → RemoteServersPanel-CMakvCCM.js} +1 -1
- package/dist/ui/assets/{ScriptEditorTabs-CCDFZjdC.js → ScriptEditorTabs-st6dJePd.js} +2 -2
- package/dist/ui/assets/{ScriptEditorView-CergLqKj.js → ScriptEditorView-BkySh57_.js} +2 -2
- package/dist/ui/assets/{ScriptsView-v7ckdhDi.js → ScriptsView-7uPKwjDB.js} +1 -1
- package/dist/ui/assets/{SecurityComplianceSettings-Bd0-66Gs.js → SecurityComplianceSettings-Tsv_pXfy.js} +1 -1
- package/dist/ui/assets/SessionSwitcher-D0fSeeHO.js +1 -0
- package/dist/ui/assets/SettingsView-cli_z8ZW.js +3 -0
- package/dist/ui/assets/{SquisqIntegration-C5l_OPvD.js → SquisqIntegration-BTZ1kBlg.js} +1 -1
- package/dist/ui/assets/{StorageCleanupDialog-3kv9-2mT.js → StorageCleanupDialog-CDBjl8JQ.js} +1 -1
- package/dist/ui/assets/{StorageUsageCard-7sWTrZFa.js → StorageUsageCard-DXY1j0dZ.js} +1 -1
- package/dist/ui/assets/TaskTabContent-C0P681SL.js +1 -0
- package/dist/ui/assets/TasksView-Ddwz10ri.js +1 -0
- package/dist/ui/assets/{TerminalCodeEditor-ChmdzmCz.js → TerminalCodeEditor-BkNQ6QoQ.js} +2 -2
- package/dist/ui/assets/ToolsetsEditor-KVigemfL.js +8 -0
- package/dist/ui/assets/{TransformToolbarButton-gzIxUBH7.js → TransformToolbarButton-8wfJR1bO.js} +2 -2
- package/dist/ui/assets/{UnrecognizedModels-0hptopv6.js → UnrecognizedModels-BzdU1clO.js} +1 -1
- package/dist/ui/assets/{VideoEngineSettings-BdNzCEdR.js → VideoEngineSettings-f79ff57u.js} +1 -1
- package/dist/ui/assets/{WorkspaceIndexPane-DnsOO916.js → WorkspaceIndexPane-fu5V6o1W.js} +1 -1
- package/dist/ui/assets/{api-C0I7spBl.js → api-CmrgM5Rf.js} +1 -1
- package/dist/ui/assets/chat-thread-memory-8MCtb17Q.js +1 -0
- package/dist/ui/assets/{chunk-6ECMNUIP-BvCy0HUI.js → chunk-6ECMNUIP-D5AA6ozp.js} +1 -1
- package/dist/ui/assets/{chunk-A6N6IN3I-ofeM4l8g.js → chunk-A6N6IN3I-BpxihS5H.js} +1 -1
- package/dist/ui/assets/{chunk-ATWVNF7D-CYuW1Yc6.js → chunk-ATWVNF7D-CKIWh7bN.js} +1 -1
- package/dist/ui/assets/{chunk-UBFT2CDQ-FexGDigd.js → chunk-CW24CH7I-BD0FIooX.js} +1 -1
- package/dist/ui/assets/{chunk-DXYWKZ52-zxe8pjH4.js → chunk-DXYWKZ52-DMKPZnpo.js} +1 -1
- package/dist/ui/assets/chunk-IIQYS2YH-BtDJt4Xr.js +1 -0
- package/dist/ui/assets/{chunk-KGWT454C-v5-l6U5m.js → chunk-KGWT454C-DsQOBuLg.js} +1 -1
- package/dist/ui/assets/{chunk-Q77KNJIN-BLuPdsQF.js → chunk-Q77KNJIN-BdWizq9s.js} +1 -1
- package/dist/ui/assets/{chunk-USU6HTKB-B_p-YcDp.js → chunk-USU6HTKB-DyGZplh4.js} +1 -1
- package/dist/ui/assets/{chunk-UXEANVBI-Bt0kX-0Z.js → chunk-UXEANVBI-BUBXvqyE.js} +1 -1
- package/dist/ui/assets/{chunk-O7JILDEF-CqcO1qaI.js → chunk-X7BNDUNI-D14WIvlD.js} +2 -2
- package/dist/ui/assets/{chunk-AE3IUKMM-mZjzzO8Z.js → chunk-ZSU5DJLX-CrjQf-vs.js} +1 -1
- package/dist/ui/assets/{container-BI8hxN1N.js → container-iFj1r6Hk.js} +1 -1
- package/dist/ui/assets/csv-Di411Mv-.js +1 -0
- package/dist/ui/assets/data-Q05qqAp4.js +1 -0
- package/dist/ui/assets/{dist-APSIK7H3.js → dist-1FNFiksd.js} +3 -3
- package/dist/ui/assets/dist-BMZhqfv7.js +2 -0
- package/dist/ui/assets/dist-CE5CbmDb.js +225 -0
- package/dist/ui/assets/doc-BHcGsJZd.js +587 -0
- package/dist/ui/assets/{document-import-DPK4r8Am.js → document-import-B2Ya6sbf.js} +1 -1
- package/dist/ui/assets/{docx-DRLuCTaC.js → docx-B8Pwz5Ih.js} +1 -1
- package/dist/ui/assets/{epub-a0p2Xb1b.js → epub-BQ4g8Q9j.js} +1 -1
- package/dist/ui/assets/{export-options-BqYFyzWx.js → export-options-Dylv69b3.js} +1 -1
- package/dist/ui/assets/file-browser-BLOPfnS0.js +5 -0
- package/dist/ui/assets/{html-BbQNmJ5X.js → html-BnA7qFwq.js} +1 -1
- package/dist/ui/assets/icons-CyM7Cg4E.js +1 -0
- package/dist/ui/assets/index-DW6qHqhU.css +1 -0
- package/dist/ui/assets/index-DivKnJyx.js +36 -0
- package/dist/ui/assets/{mail-link-CWfsP5Aq.js → mail-link-NtlcX5OE.js} +1 -1
- package/dist/ui/assets/{markdown-ryKA_OmY.js → markdown-CLKH_zzl.js} +1 -1
- package/dist/ui/assets/markdown-baseline-0dqv9qbV.js +1 -0
- package/dist/ui/assets/materialize-G4WC5UG3-xq2dcwS8.js +1 -0
- package/dist/ui/assets/{monaco-base-C0VTMpv-.js → monaco-base-BSvdAweA.js} +1 -1
- package/dist/ui/assets/{monaco-setup-CX8q88c5.js → monaco-setup-CT7LZ0o_.js} +1 -1
- package/dist/ui/assets/{new-project-meta-ZmDPGYzC.js → new-project-meta-5Y9Blozr.js} +1 -1
- package/dist/ui/assets/outside-in-Msmhxf_U.js +3 -0
- package/dist/ui/assets/{pdf-BHrygJa5.js → pdf-C4BhW3zg.js} +1 -1
- package/dist/ui/assets/{pending-drafts-27ujtQxX.js → pending-drafts-BD227X9H.js} +1 -1
- package/dist/ui/assets/{poppetje-CfaAvFkE.js → poppetje-DvCJO36y.js} +3 -3
- package/dist/ui/assets/{pptx-nDW64jAN.js → pptx-B6uaM2s7.js} +3 -3
- package/dist/ui/assets/{run-export-86KzLZ7R.js → run-export-TscWwR6y.js} +2 -2
- package/dist/ui/assets/{standalone-source-7QdiNsDW.js → standalone-source-Cw9SF7Zk.js} +1 -1
- package/dist/ui/assets/storage-Cmhlwx70.js +1 -0
- package/dist/ui/assets/styles-BjDaWeMA.css +1 -0
- package/dist/ui/assets/styles-CqO-rmOt.js +554 -0
- package/dist/ui/assets/{terminal-monaco-setup-Bar-sYKd.js → terminal-monaco-setup-me523-j-.js} +1 -1
- package/dist/ui/assets/{transform-CmAXy0Ck.js → transform-DxJCwK68.js} +1 -1
- package/dist/ui/assets/{use-local-model-manager-D1yiurrC.js → use-local-model-manager-8wvk-I-y.js} +1 -1
- package/dist/ui/assets/{useCompactLayout-BDtPQcDh.js → useCompactLayout-cm4E9Vja.js} +0 -0
- package/dist/ui/assets/{useCopilotAvailability-BHOfHrfT.js → useCopilotAvailability-D9hglSH_.js} +1 -1
- package/dist/ui/assets/{useDiffpacks-B0kYhlWQ.js → useDiffpacks-1BN2XJWg.js} +1 -1
- package/dist/ui/assets/{useGitSync-DOt-ODiw.js → useGitSync-7m9YA7h5.js} +1 -1
- package/dist/ui/assets/{useShowWorkInProgressFeatures-BtpredG7.js → useShowWorkInProgressFeatures-D6QOaTUT.js} +1 -1
- package/dist/ui/assets/{useTotalRamBytes-B8NFM27w.js → useTotalRamBytes-Durk383U.js} +1 -1
- package/dist/ui/assets/{xlsx-B_pu1ZvY.js → xlsx-BbHA9bxA.js} +1 -1
- package/dist/ui/index.html +15 -15
- package/package.json +12 -11
- package/dist/ui/assets/CatalogBrowser-7_jHy5Q3.js +0 -1
- package/dist/ui/assets/ChatTimelineView-Cg_kLK_U.js +0 -7
- package/dist/ui/assets/CraftbookEditor-BKAIsnXv.js +0 -1
- package/dist/ui/assets/DiffpackReviewView-B2a3zgE-.js +0 -1
- package/dist/ui/assets/DocumentDetail-GCYhwQqV.js +0 -1
- package/dist/ui/assets/DocumentsView-Cm3RaQ5N.js +0 -1
- package/dist/ui/assets/FileMapView-BKJovLcL.js +0 -1
- package/dist/ui/assets/FoldersSettings-CuJd2JdE.js +0 -1
- package/dist/ui/assets/GezelDetail-D_KIPDhQ.js +0 -1
- package/dist/ui/assets/GezellenView-BOOW1QQU.js +0 -1
- package/dist/ui/assets/HandboekView-gRzJcIbJ.js +0 -1
- package/dist/ui/assets/KnowledgeView-DJ3cJVHA.js +0 -1
- package/dist/ui/assets/MlxSettings-45mBFHbA.js +0 -1
- package/dist/ui/assets/NewTaskDialog-CIXVunZn.js +0 -2
- package/dist/ui/assets/ProjectChat-BiJRweob.js +0 -5
- package/dist/ui/assets/ProjectConnectionsTab-CQgaIzuv.js +0 -1
- package/dist/ui/assets/ProjectsView-BUdR76n6.js +0 -7
- package/dist/ui/assets/SessionSwitcher-BgZqyiRn.js +0 -1
- package/dist/ui/assets/SettingsView-DLhOYiR5.js +0 -3
- package/dist/ui/assets/TaskTabContent-CG2KmfwV.js +0 -1
- package/dist/ui/assets/TasksView-Dy5Ue4zS.js +0 -1
- package/dist/ui/assets/ToolsetsEditor-J9XxQ5Ms.js +0 -8
- package/dist/ui/assets/chat-thread-memory-CI2-giEq.js +0 -1
- package/dist/ui/assets/chunk-IIQYS2YH-DEkyBlHg.js +0 -1
- package/dist/ui/assets/csv-B0D9jJG2.js +0 -1
- package/dist/ui/assets/data-BIL84EaT.js +0 -1
- package/dist/ui/assets/dist-CJqyWK6E.js +0 -2
- package/dist/ui/assets/dist-DOqbRmFj.js +0 -225
- package/dist/ui/assets/doc-C2Ph2FWI.js +0 -584
- package/dist/ui/assets/document-companion-aDThLOwl.js +0 -1
- package/dist/ui/assets/file-browser-DVyWN0LD.js +0 -5
- package/dist/ui/assets/icons-DWaUNQbT.js +0 -1
- package/dist/ui/assets/index-DDu8nyO6.js +0 -34
- package/dist/ui/assets/index-DEDUSiCx.css +0 -1
- package/dist/ui/assets/markdown-baseline-9B52XlX2.js +0 -1
- package/dist/ui/assets/materialize-G4WC5UG3-BlZQe-88.js +0 -1
- package/dist/ui/assets/outside-in-BmIIeMid.js +0 -3
- package/dist/ui/assets/storage-B-vhjyV2.js +0 -1
- package/dist/ui/assets/styles-BvkZd-EV.js +0 -550
- package/dist/ui/assets/styles-IQ4adxWr.css +0 -1
|
@@ -1 +0,0 @@
|
|
|
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,Pt as i,Y as a,nt as o,z as s}from"./dist-DOqbRmFj.js";import{t as c}from"./api-C0I7spBl.js";import{y as l}from"./primitives-CWrGZpPI.js";import{i as u,n as d}from"./styles-BvkZd-EV.js";import{U as f,ht as p}from"./index-DDu8nyO6.js";import{t as m}from"./MarkdownField-Dugmfr_e.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 x(e,t){return t/e.scale+e.offsetX}function ee(e,t){return t/e.scale+e.offsetY}function te(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 ne(e,t,n,r){let i=_(e.scale*t);if(i===e.scale)return e;let a=x(e,n),o=ee(e,r);return{scale:i,offsetX:a-n/i,offsetY:o-r/i}}function S(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 C(e){return a(e.id,e.lang)}function re(e){return e.buildingCount>0&&C(e)===`code`}function w(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 T(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 ie(e){let t=0;for(let n=0;n<e.length;n++)t=(t*31+e.charCodeAt(n))%360;return t}var E={brick:{satMul:.9,litDelta:-4,hue:14,hueMix:.82},stucco:{satMul:.62,litDelta:6,hue:42,hueMix:.45},timber:{satMul:.7,litDelta:-2,hue:28,hueMix:.82},stone:{satMul:.34,litDelta:2,hue:40,hueMix:.78},slate:{satMul:.34,litDelta:-8,hue:220,hueMix:.4},tile:{satMul:.72,litDelta:-1,hue:18,hueMix:.5},thatch:{satMul:.5,litDelta:4,hue:44,hueMix:.7},glass:{satMul:.55,litDelta:10,hue:196,hueMix:.5},iron:{satMul:.35,litDelta:-10,hue:210,hueMix:.55}},D={village:[`timber`,`stucco`,`brick`,`stone`],town:[`brick`,`stucco`,`stone`],city:[`brick`,`stone`]},ae={village:[`tile`,`slate`,`thatch`],town:[`tile`,`slate`],city:[`slate`,`tile`]};function oe(e,t,n){let r=T(e),i=D[t],a=ae[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 se(e,t,n){let r=(t-e+540)%360-180;return r*=n,((e+r)%360+360)%360}var O=4;function ce(e,t){let n=E[t].litDelta,r=E[e].litDelta-n;return n+Math.max(-4,Math.min(O,r))}function k(e,t,n,r=E[t].litDelta){let i=E[t],a=i.hueMix*(1-Math.max(0,Math.min(1,n)));return{h:se(e.h,i.hue,a),s:Math.max(0,Math.min(100,e.s*i.satMul)),l:Math.max(0,Math.min(100,e.l+r))}}function le({h:e,s:t,l:n}){return`hsl(${Math.round(e)} ${Math.round(t)}% ${Math.round(n)}%)`}function ue(e){return .38+-.2*Math.max(0,Math.min(1,e))}function de(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 fe(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 A=[`hsl(28 92% 58%)`,`hsl(28 70% 46%)`,`hsl(28 42% 35%)`,`hsl(28 16% 27%)`],pe=[`hsl(28 92% 44%)`,`hsl(28 70% 34%)`,`hsl(28 42% 26%)`,`hsl(28 16% 20%)`],me=[`hsl(28 92% 68%)`,`hsl(28 70% 56%)`,`hsl(28 42% 44%)`,`hsl(28 16% 35%)`],he=[`hsl(28 95% 55%)`,`hsl(28 82% 66%)`,`hsl(28 55% 77%)`,`hsl(28 25% 86%)`],ge=[`hsl(28 95% 42%)`,`hsl(28 82% 52%)`,`hsl(28 55% 63%)`,`hsl(28 25% 72%)`],_e=[`hsl(28 95% 66%)`,`hsl(28 82% 76%)`,`hsl(28 55% 85%)`,`hsl(28 25% 92%)`],ve={typescript:210,tsx:210,javascript:48,jsx:48,python:160,rust:20,go:190,css:280,html:15,markdown:90};function ye(e){let t=ve[e.toLowerCase()];return t===void 0?Math.round(ie(e)/30)*30%360:t}function be(e,t,n){if(n!=null)return t.dark?{roof:A[n],facade:pe[n],edge:me[n]}:{roof:he[n],facade:ge[n],edge:_e[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=ye(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 xe=5,j=[`hsl(28 92% 37%)`,`hsl(28 70% 28%)`,`hsl(28 42% 21%)`,`hsl(28 16% 16%)`],Se=[`hsl(28 95% 35%)`,`hsl(28 82% 45%)`,`hsl(28 55% 56%)`,`hsl(28 25% 65%)`];function Ce(e,t,n,r){let i=be(e,t,n);if(n!=null){let e=t.dark?j[n]:Se[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=ye(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=ue(r.urbanity),l=ce(r.wall,r.roof),u=Math.max(-1,Math.min(1,r.variance??0))*xe;return{top:le(k({h:a,s:o.top,l:s.top+u},r.roof,1)),wallL:le(k({h:a,s:o.wall,l:s.wallL+u},r.wall,c,l)),wallR:le(k({h:a,s:o.wall,l:s.wallR+u},r.wall,c,l)),edge:le(k({h:a,s:o.edge,l:s.edge+u},r.roof,1))}}function M(e){return e.urbanity??.5}function N(e){switch(e.settlement){case`hamlet`:case`village`:return`village`;case`city`:return`city`;default:return`town`}}var we=new WeakMap;function Te(e){let t=we.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+=M(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 we.set(e,r),r}var Ee={kind:`none`,u0:0,v0:0,u1:0,v1:0,height:0,behind:!1},De={FACADE:2710517197,ROOF_FURNITURE:1640531527,MASSING:2654435769,MATERIAL:2246822507,TRIM:3266489909,GROUND:668265263},Oe={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`]}},ke={cornice:!1,parapet:!1,stringCourse:!1,quoins:!1};function Ae(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 je(e,t,n,r){let i=oe(e^De.MATERIAL,t,n);return r===`thatch`?i.roof=`thatch`:r===`conical`?i.roof=`brick`:r===`barrel`&&(i.roof=`glass`),i}var Me={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}},Ne={data:`field`,style:`park`,config:`signal-tower`},Pe={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 Fe(e,t,n){let r=Pe[e];if(!r)return Ee;let i=T(t^De.MASSING);if(r===`setback`)return n<3?Ee:{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 Ie(e,t){return e[Math.min(e.length-1,Math.floor(t()*e.length))]}function Le(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 Re(e,t){let n=Me[e].roofs;return n.length===1||t()<ze[e]?n[0]:n[1]}var ze={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 Be(e){return/(?:^|[/_.-])(?:test|tests|spec|specs)(?:[/_.-]|$)/i.test(e)}var Ve={village:`parish-hall`,town:`guildhall`,city:`town-hall`};function He(e){let t=w(`town-1910:v1:${e.id}`),n=T(t),r=e.health?.zone??`residential`,i=N(e),a=Oe[i],o=C(e),s;s=Ne[o]||(e.landmark?Ve[i]:Be(e.id)&&r!==`industrial`?`schoolhouse`:Ie(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=Re(s,n),g=Le(e,n),_=Me[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),x=_.cap===`cupola`&&!b?`none`:_.cap,ee=y===0&&i===`city`&&!d&&c>=3?Math.max(1,Math.min(3,Math.floor(v/2))):y,te=Ae(h,x,ee,_.roofFactor);return{archetype:s,use:o,roof:h,ridge:g,storeys:c,bays:v,chimneys:ee,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:x,trim:{...ke,..._.trim},material:je(t,i,d,h),massing:Fe(s,t,c),...te===1?{}:{roofFactor:te}}}function Ue(e,t){let n=w(`town-1910:symbol:v1:${e.id}`),r=T(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=N(t),l=s?`industrial`:o?`civic`:a?`residential`:`commercial`,u=Oe[c][l],d=e.height<.4?0:e.height<.72?1:2,f=u[Math.min(u.length-1,d)],p=Re(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=Me[f],_=g.cap===`clock-tower`?`cupola`:g.cap,v=Le(e,r),y=s||f===`cottage`||f===`farmhouse`||f===`inn`?1+ +(r()<.3):0,b=p===`sawtooth`?2+ +(r()<.4):0,x=Ae(p,_,y,g.roofFactor);return{archetype:f,use:`code`,roof:p,ridge:v,storeys:m,bays:h,chimneys:y,dormers:+(p===`mansard`&&e.height>.55),awning:t.health?.zone===`commercial`&&!a,cupola:_===`cupola`,clock:!1,sawteeth:b,seed:n,band:c,eaves:g.eaves,ground:g.ground,cap:_,trim:{...ke,...g.trim},material:je(n,c,s,p),massing:Ee,...x===1?{}:{roofFactor:x}}}function We(e){return e.archetype.replace(/-/g,` `)}function Ge(e){return`${e.band} ${We(e)}`}var Ke=new WeakMap;function qe(e){let t=Ke.get(e);if(t)return t;let n=new Map;for(let t of e.blocks)t.state!==`tombstoned`&&n.set(t.id,He(t));return Ke.set(e,n),n}function Je(e,t){let n=qe(e).get(t.id);if(n)return n;let r=He(t);return qe(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 Ye=new Map;function Xe(e,t){let n=Ye.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 Ye.set(t,r),r}var Ze=1.5,Qe=2.5,$e=6;function et(e,t){return e.tier===`street`&&re(t)}function tt(e,t){let n=t.palette,r=t.now??Date.now(),i=[];for(let e of t.model.blocks)S(t.cam,e.rect,t.viewW,t.viewH)&&i.push({b:e,r:P(t.cam,e.rect),age:t.ageLens?fe(e.lastTouchedAt??e.placedAt,r):void 0});if(t.tier!==`city`&&!t.ageLens)for(let n of i)nt(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<$e||et(t,n)||(F(e,r.x+Ze,r.y+Qe,r.w,r.h,Math.min(3,r.w/6)),e.fill())}for(let n of i)it(e,t,n)}function nt(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;rt(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 rt(e,t,n,r){let i=t.palette,a=M(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=N(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 it(e,t,n){let{b:r,r:i,age:a}=n,o=t.palette;if(r.state===`tombstoned`){ct(e,t,n);return}if(r.phantom){ut(e,t,n);return}if(r.state===`new`&&!t.ageLens){lt(e,t,n);return}let s=be(r.lang,o,a),c=Math.min(3,i.w/6),l=Je(t.model,r);if(!t.ageLens&&(l.archetype===`field`||l.archetype===`park`)){at(e,t,n,l,s.roof);return}if(t.tier===`city`||i.w<$e){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(et(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||ot(e,t,n,i.h-u,s,l)}function at(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 ot(e,t,n,r,i,a){let{r:o}=n;if(a.roof===`sawtooth`&&r>=12){st(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 st(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=T(w(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 ct(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=T(w(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 lt(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<$e){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=T(w(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 ut(e,t,n){let{b:r,r:i}=n,a=t.palette,o=Math.min(3,i.w/6);e.fillStyle=be(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=Xe(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 dt(e,t){let n=t.palette,r=(n,r,i)=>{let a=t.model.blocks.find(e=>e.id===n);if(!a||!S(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 ft(e,t){if(t.tier!==`street`)return;let n=t.palette;for(let r of t.model.buildings){if(!S(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=T(w(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 pt=[`tree1`,`tree2`,`tree3`];function mt(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=T(w(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(pt[Math.floor(r()*pt.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 ht=new WeakMap;function gt(e){let t=ht.get(e);if(t)return t;let n=new Map;for(let t of e.blocks){let e=mt(t);e.length&&n.set(t.id,e)}return ht.set(e,n),n}var _t=3e3,vt=6e3,yt=14;function bt(e,t,n){if(!n||t.tier===`city`||t.ageLens||t.tier===`district`&&t.model.blocks.length>vt)return;let r=gt(t.model);if(r.size===0)return;let i=_t;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(S(t.cam,s,t.viewW,t.viewH)&&!(t.tier===`district`&&s.w*t.cam.scale<=yt))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 xt=[{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}],St=[5,4,2,1];function Ct(e){return e.grade===void 0?St[Math.max(0,Math.min(3,e.tier))]:Math.max(0,Math.min(7,e.grade))}var wt=22,Tt=34,Et=18,Dt=26,Ot=48,kt=[`tree1`,`tree2`],At=.0055,jt=.012,Mt=.0022;function Nt(e,t,n){let r=t-e,i=Math.min(Ot,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 Pt(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=Ct(e),c=xt[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 Ft=20,It=.3;function Lt(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=Ft+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>Ft||(!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*It,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 Rt(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=T(w(`street-life:${t.id}`)),b=p+c,x=r.lamps?Nt(e.r0,e.r1,wt).map((e,t)=>d(e,(t%2==0?-1:1)*b*.9)):[],ee=r.trolley?Nt(e.r0,e.r1,Tt).map(e=>d(e,b*.85)):[],te=r.trees?Nt(e.r0,e.r1,Et).map((e,t)=>({...d(e+(y()-.5)*3,(t%2==0?1:-1)*b*.6),size:2+y()*.8,sprite:kt[Math.floor(y()*kt.length)]})):[],ne=[],S=u-l;if(r.trolley&&S>=40){let e=1+Math.floor(S/260);for(let t=0;t<e;t++)ne.push({kind:`trolley`,phase:y(),speed:jt*(.9+y()*.2),dir:t%2==0?1:-1,cross:0})}if(r.carts>0&&S>=24){let e=Math.min(5,Math.round(S/80*r.carts));for(let t=0;t<e;t++){let e=y()<.5?1:-1;ne.push({kind:`cart`,phase:y(),speed:At*(.8+y()*.4),dir:e,cross:e*p*.45})}}if(r.walkers&&g&&S>=Dt){let e=Math.min(8,Math.floor(S/Dt));for(let t=0;t<e;t++){let e=y()<.5?-1:1;ne.push({kind:`walker`,phase:y(),speed:Mt*(.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:S,center:a,width:o,carriagewayWidth:s,sidewalkWidth:c,reservation:h,carriageway:m,sidewalks:g,rails:v,gauge:_,lamps:x,poles:ee,trees:te,vehicles:ne}}var zt=new WeakMap;function Bt(e){let t=zt.get(e);if(t)return t;let n=(e.streets??[]).map(Pt);Lt(n);let r=n.map(Rt),i={streets:r,animated:r.filter(e=>e.vehicles.length>0)};return zt.set(e,i),i}function Vt(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 Ht(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 Ut(e,t,n){return e.horizontal?{x:t,y:e.center+n}:{x:e.center+n,y:t}}function Wt(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);Gt(e,t,o),Kt(e,t),qt(e,t,o)}function Gt(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)||!S(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 Kt(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t,s=Bt(r);if(s.streets.length===0)return;let c=s.streets.filter(e=>S(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=Vt(t,i),l(t.carriageway));return}let u=Te(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=Vt(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:Ut(t,t.a0,0),b:Ut(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 qt(e,t,n){let{cam:r,model:i,palette:a,tier:o,viewW:s,viewH:c}=t;for(let t of i.districts){if(!S(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 Jt={info:.78,low:.86,medium:.96,high:1.08,critical:1.18};function Yt(e){let t=Math.max(0,Math.log2(Math.max(1,e)))*.52;return .82+Math.min(1.25,t)}function Xt(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:Jt[n]+Math.min(.22,Math.log2(t)*.07),severe:n===`critical`||n===`high`}}function Zt(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 Qt(e,t,n,r,i,a,o=1,s=0){let c=n.scale*o,l=T(w(`${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=en(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,$t(e,a,d,_,g,v),e.fill(),e.globalAlpha=.96,e.fillStyle=t.crane,$t(e,a,d-.25*c,_*.66,g*.72,v*.68),e.fill(),e.globalAlpha=.98,e.fillStyle=t.windowLit,$t(e,a,d-.45*c,_*.34,g*.44,v*.42),e.fill()}e.restore()}function $t(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 en(e){return e-Math.floor(e)}function tn(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(!S(t.cam,r.rect,t.viewW,t.viewH))continue;let i=Xt(r);if(!i)continue;let a=Zt(n.get(r.id)??[]),o=P(t.cam,a?.rect??r.rect);Qt(e,t.palette,i,o.x+o.w/2,o.y,r.id,Yt(t.cam.scale),t.animationTime??0)}}function nn(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||!S(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||!S(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 rn={added:`#3fb950`,modified:`#d29922`,deleted:`#f85149`,renamed:`#a371f7`},an=`#58a6ff`;function on(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||!S(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=an,e.globalAlpha=.18,F(e,c,u,d,f,p),e.fill(),e.globalAlpha=.7,e.strokeStyle=an,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||!S(n,t.rect,a,o))continue;let i=rn[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 sn=[1,1.15,1.35,1.6],cn=.5,ln=6e3,un=80,dn=(e,t,n)=>e<t?t:e>n?n:e,fn=(e,t)=>`${Math.round(e*10)/10},${Math.round(t*10)/10}`,pn=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),mn=e=>sn[e]??1,hn=(e,t)=>e.axis===`h`?{x:t,y:e.line}:{x:e.line,y:t},gn=20;function _n(e){let t=e.streets;if(!t||t.length===0||t.length>ln)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-cn&&a.line<=t.max+cn&&t.line>=a.min-cn&&t.line<=a.max+cn&&(r[e].add(dn(a.line,t.min,t.max)),r[i].add(dn(t.line,a.min,a.max)))}}let o=[],s=(e,t)=>{let s=n[e],c=hn(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-cn||i>r.max+cn)continue;let a=Math.abs(r.line-t);a<=cn||a>gn||(!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(dn(t,e.min,e.max)),o.push({a:c,b:u.proj,w:u.w*mn(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=hn(e,t);l.set(fn(n.x,n.y),n)}let i=mn(e.tier);for(let t=0;t<n.length-1;t++){let r=hn(e,n[t]),a=hn(e,n[t+1]),o=(n[t+1]-n[t])*i;o>0&&d(fn(r.x,r.y),fn(a.x,a.y),o)}u.push({seg:e,pts:n})});for(let e of o)d(fn(e.a.x,e.a.y),fn(e.b.x,e.b.y),e.w);return{adj:c,coord:l,segs:u}}function vn(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=dn(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 yn(e,t){let{seg:n,pts:r}=e,i=mn(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`?fn(e,n.line):fn(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 bn=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 xn(e,t,n){let r=new Map([[t,0]]),i=new Map,a=new Set,o=new bn;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 Sn(e,t){return{x:dn(t.x,e.x,e.x+e.w),y:dn(t.y,e.y,e.y+e.h)}}function Cn(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 wn(e,t,n){let r=vn(e,pn(t)),i=vn(e,pn(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 yn(e.segs[r.segIndex],r.along))o(`\0A`,{to:t.key,w:t.w});for(let t of yn(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)*mn(r.seg.tier)});let s=xn(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=Sn(t,c[0]),u=Sn(n,c[c.length-1]);return Cn([l,...c,u])}function Tn(e,t){let n=pn(e),r=pn(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 En=new WeakMap,Dn=new WeakMap;function On(e){if(En.has(e))return En.get(e)??null;let t=_n(e);return En.set(e,t),t}function kn(e,t,n){let r=On(e);if(!r)return null;let i=Dn.get(e);if(i||(i=new Map,Dn.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<un&&(c=wn(r,e,s),o++),c||=Tn(e,s),a.push({points:c,bidirectional:i.bidirectional,affinity:i.affinity})}return i.set(t,a),a}function An(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 jn(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=kn(i,t.selectedId,l);if(n){Mn(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=An(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 Mn(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 Nn(e,t){e.save(),Wt(e,t),jn(e,t,`under`),tt(e,t),ft(e,t),bt(e,t,t.atlas),tn(e,t),dt(e,t),jn(e,t,`selected`),nn(e,t),on(e,t),e.restore()}var Pn=.01;function Fn(e,t){return e.x+e.w<=t.x+Pn||e.y+e.h<=t.y+Pn}function In(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=Fn(l,u),f=Fn(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 Ln=.6;function I(e,t){return{u:e-t,v:(e+t)/2}}function Rn(e){return e*3}var zn=3*Ln*.6;function Bn(e){return(.5+e*4.5)*3*Ln*.4}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?16:20,i*.17))/r}function Hn(e){return{n:I(e.x,e.y),e:I(e.x+e.w,e.y),s:I(e.x+e.w,e.y+e.h),w:I(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=qe(e),n=e.blocks.map(e=>{let n=t.get(e.id),r=e.state===`tombstoned`||n?.archetype===`field`||n?.archetype===`park`?0:Rn(qn(e)),i=r*Ln;return{block:e,hWorld:r,hIso:i,aabb:Wn(e.rect,i),...n?{style:n}:{},roofFactor:n?.roofFactor??1}}),r=In(n.map(e=>({rect:e.block.rect,u0:e.aabb.u0,u1:e.aabb.u1}))),i=0;for(let e of n)e.hIso>i&&(i=e.hIso);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),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);for(let e=s.length-1;e>=0;e--){let t=s[e];if(Gn(a,o,t.rect,Bn(t.height)+Vn(t.rect,n.scale,!0)))return t}return null}function ir(e,t,n,r){let i=n/t.scale+t.offsetX,a=r/t.scale+t.offsetY;for(let n=e.order.length-1;n>=0;n--){let r=e.geoms[e.order[n]];if(Gn(i,a,r.block.rect,r.hIso+Zn(r,t.scale)))return r.block}return null}function L(e,t,n){return{x:(t-e.offsetX)*e.scale,y:(n-e.offsetY)*e.scale}}function R(e,t,n){let r=Hn(t),i=L(e,r.n.u,r.n.v),a=L(e,r.e.u,r.e.v),o=L(e,r.s.u,r.s.v),s=L(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 z(e,t,n){let r=Hn(n),i=L(t,r.n.u,r.n.v),a=L(t,r.e.u,r.e.v),o=L(t,r.s.u,r.s.v),s=L(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 B(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 V(e,t,n,r,i,a){e.fillStyle=t,B(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&&(V(e,n.wallL,t.tw,t.ts,t.gs,t.gw),V(e,n.wallR,t.ts,t.te,t.ge,t.gs)),V(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()}},cr=2/Math.sqrt(5),lr=Math.sqrt(5)/2,ur=1.2,dr=4,fr=2.4,pr=2.6,mr=4,hr=400,gr={length:5.5,width:1.9,height:2.4},_r={length:2.4,width:1.2,height:1.1},vr={length:1.4,width:.6,height:1.2,lead:2.1},yr=1.3,br=2.2;function xr(e,t){let{cam:n,model:r,palette:i,viewW:a,viewH:o}=t,s=Bt(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=Vt(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)z(e,n,t.carriageway),e.fill()}return}let u=Te(r),d=e=>e.street.districtId?u.get(e.street.districtId):void 0,f=e=>e.sidewalks!==null&&e.sidewalkWidth*cr*l>=ur;e.fillStyle=i.street.verge;for(let t of c)!t.spec.verge||d(t)===`city`||(z(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)z(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=Vt(r,i),z(e,n,a),e.fill(),p&&r.carriagewayWidth*cr*l>=dr&&Cr(e,t,r,f(r))}for(let n of c)n.rails&&wr(e,t,n);if(p){for(let n of c)Tr(e,t,n);for(let n of c)Dr(e,t,n)}}function H(e,t,n){let r=I(t,n);return L(e.cam,r.u,r.v)}function Sr(e,t,n=40){return t.x>=-n&&t.x<=e.viewW+n&&t.y>=-n&&t.y<=e.viewH+n}function U(e,t,n,r){e.moveTo(n.x,n.y),e.lineTo(r.x,r.y)}function Cr(e,t,n,r){let i=t.cam.scale,a=n.carriagewayWidth/2,o=(e,r)=>{let i=Ut(n,e,r);return H(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*lr*i,2.4*lr*i]),e.beginPath();for(let r of[-a*.42,a*.42])U(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=.3,e.lineWidth=Math.max(.5,.2*i),e.beginPath(),U(e,t,o(n.a0+.5,0),o(n.a1-.5,0));let r=Math.min(hr,Math.floor(n.length/pr));for(let i=0;i<r;i++){let r=n.a0+pr*(i+.5);i%2==0?U(e,t,o(r,-a*.85),o(r,0)):U(e,t,o(r,0),o(r,a*.85))}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(),U(e,t,o(n.a0,-a),o(n.a1,-a)),U(e,t,o(n.a0,a),o(n.a1,a)),e.stroke(),e.globalAlpha=1;break}if(r&&n.sidewalkWidth*cr*i>=3){e.strokeStyle=`rgba(0, 0, 0, 0.12)`,e.lineWidth=Math.max(.5,.18*i),e.beginPath();let r=Math.min(hr,Math.floor(n.length/mr)),s=a+n.sidewalkWidth;for(let i=0;i<r;i++){let r=n.a0+mr*(i+.5);U(e,t,o(r,-s),o(r,-a)),U(e,t,o(r,a),o(r,s))}e.stroke()}}function wr(e,t,n){if(!n.rails)return;let r=t.cam.scale;if(e.strokeStyle=t.palette.street.rail,e.beginPath(),n.gauge*cr*r>=fr){e.lineWidth=Math.max(.7,.26*r);for(let r of n.rails)U(e,t,H(t,r.a.x,r.a.y),H(t,r.b.x,r.b.y))}else{e.lineWidth=1;let r=Ut(n,n.a0,0),i=Ut(n,n.a1,0);U(e,t,H(t,r.x,r.y),H(t,i.x,i.y))}e.stroke()}function Tr(e,t,n){let r=t.cam.scale,i=t.palette;if(n.lamps.length>0){let a=yr*r,o=Math.max(.8,.3*r),s=[];for(let e of n.lamps){let n=H(t,e.x,e.y);Sr(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)e.beginPath(),e.arc(t.x,t.y-a,o,0,Math.PI*2),e.fill()}}if(n.poles.length>0){let a=br*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=H(t,i.x,i.y),c={x:n.x,y:n.y-a};s.push(c),Sr(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];!Sr(t,i,200)&&!Sr(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=H(t,i.x,i.y);if(!Sr(t,n))continue;let a=i.size*r*2,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 Er(e,t,n,r,i){let a=Ut(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 Dr(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=Ht(n,a,r);switch(a.kind){case`trolley`:Or(e,t,n,o);break;case`cart`:{let r=Er(n,o,a.cross,_r.length,_r.width);if(!Sr(t,H(t,r.x+r.w/2,r.y+r.h/2)))break;let s=Er(n,o+a.dir*vr.lead,a.cross,vr.length,vr.width),c=a.dir===-1;c&&or(e,R(t.cam,s,vr.height*Ln),i.street.horse),or(e,R(t.cam,r,_r.height*Ln),i.street.cart),c||or(e,R(t.cam,s,vr.height*Ln),i.street.horse);break}case`walker`:{let r=Ut(n,o,a.cross),s=H(t,r.x,r.y);if(!Sr(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 Or(e,t,n,r){let i=t.palette,a=Er(n,r,0,gr.length,gr.width),o=H(t,a.x+a.w/2,a.y+a.h/2);if(!Sr(t,o,60))return;let s=R(t.cam,a,gr.height*Ln);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=W(r,a,n),s=W(r,a,i),u=W(l,c,n),d=W(l,c,i);e.beginPath(),e.moveTo(W(o,u,.2).x,W(o,u,.2).y),e.lineTo(W(s,d,.2).x,W(s,d,.2).y),e.lineTo(W(s,d,.6).x,W(s,d,.6).y),e.lineTo(W(o,u,.6).x,W(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-br*t.cam.scale),e.stroke()}}function W(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}var kr=14,Ar=6;function jr(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:Te(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)),z(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,z(e,n,l.rect),e.fill(),e.globalAlpha=1,t.tier!==`city`&&(e.strokeStyle=i.curb,e.lineWidth=1,z(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,z(e,n,s.rect),e.fill(),t.tier===`street`&&!t.ageLens&&(e.strokeStyle=i.domeAccent,e.globalAlpha=.55,e.lineWidth=1,z(e,n,s.rect),e.stroke(),e.globalAlpha=1,Mr(e,t,s))):(e.fillStyle=i.dark?`hsl(130 12% 15%)`:`hsl(90 26% 80%)`,z(e,n,s.rect),e.fill(),t.tier===`street`&&!t.ageLens&&Pr(e,t,s)));xr(e,t)}function Mr(e,t,n){let{cam:r}=t,i=Math.min(n.rect.w,n.rect.h)*.22*Math.SQRT2*r.scale;if(i<kr/2)return;let a=I(n.rect.x+n.rect.w/2,n.rect.y+n.rect.h/2);Nr(e,t,L(r,a.u,a.v),i)}function Nr(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 Pr(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(Ar,Math.floor(a/500))),s=T(w(`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=I(t,a),u=L(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 Fr=12,Ir=5,Lr=.78;function Rr(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<Fr)return;let i=Hn(r),a=[L(t.cam,i.n.u,i.n.v),L(t.cam,i.e.u,i.e.v),L(t.cam,i.s.u,i.s.v),L(t.cam,i.w.u,i.w.v)],o=M(n),s=t.palette;e.globalAlpha=.55,e.fillStyle=o<.25?s.orchard:o<.5?s.ground:s.sidewalk,Br(e,a),e.fill(),e.globalAlpha=1;let c=N(n);if(!(c===`city`&&o>Lr)){if(c===`village`){zr(e,t,a);return}e.strokeStyle=c===`town`?s.fence:s.curb,e.lineWidth=1,c===`town`&&e.setLineDash([2,2]),Br(e,a),e.stroke(),e.setLineDash([])}}function zr(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)/Ir));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 Br(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 Vr=3,Hr=2;function Ur(e,t,n,r,i,a){if(n.length===0)return;let o=T(w(`${r}:chimney-smoke`)),s=Math.max(.6,.34*i);e.save(),e.fillStyle=t.street.smoke;for(let t of n.slice(0,Hr))for(let n=0;n<Vr;n++){let n=o(),r=Wr(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 Wr(e){return e-Math.floor(e)}var Gr=20,Kr={"clock-tower":2.4,cupola:1.85,lantern:1.35,bellcote:1.5,finial:1.05};function qr(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&&mi(e,t,n,r,s),!a.suppressDetails&&n.te.x-n.tw.x>=Gr&&gi(e,t,n,r,i);let l=Jr(e,t,n,r,c,i);if(!a.suppressDetails&&t.tier===`street`){Xr(e,n,r,l,i,s),Zr(e,n,r,l,i,s);let a=c*(r.roofFactor??1),u=Math.min(l.a.y,l.b.y,l.apex.y);xi(e,t,n,r,l,c,Math.max(0,a-(n.tn.y-u)),s,o.stacks)}return o}function Jr(e,t,n,r,i,a){let o=r.ridge;switch(r.roof){case`gable`:return $r(e,n,o,i,a);case`hip`:return ri(e,n,o,i,a);case`mansard`:return ii(e,n,o,i,a);case`sawtooth`:return ai(e,n,o,i,r.sawteeth,a);case`shed`:return oi(e,n,o,i,a);case`thatch`:return ei(e,n,o,i,a);case`half-hip`:return ti(e,n,o,i,a);case`catslide`:return ni(e,n,o,i,a);case`parapet`:return si(e,n,i,a);case`monitor`:return ci(e,n,o,i,a);case`pyramid`:return li(e,n,i,a);case`barrel`:return ui(e,t,n,o,i,a);case`conical`:return di(e,n,i,a)}}function Yr(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 Xr(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=Yr(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 Zr(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 Qr(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 G(e,t){return{a:e,b:t,apex:X(e,t)}}function $r(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),V(e,i.top,t.tn,t.te,a,n),V(e,i.wallL,n,a,t.ts,t.tw),J(e,i.edge,n,a),G(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),V(e,i.top,t.tn,a,o,t.tw),V(e,i.wallL,a,t.te,t.ts,o),J(e,i.edge,a,o),G(a,o)}function ei(e,t,n,r,i){let a=$r(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 ti(e,t,n,r,i){let[a,o]=Qr(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);V(e,i.wallL,t.tn,t.tw,n,s),V(e,i.wallR,t.te,c,a,t.ts),V(e,i.top,t.tn,t.te,c,s),V(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);V(e,i.wallR,t.tn,s,n,t.te),V(e,i.wallL,t.tw,t.ts,a,c),V(e,i.top,t.tn,s,c,t.tw),V(e,i.wallL,s,t.te,t.ts,c)}return J(e,i.edge,s,c),G(s,c)}function ni(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),V(e,i.top,t.tn,t.te,o,n),V(e,i.wallL,n,o,t.ts,t.tw),J(e,i.edge,n,o),G(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),V(e,i.top,t.tn,o,s,t.tw),V(e,i.wallL,o,t.te,t.ts,s),J(e,i.edge,o,s),G(o,s)}function ri(e,t,n,r,i){let[a,o]=Qr(t,n),s=Q(Z(a,o,.24),r),c=Q(Z(a,o,.76),r);return n===`x`?(V(e,i.top,t.tn,t.te,c,s),q(e,i.wallR,t.te,t.ts,c),V(e,i.wallL,s,c,t.ts,t.tw),q(e,i.top,t.tn,s,t.tw)):(V(e,i.top,t.tn,s,c,t.tw),q(e,i.top,t.tn,t.te,s),V(e,i.wallR,s,t.te,t.ts,c),q(e,i.wallL,t.tw,c,t.ts)),J(e,i.edge,s,c),G(s,c)}function ii(e,t,n,r,i){let a=Ii(t.tn,t.te,t.ts,t.tw),o=Q(Fi(t.tn,a,.32),r),s=Q(Fi(t.te,a,.32),r),c=Q(Fi(t.ts,a,.32),r),l=Q(Fi(t.tw,a,.32),r);return V(e,i.top,t.tn,t.te,s,o),V(e,i.wallR,t.te,t.ts,c,s),V(e,i.wallL,l,c,t.ts,t.tw),V(e,i.top,t.tn,o,l,t.tw),V(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`?G(X(o,l),X(s,c)):G(X(o,s),X(l,c))}function ai(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);V(e,a.top,f,p,h,m),V(e,a.wallL,m,h,_,g),J(e,a.edge,m,h,.65)}return G(Q(Z(s,c,.68/o),r*.72),Q(Z(l,u,.68/o),r*.72))}function oi(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),V(e,i.top,n,a,t.ts,t.tw),J(e,i.edge,n,a),G(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),V(e,i.top,a,t.te,t.ts,o),J(e,i.edge,a,o),G(a,o)}function si(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);V(e,r.wallL,c,s,t.ts,t.tw),V(e,r.wallR,s,o,t.te,t.ts),V(e,r.top,a,o,s,c);let l=Ii(a,o,s,c),u=[Z(a,l,.2),Z(o,l,.2),Z(s,l,.2),Z(c,l,.2)];return V(e,r.wallL,...u),e.strokeStyle=r.edge,e.lineWidth=.8,Y(e,[a,o,s,c],!0),e.stroke(),G(u[0],u[2])}function ci(e,t,n,r,i){let a=$r(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 V(e,i.wallR,c,l,d,u),V(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)),G(Q(u,1.5),Q(d,1.5))}function li(e,t,n,r){let i=Q(Ii(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 ui(e,t,n,r,i,a){let[o,s]=Qr(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 V(e,a.wallL,d,u,h,m),V(e,a.top,m,h,p,f),V(e,t.palette.windowLit,f,p,_,g),V(e,a.wallR,g,_,l,c),J(e,a.edge,f,p,.7),G(f,p)}function di(e,t,n,r){let i=Ii(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 V(e,r.top,t.tn,t.te,c,s),V(e,r.wallR,t.te,t.ts,l,c),V(e,r.wallL,u,l,t.ts,t.tw),V(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 fi=34;function pi(e,t,n,r,i,a){if(!i)return;let o=(e,t,r,i)=>Pi(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=T(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 mi(e,t,n,r,i){let a=T(r.seed^De.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>=fi,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];pi(e,t,i,r,c,n),_i(e,t,i,r,c,s),vi(e,i,o,s,c,()=>a()<.24?t.palette.windowLit:t.palette.window)}if(hi(e,t,n,r),r.awning){let r=Pi(n.ts,n.te,n.gs,n.ge,.08,.92,.57,.7);V(e,t.palette.awning,...r),e.strokeStyle=t.palette.windowLit,e.globalAlpha=.5,e.lineWidth=.7;for(let t=1;t<4;t++){let n=t/4,i=Z(r[0],r[1],n),a=Z(r[3],r[2],n);e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke()}e.globalAlpha=1}}function hi(e,t,n,r){let i=(e,t,r,i)=>Pi(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`:V(e,t.palette.sidewalk,...i(.05,.95,.5,.59)),V(e,t.palette.windowLit,...i(.06,.43,.61,.88)),V(e,t.palette.windowLit,...i(.63,.94,.61,.88)),V(e,t.palette.window,...i(.46,.6,.64,.98)),V(e,t.palette.windowLit,...i(.46,.6,.59,.68)),V(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;V(e,t.palette.window,...i(o,s,.58,.98))}break}case`cart-door`:{V(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])V(e,t.palette.sidewalk,...i(n,n+.08,.55,.98));let n=i(.14,.78,.44,.55);V(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:{V(e,t.palette.sidewalk,...i(.09,.32,.54,.99)),V(e,t.palette.window,...i(.125,.285,.64,.99)),V(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(V(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);V(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 gi(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=Pi(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;V(e,i.edge,...Pi(n.ts,n.te,n.gs,n.ge,0,.07,r,r+.1))}e.globalAlpha=1}}function _i(e,t,n,r,i,a){let o=(e,t,r,i)=>Pi(n.ta,n.tb,n.ga,n.gb,e,t,r,i);if(e.globalAlpha=.5,V(e,t.palette.masonry,...o(0,1,.93,1)),e.globalAlpha=1,e.globalAlpha=.45,V(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;V(e,t.palette.sidewalk,...o(r-.012,r+.012,.07,.93))}if(V(e,t.palette.sidewalk,...o(0,.035,.07,.93)),V(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 vi(e,t,n,r,i,a){let o=(e,n,r,i)=>Pi(t.ta,t.tb,t.ga,t.gb,e,n,r,i);for(let t=0;t<n;t++){let s=.72/n,c=.12+t*s,l=Math.min(.86,c+s*.58);for(let t=0;t<r;t++){let n=.82/r,s=.09+t*n+n*.27,u=.09+(t+1)*n-n*.27,d=a();if(i&&(e.globalAlpha=.55,V(e,bi,...o(s-.008,u+.008,c-.022,c)),e.globalAlpha=.8,V(e,yi,...o(s-.016,u+.016,l,l+.022)),e.globalAlpha=1),V(e,d,...o(s,u,c,l)),i){e.strokeStyle=bi,e.globalAlpha=.5,e.lineWidth=.7,e.beginPath();let t=(s+u)/2,n=o(t,t,c,c)[0],r=o(t,t,l,l)[0];e.moveTo(n.x,n.y),e.lineTo(r.x,r.y);let i=c+(l-c)*.42,a=o(s,s,i,i)[0],d=o(u,u,i,i)[0];e.moveTo(a.x,a.y),e.lineTo(d.x,d.y),e.stroke(),e.globalAlpha=1}}}}var yi=`#cfc6b4`,bi=`#3a342c`;function xi(e,t,n,r,i,a,o,s,c){let l=T(r.seed^De.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;ji(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,Kr.cupola);n>=3&&Mi(e,i.apex.x,i.apex.y,n,r.clock,t)}switch(r.cap){case`bellcote`:{let n=f(d*2,Kr.bellcote);n>=2.5&&Ei(e,Z(i.a,i.b,.14),n,t);break}case`finial`:{let n=f(d*1.8,Kr.finial);n>=2&&Di(e,i.a,n,t.palette.masonry);break}case`clock-tower`:{let r=f((n.te.x-n.tw.x)*.16,Kr[`clock-tower`]);r>=3&&Oi(e,i.apex,r,t);break}case`lantern`:{let n=f(r.archetype===`signal-tower`?u*.34:d*2.2,Kr.lantern);n>=3&&Ai(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&&Ni(e,o.x,s,c,t.palette.window,t.palette.masonry)}}}function K(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 Si=`rgba(0, 0, 0, 0.3)`;function Ci(e,t,n,r,i=1){let a=K(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=Si,Y(e,[a.s,a.e,t.e,t.s],!0),e.fill(),e.globalAlpha=1,a}function wi(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=Si,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=Si,Y(e,[t.s,t.e,i],!0),e.fill()}function Ti(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 Ei(e,t,n,r){let i=K(t,n*.64),a=Ci(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),wi(e,a,n*.5,r.palette.domeAccent)}function Di(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 Oi(e,t,n,r){let i=K(t,n),a=n*1.5,o=Ci(e,i,a,r.palette.sidewalk),s=K(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(),wi(e,o,n*.88,r.palette.domeAccent),Ti(e,i,o,Math.max(1.6,n*.2),r)}function ki(e,t,n,r,i,a){if(a===`bandstand`){let a=Math.min(r,i/.95);if(a<4)return;wi(e,Ci(e,Ci(e,K(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||wi(e,Ci(e,K(n,o),o*1.6,t.palette.masonry),o*.3,t.palette.masonry)}function Ai(e,t,n,r){let i=K(t,n),a=Ci(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,wi(e,Ci(e,a,n*.1,r.palette.masonry),n*.55,r.palette.domeAccent)}function ji(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=bi,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 Mi(e,t,n,r,i,a){let o=K({x:t,y:n},r*.72),s=r*.85,c=Ci(e,o,s,a.palette.sidewalk);wi(e,K(c.c,r),r*.65,a.palette.domeAccent),i&&Ti(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 Ni(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 Pi(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 Fi(e,t,n){return Z(e,t,n)}function Q(e,t){return{x:e.x,y:e.y-t}}function Ii(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 Li=14;function Ri(e,t,n,r){return e!==`city`&&t!==!0&&n>0&&re(r)}function zi(e,t){let n=t.now??Date.now(),r=t.tier===`street`&&!t.ageLens&&t.atlas?gt(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?fe(o.lastTouchedAt??o.placedAt,n):void 0;if(o.state===`tombstoned`){r.add(t.ageLens?t.palette.tombstone:t.palette.earth,...Hi(t,o));continue}if(o.state===`new`&&!t.ageLens&&!o.phantom){r.add(t.palette.newBlock,...Hi(t,o));continue}let c=Ce(o.lang,t.palette,s),l=t.ageLens?c.top:a.style?.archetype===`field`?Ki(a.style,t.palette):a.style?.archetype===`park`?t.palette.park.lawn:c.top;r.add(l,...Hi(t,o)),o.landmark&&i.push(a)}r.flush(e),e.fillStyle=t.palette.domeAccent;for(let n of i){let r=Ui(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(Rr(e,t,a.block),Wi(e,t,a,n),r){let n=r.get(a.block.id);if(n&&t.atlas)for(let r of n){let n=I(r.x,r.y),i=L(t.cam,n.u,n.v),a=r.size*t.cam.scale*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)}}Bi(e,t,a)}}}function Bi(e,t,n){if(t.ageLens)return;let r=Xt(n.block);if(!r)return;let i=tr(t.model,n.block.id),a=Ri(t.tier,t.ageLens,i.length,n.block)?Zt(i):null,o=a?$n(t.cam,a):Vi(t,n);Qt(e,t.palette,r,o.x,o.y,n.block.id,Yt(t.cam.scale),t.animationTime??0)}function Vi(e,t){let n=Ui(e,t);return{x:n.x,y:n.y-Zn(t,e.cam.scale)*e.cam.scale}}function Hi(e,t){let n=Hn(t.rect);return[L(e.cam,n.n.u,n.n.v),L(e.cam,n.e.u,n.e.v),L(e.cam,n.s.u,n.s.v),L(e.cam,n.w.u,n.w.v)]}function Ui(e,t){let n=t.block.rect,r=I(n.x+n.w/2,n.y+n.h/2),i=L(e.cam,r.u,r.v);return{x:i.x,y:i.y-t.hIso*e.cam.scale}}function Wi(e,t,n,r){let i=n.block,a=t.palette,[o,s,c,l]=Hi(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,B(e,o,s,c,l),e.fill(),e.globalAlpha=1,u>=10&&!t.ageLens){let n=T(w(i.id));e.fillStyle=a.rubble;let r=4+Math.floor(n()*4);for(let a=0;a<r;a++){let r=I(i.rect.x+i.rect.w*(.12+.76*n()),i.rect.y+i.rect.h*(.12+.76*n())),a=L(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]),B(e,o,s,c,l),e.stroke(),e.setLineDash([]),e.globalAlpha=1}return}let d=R(t.cam,i.rect,n.hIso);if(i.phantom){let n=t.ageLens?fe(i.lastTouchedAt??i.placedAt,r):void 0,u=Ce(i.lang,a,n);e.globalAlpha=.3,or(e,R(t.cam,i.rect,3*Ln),u),e.globalAlpha=1;let d=Xe(e,a.dark?`#8b8f99`:`#8a7f64`);d&&(e.fillStyle=d,B(e,o,s,c,l),e.fill()),e.strokeStyle=a.blockStroke,e.setLineDash([4,3]),B(e,o,s,c,l),e.stroke(),e.setLineDash([]);return}if(i.state===`new`&&!t.ageLens){if(e.fillStyle=a.earth,B(e,o,s,c,l),e.fill(),e.strokeStyle=a.newBlock,e.lineWidth=1.5,e.setLineDash([4,3]),B(e,o,s,c,l),e.stroke(),e.setLineDash([]),t.tier===`street`&&u>=Li){let t=T(w(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?fe(i.lastTouchedAt??i.placedAt,r):void 0,p=n.style&&!t.ageLens&&t.tier!==`city`?{...n.style.material,urbanity:M(i),variance:(n.style.seed>>>8)%200/100-1}:void 0,m=Ce(i.lang,a,f,p),h=i.buildingCount>0?tr(t.model,i.id):Gi,g=Ri(t.tier,t.ageLens,h.length,i)?h:Gi;if(g.length>0){let n=R(t.cam,i.rect,zn);or(e,n,{top:a.sidewalk,wallL:m.wallL,wallR:m.wallR}),e.globalAlpha=.25,V(e,m.top,n.tn,n.te,n.ts,n.tw),e.globalAlpha=1,Zi(e,t,i,ta(e,t,g,n.liftPx,i,m));return}let _=n.style??He(i);if(!t.ageLens&&_.archetype===`field`){Yi(e,t,n,_);return}if(!t.ageLens&&_.archetype===`park`){Xi(e,t,n,_,m);return}let v=t.ageLens?null:$i(t,i,n,_);v?.behind&&ea(e,t,v.prism,_,m);let y=qr(e,t,d,_,m,{suppressDetails:t.ageLens===!0});v&&!v.behind&&ea(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(),Zi(e,t,i,y.stacks)}var Gi=[];function Ki(e,t){return t.farm.crops[(e.seed>>>4)%4]}var qi={district:3.2,street:1.6},Ji=80;function Yi(e,t,n,r){let i=n.block,a=t.palette,o=i.rect,[s,c,l,u]=Hi(t,i),d=c.x-u.x;if(e.fillStyle=Ki(r,a),B(e,s,c,l,u),e.fill(),d>=16){let n=qi[t.tier===`street`?`street`:`district`],i=r.ridge===`x`,s=i?o.h:o.w,c=Math.min(Ji,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?I(o.x+.6,o.y+a):I(o.x+a,o.y+.6),c=i?I(o.x+o.w-.6,o.y+a):I(o.x+a,o.y+o.h-.6),l=L(t.cam,s.u,s.v),u=L(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,R(t.cam,r,3*Ln*.55),a.farm.shed)}}function Xi(e,t,n,r,i){let a=n.block,o=t.palette,s=a.rect,[c,l,u,d]=Hi(t,a),f=l.x-d.x;if(e.fillStyle=o.park.lawn,B(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);B(e,L(t.cam,r.n.u,r.n.v),L(t.cam,r.e.u,r.e.v),L(t.cam,r.s.u,r.s.v),L(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,B(e,L(t.cam,_.n.u,_.n.v),L(t.cam,_.e.u,_.e.v),L(t.cam,_.s.u,_.s.v),L(t.cam,_.w.u,_.w.v)),e.fill(),e.globalAlpha=1,f>=30){let i=L(t.cam,I(p,m).u,I(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?ki(e,t,i,o,a,`bandstand`):c===1?Nr(e,t,i,o*.6):ki(e,t,i,o,a,`obelisk`)}if(t.tier===`street`&&t.atlas){let n=T(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=L(t.cam,I(o,c).u,I(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 Zi(e,t,n,r){t.tier!==`street`||t.ageLens||r.length===0||n.health?.zone===`industrial`&&Ur(e,t.palette,r,n.id,t.cam.scale,t.animationTime??0)}var Qi=26;function $i(e,t,n,r){let i=r.massing;if(i.kind===`none`||e.tier===`city`||(t.rect.w+t.rect.h)*e.cam.scale<Qi)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:R(e.cam,a,n.hIso*i.height),behind:i.behind}}function ea(e,t,n,r,i){qr(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 ta(e,t,n,r,i,a){let o=[];for(let s=0;s<n.length;s++){let c=n[s],l=R(t.cam,c.rect,Bn(c.height)),u=-r,d={gn:ra(l.gn,u),ge:ra(l.ge,u),gs:ra(l.gs,u),gw:ra(l.gw,u),tn:ra(l.tn,u),te:ra(l.te,u),ts:ra(l.ts,u),tw:ra(l.tw,u),liftPx:l.liftPx},f=Ue(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:Ce(i.lang,t.palette,void 0,{...f.material,urbanity:M(i),variance:(f.seed>>>8)%200/100-1});e.globalAlpha=.5+.45*c.height;let m=qr(e,t,d,f,p,{compact:!0,suppressDetails:t.ageLens===!0});e.globalAlpha=1,o.unshift(...m.stacks)}return o}function na(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=R(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 ra(e,t){return{x:e.x,y:e.y+t}}function ia(){return{accepted:new Set,measure:new Map}}var aa=`12px ui-sans-serif, system-ui, sans-serif`,oa=`13px ui-sans-serif, system-ui, sans-serif`,sa=`11px ui-sans-serif, system-ui, sans-serif`,ca=`10px ui-sans-serif, system-ui, sans-serif`,la=16,ua=2.35,da=2.75,fa=18,pa=28;function ma(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 ha(e,t,n){return e<=t?0:e>=n?1:(e-t)/(n-t)}function ga(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*ha(n.scale,1.6,2.6):1-.85*ha(n.scale,2,3.2);if(r<=.05)continue;let i=t.depth<=1?oa:aa,s=ma(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=L(n,I(c.x,c.y).u,I(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*ha(n.scale,1.2,1.6);if(r<=.05)continue;let i=ma(e,a,sa,s.label),c=L(n,I(s.rect.x+s.rect.w,s.rect.y+s.rect.h).u,I(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:sa});continue}let d=sa,f=ma(e,a,d,s.label),p=I(s.rect.x+s.rect.w/2,s.rect.y+s.rect.h/2),m=L(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:ha(n.scale,ua,da);if(s>.05){let i=new Set(r.blocks.filter(e=>e.state===`live`&&!e.phantom&&re(e)).map(e=>e.id));for(let c of r.buildings){if(!i.has(c.blockId)||(c.rect.w+c.rect.h)*n.scale<fa)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=_a(c.label),u=ma(e,a,ca,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:va(c.kind,c.lines),x:f,y:r.y-la-5,w:d,h:la,alpha:s,kind:`symbol`,font:ca,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 _a(e){return e.length<=pa?e:`${e.slice(0,pa-1)}…`}function va(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 ya={added:`#3fb950`,modified:`#d29922`,deleted:`#f85149`,renamed:`#a371f7`},ba=`#58a6ff`;function xa(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=L(n,e.u,e.v);return{x:t.x,y:t.y-l}});e.fillStyle=ba,e.globalAlpha=.18,Sa(e,u),e.fill(),e.globalAlpha=.7,e.strokeStyle=ba,e.lineWidth=1,Sa(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=ya[t.change]??`#888888`,c=R(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 Sa(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 Ca=40;function wa(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=kn(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=I(i.x,i.y),o=L(n,a.u,a.v);r===0?e.moveTo(o.x,o.y):e.lineTo(o.x,o.y)}e.stroke()}}else Ta(e,t,t.selectedId,a,2,.9);e.globalAlpha=1}t.hoverId&&t.hoverId!==t.selectedId&&Ta(e,t,t.hoverId,a,1.5,.35)}function Ta(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>=Ca)break;let i=r.get(t.a),a=r.get(t.b);if(!i||!a)continue;let s=I(i.x+i.w/2,i.y+i.h/2),c=I(a.x+a.w/2,a.y+a.h/2),u=L(o,s.u,s.v),d=L(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 Ea(e,t){e.save(),jr(e,t),zi(e,t),na(e,t),wa(e,t),ga(e,t),xa(e,t),e.restore()}var Da=[`tree1`,`tree2`,`tree3`,`shrub`,`weed`,`dryPatch`,`deadTree`,`rubble1`,`rubble2`],Oa=24,ka=new Map;function Aa(e,t){let n=t>1.5?2:1,r=`${e.dark?`dark`:`light`}|${n}`,i=ka.get(r);if(i!==void 0)return i;let a=ja(e,n*2);return ka.set(r,a),a}function ja(e,t){let n=Oa*t,r,i;try{r=document.createElement(`canvas`),r.width=n*Da.length,r.height=n,i=r.getContext(`2d`)}catch{return null}if(!i)return null;let a=e.dark?`hsl(135 28% 30%)`:`hsl(120 35% 52%)`,o=e.dark?`hsl(150 30% 24%)`:`hsl(95 38% 45%)`,s=e.dark?`hsl(140 24% 27%)`:`hsl(110 30% 60%)`,c=e.dark?`hsl(30 25% 25%)`:`hsl(30 35% 40%)`,l=e.dark?`hsl(60 20% 28%)`:`hsl(65 35% 55%)`,u=e.dark?`hsl(38 25% 30%)`:`hsl(42 45% 70%)`,d=e.dark?`hsl(30 12% 32%)`:`hsl(30 15% 45%)`,f={};Da.forEach((e,t)=>{f[e]=t});let p=(e,r)=>{i.save(),i.translate(e*n+n/2,n/2),i.scale(t,t),r(i),i.restore()},m=(e,t,n,r)=>{e.beginPath(),e.arc(t,n,r,0,Math.PI*2),e.fill()},h=(e,t,n)=>{e.fillStyle=c,e.fillRect(-1,2,2,6),e.fillStyle=t,m(e,0,-1,n),e.fillStyle=`rgba(255, 255, 255, 0.14)`,m(e,-n*.3,-1-n*.3,n*.45)};p(f.tree1,e=>h(e,a,7)),p(f.tree2,e=>h(e,o,6)),p(f.tree3,e=>{e.fillStyle=c,e.fillRect(-1,5,2,4),e.fillStyle=o;for(let[t,n]of[[7,5],[5.5,1],[4,-3]])e.beginPath(),e.moveTo(0,n-6),e.lineTo(-t,n),e.lineTo(t,n),e.closePath(),e.fill()}),p(f.shrub,e=>{e.fillStyle=s,m(e,-2.5,2,3.5),m(e,2.5,2,3),m(e,0,-1,3.5)}),p(f.weed,e=>{e.strokeStyle=l,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()}),p(f.dryPatch,e=>{e.fillStyle=u,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()}),p(f.deadTree,e=>{e.strokeStyle=d,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 g=(t,n)=>{t.fillStyle=e.rubble;for(let[e,r,i]of n)t.fillRect(e,r,i,i)};return p(f.rubble1,e=>g(e,[[-6,-2,4],[-1,2,3],[3,-4,3.5],[4,3,2.5]])),p(f.rubble2,e=>g(e,[[-5,3,3],[-4,-5,2.5],[1,-1,4],[6,-4,2]])),{canvas:r,cell:n,index:f}}var $=n();function Ma(){try{return window.localStorage.getItem(`gezel.mapRenderer`)===`flat`?`flat`:`iso`}catch{return`iso`}}function Na(e){return e.closest(`[data-theme="dark"]`)!=null||!e.closest(`[data-theme="light"]`)&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches}function Pa({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),[C,w]=(0,h.useState)(null),T=(0,h.useRef)(()=>{}),ie=(0,h.useRef)(ia()),E=a??Ma(),D=(0,h.useMemo)(()=>e.blocks.filter(e=>Xt(e)!==null),[e]),ae=(0,h.useMemo)(()=>new Set(D.map(e=>e.id)),[D]),oe=(0,h.useMemo)(()=>Bt(e).animated,[e]),se=(0,h.useMemo)(()=>{let t=qe(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]);T.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=de(Na(n)),m={cam:c.current,model:e,palette:p,tier:v(c.current.scale),viewW:o,viewH:u,selectedId:t,hoverId:y,atlas:Aa(p,f),animationTime:d.current,...r?{affectedIds:r}:{},...i?{ageLens:i}:{}};E===`iso`?Ea(a,{...m,geom:Xn(e),labels:ie.current}):Nn(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 D.length>0&&(E===`iso`?Xn(e).geoms.some(e=>ae.has(e.block.id)&&Qn(a,e,n,r)):D.some(e=>S(a,e.rect,n,r)))?!0:E!==`iso`||t!==`street`?!1:oe.some(e=>Un(a,e.reservation,n,r))?!0:se.size>0&&Xn(e).geoms.some(e=>se.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,T.current(),m.current()&&(u.current=requestAnimationFrame(e=>g.current(e)))};let O=(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,O()},n=()=>O();return t(),e?.addEventListener(`change`,t),document.addEventListener(`visibilitychange`,n),()=>{e?.removeEventListener(`change`,t),document.removeEventListener(`visibilitychange`,n)}},[O]),(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`,O()};n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[O]),(0,h.useEffect)(()=>{let{w:t,h:n}=l.current;c.current=E===`iso`?Kn(e.bounds,Xn(e).maxHIso,t||800,n||600):te(e.bounds,t||800,n||600),w(null),O()},[e,E,O]),(0,h.useEffect)(()=>{O()},[t,y,i,O]);let ce=(0,h.useCallback)((t,n)=>{let r=c.current;if(E===`iso`)return ir(Xn(e),r,t,n);let i=x(r,t),a=ee(r,n);for(let t=e.blocks.length-1;t>=0;t--){let n=e.blocks[t];if(i>=n.rect.x&&i<=n.rect.x+n.rect.w&&a>=n.rect.y&&a<=n.rect.y+n.rect.h)return n}return null},[e,E]),k=(0,h.useCallback)((t,n,r)=>!t||E!==`iso`||t.state===`tombstoned`||!re(t)||v(c.current.scale)!==`street`?null:rr(e,t.id,c.current,n,r),[e,E]);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=ne(c.current,r,t.clientX-n.left,t.clientY-n.top),w(null),O()};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[O]),(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},w(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},O();return}let n=e.clientX-t.left,r=e.clientY-t.top,i=ce(n,r);b(i?.id??null);let a=k(i,n,r);w(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=ce(t,i);n(a,k(a,t,i))}},onPointerLeave:()=>{b(null),w(null)},style:{cursor:_.current?`grabbing`:y?`pointer`:`grab`,touchAction:`none`}}),C&&(0,$.jsxs)(`div`,{className:`filemap-symtip`,style:{left:C.x,top:C.y},children:[(0,$.jsx)(`strong`,{children:C.building.label}),(0,$.jsxs)(`span`,{children:[C.building.kind,C.building.lines===void 0?``:` · ${C.building.lines} ${C.building.lines===1?`line`:`lines`}`]})]})]})}var Fa={tsx:`typescript`,jsx:`javascript`,c:`cpp`,c_sharp:`csharp`,bash:`shell`,text:`plaintext`,toml:`ini`,properties:`ini`,yml:`yaml`};function Ia(e){let t=e?.trim().toLowerCase();if(t)return Fa[t]??t}var La=s(`filemap`),Ra=()=>void 0;function za(e){let t=e.line==null?``:` (Line ${e.line})`;return`[${e.severity}] ${e.category} — ${e.message}${t}`}function Ba(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 Va={added:`added`,modified:`modified`,deleted:`deleted`,renamed:`renamed`},Ha={residential:`residential`,commercial:`commercial`,civic:`civic landmark`,industrial:`industrial`},Ua={lush:`lush`,tidy:`tidy`,plain:`plain`,scruffy:`scruffy`,blighted:`blighted`},Wa=[{value:`core`,label:`Code`},{value:`tests`,label:`Tests`},{value:`all`,label:`All`}];function Ga({projectId:e}){let[t,n]=(0,h.useState)(null),[a,s]=(0,h.useState)(!1),[u,d]=(0,h.useState)(null),[p,g]=(0,h.useState)(null),[_,v]=(0,h.useState)(null),[y,b]=(0,h.useState)(`core`),[x,ee]=(0,h.useState)([]),[te,ne]=(0,h.useState)(null),[S,C]=(0,h.useState)(!1),[re,w]=(0,h.useState)(()=>Ma()),[T,ie]=(0,h.useState)(null),[E,D]=(0,h.useState)([]),[ae,oe]=(0,h.useState)(!1),[se,O]=(0,h.useState)(null),[ce,k]=(0,h.useState)(null),[le,ue]=(0,h.useState)(null),[de,fe]=(0,h.useState)(0),[A,pe]=(0,h.useState)(null),[me,he]=(0,h.useState)(!1),[ge,_e]=(0,h.useState)(!1),[ve,ye]=(0,h.useState)(!1),[be,xe]=(0,h.useState)(null),j=(0,h.useRef)(new Map),Se=(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)},[]),Ce=(0,h.useCallback)((e,t)=>{Se(e,t?.lineStart??1)},[Se]),M=p?.id??null;(0,h.useEffect)(()=>{if(ye(!1),!M){ie(null);return}let t=!1;return ie({path:M,kind:`loading`}),c.readProjectWorkspaceFile(e,M).then(e=>{t||ie(Ba(e.content)?{path:M,kind:`binary`}:{path:M,kind:`ready`,content:e.content})}).catch(e=>{t||ie({path:M,kind:`error`,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[M,e]),(0,h.useEffect)(()=>{if(!M){D([]),O(null),ue(null);return}let t=!1;return oe(!0),ue(null),c.toolScanFindings(e,{path:M,maxResults:100}).then(e=>{if(t)return;let n=e.findings.filter(e=>e.path===M);D(n),O(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:M,line:r})}).catch(e=>{t||(D([]),ue(e instanceof Error?e.message:String(e)))}).finally(()=>{t||oe(!1)}),()=>{t=!0}},[M,e,de]),(0,h.useEffect)(()=>{if(!M){pe(null),he(!1),_e(!1);return}let t=!1;return pe(null),he(!1),_e(!1),c.toolFileReview(e,{path:M}).then(e=>{t||(pe(e.review??null),he(e.pending===!0),_e(e.eligible===!1))}).catch(e=>{t||La.debug(`file-review unavailable`,e)}),()=>{t=!0}},[M,e]),(0,h.useEffect)(()=>{if(!M){xe(null);return}let t=j.current.get(M);if(t){xe({path:M,value:t});return}let n=!1;return xe(null),c.toolFileContext(e,{path:M}).then(e=>{if(n)return;let t=r(e);if(j.current.size>=20){let e=j.current.keys().next().value;e!==void 0&&j.current.delete(e)}j.current.set(M,t),xe({path:M,value:t})}).catch(e=>{n||La.debug(`file-context unavailable`,e)}),()=>{n=!0}},[M,e,de]);let N=(0,h.useCallback)(()=>{s(!0),d(null),j.current.clear(),c.toolFileMap(e,{scope:y,...te?{pr:te}:{}}).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,te]);(0,h.useEffect)(()=>{Se(null),N()},[N,Se]),(0,h.useEffect)(()=>{let t=!1;return c.listProjectGitHubPulls(e).then(e=>{t||ee(e.pulls)}).catch(()=>{t||ee([])}),()=>{t=!0}},[e]);let we=(0,h.useMemo)(()=>new Map((t?.overlay?.changedBlocks??[]).map(e=>[e.blockId,e])),[t]),Te=(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]),Ee=(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]),De=(0,h.useMemo)(()=>{if(!p||!t)return[];let e=new Set;for(let n of t.roads)n.a===p.id?e.add(n.b):n.b===p.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)},[p,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&&Se(r,n.line),!0},[t,Se]),ke=(0,h.useCallback)(e=>{O(e.fingerprint),e.line!=null&&v({path:e.path,line:e.line})},[]),Ae=(0,h.useCallback)(async t=>{k({fingerprint:t.fingerprint,kind:`resolve`}),ue(null);try{await c.resolveSecurityFinding(e,{fingerprint:t.fingerprint}),D(e=>e.filter(e=>e.fingerprint!==t.fingerprint)),O(null),j.current.delete(t.path),fe(e=>e+1),N()}catch(e){ue(e instanceof Error?e.message:String(e))}finally{k(null)}},[N,e]),je=(0,h.useCallback)(async t=>{k({fingerprint:t.fingerprint,kind:`delegate`}),ue(null);try{let n=await c.delegateSecurityFinding(e,{fingerprint:t.fingerprint});D(e=>e.map(e=>e.fingerprint===t.fingerprint?n.finding:e)),O(t.fingerprint)}catch(e){ue(e instanceof Error?e.message:String(e))}finally{k(null)}},[e]);(0,h.useEffect)(()=>{let e=[...new Set(E.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`)&&(j.current.clear(),fe(e=>e+1),N())},r=window.setInterval(()=>void n(),5e3);return n(),()=>{t=!0,window.clearInterval(r)}},[E,N]);let Me=A?o(A):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`}),Ee&&(0,$.jsxs)(`span`,{className:`filemap-stats`,children:[Ee.files,` files · `,Ee.folders,` neighborhoods · `,Ee.roads,` roads ·`,` `,Ee.symbols,` symbols`]}),t?.overlay&&(0,$.jsxs)(`span`,{className:`filemap-overlay-stat`,children:[`PR #`,t.overlay.prNumber,` · `,t.overlay.changedBlocks.length,` changed`,Te?` · ${Te.size} affected`:``]})]}),(0,$.jsxs)(`div`,{className:`filemap-actions`,children:[x.length>0&&(0,$.jsxs)(`select`,{className:`filemap-pr`,"aria-label":`Overlay a pull request`,value:te??``,onChange:e=>ne(e.target.value?Number(e.target.value):null),children:[(0,$.jsx)(`option`,{value:``,children:`No PR overlay`}),x.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:Wa.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:S?`active`:``,"aria-pressed":S,title:`Color blocks by how recently they were added — the evolution lens`,onClick:()=>C(e=>!e),children:`Age`})}),(0,$.jsx)(`fieldset`,{className:`filemap-scope`,"aria-label":`Renderer`,children:(0,$.jsx)(`button`,{type:`button`,className:re===`iso`?`active`:``,"aria-pressed":re===`iso`,title:`Isometric village view; toggle off for the flat top-down plan`,onClick:()=>w(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:N,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)(Pa,{model:t,selectedId:p?.id??null,onSelect:Ce,...Te?{affectedIds:Te}:{},renderer:re,ageLens:S}),p?(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:p.id,children:p.label}),(0,$.jsxs)(`div`,{className:`filemap-fileview-actions`,children:[De.length>0&&(0,$.jsxs)(`button`,{type:`button`,className:`filemap-fileview-connected-btn`,"aria-expanded":ve,onClick:()=>ye(e=>!e),children:[(0,$.jsxs)(`span`,{children:[`Connected (`,De.length,`)`]}),(0,$.jsx)(l,{})]}),(0,$.jsx)(`button`,{type:`button`,className:`filemap-fileview-close`,onClick:()=>Se(null),"aria-label":`Close`,children:`×`})]}),ve&&De.length>0&&(0,$.jsx)(`div`,{className:`filemap-fileview-menu`,children:(0,$.jsx)(`ul`,{children:De.slice(0,60).map(e=>(0,$.jsx)(`li`,{children:(0,$.jsx)(`button`,{type:`button`,title:e.id,onClick:()=>{Se(e),ye(!1)},children:e.label})},e.id))})})]}),(0,$.jsxs)(`div`,{className:`filemap-fileview-stats`,children:[(0,$.jsx)(`span`,{className:`filemap-fileview-path`,children:p.id}),(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[Math.round(p.weight),` lines`]}),(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[p.buildingCount,` symbols`]}),p.lang&&(0,$.jsx)(`span`,{className:`filemap-chip`,children:p.lang}),re===`iso`&&(0,$.jsx)(`span`,{className:`filemap-chip`,children:Ge(He(p))}),p.health&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[Ha[p.health.zone],` · `,Ua[p.health.vibe]]}),p.health&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`↓`,p.health.fanIn,` imported`]}),p.health&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`↑`,p.health.fanOut,` imports`]}),p.health&&p.health.findings>0&&(0,$.jsxs)(`span`,{className:`filemap-chip filemap-chip-warn`,children:[p.health.findings,` finding`,p.health.findings>1?`s`:``,p.health.maxSeverity?` (max ${p.health.maxSeverity})`:``]}),p.placedAt&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`since `,p.placedAt.slice(0,10)]}),we.get(p.id)&&(0,$.jsxs)(`span`,{className:`filemap-chip`,children:[`PR: `,Va[we.get(p.id).change],` `,(0,$.jsxs)(`span`,{className:`filemap-add`,children:[`+`,we.get(p.id).additions]}),` `,(0,$.jsxs)(`span`,{className:`filemap-del`,children:[`−`,we.get(p.id).deletions]})]})]})]}),(ae||E.length>0||le)&&(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:[E.length,` open finding`,E.length===1?``:`s`]}),ae&&(0,$.jsx)(`span`,{children:`Checking…`})]}),E.map(e=>{let t=e.fingerprint===se,n=ce?.fingerprint===e.fingerprint&&ce.kind===`resolve`,r=ce?.fingerprint===e.fingerprint&&ce.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:()=>f({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:ce!=null,children:n?`Resolving…`:`Mark resolved`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void je(e),disabled:ce!=null||e.status===`in_progress`,children:r?`Finding a developer…`:e.status===`in_progress`?`Developer working`:`Ask a developer gezel`})]})]})]},e.fingerprint)}),le&&(0,$.jsx)(`p`,{className:`filemap-finding-error error`,children:le})]}),(A||me||ge)&&(0,$.jsx)(`section`,{className:`filemap-review`,"aria-label":`Boekwachter review`,children:A?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`filemap-review-heading`,children:[(0,$.jsxs)(`strong`,{children:[`Boekwachter review · `,A.health,`/10`]}),(0,$.jsx)(`span`,{className:`filemap-review-reason`,children:A.healthReason})]}),A.notesMd&&(0,$.jsx)(`div`,{className:`filemap-review-notes`,children:(0,$.jsx)(m,{value:A.notesMd,readOnly:!0,minHeight:`0`,onCommit:Ra},`${p.id}:review-notes`)}),A.issues.length>0&&(0,$.jsx)(`ul`,{className:`filemap-review-issues`,children:A.issues.map((e,t)=>{let n=e.line;return(0,$.jsx)(`li`,{children:n==null?(0,$.jsx)(`span`,{className:`filemap-review-issue`,children:za(e)}):(0,$.jsx)(`button`,{type:`button`,className:`filemap-review-issue`,onClick:()=>v({path:p.id,line:n}),children:za(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})]}):ge?(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:!T||T.kind===`loading`?(0,$.jsxs)(`div`,{className:`filemap-empty`,children:[`Loading `,p.label,`…`]}):T.kind===`error`?(0,$.jsxs)(`div`,{className:`filemap-empty`,children:[`Couldn’t read this file: `,T.error]}):T.kind===`binary`?(0,$.jsx)(`div`,{className:`filemap-empty`,children:`Binary file — no preview.`}):(0,$.jsx)(Ka,{path:T.path,content:T.content,language:Ia(p.lang),sourceReveal:_?.path===T.path?_:void 0,findings:E,activeFinding:se,codeContext:be?.path===T.path?be.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 Ka({path:e,content:t,language:n,sourceReveal:r,findings:i,activeFinding:a,codeContext:o,onContextLink:s}){let c=p(),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)(qa,{request:r}),(0,$.jsx)(Ja,{findings:i,activeFinding:a})]}),fullWidth:!0,readOnly:!0,...l?{codeContext:l}:{}},e)}function qa({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 Ja({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{Ga as FileMapView,za as reviewIssueLabel};
|
|
@@ -1 +0,0 @@
|
|
|
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(),s=[{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 c(){let[e,t]=(0,a.useState)(null),[n,c]=(0,a.useState)(null),[d,f]=(0,a.useState)(null),[h,_]=(0,a.useState)(null),v=(0,a.useRef)(null),y=(0,a.useCallback)(async()=>{try{let e=await r.getFolders();t(e),c(null)}catch(e){c(e.message)}},[]);(0,a.useEffect)(()=>{y()},[y]),(0,a.useEffect)(()=>{if(!h||h.status===`done`||h.status===`error`||h.status===`cancelled`){v.current&&=(clearInterval(v.current),null);return}if(!v.current)return v.current=setInterval(async()=>{try{let e=await r.getFolderMoveStatus(h.id);_(e),(e.status===`done`||e.status===`error`||e.status===`cancelled`)&&await y()}catch(e){c(e.message)}},1e3),()=>{v.current&&=(clearInterval(v.current),null)}},[h,y]);let b=(0,a.useCallback)(async(e,t)=>{let n=window.__GEZEL__?.selectDirectory;if(!n){c(`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){c(t.validation.reason??`destination is not valid`);return}f({scope:e,destPath:i,plan:t,conflictPolicy:(t.conflicts,`overwrite-all`)})}catch(e){c(e.message)}},[]),x=(0,a.useCallback)(async()=>{if(d)try{let{jobId:e}=await r.startFolderMove({scope:d.scope,destPath:d.destPath,conflictPolicy:d.conflictPolicy});f(null),_({id:e,scope:d.scope,sourcePath:d.plan.sourcePath,destPath:d.destPath,status:`queued`,filesDone:0,totalFiles:d.plan.files,bytesDone:0,totalBytes:d.plan.bytes,restartRequired:!1,startedAt:new Date().toISOString()})}catch(e){c(e.message)}},[d]),S=(0,a.useCallback)(async t=>{try{let{jobId:n}=await r.resetFolder(t);_({id:n,scope:t,sourcePath:e?.current[t]??``,destPath:e?.defaults[t]??``,status:`queued`,filesDone:0,totalFiles:0,bytesDone:0,totalBytes:0,restartRequired:!1,startedAt:new Date().toISOString()})}catch(e){c(e.message)}},[e]),C=(0,a.useCallback)(async e=>{let t=window.__GEZEL__?.openPath;if(!t){c(`Opening folders is only available in the desktop app.`);return}let n=await t(e);n&&c(n)},[]),w=(0,a.useCallback)(async()=>{let e=window.__GEZEL__?.restartService;if(!e){c(`Restart is only available in the desktop app.`);return}try{let t=await e(`folders-changed`);t.ok||c(t.error)}catch(e){c(e.message)}},[]);return e?(0,o.jsxs)(`section`,{className:`settings-section`,children:[(0,o.jsx)(`h2`,{children:`Folders`}),(0,o.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 runs, a copy of the source is written to `,(0,o.jsx)(`code`,{children:e.backups.path}),` so the move can be undone by hand if something goes wrong.`]}),n&&(0,o.jsxs)(`p`,{className:`error small`,role:`alert`,children:[n,` `,(0,o.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>c(null),children:`dismiss`})]}),(0,o.jsx)(`div`,{className:`folders-rows`,children:s.map(t=>(0,o.jsx)(l,{label:t.label,help:t.help,currentPath:e.current[t.id],externalized:e.externalized[t.id],disabled:e.activeJob||h!==null,onPick:()=>b(t.id,t.label),onReset:()=>S(t.id),onOpen:()=>C(e.current[t.id])},t.id))}),e.backups.count>0&&(0,o.jsx)(u,{backups:e.backups,onOpen:C}),h&&(0,o.jsx)(m,{job:h,onRestart:w}),(0,o.jsx)(i,{open:d!==null,title:d?`Move ${d.plan.files} files?`:``,message:d&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`p`,{children:[(0,o.jsx)(`strong`,{children:`From:`}),` `,(0,o.jsx)(`code`,{children:d.plan.sourcePath})]}),(0,o.jsxs)(`p`,{children:[(0,o.jsx)(`strong`,{children:`To:`}),` `,(0,o.jsx)(`code`,{children:d.destPath})]}),(0,o.jsxs)(`p`,{children:[d.plan.files.toLocaleString(),` files (`,g(d.plan.bytes),`) will be copied. A backup snapshot will be saved before the move.`]}),d.plan.conflicts>0&&(0,o.jsxs)(`p`,{children:[(0,o.jsx)(`strong`,{children:d.plan.conflicts}),` file`,d.plan.conflicts===1?``:`s`,` already exist at the destination.`,(0,o.jsx)(p,{value:d.conflictPolicy,onChange:e=>f(t=>t&&{...t,conflictPolicy:e})})]}),(0,o.jsx)(`p`,{children:`The gezel service will need to restart afterwards. Sessions on disk are preserved.`})]}),confirmLabel:`Start move`,cancelLabel:`Cancel`,onConfirm:x,onCancel:()=>f(null)})]}):(0,o.jsxs)(`section`,{className:`settings-section`,children:[(0,o.jsx)(`h2`,{children:`Folders`}),(0,o.jsx)(`p`,{className:`muted small`,children:`Loading…`})]})}function l({label:e,help:t,currentPath:n,externalized:r,disabled:i,onPick:a,onReset:s,onOpen:c}){return(0,o.jsxs)(`div`,{className:`folders-row`,style:{marginTop:24},children:[(0,o.jsx)(`div`,{className:`folders-row-head`,children:(0,o.jsx)(`strong`,{children:e})}),(0,o.jsx)(`p`,{className:`muted small`,children:t}),(0,o.jsx)(`div`,{className:`muted small`,children:r?`External`:`Default location`}),(0,o.jsx)(`code`,{className:`folders-row-path`,children:n}),(0,o.jsxs)(`div`,{className:`folders-row-actions`,style:{marginTop:16},children:[(0,o.jsx)(`button`,{type:`button`,className:`primary`,onClick:a,disabled:i,children:`Move to other folder…`}),window.__GEZEL__?.openPath&&(0,o.jsx)(`button`,{type:`button`,onClick:c,children:`Open`}),r&&(0,o.jsx)(`button`,{type:`button`,onClick:s,disabled:i,children:`Reset to default`})]})]})}function u({backups:e,onOpen:t}){return(0,o.jsxs)(`div`,{className:`folders-snapshots`,style:{marginTop:24},children:[(0,o.jsx)(`h3`,{children:`Move snapshots`}),(0,o.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,o.jsx)(`ul`,{className:`folders-snapshot-list`,children:e.snapshots.map(e=>(0,o.jsxs)(`li`,{className:`folders-snapshot`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{children:d(e)}),(0,o.jsxs)(`div`,{className:`muted small`,children:[f(e.scopes),` · `,g(e.bytes)]})]}),window.__GEZEL__?.openPath&&(0,o.jsx)(`button`,{type:`button`,onClick:()=>t(e.path),children:`Open`})]},e.id))}),(0,o.jsxs)(`p`,{className:`muted small`,children:[g(e.totalBytes),` total in `,(0,o.jsx)(`code`,{children:e.path})]})]})}function d(e){return e.createdAt?new Date(e.createdAt).toLocaleString():e.id}function f(e){return e.length===0?`empty`:e.map(e=>s.find(t=>t.id===e)?.label??e).join(`, `)}function p({value:e,onChange:t}){return(0,o.jsxs)(`div`,{style:{marginTop:8},children:[(0,o.jsxs)(`label`,{style:{display:`block`,marginBottom:4},children:[(0,o.jsx)(`input`,{type:`radio`,name:`conflictPolicy`,checked:e===`overwrite-all`,onChange:()=>t(`overwrite-all`)}),` `,`Overwrite destination files`]}),(0,o.jsxs)(`label`,{style:{display:`block`},children:[(0,o.jsx)(`input`,{type:`radio`,name:`conflictPolicy`,checked:e===`skip-all`,onChange:()=>t(`skip-all`)}),` `,`Skip conflicting files (keep destination)`]})]})}function m({job:e,onRestart:t}){let n=e.totalFiles>0?Math.min(100,Math.round(e.filesDone/e.totalFiles*100)):0,r=h(e);return(0,o.jsxs)(`div`,{className:`folders-progress`,style:{marginTop:16},children:[(0,o.jsxs)(`div`,{className:`folders-progress-head`,children:[(0,o.jsxs)(`strong`,{children:[`Moving `,e.scope,` → `,(0,o.jsx)(`code`,{children:e.destPath})]}),(0,o.jsx)(`span`,{className:`muted small`,children:r})]}),e.status===`running`||e.status===`queued`?(0,o.jsxs)(`div`,{className:`ollama-pull-bar`,children:[(0,o.jsx)(`div`,{className:`ollama-pull-bar-fill`,style:{width:`${n}%`}}),(0,o.jsxs)(`span`,{className:`ollama-pull-bar-label`,children:[n,`%`]})]}):null,e.status===`error`&&(0,o.jsxs)(`p`,{className:`error small`,children:[`Error: `,e.error??`unknown`]}),e.status===`done`&&e.restartRequired&&(0,o.jsxs)(`p`,{style:{marginTop:8},children:[`Move complete.`,` `,(0,o.jsx)(`button`,{type:`button`,className:`primary`,onClick:t,children:`Restart now`})]}),e.status===`cancelled`&&(0,o.jsx)(`p`,{className:`muted small`,children:`Cancelled.`})]})}function h(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 (${g(e.bytesDone)} of ${g(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 g(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{c as FoldersSettings};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{Cn as r,Jt as i,W as a,_ as o,b as s,d as c,g as l,i as u,it as d,kt as f,m as p,n as m,pt as h,t as g,v as _}from"./dist-DOqbRmFj.js";import{t as v}from"./dist-CJqyWK6E.js";import{t as y}from"./api-C0I7spBl.js";import{i as b,n as x,r as S}from"./Tabs-jE0Z5Tzd.js";import{G as C,H as w,J as T,K as E,W as D,Y as O,d as k,l as A,m as j,p as M,q as N,s as P}from"./primitives-CWrGZpPI.js";import{n as F,t as I}from"./poppetje-CfaAvFkE.js";import{t as L}from"./ConfirmDialog-Dt1ed4Fh.js";import{a as R,o as ee,t as z}from"./model-inventory-ykSm_IT5.js";import{n as te}from"./styles-BvkZd-EV.js";import{C as B,It as V,K as H,f as ne,gt as re,ht as ie,jt as U,x as ae}from"./index-DDu8nyO6.js";import{i as oe,t as se}from"./ChatTimelineView-Cg_kLK_U.js";import{t as ce}from"./SessionSwitcher-BgZqyiRn.js";import{t as le}from"./ProjectTimeline-CTPcn4Kc.js";import{c as ue,l as de,n as fe,o as pe,r as me,s as he}from"./chat-thread-memory-CI2-giEq.js";import{t as ge}from"./ToolsetsEditor-J9XxQ5Ms.js";import{t as _e}from"./MemoriesTree-CgFqUNEr.js";import{t as ve}from"./markdown-baseline-9B52XlX2.js";import{t as ye}from"./TransformToolbarButton-gzIxUBH7.js";import{t as be}from"./ds4-availability-TaGRbP_O.js";import{a as xe,t as Se}from"./ModelPicker-BVkJhNAH.js";var W=e(t(),1),G=n();function Ce({gezel:e,onUpdated:t}){let n=e.fixedFunction,r=n?.defaults?JSON.stringify(n.defaults,null,2):``,[i,a]=(0,W.useState)(r),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(!1);(0,W.useEffect)(()=>{a(r),p(!1),s(null),l(null)},[e.id]);let m=(0,W.useCallback)(async()=>{s(null),l(null);let n=null;if(i.trim())try{let e=JSON.parse(i);if(e===null||Array.isArray(e)||typeof e!=`object`)throw Error(`defaults must be a JSON object`);n=e}catch(e){s(`Invalid JSON: ${e.message}`);return}d(!0);try{t(await y.updateGezelFixedFunctionDefaults(e.id,{defaults:n&&Object.keys(n).length>0?n:null})),p(!1),l(`Saved`)}catch(e){s(`Save failed: ${e.message}`)}finally{d(!1)}},[i,e.id,t]);return n?(0,G.jsxs)(`div`,{className:`ff-about-panel`,children:[(0,G.jsxs)(`div`,{className:`ff-about-summary`,children:[(0,G.jsxs)(`div`,{className:`ff-about-row`,children:[(0,G.jsx)(`span`,{className:`ff-label`,children:`Forwards to`}),(0,G.jsx)(`code`,{className:`ff-tool-name`,children:n.tool}),(0,G.jsx)(`span`,{className:`muted small`,children:`— no LLM is invoked`})]}),(0,G.jsxs)(`div`,{className:`ff-about-row`,children:[(0,G.jsx)(`span`,{className:`ff-label`,children:`Argument`}),(0,G.jsxs)(`span`,{children:[`Your message text is passed as `,(0,G.jsx)(`code`,{children:n.promptKey}),`.`]})]}),e.description&&(0,G.jsx)(`p`,{className:`muted`,children:e.description})]}),(0,G.jsxs)(`div`,{className:`ff-defaults`,children:[(0,G.jsx)(`label`,{className:`ff-defaults-label`,htmlFor:`ff-defaults-${e.id}`,children:`Default arguments`}),(0,G.jsxs)(`p`,{className:`muted small ff-defaults-help`,children:[`Merged into every call as JSON. Your message text on `,(0,G.jsx)(`code`,{children:n.promptKey}),` always wins over a collision here. Common keys for `,(0,G.jsx)(`code`,{children:n.tool}),`: `,(0,G.jsx)(`code`,{children:`width`}),`,`,` `,(0,G.jsx)(`code`,{children:`height`}),`, `,(0,G.jsx)(`code`,{children:`steps`}),`, `,(0,G.jsx)(`code`,{children:`model`}),`, `,(0,G.jsx)(`code`,{children:`negativePrompt`}),`. Leave empty to forward only the prompt.`]}),(0,G.jsx)(`textarea`,{id:`ff-defaults-${e.id}`,className:`ff-defaults-textarea`,value:i,spellCheck:!1,rows:10,placeholder:`{\\n "width": 1024,\\n "height": 1024\\n}`,onChange:e=>{a(e.target.value),p(!0),l(null)},disabled:u}),(0,G.jsxs)(`div`,{className:`ff-defaults-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>void m(),disabled:u||!f,children:u?`Saving…`:`Save defaults`}),c&&(0,G.jsx)(`span`,{className:`muted small`,children:c}),o&&(0,G.jsx)(`span`,{className:`error small`,children:o})]})]})]}):null}function we({gezelId:e,activeSessionId:t,onFocusSession:n,onToolActivity:r,onArtifactReference:i,onArtifactSeen:a,onWorkspaceReference:o,onWorkspaceSeen:s,onOpenReference:c,onTaskReference:l,emptyPlaceholder:u}){let d=(0,W.useCallback)(t=>y.listGezelTimeline(e,t),[e]),f=(0,W.useCallback)(()=>y.gezelEventsUrl(e),[e]),p=(0,W.useMemo)(()=>({gezelId:e}),[e]);return(0,G.jsx)(se,{scopeKey:`gezel:${e}`,activeSessionId:t,onFocusSession:n,onToolActivity:r,onArtifactReference:i,onArtifactSeen:a,onWorkspaceReference:o,onWorkspaceSeen:s,onOpenReference:c,...l?{onTaskReference:l}:{},emptyPlaceholder:u,loadTimeline:d,streamUrl:f,inflightScope:p})}var K=`__ALL__`,Te=`gezel:chat:last-project:`;function Ee(e){try{return window.localStorage.getItem(`${Te}${e}`)??void 0}catch{return}}function De({projects:e,intentProjectId:t,lastProjectId:n,workingProjectIds:r}){if(t)return e.find(e=>e.projectId===t)?.projectId??t;if(n&&r?.has(n))return n;let i=e.find(e=>r?.has(e.projectId));return i?i.projectId:n===K||e.some(e=>e.projectId===n)?n:e[0]?.projectId}function Oe(e,t){return e.find(e=>t?.has(e.projectId))?.projectId}function ke({gezel:e,engineLabel:t,workingProjectIds:n,activeTurnsReady:r=!0}){let[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)(null),f=(0,W.useRef)(0),p=(0,W.useCallback)((e,t)=>{f.current+=1,d({sessionId:e,requestKey:f.current,...t===void 0?{}:{messageIndex:t}})},[]),m=(0,W.useRef)(n),h=(0,W.useRef)(r),g=(0,W.useRef)(!1),_=(0,W.useRef)(!1);return m.current=n,h.current=r,(0,W.useEffect)(()=>{let t=!1;a(null),s(``),g.current=!1,_.current=!1;let n=H(e.id);return n&&(g.current=!0,_.current=!0,l(n.sessionId),p(n.sessionId,n.messageIndex)),y.listProjectsForGezel(e.id).then(r=>{if(t)return;a(r.projects);let i=De({projects:r.projects,intentProjectId:n?.projectId,lastProjectId:Ee(e.id),workingProjectIds:h.current?m.current:void 0});i&&s(i)}).catch(()=>{t||a([])}),()=>{t=!0}},[e.id,p]),(0,W.useEffect)(()=>{if(!r||i===null||!o||g.current||_.current||(g.current=!0,n?.has(o)))return;let e=Oe(i,n);e&&s(e)},[r,i,o,n]),(0,W.useEffect)(()=>{if(o)try{window.localStorage.setItem(`${Te}${e.id}`,o)}catch{}},[e.id,o]),(0,W.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.gezelId!==e.id||(g.current=!0,_.current=!0,n.projectId&&s(n.projectId),l(n.sessionId),p(n.sessionId,n.messageIndex))};return window.addEventListener(`gezel:open-session`,t),()=>window.removeEventListener(`gezel:open-session`,t)},[e.id,p]),(0,W.useEffect)(()=>{let t=t=>{if(t.detail?.gezelId!==e.id||i===null)return;let r=Oe(i,n);r&&(g.current=!0,_.current=!1,s(r))};return window.addEventListener(`gezel:prefer-working-project`,t),()=>window.removeEventListener(`gezel:prefer-working-project`,t)},[e.id,i,n]),(0,W.useEffect)(()=>{o&&o!=="default"&&o!==K&&window.dispatchEvent(new CustomEvent(`gezel:open-tab`,{detail:{kind:`project`,id:o,activate:!1}}))},[o]),i===null?(0,G.jsx)(`p`,{className:`muted small`,children:`Loading projects…`}):i.length===0?(0,G.jsx)(`p`,{className:`muted small`,children:`No projects available yet — create one from the Projects tab.`}):(0,G.jsxs)(`div`,{className:`gezel-chat-tab`,children:[(0,G.jsxs)(`div`,{className:`gezel-chat-project-row`,children:[(0,G.jsx)(`span`,{className:`muted small`,children:`Project:`}),(0,G.jsxs)(k,{value:o,onValueChange:e=>{_.current=!0,g.current=!0,s(e)},children:[(0,G.jsx)(M,{className:`gezel-chat-project-select`,children:(0,G.jsx)(j,{})}),(0,G.jsxs)(P,{children:[(0,G.jsx)(A,{value:K,children:`All projects`}),i.map(e=>(0,G.jsx)(A,{value:e.projectId,children:Ae(e)},e.projectId))]})]})]}),o===K?(0,G.jsx)(Me,{gezel:e},`${e.id}:__ALL__`):o&&(0,G.jsx)(je,{gezel:e,engineLabel:t,project:i.find(e=>e.projectId===o)??{projectId:o,projectName:o,precedence:`session`},focusSessionId:c||void 0,sessionFocusRequest:u??void 0},`${e.id}:${o}`)]})}function Ae(e){switch(e.precedence){case`voorman`:return`${e.projectName} — voorman`;case`assignment`:return`${e.projectName} — assigned`;case`session`:return`${e.projectName}`;case`fallback`:return`${e.projectName} (default)`}}function je({gezel:e,engineLabel:t,project:n,focusSessionId:r,sessionFocusRequest:o}){let s=a(e,B()),c=me(e.id,n.projectId),[l,u]=(0,W.useState)(()=>r??pe(c)?.sessionId??``),[d,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(0),[h,g]=(0,W.useState)(0),[_,v]=(0,W.useState)(null);(0,W.useEffect)(()=>{r&&u(r)},[r]),(0,W.useEffect)(()=>{he(c,{sessionId:l})},[c,l]);let y=(0,W.useMemo)(()=>{let t=i(e.gender);return`Talk to ${s} about what ${t.subject} ${t.presentBe} working on in this project.`},[s,e.gender]),b=(0,W.useMemo)(()=>ue({role:n.precedence===`voorman`?`voorman`:`other`,gezelName:s,gezelGender:e.gender,projectName:n.projectName,fixedFunctionTool:e.fixedFunction?.tool}),[n.precedence,n.projectName,s,e.gender,e.fixedFunction?.tool]);return(0,G.jsx)(de,{projectId:n.projectId,skillsProjectId:n.projectId==="default"?void 0:n.projectId,chatKey:`${n.projectId}:${e.id}`,children:({onToolActivity:r,onArtifactReference:i,onArtifactSeen:a,onWorkspaceReference:s,onWorkspaceSeen:c,recentReferences:x,onOpenReference:S,onTaskReference:C})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(le,{projectId:n.projectId,gezelId:e.id,activeSessionId:l||void 0,onFocusSession:(t,n)=>{n===e.id&&u(t)},onToolActivity:r,onArtifactReference:i,onArtifactSeen:a,onWorkspaceReference:s,onWorkspaceSeen:c,onOpenReference:S,onTaskReference:C,emptyPlaceholder:y,sessionFocusRequest:o}),_?(0,G.jsx)(Ne,{source:_,children:(0,G.jsx)(ce,{gezelId:e.id,projectId:n.projectId,sessionId:l||void 0,onSessionIdChange:e=>u(e??``),onActiveSessionChange:e=>v(e?.source??null),onFreshThread:()=>g(e=>e+1),refreshKey:p,engineLabel:t})}):(0,G.jsx)(oe,{gezelId:e.id,gezelName:e.name,gezelRoleBasedName:e.roleBasedName,gezelRole:e.role,gezelIcon:e.icon??null,gezelPoppetje:e.poppetje,gezelIconOverride:e.iconOverride,projectId:n.projectId,sessionId:l||void 0,focusRequestKey:h,onSessionCreated:e=>{u(e),m(e=>e+1)},onToolActivity:r,recentReferences:x,onOpenReference:S,placeholder:b,draftScope:`gezel`,draftId:d||void 0,onDraftIdChange:e=>f(e??``),belowAddressLine:(0,G.jsx)(ce,{gezelId:e.id,projectId:n.projectId,sessionId:l||void 0,onSessionIdChange:e=>u(e??``),onActiveSessionChange:e=>v(e?.source??null),onFreshThread:()=>g(e=>e+1),refreshKey:p,engineLabel:t,activeDraftId:d||void 0,onDraftSelect:e=>f(e??``),draftScope:`gezel`})})]})})}function Me({gezel:e}){let t=a(e,B()),n=fe(e.id),[r,i]=(0,W.useState)(()=>{let e=pe(n);return!e?.sessionId||!e.projectId?null:{sessionId:e.sessionId,projectId:e.projectId}});(0,W.useEffect)(()=>{he(n,{sessionId:r?.sessionId??``,projectId:r?.projectId??``})},[n,r?.sessionId,r?.projectId]);let o=(0,W.useMemo)(()=>`No chats with ${t} yet — start one below.`,[t]),s=(0,W.useMemo)(()=>ue({role:`other`,gezelName:t,gezelGender:e.gender,projectName:r?void 0:`default`,fixedFunctionTool:e.fixedFunction?.tool}),[t,e.gender,r,e.fixedFunction?.tool]),c=r?.projectId??`default`;return(0,G.jsx)(de,{projectId:c,skillsProjectId:c==="default"?void 0:c,chatKey:`all:${e.id}`,children:({onToolActivity:t,onArtifactReference:n,onArtifactSeen:a,onWorkspaceReference:l,onWorkspaceSeen:u,recentReferences:d,onOpenReference:f,onTaskReference:p})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(we,{gezelId:e.id,activeSessionId:r?.sessionId,onFocusSession:(e,t,n)=>{i({sessionId:e,projectId:n}),y.getChatSession(e).then(t=>{i(r=>r?.sessionId===e?{sessionId:e,projectId:n,...t.source?{source:t.source}:{}}:r)}).catch(()=>{})},onToolActivity:t,onArtifactReference:n,onArtifactSeen:a,onWorkspaceReference:l,onWorkspaceSeen:u,onOpenReference:f,onTaskReference:p,emptyPlaceholder:o}),r?.source?(0,G.jsx)(Ne,{source:r.source}):(0,G.jsx)(oe,{gezelId:e.id,gezelName:e.name,gezelRoleBasedName:e.roleBasedName,gezelRole:e.role,gezelIcon:e.icon??null,gezelPoppetje:e.poppetje,gezelIconOverride:e.iconOverride,projectId:c,sessionId:r?.sessionId,onSessionCreated:e=>i({sessionId:e,projectId:c}),onToolActivity:t,recentReferences:d,onOpenReference:f,placeholder:s,draftScope:`gezel-all`})]})})}function Ne({source:e,children:t}){return(0,G.jsxs)(`div`,{className:`external-conversation-panel`,"aria-live":`polite`,children:[t,(0,G.jsxs)(`div`,{className:`external-conversation-notice`,children:[(0,G.jsxs)(`span`,{className:`external-conversation-label`,children:[`From `,e.appName,` · read-only`]}),(0,G.jsxs)(`span`,{children:[`This conversation updates live here. Replies and tool controls stay in `,e.appName,`.`]})]})]})}function Pe({gezelRole:e,gezelTemplateId:t,onApply:n}){let[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)([]),[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(null),[d,f]=(0,W.useState)(null);(0,W.useEffect)(()=>{r&&(c(!0),f(null),y.listCatalogItems(`gezel-template`).then(e=>o(e.items)).catch(e=>f(e.message)).finally(()=>c(!1)))},[r]);let p=(0,W.useMemo)(()=>{let n=a.filter(e=>e.manifest.kind===`gezel-template`),r=e?.toLowerCase().trim(),i=t?n.find(e=>e.manifest.id===t)?.manifest.id:void 0,o=i??(r?n.find(e=>e.manifest.role.toLowerCase().trim()===r)?.manifest.id:void 0);return n.map(e=>({item:e,isSuggested:e.manifest.id===o,isOriginal:e.manifest.id===i})).sort((e,t)=>e.isSuggested===t.isSuggested?e.item.manifest.name.localeCompare(t.item.manifest.name):e.isSuggested?-1:1)},[a,e,t]),m=(0,W.useCallback)(async e=>{u(e),f(null);try{let t=(await y.getCatalogItem(`gezel-template`,e)).about??``;if(!t.trim()){f(`This template has no about.md content.`);return}await n(e,t),i(!1)}catch(e){f(e.message)}finally{u(null)}},[n]);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{type:`button`,className:`ai-btn`,onClick:()=>i(!0),title:`Replace this gezel's about.md with a gilde template`,"aria-label":`Use a template`,children:`📇`}),(0,G.jsx)(T,{open:r,onOpenChange:e=>{e||(i(!1),f(null))},children:(0,G.jsxs)(N,{children:[(0,G.jsx)(E,{}),(0,G.jsxs)(D,{className:`gz-dialog-wide`,children:[(0,G.jsx)(O,{asChild:!0,children:(0,G.jsx)(`h3`,{children:`Apply a template`})}),(0,G.jsxs)(C,{className:`muted small`,children:[`Replace this gezel's `,(0,G.jsx)(`code`,{children:`about.md`}),` with a template from the gilde. Current content is overwritten — you can edit back to undo.`]}),s&&(0,G.jsx)(`p`,{className:`muted`,children:`Loading templates…`}),!s&&p.length===0&&(0,G.jsx)(`p`,{className:`muted`,children:`No gilde templates available.`}),!s&&p.length>0&&(0,G.jsx)(`ul`,{className:`gezel-template-list`,children:p.map(({item:e,isSuggested:t,isOriginal:n})=>{let r=e.manifest,i=l===r.id;return(0,G.jsxs)(`li`,{className:t?`suggested`:void 0,children:[(0,G.jsxs)(`div`,{className:`gezel-template-head`,children:[(0,G.jsx)(`strong`,{children:r.name}),(0,G.jsx)(`span`,{className:`muted small`,children:r.role}),t&&(0,G.jsx)(`span`,{className:`gezel-template-badge`,children:n?`Original`:`Matches role`})]}),r.description&&(0,G.jsx)(`p`,{className:`muted small`,children:r.description}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void m(r.id),disabled:l!==null,children:i?`Applying…`:t?`Reset to this`:`Use this`})]},r.id)})}),d&&(0,G.jsx)(`p`,{className:`gz-dialog-error`,children:d}),(0,G.jsx)(w,{children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),disabled:l!==null,children:`Cancel`})})]})]})})]})}function Fe({gezel:e,inherited:t,effectiveProvider:n,onUpdated:r}){let i=(0,W.useCallback)(async t=>{r(await y.updateGezelSettings(e.id,{tuning:t}))},[e.id,r]);return(0,G.jsxs)(`div`,{className:`gezel-tuning-editor`,children:[(0,G.jsx)(Ie,{gezel:e,availableProfiles:Object.keys(t?.profiles??{}),onUpdated:r}),(0,G.jsx)(xe,{provider:n,override:e.parsed?.frontmatter?.tuning,...t?{inherited:t}:{},...e.parsed?.frontmatter?.tuningProfile?{tuningProfileId:e.parsed.frontmatter.tuningProfile}:{},onSave:i,scopeLabel:e.name??`this gezel`})]})}function Ie({gezel:e,availableProfiles:t,onUpdated:n}){let r=e.parsed?.frontmatter?.tuningProfile??``,[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(null),c=(0,W.useMemo)(()=>t.map(e=>{let t=h(e)?u[e]:null;return{id:e,label:t?.label??e,description:t?.description}}),[t]),l=(0,W.useCallback)(async t=>{a(!0),s(null);try{let r=t===``?null:t;n(await y.updateGezelSettings(e.id,{tuningProfile:r}))}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}},[e.id,n]);return c.length===0&&!r?null:(0,G.jsxs)(`div`,{className:`voice-picker`,style:{marginBottom:`0.75rem`},children:[(0,G.jsxs)(`label`,{htmlFor:`voice-${e.id}`,className:`small`,style:{display:`block`,marginBottom:`0.25rem`},children:[(0,G.jsx)(`strong`,{children:`Voice`}),` `,(0,G.jsx)(`span`,{className:`muted`,children:`— preset the model applies for this gezel. Your manual tuning below overrides individual fields.`})]}),(0,G.jsxs)(`select`,{id:`voice-${e.id}`,value:r,onChange:e=>void l(e.target.value),disabled:i,children:[(0,G.jsx)(`option`,{value:``,children:`(automatic — use template / model default)`}),c.map(e=>(0,G.jsx)(`option`,{value:e.id,title:e.description,children:e.label},e.id))]}),o&&(0,G.jsx)(`div`,{className:`small error`,style:{marginTop:`0.25rem`},children:o})]})}function q({level:e,pending:t=!1,overlay:n=!1}){if(e<2&&!t)return null;let r=t?`Level ${e} — a level-up is waiting in the Growth tab`:`Level ${e}`;return(0,G.jsxs)(`span`,{className:`level-badge${n?` level-badge--overlay`:``}`,title:r,"aria-label":r,children:[`Lv `,e,t&&(0,G.jsx)(`span`,{className:`level-badge-dot`,"aria-hidden":`true`})]})}function Le(e,t,n){if(n<=t)return 100;let r=(e-t)/(n-t)*100;return Math.max(0,Math.min(100,Math.round(r)))}function J(e){let[t,n,r]=e.split(`-`).map(e=>Number.parseInt(e,10));return!t||!n||!r?e:new Date(Date.UTC(t,n-1,r)).toLocaleDateString(void 0,{month:`short`,day:`numeric`,timeZone:`UTC`})}var Re={fact:`Fact`,decision:`Decision`,pref:`Preference`,status:`Status`};function ze(e){return[{label:`Memories`,value:e.memoryXp,hint:`Distinct deduplicated memories — preferences and decisions weigh most.`},{label:`Lessons`,value:e.lessonsXp,hint:`Times the distilled lessons file was refined.`},{label:`Task work`,value:e.taskXp,hint:`Completed task steps and finished tasks.`},{label:`Consults`,value:e.consultXp,hint:`Delivered gezel-to-gezel consultations (daily-capped).`}]}function Be(e,t){return`gezel-growth-celebrated:${e}:${t}`}function Ve(e){switch(e.kind){case`trait`:return`Adopt this trait`;case`tuning`:if(e.action.type===`profile`){let t=e.action.profile;return`Switch to ${h(t)?u[t].label:t}`}return e.action.delta>0?`Run a little warmer`:`Run a little cooler`;case`cosmetic`:{let t=d(e.cosmeticId);return t?`Unlock ${t.label.toLowerCase()}`:`Mark the milestone`}}}function Y(e){if(e instanceof v){let t=e.details;if(typeof t==`object`&&t?.error)return t.error;if(typeof t==`string`&&t)return t}return e instanceof Error?e.message:String(e)}function He(e){return e instanceof v&&e.status===409&&Y(e).includes(`no pending level-up`)}function Ue(e,t){let[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(!1),f=(0,W.useCallback)(async()=>{try{r(await y.getGezelGrowth(e)),a(null)}catch(e){a(Y(e))}},[e]);(0,W.useEffect)(()=>{f()},[f]),(0,W.useEffect)(()=>{let t=t=>{let n=t.detail;(!n?.gezelId||n.gezelId===e)&&f()};return window.addEventListener(`gezel:growth-updated`,t),()=>window.removeEventListener(`gezel:growth-updated`,t)},[e,f]);let p=(0,W.useCallback)(async()=>{try{let t=await y.getGezel(e);window.dispatchEvent(new CustomEvent(`gezel:gezel-updated`,{detail:t}))}catch{}t?.()},[e,t]),m=(0,W.useCallback)(async(e,t,n)=>{l(e??`*`),s(null);try{r(await t()),n&&await p()}catch(e){He(e)?s(`This level-up was already resolved in another window.`):s(Y(e)),await f()}finally{l(null)}},[p,f]),h=(0,W.useCallback)(t=>m(t,()=>y.acceptGrowthProposal(e,t),!0),[e,m]),g=(0,W.useCallback)(t=>m(t,()=>y.declineGrowthLevelUp(e,t),!1),[e,m]),_=(0,W.useCallback)(()=>m(null,()=>y.declineGrowthLevelUp(e),!1),[e,m]),v=(0,W.useCallback)(t=>m(null,()=>y.retireGrowthTrait(e,t),!0),[e,m]),b=(0,W.useCallback)(async()=>{d(!0),s(null);try{r(await y.refreshGezelGrowth(e)),a(null)}catch(e){s(Y(e))}finally{d(!1)}},[e]);return{growth:n,error:i,notice:o,clearNotice:(0,W.useCallback)(()=>s(null),[]),busyId:c,refreshing:u,refresh:b,accept:h,decline:g,skipLevel:_,retireTrait:v}}function We({gezel:e,onUpdated:t}){let n=Ue(e.id,t),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(null),[f,p]=(0,W.useState)(!1),m=n.growth?.state.pendingLevelUp?.toLevel;if((0,W.useEffect)(()=>{if(m===void 0)return;let t=Be(e.id,m);try{if(window.localStorage.getItem(t))return;window.localStorage.setItem(t,`1`)}catch{}p(!0);let n=setTimeout(()=>p(!1),1600);return()=>clearTimeout(n)},[e.id,m]),n.error)return(0,G.jsx)(`section`,{className:`growth-panel`,"data-testid":`growth-panel`,children:(0,G.jsxs)(`p`,{className:`error`,children:[`Couldn't load growth: `,n.error]})});if(!n.growth)return(0,G.jsx)(`section`,{className:`growth-panel`,"data-testid":`growth-panel`,children:(0,G.jsx)(`p`,{className:`placeholder`,children:`Loading growth…`})});let{state:g,nextLevelXp:_,activeTraits:v,driftedTraitIds:y}=n.growth,b=g.pendingLevelUp,x=r(g.level),S=Le(g.xp,x,_),C=g.level===1&&!b&&v.length===0&&g.xp===0;return(0,G.jsxs)(`section`,{className:`growth-panel`,"data-testid":`growth-panel`,children:[n.notice&&(0,G.jsxs)(`output`,{className:`growth-notice`,children:[(0,G.jsx)(`span`,{children:n.notice}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:n.clearNotice,children:`Dismiss`})]}),b&&i&&(0,G.jsxs)(`div`,{className:`growth-deferred-reminder`,children:[(0,G.jsxs)(`span`,{children:[e.name,` reached level `,b.toLevel,` — growth choices are waiting.`]}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:()=>a(!1),children:`Show choices`})]}),b&&!i&&(0,G.jsx)(Ge,{gezel:e,growth:n,onDefer:()=>a(!0),onSkip:()=>s(!0)}),(0,G.jsxs)(`header`,{className:`growth-header`,children:[(0,G.jsxs)(`span`,{className:`level-badge-anchor${f?` growth-celebrate`:``}`,children:[(0,G.jsx)(V,{svg:e.icon??null,poppetje:f&&e.poppetje?{...e.poppetje,expression:`wider`}:e.poppetje,iconOverride:e.iconOverride,name:e.name,size:96}),(0,G.jsx)(q,{level:g.level,pending:!!b,overlay:!0})]}),(0,G.jsxs)(`div`,{className:`growth-header-text`,children:[(0,G.jsxs)(`h4`,{children:[e.name,` · Level `,g.level]}),(0,G.jsx)(`div`,{className:`growth-xp-bar`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":S,"aria-label":`${g.xp} XP — ${_} needed for level ${g.level+1}`,tabIndex:-1,children:(0,G.jsx)(`div`,{className:`growth-xp-fill`,style:{width:`${S}%`}})}),(0,G.jsxs)(`span`,{className:`muted small`,children:[g.xp,` XP · `,Math.max(0,_-g.xp),` to level `,g.level+1]})]}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn growth-refresh`,disabled:n.refreshing,title:`Recompute XP from memories, lessons, and task work now`,onClick:()=>void n.refresh(),children:n.refreshing?`Checking…`:`Check growth now`})]}),C?(0,G.jsxs)(`div`,{className:`growth-empty`,children:[(0,G.jsxs)(`p`,{children:[`Growth here is earned, not simulated — every point comes from real work. As `,e.name,` `,`accumulates distinct memories, distills lessons, and completes tasks, XP adds up; at each level you'll choose how they grow.`]}),(0,G.jsx)(`div`,{className:`growth-trait-ghost`,"aria-hidden":`true`,children:`Trait slot · unlocks at Level 2`})]}):(0,G.jsx)(`div`,{className:`growth-counters`,children:ze(g.signals).map(e=>(0,G.jsxs)(`div`,{className:`growth-counter`,title:e.hint,children:[(0,G.jsx)(`span`,{className:`growth-counter-value`,children:e.value}),(0,G.jsx)(`span`,{className:`growth-counter-label`,children:e.label})]},e.label))}),y.length>0&&(0,G.jsxs)(`p`,{className:`growth-drift-warning`,children:[y.length===1?`One adopted trait is`:`Some adopted traits are`,` no longer in `,e.name,`'s frontmatter — likely lost to a manual gezel.md edit. Re-adopt from a future level-up, or edit the frontmatter directly.`]}),v.length>0&&(0,G.jsxs)(`div`,{className:`growth-traits`,children:[(0,G.jsx)(`h5`,{children:`Traits`}),v.map(e=>{let t=g.adoptedTraits.find(t=>t.traitId===e.id&&!t.removedAt);return(0,G.jsxs)(`details`,{className:`growth-trait`,children:[(0,G.jsxs)(`summary`,{children:[(0,G.jsx)(`span`,{className:`growth-trait-text`,children:e.text}),(0,G.jsxs)(`span`,{className:`muted small`,children:[` `,`· adopted `,J(e.adoptedAt.slice(0,10))]})]}),t&&t.evidence.length>0&&(0,G.jsx)(`div`,{className:`growth-trait-evidence`,children:t.evidence.map(e=>(0,G.jsxs)(`blockquote`,{children:[`“`,e.excerpt,`”`,(0,G.jsxs)(`footer`,{children:[(0,G.jsx)(`span`,{className:`growth-day-chip`,children:J(e.day)}),(0,G.jsx)(`span`,{className:`growth-kind-chip`,children:Re[e.kind]??e.kind})]})]},`${e.day}-${e.excerpt.slice(0,24)}`))}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn growth-retire`,disabled:n.busyId!==null,onClick:()=>l(e),children:`Retire this trait`})]},e.id)})]}),e.tuningProfile&&h(e.tuningProfile)&&(0,G.jsxs)(`div`,{className:`growth-tuning`,children:[(0,G.jsx)(`h5`,{children:`Tuning`}),(0,G.jsx)(`span`,{className:`growth-tuning-chip`,children:u[e.tuningProfile].label})]}),g.unlockedCosmetics.length>0&&(0,G.jsxs)(`div`,{className:`growth-cosmetics`,children:[(0,G.jsx)(`h5`,{children:`Unlocked`}),(0,G.jsx)(`div`,{className:`growth-cosmetics-row`,children:g.unlockedCosmetics.map(e=>{let t=d(e.id);return(0,G.jsx)(`span`,{className:`growth-cosmetic-chip`,children:t?t.label:e.id.replace(/^level-(\d+)$/,`Level $1 milestone`)},e.id)})})]}),(0,G.jsx)(L,{open:o,title:`Skip level ${b?.toLevel??g.level+1}?`,message:`The level still advances — it was earned — but these trait offers won't come back. The evidence stays in memory for future level-ups.`,confirmLabel:`Skip this level`,onConfirm:async()=>{await n.skipLevel(),s(!1)},onCancel:()=>s(!1)}),(0,G.jsx)(L,{open:c!==null,title:`Retire this trait?`,message:c?(0,G.jsxs)(G.Fragment,{children:[`“`,c.text,`” will stop shaping `,e.name,`'s behavior. The adoption record and its evidence stay on the character sheet.`]}):void 0,confirmLabel:`Retire`,danger:!0,onConfirm:async()=>{c&&await n.retireTrait(c.id),l(null)},onCancel:()=>l(null)})]})}function Ge({gezel:e,growth:t,onDefer:n,onSkip:r}){let i=t.growth.state.pendingLevelUp;return i?(0,G.jsxs)(`div`,{className:`growth-levelup`,children:[(0,G.jsxs)(`h4`,{children:[e.name,` reached level `,i.toLevel,`.`]}),(0,G.jsx)(`p`,{className:`muted`,children:`Pick one way to grow — or skip; the evidence isn't going anywhere.`}),(0,G.jsx)(`div`,{className:`growth-proposals`,children:i.proposals.map(n=>(0,G.jsx)(Ke,{proposal:n,gezel:e,busy:t.busyId!==null,declinable:i.proposals.length>1,onAccept:()=>void t.accept(n.id),onDecline:()=>void t.decline(n.id)},n.id))}),(0,G.jsxs)(`div`,{className:`growth-levelup-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:n,children:`Decide later`}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:r,children:`Skip this level`})]})]}):null}function Ke({proposal:e,gezel:t,busy:n,declinable:r,onAccept:i,onDecline:a}){return(0,G.jsxs)(`div`,{className:`growth-proposal-card`,"data-kind":e.kind,children:[(0,G.jsx)(`span`,{className:`growth-proposal-kind`,children:qe[e.kind]}),(0,G.jsx)(`h5`,{children:e.title}),e.kind===`trait`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:`growth-proposal-trait-text`,children:[`“`,e.traitText,`”`]}),(0,G.jsx)(`div`,{className:`growth-trait-evidence`,children:e.evidence.map(e=>(0,G.jsxs)(`blockquote`,{children:[`“`,e.excerpt,`”`,(0,G.jsxs)(`footer`,{children:[(0,G.jsx)(`span`,{className:`growth-day-chip`,children:J(e.day)}),(0,G.jsx)(`span`,{className:`growth-kind-chip`,children:Re[e.kind]??e.kind})]})]},`${e.day}-${e.excerpt.slice(0,24)}`))})]}),e.kind===`tuning`&&(0,G.jsx)(`p`,{className:`muted small`,children:e.description}),e.kind===`cosmetic`&&(0,G.jsx)(Je,{poppetje:t.poppetje??null,cosmeticId:e.cosmeticId}),(0,G.jsxs)(`div`,{className:`growth-proposal-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`primary`,disabled:n,onClick:i,children:Ve(e)}),r&&(0,G.jsx)(`button`,{type:`button`,disabled:n,onClick:a,children:`Not this one`})]})]})}var qe={trait:`Trait`,tuning:`Tuning`,cosmetic:`Cosmetic`};function Je({poppetje:e,cosmeticId:t}){let n=d(t);return!n||!e?n?(0,G.jsx)(`p`,{className:`muted small`,children:n.label}):null:(0,G.jsxs)(`div`,{className:`growth-cosmetic-tryon`,children:[(0,G.jsx)(`div`,{className:`growth-cosmetic-figure`,children:(0,G.jsx)(I,{poppetje:{...e,[n.slot]:n.option},variant:`headshot`,size:56})}),(0,G.jsx)(`span`,{className:`muted small`,children:n.label})]})}var X=`__INHERIT__`;function Ye(e,t){return e?`${e}:${t??``}`:X}function Xe(e){if(e===X)return{kind:`inherit`};let t=e.indexOf(`:`);return t<0?{kind:`inherit`}:{kind:`override`,provider:e.slice(0,t),model:e.slice(t+1)||void 0}}function Ze(){let e=window.__GEZEL__?.platform;if(e)return U(e);let t=typeof navigator>`u`?``:navigator.userAgent??``;return/Mac/i.test(t)?U(`darwin`):/Win/i.test(t)?U(`win32`):/Linux/i.test(t)?U(`linux`):U()}function Qe(e){switch(e){case`copilot`:return`GitHub Copilot`;case`openai`:return`OpenAI`;case`anthropic`:return`Anthropic`;case`anthropic-cli`:return`Claude CLI`;case`codex-cli`:return`Codex CLI`;case`ollama`:return`Ollama`;case`mlx`:case`llama-cpp`:return Ze();case`ds4`:return`DwarfStar (ds4)`;default:return e}}function $e({provider:e,model:t,onChange:n,globalProvider:r,disabled:i}){let[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(!0),[l,u]=(0,W.useState)(0),d=(0,W.useRef)(null),f=(0,W.useRef)(!1);f.current=r===`copilot`||e===`copilot`,(0,W.useEffect)(()=>{let e=e=>{let t=R(e);t&&(d.current=t,u(e=>e+1))};return window.addEventListener(z,e),()=>window.removeEventListener(z,e)},[]),(0,W.useEffect)(()=>{let e=!1;return c(!0),(async()=>{let t=null,n=null,r=null;try{[t,n,r]=await Promise.all([y.getConfig(),y.getCopilotStatus().catch(()=>null),y.getMemoryProfile().catch(()=>null)])}catch{e||(o([]),c(!1));return}let i=[];(n?.available!==!1||f.current)&&i.push(`copilot`),t.hasOpenaiApiKey&&i.push(`openai`),t.hasAnthropicApiKey&&i.push(`anthropic`),t.anthropicCliStatus?.installed&&i.push(`anthropic-cli`),t.codexCliStatus?.installed&&i.push(`codex-cli`),i.push(`ollama`);let a=typeof navigator>`u`?``:navigator.userAgent;/Mac/i.test(a)&&i.push(`mlx`),i.push(`llama-cpp`),be({externalBaseUrl:t.ds4BaseUrl,totalRamBytes:r?.totalRamBytes}).status!==`unavailable`&&i.push(`ds4`);let s=await Promise.all(i.map(async e=>{try{let t=(e===`llama-cpp`||e===`mlx`||e===`ds4`)&&(d.current===e&&l>0||ee(e)>0),n=await y.listProviderModels(e,t?{refresh:!0}:void 0);return n.models.length===0?null:{provider:e,label:Qe(e),models:n.models}}catch{return null}}));if(e)return;let u=s.filter(e=>e!==null),p=[`mlx`,`llama-cpp`,`ds4`,`ollama`,`copilot`,`openai`,`anthropic`,`anthropic-cli`,`codex-cli`];u.sort((e,t)=>p.indexOf(e.provider)-p.indexOf(t.provider)),o(u),c(!1)})(),()=>{e=!0}},[l]);let p=(0,W.useMemo)(()=>Ye(e,t),[e,t]),m=(0,W.useMemo)(()=>`Inherit default (${Qe(r)})`,[r]);return s?(0,G.jsx)(`span`,{className:`muted small`,children:`loading providers…`}):!a||a.length===0?(0,G.jsxs)(`span`,{className:`muted small`,children:[`No providers configured —`,` `,(0,G.jsx)(`button`,{type:`button`,className:`provider-model-select-link`,onClick:()=>{re(`defaults`),window.dispatchEvent(new CustomEvent(`gezel:navigate`,{detail:{view:`settings`,section:`defaults`}}))},children:`set one up`})]}):(0,G.jsxs)(k,{value:p,onValueChange:e=>{let t=Xe(e);t.kind===`inherit`?n(null,void 0):n(t.provider,t.model)},disabled:i,children:[(0,G.jsx)(M,{children:(0,G.jsx)(j,{})}),(0,G.jsxs)(P,{children:[(0,G.jsx)(A,{value:X,children:m}),a.map(e=>e.models.map(t=>(0,G.jsxs)(A,{value:`${e.provider}:${t.id}`,children:[e.label,` — `,t.name,t.supportsReasoning?` · reasoning`:``]},`${e.provider}:${t.id}`)))]})]})}function et(e){switch(e){case`generate_video`:return{kind:`Video`,list:()=>y.listInstalledVideoModels()};case`generate_image`:return{kind:`Image`,list:()=>y.listInstalledImageModels()};default:return null}}function tt(e){let t=e?.tool,n=typeof e?.defaults?.model==`string`?e.defaults.model:void 0,[r,i]=(0,W.useState)(null);return(0,W.useEffect)(()=>{if(!t){i(null);return}let e=et(t);if(!e){i(null);return}if(i(n?`${e.kind} · ${n}`:`${e.kind} generator`),n)return;let r=!1;return e.list().then(t=>{if(r)return;let n=t.defaultModel??t.models[0]?.id,a=t.models.find(e=>e.id===n)?.name??n;i(a?`${e.kind} · ${a}`:`${e.kind} generator`)}).catch(()=>{}),()=>{r=!0}},[t,n]),r}function Z(e){window.dispatchEvent(new CustomEvent(`gezel:gezel-updated`,{detail:e}))}function nt({gezelId:e,onDeleted:t,workingProjectIds:n,activeTurnsReady:r}){let i=ie(),a=B(),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(!1),[v,C]=(0,W.useState)(0),[w,T]=(0,W.useState)(`chat`),[E,D]=(0,W.useState)(!1),[O,k]=(0,W.useState)(``),[A,j]=(0,W.useState)(!1),M=o?.fixedFunction!==void 0,N=M&&(w===`toolsets`||w===`memories`)?`chat`:w,P=tt(o?.fixedFunction),F=(0,W.useRef)(null),I=(0,W.useCallback)(t=>y.updateGezelAbout(e,{source:t}),[e]),L=ae({resourceKey:`gezel:${e}:about`,initialValue:``,save:I,onLatestSaved:t=>{let n=F.current;if(!n||n.id!==e)return;let r={...n,about:t.about};F.current=r,s(r),Z(r)}});(0,W.useEffect)(()=>{let t=!1;return s(null),l(null),d(``),(async()=>{try{let n=await y.getGezel(e);if(t)return;let r={...n,about:L.hydrate(ve(n.about))};F.current=r,s(r)}catch(e){t||l(e.message)}})(),()=>{t=!0}},[e,L.hydrate]),(0,W.useEffect)(()=>{M&&w!==N&&T(N)},[N,w,M]);let R=(0,W.useCallback)(e=>{F.current=e,s(e),Z(e)},[]),ee=(0,W.useCallback)(e=>{d(``),L.update(e)},[L.update]),z=(0,W.useCallback)(()=>{o&&(k(o.name),j(!0))},[o]),H=(0,W.useCallback)(async()=>{if(!o||!O.trim()||O.trim()===o.name){j(!1);return}try{await L.flush();let e=await y.renameGezel(o.id,{name:O.trim()});F.current=e,L.adopt(e.about),s(e),Z(e)}catch(e){d(`rename failed: ${e.message}`)}j(!1)},[o,O,L.flush,L.adopt]),re=(0,W.useCallback)(e=>{e.key===`Enter`&&H(),e.key===`Escape`&&j(!1)},[H]);return c?(0,G.jsx)(`div`,{className:`placeholder`,children:(0,G.jsxs)(`p`,{children:[`Couldn't open this gezel: `,c]})}):o?(0,G.jsxs)(`section`,{className:`gezel-detail${N===`chat`?` gezel-detail-chat`:``}`,"data-testid":`gezel-detail`,children:[(0,G.jsxs)(`header`,{className:`detail-header`,children:[(0,G.jsxs)(`span`,{className:`level-badge-anchor`,children:[(0,G.jsx)(V,{svg:o.icon??null,poppetje:o.poppetje,iconOverride:o.iconOverride,name:o.name,size:80,pulsing:f&&!o.icon&&!o.poppetje,onClick:()=>D(!0),title:o.iconOverride&&o.icon?`Click to iterate on this icon`:`Click to manage appearance`}),o.growth&&(0,G.jsx)(q,{level:o.growth.level,pending:!!o.growth.pending,overlay:!0})]}),(0,G.jsxs)(`div`,{className:`detail-header-text`,children:[A?(0,G.jsx)(`input`,{className:`rename-input`,value:O,onChange:e=>k(e.target.value),onBlur:()=>void H(),onKeyDown:re}):(0,G.jsx)(`h3`,{className:`gezel-name-editable`,onClick:z,onKeyDown:e=>{e.key===`Enter`&&z()},title:`Click to rename`,children:o.name}),o.role&&(0,G.jsx)(`span`,{className:`gezel-role`,children:o.role}),o.fixedFunction?(0,G.jsxs)(`div`,{className:`provider-override`,children:[(0,G.jsxs)(`span`,{className:`gezel-role muted small ff-header-tag`,title:`Fixed-function gezel`,children:[`Fixed-function · forwards to `,(0,G.jsx)(`code`,{children:o.fixedFunction.tool})]}),P&&(0,G.jsx)(`span`,{className:`gezel-role muted small ff-header-tag`,title:`Generation model used by this gezel`,children:P})]}):(0,G.jsx)(mt,{gezel:o,onUpdated:R})]}),(0,G.jsx)(`output`,{className:`status`,"aria-live":`polite`,children:L.phase===`error`?(0,G.jsxs)(G.Fragment,{children:[`save failed: `,L.error?.message??`unknown error`,` `,(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:()=>void L.retry().catch(()=>{}),children:`Retry`})]}):u||(L.phase===`dirty`?`unsaved changes`:L.phase===`saving`?`saving…`:L.phase===`saved`?`saved`:null)}),(0,G.jsx)(ne,{gezel:o,onDeleted:t,boringMode:a})]}),(0,G.jsx)(pt,{open:E,gezel:o,isGenerating:f,onClose:()=>D(!1),onUpdated:R,setGenerating:p}),(0,G.jsx)(`div`,{className:`entity-tabs-row`,children:(0,G.jsx)(S,{value:N,onValueChange:e=>T(e),children:(0,G.jsxs)(x,{children:[(0,G.jsx)(b,{value:`chat`,children:`Chat`}),(0,G.jsx)(b,{value:`about`,children:`About`}),(0,G.jsx)(b,{value:`appearance`,children:`Appearance`}),(0,G.jsxs)(b,{value:`growth`,children:[`Growth`,o.growth?.pending&&(0,G.jsx)(`span`,{className:`growth-tab-dot`,title:`A level-up is waiting for your choice`,"aria-label":`Level-up pending`})]}),!M&&(0,G.jsx)(b,{value:`toolsets`,children:`Toolsets`}),!M&&(0,G.jsx)(b,{value:`memories`,children:`Memories`})]})})}),N===`appearance`&&(0,G.jsx)(rt,{gezel:o,onUpdated:R}),N===`growth`&&(0,G.jsx)(We,{gezel:o,onUpdated:()=>{(async()=>{try{let e=await y.getGezel(o.id);F.current=e,s(e)}catch{}})()}}),!M&&N===`toolsets`&&(0,G.jsx)(ge,{scope:{kind:`gezel`,gezelId:o.id},subject:o.name}),N===`about`&&o.fixedFunction&&(0,G.jsx)(Ce,{gezel:o,onUpdated:R}),N===`about`&&!o.fixedFunction&&(0,G.jsxs)(`div`,{className:`editor-wrap`,children:[m&&(0,G.jsxs)(`div`,{className:`about-generating-banner`,children:[`Drafting `,(0,G.jsx)(`code`,{children:`about.md`}),` from the role…`]}),(0,G.jsx)(te,{initialMarkdown:o.about,onChange:ee,height:`calc(100vh - 220px)`,colorScheme:i,showPlayTab:!1,fullWidth:!0,readOnly:m||g,toolbarSlotAfterActions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ye,{context:`about`}),(0,G.jsx)(Pe,{...o.role?{gezelRole:o.role}:{},...o.templateId?{gezelTemplateId:o.templateId}:{},onApply:async(e,t)=>{_(!0);try{if(!await L.saveNow(t))return;C(e=>e+1),d(`applied template`)}catch(e){d(`template apply failed: ${e.message}`)}finally{_(!1)}}}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,disabled:m||!o.role,title:o.role?`Re-draft about.md from the role`:`Set a role first to enable about generation`,onClick:async()=>{if(o.role){h(!0);try{await L.flush();let e=await y.generateGezelAbout(o.id,{role:o.role});L.adopt(e.about),F.current=e,C(e=>e+1),R(e)}catch(e){d(`about generation failed: ${e.message}`)}finally{h(!1)}}},children:m?`Drafting…`:`Draft from role`})]})},`${o.id}:${v}`)]}),N===`chat`&&(0,G.jsx)(ke,{gezel:o,engineLabel:P,workingProjectIds:n,activeTurnsReady:r}),!M&&N===`memories`&&(0,G.jsx)(_e,{gezelId:o.id,gezelName:o.name})]}):(0,G.jsx)(`p`,{className:`placeholder`,children:`Loading gezel…`})}function rt({gezel:e,onUpdated:t}){let[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null),f=e.poppetje,p=async()=>{d(null),r(!0);try{let n=await y.rerollGezelPoppetje(e.id,{});t({...await y.getGezel(e.id),poppetje:n.poppetje})}catch(e){d(e.message)}finally{r(!1)}},m=async n=>{d(null),a(!0);try{t(await y.updateGezelSettings(e.id,{iconOverride:n?!0:null}))}catch(e){d(e.message)}finally{a(!1)}},h=async n=>{d(null),s(!0);try{t(await y.updateGezelSettings(e.id,{font:n||null}))}catch(e){d(e.message)}finally{s(!1)}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`section`,{className:`gezel-appearance`,"aria-label":`Appearance`,children:[(0,G.jsx)(`div`,{className:`gezel-appearance-hero`,"aria-label":`${e.name} portrait`,children:f?(0,G.jsx)(I,{poppetje:f,variant:`full`,size:160,grainStyle:`wavy`}):(0,G.jsx)(`span`,{className:`muted small`,children:`Generating…`})}),(0,G.jsxs)(`div`,{className:`gezel-appearance-actions`,children:[(0,G.jsxs)(`strong`,{children:[e.name,`'s appearance`]}),(0,G.jsxs)(`div`,{className:`gezel-appearance-buttons`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:p,disabled:n||!f,children:n?`Rerolling…`:`Reroll appearance`}),(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:()=>l(!0),disabled:!f,title:`Choose hair, bangs, part, and worn items`,children:`Accessories & hair…`})]}),(0,G.jsx)(`span`,{className:`muted small`,children:`Reroll redraws everything (body, face, hair). Accessories & hair lets you style this figure.`}),e.icon&&(0,G.jsxs)(`label`,{className:`gezel-appearance-toggle`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:!!e.iconOverride,disabled:i,onChange:e=>void m(e.target.checked)}),`Show abstract icon instead of the poppetje`]}),u&&(0,G.jsx)(`p`,{className:`error small`,children:u})]}),(0,G.jsx)(ft,{open:c,gezel:e,onClose:()=>l(!1),onUpdated:t})]}),(0,G.jsxs)(`section`,{className:`gezel-font-section`,"aria-label":`Chat font`,children:[(0,G.jsx)(`strong`,{children:`Chat font`}),(0,G.jsx)(vt,{value:e.font,onChange:e=>void h(e),disabled:o}),(0,G.jsxs)(`span`,{className:`muted small`,children:[`The typeface used for `,e.name,`'s chat bubbles. Inherits the app default unless overridden.`]})]})]})}var it={halo:`Curly`,short:`Short`,bob:`Bob`,medium:`Medium`,long:`Long`,"extra-long":`Extra long`,bun:`Bun`,braids:`Braids`,shaved:`Shaved`,bald:`Bald`},at={none:`None`,straight:`Straight`,"side-swept":`Side-swept`,curtain:`Curtain`,short:`Short`},ot={none:`None`,center:`Center`,left:`Left`,right:`Right`};function Q({label:e,slot:t,poppetje:n,options:r,labels:i,disabled:a,onChange:o}){return(0,G.jsxs)(`div`,{className:`accessory-section`,children:[(0,G.jsx)(`h4`,{className:`accessory-section-title`,children:e}),(0,G.jsx)(`div`,{className:`accessory-tiles`,role:`radiogroup`,"aria-label":e,children:r.map(e=>{let r=e??`none`,s=(n[t]??`none`)===r,c={...n,hat:null,accessory:null,[t]:e};return(0,G.jsxs)(`label`,{className:`accessory-tile hair-choice${s?` selected`:``}`,"data-disabled":a,children:[(0,G.jsx)(`input`,{type:`radio`,name:`${n.key}-${t}`,value:r,checked:s,disabled:a,onChange:()=>o(e)}),(0,G.jsx)(`span`,{className:`accessory-tile-art`,"aria-hidden":`true`,children:(0,G.jsx)(I,{poppetje:c,variant:`icon`,size:52,grainStyle:`none`})}),(0,G.jsx)(`span`,{className:`accessory-tile-label`,children:i[r]})]},r)})})]})}var st={cap:`Cap`,beanie:`Beanie`,kerchief:`Kerchief`,straw:`Straw hat`,newsboy:`Newsboy cap`,hood:`Hoodie`},ct={scarf:`Scarf`,apron:`Apron`,collar:`Collar`,turtleneck:`Turtleneck`},lt={glasses:`Glasses`,sunglasses:`Sunglasses`,cateye:`Cat-eye glasses`,readers:`Reading glasses`,monocle:`Monocle`,eyepatch:`Eye patch`,earrings:`Earrings`,"earring-left":`Left earring`,"earring-right":`Right earring`,flower:`Flower`,hairclip:`Hair clip`,headband:`Headband`,bowtie:`Bow tie`,necklace:`Necklace`,brooch:`Brooch`,facemask:`Face mask`,goggles:`Goggles`,"safety-glasses":`Safety glasses`,"pince-nez":`Pince-nez`,headphones:`Headphones`,"hearing-aid":`Hearing aid`,"nose-ring":`Nose ring`,"hoop-earrings":`Hoop earrings`,"drop-earrings":`Drop earrings`,"pearl-earrings":`Pearl earrings`,bandage:`Bandage`,feather:`Feather`,pencil:`Pencil`,ribbon:`Ribbon`,necktie:`Necktie`,cravat:`Cravat`,"bolo-tie":`Bolo tie`,lanyard:`Lanyard`,medal:`Medal`,"pocket-square":`Pocket square`,"tool-pendant":`Tool pendant`};function ut({slot:e,option:t,label:n,selected:r,disabled:i,lockText:a,onSelect:o}){let s=a?.match(/\d+/)?.[0];return(0,G.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,className:`accessory-tile${r?` selected`:``}${a?` locked`:``}`,disabled:i,onClick:o,title:a?`${n} — ${a}`:n,children:[(0,G.jsx)(`span`,{className:`accessory-tile-art`,children:e&&t?(0,G.jsx)(F,{slot:e,option:t,size:52}):(0,G.jsxs)(`svg`,{width:28,height:28,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[(0,G.jsx)(`circle`,{cx:12,cy:12,r:9,fill:`none`,stroke:`currentColor`,strokeWidth:1.6}),(0,G.jsx)(`line`,{x1:6,y1:18,x2:18,y2:6,stroke:`currentColor`,strokeWidth:1.6})]})}),(0,G.jsx)(`span`,{className:`accessory-tile-label`,children:n}),s&&(0,G.jsxs)(`span`,{className:`accessory-tile-lock`,"aria-hidden":`true`,children:[`Lv `,s]})]})}function $({slot:e,label:t,value:n,options:r,labels:i,locked:a,onChange:o,disabled:s}){return(0,G.jsxs)(`div`,{className:`accessory-section`,children:[(0,G.jsx)(`h4`,{className:`accessory-section-title`,children:t}),(0,G.jsxs)(`div`,{className:`accessory-tiles`,role:`radiogroup`,"aria-label":t,children:[(0,G.jsx)(ut,{label:`None`,selected:n===null,disabled:s,onSelect:()=>o(null)}),r.map(t=>{let r=a?.[t];return(0,G.jsx)(ut,{slot:e,option:t,label:i[t],selected:n===t,disabled:s||!!r,lockText:r,onSelect:()=>o(t)},t)})]})]})}function dt(e,t,n){let r={};for(let i of l)i.slot===e&&(i.level<=t||n!==i.option&&(r[i.option]=`unlocks at level ${i.level}`));return r}function ft({open:e,gezel:t,onClose:n,onUpdated:r}){let[i,a]=(0,W.useState)(!1),[l,u]=(0,W.useState)(null),d=t.poppetje,f=t.growth?.level??1,p=async e=>{if(d){u(null),a(!0);try{let n={...d,...e},i=await y.setGezelPoppetje(t.id,{poppetje:n});r({...t,poppetje:i.poppetje})}catch(e){u(e.message)}finally{a(!1)}}};return(0,G.jsx)(T,{open:e,onOpenChange:e=>{e||n()},children:(0,G.jsxs)(N,{children:[(0,G.jsx)(E,{}),(0,G.jsxs)(D,{className:`accessories-dialog`,children:[(0,G.jsx)(O,{asChild:!0,children:(0,G.jsxs)(`h3`,{children:[t.name,`'s accessories & hair`]})}),(0,G.jsx)(C,{className:`muted small`,children:`Choose a hairstyle and worn items. Changes save automatically.`}),(0,G.jsxs)(`div`,{className:`accessories-body`,children:[(0,G.jsx)(`div`,{className:`accessories-preview`,"aria-label":`${t.name} preview`,children:d?(0,G.jsx)(I,{poppetje:d,variant:`full`,size:150,grainStyle:`wavy`}):(0,G.jsx)(`span`,{className:`muted small`,children:`Generating…`})}),(0,G.jsxs)(`div`,{className:`accessories-controls`,children:[d&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{label:`Hair style`,slot:`hairShape`,poppetje:d,options:_,labels:it,disabled:i,onChange:e=>void p({hairShape:e})}),(0,G.jsx)(Q,{label:`Bangs`,slot:`bangs`,poppetje:d,options:[null,...m],labels:at,disabled:i||d.hairShape===`bald`||d.hairShape===`shaved`,onChange:e=>void p({bangs:e})}),(0,G.jsx)(Q,{label:`Hair part`,slot:`hairPart`,poppetje:d,options:o,labels:ot,disabled:i||d.hairShape===`bald`||d.hairShape===`shaved`,onChange:e=>void p({hairPart:e})}),(0,G.jsx)(`p`,{className:`muted small`,children:`Left and right match the preview. Hats cover the hairstyle.`})]}),(0,G.jsx)($,{slot:`hat`,label:`Hat`,value:d?.hat??null,options:s,labels:st,locked:dt(`hat`,f,d?.hat??null),onChange:e=>void p({hat:e}),disabled:i||!d}),(0,G.jsx)($,{slot:`dress`,label:`Garment`,value:d?.dress??null,options:c,labels:ct,locked:dt(`dress`,f,d?.dress??null),onChange:e=>void p({dress:e}),disabled:i||!d}),(0,G.jsx)($,{slot:`accessory`,label:`Accessory`,value:d?.accessory??null,options:g,labels:lt,locked:dt(`accessory`,f,d?.accessory??null),onChange:e=>void p({accessory:e}),disabled:i||!d})]})]}),l&&(0,G.jsx)(`p`,{className:`gz-dialog-error`,children:l}),(0,G.jsx)(w,{children:(0,G.jsx)(`button`,{type:`button`,className:`primary`,onClick:n,children:`Done`})})]})]})})}function pt({open:e,gezel:t,isGenerating:n,onClose:r,onUpdated:i,setGenerating:a}){let[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)([]),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),m=(0,W.useCallback)(async()=>{try{let e=await y.listGezelIconHistory(t.id);l(e.history)}catch(e){p(e.message)}},[t.id]);(0,W.useEffect)(()=>{u&&m()},[u,m]);let h=async()=>{p(null),a(!0);try{i(await y.generateGezelIcon(t.id,o.trim()?{instruction:o.trim()}:{})),s(``),u&&await m()}catch(e){p(e.message)}finally{a(!1)}},g=async e=>{p(null);try{i(await y.revertGezelIcon(t.id,{timestamp:e})),await m()}catch(e){p(e.message)}};return(0,G.jsx)(T,{open:e,onOpenChange:e=>{e||r()},children:(0,G.jsxs)(N,{children:[(0,G.jsx)(E,{}),(0,G.jsxs)(D,{className:`iterate-dialog`,children:[(0,G.jsx)(O,{asChild:!0,children:(0,G.jsxs)(`h3`,{children:[`Iterate on `,t.name,`'s icon`]})}),(0,G.jsx)(`div`,{className:`iterate-preview`,children:(0,G.jsx)(V,{svg:t.icon??null,poppetje:t.poppetje,iconOverride:t.iconOverride,name:t.name,size:120,pulsing:n})}),(0,G.jsxs)(`label`,{children:[`What should change?`,(0,G.jsx)(`textarea`,{value:o,onChange:e=>s(e.target.value),placeholder:`e.g. make the colors warmer, try a cat shape, more geometric`,rows:3})]}),f&&(0,G.jsx)(`p`,{className:`error`,children:f}),(0,G.jsxs)(w,{children:[(0,G.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(e=>!e),children:u?`Hide history`:`Show history`}),(0,G.jsx)(`span`,{style:{flex:1}}),(0,G.jsx)(`button`,{type:`button`,onClick:r,children:`Close`}),(0,G.jsx)(`button`,{type:`button`,className:`primary`,onClick:h,disabled:n,children:n?`Generating…`:`Regenerate`})]}),u&&(0,G.jsxs)(`div`,{className:`icon-history-row`,children:[c.length===0&&(0,G.jsx)(`p`,{className:`muted`,children:`No previous variants yet.`}),c.map(e=>(0,G.jsx)(`button`,{type:`button`,className:`icon-history-item`,onClick:()=>void g(e.timestamp),title:`Revert to ${e.timestamp}`,children:(0,G.jsx)(V,{svg:e.svg,iconOverride:!0,name:t.name,size:56})},e.timestamp))]})]})]})})}function mt({gezel:e,onUpdated:t}){let[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(`copilot`);(0,W.useEffect)(()=>{y.getConfig().then(e=>a(e.provider)).catch(()=>{})},[]);let o=(0,W.useCallback)(async(n,i)=>{let a=(e.provider??null)!==(n??null);r(!0);try{t(await y.updateGezelSettings(e.id,{provider:n??null,model:i??null,...a||!i?{reasoningEffort:null}:{}}))}finally{r(!1)}},[e.id,e.provider,t]),s=(0,W.useCallback)(async n=>{r(!0);try{t(await y.updateGezelSettings(e.id,{reasoningEffort:n??null}))}finally{r(!1)}},[e.id,t]),c=(0,W.useCallback)(async n=>{r(!0);try{t(await y.updateGezelSettings(e.id,{sandboxCopilot:n==="default"?null:n===`on`}))}finally{r(!1)}},[e.id,t]),l=(0,W.useCallback)(async n=>{r(!0);try{t(await y.updateGezelSettings(e.id,{codexPermissionMode:n===`inherit`?null:n}))}finally{r(!1)}},[e.id,t]),u=(0,W.useCallback)(async n=>{r(!0);try{t(await y.updateGezelSettings(e.id,{retrieval:n===`inherit`?null:{...e.retrieval,mode:n}}))}finally{r(!1)}},[e.id,e.retrieval,t]),d=e.provider??i,p=e.sandboxCopilot===void 0?`default`:e.sandboxCopilot?`on`:`off`,m=e.codexPermissionMode?f(e.codexPermissionMode):`inherit`,h=e.retrieval?.mode??`inherit`;return(0,G.jsxs)(`div`,{className:`provider-override`,children:[(0,G.jsx)(`span`,{className:`muted small`,children:`Model:`}),(0,G.jsx)($e,{provider:e.provider??null,model:e.model,onChange:(e,t)=>void o(e,t),globalProvider:i,disabled:n}),(0,G.jsx)(Se,{provider:d,model:e.model,value:e.reasoningEffort,onChange:e=>void s(e)}),(0,G.jsx)(`span`,{className:`muted small`,style:{marginLeft:`0.75rem`},title:`How much relevant indexed project knowledge is added to each substantive turn. Search remains available in Off mode.`,children:`Context:`}),[`inherit`,`off`,`lean`,`balanced`,`deep`].map(e=>(0,G.jsx)(`button`,{type:`button`,className:`provider-chip${h===e?` provider-chip-active`:``}`,onClick:()=>void u(e),disabled:n,children:e===`inherit`?`Inherit`:e===`off`?`Off`:e[0].toUpperCase()+e.slice(1)},e)),d===`copilot`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`muted small`,style:{marginLeft:`0.75rem`},title:`Deny the Copilot CLI's built-in tools (bash, web_fetch, file edit, grep) and force this gezel through our MCP tools.`,children:`Sandbox:`}),[`default`,`on`,`off`].map(e=>(0,G.jsx)(`button`,{type:`button`,className:`provider-chip${p===e?` provider-chip-active`:``}`,onClick:()=>void c(e),disabled:n,children:e==="default"?`Inherit`:e===`on`?`On`:`Off`},e))]}),d===`codex-cli`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`muted small`,style:{marginLeft:`0.75rem`},title:`Override this gezel's Codex execution posture. A project-level choice still takes precedence.`,children:`Access:`}),[`inherit`,`plan`,`edit`,`reviewed`,`full`].map(e=>(0,G.jsx)(`button`,{type:`button`,className:`provider-chip${m===e?` provider-chip-active`:``}`,onClick:()=>void l(e),disabled:n,children:e===`inherit`?`Inherit`:e===`plan`?`Plan`:e===`edit`?`Edit`:e===`reviewed`?`Reviewed`:`Full`},e))]}),e.model&&(0,G.jsx)(ht,{gezel:e,effectiveProvider:d,onUpdated:t})]})}function ht({gezel:e,effectiveProvider:t,onUpdated:n}){let[r,i]=(0,W.useState)(void 0),a=(0,W.useCallback)(async()=>{if(!(r!==void 0||!e.model))try{let[t,n]=await Promise.all([y.getCatalogItem(`chat-model`,e.model).catch(()=>null),y.getConfig().catch(()=>null)]),r=t&&t.manifest.kind===`chat-model`?t.manifest.tuning:void 0,a=n?.modelTuning?.[e.model],o=gt(r,a);o&&i(o)}catch{}},[r,e.model]);return(0,G.jsxs)(`details`,{className:`gezel-tuning-disclosure`,style:{flexBasis:`100%`,marginTop:`0.5rem`},onToggle:e=>{e.target.open&&a()},children:[(0,G.jsx)(`summary`,{className:`muted small`,style:{cursor:`pointer`},children:`Advanced tuning`}),(0,G.jsx)(`div`,{style:{marginTop:`0.5rem`},children:(0,G.jsx)(Fe,{gezel:e,...r?{inherited:r}:{},effectiveProvider:t,onUpdated:n})})]})}function gt(e,t){if(!(!e&&!t))return e?t?_t(e,t):e:t}function _t(e,t){let n={...e};for(let[e,r]of Object.entries(t)){if(r===void 0)continue;let t=n[e];t&&typeof t==`object`&&!Array.isArray(t)&&r&&typeof r==`object`&&!Array.isArray(r)?n[e]=_t(t,r):n[e]=r}return n}function vt({value:e,onChange:t,disabled:n}){let r=`__default`,i=e&&e.length>0?e:r,a=i===r?`Inherit default`:p.find(e=>e.id===i)?.label??`Inherit default`,o=p.find(e=>e.id===i)?.family;return(0,G.jsxs)(k,{value:i,onValueChange:e=>t(e===r?``:e),disabled:n,children:[(0,G.jsx)(M,{className:`gezel-font-picker`,title:`Font used for this gezel's chat bubbles`,style:o?{fontFamily:o}:void 0,"aria-label":`Chat bubble font`,children:(0,G.jsx)(j,{children:a})}),(0,G.jsxs)(P,{children:[(0,G.jsx)(A,{value:r,children:`Inherit default`}),p.map(e=>(0,G.jsx)(A,{value:e.id,style:{fontFamily:e.family},children:e.label},e.id))]})]})}export{nt as GezelDetail,q as t};
|
|
@@ -1 +0,0 @@
|
|
|
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,Yt as i}from"./dist-DOqbRmFj.js";import{t as a}from"./api-C0I7spBl.js";import{i as o,n as s,r as c,t as l}from"./Tabs-jE0Z5Tzd.js";import{G as u,H as d,J as f,K as p,W as m,Y as h,q as g}from"./primitives-CWrGZpPI.js";import{It as _,a as v,f as y}from"./index-DDu8nyO6.js";import{t as b}from"./CatalogBrowser-7_jHy5Q3.js";import{GezelDetail as x,t as S}from"./GezelDetail-D_KIPDhQ.js";var C=e(t(),1),w=n();function T({activeProjectsByGezel:e,activeTurnsReady:t}){let[n,r]=(0,C.useState)([]),[i,o]=(0,C.useState)(void 0),[s,c]=(0,C.useState)(!1),[l,u]=(0,C.useState)(void 0),[d,f]=(0,C.useState)(!1),[p,m]=(0,C.useState)(null),[h,g]=(0,C.useState)(new Set),b=(0,C.useCallback)(async()=>{try{let{gezels:e}=await a.listGezels();r(e)}catch(e){m(e.message)}},[]),T=(0,C.useCallback)(async()=>{try{let e=await a.getConfig();o(e.meesterGezelId),c(e.roleBasedNameOnlyMode??!1)}catch{}},[]);(0,C.useEffect)(()=>{b(),T()},[b,T]),(0,C.useEffect)(()=>{let e=e=>{let t=e.detail;typeof t?.roleBasedNameOnlyMode==`boolean`&&c(t.roleBasedNameOnlyMode)};return window.addEventListener(`gezel:config-updated`,e),()=>window.removeEventListener(`gezel:config-updated`,e)},[]),(0,C.useEffect)(()=>{if(n.length===0){u(void 0);return}u(e=>e&&n.some(t=>t.id===e)?e:n[0].id)},[n]),(0,C.useEffect)(()=>{let e=()=>void b(),t=e=>{let t=e.detail?.gezelId;t&&(r(e=>e.filter(e=>e.id!==t)),u(e=>e===t?void 0:e),g(e=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),n})),b(),T()};return window.addEventListener(`gezel:gezel-updated`,e),window.addEventListener(`gezel:growth-updated`,e),window.addEventListener(`gezel:gezel-deleted`,t),()=>{window.removeEventListener(`gezel:gezel-updated`,e),window.removeEventListener(`gezel:growth-updated`,e),window.removeEventListener(`gezel:gezel-deleted`,t)}},[b,T]),(0,C.useEffect)(()=>{v(`gezel`)&&f(!0);let e=()=>{v(`gezel`),f(!0)};return window.addEventListener(`gezel:new-gezel`,e),()=>window.removeEventListener(`gezel:new-gezel`,e)},[]);let D=(0,C.useCallback)((e,t)=>{g(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),O=(0,C.useCallback)(e=>{u(e)},[]),k=(0,C.useCallback)(t=>{O(t),(e?.get(t)?.size??0)>0&&window.dispatchEvent(new CustomEvent(`gezel:prefer-working-project`,{detail:{gezelId:t}}))},[e,O]),A=(0,C.useCallback)((e,t)=>{D(e.id,!0),(async()=>{try{let n=await a.generateGezelIcon(e.id,t?{instruction:t}:{});window.dispatchEvent(new CustomEvent(`gezel:gezel-updated`,{detail:n}))}catch{}finally{D(e.id,!1)}})(),e.role&&(async()=>{try{let t=await a.generateGezelAbout(e.id,{role:e.role});window.dispatchEvent(new CustomEvent(`gezel:gezel-updated`,{detail:t}))}catch{}})()},[D]);return(0,w.jsxs)(`div`,{className:`two-col gezellen-view`,"data-testid":`gezels-view`,children:[(0,w.jsx)(E,{open:d,onClose:()=>f(!1),onCreate:(0,C.useCallback)(async(e,t,n,r)=>{let i=await a.createGezel({name:e,gender:n,...t?{role:t}:{}});f(!1),await b(),O(i.id),window.dispatchEvent(new CustomEvent(`gezel:gezel-updated`,{detail:i})),A(i,r)},[b,O,A]),onTemplateCreated:async e=>{f(!1),await b(),O(e.id),window.dispatchEvent(new CustomEvent(`gezel:gezel-updated`,{detail:e}))}}),(0,w.jsxs)(`aside`,{className:`side gezels-side`,children:[(0,w.jsx)(`div`,{className:`area-toolbar`,children:(0,w.jsx)(`button`,{type:`button`,className:`area-toolbar-btn`,onClick:()=>f(!0),children:`+ New Gezel`})}),(0,w.jsx)(`ul`,{className:`gezel-list`,children:n.map(t=>{let n=h.has(t.id),r=t.id===l,a=(e?.get(t.id)?.size??0)>0;return(0,w.jsxs)(`li`,{className:`gezel-row-shell${r?` active`:``}`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`gezel-row${r?` active`:``}`,onClick:()=>k(t.id),children:[(0,w.jsx)(_,{svg:t.icon??null,poppetje:t.poppetje,iconOverride:t.iconOverride,name:t.name,size:36,pulsing:n&&!t.icon&&!t.poppetje}),(0,w.jsxs)(`span`,{className:`gezel-row-text`,children:[(0,w.jsxs)(`span`,{className:`gezel-row-name`,children:[t.name,t.growth&&(0,w.jsx)(S,{level:t.growth.level,pending:!!t.growth.pending}),t.storageScope===`machine-shared`&&(0,w.jsx)(`span`,{className:`machine-shared-badge`,title:`Shared with accounts on this machine; chats and memories stay private`,children:`Shared`}),t.id===i&&(0,w.jsx)(`span`,{className:`meester-badge`,title:`Current Meester — change in Settings`,"aria-label":`Current Meester`,children:`⭐`}),t.fixedFunction&&(0,w.jsx)(`span`,{className:`ff-row-badge`,title:`Fixed-function gezel — forwards messages to ${t.fixedFunction.tool} (no LLM)`,"aria-label":`Fixed-function gezel`,children:`⚡`})]}),(t.id===i||t.role)&&(0,w.jsx)(`span`,{className:`gezel-row-role`,children:t.id===i?t.role&&t.role!==`Meester`?`Meester · ${t.role}`:`Meester`:t.role})]})]}),a&&(0,w.jsxs)(`button`,{type:`button`,className:`project-row-thinking gezel-row-thinking`,onClick:()=>k(t.id),title:`${t.name} is working — open`,"aria-label":`${t.name} is working. Open gezel.`,children:[(0,w.jsx)(`span`,{className:`project-row-thinking-dot`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`project-row-thinking-dot`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`project-row-thinking-dot`,"aria-hidden":`true`})]}),(0,w.jsx)(y,{gezel:t,compact:!0,boringMode:s})]},t.id)})}),p&&(0,w.jsx)(`p`,{className:`error`,children:p})]}),(0,w.jsx)(`section`,{children:l?(0,w.jsx)(x,{gezelId:l,workingProjectIds:e?.get(l),activeTurnsReady:t},l):(0,w.jsx)(`p`,{className:`placeholder`,children:`No gezellen yet — create one to get started.`})})]})}function E({open:e,onClose:t,onCreate:n,onTemplateCreated:r}){let[i,a]=(0,C.useState)(`scratch`),[u,d]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{e&&a(`scratch`)},[e]),(0,w.jsx)(f,{open:e,onOpenChange:e=>{!e&&!u&&t()},children:(0,w.jsxs)(g,{children:[(0,w.jsx)(p,{}),(0,w.jsxs)(m,{className:`new-gezel-dialog`,children:[(0,w.jsx)(h,{asChild:!0,children:(0,w.jsx)(`h3`,{style:{margin:0},children:`New Gezel`})}),(0,w.jsxs)(c,{value:i,onValueChange:e=>a(e),children:[(0,w.jsxs)(s,{children:[(0,w.jsx)(o,{value:`scratch`,children:`From scratch`}),(0,w.jsx)(o,{value:`template`,children:`From template`})]}),(0,w.jsx)(l,{value:`scratch`,children:(0,w.jsx)(D,{onCancel:t,onCreate:n})}),(0,w.jsx)(l,{value:`template`,children:(0,w.jsx)(O,{busy:u,setBusy:d,onCancel:t,onCreated:r})})]})]})]})})}function D({onCancel:e,onCreate:t}){let[{name:n,gender:a},o]=(0,C.useState)(r),[s,c]=(0,C.useState)(``),[l,u]=(0,C.useState)(``);return(0,w.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim(),s.trim(),a,l.trim())},className:`new-gezel-form`,children:[(0,w.jsxs)(`label`,{children:[`Name`,(0,w.jsxs)(`div`,{className:`name-row`,children:[(0,w.jsx)(`input`,{value:n,onChange:e=>o(t=>({...t,name:e.target.value})),placeholder:`e.g. Ada`}),(0,w.jsx)(`button`,{type:`button`,className:`dice-btn`,onClick:()=>o(r()),title:`Pick a random name`,"aria-label":`Pick a random name`,children:`🎲`})]})]}),(0,w.jsxs)(`label`,{className:`new-gezel-gender-field`,children:[`Gender`,(0,w.jsxs)(`select`,{value:a,onChange:e=>o(t=>({...t,gender:e.target.value})),children:[(0,w.jsxs)(`option`,{value:`male`,children:[`male (`,i(`male`),`)`]}),(0,w.jsxs)(`option`,{value:`female`,children:[`female (`,i(`female`),`)`]}),(0,w.jsxs)(`option`,{value:`non-binary`,children:[`non-binary (`,i(`non-binary`),`)`]})]})]}),(0,w.jsxs)(`label`,{children:[`Role`,(0,w.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`e.g. Developer, Marketing`})]}),(0,w.jsxs)(`label`,{children:[`Describe the icon `,(0,w.jsx)(`span`,{className:`muted`,children:`(optional)`}),(0,w.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`e.g. a playful owl wearing glasses, warm colors`,rows:3})]}),(0,w.jsxs)(d,{children:[(0,w.jsx)(`button`,{type:`button`,onClick:e,children:`Cancel`}),(0,w.jsx)(`button`,{type:`submit`,className:`primary`,disabled:!n.trim(),children:`Create`})]})]})}function O({busy:e,setBusy:t,onCancel:n,onCreated:r}){let[i,o]=(0,C.useState)(null),[s,c]=(0,C.useState)(``),[l,f]=(0,C.useState)(null),p=async()=>{if(!(!i||!s.trim())){t(!0),f(null);try{r(await a.createGezelFromTemplate(i.id,{name:s.trim()}))}catch(e){f(e.message)}finally{t(!1)}}};return(0,w.jsxs)(`div`,{className:`new-gezel-template-tab`,children:[(0,w.jsx)(u,{className:`muted small`,style:{margin:`0 0 0.5rem 0`},children:`Pick a role to start from. The template's about.md becomes the new gezel's prompt — you can edit it after.`}),l&&(0,w.jsx)(`p`,{className:`error`,children:l}),(0,w.jsx)(b,{kind:`gezel-template`,emptyMessage:`No gezel templates available.`,action:t=>{if(t.manifest.kind!==`gezel-template`)return null;let n=t.manifest,r=i?.id===n.id,a=Array.isArray(n.nameSuggestions)?n.nameSuggestions:[],s=k(n.frontmatter);return(0,w.jsxs)(`div`,{className:`template-action-stack`,children:[s&&(0,w.jsx)(`span`,{className:`gz-badge gz-badge-passthrough`,title:`No LLM — passes your message straight to the configured tool`,children:`No LLM — passthrough`}),(0,w.jsx)(`button`,{type:`button`,disabled:e,className:r?`primary`:``,onClick:()=>{if(o({id:n.id,defaultName:n.name,nameSuggestions:a,isFixedFunction:s}),a.length>0){let e=Math.floor(Math.random()*a.length);c(a[e]??n.name)}else c(n.name)},children:r?`✓ Selected`:`Use this template`})]})}}),i&&(0,w.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`new-gezel-template-form`,children:[(0,w.jsxs)(`div`,{style:{display:`flex`,gap:`0.5rem`,alignItems:`center`},children:[(0,w.jsxs)(`span`,{className:`muted small`,style:{flexShrink:0},children:[`Name your `,i.defaultName.toLowerCase(),`:`]}),(0,w.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),disabled:e,style:{flex:1}})]}),i.nameSuggestions.length>0&&(0,w.jsxs)(`div`,{className:`name-suggestions`,children:[(0,w.jsx)(`span`,{className:`muted small`,children:`Suggestions:`}),i.nameSuggestions.map(t=>(0,w.jsx)(`button`,{type:`button`,className:t===s?`name-chip name-chip-active`:`name-chip`,onClick:()=>c(t),disabled:e,children:t},t))]}),(0,w.jsxs)(d,{children:[(0,w.jsx)(`button`,{type:`button`,onClick:n,disabled:e,children:`Cancel`}),(0,w.jsx)(`button`,{type:`submit`,className:`primary`,disabled:e||!s.trim(),children:e?`Creating…`:`Create`})]})]}),!i&&(0,w.jsx)(d,{children:(0,w.jsx)(`button`,{type:`button`,onClick:n,children:`Cancel`})})]})}function k(e){return!!(e&&typeof e==`object`&&`fixedFunction`in e&&e.fixedFunction)}export{T as GezellenView};
|
|
@@ -1 +0,0 @@
|
|
|
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{ft as i}from"./doc-C2Ph2FWI.js";import{n as a}from"./chunk-GAZKTT4R-w1SNypWQ.js";import{n as o}from"./chunk-UBFT2CDQ-FexGDigd.js";import"./markdown-ryKA_OmY.js";import"./schemas-BvLZUsGm.js";import{Y as s,z as c}from"./chunk-6ECMNUIP-BvCy0HUI.js";import{n as l}from"./chunk-KGWT454C-v5-l6U5m.js";import{J as u,M as d,N as f,ht as p,p as m}from"./index-DDu8nyO6.js";import{n as h,t as g}from"./HandboekMediaProvider-ByJ4NAzz.js";var _=e(t(),1),v=n(),y=`gezel:handboek:article`;function b(){let[e,t]=(0,_.useState)(null),[n,b]=(0,_.useState)(()=>{try{return window.localStorage.getItem(y)}catch{return null}}),[C,ee]=(0,_.useState)(null),[w,T]=(0,_.useState)(null),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(`doc`),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(!1),[R,z]=(0,_.useState)(()=>new Set),[B,V]=(0,_.useState)(()=>new Set),[H,U]=(0,_.useState)(``),W=(0,_.useMemo)(()=>{let t=H.trim().toLowerCase();return!t||!e?[]:e.areas.flatMap(e=>e.entries).filter(e=>e.title.toLowerCase().includes(t)||(e.summary??``).toLowerCase().includes(t))},[e,H]),G=p()===`light`?d:void 0;(0,_.useEffect)(()=>{let e=!0;return r.getAudioEngineStatus().then(t=>e&&j(t.tts.status===`ok`)).catch(()=>e&&j(!1)),()=>{e=!1}},[]),(0,_.useEffect)(()=>{let e=!0,n=u();return n&&b(n.articleId),r.getHandboekToc().then(n=>{e&&(t(n),b(e=>{let t=new Set(n.areas.flatMap(e=>e.entries.map(e=>e.id)));return e&&t.has(e)?e:n.areas[0]?.entries[0]?.id??null}))}).catch(t=>e&&T(String(t))),()=>{e=!1}},[]),(0,_.useEffect)(()=>{let e=e=>{let t=e.detail;t?.articleId&&b(t.articleId)};return window.addEventListener(`gezel:open-handboek-article`,e),()=>window.removeEventListener(`gezel:open-handboek-article`,e)},[]),(0,_.useEffect)(()=>{if(!n)return;try{window.localStorage.setItem(y,n)}catch{}let e=!0;return D(!0),T(null),r.getHandboekArticle(n).then(t=>{e&&(ee(t),k(`doc`),N(!1),F(e=>{for(let t of e?.urls??[])URL.revokeObjectURL(t);return null}))}).catch(t=>e&&T(String(t))).finally(()=>e&&D(!1)),()=>{e=!1}},[n]),(0,_.useEffect)(()=>{if(!e||!n)return;let t=e.areas.find(e=>e.entries.some(e=>e.id===n)),r=t?.entries.find(e=>e.id===n);if(!(!t||!r)&&(z(e=>{if(!e.has(t.area))return e;let n=new Set(e);return n.delete(t.area),n}),r.subcategory)){let e=S(t.area,r.subcategory.id);V(t=>t.has(e)?t:new Set(t).add(e))}},[e,n]);let K=(0,_.useMemo)(()=>C?g(C.figures):null,[C]),q=(0,_.useRef)(K);(0,_.useEffect)(()=>(q.current=K,()=>q.current?.dispose?.()),[K]);let J=(0,_.useMemo)(()=>{if(!C)return null;try{return i(o(h(C.markdown)),{articleId:C.id,defaultDuration:C.defaultDuration??6})}catch{return null}},[C]),Y=(0,_.useMemo)(()=>{if(!J||J.audio.segments.length>0)return J;let e=a(J);return e<=0?J:{...J,audio:{segments:[{src:``,name:`synthetic`,duration:e,startTime:0}]}}},[J]),X=(0,_.useCallback)(()=>{if(M){N(!1);return}if(P&&P.articleId===C?.id){N(!0);return}!C||I||(L(!0),(async()=>{let e=await r.getHandboekNarration(C.id),t=await Promise.all(e.segments.map(e=>r.fetchHandboekNarrationAudio(e.hash)));return{articleId:C.id,urls:t.map(e=>URL.createObjectURL(e)),durationsMs:e.segments.map(e=>e.durationMs)}})().then(e=>{F(e),N(!0)}).catch(e=>T(`Narration unavailable: ${String(e)}`)).finally(()=>L(!1)))},[M,P,C,I]),Z=(0,_.useMemo)(()=>{if(!J||!M||!P||P.articleId!==C?.id||P.urls.length!==J.blocks.length)return null;let e=0,t=P.urls.map((t,n)=>{let r=P.durationsMs[n]/1e3,i={src:t,name:J.blocks[n].id,duration:r,startTime:e};return e+=r,i});return{...J,audio:{segments:t},blocks:J.blocks.map((e,t)=>({...e,audioSegment:t}))}},[J,M,P,C]),Q=(0,_.useMemo)(()=>{let t=new Set,n=new Map;for(let r of e?.areas??[])for(let e of r.entries){t.add(e.id);let r=e.id.split(`/`).pop();r&&!n.has(r)&&n.set(r,e.id)}return{ids:t,byStem:n}},[e]),te=e=>{let t=e.target.closest(`a`);if(!t)return;let n=t.getAttribute(`href`);if(!n||/^[a-z][a-z0-9+.-]*:/i.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return;e.preventDefault(),e.stopPropagation();let r=n.split(/[?#]/)[0].replace(/\.md$/,``).replace(/^(\.\.?\/)+/,``),i=(Q.ids.has(r)?r:void 0)??Q.byStem.get(r.split(`/`).pop()??``);i&&b(i)},ne=e=>{z(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},re=e=>{V(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},$=(e,t=!1)=>(0,v.jsx)(`ul`,{className:t?`handboek-toc-subcategory-entries`:void 0,children:e.map(e=>(0,v.jsx)(`li`,{children:(0,v.jsx)(`button`,{type:`button`,className:e.id===n?`handboek-toc-entry handboek-toc-entry-active`:`handboek-toc-entry`,"aria-current":e.id===n?`page`:void 0,title:e.summary,onClick:()=>b(e.id),children:e.title})},e.id))});return(0,v.jsxs)(`div`,{className:`handboek-view`,"data-testid":`handboek-view`,children:[(0,v.jsxs)(`nav`,{className:`handboek-toc`,"aria-label":`Handboek contents`,children:[(0,v.jsxs)(`div`,{className:`handboek-toc-brand`,children:[(0,v.jsx)(m,{area:`handboek`,size:16}),(0,v.jsx)(`span`,{children:`Handboek`})]}),(0,v.jsx)(`input`,{type:`search`,className:`handboek-toc-filter`,placeholder:`Find an article…`,"aria-label":`Filter Handboek articles`,value:H,onChange:e=>U(e.target.value)}),!e&&!w&&(0,v.jsx)(`div`,{className:`handboek-toc-loading`,children:`Loading contents…`}),H.trim()?(0,v.jsx)(`section`,{className:`handboek-toc-area`,children:W.length>0?$(W):(0,v.jsx)(`div`,{className:`handboek-toc-loading`,children:`No articles match.`})}):null,!H.trim()&&e?.areas.map(e=>{let t=R.has(e.area),n=`handboek-area-${e.area}`,{ungrouped:r,subcategories:i}=x(e);return(0,v.jsxs)(`section`,{className:`handboek-toc-area`,children:[(0,v.jsx)(`h3`,{className:`handboek-toc-area-title`,children:(0,v.jsxs)(`button`,{type:`button`,className:`handboek-toc-disclosure handboek-toc-area-toggle`,"aria-expanded":!t,"aria-controls":n,onClick:()=>ne(e.area),children:[(0,v.jsx)(`span`,{className:`handboek-toc-caret`,"aria-hidden":`true`,children:`›`}),(0,v.jsx)(`span`,{children:e.title})]})}),!t&&(0,v.jsxs)(`div`,{id:n,className:`handboek-toc-area-contents`,children:[r.length>0&&$(r),i.map(t=>{let n=S(e.area,t.id),r=B.has(n),i=`handboek-subcategory-${e.area}-${t.id}`;return(0,v.jsxs)(`section`,{className:`handboek-toc-subcategory`,children:[(0,v.jsx)(`h4`,{className:`handboek-toc-subcategory-title`,children:(0,v.jsxs)(`button`,{type:`button`,className:`handboek-toc-disclosure handboek-toc-subcategory-toggle`,"aria-expanded":r,"aria-controls":i,onClick:()=>re(n),children:[(0,v.jsx)(`span`,{className:`handboek-toc-caret`,"aria-hidden":`true`,children:`›`}),(0,v.jsx)(`span`,{children:t.title})]})}),r&&(0,v.jsx)(`div`,{id:i,children:$(t.entries,!0)})]},t.id)})]})]},e.area)})]}),(0,v.jsxs)(`div`,{className:`handboek-pane`,children:[(0,v.jsxs)(`header`,{className:`handboek-pane-header`,children:[(0,v.jsxs)(`div`,{className:`handboek-pane-titles`,children:[(0,v.jsx)(`h2`,{children:C?.title??`Handboek`}),C?.summary&&(0,v.jsx)(`p`,{className:`handboek-pane-summary`,children:C.summary})]}),(0,v.jsxs)(`div`,{className:`handboek-header-controls`,children:[O===`video`&&A&&(0,v.jsx)(`button`,{type:`button`,className:M?`gz-key gz-key-active handboek-listen-key`:`gz-key handboek-listen-key`,"aria-pressed":M,disabled:I,onClick:X,title:`Narrate this article with the on-device voice`,children:I?`Preparing voice…`:`Listen`}),(0,v.jsxs)(`div`,{className:`gz-tray handboek-mode-tray`,role:`radiogroup`,"aria-label":`View as`,children:[(0,v.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":O===`doc`,className:O===`doc`?`gz-key gz-key-active`:`gz-key`,onClick:()=>k(`doc`),children:`Document`}),(0,v.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":O===`video`,className:O===`video`?`gz-key gz-key-active`:`gz-key`,onClick:()=>k(`video`),children:`Video`})]})]})]}),w&&(0,v.jsx)(`div`,{className:`handboek-error`,children:w}),E&&!C&&(0,v.jsx)(`div`,{className:`handboek-loading`,children:`Loading article…`}),J&&K&&(0,v.jsx)(s.Provider,{value:K,children:O===`doc`?(0,v.jsx)(`div`,{className:`handboek-doc`,"data-testid":`handboek-doc`,onClickCapture:te,children:(0,v.jsx)(c,{doc:J,className:`gezel-article-view`,theme:f,surface:G,imageDisplayMode:`inline`,showCover:!1})}):(0,v.jsx)(`div`,{className:`handboek-player`,"data-testid":`handboek-player`,children:(0,v.jsx)(l,{doc:Z??Y??J,theme:f,surface:G,displayMode:`video`,audioMode:Z?`media`:`synthetic`,captionsEnabled:!0,captionStyle:`social`,autoPlay:!0,showControls:!0,showScrubber:!0},Z?`narrated`:`synthetic`)})})]})]})}function x(e){let t=[],n=new Map;for(let r of e.entries){if(!r.subcategory){t.push(r);continue}let e=n.get(r.subcategory.id);e?e.entries.push(r):n.set(r.subcategory.id,{...r.subcategory,entries:[r]})}return{ungrouped:t,subcategories:[...n.values()].sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title))}}function S(e,t){return`${e}:${t}`}export{b as HandboekView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{Dn as r,On as i}from"./dist-DOqbRmFj.js";import{t as a}from"./api-C0I7spBl.js";import{i as o,t as s}from"./model-inventory-ykSm_IT5.js";import{ft as c}from"./doc-C2Ph2FWI.js";import{n as l}from"./chunk-UBFT2CDQ-FexGDigd.js";import"./markdown-ryKA_OmY.js";import{Y as u,z as ee}from"./chunk-6ECMNUIP-BvCy0HUI.js";import{M as te,N as ne,U as d,gt as re,ht as ie,q as ae}from"./index-DDu8nyO6.js";import{n as oe}from"./composer-prefill-CbG_i1Rx.js";var f=e(t(),1);function p(e){let t=new Map,n=new Map,r=r=>{let i=t.get(r);if(i)return Promise.resolve(i);let o=n.get(r);if(o)return o;let s=a.fetchKnowledgeAsset(e.catalogId,r,e.version?{version:e.version}:{}).then(e=>{let n=URL.createObjectURL(e);return t.set(r,n),n}).finally(()=>n.delete(r));return n.set(r,s),s};return{async addMedia(){throw Error(`knowledge catalogs are read-only`)},async resolveUrl(e){let t=e.replace(/^\.\//,``);if(!t.startsWith(`assets/`))return e;try{return await r(t)}catch{return e}},async listMedia(){return[]},async removeMedia(){},dispose(){for(let e of t.values())URL.revokeObjectURL(e);t.clear(),n.clear()}}}var m=n(),h=`gezel:knowledge:catalog`,g=`gezel:knowledge:document`,_=50;function v(e){let t=new Map(e.map(e=>[e.id,{...e,children:[]}])),n=[];for(let e of t.values()){let r=e.parentId?t.get(e.parentId):void 0;r?r.children.push(e):n.push(e)}return n}function y(){let[e,t]=(0,f.useState)(null),[n,y]=(0,f.useState)(()=>{try{return window.localStorage.getItem(h)}catch{return null}}),[b,x]=(0,f.useState)([]),[S,C]=(0,f.useState)(null),[w,T]=(0,f.useState)(null),[E,se]=(0,f.useState)(0),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(()=>{try{return window.localStorage.getItem(g)}catch{return null}}),[j,M]=(0,f.useState)(null),[ce,N]=(0,f.useState)(!1),[P,F]=(0,f.useState)(null),[I,L]=(0,f.useState)(``),[R,z]=(0,f.useState)(null),[B,V]=(0,f.useState)(!1),[H,U]=(0,f.useState)(!1),W=(0,f.useRef)(null),G=ie()===`light`?te:void 0;(0,f.useEffect)(()=>{let e=!0,n=ae();n&&(y(n.catalogId),n.documentId&&A(n.documentId));let r=()=>{a.listKnowledgeCatalogs().then(n=>{if(!e)return;let r=n.catalogs.filter(e=>e.mounted);t(r),y(e=>(e&&r.some(t=>t.ref.catalogId===e)?e:null)??r[0]?.ref.catalogId??null)}).catch(()=>{e&&t([])})};r();let i=e=>{o(e)===`knowledge`&&r()};window.addEventListener(s,i);let c=e=>{let t=e.detail;t?.catalogId&&(y(t.catalogId),t.documentId&&A(t.documentId))};return window.addEventListener(`gezel:open-knowledge-document`,c),()=>{e=!1,window.removeEventListener(s,i),window.removeEventListener(`gezel:open-knowledge-document`,c)}},[]),(0,f.useEffect)(()=>{try{n&&window.localStorage.setItem(h,n)}catch{}},[n]),(0,f.useEffect)(()=>{if(!n)return;let e=!0;return x([]),C(null),a.knowledgeCatalogTopics(n).then(t=>{e&&x(t.topics)}).catch(()=>{}),()=>{e=!1}},[n]);let K=(0,f.useCallback)(async e=>{if(!n)return;let t=await a.knowledgeCatalogDocuments(n,{...S?{topicId:S}:{},offset:e,limit:_});se(t.total),T(n=>e===0||!n?t.documents:[...n,...t.documents])},[n,S]);(0,f.useEffect)(()=>{T(null),K(0).catch(()=>T([]))},[K]),(0,f.useEffect)(()=>{if(!n||!k){M(null);return}let e=!0;N(!0),F(null),a.readKnowledgeDocument(n,k).then(t=>{e&&M(t)}).catch(t=>{e&&F(t instanceof Error?t.message:String(t))}).finally(()=>{e&&N(!1)});try{window.localStorage.setItem(g,k)}catch{}return()=>{e=!1}},[n,k]),(0,f.useEffect)(()=>{W.current&&window.clearTimeout(W.current);let e=I.trim();if(!e){z(null),V(!1);return}return V(!0),W.current=window.setTimeout(()=>{a.searchKnowledge({query:e,maxResults:20,...n?{catalogs:[n]}:{}}).then(e=>{z(e.results)}).catch(()=>{z([])}).finally(()=>V(!1))},250),()=>{W.current&&window.clearTimeout(W.current)}},[I,n]);let q=(0,f.useMemo)(()=>e?.find(e=>e.ref.catalogId===n)??null,[e,n]),le=(0,f.useMemo)(()=>v(b),[b]),J=(0,f.useMemo)(()=>new Map(b.map(e=>[e.id,e.name])),[b]),Y=(0,f.useMemo)(()=>n?p({catalogId:n,...q?.ref.version?{version:q.ref.version}:{}}):null,[n,q?.ref.version]),X=(0,f.useRef)(Y);(0,f.useEffect)(()=>(X.current=Y,()=>X.current?.dispose?.()),[Y]);let ue=(0,f.useCallback)(t=>{let r=(t.target?.closest?.(`a[href]`))?.getAttribute(`href`);if(!r)return;let a=i(r);if(!a)return;if(t.preventDefault(),t.stopPropagation(),a.catalogId===n){A(a.documentId);return}let o=e?.find(e=>e.ref.catalogId===a.catalogId&&e.ref.publisherId===a.publisherId);o&&(y(o.ref.catalogId),A(a.documentId))},[e,n]),Z=(0,f.useMemo)(()=>{if(!j)return null;try{return c(l(j.markdown),{articleId:j.id})}catch{return null}},[j]),Q=(0,f.useMemo)(()=>{if(!n||!j)return null;let t=e?.find(e=>e.ref.catalogId===n)?.ref.publisherId;return t?r({publisherId:t,catalogId:n,documentId:j.id}):null},[e,n,j]),de=(0,f.useCallback)(()=>{Q&&navigator.clipboard?.writeText(Q).then(()=>{U(!0),window.setTimeout(()=>U(!1),2e3)})},[Q]),fe=(0,f.useCallback)(()=>{!Q||!j||(oe(`default`,`I'm reading "${j.title}" (${Q}). Can you help me with a question about it?\n\n`),d({kind:`project`,id:`default`}))},[Q,j]),pe=(0,f.useCallback)(()=>{re(`knowledge`),d({kind:`area`,area:`settings`})},[]);if(e!==null&&e.length===0)return(0,m.jsx)(`div`,{className:`knowledge-view`,"data-testid":`knowledge-view`,children:(0,m.jsxs)(`div`,{className:`knowledge-empty`,style:{gridColumn:`1 / -1`},children:[(0,m.jsx)(`h2`,{children:`Knowledge`}),(0,m.jsx)(`p`,{className:`muted`,children:`No knowledge catalogs are installed yet. A catalog is a searchable, citable reference library — install one and your gezellen can look things up and cite their sources.`}),(0,m.jsx)(`button`,{type:`button`,onClick:pe,children:`Open knowledge settings`})]})});let $=(e,t)=>(0,m.jsxs)(`li`,{children:[(0,m.jsxs)(`button`,{type:`button`,className:`knowledge-topic-row`,"aria-current":S===e.id?`true`:void 0,onClick:()=>{C(t=>t===e.id?null:e.id),L(``)},children:[(0,m.jsx)(`span`,{children:e.name}),(0,m.jsx)(`span`,{className:`knowledge-topic-count`,children:e.totalDocumentCount})]}),e.children.length>0&&(0,m.jsx)(`ul`,{children:e.children.map(e=>$(e,t+1))})]},e.id);return(0,m.jsxs)(`div`,{className:`knowledge-view`,"data-testid":`knowledge-view`,children:[(0,m.jsxs)(`nav`,{className:`knowledge-rail`,"aria-label":`Knowledge catalogs and topics`,children:[e&&e.length>1&&(0,m.jsx)(`select`,{"aria-label":`Catalog`,value:n??``,onChange:e=>{y(e.target.value),A(null)},children:e.map(e=>(0,m.jsx)(`option`,{value:e.ref.catalogId,children:e.name??e.ref.catalogId},e.ref.catalogId))}),q&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`h2`,{className:`knowledge-catalog-name`,children:q.name??n}),(0,m.jsxs)(`p`,{className:`knowledge-catalog-meta`,children:[q.documents??`?`,` documents · `,q.license??``,q.ref.version?` · v${q.ref.version}`:``]})]}),(0,m.jsx)(`input`,{type:`search`,className:`knowledge-rail-search`,placeholder:`Search this catalog…`,"aria-label":`Search knowledge`,value:I,onChange:e=>L(e.target.value)}),(0,m.jsx)(`ul`,{className:`knowledge-topics`,children:le.map(e=>$(e,0))})]}),(0,m.jsx)(`section`,{className:`knowledge-list`,"aria-label":`Documents`,children:I.trim()?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`div`,{className:`knowledge-list-header`,children:`Search results`}),B&&(0,m.jsx)(`p`,{className:`muted small`,style:{padding:`0 1rem`},children:`Searching…`}),!B&&R?.length===0&&(0,m.jsxs)(`p`,{className:`muted small`,style:{padding:`0 1rem`},children:[`No results for “`,I.trim(),`”.`]}),(0,m.jsx)(`ul`,{className:`knowledge-doc-list`,children:(R??[]).map(e=>(0,m.jsx)(`li`,{children:(0,m.jsxs)(`button`,{type:`button`,className:`knowledge-doc-row`,"aria-current":e.documentId===k?`true`:void 0,onClick:()=>{e.documentId&&A(e.documentId)},children:[(0,m.jsx)(`span`,{className:`knowledge-doc-title`,children:e.title}),e.snippet&&(0,m.jsx)(`span`,{className:`knowledge-doc-summary`,children:e.snippet})]})},e.id))})]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`div`,{className:`knowledge-list-header`,children:S?J.get(S)??`Documents`:`All documents`}),w===null&&(0,m.jsx)(`p`,{className:`muted small`,style:{padding:`0 1rem`},children:`Loading…`}),(0,m.jsx)(`ul`,{className:`knowledge-doc-list`,children:(w??[]).map(e=>(0,m.jsx)(`li`,{children:(0,m.jsxs)(`button`,{type:`button`,className:`knowledge-doc-row`,"aria-current":e.id===k?`true`:void 0,onClick:()=>A(e.id),children:[(0,m.jsx)(`span`,{className:`knowledge-doc-title`,children:e.title}),e.summary&&(0,m.jsx)(`span`,{className:`knowledge-doc-summary`,children:e.summary})]})},e.id))}),w&&w.length<E&&(0,m.jsx)(`button`,{type:`button`,className:`knowledge-list-more`,disabled:D,onClick:()=>{O(!0),K(w.length).finally(()=>O(!1))},children:D?`Loading…`:`Show more (${E-w.length} left)`})]})}),(0,m.jsx)(`section`,{className:`knowledge-reader`,"aria-label":`Article`,children:j?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`header`,{className:`knowledge-reader-header`,children:[(0,m.jsx)(`h2`,{children:j.title}),(0,m.jsxs)(`p`,{className:`knowledge-reader-meta`,children:[J.get(j.topicId)??j.topicId,j.sourceUpdatedAt?` · snapshot ${j.sourceUpdatedAt.slice(0,10)}`:``]})]}),(0,m.jsx)(`div`,{className:`knowledge-reader-body`,onClickCapture:ue,children:Z&&Y?(0,m.jsx)(u.Provider,{value:Y,children:(0,m.jsx)(ee,{doc:Z,className:`gezel-article-view`,theme:ne,...G?{surface:G}:{},imageDisplayMode:`inline`,showCover:!1})}):(0,m.jsx)(`p`,{className:`error small`,children:`This document could not be rendered.`})}),(0,m.jsxs)(`footer`,{className:`knowledge-reader-footer`,children:[(0,m.jsxs)(`span`,{children:[q?.license??``,j.attribution?.text?` · ${j.attribution.text}`:``]}),(0,m.jsxs)(`span`,{className:`knowledge-footer-actions`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:de,children:H?`Copied`:`Copy citation`}),j.sourceUrl&&(0,m.jsx)(`a`,{href:j.sourceUrl,target:`_blank`,rel:`noreferrer`,children:(0,m.jsx)(`button`,{type:`button`,children:`Open source`})}),(0,m.jsx)(`button`,{type:`button`,onClick:fe,children:`Ask a gezel about this`})]})]})]}):(0,m.jsx)(`div`,{className:`knowledge-empty`,children:ce?(0,m.jsx)(`p`,{className:`muted`,children:`Loading…`}):P?(0,m.jsx)(`p`,{className:`error`,children:P}):(0,m.jsx)(`p`,{className:`placeholder`,children:`Pick a document on the left to read it here.`})})})]})}export{y as KnowledgeView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{N as r,Zt as i,bt as a}from"./dist-DOqbRmFj.js";import{t as o}from"./api-C0I7spBl.js";import{t as s}from"./model-context-DBqdK0PS.js";import{r as c}from"./model-memory-copy-Ds9w1uJE.js";import{t as l}from"./ConfirmDialog-Dt1ed4Fh.js";import{Pt as u,wt as d}from"./index-DDu8nyO6.js";import{t as f}from"./CatalogBrowser-7_jHy5Q3.js";import{n as p,r as m,t as h}from"./InstallProgressRow-DyKOI4MU.js";import{t as g}from"./IncompleteDownloads-C36lTCMG.js";import{t as _}from"./LicenseButton-D3VmcVG1.js";import{a as v,i as y,n as b,o as x,r as S,t as C}from"./UnrecognizedModels-0hptopv6.js";import{a as w,i as T,o as E,r as D,t as O}from"./use-local-model-manager-D1yiurrC.js";var k=e(t(),1),A=n(),j=5e3,M=1024*1024,ee=512,N=32*1024,P=4*1024,F=256;function I(e){if(e<1024)return`${Math.round(e)} MB`;let t=e/1024;return`${Number.isInteger(t)?t:t.toFixed(1)} GB`}function L({providerName:e,label:t,configuredBudgetMb:n}){let[r,i]=(0,k.useState)(null),[a,s]=(0,k.useState)(n??null),[c,l]=(0,k.useState)(!1),[d,f]=(0,k.useState)(!1),[p,m]=(0,k.useState)(null),h=(0,k.useCallback)(async()=>{try{let t=(await o.getCacheStats()).providers.find(t=>t.providerName===e)??null;i(t)}catch{}},[e]);(0,k.useEffect)(()=>{h();let e=setInterval(()=>void h(),j);return()=>clearInterval(e)},[h]),(0,k.useEffect)(()=>{s(n??null)},[n]);let g=(0,k.useCallback)(async t=>{l(!0),m(null);try{await o.updateConfig({cacheBudgetMb:{[e]:t}}),m(t===void 0?`Reset to auto`:`Saved`),await h()}catch(e){m(`Failed to save: ${e instanceof Error?e.message:String(e)}`)}finally{l(!1)}},[e,h]),_=(0,k.useCallback)(async()=>{f(!0),m(null);try{await o.clearProviderCache(e),m(`Cleared all caches`),await h()}catch(e){m(`Failed to clear: ${e instanceof Error?e.message:String(e)}`)}finally{f(!1)}},[e,h]),v=r?Math.round(r.totalBytes/M):0,y=r?Math.round(r.budgetBytes/M):0,b=u(r?.sessions,r?.warmSessionCount??0),x=r?.defaultBudgetBytes?Math.round(r.defaultBudgetBytes/M):y||2048,S=Math.min(ee,x),C=r?.systemRamBytes?Math.max(x,Math.round(r.systemRamBytes/M)-P):Math.max(N,x*2),w=Math.min(Math.max(a??x,S),C),T=a===null||Math.abs(a-x)<=F,E=n!==void 0,D=(a??x)!==(n??x),O=(x-S)/Math.max(1,C-S)*100;return(0,A.jsxs)(`div`,{className:`cache-controls-panel`,children:[(0,A.jsx)(`h4`,{children:`Memory budget`}),(0,A.jsxs)(`p`,{className:`muted small`,children:[`The most memory `,t,` keeps for chat and shared-prefix context before older entries are released.`]}),r&&b.totalCount>0?(0,A.jsxs)(`p`,{className:`muted small`,children:[b.label,` · `,I(v),` used of `,I(y),r.recentHitRate>0&&(0,A.jsxs)(A.Fragment,{children:[` · `,Math.round(r.recentHitRate*100),`% hit rate (last 50 turns)`]})]}):(0,A.jsx)(`p`,{className:`muted small`,children:`No warm cache entries yet — they populate after the first turn.`}),(0,A.jsxs)(`div`,{className:`gz-budget-slider`,children:[(0,A.jsxs)(`div`,{className:`gz-budget-slider-head`,children:[(0,A.jsx)(`strong`,{children:I(w)}),T?(0,A.jsx)(`span`,{className:`gz-budget-tag`,children:`Auto (RAM-aware)`}):(0,A.jsx)(`span`,{className:`gz-budget-tag gz-budget-tag-custom`,children:`Custom`})]}),(0,A.jsxs)(`div`,{className:`gz-budget-track`,children:[(0,A.jsx)(`input`,{type:`range`,min:S,max:C,step:256,value:w,"aria-label":`Memory budget for ${t}`,onChange:e=>s(Number.parseInt(e.target.value,10))}),(0,A.jsxs)(`div`,{className:`gz-budget-marker`,style:{left:`${O}%`},title:`Suggested for this Mac: ${I(x)}`,"aria-hidden":`true`,children:[(0,A.jsx)(`span`,{className:`gz-budget-marker-arrow`,children:`▲`}),(0,A.jsxs)(`span`,{className:`gz-budget-marker-label`,children:[`Auto · `,I(x)]})]})]}),(0,A.jsxs)(`div`,{className:`gz-budget-scale muted small`,children:[(0,A.jsx)(`span`,{children:I(S)}),(0,A.jsx)(`span`,{children:I(C)})]})]}),(0,A.jsxs)(`div`,{className:`cache-budget-actions`,style:{marginTop:`0.75rem`},children:[(0,A.jsx)(`button`,{type:`button`,onClick:()=>void g(T?void 0:w),disabled:c||!D,children:c?`Saving…`:`Save`}),E&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>void g(void 0),disabled:c,style:{marginLeft:`0.5rem`},children:`Reset to auto`})]}),(0,A.jsx)(`div`,{style:{marginTop:`0.75rem`},children:(0,A.jsx)(`button`,{type:`button`,onClick:()=>void _(),disabled:d||!r||b.totalCount===0,children:d?`Clearing…`:`Clear all caches`})}),p&&(0,A.jsx)(`p`,{className:`muted small`,style:{marginTop:`0.5rem`},children:p})]})}function R(e){return e.residentBytes??Math.round(e.approxSizeBytes*1.3)}function z(e,t){return R(e)<=t}function te(e){return`~${c(e)}`}function B(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleDateString(void 0,{year:`numeric`,month:`short`})}function V(e){return e.kind!==`chat-model`||!e.mlx||e.mlx.disabledReason?null:e}var H={"mix of experts":`Only a fraction of the model's parameters run per token, so it's faster than a dense model of the same nominal size.`,vision:`Can accept images alongside text.`,tools:`Supports function/tool calling via the API.`,multimodal:`Handles multiple input types (text + images).`,large:`Heavy model — needs a lot of memory and runs more slowly.`,small:`Compact model — runs quickly on modest hardware.`};function U({onModelsChanged:e,compact:t=!1}){let{models:n,modelsError:c,incomplete:u,unrecognized:h,installs:w,installWarning:E,setInstallWarning:j,installError:M,setInstallError:ee,installMismatch:N,setInstallMismatch:P,toDelete:F,setToDelete:I,fitness:L,probing:R,refreshFitness:U,refresh:G,deleteOne:K,startInstall:q,retryInstall:ne,cancelInstall:re,downloadAnyway:ie}=O(D,e),[J,ae]=(0,k.useState)(null),[Y,oe]=(0,k.useState)(!1),[X,se]=(0,k.useState)(`all`),[Z,ce]=(0,k.useState)(null),[le,Q]=(0,k.useState)(!1),[$,ue]=(0,k.useState)([]);(0,k.useEffect)(()=>{o.getMemoryProfile().then(e=>ae(e)).catch(()=>{}),o.getModelContextOverrides(`mlx`).then(()=>Q(!0)).catch(()=>Q(!1))},[]);let de=(0,k.useMemo)(()=>new Set(n.map(e=>e.id)),[n]),fe=(0,k.useMemo)(()=>new Set(h.map(e=>e.id)),[h]),pe=(0,k.useMemo)(()=>{let e=new Set;for(let t of $){let n=V(t.manifest);n&&e.add(n.category??`general`)}return[`all`,...[`general`,`coding`,`reasoning`,`vision`,`embedding`].filter(t=>e.has(t))]},[$]);return(0,A.jsxs)(`div`,{className:`ollama-model-manager`,children:[w.size>0&&(0,A.jsxs)(`div`,{className:`ollama-section`,children:[(0,A.jsx)(`h4`,{children:`Downloading…`}),(0,A.jsx)(`div`,{className:`ollama-pull-list`,children:Array.from(w.values()).map(e=>(0,A.jsx)(W,{inst:e,onCancel:()=>re(e.catalogId),onRetry:()=>ne(e.catalogId)},e.catalogId))})]}),(0,A.jsx)(C,{items:h.filter(e=>!w.has(e.id)),onUpdate:e=>q(e),onRemove:e=>I(e)}),(0,A.jsx)(g,{items:u.filter(e=>!w.has(e.id)),onResume:e=>q(e),onDelete:e=>I(e)}),N&&(0,A.jsxs)(`div`,{className:`ollama-section`,children:[(0,A.jsxs)(`div`,{className:`gz-status-pill gz-status-pill--warn`,style:{marginBottom:`0.5rem`},children:[`⚠ `,(0,A.jsx)(`code`,{children:N.catalogId}),` is newer on Hugging Face than the version Gezel knows about`]}),(0,A.jsxs)(`p`,{style:{marginBottom:`0.5rem`},children:[`The file `,(0,A.jsx)(`code`,{children:N.file}),` changed upstream, so its checksum no longer matches what this version of Gezel pinned. This is almost always a harmless upstream fix — model authors routinely re-publish chat templates and tokenizer configs — but we can't verify it automatically. You can download the current version now, or wait for a Gezel update with a refreshed catalog.`]}),(0,A.jsxs)(`div`,{style:{display:`flex`,gap:`0.75rem`},children:[(0,A.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>ie(N.catalogId),children:`Download anyway`}),(0,A.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>P(null),children:`Dismiss`})]})]}),M&&(0,A.jsx)(`div`,{className:`ollama-section`,children:(0,A.jsx)(`p`,{className:`error`,style:{marginBottom:`0.5rem`},children:M})}),E&&(0,A.jsx)(`div`,{className:`ollama-section`,children:(0,A.jsxs)(`div`,{className:`gz-status-pill gz-status-pill--warn`,style:{marginBottom:`0.5rem`},children:[`⚠ `,E.id,`: `,E.message]})}),!t&&(0,A.jsx)(b,{engine:`mlx`,onModelsChanged:e}),(n.length>0||c)&&(0,A.jsxs)(`div`,{className:`ollama-section`,children:[(0,A.jsx)(`h4`,{children:t?`Models on this device`:`Local models`}),c&&(0,A.jsx)(`p`,{className:`error`,children:c}),n.length>0&&(0,A.jsx)(`div`,{className:`ollama-model-table-wrap`,children:(0,A.jsxs)(`table`,{className:`ollama-model-table`,children:[(0,A.jsxs)(`colgroup`,{children:[(0,A.jsx)(`col`,{className:`model-name-column`}),(0,A.jsx)(`col`,{}),(0,A.jsx)(`col`,{}),(0,A.jsx)(`col`,{}),(0,A.jsx)(`col`,{}),(0,A.jsx)(`col`,{})]}),(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{children:`Name`}),(0,A.jsx)(`th`,{children:`Size`}),(0,A.jsx)(`th`,{children:`Quant`}),(0,A.jsx)(`th`,{title:`Effective per-turn context size after Gezel's configured limit`,children:`Context size`}),(0,A.jsx)(`th`,{title:`Representative startup and decode speed with an approximately 20K-token prompt`,children:`Fitness`}),(0,A.jsx)(`th`,{})]})}),(0,A.jsx)(`tbody`,{children:n.map(e=>{let t=e.updateAvailable===!0,n=!!w.get(e.id),a=`mlx:${e.id}`,c=L.get(a);return(0,A.jsxs)(k.Fragment,{children:[(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`td`,{className:`model-name-table-cell`,children:(0,A.jsxs)(`div`,{className:`model-name-cell`,children:[(0,A.jsx)(`code`,{children:e.id}),(0,A.jsx)(`div`,{className:`model-name-meta`,children:t&&(0,A.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:e.updateReason??`The catalog ships different model files than the copy on disk. Update to pick them up.`,children:`out of date`})})]})}),(0,A.jsx)(T,{model:e}),(0,A.jsx)(`td`,{title:i(e.quantization),children:r(e.quantization)}),(0,A.jsx)(`td`,{title:e.effectiveContextWindow?e.overrideContextTokens===void 0?`Gezel will grant up to ${e.effectiveContextWindow.toLocaleString()} tokens per turn${e.contextWindow?`; the model advertises ${e.contextWindow.toLocaleString()} tokens`:``}.`:`You've set this model to ${e.overrideContextTokens.toLocaleString()} tokens per turn; Gezel grants up to what memory allows (currently ${e.effectiveContextWindow.toLocaleString()}).`:e.contextSizingStatus===`restart-required`?`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.`:e.contextSizingStatus===`insufficient-memory`?`The requested context window does not fit in memory safely. Unload another model or free memory before trying again.`:`The effective context size is unavailable.`,children:e.contextSizingStatus===`restart-required`?`Restart needed`:e.contextSizingStatus===`insufficient-memory`?`Won't fit`:(0,A.jsxs)(A.Fragment,{children:[s(e.effectiveContextWindow),e.overrideContextTokens!==void 0&&(0,A.jsx)(`span`,{className:`gz-budget-tag gz-budget-tag-custom model-context-custom-tag`,children:`custom`})]})}),(0,A.jsx)(S,{entry:c,probing:R.includes(a)}),(0,A.jsx)(`td`,{className:`model-actions-table-cell`,children:(0,A.jsxs)(`div`,{className:`model-actions-cell`,children:[(0,A.jsx)(`div`,{className:`model-action-status`,children:e.readOnly&&(0,A.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,A.jsx)(`div`,{className:`model-action-links`,children:(0,A.jsx)(v,{engine:`mlx`,model:{...e,updateAvailable:t},updating:n,contextSupported:le,contextEditorOpen:Z===e.id,onToggleContextEditor:()=>ce(t=>t===e.id?null:e.id),fitnessAction:y(c,R.includes(a),()=>{o.runModelFitnessProbe(`mlx`,e.id).then(()=>U()).catch(()=>{})}),onUpdate:()=>q(e.id),updateLabel:{idle:`Download again`,busy:`Downloading…`},onDelete:()=>I(e.id)})})]})})]}),Z===e.id&&(0,A.jsx)(`tr`,{className:`model-context-editor-row`,children:(0,A.jsx)(`td`,{colSpan:6,children:(0,A.jsx)(x,{engine:`mlx`,model:e,onSaved:G})})})]},e.id)})})]})})]}),(0,A.jsxs)(`div`,{className:`ollama-section ollama-section--flat ollama-section--download`,children:[(0,A.jsx)(`h4`,{children:`Download a model`}),(0,A.jsxs)(`p`,{className:`muted small`,style:{marginTop:0},children:[`Models are hosted by`,` `,(0,A.jsx)(`a`,{href:`https://huggingface.co`,target:`_blank`,rel:`noreferrer`,style:{color:`inherit`},children:`Hugging Face`}),`, a community library of open, freely available AI models. Your device downloads them directly.`]}),(0,A.jsxs)(`p`,{className:`muted small`,children:[J?`Models that may not fit this machine, and retired models, are hidden by default. `:`Retired models are hidden by default. `,(0,A.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:()=>oe(e=>!e),style:{padding:0},children:Y?J?`Hide retired and oversized models`:`Hide retired models`:`Show all models`})]}),(0,A.jsx)(`div`,{className:`provider-switch`,style:{marginBottom:`0.5rem`},children:pe.map(e=>(0,A.jsx)(`button`,{type:`button`,className:`provider-pill${X===e?` provider-pill-active`:``}`,onClick:()=>se(e),children:e===`all`?`All`:e[0]?.toUpperCase()+e.slice(1)},e))}),(0,A.jsx)(f,{kind:`chat-model`,emptyMessage:`No MLX-format entries in the catalog yet.`,onItemsLoaded:ue,tagTooltips:H,filter:e=>{let t=V(e.manifest);return!(!t||!Y&&a(t)||X!==`all`&&(t.category??`general`)!==X||!Y&&J&&!z(t.mlx,J.usableBytes))},action:e=>{let t=V(e.manifest);if(!t)return null;let n=de.has(t.id),r=fe.has(t.id),i=w.get(t.id),a=i&&i.totalBytes>0?Math.min(100,Math.round(i.bytesWritten/i.totalBytes*100)):null,o=J?!z(t.mlx,J.usableBytes):!1;return(0,A.jsxs)(`div`,{className:`catalog-ollama-action`,children:[(0,A.jsxs)(`div`,{className:`catalog-ollama-meta`,children:[(0,A.jsxs)(`div`,{className:`catalog-ollama-specs muted small`,children:[(0,A.jsx)(p,{repo:t.mlx.huggingfaceRepo}),(0,A.jsx)(`span`,{children:`·`}),(0,A.jsx)(`span`,{children:t.parameterSize}),(0,A.jsx)(`span`,{children:`·`}),(0,A.jsx)(`span`,{children:te(t.mlx.approxSizeBytes)}),B(t.releasedAt)&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`span`,{children:`·`}),(0,A.jsx)(`span`,{children:B(t.releasedAt)})]})]}),(0,A.jsxs)(`div`,{className:`catalog-ollama-pills`,children:[(0,A.jsx)(_,{manifest:t,fallbackHref:m(t.mlx.huggingfaceRepo)}),o&&(0,A.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:`Larger than your estimated inference budget — may run slowly or fail.`,children:`may not fit`})]})]}),(0,A.jsx)(`button`,{type:`button`,disabled:n||r||!!i,onClick:()=>q(t.id),children:n?`On device`:i?i.phase===`downloading`?a===null?`Downloading…`:`Downloading… ${a}%`:i.phase===`verifying`?`Verifying…`:`Reading metadata…`:r?`Needs attention above`:`Download`})]})}})]}),(0,A.jsxs)(`div`,{className:`ollama-section ollama-section--flat`,children:[(0,A.jsx)(d,{}),(0,A.jsx)(`span`,{className:`muted small`,style:{marginLeft:`0.75rem`},children:`Import from a gezel local model package`})]}),(0,A.jsx)(l,{open:F!==null,title:`Delete ${F??``}?`,message:`This removes the downloaded model from your device. It stays available in the catalog — you can download it again any time.`,confirmLabel:`Delete`,danger:!0,onConfirm:K,onCancel:()=>I(null)})]})}function W({inst:e,onCancel:t,onRetry:n}){let r=e.totalBytes>0,i=r?Math.min(100,Math.round(e.bytesWritten/e.totalBytes*100)):0,a;if(e.error)a=e.error;else if(e.retrying){let t=Math.max(1,Math.round(e.retrying.delayMs/1e3)),n=e.fileCount>1?` on shard ${e.fileIndex}/${e.fileCount}`:``;a=`${e.retrying.reason}${n} — retrying in ${t}s (attempt ${e.retrying.attempt}/${e.retrying.maxAttempts})`}else a=e.phase===`downloading`?r?`Downloading ${c(e.bytesWritten)} of ${c(e.totalBytes)} (${i}%)`:e.bytesWritten>0?`Downloading ${c(e.bytesWritten)}…`:`Preparing download…`:e.phase===`verifying`?`Checking download${e.file?` (${e.file})`:`…`}`:`Reading model info…`;let o=e.phase!==`downloading`||!r;return(0,A.jsx)(h,{title:(0,A.jsx)(`code`,{children:e.catalogId}),status:a,percent:o?null:i,tone:e.error?`error`:e.retrying?`warning`:`normal`,onCancel:t,onRetry:n})}var G=typeof navigator<`u`&&/Mac/.test(navigator.platform)&&(navigator.userAgentData?.architecture===`arm`||/Mac.*Apple/i.test(navigator.userAgent));function K({config:e,onConfigChanged:t}){let[n,r]=(0,k.useState)(e?.mlxBaseUrl??``),[i,a]=(0,k.useState)(e?.mlxModelPath??``),[s,c]=(0,k.useState)(e?.mlxPackageSpec??``),[l,u]=(0,k.useState)(null),[d,f]=(0,k.useState)([]),[p,m]=(0,k.useState)(`idle`),[h,g]=(0,k.useState)(null),[_,v]=(0,k.useState)(`idle`);(0,k.useEffect)(()=>{r(e?.mlxBaseUrl??``)},[e?.mlxBaseUrl]),(0,k.useEffect)(()=>{a(e?.mlxModelPath??``)},[e?.mlxModelPath]),(0,k.useEffect)(()=>{c(e?.mlxPackageSpec??``)},[e?.mlxPackageSpec]);let y=(0,k.useCallback)(async()=>{try{let e=await o.getMlxRuntime();u(e)}catch{u(null)}},[]);(0,k.useEffect)(()=>{y()},[y]);let b=(0,k.useCallback)(async()=>{try{let e=await o.listMlxModels();f(e.models)}catch{}},[]);(0,k.useEffect)(()=>{b()},[b]);let x=(0,k.useCallback)(()=>{b(),y()},[b,y]),S=(0,k.useCallback)(async()=>{v(`resetting`);try{await o.resetMlxRuntime(),v(`done`),setTimeout(()=>v(`idle`),3e3),y()}catch(e){v(`idle`),g(e instanceof Error?e.message:String(e))}},[y]),C=(0,k.useCallback)(async()=>{let e=n.trim();m(`saving`);try{t(await o.updateConfig({mlxBaseUrl:e===``?null:e})),m(`saved`),setTimeout(()=>m(`idle`),1200)}catch{m(`idle`)}},[n,t]),T=(0,k.useCallback)(async()=>{let e=i.trim();m(`saving`);try{t(await o.updateConfig({mlxModelPath:e===``?null:e})),m(`saved`),setTimeout(()=>m(`idle`),1200)}catch{m(`idle`)}},[i,t]),D=(0,k.useCallback)(async()=>{let e=s.trim();m(`saving`);try{t(await o.updateConfig({mlxPackageSpec:e===``?null:e})),m(`saved`),setTimeout(()=>m(`idle`),1200)}catch{m(`idle`)}},[s,t]),O=(0,k.useCallback)(async e=>{m(`saving`);try{t(await o.updateConfig({mlxKvBits:e===0?null:e})),m(`saved`),setTimeout(()=>m(`idle`),1200)}catch{m(`idle`)}},[t]),j=(0,k.useCallback)(async n=>{m(`saving`);try{t(await o.updateConfig({defaultModel:{...e?.defaultModel,mlx:n??void 0}})),m(`saved`),setTimeout(()=>m(`idle`),1200)}catch{m(`idle`)}},[e?.defaultModel,t]),M=!!e?.mlxBaseUrl;return(0,A.jsxs)(`div`,{children:[(0,A.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,A.jsx)(`h3`,{children:`This Mac (Apple MLX)`}),(0,A.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:`On-device AI powered by Apple's MLX framework, making the best use of the hardware you already have — in many cases the best choice of engine for your Mac. Your conversations stay on your computer: no account to set up, no data sent to the cloud.`}),(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`,alignItems:`center`},children:[(0,A.jsx)(`span`,{className:`muted small`,children:`Status:`}),(0,A.jsx)(`span`,{className:`gz-status-pill gz-status-pill--ok`,children:`ready`})]}),!G&&(0,A.jsx)(`div`,{className:`gz-status-pill gz-status-pill--warn`,style:{marginTop:`0.5rem`,display:`inline-block`},children:`This machine doesn't look like Apple Silicon — chat turns routed to MLX will error out at send time.`}),M&&(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`},children:[(0,A.jsx)(`span`,{className:`gz-status-pill gz-status-pill--warn`,title:`External engine: ${e?.mlxBaseUrl}`,children:`using external engine`}),p===`saved`&&(0,A.jsx)(`span`,{className:`muted small`,children:`saved ✓`})]})]}),d.length>1&&(0,A.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,A.jsx)(`h4`,{children:`Default model`}),(0,A.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`Which local model new chat sessions use when a gezel doesn't pin one.`}),(0,A.jsx)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`},children:(0,A.jsxs)(`select`,{"aria-label":`Default model`,value:e?.defaultModel?.mlx??``,onChange:e=>void j(e.target.value||void 0),children:[(0,A.jsx)(`option`,{value:``,children:`First local model`}),d.map(e=>(0,A.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.id,`)`]},e.id))]})})]}),(0,A.jsx)(`section`,{style:{marginBottom:`2rem`},children:(0,A.jsx)(U,{onModelsChanged:x})}),(0,A.jsx)(E,{provider:`mlx`}),(0,A.jsxs)(`section`,{style:{marginBottom:`2rem`},children:[(0,A.jsx)(`h4`,{style:{marginBottom:`0.5rem`},children:`Concurrent replicas`}),(0,A.jsx)(`p`,{className:`muted small`,style:{marginTop:0},children:`Run multiple copies of the same model so unrelated sessions don't queue behind each other. Weights are shared by the OS via mmap so disk cost stays at one model file; resident memory grows because each clone keeps its own KV cache and activations.`}),(0,A.jsx)(w,{provider:`mlx`,modelId:e?.defaultModel?.mlx??null,config:e,onConfigChanged:t})]}),h&&(0,A.jsxs)(`div`,{className:`muted small`,style:{color:`#ff9b9b`,marginTop:`1rem`},role:`alert`,children:[h,` `,(0,A.jsx)(`button`,{type:`button`,onClick:()=>g(null),children:`dismiss`})]}),(0,A.jsx)(`section`,{style:{marginTop:`2rem`},children:(0,A.jsx)(L,{providerName:`mlx`,label:`This Mac AI`,configuredBudgetMb:e?.cacheBudgetMb?.mlx})}),(0,A.jsxs)(`details`,{className:`mlx-advanced`,style:{marginTop:`2rem`},children:[(0,A.jsx)(`summary`,{style:{cursor:`pointer`},children:(0,A.jsx)(`strong`,{children:`Advanced`})}),(0,A.jsxs)(`section`,{style:{marginTop:`1.25rem`},children:[(0,A.jsx)(`h4`,{style:{marginBottom:`0.35rem`},children:`Python runtime`}),l?(0,A.jsx)(`div`,{className:`muted small`,style:{marginTop:`0.25rem`},children:l.source===null?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`strong`,{children:`No Python runtime available.`}),` `,l.reason??`Install Python 3.11 or wait for a packaged build that bundles uv.`]}):(0,A.jsxs)(A.Fragment,{children:[`Source: `,(0,A.jsx)(`code`,{children:l.source}),l.uvVersion&&(0,A.jsxs)(A.Fragment,{children:[` `,`· uv `,(0,A.jsx)(`code`,{children:l.uvVersion})]}),l.pythonVersion&&(0,A.jsxs)(A.Fragment,{children:[` `,`· Python `,(0,A.jsx)(`code`,{children:l.pythonVersion})]}),l.installerPath&&(0,A.jsxs)(A.Fragment,{children:[` `,`· `,(0,A.jsx)(`span`,{title:l.installerPath,children:`installer at path`})]})]})}):(0,A.jsx)(`div`,{className:`muted small`,children:`Probing…`}),(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`,alignItems:`center`},children:[(0,A.jsx)(`button`,{type:`button`,onClick:()=>void S(),disabled:_===`resetting`,children:_===`resetting`?`Resetting…`:`Reset gezel Python environment`}),_===`done`?(0,A.jsx)(`span`,{className:`gz-status-pill gz-status-pill--ok`,children:`venv was reset ✓`}):(0,A.jsx)(`span`,{className:`muted small`,children:"Deletes the `mlx` venv; the next chat turn re-provisions it."})]})]}),(0,A.jsxs)(`section`,{style:{marginTop:`1.25rem`},children:[(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.75rem`,alignItems:`center`},children:[(0,A.jsx)(`label`,{className:`muted`,style:{fontSize:`0.9rem`,minWidth:`12rem`},children:`External mlx_lm.server URL`}),(0,A.jsx)(`input`,{type:`text`,placeholder:`e.g. http://127.0.0.1:8000 (leave blank for supervised)`,value:n,onChange:e=>r(e.target.value),style:{flex:1}}),(0,A.jsx)(`button`,{type:`button`,disabled:p===`saving`||n===(e?.mlxBaseUrl??``),onClick:()=>void C(),children:`Save`})]}),(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`,alignItems:`center`},children:[(0,A.jsx)(`label`,{className:`muted`,style:{fontSize:`0.9rem`,minWidth:`12rem`},children:`Override model directory`}),(0,A.jsx)(`input`,{type:`text`,placeholder:`Absolute path to an MLX model dir`,value:i,onChange:e=>a(e.target.value),style:{flex:1}}),(0,A.jsx)(`button`,{type:`button`,disabled:p===`saving`||i===(e?.mlxModelPath??``),onClick:()=>void T(),children:`Save`})]}),(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`,alignItems:`center`},children:[(0,A.jsx)(`label`,{className:`muted`,style:{fontSize:`0.9rem`,minWidth:`12rem`},children:`mlx-lm package spec`}),(0,A.jsx)(`input`,{type:`text`,placeholder:`e.g. mlx-lm==0.25.3 (blank → latest)`,value:s,onChange:e=>c(e.target.value),style:{flex:1}}),(0,A.jsx)(`button`,{type:`button`,disabled:p===`saving`||s===(e?.mlxPackageSpec??``),onClick:()=>void D(),children:`Save`})]}),(0,A.jsxs)(`div`,{className:`new-row`,style:{marginTop:`0.5rem`,alignItems:`center`},children:[(0,A.jsx)(`label`,{className:`muted`,style:{fontSize:`0.9rem`,minWidth:`12rem`},children:`KV cache quantization`}),(0,A.jsxs)(`select`,{value:String(e?.mlxKvBits??0),onChange:e=>void O(Number(e.target.value)),style:{flex:1},children:[(0,A.jsx)(`option`,{value:`0`,children:`Off — full precision (default)`}),(0,A.jsx)(`option`,{value:`8`,children:`8-bit — about half the memory, near-lossless`}),(0,A.jsx)(`option`,{value:`6`,children:`6-bit — smaller still`}),(0,A.jsx)(`option`,{value:`4`,children:`4-bit — smallest, some quality loss`})]})]}),(0,A.jsx)(`p`,{className:`muted small`,style:{marginTop:`0.35rem`},children:`Compresses the conversation history the model keeps in memory. That history is the biggest cost in a long chat — on a large model with a 256K context it can outweigh the model itself — and 8-bit roughly halves it at close to no quality cost. Only applies while the engine serves one chat at a time; when it is set up to handle several at once, the history stays at full precision. Takes effect the next time the engine starts.`})]})]})]})}export{K as MlxSettings};
|