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

markmap-lib

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markmap-lib - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

140

dist/browser/view.js

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

/*! markmap-lib v0.9.0 | MIT License */
/*! markmap-lib v0.9.1 | MIT License */
(function (exports, d3) {

@@ -629,2 +629,93 @@ 'use strict';

function memoize(fn) {
const cache = {};
return function memoized(...args) {
const key = `${args[0]}`;
let data = cache[key];
if (!data) {
data = {
value: fn(...args)
};
cache[key] = data;
}
return data.value;
};
}
function createElement(tagName, props, attrs) {
const el = document.createElement(tagName);
if (props) {
Object.entries(props).forEach(([key, value]) => {
el[key] = value;
});
}
if (attrs) {
Object.entries(attrs).forEach(([key, value]) => {
el.setAttribute(key, value);
});
}
return el;
}
const memoizedPreloadJS = memoize(url => {
document.head.append(createElement('link', {
rel: 'preload',
as: 'script',
href: url
}));
});
function loadJSItem(item, context) {
if (item.type === 'script') {
return new Promise((resolve, reject) => {
document.head.append(createElement('script', _extends({}, item.data, {
onload: resolve,
onerror: reject
})));
});
}
if (item.type === 'iife') {
const {
fn,
getParams
} = item.data;
fn(...((getParams == null ? void 0 : getParams(context)) || []));
}
}
function loadCSSItem(item) {
if (item.type === 'style') {
document.head.append(createElement('style', {
textContent: item.data
}));
} else if (item.type === 'stylesheet') {
document.head.append(createElement('link', _extends({
rel: 'stylesheet'
}, item.data)));
}
}
async function loadJS(items, context) {
const needPreload = items.filter(item => item.type === 'script');
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
context = _extends({
getMarkmap: () => window.markmap
}, context);
for (const item of items) {
await loadJSItem(item, context);
}
}
function loadCSS(items) {
for (const item of items) {
loadCSSItem(item);
}
}
class Hook {

@@ -670,2 +761,34 @@ constructor() {

function createViewHooks() {
return {
transformHtml: new Hook()
};
}
const refreshPromises = [];
function registerRefreshPromise(promise) {
refreshPromises.push(promise);
}
function onPromiseResolve(promises, callback) {
let scheduled;
const callbackSoon = () => {
if (!scheduled) {
scheduled = Promise.resolve().then(() => {
scheduled = undefined;
callback();
}).catch(noop);
}
};
promises.forEach(promise => {
promise.then(callbackSoon, noop).then(() => {
// No need to wait for the promise in the future
const i = promises.indexOf(promise);
if (i >= 0) promises.splice(i, 1);
});
});
}
class Markmap {

@@ -679,5 +802,7 @@ constructor(svg, opts) {

this.zoom = void 0;
this.viewHooks = void 0;
['handleZoom', 'handleClick'].forEach(key => {
this[key] = this[key].bind(this);
});
this.viewHooks = createViewHooks();
this.svg = svg.datum ? svg : d3.select(svg);

@@ -803,3 +928,3 @@ this.styleNode = this.svg.append('style');

const nodes = arrayFrom(container.childNodes);
Markmap.transformHtml.call(this, nodes);
this.viewHooks.transformHtml.call(this, nodes);
walkTree(node, (item, next, parent) => {

@@ -985,2 +1110,5 @@ var _parent$p;

onPromiseResolve(refreshPromises, () => {
mm.setData();
});
return mm;

@@ -990,10 +1118,8 @@ }

}
Markmap.transformHtml = new Hook();
function markmap(svg, data, opts) {
return Markmap.create(svg, opts, data);
}
exports.Markmap = Markmap;
exports.markmap = markmap;
exports.loadCSS = loadCSS;
exports.loadJS = loadJS;
exports.registerRefreshPromise = registerRefreshPromise;
}(this.markmap = this.markmap || {}, d3));

4

dist/browser/view.min.js

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

/*! markmap-lib v0.9.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,a,h,c=new l(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))&&(h=i.length))for(n.children=new Array(h),a=h-1;a>=0;--a)u.push(r=n.children[a]=new l(i[a])),r.parent=n,r.depth=n.depth+1;return c.eachBefore(o)}function s(t){return t.children}function a(t){t.data=t.data.data}function o(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,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 i(this).eachBefore(a)}};const h=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function c(t){const e=Object.assign({},h,t);function n(t){const n=e[t];return"function"==typeof n?n:()=>n}function r(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 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=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(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(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),h=n.children||[],c=0===h.length?" ":`,${i}children: [${s}${h.map(r(s)).join(s)}${i}],${t}`;return`{ size: [${l.join(", ")}],${i}x: ${a}, y: ${o}${c}},`};return r("\n")(t)}}),r}c.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 s=(0===r?n.lExt:n.rExt).bottom;0!==r&&f(t,r,i);return[r+1,E(s,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,s=r+i+e.change;return e.relX+=s,[i,s]},[0,0])},f=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let s=r,a=r.relX,o=i,l=i.relX,h=!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&&h)&&(l+=r,g(i,r),x(t,e,n.index,r)),h=!1;const c=s.bottom,d=o.bottom;c<=d&&(s=y(s),s&&(a+=s.relX)),c>=d&&(o=m(o),o&&(l+=o.relX))}!s&&o?v(t,e,o,l):s&&!o&&z(t,e,s,a)},g=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},x=(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,y=t=>t.hasChildren?t.lastChild:t.rThr,v=(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},z=(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},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})}},E=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}},$=Math.random().toString(36).slice(2,8);let X=0;function b(){}function w(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 k(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 C(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach(t=>{t&&n.indexOf(t)<0&&n.push(t)}),n.join(" ")}function j(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=k(this.childNodes);return e&&(t=t.filter(t=>e(t))),t}}function O(t){const e=t.data;return Math.max(6-2*e.d,1.5)}class R{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,["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=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||(X+=1,`mm-${$}-${X}`)},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",C(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:r}=t;r.p=n({},r.p,{f:!(null==(e=r.p)?void 0:e.f)}),this.renderData(t.data)}initializeData(t){let e=0;const{nodeFont:r,color:i,nodeMinHeight:s}=this.options,{id:a}=this.state,o=document.createElement("div"),l=a+"-container";o.className=C(o.className,a+"-fo",l);const h=document.createElement("style");h.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(h,o),w(t,(t,r)=>{var s;t.c=null==(s=t.c)?void 0:s.map(t=>n({},t)),e+=1;const a=document.createElement("div");a.innerHTML=t.v,o.append(a),t.p=n({},t.p,{i:e,el:a}),i(t),r()});const c=k(o.childNodes);R.transformHtml.call(this,c),w(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),s)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()}),o.remove(),h.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: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){w(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(),x=e.min(p,t=>t.x-t.xSize/2),m=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:x,maxX:m,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,E=null!=(r=z.data.p.y0)?r:z.y,$=this.g.selectAll(j("g")).data(p,t=>t.data.p.k),X=$.enter().append("g").attr("transform",t=>`translate(${E+z.ySizeInner-t.ySizeInner},${S+z.xSize/2-t.xSize})`).on("click",this.handleClick),b=this.transition($.exit());b.select("rect").attr("width",0).attr("x",t=>t.ySizeInner),b.select("foreignObject").style("opacity",0),b.attr("transform",t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`).remove();const k=$.merge(X);this.transition(k).attr("transform",t=>`translate(${t.y},${t.x-t.xSize/2})`);const C=k.selectAll(j("rect")).data(t=>[t],t=>t.data.p.k).join(t=>t.append("rect").attr("x",t=>t.ySizeInner).attr("y",t=>t.xSize-O(t)/2).attr("width",0).attr("height",O),t=>t,t=>t.remove());this.transition(C).attr("x",-1).attr("width",t=>t.ySizeInner+2).attr("fill",t=>l(t.data));const R=k.selectAll(j("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(R).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 M=k.selectAll(j("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 I=this.g.selectAll(j("path")).data(f,t=>t.target.data.p.k).join(t=>{const e=[E+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(I).attr("stroke",t=>l(t.target.data)).attr("stroke-width",t=>O(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,h=l-o,c=a-s,d=Math.min(n/h*i,r/c*i,2),u=e.zoomIdentity.translate((n-h*d)/2-o*d,(r-c*d)/2-s*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(b)}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(b)}static create(t,e,n){const r=new R(t,e);return n&&(r.setData(n),r.fit()),r}}R.transformHtml=new 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)}},t.Markmap=R,t.markmap=function(t,e,n){return R.create(t,n,e)}}(this.markmap=this.markmap||{},d3);
/*! markmap-lib v0.9.1 | 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,h,c=new l(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))&&(h=i.length))for(n.children=new Array(h),o=h-1;o>=0;--o)u.push(r=n.children[o]=new l(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 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,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 h=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function c(t){const e=Object.assign({},h,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:Math.max(t.bottom,e.bottom),left:Math.min(t.left,e.left),right:Math.max(t.right,e.right)}}}}function o(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 o=n(e)||[];return s.children=0===o.length?null:o.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(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 o(s(),t,r)},dump(t){const e=n("nodeSize"),r=t=>n=>{const i=t+" ",s=t+" ",{x:o,y:a}=n,l=e(n),h=n.children||[],c=0===h.length?" ":`,${i}children: [${s}${h.map(r(s)).join(s)}${i}],${t}`;return`{ size: [${l.join(", ")}],${i}x: ${o}, y: ${a}${c}},`};return r("\n")(t)}}),r}c.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 s=(0===r?n.lExt:n.rExt).bottom;0!==r&&f(t,r,i);return[r+1,E(s,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,s=r+i+e.change;return e.relX+=s,[i,s]},[0,0])},f=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let s=r,o=r.relX,a=i,l=i.relX,h=!0;for(;s&&a;){s.bottom>n.lowY&&(n=n.next);const r=o+s.prelim-(l+a.prelim)+s.xSize/2+a.xSize/2+s.spacing(a);(r>0||r<0&&h)&&(l+=r,g(i,r),m(t,e,n.index,r)),h=!1;const c=s.bottom,d=a.bottom;c<=d&&(s=y(s),s&&(o+=s.relX)),c>=d&&(a=x(a),a&&(l+=a.relX))}!s&&a?v(t,e,a,l):s&&!a&&z(t,e,s,o)},g=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},m=(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}},x=t=>t.hasChildren?t.firstChild:t.lThr,y=t=>t.hasChildren?t.lastChild:t.rThr,v=(t,e,n,r)=>{const i=t.firstChild,s=i.lExt,o=t.children[e];s.lThr=n;const a=r-n.relX-i.lExtRelX;s.relX+=a,s.prelim-=a,i.lExt=o.lExt,i.lExtRelX=o.lExtRelX},z=(t,e,n,r)=>{const i=t.children[e],s=i.rExt,o=t.children[e-1];s.rThr=n;const a=r-n.relX-i.rExtRelX;s.relX+=a,s.prelim-=a,i.rExt=o.rExt,i.rExtRelX=o.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})}},E=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}},$=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 k(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 C(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach(t=>{t&&n.indexOf(t)<0&&n.push(t)}),n.join(" ")}function j(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=k(this.childNodes);return e&&(t=t.filter(t=>e(t))),t}}function O(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 R=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(O("link",{rel:"preload",as:"script",href:t}))});function M(t,e){if("script"===t.type)return new Promise((e,r)=>{document.head.append(O("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 I(t){"style"===t.type?document.head.append(O("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(O("link",n({rel:"stylesheet"},t.data)))}class A{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 H(t){const e=t.data;return Math.max(6-2*e.d,1.5)}const B=[];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,["handleZoom","handleClick"].forEach(t=>{this[t]=this[t].bind(this)}),this.viewHooks={transformHtml:new A},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-${$}-${w}`)},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",C(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:r}=t;r.p=n({},r.p,{f:!(null==(e=r.p)?void 0:e.f)}),this.renderData(t.data)}initializeData(t){let e=0;const{nodeFont:r,color:i,nodeMinHeight:s}=this.options,{id:o}=this.state,a=document.createElement("div"),l=o+"-container";a.className=C(a.className,o+"-fo",l);const h=document.createElement("style");h.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(h,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 c=k(a.childNodes);this.viewHooks.transformHtml.call(this,c),b(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),s)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()}),a.remove(),h.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:s,spacingVertical:o,autoFit:a,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?o:2*o),u=d.hierarchy(this.state.data);d(u),function(t,e){b(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}),a&&this.fit();const z=t&&p.find(e=>e.data===t)||u,S=null!=(n=z.data.p.x0)?n:z.x,E=null!=(r=z.data.p.y0)?r:z.y,$=this.g.selectAll(j("g")).data(p,t=>t.data.p.k),w=$.enter().append("g").attr("transform",t=>`translate(${E+z.ySizeInner-t.ySizeInner},${S+z.xSize/2-t.xSize})`).on("click",this.handleClick),X=this.transition($.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 k=$.merge(w);this.transition(k).attr("transform",t=>`translate(${t.y},${t.x-t.xSize/2})`);const C=k.selectAll(j("rect")).data(t=>[t],t=>t.data.p.k).join(t=>t.append("rect").attr("x",t=>t.ySizeInner).attr("y",t=>t.xSize-H(t)/2).attr("width",0).attr("height",H),t=>t,t=>t.remove());this.transition(C).attr("x",-1).attr("width",t=>t.ySizeInner+2).attr("fill",t=>l(t.data));const O=k.selectAll(j("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(O).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 R=k.selectAll(j("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(R).style("opacity",1);const M=this.g.selectAll(j("path")).data(f,t=>t.target.data.p.k).join(t=>{const e=[E+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(M).attr("stroke",t=>l(t.target.data)).attr("stroke-width",t=>H(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:o,minY:a,maxY:l}=this.state,h=l-a,c=o-s,d=Math.min(n/h*i,r/c*i,2),u=e.zoomIdentity.translate((n-h*d)/2-a*d,(r-c*d)/2-s*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(X)}rescale(t){const n=this.svg.node(),{width:r,height:i}=n.getBoundingClientRect(),s=r/2,o=i/2,a=e.zoomTransform(n),l=a.translate((s-a.x)*(1-t)/a.k,(o-a.y)*(1-t)/a.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,l).end().catch(X)}static create(t,e,n){const r=new N(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(X))};t.forEach(e=>{e.then(r,X).then(()=>{const n=t.indexOf(e);n>=0&&t.splice(n,1)})})}(B,()=>{r.setData()}),r}}t.Markmap=N,t.loadCSS=function(t){for(const e of t)I(e)},t.loadJS=async function(t,e){const r=t.filter(t=>"script"===t.type);r.length>1&&r.forEach(t=>R(t.data.src)),e=n({getMarkmap:()=>window.markmap},e);for(const n of t)await M(n,e)},t.registerRefreshPromise=function(t){B.push(t)}}(this.markmap=this.markmap||{},d3);

@@ -35,3 +35,5 @@ "use strict";

data: {
fn: () => {
fn: (defer, getMarkmap) => {
const deferred = defer();
getMarkmap().registerRefreshPromise(deferred.promise);
window.WebFontConfig = {

@@ -42,6 +44,13 @@ custom: {

active: () => {
window.mm.setData();
deferred.resolve();
}
};
},
getParams({
getMarkmap
}) {
return [_util.defer, getMarkmap];
}
}

@@ -48,0 +57,0 @@ }, {

@@ -9,3 +9,3 @@ "use strict";

const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n";
const version = "0.9.0";
const version = "0.9.1";
const baseJs = ['https://cdn.jsdelivr.net/npm/d3@5', `https://cdn.jsdelivr.net/npm/markmap-lib@${version}/dist/browser/view.min.js`].map(src => ({

@@ -24,34 +24,25 @@ type: 'script',

const cssList = [...(styles ? (0, _util.persistCSS)(styles) : [])];
const jsList = [...(0, _util.persistJS)(baseJs), ...(scripts ? (0, _util.persistJS)(scripts) : []), ...(0, _util.persistJS)([{
const context = {
getMarkmap: () => window.markmap,
data
};
const jsList = [...(0, _util.persistJS)(baseJs), ...(scripts ? (0, _util.persistJS)(scripts, context) : []), ...(0, _util.persistJS)([{
type: 'iife',
data: {
fn: (data, init, items, opts) => {
fn: (getMarkmap, data) => {
const {
Markmap,
loadPlugins
} = window.markmap;
(init ? init(loadPlugins, items, opts) : Promise.resolve()).then(() => {
window.mm = Markmap.create('svg#mindmap', null, data);
});
Markmap
} = getMarkmap();
window.mm = Markmap.create('svg#mindmap', null, data);
},
getParams: ({
data,
opts
getMarkmap,
data
}) => {
const items = [(opts == null ? void 0 : opts.mathJax) && 'mathJax', (opts == null ? void 0 : opts.prism) && 'prism'].filter(Boolean);
const args = [data];
if (items.length) {
args.push((loadPlugins, items, opts) => loadPlugins(items, opts), items, opts);
}
return args;
return [getMarkmap, data];
}
}
}], {
data,
opts
})];
}], context)];
const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
return html;
}

@@ -12,2 +12,3 @@ "use strict";

exports.wrapFunction = wrapFunction;
exports.defer = defer;
const uniqId = Math.random().toString(36).slice(2, 8);

@@ -105,2 +106,11 @@ let globalIndex = 0;

};
}
function defer() {
const obj = {};
obj.promise = new Promise((resolve, reject) => {
obj.resolve = resolve;
obj.reject = reject;
});
return obj;
}

@@ -17,3 +17,3 @@ "use strict";

function buildCode(fn, ...args) {
function buildCode(fn, args) {
const params = args.map(arg => {

@@ -100,8 +100,11 @@ if (typeof arg === 'function') return arg.toString();

async function loadJS(items, options) {
async function loadJS(items, context) {
const needPreload = items.filter(item => item.type === 'script');
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
context = (0, _extends2.default)({
getMarkmap: () => window.markmap
}, context);
for (const item of items) {
await loadJSItem(item, options);
await loadJSItem(item, context);
}

@@ -125,3 +128,3 @@ }

} = item.data;
return (0, _html.wrapHtml)('script', (0, _html.escapeScript)(buildCode(fn, ...((getParams == null ? void 0 : getParams(context)) || []))));
return (0, _html.wrapHtml)('script', (0, _html.escapeScript)(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || [])));
}

@@ -128,0 +131,0 @@

@@ -8,4 +8,4 @@ "use strict";

exports.__esModule = true;
exports.markmap = markmap;
exports.Markmap = void 0;
exports.registerRefreshPromise = registerRefreshPromise;
exports.Markmap = exports.loadCSS = exports.loadJS = void 0;

@@ -20,2 +20,5 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

exports.loadJS = _util.loadJS;
exports.loadCSS = _util.loadCSS;
var _hook = require("./util/hook");

@@ -36,2 +39,35 @@

function createViewHooks() {
return {
transformHtml: new _hook.Hook()
};
}
const refreshPromises = [];
function registerRefreshPromise(promise) {
refreshPromises.push(promise);
}
function onPromiseResolve(promises, callback) {
let scheduled;
const callbackSoon = () => {
if (!scheduled) {
scheduled = Promise.resolve().then(() => {
scheduled = undefined;
callback();
}).catch(_util.noop);
}
};
promises.forEach(promise => {
promise.then(callbackSoon, _util.noop).then(() => {
// No need to wait for the promise in the future
const i = promises.indexOf(promise);
if (i >= 0) promises.splice(i, 1);
});
});
}
class Markmap {

@@ -45,5 +81,7 @@ constructor(svg, opts) {

this.zoom = void 0;
this.viewHooks = void 0;
['handleZoom', 'handleClick'].forEach(key => {
this[key] = this[key].bind(this);
});
this.viewHooks = createViewHooks();
this.svg = svg.datum ? svg : d3.select(svg);

@@ -169,3 +207,3 @@ this.styleNode = this.svg.append('style');

const nodes = (0, _util.arrayFrom)(container.childNodes);
Markmap.transformHtml.call(this, nodes);
this.viewHooks.transformHtml.call(this, nodes);
(0, _util.walkTree)(node, (item, next, parent) => {

@@ -351,2 +389,5 @@ var _parent$p;

onPromiseResolve(refreshPromises, () => {
mm.setData();
});
return mm;

@@ -357,7 +398,2 @@ }

exports.Markmap = Markmap;
Markmap.transformHtml = new _hook.Hook();
function markmap(svg, data, opts) {
return Markmap.create(svg, opts, data);
}
exports.Markmap = Markmap;
{
"name": "markmap-lib",
"version": "0.9.0",
"version": "0.9.1",
"description": "Visualize your Markdown as mindmaps with Markmap",

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

},
"gitHead": "88a9287c44f037890641a11bd67950655693900e"
"gitHead": "74930de1e1fe2228f479ae636dc8b7142444998f"
}

@@ -32,8 +32,15 @@ # markmap-lib

```js
import { transform } from 'markmap-lib/dist/transform';
import { transform, getUsedAssets, getUsed } from 'markmap-lib/dist/transform';
const data = transform(markdown);
// 1. transform markdown
const { root, features } = transform(markdown);
// 2. get assets
// either get assets required by used features
const { styles, scripts } = getUsedAssets(features);
// or get all possible assets that could be used later
const { styles, scripts } = getUsed(features);
```
Now we get the data for rendering in `data`.
Now we have the data for rendering.

@@ -47,2 +54,4 @@ ### Render

```html
<script src="https://cdn.jsdelivr.net/npm/markmap-lib/dist/browser/view.min.js"></script>
<svg id="markmap" style="width: 800px; height: 800px"></svg>

@@ -54,6 +63,14 @@ ```

```js
import { Markmap } from 'markmap-lib/dist/view';
// We got { root } data from transforming, and possible extraneous assets { styles, scripts }.
Markmap.create('#markmap', null, data);
const { Markmap, loadCSS, loadJS } = window.markmap;
// 1. load assets
if (styles) loadCSS(styles);
if (scripts) loadJS(scripts, { getMarkmap: () => window.markmap });
// 2. create markmap
Markmap.create('#markmap', null, root);
// or pass an SVG element directly

@@ -60,0 +77,0 @@ const svgEl = document.querySelector('#markmap');

@@ -113,1 +113,6 @@ import { IMarkmap } from './view';

}
export interface IDeferred<T> {
promise: Promise<T>;
resolve: (value?: any) => void;
reject: (error?: any) => void;
}

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

import { IWrapContext } from '../types';
import { IWrapContext, IDeferred } from '../types';
export declare function getId(): string;

@@ -13,1 +13,2 @@ export declare function noop(): void;

}): T;
export declare function defer<T>(): IDeferred<T>;
import { JSItem, CSSItem } from '../types';
export declare function buildCode(fn: Function, ...args: any[]): string;
export declare function buildCode(fn: Function, args: any[]): string;
export declare function memoize<T extends (...args: any[]) => any>(fn: T): T;
export declare function loadJS(items: JSItem[], options: any): Promise<void>;
export declare function loadJS(items: JSItem[], context: any): Promise<void>;
export declare function loadCSS(items: CSSItem[]): void;
export declare function persistJS(items: JSItem[], context?: any): string[];
export declare function persistCSS(items: CSSItem[]): string[];
import * as d3 from 'd3';
import { INode, IMarkmapOptions, IMarkmapState, IMarkmapFlexTreeItem } from './types';
import { Hook } from './util/hook';
export { loadJS, loadCSS } from './util';
declare type ID3SVGElement = d3.Selection<SVGElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>;
declare function createViewHooks(): {
transformHtml: Hook<(mm: Markmap, nodes: HTMLElement[]) => void>;
};
export declare function registerRefreshPromise(promise: Promise<any>): void;
export declare class Markmap {

@@ -12,3 +17,3 @@ options: IMarkmapOptions;

zoom: d3.ZoomBehavior<Element, unknown>;
static transformHtml: Hook<(mm: Markmap, nodes: HTMLElement[]) => void>;
viewHooks: ReturnType<typeof createViewHooks>;
constructor(svg: string | SVGElement | ID3SVGElement, opts?: IMarkmapOptions);

@@ -29,3 +34,1 @@ getStyleContent(): string;

export declare type IMarkmap = typeof Markmap;
export declare function markmap(svg: string | SVGElement | ID3SVGElement, data?: INode, opts?: IMarkmapOptions): Markmap;
export {};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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