@douyinfe/semi-foundation 2.63.0 → 2.64.0-beta.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.
- package/calendar/foundation.ts +20 -0
- package/chat/foundation.ts +18 -23
- package/colorPicker/AlphaSliderFoundation.ts +62 -0
- package/colorPicker/ColorChooseAreaFoundation.ts +86 -0
- package/colorPicker/ColorSliderFoundation.ts +61 -0
- package/colorPicker/DataPartFoundation.ts +113 -0
- package/colorPicker/colorPicker.scss +113 -0
- package/colorPicker/constants.ts +11 -0
- package/colorPicker/foundation.ts +206 -0
- package/colorPicker/interface.ts +51 -0
- package/colorPicker/utils/convert.ts +228 -0
- package/colorPicker/utils/round.ts +3 -0
- package/colorPicker/utils/split.ts +40 -0
- package/colorPicker/variables.scss +28 -0
- package/datePicker/foundation.ts +1 -1
- package/image/image.scss +6 -1
- package/image/previewImageFoundation.ts +233 -150
- package/image/previewInnerFoundation.ts +11 -6
- package/lib/cjs/calendar/foundation.js +18 -0
- package/lib/cjs/chat/foundation.d.ts +1 -2
- package/lib/cjs/chat/foundation.js +2 -7
- package/lib/cjs/colorPicker/AlphaSliderFoundation.d.ts +27 -0
- package/lib/cjs/colorPicker/AlphaSliderFoundation.js +40 -0
- package/lib/cjs/colorPicker/ColorChooseAreaFoundation.d.ts +42 -0
- package/lib/cjs/colorPicker/ColorChooseAreaFoundation.js +62 -0
- package/lib/cjs/colorPicker/ColorSliderFoundation.d.ts +26 -0
- package/lib/cjs/colorPicker/ColorSliderFoundation.js +40 -0
- package/lib/cjs/colorPicker/DataPartFoundation.d.ts +28 -0
- package/lib/cjs/colorPicker/DataPartFoundation.js +115 -0
- package/lib/cjs/colorPicker/colorPicker.css +84 -0
- package/lib/cjs/colorPicker/colorPicker.scss +113 -0
- package/lib/cjs/colorPicker/constants.d.ts +4 -0
- package/lib/cjs/colorPicker/constants.js +11 -0
- package/lib/cjs/colorPicker/foundation.d.ts +66 -0
- package/lib/cjs/colorPicker/foundation.js +150 -0
- package/lib/cjs/colorPicker/interface.d.ts +40 -0
- package/lib/cjs/colorPicker/interface.js +5 -0
- package/lib/cjs/colorPicker/utils/convert.d.ts +28 -0
- package/lib/cjs/colorPicker/utils/convert.js +306 -0
- package/lib/cjs/colorPicker/utils/round.d.ts +1 -0
- package/lib/cjs/colorPicker/utils/round.js +12 -0
- package/lib/cjs/colorPicker/utils/split.d.ts +18 -0
- package/lib/cjs/colorPicker/utils/split.js +40 -0
- package/lib/cjs/colorPicker/variables.scss +28 -0
- package/lib/cjs/datePicker/foundation.js +1 -1
- package/lib/cjs/image/image.css +5 -1
- package/lib/cjs/image/image.scss +6 -1
- package/lib/cjs/image/previewImageFoundation.d.ts +46 -13
- package/lib/cjs/image/previewImageFoundation.js +207 -181
- package/lib/cjs/image/previewInnerFoundation.d.ts +4 -3
- package/lib/cjs/image/previewInnerFoundation.js +5 -2
- package/lib/cjs/upload/foundation.d.ts +1 -0
- package/lib/cjs/upload/foundation.js +30 -14
- package/lib/es/calendar/foundation.js +18 -0
- package/lib/es/chat/foundation.d.ts +1 -2
- package/lib/es/chat/foundation.js +2 -7
- package/lib/es/colorPicker/AlphaSliderFoundation.d.ts +27 -0
- package/lib/es/colorPicker/AlphaSliderFoundation.js +33 -0
- package/lib/es/colorPicker/ColorChooseAreaFoundation.d.ts +42 -0
- package/lib/es/colorPicker/ColorChooseAreaFoundation.js +55 -0
- package/lib/es/colorPicker/ColorSliderFoundation.d.ts +26 -0
- package/lib/es/colorPicker/ColorSliderFoundation.js +33 -0
- package/lib/es/colorPicker/DataPartFoundation.d.ts +28 -0
- package/lib/es/colorPicker/DataPartFoundation.js +108 -0
- package/lib/es/colorPicker/colorPicker.css +84 -0
- package/lib/es/colorPicker/colorPicker.scss +113 -0
- package/lib/es/colorPicker/constants.d.ts +4 -0
- package/lib/es/colorPicker/constants.js +6 -0
- package/lib/es/colorPicker/foundation.d.ts +66 -0
- package/lib/es/colorPicker/foundation.js +143 -0
- package/lib/es/colorPicker/interface.d.ts +40 -0
- package/lib/es/colorPicker/interface.js +1 -0
- package/lib/es/colorPicker/utils/convert.d.ts +28 -0
- package/lib/es/colorPicker/utils/convert.js +277 -0
- package/lib/es/colorPicker/utils/round.d.ts +1 -0
- package/lib/es/colorPicker/utils/round.js +5 -0
- package/lib/es/colorPicker/utils/split.d.ts +18 -0
- package/lib/es/colorPicker/utils/split.js +34 -0
- package/lib/es/colorPicker/variables.scss +28 -0
- package/lib/es/datePicker/foundation.js +1 -1
- package/lib/es/image/image.css +5 -1
- package/lib/es/image/image.scss +6 -1
- package/lib/es/image/previewImageFoundation.d.ts +46 -13
- package/lib/es/image/previewImageFoundation.js +207 -181
- package/lib/es/image/previewInnerFoundation.d.ts +4 -3
- package/lib/es/image/previewInnerFoundation.js +5 -2
- package/lib/es/upload/foundation.d.ts +1 -0
- package/lib/es/upload/foundation.js +30 -14
- package/package.json +3 -3
- package/upload/foundation.ts +19 -3
|
@@ -12,60 +12,86 @@ export interface DragDirection {
|
|
|
12
12
|
canDragHorizontal: boolean
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export interface ExtremeTranslate {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Offset {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
export interface
|
|
25
|
+
export interface Translate {
|
|
21
26
|
x: number;
|
|
22
27
|
y: number
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
30
|
+
interface CalcBoundingRectMouseOffset {
|
|
31
|
+
offset: Offset;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
rotation?: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface BoundingRectSize {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
export default class PreviewImageFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<PreviewImageAdapter<P, S>, P, S> {
|
|
37
43
|
constructor(adapter: PreviewImageAdapter<P, S>) {
|
|
38
44
|
super({ ...adapter });
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
startMouseClientPosition = { x: 0, y: 0 };
|
|
42
48
|
originImageWidth = null;
|
|
43
49
|
originImageHeight = null;
|
|
44
50
|
|
|
51
|
+
containerWidth = 0;
|
|
52
|
+
containerHeight = 0;
|
|
53
|
+
|
|
54
|
+
init() {
|
|
55
|
+
this._getContainerBoundingRectSize();
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
_isImageVertical = (): boolean => this.getProp("rotation") % 180 !== 0;
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
60
|
+
_getContainerBoundingRectSize = () => {
|
|
61
|
+
const containerDOM = this._adapter.getContainer();
|
|
62
|
+
if (containerDOM) {
|
|
63
|
+
this.containerWidth = containerDOM.clientWidth;
|
|
64
|
+
this.containerHeight = containerDOM.clientHeight;
|
|
51
65
|
}
|
|
52
|
-
|
|
53
|
-
};
|
|
66
|
+
}
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
_getAdaptationZoom = () => {
|
|
69
|
+
let _zoom = 1;
|
|
56
70
|
const containerDOM = this._adapter.getContainer();
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
|
|
72
|
+
if (containerDOM && this.originImageWidth && this.originImageHeight) {
|
|
73
|
+
const { rotation } = this.getProps();
|
|
74
|
+
const { width: imageWidth, height: imageHeight } = this.calcBoundingRectSize(this.originImageWidth, this.originImageHeight, rotation);
|
|
75
|
+
const reservedWidth = this.containerWidth - 80;
|
|
76
|
+
const reservedHeight = this.containerHeight - 80;
|
|
77
|
+
|
|
78
|
+
_zoom = Number(
|
|
79
|
+
Math.min(reservedWidth / imageWidth, reservedHeight / imageHeight).toFixed(2)
|
|
80
|
+
);
|
|
59
81
|
}
|
|
60
|
-
|
|
82
|
+
|
|
83
|
+
return _zoom;
|
|
61
84
|
}
|
|
62
85
|
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
_getInitialZoom = () => {
|
|
87
|
+
const { ratio } = this.getProps();
|
|
88
|
+
let _zoom = 1;
|
|
89
|
+
|
|
90
|
+
if (ratio === 'adaptation') {
|
|
91
|
+
_zoom = this._getAdaptationZoom();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return _zoom;
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
setLoading = (loading: boolean) => {
|
|
@@ -73,9 +99,8 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
|
|
|
73
99
|
}
|
|
74
100
|
|
|
75
101
|
handleWindowResize = (): void => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
102
|
+
this._getContainerBoundingRectSize();
|
|
103
|
+
this.initializeImage();
|
|
79
104
|
};
|
|
80
105
|
|
|
81
106
|
handleLoad = (e: any): void => {
|
|
@@ -88,7 +113,7 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
|
|
|
88
113
|
} as any);
|
|
89
114
|
// 图片初次加载,计算 zoom,zoom 改变不需要通过回调透出
|
|
90
115
|
// When the image is loaded for the first time, zoom is calculated, and zoom changes do not need to be exposed through callbacks.
|
|
91
|
-
this.
|
|
116
|
+
this.initializeImage(false);
|
|
92
117
|
}
|
|
93
118
|
const { src, onLoad } = this.getProps();
|
|
94
119
|
onLoad && onLoad(src);
|
|
@@ -102,53 +127,35 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
|
|
|
102
127
|
onError && onError(src);
|
|
103
128
|
}
|
|
104
129
|
|
|
105
|
-
|
|
106
|
-
|
|
130
|
+
handleRatioChange = () => {
|
|
131
|
+
this.initializeImage();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
initializeImageZoom = (notify = true) => {
|
|
107
135
|
const { currZoom } = this.getStates();
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let _zoom = 1;
|
|
117
|
-
if (imgWidth > reservedWidth || imgHeight > reservedHeight) {
|
|
118
|
-
_zoom = Number(
|
|
119
|
-
Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2)
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
if (currZoom === _zoom) {
|
|
123
|
-
this.calculatePreviewImage(_zoom, null);
|
|
124
|
-
} else {
|
|
125
|
-
onZoom(_zoom, notify);
|
|
126
|
-
}
|
|
136
|
+
const { onZoom } = this.getProps();
|
|
137
|
+
|
|
138
|
+
const _zoom = this._getInitialZoom();
|
|
139
|
+
|
|
140
|
+
if (currZoom !== _zoom) {
|
|
141
|
+
onZoom(_zoom, notify);
|
|
142
|
+
} else {
|
|
143
|
+
this.changeZoom(_zoom);
|
|
127
144
|
}
|
|
128
145
|
}
|
|
129
146
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (ratio === 'adaptation') {
|
|
136
|
-
const horizontal = !this._isImageVertical();
|
|
137
|
-
const imgWidth = horizontal ? this.originImageWidth : this.originImageHeight;
|
|
138
|
-
const imgHeight = horizontal ? this.originImageHeight : this.originImageWidth;
|
|
139
|
-
const { width: containerWidth, height: containerHeight } = this._getContainerBounds();
|
|
140
|
-
const reservedWidth = containerWidth - 80;
|
|
141
|
-
const reservedHeight = containerHeight - 80;
|
|
142
|
-
_zoom = Number(
|
|
143
|
-
Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2)
|
|
144
|
-
);
|
|
145
|
-
} else {
|
|
146
|
-
_zoom = 1;
|
|
147
|
-
}
|
|
148
|
-
if (currZoom !== _zoom) {
|
|
149
|
-
onZoom(_zoom);
|
|
147
|
+
initializeTranslate = () => {
|
|
148
|
+
this.setState({
|
|
149
|
+
translate: {
|
|
150
|
+
x: 0,
|
|
151
|
+
y: 0
|
|
150
152
|
}
|
|
151
|
-
}
|
|
153
|
+
} as any);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
initializeImage = (notify = true) => {
|
|
157
|
+
this.initializeImageZoom(notify);
|
|
158
|
+
this.initializeTranslate();
|
|
152
159
|
}
|
|
153
160
|
|
|
154
161
|
handleRightClickImage = (e: any) => {
|
|
@@ -162,111 +169,187 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
|
|
|
162
169
|
}
|
|
163
170
|
};
|
|
164
171
|
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
calcBoundingRectSize(width = 0, height = 0, rotation = 0) {
|
|
173
|
+
const angleInRadians = rotation * Math.PI / 180;
|
|
174
|
+
const sinTheta = Math.abs(Math.sin(angleInRadians));
|
|
175
|
+
const cosTheta = Math.abs(Math.cos(angleInRadians));
|
|
176
|
+
const boundingWidth = width * cosTheta + height * sinTheta;
|
|
177
|
+
const boundingHeight = width * sinTheta + height * cosTheta;
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
width: boundingWidth,
|
|
181
|
+
height: boundingHeight
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getCanDragDirection = (width: number, height: number): DragDirection => {
|
|
186
|
+
let canDragHorizontal = width > this.containerWidth;
|
|
187
|
+
let canDragVertical = height > this.containerHeight;
|
|
188
|
+
|
|
175
189
|
return {
|
|
176
190
|
canDragVertical,
|
|
177
191
|
canDragHorizontal,
|
|
178
192
|
};
|
|
179
193
|
};
|
|
180
194
|
|
|
181
|
-
|
|
195
|
+
changeZoom = (newZoom: number, e?: WheelEvent): void => {
|
|
182
196
|
const imageDOM = this._adapter.getImage();
|
|
183
|
-
const {
|
|
184
|
-
const
|
|
185
|
-
const
|
|
197
|
+
const { currZoom, translate, width, height } = this.getStates();
|
|
198
|
+
const { rotation } = this.getProps();
|
|
199
|
+
const changeScale = newZoom / (currZoom || 1);
|
|
186
200
|
const newWidth = Math.floor(this.originImageWidth * newZoom);
|
|
187
201
|
const newHeight = Math.floor(this.originImageHeight * newZoom);
|
|
202
|
+
let newTranslateX = Math.floor(translate.x * changeScale);
|
|
203
|
+
let newTranslateY = Math.floor(translate.y * changeScale);
|
|
188
204
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
const imageBound = this.calcBoundingRectSize(width, height, rotation);
|
|
206
|
+
const newImageBound = {
|
|
207
|
+
width: imageBound.width * changeScale,
|
|
208
|
+
height: imageBound.height * changeScale
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (e && imageDOM && e.target === imageDOM) {
|
|
212
|
+
const { x: offsetX, y: offsetY } = this.calcBoundingRectMouseOffset({
|
|
213
|
+
width,
|
|
214
|
+
height,
|
|
215
|
+
offset: {
|
|
216
|
+
x: e.offsetX,
|
|
217
|
+
y: e.offsetY
|
|
218
|
+
},
|
|
219
|
+
rotation
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const imageNewCenterX = e.clientX + (imageBound.width / 2 - offsetX) * changeScale;
|
|
223
|
+
const imageNewCenterY = e.clientY + (imageBound.height / 2 - offsetY) * changeScale;
|
|
224
|
+
const containerCenterX = this.containerWidth / 2;
|
|
225
|
+
const containerCenterY = this.containerHeight / 2;
|
|
226
|
+
|
|
227
|
+
newTranslateX = imageNewCenterX - containerCenterX;
|
|
228
|
+
newTranslateY = imageNewCenterY - containerCenterY;
|
|
209
229
|
}
|
|
210
|
-
|
|
230
|
+
|
|
231
|
+
const newTranslate = this.getSafeTranslate(newImageBound.width, newImageBound.height, newTranslateX, newTranslateY);
|
|
232
|
+
|
|
211
233
|
this.setState({
|
|
234
|
+
translate: newTranslate,
|
|
212
235
|
width: newWidth,
|
|
213
236
|
height: newHeight,
|
|
214
|
-
offset: _offset,
|
|
215
|
-
left: newLeft,
|
|
216
|
-
top: newTop,
|
|
217
237
|
currZoom: newZoom,
|
|
218
238
|
} as any);
|
|
219
239
|
if (imageDOM) {
|
|
240
|
+
const { canDragVertical, canDragHorizontal } = this.getCanDragDirection(newImageBound.width, newImageBound.height);
|
|
241
|
+
const canDrag = canDragVertical || canDragHorizontal;
|
|
242
|
+
|
|
220
243
|
this._adapter.setImageCursor(canDrag);
|
|
221
244
|
}
|
|
222
245
|
};
|
|
223
246
|
|
|
224
|
-
|
|
225
|
-
const { width, height } = this.getStates();
|
|
226
|
-
const { width: containerWidth, height: containerHeight } = this._getContainerBounds();
|
|
227
|
-
let extremeLeft = containerWidth - width;
|
|
228
|
-
let extremeTop = containerHeight - height;
|
|
229
|
-
if (this._isImageVertical()) {
|
|
230
|
-
extremeLeft = containerWidth - height;
|
|
231
|
-
extremeTop = containerHeight - width;
|
|
232
|
-
}
|
|
247
|
+
getExtremeTranslate = (width: number, height: number): ExtremeTranslate => {
|
|
233
248
|
return {
|
|
234
|
-
|
|
235
|
-
|
|
249
|
+
x: (width - this.containerWidth) / 2,
|
|
250
|
+
y: (height - this.containerHeight) / 2,
|
|
236
251
|
};
|
|
237
252
|
};
|
|
238
253
|
|
|
239
|
-
|
|
240
|
-
const {
|
|
241
|
-
const { canDragVertical, canDragHorizontal } = this.
|
|
254
|
+
getSafeTranslate = (width: number, height: number, translateX: number, translateY: number) => {
|
|
255
|
+
const { x: extremeX, y: extremeY } = this.getExtremeTranslate(width, height);
|
|
256
|
+
const { canDragVertical, canDragHorizontal } = this.getCanDragDirection(width, height);
|
|
257
|
+
|
|
258
|
+
let newTranslateX = 0,
|
|
259
|
+
newTranslateY = 0;
|
|
260
|
+
|
|
261
|
+
if (canDragHorizontal) {
|
|
262
|
+
newTranslateX = translateX > 0 ? Math.min(translateX, extremeX) : Math.max(translateX, -extremeX);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (canDragVertical) {
|
|
266
|
+
newTranslateY = translateY > 0 ? Math.min(translateY, extremeY) : Math.max(translateY, -extremeY);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
x: newTranslateX,
|
|
271
|
+
y: newTranslateY
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
handleImageMove = (e: MouseEvent): void => {
|
|
242
276
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
243
277
|
const mouseLeftPress = e.buttons === 1;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
278
|
+
|
|
279
|
+
if (mouseLeftPress) {
|
|
280
|
+
this.moveImage(e);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
moveImage = (e: MouseEvent) => {
|
|
285
|
+
const { clientX, clientY } = e;
|
|
286
|
+
const { width, height, translate } = this.getStates();
|
|
287
|
+
const { rotation } = this.getProps();
|
|
288
|
+
const imageBound = this.calcBoundingRectSize(width, height, rotation);
|
|
289
|
+
const { canDragVertical, canDragHorizontal } = this.getCanDragDirection(imageBound.width, imageBound.height);
|
|
290
|
+
|
|
291
|
+
if (canDragVertical || canDragHorizontal) {
|
|
292
|
+
let newTranslateX = canDragHorizontal ? translate.x + clientX - this.startMouseClientPosition.x : translate.x;
|
|
293
|
+
let newTranslateY = canDragVertical ? translate.y + clientY - this.startMouseClientPosition.y : translate.y;
|
|
294
|
+
|
|
295
|
+
const newTranslate = this.getSafeTranslate(imageBound.width, imageBound.height, newTranslateX, newTranslateY);
|
|
296
|
+
|
|
260
297
|
this.setState({
|
|
261
|
-
|
|
262
|
-
left: this._isImageVertical() ? _offset.x - (width - height) / 2 : _offset.x,
|
|
263
|
-
top: this._isImageVertical() ? _offset.y + (width - height) / 2 : _offset.y,
|
|
298
|
+
translate: newTranslate,
|
|
264
299
|
} as any);
|
|
300
|
+
|
|
301
|
+
this.startMouseClientPosition = {
|
|
302
|
+
x: clientX,
|
|
303
|
+
y: clientY
|
|
304
|
+
};
|
|
265
305
|
}
|
|
266
306
|
};
|
|
267
307
|
|
|
268
308
|
handleImageMouseDown = (e: any): void => {
|
|
269
|
-
this.
|
|
309
|
+
this.startMouseClientPosition = {
|
|
310
|
+
x: e.clientX,
|
|
311
|
+
y: e.clientY
|
|
312
|
+
};
|
|
270
313
|
};
|
|
271
314
|
|
|
315
|
+
// 鼠标事件的 e.offset 是以 dom 旋转前左上角为零点的, 这个方法会转换为以旋转后元素的外接矩形左上角为零点的 offset
|
|
316
|
+
calcBoundingRectMouseOffset = (calcBoundingRectMouseOffset: CalcBoundingRectMouseOffset) => {
|
|
317
|
+
const {
|
|
318
|
+
width,
|
|
319
|
+
height,
|
|
320
|
+
offset,
|
|
321
|
+
rotation = 0
|
|
322
|
+
} = calcBoundingRectMouseOffset;
|
|
323
|
+
|
|
324
|
+
let degrees = rotation % 360;
|
|
325
|
+
degrees = degrees >= 0 ? degrees : 360 + degrees;
|
|
326
|
+
let boundOffsetX = 0,
|
|
327
|
+
boundOffsetY = 0;
|
|
328
|
+
|
|
329
|
+
switch (degrees) {
|
|
330
|
+
case 0:
|
|
331
|
+
boundOffsetX = offset.x;
|
|
332
|
+
boundOffsetY = offset.y;
|
|
333
|
+
break;
|
|
334
|
+
case 90:
|
|
335
|
+
boundOffsetX = height - offset.y;
|
|
336
|
+
boundOffsetY = offset.x;
|
|
337
|
+
break;
|
|
338
|
+
case 180:
|
|
339
|
+
boundOffsetX = width - offset.x;
|
|
340
|
+
boundOffsetY = height - offset.y;
|
|
341
|
+
break;
|
|
342
|
+
case 270:
|
|
343
|
+
boundOffsetX = offset.y;
|
|
344
|
+
boundOffsetY = width - offset.x;
|
|
345
|
+
break;
|
|
346
|
+
default:
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
x: boundOffsetX,
|
|
352
|
+
y: boundOffsetY
|
|
353
|
+
};
|
|
354
|
+
}
|
|
272
355
|
}
|
|
@@ -20,7 +20,8 @@ export interface PreviewInnerAdapter<P = Record<string, any>, S = Record<string,
|
|
|
20
20
|
disabledBodyScroll: () => void;
|
|
21
21
|
enabledBodyScroll: () => void;
|
|
22
22
|
getSetDownloadFunc: () => (src: string) => string;
|
|
23
|
-
isValidTarget: (e: any) => boolean
|
|
23
|
+
isValidTarget: (e: any) => boolean;
|
|
24
|
+
changeImageZoom: (zoom: number, e?: WheelEvent) => void
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
|
|
@@ -90,12 +91,12 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
handleWheel = (e:
|
|
94
|
+
handleWheel = (e: WheelEvent) => {
|
|
94
95
|
this.onWheel(e);
|
|
95
96
|
handlePrevent(e);
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
onWheel = (e:
|
|
99
|
+
onWheel = (e: WheelEvent): void => {
|
|
99
100
|
const { zoomStep, maxZoom, minZoom } = this.getProps();
|
|
100
101
|
const { zoom: currZoom } = this.getStates();
|
|
101
102
|
let _zoom: number;
|
|
@@ -111,7 +112,7 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
|
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
if (!isUndefined(_zoom)) {
|
|
114
|
-
this.handleZoomImage(_zoom);
|
|
115
|
+
this.handleZoomImage(_zoom, true, e);
|
|
115
116
|
}
|
|
116
117
|
};
|
|
117
118
|
|
|
@@ -193,17 +194,21 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
|
|
|
193
194
|
|
|
194
195
|
handleRotateImage = (direction: string) => {
|
|
195
196
|
const { rotation } = this.getStates();
|
|
196
|
-
const
|
|
197
|
+
const ROTATE_STEP = 90;
|
|
198
|
+
const newRotation = rotation + (direction === "left" ? -ROTATE_STEP : ROTATE_STEP);
|
|
199
|
+
|
|
197
200
|
this.setState({
|
|
198
201
|
rotation: newRotation,
|
|
199
202
|
} as any);
|
|
200
203
|
this._adapter.notifyRotateChange(newRotation);
|
|
201
204
|
}
|
|
202
205
|
|
|
203
|
-
handleZoomImage = (newZoom: number, notify: boolean = true) => {
|
|
206
|
+
handleZoomImage = (newZoom: number, notify: boolean = true, e?: WheelEvent) => {
|
|
204
207
|
const { zoom } = this.getStates();
|
|
205
208
|
if (zoom !== newZoom) {
|
|
206
209
|
notify && this._adapter.notifyZoom(newZoom, newZoom > zoom);
|
|
210
|
+
|
|
211
|
+
this._adapter.changeImageZoom(newZoom, e);
|
|
207
212
|
this.setState({
|
|
208
213
|
zoom: newZoom,
|
|
209
214
|
} as any);
|
|
@@ -153,6 +153,24 @@ class CalendarFoundation extends _foundation.default {
|
|
|
153
153
|
parsed.day = [];
|
|
154
154
|
}
|
|
155
155
|
parsed.day = parsed.day.map(item => (0, _eventUtil.renderDailyEvent)(item));
|
|
156
|
+
// 将 startPos & endPos 完全相同的事件编为一组
|
|
157
|
+
const sameTimeRangeGroup = parsed.day.reduce((acc, item) => {
|
|
158
|
+
const key = `${item.startPos}-${item.endPos}`;
|
|
159
|
+
if (!acc[key]) {
|
|
160
|
+
acc[key] = [];
|
|
161
|
+
}
|
|
162
|
+
acc[key].push(item);
|
|
163
|
+
return acc;
|
|
164
|
+
}, {});
|
|
165
|
+
// 计算每个 item 的 left 值,
|
|
166
|
+
const eventCountMap = {};
|
|
167
|
+
parsed.day = parsed.day.map(item => {
|
|
168
|
+
const key = `${item.startPos}-${item.endPos}`;
|
|
169
|
+
let curCount = eventCountMap[key];
|
|
170
|
+
eventCountMap[key] = curCount === undefined ? 0 : ++curCount;
|
|
171
|
+
item.left = curCount !== 0 ? `${curCount / sameTimeRangeGroup[key].length * 100}%` : 0;
|
|
172
|
+
return item;
|
|
173
|
+
});
|
|
156
174
|
return parsed;
|
|
157
175
|
}
|
|
158
176
|
parseDailyEvents() {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/// <reference types="lodash" />
|
|
3
2
|
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
4
3
|
export interface Content {
|
|
@@ -27,7 +26,7 @@ export interface Message {
|
|
|
27
26
|
[x: string]: any;
|
|
28
27
|
}
|
|
29
28
|
export interface ChatAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
30
|
-
getContainerRef: () =>
|
|
29
|
+
getContainerRef: () => HTMLDivElement;
|
|
31
30
|
setWheelScroll: (flag: boolean) => void;
|
|
32
31
|
notifyChatsChange: (chats: Message[]) => void;
|
|
33
32
|
notifyLikeMessage: (message: Message) => void;
|
|
@@ -33,16 +33,14 @@ class ChatFoundation extends _foundation.default {
|
|
|
33
33
|
this._adapter.notifyStopGenerate(e);
|
|
34
34
|
};
|
|
35
35
|
this.scrollToBottomImmediately = () => {
|
|
36
|
-
const
|
|
37
|
-
const element = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current;
|
|
36
|
+
const element = this._adapter.getContainerRef();
|
|
38
37
|
if (element) {
|
|
39
38
|
element.scrollTop = element.scrollHeight;
|
|
40
39
|
}
|
|
41
40
|
};
|
|
42
41
|
this.scrollToBottomWithAnimation = () => {
|
|
43
42
|
const duration = SCROLL_ANIMATION_TIME;
|
|
44
|
-
const
|
|
45
|
-
const element = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current;
|
|
43
|
+
const element = this._adapter.getContainerRef();
|
|
46
44
|
if (!element) {
|
|
47
45
|
return;
|
|
48
46
|
}
|
|
@@ -68,9 +66,6 @@ class ChatFoundation extends _foundation.default {
|
|
|
68
66
|
this.animation.start();
|
|
69
67
|
};
|
|
70
68
|
this.containerScroll = e => {
|
|
71
|
-
if (e.target !== e.currentTarget) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
69
|
e.persist();
|
|
75
70
|
const update = () => {
|
|
76
71
|
this.getScroll(e.target);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
2
|
+
import ColorPickerFoundation from "./foundation";
|
|
3
|
+
import { HsvaColor } from "./interface";
|
|
4
|
+
export interface AlphaSliderBaseProps {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
hsva: HsvaColor;
|
|
8
|
+
handleSize: number;
|
|
9
|
+
foundation: ColorPickerFoundation;
|
|
10
|
+
}
|
|
11
|
+
export interface AlphaSliderBaseState {
|
|
12
|
+
handlePosition: number;
|
|
13
|
+
isHandleGrabbing: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface AlphaSliderAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
16
|
+
handleMouseDown: (e: any) => void;
|
|
17
|
+
handleMouseUp: (e: any) => void;
|
|
18
|
+
getColorPickerFoundation: () => ColorPickerFoundation;
|
|
19
|
+
getDOM: () => HTMLDivElement;
|
|
20
|
+
}
|
|
21
|
+
declare class AlphaSliderFoundation extends BaseFoundation<AlphaSliderAdapter<AlphaSliderBaseProps, AlphaSliderBaseState>, AlphaSliderBaseProps, AlphaSliderBaseState> {
|
|
22
|
+
constructor(adapter: AlphaSliderAdapter<AlphaSliderBaseProps, AlphaSliderBaseState>);
|
|
23
|
+
handleMouseDown: (e: any) => void;
|
|
24
|
+
handleMouseUp: (e: any) => void;
|
|
25
|
+
setHandlePositionByMousePosition: (e: MouseEvent) => void;
|
|
26
|
+
}
|
|
27
|
+
export default AlphaSliderFoundation;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
class AlphaSliderFoundation extends _foundation.default {
|
|
10
|
+
constructor(adapter) {
|
|
11
|
+
super(Object.assign({}, adapter));
|
|
12
|
+
this.handleMouseDown = e => {
|
|
13
|
+
this._adapter.handleMouseDown(e);
|
|
14
|
+
};
|
|
15
|
+
this.handleMouseUp = e => {
|
|
16
|
+
this._adapter.handleMouseUp(e);
|
|
17
|
+
};
|
|
18
|
+
this.setHandlePositionByMousePosition = e => {
|
|
19
|
+
var _a;
|
|
20
|
+
const rect = (_a = this._adapter.getDOM()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
21
|
+
if (!rect) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const {
|
|
25
|
+
width,
|
|
26
|
+
handleSize
|
|
27
|
+
} = this._adapter.getProps();
|
|
28
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
29
|
+
const mousePosition = e.clientX - rect.x;
|
|
30
|
+
const handlePosition = colorPickerFoundation.getAlphaHandlePositionByMousePosition(mousePosition, width, handleSize);
|
|
31
|
+
colorPickerFoundation.handleAlphaChangeByHandle({
|
|
32
|
+
a: Number(Math.min(Math.max(mousePosition / width, 0), 1).toFixed(2))
|
|
33
|
+
});
|
|
34
|
+
this.setState({
|
|
35
|
+
handlePosition
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var _default = exports.default = AlphaSliderFoundation;
|