markmap-lib 0.14.2-alpha.2 → 0.14.2-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,188 +1,21 @@
1
- /*! markmap-lib v0.14.2-alpha.2+3837810 | MIT License */
2
- import _extends$1 from '@babel/runtime/helpers/esm/extends';
1
+ /*! markmap-lib v0.14.2-alpha.4+569dd11 | MIT License */
2
+ import _extends from '@babel/runtime/helpers/esm/extends';
3
+ import { persistCSS, persistJS, Hook, wrapFunction } from 'markmap-common';
3
4
  import { Remarkable } from 'remarkable';
4
5
  import remarkableKatex from 'remarkable-katex';
5
6
  import Prism from 'prismjs';
6
7
  import loadLanguages from 'prismjs/components/';
7
8
  import yaml from 'js-yaml';
8
9
 
9
- /*! markmap-common v0.14.2-alpha.2+3837810 | 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
-
177
10
  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";
178
- const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.2+3837810"}`].map(src => ({
11
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.4+569dd11"}`].map(src => ({
179
12
  type: 'script',
180
13
  data: {
181
14
  src
182
15
  }
183
16
  }));
184
17
  function fillTemplate(root, assets, extra) {
185
- extra = _extends$1({
18
+ extra = _extends({
186
19
  baseJs: BASE_JS
187
20
  }, extra);
188
21
  const {
@@ -454,7 +287,7 @@ function cleanNode(node) {
454
287
  if (['paragraph', 'fence'].includes(item.type)) {
455
288
  if (!node.content) {
456
289
  node.content = item.content;
457
- node.payload = _extends$1({}, node.payload, item.payload);
290
+ node.payload = _extends({}, node.payload, item.payload);
458
291
  }
459
292
 
460
293
  return false;
@@ -472,7 +305,7 @@ function cleanNode(node) {
472
305
  let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
473
306
  node.children.forEach(item => {
474
307
  if (item.type === 'list_item') {
475
- item.payload = _extends$1({}, item.payload, {
308
+ item.payload = _extends({}, item.payload, {
476
309
  index
477
310
  });
478
311
  index += 1;
@@ -634,7 +467,7 @@ class Transformer {
634
467
  cleanNode(root);
635
468
  if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
636
469
  resetDepth(root);
637
- return _extends$1({}, context, {
470
+ return _extends({}, context, {
638
471
  root
639
472
  });
640
473
  }
@@ -675,7 +508,7 @@ class Transformer {
675
508
  }
676
509
 
677
510
  const transformerVersions = {
678
- 'markmap-lib': '0.14.2-alpha.2+3837810',
511
+ 'markmap-lib': '0.14.2-alpha.4+569dd11',
679
512
  d3: "6.7.0"
680
513
  };
681
514
 
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- /*! markmap-lib v0.14.2-alpha.2+3837810 | MIT License */
1
+ /*! markmap-lib v0.14.2-alpha.4+569dd11 | MIT License */
2
2
  'use strict';
3
3
 
4
- var _extends$1 = require('@babel/runtime/helpers/extends');
4
+ var _extends = require('@babel/runtime/helpers/extends');
5
+ var markmapCommon = require('markmap-common');
5
6
  var remarkable = require('remarkable');
6
7
  var remarkableKatex = require('remarkable-katex');
7
8
  var Prism = require('prismjs');
@@ -10,182 +11,14 @@ var yaml = require('js-yaml');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
12
13
 
13
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends$1);
14
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
14
15
  var remarkableKatex__default = /*#__PURE__*/_interopDefaultLegacy(remarkableKatex);
15
16
  var Prism__default = /*#__PURE__*/_interopDefaultLegacy(Prism);
16
17
  var loadLanguages__default = /*#__PURE__*/_interopDefaultLegacy(loadLanguages);
17
18
  var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
18
19
 
19
- /*! markmap-common v0.14.2-alpha.2+3837810 | 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
-
187
20
  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";
188
- const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.2+3837810"}`].map(src => ({
21
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.4+569dd11"}`].map(src => ({
189
22
  type: 'script',
190
23
  data: {
191
24
  src
@@ -199,14 +32,14 @@ function fillTemplate(root, assets, extra) {
199
32
  scripts,
200
33
  styles
201
34
  } = assets;
202
- const cssList = [...(styles ? persistCSS(styles) : [])];
35
+ const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
203
36
  const context = {
204
37
  getMarkmap: () => window.markmap,
205
38
  getOptions: extra.getOptions,
206
39
  jsonOptions: extra.jsonOptions,
207
40
  root
208
41
  };
209
- const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
42
+ const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
210
43
  type: 'iife',
211
44
  data: {
212
45
  fn: (getMarkmap, getOptions, root, jsonOptions) => {
@@ -276,11 +109,11 @@ var config$1 = {
276
109
 
277
110
  function createTransformHooks() {
278
111
  return {
279
- parser: new Hook(),
280
- beforeParse: new Hook(),
281
- afterParse: new Hook(),
282
- htmltag: new Hook(),
283
- retransform: new Hook()
112
+ parser: new markmapCommon.Hook(),
113
+ beforeParse: new markmapCommon.Hook(),
114
+ afterParse: new markmapCommon.Hook(),
115
+ htmltag: new markmapCommon.Hook(),
116
+ retransform: new markmapCommon.Hook()
284
117
  };
285
118
  }
286
119
  /**
@@ -301,7 +134,7 @@ var katex = definePlugin({
301
134
 
302
135
  transformHooks.parser.tap(md => {
303
136
  md.use(remarkableKatex__default);
304
- md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, {
137
+ md.renderer.rules.katex = markmapCommon.wrapFunction(md.renderer.rules.katex, {
305
138
  after: () => {
306
139
  enableFeature();
307
140
  }
@@ -389,7 +222,7 @@ var frontmatter = definePlugin({
389
222
  transform(transformHooks) {
390
223
  transformHooks.beforeParse.tap((md, context) => {
391
224
  const origParse = md.parse;
392
- md.parse = wrapFunction(origParse, {
225
+ md.parse = markmapCommon.wrapFunction(origParse, {
393
226
  before(ctx) {
394
227
  const [content] = ctx.args;
395
228
  if (!content.startsWith('---\n')) return;
@@ -530,7 +363,7 @@ class Transformer {
530
363
  breaks: true,
531
364
  maxNesting: Infinity
532
365
  });
533
- md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, {
366
+ md.renderer.rules.htmltag = markmapCommon.wrapFunction(md.renderer.rules.htmltag, {
534
367
  after: ctx => {
535
368
  this.hooks.htmltag.call(ctx);
536
369
  }
@@ -685,7 +518,7 @@ class Transformer {
685
518
  }
686
519
 
687
520
  const transformerVersions = {
688
- 'markmap-lib': '0.14.2-alpha.2+3837810',
521
+ 'markmap-lib': '0.14.2-alpha.4+569dd11',
689
522
  d3: "6.7.0"
690
523
  };
691
524
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.14.2-alpha.2+3837810",
3
+ "version": "0.14.2-alpha.4+569dd11",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -43,8 +43,8 @@
43
43
  "repository": "git@github.com:gera2ld/markmap.git",
44
44
  "devDependencies": {
45
45
  "@types/remarkable": "^2.0.3",
46
- "markmap-common": "^0.14.2-alpha.2+3837810",
47
- "markmap-view": "^0.14.2-alpha.2+3837810",
46
+ "markmap-common": "^0.14.0",
47
+ "markmap-view": "^0.14.2-alpha.4+569dd11",
48
48
  "webfontloader": "^1.6.28"
49
49
  },
50
50
  "dependencies": {
@@ -58,5 +58,5 @@
58
58
  "peerDependencies": {
59
59
  "markmap-common": "*"
60
60
  },
61
- "gitHead": "383781072bc17aa572b0cdffcfcf8d2d38d69f39"
61
+ "gitHead": "569dd1128d16297708b4fb3789dbc43b082c2ee9"
62
62
  }