@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,57 @@
1
+ import BaseFoundation from "../base/foundation";
2
+ export default class PreviewFooterFoundation extends BaseFoundation {
3
+ constructor() {
4
+ super(...arguments);
5
+
6
+ this.changeSliderValue = type => {
7
+ const {
8
+ zoom,
9
+ step,
10
+ min,
11
+ max
12
+ } = this.getProps();
13
+ let newValue = type === "plus" ? zoom + step : zoom - step;
14
+
15
+ if (newValue > max) {
16
+ newValue = max;
17
+ } else if (newValue < min) {
18
+ newValue = min;
19
+ }
20
+
21
+ this.handleValueChange(newValue);
22
+ };
23
+
24
+ this.handleValueChange = value => {
25
+ const {
26
+ onZoomIn,
27
+ onZoomOut,
28
+ zoom
29
+ } = this.getProps();
30
+
31
+ if (value > zoom) {
32
+ onZoomIn(value / 100);
33
+ } else {
34
+ onZoomOut(value / 100);
35
+ }
36
+
37
+ this._adapter.setStartMouseOffset(value);
38
+ };
39
+
40
+ this.handleRatioClick = () => {
41
+ const {
42
+ ratio,
43
+ onAdjustRatio
44
+ } = this.getProps();
45
+ const type = ratio === "adaptation" ? "realSize" : "adaptation";
46
+ onAdjustRatio(type);
47
+ };
48
+
49
+ this.handleRotate = direction => {
50
+ const {
51
+ onRotate
52
+ } = this.getProps();
53
+ onRotate && onRotate(direction);
54
+ };
55
+ }
56
+
57
+ }
@@ -0,0 +1,5 @@
1
+ import BaseFoundation, { DefaultAdapter } from "../base/foundation";
2
+ export default class PreviewFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<Partial<DefaultAdapter>> {
3
+ handleVisibleChange: (newVisible: boolean) => void;
4
+ handleCurrentIndexChange: (index: number) => void;
5
+ }
@@ -0,0 +1,37 @@
1
+ import BaseFoundation from "../base/foundation";
2
+ export default class PreviewFoundation extends BaseFoundation {
3
+ constructor() {
4
+ super(...arguments);
5
+
6
+ this.handleVisibleChange = newVisible => {
7
+ const {
8
+ visible,
9
+ onVisibleChange
10
+ } = this.getProps();
11
+
12
+ if (!(visible in this.getProps())) {
13
+ this.setState({
14
+ visible: newVisible
15
+ });
16
+ }
17
+
18
+ onVisibleChange && onVisibleChange(newVisible);
19
+ };
20
+
21
+ this.handleCurrentIndexChange = index => {
22
+ const {
23
+ currentIndex,
24
+ onChange
25
+ } = this.getProps();
26
+
27
+ if (!(currentIndex in this.getProps())) {
28
+ this.setState({
29
+ currentIndex: index
30
+ });
31
+ }
32
+
33
+ onChange && onChange(index);
34
+ };
35
+ }
36
+
37
+ }
@@ -0,0 +1,58 @@
1
+ /// <reference types="lodash" />
2
+ import BaseFoundation, { DefaultAdapter } from "../base/foundation";
3
+ export interface PreviewImageAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
4
+ getOriginImageSize: () => {
5
+ originImageWidth: number;
6
+ originImageHeight: number;
7
+ };
8
+ setOriginImageSize: (size: {
9
+ originImageWidth: number;
10
+ originImageHeight: number;
11
+ }) => void;
12
+ getContainerRef: () => any;
13
+ getImageRef: () => any;
14
+ getMouseMove: () => boolean;
15
+ setStartMouseMove: (move: boolean) => void;
16
+ getMouseOffset: () => {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ setStartMouseOffset: (offset: {
21
+ x: number;
22
+ y: number;
23
+ }) => void;
24
+ setLoading: (loading: boolean) => void;
25
+ }
26
+ export interface DragDirection {
27
+ canDragVertical: boolean;
28
+ canDragHorizontal: boolean;
29
+ }
30
+ export interface ExtremeBounds {
31
+ left: number;
32
+ top: number;
33
+ }
34
+ export interface ImageOffset {
35
+ x: number;
36
+ y: number;
37
+ }
38
+ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<PreviewImageAdapter<P, S>, P, S> {
39
+ constructor(adapter: PreviewImageAdapter<P, S>);
40
+ _isImageVertical: () => boolean;
41
+ _getImageBounds: () => DOMRect;
42
+ _getContainerBounds: () => DOMRect;
43
+ _getOffset: (e: any) => ImageOffset;
44
+ setLoading: (loading: boolean) => void;
45
+ handleWindowResize: () => void;
46
+ handleLoad: (e: any) => void;
47
+ handleError: (e: any) => void;
48
+ handleResizeImage: () => void;
49
+ handleRightClickImage: (e: any) => boolean;
50
+ handleWheel: (e: React.WheelEvent<HTMLImageElement>) => void;
51
+ onWheel: import("lodash").DebouncedFunc<(e: React.WheelEvent<HTMLImageElement>) => void>;
52
+ calcCanDragDirection: () => DragDirection;
53
+ handleZoomChange: (newZoom: number, e: any) => void;
54
+ calcExtremeBounds: () => ExtremeBounds;
55
+ handleMoveImage: (e: any) => void;
56
+ handleImageMouseDown: (e: any) => void;
57
+ handleImageMouseUp: () => void;
58
+ }
@@ -0,0 +1,352 @@
1
+ import _isUndefined from "lodash/isUndefined";
2
+ import _throttle from "lodash/throttle";
3
+ import BaseFoundation from "../base/foundation";
4
+ import { handlePrevent } from "../utils/a11y";
5
+ export default class PreviewImageFoundation extends BaseFoundation {
6
+ constructor(adapter) {
7
+ super(Object.assign({}, adapter));
8
+
9
+ this._isImageVertical = () => this.getProp("rotation") % 180 !== 0;
10
+
11
+ this._getImageBounds = () => {
12
+ const imageRef = this._adapter.getImageRef();
13
+
14
+ return imageRef === null || imageRef === void 0 ? void 0 : imageRef.getBoundingClientRect();
15
+ };
16
+
17
+ this._getContainerBounds = () => {
18
+ var _a;
19
+
20
+ const containerRef = this._adapter.getContainerRef();
21
+
22
+ return (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
23
+ };
24
+
25
+ this._getOffset = e => {
26
+ const {
27
+ left,
28
+ top
29
+ } = this._getImageBounds();
30
+
31
+ return {
32
+ x: e.clientX - left,
33
+ y: e.clientY - top
34
+ };
35
+ };
36
+
37
+ this.setLoading = loading => {
38
+ this._adapter.setLoading(loading);
39
+ };
40
+
41
+ this.handleWindowResize = () => {
42
+ const {
43
+ setRatio
44
+ } = this.getProps();
45
+ const {
46
+ ratio
47
+ } = this.getProps();
48
+
49
+ const {
50
+ originImageWidth,
51
+ originImageHeight
52
+ } = this._adapter.getOriginImageSize();
53
+
54
+ if (originImageWidth && originImageHeight) {
55
+ if (ratio !== "adaptation") {
56
+ setRatio("adaptation");
57
+ } else {
58
+ this.handleResizeImage();
59
+ }
60
+ }
61
+ };
62
+
63
+ this.handleLoad = e => {
64
+ if (e.target) {
65
+ const {
66
+ width: w,
67
+ height: h
68
+ } = e.target;
69
+
70
+ this._adapter.setOriginImageSize({
71
+ originImageWidth: w,
72
+ originImageHeight: h
73
+ });
74
+
75
+ this.setState({
76
+ loading: false
77
+ });
78
+ this.handleResizeImage();
79
+ }
80
+
81
+ const {
82
+ src,
83
+ onLoad
84
+ } = this.getProps();
85
+ onLoad && onLoad(src);
86
+ };
87
+
88
+ this.handleError = e => {
89
+ const {
90
+ onError,
91
+ src
92
+ } = this.getProps();
93
+ this.setState({
94
+ loading: false
95
+ });
96
+ onError && onError(src);
97
+ };
98
+
99
+ this.handleResizeImage = () => {
100
+ const horizontal = !this._isImageVertical();
101
+
102
+ const {
103
+ originImageWidth,
104
+ originImageHeight
105
+ } = this._adapter.getOriginImageSize();
106
+
107
+ const imgWidth = horizontal ? originImageWidth : originImageHeight;
108
+ const imgHeight = horizontal ? originImageHeight : originImageWidth;
109
+ const {
110
+ onZoom
111
+ } = this.getProps();
112
+
113
+ const containerRef = this._adapter.getContainerRef();
114
+
115
+ if (containerRef && containerRef.current) {
116
+ const {
117
+ width: containerWidth,
118
+ height: containerHeight
119
+ } = this._getContainerBounds();
120
+
121
+ const reservedWidth = containerWidth - 80;
122
+ const reservedHeight = containerHeight - 80;
123
+
124
+ const _zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
125
+
126
+ onZoom(_zoom);
127
+ }
128
+ };
129
+
130
+ this.handleRightClickImage = e => {
131
+ const {
132
+ disableDownload
133
+ } = this.getProps();
134
+
135
+ if (disableDownload) {
136
+ e.preventDefault();
137
+ e.stopPropagation();
138
+ return false;
139
+ } else {
140
+ return true;
141
+ }
142
+ };
143
+
144
+ this.handleWheel = e => {
145
+ this.onWheel(e);
146
+ handlePrevent(e);
147
+ };
148
+
149
+ this.onWheel = _throttle(e => {
150
+ const {
151
+ onZoom,
152
+ zoomStep,
153
+ maxZoom,
154
+ minZoom
155
+ } = this.getProps();
156
+ const {
157
+ currZoom
158
+ } = this.getStates();
159
+
160
+ let _zoom;
161
+
162
+ if (e.deltaY < 0) {
163
+ /* zoom in */
164
+ if (currZoom + zoomStep <= maxZoom) {
165
+ _zoom = Number((currZoom + zoomStep).toFixed(2));
166
+ }
167
+ } else if (e.deltaY > 0) {
168
+ /* zoom out */
169
+ if (currZoom - zoomStep >= minZoom) {
170
+ _zoom = Number((currZoom - zoomStep).toFixed(2));
171
+ }
172
+ }
173
+
174
+ if (!_isUndefined(_zoom)) {
175
+ onZoom(_zoom);
176
+ }
177
+ }, 50);
178
+
179
+ this.calcCanDragDirection = () => {
180
+ const {
181
+ width,
182
+ height
183
+ } = this.getStates();
184
+ const {
185
+ rotation
186
+ } = this.getProps();
187
+
188
+ const {
189
+ width: containerWidth,
190
+ height: containerHeight
191
+ } = this._getContainerBounds();
192
+
193
+ let canDragHorizontal = width > containerWidth;
194
+ let canDragVertical = height > containerHeight;
195
+
196
+ if (this._isImageVertical()) {
197
+ canDragHorizontal = height > containerWidth;
198
+ canDragVertical = width > containerHeight;
199
+ }
200
+
201
+ return {
202
+ canDragVertical,
203
+ canDragHorizontal
204
+ };
205
+ };
206
+
207
+ this.handleZoomChange = (newZoom, e) => {
208
+ const imageRef = this._adapter.getImageRef();
209
+
210
+ const {
211
+ originImageWidth,
212
+ originImageHeight
213
+ } = this._adapter.getOriginImageSize();
214
+
215
+ const {
216
+ canDragVertical,
217
+ canDragHorizontal
218
+ } = this.calcCanDragDirection();
219
+ const canDrag = canDragVertical || canDragHorizontal;
220
+
221
+ const {
222
+ width: containerWidth,
223
+ height: containerHeight
224
+ } = this._getContainerBounds();
225
+
226
+ const newWidth = Math.floor(originImageWidth * newZoom);
227
+ const newHeight = Math.floor(originImageHeight * newZoom); // debugger;
228
+
229
+ let _offset;
230
+
231
+ const horizontal = !this._isImageVertical();
232
+ let newTop = 0;
233
+ let newLeft = 0;
234
+
235
+ if (horizontal) {
236
+ _offset = {
237
+ x: 0.5 * (containerWidth - newWidth),
238
+ y: 0.5 * (containerHeight - newHeight)
239
+ };
240
+ newLeft = _offset.x;
241
+ newTop = _offset.y;
242
+ } else {
243
+ _offset = {
244
+ x: 0.5 * (containerWidth - newHeight),
245
+ y: 0.5 * (containerHeight - newWidth)
246
+ };
247
+ newLeft = _offset.x - (newWidth - newHeight) / 2;
248
+ newTop = _offset.y + (newWidth - newHeight) / 2;
249
+ }
250
+
251
+ this.setState({
252
+ width: newWidth,
253
+ height: newHeight,
254
+ offset: _offset,
255
+ left: newLeft,
256
+ top: newTop,
257
+ currZoom: newZoom
258
+ });
259
+ imageRef && (imageRef.style.cursor = canDrag ? "grab" : "default");
260
+ };
261
+
262
+ this.calcExtremeBounds = () => {
263
+ const {
264
+ width,
265
+ height
266
+ } = this.getStates();
267
+
268
+ const {
269
+ width: containerWidth,
270
+ height: containerHeight
271
+ } = this._getContainerBounds();
272
+
273
+ let extremeLeft = containerWidth - width;
274
+ let extremeTop = containerHeight - height;
275
+
276
+ if (this._isImageVertical()) {
277
+ extremeLeft = containerWidth - height;
278
+ extremeTop = containerHeight - width;
279
+ }
280
+
281
+ return {
282
+ left: extremeLeft,
283
+ top: extremeTop
284
+ };
285
+ };
286
+
287
+ this.handleMoveImage = e => {
288
+ const {
289
+ offset,
290
+ width,
291
+ height
292
+ } = this.getStates();
293
+
294
+ const startMouseMove = this._adapter.getMouseMove();
295
+
296
+ const startMouseOffset = this._adapter.getMouseOffset();
297
+
298
+ const {
299
+ canDragVertical,
300
+ canDragHorizontal
301
+ } = this.calcCanDragDirection();
302
+
303
+ if (startMouseMove && (canDragVertical || canDragHorizontal)) {
304
+ const {
305
+ clientX,
306
+ clientY
307
+ } = e;
308
+
309
+ const {
310
+ left: containerLeft,
311
+ top: containerTop
312
+ } = this._getContainerBounds();
313
+
314
+ const {
315
+ left: extremeLeft,
316
+ top: extremeTop
317
+ } = this.calcExtremeBounds();
318
+ let newX = canDragHorizontal ? clientX - containerLeft - startMouseOffset.x : offset.x;
319
+ let newY = canDragVertical ? clientY - containerTop - startMouseOffset.y : offset.y;
320
+
321
+ if (canDragHorizontal) {
322
+ newX = newX > 0 ? 0 : newX < extremeLeft ? extremeLeft : newX;
323
+ }
324
+
325
+ if (canDragVertical) {
326
+ newY = newY > 0 ? 0 : newY < extremeTop ? extremeTop : newY;
327
+ }
328
+
329
+ const _offset = {
330
+ x: newX,
331
+ y: newY
332
+ };
333
+ this.setState({
334
+ offset: _offset,
335
+ left: this._isImageVertical() ? _offset.x - (width - height) / 2 : _offset.x,
336
+ top: this._isImageVertical() ? _offset.y + (width - height) / 2 : _offset.y
337
+ });
338
+ }
339
+ };
340
+
341
+ this.handleImageMouseDown = e => {
342
+ this._adapter.setStartMouseOffset(this._getOffset(e));
343
+
344
+ this._adapter.setStartMouseMove(true);
345
+ };
346
+
347
+ this.handleImageMouseUp = () => {
348
+ this._adapter.setStartMouseMove(false);
349
+ };
350
+ }
351
+
352
+ }
@@ -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
+ }