forked from Eliav2/react-xarrows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
134 lines (124 loc) · 3.53 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
///////////////
// public types
import React from 'react';
import { tAnchorEdge, tPaths, tSvgElems, tArrowShapes } from '.';
export type xarrowPropsType = {
start: refType;
end: refType;
startAnchor?: anchorType | anchorType[];
endAnchor?: anchorType | anchorType[];
label?: labelType | labelsType;
color?: string;
lineColor?: string | null;
headColor?: string | null;
tailColor?: string | null;
strokeWidth?: number;
showHead?: boolean;
headSize?: number;
showTail?: boolean;
tailSize?: number;
path?: pathType;
showXarrow?: boolean;
curveness?: number;
gridBreak?: number;
// gridRadius?: number;
dashness?:
| boolean
| {
strokeLen?: number;
nonStrokeLen?: number;
animation?: boolean | number;
};
headShape?: svgEdgeShapeType | svgCustomEdgeType;
tailShape?: svgEdgeShapeType | svgCustomEdgeType;
animateDrawing?: boolean | number;
passProps?: JSX.IntrinsicElements[svgElemType];
SVGcanvasProps?: React.SVGAttributes<SVGSVGElement>;
arrowBodyProps?: React.SVGProps<SVGPathElement>;
arrowHeadProps?: JSX.IntrinsicElements[svgElemType];
arrowTailProps?: JSX.IntrinsicElements[svgElemType];
divContainerProps?: React.HTMLProps<HTMLDivElement>;
SVGcanvasStyle?: React.CSSProperties;
divContainerStyle?: React.CSSProperties;
_extendSVGcanvas?: number;
_debug?: boolean;
_cpx1Offset?: number;
_cpy1Offset?: number;
_cpx2Offset?: number;
_cpy2Offset?: number;
updatePositions?: updatePositionsType;
};
export type curveType = {
x1: number;
y1: number;
x2: number;
y2: number;
cpx1: number;
cpy1: number;
cpx2: number;
cpy2: number;
};
export type updatePositionType = {
hh?: (arg1: curveType) => number[];
hv?: (arg1: curveType) => number[];
vh?: (arg1: curveType) => number[];
vv?: (arg1: curveType) => number[];
};
export type updatePositionsType = {
smooth?: updatePositionType;
grid?: updatePositionType;
};
export type pathType = typeof tPaths[number];
export type anchorType = anchorPositionType | anchorCustomPositionType;
export type anchorPositionType = typeof tAnchorEdge[number];
export type anchorCustomPositionType = {
position: anchorPositionType;
offset: { rightness?: number; bottomness?: number };
};
export type refType = React.MutableRefObject<any> | string;
export type labelsType = {
start?: labelType;
middle?: labelType;
end?: labelType;
};
export type labelType = JSX.Element | string;
export type svgCustomTypeGeneric<T extends svgElemType> = {
svgElem: T;
svgProps?: JSX.IntrinsicElements[T];
offsetForward?: number;
};
export type svgCustomEdgeType = { [K in svgElemType]: svgCustomTypeGeneric<K> }[svgElemType];
export type svgEdgeShapeType = typeof tArrowShapes[number];
export type svgEdgeType = svgEdgeShapeType | svgCustomEdgeType;
export type svgElemType = typeof tSvgElems[number];
////////////////
// private types
export type _prevPosType = {
start: {
x: number;
y: number;
right: number;
bottom: number;
};
end: {
x: number;
y: number;
right: number;
bottom: number;
};
};
// pick the common props between 2 objects
type Common<A, B> = {
[P in keyof A & keyof B]: A[P] | B[P];
};
// const c: Common<T1, T2> = { y: 123 };
// export type SvgCustomTypeOneLiner = svgElemType extends infer T
// ? T extends svgElemType
// ? { svgElem: T; svgProps?: JSX.IntrinsicElements[T] }
// : never
// : never;
// export type svgCustomType<T extends svgElemType> = {
// svgElem: T;
// svgProps?: { [key in T]: JSX.IntrinsicElements[T] };
// offsetForward?: number;
// };