markmap-view 0.18.4-alpha.4 → 0.18.5-alpha.6

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,5 +1,330 @@
1
1
  (function(exports, d32) {
2
2
  "use strict";
3
+ class Hook {
4
+ constructor() {
5
+ this.listeners = [];
6
+ }
7
+ tap(fn) {
8
+ this.listeners.push(fn);
9
+ return () => this.revoke(fn);
10
+ }
11
+ revoke(fn) {
12
+ const i = this.listeners.indexOf(fn);
13
+ if (i >= 0) this.listeners.splice(i, 1);
14
+ }
15
+ revokeAll() {
16
+ this.listeners.splice(0);
17
+ }
18
+ call(...args) {
19
+ for (const fn of this.listeners) {
20
+ fn(...args);
21
+ }
22
+ }
23
+ }
24
+ const uniqId = Math.random().toString(36).slice(2, 8);
25
+ let globalIndex = 0;
26
+ function getId() {
27
+ globalIndex += 1;
28
+ return `mm-${uniqId}-${globalIndex}`;
29
+ }
30
+ function noop() {
31
+ }
32
+ function walkTree(tree, callback) {
33
+ const walk = (item, parent) => callback(
34
+ item,
35
+ () => {
36
+ var _a;
37
+ return (_a = item.children) == null ? void 0 : _a.map((child) => walk(child, item));
38
+ },
39
+ parent
40
+ );
41
+ return walk(tree);
42
+ }
43
+ function addClass(className, ...rest) {
44
+ const classList = (className || "").split(" ").filter(Boolean);
45
+ rest.forEach((item) => {
46
+ if (item && classList.indexOf(item) < 0) classList.push(item);
47
+ });
48
+ return classList.join(" ");
49
+ }
50
+ function defer() {
51
+ const obj = {};
52
+ obj.promise = new Promise((resolve, reject) => {
53
+ obj.resolve = resolve;
54
+ obj.reject = reject;
55
+ });
56
+ return obj;
57
+ }
58
+ function memoize(fn) {
59
+ const cache = {};
60
+ return function memoized(...args) {
61
+ const key = `${args[0]}`;
62
+ let data = cache[key];
63
+ if (!data) {
64
+ data = {
65
+ value: fn(...args)
66
+ };
67
+ cache[key] = data;
68
+ }
69
+ return data.value;
70
+ };
71
+ }
72
+ function debounce(fn, time) {
73
+ const state = {
74
+ timer: 0
75
+ };
76
+ function reset() {
77
+ if (state.timer) {
78
+ window.clearTimeout(state.timer);
79
+ state.timer = 0;
80
+ }
81
+ }
82
+ function run() {
83
+ reset();
84
+ if (state.args) state.result = fn(...state.args);
85
+ }
86
+ return function debounced(...args) {
87
+ reset();
88
+ state.args = args;
89
+ state.timer = window.setTimeout(run, time);
90
+ return state.result;
91
+ };
92
+ }
93
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
94
+ const VTYPE_ELEMENT = 1;
95
+ const VTYPE_FUNCTION = 2;
96
+ const SVG_NS = "http://www.w3.org/2000/svg";
97
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
98
+ const NS_ATTRS = {
99
+ show: XLINK_NS,
100
+ actuate: XLINK_NS,
101
+ href: XLINK_NS
102
+ };
103
+ const isLeaf = (c) => typeof c === "string" || typeof c === "number";
104
+ const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
105
+ const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
106
+ function h(type, props, ...children) {
107
+ props = Object.assign({}, props, {
108
+ children: children.length === 1 ? children[0] : children
109
+ });
110
+ return jsx(type, props);
111
+ }
112
+ function jsx(type, props) {
113
+ let vtype;
114
+ if (typeof type === "string") vtype = VTYPE_ELEMENT;
115
+ else if (typeof type === "function") vtype = VTYPE_FUNCTION;
116
+ else throw new Error("Invalid VNode type");
117
+ return {
118
+ vtype,
119
+ type,
120
+ props
121
+ };
122
+ }
123
+ function Fragment(props) {
124
+ return props.children;
125
+ }
126
+ const DEFAULT_ENV = {
127
+ isSvg: false
128
+ };
129
+ function insertDom(parent, nodes) {
130
+ if (!Array.isArray(nodes)) nodes = [nodes];
131
+ nodes = nodes.filter(Boolean);
132
+ if (nodes.length) parent.append(...nodes);
133
+ }
134
+ function mountAttributes(domElement, props, env) {
135
+ for (const key in props) {
136
+ if (key === "key" || key === "children" || key === "ref") continue;
137
+ if (key === "dangerouslySetInnerHTML") {
138
+ domElement.innerHTML = props[key].__html;
139
+ } else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
140
+ const value = props[key];
141
+ if (value != null) domElement[key] = value;
142
+ } else if (key.startsWith("on")) {
143
+ domElement[key.toLowerCase()] = props[key];
144
+ } else {
145
+ setDOMAttribute(domElement, key, props[key], env.isSvg);
146
+ }
147
+ }
148
+ }
149
+ const attrMap = {
150
+ className: "class",
151
+ labelFor: "for"
152
+ };
153
+ function setDOMAttribute(el, attr, value, isSVG) {
154
+ attr = attrMap[attr] || attr;
155
+ if (value === true) {
156
+ el.setAttribute(attr, "");
157
+ } else if (value === false) {
158
+ el.removeAttribute(attr);
159
+ } else {
160
+ const namespace = isSVG ? NS_ATTRS[attr] : void 0;
161
+ if (namespace !== void 0) {
162
+ el.setAttributeNS(namespace, attr, value);
163
+ } else {
164
+ el.setAttribute(attr, value);
165
+ }
166
+ }
167
+ }
168
+ function flatten(arr) {
169
+ return arr.reduce((prev, item) => prev.concat(item), []);
170
+ }
171
+ function mountChildren(children, env) {
172
+ return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
173
+ }
174
+ function mount(vnode, env = DEFAULT_ENV) {
175
+ if (vnode == null || typeof vnode === "boolean") {
176
+ return null;
177
+ }
178
+ if (vnode instanceof Node) {
179
+ return vnode;
180
+ }
181
+ if (isRenderFunction(vnode)) {
182
+ const {
183
+ type,
184
+ props
185
+ } = vnode;
186
+ if (type === Fragment) {
187
+ const node = document.createDocumentFragment();
188
+ if (props.children) {
189
+ const children = mountChildren(props.children, env);
190
+ insertDom(node, children);
191
+ }
192
+ return node;
193
+ }
194
+ const childVNode = type(props);
195
+ return mount(childVNode, env);
196
+ }
197
+ if (isLeaf(vnode)) {
198
+ return document.createTextNode(`${vnode}`);
199
+ }
200
+ if (isElement(vnode)) {
201
+ let node;
202
+ const {
203
+ type,
204
+ props
205
+ } = vnode;
206
+ if (!env.isSvg && type === "svg") {
207
+ env = Object.assign({}, env, {
208
+ isSvg: true
209
+ });
210
+ }
211
+ if (!env.isSvg) {
212
+ node = document.createElement(type);
213
+ } else {
214
+ node = document.createElementNS(SVG_NS, type);
215
+ }
216
+ mountAttributes(node, props, env);
217
+ if (props.children) {
218
+ let childEnv = env;
219
+ if (env.isSvg && type === "foreignObject") {
220
+ childEnv = Object.assign({}, childEnv, {
221
+ isSvg: false
222
+ });
223
+ }
224
+ const children = mountChildren(props.children, childEnv);
225
+ if (children != null) insertDom(node, children);
226
+ }
227
+ const {
228
+ ref
229
+ } = props;
230
+ if (typeof ref === "function") ref(node);
231
+ return node;
232
+ }
233
+ throw new Error("mount: Invalid Vnode!");
234
+ }
235
+ function mountDom(vnode) {
236
+ return mount(vnode);
237
+ }
238
+ function hm(...args) {
239
+ return mountDom(h(...args));
240
+ }
241
+ const memoizedPreloadJS = memoize((url) => {
242
+ document.head.append(
243
+ hm("link", {
244
+ rel: "preload",
245
+ as: "script",
246
+ href: url
247
+ })
248
+ );
249
+ });
250
+ const jsCache = {};
251
+ const cssCache = {};
252
+ async function loadJSItem(item, context) {
253
+ var _a;
254
+ const src = item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src) || "";
255
+ item.loaded || (item.loaded = jsCache[src]);
256
+ if (!item.loaded) {
257
+ const deferred = defer();
258
+ item.loaded = deferred.promise;
259
+ if (item.type === "script") {
260
+ document.head.append(
261
+ hm("script", {
262
+ ...item.data,
263
+ onLoad: () => deferred.resolve(),
264
+ onError: deferred.reject
265
+ })
266
+ );
267
+ if (!src) {
268
+ deferred.resolve();
269
+ } else {
270
+ jsCache[src] = item.loaded;
271
+ }
272
+ }
273
+ if (item.type === "iife") {
274
+ const { fn, getParams } = item.data;
275
+ fn(...(getParams == null ? void 0 : getParams(context)) || []);
276
+ deferred.resolve();
277
+ }
278
+ }
279
+ await item.loaded;
280
+ }
281
+ async function loadCSSItem(item) {
282
+ const url = item.type === "stylesheet" && item.data.href || "";
283
+ item.loaded || (item.loaded = cssCache[url]);
284
+ if (!item.loaded) {
285
+ const deferred = defer();
286
+ item.loaded = deferred.promise;
287
+ if (url) cssCache[url] = item.loaded;
288
+ if (item.type === "style") {
289
+ document.head.append(
290
+ hm("style", {
291
+ textContent: item.data
292
+ })
293
+ );
294
+ deferred.resolve();
295
+ } else if (url) {
296
+ document.head.append(
297
+ hm("link", {
298
+ rel: "stylesheet",
299
+ ...item.data
300
+ })
301
+ );
302
+ fetch(url).then((res) => {
303
+ if (res.ok) return res.text();
304
+ throw res;
305
+ }).then(() => deferred.resolve(), deferred.reject);
306
+ }
307
+ }
308
+ await item.loaded;
309
+ }
310
+ async function loadJS(items, context) {
311
+ items.forEach((item) => {
312
+ var _a;
313
+ if (item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src)) {
314
+ memoizedPreloadJS(item.data.src);
315
+ }
316
+ });
317
+ context = {
318
+ getMarkmap: () => window.markmap,
319
+ ...context
320
+ };
321
+ for (const item of items) {
322
+ await loadJSItem(item, context);
323
+ }
324
+ }
325
+ async function loadCSS(items) {
326
+ await Promise.all(items.map((item) => loadCSSItem(item)));
327
+ }
3
328
  const isMacintosh = typeof navigator !== "undefined" && navigator.userAgent.includes("Macintosh");
4
329
  const defaultColorFn = d32.scaleOrdinal(d32.schemeCategory10);
5
330
  const defaultOptions = {
@@ -76,6 +401,18 @@
76
401
  }
77
402
  return (hash >>> 0).toString(36);
78
403
  }
404
+ function childSelector(filter) {
405
+ if (typeof filter === "string") {
406
+ const tagName = filter;
407
+ filter = (el) => el.tagName === tagName;
408
+ }
409
+ const filterFn = filter;
410
+ return function selector() {
411
+ let nodes = Array.from(this.childNodes);
412
+ if (filterFn) nodes = nodes.filter((node) => filterFn(node));
413
+ return nodes;
414
+ };
415
+ }
79
416
  function count(node) {
80
417
  var sum = 0, children = node.children, i = children && children.length;
81
418
  if (!i) sum = 1;
@@ -193,14 +530,14 @@
193
530
  return links;
194
531
  }
195
532
  function hierarchy(data, children) {
196
- var root = new Node(data), valued = +data.value && (root.value = data.value), node, nodes = [root], child, childs, i, n;
533
+ var root = new Node$1(data), valued = +data.value && (root.value = data.value), node, nodes = [root], child, childs, i, n;
197
534
  if (children == null) children = defaultChildren;
198
535
  while (node = nodes.pop()) {
199
536
  if (valued) node.value = +node.data.value;
200
537
  if ((childs = children(node.data)) && (n = childs.length)) {
201
538
  node.children = new Array(n);
202
539
  for (i = n - 1; i >= 0; --i) {
203
- nodes.push(child = node.children[i] = new Node(childs[i]));
540
+ nodes.push(child = node.children[i] = new Node$1(childs[i]));
204
541
  child.parent = node;
205
542
  child.depth = node.depth + 1;
206
543
  }
@@ -223,13 +560,13 @@
223
560
  node.height = height;
224
561
  while ((node = node.parent) && node.height < ++height);
225
562
  }
226
- function Node(data) {
563
+ function Node$1(data) {
227
564
  this.data = data;
228
565
  this.depth = this.height = 0;
229
566
  this.parent = null;
230
567
  }
231
- Node.prototype = hierarchy.prototype = {
232
- constructor: Node,
568
+ Node$1.prototype = hierarchy.prototype = {
569
+ constructor: Node$1,
233
570
  count: node_count,
234
571
  each: node_each,
235
572
  eachAfter: node_eachAfter,
@@ -605,86 +942,6 @@
605
942
  next: lastLows
606
943
  };
607
944
  };
608
- class Hook {
609
- constructor() {
610
- this.listeners = [];
611
- }
612
- tap(fn) {
613
- this.listeners.push(fn);
614
- return () => this.revoke(fn);
615
- }
616
- revoke(fn) {
617
- const i = this.listeners.indexOf(fn);
618
- if (i >= 0) this.listeners.splice(i, 1);
619
- }
620
- revokeAll() {
621
- this.listeners.splice(0);
622
- }
623
- call(...args) {
624
- for (const fn of this.listeners) {
625
- fn(...args);
626
- }
627
- }
628
- }
629
- const uniqId = Math.random().toString(36).slice(2, 8);
630
- let globalIndex = 0;
631
- function getId() {
632
- globalIndex += 1;
633
- return `mm-${uniqId}-${globalIndex}`;
634
- }
635
- function noop() {
636
- }
637
- function walkTree(tree, callback) {
638
- const walk = (item, parent) => callback(
639
- item,
640
- () => {
641
- var _a;
642
- return (_a = item.children) == null ? void 0 : _a.map((child) => walk(child, item));
643
- },
644
- parent
645
- );
646
- return walk(tree);
647
- }
648
- function addClass(className, ...rest) {
649
- const classList = (className || "").split(" ").filter(Boolean);
650
- rest.forEach((item) => {
651
- if (item && classList.indexOf(item) < 0) classList.push(item);
652
- });
653
- return classList.join(" ");
654
- }
655
- function childSelector(filter) {
656
- if (typeof filter === "string") {
657
- const tagName = filter;
658
- filter = (el) => el.tagName === tagName;
659
- }
660
- const filterFn = filter;
661
- return function selector() {
662
- let nodes = Array.from(this.childNodes);
663
- if (filterFn) nodes = nodes.filter((node) => filterFn(node));
664
- return nodes;
665
- };
666
- }
667
- function debounce(fn, time) {
668
- const state = {
669
- timer: 0
670
- };
671
- function reset() {
672
- if (state.timer) {
673
- window.clearTimeout(state.timer);
674
- state.timer = 0;
675
- }
676
- }
677
- function run() {
678
- reset();
679
- if (state.args) state.result = fn(...state.args);
680
- }
681
- return function debounced(...args) {
682
- reset();
683
- state.args = args;
684
- state.timer = window.setTimeout(run, time);
685
- return state.result;
686
- };
687
- }
688
945
  const css = ".markmap {\n --markmap-max-width: 9999px;\n --markmap-a-color: #0097e6;\n --markmap-a-hover-color: #00a8ff;\n --markmap-code-bg: #f0f0f0;\n --markmap-code-color: #555;\n --markmap-highlight-bg: #ffeaa7;\n --markmap-table-border: 1px solid currentColor;\n --markmap-font: 300 16px/20px sans-serif;\n --markmap-circle-open-bg: #fff;\n --markmap-text-color: #333;\n\n font: var(--markmap-font);\n color: var(--markmap-text-color);\n}\n\n .markmap-link {\n fill: none;\n }\n\n .markmap-node > circle {\n cursor: pointer;\n }\n\n .markmap-foreign {\n display: inline-block;\n }\n\n .markmap-foreign p {\n margin: 0;\n }\n\n .markmap-foreign a {\n color: var(--markmap-a-color);\n }\n\n .markmap-foreign a:hover {\n color: var(--markmap-a-hover-color);\n }\n\n .markmap-foreign code {\n padding: 0.25em;\n font-size: calc(1em - 2px);\n color: var(--markmap-code-color);\n background-color: var(--markmap-code-bg);\n border-radius: 2px;\n }\n\n .markmap-foreign pre {\n margin: 0;\n }\n\n .markmap-foreign pre > code {\n display: block;\n }\n\n .markmap-foreign del {\n text-decoration: line-through;\n }\n\n .markmap-foreign em {\n font-style: italic;\n }\n\n .markmap-foreign strong {\n font-weight: bold;\n }\n\n .markmap-foreign mark {\n background: var(--markmap-highlight-bg);\n }\n\n .markmap-foreign table,\n .markmap-foreign th,\n .markmap-foreign td {\n border-collapse: collapse;\n border: var(--markmap-table-border);\n }\n\n .markmap-foreign img {\n display: inline-block;\n }\n\n .markmap-foreign svg {\n fill: currentColor;\n }\n\n .markmap-foreign > div {\n width: var(--markmap-max-width);\n text-align: left;\n }\n\n .markmap-foreign > div > div {\n display: inline-block;\n }\n\n.markmap-dark .markmap {\n --markmap-code-bg: #1a1b26;\n --markmap-code-color: #ddd;\n --markmap-circle-open-bg: #444;\n --markmap-text-color: #eee;\n}\n";
689
946
  const globalCSS = css;
690
947
  const linkShape = d32.linkHorizontal();
@@ -1179,11 +1436,14 @@
1179
1436
  }
1180
1437
  }
1181
1438
  exports.Markmap = Markmap;
1439
+ exports.childSelector = childSelector;
1182
1440
  exports.defaultColorFn = defaultColorFn;
1183
1441
  exports.defaultOptions = defaultOptions;
1184
1442
  exports.deriveOptions = deriveOptions;
1185
1443
  exports.globalCSS = globalCSS;
1186
1444
  exports.isMacintosh = isMacintosh;
1445
+ exports.loadCSS = loadCSS;
1446
+ exports.loadJS = loadJS;
1187
1447
  exports.refreshHook = refreshHook;
1188
1448
  exports.simpleHash = simpleHash;
1189
1449
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { loadJS, loadCSS } from 'markmap-common';
1
2
  export * from './types';
2
3
  export * from './constants';
3
4
  export * from './util';