@lincle/react-shared 0.0.1 → 0.4.0-next.2
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/LICENSE.md +165 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +19 -0
- package/dist/utils/EdgeSubscriber.d.ts +15 -0
- package/dist/utils/EdgeSubscriber.js +52 -0
- package/dist/utils/GraphContext.d.ts +4 -0
- package/dist/utils/GraphContext.js +6 -0
- package/dist/utils/GridContext.d.ts +3 -0
- package/dist/utils/GridContext.js +10 -0
- package/dist/utils/NodePositions.d.ts +31 -0
- package/dist/utils/NodePositions.js +226 -0
- package/dist/utils/Path/generateOrigins.d.ts +4 -0
- package/dist/utils/Path/generateOrigins.js +18 -0
- package/dist/utils/Path/lines/generateCurve.d.ts +17 -0
- package/dist/utils/Path/lines/generateCurve.js +50 -0
- package/dist/utils/Path/lines/generateDirect.d.ts +16 -0
- package/dist/utils/Path/lines/generateDirect.js +32 -0
- package/dist/utils/Path/lines/generatePoints.d.ts +15 -0
- package/dist/utils/Path/lines/generatePoints.js +111 -0
- package/dist/utils/Path/lines/generateStep.d.ts +17 -0
- package/dist/utils/Path/lines/generateStep.js +63 -0
- package/dist/utils/Path/lines/index.d.ts +4 -0
- package/dist/utils/Path/lines/index.js +12 -0
- package/dist/utils/Path/lines/types.d.ts +34 -0
- package/dist/utils/Path/lines/types.js +2 -0
- package/dist/utils/defaultSettings.d.ts +11 -0
- package/dist/utils/defaultSettings.js +14 -0
- package/dist/utils/round.d.ts +2 -0
- package/dist/utils/round.js +9 -0
- package/package.json +29 -27
package/LICENSE.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type EdgeSubscriber from './utils/EdgeSubscriber';
|
|
2
|
+
import type NodePositions from './utils/NodePositions';
|
|
3
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
4
|
+
export type Line = 'curve' | 'direct' | 'step';
|
|
5
|
+
export type Shape = 'oval' | 'rectangle';
|
|
6
|
+
export type EdgeNodeProps = {
|
|
7
|
+
height: number;
|
|
8
|
+
id: number | string;
|
|
9
|
+
shape: Shape;
|
|
10
|
+
width: number;
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
};
|
|
14
|
+
declare const defaultSettings: {
|
|
15
|
+
edgeFrequency: number;
|
|
16
|
+
grid: [number, number];
|
|
17
|
+
height: number;
|
|
18
|
+
line: Line;
|
|
19
|
+
nodeFrequency: number;
|
|
20
|
+
shape: Shape;
|
|
21
|
+
width: number;
|
|
22
|
+
};
|
|
23
|
+
export type Size = {
|
|
24
|
+
bottom: number;
|
|
25
|
+
height: number;
|
|
26
|
+
left: number;
|
|
27
|
+
right: number;
|
|
28
|
+
top: number;
|
|
29
|
+
width: number;
|
|
30
|
+
};
|
|
31
|
+
export type NodesDimensions = {
|
|
32
|
+
[key: string]: Dimensions;
|
|
33
|
+
};
|
|
34
|
+
export type Dimensions = {
|
|
35
|
+
height: number;
|
|
36
|
+
id: number | string;
|
|
37
|
+
shape: Shape;
|
|
38
|
+
width: number;
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
};
|
|
42
|
+
export type GraphContextProps = {
|
|
43
|
+
defaultSettings: Omit<typeof defaultSettings, 'grid'>;
|
|
44
|
+
diagramId: number | string;
|
|
45
|
+
edgeSubscriber: EdgeSubscriber;
|
|
46
|
+
nodePositions: NodePositions;
|
|
47
|
+
};
|
|
48
|
+
export type GridType = [
|
|
49
|
+
number,
|
|
50
|
+
number
|
|
51
|
+
];
|
|
52
|
+
export type GridContextProps = GridType;
|
|
53
|
+
export { defaultSettings };
|
|
54
|
+
export type EdgeProps = {
|
|
55
|
+
children?: ReactNode;
|
|
56
|
+
dash?: Boolean;
|
|
57
|
+
id: number | string;
|
|
58
|
+
line?: Line;
|
|
59
|
+
markerEnd?: string;
|
|
60
|
+
markerStart?: string;
|
|
61
|
+
path?: (source?: EdgeNodeProps, target?: EdgeNodeProps, children?: ReactNode) => ReactElement;
|
|
62
|
+
sourceId: number | string;
|
|
63
|
+
targetId: number | string;
|
|
64
|
+
};
|
|
65
|
+
export type EdgesProps = {
|
|
66
|
+
children: Array<ReactElement<EdgeProps>> | ReactElement<EdgeProps>;
|
|
67
|
+
dash?: Boolean;
|
|
68
|
+
};
|
|
69
|
+
export type PathProps = {
|
|
70
|
+
children?: ReactNode;
|
|
71
|
+
diagramId?: number | string;
|
|
72
|
+
id: number | string;
|
|
73
|
+
line?: Line;
|
|
74
|
+
markerEnd?: string;
|
|
75
|
+
markerStart?: string;
|
|
76
|
+
source?: EdgeNodeProps;
|
|
77
|
+
target?: EdgeNodeProps;
|
|
78
|
+
};
|
|
79
|
+
export type NodeProps = {
|
|
80
|
+
children?: ReactElement | ReactElement[];
|
|
81
|
+
height?: number;
|
|
82
|
+
id: number | string;
|
|
83
|
+
ref?: React.MutableRefObject<HTMLDivElement | null> | ((instance: HTMLDivElement | null) => void) | null;
|
|
84
|
+
shape?: Shape;
|
|
85
|
+
track?: boolean;
|
|
86
|
+
width?: number;
|
|
87
|
+
x?: number;
|
|
88
|
+
y?: number;
|
|
89
|
+
};
|
|
90
|
+
export type NodesProps = {
|
|
91
|
+
children: Array<ReactElement<NodeProps>> | ReactElement<NodeProps>;
|
|
92
|
+
};
|
|
93
|
+
export type GridProps = {
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
scale?: number;
|
|
96
|
+
xOffset?: number;
|
|
97
|
+
yOffset?: number;
|
|
98
|
+
};
|
|
99
|
+
export type GraphProps = {
|
|
100
|
+
children?: ReactNode | ReactNode[];
|
|
101
|
+
edgeFrequency?: number;
|
|
102
|
+
grid?: GridType | false;
|
|
103
|
+
id: number | string;
|
|
104
|
+
line?: Line;
|
|
105
|
+
nodeFrequency?: number;
|
|
106
|
+
nodeHeight?: number;
|
|
107
|
+
nodeWidth?: number;
|
|
108
|
+
shape?: Shape;
|
|
109
|
+
};
|
|
110
|
+
export type GraphContextsProps = Omit<GraphProps, 'children'> & {
|
|
111
|
+
children: ReactElement<GraphProps> | ReactNode | ReactNode[];
|
|
112
|
+
};
|
|
113
|
+
export { default as EdgeSubscriber } from './utils/EdgeSubscriber';
|
|
114
|
+
export { default as GraphContext } from './utils/GraphContext';
|
|
115
|
+
export { default as GridContext } from './utils/GridContext';
|
|
116
|
+
export { default as NodePositions } from './utils/NodePositions';
|
|
117
|
+
export { default as generateOrigins } from './utils/Path/generateOrigins';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateOrigins = exports.NodePositions = exports.GridContext = exports.GraphContext = exports.EdgeSubscriber = exports.defaultSettings = void 0;
|
|
7
|
+
const defaultSettings_1 = __importDefault(require("./utils/defaultSettings"));
|
|
8
|
+
const defaultSettings = defaultSettings_1.default;
|
|
9
|
+
exports.defaultSettings = defaultSettings;
|
|
10
|
+
var EdgeSubscriber_1 = require("./utils/EdgeSubscriber");
|
|
11
|
+
Object.defineProperty(exports, "EdgeSubscriber", { enumerable: true, get: function () { return __importDefault(EdgeSubscriber_1).default; } });
|
|
12
|
+
var GraphContext_1 = require("./utils/GraphContext");
|
|
13
|
+
Object.defineProperty(exports, "GraphContext", { enumerable: true, get: function () { return __importDefault(GraphContext_1).default; } });
|
|
14
|
+
var GridContext_1 = require("./utils/GridContext");
|
|
15
|
+
Object.defineProperty(exports, "GridContext", { enumerable: true, get: function () { return __importDefault(GridContext_1).default; } });
|
|
16
|
+
var NodePositions_1 = require("./utils/NodePositions");
|
|
17
|
+
Object.defineProperty(exports, "NodePositions", { enumerable: true, get: function () { return __importDefault(NodePositions_1).default; } });
|
|
18
|
+
var generateOrigins_1 = require("./utils/Path/generateOrigins");
|
|
19
|
+
Object.defineProperty(exports, "generateOrigins", { enumerable: true, get: function () { return __importDefault(generateOrigins_1).default; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type EdgeNodeProps } from '..';
|
|
2
|
+
declare class EdgeSubscriber {
|
|
3
|
+
private frequency;
|
|
4
|
+
constructor(frequency?: number);
|
|
5
|
+
getFrequency: () => number;
|
|
6
|
+
setFrequency: (frequency: number) => number;
|
|
7
|
+
private nodes;
|
|
8
|
+
private propsCache;
|
|
9
|
+
register: <T>(edgeId: number | string, nodeId: number | string, updateFn: (update: T) => void) => EdgeNodeProps;
|
|
10
|
+
unregister: (edgeId: number | string, nodeId: number | string) => void;
|
|
11
|
+
private readonly updateEdges;
|
|
12
|
+
private throttleUpdates;
|
|
13
|
+
update: (props: EdgeNodeProps) => void;
|
|
14
|
+
}
|
|
15
|
+
export default EdgeSubscriber;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const defaultSettings_1 = __importDefault(require("./defaultSettings"));
|
|
7
|
+
const lodash_throttle_1 = __importDefault(require("lodash.throttle"));
|
|
8
|
+
const FREQUENCY = defaultSettings_1.default.edgeFrequency;
|
|
9
|
+
class EdgeSubscriber {
|
|
10
|
+
constructor(frequency = FREQUENCY) {
|
|
11
|
+
this.getFrequency = () => {
|
|
12
|
+
return this.frequency;
|
|
13
|
+
};
|
|
14
|
+
this.setFrequency = (frequency) => {
|
|
15
|
+
this.frequency = frequency;
|
|
16
|
+
return this.frequency;
|
|
17
|
+
};
|
|
18
|
+
this.nodes = {};
|
|
19
|
+
this.propsCache = {};
|
|
20
|
+
this.register = (edgeId, nodeId, updateFn) => {
|
|
21
|
+
if (!this.nodes[nodeId]) {
|
|
22
|
+
this.nodes[nodeId] = {};
|
|
23
|
+
}
|
|
24
|
+
this.nodes[nodeId][edgeId] = updateFn;
|
|
25
|
+
return this.propsCache[nodeId];
|
|
26
|
+
};
|
|
27
|
+
this.unregister = (edgeId, nodeId) => {
|
|
28
|
+
delete this.nodes[nodeId][edgeId];
|
|
29
|
+
delete this.throttleUpdates[nodeId];
|
|
30
|
+
};
|
|
31
|
+
this.updateEdges = (props) => {
|
|
32
|
+
if (this.nodes[props.id]) {
|
|
33
|
+
for (const [_edgeId, update] of Object.entries(this.nodes[props.id])) {
|
|
34
|
+
update(props);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.propsCache[props.id] = props;
|
|
38
|
+
};
|
|
39
|
+
this.throttleUpdates = {};
|
|
40
|
+
this.update = (props) => {
|
|
41
|
+
const { id } = props;
|
|
42
|
+
if (!this.throttleUpdates[id]) {
|
|
43
|
+
this.throttleUpdates[id] = (0, lodash_throttle_1.default)(this.updateEdges, this.frequency, {
|
|
44
|
+
trailing: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.throttleUpdates[id](props);
|
|
48
|
+
};
|
|
49
|
+
this.frequency = frequency;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = EdgeSubscriber;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const defaultSettings_1 = __importDefault(require("./defaultSettings"));
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const GridContext = (0, react_1.createContext)(defaultSettings_1.default.grid);
|
|
9
|
+
GridContext.displayName = 'LincleInteractiveGridContext';
|
|
10
|
+
exports.default = GridContext;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Dimensions, type NodesDimensions, type Size } from '..';
|
|
2
|
+
declare class NodePositions {
|
|
3
|
+
private frequency;
|
|
4
|
+
private subscriptions;
|
|
5
|
+
getFrequency: () => number;
|
|
6
|
+
setFrequency: (frequency: number) => number;
|
|
7
|
+
private nodes;
|
|
8
|
+
constructor(frequency?: number);
|
|
9
|
+
subscribe: (id: string, callback: (size?: Size, nodes?: NodesDimensions) => void) => void;
|
|
10
|
+
unsubscribe: (id: string) => void;
|
|
11
|
+
register: (node: Dimensions, { maxWait }?: {
|
|
12
|
+
maxWait?: number | undefined;
|
|
13
|
+
}) => void;
|
|
14
|
+
unregister: (id: number | string) => void;
|
|
15
|
+
private top;
|
|
16
|
+
private readonly getTop;
|
|
17
|
+
private right;
|
|
18
|
+
private readonly getRight;
|
|
19
|
+
private bottom;
|
|
20
|
+
private readonly getBottom;
|
|
21
|
+
private left;
|
|
22
|
+
private readonly getLeft;
|
|
23
|
+
private readonly getSize;
|
|
24
|
+
private readonly privateUpdate;
|
|
25
|
+
private readonly notify;
|
|
26
|
+
private debounceUpdates;
|
|
27
|
+
update: (node: Dimensions) => void;
|
|
28
|
+
match: (x: number, y: number) => Promise<number | string | undefined>;
|
|
29
|
+
size: () => Size;
|
|
30
|
+
}
|
|
31
|
+
export default NodePositions;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const defaultSettings_1 = __importDefault(require("./defaultSettings"));
|
|
16
|
+
const lodash_debounce_1 = __importDefault(require("lodash.debounce"));
|
|
17
|
+
const FREQUENCY = defaultSettings_1.default.nodeFrequency;
|
|
18
|
+
const MAX_WAIT = defaultSettings_1.default.nodeFrequency;
|
|
19
|
+
class NodePositions {
|
|
20
|
+
constructor(frequency = FREQUENCY) {
|
|
21
|
+
this.subscriptions = {};
|
|
22
|
+
this.getFrequency = () => {
|
|
23
|
+
return this.frequency;
|
|
24
|
+
};
|
|
25
|
+
this.setFrequency = (frequency) => {
|
|
26
|
+
this.frequency = frequency;
|
|
27
|
+
return this.frequency;
|
|
28
|
+
};
|
|
29
|
+
this.nodes = {};
|
|
30
|
+
this.subscribe = (id, callback) => {
|
|
31
|
+
this.subscriptions[id] = callback;
|
|
32
|
+
callback(this.size(), this.nodes);
|
|
33
|
+
};
|
|
34
|
+
this.unsubscribe = (id) => {
|
|
35
|
+
delete this.subscriptions[id];
|
|
36
|
+
};
|
|
37
|
+
this.register = (node, { maxWait = MAX_WAIT } = {}) => {
|
|
38
|
+
this.nodes[node.id] = node;
|
|
39
|
+
this.debounceUpdates[node.id] = (0, lodash_debounce_1.default)(this.privateUpdate, this.frequency, {
|
|
40
|
+
maxWait,
|
|
41
|
+
trailing: true
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
this.unregister = (id) => {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
delete this.nodes[id];
|
|
47
|
+
delete this.debounceUpdates[id];
|
|
48
|
+
if (((_a = this.top) === null || _a === void 0 ? void 0 : _a.id) === id) {
|
|
49
|
+
this.top = undefined;
|
|
50
|
+
for (const nodeId of Object.keys(this.nodes)) {
|
|
51
|
+
if (!this.top ||
|
|
52
|
+
this.nodes[nodeId].y < this.top.y) {
|
|
53
|
+
this.top = this.nodes[nodeId];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (((_b = this.right) === null || _b === void 0 ? void 0 : _b.id) === id) {
|
|
58
|
+
this.right = undefined;
|
|
59
|
+
for (const nodeId of Object.keys(this.nodes)) {
|
|
60
|
+
if (!this.right ||
|
|
61
|
+
this.nodes[nodeId].x + this.nodes[nodeId].height > this.right.x + this.right.width) {
|
|
62
|
+
this.right = this.nodes[nodeId];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (((_c = this.bottom) === null || _c === void 0 ? void 0 : _c.id) === id) {
|
|
67
|
+
this.bottom = undefined;
|
|
68
|
+
for (const nodeId of Object.keys(this.nodes)) {
|
|
69
|
+
if (!this.bottom ||
|
|
70
|
+
this.nodes[nodeId].y + this.nodes[nodeId].height > this.bottom.y + this.bottom.height) {
|
|
71
|
+
this.bottom = this.nodes[nodeId];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (((_d = this.left) === null || _d === void 0 ? void 0 : _d.id) === id) {
|
|
76
|
+
this.left = undefined;
|
|
77
|
+
for (const nodeId of Object.keys(this.nodes)) {
|
|
78
|
+
if (!this.left ||
|
|
79
|
+
this.nodes[nodeId].x < this.left.x) {
|
|
80
|
+
this.left = this.nodes[nodeId];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.notify();
|
|
85
|
+
};
|
|
86
|
+
this.getTop = (node) => {
|
|
87
|
+
if (this.top &&
|
|
88
|
+
this.top.id === node.id) {
|
|
89
|
+
if (node.y > this.top.y) {
|
|
90
|
+
this.top = node;
|
|
91
|
+
for (const id of Object.keys(this.nodes)) {
|
|
92
|
+
if (this.top && this.nodes[id].y < this.top.y) {
|
|
93
|
+
this.top = this.nodes[id];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.top = node;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (!this.top ||
|
|
102
|
+
node.y < this.top.y) {
|
|
103
|
+
this.top = node;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
this.getRight = (node) => {
|
|
107
|
+
const nodeX = node.x + node.width;
|
|
108
|
+
const rightNodeX = this.right ?
|
|
109
|
+
this.right.x + this.right.width :
|
|
110
|
+
undefined;
|
|
111
|
+
if (this.right &&
|
|
112
|
+
this.right.id === node.id) {
|
|
113
|
+
if (!rightNodeX ||
|
|
114
|
+
nodeX < rightNodeX) {
|
|
115
|
+
this.right = node;
|
|
116
|
+
for (const id of Object.keys(this.nodes)) {
|
|
117
|
+
if (this.nodes[id].x + this.nodes[id].width > this.right.x + this.right.width) {
|
|
118
|
+
this.right = this.nodes[id];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.right = node;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (!this.right ||
|
|
127
|
+
rightNodeX &&
|
|
128
|
+
nodeX > rightNodeX) {
|
|
129
|
+
this.right = node;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
this.getBottom = (node) => {
|
|
133
|
+
const nodeY = node.y + node.height;
|
|
134
|
+
const bottomNodeY = this.bottom ?
|
|
135
|
+
this.bottom.y + this.bottom.height :
|
|
136
|
+
undefined;
|
|
137
|
+
if (this.bottom &&
|
|
138
|
+
this.bottom.id === node.id) {
|
|
139
|
+
if (!bottomNodeY ||
|
|
140
|
+
nodeY < bottomNodeY) {
|
|
141
|
+
this.bottom = node;
|
|
142
|
+
for (const id of Object.keys(this.nodes)) {
|
|
143
|
+
if (this.nodes[id].y + this.nodes[id].height > this.bottom.y + this.bottom.height) {
|
|
144
|
+
this.bottom = this.nodes[id];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.bottom = node;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (!this.bottom ||
|
|
153
|
+
bottomNodeY &&
|
|
154
|
+
nodeY > bottomNodeY) {
|
|
155
|
+
this.bottom = node;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
this.getLeft = (node) => {
|
|
159
|
+
if (this.left &&
|
|
160
|
+
this.left.id === node.id) {
|
|
161
|
+
if (node.x > this.left.x) {
|
|
162
|
+
this.left = node;
|
|
163
|
+
for (const id of Object.keys(this.nodes)) {
|
|
164
|
+
if (this.nodes[id].x < this.left.x) {
|
|
165
|
+
this.left = this.nodes[id];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.left = node;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (!this.left ||
|
|
174
|
+
node.x < this.left.x) {
|
|
175
|
+
this.left = node;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
this.getSize = (node) => {
|
|
179
|
+
this.getTop(node);
|
|
180
|
+
this.getRight(node);
|
|
181
|
+
this.getBottom(node);
|
|
182
|
+
this.getLeft(node);
|
|
183
|
+
};
|
|
184
|
+
this.privateUpdate = (node) => {
|
|
185
|
+
this.register(node);
|
|
186
|
+
this.getSize(node);
|
|
187
|
+
this.notify();
|
|
188
|
+
};
|
|
189
|
+
this.notify = () => {
|
|
190
|
+
for (const [_id, update] of Object.entries(this.subscriptions)) {
|
|
191
|
+
update(this.size(), this.nodes);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
this.debounceUpdates = {};
|
|
195
|
+
this.update = (node) => {
|
|
196
|
+
this.debounceUpdates[node.id](node);
|
|
197
|
+
};
|
|
198
|
+
this.match = (x, y) => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
const ids = yield Promise.resolve(Object.keys(this.nodes).find((id) => {
|
|
200
|
+
const node = this.nodes[id];
|
|
201
|
+
return x > node.x &&
|
|
202
|
+
x < node.x + node.width &&
|
|
203
|
+
y > node.y &&
|
|
204
|
+
y < node.y + node.height;
|
|
205
|
+
}));
|
|
206
|
+
return ids ?
|
|
207
|
+
ids :
|
|
208
|
+
undefined;
|
|
209
|
+
});
|
|
210
|
+
this.size = () => {
|
|
211
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
212
|
+
return {
|
|
213
|
+
bottom: ((_b = (_a = this.bottom) === null || _a === void 0 ? void 0 : _a.y) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = this.bottom) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0),
|
|
214
|
+
height: (((_f = (_e = this.bottom) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 0) +
|
|
215
|
+
((_h = (_g = this.bottom) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : 0)) - ((_k = (_j = this.top) === null || _j === void 0 ? void 0 : _j.y) !== null && _k !== void 0 ? _k : 0),
|
|
216
|
+
left: (_m = (_l = this.left) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
217
|
+
right: ((_p = (_o = this.right) === null || _o === void 0 ? void 0 : _o.x) !== null && _p !== void 0 ? _p : 0) + ((_r = (_q = this.right) === null || _q === void 0 ? void 0 : _q.width) !== null && _r !== void 0 ? _r : 0),
|
|
218
|
+
top: (_t = (_s = this.top) === null || _s === void 0 ? void 0 : _s.y) !== null && _t !== void 0 ? _t : 0,
|
|
219
|
+
width: (((_v = (_u = this.right) === null || _u === void 0 ? void 0 : _u.x) !== null && _v !== void 0 ? _v : 0) +
|
|
220
|
+
((_x = (_w = this.right) === null || _w === void 0 ? void 0 : _w.width) !== null && _x !== void 0 ? _x : 0)) - ((_z = (_y = this.left) === null || _y === void 0 ? void 0 : _y.x) !== null && _z !== void 0 ? _z : 0)
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
this.frequency = frequency;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.default = NodePositions;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lines_1 = require("./lines");
|
|
4
|
+
const generateOrigins = (target, source, line, center) => {
|
|
5
|
+
switch (line) {
|
|
6
|
+
case 'curve': {
|
|
7
|
+
return (0, lines_1.generateCurve)(source, target, center);
|
|
8
|
+
}
|
|
9
|
+
case 'direct': {
|
|
10
|
+
return (0, lines_1.generateDirect)(source, target, center);
|
|
11
|
+
}
|
|
12
|
+
case 'step':
|
|
13
|
+
default: {
|
|
14
|
+
return (0, lines_1.generateStep)(source, target, center);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.default = generateOrigins;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Coordinates, type Line } from './types';
|
|
2
|
+
export declare const curveHorizontal: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
3
|
+
export declare const curveVertical: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
4
|
+
declare const _default: (source: {
|
|
5
|
+
height: number;
|
|
6
|
+
shape: 'oval' | 'rectangle';
|
|
7
|
+
width: number;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
}, target: {
|
|
11
|
+
height: number;
|
|
12
|
+
shape: 'oval' | 'rectangle';
|
|
13
|
+
width: number;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}, center?: boolean) => Coordinates;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.curveVertical = exports.curveHorizontal = void 0;
|
|
7
|
+
const generatePoints_1 = __importDefault(require("./generatePoints"));
|
|
8
|
+
const bezier_js_1 = require("bezier-js");
|
|
9
|
+
const curveHorizontal = (rx1, ry1, rx2, ry2, center) => {
|
|
10
|
+
const x1 = Math.round(rx1);
|
|
11
|
+
const y1 = Math.round(ry1);
|
|
12
|
+
const x2 = Math.round(rx2);
|
|
13
|
+
const y2 = Math.round(ry2);
|
|
14
|
+
const d = [];
|
|
15
|
+
const mx = Math.round(x1 + (x2 - x1) / 2);
|
|
16
|
+
const c = center ?
|
|
17
|
+
new bezier_js_1.Bezier(x1, y1, mx, y1, mx, y2, x2, y2).compute(0.5) :
|
|
18
|
+
undefined;
|
|
19
|
+
d.push('M', x1, y1);
|
|
20
|
+
d.push('C', mx, y1, mx, y2, x2, y2);
|
|
21
|
+
return {
|
|
22
|
+
center: c,
|
|
23
|
+
path: d.join(' ')
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.curveHorizontal = curveHorizontal;
|
|
27
|
+
const curveVertical = (rx1, ry1, rx2, ry2, center) => {
|
|
28
|
+
const x1 = Math.round(rx1);
|
|
29
|
+
const y1 = Math.round(ry1);
|
|
30
|
+
const x2 = Math.round(rx2);
|
|
31
|
+
const y2 = Math.round(ry2);
|
|
32
|
+
const d = [];
|
|
33
|
+
const my = Math.round(y1 + (y2 - y1) / 2);
|
|
34
|
+
const c = center ?
|
|
35
|
+
new bezier_js_1.Bezier(x1, y1, x1, my, x2, my, x2, y2).compute(0.5) :
|
|
36
|
+
undefined;
|
|
37
|
+
d.push('M', x1, y1);
|
|
38
|
+
d.push('C', x1, my, x2, my, x2, y2);
|
|
39
|
+
return {
|
|
40
|
+
center: c,
|
|
41
|
+
path: d.join(' ')
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.curveVertical = curveVertical;
|
|
45
|
+
exports.default = (source, target, center) => {
|
|
46
|
+
const { orientation, source: sourcePoints, target: targetPoints } = (0, generatePoints_1.default)(source, target);
|
|
47
|
+
return Object.assign(Object.assign({}, (orientation === 'horizontal' ?
|
|
48
|
+
(0, exports.curveHorizontal)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center) :
|
|
49
|
+
(0, exports.curveVertical)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center))), { source: sourcePoints, target: targetPoints });
|
|
50
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Coordinates, type Line } from './types';
|
|
2
|
+
export declare const direct: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
3
|
+
declare const _default: (source: {
|
|
4
|
+
height: number;
|
|
5
|
+
shape: 'oval' | 'rectangle';
|
|
6
|
+
width: number;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}, target: {
|
|
10
|
+
height: number;
|
|
11
|
+
shape: 'oval' | 'rectangle';
|
|
12
|
+
width: number;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}, center?: boolean) => Coordinates;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.direct = void 0;
|
|
7
|
+
const generatePoints_1 = __importDefault(require("./generatePoints"));
|
|
8
|
+
const direct = (rx1, ry1, rx2, ry2, center) => {
|
|
9
|
+
const x1 = Math.round(rx1);
|
|
10
|
+
const y1 = Math.round(ry1);
|
|
11
|
+
const x2 = Math.round(rx2);
|
|
12
|
+
const y2 = Math.round(ry2);
|
|
13
|
+
const cx = Math.round((x2 + x1) / 2);
|
|
14
|
+
const cy = Math.round((y2 + y1) / 2);
|
|
15
|
+
const d = [];
|
|
16
|
+
d.push('M', x1, y1);
|
|
17
|
+
d.push('L', x2, y2);
|
|
18
|
+
return {
|
|
19
|
+
center: center ?
|
|
20
|
+
{
|
|
21
|
+
x: cx,
|
|
22
|
+
y: cy
|
|
23
|
+
} :
|
|
24
|
+
undefined,
|
|
25
|
+
path: d.join(' ')
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.direct = direct;
|
|
29
|
+
exports.default = (source, target, center) => {
|
|
30
|
+
const { source: sourcePoints, target: targetPoints } = (0, generatePoints_1.default)(source, target);
|
|
31
|
+
return Object.assign(Object.assign({}, (0, exports.direct)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center)), { source: sourcePoints, target: targetPoints });
|
|
32
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Points } from './types';
|
|
2
|
+
declare const _default: (source: {
|
|
3
|
+
height: number;
|
|
4
|
+
shape: 'oval' | 'rectangle';
|
|
5
|
+
width: number;
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}, target: {
|
|
9
|
+
height: number;
|
|
10
|
+
shape: 'oval' | 'rectangle';
|
|
11
|
+
width: number;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}) => Points;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (source, target) => {
|
|
4
|
+
const sx = Math.round(source.x);
|
|
5
|
+
const sy = Math.round(source.y);
|
|
6
|
+
const tx = Math.round(target.x);
|
|
7
|
+
const ty = Math.round(target.y);
|
|
8
|
+
const halfTargetWidth = Math.round(target.width / 2);
|
|
9
|
+
const halfTargetHeight = Math.round(target.height / 2);
|
|
10
|
+
const halfSourceWidth = Math.round(source.width / 2);
|
|
11
|
+
const halfSourceHeight = Math.round(source.height / 2);
|
|
12
|
+
const sourceAngle = Math.atan2(tx + halfTargetWidth - (sx + halfSourceWidth), ty + halfTargetHeight - (sy + halfSourceHeight));
|
|
13
|
+
const targetAngle = Math.atan2(sx + halfSourceWidth - (tx + halfTargetWidth), sy + halfSourceHeight - (ty + halfTargetHeight));
|
|
14
|
+
const sourceEdgeX = Math.sin(sourceAngle) * halfSourceWidth + halfSourceWidth;
|
|
15
|
+
const sourceEdgeY = Math.cos(sourceAngle) * halfSourceHeight + halfSourceHeight;
|
|
16
|
+
const targetEdgeX = Math.sin(targetAngle) * halfTargetWidth + halfTargetWidth;
|
|
17
|
+
const targetEdgeY = Math.cos(targetAngle) * halfTargetHeight + halfTargetHeight;
|
|
18
|
+
const sourceDX = sx + sourceEdgeX - tx - targetEdgeX;
|
|
19
|
+
const sourceDY = sy + sourceEdgeY - ty - targetEdgeY;
|
|
20
|
+
const sourceROR = sourceDX / sourceDY;
|
|
21
|
+
let orientation;
|
|
22
|
+
let targetPoints = {
|
|
23
|
+
x: sourceEdgeX,
|
|
24
|
+
y: sourceEdgeY
|
|
25
|
+
};
|
|
26
|
+
if (sourceROR < 1 && sourceROR > -1) {
|
|
27
|
+
orientation = 'vertical';
|
|
28
|
+
if (sourceDY > 0) {
|
|
29
|
+
targetPoints = {
|
|
30
|
+
x: sx + sourceEdgeX,
|
|
31
|
+
y: sy + (source.shape === 'oval' ?
|
|
32
|
+
sourceEdgeY :
|
|
33
|
+
0)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
targetPoints = {
|
|
38
|
+
x: sx + sourceEdgeX,
|
|
39
|
+
y: sy + (source.shape === 'oval' ?
|
|
40
|
+
sourceEdgeY :
|
|
41
|
+
source.height)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
orientation = 'horizontal';
|
|
47
|
+
if (sourceDX > 0) {
|
|
48
|
+
targetPoints = {
|
|
49
|
+
x: sx + (source.shape === 'oval' ?
|
|
50
|
+
sourceEdgeX :
|
|
51
|
+
0),
|
|
52
|
+
y: sy + sourceEdgeY
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
targetPoints = {
|
|
57
|
+
x: sx + (source.shape === 'oval' ?
|
|
58
|
+
sourceEdgeX :
|
|
59
|
+
source.width),
|
|
60
|
+
y: sy + sourceEdgeY
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const targetDX = tx - targetEdgeX - sx - sourceEdgeX;
|
|
65
|
+
const targetDY = ty - targetEdgeY - sy - sourceEdgeY;
|
|
66
|
+
let sourcePoints = {
|
|
67
|
+
x: targetEdgeX,
|
|
68
|
+
y: targetEdgeY
|
|
69
|
+
};
|
|
70
|
+
if (orientation === 'vertical') {
|
|
71
|
+
if (targetDY > 0) {
|
|
72
|
+
sourcePoints = {
|
|
73
|
+
x: tx + targetEdgeX,
|
|
74
|
+
y: ty + (target.shape === 'oval' ?
|
|
75
|
+
targetEdgeY :
|
|
76
|
+
0)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
sourcePoints = {
|
|
81
|
+
x: tx + targetEdgeX,
|
|
82
|
+
y: ty + (target.shape === 'oval' ?
|
|
83
|
+
targetEdgeY :
|
|
84
|
+
target.height)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (targetDX > 0) {
|
|
90
|
+
sourcePoints = {
|
|
91
|
+
x: tx + (target.shape === 'oval' ?
|
|
92
|
+
targetEdgeX :
|
|
93
|
+
0),
|
|
94
|
+
y: ty + targetEdgeY
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
sourcePoints = {
|
|
99
|
+
x: tx + (target.shape === 'oval' ?
|
|
100
|
+
targetEdgeX :
|
|
101
|
+
target.width),
|
|
102
|
+
y: ty + targetEdgeY
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
orientation,
|
|
108
|
+
source: sourcePoints,
|
|
109
|
+
target: targetPoints
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Coordinates, type Line } from './types';
|
|
2
|
+
export declare const stepHorizontal: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
3
|
+
export declare const stepVertical: (rx1: number, ry1: number, rx2: number, ry2: number, center?: boolean) => Line;
|
|
4
|
+
declare const _default: (source: {
|
|
5
|
+
height: number;
|
|
6
|
+
shape: 'oval' | 'rectangle';
|
|
7
|
+
width: number;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
}, target: {
|
|
11
|
+
height: number;
|
|
12
|
+
shape: 'oval' | 'rectangle';
|
|
13
|
+
width: number;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}, center?: boolean) => Coordinates;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stepVertical = exports.stepHorizontal = void 0;
|
|
7
|
+
const generatePoints_1 = __importDefault(require("./generatePoints"));
|
|
8
|
+
const stepHorizontal = (rx1, ry1, rx2, ry2, center) => {
|
|
9
|
+
const x1 = Math.round(rx1);
|
|
10
|
+
const y1 = Math.round(ry1);
|
|
11
|
+
const x2 = Math.round(rx2);
|
|
12
|
+
const y2 = Math.round(ry2);
|
|
13
|
+
const d = [];
|
|
14
|
+
const mx = Math.round(x1 + (x2 - x1) / 2);
|
|
15
|
+
const my = Math.round(y1 + (y2 - y1) / 2);
|
|
16
|
+
const cx = Math.round((x2 + x1) / 2);
|
|
17
|
+
const cy = my;
|
|
18
|
+
d.push('M', x1, y1);
|
|
19
|
+
d.push('L', mx, y1);
|
|
20
|
+
d.push('L', mx, y2);
|
|
21
|
+
d.push('L', x2, y2);
|
|
22
|
+
return {
|
|
23
|
+
center: center ?
|
|
24
|
+
{
|
|
25
|
+
x: cx,
|
|
26
|
+
y: cy
|
|
27
|
+
} :
|
|
28
|
+
undefined,
|
|
29
|
+
path: d.join(' ')
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.stepHorizontal = stepHorizontal;
|
|
33
|
+
const stepVertical = (rx1, ry1, rx2, ry2, center) => {
|
|
34
|
+
const x1 = Math.round(rx1);
|
|
35
|
+
const y1 = Math.round(ry1);
|
|
36
|
+
const x2 = Math.round(rx2);
|
|
37
|
+
const y2 = Math.round(ry2);
|
|
38
|
+
const d = [];
|
|
39
|
+
const mx = Math.round(x1 + (x2 - x1) / 2);
|
|
40
|
+
const my = Math.round(y1 + (y2 - y1) / 2);
|
|
41
|
+
const cx = mx;
|
|
42
|
+
const cy = Math.round((y2 + y1) / 2);
|
|
43
|
+
d.push('M', x1, y1);
|
|
44
|
+
d.push('L', x1, my);
|
|
45
|
+
d.push('L', x2, my);
|
|
46
|
+
d.push('L', x2, y2);
|
|
47
|
+
return {
|
|
48
|
+
center: center ?
|
|
49
|
+
{
|
|
50
|
+
x: cx,
|
|
51
|
+
y: cy
|
|
52
|
+
} :
|
|
53
|
+
undefined,
|
|
54
|
+
path: d.join(' ')
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.stepVertical = stepVertical;
|
|
58
|
+
exports.default = (source, target, center) => {
|
|
59
|
+
const { orientation, source: sourcePoints, target: targetPoints } = (0, generatePoints_1.default)(source, target);
|
|
60
|
+
return Object.assign(Object.assign({}, (orientation === 'horizontal' ?
|
|
61
|
+
(0, exports.stepHorizontal)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center) :
|
|
62
|
+
(0, exports.stepVertical)(sourcePoints.x, sourcePoints.y, targetPoints.x, targetPoints.y, center))), { source: sourcePoints, target: targetPoints });
|
|
63
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateStep = exports.generateDirect = exports.generateCurve = void 0;
|
|
7
|
+
var generateCurve_1 = require("./generateCurve");
|
|
8
|
+
Object.defineProperty(exports, "generateCurve", { enumerable: true, get: function () { return __importDefault(generateCurve_1).default; } });
|
|
9
|
+
var generateDirect_1 = require("./generateDirect");
|
|
10
|
+
Object.defineProperty(exports, "generateDirect", { enumerable: true, get: function () { return __importDefault(generateDirect_1).default; } });
|
|
11
|
+
var generateStep_1 = require("./generateStep");
|
|
12
|
+
Object.defineProperty(exports, "generateStep", { enumerable: true, get: function () { return __importDefault(generateStep_1).default; } });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type Line = {
|
|
2
|
+
center?: {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
export type Orientation = 'horizontal' | 'vertical';
|
|
9
|
+
export type Points = {
|
|
10
|
+
orientation: Orientation;
|
|
11
|
+
source: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
};
|
|
15
|
+
target: {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type Coordinates = {
|
|
21
|
+
center?: {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
};
|
|
25
|
+
path: string;
|
|
26
|
+
source: {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
};
|
|
30
|
+
target: {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
};
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"name": "@lincle/react-shared",
|
|
3
3
|
"title": "lincle react shared",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.4.0-next.2",
|
|
6
|
+
"private": false,
|
|
6
7
|
"description": "Shared library for @lincle",
|
|
7
8
|
"author": "wallzero @wallzeroblog (http://wallzero.com)",
|
|
8
9
|
"contributors": [
|
|
@@ -19,20 +20,19 @@
|
|
|
19
20
|
"COPYING.md",
|
|
20
21
|
"COPYING.LESSER.md"
|
|
21
22
|
],
|
|
22
|
-
"homepage": "https://gitlab.com/
|
|
23
|
+
"homepage": "https://gitlab.com/digested/lincle/tree/master/packages/react-shared/",
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
25
|
-
"url": "https://gitlab.com/
|
|
26
|
+
"url": "https://gitlab.com/digested/lincle.git"
|
|
26
27
|
},
|
|
27
28
|
"bugs": {
|
|
28
|
-
"url": "https://gitlab.com/
|
|
29
|
+
"url": "https://gitlab.com/digested/lincle/issues"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
|
-
"build": "run-s clean:dist build:prod
|
|
32
|
+
"build": "run-s clean:dist build:prod",
|
|
32
33
|
"build:prod": "tsc -p ./tsconfig.json",
|
|
33
|
-
"build:watch": "run-s clean:dist build:prod build:
|
|
34
|
+
"build:watch": "run-s clean:dist build:prod build:watch:tsc",
|
|
34
35
|
"build:watch:tsc": "tsc -p ./tsconfig.json --watch --pretty --preserveWatchOutput",
|
|
35
|
-
"build:styles": "ncp src/styles.g.css dist/styles.g.css",
|
|
36
36
|
"----------------------------------------------------------------": "",
|
|
37
37
|
"build:prod:config": "",
|
|
38
38
|
"---------------------------------------------------------------": "",
|
|
@@ -43,31 +43,32 @@
|
|
|
43
43
|
"clean:dist": "rimraf dist"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@digest/eslint-config-jest": "^4.
|
|
47
|
-
"@digest/eslint-config-react": "^4.
|
|
48
|
-
"@digest/eslint-config-typescript": "^4.
|
|
49
|
-
"@digest/jest-junit": "^4.
|
|
50
|
-
"@digest/jest-react": "^4.
|
|
51
|
-
"@digest/jest-typescript": "^4.
|
|
52
|
-
"@digest/typescript": "^4.
|
|
53
|
-
"@types/bezier-js": "^4.1.
|
|
54
|
-
"@types/jest": "^29.5.
|
|
55
|
-
"@types/lodash.
|
|
56
|
-
"@types/lodash.
|
|
57
|
-
"@types/node": "^20.
|
|
58
|
-
"@types/react": "^18.2
|
|
59
|
-
"@types/react-dom": "^18.
|
|
60
|
-
"@types/react-test-renderer": "^18.0
|
|
46
|
+
"@digest/eslint-config-jest": "^4.3.1",
|
|
47
|
+
"@digest/eslint-config-react": "^4.3.1",
|
|
48
|
+
"@digest/eslint-config-typescript": "^4.3.1",
|
|
49
|
+
"@digest/jest-junit": "^4.3.1",
|
|
50
|
+
"@digest/jest-react": "^4.3.1",
|
|
51
|
+
"@digest/jest-typescript": "^4.3.1",
|
|
52
|
+
"@digest/typescript": "^4.3.1",
|
|
53
|
+
"@types/bezier-js": "^4.1.3",
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
55
|
+
"@types/lodash.debounce": "^4.0.9",
|
|
56
|
+
"@types/lodash.throttle": "^4.1.9",
|
|
57
|
+
"@types/node": "^20.12.12",
|
|
58
|
+
"@types/react": "^18.3.2",
|
|
59
|
+
"@types/react-dom": "^18.3.0",
|
|
60
|
+
"@types/react-test-renderer": "^18.3.0",
|
|
61
61
|
"cross-env": "^7.0.3",
|
|
62
|
-
"jest-environment-jsdom": "^29.
|
|
62
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
63
63
|
"jest-environment-jsdom-global": "^4.0.0",
|
|
64
64
|
"ncp": "^2.0.0",
|
|
65
65
|
"npm-run-all": "^4.1.5",
|
|
66
|
-
"react": "^18.
|
|
67
|
-
"react-test-renderer": "^18.
|
|
68
|
-
"rimraf": "^5.0.
|
|
66
|
+
"react": "^18.3.1",
|
|
67
|
+
"react-test-renderer": "^18.3.1",
|
|
68
|
+
"rimraf": "^5.0.7"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
+
"bezier-js": "^6.1.4",
|
|
71
72
|
"lodash.debounce": "^4.0.8",
|
|
72
73
|
"lodash.throttle": "^4.1.1"
|
|
73
74
|
},
|
|
@@ -86,5 +87,6 @@
|
|
|
86
87
|
"dag",
|
|
87
88
|
"acyclical graph",
|
|
88
89
|
"cyclical graph"
|
|
89
|
-
]
|
|
90
|
+
],
|
|
91
|
+
"gitHead": "c00bcd56556ee5599505cbeeebfdab06e4a8c552"
|
|
90
92
|
}
|