markmap-autoloader 0.14.5-alpha.15 → 0.14.5-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.
- package/dist/index.js +172 -28
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.14.5-alpha.
|
|
1
|
+
/*! markmap-autoloader v0.14.5-alpha.16+33e8294 | MIT License */
|
|
2
2
|
this.markmap = this.markmap || {};
|
|
3
3
|
(function (exports) {
|
|
4
4
|
'use strict';
|
|
@@ -18,7 +18,7 @@ function _extends$1() {
|
|
|
18
18
|
return _extends$1.apply(this, arguments);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
/*! markmap-common v0.14.5-alpha.
|
|
21
|
+
/*! markmap-common v0.14.5-alpha.16+33e8294 | MIT License */
|
|
22
22
|
function _extends() {
|
|
23
23
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
24
24
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -48,6 +48,161 @@ function memoize(fn) {
|
|
|
48
48
|
return data.value;
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
53
|
+
const VTYPE_ELEMENT = 1;
|
|
54
|
+
const VTYPE_FUNCTION = 2;
|
|
55
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
56
|
+
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
57
|
+
const NS_ATTRS = {
|
|
58
|
+
show: XLINK_NS,
|
|
59
|
+
actuate: XLINK_NS,
|
|
60
|
+
href: XLINK_NS
|
|
61
|
+
};
|
|
62
|
+
const isLeaf = c => typeof c === 'string' || typeof c === 'number';
|
|
63
|
+
const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
64
|
+
const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
65
|
+
function h(type, props, ...children) {
|
|
66
|
+
props = Object.assign({}, props, {
|
|
67
|
+
children: children.length === 1 ? children[0] : children
|
|
68
|
+
});
|
|
69
|
+
return jsx(type, props);
|
|
70
|
+
}
|
|
71
|
+
function jsx(type, props) {
|
|
72
|
+
let vtype;
|
|
73
|
+
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
|
|
74
|
+
return {
|
|
75
|
+
vtype,
|
|
76
|
+
type,
|
|
77
|
+
props
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function Fragment(props) {
|
|
81
|
+
return props.children;
|
|
82
|
+
}
|
|
83
|
+
const DEFAULT_ENV = {
|
|
84
|
+
isSvg: false
|
|
85
|
+
};
|
|
86
|
+
function insertDom(parent, nodes) {
|
|
87
|
+
if (!Array.isArray(nodes)) nodes = [nodes];
|
|
88
|
+
nodes = nodes.filter(Boolean);
|
|
89
|
+
if (nodes.length) parent.append(...nodes);
|
|
90
|
+
}
|
|
91
|
+
function mountAttributes(domElement, props, env) {
|
|
92
|
+
for (const key in props) {
|
|
93
|
+
if (key === 'key' || key === 'children' || key === 'ref') continue;
|
|
94
|
+
if (key === 'dangerouslySetInnerHTML') {
|
|
95
|
+
domElement.innerHTML = props[key].__html;
|
|
96
|
+
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
|
|
97
|
+
const value = props[key];
|
|
98
|
+
if (value != null) domElement[key] = value;
|
|
99
|
+
} else if (key.startsWith('on')) {
|
|
100
|
+
domElement[key.toLowerCase()] = props[key];
|
|
101
|
+
} else {
|
|
102
|
+
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const attrMap = {
|
|
107
|
+
className: 'class',
|
|
108
|
+
labelFor: 'for'
|
|
109
|
+
};
|
|
110
|
+
function setDOMAttribute(el, attr, value, isSVG) {
|
|
111
|
+
attr = attrMap[attr] || attr;
|
|
112
|
+
if (value === true) {
|
|
113
|
+
el.setAttribute(attr, '');
|
|
114
|
+
} else if (value === false) {
|
|
115
|
+
el.removeAttribute(attr);
|
|
116
|
+
} else {
|
|
117
|
+
const namespace = isSVG ? NS_ATTRS[attr] : undefined;
|
|
118
|
+
if (namespace !== undefined) {
|
|
119
|
+
el.setAttributeNS(namespace, attr, value);
|
|
120
|
+
} else {
|
|
121
|
+
el.setAttribute(attr, value);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function flatten(arr) {
|
|
126
|
+
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
127
|
+
}
|
|
128
|
+
function mountChildren(children, env) {
|
|
129
|
+
return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
|
|
130
|
+
}
|
|
131
|
+
function mount(vnode, env = DEFAULT_ENV) {
|
|
132
|
+
if (vnode == null || typeof vnode === 'boolean') {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (vnode instanceof Node) {
|
|
136
|
+
return vnode;
|
|
137
|
+
}
|
|
138
|
+
if (isRenderFunction(vnode)) {
|
|
139
|
+
const {
|
|
140
|
+
type,
|
|
141
|
+
props
|
|
142
|
+
} = vnode;
|
|
143
|
+
if (type === Fragment) {
|
|
144
|
+
const node = document.createDocumentFragment();
|
|
145
|
+
if (props.children) {
|
|
146
|
+
const children = mountChildren(props.children, env);
|
|
147
|
+
insertDom(node, children);
|
|
148
|
+
}
|
|
149
|
+
return node;
|
|
150
|
+
}
|
|
151
|
+
const childVNode = type(props);
|
|
152
|
+
return mount(childVNode, env);
|
|
153
|
+
}
|
|
154
|
+
if (isLeaf(vnode)) {
|
|
155
|
+
return document.createTextNode(`${vnode}`);
|
|
156
|
+
}
|
|
157
|
+
if (isElement(vnode)) {
|
|
158
|
+
let node;
|
|
159
|
+
const {
|
|
160
|
+
type,
|
|
161
|
+
props
|
|
162
|
+
} = vnode;
|
|
163
|
+
if (!env.isSvg && type === 'svg') {
|
|
164
|
+
env = Object.assign({}, env, {
|
|
165
|
+
isSvg: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (!env.isSvg) {
|
|
169
|
+
node = document.createElement(type);
|
|
170
|
+
} else {
|
|
171
|
+
node = document.createElementNS(SVG_NS, type);
|
|
172
|
+
}
|
|
173
|
+
mountAttributes(node, props, env);
|
|
174
|
+
if (props.children) {
|
|
175
|
+
let childEnv = env;
|
|
176
|
+
if (env.isSvg && type === 'foreignObject') {
|
|
177
|
+
childEnv = Object.assign({}, childEnv, {
|
|
178
|
+
isSvg: false
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
const children = mountChildren(props.children, childEnv);
|
|
182
|
+
if (children != null) insertDom(node, children);
|
|
183
|
+
}
|
|
184
|
+
const {
|
|
185
|
+
ref
|
|
186
|
+
} = props;
|
|
187
|
+
if (typeof ref === 'function') ref(node);
|
|
188
|
+
return node;
|
|
189
|
+
}
|
|
190
|
+
throw new Error('mount: Invalid Vnode!');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Mount vdom as real DOM nodes.
|
|
195
|
+
*/
|
|
196
|
+
function mountDom(vnode) {
|
|
197
|
+
return mount(vnode);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Render and mount without returning VirtualDOM, useful when you don't need SVG support.
|
|
202
|
+
*/
|
|
203
|
+
function hm(...args) {
|
|
204
|
+
return mountDom(h(...args));
|
|
205
|
+
}
|
|
51
206
|
const providers = {
|
|
52
207
|
jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
|
|
53
208
|
unpkg: path => `https://unpkg.com/${path}`
|
|
@@ -59,22 +214,8 @@ function cdnUrl(provider, path) {
|
|
|
59
214
|
}
|
|
60
215
|
return factory(path);
|
|
61
216
|
}
|
|
62
|
-
function createElement(tagName, props, attrs) {
|
|
63
|
-
const el = document.createElement(tagName);
|
|
64
|
-
if (props) {
|
|
65
|
-
Object.entries(props).forEach(([key, value]) => {
|
|
66
|
-
el[key] = value;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (attrs) {
|
|
70
|
-
Object.entries(attrs).forEach(([key, value]) => {
|
|
71
|
-
el.setAttribute(key, value);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return el;
|
|
75
|
-
}
|
|
76
217
|
const memoizedPreloadJS = memoize(url => {
|
|
77
|
-
document.head.append(
|
|
218
|
+
document.head.append(hm('link', {
|
|
78
219
|
rel: 'preload',
|
|
79
220
|
as: 'script',
|
|
80
221
|
href: url
|
|
@@ -85,9 +226,9 @@ async function loadJSItem(item, context) {
|
|
|
85
226
|
if (item.type === 'script') {
|
|
86
227
|
item.loaded = new Promise((resolve, reject) => {
|
|
87
228
|
var _item$data;
|
|
88
|
-
document.head.append(
|
|
89
|
-
|
|
90
|
-
|
|
229
|
+
document.head.append(hm('script', _extends({}, item.data, {
|
|
230
|
+
onLoad: resolve,
|
|
231
|
+
onError: reject
|
|
91
232
|
})));
|
|
92
233
|
// Run inline script synchronously
|
|
93
234
|
if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
|
|
@@ -110,21 +251,22 @@ function loadCSSItem(item) {
|
|
|
110
251
|
if (item.loaded) return;
|
|
111
252
|
item.loaded = true;
|
|
112
253
|
if (item.type === 'style') {
|
|
113
|
-
document.head.append(
|
|
254
|
+
document.head.append(hm('style', {
|
|
114
255
|
textContent: item.data
|
|
115
256
|
}));
|
|
116
257
|
} else if (item.type === 'stylesheet') {
|
|
117
|
-
document.head.append(
|
|
258
|
+
document.head.append(hm('link', _extends({
|
|
118
259
|
rel: 'stylesheet'
|
|
119
260
|
}, item.data)));
|
|
120
261
|
}
|
|
121
262
|
}
|
|
122
263
|
async function loadJS(items, context) {
|
|
123
|
-
|
|
264
|
+
items.forEach(item => {
|
|
124
265
|
var _item$data2;
|
|
125
|
-
|
|
266
|
+
if (item.type === 'script' && (_item$data2 = item.data) != null && _item$data2.src) {
|
|
267
|
+
memoizedPreloadJS(item.data.src);
|
|
268
|
+
}
|
|
126
269
|
});
|
|
127
|
-
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
|
|
128
270
|
context = _extends({
|
|
129
271
|
getMarkmap: () => window.markmap
|
|
130
272
|
}, context);
|
|
@@ -162,7 +304,7 @@ function buildCSSItem(path, overrideProvider) {
|
|
|
162
304
|
var _window$markmap;
|
|
163
305
|
const enabled = {};
|
|
164
306
|
const autoLoaderOptions = _extends$1({
|
|
165
|
-
baseJs: [`d3@${"6.2.0"}`, `markmap-lib@${"0.14.5-alpha.
|
|
307
|
+
baseJs: [`d3@${"6.2.0"}`, `markmap-lib@${"0.14.5-alpha.16+33e8294"}`, `markmap-view@${"0.14.5-alpha.16+33e8294"}`, `markmap-toolbar@${process.env.TOOLBAR_VERSION}`],
|
|
166
308
|
baseCss: [`markmap-toolbar@${process.env.TOOLBAR_VERSION}/dist/style.css`],
|
|
167
309
|
manual: false,
|
|
168
310
|
toolbar: false
|
|
@@ -195,16 +337,18 @@ function transform(transformer, content) {
|
|
|
195
337
|
return result;
|
|
196
338
|
}
|
|
197
339
|
function render(el) {
|
|
340
|
+
var _el$textContent;
|
|
198
341
|
const {
|
|
199
342
|
Transformer,
|
|
200
343
|
Markmap,
|
|
201
344
|
deriveOptions,
|
|
202
345
|
Toolbar
|
|
203
346
|
} = window.markmap;
|
|
204
|
-
const lines = el.textContent.split('\n');
|
|
347
|
+
const lines = ((_el$textContent = el.textContent) == null ? void 0 : _el$textContent.split('\n')) || [];
|
|
205
348
|
let indent = Infinity;
|
|
206
349
|
lines.forEach(line => {
|
|
207
|
-
|
|
350
|
+
var _line$match;
|
|
351
|
+
const spaces = ((_line$match = line.match(/^\s*/)) == null ? void 0 : _line$match[0].length) || 0;
|
|
208
352
|
if (spaces < line.length) indent = Math.min(indent, spaces);
|
|
209
353
|
});
|
|
210
354
|
const content = lines.map(line => line.slice(indent)).join('\n').trim();
|
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.16+33e8294",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,10 +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-toolbar": "0.14.5-alpha.
|
|
44
|
-
"markmap-view": "0.14.5-alpha.
|
|
41
|
+
"markmap-common": "0.14.5-alpha.16+33e8294",
|
|
42
|
+
"markmap-lib": "0.14.5-alpha.16+33e8294",
|
|
43
|
+
"markmap-toolbar": "0.14.5-alpha.16+33e8294",
|
|
44
|
+
"markmap-view": "0.14.5-alpha.16+33e8294"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "33e8294050d7438f6cdadd5bf06a665560585195"
|
|
47
47
|
}
|