markmap-lib 0.13.6-alpha.3 → 0.13.6-alpha.4

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.esm.js CHANGED
@@ -1,21 +1,188 @@
1
- /*! markmap-lib v0.13.6-alpha.3+3e26a91 | MIT License */
2
- import _extends from '@babel/runtime/helpers/esm/extends';
3
- import { persistCSS, persistJS, wrapFunction, Hook } from 'markmap-common';
1
+ /*! markmap-lib v0.13.6-alpha.4+70ae484 | MIT License */
2
+ import _extends$1 from '@babel/runtime/helpers/esm/extends';
4
3
  import { Remarkable } from 'remarkable';
5
4
  import remarkableKatex from 'remarkable-katex';
6
5
  import Prism from 'prismjs';
7
6
  import loadLanguages from 'prismjs/components/';
8
7
  import yaml from 'js-yaml';
9
8
 
9
+ /*! markmap-common v0.13.4 | MIT License */
10
+ class Hook {
11
+ constructor() {
12
+ this.listeners = [];
13
+ }
14
+
15
+ tap(fn) {
16
+ this.listeners.push(fn);
17
+ return () => this.revoke(fn);
18
+ }
19
+
20
+ revoke(fn) {
21
+ const i = this.listeners.indexOf(fn);
22
+ if (i >= 0) this.listeners.splice(i, 1);
23
+ }
24
+
25
+ revokeAll() {
26
+ this.listeners.splice(0);
27
+ }
28
+
29
+ call(...args) {
30
+ for (const fn of this.listeners) {
31
+ fn(...args);
32
+ }
33
+ }
34
+
35
+ }
36
+
37
+ function _extends() {
38
+ _extends = Object.assign || function (target) {
39
+ for (var i = 1; i < arguments.length; i++) {
40
+ var source = arguments[i];
41
+
42
+ for (var key in source) {
43
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
44
+ target[key] = source[key];
45
+ }
46
+ }
47
+ }
48
+
49
+ return target;
50
+ };
51
+
52
+ return _extends.apply(this, arguments);
53
+ }
54
+
55
+ function _objectWithoutPropertiesLoose(source, excluded) {
56
+ if (source == null) return {};
57
+ var target = {};
58
+ var sourceKeys = Object.keys(source);
59
+ var key, i;
60
+
61
+ for (i = 0; i < sourceKeys.length; i++) {
62
+ key = sourceKeys[i];
63
+ if (excluded.indexOf(key) >= 0) continue;
64
+ target[key] = source[key];
65
+ }
66
+
67
+ return target;
68
+ }
69
+
70
+ const _excluded = ["textContent"];
71
+
72
+ function escapeHtml(html) {
73
+ return html.replace(/[&<"]/g, m => ({
74
+ '&': '&amp;',
75
+ '<': '&lt;',
76
+ '"': '&quot;'
77
+ })[m]);
78
+ }
79
+
80
+ function escapeScript(content) {
81
+ return content.replace(/<(\/script>)/g, '\\x3c$2');
82
+ }
83
+
84
+ function htmlOpen(tagName, attrs) {
85
+ const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => {
86
+ if (value == null || value === false) return;
87
+ key = ` ${escapeHtml(key)}`;
88
+ if (value === true) return key;
89
+ return `${key}="${escapeHtml(value)}"`;
90
+ }).filter(Boolean).join('') : '';
91
+ return `<${tagName}${attrStr}>`;
92
+ }
93
+
94
+ function htmlClose(tagName) {
95
+ return `</${tagName}>`;
96
+ }
97
+
98
+ function wrapHtml(tagName, content, attrs) {
99
+ if (content == null) return htmlOpen(tagName, attrs);
100
+ return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName);
101
+ }
102
+
103
+ function buildCode(fn, args) {
104
+ const params = args.map(arg => {
105
+ if (typeof arg === 'function') return arg.toString();
106
+ return JSON.stringify(arg != null ? arg : null);
107
+ }).join(',');
108
+ return `(${fn.toString()})(${params})`;
109
+ }
110
+
111
+ function persistJS(items, context) {
112
+ return items.map(item => {
113
+ if (item.type === 'script') {
114
+ const _item$data = item.data,
115
+ {
116
+ textContent
117
+ } = _item$data,
118
+ rest = _objectWithoutPropertiesLoose(_item$data, _excluded);
119
+
120
+ return wrapHtml('script', textContent || '', rest);
121
+ }
122
+
123
+ if (item.type === 'iife') {
124
+ const {
125
+ fn,
126
+ getParams
127
+ } = item.data;
128
+ return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || [])));
129
+ }
130
+
131
+ return '';
132
+ });
133
+ }
134
+
135
+ function persistCSS(items) {
136
+ return items.map(item => {
137
+ if (item.type === 'stylesheet') {
138
+ return wrapHtml('link', null, _extends({
139
+ rel: 'stylesheet'
140
+ }, item.data));
141
+ }
142
+ /* else if (item.type === 'style') */
143
+
144
+
145
+ return wrapHtml('style', item.data);
146
+ });
147
+ }
148
+
149
+ Math.random().toString(36).slice(2, 8);
150
+
151
+ function wrapFunction(fn, {
152
+ before,
153
+ after
154
+ }) {
155
+ return function wrapped(...args) {
156
+ const ctx = {
157
+ args,
158
+ thisObj: this
159
+ };
160
+
161
+ try {
162
+ if (before) before(ctx);
163
+ } catch (_unused) {// ignore
164
+ }
165
+
166
+ ctx.result = fn.apply(ctx.thisObj, ctx.args);
167
+
168
+ try {
169
+ if (after) after(ctx);
170
+ } catch (_unused2) {// ignore
171
+ }
172
+
173
+ return ctx.result;
174
+ };
175
+ }
176
+
10
177
  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";
11
- const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.5"}`].map(src => ({
178
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.6-alpha.4+70ae484"}`].map(src => ({
12
179
  type: 'script',
13
180
  data: {
14
181
  src
15
182
  }
16
183
  }));
17
184
  function fillTemplate(root, assets, extra) {
18
- extra = _extends({
185
+ extra = _extends$1({
19
186
  baseJs: BASE_JS
20
187
  }, extra);
21
188
  const {
@@ -282,7 +449,7 @@ function cleanNode(node) {
282
449
  if (['paragraph', 'fence'].includes(item.type)) {
283
450
  if (!node.content) {
284
451
  node.content = item.content;
285
- node.payload = _extends({}, node.payload, item.payload);
452
+ node.payload = _extends$1({}, node.payload, item.payload);
286
453
  }
287
454
 
288
455
  return false;
@@ -300,7 +467,7 @@ function cleanNode(node) {
300
467
  let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
301
468
  node.children.forEach(item => {
302
469
  if (item.type === 'list_item') {
303
- item.payload = _extends({}, item.payload, {
470
+ item.payload = _extends$1({}, item.payload, {
304
471
  index
305
472
  });
306
473
  index += 1;
@@ -460,7 +627,7 @@ class Transformer {
460
627
  cleanNode(root);
461
628
  if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
462
629
  resetDepth(root);
463
- return _extends({}, context, {
630
+ return _extends$1({}, context, {
464
631
  root
465
632
  });
466
633
  }
@@ -501,7 +668,7 @@ class Transformer {
501
668
  }
502
669
 
503
670
  const transformerVersions = {
504
- 'markmap-lib': '0.13.6-alpha.3+3e26a91',
671
+ 'markmap-lib': '0.13.6-alpha.4+70ae484',
505
672
  d3: "6.7.0"
506
673
  };
507
674
 
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
- /*! markmap-lib v0.13.6-alpha.3+3e26a91 | MIT License */
1
+ /*! markmap-lib v0.13.6-alpha.4+70ae484 | MIT License */
2
2
  'use strict';
3
3
 
4
- var _extends = require('@babel/runtime/helpers/extends');
5
- var markmapCommon = require('markmap-common');
4
+ var _extends$1 = require('@babel/runtime/helpers/extends');
6
5
  var remarkable = require('remarkable');
7
6
  var remarkableKatex = require('remarkable-katex');
8
7
  var Prism = require('prismjs');
@@ -11,14 +10,182 @@ var yaml = require('js-yaml');
11
10
 
12
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
13
12
 
14
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
13
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends$1);
15
14
  var remarkableKatex__default = /*#__PURE__*/_interopDefaultLegacy(remarkableKatex);
16
15
  var Prism__default = /*#__PURE__*/_interopDefaultLegacy(Prism);
17
16
  var loadLanguages__default = /*#__PURE__*/_interopDefaultLegacy(loadLanguages);
18
17
  var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
19
18
 
19
+ /*! markmap-common v0.13.4 | MIT License */
20
+ class Hook {
21
+ constructor() {
22
+ this.listeners = [];
23
+ }
24
+
25
+ tap(fn) {
26
+ this.listeners.push(fn);
27
+ return () => this.revoke(fn);
28
+ }
29
+
30
+ revoke(fn) {
31
+ const i = this.listeners.indexOf(fn);
32
+ if (i >= 0) this.listeners.splice(i, 1);
33
+ }
34
+
35
+ revokeAll() {
36
+ this.listeners.splice(0);
37
+ }
38
+
39
+ call(...args) {
40
+ for (const fn of this.listeners) {
41
+ fn(...args);
42
+ }
43
+ }
44
+
45
+ }
46
+
47
+ function _extends() {
48
+ _extends = Object.assign || function (target) {
49
+ for (var i = 1; i < arguments.length; i++) {
50
+ var source = arguments[i];
51
+
52
+ for (var key in source) {
53
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
54
+ target[key] = source[key];
55
+ }
56
+ }
57
+ }
58
+
59
+ return target;
60
+ };
61
+
62
+ return _extends.apply(this, arguments);
63
+ }
64
+
65
+ function _objectWithoutPropertiesLoose(source, excluded) {
66
+ if (source == null) return {};
67
+ var target = {};
68
+ var sourceKeys = Object.keys(source);
69
+ var key, i;
70
+
71
+ for (i = 0; i < sourceKeys.length; i++) {
72
+ key = sourceKeys[i];
73
+ if (excluded.indexOf(key) >= 0) continue;
74
+ target[key] = source[key];
75
+ }
76
+
77
+ return target;
78
+ }
79
+
80
+ const _excluded = ["textContent"];
81
+
82
+ function escapeHtml(html) {
83
+ return html.replace(/[&<"]/g, m => ({
84
+ '&': '&amp;',
85
+ '<': '&lt;',
86
+ '"': '&quot;'
87
+ })[m]);
88
+ }
89
+
90
+ function escapeScript(content) {
91
+ return content.replace(/<(\/script>)/g, '\\x3c$2');
92
+ }
93
+
94
+ function htmlOpen(tagName, attrs) {
95
+ const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => {
96
+ if (value == null || value === false) return;
97
+ key = ` ${escapeHtml(key)}`;
98
+ if (value === true) return key;
99
+ return `${key}="${escapeHtml(value)}"`;
100
+ }).filter(Boolean).join('') : '';
101
+ return `<${tagName}${attrStr}>`;
102
+ }
103
+
104
+ function htmlClose(tagName) {
105
+ return `</${tagName}>`;
106
+ }
107
+
108
+ function wrapHtml(tagName, content, attrs) {
109
+ if (content == null) return htmlOpen(tagName, attrs);
110
+ return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName);
111
+ }
112
+
113
+ function buildCode(fn, args) {
114
+ const params = args.map(arg => {
115
+ if (typeof arg === 'function') return arg.toString();
116
+ return JSON.stringify(arg != null ? arg : null);
117
+ }).join(',');
118
+ return `(${fn.toString()})(${params})`;
119
+ }
120
+
121
+ function persistJS(items, context) {
122
+ return items.map(item => {
123
+ if (item.type === 'script') {
124
+ const _item$data = item.data,
125
+ {
126
+ textContent
127
+ } = _item$data,
128
+ rest = _objectWithoutPropertiesLoose(_item$data, _excluded);
129
+
130
+ return wrapHtml('script', textContent || '', rest);
131
+ }
132
+
133
+ if (item.type === 'iife') {
134
+ const {
135
+ fn,
136
+ getParams
137
+ } = item.data;
138
+ return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || [])));
139
+ }
140
+
141
+ return '';
142
+ });
143
+ }
144
+
145
+ function persistCSS(items) {
146
+ return items.map(item => {
147
+ if (item.type === 'stylesheet') {
148
+ return wrapHtml('link', null, _extends({
149
+ rel: 'stylesheet'
150
+ }, item.data));
151
+ }
152
+ /* else if (item.type === 'style') */
153
+
154
+
155
+ return wrapHtml('style', item.data);
156
+ });
157
+ }
158
+
159
+ Math.random().toString(36).slice(2, 8);
160
+
161
+ function wrapFunction(fn, {
162
+ before,
163
+ after
164
+ }) {
165
+ return function wrapped(...args) {
166
+ const ctx = {
167
+ args,
168
+ thisObj: this
169
+ };
170
+
171
+ try {
172
+ if (before) before(ctx);
173
+ } catch (_unused) {// ignore
174
+ }
175
+
176
+ ctx.result = fn.apply(ctx.thisObj, ctx.args);
177
+
178
+ try {
179
+ if (after) after(ctx);
180
+ } catch (_unused2) {// ignore
181
+ }
182
+
183
+ return ctx.result;
184
+ };
185
+ }
186
+
20
187
  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";
21
- const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.5"}`].map(src => ({
188
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.6-alpha.4+70ae484"}`].map(src => ({
22
189
  type: 'script',
23
190
  data: {
24
191
  src
@@ -32,14 +199,14 @@ function fillTemplate(root, assets, extra) {
32
199
  scripts,
33
200
  styles
34
201
  } = assets;
35
- const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
202
+ const cssList = [...(styles ? persistCSS(styles) : [])];
36
203
  const context = {
37
204
  getMarkmap: () => window.markmap,
38
205
  getOptions: extra.getOptions,
39
206
  jsonOptions: extra.jsonOptions,
40
207
  root
41
208
  };
42
- const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
209
+ const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
43
210
  type: 'iife',
44
211
  data: {
45
212
  fn: (getMarkmap, getOptions, root, jsonOptions) => {
@@ -113,7 +280,7 @@ function transform$2(transformHooks) {
113
280
 
114
281
  transformHooks.parser.tap(md => {
115
282
  md.use(remarkableKatex__default);
116
- md.renderer.rules.katex = markmapCommon.wrapFunction(md.renderer.rules.katex, {
283
+ md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, {
117
284
  after: () => {
118
285
  enableFeature();
119
286
  }
@@ -204,7 +371,7 @@ const name = 'frontmatter';
204
371
  function transform(transformHooks) {
205
372
  transformHooks.transform.tap((md, context) => {
206
373
  const origParse = md.parse;
207
- md.parse = markmapCommon.wrapFunction(origParse, {
374
+ md.parse = wrapFunction(origParse, {
208
375
  before(ctx) {
209
376
  const [content] = ctx.args;
210
377
  if (!content.startsWith('---\n')) return;
@@ -271,10 +438,10 @@ transform: transform
271
438
 
272
439
  function createTransformHooks() {
273
440
  return {
274
- parser: new markmapCommon.Hook(),
275
- transform: new markmapCommon.Hook(),
276
- htmltag: new markmapCommon.Hook(),
277
- retransform: new markmapCommon.Hook()
441
+ parser: new Hook(),
442
+ transform: new Hook(),
443
+ htmltag: new Hook(),
444
+ retransform: new Hook()
278
445
  };
279
446
  }
280
447
 
@@ -357,7 +524,7 @@ class Transformer {
357
524
  breaks: true,
358
525
  maxNesting: Infinity
359
526
  });
360
- md.renderer.rules.htmltag = markmapCommon.wrapFunction(md.renderer.rules.htmltag, {
527
+ md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, {
361
528
  after: ctx => {
362
529
  this.hooks.htmltag.call(ctx);
363
530
  }
@@ -511,7 +678,7 @@ class Transformer {
511
678
  }
512
679
 
513
680
  const transformerVersions = {
514
- 'markmap-lib': '0.13.6-alpha.3+3e26a91',
681
+ 'markmap-lib': '0.13.6-alpha.4+70ae484',
515
682
  d3: "6.7.0"
516
683
  };
517
684
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.13.6-alpha.3+3e26a91",
3
+ "version": "0.13.6-alpha.4+70ae484",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -42,17 +42,20 @@
42
42
  "repository": "git@github.com:gera2ld/markmap.git",
43
43
  "devDependencies": {
44
44
  "@types/remarkable": "^2.0.3",
45
- "markmap-view": "^0.13.5",
45
+ "markmap-common": "^0.13.4",
46
+ "markmap-view": "^0.13.6-alpha.4+70ae484",
46
47
  "webfontloader": "^1.6.28"
47
48
  },
48
49
  "dependencies": {
49
50
  "@babel/runtime": "^7.16.3",
50
51
  "js-yaml": "^4.1.0",
51
52
  "katex": "^0.15.1",
52
- "markmap-common": "^0.13.4",
53
53
  "prismjs": "^1.25.0",
54
54
  "remarkable": "^2.0.1",
55
55
  "remarkable-katex": "^1.1.8"
56
56
  },
57
- "gitHead": "3e26a917be187039277d215033fcd537915bb837"
57
+ "peerDependencies": {
58
+ "markmap-common": "^0.13.4"
59
+ },
60
+ "gitHead": "70ae4840c81db3ed8f7a143a11ce1cd6be9b4dbf"
58
61
  }