@davmash/bygone 0.5.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -2
- package/README.md +64 -22
- package/bin/bygone.js +72 -38
- package/cli/commandSpec.js +178 -0
- package/cli/completions.js +321 -0
- package/cli/present.js +166 -0
- package/cli/tour.js +189 -0
- package/cli/tourFile.js +26 -0
- package/completions/_bygone +131 -0
- package/completions/bygone +83 -0
- package/completions/bygone.fish +34 -0
- package/docs/change-explanation-plan.md +358 -0
- package/docs/change-tour-format.md +62 -0
- package/docs/generating-change-tours.md +75 -0
- package/docs/releasing.md +342 -0
- package/docs/walkthrough.md +103 -0
- package/examples/bygone-history.bygone.yaml +80 -0
- package/media/editor.worker.js +26 -14250
- package/media/icon.png +0 -0
- package/media/webview.css +1 -9818
- package/media/webview.js +358 -132939
- package/out/changeTour.js +1901 -0
- package/out/standalone-main.js +14698 -8507
- package/out/standalone-preload.js +5 -4
- package/out/tourCoverage.js +1792 -0
- package/package.json +10 -3
- package/schemas/change-tour-source.schema.json +287 -0
- package/standalone/index.html +23 -6
- package/web/index.html +266 -0
- package/web/presenter.css +725 -0
- package/web/web-host.js +149 -0
package/web/web-host.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
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,`
|
|
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
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A simple utility class for file operations
|
|
10
|
+
*/
|
|
11
|
+
class FileProcessor {
|
|
12
|
+
constructor(directory = './') {
|
|
13
|
+
this.directory = directory;
|
|
14
|
+
this.files = [];
|
|
15
|
+
this.processedCount = 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Method to read files from directory
|
|
19
|
+
readFiles() {
|
|
20
|
+
try {
|
|
21
|
+
const files = fs.readdirSync(this.directory);
|
|
22
|
+
this.files = files.filter(file => file.endsWith('.js'));
|
|
23
|
+
console.log(\`Found \${this.files.length} JavaScript files\`);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Error reading directory:', error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Process each file
|
|
30
|
+
processFiles() {
|
|
31
|
+
this.files.forEach(file => {
|
|
32
|
+
try {
|
|
33
|
+
const filePath = path.join(this.directory, file);
|
|
34
|
+
fs.readFileSync(filePath, 'utf8');
|
|
35
|
+
this.processedCount++;
|
|
36
|
+
console.log(\`Processed: \${file}\`);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(\`Error processing \${file}:\`, error);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Get processing results
|
|
44
|
+
getResults() {
|
|
45
|
+
return {
|
|
46
|
+
totalFiles: this.files.length,
|
|
47
|
+
processed: this.processedCount,
|
|
48
|
+
directory: this.directory
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Usage example
|
|
54
|
+
const processor = new FileProcessor('./src');
|
|
55
|
+
processor.readFiles();
|
|
56
|
+
processor.processFiles();
|
|
57
|
+
const results = processor.getResults();
|
|
58
|
+
console.log('Results:', results);
|
|
59
|
+
|
|
60
|
+
module.exports = FileProcessor;
|
|
61
|
+
`,rightContent:`// Test File 2 - Modified JavaScript Code
|
|
62
|
+
const fs = require('fs');
|
|
63
|
+
const path = require('path');
|
|
64
|
+
const util = require('util');
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* An enhanced utility class for file operations
|
|
68
|
+
* Added more features and error handling
|
|
69
|
+
*/
|
|
70
|
+
class FileProcessor {
|
|
71
|
+
constructor(directory = './', options = {}) {
|
|
72
|
+
this.directory = directory;
|
|
73
|
+
this.files = [];
|
|
74
|
+
this.processedCount = 0;
|
|
75
|
+
this.options = { recursive: false, ...options };
|
|
76
|
+
this.startTime = Date.now();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Enhanced method to read files from directory
|
|
80
|
+
readFiles() {
|
|
81
|
+
try {
|
|
82
|
+
const items = fs.readdirSync(this.directory);
|
|
83
|
+
this.files = items.filter(item => {
|
|
84
|
+
const itemPath = path.join(this.directory, item);
|
|
85
|
+
const stat = fs.statSync(itemPath);
|
|
86
|
+
return stat.isFile() && item.endsWith('.js');
|
|
87
|
+
});
|
|
88
|
+
console.log(\`Found \${this.files.length} JavaScript files in \${this.directory}\`);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw new Error(\`Failed to read directory \${this.directory}: \${error.message}\`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Enhanced file processing with async support
|
|
95
|
+
async processFiles() {
|
|
96
|
+
const promises = this.files.map(async (file) => {
|
|
97
|
+
try {
|
|
98
|
+
const filePath = path.join(this.directory, file);
|
|
99
|
+
const content = await util.promisify(fs.readFile)(filePath, 'utf8');
|
|
100
|
+
this.processedCount++;
|
|
101
|
+
console.log(\`Successfully processed: \${file}\`);
|
|
102
|
+
return { file, content };
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error(\`Error processing \${file}:\`, error);
|
|
105
|
+
return { file, error: error.message };
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const results = await Promise.all(promises);
|
|
110
|
+
return results.filter(result => !result.error);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get enhanced processing results
|
|
114
|
+
getResults() {
|
|
115
|
+
const duration = Date.now() - this.startTime;
|
|
116
|
+
return {
|
|
117
|
+
totalFiles: this.files.length,
|
|
118
|
+
processed: this.processedCount,
|
|
119
|
+
directory: this.directory,
|
|
120
|
+
duration: \`\${duration}ms\`,
|
|
121
|
+
options: this.options
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// New method to clean up files
|
|
126
|
+
cleanUp() {
|
|
127
|
+
console.log('Cleaning up resources...');
|
|
128
|
+
this.files = [];
|
|
129
|
+
this.processedCount = 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Enhanced usage example
|
|
134
|
+
async function main() {
|
|
135
|
+
const processor = new FileProcessor('./src', { recursive: true });
|
|
136
|
+
processor.readFiles();
|
|
137
|
+
await processor.processFiles();
|
|
138
|
+
const results = processor.getResults();
|
|
139
|
+
console.log('Processing complete:', results);
|
|
140
|
+
processor.cleanUp();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (require.main === module) {
|
|
144
|
+
main().catch(console.error);
|
|
145
|
+
}
|
|
146
|
+
|
|
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)}})();})();
|
|
149
|
+
//# sourceMappingURL=web-host.js.map
|