markmap-autoloader 0.14.5-alpha.13 → 0.14.5-alpha.15
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/README.md +33 -28
- package/dist/index.js +71 -14
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -12,18 +12,23 @@ HTML:
|
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
14
|
<style>
|
|
15
|
-
.markmap
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
.markmap {
|
|
16
|
+
position: relative;
|
|
17
|
+
}
|
|
18
|
+
.markmap > svg {
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: 300px;
|
|
21
|
+
}
|
|
19
22
|
</style>
|
|
20
23
|
|
|
21
|
-
<div class="markmap"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
<div class="markmap">
|
|
25
|
+
<script type="text/template">
|
|
26
|
+
- markmap
|
|
27
|
+
- autoloader
|
|
28
|
+
- transformer
|
|
29
|
+
- view
|
|
30
|
+
</script>
|
|
31
|
+
</div>
|
|
27
32
|
```
|
|
28
33
|
|
|
29
34
|
Note that `<script type="text/template">` is optional, for the content inside to be invisible before the markmap is rendered.
|
|
@@ -44,16 +49,16 @@ Load manually:
|
|
|
44
49
|
|
|
45
50
|
```html
|
|
46
51
|
<script>
|
|
47
|
-
window.markmap = {
|
|
48
|
-
|
|
49
|
-
};
|
|
52
|
+
window.markmap = {
|
|
53
|
+
autoLoader: { manual: true },
|
|
54
|
+
};
|
|
50
55
|
</script>
|
|
51
56
|
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
|
|
52
57
|
<script>
|
|
53
|
-
// Render in 5s
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
|
|
56
|
-
}, 5000);
|
|
58
|
+
// Render in 5s
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
markmap.autoLoader.renderAll();
|
|
61
|
+
}, 5000);
|
|
57
62
|
</script>
|
|
58
63
|
```
|
|
59
64
|
|
|
@@ -61,11 +66,11 @@ Disable built-in plugins:
|
|
|
61
66
|
|
|
62
67
|
```html
|
|
63
68
|
<script>
|
|
64
|
-
window.markmap = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
+
window.markmap = {
|
|
70
|
+
autoLoader: {
|
|
71
|
+
transformPlugins: [],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
69
74
|
</script>
|
|
70
75
|
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
|
|
71
76
|
```
|
|
@@ -76,17 +81,17 @@ window.markmap = {
|
|
|
76
81
|
|
|
77
82
|
If `window.markmap.autoLoader` is defined before this package is loaded, it will be regarded as autoLoader options.
|
|
78
83
|
|
|
79
|
-
- `autoLoader.manual`
|
|
84
|
+
- `autoLoader.manual` _boolean_ default as `false`
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
Whether to render markmaps manually. If false, all elements matching `.markmap` will be rendered once this package loads or DOMContentLoaded is emitted, whichever later.
|
|
82
87
|
|
|
83
|
-
- `autoLoader.transformPlugins`
|
|
88
|
+
- `autoLoader.transformPlugins` _ITransformPlugin[]_
|
|
84
89
|
|
|
85
|
-
|
|
90
|
+
Override built-in plugins if provided. Set to `[]` to disable all built-in plugins for auto-loader.
|
|
86
91
|
|
|
87
|
-
- `autoLoader.onReady`
|
|
92
|
+
- `autoLoader.onReady` _function_
|
|
88
93
|
|
|
89
|
-
|
|
94
|
+
Callback when markmap-lib/markmap-view and their dependencies are loaded. We can tweak global options in this callback.
|
|
90
95
|
|
|
91
96
|
### markmap.autoLoader.renderAll()
|
|
92
97
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.14.5-alpha.
|
|
1
|
+
/*! markmap-autoloader v0.14.5-alpha.15+1fe26c8 | MIT License */
|
|
2
2
|
this.markmap = this.markmap || {};
|
|
3
3
|
(function (exports) {
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function _extends$1() {
|
|
7
|
+
_extends$1 = Object.assign ? Object.assign.bind() : function (target) {
|
|
8
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
for (var key in source) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
12
|
+
target[key] = source[key];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
return _extends$1.apply(this, arguments);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*! markmap-common v0.14.5-alpha.15+1fe26c8 | MIT License */
|
|
7
22
|
function _extends() {
|
|
8
23
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
9
24
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -91,6 +106,19 @@ async function loadJSItem(item, context) {
|
|
|
91
106
|
}
|
|
92
107
|
await item.loaded;
|
|
93
108
|
}
|
|
109
|
+
function loadCSSItem(item) {
|
|
110
|
+
if (item.loaded) return;
|
|
111
|
+
item.loaded = true;
|
|
112
|
+
if (item.type === 'style') {
|
|
113
|
+
document.head.append(createElement('style', {
|
|
114
|
+
textContent: item.data
|
|
115
|
+
}));
|
|
116
|
+
} else if (item.type === 'stylesheet') {
|
|
117
|
+
document.head.append(createElement('link', _extends({
|
|
118
|
+
rel: 'stylesheet'
|
|
119
|
+
}, item.data)));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
94
122
|
async function loadJS(items, context) {
|
|
95
123
|
const needPreload = items.filter(item => {
|
|
96
124
|
var _item$data2;
|
|
@@ -104,24 +132,42 @@ async function loadJS(items, context) {
|
|
|
104
132
|
await loadJSItem(item, context);
|
|
105
133
|
}
|
|
106
134
|
}
|
|
135
|
+
function loadCSS(items) {
|
|
136
|
+
for (const item of items) {
|
|
137
|
+
loadCSSItem(item);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
107
140
|
let provider = 'jsdelivr';
|
|
108
|
-
function getFullUrl(path) {
|
|
141
|
+
function getFullUrl(path, overrideProvider = provider) {
|
|
109
142
|
if (path.includes('://')) return path;
|
|
110
|
-
return cdnUrl(
|
|
143
|
+
return cdnUrl(overrideProvider, path);
|
|
111
144
|
}
|
|
112
|
-
function buildJSItem(path) {
|
|
145
|
+
function buildJSItem(path, overrideProvider) {
|
|
113
146
|
return {
|
|
114
147
|
type: 'script',
|
|
115
148
|
data: {
|
|
116
|
-
src: getFullUrl(path)
|
|
149
|
+
src: getFullUrl(path, overrideProvider)
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function buildCSSItem(path, overrideProvider) {
|
|
154
|
+
return {
|
|
155
|
+
type: 'stylesheet',
|
|
156
|
+
data: {
|
|
157
|
+
href: getFullUrl(path, overrideProvider)
|
|
117
158
|
}
|
|
118
159
|
};
|
|
119
160
|
}
|
|
120
161
|
|
|
121
|
-
var _window$markmap
|
|
162
|
+
var _window$markmap;
|
|
122
163
|
const enabled = {};
|
|
123
|
-
const
|
|
124
|
-
|
|
164
|
+
const autoLoaderOptions = _extends$1({
|
|
165
|
+
baseJs: [`d3@${"6.2.0"}`, `markmap-lib@${"0.14.5-alpha.15+1fe26c8"}`, `markmap-view@${"0.14.5-alpha.15+1fe26c8"}`, `markmap-toolbar@${process.env.TOOLBAR_VERSION}`],
|
|
166
|
+
baseCss: [`markmap-toolbar@${process.env.TOOLBAR_VERSION}/dist/style.css`],
|
|
167
|
+
manual: false,
|
|
168
|
+
toolbar: false
|
|
169
|
+
}, (_window$markmap = window.markmap) == null ? void 0 : _window$markmap.autoLoader);
|
|
170
|
+
const ready = Promise.all([loadJS(autoLoaderOptions.baseJs.map(item => typeof item === 'string' ? buildJSItem(item) : item)), loadCSS(autoLoaderOptions.baseCss.map(item => typeof item === 'string' ? buildCSSItem(item) : item))]).then(() => {
|
|
125
171
|
const {
|
|
126
172
|
markmap
|
|
127
173
|
} = window;
|
|
@@ -129,7 +175,7 @@ const ready = loadJS(((_window$markmap = window.markmap) == null || (_window$mar
|
|
|
129
175
|
style.textContent = markmap.globalCSS;
|
|
130
176
|
// Insert global CSS to body so it has higher priority than prism.css, etc.
|
|
131
177
|
document.body.prepend(style);
|
|
132
|
-
|
|
178
|
+
autoLoaderOptions.onReady == null ? void 0 : autoLoaderOptions.onReady();
|
|
133
179
|
});
|
|
134
180
|
function transform(transformer, content) {
|
|
135
181
|
const result = transformer.transform(content);
|
|
@@ -152,8 +198,8 @@ function render(el) {
|
|
|
152
198
|
const {
|
|
153
199
|
Transformer,
|
|
154
200
|
Markmap,
|
|
155
|
-
|
|
156
|
-
|
|
201
|
+
deriveOptions,
|
|
202
|
+
Toolbar
|
|
157
203
|
} = window.markmap;
|
|
158
204
|
const lines = el.textContent.split('\n');
|
|
159
205
|
let indent = Infinity;
|
|
@@ -162,12 +208,23 @@ function render(el) {
|
|
|
162
208
|
if (spaces < line.length) indent = Math.min(indent, spaces);
|
|
163
209
|
});
|
|
164
210
|
const content = lines.map(line => line.slice(indent)).join('\n').trim();
|
|
165
|
-
const transformer = new Transformer(
|
|
211
|
+
const transformer = new Transformer(autoLoaderOptions.transformPlugins);
|
|
166
212
|
el.innerHTML = '<svg></svg>';
|
|
167
213
|
const svg = el.firstChild;
|
|
168
214
|
const mm = Markmap.create(svg, {
|
|
169
215
|
embedGlobalCSS: false
|
|
170
216
|
});
|
|
217
|
+
if (autoLoaderOptions.toolbar) {
|
|
218
|
+
const {
|
|
219
|
+
el: toolbar
|
|
220
|
+
} = Toolbar.create(mm);
|
|
221
|
+
Object.assign(toolbar.style, {
|
|
222
|
+
position: 'absolute',
|
|
223
|
+
right: '20px',
|
|
224
|
+
bottom: '20px'
|
|
225
|
+
});
|
|
226
|
+
el.append(toolbar);
|
|
227
|
+
}
|
|
171
228
|
const doRender = () => {
|
|
172
229
|
const {
|
|
173
230
|
root,
|
|
@@ -188,7 +245,7 @@ async function renderAllUnder(container) {
|
|
|
188
245
|
function renderAll() {
|
|
189
246
|
return renderAllUnder(document);
|
|
190
247
|
}
|
|
191
|
-
if (!
|
|
248
|
+
if (!autoLoaderOptions.manual) {
|
|
192
249
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => {
|
|
193
250
|
renderAll();
|
|
194
251
|
});else renderAll();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-autoloader",
|
|
3
|
-
"version": "0.14.5-alpha.
|
|
3
|
+
"version": "0.14.5-alpha.15+1fe26c8",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,9 +38,10 @@
|
|
|
38
38
|
"markmap-common": "*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"markmap-common": "0.14.5-alpha.
|
|
42
|
-
"markmap-lib": "0.14.5-alpha.
|
|
43
|
-
"markmap-
|
|
41
|
+
"markmap-common": "0.14.5-alpha.15+1fe26c8",
|
|
42
|
+
"markmap-lib": "0.14.5-alpha.15+1fe26c8",
|
|
43
|
+
"markmap-toolbar": "0.14.5-alpha.15+1fe26c8",
|
|
44
|
+
"markmap-view": "0.14.5-alpha.15+1fe26c8"
|
|
44
45
|
},
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "1fe26c8234296e2188e466c7b9dbf3b7e171857d"
|
|
46
47
|
}
|