markmap-autoloader 0.15.5-alpha.1 → 0.15.6-alpha.4
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 +437 -419
- package/package.json +9 -11
- /package/{types → dist}/index.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,459 +1,477 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.15.5-alpha.1+013bf59 | MIT License */
|
|
2
1
|
this.markmap = this.markmap || {};
|
|
3
|
-
(function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
(function(exports) {
|
|
3
|
+
"use strict";
|
|
4
|
+
var _a;
|
|
5
|
+
const testPath = "npm2url/dist/index.cjs";
|
|
6
|
+
const defaultProviders = {
|
|
7
|
+
jsdelivr: (path) => `https://cdn.jsdelivr.net/npm/${path}`,
|
|
8
|
+
unpkg: (path) => `https://unpkg.com/${path}`
|
|
9
|
+
};
|
|
10
|
+
async function checkUrl(url, signal) {
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
signal
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) {
|
|
15
|
+
throw res;
|
|
16
|
+
}
|
|
17
|
+
await res.text();
|
|
18
|
+
}
|
|
19
|
+
class UrlBuilder {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.providers = { ...defaultProviders };
|
|
22
|
+
this.provider = "jsdelivr";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the fastest provider name.
|
|
26
|
+
* If none of the providers returns a valid response within `timeout`, an error will be thrown.
|
|
27
|
+
*/
|
|
28
|
+
async getFastestProvider(timeout = 5e3, path = testPath) {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
let timer = 0;
|
|
31
|
+
try {
|
|
32
|
+
return await new Promise((resolve, reject) => {
|
|
33
|
+
Promise.all(
|
|
34
|
+
Object.entries(this.providers).map(async ([name, factory]) => {
|
|
35
|
+
try {
|
|
36
|
+
await checkUrl(factory(path), controller.signal);
|
|
37
|
+
resolve(name);
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
).then(() => reject(new Error("All providers failed")));
|
|
42
|
+
timer = setTimeout(reject, timeout, new Error("Timed out"));
|
|
43
|
+
});
|
|
44
|
+
} finally {
|
|
45
|
+
controller.abort();
|
|
46
|
+
clearTimeout(timer);
|
|
14
47
|
}
|
|
15
48
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
target[key] = source[key];
|
|
29
|
-
}
|
|
49
|
+
/**
|
|
50
|
+
* Set the current provider to the fastest provider found by `getFastestProvider`.
|
|
51
|
+
*/
|
|
52
|
+
async findFastestProvider(timeout, path) {
|
|
53
|
+
this.provider = await this.getFastestProvider(timeout, path);
|
|
54
|
+
return this.provider;
|
|
55
|
+
}
|
|
56
|
+
setProvider(name, factory) {
|
|
57
|
+
if (factory) {
|
|
58
|
+
this.providers[name] = factory;
|
|
59
|
+
} else {
|
|
60
|
+
delete this.providers[name];
|
|
30
61
|
}
|
|
31
62
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
constructor() {
|
|
43
|
-
this.providers = _extends({}, defaultProviders);
|
|
44
|
-
this.provider = "jsdelivr";
|
|
63
|
+
getFullUrl(path, provider = this.provider) {
|
|
64
|
+
if (path.includes("://")) {
|
|
65
|
+
return path;
|
|
66
|
+
}
|
|
67
|
+
const factory = this.providers[provider];
|
|
68
|
+
if (!factory) {
|
|
69
|
+
throw new Error(`Provider ${provider} not found`);
|
|
70
|
+
}
|
|
71
|
+
return factory(path);
|
|
72
|
+
}
|
|
45
73
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
await res.text();
|
|
55
|
-
resolve(name);
|
|
56
|
-
} catch (_unused) {}
|
|
57
|
-
})).then(() => reject(new Error("All providers failed")));
|
|
58
|
-
setTimeout(reject, timeout, new Error("Timed out"));
|
|
74
|
+
const urlBuilder = new UrlBuilder();
|
|
75
|
+
Math.random().toString(36).slice(2, 8);
|
|
76
|
+
function defer() {
|
|
77
|
+
const obj = {};
|
|
78
|
+
obj.promise = new Promise((resolve, reject) => {
|
|
79
|
+
obj.resolve = resolve;
|
|
80
|
+
obj.reject = reject;
|
|
59
81
|
});
|
|
82
|
+
return obj;
|
|
60
83
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
84
|
+
function memoize(fn) {
|
|
85
|
+
const cache = {};
|
|
86
|
+
return function memoized(...args) {
|
|
87
|
+
const key = `${args[0]}`;
|
|
88
|
+
let data = cache[key];
|
|
89
|
+
if (!data) {
|
|
90
|
+
data = {
|
|
91
|
+
value: fn(...args)
|
|
92
|
+
};
|
|
93
|
+
cache[key] = data;
|
|
94
|
+
}
|
|
95
|
+
return data.value;
|
|
96
|
+
};
|
|
64
97
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
98
|
+
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
99
|
+
const VTYPE_ELEMENT = 1;
|
|
100
|
+
const VTYPE_FUNCTION = 2;
|
|
101
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
102
|
+
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
103
|
+
const NS_ATTRS = {
|
|
104
|
+
show: XLINK_NS,
|
|
105
|
+
actuate: XLINK_NS,
|
|
106
|
+
href: XLINK_NS
|
|
107
|
+
};
|
|
108
|
+
const isLeaf = (c) => typeof c === "string" || typeof c === "number";
|
|
109
|
+
const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
110
|
+
const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
111
|
+
function h(type, props, ...children) {
|
|
112
|
+
props = Object.assign({}, props, {
|
|
113
|
+
children: children.length === 1 ? children[0] : children
|
|
114
|
+
});
|
|
115
|
+
return jsx(type, props);
|
|
71
116
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
117
|
+
function jsx(type, props) {
|
|
118
|
+
let vtype;
|
|
119
|
+
if (typeof type === "string")
|
|
120
|
+
vtype = VTYPE_ELEMENT;
|
|
121
|
+
else if (typeof type === "function")
|
|
122
|
+
vtype = VTYPE_FUNCTION;
|
|
123
|
+
else
|
|
124
|
+
throw new Error("Invalid VNode type");
|
|
125
|
+
return {
|
|
126
|
+
vtype,
|
|
127
|
+
type,
|
|
128
|
+
props
|
|
129
|
+
};
|
|
81
130
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return function memoized(...args) {
|
|
88
|
-
const key = `${args[0]}`;
|
|
89
|
-
let data = cache[key];
|
|
90
|
-
if (!data) {
|
|
91
|
-
data = {
|
|
92
|
-
value: fn(...args)
|
|
93
|
-
};
|
|
94
|
-
cache[key] = data;
|
|
95
|
-
}
|
|
96
|
-
return data.value;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
101
|
-
const VTYPE_ELEMENT = 1;
|
|
102
|
-
const VTYPE_FUNCTION = 2;
|
|
103
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
104
|
-
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
105
|
-
const NS_ATTRS = {
|
|
106
|
-
show: XLINK_NS,
|
|
107
|
-
actuate: XLINK_NS,
|
|
108
|
-
href: XLINK_NS
|
|
109
|
-
};
|
|
110
|
-
const isLeaf = c => typeof c === 'string' || typeof c === 'number';
|
|
111
|
-
const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
112
|
-
const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
113
|
-
function h(type, props, ...children) {
|
|
114
|
-
props = Object.assign({}, props, {
|
|
115
|
-
children: children.length === 1 ? children[0] : children
|
|
116
|
-
});
|
|
117
|
-
return jsx(type, props);
|
|
118
|
-
}
|
|
119
|
-
function jsx(type, props) {
|
|
120
|
-
let vtype;
|
|
121
|
-
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
|
|
122
|
-
return {
|
|
123
|
-
vtype,
|
|
124
|
-
type,
|
|
125
|
-
props
|
|
131
|
+
function Fragment(props) {
|
|
132
|
+
return props.children;
|
|
133
|
+
}
|
|
134
|
+
const DEFAULT_ENV = {
|
|
135
|
+
isSvg: false
|
|
126
136
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
} else {
|
|
150
|
-
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
137
|
+
function insertDom(parent, nodes) {
|
|
138
|
+
if (!Array.isArray(nodes))
|
|
139
|
+
nodes = [nodes];
|
|
140
|
+
nodes = nodes.filter(Boolean);
|
|
141
|
+
if (nodes.length)
|
|
142
|
+
parent.append(...nodes);
|
|
143
|
+
}
|
|
144
|
+
function mountAttributes(domElement, props, env) {
|
|
145
|
+
for (const key in props) {
|
|
146
|
+
if (key === "key" || key === "children" || key === "ref")
|
|
147
|
+
continue;
|
|
148
|
+
if (key === "dangerouslySetInnerHTML") {
|
|
149
|
+
domElement.innerHTML = props[key].__html;
|
|
150
|
+
} else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
|
|
151
|
+
const value = props[key];
|
|
152
|
+
if (value != null)
|
|
153
|
+
domElement[key] = value;
|
|
154
|
+
} else if (key.startsWith("on")) {
|
|
155
|
+
domElement[key.toLowerCase()] = props[key];
|
|
156
|
+
} else {
|
|
157
|
+
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
158
|
+
}
|
|
151
159
|
}
|
|
152
160
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
el.removeAttribute(attr);
|
|
164
|
-
} else {
|
|
165
|
-
const namespace = isSVG ? NS_ATTRS[attr] : undefined;
|
|
166
|
-
if (namespace !== undefined) {
|
|
167
|
-
el.setAttributeNS(namespace, attr, value);
|
|
161
|
+
const attrMap = {
|
|
162
|
+
className: "class",
|
|
163
|
+
labelFor: "for"
|
|
164
|
+
};
|
|
165
|
+
function setDOMAttribute(el, attr, value, isSVG) {
|
|
166
|
+
attr = attrMap[attr] || attr;
|
|
167
|
+
if (value === true) {
|
|
168
|
+
el.setAttribute(attr, "");
|
|
169
|
+
} else if (value === false) {
|
|
170
|
+
el.removeAttribute(attr);
|
|
168
171
|
} else {
|
|
169
|
-
|
|
172
|
+
const namespace = isSVG ? NS_ATTRS[attr] : void 0;
|
|
173
|
+
if (namespace !== void 0) {
|
|
174
|
+
el.setAttributeNS(namespace, attr, value);
|
|
175
|
+
} else {
|
|
176
|
+
el.setAttribute(attr, value);
|
|
177
|
+
}
|
|
170
178
|
}
|
|
171
179
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
175
|
-
}
|
|
176
|
-
function mountChildren(children, env) {
|
|
177
|
-
return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
|
|
178
|
-
}
|
|
179
|
-
function mount(vnode, env = DEFAULT_ENV) {
|
|
180
|
-
if (vnode == null || typeof vnode === 'boolean') {
|
|
181
|
-
return null;
|
|
180
|
+
function flatten(arr) {
|
|
181
|
+
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
182
182
|
}
|
|
183
|
-
|
|
184
|
-
return
|
|
183
|
+
function mountChildren(children, env) {
|
|
184
|
+
return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
|
|
185
185
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
props
|
|
190
|
-
} = vnode;
|
|
191
|
-
if (type === Fragment) {
|
|
192
|
-
const node = document.createDocumentFragment();
|
|
193
|
-
if (props.children) {
|
|
194
|
-
const children = mountChildren(props.children, env);
|
|
195
|
-
insertDom(node, children);
|
|
196
|
-
}
|
|
197
|
-
return node;
|
|
186
|
+
function mount(vnode, env = DEFAULT_ENV) {
|
|
187
|
+
if (vnode == null || typeof vnode === "boolean") {
|
|
188
|
+
return null;
|
|
198
189
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
if (isLeaf(vnode)) {
|
|
203
|
-
return document.createTextNode(`${vnode}`);
|
|
204
|
-
}
|
|
205
|
-
if (isElement(vnode)) {
|
|
206
|
-
let node;
|
|
207
|
-
const {
|
|
208
|
-
type,
|
|
209
|
-
props
|
|
210
|
-
} = vnode;
|
|
211
|
-
if (!env.isSvg && type === 'svg') {
|
|
212
|
-
env = Object.assign({}, env, {
|
|
213
|
-
isSvg: true
|
|
214
|
-
});
|
|
190
|
+
if (vnode instanceof Node) {
|
|
191
|
+
return vnode;
|
|
215
192
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
193
|
+
if (isRenderFunction(vnode)) {
|
|
194
|
+
const {
|
|
195
|
+
type,
|
|
196
|
+
props
|
|
197
|
+
} = vnode;
|
|
198
|
+
if (type === Fragment) {
|
|
199
|
+
const node = document.createDocumentFragment();
|
|
200
|
+
if (props.children) {
|
|
201
|
+
const children = mountChildren(props.children, env);
|
|
202
|
+
insertDom(node, children);
|
|
203
|
+
}
|
|
204
|
+
return node;
|
|
205
|
+
}
|
|
206
|
+
const childVNode = type(props);
|
|
207
|
+
return mount(childVNode, env);
|
|
208
|
+
}
|
|
209
|
+
if (isLeaf(vnode)) {
|
|
210
|
+
return document.createTextNode(`${vnode}`);
|
|
220
211
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
212
|
+
if (isElement(vnode)) {
|
|
213
|
+
let node;
|
|
214
|
+
const {
|
|
215
|
+
type,
|
|
216
|
+
props
|
|
217
|
+
} = vnode;
|
|
218
|
+
if (!env.isSvg && type === "svg") {
|
|
219
|
+
env = Object.assign({}, env, {
|
|
220
|
+
isSvg: true
|
|
227
221
|
});
|
|
228
222
|
}
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
if (!env.isSvg) {
|
|
224
|
+
node = document.createElement(type);
|
|
225
|
+
} else {
|
|
226
|
+
node = document.createElementNS(SVG_NS, type);
|
|
227
|
+
}
|
|
228
|
+
mountAttributes(node, props, env);
|
|
229
|
+
if (props.children) {
|
|
230
|
+
let childEnv = env;
|
|
231
|
+
if (env.isSvg && type === "foreignObject") {
|
|
232
|
+
childEnv = Object.assign({}, childEnv, {
|
|
233
|
+
isSvg: false
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const children = mountChildren(props.children, childEnv);
|
|
237
|
+
if (children != null)
|
|
238
|
+
insertDom(node, children);
|
|
239
|
+
}
|
|
240
|
+
const {
|
|
241
|
+
ref
|
|
242
|
+
} = props;
|
|
243
|
+
if (typeof ref === "function")
|
|
244
|
+
ref(node);
|
|
245
|
+
return node;
|
|
231
246
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return node;
|
|
247
|
+
throw new Error("mount: Invalid Vnode!");
|
|
248
|
+
}
|
|
249
|
+
function mountDom(vnode) {
|
|
250
|
+
return mount(vnode);
|
|
237
251
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (!item.loaded) {
|
|
268
|
-
if (item.type === 'script') {
|
|
269
|
-
item.loaded = new Promise((resolve, reject) => {
|
|
270
|
-
document.head.append(hm('script', _extends({}, item.data, {
|
|
271
|
-
onLoad: resolve,
|
|
272
|
-
onError: reject
|
|
273
|
-
})));
|
|
252
|
+
function hm(...args) {
|
|
253
|
+
return mountDom(h(...args));
|
|
254
|
+
}
|
|
255
|
+
const memoizedPreloadJS = memoize((url) => {
|
|
256
|
+
document.head.append(
|
|
257
|
+
hm("link", {
|
|
258
|
+
rel: "preload",
|
|
259
|
+
as: "script",
|
|
260
|
+
href: url
|
|
261
|
+
})
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
const jsCache = {};
|
|
265
|
+
const cssCache = {};
|
|
266
|
+
async function loadJSItem(item, context) {
|
|
267
|
+
var _a2;
|
|
268
|
+
const src = item.type === "script" && ((_a2 = item.data) == null ? void 0 : _a2.src) || "";
|
|
269
|
+
item.loaded || (item.loaded = jsCache[src]);
|
|
270
|
+
if (!item.loaded) {
|
|
271
|
+
const deferred = defer();
|
|
272
|
+
item.loaded = deferred.promise;
|
|
273
|
+
if (item.type === "script") {
|
|
274
|
+
document.head.append(
|
|
275
|
+
hm("script", {
|
|
276
|
+
...item.data,
|
|
277
|
+
onLoad: () => deferred.resolve(),
|
|
278
|
+
onError: deferred.reject
|
|
279
|
+
})
|
|
280
|
+
);
|
|
274
281
|
if (!src) {
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
deferred.resolve();
|
|
283
|
+
} else {
|
|
284
|
+
jsCache[src] = item.loaded;
|
|
277
285
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const {
|
|
285
|
-
fn,
|
|
286
|
-
getParams
|
|
287
|
-
} = item.data;
|
|
288
|
-
fn(...((getParams == null ? void 0 : getParams(context)) || []));
|
|
289
|
-
item.loaded = true;
|
|
286
|
+
}
|
|
287
|
+
if (item.type === "iife") {
|
|
288
|
+
const { fn, getParams } = item.data;
|
|
289
|
+
fn(...(getParams == null ? void 0 : getParams(context)) || []);
|
|
290
|
+
deferred.resolve();
|
|
291
|
+
}
|
|
290
292
|
}
|
|
293
|
+
await item.loaded;
|
|
291
294
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
295
|
+
async function loadCSSItem(item) {
|
|
296
|
+
const url = item.type === "stylesheet" && item.data.href || "";
|
|
297
|
+
item.loaded || (item.loaded = cssCache[url]);
|
|
298
|
+
if (!item.loaded) {
|
|
299
|
+
const deferred = defer();
|
|
300
|
+
item.loaded = deferred.promise;
|
|
301
|
+
if (url)
|
|
302
|
+
cssCache[url] = item.loaded;
|
|
303
|
+
if (item.type === "style") {
|
|
304
|
+
document.head.append(
|
|
305
|
+
hm("style", {
|
|
306
|
+
textContent: item.data
|
|
307
|
+
})
|
|
308
|
+
);
|
|
309
|
+
deferred.resolve();
|
|
310
|
+
} else if (url) {
|
|
311
|
+
document.head.append(
|
|
312
|
+
hm("link", {
|
|
313
|
+
rel: "stylesheet",
|
|
314
|
+
...item.data
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
fetch(url).then((res) => {
|
|
318
|
+
if (res.ok)
|
|
319
|
+
return res.text();
|
|
320
|
+
throw res;
|
|
321
|
+
}).then(() => deferred.resolve(), deferred.reject);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
await item.loaded;
|
|
308
325
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
326
|
+
async function loadJS(items, context) {
|
|
327
|
+
items.forEach((item) => {
|
|
328
|
+
var _a2;
|
|
329
|
+
if (item.type === "script" && ((_a2 = item.data) == null ? void 0 : _a2.src)) {
|
|
330
|
+
memoizedPreloadJS(item.data.src);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
context = {
|
|
334
|
+
getMarkmap: () => window.markmap,
|
|
335
|
+
...context
|
|
336
|
+
};
|
|
337
|
+
for (const item of items) {
|
|
338
|
+
await loadJSItem(item, context);
|
|
315
339
|
}
|
|
316
|
-
});
|
|
317
|
-
context = _extends({
|
|
318
|
-
getMarkmap: () => window.markmap
|
|
319
|
-
}, context);
|
|
320
|
-
for (const item of items) {
|
|
321
|
-
await loadJSItem(item, context);
|
|
322
340
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
for (const item of items) {
|
|
326
|
-
loadCSSItem(item);
|
|
341
|
+
async function loadCSS(items) {
|
|
342
|
+
await Promise.all(items.map((item) => loadCSSItem(item)));
|
|
327
343
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
344
|
+
function buildJSItem(path) {
|
|
345
|
+
return {
|
|
346
|
+
type: "script",
|
|
347
|
+
data: {
|
|
348
|
+
src: path
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function buildCSSItem(path) {
|
|
353
|
+
return {
|
|
354
|
+
type: "stylesheet",
|
|
355
|
+
data: {
|
|
356
|
+
href: path
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
const enabled = {};
|
|
361
|
+
const autoLoaderOptions = {
|
|
362
|
+
baseJs: [
|
|
363
|
+
`d3@${"7.8.5"}`,
|
|
364
|
+
`markmap-lib@${"0.15.6-alpha.4"}`,
|
|
365
|
+
`markmap-view@${"0.15.6-alpha.4"}`,
|
|
366
|
+
`markmap-toolbar@${"0.15.6-alpha.4"}`
|
|
367
|
+
],
|
|
368
|
+
baseCss: [`markmap-toolbar@${"0.15.6-alpha.4"}/dist/style.css`],
|
|
369
|
+
manual: false,
|
|
370
|
+
toolbar: false,
|
|
371
|
+
...(_a = window.markmap) == null ? void 0 : _a.autoLoader
|
|
343
372
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
urlBuilder.provider = autoLoaderOptions.provider;
|
|
359
|
-
} else {
|
|
360
|
-
try {
|
|
361
|
-
await urlBuilder.findFastestProvider();
|
|
362
|
-
} catch (_unused) {
|
|
363
|
-
// ignore
|
|
373
|
+
async function initialize() {
|
|
374
|
+
var _a2;
|
|
375
|
+
if (typeof autoLoaderOptions.provider === "function") {
|
|
376
|
+
urlBuilder.setProvider(
|
|
377
|
+
urlBuilder.provider = "autoLoader",
|
|
378
|
+
autoLoaderOptions.provider
|
|
379
|
+
);
|
|
380
|
+
} else if (typeof autoLoaderOptions.provider === "string") {
|
|
381
|
+
urlBuilder.provider = autoLoaderOptions.provider;
|
|
382
|
+
} else {
|
|
383
|
+
try {
|
|
384
|
+
await urlBuilder.findFastestProvider();
|
|
385
|
+
} catch {
|
|
386
|
+
}
|
|
364
387
|
}
|
|
388
|
+
await Promise.all([
|
|
389
|
+
loadJS(
|
|
390
|
+
autoLoaderOptions.baseJs.map(
|
|
391
|
+
(item) => typeof item === "string" ? buildJSItem(urlBuilder.getFullUrl(item)) : item
|
|
392
|
+
)
|
|
393
|
+
),
|
|
394
|
+
loadCSS(
|
|
395
|
+
autoLoaderOptions.baseCss.map(
|
|
396
|
+
(item) => typeof item === "string" ? buildCSSItem(urlBuilder.getFullUrl(item)) : item
|
|
397
|
+
)
|
|
398
|
+
)
|
|
399
|
+
]);
|
|
400
|
+
const { markmap } = window;
|
|
401
|
+
const style = document.createElement("style");
|
|
402
|
+
style.textContent = markmap.globalCSS;
|
|
403
|
+
document.body.prepend(style);
|
|
404
|
+
(_a2 = autoLoaderOptions.onReady) == null ? void 0 : _a2.call(autoLoaderOptions);
|
|
365
405
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// Insert global CSS to body so it has higher priority than prism.css, etc.
|
|
373
|
-
document.body.prepend(style);
|
|
374
|
-
autoLoaderOptions.onReady == null || autoLoaderOptions.onReady();
|
|
375
|
-
}
|
|
376
|
-
const ready = initialize();
|
|
377
|
-
function transform(transformer, content) {
|
|
378
|
-
const result = transformer.transform(content);
|
|
379
|
-
const keys = Object.keys(result.features).filter(key => !enabled[key]);
|
|
380
|
-
keys.forEach(key => {
|
|
381
|
-
enabled[key] = true;
|
|
382
|
-
});
|
|
383
|
-
const {
|
|
384
|
-
styles,
|
|
385
|
-
scripts
|
|
386
|
-
} = transformer.getAssets(keys);
|
|
387
|
-
const {
|
|
388
|
-
markmap
|
|
389
|
-
} = window;
|
|
390
|
-
if (styles) markmap.loadCSS(styles);
|
|
391
|
-
if (scripts) markmap.loadJS(scripts);
|
|
392
|
-
return result;
|
|
393
|
-
}
|
|
394
|
-
function render(el) {
|
|
395
|
-
var _el$textContent;
|
|
396
|
-
const {
|
|
397
|
-
Transformer,
|
|
398
|
-
Markmap,
|
|
399
|
-
deriveOptions,
|
|
400
|
-
Toolbar
|
|
401
|
-
} = window.markmap;
|
|
402
|
-
const lines = ((_el$textContent = el.textContent) == null ? void 0 : _el$textContent.split('\n')) || [];
|
|
403
|
-
let indent = Infinity;
|
|
404
|
-
lines.forEach(line => {
|
|
405
|
-
var _line$match;
|
|
406
|
-
const spaces = ((_line$match = line.match(/^\s*/)) == null ? void 0 : _line$match[0].length) || 0;
|
|
407
|
-
if (spaces < line.length) indent = Math.min(indent, spaces);
|
|
408
|
-
});
|
|
409
|
-
const content = lines.map(line => line.slice(indent)).join('\n').trim();
|
|
410
|
-
const transformer = new Transformer(autoLoaderOptions.transformPlugins);
|
|
411
|
-
transformer.urlBuilder = urlBuilder;
|
|
412
|
-
el.innerHTML = '<svg></svg>';
|
|
413
|
-
const svg = el.firstChild;
|
|
414
|
-
const mm = Markmap.create(svg, {
|
|
415
|
-
embedGlobalCSS: false
|
|
416
|
-
});
|
|
417
|
-
if (autoLoaderOptions.toolbar) {
|
|
418
|
-
const {
|
|
419
|
-
el: toolbar
|
|
420
|
-
} = Toolbar.create(mm);
|
|
421
|
-
Object.assign(toolbar.style, {
|
|
422
|
-
position: 'absolute',
|
|
423
|
-
right: '20px',
|
|
424
|
-
bottom: '20px'
|
|
406
|
+
const ready = initialize();
|
|
407
|
+
function transform(transformer, content) {
|
|
408
|
+
const result = transformer.transform(content);
|
|
409
|
+
const keys = Object.keys(result.features).filter((key) => !enabled[key]);
|
|
410
|
+
keys.forEach((key) => {
|
|
411
|
+
enabled[key] = true;
|
|
425
412
|
});
|
|
426
|
-
|
|
413
|
+
const { styles, scripts } = transformer.getAssets(keys);
|
|
414
|
+
const { markmap } = window;
|
|
415
|
+
if (styles)
|
|
416
|
+
markmap.loadCSS(styles);
|
|
417
|
+
if (scripts)
|
|
418
|
+
markmap.loadJS(scripts);
|
|
419
|
+
return result;
|
|
427
420
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
421
|
+
function render(el) {
|
|
422
|
+
var _a2;
|
|
423
|
+
const { Transformer, Markmap, deriveOptions, Toolbar } = window.markmap;
|
|
424
|
+
const lines = ((_a2 = el.textContent) == null ? void 0 : _a2.split("\n")) || [];
|
|
425
|
+
let indent = Infinity;
|
|
426
|
+
lines.forEach((line) => {
|
|
427
|
+
var _a3;
|
|
428
|
+
const spaces = ((_a3 = line.match(/^\s*/)) == null ? void 0 : _a3[0].length) || 0;
|
|
429
|
+
if (spaces < line.length)
|
|
430
|
+
indent = Math.min(indent, spaces);
|
|
431
|
+
});
|
|
432
|
+
const content = lines.map((line) => line.slice(indent)).join("\n").trim();
|
|
433
|
+
const transformer = new Transformer(autoLoaderOptions.transformPlugins);
|
|
434
|
+
transformer.urlBuilder = urlBuilder;
|
|
435
|
+
el.innerHTML = "<svg></svg>";
|
|
436
|
+
const svg = el.firstChild;
|
|
437
|
+
const mm = Markmap.create(svg, { embedGlobalCSS: false });
|
|
438
|
+
if (autoLoaderOptions.toolbar) {
|
|
439
|
+
const { el: toolbar } = Toolbar.create(mm);
|
|
440
|
+
Object.assign(toolbar.style, {
|
|
441
|
+
position: "absolute",
|
|
442
|
+
right: "20px",
|
|
443
|
+
bottom: "20px"
|
|
444
|
+
});
|
|
445
|
+
el.append(toolbar);
|
|
446
|
+
}
|
|
447
|
+
const doRender = () => {
|
|
448
|
+
const { root, frontmatter } = transform(transformer, content);
|
|
449
|
+
const markmapOptions = frontmatter == null ? void 0 : frontmatter.markmap;
|
|
450
|
+
const frontmatterOptions = deriveOptions(markmapOptions);
|
|
451
|
+
mm.setData(root, frontmatterOptions);
|
|
452
|
+
mm.fit();
|
|
453
|
+
};
|
|
454
|
+
transformer.hooks.retransform.tap(doRender);
|
|
455
|
+
doRender();
|
|
456
|
+
}
|
|
457
|
+
async function renderAllUnder(container) {
|
|
458
|
+
await ready;
|
|
459
|
+
container.querySelectorAll(".markmap").forEach(render);
|
|
460
|
+
}
|
|
461
|
+
function renderAll() {
|
|
462
|
+
return renderAllUnder(document);
|
|
463
|
+
}
|
|
464
|
+
if (!autoLoaderOptions.manual) {
|
|
465
|
+
if (document.readyState === "loading")
|
|
466
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
467
|
+
renderAll();
|
|
468
|
+
});
|
|
469
|
+
else
|
|
470
|
+
renderAll();
|
|
471
|
+
}
|
|
472
|
+
exports.ready = ready;
|
|
473
|
+
exports.render = render;
|
|
474
|
+
exports.renderAll = renderAll;
|
|
475
|
+
exports.renderAllUnder = renderAllUnder;
|
|
476
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
459
477
|
})(this.markmap.autoLoader = this.markmap.autoLoader || {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-autoloader",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.6-alpha.4+4734119",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,9 @@
|
|
|
19
19
|
"url": "git+https://github.com/markmap/markmap.git"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"clean": "del-cli dist types",
|
|
22
|
+
"clean": "del-cli dist",
|
|
24
23
|
"build:types": "tsc",
|
|
25
|
-
"build:js": "
|
|
24
|
+
"build:js": "vite build"
|
|
26
25
|
},
|
|
27
26
|
"bugs": {
|
|
28
27
|
"url": "https://github.com/markmap/markmap/issues"
|
|
@@ -31,17 +30,16 @@
|
|
|
31
30
|
"unpkg": "dist/index.js",
|
|
32
31
|
"jsdelivr": "dist/index.js",
|
|
33
32
|
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
"types"
|
|
33
|
+
"dist"
|
|
36
34
|
],
|
|
37
35
|
"peerDependencies": {
|
|
38
36
|
"markmap-common": "*"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
|
-
"markmap-common": "0.15.5
|
|
42
|
-
"markmap-lib": "0.15.
|
|
43
|
-
"markmap-toolbar": "0.15.
|
|
44
|
-
"markmap-view": "0.15.
|
|
39
|
+
"markmap-common": "0.15.5",
|
|
40
|
+
"markmap-lib": "0.15.6-alpha.4+4734119",
|
|
41
|
+
"markmap-toolbar": "0.15.6-alpha.4+4734119",
|
|
42
|
+
"markmap-view": "0.15.6-alpha.4+4734119"
|
|
45
43
|
},
|
|
46
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "473411985496abcc20a546978438614c48ec56cf"
|
|
47
45
|
}
|
|
File without changes
|