@douyinfe/semi-foundation 2.67.3-alpha.0 → 2.68.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 (53) hide show
  1. package/datePicker/foundation.ts +1 -1
  2. package/hotKeys/foundation.ts +4 -5
  3. package/lib/cjs/datePicker/foundation.d.ts +1 -1
  4. package/lib/cjs/hotKeys/foundation.d.ts +2 -1
  5. package/lib/cjs/hotKeys/foundation.js +2 -4
  6. package/lib/cjs/overflowList/constants.d.ts +1 -1
  7. package/lib/cjs/resizable/constants.d.ts +5 -0
  8. package/lib/cjs/resizable/constants.js +11 -0
  9. package/lib/cjs/resizable/foundation.d.ts +4 -0
  10. package/lib/cjs/resizable/foundation.js +37 -0
  11. package/lib/cjs/resizable/group/index.d.ts +50 -0
  12. package/lib/cjs/resizable/group/index.js +271 -0
  13. package/lib/cjs/resizable/groupConstants.d.ts +16 -0
  14. package/lib/cjs/resizable/groupConstants.js +25 -0
  15. package/lib/cjs/resizable/resizable.css +34 -0
  16. package/lib/cjs/resizable/resizable.scss +39 -0
  17. package/lib/cjs/resizable/single/index.d.ts +70 -0
  18. package/lib/cjs/resizable/single/index.js +574 -0
  19. package/lib/cjs/resizable/singleConstants.d.ts +105 -0
  20. package/lib/cjs/resizable/singleConstants.js +67 -0
  21. package/lib/cjs/resizable/utils.d.ts +20 -0
  22. package/lib/cjs/resizable/utils.js +142 -0
  23. package/lib/cjs/tree/treeUtil.d.ts +1 -1
  24. package/lib/es/datePicker/foundation.d.ts +1 -1
  25. package/lib/es/hotKeys/foundation.d.ts +2 -1
  26. package/lib/es/hotKeys/foundation.js +2 -4
  27. package/lib/es/overflowList/constants.d.ts +1 -1
  28. package/lib/es/resizable/constants.d.ts +5 -0
  29. package/lib/es/resizable/constants.js +6 -0
  30. package/lib/es/resizable/foundation.d.ts +4 -0
  31. package/lib/es/resizable/foundation.js +4 -0
  32. package/lib/es/resizable/group/index.d.ts +50 -0
  33. package/lib/es/resizable/group/index.js +262 -0
  34. package/lib/es/resizable/groupConstants.d.ts +16 -0
  35. package/lib/es/resizable/groupConstants.js +19 -0
  36. package/lib/es/resizable/resizable.css +34 -0
  37. package/lib/es/resizable/resizable.scss +39 -0
  38. package/lib/es/resizable/single/index.d.ts +70 -0
  39. package/lib/es/resizable/single/index.js +565 -0
  40. package/lib/es/resizable/singleConstants.d.ts +105 -0
  41. package/lib/es/resizable/singleConstants.js +61 -0
  42. package/lib/es/resizable/utils.d.ts +20 -0
  43. package/lib/es/resizable/utils.js +124 -0
  44. package/lib/es/tree/treeUtil.d.ts +1 -1
  45. package/package.json +3 -3
  46. package/resizable/constants.ts +13 -0
  47. package/resizable/foundation.ts +31 -0
  48. package/resizable/group/index.ts +293 -0
  49. package/resizable/groupConstants.ts +25 -0
  50. package/resizable/resizable.scss +39 -0
  51. package/resizable/single/index.ts +629 -0
  52. package/resizable/singleConstants.ts +127 -0
  53. package/resizable/utils.ts +145 -0
@@ -0,0 +1,127 @@
1
+ // single
2
+ const rowStyleBase = {
3
+ width: '100%',
4
+ height: '10px',
5
+ top: '0px',
6
+ left: '0px',
7
+ cursor: 'row-resize',
8
+ } as const;
9
+ const colStyleBase = {
10
+ width: '10px',
11
+ height: '100%',
12
+ top: '0px',
13
+ left: '0px',
14
+ cursor: 'col-resize',
15
+ } as const;
16
+ const edgeStyleBase = {
17
+ width: '20px',
18
+ height: '20px',
19
+ position: 'absolute',
20
+ } as const;
21
+
22
+ export const directions = ['top', 'right', 'bottom', 'left', 'topRight', 'bottomRight', 'bottomLeft', 'topLeft'] as const;
23
+
24
+ export const directionStyles = {
25
+ top: {
26
+ ...rowStyleBase,
27
+ top: '-5px',
28
+ },
29
+ right: {
30
+ ...colStyleBase,
31
+ left: undefined,
32
+ right: '-5px',
33
+ },
34
+ bottom: {
35
+ ...rowStyleBase,
36
+ top: undefined,
37
+ bottom: '-5px',
38
+ },
39
+ left: {
40
+ ...colStyleBase,
41
+ left: '-5px',
42
+ },
43
+ topRight: {
44
+ ...edgeStyleBase,
45
+ right: '-10px',
46
+ top: '-10px',
47
+ cursor: 'ne-resize',
48
+ },
49
+ bottomRight: {
50
+ ...edgeStyleBase,
51
+ right: '-10px',
52
+ bottom: '-10px',
53
+ cursor: 'se-resize',
54
+ },
55
+ bottomLeft: {
56
+ ...edgeStyleBase,
57
+ left: '-10px',
58
+ bottom: '-10px',
59
+ cursor: 'sw-resize',
60
+ },
61
+ topLeft: {
62
+ ...edgeStyleBase,
63
+ left: '-10px',
64
+ top: '-10px',
65
+ cursor: 'nw-resize',
66
+ },
67
+ } as const;
68
+
69
+ export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'topRight' | 'bottomRight' | 'bottomLeft' | 'topLeft';
70
+
71
+ export interface HandleClassName {
72
+ top?: string;
73
+ right?: string;
74
+ bottom?: string;
75
+ left?: string;
76
+ topRight?: string;
77
+ bottomRight?: string;
78
+ bottomLeft?: string;
79
+ topLeft?: string
80
+ }
81
+
82
+ export type HandlerCallback = (
83
+ e: MouseEvent,
84
+ direction: Direction
85
+ ) => void;
86
+
87
+ export interface Enable {
88
+ top?: boolean;
89
+ right?: boolean;
90
+ bottom?: boolean;
91
+ left?: boolean;
92
+ topRight?: boolean;
93
+ bottomRight?: boolean;
94
+ bottomLeft?: boolean;
95
+ topLeft?: boolean
96
+ }
97
+
98
+ export interface Size {
99
+ width?: string | number;
100
+ height?: string | number
101
+ }
102
+
103
+ export interface NumberSize {
104
+ width: number;
105
+ height: number
106
+ }
107
+ export interface NewSize {
108
+ newHeight: number | string;
109
+ newWidth: number | string
110
+ }
111
+
112
+ export const DEFAULT_SIZE = {
113
+ width: 'auto',
114
+ height: 'auto',
115
+ };
116
+
117
+ export type ResizeCallback = (
118
+ size: Size,
119
+ event: MouseEvent,
120
+ direction: Direction,
121
+ ) => void;
122
+
123
+ export type ResizeStartCallback = (
124
+ e: MouseEvent,
125
+ dir: Direction,
126
+ ) => void | boolean;
127
+
@@ -0,0 +1,145 @@
1
+
2
+ export const clamp = (n: number, min: number, max: number): number => Math.max(Math.min(n, max), min);
3
+ export const snap = (n: number, size: number): number => Math.round(n / size) * size;
4
+ export const has = (dir: 'top' | 'right' | 'bottom' | 'left', target: string): boolean => new RegExp(dir, 'i').test(target);
5
+ export const findNextSnap = (n: number, snapArray: number[], snapGap: number = 0): number => {
6
+ const closestGapIndex = snapArray.reduce(
7
+ (prev, curr, index) => (Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev),
8
+ 0
9
+ );
10
+ const gap = Math.abs(snapArray[closestGapIndex] - n);
11
+
12
+ return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
13
+ };
14
+ export const getStringSize = (n: number | string): string => {
15
+ n = n.toString();
16
+ if (n === 'auto') {
17
+ return n;
18
+ }
19
+ if (n.endsWith('px')) {
20
+ return n;
21
+ }
22
+ if (n.endsWith('%')) {
23
+ return n;
24
+ }
25
+ if (n.endsWith('vh')) {
26
+ return n;
27
+ }
28
+ if (n.endsWith('vw')) {
29
+ return n;
30
+ }
31
+ if (n.endsWith('vmax')) {
32
+ return n;
33
+ }
34
+ if (n.endsWith('vmin')) {
35
+ return n;
36
+ }
37
+ return `${n}px`;
38
+ };
39
+ export const getNumberSize = (
40
+ size: undefined | string | number,
41
+ parentSize: number,
42
+ innerWidth: number,
43
+ innerHeight: number
44
+ ) => {
45
+ if (size && typeof size === 'string') {
46
+ if (size.endsWith('px')) {
47
+ return Number(size.replace('px', ''));
48
+ }
49
+ if (size.endsWith('%')) {
50
+ const ratio = Number(size.replace('%', '')) / 100;
51
+ return parentSize * ratio;
52
+ }
53
+ if (size.endsWith('vw')) {
54
+ const ratio = Number(size.replace('vw', '')) / 100;
55
+ return innerWidth * ratio;
56
+ }
57
+ if (size.endsWith('vh')) {
58
+ const ratio = Number(size.replace('vh', '')) / 100;
59
+ return innerHeight * ratio;
60
+ }
61
+ }
62
+ return typeof size === 'undefined' ? size : Number(size);
63
+ };
64
+ export const calculateNewMax = (
65
+ parentSize: { width: number; height: number },
66
+ innerWidth: number,
67
+ innerHeight: number,
68
+ maxWidth?: string | number,
69
+ maxHeight?: string | number,
70
+ minWidth?: string | number,
71
+ minHeight?: string | number
72
+ ) => {
73
+ maxWidth = getNumberSize(maxWidth, parentSize.width, innerWidth, innerHeight);
74
+ maxHeight = getNumberSize(maxHeight, parentSize.height, innerWidth, innerHeight);
75
+ minWidth = getNumberSize(minWidth, parentSize.width, innerWidth, innerHeight);
76
+ minHeight = getNumberSize(minHeight, parentSize.height, innerWidth, innerHeight);
77
+ return {
78
+ maxWidth,
79
+ maxHeight,
80
+ minWidth,
81
+ minHeight,
82
+ };
83
+ };export const getItemDirection = (dir: 'vertical' | 'horizontal') => {
84
+ if (dir === 'vertical') {
85
+ return ['bottom', 'top'];
86
+ } else {
87
+ return ['right', 'left'];
88
+ }
89
+ };
90
+
91
+ export const getPixelSize = (size: string, parentSize: number): number => {
92
+ if (size.endsWith('px')) {
93
+ return Number(size.replace('px', ''));
94
+ }
95
+ if (size.endsWith('%')) {
96
+ return Number(size.replace('%', '')) / 100 * parentSize;
97
+ }
98
+
99
+ return typeof size === 'undefined' ? size : Number(size);
100
+ };
101
+
102
+ export const judgeConstraint = (newSize: number, min: string, max: string, parentSize: number, offset: number = 0) => {
103
+ min = min ?? "0%";
104
+ max = max ?? "100%";
105
+ const minSize = getPixelSize(min, parentSize);
106
+ const maxSize = getPixelSize(max, parentSize);
107
+ if (newSize <= minSize + offset) {
108
+ return true;
109
+ }
110
+ if (newSize >= maxSize - offset) {
111
+ return true;
112
+ }
113
+ return false;
114
+ };
115
+
116
+ export const adjustNewSize = (newSize: number, min: string, max: string, parentSize: number, offset: number) => {
117
+ min = min ?? "0%";
118
+ max = max ?? "100%";
119
+ const minSize = getPixelSize(min, parentSize);
120
+ const maxSize = getPixelSize(max, parentSize);
121
+ if (newSize <= minSize + offset) {
122
+ return minSize + offset;
123
+ }
124
+ if (newSize >= maxSize - offset) {
125
+ return maxSize - offset;
126
+ }
127
+ return newSize;
128
+ };
129
+
130
+ export const getOffset = (style: CSSStyleDeclaration, direction: 'horizontal' | 'vertical') => {
131
+ if (direction === 'horizontal') {
132
+ const paddingLeft = parseFloat(style.paddingLeft);
133
+ const paddingRight = parseFloat(style.paddingRight);
134
+ const borderLeftWidth = parseFloat(style.borderLeftWidth);
135
+ const borderRightWidth = parseFloat(style.borderRightWidth);
136
+ return paddingLeft + paddingRight + borderLeftWidth + borderRightWidth;
137
+ } else {
138
+ const paddingTop = parseFloat(style.paddingTop);
139
+ const paddingBottom = parseFloat(style.paddingBottom);
140
+ const borderTopWidth = parseFloat(style.borderTopWidth);
141
+ const borderBottomWidth = parseFloat(style.borderBottomWidth);
142
+ return paddingTop + paddingBottom + borderTopWidth + borderBottomWidth;
143
+ }
144
+ };
145
+