markmap-cli 0.18.8 → 0.18.10-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/bin/cli.js +1 -6
  2. package/dist/assets/@highlightjs/cdn-assets@11.11.1/styles/default.min.css +9 -0
  3. package/dist/assets/d3@7.9.0/dist/d3.min.js +2 -0
  4. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  5. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  6. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  7. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  8. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  9. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
  10. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  11. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
  12. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
  13. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  14. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
  15. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  16. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  17. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  18. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
  19. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  20. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  21. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  22. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  23. package/dist/assets/katex@0.16.18/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  24. package/dist/assets/katex@0.16.18/dist/katex.min.css +1 -0
  25. package/dist/assets/markmap-toolbar@0.18.10-alpha.2+9487f11/dist/index.js +281 -0
  26. package/dist/assets/markmap-toolbar@0.18.10-alpha.2+9487f11/dist/style.css +37 -0
  27. package/dist/assets/markmap-view@0.18.10-alpha.2+9487f11/dist/browser/index.js +1482 -0
  28. package/dist/assets/webfontloader@1.6.28/webfontloader.js +17 -0
  29. package/dist/cli.d.ts +1 -0
  30. package/dist/cli.js +55 -0
  31. package/dist/common-CwPtCJvD.js +61 -0
  32. package/dist/fetch-assets.d.ts +1 -1
  33. package/dist/fetch-assets.js +81 -0
  34. package/dist/index.d.ts +3 -5
  35. package/dist/index.js +7 -160
  36. package/dist/{dev-server.d.ts → util/dev-server.d.ts} +1 -1
  37. package/package.json +9 -9
  38. /package/dist/{util.d.ts → util/common.d.ts} +0 -0
@@ -0,0 +1,17 @@
1
+ /* Web Font Loader v1.6.28 - (c) Adobe Systems, Google. License: Apache 2.0 */(function(){function aa(a,b,c){return a.call.apply(a.bind,arguments)}function ba(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function p(a,b,c){p=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?aa:ba;return p.apply(null,arguments)}var q=Date.now||function(){return+new Date};function ca(a,b){this.a=a;this.o=b||a;this.c=this.o.document}var da=!!window.FontFace;function t(a,b,c,d){b=a.c.createElement(b);if(c)for(var e in c)c.hasOwnProperty(e)&&("style"==e?b.style.cssText=c[e]:b.setAttribute(e,c[e]));d&&b.appendChild(a.c.createTextNode(d));return b}function u(a,b,c){a=a.c.getElementsByTagName(b)[0];a||(a=document.documentElement);a.insertBefore(c,a.lastChild)}function v(a){a.parentNode&&a.parentNode.removeChild(a)}
2
+ function w(a,b,c){b=b||[];c=c||[];for(var d=a.className.split(/\s+/),e=0;e<b.length;e+=1){for(var f=!1,g=0;g<d.length;g+=1)if(b[e]===d[g]){f=!0;break}f||d.push(b[e])}b=[];for(e=0;e<d.length;e+=1){f=!1;for(g=0;g<c.length;g+=1)if(d[e]===c[g]){f=!0;break}f||b.push(d[e])}a.className=b.join(" ").replace(/\s+/g," ").replace(/^\s+|\s+$/,"")}function y(a,b){for(var c=a.className.split(/\s+/),d=0,e=c.length;d<e;d++)if(c[d]==b)return!0;return!1}
3
+ function ea(a){return a.o.location.hostname||a.a.location.hostname}function z(a,b,c){function d(){m&&e&&f&&(m(g),m=null)}b=t(a,"link",{rel:"stylesheet",href:b,media:"all"});var e=!1,f=!0,g=null,m=c||null;da?(b.onload=function(){e=!0;d()},b.onerror=function(){e=!0;g=Error("Stylesheet failed to load");d()}):setTimeout(function(){e=!0;d()},0);u(a,"head",b)}
4
+ function A(a,b,c,d){var e=a.c.getElementsByTagName("head")[0];if(e){var f=t(a,"script",{src:b}),g=!1;f.onload=f.onreadystatechange=function(){g||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState||(g=!0,c&&c(null),f.onload=f.onreadystatechange=null,"HEAD"==f.parentNode.tagName&&e.removeChild(f))};e.appendChild(f);setTimeout(function(){g||(g=!0,c&&c(Error("Script load timeout")))},d||5E3);return f}return null};function B(){this.a=0;this.c=null}function C(a){a.a++;return function(){a.a--;D(a)}}function E(a,b){a.c=b;D(a)}function D(a){0==a.a&&a.c&&(a.c(),a.c=null)};function F(a){this.a=a||"-"}F.prototype.c=function(a){for(var b=[],c=0;c<arguments.length;c++)b.push(arguments[c].replace(/[\W_]+/g,"").toLowerCase());return b.join(this.a)};function G(a,b){this.c=a;this.f=4;this.a="n";var c=(b||"n4").match(/^([nio])([1-9])$/i);c&&(this.a=c[1],this.f=parseInt(c[2],10))}function fa(a){return H(a)+" "+(a.f+"00")+" 300px "+I(a.c)}function I(a){var b=[];a=a.split(/,\s*/);for(var c=0;c<a.length;c++){var d=a[c].replace(/['"]/g,"");-1!=d.indexOf(" ")||/^\d/.test(d)?b.push("'"+d+"'"):b.push(d)}return b.join(",")}function J(a){return a.a+a.f}function H(a){var b="normal";"o"===a.a?b="oblique":"i"===a.a&&(b="italic");return b}
5
+ function ga(a){var b=4,c="n",d=null;a&&((d=a.match(/(normal|oblique|italic)/i))&&d[1]&&(c=d[1].substr(0,1).toLowerCase()),(d=a.match(/([1-9]00|normal|bold)/i))&&d[1]&&(/bold/i.test(d[1])?b=7:/[1-9]00/.test(d[1])&&(b=parseInt(d[1].substr(0,1),10))));return c+b};function ha(a,b){this.c=a;this.f=a.o.document.documentElement;this.h=b;this.a=new F("-");this.j=!1!==b.events;this.g=!1!==b.classes}function ia(a){a.g&&w(a.f,[a.a.c("wf","loading")]);K(a,"loading")}function L(a){if(a.g){var b=y(a.f,a.a.c("wf","active")),c=[],d=[a.a.c("wf","loading")];b||c.push(a.a.c("wf","inactive"));w(a.f,c,d)}K(a,"inactive")}function K(a,b,c){if(a.j&&a.h[b])if(c)a.h[b](c.c,J(c));else a.h[b]()};function ja(){this.c={}}function ka(a,b,c){var d=[],e;for(e in b)if(b.hasOwnProperty(e)){var f=a.c[e];f&&d.push(f(b[e],c))}return d};function M(a,b){this.c=a;this.f=b;this.a=t(this.c,"span",{"aria-hidden":"true"},this.f)}function N(a){u(a.c,"body",a.a)}function O(a){return"display:block;position:absolute;top:-9999px;left:-9999px;font-size:300px;width:auto;height:auto;line-height:normal;margin:0;padding:0;font-variant:normal;white-space:nowrap;font-family:"+I(a.c)+";"+("font-style:"+H(a)+";font-weight:"+(a.f+"00")+";")};function P(a,b,c,d,e,f){this.g=a;this.j=b;this.a=d;this.c=c;this.f=e||3E3;this.h=f||void 0}P.prototype.start=function(){var a=this.c.o.document,b=this,c=q(),d=new Promise(function(d,e){function f(){q()-c>=b.f?e():a.fonts.load(fa(b.a),b.h).then(function(a){1<=a.length?d():setTimeout(f,25)},function(){e()})}f()}),e=null,f=new Promise(function(a,d){e=setTimeout(d,b.f)});Promise.race([f,d]).then(function(){e&&(clearTimeout(e),e=null);b.g(b.a)},function(){b.j(b.a)})};function Q(a,b,c,d,e,f,g){this.v=a;this.B=b;this.c=c;this.a=d;this.s=g||"BESbswy";this.f={};this.w=e||3E3;this.u=f||null;this.m=this.j=this.h=this.g=null;this.g=new M(this.c,this.s);this.h=new M(this.c,this.s);this.j=new M(this.c,this.s);this.m=new M(this.c,this.s);a=new G(this.a.c+",serif",J(this.a));a=O(a);this.g.a.style.cssText=a;a=new G(this.a.c+",sans-serif",J(this.a));a=O(a);this.h.a.style.cssText=a;a=new G("serif",J(this.a));a=O(a);this.j.a.style.cssText=a;a=new G("sans-serif",J(this.a));a=
6
+ O(a);this.m.a.style.cssText=a;N(this.g);N(this.h);N(this.j);N(this.m)}var R={D:"serif",C:"sans-serif"},S=null;function T(){if(null===S){var a=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent);S=!!a&&(536>parseInt(a[1],10)||536===parseInt(a[1],10)&&11>=parseInt(a[2],10))}return S}Q.prototype.start=function(){this.f.serif=this.j.a.offsetWidth;this.f["sans-serif"]=this.m.a.offsetWidth;this.A=q();U(this)};
7
+ function la(a,b,c){for(var d in R)if(R.hasOwnProperty(d)&&b===a.f[R[d]]&&c===a.f[R[d]])return!0;return!1}function U(a){var b=a.g.a.offsetWidth,c=a.h.a.offsetWidth,d;(d=b===a.f.serif&&c===a.f["sans-serif"])||(d=T()&&la(a,b,c));d?q()-a.A>=a.w?T()&&la(a,b,c)&&(null===a.u||a.u.hasOwnProperty(a.a.c))?V(a,a.v):V(a,a.B):ma(a):V(a,a.v)}function ma(a){setTimeout(p(function(){U(this)},a),50)}function V(a,b){setTimeout(p(function(){v(this.g.a);v(this.h.a);v(this.j.a);v(this.m.a);b(this.a)},a),0)};function W(a,b,c){this.c=a;this.a=b;this.f=0;this.m=this.j=!1;this.s=c}var X=null;W.prototype.g=function(a){var b=this.a;b.g&&w(b.f,[b.a.c("wf",a.c,J(a).toString(),"active")],[b.a.c("wf",a.c,J(a).toString(),"loading"),b.a.c("wf",a.c,J(a).toString(),"inactive")]);K(b,"fontactive",a);this.m=!0;na(this)};
8
+ W.prototype.h=function(a){var b=this.a;if(b.g){var c=y(b.f,b.a.c("wf",a.c,J(a).toString(),"active")),d=[],e=[b.a.c("wf",a.c,J(a).toString(),"loading")];c||d.push(b.a.c("wf",a.c,J(a).toString(),"inactive"));w(b.f,d,e)}K(b,"fontinactive",a);na(this)};function na(a){0==--a.f&&a.j&&(a.m?(a=a.a,a.g&&w(a.f,[a.a.c("wf","active")],[a.a.c("wf","loading"),a.a.c("wf","inactive")]),K(a,"active")):L(a.a))};function oa(a){this.j=a;this.a=new ja;this.h=0;this.f=this.g=!0}oa.prototype.load=function(a){this.c=new ca(this.j,a.context||this.j);this.g=!1!==a.events;this.f=!1!==a.classes;pa(this,new ha(this.c,a),a)};
9
+ function qa(a,b,c,d,e){var f=0==--a.h;(a.f||a.g)&&setTimeout(function(){var a=e||null,m=d||null||{};if(0===c.length&&f)L(b.a);else{b.f+=c.length;f&&(b.j=f);var h,l=[];for(h=0;h<c.length;h++){var k=c[h],n=m[k.c],r=b.a,x=k;r.g&&w(r.f,[r.a.c("wf",x.c,J(x).toString(),"loading")]);K(r,"fontloading",x);r=null;if(null===X)if(window.FontFace){var x=/Gecko.*Firefox\/(\d+)/.exec(window.navigator.userAgent),xa=/OS X.*Version\/10\..*Safari/.exec(window.navigator.userAgent)&&/Apple/.exec(window.navigator.vendor);
10
+ X=x?42<parseInt(x[1],10):xa?!1:!0}else X=!1;X?r=new P(p(b.g,b),p(b.h,b),b.c,k,b.s,n):r=new Q(p(b.g,b),p(b.h,b),b.c,k,b.s,a,n);l.push(r)}for(h=0;h<l.length;h++)l[h].start()}},0)}function pa(a,b,c){var d=[],e=c.timeout;ia(b);var d=ka(a.a,c,a.c),f=new W(a.c,b,e);a.h=d.length;b=0;for(c=d.length;b<c;b++)d[b].load(function(b,d,c){qa(a,f,b,d,c)})};function ra(a,b){this.c=a;this.a=b}
11
+ ra.prototype.load=function(a){function b(){if(f["__mti_fntLst"+d]){var c=f["__mti_fntLst"+d](),e=[],h;if(c)for(var l=0;l<c.length;l++){var k=c[l].fontfamily;void 0!=c[l].fontStyle&&void 0!=c[l].fontWeight?(h=c[l].fontStyle+c[l].fontWeight,e.push(new G(k,h))):e.push(new G(k))}a(e)}else setTimeout(function(){b()},50)}var c=this,d=c.a.projectId,e=c.a.version;if(d){var f=c.c.o;A(this.c,(c.a.api||"https://fast.fonts.net/jsapi")+"/"+d+".js"+(e?"?v="+e:""),function(e){e?a([]):(f["__MonotypeConfiguration__"+
12
+ d]=function(){return c.a},b())}).id="__MonotypeAPIScript__"+d}else a([])};function sa(a,b){this.c=a;this.a=b}sa.prototype.load=function(a){var b,c,d=this.a.urls||[],e=this.a.families||[],f=this.a.testStrings||{},g=new B;b=0;for(c=d.length;b<c;b++)z(this.c,d[b],C(g));var m=[];b=0;for(c=e.length;b<c;b++)if(d=e[b].split(":"),d[1])for(var h=d[1].split(","),l=0;l<h.length;l+=1)m.push(new G(d[0],h[l]));else m.push(new G(d[0]));E(g,function(){a(m,f)})};function ta(a,b){a?this.c=a:this.c=ua;this.a=[];this.f=[];this.g=b||""}var ua="https://fonts.googleapis.com/css";function va(a,b){for(var c=b.length,d=0;d<c;d++){var e=b[d].split(":");3==e.length&&a.f.push(e.pop());var f="";2==e.length&&""!=e[1]&&(f=":");a.a.push(e.join(f))}}
13
+ function wa(a){if(0==a.a.length)throw Error("No fonts to load!");if(-1!=a.c.indexOf("kit="))return a.c;for(var b=a.a.length,c=[],d=0;d<b;d++)c.push(a.a[d].replace(/ /g,"+"));b=a.c+"?family="+c.join("%7C");0<a.f.length&&(b+="&subset="+a.f.join(","));0<a.g.length&&(b+="&text="+encodeURIComponent(a.g));return b};function ya(a){this.f=a;this.a=[];this.c={}}
14
+ var za={latin:"BESbswy","latin-ext":"\u00e7\u00f6\u00fc\u011f\u015f",cyrillic:"\u0439\u044f\u0416",greek:"\u03b1\u03b2\u03a3",khmer:"\u1780\u1781\u1782",Hanuman:"\u1780\u1781\u1782"},Aa={thin:"1",extralight:"2","extra-light":"2",ultralight:"2","ultra-light":"2",light:"3",regular:"4",book:"4",medium:"5","semi-bold":"6",semibold:"6","demi-bold":"6",demibold:"6",bold:"7","extra-bold":"8",extrabold:"8","ultra-bold":"8",ultrabold:"8",black:"9",heavy:"9",l:"3",r:"4",b:"7"},Ba={i:"i",italic:"i",n:"n",normal:"n"},
15
+ Ca=/^(thin|(?:(?:extra|ultra)-?)?light|regular|book|medium|(?:(?:semi|demi|extra|ultra)-?)?bold|black|heavy|l|r|b|[1-9]00)?(n|i|normal|italic)?$/;
16
+ function Da(a){for(var b=a.f.length,c=0;c<b;c++){var d=a.f[c].split(":"),e=d[0].replace(/\+/g," "),f=["n4"];if(2<=d.length){var g;var m=d[1];g=[];if(m)for(var m=m.split(","),h=m.length,l=0;l<h;l++){var k;k=m[l];if(k.match(/^[\w-]+$/)){var n=Ca.exec(k.toLowerCase());if(null==n)k="";else{k=n[2];k=null==k||""==k?"n":Ba[k];n=n[1];if(null==n||""==n)n="4";else var r=Aa[n],n=r?r:isNaN(n)?"4":n.substr(0,1);k=[k,n].join("")}}else k="";k&&g.push(k)}0<g.length&&(f=g);3==d.length&&(d=d[2],g=[],d=d?d.split(","):
17
+ g,0<d.length&&(d=za[d[0]])&&(a.c[e]=d))}a.c[e]||(d=za[e])&&(a.c[e]=d);for(d=0;d<f.length;d+=1)a.a.push(new G(e,f[d]))}};function Ea(a,b){this.c=a;this.a=b}var Fa={Arimo:!0,Cousine:!0,Tinos:!0};Ea.prototype.load=function(a){var b=new B,c=this.c,d=new ta(this.a.api,this.a.text),e=this.a.families;va(d,e);var f=new ya(e);Da(f);z(c,wa(d),C(b));E(b,function(){a(f.a,f.c,Fa)})};function Ga(a,b){this.c=a;this.a=b}Ga.prototype.load=function(a){var b=this.a.id,c=this.c.o;b?A(this.c,(this.a.api||"https://use.typekit.net")+"/"+b+".js",function(b){if(b)a([]);else if(c.Typekit&&c.Typekit.config&&c.Typekit.config.fn){b=c.Typekit.config.fn;for(var e=[],f=0;f<b.length;f+=2)for(var g=b[f],m=b[f+1],h=0;h<m.length;h++)e.push(new G(g,m[h]));try{c.Typekit.load({events:!1,classes:!1,async:!0})}catch(l){}a(e)}},2E3):a([])};function Ha(a,b){this.c=a;this.f=b;this.a=[]}Ha.prototype.load=function(a){var b=this.f.id,c=this.c.o,d=this;b?(c.__webfontfontdeckmodule__||(c.__webfontfontdeckmodule__={}),c.__webfontfontdeckmodule__[b]=function(b,c){for(var g=0,m=c.fonts.length;g<m;++g){var h=c.fonts[g];d.a.push(new G(h.name,ga("font-weight:"+h.weight+";font-style:"+h.style)))}a(d.a)},A(this.c,(this.f.api||"https://f.fontdeck.com/s/css/js/")+ea(this.c)+"/"+b+".js",function(b){b&&a([])})):a([])};var Y=new oa(window);Y.a.c.custom=function(a,b){return new sa(b,a)};Y.a.c.fontdeck=function(a,b){return new Ha(b,a)};Y.a.c.monotype=function(a,b){return new ra(b,a)};Y.a.c.typekit=function(a,b){return new Ga(b,a)};Y.a.c.google=function(a,b){return new Ea(b,a)};var Z={load:p(Y.load,Y)};"function"===typeof define&&define.amd?define(function(){return Z}):"undefined"!==typeof module&&module.exports?module.exports=Z:(window.WebFont=Z,window.WebFontConfig&&Y.load(window.WebFontConfig));}());
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,55 @@
1
+ import { program } from "commander";
2
+ import { readFile } from "fs/promises";
3
+ import open from "open";
4
+ import { basename } from "path";
5
+ import { readPackageUp } from "read-package-up";
6
+ import updateNotifier from "update-notifier";
7
+ import { fileURLToPath } from "url";
8
+ import { develop, createMarkmap } from "./index.js";
9
+ async function main() {
10
+ var _a;
11
+ const pkg = (_a = await readPackageUp({
12
+ cwd: fileURLToPath(import.meta.url)
13
+ })) == null ? void 0 : _a.packageJson;
14
+ if (!pkg) throw new Error("Invalid package");
15
+ const notifier = updateNotifier({ pkg });
16
+ notifier.notify();
17
+ program.version(pkg.version).description("Create a markmap from a Markdown input file").arguments("<input>").option("--no-open", "Do not open the output file after generation").option("--no-toolbar", "Do not show toolbar").option("-o, --output <output>", "Specify the filename of the output HTML").option(
18
+ "--offline",
19
+ "Inline all assets to allow the generated HTML to work offline"
20
+ ).option(
21
+ "-w, --watch",
22
+ "Watch the input file and update output on the fly, note that this feature is for development only"
23
+ ).option("--port <port>", "Set the port for the devServer to listen").action(async (input, cmd) => {
24
+ let { offline } = cmd;
25
+ if (cmd.watch) offline = true;
26
+ const content = await readFile(input, "utf8");
27
+ const output = cmd.output || `${input.replace(/\.\w*$/, "")}.html`;
28
+ if (cmd.watch) {
29
+ const devServer = await develop({
30
+ toolbar: cmd.toolbar,
31
+ offline,
32
+ port: +cmd.port || void 0
33
+ });
34
+ const address = devServer.serverInfo.address;
35
+ const provider = devServer.addProvider({ filePath: input });
36
+ const filename = basename(input);
37
+ const url = `http://localhost:${address.port}/?key=${provider.key}&filename=${encodeURIComponent(filename)}`;
38
+ console.log(`Listening at ${url}`);
39
+ if (cmd.open) open(url);
40
+ } else {
41
+ await createMarkmap({
42
+ content,
43
+ output,
44
+ open: cmd.open,
45
+ toolbar: cmd.toolbar,
46
+ offline
47
+ });
48
+ }
49
+ });
50
+ program.parse();
51
+ }
52
+ main().catch((err) => {
53
+ console.error(err);
54
+ process.exitCode = 1;
55
+ });
@@ -0,0 +1,61 @@
1
+ import { buildCSSItem, buildJSItem } from "markmap-common";
2
+ import { dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+ const TOOLBAR_VERSION = "0.18.10-alpha.2+9487f11";
5
+ const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
6
+ const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
7
+ const distDir = dirname(fileURLToPath(import.meta.url));
8
+ const ASSETS_PREFIX = "/assets/";
9
+ const renderToolbar = () => {
10
+ const { markmap, mm } = window;
11
+ const toolbar = new markmap.Toolbar();
12
+ toolbar.attach(mm);
13
+ const el = toolbar.render();
14
+ el.setAttribute("style", "position:absolute;bottom:20px;right:20px");
15
+ document.body.append(el);
16
+ };
17
+ const toolbarAssets = {
18
+ styles: [buildCSSItem(TOOLBAR_CSS)],
19
+ scripts: [
20
+ buildJSItem(TOOLBAR_JS),
21
+ {
22
+ type: "iife",
23
+ data: {
24
+ fn: (r) => {
25
+ setTimeout(r);
26
+ },
27
+ getParams: () => [renderToolbar]
28
+ }
29
+ }
30
+ ]
31
+ };
32
+ function localProvider(path) {
33
+ return `${ASSETS_PREFIX}${path}`;
34
+ }
35
+ function createStreamBody(stream) {
36
+ const body = new ReadableStream({
37
+ start(controller) {
38
+ stream.on("data", (chunk) => {
39
+ controller.enqueue(chunk);
40
+ });
41
+ stream.on("end", () => {
42
+ controller.close();
43
+ });
44
+ },
45
+ cancel() {
46
+ stream.destroy();
47
+ }
48
+ });
49
+ return body;
50
+ }
51
+ const config = {
52
+ distDir,
53
+ assetsDir: `${distDir}${ASSETS_PREFIX}`
54
+ };
55
+ export {
56
+ ASSETS_PREFIX as A,
57
+ config as a,
58
+ createStreamBody as c,
59
+ localProvider as l,
60
+ toolbarAssets as t
61
+ };
@@ -1 +1 @@
1
- export declare function fetchAssets(assetsDir?: string): Promise<void>;
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { createReadStream, createWriteStream } from "fs";
2
+ import { stat, mkdir } from "fs/promises";
3
+ import { extractAssets } from "markmap-common";
4
+ import { Transformer } from "markmap-lib";
5
+ import { baseJsPaths } from "markmap-render";
6
+ import { resolve, dirname } from "path";
7
+ import { pipeline } from "stream/promises";
8
+ import { l as localProvider, A as ASSETS_PREFIX, t as toolbarAssets, a as config, c as createStreamBody } from "./common-CwPtCJvD.js";
9
+ const providerName = "local-hook";
10
+ async function fetchAssets({
11
+ assetsDir = config.assetsDir,
12
+ verbose
13
+ } = {}) {
14
+ const transformer = new Transformer();
15
+ transformer.urlBuilder.setProvider(providerName, localProvider);
16
+ transformer.urlBuilder.provider = providerName;
17
+ const assets = transformer.getAssets();
18
+ delete transformer.urlBuilder.providers[providerName];
19
+ const pluginPaths = extractAssets(assets).filter((url) => url.startsWith(ASSETS_PREFIX)).map((url) => url.slice(ASSETS_PREFIX.length));
20
+ const resources = transformer.plugins.flatMap(
21
+ (plugin) => {
22
+ var _a;
23
+ return ((_a = plugin.config) == null ? void 0 : _a.resources) || [];
24
+ }
25
+ );
26
+ const paths = [
27
+ ...baseJsPaths,
28
+ ...pluginPaths,
29
+ ...resources,
30
+ ...extractAssets(toolbarAssets)
31
+ ];
32
+ const resolveDepPath = (path) => {
33
+ const parts = path.split("/");
34
+ const offset = parts[0].startsWith("@") ? 1 : 0;
35
+ parts[offset] = parts[offset].split("@")[0];
36
+ path = parts.join("/");
37
+ if (path.startsWith("d3")) {
38
+ path = "markmap-view/node_modules/" + path;
39
+ } else if (!path.startsWith("markmap-")) {
40
+ path = "markmap-lib/node_modules/" + path;
41
+ }
42
+ return resolve("..", path);
43
+ };
44
+ await Promise.all(
45
+ paths.map(async (path) => {
46
+ const fullPath = resolve(assetsDir, path);
47
+ let url;
48
+ await downloadAsset(fullPath, async () => url = resolveDepPath(path));
49
+ if (verbose) {
50
+ console.log(
51
+ url ? `Fetched: ${url} -> ${fullPath}` : `Skipped existing file: ${fullPath}`
52
+ );
53
+ }
54
+ })
55
+ );
56
+ }
57
+ async function downloadAsset(fullPath, resolveUrl) {
58
+ try {
59
+ const result = await stat(fullPath);
60
+ if (result.isFile()) return;
61
+ } catch {
62
+ }
63
+ const url = await resolveUrl();
64
+ let body;
65
+ if (url.startsWith("/")) {
66
+ body = createStreamBody(createReadStream(url));
67
+ } else {
68
+ const res = await fetch(url);
69
+ if (!res.ok || !res.body) throw new Error(`Failed to download: ${url}`);
70
+ body = res.body;
71
+ }
72
+ await mkdir(dirname(fullPath), { recursive: true });
73
+ await pipeline(body, createWriteStream(fullPath));
74
+ }
75
+ async function main() {
76
+ await fetchAssets({ verbose: true });
77
+ }
78
+ main().catch((err) => {
79
+ console.error(err);
80
+ process.exitCode = 1;
81
+ });
package/dist/index.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import { type IMarkmapCreateOptions } from 'markmap-lib';
2
- import { fetchAssets } from './fetch-assets';
3
2
  import { IDevelopOptions } from './types';
4
- import { config } from './util';
5
- export * from './dev-server';
3
+ import { config } from './util/common';
6
4
  export * from './types';
7
- export { config, fetchAssets };
5
+ export * from './util/dev-server';
6
+ export { config };
8
7
  export * as markmap from 'markmap-lib';
9
8
  export declare function createMarkmap(options: IMarkmapCreateOptions & IDevelopOptions & {
10
9
  open: boolean;
11
10
  }): Promise<void>;
12
- export declare function main(): Promise<void>;
package/dist/index.js CHANGED
@@ -1,22 +1,17 @@
1
- import { Command } from "commander";
2
- import { readFile, stat, mkdir, writeFile } from "fs/promises";
3
- import { buildCSSItem, buildJSItem, mergeAssets, defer, extractAssets } from "markmap-common";
1
+ import { readFile, stat, writeFile } from "fs/promises";
2
+ import { mergeAssets, defer, buildJSItem } from "markmap-common";
4
3
  import { Transformer } from "markmap-lib";
5
4
  import * as markmapLib from "markmap-lib";
6
5
  import { fillTemplate, baseJsPaths } from "markmap-render";
7
6
  import open from "open";
8
- import { dirname, join, resolve, basename } from "path";
9
- import { readPackageUp } from "read-package-up";
10
- import updateNotifier from "update-notifier";
11
- import { fileURLToPath } from "url";
7
+ import { join, resolve } from "path";
8
+ import { t as toolbarAssets, A as ASSETS_PREFIX, l as localProvider, c as createStreamBody, a as config } from "./common-CwPtCJvD.js";
12
9
  import { serve } from "@hono/node-server";
13
10
  import { watch } from "chokidar";
14
11
  import { createHash } from "crypto";
15
- import { createReadStream, createWriteStream } from "fs";
12
+ import { createReadStream } from "fs";
16
13
  import { Hono } from "hono";
17
14
  import { getPortPromise } from "portfinder";
18
- import { Readable } from "stream";
19
- import { finished } from "stream/promises";
20
15
  var getMimeType = (filename, mimes = baseMimes) => {
21
16
  const regexp = /\.([a-zA-Z0-9]+?)$/;
22
17
  const match = filename.match(regexp);
@@ -87,57 +82,6 @@ var _baseMimes = {
87
82
  glb: "model/gltf-binary"
88
83
  };
89
84
  var baseMimes = _baseMimes;
90
- const TOOLBAR_VERSION = "0.18.8";
91
- const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
92
- const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
93
- const distDir = dirname(fileURLToPath(import.meta.url));
94
- const ASSETS_PREFIX = "/assets/";
95
- const renderToolbar = () => {
96
- const { markmap, mm } = window;
97
- const toolbar = new markmap.Toolbar();
98
- toolbar.attach(mm);
99
- const el = toolbar.render();
100
- el.setAttribute("style", "position:absolute;bottom:20px;right:20px");
101
- document.body.append(el);
102
- };
103
- const toolbarAssets = {
104
- styles: [buildCSSItem(TOOLBAR_CSS)],
105
- scripts: [
106
- buildJSItem(TOOLBAR_JS),
107
- {
108
- type: "iife",
109
- data: {
110
- fn: (r) => {
111
- setTimeout(r);
112
- },
113
- getParams: () => [renderToolbar]
114
- }
115
- }
116
- ]
117
- };
118
- function localProvider(path) {
119
- return `${ASSETS_PREFIX}${path}`;
120
- }
121
- function createStreamBody(stream) {
122
- const body = new ReadableStream({
123
- start(controller) {
124
- stream.on("data", (chunk) => {
125
- controller.enqueue(chunk);
126
- });
127
- stream.on("end", () => {
128
- controller.close();
129
- });
130
- },
131
- cancel() {
132
- stream.destroy();
133
- }
134
- });
135
- return body;
136
- }
137
- const config = {
138
- distDir,
139
- assetsDir: `${distDir}${ASSETS_PREFIX}`
140
- };
141
85
  function sequence(fn) {
142
86
  let promise;
143
87
  return () => {
@@ -325,9 +269,9 @@ class MarkmapDevServer {
325
269
  await ((_a = provider[cmd]) == null ? void 0 : _a.call(provider, ...args));
326
270
  return c.body(null, 204);
327
271
  });
328
- const { distDir: distDir2, assetsDir } = config;
272
+ const { distDir, assetsDir } = config;
329
273
  app.get("/~client.*", async (c) => {
330
- const realpath = join(distDir2, c.req.path.slice(2));
274
+ const realpath = join(distDir, c.req.path.slice(2));
331
275
  return sendStatic(c, realpath);
332
276
  });
333
277
  app.get(`${ASSETS_PREFIX}*`, async (c) => {
@@ -404,56 +348,6 @@ async function develop(options) {
404
348
  await devServer.setup();
405
349
  return devServer;
406
350
  }
407
- const providerName = "local-hook";
408
- async function fetchAssets(assetsDir = config.assetsDir) {
409
- const transformer = new Transformer();
410
- transformer.urlBuilder.setProvider(providerName, localProvider);
411
- transformer.urlBuilder.provider = providerName;
412
- const assets = transformer.getAssets();
413
- delete transformer.urlBuilder.providers[providerName];
414
- const pluginPaths = extractAssets(assets).filter((url) => url.startsWith(ASSETS_PREFIX)).map((url) => url.slice(ASSETS_PREFIX.length));
415
- const resources = transformer.plugins.flatMap(
416
- (plugin) => {
417
- var _a;
418
- return ((_a = plugin.config) == null ? void 0 : _a.resources) || [];
419
- }
420
- );
421
- const paths = [
422
- ...baseJsPaths,
423
- ...pluginPaths,
424
- ...resources,
425
- ...extractAssets(toolbarAssets)
426
- ];
427
- let findingProvider;
428
- const findProvider = () => {
429
- findingProvider || (findingProvider = transformer.urlBuilder.getFastestProvider());
430
- return findingProvider;
431
- };
432
- await Promise.all(
433
- paths.map(
434
- (path) => downloadAsset(
435
- resolve(assetsDir, path),
436
- async () => transformer.urlBuilder.getFullUrl(path, await findProvider())
437
- )
438
- )
439
- );
440
- }
441
- async function downloadAsset(fullPath, resolveUrl) {
442
- try {
443
- const result = await stat(fullPath);
444
- if (result.isFile()) return;
445
- } catch {
446
- }
447
- const url = await resolveUrl();
448
- const res = await fetch(url);
449
- if (!res.ok || !res.body) throw new Error(`Failed to download: ${url}`);
450
- await mkdir(dirname(fullPath), { recursive: true });
451
- await finished(
452
- Readable.fromWeb(res.body).pipe(
453
- createWriteStream(fullPath)
454
- )
455
- );
456
- }
457
351
  async function loadFile(path) {
458
352
  if (path.startsWith(ASSETS_PREFIX)) {
459
353
  const relpath = path.slice(ASSETS_PREFIX.length);
@@ -527,57 +421,10 @@ async function createMarkmap(options) {
527
421
  await writeFile(output, html, "utf8");
528
422
  if (options.open) open(output);
529
423
  }
530
- async function main() {
531
- var _a;
532
- const pkg = (_a = await readPackageUp({
533
- cwd: fileURLToPath(import.meta.url)
534
- })) == null ? void 0 : _a.packageJson;
535
- if (!pkg) throw new Error("package.json not found");
536
- const notifier = updateNotifier({ pkg });
537
- notifier.notify();
538
- const program = new Command();
539
- program.version(pkg.version).description("Create a markmap from a Markdown input file").arguments("<input>").option("--no-open", "Do not open the output file after generation").option("--no-toolbar", "Do not show toolbar").option("-o, --output <output>", "Specify the filename of the output HTML").option(
540
- "--offline",
541
- "Inline all assets to allow the generated HTML to work offline"
542
- ).option(
543
- "-w, --watch",
544
- "Watch the input file and update output on the fly, note that this feature is for development only"
545
- ).option("--port <port>", "Set the port for the devServer to listen").action(async (input, cmd) => {
546
- let { offline } = cmd;
547
- if (cmd.watch) offline = true;
548
- if (offline) await fetchAssets();
549
- const content = await readFile(input, "utf8");
550
- const output = cmd.output || `${input.replace(/\.\w*$/, "")}.html`;
551
- if (cmd.watch) {
552
- const devServer = await develop({
553
- toolbar: cmd.toolbar,
554
- offline,
555
- port: +cmd.port || void 0
556
- });
557
- const address = devServer.serverInfo.address;
558
- const provider = devServer.addProvider({ filePath: input });
559
- const filename = basename(input);
560
- const url = `http://localhost:${address.port}/?key=${provider.key}&filename=${encodeURIComponent(filename)}`;
561
- console.log(`Listening at ${url}`);
562
- if (cmd.open) open(url);
563
- } else {
564
- await createMarkmap({
565
- content,
566
- output,
567
- open: cmd.open,
568
- toolbar: cmd.toolbar,
569
- offline
570
- });
571
- }
572
- });
573
- program.parse(process.argv);
574
- }
575
424
  export {
576
425
  MarkmapDevServer,
577
426
  config,
578
427
  createMarkmap,
579
428
  develop,
580
- fetchAssets,
581
- main,
582
429
  markmapLib as markmap
583
430
  };
@@ -1,7 +1,7 @@
1
1
  import { ServerType } from '@hono/node-server';
2
2
  import { Transformer } from 'markmap-lib';
3
3
  import { AddressInfo } from 'net';
4
- import { IContentProvider, IDevelopOptions } from './types';
4
+ import { IContentProvider, IDevelopOptions } from '../types';
5
5
  export declare class MarkmapDevServer {
6
6
  options: IDevelopOptions;
7
7
  providers: Record<string, IContentProvider>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-cli",
3
- "version": "0.18.8",
3
+ "version": "0.18.10-alpha.2+9487f11",
4
4
  "description": "Create markmaps from CLI",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -27,10 +27,10 @@
27
27
  "scripts": {
28
28
  "clean": "del-cli dist tsconfig.tsbuildinfo",
29
29
  "build:types": "tsc",
30
- "build:js": "vite build",
30
+ "build:js": "vite build && pnpm fetch-assets",
31
31
  "build": "pnpm clean && pnpm /^build:/",
32
- "prepublishOnly": "pnpm build",
33
- "postinstall": "node -e \"import('./dist/index.js').then(({ fetchAssets }) => fetchAssets()).catch(() => {})\""
32
+ "fetch-assets": "node ./dist/fetch-assets.js",
33
+ "prepublishOnly": "pnpm build"
34
34
  },
35
35
  "bugs": {
36
36
  "url": "https://github.com/markmap/markmap/issues"
@@ -49,14 +49,14 @@
49
49
  "chokidar": "^4.0.1",
50
50
  "commander": "^12.1.0",
51
51
  "hono": "^4.6.13",
52
- "markmap-common": "0.18.8",
53
- "markmap-lib": "0.18.8",
54
- "markmap-render": "0.18.8",
55
- "markmap-toolbar": "0.18.8",
52
+ "markmap-common": "0.18.9",
53
+ "markmap-lib": "0.18.10-alpha.2+9487f11",
54
+ "markmap-render": "0.18.10-alpha.2+9487f11",
55
+ "markmap-toolbar": "0.18.10-alpha.2+9487f11",
56
56
  "open": "^10.1.0",
57
57
  "portfinder": "^1.0.32",
58
58
  "read-package-up": "^11.0.0",
59
59
  "update-notifier": "^7.3.1"
60
60
  },
61
- "gitHead": "476d2e8abb528af6f6f0c468c6c63791b7c1911a"
61
+ "gitHead": "9487f115b82c8eaee934c7f848faf67f05c700b1"
62
62
  }
File without changes