markmap-autoloader 0.15.5 → 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 CHANGED
@@ -1,459 +1,477 @@
1
- /*! markmap-autoloader v0.15.5 | MIT License */
2
1
  this.markmap = this.markmap || {};
3
- (function (exports) {
4
- 'use strict';
5
-
6
- function _extends$1() {
7
- _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
8
- for (var i = 1; i < arguments.length; i++) {
9
- var source = arguments[i];
10
- for (var key in source) {
11
- if (Object.prototype.hasOwnProperty.call(source, key)) {
12
- target[key] = source[key];
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
- return target;
17
- };
18
- return _extends$1.apply(this, arguments);
19
- }
20
-
21
- /*! markmap-common v0.15.5 | MIT License */
22
- function _extends() {
23
- _extends = Object.assign ? Object.assign.bind() : function (target) {
24
- for (var i = 1; i < arguments.length; i++) {
25
- var source = arguments[i];
26
- for (var key in source) {
27
- if (Object.prototype.hasOwnProperty.call(source, key)) {
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
- return target;
33
- };
34
- return _extends.apply(this, arguments);
35
- }
36
- const testPath = "npm2url/dist/index.cjs";
37
- const defaultProviders = {
38
- jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
39
- unpkg: path => `https://unpkg.com/${path}`
40
- };
41
- class UrlBuilder {
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
- getFastestProvider(timeout = 5e3, path = testPath) {
47
- return new Promise((resolve, reject) => {
48
- Promise.all(Object.entries(this.providers).map(async ([name, factory]) => {
49
- try {
50
- const res = await fetch(factory(path));
51
- if (!res.ok) {
52
- throw res;
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
- async findFastestProvider(timeout) {
62
- this.provider = await this.getFastestProvider(timeout);
63
- return this.provider;
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
- setProvider(name, factory) {
66
- if (factory) {
67
- this.providers[name] = factory;
68
- } else {
69
- delete this.providers[name];
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
- getFullUrl(path, provider = this.provider) {
73
- if (path.includes("://")) {
74
- return path;
75
- }
76
- const factory = this.providers[provider];
77
- if (!factory) {
78
- throw new Error(`Provider ${provider} not found`);
79
- }
80
- return factory(path);
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
- const urlBuilder = new UrlBuilder();
84
- Math.random().toString(36).slice(2, 8);
85
- function memoize(fn) {
86
- const cache = {};
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
- function Fragment(props) {
129
- return props.children;
130
- }
131
- const DEFAULT_ENV = {
132
- isSvg: false
133
- };
134
- function insertDom(parent, nodes) {
135
- if (!Array.isArray(nodes)) nodes = [nodes];
136
- nodes = nodes.filter(Boolean);
137
- if (nodes.length) parent.append(...nodes);
138
- }
139
- function mountAttributes(domElement, props, env) {
140
- for (const key in props) {
141
- if (key === 'key' || key === 'children' || key === 'ref') continue;
142
- if (key === 'dangerouslySetInnerHTML') {
143
- domElement.innerHTML = props[key].__html;
144
- } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
145
- const value = props[key];
146
- if (value != null) domElement[key] = value;
147
- } else if (key.startsWith('on')) {
148
- domElement[key.toLowerCase()] = props[key];
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
- const attrMap = {
155
- className: 'class',
156
- labelFor: 'for'
157
- };
158
- function setDOMAttribute(el, attr, value, isSVG) {
159
- attr = attrMap[attr] || attr;
160
- if (value === true) {
161
- el.setAttribute(attr, '');
162
- } else if (value === false) {
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
- el.setAttribute(attr, value);
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
- function flatten(arr) {
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
- if (vnode instanceof Node) {
184
- return vnode;
183
+ function mountChildren(children, env) {
184
+ return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
185
185
  }
186
- if (isRenderFunction(vnode)) {
187
- const {
188
- type,
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
- const childVNode = type(props);
200
- return mount(childVNode, env);
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 (!env.isSvg) {
217
- node = document.createElement(type);
218
- } else {
219
- node = document.createElementNS(SVG_NS, type);
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
- mountAttributes(node, props, env);
222
- if (props.children) {
223
- let childEnv = env;
224
- if (env.isSvg && type === 'foreignObject') {
225
- childEnv = Object.assign({}, childEnv, {
226
- isSvg: false
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
- const children = mountChildren(props.children, childEnv);
230
- if (children != null) insertDom(node, children);
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
- const {
233
- ref
234
- } = props;
235
- if (typeof ref === 'function') ref(node);
236
- return node;
247
+ throw new Error("mount: Invalid Vnode!");
248
+ }
249
+ function mountDom(vnode) {
250
+ return mount(vnode);
237
251
  }
238
- throw new Error('mount: Invalid Vnode!');
239
- }
240
-
241
- /**
242
- * Mount vdom as real DOM nodes.
243
- */
244
- function mountDom(vnode) {
245
- return mount(vnode);
246
- }
247
-
248
- /**
249
- * Render and mount without returning VirtualDOM, useful when you don't need SVG support.
250
- */
251
- function hm(...args) {
252
- return mountDom(h(...args));
253
- }
254
- const memoizedPreloadJS = memoize(url => {
255
- document.head.append(hm('link', {
256
- rel: 'preload',
257
- as: 'script',
258
- href: url
259
- }));
260
- });
261
- const jsCache = {};
262
- const cssCache = {};
263
- async function loadJSItem(item, context) {
264
- var _item$data;
265
- const src = item.type === 'script' && ((_item$data = item.data) == null ? void 0 : _item$data.src) || '';
266
- item.loaded || (item.loaded = jsCache[src]);
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
- // Run inline script synchronously
276
- resolve(undefined);
282
+ deferred.resolve();
283
+ } else {
284
+ jsCache[src] = item.loaded;
277
285
  }
278
- }).then(() => {
279
- item.loaded = true;
280
- });
281
- if (src) jsCache[src] = item.loaded;
282
- }
283
- if (item.type === 'iife') {
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
- await item.loaded;
293
- }
294
- function loadCSSItem(item) {
295
- const url = item.type === 'stylesheet' && item.data.href || '';
296
- item.loaded || (item.loaded = cssCache[url]);
297
- if (item.loaded) return;
298
- item.loaded = true;
299
- if (url) cssCache[url] = true;
300
- if (item.type === 'style') {
301
- document.head.append(hm('style', {
302
- textContent: item.data
303
- }));
304
- } else if (item.type === 'stylesheet') {
305
- document.head.append(hm('link', _extends({
306
- rel: 'stylesheet'
307
- }, item.data)));
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
- async function loadJS(items, context) {
311
- items.forEach(item => {
312
- var _item$data2;
313
- if (item.type === 'script' && (_item$data2 = item.data) != null && _item$data2.src) {
314
- memoizedPreloadJS(item.data.src);
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
- function loadCSS(items) {
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
- function buildJSItem(path) {
330
- return {
331
- type: 'script',
332
- data: {
333
- src: path
334
- }
335
- };
336
- }
337
- function buildCSSItem(path) {
338
- return {
339
- type: 'stylesheet',
340
- data: {
341
- href: path
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
- var _window$markmap;
347
- const enabled = {};
348
- const autoLoaderOptions = _extends$1({
349
- baseJs: [`d3@${"7.8.5"}`, `markmap-lib@${"0.15.5"}`, `markmap-view@${"0.15.5"}`, `markmap-toolbar@${"0.15.5"}`],
350
- baseCss: [`markmap-toolbar@${"0.15.5"}/dist/style.css`],
351
- manual: false,
352
- toolbar: false
353
- }, (_window$markmap = window.markmap) == null ? void 0 : _window$markmap.autoLoader);
354
- async function initialize() {
355
- if (typeof autoLoaderOptions.provider === 'function') {
356
- urlBuilder.setProvider(urlBuilder.provider = 'autoLoader', autoLoaderOptions.provider);
357
- } else if (typeof autoLoaderOptions.provider === 'string') {
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
- await Promise.all([loadJS(autoLoaderOptions.baseJs.map(item => typeof item === 'string' ? buildJSItem(urlBuilder.getFullUrl(item)) : item)), loadCSS(autoLoaderOptions.baseCss.map(item => typeof item === 'string' ? buildCSSItem(urlBuilder.getFullUrl(item)) : item))]);
367
- const {
368
- markmap
369
- } = window;
370
- const style = document.createElement('style');
371
- style.textContent = markmap.globalCSS;
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
- el.append(toolbar);
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
- const doRender = () => {
429
- const {
430
- root,
431
- frontmatter
432
- } = transform(transformer, content);
433
- const markmapOptions = frontmatter == null ? void 0 : frontmatter.markmap;
434
- const frontmatterOptions = deriveOptions(markmapOptions);
435
- mm.setData(root, frontmatterOptions);
436
- mm.fit();
437
- };
438
- transformer.hooks.retransform.tap(doRender);
439
- doRender();
440
- }
441
- async function renderAllUnder(container) {
442
- await ready;
443
- container.querySelectorAll('.markmap').forEach(render);
444
- }
445
- function renderAll() {
446
- return renderAllUnder(document);
447
- }
448
- if (!autoLoaderOptions.manual) {
449
- if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => {
450
- renderAll();
451
- });else renderAll();
452
- }
453
-
454
- exports.ready = ready;
455
- exports.render = render;
456
- exports.renderAll = renderAll;
457
- exports.renderAllUnder = renderAllUnder;
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.5",
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
- "dev": "rollup -wc",
23
- "clean": "del-cli dist types",
22
+ "clean": "del-cli dist",
24
23
  "build:types": "tsc",
25
- "build:js": "rollup -c"
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
39
  "markmap-common": "0.15.5",
42
- "markmap-lib": "0.15.5",
43
- "markmap-toolbar": "0.15.5",
44
- "markmap-view": "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": "f7bda12b219cba3833dec1dae1daad14c3b53db6"
44
+ "gitHead": "473411985496abcc20a546978438614c48ec56cf"
47
45
  }
File without changes