markmap-lib
Advanced tools
Comparing version 0.3.0-3 to 0.3.0
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.3.0-3 | MIT License */ | ||
/*! markmap-lib v0.3.0 | MIT License */ | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.3.0-3 | MIT License */ | ||
/*! markmap-lib v0.3.0 | MIT License */ | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.3.0-3 | MIT License */ | ||
/*! markmap-lib v0.3.0 | MIT License */ | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.3.0-3 | MIT License */ | ||
/*! markmap-lib v0.3.0 | MIT License */ | ||
(function (exports, d3) { | ||
@@ -3,0 +3,0 @@ 'use strict'; |
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.3.0-3 | MIT License */ | ||
/*! markmap-lib v0.3.0 | MIT License */ | ||
!function(t,e){"use strict";function n(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function r(t,e){var n,r,a,s,c,h=new l(t),u=+t.value&&(h.value=t.value),d=[h];for(null==e&&(e=i);n=d.pop();)if(u&&(n.value=+n.data.value),(a=e(n.data))&&(c=a.length))for(n.children=new Array(c),s=c-1;s>=0;--s)d.push(r=n.children[s]=new l(a[s])),r.parent=n,r.depth=n.depth+1;return h.eachBefore(o)}function i(t){return t.children}function a(t){t.data=t.data.data}function o(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function l(t){this.data=t,this.depth=this.height=0,this.parent=null}l.prototype=r.prototype={constructor:l,count:function(){return this.eachAfter(n)},each:function(t){var e,n,r,i,a=this,o=[a];do{for(e=o.reverse(),o=[];a=e.pop();)if(t(a),n=a.children)for(r=0,i=n.length;r<i;++r)o.push(n[r])}while(o.length);return this},eachAfter:function(t){for(var e,n,r,i=this,a=[i],o=[];i=a.pop();)if(o.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)a.push(e[n]);for(;i=o.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return r(this).eachBefore(a)}};const s=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function c(t){const e=Object.assign({},s,t);function n(t){const n=e[t];return"function"==typeof n?n:()=>n}function i(t){const e=o(function(){const t=a(),e=n("nodeSize"),r=n("spacing");return class extends t{constructor(t){super(t),Object.assign(this,{x:0,y:0,relX:0,prelim:0,shift:0,change:0,lExt:this,lExtRelX:0,lThr:null,rExt:this,rExtRelX:0,rThr:null})}get size(){return e(this.data)}spacing(t){return r(this.data,t.data)}get x(){return this.data.x}set x(t){this.data.x=t}get y(){return this.data.y}set y(t){this.data.y=t}update(){return h(this),u(this),this}}}(),t,t=>t.children);return e.update(),e.data}function a(){const t=n("nodeSize"),e=n("spacing");return class n extends r.prototype.constructor{constructor(t){super(t)}copy(){const t=o(this.constructor,this,t=>t.children);return t.each(t=>t.data=t.data.data),t}get size(){return t(this)}spacing(t){return e(this,t)}get nodes(){return this.descendants()}get xSize(){return this.size[0]}get ySize(){return this.size[1]}get top(){return this.y}get bottom(){return this.y+this.ySize}get left(){return this.x-this.xSize/2}get right(){return this.x+this.xSize/2}get root(){const t=this.ancestors();return t[t.length-1]}get numChildren(){return this.hasChildren?this.children.length:0}get hasChildren(){return!this.noChildren}get noChildren(){return null===this.children}get firstChild(){return this.hasChildren?this.children[0]:null}get lastChild(){return this.hasChildren?this.children[this.numChildren-1]:null}get extents(){return(this.children||[]).reduce((t,e)=>n.maxExtents(t,e.extents),this.nodeExtents)}get nodeExtents(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}static maxExtents(t,e){return{top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom),left:Math.min(t.left,e.left),right:Math.max(t.right,e.right)}}}}function o(t,e,n){const r=(e,i)=>{const a=new t(e);Object.assign(a,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});const o=n(e)||[];return a.children=0===o.length?null:o.map(t=>r(t,a)),a.children&&Object.assign(a,a.children.reduce((t,e)=>({height:Math.max(t.height,e.height+1),length:t.length+e.length}),a)),a};return r(e,null)}return Object.assign(i,{nodeSize(t){return arguments.length?(e.nodeSize=t,i):e.nodeSize},spacing(t){return arguments.length?(e.spacing=t,i):e.spacing},children(t){return arguments.length?(e.children=t,i):e.children},hierarchy(t,n){const r=void 0===n?e.children:n;return o(a(),t,r)},dump(t){const e=n("nodeSize"),r=t=>n=>{const i=t+" ",a=t+" ",{x:o,y:l}=n,s=e(n),c=n.children||[],h=0===c.length?" ":`,${i}children: [${a}${c.map(r(a)).join(a)}${i}],${t}`;return`{ size: [${s.join(", ")}],${i}x: ${o}, y: ${l}${h}},`};return r("\n")(t)}}),i}c.version="2.1.1";const h=(t,e=0)=>(t.y=e,(t.children||[]).reduce((e,n)=>{const[r,i]=e;h(n,t.y+t.ySize);const a=(0===r?n.lExt:n.rExt).bottom;return 0!==r&&p(t,r,i),[r+1,E(a,r,i)]},[0,null]),d(t),z(t),t),u=(t,e,n)=>{void 0===e&&(e=-t.relX-t.prelim,n=0);const r=e+t.relX;return t.relX=r+t.prelim-n,t.prelim=0,t.x=n+t.relX,(t.children||[]).forEach(e=>u(e,r,t.x)),t},d=t=>{(t.children||[]).reduce((t,e)=>{const[n,r]=t,i=n+e.shift,a=r+i+e.change;return e.relX+=a,[i,a]},[0,0])},p=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let a=r,o=r.relX,l=i,s=i.relX,c=!0;for(;a&&l;){a.bottom>n.lowY&&(n=n.next);const r=o+a.prelim-(s+l.prelim)+a.xSize/2+l.xSize/2+a.spacing(l);(r>0||r<0&&c)&&(s+=r,f(i,r),x(t,e,n.index,r)),c=!1;const h=a.bottom,u=l.bottom;h<=u&&(a=m(a),a&&(o+=a.relX)),h>=u&&(l=g(l),l&&(s+=l.relX))}!a&&l?y(t,e,l,s):a&&!l&&v(t,e,a,o)},f=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},x=(t,e,n,r)=>{const i=t.children[e],a=e-n;if(a>1){const e=r/a;t.children[n+1].shift+=e,i.shift-=e,i.change-=r-e}},g=t=>t.hasChildren?t.firstChild:t.lThr,m=t=>t.hasChildren?t.lastChild:t.rThr,y=(t,e,n,r)=>{const i=t.firstChild,a=i.lExt,o=t.children[e];a.lThr=n;const l=r-n.relX-i.lExtRelX;a.relX+=l,a.prelim-=l,i.lExt=o.lExt,i.lExtRelX=o.lExtRelX},v=(t,e,n,r)=>{const i=t.children[e],a=i.rExt,o=t.children[e-1];a.rThr=n;const l=r-n.relX-i.rExtRelX;a.relX+=l,a.prelim-=l,i.rExt=o.rExt,i.rExtRelX=o.rExtRelX},z=t=>{if(t.hasChildren){const e=t.firstChild,n=t.lastChild,r=(e.prelim+e.relX-e.xSize/2+n.relX+n.prelim+n.xSize/2)/2;Object.assign(t,{prelim:r,lExt:e.lExt,lExtRelX:e.lExtRelX,rExt:n.rExt,rExtRelX:n.rExtRelX})}},E=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}};function S(t,e){const n=t=>e(t,()=>{var e;null==(e=t.children)||e.forEach(n)});n(t)}let X;function k(t){const e=t.data;return Math.max(6-2*e.d,1.5)}function w(){return this.childNodes}t.markmap=function(t,n,r){const i=((t=t.datum?t:e.select(t)).attr("class")||"").split(" ").filter(Boolean);i.indexOf("markmap")<0&&(i.push("markmap"),t.attr("class",i.join(" ")));const a=t.append("style"),o=t.append("g"),l=e.zoom().on("zoom",(function(){const{transform:t}=e.event;o.attr("transform",t)})),s=t.node(),h={duration:500,nodeFont:"300 16px sans-serif",lineHeight:20,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:e.scaleOrdinal(e.schemeCategory10),colorDepth:0,...r},u={};return a.text(`a {\n fill: #0097e6;\n}\na:hover {\n fill: #00a8ff;\n}\npath {\n fill: none;\n}\ntext {\n font: ${h.nodeFont}\n}\ntspan.markmap-em {\n font-style: italic;\n}\ntspan.markmap-strong {\n font-weight: 500;\n}\ng > g {\n cursor: pointer;\n}\n`),n&&(f(n),x()),t.call(l),{setData:f,setOptions:p,fit:x};function d(t){let e=1;const{colorDepth:n}=h;S(t,(t,r)=>{var i;h.color(`${e}`),t.p={i:e,...t.p},(null==(i=t.v)?void 0:i.length)&&(t.p.k=function t(e){const n=["<"];return e.forEach(e=>{"text"===e.t?n.push(e.v.replace(/[<|&]/g,t=>`&${t}`)):e.children&&n.push(t(e.children))}),n.push(">"),n.join("")}(t.v)),r(),n&&t.d!==n||(e+=1)})}function p(t){Object.assign(h,t)}function f(t,e){d(t),u.data=t,e&&p(e),v(t)}function x(){const{width:n,height:r}=s.getBoundingClientRect(),{minX:i,maxX:a,minY:o,maxY:c}=u,d=c-o,p=a-i,f=Math.min(n/d*h.fitRatio,r/p*h.fitRatio,2),x=e.zoomIdentity.translate((n-d*f)/2-o*f,(r-p*f)/2-i*f).scale(f);t.transition().duration(h.duration).call(l.transform,x)}function g(t){t.data.fold=!t.data.fold,v(t.data)}function m(t){e.event.preventDefault(),window.open(t.p.href)}function y(t){return t.selectAll(w).data(t=>t.data.v).enter().each((function(t){!function t(n,r){if("link"===r.t){n.append("a").attr("href",r.p.href).attr("title",r.p.title).on("click",m).selectAll(w).data(t=>t.children).enter().each((function(n){t(e.select(this),n)}))}"text"===r.t&&n.append("tspan").text(r.v).attr("class",t=>{var e;const n=(null==(e=t.p)?void 0:e.style)||{};return[n.em&&"markmap-em",n.strong&&"markmap-strong"].filter(Boolean).join(" ")}).attr("x",t=>{var e;return(null==(e=t.p)?void 0:e.newline)?8:null}).attr("dy",t=>{var e;return(null==(e=t.p)?void 0:e.newline)?h.lineHeight:null})}(e.select(this),t)})),t}function v(t){var n,r;if(!u.data)return;const i=c().children(t=>!t.fold&&t.children).nodeSize(t=>{const[e,n]=function(t,e){X||(X=document.createElement("canvas"));const n=X.getContext("2d");n.font=e;let r=0,i=0,a=0;const o=t=>{if("text"===t.t){t.p={...t.p},!i&&a&&(t.p.newline=!0);const e=n.measureText(t.v);i+=e.width,r<i&&(r=i)}else"softbreak"===t.t?(i=0,a+=1):"link"===t.t&&t.children.forEach(o)};return t.forEach(o),[r,a+1]}(t.data.v,h.nodeFont);return[n*h.lineHeight,e+16]}).spacing((t,e)=>t.parent===e.parent?h.spacingVertical:2*h.spacingVertical),a=i.hierarchy(u.data);i(a),function(t,e){let n=0;S(t,(t,r)=>{t.y+=n*e,n+=1,r(),n-=1})}(a,h.spacingHorizontal);const l=a.descendants().reverse(),s=a.links(),d=e.linkHorizontal(),p=e.min(l,t=>t.x),f=e.max(l,t=>t.x),m=e.min(l,t=>t.y),v=e.max(l,t=>t.y+t.ySize);u.minX=p,u.maxX=f,u.minY=m,u.maxY=v,h.autoFit&&x();const z=t?l.find(e=>e.data===t):a,E=null!=(n=z.data.x0)?n:z.x,w=null!=(r=z.data.y0)?r:z.y,C=o.selectAll("g").data(l,t=>t.data.p.k),b=C.enter().append("g").attr("transform",t=>`translate(${w+z.ySize-t.ySize},${E+z.xSize/2})`).on("click",g),$=C.exit().transition().duration(h.duration);$.select("rect").attr("width",0).attr("x",t=>t.ySize),$.select("text").attr("fill-opacity",0),$.attr("transform",t=>`translate(${z.y+z.ySize-t.ySize},${z.x+z.xSize/2})`).remove();const R=C.merge(b);R.transition().duration(h.duration).attr("transform",t=>`translate(${t.y},${t.x+t.xSize/2})`),R.selectAll("rect").data(t=>[t],t=>t.data.p.k).join(t=>t.append("rect").attr("y",-1).attr("x",t=>t.ySize).attr("width",0).attr("height",k),t=>t,t=>t.remove()).transition().duration(h.duration).attr("x",-1).attr("width",t=>t.ySize+2).attr("fill",t=>h.color(t.data.p.i)),R.selectAll("circle").data(t=>t.data.children?[t]:[],t=>t.data.p.k).join(t=>t.append("circle").attr("stroke-width","1.5").attr("r",0),t=>t,t=>t.remove()).transition().duration(h.duration).attr("cx",t=>t.ySize).attr("r",6).attr("stroke",t=>h.color(t.data.p.i)).attr("fill",t=>t.data.fold?h.color(t.data.p.i):"#fff"),R.selectAll("text").data(t=>[t],t=>t.data.p.k).join(t=>t.append("text").attr("x",8).attr("y",t=>h.lineHeight-4-t.xSize).attr("text-anchor","start").attr("fill-opacity",0).call(y),t=>t,t=>t.remove()).transition().duration(h.duration).attr("fill-opacity",1),o.selectAll("path").data(s,t=>t.target.data.p.k).join(t=>{const e=[w+z.ySize,E+z.xSize/2];return t.insert("path","g").attr("d",d({source:e,target:e}))},t=>t,t=>{const e=[z.y+z.ySize,z.x+z.xSize/2];return t.transition().duration(h.duration).attr("d",d({source:e,target:e})).remove()}).transition().duration(h.duration).attr("stroke",t=>h.color(t.target.data.p.i)).attr("stroke-width",t=>k(t.target)).attr("d",t=>{const e=[t.source.y+t.source.ySize,t.source.x+t.source.xSize/2],n=[t.target.y,t.target.x+t.target.xSize/2];return d({source:e,target:n})}),l.forEach(t=>{t.data.x0=t.x,t.data.y0=t.y})}}}(this.markmap=this.markmap||{},d3); |
{ | ||
"name": "markmap-lib", | ||
"version": "0.3.0-3", | ||
"version": "0.3.0", | ||
"description": "Visualize your Markdown as mindmaps with Markmap", | ||
@@ -5,0 +5,0 @@ "author": "Gerald <i@gerald.top>", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
333770