,
+ because they automatically adapt to theme changes.
+
+ See:
+ List of available CSS variables in Obsidian
+
+ `,new V.Setting(this.containerEl).setName("Ignore whitespace and newlines in changes").addToggle(a=>{a.setValue(this.settings.lineAuthor.ignoreWhitespace),a.onChange(s=>this.lineAuthorSettingHandler("ignoreWhitespace",s))}).descEl.innerHTML=`
+ Whitespace and newlines are interpreted as
+ part of the document and in changes
+ by default (hence not ignored).
+ This makes the last line being shown as 'changed'
+ when a new subsequent line is added,
+ even if the previously last line's text is the same.
+
+ If you don't care about purely-whitespace changes
+ (e.g. list nesting / quote indentation changes),
+ then activating this will provide more meaningful change detection.
+ `}}createColorSetting(r){let n=new V.Setting(this.containerEl).setName("").addText(i=>{let a=i0(r,this.settings.lineAuthor),s=i0(r,ar.lineAuthor);i.setPlaceholder(Gg(s)),i.setValue(Gg(a)),i.onChange(async o=>{let c=lT(o);if(c!==void 0){let l=r==="newest"?"colorNew":"colorOld";await this.lineAuthorSettingHandler(l,c)}this.refreshColorSettingsDesc(r,c)})});this.lineAuthorColorSettings.set(r,n),this.refreshColorSettingsName(r),this.refreshColorSettingsDesc(r,i0(r,this.settings.lineAuthor))}refreshColorSettingsName(r){let n=this.lineAuthorColorSettings.get(r);if(n){let i=r==="oldest"?`oldest (${this.settings.lineAuthor.coloringMaxAge} or older)`:"newest";n.nameEl.innerText=`Color for ${i} commits`}}refreshColorSettingsDesc(r,n){let i=this.lineAuthorColorSettings.get(r);i&&(i.descEl.innerHTML=this.colorSettingPreviewDescHtml(r,this.settings.lineAuthor,n!==void 0))}colorSettingPreviewDescHtml(r,n,i){let a=i?a0(r,n):"rgba(127,127,127,0.3)",s=V.moment.unix(V.moment.now()/1e3).format("YYYY-MM-DD"),o=i?`abcdef Author Name ${s}`:"invalid color";return`Supports 'rgb(r,g,b)', 'hsl(h,s,l)', hex (#) and
+ named colors (e.g. 'black', 'purple'). Color preview: ${`
${o}
`}`}previewCustomDateTimeDescriptionHtml(r){let n=(0,V.moment)().format(r);return`Format string to display the authoring date.Currently: ${n}`}previewOldestAgeDescriptionHtml(r){let n=Vf(r);return[`The oldest age in the line author coloring. Everything older will have the same color.
+ Smallest valid age is "1d". Currently: ${n!==void 0?`${n.asDays()} days`:"invalid!"}`,n]}};function i0(e,t){return e==="oldest"?t.colorOld:t.colorNew}function Vf(e){let t=V.moment.duration("P"+e.toUpperCase());return t.isValid()&&t.asDays()&&t.asDays()>=1?t:void 0}function PT(e,t,r){if(!(e===void 0||t===void 0||r===void 0))return`head${e}-obj${t}-path${r}`}var RT=Wf.Annotation.define();function MT(e,t,r){return r.update({annotations:RT.of({key:e,la:t,lineOffsetsFromUnsavedChanges:new Map})})}function tB(e){return e.annotation(RT)}var qs=Wf.StateField.define({create:e=>{},update:(e,t)=>{var r;return(r=tB(t))!=null?r:rB(t,e)},compare:(e,t)=>(e==null?void 0:e.key)===(t==null?void 0:t.key)});function qf(e){var a;let t=CT.sha256.create();if(!e)return t;let{la:r,key:n,lineOffsetsFromUnsavedChanges:i}=e;t.update(r==="untracked"?"t":"f"),t.update(n);for(let[s,o]of(a=i.entries())!=null?a:[])t.update([s,o]);return t}var Dr={get:void 0,save:void 0};function OT(e,t){Dr.get=e,Dr.save=t}function Yf(e){var t,r;return(r=(t=Vf(e.coloringMaxAge))==null?void 0:t.asDays())!=null?r:Vf(ar.lineAuthor.coloringMaxAge).asDays()}function rB(e,t){if(t)return e.changes.empty||e.changes.iterChanges((r,n,i,a)=>{var p;let s=e.startState.doc,{newDoc:o}=e,c=s.lineAt(r).number,l=s.lineAt(n).number,u=o.lineAt(i).number,f=o.lineAt(a).number,d=l-c+1,h=f-u+1;for(let m=u;m<=f;m++){let v=(p=t.lineOffsetsFromUnsavedChanges.get(m))!=null?p:0,y=f===m,b=h-d;y&&(v+=b),t.lineOffsetsFromUnsavedChanges.set(m,v)}}),t}var s0=class{constructor(t){this.state=t;this.subscribeMe()}notifyLineAuthoring(t,r){if(this.view===void 0){console.warn(`Git: View is not defined for editor cache key. Unforeseen situation. id: ${t}`);return}let n=this.view.state,i=MT(t,r,n);this.view.dispatch(i)}updateToNewState(t){let r=this.lastSeenPath&&this.filepath!=this.lastSeenPath;return this.state=t,r&&(this.unsubscribeMe(this.lastSeenPath),this.subscribeMe()),this}removeIfStale(){this.view.destroyed&&this.unsubscribeMe(this.lastSeenPath)}subscribeMe(){this.filepath!==void 0&&(Ws.ifFilepathDefinedTransformSubscribers(this.filepath,t=>t.add(this)),this.lastSeenPath=this.filepath)}unsubscribeMe(t){Ws.ifFilepathDefinedTransformSubscribers(t,r=>r.delete(this))}get filepath(){var t,r;return(r=(t=this.state.field(Xf.editorInfoField))==null?void 0:t.file)==null?void 0:r.path}get view(){return this.state.field(Xf.editorEditorField)}},FT=IT.StateField.define({create:e=>new s0(e),update:(e,t)=>e.updateToNewState(t.state),compare:(e,t)=>e===t});g();function $T(){Ys=void 0,o0=[],Zf=0,Jf.clear(),Qf.clear(),Xs.clear()}var Ys,Kf=()=>Ys;function LT(e,t){var i;let r=t.length;if(r<((i=Ys==null?void 0:Ys.length)!=null?i:0))return;Ys={gutter:e,length:r,text:t};let n=Dr.get();r!==n.gutterSpacingFallbackLength&&(n.gutterSpacingFallbackLength=r,Dr.save(n))}var o0=[],nB=15,Zf=0;function DT(e){o0[Zf]=e,Zf=(Zf+1)%nB}function NT(){return uT(o0)}var Jf=new Map,Qf=new Map,Xs=new Set;g();var KT=require("@codemirror/state"),JT=require("@codemirror/view");g();var f0=require("@codemirror/view"),qT=ze(Xg()),rd=require("obsidian");g();g();var ed={x:-10,y:-10};function jT(){ed.x===-10&&window.addEventListener("mousedown",e=>{ed.x=e.clientX,ed.y=e.clientY})}function BT(){for(let e of Xs)if(iB(e,ed))return e}function iB(e,t){let{x:r,y:n,width:i,height:a}=e.getBoundingClientRect();return r<=t.x&&t.x<=r+i&&n<=t.y&&t.y<=n+a}g();var Yl={};var HT="data-commit";function UT(e,t,r){if(t.hasFocus())return;let n=BT();if(!n)return;let i=sB(n);i&&(!i.isZeroCommit&&!i.isWaitingGutter&&aB(i,e),l0("showCommitHash",e),l0("authorDisplay",e),l0("dateTimeFormatOptions",e))}function aB(e,t){t.addItem(r=>r.setTitle("Copy commit hash").setIcon("copy").setSection("obs-git-line-author-copy").onClick(n=>navigator.clipboard.writeText(e.hash)))}function l0(e,t){var c,l;let r,n,i=Yl.plugin.settings.lineAuthor,a=i[e],s=typeof a=="boolean"?a:a!=="hide",o=ar.lineAuthor[e];if(e==="showCommitHash")r="Show commit hash",n=a;else if(e==="authorDisplay"){let u=(c=i.lastShownAuthorDisplay)!=null?c:o;r="Show author "+(s?a:u),n=s?"hide":u}else if(e==="dateTimeFormatOptions"){let u=(l=i.lastShownDateTimeFormatOptions)!=null?l:o;r="Show "+(s?a:u),r+=r.contains("date")?"":" date",n=s?"hide":u}else Oi(e);t.addItem(u=>u.setTitle(r).setSection("obs-git-line-author-configure").setChecked(s).onClick(f=>{var d,h;return(h=(d=Yl.plugin)==null?void 0:d.settingsTab)==null?void 0:h.lineAuthorSettingHandler(e,n)}))}function GT(e,t,r){r.setAttr(HT,JSON.stringify({hash:e.hash,isZeroCommit:e.isZeroCommit,isWaitingGutter:t}))}function sB(e){let t=e.getAttr(HT);return t?JSON.parse(t):void 0}g();function a0(e,t){return e==="oldest"?td(0,!1,t).color:td(void 0,!0,t).color}function td(e,t,r){let n=Yf(r),i=Date.now()/1e3,a=e!=null?e:0,o=(t?0:i-a)/60/60/24,c=Math.pow(Math.clamp(o/n,0,1),1/2.3),l=oB(),u=r.colorNew,f=r.colorOld,d=l?.4:1,h=c0(u.r,f.r,c)*d,p=c0(u.g,f.g,c)*d,m=c0(u.b,f.b,c)*d;return{color:`rgba(${h},${p},${m},${l?.75:.25})`,daysSinceCommit:o}}function c0(e,t,r){return e+(t-e)*r}function oB(){var e;return((e=window.app)==null?void 0:e.getTheme())==="obsidian"}function zT(e){document.body.style.setProperty("--obs-git-gutter-text",e.textColorCss)}g();function VT(e,t,r){let n;for(let i=t;i<=r;i++){let a=e.hashPerLine[i],s=e.commits.get(a);(!n||s.isZeroCommit||lB(s,n))&&(n=s)}return n}function lB(e,t){var i,a,s,o;let r=(a=(i=e.author)==null?void 0:i.epochSeconds)!=null?a:0,n=(o=(s=t.author)==null?void 0:s.epochSeconds)!=null?o:0;return r>n}var WT="-",cB="+",uB=3,fB="*",dB=/\S/g,hB="%",Zs=class e extends f0.GutterMarker{constructor(r){super();this.text=r}eq(r){return r instanceof e&&this.text===r.text}toDOM(){return document.createTextNode(this.text)}destroy(r){document.body.contains(r)||r.remove()}},u0=class extends f0.GutterMarker{constructor(r,n,i,a,s,o){super();this.lineAuthoring=r;this.startLine=n;this.endLine=i;this.key=a;this.settings=s;this.options=o;this.point=!1;this.elementClass="obs-git-blame-gutter"}eq(r){return this.key===(r==null?void 0:r.key)&&this.startLine===(r==null?void 0:r.startLine)&&this.endLine===(r==null?void 0:r.endLine)&&(this==null?void 0:this.options)===(r==null?void 0:r.options)}toDOM(){var r;return this.precomputedDomProvider=(r=this.precomputedDomProvider)!=null?r:this.computeDom(),this.precomputedDomProvider()}destroy(r){document.body.contains(r)||(r.remove(),Xs.delete(r))}computeDom(){let r=VT(this.lineAuthoring,this.startLine,this.endLine),n=r.isZeroCommit?"":this.renderNonZeroCommit(r);return!r.isZeroCommit&&this.options!=="waiting-for-result"?LT(this,n):n=this.adaptTextForFakeCommit(r,n,this.options),this.createHtmlNode(r,n,this.options==="waiting-for-result")}createHtmlNode(r,n,i){var l;let a=window.createDiv();a.innerText=n;let{color:s,daysSinceCommit:o}=td((l=r==null?void 0:r.author)==null?void 0:l.epochSeconds,r==null?void 0:r.isZeroCommit,this.settings);a.style.backgroundColor=s,GT(r,i,a);function c(){let u=a.cloneNode(!0);return Xs.add(u),i||DT(o),u}return c}renderNonZeroCommit(r){let n=this.settings.showCommitHash?this.renderHash(r):"",i=this.settings.authorDisplay==="hide"?"":`${this.renderAuthorName(r,this.settings.authorDisplay)}`,a=this.settings.dateTimeFormatOptions==="hide"?"":`${this.renderAuthoringDate(r,this.settings.dateTimeFormatOptions,this.settings.dateTimeFormatCustomString,this.settings.dateTimeTimezone)}`;return[n,i,a].filter(o=>o.length>=1).join(" ")}renderHash(r){return r.hash.substring(0,6)}renderAuthorName(r,n){var o,c,l,u;let i=(c=(o=r==null?void 0:r.author)==null?void 0:o.name)!=null?c:"",a=i.split(" ").filter(f=>f.length>=1),s;switch(n){case"initials":s=a.map(f=>f[0].toUpperCase()).join("");break;case"first name":s=(l=a.first())!=null?l:WT;break;case"last name":s=(u=a.last())!=null?u:WT;break;case"full":s=i;break;default:return Oi(n)}return fT(r==null?void 0:r.author,r==null?void 0:r.committer)||(s=s+fB),s}renderAuthoringDate(r,n,i,a){var l;let s="?";if(((l=r==null?void 0:r.author)==null?void 0:l.epochSeconds)===void 0)return s;let o;switch(n){case"date":o=Gu;break;case"datetime":o=bm;break;case"custom":o=i;break;case"natural language":o=u=>{let f=u.diff((0,rd.moment)());return rd.moment.duration(f).humanize(!0)};break;default:return Oi(n)}let c=rd.moment.unix(r.author.epochSeconds);switch(a){case"viewer-local":break;case"author-local":c=c.utcOffset(r.author.tz),typeof o=="string"&&(o+=" Z");break;case"utc0000":c=c.utc(),typeof o=="string"&&(o+="[Z]");break;default:return Oi(a)}return typeof o=="string"?c.format(o):o(c)}adaptTextForFakeCommit(r,n,i){var c,l,u,f;let a=(l=(c=Kf())==null?void 0:c.text)!=null?l:n,s=i!=="waiting-for-result"&&r.isZeroCommit?cB:hB;n=a.replace(dB,s);let o=(f=(u=Dr.get())==null?void 0:u.gutterSpacingFallbackLength)!=null?f:n.length;if(n=dT(n,o,s),i!=="waiting-for-result"&&r.isZeroCommit){let d=Math.min(o,uB);n=hT(n,o-d)}return n}};function xa(e,t,r,n,i,a){let s=qT.sha256.create();s.update(Object.values(i).join(",")),s.update(`s${t}-e${r}-k${n}-o${a}`);let o=s.hex(),c=Jf.get(o);if(c)return c;let l=new u0(e,t,r,n,i,a);return Jf.set(o,l),l}g();var YT=require("obsidian");function d0(){var t,r;let e=(r=(t=Dr.get())==null?void 0:t.gutterSpacingFallbackLength)!=null?r:ar.lineAuthor.gutterSpacingFallbackLength;return new Zs(Array(e).fill("-").join(""))}function h0(e){let{lineAuthoring:t,ageForInitialRender:r}=pB(e);return xa(t,1,1,"initialGutter"+r,e,"waiting-for-result")}function pB(e){var a;let t=(a=NT())!=null?a:Yf(e)*.25,r=(0,YT.moment)().add(-t,"days"),n={name:"",epochSeconds:cT(r),tz:"+0000"},i={hash:"waiting-for-result",author:n,committer:n,isZeroCommit:!1};return{lineAuthoring:{hashPerLine:[void 0,"waiting-for-result"],commits:new Map([["waiting-for-result",i]])},ageForInitialRender:t}}g();function XT(e,t){return xa({hashPerLine:[void 0,"000000"],commits:new Map([["000000",wT]])},1,1,e,t)}var p0=new Zs(""),QT=(0,JT.gutter)({class:"line-author-gutter-container",markers(e){let t=e.state.field(qs,!1);return mB(e,t)},lineMarkerChange(e){let t=qf(e.state.field(qs));return qf(e.startState.field(qs))!==t},renderEmptyElements:!0,initialSpacer:e=>(ZT(e),d0()),updateSpacer:(e,t)=>{var r,n;return ZT(t.view),(n=(r=Kf())==null?void 0:r.gutter)!=null?n:d0()}});function mB(e,t){let r=qf(t),n=e.state.doc,i=new Map;for(let u=1;u<=n.lines;u++){let f=n.line(u).from,d=e.lineBlockAt(f).to;i.set(u,[f,d]),r.update([f,d,0])}let a=Dr.get();r.update("s"+Object.values(Dr).join(","));let s=r.hex(),o=Qf.get(s);if(o)return o;let{result:c,allowCache:l}=gB(n,i,a,t);return l&&Qf.set(s,c),c}function gB(e,t,r,n){let i=!0,a=e.lines,s=[];function o(f,d,h){return s.push(h.range(f,d))}let c=vB(a,n),l=e.length===0,u=e.iterLines(a,a+1).next().value==="";for(let f=1;f<=a;f++){let[d,h]=t.get(f),p=e.lineAt(h).number;if(l){o(d,h,p0);continue}if(f===a&&u){o(d,h,p0);continue}if(n===void 0){o(d,h,h0(r)),i=!1;continue}let{key:m,la:v}=n;if(v==="untracked"){o(d,h,XT(v,r));continue}let y=v.hashPerLine.length-1,b=c[f],x=c[p];if(x&&x>y&&o(d,h,p0),b!==void 0&&zg(1,b,y)&&x!==void 0&&zg(1,x,y)){o(d,h,xa(v,b,x,m,r));continue}if(y<1){o(d,h,h0(r)),i=!1;continue}let E=Math.clamp(b!=null?b:f,1,y),_=Math.clamp(x!=null?x:p,1,y);o(d,h,xa(v,E,_,m+"computing",r,"waiting-for-result"))}return{result:KT.RangeSet.of(s,!0),allowCache:i}}function vB(e,t){if(!(t!=null&&t.lineOffsetsFromUnsavedChanges))return Array.from(new Array(e+1),i=>i);let r=[void 0],n=0;for(let i=1;i<=e;i++){let a=t.lineOffsetsFromUnsavedChanges.get(i);n+=a!=null?a:0,r[i]=a===void 0?i-n:void 0}return r}function ZT(e){e.dom.querySelectorAll(".cm-gutters").forEach(r=>{r!=null&&r.style&&(r.style.marginLeft||(r.style.marginLeft="unset"))})}var nd=class{constructor(t){this.plugin=t;this.lineAuthorings=new Map}async trackChanged(t){return this.trackChangedHelper(t).catch(r=>(console.warn("Git: Error in trackChanged."+r),Promise.reject(r)))}async trackChangedHelper(t){if(t){if(t.path===void 0){console.warn("Git: Attempted to track change of undefined filepath. Unforeseen situation.");return}return this.computeLineAuthorInfo(t.path)}}destroy(){this.lineAuthorings.clear(),Ws.clear(),$T()}async computeLineAuthorInfo(t){let r=this.plugin.lineAuthoringFeature.isAvailableOnCurrentPlatform().gitManager,n=await r.submoduleAwareHeadRevisonInContainingDirectory(t),i=await r.hashObject(t),a=PT(n,i,t);if(a!==void 0){if(!this.lineAuthorings.has(a)){let s=await r.blame(t,this.plugin.settings.lineAuthor.followMovement,this.plugin.settings.lineAuthor.ignoreWhitespace);this.lineAuthorings.set(a,s)}this.notifyComputationResultToSubscribers(t,a)}}notifyComputationResultToSubscribers(t,r){Ws.ifFilepathDefinedTransformSubscribers(t,n=>n.forEach(i=>i.notifyLineAuthoring(r,this.lineAuthorings.get(r))))}},tC=eC.Prec.high([FT,qs,QT]);var id=class{constructor(t){this.plg=t;this.codeMirrorExtensions=[];this.handleWorkspaceLeaf=t=>{if(!this.lineAuthorInfoProvider){console.warn("Git: undefined lineAuthorInfoProvider. Unexpected situation.");return}let r=t==null?void 0:t.view;!(r instanceof Sa.MarkdownView)||r.file==null||(r==null?void 0:r.allowNoFile)===!0||this.lineAuthorInfoProvider.trackChanged(r.file).catch(console.error)}}onLoadPlugin(){this.plg.registerEditorExtension(this.codeMirrorExtensions),OT(()=>this.plg.settings.lineAuthor,t=>{this.plg.settings.lineAuthor=t,this.plg.saveSettings()})}conditionallyActivateBySettings(){this.plg.settings.lineAuthor.show&&this.activateFeature()}activateFeature(){try{if(!this.isAvailableOnCurrentPlatform().available)return;zT(this.plg.settings.lineAuthor),this.lineAuthorInfoProvider=new nd(this.plg),this.createEventHandlers(),this.activateCodeMirrorExtensions(),console.log(this.plg.manifest.name+": Enabled line authoring.")}catch(t){console.warn("Git: Error while loading line authoring feature.",t),this.deactivateFeature()}}deactivateFeature(){var t;this.destroyEventHandlers(),this.deactivateCodeMirrorExtensions(),(t=this.lineAuthorInfoProvider)==null||t.destroy(),this.lineAuthorInfoProvider=void 0,console.log(this.plg.manifest.name+": Disabled line authoring.")}isAvailableOnCurrentPlatform(){return{available:this.plg.useSimpleGit&&Sa.Platform.isDesktopApp,gitManager:this.plg.gitManager instanceof Te?this.plg.gitManager:void 0}}refreshLineAuthorViews(){this.plg.settings.lineAuthor.show&&(this.deactivateFeature(),this.activateFeature())}activateCodeMirrorExtensions(){this.codeMirrorExtensions.push(tC),this.plg.app.workspace.updateOptions(),this.plg.app.workspace.iterateAllLeaves(this.handleWorkspaceLeaf)}deactivateCodeMirrorExtensions(){for(let t of this.codeMirrorExtensions)this.codeMirrorExtensions.remove(t);this.plg.app.workspace.updateOptions()}createEventHandlers(){this.gutterContextMenuEvent=this.createGutterContextMenuHandler(),this.fileOpenEvent=this.createFileOpenEvent(),this.workspaceLeafChangeEvent=this.createWorkspaceLeafChangeEvent(),this.fileModificationEvent=this.createVaultFileModificationHandler(),this.refreshOnCssChangeEvent=this.createCssRefreshHandler(),this.fileRenameEvent=this.createFileRenameEvent(),jT(),this.plg.registerEvent(this.gutterContextMenuEvent),this.plg.registerEvent(this.refreshOnCssChangeEvent),this.plg.registerEvent(this.fileOpenEvent),this.plg.registerEvent(this.workspaceLeafChangeEvent),this.plg.registerEvent(this.fileModificationEvent),this.plg.registerEvent(this.fileRenameEvent)}destroyEventHandlers(){this.plg.app.workspace.offref(this.refreshOnCssChangeEvent),this.plg.app.workspace.offref(this.fileOpenEvent),this.plg.app.workspace.offref(this.workspaceLeafChangeEvent),this.plg.app.workspace.offref(this.refreshOnCssChangeEvent),this.plg.app.vault.offref(this.fileRenameEvent),this.plg.app.workspace.offref(this.gutterContextMenuEvent)}createFileOpenEvent(){return this.plg.app.workspace.on("file-open",t=>{var r;return void((r=this.lineAuthorInfoProvider)==null?void 0:r.trackChanged(t).catch(console.error))})}createWorkspaceLeafChangeEvent(){return this.plg.app.workspace.on("active-leaf-change",this.handleWorkspaceLeaf)}createFileRenameEvent(){return this.plg.app.vault.on("rename",(t,r)=>{var n;return t instanceof Sa.TFile&&((n=this.lineAuthorInfoProvider)==null?void 0:n.trackChanged(t))})}createVaultFileModificationHandler(){return this.plg.app.vault.on("modify",t=>{var r;return t instanceof Sa.TFile&&((r=this.lineAuthorInfoProvider)==null?void 0:r.trackChanged(t))})}createCssRefreshHandler(){return this.plg.app.workspace.on("css-change",()=>this.refreshLineAuthorViews())}createGutterContextMenuHandler(){return this.plg.app.workspace.on("editor-menu",UT)}};g();var ad=class{constructor(t){this.plugin=t;this.tasks=[]}addTask(t,r){this.tasks.push({task:t,onFinished:r!=null?r:()=>{}}),this.tasks.length===1&&this.handleTask()}handleTask(){if(this.tasks.length>0){let t=this.tasks[0];t.task().then(r=>{t.onFinished(r),this.tasks.shift(),this.handleTask()},r=>{this.plugin.displayError(r),t.onFinished(void 0),this.tasks.shift(),this.handleTask()})}}clear(){this.tasks=[]}};g();var Nr=require("obsidian");var sd=class{constructor(t,r){this.statusBarEl=t;this.plugin=r;this.messages=[];this.base="obsidian-git-statusbar-";this.statusBarEl.setAttribute("data-tooltip-position","top"),r.registerEvent(r.app.workspace.on("obsidian-git:refreshed",()=>{this.refreshCommitTimestamp().catch(console.error)}))}displayMessage(t,r){this.messages.push({message:`Git: ${t.slice(0,100)}`,timeout:r}),this.display()}display(){this.messages.length>0&&!this.currentMessage?(this.currentMessage=this.messages.shift(),this.statusBarEl.addClass(this.base+"message"),this.statusBarEl.ariaLabel="",this.statusBarEl.setText(this.currentMessage.message),this.lastMessageTimestamp=Date.now()):this.currentMessage?Date.now()-this.lastMessageTimestamp>=this.currentMessage.timeout&&(this.currentMessage=null,this.lastMessageTimestamp=null):this.displayState()}displayState(){switch((this.statusBarEl.getText().length>3||!this.statusBarEl.hasChildNodes())&&(this.statusBarEl.empty(),this.conflictEl=this.statusBarEl.createDiv(),this.conflictEl.setAttribute("data-tooltip-position","top"),this.conflictEl.style.float="left",this.iconEl=this.statusBarEl.createDiv(),this.iconEl.style.float="left",this.textEl=this.statusBarEl.createDiv(),this.textEl.style.float="right",this.textEl.style.marginLeft="5px"),this.plugin.localStorage.getConflict()?((0,Nr.setIcon)(this.conflictEl,"alert-circle"),this.conflictEl.ariaLabel="You have merge conflicts. Resolve them and commit afterwards.",this.conflictEl.style.marginRight="5px",this.conflictEl.addClass(this.base+"conflict")):(this.conflictEl.empty(),this.conflictEl.style.marginRight=""),this.plugin.state.gitAction){case 0:this.displayFromNow();break;case 1:this.statusBarEl.ariaLabel="Checking repository status...",(0,Nr.setIcon)(this.iconEl,"refresh-cw"),this.statusBarEl.addClass(this.base+"status");break;case 3:this.statusBarEl.ariaLabel="Adding files...",(0,Nr.setIcon)(this.iconEl,"archive"),this.statusBarEl.addClass(this.base+"add");break;case 4:this.statusBarEl.ariaLabel="Committing changes...",(0,Nr.setIcon)(this.iconEl,"git-commit"),this.statusBarEl.addClass(this.base+"commit");break;case 5:this.statusBarEl.ariaLabel="Pushing changes...",(0,Nr.setIcon)(this.iconEl,"upload"),this.statusBarEl.addClass(this.base+"push");break;case 2:this.statusBarEl.ariaLabel="Pulling changes...",(0,Nr.setIcon)(this.iconEl,"download"),this.statusBarEl.addClass(this.base+"pull");break;default:this.statusBarEl.ariaLabel="Failed on initialization!",(0,Nr.setIcon)(this.iconEl,"alert-triangle"),this.statusBarEl.addClass(this.base+"failed-init");break}}displayFromNow(){var n;let t=this.lastCommitTimestamp,r=this.plugin.state.offlineMode;if(t){let i=(0,Nr.moment)(t).fromNow();this.statusBarEl.ariaLabel=`${r?"Offline: ":""}Last Commit: ${i}`,(n=this.unPushedCommits)!=null&&n&&(this.statusBarEl.ariaLabel+=`
+(${this.unPushedCommits} unpushed commits)`)}else this.statusBarEl.ariaLabel=r?"Git is offline":"Git is ready";r?(0,Nr.setIcon)(this.iconEl,"globe"):(0,Nr.setIcon)(this.iconEl,"check"),this.plugin.settings.changedFilesInStatusBar&&this.plugin.cachedStatus&&this.textEl.setText(this.plugin.cachedStatus.changed.length.toString()),this.statusBarEl.addClass(this.base+"idle")}async refreshCommitTimestamp(){this.lastCommitTimestamp=await this.plugin.gitManager.getLastCommitTime(),this.unPushedCommits=await this.plugin.gitManager.getUnpushedCommits()}remove(){this.statusBarEl.remove()}};g();var ld=require("obsidian"),od=class extends ld.SuggestModal{constructor(r){super(r.app);this.plugin=r;this.resolve=null;this.setPlaceholder("Type your message and select optional the version with the added date.")}openAndGetResult(){return new Promise(r=>{this.resolve=r,this.open()})}onClose(){new Promise(r=>setTimeout(r,10)).then(()=>{this.resolve&&this.resolve(void 0)})}getSuggestions(r){let n=(0,ld.moment)().format(this.plugin.settings.commitDateFormat);return r==""&&(r="..."),[r,`${n}: ${r}`,`${r}: ${n}`]}renderSuggestion(r,n){n.innerText=r}onChooseSuggestion(r,n){this.resolve&&this.resolve(r)}};g();var rC=require("obsidian"),Xl=class{constructor(t){this.plugin=t}saveLastAuto(t,r){r==="backup"?this.plugin.localStorage.setLastAutoBackup(t.toString()):r==="pull"?this.plugin.localStorage.setLastAutoPull(t.toString()):r==="push"&&this.plugin.localStorage.setLastAutoPush(t.toString())}loadLastAuto(){var t,r,n;return{backup:new Date((t=this.plugin.localStorage.getLastAutoBackup())!=null?t:""),pull:new Date((r=this.plugin.localStorage.getLastAutoPull())!=null?r:""),push:new Date((n=this.plugin.localStorage.getLastAutoPush())!=null?n:"")}}async init(){await this.setUpAutoCommitAndSync();let t=this.loadLastAuto();if(this.plugin.settings.differentIntervalCommitAndPush&&this.plugin.settings.autoPushInterval>0){let r=this.diff(this.plugin.settings.autoPushInterval,t.push);this.startAutoPush(r)}if(this.plugin.settings.autoPullInterval>0){let r=this.diff(this.plugin.settings.autoPullInterval,t.pull);this.startAutoPull(r)}}unload(){this.clearAutoPull(),this.clearAutoPush(),this.clearAutoCommitAndSync()}reload(...t){t.contains("commit")&&(this.clearAutoCommitAndSync(),this.plugin.settings.autoSaveInterval>0&&this.startAutoCommitAndSync(this.plugin.settings.autoSaveInterval)),t.contains("push")&&(this.clearAutoPush(),this.plugin.settings.differentIntervalCommitAndPush&&this.plugin.settings.autoPushInterval>0&&this.startAutoPush(this.plugin.settings.autoPushInterval)),t.contains("pull")&&(this.clearAutoPull(),this.plugin.settings.autoPullInterval>0&&this.startAutoPull(this.plugin.settings.autoPullInterval))}async setUpAutoCommitAndSync(){if(this.plugin.settings.setLastSaveToLastCommit){this.clearAutoCommitAndSync();let t=await this.plugin.gitManager.getLastCommitTime();t&&this.saveLastAuto(t,"backup")}if(!this.timeoutIDCommitAndSync&&!this.plugin.autoCommitDebouncer){let t=this.loadLastAuto();if(this.plugin.settings.autoSaveInterval>0){let r=this.diff(this.plugin.settings.autoSaveInterval,t.backup);this.startAutoCommitAndSync(r)}}}startAutoCommitAndSync(t){let r=(t!=null?t:this.plugin.settings.autoSaveInterval)*6e4;this.plugin.settings.autoBackupAfterFileChange?t===0?this.doAutoCommitAndSync():this.plugin.autoCommitDebouncer=(0,rC.debounce)(()=>this.doAutoCommitAndSync(),r,!0):(r>2147483647&&(r=2147483647),this.timeoutIDCommitAndSync=window.setTimeout(()=>this.doAutoCommitAndSync(),r))}doAutoCommitAndSync(){this.plugin.promiseQueue.addTask(async()=>{if(this.plugin.settings.setLastSaveToLastCommit){let t=await this.plugin.gitManager.getLastCommitTime();if(t){this.saveLastAuto(t,"backup");let r=this.diff(this.plugin.settings.autoSaveInterval,t);if(r>0)return this.startAutoCommitAndSync(r),!1}}return this.plugin.settings.differentIntervalCommitAndPush?await this.plugin.commit({fromAuto:!0}):await this.plugin.commitAndSync(!0),!0},t=>{t!==!1&&(this.saveLastAuto(new Date,"backup"),this.startAutoCommitAndSync())})}startAutoPull(t){let r=(t!=null?t:this.plugin.settings.autoPullInterval)*6e4;r>2147483647&&(r=2147483647),this.timeoutIDPull=window.setTimeout(()=>this.doAutoPull(),r)}doAutoPull(){this.plugin.promiseQueue.addTask(()=>this.plugin.pullChangesFromRemote(),()=>{this.saveLastAuto(new Date,"pull"),this.startAutoPull()})}startAutoPush(t){let r=(t!=null?t:this.plugin.settings.autoPushInterval)*6e4;r>2147483647&&(r=2147483647),this.timeoutIDPush=window.setTimeout(()=>this.doAutoPush(),r)}doAutoPush(){this.plugin.promiseQueue.addTask(()=>this.plugin.push(),()=>{this.saveLastAuto(new Date,"push"),this.startAutoPush()})}clearAutoCommitAndSync(){var r;let t=!1;return this.timeoutIDCommitAndSync&&(window.clearTimeout(this.timeoutIDCommitAndSync),this.timeoutIDCommitAndSync=void 0,t=!0),this.plugin.autoCommitDebouncer&&((r=this.plugin.autoCommitDebouncer)==null||r.cancel(),this.plugin.autoCommitDebouncer=void 0,t=!0),t}clearAutoPull(){return this.timeoutIDPull?(window.clearTimeout(this.timeoutIDPull),this.timeoutIDPull=void 0,!0):!1}clearAutoPush(){return this.timeoutIDPush?(window.clearTimeout(this.timeoutIDPush),this.timeoutIDPush=void 0,!0):!1}diff(t,r){let i=t-Math.round((new Date().getTime()-r.getTime())/1e3/60);return Math.max(0,i)}};g();var Kl=require("obsidian");g();var Zl=require("obsidian");async function nC(e,t,r){let n=await aC(t,r);if(n.result==="failure"){new Zl.Notice(n.reason);return}let{isGitHub:i,branch:a,repo:s,user:o,filePath:c}=n;if(i){let l=e.getCursor("from").line+1,u=e.getCursor("to").line+1;l===u?window.open(`https://github.com/${o}/${s}/blob/${a}/${c}?plain=1#L${l}`):window.open(`https://github.com/${o}/${s}/blob/${a}/${c}?plain=1#L${l}-L${u}`)}else new Zl.Notice("It seems like you are not using GitHub")}async function iC(e,t){let r=await aC(e,t);if(r.result==="failure"){new Zl.Notice(r.reason);return}let{isGitHub:n,branch:i,repo:a,user:s,filePath:o}=r;n?window.open(`https://github.com/${s}/${a}/commits/${i}/${o}`):new Zl.Notice("It seems like you are not using GitHub")}async function aC(e,t){let r=await t.branchInfo(),n=r.tracking,i=r.current,a,s=t.getRelativeRepoPath(e.path);if(t instanceof Te){let c=await t.getSubmoduleOfFile(t.getRelativeRepoPath(e.path));if(c){s=c.relativeFilepath;let l=await t.git.cwd({path:c.submodule,root:!1}).status();if(n=l.tracking||void 0,i=l.current||void 0,n){let u=n.substring(0,n.indexOf("/")),f=await t.git.cwd({path:c.submodule,root:!1}).getConfig(`remote.${u}.url`,"local");if(f.value!=null)a=f.value;else return{result:"failure",reason:"Failed to get remote url of submodule"}}}}if(n==null)return{result:"failure",reason:"Remote branch is not configured"};if(i==null)return{result:"failure",reason:"Failed to get current branch name"};if(a==null){let c=n.substring(0,n.indexOf("/"));if(a=await t.getConfig(`remote.${c}.url`),a==null)return{result:"failure",reason:"Failed to get remote url"}}let o=a.match(/(?:^https:\/\/github\.com\/(.+)\/(.+?)(?:\.git)?$)|(?:^[a-zA-Z]+@github\.com:(.+)\/(.+?)(?:\.git)?$)/);if(o==null)return{result:"failure",reason:"Could not parse remote url"};{let[c,l,u,f,d]=o;return{result:"success",isGitHub:!!c,repo:u||d,user:l||f,branch:i,filePath:s}}}g();var sC=require("obsidian"),cd=class extends sC.FuzzySuggestModal{constructor(t,r){super(t.app),this.plugin=t,this.changedFiles=r,this.setPlaceholder("Not supported files will be opened by default app!")}getItems(){return this.changedFiles}getItemText(t){if(t.index=="U"&&t.workingDir=="U")return`Untracked | ${t.vaultPath}`;let r="",n="";return t.workingDir!=" "&&(r=`Working Dir: ${t.workingDir} `),t.index!=" "&&(n=`Index: ${t.index}`),`${r}${n} | ${t.vaultPath}`}onChooseItem(t,r){this.plugin.app.metadataCache.getFirstLinkpathDest(t.vaultPath,"")==null?this.app.openWithDefaultApp(t.vaultPath):this.plugin.app.workspace.openLinkText(t.vaultPath,"/")}};g();var oC=require("obsidian"),ud=class extends oC.Modal{constructor(r,n){super(r);this.content=n;this.resolve=null}openAndGetReslt(){return new Promise(r=>{this.resolve=r,this.open()})}onOpen(){let{contentEl:r,titleEl:n}=this;n.setText("Edit .gitignore");let i=r.createDiv(),a=i.createEl("textarea",{text:this.content,cls:["obsidian-git-textarea"],attr:{rows:10,cols:30,wrap:"off"}});i.createEl("button",{cls:["mod-cta","obsidian-git-center-button"],text:"Save"}).addEventListener("click",()=>{this.resolve(a.value),this.close()})}onClose(){let{contentEl:r}=this;r.empty(),this.resolve&&this.resolve(void 0)}};function lC(e){let t=e.app;e.addCommand({id:"edit-gitignore",name:"Edit .gitignore",callback:async()=>{let r=e.gitManager.getRelativeVaultPath(".gitignore");await t.vault.adapter.exists(r)||await t.vault.adapter.write(r,"");let n=await t.vault.adapter.read(r),a=await new ud(t,n).openAndGetReslt();a!==void 0&&(await t.vault.adapter.write(r,a),await e.refresh())}}),e.addCommand({id:"open-git-view",name:"Open source control view",callback:async()=>{var i;let r=t.workspace.getLeavesOfType(St.type),n;r.length===0?(n=(i=t.workspace.getRightLeaf(!1))!=null?i:t.workspace.getLeaf(),await n.setViewState({type:St.type})):n=r.first(),await t.workspace.revealLeaf(n),t.workspace.trigger("obsidian-git:refresh")}}),e.addCommand({id:"open-history-view",name:"Open history view",callback:async()=>{var i;let r=t.workspace.getLeavesOfType($r.type),n;r.length===0?(n=(i=t.workspace.getRightLeaf(!1))!=null?i:t.workspace.getLeaf(),await n.setViewState({type:$r.type})):n=r.first(),await t.workspace.revealLeaf(n),t.workspace.trigger("obsidian-git:refresh")}}),e.addCommand({id:"open-diff-view",name:"Open diff view",checkCallback:r=>{let n=t.workspace.getActiveFile();if(r)return n!==null;{let i=e.gitManager.getRelativeRepoPath(n.path,!0);e.tools.openDiff({aFile:i,aRef:""})}}}),e.addCommand({id:"view-file-on-github",name:"Open file on GitHub",editorCallback:(r,{file:n})=>{if(n)return nC(r,n,e.gitManager)}}),e.addCommand({id:"view-history-on-github",name:"Open file history on GitHub",editorCallback:(r,{file:n})=>{if(n)return iC(n,e.gitManager)}}),e.addCommand({id:"pull",name:"Pull",callback:()=>e.promiseQueue.addTask(()=>e.pullChangesFromRemote())}),e.addCommand({id:"fetch",name:"Fetch",callback:()=>e.promiseQueue.addTask(()=>e.fetch())}),e.addCommand({id:"switch-to-remote-branch",name:"Switch to remote branch",callback:()=>e.promiseQueue.addTask(()=>e.switchRemoteBranch())}),e.addCommand({id:"add-to-gitignore",name:"Add file to .gitignore",checkCallback:r=>{let n=t.workspace.getActiveFile();if(r)return n!==null;e.addFileToGitignore(n.path).catch(i=>e.displayError(i))}}),e.addCommand({id:"push",name:"Commit-and-sync",callback:()=>e.promiseQueue.addTask(()=>e.commitAndSync(!1))}),e.addCommand({id:"backup-and-close",name:"Commit-and-sync and then close Obsidian",callback:()=>e.promiseQueue.addTask(async()=>{await e.commitAndSync(!1),window.close()})}),e.addCommand({id:"commit-push-specified-message",name:"Commit-and-sync with specific message",callback:()=>e.promiseQueue.addTask(()=>e.commitAndSync(!1,!0))}),e.addCommand({id:"commit",name:"Commit all changes",callback:()=>e.promiseQueue.addTask(()=>e.commit({fromAuto:!1}))}),e.addCommand({id:"commit-specified-message",name:"Commit all changes with specific message",callback:()=>e.promiseQueue.addTask(()=>e.commit({fromAuto:!1,requestCustomMessage:!0}))}),e.addCommand({id:"commit-staged",name:"Commit staged",callback:()=>e.promiseQueue.addTask(()=>e.commit({fromAuto:!1,requestCustomMessage:!1,onlyStaged:!0}))}),Kl.Platform.isDesktopApp&&e.addCommand({id:"commit-amend-staged-specified-message",name:"Amend staged",callback:()=>e.promiseQueue.addTask(()=>e.commit({fromAuto:!1,requestCustomMessage:!0,onlyStaged:!0,amend:!0}))}),e.addCommand({id:"commit-staged-specified-message",name:"Commit staged with specific message",callback:()=>e.promiseQueue.addTask(()=>e.commit({fromAuto:!1,requestCustomMessage:!0,onlyStaged:!0}))}),e.addCommand({id:"push2",name:"Push",callback:()=>e.promiseQueue.addTask(()=>e.push())}),e.addCommand({id:"stage-current-file",name:"Stage current file",checkCallback:r=>{let n=t.workspace.getActiveFile();if(r)return n!==null;e.promiseQueue.addTask(()=>e.stageFile(n))}}),e.addCommand({id:"unstage-current-file",name:"Unstage current file",checkCallback:r=>{let n=t.workspace.getActiveFile();if(r)return n!==null;e.promiseQueue.addTask(()=>e.unstageFile(n))}}),e.addCommand({id:"edit-remotes",name:"Edit remotes",callback:()=>e.editRemotes().catch(r=>e.displayError(r))}),e.addCommand({id:"remove-remote",name:"Remove remote",callback:()=>e.removeRemote().catch(r=>e.displayError(r))}),e.addCommand({id:"set-upstream-branch",name:"Set upstream branch",callback:()=>e.setUpstreamBranch().catch(r=>e.displayError(r))}),e.addCommand({id:"delete-repo",name:"CAUTION: Delete repository",callback:async()=>{await t.vault.adapter.exists(`${e.settings.basePath}/.git`)?await new Fe(e,{options:["NO","YES"],placeholder:"Do you really want to delete the repository (.git directory)? plugin action cannot be undone.",onlySelection:!0}).openAndGetResult()==="YES"&&(await t.vault.adapter.rmdir(`${e.settings.basePath}/.git`,!0),new Kl.Notice("Successfully deleted repository. Reloading plugin..."),e.unloadPlugin(),await e.init({fromReload:!0})):new Kl.Notice("No repository found")}}),e.addCommand({id:"init-repo",name:"Initialize a new repo",callback:()=>e.createNewRepo().catch(r=>e.displayError(r))}),e.addCommand({id:"clone-repo",name:"Clone an existing remote repo",callback:()=>e.cloneNewRepo().catch(r=>e.displayError(r))}),e.addCommand({id:"list-changed-files",name:"List changed files",callback:async()=>{if(await e.isAllInitialized())try{let r=await e.updateCachedStatus();if(r.changed.length+r.staged.length>500){e.displayError("Too many changes to display");return}new cd(e,r.all).open()}catch(r){e.displayError(r)}}}),e.addCommand({id:"switch-branch",name:"Switch branch",callback:()=>{e.switchBranch().catch(r=>e.displayError(r))}}),e.addCommand({id:"create-branch",name:"Create new branch",callback:()=>{e.createBranch().catch(r=>e.displayError(r))}}),e.addCommand({id:"delete-branch",name:"Delete branch",callback:()=>{e.deleteBranch().catch(r=>e.displayError(r))}}),e.addCommand({id:"discard-all",name:"CAUTION: Discard all changes",callback:async()=>{if(!await e.isAllInitialized())return!1;await new Fe(e,{options:["NO","YES"],placeholder:"Do you want to discard all changes to tracked files? plugin action cannot be undone.",onlySelection:!0}).openAndGetResult()==="YES"&&e.promiseQueue.addTask(()=>e.discardAll())}}),e.addCommand({id:"raw-command",name:"Raw command",checkCallback:r=>{let n=e.gitManager;if(r)return n instanceof Te;e.tools.runRawCommand().catch(i=>e.displayError(i))}}),e.addCommand({id:"toggle-line-author-info",name:"Toggle line author information",callback:()=>{var r;return(r=e.settingsTab)==null?void 0:r.configureLineAuthorShowStatus(!e.settings.lineAuthor.show)}})}g();var fd=class{constructor(t){this.plugin=t;this.prefix=this.plugin.manifest.id+":",this.app=t.app}migrate(){let t=["password","hostname","conflict","lastAutoPull","lastAutoBackup","lastAutoPush","gitPath","pluginDisabled"];for(let r of t){let n=localStorage.getItem(this.prefix+r);this.app.loadLocalStorage(this.prefix+r)==null&&n!=null&&n!=null&&(this.app.saveLocalStorage(this.prefix+r,n),localStorage.removeItem(this.prefix+r))}}getPassword(){return this.app.loadLocalStorage(this.prefix+"password")}setPassword(t){return this.app.saveLocalStorage(this.prefix+"password",t)}getUsername(){return this.app.loadLocalStorage(this.prefix+"username")}setUsername(t){return this.app.saveLocalStorage(this.prefix+"username",t)}getHostname(){return this.app.loadLocalStorage(this.prefix+"hostname")}setHostname(t){return this.app.saveLocalStorage(this.prefix+"hostname",t)}getConflict(){return this.app.loadLocalStorage(this.prefix+"conflict")=="true"}setConflict(t){return this.app.saveLocalStorage(this.prefix+"conflict",`${t}`)}getLastAutoPull(){return this.app.loadLocalStorage(this.prefix+"lastAutoPull")}setLastAutoPull(t){return this.app.saveLocalStorage(this.prefix+"lastAutoPull",t)}getLastAutoBackup(){return this.app.loadLocalStorage(this.prefix+"lastAutoBackup")}setLastAutoBackup(t){return this.app.saveLocalStorage(this.prefix+"lastAutoBackup",t)}getLastAutoPush(){return this.app.loadLocalStorage(this.prefix+"lastAutoPush")}setLastAutoPush(t){return this.app.saveLocalStorage(this.prefix+"lastAutoPush",t)}getGitPath(){return this.app.loadLocalStorage(this.prefix+"gitPath")}setGitPath(t){return this.app.saveLocalStorage(this.prefix+"gitPath",t)}getPATHPaths(){var t,r;return(r=(t=this.app.loadLocalStorage(this.prefix+"PATHPaths"))==null?void 0:t.split(":"))!=null?r:[]}setPATHPaths(t){return this.app.saveLocalStorage(this.prefix+"PATHPaths",t.join(":"))}getEnvVars(){var t;return JSON.parse((t=this.app.loadLocalStorage(this.prefix+"envVars"))!=null?t:"[]")}setEnvVars(t){return this.app.saveLocalStorage(this.prefix+"envVars",JSON.stringify(t))}getPluginDisabled(){return this.app.loadLocalStorage(this.prefix+"pluginDisabled")=="true"}setPluginDisabled(t){return this.app.saveLocalStorage(this.prefix+"pluginDisabled",`${t}`)}};g();g();g();g();var He;(function(e){e.INSERT="insert",e.DELETE="delete",e.CONTEXT="context"})(He||(He={}));var cC={LINE_BY_LINE:"line-by-line",SIDE_BY_SIDE:"side-by-side"},uC={LINES:"lines",WORDS:"words",NONE:"none"},fC={WORD:"word",CHAR:"char"},Ea;(function(e){e.AUTO="auto",e.DARK="dark",e.LIGHT="light"})(Ea||(Ea={}));g();var yB=["-","[","]","/","{","}","(",")","*","+","?",".","\\","^","$","|"],wB=RegExp("["+yB.join("\\")+"]","g");function dC(e){return e.replace(wB,"\\$&")}function m0(e){return e&&e.replace(/\\/g,"/")}function hC(e){let t,r,n,i=0;for(t=0,n=e.length;t1?r[r.length-1]:t}function mC(e,t){return t.reduce((r,n)=>r||e.startsWith(n),!1)}var gC=["a/","b/","i/","w/","c/","o/"];function $i(e,t,r){let n=r!==void 0?[...gC,r]:gC,i=t?new RegExp(`^${dC(t)} "?(.+?)"?$`):new RegExp('^"?(.+?)"?$'),[,a=""]=i.exec(e)||[],s=n.find(c=>a.indexOf(c)===0);return(s?a.slice(s.length):a).replace(/\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? [+-]\d{4}.*$/,"")}function bB(e,t){return $i(e,"---",t)}function _B(e,t){return $i(e,"+++",t)}function vC(e,t={}){let r=[],n=null,i=null,a=null,s=null,o=null,c=null,l=null,u="--- ",f="+++ ",d="@@",h=/^old mode (\d{6})/,p=/^new mode (\d{6})/,m=/^deleted file mode (\d{6})/,v=/^new file mode (\d{6})/,y=/^copy from "?(.+)"?/,b=/^copy to "?(.+)"?/,x=/^rename from "?(.+)"?/,E=/^rename to "?(.+)"?/,_=/^similarity index (\d+)%/,k=/^dissimilarity index (\d+)%/,w=/^index ([\da-z]+)\.\.([\da-z]+)\s*(\d{6})?/,A=/^Binary files (.*) and (.*) differ/,S=/^GIT binary patch/,T=/^index ([\da-z]+),([\da-z]+)\.\.([\da-z]+)/,P=/^mode (\d{6}),(\d{6})\.\.(\d{6})/,O=/^new file mode (\d{6})/,j=/^deleted file mode (\d{6}),(\d{6})/,D=e.replace(/\\ No newline at end of file/g,"").replace(/\r\n?/g,`
+`).split(`
+`);function Q(){i!==null&&n!==null&&(n.blocks.push(i),i=null)}function de(){n!==null&&(!n.oldName&&c!==null&&(n.oldName=c),!n.newName&&l!==null&&(n.newName=l),n.newName&&(r.push(n),n=null)),c=null,l=null}function ee(){Q(),de(),n={blocks:[],deletedLines:0,addedLines:0}}function J(F){Q();let G;n!==null&&((G=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@.*/.exec(F))?(n.isCombined=!1,a=parseInt(G[1],10),o=parseInt(G[2],10)):(G=/^@@@ -(\d+)(?:,\d+)? -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@@.*/.exec(F))?(n.isCombined=!0,a=parseInt(G[1],10),s=parseInt(G[2],10),o=parseInt(G[3],10)):(F.startsWith(d)&&console.error("Failed to parse lines, starting in 0!"),a=0,o=0,n.isCombined=!1)),i={lines:[],oldStartLine:a,oldStartLine2:s,newStartLine:o,header:F}}function Pe(F){if(n===null||i===null||a===null||o===null)return;let G={content:F},N=n.isCombined?["+ "," +","++"]:["+"],Me=n.isCombined?["- "," -","--"]:["-"];mC(F,N)?(n.addedLines++,G.type=He.INSERT,G.oldNumber=void 0,G.newNumber=o++):mC(F,Me)?(n.deletedLines++,G.type=He.DELETE,G.oldNumber=a++,G.newNumber=void 0):(G.type=He.CONTEXT,G.oldNumber=a++,G.newNumber=o++),i.lines.push(G)}function me(F,G){let N=G;for(;N{if(!F||F.startsWith("*"))return;let N,Me=D[G-1],Dt=D[G+1],_t=D[G+2];if(F.startsWith("diff --git")||F.startsWith("diff --combined")){if(ee(),(N=/^diff --git "?([a-ciow]\/.+)"? "?([a-ciow]\/.+)"?/.exec(F))&&(c=$i(N[1],void 0,t.dstPrefix),l=$i(N[2],void 0,t.srcPrefix)),n===null)throw new Error("Where is my file !!!");n.isGitDiff=!0;return}if(F.startsWith("Binary files")&&!(n!=null&&n.isGitDiff)){if(ee(),(N=/^Binary files "?([a-ciow]\/.+)"? and "?([a-ciow]\/.+)"? differ/.exec(F))&&(c=$i(N[1],void 0,t.dstPrefix),l=$i(N[2],void 0,t.srcPrefix)),n===null)throw new Error("Where is my file !!!");n.isBinary=!0;return}if((!n||!n.isGitDiff&&n&&F.startsWith(u)&&Dt.startsWith(f)&&_t.startsWith(d))&&ee(),n!=null&&n.isTooBig)return;if(n&&(typeof t.diffMaxChanges=="number"&&n.addedLines+n.deletedLines>t.diffMaxChanges||typeof t.diffMaxLineLength=="number"&&F.length>t.diffMaxLineLength)){n.isTooBig=!0,n.addedLines=0,n.deletedLines=0,n.blocks=[],i=null;let st=typeof t.diffTooBigMessage=="function"?t.diffTooBigMessage(r.length):"Diff too big to be displayed";J(st);return}if(F.startsWith(u)&&Dt.startsWith(f)||F.startsWith(f)&&Me.startsWith(u)){if(n&&!n.oldName&&F.startsWith("--- ")&&(N=bB(F,t.srcPrefix))){n.oldName=N,n.language=pC(n.oldName,n.language);return}if(n&&!n.newName&&F.startsWith("+++ ")&&(N=_B(F,t.dstPrefix))){n.newName=N,n.language=pC(n.newName,n.language);return}}if(n&&(F.startsWith(d)||n.isGitDiff&&n.oldName&&n.newName&&!i)){J(F);return}if(i&&(F.startsWith("+")||F.startsWith("-")||F.startsWith(" "))){Pe(F);return}let Ee=!me(F,G);if(n===null)throw new Error("Where is my file !!!");(N=h.exec(F))?n.oldMode=N[1]:(N=p.exec(F))?n.newMode=N[1]:(N=m.exec(F))?(n.deletedFileMode=N[1],n.isDeleted=!0):(N=v.exec(F))?(n.newFileMode=N[1],n.isNew=!0):(N=y.exec(F))?(Ee&&(n.oldName=N[1]),n.isCopy=!0):(N=b.exec(F))?(Ee&&(n.newName=N[1]),n.isCopy=!0):(N=x.exec(F))?(Ee&&(n.oldName=N[1]),n.isRename=!0):(N=E.exec(F))?(Ee&&(n.newName=N[1]),n.isRename=!0):(N=A.exec(F))?(n.isBinary=!0,n.oldName=$i(N[1],void 0,t.srcPrefix),n.newName=$i(N[2],void 0,t.dstPrefix),J("Binary file")):S.test(F)?(n.isBinary=!0,J(F)):(N=_.exec(F))?n.unchangedPercentage=parseInt(N[1],10):(N=k.exec(F))?n.changedPercentage=parseInt(N[1],10):(N=w.exec(F))?(n.checksumBefore=N[1],n.checksumAfter=N[2],N[3]&&(n.mode=N[3])):(N=T.exec(F))?(n.checksumBefore=[N[2],N[3]],n.checksumAfter=N[1]):(N=P.exec(F))?(n.oldMode=[N[2],N[3]],n.newMode=N[1]):(N=O.exec(F))?(n.newFileMode=N[1],n.isNew=!0):(N=j.exec(F))&&(n.deletedFileMode=N[1],n.isDeleted=!0)}),Q(),de(),r}g();g();g();function Kn(){}Kn.prototype={diff:function(t,r){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=n.callback;typeof n=="function"&&(i=n,n={}),this.options=n;var a=this;function s(m){return i?(setTimeout(function(){i(void 0,m)},0),!0):m}t=this.castInput(t),r=this.castInput(r),t=this.removeEmpty(this.tokenize(t)),r=this.removeEmpty(this.tokenize(r));var o=r.length,c=t.length,l=1,u=o+c;n.maxEditLength&&(u=Math.min(u,n.maxEditLength));var f=[{newPos:-1,components:[]}],d=this.extractCommon(f[0],r,t,0);if(f[0].newPos+1>=o&&d+1>=c)return s([{value:this.join(r),count:r.length}]);function h(){for(var m=-1*l;m<=l;m+=2){var v=void 0,y=f[m-1],b=f[m+1],x=(b?b.newPos:0)-m;y&&(f[m-1]=void 0);var E=y&&y.newPos+1=o&&x+1>=c)return s(SB(a,v.components,r,t,a.useLongestToken));f[m]=v}l++}if(i)(function m(){setTimeout(function(){if(l>u)return i();h()||m()},0)})();else for(;l<=u;){var p=h();if(p)return p}},pushComponent:function(t,r,n){var i=t[t.length-1];i&&i.added===r&&i.removed===n?t[t.length-1]={count:i.count+1,added:r,removed:n}:t.push({count:1,added:r,removed:n})},extractCommon:function(t,r,n,i){for(var a=r.length,s=n.length,o=t.newPos,c=o-i,l=0;o+1h.length?m:h}),l.value=e.join(u)}else l.value=e.join(r.slice(o,o+l.count));o+=l.count,l.added||(c+=l.count)}}var d=t[s-1];return s>1&&typeof d.value=="string"&&(d.added||d.removed)&&e.equals("",d.value)&&(t[s-2].value+=d.value,t.pop()),t}function EB(e){return{newPos:e.newPos,components:e.components.slice(0)}}var AB=new Kn;function bC(e,t,r){return AB.diff(e,t,r)}var yC=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,wC=/\S/,y0=new Kn;y0.equals=function(e,t){return this.options.ignoreCase&&(e=e.toLowerCase(),t=t.toLowerCase()),e===t||this.options.ignoreWhitespace&&!wC.test(e)&&!wC.test(t)};y0.tokenize=function(e){for(var t=e.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/),r=0;r{let n=e(t).trim(),i=e(r).trim();return RB(n,i)/(n.length+i.length)}}function Js(e){function t(n,i,a=new Map){let s=1/0,o;for(let c=0;c0||o.indexB>0)&&(x=v.concat(x)),(n.length>d||i.length>h)&&(x=x.concat(b)),x}return r}var Et={INSERTS:"d2h-ins",DELETES:"d2h-del",CONTEXT:"d2h-cntx",INFO:"d2h-info",INSERT_CHANGES:"d2h-ins d2h-change",DELETE_CHANGES:"d2h-del d2h-change"},Aa={matching:uC.NONE,matchWordsThreshold:.25,maxLineLengthHighlight:1e4,diffStyle:fC.WORD,colorScheme:Ea.LIGHT},Cn="/",SC=Ks(e=>e.value),MB=Js(SC);function b0(e){return e.indexOf("dev/null")!==-1}function OB(e){return e.replace(/(]*>((.|\n)*?)<\/ins>)/g,"")}function IB(e){return e.replace(/(]*>((.|\n)*?)<\/del>)/g,"")}function Qs(e){switch(e){case He.CONTEXT:return Et.CONTEXT;case He.INSERT:return Et.INSERTS;case He.DELETE:return Et.DELETES}}function eo(e){switch(e){case Ea.DARK:return"d2h-dark-color-scheme";case Ea.AUTO:return"d2h-auto-color-scheme";case Ea.LIGHT:default:return"d2h-light-color-scheme"}}function FB(e){return e?2:1}function Li(e){return e.slice(0).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}function jr(e,t,r=!0){let n=FB(t);return{prefix:e.substring(0,n),content:r?Li(e.substring(n)):e.substring(n)}}function ka(e){let t=m0(e.oldName),r=m0(e.newName);if(t!==r&&!b0(t)&&!b0(r)){let n=[],i=[],a=t.split(Cn),s=r.split(Cn),o=a.length,c=s.length,l=0,u=o-1,f=c-1;for(;ll&&f>l&&a[u]===s[f];)i.unshift(s[f]),u-=1,f-=1;let d=n.join(Cn),h=i.join(Cn),p=a.slice(l,u+1).join(Cn),m=s.slice(l,f+1).join(Cn);return d.length&&h.length?d+Cn+"{"+p+" \u2192 "+m+"}"+Cn+h:d.length?d+Cn+"{"+p+" \u2192 "+m+"}":h.length?"{"+p+" \u2192 "+m+"}"+Cn+h:t+" \u2192 "+r}else return b0(r)?t:r}function to(e){return`d2h-${hC(ka(e)).toString().slice(-6)}`}function ro(e){let t="file-changed";return e.isRename||e.isCopy?t="file-renamed":e.isNew?t="file-added":e.isDeleted?t="file-deleted":e.newName!==e.oldName&&(t="file-renamed"),t}function hd(e,t,r,n={}){let{matching:i,maxLineLengthHighlight:a,matchWordsThreshold:s,diffStyle:o}=Object.assign(Object.assign({},Aa),n),c=jr(e,r,!1),l=jr(t,r,!1);if(c.content.length>a||l.content.length>a)return{oldLine:{prefix:c.prefix,content:Li(c.content)},newLine:{prefix:l.prefix,content:Li(l.content)}};let u=o==="char"?bC(c.content,l.content):_C(c.content,l.content),f=[];if(o==="word"&&i==="words"){let h=u.filter(v=>v.removed),p=u.filter(v=>v.added);MB(p,h).forEach(v=>{v[0].length===1&&v[1].length===1&&SC(v[0][0],v[1][0]){let m=p.added?"ins":p.removed?"del":null,v=f.indexOf(p)>-1?' class="d2h-change"':"",y=Li(p.value);return m!==null?`${h}<${m}${v}>${y}${m}>`:`${h}${y}`},"");return{oldLine:{prefix:c.prefix,content:OB(d)},newLine:{prefix:l.prefix,content:IB(d)}}}var EC="file-summary",$B="icon",LB={colorScheme:Aa.colorScheme},pd=class{constructor(t,r={}){this.hoganUtils=t,this.config=Object.assign(Object.assign({},LB),r)}render(t){let r=t.map(n=>this.hoganUtils.render(EC,"line",{fileHtmlId:to(n),oldName:n.oldName,newName:n.newName,fileName:ka(n),deletedLines:"-"+n.deletedLines,addedLines:"+"+n.addedLines},{fileIcon:this.hoganUtils.template($B,ro(n))})).join(`
+`);return this.hoganUtils.render(EC,"wrapper",{colorScheme:eo(this.config.colorScheme),filesNumber:t.length,files:r})}};g();var x0=Object.assign(Object.assign({},Aa),{renderNothingWhenEmpty:!1,matchingMaxComparisons:2500,maxLineSizeInBlockForComparison:200}),Ql="generic",AC="line-by-line",DB="icon",NB="tag",ec=class{constructor(t,r={}){this.hoganUtils=t,this.config=Object.assign(Object.assign({},x0),r)}render(t){let r=t.map(n=>{let i;return n.blocks.length?i=this.generateFileHtml(n):i=this.generateEmptyDiff(),this.makeFileDiffHtml(n,i)}).join(`
+`);return this.hoganUtils.render(Ql,"wrapper",{colorScheme:eo(this.config.colorScheme),content:r})}makeFileDiffHtml(t,r){if(this.config.renderNothingWhenEmpty&&Array.isArray(t.blocks)&&t.blocks.length===0)return"";let n=this.hoganUtils.template(AC,"file-diff"),i=this.hoganUtils.template(Ql,"file-path"),a=this.hoganUtils.template(DB,"file"),s=this.hoganUtils.template(NB,ro(t));return n.render({file:t,fileHtmlId:to(t),diffs:r,filePath:i.render({fileDiffName:ka(t)},{fileIcon:a,fileTag:s})})}generateEmptyDiff(){return this.hoganUtils.render(Ql,"empty-diff",{contentClass:"d2h-code-line",CSSLineClass:Et})}generateFileHtml(t){let r=Js(Ks(n=>jr(n.content,t.isCombined).content));return t.blocks.map(n=>{let i=this.hoganUtils.render(Ql,"block-header",{CSSLineClass:Et,blockHeader:t.isTooBig?n.header:Li(n.header),lineClass:"d2h-code-linenumber",contentClass:"d2h-code-line"});return this.applyLineGroupping(n).forEach(([a,s,o])=>{if(s.length&&o.length&&!a.length)this.applyRematchMatching(s,o,r).map(([c,l])=>{let{left:u,right:f}=this.processChangedLines(t,t.isCombined,c,l);i+=u,i+=f});else if(a.length)a.forEach(c=>{let{prefix:l,content:u}=jr(c.content,t.isCombined);i+=this.generateSingleLineHtml(t,{type:Et.CONTEXT,prefix:l,content:u,oldNumber:c.oldNumber,newNumber:c.newNumber})});else if(s.length||o.length){let{left:c,right:l}=this.processChangedLines(t,t.isCombined,s,o);i+=c,i+=l}else console.error("Unknown state reached while processing groups of lines",a,s,o)}),i}).join(`
+`)}applyLineGroupping(t){let r=[],n=[],i=[];for(let a=0;a0)&&(r.push([[],n,i]),n=[],i=[]),s.type===He.CONTEXT?r.push([[s],[],[]]):s.type===He.INSERT&&n.length===0?r.push([[],[],[s]]):s.type===He.INSERT&&n.length>0?i.push(s):s.type===He.DELETE&&n.push(s)}return(n.length||i.length)&&(r.push([[],n,i]),n=[],i=[]),r}applyRematchMatching(t,r,n){let i=t.length*r.length,a=Math.max.apply(null,[0].concat(t.concat(r).map(o=>o.content.length)));return i{let i;return n.blocks.length?i=this.generateFileHtml(n):i=this.generateEmptyDiff(),this.makeFileDiffHtml(n,i)}).join(`
+`);return this.hoganUtils.render(tc,"wrapper",{colorScheme:eo(this.config.colorScheme),content:r})}makeFileDiffHtml(t,r){if(this.config.renderNothingWhenEmpty&&Array.isArray(t.blocks)&&t.blocks.length===0)return"";let n=this.hoganUtils.template(jB,"file-diff"),i=this.hoganUtils.template(tc,"file-path"),a=this.hoganUtils.template(BB,"file"),s=this.hoganUtils.template(HB,ro(t));return n.render({file:t,fileHtmlId:to(t),diffs:r,filePath:i.render({fileDiffName:ka(t)},{fileIcon:a,fileTag:s})})}generateEmptyDiff(){return{right:"",left:this.hoganUtils.render(tc,"empty-diff",{contentClass:"d2h-code-side-line",CSSLineClass:Et})}}generateFileHtml(t){let r=Js(Ks(n=>jr(n.content,t.isCombined).content));return t.blocks.map(n=>{let i={left:this.makeHeaderHtml(n.header,t),right:this.makeHeaderHtml("")};return this.applyLineGroupping(n).forEach(([a,s,o])=>{if(s.length&&o.length&&!a.length)this.applyRematchMatching(s,o,r).map(([c,l])=>{let{left:u,right:f}=this.processChangedLines(t.isCombined,c,l);i.left+=u,i.right+=f});else if(a.length)a.forEach(c=>{let{prefix:l,content:u}=jr(c.content,t.isCombined),{left:f,right:d}=this.generateLineHtml({type:Et.CONTEXT,prefix:l,content:u,number:c.oldNumber},{type:Et.CONTEXT,prefix:l,content:u,number:c.newNumber});i.left+=f,i.right+=d});else if(s.length||o.length){let{left:c,right:l}=this.processChangedLines(t.isCombined,s,o);i.left+=c,i.right+=l}else console.error("Unknown state reached while processing groups of lines",a,s,o)}),i}).reduce((n,i)=>({left:n.left+i.left,right:n.right+i.right}),{left:"",right:""})}applyLineGroupping(t){let r=[],n=[],i=[];for(let a=0;a0)&&(r.push([[],n,i]),n=[],i=[]),s.type===He.CONTEXT?r.push([[s],[],[]]):s.type===He.INSERT&&n.length===0?r.push([[],[],[s]]):s.type===He.INSERT&&n.length>0?i.push(s):s.type===He.DELETE&&n.push(s)}return(n.length||i.length)&&(r.push([[],n,i]),n=[],i=[]),r}applyRematchMatching(t,r,n){let i=t.length*r.length,a=Math.max.apply(null,[0].concat(t.concat(r).map(o=>o.content.length)));return i'),n.b(`
+`+r),n.b(' '),n.b(`
+`+r),n.b(n.rp("'),n.b(n.v(n.f("fileName",e,t,0))),n.b(""),n.b(`
+`+r),n.b(' '),n.b(`
+`+r),n.b(' '),n.b(n.v(n.f("addedLines",e,t,0))),n.b(""),n.b(`
+`+r),n.b(' '),n.b(n.v(n.f("deletedLines",e,t,0))),n.b(""),n.b(`
+`+r),n.b(" "),n.b(`
+`+r),n.b(" "),n.b(`
+`+r),n.b(""),n.fl()},partials:{"'),n.b(`
+`+r),n.b('