markmap-autoloader 0.14.4 → 0.14.5-alpha.13
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.js +35 -46
- package/package.json +10 -13
- package/dist/index.min.js +0 -3
package/dist/index.js
CHANGED
|
@@ -1,64 +1,63 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.14.
|
|
1
|
+
/*! markmap-autoloader v0.14.5-alpha.13+50ca560 | MIT License */
|
|
2
2
|
this.markmap = this.markmap || {};
|
|
3
3
|
(function (exports) {
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
/*! markmap-common v0.14.
|
|
7
|
-
|
|
6
|
+
/*! markmap-common v0.14.5-alpha.13+50ca560 | 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
22
|
function memoize(fn) {
|
|
28
23
|
const cache = {};
|
|
29
24
|
return function memoized(...args) {
|
|
30
25
|
const key = `${args[0]}`;
|
|
31
26
|
let data = cache[key];
|
|
32
|
-
|
|
33
27
|
if (!data) {
|
|
34
28
|
data = {
|
|
35
29
|
value: fn(...args)
|
|
36
30
|
};
|
|
37
31
|
cache[key] = data;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
return data.value;
|
|
41
34
|
};
|
|
42
35
|
}
|
|
43
|
-
|
|
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
|
+
}
|
|
44
47
|
function createElement(tagName, props, attrs) {
|
|
45
48
|
const el = document.createElement(tagName);
|
|
46
|
-
|
|
47
49
|
if (props) {
|
|
48
50
|
Object.entries(props).forEach(([key, value]) => {
|
|
49
51
|
el[key] = value;
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
|
-
|
|
53
54
|
if (attrs) {
|
|
54
55
|
Object.entries(attrs).forEach(([key, value]) => {
|
|
55
56
|
el.setAttribute(key, value);
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
|
-
|
|
59
59
|
return el;
|
|
60
60
|
}
|
|
61
|
-
|
|
62
61
|
const memoizedPreloadJS = memoize(url => {
|
|
63
62
|
document.head.append(createElement('link', {
|
|
64
63
|
rel: 'preload',
|
|
@@ -66,24 +65,21 @@ const memoizedPreloadJS = memoize(url => {
|
|
|
66
65
|
href: url
|
|
67
66
|
}));
|
|
68
67
|
});
|
|
69
|
-
|
|
70
68
|
async function loadJSItem(item, context) {
|
|
71
69
|
if (!item.loaded) {
|
|
72
70
|
if (item.type === 'script') {
|
|
73
71
|
item.loaded = new Promise((resolve, reject) => {
|
|
74
72
|
var _item$data;
|
|
75
|
-
|
|
76
73
|
document.head.append(createElement('script', _extends({}, item.data, {
|
|
77
74
|
onload: resolve,
|
|
78
75
|
onerror: reject
|
|
79
|
-
})));
|
|
80
|
-
|
|
76
|
+
})));
|
|
77
|
+
// Run inline script synchronously
|
|
81
78
|
if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
|
|
82
79
|
}).then(() => {
|
|
83
80
|
item.loaded = true;
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
|
-
|
|
87
83
|
if (item.type === 'iife') {
|
|
88
84
|
const {
|
|
89
85
|
fn,
|
|
@@ -93,51 +89,48 @@ async function loadJSItem(item, context) {
|
|
|
93
89
|
item.loaded = true;
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
|
-
|
|
97
92
|
await item.loaded;
|
|
98
93
|
}
|
|
99
|
-
|
|
100
94
|
async function loadJS(items, context) {
|
|
101
95
|
const needPreload = items.filter(item => {
|
|
102
96
|
var _item$data2;
|
|
103
|
-
|
|
104
97
|
return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
|
|
105
98
|
});
|
|
106
99
|
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
|
|
107
100
|
context = _extends({
|
|
108
101
|
getMarkmap: () => window.markmap
|
|
109
102
|
}, context);
|
|
110
|
-
|
|
111
103
|
for (const item of items) {
|
|
112
104
|
await loadJSItem(item, context);
|
|
113
105
|
}
|
|
114
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
|
+
}
|
|
115
120
|
|
|
116
|
-
var _window$markmap, _window$
|
|
121
|
+
var _window$markmap, _window$markmap2;
|
|
117
122
|
const enabled = {};
|
|
118
|
-
const ready = loadJS(((_window$markmap = window.markmap) == null
|
|
119
|
-
type: 'script',
|
|
120
|
-
data: {
|
|
121
|
-
src: `https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
type: 'script',
|
|
125
|
-
data: {
|
|
126
|
-
src: `https://cdn.jsdelivr.net/combine/npm/markmap-lib@${"0.14.4"},npm/markmap-view@${"0.14.4"}`
|
|
127
|
-
}
|
|
128
|
-
}]).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.14.5-alpha.13+50ca560"}`, `markmap-view@${"0.14.5-alpha.13+50ca560"}`].map(buildJSItem)).then(() => {
|
|
129
124
|
var _markmap$autoLoader;
|
|
130
|
-
|
|
131
125
|
const {
|
|
132
126
|
markmap
|
|
133
127
|
} = window;
|
|
134
128
|
const style = document.createElement('style');
|
|
135
|
-
style.textContent = markmap.globalCSS;
|
|
136
|
-
|
|
129
|
+
style.textContent = markmap.globalCSS;
|
|
130
|
+
// Insert global CSS to body so it has higher priority than prism.css, etc.
|
|
137
131
|
document.body.prepend(style);
|
|
138
|
-
(_markmap$autoLoader = markmap.autoLoader) == null
|
|
132
|
+
(_markmap$autoLoader = markmap.autoLoader) == null || _markmap$autoLoader.onReady == null ? void 0 : _markmap$autoLoader.onReady();
|
|
139
133
|
});
|
|
140
|
-
|
|
141
134
|
function transform(transformer, content) {
|
|
142
135
|
const result = transformer.transform(content);
|
|
143
136
|
const keys = Object.keys(result.features).filter(key => !enabled[key]);
|
|
@@ -155,7 +148,6 @@ function transform(transformer, content) {
|
|
|
155
148
|
if (scripts) markmap.loadJS(scripts);
|
|
156
149
|
return result;
|
|
157
150
|
}
|
|
158
|
-
|
|
159
151
|
function render(el) {
|
|
160
152
|
const {
|
|
161
153
|
Transformer,
|
|
@@ -176,7 +168,6 @@ function render(el) {
|
|
|
176
168
|
const mm = Markmap.create(svg, {
|
|
177
169
|
embedGlobalCSS: false
|
|
178
170
|
});
|
|
179
|
-
|
|
180
171
|
const doRender = () => {
|
|
181
172
|
const {
|
|
182
173
|
root,
|
|
@@ -187,7 +178,6 @@ function render(el) {
|
|
|
187
178
|
mm.setData(root, frontmatterOptions);
|
|
188
179
|
mm.fit();
|
|
189
180
|
};
|
|
190
|
-
|
|
191
181
|
transformer.hooks.retransform.tap(doRender);
|
|
192
182
|
doRender();
|
|
193
183
|
}
|
|
@@ -198,8 +188,7 @@ async function renderAllUnder(container) {
|
|
|
198
188
|
function renderAll() {
|
|
199
189
|
return renderAllUnder(document);
|
|
200
190
|
}
|
|
201
|
-
|
|
202
|
-
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)) {
|
|
203
192
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => {
|
|
204
193
|
renderAll();
|
|
205
194
|
});else renderAll();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-autoloader",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5-alpha.13+50ca560",
|
|
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.14.5-alpha.13+50ca560",
|
|
42
|
+
"markmap-lib": "0.14.5-alpha.13+50ca560",
|
|
43
|
+
"markmap-view": "0.14.5-alpha.13+50ca560"
|
|
47
44
|
},
|
|
48
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
|
|
49
46
|
}
|
package/dist/index.min.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.14.4 | MIT License */
|
|
2
|
-
this.markmap=this.markmap||{},function(t){"use strict";
|
|
3
|
-
/*! markmap-common v0.14.2 | MIT License */function n(){return n=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},n.apply(this,arguments)}function e(t,n,e){const a=document.createElement(t);return n&&Object.entries(n).forEach((([t,n])=>{a[t]=n})),e&&Object.entries(e).forEach((([t,n])=>{a.setAttribute(t,n)})),a}Math.random().toString(36).slice(2,8);const a=function(t){const n={};return function(...e){const a=`${e[0]}`;let r=n[a];return r||(r={value:t(...e)},n[a]=r),r.value}}((t=>{document.head.append(e("link",{rel:"preload",as:"script",href:t}))}));async function r(t,a){if(!t.loaded&&("script"===t.type&&(t.loaded=new Promise(((a,r)=>{var o;document.head.append(e("script",n({},t.data,{onload:a,onerror:r}))),null!=(o=t.data)&&o.src||a(void 0)})).then((()=>{t.loaded=!0}))),"iife"===t.type)){const{fn:n,getParams:e}=t.data;n(...(null==e?void 0:e(a))||[]),t.loaded=!0}await t.loaded}var o,s,d,c;const i={},l=async function(t,e){const o=t.filter((t=>{var n;return"script"===t.type&&(null==(n=t.data)?void 0:n.src)}));o.length>1&&o.forEach((t=>a(t.data.src))),e=n({getMarkmap:()=>window.markmap},e);for(const n of t)await r(n,e)}((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,npm/markmap-view@0.14.4"}}]).then((()=>{var t;const{markmap:n}=window,e=document.createElement("style");e.textContent=n.globalCSS,document.body.prepend(e),null==(t=n.autoLoader)||null==t.onReady||t.onReady()}));function m(t){const{Transformer:n,Markmap:e,autoLoader:a,deriveOptions:r}=window.markmap,o=t.textContent.split("\n");let s=1/0;o.forEach((t=>{const n=t.match(/^\s*/)[0].length;n<t.length&&(s=Math.min(s,n))}));const d=o.map((t=>t.slice(s))).join("\n").trim(),c=new n(null==a?void 0:a.transformPlugins);t.innerHTML="<svg></svg>";const l=t.firstChild,m=e.create(l,{embedGlobalCSS:!1}),u=()=>{const{root:t,frontmatter:n}=function(t,n){const e=t.transform(n),a=Object.keys(e.features).filter((t=>!i[t]));a.forEach((t=>{i[t]=!0}));const{styles:r,scripts:o}=t.getAssets(a),{markmap:s}=window;return r&&s.loadCSS(r),o&&s.loadJS(o),e}(c,d),e=null==n?void 0:n.markmap,a=r(e);m.setData(t,a),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||{});
|