@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
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
import BaseFoundation from "../base/foundation";
|
|
2
|
-
const DefaultDOMRect = {
|
|
3
|
-
bottom: 0,
|
|
4
|
-
height: 0,
|
|
5
|
-
left: 0,
|
|
6
|
-
right: 0,
|
|
7
|
-
top: 0,
|
|
8
|
-
width: 0,
|
|
9
|
-
x: 0,
|
|
10
|
-
y: 0,
|
|
11
|
-
toJSON: () => ({})
|
|
12
|
-
};
|
|
13
2
|
export default class PreviewImageFoundation extends BaseFoundation {
|
|
14
3
|
constructor(adapter) {
|
|
15
4
|
var _this;
|
|
16
5
|
super(Object.assign({}, adapter));
|
|
17
6
|
_this = this;
|
|
18
|
-
this.
|
|
7
|
+
this.startMouseClientPosition = {
|
|
19
8
|
x: 0,
|
|
20
9
|
y: 0
|
|
21
10
|
};
|
|
22
11
|
this.originImageWidth = null;
|
|
23
12
|
this.originImageHeight = null;
|
|
13
|
+
this.containerWidth = 0;
|
|
14
|
+
this.containerHeight = 0;
|
|
24
15
|
this._isImageVertical = () => this.getProp("rotation") % 180 !== 0;
|
|
25
|
-
this.
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
16
|
+
this._getContainerBoundingRectSize = () => {
|
|
17
|
+
const containerDOM = this._adapter.getContainer();
|
|
18
|
+
if (containerDOM) {
|
|
19
|
+
this.containerWidth = containerDOM.clientWidth;
|
|
20
|
+
this.containerHeight = containerDOM.clientHeight;
|
|
29
21
|
}
|
|
30
|
-
return DefaultDOMRect;
|
|
31
22
|
};
|
|
32
|
-
this.
|
|
23
|
+
this._getAdaptationZoom = () => {
|
|
24
|
+
let _zoom = 1;
|
|
33
25
|
const containerDOM = this._adapter.getContainer();
|
|
34
|
-
if (containerDOM) {
|
|
35
|
-
|
|
26
|
+
if (containerDOM && this.originImageWidth && this.originImageHeight) {
|
|
27
|
+
const {
|
|
28
|
+
rotation
|
|
29
|
+
} = this.getProps();
|
|
30
|
+
const {
|
|
31
|
+
width: imageWidth,
|
|
32
|
+
height: imageHeight
|
|
33
|
+
} = this.calcBoundingRectSize(this.originImageWidth, this.originImageHeight, rotation);
|
|
34
|
+
const reservedWidth = this.containerWidth - 80;
|
|
35
|
+
const reservedHeight = this.containerHeight - 80;
|
|
36
|
+
_zoom = Number(Math.min(reservedWidth / imageWidth, reservedHeight / imageHeight).toFixed(2));
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
+
return _zoom;
|
|
38
39
|
};
|
|
39
|
-
this.
|
|
40
|
+
this._getInitialZoom = () => {
|
|
40
41
|
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
ratio
|
|
43
|
+
} = this.getProps();
|
|
44
|
+
let _zoom = 1;
|
|
45
|
+
if (ratio === 'adaptation') {
|
|
46
|
+
_zoom = this._getAdaptationZoom();
|
|
47
|
+
}
|
|
48
|
+
return _zoom;
|
|
48
49
|
};
|
|
49
50
|
this.setLoading = loading => {
|
|
50
51
|
this._adapter.setLoading(loading);
|
|
51
52
|
};
|
|
52
53
|
this.handleWindowResize = () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
54
|
+
this._getContainerBoundingRectSize();
|
|
55
|
+
this.initializeImage();
|
|
56
56
|
};
|
|
57
57
|
this.handleLoad = e => {
|
|
58
58
|
if (e.target) {
|
|
@@ -67,7 +67,7 @@ export default class PreviewImageFoundation extends BaseFoundation {
|
|
|
67
67
|
});
|
|
68
68
|
// 图片初次加载,计算 zoom,zoom 改变不需要通过回调透出
|
|
69
69
|
// When the image is loaded for the first time, zoom is calculated, and zoom changes do not need to be exposed through callbacks.
|
|
70
|
-
this.
|
|
70
|
+
this.initializeImage(false);
|
|
71
71
|
}
|
|
72
72
|
const {
|
|
73
73
|
src,
|
|
@@ -85,66 +85,36 @@ export default class PreviewImageFoundation extends BaseFoundation {
|
|
|
85
85
|
});
|
|
86
86
|
onError && onError(src);
|
|
87
87
|
};
|
|
88
|
-
this.
|
|
88
|
+
this.handleRatioChange = () => {
|
|
89
|
+
this.initializeImage();
|
|
90
|
+
};
|
|
91
|
+
this.initializeImageZoom = function () {
|
|
89
92
|
let notify = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
90
|
-
const horizontal = !_this._isImageVertical();
|
|
91
93
|
const {
|
|
92
94
|
currZoom
|
|
93
95
|
} = _this.getStates();
|
|
94
|
-
const imgWidth = horizontal ? _this.originImageWidth : _this.originImageHeight;
|
|
95
|
-
const imgHeight = horizontal ? _this.originImageHeight : _this.originImageWidth;
|
|
96
96
|
const {
|
|
97
|
-
onZoom
|
|
98
|
-
setRatio,
|
|
99
|
-
ratio
|
|
97
|
+
onZoom
|
|
100
98
|
} = _this.getProps();
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} = _this._getContainerBounds();
|
|
107
|
-
const reservedWidth = containerWidth - 80;
|
|
108
|
-
const reservedHeight = containerHeight - 80;
|
|
109
|
-
let _zoom = 1;
|
|
110
|
-
if (imgWidth > reservedWidth || imgHeight > reservedHeight) {
|
|
111
|
-
_zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
|
|
112
|
-
}
|
|
113
|
-
if (currZoom === _zoom) {
|
|
114
|
-
_this.calculatePreviewImage(_zoom, null);
|
|
115
|
-
} else {
|
|
116
|
-
onZoom(_zoom, notify);
|
|
117
|
-
}
|
|
99
|
+
const _zoom = _this._getInitialZoom();
|
|
100
|
+
if (currZoom !== _zoom) {
|
|
101
|
+
onZoom(_zoom, notify);
|
|
102
|
+
} else {
|
|
103
|
+
_this.changeZoom(_zoom);
|
|
118
104
|
}
|
|
119
105
|
};
|
|
120
|
-
this.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const {
|
|
126
|
-
ratio,
|
|
127
|
-
onZoom
|
|
128
|
-
} = this.getProps();
|
|
129
|
-
let _zoom;
|
|
130
|
-
if (ratio === 'adaptation') {
|
|
131
|
-
const horizontal = !this._isImageVertical();
|
|
132
|
-
const imgWidth = horizontal ? this.originImageWidth : this.originImageHeight;
|
|
133
|
-
const imgHeight = horizontal ? this.originImageHeight : this.originImageWidth;
|
|
134
|
-
const {
|
|
135
|
-
width: containerWidth,
|
|
136
|
-
height: containerHeight
|
|
137
|
-
} = this._getContainerBounds();
|
|
138
|
-
const reservedWidth = containerWidth - 80;
|
|
139
|
-
const reservedHeight = containerHeight - 80;
|
|
140
|
-
_zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
|
|
141
|
-
} else {
|
|
142
|
-
_zoom = 1;
|
|
143
|
-
}
|
|
144
|
-
if (currZoom !== _zoom) {
|
|
145
|
-
onZoom(_zoom);
|
|
106
|
+
this.initializeTranslate = () => {
|
|
107
|
+
this.setState({
|
|
108
|
+
translate: {
|
|
109
|
+
x: 0,
|
|
110
|
+
y: 0
|
|
146
111
|
}
|
|
147
|
-
}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
this.initializeImage = function () {
|
|
115
|
+
let notify = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
116
|
+
_this.initializeImageZoom(notify);
|
|
117
|
+
_this.initializeTranslate();
|
|
148
118
|
};
|
|
149
119
|
this.handleRightClickImage = e => {
|
|
150
120
|
const {
|
|
@@ -158,140 +128,196 @@ export default class PreviewImageFoundation extends BaseFoundation {
|
|
|
158
128
|
return true;
|
|
159
129
|
}
|
|
160
130
|
};
|
|
161
|
-
this.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
height
|
|
165
|
-
} = this.getStates();
|
|
166
|
-
const {
|
|
167
|
-
rotation
|
|
168
|
-
} = this.getProps();
|
|
169
|
-
const {
|
|
170
|
-
width: containerWidth,
|
|
171
|
-
height: containerHeight
|
|
172
|
-
} = this._getContainerBounds();
|
|
173
|
-
let canDragHorizontal = width > containerWidth;
|
|
174
|
-
let canDragVertical = height > containerHeight;
|
|
175
|
-
if (this._isImageVertical()) {
|
|
176
|
-
canDragHorizontal = height > containerWidth;
|
|
177
|
-
canDragVertical = width > containerHeight;
|
|
178
|
-
}
|
|
131
|
+
this.getCanDragDirection = (width, height) => {
|
|
132
|
+
let canDragHorizontal = width > this.containerWidth;
|
|
133
|
+
let canDragVertical = height > this.containerHeight;
|
|
179
134
|
return {
|
|
180
135
|
canDragVertical,
|
|
181
136
|
canDragHorizontal
|
|
182
137
|
};
|
|
183
138
|
};
|
|
184
|
-
this.
|
|
139
|
+
this.changeZoom = (newZoom, e) => {
|
|
185
140
|
const imageDOM = this._adapter.getImage();
|
|
186
141
|
const {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
142
|
+
currZoom,
|
|
143
|
+
translate,
|
|
144
|
+
width,
|
|
145
|
+
height
|
|
146
|
+
} = this.getStates();
|
|
191
147
|
const {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
148
|
+
rotation
|
|
149
|
+
} = this.getProps();
|
|
150
|
+
const changeScale = newZoom / (currZoom || 1);
|
|
195
151
|
const newWidth = Math.floor(this.originImageWidth * newZoom);
|
|
196
152
|
const newHeight = Math.floor(this.originImageHeight * newZoom);
|
|
197
|
-
|
|
198
|
-
let
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
153
|
+
let newTranslateX = Math.floor(translate.x * changeScale);
|
|
154
|
+
let newTranslateY = Math.floor(translate.y * changeScale);
|
|
155
|
+
const imageBound = this.calcBoundingRectSize(width, height, rotation);
|
|
156
|
+
const newImageBound = {
|
|
157
|
+
width: imageBound.width * changeScale,
|
|
158
|
+
height: imageBound.height * changeScale
|
|
159
|
+
};
|
|
160
|
+
if (e && imageDOM && e.target === imageDOM) {
|
|
161
|
+
const {
|
|
162
|
+
x: offsetX,
|
|
163
|
+
y: offsetY
|
|
164
|
+
} = this.calcBoundingRectMouseOffset({
|
|
165
|
+
width,
|
|
166
|
+
height,
|
|
167
|
+
offset: {
|
|
168
|
+
x: e.offsetX,
|
|
169
|
+
y: e.offsetY
|
|
170
|
+
},
|
|
171
|
+
rotation
|
|
172
|
+
});
|
|
173
|
+
const imageNewCenterX = e.clientX + (imageBound.width / 2 - offsetX) * changeScale;
|
|
174
|
+
const imageNewCenterY = e.clientY + (imageBound.height / 2 - offsetY) * changeScale;
|
|
175
|
+
const containerCenterX = this.containerWidth / 2;
|
|
176
|
+
const containerCenterY = this.containerHeight / 2;
|
|
177
|
+
newTranslateX = imageNewCenterX - containerCenterX;
|
|
178
|
+
newTranslateY = imageNewCenterY - containerCenterY;
|
|
216
179
|
}
|
|
180
|
+
const newTranslate = this.getSafeTranslate(newImageBound.width, newImageBound.height, newTranslateX, newTranslateY);
|
|
217
181
|
this.setState({
|
|
182
|
+
translate: newTranslate,
|
|
218
183
|
width: newWidth,
|
|
219
184
|
height: newHeight,
|
|
220
|
-
offset: _offset,
|
|
221
|
-
left: newLeft,
|
|
222
|
-
top: newTop,
|
|
223
185
|
currZoom: newZoom
|
|
224
186
|
});
|
|
225
187
|
if (imageDOM) {
|
|
188
|
+
const {
|
|
189
|
+
canDragVertical,
|
|
190
|
+
canDragHorizontal
|
|
191
|
+
} = this.getCanDragDirection(newImageBound.width, newImageBound.height);
|
|
192
|
+
const canDrag = canDragVertical || canDragHorizontal;
|
|
226
193
|
this._adapter.setImageCursor(canDrag);
|
|
227
194
|
}
|
|
228
195
|
};
|
|
229
|
-
this.
|
|
196
|
+
this.getExtremeTranslate = (width, height) => {
|
|
197
|
+
return {
|
|
198
|
+
x: (width - this.containerWidth) / 2,
|
|
199
|
+
y: (height - this.containerHeight) / 2
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
this.getSafeTranslate = (width, height, translateX, translateY) => {
|
|
230
203
|
const {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} = this.
|
|
204
|
+
x: extremeX,
|
|
205
|
+
y: extremeY
|
|
206
|
+
} = this.getExtremeTranslate(width, height);
|
|
234
207
|
const {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
} = this.
|
|
238
|
-
let
|
|
239
|
-
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
208
|
+
canDragVertical,
|
|
209
|
+
canDragHorizontal
|
|
210
|
+
} = this.getCanDragDirection(width, height);
|
|
211
|
+
let newTranslateX = 0,
|
|
212
|
+
newTranslateY = 0;
|
|
213
|
+
if (canDragHorizontal) {
|
|
214
|
+
newTranslateX = translateX > 0 ? Math.min(translateX, extremeX) : Math.max(translateX, -extremeX);
|
|
215
|
+
}
|
|
216
|
+
if (canDragVertical) {
|
|
217
|
+
newTranslateY = translateY > 0 ? Math.min(translateY, extremeY) : Math.max(translateY, -extremeY);
|
|
243
218
|
}
|
|
244
219
|
return {
|
|
245
|
-
|
|
246
|
-
|
|
220
|
+
x: newTranslateX,
|
|
221
|
+
y: newTranslateY
|
|
247
222
|
};
|
|
248
223
|
};
|
|
249
|
-
this.
|
|
224
|
+
this.handleImageMove = e => {
|
|
225
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
226
|
+
const mouseLeftPress = e.buttons === 1;
|
|
227
|
+
if (mouseLeftPress) {
|
|
228
|
+
this.moveImage(e);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
this.moveImage = e => {
|
|
232
|
+
const {
|
|
233
|
+
clientX,
|
|
234
|
+
clientY
|
|
235
|
+
} = e;
|
|
250
236
|
const {
|
|
251
|
-
offset,
|
|
252
237
|
width,
|
|
253
|
-
height
|
|
238
|
+
height,
|
|
239
|
+
translate
|
|
254
240
|
} = this.getStates();
|
|
241
|
+
const {
|
|
242
|
+
rotation
|
|
243
|
+
} = this.getProps();
|
|
244
|
+
const imageBound = this.calcBoundingRectSize(width, height, rotation);
|
|
255
245
|
const {
|
|
256
246
|
canDragVertical,
|
|
257
247
|
canDragHorizontal
|
|
258
|
-
} = this.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
clientX,
|
|
264
|
-
clientY
|
|
265
|
-
} = e;
|
|
266
|
-
const {
|
|
267
|
-
left: containerLeft,
|
|
268
|
-
top: containerTop
|
|
269
|
-
} = this._getContainerBounds();
|
|
270
|
-
const {
|
|
271
|
-
left: extremeLeft,
|
|
272
|
-
top: extremeTop
|
|
273
|
-
} = this.calcExtremeBounds();
|
|
274
|
-
let newX = canDragHorizontal ? clientX - containerLeft - this.startMouseOffset.x : offset.x;
|
|
275
|
-
let newY = canDragVertical ? clientY - containerTop - this.startMouseOffset.y : offset.y;
|
|
276
|
-
if (canDragHorizontal) {
|
|
277
|
-
newX = newX > 0 ? 0 : newX < extremeLeft ? extremeLeft : newX;
|
|
278
|
-
}
|
|
279
|
-
if (canDragVertical) {
|
|
280
|
-
newY = newY > 0 ? 0 : newY < extremeTop ? extremeTop : newY;
|
|
281
|
-
}
|
|
282
|
-
const _offset = {
|
|
283
|
-
x: newX,
|
|
284
|
-
y: newY
|
|
285
|
-
};
|
|
248
|
+
} = this.getCanDragDirection(imageBound.width, imageBound.height);
|
|
249
|
+
if (canDragVertical || canDragHorizontal) {
|
|
250
|
+
let newTranslateX = canDragHorizontal ? translate.x + clientX - this.startMouseClientPosition.x : translate.x;
|
|
251
|
+
let newTranslateY = canDragVertical ? translate.y + clientY - this.startMouseClientPosition.y : translate.y;
|
|
252
|
+
const newTranslate = this.getSafeTranslate(imageBound.width, imageBound.height, newTranslateX, newTranslateY);
|
|
286
253
|
this.setState({
|
|
287
|
-
|
|
288
|
-
left: this._isImageVertical() ? _offset.x - (width - height) / 2 : _offset.x,
|
|
289
|
-
top: this._isImageVertical() ? _offset.y + (width - height) / 2 : _offset.y
|
|
254
|
+
translate: newTranslate
|
|
290
255
|
});
|
|
256
|
+
this.startMouseClientPosition = {
|
|
257
|
+
x: clientX,
|
|
258
|
+
y: clientY
|
|
259
|
+
};
|
|
291
260
|
}
|
|
292
261
|
};
|
|
293
262
|
this.handleImageMouseDown = e => {
|
|
294
|
-
this.
|
|
263
|
+
this.startMouseClientPosition = {
|
|
264
|
+
x: e.clientX,
|
|
265
|
+
y: e.clientY
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
// 鼠标事件的 e.offset 是以 dom 旋转前左上角为零点的, 这个方法会转换为以旋转后元素的外接矩形左上角为零点的 offset
|
|
269
|
+
this.calcBoundingRectMouseOffset = calcBoundingRectMouseOffset => {
|
|
270
|
+
const {
|
|
271
|
+
width,
|
|
272
|
+
height,
|
|
273
|
+
offset,
|
|
274
|
+
rotation = 0
|
|
275
|
+
} = calcBoundingRectMouseOffset;
|
|
276
|
+
let degrees = rotation % 360;
|
|
277
|
+
degrees = degrees >= 0 ? degrees : 360 + degrees;
|
|
278
|
+
let boundOffsetX = 0,
|
|
279
|
+
boundOffsetY = 0;
|
|
280
|
+
switch (degrees) {
|
|
281
|
+
case 0:
|
|
282
|
+
boundOffsetX = offset.x;
|
|
283
|
+
boundOffsetY = offset.y;
|
|
284
|
+
break;
|
|
285
|
+
case 90:
|
|
286
|
+
boundOffsetX = height - offset.y;
|
|
287
|
+
boundOffsetY = offset.x;
|
|
288
|
+
break;
|
|
289
|
+
case 180:
|
|
290
|
+
boundOffsetX = width - offset.x;
|
|
291
|
+
boundOffsetY = height - offset.y;
|
|
292
|
+
break;
|
|
293
|
+
case 270:
|
|
294
|
+
boundOffsetX = offset.y;
|
|
295
|
+
boundOffsetY = width - offset.x;
|
|
296
|
+
break;
|
|
297
|
+
default:
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
x: boundOffsetX,
|
|
302
|
+
y: boundOffsetY
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
init() {
|
|
307
|
+
this._getContainerBoundingRectSize();
|
|
308
|
+
}
|
|
309
|
+
calcBoundingRectSize() {
|
|
310
|
+
let width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
311
|
+
let height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
312
|
+
let rotation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
313
|
+
const angleInRadians = rotation * Math.PI / 180;
|
|
314
|
+
const sinTheta = Math.abs(Math.sin(angleInRadians));
|
|
315
|
+
const cosTheta = Math.abs(Math.cos(angleInRadians));
|
|
316
|
+
const boundingWidth = width * cosTheta + height * sinTheta;
|
|
317
|
+
const boundingHeight = width * sinTheta + height * cosTheta;
|
|
318
|
+
return {
|
|
319
|
+
width: boundingWidth,
|
|
320
|
+
height: boundingHeight
|
|
295
321
|
};
|
|
296
322
|
}
|
|
297
323
|
}
|
|
@@ -17,6 +17,7 @@ export interface PreviewInnerAdapter<P = Record<string, any>, S = Record<string,
|
|
|
17
17
|
enabledBodyScroll: () => void;
|
|
18
18
|
getSetDownloadFunc: () => (src: string) => string;
|
|
19
19
|
isValidTarget: (e: any) => boolean;
|
|
20
|
+
changeImageZoom: (zoom: number, e?: WheelEvent) => void;
|
|
20
21
|
}
|
|
21
22
|
export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<PreviewInnerAdapter<P, S>, P, S> {
|
|
22
23
|
constructor(adapter: PreviewInnerAdapter<P, S>);
|
|
@@ -32,8 +33,8 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
|
|
|
32
33
|
mouseMoveHandler: import("lodash").DebouncedFuncLeading<(e: any) => void>;
|
|
33
34
|
updateTimer: () => void;
|
|
34
35
|
clearTimer: () => void;
|
|
35
|
-
handleWheel: (e:
|
|
36
|
-
onWheel: (e:
|
|
36
|
+
handleWheel: (e: WheelEvent) => void;
|
|
37
|
+
onWheel: (e: WheelEvent) => void;
|
|
37
38
|
handleMouseUp: (e: any) => void;
|
|
38
39
|
handleMouseDown: (e: any) => void;
|
|
39
40
|
handleKeyDown: (e: any) => void;
|
|
@@ -42,7 +43,7 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
|
|
|
42
43
|
handlePreviewClose: (e: any) => void;
|
|
43
44
|
handleAdjustRatio: (type: RatioType) => void;
|
|
44
45
|
handleRotateImage: (direction: string) => void;
|
|
45
|
-
handleZoomImage: (newZoom: number, notify?: boolean) => void;
|
|
46
|
+
handleZoomImage: (newZoom: number, notify?: boolean, e?: WheelEvent) => void;
|
|
46
47
|
preloadGapImage: () => void;
|
|
47
48
|
preloadSingleImage: () => void;
|
|
48
49
|
setLoadSuccessStatus: (src: string) => void;
|
|
@@ -86,7 +86,7 @@ export default class PreviewInnerFoundation extends BaseFoundation {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
if (!_isUndefined(_zoom)) {
|
|
89
|
-
this.handleZoomImage(_zoom);
|
|
89
|
+
this.handleZoomImage(_zoom, true, e);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
this.handleMouseUp = e => {
|
|
@@ -184,7 +184,8 @@ export default class PreviewInnerFoundation extends BaseFoundation {
|
|
|
184
184
|
const {
|
|
185
185
|
rotation
|
|
186
186
|
} = this.getStates();
|
|
187
|
-
const
|
|
187
|
+
const ROTATE_STEP = 90;
|
|
188
|
+
const newRotation = rotation + (direction === "left" ? -ROTATE_STEP : ROTATE_STEP);
|
|
188
189
|
this.setState({
|
|
189
190
|
rotation: newRotation
|
|
190
191
|
});
|
|
@@ -192,11 +193,13 @@ export default class PreviewInnerFoundation extends BaseFoundation {
|
|
|
192
193
|
};
|
|
193
194
|
this.handleZoomImage = function (newZoom) {
|
|
194
195
|
let notify = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
196
|
+
let e = arguments.length > 2 ? arguments[2] : undefined;
|
|
195
197
|
const {
|
|
196
198
|
zoom
|
|
197
199
|
} = _this.getStates();
|
|
198
200
|
if (zoom !== newZoom) {
|
|
199
201
|
notify && _this._adapter.notifyZoom(newZoom, newZoom > zoom);
|
|
202
|
+
_this._adapter.changeImageZoom(newZoom, e);
|
|
200
203
|
_this.setState({
|
|
201
204
|
zoom: newZoom
|
|
202
205
|
});
|
|
@@ -80,6 +80,7 @@ export interface UploadAdapter<P = Record<string, any>, S = Record<string, any>>
|
|
|
80
80
|
notifyPastingError: (error: Error | PermissionStatus) => void;
|
|
81
81
|
}
|
|
82
82
|
declare class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<UploadAdapter<P, S>, P, S> {
|
|
83
|
+
destroyState: boolean;
|
|
83
84
|
constructor(adapter: UploadAdapter<P, S>);
|
|
84
85
|
init(): void;
|
|
85
86
|
destroy(): void;
|
|
@@ -43,6 +43,7 @@ const {
|
|
|
43
43
|
class UploadFoundation extends BaseFoundation {
|
|
44
44
|
constructor(adapter) {
|
|
45
45
|
super(Object.assign({}, adapter));
|
|
46
|
+
this.destroyState = false;
|
|
46
47
|
}
|
|
47
48
|
init() {
|
|
48
49
|
const {
|
|
@@ -62,6 +63,7 @@ class UploadFoundation extends BaseFoundation {
|
|
|
62
63
|
if (!disabled) {
|
|
63
64
|
this.unbindPastingHandler();
|
|
64
65
|
}
|
|
66
|
+
this.destroyState = true;
|
|
65
67
|
}
|
|
66
68
|
getError(_ref) {
|
|
67
69
|
let {
|
|
@@ -570,22 +572,36 @@ class UploadFoundation extends BaseFoundation {
|
|
|
570
572
|
xhr.withCredentials = true;
|
|
571
573
|
}
|
|
572
574
|
if (xhr.upload) {
|
|
573
|
-
xhr.upload.onprogress = e =>
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
575
|
+
xhr.upload.onprogress = e => {
|
|
576
|
+
if (!this.destroyState) {
|
|
577
|
+
this.handleProgress({
|
|
578
|
+
e,
|
|
579
|
+
fileInstance
|
|
580
|
+
});
|
|
581
|
+
} else {
|
|
582
|
+
xhr.abort();
|
|
583
|
+
}
|
|
584
|
+
};
|
|
577
585
|
}
|
|
578
586
|
// Callback function after upload is completed
|
|
579
|
-
xhr.onload = e =>
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
587
|
+
xhr.onload = e => {
|
|
588
|
+
if (!this.destroyState) {
|
|
589
|
+
this.handleOnLoad({
|
|
590
|
+
e,
|
|
591
|
+
xhr,
|
|
592
|
+
fileInstance
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
xhr.onerror = e => {
|
|
597
|
+
if (!this.destroyState) {
|
|
598
|
+
this.handleError({
|
|
599
|
+
e,
|
|
600
|
+
xhr,
|
|
601
|
+
fileInstance
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
};
|
|
589
605
|
// add headers
|
|
590
606
|
let headers = option.headers || {};
|
|
591
607
|
if (typeof headers === 'function') {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.64.0-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
7
7
|
"prepublishOnly": "npm run build:lib"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@douyinfe/semi-animation": "2.
|
|
10
|
+
"@douyinfe/semi-animation": "2.64.0-beta.0",
|
|
11
11
|
"@mdx-js/mdx": "^3.0.1",
|
|
12
12
|
"async-validator": "^3.5.0",
|
|
13
13
|
"classnames": "^2.2.6",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"*.scss",
|
|
29
29
|
"*.css"
|
|
30
30
|
],
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "57ca3b4704969aa7ea94d4b1ec7d45024ecd61d6",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
34
34
|
"@babel/preset-env": "^7.15.8",
|