marimo-learn / _site /functional_programming /assets /gitGraphDiagram-NRZ2UAAF-BFAzgdY8.js
Haleshot's picture
Update course materials and assets across various sections, including functional programming, optimization, probability, and Python. Enhance HTML content and ensure consistency in asset management.
565ea71 unverified
raw
history blame
25 kB
import{p as t}from"./chunk-TMUBEWPD-BquqjOnw.js";import{I as r}from"./chunk-KFBOBJHC-B-z9SwfH.js";import{_ as e,n as o,o as n,s as a,g as s,a as i,b as c,l as d,c as h,u as m,B as $,v as l,j as y,D as g,E as p,F as u,G as x}from"./mermaid-D0MGOvVE.js";import{p as f}from"./gitGraph-YCYPL57B-GhuaekAb.js";import{s as b}from"./transform-CdY8z5kT.js";import"./index-BiV-b1K2.js";import"./step-xJWGRC3d.js";import"./main-CEaoNRsh.js";import"./_baseEach-DDZLUgL5.js";import"./_baseUniq-DUj_-ybn.js";import"./min-FhCtSWQU.js";import"./_baseMap-CoUfqKnE.js";import"./clone-DIWvwcEg.js";var w={NORMAL:0,REVERSE:1,HIGHLIGHT:2,MERGE:3,CHERRY_PICK:4},B=u.gitGraph,E=e((()=>g({...B,...p().gitGraph})),"getConfig"),v=new r((()=>{const t=E(),r=t.mainBranchName,e=t.mainBranchOrder;return{mainBranchName:r,commits:new Map,head:null,branchConfig:new Map([[r,{name:r,order:e}]]),branches:new Map([[r,null]]),currBranch:r,direction:"LR",seq:0,options:{}}}));function k(){return x({length:7})}function C(t,r){const e=Object.create(null);return t.reduce(((t,o)=>{const n=r(o);return e[n]||(e[n]=!0,t.push(o)),t}),[])}e(k,"getID"),e(C,"uniqBy");var L=e((function(t){v.records.direction=t}),"setDirection"),T=e((function(t){d.debug("options str",t),t=(t=null==t?void 0:t.trim())||"{}";try{v.records.options=JSON.parse(t)}catch(r){d.error("error while parsing gitGraph options",r.message)}}),"setOptions"),M=e((function(){return v.records.options}),"getOptions"),P=e((function(t){let r=t.msg,e=t.id;const o=t.type;let n=t.tags;d.info("commit",r,e,o,n),d.debug("Entering commit:",r,e,o,n);const a=E();e=y.sanitizeText(e,a),r=y.sanitizeText(r,a),n=null==n?void 0:n.map((t=>y.sanitizeText(t,a)));const s={id:e||v.records.seq+"-"+k(),message:r,seq:v.records.seq++,type:o??w.NORMAL,tags:n??[],parents:null==v.records.head?[]:[v.records.head.id],branch:v.records.currBranch};v.records.head=s,d.info("main branch",a.mainBranchName),v.records.commits.set(s.id,s),v.records.branches.set(v.records.currBranch,s.id),d.debug("in pushCommit "+s.id)}),"commit"),R=e((function(t){let r=t.name;const e=t.order;if(r=y.sanitizeText(r,E()),v.records.branches.has(r))throw new Error(`Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout ${r}")`);v.records.branches.set(r,null!=v.records.head?v.records.head.id:null),v.records.branchConfig.set(r,{name:r,order:e}),A(r),d.debug("in createBranch")}),"branch"),I=e((t=>{let r=t.branch,e=t.id;const o=t.type,n=t.tags,a=E();r=y.sanitizeText(r,a),e&&(e=y.sanitizeText(e,a));const s=v.records.branches.get(v.records.currBranch),i=v.records.branches.get(r),c=s?v.records.commits.get(s):void 0,h=i?v.records.commits.get(i):void 0;if(c&&h&&c.branch===r)throw new Error(`Cannot merge branch '${r}' into itself.`);if(v.records.currBranch===r){const t=new Error('Incorrect usage of "merge". Cannot merge a branch to itself');throw t.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["branch abc"]},t}if(void 0===c||!c){const t=new Error(`Incorrect usage of "merge". Current branch (${v.records.currBranch})has no commits`);throw t.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["commit"]},t}if(!v.records.branches.has(r)){const t=new Error('Incorrect usage of "merge". Branch to be merged ('+r+") does not exist");throw t.hash={text:`merge ${r}`,token:`merge ${r}`,expected:[`branch ${r}`]},t}if(void 0===h||!h){const t=new Error('Incorrect usage of "merge". Branch to be merged ('+r+") has no commits");throw t.hash={text:`merge ${r}`,token:`merge ${r}`,expected:['"commit"']},t}if(c===h){const t=new Error('Incorrect usage of "merge". Both branches have same head');throw t.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["branch abc"]},t}if(e&&v.records.commits.has(e)){const t=new Error('Incorrect usage of "merge". Commit with id:'+e+" already exists, use different custom Id");throw t.hash={text:`merge ${r} ${e} ${o} ${null==n?void 0:n.join(" ")}`,token:`merge ${r} ${e} ${o} ${null==n?void 0:n.join(" ")}`,expected:[`merge ${r} ${e}_UNIQUE ${o} ${null==n?void 0:n.join(" ")}`]},t}const m=i||"",$={id:e||`${v.records.seq}-${k()}`,message:`merged branch ${r} into ${v.records.currBranch}`,seq:v.records.seq++,parents:null==v.records.head?[]:[v.records.head.id,m],branch:v.records.currBranch,type:w.MERGE,customType:o,customId:!!e,tags:n??[]};v.records.head=$,v.records.commits.set($.id,$),v.records.branches.set(v.records.currBranch,$.id),d.debug(v.records.branches),d.debug("in mergeBranch")}),"merge"),G=e((function(t){let r=t.id,e=t.targetId,o=t.tags,n=t.parent;d.debug("Entering cherryPick:",r,e,o);const a=E();if(r=y.sanitizeText(r,a),e=y.sanitizeText(e,a),o=null==o?void 0:o.map((t=>y.sanitizeText(t,a))),n=y.sanitizeText(n,a),!r||!v.records.commits.has(r)){const t=new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');throw t.hash={text:`cherryPick ${r} ${e}`,token:`cherryPick ${r} ${e}`,expected:["cherry-pick abc"]},t}const s=v.records.commits.get(r);if(void 0===s||!s)throw new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');if(n&&(!Array.isArray(s.parents)||!s.parents.includes(n))){throw new Error("Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.")}const i=s.branch;if(s.type===w.MERGE&&!n){throw new Error("Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.")}if(!e||!v.records.commits.has(e)){if(i===v.records.currBranch){const t=new Error('Incorrect usage of "cherryPick". Source commit is already on current branch');throw t.hash={text:`cherryPick ${r} ${e}`,token:`cherryPick ${r} ${e}`,expected:["cherry-pick abc"]},t}const t=v.records.branches.get(v.records.currBranch);if(void 0===t||!t){const t=new Error(`Incorrect usage of "cherry-pick". Current branch (${v.records.currBranch})has no commits`);throw t.hash={text:`cherryPick ${r} ${e}`,token:`cherryPick ${r} ${e}`,expected:["cherry-pick abc"]},t}const a=v.records.commits.get(t);if(void 0===a||!a){const t=new Error(`Incorrect usage of "cherry-pick". Current branch (${v.records.currBranch})has no commits`);throw t.hash={text:`cherryPick ${r} ${e}`,token:`cherryPick ${r} ${e}`,expected:["cherry-pick abc"]},t}const c={id:v.records.seq+"-"+k(),message:`cherry-picked ${null==s?void 0:s.message} into ${v.records.currBranch}`,seq:v.records.seq++,parents:null==v.records.head?[]:[v.records.head.id,s.id],branch:v.records.currBranch,type:w.CHERRY_PICK,tags:o?o.filter(Boolean):[`cherry-pick:${s.id}${s.type===w.MERGE?`|parent:${n}`:""}`]};v.records.head=c,v.records.commits.set(c.id,c),v.records.branches.set(v.records.currBranch,c.id),d.debug(v.records.branches),d.debug("in cherryPick")}}),"cherryPick"),A=e((function(t){if(t=y.sanitizeText(t,E()),!v.records.branches.has(t)){const r=new Error(`Trying to checkout branch which is not yet created. (Help try using "branch ${t}")`);throw r.hash={text:`checkout ${t}`,token:`checkout ${t}`,expected:[`branch ${t}`]},r}{v.records.currBranch=t;const r=v.records.branches.get(v.records.currBranch);v.records.head=void 0!==r&&r?v.records.commits.get(r)??null:null}}),"checkout");function O(t,r,e){const o=t.indexOf(r);-1===o?t.push(e):t.splice(o,1,e)}function j(t){const r=t.reduce(((t,r)=>t.seq>r.seq?t:r),t[0]);let e="";t.forEach((function(t){e+=t===r?"\t*":"\t|"}));const o=[e,r.id,r.seq];for(const n in v.records.branches)v.records.branches.get(n)===r.id&&o.push(n);if(d.debug(o.join(" ")),r.parents&&2==r.parents.length&&r.parents[0]&&r.parents[1]){const e=v.records.commits.get(r.parents[0]);O(t,r,e),r.parents[1]&&t.push(v.records.commits.get(r.parents[1]))}else{if(0==r.parents.length)return;if(r.parents[0]){const e=v.records.commits.get(r.parents[0]);O(t,r,e)}}j(t=C(t,(t=>t.id)))}e(O,"upsert"),e(j,"prettyPrintCommitHistory");var q=e((function(){d.debug(v.records.commits);j([N()[0]])}),"prettyPrint"),H=e((function(){v.reset(),l()}),"clear"),z=e((function(){return[...v.records.branchConfig.values()].map(((t,r)=>null!==t.order&&void 0!==t.order?t:{...t,order:parseFloat(`0.${r}`)})).sort(((t,r)=>(t.order??0)-(r.order??0))).map((({name:t})=>({name:t})))}),"getBranchesAsObjArray"),S=e((function(){return v.records.branches}),"getBranches"),D=e((function(){return v.records.commits}),"getCommits"),N=e((function(){const t=[...v.records.commits.values()];return t.forEach((function(t){d.debug(t.id)})),t.sort(((t,r)=>t.seq-r.seq)),t}),"getCommitsArray"),W={commitType:w,getConfig:E,setDirection:L,setOptions:T,getOptions:M,commit:P,branch:R,merge:I,cherryPick:G,checkout:A,prettyPrint:q,clear:H,getBranchesAsObjArray:z,getBranches:S,getCommits:D,getCommitsArray:N,getCurrentBranch:e((function(){return v.records.currBranch}),"getCurrentBranch"),getDirection:e((function(){return v.records.direction}),"getDirection"),getHead:e((function(){return v.records.head}),"getHead"),setAccTitle:c,getAccTitle:i,getAccDescription:s,setAccDescription:a,setDiagramTitle:n,getDiagramTitle:o},_=e(((r,e)=>{t(r,e),r.dir&&e.setDirection(r.dir);for(const t of r.statements)F(t,e)}),"populate"),F=e(((t,r)=>{const o={Commit:e((t=>r.commit(Y(t))),"Commit"),Branch:e((t=>r.branch(K(t))),"Branch"),Merge:e((t=>r.merge(U(t))),"Merge"),Checkout:e((t=>r.checkout(V(t))),"Checkout"),CherryPicking:e((t=>r.cherryPick(J(t))),"CherryPicking")}[t.$type];o?o(t):d.error(`Unknown statement type: ${t.$type}`)}),"parseStatement"),Y=e((t=>({id:t.id,msg:t.message??"",type:void 0!==t.type?w[t.type]:w.NORMAL,tags:t.tags??void 0})),"parseCommit"),K=e((t=>({name:t.name,order:t.order??0})),"parseBranch"),U=e((t=>({branch:t.branch,id:t.id??"",type:void 0!==t.type?w[t.type]:void 0,tags:t.tags??void 0})),"parseMerge"),V=e((t=>t.branch),"parseCheckout"),J=e((t=>{var r;return{id:t.id,targetId:"",tags:0===(null==(r=t.tags)?void 0:r.length)?void 0:t.tags,parent:t.parent}}),"parseCherryPicking"),X={parse:e((async t=>{const r=await f("gitGraph",t);d.debug(r),_(r,W)}),"parse")},Q=h(),Z=null==Q?void 0:Q.gitGraph,tt=10,rt=40,et=new Map,ot=new Map,nt=new Map,at=[],st=0,it="LR",ct=e((()=>{et.clear(),ot.clear(),nt.clear(),st=0,at=[],it="LR"}),"clear"),dt=e((t=>{const r=document.createElementNS("http://www.w3.org/2000/svg","text");return("string"==typeof t?t.split(/\\n|\n|<br\s*\/?>/gi):t).forEach((t=>{const e=document.createElementNS("http://www.w3.org/2000/svg","tspan");e.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),e.setAttribute("dy","1em"),e.setAttribute("x","0"),e.setAttribute("class","row"),e.textContent=t.trim(),r.appendChild(e)})),r}),"drawText"),ht=e((t=>{let r,o,n;return"BT"===it?(o=e(((t,r)=>t<=r),"comparisonFunc"),n=1/0):(o=e(((t,r)=>t>=r),"comparisonFunc"),n=0),t.forEach((t=>{var e,a;const s="TB"===it||"BT"==it?null==(e=ot.get(t))?void 0:e.y:null==(a=ot.get(t))?void 0:a.x;void 0!==s&&o(s,n)&&(r=t,n=s)})),r}),"findClosestParent"),mt=e((t=>{let r="",e=1/0;return t.forEach((t=>{const o=ot.get(t).y;o<=e&&(r=t,e=o)})),r||void 0}),"findClosestParentBT"),$t=e(((t,r,e)=>{let o=e,n=e;const a=[];t.forEach((t=>{const e=r.get(t);if(!e)throw new Error(`Commit not found for key ${t}`);e.parents.length?(o=yt(e),n=Math.max(o,n)):a.push(e),gt(e,o)})),o=n,a.forEach((t=>{pt(t,o,e)})),t.forEach((t=>{const e=r.get(t);if(null==e?void 0:e.parents.length){const t=mt(e.parents);o=ot.get(t).y-rt,o<=n&&(n=o);const r=et.get(e.branch).pos,a=o-tt;ot.set(e.id,{x:r,y:a})}}))}),"setParallelBTPos"),lt=e((t=>{var r;const e=ht(t.parents.filter((t=>null!==t)));if(!e)throw new Error(`Closest parent not found for commit ${t.id}`);const o=null==(r=ot.get(e))?void 0:r.y;if(void 0===o)throw new Error(`Closest parent position not found for commit ${t.id}`);return o}),"findClosestParentPos"),yt=e((t=>lt(t)+rt),"calculateCommitPosition"),gt=e(((t,r)=>{const e=et.get(t.branch);if(!e)throw new Error(`Branch not found for commit ${t.id}`);const o=e.pos,n=r+tt;return ot.set(t.id,{x:o,y:n}),{x:o,y:n}}),"setCommitPosition"),pt=e(((t,r,e)=>{const o=et.get(t.branch);if(!o)throw new Error(`Branch not found for commit ${t.id}`);const n=r+e,a=o.pos;ot.set(t.id,{x:a,y:n})}),"setRootPosition"),ut=e(((t,r,e,o,n,a)=>{if(a===w.HIGHLIGHT)t.append("rect").attr("x",e.x-10).attr("y",e.y-10).attr("width",20).attr("height",20).attr("class",`commit ${r.id} commit-highlight${n%8} ${o}-outer`),t.append("rect").attr("x",e.x-6).attr("y",e.y-6).attr("width",12).attr("height",12).attr("class",`commit ${r.id} commit${n%8} ${o}-inner`);else if(a===w.CHERRY_PICK)t.append("circle").attr("cx",e.x).attr("cy",e.y).attr("r",10).attr("class",`commit ${r.id} ${o}`),t.append("circle").attr("cx",e.x-3).attr("cy",e.y+2).attr("r",2.75).attr("fill","#fff").attr("class",`commit ${r.id} ${o}`),t.append("circle").attr("cx",e.x+3).attr("cy",e.y+2).attr("r",2.75).attr("fill","#fff").attr("class",`commit ${r.id} ${o}`),t.append("line").attr("x1",e.x+3).attr("y1",e.y+1).attr("x2",e.x).attr("y2",e.y-5).attr("stroke","#fff").attr("class",`commit ${r.id} ${o}`),t.append("line").attr("x1",e.x-3).attr("y1",e.y+1).attr("x2",e.x).attr("y2",e.y-5).attr("stroke","#fff").attr("class",`commit ${r.id} ${o}`);else{const s=t.append("circle");if(s.attr("cx",e.x),s.attr("cy",e.y),s.attr("r",r.type===w.MERGE?9:10),s.attr("class",`commit ${r.id} commit${n%8}`),a===w.MERGE){const a=t.append("circle");a.attr("cx",e.x),a.attr("cy",e.y),a.attr("r",6),a.attr("class",`commit ${o} ${r.id} commit${n%8}`)}if(a===w.REVERSE){t.append("path").attr("d",`M ${e.x-5},${e.y-5}L${e.x+5},${e.y+5}M${e.x-5},${e.y+5}L${e.x+5},${e.y-5}`).attr("class",`commit ${o} ${r.id} commit${n%8}`)}}}),"drawCommitBullet"),xt=e(((t,r,e,o)=>{var n;if(r.type!==w.CHERRY_PICK&&(r.customId&&r.type===w.MERGE||r.type!==w.MERGE)&&(null==Z?void 0:Z.showCommitLabel)){const a=t.append("g"),s=a.insert("rect").attr("class","commit-label-bkg"),i=a.append("text").attr("x",o).attr("y",e.y+25).attr("class","commit-label").text(r.id),c=null==(n=i.node())?void 0:n.getBBox();if(c&&(s.attr("x",e.posWithOffset-c.width/2-2).attr("y",e.y+13.5).attr("width",c.width+4).attr("height",c.height+4),"TB"===it||"BT"===it?(s.attr("x",e.x-(c.width+16+5)).attr("y",e.y-12),i.attr("x",e.x-(c.width+16)).attr("y",e.y+c.height-12)):i.attr("x",e.posWithOffset-c.width/2),Z.rotateCommitLabel))if("TB"===it||"BT"===it)i.attr("transform","rotate(-45, "+e.x+", "+e.y+")"),s.attr("transform","rotate(-45, "+e.x+", "+e.y+")");else{const t=-7.5-(c.width+10)/25*9.5,r=10+c.width/25*8.5;a.attr("transform","translate("+t+", "+r+") rotate(-45, "+o+", "+e.y+")")}}}),"drawCommitLabel"),ft=e(((t,r,e,o)=>{var n;if(r.tags.length>0){let a=0,s=0,i=0;const c=[];for(const o of r.tags.reverse()){const r=t.insert("polygon"),d=t.append("circle"),h=t.append("text").attr("y",e.y-16-a).attr("class","tag-label").text(o),m=null==(n=h.node())?void 0:n.getBBox();if(!m)throw new Error("Tag bbox not found");s=Math.max(s,m.width),i=Math.max(i,m.height),h.attr("x",e.posWithOffset-m.width/2),c.push({tag:h,hole:d,rect:r,yOffset:a}),a+=20}for(const{tag:t,hole:r,rect:n,yOffset:d}of c){const a=i/2,c=e.y-19.2-d;if(n.attr("class","tag-label-bkg").attr("points",`\n ${o-s/2-2},${c+2} \n ${o-s/2-2},${c-2}\n ${e.posWithOffset-s/2-4},${c-a-2}\n ${e.posWithOffset+s/2+4},${c-a-2}\n ${e.posWithOffset+s/2+4},${c+a+2}\n ${e.posWithOffset-s/2-4},${c+a+2}`),r.attr("cy",c).attr("cx",o-s/2+2).attr("r",1.5).attr("class","tag-hole"),"TB"===it||"BT"===it){const i=o+d;n.attr("class","tag-label-bkg").attr("points",`\n ${e.x},${i+2}\n ${e.x},${i-2}\n ${e.x+tt},${i-a-2}\n ${e.x+tt+s+4},${i-a-2}\n ${e.x+tt+s+4},${i+a+2}\n ${e.x+tt},${i+a+2}`).attr("transform","translate(12,12) rotate(45, "+e.x+","+o+")"),r.attr("cx",e.x+2).attr("cy",i).attr("transform","translate(12,12) rotate(45, "+e.x+","+o+")"),t.attr("x",e.x+5).attr("y",i+3).attr("transform","translate(14,14) rotate(45, "+e.x+","+o+")")}}}}),"drawCommitTags"),bt=e((t=>{switch(t.customType??t.type){case w.NORMAL:return"commit-normal";case w.REVERSE:return"commit-reverse";case w.HIGHLIGHT:return"commit-highlight";case w.MERGE:return"commit-merge";case w.CHERRY_PICK:return"commit-cherry-pick";default:return"commit-normal"}}),"getCommitClassType"),wt=e(((t,r,e,o)=>{const n={x:0,y:0};if(!(t.parents.length>0)){if("TB"===r)return 30;if("BT"===r){return(o.get(t.id)??n).y-rt}return 0}{const e=ht(t.parents);if(e){const a=o.get(e)??n;if("TB"===r)return a.y+rt;if("BT"===r){return(o.get(t.id)??n).y-rt}return a.x+rt}}return 0}),"calculatePosition"),Bt=e(((t,r,e)=>{var o,n;const a="BT"===it&&e?r:r+tt,s="TB"===it||"BT"===it?a:null==(o=et.get(t.branch))?void 0:o.pos,i="TB"===it||"BT"===it?null==(n=et.get(t.branch))?void 0:n.pos:a;if(void 0===i||void 0===s)throw new Error(`Position were undefined for commit ${t.id}`);return{x:i,y:s,posWithOffset:a}}),"getCommitPosition"),Et=e(((t,r,o)=>{if(!Z)throw new Error("GitGraph config not found");const n=t.append("g").attr("class","commit-bullets"),a=t.append("g").attr("class","commit-labels");let s="TB"===it||"BT"===it?30:0;const i=[...r.keys()],c=(null==Z?void 0:Z.parallelCommits)??!1,d=e(((t,e)=>{var o,n;const a=null==(o=r.get(t))?void 0:o.seq,s=null==(n=r.get(e))?void 0:n.seq;return void 0!==a&&void 0!==s?a-s:0}),"sortKeys");let h=i.sort(d);"BT"===it&&(c&&$t(h,r,s),h=h.reverse()),h.forEach((t=>{var e;const i=r.get(t);if(!i)throw new Error(`Commit not found for key ${t}`);c&&(s=wt(i,it,s,ot));const d=Bt(i,s,c);if(o){const t=bt(i),r=i.customType??i.type,o=(null==(e=et.get(i.branch))?void 0:e.index)??0;ut(n,i,d,t,o,r),xt(a,i,d,s),ft(a,i,d,s)}"TB"===it||"BT"===it?ot.set(i.id,{x:d.x,y:d.posWithOffset}):ot.set(i.id,{x:d.posWithOffset,y:d.y}),s="BT"===it&&c?s+rt:s+rt+tt,s>st&&(st=s)}))}),"drawCommits"),vt=e(((t,r,o,n,a)=>{const s=("TB"===it||"BT"===it?o.x<n.x:o.y<n.y)?r.branch:t.branch,i=e((t=>t.branch===s),"isOnBranchToGetCurve"),c=e((e=>e.seq>t.seq&&e.seq<r.seq),"isBetweenCommits");return[...a.values()].some((t=>c(t)&&i(t)))}),"shouldRerouteArrow"),kt=e(((t,r,e=0)=>{const o=t+Math.abs(t-r)/2;if(e>5)return o;if(at.every((t=>Math.abs(t-o)>=10)))return at.push(o),o;const n=Math.abs(t-r);return kt(t,r-n/5,e+1)}),"findLane"),Ct=e(((t,r,e,o)=>{var n,a,s,i,c;const d=ot.get(r.id),h=ot.get(e.id);if(void 0===d||void 0===h)throw new Error(`Commit positions not found for commits ${r.id} and ${e.id}`);const m=vt(r,e,d,h,o);let $,l="",y="",g=0,p=0,u=null==(n=et.get(e.branch))?void 0:n.index;if(e.type===w.MERGE&&r.id!==e.parents[0]&&(u=null==(a=et.get(r.branch))?void 0:a.index),m){l="A 10 10, 0, 0, 0,",y="A 10 10, 0, 0, 1,",g=10,p=10;const t=d.y<h.y?kt(d.y,h.y):kt(h.y,d.y),e=d.x<h.x?kt(d.x,h.x):kt(h.x,d.x);"TB"===it?d.x<h.x?$=`M ${d.x} ${d.y} L ${e-g} ${d.y} ${y} ${e} ${d.y+p} L ${e} ${h.y-g} ${l} ${e+p} ${h.y} L ${h.x} ${h.y}`:(u=null==(s=et.get(r.branch))?void 0:s.index,$=`M ${d.x} ${d.y} L ${e+g} ${d.y} ${l} ${e} ${d.y+p} L ${e} ${h.y-g} ${y} ${e-p} ${h.y} L ${h.x} ${h.y}`):"BT"===it?d.x<h.x?$=`M ${d.x} ${d.y} L ${e-g} ${d.y} ${l} ${e} ${d.y-p} L ${e} ${h.y+g} ${y} ${e+p} ${h.y} L ${h.x} ${h.y}`:(u=null==(i=et.get(r.branch))?void 0:i.index,$=`M ${d.x} ${d.y} L ${e+g} ${d.y} ${y} ${e} ${d.y-p} L ${e} ${h.y+g} ${l} ${e-p} ${h.y} L ${h.x} ${h.y}`):d.y<h.y?$=`M ${d.x} ${d.y} L ${d.x} ${t-g} ${l} ${d.x+p} ${t} L ${h.x-g} ${t} ${y} ${h.x} ${t+p} L ${h.x} ${h.y}`:(u=null==(c=et.get(r.branch))?void 0:c.index,$=`M ${d.x} ${d.y} L ${d.x} ${t+g} ${y} ${d.x+p} ${t} L ${h.x-g} ${t} ${l} ${h.x} ${t-p} L ${h.x} ${h.y}`)}else l="A 20 20, 0, 0, 0,",y="A 20 20, 0, 0, 1,",g=20,p=20,"TB"===it?(d.x<h.x&&($=e.type===w.MERGE&&r.id!==e.parents[0]?`M ${d.x} ${d.y} L ${d.x} ${h.y-g} ${l} ${d.x+p} ${h.y} L ${h.x} ${h.y}`:`M ${d.x} ${d.y} L ${h.x-g} ${d.y} ${y} ${h.x} ${d.y+p} L ${h.x} ${h.y}`),d.x>h.x&&(l="A 20 20, 0, 0, 0,",y="A 20 20, 0, 0, 1,",g=20,p=20,$=e.type===w.MERGE&&r.id!==e.parents[0]?`M ${d.x} ${d.y} L ${d.x} ${h.y-g} ${y} ${d.x-p} ${h.y} L ${h.x} ${h.y}`:`M ${d.x} ${d.y} L ${h.x+g} ${d.y} ${l} ${h.x} ${d.y+p} L ${h.x} ${h.y}`),d.x===h.x&&($=`M ${d.x} ${d.y} L ${h.x} ${h.y}`)):"BT"===it?(d.x<h.x&&($=e.type===w.MERGE&&r.id!==e.parents[0]?`M ${d.x} ${d.y} L ${d.x} ${h.y+g} ${y} ${d.x+p} ${h.y} L ${h.x} ${h.y}`:`M ${d.x} ${d.y} L ${h.x-g} ${d.y} ${l} ${h.x} ${d.y-p} L ${h.x} ${h.y}`),d.x>h.x&&(l="A 20 20, 0, 0, 0,",y="A 20 20, 0, 0, 1,",g=20,p=20,$=e.type===w.MERGE&&r.id!==e.parents[0]?`M ${d.x} ${d.y} L ${d.x} ${h.y+g} ${l} ${d.x-p} ${h.y} L ${h.x} ${h.y}`:`M ${d.x} ${d.y} L ${h.x-g} ${d.y} ${l} ${h.x} ${d.y-p} L ${h.x} ${h.y}`),d.x===h.x&&($=`M ${d.x} ${d.y} L ${h.x} ${h.y}`)):(d.y<h.y&&($=e.type===w.MERGE&&r.id!==e.parents[0]?`M ${d.x} ${d.y} L ${h.x-g} ${d.y} ${y} ${h.x} ${d.y+p} L ${h.x} ${h.y}`:`M ${d.x} ${d.y} L ${d.x} ${h.y-g} ${l} ${d.x+p} ${h.y} L ${h.x} ${h.y}`),d.y>h.y&&($=e.type===w.MERGE&&r.id!==e.parents[0]?`M ${d.x} ${d.y} L ${h.x-g} ${d.y} ${l} ${h.x} ${d.y-p} L ${h.x} ${h.y}`:`M ${d.x} ${d.y} L ${d.x} ${h.y+g} ${y} ${d.x+p} ${h.y} L ${h.x} ${h.y}`),d.y===h.y&&($=`M ${d.x} ${d.y} L ${h.x} ${h.y}`));if(void 0===$)throw new Error("Line definition not found");t.append("path").attr("d",$).attr("class","arrow arrow"+u%8)}),"drawArrow"),Lt=e(((t,r)=>{const e=t.append("g").attr("class","commit-arrows");[...r.keys()].forEach((t=>{const o=r.get(t);o.parents&&o.parents.length>0&&o.parents.forEach((t=>{Ct(e,r.get(t),o,r)}))}))}),"drawArrows"),Tt=e(((t,r)=>{const e=t.append("g");r.forEach(((t,r)=>{var o;const n=r%8,a=null==(o=et.get(t.name))?void 0:o.pos;if(void 0===a)throw new Error(`Position not found for branch ${t.name}`);const s=e.append("line");s.attr("x1",0),s.attr("y1",a),s.attr("x2",st),s.attr("y2",a),s.attr("class","branch branch"+n),"TB"===it?(s.attr("y1",30),s.attr("x1",a),s.attr("y2",st),s.attr("x2",a)):"BT"===it&&(s.attr("y1",st),s.attr("x1",a),s.attr("y2",30),s.attr("x2",a)),at.push(a);const i=t.name,c=dt(i),d=e.insert("rect"),h=e.insert("g").attr("class","branchLabel").insert("g").attr("class","label branch-label"+n);h.node().appendChild(c);const m=c.getBBox();d.attr("class","branchLabelBkg label"+n).attr("rx",4).attr("ry",4).attr("x",-m.width-4-(!0===(null==Z?void 0:Z.rotateCommitLabel)?30:0)).attr("y",-m.height/2+8).attr("width",m.width+18).attr("height",m.height+4),h.attr("transform","translate("+(-m.width-14-(!0===(null==Z?void 0:Z.rotateCommitLabel)?30:0))+", "+(a-m.height/2-1)+")"),"TB"===it?(d.attr("x",a-m.width/2-10).attr("y",0),h.attr("transform","translate("+(a-m.width/2-5)+", 0)")):"BT"===it?(d.attr("x",a-m.width/2-10).attr("y",st),h.attr("transform","translate("+(a-m.width/2-5)+", "+st+")")):d.attr("transform","translate(-19, "+(a-m.height/2)+")")}))}),"drawBranches"),Mt=e((function(t,r,e,o,n){return et.set(t,{pos:r,index:e}),r+=50+(n?40:0)+("TB"===it||"BT"===it?o.width/2:0)}),"setBranchPosition"),Pt={parser:X,db:W,renderer:{draw:e((function(t,r,e,o){if(ct(),d.debug("in gitgraph renderer",t+"\n","id:",r,e),!Z)throw new Error("GitGraph config not found");const n=Z.rotateCommitLabel??!1,a=o.db;nt=a.getCommits();const s=a.getBranchesAsObjArray();it=a.getDirection();const i=b(`[id="${r}"]`);let c=0;s.forEach(((t,r)=>{var e;const o=dt(t.name),a=i.append("g"),s=a.insert("g").attr("class","branchLabel"),d=s.insert("g").attr("class","label branch-label");null==(e=d.node())||e.appendChild(o);const h=o.getBBox();c=Mt(t.name,c,r,h,n),d.remove(),s.remove(),a.remove()})),Et(i,nt,!1),Z.showBranches&&Tt(i,s),Lt(i,nt),Et(i,nt,!0),m.insertTitle(i,"gitTitleText",Z.titleTopMargin??0,a.getDiagramTitle()),$(void 0,i,Z.diagramPadding,Z.useMaxWidth)}),"draw")},styles:e((t=>`\n .commit-id,\n .commit-msg,\n .branch-label {\n fill: lightgrey;\n color: lightgrey;\n font-family: 'trebuchet ms', verdana, arial, sans-serif;\n font-family: var(--mermaid-font-family);\n }\n ${[0,1,2,3,4,5,6,7].map((r=>`\n .branch-label${r} { fill: ${t["gitBranchLabel"+r]}; }\n .commit${r} { stroke: ${t["git"+r]}; fill: ${t["git"+r]}; }\n .commit-highlight${r} { stroke: ${t["gitInv"+r]}; fill: ${t["gitInv"+r]}; }\n .label${r} { fill: ${t["git"+r]}; }\n .arrow${r} { stroke: ${t["git"+r]}; }\n `)).join("\n")}\n\n .branch {\n stroke-width: 1;\n stroke: ${t.lineColor};\n stroke-dasharray: 2;\n }\n .commit-label { font-size: ${t.commitLabelFontSize}; fill: ${t.commitLabelColor};}\n .commit-label-bkg { font-size: ${t.commitLabelFontSize}; fill: ${t.commitLabelBackground}; opacity: 0.5; }\n .tag-label { font-size: ${t.tagLabelFontSize}; fill: ${t.tagLabelColor};}\n .tag-label-bkg { fill: ${t.tagLabelBackground}; stroke: ${t.tagLabelBorder}; }\n .tag-hole { fill: ${t.textColor}; }\n\n .commit-merge {\n stroke: ${t.primaryColor};\n fill: ${t.primaryColor};\n }\n .commit-reverse {\n stroke: ${t.primaryColor};\n fill: ${t.primaryColor};\n stroke-width: 3;\n }\n .commit-highlight-outer {\n }\n .commit-highlight-inner {\n stroke: ${t.primaryColor};\n fill: ${t.primaryColor};\n }\n\n .arrow { stroke-width: 8; stroke-linecap: round; fill: none}\n .gitTitleText {\n text-anchor: middle;\n font-size: 18px;\n fill: ${t.textColor};\n }\n`),"getStyles")};export{Pt as diagram};