markmap-autoloader 0.1.3 → 0.2.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 +25 -20
- package/dist/index.min.js +2 -2
- package/package.json +7 -12
- 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.2.0 | MIT License */
|
|
2
2
|
this.markmap = this.markmap || {};
|
|
3
3
|
(function (exports) {
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
/*! markmap-common v0.1.
|
|
6
|
+
/*! markmap-common v0.1.6 | MIT License */
|
|
7
7
|
|
|
8
8
|
function _extends() {
|
|
9
9
|
_extends = Object.assign || function (target) {
|
|
@@ -107,19 +107,23 @@ async function loadJS(items, context) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
var _window$
|
|
110
|
+
var _window$markmap2, _window$markmap2$auto;
|
|
111
111
|
const enabled = {};
|
|
112
|
-
const
|
|
112
|
+
const ready = loadJS([{
|
|
113
113
|
type: 'script',
|
|
114
114
|
data: {
|
|
115
|
-
src: `https://cdn.jsdelivr.net/npm/d3@${"6.
|
|
115
|
+
src: `https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`
|
|
116
116
|
}
|
|
117
117
|
}, {
|
|
118
118
|
type: 'script',
|
|
119
119
|
data: {
|
|
120
|
-
src: `https://cdn.jsdelivr.net/combine/npm/markmap-lib@${"0.
|
|
120
|
+
src: `https://cdn.jsdelivr.net/combine/npm/markmap-lib@${"0.12.0"},npm/markmap-view@${"0.2.7"}`
|
|
121
121
|
}
|
|
122
|
-
}])
|
|
122
|
+
}]).then(() => {
|
|
123
|
+
var _window$markmap, _window$markmap$autoL;
|
|
124
|
+
|
|
125
|
+
(_window$markmap = window.markmap) == null ? void 0 : (_window$markmap$autoL = _window$markmap.autoLoader) == null ? void 0 : _window$markmap$autoL.onReady == null ? void 0 : _window$markmap$autoL.onReady();
|
|
126
|
+
});
|
|
123
127
|
|
|
124
128
|
function transform(transformer, content) {
|
|
125
129
|
const {
|
|
@@ -135,18 +139,18 @@ function transform(transformer, content) {
|
|
|
135
139
|
scripts
|
|
136
140
|
} = transformer.getAssets(keys);
|
|
137
141
|
const {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
if (scripts) loadJS(scripts);
|
|
142
|
+
markmap
|
|
143
|
+
} = window;
|
|
144
|
+
if (styles) markmap.loadCSS(styles);
|
|
145
|
+
if (scripts) markmap.loadJS(scripts);
|
|
143
146
|
return root;
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
function render(el) {
|
|
147
150
|
const {
|
|
148
151
|
Transformer,
|
|
149
|
-
Markmap
|
|
152
|
+
Markmap,
|
|
153
|
+
autoLoader
|
|
150
154
|
} = window.markmap;
|
|
151
155
|
const lines = el.textContent.split('\n');
|
|
152
156
|
let indent = Infinity;
|
|
@@ -155,36 +159,37 @@ function render(el) {
|
|
|
155
159
|
if (spaces < line.length) indent = Math.min(indent, spaces);
|
|
156
160
|
});
|
|
157
161
|
const content = lines.map(line => line.slice(indent)).join('\n');
|
|
158
|
-
const transformer = new Transformer();
|
|
162
|
+
const transformer = new Transformer(autoLoader == null ? void 0 : autoLoader.transformPlugins);
|
|
159
163
|
el.innerHTML = '<svg></svg>';
|
|
160
164
|
const svg = el.firstChild;
|
|
161
165
|
const mm = Markmap.create(svg);
|
|
162
166
|
|
|
163
|
-
const
|
|
167
|
+
const doRender = () => {
|
|
164
168
|
const root = transform(transformer, content);
|
|
165
169
|
mm.setData(root);
|
|
166
170
|
mm.fit();
|
|
167
171
|
};
|
|
168
172
|
|
|
169
|
-
transformer.hooks.retransform.tap(
|
|
170
|
-
|
|
173
|
+
transformer.hooks.retransform.tap(doRender);
|
|
174
|
+
doRender();
|
|
171
175
|
}
|
|
172
176
|
async function renderAllUnder(container) {
|
|
173
|
-
await
|
|
177
|
+
await ready;
|
|
174
178
|
container.querySelectorAll('.markmap').forEach(render);
|
|
175
179
|
}
|
|
176
180
|
function renderAll() {
|
|
177
181
|
return renderAllUnder(document);
|
|
178
182
|
}
|
|
179
183
|
|
|
180
|
-
if (!((_window$
|
|
184
|
+
if (!((_window$markmap2 = window.markmap) != null && (_window$markmap2$auto = _window$markmap2.autoLoader) != null && _window$markmap2$auto.manual)) {
|
|
181
185
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => {
|
|
182
186
|
renderAll();
|
|
183
187
|
});else renderAll();
|
|
184
188
|
}
|
|
185
189
|
|
|
190
|
+
exports.ready = ready;
|
|
186
191
|
exports.render = render;
|
|
187
192
|
exports.renderAll = renderAll;
|
|
188
193
|
exports.renderAllUnder = renderAllUnder;
|
|
189
194
|
|
|
190
|
-
}(this.markmap.autoLoader = this.markmap.autoLoader || {})
|
|
195
|
+
})(this.markmap.autoLoader = this.markmap.autoLoader || {});
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.
|
|
1
|
+
/*! markmap-autoloader v0.2.0 | MIT License */
|
|
2
2
|
this.markmap=this.markmap||{},function(t){"use strict";
|
|
3
|
-
/*! markmap-common v0.1.
|
|
3
|
+
/*! markmap-common v0.1.6 | MIT License */function n(){return n=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t[a]=r[a])}return t},n.apply(this,arguments)}function r(t,n,r){const a=document.createElement(t);return n&&Object.entries(n).forEach((([t,n])=>{a[t]=n})),r&&Object.entries(r).forEach((([t,n])=>{a.setAttribute(t,n)})),a}Math.random().toString(36).slice(2,8);const a=function(t){const n={};return function(...r){const a=`${r[0]}`;let e=n[a];return e||(e={value:t(...r)},n[a]=e),e.value}}((t=>{document.head.append(r("link",{rel:"preload",as:"script",href:t}))}));function e(t,a){if("script"===t.type)return new Promise(((a,e)=>{var o;document.head.append(r("script",n({},t.data,{onload:a,onerror:e}))),null!=(o=t.data)&&o.src||a()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(a))||[])}}var o,s;const c={},i=async function(t,r){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))),r=n({getMarkmap:()=>window.markmap},r);for(const n of t)await e(n,r)}([{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.12.0,npm/markmap-view@0.2.7"}}]).then((()=>{var t,n;null==(t=window.markmap)||null==(n=t.autoLoader)||null==n.onReady||n.onReady()}));function l(t){const{Transformer:n,Markmap:r,autoLoader:a}=window.markmap,e=t.textContent.split("\n");let o=1/0;e.forEach((t=>{const n=t.match(/^\s*/)[0].length;n<t.length&&(o=Math.min(o,n))}));const s=e.map((t=>t.slice(o))).join("\n"),i=new n(null==a?void 0:a.transformPlugins);t.innerHTML="<svg></svg>";const l=t.firstChild,d=r.create(l),u=()=>{const t=function(t,n){const{root:r,features:a}=t.transform(n),e=Object.keys(a).filter((t=>!c[t]));e.forEach((t=>{c[t]=!0}));const{styles:o,scripts:s}=t.getAssets(e),{markmap:i}=window;return o&&i.loadCSS(o),s&&i.loadJS(s),r}(i,s);d.setData(t),d.fit()};i.hooks.retransform.tap(u),u()}async function d(t){await i,t.querySelectorAll(".markmap").forEach(l)}function u(){return d(document)}null!=(o=window.markmap)&&null!=(s=o.autoLoader)&&s.manual||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{u()})):u()),t.ready=i,t.render=l,t.renderAll=u,t.renderAllUnder=d}(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.2.0",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,14 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "rollup -wc rollup.conf.js",
|
|
23
|
-
"clean": "del-cli dist",
|
|
24
|
-
"prebuild": "run-s ci clean",
|
|
25
|
-
"prepublishOnly": "run-s build",
|
|
26
|
-
"ci": "run-s lint",
|
|
27
|
-
"lint": "eslint --ext .ts .",
|
|
23
|
+
"clean": "del-cli dist types",
|
|
28
24
|
"build:types": "tsc",
|
|
29
|
-
"build:js": "rollup -c rollup.conf.js"
|
|
30
|
-
"build": "run-s build:types build:js"
|
|
25
|
+
"build:js": "rollup -c rollup.conf.js"
|
|
31
26
|
},
|
|
32
27
|
"bugs": {
|
|
33
28
|
"url": "https://github.com/gera2ld/markmap/issues"
|
|
@@ -43,11 +38,11 @@
|
|
|
43
38
|
"node": ">=10"
|
|
44
39
|
},
|
|
45
40
|
"dependencies": {
|
|
46
|
-
"markmap-common": "^0.1.
|
|
41
|
+
"markmap-common": "^0.1.6"
|
|
47
42
|
},
|
|
48
43
|
"devDependencies": {
|
|
49
|
-
"markmap-lib": "^0.
|
|
50
|
-
"markmap-view": "^0.2.
|
|
44
|
+
"markmap-lib": "^0.12.0",
|
|
45
|
+
"markmap-view": "^0.2.7"
|
|
51
46
|
},
|
|
52
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "fbec667e1706813f9f60bea6a971f3820858ca40"
|
|
53
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: any): void;
|
|
3
|
+
export declare function renderAllUnder(container: ParentNode): Promise<void>;
|
|
4
|
+
export declare function renderAll(): Promise<void>;
|