markmap-view 0.14.5-alpha.21 → 0.14.5-alpha.24

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.
@@ -1,8 +1,65 @@
1
- /*! markmap-view v0.14.5-alpha.21+fb81f2c | MIT License */
1
+ /*! markmap-view v0.14.5-alpha.24+08dd40c | MIT License */
2
2
  (function (exports, d3) {
3
3
  'use strict';
4
4
 
5
- /*! markmap-common v0.14.5-alpha.21+fb81f2c | MIT License */
5
+ /*! markmap-common v0.14.5-alpha.24+08dd40c | MIT License */
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
+ }
14
+ }
15
+ }
16
+ return target;
17
+ };
18
+ return _extends$1.apply(this, arguments);
19
+ }
20
+ const testPath = "npm2url/dist/index.cjs";
21
+ const defaultProviders = {
22
+ jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
23
+ unpkg: path => `https://unpkg.com/${path}`
24
+ };
25
+ class UrlBuilder {
26
+ constructor() {
27
+ this.providers = _extends$1({}, defaultProviders);
28
+ this.provider = "jsdelivr";
29
+ }
30
+ getFastestProvider(path = testPath) {
31
+ return Promise.any(Object.entries(this.providers).map(async ([name, factory]) => {
32
+ const res = await fetch(factory(path));
33
+ if (!res.ok) {
34
+ throw res;
35
+ }
36
+ await res.text();
37
+ return name;
38
+ }));
39
+ }
40
+ async findFastestProvider() {
41
+ this.provider = await this.getFastestProvider();
42
+ return this.provider;
43
+ }
44
+ setProvider(name, factory) {
45
+ if (factory) {
46
+ this.providers[name] = factory;
47
+ } else {
48
+ delete this.providers[name];
49
+ }
50
+ }
51
+ getFullUrl(path, provider = this.provider) {
52
+ if (path.includes("://")) {
53
+ return path;
54
+ }
55
+ const factory = this.providers[provider];
56
+ if (!factory) {
57
+ throw new Error(`Provider ${provider} not found`);
58
+ }
59
+ return factory(path);
60
+ }
61
+ }
62
+ new UrlBuilder();
6
63
  class Hook {
7
64
  constructor() {
8
65
  this.listeners = [];
@@ -24,20 +81,6 @@ class Hook {
24
81
  }
25
82
  }
26
83
  }
27
- function _extends$1() {
28
- _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
29
- for (var i = 1; i < arguments.length; i++) {
30
- var source = arguments[i];
31
- for (var key in source) {
32
- if (Object.prototype.hasOwnProperty.call(source, key)) {
33
- target[key] = source[key];
34
- }
35
- }
36
- }
37
- return target;
38
- };
39
- return _extends$1.apply(this, arguments);
40
- }
41
84
  const uniqId = Math.random().toString(36).slice(2, 8);
42
85
  let globalIndex = 0;
43
86
  function getId() {
@@ -251,20 +294,27 @@ const memoizedPreloadJS = memoize(url => {
251
294
  href: url
252
295
  }));
253
296
  });
297
+ const jsCache = {};
298
+ const cssCache = {};
254
299
  async function loadJSItem(item, context) {
300
+ var _item$data;
301
+ const src = item.type === 'script' && ((_item$data = item.data) == null ? void 0 : _item$data.src) || '';
302
+ item.loaded || (item.loaded = jsCache[src]);
255
303
  if (!item.loaded) {
256
304
  if (item.type === 'script') {
257
305
  item.loaded = new Promise((resolve, reject) => {
258
- var _item$data;
259
306
  document.head.append(hm('script', _extends$1({}, item.data, {
260
307
  onLoad: resolve,
261
308
  onError: reject
262
309
  })));
263
- // Run inline script synchronously
264
- if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
310
+ if (!src) {
311
+ // Run inline script synchronously
312
+ resolve(undefined);
313
+ }
265
314
  }).then(() => {
266
315
  item.loaded = true;
267
316
  });
317
+ if (src) jsCache[src] = item.loaded;
268
318
  }
269
319
  if (item.type === 'iife') {
270
320
  const {
@@ -278,8 +328,11 @@ async function loadJSItem(item, context) {
278
328
  await item.loaded;
279
329
  }
280
330
  function loadCSSItem(item) {
331
+ const url = item.type === 'stylesheet' && item.data.href || '';
332
+ item.loaded || (item.loaded = cssCache[url]);
281
333
  if (item.loaded) return;
282
334
  item.loaded = true;
335
+ if (url) cssCache[url] = true;
283
336
  if (item.type === 'style') {
284
337
  document.head.append(hm('style', {
285
338
  textContent: item.data
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-view v0.14.5-alpha.21+fb81f2c | MIT License */
1
+ /*! markmap-view v0.14.5-alpha.24+08dd40c | MIT License */
2
2
  import { Hook, getId, addClass, walkTree, childSelector, noop } from 'markmap-common';
3
3
  export { loadCSS, loadJS } from 'markmap-common';
4
4
  import { scaleOrdinal, schemeCategory10, zoomTransform, select, zoom, linkHorizontal, min, max, zoomIdentity, minIndex } from 'd3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-view",
3
- "version": "0.14.5-alpha.21+fb81f2c",
3
+ "version": "0.14.5-alpha.24+08dd40c",
4
4
  "description": "View markmaps in browser",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -46,10 +46,10 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/d3-flextree": "^2.1.1",
49
- "markmap-common": "0.14.5-alpha.21+fb81f2c"
49
+ "markmap-common": "0.14.5-alpha.24+08dd40c"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "markmap-common": "*"
53
53
  },
54
- "gitHead": "fb81f2cb688f400f17f911774539267219f639ce"
54
+ "gitHead": "08dd40c9353058928a148f6b97d11e98ec1d328b"
55
55
  }