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.
package/dist/index.mjs CHANGED
@@ -1,87 +1,51 @@
1
- /*! markmap-lib v0.14.5-alpha.21+fb81f2c | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.22+04afb38 | MIT License */
2
2
  import _extends from '@babel/runtime/helpers/esm/extends';
3
- import { buildJSItem, persistCSS, persistJS, buildCSSItem, Hook, wrapFunction, noop, getFullUrl } from 'markmap-common';
4
3
  import { Remarkable } from 'remarkable';
4
+ import { buildJSItem, buildCSSItem, Hook, wrapFunction, noop, UrlBuilder, persistCSS, persistJS } from 'markmap-common';
5
5
  import remarkableKatex from 'remarkable-katex';
6
6
  import yaml from 'js-yaml';
7
- import hljs$1 from 'highlight.js';
7
+ import hljs from 'highlight.js';
8
8
 
9
9
  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" ;
10
- const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.21"}/dist/browser/index.js`];
11
- function fillTemplate(root, assets, extra) {
12
- var _extra, _extra$baseJs;
13
- extra = _extends({}, extra);
14
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => buildJSItem(path));
15
- const {
16
- scripts,
17
- styles
18
- } = assets;
19
- const cssList = [...(styles ? persistCSS(styles) : [])];
20
- const context = {
21
- getMarkmap: () => window.markmap,
22
- getOptions: extra.getOptions,
23
- jsonOptions: extra.jsonOptions,
24
- root
25
- };
26
- const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
10
+ const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.22"}/dist/browser/index.js`];
11
+
12
+ const name$3 = 'katex';
13
+ const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => buildJSItem(path));
14
+ const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
15
+ webfontloader.data.defer = true;
16
+ const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => buildCSSItem(path));
17
+ const config$1 = {
18
+ versions: {
19
+ katex: "0.16.8" ,
20
+ webfontloader: "1.6.28"
21
+ },
22
+ preloadScripts,
23
+ scripts: [{
27
24
  type: 'iife',
28
25
  data: {
29
- fn: (getMarkmap, getOptions, root, jsonOptions) => {
30
- const markmap = getMarkmap();
31
- window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
26
+ fn: getMarkmap => {
27
+ window.WebFontConfig = {
28
+ custom: {
29
+ 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']
30
+ },
31
+ active: () => {
32
+ getMarkmap().refreshHook.call();
33
+ }
34
+ };
32
35
  },
33
- getParams: ({
34
- getMarkmap,
35
- getOptions,
36
- root,
37
- jsonOptions
38
- }) => {
39
- return [getMarkmap, getOptions, root, jsonOptions];
36
+ getParams({
37
+ getMarkmap
38
+ }) {
39
+ return [getMarkmap];
40
40
  }
41
41
  }
42
- }], context)];
43
- const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
44
- return html;
45
- }
46
-
47
- const name$3 = 'katex';
48
- function getConfig$1() {
49
- const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => buildJSItem(path));
50
- const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
51
- webfontloader.data.defer = true;
52
- const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => buildCSSItem(path));
53
- return {
54
- versions: {
55
- katex: "0.16.8" ,
56
- webfontloader: "1.6.28"
57
- },
58
- preloadScripts,
59
- scripts: [{
60
- type: 'iife',
61
- data: {
62
- fn: getMarkmap => {
63
- window.WebFontConfig = {
64
- custom: {
65
- 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']
66
- },
67
- active: () => {
68
- getMarkmap().refreshHook.call();
69
- }
70
- };
71
- },
72
- getParams({
73
- getMarkmap
74
- }) {
75
- return [getMarkmap];
76
- }
77
- }
78
- }, webfontloader],
79
- styles
80
- };
81
- }
42
+ }, webfontloader],
43
+ styles: styles$1
44
+ };
82
45
 
83
- function createTransformHooks() {
46
+ function createTransformHooks(transformer) {
84
47
  return {
48
+ transformer,
85
49
  parser: new Hook(),
86
50
  beforeParse: new Hook(),
87
51
  afterParse: new Hook(),
@@ -97,31 +61,29 @@ function definePlugin(plugin) {
97
61
  return plugin;
98
62
  }
99
63
 
100
- var katex = definePlugin(() => {
101
- const plugin = {
102
- name: name$3,
103
- config: getConfig$1(),
104
- transform(transformHooks) {
105
- let enableFeature = noop;
106
- transformHooks.parser.tap(md => {
107
- md.use(remarkableKatex);
108
- md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, (render, ...args) => {
109
- enableFeature();
110
- return render(...args);
111
- });
112
- });
113
- transformHooks.beforeParse.tap((_, context) => {
114
- enableFeature = () => {
115
- context.features[name$3] = true;
116
- };
64
+ const plugin$1 = definePlugin({
65
+ name: name$3,
66
+ config: config$1,
67
+ transform(transformHooks) {
68
+ var _plugin$config, _plugin$config2;
69
+ let enableFeature = noop;
70
+ transformHooks.parser.tap(md => {
71
+ md.use(remarkableKatex);
72
+ md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, (render, ...args) => {
73
+ enableFeature();
74
+ return render(...args);
117
75
  });
118
- return {
119
- styles: plugin.config.styles,
120
- scripts: plugin.config.scripts
76
+ });
77
+ transformHooks.beforeParse.tap((_, context) => {
78
+ enableFeature = () => {
79
+ context.features[name$3] = true;
121
80
  };
122
- }
123
- };
124
- return plugin;
81
+ });
82
+ return {
83
+ styles: (_plugin$config = plugin$1.config) == null ? void 0 : _plugin$config.styles,
84
+ scripts: (_plugin$config2 = plugin$1.config) == null ? void 0 : _plugin$config2.scripts
85
+ };
86
+ }
125
87
  });
126
88
 
127
89
  const name$2 = 'frontmatter';
@@ -189,7 +151,7 @@ var npmUrl = definePlugin({
189
151
  if (value) {
190
152
  markmap[key] = value.map(path => {
191
153
  if (path.startsWith('npm:')) {
192
- return getFullUrl(path.slice(4));
154
+ return transformHooks.transformer.urlBuilder.getFullUrl(path.slice(4));
193
155
  }
194
156
  return path;
195
157
  });
@@ -202,43 +164,60 @@ var npmUrl = definePlugin({
202
164
  });
203
165
 
204
166
  const name = 'hljs';
205
- function getConfig() {
206
- const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => buildCSSItem(path));
207
- return {
208
- versions: {
209
- hljs: "11.8.0"
210
- },
211
- styles
212
- };
213
- }
214
- var hljs = definePlugin(() => {
215
- const plugin = {
216
- name,
217
- config: getConfig(),
218
- transform(transformHooks) {
219
- let enableFeature = noop;
220
- transformHooks.parser.tap(md => {
221
- md.set({
222
- highlight: (str, language) => {
223
- enableFeature();
224
- return hljs$1.highlightAuto(str, language ? [language] : undefined).value;
225
- }
226
- });
227
- });
228
- transformHooks.beforeParse.tap((_, context) => {
229
- enableFeature = () => {
230
- context.features[name] = true;
231
- };
167
+ const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => buildCSSItem(path));
168
+ const config = {
169
+ versions: {
170
+ hljs: "11.8.0"
171
+ },
172
+ styles
173
+ };
174
+ const plugin = definePlugin({
175
+ name,
176
+ config,
177
+ transform(transformHooks) {
178
+ var _plugin$config;
179
+ let enableFeature = noop;
180
+ transformHooks.parser.tap(md => {
181
+ md.set({
182
+ highlight: (str, language) => {
183
+ enableFeature();
184
+ return hljs.highlightAuto(str, language ? [language] : undefined).value;
185
+ }
232
186
  });
233
- return {
234
- styles: plugin.config.styles
187
+ });
188
+ transformHooks.beforeParse.tap((_, context) => {
189
+ enableFeature = () => {
190
+ context.features[name] = true;
235
191
  };
236
- }
237
- };
238
- return plugin;
192
+ });
193
+ return {
194
+ styles: (_plugin$config = plugin.config) == null ? void 0 : _plugin$config.styles
195
+ };
196
+ }
239
197
  });
240
198
 
241
- const plugins = [frontmatter, katex, hljs, npmUrl];
199
+ const plugins = [frontmatter, plugin$1, plugin, npmUrl];
200
+
201
+ function patchJSItem(transformer, item) {
202
+ if (item.type === 'script' && item.data.src) {
203
+ return _extends({}, item, {
204
+ data: _extends({}, item.data, {
205
+ src: transformer.urlBuilder.getFullUrl(item.data.src)
206
+ })
207
+ });
208
+ }
209
+ return item;
210
+ }
211
+ function patchCSSItem(transformer, item) {
212
+ if (item.type === 'stylesheet' && item.data.href) {
213
+ return _extends({}, item, {
214
+ data: _extends({}, item.data, {
215
+ href: transformer.urlBuilder.getFullUrl(item.data.href)
216
+ })
217
+ });
218
+ }
219
+ return item;
220
+ }
242
221
 
243
222
  function cleanNode(node) {
244
223
  if (node.type === 'heading') {
@@ -288,7 +267,8 @@ function resetDepth(node, depth = 0) {
288
267
  class Transformer {
289
268
  constructor(plugins$1 = plugins) {
290
269
  this.assetsMap = {};
291
- this.hooks = createTransformHooks();
270
+ this.urlBuilder = new UrlBuilder();
271
+ this.hooks = createTransformHooks(this);
292
272
  this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
293
273
  const assetsMap = {};
294
274
  for (const {
@@ -429,8 +409,8 @@ class Transformer {
429
409
  }
430
410
  }
431
411
  return {
432
- styles,
433
- scripts
412
+ styles: styles.map(item => patchCSSItem(this, item)),
413
+ scripts: scripts.map(item => patchJSItem(this, item))
434
414
  };
435
415
  }
436
416
 
@@ -441,11 +421,46 @@ class Transformer {
441
421
  const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
442
422
  return this.getAssets(keys);
443
423
  }
424
+ fillTemplate(root, assets, extra) {
425
+ var _extra, _extra$baseJs;
426
+ extra = _extends({}, extra);
427
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => this.urlBuilder.getFullUrl(path)).map(path => buildJSItem(path));
428
+ const {
429
+ scripts,
430
+ styles
431
+ } = assets;
432
+ const cssList = [...(styles ? persistCSS(styles) : [])];
433
+ const context = {
434
+ getMarkmap: () => window.markmap,
435
+ getOptions: extra.getOptions,
436
+ jsonOptions: extra.jsonOptions,
437
+ root
438
+ };
439
+ const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
440
+ type: 'iife',
441
+ data: {
442
+ fn: (getMarkmap, getOptions, root, jsonOptions) => {
443
+ const markmap = getMarkmap();
444
+ window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
445
+ },
446
+ getParams: ({
447
+ getMarkmap,
448
+ getOptions,
449
+ root,
450
+ jsonOptions
451
+ }) => {
452
+ return [getMarkmap, getOptions, root, jsonOptions];
453
+ }
454
+ }
455
+ }], context)];
456
+ const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
457
+ return html;
458
+ }
444
459
  }
445
460
 
446
461
  const transformerVersions = {
447
- 'markmap-lib': '0.14.5-alpha.21+fb81f2c',
462
+ 'markmap-lib': '0.14.5-alpha.22+04afb38',
448
463
  d3: "7.8.5"
449
464
  };
450
465
 
451
- export { Transformer, baseJsPaths, plugins as builtInPlugins, fillTemplate, transformerVersions };
466
+ export { Transformer, baseJsPaths, plugins as builtInPlugins, template, transformerVersions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.14.5-alpha.21+fb81f2c",
3
+ "version": "0.14.5-alpha.22+04afb38",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -47,8 +47,8 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/remarkable": "^2.0.3",
50
- "markmap-common": "0.14.5-alpha.21+fb81f2c",
51
- "markmap-view": "0.14.5-alpha.21+fb81f2c",
50
+ "markmap-common": "0.14.5-alpha.22+04afb38",
51
+ "markmap-view": "0.14.5-alpha.22+04afb38",
52
52
  "webfontloader": "^1.6.28"
53
53
  },
54
54
  "dependencies": {
@@ -63,5 +63,5 @@
63
63
  "peerDependencies": {
64
64
  "markmap-common": "*"
65
65
  },
66
- "gitHead": "fb81f2cb688f400f17f911774539267219f639ce"
66
+ "gitHead": "04afb38dd0a6f3b5e8eaffde3c29e9e38b215c35"
67
67
  }
@@ -0,0 +1,2 @@
1
+ export declare const template: string;
2
+ export declare const baseJsPaths: string[];
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './types';
2
- export * from './template';
2
+ export * from './constants';
3
3
  export * from './transform';
4
4
  export declare const transformerVersions: {
5
5
  'markmap-lib': string;
@@ -1,6 +1,6 @@
1
- import { ITransformHooks, ITransformPlugin } from '../types';
2
- export declare function createTransformHooks(): ITransformHooks;
1
+ import { ITransformer, ITransformHooks, ITransformPlugin } from '../types';
2
+ export declare function createTransformHooks(transformer: ITransformer): ITransformHooks;
3
3
  /**
4
4
  * This function is only used to help type checking.
5
5
  */
6
- export declare function definePlugin(plugin: ITransformPlugin | (() => ITransformPlugin)): ITransformPlugin | (() => ITransformPlugin);
6
+ export declare function definePlugin(plugin: ITransformPlugin): ITransformPlugin;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
1
+ declare const _default: import("../types").ITransformPlugin;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
2
- export default _default;
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
@@ -1,2 +1,2 @@
1
1
  export * from './base';
2
- export declare const plugins: (import("..").ITransformPlugin | (() => import("..").ITransformPlugin))[];
2
+ export declare const plugins: import("..").ITransformPlugin[];
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
2
- export default _default;
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
@@ -1,6 +1,6 @@
1
1
  import { JSItem } from 'markmap-common';
2
2
  export declare const name = "katex";
3
- export declare function getConfig(): {
3
+ export declare const config: {
4
4
  versions: {
5
5
  katex: string;
6
6
  webfontloader: string;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
2
- export default _default;
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
1
+ declare const _default: import("../types").ITransformPlugin;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
2
- export default _default;
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
@@ -1,5 +1,5 @@
1
1
  export declare const name = "prism";
2
- export declare function getConfig(): {
2
+ export declare const config: {
3
3
  versions: {
4
4
  prismjs: string;
5
5
  };
@@ -1,2 +1,2 @@
1
- declare const _default: import("../types").ITransformPlugin | (() => import("../types").ITransformPlugin);
2
- export default _default;
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
@@ -1,4 +1,8 @@
1
+ import { CSSItem, JSItem } from 'markmap-common';
2
+ import { ITransformer } from '../types';
1
3
  /**
2
4
  * Find NPM paths and resolve them to full URLs with the same package version as in this library.
3
5
  */
4
6
  export declare function addDefaultVersions(paths: string[], name: string, version: string): string[];
7
+ export declare function patchJSItem(transformer: ITransformer, item: JSItem): JSItem;
8
+ export declare function patchCSSItem(transformer: ITransformer, item: CSSItem): CSSItem;
@@ -1,12 +1,13 @@
1
1
  import { Remarkable } from 'remarkable';
2
- import { IPureNode } from 'markmap-common';
3
- import { ITransformResult, ITransformPlugin, IAssets, ITransformHooks, IFeatures } from './types';
2
+ import { UrlBuilder, JSItem, IMarkmapOptions, IMarkmapJSONOptions, IPureNode } from 'markmap-common';
3
+ import { ITransformResult, ITransformPlugin, IAssets, ITransformHooks, IFeatures, ITransformer } from './types';
4
4
  import { plugins as builtInPlugins } from './plugins';
5
5
  export { builtInPlugins };
6
- export declare class Transformer {
6
+ export declare class Transformer implements ITransformer {
7
7
  hooks: ITransformHooks;
8
8
  md: Remarkable;
9
9
  assetsMap: Record<string, IAssets>;
10
+ urlBuilder: UrlBuilder;
10
11
  plugins: ITransformPlugin[];
11
12
  constructor(plugins?: Array<ITransformPlugin | (() => ITransformPlugin)>);
12
13
  buildTree(tokens: Remarkable.Token[]): IPureNode;
@@ -19,4 +20,9 @@ export declare class Transformer {
19
20
  * Get used assets by features object returned by `transform`.
20
21
  */
21
22
  getUsedAssets(features: IFeatures): IAssets;
23
+ fillTemplate(root: IPureNode | null, assets: IAssets, extra?: {
24
+ baseJs?: JSItem[];
25
+ jsonOptions?: IMarkmapJSONOptions;
26
+ getOptions?: (jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>;
27
+ }): string;
22
28
  }
package/types/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { Remarkable } from 'remarkable';
2
- import { CSSItem, JSItem, IPureNode, IWrapContext, Hook, IMarkmapJSONOptions } from 'markmap-common';
2
+ import { UrlBuilder, CSSItem, JSItem, IPureNode, IWrapContext, Hook, IMarkmapJSONOptions } from 'markmap-common';
3
3
  type Htmltag = Remarkable.Rule<Remarkable.HtmlTagToken, string>;
4
4
  export interface ITransformHooks {
5
+ transformer: ITransformer;
5
6
  /**
6
7
  * Tapped once when the parser is created.
7
8
  */
@@ -41,6 +42,9 @@ export interface IMarkmapCreateOptions {
41
42
  export interface IFeatures {
42
43
  [key: string]: boolean;
43
44
  }
45
+ export interface ITransformer {
46
+ urlBuilder: UrlBuilder;
47
+ }
44
48
  export interface ITransformContext {
45
49
  features: IFeatures;
46
50
  content: string;
@@ -1,8 +0,0 @@
1
- import { JSItem, IMarkmapOptions, IMarkmapJSONOptions, IPureNode } from 'markmap-common';
2
- import { IAssets } from './types';
3
- export declare const baseJsPaths: string[];
4
- export declare function fillTemplate(root: IPureNode | null, assets: IAssets, extra?: {
5
- baseJs?: JSItem[];
6
- jsonOptions?: IMarkmapJSONOptions;
7
- getOptions?: (jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>;
8
- }): string;