mirror of
https://github.com/doocs/md.git
synced 2024-11-28 13:36:32 +08:00
66 lines
24 KiB
JavaScript
66 lines
24 KiB
JavaScript
|
import{p as Z}from"./chunk-JJENOPKO-SEXPrtzX.js";import{I as F}from"./chunk-FBCX6ULS-kKlZnFST.js";import{z as U,_ as h,d as rr,A as er,B as tr,C as ar,l as w,s as nr,g as sr,b as or,c as cr,p as ir,q as dr,e as E,r as hr,j as lr,u as $r,D as fr}from"./index-DmZQsxOK.js";import{p as gr}from"./gitGraph-F2EDSAW4-9ItpowA5.js";import"./min-BGRXW4Ku.js";import"./_baseUniq-BxBa45pm.js";var x={NORMAL:0,REVERSE:1,HIGHLIGHT:2,MERGE:3,CHERRY_PICK:4},yr=U.gitGraph,z=h(()=>er({...yr,...tr().gitGraph}),"getConfig"),i=new F(()=>{const t=z(),r=t.mainBranchName,a=t.mainBranchOrder;return{mainBranchName:r,commits:new Map,head:null,branchConfig:new Map([[r,{name:r,order:a}]]),branches:new Map([[r,null]]),currBranch:r,direction:"LR",seq:0,options:{}}});function j(){return ar({length:7})}h(j,"getID");function N(t,r){const a=Object.create(null);return t.reduce((s,e)=>{const n=r(e);return a[n]||(a[n]=!0,s.push(e)),s},[])}h(N,"uniqBy");var ur=h(function(t){i.records.direction=t},"setDirection"),xr=h(function(t){w.debug("options str",t),t=t==null?void 0:t.trim(),t=t||"{}";try{i.records.options=JSON.parse(t)}catch(r){w.error("error while parsing gitGraph options",r.message)}},"setOptions"),pr=h(function(){return i.records.options},"getOptions"),br=h(function(t){let r=t.msg,a=t.id;const s=t.type;let e=t.tags;w.info("commit",r,a,s,e),w.debug("Entering commit:",r,a,s,e);const n=z();a=E.sanitizeText(a,n),r=E.sanitizeText(r,n),e=e==null?void 0:e.map(o=>E.sanitizeText(o,n));const c={id:a||i.records.seq+"-"+j(),message:r,seq:i.records.seq++,type:s??x.NORMAL,tags:e??[],parents:i.records.head==null?[]:[i.records.head.id],branch:i.records.currBranch};i.records.head=c,w.info("main branch",n.mainBranchName),i.records.commits.set(c.id,c),i.records.branches.set(i.records.currBranch,c.id),w.debug("in pushCommit "+c.id)},"commit"),mr=h(function(t){let r=t.name;const a=t.order;if(r=E.sanitizeText(r,z()),i.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}")`);i.records.branches.set(r,i.records.head!=null?i.records.head.id:null),i.records.branchConfig.set(r,{name:r,order:a}),_(r),w.debug("in createBranch")},"branch"),wr=h(t=>{let r=t.branch,a=t.id;const s=t.type,e=t.tags,n=z();r=E.sanitizeText(r,n),a&&(a=E.sanitizeText(a,n));const c=i.records.branches.get(i.records.currBranch),o=i.records.branches.get(r),$=c?i.records.commits.get(c):void 0,l=o?i.records.commits.get(o):void 0;if($&&l&&$.branch===r)throw new Error(`Cannot merge branch '${r}' into itself.`);if(i.records.currBranch===r){const d=new Error('Incorrect usage of "merge". Cannot merge a branch to itself');throw d.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["branch abc"]},d}if($===void 0||!$){const d=new Error(`Incorrect usage of "merge". Current branch (${i.records.currBranch})has no commits`);throw d.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["commit"]},d}if(!i.records.branches.has(r)){const d=new Error('Incorrect usage of "merge". Branch to be merged ('+r+") does not exist");throw d.hash={text:`merge ${r}`,token:`merge ${r}`,expected:[`branch ${r}`]},d}if(l===void 0||!l){const d=new Error('Incorrect usage of "merge". Branch to be merged ('+r+") has no commits");throw d.hash={text:`merge ${r}`,token:`merge ${r}`,expected:['"commit"']},d}if($===l){const d=new Error('Incorrect usage of "merge". Both branches have same head');throw d.hash={text:`merge ${r}`,token:`merge ${r}`,expected:["branch abc"]},d}if(a&&i.records.commits.has(a)){const d=new Error('Incorrect usage of "merge". Commit with id:'+a+" already exists, use different custom Id");throw d.hash={text:`merge ${r} ${a} ${s} ${e==null?void 0:e.join(" ")}`,token:`merge ${r} ${a} ${s} ${e==null?void 0:e.join(" ")}`,expected:[`merge ${r} ${a}_UNIQUE ${s} ${e==null?void 0:e.join(" ")}`]},d}const f=o||"",g={id:a||`${i.records.seq}-${j()}`,message:`merged branch ${r} into ${i.records.currBranch}`,seq:i.records.seq++,parents:i.records.head==null?[]:[i.records.head.id,f],branch:i.records.currBranch,type:x.MERGE,customType:s,cu
|
||
|
${s-c/2-k/2},${p+L}
|
||
|
${s-c/2-k/2},${p-L}
|
||
|
${a.posWithOffset-c/2-k},${p-y-L}
|
||
|
${a.posWithOffset+c/2+k},${p-y-L}
|
||
|
${a.posWithOffset+c/2+k},${p+y+L}
|
||
|
${a.posWithOffset-c/2-k},${p+y+L}`),f.attr("cy",p).attr("cx",s-c/2+k/2).attr("r",1.5).attr("class","tag-hole"),u==="TB"||u==="BT"){const m=s+d;g.attr("class","tag-label-bkg").attr("points",`
|
||
|
${a.x},${m+2}
|
||
|
${a.x},${m-2}
|
||
|
${a.x+R},${m-y-2}
|
||
|
${a.x+R+c+4},${m-y-2}
|
||
|
${a.x+R+c+4},${m+y+2}
|
||
|
${a.x+R},${m+y+2}`).attr("transform","translate(12,12) rotate(45, "+a.x+","+s+")"),f.attr("cx",a.x+k/2).attr("cy",m).attr("transform","translate(12,12) rotate(45, "+a.x+","+s+")"),l.attr("x",a.x+5).attr("y",m+3).attr("transform","translate(14,14) rotate(45, "+a.x+","+s+")")}}}},"drawCommitTags"),Jr=h(t=>{switch(t.customType??t.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"),Qr=h((t,r,a,s)=>{const e={x:0,y:0};if(t.parents.length>0){const n=Q(t.parents);if(n){const c=s.get(n)??e;return r==="TB"?c.y+I:r==="BT"?(s.get(t.id)??e).y-I:c.x+I}}else return r==="TB"?P:r==="BT"?(s.get(t.id)??e).y-I:0;return 0},"calculatePosition"),Zr=h((t,r,a)=>{var c,o;const s=u==="BT"&&a?r:r+R,e=u==="TB"||u==="BT"?s:(c=C.get(t.branch))==null?void 0:c.pos,n=u==="TB"||u==="BT"?(o=C.get(t.branch))==null?void 0:o.pos:s;if(n===void 0||e===void 0)throw new Error(`Position were undefined for commit ${t.id}`);return{x:n,y:e,posWithOffset:s}},"getCommitPosition"),K=h((t,r,a)=>{if(!b)throw new Error("GitGraph config not found");const s=t.append("g").attr("class","commit-bullets"),e=t.append("g").attr("class","commit-labels");let n=u==="TB"||u==="BT"?P:0;const c=[...r.keys()],o=(b==null?void 0:b.parallelCommits)??!1,$=h((f,g)=>{var p,m;const d=(p=r.get(f))==null?void 0:p.seq,y=(m=r.get(g))==null?void 0:m.seq;return d!==void 0&&y!==void 0?d-y:0},"sortKeys");let l=c.sort($);u==="BT"&&(o&&Ar(l,r,n),l=l.reverse()),l.forEach(f=>{var y;const g=r.get(f);if(!g)throw new Error(`Commit not found for key ${f}`);o&&(n=Qr(g,u,n,B));const d=Zr(g,n,o);if(a){const p=Jr(g),m=g.customType??g.type,q=((y=C.get(g.branch))==null?void 0:y.index)??0;_r(s,g,d,p,q,m),Vr(e,g,d,n),Xr(e,g,d,n)}u==="TB"||u==="BT"?B.set(g.id,{x:d.x,y:d.posWithOffset}):B.set(g.id,{x:d.posWithOffset,y:d.y}),n=u==="BT"&&o?n+I:n+I+R,n>M&&(M=n)})},"drawCommits"),Fr=h((t,r,a,s,e)=>{const c=(u==="TB"||u==="BT"?a.x<s.x:a.y<s.y)?r.branch:t.branch,o=h(l=>l.branch===c,"isOnBranchToGetCurve"),$=h(l=>l.seq>t.seq&&l.seq<r.seq,"isBetweenCommits");return[...e.values()].some(l=>$(l)&&o(l))},"shouldRerouteArrow"),H=h((t,r,a=0)=>{const s=t+Math.abs(t-r)/2;if(a>5)return s;if(W.every(c=>Math.abs(c-s)>=10))return W.push(s),s;const n=Math.abs(t-r);return H(t,r-n/5,a+1)},"findLane"),Ur=h((t,r,a,s)=>{var y,p,m,q,Y;const e=B.get(r.id),n=B.get(a.id);if(e===void 0||n===void 0)throw new Error(`Commit positions not found for commits ${r.id} and ${a.id}`);const c=Fr(r,a,e,n,s);let o="",$="",l=0,f=0,g=(y=C.get(a.branch))==null?void 0:y.index;a.type===x.MERGE&&r.id!==a.parents[0]&&(g=(p=C.get(r.branch))==null?void 0:p.index);let d;if(c){o="A 10 10, 0, 0, 0,",$="A 10 10, 0, 0, 1,",l=10,f=10;const T=e.y<n.y?H(e.y,n.y):H(n.y,e.y),v=e.x<n.x?H(e.x,n.x):H(n.x,e.x);u==="TB"?e.x<n.x?d=`M ${e.x} ${e.y} L ${v-l} ${e.y} ${$} ${v} ${e.y+f} L ${v} ${n.y-l} ${o} ${v+f} ${n.y} L ${n.x} ${n.y}`:(g=(m=C.get(r.branch))==null?void 0:m.index,d=`M ${e.x} ${e.y} L ${v+l} ${e.y} ${o} ${v} ${e.y+f} L ${v} ${n.y-l} ${$} ${v-f} ${n.y} L ${n.x} ${n.y}`):u==="BT"?e.x<n.x?d=`M ${e.x} ${e.y} L ${v-l} ${e.y} ${o} ${v} ${e.y-f} L ${v} ${n.y+l} ${$} ${v+f} ${n.y} L ${n.x} ${n.y}`:(g=(q=C.get(r.branch))==null?void 0:q.index,d=`M ${e.x} ${e.y} L ${v+l} ${e.y} ${$} ${v} ${e.y-f} L ${v} ${n.y+l} ${o} ${v-f} ${n.y} L ${n.x} ${n.y}`):e.y<n.y?d=`M ${e.x} ${e.y} L ${e.x} ${T-l} ${o} ${e.x+f} ${T} L ${n.x-l} ${T} ${$} ${n.x} ${T+f} L ${n.x} ${n.y}`:(g=(Y=C.get(r.branch))==null?void 0:Y.index,d=`M ${e.x} ${e.y} L ${e.x} ${T+l} ${$} ${e.x+f} ${T} L ${n.x-l} ${T} ${o} ${n.x} ${T-f} L ${n.x} ${n.y}`)}else o="A 20 20, 0, 0, 0,",$="A 20 20, 0, 0, 1,",l=20,f=20,u==="TB"?(e.x<n.x&&(a.type===x.MERGE&&r.id!==a.parents[0]?d=`M ${e.x} ${e.y} L ${e.x} ${n.y-l} ${o} ${e.x+f} ${n.y} L ${n.x} ${n.y}`:d=`M ${e.x} ${e.y} L ${n.x-l} ${e.y} ${$} ${n.x} ${e.y+f} L ${n.x} ${n.y}`),e.x>n.x&&(o="A 20 20, 0, 0, 0,",$="A 20 20, 0, 0, 1,",l=20,f=20,a.type===x.MERGE&&r.id!==a.parents[0]?d=`M $
|
||
|
`,"id:",r,a),!b)throw new Error("GitGraph config not found");const e=b.rotateCommitLabel??!1,n=s.db;G=n.getCommits();const c=n.getBranchesAsObjArray();u=n.getDirection();const o=lr(`[id="${r}"]`);let $=0;c.forEach((l,f)=>{var q;const g=J(l.name),d=o.append("g"),y=d.insert("g").attr("class","branchLabel"),p=y.insert("g").attr("class","label branch-label");(q=p.node())==null||q.appendChild(g);const m=g.getBBox();$=te(l.name,$,f,m,e),p.remove(),y.remove(),d.remove()}),K(o,G,!1),b.showBranches&&ee(o,c),re(o,G),K(o,G,!0),$r.insertTitle(o,"gitTitleText",b.titleTopMargin??0,n.getDiagramTitle()),fr(void 0,o,b.diagramPadding,b.useMaxWidth)},"draw"),ne={draw:ae},se=h(t=>`
|
||
|
.commit-id,
|
||
|
.commit-msg,
|
||
|
.branch-label {
|
||
|
fill: lightgrey;
|
||
|
color: lightgrey;
|
||
|
font-family: 'trebuchet ms', verdana, arial, sans-serif;
|
||
|
font-family: var(--mermaid-font-family);
|
||
|
}
|
||
|
${[0,1,2,3,4,5,6,7].map(r=>`
|
||
|
.branch-label${r} { fill: ${t["gitBranchLabel"+r]}; }
|
||
|
.commit${r} { stroke: ${t["git"+r]}; fill: ${t["git"+r]}; }
|
||
|
.commit-highlight${r} { stroke: ${t["gitInv"+r]}; fill: ${t["gitInv"+r]}; }
|
||
|
.label${r} { fill: ${t["git"+r]}; }
|
||
|
.arrow${r} { stroke: ${t["git"+r]}; }
|
||
|
`).join(`
|
||
|
`)}
|
||
|
|
||
|
.branch {
|
||
|
stroke-width: 1;
|
||
|
stroke: ${t.lineColor};
|
||
|
stroke-dasharray: 2;
|
||
|
}
|
||
|
.commit-label { font-size: ${t.commitLabelFontSize}; fill: ${t.commitLabelColor};}
|
||
|
.commit-label-bkg { font-size: ${t.commitLabelFontSize}; fill: ${t.commitLabelBackground}; opacity: 0.5; }
|
||
|
.tag-label { font-size: ${t.tagLabelFontSize}; fill: ${t.tagLabelColor};}
|
||
|
.tag-label-bkg { fill: ${t.tagLabelBackground}; stroke: ${t.tagLabelBorder}; }
|
||
|
.tag-hole { fill: ${t.textColor}; }
|
||
|
|
||
|
.commit-merge {
|
||
|
stroke: ${t.primaryColor};
|
||
|
fill: ${t.primaryColor};
|
||
|
}
|
||
|
.commit-reverse {
|
||
|
stroke: ${t.primaryColor};
|
||
|
fill: ${t.primaryColor};
|
||
|
stroke-width: 3;
|
||
|
}
|
||
|
.commit-highlight-outer {
|
||
|
}
|
||
|
.commit-highlight-inner {
|
||
|
stroke: ${t.primaryColor};
|
||
|
fill: ${t.primaryColor};
|
||
|
}
|
||
|
|
||
|
.arrow { stroke-width: 8; stroke-linecap: round; fill: none}
|
||
|
.gitTitleText {
|
||
|
text-anchor: middle;
|
||
|
font-size: 18px;
|
||
|
fill: ${t.textColor};
|
||
|
}
|
||
|
`,"getStyles"),oe=se,fe={parser:Wr,db:X,renderer:ne,styles:oe};export{fe as diagram};
|