markmap-lib 0.14.0 → 0.14.2-alpha.0

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,4 +1,4 @@
1
- /*! markmap-lib v0.14.0 | MIT License */
1
+ /*! markmap-lib v0.14.2-alpha.0+518591b | MIT License */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('katex')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'katex'], factory) :
@@ -26,7 +26,7 @@ function _extends$1() {
26
26
  return _extends$1.apply(this, arguments);
27
27
  }
28
28
 
29
- /*! markmap-common v0.14.0 | MIT License */
29
+ /*! markmap-common v0.14.2-alpha.0+518591b | MIT License */
30
30
  class Hook {
31
31
  constructor() {
32
32
  this.listeners = [];
@@ -237,27 +237,34 @@ const memoizedPreloadJS = memoize(url => {
237
237
  }));
238
238
  });
239
239
 
240
- function loadJSItem(item, context) {
241
- if (item.type === 'script') {
242
- return new Promise((resolve, reject) => {
243
- var _item$data;
240
+ async function loadJSItem(item, context) {
241
+ if (!item.loaded) {
242
+ if (item.type === 'script') {
243
+ item.loaded = new Promise((resolve, reject) => {
244
+ var _item$data;
244
245
 
245
- document.head.append(createElement('script', _extends({}, item.data, {
246
- onload: resolve,
247
- onerror: reject
248
- }))); // Run inline script synchronously
246
+ document.head.append(createElement('script', _extends({}, item.data, {
247
+ onload: resolve,
248
+ onerror: reject
249
+ }))); // Run inline script synchronously
249
250
 
250
- if (!((_item$data = item.data) != null && _item$data.src)) resolve();
251
- });
252
- }
251
+ if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
252
+ }).then(() => {
253
+ item.loaded = true;
254
+ });
255
+ }
253
256
 
254
- if (item.type === 'iife') {
255
- const {
256
- fn,
257
- getParams
258
- } = item.data;
259
- fn(...((getParams == null ? void 0 : getParams(context)) || []));
257
+ if (item.type === 'iife') {
258
+ const {
259
+ fn,
260
+ getParams
261
+ } = item.data;
262
+ fn(...((getParams == null ? void 0 : getParams(context)) || []));
263
+ item.loaded = true;
264
+ }
260
265
  }
266
+
267
+ await item.loaded;
261
268
  }
262
269
 
263
270
  async function loadJS(items, context) {
@@ -277,7 +284,7 @@ async function loadJS(items, context) {
277
284
  }
278
285
 
279
286
  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";
280
- const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.0"}`].map(src => ({
287
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.0+518591b"}`].map(src => ({
281
288
  type: 'script',
282
289
  data: {
283
290
  src
@@ -8675,72 +8682,89 @@ function resolveNpmPaths(paths, name, version) {
8675
8682
  });
8676
8683
  }
8677
8684
 
8685
+ function createTransformHooks() {
8686
+ return {
8687
+ parser: new Hook(),
8688
+ beforeParse: new Hook(),
8689
+ afterParse: new Hook(),
8690
+ htmltag: new Hook(),
8691
+ retransform: new Hook()
8692
+ };
8693
+ }
8694
+ /**
8695
+ * This function is only used to help type checking.
8696
+ */
8697
+
8698
+ function definePlugin(plugin) {
8699
+ return plugin;
8700
+ }
8701
+
8678
8702
  let loading$1;
8679
8703
 
8680
8704
  const autoload$1 = () => {
8681
8705
  loading$1 || (loading$1 = loadJS(config$1.preloadScripts));
8682
8706
  return loading$1;
8683
8707
  };
8708
+
8684
8709
  const name$2 = 'katex';
8685
- function transform$2(transformHooks) {
8686
- const renderKatex = (source, displayMode) => {
8687
- const {
8688
- katex
8689
- } = window;
8710
+ var katex = definePlugin({
8711
+ name: name$2,
8712
+ config: config$1,
8690
8713
 
8691
- if (katex) {
8692
- return katex.renderToString(source, {
8693
- displayMode,
8694
- throwOnError: false
8714
+ transform(transformHooks) {
8715
+ const renderKatex = (source, displayMode) => {
8716
+ const {
8717
+ katex
8718
+ } = window;
8719
+
8720
+ if (katex) {
8721
+ return katex.renderToString(source, {
8722
+ displayMode,
8723
+ throwOnError: false
8724
+ });
8725
+ }
8726
+
8727
+ autoload$1().then(() => {
8728
+ transformHooks.retransform.call();
8695
8729
  });
8696
- }
8730
+ return source;
8731
+ };
8697
8732
 
8698
- autoload$1().then(() => {
8699
- transformHooks.retransform.call();
8700
- });
8701
- return source;
8702
- };
8733
+ let enableFeature = () => {};
8703
8734
 
8704
- let enableFeature = () => {};
8735
+ transformHooks.parser.tap(md => {
8736
+ md.use(remarkableKatex);
8705
8737
 
8706
- transformHooks.parser.tap(md => {
8707
- md.use(remarkableKatex);
8738
+ md.renderer.rules.katex = (tokens, idx) => {
8739
+ enableFeature();
8740
+ const result = renderKatex(tokens[idx].content, tokens[idx].block);
8741
+ return result;
8742
+ };
8743
+ });
8744
+ transformHooks.beforeParse.tap((_, context) => {
8745
+ enableFeature = () => {
8746
+ context.features[name$2] = true;
8747
+ };
8748
+ });
8749
+ transformHooks.afterParse.tap((_, context) => {
8750
+ const {
8751
+ frontmatter
8752
+ } = context;
8708
8753
 
8709
- md.renderer.rules.katex = (tokens, idx) => {
8710
- enableFeature();
8711
- const result = renderKatex(tokens[idx].content, tokens[idx].block);
8712
- return result;
8713
- };
8714
- });
8715
- transformHooks.beforeParse.tap((_, context) => {
8716
- enableFeature = () => {
8717
- context.features[name$2] = true;
8754
+ if (frontmatter != null && frontmatter.markmap) {
8755
+ ['extraJs', 'extraCss'].forEach(key => {
8756
+ if (frontmatter.markmap[key]) {
8757
+ frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
8758
+ }
8759
+ });
8760
+ }
8761
+ });
8762
+ return {
8763
+ styles: config$1.styles,
8764
+ scripts: config$1.scripts
8718
8765
  };
8719
- });
8720
- transformHooks.afterParse.tap((_, context) => {
8721
- const {
8722
- frontmatter
8723
- } = context;
8724
-
8725
- if (frontmatter != null && frontmatter.markmap) {
8726
- ['extraJs', 'extraCss'].forEach(key => {
8727
- if (frontmatter.markmap[key]) {
8728
- frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
8729
- }
8730
- });
8731
- }
8732
- });
8733
- return {
8734
- styles: config$1.styles,
8735
- scripts: config$1.scripts
8736
- };
8737
- }
8766
+ }
8738
8767
 
8739
- var katex = /*#__PURE__*/Object.freeze({
8740
- __proto__: null,
8741
- config: config$1,
8742
- name: name$2,
8743
- transform: transform$2
8744
8768
  });
8745
8769
 
8746
8770
  var config = {
@@ -8780,45 +8804,45 @@ function loadLanguageAndRefresh(lang, transformHooks) {
8780
8804
  });
8781
8805
  });
8782
8806
  }
8783
- const name$1 = 'prism';
8784
- function transform$1(transformHooks) {
8785
- let enableFeature = () => {};
8786
8807
 
8787
- transformHooks.parser.tap(md => {
8788
- md.set({
8789
- highlight: (str, lang) => {
8790
- var _Prism$languages;
8808
+ const name$1 = 'prism';
8809
+ var prism = definePlugin({
8810
+ name: name$1,
8811
+ config,
8812
+
8813
+ transform(transformHooks) {
8814
+ let enableFeature = () => {};
8815
+
8816
+ transformHooks.parser.tap(md => {
8817
+ md.set({
8818
+ highlight: (str, lang) => {
8819
+ var _Prism$languages;
8820
+
8821
+ enableFeature();
8822
+ const {
8823
+ Prism
8824
+ } = window;
8825
+ const grammar = Prism == null ? void 0 : (_Prism$languages = Prism.languages) == null ? void 0 : _Prism$languages[lang];
8826
+
8827
+ if (!grammar) {
8828
+ loadLanguageAndRefresh(lang, transformHooks);
8829
+ return '';
8830
+ }
8791
8831
 
8792
- enableFeature();
8793
- const {
8794
- Prism
8795
- } = window;
8796
- const grammar = Prism == null ? void 0 : (_Prism$languages = Prism.languages) == null ? void 0 : _Prism$languages[lang];
8797
-
8798
- if (!grammar) {
8799
- loadLanguageAndRefresh(lang, transformHooks);
8800
- return '';
8832
+ return Prism.highlight(str, grammar, lang);
8801
8833
  }
8802
-
8803
- return Prism.highlight(str, grammar, lang);
8804
- }
8834
+ });
8805
8835
  });
8806
- });
8807
- transformHooks.beforeParse.tap((_, context) => {
8808
- enableFeature = () => {
8809
- context.features[name$1] = true;
8836
+ transformHooks.beforeParse.tap((_, context) => {
8837
+ enableFeature = () => {
8838
+ context.features[name$1] = true;
8839
+ };
8840
+ });
8841
+ return {
8842
+ styles: config.styles
8810
8843
  };
8811
- });
8812
- return {
8813
- styles: config.styles
8814
- };
8815
- }
8844
+ }
8816
8845
 
8817
- var prism = /*#__PURE__*/Object.freeze({
8818
- __proto__: null,
8819
- config: config,
8820
- name: name$1,
8821
- transform: transform$1
8822
8846
  });
8823
8847
 
8824
8848
  /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
@@ -12672,43 +12696,48 @@ var jsYaml = {
12672
12696
  };
12673
12697
 
12674
12698
  const name = 'frontmatter';
12675
- function transform(transformHooks) {
12676
- transformHooks.beforeParse.tap((md, context) => {
12677
- const origParse = md.parse;
12678
- md.parse = wrapFunction(origParse, {
12679
- before(ctx) {
12680
- const [content] = ctx.args;
12681
- if (!content.startsWith('---\n')) return;
12682
- const endOffset = content.indexOf('\n---\n');
12683
- if (endOffset < 0) return;
12684
- const raw = content.slice(4, endOffset);
12685
- let frontmatter;
12686
-
12687
- try {
12688
- var _frontmatter;
12689
-
12690
- frontmatter = jsYaml.load(raw);
12691
-
12692
- if ((_frontmatter = frontmatter) != null && _frontmatter.markmap) {
12693
- frontmatter.markmap = normalizeMarkmapJsonOptions(frontmatter.markmap);
12699
+ var frontmatter = definePlugin({
12700
+ name,
12701
+
12702
+ transform(transformHooks) {
12703
+ transformHooks.beforeParse.tap((md, context) => {
12704
+ const origParse = md.parse;
12705
+ md.parse = wrapFunction(origParse, {
12706
+ before(ctx) {
12707
+ const [content] = ctx.args;
12708
+ if (!content.startsWith('---\n')) return;
12709
+ const endOffset = content.indexOf('\n---\n');
12710
+ if (endOffset < 0) return;
12711
+ const raw = content.slice(4, endOffset);
12712
+ let frontmatter;
12713
+
12714
+ try {
12715
+ var _frontmatter;
12716
+
12717
+ frontmatter = jsYaml.load(raw);
12718
+
12719
+ if ((_frontmatter = frontmatter) != null && _frontmatter.markmap) {
12720
+ frontmatter.markmap = normalizeMarkmapJsonOptions(frontmatter.markmap);
12721
+ }
12722
+ } catch (_unused) {
12723
+ return;
12694
12724
  }
12695
- } catch (_unused) {
12696
- return;
12697
- }
12698
12725
 
12699
- context.frontmatter = frontmatter;
12700
- const offset = endOffset + 5;
12701
- ctx.args[0] = content.slice(offset);
12702
- },
12726
+ context.frontmatter = frontmatter;
12727
+ const offset = endOffset + 5;
12728
+ ctx.args[0] = content.slice(offset);
12729
+ },
12703
12730
 
12704
- after() {
12705
- md.parse = origParse;
12706
- }
12731
+ after() {
12732
+ md.parse = origParse;
12733
+ }
12707
12734
 
12735
+ });
12708
12736
  });
12709
- });
12710
- return {};
12711
- }
12737
+ return {};
12738
+ }
12739
+
12740
+ });
12712
12741
 
12713
12742
  function normalizeMarkmapJsonOptions(options) {
12714
12743
  if (!options) return;
@@ -12734,22 +12763,6 @@ function normalizeNumber(value) {
12734
12763
  return +value;
12735
12764
  }
12736
12765
 
12737
- var frontmatter = /*#__PURE__*/Object.freeze({
12738
- __proto__: null,
12739
- name: name,
12740
- transform: transform
12741
- });
12742
-
12743
- function createTransformHooks() {
12744
- return {
12745
- parser: new Hook(),
12746
- beforeParse: new Hook(),
12747
- afterParse: new Hook(),
12748
- htmltag: new Hook(),
12749
- retransform: new Hook()
12750
- };
12751
- }
12752
-
12753
12766
  const plugins = [frontmatter, katex, prism];
12754
12767
 
12755
12768
  function cleanNode(node) {
@@ -12812,6 +12825,7 @@ function resetDepth(node, depth = 0) {
12812
12825
 
12813
12826
  class Transformer {
12814
12827
  constructor(plugins$1 = plugins) {
12828
+ this.assetsMap = {};
12815
12829
  this.plugins = plugins$1;
12816
12830
  this.hooks = createTransformHooks();
12817
12831
  const assetsMap = {};
@@ -12984,7 +12998,7 @@ class Transformer {
12984
12998
  }
12985
12999
 
12986
13000
  const transformerVersions = {
12987
- 'markmap-lib': '0.14.0',
13001
+ 'markmap-lib': '0.14.2-alpha.0+518591b',
12988
13002
  d3: "6.7.0"
12989
13003
  };
12990
13004