@billtaofbj/mindmap 1.0.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.
@@ -0,0 +1,106 @@
1
+ import { Dt as e, i as t } from "./utils-DjW7eJ1w.mjs";
2
+ //#region ../../node_modules/.pnpm/simple-mind-map@0.14.0-fix.2/node_modules/simple-mind-map/src/plugins/KeyboardNavigation.js
3
+ var n = class {
4
+ constructor(e) {
5
+ this.opt = e, this.mindMap = e.mindMap, this.addShortcut();
6
+ }
7
+ addShortcut() {
8
+ this.onLeftKeyUp = this.onLeftKeyUp.bind(this), this.onUpKeyUp = this.onUpKeyUp.bind(this), this.onRightKeyUp = this.onRightKeyUp.bind(this), this.onDownKeyUp = this.onDownKeyUp.bind(this), this.mindMap.keyCommand.addShortcut(e.KEY_DIR.LEFT, this.onLeftKeyUp), this.mindMap.keyCommand.addShortcut(e.KEY_DIR.UP, this.onUpKeyUp), this.mindMap.keyCommand.addShortcut(e.KEY_DIR.RIGHT, this.onRightKeyUp), this.mindMap.keyCommand.addShortcut(e.KEY_DIR.DOWN, this.onDownKeyUp);
9
+ }
10
+ removeShortcut() {
11
+ this.mindMap.keyCommand.removeShortcut(e.KEY_DIR.LEFT, this.onLeftKeyUp), this.mindMap.keyCommand.removeShortcut(e.KEY_DIR.UP, this.onUpKeyUp), this.mindMap.keyCommand.removeShortcut(e.KEY_DIR.RIGHT, this.onRightKeyUp), this.mindMap.keyCommand.removeShortcut(e.KEY_DIR.DOWN, this.onDownKeyUp);
12
+ }
13
+ onLeftKeyUp() {
14
+ this.onKeyup(e.KEY_DIR.LEFT);
15
+ }
16
+ onUpKeyUp() {
17
+ this.onKeyup(e.KEY_DIR.UP);
18
+ }
19
+ onRightKeyUp() {
20
+ this.onKeyup(e.KEY_DIR.RIGHT);
21
+ }
22
+ onDownKeyUp() {
23
+ this.onKeyup(e.KEY_DIR.DOWN);
24
+ }
25
+ onKeyup(e) {
26
+ if (this.mindMap.renderer.activeNodeList.length > 0) this.focus(e);
27
+ else {
28
+ let e = this.mindMap.renderer.root;
29
+ this.mindMap.execCommand("GO_TARGET_NODE", e);
30
+ }
31
+ }
32
+ focus(e) {
33
+ let t = this.mindMap.renderer.activeNodeList[0], n = this.getNodeRect(t), r = null, i = Infinity, a = (e, t) => {
34
+ let a = this.getDistance(n, e);
35
+ a < i && (r = t, i = a);
36
+ };
37
+ this.getFocusNodeByShadowAlgorithm({
38
+ currentActiveNode: t,
39
+ currentActiveNodeRect: n,
40
+ dir: e,
41
+ checkNodeDis: a
42
+ }), r || this.getFocusNodeByAreaAlgorithm({
43
+ currentActiveNode: t,
44
+ currentActiveNodeRect: n,
45
+ dir: e,
46
+ checkNodeDis: a
47
+ }), r || this.getFocusNodeBySimpleAlgorithm({
48
+ currentActiveNode: t,
49
+ currentActiveNodeRect: n,
50
+ dir: e,
51
+ checkNodeDis: a
52
+ }), r && this.mindMap.execCommand("GO_TARGET_NODE", r);
53
+ }
54
+ getFocusNodeBySimpleAlgorithm({ currentActiveNode: n, currentActiveNodeRect: r, dir: i, checkNodeDis: a }) {
55
+ t(this.mindMap.renderer.root, (t) => {
56
+ if (t.uid === n.uid) return;
57
+ let o = this.getNodeRect(t), { left: s, top: c, right: l, bottom: u } = o, d = !1;
58
+ i === e.KEY_DIR.LEFT ? d = l <= r.left : i === e.KEY_DIR.RIGHT ? d = s >= r.right : i === e.KEY_DIR.UP ? d = u <= r.top : i === e.KEY_DIR.DOWN && (d = c >= r.bottom), d && a(o, t);
59
+ });
60
+ }
61
+ getFocusNodeByShadowAlgorithm({ currentActiveNode: n, currentActiveNodeRect: r, dir: i, checkNodeDis: a }) {
62
+ t(this.mindMap.renderer.root, (t) => {
63
+ if (t.uid === n.uid) return;
64
+ let o = this.getNodeRect(t), { left: s, top: c, right: l, bottom: u } = o, d = !1;
65
+ i === e.KEY_DIR.LEFT ? d = s < r.left && c < r.bottom && u > r.top : i === e.KEY_DIR.RIGHT ? d = l > r.right && c < r.bottom && u > r.top : i === e.KEY_DIR.UP ? d = c < r.top && s < r.right && l > r.left : i === e.KEY_DIR.DOWN && (d = u > r.bottom && s < r.right && l > r.left), d && a(o, t);
66
+ });
67
+ }
68
+ getFocusNodeByAreaAlgorithm({ currentActiveNode: n, currentActiveNodeRect: r, dir: i, checkNodeDis: a }) {
69
+ let o = (r.right + r.left) / 2, s = (r.bottom + r.top) / 2;
70
+ t(this.mindMap.renderer.root, (t) => {
71
+ if (t.uid === n.uid) return;
72
+ let r = this.getNodeRect(t), { left: c, top: l, right: u, bottom: d } = r, f = (u + c) / 2, p = (d + l) / 2, m = f - o, h = p - s;
73
+ if (m === 0 && h === 0) return;
74
+ let g = !1;
75
+ i === e.KEY_DIR.LEFT ? g = m <= 0 && m <= h && m <= -h : i === e.KEY_DIR.RIGHT ? g = m > 0 && m >= -h && m >= h : i === e.KEY_DIR.UP ? g = h <= 0 && h < m && h < -m : i === e.KEY_DIR.DOWN && (g = h > 0 && -h < m && h > m), g && a(r, t);
76
+ });
77
+ }
78
+ getNodeRect(e) {
79
+ let { scaleX: t, scaleY: n, translateX: r, translateY: i } = this.mindMap.draw.transform(), { left: a, top: o, width: s, height: c } = e;
80
+ return {
81
+ right: (a + s) * t + r,
82
+ bottom: (o + c) * n + i,
83
+ left: a * t + r,
84
+ top: o * n + i
85
+ };
86
+ }
87
+ getDistance(e, t) {
88
+ let n = this.getCenter(e), r = this.getCenter(t);
89
+ return Math.sqrt((n.x - r.x) ** 2 + (n.y - r.y) ** 2);
90
+ }
91
+ getCenter({ left: e, right: t, top: n, bottom: r }) {
92
+ return {
93
+ x: (e + t) / 2,
94
+ y: (n + r) / 2
95
+ };
96
+ }
97
+ beforePluginRemove() {
98
+ this.removeShortcut();
99
+ }
100
+ beforePluginDestroy() {
101
+ this.removeShortcut();
102
+ }
103
+ };
104
+ n.instanceName = "keyboardNavigation";
105
+ //#endregion
106
+ export { n as default };