-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathstyles.ts
201 lines (180 loc) · 4.55 KB
/
styles.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
197
198
199
200
201
import { CSSProperties } from "react";
import {
ImageExtended,
StyleFunction,
StyleFunctionContext,
StyleProp,
} from "./types";
export const getStyle = (
styleProp: StyleProp | undefined,
fallback: StyleFunction,
context: StyleFunctionContext
): CSSProperties => {
if (typeof styleProp === "function") {
return styleProp(context);
}
if (typeof styleProp === "object") {
return styleProp;
}
return fallback(context);
};
const rotationTransformMap: Record<number, string> = {
3: "rotate(180deg)",
2: "rotateY(180deg)",
4: "rotate(180deg) rotateY(180deg)",
5: "rotate(270deg) rotateY(180deg)",
6: "rotate(90deg)",
7: "rotate(90deg) rotateY(180deg)",
8: "rotate(270deg)",
};
const SELECTION_MARGIN = 16;
export const gallery: CSSProperties = {
display: "flex",
flexWrap: "wrap",
};
export const thumbnail = ({ item }: { item: ImageExtended }): CSSProperties => {
const rotationTransformValue = rotationTransformMap[item.orientation];
const style = {
cursor: "pointer",
maxWidth: "none",
width: item.scaledWidth,
height: item.scaledHeight,
marginLeft: item.marginLeft,
marginTop: 0,
transform: rotationTransformValue,
};
if (item.isSelected) {
const ratio = item.scaledWidth / item.scaledHeight;
const viewportHeight = item.scaledHeight - SELECTION_MARGIN * 2;
const viewportWidth = item.viewportWidth - SELECTION_MARGIN * 2;
let height, width;
if (item.scaledWidth > item.scaledHeight) {
width = item.scaledWidth - SELECTION_MARGIN * 2;
height = Math.floor(width / ratio);
} else {
height = item.scaledHeight - SELECTION_MARGIN * 2;
width = Math.floor(height * ratio);
}
const marginTop = Math.abs(Math.floor((viewportHeight - height) / 2));
const marginLeft = Math.abs(Math.floor((viewportWidth - width) / 2));
style.width = width;
style.height = height;
style.marginLeft = marginLeft === 0 ? 0 : -marginLeft;
style.marginTop = marginTop === 0 ? 0 : -marginTop;
}
return style;
};
export const tileViewport = ({
item,
}: {
item: ImageExtended;
}): CSSProperties => {
const styles: CSSProperties = {
width: item.viewportWidth,
height: item.scaledHeight,
overflow: "hidden",
};
if (item.nano) {
styles.background = `url(${item.nano})`;
styles.backgroundSize = "cover";
styles.backgroundPosition = "center center";
}
if (item.isSelected) {
styles.width = item.viewportWidth - SELECTION_MARGIN * 2;
styles.height = item.scaledHeight - SELECTION_MARGIN * 2;
styles.margin = SELECTION_MARGIN;
}
return styles;
};
export const customOverlay = ({
hover,
}: {
hover: boolean;
}): CSSProperties => ({
pointerEvents: "none",
opacity: hover ? 1 : 0,
position: "absolute",
height: "100%",
width: "100%",
});
export const galleryItem = ({ margin }: { margin: number }): CSSProperties => ({
margin,
WebkitUserSelect: "none",
position: "relative",
background: "#eee",
padding: "0px",
});
export const tileOverlay = ({
showOverlay,
}: {
showOverlay: boolean;
}): CSSProperties => ({
pointerEvents: "none",
opacity: 1,
position: "absolute",
height: "100%",
width: "100%",
background: showOverlay
? "linear-gradient(to bottom,rgba(0,0,0,0.26),transparent 56px,transparent)"
: "none",
});
export const tileIconBar: CSSProperties = {
pointerEvents: "none",
opacity: 1,
position: "absolute",
height: "36px",
width: "100%",
};
export const tileDescription: CSSProperties = {
background: "white",
width: "100%",
margin: 0,
userSelect: "text",
WebkitUserSelect: "text",
MozUserSelect: "text",
overflow: "hidden",
};
export const bottomBar: CSSProperties = {
padding: "2px",
pointerEvents: "none",
position: "absolute",
minHeight: "0px",
maxHeight: "160px",
width: "100%",
bottom: "0px",
overflow: "hidden",
};
export const tagItemBlock: CSSProperties = {
display: "inline-block",
cursor: "pointer",
pointerEvents: "visible",
margin: "2px",
};
export const tagItem = (): CSSProperties => ({
display: "inline",
padding: ".2em .6em .3em",
fontSize: "75%",
fontWeight: "600",
lineHeight: "1",
color: "yellow",
background: "rgba(0,0,0,0.65)",
textAlign: "center",
whiteSpace: "nowrap",
verticalAlign: "baseline",
borderRadius: ".25em",
});
export const checkButton = ({
isVisible,
}: {
isVisible: boolean;
}): CSSProperties => ({
visibility: isVisible ? "visible" : "hidden",
background: "none",
float: "left",
width: 36,
height: 36,
border: "none",
padding: 6,
cursor: "pointer",
pointerEvents: "visible",
});