-
Notifications
You must be signed in to change notification settings - Fork 9
/
markmap-lib.view.min.js
2 lines (2 loc) · 16.3 KB
/
markmap-lib.view.min.js
1
2
/*! markmap-lib v0.7.11 | MIT License */
!function(t,e){"use strict";function n(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function r(t,e){var n,r,s,l,c,h=new o(t),d=+t.value&&(h.value=t.value),u=[h];for(null==e&&(e=i);n=u.pop();)if(d&&(n.value=+n.data.value),(s=e(n.data))&&(c=s.length))for(n.children=new Array(c),l=c-1;l>=0;--l)u.push(r=n.children[l]=new o(s[l])),r.parent=n,r.depth=n.depth+1;return h.eachBefore(a)}function i(t){return t.children}function s(t){t.data=t.data.data}function a(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function o(t){this.data=t,this.depth=this.height=0,this.parent=null}o.prototype=r.prototype={constructor:o,count:function(){return this.eachAfter(n)},each:function(t){var e,n,r,i,s=this,a=[s];do{for(e=a.reverse(),a=[];s=e.pop();)if(t(s),n=s.children)for(r=0,i=n.length;r<i;++r)a.push(n[r])}while(a.length);return this},eachAfter:function(t){for(var e,n,r,i=this,s=[i],a=[];i=s.pop();)if(a.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)s.push(e[n]);for(;i=a.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return r(this).eachBefore(s)}};const l=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function c(t){const e=Object.assign({},l,t);function n(t){const n=e[t];return"function"==typeof n?n:()=>n}function i(t){const e=a(function(){const t=s(),e=n("nodeSize"),r=n("spacing");return class extends t{constructor(t){super(t),Object.assign(this,{x:0,y:0,relX:0,prelim:0,shift:0,change:0,lExt:this,lExtRelX:0,lThr:null,rExt:this,rExtRelX:0,rThr:null})}get size(){return e(this.data)}spacing(t){return r(this.data,t.data)}get x(){return this.data.x}set x(t){this.data.x=t}get y(){return this.data.y}set y(t){this.data.y=t}update(){return h(this),d(this),this}}}(),t,t=>t.children);return e.update(),e.data}function s(){const t=n("nodeSize"),e=n("spacing");return class n extends r.prototype.constructor{constructor(t){super(t)}copy(){const t=a(this.constructor,this,t=>t.children);return t.each(t=>t.data=t.data.data),t}get size(){return t(this)}spacing(t){return e(this,t)}get nodes(){return this.descendants()}get xSize(){return this.size[0]}get ySize(){return this.size[1]}get top(){return this.y}get bottom(){return this.y+this.ySize}get left(){return this.x-this.xSize/2}get right(){return this.x+this.xSize/2}get root(){const t=this.ancestors();return t[t.length-1]}get numChildren(){return this.hasChildren?this.children.length:0}get hasChildren(){return!this.noChildren}get noChildren(){return null===this.children}get firstChild(){return this.hasChildren?this.children[0]:null}get lastChild(){return this.hasChildren?this.children[this.numChildren-1]:null}get extents(){return(this.children||[]).reduce((t,e)=>n.maxExtents(t,e.extents),this.nodeExtents)}get nodeExtents(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}static maxExtents(t,e){return{top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom),left:Math.min(t.left,e.left),right:Math.max(t.right,e.right)}}}}function a(t,e,n){const r=(e,i)=>{const s=new t(e);Object.assign(s,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});const a=n(e)||[];return s.children=0===a.length?null:a.map(t=>r(t,s)),s.children&&Object.assign(s,s.children.reduce((t,e)=>({height:Math.max(t.height,e.height+1),length:t.length+e.length}),s)),s};return r(e,null)}return Object.assign(i,{nodeSize(t){return arguments.length?(e.nodeSize=t,i):e.nodeSize},spacing(t){return arguments.length?(e.spacing=t,i):e.spacing},children(t){return arguments.length?(e.children=t,i):e.children},hierarchy(t,n){const r=void 0===n?e.children:n;return a(s(),t,r)},dump(t){const e=n("nodeSize"),r=t=>n=>{const i=t+" ",s=t+" ",{x:a,y:o}=n,l=e(n),c=n.children||[],h=0===c.length?" ":`,${i}children: [${s}${c.map(r(s)).join(s)}${i}],${t}`;return`{ size: [${l.join(", ")}],${i}x: ${a}, y: ${o}${h}},`};return r("\n")(t)}}),i}c.version="2.1.1";const h=(t,e=0)=>(t.y=e,(t.children||[]).reduce((e,n)=>{const[r,i]=e;h(n,t.y+t.ySize);const s=(0===r?n.lExt:n.rExt).bottom;return 0!==r&&p(t,r,i),[r+1,S(s,r,i)]},[0,null]),u(t),z(t),t),d=(t,e,n)=>{void 0===e&&(e=-t.relX-t.prelim,n=0);const r=e+t.relX;return t.relX=r+t.prelim-n,t.prelim=0,t.x=n+t.relX,(t.children||[]).forEach(e=>d(e,r,t.x)),t},u=t=>{(t.children||[]).reduce((t,e)=>{const[n,r]=t,i=n+e.shift,s=r+i+e.change;return e.relX+=s,[i,s]},[0,0])},p=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let s=r,a=r.relX,o=i,l=i.relX,c=!0;for(;s&&o;){s.bottom>n.lowY&&(n=n.next);const r=a+s.prelim-(l+o.prelim)+s.xSize/2+o.xSize/2+s.spacing(o);(r>0||r<0&&c)&&(l+=r,f(i,r),g(t,e,n.index,r)),c=!1;const h=s.bottom,d=o.bottom;h<=d&&(s=x(s),s&&(a+=s.relX)),h>=d&&(o=m(o),o&&(l+=o.relX))}!s&&o?y(t,e,o,l):s&&!o&&v(t,e,s,a)},f=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},g=(t,e,n,r)=>{const i=t.children[e],s=e-n;if(s>1){const e=r/s;t.children[n+1].shift+=e,i.shift-=e,i.change-=r-e}},m=t=>t.hasChildren?t.firstChild:t.lThr,x=t=>t.hasChildren?t.lastChild:t.rThr,y=(t,e,n,r)=>{const i=t.firstChild,s=i.lExt,a=t.children[e];s.lThr=n;const o=r-n.relX-i.lExtRelX;s.relX+=o,s.prelim-=o,i.lExt=a.lExt,i.lExtRelX=a.lExtRelX},v=(t,e,n,r)=>{const i=t.children[e],s=i.rExt,a=t.children[e-1];s.rThr=n;const o=r-n.relX-i.rExtRelX;s.relX+=o,s.prelim-=o,i.rExt=a.rExt,i.rExtRelX=a.rExtRelX},z=t=>{if(t.hasChildren){const e=t.firstChild,n=t.lastChild,r=(e.prelim+e.relX-e.xSize/2+n.relX+n.prelim+n.xSize/2)/2;Object.assign(t,{prelim:r,lExt:e.lExt,lExtRelX:e.lExtRelX,rExt:n.rExt,rExtRelX:n.rExtRelX})}},S=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}},j=Math.random().toString(36).slice(2,8);let b=0;function w(){}function E(t,e,n="c"){const r=(t,i)=>e(t,()=>{var e;null==(e=t[n])||e.forEach(e=>{r(e,t)})},i);r(t)}function $(t){if(Array.from)return Array.from(t);const e=[];for(let n=0;n<t.length;n+=1)e.push(t[n]);return e}function X(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach(t=>{t&&n.indexOf(t)<0&&n.push(t)}),n.join(" ")}function O(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=$(this.childNodes);return e&&(t=t.filter(t=>e(t))),t}}function k(t,e,n){const r=document.createElement(t);return e&&Object.entries(e).forEach(([t,e])=>{r[t]=e}),n&&Object.entries(n).forEach(([t,e])=>{r.setAttribute(t,e)}),r}const C=function(t){const e={};return function(...n){const r=""+n[0];let i=e[r];return i||(i={value:t(...n)},e[r]=i),i.value}}(t=>{document.head.append(k("link",{rel:"preload",as:"script",href:t}))});function M(t,e){if("script"===t.type)return new Promise((e,n)=>{document.head.append(k("script",Object.assign(Object.assign({},t.data),{},{onload:e,onerror:n})))});if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function R(t){"style"===t.type?document.head.append(k("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(k("link",Object.assign({rel:"stylesheet"},t.data)))}async function A(t,e,n){n=Object.assign({},n),await Promise.all(e.map(t=>(function(t){for(const e of t)R(e)}(t.styles),async function(t,e){const n=t.filter(t=>"script"===t.type);n.length>1&&n.forEach(t=>C(t.data.src));for(const n of t)await M(n,e)}(t.scripts,n))));for(const{initialize:r}of e)r&&r(t,n)}const I={styles:[],scripts:[{type:"iife",data:{fn:t=>{t.options=Object.assign({skipHtmlTags:{"[-]":["code","pre"]}},t.options),t.startup=Object.assign({typeset:!1},t.startup),window.MathJax=t},getParams:t=>[Object.assign({},t.mathJax)]}},{type:"script",data:{src:"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"}}],initialize:function(t,e){t.transformHtml.tap((t,e)=>{var n,r;null==(n=(r=window.MathJax).typeset)||n.call(r,e)})}},H={};const B={styles:[{type:"stylesheet",data:{href:"https://cdn.jsdelivr.net/npm/prismjs@1/themes/prism.css"}}],scripts:[{type:"iife",data:{fn:()=>{window.Prism={manual:!0}}}},{type:"script",data:{src:"https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-core.min.js"}},{type:"script",data:{src:"https://cdn.jsdelivr.net/npm/prismjs@1/plugins/autoloader/prism-autoloader.min.js"}}],initialize:function(t,e){t.transformHtml.tap((t,e)=>{const{Prism:n}=window;!async function(t,e){if(!e.length)return;const{Prism:n}=window;try{await new Promise((t,r)=>{n.plugins.autoloader.loadLanguages(e,t,r)})}catch(t){H[t]=!0}t.setData(),t.fit()}(t,function(t,e){if(t.flatMap)return t.flatMap(e);const n=[];for(let r=0;r<t.length;r+=1){const i=e(t[r],r,t);Array.isArray(i)?n.push(...i):n.push(i)}return n}(e,t=>$(t.querySelectorAll("code[class*=language-]"))).map(t=>{const e=t.className.match(/(?:^|\s)language-(\S+)|$/)[1];if(n.languages[e])n.highlightElement(t);else if(!H[e])return e}).filter(Boolean))})}};var N=Object.freeze({__proto__:null,mathJax:I,prism:B});function T(t){const e=t.data;return Math.max(6-2*e.d,1.5)}class P{constructor(t,n){var r;this.options=void 0,this.state=void 0,this.svg=void 0,this.styleNode=void 0,this.g=void 0,this.zoom=void 0,["handleZoom","handleClick"].forEach(t=>{this[t]=this[t].bind(this)}),this.svg=t.datum?t:e.select(t),this.styleNode=this.svg.append("style"),this.zoom=e.zoom().on("zoom",this.handleZoom),this.options=Object.assign({duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(r=e.scaleOrdinal(e.schemeCategory10),t=>r(t.p.i)),paddingX:8},n),this.state={id:this.options.id||(b+=1,`mm-${j}-${b}`)},this.g=this.svg.append("g").attr("class",this.state.id+"-g"),this.updateStyle(),this.svg.call(this.zoom)}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-fo > div { font: ${e}; white-space: nowrap; }\n.${n}-fo code { padding: .2em .4em; font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }\n.${n}-fo del { text-decoration: line-through; }\n.${n}-fo em { font-style: italic; }\n.${n}-fo strong { font-weight: 600; }\n.${n}-fo pre { margin: 0; }\n.${n}-fo pre[class*=language-] { padding: 0; }\n.${n}-g > g { cursor: pointer; }\n${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",X(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(){const{transform:t}=e.event;this.g.attr("transform",t)}handleClick(t){var e;const{data:n}=t;n.p=Object.assign(Object.assign({},n.p),{},{f:!(null==(e=n.p)?void 0:e.f)}),this.renderData(t.data)}initializeData(t){let e=0;const{nodeFont:n,color:r,nodeMinHeight:i}=this.options,{id:s}=this.state,a=document.createElement("div"),o=s+"-container";a.className=X(a.className,s+"-fo",o);const l=document.createElement("style");l.textContent=`\n${this.getStyleContent()}\n.${o} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${n};\n}\n.${o} > div {\n display: inline-block;\n}\n`,document.body.append(l,a),E(t,(t,n)=>{var i;t.c=null==(i=t.c)?void 0:i.map(t=>Object.assign({},t)),e+=1;const s=document.createElement("div");s.innerHTML=t.v,a.append(s),t.p=Object.assign(Object.assign({},t.p),{},{i:e,el:s}),r(t),n()});const c=$(a.childNodes);this.constructor.transformHtml.call(this,c),E(t,(t,e,n)=>{var r;const s=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(s.width),Math.max(Math.ceil(s.height),i)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()}),a.remove(),l.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t||(t=Object.assign({},this.state.data)),this.state.data=t,this.initializeData(t),e&&this.setOptions(e),this.renderData()}renderData(t){var n,r;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:s,spacingVertical:a,autoFit:o,color:l}=this.options,{id:h}=this.state,d=c().children(t=>{var e;return!(null==(e=t.p)?void 0:e.f)&&t.c}).nodeSize(t=>{const[e,n]=t.data.p.s;return[n,e+(e?2*s:0)+i]}).spacing((t,e)=>t.parent===e.parent?a:2*a),u=d.hierarchy(this.state.data);d(u),function(t,e){E(t,(t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()},"children")}(u,i);const p=u.descendants().reverse(),f=u.links(),g=e.linkHorizontal(),m=e.min(p,t=>t.x-t.xSize/2),x=e.max(p,t=>t.x+t.xSize/2),y=e.min(p,t=>t.y),v=e.max(p,t=>t.y+t.ySizeInner);Object.assign(this.state,{minX:m,maxX:x,minY:y,maxY:v}),o&&this.fit();const z=t&&p.find(e=>e.data===t)||u,S=null!=(n=z.data.p.x0)?n:z.x,j=null!=(r=z.data.p.y0)?r:z.y,b=this.g.selectAll(O("g")).data(p,t=>t.data.p.k),w=b.enter().append("g").attr("transform",t=>`translate(${j+z.ySizeInner-t.ySizeInner},${S+z.xSize/2-t.xSize})`).on("click",this.handleClick),$=this.transition(b.exit());$.select("rect").attr("width",0).attr("x",t=>t.ySizeInner),$.select("foreignObject").style("opacity",0),$.attr("transform",t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`).remove();const X=b.merge(w);this.transition(X).attr("transform",t=>`translate(${t.y},${t.x-t.xSize/2})`);const k=X.selectAll(O("rect")).data(t=>[t],t=>t.data.p.k).join(t=>t.append("rect").attr("x",t=>t.ySizeInner).attr("y",t=>t.xSize-T(t)/2).attr("width",0).attr("height",T),t=>t,t=>t.remove());this.transition(k).attr("x",-1).attr("width",t=>t.ySizeInner+2).attr("fill",t=>l(t.data));const C=X.selectAll(O("circle")).data(t=>t.data.c?[t]:[],t=>t.data.p.k).join(t=>t.append("circle").attr("stroke-width","1.5").attr("cx",t=>t.ySizeInner).attr("cy",t=>t.xSize).attr("r",0),t=>t,t=>t.remove());this.transition(C).attr("r",6).attr("stroke",t=>l(t.data)).attr("fill",t=>{var e;return(null==(e=t.data.p)?void 0:e.f)?l(t.data):"#fff"});const M=X.selectAll(O("foreignObject")).data(t=>[t],t=>t.data.p.k).join(t=>{const e=t.append("foreignObject").attr("class",h+"-fo").attr("x",s).attr("y",0).style("opacity",0).attr("height",t=>t.xSize);return e.append("xhtml:div").select((function(t){const e=t.data.p.el.cloneNode(!0);return this.replaceWith(e),e})).attr("xmlns","http://www.w3.org/1999/xhtml"),e},t=>t,t=>t.remove()).attr("width",t=>Math.max(0,t.ySizeInner-2*s));this.transition(M).style("opacity",1);const R=this.g.selectAll(O("path")).data(f,t=>t.target.data.p.k).join(t=>{const e=[j+z.ySizeInner,S+z.xSize/2];return t.insert("path","g").attr("d",g({source:e,target:e}))},t=>t,t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",g({source:e,target:e})).remove()});this.transition(R).attr("stroke",t=>l(t.target.data)).attr("stroke-width",t=>T(t.target)).attr("d",t=>{const e=[t.source.y+t.source.ySizeInner,t.source.x+t.source.xSize/2],n=[t.target.y,t.target.x+t.target.xSize/2];return g({source:e,target:n})}),p.forEach(t=>{t.data.p.x0=t.x,t.data.p.y0=t.y})}transition(t){const{duration:e}=this.options;return t.transition().duration(e)}fit(){const t=this.svg.node(),{width:n,height:r}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:s,maxX:a,minY:o,maxY:l}=this.state,c=l-o,h=a-s,d=Math.min(n/c*i,r/h*i,2),u=e.zoomIdentity.translate((n-c*d)/2-o*d,(r-h*d)/2-s*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(w)}rescale(t){const n=this.svg.node(),{width:r,height:i}=n.getBoundingClientRect(),s=r/2,a=i/2,o=e.zoomTransform(n),l=o.translate((s-o.x)*(1-t)/o.k,(a-o.y)*(1-t)/o.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,l).end().catch(w)}static create(t,e,n){const r=new P(t,e);return n&&(r.setData(n),r.fit()),r}}P.transformHtml=new class{constructor(){this.listeners=[]}tap(t){this.listeners.push(t)}call(...t){for(const e of this.listeners)e(...t)}},t.Markmap=P,t.loadPlugins=async function(t,e){return t=t.map(t=>{if("string"==typeof t){const e=t;(t=N[e])||console.warn("[markmap] Unknown plugin: "+e)}return t}).filter(Boolean),A(P,t,e)},t.markmap=function(t,e,n){return P.create(t,n,e)},t.plugins=N}(this.markmap=this.markmap||{},d3);