New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

markmap-view

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markmap-view - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

7

dist/index.cjs.js

@@ -1,2 +0,2 @@

/*! markmap-view v0.2.5 | MIT License */
/*! markmap-view v0.2.6 | MIT License */
'use strict';

@@ -1200,5 +1200,4 @@

setData(data, opts) {
if (!data) data = _extends$1({}, this.state.data);
this.state.data = data;
this.initializeData(data);
if (data) this.state.data = data;
this.initializeData(this.state.data);
if (opts) this.setOptions(opts);

@@ -1205,0 +1204,0 @@ this.renderData();

@@ -1,2 +0,2 @@

/*! markmap-view v0.2.5 | MIT License */
/*! markmap-view v0.2.6 | MIT License */
import * as d3 from 'd3';

@@ -1184,5 +1184,4 @@

setData(data, opts) {
if (!data) data = _extends$1({}, this.state.data);
this.state.data = data;
this.initializeData(data);
if (data) this.state.data = data;
this.initializeData(this.state.data);
if (opts) this.setOptions(opts);

@@ -1189,0 +1188,0 @@ this.renderData();

@@ -1,2 +0,2 @@

/*! markmap-view v0.2.5 | MIT License */
/*! markmap-view v0.2.6 | MIT License */
(function (exports, d3) {

@@ -1199,5 +1199,4 @@ 'use strict';

setData(data, opts) {
if (!data) data = _extends$1({}, this.state.data);
this.state.data = data;
this.initializeData(data);
if (data) this.state.data = data;
this.initializeData(this.state.data);
if (opts) this.setOptions(opts);

@@ -1204,0 +1203,0 @@ this.renderData();

@@ -1,4 +0,4 @@

/*! markmap-view v0.2.5 | MIT License */
/*! markmap-view v0.2.6 | MIT License */
!function(t,e){"use strict";function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){e[n]=t[n]})),e.default=t,Object.freeze(e)}var r=n(e);function i(){return(i=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 o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,c(t,e)}function h(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 u(t,e){var n,r,i,o,a,s=new g(t),c=+t.value&&(s.value=t.value),l=[s];for(null==e&&(e=d);n=l.pop();)if(c&&(n.value=+n.data.value),(i=e(n.data))&&(a=i.length))for(n.children=new Array(a),o=a-1;o>=0;--o)l.push(r=n.children[o]=new g(i[o])),r.parent=n,r.depth=n.depth+1;return s.eachBefore(p)}function d(t){return t.children}function f(t){t.data=t.data.data}function p(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function g(t){this.data=t,this.depth=this.height=0,this.parent=null}g.prototype=u.prototype={constructor:g,count:function(){return this.eachAfter(h)},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 u(this).eachBefore(f)}};var m=Object.freeze({children:function(t){return t.children},nodeSize:function(t){return t.data.size},spacing:0});function v(t){var e=Object.assign({},m,t);function n(t){var n=e[t];return"function"==typeof n?n:function(){return n}}function r(t){var e,r,c,h=a((e=i(),r=n("nodeSize"),c=n("spacing"),function(t){function e(e){var n;return n=t.call(this,e)||this,Object.assign(o(n),{x:0,y:0,relX:0,prelim:0,shift:0,change:0,lExt:o(n),lExtRelX:0,lThr:null,rExt:o(n),rExtRelX:0,rThr:null}),n}l(e,t);var n=e.prototype;return n.spacing=function(t){return c(this.data,t.data)},n.update=function(){return y(this),x(this),this},s(e,[{key:"size",get:function(){return r(this.data)}},{key:"x",get:function(){return this.data.x},set:function(t){this.data.x=t}},{key:"y",get:function(){return this.data.y},set:function(t){this.data.y=t}}]),e}(e)),t,(function(t){return t.children}));return h.update(),h.data}function i(){var t=n("nodeSize"),e=n("spacing");return function(n){function r(t){return n.call(this,t)||this}l(r,n);var i=r.prototype;return i.copy=function(){var t=a(this.constructor,this,(function(t){return t.children}));return t.each((function(t){return t.data=t.data.data})),t},i.spacing=function(t){return e(this,t)},r.maxExtents=function(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)}},s(r,[{key:"size",get:function(){return t(this)}},{key:"nodes",get:function(){return this.descendants()}},{key:"xSize",get:function(){return this.size[0]}},{key:"ySize",get:function(){return this.size[1]}},{key:"top",get:function(){return this.y}},{key:"bottom",get:function(){return this.y+this.ySize}},{key:"left",get:function(){return this.x-this.xSize/2}},{key:"right",get:function(){return this.x+this.xSize/2}},{key:"root",get:function(){var t=this.ancestors();return t[t.length-1]}},{key:"numChildren",get:function(){return this.hasChildren?this.children.length:0}},{key:"hasChildren",get:function(){return!this.noChildren}},{key:"noChildren",get:function(){return null===this.children}},{key:"firstChild",get:function(){return this.hasChildren?this.children[0]:null}},{key:"lastChild",get:function(){return this.hasChildren?this.children[this.numChildren-1]:null}},{key:"extents",get:function(){return(this.children||[]).reduce((function(t,e){return r.maxExtents(t,e.extents)}),this.nodeExtents)}},{key:"nodeExtents",get:function(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}}]),r}(u.prototype.constructor)}function a(t,e,n){return function e(r,i){var o=new t(r);Object.assign(o,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});var a=n(r)||[];return o.children=0===a.length?null:a.map((function(t){return e(t,o)})),o.children&&Object.assign(o,o.children.reduce((function(t,e){return{height:Math.max(t.height,e.height+1),length:t.length+e.length}}),o)),o}(e,null)}return Object.assign(r,{nodeSize:function(t){return arguments.length?(e.nodeSize=t,r):e.nodeSize},spacing:function(t){return arguments.length?(e.spacing=t,r):e.spacing},children:function(t){return arguments.length?(e.children=t,r):e.children},hierarchy:function(t,n){var r=void 0===n?e.children:n;return a(i(),t,r)},dump:function(t){var e=n("nodeSize");return function t(n){return function(r){var i=n+" ",o=n+" ",a=r.x,s=r.y,c=e(r),l=r.children||[],h=0===l.length?" ":","+i+"children: ["+o+l.map(t(o)).join(o)+i+"],"+n;return"{ size: ["+c.join(", ")+"],"+i+"x: "+a+", y: "+s+h+"},"}}("\n")(t)}}),r}v.version="2.1.1";var y=function t(e,n){return void 0===n&&(n=0),e.y=n,(e.children||[]).reduce((function(n,r){var i=n[0],o=n[1];t(r,e.y+e.ySize);var a=(0===i?r.lExt:r.rExt).bottom;return 0!==i&&k(e,i,o),[i+1,C(a,i,o)]}),[0,null]),z(e),$(e),e},x=function t(e,n,r){void 0===n&&(n=-e.relX-e.prelim,r=0);var i=n+e.relX;return e.relX=i+e.prelim-r,e.prelim=0,e.x=r+e.relX,(e.children||[]).forEach((function(n){return t(n,i,e.x)})),e},z=function(t){(t.children||[]).reduce((function(t,e){var n=t[0],r=t[1],i=n+e.shift,o=r+i+e.change;return e.relX+=o,[i,o]}),[0,0])},k=function(t,e,n){for(var r=t.children[e-1],i=t.children[e],o=r,a=r.relX,s=i,c=i.relX,l=!0;o&&s;){o.bottom>n.lowY&&(n=n.next);var h=a+o.prelim-(c+s.prelim)+o.xSize/2+s.xSize/2+o.spacing(s);(h>0||h<0&&l)&&(c+=h,S(i,h),b(t,e,n.index,h)),l=!1;var u=o.bottom,d=s.bottom;u<=d&&(o=w(o))&&(a+=o.relX),u>=d&&(s=E(s))&&(c+=s.relX)}!o&&s?X(t,e,s,c):o&&!s&&O(t,e,o,a)},S=function(t,e){t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},b=function(t,e,n,r){var i=t.children[e],o=e-n;if(o>1){var a=r/o;t.children[n+1].shift+=a,i.shift-=a,i.change-=r-a}},E=function(t){return t.hasChildren?t.firstChild:t.lThr},w=function(t){return t.hasChildren?t.lastChild:t.rThr},X=function(t,e,n,r){var i=t.firstChild,o=i.lExt,a=t.children[e];o.lThr=n;var s=r-n.relX-i.lExtRelX;o.relX+=s,o.prelim-=s,i.lExt=a.lExt,i.lExtRelX=a.lExtRelX},O=function(t,e,n,r){var i=t.children[e],o=i.rExt,a=t.children[e-1];o.rThr=n;var s=r-n.relX-i.rExtRelX;o.relX+=s,o.prelim-=s,i.rExt=a.rExt,i.rExtRelX=a.rExtRelX},$=function(t){if(t.hasChildren){var 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})}},C=function(t,e,n){for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}};
/*! markmap-common v0.1.5 | MIT License */
class j{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)}}function M(){return(M=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)}const R=Math.random().toString(36).slice(2,8);let I=0;function A(){}function H(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 B(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 T(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach((t=>{t&&n.indexOf(t)<0&&n.push(t)})),n.join(" ")}function N(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=B(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function D(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 P=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(D("link",{rel:"preload",as:"script",href:t}))}));function Y(t,e){if("script"===t.type)return new Promise(((e,n)=>{var r;document.head.append(D("script",M({},t.data,{onload:e,onerror:n}))),null!=(r=t.data)&&r.src||e()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function _(t){"style"===t.type?document.head.append(D("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(D("link",M({rel:"stylesheet"},t.data)))}function F(t){const e=t.data;return Math.max(6-2*e.d,1.5)}function V(t,e){return t[r.minIndex(t,e)]}function Z(t){t.stopPropagation()}const L=new j;class J{constructor(t,e){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 j},this.svg=t.datum?t:r.select(t),this.styleNode=this.svg.append("style"),this.zoom=r.zoom().on("zoom",this.handleZoom),this.options=i({},J.defaultOptions,e),this.state={id:this.options.id||(I+=1,`mm-${R}-${I}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(L.tap((()=>{this.setData()})))}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} { line-height: 1; }\n.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-g > g > circle { cursor: pointer; }\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${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",T(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 n;const{data:r}=e;r.p=i({},r.p,{f:!(null!=(n=r.p)&&n.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:n,color:r,nodeMinHeight:o}=this.options,{id:a}=this.state,s=document.createElement("div"),c=`${a}-container`;s.className=T(s.className,`${a}-fo`,c);const l=document.createElement("style");l.textContent=`\n${this.getStyleContent()}\n.${c} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${n};\n}\n.${c} > div {\n display: inline-block;\n}\n`,document.body.append(l,s),H(t,((t,n)=>{var o;t.c=null==(o=t.c)?void 0:o.map((t=>i({},t))),e+=1;const a=document.createElement("div");a.innerHTML=t.v,s.append(a),t.p=i({},t.p,{i:e,el:a}),r(t),n()}));const h=B(s.childNodes);this.viewHooks.transformHtml.call(this,h),H(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(),l.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t||(t=i({},this.state.data)),this.state.data=t,this.initializeData(t),e&&this.setOptions(e),this.renderData()}renderData(t){var e,n;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:o,spacingVertical:a,autoFit:s,color:c}=this.options,{id:l}=this.state,h=v().children((t=>{var e;return!(null!=(e=t.p)&&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=h.hierarchy(this.state.data);h(u),function(t,e){H(t,((t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()}),"children")}(u,i);const d=u.descendants().reverse(),f=u.links(),p=r.linkHorizontal(),g=r.min(d,(t=>t.x-t.xSize/2)),m=r.max(d,(t=>t.x+t.xSize/2)),y=r.min(d,(t=>t.y)),x=r.max(d,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:g,maxX:m,minY:y,maxY:x}),s&&this.fit();const z=t&&d.find((e=>e.data===t))||u,k=null!=(e=z.data.p.x0)?e:z.x,S=null!=(n=z.data.p.y0)?n:z.y,b=this.g.selectAll(N("g")).data(d,(t=>t.data.p.k)),E=b.enter().append("g").attr("transform",(t=>`translate(${S+z.ySizeInner-t.ySizeInner},${k+z.xSize/2-t.xSize})`)),w=this.transition(b.exit());w.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),w.select("foreignObject").style("opacity",0),w.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const X=b.merge(E);this.transition(X).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const O=X.selectAll(N("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-F(t)/2)).attr("width",0).attr("height",F)),(t=>t),(t=>t.remove()));this.transition(O).attr("x",-1).attr("width",(t=>t.ySizeInner+2)).attr("fill",(t=>c(t.data)));const $=X.selectAll(N("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).on("click",this.handleClick)),(t=>t),(t=>t.remove()));this.transition($).attr("r",6).attr("stroke",(t=>c(t.data))).attr("fill",(t=>{var e;return null!=(e=t.data.p)&&e.f&&t.data.c?c(t.data):"#fff"}));const C=X.selectAll(N("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",`${l}-fo`).attr("x",o).attr("y",0).style("opacity",0).attr("height",(t=>t.xSize)).on("mousedown",Z).on("dblclick",Z);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(C).style("opacity",1);const j=this.g.selectAll(N("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[S+z.ySizeInner,k+z.xSize/2];return t.insert("path","g").attr("d",p({source:e,target:e}))}),(t=>t),(t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",p({source:e,target:e})).remove()}));this.transition(j).attr("stroke",(t=>c(t.target.data))).attr("stroke-width",(t=>F(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 p({source:e,target:n})})),d.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)}async fit(){const t=this.svg.node(),{width:e,height:n}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:o,maxX:a,minY:s,maxY:c}=this.state,l=c-s,h=a-o,u=Math.min(e/l*i,n/h*i,2),d=r.zoomIdentity.translate((e-l*u)/2-s*u,(n-h*u)/2-o*u).scale(u);return this.transition(this.svg).call(this.zoom.transform,d).end().catch(A)}async ensureView(t,e){let n,o;if(this.g.selectAll(N("g")).each((function(e){e.data===t&&(n=this,o=e)})),!n||!o)return;const a=this.svg.node(),s=a.getBoundingClientRect(),c=r.zoomTransform(a),[l,h]=[o.y,o.y+o.ySizeInner+2].map((t=>t*c.k+c.x)),[u,d]=[o.x-o.xSize/2,o.x+o.xSize/2].map((t=>t*c.k+c.y)),f=i({left:0,right:0,top:0,bottom:0},e),p=[f.left-l,s.width-f.right-h],g=[f.top-u,s.height-f.bottom-d],m=p[0]*p[1]>0?V(p,Math.abs)/c.k:0,v=g[0]*g[1]>0?V(g,Math.abs)/c.k:0;if(m||v){const t=c.translate(m,v);return this.transition(this.svg).call(this.zoom.transform,t).end().catch(A)}}async rescale(t){const e=this.svg.node(),{width:n,height:i}=e.getBoundingClientRect(),o=n/2,a=i/2,s=r.zoomTransform(e),c=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,c).end().catch(A)}destroy(){this.svg.remove(),this.revokers.forEach((t=>{t()}))}static create(t,e,n){const r=new J(t,e);return n&&(r.setData(n),r.fit()),r}}var W;J.defaultOptions={duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(W=r.scaleOrdinal(r.schemeCategory10),t=>W(t.p.i)),paddingX:8},t.Markmap=J,t.loadCSS=function(t){for(const e of t)_(e)},t.loadJS=async function(t,e){const n=t.filter((t=>{var e;return"script"===t.type&&(null==(e=t.data)?void 0:e.src)}));n.length>1&&n.forEach((t=>P(t.data.src))),e=M({getMarkmap:()=>window.markmap},e);for(const n of t)await Y(n,e)},t.refreshHook=L}(this.markmap=this.markmap||{},d3);
class j{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)}}function M(){return(M=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)}const R=Math.random().toString(36).slice(2,8);let I=0;function A(){}function H(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 B(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 T(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach((t=>{t&&n.indexOf(t)<0&&n.push(t)})),n.join(" ")}function N(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=B(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function D(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 P=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(D("link",{rel:"preload",as:"script",href:t}))}));function Y(t,e){if("script"===t.type)return new Promise(((e,n)=>{var r;document.head.append(D("script",M({},t.data,{onload:e,onerror:n}))),null!=(r=t.data)&&r.src||e()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function _(t){"style"===t.type?document.head.append(D("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(D("link",M({rel:"stylesheet"},t.data)))}function F(t){const e=t.data;return Math.max(6-2*e.d,1.5)}function V(t,e){return t[r.minIndex(t,e)]}function Z(t){t.stopPropagation()}const L=new j;class J{constructor(t,e){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 j},this.svg=t.datum?t:r.select(t),this.styleNode=this.svg.append("style"),this.zoom=r.zoom().on("zoom",this.handleZoom),this.options=i({},J.defaultOptions,e),this.state={id:this.options.id||(I+=1,`mm-${R}-${I}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(L.tap((()=>{this.setData()})))}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} { line-height: 1; }\n.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-g > g > circle { cursor: pointer; }\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${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",T(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 n;const{data:r}=e;r.p=i({},r.p,{f:!(null!=(n=r.p)&&n.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:n,color:r,nodeMinHeight:o}=this.options,{id:a}=this.state,s=document.createElement("div"),c=`${a}-container`;s.className=T(s.className,`${a}-fo`,c);const l=document.createElement("style");l.textContent=`\n${this.getStyleContent()}\n.${c} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${n};\n}\n.${c} > div {\n display: inline-block;\n}\n`,document.body.append(l,s),H(t,((t,n)=>{var o;t.c=null==(o=t.c)?void 0:o.map((t=>i({},t))),e+=1;const a=document.createElement("div");a.innerHTML=t.v,s.append(a),t.p=i({},t.p,{i:e,el:a}),r(t),n()}));const h=B(s.childNodes);this.viewHooks.transformHtml.call(this,h),H(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(),l.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t&&(this.state.data=t),this.initializeData(this.state.data),e&&this.setOptions(e),this.renderData()}renderData(t){var e,n;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:o,spacingVertical:a,autoFit:s,color:c}=this.options,{id:l}=this.state,h=v().children((t=>{var e;return!(null!=(e=t.p)&&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=h.hierarchy(this.state.data);h(u),function(t,e){H(t,((t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()}),"children")}(u,i);const d=u.descendants().reverse(),f=u.links(),p=r.linkHorizontal(),g=r.min(d,(t=>t.x-t.xSize/2)),m=r.max(d,(t=>t.x+t.xSize/2)),y=r.min(d,(t=>t.y)),x=r.max(d,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:g,maxX:m,minY:y,maxY:x}),s&&this.fit();const z=t&&d.find((e=>e.data===t))||u,k=null!=(e=z.data.p.x0)?e:z.x,S=null!=(n=z.data.p.y0)?n:z.y,b=this.g.selectAll(N("g")).data(d,(t=>t.data.p.k)),E=b.enter().append("g").attr("transform",(t=>`translate(${S+z.ySizeInner-t.ySizeInner},${k+z.xSize/2-t.xSize})`)),w=this.transition(b.exit());w.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),w.select("foreignObject").style("opacity",0),w.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const X=b.merge(E);this.transition(X).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const O=X.selectAll(N("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-F(t)/2)).attr("width",0).attr("height",F)),(t=>t),(t=>t.remove()));this.transition(O).attr("x",-1).attr("width",(t=>t.ySizeInner+2)).attr("fill",(t=>c(t.data)));const $=X.selectAll(N("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).on("click",this.handleClick)),(t=>t),(t=>t.remove()));this.transition($).attr("r",6).attr("stroke",(t=>c(t.data))).attr("fill",(t=>{var e;return null!=(e=t.data.p)&&e.f&&t.data.c?c(t.data):"#fff"}));const C=X.selectAll(N("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",`${l}-fo`).attr("x",o).attr("y",0).style("opacity",0).attr("height",(t=>t.xSize)).on("mousedown",Z).on("dblclick",Z);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(C).style("opacity",1);const j=this.g.selectAll(N("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[S+z.ySizeInner,k+z.xSize/2];return t.insert("path","g").attr("d",p({source:e,target:e}))}),(t=>t),(t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",p({source:e,target:e})).remove()}));this.transition(j).attr("stroke",(t=>c(t.target.data))).attr("stroke-width",(t=>F(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 p({source:e,target:n})})),d.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)}async fit(){const t=this.svg.node(),{width:e,height:n}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:o,maxX:a,minY:s,maxY:c}=this.state,l=c-s,h=a-o,u=Math.min(e/l*i,n/h*i,2),d=r.zoomIdentity.translate((e-l*u)/2-s*u,(n-h*u)/2-o*u).scale(u);return this.transition(this.svg).call(this.zoom.transform,d).end().catch(A)}async ensureView(t,e){let n,o;if(this.g.selectAll(N("g")).each((function(e){e.data===t&&(n=this,o=e)})),!n||!o)return;const a=this.svg.node(),s=a.getBoundingClientRect(),c=r.zoomTransform(a),[l,h]=[o.y,o.y+o.ySizeInner+2].map((t=>t*c.k+c.x)),[u,d]=[o.x-o.xSize/2,o.x+o.xSize/2].map((t=>t*c.k+c.y)),f=i({left:0,right:0,top:0,bottom:0},e),p=[f.left-l,s.width-f.right-h],g=[f.top-u,s.height-f.bottom-d],m=p[0]*p[1]>0?V(p,Math.abs)/c.k:0,v=g[0]*g[1]>0?V(g,Math.abs)/c.k:0;if(m||v){const t=c.translate(m,v);return this.transition(this.svg).call(this.zoom.transform,t).end().catch(A)}}async rescale(t){const e=this.svg.node(),{width:n,height:i}=e.getBoundingClientRect(),o=n/2,a=i/2,s=r.zoomTransform(e),c=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,c).end().catch(A)}destroy(){this.svg.remove(),this.revokers.forEach((t=>{t()}))}static create(t,e,n){const r=new J(t,e);return n&&(r.setData(n),r.fit()),r}}var W;J.defaultOptions={duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(W=r.scaleOrdinal(r.schemeCategory10),t=>W(t.p.i)),paddingX:8},t.Markmap=J,t.loadCSS=function(t){for(const e of t)_(e)},t.loadJS=async function(t,e){const n=t.filter((t=>{var e;return"script"===t.type&&(null==(e=t.data)?void 0:e.src)}));n.length>1&&n.forEach((t=>P(t.data.src))),e=M({getMarkmap:()=>window.markmap},e);for(const n of t)await Y(n,e)},t.refreshHook=L}(this.markmap=this.markmap||{},d3);
{
"name": "markmap-view",
"version": "0.2.5",
"version": "0.2.6",
"description": "View markmaps in browser",

@@ -50,3 +50,3 @@ "author": "Gerald <gera2ld@live.com>",

},
"gitHead": "e7ad38a05cf693b73c584899419eb945e7cb0c7a"
"gitHead": "c1b04d45e3d7a9be432c2980ee105983abac7470"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc