markmap-view 0.15.9-alpha.5 → 0.16.0
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/browser/index.js +14 -6
- package/dist/index.js +68 -60
- package/dist/types.d.ts +8 -0
- package/dist/view.d.ts +5 -9
- package/package.json +5 -4
package/dist/browser/index.js
CHANGED
|
@@ -1549,18 +1549,26 @@
|
|
|
1549
1549
|
).scale(scale);
|
|
1550
1550
|
return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop);
|
|
1551
1551
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
*/
|
|
1555
|
-
async ensureView(node, padding) {
|
|
1556
|
-
let itemData;
|
|
1552
|
+
findElement(node) {
|
|
1553
|
+
let result;
|
|
1557
1554
|
this.g.selectAll(
|
|
1558
1555
|
childSelector("g")
|
|
1559
1556
|
).each(function walk(d) {
|
|
1560
1557
|
if (d.data === node) {
|
|
1561
|
-
|
|
1558
|
+
result = {
|
|
1559
|
+
data: d,
|
|
1560
|
+
g: this
|
|
1561
|
+
};
|
|
1562
1562
|
}
|
|
1563
1563
|
});
|
|
1564
|
+
return result;
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Pan the content to make the provided node visible in the viewport.
|
|
1568
|
+
*/
|
|
1569
|
+
async ensureView(node, padding) {
|
|
1570
|
+
var _a;
|
|
1571
|
+
const itemData = (_a = this.findElement(node)) == null ? void 0 : _a.data;
|
|
1564
1572
|
if (!itemData)
|
|
1565
1573
|
return;
|
|
1566
1574
|
const svgNode = this.svg.node();
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Hook as st, getId as at, debounce as lt, addClass as ct, walkTree as T, childSelector as
|
|
2
|
-
import { loadCSS as
|
|
1
|
+
import { Hook as st, getId as at, debounce as lt, addClass as ct, walkTree as T, childSelector as C, noop as M } from "markmap-common";
|
|
2
|
+
import { loadCSS as Ce, loadJS as we } from "markmap-common";
|
|
3
3
|
import { scaleOrdinal as V, schemeCategory10 as ht, zoomTransform as A, select as dt, zoom as ut, linkHorizontal as pt, min as H, max as L, zoomIdentity as ft, minIndex as mt } from "d3";
|
|
4
4
|
const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), gt = V(ht), P = {
|
|
5
5
|
autoFit: !1,
|
|
@@ -77,7 +77,7 @@ const zt = {
|
|
|
77
77
|
function I(e, t) {
|
|
78
78
|
Array.isArray(t) || (t = [t]), t = t.filter(Boolean), t.length && e.append(...t);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function Et(e, t, n) {
|
|
81
81
|
for (const i in t)
|
|
82
82
|
if (!(i === "key" || i === "children" || i === "ref"))
|
|
83
83
|
if (i === "dangerouslySetInnerHTML")
|
|
@@ -88,12 +88,12 @@ function Ct(e, t, n) {
|
|
|
88
88
|
} else
|
|
89
89
|
i.startsWith("on") ? e[i.toLowerCase()] = t[i] : wt(e, i, t[i], n.isSvg);
|
|
90
90
|
}
|
|
91
|
-
const
|
|
91
|
+
const Ct = {
|
|
92
92
|
className: "class",
|
|
93
93
|
labelFor: "for"
|
|
94
94
|
};
|
|
95
95
|
function wt(e, t, n, i) {
|
|
96
|
-
if (t =
|
|
96
|
+
if (t = Ct[t] || t, n === !0)
|
|
97
97
|
e.setAttribute(t, "");
|
|
98
98
|
else if (n === !1)
|
|
99
99
|
e.removeAttribute(t);
|
|
@@ -139,7 +139,7 @@ function B(e, t = zt) {
|
|
|
139
139
|
} = e;
|
|
140
140
|
if (!t.isSvg && i === "svg" && (t = Object.assign({}, t, {
|
|
141
141
|
isSvg: !0
|
|
142
|
-
})), t.isSvg ? n = document.createElementNS(xt, i) : n = document.createElement(i),
|
|
142
|
+
})), t.isSvg ? n = document.createElementNS(xt, i) : n = document.createElement(i), Et(n, o, t), o.children) {
|
|
143
143
|
let c = t;
|
|
144
144
|
t.isSvg && i === "foreignObject" && (c = Object.assign({}, c, {
|
|
145
145
|
isSvg: !1
|
|
@@ -488,21 +488,21 @@ function q(e) {
|
|
|
488
488
|
}
|
|
489
489
|
function c(s, l, p) {
|
|
490
490
|
const h = (u, g) => {
|
|
491
|
-
const
|
|
492
|
-
Object.assign(
|
|
491
|
+
const x = new s(u);
|
|
492
|
+
Object.assign(x, {
|
|
493
493
|
parent: g,
|
|
494
494
|
depth: g === null ? 0 : g.depth + 1,
|
|
495
495
|
height: 0,
|
|
496
496
|
length: 1
|
|
497
497
|
});
|
|
498
498
|
const f = p(u) || [];
|
|
499
|
-
return
|
|
500
|
-
(
|
|
501
|
-
height: Math.max(
|
|
502
|
-
length:
|
|
499
|
+
return x.children = f.length === 0 ? null : f.map((y) => h(y, x)), x.children && Object.assign(x, x.children.reduce(
|
|
500
|
+
(y, m) => ({
|
|
501
|
+
height: Math.max(y.height, m.height + 1),
|
|
502
|
+
length: y.length + m.length
|
|
503
503
|
}),
|
|
504
|
-
|
|
505
|
-
)),
|
|
504
|
+
x
|
|
505
|
+
)), x;
|
|
506
506
|
};
|
|
507
507
|
return h(l, null);
|
|
508
508
|
}
|
|
@@ -522,8 +522,8 @@ function q(e) {
|
|
|
522
522
|
},
|
|
523
523
|
dump(s) {
|
|
524
524
|
const l = n("nodeSize"), p = (h) => (u) => {
|
|
525
|
-
const g = h + " ",
|
|
526
|
-
return `{ size: [${m.join(", ")}],${g}x: ${f}, y: ${
|
|
525
|
+
const g = h + " ", x = h + " ", { x: f, y } = u, m = l(u), k = u.children || [], v = k.length === 0 ? " " : `,${g}children: [${x}${k.map(p(x)).join(x)}${g}],${h}`;
|
|
526
|
+
return `{ size: [${m.join(", ")}],${g}x: ${f}, y: ${y}${v}},`;
|
|
527
527
|
};
|
|
528
528
|
return p(`
|
|
529
529
|
`)(s);
|
|
@@ -672,10 +672,10 @@ class et {
|
|
|
672
672
|
document.body.append(l, p);
|
|
673
673
|
const h = a ? `--markmap-max-width: ${a}px` : "";
|
|
674
674
|
let u = 0, g = 0;
|
|
675
|
-
T(t, (f,
|
|
675
|
+
T(t, (f, y, m) => {
|
|
676
676
|
var b, w, z;
|
|
677
|
-
g += 1, f.children = (b = f.children) == null ? void 0 : b.map((
|
|
678
|
-
const
|
|
677
|
+
g += 1, f.children = (b = f.children) == null ? void 0 : b.map((E) => ({ ...E })), n += 1;
|
|
678
|
+
const k = O(
|
|
679
679
|
/* @__PURE__ */ j(
|
|
680
680
|
"div",
|
|
681
681
|
{
|
|
@@ -685,29 +685,29 @@ class et {
|
|
|
685
685
|
}
|
|
686
686
|
)
|
|
687
687
|
);
|
|
688
|
-
l.append(
|
|
688
|
+
l.append(k), f.state = {
|
|
689
689
|
...f.state,
|
|
690
690
|
depth: g,
|
|
691
691
|
id: n,
|
|
692
|
-
el:
|
|
692
|
+
el: k.firstChild
|
|
693
693
|
}, f.state.path = [(w = m == null ? void 0 : m.state) == null ? void 0 : w.path, f.state.id].filter(Boolean).join("."), i(f);
|
|
694
694
|
const v = ((z = f.payload) == null ? void 0 : z.fold) === 2;
|
|
695
|
-
v ? u += 1 : (u || c >= 0 && f.state.depth >= c) && (f.payload = { ...f.payload, fold: 1 }),
|
|
695
|
+
v ? u += 1 : (u || c >= 0 && f.state.depth >= c) && (f.payload = { ...f.payload, fold: 1 }), y(), v && (u -= 1), g -= 1;
|
|
696
696
|
});
|
|
697
|
-
const
|
|
697
|
+
const x = Array.from(l.childNodes).map(
|
|
698
698
|
(f) => f.firstChild
|
|
699
699
|
);
|
|
700
|
-
this._checkImages(l),
|
|
701
|
-
var
|
|
702
|
-
(
|
|
703
|
-
}), T(t, (f,
|
|
700
|
+
this._checkImages(l), x.forEach((f) => {
|
|
701
|
+
var y;
|
|
702
|
+
(y = f.parentNode) == null || y.append(f.cloneNode(!0));
|
|
703
|
+
}), T(t, (f, y, m) => {
|
|
704
704
|
var b;
|
|
705
|
-
const
|
|
706
|
-
f.content =
|
|
705
|
+
const k = f.state, v = k.el.getBoundingClientRect();
|
|
706
|
+
f.content = k.el.innerHTML, k.size = [
|
|
707
707
|
Math.ceil(v.width) + 1,
|
|
708
708
|
Math.max(Math.ceil(v.height), o)
|
|
709
|
-
],
|
|
710
|
-
f.content,
|
|
709
|
+
], k.key = [(b = m == null ? void 0 : m.state) == null ? void 0 : b.id, k.id].filter(Boolean).join(".") + // FIXME: find a way to check content hash
|
|
710
|
+
f.content, y();
|
|
711
711
|
}), l.remove(), p.remove();
|
|
712
712
|
}
|
|
713
713
|
_checkImages(t) {
|
|
@@ -746,36 +746,36 @@ class et {
|
|
|
746
746
|
return [S, d + (d ? i * 2 : 0) + n];
|
|
747
747
|
}).spacing((r, d) => r.parent === d.parent ? o : o * 2), l = s.hierarchy(this.state.data);
|
|
748
748
|
s(l);
|
|
749
|
-
const p = l.descendants().reverse(), h = l.links(), u = pt(), g = H(p, (r) => r.x - r.xSize / 2),
|
|
749
|
+
const p = l.descendants().reverse(), h = l.links(), u = pt(), g = H(p, (r) => r.x - r.xSize / 2), x = L(p, (r) => r.x + r.xSize / 2), f = H(p, (r) => r.y), y = L(p, (r) => r.y + r.ySize - n);
|
|
750
750
|
Object.assign(this.state, {
|
|
751
751
|
minX: g,
|
|
752
|
-
maxX:
|
|
752
|
+
maxX: x,
|
|
753
753
|
minY: f,
|
|
754
|
-
maxY:
|
|
754
|
+
maxY: y
|
|
755
755
|
}), a && this.fit();
|
|
756
|
-
const m = t && p.find((r) => r.data === t) || l,
|
|
757
|
-
|
|
756
|
+
const m = t && p.find((r) => r.data === t) || l, k = m.data.state.x0 ?? m.x, v = m.data.state.y0 ?? m.y, b = this.g.selectAll(
|
|
757
|
+
C("g")
|
|
758
758
|
).data(p, (r) => r.data.state.key), w = b.enter().append("g").attr("data-depth", (r) => r.data.state.depth).attr("data-path", (r) => r.data.state.path).attr(
|
|
759
759
|
"transform",
|
|
760
|
-
(r) => `translate(${v + m.ySize - r.ySize},${
|
|
760
|
+
(r) => `translate(${v + m.ySize - r.ySize},${k + m.xSize / 2 - r.xSize})`
|
|
761
761
|
), z = this.transition(b.exit());
|
|
762
762
|
z.select("line").attr("x1", (r) => r.ySize - n).attr("x2", (r) => r.ySize - n), z.select("foreignObject").style("opacity", 0), z.attr(
|
|
763
763
|
"transform",
|
|
764
764
|
(r) => `translate(${m.y + m.ySize - r.ySize},${m.x + m.xSize / 2 - r.xSize})`
|
|
765
765
|
).remove();
|
|
766
|
-
const
|
|
766
|
+
const E = b.merge(w).attr(
|
|
767
767
|
"class",
|
|
768
768
|
(r) => {
|
|
769
769
|
var d;
|
|
770
770
|
return ["markmap-node", ((d = r.data.payload) == null ? void 0 : d.fold) && "markmap-fold"].filter(Boolean).join(" ");
|
|
771
771
|
}
|
|
772
772
|
);
|
|
773
|
-
this.transition(
|
|
773
|
+
this.transition(E).attr(
|
|
774
774
|
"transform",
|
|
775
775
|
(r) => `translate(${r.y},${r.x - r.xSize / 2})`
|
|
776
776
|
);
|
|
777
|
-
const nt =
|
|
778
|
-
|
|
777
|
+
const nt = E.selectAll(
|
|
778
|
+
C("line")
|
|
779
779
|
).data(
|
|
780
780
|
(r) => [r],
|
|
781
781
|
(r) => r.data.state.key
|
|
@@ -785,8 +785,8 @@ class et {
|
|
|
785
785
|
(r) => r.remove()
|
|
786
786
|
);
|
|
787
787
|
this.transition(nt).attr("x1", -1).attr("x2", (r) => r.ySize - n + 2).attr("y1", (r) => r.xSize).attr("y2", (r) => r.xSize).attr("stroke", (r) => c(r.data)).attr("stroke-width", W);
|
|
788
|
-
const it =
|
|
789
|
-
|
|
788
|
+
const it = E.selectAll(
|
|
789
|
+
C("circle")
|
|
790
790
|
).data(
|
|
791
791
|
(r) => {
|
|
792
792
|
var d;
|
|
@@ -805,8 +805,8 @@ class et {
|
|
|
805
805
|
return (d = r.data.payload) != null && d.fold && r.data.children ? c(r.data) : "#fff";
|
|
806
806
|
}
|
|
807
807
|
);
|
|
808
|
-
const rt =
|
|
809
|
-
|
|
808
|
+
const rt = E.selectAll(
|
|
809
|
+
C("foreignObject")
|
|
810
810
|
).data(
|
|
811
811
|
(r) => [r],
|
|
812
812
|
(r) => r.data.state.key
|
|
@@ -826,12 +826,12 @@ class et {
|
|
|
826
826
|
).attr("height", (r) => r.xSize);
|
|
827
827
|
this.transition(rt).style("opacity", 1);
|
|
828
828
|
const ot = this.g.selectAll(
|
|
829
|
-
|
|
829
|
+
C("path")
|
|
830
830
|
).data(h, (r) => r.target.data.state.key).join(
|
|
831
831
|
(r) => {
|
|
832
832
|
const d = [
|
|
833
833
|
v + m.ySize - n,
|
|
834
|
-
|
|
834
|
+
k + m.xSize / 2
|
|
835
835
|
];
|
|
836
836
|
return r.insert("path", "g").attr("class", "markmap-link").attr("data-depth", (S) => S.target.data.state.depth).attr("data-path", (S) => S.target.data.state.path).attr("d", u({ source: d, target: d }));
|
|
837
837
|
},
|
|
@@ -875,33 +875,41 @@ class et {
|
|
|
875
875
|
).scale(u);
|
|
876
876
|
return this.transition(this.svg).call(this.zoom.transform, g).end().catch(M);
|
|
877
877
|
}
|
|
878
|
+
findElement(t) {
|
|
879
|
+
let n;
|
|
880
|
+
return this.g.selectAll(
|
|
881
|
+
C("g")
|
|
882
|
+
).each(function(o) {
|
|
883
|
+
o.data === t && (n = {
|
|
884
|
+
data: o,
|
|
885
|
+
g: this
|
|
886
|
+
});
|
|
887
|
+
}), n;
|
|
888
|
+
}
|
|
878
889
|
/**
|
|
879
890
|
* Pan the content to make the provided node visible in the viewport.
|
|
880
891
|
*/
|
|
881
892
|
async ensureView(t, n) {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
).each(function(v) {
|
|
886
|
-
v.data === t && (i = v);
|
|
887
|
-
}), !i)
|
|
893
|
+
var k;
|
|
894
|
+
const i = (k = this.findElement(t)) == null ? void 0 : k.data;
|
|
895
|
+
if (!i)
|
|
888
896
|
return;
|
|
889
897
|
const o = this.svg.node(), { spacingHorizontal: a } = this.options, c = o.getBoundingClientRect(), s = A(o), [l, p] = [
|
|
890
898
|
i.y,
|
|
891
899
|
i.y + i.ySize - a + 2
|
|
892
|
-
].map((
|
|
900
|
+
].map((v) => v * s.k + s.x), [h, u] = [
|
|
893
901
|
i.x - i.xSize / 2,
|
|
894
902
|
i.x + i.xSize / 2
|
|
895
|
-
].map((
|
|
903
|
+
].map((v) => v * s.k + s.y), g = {
|
|
896
904
|
left: 0,
|
|
897
905
|
right: 0,
|
|
898
906
|
top: 0,
|
|
899
907
|
bottom: 0,
|
|
900
908
|
...n
|
|
901
|
-
},
|
|
902
|
-
if (
|
|
903
|
-
const
|
|
904
|
-
return this.transition(this.svg).call(this.zoom.transform,
|
|
909
|
+
}, x = [g.left - l, c.width - g.right - p], f = [g.top - h, c.height - g.bottom - u], y = x[0] * x[1] > 0 ? Y(x, Math.abs) / s.k : 0, m = f[0] * f[1] > 0 ? Y(f, Math.abs) / s.k : 0;
|
|
910
|
+
if (y || m) {
|
|
911
|
+
const v = s.translate(y, m);
|
|
912
|
+
return this.transition(this.svg).call(this.zoom.transform, v).end().catch(M);
|
|
905
913
|
}
|
|
906
914
|
}
|
|
907
915
|
/**
|
|
@@ -931,7 +939,7 @@ export {
|
|
|
931
939
|
Se as deriveOptions,
|
|
932
940
|
be as globalCSS,
|
|
933
941
|
K as isMacintosh,
|
|
934
|
-
|
|
942
|
+
Ce as loadCSS,
|
|
935
943
|
we as loadJS,
|
|
936
944
|
ye as refreshHook
|
|
937
945
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { INode } from 'markmap-common';
|
|
2
|
+
import { FlextreeNode } from 'd3-flextree';
|
|
2
3
|
export interface IMarkmapState {
|
|
3
4
|
id: string;
|
|
4
5
|
data?: INode;
|
|
@@ -18,3 +19,10 @@ export interface IMarkmapJSONOptions {
|
|
|
18
19
|
zoom?: boolean;
|
|
19
20
|
pan?: boolean;
|
|
20
21
|
}
|
|
22
|
+
export interface IPadding {
|
|
23
|
+
left: number;
|
|
24
|
+
right: number;
|
|
25
|
+
top: number;
|
|
26
|
+
bottom: number;
|
|
27
|
+
}
|
|
28
|
+
export type ID3SVGElement = d3.Selection<SVGElement, FlextreeNode<INode>, HTMLElement, FlextreeNode<INode>>;
|
package/dist/view.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import type * as d3 from 'd3';
|
|
2
2
|
import { FlextreeNode } from 'd3-flextree';
|
|
3
3
|
import { Hook, IMarkmapOptions, INode, IPureNode } from 'markmap-common';
|
|
4
|
-
import { IMarkmapState } from './types';
|
|
4
|
+
import { IMarkmapState, IPadding, ID3SVGElement } from './types';
|
|
5
5
|
export declare const globalCSS: string;
|
|
6
|
-
interface IPadding {
|
|
7
|
-
left: number;
|
|
8
|
-
right: number;
|
|
9
|
-
top: number;
|
|
10
|
-
bottom: number;
|
|
11
|
-
}
|
|
12
|
-
type ID3SVGElement = d3.Selection<SVGElement, FlextreeNode<INode>, HTMLElement, FlextreeNode<INode>>;
|
|
13
6
|
/**
|
|
14
7
|
* A global hook to refresh all markmaps when called.
|
|
15
8
|
*/
|
|
@@ -42,6 +35,10 @@ export declare class Markmap {
|
|
|
42
35
|
* Fit the content to the viewport.
|
|
43
36
|
*/
|
|
44
37
|
fit(): Promise<void>;
|
|
38
|
+
findElement(node: INode): {
|
|
39
|
+
data: FlextreeNode<INode>;
|
|
40
|
+
g: SVGGElement;
|
|
41
|
+
} | undefined;
|
|
45
42
|
/**
|
|
46
43
|
* Pan the content to make the provided node visible in the viewport.
|
|
47
44
|
*/
|
|
@@ -53,4 +50,3 @@ export declare class Markmap {
|
|
|
53
50
|
destroy(): void;
|
|
54
51
|
static create(svg: string | SVGElement | ID3SVGElement, opts?: Partial<IMarkmapOptions>, data?: IPureNode | null): Markmap;
|
|
55
52
|
}
|
|
56
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-view",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "View markmaps in browser",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"clean": "del-cli dist",
|
|
23
23
|
"build:types": "tsc",
|
|
24
|
-
"build:js": "vite build && TARGET=es vite build
|
|
24
|
+
"build:js": "vite build && TARGET=es vite build",
|
|
25
|
+
"build": "run-s clean build:*"
|
|
25
26
|
},
|
|
26
27
|
"bugs": {
|
|
27
28
|
"url": "https://github.com/markmap/markmap/issues"
|
|
@@ -44,10 +45,10 @@
|
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/d3-flextree": "^2.1.1",
|
|
47
|
-
"markmap-common": "0.
|
|
48
|
+
"markmap-common": "0.16.0"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"markmap-common": "*"
|
|
51
52
|
},
|
|
52
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "caf3f840ad39c240ba522bfea83c57de62c6cac4"
|
|
53
54
|
}
|