UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

107 lines (102 loc) 30.3 kB
const ie=require("./mermaid-parser.core-DYumW1vq.cjs"),l=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),w=require("./src-C9EhKhbk.cjs"),_=require("./chunk-WYO6CB5R-u4mJNOcO.cjs"),X=require("./chunk-ICXQ74PX-BbT9JaEW.cjs"),de=require("./chunk-JWPE2WC7-D8EnWK1B.cjs"),le=require("./chunk-2Q5K7J3B-CTMy5FII.cjs");var x={NORMAL:0,REVERSE:1,HIGHLIGHT:2,MERGE:3,CHERRY_PICK:4},he=_.defaultConfig_default.gitGraph,H=l.__name(()=>X.cleanAndMerge({...he,..._.getConfig().gitGraph}),"getConfig"),d=new le.ImperativeState(()=>{const e=H(),r=e.mainBranchName,t=e.mainBranchOrder;return{mainBranchName:r,commits:new Map,head:null,branchConfig:new Map([[r,{name:r,order:t}]]),branches:new Map([[r,null]]),currBranch:r,direction:"LR",seq:0,options:{}}});function Y(){return X.random({length:7})}l.__name(Y,"getID");function ee(e,r){const t=Object.create(null);return e.reduce((o,s)=>{const c=r(s);return t[c]||(t[c]=!0,o.push(s)),o},[])}l.__name(ee,"uniqBy");var $e=l.__name(function(e){d.records.direction=e},"setDirection"),fe=l.__name(function(e){w.log.debug("options str",e),e=e?.trim(),e=e||"{}";try{d.records.options=JSON.parse(e)}catch(r){w.log.error("error while parsing gitGraph options",r.message)}},"setOptions"),ge=l.__name(function(){return d.records.options},"getOptions"),ue=l.__name(function(e){let r=e.msg,t=e.id;const o=e.type;let s=e.tags;w.log.info("commit",r,t,o,s),w.log.debug("Entering commit:",r,t,o,s);const c=H();t=_.common_default.sanitizeText(t,c),r=_.common_default.sanitizeText(r,c),s=s?.map(n=>_.common_default.sanitizeText(n,c));const a={id:t||d.records.seq+"-"+Y(),message:r,seq:d.records.seq++,type:o??x.NORMAL,tags:s??[],parents:d.records.head==null?[]:[d.records.head.id],branch:d.records.currBranch};d.records.head=a,w.log.info("main branch",c.mainBranchName),d.records.commits.has(a.id)&&w.log.warn(`Commit ID ${a.id} already exists`),d.records.commits.set(a.id,a),d.records.branches.set(d.records.currBranch,a.id),w.log.debug("in pushCommit "+a.id)},"commit"),me=l.__name(function(e){let r=e.name;const t=e.order;if(r=_.common_default.sanitizeText(r,H()),d.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}")`);d.records.branches.set(r,d.records.head!=null?d.records.head.id:null),d.records.branchConfig.set(r,{name:r,order:t}),re(r),w.log.debug("in createBranch")},"branch"),ye=l.__name(e=>{let r=e.branch,t=e.id;const o=e.type,s=e.tags,c=H();r=_.common_default.sanitizeText(r,c),t&&(t=_.common_default.sanitizeText(t,c));const a=d.records.branches.get(d.records.currBranch),n=d.records.branches.get(r),$=a?d.records.commits.get(a):void 0,f=n?d.records.commits.get(n):void 0;if($&&f&&$.branch===r)throw new Error(`Cannot merge branch '${r}' into itself.`);if(d.records.currBranch===r){const i=new Error('Incorrect usage of "merge". Cannot merge a branch to itself');throw i.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["branch abc"]},i}if($===void 0||!$){const i=new Error(`Incorrect usage of "merge". Current branch (${d.records.currBranch})has no commits`);throw i.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["commit"]},i}if(!d.records.branches.has(r)){const i=new Error('Incorrect usage of "merge". Branch to be merged ('+r+") does not exist");throw i.hash={text:`merge ${r}`,token:`merge ${r}`,expected:[`branch ${r}`]},i}if(f===void 0||!f){const i=new Error('Incorrect usage of "merge". Branch to be merged ('+r+") has no commits");throw i.hash={text:`merge ${r}`,token:`merge ${r}`,expected:['"commit"']},i}if($===f){const i=new Error('Incorrect usage of "merge". Both branches have same head');throw i.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["branch abc"]},i}if(t&&d.records.commits.has(t)){const i=new Error('Incorrect usage of "merge". Commit with id:'+t+" already exists, use different custom id");throw i.hash={text:`merge ${r} ${t} ${o} ${s?.join(" ")}`,token:`merge ${r} ${t} ${o} ${s?.join(" ")}`,expected:[`merge ${r} ${t}_UNIQUE ${o} ${s?.join(" ")}`]},i}const g=n||"",h={id:t||`${d.records.seq}-${Y()}`,message:`merged branch ${r} into ${d.records.currBranch}`,seq:d.records.seq++,parents:d.records.head==null?[]:[d.records.head.id,g],branch:d.records.currBranch,type:x.MERGE,customType:o,customId:!!t,tags:s??[]};d.records.head=h,d.records.commits.set(h.id,h),d.records.branches.set(d.records.currBranch,h.id),w.log.debug(d.records.branches),w.log.debug("in mergeBranch")},"merge"),xe=l.__name(function(e){let r=e.id,t=e.targetId,o=e.tags,s=e.parent;w.log.debug("Entering cherryPick:",r,t,o);const c=H();if(r=_.common_default.sanitizeText(r,c),t=_.common_default.sanitizeText(t,c),o=o?.map($=>_.common_default.sanitizeText($,c)),s=_.common_default.sanitizeText(s,c),!r||!d.records.commits.has(r)){const $=new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');throw $.hash={text:`cherryPick ${r} ${t}`,token:`cherryPick ${r} ${t}`,expected:["cherry-pick abc"]},$}const a=d.records.commits.get(r);if(a===void 0||!a)throw new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');if(s&&!(Array.isArray(a.parents)&&a.parents.includes(s)))throw new Error("Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.");const n=a.branch;if(a.type===x.MERGE&&!s)throw new Error("Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.");if(!t||!d.records.commits.has(t)){if(n===d.records.currBranch){const h=new Error('Incorrect usage of "cherryPick". Source commit is already on current branch');throw h.hash={text:`cherryPick ${r} ${t}`,token:`cherryPick ${r} ${t}`,expected:["cherry-pick abc"]},h}const $=d.records.branches.get(d.records.currBranch);if($===void 0||!$){const h=new Error(`Incorrect usage of "cherry-pick". Current branch (${d.records.currBranch})has no commits`);throw h.hash={text:`cherryPick ${r} ${t}`,token:`cherryPick ${r} ${t}`,expected:["cherry-pick abc"]},h}const f=d.records.commits.get($);if(f===void 0||!f){const h=new Error(`Incorrect usage of "cherry-pick". Current branch (${d.records.currBranch})has no commits`);throw h.hash={text:`cherryPick ${r} ${t}`,token:`cherryPick ${r} ${t}`,expected:["cherry-pick abc"]},h}const g={id:d.records.seq+"-"+Y(),message:`cherry-picked ${a?.message} into ${d.records.currBranch}`,seq:d.records.seq++,parents:d.records.head==null?[]:[d.records.head.id,a.id],branch:d.records.currBranch,type:x.CHERRY_PICK,tags:o?o.filter(Boolean):[`cherry-pick:${a.id}${a.type===x.MERGE?`|parent:${s}`:""}`]};d.records.head=g,d.records.commits.set(g.id,g),d.records.branches.set(d.records.currBranch,g.id),w.log.debug(d.records.branches),w.log.debug("in cherryPick")}},"cherryPick"),re=l.__name(function(e){if(e=_.common_default.sanitizeText(e,H()),d.records.branches.has(e)){d.records.currBranch=e;const r=d.records.branches.get(d.records.currBranch);r===void 0||!r?d.records.head=null:d.records.head=d.records.commits.get(r)??null}else{const r=new Error(`Trying to checkout branch which is not yet created. (Help try using "branch ${e}")`);throw r.hash={text:`checkout ${e}`,token:`checkout ${e}`,expected:[`branch ${e}`]},r}},"checkout");function U(e,r,t){const o=e.indexOf(r);o===-1?e.push(t):e.splice(o,1,t)}l.__name(U,"upsert");function J(e){const r=e.reduce((s,c)=>s.seq>c.seq?s:c,e[0]);let t="";e.forEach(function(s){s===r?t+=" *":t+=" |"});const o=[t,r.id,r.seq];for(const s in d.records.branches)d.records.branches.get(s)===r.id&&o.push(s);if(w.log.debug(o.join(" ")),r.parents&&r.parents.length==2&&r.parents[0]&&r.parents[1]){const s=d.records.commits.get(r.parents[0]);U(e,r,s),r.parents[1]&&e.push(d.records.commits.get(r.parents[1]))}else{if(r.parents.length==0)return;if(r.parents[0]){const s=d.records.commits.get(r.parents[0]);U(e,r,s)}}e=ee(e,s=>s.id),J(e)}l.__name(J,"prettyPrintCommitHistory");var _e=l.__name(function(){w.log.debug(d.records.commits);const e=te()[0];J([e])},"prettyPrint"),pe=l.__name(function(){d.reset(),_.clear()},"clear"),be=l.__name(function(){return[...d.records.branchConfig.values()].map((e,r)=>e.order!==null&&e.order!==void 0?e:{...e,order:parseFloat(`0.${r}`)}).sort((e,r)=>(e.order??0)-(r.order??0)).map(({name:e})=>({name:e}))},"getBranchesAsObjArray"),we=l.__name(function(){return d.records.branches},"getBranches"),ke=l.__name(function(){return d.records.commits},"getCommits"),te=l.__name(function(){const e=[...d.records.commits.values()];return e.forEach(function(r){w.log.debug(r.id)}),e.sort((r,t)=>r.seq-t.seq),e},"getCommitsArray"),ae={commitType:x,getConfig:H,setDirection:$e,setOptions:fe,getOptions:ge,commit:ue,branch:me,merge:ye,cherryPick:xe,checkout:re,prettyPrint:_e,clear:pe,getBranchesAsObjArray:be,getBranches:we,getCommits:ke,getCommitsArray:te,getCurrentBranch:l.__name(function(){return d.records.currBranch},"getCurrentBranch"),getDirection:l.__name(function(){return d.records.direction},"getDirection"),getHead:l.__name(function(){return d.records.head},"getHead"),setAccTitle:_.setAccTitle,getAccTitle:_.getAccTitle,getAccDescription:_.getAccDescription,setAccDescription:_.setAccDescription,setDiagramTitle:_.setDiagramTitle,getDiagramTitle:_.getDiagramTitle},Ce=l.__name((e,r)=>{de.populateCommonDb(e,r),e.dir&&r.setDirection(e.dir);for(const t of e.statements)Ee(t,r)},"populate"),Ee=l.__name((e,r)=>{const t={Commit:l.__name(o=>r.commit(ve(o)),"Commit"),Branch:l.__name(o=>r.branch(Te(o)),"Branch"),Merge:l.__name(o=>r.merge(Be(o)),"Merge"),Checkout:l.__name(o=>r.checkout(Le(o)),"Checkout"),CherryPicking:l.__name(o=>r.cherryPick(Me(o)),"CherryPicking")}[e.$type];t?t(e):w.log.error(`Unknown statement type: ${e.$type}`)},"parseStatement"),ve=l.__name(e=>({id:e.id,msg:e.message??"",type:e.type!==void 0?x[e.type]:x.NORMAL,tags:e.tags??void 0}),"parseCommit"),Te=l.__name(e=>({name:e.name,order:e.order??0}),"parseBranch"),Be=l.__name(e=>({branch:e.branch,id:e.id??"",type:e.type!==void 0?x[e.type]:void 0,tags:e.tags??void 0}),"parseMerge"),Le=l.__name(e=>e.branch,"parseCheckout"),Me=l.__name(e=>({id:e.id,targetId:"",tags:e.tags?.length===0?void 0:e.tags,parent:e.parent}),"parseCherryPicking"),Re={parse:l.__name(async e=>{const r=await ie.parse("gitGraph",e);w.log.debug(r),Ce(r,ae)},"parse")},I=10,O=40,B=4,M=2,G=8,j=new Set(["redux","redux-dark","redux-color","redux-dark-color"]),V=12,Q=new Set(["redux-color","redux-dark-color"]),Ie=new Set(["dark","redux-dark","redux-dark-color","neo-dark"]),q=l.__name((e,r,t=!1)=>t&&e>0?(e-1)%(r-1)+1:e%r,"calcColorIndex"),E=new Map,v=new Map,F=30,W=new Map,P=[],R=0,m="LR",Oe=l.__name(()=>{E.clear(),v.clear(),W.clear(),R=0,P=[],m="LR"},"clear"),ne=l.__name(e=>{const r=document.createElementNS("http://www.w3.org/2000/svg","text");return(typeof e=="string"?e.split(/\\n|\n|<br\s*\/?>/gi):e).forEach(t=>{const o=document.createElementNS("http://www.w3.org/2000/svg","tspan");o.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),o.setAttribute("dy","1em"),o.setAttribute("x","0"),o.setAttribute("class","row"),o.textContent=t.trim(),r.appendChild(o)}),r},"drawText"),oe=l.__name(e=>{let r,t,o;return m==="BT"?(t=l.__name((s,c)=>s<=c,"comparisonFunc"),o=1/0):(t=l.__name((s,c)=>s>=c,"comparisonFunc"),o=0),e.forEach(s=>{const c=m==="TB"||m=="BT"?v.get(s)?.y:v.get(s)?.x;c!==void 0&&t(c,o)&&(r=s,o=c)}),r},"findClosestParent"),Ge=l.__name(e=>{let r="",t=1/0;return e.forEach(o=>{const s=v.get(o).y;s<=t&&(r=o,t=s)}),r||void 0},"findClosestParentBT"),qe=l.__name((e,r,t)=>{let o=t,s=t;const c=[];e.forEach(a=>{const n=r.get(a);if(!n)throw new Error(`Commit not found for key ${a}`);n.parents.length?(o=Ae(n),s=Math.max(o,s)):c.push(n),Se(n,o)}),o=s,c.forEach(a=>{We(a,o,t)}),e.forEach(a=>{const n=r.get(a);if(n?.parents.length){const $=Ge(n.parents);o=v.get($).y-O,o<=s&&(s=o);const f=E.get(n.branch).pos,g=o-I;v.set(n.id,{x:f,y:g})}})},"setParallelBTPos"),He=l.__name(e=>{const r=oe(e.parents.filter(o=>o!==null));if(!r)throw new Error(`Closest parent not found for commit ${e.id}`);const t=v.get(r)?.y;if(t===void 0)throw new Error(`Closest parent position not found for commit ${e.id}`);return t},"findClosestParentPos"),Ae=l.__name(e=>He(e)+O,"calculateCommitPosition"),Se=l.__name((e,r)=>{const t=E.get(e.branch);if(!t)throw new Error(`Branch not found for commit ${e.id}`);const o=t.pos,s=r+I;return v.set(e.id,{x:o,y:s}),{x:o,y:s}},"setCommitPosition"),We=l.__name((e,r,t)=>{const o=E.get(e.branch);if(!o)throw new Error(`Branch not found for commit ${e.id}`);const s=r+t,c=o.pos;v.set(e.id,{x:c,y:s})},"setRootPosition"),De=l.__name((e,r,t,o,s,c)=>{const{theme:a}=_.getConfig2(),n=j.has(a??""),$=Q.has(a??""),f=Ie.has(a??"");if(c===x.HIGHLIGHT)e.append("rect").attr("x",t.x-10+(n?3:0)).attr("y",t.y-10+(n?3:0)).attr("width",n?14:20).attr("height",n?14:20).attr("class",`commit ${r.id} commit-highlight${q(s,G,$)} ${o}-outer`),e.append("rect").attr("x",t.x-6+(n?2:0)).attr("y",t.y-6+(n?2:0)).attr("width",n?8:12).attr("height",n?8:12).attr("class",`commit ${r.id} commit${q(s,G,$)} ${o}-inner`);else if(c===x.CHERRY_PICK)e.append("circle").attr("cx",t.x).attr("cy",t.y).attr("r",n?7:10).attr("class",`commit ${r.id} ${o}`),e.append("circle").attr("cx",t.x-3).attr("cy",t.y+2).attr("r",n?2.5:2.75).attr("fill",f?"#000000":"#fff").attr("class",`commit ${r.id} ${o}`),e.append("circle").attr("cx",t.x+3).attr("cy",t.y+2).attr("r",n?2.5:2.75).attr("fill",f?"#000000":"#fff").attr("class",`commit ${r.id} ${o}`),e.append("line").attr("x1",t.x+3).attr("y1",t.y+1).attr("x2",t.x).attr("y2",t.y-5).attr("stroke",f?"#000000":"#fff").attr("class",`commit ${r.id} ${o}`),e.append("line").attr("x1",t.x-3).attr("y1",t.y+1).attr("x2",t.x).attr("y2",t.y-5).attr("stroke",f?"#000000":"#fff").attr("class",`commit ${r.id} ${o}`);else{const g=e.append("circle");if(g.attr("cx",t.x),g.attr("cy",t.y),g.attr("r",n?7:10),g.attr("class",`commit ${r.id} commit${q(s,G,$)}`),c===x.MERGE){const h=e.append("circle");h.attr("cx",t.x),h.attr("cy",t.y),h.attr("r",n?5:6),h.attr("class",`commit ${o} ${r.id} commit${q(s,G,$)}`)}if(c===x.REVERSE){const h=e.append("path"),i=n?4:5;h.attr("d",`M ${t.x-i},${t.y-i}L${t.x+i},${t.y+i}M${t.x-i},${t.y+i}L${t.x+i},${t.y-i}`).attr("class",`commit ${o} ${r.id} commit${q(s,G,$)}`)}}},"drawCommitBullet"),Ne=l.__name((e,r,t,o,s)=>{if(r.type!==x.CHERRY_PICK&&(r.customId&&r.type===x.MERGE||r.type!==x.MERGE)&&s.showCommitLabel){const c=e.append("g"),a=c.insert("rect").attr("class","commit-label-bkg"),n=c.append("text").attr("x",o).attr("y",t.y+25).attr("class","commit-label").text(r.id),$=n.node()?.getBBox();if($&&(a.attr("x",t.posWithOffset-$.width/2-M).attr("y",t.y+13.5).attr("width",$.width+2*M).attr("height",$.height+2*M),m==="TB"||m==="BT"?(a.attr("x",t.x-($.width+4*B+5)).attr("y",t.y-12),n.attr("x",t.x-($.width+4*B)).attr("y",t.y+$.height-12)):n.attr("x",t.posWithOffset-$.width/2),s.rotateCommitLabel))if(m==="TB"||m==="BT")n.attr("transform","rotate(-45, "+t.x+", "+t.y+")"),a.attr("transform","rotate(-45, "+t.x+", "+t.y+")");else{const f=-7.5-($.width+10)/25*9.5,g=10+$.width/25*8.5;c.attr("transform","translate("+f+", "+g+") rotate(-45, "+o+", "+t.y+")")}}},"drawCommitLabel"),ze=l.__name((e,r,t,o)=>{if(r.tags.length>0){let s=0,c=0,a=0;const n=[];for(const $ of r.tags.reverse()){const f=e.insert("polygon"),g=e.append("circle"),h=e.append("text").attr("y",t.y-16-s).attr("class","tag-label").text($),i=h.node()?.getBBox();if(!i)throw new Error("Tag bbox not found");c=Math.max(c,i.width),a=Math.max(a,i.height),h.attr("x",t.posWithOffset-i.width/2),n.push({tag:h,hole:g,rect:f,yOffset:s}),s+=20}for(const{tag:$,hole:f,rect:g,yOffset:h}of n){const i=a/2,y=t.y-19.2-h;if(g.attr("class","tag-label-bkg").attr("points",` ${o-c/2-B/2},${y+M} ${o-c/2-B/2},${y-M} ${t.posWithOffset-c/2-B},${y-i-M} ${t.posWithOffset+c/2+B},${y-i-M} ${t.posWithOffset+c/2+B},${y+i+M} ${t.posWithOffset-c/2-B},${y+i+M}`),f.attr("cy",y).attr("cx",o-c/2+B/2).attr("r",1.5).attr("class","tag-hole"),m==="TB"||m==="BT"){const u=o+h;g.attr("class","tag-label-bkg").attr("points",` ${t.x},${u+2} ${t.x},${u-2} ${t.x+I},${u-i-2} ${t.x+I+c+4},${u-i-2} ${t.x+I+c+4},${u+i+2} ${t.x+I},${u+i+2}`).attr("transform","translate(12,12) rotate(45, "+t.x+","+o+")"),f.attr("cx",t.x+B/2).attr("cy",u).attr("transform","translate(12,12) rotate(45, "+t.x+","+o+")"),$.attr("x",t.x+5).attr("y",u+3).attr("transform","translate(14,14) rotate(45, "+t.x+","+o+")")}}}},"drawCommitTags"),Fe=l.__name(e=>{switch(e.customType??e.type){case x.NORMAL:return"commit-normal";case x.REVERSE:return"commit-reverse";case x.HIGHLIGHT:return"commit-highlight";case x.MERGE:return"commit-merge";case x.CHERRY_PICK:return"commit-cherry-pick";default:return"commit-normal"}},"getCommitClassType"),Pe=l.__name((e,r,t,o)=>{const s={x:0,y:0};if(e.parents.length>0){const c=oe(e.parents);if(c){const a=o.get(c)??s;return r==="TB"?a.y+O:r==="BT"?(o.get(e.id)??s).y-O:a.x+O}}else return r==="TB"?F:r==="BT"?(o.get(e.id)??s).y-O:0;return 0},"calculatePosition"),Ye=l.__name((e,r,t)=>{const o=m==="BT"&&t?r:r+I,s=E.get(e.branch)?.pos,c=m==="TB"||m==="BT"?E.get(e.branch)?.pos:o;if(c===void 0||s===void 0)throw new Error(`Position were undefined for commit ${e.id}`);const a=j.has(_.getConfig2().theme??"");return{x:c,y:m==="TB"||m==="BT"?o:s+(a?V/2+1:-2),posWithOffset:o}},"getCommitPosition"),Z=l.__name((e,r,t,o)=>{const s=e.append("g").attr("class","commit-bullets"),c=e.append("g").attr("class","commit-labels");let a=m==="TB"||m==="BT"?F:0;const n=[...r.keys()],$=o.parallelCommits??!1,f=l.__name((h,i)=>{const y=r.get(h)?.seq,u=r.get(i)?.seq;return y!==void 0&&u!==void 0?y-u:0},"sortKeys");let g=n.sort(f);m==="BT"&&($&&qe(g,r,a),g=g.reverse()),g.forEach(h=>{const i=r.get(h);if(!i)throw new Error(`Commit not found for key ${h}`);$&&(a=Pe(i,m,a,v));const y=Ye(i,a,$);if(t){const u=Fe(i),p=i.customType??i.type,b=E.get(i.branch)?.index??0;De(s,i,y,u,b,p),Ne(c,i,y,a,o),ze(c,i,y,a)}m==="TB"||m==="BT"?v.set(i.id,{x:y.x,y:y.posWithOffset}):v.set(i.id,{x:y.posWithOffset,y:y.y}),a=m==="BT"&&$?a+O:a+O+I,a>R&&(R=a)})},"drawCommits"),je=l.__name((e,r,t,o,s)=>{const c=(m==="TB"||m==="BT"?t.x<o.x:t.y<o.y)?r.branch:e.branch,a=l.__name($=>$.branch===c,"isOnBranchToGetCurve"),n=l.__name($=>$.seq>e.seq&&$.seq<r.seq,"isBetweenCommits");return[...s.values()].some($=>n($)&&a($))},"shouldRerouteArrow"),D=l.__name((e,r,t=0)=>{const o=e+Math.abs(e-r)/2;return t>5?o:P.every(s=>Math.abs(s-o)>=10)?(P.push(o),o):D(e,r-Math.abs(e-r)/5,t+1)},"findLane"),Ke=l.__name((e,r,t,o)=>{const{theme:s}=_.getConfig2(),c=Q.has(s??""),a=v.get(r.id),n=v.get(t.id);if(a===void 0||n===void 0)throw new Error(`Commit positions not found for commits ${r.id} and ${t.id}`);const $=je(r,t,a,n,o);let f="",g="",h=0,i=0,y=E.get(t.branch)?.index;t.type===x.MERGE&&r.id!==t.parents[0]&&(y=E.get(r.branch)?.index);let u;if($){f="A 10 10, 0, 0, 0,",g="A 10 10, 0, 0, 1,",h=10,i=10;const p=a.y<n.y?D(a.y,n.y):D(n.y,a.y),b=a.x<n.x?D(a.x,n.x):D(n.x,a.x);m==="TB"?a.x<n.x?u=`M ${a.x} ${a.y} L ${b-h} ${a.y} ${g} ${b} ${a.y+i} L ${b} ${n.y-h} ${f} ${b+i} ${n.y} L ${n.x} ${n.y}`:(y=E.get(r.branch)?.index,u=`M ${a.x} ${a.y} L ${b+h} ${a.y} ${f} ${b} ${a.y+i} L ${b} ${n.y-h} ${g} ${b-i} ${n.y} L ${n.x} ${n.y}`):m==="BT"?a.x<n.x?u=`M ${a.x} ${a.y} L ${b-h} ${a.y} ${f} ${b} ${a.y-i} L ${b} ${n.y+h} ${g} ${b+i} ${n.y} L ${n.x} ${n.y}`:(y=E.get(r.branch)?.index,u=`M ${a.x} ${a.y} L ${b+h} ${a.y} ${g} ${b} ${a.y-i} L ${b} ${n.y+h} ${f} ${b-i} ${n.y} L ${n.x} ${n.y}`):a.y<n.y?u=`M ${a.x} ${a.y} L ${a.x} ${p-h} ${f} ${a.x+i} ${p} L ${n.x-h} ${p} ${g} ${n.x} ${p+i} L ${n.x} ${n.y}`:(y=E.get(r.branch)?.index,u=`M ${a.x} ${a.y} L ${a.x} ${p+h} ${g} ${a.x+i} ${p} L ${n.x-h} ${p} ${f} ${n.x} ${p-i} L ${n.x} ${n.y}`)}else f="A 20 20, 0, 0, 0,",g="A 20 20, 0, 0, 1,",h=20,i=20,m==="TB"?(a.x<n.x&&(t.type===x.MERGE&&r.id!==t.parents[0]?u=`M ${a.x} ${a.y} L ${a.x} ${n.y-h} ${f} ${a.x+i} ${n.y} L ${n.x} ${n.y}`:u=`M ${a.x} ${a.y} L ${n.x-h} ${a.y} ${g} ${n.x} ${a.y+i} L ${n.x} ${n.y}`),a.x>n.x&&(f="A 20 20, 0, 0, 0,",g="A 20 20, 0, 0, 1,",h=20,i=20,t.type===x.MERGE&&r.id!==t.parents[0]?u=`M ${a.x} ${a.y} L ${a.x} ${n.y-h} ${g} ${a.x-i} ${n.y} L ${n.x} ${n.y}`:u=`M ${a.x} ${a.y} L ${n.x+h} ${a.y} ${f} ${n.x} ${a.y+i} L ${n.x} ${n.y}`),a.x===n.x&&(u=`M ${a.x} ${a.y} L ${n.x} ${n.y}`)):m==="BT"?(a.x<n.x&&(t.type===x.MERGE&&r.id!==t.parents[0]?u=`M ${a.x} ${a.y} L ${a.x} ${n.y+h} ${g} ${a.x+i} ${n.y} L ${n.x} ${n.y}`:u=`M ${a.x} ${a.y} L ${n.x-h} ${a.y} ${f} ${n.x} ${a.y-i} L ${n.x} ${n.y}`),a.x>n.x&&(f="A 20 20, 0, 0, 0,",g="A 20 20, 0, 0, 1,",h=20,i=20,t.type===x.MERGE&&r.id!==t.parents[0]?u=`M ${a.x} ${a.y} L ${a.x} ${n.y+h} ${f} ${a.x-i} ${n.y} L ${n.x} ${n.y}`:u=`M ${a.x} ${a.y} L ${n.x+h} ${a.y} ${g} ${n.x} ${a.y-i} L ${n.x} ${n.y}`),a.x===n.x&&(u=`M ${a.x} ${a.y} L ${n.x} ${n.y}`)):(a.y<n.y&&(t.type===x.MERGE&&r.id!==t.parents[0]?u=`M ${a.x} ${a.y} L ${n.x-h} ${a.y} ${g} ${n.x} ${a.y+i} L ${n.x} ${n.y}`:u=`M ${a.x} ${a.y} L ${a.x} ${n.y-h} ${f} ${a.x+i} ${n.y} L ${n.x} ${n.y}`),a.y>n.y&&(t.type===x.MERGE&&r.id!==t.parents[0]?u=`M ${a.x} ${a.y} L ${n.x-h} ${a.y} ${f} ${n.x} ${a.y-i} L ${n.x} ${n.y}`:u=`M ${a.x} ${a.y} L ${a.x} ${n.y+h} ${g} ${a.x+i} ${n.y} L ${n.x} ${n.y}`),a.y===n.y&&(u=`M ${a.x} ${a.y} L ${n.x} ${n.y}`));if(u===void 0)throw new Error("Line definition not found");e.append("path").attr("d",u).attr("class","arrow arrow"+q(y,G,c))},"drawArrow"),Ue=l.__name((e,r)=>{const t=e.append("g").attr("class","commit-arrows");[...r.keys()].forEach(o=>{const s=r.get(o);s.parents&&s.parents.length>0&&s.parents.forEach(c=>{Ke(t,r.get(c),s,r)})})},"drawArrows"),Ve=l.__name((e,r,t,o)=>{const{look:s,theme:c,themeVariables:a}=_.getConfig2(),{dropShadow:n,THEME_COLOR_LIMIT:$}=a,f=j.has(c??""),g=Q.has(c??""),h=e.append("g");r.forEach((i,y)=>{const u=q(y,f?$:G,g),p=E.get(i.name)?.pos;if(p===void 0)throw new Error(`Position not found for branch ${i.name}`);const b=m==="TB"||m==="BT"?p:f?p+V/2+1:p-2,k=h.append("line");k.attr("x1",0),k.attr("y1",b),k.attr("x2",R),k.attr("y2",b),k.attr("class","branch branch"+u),m==="TB"?(k.attr("y1",F),k.attr("x1",p),k.attr("y2",R),k.attr("x2",p)):m==="BT"&&(k.attr("y1",R),k.attr("x1",p),k.attr("y2",F),k.attr("x2",p)),P.push(b);const K=i.name,S=ne(K),T=h.insert("rect"),L=h.insert("g").attr("class","branchLabel").insert("g").attr("class","label branch-label"+u);L.node().appendChild(S);const C=S.getBBox(),N=f?0:4,z=f?16:0,A=f?V:0;s==="neo"&&T.attr("data-look","neo"),T.attr("class","branchLabelBkg label"+u).attr("style",s==="neo"?`filter:${f?`url(#${o}-drop-shadow)`:n}`:"").attr("rx",N).attr("ry",N).attr("x",-C.width-4-(t.rotateCommitLabel===!0?30:0)).attr("y",-C.height/2+10).attr("width",C.width+18+z).attr("height",C.height+4+A),L.attr("transform","translate("+(-C.width-14-(t.rotateCommitLabel===!0?30:0)+z/2)+", "+(b-C.height/2-2)+")"),m==="TB"?(T.attr("x",p-C.width/2-10).attr("y",0),L.attr("transform","translate("+(p-C.width/2-5)+", 0)"),f&&(T.attr("transform",`translate(${-z/2-3}, ${-A-10})`),L.attr("transform","translate("+(p-C.width/2-5)+", "+(-A*2+7)+")"))):m==="BT"?(T.attr("x",p-C.width/2-10).attr("y",R),L.attr("transform","translate("+(p-C.width/2-5)+", "+R+")"),f&&(T.attr("transform",`translate(${-z/2-3}, ${A+10})`),L.attr("transform","translate("+(p-C.width/2-5)+", "+(R+A*2+4)+")"))):T.attr("transform","translate(-19, "+(b-12-A/2)+")")})},"drawBranches"),Xe=l.__name(function(e,r,t,o,s){return E.set(e,{pos:r,index:t}),r+=50+(s?40:0)+(m==="TB"||m==="BT"?o.width/2:0),r},"setBranchPosition"),Je={draw:l.__name(function(e,r,t,o){Oe(),w.log.debug("in gitgraph renderer",e+` `,"id:",r,t);const s=o.db;if(!s.getConfig){w.log.error("getConfig method is not available on db");return}const c=s.getConfig(),a=c.rotateCommitLabel??!1;W=s.getCommits();const n=s.getBranchesAsObjArray();m=s.getDirection();const $=w.select_default(`[id="${r}"]`),{look:f,theme:g,themeVariables:h}=_.getConfig2(),{useGradient:i,gradientStart:y,gradientStop:u,filterColor:p}=h;if(i){const k=$.append("defs").append("linearGradient").attr("id",r+"-gradient").attr("gradientUnits","objectBoundingBox").attr("x1","0%").attr("y1","0%").attr("x2","100%").attr("y2","0%");k.append("stop").attr("offset","0%").attr("stop-color",y).attr("stop-opacity",1),k.append("stop").attr("offset","100%").attr("stop-color",u).attr("stop-opacity",1)}f==="neo"&&j.has(g??"")&&$.append("defs").append("filter").attr("id",r+"-drop-shadow").attr("height","130%").attr("width","130%").append("feDropShadow").attr("dx","4").attr("dy","4").attr("stdDeviation",0).attr("flood-opacity","0.06").attr("flood-color",p);let b=0;n.forEach((k,K)=>{const S=ne(k.name),T=$.append("g"),L=T.insert("g").attr("class","branchLabel"),C=L.insert("g").attr("class","label branch-label");C.node()?.appendChild(S);const N=S.getBBox();b=Xe(k.name,b,K,N,a),C.remove(),L.remove(),T.remove()}),Z($,W,!1,c),c.showBranches&&Ve($,n,c,r),Ue($,W),Z($,W,!0,c),X.utils_default.insertTitle($,"gitTitleText",c.titleTopMargin??0,s.getDiagramTitle()),_.setupGraphViewbox2(void 0,$,c.diagramPadding,c.useMaxWidth)},"draw")},se=8,ce=new Set(["redux","redux-dark","redux-color","redux-dark-color"]),Qe=new Set(["redux-color","redux-dark-color"]),Ze=new Set(["neo","neo-dark"]),er=new Set(["dark","redux-dark","redux-dark-color","neo-dark"]),rr=new Set(["redux","redux-dark","redux-color","redux-dark-color","neo","neo-dark"]),tr=l.__name(e=>{const{svgId:r}=e;let t="";if(e.useGradient&&r)for(let o=0;o<e.THEME_COLOR_LIMIT;o++)t+=` .label${o} { fill: ${e.mainBkg}; stroke: url(${r}-gradient); stroke-width: ${e.strokeWidth};} `;return t},"genGitGraphGradient"),ar=l.__name(e=>{const{theme:r,themeVariables:t}=_.getConfig(),{borderColorArray:o}=t,s=ce.has(r);if(Ze.has(r)){let c="";for(let a=0;a<e.THEME_COLOR_LIMIT;a++)if(a===0)c+=` .branch-label${a} { fill: ${e.nodeBorder};} .commit${a} { stroke: ${e.nodeBorder}; } .commit-highlight${a} { stroke: ${e.nodeBorder}; fill: ${e.nodeBorder}; } .arrow${a} { stroke: ${e.nodeBorder}; } .commit-bullets { fill: ${e.nodeBorder}; } .commit-cherry-pick${a} { stroke: ${e.nodeBorder}; } ${tr(e)}`;else{const n=a%se;c+=` .branch-label${a} { fill: ${e["gitBranchLabel"+n]}; } .commit${a} { stroke: ${e["git"+n]}; fill: ${e["git"+n]}; } .commit-highlight${a} { stroke: ${e["gitInv"+n]}; fill: ${e["gitInv"+n]}; } .arrow${a} { stroke: ${e["git"+n]}; } `}return c}else if(Qe.has(r)){let c="";for(let a=0;a<e.THEME_COLOR_LIMIT;a++)if(a===0)c+=` .branch-label${a} { fill: ${e.nodeBorder}; ${s?`font-weight:${e.noteFontWeight}`:""} } .commit${a} { stroke: ${e.nodeBorder}; } .commit-highlight${a} { stroke: ${e.nodeBorder}; fill: ${e.mainBkg}; } .label${a} { fill: ${e.mainBkg}; stroke: ${e.nodeBorder}; stroke-width: ${e.strokeWidth}; ${s?`font-weight:${e.noteFontWeight}`:""} } .arrow${a} { stroke: ${e.nodeBorder}; } .commit-bullets { fill: ${e.nodeBorder}; } `;else{const n=a%o.length;c+=` .branch-label${a} { fill: ${e.nodeBorder}; ${s?`font-weight:${e.noteFontWeight}`:""} } .commit${a} { stroke: ${o[n]}; fill: ${o[n]}; } .commit-highlight${a} { stroke: ${o[n]}; fill: ${o[n]}; } .label${a} { fill: ${er.has(r)?e.mainBkg:o[n]}; stroke: ${o[n]}; stroke-width: ${e.strokeWidth}; } .arrow${a} { stroke: ${o[n]}; } `}return c}else{let c="";for(let a=0;a<e.THEME_COLOR_LIMIT;a++)c+=` .branch-label${a} { fill: ${e.nodeBorder}; ${s?`font-weight:${e.noteFontWeight}`:""} } .commit${a} { stroke: ${e.nodeBorder}; } .commit-highlight${a} { stroke: ${e.nodeBorder}; fill: ${e.nodeBorder}; } .label${a} { fill: ${e.mainBkg}; stroke: ${e.nodeBorder}; stroke-width: ${e.strokeWidth}; ${s?`font-weight:${e.noteFontWeight}`:""}} .arrow${a} { stroke: ${e.nodeBorder}; } .commit-bullets { fill: ${e.nodeBorder}; } .commit-cherry-pick${a} { stroke: ${e.nodeBorder}; } `;return c}},"genColor"),nr=l.__name(e=>`${Array.from({length:e.THEME_COLOR_LIMIT},(r,t)=>t).map(r=>{const t=r%se;return` .branch-label${r} { fill: ${e["gitBranchLabel"+t]}; } .commit${r} { stroke: ${e["git"+t]}; fill: ${e["git"+t]}; } .commit-highlight${r} { stroke: ${e["gitInv"+t]}; fill: ${e["gitInv"+t]}; } .label${r} { fill: ${e["git"+t]}; } .arrow${r} { stroke: ${e["git"+t]}; } `}).join(` `)}`,"normalTheme"),or={parser:Re,db:ae,renderer:Je,styles:l.__name(e=>{const{theme:r}=_.getConfig(),t=rr.has(r);return` .commit-id, .commit-msg, .branch-label { fill: lightgrey; color: lightgrey; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-family: var(--mermaid-font-family); } ${t?ar(e):nr(e)} .branch { stroke-width: ${e.strokeWidth}; stroke: ${e.commitLineColor??e.lineColor}; stroke-dasharray: ${t?"4 2":"2"}; } .commit-label { font-size: ${e.commitLabelFontSize}; fill: ${t?e.nodeBorder:e.commitLabelColor}; ${t?`font-weight:${e.noteFontWeight};`:""}} .commit-label-bkg { font-size: ${e.commitLabelFontSize}; fill: ${t?"transparent":e.commitLabelBackground}; opacity: ${t?"":.5}; } .tag-label { font-size: ${e.tagLabelFontSize}; fill: ${e.tagLabelColor};} .tag-label-bkg { fill: ${t?e.mainBkg:e.tagLabelBackground}; stroke: ${t?e.nodeBorder:e.tagLabelBorder}; ${t?`filter:${e.dropShadow}`:""} } .tag-hole { fill: ${e.textColor}; } .commit-merge { stroke: ${t?e.mainBkg:e.primaryColor}; fill: ${t?e.mainBkg:e.primaryColor}; } .commit-reverse { stroke: ${t?e.mainBkg:e.primaryColor}; fill: ${t?e.mainBkg:e.primaryColor}; stroke-width: ${t?e.strokeWidth:3}; } .commit-highlight-outer { } .commit-highlight-inner { stroke: ${t?e.mainBkg:e.primaryColor}; fill: ${t?e.mainBkg:e.primaryColor}; } .arrow { /* Intentional: neo themes keep the bold 8px arrow (like classic themes); only redux-geometry themes use the thinner options.strokeWidth. */ stroke-width: ${ce.has(r)?e.strokeWidth:8}; stroke-linecap: round; fill: none } .gitTitleText { text-anchor: middle; font-size: 18px; fill: ${e.textColor}; } `},"getStyles")};exports.diagram=or;