@davmash/bygone 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web/web-host.js CHANGED
@@ -667,5 +667,5 @@ Verify the pinned and current implementation revisions before acting. If authori
667
667
 
668
668
  ${g.conversion.detail}
669
669
 
670
- The converted copy will be downloaded after opening.`)){Qe("Tour conversion canceled.");return}p=await d(!0),g=await p.json().catch(()=>({}))}if(!p.ok)throw new Error(g.error||`Tour upload failed (${p.status}).`);if(!g||typeof g.manifestUrl!="string"||!g.manifestUrl)throw new Error("Tour upload did not return a manifest URL.");if(Fi(g)&&!window.confirm(Di(g))){Qe("Kept the current tour.");return}if(!await Hr(g.manifestUrl)){Qe("Could not load the uploaded tour.");return}if(typeof g.convertedSource=="string"){let b=URL.createObjectURL(new Blob([g.convertedSource],{type:"application/yaml"})),E=document.createElement("a");E.href=b,E.download=`${r.name.replace(/(?:\.bygone)?\.ya?ml$|\.bygone$/i,"")}.v4.bygone`,document.body.appendChild(E),E.click(),E.remove(),setTimeout(()=>URL.revokeObjectURL(b),1e3)}Qe("")}catch(r){Qe(`Could not open existing tour: ${r instanceof Error?r.message:String(r)}`)}}function re(){return!n.zoom||!!G()[n.zoom.mode]}function Ct(r){let a=n.authoredTour;if(G()[r])return{...a,opening:void 0,conclusion:void 0,details:void 0,...G()[r]};let u=r==="compare"&&n.compare?[...new Map([...n.compare.inventory||a.files,...n.compare.files].map(d=>[d.path,d])).values()]:r==="history"&&n.historyFiles||a.files;return{...a,opening:void 0,conclusion:void 0,details:void 0,scenes:[],chapters:[],files:u}}function ct(){let r=document.getElementById("tour-mode-controls");if(r.hidden=!n.zoom||ce,!n.zoom)return;be();let a=document.getElementById("tour-mode-tabs"),u=document.getElementById("tour-mode-description");a&&(a.hidden=!0),u&&(u.hidden=!0);let d=n.zoom.mode==="history",p=ae();document.getElementById("tour-history-controls").hidden=!p||n.zoom.mode==="compare",document.getElementById("tour-compare-controls").hidden=!p||n.zoom.mode!=="compare";let g=["historical","deconstructed"].includes(n.zoom.mode)&&!G()[n.zoom.mode];document.body.classList.toggle("workspace-empty-tour",g),document.body.classList.toggle("tour-derived-mode",!re()),re()||document.body.classList.remove("tour-discussion");for(let y of["tour-history-parent","tour-history-base"])document.getElementById(y).hidden=!d;dt()}function dt(){let r=n.comparisonDraftCommits,a=r.length,u=ae(),d=[...new Set(An())],p=E=>E.length===a&&E.every(P=>r.includes(P)),g=n.zoom?.mode==="compare"&&p(n.compare?.commits||[]);for(let E of["history","compare"])document.getElementById(`tour-${E}-count`).textContent=`${a} selected`,document.getElementById(`tour-${E}-hint`).textContent=a<2?"Select 2+ revisions":g?"Selection applied":E==="compare"?"Unapplied selection":"Ready to compare",document.getElementById(`tour-${E}-clear`).disabled=!a,document.getElementById(`tour-${E}-reset`).disabled=!d.length||p(d);document.getElementById("tour-history-compare").disabled=a<2||!u;let y=document.getElementById("tour-compare-apply");y.disabled=a<2||!u||g,y.title=g?"These revisions are already displayed":"Apply the selected revisions";let b=document.getElementById("tour-compare-scope");b.textContent=n.compare?.path||"All changed files",b.title=n.compare?.path?`File scope: ${n.compare.path}`:"Comparing across all changed files",document.getElementById("tour-compare-all").hidden=!n.compare?.path;for(let E of["tour-history-parent","tour-history-base"])document.getElementById(E).disabled=!ae()||!n.historyCommit}function $n(){return[...new Set([...[...n.historyEntries].reverse().map(r=>r.commit),n.authoredTour.range.mergeBaseOid,...n.authoredTour.commits.map(r=>r.oid),n.authoredTour.range.headOid])]}function Lr(r){return hi(r,$n())}async function we(r,a,u=n.historyPrefix,d=n.authoredTour){if(c)return c(r,a);if(!ae(d))throw new Error(je());let p=await fetch(`${u||"/history/"}${r}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),g=await p.json();if(!p.ok)throw new Error(g.error||`History request failed (${p.status}).`);return g}function fe(r){let a=r instanceof Error?r.message:String(r),u=document.getElementById("tour-mode-status");u&&(u.textContent=a),N&&Qe(a)}function An(){return n.displayedPanels.map(r=>r.commit).filter(Boolean)}function Oi(){let r=n.tour?.scenes[n.activeSceneIndex],a=n.zoom?.mode==="compare"?n.comparisonCommits:[n.authoredTour.range.mergeBaseOid,n.authoredTour.range.headOid];if(n.directoryEvidence&&Me(r)){let u=Ft(r),d=r.overview?.comparison;a=r.kind==="deconstructed-diff"?[]:[(d?u.find(p=>p.id===d.from):u[0])?.oid,(d?u.find(p=>p.id===d.to):u.at(-1))?.oid]}return["left","right"].map((u,d)=>({id:u,commit:a[d]}))}function Nr(){let r=n.displayedPanels.map(a=>a.commit);return{...Tt(Nn({commits:An()}),r,null),navigatorOnly:!0}}async function Bi(r){if(!r||!n.zoom||!ae())return[];if(!n.fileHistoryCache.has(r)){let a=we("list",{path:r,commit:n.authoredTour.range.headOid}).then(u=>u.entries);n.fileHistoryCache.set(r,a),a.catch(()=>n.fileHistoryCache.delete(r))}return n.fileHistoryCache.get(r)}async function Ui(r,a){try{let u=await Bi(r);if(a!==ge)return;se({type:"updateCommitMarkers",changedCommits:u.map(d=>d.commit),path:r})}catch(u){a===ge&&fe(u)}}async function et(r,a,u=!0){if(a=a||n.historyCommit||n.authoredTour.range.headOid,!r)return zi(a,u);let d=++oe,p=n.historyEntries,g=p.find(M=>M.commit===a);if(n.historyPath===r&&n.historyCommit===a&&n.historyPanels.length){await Wt();return}let y=await we("diff",{path:r,commit:a,head:n.authoredTour.range.headOid});if(d!==oe||n.zoom.mode!=="history")return;if(u&&n.historyPanels.length&&n.historyCommit===a){let M=await Promise.all(n.historyPanels.map(async z=>{let L=z.commit===a?{rightContent:y.rightContent,path:y.path}:z.commit===y.parentCommit?{rightContent:y.leftContent,path:y.previousPath||y.path}:z.commit?await we("diff",{path:r,commit:z.commit,head:n.authoredTour.range.headOid}):{rightContent:"",path:r};return{...z,content:L.rightContent,path:L.path}}));if(d!==oe||n.zoom.mode!=="history")return;n.historyPanels=M,n.historyPath=r,n.historyDiff=y,await Wt(),Se();return}let b=p.findIndex(M=>M.commit===a),P=(b>=0?p[b+1]:null)?.commit||y.parentCommit,R=P&&P!==y.parentCommit?(await we("diff",{path:r,commit:P,head:n.authoredTour.range.headOid})).rightContent:y.leftContent;if(d!==oe||n.zoom.mode!=="history")return;n.historyPath=r,n.historyCommit=a;let U=Math.max(2,n.historyPanels.length);n.historyDiff=y;let F=(M,z,L)=>({id:`history-${M||"empty"}`,commit:M,content:z,label:L,path:y.path,editable:!1});for(n.historyPanels=[F(P,R,P?.slice(0,7)||"Empty tree"),F(a,y.rightContent,g?`${g.shortCommit} ${g.summary}`:a.slice(0,7))],n.historyFocus=`history-${a}`;n.historyPanels.length<U;){let M=Kt(n.historyPanels[0],"left");if(!M)break;let z=await we("diff",{path:r,commit:M.commit,head:n.authoredTour.range.headOid});if(d!==oe||n.zoom.mode!=="history")return;n.historyPanels.unshift(F(M.commit,z.rightContent,`${M.shortCommit} ${M.summary}`))}await Wt(),document.getElementById("tour-mode-status").textContent="",dt(),Se()}async function zi(r=n.historyCommit||n.authoredTour.range.headOid,a=!0){let u=++oe,d=n.historyEntries.find(y=>y.commit===r);if(!d)throw new Error("The selected revision is unavailable in this history.");let p=a&&n.historyCommit===r&&n.historyPanels.length?n.historyPanels:[d.parentCommit||null,r].map(y=>({id:`history-${y||"empty"}`,commit:y,content:"",editable:!1,label:y?y.slice(0,7):"Empty tree"})),g=await we("changed-files",{commits:p.map(y=>y.commit||null),includeEntries:!0,includeFiles:!0});u!==oe||n.zoom.mode!=="history"||(n.historyCommit=r,n.historyPanels=p,n.historyFocus=p.at(-1).id,n.historyPath=null,n.historyChangedFiles=new Set(g.paths),n.historyFiles=g.files,n.tour.files=g.files,Un(),n.activeTourFilePath=null,pe(),se({...sn(p.map(y=>y.label),g.entries),history:Tt(Rr(n.historyEntries,r,{}),p.map(y=>y.commit),r)}),Ge(g.paths.length?"":"No changed files for the selected revisions."),dt(),Se())}function Rr(r,a,u){let d=r.findIndex(g=>g.commit===a),p=r[d];return{fileName:(n.historyPath||u.path||"Changed files").split("/").pop(),canGoBack:d>=0&&d<r.length-1,canGoForward:d>0,positionLabel:`${d+1} / ${r.length}`,leftCommitLabel:n.historyPanels[0]?.commit?.slice(0,7)||"Empty tree",leftTimestamp:"",rightCommitLabel:n.historyPanels.at(-1)?.label||(p?`${p.shortCommit} ${p.summary}`.trim():a.slice(0,7)),rightTimestamp:p?.timestamp||"",workingTreeControls:!1,rail:{activeTabId:"history",tabs:[{id:"history",label:"History"}],itemsByTab:{history:[]}}}}function Kt(r,a){let u=$n(),d=u.indexOf(r.commit);if(d<0)return null;let p=new Set(n.historyPanels.map(b=>b.commit)),y=(a==="left"?u.slice(0,d).reverse():u.slice(d+1)).find(b=>!p.has(b)&&n.historyEntries.some(E=>E.commit===b));return n.historyEntries.find(b=>b.commit===y)}function Tt(r,a,u){return r.rail.itemsByTab.history=po(n.historyEntries,{displayed:a,active:u,selected:n.comparisonDraftCommits,tourCommits:new Set(n.authoredTour?.commits.map(d=>d.oid)),selectionEnabled:!!n.zoom,missingRevisionSelectionEnabled:!!n.zoom,missingRevisionLabel:d=>d?`${d.slice(0,7)} \xB7 Parent/base revision`:"Empty tree"}).map(d=>({...d,meta:d.parents.length>1?`${d.meta} \xB7 Merge: ${d.parents.map(p=>p.slice(0,7)).join(", ")}`:d.meta})),r}async function Wt(){let r=n.historyPanels,a=n.authoredTour,u=oe,d=await we("changed-files",{commits:r.map(y=>y.commit||null),includeFiles:!0});if(u!==oe||r!==n.historyPanels||a!==n.authoredTour||n.zoom.mode!=="history")return;n.historyChangedFiles=new Set(d.paths),n.historyFiles=d.files,n.tour.files=d.files,Un();let p=n.historyPanels.map(y=>({...y,addLeftEnabled:!!Kt(y,"left"),addRightEnabled:!!Kt(y,"right"),removeEnabled:n.historyPanels.length>2})),g=p.find(y=>y.id===n.historyFocus)?.commit;n.activeTourFilePath=n.historyPath,pe(),se({...an({panels:p,files:Xt(),activePanelId:n.historyFocus,mutationEnabled:!0,canReturnToDirectory:!0},(y,b)=>ke(y.content,b.content)),history:Tt(Rr(n.historyEntries,n.historyCommit,n.historyDiff),p.map(y=>y.commit),g)})}async function qi(r){let a=n.historyPanels.find(u=>u.id===(r.anchorPanelId||r.panelId));if(a){if(r.type==="multiRemovePanel"){if(n.historyPanels.length<=2)return;++oe,n.historyPanels=n.historyPanels.filter(u=>u!==a),n.historyFocus===a.id&&(n.historyFocus=n.historyPanels.at(-1).id)}else{let u=Kt(a,r.side);if(!u)return;let d=++oe,p=await we("diff",{path:n.historyPath,commit:u.commit,head:n.authoredTour.range.headOid});if(d!==oe||n.zoom.mode!=="history")return;let g={id:`history-${u.commit}`,commit:u.commit,content:p.rightContent,label:`${u.shortCommit} ${u.summary}`,path:p.path,editable:!1};n.historyPanels.push(g);let y=$n();n.historyPanels.sort((b,E)=>y.indexOf(b.commit)-y.indexOf(E.commit)),n.historyFocus=g.id}await Wt()}}function Ln(r){let a=n.historyEntries.findIndex(d=>d.commit===n.historyCommit),u=n.historyEntries[a+r];if(u)return et(n.historyPath,u.commit,!1)}function Nn(r){let a=r.commits;return{fileName:(r.path||n.activeTourFilePath||"Comparison").split("/").pop(),canGoBack:!1,canGoForward:!1,positionLabel:`${r.commits.length} loaded panels`,leftCommitLabel:a[0]?.slice(0,7)||"",leftTimestamp:"",rightCommitLabel:a.at(-1)?.slice(0,7)||"",rightTimestamp:"",workingTreeControls:!1,rail:{activeTabId:"history",tabs:[{id:"history",label:"History"}],itemsByTab:{history:[]}}}}function Pr(r,a=null){if(!r||r.kind!=="text-diff")return!1;Ge("");let u=r.comparisonPanels;return a=a||n.comparisonFocus,n.comparisonFocus=a,n.activeTourFilePath=r.path,pe(),se({...an({panels:u,files:Xt(),activePanelId:a?`compare-${a}`:null,mutationEnabled:!1,reorderEnabled:!1,canReturnToDirectory:!0},(d,p)=>ke(d.content,p.content)),history:Tt(Nn(n.compare),n.compare.commits,a)}),Se(),!0}async function Fr(r,a=null){let u=++oe;if(!r.comparisonPanels){let d;try{d=await we("compare-many",{commits:n.compare.commits,path:r.path})}catch(y){if(u!==oe)return!1;throw y}if(u!==oe||n.zoom?.mode!=="compare")return!1;let p=n.tour.files.findIndex(y=>y.path===r.path),g=d.files.find(y=>y.path===r.path)||d.files[0];if(!g)return document.getElementById("tour-mode-status").textContent="This file is absent from the selected revisions.",!1;r={...g,path:r.path},n.tour.files[p]=r,pe(),r.kind==="omitted"&&(document.getElementById("tour-mode-status").textContent=r.reason)}return Pr(r,a)}async function Dr(r,a,u=null){r=Lr(r);let d=++oe,p=await we("compare-many",r),g=ae()?await we("changed-files",{commits:r.commits,includeFiles:!0}):null,y=new Set(g?.paths||p.files.map(P=>P.path));for(let P of p.files)P.comparisonPanels?.some(R=>y.has(R.path))&&y.add(P.path);if(d!==oe||n.zoom.mode!=="compare")return;let b=p.files;n.comparisonCommits=r.commits,n.compare={...r,files:b,inventory:g?.files,entries:p.entries,changedPaths:y},n.tour=Ct("compare"),n.activeSceneIndex=-1,n.tourFocusFilePath=null,lt(),ct(),tt();let E=n.tour.files.find(P=>P.kind==="text-diff"&&P.path===a)||b.find(P=>P.kind==="text-diff");if(le?.view==="directory")Rn();else if(E){if(!await Fr(E,u))return}else{n.activeTourFilePath=null;let P=r.commits.map(R=>({id:`compare-${R}`,commit:R,path:"No text changes",content:"",label:R.slice(0,7),editable:!1}));se({...an({panels:P,files:{paths:[],currentPath:null},mutationEnabled:!1,reorderEnabled:!1,canReturnToDirectory:!0},(R,U)=>ke(R.content,U.content)),history:Tt(Nn(r),r.commits,null)}),n.activeTourFilePath=null,le=null,pe()}document.getElementById("tour-mode-status").textContent=b.length?E?"":"Changed files cannot be displayed as text. See the file list for details.":"No changes between these revisions.",Se()}async function Ke(r){if(!ae()){Qe(De());return}n.zoomSwitching||(n.zoom.mode!=="compare"?await We("compare",r):await Dr(r,n.activeTourFilePath),Pt("commits"))}function Rn(){n.compare&&(n.activeTourFilePath=null,pe(),se(sn(n.compare.commits.map(r=>r.slice(0,7)),n.compare.entries)),Ge(n.compare.entries.length?"":"No changed files for the selected comparison."),Se())}function Pn(){return{commits:[n.authoredTour.range.mergeBaseOid,n.authoredTour.range.headOid]}}function Mr(){return n.historyEntries.find(r=>r.commit===n.historyCommit)?.path||n.historyPath}function We(r,a,u){let d=m.then(()=>Hi(r,a,u));return m=d.catch(()=>{}),d}async function Hi(r,a,u){if(!n.zoom||n.zoomSwitching||r===n.zoom.mode||!de().includes(r))return;n.zoomSwitching=!0,++oe;let d=n.zoom.mode,p;try{p=await _e(),n.zoom.depart(p),Q.stop();let g=n.zoom.enter(r,r==="history"?p:null);if(n.tourNavigatorTab=g.restore?g.location.navigatorTab||"commits":re()?"tour":"commits",n.activeSceneIndex=-1,n.activeStepIndex=0,n.narrativeParent=null,n.directoryEvidence=null,n.sceneIntroVisible=!1,n.tourFocusFilePath=null,n.tour=Ct(r),lt(),tt(),ct(),document.getElementById("tour-mode-status").textContent="",le=g.restore&&!a?g.location:null,r==="history")await et(u||(g.restore?g.location.path:null),n.historyCommit||g.location.commit);else if(r==="compare")await Dr(a||n.compare||Pn(),u||g.location.path||p.path);else if(G()[r]&&(ve(Math.max(0,g.location.sceneIndex),g.location.stepIndex,{zoomLanding:!0,showIntro:g.restore?g.location.sceneIntroVisible:!0,readingKey:g.restore?g.location.readingKey:"title"}),g.location.path&&n.activeTourFilePath!==g.location.path)){let y=n.tour.files.findIndex(b=>b.path===g.location.path);y>=0&&ft(y)}if(Se(),l&&!s){let y=new URL(window.location.href);y.hash=re()?nt(n.zoom.mode,pt(_.find(b=>b.key===n.readingKey))):"",window.history.replaceState(null,"",y)}}catch(g){le=null,n.zoom.enter(d),n.tour=Ct(d),p&&(n.activeSceneIndex=p.sceneIndex,n.activeStepIndex=p.stepIndex,n.activeTourFilePath=p.path,n.narrativeParent=p.narrativeParent,n.sceneIntroVisible=p.sceneIntroVisible,n.tourNavigatorTab=p.navigatorTab),lt(),ct(),tt(),p&&re()&&(le=p,ve(p.sceneIndex,p.stepIndex,{zoomLanding:!0,showIntro:p.sceneIntroVisible,readingKey:p.readingKey}),p.path&&n.activeTourFilePath!==p.path&&ft(n.tour.files.findIndex(y=>y.path===p.path))),pe(),Se(),fe(g)}finally{n.zoomSwitching=!1}}async function _i(r){if(!(!r||typeof r!="object")){if(r.type==="navigationState"){Te.get(r.requestId)?.(r.navigation);return}if(r.type==="renderComplete"&&n.mode==="tour"&&r.renderRequestId===ge&&Ui(n.activeTourFilePath,ge),r.type==="renderComplete"&&le&&r.renderRequestId===Pe){let a=le;le=null,se({type:"restoreNavigationState",navigation:a.navigation});let u=document.getElementById("tour-narrative-content");u&&(u.scrollTop=a.narrativeScroll||0,X=u.scrollTop),a.focusId&&document.getElementById(a.focusId)?.focus({preventScroll:!0})}if(r.type==="ready"){let a=new URLSearchParams(window.location.search),u=a.get("manifest");u||o?Hr(u):a.get("demo")==="1"&&co();return}if(n.mode==="tour"&&n.directoryEvidence&&re()){if(r.type==="openDirectoryEntry"){qn(r.relativePath);return}if(r.type==="returnToDirectory"){zn();return}}if(n.mode==="tour"){if(n.zoom?.mode==="compare"&&["openDirectoryEntry","returnToDirectory"].includes(r.type)){if(Ee(),r.type==="returnToDirectory")Rn();else{let a=n.compare.files.find(u=>u.path===r.relativePath);a?.kind==="text-diff"?Pr(a):a&&Ge(`${a.path}: ${a.reason||"This file cannot be displayed as text."}`)}return}if(r.type==="multiMovePanel")return;if(n.zoom?.mode==="history"&&["openDirectoryEntry","returnToDirectory","navigateFile"].includes(r.type)){Ee();let a=Xt();r.type==="openDirectoryEntry"&&(a.paths=[...n.historyChangedFiles]);let u=fo(r,a,!0);u&&et(u.path,n.historyCommit).catch(fe);return}if(n.zoom?.mode==="history"&&["multiAddPanel","multiRemovePanel"].includes(r.type)){qi(r).catch(fe);return}if(r.type==="multiSetActivePair"||r.type==="multiSetActivePanel"){re()&&Number.isInteger(r.pairIndex)&&(document.getElementById("file-info").textContent=Hn(n.activeTourFilePath,r.pairIndex)),n.zoom?.mode==="history"?n.historyFocus=r.type==="multiSetActivePanel"?r.panelId:n.historyPanels[r.pairIndex]?.id||n.historyFocus:n.zoom?.mode==="compare"&&(n.comparisonFocus=r.type==="multiSetActivePanel"?r.panelId.replace(/^compare-/,""):n.comparisonCommits[r.pairIndex]);return}if(r.type==="historyBack"||r.type==="historyForward"){if(n.zoom?.mode!=="history")return;let a=Ln(r.type==="historyBack"?1:-1);a&&a.catch(fe);return}if(r.type==="toggleHistorySelection"&&Number.isInteger(r.index)){let a=n.displayedPanels.map(p=>p.commit),u=r.index<0?{commit:a[-r.index-1]}:n.historyEntries[r.index];if(!u?.commit)return;let d=n.comparisonDraftCommits.includes(u.commit)?n.comparisonDraftCommits.filter(p=>p!==u.commit):[...n.comparisonDraftCommits,u.commit];n.comparisonDraftCommits=d.length>=2?Lr({commits:d}).commits:d,dt();return}if(r.type==="compareHistoryEntry"&&Number.isInteger(r.index)){let a=n.historyEntries[r.index];a?.parentCommit&&Ke({commits:[a.parentCommit,a.commit],path:n.activeTourFilePath}).catch(fe);return}if(r.type==="selectHistoryEntry"&&Number.isInteger(r.index)){let a=n.historyEntries[r.index];if(a&&n.zoom?.mode==="history"){let u=n.historyPanels.find(d=>d.commit===a.commit);u&&n.historyPath?(n.historyFocus=u.id,se({type:"focusHistoryPanel",panelId:u.id})):et(n.historyPath,a.commit,!1).catch(fe)}if(a&&n.zoom?.mode!=="history"){let u=n.displayedPanels.find(d=>d.commit===a.commit);u?se({type:"focusHistoryPanel",panelId:u.id}):(n.historyCommit=a.commit,n.historyPath=n.activeTourFilePath||n.historyPath,We("history",void 0,n.activeTourFilePath).catch(fe))}return}}if(r.type==="navigateFile"&&n.mode==="tour"){Xr(r.direction==="previous"?-1:1);return}if(r.type==="navigateTourStep"&&n.mode==="tour"){let a=r.sceneIndex,u=r.stepIndex;Number.isInteger(a)&&Number.isInteger(u)&&ve(a,u,{userNavigation:!0,showIntro:!1});return}r.type==="recomputeDiff"&&n.mode==="diff"&&n.left&&n.right&&(n.left.content=r.leftContent,n.right.content=r.rightContent,se({type:"showDiff",file1:n.left.name,file2:n.right.name,comparisonId:`web-${n.comparisonId}`,leftContent:n.left.content,rightContent:n.right.content,diffModel:ke(n.left.content,n.right.content),history:null}))}}function ji(){let r=(T,W)=>document.getElementById(T)?.addEventListener("click",()=>{Promise.resolve().then(W).catch(fe)});for(let T of["explain","question"])r(`tour-feedback-${T}`,()=>{if(!re())return;let W=_.find(Z=>Z.key===n.readingKey);W&&$i(T,()=>Ci(n.tour,W,{mode:n.zoom?.mode||"historical",location:no(pt(W)),imageVisible:t.isVisible(),displayedEvidence:document.body.classList.contains("tour-discussion")||t.isVisible()?null:Ie?.tour===n.tour?Ie.context:null}))});let a=[...document.querySelectorAll(".tour-selection-more")],u=(T,W=!1)=>{T.open=!1,W&&T.querySelector("summary").focus()};for(let T of a)T.addEventListener("click",W=>{W.target.closest("button")&&u(T,!0)});document.addEventListener("click",T=>{for(let W of a)W.open&&!W.contains(T.target)&&u(W)}),document.addEventListener("keydown",T=>{if(T.key==="Escape")for(let W of a)W.open&&(T.preventDefault(),u(W,!0))}),r("tour-history-compare",()=>Ke({commits:n.comparisonDraftCommits})),r("tour-compare-apply",()=>Ke({commits:n.comparisonDraftCommits,path:n.compare?.path})),r("tour-history-parent",()=>{let T=n.historyEntries.find(W=>W.commit===n.historyCommit)?.parentCommit;if(!T){fe("This is the first commit; History already shows its comparison with the empty tree.");return}return Ke({commits:[T,n.historyCommit],path:Mr()})}),r("tour-history-base",()=>Ke({commits:[n.authoredTour.range.mergeBaseOid,n.historyCommit],path:Mr()})),r("tour-history-final",()=>Ke(Pn())),r("tour-compare-final",()=>Ke(Pn())),r("tour-compare-all",()=>Ke({commits:n.compare.commits}));let d=T=>{n.comparisonDraftCommits=T.filter(Boolean),dt(),se({type:"updateHistorySelection",commits:n.comparisonDraftCommits})};for(let T of["history","compare"])r(`tour-${T}-clear`,()=>d([])),r(`tour-${T}-reset`,()=>d(An()));for(let T of["wheel","pointerdown","keydown"])document.addEventListener(T,W=>{!W.isTrusted||W.target?.closest?.("#tour-mode-controls")||W.target?.closest?.(".monaco-editor, .diff-toolbar, #tour-narrative")&&Ee()},{capture:!0,passive:!0});let p=document.getElementById("web-compare-test"),g=document.getElementById("web-open-diff"),y=document.getElementById("web-open-diff3"),b=document.getElementById("web-diff-input"),E=document.getElementById("web-diff3-input"),P=document.getElementById("tour-narration"),R=document.getElementById("tour-return-focus"),U=document.getElementById("tour-search-input"),F=document.getElementById("tour-search-scope"),M=document.getElementById("tour-listen"),z=document.getElementById("tour-stop"),L=document.getElementById("tour-narration-skip-back"),H=document.getElementById("tour-narration-skip-ahead"),K=document.getElementById("tour-narration-voice"),q=document.getElementById("tour-narration-rate");ts(),document.getElementById("tour-show-all-files")?.addEventListener("change",T=>{re()?n.showAllTourFiles=T.target.checked:n.showAllFiles=T.target.checked,pe()}),document.getElementById("tour-files")?.addEventListener("toggle",T=>{let W=T.target;!(W instanceof HTMLDetailsElement)||!W.dataset.fileFolder||!W.isConnected||(W.open?n.collapsedFileFolders.delete(W.dataset.fileFolder):n.collapsedFileFolders.add(W.dataset.fileFolder))},!0),rs(),is(),Ki(),document.getElementById("correspondence-filter")?.addEventListener("input",Lt),document.getElementById("correspondence-context")?.addEventListener("click",()=>Gt(!0)),document.getElementById("file-symbol-context")?.addEventListener("click",()=>Gt(!!(n.activeCorrespondenceId&&!n.symbolContext))),document.getElementById("correspondence-all")?.addEventListener("change",Lt),document.getElementById("correspondence-unmatched")?.addEventListener("change",Lt),document.getElementById("tour-navigator-tabs")?.addEventListener("click",T=>{let W=T.target instanceof Element?T.target.closest("[data-tour-navigator]"):null;W?.dataset.tourNavigator&&Pt(W.dataset.tourNavigator)}),p?.addEventListener("click",()=>{co()}),g?.addEventListener("click",()=>{b.value="",b.click()}),y?.addEventListener("click",()=>{E.value="",E.click()}),b?.addEventListener("change",async()=>{let T=Array.from(b.files||[]);if(T.length!==2){Le("Select exactly 2 files for a diff.");return}await Is(T)}),E?.addEventListener("change",async()=>{let T=Array.from(E.files||[]);if(T.length<1){Le("Select one or more files.");return}await Ss(T)}),document.getElementById("tour-title")?.addEventListener("click",()=>en("tour")),document.getElementById("tour-narrative-content")?.addEventListener("scroll",vs,{passive:!0}),document.getElementById("tour-back")?.addEventListener("click",()=>Yt(-1)),document.getElementById("tour-next")?.addEventListener("click",()=>Yt(1)),P?.addEventListener("click",()=>ms()),R?.addEventListener("click",ls),document.getElementById("tour-directory-root")?.addEventListener("click",()=>{en("scene"),document.getElementById("tour-directory-root").focus({preventScroll:!0})}),U?.addEventListener("input",tt),F?.addEventListener("change",tt),M?.addEventListener("click",Or),z?.addEventListener("click",()=>Q.stop()),L?.addEventListener("click",()=>Q.skipSegment(-1)),H?.addEventListener("click",()=>Q.skipSegment(1)),K?.addEventListener("change",()=>{n.narrationVoiceURI=K.value,i.setItem(I,n.narrationVoiceURI)}),q&&(q.value=String(n.narrationRate),q.addEventListener("change",()=>{let T=Number(q.value);n.narrationRate=D.has(T)?T:1,q.value=String(n.narrationRate),i.setItem($,String(n.narrationRate))})),document.getElementById("tour-search-results")?.addEventListener("click",T=>{let W=T.target instanceof Element?T.target.closest("[data-tour-search-result]"):null;W&&es(Number(W.getAttribute("data-tour-search-result")))}),window.addEventListener("keydown",T=>{if(n.mode==="tour"&&(T.metaKey||T.ctrlKey)&&T.shiftKey&&T.key.toLocaleLowerCase()==="f"){T.preventDefault(),T.stopImmediatePropagation(),n.tourSidebarHidden&&Mn(!1),Pt("tour"),document.querySelector(".tour-search-disclosure")?.setAttribute("open",""),U?.focus(),U?.select();return}n.mode!=="tour"||T.metaKey||T.ctrlKey||T.altKey||ps(T.target)||(T.key==="PageUp"||T.key==="ArrowLeft"?(T.preventDefault(),n.zoom?.mode==="history"?Ln(1)?.catch(fe):Yt(-1)):T.key==="PageDown"||T.key==="ArrowRight"?(T.preventDefault(),n.zoom?.mode==="history"?Ln(-1)?.catch(fe):Yt(1)):n.zoom?.mode==="history"&&["ArrowUp","ArrowDown"].includes(T.key)&&(T.preventDefault(),Xr(T.key==="ArrowUp"?-1:1)))},!0),window.addEventListener("bygone:tour-command",T=>{T.detail==="toggleNarration"&&Or(),T.detail==="pauseNarration"&&Q.pauseForExternalOwner()}),window.addEventListener("beforeunload",()=>Q.dispose(),{once:!0}),Fn(Q.state)}function Ki(){let r=document.getElementById("tour-narration-voice"),a=document.getElementById("tour-listen");if(!A){a&&(a.disabled=!0,a.title="Device narration is not supported by this browser."),r&&(r.disabled=!0),$t("Device narration unavailable");return}let u=()=>{if(n.narrationVoices=window.speechSynthesis.getVoices().filter(d=>!o||d.localService).slice().sort((d,p)=>Number(p.default)-Number(d.default)||d.lang.localeCompare(p.lang)||d.name.localeCompare(p.name)),n.narrationVoiceURI&&n.narrationVoices.length>0&&!n.narrationVoices.some(d=>d.voiceURI===n.narrationVoiceURI)&&(n.narrationVoiceURI="",i.removeItem(I)),r){let d=document.createElement("option");d.value="",d.textContent="System default voice",r.replaceChildren(d,...n.narrationVoices.map(p=>{let g=document.createElement("option");return g.value=p.voiceURI,g.textContent=`${p.name} (${p.lang})${p.default?" \u2014 default":""}`,g})),r.value=n.narrationVoiceURI,r.disabled=n.narrationVoices.length===0}};u(),window.speechSynthesis.addEventListener("voiceschanged",u)}function Wi(){let r=Number(i.getItem($));return D.has(r)?r:1}function Gi(){let r=null;return{speak(a,u){if(!A){u.onError("Device narration is not supported by this browser.");return}let d=new window.SpeechSynthesisUtterance(a.speechText),p=n.narrationVoices.find(g=>g.voiceURI===n.narrationVoiceURI)||(o?n.narrationVoices[0]:null);if(o&&!p){u.onError("No local narration voice is available.");return}p&&(d.voice=p),d.rate=n.narrationRate,d.onend=()=>{r===d&&(r=null),u.onEnd()},d.onerror=g=>{r===d&&(r=null),u.onError(Vi(g.error))},r=d,window.speechSynthesis.speak(d)},pause(){A&&window.speechSynthesis.pause()},resume(){A&&window.speechSynthesis.resume()},cancel(){r=null,A&&window.speechSynthesis.cancel()}}}function Vi(r){return r==="not-allowed"?"Device narration needs permission to play audio.":r==="language-unavailable"||r==="voice-unavailable"?"The selected device voice is unavailable.":`Device narration failed${r?`: ${r}`:"."}`}function Ji(){if(!A||n.mode!=="tour")return;let r=Br("playback-start");r&&(n.renderedNarrationUnit=r,hs(r),Q.start(r,!0))}function Or(){Q.state.kind==="playing"||Q.state.kind==="paused"?Q.togglePause():Ji()}function Br(r){let a=_.find(u=>u.key===n.readingKey);return n.tour&&a?ci(n.tour,a,{entry:r}):null}function Yi(r,a){return!!(n.tour&&Ht(_,r.readingKey,a,st(n.tour)))}function Xi(r,a){if(!n.tour)return null;let u=Ht(_,r.readingKey,a,st(n.tour));return u?ve(u.sceneIndex,u.stepIndex,{readingKey:u.key,narrationNavigation:"controller",narrationEntry:"continuous"}):null}function Zi(){o||fetch("/narration/claim",{method:"POST",cache:"no-store"}).catch(()=>{})}function Fn(r){let a=document.getElementById("tour-listen"),u=document.getElementById("tour-stop"),d=document.getElementById("tour-narration-skip-back"),p=document.getElementById("tour-narration-skip-ahead");if(a){a.disabled=!A||n.mode!=="tour";let g=r.kind==="playing";a.querySelector(".tour-play-pause-icon")?.setAttribute("d",g?"M7 5h4v14H7zM13 5h4v14h-4z":"m8 5 11 7-11 7Z");let y=g?"Pause narration":r.kind==="paused"?"Resume narration":"Listen from the current tour item";a.title=y,a.setAttribute("aria-label",y),document.getElementById("tour-listen-label").textContent=g?"Pause":r.kind==="paused"?"Resume":"Listen"}if(u&&(u.disabled=r.kind!=="playing"&&r.kind!=="paused"),d&&(d.disabled=!Q.canSkipSegment(-1)),p&&(p.disabled=!Q.canSkipSegment(1)),r.kind==="playing"||r.kind==="paused"){let g=r.segmentIndex+1,y=r.unit.segments.length;$t(`${r.kind==="paused"?"Paused":"Speaking"} \xB7 segment ${g} of ${y}`)}else r.kind==="completed"?$t("Narration complete"):r.kind==="error"?$t(r.message):A&&$t("Device voice ready")}function $t(r){let a=document.getElementById("tour-narration-status");a&&(a.textContent=r)}function Qi(r,a){if(document.querySelectorAll(".tour-narration-segment.is-speaking").forEach(b=>{b.classList.remove("is-speaking","is-paused")}),!r)return;let u=[...document.querySelectorAll("[data-narration-segment-id]")].filter(b=>b.dataset.narrationSegmentId===r.id),d=u[0];if(!d||(u.forEach(b=>{b.classList.add("is-speaking"),b.classList.toggle("is-paused",a)}),a))return;let p=document.getElementById("tour-narrative-content");if(!p)return;let g=d.getBoundingClientRect(),y=p.getBoundingClientRect();(g.top<y.top+tn()||g.bottom>y.bottom)&&(d.scrollIntoView({block:"nearest"}),X=p.scrollTop)}let At=[];function tt(){let r=document.getElementById("tour-search-input"),a=document.getElementById("tour-search-scope"),u=document.getElementById("tour-search-status"),d=document.getElementById("tour-search-results");if(!(!n.tour||!r||!a||!u||!d)){if(At=li(n.tour,r.value,a.value),!r.value.trim()){u.textContent="Cmd/Ctrl+Shift+F",d.replaceChildren();return}u.textContent=`${At.length} result${At.length===1?"":"s"}`,d.replaceChildren(...At.map((p,g)=>{let y=document.createElement("button");y.type="button",y.className="tour-search-result",y.setAttribute("role","option"),y.dataset.tourSearchResult=String(g),y.title=`Open ${p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label}`;let b=document.createElement("span");b.className="tour-search-location",b.textContent=p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label;let E=document.createElement("span");return E.className="tour-search-preview",E.textContent=p.preview.trim(),y.append(b,E),y}))}}function es(r){let a=At[r];if(a){if(a.kind==="narrative"){Ee(),ve(a.sceneIndex,a.stepIndex??0,{readingKey:a.readingKey,showIntro:a.stepIndex===void 0});return}_n(a.fileIndex)&&window.requestAnimationFrame(()=>se({type:"revealSearchResult",sideIndex:a.sideIndex,lineNumber:a.lineNumber,startColumn:a.startColumn,endColumn:a.endColumn}))}}function ts(){let r=document.getElementById("tour-shell"),a=document.getElementById("tour-sidebar-resizer"),u=document.getElementById("tour-sidebar-hide"),d=document.getElementById("tour-sidebar-show");!r||!a||!u||!d||(zr(),u.addEventListener("click",()=>Mn(!0)),d.addEventListener("click",()=>Mn(!1)),a.addEventListener("pointerdown",p=>{p.preventDefault(),document.body.classList.add("is-resizing-tour-sidebar"),a.setPointerCapture?.(p.pointerId);let g=b=>Ur(b.clientX),y=()=>{document.body.classList.remove("is-resizing-tour-sidebar"),window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",y),window.removeEventListener("pointercancel",y),i.setItem(w,String(n.tourSidebarWidth))};window.addEventListener("pointermove",g),window.addEventListener("pointerup",y),window.addEventListener("pointercancel",y)}),a.addEventListener("keydown",p=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(p.key))return;p.preventDefault();let g=n.tourSidebarWidth;p.key==="Home"?g=v:p.key==="End"?g=Dn():g+=p.key==="ArrowLeft"?-16:16,Ur(g),i.setItem(w,String(n.tourSidebarWidth))}))}function ns(){let r=Number.parseInt(i.getItem(w)||"",10);return Number.isFinite(r)?Math.min(k,Math.max(v,r)):300}function Dn(){return Math.max(v,Math.min(k,Math.floor(window.innerWidth*.6)))}function Ur(r){n.tourSidebarWidth=Math.min(Dn(),Math.max(v,Math.round(r))),zr(),window.dispatchEvent(new Event("resize"))}function zr(){document.documentElement.style.setProperty("--tour-rail-width",`${n.tourSidebarWidth}px`);let r=document.getElementById("tour-sidebar-resizer");r?.setAttribute("aria-valuemax",String(Dn())),r?.setAttribute("aria-valuenow",String(n.tourSidebarWidth))}function Mn(r){n.tourSidebarHidden=r,document.body.classList.toggle("tour-sidebar-hidden",r);let a=document.getElementById("tour-sidebar-show");a&&(a.hidden=!r),window.dispatchEvent(new Event("resize"))}function rs(){let r=document.getElementById("tour-narrative-resizer");r&&(Bn(),r.addEventListener("pointerdown",a=>{if(a.button!==0)return;a.preventDefault(),document.body.classList.add("is-resizing-tour-narrative"),r.setPointerCapture?.(a.pointerId),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-start"));let u=document.getElementById("tour-narrative").getBoundingClientRect().top,d=g=>qr(g.clientY-u),p=()=>{document.body.classList.remove("is-resizing-tour-narrative"),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",p),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-end")),i.setItem(x,String(n.tourNarrativeHeight))};window.addEventListener("pointermove",d),window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p)}),r.addEventListener("keydown",a=>{if(!["ArrowUp","ArrowDown","Home","End"].includes(a.key))return;a.preventDefault();let u=a.key==="Home"?C:a.key==="End"?On():n.tourNarrativeHeight+(a.key==="ArrowUp"?-16:16);qr(u),i.setItem(x,String(n.tourNarrativeHeight))}),window.addEventListener("resize",Bn))}function os(){let r=Number.parseInt(i.getItem(x)||"",10);return Number.isFinite(r)?r:Math.min(window.innerHeight*.38,360)}function On(){return Math.max(C,window.innerHeight-document.getElementById("tour-mode-controls").offsetHeight-S)}function qr(r){n.tourNarrativeHeight=r,Bn()}function Bn(){n.tourNarrativeHeight=Math.min(On(),Math.max(C,Math.round(n.tourNarrativeHeight))),document.getElementById("tour-narrative").style.height=`${n.tourNarrativeHeight}px`;let r=document.getElementById("tour-narrative-resizer");r?.setAttribute("aria-valuemax",String(On())),r?.setAttribute("aria-valuenow",String(n.tourNarrativeHeight)),r&&(r.style.top=`calc(var(--workspace-toolbar-height, 0px) + ${n.tourNarrativeHeight-4}px)`)}function is(){let r=document.getElementById("tour-narrative");if(!r)return;let a=()=>{let u=r.hidden?0:Math.ceil(r.getBoundingClientRect().height);document.documentElement.style.setProperty("--tour-narrative-height",`${u}px`),so(),tn(),window.dispatchEvent(new Event("resize"))};new ResizeObserver(a).observe(r),a()}async function Hr(r){Le("Loading change tour\u2026");let a=Ri(r),u={...n,historyEntries:[...n.historyEntries],fileHistoryCache:new Map(n.fileHistoryCache),displayedPanels:[...n.displayedPanels],historyPanels:[...n.historyPanels],comparisonCommits:[...n.comparisonCommits],comparisonDraftCommits:[...n.comparisonDraftCommits]},d=document.body.className,p=document.getElementById("tour-shell")?.hidden,g=document.getElementById("tour-narrative")?.hidden,y=document.getElementById("tour-mode-controls")?.hidden,b=ge,E=le,P=Pe,R=oe;try{Q.stop();let U=o?.manifest;if(!o){let W=await fetch(r,{cache:"no-store"});if(!W.ok)throw new Error(`Manifest request failed (${W.status}).`);U=await W.json()}let F=ei(U,{exported:!!o}),M=null;if(!o&&new URLSearchParams(window.location.search).has("correspondence")&&r==="/tour.json"){let W=await fetch("/correspondence.json",{cache:"no-store"});if(!W.ok)throw new Error(`Correspondence request failed (${W.status}).`);if(M=await W.json(),M.range.baseOid!==F.range.mergeBaseOid||M.range.headOid!==F.range.headOid)throw new Error("Correspondence revisions do not match this view.")}let z=Qn(window.location.hash);z&&Zn(F,z.mode,z.focus);let H=G(F).deconstructed?"deconstructed":"historical",K=ae(F)?(await we("list",{commit:F.range.headOid},a,F)).entries:[];n.tour=F,n.correspondence=M,n.collapsedSymbolNodes=new Set,n.activeCorrespondenceId=null,n.symbolSelection=null,n.expandedFileSymbols.clear(),document.getElementById("file-symbol-context").hidden=!0,document.getElementById("correspondence-context").hidden=!0,n.authoredTour=F,n.historyPrefix=a,n.zoom=new En(H),n.historyEntries=K,n.historyCommit=null,n.historyPath=null,n.historyPanels=[],n.historyFocus=null,n.historyDiff=null,n.historyChangedFiles=new Set,n.historyFiles=null,n.showAllFiles=!1,n.showAllTourFiles=!1,n.collapsedFileFolders=new Set,n.revealedFilePath=null,n.zoom&&(n.tour=Ct(H)),n.mode="tour",document.body.classList.add("tour-mode"),lt(),ct(),tt();let q=new URLSearchParams(window.location.search),T=xr(n.tour.scenes,q.get("scene"),q.get("step"));if(ve(T.sceneIndex,T.stepIndex,{showIntro:q.get("view")==="overview"||!q.get("step"),readingKey:!q.get("scene")&&!q.get("step")?"title":void 0}),["tour","chapter","conclusion"].includes(q.get("view"))&&en(q.get("view")),n.zoom){let Z={explanation:"deconstructed",revisions:"historical",final:Fe()?"historical":"compare"}[q.get("mode")]||q.get("mode");if(Z==="history"&&de().includes("history"))n.historyPath=q.get("file"),n.tourNavigatorTab="commits",n.zoom.enter("history"),n.tour=Ct("history"),lt(),ct(),await et(n.historyPath,q.get("commit"));else if(Z==="compare"&&de().includes("compare")){let ue=q.get("commits")?.split(",").filter(Boolean);await We("compare",{commits:ue?.length?ue:[q.get("from")||n.authoredTour.range.mergeBaseOid,q.get("to")||n.authoredTour.range.headOid],...q.get("scope")?{path:q.get("scope")}:{}},q.get("file")),q.get("view")==="directory"&&Rn()}else if(Z&&Z!==n.zoom.mode&&de().includes(Z)){await We(Z);let ue=xr(n.tour.scenes,q.get("scene"),q.get("step"));ve(ue.sceneIndex,ue.stepIndex,{showIntro:q.get("view")==="overview"||!q.get("step"),readingKey:!q.get("scene")&&!q.get("step")?"title":void 0}),["tour","chapter","conclusion"].includes(q.get("view"))&&en(q.get("view"))}let ie=He;He=null,ce&&ie&&ie!==n.zoom.mode&&de().includes(ie)&&await We(ie)}return n.directoryEvidence&&q.get("file")&&qn(q.get("file")),Fn(Q.state),n.workspacePromptStatus="",be(),Le(""),z?await ro(z):re()&&window.history.replaceState(null,"",nt(n.zoom.mode,pt(_.find(W=>W.key===n.readingKey)))),document.getElementById("export-loading")?.remove(),window.__BYGONE_EXPORT_READY__=!!o,l=!0,!0}catch(U){let F=document.getElementById("export-loading");F&&(F.textContent=`Could not open export: ${U.message}`),Object.assign(n,u),ge=b,le=E,Pe=P,oe=R,document.body.className=d;let M=document.getElementById("tour-shell");M&&p!==void 0&&(M.hidden=p);let z=document.getElementById("tour-narrative");z&&g!==void 0&&(z.hidden=g);let L=document.getElementById("tour-mode-controls");return L&&y!==void 0&&(L.hidden=y),n.mode==="tour"&&n.tour&&(lt(),ct(),tt(),be()),Le(`Could not load change tour: ${U instanceof Error?U.message:String(U)}`),!1}}function lt(){Zt();let r=n.tour;if(!r)return;let a=document.getElementById("tour-shell"),u=document.getElementById("tour-title"),d=document.getElementById("tour-source"),p=document.getElementById("tour-range"),g=document.getElementById("tour-stats"),y=document.getElementById("tour-authoring-coverage"),b=document.getElementById("tour-scenes"),E=document.getElementById("tour-scene-count"),P=document.getElementById("tour-files"),R=document.getElementById("tour-file-count");if(!a||!u||!d||!p||!g||!y||!b||!E||!P||!R)throw new Error("Presenter UI is incomplete.");a.hidden=!1,u.textContent=r.title,document.title=pi(r),r.sourceUrl?(d.href=r.sourceUrl,d.hidden=!1):(d.removeAttribute("href"),d.hidden=!0);let U=Qr(r.range.baseRef),F=Qr(r.range.headRef),M=r.range.headOid.slice(0,7);if(p.textContent=`${re()?"Tour range: ":""}${U} \u2192 ${F}${F===M?"":` \xB7 ${M}`}`,g.textContent=`${Dt(r.summary.changedFiles,"file")} \xB7 +${r.summary.additions} \u2212${r.summary.deletions} \xB7 ${Dt(r.summary.commitCount,"commit")}`,cs(y,r.authoringCoverage),Si(document.getElementById("tour-audience"),re()?r:null),E.textContent=re()&&r.scenes.length?String(r.scenes.length):"",R.textContent=String(r.files.length),b.replaceChildren(),re()){Wn();let L=Ve("Intro","Read the introduction and tour route",()=>Ae(_.find(H=>H.kind==="title")));L.className="tour-scene",L.dataset.readingLink="title",b.append(L)}let z=new Map(r.scenes.map(L=>[L.id,L]));for(let L of r.chapters){let H=eo(`chapter:${L.id}`,`${r.chapters.indexOf(L)+1}. ${L.title}`,"tour-chapter-link",()=>{let q=_.find(T=>T.kind==="chapter"&&T.chapterId===L.id)||_.find(T=>T.kind==="scene"&&L.sceneIds.includes(r.scenes[T.sceneIndex]?.id));q&&Ae(q)}),K=H.children;b.append(H.group);for(let q of L.sceneIds){let T=z.get(q);if(!T)continue;let W=r.scenes.indexOf(T),Z=eo(`scene:${T.id}`,T.title,"tour-scene",()=>ve(W,0,{userNavigation:!0,showIntro:!0})),ie=Z.link;ie.replaceChildren(),ie.dataset.sceneId=T.id,T.kind==="text-diff"&&(ie.dataset.filePath=T.path),Z.link.title=`Open scene: ${T.kind==="text-diff"?T.path:T.title}`;let ue=document.createElement("span");ue.className="tour-scene-copy";for(let[ye,xe]of[["tour-scene-title",`${W+1}. ${T.title}`],["tour-scene-path",T.kind==="text-diff"?T.path:T.kind==="deconstructed-diff"?`${Dt(T.panels.length-1,"comparison stage")} \xB7 ${Dt(T.steps.length,"tour slide")}`:$e(T)?Dt(T.steps.length,T.steps.every(Oe=>Oe.image)?"image":"step"):"Discussion"],["tour-scene-note",T.takeaway]]){let Oe=document.createElement("span");Oe.className=ye,Oe.textContent=xe,ue.append(Oe)}if(ie.append(ue),K.append(Z.group),$e(T)){let ye=Z.children;ye.classList.add("tour-outline-steps"),ye.dataset.sceneId=T.id,T.steps.forEach((xe,Oe)=>{let Je=document.createElement("button");Je.type="button",Je.className="tour-outline-step",Je.dataset.sceneId=T.id,Je.dataset.stepIndex=String(Oe);let Cs=T.kind==="deconstructed-diff"?`Stage ${(xe.stageIndex??xe.pairIndex)+1}: `:"";Je.textContent=`${Oe+1}. ${xe.title}`,Je.title=`${Cs}${xe.title}`,Je.addEventListener("click",()=>ve(W,Oe,{userNavigation:!0,showIntro:!1})),ye.append(Je)})}else Z.toggle.hidden=!0}}if(re()&&r.conclusion){let L=Ve("Conclusion",`Read ${r.conclusion.title}`,()=>Ae(_.find(H=>H.kind==="conclusion")));L.className="tour-scene",L.dataset.readingLink="conclusion",b.append(L)}Un(),Lt(),Pt(n.tourNavigatorTab)}function Lt(){let r=n.correspondence;document.getElementById("correspondence-tab").hidden=!r;let a=document.getElementById("correspondence-list");if(a.replaceChildren(),!r)return;let u=document.getElementById("correspondence-filter").value.toLowerCase(),d=document.getElementById("correspondence-all").checked,p=document.getElementById("correspondence-unmatched")?.checked??!0,g=$r(r,{all:d,includeUnmatched:p,query:u});if(document.getElementById("correspondence-status").textContent=`${r.range.baseOid.slice(0,7)} \u2192 ${r.range.headOid.slice(0,7)} \xB7 ${r.status} analysis \xB7 ${g.matchingRelations} of ${r.relations.length} inferred mappings \xB7 ${g.matchingUnmatched} unmatched symbols \xB7 ${r.unresolved.length} ambiguous groups. Behavior unassessed.`,jr(a,g.files),_r(g),!g.files.length){let y=document.createElement("p");y.className="history-rail-empty",y.textContent=u.trim()?"No symbols match this filter.":"No symbols match the current filters. Enable the include options to see more inventoried declarations.",a.append(y)}as(r)}function _r(r=$r(n.correspondence,{all:document.getElementById("correspondence-all").checked,includeUnmatched:document.getElementById("correspondence-unmatched")?.checked??!0,query:document.getElementById("correspondence-filter").value})){document.querySelectorAll("#tour-files .file-symbols, #tour-files .file-symbol-toggle").forEach(a=>a.remove());for(let a of document.querySelectorAll("#tour-files .tour-file")){a.parentElement.classList.remove("has-file-symbols");let u=n.tour.files.find(E=>E.path===a.dataset.filePath),d=r.files.filter(E=>E.path===u?.path||E.path===u?.previousPath),p=d.length?{path:u.path,children:d.flatMap(E=>E.children)}:null;if(!p?.children.length)continue;let g=document.createElement("div");g.className="file-symbols",g.id=`file-symbols-${++Xe}`,jr(g,p.children);let y=document.createElement("button");y.type="button",y.className="file-symbol-toggle",y.setAttribute("aria-controls",g.id);let b=()=>{let E=n.expandedFileSymbols.has(p.path);g.hidden=!E,y.setAttribute("aria-expanded",String(E)),y.dataset.tooltip=E?"Hide Symbols":"Show Symbols",y.setAttribute("aria-label",`${y.dataset.tooltip}: ${p.path}`),y.textContent=E?"\u25BE":"\u25B8"};y.addEventListener("click",()=>{n.expandedFileSymbols.has(p.path)?n.expandedFileSymbols.delete(p.path):n.expandedFileSymbols.add(p.path),b()}),b(),a.parentElement.classList.add("has-file-symbols"),a.parentElement.append(y,g)}}function jr(r,a){let u=n.correspondence,d=document.getElementById("correspondence-filter").value,p=++Xe,g=document.createElement("ul");g.className="correspondence-tree",r.append(g);let y=a.map(b=>({node:b,parent:g})).reverse();for(;y.length;){let{node:b,parent:E}=y.pop(),P=document.createElement("li");P.dataset.symbolKey=b.key,P.classList.toggle("is-context",b.type==="symbol"&&b.context);let R=document.createElement("div");R.className="correspondence-heading";let U=document.createElement("ul");U.id=`symbols-${p}-${encodeURIComponent(b.key)}`;let F=document.createElement("button");F.type="button",F.className="correspondence-toggle";let M=b.type==="file"?b.path:b.entry.name,z=()=>{F.setAttribute("aria-expanded",String(!U.hidden)),F.setAttribute("aria-label",`${U.hidden?"Expand":"Collapse"} ${M}`),F.textContent=U.hidden?"\u25B8":"\u25BE"};if(U.hidden=!d.trim()&&n.collapsedSymbolNodes.has(b.key),F.setAttribute("aria-controls",U.id),F.addEventListener("click",()=>{U.hidden=!U.hidden,U.hidden?n.collapsedSymbolNodes.add(b.key):n.collapsedSymbolNodes.delete(b.key),z()}),z(),F.hidden=!b.children.length,R.append(F),P.append(R),b.type==="file"){P.classList.add("correspondence-file");let L=document.createElement("button");L.type="button",L.className="correspondence-file-label",L.textContent=b.path,L.title=b.path,L.setAttribute("aria-current",String(n.activeTourFilePath===b.path)),L.addEventListener("click",()=>{let H=n.tour.files.findIndex(K=>K.path===b.path||K.previousPath===b.path);H>=0&&ft(H)}),R.append(L)}else{let{before:L,after:H,relation:K}=b,q=document.createElement("button");q.type="button",q.className="correspondence-item";let T=K?.id||b.key;q.dataset.correspondenceId=T,q.dataset.sourceReference=String(!!b.sourceReference),q.dataset.changeKind=K?b.changed?"modified":"unchanged":b.ambiguous?"ambiguous":b.side==="before"?"deleted":"added",q.classList.toggle("is-relocated",!!b.sourceReference||!!K?.pathChanged),q.setAttribute("aria-pressed",String(n.activeCorrespondenceId===T));let W=xe=>`${xe.path}:${xe.startLine}`;q.title=K?`Compare ${W(L)} with ${W(H)}`:`Inspect ${W(b.entry)} \xB7 no accepted match`;let Z=document.createElement("strong");Z.textContent=L&&H&&L.name!==H.name?`${L.name} \u2192 ${H.name}`:b.entry.name;let ie=document.createElement("span");ie.textContent=K?`${W(L)} \u2192 ${W(H)}`:`${W(b.entry)} \xB7 ${b.side==="before"?"base":"head"}`,ie.className="correspondence-location";let ue=document.createElement("span"),ye=K?[b.sourceReference?"Before location":"",K.pathChanged?"Moved":"",K.nameChanged?"Renamed":"",K.rawEqual?"":"Edited",b.changed&&!K.pathChanged&&!K.nameChanged&&K.rawEqual?"Reparented":""].filter(Boolean):[b.side==="before"?"Before only":"After only",b.ambiguous?"Ambiguous":"Unmatched"];ue.textContent=`${b.entry.kind} \xB7 ${ye.join(" \xB7 ")||"Unchanged text"}${b.context?" \xB7 ancestor context":""}`,q.append(Z,ie,ue),q.addEventListener("click",()=>{Ee(),oe+=1,document.body.classList.remove("tour-discussion"),Ie=null,Q.interruptForExploration(),n.directoryEvidence=null,n.symbolSelection={before:L,after:H,relation:K,ambiguous:b.ambiguous,side:b.side,entry:b.entry,id:T,range:u.range},Gt(!1),r.querySelectorAll(".correspondence-item").forEach(xe=>xe.setAttribute("aria-pressed",String(xe.dataset.correspondenceId===T)))}),R.append(q)}E.append(P),b.children.length&&(P.append(U),y.push(...b.children.map(L=>({node:L,parent:U})).reverse()))}}function Gt(r=!1){let a=n.symbolSelection;if(!a)return;let{before:u,after:d,relation:p,range:g}=a,y=(F,M)=>F?r?n.correspondence?.documents[M].find(z=>z.path===F.path)?.text??a.context?.[M==="before"?"leftContent":"rightContent"]??null:F.text:"",b=y(u,"before"),E=y(d,"after");if(b===null||E===null){document.getElementById("correspondence-selection").textContent="Full file context is unavailable in this older artifact. Rebuild the correspondence artifact to include it.";return}++ge,t.clear(),n.displayedPanels=[],n.activeCorrespondenceId=a.id,n.activeTourFilePath=d?.path||u?.path,n.symbolContext=r,document.getElementById("correspondence-context").hidden=r,document.getElementById("file-symbol-context").hidden=!1,document.getElementById("file-symbol-context").textContent=r?"Return to symbol comparison":"Show file context",document.getElementById("correspondence-selection").textContent=p?`${u.name}: inferred correspondence \xB7 behavior unassessed. ${r?"Complete source and destination files; declarations highlighted.":`Complete declarations; line 1 starts at source lines ${u.startLine} / ${d.startLine}.`}`:`${a.entry.name}: ${a.ambiguous?"ambiguous":"unmatched"} ${a.side} symbol. The empty side does not establish an addition or deletion.`;let P=r?[[u,"left"],[d,"right"]].filter(([F])=>F).map(([F,M])=>({side:M,startLine:F.startLine,endLine:F.endLine,label:F.name,active:!0})):[],R=F=>F?`${F.path}:${F.startLine}`:"No accepted match",U=ke(b,E);se({type:"showDiff",file1:`${R(u)} @ ${g.baseOid.slice(0,7)}`,file2:`${R(d)} @ ${g.headOid.slice(0,7)}`,sourceInfo:{leftPath:u?.path||a.entry.path,rightPath:d?.path||a.entry.path},comparisonId:`correspondence-${a.id}-${r?"file":"symbol"}`,leftContent:b,rightContent:E,diffModel:U,history:null,correspondenceView:!0,editableSides:{left:!1,right:!1},tourAnnotations:P,initialChangeIndex:r?Kn(U,d?"right":"left",(d||u).startLine):0,comparisonSummary:p?"Inferred symbol correspondence \xB7 behavior unassessed":"No accepted symbol match \xB7 addition/deletion unassessed"}),pe(),document.querySelectorAll(".correspondence-item").forEach(F=>F.setAttribute("aria-pressed",String(F.dataset.correspondenceId===a.id))),r&&Pt("files")}function ss(r){document.getElementById("correspondence-filter").value="",document.getElementById("correspondence-all").checked=!0;let a=document.getElementById("correspondence-unmatched");a&&(a.checked=!0),Lt();let u=n.correspondence.relations.find(y=>y.sourceId===r||y.destinationId===r),d=[...document.querySelectorAll("#correspondence-list .correspondence-item")],p=d.find(y=>y.parentElement.parentElement.dataset.symbolKey===`after:${r}`||y.parentElement.parentElement.dataset.symbolKey===`before:${r}`)||d.find(y=>y.dataset.correspondenceId===u?.id);if(!p)return;let g=p.closest("li").parentElement;for(;g?.closest("#correspondence-list");)g.tagName==="UL"&&g.hidden&&g.previousElementSibling?.querySelector(".correspondence-toggle")?.click(),g=g.parentElement;p.click(),p.focus(),p.scrollIntoView({block:"nearest"})}function as(r){let a=document.getElementById("correspondence-limitations"),u=new Set([...a.querySelectorAll("details[open]")].map(b=>b.dataset.diagnosticCategory));a.replaceChildren();let d=(b,E)=>{let P=document.createElement("p");P.textContent=E,b.append(P)},p=new Map([...r.symbols.before,...r.symbols.after].map(b=>[b.id,b]));d(a,"Categories overlap and use different units. Rejected records are not missing functions; these counts do not measure coverage."),r.diagnostics||d(a,"Detailed diagnostics unavailable. This older artifact retains summaries and inventoried symbols only.");for(let b of r.diagnostics?.scope||[])d(a,b);for(let b of Ai(r)){let E=document.createElement("details");E.dataset.diagnosticCategory=b.category,E.open=u.has(b.category);let P=document.createElement("summary");P.textContent=`${b.title} \xB7 ${b.count}`,E.append(P),d(E,b.description);let R=document.createElement("ul");R.className="correspondence-diagnostics";for(let U of b.records){let F=document.createElement("li");d(F,Ar(U.reason));let M=document.createElement("code");M.textContent=U.reason,F.append(M),U.producerId&&d(F,`Engine record: ${U.producerId}`),U.message&&d(F,U.message);for(let z of U.locations){let L=p.get(z.symbolId),H=n.tour?.files.find(T=>T.path===z.path&&T.kind==="text-diff"),K=`${z.side?`${z.side} @ ${(z.side==="before"?r.range.baseOid:r.range.headOid).slice(0,7)} \xB7 `:"changed path \xB7 "}${z.path}${z.line?`:${z.line}`:""}${L?` (${L.name})`:""}`,q=document.createElement(L||H?"button":"span");if(q.textContent=K,q.className="correspondence-diagnostic-location",L||H?(q.type="button",q.title=L?"Inspect symbol (enables both include options and clears search)":"Inspect complete file context",q.addEventListener("click",()=>{if(L)return ss(L.id);Ee(),oe+=1,Q.interruptForExploration(),n.directoryEvidence=null,n.activeCorrespondenceId=null,ut(H,[],Jt(H.path),null,z.line&&z.side?{revision:z.side==="before"?"base":"head",startLine:z.line}:null),document.getElementById("correspondence-selection").textContent=`Complete file context: ${K}`,document.querySelectorAll(".correspondence-item").forEach(T=>T.setAttribute("aria-pressed","false"))})):q.title="File context is not available in this comparison.",F.append(q),z.reason){d(F,Ar(z.reason));let T=document.createElement("code");T.textContent=z.reason,F.append(T)}}R.append(F)}b.records.length&&E.append(R),a.append(E)}let g=document.createElement("details"),y=document.createElement("summary");y.textContent="Analysis summaries and provenance",g.append(y);for(let b of r.limitations)d(g,b);a.append(g)}function Un(){let r=n.tour,a=document.getElementById("tour-files");document.getElementById("tour-file-count").textContent=String(r.files.length),a.replaceChildren(Kr(Ii(r.files,d=>d.path),(d,p,g)=>{let y=document.createElement("button");y.type="button",y.className=`tour-file${d.kind==="omitted"?" is-omitted":""}`,y.dataset.filePath=d.path,y.disabled=d.kind==="omitted",y.title=d.kind==="omitted"?`${d.path}: ${d.reason}`:`Open file: ${d.path}`,d.kind==="text-diff"&&y.addEventListener("click",()=>ft(p));let b=document.createElement("span");b.className="tour-file-marker",b.textContent=d.kind==="omitted"?"\xD7":jn(d.changeKind);let E=document.createElement("span");E.className="tour-file-copy";let P=document.createElement("span");P.className="tour-file-path",P.textContent=g;let R=document.createElement("span");return R.className="tour-file-meta",R.textContent=d.kind==="omitted"?`Not rendered \xB7 ${d.reason}`:Number.isFinite(d.additions)?`${Qt(d.changeKind)} \xB7 +${d.additions} \u2212${d.deletions}`:Qt(d.changeKind),E.append(P,R),y.append(b,E),y}));let u=document.createElement("div");u.className="history-rail-empty",u.dataset.fileTreeEmpty="",a.append(u),n.correspondence&&_r(),pe()}function Kr(r,a){let u=document.createElement("ul");u.className="file-tree";for(let d of r.folders){let p=document.createElement("li"),g=document.createElement("details");g.dataset.fileFolder=d.path,g.open=!n.collapsedFileFolders.has(d.path);let y=document.createElement("summary"),b=document.createElement("span");b.className="tour-file-path",b.textContent=d.name,y.append(b),y.title=d.path,g.append(y,Kr(d,a)),p.append(g),u.append(p)}for(let{item:d,index:p,name:g}of r.files){let y=document.createElement("li");y.append(a(d,p,g)),u.append(y)}return u}function cs(r,a){if(r.replaceChildren(),r.hidden=!a,!a)return;let u=[{metric:"walkthrough",label:"Anchored diff hunks",covered:a.walkthrough.coveredUnits,total:a.walkthrough.includedUnits,percent:a.walkthrough.coveragePercent,description:"Distinct change hunks referenced by authored base/head focus anchors. Revision-stack steps are not counted."},...a.explanationAssignments.map(d=>({metric:"assignment",label:a.explanationAssignments.length>1?`Deconstructed assignment \xB7 ${d.sceneId}`:"Deconstructed assignment",covered:d.completeUnits,total:d.totalUnits,percent:d.assignmentPercent,description:`${d.assignedUnits} assigned, ${d.excludedUnits} explicitly excluded.`}))];for(let d of u){let p=document.createElement("div");p.className="tour-coverage-item",p.dataset.metric=d.metric,p.dataset.tooltip=d.description,p.tabIndex=0,p.setAttribute("aria-description",d.description);let g=document.createElement("div");g.className="tour-coverage-heading";let y=document.createElement("span");y.textContent=d.label;let b=document.createElement("strong");b.textContent=`${d.covered}/${d.total} \xB7 ${d.percent}%`,g.append(y,b);let E=document.createElement("div");E.className="tour-coverage-meter",E.setAttribute("role","progressbar"),E.setAttribute("aria-label",d.label),E.setAttribute("aria-valuemin","0"),E.setAttribute("aria-valuemax","100"),E.setAttribute("aria-valuenow",String(d.percent));let P=document.createElement("span");P.style.width=`${d.percent}%`,E.append(P),p.append(g,E),r.append(p)}}let Ie=null;function ve(r,a=0,u={}){let d=n.tour;if(!d||u.readingKey!=="conclusion"&&(r<0||r>=d.scenes.length))return null;if(t.clear(),u.userNavigation&&Ee(),n.zoom?.mode==="history"&&!n.zoomSwitching){let z=d.scenes[r],L=z.path||z.steps?.[a]?.file||n.activeTourFilePath;return et(L,n.historyCommit).catch(H=>{document.getElementById("tour-mode-status").textContent=H.message}),null}let p=Ie?.tour===d&&!u.zoomLanding&&!s?Ie.context:null;n.directoryEvidence=null,n.activeCorrespondenceId=null,Ge(""),Zt(),Wn();let g=_.find(z=>z.key===u.readingKey)||xn(_,r,a,u.showIntro?"overview":null);g&&g.kind!=="step"&&g.kind!=="conclusion"&&g.kind!=="title"&&st(d)&&(g=xn(_,g.sceneIndex,0)),g&&(r=g.sceneIndex,a=g.stepIndex);let y=d.scenes[r],b=rn(d,g);document.body.classList.toggle("tour-discussion",b==="narrative");let E=g.kind==="title"||g.kind==="chapter"||g.kind==="conclusion",P=document.body.classList.contains("tour-bookend")!==E;document.body.classList.toggle("tour-bookend",E),n.readingKey=g?.key||"title",n.sceneIntroVisible=g?.kind!=="step",n.narrativeParent=g?.kind==="conclusion"?"conclusion":g?.kind==="title"?"tour":g?.kind==="chapter"?"chapter":null,n.activeSceneIndex=r,n.activeStepIndex=$e(y)?Math.min(Math.max(a,0),Math.max(y.steps.length-1,0)):0,n.tourFocusFilePath=!y||n.narrativeParent?null:y.kind==="text-diff"?y.path:y.kind==="walkthrough"?y.steps[n.activeStepIndex]?.diff.path??null:Me(y)?y.steps[n.activeStepIndex]?.file??null:null;let R=y?Zr(d,r):null;ws();let U=u.preserveNarration&&Q.engaged?Q.state.unit:Br(u.narrationEntry||"playback-start");n.renderedNarrationUnit=U,io(y,R,U),(!u.fromReadingScroll||P)&&ao(n.readingKey),U&&!u.zoomLanding&&!u.preserveNarration&&(!n.zoom||re())&&(u.narrationNavigation==="linear"?Q.followLinearNavigation(U):u.narrationNavigation!=="controller"&&Q.followDirectNavigation(U)),Se();let F=me(d,g,n.zoom?.mode);b==="overview"?Ie={tour:d,context:F}:b!=="narrative"?Ie=p?{tour:d,context:p}:null:g.kind!=="chapter"&&(Ie=null);let M=J.get(g.key)?.querySelector(".tour-scene-orientation");return M&&F&&(M.textContent=Gn(p,F)),b==="overview"&&zn()?U:b==="narrative"?(++ge,n.displayedPanels=[],n.activeTourFilePath=null,se({type:"updateCommitHistory",history:Nr()}),document.body.classList.add("tour-discussion"),n.tourFocusFilePath=null,pe(),be(),U):(document.body.classList.remove("tour-discussion"),y.kind==="walkthrough"?(Vr(y),U):Me(y)?(Jr(y),U):(ut(y,Vt(y.path)),U))}function Ge(r){let a=document.getElementById("status-banner");a.textContent=r,a.hidden=!r}function zn(){let r=n.tour?.scenes[n.activeSceneIndex];if(!re()||!r||st(n.tour)||n.narrativeParent||!r.overview)return!1;let a=nn(n.tour,r);n.directoryEvidence=a,n.activeCorrespondenceId=null,n.activeTourFilePath=null,pe(),document.body.classList.remove("tour-discussion");let u=me(n.tour,_.find(d=>d.key===n.readingKey),n.zoom?.mode);return se(sn(u.labels,a.entries)),document.getElementById("file-info").textContent=gt(u),Ge(a.entries.length?"":"No changed files in this directory for the selected comparison."),Se(),!0}function qn(r){let a=n.directoryEvidence;if(!a)return!1;let u=a.files.find(d=>d.path===r);if(!u){let d=a.omitted.find(p=>p.path===r);return Ge(d?`${r}: ${d.reason}`:"This file has no change in the overview comparison."),!1}return Ee(),Ge(""),ut(u,[],`directory-${n.tour.scenes[n.activeSceneIndex].id}-${r}`),Se(),!0}function Vt(r){let a=n.tour;return!a||!r?[]:ui(a,r,n.activeSceneIndex,n.activeStepIndex)}function ds(r,a){let u=n.tour;return!u||!r?[]:fi(u,r,n.activeSceneIndex,n.activeStepIndex,(d,p)=>Er(a?.[d]?.diffModel,p))}function Jt(r){return`file::${r}`}function ut(r,a=[],u=Jt(r.path),d=null,p=null){if(document.body.classList.remove("tour-discussion"),!n.tour)return;t.clear(),n.activeCorrespondenceId=null,n.activeTourFilePath=n.zoom?.mode==="history"&&n.historyPath||r.path,pe();let y=ke(r.leftContent,r.rightContent),b=Wr(r,r.leftLabel,n.zoom?.mode==="compare"?"from":"base"),E=Wr(r,r.rightLabel,n.zoom?.mode==="compare"?"to":"head"),P=a.find(U=>U.active)||p&&{side:p.revision==="head"?"right":"left",startLine:p.startLine},R=r.changeKind==="added"?{left:!1,right:!0}:r.changeKind==="deleted"?{left:!0,right:!1}:{left:!0,right:!0};se({type:"showDiff",file1:`1. ${b}`,file2:`2. ${E}`,comparisonId:`tour-${u}`,leftContent:r.leftContent,rightContent:r.rightContent,canReturnToDirectory:!!n.directoryEvidence,sourceInfo:{leftPath:r.previousPath||r.path,rightPath:r.path},fileExists:R,diffModel:y,history:d,fileNavigation:{canGoPrevious:!!Nt(-1),canGoNext:!!Nt(1)},editableSides:{left:!1,right:!1},comparisonSummary:Hn(r.path,void 0,!n.directoryEvidence),initialChangeIndex:P?Kn(y,P.side,P.startLine):r.focusChangeIndex,tourAnnotations:a})}function Hn(r,a,u=!1){if(!re())return r;let d=_.find(K=>K.key===n.readingKey),p=d&&me(n.tour,d,n.zoom?.mode),g=a===void 0?d:{kind:"step",sceneIndex:n.activeSceneIndex,stepIndex:n.activeStepIndex},y=g&&me(n.tour,g,n.zoom?.mode,a),b=u||!y?lo(n.tour,r):y,E={...b,scope:r,scopeKey:JSON.stringify([r]),overview:!1},P=Ie?.tour===n.tour?Ie.context:null,R=P&&(P.comparisonKey!==E.comparisonKey||P.scopeKey!==E.scopeKey)?Gn(P,E):gt(E);Ie={tour:n.tour,context:E};let U=p,F=d&&rn(n.tour,d)==="preview"&&U?.scope===r&&U.comparisonKey===b.comparisonKey,M=d&&n.tour.scenes[d.sceneIndex],z=M&&$e(M)?M.steps[d.kind==="step"?d.stepIndex:0]:null;return`${z&&U?.scope===r&&U.comparisonKey===b.comparisonKey?`${F?"Coming up":"Evidence for"}: ${Be(n.tour,{kind:"step",key:`step:${M.id}:${z.id}`,sceneIndex:d.sceneIndex,stepIndex:d.kind==="step"?d.stepIndex:0})} \xB7 `:""}${R}`}function Wr(r,a,u){if(n.zoom?.mode==="history")return a;let d=a.startsWith(r.path)?a.slice(r.path.length).trim():a.trim();return d?`${u} ${d}`:u}function Gr(r){return r.status==="inferred"?r.id:`${r.before?"before":"after"}:${r.id}`}function Vr(r){let a=r.steps[n.activeStepIndex];if(a){if(a.symbol&&!n.sceneIntroVisible){let u=a.symbol;n.symbolSelection={...u,id:Gr(u),entry:u.after||u.before,relation:u.status==="inferred"?{id:u.id}:null,ambiguous:u.status==="ambiguous",side:u.before?"before":"after"},Gt(!1);return}if(a.image){++ge,n.displayedPanels=[],n.activeCorrespondenceId=null,n.activeTourFilePath=a.diff.path,t.show(a.image,a.title),pe();return}ut(a.diff,n.sceneIntroVisible?[]:Vt(a.diff.path),Jt(a.diff.path),null,n.sceneIntroVisible?a.focus:null)}}function Jr(r){let a=r.steps[n.activeStepIndex];a&&Yr(r,a.file,a)}function Yr(r,a,u){document.body.classList.remove("tour-discussion");let d=Rt(r,a);if(!u||!d)return;n.activeCorrespondenceId=null,n.activeTourFilePath=d.path,pe();let p=d.panels.map((M,z)=>({id:`${r.id}-${d.path}-${M.id}`,commit:r.kind==="stacked-diff"?Ft(r)[z].oid:void 0,label:M.label,path:M.path||d.path,content:M.content,savedContent:M.content,dirty:!1,editable:!1,stackId:Ft(r)[z].id})),g=Vn(p,(M,z)=>ke(M.content,z.content)),y=n.sceneIntroVisible?[]:ds(d.path,g),b=y.find(M=>M.active),E=b?.pairIndex??u.pairIndex,P=b?.side??u.side,R=b?.startLine??u.startLine,U=g[E]?.diffModel,F=U&&R?Kn(U,P,R):0;se({type:"showMultiDiff",panels:p,pairs:g,activePanelId:p[E+(P==="right"?1:0)]?.id,activePairIndex:E,initialChangeIndex:F,revealFirstChangeInEachPanel:r.kind==="deconstructed-diff",history:null,fileNavigation:{canGoPrevious:!!Nt(-1),canGoNext:!!Nt(1)},mutationEnabled:!1,comparisonSummary:Hn(d.path,E),tourAnnotations:y})}function Yt(r){if(!re())return!1;let a=Ht(_,n.readingKey,r,st(n.tour));return a?(Ae(a,!1,!0),!0):!1}function Xt(){return{paths:n.tour.files.filter(r=>r.kind==="text-diff").map(r=>r.path),currentPath:n.activeTourFilePath,changedPaths:n.zoom?.mode==="compare"?n.compare?.changedPaths:n.historyChangedFiles}}function Nt(r){let a=n.tour;if(!a||r!==-1&&r!==1)return null;let u=a.scenes[n.activeSceneIndex];if(n.zoom?.mode==="history"||n.zoom?.mode==="compare"){let d=Ye(Xt(),r);return d?{fileIndex:a.files.findIndex(p=>p.path===d),path:d}:null}if(n.directoryEvidence){let d=n.directoryEvidence.files,p=d.findIndex(b=>b.path===n.activeTourFilePath),g=d[p+r],y=g?a.files.findIndex(b=>b.path===g.path):-1;return y>=0?{fileIndex:y,path:g.path}:null}if(Me(u)){let d=u.steps[n.activeStepIndex]?.pairIndex;if(!Number.isInteger(d))return null;let p=a.files.flatMap(b=>{if(b.kind!=="text-diff")return[];let E=Rt(u,b.path);return E?[E]:[]}),g=ri(p,d,n.activeTourFilePath,r);if(!g)return null;let y=a.files.findIndex(b=>b.kind==="text-diff"&&b.path===g.path);return y>=0?{fileIndex:y,path:g.path}:null}return oi(a.files,n.activeTourFilePath,r)}function Xr(r){let a=Nt(r);return a?ft(a.fileIndex):!1}function _n(r,a=!0){let u=n.tour?.files[r];return!u||u.kind!=="text-diff"?!1:(a&&Q.interruptForExploration(),n.directoryEvidence=null,ut(u,Vt(u.path),Jt(u.path)),!0)}function ft(r){let a=n.tour?.files[r];if(!a||a.kind!=="text-diff")return!1;if(Ee(),n.activeCorrespondenceId=null,n.symbolContext=!1,document.getElementById("file-symbol-context").hidden=!n.symbolSelection,document.getElementById("file-symbol-context").textContent="Return to symbol comparison",document.querySelectorAll(".correspondence-file-label").forEach(d=>d.setAttribute("aria-current",String(d.textContent===a.path))),document.querySelectorAll(".correspondence-item").forEach(d=>d.setAttribute("aria-pressed","false")),n.zoom?.mode==="history")return et(a.path,n.historyCommit).catch(d=>{document.getElementById("tour-mode-status").textContent=d.message}),!0;if(n.zoom?.mode==="compare")return Fr(a).catch(d=>{document.getElementById("tour-mode-status").textContent=d.message}),!0;if(n.directoryEvidence&&re())return qn(a.path);n.zoomSwitching||Q.interruptForExploration();let u=n.tour?.scenes[n.activeSceneIndex];if(Me(u)){let d=u.steps[n.activeStepIndex];return d&&Rt(u,a.path)?(Yr(u,a.path,d),!0):!1}return _n(r,!1)}function Rt(r,a){let u=r?.files?.find(g=>g.path===a);if(u||r?.kind!=="deconstructed-diff")return u;let d=n.tour?.files.find(g=>g.kind==="text-diff"&&g.path===a);if(!d||d.kind!=="text-diff")return null;let p=d.changeKind!=="deleted";return{path:d.path,panels:Ft(r).map(g=>({id:g.id,label:`${g.label} / ${d.path}${p?"":" (absent)"}`,path:p?d.path:void 0,content:p?d.rightContent:"",exists:p}))}}function ls(){if(n.narrativeParent)return!!ve(n.activeSceneIndex,n.activeStepIndex,{readingKey:n.readingKey,preserveNarration:!0});if(n.directoryEvidence)return zn();let r=n.tour?.scenes[n.activeSceneIndex];if(!r||!n.tourFocusFilePath)return!1;if(r.kind==="walkthrough")Vr(r);else if(Me(r))Jr(r);else if(r.kind==="text-diff")ut(r,Vt(r.path));else return!1;return!0}function Pt(r){if(!["tour","files","commits","symbols"].includes(r))return;r==="symbols"&&!n.correspondence&&(r="files");let a=re()&&!!n.tour?.scenes.length;r==="tour"&&!a&&(r="commits"),n.tourNavigatorTab=r,document.querySelectorAll("[data-tour-navigator]").forEach(u=>{let d=u.dataset.tourNavigator===r;u.disabled=u.dataset.tourNavigator==="tour"&&!a,u.classList.toggle("is-active",d),u.setAttribute("aria-selected",String(d)),u.tabIndex=d?0:-1}),document.querySelectorAll("[data-tour-navigator-panel]").forEach(u=>{u.hidden=u.dataset.tourNavigatorPanel!==r}),window.dispatchEvent(new CustomEvent("bygone:present-navigator-change",{detail:{tab:r}})),window.dispatchEvent(new Event("resize"))}function Zt(){let r=!!(n.directoryEvidence&&re()),a=r?n.activeTourFilePath:null;document.body.classList.toggle("tour-directory-overview",r),document.body.classList.toggle("tour-directory-file-open",!!a),document.getElementById("tour-directory-breadcrumb").hidden=!r;let u=document.getElementById("tour-directory-root");a?u.removeAttribute("aria-current"):u.setAttribute("aria-current","location"),document.getElementById("tour-directory-separator").hidden=!a;let d=document.getElementById("tour-directory-file");d.textContent=a||"",d.hidden=!a;let p=document.getElementById("tour-directory-narration-context");p.hidden=!a,p.textContent=`Narration describes the ${n.narrativeParent||"overview"}`}function pe(){Zt();let r=document.getElementById("file-symbol-context");r.hidden=!n.symbolSelection,r.textContent=n.activeCorrespondenceId&&!n.symbolContext?"Show file context":"Return to symbol comparison";let a=n.activeCorrespondenceId?[n.symbolSelection?.before?.path,n.symbolSelection?.after?.path].filter(Boolean):[],u=n.tour?.files.find(L=>L.path===n.activeTourFilePath),d=a.length?a:[n.activeTourFilePath,u?.previousPath];document.querySelectorAll(".correspondence-file-label").forEach(L=>{let H=d.includes(L.textContent);L.setAttribute("aria-current",String(H))}),document.querySelectorAll(".correspondence-item").forEach(L=>L.setAttribute("aria-pressed",String(L.dataset.correspondenceId===n.activeCorrespondenceId)));let p=n.tour?.scenes[n.activeSceneIndex],g=Me(p)?p.steps[n.activeStepIndex]:null,y=new Map(n.tour?.files.map(L=>[L.path,L]));document.querySelectorAll(".tour-file").forEach(L=>{let H=L.dataset.filePath;L.classList.toggle("is-active",H===n.activeTourFilePath||a.includes(H)||a.includes(y.get(H)?.previousPath)),L.classList.toggle("is-tour-focus",!n.directoryEvidence&&H===n.tourFocusFilePath),L.classList.remove("is-comparison-changed","is-comparison-empty"),delete L.dataset.comparisonState;let K=y.get(H);L.dataset.changeKind=K?.changeKind||"",L.classList.toggle("is-omitted",K?.kind==="omitted"),L.disabled=K?.kind==="omitted"||!!(n.directoryEvidence&&!n.directoryEvidence.files.some(Z=>Z.path===H)),H===n.activeTourFilePath?L.setAttribute("aria-current","true"):L.removeAttribute("aria-current");let q=L.querySelector(".tour-file-marker"),T=L.querySelector(".tour-file-meta");if(n.directoryEvidence&&L.disabled&&K?.kind==="text-diff"){let Z="Not in this overview comparison";L.setAttribute("title",`${H} \xB7 ${Z}`),L.setAttribute("aria-label",`${H}, ${Z}`),T&&(T.textContent=Z),q&&(q.textContent="\u25CB");return}if(n.directoryEvidence&&K?.kind==="text-diff"){let Z=n.directoryEvidence.files.find(ue=>ue.path===H);L.dataset.changeKind=Z.changeKind;let ie=`${Qt(Z.changeKind)} in overview`;L.setAttribute("title",`${H} \xB7 ${ie}`),L.setAttribute("aria-label",`${H}, ${ie}`),T&&(T.textContent=ie),q&&(q.textContent=jn(Z.changeKind));return}let W=n.zoom?.mode==="history"?n.historyChangedFiles:n.zoom?.mode==="compare"?n.compare?.changedPaths:null;if(W&&K?.kind==="text-diff"){let Z=W.has(H),ie=Z?"Changed in this comparison":"Unchanged in this comparison";L.classList.add(Z?"is-comparison-changed":"is-comparison-empty"),L.setAttribute("title",`${H} \xB7 ${ie}`),L.setAttribute("aria-label",`${H}, ${ie}`),T&&(T.textContent=ie),q&&(q.textContent=Z?"M":"\u25CB");return}if(g&&K?.kind==="text-diff"){let Z=Rt(p,H);if(Z){let ue=vr(Z,g.pairIndex),ye=us(ue);L.dataset.comparisonState=ue,L.classList.add(ye.changed?"is-comparison-changed":"is-comparison-empty"),L.setAttribute("title",`${K.path} \xB7 ${ye.label}`),L.setAttribute("aria-label",`${K.path}, ${ye.label}`),q&&(q.textContent=ye.marker),T&&(T.textContent=ye.label);return}L.disabled=!0;let ie="Not included in this tour comparison";L.setAttribute("title",`${H} \xB7 ${ie}`),L.setAttribute("aria-label",`${H}, ${ie}`),q&&(q.textContent="\u25CB"),T&&(T.textContent=ie);return}if(K){let Z=K.kind==="omitted"?`${K.path}: ${K.reason}`:`Open file: ${K.path}`;L.setAttribute("title",Z),L.setAttribute("aria-label",Z),q&&(q.textContent=K.kind==="omitted"?"\xD7":jn(K.changeKind)),T&&(T.textContent=K.kind==="omitted"?`Not rendered \xB7 ${K.reason}`:`${Qt(K.changeKind)} \xB7 +${K.additions} \u2212${K.deletions}`)}});let b=document.getElementById("tour-files"),E=re(),P=!E||!!(g||n.directoryEvidence),R=!P||(E?n.showAllTourFiles:n.showAllFiles),U=0;b.querySelectorAll(".tour-file").forEach(L=>{let H=L.dataset.filePath,K=n.directoryEvidence?n.directoryEvidence.files.some(q=>q.path===H):n.zoom?.mode==="history"?n.historyChangedFiles.has(H):n.zoom?.mode==="compare"?n.compare?.changedPaths.has(H):g?L.classList.contains("is-comparison-changed"):!0;L.parentElement.hidden=!R&&!K,L.parentElement.hidden||U++});for(let L of[...b.querySelectorAll("details[data-file-folder]")].reverse())L.parentElement.hidden=![...L.querySelector(":scope > ul").children].some(H=>!H.hidden);b.querySelector("[data-file-tree-empty]").hidden=U>0,b.querySelector("[data-file-tree-empty]").textContent=R?"No files":"No changed files",b.setAttribute("aria-label",R?E?"Tour files":o?"Included files":"Files in selected revisions":"Changed files");let F=document.getElementById("tour-file-filter");F.hidden=!P,F.title=E?"Include tour files unchanged in this step comparison":o?"Include unchanged files packaged in this export":"Include unchanged files from the selected revisions",document.getElementById("tour-file-filter-label").textContent=E?"Show unchanged tour files":o?"Show all included files":"Show all files",document.getElementById("tour-show-all-files").checked=E?n.showAllTourFiles:n.showAllFiles,document.getElementById("tour-visible-file-count").textContent=`${U} / ${n.tour.files.length}`;let M=b.querySelector(".tour-file.is-active");if(n.revealedFilePath!==n.activeTourFilePath&&M&&!M.parentElement.hidden){for(let L=M.closest("details");L;L=L.parentElement.closest("details"))L.open=!0,n.collapsedFileFolders.delete(L.dataset.fileFolder);M.scrollIntoView({block:"nearest"})}n.revealedFilePath=n.activeTourFilePath;let z=document.getElementById("tour-return-focus");if(z){let L=re(),H=p?.kind==="walkthrough"&&p.steps[n.activeStepIndex]?.image,K=p?.kind==="walkthrough"&&p.steps[n.activeStepIndex]?.symbol;z.hidden=!L||!!n.directoryEvidence||(n.narrativeParent?!n.activeTourFilePath:!n.tourFocusFilePath||(H?t.isVisible():K?n.activeCorrespondenceId===Gr(K)&&!n.symbolContext:n.activeTourFilePath===n.tourFocusFilePath)),z.textContent=n.narrativeParent?"Return to passage":"Return to tour focus"}}function us(r){return{"modified-here":{label:"Modified here",marker:"\u2022",changed:!0},"created-here":{label:"Created here",marker:"+",changed:!0},"deleted-here":{label:"Deleted here",marker:"\u2212",changed:!0},"unchanged-here":{label:"Unchanged here",marker:"\u25CB",changed:!1},"not-created-yet":{label:"Not created yet",marker:"\u2026",changed:!1},"already-deleted":{label:"Already deleted",marker:"\xD7",changed:!1}}[r]}function $e(r){return r?.kind==="walkthrough"||r?.kind==="stacked-diff"||r?.kind==="deconstructed-diff"}function Me(r){return r?.kind==="stacked-diff"||r?.kind==="deconstructed-diff"}function Ft(r){return r.kind==="deconstructed-diff"?r.panels:r.stack}function jn(r){return{added:"+",deleted:"\u2212",renamed:"\u2192",modified:"\u2022"}[r]||"\u2022"}function Qt(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function Zr(r,a){let u=r.scenes[a],d=r.chapters.findIndex(b=>b.sceneIds.includes(u.id)),p=d>=0?r.chapters[d]:null,g=p?p.sceneIds.indexOf(u.id)+1:a+1,y=p?p.sceneIds.length:r.scenes.length;return{chapter:p,chapterIndex:d,chapterNumber:d>=0?d+1:a+1,sceneInChapter:g,scenesInChapter:y,sceneCount:r.scenes.length}}function fs(r,a){return $e(r)?`${r.title} \xB7 Step ${a+1} of ${r.steps.length}`:r.title}function Kn(r,a,u){let p=(a==="left"?r.leftLines:r.rightLines).findIndex(R=>R.lineNumber===u);if(p<0)return 0;let g=a==="left"?"leftStart":"rightStart",y=a==="left"?"leftEnd":"rightEnd",b=r.blocks.findIndex(R=>p>=R[g]&&p<R[y]);if(b>=0)return b;let E=0,P=Number.POSITIVE_INFINITY;return r.blocks.forEach((R,U)=>{let F=Math.min(Math.abs(p-R[g]),Math.abs(p-R[y]));F<P&&(E=U,P=F)}),E}function Qr(r){return/^[0-9a-f]{40}$/i.test(r)?r.slice(0,7):r}function Dt(r,a){return`${r} ${r===1?a:`${a}s`}`}function ps(r){return r instanceof Element&&!!r.closest('a, button, input, select, summary, textarea, [contenteditable="true"], [role="textbox"], .monaco-editor')}function hs(r){let a=n.tour?.scenes[n.activeSceneIndex];n.tour&&io(a,a?Zr(n.tour,n.activeSceneIndex):null,r)}function en(r){let a=xn(_,n.activeSceneIndex,n.activeStepIndex,r==="scene"?"overview":r==="step"?null:r);a&&Ae(a)}function Ve(r,a,u){let d=document.createElement("button");return d.type="button",d.textContent=r,d.title=a,d.addEventListener("click",u),d}function eo(r,a,u,d){let p=document.createElement("div");p.className="tour-outline-group",p.dataset.readingGroup=r;let g=document.createElement("div");g.className="tour-outline-heading";let y=document.createElement("div");y.className="tour-outline-children",y.id=`outline-${encodeURIComponent(r)}`;let b=`${n.zoom?.mode||"tour"}:${r}`,E=Ve("\u25BE",`Expand or collapse ${a}`,()=>{te.has(b)?te.delete(b):te.add(b),P()});E.className="tour-outline-toggle",E.setAttribute("aria-controls",y.id);let P=()=>{y.hidden=te.has(b),E.setAttribute("aria-expanded",String(!y.hidden)),E.textContent=y.hidden?"\u25B8":"\u25BE"};P();let R=Ve(a,`Read ${a}`,d);return R.className=u,R.dataset.readingLink=r,g.append(E,R),p.append(g,y),{group:p,children:y,link:R,toggle:E}}function ms(){let r=document.getElementById("tour-audio-settings");r&&(r.hidden=!r.hidden,to())}function to(){Zt();for(let[u,d]of[["tour-back",-1],["tour-next",1]]){let p=document.getElementById(u);p&&(p.disabled=!re()||!Ht(_,n.readingKey,d,st(n.tour)))}let r=document.getElementById("tour-narration"),a=document.getElementById("tour-audio-settings");if(r){let u=!!(a&&!a.hidden);r.setAttribute("aria-expanded",String(u)),r.textContent=u?"\u203A":"\u2039 Narration",r.title=u?"Hide narration controls":"Show narration controls",r.setAttribute("aria-label",r.title)}}function pt(r){if(!r||r.kind==="title")return{part:"title"};if(r.kind==="conclusion")return{part:"conclusion"};if(r.kind==="chapter")return{part:"chapter",chapter:r.chapterId};let a=n.tour.scenes[r.sceneIndex];return r.kind==="scene"?{part:"scene",scene:a.id}:{part:"step",scene:a.id,step:a.steps[r.stepIndex].id}}function gs(r){let a=document.createElement("button");return a.type="button",a.className="tour-copy-location",a.setAttribute("aria-label","Copy link to this section"),a.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path class="tour-link-chain" d="M10 13a5 5 0 0 0 7 .1l3-3a5 5 0 0 0-7-7l-2 2M14 11a5 5 0 0 0-7-.1l-3 3a5 5 0 0 0 7 7l2-2"/><path class="tour-link-check" d="m5 12 4 4L19 6"/></svg>',a.title=o?"Copy location within this export; share the HTML file separately":n.authoredTour?.localSource?"Copy local link to the saved current document; evidence may change":"Copy browser location (requires this presentation server)",a.addEventListener("click",async u=>{u.stopPropagation();let d=no(r);try{await navigator.clipboard.writeText(d),a.classList.add("is-copied"),a.setAttribute("aria-label","Link copied"),setTimeout(()=>{a.classList.remove("is-copied"),a.setAttribute("aria-label","Copy link to this section")},1800)}catch{let p=document.createElement("dialog"),g=document.createElement("p");g.textContent="Copy this link:";let y=document.createElement("textarea");y.value=d,y.readOnly=!0,y.setAttribute("aria-label","Link to this tour location");let b=document.createElement("button");b.textContent="Close",b.addEventListener("click",()=>p.close()),p.append(g,y,b),document.body.append(p),p.addEventListener("close",()=>p.remove(),{once:!0}),p.showModal(),y.select()}}),a}function no(r){let a=re()?n.zoom?.mode||"historical":Object.keys(G())[0],u=n.authoredTour.localSource;return u&&!o?bo({kind:"tour",...u,mode:a,focus:r}):new URL(nt(a,r),window.location.href).href}function ro(r){let a=++f,u=h.then(()=>ys(r,a));return h=u.catch(()=>{}),u}async function ys(r,a){if(!r||!n.authoredTour)return;let u=Zn(n.authoredTour,r.mode,r.focus);if(a===f){s=!0;try{if(n.zoom.mode!==r.mode&&await We(r.mode),a!==f)return;if(n.zoom.mode!==r.mode)throw new Error("The requested tour mode could not be opened.");if(le=null,document.getElementById("tour-mode-status").textContent="",ve(u.sceneIndex,u.stepIndex,{readingKey:u.key,showIntro:r.focus.part!=="step"}),await new Promise(p=>window.requestAnimationFrame(p)),a!==f)return;let d=J.get(u.key);if(!d)throw new Error("The requested document section could not be rendered.");d.tabIndex=-1,d.focus({preventScroll:!0}),ao(u.key),d.classList.add("tour-link-target"),window.setTimeout(()=>d.classList.remove("tour-link-target"),1800)}finally{s=!1}}}window.addEventListener("hashchange",()=>{try{ro(Qn(window.location.hash)).catch(fe)}catch(r){fe(r)}});function Se(){if(o)return;let r=n.tour?.scenes[n.activeSceneIndex],a=new URLSearchParams(window.location.search);for(let d of["from","to","commits","scope","commit","file","panelOrder"])a.delete(d);if(n.zoom&&a.set("mode",n.zoom.mode),n.zoom&&!re()){for(let d of["scene","step","view"])a.delete(d);n.zoom.mode==="compare"&&n.compare&&(a.set("commits",n.compare.commits.join(",")),n.compare.path&&a.set("scope",n.compare.path),n.activeTourFilePath||a.set("view","directory")),n.zoom.mode==="history"&&n.historyCommit&&a.set("commit",n.historyCommit),n.activeTourFilePath&&a.set("file",n.zoom.mode==="history"?n.historyPath:n.activeTourFilePath),window.history.replaceState(null,"",`${window.location.pathname}?${a.toString()}${window.location.hash}`);return}if(n.readingKey==="conclusion"){a.delete("scene"),a.delete("step"),a.set("view","conclusion"),window.history.replaceState(null,"",`${window.location.pathname}?${a.toString()}${nt(n.zoom.mode,{part:"conclusion"})}`);return}if(!r)return;a.set("scene",r.id);let u=$e(r)?r.steps[n.activeStepIndex]:null;u?a.set("step",u.id):a.delete("step"),n.directoryEvidence&&n.activeTourFilePath?a.set("file",n.activeTourFilePath):a.delete("file"),n.narrativeParent?a.set("view",n.narrativeParent):u&&n.sceneIntroVisible?a.set("view","overview"):a.delete("view"),window.history.replaceState(null,"",`${window.location.pathname}?${a.toString()}${nt(n.zoom.mode,pt(_.find(d=>d.key===n.readingKey)))}`)}function oo(r=n.tour?.scenes[n.activeSceneIndex],a=n.activeStepIndex){if(!r||!$e(r))return null;let u=r.steps[a];if(!u)return null;if(r.kind==="walkthrough"){if(u.image)return null;let p=u.focus;return!p?.path||!Number.isInteger(p.startLine)?null:{filePath:p.path,sideIndex:p.revision==="base"?0:1,lineNumber:p.startLine,label:`${p.path}:${p.startLine}`}}let d=u.startLine;if(!Number.isInteger(d)){let p=Rt(r,u.file),g=p?.panels?.[u.pairIndex],y=p?.panels?.[u.pairIndex+1];if(g&&y){let b=ke(g.content,y.content);d=Er(b,u.side)?.startLine}}return!u.file||!Number.isInteger(d)?null:{filePath:u.file,sideIndex:u.pairIndex+(u.side==="right"?1:0),lineNumber:d,label:`${u.file}:${d}`}}function bs(){let r=oo(),a=n.tour?.scenes[n.activeSceneIndex];if(n.sceneIntroVisible||!r||!a)return!1;if(Q.interruptForExploration(),n.activeTourFilePath!==r.filePath){let u=n.tour.files.findIndex(p=>p.kind==="text-diff"&&p.path===r.filePath);if(u<0||!(Me(a)?ft(u):_n(u,!1)))return!1}return window.requestAnimationFrame(()=>se({type:"revealSearchResult",sideIndex:r.sideIndex,lineNumber:r.lineNumber,startColumn:1,endColumn:1})),!0}function io(r,a,u){Wn(),document.getElementById("tour-narrative").hidden=!1,document.getElementById("tour-breadcrumb").textContent=n.narrativeParent==="tour"?"Intro":n.narrativeParent==="conclusion"?"Conclusion":n.narrativeParent==="chapter"?a.chapter?.title||"":n.sceneIntroVisible?r.title:fs(r,n.activeStepIndex);let d=r&&J.get(`scene:${r.id}`),p=$e(r)?r.steps[n.activeStepIndex]:null,g=p&&J.get(`step:${r.id}:${p.id}`);for(let y of new Set([d,g,J.get(n.readingKey)].filter(Boolean)))y.querySelectorAll("[data-reading-field]").forEach(b=>{b.closest("[data-reading-key]")===y&&Es(b,b.dataset.readingText,{field:b.dataset.readingField,...b.dataset.itemIndex!==void 0?{itemIndex:Number(b.dataset.itemIndex)}:{}},u)});to()}function Wn(){if(O===n.tour)return;O=n.tour,_=di(n.tour),J.clear();let r=document.getElementById("tour-narrative-content"),a=[],u,d=(b,E,P,R,U,F)=>{let M=document.createElement(E);M.className=P;let z=U&&/^h[1-6]$/.test(E)?document.createElement("span"):M;return z!==M&&M.append(z),z.replaceChildren(...Tr(document,R||"")),U&&(z.dataset.readingField=U,z.dataset.readingText=R||"",F!==void 0&&(z.dataset.itemIndex=String(F))),b.append(M),M},p=(b,E,P)=>{if(d(b,"p","tour-narrative-summary",E.summary,P?"summary":null),E.bullets?.length){let R=document.createElement("ul");R.className="tour-narrative-bullets",E.bullets.forEach((U,F)=>d(R,"li","",U,P?"bullet":null,F)),b.append(R)}E.takeaway&&d(b,"p","tour-narrative-takeaway",E.takeaway,P?"takeaway":null)},g=Mt(n.tour),y=(b,E)=>{let P=d(b,"ul","tour-route","");E.forEach(R=>{let U=d(P,"li","",""),F=Ve("",`Read ${R.title}`,()=>Ae(_.find(M=>M.kind==="scene"&&M.sceneIndex===R.sceneIndex)));F.className="tour-route-link",d(F,"span","tour-route-number",`${R.sceneIndex+1}. `),d(F,"span","",R.title,"route-title",R.sceneIndex),U.append(F)})};for(let b of _){let E=document.createElement("section");E.className="tour-reading-item",E.dataset.readingKey=b.key,E.dataset.readingKind=b.kind,E.dataset.sceneIndex=String(b.sceneIndex),E.dataset.stepIndex=String(b.stepIndex);let P=n.tour.scenes[b.sceneIndex];if(b.kind==="title")d(E,"h1","tour-document-title",n.tour.title,"document-title"),n.tour.opening&&(d(E,"h2","tour-passage-title",n.tour.opening.title,"passage-title"),p(E,n.tour.opening,!0)),d(E,"h2","tour-passage-title","What you'll see"),g.chapters.forEach(R=>{let U=d(E,"section","tour-route-chapter",""),F=d(U,"h3","",""),M=Ve("",`Read ${R.title}`,()=>Ae(_.find(z=>z.kind==="chapter"&&z.chapterId===R.chapterId)||_.find(z=>z.kind==="scene"&&z.sceneIndex===R.scenes[0]?.sceneIndex)));M.className="tour-route-link tour-route-chapter-link",d(M,"span","tour-route-number",`${R.chapterIndex+1}. `),d(M,"span","",R.title,"route-chapter",R.chapterIndex),F.append(M)}),g.chapters.length||y(E,g.scenes);else if(b.kind==="conclusion")d(E,"h2","tour-passage-title",n.tour.conclusion.title,"passage-title"),p(E,n.tour.conclusion,!0);else if(b.kind==="chapter"){let R=g.chapters.find(U=>U.chapterId===b.chapterId);d(E,"h2","tour-document-chapter",R.title,"chapter"),d(E,"p","tour-narrative-summary",R.summary,"summary"),y(E,R.scenes)}else if(b.kind==="scene"){E.classList.add("tour-scene-group");let R=d(E,"div","tour-scene-header",""),U=d(R,"h2","tour-scene-heading",Be(n.tour,b),"scene-title"),F=document.createElement("button");F.className="tour-scene-title-toggle",F.type="button",F.title="Expand or collapse scene overview",F.disabled=!0,F.append(...U.childNodes),U.append(F);let M=document.createElement("details");M.className="tour-scene-context";let z=d(M,"summary","","");z.setAttribute("aria-label",`Scene overview: ${P.title}`),z.dataset.tooltip="Expand or collapse scene overview";let L=d(M,"div","tour-scene-context-body","");L.id=`scene-overview-${b.sceneIndex}`,F.setAttribute("aria-controls",L.id),F.setAttribute("aria-expanded","false"),F.addEventListener("click",T=>{T.target.closest("a")||(M.open=!M.open)}),M.addEventListener("toggle",()=>F.setAttribute("aria-expanded",String(M.open))),p(L,P,!1),R.addEventListener("keydown",T=>{T.key==="Escape"&&M.open&&(T.preventDefault(),T.stopPropagation(),M.open=!1,z.focus({preventScroll:!0}))}),R.append(M);let H=d(E,"div","tour-scene-overview","");p(H,{...P,takeaway:$e(P)?"":P.takeaway},!0),P.overview?.purpose&&d(H,"p","tour-overview-purpose",P.overview.purpose,"overview-purpose");let K=me(n.tour,b,n.zoom?.mode);K&&d(H,"p","tour-scene-orientation",gt(K));let q=d(H,"div","tour-narrative-tags","");P.tags.forEach(T=>d(q,"span","",T))}else{let R=P.steps[b.stepIndex],U=P.kind==="deconstructed-diff"?R.body?`Stage ${(R.stageIndex??R.pairIndex)+1}`:P.panels[R.pairIndex+1].label:"";if(U&&d(E,"div","tour-narrative-chapter",U,"stage-title"),d(E,"h3","tour-step-title",Be(n.tour,b),"step-title"),d(E,"p","tour-step-orientation",on(n.tour,b.sceneIndex,b.stepIndex),"step-orientation"),R.body&&d(E,"p","tour-step-body",R.body,"step-body"),P.kind==="deconstructed-diff"&&!R.body){let z=P.steps.findIndex(L=>L.pairIndex===R.pairIndex);if(z>=0&&z<b.stepIndex){let L=_.find(K=>K.kind==="step"&&K.sceneIndex===b.sceneIndex&&K.stepIndex===z),H=Ve("Read stage explanation",`Read ${P.steps[z].title}`,()=>Ae(L));H.className="tour-show-in-code tour-stage-explanation",E.append(H)}}let F=d(E,"div","tour-step-requirement","");ks(F,R.requirement),R.connection&&(d(E,"p","tour-connection",`${R.connection.from.path} \u2192 ${R.connection.to.path}`),d(E,"p","tour-connection",R.connection.label,"connection")),b.stepIndex===P.steps.length-1&&d(E,"p","tour-narrative-takeaway",P.takeaway,"takeaway");let M=oo(P,b.stepIndex);if(M){let z=d(E,"div","tour-step-code","");d(z,"span","tour-step-code-location",M.label);let L=Ve("Show in code",`Show ${M.label}`,()=>{Ae(b),bs()});L.className="tour-show-in-code",z.append(L)}}E.querySelector("h1, h2, h3").append(gs(pt(b))),J.set(b.key,E),b.kind==="step"?u.append(E):(a.push(E),u=b.kind==="scene"?E:null)}r.replaceChildren(...a),X=r.scrollTop}function ws(){for(let[u,d]of J)d.classList.toggle("is-active",u===n.readingKey);document.querySelectorAll("[data-reading-link], .tour-outline-step, #tour-title").forEach(u=>{let d=n.tour?.scenes[n.activeSceneIndex],p=d&&$e(d)?d.steps[Number(u.dataset.stepIndex)]:null,y=(u.id==="tour-title"?"title":u.dataset.readingLink||(p&&u.dataset.sceneId===d.id?`step:${d.id}:${p.id}`:null))===n.readingKey;u.classList.toggle("is-active",y),y?u.setAttribute("aria-current","location"):u.removeAttribute("aria-current")}),document.querySelectorAll(".tour-outline-group").forEach(u=>{u.classList.toggle("has-active",!!u.querySelector('[aria-current="location"]'))});let r=document.getElementById("tour-scenes"),a=r?.querySelector('[aria-current="location"]');for(;a&&!a.getClientRects().length;)a=a.closest(".tour-outline-children[hidden]")?.parentElement.querySelector(":scope > .tour-outline-heading [data-reading-link]");if(a&&r.clientHeight){let u=r.getBoundingClientRect(),d=a.getBoundingClientRect();d.top<u.top?r.scrollTop+=d.top-u.top:d.bottom>u.bottom&&(r.scrollTop+=d.bottom-u.bottom)}}function so(){let r=document.getElementById("tour-narrative"),a=document.getElementById("tour-narrative-content");if(!r||!a||!r.getClientRects().length)return;let u=r.getBoundingClientRect(),d=u.height-a.clientHeight;a.style.setProperty("--tour-reading-viewport",`${a.clientHeight}px`),a.style.setProperty("--tour-bookend-viewport",`${Math.max(0,window.innerHeight-u.top-d)}px`)}function ao(r){let a=document.getElementById("tour-narrative-content"),u=J.get(r);if(!a||!u)return;so();let d=u.dataset.readingKind==="step"?u.closest(".tour-scene-group")?.querySelector(".tour-scene-header"):null;a.scrollTop+=u.getBoundingClientRect().top-a.getBoundingClientRect().top-(d?.getBoundingClientRect().height||0),X=a.scrollTop,tn()}function tn(){let r=document.getElementById("tour-narrative-content"),a=r.getBoundingClientRect().top,u=0;return r.querySelectorAll(".tour-scene-header").forEach(d=>{let p=d.parentElement.getBoundingClientRect(),g=p.top<a-1&&p.bottom>a;d.classList.toggle("is-stuck",g),d.querySelector(".tour-scene-title-toggle").disabled=!g,g?u=Math.max(u,d.getBoundingClientRect().bottom-a):d.querySelector("details").open=!1}),r.style.scrollPaddingTop=`${u}px`,u}function Ae(r,a=!1,u=!1){return!a&&!s&&re()&&window.history.pushState(null,"",nt(n.zoom.mode,pt(r))),ve(r.sceneIndex,r.stepIndex,{readingKey:r.key,showIntro:r.kind!=="step",userNavigation:!0,fromReadingScroll:a,narrationNavigation:u?"linear":void 0,narrationEntry:u?"continuous":"playback-start"})}function vs(){ne===null&&(ne=window.requestAnimationFrame(()=>{if(ne=null,!re()||n.zoomSwitching)return;let r=document.getElementById("tour-narrative-content"),a=tn();if(X!==null&&Math.abs(r.scrollTop-X)<2)return;X=null;let u=r.getBoundingClientRect().top+a+24,d=_[0];for(let p of _){if(J.get(p.key).getBoundingClientRect().top>u)break;d=p}d&&d.key!==n.readingKey&&Ae(d,!0)}))}function xs(r){let a=[];return r.source&&a.push(r.source),r.confidence&&a.push(`${r.confidence} confidence`),a.join(" \xB7 ")}function ks(r,a){if(!a){r.hidden=!0,r.replaceChildren(),r.removeAttribute("title");return}let u=document.createElement("span");u.className="tour-requirement-chip",u.dataset.status=a.status||"unspecified",u.textContent=a.status?`${a.id} \xB7 ${a.status}`:a.id;let d=document.createElement("span");d.className="tour-requirement-text",d.textContent=a.text;let p=[u,d],g=xs(a);if(g){let y=document.createElement("span");y.className="tour-requirement-meta",y.textContent=g,p.push(y)}r.replaceChildren(...p),r.title=[`${a.id}: ${a.text}`,g].filter(Boolean).join(" \u2014 "),r.hidden=!1}function Es(r,a,u,d,p={}){let g=d?.segments.filter(b=>b.source.field===u.field&&b.source.itemIndex===u.itemIndex)||[],y=[];p.prefix&&y.push(document.createTextNode(p.prefix)),y.push(...Tr(document,a,g)),p.suffix&&y.push(document.createTextNode(p.suffix)),r.replaceChildren(...y)}function co(){Q.stop();let r=Go();n.mode="diff",n.comparisonId+=1,n.left={name:r.leftFileName,content:r.leftContent},n.right={name:r.rightFileName,content:r.rightContent},Le("Loaded sample diff."),se({type:"showDiff",file1:n.left.name,file2:n.right.name,comparisonId:`web-${n.comparisonId}`,leftContent:n.left.content,rightContent:n.right.content,diffModel:ke(n.left.content,n.right.content),history:null})}async function Is(r){Q.stop();let[a,u]=r,[d,p]=await Promise.all([a.text(),u.text()]);n.mode="diff",n.comparisonId+=1,n.left={name:a.name,content:d},n.right={name:u.name,content:p},Le(`Loaded ${a.name} and ${u.name}.`),se({type:"showDiff",file1:a.name,file2:u.name,comparisonId:`web-${n.comparisonId}`,leftContent:d,rightContent:p,diffModel:ke(d,p),history:null})}async function Ss(r){Q.stop();let a=await Promise.all(r.map(async(u,d)=>{let p=await u.text();return{id:`web-panel-${d}`,label:u.name,content:p,savedContent:p,dirty:!1,editable:!0}}));n.mode="multi-diff",Le(`Loaded ${a.length}-panel diff for ${a.map(u=>u.label).join(", ")}.`),se({type:"showMultiDiff",panels:a,pairs:a.slice(0,-1).map((u,d)=>({leftIndex:d,rightIndex:d+1,diffModel:ke(u.content,a[d+1].content)}))})}function Le(r){let a=document.getElementById("web-status");a&&(a.textContent=r)}})();})();
670
+ The converted copy will be downloaded after opening.`)){Qe("Tour conversion canceled.");return}p=await d(!0),g=await p.json().catch(()=>({}))}if(!p.ok)throw new Error(g.error||`Tour upload failed (${p.status}).`);if(!g||typeof g.manifestUrl!="string"||!g.manifestUrl)throw new Error("Tour upload did not return a manifest URL.");if(Fi(g)&&!window.confirm(Di(g))){Qe("Kept the current tour.");return}if(!await Hr(g.manifestUrl)){Qe("Could not load the uploaded tour.");return}if(typeof g.convertedSource=="string"){let b=URL.createObjectURL(new Blob([g.convertedSource],{type:"application/yaml"})),E=document.createElement("a");E.href=b,E.download=`${r.name.replace(/(?:\.bygone)?\.ya?ml$|\.bygone$/i,"")}.v4.bygone`,document.body.appendChild(E),E.click(),E.remove(),setTimeout(()=>URL.revokeObjectURL(b),1e3)}Qe("")}catch(r){Qe(`Could not open existing tour: ${r instanceof Error?r.message:String(r)}`)}}function re(){return!n.zoom||!!G()[n.zoom.mode]}function Ct(r){let a=n.authoredTour;if(G()[r])return{...a,opening:void 0,conclusion:void 0,details:void 0,...G()[r]};let u=r==="compare"&&n.compare?[...new Map([...n.compare.inventory||a.files,...n.compare.files].map(d=>[d.path,d])).values()]:r==="history"&&n.historyFiles||a.files;return{...a,opening:void 0,conclusion:void 0,details:void 0,scenes:[],chapters:[],files:u}}function ct(){let r=document.getElementById("tour-mode-controls");if(r.hidden=!n.zoom||ce,!n.zoom)return;be();let a=document.getElementById("tour-mode-tabs"),u=document.getElementById("tour-mode-description");a&&(a.hidden=!0),u&&(u.hidden=!0);let d=n.zoom.mode==="history",p=ae();document.getElementById("tour-history-controls").hidden=!p||n.zoom.mode==="compare",document.getElementById("tour-compare-controls").hidden=!p||n.zoom.mode!=="compare";let g=["historical","deconstructed"].includes(n.zoom.mode)&&!G()[n.zoom.mode];document.body.classList.toggle("workspace-empty-tour",g),document.body.classList.toggle("tour-derived-mode",!re()),re()||document.body.classList.remove("tour-discussion");for(let y of["tour-history-parent","tour-history-base"])document.getElementById(y).hidden=!d;dt()}function dt(){let r=n.comparisonDraftCommits,a=r.length,u=ae(),d=[...new Set(An())],p=E=>E.length===a&&E.every(P=>r.includes(P)),g=n.zoom?.mode==="compare"&&p(n.compare?.commits||[]);for(let E of["history","compare"])document.getElementById(`tour-${E}-count`).textContent=`${a} selected`,document.getElementById(`tour-${E}-hint`).textContent=a<2?"Select 2+ revisions":g?"Selection applied":E==="compare"?"Unapplied selection":"Ready to compare",document.getElementById(`tour-${E}-clear`).disabled=!a,document.getElementById(`tour-${E}-reset`).disabled=!d.length||p(d);document.getElementById("tour-history-compare").disabled=a<2||!u;let y=document.getElementById("tour-compare-apply");y.disabled=a<2||!u||g,y.title=g?"These revisions are already displayed":"Apply the selected revisions";let b=document.getElementById("tour-compare-scope");b.textContent=n.compare?.path||"All changed files",b.title=n.compare?.path?`File scope: ${n.compare.path}`:"Comparing across all changed files",document.getElementById("tour-compare-all").hidden=!n.compare?.path;for(let E of["tour-history-parent","tour-history-base"])document.getElementById(E).disabled=!ae()||!n.historyCommit}function $n(){return[...new Set([...[...n.historyEntries].reverse().map(r=>r.commit),n.authoredTour.range.mergeBaseOid,...n.authoredTour.commits.map(r=>r.oid),n.authoredTour.range.headOid])]}function Lr(r){return hi(r,$n())}async function we(r,a,u=n.historyPrefix,d=n.authoredTour){if(c)return c(r,a);if(!ae(d))throw new Error(je());let p=await fetch(`${u||"/history/"}${r}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),g=await p.json();if(!p.ok)throw new Error(g.error||`History request failed (${p.status}).`);return g}function fe(r){let a=r instanceof Error?r.message:String(r),u=document.getElementById("tour-mode-status");u&&(u.textContent=a),N&&Qe(a)}function An(){return n.displayedPanels.map(r=>r.commit).filter(Boolean)}function Oi(){let r=n.tour?.scenes[n.activeSceneIndex],a=n.zoom?.mode==="compare"?n.comparisonCommits:[n.authoredTour.range.mergeBaseOid,n.authoredTour.range.headOid];if(n.directoryEvidence&&Me(r)){let u=Ft(r),d=r.overview?.comparison;a=r.kind==="deconstructed-diff"?[]:[(d?u.find(p=>p.id===d.from):u[0])?.oid,(d?u.find(p=>p.id===d.to):u.at(-1))?.oid]}return["left","right"].map((u,d)=>({id:u,commit:a[d]}))}function Nr(){let r=n.displayedPanels.map(a=>a.commit);return{...Tt(Nn({commits:An()}),r,null),navigatorOnly:!0}}async function Bi(r){if(!r||!n.zoom||!ae())return[];if(!n.fileHistoryCache.has(r)){let a=we("list",{path:r,commit:n.authoredTour.range.headOid}).then(u=>u.entries);n.fileHistoryCache.set(r,a),a.catch(()=>n.fileHistoryCache.delete(r))}return n.fileHistoryCache.get(r)}async function Ui(r,a){try{let u=await Bi(r);if(a!==ge)return;se({type:"updateCommitMarkers",changedCommits:u.map(d=>d.commit),path:r})}catch(u){a===ge&&fe(u)}}async function et(r,a,u=!0){if(a=a||n.historyCommit||n.authoredTour.range.headOid,!r)return zi(a,u);let d=++oe,p=n.historyEntries,g=p.find(M=>M.commit===a);if(n.historyPath===r&&n.historyCommit===a&&n.historyPanels.length){await Wt();return}let y=await we("diff",{path:r,commit:a,head:n.authoredTour.range.headOid});if(d!==oe||n.zoom.mode!=="history")return;if(u&&n.historyPanels.length&&n.historyCommit===a){let M=await Promise.all(n.historyPanels.map(async z=>{let L=z.commit===a?{rightContent:y.rightContent,path:y.path}:z.commit===y.parentCommit?{rightContent:y.leftContent,path:y.previousPath||y.path}:z.commit?await we("diff",{path:r,commit:z.commit,head:n.authoredTour.range.headOid}):{rightContent:"",path:r};return{...z,content:L.rightContent,path:L.path}}));if(d!==oe||n.zoom.mode!=="history")return;n.historyPanels=M,n.historyPath=r,n.historyDiff=y,await Wt(),Se();return}let b=p.findIndex(M=>M.commit===a),P=(b>=0?p[b+1]:null)?.commit||y.parentCommit,R=P&&P!==y.parentCommit?(await we("diff",{path:r,commit:P,head:n.authoredTour.range.headOid})).rightContent:y.leftContent;if(d!==oe||n.zoom.mode!=="history")return;n.historyPath=r,n.historyCommit=a;let U=Math.max(2,n.historyPanels.length);n.historyDiff=y;let F=(M,z,L)=>({id:`history-${M||"empty"}`,commit:M,content:z,label:L,path:y.path,editable:!1});for(n.historyPanels=[F(P,R,P?.slice(0,7)||"Empty tree"),F(a,y.rightContent,g?`${g.shortCommit} ${g.summary}`:a.slice(0,7))],n.historyFocus=`history-${a}`;n.historyPanels.length<U;){let M=Kt(n.historyPanels[0],"left");if(!M)break;let z=await we("diff",{path:r,commit:M.commit,head:n.authoredTour.range.headOid});if(d!==oe||n.zoom.mode!=="history")return;n.historyPanels.unshift(F(M.commit,z.rightContent,`${M.shortCommit} ${M.summary}`))}await Wt(),document.getElementById("tour-mode-status").textContent="",dt(),Se()}async function zi(r=n.historyCommit||n.authoredTour.range.headOid,a=!0){let u=++oe,d=n.historyEntries.find(y=>y.commit===r);if(!d)throw new Error("The selected revision is unavailable in this history.");let p=a&&n.historyCommit===r&&n.historyPanels.length?n.historyPanels:[d.parentCommit||null,r].map(y=>({id:`history-${y||"empty"}`,commit:y,content:"",editable:!1,label:y?y.slice(0,7):"Empty tree"})),g=await we("changed-files",{commits:p.map(y=>y.commit||null),includeEntries:!0,includeFiles:!0});u!==oe||n.zoom.mode!=="history"||(n.historyCommit=r,n.historyPanels=p,n.historyFocus=p.at(-1).id,n.historyPath=null,n.historyChangedFiles=new Set(g.paths),n.historyFiles=g.files,n.tour.files=g.files,Un(),n.activeTourFilePath=null,pe(),se({...sn(p.map(y=>y.label),g.entries),history:Tt(Rr(n.historyEntries,r,{}),p.map(y=>y.commit),r)}),Ge(g.paths.length?"":"No changed files for the selected revisions."),dt(),Se())}function Rr(r,a,u){let d=r.findIndex(g=>g.commit===a),p=r[d];return{fileName:(n.historyPath||u.path||"Changed files").split("/").pop(),canGoBack:d>=0&&d<r.length-1,canGoForward:d>0,positionLabel:`${d+1} / ${r.length}`,leftCommitLabel:n.historyPanels[0]?.commit?.slice(0,7)||"Empty tree",leftTimestamp:"",rightCommitLabel:n.historyPanels.at(-1)?.label||(p?`${p.shortCommit} ${p.summary}`.trim():a.slice(0,7)),rightTimestamp:p?.timestamp||"",workingTreeControls:!1,rail:{activeTabId:"history",tabs:[{id:"history",label:"History"}],itemsByTab:{history:[]}}}}function Kt(r,a){let u=$n(),d=u.indexOf(r.commit);if(d<0)return null;let p=new Set(n.historyPanels.map(b=>b.commit)),y=(a==="left"?u.slice(0,d).reverse():u.slice(d+1)).find(b=>!p.has(b)&&n.historyEntries.some(E=>E.commit===b));return n.historyEntries.find(b=>b.commit===y)}function Tt(r,a,u){return r.rail.itemsByTab.history=po(n.historyEntries,{displayed:a,active:u,selected:n.comparisonDraftCommits,tourCommits:new Set(n.authoredTour?.commits.map(d=>d.oid)),selectionEnabled:!!n.zoom,missingRevisionSelectionEnabled:!!n.zoom,missingRevisionLabel:d=>d?`${d.slice(0,7)} \xB7 Parent/base revision`:"Empty tree"}).map(d=>({...d,meta:d.parents.length>1?`${d.meta} \xB7 Merge: ${d.parents.map(p=>p.slice(0,7)).join(", ")}`:d.meta})),r}async function Wt(){let r=n.historyPanels,a=n.authoredTour,u=oe,d=await we("changed-files",{commits:r.map(y=>y.commit||null),includeFiles:!0});if(u!==oe||r!==n.historyPanels||a!==n.authoredTour||n.zoom.mode!=="history")return;n.historyChangedFiles=new Set(d.paths),n.historyFiles=d.files,n.tour.files=d.files,Un();let p=n.historyPanels.map(y=>({...y,addLeftEnabled:!!Kt(y,"left"),addRightEnabled:!!Kt(y,"right"),removeEnabled:n.historyPanels.length>2})),g=p.find(y=>y.id===n.historyFocus)?.commit;n.activeTourFilePath=n.historyPath,pe(),se({...an({panels:p,files:Xt(),activePanelId:n.historyFocus,mutationEnabled:!0,canReturnToDirectory:!0},(y,b)=>ke(y.content,b.content)),history:Tt(Rr(n.historyEntries,n.historyCommit,n.historyDiff),p.map(y=>y.commit),g)})}async function qi(r){let a=n.historyPanels.find(u=>u.id===(r.anchorPanelId||r.panelId));if(a){if(r.type==="multiRemovePanel"){if(n.historyPanels.length<=2)return;++oe,n.historyPanels=n.historyPanels.filter(u=>u!==a),n.historyFocus===a.id&&(n.historyFocus=n.historyPanels.at(-1).id)}else{let u=Kt(a,r.side);if(!u)return;let d=++oe,p=await we("diff",{path:n.historyPath,commit:u.commit,head:n.authoredTour.range.headOid});if(d!==oe||n.zoom.mode!=="history")return;let g={id:`history-${u.commit}`,commit:u.commit,content:p.rightContent,label:`${u.shortCommit} ${u.summary}`,path:p.path,editable:!1};n.historyPanels.push(g);let y=$n();n.historyPanels.sort((b,E)=>y.indexOf(b.commit)-y.indexOf(E.commit)),n.historyFocus=g.id}await Wt()}}function Ln(r){let a=n.historyEntries.findIndex(d=>d.commit===n.historyCommit),u=n.historyEntries[a+r];if(u)return et(n.historyPath,u.commit,!1)}function Nn(r){let a=r.commits;return{fileName:(r.path||n.activeTourFilePath||"Comparison").split("/").pop(),canGoBack:!1,canGoForward:!1,positionLabel:`${r.commits.length} loaded panels`,leftCommitLabel:a[0]?.slice(0,7)||"",leftTimestamp:"",rightCommitLabel:a.at(-1)?.slice(0,7)||"",rightTimestamp:"",workingTreeControls:!1,rail:{activeTabId:"history",tabs:[{id:"history",label:"History"}],itemsByTab:{history:[]}}}}function Pr(r,a=null){if(!r||r.kind!=="text-diff")return!1;Ge("");let u=r.comparisonPanels;return a=a||n.comparisonFocus,n.comparisonFocus=a,n.activeTourFilePath=r.path,pe(),se({...an({panels:u,files:Xt(),activePanelId:a?`compare-${a}`:null,mutationEnabled:!1,reorderEnabled:!1,canReturnToDirectory:!0},(d,p)=>ke(d.content,p.content)),history:Tt(Nn(n.compare),n.compare.commits,a)}),Se(),!0}async function Fr(r,a=null){let u=++oe;if(!r.comparisonPanels){let d;try{d=await we("compare-many",{commits:n.compare.commits,path:r.path})}catch(y){if(u!==oe)return!1;throw y}if(u!==oe||n.zoom?.mode!=="compare")return!1;let p=n.tour.files.findIndex(y=>y.path===r.path),g=d.files.find(y=>y.path===r.path)||d.files[0];if(!g)return document.getElementById("tour-mode-status").textContent="This file is absent from the selected revisions.",!1;r={...g,path:r.path},n.tour.files[p]=r,pe(),r.kind==="omitted"&&(document.getElementById("tour-mode-status").textContent=r.reason)}return Pr(r,a)}async function Dr(r,a,u=null){r=Lr(r);let d=++oe,p=await we("compare-many",r),g=ae()?await we("changed-files",{commits:r.commits,includeFiles:!0}):null,y=new Set(g?.paths||p.files.map(P=>P.path));for(let P of p.files)P.comparisonPanels?.some(R=>y.has(R.path))&&y.add(P.path);if(d!==oe||n.zoom.mode!=="compare")return;let b=p.files;n.comparisonCommits=r.commits,n.compare={...r,files:b,inventory:g?.files,entries:p.entries,changedPaths:y},n.tour=Ct("compare"),n.activeSceneIndex=-1,n.tourFocusFilePath=null,lt(),ct(),tt();let E=n.tour.files.find(P=>P.kind==="text-diff"&&P.path===a)||b.find(P=>P.kind==="text-diff");if(le?.view==="directory")Rn();else if(E){if(!await Fr(E,u))return}else{n.activeTourFilePath=null;let P=r.commits.map(R=>({id:`compare-${R}`,commit:R,path:"No text changes",content:"",label:R.slice(0,7),editable:!1}));se({...an({panels:P,files:{paths:[],currentPath:null},mutationEnabled:!1,reorderEnabled:!1,canReturnToDirectory:!0},(R,U)=>ke(R.content,U.content)),history:Tt(Nn(r),r.commits,null)}),n.activeTourFilePath=null,le=null,pe()}document.getElementById("tour-mode-status").textContent=b.length?E?"":"Changed files cannot be displayed as text. See the file list for details.":"No changes between these revisions.",Se()}async function Ke(r){if(!ae()){Qe(De());return}n.zoomSwitching||(n.zoom.mode!=="compare"?await We("compare",r):await Dr(r,n.activeTourFilePath),Pt("commits"))}function Rn(){n.compare&&(n.activeTourFilePath=null,pe(),se(sn(n.compare.commits.map(r=>r.slice(0,7)),n.compare.entries)),Ge(n.compare.entries.length?"":"No changed files for the selected comparison."),Se())}function Pn(){return{commits:[n.authoredTour.range.mergeBaseOid,n.authoredTour.range.headOid]}}function Mr(){return n.historyEntries.find(r=>r.commit===n.historyCommit)?.path||n.historyPath}function We(r,a,u){let d=m.then(()=>Hi(r,a,u));return m=d.catch(()=>{}),d}async function Hi(r,a,u){if(!n.zoom||n.zoomSwitching||r===n.zoom.mode||!de().includes(r))return;n.zoomSwitching=!0,++oe;let d=n.zoom.mode,p;try{p=await _e(),n.zoom.depart(p),Q.stop();let g=n.zoom.enter(r,r==="history"?p:null);if(n.tourNavigatorTab=g.restore?g.location.navigatorTab||"commits":re()?"tour":"commits",n.activeSceneIndex=-1,n.activeStepIndex=0,n.narrativeParent=null,n.directoryEvidence=null,n.sceneIntroVisible=!1,n.tourFocusFilePath=null,n.tour=Ct(r),lt(),tt(),ct(),document.getElementById("tour-mode-status").textContent="",le=g.restore&&!a?g.location:null,r==="history")await et(u||(g.restore?g.location.path:null),n.historyCommit||g.location.commit);else if(r==="compare")await Dr(a||n.compare||Pn(),u||g.location.path||p.path);else if(G()[r]&&(ve(Math.max(0,g.location.sceneIndex),g.location.stepIndex,{zoomLanding:!0,showIntro:g.restore?g.location.sceneIntroVisible:!0,readingKey:g.restore?g.location.readingKey:"title"}),g.location.path&&n.activeTourFilePath!==g.location.path)){let y=n.tour.files.findIndex(b=>b.path===g.location.path);y>=0&&ft(y)}if(Se(),l&&!s){let y=new URL(window.location.href);y.hash=re()?nt(n.zoom.mode,pt(_.find(b=>b.key===n.readingKey))):"",window.history.replaceState(null,"",y)}}catch(g){le=null,n.zoom.enter(d),n.tour=Ct(d),p&&(n.activeSceneIndex=p.sceneIndex,n.activeStepIndex=p.stepIndex,n.activeTourFilePath=p.path,n.narrativeParent=p.narrativeParent,n.sceneIntroVisible=p.sceneIntroVisible,n.tourNavigatorTab=p.navigatorTab),lt(),ct(),tt(),p&&re()&&(le=p,ve(p.sceneIndex,p.stepIndex,{zoomLanding:!0,showIntro:p.sceneIntroVisible,readingKey:p.readingKey}),p.path&&n.activeTourFilePath!==p.path&&ft(n.tour.files.findIndex(y=>y.path===p.path))),pe(),Se(),fe(g)}finally{n.zoomSwitching=!1}}async function _i(r){if(!(!r||typeof r!="object")){if(r.type==="navigationState"){Te.get(r.requestId)?.(r.navigation);return}if(r.type==="renderComplete"&&n.mode==="tour"&&r.renderRequestId===ge&&Ui(n.activeTourFilePath,ge),r.type==="renderComplete"&&le&&r.renderRequestId===Pe){let a=le;le=null,se({type:"restoreNavigationState",navigation:a.navigation});let u=document.getElementById("tour-narrative-content");u&&(u.scrollTop=a.narrativeScroll||0,X=u.scrollTop),a.focusId&&document.getElementById(a.focusId)?.focus({preventScroll:!0})}if(r.type==="ready"){let a=new URLSearchParams(window.location.search),u=a.get("manifest");u||o?Hr(u):a.get("demo")==="1"&&co();return}if(n.mode==="tour"&&n.directoryEvidence&&re()){if(r.type==="openDirectoryEntry"){qn(r.relativePath);return}if(r.type==="returnToDirectory"){zn();return}}if(n.mode==="tour"){if(n.zoom?.mode==="compare"&&["openDirectoryEntry","returnToDirectory"].includes(r.type)){if(Ee(),r.type==="returnToDirectory")Rn();else{let a=n.compare.files.find(u=>u.path===r.relativePath);a?.kind==="text-diff"?Pr(a):a&&Ge(`${a.path}: ${a.reason||"This file cannot be displayed as text."}`)}return}if(r.type==="multiMovePanel")return;if(n.zoom?.mode==="history"&&["openDirectoryEntry","returnToDirectory","navigateFile"].includes(r.type)){Ee();let a=Xt();r.type==="openDirectoryEntry"&&(a.paths=[...n.historyChangedFiles]);let u=fo(r,a,!0);u&&et(u.path,n.historyCommit).catch(fe);return}if(n.zoom?.mode==="history"&&["multiAddPanel","multiRemovePanel"].includes(r.type)){qi(r).catch(fe);return}if(r.type==="multiSetActivePair"||r.type==="multiSetActivePanel"){re()&&Number.isInteger(r.pairIndex)&&(document.getElementById("file-info").textContent=Hn(n.activeTourFilePath,r.pairIndex)),n.zoom?.mode==="history"?n.historyFocus=r.type==="multiSetActivePanel"?r.panelId:n.historyPanels[r.pairIndex]?.id||n.historyFocus:n.zoom?.mode==="compare"&&(n.comparisonFocus=r.type==="multiSetActivePanel"?r.panelId.replace(/^compare-/,""):n.comparisonCommits[r.pairIndex]);return}if(r.type==="historyBack"||r.type==="historyForward"){if(n.zoom?.mode!=="history")return;let a=Ln(r.type==="historyBack"?1:-1);a&&a.catch(fe);return}if(r.type==="toggleHistorySelection"&&Number.isInteger(r.index)){let a=n.displayedPanels.map(p=>p.commit),u=r.index<0?{commit:a[-r.index-1]}:n.historyEntries[r.index];if(!u?.commit)return;let d=n.comparisonDraftCommits.includes(u.commit)?n.comparisonDraftCommits.filter(p=>p!==u.commit):[...n.comparisonDraftCommits,u.commit];n.comparisonDraftCommits=d.length>=2?Lr({commits:d}).commits:d,dt();return}if(r.type==="compareHistoryEntry"&&Number.isInteger(r.index)){let a=n.historyEntries[r.index];a?.parentCommit&&Ke({commits:[a.parentCommit,a.commit],path:n.activeTourFilePath}).catch(fe);return}if(r.type==="selectHistoryEntry"&&Number.isInteger(r.index)){let a=n.historyEntries[r.index];if(a&&n.zoom?.mode==="history"){let u=n.historyPanels.find(d=>d.commit===a.commit);u&&n.historyPath?(n.historyFocus=u.id,se({type:"focusHistoryPanel",panelId:u.id})):et(n.historyPath,a.commit,!1).catch(fe)}if(a&&n.zoom?.mode!=="history"){let u=n.displayedPanels.find(d=>d.commit===a.commit);u?se({type:"focusHistoryPanel",panelId:u.id}):(n.historyCommit=a.commit,n.historyPath=n.activeTourFilePath||n.historyPath,We("history",void 0,n.activeTourFilePath).catch(fe))}return}}if(r.type==="navigateFile"&&n.mode==="tour"){Xr(r.direction==="previous"?-1:1);return}if(r.type==="navigateTourStep"&&n.mode==="tour"){let a=r.sceneIndex,u=r.stepIndex;Number.isInteger(a)&&Number.isInteger(u)&&ve(a,u,{userNavigation:!0,showIntro:!1});return}r.type==="recomputeDiff"&&n.mode==="diff"&&n.left&&n.right&&(n.left.content=r.leftContent,n.right.content=r.rightContent,se({type:"showDiff",file1:n.left.name,file2:n.right.name,comparisonId:`web-${n.comparisonId}`,leftContent:n.left.content,rightContent:n.right.content,diffModel:ke(n.left.content,n.right.content),history:null}))}}function ji(){let r=(T,W)=>document.getElementById(T)?.addEventListener("click",()=>{Promise.resolve().then(W).catch(fe)});for(let T of["explain","question"])r(`tour-feedback-${T}`,()=>{if(!re())return;let W=_.find(Z=>Z.key===n.readingKey);W&&$i(T,()=>Ci(n.tour,W,{mode:n.zoom?.mode||"historical",location:no(pt(W)),imageVisible:t.isVisible(),displayedEvidence:document.body.classList.contains("tour-discussion")||t.isVisible()?null:Ie?.tour===n.tour?Ie.context:null}))});let a=[...document.querySelectorAll(".tour-selection-more")],u=(T,W=!1)=>{T.open=!1,W&&T.querySelector("summary").focus()};for(let T of a)T.addEventListener("click",W=>{W.target.closest("button")&&u(T,!0)});document.addEventListener("click",T=>{for(let W of a)W.open&&!W.contains(T.target)&&u(W)}),document.addEventListener("keydown",T=>{if(T.key==="Escape")for(let W of a)W.open&&(T.preventDefault(),u(W,!0))}),r("tour-history-compare",()=>Ke({commits:n.comparisonDraftCommits})),r("tour-compare-apply",()=>Ke({commits:n.comparisonDraftCommits,path:n.compare?.path})),r("tour-history-parent",()=>{let T=n.historyEntries.find(W=>W.commit===n.historyCommit)?.parentCommit;if(!T){fe("This is the first commit; History already shows its comparison with the empty tree.");return}return Ke({commits:[T,n.historyCommit],path:Mr()})}),r("tour-history-base",()=>Ke({commits:[n.authoredTour.range.mergeBaseOid,n.historyCommit],path:Mr()})),r("tour-history-final",()=>Ke(Pn())),r("tour-compare-final",()=>Ke(Pn())),r("tour-compare-all",()=>Ke({commits:n.compare.commits}));let d=T=>{n.comparisonDraftCommits=T.filter(Boolean),dt(),se({type:"updateHistorySelection",commits:n.comparisonDraftCommits})};for(let T of["history","compare"])r(`tour-${T}-clear`,()=>d([])),r(`tour-${T}-reset`,()=>d(An()));for(let T of["wheel","pointerdown","keydown"])document.addEventListener(T,W=>{!W.isTrusted||W.target?.closest?.("#tour-mode-controls")||W.target?.closest?.(".monaco-editor, .diff-toolbar, #tour-narrative")&&Ee()},{capture:!0,passive:!0});let p=document.getElementById("web-compare-test"),g=document.getElementById("web-open-diff"),y=document.getElementById("web-open-diff3"),b=document.getElementById("web-diff-input"),E=document.getElementById("web-diff3-input"),P=document.getElementById("tour-narration"),R=document.getElementById("tour-return-focus"),U=document.getElementById("tour-search-input"),F=document.getElementById("tour-search-scope"),M=document.getElementById("tour-listen"),z=document.getElementById("tour-stop"),L=document.getElementById("tour-narration-skip-back"),H=document.getElementById("tour-narration-skip-ahead"),K=document.getElementById("tour-narration-voice"),q=document.getElementById("tour-narration-rate");ts(),document.getElementById("tour-show-all-files")?.addEventListener("change",T=>{re()?n.showAllTourFiles=T.target.checked:n.showAllFiles=T.target.checked,pe()}),document.getElementById("tour-files")?.addEventListener("toggle",T=>{let W=T.target;!(W instanceof HTMLDetailsElement)||!W.dataset.fileFolder||!W.isConnected||(W.open?n.collapsedFileFolders.delete(W.dataset.fileFolder):n.collapsedFileFolders.add(W.dataset.fileFolder))},!0),rs(),is(),Ki(),document.getElementById("correspondence-filter")?.addEventListener("input",Lt),document.getElementById("correspondence-context")?.addEventListener("click",()=>Gt(!0)),document.getElementById("file-symbol-context")?.addEventListener("click",()=>Gt(!!(n.activeCorrespondenceId&&!n.symbolContext))),document.getElementById("correspondence-all")?.addEventListener("change",Lt),document.getElementById("correspondence-unmatched")?.addEventListener("change",Lt),document.getElementById("tour-navigator-tabs")?.addEventListener("click",T=>{let W=T.target instanceof Element?T.target.closest("[data-tour-navigator]"):null;W?.dataset.tourNavigator&&Pt(W.dataset.tourNavigator)}),p?.addEventListener("click",()=>{co()}),g?.addEventListener("click",()=>{b.value="",b.click()}),y?.addEventListener("click",()=>{E.value="",E.click()}),b?.addEventListener("change",async()=>{let T=Array.from(b.files||[]);if(T.length!==2){Le("Select exactly 2 files for a diff.");return}await Is(T)}),E?.addEventListener("change",async()=>{let T=Array.from(E.files||[]);if(T.length<1){Le("Select one or more files.");return}await Ss(T)}),document.getElementById("tour-title")?.addEventListener("click",()=>en("tour")),document.getElementById("tour-narrative-content")?.addEventListener("scroll",vs,{passive:!0}),document.getElementById("tour-back")?.addEventListener("click",()=>Yt(-1)),document.getElementById("tour-next")?.addEventListener("click",()=>Yt(1)),P?.addEventListener("click",()=>ms()),R?.addEventListener("click",ls),document.getElementById("tour-directory-root")?.addEventListener("click",()=>{en("scene"),document.getElementById("tour-directory-root").focus({preventScroll:!0})}),U?.addEventListener("input",tt),F?.addEventListener("change",tt),M?.addEventListener("click",Or),z?.addEventListener("click",()=>Q.stop()),L?.addEventListener("click",()=>Q.skipSegment(-1)),H?.addEventListener("click",()=>Q.skipSegment(1)),K?.addEventListener("change",()=>{n.narrationVoiceURI=K.value,i.setItem(I,n.narrationVoiceURI)}),q&&(q.value=String(n.narrationRate),q.addEventListener("change",()=>{let T=Number(q.value);n.narrationRate=D.has(T)?T:1,q.value=String(n.narrationRate),i.setItem($,String(n.narrationRate))})),document.getElementById("tour-search-results")?.addEventListener("click",T=>{let W=T.target instanceof Element?T.target.closest("[data-tour-search-result]"):null;W&&es(Number(W.getAttribute("data-tour-search-result")))}),window.addEventListener("keydown",T=>{if(n.mode==="tour"&&(T.metaKey||T.ctrlKey)&&T.shiftKey&&T.key.toLocaleLowerCase()==="f"){T.preventDefault(),T.stopImmediatePropagation(),n.tourSidebarHidden&&Mn(!1),Pt("tour"),document.querySelector(".tour-search-disclosure")?.setAttribute("open",""),U?.focus(),U?.select();return}n.mode!=="tour"||T.metaKey||T.ctrlKey||T.altKey||ps(T.target)||(T.key==="PageUp"||T.key==="ArrowLeft"?(T.preventDefault(),n.zoom?.mode==="history"?Ln(1)?.catch(fe):Yt(-1)):T.key==="PageDown"||T.key==="ArrowRight"?(T.preventDefault(),n.zoom?.mode==="history"?Ln(-1)?.catch(fe):Yt(1)):n.zoom?.mode==="history"&&["ArrowUp","ArrowDown"].includes(T.key)&&(T.preventDefault(),Xr(T.key==="ArrowUp"?-1:1)))},!0),window.addEventListener("bygone:tour-command",T=>{T.detail==="toggleNarration"&&Or(),T.detail==="pauseNarration"&&Q.pauseForExternalOwner()}),window.addEventListener("beforeunload",()=>Q.dispose(),{once:!0}),Fn(Q.state)}function Ki(){let r=document.getElementById("tour-narration-voice"),a=document.getElementById("tour-listen");if(!A){a&&(a.disabled=!0,a.title="Device narration is not supported by this browser."),r&&(r.disabled=!0),$t("Device narration unavailable");return}let u=()=>{if(n.narrationVoices=window.speechSynthesis.getVoices().filter(d=>!o||d.localService).slice().sort((d,p)=>Number(p.default)-Number(d.default)||d.lang.localeCompare(p.lang)||d.name.localeCompare(p.name)),n.narrationVoiceURI&&n.narrationVoices.length>0&&!n.narrationVoices.some(d=>d.voiceURI===n.narrationVoiceURI)&&(n.narrationVoiceURI="",i.removeItem(I)),r){let d=document.createElement("option");d.value="",d.textContent="System default voice",r.replaceChildren(d,...n.narrationVoices.map(p=>{let g=document.createElement("option");return g.value=p.voiceURI,g.textContent=`${p.name} (${p.lang})${p.default?" \u2014 default":""}`,g})),r.value=n.narrationVoiceURI,r.disabled=n.narrationVoices.length===0}};u(),window.speechSynthesis.addEventListener("voiceschanged",u)}function Wi(){let r=Number(i.getItem($));return D.has(r)?r:1}function Gi(){let r=null;return{speak(a,u){if(!A){u.onError("Device narration is not supported by this browser.");return}let d=new window.SpeechSynthesisUtterance(a.speechText),p=n.narrationVoices.find(g=>g.voiceURI===n.narrationVoiceURI)||(o?n.narrationVoices[0]:null);if(o&&!p){u.onError("No local narration voice is available.");return}p&&(d.voice=p),d.rate=n.narrationRate,d.onend=()=>{r===d&&(r=null),u.onEnd()},d.onerror=g=>{r===d&&(r=null),u.onError(Vi(g.error))},r=d,window.speechSynthesis.speak(d)},pause(){A&&window.speechSynthesis.pause()},resume(){A&&window.speechSynthesis.resume()},cancel(){r=null,A&&window.speechSynthesis.cancel()}}}function Vi(r){return r==="not-allowed"?"Device narration needs permission to play audio.":r==="language-unavailable"||r==="voice-unavailable"?"The selected device voice is unavailable.":`Device narration failed${r?`: ${r}`:"."}`}function Ji(){if(!A||n.mode!=="tour")return;let r=Br("playback-start");r&&(n.renderedNarrationUnit=r,hs(r),Q.start(r,!0))}function Or(){Q.state.kind==="playing"||Q.state.kind==="paused"?Q.togglePause():Ji()}function Br(r){let a=_.find(u=>u.key===n.readingKey);return n.tour&&a?ci(n.tour,a,{entry:r}):null}function Yi(r,a){return!!(n.tour&&Ht(_,r.readingKey,a,st(n.tour)))}function Xi(r,a){if(!n.tour)return null;let u=Ht(_,r.readingKey,a,st(n.tour));return u?ve(u.sceneIndex,u.stepIndex,{readingKey:u.key,narrationNavigation:"controller",narrationEntry:"continuous"}):null}function Zi(){o||fetch("/narration/claim",{method:"POST",cache:"no-store"}).catch(()=>{})}function Fn(r){let a=document.getElementById("tour-listen"),u=document.getElementById("tour-stop"),d=document.getElementById("tour-narration-skip-back"),p=document.getElementById("tour-narration-skip-ahead");if(a){a.disabled=!A||n.mode!=="tour";let g=r.kind==="playing";a.querySelector(".tour-play-pause-icon")?.setAttribute("d",g?"M7 5h4v14H7zM13 5h4v14h-4z":"m8 5 11 7-11 7Z");let y=g?"Pause narration":r.kind==="paused"?"Resume narration":"Listen from the current tour item";a.title=y,a.setAttribute("aria-label",y),document.getElementById("tour-listen-label").textContent=g?"Pause":r.kind==="paused"?"Resume":"Listen"}if(u&&(u.disabled=r.kind!=="playing"&&r.kind!=="paused"),d&&(d.disabled=!Q.canSkipSegment(-1)),p&&(p.disabled=!Q.canSkipSegment(1)),r.kind==="playing"||r.kind==="paused"){let g=r.segmentIndex+1,y=r.unit.segments.length;$t(`${r.kind==="paused"?"Paused":"Speaking"} \xB7 segment ${g} of ${y}`)}else r.kind==="completed"?$t("Narration complete"):r.kind==="error"?$t(r.message):A&&$t("Device voice ready")}function $t(r){let a=document.getElementById("tour-narration-status");a&&(a.textContent=r)}function Qi(r,a){if(document.querySelectorAll(".tour-narration-segment.is-speaking").forEach(b=>{b.classList.remove("is-speaking","is-paused")}),!r)return;let u=[...document.querySelectorAll("[data-narration-segment-id]")].filter(b=>b.dataset.narrationSegmentId===r.id),d=u[0];if(!d||(u.forEach(b=>{b.classList.add("is-speaking"),b.classList.toggle("is-paused",a)}),a))return;let p=document.getElementById("tour-narrative-content");if(!p)return;let g=d.getBoundingClientRect(),y=p.getBoundingClientRect();(g.top<y.top+tn()||g.bottom>y.bottom)&&(d.scrollIntoView({block:"nearest"}),X=p.scrollTop)}let At=[];function tt(){let r=document.getElementById("tour-search-input"),a=document.getElementById("tour-search-scope"),u=document.getElementById("tour-search-status"),d=document.getElementById("tour-search-results");if(!(!n.tour||!r||!a||!u||!d)){if(At=li(n.tour,r.value,a.value),!r.value.trim()){u.textContent="Cmd/Ctrl+Shift+F",d.replaceChildren();return}u.textContent=`${At.length} result${At.length===1?"":"s"}`,d.replaceChildren(...At.map((p,g)=>{let y=document.createElement("button");y.type="button",y.className="tour-search-result",y.setAttribute("role","option"),y.dataset.tourSearchResult=String(g),y.title=`Open ${p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label}`;let b=document.createElement("span");b.className="tour-search-location",b.textContent=p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label;let E=document.createElement("span");return E.className="tour-search-preview",E.textContent=p.preview.trim(),y.append(b,E),y}))}}function es(r){let a=At[r];if(a){if(a.kind==="narrative"){Ee(),ve(a.sceneIndex,a.stepIndex??0,{readingKey:a.readingKey,showIntro:a.stepIndex===void 0});return}_n(a.fileIndex)&&window.requestAnimationFrame(()=>se({type:"revealSearchResult",sideIndex:a.sideIndex,lineNumber:a.lineNumber,startColumn:a.startColumn,endColumn:a.endColumn}))}}function ts(){let r=document.getElementById("tour-shell"),a=document.getElementById("tour-sidebar-resizer"),u=document.getElementById("tour-sidebar-hide"),d=document.getElementById("tour-sidebar-show");!r||!a||!u||!d||(zr(),u.addEventListener("click",()=>Mn(!0)),d.addEventListener("click",()=>Mn(!1)),a.addEventListener("pointerdown",p=>{p.preventDefault(),document.body.classList.add("is-resizing-tour-sidebar"),a.setPointerCapture?.(p.pointerId);let g=b=>Ur(b.clientX),y=()=>{document.body.classList.remove("is-resizing-tour-sidebar"),window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",y),window.removeEventListener("pointercancel",y),i.setItem(w,String(n.tourSidebarWidth))};window.addEventListener("pointermove",g),window.addEventListener("pointerup",y),window.addEventListener("pointercancel",y)}),a.addEventListener("keydown",p=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(p.key))return;p.preventDefault();let g=n.tourSidebarWidth;p.key==="Home"?g=v:p.key==="End"?g=Dn():g+=p.key==="ArrowLeft"?-16:16,Ur(g),i.setItem(w,String(n.tourSidebarWidth))}))}function ns(){let r=Number.parseInt(i.getItem(w)||"",10);return Number.isFinite(r)?Math.min(k,Math.max(v,r)):300}function Dn(){return Math.max(v,Math.min(k,Math.floor(window.innerWidth*.6)))}function Ur(r){n.tourSidebarWidth=Math.min(Dn(),Math.max(v,Math.round(r))),zr(),window.dispatchEvent(new Event("resize"))}function zr(){document.documentElement.style.setProperty("--tour-rail-width",`${n.tourSidebarWidth}px`);let r=document.getElementById("tour-sidebar-resizer");r?.setAttribute("aria-valuemax",String(Dn())),r?.setAttribute("aria-valuenow",String(n.tourSidebarWidth))}function Mn(r){n.tourSidebarHidden=r,document.body.classList.toggle("tour-sidebar-hidden",r);let a=document.getElementById("tour-sidebar-show");a&&(a.hidden=!r),window.dispatchEvent(new Event("resize"))}function rs(){let r=document.getElementById("tour-narrative-resizer");r&&(Bn(),r.addEventListener("pointerdown",a=>{if(a.button!==0)return;a.preventDefault(),document.body.classList.add("is-resizing-tour-narrative"),r.setPointerCapture?.(a.pointerId),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-start"));let u=document.getElementById("tour-narrative").getBoundingClientRect().top,d=g=>qr(g.clientY-u),p=()=>{document.body.classList.remove("is-resizing-tour-narrative"),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",p),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-end")),i.setItem(x,String(n.tourNarrativeHeight))};window.addEventListener("pointermove",d),window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p)}),r.addEventListener("keydown",a=>{if(!["ArrowUp","ArrowDown","Home","End"].includes(a.key))return;a.preventDefault();let u=a.key==="Home"?C:a.key==="End"?On():n.tourNarrativeHeight+(a.key==="ArrowUp"?-16:16);qr(u),i.setItem(x,String(n.tourNarrativeHeight))}),window.addEventListener("resize",Bn))}function os(){let r=Number.parseInt(i.getItem(x)||"",10);return Number.isFinite(r)?r:Math.min(window.innerHeight*.38,360)}function On(){return Math.max(C,window.innerHeight-document.getElementById("tour-mode-controls").offsetHeight-S)}function qr(r){n.tourNarrativeHeight=r,Bn()}function Bn(){n.tourNarrativeHeight=Math.min(On(),Math.max(C,Math.round(n.tourNarrativeHeight))),document.getElementById("tour-narrative").style.height=`${n.tourNarrativeHeight}px`;let r=document.getElementById("tour-narrative-resizer");r?.setAttribute("aria-valuemax",String(On())),r?.setAttribute("aria-valuenow",String(n.tourNarrativeHeight)),r&&(r.style.top=`calc(var(--workspace-toolbar-height, 0px) + ${n.tourNarrativeHeight-4}px)`)}function is(){let r=document.getElementById("tour-narrative");if(!r)return;let a=()=>{let u=r.hidden?0:Math.ceil(r.getBoundingClientRect().height);document.documentElement.style.setProperty("--tour-narrative-height",`${u}px`),so(),tn(),window.dispatchEvent(new Event("resize"))};new ResizeObserver(a).observe(r),a()}async function Hr(r){Le("Loading change tour\u2026");let a=Ri(r),u={...n,historyEntries:[...n.historyEntries],fileHistoryCache:new Map(n.fileHistoryCache),displayedPanels:[...n.displayedPanels],historyPanels:[...n.historyPanels],comparisonCommits:[...n.comparisonCommits],comparisonDraftCommits:[...n.comparisonDraftCommits]},d=document.body.className,p=document.getElementById("tour-shell")?.hidden,g=document.getElementById("tour-narrative")?.hidden,y=document.getElementById("tour-mode-controls")?.hidden,b=ge,E=le,P=Pe,R=oe;try{Q.stop();let U=o?.manifest;if(!o){let W=await fetch(r,{cache:"no-store"});if(!W.ok)throw new Error(`Manifest request failed (${W.status}).`);U=await W.json()}let F=ei(U,{exported:!!o}),M=null;if(!o&&new URLSearchParams(window.location.search).has("correspondence")&&r==="/tour.json"){let W=await fetch("/correspondence.json",{cache:"no-store"});if(!W.ok)throw new Error(`Correspondence request failed (${W.status}).`);if(M=await W.json(),M.range.baseOid!==F.range.mergeBaseOid||M.range.headOid!==F.range.headOid)throw new Error("Correspondence revisions do not match this view.")}let z=Qn(window.location.hash);z&&Zn(F,z.mode,z.focus);let H=G(F).deconstructed?"deconstructed":"historical",K=ae(F)?(await we("list",{commit:F.range.headOid},a,F)).entries:[];n.tour=F,n.correspondence=M,n.collapsedSymbolNodes=new Set,n.activeCorrespondenceId=null,n.symbolSelection=null,n.expandedFileSymbols.clear(),document.getElementById("file-symbol-context").hidden=!0,document.getElementById("correspondence-context").hidden=!0,n.authoredTour=F,n.historyPrefix=a,n.zoom=new En(H),n.historyEntries=K,n.historyCommit=null,n.historyPath=null,n.historyPanels=[],n.historyFocus=null,n.historyDiff=null,n.historyChangedFiles=new Set,n.historyFiles=null,n.showAllFiles=!1,n.showAllTourFiles=!1,n.collapsedFileFolders=new Set,n.revealedFilePath=null,n.zoom&&(n.tour=Ct(H)),n.mode="tour",document.body.classList.add("tour-mode"),lt(),ct(),tt();let q=new URLSearchParams(window.location.search),T=xr(n.tour.scenes,q.get("scene"),q.get("step"));if(ve(T.sceneIndex,T.stepIndex,{showIntro:q.get("view")==="overview"||!q.get("step"),readingKey:!q.get("scene")&&!q.get("step")?"title":void 0}),["tour","chapter","conclusion"].includes(q.get("view"))&&en(q.get("view")),n.zoom){let Z={explanation:"deconstructed",revisions:"historical",final:Fe()?"historical":"compare"}[q.get("mode")]||q.get("mode");if(Z==="history"&&de().includes("history"))n.historyPath=q.get("file"),n.tourNavigatorTab="commits",n.zoom.enter("history"),n.tour=Ct("history"),lt(),ct(),await et(n.historyPath,q.get("commit"));else if(Z==="compare"&&de().includes("compare")){let ue=q.get("commits")?.split(",").filter(Boolean);await We("compare",{commits:ue?.length?ue:[q.get("from")||n.authoredTour.range.mergeBaseOid,q.get("to")||n.authoredTour.range.headOid],...q.get("scope")?{path:q.get("scope")}:{}},q.get("file")),q.get("view")==="directory"&&Rn()}else if(Z&&Z!==n.zoom.mode&&de().includes(Z)){await We(Z);let ue=xr(n.tour.scenes,q.get("scene"),q.get("step"));ve(ue.sceneIndex,ue.stepIndex,{showIntro:q.get("view")==="overview"||!q.get("step"),readingKey:!q.get("scene")&&!q.get("step")?"title":void 0}),["tour","chapter","conclusion"].includes(q.get("view"))&&en(q.get("view"))}let ie=He;He=null,ce&&ie&&ie!==n.zoom.mode&&de().includes(ie)&&await We(ie)}return n.directoryEvidence&&q.get("file")&&qn(q.get("file")),Fn(Q.state),n.workspacePromptStatus="",be(),Le(""),z?await ro(z):re()&&window.history.replaceState(null,"",nt(n.zoom.mode,pt(_.find(W=>W.key===n.readingKey)))),document.getElementById("export-loading")?.remove(),window.__BYGONE_EXPORT_READY__=!!o,l=!0,!0}catch(U){let F=document.getElementById("export-loading");F&&(F.textContent=`Could not open export: ${U.message}`),Object.assign(n,u),ge=b,le=E,Pe=P,oe=R,document.body.className=d;let M=document.getElementById("tour-shell");M&&p!==void 0&&(M.hidden=p);let z=document.getElementById("tour-narrative");z&&g!==void 0&&(z.hidden=g);let L=document.getElementById("tour-mode-controls");return L&&y!==void 0&&(L.hidden=y),n.mode==="tour"&&n.tour&&(lt(),ct(),tt(),be()),Le(`Could not load change tour: ${U instanceof Error?U.message:String(U)}`),!1}}function lt(){Zt();let r=n.tour;if(!r)return;let a=document.getElementById("tour-shell"),u=document.getElementById("tour-title"),d=document.getElementById("tour-source"),p=document.getElementById("tour-range"),g=document.getElementById("tour-stats"),y=document.getElementById("tour-authoring-coverage"),b=document.getElementById("tour-scenes"),E=document.getElementById("tour-scene-count"),P=document.getElementById("tour-files"),R=document.getElementById("tour-file-count");if(!a||!u||!d||!p||!g||!y||!b||!E||!P||!R)throw new Error("Presenter UI is incomplete.");a.hidden=!1,u.textContent=r.title,document.title=pi(r),r.sourceUrl?(d.href=r.sourceUrl,d.hidden=!1):(d.removeAttribute("href"),d.hidden=!0);let U=Qr(r.range.baseRef),F=Qr(r.range.headRef),M=r.range.headOid.slice(0,7);if(p.textContent=`${re()?"Tour range: ":""}${U} \u2192 ${F}${F===M?"":` \xB7 ${M}`}`,g.textContent=`${Dt(r.summary.changedFiles,"file")} \xB7 +${r.summary.additions} \u2212${r.summary.deletions} \xB7 ${Dt(r.summary.commitCount,"commit")}`,cs(y,r.authoringCoverage),Si(document.getElementById("tour-audience"),re()?r:null),E.textContent=re()&&r.scenes.length?String(r.scenes.length):"",R.textContent=String(r.files.length),b.replaceChildren(),re()){Wn();let L=Ve("Intro","Read the introduction and tour route",()=>Ae(_.find(H=>H.kind==="title")));L.className="tour-scene",L.dataset.readingLink="title",b.append(L)}let z=new Map(r.scenes.map(L=>[L.id,L]));for(let L of r.chapters){let H=eo(`chapter:${L.id}`,`${r.chapters.indexOf(L)+1}. ${L.title}`,"tour-chapter-link",()=>{let q=_.find(T=>T.kind==="chapter"&&T.chapterId===L.id)||_.find(T=>T.kind==="scene"&&L.sceneIds.includes(r.scenes[T.sceneIndex]?.id));q&&Ae(q)}),K=H.children;b.append(H.group);for(let q of L.sceneIds){let T=z.get(q);if(!T)continue;let W=r.scenes.indexOf(T),Z=eo(`scene:${T.id}`,T.title,"tour-scene",()=>ve(W,0,{userNavigation:!0,showIntro:!0})),ie=Z.link;ie.replaceChildren(),ie.dataset.sceneId=T.id,T.kind==="text-diff"&&(ie.dataset.filePath=T.path),Z.link.title=`Open scene: ${T.kind==="text-diff"?T.path:T.title}`;let ue=document.createElement("span");ue.className="tour-scene-copy";for(let[ye,xe]of[["tour-scene-title",`${W+1}. ${T.title}`],["tour-scene-path",T.kind==="text-diff"?T.path:T.kind==="deconstructed-diff"?`${Dt(T.panels.length-1,"comparison stage")} \xB7 ${Dt(T.steps.length,"tour slide")}`:$e(T)?Dt(T.steps.length,T.steps.every(Oe=>Oe.image)?"image":"step"):"Discussion"],["tour-scene-note",T.takeaway]]){let Oe=document.createElement("span");Oe.className=ye,Oe.textContent=xe,ue.append(Oe)}if(ie.append(ue),K.append(Z.group),$e(T)){let ye=Z.children;ye.classList.add("tour-outline-steps"),ye.dataset.sceneId=T.id,T.steps.forEach((xe,Oe)=>{let Je=document.createElement("button");Je.type="button",Je.className="tour-outline-step",Je.dataset.sceneId=T.id,Je.dataset.stepIndex=String(Oe);let Cs=T.kind==="deconstructed-diff"?`Stage ${(xe.stageIndex??xe.pairIndex)+1}: `:"";Je.textContent=`${Oe+1}. ${xe.title}`,Je.title=`${Cs}${xe.title}`,Je.addEventListener("click",()=>ve(W,Oe,{userNavigation:!0,showIntro:!1})),ye.append(Je)})}else Z.toggle.hidden=!0}}if(re()&&r.conclusion){let L=Ve("Conclusion",`Read ${r.conclusion.title}`,()=>Ae(_.find(H=>H.kind==="conclusion")));L.className="tour-scene",L.dataset.readingLink="conclusion",b.append(L)}Un(),Lt(),Pt(n.tourNavigatorTab)}function Lt(){let r=n.correspondence;document.getElementById("correspondence-tab").hidden=!r,document.getElementById("correspondence-availability").hidden=!!r;let a=document.getElementById("correspondence-list");if(a.replaceChildren(),!r)return;let u=document.getElementById("correspondence-filter").value.toLowerCase(),d=document.getElementById("correspondence-all").checked,p=document.getElementById("correspondence-unmatched")?.checked??!0,g=$r(r,{all:d,includeUnmatched:p,query:u});if(document.getElementById("correspondence-status").textContent=`${r.range.baseOid.slice(0,7)} \u2192 ${r.range.headOid.slice(0,7)} \xB7 ${r.status} analysis \xB7 ${g.matchingRelations} of ${r.relations.length} inferred mappings \xB7 ${g.matchingUnmatched} unmatched symbols \xB7 ${r.unresolved.length} ambiguous groups. Behavior unassessed.`,jr(a,g.files),_r(g),!g.files.length){let y=document.createElement("p");y.className="history-rail-empty",y.textContent=u.trim()?"No symbols match this filter.":"No symbols match the current filters. Enable the include options to see more inventoried declarations.",a.append(y)}as(r)}function _r(r=$r(n.correspondence,{all:document.getElementById("correspondence-all").checked,includeUnmatched:document.getElementById("correspondence-unmatched")?.checked??!0,query:document.getElementById("correspondence-filter").value})){document.querySelectorAll("#tour-files .file-symbols, #tour-files .file-symbol-toggle").forEach(a=>a.remove());for(let a of document.querySelectorAll("#tour-files .tour-file")){a.parentElement.classList.remove("has-file-symbols");let u=n.tour.files.find(E=>E.path===a.dataset.filePath),d=r.files.filter(E=>E.path===u?.path||E.path===u?.previousPath),p=d.length?{path:u.path,children:d.flatMap(E=>E.children)}:null;if(!p?.children.length)continue;let g=document.createElement("div");g.className="file-symbols",g.id=`file-symbols-${++Xe}`,jr(g,p.children);let y=document.createElement("button");y.type="button",y.className="file-symbol-toggle",y.setAttribute("aria-controls",g.id);let b=()=>{let E=n.expandedFileSymbols.has(p.path);g.hidden=!E,y.setAttribute("aria-expanded",String(E)),y.dataset.tooltip=E?"Hide Symbols":"Show Symbols",y.setAttribute("aria-label",`${y.dataset.tooltip}: ${p.path}`),y.textContent=E?"\u25BE":"\u25B8"};y.addEventListener("click",()=>{n.expandedFileSymbols.has(p.path)?n.expandedFileSymbols.delete(p.path):n.expandedFileSymbols.add(p.path),b()}),b(),a.parentElement.classList.add("has-file-symbols"),a.parentElement.append(y,g)}}function jr(r,a){let u=n.correspondence,d=document.getElementById("correspondence-filter").value,p=++Xe,g=document.createElement("ul");g.className="correspondence-tree",r.append(g);let y=a.map(b=>({node:b,parent:g})).reverse();for(;y.length;){let{node:b,parent:E}=y.pop(),P=document.createElement("li");P.dataset.symbolKey=b.key,P.classList.toggle("is-context",b.type==="symbol"&&b.context);let R=document.createElement("div");R.className="correspondence-heading";let U=document.createElement("ul");U.id=`symbols-${p}-${encodeURIComponent(b.key)}`;let F=document.createElement("button");F.type="button",F.className="correspondence-toggle";let M=b.type==="file"?b.path:b.entry.name,z=()=>{F.setAttribute("aria-expanded",String(!U.hidden)),F.setAttribute("aria-label",`${U.hidden?"Expand":"Collapse"} ${M}`),F.textContent=U.hidden?"\u25B8":"\u25BE"};if(U.hidden=!d.trim()&&n.collapsedSymbolNodes.has(b.key),F.setAttribute("aria-controls",U.id),F.addEventListener("click",()=>{U.hidden=!U.hidden,U.hidden?n.collapsedSymbolNodes.add(b.key):n.collapsedSymbolNodes.delete(b.key),z()}),z(),F.hidden=!b.children.length,R.append(F),P.append(R),b.type==="file"){P.classList.add("correspondence-file");let L=document.createElement("button");L.type="button",L.className="correspondence-file-label",L.textContent=b.path,L.title=b.path,L.setAttribute("aria-current",String(n.activeTourFilePath===b.path)),L.addEventListener("click",()=>{let H=n.tour.files.findIndex(K=>K.path===b.path||K.previousPath===b.path);H>=0&&ft(H)}),R.append(L)}else{let{before:L,after:H,relation:K}=b,q=document.createElement("button");q.type="button",q.className="correspondence-item";let T=K?.id||b.key;q.dataset.correspondenceId=T,q.dataset.sourceReference=String(!!b.sourceReference),q.dataset.changeKind=K?b.changed?"modified":"unchanged":b.ambiguous?"ambiguous":b.side==="before"?"deleted":"added",q.classList.toggle("is-relocated",!!b.sourceReference||!!K?.pathChanged),q.setAttribute("aria-pressed",String(n.activeCorrespondenceId===T));let W=xe=>`${xe.path}:${xe.startLine}`;q.title=K?`Compare ${W(L)} with ${W(H)}`:`Inspect ${W(b.entry)} \xB7 no accepted match`;let Z=document.createElement("strong");Z.textContent=L&&H&&L.name!==H.name?`${L.name} \u2192 ${H.name}`:b.entry.name;let ie=document.createElement("span");ie.textContent=K?`${W(L)} \u2192 ${W(H)}`:`${W(b.entry)} \xB7 ${b.side==="before"?"base":"head"}`,ie.className="correspondence-location";let ue=document.createElement("span"),ye=K?[b.sourceReference?"Before location":"",K.pathChanged?"Moved":"",K.nameChanged?"Renamed":"",K.rawEqual?"":"Edited",b.changed&&!K.pathChanged&&!K.nameChanged&&K.rawEqual?"Reparented":""].filter(Boolean):[b.side==="before"?"Before only":"After only",b.ambiguous?"Ambiguous":"Unmatched"];ue.textContent=`${b.entry.kind} \xB7 ${ye.join(" \xB7 ")||"Unchanged text"}${b.context?" \xB7 ancestor context":""}`,q.append(Z,ie,ue),q.addEventListener("click",()=>{Ee(),oe+=1,document.body.classList.remove("tour-discussion"),Ie=null,Q.interruptForExploration(),n.directoryEvidence=null,n.symbolSelection={before:L,after:H,relation:K,ambiguous:b.ambiguous,side:b.side,entry:b.entry,id:T,range:u.range},Gt(!1),r.querySelectorAll(".correspondence-item").forEach(xe=>xe.setAttribute("aria-pressed",String(xe.dataset.correspondenceId===T)))}),R.append(q)}E.append(P),b.children.length&&(P.append(U),y.push(...b.children.map(L=>({node:L,parent:U})).reverse()))}}function Gt(r=!1){let a=n.symbolSelection;if(!a)return;let{before:u,after:d,relation:p,range:g}=a,y=(F,M)=>F?r?n.correspondence?.documents[M].find(z=>z.path===F.path)?.text??a.context?.[M==="before"?"leftContent":"rightContent"]??null:F.text:"",b=y(u,"before"),E=y(d,"after");if(b===null||E===null){document.getElementById("correspondence-selection").textContent="Full file context is unavailable in this older artifact. Rebuild the correspondence artifact to include it.";return}++ge,t.clear(),n.displayedPanels=[],n.activeCorrespondenceId=a.id,n.activeTourFilePath=d?.path||u?.path,n.symbolContext=r,document.getElementById("correspondence-context").hidden=r,document.getElementById("file-symbol-context").hidden=!1,document.getElementById("file-symbol-context").textContent=r?"Return to symbol comparison":"Show file context",document.getElementById("correspondence-selection").textContent=p?`${u.name}: inferred correspondence \xB7 behavior unassessed. ${r?"Complete source and destination files; declarations highlighted.":`Complete declarations; line 1 starts at source lines ${u.startLine} / ${d.startLine}.`}`:`${a.entry.name}: ${a.ambiguous?"ambiguous":"unmatched"} ${a.side} symbol. The empty side does not establish an addition or deletion.`;let P=r?[[u,"left"],[d,"right"]].filter(([F])=>F).map(([F,M])=>({side:M,startLine:F.startLine,endLine:F.endLine,label:F.name,active:!0})):[],R=F=>F?`${F.path}:${F.startLine}`:"No accepted match",U=ke(b,E);se({type:"showDiff",file1:`${R(u)} @ ${g.baseOid.slice(0,7)}`,file2:`${R(d)} @ ${g.headOid.slice(0,7)}`,sourceInfo:{leftPath:u?.path||a.entry.path,rightPath:d?.path||a.entry.path},comparisonId:`correspondence-${a.id}-${r?"file":"symbol"}`,leftContent:b,rightContent:E,diffModel:U,history:null,correspondenceView:!0,editableSides:{left:!1,right:!1},tourAnnotations:P,initialChangeIndex:r?Kn(U,d?"right":"left",(d||u).startLine):0,comparisonSummary:p?"Inferred symbol correspondence \xB7 behavior unassessed":"No accepted symbol match \xB7 addition/deletion unassessed"}),pe(),document.querySelectorAll(".correspondence-item").forEach(F=>F.setAttribute("aria-pressed",String(F.dataset.correspondenceId===a.id))),r&&Pt("files")}function ss(r){document.getElementById("correspondence-filter").value="",document.getElementById("correspondence-all").checked=!0;let a=document.getElementById("correspondence-unmatched");a&&(a.checked=!0),Lt();let u=n.correspondence.relations.find(y=>y.sourceId===r||y.destinationId===r),d=[...document.querySelectorAll("#correspondence-list .correspondence-item")],p=d.find(y=>y.parentElement.parentElement.dataset.symbolKey===`after:${r}`||y.parentElement.parentElement.dataset.symbolKey===`before:${r}`)||d.find(y=>y.dataset.correspondenceId===u?.id);if(!p)return;let g=p.closest("li").parentElement;for(;g?.closest("#correspondence-list");)g.tagName==="UL"&&g.hidden&&g.previousElementSibling?.querySelector(".correspondence-toggle")?.click(),g=g.parentElement;p.click(),p.focus(),p.scrollIntoView({block:"nearest"})}function as(r){let a=document.getElementById("correspondence-limitations"),u=new Set([...a.querySelectorAll("details[open]")].map(b=>b.dataset.diagnosticCategory));a.replaceChildren();let d=(b,E)=>{let P=document.createElement("p");P.textContent=E,b.append(P)},p=new Map([...r.symbols.before,...r.symbols.after].map(b=>[b.id,b]));d(a,"Categories overlap and use different units. Rejected records are not missing functions; these counts do not measure coverage."),r.diagnostics||d(a,"Detailed diagnostics unavailable. This older artifact retains summaries and inventoried symbols only.");for(let b of r.diagnostics?.scope||[])d(a,b);for(let b of Ai(r)){let E=document.createElement("details");E.dataset.diagnosticCategory=b.category,E.open=u.has(b.category);let P=document.createElement("summary");P.textContent=`${b.title} \xB7 ${b.count}`,E.append(P),d(E,b.description);let R=document.createElement("ul");R.className="correspondence-diagnostics";for(let U of b.records){let F=document.createElement("li");d(F,Ar(U.reason));let M=document.createElement("code");M.textContent=U.reason,F.append(M),U.producerId&&d(F,`Engine record: ${U.producerId}`),U.message&&d(F,U.message);for(let z of U.locations){let L=p.get(z.symbolId),H=n.tour?.files.find(T=>T.path===z.path&&T.kind==="text-diff"),K=`${z.side?`${z.side} @ ${(z.side==="before"?r.range.baseOid:r.range.headOid).slice(0,7)} \xB7 `:"changed path \xB7 "}${z.path}${z.line?`:${z.line}`:""}${L?` (${L.name})`:""}`,q=document.createElement(L||H?"button":"span");if(q.textContent=K,q.className="correspondence-diagnostic-location",L||H?(q.type="button",q.title=L?"Inspect symbol (enables both include options and clears search)":"Inspect complete file context",q.addEventListener("click",()=>{if(L)return ss(L.id);Ee(),oe+=1,Q.interruptForExploration(),n.directoryEvidence=null,n.activeCorrespondenceId=null,ut(H,[],Jt(H.path),null,z.line&&z.side?{revision:z.side==="before"?"base":"head",startLine:z.line}:null),document.getElementById("correspondence-selection").textContent=`Complete file context: ${K}`,document.querySelectorAll(".correspondence-item").forEach(T=>T.setAttribute("aria-pressed","false"))})):q.title="File context is not available in this comparison.",F.append(q),z.reason){d(F,Ar(z.reason));let T=document.createElement("code");T.textContent=z.reason,F.append(T)}}R.append(F)}b.records.length&&E.append(R),a.append(E)}let g=document.createElement("details"),y=document.createElement("summary");y.textContent="Analysis summaries and provenance",g.append(y);for(let b of r.limitations)d(g,b);a.append(g)}function Un(){let r=n.tour,a=document.getElementById("tour-files");document.getElementById("tour-file-count").textContent=String(r.files.length),a.replaceChildren(Kr(Ii(r.files,d=>d.path),(d,p,g)=>{let y=document.createElement("button");y.type="button",y.className=`tour-file${d.kind==="omitted"?" is-omitted":""}`,y.dataset.filePath=d.path,y.disabled=d.kind==="omitted",y.title=d.kind==="omitted"?`${d.path}: ${d.reason}`:`Open file: ${d.path}`,d.kind==="text-diff"&&y.addEventListener("click",()=>ft(p));let b=document.createElement("span");b.className="tour-file-marker",b.textContent=d.kind==="omitted"?"\xD7":jn(d.changeKind);let E=document.createElement("span");E.className="tour-file-copy";let P=document.createElement("span");P.className="tour-file-path",P.textContent=g;let R=document.createElement("span");return R.className="tour-file-meta",R.textContent=d.kind==="omitted"?`Not rendered \xB7 ${d.reason}`:Number.isFinite(d.additions)?`${Qt(d.changeKind)} \xB7 +${d.additions} \u2212${d.deletions}`:Qt(d.changeKind),E.append(P,R),y.append(b,E),y}));let u=document.createElement("div");u.className="history-rail-empty",u.dataset.fileTreeEmpty="",a.append(u),n.correspondence&&_r(),pe()}function Kr(r,a){let u=document.createElement("ul");u.className="file-tree";for(let d of r.folders){let p=document.createElement("li"),g=document.createElement("details");g.dataset.fileFolder=d.path,g.open=!n.collapsedFileFolders.has(d.path);let y=document.createElement("summary"),b=document.createElement("span");b.className="tour-file-path",b.textContent=d.name,y.append(b),y.title=d.path,g.append(y,Kr(d,a)),p.append(g),u.append(p)}for(let{item:d,index:p,name:g}of r.files){let y=document.createElement("li");y.append(a(d,p,g)),u.append(y)}return u}function cs(r,a){if(r.replaceChildren(),r.hidden=!a,!a)return;let u=[{metric:"walkthrough",label:"Anchored diff hunks",covered:a.walkthrough.coveredUnits,total:a.walkthrough.includedUnits,percent:a.walkthrough.coveragePercent,description:"Distinct change hunks referenced by authored base/head focus anchors. Revision-stack steps are not counted."},...a.explanationAssignments.map(d=>({metric:"assignment",label:a.explanationAssignments.length>1?`Deconstructed assignment \xB7 ${d.sceneId}`:"Deconstructed assignment",covered:d.completeUnits,total:d.totalUnits,percent:d.assignmentPercent,description:`${d.assignedUnits} assigned, ${d.excludedUnits} explicitly excluded.`}))];for(let d of u){let p=document.createElement("div");p.className="tour-coverage-item",p.dataset.metric=d.metric,p.dataset.tooltip=d.description,p.tabIndex=0,p.setAttribute("aria-description",d.description);let g=document.createElement("div");g.className="tour-coverage-heading";let y=document.createElement("span");y.textContent=d.label;let b=document.createElement("strong");b.textContent=`${d.covered}/${d.total} \xB7 ${d.percent}%`,g.append(y,b);let E=document.createElement("div");E.className="tour-coverage-meter",E.setAttribute("role","progressbar"),E.setAttribute("aria-label",d.label),E.setAttribute("aria-valuemin","0"),E.setAttribute("aria-valuemax","100"),E.setAttribute("aria-valuenow",String(d.percent));let P=document.createElement("span");P.style.width=`${d.percent}%`,E.append(P),p.append(g,E),r.append(p)}}let Ie=null;function ve(r,a=0,u={}){let d=n.tour;if(!d||u.readingKey!=="conclusion"&&(r<0||r>=d.scenes.length))return null;if(t.clear(),u.userNavigation&&Ee(),n.zoom?.mode==="history"&&!n.zoomSwitching){let z=d.scenes[r],L=z.path||z.steps?.[a]?.file||n.activeTourFilePath;return et(L,n.historyCommit).catch(H=>{document.getElementById("tour-mode-status").textContent=H.message}),null}let p=Ie?.tour===d&&!u.zoomLanding&&!s?Ie.context:null;n.directoryEvidence=null,n.activeCorrespondenceId=null,Ge(""),Zt(),Wn();let g=_.find(z=>z.key===u.readingKey)||xn(_,r,a,u.showIntro?"overview":null);g&&g.kind!=="step"&&g.kind!=="conclusion"&&g.kind!=="title"&&st(d)&&(g=xn(_,g.sceneIndex,0)),g&&(r=g.sceneIndex,a=g.stepIndex);let y=d.scenes[r],b=rn(d,g);document.body.classList.toggle("tour-discussion",b==="narrative");let E=g.kind==="title"||g.kind==="chapter"||g.kind==="conclusion",P=document.body.classList.contains("tour-bookend")!==E;document.body.classList.toggle("tour-bookend",E),n.readingKey=g?.key||"title",n.sceneIntroVisible=g?.kind!=="step",n.narrativeParent=g?.kind==="conclusion"?"conclusion":g?.kind==="title"?"tour":g?.kind==="chapter"?"chapter":null,n.activeSceneIndex=r,n.activeStepIndex=$e(y)?Math.min(Math.max(a,0),Math.max(y.steps.length-1,0)):0,n.tourFocusFilePath=!y||n.narrativeParent?null:y.kind==="text-diff"?y.path:y.kind==="walkthrough"?y.steps[n.activeStepIndex]?.diff.path??null:Me(y)?y.steps[n.activeStepIndex]?.file??null:null;let R=y?Zr(d,r):null;ws();let U=u.preserveNarration&&Q.engaged?Q.state.unit:Br(u.narrationEntry||"playback-start");n.renderedNarrationUnit=U,io(y,R,U),(!u.fromReadingScroll||P)&&ao(n.readingKey),U&&!u.zoomLanding&&!u.preserveNarration&&(!n.zoom||re())&&(u.narrationNavigation==="linear"?Q.followLinearNavigation(U):u.narrationNavigation!=="controller"&&Q.followDirectNavigation(U)),Se();let F=me(d,g,n.zoom?.mode);b==="overview"?Ie={tour:d,context:F}:b!=="narrative"?Ie=p?{tour:d,context:p}:null:g.kind!=="chapter"&&(Ie=null);let M=J.get(g.key)?.querySelector(".tour-scene-orientation");return M&&F&&(M.textContent=Gn(p,F)),b==="overview"&&zn()?U:b==="narrative"?(++ge,n.displayedPanels=[],n.activeTourFilePath=null,se({type:"updateCommitHistory",history:Nr()}),document.body.classList.add("tour-discussion"),n.tourFocusFilePath=null,pe(),be(),U):(document.body.classList.remove("tour-discussion"),y.kind==="walkthrough"?(Vr(y),U):Me(y)?(Jr(y),U):(ut(y,Vt(y.path)),U))}function Ge(r){let a=document.getElementById("status-banner");a.textContent=r,a.hidden=!r}function zn(){let r=n.tour?.scenes[n.activeSceneIndex];if(!re()||!r||st(n.tour)||n.narrativeParent||!r.overview)return!1;let a=nn(n.tour,r);n.directoryEvidence=a,n.activeCorrespondenceId=null,n.activeTourFilePath=null,pe(),document.body.classList.remove("tour-discussion");let u=me(n.tour,_.find(d=>d.key===n.readingKey),n.zoom?.mode);return se(sn(u.labels,a.entries)),document.getElementById("file-info").textContent=gt(u),Ge(a.entries.length?"":"No changed files in this directory for the selected comparison."),Se(),!0}function qn(r){let a=n.directoryEvidence;if(!a)return!1;let u=a.files.find(d=>d.path===r);if(!u){let d=a.omitted.find(p=>p.path===r);return Ge(d?`${r}: ${d.reason}`:"This file has no change in the overview comparison."),!1}return Ee(),Ge(""),ut(u,[],`directory-${n.tour.scenes[n.activeSceneIndex].id}-${r}`),Se(),!0}function Vt(r){let a=n.tour;return!a||!r?[]:ui(a,r,n.activeSceneIndex,n.activeStepIndex)}function ds(r,a){let u=n.tour;return!u||!r?[]:fi(u,r,n.activeSceneIndex,n.activeStepIndex,(d,p)=>Er(a?.[d]?.diffModel,p))}function Jt(r){return`file::${r}`}function ut(r,a=[],u=Jt(r.path),d=null,p=null){if(document.body.classList.remove("tour-discussion"),!n.tour)return;t.clear(),n.activeCorrespondenceId=null,n.activeTourFilePath=n.zoom?.mode==="history"&&n.historyPath||r.path,pe();let y=ke(r.leftContent,r.rightContent),b=Wr(r,r.leftLabel,n.zoom?.mode==="compare"?"from":"base"),E=Wr(r,r.rightLabel,n.zoom?.mode==="compare"?"to":"head"),P=a.find(U=>U.active)||p&&{side:p.revision==="head"?"right":"left",startLine:p.startLine},R=r.changeKind==="added"?{left:!1,right:!0}:r.changeKind==="deleted"?{left:!0,right:!1}:{left:!0,right:!0};se({type:"showDiff",file1:`1. ${b}`,file2:`2. ${E}`,comparisonId:`tour-${u}`,leftContent:r.leftContent,rightContent:r.rightContent,canReturnToDirectory:!!n.directoryEvidence,sourceInfo:{leftPath:r.previousPath||r.path,rightPath:r.path},fileExists:R,diffModel:y,history:d,fileNavigation:{canGoPrevious:!!Nt(-1),canGoNext:!!Nt(1)},editableSides:{left:!1,right:!1},comparisonSummary:Hn(r.path,void 0,!n.directoryEvidence),initialChangeIndex:P?Kn(y,P.side,P.startLine):r.focusChangeIndex,tourAnnotations:a})}function Hn(r,a,u=!1){if(!re())return r;let d=_.find(K=>K.key===n.readingKey),p=d&&me(n.tour,d,n.zoom?.mode),g=a===void 0?d:{kind:"step",sceneIndex:n.activeSceneIndex,stepIndex:n.activeStepIndex},y=g&&me(n.tour,g,n.zoom?.mode,a),b=u||!y?lo(n.tour,r):y,E={...b,scope:r,scopeKey:JSON.stringify([r]),overview:!1},P=Ie?.tour===n.tour?Ie.context:null,R=P&&(P.comparisonKey!==E.comparisonKey||P.scopeKey!==E.scopeKey)?Gn(P,E):gt(E);Ie={tour:n.tour,context:E};let U=p,F=d&&rn(n.tour,d)==="preview"&&U?.scope===r&&U.comparisonKey===b.comparisonKey,M=d&&n.tour.scenes[d.sceneIndex],z=M&&$e(M)?M.steps[d.kind==="step"?d.stepIndex:0]:null;return`${z&&U?.scope===r&&U.comparisonKey===b.comparisonKey?`${F?"Coming up":"Evidence for"}: ${Be(n.tour,{kind:"step",key:`step:${M.id}:${z.id}`,sceneIndex:d.sceneIndex,stepIndex:d.kind==="step"?d.stepIndex:0})} \xB7 `:""}${R}`}function Wr(r,a,u){if(n.zoom?.mode==="history")return a;let d=a.startsWith(r.path)?a.slice(r.path.length).trim():a.trim();return d?`${u} ${d}`:u}function Gr(r){return r.status==="inferred"?r.id:`${r.before?"before":"after"}:${r.id}`}function Vr(r){let a=r.steps[n.activeStepIndex];if(a){if(a.symbol&&!n.sceneIntroVisible){let u=a.symbol;n.symbolSelection={...u,id:Gr(u),entry:u.after||u.before,relation:u.status==="inferred"?{id:u.id}:null,ambiguous:u.status==="ambiguous",side:u.before?"before":"after"},Gt(!1);return}if(a.image){++ge,n.displayedPanels=[],n.activeCorrespondenceId=null,n.activeTourFilePath=a.diff.path,t.show(a.image,a.title),pe();return}ut(a.diff,n.sceneIntroVisible?[]:Vt(a.diff.path),Jt(a.diff.path),null,n.sceneIntroVisible?a.focus:null)}}function Jr(r){let a=r.steps[n.activeStepIndex];a&&Yr(r,a.file,a)}function Yr(r,a,u){document.body.classList.remove("tour-discussion");let d=Rt(r,a);if(!u||!d)return;n.activeCorrespondenceId=null,n.activeTourFilePath=d.path,pe();let p=d.panels.map((M,z)=>({id:`${r.id}-${d.path}-${M.id}`,commit:r.kind==="stacked-diff"?Ft(r)[z].oid:void 0,label:M.label,path:M.path||d.path,content:M.content,savedContent:M.content,dirty:!1,editable:!1,stackId:Ft(r)[z].id})),g=Vn(p,(M,z)=>ke(M.content,z.content)),y=n.sceneIntroVisible?[]:ds(d.path,g),b=y.find(M=>M.active),E=b?.pairIndex??u.pairIndex,P=b?.side??u.side,R=b?.startLine??u.startLine,U=g[E]?.diffModel,F=U&&R?Kn(U,P,R):0;se({type:"showMultiDiff",panels:p,pairs:g,activePanelId:p[E+(P==="right"?1:0)]?.id,activePairIndex:E,initialChangeIndex:F,revealFirstChangeInEachPanel:r.kind==="deconstructed-diff",history:null,fileNavigation:{canGoPrevious:!!Nt(-1),canGoNext:!!Nt(1)},mutationEnabled:!1,comparisonSummary:Hn(d.path,E),tourAnnotations:y})}function Yt(r){if(!re())return!1;let a=Ht(_,n.readingKey,r,st(n.tour));return a?(Ae(a,!1,!0),!0):!1}function Xt(){return{paths:n.tour.files.filter(r=>r.kind==="text-diff").map(r=>r.path),currentPath:n.activeTourFilePath,changedPaths:n.zoom?.mode==="compare"?n.compare?.changedPaths:n.historyChangedFiles}}function Nt(r){let a=n.tour;if(!a||r!==-1&&r!==1)return null;let u=a.scenes[n.activeSceneIndex];if(n.zoom?.mode==="history"||n.zoom?.mode==="compare"){let d=Ye(Xt(),r);return d?{fileIndex:a.files.findIndex(p=>p.path===d),path:d}:null}if(n.directoryEvidence){let d=n.directoryEvidence.files,p=d.findIndex(b=>b.path===n.activeTourFilePath),g=d[p+r],y=g?a.files.findIndex(b=>b.path===g.path):-1;return y>=0?{fileIndex:y,path:g.path}:null}if(Me(u)){let d=u.steps[n.activeStepIndex]?.pairIndex;if(!Number.isInteger(d))return null;let p=a.files.flatMap(b=>{if(b.kind!=="text-diff")return[];let E=Rt(u,b.path);return E?[E]:[]}),g=ri(p,d,n.activeTourFilePath,r);if(!g)return null;let y=a.files.findIndex(b=>b.kind==="text-diff"&&b.path===g.path);return y>=0?{fileIndex:y,path:g.path}:null}return oi(a.files,n.activeTourFilePath,r)}function Xr(r){let a=Nt(r);return a?ft(a.fileIndex):!1}function _n(r,a=!0){let u=n.tour?.files[r];return!u||u.kind!=="text-diff"?!1:(a&&Q.interruptForExploration(),n.directoryEvidence=null,ut(u,Vt(u.path),Jt(u.path)),!0)}function ft(r){let a=n.tour?.files[r];if(!a||a.kind!=="text-diff")return!1;if(Ee(),n.activeCorrespondenceId=null,n.symbolContext=!1,document.getElementById("file-symbol-context").hidden=!n.symbolSelection,document.getElementById("file-symbol-context").textContent="Return to symbol comparison",document.querySelectorAll(".correspondence-file-label").forEach(d=>d.setAttribute("aria-current",String(d.textContent===a.path))),document.querySelectorAll(".correspondence-item").forEach(d=>d.setAttribute("aria-pressed","false")),n.zoom?.mode==="history")return et(a.path,n.historyCommit).catch(d=>{document.getElementById("tour-mode-status").textContent=d.message}),!0;if(n.zoom?.mode==="compare")return Fr(a).catch(d=>{document.getElementById("tour-mode-status").textContent=d.message}),!0;if(n.directoryEvidence&&re())return qn(a.path);n.zoomSwitching||Q.interruptForExploration();let u=n.tour?.scenes[n.activeSceneIndex];if(Me(u)){let d=u.steps[n.activeStepIndex];return d&&Rt(u,a.path)?(Yr(u,a.path,d),!0):!1}return _n(r,!1)}function Rt(r,a){let u=r?.files?.find(g=>g.path===a);if(u||r?.kind!=="deconstructed-diff")return u;let d=n.tour?.files.find(g=>g.kind==="text-diff"&&g.path===a);if(!d||d.kind!=="text-diff")return null;let p=d.changeKind!=="deleted";return{path:d.path,panels:Ft(r).map(g=>({id:g.id,label:`${g.label} / ${d.path}${p?"":" (absent)"}`,path:p?d.path:void 0,content:p?d.rightContent:"",exists:p}))}}function ls(){if(n.narrativeParent)return!!ve(n.activeSceneIndex,n.activeStepIndex,{readingKey:n.readingKey,preserveNarration:!0});if(n.directoryEvidence)return zn();let r=n.tour?.scenes[n.activeSceneIndex];if(!r||!n.tourFocusFilePath)return!1;if(r.kind==="walkthrough")Vr(r);else if(Me(r))Jr(r);else if(r.kind==="text-diff")ut(r,Vt(r.path));else return!1;return!0}function Pt(r){if(!["tour","files","commits","symbols"].includes(r))return;r==="symbols"&&!n.correspondence&&(r="files");let a=re()&&!!n.tour?.scenes.length;r==="tour"&&!a&&(r="commits"),n.tourNavigatorTab=r,document.querySelectorAll("[data-tour-navigator]").forEach(u=>{let d=u.dataset.tourNavigator===r;u.disabled=u.dataset.tourNavigator==="tour"&&!a,u.classList.toggle("is-active",d),u.setAttribute("aria-selected",String(d)),u.tabIndex=d?0:-1}),document.querySelectorAll("[data-tour-navigator-panel]").forEach(u=>{u.hidden=u.dataset.tourNavigatorPanel!==r}),window.dispatchEvent(new CustomEvent("bygone:present-navigator-change",{detail:{tab:r}})),window.dispatchEvent(new Event("resize"))}function Zt(){let r=!!(n.directoryEvidence&&re()),a=r?n.activeTourFilePath:null;document.body.classList.toggle("tour-directory-overview",r),document.body.classList.toggle("tour-directory-file-open",!!a),document.getElementById("tour-directory-breadcrumb").hidden=!r;let u=document.getElementById("tour-directory-root");a?u.removeAttribute("aria-current"):u.setAttribute("aria-current","location"),document.getElementById("tour-directory-separator").hidden=!a;let d=document.getElementById("tour-directory-file");d.textContent=a||"",d.hidden=!a;let p=document.getElementById("tour-directory-narration-context");p.hidden=!a,p.textContent=`Narration describes the ${n.narrativeParent||"overview"}`}function pe(){Zt();let r=document.getElementById("file-symbol-context");r.hidden=!n.symbolSelection,r.textContent=n.activeCorrespondenceId&&!n.symbolContext?"Show file context":"Return to symbol comparison";let a=n.activeCorrespondenceId?[n.symbolSelection?.before?.path,n.symbolSelection?.after?.path].filter(Boolean):[],u=n.tour?.files.find(L=>L.path===n.activeTourFilePath),d=a.length?a:[n.activeTourFilePath,u?.previousPath];document.querySelectorAll(".correspondence-file-label").forEach(L=>{let H=d.includes(L.textContent);L.setAttribute("aria-current",String(H))}),document.querySelectorAll(".correspondence-item").forEach(L=>L.setAttribute("aria-pressed",String(L.dataset.correspondenceId===n.activeCorrespondenceId)));let p=n.tour?.scenes[n.activeSceneIndex],g=Me(p)?p.steps[n.activeStepIndex]:null,y=new Map(n.tour?.files.map(L=>[L.path,L]));document.querySelectorAll(".tour-file").forEach(L=>{let H=L.dataset.filePath;L.classList.toggle("is-active",H===n.activeTourFilePath||a.includes(H)||a.includes(y.get(H)?.previousPath)),L.classList.toggle("is-tour-focus",!n.directoryEvidence&&H===n.tourFocusFilePath),L.classList.remove("is-comparison-changed","is-comparison-empty"),delete L.dataset.comparisonState;let K=y.get(H);L.dataset.changeKind=K?.changeKind||"",L.classList.toggle("is-omitted",K?.kind==="omitted"),L.disabled=K?.kind==="omitted"||!!(n.directoryEvidence&&!n.directoryEvidence.files.some(Z=>Z.path===H)),H===n.activeTourFilePath?L.setAttribute("aria-current","true"):L.removeAttribute("aria-current");let q=L.querySelector(".tour-file-marker"),T=L.querySelector(".tour-file-meta");if(n.directoryEvidence&&L.disabled&&K?.kind==="text-diff"){let Z="Not in this overview comparison";L.setAttribute("title",`${H} \xB7 ${Z}`),L.setAttribute("aria-label",`${H}, ${Z}`),T&&(T.textContent=Z),q&&(q.textContent="\u25CB");return}if(n.directoryEvidence&&K?.kind==="text-diff"){let Z=n.directoryEvidence.files.find(ue=>ue.path===H);L.dataset.changeKind=Z.changeKind;let ie=`${Qt(Z.changeKind)} in overview`;L.setAttribute("title",`${H} \xB7 ${ie}`),L.setAttribute("aria-label",`${H}, ${ie}`),T&&(T.textContent=ie),q&&(q.textContent=jn(Z.changeKind));return}let W=n.zoom?.mode==="history"?n.historyChangedFiles:n.zoom?.mode==="compare"?n.compare?.changedPaths:null;if(W&&K?.kind==="text-diff"){let Z=W.has(H),ie=Z?"Changed in this comparison":"Unchanged in this comparison";L.classList.add(Z?"is-comparison-changed":"is-comparison-empty"),L.setAttribute("title",`${H} \xB7 ${ie}`),L.setAttribute("aria-label",`${H}, ${ie}`),T&&(T.textContent=ie),q&&(q.textContent=Z?"M":"\u25CB");return}if(g&&K?.kind==="text-diff"){let Z=Rt(p,H);if(Z){let ue=vr(Z,g.pairIndex),ye=us(ue);L.dataset.comparisonState=ue,L.classList.add(ye.changed?"is-comparison-changed":"is-comparison-empty"),L.setAttribute("title",`${K.path} \xB7 ${ye.label}`),L.setAttribute("aria-label",`${K.path}, ${ye.label}`),q&&(q.textContent=ye.marker),T&&(T.textContent=ye.label);return}L.disabled=!0;let ie="Not included in this tour comparison";L.setAttribute("title",`${H} \xB7 ${ie}`),L.setAttribute("aria-label",`${H}, ${ie}`),q&&(q.textContent="\u25CB"),T&&(T.textContent=ie);return}if(K){let Z=K.kind==="omitted"?`${K.path}: ${K.reason}`:`Open file: ${K.path}`;L.setAttribute("title",Z),L.setAttribute("aria-label",Z),q&&(q.textContent=K.kind==="omitted"?"\xD7":jn(K.changeKind)),T&&(T.textContent=K.kind==="omitted"?`Not rendered \xB7 ${K.reason}`:`${Qt(K.changeKind)} \xB7 +${K.additions} \u2212${K.deletions}`)}});let b=document.getElementById("tour-files"),E=re(),P=!E||!!(g||n.directoryEvidence),R=!P||(E?n.showAllTourFiles:n.showAllFiles),U=0;b.querySelectorAll(".tour-file").forEach(L=>{let H=L.dataset.filePath,K=n.directoryEvidence?n.directoryEvidence.files.some(q=>q.path===H):n.zoom?.mode==="history"?n.historyChangedFiles.has(H):n.zoom?.mode==="compare"?n.compare?.changedPaths.has(H):g?L.classList.contains("is-comparison-changed"):!0;L.parentElement.hidden=!R&&!K,L.parentElement.hidden||U++});for(let L of[...b.querySelectorAll("details[data-file-folder]")].reverse())L.parentElement.hidden=![...L.querySelector(":scope > ul").children].some(H=>!H.hidden);b.querySelector("[data-file-tree-empty]").hidden=U>0,b.querySelector("[data-file-tree-empty]").textContent=R?"No files":"No changed files",b.setAttribute("aria-label",R?E?"Tour files":o?"Included files":"Files in selected revisions":"Changed files");let F=document.getElementById("tour-file-filter");F.hidden=!P,F.title=E?"Include tour files unchanged in this step comparison":o?"Include unchanged files packaged in this export":"Include unchanged files from the selected revisions",document.getElementById("tour-file-filter-label").textContent=E?"Show unchanged tour files":o?"Show all included files":"Show all files",document.getElementById("tour-show-all-files").checked=E?n.showAllTourFiles:n.showAllFiles,document.getElementById("tour-visible-file-count").textContent=`${U} / ${n.tour.files.length}`;let M=b.querySelector(".tour-file.is-active");if(n.revealedFilePath!==n.activeTourFilePath&&M&&!M.parentElement.hidden){for(let L=M.closest("details");L;L=L.parentElement.closest("details"))L.open=!0,n.collapsedFileFolders.delete(L.dataset.fileFolder);M.scrollIntoView({block:"nearest"})}n.revealedFilePath=n.activeTourFilePath;let z=document.getElementById("tour-return-focus");if(z){let L=re(),H=p?.kind==="walkthrough"&&p.steps[n.activeStepIndex]?.image,K=p?.kind==="walkthrough"&&p.steps[n.activeStepIndex]?.symbol;z.hidden=!L||!!n.directoryEvidence||(n.narrativeParent?!n.activeTourFilePath:!n.tourFocusFilePath||(H?t.isVisible():K?n.activeCorrespondenceId===Gr(K)&&!n.symbolContext:n.activeTourFilePath===n.tourFocusFilePath)),z.textContent=n.narrativeParent?"Return to passage":"Return to tour focus"}}function us(r){return{"modified-here":{label:"Modified here",marker:"\u2022",changed:!0},"created-here":{label:"Created here",marker:"+",changed:!0},"deleted-here":{label:"Deleted here",marker:"\u2212",changed:!0},"unchanged-here":{label:"Unchanged here",marker:"\u25CB",changed:!1},"not-created-yet":{label:"Not created yet",marker:"\u2026",changed:!1},"already-deleted":{label:"Already deleted",marker:"\xD7",changed:!1}}[r]}function $e(r){return r?.kind==="walkthrough"||r?.kind==="stacked-diff"||r?.kind==="deconstructed-diff"}function Me(r){return r?.kind==="stacked-diff"||r?.kind==="deconstructed-diff"}function Ft(r){return r.kind==="deconstructed-diff"?r.panels:r.stack}function jn(r){return{added:"+",deleted:"\u2212",renamed:"\u2192",modified:"\u2022"}[r]||"\u2022"}function Qt(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function Zr(r,a){let u=r.scenes[a],d=r.chapters.findIndex(b=>b.sceneIds.includes(u.id)),p=d>=0?r.chapters[d]:null,g=p?p.sceneIds.indexOf(u.id)+1:a+1,y=p?p.sceneIds.length:r.scenes.length;return{chapter:p,chapterIndex:d,chapterNumber:d>=0?d+1:a+1,sceneInChapter:g,scenesInChapter:y,sceneCount:r.scenes.length}}function fs(r,a){return $e(r)?`${r.title} \xB7 Step ${a+1} of ${r.steps.length}`:r.title}function Kn(r,a,u){let p=(a==="left"?r.leftLines:r.rightLines).findIndex(R=>R.lineNumber===u);if(p<0)return 0;let g=a==="left"?"leftStart":"rightStart",y=a==="left"?"leftEnd":"rightEnd",b=r.blocks.findIndex(R=>p>=R[g]&&p<R[y]);if(b>=0)return b;let E=0,P=Number.POSITIVE_INFINITY;return r.blocks.forEach((R,U)=>{let F=Math.min(Math.abs(p-R[g]),Math.abs(p-R[y]));F<P&&(E=U,P=F)}),E}function Qr(r){return/^[0-9a-f]{40}$/i.test(r)?r.slice(0,7):r}function Dt(r,a){return`${r} ${r===1?a:`${a}s`}`}function ps(r){return r instanceof Element&&!!r.closest('a, button, input, select, summary, textarea, [contenteditable="true"], [role="textbox"], .monaco-editor')}function hs(r){let a=n.tour?.scenes[n.activeSceneIndex];n.tour&&io(a,a?Zr(n.tour,n.activeSceneIndex):null,r)}function en(r){let a=xn(_,n.activeSceneIndex,n.activeStepIndex,r==="scene"?"overview":r==="step"?null:r);a&&Ae(a)}function Ve(r,a,u){let d=document.createElement("button");return d.type="button",d.textContent=r,d.title=a,d.addEventListener("click",u),d}function eo(r,a,u,d){let p=document.createElement("div");p.className="tour-outline-group",p.dataset.readingGroup=r;let g=document.createElement("div");g.className="tour-outline-heading";let y=document.createElement("div");y.className="tour-outline-children",y.id=`outline-${encodeURIComponent(r)}`;let b=`${n.zoom?.mode||"tour"}:${r}`,E=Ve("\u25BE",`Expand or collapse ${a}`,()=>{te.has(b)?te.delete(b):te.add(b),P()});E.className="tour-outline-toggle",E.setAttribute("aria-controls",y.id);let P=()=>{y.hidden=te.has(b),E.setAttribute("aria-expanded",String(!y.hidden)),E.textContent=y.hidden?"\u25B8":"\u25BE"};P();let R=Ve(a,`Read ${a}`,d);return R.className=u,R.dataset.readingLink=r,g.append(E,R),p.append(g,y),{group:p,children:y,link:R,toggle:E}}function ms(){let r=document.getElementById("tour-audio-settings");r&&(r.hidden=!r.hidden,to())}function to(){Zt();for(let[u,d]of[["tour-back",-1],["tour-next",1]]){let p=document.getElementById(u);p&&(p.disabled=!re()||!Ht(_,n.readingKey,d,st(n.tour)))}let r=document.getElementById("tour-narration"),a=document.getElementById("tour-audio-settings");if(r){let u=!!(a&&!a.hidden);r.setAttribute("aria-expanded",String(u)),r.textContent=u?"\u203A":"\u2039 Narration",r.title=u?"Hide narration controls":"Show narration controls",r.setAttribute("aria-label",r.title)}}function pt(r){if(!r||r.kind==="title")return{part:"title"};if(r.kind==="conclusion")return{part:"conclusion"};if(r.kind==="chapter")return{part:"chapter",chapter:r.chapterId};let a=n.tour.scenes[r.sceneIndex];return r.kind==="scene"?{part:"scene",scene:a.id}:{part:"step",scene:a.id,step:a.steps[r.stepIndex].id}}function gs(r){let a=document.createElement("button");return a.type="button",a.className="tour-copy-location",a.setAttribute("aria-label","Copy link to this section"),a.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path class="tour-link-chain" d="M10 13a5 5 0 0 0 7 .1l3-3a5 5 0 0 0-7-7l-2 2M14 11a5 5 0 0 0-7-.1l-3 3a5 5 0 0 0 7 7l2-2"/><path class="tour-link-check" d="m5 12 4 4L19 6"/></svg>',a.title=o?"Copy location within this export; share the HTML file separately":n.authoredTour?.localSource?"Copy local link to the saved current document; evidence may change":"Copy browser location (requires this presentation server)",a.addEventListener("click",async u=>{u.stopPropagation();let d=no(r);try{await navigator.clipboard.writeText(d),a.classList.add("is-copied"),a.setAttribute("aria-label","Link copied"),setTimeout(()=>{a.classList.remove("is-copied"),a.setAttribute("aria-label","Copy link to this section")},1800)}catch{let p=document.createElement("dialog"),g=document.createElement("p");g.textContent="Copy this link:";let y=document.createElement("textarea");y.value=d,y.readOnly=!0,y.setAttribute("aria-label","Link to this tour location");let b=document.createElement("button");b.textContent="Close",b.addEventListener("click",()=>p.close()),p.append(g,y,b),document.body.append(p),p.addEventListener("close",()=>p.remove(),{once:!0}),p.showModal(),y.select()}}),a}function no(r){let a=re()?n.zoom?.mode||"historical":Object.keys(G())[0],u=n.authoredTour.localSource;return u&&!o?bo({kind:"tour",...u,mode:a,focus:r}):new URL(nt(a,r),window.location.href).href}function ro(r){let a=++f,u=h.then(()=>ys(r,a));return h=u.catch(()=>{}),u}async function ys(r,a){if(!r||!n.authoredTour)return;let u=Zn(n.authoredTour,r.mode,r.focus);if(a===f){s=!0;try{if(n.zoom.mode!==r.mode&&await We(r.mode),a!==f)return;if(n.zoom.mode!==r.mode)throw new Error("The requested tour mode could not be opened.");if(le=null,document.getElementById("tour-mode-status").textContent="",ve(u.sceneIndex,u.stepIndex,{readingKey:u.key,showIntro:r.focus.part!=="step"}),await new Promise(p=>window.requestAnimationFrame(p)),a!==f)return;let d=J.get(u.key);if(!d)throw new Error("The requested document section could not be rendered.");d.tabIndex=-1,d.focus({preventScroll:!0}),ao(u.key),d.classList.add("tour-link-target"),window.setTimeout(()=>d.classList.remove("tour-link-target"),1800)}finally{s=!1}}}window.addEventListener("hashchange",()=>{try{ro(Qn(window.location.hash)).catch(fe)}catch(r){fe(r)}});function Se(){if(o)return;let r=n.tour?.scenes[n.activeSceneIndex],a=new URLSearchParams(window.location.search);for(let d of["from","to","commits","scope","commit","file","panelOrder"])a.delete(d);if(n.zoom&&a.set("mode",n.zoom.mode),n.zoom&&!re()){for(let d of["scene","step","view"])a.delete(d);n.zoom.mode==="compare"&&n.compare&&(a.set("commits",n.compare.commits.join(",")),n.compare.path&&a.set("scope",n.compare.path),n.activeTourFilePath||a.set("view","directory")),n.zoom.mode==="history"&&n.historyCommit&&a.set("commit",n.historyCommit),n.activeTourFilePath&&a.set("file",n.zoom.mode==="history"?n.historyPath:n.activeTourFilePath),window.history.replaceState(null,"",`${window.location.pathname}?${a.toString()}${window.location.hash}`);return}if(n.readingKey==="conclusion"){a.delete("scene"),a.delete("step"),a.set("view","conclusion"),window.history.replaceState(null,"",`${window.location.pathname}?${a.toString()}${nt(n.zoom.mode,{part:"conclusion"})}`);return}if(!r)return;a.set("scene",r.id);let u=$e(r)?r.steps[n.activeStepIndex]:null;u?a.set("step",u.id):a.delete("step"),n.directoryEvidence&&n.activeTourFilePath?a.set("file",n.activeTourFilePath):a.delete("file"),n.narrativeParent?a.set("view",n.narrativeParent):u&&n.sceneIntroVisible?a.set("view","overview"):a.delete("view"),window.history.replaceState(null,"",`${window.location.pathname}?${a.toString()}${nt(n.zoom.mode,pt(_.find(d=>d.key===n.readingKey)))}`)}function oo(r=n.tour?.scenes[n.activeSceneIndex],a=n.activeStepIndex){if(!r||!$e(r))return null;let u=r.steps[a];if(!u)return null;if(r.kind==="walkthrough"){if(u.image)return null;let p=u.focus;return!p?.path||!Number.isInteger(p.startLine)?null:{filePath:p.path,sideIndex:p.revision==="base"?0:1,lineNumber:p.startLine,label:`${p.path}:${p.startLine}`}}let d=u.startLine;if(!Number.isInteger(d)){let p=Rt(r,u.file),g=p?.panels?.[u.pairIndex],y=p?.panels?.[u.pairIndex+1];if(g&&y){let b=ke(g.content,y.content);d=Er(b,u.side)?.startLine}}return!u.file||!Number.isInteger(d)?null:{filePath:u.file,sideIndex:u.pairIndex+(u.side==="right"?1:0),lineNumber:d,label:`${u.file}:${d}`}}function bs(){let r=oo(),a=n.tour?.scenes[n.activeSceneIndex];if(n.sceneIntroVisible||!r||!a)return!1;if(Q.interruptForExploration(),n.activeTourFilePath!==r.filePath){let u=n.tour.files.findIndex(p=>p.kind==="text-diff"&&p.path===r.filePath);if(u<0||!(Me(a)?ft(u):_n(u,!1)))return!1}return window.requestAnimationFrame(()=>se({type:"revealSearchResult",sideIndex:r.sideIndex,lineNumber:r.lineNumber,startColumn:1,endColumn:1})),!0}function io(r,a,u){Wn(),document.getElementById("tour-narrative").hidden=!1,document.getElementById("tour-breadcrumb").textContent=n.narrativeParent==="tour"?"Intro":n.narrativeParent==="conclusion"?"Conclusion":n.narrativeParent==="chapter"?a.chapter?.title||"":n.sceneIntroVisible?r.title:fs(r,n.activeStepIndex);let d=r&&J.get(`scene:${r.id}`),p=$e(r)?r.steps[n.activeStepIndex]:null,g=p&&J.get(`step:${r.id}:${p.id}`);for(let y of new Set([d,g,J.get(n.readingKey)].filter(Boolean)))y.querySelectorAll("[data-reading-field]").forEach(b=>{b.closest("[data-reading-key]")===y&&Es(b,b.dataset.readingText,{field:b.dataset.readingField,...b.dataset.itemIndex!==void 0?{itemIndex:Number(b.dataset.itemIndex)}:{}},u)});to()}function Wn(){if(O===n.tour)return;O=n.tour,_=di(n.tour),J.clear();let r=document.getElementById("tour-narrative-content"),a=[],u,d=(b,E,P,R,U,F)=>{let M=document.createElement(E);M.className=P;let z=U&&/^h[1-6]$/.test(E)?document.createElement("span"):M;return z!==M&&M.append(z),z.replaceChildren(...Tr(document,R||"")),U&&(z.dataset.readingField=U,z.dataset.readingText=R||"",F!==void 0&&(z.dataset.itemIndex=String(F))),b.append(M),M},p=(b,E,P)=>{if(d(b,"p","tour-narrative-summary",E.summary,P?"summary":null),E.bullets?.length){let R=document.createElement("ul");R.className="tour-narrative-bullets",E.bullets.forEach((U,F)=>d(R,"li","",U,P?"bullet":null,F)),b.append(R)}E.takeaway&&d(b,"p","tour-narrative-takeaway",E.takeaway,P?"takeaway":null)},g=Mt(n.tour),y=(b,E)=>{let P=d(b,"ul","tour-route","");E.forEach(R=>{let U=d(P,"li","",""),F=Ve("",`Read ${R.title}`,()=>Ae(_.find(M=>M.kind==="scene"&&M.sceneIndex===R.sceneIndex)));F.className="tour-route-link",d(F,"span","tour-route-number",`${R.sceneIndex+1}. `),d(F,"span","",R.title,"route-title",R.sceneIndex),U.append(F)})};for(let b of _){let E=document.createElement("section");E.className="tour-reading-item",E.dataset.readingKey=b.key,E.dataset.readingKind=b.kind,E.dataset.sceneIndex=String(b.sceneIndex),E.dataset.stepIndex=String(b.stepIndex);let P=n.tour.scenes[b.sceneIndex];if(b.kind==="title")d(E,"h1","tour-document-title",n.tour.title,"document-title"),n.tour.opening&&(d(E,"h2","tour-passage-title",n.tour.opening.title,"passage-title"),p(E,n.tour.opening,!0)),d(E,"h2","tour-passage-title","What you'll see"),g.chapters.forEach(R=>{let U=d(E,"section","tour-route-chapter",""),F=d(U,"h3","",""),M=Ve("",`Read ${R.title}`,()=>Ae(_.find(z=>z.kind==="chapter"&&z.chapterId===R.chapterId)||_.find(z=>z.kind==="scene"&&z.sceneIndex===R.scenes[0]?.sceneIndex)));M.className="tour-route-link tour-route-chapter-link",d(M,"span","tour-route-number",`${R.chapterIndex+1}. `),d(M,"span","",R.title,"route-chapter",R.chapterIndex),F.append(M)}),g.chapters.length||y(E,g.scenes);else if(b.kind==="conclusion")d(E,"h2","tour-passage-title",n.tour.conclusion.title,"passage-title"),p(E,n.tour.conclusion,!0);else if(b.kind==="chapter"){let R=g.chapters.find(U=>U.chapterId===b.chapterId);d(E,"h2","tour-document-chapter",R.title,"chapter"),d(E,"p","tour-narrative-summary",R.summary,"summary"),y(E,R.scenes)}else if(b.kind==="scene"){E.classList.add("tour-scene-group");let R=d(E,"div","tour-scene-header",""),U=d(R,"h2","tour-scene-heading",Be(n.tour,b),"scene-title"),F=document.createElement("button");F.className="tour-scene-title-toggle",F.type="button",F.title="Expand or collapse scene overview",F.disabled=!0,F.append(...U.childNodes),U.append(F);let M=document.createElement("details");M.className="tour-scene-context";let z=d(M,"summary","","");z.setAttribute("aria-label",`Scene overview: ${P.title}`),z.dataset.tooltip="Expand or collapse scene overview";let L=d(M,"div","tour-scene-context-body","");L.id=`scene-overview-${b.sceneIndex}`,F.setAttribute("aria-controls",L.id),F.setAttribute("aria-expanded","false"),F.addEventListener("click",T=>{T.target.closest("a")||(M.open=!M.open)}),M.addEventListener("toggle",()=>F.setAttribute("aria-expanded",String(M.open))),p(L,P,!1),R.addEventListener("keydown",T=>{T.key==="Escape"&&M.open&&(T.preventDefault(),T.stopPropagation(),M.open=!1,z.focus({preventScroll:!0}))}),R.append(M);let H=d(E,"div","tour-scene-overview","");p(H,{...P,takeaway:$e(P)?"":P.takeaway},!0),P.overview?.purpose&&d(H,"p","tour-overview-purpose",P.overview.purpose,"overview-purpose");let K=me(n.tour,b,n.zoom?.mode);K&&d(H,"p","tour-scene-orientation",gt(K));let q=d(H,"div","tour-narrative-tags","");P.tags.forEach(T=>d(q,"span","",T))}else{let R=P.steps[b.stepIndex],U=P.kind==="deconstructed-diff"?R.body?`Stage ${(R.stageIndex??R.pairIndex)+1}`:P.panels[R.pairIndex+1].label:"";if(U&&d(E,"div","tour-narrative-chapter",U,"stage-title"),d(E,"h3","tour-step-title",Be(n.tour,b),"step-title"),d(E,"p","tour-step-orientation",on(n.tour,b.sceneIndex,b.stepIndex),"step-orientation"),R.body&&d(E,"p","tour-step-body",R.body,"step-body"),P.kind==="deconstructed-diff"&&!R.body){let z=P.steps.findIndex(L=>L.pairIndex===R.pairIndex);if(z>=0&&z<b.stepIndex){let L=_.find(K=>K.kind==="step"&&K.sceneIndex===b.sceneIndex&&K.stepIndex===z),H=Ve("Read stage explanation",`Read ${P.steps[z].title}`,()=>Ae(L));H.className="tour-show-in-code tour-stage-explanation",E.append(H)}}let F=d(E,"div","tour-step-requirement","");ks(F,R.requirement),R.connection&&(d(E,"p","tour-connection",`${R.connection.from.path} \u2192 ${R.connection.to.path}`),d(E,"p","tour-connection",R.connection.label,"connection")),b.stepIndex===P.steps.length-1&&d(E,"p","tour-narrative-takeaway",P.takeaway,"takeaway");let M=oo(P,b.stepIndex);if(M){let z=d(E,"div","tour-step-code","");d(z,"span","tour-step-code-location",M.label);let L=Ve("Show in code",`Show ${M.label}`,()=>{Ae(b),bs()});L.className="tour-show-in-code",z.append(L)}}E.querySelector("h1, h2, h3").append(gs(pt(b))),J.set(b.key,E),b.kind==="step"?u.append(E):(a.push(E),u=b.kind==="scene"?E:null)}r.replaceChildren(...a),X=r.scrollTop}function ws(){for(let[u,d]of J)d.classList.toggle("is-active",u===n.readingKey);document.querySelectorAll("[data-reading-link], .tour-outline-step, #tour-title").forEach(u=>{let d=n.tour?.scenes[n.activeSceneIndex],p=d&&$e(d)?d.steps[Number(u.dataset.stepIndex)]:null,y=(u.id==="tour-title"?"title":u.dataset.readingLink||(p&&u.dataset.sceneId===d.id?`step:${d.id}:${p.id}`:null))===n.readingKey;u.classList.toggle("is-active",y),y?u.setAttribute("aria-current","location"):u.removeAttribute("aria-current")}),document.querySelectorAll(".tour-outline-group").forEach(u=>{u.classList.toggle("has-active",!!u.querySelector('[aria-current="location"]'))});let r=document.getElementById("tour-scenes"),a=r?.querySelector('[aria-current="location"]');for(;a&&!a.getClientRects().length;)a=a.closest(".tour-outline-children[hidden]")?.parentElement.querySelector(":scope > .tour-outline-heading [data-reading-link]");if(a&&r.clientHeight){let u=r.getBoundingClientRect(),d=a.getBoundingClientRect();d.top<u.top?r.scrollTop+=d.top-u.top:d.bottom>u.bottom&&(r.scrollTop+=d.bottom-u.bottom)}}function so(){let r=document.getElementById("tour-narrative"),a=document.getElementById("tour-narrative-content");if(!r||!a||!r.getClientRects().length)return;let u=r.getBoundingClientRect(),d=u.height-a.clientHeight;a.style.setProperty("--tour-reading-viewport",`${a.clientHeight}px`),a.style.setProperty("--tour-bookend-viewport",`${Math.max(0,window.innerHeight-u.top-d)}px`)}function ao(r){let a=document.getElementById("tour-narrative-content"),u=J.get(r);if(!a||!u)return;so();let d=u.dataset.readingKind==="step"?u.closest(".tour-scene-group")?.querySelector(".tour-scene-header"):null;a.scrollTop+=u.getBoundingClientRect().top-a.getBoundingClientRect().top-(d?.getBoundingClientRect().height||0),X=a.scrollTop,tn()}function tn(){let r=document.getElementById("tour-narrative-content"),a=r.getBoundingClientRect().top,u=0;return r.querySelectorAll(".tour-scene-header").forEach(d=>{let p=d.parentElement.getBoundingClientRect(),g=p.top<a-1&&p.bottom>a;d.classList.toggle("is-stuck",g),d.querySelector(".tour-scene-title-toggle").disabled=!g,g?u=Math.max(u,d.getBoundingClientRect().bottom-a):d.querySelector("details").open=!1}),r.style.scrollPaddingTop=`${u}px`,u}function Ae(r,a=!1,u=!1){return!a&&!s&&re()&&window.history.pushState(null,"",nt(n.zoom.mode,pt(r))),ve(r.sceneIndex,r.stepIndex,{readingKey:r.key,showIntro:r.kind!=="step",userNavigation:!0,fromReadingScroll:a,narrationNavigation:u?"linear":void 0,narrationEntry:u?"continuous":"playback-start"})}function vs(){ne===null&&(ne=window.requestAnimationFrame(()=>{if(ne=null,!re()||n.zoomSwitching)return;let r=document.getElementById("tour-narrative-content"),a=tn();if(X!==null&&Math.abs(r.scrollTop-X)<2)return;X=null;let u=r.getBoundingClientRect().top+a+24,d=_[0];for(let p of _){if(J.get(p.key).getBoundingClientRect().top>u)break;d=p}d&&d.key!==n.readingKey&&Ae(d,!0)}))}function xs(r){let a=[];return r.source&&a.push(r.source),r.confidence&&a.push(`${r.confidence} confidence`),a.join(" \xB7 ")}function ks(r,a){if(!a){r.hidden=!0,r.replaceChildren(),r.removeAttribute("title");return}let u=document.createElement("span");u.className="tour-requirement-chip",u.dataset.status=a.status||"unspecified",u.textContent=a.status?`${a.id} \xB7 ${a.status}`:a.id;let d=document.createElement("span");d.className="tour-requirement-text",d.textContent=a.text;let p=[u,d],g=xs(a);if(g){let y=document.createElement("span");y.className="tour-requirement-meta",y.textContent=g,p.push(y)}r.replaceChildren(...p),r.title=[`${a.id}: ${a.text}`,g].filter(Boolean).join(" \u2014 "),r.hidden=!1}function Es(r,a,u,d,p={}){let g=d?.segments.filter(b=>b.source.field===u.field&&b.source.itemIndex===u.itemIndex)||[],y=[];p.prefix&&y.push(document.createTextNode(p.prefix)),y.push(...Tr(document,a,g)),p.suffix&&y.push(document.createTextNode(p.suffix)),r.replaceChildren(...y)}function co(){Q.stop();let r=Go();n.mode="diff",n.comparisonId+=1,n.left={name:r.leftFileName,content:r.leftContent},n.right={name:r.rightFileName,content:r.rightContent},Le("Loaded sample diff."),se({type:"showDiff",file1:n.left.name,file2:n.right.name,comparisonId:`web-${n.comparisonId}`,leftContent:n.left.content,rightContent:n.right.content,diffModel:ke(n.left.content,n.right.content),history:null})}async function Is(r){Q.stop();let[a,u]=r,[d,p]=await Promise.all([a.text(),u.text()]);n.mode="diff",n.comparisonId+=1,n.left={name:a.name,content:d},n.right={name:u.name,content:p},Le(`Loaded ${a.name} and ${u.name}.`),se({type:"showDiff",file1:a.name,file2:u.name,comparisonId:`web-${n.comparisonId}`,leftContent:d,rightContent:p,diffModel:ke(d,p),history:null})}async function Ss(r){Q.stop();let a=await Promise.all(r.map(async(u,d)=>{let p=await u.text();return{id:`web-panel-${d}`,label:u.name,content:p,savedContent:p,dirty:!1,editable:!0}}));n.mode="multi-diff",Le(`Loaded ${a.length}-panel diff for ${a.map(u=>u.label).join(", ")}.`),se({type:"showMultiDiff",panels:a,pairs:a.slice(0,-1).map((u,d)=>({leftIndex:d,rightIndex:d+1,diffModel:ke(u.content,a[d+1].content)}))})}function Le(r){let a=document.getElementById("web-status");a&&(a.textContent=r)}})();})();
671
671
  //# sourceMappingURL=web-host.js.map