forked from marionebl/react-surface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.d.ts
196 lines (175 loc) · 5.43 KB
/
global.d.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
declare module JSX {
interface IntrinsicElements {
text: SurfaceProps;
surface: SurfaceProps;
}
}
type CSSProps = React.CSSProperties;
type Percentage = string; // TODO can typescript enforce percentage strings?
type SurfaceTweenInstruction = any;
type SurfaceValue = number | SurfaceTweenInstruction;
type SurfaceValueP = SurfaceValue | Percentage; // SurfaceValue with percentage support
type SurfaceChild = React.ReactElement<SurfaceProps> | React.ReactNode;
type SurfaceStyle = YogaProps & RenderProps;
type SurfaceStyleDict = {[key: string]: SurfaceStyle};
type SurfaceMaskId = number | string;
// TODO use 'color' package
type IColor = SurfaceTweenInstruction | {
rgbNumber (): number;
red (): number;
green (): number;
blue (): number;
alpha (): number;
};
type Point = {
x: number,
y: number
};
type Size = {
width: number,
height: number
};
type Bounds = {
top: number,
right: number,
width: number;
height: number;
bottom: number,
left: number
};
type YogaProps = {
position?: 'absolute' | 'relative',
alignContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'stretch';
alignItems?: 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch';
alignSelf?: 'auto' | 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch';
flexAlign?: any;
flexBasis?: SurfaceValue;
flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
flexFlow?: string;
flexGrow?: SurfaceValue;
flexItemAlign?: any;
flexLinePack?: any;
flexOrder?: any;
flexShrink?: SurfaceValue;
flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
top?: SurfaceValueP;
right?: SurfaceValueP;
bottom?: SurfaceValueP;
left?: SurfaceValueP;
width?: SurfaceValueP;
height?: SurfaceValueP;
minWidth?: SurfaceValueP;
minHeight?: SurfaceValueP;
maxWidth?: SurfaceValueP;
maxHeight?: SurfaceValueP;
justifyContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly';
margin?: SurfaceValueP;
marginBottom?: SurfaceValueP;
marginLeft?: SurfaceValueP;
marginRight?: SurfaceValueP;
marginTop?: SurfaceValueP;
padding?: SurfaceValueP;
paddingBottom?: SurfaceValueP;
paddingLeft?: SurfaceValueP;
paddingRight?: SurfaceValueP;
paddingTop?: SurfaceValueP;
border?: SurfaceValueP;
borderTop?: SurfaceValueP;
borderRight?: SurfaceValueP;
borderBottom?: SurfaceValueP;
borderLeft?: SurfaceValueP;
overflow?: 'visible' | 'hidden' | 'scroll';
opacity?: SurfaceValue;
};
type RenderProps = SurfaceTransform & {
color?: IColor;
textAlign?: 'start' | 'center' | 'end',
wordWrap?: boolean;
letterSpacing?: SurfaceValue;
fontFamily?: string | string[];
fontSize?: SurfaceValue;
fontStyle?: string;
fontWeight?: string;
backgroundGradient?: any; // TODO type
backgroundColor?: IColor;
backgroundImage?: any;
backgroundOpacity?: SurfaceValue,
backgroundPosition?: Array<SurfaceValueP>;
backgroundSize?: 'auto' | 'cover' | 'contain' | Percentage | Array<Percentage>;
borderRadius?: SurfaceValue;
borderColor?: IColor;
borderColorTop?: IColor;
borderColorRight?: IColor;
borderColorBottom?: IColor;
borderColorLeft?: IColor;
dropShadowDistance?: SurfaceValue,
dropShadowColor?: IColor,
dropShadowAlpha?: SurfaceValue,
dropShadowSize?: SurfaceValue,
dropShadowRotation?: SurfaceValue,
mask?: SurfaceMaskId,
maskedBy?: SurfaceMaskId
};
type SurfaceTransform = {
translateX?: SurfaceValue,
translateY?: SurfaceValue,
scaleX?: SurfaceValue,
scaleY?: SurfaceValue,
rotation?: SurfaceValue,
skewX?: SurfaceValue,
skewY?: SurfaceValue,
pivotX?: SurfaceValue,
pivotY?: SurfaceValue
};
type SurfaceEvents = {
onClick?: (e: PIXI.interaction.InteractionEvent) => void;
onRightClick?: (e: PIXI.interaction.InteractionEvent) => void;
onMouseUp?: (e: PIXI.interaction.InteractionEvent) => void;
onMouseDown?: (e: PIXI.interaction.InteractionEvent) => void;
onMouseEnter?: (e: PIXI.interaction.InteractionEvent) => void;
onMouseLeave?: (e: PIXI.interaction.InteractionEvent) => void;
onSizeChanged?: (size: Size) => void;
onBoundsChanged?: (bounds: Bounds) => void;
};
type SurfaceProps = SurfaceEvents & RenderProps & YogaProps & {
// React internals
key?: string | number;
ref?: (surf: any) => void;
hidden?: boolean;
children?: SurfaceChild | Array<SurfaceChild | Array<SurfaceChild>>;
};
// TODO replace types below with actual types from react-reconciler and yoga-layout when they are available
type FiberNode = {
_debugID: number;
stateNode: Element; // TODO generate dom node equivalents of all surfaces to enable dev tool highlights
type: string;
};
type HostContext = {};
type ReactContainer<TContainerInfo> = {
containerInfo: TContainerInfo
};
type ReactReconciler<TRoot> = {
injectIntoDevTools (config: any): void;
createContainer (root: TRoot): ReactContainer<TRoot>;
updateContainer<P> (element: React.ReactElement<P>, container: ReactContainer<TRoot>): void;
};
type YogaLayout = {
left: number,
top: number,
right: number,
bottom: number,
width: number,
height: number
};
type YogaNode = {
reset (): void;
getParent (): YogaNode;
getChild (index: number): YogaNode;
getChildCount (): number;
insertChild (child: YogaNode, index?: number): void;
removeChild (child: YogaNode): void;
calculateLayout (width: number, height: number, direction: any): void;
getComputedLayout (): YogaLayout;
setMeasureFunc (fn: () => any): void;
markDirty (): void;
};