personal_maps/lib/markmap-view@0.2.0.js

5 lines
15 KiB
JavaScript
Raw Permalink Normal View History

2020-12-18 00:19:05 -05:00
/*! markmap-view v0.2.0 | MIT License */
!function(t,e){"use strict";function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function r(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 i(t,e){var n,r,i,o,l,c=new h(t),d=+t.value&&(c.value=t.value),u=[c];for(null==e&&(e=s);n=u.pop();)if(d&&(n.value=+n.data.value),(i=e(n.data))&&(l=i.length))for(n.children=new Array(l),o=l-1;o>=0;--o)u.push(r=n.children[o]=new h(i[o])),r.parent=n,r.depth=n.depth+1;return c.eachBefore(a)}function s(t){return t.children}function o(t){t.data=t.data.data}function a(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}h.prototype=i.prototype={constructor:h,count:function(){return this.eachAfter(r)},each:function(t){var e,n,r,i,s=this,o=[s];do{for(e=o.reverse(),o=[];s=e.pop();)if(t(s),n=s.children)for(r=0,i=n.length;r<i;++r)o.push(n[r])}while(o.length);return this},eachAfter:function(t){for(var e,n,r,i=this,s=[i],o=[];i=s.pop();)if(o.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)s.push(e[n]);for(;i=o.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return i(this).eachBefore(o)}};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 r(t){const e=o(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 d(this),u(this),this}}}(),t,(t=>t.children));return e.update(),e.data}function s(){const t=n("nodeSize"),e=n("spacing");return class n extends i.prototype.constructor{constructor(t){super(t)}copy(){const t=o(this.constructor,this,(t=>t.children));return t.each((t=>t.data=t.data.data)),t}get size(){return t(this)}spacing(t){return e(this,t)}get nodes(){return this.descendants()}get xSize(){return this.size[0]}get ySize(){return this.size[1]}get top(){return this.y}get bottom(){return this.y+this.ySize}get left(){return this.x-this.xSize/2}get right(){return this.x+this.xSize/2}get root(){const t=this.ancestors();return t[t.length-1]}get numChildren(){return this.hasChildren?this.children.length:0}get hasChildren(){return!this.noChildren}get noChildren(){return null===this.children}get firstChild(){return this.hasChildren?this.children[0]:null}get lastChild(){return this.hasChildren?this.children[this.numChildren-1]:null}get extents(){return(this.children||[]).reduce(((t,e)=>n.maxExtents(t,e.extents)),this.nodeExtents)}get nodeExtents(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}static maxExtents(t,e){return{top:Math.min(t.top,e.top),bottom:Mat
/*! markmap-common v0.1.1 | MIT License */
class ${constructor(){this.listeners=[]}tap(t){return this.listeners.push(t),()=>this.revoke(t)}revoke(t){const e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)}revokeAll(){this.listeners.splice(0)}call(...t){for(const e of this.listeners)e(...t)}}const k=Math.random().toString(36).slice(2,8);let w=0;function X(){}function b(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 C(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 j(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=C(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function R(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 M=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(R("link",{rel:"preload",as:"script",href:t}))}));function I(t,e){if("script"===t.type)return new Promise(((e,r)=>{document.head.append(R("script",n({},t.data,{onload:e,onerror:r})))}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function A(t){"style"===t.type?document.head.append(R("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(R("link",n({rel:"stylesheet"},t.data)))}function H(t){const e=t.data;return Math.max(6-2*e.d,1.5)}const B=new $;class N{constructor(t,r){var i;this.options=void 0,this.state=void 0,this.svg=void 0,this.styleNode=void 0,this.g=void 0,this.zoom=void 0,this.viewHooks=void 0,this.revokers=[],["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new $},this.svg=t.datum?t:e.select(t),this.styleNode=this.svg.append("style"),this.zoom=e.zoom().on("zoom",this.handleZoom),this.options=n({duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(i=e.scaleOrdinal(e.schemeCategory10),t=>i(t.p.i)),paddingX:8},r),this.state={id:this.options.id||(w+=1,`mm-${k}-${w}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(B.tap((()=>{this.setData()})))}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 { display: inline-block; font: ${e}; white-space: nowrap; }\n.${n}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }\n.${n}-fo :not(pre) > code { padding: .2em .4em; }\n.${n}-fo del { text-decoration: line-through; }\n.${n}-fo em { font-style: italic; }\n.${n}-fo strong { font-weight: bolder; }\n.${n}-fo pre { margin: 0; padding: .2em .4em; }\n.${n}-g > g { cursor: pointer; }\n${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",j(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var r;const{data:i}=e;i.p=n({},i.p,{f:!(null!=(r=i.p)&&r.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:r,color:i,nodeMinHeight:s}=this.options,{id:o}=this.state,a=document.createElement("div"),h=`${o}-container`;a.className=j(a.className,`${o}-fo`,h);const l=document.createElement("style");l.textContent=`\n${this.getStyleContent()}\n.${h} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${r};\n}\n.${h} > div {\n display: inline-block;\n}\n`,document.body.append(l,a),b(t,((t,r)=>{var s;t.c=null==(s=t.c)?void 0:s.map((t=>n({},t))),e+=1;const o=document.createElement("div");o.innerHTML=t.v,a.append(o),t.p=n({},t.p,{i:e,el:o}),i(t),r()}));const