Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gitgraph/core

Package Overview
Dependencies
Maintainers
4
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gitgraph/core - npm Package Compare versions

Comparing version 1.4.5 to 1.5.0

33

CHANGELOG.md

@@ -7,2 +7,33 @@ ### Changelog

#### [1.5.0](https://github.com/nicoespeon/gitgraph.js/compare/@gitgraph/core@1.4.5...@gitgraph/core@1.5.0)
> 6 March 2021
- docs: add Marty as a contributor [`#408`](https://github.com/nicoespeon/gitgraph.js/pull/408)
- docs: add longgt as a contributor [`#406`](https://github.com/nicoespeon/gitgraph.js/pull/406)
- docs: add aensley as a contributor [`#404`](https://github.com/nicoespeon/gitgraph.js/pull/404)
- docs: add soumyart as a contributor [`#403`](https://github.com/nicoespeon/gitgraph.js/pull/403)
- docs: add acransac as a contributor [`#402`](https://github.com/nicoespeon/gitgraph.js/pull/402)
- (@gitgraph/js) Add option to make graph responsive [`#401`](https://github.com/nicoespeon/gitgraph.js/pull/401)
- Branch Deletion [`#399`](https://github.com/nicoespeon/gitgraph.js/pull/399)
- Migrate linting to eslint [`#395`](https://github.com/nicoespeon/gitgraph.js/pull/395)
- [React] Fix strict mode label placement [`#392`](https://github.com/nicoespeon/gitgraph.js/pull/392)
- Fix linting glob [`#394`](https://github.com/nicoespeon/gitgraph.js/pull/394)
- docs: add crutchcorn as a contributor [`#393`](https://github.com/nicoespeon/gitgraph.js/pull/393)
- [React] Individual file breakout [`#391`](https://github.com/nicoespeon/gitgraph.js/pull/391)
- Fix body of last commit not visible [`#386`](https://github.com/nicoespeon/gitgraph.js/pull/386)
- Fix infrastractural problems [`#385`](https://github.com/nicoespeon/gitgraph.js/pull/385)
- docs: add andreasonny83 as a contributor [`#384`](https://github.com/nicoespeon/gitgraph.js/pull/384)
- Fix failing TravisCI [`#383`](https://github.com/nicoespeon/gitgraph.js/pull/383)
- feat: update address about Usage Demo & Documentation [`#382`](https://github.com/nicoespeon/gitgraph.js/pull/382)
- docs: add Nebula83 as a contributor [`#368`](https://github.com/nicoespeon/gitgraph.js/pull/368)
- fix: replace 'transparent' with 'none' [`#366`](https://github.com/nicoespeon/gitgraph.js/pull/366)
- Bump websocket-extensions from 0.1.3 to 0.1.4 [`#362`](https://github.com/nicoespeon/gitgraph.js/pull/362)
- Fixing the parent branch name in readme [`#355`](https://github.com/nicoespeon/gitgraph.js/pull/355)
- Bump https-proxy-agent from 2.2.1 to 2.2.4 [`#353`](https://github.com/nicoespeon/gitgraph.js/pull/353)
- Use hash instead of hashAbbrev as key [`#321`](https://github.com/nicoespeon/gitgraph.js/issues/321)
- Make JS graph responsive with an option [`#303`](https://github.com/nicoespeon/gitgraph.js/issues/303)
- Fix body of last commit not visible [`#374`](https://github.com/nicoespeon/gitgraph.js/issues/374)
- Backfill with contributors since GitGraph v2 [`#296`](https://github.com/nicoespeon/gitgraph.js/issues/296)
#### [1.4.5](https://github.com/nicoespeon/gitgraph.js/compare/@gitgraph/core@1.4.4...@gitgraph/core@1.4.5)

@@ -185,3 +216,3 @@

- Fix #89 [`#95`](https://github.com/nicoespeon/gitgraph.js/pull/95)
- [BUGFIX][`#93`](https://github.com/nicoespeon/gitgraph.js/pull/93)
- [BUGFIX] [`#93`](https://github.com/nicoespeon/gitgraph.js/pull/93)
- Adds `detailId` to commitWithDetailsConfig example [`#92`](https://github.com/nicoespeon/gitgraph.js/pull/92)

@@ -188,0 +219,0 @@ - Added the ability to assign 'onClick' events to commits. [`#76`](https://github.com/nicoespeon/gitgraph.js/pull/76)

2

lib/bundle.min.js

@@ -1,1 +0,1 @@

!function(){return function t(e,s,r){function i(o,n){if(!s[o]){if(!e[o]){var h="function"==typeof require&&require;if(!n&&h)return h(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var m=s[o]={exports:{}};e[o][0].call(m.exports,function(t){return i(e[o][1][t]||t)},m,m.exports,t,e,s,r)}return s[o].exports}for(var a="function"==typeof require&&require,o=0;o<r.length;o++)i(r[o]);return i}}()({1:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./user-api/branch-user-api"),i="";s.DELETED_BRANCH_NAME=i;class a{constructor(t){this.gitgraph=t.gitgraph,this.name=t.name,this.style=t.style,this.parentCommitHash=t.parentCommitHash,this.commitDefaultOptions=t.commitDefaultOptions||{style:{}},this.onGraphUpdate=t.onGraphUpdate,this.renderLabel=t.renderLabel}getUserApi(){return new r.BranchUserApi(this,this.gitgraph,this.onGraphUpdate)}isDeleted(){return this.name===i}}s.Branch=a,s.createDeletedBranch=function(t,e,s){return new a({name:i,gitgraph:t,style:e,onGraphUpdate:s})}},{"./user-api/branch-user-api":15}],2:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.BranchesOrder=class{constructor(t,e,s){this.branches=new Set,this.colors=e,t.forEach(t=>this.branches.add(t.branchToDisplay)),s&&(this.branches=new Set(Array.from(this.branches).sort(s)))}get(t){return Array.from(this.branches).findIndex(e=>e===t)}getColorOf(t){return this.colors[this.get(t)%this.colors.length]}}},{}],3:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./utils");s.BranchesPathsCalculator=class{constructor(t,e,s,r,i,a){this.branchesPaths=new Map,this.commits=t,this.branches=e,this.commitSpacing=s,this.isGraphVertical=r,this.isGraphReverse=i,this.createDeletedBranch=a}execute(){return this.fromCommits(),this.withMergeCommits(),this.smoothBranchesPaths()}fromCommits(){this.commits.forEach(t=>{let e=this.branches.get(t.branchToDisplay);e||(e=this.getDeletedBranchInPath()||this.createDeletedBranch());const s=[],r=this.branchesPaths.get(e),i=this.commits.find(({hash:e})=>e===t.parents[0]);r?s.push(...r):i&&s.push({x:i.x,y:i.y}),s.push({x:t.x,y:t.y}),this.branchesPaths.set(e,s)})}withMergeCommits(){this.commits.filter(({parents:t})=>t.length>1).forEach(t=>{const e=this.commits.find(({hash:e})=>e===t.parents[1]);if(!e)return;const s=e.branches?e.branches[0]:"";let r=this.branches.get(s);if(!r&&!(r=this.getDeletedBranchInPath()))return;const i=[...this.branchesPaths.get(r)||[]];this.branchesPaths.set(r,[...i,{x:t.x,y:t.y,mergeCommit:!0}])})}getDeletedBranchInPath(){return Array.from(this.branchesPaths.keys()).find(t=>t.isDeleted())}smoothBranchesPaths(){const t=new Map;return this.branchesPaths.forEach((e,s)=>{if(e.length<=1)return void t.set(s,[e]);e=this.isGraphVertical?e.sort((t,e)=>t.y>e.y?-1:1):e.sort((t,e)=>t.x>e.x?1:-1),this.isGraphReverse&&(e=e.reverse());const i=e.reduce((t,s,i)=>{if(s.mergeCommit){t[t.length-1].push(r.pick(s,["x","y"]));let a=i-1,o=e[a];for(;a>=0&&o.mergeCommit;)o=e[--a];a>=0&&t.push([o])}else t[t.length-1].push(s);return t},[[]]);this.isGraphReverse&&i.forEach(t=>t.reverse()),this.isGraphVertical?i.forEach(e=>{if(e.length<=1)return;const r=e[0],i=e[e.length-1],a=e[1].x,o=Math.round(Math.abs(r.y-i.y)/this.commitSpacing)-1,n=o>0?new Array(o).fill(0).map((t,s)=>({x:a,y:e[0].y-this.commitSpacing*(s+1)})):[],h=t.get(s)||[];t.set(s,[...h,[r,...n,i]])}):i.forEach(e=>{if(e.length<=1)return;const r=e[0],i=e[e.length-1],a=e[1].y,o=Math.round(Math.abs(r.x-i.x)/this.commitSpacing)-1,n=o>0?new Array(o).fill(0).map((t,s)=>({y:a,x:e[0].x+this.commitSpacing*(s+1)})):[],h=t.get(s)||[];t.set(s,[...h,[r,...n,i]])})}),t}},s.toSvgPath=function(t,e,s){return t.map(t=>"M"+t.map(({x:t,y:r},i,a)=>{if(e&&a.length>1&&(1===i||i===a.length-1)){const e=a[i-1];if(s){const s=(e.y+r)/2;return`C ${e.x} ${s} ${t} ${s} ${t} ${r}`}{const s=(e.x+t)/2;return`C ${s} ${e.y} ${s} ${r} ${t} ${r}`}}return`L ${t} ${r}`}).join(" ").slice(1)).join(" ")}},{"./utils":17}],4:[function(t,e,s){var r;r=function(){"use strict";Object.defineProperty(s,"__esModule",{value:!0});var e=t("./gitgraph");s.GitgraphCore=e.GitgraphCore;var r=t("./mode");s.Mode=r.Mode;var i=t("./user-api/gitgraph-user-api");s.GitgraphUserApi=i.GitgraphUserApi;var a=t("./user-api/branch-user-api");s.BranchUserApi=a.BranchUserApi;var o=t("./branch");s.Branch=o.Branch;var n=t("./commit");s.Commit=n.Commit;var h=t("./tag");s.Tag=h.Tag;var c=t("./refs");s.Refs=c.Refs;var m=t("./template");s.MergeStyle=m.MergeStyle,s.TemplateName=m.TemplateName,s.templateExtend=m.templateExtend;var l=t("./orientation");s.Orientation=l.Orientation;var p=t("./branches-paths");s.toSvgPath=p.toSvgPath;var u=t("./utils");s.arrowSvgPath=u.arrowSvgPath},"object"==typeof s&&void 0!==e?r():"function"==typeof define&&define.amd?define(r):r()},{"./branch":1,"./branches-paths":3,"./commit":5,"./gitgraph":6,"./mode":10,"./orientation":11,"./refs":12,"./tag":13,"./template":14,"./user-api/branch-user-api":15,"./user-api/gitgraph-user-api":16,"./utils":17}],5:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./tag"),i=()=>(Math.random().toString(16).substring(3)+Math.random().toString(16).substring(3)+Math.random().toString(16).substring(3)+Math.random().toString(16).substring(3)).substring(0,40);class a{constructor(t){let e,s;this.refs=[],this.x=0,this.y=0;try{[,e,s]=t.author.match(/(.*) <(.*)>/)}catch(r){[e,s]=[t.author,""]}this.author={name:e,email:s,timestamp:Date.now()},this.committer={name:e,email:s,timestamp:Date.now()},this.subject=t.subject,this.body=t.body||"",this.hash=t.hash||i(),this.hashAbbrev=this.hash.substring(0,7),this.parents=t.parents?t.parents:[],this.parentsAbbrev=this.parents.map(t=>t.substring(0,7)),this.style=Object.assign({},t.style,{message:Object.assign({},t.style.message),dot:Object.assign({},t.style.dot)}),this.dotText=t.dotText,this.onClick=(()=>t.onClick?t.onClick(this):void 0),this.onMessageClick=(()=>t.onMessageClick?t.onMessageClick(this):void 0),this.onMouseOver=(()=>t.onMouseOver?t.onMouseOver(this):void 0),this.onMouseOut=(()=>t.onMouseOut?t.onMouseOut(this):void 0),this.renderDot=t.renderDot,this.renderMessage=t.renderMessage,this.renderTooltip=t.renderTooltip}get message(){let t="";return this.style.message.displayHash&&(t+=`${this.hashAbbrev} `),t+=this.subject,this.style.message.displayAuthor&&(t+=` - ${this.author.name} <${this.author.email}>`),t}get branchToDisplay(){return this.branches?this.branches[0]:""}setRefs(t){return this.refs=t.getNames(this.hash),this}setTags(t,e,s){return this.tags=t.getNames(this.hash).map(t=>new r.Tag(t,e(t),s(t),this.style)),this}setBranches(t){return this.branches=t,this}setPosition({x:t,y:e}){return this.x=t,this.y=e,this}withDefaultColor(t){const e=Object.assign({},this.style,{dot:Object.assign({},this.style.dot),message:Object.assign({},this.style.message)});e.color||(e.color=t),e.dot.color||(e.dot.color=t),e.message.color||(e.message.color=t);const s=this.cloneCommit();return s.style=e,s}cloneCommit(){const t=new a({author:`${this.author.name} <${this.author.email}>`,subject:this.subject,style:this.style,body:this.body,hash:this.hash,parents:this.parents,dotText:this.dotText,onClick:this.onClick,onMessageClick:this.onMessageClick,onMouseOver:this.onMouseOver,onMouseOut:this.onMouseOut,renderDot:this.renderDot,renderMessage:this.renderMessage,renderTooltip:this.renderTooltip});return t.refs=this.refs,t.branches=this.branches,t.tags=this.tags,t.x=this.x,t.y=this.y,t}}s.Commit=a},{"./tag":13}],6:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./branch"),i=t("./graph-rows"),a=t("./mode"),o=t("./branches-order"),n=t("./template"),h=t("./refs"),c=t("./branches-paths"),m=t("./utils"),l=t("./orientation"),p=t("./user-api/gitgraph-user-api");s.GitgraphCore=class{constructor(t={}){this.refs=new h.Refs,this.tags=new h.Refs,this.tagStyles={},this.tagRenders={},this.commits=[],this.branches=new Map,this.listeners=[],this.nextTimeoutId=null,this.template=n.getTemplate(t.template),this.currentBranch=this.createBranch("master"),this.orientation=t.orientation,this.reverseArrow=m.booleanOptionOr(t.reverseArrow,!1),this.initCommitOffsetX=m.numberOptionOr(t.initCommitOffsetX,0),this.initCommitOffsetY=m.numberOptionOr(t.initCommitOffsetY,0),this.mode=t.mode,this.author=t.author||"Sergio Flores <saxo-guy@epic.com>",this.commitMessage=t.commitMessage||"He doesn't like George Michael! Boooo!",this.generateCommitHash="function"==typeof t.generateCommitHash?t.generateCommitHash:()=>void 0,this.branchesOrderFunction="function"==typeof t.compareBranchesOrder?t.compareBranchesOrder:void 0,this.branchLabelOnEveryCommit=m.booleanOptionOr(t.branchLabelOnEveryCommit,!1)}get isHorizontal(){return this.orientation===l.Orientation.Horizontal||this.orientation===l.Orientation.HorizontalReverse}get isVertical(){return!this.isHorizontal}get isReverse(){return this.orientation===l.Orientation.HorizontalReverse||this.orientation===l.Orientation.VerticalReverse}get shouldDisplayCommitMessage(){return!this.isHorizontal&&this.mode!==a.Mode.Compact}getUserApi(){return new p.GitgraphUserApi(this,()=>this.next())}subscribe(t){this.listeners.push(t);let e=!0;return()=>{if(!e)return;e=!1;const s=this.listeners.indexOf(t);this.listeners.splice(s,1)}}getRenderedData(){const t=this.computeRenderedCommits(),e=this.computeRenderedBranchesPaths(t),s=this.computeCommitMessagesX(e);return this.computeBranchesColor(t,e),{commits:t,branchesPaths:e,commitMessagesX:s}}createBranch(t){let e={gitgraph:this,name:"",parentCommitHash:this.refs.getCommit("HEAD"),style:this.template.branch,onGraphUpdate:()=>this.next()};if("string"==typeof t)e.name=t,e.parentCommitHash=this.refs.getCommit("HEAD");else{const s=t.from?t.from.name:"HEAD",r=this.refs.getCommit(s)||(this.refs.hasCommit(t.from)?t.from:void 0);t.style=t.style||{},e=Object.assign({},e,t,{parentCommitHash:r,style:Object.assign({},e.style,t.style,{label:Object.assign({},e.style.label,t.style.label)})})}const s=new r.Branch(e);return this.branches.set(s.name,s),s}computeRenderedCommits(){const t=this.getBranches(),e=this.commits.map(e=>this.withBranches(t,e)),s=i.createGraphRows(this.mode,this.commits),r=new o.BranchesOrder(e,this.template.colors,this.branchesOrderFunction);return e.map(t=>t.setRefs(this.refs)).map(t=>this.withPosition(s,r,t)).map(t=>t.withDefaultColor(this.getBranchDefaultColor(r,t.branchToDisplay))).map(t=>t.setTags(this.tags,t=>Object.assign({},this.tagStyles[t],this.template.tag),t=>this.tagRenders[t]))}computeRenderedBranchesPaths(t){return new c.BranchesPathsCalculator(t,this.branches,this.template.commit.spacing,this.isVertical,this.isReverse,()=>r.createDeletedBranch(this,this.template.branch,()=>this.next())).execute()}computeBranchesColor(t,e){const s=new o.BranchesOrder(t,this.template.colors,this.branchesOrderFunction);Array.from(e).forEach(([t])=>{t.computedColor=t.style.color||this.getBranchDefaultColor(s,t.name)})}computeCommitMessagesX(t){return Array.from(t).length*this.template.branch.spacing}withBranches(t,e){let s=Array.from((t.get(e.hash)||new Set).values());return 0===s.length&&(s=[r.DELETED_BRANCH_NAME]),e.setBranches(s)}getBranches(){const t=new Map,e=[];return this.refs.getAllNames().filter(t=>"HEAD"!==t).forEach(s=>{const r=this.refs.getCommit(s);for(r&&e.push(r);e.length>0;){const r=e.pop(),i=this.commits.find(({hash:t})=>t===r),a=t.get(r)||new Set;a.add(s),t.set(r,a),i&&i.parents&&i.parents.length>0&&e.push(i.parents[0])}}),t}withPosition(t,e,s){const r=t.getRowOf(s.hash),i=t.getMaxRow(),a=e.get(s.branchToDisplay);switch(this.orientation){default:return s.setPosition({x:this.initCommitOffsetX+this.template.branch.spacing*a,y:this.initCommitOffsetY+this.template.commit.spacing*(i-r)});case l.Orientation.VerticalReverse:return s.setPosition({x:this.initCommitOffsetX+this.template.branch.spacing*a,y:this.initCommitOffsetY+this.template.commit.spacing*r});case l.Orientation.Horizontal:return s.setPosition({x:this.initCommitOffsetX+this.template.commit.spacing*r,y:this.initCommitOffsetY+this.template.branch.spacing*a});case l.Orientation.HorizontalReverse:return s.setPosition({x:this.initCommitOffsetX+this.template.commit.spacing*(i-r),y:this.initCommitOffsetY+this.template.branch.spacing*a})}}getBranchDefaultColor(t,e){return t.getColorOf(e)}next(){this.nextTimeoutId&&window.clearTimeout(this.nextTimeoutId),this.nextTimeoutId=window.setTimeout(()=>{this.listeners.forEach(t=>t(this.getRenderedData()))},0)}}},{"./branch":1,"./branches-order":2,"./branches-paths":3,"./graph-rows":8,"./mode":10,"./orientation":11,"./refs":12,"./template":14,"./user-api/gitgraph-user-api":16,"./utils":17}],7:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./regular");s.CompactGraphRows=class extends r.RegularGraphRows{computeRowsFromCommits(t){t.forEach((e,s)=>{let r=s;if(0!==s){const i=this.getRowOf(e.parents[0]),a=t[s-1];r=Math.max(i+1,this.getRowOf(a.hash)),e.parents.length>1&&i<this.getRowOf(e.parents[1])&&r++}this.rows.set(e.hash,r)})}}},{"./regular":9}],8:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("../mode"),i=t("./compact"),a=t("./regular");s.GraphRows=a.RegularGraphRows,s.createGraphRows=function(t,e){return t===r.Mode.Compact?new i.CompactGraphRows(e):new a.RegularGraphRows(e)}},{"../mode":10,"./compact":7,"./regular":9}],9:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.RegularGraphRows=class{constructor(t){this.rows=new Map,this.maxRowCache=void 0,this.computeRowsFromCommits(t)}getRowOf(t){return this.rows.get(t)||0}getMaxRow(){return void 0===this.maxRowCache&&(this.maxRowCache=function(t){const e=new Set;return t.forEach(t=>e.add(t)),Array.from(e)}(Array.from(this.rows.values())).length-1),this.maxRowCache}computeRowsFromCommits(t){t.forEach((t,e)=>{this.rows.set(t.hash,e)}),this.maxRowCache=void 0}}},{}],10:[function(t,e,s){"use strict";var r;Object.defineProperty(s,"__esModule",{value:!0}),function(t){t.Compact="compact"}(r||(r={})),s.Mode=r},{}],11:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),function(t){t.VerticalReverse="vertical-reverse",t.Horizontal="horizontal",t.HorizontalReverse="horizontal-reverse"}(s.Orientation||(s.Orientation={}))},{}],12:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.Refs=class{constructor(){this.commitPerName=new Map,this.namesPerCommit=new Map}set(t,e){const s=this.commitPerName.get(t);return s&&this.removeNameFrom(s,t),this.addNameTo(e,t),this.addCommitTo(t,e),this}getCommit(t){return this.commitPerName.get(t)}getNames(t){return this.namesPerCommit.get(t)||[]}getAllNames(){return Array.from(this.commitPerName.keys())}hasCommit(t){return this.namesPerCommit.has(t)}hasName(t){return this.commitPerName.has(t)}removeNameFrom(t,e){const s=this.namesPerCommit.get(t)||[];this.namesPerCommit.set(t,s.filter(t=>t!==e))}addNameTo(t,e){const s=this.namesPerCommit.get(t)||[];this.namesPerCommit.set(t,[...s,e])}addCommitTo(t,e){this.commitPerName.set(t,e)}}},{}],13:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./template"),i=t("./utils");s.Tag=class{constructor(t,e,s,r){this.name=t,this.tagStyle=e,this.commitStyle=r,this.render=s}get style(){return{strokeColor:this.tagStyle.strokeColor||this.commitStyle.color,bgColor:this.tagStyle.bgColor||this.commitStyle.color,color:this.tagStyle.color||"white",font:this.tagStyle.font||this.commitStyle.message.font||r.DEFAULT_FONT,borderRadius:i.numberOptionOr(this.tagStyle.borderRadius,10),pointerWidth:i.numberOptionOr(this.tagStyle.pointerWidth,12)}}}},{"./template":14,"./utils":17}],14:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./utils");var i;!function(t){t.Bezier="bezier",t.Straight="straight"}(i||(i={})),s.MergeStyle=i,s.DEFAULT_FONT="normal 12pt Calibri";class a{constructor(t){t.branch=t.branch||{},t.branch.label=t.branch.label||{},t.arrow=t.arrow||{},t.commit=t.commit||{},t.commit.dot=t.commit.dot||{},t.commit.message=t.commit.message||{},this.colors=t.colors||["#000000"],this.branch={color:t.branch.color,lineWidth:t.branch.lineWidth||2,mergeStyle:t.branch.mergeStyle||i.Bezier,spacing:r.numberOptionOr(t.branch.spacing,20),label:{display:r.booleanOptionOr(t.branch.label.display,!0),color:t.branch.label.color||t.commit.color,strokeColor:t.branch.label.strokeColor||t.commit.color,bgColor:t.branch.label.bgColor||"white",font:t.branch.label.font||t.commit.message.font||s.DEFAULT_FONT,borderRadius:r.numberOptionOr(t.branch.label.borderRadius,10)}},this.arrow={size:t.arrow.size||null,color:t.arrow.color||null,offset:t.arrow.offset||2},this.commit={color:t.commit.color,spacing:r.numberOptionOr(t.commit.spacing,25),hasTooltipInCompactMode:r.booleanOptionOr(t.commit.hasTooltipInCompactMode,!0),dot:{color:t.commit.dot.color||t.commit.color,size:t.commit.dot.size||3,strokeWidth:r.numberOptionOr(t.commit.dot.strokeWidth,0),strokeColor:t.commit.dot.strokeColor,font:t.commit.dot.font||t.commit.message.font||"normal 10pt Calibri"},message:{display:r.booleanOptionOr(t.commit.message.display,!0),displayAuthor:r.booleanOptionOr(t.commit.message.displayAuthor,!0),displayHash:r.booleanOptionOr(t.commit.message.displayHash,!0),color:t.commit.message.color||t.commit.color,font:t.commit.message.font||s.DEFAULT_FONT}},this.tag=t.tag||{}}}s.Template=a;const o=new a({colors:["#6963FF","#47E8D4","#6BDB52","#E84BA5","#FFA657"],branch:{color:"#000000",lineWidth:4,spacing:50,mergeStyle:i.Straight},commit:{spacing:60,dot:{size:16,strokeColor:"#000000",strokeWidth:4},message:{color:"black"}},arrow:{size:16,offset:-1.5}});s.blackArrowTemplate=o;const n=new a({colors:["#979797","#008fb5","#f1c109"],branch:{lineWidth:10,spacing:50},commit:{spacing:80,dot:{size:14},message:{font:"normal 14pt Arial"}}});var h;function c(t){return t?"string"==typeof t?{[h.BlackArrow]:o,[h.Metro]:n}[t]:t:n}s.metroTemplate=n,function(t){t.Metro="metro",t.BlackArrow="blackarrow"}(h||(h={})),s.TemplateName=h,s.templateExtend=function(t,e){const s=c(t);return e.branch||(e.branch={}),e.commit||(e.commit={}),{colors:e.colors||s.colors,arrow:Object.assign({},s.arrow,e.arrow),branch:Object.assign({},s.branch,e.branch,{label:Object.assign({},s.branch.label,e.branch.label)}),commit:Object.assign({},s.commit,e.commit,{dot:Object.assign({},s.commit.dot,e.commit.dot),message:Object.assign({},s.commit.message,e.commit.message)}),tag:Object.assign({},s.tag,e.tag)}},s.getTemplate=c},{"./utils":17}],15:[function(t,e,s){"use strict";var r=this&&this.__rest||function(t,e){var s={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(s[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(s[r[i]]=t[r[i]])}return s};Object.defineProperty(s,"__esModule",{value:!0});const i=t("../commit"),a=t("../utils");class o{constructor(t,e,s){this._branch=t,this.name=t.name,this._graph=e,this._onGraphUpdate=s}branch(t){const e="string"==typeof t?{name:t}:t;return e.from=this,this._graph.createBranch(e).getUserApi()}commit(t){return"string"==typeof t&&(t={subject:t}),t||(t={}),this._commitWithParents(t,[]),this._onGraphUpdate(),this}merge(...t){let e=t[0];(function(t){return"object"==typeof t&&!(t instanceof o)})(e)||(e={branch:t[0],fastForward:!1,commitOptions:{subject:t[1]}});const{branch:s,fastForward:r,commitOptions:i}=e,a="string"==typeof s?s:s.name,n=this._graph.refs.getCommit(a);if(!n)throw new Error(`The branch called "${a}" is unknown`);let h=!1;if(r){const t=this._graph.refs.getCommit(this._branch.name);t&&(h=this._areCommitsConnected(t,n))}return r&&h?this._fastForwardTo(n):this._commitWithParents(Object.assign({},i,{subject:i&&i.subject||`Merge branch ${a}`}),[n]),this._onGraphUpdate(),this}tag(t){return"string"==typeof t?this._graph.getUserApi().tag({name:t,ref:this._branch.name}):this._graph.getUserApi().tag(Object.assign({},t,{ref:this._branch.name})),this}checkout(){const t=this._branch,e=this._graph.refs.getCommit(t.name);return this._graph.currentBranch=t,e&&this._graph.refs.set("HEAD",e),this}_commitWithParents(t,e){const s=this._graph.refs.getCommit(this._branch.name);s?e.unshift(s):this._branch.parentCommitHash&&e.unshift(this._branch.parentCommitHash);const{tag:a}=t,o=r(t,["tag"]),n=new i.Commit(Object.assign({hash:this._graph.generateCommitHash(),author:this._branch.commitDefaultOptions.author||this._graph.author,subject:this._branch.commitDefaultOptions.subject||this._graph.commitMessage},o,{parents:e,style:this._getCommitStyle(t.style)}));if(s){this._graph.refs.getNames(s).forEach(t=>this._graph.refs.set(t,n.hash))}else this._graph.refs.set(this._branch.name,n.hash);this._graph.commits.push(n),this.checkout(),a&&this.tag(a)}_areCommitsConnected(t,e){const s=this._graph.commits.find(({hash:t})=>e===t);return!!s&&(!(0===s.parents.length)&&(!!s.parents.includes(t)||s.parents.some(e=>this._areCommitsConnected(t,e))))}_fastForwardTo(t){this._graph.refs.set(this._branch.name,t)}_getCommitStyle(t={}){return Object.assign({},a.withoutUndefinedKeys(this._graph.template.commit),a.withoutUndefinedKeys(this._branch.commitDefaultOptions.style),t,{message:Object.assign({},a.withoutUndefinedKeys(this._graph.template.commit.message),a.withoutUndefinedKeys(this._branch.commitDefaultOptions.style.message),t.message,a.withoutUndefinedKeys({display:this._graph.shouldDisplayCommitMessage&&void 0})),dot:Object.assign({},a.withoutUndefinedKeys(this._graph.template.commit.dot),a.withoutUndefinedKeys(this._branch.commitDefaultOptions.style.dot),t.dot)})}}s.BranchUserApi=o},{"../commit":5,"../utils":17}],16:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("../commit"),i=t("../branch"),a=t("../refs");s.GitgraphUserApi=class{constructor(t,e){this._graph=t,this._onGraphUpdate=e}clear(){return this._graph.refs=new a.Refs,this._graph.tags=new a.Refs,this._graph.commits=[],this._graph.branches=new Map,this._graph.currentBranch=this._graph.createBranch("master"),this._onGraphUpdate(),this}commit(t){return this._graph.currentBranch.getUserApi().commit(t),this}branch(t){return this._graph.createBranch(t).getUserApi()}tag(...t){let e,s,r,i,a;if("string"==typeof t[0]?(e=t[0],s=t[1]):(e=t[0].name,s=t[0].ref,r=t[0].style,i=t[0].render),!s){const t=this._graph.refs.getCommit("HEAD");if(!t)return this;s=t}if(this._graph.refs.hasCommit(s)&&(a=s),this._graph.refs.hasName(s)&&(a=this._graph.refs.getCommit(s)),!a)throw new Error(`The ref "${s}" does not exist`);return this._graph.tags.set(e,a),this._graph.tagStyles[e]=r,this._graph.tagRenders[e]=i,this._onGraphUpdate(),this}import(t){const e=new Error("Only `git2json` format is supported for imported data.");if(!Array.isArray(t))throw e;if(!t.every(t=>"object"==typeof t&&"object"==typeof t.author&&Array.isArray(t.refs)))throw e;const s=t.map(t=>Object.assign({},t,{style:Object.assign({},this._graph.template.commit,{message:Object.assign({},this._graph.template.commit.message,{display:this._graph.shouldDisplayCommitMessage})}),author:`${t.author.name} <${t.author.email}>`})).reverse();this.clear(),this._graph.commits=s.map(t=>new r.Commit(t)),s.forEach(({refs:t,hash:e})=>{t&&e&&(t.map(t=>t.split("tag: ")).map(([t,e])=>e).filter(t=>"string"==typeof t).forEach(t=>this._graph.tags.set(t,e)),t.filter(t=>!t.startsWith("tag: ")).forEach(t=>this._graph.refs.set(t,e)))});const i=this._getBranches();return this._graph.commits.map(t=>this._withBranches(i,t)).reduce((t,e)=>e.branches?(e.branches.forEach(e=>t.add(e)),t):t,new Set).forEach(t=>this.branch(t)),this._onGraphUpdate(),this}_withBranches(t,e){let s=Array.from((t.get(e.hash)||new Set).values());return 0===s.length&&(s=[i.DELETED_BRANCH_NAME]),e.setBranches(s)}_getBranches(){const t=new Map,e=[];return this._graph.refs.getAllNames().filter(t=>"HEAD"!==t).forEach(s=>{const r=this._graph.refs.getCommit(s);for(r&&e.push(r);e.length>0;){const r=e.pop(),i=this._graph.commits.find(({hash:t})=>t===r),a=t.get(r)||new Set;a.add(s),t.set(r,a),i&&i.parents&&i.parents.length>0&&e.push(i.parents[0])}}),t}}},{"../branch":1,"../commit":5,"../refs":12}],17:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./orientation");function i(t,e){return Object.assign({},e.reduce((e,s)=>Object.assign({},e,{[s]:t[s]}),{}))}function a(t){return void 0===t}s.booleanOptionOr=function(t,e){return"boolean"==typeof t?t:e},s.numberOptionOr=function(t,e){return"number"==typeof t?t:e},s.pick=i,s.debug=function(t,e){console.log(JSON.stringify(t.map(t=>i(t,e)),null,2))},s.isUndefined=a,s.withoutUndefinedKeys=function(t={}){return Object.keys(t).reduce((e,s)=>a(t[s])?e:Object.assign({},e,{[s]:t[s]}),{})},s.arrowSvgPath=function(t,e,s){const i=s.style.dot.size,a=t.template.arrow.size,o=i+t.template.arrow.offset,n=Math.PI/7,h=function(t,e,s){const i=e.x-s.x,a=e.y-s.y,o=t.template.commit.spacing;let n,h;switch(t.orientation){case r.Orientation.Horizontal:n=a,h=-o;break;case r.Orientation.HorizontalReverse:n=a,h=o;break;case r.Orientation.VerticalReverse:n=-o,h=i;break;default:n=o,h=i}return t.isVertical?Math.abs(a)>o&&(h=0):Math.abs(i)>o&&(n=0),t.reverseArrow&&(n*=-1,h*=-1),Math.atan2(n,h)}(t,e,s),c=o*Math.cos(h),m=o*Math.sin(h),l=(o+a)*Math.cos(h-n),p=(o+a)*Math.sin(h-n),u=(o+a/2)*Math.cos(h),g=(o+a/2)*Math.sin(h),f=(o+a)*Math.cos(h+n),d=(o+a)*Math.sin(h+n);return`M${c},${m} L${l},${p} Q${u},${g} ${f},${d} L${f},${d}`}},{"./orientation":11}]},{},[4]);
!function(){return function t(e,s,r){function i(o,n){if(!s[o]){if(!e[o]){var h="function"==typeof require&&require;if(!n&&h)return h(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var m=s[o]={exports:{}};e[o][0].call(m.exports,function(t){return i(e[o][1][t]||t)},m,m.exports,t,e,s,r)}return s[o].exports}for(var a="function"==typeof require&&require,o=0;o<r.length;o++)i(r[o]);return i}}()({1:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./user-api/branch-user-api"),i="";s.DELETED_BRANCH_NAME=i;class a{constructor(t){this.gitgraph=t.gitgraph,this.name=t.name,this.style=t.style,this.parentCommitHash=t.parentCommitHash,this.commitDefaultOptions=t.commitDefaultOptions||{style:{}},this.onGraphUpdate=t.onGraphUpdate,this.renderLabel=t.renderLabel}getUserApi(){return new r.BranchUserApi(this,this.gitgraph,this.onGraphUpdate)}isDeleted(){return this.name===i}}s.Branch=a,s.createDeletedBranch=function(t,e,s){return new a({name:i,gitgraph:t,style:e,onGraphUpdate:s})}},{"./user-api/branch-user-api":15}],2:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.BranchesOrder=class{constructor(t,e,s){this.branches=new Set,this.colors=e,t.forEach(t=>this.branches.add(t.branchToDisplay)),s&&(this.branches=new Set(Array.from(this.branches).sort(s)))}get(t){return Array.from(this.branches).findIndex(e=>e===t)}getColorOf(t){return this.colors[this.get(t)%this.colors.length]}}},{}],3:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./utils");s.BranchesPathsCalculator=class{constructor(t,e,s,r,i,a){this.branchesPaths=new Map,this.commits=t,this.branches=e,this.commitSpacing=s,this.isGraphVertical=r,this.isGraphReverse=i,this.createDeletedBranch=a}execute(){return this.fromCommits(),this.withMergeCommits(),this.smoothBranchesPaths()}fromCommits(){this.commits.forEach(t=>{let e=this.branches.get(t.branchToDisplay);e||(e=this.getDeletedBranchInPath()||this.createDeletedBranch());const s=[],r=this.branchesPaths.get(e),i=this.commits.find(({hash:e})=>e===t.parents[0]);r?s.push(...r):i&&s.push({x:i.x,y:i.y}),s.push({x:t.x,y:t.y}),this.branchesPaths.set(e,s)})}withMergeCommits(){this.commits.filter(({parents:t})=>t.length>1).forEach(t=>{const e=this.commits.find(({hash:e})=>e===t.parents[1]);if(!e)return;const s=e.branches?e.branches[0]:"";let r=this.branches.get(s);if(!r&&!(r=this.getDeletedBranchInPath()))return;const i=[...this.branchesPaths.get(r)||[]];this.branchesPaths.set(r,[...i,{x:t.x,y:t.y,mergeCommit:!0}])})}getDeletedBranchInPath(){return Array.from(this.branchesPaths.keys()).find(t=>t.isDeleted())}smoothBranchesPaths(){const t=new Map;return this.branchesPaths.forEach((e,s)=>{if(e.length<=1)return void t.set(s,[e]);e=this.isGraphVertical?e.sort((t,e)=>t.y>e.y?-1:1):e.sort((t,e)=>t.x>e.x?1:-1),this.isGraphReverse&&(e=e.reverse());const i=e.reduce((t,s,i)=>{if(s.mergeCommit){t[t.length-1].push(r.pick(s,["x","y"]));let a=i-1,o=e[a];for(;a>=0&&o.mergeCommit;)o=e[--a];a>=0&&t.push([o])}else t[t.length-1].push(s);return t},[[]]);this.isGraphReverse&&i.forEach(t=>t.reverse()),this.isGraphVertical?i.forEach(e=>{if(e.length<=1)return;const r=e[0],i=e[e.length-1],a=e[1].x,o=Math.round(Math.abs(r.y-i.y)/this.commitSpacing)-1,n=o>0?new Array(o).fill(0).map((t,s)=>({x:a,y:e[0].y-this.commitSpacing*(s+1)})):[],h=t.get(s)||[];t.set(s,[...h,[r,...n,i]])}):i.forEach(e=>{if(e.length<=1)return;const r=e[0],i=e[e.length-1],a=e[1].y,o=Math.round(Math.abs(r.x-i.x)/this.commitSpacing)-1,n=o>0?new Array(o).fill(0).map((t,s)=>({y:a,x:e[0].x+this.commitSpacing*(s+1)})):[],h=t.get(s)||[];t.set(s,[...h,[r,...n,i]])})}),t}},s.toSvgPath=function(t,e,s){return t.map(t=>"M"+t.map(({x:t,y:r},i,a)=>{if(e&&a.length>1&&(1===i||i===a.length-1)){const e=a[i-1];if(s){const s=(e.y+r)/2;return`C ${e.x} ${s} ${t} ${s} ${t} ${r}`}{const s=(e.x+t)/2;return`C ${s} ${e.y} ${s} ${r} ${t} ${r}`}}return`L ${t} ${r}`}).join(" ").slice(1)).join(" ")}},{"./utils":17}],4:[function(t,e,s){var r;r=function(){"use strict";Object.defineProperty(s,"__esModule",{value:!0});var e=t("./gitgraph");s.GitgraphCore=e.GitgraphCore;var r=t("./mode");s.Mode=r.Mode;var i=t("./user-api/gitgraph-user-api");s.GitgraphUserApi=i.GitgraphUserApi;var a=t("./user-api/branch-user-api");s.BranchUserApi=a.BranchUserApi;var o=t("./branch");s.Branch=o.Branch;var n=t("./commit");s.Commit=n.Commit;var h=t("./tag");s.Tag=h.Tag;var c=t("./refs");s.Refs=c.Refs;var m=t("./template");s.MergeStyle=m.MergeStyle,s.TemplateName=m.TemplateName,s.templateExtend=m.templateExtend;var l=t("./orientation");s.Orientation=l.Orientation;var p=t("./branches-paths");s.toSvgPath=p.toSvgPath;var g=t("./utils");s.arrowSvgPath=g.arrowSvgPath},"object"==typeof s&&void 0!==e?r():"function"==typeof define&&define.amd?define(r):r()},{"./branch":1,"./branches-paths":3,"./commit":5,"./gitgraph":6,"./mode":10,"./orientation":11,"./refs":12,"./tag":13,"./template":14,"./user-api/branch-user-api":15,"./user-api/gitgraph-user-api":16,"./utils":17}],5:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./tag"),i=()=>(Math.random().toString(16).substring(3)+Math.random().toString(16).substring(3)+Math.random().toString(16).substring(3)+Math.random().toString(16).substring(3)).substring(0,40);class a{constructor(t){let e,s;this.refs=[],this.x=0,this.y=0;try{[,e,s]=t.author.match(/(.*) <(.*)>/)}catch(r){[e,s]=[t.author,""]}this.author={name:e,email:s,timestamp:Date.now()},this.committer={name:e,email:s,timestamp:Date.now()},this.subject=t.subject,this.body=t.body||"",this.hash=t.hash||i(),this.hashAbbrev=this.hash.substring(0,7),this.parents=t.parents?t.parents:[],this.parentsAbbrev=this.parents.map(t=>t.substring(0,7)),this.style=Object.assign({},t.style,{message:Object.assign({},t.style.message),dot:Object.assign({},t.style.dot)}),this.dotText=t.dotText,this.onClick=(()=>t.onClick?t.onClick(this):void 0),this.onMessageClick=(()=>t.onMessageClick?t.onMessageClick(this):void 0),this.onMouseOver=(()=>t.onMouseOver?t.onMouseOver(this):void 0),this.onMouseOut=(()=>t.onMouseOut?t.onMouseOut(this):void 0),this.renderDot=t.renderDot,this.renderMessage=t.renderMessage,this.renderTooltip=t.renderTooltip}get message(){let t="";return this.style.message.displayHash&&(t+=`${this.hashAbbrev} `),t+=this.subject,this.style.message.displayAuthor&&(t+=` - ${this.author.name} <${this.author.email}>`),t}get branchToDisplay(){return this.branches?this.branches[0]:""}setRefs(t){return this.refs=t.getNames(this.hash),this}setTags(t,e,s){return this.tags=t.getNames(this.hash).map(t=>new r.Tag(t,e(t),s(t),this.style)),this}setBranches(t){return this.branches=t,this}setPosition({x:t,y:e}){return this.x=t,this.y=e,this}withDefaultColor(t){const e=Object.assign({},this.style,{dot:Object.assign({},this.style.dot),message:Object.assign({},this.style.message)});e.color||(e.color=t),e.dot.color||(e.dot.color=t),e.message.color||(e.message.color=t);const s=this.cloneCommit();return s.style=e,s}cloneCommit(){const t=new a({author:`${this.author.name} <${this.author.email}>`,subject:this.subject,style:this.style,body:this.body,hash:this.hash,parents:this.parents,dotText:this.dotText,onClick:this.onClick,onMessageClick:this.onMessageClick,onMouseOver:this.onMouseOver,onMouseOut:this.onMouseOut,renderDot:this.renderDot,renderMessage:this.renderMessage,renderTooltip:this.renderTooltip});return t.refs=this.refs,t.branches=this.branches,t.tags=this.tags,t.x=this.x,t.y=this.y,t}}s.Commit=a},{"./tag":13}],6:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./branch"),i=t("./graph-rows"),a=t("./mode"),o=t("./branches-order"),n=t("./template"),h=t("./refs"),c=t("./branches-paths"),m=t("./utils"),l=t("./orientation"),p=t("./user-api/gitgraph-user-api");s.GitgraphCore=class{constructor(t={}){this.refs=new h.Refs,this.tags=new h.Refs,this.tagStyles={},this.tagRenders={},this.commits=[],this.branches=new Map,this.listeners=[],this.nextTimeoutId=null,this.template=n.getTemplate(t.template),this.currentBranch=this.createBranch("master"),this.orientation=t.orientation,this.reverseArrow=m.booleanOptionOr(t.reverseArrow,!1),this.initCommitOffsetX=m.numberOptionOr(t.initCommitOffsetX,0),this.initCommitOffsetY=m.numberOptionOr(t.initCommitOffsetY,0),this.mode=t.mode,this.author=t.author||"Sergio Flores <saxo-guy@epic.com>",this.commitMessage=t.commitMessage||"He doesn't like George Michael! Boooo!",this.generateCommitHash="function"==typeof t.generateCommitHash?t.generateCommitHash:()=>void 0,this.branchesOrderFunction="function"==typeof t.compareBranchesOrder?t.compareBranchesOrder:void 0,this.branchLabelOnEveryCommit=m.booleanOptionOr(t.branchLabelOnEveryCommit,!1)}get isHorizontal(){return this.orientation===l.Orientation.Horizontal||this.orientation===l.Orientation.HorizontalReverse}get isVertical(){return!this.isHorizontal}get isReverse(){return this.orientation===l.Orientation.HorizontalReverse||this.orientation===l.Orientation.VerticalReverse}get shouldDisplayCommitMessage(){return!this.isHorizontal&&this.mode!==a.Mode.Compact}getUserApi(){return new p.GitgraphUserApi(this,()=>this.next())}subscribe(t){this.listeners.push(t);let e=!0;return()=>{if(!e)return;e=!1;const s=this.listeners.indexOf(t);this.listeners.splice(s,1)}}getRenderedData(){const t=this.computeRenderedCommits(),e=this.computeRenderedBranchesPaths(t),s=this.computeCommitMessagesX(e);return this.computeBranchesColor(t,e),{commits:t,branchesPaths:e,commitMessagesX:s}}createBranch(t){let e={gitgraph:this,name:"",parentCommitHash:this.refs.getCommit("HEAD"),style:this.template.branch,onGraphUpdate:()=>this.next()};if("string"==typeof t)e.name=t,e.parentCommitHash=this.refs.getCommit("HEAD");else{const s=t.from?t.from.name:"HEAD",r=this.refs.getCommit(s)||(this.refs.hasCommit(t.from)?t.from:void 0);t.style=t.style||{},e=Object.assign({},e,t,{parentCommitHash:r,style:Object.assign({},e.style,t.style,{label:Object.assign({},e.style.label,t.style.label)})})}const s=new r.Branch(e);return this.branches.set(s.name,s),s}computeRenderedCommits(){const t=this.getBranches(),e=(()=>{const e=new Set(this.commits.reduce((e,{hash:s})=>t.has(s)?e:[...e,s],[])),s=this.commits.reduce((t,e)=>e.parents.length>1?[...t,...e.parents.slice(1).map(t=>this.commits.find(({hash:e})=>t===e))]:t,[]),r=new Set;return s.forEach(t=>{let s=t;for(;s&&e.has(s.hash);)r.add(s.hash),s=s.parents.length>0?this.commits.find(({hash:t})=>s.parents[0]===t):void 0}),r})(),s=this.commits.filter(({hash:s})=>t.has(s)||e.has(s)),r=s.map(e=>this.withBranches(t,e)),a=i.createGraphRows(this.mode,s),n=new o.BranchesOrder(r,this.template.colors,this.branchesOrderFunction);return r.map(t=>t.setRefs(this.refs)).map(t=>this.withPosition(a,n,t)).map(t=>t.withDefaultColor(this.getBranchDefaultColor(n,t.branchToDisplay))).map(t=>t.setTags(this.tags,t=>Object.assign({},this.tagStyles[t],this.template.tag),t=>this.tagRenders[t]))}computeRenderedBranchesPaths(t){return new c.BranchesPathsCalculator(t,this.branches,this.template.commit.spacing,this.isVertical,this.isReverse,()=>r.createDeletedBranch(this,this.template.branch,()=>this.next())).execute()}computeBranchesColor(t,e){const s=new o.BranchesOrder(t,this.template.colors,this.branchesOrderFunction);Array.from(e).forEach(([t])=>{t.computedColor=t.style.color||this.getBranchDefaultColor(s,t.name)})}computeCommitMessagesX(t){return Array.from(t).length*this.template.branch.spacing}withBranches(t,e){let s=Array.from((t.get(e.hash)||new Set).values());return 0===s.length&&(s=[r.DELETED_BRANCH_NAME]),e.setBranches(s)}getBranches(){const t=new Map,e=[];return this.refs.getAllNames().filter(t=>"HEAD"!==t).forEach(s=>{const r=this.refs.getCommit(s);for(r&&e.push(r);e.length>0;){const r=e.pop(),i=this.commits.find(({hash:t})=>t===r),a=t.get(r)||new Set;a.add(s),t.set(r,a),i&&i.parents&&i.parents.length>0&&e.push(i.parents[0])}}),t}withPosition(t,e,s){const r=t.getRowOf(s.hash),i=t.getMaxRow(),a=e.get(s.branchToDisplay);switch(this.orientation){default:return s.setPosition({x:this.initCommitOffsetX+this.template.branch.spacing*a,y:this.initCommitOffsetY+this.template.commit.spacing*(i-r)});case l.Orientation.VerticalReverse:return s.setPosition({x:this.initCommitOffsetX+this.template.branch.spacing*a,y:this.initCommitOffsetY+this.template.commit.spacing*r});case l.Orientation.Horizontal:return s.setPosition({x:this.initCommitOffsetX+this.template.commit.spacing*r,y:this.initCommitOffsetY+this.template.branch.spacing*a});case l.Orientation.HorizontalReverse:return s.setPosition({x:this.initCommitOffsetX+this.template.commit.spacing*(i-r),y:this.initCommitOffsetY+this.template.branch.spacing*a})}}getBranchDefaultColor(t,e){return t.getColorOf(e)}next(){this.nextTimeoutId&&window.clearTimeout(this.nextTimeoutId),this.nextTimeoutId=window.setTimeout(()=>{this.listeners.forEach(t=>t(this.getRenderedData()))},0)}}},{"./branch":1,"./branches-order":2,"./branches-paths":3,"./graph-rows":8,"./mode":10,"./orientation":11,"./refs":12,"./template":14,"./user-api/gitgraph-user-api":16,"./utils":17}],7:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./regular");s.CompactGraphRows=class extends r.RegularGraphRows{computeRowsFromCommits(t){t.forEach((e,s)=>{let r=s;if(0!==s){const i=this.getRowOf(e.parents[0]),a=t[s-1];r=Math.max(i+1,this.getRowOf(a.hash)),e.parents.length>1&&i<this.getRowOf(e.parents[1])&&r++}this.rows.set(e.hash,r)})}}},{"./regular":9}],8:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("../mode"),i=t("./compact"),a=t("./regular");s.GraphRows=a.RegularGraphRows,s.createGraphRows=function(t,e){return t===r.Mode.Compact?new i.CompactGraphRows(e):new a.RegularGraphRows(e)}},{"../mode":10,"./compact":7,"./regular":9}],9:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.RegularGraphRows=class{constructor(t){this.rows=new Map,this.maxRowCache=void 0,this.computeRowsFromCommits(t)}getRowOf(t){return this.rows.get(t)||0}getMaxRow(){return void 0===this.maxRowCache&&(this.maxRowCache=function(t){const e=new Set;return t.forEach(t=>e.add(t)),Array.from(e)}(Array.from(this.rows.values())).length-1),this.maxRowCache}computeRowsFromCommits(t){t.forEach((t,e)=>{this.rows.set(t.hash,e)}),this.maxRowCache=void 0}}},{}],10:[function(t,e,s){"use strict";var r;Object.defineProperty(s,"__esModule",{value:!0}),function(t){t.Compact="compact"}(r||(r={})),s.Mode=r},{}],11:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),function(t){t.VerticalReverse="vertical-reverse",t.Horizontal="horizontal",t.HorizontalReverse="horizontal-reverse"}(s.Orientation||(s.Orientation={}))},{}],12:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.Refs=class{constructor(){this.commitPerName=new Map,this.namesPerCommit=new Map}set(t,e){const s=this.commitPerName.get(t);return s&&this.removeNameFrom(s,t),this.addNameTo(e,t),this.addCommitTo(t,e),this}delete(t){return this.hasName(t)&&(this.removeNameFrom(this.getCommit(t),t),this.commitPerName.delete(t)),this}getCommit(t){return this.commitPerName.get(t)}getNames(t){return this.namesPerCommit.get(t)||[]}getAllNames(){return Array.from(this.commitPerName.keys())}hasCommit(t){return this.namesPerCommit.has(t)}hasName(t){return this.commitPerName.has(t)}removeNameFrom(t,e){const s=this.namesPerCommit.get(t)||[];this.namesPerCommit.set(t,s.filter(t=>t!==e))}addNameTo(t,e){const s=this.namesPerCommit.get(t)||[];this.namesPerCommit.set(t,[...s,e])}addCommitTo(t,e){this.commitPerName.set(t,e)}}},{}],13:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./template"),i=t("./utils");s.Tag=class{constructor(t,e,s,r){this.name=t,this.tagStyle=e,this.commitStyle=r,this.render=s}get style(){return{strokeColor:this.tagStyle.strokeColor||this.commitStyle.color,bgColor:this.tagStyle.bgColor||this.commitStyle.color,color:this.tagStyle.color||"white",font:this.tagStyle.font||this.commitStyle.message.font||r.DEFAULT_FONT,borderRadius:i.numberOptionOr(this.tagStyle.borderRadius,10),pointerWidth:i.numberOptionOr(this.tagStyle.pointerWidth,12)}}}},{"./template":14,"./utils":17}],14:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./utils");var i;!function(t){t.Bezier="bezier",t.Straight="straight"}(i||(i={})),s.MergeStyle=i,s.DEFAULT_FONT="normal 12pt Calibri";class a{constructor(t){t.branch=t.branch||{},t.branch.label=t.branch.label||{},t.arrow=t.arrow||{},t.commit=t.commit||{},t.commit.dot=t.commit.dot||{},t.commit.message=t.commit.message||{},this.colors=t.colors||["#000000"],this.branch={color:t.branch.color,lineWidth:t.branch.lineWidth||2,mergeStyle:t.branch.mergeStyle||i.Bezier,spacing:r.numberOptionOr(t.branch.spacing,20),label:{display:r.booleanOptionOr(t.branch.label.display,!0),color:t.branch.label.color||t.commit.color,strokeColor:t.branch.label.strokeColor||t.commit.color,bgColor:t.branch.label.bgColor||"white",font:t.branch.label.font||t.commit.message.font||s.DEFAULT_FONT,borderRadius:r.numberOptionOr(t.branch.label.borderRadius,10)}},this.arrow={size:t.arrow.size||null,color:t.arrow.color||null,offset:t.arrow.offset||2},this.commit={color:t.commit.color,spacing:r.numberOptionOr(t.commit.spacing,25),hasTooltipInCompactMode:r.booleanOptionOr(t.commit.hasTooltipInCompactMode,!0),dot:{color:t.commit.dot.color||t.commit.color,size:t.commit.dot.size||3,strokeWidth:r.numberOptionOr(t.commit.dot.strokeWidth,0),strokeColor:t.commit.dot.strokeColor,font:t.commit.dot.font||t.commit.message.font||"normal 10pt Calibri"},message:{display:r.booleanOptionOr(t.commit.message.display,!0),displayAuthor:r.booleanOptionOr(t.commit.message.displayAuthor,!0),displayHash:r.booleanOptionOr(t.commit.message.displayHash,!0),color:t.commit.message.color||t.commit.color,font:t.commit.message.font||s.DEFAULT_FONT}},this.tag=t.tag||{}}}s.Template=a;const o=new a({colors:["#6963FF","#47E8D4","#6BDB52","#E84BA5","#FFA657"],branch:{color:"#000000",lineWidth:4,spacing:50,mergeStyle:i.Straight},commit:{spacing:60,dot:{size:16,strokeColor:"#000000",strokeWidth:4},message:{color:"black"}},arrow:{size:16,offset:-1.5}});s.blackArrowTemplate=o;const n=new a({colors:["#979797","#008fb5","#f1c109"],branch:{lineWidth:10,spacing:50},commit:{spacing:80,dot:{size:14},message:{font:"normal 14pt Arial"}}});var h;function c(t){return t?"string"==typeof t?{[h.BlackArrow]:o,[h.Metro]:n}[t]:t:n}s.metroTemplate=n,function(t){t.Metro="metro",t.BlackArrow="blackarrow"}(h||(h={})),s.TemplateName=h,s.templateExtend=function(t,e){const s=c(t);return e.branch||(e.branch={}),e.commit||(e.commit={}),{colors:e.colors||s.colors,arrow:Object.assign({},s.arrow,e.arrow),branch:Object.assign({},s.branch,e.branch,{label:Object.assign({},s.branch.label,e.branch.label)}),commit:Object.assign({},s.commit,e.commit,{dot:Object.assign({},s.commit.dot,e.commit.dot),message:Object.assign({},s.commit.message,e.commit.message)}),tag:Object.assign({},s.tag,e.tag)}},s.getTemplate=c},{"./utils":17}],15:[function(t,e,s){"use strict";var r=this&&this.__rest||function(t,e){var s={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(s[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(s[r[i]]=t[r[i]])}return s};Object.defineProperty(s,"__esModule",{value:!0});const i=t("../commit"),a=t("../branch"),o=t("../utils");class n{constructor(t,e,s){this._branch=t,this.name=t.name,this._graph=e,this._onGraphUpdate=s}branch(t){if(this._branch.isDeleted()&&!this._isReferenced())throw new Error(`Cannot branch from the deleted branch "${this.name}"`);const e="string"==typeof t?{name:t}:t;return e.from=this,this._graph.createBranch(e).getUserApi()}commit(t){if(this._branch.isDeleted()&&!this._isReferenced())throw new Error(`Cannot commit on the deleted branch "${this.name}"`);return"string"==typeof t&&(t={subject:t}),t||(t={}),this._commitWithParents(t,[]),this._onGraphUpdate(),this}delete(){if(this._graph.refs.getCommit("HEAD")===this._graph.refs.getCommit(this.name))throw new Error(`Cannot delete the checked out branch "${this.name}"`);return[...function*(t,e){const s=(t,e)=>t.commits.find(({hash:t})=>t===e);let r=s(t,t.refs.getCommit(e.name));for(;r&&r.hash!==e.parentCommitHash;)yield r,r=s(t,r.parents[0])}(this._graph,this._branch)].forEach(t=>{t.refs=t.refs.filter(t=>t!==this.name)}),this._graph.refs.delete(this.name),this._graph.branches.delete(this.name),this._branch=a.createDeletedBranch(this._graph,this._branch.style,()=>{}),this._onGraphUpdate(),this}merge(...t){if(this._branch.isDeleted()&&!this._isReferenced())throw new Error(`Cannot merge to the deleted branch "${this.name}"`);let e=t[0];(function(t){return"object"==typeof t&&!(t instanceof n)})(e)||(e={branch:t[0],fastForward:!1,commitOptions:{subject:t[1]}});const{branch:s,fastForward:r,commitOptions:i}=e,a="string"==typeof s?s:s.name,o=this._graph.refs.getCommit(a);if(!o)throw new Error(`The branch called "${a}" is unknown`);let h=!1;if(r){const t=this._graph.refs.getCommit(this._branch.name);t&&(h=this._areCommitsConnected(t,o))}return r&&h?this._fastForwardTo(o):this._commitWithParents(Object.assign({},i,{subject:i&&i.subject||`Merge branch ${a}`}),[o]),this._onGraphUpdate(),this}tag(t){if(this._branch.isDeleted()&&!this._isReferenced())throw new Error(`Cannot tag on the deleted branch "${this.name}"`);return"string"==typeof t?this._graph.getUserApi().tag({name:t,ref:this._branch.name}):this._graph.getUserApi().tag(Object.assign({},t,{ref:this._branch.name})),this}checkout(){if(this._branch.isDeleted()&&!this._isReferenced())throw new Error(`Cannot checkout the deleted branch "${this.name}"`);const t=this._branch,e=this._graph.refs.getCommit(t.name);return this._graph.currentBranch=t,e&&this._graph.refs.set("HEAD",e),this}_commitWithParents(t,e){const s=this._graph.refs.getCommit(this._branch.name);s?e.unshift(s):this._branch.parentCommitHash&&e.unshift(this._branch.parentCommitHash);const{tag:a}=t,o=r(t,["tag"]),n=new i.Commit(Object.assign({hash:this._graph.generateCommitHash(),author:this._branch.commitDefaultOptions.author||this._graph.author,subject:this._branch.commitDefaultOptions.subject||this._graph.commitMessage},o,{parents:e,style:this._getCommitStyle(t.style)}));if(s){this._graph.refs.getNames(s).forEach(t=>this._graph.refs.set(t,n.hash))}else this._graph.refs.set(this._branch.name,n.hash);this._graph.commits.push(n),this.checkout(),a&&this.tag(a)}_areCommitsConnected(t,e){const s=this._graph.commits.find(({hash:t})=>e===t);return!!s&&(!(0===s.parents.length)&&(!!s.parents.includes(t)||s.parents.some(e=>this._areCommitsConnected(t,e))))}_fastForwardTo(t){this._graph.refs.set(this._branch.name,t)}_getCommitStyle(t={}){return Object.assign({},o.withoutUndefinedKeys(this._graph.template.commit),o.withoutUndefinedKeys(this._branch.commitDefaultOptions.style),t,{message:Object.assign({},o.withoutUndefinedKeys(this._graph.template.commit.message),o.withoutUndefinedKeys(this._branch.commitDefaultOptions.style.message),t.message,o.withoutUndefinedKeys({display:this._graph.shouldDisplayCommitMessage&&void 0})),dot:Object.assign({},o.withoutUndefinedKeys(this._graph.template.commit.dot),o.withoutUndefinedKeys(this._branch.commitDefaultOptions.style.dot),t.dot)})}_isReferenced(){return this._graph.branches.has(this.name)||this._graph.refs.hasName(this.name)||this._graph.commits.reduce((t,{refs:e})=>[...t,...e],[]).includes(this.name)}}s.BranchUserApi=n},{"../branch":1,"../commit":5,"../utils":17}],16:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("../commit"),i=t("../branch"),a=t("../refs");s.GitgraphUserApi=class{constructor(t,e){this._graph=t,this._onGraphUpdate=e}clear(){return this._graph.refs=new a.Refs,this._graph.tags=new a.Refs,this._graph.commits=[],this._graph.branches=new Map,this._graph.currentBranch=this._graph.createBranch("master"),this._onGraphUpdate(),this}commit(t){return this._graph.currentBranch.getUserApi().commit(t),this}branch(t){return this._graph.createBranch(t).getUserApi()}tag(...t){let e,s,r,i,a;if("string"==typeof t[0]?(e=t[0],s=t[1]):(e=t[0].name,s=t[0].ref,r=t[0].style,i=t[0].render),!s){const t=this._graph.refs.getCommit("HEAD");if(!t)return this;s=t}if(this._graph.refs.hasCommit(s)&&(a=s),this._graph.refs.hasName(s)&&(a=this._graph.refs.getCommit(s)),!a)throw new Error(`The ref "${s}" does not exist`);return this._graph.tags.set(e,a),this._graph.tagStyles[e]=r,this._graph.tagRenders[e]=i,this._onGraphUpdate(),this}import(t){const e=new Error("Only `git2json` format is supported for imported data.");if(!Array.isArray(t))throw e;if(!t.every(t=>"object"==typeof t&&"object"==typeof t.author&&Array.isArray(t.refs)))throw e;const s=t.map(t=>Object.assign({},t,{style:Object.assign({},this._graph.template.commit,{message:Object.assign({},this._graph.template.commit.message,{display:this._graph.shouldDisplayCommitMessage})}),author:`${t.author.name} <${t.author.email}>`})).reverse();this.clear(),this._graph.commits=s.map(t=>new r.Commit(t)),s.forEach(({refs:t,hash:e})=>{t&&e&&(t.map(t=>t.split("tag: ")).map(([t,e])=>e).filter(t=>"string"==typeof t).forEach(t=>this._graph.tags.set(t,e)),t.filter(t=>!t.startsWith("tag: ")).forEach(t=>this._graph.refs.set(t,e)))});const i=this._getBranches();return this._graph.commits.map(t=>this._withBranches(i,t)).reduce((t,e)=>e.branches?(e.branches.forEach(e=>t.add(e)),t):t,new Set).forEach(t=>this.branch(t)),this._onGraphUpdate(),this}_withBranches(t,e){let s=Array.from((t.get(e.hash)||new Set).values());return 0===s.length&&(s=[i.DELETED_BRANCH_NAME]),e.setBranches(s)}_getBranches(){const t=new Map,e=[];return this._graph.refs.getAllNames().filter(t=>"HEAD"!==t).forEach(s=>{const r=this._graph.refs.getCommit(s);for(r&&e.push(r);e.length>0;){const r=e.pop(),i=this._graph.commits.find(({hash:t})=>t===r),a=t.get(r)||new Set;a.add(s),t.set(r,a),i&&i.parents&&i.parents.length>0&&e.push(i.parents[0])}}),t}}},{"../branch":1,"../commit":5,"../refs":12}],17:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0});const r=t("./orientation");function i(t,e){return Object.assign({},e.reduce((e,s)=>Object.assign({},e,{[s]:t[s]}),{}))}function a(t){return void 0===t}s.booleanOptionOr=function(t,e){return"boolean"==typeof t?t:e},s.numberOptionOr=function(t,e){return"number"==typeof t?t:e},s.pick=i,s.debug=function(t,e){console.log(JSON.stringify(t.map(t=>i(t,e)),null,2))},s.isUndefined=a,s.withoutUndefinedKeys=function(t={}){return Object.keys(t).reduce((e,s)=>a(t[s])?e:Object.assign({},e,{[s]:t[s]}),{})},s.arrowSvgPath=function(t,e,s){const i=s.style.dot.size,a=t.template.arrow.size,o=i+t.template.arrow.offset,n=Math.PI/7,h=function(t,e,s){const i=e.x-s.x,a=e.y-s.y,o=t.template.commit.spacing;let n,h;switch(t.orientation){case r.Orientation.Horizontal:n=a,h=-o;break;case r.Orientation.HorizontalReverse:n=a,h=o;break;case r.Orientation.VerticalReverse:n=-o,h=i;break;default:n=o,h=i}return t.isVertical?Math.abs(a)>o&&(h=0):Math.abs(i)>o&&(n=0),t.reverseArrow&&(n*=-1,h*=-1),Math.atan2(n,h)}(t,e,s),c=o*Math.cos(h),m=o*Math.sin(h),l=(o+a)*Math.cos(h-n),p=(o+a)*Math.sin(h-n),g=(o+a/2)*Math.cos(h),u=(o+a/2)*Math.sin(h),f=(o+a)*Math.cos(h+n),d=(o+a)*Math.sin(h+n);return`M${c},${m} L${l},${p} Q${g},${u} ${f},${d} L${f},${d}`}},{"./orientation":11}]},{},[4]);

@@ -9,14 +9,6 @@ "use strict";

*/
const getRandomHash = () => (Math.random()
.toString(16)
.substring(3) +
Math.random()
.toString(16)
.substring(3) +
Math.random()
.toString(16)
.substring(3) +
Math.random()
.toString(16)
.substring(3)).substring(0, 40);
const getRandomHash = () => (Math.random().toString(16).substring(3) +
Math.random().toString(16).substring(3) +
Math.random().toString(16).substring(3) +
Math.random().toString(16).substring(3)).substring(0, 40);
class Commit {

@@ -23,0 +15,0 @@ constructor(options) {

@@ -126,4 +126,31 @@ "use strict";

const branches = this.getBranches();
const commitsWithBranches = this.commits.map((commit) => this.withBranches(branches, commit));
const rows = graph_rows_1.createGraphRows(this.mode, this.commits);
// Commits that are not associated to a branch in `branches`
// were in a deleted branch. If the latter was merged beforehand
// they are reachable and are rendered. Others are not
const reachableUnassociatedCommits = (() => {
const unassociatedCommits = new Set(this.commits.reduce((commits, { hash }) => !branches.has(hash) ? [...commits, hash] : commits, []));
const tipsOfMergedBranches = this.commits.reduce((tipsOfMergedBranches, commit) => commit.parents.length > 1
? [
...tipsOfMergedBranches,
...commit.parents
.slice(1)
.map((parentHash) => this.commits.find(({ hash }) => parentHash === hash)),
]
: tipsOfMergedBranches, []);
const reachableCommits = new Set();
tipsOfMergedBranches.forEach((tip) => {
let currentCommit = tip;
while (currentCommit && unassociatedCommits.has(currentCommit.hash)) {
reachableCommits.add(currentCommit.hash);
currentCommit =
currentCommit.parents.length > 0
? this.commits.find(({ hash }) => currentCommit.parents[0] === hash)
: undefined;
}
});
return reachableCommits;
})();
const commitsToRender = this.commits.filter(({ hash }) => branches.has(hash) || reachableUnassociatedCommits.has(hash));
const commitsWithBranches = commitsToRender.map((commit) => this.withBranches(branches, commit));
const rows = graph_rows_1.createGraphRows(this.mode, commitsToRender);
const branchesOrder = new branches_order_1.BranchesOrder(commitsWithBranches, this.template.colors, this.branchesOrderFunction);

@@ -130,0 +157,0 @@ return (commitsWithBranches

@@ -15,2 +15,8 @@ import { Commit } from "./commit";

/**
* Delete a reference
*
* @param name Name of the reference
*/
delete(name: Name): this;
/**
* Get the commit hash associated with the given reference name.

@@ -17,0 +23,0 @@ *

@@ -24,2 +24,14 @@ "use strict";

/**
* Delete a reference
*
* @param name Name of the reference
*/
delete(name) {
if (this.hasName(name)) {
this.removeNameFrom(this.getCommit(name), name);
this.commitPerName.delete(name);
}
return this;
}
/**
* Get the commit hash associated with the given reference name.

@@ -26,0 +38,0 @@ *

@@ -56,2 +56,6 @@ import { GitgraphCore } from "../gitgraph";

/**
* Delete the branch (as `git branch -d`)
*/
delete(): this;
/**
* Create a merge commit.

@@ -96,2 +100,3 @@ *

private _getCommitStyle;
private _isReferenced;
}

@@ -7,4 +7,6 @@ "use strict";

if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;

@@ -14,2 +16,3 @@ };

const commit_1 = require("../commit");
const branch_1 = require("../branch");
const utils_1 = require("../utils");

@@ -25,2 +28,5 @@ class BranchUserApi {

branch(args) {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot branch from the deleted branch "${this.name}"`);
}
const options = typeof args === "string" ? { name: args } : args;

@@ -31,2 +37,5 @@ options.from = this;

commit(options) {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot commit on the deleted branch "${this.name}"`);
}
// Deal with shorter syntax

@@ -41,3 +50,39 @@ if (typeof options === "string")

}
/**
* Delete the branch (as `git branch -d`)
*/
delete() {
// Delete all references to the branch from the graph (graph.branches and graph.refs)
// and from the commits (commit.refs). Then, make the branch instance a deleted branch.
// Like in git, the commits and tags in the deleted branch remain in the graph
if (this._graph.refs.getCommit("HEAD") ===
this._graph.refs.getCommit(this.name)) {
throw new Error(`Cannot delete the checked out branch "${this.name}"`);
}
const branchCommits = (function* (graph, branch) {
const lookupCommit = (graph, commitHash) => {
return graph.commits.find(({ hash }) => hash === commitHash);
};
let currentCommit = lookupCommit(graph, graph.refs.getCommit(branch.name));
while (currentCommit && currentCommit.hash !== branch.parentCommitHash) {
yield currentCommit;
currentCommit = lookupCommit(graph, currentCommit.parents[0]);
}
return;
})(this._graph, this._branch);
[...branchCommits].forEach((commit) => {
commit.refs = commit.refs.filter((branchName) => branchName !== this.name);
});
this._graph.refs.delete(this.name);
this._graph.branches.delete(this.name);
this._branch = branch_1.createDeletedBranch(this._graph, this._branch.style, () => {
// do nothing
});
this._onGraphUpdate();
return this;
}
merge(...args) {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot merge to the deleted branch "${this.name}"`);
}
let options = args[0];

@@ -75,2 +120,5 @@ if (!isBranchMergeOptions(options)) {

tag(options) {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot tag on the deleted branch "${this.name}"`);
}
if (typeof options === "string") {

@@ -88,2 +136,5 @@ this._graph.getUserApi().tag({ name: options, ref: this._branch.name });

checkout() {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot checkout the deleted branch "${this.name}"`);
}
const target = this._branch;

@@ -149,2 +200,9 @@ const headCommit = this._graph.refs.getCommit(target.name);

}
_isReferenced() {
return (this._graph.branches.has(this.name) ||
this._graph.refs.hasName(this.name) ||
this._graph.commits
.reduce((allNames, { refs }) => [...allNames, ...refs], [])
.includes(this.name));
}
}

@@ -151,0 +209,0 @@ exports.BranchUserApi = BranchUserApi;

@@ -58,3 +58,3 @@ import { Commit } from "./commit";

*/
declare function withoutUndefinedKeys<T extends object>(obj?: T): NonMatchingProp<T, undefined>;
declare function withoutUndefinedKeys<T>(obj?: T): NonMatchingProp<T, undefined>;
/**

@@ -61,0 +61,0 @@ * Return a string ready to use in `svg.path.d` to draw an arrow from params.

{
"name": "@gitgraph/core",
"version": "1.4.5",
"version": "1.5.0",
"description": "Core of gitgraph, a JavaScript library to draw pretty git graphs",

@@ -48,9 +48,9 @@ "author": "Nicolas Carlo <nicolascarlo.espeon@gmail.com>",

"devDependencies": {
"@types/node": "^9.4.6",
"@types/node": "9.4.6",
"auto-changelog": "1.12.1",
"browserify": "^14.5.0",
"npm-run-all": "^4.1.2",
"rimraf": "^2.6.2",
"rollup": "^0.51.8",
"uglify-es": "^3.3.9"
"browserify": "14.5.0",
"npm-run-all": "4.1.2",
"rimraf": "2.6.2",
"rollup": "0.51.8",
"uglify-es": "3.3.9"
},

@@ -68,3 +68,3 @@ "jest": {

},
"gitHead": "bc40f5a245d76b7c113da1f0c073d0da2e59b115"
"gitHead": "9239bab87f6f00dc4c5da1d1f5b3efec47827748"
}

@@ -191,2 +191,124 @@ import { GitgraphCore } from "../gitgraph";

});
describe("delete", () => {
let gitgraph;
let develop;
let feature;
beforeEach(() => {
gitgraph = new GitgraphCore().getUserApi();
develop = gitgraph.branch("develop");
develop.commit("develop first");
feature = gitgraph.branch("feature");
feature.commit("feature first");
});
it("should be deleted and not referenced", () => {
develop.checkout();
feature.delete();
expect(feature._branch.isDeleted() && !feature._isReferenced()).toBe(
true,
);
});
it("should leave commits and tags from the deleted branch in the graph", () => {
feature.tag("some tag");
const featureCommit = gitgraph._graph.refs.getCommit("feature");
develop.checkout();
feature.delete();
expect(
gitgraph._graph.commits.find(({ hash }) => hash === featureCommit) &&
gitgraph._graph.refs.hasCommit(featureCommit) &&
gitgraph._graph.tags.hasName("some tag"),
).toBe(true);
});
it("should throw if the branch is checked out", () => {
expect(() => feature.delete()).toThrow(
`Cannot delete the checked out branch "feature"`,
);
});
it("should throw when branching from a deleted branch", () => {
develop.checkout();
feature.delete();
expect(() => feature.branch("other-feature")).toThrow(
`Cannot branch from the deleted branch "feature"`,
);
});
it("should throw when committing on a deleted branch", () => {
develop.checkout();
feature.delete();
expect(() => feature.commit("other commit")).toThrow(
`Cannot commit on the deleted branch "feature"`,
);
});
it("should silently do nothing when deleting twice", () => {
develop.checkout();
feature.delete();
feature.delete();
expect(feature._branch.isDeleted() && !feature._isReferenced()).toBe(
true,
);
});
it("should throw when merging a deleted branch to an existing one", () => {
develop.checkout();
feature.delete();
expect(() => develop.merge(feature)).toThrow(
`The branch called "feature" is unknown`,
);
});
it("should throw when merging some branch to a deleted branch", () => {
develop.checkout();
feature.delete();
expect(() => feature.merge(develop)).toThrow(
`Cannot merge to the deleted branch "feature"`,
);
});
it("should throw when tagging on a deleted branch", () => {
develop.checkout();
feature.delete();
expect(() => feature.tag("some tag")).toThrow(
`Cannot tag on the deleted branch "feature"`,
);
});
it("should throw when checking out a deleted branch", () => {
develop.checkout();
feature.delete();
expect(() => feature.checkout()).toThrow(
`Cannot checkout the deleted branch "feature"`,
);
});
});
});

@@ -40,11 +40,5 @@ import { GitgraphCore } from "../gitgraph";

gitgraph
.branch("dev")
.commit("one")
.commit("two");
gitgraph.branch("dev").commit("one").commit("two");
gitgraph.clear();
gitgraph
.branch("feat")
.commit("three")
.commit("four");
gitgraph.branch("feat").commit("three").commit("four");

@@ -51,0 +45,0 @@ const { commits } = core.getRenderedData();

@@ -166,7 +166,3 @@ import { GitgraphCore } from "../gitgraph";

gitgraph
.commit()
.commit()
.branch("develop")
.commit();
gitgraph.commit().commit().branch("develop").commit();

@@ -229,2 +225,52 @@ const { commits } = core.getRenderedData();

});
describe("deleted branch", () => {
let gitgraph;
let master;
let develop;
beforeEach(() => {
gitgraph = new GitgraphCore().getUserApi();
master = gitgraph.branch("master");
master.commit("one");
master.commit("two");
develop = gitgraph.branch("develop");
develop.commit("three");
master.checkout();
});
it("should ignore commits on a deleted branch", () => {
develop.delete();
const { commits } = gitgraph._graph.getRenderedData();
expect(commits).toMatchObject([
{ subject: "one", refs: [] },
{ subject: "two", refs: ["master", "HEAD"] },
]);
});
it("should render commits on a deleted branch that was merged before", () => {
master.merge(develop);
develop.delete();
const { commits } = gitgraph._graph.getRenderedData();
expect(commits).toMatchObject([
{ subject: "one", refs: [] },
{ subject: "two", refs: [] },
{ subject: "three", refs: [] },
{ subject: "Merge branch develop", refs: ["master", "HEAD"] },
]);
});
});
});

@@ -82,6 +82,3 @@ import { GitgraphCore } from "../gitgraph";

gitgraph.branch("master").commit("Initial commit");
gitgraph
.branch("dev")
.commit()
.commit();
gitgraph.branch("dev").commit().commit();

@@ -88,0 +85,0 @@ const { branchesPaths } = core.getRenderedData();

@@ -10,6 +10,3 @@ import { GitgraphCore } from "../gitgraph";

gitgraph
.commit("one")
.commit("two")
.commit("three");
gitgraph.commit("one").commit("two").commit("three");

@@ -43,6 +40,3 @@ const { commits } = core.getRenderedData();

gitgraph
.commit("one")
.commit("two")
.commit("three");
gitgraph.commit("one").commit("two").commit("three");

@@ -76,6 +70,3 @@ const { commits } = core.getRenderedData();

gitgraph
.commit("one")
.commit("two")
.commit("three");
gitgraph.commit("one").commit("two").commit("three");

@@ -109,6 +100,3 @@ const { commits } = core.getRenderedData();

gitgraph
.commit("one")
.commit("two")
.commit("three");
gitgraph.commit("one").commit("two").commit("three");

@@ -590,6 +578,3 @@ const { commits } = core.getRenderedData();

const master = gitgraph
.branch("master")
.commit("one")
.commit("two");
const master = gitgraph.branch("master").commit("one").commit("two");

@@ -596,0 +581,0 @@ // Branch has more commits.

@@ -13,6 +13,3 @@ import { GitgraphCore } from "../gitgraph";

gitgraph
.commit()
.commit()
.commit();
gitgraph.commit().commit().commit();

@@ -32,11 +29,4 @@ jest.runAllTimers();

const master = gitgraph
.branch("master")
.commit()
.commit()
.commit();
const dev = gitgraph
.branch("dev")
.commit()
.commit();
const master = gitgraph.branch("master").commit().commit().commit();
const dev = gitgraph.branch("dev").commit().commit();
master.merge(dev);

@@ -57,7 +47,3 @@

const master = gitgraph
.branch("master")
.commit()
.commit()
.commit();
const master = gitgraph.branch("master").commit().commit().commit();

@@ -68,6 +54,3 @@ jest.runAllTimers();

const dev = gitgraph
.branch("dev")
.commit()
.commit();
const dev = gitgraph.branch("dev").commit().commit();
master.merge(dev);

@@ -74,0 +57,0 @@

@@ -11,6 +11,3 @@ import { GitgraphCore } from "../gitgraph";

.commit({ subject: "one-tagged", hash: "one-tagged-hash" });
gitgraph
.branch("dev")
.commit("two")
.commit("three");
gitgraph.branch("dev").commit("two").commit("three");
master.commit("four");

@@ -114,6 +111,3 @@ gitgraph.tag("this-one", "one-tagged-hash");

const master = gitgraph.branch("master").commit("one");
gitgraph
.branch("dev")
.commit("two")
.commit("three");
gitgraph.branch("dev").commit("two").commit("three");
master.commit({ subject: "four-tagged", hash: "four-tagged-hash" });

@@ -143,6 +137,3 @@ gitgraph.tag("this-one");

const master = gitgraph.branch("master").commit("one");
gitgraph
.branch("dev")
.commit("two")
.commit("three");
gitgraph.branch("dev").commit("two").commit("three");
master.commit("four-tagged");

@@ -149,0 +140,0 @@ gitgraph.tag("tag-one").tag("tag-two");

@@ -36,14 +36,6 @@ import { CommitStyle, TagStyle } from "./template";

(
Math.random()
.toString(16)
.substring(3) +
Math.random()
.toString(16)
.substring(3) +
Math.random()
.toString(16)
.substring(3) +
Math.random()
.toString(16)
.substring(3)
Math.random().toString(16).substring(3) +
Math.random().toString(16).substring(3) +
Math.random().toString(16).substring(3) +
Math.random().toString(16).substring(3)
).substring(0, 40);

@@ -59,7 +51,7 @@

*/
public x: number = 0;
public x = 0;
/**
* Commit y position
*/
public y: number = 0;
public y = 0;
/**

@@ -66,0 +58,0 @@ * Commit hash

@@ -220,7 +220,61 @@ import { Branch, DELETED_BRANCH_NAME, createDeletedBranch } from "./branch";

const branches = this.getBranches();
const commitsWithBranches = this.commits.map((commit) =>
// Commits that are not associated to a branch in `branches`
// were in a deleted branch. If the latter was merged beforehand
// they are reachable and are rendered. Others are not
const reachableUnassociatedCommits = (() => {
const unassociatedCommits = new Set(
this.commits.reduce(
(commits: Commit["hash"][], { hash }: { hash: Commit["hash"] }) =>
!branches.has(hash) ? [...commits, hash] : commits,
[],
),
);
const tipsOfMergedBranches = this.commits.reduce(
(tipsOfMergedBranches: Commit<TNode>[], commit: Commit<TNode>) =>
commit.parents.length > 1
? [
...tipsOfMergedBranches,
...commit.parents
.slice(1)
.map(
(parentHash) =>
this.commits.find(({ hash }) => parentHash === hash)!,
),
]
: tipsOfMergedBranches,
[],
);
const reachableCommits = new Set();
tipsOfMergedBranches.forEach((tip) => {
let currentCommit: Commit<TNode> | undefined = tip;
while (currentCommit && unassociatedCommits.has(currentCommit.hash)) {
reachableCommits.add(currentCommit.hash);
currentCommit =
currentCommit.parents.length > 0
? this.commits.find(
({ hash }) => currentCommit!.parents[0] === hash,
)
: undefined;
}
});
return reachableCommits;
})();
const commitsToRender = this.commits.filter(
({ hash }) =>
branches.has(hash) || reachableUnassociatedCommits.has(hash),
);
const commitsWithBranches = commitsToRender.map((commit) =>
this.withBranches(branches, commit),
);
const rows = createGraphRows(this.mode, this.commits);
const rows = createGraphRows(this.mode, commitsToRender);
const branchesOrder = new BranchesOrder<TNode>(

@@ -227,0 +281,0 @@ commitsWithBranches,

@@ -30,2 +30,17 @@ import { Commit } from "./commit";

/**
* Delete a reference
*
* @param name Name of the reference
*/
public delete(name: Name): this {
if (this.hasName(name)) {
this.removeNameFrom(this.getCommit(name)!, name);
this.commitPerName.delete(name);
}
return this;
}
/**
* Get the commit hash associated with the given reference name.

@@ -32,0 +47,0 @@ *

@@ -9,3 +9,3 @@ import { GitgraphCore } from "../gitgraph";

import { Commit } from "../commit";
import { Branch } from "../branch";
import { Branch, createDeletedBranch } from "../branch";
import { withoutUndefinedKeys, Omit } from "../utils";

@@ -71,2 +71,6 @@

public branch(args: any): BranchUserApi<TNode> {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot branch from the deleted branch "${this.name}"`);
}
const options: GitgraphBranchOptions<TNode> =

@@ -93,2 +97,6 @@ typeof args === "string" ? { name: args } : args;

public commit(options?: GitgraphCommitOptions<TNode> | string): this {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot commit on the deleted branch "${this.name}"`);
}
// Deal with shorter syntax

@@ -105,2 +113,60 @@ if (typeof options === "string") options = { subject: options };

/**
* Delete the branch (as `git branch -d`)
*/
public delete(): this {
// Delete all references to the branch from the graph (graph.branches and graph.refs)
// and from the commits (commit.refs). Then, make the branch instance a deleted branch.
// Like in git, the commits and tags in the deleted branch remain in the graph
if (
this._graph.refs.getCommit("HEAD") ===
this._graph.refs.getCommit(this.name)
) {
throw new Error(`Cannot delete the checked out branch "${this.name}"`);
}
const branchCommits = (function* (
graph: GitgraphCore<TNode>,
branch: Branch<TNode>,
) {
const lookupCommit = (
graph: GitgraphCore<TNode>,
commitHash: Commit["hash"] | undefined,
) => {
return graph.commits.find(({ hash }) => hash === commitHash);
};
let currentCommit = lookupCommit(
graph,
graph.refs.getCommit(branch.name),
);
while (currentCommit && currentCommit.hash !== branch.parentCommitHash) {
yield currentCommit;
currentCommit = lookupCommit(graph, currentCommit.parents[0]);
}
return;
})(this._graph, this._branch);
[...branchCommits].forEach((commit) => {
commit.refs = commit.refs.filter(
(branchName) => branchName !== this.name,
);
});
this._graph.refs.delete(this.name);
this._graph.branches.delete(this.name);
this._branch = createDeletedBranch(this._graph, this._branch.style, () => {
// do nothing
});
this._onGraphUpdate();
return this;
}
/**
* Create a merge commit.

@@ -126,2 +192,6 @@ *

public merge(...args: any[]): this {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot merge to the deleted branch "${this.name}"`);
}
let options = args[0];

@@ -189,2 +259,6 @@ if (!isBranchMergeOptions<TNode>(options)) {

public tag(options?: any): this {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot tag on the deleted branch "${this.name}"`);
}
if (typeof options === "string") {

@@ -203,2 +277,6 @@ this._graph.getUserApi().tag({ name: options, ref: this._branch.name });

public checkout(): this {
if (this._branch.isDeleted() && !this._isReferenced()) {
throw new Error(`Cannot checkout the deleted branch "${this.name}"`);
}
const target = this._branch;

@@ -309,2 +387,11 @@ const headCommit = this._graph.refs.getCommit(target.name);

private _isReferenced(): boolean {
return (
this._graph.branches.has(this.name) ||
this._graph.refs.hasName(this.name) ||
this._graph.commits
.reduce((allNames: string[], { refs }) => [...allNames, ...refs], [])
.includes(this.name)
);
}
// tslint:enable:variable-name

@@ -311,0 +398,0 @@ }

@@ -30,3 +30,3 @@ import { Commit } from "./commit";

type NonMatchingPropNames<T, X> = {
[K in keyof T]: T[K] extends X ? never : K
[K in keyof T]: T[K] extends X ? never : K;
}[keyof T];

@@ -81,3 +81,7 @@

console.log(
JSON.stringify(commits.map((commit) => pick(commit, paths)), null, 2),
JSON.stringify(
commits.map((commit) => pick(commit, paths)),
null,
2,
),
);

@@ -100,3 +104,3 @@ }

*/
function withoutUndefinedKeys<T extends object>(
function withoutUndefinedKeys<T>(
obj: T = {} as T,

@@ -103,0 +107,0 @@ ): NonMatchingProp<T, undefined> {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc