markmap-view 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-view v0.2.6 | MIT License */
2
- !function(t,e){"use strict";function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){e[n]=t[n]})),e.default=t,Object.freeze(e)}var r=n(e);function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,c(t,e)}function h(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 u(t,e){var n,r,i,o,a,s=new g(t),c=+t.value&&(s.value=t.value),l=[s];for(null==e&&(e=d);n=l.pop();)if(c&&(n.value=+n.data.value),(i=e(n.data))&&(a=i.length))for(n.children=new Array(a),o=a-1;o>=0;--o)l.push(r=n.children[o]=new g(i[o])),r.parent=n,r.depth=n.depth+1;return s.eachBefore(p)}function d(t){return t.children}function f(t){t.data=t.data.data}function p(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function g(t){this.data=t,this.depth=this.height=0,this.parent=null}g.prototype=u.prototype={constructor:g,count:function(){return this.eachAfter(h)},each:function(t){var e,n,r,i,o=this,a=[o];do{for(e=a.reverse(),a=[];o=e.pop();)if(t(o),n=o.children)for(r=0,i=n.length;r<i;++r)a.push(n[r])}while(a.length);return this},eachAfter:function(t){for(var e,n,r,i=this,o=[i],a=[];i=o.pop();)if(a.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)o.push(e[n]);for(;i=a.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 u(this).eachBefore(f)}};var m=Object.freeze({children:function(t){return t.children},nodeSize:function(t){return t.data.size},spacing:0});function v(t){var e=Object.assign({},m,t);function n(t){var n=e[t];return"function"==typeof n?n:function(){return n}}function r(t){var e,r,c,h=a((e=i(),r=n("nodeSize"),c=n("spacing"),function(t){function e(e){var n;return n=t.call(this,e)||this,Object.assign(o(n),{x:0,y:0,relX:0,prelim:0,shift:0,change:0,lExt:o(n),lExtRelX:0,lThr:null,rExt:o(n),rExtRelX:0,rThr:null}),n}l(e,t);var n=e.prototype;return n.spacing=function(t){return c(this.data,t.data)},n.update=function(){return y(this),x(this),this},s(e,[{key:"size",get:function(){return r(this.data)}},{key:"x",get:function(){return this.data.x},set:function(t){this.data.x=t}},{key:"y",get:function(){return this.data.y},set:function(t){this.data.y=t}}]),e}(e)),t,(function(t){return t.children}));return h.update(),h.data}function i(){var t=n("nodeSize"),e=n("spacing");return function(n){function r(t){return n.call(this,t)||this}l(r,n);var i=r.prototype;return i.copy=function(){var t=a(this.constructor,this,(function(t){return t.children}));return t.each((function(t){return t.data=t.data.data})),t},i.spacing=function(t){return e(this,t)},r.maxExtents=function(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)}},s(r,[{key:"size",get:function(){return t(this)}},{key:"nodes",get:function(){return this.descendants()}},{key:"xSize",get:function(){return this.size[0]}},{key:"ySize",get:function(){return this.size[1]}},{key:"top",get:function(){return this.y}},{key:"bottom",get:function(){return this.y+this.ySize}},{key:"left",get:function(){return this.x-this.xSize/2}},{key:"right",get:function(){return this.x+this.xSize/2}},{key:"root",get:function(){var t=this.ancestors();return t[t.length-1]}},{key:"numChildren",get:function(){return this.hasChildren?this.children.length:0}},{key:"hasChildren",get:function(){return!this.noChildren}},{key:"noChildren",get:function(){return null===this.children}},{key:"firstChild",get:function(){return this.hasChildren?this.children[0]:null}},{key:"lastChild",get:function(){return this.hasChildren?this.children[this.numChildren-1]:null}},{key:"extents",get:function(){return(this.children||[]).reduce((function(t,e){return r.maxExtents(t,e.extents)}),this.nodeExtents)}},{key:"nodeExtents",get:function(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}}]),r}(u.prototype.constructor)}function a(t,e,n){return function e(r,i){var o=new t(r);Object.assign(o,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});var a=n(r)||[];return o.children=0===a.length?null:a.map((function(t){return e(t,o)})),o.children&&Object.assign(o,o.children.reduce((function(t,e){return{height:Math.max(t.height,e.height+1),length:t.length+e.length}}),o)),o}(e,null)}return Object.assign(r,{nodeSize:function(t){return arguments.length?(e.nodeSize=t,r):e.nodeSize},spacing:function(t){return arguments.length?(e.spacing=t,r):e.spacing},children:function(t){return arguments.length?(e.children=t,r):e.children},hierarchy:function(t,n){var r=void 0===n?e.children:n;return a(i(),t,r)},dump:function(t){var e=n("nodeSize");return function t(n){return function(r){var i=n+" ",o=n+" ",a=r.x,s=r.y,c=e(r),l=r.children||[],h=0===l.length?" ":","+i+"children: ["+o+l.map(t(o)).join(o)+i+"],"+n;return"{ size: ["+c.join(", ")+"],"+i+"x: "+a+", y: "+s+h+"},"}}("\n")(t)}}),r}v.version="2.1.1";var y=function t(e,n){return void 0===n&&(n=0),e.y=n,(e.children||[]).reduce((function(n,r){var i=n[0],o=n[1];t(r,e.y+e.ySize);var a=(0===i?r.lExt:r.rExt).bottom;return 0!==i&&k(e,i,o),[i+1,C(a,i,o)]}),[0,null]),z(e),$(e),e},x=function t(e,n,r){void 0===n&&(n=-e.relX-e.prelim,r=0);var i=n+e.relX;return e.relX=i+e.prelim-r,e.prelim=0,e.x=r+e.relX,(e.children||[]).forEach((function(n){return t(n,i,e.x)})),e},z=function(t){(t.children||[]).reduce((function(t,e){var n=t[0],r=t[1],i=n+e.shift,o=r+i+e.change;return e.relX+=o,[i,o]}),[0,0])},k=function(t,e,n){for(var r=t.children[e-1],i=t.children[e],o=r,a=r.relX,s=i,c=i.relX,l=!0;o&&s;){o.bottom>n.lowY&&(n=n.next);var h=a+o.prelim-(c+s.prelim)+o.xSize/2+s.xSize/2+o.spacing(s);(h>0||h<0&&l)&&(c+=h,S(i,h),b(t,e,n.index,h)),l=!1;var u=o.bottom,d=s.bottom;u<=d&&(o=w(o))&&(a+=o.relX),u>=d&&(s=E(s))&&(c+=s.relX)}!o&&s?X(t,e,s,c):o&&!s&&O(t,e,o,a)},S=function(t,e){t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},b=function(t,e,n,r){var i=t.children[e],o=e-n;if(o>1){var a=r/o;t.children[n+1].shift+=a,i.shift-=a,i.change-=r-a}},E=function(t){return t.hasChildren?t.firstChild:t.lThr},w=function(t){return t.hasChildren?t.lastChild:t.rThr},X=function(t,e,n,r){var i=t.firstChild,o=i.lExt,a=t.children[e];o.lThr=n;var s=r-n.relX-i.lExtRelX;o.relX+=s,o.prelim-=s,i.lExt=a.lExt,i.lExtRelX=a.lExtRelX},O=function(t,e,n,r){var i=t.children[e],o=i.rExt,a=t.children[e-1];o.rThr=n;var s=r-n.relX-i.rExtRelX;o.relX+=s,o.prelim-=s,i.rExt=a.rExt,i.rExtRelX=a.rExtRelX},$=function(t){if(t.hasChildren){var 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})}},C=function(t,e,n){for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}};
3
- /*! markmap-common v0.1.5 | MIT License */
4
- class j{constructor(){this.listeners=[]}tap(t){return this.listeners.push(t),()=>this.revoke(t)}revoke(t){const e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)}revokeAll(){this.listeners.splice(0)}call(...t){for(const e of this.listeners)e(...t)}}function M(){return(M=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}const R=Math.random().toString(36).slice(2,8);let I=0;function A(){}function H(t,e,n="c"){const r=(t,i)=>e(t,(()=>{var e;null==(e=t[n])||e.forEach((e=>{r(e,t)}))}),i);r(t)}function B(t){if(Array.from)return Array.from(t);const e=[];for(let n=0;n<t.length;n+=1)e.push(t[n]);return e}function T(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach((t=>{t&&n.indexOf(t)<0&&n.push(t)})),n.join(" ")}function N(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=B(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function D(t,e,n){const r=document.createElement(t);return e&&Object.entries(e).forEach((([t,e])=>{r[t]=e})),n&&Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e)})),r}const P=function(t){const e={};return function(...n){const r=`${n[0]}`;let i=e[r];return i||(i={value:t(...n)},e[r]=i),i.value}}((t=>{document.head.append(D("link",{rel:"preload",as:"script",href:t}))}));function Y(t,e){if("script"===t.type)return new Promise(((e,n)=>{var r;document.head.append(D("script",M({},t.data,{onload:e,onerror:n}))),null!=(r=t.data)&&r.src||e()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function _(t){"style"===t.type?document.head.append(D("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(D("link",M({rel:"stylesheet"},t.data)))}function F(t){const e=t.data;return Math.max(6-2*e.d,1.5)}function V(t,e){return t[r.minIndex(t,e)]}function Z(t){t.stopPropagation()}const L=new j;class J{constructor(t,e){this.options=void 0,this.state=void 0,this.svg=void 0,this.styleNode=void 0,this.g=void 0,this.zoom=void 0,this.viewHooks=void 0,this.revokers=[],["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new j},this.svg=t.datum?t:r.select(t),this.styleNode=this.svg.append("style"),this.zoom=r.zoom().on("zoom",this.handleZoom),this.options=i({},J.defaultOptions,e),this.state={id:this.options.id||(I+=1,`mm-${R}-${I}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(L.tap((()=>{this.setData()})))}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} { line-height: 1; }\n.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-g > g > circle { cursor: pointer; }\n.${n}-fo > div { display: inline-block; font: ${e}; white-space: nowrap; }\n.${n}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }\n.${n}-fo :not(pre) > code { padding: .2em .4em; }\n.${n}-fo del { text-decoration: line-through; }\n.${n}-fo em { font-style: italic; }\n.${n}-fo strong { font-weight: bolder; }\n.${n}-fo pre { margin: 0; padding: .2em .4em; }\n${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",T(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var n;const{data:r}=e;r.p=i({},r.p,{f:!(null!=(n=r.p)&&n.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:n,color:r,nodeMinHeight:o}=this.options,{id:a}=this.state,s=document.createElement("div"),c=`${a}-container`;s.className=T(s.className,`${a}-fo`,c);const l=document.createElement("style");l.textContent=`\n${this.getStyleContent()}\n.${c} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${n};\n}\n.${c} > div {\n display: inline-block;\n}\n`,document.body.append(l,s),H(t,((t,n)=>{var o;t.c=null==(o=t.c)?void 0:o.map((t=>i({},t))),e+=1;const a=document.createElement("div");a.innerHTML=t.v,s.append(a),t.p=i({},t.p,{i:e,el:a}),r(t),n()}));const h=B(s.childNodes);this.viewHooks.transformHtml.call(this,h),H(t,((t,e,n)=>{var r;const i=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(i.width),Math.max(Math.ceil(i.height),o)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()})),s.remove(),l.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t&&(this.state.data=t),this.initializeData(this.state.data),e&&this.setOptions(e),this.renderData()}renderData(t){var e,n;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:o,spacingVertical:a,autoFit:s,color:c}=this.options,{id:l}=this.state,h=v().children((t=>{var e;return!(null!=(e=t.p)&&e.f)&&t.c})).nodeSize((t=>{const[e,n]=t.data.p.s;return[n,e+(e?2*o:0)+i]})).spacing(((t,e)=>t.parent===e.parent?a:2*a)),u=h.hierarchy(this.state.data);h(u),function(t,e){H(t,((t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()}),"children")}(u,i);const d=u.descendants().reverse(),f=u.links(),p=r.linkHorizontal(),g=r.min(d,(t=>t.x-t.xSize/2)),m=r.max(d,(t=>t.x+t.xSize/2)),y=r.min(d,(t=>t.y)),x=r.max(d,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:g,maxX:m,minY:y,maxY:x}),s&&this.fit();const z=t&&d.find((e=>e.data===t))||u,k=null!=(e=z.data.p.x0)?e:z.x,S=null!=(n=z.data.p.y0)?n:z.y,b=this.g.selectAll(N("g")).data(d,(t=>t.data.p.k)),E=b.enter().append("g").attr("transform",(t=>`translate(${S+z.ySizeInner-t.ySizeInner},${k+z.xSize/2-t.xSize})`)),w=this.transition(b.exit());w.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),w.select("foreignObject").style("opacity",0),w.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const X=b.merge(E);this.transition(X).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const O=X.selectAll(N("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-F(t)/2)).attr("width",0).attr("height",F)),(t=>t),(t=>t.remove()));this.transition(O).attr("x",-1).attr("width",(t=>t.ySizeInner+2)).attr("fill",(t=>c(t.data)));const $=X.selectAll(N("circle")).data((t=>t.data.c?[t]:[]),(t=>t.data.p.k)).join((t=>t.append("circle").attr("stroke-width","1.5").attr("cx",(t=>t.ySizeInner)).attr("cy",(t=>t.xSize)).attr("r",0).on("click",this.handleClick)),(t=>t),(t=>t.remove()));this.transition($).attr("r",6).attr("stroke",(t=>c(t.data))).attr("fill",(t=>{var e;return null!=(e=t.data.p)&&e.f&&t.data.c?c(t.data):"#fff"}));const C=X.selectAll(N("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",`${l}-fo`).attr("x",o).attr("y",0).style("opacity",0).attr("height",(t=>t.xSize)).on("mousedown",Z).on("dblclick",Z);return e.append("xhtml:div").select((function(t){const e=t.data.p.el.cloneNode(!0);return this.replaceWith(e),e})).attr("xmlns","http://www.w3.org/1999/xhtml"),e}),(t=>t),(t=>t.remove())).attr("width",(t=>Math.max(0,t.ySizeInner-2*o)));this.transition(C).style("opacity",1);const j=this.g.selectAll(N("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[S+z.ySizeInner,k+z.xSize/2];return t.insert("path","g").attr("d",p({source:e,target:e}))}),(t=>t),(t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",p({source:e,target:e})).remove()}));this.transition(j).attr("stroke",(t=>c(t.target.data))).attr("stroke-width",(t=>F(t.target))).attr("d",(t=>{const e=[t.source.y+t.source.ySizeInner,t.source.x+t.source.xSize/2],n=[t.target.y,t.target.x+t.target.xSize/2];return p({source:e,target:n})})),d.forEach((t=>{t.data.p.x0=t.x,t.data.p.y0=t.y}))}transition(t){const{duration:e}=this.options;return t.transition().duration(e)}async fit(){const t=this.svg.node(),{width:e,height:n}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:o,maxX:a,minY:s,maxY:c}=this.state,l=c-s,h=a-o,u=Math.min(e/l*i,n/h*i,2),d=r.zoomIdentity.translate((e-l*u)/2-s*u,(n-h*u)/2-o*u).scale(u);return this.transition(this.svg).call(this.zoom.transform,d).end().catch(A)}async ensureView(t,e){let n,o;if(this.g.selectAll(N("g")).each((function(e){e.data===t&&(n=this,o=e)})),!n||!o)return;const a=this.svg.node(),s=a.getBoundingClientRect(),c=r.zoomTransform(a),[l,h]=[o.y,o.y+o.ySizeInner+2].map((t=>t*c.k+c.x)),[u,d]=[o.x-o.xSize/2,o.x+o.xSize/2].map((t=>t*c.k+c.y)),f=i({left:0,right:0,top:0,bottom:0},e),p=[f.left-l,s.width-f.right-h],g=[f.top-u,s.height-f.bottom-d],m=p[0]*p[1]>0?V(p,Math.abs)/c.k:0,v=g[0]*g[1]>0?V(g,Math.abs)/c.k:0;if(m||v){const t=c.translate(m,v);return this.transition(this.svg).call(this.zoom.transform,t).end().catch(A)}}async rescale(t){const e=this.svg.node(),{width:n,height:i}=e.getBoundingClientRect(),o=n/2,a=i/2,s=r.zoomTransform(e),c=s.translate((o-s.x)*(1-t)/s.k,(a-s.y)*(1-t)/s.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,c).end().catch(A)}destroy(){this.svg.remove(),this.revokers.forEach((t=>{t()}))}static create(t,e,n){const r=new J(t,e);return n&&(r.setData(n),r.fit()),r}}var W;J.defaultOptions={duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(W=r.scaleOrdinal(r.schemeCategory10),t=>W(t.p.i)),paddingX:8},t.Markmap=J,t.loadCSS=function(t){for(const e of t)_(e)},t.loadJS=async function(t,e){const n=t.filter((t=>{var e;return"script"===t.type&&(null==(e=t.data)?void 0:e.src)}));n.length>1&&n.forEach((t=>P(t.data.src))),e=M({getMarkmap:()=>window.markmap},e);for(const n of t)await Y(n,e)},t.refreshHook=L}(this.markmap=this.markmap||{},d3);
1
+ /*! markmap-view v0.2.7 | MIT License */
2
+ !function(t,e){"use strict";function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);if(t)for(var n in t)e[n]=t[n];return e.default=t,Object.freeze(e)}var r=n(e);function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function s(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 o(t,e){var n,r,i,s,o,l=new h(t),d=+t.value&&(l.value=t.value),u=[l];for(null==e&&(e=a);n=u.pop();)if(d&&(n.value=+n.data.value),(i=e(n.data))&&(o=i.length))for(n.children=new Array(o),s=o-1;s>=0;--s)u.push(r=n.children[s]=new h(i[s])),r.parent=n,r.depth=n.depth+1;return l.eachBefore(c)}function a(t){return t.children}function l(t){t.data=t.data.data}function c(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}h.prototype=o.prototype={constructor:h,count:function(){return this.eachAfter(s)},each:function(t){var e,n,r,i,s=this,o=[s];do{for(e=o.reverse(),o=[];s=e.pop();)if(t(s),n=s.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,s=[i],o=[];i=s.pop();)if(o.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)s.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 o(this).eachBefore(l)}};var d={name:"d3-flextree",version:"2.1.2",main:"build/d3-flextree.js",module:"index","jsnext:main":"index",author:{name:"Chris Maloney",url:"http://chrismaloney.org"},description:"Flexible tree layout algorithm that allows for variable node sizes.",keywords:["d3","d3-module","layout","tree","hierarchy","d3-hierarchy","plugin","d3-plugin","infovis","visualization","2d"],homepage:"https://github.com/klortho/d3-flextree",license:"WTFPL",repository:{type:"git",url:"https://github.com/klortho/d3-flextree.git"},scripts:{clean:"rm -rf build demo test","build:demo":"rollup -c --environment BUILD:demo","build:dev":"rollup -c --environment BUILD:dev","build:prod":"rollup -c --environment BUILD:prod","build:test":"rollup -c --environment BUILD:test",build:"rollup -c",lint:"eslint index.js src","test:main":"node test/bundle.js","test:browser":"node test/browser-tests.js",test:"npm-run-all test:*",prepare:"npm-run-all clean build lint test"},dependencies:{"d3-hierarchy":"^1.1.5"},devDependencies:{"babel-plugin-external-helpers":"^6.22.0","babel-preset-es2015-rollup":"^3.0.0",d3:"^4.13.0","d3-selection-multi":"^1.0.1",eslint:"^4.19.1",jsdom:"^11.6.2","npm-run-all":"^4.1.2",rollup:"^0.55.3","rollup-plugin-babel":"^2.7.1","rollup-plugin-commonjs":"^8.0.2","rollup-plugin-copy":"^0.2.3","rollup-plugin-json":"^2.3.0","rollup-plugin-node-resolve":"^3.0.2","rollup-plugin-uglify":"^3.0.0","uglify-es":"^3.3.9"}};const{version:u}=d,p=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function f(t){const e=Object.assign({},p,t);function n(t){const n=e[t];return"function"==typeof n?n:()=>n}function r(t){const e=s(function(){const t=i(),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 g(this),m(this),this}}}(),t,(t=>t.children));return e.update(),e.data}function i(){const t=n("nodeSize"),e=n("spacing");return class n extends o.prototype.constructor{constructor(t){super(t)}copy(){const t=s(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 s(t,e,n){const r=(e,i)=>{const s=new t(e);Object.assign(s,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});const o=n(e)||[];return s.children=0===o.length?null:o.map((t=>r(t,s))),s.children&&Object.assign(s,s.children.reduce(((t,e)=>({height:Math.max(t.height,e.height+1),length:t.length+e.length})),s)),s};return r(e,null)}return Object.assign(r,{nodeSize(t){return arguments.length?(e.nodeSize=t,r):e.nodeSize},spacing(t){return arguments.length?(e.spacing=t,r):e.spacing},children(t){return arguments.length?(e.children=t,r):e.children},hierarchy(t,n){const r=void 0===n?e.children:n;return s(i(),t,r)},dump(t){const e=n("nodeSize"),r=t=>n=>{const i=t+" ",s=t+" ",{x:o,y:a}=n,l=e(n),c=n.children||[],h=0===c.length?" ":`,${i}children: [${s}${c.map(r(s)).join(s)}${i}],${t}`;return`{ size: [${l.join(", ")}],${i}x: ${o}, y: ${a}${h}},`};return r("\n")(t)}}),r}f.version=u;const g=(t,e=0)=>(t.y=e,(t.children||[]).reduce(((e,n)=>{const[r,i]=e;g(n,t.y+t.ySize);const s=(0===r?n.lExt:n.rExt).bottom;0!==r&&y(t,r,i);return[r+1,$(s,r,i)]}),[0,null]),x(t),E(t),t),m=(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=>m(e,r,t.x))),t},x=t=>{(t.children||[]).reduce(((t,e)=>{const[n,r]=t,i=n+e.shift,s=r+i+e.change;return e.relX+=s,[i,s]}),[0,0])},y=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let s=r,o=r.relX,a=i,l=i.relX,c=!0;for(;s&&a;){s.bottom>n.lowY&&(n=n.next);const r=o+s.prelim-(l+a.prelim)+s.xSize/2+a.xSize/2+s.spacing(a);(r>0||r<0&&c)&&(l+=r,v(i,r),z(t,e,n.index,r)),c=!1;const h=s.bottom,d=a.bottom;h<=d&&(s=S(s),s&&(o+=s.relX)),h>=d&&(a=b(a),a&&(l+=a.relX))}!s&&a?k(t,e,a,l):s&&!a&&w(t,e,s,o)},v=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},z=(t,e,n,r)=>{const i=t.children[e],s=e-n;if(s>1){const e=r/s;t.children[n+1].shift+=e,i.shift-=e,i.change-=r-e}},b=t=>t.hasChildren?t.firstChild:t.lThr,S=t=>t.hasChildren?t.lastChild:t.rThr,k=(t,e,n,r)=>{const i=t.firstChild,s=i.lExt,o=t.children[e];s.lThr=n;const a=r-n.relX-i.lExtRelX;s.relX+=a,s.prelim-=a,i.lExt=o.lExt,i.lExtRelX=o.lExtRelX},w=(t,e,n,r)=>{const i=t.children[e],s=i.rExt,o=t.children[e-1];s.rThr=n;const a=r-n.relX-i.rExtRelX;s.relX+=a,s.prelim-=a,i.rExt=o.rExt,i.rExtRelX=o.rExtRelX},E=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})}},$=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}};
3
+ /*! markmap-common v0.1.6 | MIT License */
4
+ class X{constructor(){this.listeners=[]}tap(t){return this.listeners.push(t),()=>this.revoke(t)}revoke(t){const e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)}revokeAll(){this.listeners.splice(0)}call(...t){for(const e of this.listeners)e(...t)}}function j(){return j=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},j.apply(this,arguments)}const C=Math.random().toString(36).slice(2,8);let O=0;function M(){}function I(t,e,n="c"){const r=(t,i)=>e(t,(()=>{var e;null==(e=t[n])||e.forEach((e=>{r(e,t)}))}),i);r(t)}function R(t){if(Array.from)return Array.from(t);const e=[];for(let n=0;n<t.length;n+=1)e.push(t[n]);return e}function A(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach((t=>{t&&n.indexOf(t)<0&&n.push(t)})),n.join(" ")}function B(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=R(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function D(t,e,n){const r=document.createElement(t);return e&&Object.entries(e).forEach((([t,e])=>{r[t]=e})),n&&Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e)})),r}const H=function(t){const e={};return function(...n){const r=`${n[0]}`;let i=e[r];return i||(i={value:t(...n)},e[r]=i),i.value}}((t=>{document.head.append(D("link",{rel:"preload",as:"script",href:t}))}));function T(t,e){if("script"===t.type)return new Promise(((e,n)=>{var r;document.head.append(D("script",j({},t.data,{onload:e,onerror:n}))),null!=(r=t.data)&&r.src||e()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function N(t){"style"===t.type?document.head.append(D("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(D("link",j({rel:"stylesheet"},t.data)))}function F(t){const e=t.data;return Math.max(6-2*e.d,1.5)}function L(t,e){return t[r.minIndex(t,e)]}function Y(t){t.stopPropagation()}const P=new X;class U{constructor(t,e){this.revokers=[],["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new X},this.svg=t.datum?t:r.select(t),this.styleNode=this.svg.append("style"),this.zoom=r.zoom().on("zoom",this.handleZoom),this.options=i({},U.defaultOptions,e),this.state={id:this.options.id||(O+=1,`mm-${C}-${O}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(P.tap((()=>{this.setData()})))}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} { line-height: 1; }\n.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-g > g > circle { cursor: pointer; }\n.${n}-fo > div { display: inline-block; font: ${e}; white-space: nowrap; }\n.${n}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }\n.${n}-fo :not(pre) > code { padding: .2em .4em; }\n.${n}-fo del { text-decoration: line-through; }\n.${n}-fo em { font-style: italic; }\n.${n}-fo strong { font-weight: bolder; }\n.${n}-fo pre { margin: 0; padding: .2em .4em; }\n${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",A(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var n;const{data:r}=e;r.p=i({},r.p,{f:!(null!=(n=r.p)&&n.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:n,color:r,nodeMinHeight:s}=this.options,{id:o}=this.state,a=document.createElement("div"),l=`${o}-container`;a.className=A(a.className,`${o}-fo`,l);const c=document.createElement("style");c.textContent=`\n${this.getStyleContent()}\n.${l} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${n};\n}\n.${l} > div {\n display: inline-block;\n}\n`,document.body.append(c,a),I(t,((t,n)=>{var s;t.c=null==(s=t.c)?void 0:s.map((t=>i({},t))),e+=1;const o=document.createElement("div");o.innerHTML=t.v,a.append(o),t.p=i({},t.p,{i:e,el:o}),r(t),n()}));const h=R(a.childNodes);this.viewHooks.transformHtml.call(this,h),I(t,((t,e,n)=>{var r;const i=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(i.width),Math.max(Math.ceil(i.height),s)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()})),a.remove(),c.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t&&(this.state.data=t),this.initializeData(this.state.data),e&&this.setOptions(e),this.renderData()}renderData(t){var e,n;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:s,spacingVertical:o,autoFit:a,color:l}=this.options,{id:c}=this.state,h=f().children((t=>{var e;return!(null!=(e=t.p)&&e.f)&&t.c})).nodeSize((t=>{const[e,n]=t.data.p.s;return[n,e+(e?2*s:0)+i]})).spacing(((t,e)=>t.parent===e.parent?o:2*o)),d=h.hierarchy(this.state.data);h(d),function(t,e){I(t,((t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()}),"children")}(d,i);const u=d.descendants().reverse(),p=d.links(),g=r.linkHorizontal(),m=r.min(u,(t=>t.x-t.xSize/2)),x=r.max(u,(t=>t.x+t.xSize/2)),y=r.min(u,(t=>t.y)),v=r.max(u,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:m,maxX:x,minY:y,maxY:v}),a&&this.fit();const z=t&&u.find((e=>e.data===t))||d,b=null!=(e=z.data.p.x0)?e:z.x,S=null!=(n=z.data.p.y0)?n:z.y,k=this.g.selectAll(B("g")).data(u,(t=>t.data.p.k)),w=k.enter().append("g").attr("transform",(t=>`translate(${S+z.ySizeInner-t.ySizeInner},${b+z.xSize/2-t.xSize})`)),E=this.transition(k.exit());E.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),E.select("foreignObject").style("opacity",0),E.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const $=k.merge(w);this.transition($).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const X=$.selectAll(B("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-F(t)/2)).attr("width",0).attr("height",F)),(t=>t),(t=>t.remove()));this.transition(X).attr("x",-1).attr("width",(t=>t.ySizeInner+2)).attr("fill",(t=>l(t.data)));const j=$.selectAll(B("circle")).data((t=>t.data.c?[t]:[]),(t=>t.data.p.k)).join((t=>t.append("circle").attr("stroke-width","1.5").attr("cx",(t=>t.ySizeInner)).attr("cy",(t=>t.xSize)).attr("r",0).on("click",this.handleClick)),(t=>t),(t=>t.remove()));this.transition(j).attr("r",6).attr("stroke",(t=>l(t.data))).attr("fill",(t=>{var e;return null!=(e=t.data.p)&&e.f&&t.data.c?l(t.data):"#fff"}));const C=$.selectAll(B("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",`${c}-fo`).attr("x",s).attr("y",0).style("opacity",0).attr("height",(t=>t.xSize)).on("mousedown",Y).on("dblclick",Y);return e.append("xhtml:div").select((function(t){const e=t.data.p.el.cloneNode(!0);return this.replaceWith(e),e})).attr("xmlns","http://www.w3.org/1999/xhtml"),e}),(t=>t),(t=>t.remove())).attr("width",(t=>Math.max(0,t.ySizeInner-2*s)));this.transition(C).style("opacity",1);const O=this.g.selectAll(B("path")).data(p,(t=>t.target.data.p.k)).join((t=>{const e=[S+z.ySizeInner,b+z.xSize/2];return t.insert("path","g").attr("d",g({source:e,target:e}))}),(t=>t),(t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",g({source:e,target:e})).remove()}));this.transition(O).attr("stroke",(t=>l(t.target.data))).attr("stroke-width",(t=>F(t.target))).attr("d",(t=>{const e=[t.source.y+t.source.ySizeInner,t.source.x+t.source.xSize/2],n=[t.target.y,t.target.x+t.target.xSize/2];return g({source:e,target:n})})),u.forEach((t=>{t.data.p.x0=t.x,t.data.p.y0=t.y}))}transition(t){const{duration:e}=this.options;return t.transition().duration(e)}async fit(){const t=this.svg.node(),{width:e,height:n}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:s,maxX:o,minY:a,maxY:l}=this.state,c=l-a,h=o-s,d=Math.min(e/c*i,n/h*i,2),u=r.zoomIdentity.translate((e-c*d)/2-a*d,(n-h*d)/2-s*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(M)}async ensureView(t,e){let n,s;if(this.g.selectAll(B("g")).each((function(e){e.data===t&&(n=this,s=e)})),!n||!s)return;const o=this.svg.node(),a=o.getBoundingClientRect(),l=r.zoomTransform(o),[c,h]=[s.y,s.y+s.ySizeInner+2].map((t=>t*l.k+l.x)),[d,u]=[s.x-s.xSize/2,s.x+s.xSize/2].map((t=>t*l.k+l.y)),p=i({left:0,right:0,top:0,bottom:0},e),f=[p.left-c,a.width-p.right-h],g=[p.top-d,a.height-p.bottom-u],m=f[0]*f[1]>0?L(f,Math.abs)/l.k:0,x=g[0]*g[1]>0?L(g,Math.abs)/l.k:0;if(m||x){const t=l.translate(m,x);return this.transition(this.svg).call(this.zoom.transform,t).end().catch(M)}}async rescale(t){const e=this.svg.node(),{width:n,height:i}=e.getBoundingClientRect(),s=n/2,o=i/2,a=r.zoomTransform(e),l=a.translate((s-a.x)*(1-t)/a.k,(o-a.y)*(1-t)/a.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,l).end().catch(M)}destroy(){this.svg.remove(),this.revokers.forEach((t=>{t()}))}static create(t,e,n){const r=new U(t,e);return n&&(r.setData(n),r.fit()),r}}var V;U.defaultOptions={duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(V=r.scaleOrdinal(r.schemeCategory10),t=>V(t.p.i)),paddingX:8},t.Markmap=U,t.loadCSS=function(t){for(const e of t)N(e)},t.loadJS=async function(t,e){const n=t.filter((t=>{var e;return"script"===t.type&&(null==(e=t.data)?void 0:e.src)}));n.length>1&&n.forEach((t=>H(t.data.src))),e=j({getMarkmap:()=>window.markmap},e);for(const n of t)await T(n,e)},t.refreshHook=P}(this.markmap=this.markmap||{},d3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-view",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "View markmaps in browser",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -21,7 +21,6 @@
21
21
  "scripts": {
22
22
  "dev": "rollup -wc rollup.conf.js",
23
23
  "clean": "del-cli dist types",
24
- "lint": "eslint --ext .ts .",
25
24
  "build:js": "rollup -c rollup.conf.js",
26
25
  "build:types": "tsc"
27
26
  },
@@ -42,10 +41,10 @@
42
41
  "@types/d3": "^6.0.0",
43
42
  "d3": "^6.2.0",
44
43
  "d3-flextree": "^2.1.1",
45
- "markmap-common": "^0.1.5"
44
+ "markmap-common": "^0.1.6"
46
45
  },
47
46
  "engines": {
48
47
  "node": ">=10"
49
48
  },
50
- "gitHead": "c1b04d45e3d7a9be432c2980ee105983abac7470"
49
+ "gitHead": "fbec667e1706813f9f60bea6a971f3820858ca40"
51
50
  }
package/types/index.d.ts CHANGED
@@ -1,53 +1,53 @@
1
- import * as d3 from 'd3';
2
- import { INode, Hook, loadJS, loadCSS } from 'markmap-common';
3
- import { IMarkmapOptions, IMarkmapState, IMarkmapFlexTreeItem } from './types';
4
- export { loadJS, loadCSS };
5
- interface IPadding {
6
- left: number;
7
- right: number;
8
- top: number;
9
- bottom: number;
10
- }
11
- declare type ID3SVGElement = d3.Selection<SVGElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
12
- declare function createViewHooks(): {
13
- transformHtml: Hook<(mm: Markmap, nodes: HTMLElement[]) => void>;
14
- };
15
- /**
16
- * A global hook to refresh all markmaps when called.
17
- */
18
- export declare const refreshHook: Hook<() => void>;
19
- export declare class Markmap {
20
- static defaultOptions: IMarkmapOptions;
21
- options: IMarkmapOptions;
22
- state: IMarkmapState;
23
- svg: ID3SVGElement;
24
- styleNode: d3.Selection<HTMLStyleElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
25
- g: d3.Selection<SVGGElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
26
- zoom: d3.ZoomBehavior<Element, unknown>;
27
- viewHooks: ReturnType<typeof createViewHooks>;
28
- revokers: (() => void)[];
29
- constructor(svg: string | SVGElement | ID3SVGElement, opts?: IMarkmapOptions);
30
- getStyleContent(): string;
31
- updateStyle(): void;
32
- handleZoom(e: any): void;
33
- handleClick(e: any, d: IMarkmapFlexTreeItem): void;
34
- initializeData(node: INode): void;
35
- setOptions(opts: IMarkmapOptions): void;
36
- setData(data?: INode, opts?: IMarkmapOptions): void;
37
- renderData(originData?: INode): void;
38
- transition<T extends d3.BaseType, U, P extends d3.BaseType, Q>(sel: d3.Selection<T, U, P, Q>): d3.Transition<T, U, P, Q>;
39
- /**
40
- * Fit the content to the viewport.
41
- */
42
- fit(): Promise<void>;
43
- /**
44
- * Pan the content to make the provided node visible in the viewport.
45
- */
46
- ensureView(node: INode, padding: Partial<IPadding> | undefined): Promise<void>;
47
- /**
48
- * Scale content with it pinned at the center of the viewport.
49
- */
50
- rescale(scale: number): Promise<void>;
51
- destroy(): void;
52
- static create(svg: string | SVGElement | ID3SVGElement, opts?: IMarkmapOptions, data?: INode): Markmap;
53
- }
1
+ import * as d3 from 'd3';
2
+ import { INode, Hook, loadJS, loadCSS } from 'markmap-common';
3
+ import { IMarkmapOptions, IMarkmapState, IMarkmapFlexTreeItem } from './types';
4
+ export { loadJS, loadCSS };
5
+ interface IPadding {
6
+ left: number;
7
+ right: number;
8
+ top: number;
9
+ bottom: number;
10
+ }
11
+ declare type ID3SVGElement = d3.Selection<SVGElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
12
+ declare function createViewHooks(): {
13
+ transformHtml: Hook<[mm: Markmap, nodes: HTMLElement[]]>;
14
+ };
15
+ /**
16
+ * A global hook to refresh all markmaps when called.
17
+ */
18
+ export declare const refreshHook: Hook<[]>;
19
+ export declare class Markmap {
20
+ static defaultOptions: IMarkmapOptions;
21
+ options: IMarkmapOptions;
22
+ state: IMarkmapState;
23
+ svg: ID3SVGElement;
24
+ styleNode: d3.Selection<HTMLStyleElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
25
+ g: d3.Selection<SVGGElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
26
+ zoom: d3.ZoomBehavior<Element, unknown>;
27
+ viewHooks: ReturnType<typeof createViewHooks>;
28
+ revokers: (() => void)[];
29
+ constructor(svg: string | SVGElement | ID3SVGElement, opts?: IMarkmapOptions);
30
+ getStyleContent(): string;
31
+ updateStyle(): void;
32
+ handleZoom(e: any): void;
33
+ handleClick(e: any, d: IMarkmapFlexTreeItem): void;
34
+ initializeData(node: INode): void;
35
+ setOptions(opts: IMarkmapOptions): void;
36
+ setData(data?: INode, opts?: IMarkmapOptions): void;
37
+ renderData(originData?: INode): void;
38
+ transition<T extends d3.BaseType, U, P extends d3.BaseType, Q>(sel: d3.Selection<T, U, P, Q>): d3.Transition<T, U, P, Q>;
39
+ /**
40
+ * Fit the content to the viewport.
41
+ */
42
+ fit(): Promise<void>;
43
+ /**
44
+ * Pan the content to make the provided node visible in the viewport.
45
+ */
46
+ ensureView(node: INode, padding: Partial<IPadding> | undefined): Promise<void>;
47
+ /**
48
+ * Scale content with it pinned at the center of the viewport.
49
+ */
50
+ rescale(scale: number): Promise<void>;
51
+ destroy(): void;
52
+ static create(svg: string | SVGElement | ID3SVGElement, opts?: IMarkmapOptions, data?: INode): Markmap;
53
+ }
package/types/types.d.ts CHANGED
@@ -1,38 +1,36 @@
1
- import { INode } from 'markmap-common';
2
- import { Markmap } from '.';
3
- export declare type IMarkmap = typeof Markmap;
4
- export interface IMarkmapOptions {
5
- id?: string;
6
- duration?: number;
7
- nodeFont?: string;
8
- nodeMinHeight?: number;
9
- spacingVertical?: number;
10
- spacingHorizontal?: number;
11
- autoFit?: boolean;
12
- fitRatio?: number;
13
- color?: (node: INode) => string;
14
- paddingX?: number;
15
- style?: (id: string) => string;
16
- }
17
- export interface IMarkmapState {
18
- id: string;
19
- data?: INode;
20
- minX?: number;
21
- maxX?: number;
22
- minY?: number;
23
- maxY?: number;
24
- }
25
- export interface IMarkmapFlexTreeItem {
26
- parent: IMarkmapFlexTreeItem;
27
- data: INode;
28
- depth: number;
29
- xSize: number;
30
- ySize: number;
31
- ySizeInner: number;
32
- x: number;
33
- y: number;
34
- }
35
- export interface IMarkmapLinkItem {
36
- source: IMarkmapFlexTreeItem;
37
- target: IMarkmapFlexTreeItem;
38
- }
1
+ import { INode } from 'markmap-common';
2
+ export interface IMarkmapOptions {
3
+ id?: string;
4
+ duration?: number;
5
+ nodeFont?: string;
6
+ nodeMinHeight?: number;
7
+ spacingVertical?: number;
8
+ spacingHorizontal?: number;
9
+ autoFit?: boolean;
10
+ fitRatio?: number;
11
+ color?: (node: INode) => string;
12
+ paddingX?: number;
13
+ style?: (id: string) => string;
14
+ }
15
+ export interface IMarkmapState {
16
+ id: string;
17
+ data?: INode;
18
+ minX?: number;
19
+ maxX?: number;
20
+ minY?: number;
21
+ maxY?: number;
22
+ }
23
+ export interface IMarkmapFlexTreeItem {
24
+ parent: IMarkmapFlexTreeItem;
25
+ data: INode;
26
+ depth: number;
27
+ xSize: number;
28
+ ySize: number;
29
+ ySizeInner: number;
30
+ x: number;
31
+ y: number;
32
+ }
33
+ export interface IMarkmapLinkItem {
34
+ source: IMarkmapFlexTreeItem;
35
+ target: IMarkmapFlexTreeItem;
36
+ }