markmap-view 0.15.6 → 0.15.9-alpha.0

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