markmap-view
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,2 +0,2 @@ | ||
/*! markmap-view v0.1.1 | MIT License */ | ||
/*! markmap-view v0.1.2 | MIT License */ | ||
'use strict'; | ||
@@ -1051,8 +1051,8 @@ | ||
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; } | ||
.${id}-fo code { padding: .2em .4em; font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo :not(pre) > code { padding: .2em .4em; } | ||
.${id}-fo del { text-decoration: line-through; } | ||
.${id}-fo em { font-style: italic; } | ||
.${id}-fo strong { font-weight: bolder; } | ||
.${id}-fo pre { margin: 0; } | ||
.${id}-fo pre[class*=language-] { padding: 0; } | ||
.${id}-fo pre { margin: 0; padding: .2em .4em; } | ||
.${id}-g > g { cursor: pointer; } | ||
@@ -1059,0 +1059,0 @@ ${extraStyle} |
@@ -1,2 +0,2 @@ | ||
/*! markmap-view v0.1.1 | MIT License */ | ||
/*! markmap-view v0.1.2 | MIT License */ | ||
import _extends from '@babel/runtime/helpers/esm/extends'; | ||
@@ -1014,8 +1014,8 @@ import { select, zoom, scaleOrdinal, schemeCategory10, linkHorizontal, min, max, zoomIdentity, zoomTransform } from 'd3'; | ||
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; } | ||
.${id}-fo code { padding: .2em .4em; font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo :not(pre) > code { padding: .2em .4em; } | ||
.${id}-fo del { text-decoration: line-through; } | ||
.${id}-fo em { font-style: italic; } | ||
.${id}-fo strong { font-weight: bolder; } | ||
.${id}-fo pre { margin: 0; } | ||
.${id}-fo pre[class*=language-] { padding: 0; } | ||
.${id}-fo pre { margin: 0; padding: .2em .4em; } | ||
.${id}-g > g { cursor: pointer; } | ||
@@ -1022,0 +1022,0 @@ ${extraStyle} |
@@ -1,2 +0,2 @@ | ||
/*! markmap-view v0.1.1 | MIT License */ | ||
/*! markmap-view v0.1.2 | MIT License */ | ||
(function (exports, d3) { | ||
@@ -1032,8 +1032,8 @@ 'use strict'; | ||
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; } | ||
.${id}-fo code { padding: .2em .4em; font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo :not(pre) > code { padding: .2em .4em; } | ||
.${id}-fo del { text-decoration: line-through; } | ||
.${id}-fo em { font-style: italic; } | ||
.${id}-fo strong { font-weight: bolder; } | ||
.${id}-fo pre { margin: 0; } | ||
.${id}-fo pre[class*=language-] { padding: 0; } | ||
.${id}-fo pre { margin: 0; padding: .2em .4em; } | ||
.${id}-g > g { cursor: pointer; } | ||
@@ -1040,0 +1040,0 @@ ${extraStyle} |
@@ -1,4 +0,4 @@ | ||
/*! markmap-view v0.1.1 | MIT License */ | ||
/*! markmap-view v0.1.2 | 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,a,c,h=new l(t),d=+t.value&&(h.value=t.value),u=[h];for(null==e&&(e=o);n=u.pop();)if(d&&(n.value=+n.data.value),(i=e(n.data))&&(c=i.length))for(n.children=new Array(c),a=c-1;a>=0;--a)u.push(r=n.children[a]=new l(i[a])),r.parent=n,r.depth=n.depth+1;return h.eachBefore(s)}function o(t){return t.children}function a(t){t.data=t.data.data}function s(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function l(t){this.data=t,this.depth=this.height=0,this.parent=null}l.prototype=i.prototype={constructor:l,count:function(){return this.eachAfter(r)},each:function(t){var e,n,r,i,o=this,a=[o];do{for(e=a.reverse(),a=[];o=e.pop();)if(t(o),n=o.children)for(r=0,i=n.length;r<i;++r)a.push(n[r])}while(a.length);return this},eachAfter:function(t){for(var e,n,r,i=this,o=[i],a=[];i=o.pop();)if(a.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)o.push(e[n]);for(;i=a.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return i(this).eachBefore(a)}};const c=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function h(t){const e=Object.assign({},c,t);function n(t){const n=e[t];return"function"==typeof n?n:()=>n}function r(t){const e=a(function(){const t=o(),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 o(){const t=n("nodeSize"),e=n("spacing");return class n extends i.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 o=new t(e);Object.assign(o,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});const a=n(e)||[];return o.children=0===a.length?null:a.map((t=>r(t,o))),o.children&&Object.assign(o,o.children.reduce(((t,e)=>({height:Math.max(t.height,e.height+1),length:t.length+e.length})),o)),o};return r(e,null)}return Object.assign(r,{nodeSize(t){return arguments.length?(e.nodeSize=t,r):e.nodeSize},spacing(t){return arguments.length?(e.spacing=t,r):e.spacing},children(t){return arguments.length?(e.children=t,r):e.children},hierarchy(t,n){const r=void 0===n?e.children:n;return a(o(),t,r)},dump(t){const e=n("nodeSize"),r=t=>n=>{const i=t+" ",o=t+" ",{x:a,y:s}=n,l=e(n),c=n.children||[],h=0===c.length?" ":`,${i}children: [${o}${c.map(r(o)).join(o)}${i}],${t}`;return`{ size: [${l.join(", ")}],${i}x: ${a}, y: ${s}${h}},`};return r("\n")(t)}}),r}h.version="2.1.1";const d=(t,e=0)=>(t.y=e,(t.children||[]).reduce(((e,n)=>{const[r,i]=e;d(n,t.y+t.ySize);const o=(0===r?n.lExt:n.rExt).bottom;0!==r&&f(t,r,i);return[r+1,b(o,r,i)]}),[0,null]),p(t),S(t),t),u=(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=>u(e,r,t.x))),t},p=t=>{(t.children||[]).reduce(((t,e)=>{const[n,r]=t,i=n+e.shift,o=r+i+e.change;return e.relX+=o,[i,o]}),[0,0])},f=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let o=r,a=r.relX,s=i,l=i.relX,c=!0;for(;o&&s;){o.bottom>n.lowY&&(n=n.next);const r=a+o.prelim-(l+s.prelim)+o.xSize/2+s.xSize/2+o.spacing(s);(r>0||r<0&&c)&&(l+=r,g(i,r),m(t,e,n.index,r)),c=!1;const h=o.bottom,d=s.bottom;h<=d&&(o=v(o),o&&(a+=o.relX)),h>=d&&(s=x(s),s&&(l+=s.relX))}!o&&s?y(t,e,s,l):o&&!s&&z(t,e,o,a)},g=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},m=(t,e,n,r)=>{const i=t.children[e],o=e-n;if(o>1){const e=r/o;t.children[n+1].shift+=e,i.shift-=e,i.change-=r-e}},x=t=>t.hasChildren?t.firstChild:t.lThr,v=t=>t.hasChildren?t.lastChild:t.rThr,y=(t,e,n,r)=>{const i=t.firstChild,o=i.lExt,a=t.children[e];o.lThr=n;const s=r-n.relX-i.lExtRelX;o.relX+=s,o.prelim-=s,i.lExt=a.lExt,i.lExtRelX=a.lExtRelX},z=(t,e,n,r)=>{const i=t.children[e],o=i.rExt,a=t.children[e-1];o.rThr=n;const s=r-n.relX-i.rExtRelX;o.relX+=s,o.prelim-=s,i.rExt=a.rExt,i.rExtRelX=a.rExtRelX},S=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})}},b=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}}; | ||
/*! markmap-common v0.1.0 | MIT License */ | ||
function E(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return w(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return w(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var X=function(){function t(){this.listeners=[]}var e=t.prototype;return e.tap=function(t){var e=this;return this.listeners.push(t),function(){return e.revoke(t)}},e.revoke=function(t){var e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)},e.revokeAll=function(){this.listeners.splice(0)},e.call=function(){for(var t,e=E(this.listeners);!(t=e()).done;){var n=t.value;n.apply(void 0,arguments)}},t}(),$=Math.random().toString(36).slice(2,8),k=0;function C(){}function j(t,e,n){void 0===n&&(n="c");!function t(r,i){return e(r,(function(){var e;null==(e=r[n])||e.forEach((function(e){t(e,r)}))}),i)}(t)}function O(t){if(Array.from)return Array.from(t);for(var e=[],n=0;n<t.length;n+=1)e.push(t[n]);return e}function A(t){for(var e=(t||"").split(" ").filter(Boolean),n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.forEach((function(t){t&&e.indexOf(t)<0&&e.push(t)})),e.join(" ")}function R(t){if("string"==typeof t){var e=t;t=function(t){return t.tagName===e}}var n=t;return function(){var t=O(this.childNodes);return n&&(t=t.filter((function(t){return n(t)}))),t}}function M(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 I=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(M("link",{rel:"preload",as:"script",href:t}))}));function H(t,e){if("script"===t.type)return new Promise(((e,r)=>{document.head.append(M("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 T(t){"style"===t.type?document.head.append(M("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(M("link",n({rel:"stylesheet"},t.data)))}function B(t){const e=t.data;return Math.max(6-2*e.d,1.5)}const N=[];class D{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,["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new X},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||"mm-"+$+"-"+(k+=1)},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 { display: inline-block; 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: bolder; }\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",A(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var r;const{data:i}=e;i.p=n({},i.p,{f:!(null==(r=i.p)?void 0:r.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:r,color:i,nodeMinHeight:o}=this.options,{id:a}=this.state,s=document.createElement("div"),l=a+"-container";s.className=A(s.className,a+"-fo",l);const c=document.createElement("style");c.textContent=`\n${this.getStyleContent()}\n.${l} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${r};\n}\n.${l} > div {\n display: inline-block;\n}\n`,document.body.append(c,s),j(t,((t,r)=>{var o;t.c=null==(o=t.c)?void 0:o.map((t=>n({},t))),e+=1;const a=document.createElement("div");a.innerHTML=t.v,s.append(a),t.p=n({},t.p,{i:e,el:a}),i(t),r()}));const h=O(s.childNodes);this.viewHooks.transformHtml.call(this,h),j(t,((t,e,n)=>{var r;const i=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(i.width),Math.max(Math.ceil(i.height),o)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()})),s.remove(),c.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t||(t=n({},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:o,spacingVertical:a,autoFit:s,color:l}=this.options,{id:c}=this.state,d=h().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*o:0)+i]})).spacing(((t,e)=>t.parent===e.parent?a:2*a)),u=d.hierarchy(this.state.data);d(u),function(t,e){j(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)),v=e.min(p,(t=>t.y)),y=e.max(p,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:m,maxX:x,minY:v,maxY:y}),s&&this.fit();const z=t&&p.find((e=>e.data===t))||u,S=null!=(n=z.data.p.x0)?n:z.x,b=null!=(r=z.data.p.y0)?r:z.y,E=this.g.selectAll(R("g")).data(p,(t=>t.data.p.k)),w=E.enter().append("g").attr("transform",(t=>`translate(${b+z.ySizeInner-t.ySizeInner},${S+z.xSize/2-t.xSize})`)).on("click",this.handleClick),X=this.transition(E.exit());X.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),X.select("foreignObject").style("opacity",0),X.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const $=E.merge(w);this.transition($).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const k=$.selectAll(R("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-B(t)/2)).attr("width",0).attr("height",B)),(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=$.selectAll(R("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)&&t.data.c?l(t.data):"#fff"}));const O=$.selectAll(R("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",c+"-fo").attr("x",o).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*o)));this.transition(O).style("opacity",1);const A=this.g.selectAll(R("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[b+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(A).attr("stroke",(t=>l(t.target.data))).attr("stroke-width",(t=>B(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:o,maxX:a,minY:s,maxY:l}=this.state,c=l-s,h=a-o,d=Math.min(n/c*i,r/h*i,2),u=e.zoomIdentity.translate((n-c*d)/2-s*d,(r-h*d)/2-o*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(C)}rescale(t){const n=this.svg.node(),{width:r,height:i}=n.getBoundingClientRect(),o=r/2,a=i/2,s=e.zoomTransform(n),l=s.translate((o-s.x)*(1-t)/s.k,(a-s.y)*(1-t)/s.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,l).end().catch(C)}static create(t,e,n){const r=new D(t,e);return n&&(r.setData(n),r.fit()),function(t,e){let n;const r=()=>{n||(n=Promise.resolve().then((()=>{n=void 0,e()})).catch(C))};t.forEach((e=>{e.then(r,C).then((()=>{const n=t.indexOf(e);n>=0&&t.splice(n,1)}))}))}(N,(()=>{r.setData()})),r}}t.Markmap=D,t.loadCSS=function(t){for(const e of t)T(e)},t.loadJS=async function(t,e){const r=t.filter((t=>"script"===t.type));r.length>1&&r.forEach((t=>I(t.data.src))),e=n({getMarkmap:()=>window.markmap},e);for(const n of t)await H(n,e)},t.registerRefreshPromise=function(t){N.push(t)}}(this.markmap=this.markmap||{},d3); | ||
function E(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return w(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return w(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var X=function(){function t(){this.listeners=[]}var e=t.prototype;return e.tap=function(t){var e=this;return this.listeners.push(t),function(){return e.revoke(t)}},e.revoke=function(t){var e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)},e.revokeAll=function(){this.listeners.splice(0)},e.call=function(){for(var t,e=E(this.listeners);!(t=e()).done;){var n=t.value;n.apply(void 0,arguments)}},t}(),$=Math.random().toString(36).slice(2,8),k=0;function C(){}function j(t,e,n){void 0===n&&(n="c");!function t(r,i){return e(r,(function(){var e;null==(e=r[n])||e.forEach((function(e){t(e,r)}))}),i)}(t)}function O(t){if(Array.from)return Array.from(t);for(var e=[],n=0;n<t.length;n+=1)e.push(t[n]);return e}function A(t){for(var e=(t||"").split(" ").filter(Boolean),n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.forEach((function(t){t&&e.indexOf(t)<0&&e.push(t)})),e.join(" ")}function R(t){if("string"==typeof t){var e=t;t=function(t){return t.tagName===e}}var n=t;return function(){var t=O(this.childNodes);return n&&(t=t.filter((function(t){return n(t)}))),t}}function M(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 I=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(M("link",{rel:"preload",as:"script",href:t}))}));function H(t,e){if("script"===t.type)return new Promise(((e,r)=>{document.head.append(M("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 T(t){"style"===t.type?document.head.append(M("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(M("link",n({rel:"stylesheet"},t.data)))}function B(t){const e=t.data;return Math.max(6-2*e.d,1.5)}const N=[];class D{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,["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new X},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||"mm-"+$+"-"+(k+=1)},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 { 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",A(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var r;const{data:i}=e;i.p=n({},i.p,{f:!(null==(r=i.p)?void 0:r.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:r,color:i,nodeMinHeight:o}=this.options,{id:a}=this.state,s=document.createElement("div"),l=a+"-container";s.className=A(s.className,a+"-fo",l);const c=document.createElement("style");c.textContent=`\n${this.getStyleContent()}\n.${l} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${r};\n}\n.${l} > div {\n display: inline-block;\n}\n`,document.body.append(c,s),j(t,((t,r)=>{var o;t.c=null==(o=t.c)?void 0:o.map((t=>n({},t))),e+=1;const a=document.createElement("div");a.innerHTML=t.v,s.append(a),t.p=n({},t.p,{i:e,el:a}),i(t),r()}));const h=O(s.childNodes);this.viewHooks.transformHtml.call(this,h),j(t,((t,e,n)=>{var r;const i=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(i.width),Math.max(Math.ceil(i.height),o)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()})),s.remove(),c.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t||(t=n({},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:o,spacingVertical:a,autoFit:s,color:l}=this.options,{id:c}=this.state,d=h().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*o:0)+i]})).spacing(((t,e)=>t.parent===e.parent?a:2*a)),u=d.hierarchy(this.state.data);d(u),function(t,e){j(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)),v=e.min(p,(t=>t.y)),y=e.max(p,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:m,maxX:x,minY:v,maxY:y}),s&&this.fit();const z=t&&p.find((e=>e.data===t))||u,S=null!=(n=z.data.p.x0)?n:z.x,b=null!=(r=z.data.p.y0)?r:z.y,E=this.g.selectAll(R("g")).data(p,(t=>t.data.p.k)),w=E.enter().append("g").attr("transform",(t=>`translate(${b+z.ySizeInner-t.ySizeInner},${S+z.xSize/2-t.xSize})`)).on("click",this.handleClick),X=this.transition(E.exit());X.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),X.select("foreignObject").style("opacity",0),X.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const $=E.merge(w);this.transition($).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const k=$.selectAll(R("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-B(t)/2)).attr("width",0).attr("height",B)),(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=$.selectAll(R("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)&&t.data.c?l(t.data):"#fff"}));const O=$.selectAll(R("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",c+"-fo").attr("x",o).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*o)));this.transition(O).style("opacity",1);const A=this.g.selectAll(R("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[b+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(A).attr("stroke",(t=>l(t.target.data))).attr("stroke-width",(t=>B(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:o,maxX:a,minY:s,maxY:l}=this.state,c=l-s,h=a-o,d=Math.min(n/c*i,r/h*i,2),u=e.zoomIdentity.translate((n-c*d)/2-s*d,(r-h*d)/2-o*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(C)}rescale(t){const n=this.svg.node(),{width:r,height:i}=n.getBoundingClientRect(),o=r/2,a=i/2,s=e.zoomTransform(n),l=s.translate((o-s.x)*(1-t)/s.k,(a-s.y)*(1-t)/s.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,l).end().catch(C)}static create(t,e,n){const r=new D(t,e);return n&&(r.setData(n),r.fit()),function(t,e){let n;const r=()=>{n||(n=Promise.resolve().then((()=>{n=void 0,e()})).catch(C))};t.forEach((e=>{e.then(r,C).then((()=>{const n=t.indexOf(e);n>=0&&t.splice(n,1)}))}))}(N,(()=>{r.setData()})),r}}t.Markmap=D,t.loadCSS=function(t){for(const e of t)T(e)},t.loadJS=async function(t,e){const r=t.filter((t=>"script"===t.type));r.length>1&&r.forEach((t=>I(t.data.src))),e=n({getMarkmap:()=>window.markmap},e);for(const n of t)await H(n,e)},t.registerRefreshPromise=function(t){N.push(t)}}(this.markmap=this.markmap||{},d3); |
{ | ||
"name": "markmap-view", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "View markmaps in browser", | ||
@@ -53,3 +53,3 @@ "author": "Gerald <gera2ld@live.com>", | ||
}, | ||
"gitHead": "d5c4ebad6ecdb72167d9e8ff5947f2793aa360ae" | ||
"gitHead": "3d2300a0c6421cc15f9e80de70f3be0be0d8c3bb" | ||
} |
124852