markmap-autoloader 0.1.5 → 0.13.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 +32 -3
- package/dist/index.js +51 -19
- package/dist/index.min.js +2 -2
- package/package.json +5 -6
- package/types/index.d.ts +4 -3
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ HTML:
|
|
|
26
26
|
</div>
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Autoload all `.markmap`:
|
|
29
|
+
Autoload all elements matching `.markmap`:
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
32
|
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
|
|
@@ -49,15 +49,44 @@ setTimeout(() => {
|
|
|
49
49
|
</script>
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
Disable built-in plugins:
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script>
|
|
56
|
+
window.markmap = {
|
|
57
|
+
autoLoader: {
|
|
58
|
+
transformPlugins: [],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
</script>
|
|
62
|
+
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
|
|
63
|
+
```
|
|
64
|
+
|
|
52
65
|
## API
|
|
53
66
|
|
|
67
|
+
### Options
|
|
68
|
+
|
|
69
|
+
If `window.markmap.autoLoader` is defined before this package is loaded, it will be regarded as autoLoader options.
|
|
70
|
+
|
|
71
|
+
- `autoLoader.manual` *boolean* default as `false`
|
|
72
|
+
|
|
73
|
+
Whether to render markmaps manually. If false, all elements matching `.markmap` will be rendered once this package loads or DOMContentLoaded is emitted, whichever later.
|
|
74
|
+
|
|
75
|
+
- `autoLoader.transformPlugins` *ITransformPlugin[]*
|
|
76
|
+
|
|
77
|
+
Override built-in plugins if provided. Set to `[]` to disable all built-in plugins for auto-loader.
|
|
78
|
+
|
|
79
|
+
- `autoLoader.onReady` *function*
|
|
80
|
+
|
|
81
|
+
Callback when markmap-lib/markmap-view and their dependencies are loaded. We can tweak global options in this callback.
|
|
82
|
+
|
|
54
83
|
### markmap.autoLoader.renderAll()
|
|
55
84
|
|
|
56
|
-
Render all `.markmap
|
|
85
|
+
Render all elements matching `.markmap`.
|
|
57
86
|
|
|
58
87
|
### markmap.autoLoader.renderAllUnder(el)
|
|
59
88
|
|
|
60
|
-
Render all `.markmap`
|
|
89
|
+
Render all elements matching `.markmap` under container `el`.
|
|
61
90
|
|
|
62
91
|
### markmap.autoLoader.render(el)
|
|
63
92
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.
|
|
1
|
+
/*! markmap-autoloader v0.13.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.
|
|
6
|
+
/*! markmap-common v0.13.0-alpha.0 | MIT License */
|
|
7
7
|
|
|
8
8
|
function _extends() {
|
|
9
9
|
_extends = Object.assign || function (target) {
|
|
@@ -91,6 +91,18 @@ function loadJSItem(item, context) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
function loadCSSItem(item) {
|
|
95
|
+
if (item.type === 'style') {
|
|
96
|
+
document.head.append(createElement('style', {
|
|
97
|
+
textContent: item.data
|
|
98
|
+
}));
|
|
99
|
+
} else if (item.type === 'stylesheet') {
|
|
100
|
+
document.head.append(createElement('link', _extends({
|
|
101
|
+
rel: 'stylesheet'
|
|
102
|
+
}, item.data)));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
94
106
|
async function loadJS(items, context) {
|
|
95
107
|
const needPreload = items.filter(item => {
|
|
96
108
|
var _item$data2;
|
|
@@ -107,19 +119,36 @@ async function loadJS(items, context) {
|
|
|
107
119
|
}
|
|
108
120
|
}
|
|
109
121
|
|
|
122
|
+
function loadCSS(items) {
|
|
123
|
+
for (const item of items) {
|
|
124
|
+
loadCSSItem(item);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
110
128
|
var _window$markmap, _window$markmap$autoL;
|
|
111
129
|
const enabled = {};
|
|
112
|
-
const
|
|
130
|
+
const ready = loadJS([{
|
|
113
131
|
type: 'script',
|
|
114
132
|
data: {
|
|
115
|
-
src: `https://cdn.jsdelivr.net/npm/d3@${"6.
|
|
133
|
+
src: `https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`
|
|
116
134
|
}
|
|
117
135
|
}, {
|
|
118
136
|
type: 'script',
|
|
119
137
|
data: {
|
|
120
|
-
src: `https://cdn.jsdelivr.net/combine/npm/markmap-lib@${"0.
|
|
138
|
+
src: `https://cdn.jsdelivr.net/combine/npm/markmap-lib@${"0.13.0-alpha.0"},npm/markmap-view@${"0.13.0-alpha.0"}`
|
|
121
139
|
}
|
|
122
|
-
}])
|
|
140
|
+
}]).then(() => {
|
|
141
|
+
var _markmap$autoLoader;
|
|
142
|
+
|
|
143
|
+
const {
|
|
144
|
+
markmap
|
|
145
|
+
} = window;
|
|
146
|
+
loadCSS([{
|
|
147
|
+
type: 'style',
|
|
148
|
+
data: markmap.globalCSS
|
|
149
|
+
}]);
|
|
150
|
+
(_markmap$autoLoader = markmap.autoLoader) == null ? void 0 : _markmap$autoLoader.onReady == null ? void 0 : _markmap$autoLoader.onReady();
|
|
151
|
+
});
|
|
123
152
|
|
|
124
153
|
function transform(transformer, content) {
|
|
125
154
|
const {
|
|
@@ -135,18 +164,18 @@ function transform(transformer, content) {
|
|
|
135
164
|
scripts
|
|
136
165
|
} = transformer.getAssets(keys);
|
|
137
166
|
const {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
if (scripts) loadJS(scripts);
|
|
167
|
+
markmap
|
|
168
|
+
} = window;
|
|
169
|
+
if (styles) markmap.loadCSS(styles);
|
|
170
|
+
if (scripts) markmap.loadJS(scripts);
|
|
143
171
|
return root;
|
|
144
172
|
}
|
|
145
173
|
|
|
146
174
|
function render(el) {
|
|
147
175
|
const {
|
|
148
176
|
Transformer,
|
|
149
|
-
Markmap
|
|
177
|
+
Markmap,
|
|
178
|
+
autoLoader
|
|
150
179
|
} = window.markmap;
|
|
151
180
|
const lines = el.textContent.split('\n');
|
|
152
181
|
let indent = Infinity;
|
|
@@ -155,22 +184,24 @@ function render(el) {
|
|
|
155
184
|
if (spaces < line.length) indent = Math.min(indent, spaces);
|
|
156
185
|
});
|
|
157
186
|
const content = lines.map(line => line.slice(indent)).join('\n');
|
|
158
|
-
const transformer = new Transformer();
|
|
187
|
+
const transformer = new Transformer(autoLoader == null ? void 0 : autoLoader.transformPlugins);
|
|
159
188
|
el.innerHTML = '<svg></svg>';
|
|
160
189
|
const svg = el.firstChild;
|
|
161
|
-
const mm = Markmap.create(svg
|
|
190
|
+
const mm = Markmap.create(svg, {
|
|
191
|
+
embedGlobalCSS: false
|
|
192
|
+
});
|
|
162
193
|
|
|
163
|
-
const
|
|
194
|
+
const doRender = () => {
|
|
164
195
|
const root = transform(transformer, content);
|
|
165
196
|
mm.setData(root);
|
|
166
197
|
mm.fit();
|
|
167
198
|
};
|
|
168
199
|
|
|
169
|
-
transformer.hooks.retransform.tap(
|
|
170
|
-
|
|
200
|
+
transformer.hooks.retransform.tap(doRender);
|
|
201
|
+
doRender();
|
|
171
202
|
}
|
|
172
203
|
async function renderAllUnder(container) {
|
|
173
|
-
await
|
|
204
|
+
await ready;
|
|
174
205
|
container.querySelectorAll('.markmap').forEach(render);
|
|
175
206
|
}
|
|
176
207
|
function renderAll() {
|
|
@@ -183,8 +214,9 @@ if (!((_window$markmap = window.markmap) != null && (_window$markmap$autoL = _wi
|
|
|
183
214
|
});else renderAll();
|
|
184
215
|
}
|
|
185
216
|
|
|
217
|
+
exports.ready = ready;
|
|
186
218
|
exports.render = render;
|
|
187
219
|
exports.renderAll = renderAll;
|
|
188
220
|
exports.renderAllUnder = renderAllUnder;
|
|
189
221
|
|
|
190
|
-
}(this.markmap.autoLoader = this.markmap.autoLoader || {})
|
|
222
|
+
})(this.markmap.autoLoader = this.markmap.autoLoader || {});
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.
|
|
1
|
+
/*! markmap-autoloader v0.13.0-alpha.0 | MIT License */
|
|
2
2
|
this.markmap=this.markmap||{},function(t){"use strict";
|
|
3
|
-
/*! markmap-common v0.
|
|
3
|
+
/*! markmap-common v0.13.0-alpha.0 | 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}))}));function r(t,a){if("script"===t.type)return 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()}));if("iife"===t.type){const{fn:n,getParams:e}=t.data;n(...(null==e?void 0:e(a))||[])}}function o(t){"style"===t.type?document.head.append(e("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(e("link",n({rel:"stylesheet"},t.data)))}var s,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)}([{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.13.0-alpha.0,npm/markmap-view@0.13.0-alpha.0"}}]).then((()=>{var t;const{markmap:n}=window;!function(t){for(const n of t)o(n)}([{type:"style",data:n.globalCSS}]),null==(t=n.autoLoader)||null==t.onReady||t.onReady()}));function d(t){const{Transformer:n,Markmap:e,autoLoader:a}=window.markmap,r=t.textContent.split("\n");let o=1/0;r.forEach((t=>{const n=t.match(/^\s*/)[0].length;n<t.length&&(o=Math.min(o,n))}));const s=r.map((t=>t.slice(o))).join("\n"),c=new n(null==a?void 0:a.transformPlugins);t.innerHTML="<svg></svg>";const l=t.firstChild,d=e.create(l,{embedGlobalCSS:!1}),p=()=>{const t=function(t,n){const{root:e,features:a}=t.transform(n),r=Object.keys(a).filter((t=>!i[t]));r.forEach((t=>{i[t]=!0}));const{styles:o,scripts:s}=t.getAssets(r),{markmap:c}=window;return o&&c.loadCSS(o),s&&c.loadJS(s),e}(c,s);d.setData(t),d.fit()};c.hooks.retransform.tap(p),p()}async function p(t){await l,t.querySelectorAll(".markmap").forEach(d)}function u(){return p(document)}null!=(s=window.markmap)&&null!=(c=s.autoLoader)&&c.manual||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{u()})):u()),t.ready=l,t.render=d,t.renderAll=u,t.renderAllUnder=p}(this.markmap.autoLoader=this.markmap.autoLoader||{});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-autoloader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0-alpha.0",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "rollup -wc rollup.conf.js",
|
|
23
23
|
"clean": "del-cli dist types",
|
|
24
|
-
"lint": "eslint --ext .ts .",
|
|
25
24
|
"build:types": "tsc",
|
|
26
25
|
"build:js": "rollup -c rollup.conf.js"
|
|
27
26
|
},
|
|
@@ -39,11 +38,11 @@
|
|
|
39
38
|
"node": ">=10"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
|
-
"markmap-common": "^0.
|
|
41
|
+
"markmap-common": "^0.13.0-alpha.0"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"markmap-lib": "^0.
|
|
46
|
-
"markmap-view": "^0.
|
|
44
|
+
"markmap-lib": "^0.13.0-alpha.0",
|
|
45
|
+
"markmap-view": "^0.13.0-alpha.0"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "969aa149f36580954e77b7ba434e5c48b409cfc2"
|
|
49
48
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
1
|
+
export declare const ready: Promise<void>;
|
|
2
|
+
export declare function render(el: HTMLElement): void;
|
|
3
|
+
export declare function renderAllUnder(container: ParentNode): Promise<void>;
|
|
4
|
+
export declare function renderAll(): Promise<void>;
|