markmap-autoloader 0.15.2-alpha.1 → 0.15.3-alpha.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -16
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-autoloader v0.15.2-alpha.1+6800b6d | MIT License */
1
+ /*! markmap-autoloader v0.15.3-alpha.1+fb5e189 | 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.15.0 | MIT License */
21
+ /*! markmap-common v0.15.3-alpha.1+fb5e189 | 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++) {
@@ -43,18 +43,23 @@ class UrlBuilder {
43
43
  this.providers = _extends({}, defaultProviders);
44
44
  this.provider = "jsdelivr";
45
45
  }
46
- getFastestProvider(path = testPath) {
47
- return Promise.any(Object.entries(this.providers).map(async ([name, factory]) => {
48
- const res = await fetch(factory(path));
49
- if (!res.ok) {
50
- throw res;
51
- }
52
- await res.text();
53
- return name;
54
- }));
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"));
59
+ });
55
60
  }
56
- async findFastestProvider() {
57
- this.provider = await this.getFastestProvider();
61
+ async findFastestProvider(timeout) {
62
+ this.provider = await this.getFastestProvider(timeout);
58
63
  return this.provider;
59
64
  }
60
65
  setProvider(name, factory) {
@@ -341,13 +346,17 @@ function buildCSSItem(path) {
341
346
  var _window$markmap;
342
347
  const enabled = {};
343
348
  const autoLoaderOptions = _extends$1({
344
- baseJs: [`d3@${"7.8.5"}`, `markmap-lib@${"0.15.2-alpha.1"}`, `markmap-view@${"0.15.0"}`, `markmap-toolbar@${"0.15.0"}`],
345
- baseCss: [`markmap-toolbar@${"0.15.0"}/dist/style.css`],
349
+ baseJs: [`d3@${"7.8.5"}`, `markmap-lib@${"0.15.3-alpha.1"}`, `markmap-view@${"0.15.3-alpha.1"}`, `markmap-toolbar@${"0.15.3-alpha.1"}`],
350
+ baseCss: [`markmap-toolbar@${"0.15.3-alpha.1"}/dist/style.css`],
346
351
  manual: false,
347
352
  toolbar: false
348
353
  }, (_window$markmap = window.markmap) == null ? void 0 : _window$markmap.autoLoader);
349
354
  async function initialize() {
350
- await urlBuilder.findFastestProvider();
355
+ try {
356
+ await urlBuilder.findFastestProvider();
357
+ } catch (_unused) {
358
+ // ignore
359
+ }
351
360
  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))]);
352
361
  const {
353
362
  markmap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-autoloader",
3
- "version": "0.15.2-alpha.1+6800b6d",
3
+ "version": "0.15.3-alpha.1+fb5e189",
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.15.0",
42
- "markmap-lib": "0.15.2-alpha.1+6800b6d",
43
- "markmap-toolbar": "0.15.0",
44
- "markmap-view": "0.15.0"
41
+ "markmap-common": "0.15.3-alpha.1+fb5e189",
42
+ "markmap-lib": "0.15.3-alpha.1+fb5e189",
43
+ "markmap-toolbar": "0.15.3-alpha.1+fb5e189",
44
+ "markmap-view": "0.15.3-alpha.1+fb5e189"
45
45
  },
46
- "gitHead": "6800b6db7cde4b2a27175091eeccc8abbf7fadba"
46
+ "gitHead": "fb5e1891c9cfda0426feb8f43555f32c56648f10"
47
47
  }