@douyinfe/semi-foundation 2.20.0-beta.0 → 2.20.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.
Files changed (57) hide show
  1. package/calendar/foundation.ts +1 -2
  2. package/datePicker/foundation.ts +6 -5
  3. package/datePicker/monthsGridFoundation.ts +6 -6
  4. package/datePicker/yearAndMonthFoundation.ts +2 -2
  5. package/form/form.scss +14 -0
  6. package/image/image.scss +3 -0
  7. package/image/{imageFoundation.tsx → imageFoundation.ts} +0 -0
  8. package/image/{previewFooterFoundation.tsx → previewFooterFoundation.ts} +0 -0
  9. package/image/{previewFoundation.tsx → previewFoundation.ts} +0 -0
  10. package/image/{previewImageFoundation.tsx → previewImageFoundation.ts} +5 -5
  11. package/image/{previewInnerFoundation.tsx → previewInnerFoundation.ts} +5 -1
  12. package/image/utils.ts +5 -3
  13. package/lib/cjs/calendar/foundation.d.ts +2 -1
  14. package/lib/cjs/datePicker/foundation.d.ts +4 -4
  15. package/lib/cjs/datePicker/monthsGridFoundation.d.ts +2 -3
  16. package/lib/cjs/datePicker/yearAndMonthFoundation.d.ts +2 -3
  17. package/lib/cjs/form/form.css +8 -0
  18. package/lib/cjs/form/form.scss +14 -0
  19. package/lib/cjs/image/image.css +3 -0
  20. package/lib/cjs/image/image.scss +3 -0
  21. package/lib/cjs/image/imageFoundation.d.ts +11 -0
  22. package/lib/cjs/image/imageFoundation.js +89 -0
  23. package/lib/cjs/image/previewFooterFoundation.d.ts +10 -0
  24. package/lib/cjs/image/previewFooterFoundation.js +69 -0
  25. package/lib/cjs/image/previewFoundation.d.ts +5 -0
  26. package/lib/cjs/image/previewFoundation.js +49 -0
  27. package/lib/cjs/image/previewImageFoundation.d.ts +58 -0
  28. package/lib/cjs/image/previewImageFoundation.js +367 -0
  29. package/lib/cjs/image/previewInnerFoundation.d.ts +44 -0
  30. package/lib/cjs/image/previewInnerFoundation.js +341 -0
  31. package/lib/cjs/image/utils.js +5 -5
  32. package/lib/cjs/navigation/foundation.d.ts +0 -1
  33. package/lib/cjs/navigation/foundation.js +1 -11
  34. package/lib/es/calendar/foundation.d.ts +2 -1
  35. package/lib/es/datePicker/foundation.d.ts +4 -4
  36. package/lib/es/datePicker/monthsGridFoundation.d.ts +2 -3
  37. package/lib/es/datePicker/yearAndMonthFoundation.d.ts +2 -3
  38. package/lib/es/form/form.css +8 -0
  39. package/lib/es/form/form.scss +14 -0
  40. package/lib/es/image/image.css +3 -0
  41. package/lib/es/image/image.scss +3 -0
  42. package/lib/es/image/imageFoundation.d.ts +11 -0
  43. package/lib/es/image/imageFoundation.js +76 -0
  44. package/lib/es/image/previewFooterFoundation.d.ts +10 -0
  45. package/lib/es/image/previewFooterFoundation.js +57 -0
  46. package/lib/es/image/previewFoundation.d.ts +5 -0
  47. package/lib/es/image/previewFoundation.js +37 -0
  48. package/lib/es/image/previewImageFoundation.d.ts +58 -0
  49. package/lib/es/image/previewImageFoundation.js +352 -0
  50. package/lib/es/image/previewInnerFoundation.d.ts +44 -0
  51. package/lib/es/image/previewInnerFoundation.js +326 -0
  52. package/lib/es/image/utils.js +5 -5
  53. package/lib/es/navigation/foundation.d.ts +0 -1
  54. package/lib/es/navigation/foundation.js +1 -11
  55. package/navigation/foundation.ts +2 -9
  56. package/package.json +2 -2
  57. package/tree/treeUtil.ts +1 -1
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
9
+
10
+ var _throttle2 = _interopRequireDefault(require("lodash/throttle"));
11
+
12
+ var _foundation = _interopRequireDefault(require("../base/foundation"));
13
+
14
+ var _a11y = require("../utils/a11y");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ class PreviewImageFoundation extends _foundation.default {
19
+ constructor(adapter) {
20
+ super(Object.assign({}, adapter));
21
+
22
+ this._isImageVertical = () => this.getProp("rotation") % 180 !== 0;
23
+
24
+ this._getImageBounds = () => {
25
+ const imageRef = this._adapter.getImageRef();
26
+
27
+ return imageRef === null || imageRef === void 0 ? void 0 : imageRef.getBoundingClientRect();
28
+ };
29
+
30
+ this._getContainerBounds = () => {
31
+ var _a;
32
+
33
+ const containerRef = this._adapter.getContainerRef();
34
+
35
+ return (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
36
+ };
37
+
38
+ this._getOffset = e => {
39
+ const {
40
+ left,
41
+ top
42
+ } = this._getImageBounds();
43
+
44
+ return {
45
+ x: e.clientX - left,
46
+ y: e.clientY - top
47
+ };
48
+ };
49
+
50
+ this.setLoading = loading => {
51
+ this._adapter.setLoading(loading);
52
+ };
53
+
54
+ this.handleWindowResize = () => {
55
+ const {
56
+ setRatio
57
+ } = this.getProps();
58
+ const {
59
+ ratio
60
+ } = this.getProps();
61
+
62
+ const {
63
+ originImageWidth,
64
+ originImageHeight
65
+ } = this._adapter.getOriginImageSize();
66
+
67
+ if (originImageWidth && originImageHeight) {
68
+ if (ratio !== "adaptation") {
69
+ setRatio("adaptation");
70
+ } else {
71
+ this.handleResizeImage();
72
+ }
73
+ }
74
+ };
75
+
76
+ this.handleLoad = e => {
77
+ if (e.target) {
78
+ const {
79
+ width: w,
80
+ height: h
81
+ } = e.target;
82
+
83
+ this._adapter.setOriginImageSize({
84
+ originImageWidth: w,
85
+ originImageHeight: h
86
+ });
87
+
88
+ this.setState({
89
+ loading: false
90
+ });
91
+ this.handleResizeImage();
92
+ }
93
+
94
+ const {
95
+ src,
96
+ onLoad
97
+ } = this.getProps();
98
+ onLoad && onLoad(src);
99
+ };
100
+
101
+ this.handleError = e => {
102
+ const {
103
+ onError,
104
+ src
105
+ } = this.getProps();
106
+ this.setState({
107
+ loading: false
108
+ });
109
+ onError && onError(src);
110
+ };
111
+
112
+ this.handleResizeImage = () => {
113
+ const horizontal = !this._isImageVertical();
114
+
115
+ const {
116
+ originImageWidth,
117
+ originImageHeight
118
+ } = this._adapter.getOriginImageSize();
119
+
120
+ const imgWidth = horizontal ? originImageWidth : originImageHeight;
121
+ const imgHeight = horizontal ? originImageHeight : originImageWidth;
122
+ const {
123
+ onZoom
124
+ } = this.getProps();
125
+
126
+ const containerRef = this._adapter.getContainerRef();
127
+
128
+ if (containerRef && containerRef.current) {
129
+ const {
130
+ width: containerWidth,
131
+ height: containerHeight
132
+ } = this._getContainerBounds();
133
+
134
+ const reservedWidth = containerWidth - 80;
135
+ const reservedHeight = containerHeight - 80;
136
+
137
+ const _zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
138
+
139
+ onZoom(_zoom);
140
+ }
141
+ };
142
+
143
+ this.handleRightClickImage = e => {
144
+ const {
145
+ disableDownload
146
+ } = this.getProps();
147
+
148
+ if (disableDownload) {
149
+ e.preventDefault();
150
+ e.stopPropagation();
151
+ return false;
152
+ } else {
153
+ return true;
154
+ }
155
+ };
156
+
157
+ this.handleWheel = e => {
158
+ this.onWheel(e);
159
+ (0, _a11y.handlePrevent)(e);
160
+ };
161
+
162
+ this.onWheel = (0, _throttle2.default)(e => {
163
+ const {
164
+ onZoom,
165
+ zoomStep,
166
+ maxZoom,
167
+ minZoom
168
+ } = this.getProps();
169
+ const {
170
+ currZoom
171
+ } = this.getStates();
172
+
173
+ let _zoom;
174
+
175
+ if (e.deltaY < 0) {
176
+ /* zoom in */
177
+ if (currZoom + zoomStep <= maxZoom) {
178
+ _zoom = Number((currZoom + zoomStep).toFixed(2));
179
+ }
180
+ } else if (e.deltaY > 0) {
181
+ /* zoom out */
182
+ if (currZoom - zoomStep >= minZoom) {
183
+ _zoom = Number((currZoom - zoomStep).toFixed(2));
184
+ }
185
+ }
186
+
187
+ if (!(0, _isUndefined2.default)(_zoom)) {
188
+ onZoom(_zoom);
189
+ }
190
+ }, 50);
191
+
192
+ this.calcCanDragDirection = () => {
193
+ const {
194
+ width,
195
+ height
196
+ } = this.getStates();
197
+ const {
198
+ rotation
199
+ } = this.getProps();
200
+
201
+ const {
202
+ width: containerWidth,
203
+ height: containerHeight
204
+ } = this._getContainerBounds();
205
+
206
+ let canDragHorizontal = width > containerWidth;
207
+ let canDragVertical = height > containerHeight;
208
+
209
+ if (this._isImageVertical()) {
210
+ canDragHorizontal = height > containerWidth;
211
+ canDragVertical = width > containerHeight;
212
+ }
213
+
214
+ return {
215
+ canDragVertical,
216
+ canDragHorizontal
217
+ };
218
+ };
219
+
220
+ this.handleZoomChange = (newZoom, e) => {
221
+ const imageRef = this._adapter.getImageRef();
222
+
223
+ const {
224
+ originImageWidth,
225
+ originImageHeight
226
+ } = this._adapter.getOriginImageSize();
227
+
228
+ const {
229
+ canDragVertical,
230
+ canDragHorizontal
231
+ } = this.calcCanDragDirection();
232
+ const canDrag = canDragVertical || canDragHorizontal;
233
+
234
+ const {
235
+ width: containerWidth,
236
+ height: containerHeight
237
+ } = this._getContainerBounds();
238
+
239
+ const newWidth = Math.floor(originImageWidth * newZoom);
240
+ const newHeight = Math.floor(originImageHeight * newZoom); // debugger;
241
+
242
+ let _offset;
243
+
244
+ const horizontal = !this._isImageVertical();
245
+ let newTop = 0;
246
+ let newLeft = 0;
247
+
248
+ if (horizontal) {
249
+ _offset = {
250
+ x: 0.5 * (containerWidth - newWidth),
251
+ y: 0.5 * (containerHeight - newHeight)
252
+ };
253
+ newLeft = _offset.x;
254
+ newTop = _offset.y;
255
+ } else {
256
+ _offset = {
257
+ x: 0.5 * (containerWidth - newHeight),
258
+ y: 0.5 * (containerHeight - newWidth)
259
+ };
260
+ newLeft = _offset.x - (newWidth - newHeight) / 2;
261
+ newTop = _offset.y + (newWidth - newHeight) / 2;
262
+ }
263
+
264
+ this.setState({
265
+ width: newWidth,
266
+ height: newHeight,
267
+ offset: _offset,
268
+ left: newLeft,
269
+ top: newTop,
270
+ currZoom: newZoom
271
+ });
272
+ imageRef && (imageRef.style.cursor = canDrag ? "grab" : "default");
273
+ };
274
+
275
+ this.calcExtremeBounds = () => {
276
+ const {
277
+ width,
278
+ height
279
+ } = this.getStates();
280
+
281
+ const {
282
+ width: containerWidth,
283
+ height: containerHeight
284
+ } = this._getContainerBounds();
285
+
286
+ let extremeLeft = containerWidth - width;
287
+ let extremeTop = containerHeight - height;
288
+
289
+ if (this._isImageVertical()) {
290
+ extremeLeft = containerWidth - height;
291
+ extremeTop = containerHeight - width;
292
+ }
293
+
294
+ return {
295
+ left: extremeLeft,
296
+ top: extremeTop
297
+ };
298
+ };
299
+
300
+ this.handleMoveImage = e => {
301
+ const {
302
+ offset,
303
+ width,
304
+ height
305
+ } = this.getStates();
306
+
307
+ const startMouseMove = this._adapter.getMouseMove();
308
+
309
+ const startMouseOffset = this._adapter.getMouseOffset();
310
+
311
+ const {
312
+ canDragVertical,
313
+ canDragHorizontal
314
+ } = this.calcCanDragDirection();
315
+
316
+ if (startMouseMove && (canDragVertical || canDragHorizontal)) {
317
+ const {
318
+ clientX,
319
+ clientY
320
+ } = e;
321
+
322
+ const {
323
+ left: containerLeft,
324
+ top: containerTop
325
+ } = this._getContainerBounds();
326
+
327
+ const {
328
+ left: extremeLeft,
329
+ top: extremeTop
330
+ } = this.calcExtremeBounds();
331
+ let newX = canDragHorizontal ? clientX - containerLeft - startMouseOffset.x : offset.x;
332
+ let newY = canDragVertical ? clientY - containerTop - startMouseOffset.y : offset.y;
333
+
334
+ if (canDragHorizontal) {
335
+ newX = newX > 0 ? 0 : newX < extremeLeft ? extremeLeft : newX;
336
+ }
337
+
338
+ if (canDragVertical) {
339
+ newY = newY > 0 ? 0 : newY < extremeTop ? extremeTop : newY;
340
+ }
341
+
342
+ const _offset = {
343
+ x: newX,
344
+ y: newY
345
+ };
346
+ this.setState({
347
+ offset: _offset,
348
+ left: this._isImageVertical() ? _offset.x - (width - height) / 2 : _offset.x,
349
+ top: this._isImageVertical() ? _offset.y + (width - height) / 2 : _offset.y
350
+ });
351
+ }
352
+ };
353
+
354
+ this.handleImageMouseDown = e => {
355
+ this._adapter.setStartMouseOffset(this._getOffset(e));
356
+
357
+ this._adapter.setStartMouseMove(true);
358
+ };
359
+
360
+ this.handleImageMouseUp = () => {
361
+ this._adapter.setStartMouseMove(false);
362
+ };
363
+ }
364
+
365
+ }
366
+
367
+ exports.default = PreviewImageFoundation;
@@ -0,0 +1,44 @@
1
+ import BaseFoundation, { DefaultAdapter } from "../base/foundation";
2
+ export interface PreviewInnerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
3
+ getIsInGroup: () => boolean;
4
+ notifyChange: (index: number) => void;
5
+ notifyZoom: (zoom: number, increase: boolean) => void;
6
+ notifyClose: () => void;
7
+ notifyVisibleChange: (visible: boolean) => void;
8
+ notifyRatioChange: (type: string) => void;
9
+ notifyRotateChange: (angle: number) => void;
10
+ notifyDownload: (src: string, index: number) => void;
11
+ registerKeyDownListener: () => void;
12
+ unregisterKeyDownListener: () => void;
13
+ getMouseActiveTime: () => number;
14
+ getStopTiming: () => boolean;
15
+ setStopTiming: (value: boolean) => void;
16
+ getStartMouseDown: () => {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ setStartMouseDown: (x: number, y: number) => void;
21
+ setMouseActiveTime: (time: number) => void;
22
+ }
23
+ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<PreviewInnerAdapter<P, S>, P, S> {
24
+ constructor(adapter: PreviewInnerAdapter<P, S>);
25
+ beforeShow(): void;
26
+ afterHide(): void;
27
+ handleRatio(type: string): void;
28
+ handleViewVisibleChange: () => void;
29
+ handleMouseMoveEvent: (e: any, event: string) => void;
30
+ handleMouseMove: (e: any) => void;
31
+ handleMouseUp: (e: any) => void;
32
+ handleMouseDown: (e: any) => void;
33
+ handleKeyDown: (e: any) => void;
34
+ handleSwitchImage: (direction: string) => void;
35
+ handleDownload: () => void;
36
+ handlePreviewClose: () => void;
37
+ handleAdjustRatio: (type: string) => void;
38
+ handleRotateImage: (direction: string) => void;
39
+ handleZoomImage: (newZoom: number) => void;
40
+ preloadGapImage: () => void;
41
+ preloadSingleImage: () => void;
42
+ setLoadSuccessStatus: (src: string) => void;
43
+ onImageLoad: (src: string) => void;
44
+ }