markmap-cli 0.14.5-alpha.17 → 0.14.5-alpha.19

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -7
  2. package/package.json +14 -14
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-cli v0.14.5-alpha.17+0d6a717 | MIT License */
1
+ /*! markmap-cli v0.14.5-alpha.19+5323905 | MIT License */
2
2
  'use strict';
3
3
 
4
4
  var fs = require('fs');
@@ -27,7 +27,7 @@ function _extends() {
27
27
  return _extends.apply(this, arguments);
28
28
  }
29
29
 
30
- const TOOLBAR_VERSION = "0.14.5-alpha.17+0d6a717";
30
+ const TOOLBAR_VERSION = "0.14.5-alpha.19+5323905";
31
31
  const TOOLBAR_CSS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/style.css`;
32
32
  const TOOLBAR_JS = `markmap-toolbar@${TOOLBAR_VERSION}/dist/index.js`;
33
33
  const renderToolbar = () => {
@@ -55,9 +55,18 @@ function addToolbar(assets) {
55
55
  }]
56
56
  };
57
57
  }
58
+ function removeVersionString(part) {
59
+ return part.replace(/@.+$/, '');
60
+ }
58
61
  function localProvider(path) {
59
62
  const parts = path.split('/');
60
- parts[0] = parts[0].replace(/@[\d.]+$/, '');
63
+ // xxx@0.0.0-alpha.0+aaaaaa
64
+ // @scope/xxx@0.0.0-alpha.0+aaaaaa
65
+ if (parts[0].startsWith('@')) {
66
+ parts[1] = removeVersionString(parts[1]);
67
+ } else {
68
+ parts[0] = removeVersionString(parts[0]);
69
+ }
61
70
  path = parts.join('/');
62
71
  return `/node_modules/${path}`;
63
72
  }
@@ -145,6 +154,9 @@ class FileSystemProvider extends BufferContentProvider {
145
154
  }
146
155
  function startServer(paddingBottom) {
147
156
  let ts = 0;
157
+ let root;
158
+ let line;
159
+ let offset = 0;
148
160
  const {
149
161
  mm,
150
162
  markmap
@@ -153,19 +165,43 @@ function startServer(paddingBottom) {
153
165
  function refresh() {
154
166
  fetch(`/data?ts=${ts}`).then(res => res.json()).then(res => {
155
167
  if (res.ts && res.ts > ts && res.result) {
156
- const {
168
+ var _frontmatter;
169
+ let frontmatter;
170
+ ({
157
171
  root,
158
172
  frontmatter,
159
- contentLineOffset
160
- } = res.result;
161
- mm.setOptions(markmap.deriveOptions(frontmatter == null ? void 0 : frontmatter.markmap));
173
+ contentLineOffset: offset
174
+ } = res.result);
175
+ mm.setOptions(markmap.deriveOptions((_frontmatter = frontmatter) == null ? void 0 : _frontmatter.markmap));
162
176
  mm.setData(root);
163
177
  if (!ts) mm.fit();
164
178
  ts = res.ts;
179
+ line = -1;
180
+ }
181
+ if (root && res.line != null && line !== res.line) {
182
+ line = res.line;
183
+ const active = findActiveNode();
184
+ if (active) mm.ensureView(active, {
185
+ bottom: paddingBottom
186
+ });
165
187
  }
166
188
  setTimeout(refresh, 300);
167
189
  });
168
190
  }
191
+ function findActiveNode() {
192
+ const lineWithoutFrontmatter = line - offset;
193
+ let best;
194
+ dfs(root);
195
+ return best;
196
+ function dfs(node) {
197
+ var _node$payload, _node$children;
198
+ const lines = (_node$payload = node.payload) == null ? void 0 : _node$payload.lines;
199
+ if (lines && lines[0] <= lineWithoutFrontmatter && lineWithoutFrontmatter < lines[1]) {
200
+ best = node;
201
+ }
202
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(dfs);
203
+ }
204
+ }
169
205
  }
170
206
  function setUpServer(transformer, provider, options) {
171
207
  let assets = transformer.getAssets();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-cli",
3
- "version": "0.14.5-alpha.17+0d6a717",
3
+ "version": "0.14.5-alpha.19+5323905",
4
4
  "description": "Create markmaps from CLI",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -38,20 +38,20 @@
38
38
  ],
39
39
  "typings": "types/index.d.ts",
40
40
  "dependencies": {
41
- "@babel/runtime": "^7.13.10",
42
- "chokidar": "^3.5.1",
43
- "commander": "^7.1.0",
44
- "d3": "^6.2.0",
45
- "katex": "^0.16.0",
46
- "koa": "^2.13.1",
47
- "markmap-common": "0.14.2",
48
- "markmap-lib": "0.14.5-alpha.17+0d6a717",
49
- "markmap-toolbar": "0.14.5-alpha.17+0d6a717",
50
- "markmap-view": "0.14.5-alpha.17+0d6a717",
51
- "open": "^8.0.3",
52
- "prismjs": "^1.28.0",
41
+ "@babel/runtime": "^7.22.6",
42
+ "chokidar": "^3.5.3",
43
+ "commander": "^7.2.0",
44
+ "d3": "^7.8.5",
45
+ "katex": "^0.16.8",
46
+ "koa": "^2.14.2",
47
+ "markmap-common": "0.14.5-alpha.19+5323905",
48
+ "markmap-lib": "0.14.5-alpha.19+5323905",
49
+ "markmap-toolbar": "0.14.5-alpha.19+5323905",
50
+ "markmap-view": "0.14.5-alpha.19+5323905",
51
+ "open": "^8.4.2",
52
+ "prismjs": "^1.29.0",
53
53
  "update-notifier": "^5.1.0",
54
54
  "webfontloader": "^1.6.28"
55
55
  },
56
- "gitHead": "0d6a717b05c622a23faa501e79a7da7cda3ea0b6"
56
+ "gitHead": "532390588885518c11fa50b8a77c0694821cfecf"
57
57
  }