markmap-lib 0.15.9-alpha.12 → 0.15.9-alpha.16

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,10 +1,5 @@
1
1
  (function(exports, require$$0) {
2
2
  "use strict";
3
- 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';
4
- const baseJsPaths = [
5
- `d3@${"7.8.5"}/dist/d3.min.js`,
6
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
7
- ];
8
3
  const testPath = "npm2url/dist/index.cjs";
9
4
  const defaultProviders = {
10
5
  jsdelivr: (path) => `https://cdn.jsdelivr.net/npm/${path}`,
@@ -96,75 +91,6 @@
96
91
  }
97
92
  }
98
93
  }
99
- const escapeChars = {
100
- "&": "&amp;",
101
- "<": "&lt;",
102
- '"': "&quot;"
103
- };
104
- function escapeHtml$1(html2) {
105
- return html2.replace(/[&<"]/g, (m) => escapeChars[m]);
106
- }
107
- function escapeScript(content) {
108
- return content.replace(/<(\/script>)/g, "\\x3c$2");
109
- }
110
- function htmlOpen(tagName, attrs) {
111
- const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => {
112
- if (value == null || value === false)
113
- return;
114
- key = ` ${escapeHtml$1(key)}`;
115
- if (value === true)
116
- return key;
117
- return `${key}="${escapeHtml$1(value)}"`;
118
- }).filter(Boolean).join("") : "";
119
- return `<${tagName}${attrStr}>`;
120
- }
121
- function htmlClose(tagName) {
122
- return `</${tagName}>`;
123
- }
124
- function wrapHtml(tagName, content, attrs) {
125
- if (content == null)
126
- return htmlOpen(tagName, attrs);
127
- return htmlOpen(tagName, attrs) + (content || "") + htmlClose(tagName);
128
- }
129
- function buildCode(fn, args) {
130
- const params = args.map((arg) => {
131
- if (typeof arg === "function")
132
- return arg.toString();
133
- return JSON.stringify(arg ?? null);
134
- }).join(",");
135
- return `(${fn.toString()})(${params})`;
136
- }
137
- function persistJS(items, context) {
138
- return items.map((item) => {
139
- if (item.type === "script") {
140
- const { textContent: textContent2, ...rest } = item.data;
141
- return wrapHtml(
142
- "script",
143
- textContent2 || "",
144
- rest
145
- );
146
- }
147
- if (item.type === "iife") {
148
- const { fn, getParams } = item.data;
149
- return wrapHtml(
150
- "script",
151
- escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || []))
152
- );
153
- }
154
- return "";
155
- });
156
- }
157
- function persistCSS(items) {
158
- return items.map((item) => {
159
- if (item.type === "stylesheet") {
160
- return wrapHtml("link", null, {
161
- rel: "stylesheet",
162
- ...item.data
163
- });
164
- }
165
- return wrapHtml("style", item.data);
166
- });
167
- }
168
94
  Math.random().toString(36).slice(2, 8);
169
95
  function noop() {
170
96
  }
@@ -18045,9 +17971,13 @@
18045
17971
  function definePlugin(plugin2) {
18046
17972
  return plugin2;
18047
17973
  }
18048
- const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
18049
- const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
17974
+ const svgMarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>\n';
17975
+ const svgUnmarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>\n';
18050
17976
  const name$5 = "checkbox";
17977
+ const images = {
17978
+ " ": svgUnmarked.trim(),
17979
+ x: svgMarked.trim()
17980
+ };
18051
17981
  const plugin$3 = definePlugin({
18052
17982
  name: name$5,
18053
17983
  transform(transformHooks) {
@@ -18062,11 +17992,10 @@
18062
17992
  const prevType = state.tokens[i2 - 1].type;
18063
17993
  const prevPrevType = state.tokens[i2 - 2].type;
18064
17994
  if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
18065
- if (token.content.startsWith("[ ]")) {
18066
- token.content = `${svg_unmarked} ${token.content.slice(3)}`;
18067
- } else if (token.content.startsWith("[x]")) {
18068
- token.content = `${svg_marked} ${token.content.slice(3)}`;
18069
- }
17995
+ token.content = token.content.replace(
17996
+ /^\[(.)\] /,
17997
+ (m, g) => images[g] ? `${images[g]} ` : m
17998
+ );
18070
17999
  }
18071
18000
  }
18072
18001
  }
@@ -20854,7 +20783,6 @@
20854
20783
  ].map((path) => buildJSItem(path));
20855
20784
  const styles$1 = [
20856
20785
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
20857
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
20858
20786
  ].map((path) => buildCSSItem(path));
20859
20787
  const config$1 = {
20860
20788
  versions: {
@@ -21322,56 +21250,13 @@
21322
21250
  const keys = this.plugins.map((plugin2) => plugin2.name).filter((name2) => features[name2]);
21323
21251
  return this.getAssets(keys);
21324
21252
  }
21325
- fillTemplate(root2, assets, extra) {
21326
- extra = {
21327
- ...extra
21328
- };
21329
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
21330
- const { scripts, styles: styles2 } = assets;
21331
- const cssList = [...styles2 ? persistCSS(styles2) : []];
21332
- const context = {
21333
- getMarkmap: () => window.markmap,
21334
- getOptions: extra.getOptions,
21335
- jsonOptions: extra.jsonOptions,
21336
- root: root2
21337
- };
21338
- const jsList = [
21339
- ...persistJS(
21340
- [
21341
- ...extra.baseJs,
21342
- ...scripts || [],
21343
- {
21344
- type: "iife",
21345
- data: {
21346
- fn: (getMarkmap, getOptions, root22, jsonOptions) => {
21347
- const markmap = getMarkmap();
21348
- window.mm = markmap.Markmap.create(
21349
- "svg#mindmap",
21350
- (getOptions || markmap.deriveOptions)(jsonOptions),
21351
- root22
21352
- );
21353
- },
21354
- getParams: ({ getMarkmap, getOptions, root: root22, jsonOptions }) => {
21355
- return [getMarkmap, getOptions, root22, jsonOptions];
21356
- }
21357
- }
21358
- }
21359
- ],
21360
- context
21361
- )
21362
- ];
21363
- const html2 = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
21364
- return html2;
21365
- }
21366
21253
  }
21367
21254
  const transformerVersions = {
21368
- "markmap-lib": "process.env.VERSION",
21255
+ "markmap-lib": "0.15.9-alpha.16+01ebaff",
21369
21256
  d3: "7.8.5"
21370
21257
  };
21371
21258
  exports.Transformer = Transformer;
21372
- exports.baseJsPaths = baseJsPaths;
21373
21259
  exports.builtInPlugins = builtInPlugins;
21374
- exports.template = template;
21375
21260
  exports.transformerVersions = transformerVersions;
21376
21261
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
21377
21262
  })(this.markmap = this.markmap || {}, window.katex);
@@ -1,13 +1,8 @@
1
- import { Hook, buildJSItem, buildCSSItem, loadJS, noop, wrapFunction, UrlBuilder, persistCSS, persistJS } from "markmap-common";
1
+ import { Hook, buildJSItem, buildCSSItem, loadJS, noop, wrapFunction, UrlBuilder } from "markmap-common";
2
2
  import { buildTree } from "markmap-html-parser";
3
3
  import { Remarkable } from "remarkable";
4
4
  import yaml from "js-yaml";
5
5
  import remarkableKatex from "remarkable-katex";
6
- 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';
7
- const baseJsPaths = [
8
- `d3@${"7.8.5"}/dist/d3.min.js`,
9
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
10
- ];
11
6
  function createTransformHooks(transformer) {
12
7
  return {
13
8
  transformer,
@@ -21,9 +16,13 @@ function createTransformHooks(transformer) {
21
16
  function definePlugin(plugin2) {
22
17
  return plugin2;
23
18
  }
24
- const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
25
- const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
19
+ const svgMarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>\n';
20
+ const svgUnmarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>\n';
26
21
  const name$5 = "checkbox";
22
+ const images = {
23
+ " ": svgUnmarked.trim(),
24
+ x: svgMarked.trim()
25
+ };
27
26
  const plugin$3 = definePlugin({
28
27
  name: name$5,
29
28
  transform(transformHooks) {
@@ -38,11 +37,10 @@ const plugin$3 = definePlugin({
38
37
  const prevType = state.tokens[i - 1].type;
39
38
  const prevPrevType = state.tokens[i - 2].type;
40
39
  if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
41
- if (token.content.startsWith("[ ]")) {
42
- token.content = `${svg_unmarked} ${token.content.slice(3)}`;
43
- } else if (token.content.startsWith("[x]")) {
44
- token.content = `${svg_marked} ${token.content.slice(3)}`;
45
- }
40
+ token.content = token.content.replace(
41
+ /^\[(.)\] /,
42
+ (m, g) => images[g] ? `${images[g]} ` : m
43
+ );
46
44
  }
47
45
  }
48
46
  }
@@ -141,7 +139,6 @@ const preloadScripts$1 = [
141
139
  ].map((path) => buildJSItem(path));
142
140
  const styles$1 = [
143
141
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
144
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
145
142
  ].map((path) => buildCSSItem(path));
146
143
  const config$1 = {
147
144
  versions: {
@@ -479,56 +476,13 @@ class Transformer {
479
476
  const keys = this.plugins.map((plugin2) => plugin2.name).filter((name2) => features[name2]);
480
477
  return this.getAssets(keys);
481
478
  }
482
- fillTemplate(root, assets, extra) {
483
- extra = {
484
- ...extra
485
- };
486
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
487
- const { scripts, styles: styles2 } = assets;
488
- const cssList = [...styles2 ? persistCSS(styles2) : []];
489
- const context = {
490
- getMarkmap: () => window.markmap,
491
- getOptions: extra.getOptions,
492
- jsonOptions: extra.jsonOptions,
493
- root
494
- };
495
- const jsList = [
496
- ...persistJS(
497
- [
498
- ...extra.baseJs,
499
- ...scripts || [],
500
- {
501
- type: "iife",
502
- data: {
503
- fn: (getMarkmap, getOptions, root2, jsonOptions) => {
504
- const markmap = getMarkmap();
505
- window.mm = markmap.Markmap.create(
506
- "svg#mindmap",
507
- (getOptions || markmap.deriveOptions)(jsonOptions),
508
- root2
509
- );
510
- },
511
- getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
512
- return [getMarkmap, getOptions, root2, jsonOptions];
513
- }
514
- }
515
- }
516
- ],
517
- context
518
- )
519
- ];
520
- const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
521
- return html;
522
- }
523
479
  }
524
480
  const transformerVersions = {
525
- "markmap-lib": "process.env.VERSION",
481
+ "markmap-lib": "0.15.9-alpha.16+01ebaff",
526
482
  d3: "7.8.5"
527
483
  };
528
484
  export {
529
485
  Transformer,
530
- baseJsPaths,
531
486
  builtInPlugins,
532
- template,
533
487
  transformerVersions
534
488
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from './types';
2
- export * from './constants';
3
2
  export * from './transform';
4
3
  export declare const transformerVersions: {
5
- 'markmap-lib': string;
4
+ 'markmap-lib': string | undefined;
6
5
  d3: string | undefined;
7
6
  };
package/dist/index.js CHANGED
@@ -7,11 +7,6 @@ const plugins = require("./plugins.js");
7
7
  require("js-yaml");
8
8
  require("highlight.js");
9
9
  require("remarkable-katex");
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';
11
- const baseJsPaths = [
12
- `d3@${"7.8.5"}/dist/d3.min.js`,
13
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
14
- ];
15
10
  function patchJSItem(urlBuilder, item) {
16
11
  if (item.type === "script" && item.data.src) {
17
12
  return {
@@ -126,54 +121,11 @@ class Transformer {
126
121
  const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
127
122
  return this.getAssets(keys);
128
123
  }
129
- fillTemplate(root, assets, extra) {
130
- extra = {
131
- ...extra
132
- };
133
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
134
- const { scripts, styles } = assets;
135
- const cssList = [...styles ? markmapCommon.persistCSS(styles) : []];
136
- const context = {
137
- getMarkmap: () => window.markmap,
138
- getOptions: extra.getOptions,
139
- jsonOptions: extra.jsonOptions,
140
- root
141
- };
142
- const jsList = [
143
- ...markmapCommon.persistJS(
144
- [
145
- ...extra.baseJs,
146
- ...scripts || [],
147
- {
148
- type: "iife",
149
- data: {
150
- fn: (getMarkmap, getOptions, root2, jsonOptions) => {
151
- const markmap = getMarkmap();
152
- window.mm = markmap.Markmap.create(
153
- "svg#mindmap",
154
- (getOptions || markmap.deriveOptions)(jsonOptions),
155
- root2
156
- );
157
- },
158
- getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
159
- return [getMarkmap, getOptions, root2, jsonOptions];
160
- }
161
- }
162
- }
163
- ],
164
- context
165
- )
166
- ];
167
- const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
168
- return html;
169
- }
170
124
  }
171
125
  const transformerVersions = {
172
- "markmap-lib": "process.env.VERSION",
126
+ "markmap-lib": "0.15.9-alpha.16+01ebaff",
173
127
  d3: "7.8.5"
174
128
  };
175
129
  exports.Transformer = Transformer;
176
- exports.baseJsPaths = baseJsPaths;
177
130
  exports.builtInPlugins = builtInPlugins;
178
- exports.template = template;
179
131
  exports.transformerVersions = transformerVersions;
package/dist/index.mjs CHANGED
@@ -1,15 +1,10 @@
1
- import { UrlBuilder, wrapFunction, buildJSItem, persistCSS, persistJS } from "markmap-common";
1
+ import { UrlBuilder, wrapFunction } from "markmap-common";
2
2
  import { buildTree } from "markmap-html-parser";
3
3
  import { Remarkable } from "remarkable";
4
4
  import { plugins, createTransformHooks } from "./plugins.mjs";
5
5
  import "js-yaml";
6
6
  import "highlight.js";
7
7
  import "remarkable-katex";
8
- 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';
9
- const baseJsPaths = [
10
- `d3@${"7.8.5"}/dist/d3.min.js`,
11
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
12
- ];
13
8
  function patchJSItem(urlBuilder, item) {
14
9
  if (item.type === "script" && item.data.src) {
15
10
  return {
@@ -124,56 +119,13 @@ class Transformer {
124
119
  const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
125
120
  return this.getAssets(keys);
126
121
  }
127
- fillTemplate(root, assets, extra) {
128
- extra = {
129
- ...extra
130
- };
131
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
132
- const { scripts, styles } = assets;
133
- const cssList = [...styles ? persistCSS(styles) : []];
134
- const context = {
135
- getMarkmap: () => window.markmap,
136
- getOptions: extra.getOptions,
137
- jsonOptions: extra.jsonOptions,
138
- root
139
- };
140
- const jsList = [
141
- ...persistJS(
142
- [
143
- ...extra.baseJs,
144
- ...scripts || [],
145
- {
146
- type: "iife",
147
- data: {
148
- fn: (getMarkmap, getOptions, root2, jsonOptions) => {
149
- const markmap = getMarkmap();
150
- window.mm = markmap.Markmap.create(
151
- "svg#mindmap",
152
- (getOptions || markmap.deriveOptions)(jsonOptions),
153
- root2
154
- );
155
- },
156
- getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
157
- return [getMarkmap, getOptions, root2, jsonOptions];
158
- }
159
- }
160
- }
161
- ],
162
- context
163
- )
164
- ];
165
- const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
166
- return html;
167
- }
168
122
  }
169
123
  const transformerVersions = {
170
- "markmap-lib": "process.env.VERSION",
124
+ "markmap-lib": "0.15.9-alpha.16+01ebaff",
171
125
  d3: "7.8.5"
172
126
  };
173
127
  export {
174
128
  Transformer,
175
- baseJsPaths,
176
129
  builtInPlugins,
177
- template,
178
130
  transformerVersions
179
131
  };
@@ -3,11 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const markmapCommon = require("markmap-common");
4
4
  const markmapHtmlParser = require("markmap-html-parser");
5
5
  const remarkable = require("remarkable");
6
- 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';
7
- const baseJsPaths = [
8
- `d3@${"7.8.5"}/dist/d3.min.js`,
9
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
10
- ];
11
6
  function createTransformHooks(transformer) {
12
7
  return {
13
8
  transformer,
@@ -132,54 +127,11 @@ class Transformer {
132
127
  const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
133
128
  return this.getAssets(keys);
134
129
  }
135
- fillTemplate(root, assets, extra) {
136
- extra = {
137
- ...extra
138
- };
139
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
140
- const { scripts, styles } = assets;
141
- const cssList = [...styles ? markmapCommon.persistCSS(styles) : []];
142
- const context = {
143
- getMarkmap: () => window.markmap,
144
- getOptions: extra.getOptions,
145
- jsonOptions: extra.jsonOptions,
146
- root
147
- };
148
- const jsList = [
149
- ...markmapCommon.persistJS(
150
- [
151
- ...extra.baseJs,
152
- ...scripts || [],
153
- {
154
- type: "iife",
155
- data: {
156
- fn: (getMarkmap, getOptions, root2, jsonOptions) => {
157
- const markmap = getMarkmap();
158
- window.mm = markmap.Markmap.create(
159
- "svg#mindmap",
160
- (getOptions || markmap.deriveOptions)(jsonOptions),
161
- root2
162
- );
163
- },
164
- getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
165
- return [getMarkmap, getOptions, root2, jsonOptions];
166
- }
167
- }
168
- }
169
- ],
170
- context
171
- )
172
- ];
173
- const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
174
- return html;
175
- }
176
130
  }
177
131
  const transformerVersions = {
178
- "markmap-lib": "process.env.VERSION",
132
+ "markmap-lib": "0.15.9-alpha.16+01ebaff",
179
133
  d3: "7.8.5"
180
134
  };
181
135
  exports.Transformer = Transformer;
182
- exports.baseJsPaths = baseJsPaths;
183
136
  exports.builtInPlugins = builtInPlugins;
184
- exports.template = template;
185
137
  exports.transformerVersions = transformerVersions;
@@ -1,11 +1,6 @@
1
- import { Hook, UrlBuilder, wrapFunction, buildJSItem, persistCSS, persistJS } from "markmap-common";
1
+ import { Hook, UrlBuilder, wrapFunction } from "markmap-common";
2
2
  import { buildTree } from "markmap-html-parser";
3
3
  import { Remarkable } from "remarkable";
4
- 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';
5
- const baseJsPaths = [
6
- `d3@${"7.8.5"}/dist/d3.min.js`,
7
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
8
- ];
9
4
  function createTransformHooks(transformer) {
10
5
  return {
11
6
  transformer,
@@ -130,56 +125,13 @@ class Transformer {
130
125
  const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
131
126
  return this.getAssets(keys);
132
127
  }
133
- fillTemplate(root, assets, extra) {
134
- extra = {
135
- ...extra
136
- };
137
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
138
- const { scripts, styles } = assets;
139
- const cssList = [...styles ? persistCSS(styles) : []];
140
- const context = {
141
- getMarkmap: () => window.markmap,
142
- getOptions: extra.getOptions,
143
- jsonOptions: extra.jsonOptions,
144
- root
145
- };
146
- const jsList = [
147
- ...persistJS(
148
- [
149
- ...extra.baseJs,
150
- ...scripts || [],
151
- {
152
- type: "iife",
153
- data: {
154
- fn: (getMarkmap, getOptions, root2, jsonOptions) => {
155
- const markmap = getMarkmap();
156
- window.mm = markmap.Markmap.create(
157
- "svg#mindmap",
158
- (getOptions || markmap.deriveOptions)(jsonOptions),
159
- root2
160
- );
161
- },
162
- getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
163
- return [getMarkmap, getOptions, root2, jsonOptions];
164
- }
165
- }
166
- }
167
- ],
168
- context
169
- )
170
- ];
171
- const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
172
- return html;
173
- }
174
128
  }
175
129
  const transformerVersions = {
176
- "markmap-lib": "process.env.VERSION",
130
+ "markmap-lib": "0.15.9-alpha.16+01ebaff",
177
131
  d3: "7.8.5"
178
132
  };
179
133
  export {
180
134
  Transformer,
181
- baseJsPaths,
182
135
  builtInPlugins,
183
- template,
184
136
  transformerVersions
185
137
  };
package/dist/plugins.js CHANGED
@@ -17,9 +17,13 @@ function createTransformHooks(transformer) {
17
17
  function definePlugin(plugin2) {
18
18
  return plugin2;
19
19
  }
20
- const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
21
- const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
20
+ const svgMarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>\n';
21
+ const svgUnmarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>\n';
22
22
  const name$5 = "checkbox";
23
+ const images = {
24
+ " ": svgUnmarked.trim(),
25
+ x: svgMarked.trim()
26
+ };
23
27
  const plugin$3 = definePlugin({
24
28
  name: name$5,
25
29
  transform(transformHooks) {
@@ -34,11 +38,10 @@ const plugin$3 = definePlugin({
34
38
  const prevType = state.tokens[i - 1].type;
35
39
  const prevPrevType = state.tokens[i - 2].type;
36
40
  if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
37
- if (token.content.startsWith("[ ]")) {
38
- token.content = `${svg_unmarked} ${token.content.slice(3)}`;
39
- } else if (token.content.startsWith("[x]")) {
40
- token.content = `${svg_marked} ${token.content.slice(3)}`;
41
- }
41
+ token.content = token.content.replace(
42
+ /^\[(.)\] /,
43
+ (m, g) => images[g] ? `${images[g]} ` : m
44
+ );
42
45
  }
43
46
  }
44
47
  }
@@ -113,7 +116,6 @@ const preloadScripts$1 = [
113
116
  ].map((path) => markmapCommon.buildJSItem(path));
114
117
  const styles$1 = [
115
118
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
116
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
117
119
  ].map((path) => markmapCommon.buildCSSItem(path));
118
120
  const config$1 = {
119
121
  versions: {
package/dist/plugins.mjs CHANGED
@@ -15,9 +15,13 @@ function createTransformHooks(transformer) {
15
15
  function definePlugin(plugin2) {
16
16
  return plugin2;
17
17
  }
18
- const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
19
- const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
18
+ const svgMarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>\n';
19
+ const svgUnmarked = '<svg width="16" height="16" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>\n';
20
20
  const name$5 = "checkbox";
21
+ const images = {
22
+ " ": svgUnmarked.trim(),
23
+ x: svgMarked.trim()
24
+ };
21
25
  const plugin$3 = definePlugin({
22
26
  name: name$5,
23
27
  transform(transformHooks) {
@@ -32,11 +36,10 @@ const plugin$3 = definePlugin({
32
36
  const prevType = state.tokens[i - 1].type;
33
37
  const prevPrevType = state.tokens[i - 2].type;
34
38
  if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
35
- if (token.content.startsWith("[ ]")) {
36
- token.content = `${svg_unmarked} ${token.content.slice(3)}`;
37
- } else if (token.content.startsWith("[x]")) {
38
- token.content = `${svg_marked} ${token.content.slice(3)}`;
39
- }
39
+ token.content = token.content.replace(
40
+ /^\[(.)\] /,
41
+ (m, g) => images[g] ? `${images[g]} ` : m
42
+ );
40
43
  }
41
44
  }
42
45
  }
@@ -111,7 +114,6 @@ const preloadScripts$1 = [
111
114
  ].map((path) => buildJSItem(path));
112
115
  const styles$1 = [
113
116
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
114
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
115
117
  ].map((path) => buildCSSItem(path));
116
118
  const config$1 = {
117
119
  versions: {
@@ -1,7 +1,7 @@
1
- import { IMarkmapOptions, IPureNode, JSItem, UrlBuilder } from 'markmap-common';
1
+ import { UrlBuilder } from 'markmap-common';
2
2
  import { IHtmlParserOptions } from 'markmap-html-parser';
3
3
  import { Remarkable } from 'remarkable';
4
- import { IAssets, IFeatures, ITransformHooks, ITransformPlugin, ITransformResult, ITransformer, IMarkmapJSONOptions } from './types';
4
+ import { IAssets, IFeatures, ITransformHooks, ITransformPlugin, ITransformResult, ITransformer } from './types';
5
5
  export declare const builtInPlugins: ITransformPlugin[];
6
6
  export declare class Transformer implements ITransformer {
7
7
  hooks: ITransformHooks;
@@ -19,9 +19,4 @@ export declare class Transformer implements ITransformer {
19
19
  * Get used assets by features object returned by `transform`.
20
20
  */
21
21
  getUsedAssets(features: IFeatures): IAssets;
22
- fillTemplate(root: IPureNode | null, assets: IAssets, extra?: {
23
- baseJs?: JSItem[];
24
- jsonOptions?: IMarkmapJSONOptions;
25
- getOptions?: (jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>;
26
- }): string;
27
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.15.9-alpha.12+e2132d2",
3
+ "version": "0.15.9-alpha.16+01ebaff",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -59,8 +59,7 @@
59
59
  "devDependencies": {
60
60
  "@highlightjs/cdn-assets": "^11.8.0",
61
61
  "@types/remarkable": "^2.0.3",
62
- "markmap-common": "0.15.9-alpha.12+e2132d2",
63
- "markmap-view": "0.15.9-alpha.12+e2132d2",
62
+ "markmap-common": "0.15.9-alpha.16+01ebaff",
64
63
  "webfontloader": "^1.6.28"
65
64
  },
66
65
  "dependencies": {
@@ -68,7 +67,8 @@
68
67
  "highlight.js": "^11.8.0",
69
68
  "js-yaml": "^4.1.0",
70
69
  "katex": "^0.16.8",
71
- "markmap-html-parser": "0.15.9-alpha.12+e2132d2",
70
+ "markmap-html-parser": "0.15.9-alpha.16+01ebaff",
71
+ "markmap-view": "0.15.9-alpha.16+01ebaff",
72
72
  "prismjs": "^1.29.0",
73
73
  "remarkable": "^2.0.1",
74
74
  "remarkable-katex": "^1.2.1"
@@ -83,8 +83,12 @@
83
83
  {
84
84
  "rootMode": "upward"
85
85
  }
86
- ]
86
+ ],
87
+ "\\.svg$": "<rootDir>/scripts/file-transform.js"
88
+ },
89
+ "moduleNameMapper": {
90
+ "^(.*\\.svg)\\?raw$": "$1"
87
91
  }
88
92
  },
89
- "gitHead": "e2132d2615f5b19e246478dc9dbb6b6ca4d6d75f"
93
+ "gitHead": "01ebaffc9c373b822b5c78808fff8f009843bd4d"
90
94
  }
@@ -1,2 +0,0 @@
1
- export declare const template: string;
2
- export declare const baseJsPaths: string[];