markmap-autoloader 0.14.4-alpha.1 → 0.15.0-alpha.0
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 +8 -2
- package/dist/index.js +35 -47
- package/package.json +10 -13
- package/dist/index.min.js +0 -3
package/README.md
CHANGED
|
@@ -28,10 +28,16 @@ HTML:
|
|
|
28
28
|
|
|
29
29
|
Note that `<script type="text/template">` is optional, for the content inside to be invisible before the markmap is rendered.
|
|
30
30
|
|
|
31
|
-
Autoload all elements matching `.markmap
|
|
31
|
+
Autoload all elements matching `.markmap`, using latest autoloader version:
|
|
32
32
|
|
|
33
33
|
```html
|
|
34
|
-
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
|
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@latest"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
To use specific version (here: `0.14.3`) of `mark-autoloader`:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@0.14.3"></script>
|
|
35
41
|
```
|
|
36
42
|
|
|
37
43
|
Load manually:
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,63 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.
|
|
1
|
+
/*! markmap-autoloader v0.15.0-alpha.0 | MIT License */
|
|
2
2
|
this.markmap = this.markmap || {};
|
|
3
3
|
(function (exports) {
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
/*! markmap-common v0.
|
|
7
|
-
|
|
6
|
+
/*! markmap-common v0.15.0-alpha.0 | MIT License */
|
|
8
7
|
function _extends() {
|
|
9
|
-
_extends = Object.assign
|
|
8
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
10
9
|
for (var i = 1; i < arguments.length; i++) {
|
|
11
10
|
var source = arguments[i];
|
|
12
|
-
|
|
13
11
|
for (var key in source) {
|
|
14
12
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
15
13
|
target[key] = source[key];
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
return target;
|
|
21
18
|
};
|
|
22
|
-
|
|
23
19
|
return _extends.apply(this, arguments);
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
Math.random().toString(36).slice(2, 8);
|
|
27
|
-
|
|
28
22
|
function memoize(fn) {
|
|
29
23
|
const cache = {};
|
|
30
24
|
return function memoized(...args) {
|
|
31
25
|
const key = `${args[0]}`;
|
|
32
26
|
let data = cache[key];
|
|
33
|
-
|
|
34
27
|
if (!data) {
|
|
35
28
|
data = {
|
|
36
29
|
value: fn(...args)
|
|
37
30
|
};
|
|
38
31
|
cache[key] = data;
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
return data.value;
|
|
42
34
|
};
|
|
43
35
|
}
|
|
44
|
-
|
|
36
|
+
const providers = {
|
|
37
|
+
jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
|
|
38
|
+
unpkg: path => `https://unpkg.com/${path}`
|
|
39
|
+
};
|
|
40
|
+
function cdnUrl(provider, path) {
|
|
41
|
+
const factory = providers[provider];
|
|
42
|
+
if (!factory) {
|
|
43
|
+
throw new Error(`Provider ${provider} not found`);
|
|
44
|
+
}
|
|
45
|
+
return factory(path);
|
|
46
|
+
}
|
|
45
47
|
function createElement(tagName, props, attrs) {
|
|
46
48
|
const el = document.createElement(tagName);
|
|
47
|
-
|
|
48
49
|
if (props) {
|
|
49
50
|
Object.entries(props).forEach(([key, value]) => {
|
|
50
51
|
el[key] = value;
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
|
|
54
54
|
if (attrs) {
|
|
55
55
|
Object.entries(attrs).forEach(([key, value]) => {
|
|
56
56
|
el.setAttribute(key, value);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
|
|
60
59
|
return el;
|
|
61
60
|
}
|
|
62
|
-
|
|
63
61
|
const memoizedPreloadJS = memoize(url => {
|
|
64
62
|
document.head.append(createElement('link', {
|
|
65
63
|
rel: 'preload',
|
|
@@ -67,24 +65,21 @@ const memoizedPreloadJS = memoize(url => {
|
|
|
67
65
|
href: url
|
|
68
66
|
}));
|
|
69
67
|
});
|
|
70
|
-
|
|
71
68
|
async function loadJSItem(item, context) {
|
|
72
69
|
if (!item.loaded) {
|
|
73
70
|
if (item.type === 'script') {
|
|
74
71
|
item.loaded = new Promise((resolve, reject) => {
|
|
75
72
|
var _item$data;
|
|
76
|
-
|
|
77
73
|
document.head.append(createElement('script', _extends({}, item.data, {
|
|
78
74
|
onload: resolve,
|
|
79
75
|
onerror: reject
|
|
80
|
-
})));
|
|
81
|
-
|
|
76
|
+
})));
|
|
77
|
+
// Run inline script synchronously
|
|
82
78
|
if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
|
|
83
79
|
}).then(() => {
|
|
84
80
|
item.loaded = true;
|
|
85
81
|
});
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
if (item.type === 'iife') {
|
|
89
84
|
const {
|
|
90
85
|
fn,
|
|
@@ -94,51 +89,48 @@ async function loadJSItem(item, context) {
|
|
|
94
89
|
item.loaded = true;
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
|
-
|
|
98
92
|
await item.loaded;
|
|
99
93
|
}
|
|
100
|
-
|
|
101
94
|
async function loadJS(items, context) {
|
|
102
95
|
const needPreload = items.filter(item => {
|
|
103
96
|
var _item$data2;
|
|
104
|
-
|
|
105
97
|
return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
|
|
106
98
|
});
|
|
107
99
|
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
|
|
108
100
|
context = _extends({
|
|
109
101
|
getMarkmap: () => window.markmap
|
|
110
102
|
}, context);
|
|
111
|
-
|
|
112
103
|
for (const item of items) {
|
|
113
104
|
await loadJSItem(item, context);
|
|
114
105
|
}
|
|
115
106
|
}
|
|
107
|
+
let provider = 'jsdelivr';
|
|
108
|
+
function getFullUrl(path) {
|
|
109
|
+
if (path.includes('://')) return path;
|
|
110
|
+
return cdnUrl(provider, path);
|
|
111
|
+
}
|
|
112
|
+
function buildJSItem(path) {
|
|
113
|
+
return {
|
|
114
|
+
type: 'script',
|
|
115
|
+
data: {
|
|
116
|
+
src: getFullUrl(path)
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
116
120
|
|
|
117
|
-
var _window$markmap, _window$
|
|
121
|
+
var _window$markmap, _window$markmap2;
|
|
118
122
|
const enabled = {};
|
|
119
|
-
const ready = loadJS(((_window$markmap = window.markmap) == null
|
|
120
|
-
type: 'script',
|
|
121
|
-
data: {
|
|
122
|
-
src: `https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`
|
|
123
|
-
}
|
|
124
|
-
}, {
|
|
125
|
-
type: 'script',
|
|
126
|
-
data: {
|
|
127
|
-
src: `https://cdn.jsdelivr.net/combine/npm/markmap-lib@${"0.14.4-alpha.1+8a57fea"},npm/markmap-view@${"0.14.4-alpha.1+8a57fea"}`
|
|
128
|
-
}
|
|
129
|
-
}]).then(() => {
|
|
123
|
+
const ready = loadJS(((_window$markmap = window.markmap) == null || (_window$markmap = _window$markmap.autoLoader) == null ? void 0 : _window$markmap.baseJs) || [`d3@${"6.2.0"}`, `markmap-lib@${"0.15.0-alpha.0"}`, `markmap-view@${"0.15.0-alpha.0"}`].map(buildJSItem)).then(() => {
|
|
130
124
|
var _markmap$autoLoader;
|
|
131
|
-
|
|
132
125
|
const {
|
|
133
126
|
markmap
|
|
134
127
|
} = window;
|
|
135
128
|
const style = document.createElement('style');
|
|
136
|
-
style.textContent = markmap.globalCSS;
|
|
137
|
-
|
|
129
|
+
style.textContent = markmap.globalCSS;
|
|
130
|
+
// Insert global CSS to body so it has higher priority than prism.css, etc.
|
|
138
131
|
document.body.prepend(style);
|
|
139
|
-
(_markmap$autoLoader = markmap.autoLoader) == null
|
|
132
|
+
(_markmap$autoLoader = markmap.autoLoader) == null || _markmap$autoLoader.onReady == null ? void 0 : _markmap$autoLoader.onReady();
|
|
140
133
|
});
|
|
141
|
-
|
|
142
134
|
function transform(transformer, content) {
|
|
143
135
|
const result = transformer.transform(content);
|
|
144
136
|
const keys = Object.keys(result.features).filter(key => !enabled[key]);
|
|
@@ -156,7 +148,6 @@ function transform(transformer, content) {
|
|
|
156
148
|
if (scripts) markmap.loadJS(scripts);
|
|
157
149
|
return result;
|
|
158
150
|
}
|
|
159
|
-
|
|
160
151
|
function render(el) {
|
|
161
152
|
const {
|
|
162
153
|
Transformer,
|
|
@@ -177,7 +168,6 @@ function render(el) {
|
|
|
177
168
|
const mm = Markmap.create(svg, {
|
|
178
169
|
embedGlobalCSS: false
|
|
179
170
|
});
|
|
180
|
-
|
|
181
171
|
const doRender = () => {
|
|
182
172
|
const {
|
|
183
173
|
root,
|
|
@@ -188,7 +178,6 @@ function render(el) {
|
|
|
188
178
|
mm.setData(root, frontmatterOptions);
|
|
189
179
|
mm.fit();
|
|
190
180
|
};
|
|
191
|
-
|
|
192
181
|
transformer.hooks.retransform.tap(doRender);
|
|
193
182
|
doRender();
|
|
194
183
|
}
|
|
@@ -199,8 +188,7 @@ async function renderAllUnder(container) {
|
|
|
199
188
|
function renderAll() {
|
|
200
189
|
return renderAllUnder(document);
|
|
201
190
|
}
|
|
202
|
-
|
|
203
|
-
if (!((_window$markmap2 = window.markmap) != null && (_window$markmap2$auto = _window$markmap2.autoLoader) != null && _window$markmap2$auto.manual)) {
|
|
191
|
+
if (!((_window$markmap2 = window.markmap) != null && (_window$markmap2 = _window$markmap2.autoLoader) != null && _window$markmap2.manual)) {
|
|
204
192
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => {
|
|
205
193
|
renderAll();
|
|
206
194
|
});else renderAll();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-autoloader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0-alpha.0",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"markdown",
|
|
10
10
|
"mindmap"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://github.com/
|
|
12
|
+
"homepage": "https://github.com/markmap/markmap/packages/markmap-autoloader#readme",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public",
|
|
15
15
|
"registry": "https://registry.npmjs.org/"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/markmap/markmap.git"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "rollup -wc rollup.conf.js",
|
|
@@ -25,25 +25,22 @@
|
|
|
25
25
|
"build:js": "rollup -c rollup.conf.js"
|
|
26
26
|
},
|
|
27
27
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/markmap/markmap/issues"
|
|
29
29
|
},
|
|
30
30
|
"main": "dist/index.js",
|
|
31
|
-
"unpkg": "dist/index.
|
|
32
|
-
"jsdelivr": "dist/index.
|
|
31
|
+
"unpkg": "dist/index.js",
|
|
32
|
+
"jsdelivr": "dist/index.js",
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
|
35
35
|
"types"
|
|
36
36
|
],
|
|
37
|
-
"engines": {
|
|
38
|
-
"node": ">=10"
|
|
39
|
-
},
|
|
40
37
|
"peerDependencies": {
|
|
41
38
|
"markmap-common": "*"
|
|
42
39
|
},
|
|
43
40
|
"devDependencies": {
|
|
44
|
-
"markmap-common": "
|
|
45
|
-
"markmap-lib": "
|
|
46
|
-
"markmap-view": "
|
|
41
|
+
"markmap-common": "0.15.0-alpha.0",
|
|
42
|
+
"markmap-lib": "0.15.0-alpha.0",
|
|
43
|
+
"markmap-view": "0.15.0-alpha.0"
|
|
47
44
|
},
|
|
48
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "cea14d4791b8483481a99baa5d256017f52f267c"
|
|
49
46
|
}
|
package/dist/index.min.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.14.4-alpha.1+8a57fea | MIT License */
|
|
2
|
-
this.markmap=this.markmap||{},function(t){"use strict";
|
|
3
|
-
/*! markmap-common v0.14.2 | MIT License */function a(){return a=Object.assign||function(t){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},a.apply(this,arguments)}function n(t,a,n){const e=document.createElement(t);return a&&Object.entries(a).forEach((([t,a])=>{e[t]=a})),n&&Object.entries(n).forEach((([t,a])=>{e.setAttribute(t,a)})),e}Math.random().toString(36).slice(2,8);const e=function(t){const a={};return function(...n){const e=`${n[0]}`;let r=a[e];return r||(r={value:t(...n)},a[e]=r),r.value}}((t=>{document.head.append(n("link",{rel:"preload",as:"script",href:t}))}));async function r(t,e){if(!t.loaded&&("script"===t.type&&(t.loaded=new Promise(((e,r)=>{var o;document.head.append(n("script",a({},t.data,{onload:e,onerror:r}))),null!=(o=t.data)&&o.src||e(void 0)})).then((()=>{t.loaded=!0}))),"iife"===t.type)){const{fn:a,getParams:n}=t.data;a(...(null==n?void 0:n(e))||[]),t.loaded=!0}await t.loaded}var o,s,d,c;const i={},l=async function(t,n){const o=t.filter((t=>{var a;return"script"===t.type&&(null==(a=t.data)?void 0:a.src)}));o.length>1&&o.forEach((t=>e(t.data.src))),n=a({getMarkmap:()=>window.markmap},n);for(const a of t)await r(a,n)}((null==(o=window.markmap)||null==(s=o.autoLoader)?void 0:s.baseJs)||[{type:"script",data:{src:"https://cdn.jsdelivr.net/npm/d3@6.7.0"}},{type:"script",data:{src:"https://cdn.jsdelivr.net/combine/npm/markmap-lib@0.14.4-alpha.1+8a57fea,npm/markmap-view@0.14.4-alpha.1+8a57fea"}}]).then((()=>{var t;const{markmap:a}=window,n=document.createElement("style");n.textContent=a.globalCSS,document.body.prepend(n),null==(t=a.autoLoader)||null==t.onReady||t.onReady()}));function m(t){const{Transformer:a,Markmap:n,autoLoader:e,deriveOptions:r}=window.markmap,o=t.textContent.split("\n");let s=1/0;o.forEach((t=>{const a=t.match(/^\s*/)[0].length;a<t.length&&(s=Math.min(s,a))}));const d=o.map((t=>t.slice(s))).join("\n").trim(),c=new a(null==e?void 0:e.transformPlugins);t.innerHTML="<svg></svg>";const l=t.firstChild,m=n.create(l,{embedGlobalCSS:!1}),u=()=>{const{root:t,frontmatter:a}=function(t,a){const n=t.transform(a),e=Object.keys(n.features).filter((t=>!i[t]));e.forEach((t=>{i[t]=!0}));const{styles:r,scripts:o}=t.getAssets(e),{markmap:s}=window;return r&&s.loadCSS(r),o&&s.loadJS(o),n}(c,d),n=null==a?void 0:a.markmap,e=r(n);m.setData(t,e),m.fit()};c.hooks.retransform.tap(u),u()}async function u(t){await l,t.querySelectorAll(".markmap").forEach(m)}function p(){return u(document)}null!=(d=window.markmap)&&null!=(c=d.autoLoader)&&c.manual||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{p()})):p()),t.ready=l,t.render=m,t.renderAll=p,t.renderAllUnder=u}(this.markmap.autoLoader=this.markmap.autoLoader||{});
|