markmap-view 0.15.6 → 0.15.8

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.
Files changed (2) hide show
  1. package/dist/browser/index.js +1586 -4
  2. package/package.json +2 -2
@@ -1,4 +1,1586 @@
1
- (function(z,v){"use strict";class K{constructor(){this.listeners=[]}tap(e){return this.listeners.push(e),()=>this.revoke(e)}revoke(e){const n=this.listeners.indexOf(e);n>=0&&this.listeners.splice(n,1)}revokeAll(){this.listeners.splice(0)}call(...e){for(const n of this.listeners)n(...e)}}const pt=Math.random().toString(36).slice(2,8);let U=0;function gt(){return U+=1,`mm-${pt}-${U}`}function R(){}function _(t,e){const n=(i,o)=>e(i,()=>{var s;(s=i.children)==null||s.forEach(l=>{n(l,i)})},o);n(t)}function mt(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach(i=>{i&&n.indexOf(i)<0&&n.push(i)}),n.join(" ")}function w(t){if(typeof t=="string"){const n=t;t=i=>i.tagName===n}const e=t;return function(){let i=Array.from(this.childNodes);return e&&(i=i.filter(o=>e(o))),i}}function G(){const t={};return t.promise=new Promise((e,n)=>{t.resolve=e,t.reject=n}),t}function yt(t){const e={};return function(...i){const o=`${i[0]}`;let s=e[o];return s||(s={value:t(...i)},e[o]=s),s.value}}/*! @gera2ld/jsx-dom v2.2.2 | ISC License */const J=1,Z=2,xt="http://www.w3.org/2000/svg",L="http://www.w3.org/1999/xlink",St={show:L,actuate:L,href:L},vt=t=>typeof t=="string"||typeof t=="number",kt=t=>(t==null?void 0:t.vtype)===J,bt=t=>(t==null?void 0:t.vtype)===Z;function zt(t,e,...n){return e=Object.assign({},e,{children:n.length===1?n[0]:n}),wt(t,e)}function wt(t,e){let n;if(typeof t=="string")n=J;else if(typeof t=="function")n=Z;else throw new Error("Invalid VNode type");return{vtype:n,type:t,props:e}}function Et(t){return t.children}const Ct={isSvg:!1};function q(t,e){Array.isArray(e)||(e=[e]),e=e.filter(Boolean),e.length&&t.append(...e)}function Nt(t,e,n){for(const i in e)if(!(i==="key"||i==="children"||i==="ref"))if(i==="dangerouslySetInnerHTML")t.innerHTML=e[i].__html;else if(i==="innerHTML"||i==="textContent"||i==="innerText"||i==="value"&&["textarea","select"].includes(t.tagName)){const o=e[i];o!=null&&(t[i]=o)}else i.startsWith("on")?t[i.toLowerCase()]=e[i]:$t(t,i,e[i],n.isSvg)}const jt={className:"class",labelFor:"for"};function $t(t,e,n,i){if(e=jt[e]||e,n===!0)t.setAttribute(e,"");else if(n===!1)t.removeAttribute(e);else{const o=i?St[e]:void 0;o!==void 0?t.setAttributeNS(o,e,n):t.setAttribute(e,n)}}function Tt(t){return t.reduce((e,n)=>e.concat(n),[])}function D(t,e){return Array.isArray(t)?Tt(t.map(n=>D(n,e))):F(t,e)}function F(t,e=Ct){if(t==null||typeof t=="boolean")return null;if(t instanceof Node)return t;if(bt(t)){const{type:n,props:i}=t;if(n===Et){const s=document.createDocumentFragment();if(i.children){const l=D(i.children,e);q(s,l)}return s}const o=n(i);return F(o,e)}if(vt(t))return document.createTextNode(`${t}`);if(kt(t)){let n;const{type:i,props:o}=t;if(!e.isSvg&&i==="svg"&&(e=Object.assign({},e,{isSvg:!0})),e.isSvg?n=document.createElementNS(xt,i):n=document.createElement(i),Nt(n,o,e),o.children){let l=e;e.isSvg&&i==="foreignObject"&&(l=Object.assign({},l,{isSvg:!1}));const a=D(o.children,l);a!=null&&q(n,a)}const{ref:s}=o;return typeof s=="function"&&s(n),n}throw new Error("mount: Invalid Vnode!")}function Xt(t){return F(t)}function j(...t){return Xt(zt(...t))}const At=yt(t=>{document.head.append(j("link",{rel:"preload",as:"script",href:t}))}),Q={},tt={};async function Mt(t,e){var n;const i=t.type==="script"&&((n=t.data)==null?void 0:n.src)||"";if(t.loaded||(t.loaded=Q[i]),!t.loaded){const o=G();if(t.loaded=o.promise,t.type==="script"&&(document.head.append(j("script",{...t.data,onLoad:()=>o.resolve(),onError:o.reject})),i?Q[i]=t.loaded:o.resolve()),t.type==="iife"){const{fn:s,getParams:l}=t.data;s(...(l==null?void 0:l(e))||[]),o.resolve()}}await t.loaded}async function Ot(t){const e=t.type==="stylesheet"&&t.data.href||"";if(t.loaded||(t.loaded=tt[e]),!t.loaded){const n=G();t.loaded=n.promise,e&&(tt[e]=t.loaded),t.type==="style"?(document.head.append(j("style",{textContent:t.data})),n.resolve()):e&&(document.head.append(j("link",{rel:"stylesheet",...t.data})),fetch(e).then(i=>{if(i.ok)return i.text();throw i}).then(()=>n.resolve(),n.reject))}await t.loaded}async function Rt(t,e){t.forEach(n=>{var i;n.type==="script"&&((i=n.data)!=null&&i.src)&&At(n.data.src)}),e={getMarkmap:()=>window.markmap,...e};for(const n of t)await Mt(n,e)}async function _t(t){await Promise.all(t.map(e=>Ot(e)))}/*! @gera2ld/jsx-dom v2.2.2 | ISC License */const et=1,nt=2,Lt="http://www.w3.org/2000/svg",H="http://www.w3.org/1999/xlink",Dt={show:H,actuate:H,href:H},Ft=t=>typeof t=="string"||typeof t=="number",Ht=t=>(t==null?void 0:t.vtype)===et,Bt=t=>(t==null?void 0:t.vtype)===nt;function $(t,e){let n;if(typeof t=="string")n=et;else if(typeof t=="function")n=nt;else throw new Error("Invalid VNode type");return{vtype:n,type:t,props:e}}function It(t){return t.children}const Vt={isSvg:!1};function it(t,e){Array.isArray(e)||(e=[e]),e=e.filter(Boolean),e.length&&t.append(...e)}function Pt(t,e,n){for(const i in e)if(!(i==="key"||i==="children"||i==="ref"))if(i==="dangerouslySetInnerHTML")t.innerHTML=e[i].__html;else if(i==="innerHTML"||i==="textContent"||i==="innerText"||i==="value"&&["textarea","select"].includes(t.tagName)){const o=e[i];o!=null&&(t[i]=o)}else i.startsWith("on")?t[i.toLowerCase()]=e[i]:Yt(t,i,e[i],n.isSvg)}const Wt={className:"class",labelFor:"for"};function Yt(t,e,n,i){if(e=Wt[e]||e,n===!0)t.setAttribute(e,"");else if(n===!1)t.removeAttribute(e);else{const o=i?Dt[e]:void 0;o!==void 0?t.setAttributeNS(o,e,n):t.setAttribute(e,n)}}function Kt(t){return t.reduce((e,n)=>e.concat(n),[])}function B(t,e){return Array.isArray(t)?Kt(t.map(n=>B(n,e))):I(t,e)}function I(t,e=Vt){if(t==null||typeof t=="boolean")return null;if(t instanceof Node)return t;if(Bt(t)){const{type:n,props:i}=t;if(n===It){const s=document.createDocumentFragment();if(i.children){const l=B(i.children,e);it(s,l)}return s}const o=n(i);return I(o,e)}if(Ft(t))return document.createTextNode(`${t}`);if(Ht(t)){let n;const{type:i,props:o}=t;if(!e.isSvg&&i==="svg"&&(e=Object.assign({},e,{isSvg:!0})),e.isSvg?n=document.createElementNS(Lt,i):n=document.createElement(i),Pt(n,o,e),o.children){let l=e;e.isSvg&&i==="foreignObject"&&(l=Object.assign({},l,{isSvg:!1}));const a=B(o.children,l);a!=null&&it(n,a)}const{ref:s}=o;return typeof s=="function"&&s(n),n}throw new Error("mount: Invalid Vnode!")}function V(t){return I(t)}function Ut(t){var e=0,n=t.children,i=n&&n.length;if(!i)e=1;else for(;--i>=0;)e+=n[i].value;t.value=e}function Gt(){return this.eachAfter(Ut)}function Jt(t){var e=this,n,i=[e],o,s,l;do for(n=i.reverse(),i=[];e=n.pop();)if(t(e),o=e.children,o)for(s=0,l=o.length;s<l;++s)i.push(o[s]);while(i.length);return this}function Zt(t){for(var e=this,n=[e],i,o;e=n.pop();)if(t(e),i=e.children,i)for(o=i.length-1;o>=0;--o)n.push(i[o]);return this}function qt(t){for(var e=this,n=[e],i=[],o,s,l;e=n.pop();)if(i.push(e),o=e.children,o)for(s=0,l=o.length;s<l;++s)n.push(o[s]);for(;e=i.pop();)t(e);return this}function Qt(t){return this.eachAfter(function(e){for(var n=+t(e.data)||0,i=e.children,o=i&&i.length;--o>=0;)n+=i[o].value;e.value=n})}function te(t){return this.eachBefore(function(e){e.children&&e.children.sort(t)})}function ee(t){for(var e=this,n=ne(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var o=i.length;t!==n;)i.splice(o,0,t),t=t.parent;return i}function ne(t,e){if(t===e)return t;var n=t.ancestors(),i=e.ancestors(),o=null;for(t=n.pop(),e=i.pop();t===e;)o=t,t=n.pop(),e=i.pop();return o}function ie(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e}function oe(){var t=[];return this.each(function(e){t.push(e)}),t}function re(){var t=[];return this.eachBefore(function(e){e.children||t.push(e)}),t}function se(){var t=this,e=[];return t.each(function(n){n!==t&&e.push({source:n.parent,target:n})}),e}function P(t,e){var n=new T(t),i=+t.value&&(n.value=t.value),o,s=[n],l,a,c,p;for(e==null&&(e=le);o=s.pop();)if(i&&(o.value=+o.data.value),(a=e(o.data))&&(p=a.length))for(o.children=new Array(p),c=p-1;c>=0;--c)s.push(l=o.children[c]=new T(a[c])),l.parent=o,l.depth=o.depth+1;return n.eachBefore(he)}function ae(){return P(this).eachBefore(ce)}function le(t){return t.children}function ce(t){t.data=t.data.data}function he(t){var e=0;do t.height=e;while((t=t.parent)&&t.height<++e)}function T(t){this.data=t,this.depth=this.height=0,this.parent=null}T.prototype=P.prototype={constructor:T,count:Gt,each:Jt,eachAfter:qt,eachBefore:Zt,sum:Qt,sort:te,path:ee,ancestors:ie,descendants:oe,leaves:re,links:se,copy:ae};const de={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"}},{version:ue}=de,fe=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function ot(t){const e=Object.assign({},fe,t);function n(a){const c=e[a];return typeof c=="function"?c:()=>c}function i(a){const c=l(s(),a,p=>p.children);return c.update(),c.data}function o(){const a=n("nodeSize"),c=n("spacing");return class ft extends P.prototype.constructor{constructor(h){super(h)}copy(){const h=l(this.constructor,this,f=>f.children);return h.each(f=>f.data=f.data.data),h}get size(){return a(this)}spacing(h){return c(this,h)}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 h=this.ancestors();return h[h.length-1]}get numChildren(){return this.hasChildren?this.children.length:0}get hasChildren(){return!this.noChildren}get noChildren(){return this.children===null}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((h,f)=>ft.maxExtents(h,f.extents),this.nodeExtents)}get nodeExtents(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}static maxExtents(h,f){return{top:Math.min(h.top,f.top),bottom:Math.max(h.bottom,f.bottom),left:Math.min(h.left,f.left),right:Math.max(h.right,f.right)}}}}function s(){const a=o(),c=n("nodeSize"),p=n("spacing");return class extends a{constructor(h){super(h),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 c(this.data)}spacing(h){return p(this.data,h.data)}get x(){return this.data.x}set x(h){this.data.x=h}get y(){return this.data.y}set y(h){this.data.y=h}update(){return rt(this),st(this),this}}}function l(a,c,p){const h=(f,m)=>{const d=new a(f);Object.assign(d,{parent:m,depth:m===null?0:m.depth+1,height:0,length:1});const S=p(f)||[];return d.children=S.length===0?null:S.map(y=>h(y,d)),d.children&&Object.assign(d,d.children.reduce((y,g)=>({height:Math.max(y.height,g.height+1),length:y.length+g.length}),d)),d};return h(c,null)}return Object.assign(i,{nodeSize(a){return arguments.length?(e.nodeSize=a,i):e.nodeSize},spacing(a){return arguments.length?(e.spacing=a,i):e.spacing},children(a){return arguments.length?(e.children=a,i):e.children},hierarchy(a,c){const p=typeof c>"u"?e.children:c;return l(o(),a,p)},dump(a){const c=n("nodeSize"),p=h=>f=>{const m=h+" ",d=h+" ",{x:S,y}=f,g=c(f),x=f.children||[],k=x.length===0?" ":`,${m}children: [${d}${x.map(p(d)).join(d)}${m}],${h}`;return`{ size: [${g.join(", ")}],${m}x: ${S}, y: ${y}${k}},`};return p(`
2
- `)(a)}}),i}ot.version=ue;const rt=(t,e=0)=>(t.y=e,(t.children||[]).reduce((n,i)=>{const[o,s]=n;rt(i,t.y+t.ySize);const l=(o===0?i.lExt:i.rExt).bottom;o!==0&&ge(t,o,s);const a=ze(l,o,s);return[o+1,a]},[0,null]),pe(t),be(t),t),st=(t,e,n)=>{typeof e>"u"&&(e=-t.relX-t.prelim,n=0);const i=e+t.relX;return t.relX=i+t.prelim-n,t.prelim=0,t.x=n+t.relX,(t.children||[]).forEach(o=>st(o,i,t.x)),t},pe=t=>{(t.children||[]).reduce((e,n)=>{const[i,o]=e,s=i+n.shift,l=o+s+n.change;return n.relX+=l,[s,l]},[0,0])},ge=(t,e,n)=>{const i=t.children[e-1],o=t.children[e];let s=i,l=i.relX,a=o,c=o.relX,p=!0;for(;s&&a;){s.bottom>n.lowY&&(n=n.next);const h=l+s.prelim-(c+a.prelim)+s.xSize/2+a.xSize/2+s.spacing(a);(h>0||h<0&&p)&&(c+=h,me(o,h),ye(t,e,n.index,h)),p=!1;const f=s.bottom,m=a.bottom;f<=m&&(s=Se(s),s&&(l+=s.relX)),f>=m&&(a=xe(a),a&&(c+=a.relX))}!s&&a?ve(t,e,a,c):s&&!a&&ke(t,e,s,l)},me=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},ye=(t,e,n,i)=>{const o=t.children[e],s=e-n;if(s>1){const l=i/s;t.children[n+1].shift+=l,o.shift-=l,o.change-=i-l}},xe=t=>t.hasChildren?t.firstChild:t.lThr,Se=t=>t.hasChildren?t.lastChild:t.rThr,ve=(t,e,n,i)=>{const o=t.firstChild,s=o.lExt,l=t.children[e];s.lThr=n;const a=i-n.relX-o.lExtRelX;s.relX+=a,s.prelim-=a,o.lExt=l.lExt,o.lExtRelX=l.lExtRelX},ke=(t,e,n,i)=>{const o=t.children[e],s=o.rExt,l=t.children[e-1];s.rThr=n;const a=i-n.relX-o.rExtRelX;s.relX+=a,s.prelim-=a,o.rExt=l.rExt,o.rExtRelX=l.rExtRelX},be=t=>{if(t.hasChildren){const e=t.firstChild,n=t.lastChild,i=(e.prelim+e.relX-e.xSize/2+n.relX+n.prelim+n.xSize/2)/2;Object.assign(t,{prelim:i,lExt:e.lExt,lExtRelX:e.lExtRelX,rExt:n.rExt,rExtRelX:n.rExtRelX})}},ze=(t,e,n)=>{for(;n!==null&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}},at=".markmap{font:300 16px/20px sans-serif}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign a{color:#0097e6}.markmap-foreign a:hover{color:#00a8ff}.markmap-foreign code{padding:.25em;font-size:calc(1em - 2px);color:#555;background-color:#f0f0f0;border-radius:2px}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:#ffeaa7}",we=".markmap-container{position:absolute;width:0;height:0;top:-100px;left:-100px;overflow:hidden}.markmap-container>.markmap-foreign{display:inline-block}.markmap-container>.markmap-foreign>div:last-child,.markmap-container>.markmap-foreign>div:last-child :not(pre){white-space:nowrap}.markmap-container>.markmap-foreign>div:last-child code{white-space:inherit}",Ee=at;function lt(t){const e=t.data;return Math.max(4-2*e.depth,1.5)}function ct(t,e){const n=v.minIndex(t,e);return t[n]}function W(t){t.stopPropagation()}function Ce(){return{transformHtml:new K}}const ht=new K,dt=v.scaleOrdinal(v.schemeCategory10),ut=typeof navigator<"u"&&navigator.userAgent.includes("Macintosh"),C=class C{constructor(e,n){this.options=C.defaultOptions,this.revokers=[],this.handleZoom=i=>{const{transform:o}=i;this.g.attr("transform",o)},this.handlePan=i=>{i.preventDefault();const o=v.zoomTransform(this.svg.node()),s=o.translate(-i.deltaX/o.k,-i.deltaY/o.k);this.svg.call(this.zoom.transform,s)},this.handleClick=(i,o)=>{let s=this.options.toggleRecursively;(ut?i.metaKey:i.ctrlKey)&&(s=!s),this.toggleNode(o.data,s)},this.viewHooks=Ce(),this.svg=e.datum?e:v.select(e),this.styleNode=this.svg.append("style"),this.zoom=v.zoom().filter(i=>this.options.scrollForPan&&i.type==="wheel"?i.ctrlKey&&!i.button:(!i.ctrlKey||i.type==="wheel")&&!i.button).on("zoom",this.handleZoom),this.setOptions(n),this.state={id:this.options.id||this.svg.attr("id")||gt(),minX:0,maxX:0,minY:0,maxY:0},this.g=this.svg.append("g"),this.revokers.push(ht.tap(()=>{this.setData()}))}getStyleContent(){const{style:e}=this.options,{id:n}=this.state,i=typeof e=="function"?e(n):"";return[this.options.embedGlobalCSS&&at,i].filter(Boolean).join(`
3
- `)}updateStyle(){this.svg.attr("class",mt(this.svg.attr("class"),"markmap",this.state.id));const e=this.getStyleContent();this.styleNode.text(e)}toggleNode(e,n=!1){var o,s;const i=(o=e.payload)!=null&&o.fold?0:1;n?_(e,(l,a)=>{l.payload={...l.payload,fold:i},a()}):e.payload={...e.payload,fold:(s=e.payload)!=null&&s.fold?0:1},this.renderData(e)}initializeData(e){let n=0;const{color:i,nodeMinHeight:o,maxWidth:s,initialExpandLevel:l}=this.options,{id:a}=this.state,c=V($("div",{className:`markmap-container markmap ${a}-g`})),p=V($("style",{children:[this.getStyleContent(),we].join(`
4
- `)}));document.body.append(c,p);const h=s?`max-width: ${s}px`:"";let f=0;_(e,(d,S,y)=>{var k,E,A;d.children=(k=d.children)==null?void 0:k.map(N=>({...N})),n+=1;const g=V($("div",{className:"markmap-foreign",style:h,children:$("div",{dangerouslySetInnerHTML:{__html:d.content}})}));c.append(g),d.state={...d.state,id:n,el:g.firstChild},d.state.path=[(E=y==null?void 0:y.state)==null?void 0:E.path,d.state.id].filter(Boolean).join("."),i(d);const x=((A=d.payload)==null?void 0:A.fold)===2;x?f+=1:(f||l>=0&&d.depth>=l)&&(d.payload={...d.payload,fold:1}),S(),x&&(f-=1)});const m=Array.from(c.childNodes).map(d=>d.firstChild);this.viewHooks.transformHtml.call(this,m),m.forEach(d=>{var S;(S=d.parentNode)==null||S.append(d.cloneNode(!0))}),_(e,(d,S,y)=>{var k;const g=d.state,x=g.el.getBoundingClientRect();d.content=g.el.innerHTML,g.size=[Math.ceil(x.width)+1,Math.max(Math.ceil(x.height),o)],g.key=[(k=y==null?void 0:y.state)==null?void 0:k.id,g.id].filter(Boolean).join(".")+d.content,S()}),c.remove(),p.remove()}setOptions(e){this.options={...this.options,...e},this.options.zoom?this.svg.call(this.zoom):this.svg.on(".zoom",null),this.options.pan?this.svg.on("wheel",this.handlePan):this.svg.on("wheel",null)}setData(e,n){n&&this.setOptions(n),e&&(this.state.data=e),this.state.data&&(this.initializeData(this.state.data),this.updateStyle(),this.renderData())}renderData(e){if(!this.state.data)return;const{spacingHorizontal:n,paddingX:i,spacingVertical:o,autoFit:s,color:l}=this.options,a=ot({}).children(r=>{var u;if(!((u=r.payload)!=null&&u.fold))return r.children}).nodeSize(r=>{const[u,b]=r.data.state.size;return[b,u+(u?i*2:0)+n]}).spacing((r,u)=>r.parent===u.parent?o:o*2),c=a.hierarchy(this.state.data);a(c);const p=c.descendants().reverse(),h=c.links(),f=v.linkHorizontal(),m=v.min(p,r=>r.x-r.xSize/2),d=v.max(p,r=>r.x+r.xSize/2),S=v.min(p,r=>r.y),y=v.max(p,r=>r.y+r.ySize-n);Object.assign(this.state,{minX:m,maxX:d,minY:S,maxY:y}),s&&this.fit();const g=e&&p.find(r=>r.data===e)||c,x=g.data.state.x0??g.x,k=g.data.state.y0??g.y,E=this.g.selectAll(w("g")).data(p,r=>r.data.state.key),A=E.enter().append("g").attr("data-depth",r=>r.data.depth).attr("data-path",r=>r.data.state.path).attr("transform",r=>`translate(${k+g.ySize-r.ySize},${x+g.xSize/2-r.xSize})`),N=this.transition(E.exit());N.select("line").attr("x1",r=>r.ySize-n).attr("x2",r=>r.ySize-n),N.select("foreignObject").style("opacity",0),N.attr("transform",r=>`translate(${g.y+g.ySize-r.ySize},${g.x+g.xSize/2-r.xSize})`).remove();const M=E.merge(A).attr("class",r=>{var u;return["markmap-node",((u=r.data.payload)==null?void 0:u.fold)&&"markmap-fold"].filter(Boolean).join(" ")});this.transition(M).attr("transform",r=>`translate(${r.y},${r.x-r.xSize/2})`);const je=M.selectAll(w("line")).data(r=>[r],r=>r.data.state.key).join(r=>r.append("line").attr("x1",u=>u.ySize-n).attr("x2",u=>u.ySize-n),r=>r,r=>r.remove());this.transition(je).attr("x1",-1).attr("x2",r=>r.ySize-n+2).attr("y1",r=>r.xSize).attr("y2",r=>r.xSize).attr("stroke",r=>l(r.data)).attr("stroke-width",lt);const $e=M.selectAll(w("circle")).data(r=>{var u;return(u=r.data.children)!=null&&u.length?[r]:[]},r=>r.data.state.key).join(r=>r.append("circle").attr("stroke-width","1.5").attr("cx",u=>u.ySize-n).attr("cy",u=>u.xSize).attr("r",0).on("click",(u,b)=>this.handleClick(u,b)).on("mousedown",W),r=>r,r=>r.remove());this.transition($e).attr("r",6).attr("cx",r=>r.ySize-n).attr("cy",r=>r.xSize).attr("stroke",r=>l(r.data)).attr("fill",r=>{var u;return(u=r.data.payload)!=null&&u.fold&&r.data.children?l(r.data):"#fff"});const Te=M.selectAll(w("foreignObject")).data(r=>[r],r=>r.data.state.key).join(r=>{const u=r.append("foreignObject").attr("class","markmap-foreign").attr("x",i).attr("y",0).style("opacity",0).on("mousedown",W).on("dblclick",W);return u.append("xhtml:div").select(function(Y){const O=Y.data.state.el.cloneNode(!0);return this.replaceWith(O),O}).attr("xmlns","http://www.w3.org/1999/xhtml"),u},r=>r,r=>r.remove()).attr("width",r=>Math.max(0,r.ySize-n-i*2)).attr("height",r=>r.xSize);this.transition(Te).style("opacity",1);const Xe=this.g.selectAll(w("path")).data(h,r=>r.target.data.state.key).join(r=>{const u=[k+g.ySize-n,x+g.xSize/2];return r.insert("path","g").attr("class","markmap-link").attr("data-depth",b=>b.target.data.depth).attr("data-path",b=>b.target.data.state.path).attr("d",f({source:u,target:u}))},r=>r,r=>{const u=[g.y+g.ySize-n,g.x+g.xSize/2];return this.transition(r).attr("d",f({source:u,target:u})).remove()});this.transition(Xe).attr("stroke",r=>l(r.target.data)).attr("stroke-width",r=>lt(r.target)).attr("d",r=>{const u=r.source,b=r.target,Y=[u.y+u.ySize-n,u.x+u.xSize/2],O=[b.y,b.x+b.xSize/2];return f({source:Y,target:O})}),p.forEach(r=>{r.data.state.x0=r.x,r.data.state.y0=r.y})}transition(e){const{duration:n}=this.options;return e.transition().duration(n)}async fit(){const e=this.svg.node(),{width:n,height:i}=e.getBoundingClientRect(),{fitRatio:o}=this.options,{minX:s,maxX:l,minY:a,maxY:c}=this.state,p=c-a,h=l-s,f=Math.min(n/p*o,i/h*o,2),m=v.zoomIdentity.translate((n-p*f)/2-a*f,(i-h*f)/2-s*f).scale(f);return this.transition(this.svg).call(this.zoom.transform,m).end().catch(R)}async ensureView(e,n){let i;if(this.g.selectAll(w("g")).each(function(k){k.data===e&&(i=k)}),!i)return;const o=this.svg.node(),{spacingHorizontal:s}=this.options,l=o.getBoundingClientRect(),a=v.zoomTransform(o),[c,p]=[i.y,i.y+i.ySize-s+2].map(x=>x*a.k+a.x),[h,f]=[i.x-i.xSize/2,i.x+i.xSize/2].map(x=>x*a.k+a.y),m={left:0,right:0,top:0,bottom:0,...n},d=[m.left-c,l.width-m.right-p],S=[m.top-h,l.height-m.bottom-f],y=d[0]*d[1]>0?ct(d,Math.abs)/a.k:0,g=S[0]*S[1]>0?ct(S,Math.abs)/a.k:0;if(y||g){const x=a.translate(y,g);return this.transition(this.svg).call(this.zoom.transform,x).end().catch(R)}}async rescale(e){const n=this.svg.node(),{width:i,height:o}=n.getBoundingClientRect(),s=i/2,l=o/2,a=v.zoomTransform(n),c=a.translate((s-a.x)*(1-e)/a.k,(l-a.y)*(1-e)/a.k).scale(e);return this.transition(this.svg).call(this.zoom.transform,c).end().catch(R)}destroy(){this.svg.on(".zoom",null),this.svg.html(null),this.revokers.forEach(e=>{e()})}static create(e,n,i=null){const o=new C(e,n);return i&&(o.setData(i),o.fit()),o}};C.defaultOptions={autoFit:!1,color:e=>{var n;return dt(`${((n=e.state)==null?void 0:n.path)||""}`)},duration:500,embedGlobalCSS:!0,fitRatio:.95,maxWidth:0,nodeMinHeight:16,paddingX:8,scrollForPan:ut,spacingHorizontal:80,spacingVertical:5,initialExpandLevel:-1,zoom:!0,pan:!0,toggleRecursively:!1};let X=C;function Ne(t){const e={},n={...t},{color:i,colorFreezeLevel:o}=n;if((i==null?void 0:i.length)===1){const a=i[0];e.color=()=>a}else if(i!=null&&i.length){const a=v.scaleOrdinal(i);e.color=c=>a(`${c.state.path}`)}if(o){const a=e.color||X.defaultOptions.color;e.color=c=>(c={...c,state:{...c.state,path:c.state.path.split(".").slice(0,o).join(".")}},a(c))}return["duration","maxWidth","initialExpandLevel"].forEach(a=>{const c=n[a];typeof c=="number"&&(e[a]=c)}),["zoom","pan"].forEach(a=>{const c=n[a];c!=null&&(e[a]=!!c)}),e}z.Markmap=X,z.defaultColorFn=dt,z.deriveOptions=Ne,z.globalCSS=Ee,z.loadCSS=_t,z.loadJS=Rt,z.refreshHook=ht,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})})(this.markmap=this.markmap||{},d3);
1
+ (function(exports, d32) {
2
+ "use strict";
3
+ class Hook {
4
+ constructor() {
5
+ this.listeners = [];
6
+ }
7
+ tap(fn) {
8
+ this.listeners.push(fn);
9
+ return () => this.revoke(fn);
10
+ }
11
+ revoke(fn) {
12
+ const i = this.listeners.indexOf(fn);
13
+ if (i >= 0)
14
+ this.listeners.splice(i, 1);
15
+ }
16
+ revokeAll() {
17
+ this.listeners.splice(0);
18
+ }
19
+ call(...args) {
20
+ for (const fn of this.listeners) {
21
+ fn(...args);
22
+ }
23
+ }
24
+ }
25
+ const uniqId = Math.random().toString(36).slice(2, 8);
26
+ let globalIndex = 0;
27
+ function getId() {
28
+ globalIndex += 1;
29
+ return `mm-${uniqId}-${globalIndex}`;
30
+ }
31
+ function noop() {
32
+ }
33
+ function walkTree(tree, callback) {
34
+ const walk = (item, parent) => callback(
35
+ item,
36
+ () => {
37
+ var _a;
38
+ (_a = item.children) == null ? void 0 : _a.forEach((child) => {
39
+ walk(child, item);
40
+ });
41
+ },
42
+ parent
43
+ );
44
+ walk(tree);
45
+ }
46
+ function addClass(className, ...rest) {
47
+ const classList = (className || "").split(" ").filter(Boolean);
48
+ rest.forEach((item) => {
49
+ if (item && classList.indexOf(item) < 0)
50
+ classList.push(item);
51
+ });
52
+ return classList.join(" ");
53
+ }
54
+ function childSelector(filter) {
55
+ if (typeof filter === "string") {
56
+ const tagName = filter;
57
+ filter = (el) => el.tagName === tagName;
58
+ }
59
+ const filterFn = filter;
60
+ return function selector() {
61
+ let nodes = Array.from(this.childNodes);
62
+ if (filterFn)
63
+ nodes = nodes.filter((node) => filterFn(node));
64
+ return nodes;
65
+ };
66
+ }
67
+ function defer() {
68
+ const obj = {};
69
+ obj.promise = new Promise((resolve, reject) => {
70
+ obj.resolve = resolve;
71
+ obj.reject = reject;
72
+ });
73
+ return obj;
74
+ }
75
+ function memoize(fn) {
76
+ const cache = {};
77
+ return function memoized(...args) {
78
+ const key = `${args[0]}`;
79
+ let data = cache[key];
80
+ if (!data) {
81
+ data = {
82
+ value: fn(...args)
83
+ };
84
+ cache[key] = data;
85
+ }
86
+ return data.value;
87
+ };
88
+ }
89
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
90
+ const VTYPE_ELEMENT$1 = 1;
91
+ const VTYPE_FUNCTION$1 = 2;
92
+ const SVG_NS$1 = "http://www.w3.org/2000/svg";
93
+ const XLINK_NS$1 = "http://www.w3.org/1999/xlink";
94
+ const NS_ATTRS$1 = {
95
+ show: XLINK_NS$1,
96
+ actuate: XLINK_NS$1,
97
+ href: XLINK_NS$1
98
+ };
99
+ const isLeaf$1 = (c) => typeof c === "string" || typeof c === "number";
100
+ const isElement$1 = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT$1;
101
+ const isRenderFunction$1 = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION$1;
102
+ function h(type, props, ...children) {
103
+ props = Object.assign({}, props, {
104
+ children: children.length === 1 ? children[0] : children
105
+ });
106
+ return jsx$1(type, props);
107
+ }
108
+ function jsx$1(type, props) {
109
+ let vtype;
110
+ if (typeof type === "string")
111
+ vtype = VTYPE_ELEMENT$1;
112
+ else if (typeof type === "function")
113
+ vtype = VTYPE_FUNCTION$1;
114
+ else
115
+ throw new Error("Invalid VNode type");
116
+ return {
117
+ vtype,
118
+ type,
119
+ props
120
+ };
121
+ }
122
+ function Fragment$1(props) {
123
+ return props.children;
124
+ }
125
+ const DEFAULT_ENV$1 = {
126
+ isSvg: false
127
+ };
128
+ function insertDom$1(parent, nodes) {
129
+ if (!Array.isArray(nodes))
130
+ nodes = [nodes];
131
+ nodes = nodes.filter(Boolean);
132
+ if (nodes.length)
133
+ parent.append(...nodes);
134
+ }
135
+ function mountAttributes$1(domElement, props, env) {
136
+ for (const key in props) {
137
+ if (key === "key" || key === "children" || key === "ref")
138
+ continue;
139
+ if (key === "dangerouslySetInnerHTML") {
140
+ domElement.innerHTML = props[key].__html;
141
+ } else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
142
+ const value = props[key];
143
+ if (value != null)
144
+ domElement[key] = value;
145
+ } else if (key.startsWith("on")) {
146
+ domElement[key.toLowerCase()] = props[key];
147
+ } else {
148
+ setDOMAttribute$1(domElement, key, props[key], env.isSvg);
149
+ }
150
+ }
151
+ }
152
+ const attrMap$1 = {
153
+ className: "class",
154
+ labelFor: "for"
155
+ };
156
+ function setDOMAttribute$1(el, attr, value, isSVG) {
157
+ attr = attrMap$1[attr] || attr;
158
+ if (value === true) {
159
+ el.setAttribute(attr, "");
160
+ } else if (value === false) {
161
+ el.removeAttribute(attr);
162
+ } else {
163
+ const namespace = isSVG ? NS_ATTRS$1[attr] : void 0;
164
+ if (namespace !== void 0) {
165
+ el.setAttributeNS(namespace, attr, value);
166
+ } else {
167
+ el.setAttribute(attr, value);
168
+ }
169
+ }
170
+ }
171
+ function flatten$1(arr) {
172
+ return arr.reduce((prev, item) => prev.concat(item), []);
173
+ }
174
+ function mountChildren$1(children, env) {
175
+ return Array.isArray(children) ? flatten$1(children.map((child) => mountChildren$1(child, env))) : mount$1(children, env);
176
+ }
177
+ function mount$1(vnode, env = DEFAULT_ENV$1) {
178
+ if (vnode == null || typeof vnode === "boolean") {
179
+ return null;
180
+ }
181
+ if (vnode instanceof Node) {
182
+ return vnode;
183
+ }
184
+ if (isRenderFunction$1(vnode)) {
185
+ const {
186
+ type,
187
+ props
188
+ } = vnode;
189
+ if (type === Fragment$1) {
190
+ const node = document.createDocumentFragment();
191
+ if (props.children) {
192
+ const children = mountChildren$1(props.children, env);
193
+ insertDom$1(node, children);
194
+ }
195
+ return node;
196
+ }
197
+ const childVNode = type(props);
198
+ return mount$1(childVNode, env);
199
+ }
200
+ if (isLeaf$1(vnode)) {
201
+ return document.createTextNode(`${vnode}`);
202
+ }
203
+ if (isElement$1(vnode)) {
204
+ let node;
205
+ const {
206
+ type,
207
+ props
208
+ } = vnode;
209
+ if (!env.isSvg && type === "svg") {
210
+ env = Object.assign({}, env, {
211
+ isSvg: true
212
+ });
213
+ }
214
+ if (!env.isSvg) {
215
+ node = document.createElement(type);
216
+ } else {
217
+ node = document.createElementNS(SVG_NS$1, type);
218
+ }
219
+ mountAttributes$1(node, props, env);
220
+ if (props.children) {
221
+ let childEnv = env;
222
+ if (env.isSvg && type === "foreignObject") {
223
+ childEnv = Object.assign({}, childEnv, {
224
+ isSvg: false
225
+ });
226
+ }
227
+ const children = mountChildren$1(props.children, childEnv);
228
+ if (children != null)
229
+ insertDom$1(node, children);
230
+ }
231
+ const {
232
+ ref
233
+ } = props;
234
+ if (typeof ref === "function")
235
+ ref(node);
236
+ return node;
237
+ }
238
+ throw new Error("mount: Invalid Vnode!");
239
+ }
240
+ function mountDom$1(vnode) {
241
+ return mount$1(vnode);
242
+ }
243
+ function hm(...args) {
244
+ return mountDom$1(h(...args));
245
+ }
246
+ const memoizedPreloadJS = memoize((url) => {
247
+ document.head.append(
248
+ hm("link", {
249
+ rel: "preload",
250
+ as: "script",
251
+ href: url
252
+ })
253
+ );
254
+ });
255
+ const jsCache = {};
256
+ const cssCache = {};
257
+ async function loadJSItem(item, context) {
258
+ var _a;
259
+ const src = item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src) || "";
260
+ item.loaded || (item.loaded = jsCache[src]);
261
+ if (!item.loaded) {
262
+ const deferred = defer();
263
+ item.loaded = deferred.promise;
264
+ if (item.type === "script") {
265
+ document.head.append(
266
+ hm("script", {
267
+ ...item.data,
268
+ onLoad: () => deferred.resolve(),
269
+ onError: deferred.reject
270
+ })
271
+ );
272
+ if (!src) {
273
+ deferred.resolve();
274
+ } else {
275
+ jsCache[src] = item.loaded;
276
+ }
277
+ }
278
+ if (item.type === "iife") {
279
+ const { fn, getParams } = item.data;
280
+ fn(...(getParams == null ? void 0 : getParams(context)) || []);
281
+ deferred.resolve();
282
+ }
283
+ }
284
+ await item.loaded;
285
+ }
286
+ async function loadCSSItem(item) {
287
+ const url = item.type === "stylesheet" && item.data.href || "";
288
+ item.loaded || (item.loaded = cssCache[url]);
289
+ if (!item.loaded) {
290
+ const deferred = defer();
291
+ item.loaded = deferred.promise;
292
+ if (url)
293
+ cssCache[url] = item.loaded;
294
+ if (item.type === "style") {
295
+ document.head.append(
296
+ hm("style", {
297
+ textContent: item.data
298
+ })
299
+ );
300
+ deferred.resolve();
301
+ } else if (url) {
302
+ document.head.append(
303
+ hm("link", {
304
+ rel: "stylesheet",
305
+ ...item.data
306
+ })
307
+ );
308
+ fetch(url).then((res) => {
309
+ if (res.ok)
310
+ return res.text();
311
+ throw res;
312
+ }).then(() => deferred.resolve(), deferred.reject);
313
+ }
314
+ }
315
+ await item.loaded;
316
+ }
317
+ async function loadJS(items, context) {
318
+ items.forEach((item) => {
319
+ var _a;
320
+ if (item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src)) {
321
+ memoizedPreloadJS(item.data.src);
322
+ }
323
+ });
324
+ context = {
325
+ getMarkmap: () => window.markmap,
326
+ ...context
327
+ };
328
+ for (const item of items) {
329
+ await loadJSItem(item, context);
330
+ }
331
+ }
332
+ async function loadCSS(items) {
333
+ await Promise.all(items.map((item) => loadCSSItem(item)));
334
+ }
335
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
336
+ const VTYPE_ELEMENT = 1;
337
+ const VTYPE_FUNCTION = 2;
338
+ const SVG_NS = "http://www.w3.org/2000/svg";
339
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
340
+ const NS_ATTRS = {
341
+ show: XLINK_NS,
342
+ actuate: XLINK_NS,
343
+ href: XLINK_NS
344
+ };
345
+ const isLeaf = (c) => typeof c === "string" || typeof c === "number";
346
+ const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
347
+ const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
348
+ function jsx(type, props) {
349
+ let vtype;
350
+ if (typeof type === "string")
351
+ vtype = VTYPE_ELEMENT;
352
+ else if (typeof type === "function")
353
+ vtype = VTYPE_FUNCTION;
354
+ else
355
+ throw new Error("Invalid VNode type");
356
+ return {
357
+ vtype,
358
+ type,
359
+ props
360
+ };
361
+ }
362
+ function Fragment(props) {
363
+ return props.children;
364
+ }
365
+ const DEFAULT_ENV = {
366
+ isSvg: false
367
+ };
368
+ function insertDom(parent, nodes) {
369
+ if (!Array.isArray(nodes))
370
+ nodes = [nodes];
371
+ nodes = nodes.filter(Boolean);
372
+ if (nodes.length)
373
+ parent.append(...nodes);
374
+ }
375
+ function mountAttributes(domElement, props, env) {
376
+ for (const key in props) {
377
+ if (key === "key" || key === "children" || key === "ref")
378
+ continue;
379
+ if (key === "dangerouslySetInnerHTML") {
380
+ domElement.innerHTML = props[key].__html;
381
+ } else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
382
+ const value = props[key];
383
+ if (value != null)
384
+ domElement[key] = value;
385
+ } else if (key.startsWith("on")) {
386
+ domElement[key.toLowerCase()] = props[key];
387
+ } else {
388
+ setDOMAttribute(domElement, key, props[key], env.isSvg);
389
+ }
390
+ }
391
+ }
392
+ const attrMap = {
393
+ className: "class",
394
+ labelFor: "for"
395
+ };
396
+ function setDOMAttribute(el, attr, value, isSVG) {
397
+ attr = attrMap[attr] || attr;
398
+ if (value === true) {
399
+ el.setAttribute(attr, "");
400
+ } else if (value === false) {
401
+ el.removeAttribute(attr);
402
+ } else {
403
+ const namespace = isSVG ? NS_ATTRS[attr] : void 0;
404
+ if (namespace !== void 0) {
405
+ el.setAttributeNS(namespace, attr, value);
406
+ } else {
407
+ el.setAttribute(attr, value);
408
+ }
409
+ }
410
+ }
411
+ function flatten(arr) {
412
+ return arr.reduce((prev, item) => prev.concat(item), []);
413
+ }
414
+ function mountChildren(children, env) {
415
+ return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
416
+ }
417
+ function mount(vnode, env = DEFAULT_ENV) {
418
+ if (vnode == null || typeof vnode === "boolean") {
419
+ return null;
420
+ }
421
+ if (vnode instanceof Node) {
422
+ return vnode;
423
+ }
424
+ if (isRenderFunction(vnode)) {
425
+ const {
426
+ type,
427
+ props
428
+ } = vnode;
429
+ if (type === Fragment) {
430
+ const node = document.createDocumentFragment();
431
+ if (props.children) {
432
+ const children = mountChildren(props.children, env);
433
+ insertDom(node, children);
434
+ }
435
+ return node;
436
+ }
437
+ const childVNode = type(props);
438
+ return mount(childVNode, env);
439
+ }
440
+ if (isLeaf(vnode)) {
441
+ return document.createTextNode(`${vnode}`);
442
+ }
443
+ if (isElement(vnode)) {
444
+ let node;
445
+ const {
446
+ type,
447
+ props
448
+ } = vnode;
449
+ if (!env.isSvg && type === "svg") {
450
+ env = Object.assign({}, env, {
451
+ isSvg: true
452
+ });
453
+ }
454
+ if (!env.isSvg) {
455
+ node = document.createElement(type);
456
+ } else {
457
+ node = document.createElementNS(SVG_NS, type);
458
+ }
459
+ mountAttributes(node, props, env);
460
+ if (props.children) {
461
+ let childEnv = env;
462
+ if (env.isSvg && type === "foreignObject") {
463
+ childEnv = Object.assign({}, childEnv, {
464
+ isSvg: false
465
+ });
466
+ }
467
+ const children = mountChildren(props.children, childEnv);
468
+ if (children != null)
469
+ insertDom(node, children);
470
+ }
471
+ const {
472
+ ref
473
+ } = props;
474
+ if (typeof ref === "function")
475
+ ref(node);
476
+ return node;
477
+ }
478
+ throw new Error("mount: Invalid Vnode!");
479
+ }
480
+ function mountDom(vnode) {
481
+ return mount(vnode);
482
+ }
483
+ function count(node) {
484
+ var sum = 0, children = node.children, i = children && children.length;
485
+ if (!i)
486
+ sum = 1;
487
+ else
488
+ while (--i >= 0)
489
+ sum += children[i].value;
490
+ node.value = sum;
491
+ }
492
+ function node_count() {
493
+ return this.eachAfter(count);
494
+ }
495
+ function node_each(callback) {
496
+ var node = this, current, next = [node], children, i, n;
497
+ do {
498
+ current = next.reverse(), next = [];
499
+ while (node = current.pop()) {
500
+ callback(node), children = node.children;
501
+ if (children)
502
+ for (i = 0, n = children.length; i < n; ++i) {
503
+ next.push(children[i]);
504
+ }
505
+ }
506
+ } while (next.length);
507
+ return this;
508
+ }
509
+ function node_eachBefore(callback) {
510
+ var node = this, nodes = [node], children, i;
511
+ while (node = nodes.pop()) {
512
+ callback(node), children = node.children;
513
+ if (children)
514
+ for (i = children.length - 1; i >= 0; --i) {
515
+ nodes.push(children[i]);
516
+ }
517
+ }
518
+ return this;
519
+ }
520
+ function node_eachAfter(callback) {
521
+ var node = this, nodes = [node], next = [], children, i, n;
522
+ while (node = nodes.pop()) {
523
+ next.push(node), children = node.children;
524
+ if (children)
525
+ for (i = 0, n = children.length; i < n; ++i) {
526
+ nodes.push(children[i]);
527
+ }
528
+ }
529
+ while (node = next.pop()) {
530
+ callback(node);
531
+ }
532
+ return this;
533
+ }
534
+ function node_sum(value) {
535
+ return this.eachAfter(function(node) {
536
+ var sum = +value(node.data) || 0, children = node.children, i = children && children.length;
537
+ while (--i >= 0)
538
+ sum += children[i].value;
539
+ node.value = sum;
540
+ });
541
+ }
542
+ function node_sort(compare) {
543
+ return this.eachBefore(function(node) {
544
+ if (node.children) {
545
+ node.children.sort(compare);
546
+ }
547
+ });
548
+ }
549
+ function node_path(end) {
550
+ var start = this, ancestor = leastCommonAncestor(start, end), nodes = [start];
551
+ while (start !== ancestor) {
552
+ start = start.parent;
553
+ nodes.push(start);
554
+ }
555
+ var k = nodes.length;
556
+ while (end !== ancestor) {
557
+ nodes.splice(k, 0, end);
558
+ end = end.parent;
559
+ }
560
+ return nodes;
561
+ }
562
+ function leastCommonAncestor(a, b) {
563
+ if (a === b)
564
+ return a;
565
+ var aNodes = a.ancestors(), bNodes = b.ancestors(), c = null;
566
+ a = aNodes.pop();
567
+ b = bNodes.pop();
568
+ while (a === b) {
569
+ c = a;
570
+ a = aNodes.pop();
571
+ b = bNodes.pop();
572
+ }
573
+ return c;
574
+ }
575
+ function node_ancestors() {
576
+ var node = this, nodes = [node];
577
+ while (node = node.parent) {
578
+ nodes.push(node);
579
+ }
580
+ return nodes;
581
+ }
582
+ function node_descendants() {
583
+ var nodes = [];
584
+ this.each(function(node) {
585
+ nodes.push(node);
586
+ });
587
+ return nodes;
588
+ }
589
+ function node_leaves() {
590
+ var leaves = [];
591
+ this.eachBefore(function(node) {
592
+ if (!node.children) {
593
+ leaves.push(node);
594
+ }
595
+ });
596
+ return leaves;
597
+ }
598
+ function node_links() {
599
+ var root = this, links = [];
600
+ root.each(function(node) {
601
+ if (node !== root) {
602
+ links.push({ source: node.parent, target: node });
603
+ }
604
+ });
605
+ return links;
606
+ }
607
+ function hierarchy(data, children) {
608
+ var root = new Node$1(data), valued = +data.value && (root.value = data.value), node, nodes = [root], child, childs, i, n;
609
+ if (children == null)
610
+ children = defaultChildren;
611
+ while (node = nodes.pop()) {
612
+ if (valued)
613
+ node.value = +node.data.value;
614
+ if ((childs = children(node.data)) && (n = childs.length)) {
615
+ node.children = new Array(n);
616
+ for (i = n - 1; i >= 0; --i) {
617
+ nodes.push(child = node.children[i] = new Node$1(childs[i]));
618
+ child.parent = node;
619
+ child.depth = node.depth + 1;
620
+ }
621
+ }
622
+ }
623
+ return root.eachBefore(computeHeight);
624
+ }
625
+ function node_copy() {
626
+ return hierarchy(this).eachBefore(copyData);
627
+ }
628
+ function defaultChildren(d) {
629
+ return d.children;
630
+ }
631
+ function copyData(node) {
632
+ node.data = node.data.data;
633
+ }
634
+ function computeHeight(node) {
635
+ var height = 0;
636
+ do
637
+ node.height = height;
638
+ while ((node = node.parent) && node.height < ++height);
639
+ }
640
+ function Node$1(data) {
641
+ this.data = data;
642
+ this.depth = this.height = 0;
643
+ this.parent = null;
644
+ }
645
+ Node$1.prototype = hierarchy.prototype = {
646
+ constructor: Node$1,
647
+ count: node_count,
648
+ each: node_each,
649
+ eachAfter: node_eachAfter,
650
+ eachBefore: node_eachBefore,
651
+ sum: node_sum,
652
+ sort: node_sort,
653
+ path: node_path,
654
+ ancestors: node_ancestors,
655
+ descendants: node_descendants,
656
+ leaves: node_leaves,
657
+ links: node_links,
658
+ copy: node_copy
659
+ };
660
+ const name = "d3-flextree";
661
+ const version$1 = "2.1.2";
662
+ const main = "build/d3-flextree.js";
663
+ const module = "index";
664
+ const author = {
665
+ name: "Chris Maloney",
666
+ url: "http://chrismaloney.org"
667
+ };
668
+ const description = "Flexible tree layout algorithm that allows for variable node sizes.";
669
+ const keywords = [
670
+ "d3",
671
+ "d3-module",
672
+ "layout",
673
+ "tree",
674
+ "hierarchy",
675
+ "d3-hierarchy",
676
+ "plugin",
677
+ "d3-plugin",
678
+ "infovis",
679
+ "visualization",
680
+ "2d"
681
+ ];
682
+ const homepage = "https://github.com/klortho/d3-flextree";
683
+ const license = "WTFPL";
684
+ const repository = {
685
+ type: "git",
686
+ url: "https://github.com/klortho/d3-flextree.git"
687
+ };
688
+ const scripts = {
689
+ clean: "rm -rf build demo test",
690
+ "build:demo": "rollup -c --environment BUILD:demo",
691
+ "build:dev": "rollup -c --environment BUILD:dev",
692
+ "build:prod": "rollup -c --environment BUILD:prod",
693
+ "build:test": "rollup -c --environment BUILD:test",
694
+ build: "rollup -c",
695
+ lint: "eslint index.js src",
696
+ "test:main": "node test/bundle.js",
697
+ "test:browser": "node test/browser-tests.js",
698
+ test: "npm-run-all test:*",
699
+ prepare: "npm-run-all clean build lint test"
700
+ };
701
+ const dependencies = {
702
+ "d3-hierarchy": "^1.1.5"
703
+ };
704
+ const devDependencies = {
705
+ "babel-plugin-external-helpers": "^6.22.0",
706
+ "babel-preset-es2015-rollup": "^3.0.0",
707
+ d3: "^4.13.0",
708
+ "d3-selection-multi": "^1.0.1",
709
+ eslint: "^4.19.1",
710
+ jsdom: "^11.6.2",
711
+ "npm-run-all": "^4.1.2",
712
+ rollup: "^0.55.3",
713
+ "rollup-plugin-babel": "^2.7.1",
714
+ "rollup-plugin-commonjs": "^8.0.2",
715
+ "rollup-plugin-copy": "^0.2.3",
716
+ "rollup-plugin-json": "^2.3.0",
717
+ "rollup-plugin-node-resolve": "^3.0.2",
718
+ "rollup-plugin-uglify": "^3.0.0",
719
+ "uglify-es": "^3.3.9"
720
+ };
721
+ const packageInfo = {
722
+ name,
723
+ version: version$1,
724
+ main,
725
+ module,
726
+ "jsnext:main": "index",
727
+ author,
728
+ description,
729
+ keywords,
730
+ homepage,
731
+ license,
732
+ repository,
733
+ scripts,
734
+ dependencies,
735
+ devDependencies
736
+ };
737
+ const { version } = packageInfo;
738
+ const defaults = Object.freeze({
739
+ children: (data) => data.children,
740
+ nodeSize: (node) => node.data.size,
741
+ spacing: 0
742
+ });
743
+ function flextree(options) {
744
+ const opts = Object.assign({}, defaults, options);
745
+ function accessor(name2) {
746
+ const opt = opts[name2];
747
+ return typeof opt === "function" ? opt : () => opt;
748
+ }
749
+ function layout(tree) {
750
+ const wtree = wrap(getWrapper(), tree, (node) => node.children);
751
+ wtree.update();
752
+ return wtree.data;
753
+ }
754
+ function getFlexNode() {
755
+ const nodeSize = accessor("nodeSize");
756
+ const spacing = accessor("spacing");
757
+ return class FlexNode extends hierarchy.prototype.constructor {
758
+ constructor(data) {
759
+ super(data);
760
+ }
761
+ copy() {
762
+ const c = wrap(this.constructor, this, (node) => node.children);
763
+ c.each((node) => node.data = node.data.data);
764
+ return c;
765
+ }
766
+ get size() {
767
+ return nodeSize(this);
768
+ }
769
+ spacing(oNode) {
770
+ return spacing(this, oNode);
771
+ }
772
+ get nodes() {
773
+ return this.descendants();
774
+ }
775
+ get xSize() {
776
+ return this.size[0];
777
+ }
778
+ get ySize() {
779
+ return this.size[1];
780
+ }
781
+ get top() {
782
+ return this.y;
783
+ }
784
+ get bottom() {
785
+ return this.y + this.ySize;
786
+ }
787
+ get left() {
788
+ return this.x - this.xSize / 2;
789
+ }
790
+ get right() {
791
+ return this.x + this.xSize / 2;
792
+ }
793
+ get root() {
794
+ const ancs = this.ancestors();
795
+ return ancs[ancs.length - 1];
796
+ }
797
+ get numChildren() {
798
+ return this.hasChildren ? this.children.length : 0;
799
+ }
800
+ get hasChildren() {
801
+ return !this.noChildren;
802
+ }
803
+ get noChildren() {
804
+ return this.children === null;
805
+ }
806
+ get firstChild() {
807
+ return this.hasChildren ? this.children[0] : null;
808
+ }
809
+ get lastChild() {
810
+ return this.hasChildren ? this.children[this.numChildren - 1] : null;
811
+ }
812
+ get extents() {
813
+ return (this.children || []).reduce(
814
+ (acc, kid) => FlexNode.maxExtents(acc, kid.extents),
815
+ this.nodeExtents
816
+ );
817
+ }
818
+ get nodeExtents() {
819
+ return {
820
+ top: this.top,
821
+ bottom: this.bottom,
822
+ left: this.left,
823
+ right: this.right
824
+ };
825
+ }
826
+ static maxExtents(e0, e1) {
827
+ return {
828
+ top: Math.min(e0.top, e1.top),
829
+ bottom: Math.max(e0.bottom, e1.bottom),
830
+ left: Math.min(e0.left, e1.left),
831
+ right: Math.max(e0.right, e1.right)
832
+ };
833
+ }
834
+ };
835
+ }
836
+ function getWrapper() {
837
+ const FlexNode = getFlexNode();
838
+ const nodeSize = accessor("nodeSize");
839
+ const spacing = accessor("spacing");
840
+ return class extends FlexNode {
841
+ constructor(data) {
842
+ super(data);
843
+ Object.assign(this, {
844
+ x: 0,
845
+ y: 0,
846
+ relX: 0,
847
+ prelim: 0,
848
+ shift: 0,
849
+ change: 0,
850
+ lExt: this,
851
+ lExtRelX: 0,
852
+ lThr: null,
853
+ rExt: this,
854
+ rExtRelX: 0,
855
+ rThr: null
856
+ });
857
+ }
858
+ get size() {
859
+ return nodeSize(this.data);
860
+ }
861
+ spacing(oNode) {
862
+ return spacing(this.data, oNode.data);
863
+ }
864
+ get x() {
865
+ return this.data.x;
866
+ }
867
+ set x(v) {
868
+ this.data.x = v;
869
+ }
870
+ get y() {
871
+ return this.data.y;
872
+ }
873
+ set y(v) {
874
+ this.data.y = v;
875
+ }
876
+ update() {
877
+ layoutChildren(this);
878
+ resolveX(this);
879
+ return this;
880
+ }
881
+ };
882
+ }
883
+ function wrap(FlexClass, treeData, children) {
884
+ const _wrap = (data, parent) => {
885
+ const node = new FlexClass(data);
886
+ Object.assign(node, {
887
+ parent,
888
+ depth: parent === null ? 0 : parent.depth + 1,
889
+ height: 0,
890
+ length: 1
891
+ });
892
+ const kidsData = children(data) || [];
893
+ node.children = kidsData.length === 0 ? null : kidsData.map((kd) => _wrap(kd, node));
894
+ if (node.children) {
895
+ Object.assign(node, node.children.reduce(
896
+ (hl, kid) => ({
897
+ height: Math.max(hl.height, kid.height + 1),
898
+ length: hl.length + kid.length
899
+ }),
900
+ node
901
+ ));
902
+ }
903
+ return node;
904
+ };
905
+ return _wrap(treeData, null);
906
+ }
907
+ Object.assign(layout, {
908
+ nodeSize(arg) {
909
+ return arguments.length ? (opts.nodeSize = arg, layout) : opts.nodeSize;
910
+ },
911
+ spacing(arg) {
912
+ return arguments.length ? (opts.spacing = arg, layout) : opts.spacing;
913
+ },
914
+ children(arg) {
915
+ return arguments.length ? (opts.children = arg, layout) : opts.children;
916
+ },
917
+ hierarchy(treeData, children) {
918
+ const kids = typeof children === "undefined" ? opts.children : children;
919
+ return wrap(getFlexNode(), treeData, kids);
920
+ },
921
+ dump(tree) {
922
+ const nodeSize = accessor("nodeSize");
923
+ const _dump = (i0) => (node) => {
924
+ const i1 = i0 + " ";
925
+ const i2 = i0 + " ";
926
+ const { x, y } = node;
927
+ const size = nodeSize(node);
928
+ const kids = node.children || [];
929
+ const kdumps = kids.length === 0 ? " " : `,${i1}children: [${i2}${kids.map(_dump(i2)).join(i2)}${i1}],${i0}`;
930
+ return `{ size: [${size.join(", ")}],${i1}x: ${x}, y: ${y}${kdumps}},`;
931
+ };
932
+ return _dump("\n")(tree);
933
+ }
934
+ });
935
+ return layout;
936
+ }
937
+ flextree.version = version;
938
+ const layoutChildren = (w, y = 0) => {
939
+ w.y = y;
940
+ (w.children || []).reduce((acc, kid) => {
941
+ const [i, lastLows] = acc;
942
+ layoutChildren(kid, w.y + w.ySize);
943
+ const lowY = (i === 0 ? kid.lExt : kid.rExt).bottom;
944
+ if (i !== 0)
945
+ separate(w, i, lastLows);
946
+ const lows = updateLows(lowY, i, lastLows);
947
+ return [i + 1, lows];
948
+ }, [0, null]);
949
+ shiftChange(w);
950
+ positionRoot(w);
951
+ return w;
952
+ };
953
+ const resolveX = (w, prevSum, parentX) => {
954
+ if (typeof prevSum === "undefined") {
955
+ prevSum = -w.relX - w.prelim;
956
+ parentX = 0;
957
+ }
958
+ const sum = prevSum + w.relX;
959
+ w.relX = sum + w.prelim - parentX;
960
+ w.prelim = 0;
961
+ w.x = parentX + w.relX;
962
+ (w.children || []).forEach((k) => resolveX(k, sum, w.x));
963
+ return w;
964
+ };
965
+ const shiftChange = (w) => {
966
+ (w.children || []).reduce((acc, child) => {
967
+ const [lastShiftSum, lastChangeSum] = acc;
968
+ const shiftSum = lastShiftSum + child.shift;
969
+ const changeSum = lastChangeSum + shiftSum + child.change;
970
+ child.relX += changeSum;
971
+ return [shiftSum, changeSum];
972
+ }, [0, 0]);
973
+ };
974
+ const separate = (w, i, lows) => {
975
+ const lSib = w.children[i - 1];
976
+ const curSubtree = w.children[i];
977
+ let rContour = lSib;
978
+ let rSumMods = lSib.relX;
979
+ let lContour = curSubtree;
980
+ let lSumMods = curSubtree.relX;
981
+ let isFirst = true;
982
+ while (rContour && lContour) {
983
+ if (rContour.bottom > lows.lowY)
984
+ lows = lows.next;
985
+ const dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour);
986
+ if (dist > 0 || dist < 0 && isFirst) {
987
+ lSumMods += dist;
988
+ moveSubtree(curSubtree, dist);
989
+ distributeExtra(w, i, lows.index, dist);
990
+ }
991
+ isFirst = false;
992
+ const rightBottom = rContour.bottom;
993
+ const leftBottom = lContour.bottom;
994
+ if (rightBottom <= leftBottom) {
995
+ rContour = nextRContour(rContour);
996
+ if (rContour)
997
+ rSumMods += rContour.relX;
998
+ }
999
+ if (rightBottom >= leftBottom) {
1000
+ lContour = nextLContour(lContour);
1001
+ if (lContour)
1002
+ lSumMods += lContour.relX;
1003
+ }
1004
+ }
1005
+ if (!rContour && lContour)
1006
+ setLThr(w, i, lContour, lSumMods);
1007
+ else if (rContour && !lContour)
1008
+ setRThr(w, i, rContour, rSumMods);
1009
+ };
1010
+ const moveSubtree = (subtree, distance) => {
1011
+ subtree.relX += distance;
1012
+ subtree.lExtRelX += distance;
1013
+ subtree.rExtRelX += distance;
1014
+ };
1015
+ const distributeExtra = (w, curSubtreeI, leftSibI, dist) => {
1016
+ const curSubtree = w.children[curSubtreeI];
1017
+ const n = curSubtreeI - leftSibI;
1018
+ if (n > 1) {
1019
+ const delta = dist / n;
1020
+ w.children[leftSibI + 1].shift += delta;
1021
+ curSubtree.shift -= delta;
1022
+ curSubtree.change -= dist - delta;
1023
+ }
1024
+ };
1025
+ const nextLContour = (w) => {
1026
+ return w.hasChildren ? w.firstChild : w.lThr;
1027
+ };
1028
+ const nextRContour = (w) => {
1029
+ return w.hasChildren ? w.lastChild : w.rThr;
1030
+ };
1031
+ const setLThr = (w, i, lContour, lSumMods) => {
1032
+ const firstChild = w.firstChild;
1033
+ const lExt = firstChild.lExt;
1034
+ const curSubtree = w.children[i];
1035
+ lExt.lThr = lContour;
1036
+ const diff = lSumMods - lContour.relX - firstChild.lExtRelX;
1037
+ lExt.relX += diff;
1038
+ lExt.prelim -= diff;
1039
+ firstChild.lExt = curSubtree.lExt;
1040
+ firstChild.lExtRelX = curSubtree.lExtRelX;
1041
+ };
1042
+ const setRThr = (w, i, rContour, rSumMods) => {
1043
+ const curSubtree = w.children[i];
1044
+ const rExt = curSubtree.rExt;
1045
+ const lSib = w.children[i - 1];
1046
+ rExt.rThr = rContour;
1047
+ const diff = rSumMods - rContour.relX - curSubtree.rExtRelX;
1048
+ rExt.relX += diff;
1049
+ rExt.prelim -= diff;
1050
+ curSubtree.rExt = lSib.rExt;
1051
+ curSubtree.rExtRelX = lSib.rExtRelX;
1052
+ };
1053
+ const positionRoot = (w) => {
1054
+ if (w.hasChildren) {
1055
+ const k0 = w.firstChild;
1056
+ const kf = w.lastChild;
1057
+ const prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2;
1058
+ Object.assign(w, {
1059
+ prelim,
1060
+ lExt: k0.lExt,
1061
+ lExtRelX: k0.lExtRelX,
1062
+ rExt: kf.rExt,
1063
+ rExtRelX: kf.rExtRelX
1064
+ });
1065
+ }
1066
+ };
1067
+ const updateLows = (lowY, index, lastLows) => {
1068
+ while (lastLows !== null && lowY >= lastLows.lowY)
1069
+ lastLows = lastLows.next;
1070
+ return {
1071
+ lowY,
1072
+ index,
1073
+ next: lastLows
1074
+ };
1075
+ };
1076
+ const css = ".markmap {\n font: 300 16px/20px sans-serif;\n}\n\n .markmap-link {\n fill: none;\n }\n\n .markmap-node > circle {\n cursor: pointer;\n }\n\n .markmap-foreign {\n display: inline-block;\n }\n\n .markmap-foreign a {\n color: #0097e6;\n }\n\n .markmap-foreign a:hover {\n color: #00a8ff;\n }\n\n .markmap-foreign code {\n padding: 0.25em;\n font-size: calc(1em - 2px);\n color: #555;\n background-color: #f0f0f0;\n border-radius: 2px;\n }\n\n .markmap-foreign pre {\n margin: 0;\n }\n\n .markmap-foreign pre > code {\n display: block;\n }\n\n .markmap-foreign del {\n text-decoration: line-through;\n }\n\n .markmap-foreign em {\n font-style: italic;\n }\n\n .markmap-foreign strong {\n font-weight: bold;\n }\n\n .markmap-foreign mark {\n background: #ffeaa7;\n }\n";
1077
+ const containerCSS = "/* used for pre-rendering to get the size of each node */\n.markmap-container {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n}\n.markmap-container > .markmap-foreign {\n display: inline-block;\n }\n/* first-child for line wrapping, last-child for max-width detection */\n.markmap-container > .markmap-foreign > div:last-child,\n \n .markmap-container > .markmap-foreign > div:last-child :not(pre) {\n white-space: nowrap;\n }\n.markmap-container > .markmap-foreign > div:last-child code {\n white-space: inherit;\n }\n";
1078
+ const globalCSS = css;
1079
+ function linkWidth(nodeData) {
1080
+ const data = nodeData.data;
1081
+ return Math.max(4 - 2 * data.depth, 1.5);
1082
+ }
1083
+ function minBy(numbers, by) {
1084
+ const index = d32.minIndex(numbers, by);
1085
+ return numbers[index];
1086
+ }
1087
+ function stopPropagation(e) {
1088
+ e.stopPropagation();
1089
+ }
1090
+ function createViewHooks() {
1091
+ return {
1092
+ transformHtml: new Hook()
1093
+ };
1094
+ }
1095
+ const refreshHook = new Hook();
1096
+ const defaultColorFn = d32.scaleOrdinal(d32.schemeCategory10);
1097
+ const isMacintosh = typeof navigator !== "undefined" && navigator.userAgent.includes("Macintosh");
1098
+ const _Markmap = class _Markmap {
1099
+ constructor(svg, opts) {
1100
+ this.options = _Markmap.defaultOptions;
1101
+ this.revokers = [];
1102
+ this.handleZoom = (e) => {
1103
+ const { transform } = e;
1104
+ this.g.attr("transform", transform);
1105
+ };
1106
+ this.handlePan = (e) => {
1107
+ e.preventDefault();
1108
+ const transform = d32.zoomTransform(this.svg.node());
1109
+ const newTransform = transform.translate(
1110
+ -e.deltaX / transform.k,
1111
+ -e.deltaY / transform.k
1112
+ );
1113
+ this.svg.call(this.zoom.transform, newTransform);
1114
+ };
1115
+ this.handleClick = (e, d) => {
1116
+ let recursive = this.options.toggleRecursively;
1117
+ if (isMacintosh ? e.metaKey : e.ctrlKey)
1118
+ recursive = !recursive;
1119
+ this.toggleNode(d.data, recursive);
1120
+ };
1121
+ this.viewHooks = createViewHooks();
1122
+ this.svg = svg.datum ? svg : d32.select(svg);
1123
+ this.styleNode = this.svg.append("style");
1124
+ this.zoom = d32.zoom().filter((event) => {
1125
+ if (this.options.scrollForPan) {
1126
+ if (event.type === "wheel")
1127
+ return event.ctrlKey && !event.button;
1128
+ }
1129
+ return (!event.ctrlKey || event.type === "wheel") && !event.button;
1130
+ }).on("zoom", this.handleZoom);
1131
+ this.setOptions(opts);
1132
+ this.state = {
1133
+ id: this.options.id || this.svg.attr("id") || getId(),
1134
+ minX: 0,
1135
+ maxX: 0,
1136
+ minY: 0,
1137
+ maxY: 0
1138
+ };
1139
+ this.g = this.svg.append("g");
1140
+ this.revokers.push(
1141
+ refreshHook.tap(() => {
1142
+ this.setData();
1143
+ })
1144
+ );
1145
+ }
1146
+ getStyleContent() {
1147
+ const { style } = this.options;
1148
+ const { id } = this.state;
1149
+ const styleText = typeof style === "function" ? style(id) : "";
1150
+ return [this.options.embedGlobalCSS && css, styleText].filter(Boolean).join("\n");
1151
+ }
1152
+ updateStyle() {
1153
+ this.svg.attr(
1154
+ "class",
1155
+ addClass(this.svg.attr("class"), "markmap", this.state.id)
1156
+ );
1157
+ const style = this.getStyleContent();
1158
+ this.styleNode.text(style);
1159
+ }
1160
+ toggleNode(data, recursive = false) {
1161
+ var _a, _b;
1162
+ const fold = ((_a = data.payload) == null ? void 0 : _a.fold) ? 0 : 1;
1163
+ if (recursive) {
1164
+ walkTree(data, (item, next) => {
1165
+ item.payload = {
1166
+ ...item.payload,
1167
+ fold
1168
+ };
1169
+ next();
1170
+ });
1171
+ } else {
1172
+ data.payload = {
1173
+ ...data.payload,
1174
+ fold: ((_b = data.payload) == null ? void 0 : _b.fold) ? 0 : 1
1175
+ };
1176
+ }
1177
+ this.renderData(data);
1178
+ }
1179
+ initializeData(node) {
1180
+ let nodeId = 0;
1181
+ const { color, nodeMinHeight, maxWidth, initialExpandLevel } = this.options;
1182
+ const { id } = this.state;
1183
+ const container = mountDom(
1184
+ /* @__PURE__ */ jsx("div", { className: `markmap-container markmap ${id}-g` })
1185
+ );
1186
+ const style = mountDom(
1187
+ /* @__PURE__ */ jsx("style", { children: [this.getStyleContent(), containerCSS].join("\n") })
1188
+ );
1189
+ document.body.append(container, style);
1190
+ const groupStyle = maxWidth ? `max-width: ${maxWidth}px` : "";
1191
+ let foldRecursively = 0;
1192
+ walkTree(node, (item, next, parent) => {
1193
+ var _a, _b, _c;
1194
+ item.children = (_a = item.children) == null ? void 0 : _a.map((child) => ({ ...child }));
1195
+ nodeId += 1;
1196
+ const group = mountDom(
1197
+ /* @__PURE__ */ jsx("div", { className: "markmap-foreign", style: groupStyle, children: /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: item.content } }) })
1198
+ );
1199
+ container.append(group);
1200
+ item.state = {
1201
+ ...item.state,
1202
+ id: nodeId,
1203
+ el: group.firstChild
1204
+ };
1205
+ item.state.path = [(_b = parent == null ? void 0 : parent.state) == null ? void 0 : _b.path, item.state.id].filter(Boolean).join(".");
1206
+ color(item);
1207
+ const isFoldRecursively = ((_c = item.payload) == null ? void 0 : _c.fold) === 2;
1208
+ if (isFoldRecursively) {
1209
+ foldRecursively += 1;
1210
+ } else if (foldRecursively || initialExpandLevel >= 0 && item.depth >= initialExpandLevel) {
1211
+ item.payload = { ...item.payload, fold: 1 };
1212
+ }
1213
+ next();
1214
+ if (isFoldRecursively)
1215
+ foldRecursively -= 1;
1216
+ });
1217
+ const nodes = Array.from(container.childNodes).map(
1218
+ (group) => group.firstChild
1219
+ );
1220
+ this.viewHooks.transformHtml.call(this, nodes);
1221
+ nodes.forEach((node2) => {
1222
+ var _a;
1223
+ (_a = node2.parentNode) == null ? void 0 : _a.append(node2.cloneNode(true));
1224
+ });
1225
+ walkTree(node, (item, next, parent) => {
1226
+ var _a;
1227
+ const state = item.state;
1228
+ const rect = state.el.getBoundingClientRect();
1229
+ item.content = state.el.innerHTML;
1230
+ state.size = [
1231
+ Math.ceil(rect.width) + 1,
1232
+ Math.max(Math.ceil(rect.height), nodeMinHeight)
1233
+ ];
1234
+ state.key = [(_a = parent == null ? void 0 : parent.state) == null ? void 0 : _a.id, state.id].filter(Boolean).join(".") + // FIXME: find a way to check content hash
1235
+ item.content;
1236
+ next();
1237
+ });
1238
+ container.remove();
1239
+ style.remove();
1240
+ }
1241
+ setOptions(opts) {
1242
+ this.options = {
1243
+ ...this.options,
1244
+ ...opts
1245
+ };
1246
+ if (this.options.zoom) {
1247
+ this.svg.call(this.zoom);
1248
+ } else {
1249
+ this.svg.on(".zoom", null);
1250
+ }
1251
+ if (this.options.pan) {
1252
+ this.svg.on("wheel", this.handlePan);
1253
+ } else {
1254
+ this.svg.on("wheel", null);
1255
+ }
1256
+ }
1257
+ setData(data, opts) {
1258
+ if (opts)
1259
+ this.setOptions(opts);
1260
+ if (data)
1261
+ this.state.data = data;
1262
+ if (!this.state.data)
1263
+ return;
1264
+ this.initializeData(this.state.data);
1265
+ this.updateStyle();
1266
+ this.renderData();
1267
+ }
1268
+ renderData(originData) {
1269
+ if (!this.state.data)
1270
+ return;
1271
+ const { spacingHorizontal, paddingX, spacingVertical, autoFit, color } = this.options;
1272
+ const layout = flextree({}).children((d) => {
1273
+ var _a;
1274
+ if (!((_a = d.payload) == null ? void 0 : _a.fold))
1275
+ return d.children;
1276
+ }).nodeSize((node2) => {
1277
+ const [width, height] = node2.data.state.size;
1278
+ return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
1279
+ }).spacing((a, b) => {
1280
+ return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
1281
+ });
1282
+ const tree = layout.hierarchy(this.state.data);
1283
+ layout(tree);
1284
+ const descendants = tree.descendants().reverse();
1285
+ const links = tree.links();
1286
+ const linkShape = d32.linkHorizontal();
1287
+ const minX = d32.min(descendants, (d) => d.x - d.xSize / 2);
1288
+ const maxX = d32.max(descendants, (d) => d.x + d.xSize / 2);
1289
+ const minY = d32.min(descendants, (d) => d.y);
1290
+ const maxY = d32.max(descendants, (d) => d.y + d.ySize - spacingHorizontal);
1291
+ Object.assign(this.state, {
1292
+ minX,
1293
+ maxX,
1294
+ minY,
1295
+ maxY
1296
+ });
1297
+ if (autoFit)
1298
+ this.fit();
1299
+ const origin = originData && descendants.find((item) => item.data === originData) || tree;
1300
+ const x0 = origin.data.state.x0 ?? origin.x;
1301
+ const y0 = origin.data.state.y0 ?? origin.y;
1302
+ const node = this.g.selectAll(
1303
+ childSelector("g")
1304
+ ).data(descendants, (d) => d.data.state.key);
1305
+ const nodeEnter = node.enter().append("g").attr("data-depth", (d) => d.data.depth).attr("data-path", (d) => d.data.state.path).attr(
1306
+ "transform",
1307
+ (d) => `translate(${y0 + origin.ySize - d.ySize},${x0 + origin.xSize / 2 - d.xSize})`
1308
+ );
1309
+ const nodeExit = this.transition(node.exit());
1310
+ nodeExit.select("line").attr("x1", (d) => d.ySize - spacingHorizontal).attr("x2", (d) => d.ySize - spacingHorizontal);
1311
+ nodeExit.select("foreignObject").style("opacity", 0);
1312
+ nodeExit.attr(
1313
+ "transform",
1314
+ (d) => `translate(${origin.y + origin.ySize - d.ySize},${origin.x + origin.xSize / 2 - d.xSize})`
1315
+ ).remove();
1316
+ const nodeMerge = node.merge(nodeEnter).attr(
1317
+ "class",
1318
+ (d) => {
1319
+ var _a;
1320
+ return ["markmap-node", ((_a = d.data.payload) == null ? void 0 : _a.fold) && "markmap-fold"].filter(Boolean).join(" ");
1321
+ }
1322
+ );
1323
+ this.transition(nodeMerge).attr(
1324
+ "transform",
1325
+ (d) => `translate(${d.y},${d.x - d.xSize / 2})`
1326
+ );
1327
+ const line = nodeMerge.selectAll(
1328
+ childSelector("line")
1329
+ ).data(
1330
+ (d) => [d],
1331
+ (d) => d.data.state.key
1332
+ ).join(
1333
+ (enter) => {
1334
+ return enter.append("line").attr("x1", (d) => d.ySize - spacingHorizontal).attr("x2", (d) => d.ySize - spacingHorizontal);
1335
+ },
1336
+ (update) => update,
1337
+ (exit) => exit.remove()
1338
+ );
1339
+ this.transition(line).attr("x1", -1).attr("x2", (d) => d.ySize - spacingHorizontal + 2).attr("y1", (d) => d.xSize).attr("y2", (d) => d.xSize).attr("stroke", (d) => color(d.data)).attr("stroke-width", linkWidth);
1340
+ const circle = nodeMerge.selectAll(
1341
+ childSelector("circle")
1342
+ ).data(
1343
+ (d) => {
1344
+ var _a;
1345
+ return ((_a = d.data.children) == null ? void 0 : _a.length) ? [d] : [];
1346
+ },
1347
+ (d) => d.data.state.key
1348
+ ).join(
1349
+ (enter) => {
1350
+ return enter.append("circle").attr("stroke-width", "1.5").attr("cx", (d) => d.ySize - spacingHorizontal).attr("cy", (d) => d.xSize).attr("r", 0).on("click", (e, d) => this.handleClick(e, d)).on("mousedown", stopPropagation);
1351
+ },
1352
+ (update) => update,
1353
+ (exit) => exit.remove()
1354
+ );
1355
+ this.transition(circle).attr("r", 6).attr("cx", (d) => d.ySize - spacingHorizontal).attr("cy", (d) => d.xSize).attr("stroke", (d) => color(d.data)).attr(
1356
+ "fill",
1357
+ (d) => {
1358
+ var _a;
1359
+ return ((_a = d.data.payload) == null ? void 0 : _a.fold) && d.data.children ? color(d.data) : "#fff";
1360
+ }
1361
+ );
1362
+ const foreignObject = nodeMerge.selectAll(
1363
+ childSelector("foreignObject")
1364
+ ).data(
1365
+ (d) => [d],
1366
+ (d) => d.data.state.key
1367
+ ).join(
1368
+ (enter) => {
1369
+ const fo = enter.append("foreignObject").attr("class", "markmap-foreign").attr("x", paddingX).attr("y", 0).style("opacity", 0).on("mousedown", stopPropagation).on("dblclick", stopPropagation);
1370
+ fo.append("xhtml:div").select(function select2(d) {
1371
+ const clone = d.data.state.el.cloneNode(true);
1372
+ this.replaceWith(clone);
1373
+ return clone;
1374
+ }).attr("xmlns", "http://www.w3.org/1999/xhtml");
1375
+ return fo;
1376
+ },
1377
+ (update) => update,
1378
+ (exit) => exit.remove()
1379
+ ).attr(
1380
+ "width",
1381
+ (d) => Math.max(0, d.ySize - spacingHorizontal - paddingX * 2)
1382
+ ).attr("height", (d) => d.xSize);
1383
+ this.transition(foreignObject).style("opacity", 1);
1384
+ const path = this.g.selectAll(
1385
+ childSelector("path")
1386
+ ).data(links, (d) => d.target.data.state.key).join(
1387
+ (enter) => {
1388
+ const source = [
1389
+ y0 + origin.ySize - spacingHorizontal,
1390
+ x0 + origin.xSize / 2
1391
+ ];
1392
+ return enter.insert("path", "g").attr("class", "markmap-link").attr("data-depth", (d) => d.target.data.depth).attr("data-path", (d) => d.target.data.state.path).attr("d", linkShape({ source, target: source }));
1393
+ },
1394
+ (update) => update,
1395
+ (exit) => {
1396
+ const source = [
1397
+ origin.y + origin.ySize - spacingHorizontal,
1398
+ origin.x + origin.xSize / 2
1399
+ ];
1400
+ return this.transition(exit).attr("d", linkShape({ source, target: source })).remove();
1401
+ }
1402
+ );
1403
+ this.transition(path).attr("stroke", (d) => color(d.target.data)).attr("stroke-width", (d) => linkWidth(d.target)).attr("d", (d) => {
1404
+ const origSource = d.source;
1405
+ const origTarget = d.target;
1406
+ const source = [
1407
+ origSource.y + origSource.ySize - spacingHorizontal,
1408
+ origSource.x + origSource.xSize / 2
1409
+ ];
1410
+ const target = [
1411
+ origTarget.y,
1412
+ origTarget.x + origTarget.xSize / 2
1413
+ ];
1414
+ return linkShape({ source, target });
1415
+ });
1416
+ descendants.forEach((d) => {
1417
+ d.data.state.x0 = d.x;
1418
+ d.data.state.y0 = d.y;
1419
+ });
1420
+ }
1421
+ transition(sel) {
1422
+ const { duration } = this.options;
1423
+ return sel.transition().duration(duration);
1424
+ }
1425
+ /**
1426
+ * Fit the content to the viewport.
1427
+ */
1428
+ async fit() {
1429
+ const svgNode = this.svg.node();
1430
+ const { width: offsetWidth, height: offsetHeight } = svgNode.getBoundingClientRect();
1431
+ const { fitRatio } = this.options;
1432
+ const { minX, maxX, minY, maxY } = this.state;
1433
+ const naturalWidth = maxY - minY;
1434
+ const naturalHeight = maxX - minX;
1435
+ const scale = Math.min(
1436
+ offsetWidth / naturalWidth * fitRatio,
1437
+ offsetHeight / naturalHeight * fitRatio,
1438
+ 2
1439
+ );
1440
+ const initialZoom = d32.zoomIdentity.translate(
1441
+ (offsetWidth - naturalWidth * scale) / 2 - minY * scale,
1442
+ (offsetHeight - naturalHeight * scale) / 2 - minX * scale
1443
+ ).scale(scale);
1444
+ return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop);
1445
+ }
1446
+ /**
1447
+ * Pan the content to make the provided node visible in the viewport.
1448
+ */
1449
+ async ensureView(node, padding) {
1450
+ let itemData;
1451
+ this.g.selectAll(
1452
+ childSelector("g")
1453
+ ).each(function walk(d) {
1454
+ if (d.data === node) {
1455
+ itemData = d;
1456
+ }
1457
+ });
1458
+ if (!itemData)
1459
+ return;
1460
+ const svgNode = this.svg.node();
1461
+ const { spacingHorizontal } = this.options;
1462
+ const relRect = svgNode.getBoundingClientRect();
1463
+ const transform = d32.zoomTransform(svgNode);
1464
+ const [left, right] = [
1465
+ itemData.y,
1466
+ itemData.y + itemData.ySize - spacingHorizontal + 2
1467
+ ].map((x) => x * transform.k + transform.x);
1468
+ const [top, bottom] = [
1469
+ itemData.x - itemData.xSize / 2,
1470
+ itemData.x + itemData.xSize / 2
1471
+ ].map((y) => y * transform.k + transform.y);
1472
+ const pd = {
1473
+ left: 0,
1474
+ right: 0,
1475
+ top: 0,
1476
+ bottom: 0,
1477
+ ...padding
1478
+ };
1479
+ const dxs = [pd.left - left, relRect.width - pd.right - right];
1480
+ const dys = [pd.top - top, relRect.height - pd.bottom - bottom];
1481
+ const dx = dxs[0] * dxs[1] > 0 ? minBy(dxs, Math.abs) / transform.k : 0;
1482
+ const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0;
1483
+ if (dx || dy) {
1484
+ const newTransform = transform.translate(dx, dy);
1485
+ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
1486
+ }
1487
+ }
1488
+ /**
1489
+ * Scale content with it pinned at the center of the viewport.
1490
+ */
1491
+ async rescale(scale) {
1492
+ const svgNode = this.svg.node();
1493
+ const { width: offsetWidth, height: offsetHeight } = svgNode.getBoundingClientRect();
1494
+ const halfWidth = offsetWidth / 2;
1495
+ const halfHeight = offsetHeight / 2;
1496
+ const transform = d32.zoomTransform(svgNode);
1497
+ const newTransform = transform.translate(
1498
+ (halfWidth - transform.x) * (1 - scale) / transform.k,
1499
+ (halfHeight - transform.y) * (1 - scale) / transform.k
1500
+ ).scale(scale);
1501
+ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
1502
+ }
1503
+ destroy() {
1504
+ this.svg.on(".zoom", null);
1505
+ this.svg.html(null);
1506
+ this.revokers.forEach((fn) => {
1507
+ fn();
1508
+ });
1509
+ }
1510
+ static create(svg, opts, data = null) {
1511
+ const mm = new _Markmap(svg, opts);
1512
+ if (data) {
1513
+ mm.setData(data);
1514
+ mm.fit();
1515
+ }
1516
+ return mm;
1517
+ }
1518
+ };
1519
+ _Markmap.defaultOptions = {
1520
+ autoFit: false,
1521
+ color: (node) => {
1522
+ var _a;
1523
+ return defaultColorFn(`${((_a = node.state) == null ? void 0 : _a.path) || ""}`);
1524
+ },
1525
+ duration: 500,
1526
+ embedGlobalCSS: true,
1527
+ fitRatio: 0.95,
1528
+ maxWidth: 0,
1529
+ nodeMinHeight: 16,
1530
+ paddingX: 8,
1531
+ scrollForPan: isMacintosh,
1532
+ spacingHorizontal: 80,
1533
+ spacingVertical: 5,
1534
+ initialExpandLevel: -1,
1535
+ zoom: true,
1536
+ pan: true,
1537
+ toggleRecursively: false
1538
+ };
1539
+ let Markmap = _Markmap;
1540
+ function deriveOptions(jsonOptions) {
1541
+ const derivedOptions = {};
1542
+ const options = { ...jsonOptions };
1543
+ const { color, colorFreezeLevel } = options;
1544
+ if ((color == null ? void 0 : color.length) === 1) {
1545
+ const solidColor = color[0];
1546
+ derivedOptions.color = () => solidColor;
1547
+ } else if (color == null ? void 0 : color.length) {
1548
+ const colorFn = d32.scaleOrdinal(color);
1549
+ derivedOptions.color = (node) => colorFn(`${node.state.path}`);
1550
+ }
1551
+ if (colorFreezeLevel) {
1552
+ const color2 = derivedOptions.color || Markmap.defaultOptions.color;
1553
+ derivedOptions.color = (node) => {
1554
+ node = {
1555
+ ...node,
1556
+ state: {
1557
+ ...node.state,
1558
+ path: node.state.path.split(".").slice(0, colorFreezeLevel).join(".")
1559
+ }
1560
+ };
1561
+ return color2(node);
1562
+ };
1563
+ }
1564
+ const numberKeys = ["duration", "maxWidth", "initialExpandLevel"];
1565
+ numberKeys.forEach((key) => {
1566
+ const value = options[key];
1567
+ if (typeof value === "number")
1568
+ derivedOptions[key] = value;
1569
+ });
1570
+ const booleanKeys = ["zoom", "pan"];
1571
+ booleanKeys.forEach((key) => {
1572
+ const value = options[key];
1573
+ if (value != null)
1574
+ derivedOptions[key] = !!value;
1575
+ });
1576
+ return derivedOptions;
1577
+ }
1578
+ exports.Markmap = Markmap;
1579
+ exports.defaultColorFn = defaultColorFn;
1580
+ exports.deriveOptions = deriveOptions;
1581
+ exports.globalCSS = globalCSS;
1582
+ exports.loadCSS = loadCSS;
1583
+ exports.loadJS = loadJS;
1584
+ exports.refreshHook = refreshHook;
1585
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1586
+ })(this.markmap = this.markmap || {}, d3);