markmap-autoloader 0.2.0 → 0.13.1
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 -8
- package/dist/index.min.js +2 -2
- package/package.json +5 -5
- package/types/index.d.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.
|
|
1
|
+
/*! markmap-autoloader v0.13.1 | 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 | 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,7 +119,13 @@ async function loadJS(items, context) {
|
|
|
107
119
|
}
|
|
108
120
|
}
|
|
109
121
|
|
|
110
|
-
|
|
122
|
+
function loadCSS(items) {
|
|
123
|
+
for (const item of items) {
|
|
124
|
+
loadCSSItem(item);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var _window$markmap, _window$markmap$autoL;
|
|
111
129
|
const enabled = {};
|
|
112
130
|
const ready = loadJS([{
|
|
113
131
|
type: 'script',
|
|
@@ -117,12 +135,19 @@ const ready = loadJS([{
|
|
|
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.1"},npm/markmap-view@${"0.13.1"}`
|
|
121
139
|
}
|
|
122
140
|
}]).then(() => {
|
|
123
|
-
var
|
|
141
|
+
var _markmap$autoLoader;
|
|
124
142
|
|
|
125
|
-
|
|
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();
|
|
126
151
|
});
|
|
127
152
|
|
|
128
153
|
function transform(transformer, content) {
|
|
@@ -162,7 +187,9 @@ function render(el) {
|
|
|
162
187
|
const transformer = new Transformer(autoLoader == null ? void 0 : autoLoader.transformPlugins);
|
|
163
188
|
el.innerHTML = '<svg></svg>';
|
|
164
189
|
const svg = el.firstChild;
|
|
165
|
-
const mm = Markmap.create(svg
|
|
190
|
+
const mm = Markmap.create(svg, {
|
|
191
|
+
embedGlobalCSS: false
|
|
192
|
+
});
|
|
166
193
|
|
|
167
194
|
const doRender = () => {
|
|
168
195
|
const root = transform(transformer, content);
|
|
@@ -181,7 +208,7 @@ function renderAll() {
|
|
|
181
208
|
return renderAllUnder(document);
|
|
182
209
|
}
|
|
183
210
|
|
|
184
|
-
if (!((_window$
|
|
211
|
+
if (!((_window$markmap = window.markmap) != null && (_window$markmap$autoL = _window$markmap.autoLoader) != null && _window$markmap$autoL.manual)) {
|
|
185
212
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => {
|
|
186
213
|
renderAll();
|
|
187
214
|
});else renderAll();
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! markmap-autoloader v0.
|
|
1
|
+
/*! markmap-autoloader v0.13.1 | MIT License */
|
|
2
2
|
this.markmap=this.markmap||{},function(t){"use strict";
|
|
3
|
-
/*! markmap-common v0.
|
|
3
|
+
/*! markmap-common v0.13.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.1,npm/markmap-view@0.13.1"}}]).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}),u=()=>{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(u),u()}async function u(t){await l,t.querySelectorAll(".markmap").forEach(d)}function m(){return u(document)}null!=(s=window.markmap)&&null!=(c=s.autoLoader)&&c.manual||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{m()})):m()),t.ready=l,t.render=d,t.renderAll=m,t.renderAllUnder=u}(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.1",
|
|
4
4
|
"description": "Load markmaps automatically in HTML",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"node": ">=10"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"markmap-common": "^0.
|
|
41
|
+
"markmap-common": "^0.13.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"markmap-lib": "^0.
|
|
45
|
-
"markmap-view": "^0.
|
|
44
|
+
"markmap-lib": "^0.13.1",
|
|
45
|
+
"markmap-view": "^0.13.1"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "c23f372da8c72b8053659cfbb9583c027dea6dab"
|
|
48
48
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const ready: Promise<void>;
|
|
2
|
-
export declare function render(el:
|
|
2
|
+
export declare function render(el: HTMLElement): void;
|
|
3
3
|
export declare function renderAllUnder(container: ParentNode): Promise<void>;
|
|
4
4
|
export declare function renderAll(): Promise<void>;
|