@davmash/bygone 0.7.0 → 0.8.0

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