markmap-lib 0.14.5-alpha.21 → 0.14.5-alpha.22

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.
@@ -1,9 +1,12 @@
1
- /*! markmap-lib v0.14.5-alpha.21+fb81f2c | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.22+04afb38 | MIT License */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('markmap-common'), require('katex'), require('highlight.js')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'markmap-common', 'katex', 'highlight.js'], factory) :
5
5
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markmap = global.markmap || {}, global.markmap, global.window.katex, global.window.hljs));
6
- })(this, (function (exports, markmapCommon, require$$0, hljs$1) { 'use strict';
6
+ })(this, (function (exports, markmapCommon, require$$0, hljs) { 'use strict';
7
+
8
+ 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" ;
9
+ const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.22"}/dist/browser/index.js`];
7
10
 
8
11
  function _extends() {
9
12
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -20,44 +23,6 @@ function _extends() {
20
23
  return _extends.apply(this, arguments);
21
24
  }
22
25
 
23
- 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" ;
24
- const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.21"}/dist/browser/index.js`];
25
- function fillTemplate(root, assets, extra) {
26
- var _extra, _extra$baseJs;
27
- extra = _extends({}, extra);
28
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => markmapCommon.buildJSItem(path));
29
- const {
30
- scripts,
31
- styles
32
- } = assets;
33
- const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
34
- const context = {
35
- getMarkmap: () => window.markmap,
36
- getOptions: extra.getOptions,
37
- jsonOptions: extra.jsonOptions,
38
- root
39
- };
40
- const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
41
- type: 'iife',
42
- data: {
43
- fn: (getMarkmap, getOptions, root, jsonOptions) => {
44
- const markmap = getMarkmap();
45
- window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
46
- },
47
- getParams: ({
48
- getMarkmap,
49
- getOptions,
50
- root,
51
- jsonOptions
52
- }) => {
53
- return [getMarkmap, getOptions, root, jsonOptions];
54
- }
55
- }
56
- }], context)];
57
- const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
58
- return html;
59
- }
60
-
61
26
  // List of valid entities
62
27
  //
63
28
  // Generate with ./support/entities.js script
@@ -6986,7 +6951,7 @@ var commonmarkConfig = {
6986
6951
  * Preset configs
6987
6952
  */
6988
6953
 
6989
- var config = {
6954
+ var config$2 = {
6990
6955
  'default': defaultConfig,
6991
6956
  'full': fullConfig,
6992
6957
  'commonmark': commonmarkConfig
@@ -7034,7 +6999,7 @@ function Remarkable(preset, options) {
7034
6999
  this.renderer = new Renderer();
7035
7000
  this.ruler = new Ruler();
7036
7001
  this.options = {};
7037
- this.configure(config[preset]);
7002
+ this.configure(config$2[preset]);
7038
7003
  this.set(options || {});
7039
7004
  }
7040
7005
 
@@ -7319,40 +7284,38 @@ var remarkableKatex = rkatex;
7319
7284
  var remarkableKatex$1 = /*@__PURE__*/getDefaultExportFromCjs(remarkableKatex);
7320
7285
 
7321
7286
  const name$3 = 'katex';
7322
- function getConfig$1() {
7323
- const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => markmapCommon.buildJSItem(path));
7324
- const webfontloader = markmapCommon.buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
7325
- webfontloader.data.defer = true;
7326
- const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => markmapCommon.buildCSSItem(path));
7327
- return {
7328
- versions: {
7329
- katex: "0.16.8" ,
7330
- webfontloader: "1.6.28"
7331
- },
7332
- preloadScripts,
7333
- scripts: [{
7334
- type: 'iife',
7335
- data: {
7336
- fn: getMarkmap => {
7337
- window.WebFontConfig = {
7338
- custom: {
7339
- families: ['KaTeX_AMS', 'KaTeX_Caligraphic:n4,n7', 'KaTeX_Fraktur:n4,n7', 'KaTeX_Main:n4,n7,i4,i7', 'KaTeX_Math:i4,i7', 'KaTeX_Script', 'KaTeX_SansSerif:n4,n7,i4', 'KaTeX_Size1', 'KaTeX_Size2', 'KaTeX_Size3', 'KaTeX_Size4', 'KaTeX_Typewriter']
7340
- },
7341
- active: () => {
7342
- getMarkmap().refreshHook.call();
7343
- }
7344
- };
7345
- },
7346
- getParams({
7347
- getMarkmap
7348
- }) {
7349
- return [getMarkmap];
7350
- }
7287
+ const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => markmapCommon.buildJSItem(path));
7288
+ const webfontloader = markmapCommon.buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
7289
+ webfontloader.data.defer = true;
7290
+ const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => markmapCommon.buildCSSItem(path));
7291
+ const config$1 = {
7292
+ versions: {
7293
+ katex: "0.16.8" ,
7294
+ webfontloader: "1.6.28"
7295
+ },
7296
+ preloadScripts,
7297
+ scripts: [{
7298
+ type: 'iife',
7299
+ data: {
7300
+ fn: getMarkmap => {
7301
+ window.WebFontConfig = {
7302
+ custom: {
7303
+ families: ['KaTeX_AMS', 'KaTeX_Caligraphic:n4,n7', 'KaTeX_Fraktur:n4,n7', 'KaTeX_Main:n4,n7,i4,i7', 'KaTeX_Math:i4,i7', 'KaTeX_Script', 'KaTeX_SansSerif:n4,n7,i4', 'KaTeX_Size1', 'KaTeX_Size2', 'KaTeX_Size3', 'KaTeX_Size4', 'KaTeX_Typewriter']
7304
+ },
7305
+ active: () => {
7306
+ getMarkmap().refreshHook.call();
7307
+ }
7308
+ };
7309
+ },
7310
+ getParams({
7311
+ getMarkmap
7312
+ }) {
7313
+ return [getMarkmap];
7351
7314
  }
7352
- }, webfontloader],
7353
- styles
7354
- };
7355
- }
7315
+ }
7316
+ }, webfontloader],
7317
+ styles: styles$1
7318
+ };
7356
7319
 
7357
7320
  /**
7358
7321
  * Find NPM paths and resolve them to full URLs with the same package version as in this library.
@@ -7371,9 +7334,30 @@ function addDefaultVersions(paths, name, version) {
7371
7334
  return path;
7372
7335
  });
7373
7336
  }
7337
+ function patchJSItem(transformer, item) {
7338
+ if (item.type === 'script' && item.data.src) {
7339
+ return _extends({}, item, {
7340
+ data: _extends({}, item.data, {
7341
+ src: transformer.urlBuilder.getFullUrl(item.data.src)
7342
+ })
7343
+ });
7344
+ }
7345
+ return item;
7346
+ }
7347
+ function patchCSSItem(transformer, item) {
7348
+ if (item.type === 'stylesheet' && item.data.href) {
7349
+ return _extends({}, item, {
7350
+ data: _extends({}, item.data, {
7351
+ href: transformer.urlBuilder.getFullUrl(item.data.href)
7352
+ })
7353
+ });
7354
+ }
7355
+ return item;
7356
+ }
7374
7357
 
7375
- function createTransformHooks() {
7358
+ function createTransformHooks(transformer) {
7376
7359
  return {
7360
+ transformer,
7377
7361
  parser: new markmapCommon.Hook(),
7378
7362
  beforeParse: new markmapCommon.Hook(),
7379
7363
  afterParse: new markmapCommon.Hook(),
@@ -7389,64 +7373,64 @@ function definePlugin(plugin) {
7389
7373
  return plugin;
7390
7374
  }
7391
7375
 
7392
- var katex = definePlugin(() => {
7393
- const plugin = {
7394
- name: name$3,
7395
- config: getConfig$1(),
7396
- transform(transformHooks) {
7397
- let loading;
7398
- const autoload = () => {
7399
- loading || (loading = markmapCommon.loadJS(plugin.config.preloadScripts));
7400
- return loading;
7401
- };
7402
- const renderKatex = (source, displayMode) => {
7403
- const {
7404
- katex
7405
- } = window;
7406
- if (katex) {
7407
- return katex.renderToString(source, {
7408
- displayMode,
7409
- throwOnError: false
7410
- });
7411
- }
7412
- autoload().then(() => {
7413
- transformHooks.retransform.call();
7376
+ const plugin$1 = definePlugin({
7377
+ name: name$3,
7378
+ config: config$1,
7379
+ transform(transformHooks) {
7380
+ var _plugin$config3, _plugin$config4;
7381
+ let loading;
7382
+ const autoload = () => {
7383
+ var _plugin$config;
7384
+ loading || (loading = markmapCommon.loadJS(((_plugin$config = plugin$1.config) == null ? void 0 : _plugin$config.preloadScripts) || []));
7385
+ return loading;
7386
+ };
7387
+ const renderKatex = (source, displayMode) => {
7388
+ const {
7389
+ katex
7390
+ } = window;
7391
+ if (katex) {
7392
+ return katex.renderToString(source, {
7393
+ displayMode,
7394
+ throwOnError: false
7414
7395
  });
7415
- return source;
7416
- };
7417
- let enableFeature = markmapCommon.noop;
7418
- transformHooks.parser.tap(md => {
7419
- md.use(remarkableKatex$1);
7420
- md.renderer.rules.katex = (tokens, idx) => {
7421
- enableFeature();
7422
- const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
7423
- return result;
7424
- };
7425
- });
7426
- transformHooks.beforeParse.tap((_, context) => {
7427
- enableFeature = () => {
7428
- context.features[name$3] = true;
7429
- };
7430
- });
7431
- transformHooks.afterParse.tap((_, context) => {
7432
- var _context$frontmatter;
7433
- const markmap = (_context$frontmatter = context.frontmatter) == null ? void 0 : _context$frontmatter.markmap;
7434
- if (markmap) {
7435
- ['extraJs', 'extraCss'].forEach(key => {
7436
- const value = markmap[key];
7437
- if (value) {
7438
- markmap[key] = addDefaultVersions(value, name$3, plugin.config.versions.katex);
7439
- }
7440
- });
7441
- }
7396
+ }
7397
+ autoload().then(() => {
7398
+ transformHooks.retransform.call();
7442
7399
  });
7443
- return {
7444
- styles: plugin.config.styles,
7445
- scripts: plugin.config.scripts
7400
+ return source;
7401
+ };
7402
+ let enableFeature = markmapCommon.noop;
7403
+ transformHooks.parser.tap(md => {
7404
+ md.use(remarkableKatex$1);
7405
+ md.renderer.rules.katex = (tokens, idx) => {
7406
+ enableFeature();
7407
+ const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
7408
+ return result;
7446
7409
  };
7447
- }
7448
- };
7449
- return plugin;
7410
+ });
7411
+ transformHooks.beforeParse.tap((_, context) => {
7412
+ enableFeature = () => {
7413
+ context.features[name$3] = true;
7414
+ };
7415
+ });
7416
+ transformHooks.afterParse.tap((_, context) => {
7417
+ var _context$frontmatter;
7418
+ const markmap = (_context$frontmatter = context.frontmatter) == null ? void 0 : _context$frontmatter.markmap;
7419
+ if (markmap) {
7420
+ ['extraJs', 'extraCss'].forEach(key => {
7421
+ const value = markmap[key];
7422
+ if (value) {
7423
+ var _plugin$config2;
7424
+ markmap[key] = addDefaultVersions(value, name$3, ((_plugin$config2 = plugin$1.config) == null || (_plugin$config2 = _plugin$config2.versions) == null ? void 0 : _plugin$config2.katex) || '');
7425
+ }
7426
+ });
7427
+ }
7428
+ });
7429
+ return {
7430
+ styles: (_plugin$config3 = plugin$1.config) == null ? void 0 : _plugin$config3.styles,
7431
+ scripts: (_plugin$config4 = plugin$1.config) == null ? void 0 : _plugin$config4.scripts
7432
+ };
7433
+ }
7450
7434
  });
7451
7435
 
7452
7436
  /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
@@ -10625,7 +10609,7 @@ var npmUrl = definePlugin({
10625
10609
  if (value) {
10626
10610
  markmap[key] = value.map(path => {
10627
10611
  if (path.startsWith('npm:')) {
10628
- return markmapCommon.getFullUrl(path.slice(4));
10612
+ return transformHooks.transformer.urlBuilder.getFullUrl(path.slice(4));
10629
10613
  }
10630
10614
  return path;
10631
10615
  });
@@ -10638,43 +10622,39 @@ var npmUrl = definePlugin({
10638
10622
  });
10639
10623
 
10640
10624
  const name = 'hljs';
10641
- function getConfig() {
10642
- const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => markmapCommon.buildCSSItem(path));
10643
- return {
10644
- versions: {
10645
- hljs: "11.8.0"
10646
- },
10647
- styles
10648
- };
10649
- }
10650
- var hljs = definePlugin(() => {
10651
- const plugin = {
10652
- name,
10653
- config: getConfig(),
10654
- transform(transformHooks) {
10655
- let enableFeature = markmapCommon.noop;
10656
- transformHooks.parser.tap(md => {
10657
- md.set({
10658
- highlight: (str, language) => {
10659
- enableFeature();
10660
- return hljs$1.highlightAuto(str, language ? [language] : undefined).value;
10661
- }
10662
- });
10663
- });
10664
- transformHooks.beforeParse.tap((_, context) => {
10665
- enableFeature = () => {
10666
- context.features[name] = true;
10667
- };
10625
+ const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => markmapCommon.buildCSSItem(path));
10626
+ const config = {
10627
+ versions: {
10628
+ hljs: "11.8.0"
10629
+ },
10630
+ styles
10631
+ };
10632
+ const plugin = definePlugin({
10633
+ name,
10634
+ config,
10635
+ transform(transformHooks) {
10636
+ var _plugin$config;
10637
+ let enableFeature = markmapCommon.noop;
10638
+ transformHooks.parser.tap(md => {
10639
+ md.set({
10640
+ highlight: (str, language) => {
10641
+ enableFeature();
10642
+ return hljs.highlightAuto(str, language ? [language] : undefined).value;
10643
+ }
10668
10644
  });
10669
- return {
10670
- styles: plugin.config.styles
10645
+ });
10646
+ transformHooks.beforeParse.tap((_, context) => {
10647
+ enableFeature = () => {
10648
+ context.features[name] = true;
10671
10649
  };
10672
- }
10673
- };
10674
- return plugin;
10650
+ });
10651
+ return {
10652
+ styles: (_plugin$config = plugin.config) == null ? void 0 : _plugin$config.styles
10653
+ };
10654
+ }
10675
10655
  });
10676
10656
 
10677
- const plugins = [frontmatter, katex, hljs, npmUrl];
10657
+ const plugins = [frontmatter, plugin$1, plugin, npmUrl];
10678
10658
 
10679
10659
  function cleanNode(node) {
10680
10660
  if (node.type === 'heading') {
@@ -10724,7 +10704,8 @@ function resetDepth(node, depth = 0) {
10724
10704
  class Transformer {
10725
10705
  constructor(plugins$1 = plugins) {
10726
10706
  this.assetsMap = {};
10727
- this.hooks = createTransformHooks();
10707
+ this.urlBuilder = new markmapCommon.UrlBuilder();
10708
+ this.hooks = createTransformHooks(this);
10728
10709
  this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
10729
10710
  const assetsMap = {};
10730
10711
  for (const {
@@ -10865,8 +10846,8 @@ class Transformer {
10865
10846
  }
10866
10847
  }
10867
10848
  return {
10868
- styles,
10869
- scripts
10849
+ styles: styles.map(item => patchCSSItem(this, item)),
10850
+ scripts: scripts.map(item => patchJSItem(this, item))
10870
10851
  };
10871
10852
  }
10872
10853
 
@@ -10877,17 +10858,52 @@ class Transformer {
10877
10858
  const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
10878
10859
  return this.getAssets(keys);
10879
10860
  }
10861
+ fillTemplate(root, assets, extra) {
10862
+ var _extra, _extra$baseJs;
10863
+ extra = _extends({}, extra);
10864
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => this.urlBuilder.getFullUrl(path)).map(path => markmapCommon.buildJSItem(path));
10865
+ const {
10866
+ scripts,
10867
+ styles
10868
+ } = assets;
10869
+ const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
10870
+ const context = {
10871
+ getMarkmap: () => window.markmap,
10872
+ getOptions: extra.getOptions,
10873
+ jsonOptions: extra.jsonOptions,
10874
+ root
10875
+ };
10876
+ const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
10877
+ type: 'iife',
10878
+ data: {
10879
+ fn: (getMarkmap, getOptions, root, jsonOptions) => {
10880
+ const markmap = getMarkmap();
10881
+ window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
10882
+ },
10883
+ getParams: ({
10884
+ getMarkmap,
10885
+ getOptions,
10886
+ root,
10887
+ jsonOptions
10888
+ }) => {
10889
+ return [getMarkmap, getOptions, root, jsonOptions];
10890
+ }
10891
+ }
10892
+ }], context)];
10893
+ const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
10894
+ return html;
10895
+ }
10880
10896
  }
10881
10897
 
10882
10898
  const transformerVersions = {
10883
- 'markmap-lib': '0.14.5-alpha.21+fb81f2c',
10899
+ 'markmap-lib': '0.14.5-alpha.22+04afb38',
10884
10900
  d3: "7.8.5"
10885
10901
  };
10886
10902
 
10887
10903
  exports.Transformer = Transformer;
10888
10904
  exports.baseJsPaths = baseJsPaths;
10889
10905
  exports.builtInPlugins = plugins;
10890
- exports.fillTemplate = fillTemplate;
10906
+ exports.template = template;
10891
10907
  exports.transformerVersions = transformerVersions;
10892
10908
 
10893
10909
  }));