@davmash/bygone 0.8.0 → 0.8.3

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
@@ -1,7 +1,7 @@
1
- "use strict";(()=>{function K(){}K.prototype={diff:function(t,n){var r,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},a=s.callback;typeof s=="function"&&(a=s,s={}),this.options=s;var l=this;function i($){return a?(setTimeout(function(){a(void 0,$)},0),!0):$}t=this.castInput(t),n=this.castInput(n),t=this.removeEmpty(this.tokenize(t)),n=this.removeEmpty(this.tokenize(n));var u=n.length,f=t.length,g=1,m=u+f;s.maxEditLength&&(m=Math.min(m,s.maxEditLength));var C=(r=s.timeout)!==null&&r!==void 0?r:1/0,L=Date.now()+C,T=[{oldPos:-1,lastComponent:void 0}],y=this.extractCommon(T[0],n,t,0);if(T[0].oldPos+1>=f&&y+1>=u)return i([{value:this.join(n),count:n.length}]);var w=-1/0,b=1/0;function v(){for(var $=Math.max(w,-g);$<=Math.min(b,g);$+=2){var D=void 0,F=T[$-1],P=T[$+1];F&&(T[$-1]=void 0);var B=!1;if(P){var re=P.oldPos-$;B=P&&0<=re&&re<u}var de=F&&F.oldPos+1<f;if(!B&&!de){T[$]=void 0;continue}if(!de||B&&F.oldPos+1<P.oldPos?D=l.addToPath(P,!0,void 0,0):D=l.addToPath(F,void 0,!0,1),y=l.extractCommon(D,n,t,$),D.oldPos+1>=f&&y+1>=u)return i(Bt(l,D.lastComponent,n,t,l.useLongestToken));T[$]=D,D.oldPos+1>=f&&(b=Math.min(b,$-1)),y+1>=u&&(w=Math.max(w,$+1))}g++}if(a)(function $(){setTimeout(function(){if(g>m||Date.now()>L)return a();v()||$()},0)})();else for(;g<=m&&Date.now()<=L;){var k=v();if(k)return k}},addToPath:function(t,n,r,s){var a=t.lastComponent;return a&&a.added===n&&a.removed===r?{oldPos:t.oldPos+s,lastComponent:{count:a.count+1,added:n,removed:r,previousComponent:a.previousComponent}}:{oldPos:t.oldPos+s,lastComponent:{count:1,added:n,removed:r,previousComponent:a}}},extractCommon:function(t,n,r,s){for(var a=n.length,l=r.length,i=t.oldPos,u=i-s,f=0;u+1<a&&i+1<l&&this.equals(n[u+1],r[i+1]);)u++,i++,f++;return f&&(t.lastComponent={count:f,previousComponent:t.lastComponent}),t.oldPos=i,u},equals:function(t,n){return this.options.comparator?this.options.comparator(t,n):t===n||this.options.ignoreCase&&t.toLowerCase()===n.toLowerCase()},removeEmpty:function(t){for(var n=[],r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n},castInput:function(t){return t},tokenize:function(t){return t.split("")},join:function(t){return t.join("")}};function Bt(e,t,n,r,s){for(var a=[],l;t;)a.push(t),l=t.previousComponent,delete t.previousComponent,t=l;a.reverse();for(var i=0,u=a.length,f=0,g=0;i<u;i++){var m=a[i];if(m.removed){if(m.value=e.join(r.slice(g,g+m.count)),g+=m.count,i&&a[i-1].added){var L=a[i-1];a[i-1]=a[i],a[i]=L}}else{if(!m.added&&s){var C=n.slice(f,f+m.count);C=C.map(function(y,w){var b=r[g+w];return b.length>y.length?b:y}),m.value=e.join(C)}else m.value=e.join(n.slice(f,f+m.count));f+=m.count,m.added||(g+=m.count)}}var T=a[u-1];return u>1&&typeof T.value=="string"&&(T.added||T.removed)&&e.equals("",T.value)&&(a[u-2].value+=T.value,a.pop()),a}var Ut=new K;function Xe(e,t,n){return Ut.diff(e,t,n)}var je=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,Ve=/\S/,Fe=new K;Fe.equals=function(e,t){return this.options.ignoreCase&&(e=e.toLowerCase(),t=t.toLowerCase()),e===t||this.options.ignoreWhitespace&&!Ve.test(e)&&!Ve.test(t)};Fe.tokenize=function(e){for(var t=e.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/),n=0;n<t.length-1;n++)!t[n+1]&&t[n+2]&&je.test(t[n])&&je.test(t[n+2])&&(t[n]+=t[n+2],t.splice(n+1,2),n--);return t};function Ye(e,t,n){return Fe.diff(e,t,n)}var Je=new K;Je.tokenize=function(e){this.options.stripTrailingCr&&(e=e.replace(/\r\n/g,`
2
- `));var t=[],n=e.split(/(\n|\r\n)/);n[n.length-1]||n.pop();for(var r=0;r<n.length;r++){var s=n[r];r%2&&!this.options.newlineIsToken?t[t.length-1]+=s:(this.options.ignoreWhitespace&&(s=s.trim()),t.push(s))}return t};var Wt=new K;Wt.tokenize=function(e){return e.split(/(\S.+?[.!?])(?=\s+|$)/)};var Gt=new K;Gt.tokenize=function(e){return e.split(/([{}:;,]|\s+)/)};function be(e){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?be=function(t){return typeof t}:be=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},be(e)}var zt=Object.prototype.toString,ce=new K;ce.useLongestToken=!0;ce.tokenize=Je.tokenize;ce.castInput=function(e){var t=this.options,n=t.undefinedReplacement,r=t.stringifyReplacer,s=r===void 0?function(a,l){return typeof l>"u"?n:l}:r;return typeof e=="string"?e:JSON.stringify(Re(e,null,null,s),s," ")};ce.equals=function(e,t){return K.prototype.equals.call(ce,e.replace(/,([\r\n])/g,"$1"),t.replace(/,([\r\n])/g,"$1"))};function Re(e,t,n,r,s){t=t||[],n=n||[],r&&(e=r(s,e));var a;for(a=0;a<t.length;a+=1)if(t[a]===e)return n[a];var l;if(zt.call(e)==="[object Array]"){for(t.push(e),l=new Array(e.length),n.push(l),a=0;a<e.length;a+=1)l[a]=Re(e[a],t,n,r,s);return t.pop(),n.pop(),l}if(e&&e.toJSON&&(e=e.toJSON()),be(e)==="object"&&e!==null){t.push(e),l={},n.push(l);var i=[],u;for(u in e)e.hasOwnProperty(u)&&i.push(u);for(i.sort(),a=0;a<i.length;a+=1)u=i[a],l[u]=Re(e[u],t,n,r,u);t.pop(),n.pop()}else l=e;return l}var we=new K;we.tokenize=function(e){return e.slice()};we.join=we.removeEmpty=function(e){return e};function Ze(e,t,n){return we.diff(e,t,n)}var Kt=500,jt=100,Qe=gt("BYGONE_MAX_INLINE_HIGHLIGHT_LINE_LENGTH",Kt),Vt=gt("BYGONE_DIFF_TIMEOUT_MS",jt);function Z(e,t,n={}){let r=et(e),s=et(t),a=Ze(r,s,{timeout:n.timeoutMs??Vt});if(!a)return Xt(r,s);let l=[],i=[],u=[],f=[],g=1,m=1;for(let L=0;L<a.length;L++){let T=a[L],y=T.removed?T.value:[],w=T.added?T.value:[];if(!T.added&&!T.removed){for(let b of T.value)i.push(V("context",b,g)),u.push(V("context",b,m)),l.push(ne(j("context",b,g++),j("context",b,m++)));continue}if(T.removed&&L+1<a.length&&a[L+1].added){let b=a[L+1],v=i.length,k=u.length,$=ht(y,b.value);for(let{left:D,right:F}of $){let P,B;D!==void 0&&(P=V("removed",D,g),i.push(P)),F!==void 0&&(B=V("added",F,m),u.push(B)),P&&B&&gn(P,B),l.push(ne(D===void 0?te():j("removed",D,g++),F===void 0?te():j("added",F,m++)))}f.push(ve("replace",v,i.length,k,u.length)),L++;continue}if(T.removed){let b=i.length,v=u.length;for(let k of y)i.push(V("removed",k,g)),l.push(ne(j("removed",k,g++),te()));f.push(ve("delete",b,i.length,v,u.length));continue}if(T.added){let b=i.length,v=u.length;for(let k of w)u.push(V("added",k,m)),l.push(ne(te(),j("added",k,m++)));f.push(ve("insert",b,i.length,v,u.length))}}let C=l.some(L=>L.left.kind!=="context"||L.right.kind!=="context");return{rows:l,leftLines:i,rightLines:u,blocks:f,hasChanges:C}}function Xt(e,t){let n=e.map((l,i)=>V("removed",l,i+1)),r=t.map((l,i)=>V("added",l,i+1)),s=[...e.map((l,i)=>ne(j("removed",l,i+1),te())),...t.map((l,i)=>ne(te(),j("added",l,i+1)))],a="replace";return e.length===0?a="insert":t.length===0&&(a="delete"),{rows:s,leftLines:n,rightLines:r,blocks:s.length===0?[]:[ve(a,0,e.length,0,t.length)],hasChanges:s.length>0}}function et(e){if(e.length===0)return[];let t=e.replace(/\r\n/g,`
1
+ "use strict";(()=>{function V(){}V.prototype={diff:function(t,n){var r,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},a=s.callback;typeof s=="function"&&(a=s,s={}),this.options=s;var l=this;function i(N){return a?(setTimeout(function(){a(void 0,N)},0),!0):N}t=this.castInput(t),n=this.castInput(n),t=this.removeEmpty(this.tokenize(t)),n=this.removeEmpty(this.tokenize(n));var u=n.length,d=t.length,g=1,h=u+d;s.maxEditLength&&(h=Math.min(h,s.maxEditLength));var T=(r=s.timeout)!==null&&r!==void 0?r:1/0,L=Date.now()+T,C=[{oldPos:-1,lastComponent:void 0}],I=this.extractCommon(C[0],n,t,0);if(C[0].oldPos+1>=d&&I+1>=u)return i([{value:this.join(n),count:n.length}]);var w=-1/0,b=1/0;function x(){for(var N=Math.max(w,-g);N<=Math.min(b,g);N+=2){var _=void 0,M=C[N-1],O=C[N+1];M&&(C[N-1]=void 0);var B=!1;if(O){var ie=O.oldPos-N;B=O&&0<=ie&&ie<u}var fe=M&&M.oldPos+1<d;if(!B&&!fe){C[N]=void 0;continue}if(!fe||B&&M.oldPos+1<O.oldPos?_=l.addToPath(O,!0,void 0,0):_=l.addToPath(M,void 0,!0,1),I=l.extractCommon(_,n,t,N),_.oldPos+1>=d&&I+1>=u)return i(Vt(l,_.lastComponent,n,t,l.useLongestToken));C[N]=_,_.oldPos+1>=d&&(b=Math.min(b,N-1)),I+1>=u&&(w=Math.max(w,N+1))}g++}if(a)(function N(){setTimeout(function(){if(g>h||Date.now()>L)return a();x()||N()},0)})();else for(;g<=h&&Date.now()<=L;){var k=x();if(k)return k}},addToPath:function(t,n,r,s){var a=t.lastComponent;return a&&a.added===n&&a.removed===r?{oldPos:t.oldPos+s,lastComponent:{count:a.count+1,added:n,removed:r,previousComponent:a.previousComponent}}:{oldPos:t.oldPos+s,lastComponent:{count:1,added:n,removed:r,previousComponent:a}}},extractCommon:function(t,n,r,s){for(var a=n.length,l=r.length,i=t.oldPos,u=i-s,d=0;u+1<a&&i+1<l&&this.equals(n[u+1],r[i+1]);)u++,i++,d++;return d&&(t.lastComponent={count:d,previousComponent:t.lastComponent}),t.oldPos=i,u},equals:function(t,n){return this.options.comparator?this.options.comparator(t,n):t===n||this.options.ignoreCase&&t.toLowerCase()===n.toLowerCase()},removeEmpty:function(t){for(var n=[],r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n},castInput:function(t){return t},tokenize:function(t){return t.split("")},join:function(t){return t.join("")}};function Vt(e,t,n,r,s){for(var a=[],l;t;)a.push(t),l=t.previousComponent,delete t.previousComponent,t=l;a.reverse();for(var i=0,u=a.length,d=0,g=0;i<u;i++){var h=a[i];if(h.removed){if(h.value=e.join(r.slice(g,g+h.count)),g+=h.count,i&&a[i-1].added){var L=a[i-1];a[i-1]=a[i],a[i]=L}}else{if(!h.added&&s){var T=n.slice(d,d+h.count);T=T.map(function(I,w){var b=r[g+w];return b.length>I.length?b:I}),h.value=e.join(T)}else h.value=e.join(n.slice(d,d+h.count));d+=h.count,h.added||(g+=h.count)}}var C=a[u-1];return u>1&&typeof C.value=="string"&&(C.added||C.removed)&&e.equals("",C.value)&&(a[u-2].value+=C.value,a.pop()),a}var Xt=new V;function Ze(e,t,n){return Xt.diff(e,t,n)}var Ye=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,Je=/\S/,Fe=new V;Fe.equals=function(e,t){return this.options.ignoreCase&&(e=e.toLowerCase(),t=t.toLowerCase()),e===t||this.options.ignoreWhitespace&&!Je.test(e)&&!Je.test(t)};Fe.tokenize=function(e){for(var t=e.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/),n=0;n<t.length-1;n++)!t[n+1]&&t[n+2]&&Ye.test(t[n])&&Ye.test(t[n+2])&&(t[n]+=t[n+2],t.splice(n+1,2),n--);return t};function Qe(e,t,n){return Fe.diff(e,t,n)}var et=new V;et.tokenize=function(e){this.options.stripTrailingCr&&(e=e.replace(/\r\n/g,`
2
+ `));var t=[],n=e.split(/(\n|\r\n)/);n[n.length-1]||n.pop();for(var r=0;r<n.length;r++){var s=n[r];r%2&&!this.options.newlineIsToken?t[t.length-1]+=s:(this.options.ignoreWhitespace&&(s=s.trim()),t.push(s))}return t};var Yt=new V;Yt.tokenize=function(e){return e.split(/(\S.+?[.!?])(?=\s+|$)/)};var Jt=new V;Jt.tokenize=function(e){return e.split(/([{}:;,]|\s+)/)};function ye(e){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ye=function(t){return typeof t}:ye=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ye(e)}var Zt=Object.prototype.toString,le=new V;le.useLongestToken=!0;le.tokenize=et.tokenize;le.castInput=function(e){var t=this.options,n=t.undefinedReplacement,r=t.stringifyReplacer,s=r===void 0?function(a,l){return typeof l>"u"?n:l}:r;return typeof e=="string"?e:JSON.stringify(Re(e,null,null,s),s," ")};le.equals=function(e,t){return V.prototype.equals.call(le,e.replace(/,([\r\n])/g,"$1"),t.replace(/,([\r\n])/g,"$1"))};function Re(e,t,n,r,s){t=t||[],n=n||[],r&&(e=r(s,e));var a;for(a=0;a<t.length;a+=1)if(t[a]===e)return n[a];var l;if(Zt.call(e)==="[object Array]"){for(t.push(e),l=new Array(e.length),n.push(l),a=0;a<e.length;a+=1)l[a]=Re(e[a],t,n,r,s);return t.pop(),n.pop(),l}if(e&&e.toJSON&&(e=e.toJSON()),ye(e)==="object"&&e!==null){t.push(e),l={},n.push(l);var i=[],u;for(u in e)e.hasOwnProperty(u)&&i.push(u);for(i.sort(),a=0;a<i.length;a+=1)u=i[a],l[u]=Re(e[u],t,n,r,u);t.pop(),n.pop()}else l=e;return l}var Ie=new V;Ie.tokenize=function(e){return e.slice()};Ie.join=Ie.removeEmpty=function(e){return e};function tt(e,t,n){return Ie.diff(e,t,n)}var en=500,tn=100,nt=wt("BYGONE_MAX_INLINE_HIGHLIGHT_LINE_LENGTH",en),nn=wt("BYGONE_DIFF_TIMEOUT_MS",tn);function Q(e,t,n={}){let r=rt(e),s=rt(t),a=tt(r,s,{timeout:n.timeoutMs??nn});if(!a)return rn(r,s);let l=[],i=[],u=[],d=[],g=1,h=1;for(let L=0;L<a.length;L++){let C=a[L],I=C.removed?C.value:[],w=C.added?C.value:[];if(!C.added&&!C.removed){for(let b of C.value)i.push(Y("context",b,g)),u.push(Y("context",b,h)),l.push(re(X("context",b,g++),X("context",b,h++)));continue}if(C.removed&&L+1<a.length&&a[L+1].added){let b=a[L+1],x=i.length,k=u.length,N=pt(I,b.value);for(let{left:_,right:M}of N){let O,B;_!==void 0&&(O=Y("removed",_,g),i.push(O)),M!==void 0&&(B=Y("added",M,h),u.push(B)),O&&B&&En(O,B),l.push(re(_===void 0?ne():X("removed",_,g++),M===void 0?ne():X("added",M,h++)))}d.push(Se("replace",x,i.length,k,u.length)),L++;continue}if(C.removed){let b=i.length,x=u.length;for(let k of I)i.push(Y("removed",k,g)),l.push(re(X("removed",k,g++),ne()));d.push(Se("delete",b,i.length,x,u.length));continue}if(C.added){let b=i.length,x=u.length;for(let k of w)u.push(Y("added",k,h)),l.push(re(ne(),X("added",k,h++)));d.push(Se("insert",b,i.length,x,u.length))}}let T=l.some(L=>L.left.kind!=="context"||L.right.kind!=="context");return{rows:l,leftLines:i,rightLines:u,blocks:d,hasChanges:T}}function rn(e,t){let n=e.map((l,i)=>Y("removed",l,i+1)),r=t.map((l,i)=>Y("added",l,i+1)),s=[...e.map((l,i)=>re(X("removed",l,i+1),ne())),...t.map((l,i)=>re(ne(),X("added",l,i+1)))],a="replace";return e.length===0?a="insert":t.length===0&&(a="delete"),{rows:s,leftLines:n,rightLines:r,blocks:s.length===0?[]:[Se(a,0,e.length,0,t.length)],hasChanges:s.length>0}}function rt(e){if(e.length===0)return[];let t=e.replace(/\r\n/g,`
3
3
  `).split(`
4
- `);return t[t.length-1]===""&&t.pop(),t}var ut=1e4,tt=2e3,Yt=.52,Jt=.35,dt=.38,Zt=.33,ft=.86,Ee=.08,ye=.05,Ie=-.12,nt=5e3,Qt=2e3,rt=4,en=8,Me=4;function ht(e,t){if(e.length===0)return t.map(u=>({right:u}));if(t.length===0)return e.map(u=>({left:u}));if(e.length===1&&t.length===1){let u=Pe(e[0],t[0]);return(u.eligible||u.score>=Jt)&&_e(e[0],t[0])&&le(X(e[0]))&&le(X(t[0]))?[{left:e[0],right:t[0]}]:[{left:e[0]},{right:t[0]}]}if(e.length*t.length>ut)return sn(e,t);let n=tn(e,t),r=Array.from({length:e.length+1},()=>new Array(t.length+1).fill(Number.NEGATIVE_INFINITY)),s=Array.from({length:e.length+1},()=>new Array(t.length+1).fill(null));r[0][0]=0;for(let u=1;u<=e.length;u++)r[u][0]=r[u-1][0]+Ie,s[u][0]="left";for(let u=1;u<=t.length;u++)r[0][u]=r[0][u-1]+Ie,s[0][u]="right";for(let u=1;u<=e.length;u++)for(let f=1;f<=t.length;f++){let g=n[u-1][f-1],C=[{move:"left",score:r[u-1][f]+Ie},{move:"right",score:r[u][f-1]+Ie},{move:"match",score:g===null?Number.NEGATIVE_INFINITY:r[u-1][f-1]+g}].reduce((L,T)=>T.score>L.score?T:L);r[u][f]=C.score,s[u][f]=C.move}let a=[],l=e.length,i=t.length;for(;l>0||i>0;){let u=s[l][i];u==="match"?a.push({left:e[--l],right:t[--i]}):u==="left"?a.push({left:e[--l]}):a.push({right:t[--i]})}return a.reverse()}function Pe(e,t){let n=X(e),r=X(t),s=le(n),a=le(r);if(!s||!a||n.length>tt||r.length>tt)return{score:0,eligible:!1,characterSimilarity:0,tokenSimilarity:0,lengthSimilarity:0};if(n===r)return{score:1,eligible:!0,characterSimilarity:1,tokenSimilarity:1,lengthSimilarity:1};let l=Oe(n),i=Oe(r),u=mn(n,r),f=fn(l,i),g=Math.min(n.length,r.length)/Math.max(n.length,r.length),m=hn(l,i),C=u*.52+f*.32+g*.1+m*.06,L=u>=.52||f>=.45||u>=.48&&f>=.28;return{score:C,eligible:L&&C>=Yt,characterSimilarity:u,tokenSimilarity:f,lengthSimilarity:g}}function tn(e,t){let n=e.map(y=>t.map(w=>Pe(y,w))),r=mt(e,t),s=n.map(y=>De(y)),a=t.map((y,w)=>De(n.map(b=>b[w]))),l=n.map((y,w)=>y.map((b,v)=>{if(r.has(`${w}:${v}`))return Math.max(b.score,1);if(!b.eligible)return null;let k=s[w],$=a[v],D=b.score===k.best&&b.score===$.best,F=b.score>=ft?Ee/2:Ee,P=k.best-k.second>=F,B=$.best-$.second>=F;return D&&P&&B?b.score:null}));if(Math.max(e.length,t.length)>en||Math.abs(e.length-t.length)>Me)return l;let i=(y,w,b)=>y.score>=dt&&_e(e[w],t[b])&&Math.abs(w-b)<=Me,u=n.map((y,w)=>xe(y,(b,v)=>i(b,w,v))),f=t.map((y,w)=>xe(n.map(b=>b[w]),(b,v)=>i(b,v,w))),g=(y,w,b)=>y.score>=Zt&&_e(e[w],t[b])&&Math.abs(w-b)<=Me,m=n.map((y,w)=>xe(y,(b,v)=>g(b,w,v))),C=t.map((y,w)=>xe(n.map(b=>b[w]),(b,v)=>g(b,v,w))),L=(y,w)=>{let b=n[y][w];if(!i(b,y,w))return!1;let v=u[y],k=f[w];return b.score===v.best&&b.score===k.best&&v.best-v.second>=ye&&k.best-k.second>=ye},T=(y,w)=>{let b=n[y][w];if(!g(b,y,w))return!1;let v=m[y],k=C[w];return b.score===v.best&&b.score===k.best&&v.best-v.second>=ye&&k.best-k.second>=ye};return l.map((y,w)=>y.map((b,v)=>{if(b!==null)return b;let k=L(w,v)&&(nn(l,w,v)||rn(n,w,v,L)),$=on(n,w,v,(D,F)=>g(n[D][F],D,F),T);return!k&&!$?null:n[w][v].score}))}function nn(e,t,n){return t>0&&n>0&&e[t-1][n-1]!==null||t+1<e.length&&n+1<e[t+1].length&&e[t+1][n+1]!==null}function rn(e,t,n,r){return t>0&&n>0&&r(t-1,n-1)||t+1<e.length&&n+1<e[t+1].length&&r(t+1,n+1)}function on(e,t,n,r,s){let a=t,l=n;for(;a>0&&l>0&&r(a-1,l-1);)a--,l--;let i=t,u=n,f=e[t][n].score,g=1;for(;i+1<e.length&&u+1<e[i+1].length&&r(i+1,u+1);)i++,u++,f+=e[i][u].score,g++;for(let m=t-1,C=n-1;m>=a&&C>=l;m--,C--)f+=e[m][C].score,g++;return g>=3&&f/g>=dt&&s(a,l)&&s(i,u)}function xe(e,t){let n=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY;return e.forEach((s,a)=>{t(s,a)&&(s.score>n?(r=n,n=s.score):s.score>r&&(r=s.score))}),{best:n,second:r}}function De(e){let t=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(let r of e)r.eligible&&(r.score>t?(n=t,t=r.score):r.score>n&&(n=r.score));return{best:t,second:n}}function sn(e,t){let n=an(e,t),r=[],s=0,a=0;for(let l of n)ct(r,e.slice(s,l.leftIndex),t.slice(a,l.rightIndex)),r.push({left:e[l.leftIndex],right:t[l.rightIndex]}),s=l.leftIndex+1,a=l.rightIndex+1;return ct(r,e.slice(s),t.slice(a)),r}function an(e,t){let n=cn(e,t);if(n===null)return[];let r=mt(e,t),s=n.map(({leftIndex:f,rightIndex:g,exact:m})=>({leftIndex:f,rightIndex:g,exact:m,structural:r.has(`${f}:${g}`),match:Pe(e[f],t[g])})).filter(f=>f.exact||f.structural||f.match.eligible),a=st(s,"leftIndex"),l=st(s,"rightIndex"),i=s.filter(f=>{if(f.exact||f.structural)return!0;let g=a.get(f.leftIndex),m=l.get(f.rightIndex);if(!g||!m||f.match.score!==g.best||f.match.score!==m.best)return!1;let C=f.match.score>=ft?Ee/2:Ee;return g.best-g.second>=C&&m.best-m.second>=C}),u=un(i,t.length);return u.length<=Qt?u:[]}function cn(e,t){let n=it(e,X),r=it(t,X),s=new Map;for(let[i,u]of n){let f=r.get(i);if(!le(i)||u.length!==1||f?.length!==1)continue;let g=u[0],m=f[0];if(s.set(`${g}:${m}`,{leftIndex:g,rightIndex:m,exact:!0}),s.size>nt)return null}let a=ot(e),l=ot(t);for(let[i,u]of a){let f=l.get(i);if(!(!f||u.length>rt||f.length>rt))for(let g of u)for(let m of f){let C=`${g}:${m}`;if(!s.has(C)&&(s.set(C,{leftIndex:g,rightIndex:m,exact:!1}),s.size>nt))return null}}return[...s.values()]}function it(e,t){let n=new Map;return e.forEach((r,s)=>{let a=t(r),l=n.get(a)??[];l.push(s),n.set(a,l)}),n}function ot(e){let t=new Map;return e.forEach((n,r)=>{let s=new Set(Oe(X(n)).filter(ln));for(let a of s){let l=t.get(a)??[];l.push(r),t.set(a,l)}}),t}function ln(e){return e.length>=2&&/[\p{L}\p{N}_$]/u.test(e)}function st(e,t){let n=new Map;for(let r of e){let s=n.get(r[t])??[];s.push(r.match),n.set(r[t],s)}return new Map([...n].map(([r,s])=>[r,De(s)]))}function un(e,t){let n=[...e].sort((f,g)=>f.leftIndex-g.leftIndex||f.rightIndex-g.rightIndex),r=new Array(t+2).fill(0),s=new Array(t+2).fill(-1),a=new Array(n.length).fill(0),l=new Array(n.length).fill(-1);for(let f=0;f<n.length;){let g=f+1;for(;g<n.length&&n[g].leftIndex===n[f].leftIndex;)g++;for(let m=f;m<g;m++){let C=at(r,s,n[m].rightIndex),L=n[m].exact||n[m].structural?.5:0;a[m]=C.score+n[m].match.score+L,l[m]=C.candidateIndex}for(let m=f;m<g;m++)dn(r,s,n[m].rightIndex+1,a[m],m);f=g}let i=at(r,s,t+1),u=[];for(let f=i.candidateIndex;f>=0;f=l[f])u.push({leftIndex:n[f].leftIndex,rightIndex:n[f].rightIndex});return u.reverse()}function at(e,t,n){let r=0,s=-1;for(let a=n;a>0;a-=a&-a)e[a]>r&&(r=e[a],s=t[a]);return{score:r,candidateIndex:s}}function dn(e,t,n,r,s){for(let a=n;a<e.length;a+=a&-a)r>e[a]&&(e[a]=r,t[a]=s)}function ct(e,t,n){if(t.length*n.length<=ut){e.push(...ht(t,n));return}e.push(...t.map(r=>({left:r}))),e.push(...n.map(r=>({right:r})))}function X(e){return e.trim().replace(/\s+/g," ")}function mt(e,t){let n=lt(e),r=lt(t),s=new Set;for(let[a,l]of n){let i=r.get(a);l.length===1&&i?.length===1&&s.add(`${l[0]}:${i[0]}`)}return s}function lt(e){let t=new Map;return e.forEach((n,r)=>{let s=He(n);if(!s)return;let a=t.get(s)??[];a.push(r),t.set(s,a)}),t}function _e(e,t){let n=He(e),r=He(t);return!n||!r?n===r:n.split(":",1)[0]===r.split(":",1)[0]}function He(e){let t=X(e),n=[["function",/^(?:(?:export|default)\s+)*(?:async\s+)?function\s*\*?\s*([\p{L}_$][\p{L}\p{N}_$]*)\s*\(/u],["function",/^(?:async\s+)?def\s+([\p{L}_][\p{L}\p{N}_]*)\s*\(/u],["function",/^(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+([\p{L}_][\p{L}\p{N}_]*)\s*(?:<[^>]*>)?\s*\(/u],["function",/^func\s+(?:\([^)]*\)\s*)?([\p{L}_][\p{L}\p{N}_]*)\s*\(/u],["class",/^(?:(?:export|default|abstract|public)\s+)*class\s+([\p{L}_$][\p{L}\p{N}_$]*)\b/u]];for(let[r,s]of n){let a=t.match(s);if(a)return`${r}:${a[1]}`}return null}function le(e){return e.length<3?!1:/[\p{L}\p{N}_$]/u.test(e)&&!/^[\s()[\]{};,.:+\-*/=>|&!?'"`]+$/.test(e)}function Oe(e){return e.toLowerCase().match(/[\p{L}_$][\p{L}\p{N}_$]*|\p{N}+(?:\.\p{N}+)?|[^\s\p{L}\p{N}_$]/gu)??[]}function fn(e,t){if(e.length+t.length===0)return 1;let n=new Map;e.forEach(s=>n.set(s,(n.get(s)??0)+1));let r=0;for(let s of t){let a=n.get(s)??0;a>0&&(r++,n.set(s,a-1))}return 2*r/(e.length+t.length)}function hn(e,t){if(e.length===0||t.length===0)return 0;let n=e[0]===t[0]?.5:0,r=e[e.length-1]===t[t.length-1]?.5:0;return n+r}function mn(e,t){let n=e.length+t.length;return n===0?1:2*Xe(e,t).filter(s=>!s.added&&!s.removed).reduce((s,a)=>s+a.value.length,0)/n}function gn(e,t){if(e.content.length>Qe||t.content.length>Qe)return;let{leftSegments:n,rightSegments:r,hasInlineChanges:s}=pn(e.content,t.content);s&&(e.segments=n,t.segments=r)}function pn(e,t){let n=Ye(e,t),r=[],s=[],a=!1;for(let l of n){let i=l.value;if(!l.added&&!l.removed){let f={kind:"context",text:i,emphasis:!1};r.push(f),s.push(f);continue}let u=/[^\s]/.test(i);a=a||u,l.removed&&r.push({kind:"removed",text:i,emphasis:u}),l.added&&s.push({kind:"added",text:i,emphasis:u})}return{leftSegments:r,rightSegments:s,hasInlineChanges:a}}function te(){return{kind:"placeholder",content:"",lineNumber:null}}function j(e,t,n){return{kind:e,content:t,lineNumber:n}}function V(e,t,n){return{kind:e,content:t,lineNumber:n}}function ne(e,t){return{left:e,right:t}}function ve(e,t,n,r,s){return{kind:e,leftStart:t,leftEnd:n,rightStart:r,rightEnd:s}}function gt(e,t){let n=typeof process<"u"?process.env?.[e]:void 0,r=Number.parseInt(n??"",10);return Number.isFinite(r)&&r>0?r:t}function pt(){return{leftFileName:"test-file-1.js",rightFileName:"test-file-2.js",leftContent:`// Test File 1 - Example JavaScript Code
4
+ `);return t[t.length-1]===""&&t.pop(),t}var ht=1e4,it=2e3,on=.52,sn=.35,gt=.38,an=.33,mt=.86,Te=.08,xe=.05,ve=-.12,ot=5e3,cn=2e3,st=4,ln=8,Me=4;function pt(e,t){if(e.length===0)return t.map(u=>({right:u}));if(t.length===0)return e.map(u=>({left:u}));if(e.length===1&&t.length===1){let u=Oe(e[0],t[0]);return(u.eligible||u.score>=sn)&&_e(e[0],t[0])&&ue(J(e[0]))&&ue(J(t[0]))?[{left:e[0],right:t[0]}]:[{left:e[0]},{right:t[0]}]}if(e.length*t.length>ht)return gn(e,t);let n=un(e,t),r=Array.from({length:e.length+1},()=>new Array(t.length+1).fill(Number.NEGATIVE_INFINITY)),s=Array.from({length:e.length+1},()=>new Array(t.length+1).fill(null));r[0][0]=0;for(let u=1;u<=e.length;u++)r[u][0]=r[u-1][0]+ve,s[u][0]="left";for(let u=1;u<=t.length;u++)r[0][u]=r[0][u-1]+ve,s[0][u]="right";for(let u=1;u<=e.length;u++)for(let d=1;d<=t.length;d++){let g=n[u-1][d-1],T=[{move:"left",score:r[u-1][d]+ve},{move:"right",score:r[u][d-1]+ve},{move:"match",score:g===null?Number.NEGATIVE_INFINITY:r[u-1][d-1]+g}].reduce((L,C)=>C.score>L.score?C:L);r[u][d]=T.score,s[u][d]=T.move}let a=[],l=e.length,i=t.length;for(;l>0||i>0;){let u=s[l][i];u==="match"?a.push({left:e[--l],right:t[--i]}):u==="left"?a.push({left:e[--l]}):a.push({right:t[--i]})}return a.reverse()}function Oe(e,t){let n=J(e),r=J(t),s=ue(n),a=ue(r);if(!s||!a||n.length>it||r.length>it)return{score:0,eligible:!1,characterSimilarity:0,tokenSimilarity:0,lengthSimilarity:0};if(n===r)return{score:1,eligible:!0,characterSimilarity:1,tokenSimilarity:1,lengthSimilarity:1};let l=Pe(n),i=Pe(r),u=vn(n,r),d=In(l,i),g=Math.min(n.length,r.length)/Math.max(n.length,r.length),h=xn(l,i),T=u*.52+d*.32+g*.1+h*.06,L=u>=.52||d>=.45||u>=.48&&d>=.28;return{score:T,eligible:L&&T>=on,characterSimilarity:u,tokenSimilarity:d,lengthSimilarity:g}}function un(e,t){let n=e.map(I=>t.map(w=>Oe(I,w))),r=bt(e,t),s=n.map(I=>De(I)),a=t.map((I,w)=>De(n.map(b=>b[w]))),l=n.map((I,w)=>I.map((b,x)=>{if(r.has(`${w}:${x}`))return Math.max(b.score,1);if(!b.eligible)return null;let k=s[w],N=a[x],_=b.score===k.best&&b.score===N.best,M=b.score>=mt?Te/2:Te,O=k.best-k.second>=M,B=N.best-N.second>=M;return _&&O&&B?b.score:null}));if(Math.max(e.length,t.length)>ln||Math.abs(e.length-t.length)>Me)return l;let i=(I,w,b)=>I.score>=gt&&_e(e[w],t[b])&&Math.abs(w-b)<=Me,u=n.map((I,w)=>Ee(I,(b,x)=>i(b,w,x))),d=t.map((I,w)=>Ee(n.map(b=>b[w]),(b,x)=>i(b,x,w))),g=(I,w,b)=>I.score>=an&&_e(e[w],t[b])&&Math.abs(w-b)<=Me,h=n.map((I,w)=>Ee(I,(b,x)=>g(b,w,x))),T=t.map((I,w)=>Ee(n.map(b=>b[w]),(b,x)=>g(b,x,w))),L=(I,w)=>{let b=n[I][w];if(!i(b,I,w))return!1;let x=u[I],k=d[w];return b.score===x.best&&b.score===k.best&&x.best-x.second>=xe&&k.best-k.second>=xe},C=(I,w)=>{let b=n[I][w];if(!g(b,I,w))return!1;let x=h[I],k=T[w];return b.score===x.best&&b.score===k.best&&x.best-x.second>=xe&&k.best-k.second>=xe};return l.map((I,w)=>I.map((b,x)=>{if(b!==null)return b;let k=L(w,x)&&(dn(l,w,x)||fn(n,w,x,L)),N=hn(n,w,x,(_,M)=>g(n[_][M],_,M),C);return!k&&!N?null:n[w][x].score}))}function dn(e,t,n){return t>0&&n>0&&e[t-1][n-1]!==null||t+1<e.length&&n+1<e[t+1].length&&e[t+1][n+1]!==null}function fn(e,t,n,r){return t>0&&n>0&&r(t-1,n-1)||t+1<e.length&&n+1<e[t+1].length&&r(t+1,n+1)}function hn(e,t,n,r,s){let a=t,l=n;for(;a>0&&l>0&&r(a-1,l-1);)a--,l--;let i=t,u=n,d=e[t][n].score,g=1;for(;i+1<e.length&&u+1<e[i+1].length&&r(i+1,u+1);)i++,u++,d+=e[i][u].score,g++;for(let h=t-1,T=n-1;h>=a&&T>=l;h--,T--)d+=e[h][T].score,g++;return g>=3&&d/g>=gt&&s(a,l)&&s(i,u)}function Ee(e,t){let n=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY;return e.forEach((s,a)=>{t(s,a)&&(s.score>n?(r=n,n=s.score):s.score>r&&(r=s.score))}),{best:n,second:r}}function De(e){let t=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(let r of e)r.eligible&&(r.score>t?(n=t,t=r.score):r.score>n&&(n=r.score));return{best:t,second:n}}function gn(e,t){let n=mn(e,t),r=[],s=0,a=0;for(let l of n)dt(r,e.slice(s,l.leftIndex),t.slice(a,l.rightIndex)),r.push({left:e[l.leftIndex],right:t[l.rightIndex]}),s=l.leftIndex+1,a=l.rightIndex+1;return dt(r,e.slice(s),t.slice(a)),r}function mn(e,t){let n=pn(e,t);if(n===null)return[];let r=bt(e,t),s=n.map(({leftIndex:d,rightIndex:g,exact:h})=>({leftIndex:d,rightIndex:g,exact:h,structural:r.has(`${d}:${g}`),match:Oe(e[d],t[g])})).filter(d=>d.exact||d.structural||d.match.eligible),a=lt(s,"leftIndex"),l=lt(s,"rightIndex"),i=s.filter(d=>{if(d.exact||d.structural)return!0;let g=a.get(d.leftIndex),h=l.get(d.rightIndex);if(!g||!h||d.match.score!==g.best||d.match.score!==h.best)return!1;let T=d.match.score>=mt?Te/2:Te;return g.best-g.second>=T&&h.best-h.second>=T}),u=wn(i,t.length);return u.length<=cn?u:[]}function pn(e,t){let n=at(e,J),r=at(t,J),s=new Map;for(let[i,u]of n){let d=r.get(i);if(!ue(i)||u.length!==1||d?.length!==1)continue;let g=u[0],h=d[0];if(s.set(`${g}:${h}`,{leftIndex:g,rightIndex:h,exact:!0}),s.size>ot)return null}let a=ct(e),l=ct(t);for(let[i,u]of a){let d=l.get(i);if(!(!d||u.length>st||d.length>st))for(let g of u)for(let h of d){let T=`${g}:${h}`;if(!s.has(T)&&(s.set(T,{leftIndex:g,rightIndex:h,exact:!1}),s.size>ot))return null}}return[...s.values()]}function at(e,t){let n=new Map;return e.forEach((r,s)=>{let a=t(r),l=n.get(a)??[];l.push(s),n.set(a,l)}),n}function ct(e){let t=new Map;return e.forEach((n,r)=>{let s=new Set(Pe(J(n)).filter(bn));for(let a of s){let l=t.get(a)??[];l.push(r),t.set(a,l)}}),t}function bn(e){return e.length>=2&&/[\p{L}\p{N}_$]/u.test(e)}function lt(e,t){let n=new Map;for(let r of e){let s=n.get(r[t])??[];s.push(r.match),n.set(r[t],s)}return new Map([...n].map(([r,s])=>[r,De(s)]))}function wn(e,t){let n=[...e].sort((d,g)=>d.leftIndex-g.leftIndex||d.rightIndex-g.rightIndex),r=new Array(t+2).fill(0),s=new Array(t+2).fill(-1),a=new Array(n.length).fill(0),l=new Array(n.length).fill(-1);for(let d=0;d<n.length;){let g=d+1;for(;g<n.length&&n[g].leftIndex===n[d].leftIndex;)g++;for(let h=d;h<g;h++){let T=ut(r,s,n[h].rightIndex),L=n[h].exact||n[h].structural?.5:0;a[h]=T.score+n[h].match.score+L,l[h]=T.candidateIndex}for(let h=d;h<g;h++)yn(r,s,n[h].rightIndex+1,a[h],h);d=g}let i=ut(r,s,t+1),u=[];for(let d=i.candidateIndex;d>=0;d=l[d])u.push({leftIndex:n[d].leftIndex,rightIndex:n[d].rightIndex});return u.reverse()}function ut(e,t,n){let r=0,s=-1;for(let a=n;a>0;a-=a&-a)e[a]>r&&(r=e[a],s=t[a]);return{score:r,candidateIndex:s}}function yn(e,t,n,r,s){for(let a=n;a<e.length;a+=a&-a)r>e[a]&&(e[a]=r,t[a]=s)}function dt(e,t,n){if(t.length*n.length<=ht){e.push(...pt(t,n));return}e.push(...t.map(r=>({left:r}))),e.push(...n.map(r=>({right:r})))}function J(e){return e.trim().replace(/\s+/g," ")}function bt(e,t){let n=ft(e),r=ft(t),s=new Set;for(let[a,l]of n){let i=r.get(a);l.length===1&&i?.length===1&&s.add(`${l[0]}:${i[0]}`)}return s}function ft(e){let t=new Map;return e.forEach((n,r)=>{let s=He(n);if(!s)return;let a=t.get(s)??[];a.push(r),t.set(s,a)}),t}function _e(e,t){let n=He(e),r=He(t);return!n||!r?n===r:n.split(":",1)[0]===r.split(":",1)[0]}function He(e){let t=J(e),n=[["function",/^(?:(?:export|default)\s+)*(?:async\s+)?function\s*\*?\s*([\p{L}_$][\p{L}\p{N}_$]*)\s*\(/u],["function",/^(?:async\s+)?def\s+([\p{L}_][\p{L}\p{N}_]*)\s*\(/u],["function",/^(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+([\p{L}_][\p{L}\p{N}_]*)\s*(?:<[^>]*>)?\s*\(/u],["function",/^func\s+(?:\([^)]*\)\s*)?([\p{L}_][\p{L}\p{N}_]*)\s*\(/u],["class",/^(?:(?:export|default|abstract|public)\s+)*class\s+([\p{L}_$][\p{L}\p{N}_$]*)\b/u]];for(let[r,s]of n){let a=t.match(s);if(a)return`${r}:${a[1]}`}return null}function ue(e){return e.length<3?!1:/[\p{L}\p{N}_$]/u.test(e)&&!/^[\s()[\]{};,.:+\-*/=>|&!?'"`]+$/.test(e)}function Pe(e){return e.toLowerCase().match(/[\p{L}_$][\p{L}\p{N}_$]*|\p{N}+(?:\.\p{N}+)?|[^\s\p{L}\p{N}_$]/gu)??[]}function In(e,t){if(e.length+t.length===0)return 1;let n=new Map;e.forEach(s=>n.set(s,(n.get(s)??0)+1));let r=0;for(let s of t){let a=n.get(s)??0;a>0&&(r++,n.set(s,a-1))}return 2*r/(e.length+t.length)}function xn(e,t){if(e.length===0||t.length===0)return 0;let n=e[0]===t[0]?.5:0,r=e[e.length-1]===t[t.length-1]?.5:0;return n+r}function vn(e,t){let n=e.length+t.length;return n===0?1:2*Ze(e,t).filter(s=>!s.added&&!s.removed).reduce((s,a)=>s+a.value.length,0)/n}function En(e,t){if(e.content.length>nt||t.content.length>nt)return;let{leftSegments:n,rightSegments:r,hasInlineChanges:s}=Sn(e.content,t.content);s&&(e.segments=n,t.segments=r)}function Sn(e,t){let n=Qe(e,t),r=[],s=[],a=!1;for(let l of n){let i=l.value;if(!l.added&&!l.removed){let d={kind:"context",text:i,emphasis:!1};r.push(d),s.push(d);continue}let u=/[^\s]/.test(i);a=a||u,l.removed&&r.push({kind:"removed",text:i,emphasis:u}),l.added&&s.push({kind:"added",text:i,emphasis:u})}return{leftSegments:r,rightSegments:s,hasInlineChanges:a}}function ne(){return{kind:"placeholder",content:"",lineNumber:null}}function X(e,t,n){return{kind:e,content:t,lineNumber:n}}function Y(e,t,n){return{kind:e,content:t,lineNumber:n}}function re(e,t){return{left:e,right:t}}function Se(e,t,n,r,s){return{kind:e,leftStart:t,leftEnd:n,rightStart:r,rightEnd:s}}function wt(e,t){let n=typeof process<"u"?process.env?.[e]:void 0,r=Number.parseInt(n??"",10);return Number.isFinite(r)&&r>0?r:t}function yt(){return{leftFileName:"test-file-1.js",rightFileName:"test-file-2.js",leftContent:`// Test File 1 - Example JavaScript Code
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
7
 
@@ -145,7 +145,7 @@ if (require.main === module) {
145
145
  }
146
146
 
147
147
  module.exports = FileProcessor;
148
- `}}function bt(e){if(!_(e)||e.version!==1)throw new Error("Unsupported or missing change-tour manifest version.");if(A(e.title,"title"),A(e.generatedAt,"generatedAt"),e.sourceUrl!==void 0&&A(e.sourceUrl,"sourceUrl"),!_(e.range))throw new Error("Change-tour manifest range must be an object.");for(let r of["baseRef","headRef","mergeBaseOid","headOid"])A(e.range[r],`range.${r}`);if(!_(e.summary))throw new Error("Change-tour manifest summary must be an object.");for(let r of["changedFiles","includedScenes","additions","deletions","commitCount"])Q(e.summary[r],`summary.${r}`);if(ue(e.summary.omittedFiles,"summary.omittedFiles"),!Array.isArray(e.commits)||!Array.isArray(e.chapters)||!Array.isArray(e.scenes))throw new Error("Change-tour manifest commits, chapters, and scenes must be arrays.");if(e.files!==void 0&&!Array.isArray(e.files))throw new Error("Change-tour manifest files must be an array.");let t=new Set;for(let[r,s]of e.scenes.entries()){if(Ue(s,r),t.has(s.id))throw new Error(`Duplicate change-tour scene id: ${s.id}`);t.add(s.id)}for(let[r,s]of e.chapters.entries()){if(!_(s))throw new Error(`chapters[${r}] must be an object.`);A(s.id,`chapters[${r}].id`),A(s.title,`chapters[${r}].title`),ue(s.sceneIds,`chapters[${r}].sceneIds`);for(let a of s.sceneIds)if(!t.has(a))throw new Error(`Chapter references unknown scene id: ${a}`)}if(e.summary.includedScenes!==e.scenes.length)throw new Error("summary.includedScenes must match the number of scenes.");let n=e.files===void 0?In(e.scenes):e.files.map((r,s)=>(yn(r,s),r));if(e.files!==void 0&&e.summary.changedFiles!==n.length)throw new Error("summary.changedFiles must match the number of files.");return{...e,files:n}}function Ue(e,t){if(!_(e)||!["text-diff","discussion","walkthrough","stacked-diff","deconstructed-diff"].includes(String(e.kind)))throw new Error(`scenes[${t}] must be a text-diff, discussion, walkthrough, stacked-diff, or deconstructed-diff scene.`);for(let n of["id","title"])A(e[n],`scenes[${t}].${n}`);if(xn(e,`scenes[${t}]`),e.kind!=="discussion"){if(e.kind==="walkthrough"){if(!Array.isArray(e.steps)||e.steps.length===0)throw new Error(`scenes[${t}].steps must be a non-empty array.`);for(let[n,r]of e.steps.entries()){let s=`scenes[${t}].steps[${n}]`;if(!_(r)||!_(r.focus)||!_(r.diff))throw new Error(`${s} must contain focus and diff objects.`);for(let a of["id","title","body"])A(r[a],`${s}.${a}`);if(r.depth!==void 0&&!["mentioned","explained","contextualized"].includes(String(r.depth)))throw new Error(`${s}.depth must be mentioned, explained, or contextualized.`);if(Be(r.focus,`${s}.focus`),Ue(r.diff,t),r.diff.kind!=="text-diff")throw new Error(`${s}.diff must be a text-diff scene.`);if(r.connection!==void 0){if(!_(r.connection))throw new Error(`${s}.connection must be an object.`);A(r.connection.id,`${s}.connection.id`),A(r.connection.label,`${s}.connection.label`),Be(r.connection.from,`${s}.connection.from`),Be(r.connection.to,`${s}.connection.to`)}}return}if(e.kind==="stacked-diff"){bn(e,t);return}if(e.kind==="deconstructed-diff"){wn(e,t);return}for(let n of["path","leftLabel","rightLabel","leftContent","rightContent"])A(e[n],`scenes[${t}].${n}`);e.previousPath!==void 0&&A(e.previousPath,`scenes[${t}].previousPath`),A(e.changeKind,`scenes[${t}].changeKind`),Q(e.additions,`scenes[${t}].additions`),Q(e.deletions,`scenes[${t}].deletions`),e.focusChangeIndex!==void 0&&Q(e.focusChangeIndex,`scenes[${t}].focusChangeIndex`)}}function bn(e,t){if(!Array.isArray(e.stack)||e.stack.length<3||e.stack.length>6)throw new Error(`scenes[${t}].stack must contain between 3 and 6 revisions.`);for(let[n,r]of e.stack.entries()){if(!_(r))throw new Error(`scenes[${t}].stack[${n}] must be an object.`);for(let s of["id","ref","oid","label"])A(r[s],`scenes[${t}].stack[${n}].${s}`)}wt(e.files,e.stack.length,t),yt(e.steps,e.stack.length,t,!1)}function wn(e,t){if(e.stageLabel!=="Explanation stages")throw new Error(`scenes[${t}].stageLabel must be Explanation stages.`);if(!_(e.realRange))throw new Error(`scenes[${t}].realRange must be an object.`);for(let r of["baseRef","targetRef","baseOid","targetOid"])A(e.realRange[r],`scenes[${t}].realRange.${r}`);if(!Array.isArray(e.panels)||e.panels.length<2||e.panels.length>13)throw new Error(`scenes[${t}].panels must contain a baseline and between 1 and 12 stages.`);let n=e.panels;for(let[r,s]of n.entries()){if(!_(s))throw new Error(`scenes[${t}].panels[${r}] must be an object.`);for(let l of["id","label","role"])A(s[l],`scenes[${t}].panels[${r}].${l}`);let a=r===0?"baseline":"stage";if(s.role!==a)throw new Error(`scenes[${t}].panels[${r}].role must be ${a}.`);r>0&&A(s.stageId,`scenes[${t}].panels[${r}].stageId`)}if(wt(e.files,n.length,t),yt(e.steps,n.length,t,!0),Array.isArray(e.steps)&&e.steps.length!==n.length-1)throw new Error(`scenes[${t}].steps must match the number of explanation stages.`);Array.isArray(e.steps)&&e.steps.forEach((r,s)=>{let a=n[s+1];if(!_(r)||!_(a)||a.stageId!==r.id)throw new Error(`scenes[${t}].panels must align with explanation stage ids.`)})}function wt(e,t,n){if(!Array.isArray(e)||e.length===0)throw new Error(`scenes[${n}].files must be non-empty.`);for(let[r,s]of e.entries()){if(!_(s))throw new Error(`scenes[${n}].files[${r}] must be an object.`);if(A(s.path,`scenes[${n}].files[${r}].path`),!Array.isArray(s.panels)||s.panels.length!==t)throw new Error(`scenes[${n}].files[${r}].panels must match panel count.`);for(let[a,l]of s.panels.entries()){if(!_(l))throw new Error(`scenes[${n}].files[${r}].panels[${a}] must be an object.`);for(let i of["id","label","content"])A(l[i],`scenes[${n}].files[${r}].panels[${a}].${i}`);if(l.path!==void 0&&A(l.path,`scenes[${n}].files[${r}].panels[${a}].path`),typeof l.exists!="boolean")throw new Error(`scenes[${n}].files[${r}].panels[${a}].exists must be boolean.`)}}}function yt(e,t,n,r){if(!Array.isArray(e)||e.length===0)throw new Error(`scenes[${n}].steps must be non-empty.`);for(let[s,a]of e.entries()){if(!_(a))throw new Error(`scenes[${n}].steps[${s}] must be an object.`);for(let l of["id","title","body","file","side"])A(a[l],`scenes[${n}].steps[${s}].${l}`);if(Q(a.pairIndex,`scenes[${n}].steps[${s}].pairIndex`),Number(a.pairIndex)>=t-1)throw new Error(`scenes[${n}].steps[${s}].pairIndex is outside the panels.`);if(r){if(ue(a.introducedHunks,`scenes[${n}].steps[${s}].introducedHunks`),a.introducedHunks.length===0)throw new Error(`scenes[${n}].steps[${s}].introducedHunks must be non-empty.`);if(Number(a.pairIndex)!==s)throw new Error(`scenes[${n}].steps[${s}].pairIndex must match its explanation stage.`)}if(a.side!=="left"&&a.side!=="right")throw new Error(`scenes[${n}].steps[${s}].side must be left or right.`);a.startLine!==void 0&&Se(a.startLine,`scenes[${n}].steps[${s}].startLine`),a.endLine!==void 0&&Se(a.endLine,`scenes[${n}].steps[${s}].endLine`)}}function yn(e,t){if(!_(e))throw new Error(`files[${t}] must be an object.`);if(e.kind==="text-diff"){Ue(e,t);return}if(e.kind!=="omitted")throw new Error(`files[${t}].kind must be text-diff or omitted.`);for(let n of["id","title","path","changeKind","reason"])A(e[n],`files[${t}].${n}`);e.previousPath!==void 0&&A(e.previousPath,`files[${t}].previousPath`),Q(e.additions,`files[${t}].additions`),Q(e.deletions,`files[${t}].deletions`)}function In(e){let t=new Map;for(let n of e){if(n.kind==="text-diff"){t.has(n.path)||t.set(n.path,n);continue}if(n.kind==="walkthrough")for(let r of n.steps)t.has(r.diff.path)||t.set(r.diff.path,r.diff)}return[...t.values()].sort((n,r)=>n.path.localeCompare(r.path))}function Be(e,t){if(!_(e))throw new Error(`${t} must be an object.`);for(let n of["id","path","revision","excerpt"])A(e[n],`${t}.${n}`);if(e.revision!=="base"&&e.revision!=="head")throw new Error(`${t}.revision must be base or head.`);if(Se(e.startLine,`${t}.startLine`),Se(e.endLine,`${t}.endLine`),Number(e.endLine)<Number(e.startLine))throw new Error(`${t}.endLine must not precede startLine.`)}function xn(e,t){A(e.summary,`${t}.summary`),ue(e.bullets,`${t}.bullets`),ue(e.tags,`${t}.tags`),A(e.takeaway,`${t}.takeaway`)}function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function A(e,t){if(typeof e!="string")throw new Error(`${t} must be a string.`)}function ue(e,t){if(!Array.isArray(e)||e.some(n=>typeof n!="string"))throw new Error(`${t} must be an array of strings.`)}function Q(e,t){if(!Number.isInteger(e)||Number(e)<0)throw new Error(`${t} must be a non-negative integer.`)}function Se(e,t){if(!Number.isInteger(e)||Number(e)<1)throw new Error(`${t} must be a positive integer.`)}function It(e,t,n){let r=e.findIndex(i=>i.id===t),s=r>=0?r:0,a=e[s];if(!a||a.kind!=="walkthrough"&&a.kind!=="stacked-diff"&&a.kind!=="deconstructed-diff"||!n)return{sceneIndex:s,stepIndex:0};let l=a.steps.findIndex(i=>i.id===n);return{sceneIndex:s,stepIndex:l>=0?l:0}}function xt(e,t,n){let r=e[t.sceneIndex];if(!r)return null;if(n>0)return(r.kind==="walkthrough"||r.kind==="stacked-diff"||r.kind==="deconstructed-diff")&&t.stepIndex<r.steps.length-1?{sceneIndex:t.sceneIndex,stepIndex:t.stepIndex+1}:t.sceneIndex<e.length-1?{sceneIndex:t.sceneIndex+1,stepIndex:0}:null;if((r.kind==="walkthrough"||r.kind==="stacked-diff"||r.kind==="deconstructed-diff")&&t.stepIndex>0)return{sceneIndex:t.sceneIndex,stepIndex:t.stepIndex-1};if(t.sceneIndex===0)return null;let s=e[t.sceneIndex-1];return{sceneIndex:t.sceneIndex-1,stepIndex:s.kind==="walkthrough"||s.kind==="stacked-diff"||s.kind==="deconstructed-diff"?s.steps.length-1:0}}function vt(e,t,n){if(!t)return null;let r=e.map((i,u)=>({file:i,fileIndex:u})).filter(({file:i})=>i.kind==="text-diff"),s=r.findIndex(({file:i})=>i.path===t),a=s+n,l=s>=0?r[a]:null;return l?{fileIndex:l.fileIndex,path:l.file.path}:null}function St(e,t,n="all",r=300){let s=t.trim().toLocaleLowerCase();if(!s||r<=0)return[];let a=[];if(n!=="code"){let l=new Map;e.chapters.forEach(i=>i.sceneIds.forEach(u=>l.set(u,i.title))),e.scenes.forEach((i,u)=>{let f=[l.get(i.id),i.title,i.summary,...i.bullets,...i.tags,i.takeaway],g=Et(f,s);g&&a.push({kind:"narrative",sceneIndex:u,label:i.title,preview:g}),En(i)&&i.steps.forEach((m,C)=>{let L=Et([m.title,m.body,"connection"in m?m.connection?.label:void 0],s);L&&a.push({kind:"narrative",sceneIndex:u,stepIndex:C,label:`${i.title} \xB7 ${m.title}`,preview:L})})})}if(n!=="narrative"&&a.length<r)for(let l=0;l<e.files.length;l+=1){let i=e.files[l];if(i.kind==="text-diff"){for(let[u,f]of[[0,i.leftContent],[1,i.rightContent]])for(let g of vn(f,s))if(a.push({kind:"code",fileIndex:l,sideIndex:u,label:`${i.path} \xB7 ${u===0?"base":"head"}`,...g}),a.length>=r)return a}}return a.slice(0,r)}function Et(e,t){return e.find(n=>n?.toLocaleLowerCase().includes(t))}function vn(e,t){let n=[];return e.replace(/\r\n/g,`
148
+ `}}function It(e){if(!H(e)||e.version!==1)throw new Error("Unsupported or missing change-tour manifest version.");if(A(e.title,"title"),A(e.generatedAt,"generatedAt"),e.sourceUrl!==void 0&&A(e.sourceUrl,"sourceUrl"),!H(e.range))throw new Error("Change-tour manifest range must be an object.");for(let r of["baseRef","headRef","mergeBaseOid","headOid"])A(e.range[r],`range.${r}`);if(!H(e.summary))throw new Error("Change-tour manifest summary must be an object.");for(let r of["changedFiles","includedScenes","additions","deletions","commitCount"])ee(e.summary[r],`summary.${r}`);if(de(e.summary.omittedFiles,"summary.omittedFiles"),!Array.isArray(e.commits)||!Array.isArray(e.chapters)||!Array.isArray(e.scenes))throw new Error("Change-tour manifest commits, chapters, and scenes must be arrays.");if(e.files!==void 0&&!Array.isArray(e.files))throw new Error("Change-tour manifest files must be an array.");let t=new Set;for(let[r,s]of e.scenes.entries()){if(Ue(s,r),t.has(s.id))throw new Error(`Duplicate change-tour scene id: ${s.id}`);t.add(s.id)}for(let[r,s]of e.chapters.entries()){if(!H(s))throw new Error(`chapters[${r}] must be an object.`);A(s.id,`chapters[${r}].id`),A(s.title,`chapters[${r}].title`),de(s.sceneIds,`chapters[${r}].sceneIds`);for(let a of s.sceneIds)if(!t.has(a))throw new Error(`Chapter references unknown scene id: ${a}`)}if(e.summary.includedScenes!==e.scenes.length)throw new Error("summary.includedScenes must match the number of scenes.");let n=e.files===void 0?kn(e.scenes):e.files.map((r,s)=>(Ln(r,s),r));if(e.files!==void 0&&e.summary.changedFiles!==n.length)throw new Error("summary.changedFiles must match the number of files.");return{...e,files:n}}function Ue(e,t){if(!H(e)||!["text-diff","discussion","walkthrough","stacked-diff","deconstructed-diff"].includes(String(e.kind)))throw new Error(`scenes[${t}] must be a text-diff, discussion, walkthrough, stacked-diff, or deconstructed-diff scene.`);for(let n of["id","title"])A(e[n],`scenes[${t}].${n}`);if(Nn(e,`scenes[${t}]`),e.kind!=="discussion"){if(e.kind==="walkthrough"){if(!Array.isArray(e.steps)||e.steps.length===0)throw new Error(`scenes[${t}].steps must be a non-empty array.`);for(let[n,r]of e.steps.entries()){let s=`scenes[${t}].steps[${n}]`;if(!H(r)||!H(r.focus)||!H(r.diff))throw new Error(`${s} must contain focus and diff objects.`);for(let a of["id","title","body"])A(r[a],`${s}.${a}`);if(r.depth!==void 0&&!["mentioned","explained","contextualized"].includes(String(r.depth)))throw new Error(`${s}.depth must be mentioned, explained, or contextualized.`);if(Be(r.focus,`${s}.focus`),Ue(r.diff,t),r.diff.kind!=="text-diff")throw new Error(`${s}.diff must be a text-diff scene.`);if(r.connection!==void 0){if(!H(r.connection))throw new Error(`${s}.connection must be an object.`);A(r.connection.id,`${s}.connection.id`),A(r.connection.label,`${s}.connection.label`),Be(r.connection.from,`${s}.connection.from`),Be(r.connection.to,`${s}.connection.to`)}}return}if(e.kind==="stacked-diff"){Tn(e,t);return}if(e.kind==="deconstructed-diff"){Cn(e,t);return}for(let n of["path","leftLabel","rightLabel","leftContent","rightContent"])A(e[n],`scenes[${t}].${n}`);e.previousPath!==void 0&&A(e.previousPath,`scenes[${t}].previousPath`),A(e.changeKind,`scenes[${t}].changeKind`),ee(e.additions,`scenes[${t}].additions`),ee(e.deletions,`scenes[${t}].deletions`),e.focusChangeIndex!==void 0&&ee(e.focusChangeIndex,`scenes[${t}].focusChangeIndex`)}}function Tn(e,t){if(!Array.isArray(e.stack)||e.stack.length<3||e.stack.length>6)throw new Error(`scenes[${t}].stack must contain between 3 and 6 revisions.`);for(let[n,r]of e.stack.entries()){if(!H(r))throw new Error(`scenes[${t}].stack[${n}] must be an object.`);for(let s of["id","ref","oid","label"])A(r[s],`scenes[${t}].stack[${n}].${s}`)}xt(e.files,e.stack.length,t),vt(e.steps,e.stack.length,t,!1)}function Cn(e,t){if(e.stageLabel!=="Explanation stages")throw new Error(`scenes[${t}].stageLabel must be Explanation stages.`);if(!H(e.realRange))throw new Error(`scenes[${t}].realRange must be an object.`);for(let r of["baseRef","targetRef","baseOid","targetOid"])A(e.realRange[r],`scenes[${t}].realRange.${r}`);if(!Array.isArray(e.panels)||e.panels.length<2||e.panels.length>13)throw new Error(`scenes[${t}].panels must contain a baseline and between 1 and 12 stages.`);let n=e.panels;for(let[r,s]of n.entries()){if(!H(s))throw new Error(`scenes[${t}].panels[${r}] must be an object.`);for(let l of["id","label","role"])A(s[l],`scenes[${t}].panels[${r}].${l}`);let a=r===0?"baseline":"stage";if(s.role!==a)throw new Error(`scenes[${t}].panels[${r}].role must be ${a}.`);r>0&&A(s.stageId,`scenes[${t}].panels[${r}].stageId`)}if(xt(e.files,n.length,t),vt(e.steps,n.length,t,!0),Array.isArray(e.steps)&&e.steps.length!==n.length-1)throw new Error(`scenes[${t}].steps must match the number of explanation stages.`);Array.isArray(e.steps)&&e.steps.forEach((r,s)=>{let a=n[s+1];if(!H(r)||!H(a)||a.stageId!==r.id)throw new Error(`scenes[${t}].panels must align with explanation stage ids.`)})}function xt(e,t,n){if(!Array.isArray(e)||e.length===0)throw new Error(`scenes[${n}].files must be non-empty.`);for(let[r,s]of e.entries()){if(!H(s))throw new Error(`scenes[${n}].files[${r}] must be an object.`);if(A(s.path,`scenes[${n}].files[${r}].path`),!Array.isArray(s.panels)||s.panels.length!==t)throw new Error(`scenes[${n}].files[${r}].panels must match panel count.`);for(let[a,l]of s.panels.entries()){if(!H(l))throw new Error(`scenes[${n}].files[${r}].panels[${a}] must be an object.`);for(let i of["id","label","content"])A(l[i],`scenes[${n}].files[${r}].panels[${a}].${i}`);if(l.path!==void 0&&A(l.path,`scenes[${n}].files[${r}].panels[${a}].path`),typeof l.exists!="boolean")throw new Error(`scenes[${n}].files[${r}].panels[${a}].exists must be boolean.`)}}}function vt(e,t,n,r){if(!Array.isArray(e)||e.length===0)throw new Error(`scenes[${n}].steps must be non-empty.`);for(let[s,a]of e.entries()){if(!H(a))throw new Error(`scenes[${n}].steps[${s}] must be an object.`);for(let l of["id","title","body","file","side"])A(a[l],`scenes[${n}].steps[${s}].${l}`);if(ee(a.pairIndex,`scenes[${n}].steps[${s}].pairIndex`),Number(a.pairIndex)>=t-1)throw new Error(`scenes[${n}].steps[${s}].pairIndex is outside the panels.`);if(r){if(de(a.introducedHunks,`scenes[${n}].steps[${s}].introducedHunks`),a.introducedHunks.length===0)throw new Error(`scenes[${n}].steps[${s}].introducedHunks must be non-empty.`);if(Number(a.pairIndex)!==s)throw new Error(`scenes[${n}].steps[${s}].pairIndex must match its explanation stage.`)}if(a.side!=="left"&&a.side!=="right")throw new Error(`scenes[${n}].steps[${s}].side must be left or right.`);a.startLine!==void 0&&Ce(a.startLine,`scenes[${n}].steps[${s}].startLine`),a.endLine!==void 0&&Ce(a.endLine,`scenes[${n}].steps[${s}].endLine`)}}function Ln(e,t){if(!H(e))throw new Error(`files[${t}] must be an object.`);if(e.kind==="text-diff"){Ue(e,t);return}if(e.kind!=="omitted")throw new Error(`files[${t}].kind must be text-diff or omitted.`);for(let n of["id","title","path","changeKind","reason"])A(e[n],`files[${t}].${n}`);e.previousPath!==void 0&&A(e.previousPath,`files[${t}].previousPath`),ee(e.additions,`files[${t}].additions`),ee(e.deletions,`files[${t}].deletions`)}function kn(e){let t=new Map;for(let n of e){if(n.kind==="text-diff"){t.has(n.path)||t.set(n.path,n);continue}if(n.kind==="walkthrough")for(let r of n.steps)t.has(r.diff.path)||t.set(r.diff.path,r.diff)}return[...t.values()].sort((n,r)=>n.path.localeCompare(r.path))}function Be(e,t){if(!H(e))throw new Error(`${t} must be an object.`);for(let n of["id","path","revision","excerpt"])A(e[n],`${t}.${n}`);if(e.revision!=="base"&&e.revision!=="head")throw new Error(`${t}.revision must be base or head.`);if(Ce(e.startLine,`${t}.startLine`),Ce(e.endLine,`${t}.endLine`),Number(e.endLine)<Number(e.startLine))throw new Error(`${t}.endLine must not precede startLine.`)}function Nn(e,t){A(e.summary,`${t}.summary`),de(e.bullets,`${t}.bullets`),de(e.tags,`${t}.tags`),A(e.takeaway,`${t}.takeaway`)}function H(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function A(e,t){if(typeof e!="string")throw new Error(`${t} must be a string.`)}function de(e,t){if(!Array.isArray(e)||e.some(n=>typeof n!="string"))throw new Error(`${t} must be an array of strings.`)}function ee(e,t){if(!Number.isInteger(e)||Number(e)<0)throw new Error(`${t} must be a non-negative integer.`)}function Ce(e,t){if(!Number.isInteger(e)||Number(e)<1)throw new Error(`${t} must be a positive integer.`)}function St(e,t,n){let r=e.findIndex(i=>i.id===t),s=r>=0?r:0,a=e[s];if(!a||a.kind!=="walkthrough"&&a.kind!=="stacked-diff"&&a.kind!=="deconstructed-diff"||!n)return{sceneIndex:s,stepIndex:0};let l=a.steps.findIndex(i=>i.id===n);return{sceneIndex:s,stepIndex:l>=0?l:0}}function Tt(e,t,n){let r=e[t.sceneIndex];if(!r)return null;if(n>0)return(r.kind==="walkthrough"||r.kind==="stacked-diff"||r.kind==="deconstructed-diff")&&t.stepIndex<r.steps.length-1?{sceneIndex:t.sceneIndex,stepIndex:t.stepIndex+1}:t.sceneIndex<e.length-1?{sceneIndex:t.sceneIndex+1,stepIndex:0}:null;if((r.kind==="walkthrough"||r.kind==="stacked-diff"||r.kind==="deconstructed-diff")&&t.stepIndex>0)return{sceneIndex:t.sceneIndex,stepIndex:t.stepIndex-1};if(t.sceneIndex===0)return null;let s=e[t.sceneIndex-1];return{sceneIndex:t.sceneIndex-1,stepIndex:s.kind==="walkthrough"||s.kind==="stacked-diff"||s.kind==="deconstructed-diff"?s.steps.length-1:0}}function Ct(e,t,n){if(!t)return null;let r=e.map((i,u)=>({file:i,fileIndex:u})).filter(({file:i})=>i.kind==="text-diff"),s=r.findIndex(({file:i})=>i.path===t),a=s+n,l=s>=0?r[a]:null;return l?{fileIndex:l.fileIndex,path:l.file.path}:null}function Lt(e,t,n){let r=e[t.sceneIndex],s=Et(r,t.sceneIndex,t.stepIndex,n);if(s)return s;for(let a=0;a<e.length;a+=1){if(a===t.sceneIndex)continue;let l=Et(e[a],a,0,n);if(l)return l}return null}function Et(e,t,n,r){if(!e||e.kind!=="stacked-diff"&&e.kind!=="deconstructed-diff"||!e.files.some(l=>l.path===r))return null;let a=e.steps[n]?.file===r?n:e.steps.findIndex(l=>l.file===r);return{sceneIndex:t,stepIndex:a>=0?a:Math.max(n,0)}}function Nt(e,t,n="all",r=300){let s=t.trim().toLocaleLowerCase();if(!s||r<=0)return[];let a=[];if(n!=="code"){let l=new Map;e.chapters.forEach(i=>i.sceneIds.forEach(u=>l.set(u,i.title))),e.scenes.forEach((i,u)=>{let d=[l.get(i.id),i.title,i.summary,...i.bullets,...i.tags,i.takeaway],g=kt(d,s);g&&a.push({kind:"narrative",sceneIndex:u,label:i.title,preview:g}),An(i)&&i.steps.forEach((h,T)=>{let L=kt([h.title,h.body,"connection"in h?h.connection?.label:void 0],s);L&&a.push({kind:"narrative",sceneIndex:u,stepIndex:T,label:`${i.title} \xB7 ${h.title}`,preview:L})})})}if(n!=="narrative"&&a.length<r)for(let l=0;l<e.files.length;l+=1){let i=e.files[l];if(i.kind==="text-diff"){for(let[u,d]of[[0,i.leftContent],[1,i.rightContent]])for(let g of $n(d,s))if(a.push({kind:"code",fileIndex:l,sideIndex:u,label:`${i.path} \xB7 ${u===0?"base":"head"}`,...g}),a.length>=r)return a}}return a.slice(0,r)}function kt(e,t){return e.find(n=>n?.toLocaleLowerCase().includes(t))}function $n(e,t){let n=[];return e.replace(/\r\n/g,`
149
149
  `).split(`
150
- `).forEach((r,s)=>{let a=r.toLocaleLowerCase(),l=0;for(;l<=a.length-t.length;){let i=a.indexOf(t,l);if(i<0)break;n.push({lineNumber:s+1,startColumn:i+1,endColumn:i+t.length+1,preview:r}),l=i+Math.max(t.length,1)}}),n}function En(e){return e.kind==="walkthrough"||e.kind==="stacked-diff"||e.kind==="deconstructed-diff"}(function(){let t="bygone.tourSidebarWidth",s="bygone.tourNarrativeHeight",i={mode:"empty",left:null,right:null,comparisonId:0,tour:null,activeSceneIndex:-1,activeStepIndex:0,activeTourFilePath:null,tourFocusFilePath:null,tourSidebarWidth:y(),tourSidebarHidden:!1,tourNarrativeHeight:D()};window.__BYGONE_HOST__={environment:"web",editorWorkerUrl:"/media/editor.worker.js",postMessage(o){f(o)}},window.addEventListener("DOMContentLoaded",()=>{g(),q("Browser host ready.")});function u(o){window.dispatchEvent(new window.CustomEvent("bygone:host-message",{detail:o}))}async function f(o){if(!(!o||typeof o!="object")){if(o.type==="ready"){let c=new URLSearchParams(window.location.search),h=c.get("manifest");h?de(h):c.get("demo")==="1"&&Ke();return}if(o.type==="navigateFile"&&i.mode==="tour"){Tt(o.direction==="previous"?-1:1);return}o.type==="recomputeDiff"&&i.mode==="diff"&&i.left&&i.right&&(i.left.content=o.leftContent,i.right.content=o.rightContent,u({type:"showDiff",file1:i.left.name,file2:i.right.name,comparisonId:`web-${i.comparisonId}`,leftContent:i.left.content,rightContent:i.right.content,diffModel:Z(i.left.content,i.right.content),history:null}))}}function g(){let o=document.getElementById("web-compare-test"),c=document.getElementById("web-open-diff"),h=document.getElementById("web-open-diff3"),d=document.getElementById("web-diff-input"),p=document.getElementById("web-diff3-input"),x=document.getElementById("tour-previous"),E=document.getElementById("tour-next"),R=document.getElementById("tour-return-focus"),N=document.getElementById("tour-search-input"),O=document.getElementById("tour-search-scope");T(),$(),o?.addEventListener("click",()=>{Ke()}),c?.addEventListener("click",()=>{d.value="",d.click()}),h?.addEventListener("click",()=>{p.value="",p.click()}),d?.addEventListener("change",async()=>{let I=Array.from(d.files||[]);if(I.length!==2){q("Select exactly 2 files for a diff.");return}await _t(I)}),p?.addEventListener("change",async()=>{let I=Array.from(p.files||[]);if(I.length<1){q("Select one or more files.");return}await Ht(I)}),x?.addEventListener("click",()=>me(-1)),E?.addEventListener("click",()=>me(1)),R?.addEventListener("click",kt),N?.addEventListener("input",C),O?.addEventListener("change",C),document.getElementById("tour-search-results")?.addEventListener("click",I=>{let G=I.target instanceof Element?I.target.closest("[data-tour-search-result]"):null;G&&L(Number(G.getAttribute("data-tour-search-result")))}),window.addEventListener("keydown",I=>{if(i.mode==="tour"&&(I.metaKey||I.ctrlKey)&&I.shiftKey&&I.key.toLocaleLowerCase()==="f"){I.preventDefault(),I.stopImmediatePropagation(),i.tourSidebarHidden&&k(!1),N?.focus(),N?.select();return}i.mode!=="tour"||I.metaKey||I.ctrlKey||I.altKey||Mt(I.target)||(I.key==="PageUp"||I.key==="ArrowLeft"?(I.preventDefault(),me(-1)):(I.key==="PageDown"||I.key==="ArrowRight")&&(I.preventDefault(),me(1)))},!0)}let m=[];function C(){let o=document.getElementById("tour-search-input"),c=document.getElementById("tour-search-scope"),h=document.getElementById("tour-search-status"),d=document.getElementById("tour-search-results");if(!(!i.tour||!o||!c||!h||!d)){if(m=St(i.tour,o.value,c.value),!o.value.trim()){h.textContent="Cmd/Ctrl+Shift+F",d.replaceChildren();return}h.textContent=`${m.length} result${m.length===1?"":"s"}`,d.replaceChildren(...m.map((p,x)=>{let E=document.createElement("button");E.type="button",E.className="tour-search-result",E.setAttribute("role","option"),E.dataset.tourSearchResult=String(x);let R=document.createElement("span");R.className="tour-search-location",R.textContent=p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label;let N=document.createElement("span");return N.className="tour-search-preview",N.textContent=p.preview.trim(),E.append(R,N),E}))}}function L(o){let c=m[o];if(c){if(c.kind==="narrative"){fe(c.sceneIndex,c.stepIndex??0);return}ke(c.fileIndex)&&window.requestAnimationFrame(()=>u({type:"revealSearchResult",sideIndex:c.sideIndex,lineNumber:c.lineNumber,startColumn:c.startColumn,endColumn:c.endColumn}))}}function T(){let o=document.getElementById("tour-shell"),c=document.getElementById("tour-sidebar-resizer"),h=document.getElementById("tour-sidebar-hide"),d=document.getElementById("tour-sidebar-show");!o||!c||!h||!d||(v(),h.addEventListener("click",()=>k(!0)),d.addEventListener("click",()=>k(!1)),c.addEventListener("pointerdown",p=>{p.preventDefault(),document.body.classList.add("is-resizing-tour-sidebar"),c.setPointerCapture?.(p.pointerId);let x=R=>b(R.clientX),E=()=>{document.body.classList.remove("is-resizing-tour-sidebar"),window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",E),window.removeEventListener("pointercancel",E),window.localStorage.setItem(t,String(i.tourSidebarWidth))};window.addEventListener("pointermove",x),window.addEventListener("pointerup",E),window.addEventListener("pointercancel",E)}),c.addEventListener("keydown",p=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(p.key))return;p.preventDefault();let x=i.tourSidebarWidth;p.key==="Home"?x=240:p.key==="End"?x=w():x+=p.key==="ArrowLeft"?-16:16,b(x),window.localStorage.setItem(t,String(i.tourSidebarWidth))}))}function y(){let o=Number.parseInt(window.localStorage.getItem(t)||"",10);return Number.isFinite(o)?Math.min(600,Math.max(240,o)):360}function w(){return Math.max(240,Math.min(600,Math.floor(window.innerWidth*.6)))}function b(o){i.tourSidebarWidth=Math.min(w(),Math.max(240,Math.round(o))),v(),window.dispatchEvent(new Event("resize"))}function v(){document.documentElement.style.setProperty("--tour-rail-width",`${i.tourSidebarWidth}px`);let o=document.getElementById("tour-sidebar-resizer");o?.setAttribute("aria-valuemax",String(w())),o?.setAttribute("aria-valuenow",String(i.tourSidebarWidth))}function k(o){i.tourSidebarHidden=o,document.body.classList.toggle("tour-sidebar-hidden",o);let c=document.getElementById("tour-sidebar-show");c&&(c.hidden=!o),window.dispatchEvent(new Event("resize"))}function $(){let o=document.getElementById("tour-narrative-resizer");o&&(B(),o.addEventListener("pointerdown",c=>{c.preventDefault(),document.body.classList.add("is-resizing-tour-narrative"),o.setPointerCapture?.(c.pointerId),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-start"));let h=document.getElementById("tour-narrative")?.getBoundingClientRect().top||0,d=x=>P(x.clientY-h),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")),re()};window.addEventListener("pointermove",d),window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p)}),o.addEventListener("keydown",c=>{if(!["ArrowUp","ArrowDown","Home","End"].includes(c.key))return;c.preventDefault();let h=c.key==="Home"?180:c.key==="End"?F():i.tourNarrativeHeight+(c.key==="ArrowUp"?-16:16);P(h),re()}),window.addEventListener("resize",()=>{i.tourNarrativeHeight=Math.min(F(),i.tourNarrativeHeight),B()}))}function D(){let o=Number.parseInt(window.localStorage.getItem(s)||"",10);if(Number.isFinite(o))return Math.max(180,o);let c=Number.parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--tour-narrative-height"),10);return Number.isFinite(c)?c:296}function F(){let o=document.getElementById("tour-narrative")?.getBoundingClientRect().top||0;return Math.max(180,window.innerHeight-o-180)}function P(o){i.tourNarrativeHeight=Math.min(F(),Math.max(180,Math.round(o))),B(),window.dispatchEvent(new Event("resize"))}function B(){document.documentElement.style.setProperty("--tour-narrative-height",`${i.tourNarrativeHeight}px`);let o=document.getElementById("tour-narrative-resizer");o?.setAttribute("aria-valuemax",String(F())),o?.setAttribute("aria-valuenow",String(i.tourNarrativeHeight))}function re(){window.localStorage.setItem(s,String(i.tourNarrativeHeight))}async function de(o){q("Loading change tour\u2026");try{let c=await fetch(o,{cache:"no-store"});if(!c.ok)throw new Error(`Manifest request failed (${c.status}).`);i.tour=bt(await c.json()),i.mode="tour",document.body.classList.add("tour-mode"),Ct(),C();let h=new URLSearchParams(window.location.search),d=It(i.tour.scenes,h.get("scene"),h.get("step"));fe(d.sceneIndex,d.stepIndex),q("")}catch(c){q(`Could not load change tour: ${c instanceof Error?c.message:String(c)}`)}}function Ct(){let o=i.tour;if(!o)return;let c=document.getElementById("tour-shell"),h=document.getElementById("tour-title"),d=document.getElementById("tour-source"),p=document.getElementById("tour-range"),x=document.getElementById("tour-stats"),E=document.getElementById("tour-scenes"),R=document.getElementById("tour-scene-count"),N=document.getElementById("tour-files"),O=document.getElementById("tour-file-count"),I=document.getElementById("tour-commits"),G=document.getElementById("tour-commits-summary");if(!c||!h||!d||!p||!x||!E||!R||!N||!O||!I||!G)throw new Error("Presenter UI is incomplete.");c.hidden=!1,h.textContent=o.title,o.sourceUrl?(d.href=o.sourceUrl,d.hidden=!1):d.hidden=!0;let Y=ge(o.range.baseRef),z=ge(o.range.headRef),ae=o.range.headOid.slice(0,7);p.textContent=`${Y} \u2192 ${z}${z===ae?"":` \xB7 ${ae}`}`,x.textContent=`${se(o.summary.changedFiles,"file")} \xB7 +${o.summary.additions} \u2212${o.summary.deletions} \xB7 ${se(o.summary.commitCount,"commit")}`,R.textContent=String(o.scenes.length),O.textContent=String(o.files.length),G.textContent=se(o.summary.commitCount,"commit"),E.replaceChildren();let pe=new Map(o.scenes.map(S=>[S.id,S]));for(let S of o.chapters){let U=document.createElement("h2");U.className="tour-chapter-title",U.textContent=S.title,E.append(U);for(let M of S.sceneIds){let H=pe.get(M);if(!H)continue;let ee=o.scenes.indexOf(H),W=document.createElement("button");W.type="button",W.className="tour-scene",W.dataset.sceneId=H.id,W.title=H.kind==="text-diff"?H.path:H.title,W.addEventListener("click",()=>fe(ee));let J=document.createElement("span");J.className="tour-scene-number",J.textContent=String(ee+1).padStart(2,"0");let $e=document.createElement("span");$e.className="tour-scene-copy";for(let[Ot,Pt]of[["tour-scene-title",H.title],["tour-scene-path",H.kind==="text-diff"?H.path:H.kind==="deconstructed-diff"?se(H.steps.length,"explanation stage"):ie(H)?se(H.steps.length,"code step"):"Discussion"],["tour-scene-note",H.takeaway]]){let Ae=document.createElement("span");Ae.className=Ot,Ae.textContent=Pt,$e.append(Ae)}W.append(J,$e),E.append(W)}}N.replaceChildren(...o.files.map((S,U)=>{let M=document.createElement("button");M.type="button",M.className=`tour-file${S.kind==="omitted"?" is-omitted":""}`,M.dataset.filePath=S.path,M.disabled=S.kind==="omitted",M.title=S.kind==="omitted"?`${S.path}: ${S.reason}`:S.path,S.kind==="text-diff"&&M.addEventListener("click",()=>Lt(U));let H=document.createElement("span");H.className="tour-file-marker",H.textContent=S.kind==="omitted"?"\xD7":$t(S.changeKind);let ee=document.createElement("span");ee.className="tour-file-copy";let W=document.createElement("span");W.className="tour-file-path",W.textContent=S.path;let J=document.createElement("span");return J.className="tour-file-meta",J.textContent=S.kind==="omitted"?`Not rendered \xB7 ${S.reason}`:`${At(S.changeKind)} \xB7 +${S.additions} \u2212${S.deletions}`,ee.append(W,J),M.append(H,ee),M})),I.replaceChildren(...o.commits.map(S=>{let U=document.createElement("li"),M=document.createElement("span");return M.className="tour-commit-oid",M.textContent=S.shortOid,U.append(M,document.createTextNode(S.summary)),U}))}function fe(o,c=0){let h=i.tour;if(!h||o<0||o>=h.scenes.length)return;let d=h.scenes[o];i.activeSceneIndex=o,i.activeStepIndex=ie(d)?Math.min(Math.max(c,0),Math.max(d.steps.length-1,0)):0,i.tourFocusFilePath=d.kind==="text-diff"?d.path:d.kind==="walkthrough"?d.steps[i.activeStepIndex]?.diff.path??null:oe(d)?d.steps[i.activeStepIndex]?.file??null:null;let p=Rt(h,o);document.querySelectorAll(".tour-scene").forEach(E=>{E.classList.toggle("is-active",E.dataset.sceneId===d.id)}),document.querySelector(`.tour-scene[data-scene-id="${d.id}"]`)?.scrollIntoView({block:"nearest"}),Dt(d,p);let x=new URLSearchParams(window.location.search);if(x.set("scene",d.id),ie(d)?x.set("step",d.steps[i.activeStepIndex].id):x.delete("step"),window.history.replaceState(null,"",`${window.location.pathname}?${x.toString()}`),d.kind==="discussion"){document.body.classList.add("tour-discussion"),Ne();return}if(document.body.classList.remove("tour-discussion"),d.kind==="walkthrough"){Ge(d);return}if(oe(d)){ze(d);return}he(d)}function he(o,c=[],h=o.id){if(!i.tour)return;i.activeTourFilePath=o.path,Ne();let p=Z(o.leftContent,o.rightContent),x=We(o,o.leftLabel,"base"),E=We(o,o.rightLabel,"head"),R=c.find(N=>N.active);u({type:"showDiff",file1:x,file2:E,comparisonId:`tour-${h}`,leftContent:o.leftContent,rightContent:o.rightContent,diffModel:p,history:null,fileNavigation:{canGoPrevious:!!Le(-1),canGoNext:!!Le(1)},editableSides:{left:!1,right:!1},comparisonSummary:`${o.path} \xB7 ${o.takeaway}`,initialChangeIndex:R?qe(p,R.side,R.startLine):o.focusChangeIndex,tourAnnotations:c})}function We(o,c,h){let d=c.startsWith(o.path)?c.slice(o.path.length).trim():c.trim();return d?`${h} ${d}`:h}function Ge(o){let c=o.steps[i.activeStepIndex];if(!c)return;let h=o.steps.filter(d=>d.diff.path===c.diff.path).map(d=>({side:d.focus.revision==="base"?"left":"right",startLine:d.focus.startLine,endLine:d.focus.endLine,label:`${d.title}: ${d.body}`,active:d.id===c.id}));he(c.diff,h,`${o.id}-${c.id}`)}function ze(o){let c=o.steps[i.activeStepIndex];c&&Ce(o,c.file,c)}function Ce(o,c,h){let d=o.files.find(N=>N.path===c);if(!h||!d)return;i.activeTourFilePath=d.path,Ne();let p=d.panels.map((N,O)=>({id:`${o.id}-${d.path}-${N.id}`,label:N.label,path:N.path||"",content:N.content,savedContent:N.content,dirty:!1,editable:!1,stackId:Nt(o)[O].id})),x=p.slice(0,-1).map((N,O)=>({leftIndex:O,rightIndex:O+1,diffModel:Z(N.content,p[O+1].content)})),E=x[h.pairIndex]?.diffModel,R=d.path===h.file&&E&&h.startLine?qe(E,h.side,h.startLine):0;u({type:"showMultiDiff",panels:p,pairs:x,activePanelId:p[h.pairIndex+(h.side==="right"?1:0)]?.id,activePairIndex:h.pairIndex,initialChangeIndex:R,revealFirstChangeInEachPanel:o.kind==="deconstructed-diff",history:null,fileNavigation:{canGoPrevious:o.files.indexOf(d)>0,canGoNext:o.files.indexOf(d)<o.files.length-1},mutationEnabled:!1,comparisonSummary:o.kind==="deconstructed-diff"?`${o.stageLabel} \xB7 ${d.path} \xB7 ${ge(o.realRange.baseRef)} \u2192 ${ge(o.realRange.targetRef)}`:`${d.path} \xB7 ${o.takeaway}`})}function Te(o){let c=i.tour;return!c||o!==-1&&o!==1?null:xt(c.scenes,{sceneIndex:i.activeSceneIndex,stepIndex:i.activeStepIndex},o)}function me(o){let c=Te(o);return c?(fe(c.sceneIndex,c.stepIndex),!0):!1}function Le(o){let c=i.tour;return!c||o!==-1&&o!==1?null:vt(c.files,i.activeTourFilePath,o)}function Tt(o){let c=i.tour?.scenes[i.activeSceneIndex];if(c&&oe(c)){let d=c.files.findIndex(E=>E.path===i.activeTourFilePath),p=c.files[d+o],x=c.steps[i.activeStepIndex];return!p||!x?!1:(Ce(c,p.path,x),!0)}let h=Le(o);return h?ke(h.fileIndex):!1}function ke(o){let c=i.tour?.files[o];return!c||c.kind!=="text-diff"?!1:(he(c),!0)}function Lt(o){let c=i.tour?.files[o],h=i.tour?.scenes[i.activeSceneIndex];if(c?.kind==="text-diff"&&h&&oe(h)){let d=h.steps[i.activeStepIndex];if(d&&h.files.some(p=>p.path===c.path))return Ce(h,c.path,d),!0}return ke(o)}function kt(){let o=i.tour?.scenes[i.activeSceneIndex];if(!o||!i.tourFocusFilePath)return!1;if(o.kind==="walkthrough")Ge(o);else if(oe(o))ze(o);else if(o.kind==="text-diff")he(o);else return!1;return!0}function Ne(){document.querySelectorAll(".tour-file").forEach(c=>{c.classList.toggle("is-active",c.dataset.filePath===i.activeTourFilePath),c.classList.toggle("is-tour-focus",c.dataset.filePath===i.tourFocusFilePath)}),document.querySelector(".tour-file.is-active")?.scrollIntoView({block:"nearest"});let o=document.getElementById("tour-return-focus");o&&(o.hidden=!i.tourFocusFilePath||i.activeTourFilePath===i.tourFocusFilePath)}function ie(o){return o.kind==="walkthrough"||o.kind==="stacked-diff"||o.kind==="deconstructed-diff"}function oe(o){return o.kind==="stacked-diff"||o.kind==="deconstructed-diff"}function Nt(o){return o.kind==="deconstructed-diff"?o.panels:o.stack}function $t(o){return{added:"+",deleted:"\u2212",renamed:"\u2192",modified:"\u2022"}[o]||"\u2022"}function At(o){return`${o.charAt(0).toUpperCase()}${o.slice(1)}`}function Rt(o,c){let h=o.scenes[c],d=o.chapters.findIndex(R=>R.sceneIds.includes(h.id)),p=d>=0?o.chapters[d]:null,x=p?p.sceneIds.indexOf(h.id)+1:c+1,E=p?p.sceneIds.length:o.scenes.length;return{chapter:p,chapterIndex:d,chapterNumber:d>=0?d+1:c+1,sceneInChapter:x,scenesInChapter:E}}function Ft(o,c,h){let d=[`Ch ${o.chapterNumber}`,`Scene ${o.sceneInChapter}/${o.scenesInChapter}`];return ie(c)&&d.push(`Step ${h+1}/${c.steps.length}`),d.join(" \xB7 ")}function qe(o,c,h){let p=(c==="left"?o.leftLines:o.rightLines).findIndex(I=>I.lineNumber===h);if(p<0)return 0;let x=c==="left"?"leftStart":"rightStart",E=c==="left"?"leftEnd":"rightEnd",R=o.blocks.findIndex(I=>p>=I[x]&&p<I[E]);if(R>=0)return R;let N=0,O=Number.POSITIVE_INFINITY;return o.blocks.forEach((I,G)=>{let Y=Math.min(Math.abs(p-I[x]),Math.abs(p-I[E]));Y<O&&(N=G,O=Y)}),N}function ge(o){return/^[0-9a-f]{40}$/i.test(o)?o.slice(0,7):o}function se(o,c){return`${o} ${o===1?c:`${c}s`}`}function Mt(o){return o instanceof Element&&!!o.closest('a, button, input, select, summary, textarea, [contenteditable="true"], [role="textbox"], .monaco-editor')}function Dt(o,c){let h=document.getElementById("tour-narrative"),d=document.getElementById("tour-breadcrumb"),p=document.getElementById("tour-narrative-chapter"),x=document.getElementById("tour-narrative-title"),E=document.getElementById("tour-narrative-summary"),R=document.getElementById("tour-narrative-bullets"),N=document.getElementById("tour-narrative-tags"),O=document.getElementById("tour-narrative-takeaway"),I=document.getElementById("tour-step"),G=document.getElementById("tour-step-title"),Y=document.getElementById("tour-step-body"),z=document.getElementById("tour-connection"),ae=document.getElementById("tour-previous"),pe=document.getElementById("tour-next");if(!h||!d||!p||!x||!E||!R||!N||!O||!I||!G||!Y||!z||!ae||!pe)throw new Error("Tour narrative UI is incomplete.");h.hidden=!1,d.textContent=Ft(c,o,i.activeStepIndex),p.textContent=o.kind==="deconstructed-diff"?`${c.chapter?.title||"Change tour"} \xB7 ${o.stageLabel}`:c.chapter?.title||"Change tour",x.textContent=o.title,E.textContent=o.summary,R.replaceChildren(...o.bullets.map(U=>{let M=document.createElement("li");return M.textContent=U,M})),N.replaceChildren(...o.tags.map(U=>{let M=document.createElement("span");return M.textContent=U,M})),O.textContent=o.takeaway;let S=ie(o)?o.steps[i.activeStepIndex]:null;I.hidden=!S,S?(G.textContent=o.kind==="deconstructed-diff"?`Stage ${i.activeStepIndex+1}: ${S.title}`:S.title,Y.textContent=S.body,"connection"in S&&S.connection?(z.hidden=!1,z.textContent=`${S.connection.from.path} \u2192 ${S.connection.to.path} \xB7 ${S.connection.label}`):(z.hidden=!0,z.textContent="")):(z.hidden=!0,z.textContent=""),ae.disabled=!Te(-1),pe.disabled=!Te(1)}function Ke(){let o=pt();i.mode="diff",i.comparisonId+=1,i.left={name:o.leftFileName,content:o.leftContent},i.right={name:o.rightFileName,content:o.rightContent},q("Loaded sample diff."),u({type:"showDiff",file1:i.left.name,file2:i.right.name,comparisonId:`web-${i.comparisonId}`,leftContent:i.left.content,rightContent:i.right.content,diffModel:Z(i.left.content,i.right.content),history:null})}async function _t(o){let[c,h]=o,[d,p]=await Promise.all([c.text(),h.text()]);i.mode="diff",i.comparisonId+=1,i.left={name:c.name,content:d},i.right={name:h.name,content:p},q(`Loaded ${c.name} and ${h.name}.`),u({type:"showDiff",file1:c.name,file2:h.name,comparisonId:`web-${i.comparisonId}`,leftContent:d,rightContent:p,diffModel:Z(d,p),history:null})}async function Ht(o){let c=await Promise.all(o.map(async(h,d)=>{let p=await h.text();return{id:`web-panel-${d}`,label:h.name,content:p,savedContent:p,dirty:!1,editable:!0}}));i.mode="multi-diff",q(`Loaded ${c.length}-panel diff for ${c.map(h=>h.label).join(", ")}.`),u({type:"showMultiDiff",panels:c,pairs:c.slice(0,-1).map((h,d)=>({leftIndex:d,rightIndex:d+1,diffModel:Z(h.content,c[d+1].content)}))})}function q(o){let c=document.getElementById("web-status");c&&(c.textContent=o)}})();})();
150
+ `).forEach((r,s)=>{let a=r.toLocaleLowerCase(),l=0;for(;l<=a.length-t.length;){let i=a.indexOf(t,l);if(i<0)break;n.push({lineNumber:s+1,startColumn:i+1,endColumn:i+t.length+1,preview:r}),l=i+Math.max(t.length,1)}}),n}function An(e){return e.kind==="walkthrough"||e.kind==="stacked-diff"||e.kind==="deconstructed-diff"}function $t(e,t){let n=e?.blocks[0],r=t==="left"?e?.leftLines:e?.rightLines;if(!n||!r?.length)return;let s=t==="left"?n.leftStart:n.rightStart,a=t==="left"?n.leftEnd:n.rightEnd,l=r.slice(s,a),i=l[0]?.lineNumber??r[Math.min(s,r.length-1)]?.lineNumber;if(Number.isInteger(i))return{startLine:i,endLine:l.at(-1)?.lineNumber??i}}function At(e,t,n,r){let s=[];return e.scenes.forEach((a,l)=>{a.kind==="walkthrough"&&a.steps.forEach((i,u)=>{i.diff.path===t&&s.push({side:i.focus.revision==="base"?"left":"right",startLine:i.focus.startLine,endLine:i.focus.endLine,label:`${a.title} \xB7 ${i.title}: ${i.body}`,active:l===n&&u===r,jumpTarget:{sceneIndex:l,stepIndex:u}})})}),s}function Rt(e,t,n,r,s){let a=[];return e.scenes.forEach((l,i)=>{l.kind==="stacked-diff"&&l.steps.forEach((u,d)=>{if(u.file!==t)return;let g=u.startLine===void 0?s?.(u.pairIndex,u.side):{startLine:u.startLine,endLine:u.endLine??u.startLine};if(!g)return;let h=u.pairIndex+(u.side==="right"?1:0);a.push({pairIndex:u.pairIndex,panelIndex:h,side:u.side,startLine:g.startLine,endLine:g.endLine,label:`${l.title} \xB7 ${u.title}: ${u.body}`,active:i===n&&d===r,jumpTarget:{sceneIndex:i,stepIndex:d}})})}),a}(function(){let t="bygone.tourSidebarWidth",s="bygone.tourNarrativeHeight",i={mode:"empty",left:null,right:null,comparisonId:0,tour:null,activeSceneIndex:-1,activeStepIndex:0,activeTourFilePath:null,tourFocusFilePath:null,tourSidebarWidth:I(),tourSidebarHidden:!1,tourNarrativeHeight:_()};window.__BYGONE_HOST__={environment:"web",editorWorkerUrl:"/media/editor.worker.js",postMessage(o){d(o)}},window.addEventListener("DOMContentLoaded",()=>{g(),j("Browser host ready.")});function u(o){window.dispatchEvent(new window.CustomEvent("bygone:host-message",{detail:o}))}async function d(o){if(!(!o||typeof o!="object")){if(o.type==="ready"){let c=new URLSearchParams(window.location.search),m=c.get("manifest");m?fe(m):c.get("demo")==="1"&&Xe();return}if(o.type==="navigateFile"&&i.mode==="tour"){Dt(o.direction==="previous"?-1:1);return}if(o.type==="navigateTourStep"&&i.mode==="tour"){let c=o.sceneIndex,m=o.stepIndex;Number.isInteger(c)&&Number.isInteger(m)&&oe(c,m);return}o.type==="recomputeDiff"&&i.mode==="diff"&&i.left&&i.right&&(i.left.content=o.leftContent,i.right.content=o.rightContent,u({type:"showDiff",file1:i.left.name,file2:i.right.name,comparisonId:`web-${i.comparisonId}`,leftContent:i.left.content,rightContent:i.right.content,diffModel:Q(i.left.content,i.right.content),history:null}))}}function g(){let o=document.getElementById("web-compare-test"),c=document.getElementById("web-open-diff"),m=document.getElementById("web-open-diff3"),f=document.getElementById("web-diff-input"),p=document.getElementById("web-diff3-input"),E=document.getElementById("tour-previous"),S=document.getElementById("tour-next"),$=document.getElementById("tour-return-focus"),R=document.getElementById("tour-search-input"),U=document.getElementById("tour-search-scope");C(),N(),o?.addEventListener("click",()=>{Xe()}),c?.addEventListener("click",()=>{f.value="",f.click()}),m?.addEventListener("click",()=>{p.value="",p.click()}),f?.addEventListener("change",async()=>{let y=Array.from(f.files||[]);if(y.length!==2){j("Select exactly 2 files for a diff.");return}await zt(y)}),p?.addEventListener("change",async()=>{let y=Array.from(p.files||[]);if(y.length<1){j("Select one or more files.");return}await qt(y)}),E?.addEventListener("click",()=>me(-1)),S?.addEventListener("click",()=>me(1)),$?.addEventListener("click",_t),R?.addEventListener("input",T),U?.addEventListener("change",T),document.getElementById("tour-search-results")?.addEventListener("click",y=>{let W=y.target instanceof Element?y.target.closest("[data-tour-search-result]"):null;W&&L(Number(W.getAttribute("data-tour-search-result")))}),window.addEventListener("keydown",y=>{if(i.mode==="tour"&&(y.metaKey||y.ctrlKey)&&y.shiftKey&&y.key.toLocaleLowerCase()==="f"){y.preventDefault(),y.stopImmediatePropagation(),i.tourSidebarHidden&&k(!1),R?.focus(),R?.select();return}i.mode!=="tour"||y.metaKey||y.ctrlKey||y.altKey||Wt(y.target)||(y.key==="PageUp"||y.key==="ArrowLeft"?(y.preventDefault(),me(-1)):(y.key==="PageDown"||y.key==="ArrowRight")&&(y.preventDefault(),me(1)))},!0)}let h=[];function T(){let o=document.getElementById("tour-search-input"),c=document.getElementById("tour-search-scope"),m=document.getElementById("tour-search-status"),f=document.getElementById("tour-search-results");if(!(!i.tour||!o||!c||!m||!f)){if(h=Nt(i.tour,o.value,c.value),!o.value.trim()){m.textContent="Cmd/Ctrl+Shift+F",f.replaceChildren();return}m.textContent=`${h.length} result${h.length===1?"":"s"}`,f.replaceChildren(...h.map((p,E)=>{let S=document.createElement("button");S.type="button",S.className="tour-search-result",S.setAttribute("role","option"),S.dataset.tourSearchResult=String(E),S.title=`Open ${p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label}`;let $=document.createElement("span");$.className="tour-search-location",$.textContent=p.kind==="code"?`${p.label}:${p.lineNumber}`:p.label;let R=document.createElement("span");return R.className="tour-search-preview",R.textContent=p.preview.trim(),S.append($,R),S}))}}function L(o){let c=h[o];if(c){if(c.kind==="narrative"){oe(c.sceneIndex,c.stepIndex??0);return}je(c.fileIndex)&&window.requestAnimationFrame(()=>u({type:"revealSearchResult",sideIndex:c.sideIndex,lineNumber:c.lineNumber,startColumn:c.startColumn,endColumn:c.endColumn}))}}function C(){let o=document.getElementById("tour-shell"),c=document.getElementById("tour-sidebar-resizer"),m=document.getElementById("tour-sidebar-hide"),f=document.getElementById("tour-sidebar-show");!o||!c||!m||!f||(x(),m.addEventListener("click",()=>k(!0)),f.addEventListener("click",()=>k(!1)),c.addEventListener("pointerdown",p=>{p.preventDefault(),document.body.classList.add("is-resizing-tour-sidebar"),c.setPointerCapture?.(p.pointerId);let E=$=>b($.clientX),S=()=>{document.body.classList.remove("is-resizing-tour-sidebar"),window.removeEventListener("pointermove",E),window.removeEventListener("pointerup",S),window.removeEventListener("pointercancel",S),window.localStorage.setItem(t,String(i.tourSidebarWidth))};window.addEventListener("pointermove",E),window.addEventListener("pointerup",S),window.addEventListener("pointercancel",S)}),c.addEventListener("keydown",p=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(p.key))return;p.preventDefault();let E=i.tourSidebarWidth;p.key==="Home"?E=240:p.key==="End"?E=w():E+=p.key==="ArrowLeft"?-16:16,b(E),window.localStorage.setItem(t,String(i.tourSidebarWidth))}))}function I(){let o=Number.parseInt(window.localStorage.getItem(t)||"",10);return Number.isFinite(o)?Math.min(600,Math.max(240,o)):360}function w(){return Math.max(240,Math.min(600,Math.floor(window.innerWidth*.6)))}function b(o){i.tourSidebarWidth=Math.min(w(),Math.max(240,Math.round(o))),x(),window.dispatchEvent(new Event("resize"))}function x(){document.documentElement.style.setProperty("--tour-rail-width",`${i.tourSidebarWidth}px`);let o=document.getElementById("tour-sidebar-resizer");o?.setAttribute("aria-valuemax",String(w())),o?.setAttribute("aria-valuenow",String(i.tourSidebarWidth))}function k(o){i.tourSidebarHidden=o,document.body.classList.toggle("tour-sidebar-hidden",o);let c=document.getElementById("tour-sidebar-show");c&&(c.hidden=!o),window.dispatchEvent(new Event("resize"))}function N(){let o=document.getElementById("tour-narrative-resizer");o&&(B(),o.addEventListener("pointerdown",c=>{c.preventDefault(),document.body.classList.add("is-resizing-tour-narrative"),o.setPointerCapture?.(c.pointerId),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-start"));let m=document.getElementById("tour-narrative")?.getBoundingClientRect().top||0,f=E=>O(E.clientY-m),p=()=>{document.body.classList.remove("is-resizing-tour-narrative"),window.removeEventListener("pointermove",f),window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",p),window.dispatchEvent(new CustomEvent("bygone:workspace-resize-end")),ie()};window.addEventListener("pointermove",f),window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p)}),o.addEventListener("keydown",c=>{if(!["ArrowUp","ArrowDown","Home","End"].includes(c.key))return;c.preventDefault();let m=c.key==="Home"?180:c.key==="End"?M():i.tourNarrativeHeight+(c.key==="ArrowUp"?-16:16);O(m),ie()}),window.addEventListener("resize",()=>{i.tourNarrativeHeight=Math.min(M(),i.tourNarrativeHeight),B()}))}function _(){let o=Number.parseInt(window.localStorage.getItem(s)||"",10);if(Number.isFinite(o))return Math.max(180,o);let c=Number.parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--tour-narrative-height"),10);return Number.isFinite(c)?c:296}function M(){let o=document.getElementById("tour-narrative")?.getBoundingClientRect().top||0;return Math.max(180,window.innerHeight-o-180)}function O(o){i.tourNarrativeHeight=Math.min(M(),Math.max(180,Math.round(o))),B(),window.dispatchEvent(new Event("resize"))}function B(){document.documentElement.style.setProperty("--tour-narrative-height",`${i.tourNarrativeHeight}px`);let o=document.getElementById("tour-narrative-resizer");o?.setAttribute("aria-valuemax",String(M())),o?.setAttribute("aria-valuenow",String(i.tourNarrativeHeight))}function ie(){window.localStorage.setItem(s,String(i.tourNarrativeHeight))}async function fe(o){j("Loading change tour\u2026");try{let c=await fetch(o,{cache:"no-store"});if(!c.ok)throw new Error(`Manifest request failed (${c.status}).`);i.tour=It(await c.json()),i.mode="tour",document.body.classList.add("tour-mode"),Ft(),T();let m=new URLSearchParams(window.location.search),f=St(i.tour.scenes,m.get("scene"),m.get("step"));oe(f.sceneIndex,f.stepIndex),j("")}catch(c){j(`Could not load change tour: ${c instanceof Error?c.message:String(c)}`)}}function Ft(){let o=i.tour;if(!o)return;let c=document.getElementById("tour-shell"),m=document.getElementById("tour-title"),f=document.getElementById("tour-source"),p=document.getElementById("tour-range"),E=document.getElementById("tour-stats"),S=document.getElementById("tour-scenes"),$=document.getElementById("tour-scene-count"),R=document.getElementById("tour-files"),U=document.getElementById("tour-file-count"),y=document.getElementById("tour-commits"),W=document.getElementById("tour-commits-summary");if(!c||!m||!f||!p||!E||!S||!$||!R||!U||!y||!W)throw new Error("Presenter UI is incomplete.");c.hidden=!1,m.textContent=o.title,o.sourceUrl?(f.href=o.sourceUrl,f.hidden=!1):f.hidden=!0;let K=be(o.range.baseRef),F=be(o.range.headRef),z=o.range.headOid.slice(0,7);p.textContent=`${K} \u2192 ${F}${F===z?"":` \xB7 ${z}`}`,E.textContent=`${ce(o.summary.changedFiles,"file")} \xB7 +${o.summary.additions} \u2212${o.summary.deletions} \xB7 ${ce(o.summary.commitCount,"commit")}`,$.textContent=String(o.scenes.length),U.textContent=String(o.files.length),W.textContent=ce(o.summary.commitCount,"commit"),S.replaceChildren();let we=new Map(o.scenes.map(v=>[v.id,v]));for(let v of o.chapters){let G=document.createElement("h2");G.className="tour-chapter-title",G.textContent=v.title,S.append(G);for(let D of v.sceneIds){let P=we.get(D);if(!P)continue;let te=o.scenes.indexOf(P),q=document.createElement("button");q.type="button",q.className="tour-scene",q.dataset.sceneId=P.id,q.title=`Open scene: ${P.kind==="text-diff"?P.path:P.title}`,q.addEventListener("click",()=>oe(te));let Z=document.createElement("span");Z.className="tour-scene-number",Z.textContent=String(te+1).padStart(2,"0");let $e=document.createElement("span");$e.className="tour-scene-copy";for(let[jt,Kt]of[["tour-scene-title",P.title],["tour-scene-path",P.kind==="text-diff"?P.path:P.kind==="deconstructed-diff"?ce(P.steps.length,"explanation stage"):ae(P)?ce(P.steps.length,"code step"):"Discussion"],["tour-scene-note",P.takeaway]]){let Ae=document.createElement("span");Ae.className=jt,Ae.textContent=Kt,$e.append(Ae)}q.append(Z,$e),S.append(q)}}R.replaceChildren(...o.files.map((v,G)=>{let D=document.createElement("button");D.type="button",D.className=`tour-file${v.kind==="omitted"?" is-omitted":""}`,D.dataset.filePath=v.path,D.disabled=v.kind==="omitted",D.title=v.kind==="omitted"?`${v.path}: ${v.reason}`:`Open file: ${v.path}`,v.kind==="text-diff"&&D.addEventListener("click",()=>Ke(G));let P=document.createElement("span");P.className="tour-file-marker",P.textContent=v.kind==="omitted"?"\xD7":Pt(v.changeKind);let te=document.createElement("span");te.className="tour-file-copy";let q=document.createElement("span");q.className="tour-file-path",q.textContent=v.path;let Z=document.createElement("span");return Z.className="tour-file-meta",Z.textContent=v.kind==="omitted"?`Not rendered \xB7 ${v.reason}`:`${Ot(v.changeKind)} \xB7 +${v.additions} \u2212${v.deletions}`,te.append(q,Z),D.append(P,te),D})),y.replaceChildren(...o.commits.map(v=>{let G=document.createElement("li"),D=document.createElement("span");return D.className="tour-commit-oid",D.textContent=v.shortOid,G.append(D,document.createTextNode(v.summary)),G}))}function oe(o,c=0){let m=i.tour;if(!m||o<0||o>=m.scenes.length)return;let f=m.scenes[o];i.activeSceneIndex=o,i.activeStepIndex=ae(f)?Math.min(Math.max(c,0),Math.max(f.steps.length-1,0)):0,i.tourFocusFilePath=f.kind==="text-diff"?f.path:f.kind==="walkthrough"?f.steps[i.activeStepIndex]?.diff.path??null:pe(f)?f.steps[i.activeStepIndex]?.file??null:null;let p=Bt(m,o);document.querySelectorAll(".tour-scene").forEach(S=>{S.classList.toggle("is-active",S.dataset.sceneId===f.id)}),document.querySelector(`.tour-scene[data-scene-id="${f.id}"]`)?.scrollIntoView({block:"nearest"}),Gt(f,p);let E=new URLSearchParams(window.location.search);if(E.set("scene",f.id),ae(f)?E.set("step",f.steps[i.activeStepIndex].id):E.delete("step"),window.history.replaceState(null,"",`${window.location.pathname}?${E.toString()}`),f.kind==="discussion"){document.body.classList.add("tour-discussion"),Ne();return}if(document.body.classList.remove("tour-discussion"),f.kind==="walkthrough"){Ge(f);return}if(pe(f)){ze(f);return}ge(f,he(f.path))}function he(o){let c=i.tour;return!c||!o?[]:At(c,o,i.activeSceneIndex,i.activeStepIndex)}function Mt(o,c){let m=i.tour;return!m||!o?[]:Rt(m,o,i.activeSceneIndex,i.activeStepIndex,(f,p)=>$t(c?.[f]?.diffModel,p))}function Le(o){return`file::${o}`}function ge(o,c=[],m=Le(o.path)){if(!i.tour)return;i.activeTourFilePath=o.path,Ne();let p=Q(o.leftContent,o.rightContent),E=We(o,o.leftLabel,"base"),S=We(o,o.rightLabel,"head"),$=c.find(R=>R.active);u({type:"showDiff",file1:E,file2:S,comparisonId:`tour-${m}`,leftContent:o.leftContent,rightContent:o.rightContent,sourceInfo:{leftPath:o.path,rightPath:o.path},diffModel:p,history:null,fileNavigation:{canGoPrevious:!!se(-1),canGoNext:!!se(1)},editableSides:{left:!1,right:!1},comparisonSummary:`${o.path} \xB7 ${o.takeaway}`,initialChangeIndex:$?Ve(p,$.side,$.startLine):o.focusChangeIndex,tourAnnotations:c})}function We(o,c,m){let f=c.startsWith(o.path)?c.slice(o.path.length).trim():c.trim();return f?`${m} ${f}`:m}function Ge(o){let c=o.steps[i.activeStepIndex];c&&ge(c.diff,he(c.diff.path),Le(c.diff.path))}function ze(o){let c=o.steps[i.activeStepIndex];c&&qe(o,c.file,c)}function qe(o,c,m){let f=o.files.find(F=>F.path===c);if(!m||!f)return;i.activeTourFilePath=f.path,Ne();let p=f.panels.map((F,z)=>({id:`${o.id}-${f.path}-${F.id}`,label:F.label,path:F.path||f.path,content:F.content,savedContent:F.content,dirty:!1,editable:!1,stackId:Ht(o)[z].id})),E=p.slice(0,-1).map((F,z)=>({leftIndex:z,rightIndex:z+1,diffModel:Q(F.content,p[z+1].content)})),S=o.kind==="stacked-diff"?Mt(f.path,E):[],$=S.find(F=>F.active),R=$?.pairIndex??m.pairIndex,U=$?.side??m.side,y=$?.startLine??m.startLine,W=E[R]?.diffModel,K=W&&y?Ve(W,U,y):0;u({type:"showMultiDiff",panels:p,pairs:E,activePanelId:p[R+(U==="right"?1:0)]?.id,activePairIndex:R,initialChangeIndex:K,revealFirstChangeInEachPanel:o.kind==="deconstructed-diff",history:null,fileNavigation:{canGoPrevious:!!se(-1),canGoNext:!!se(1)},mutationEnabled:!1,comparisonSummary:o.kind==="deconstructed-diff"?`${o.stageLabel} \xB7 ${f.path} \xB7 ${be(o.realRange.baseRef)} \u2192 ${be(o.realRange.targetRef)}`:`${f.path} \xB7 ${o.takeaway}`,tourAnnotations:S})}function ke(o){let c=i.tour;return!c||o!==-1&&o!==1?null:Tt(c.scenes,{sceneIndex:i.activeSceneIndex,stepIndex:i.activeStepIndex},o)}function me(o){let c=ke(o);return c?(oe(c.sceneIndex,c.stepIndex),!0):!1}function se(o){let c=i.tour;return!c||o!==-1&&o!==1?null:Ct(c.files,i.activeTourFilePath,o)}function Dt(o){let c=se(o);return c?Ke(c.fileIndex):!1}function je(o){let c=i.tour?.files[o];return!c||c.kind!=="text-diff"?!1:(ge(c,he(c.path),Le(c.path)),!0)}function Ke(o){let c=i.tour?.files[o];if(c?.kind==="text-diff"&&i.tour){let m=Lt(i.tour.scenes,{sceneIndex:i.activeSceneIndex,stepIndex:i.activeStepIndex},c.path);if(m){let f=i.tour.scenes[m.sceneIndex],p=pe(f)?f.steps[m.stepIndex]:null;if(p)return qe(f,c.path,p),!0}}return je(o)}function _t(){let o=i.tour?.scenes[i.activeSceneIndex];if(!o||!i.tourFocusFilePath)return!1;if(o.kind==="walkthrough")Ge(o);else if(pe(o))ze(o);else if(o.kind==="text-diff")ge(o,he(o.path));else return!1;return!0}function Ne(){document.querySelectorAll(".tour-file").forEach(c=>{c.classList.toggle("is-active",c.dataset.filePath===i.activeTourFilePath),c.classList.toggle("is-tour-focus",c.dataset.filePath===i.tourFocusFilePath)}),document.querySelector(".tour-file.is-active")?.scrollIntoView({block:"nearest"});let o=document.getElementById("tour-return-focus");o&&(o.hidden=!i.tourFocusFilePath||i.activeTourFilePath===i.tourFocusFilePath)}function ae(o){return o.kind==="walkthrough"||o.kind==="stacked-diff"||o.kind==="deconstructed-diff"}function pe(o){return o.kind==="stacked-diff"||o.kind==="deconstructed-diff"}function Ht(o){return o.kind==="deconstructed-diff"?o.panels:o.stack}function Pt(o){return{added:"+",deleted:"\u2212",renamed:"\u2192",modified:"\u2022"}[o]||"\u2022"}function Ot(o){return`${o.charAt(0).toUpperCase()}${o.slice(1)}`}function Bt(o,c){let m=o.scenes[c],f=o.chapters.findIndex($=>$.sceneIds.includes(m.id)),p=f>=0?o.chapters[f]:null,E=p?p.sceneIds.indexOf(m.id)+1:c+1,S=p?p.sceneIds.length:o.scenes.length;return{chapter:p,chapterIndex:f,chapterNumber:f>=0?f+1:c+1,sceneInChapter:E,scenesInChapter:S}}function Ut(o,c,m){let f=[`Ch ${o.chapterNumber}`,`Scene ${o.sceneInChapter}/${o.scenesInChapter}`];return ae(c)&&f.push(`Step ${m+1}/${c.steps.length}`),f.join(" \xB7 ")}function Ve(o,c,m){let p=(c==="left"?o.leftLines:o.rightLines).findIndex(y=>y.lineNumber===m);if(p<0)return 0;let E=c==="left"?"leftStart":"rightStart",S=c==="left"?"leftEnd":"rightEnd",$=o.blocks.findIndex(y=>p>=y[E]&&p<y[S]);if($>=0)return $;let R=0,U=Number.POSITIVE_INFINITY;return o.blocks.forEach((y,W)=>{let K=Math.min(Math.abs(p-y[E]),Math.abs(p-y[S]));K<U&&(R=W,U=K)}),R}function be(o){return/^[0-9a-f]{40}$/i.test(o)?o.slice(0,7):o}function ce(o,c){return`${o} ${o===1?c:`${c}s`}`}function Wt(o){return o instanceof Element&&!!o.closest('a, button, input, select, summary, textarea, [contenteditable="true"], [role="textbox"], .monaco-editor')}function Gt(o,c){let m=document.getElementById("tour-narrative"),f=document.getElementById("tour-breadcrumb"),p=document.getElementById("tour-narrative-chapter"),E=document.getElementById("tour-narrative-title"),S=document.getElementById("tour-narrative-summary"),$=document.getElementById("tour-narrative-bullets"),R=document.getElementById("tour-narrative-tags"),U=document.getElementById("tour-narrative-takeaway"),y=document.getElementById("tour-step"),W=document.getElementById("tour-step-title"),K=document.getElementById("tour-step-body"),F=document.getElementById("tour-connection"),z=document.getElementById("tour-previous"),we=document.getElementById("tour-next");if(!m||!f||!p||!E||!S||!$||!R||!U||!y||!W||!K||!F||!z||!we)throw new Error("Tour narrative UI is incomplete.");m.hidden=!1,f.textContent=Ut(c,o,i.activeStepIndex),p.textContent=o.kind==="deconstructed-diff"?`${c.chapter?.title||"Change tour"} \xB7 ${o.stageLabel}`:c.chapter?.title||"Change tour",E.textContent=o.title,S.textContent=o.summary,$.replaceChildren(...o.bullets.map(G=>{let D=document.createElement("li");return D.textContent=G,D})),R.replaceChildren(...o.tags.map(G=>{let D=document.createElement("span");return D.textContent=G,D})),U.textContent=o.takeaway;let v=ae(o)?o.steps[i.activeStepIndex]:null;y.hidden=!v,v?(W.textContent=o.kind==="deconstructed-diff"?`Stage ${i.activeStepIndex+1}: ${v.title}`:v.title,K.textContent=v.body,"connection"in v&&v.connection?(F.hidden=!1,F.textContent=`${v.connection.from.path} \u2192 ${v.connection.to.path} \xB7 ${v.connection.label}`):(F.hidden=!0,F.textContent="")):(F.hidden=!0,F.textContent=""),z.disabled=!ke(-1),we.disabled=!ke(1)}function Xe(){let o=yt();i.mode="diff",i.comparisonId+=1,i.left={name:o.leftFileName,content:o.leftContent},i.right={name:o.rightFileName,content:o.rightContent},j("Loaded sample diff."),u({type:"showDiff",file1:i.left.name,file2:i.right.name,comparisonId:`web-${i.comparisonId}`,leftContent:i.left.content,rightContent:i.right.content,diffModel:Q(i.left.content,i.right.content),history:null})}async function zt(o){let[c,m]=o,[f,p]=await Promise.all([c.text(),m.text()]);i.mode="diff",i.comparisonId+=1,i.left={name:c.name,content:f},i.right={name:m.name,content:p},j(`Loaded ${c.name} and ${m.name}.`),u({type:"showDiff",file1:c.name,file2:m.name,comparisonId:`web-${i.comparisonId}`,leftContent:f,rightContent:p,diffModel:Q(f,p),history:null})}async function qt(o){let c=await Promise.all(o.map(async(m,f)=>{let p=await m.text();return{id:`web-panel-${f}`,label:m.name,content:p,savedContent:p,dirty:!1,editable:!0}}));i.mode="multi-diff",j(`Loaded ${c.length}-panel diff for ${c.map(m=>m.label).join(", ")}.`),u({type:"showMultiDiff",panels:c,pairs:c.slice(0,-1).map((m,f)=>({leftIndex:f,rightIndex:f+1,diffModel:Q(m.content,c[f+1].content)}))})}function j(o){let c=document.getElementById("web-status");c&&(c.textContent=o)}})();})();
151
151
  //# sourceMappingURL=web-host.js.map