@douyinfe/semi-foundation 2.63.2-alpha.0 → 2.64.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 (95) hide show
  1. package/calendar/foundation.ts +20 -0
  2. package/colorPicker/AlphaSliderFoundation.ts +62 -0
  3. package/colorPicker/ColorChooseAreaFoundation.ts +86 -0
  4. package/colorPicker/ColorSliderFoundation.ts +61 -0
  5. package/colorPicker/DataPartFoundation.ts +113 -0
  6. package/colorPicker/colorPicker.scss +113 -0
  7. package/colorPicker/constants.ts +11 -0
  8. package/colorPicker/foundation.ts +206 -0
  9. package/colorPicker/interface.ts +51 -0
  10. package/colorPicker/utils/convert.ts +228 -0
  11. package/colorPicker/utils/round.ts +3 -0
  12. package/colorPicker/utils/split.ts +40 -0
  13. package/colorPicker/variables.scss +28 -0
  14. package/image/previewImageFoundation.ts +22 -17
  15. package/lib/cjs/calendar/foundation.js +18 -0
  16. package/lib/cjs/colorPicker/AlphaSliderFoundation.d.ts +27 -0
  17. package/lib/cjs/colorPicker/AlphaSliderFoundation.js +40 -0
  18. package/lib/cjs/colorPicker/ColorChooseAreaFoundation.d.ts +42 -0
  19. package/lib/cjs/colorPicker/ColorChooseAreaFoundation.js +62 -0
  20. package/lib/cjs/colorPicker/ColorSliderFoundation.d.ts +26 -0
  21. package/lib/cjs/colorPicker/ColorSliderFoundation.js +40 -0
  22. package/lib/cjs/colorPicker/DataPartFoundation.d.ts +28 -0
  23. package/lib/cjs/colorPicker/DataPartFoundation.js +115 -0
  24. package/lib/cjs/colorPicker/colorPicker.css +84 -0
  25. package/lib/cjs/colorPicker/colorPicker.scss +113 -0
  26. package/lib/cjs/colorPicker/constants.d.ts +4 -0
  27. package/lib/cjs/colorPicker/constants.js +11 -0
  28. package/lib/cjs/colorPicker/foundation.d.ts +66 -0
  29. package/lib/cjs/colorPicker/foundation.js +150 -0
  30. package/lib/cjs/colorPicker/interface.d.ts +40 -0
  31. package/lib/cjs/colorPicker/interface.js +5 -0
  32. package/lib/cjs/colorPicker/utils/convert.d.ts +28 -0
  33. package/lib/cjs/colorPicker/utils/convert.js +306 -0
  34. package/lib/cjs/colorPicker/utils/round.d.ts +1 -0
  35. package/lib/cjs/colorPicker/utils/round.js +12 -0
  36. package/lib/cjs/colorPicker/utils/split.d.ts +18 -0
  37. package/lib/cjs/colorPicker/utils/split.js +40 -0
  38. package/lib/cjs/colorPicker/variables.scss +28 -0
  39. package/lib/cjs/image/previewImageFoundation.js +22 -18
  40. package/lib/cjs/slider/foundation.d.ts +1 -0
  41. package/lib/cjs/slider/foundation.js +15 -0
  42. package/lib/cjs/tabs/constants.d.ts +0 -1
  43. package/lib/cjs/tabs/constants.js +1 -2
  44. package/lib/cjs/tabs/tabs.css +199 -28
  45. package/lib/cjs/tabs/tabs.scss +297 -336
  46. package/lib/cjs/tabs/variables.scss +2 -21
  47. package/lib/cjs/tooltip/foundation.js +2 -1
  48. package/lib/cjs/tree/treeUtil.d.ts +1 -1
  49. package/lib/cjs/upload/constants.d.ts +1 -1
  50. package/lib/cjs/upload/foundation.d.ts +1 -0
  51. package/lib/cjs/upload/foundation.js +30 -14
  52. package/lib/es/calendar/foundation.js +18 -0
  53. package/lib/es/colorPicker/AlphaSliderFoundation.d.ts +27 -0
  54. package/lib/es/colorPicker/AlphaSliderFoundation.js +33 -0
  55. package/lib/es/colorPicker/ColorChooseAreaFoundation.d.ts +42 -0
  56. package/lib/es/colorPicker/ColorChooseAreaFoundation.js +55 -0
  57. package/lib/es/colorPicker/ColorSliderFoundation.d.ts +26 -0
  58. package/lib/es/colorPicker/ColorSliderFoundation.js +33 -0
  59. package/lib/es/colorPicker/DataPartFoundation.d.ts +28 -0
  60. package/lib/es/colorPicker/DataPartFoundation.js +108 -0
  61. package/lib/es/colorPicker/colorPicker.css +84 -0
  62. package/lib/es/colorPicker/colorPicker.scss +113 -0
  63. package/lib/es/colorPicker/constants.d.ts +4 -0
  64. package/lib/es/colorPicker/constants.js +6 -0
  65. package/lib/es/colorPicker/foundation.d.ts +66 -0
  66. package/lib/es/colorPicker/foundation.js +143 -0
  67. package/lib/es/colorPicker/interface.d.ts +40 -0
  68. package/lib/es/colorPicker/interface.js +1 -0
  69. package/lib/es/colorPicker/utils/convert.d.ts +28 -0
  70. package/lib/es/colorPicker/utils/convert.js +277 -0
  71. package/lib/es/colorPicker/utils/round.d.ts +1 -0
  72. package/lib/es/colorPicker/utils/round.js +5 -0
  73. package/lib/es/colorPicker/utils/split.d.ts +18 -0
  74. package/lib/es/colorPicker/utils/split.js +34 -0
  75. package/lib/es/colorPicker/variables.scss +28 -0
  76. package/lib/es/image/previewImageFoundation.js +22 -18
  77. package/lib/es/slider/foundation.d.ts +1 -0
  78. package/lib/es/slider/foundation.js +15 -0
  79. package/lib/es/tabs/constants.d.ts +0 -1
  80. package/lib/es/tabs/constants.js +1 -2
  81. package/lib/es/tabs/tabs.css +199 -28
  82. package/lib/es/tabs/tabs.scss +297 -336
  83. package/lib/es/tabs/variables.scss +2 -21
  84. package/lib/es/tooltip/foundation.js +2 -1
  85. package/lib/es/tree/treeUtil.d.ts +1 -1
  86. package/lib/es/upload/constants.d.ts +1 -1
  87. package/lib/es/upload/foundation.d.ts +1 -0
  88. package/lib/es/upload/foundation.js +30 -14
  89. package/package.json +3 -3
  90. package/slider/foundation.ts +13 -0
  91. package/tabs/constants.ts +1 -2
  92. package/tabs/tabs.scss +297 -336
  93. package/tabs/variables.scss +2 -21
  94. package/tooltip/foundation.ts +1 -1
  95. package/upload/foundation.ts +19 -3
@@ -0,0 +1,51 @@
1
+ export interface HsvColor {
2
+ h: number;
3
+ s: number;
4
+ v: number
5
+ }
6
+
7
+ export interface HsvaColor extends HsvColor {
8
+ a: number
9
+ }
10
+
11
+
12
+ export interface RgbColor {
13
+ r: number;
14
+ g: number;
15
+ b: number
16
+ }
17
+
18
+ export interface RgbaColor extends RgbColor {
19
+ a: number
20
+ }
21
+
22
+ export interface HslColor {
23
+ h: number;
24
+ s: number;
25
+ l: number
26
+ }
27
+
28
+ export interface HslaColor extends HslColor {
29
+ a: number
30
+ }
31
+
32
+ export interface HsvColor {
33
+ h: number;
34
+ s: number;
35
+ v: number
36
+ }
37
+
38
+ export interface HsvaColor extends HsvColor {
39
+ a: number
40
+ }
41
+
42
+ export type ObjectColor = RgbColor | HslColor | HsvColor | RgbaColor | HslaColor | HsvaColor;
43
+
44
+ export type AnyColor = string | ObjectColor;
45
+
46
+ export interface ColorModel<T extends AnyColor> {
47
+ defaultColor: T;
48
+ toHsva: (defaultColor: T) => HsvaColor;
49
+ fromHsva: (hsva: HsvaColor) => T;
50
+ equal: (first: T, second: T) => boolean
51
+ }
@@ -0,0 +1,228 @@
1
+ import { round } from "./round";
2
+ import { RgbaColor, RgbColor, HslaColor, HslColor, HsvaColor, HsvColor } from "../interface";
3
+ /**
4
+ * Valid CSS <angle> units.
5
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/angle
6
+ */
7
+
8
+ /**
9
+ * Referrer from https://github.com/web-padawan/vanilla-colorful/blob/master/src/lib/utils/convert.ts
10
+ */
11
+ const angleUnits: Record<string, number> = {
12
+ grad: 360 / 400,
13
+ turn: 360,
14
+ rad: 360 / (Math.PI * 2),
15
+ };
16
+
17
+ export const hexToHsva = (hex: string): HsvaColor => rgbaToHsva(hexToRgba(hex));
18
+
19
+ export const hexToRgba = (hex: string): RgbaColor => {
20
+ if (hex[0] === "#") hex = hex.substring(1);
21
+
22
+ const hexToPercent = (str: string) => {
23
+ const decimal = parseInt(str, 16);
24
+ if (!isNaN(decimal)) {
25
+ const percent = decimal / 255;
26
+ return percent;
27
+ }
28
+ return 1;
29
+ };
30
+
31
+
32
+ return {
33
+ r: parseInt(hex.substring(0, 2), 16),
34
+ g: parseInt(hex.substring(2, 4), 16),
35
+ b: parseInt(hex.substring(4, 6), 16),
36
+ a: hexToPercent(hex.substring(6, 8)),
37
+ };
38
+ };
39
+
40
+ export const parseHue = (value: string, unit = "deg"): number => {
41
+ return Number(value) * (angleUnits[unit] || 1);
42
+ };
43
+
44
+ export const hslaStringToHsva = (hslString: string): HsvaColor => {
45
+ const matcher = /hsla?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
46
+ const match = matcher.exec(hslString);
47
+
48
+ if (!match) return { h: 0, s: 0, v: 0, a: 1 };
49
+
50
+ return hslaToHsva({
51
+ h: parseHue(match[1], match[2]),
52
+ s: Number(match[3]),
53
+ l: Number(match[4]),
54
+ a: match[5] === undefined ? 1 : Number(match[5]) / (match[6] ? 100 : 1),
55
+ });
56
+ };
57
+
58
+ export const hslStringToHsva = hslaStringToHsva;
59
+
60
+ export const hslaToHsva = ({ h, s, l, a }: HslaColor): HsvaColor => {
61
+ s *= (l < 50 ? l : 100 - l) / 100;
62
+
63
+ return {
64
+ h: h,
65
+ s: s > 0 ? ((2 * s) / (l + s)) * 100 : 0,
66
+ v: l + s,
67
+ a,
68
+ };
69
+ };
70
+
71
+ export const hsvaToHex = (hsva: HsvaColor): string => rgbaToHex(hsvaToRgba(hsva));
72
+
73
+ export const hsvaToHsla = ({ h, s, v, a }: HsvaColor): HslaColor => {
74
+ const hh = ((200 - s) * v) / 100;
75
+
76
+ return {
77
+ h: round(h),
78
+ s: round(hh > 0 && hh < 200 ? ((s * v) / 100 / (hh <= 100 ? hh : 200 - hh)) * 100 : 0),
79
+ l: round(hh / 2),
80
+ a: round(a, 2),
81
+ };
82
+ };
83
+
84
+ export const hsvaToHslString = (hsva: HsvaColor): string => {
85
+ const { h, s, l } = hsvaToHsla(hsva);
86
+ return `hsl(${h}, ${s}%, ${l}%)`;
87
+ };
88
+
89
+ export const hsvaToHsvString = (hsva: HsvaColor): string => {
90
+ const { h, s, v } = roundHsva(hsva);
91
+ return `hsv(${h}, ${s}%, ${v}%)`;
92
+ };
93
+
94
+ export const hsvaToHsvaString = (hsva: HsvaColor): string => {
95
+ const { h, s, v, a } = roundHsva(hsva);
96
+ return `hsva(${h}, ${s}%, ${v}%, ${a})`;
97
+ };
98
+
99
+ export const hsvaToHslaString = (hsva: HsvaColor): string => {
100
+ const { h, s, l, a } = hsvaToHsla(hsva);
101
+ return `hsla(${h}, ${s}%, ${l}%, ${a})`;
102
+ };
103
+
104
+ export const hsvaToRgba = ({ h, s, v, a }: HsvaColor): RgbaColor => {
105
+
106
+
107
+ h = (h / 360) * 6;
108
+ s = s / 100;
109
+ v = v / 100;
110
+
111
+ const hh = Math.floor(h),
112
+ b = v * (1 - s),
113
+ c = v * (1 - (h - hh) * s),
114
+ d = v * (1 - (1 - h + hh) * s),
115
+ module = hh % 6;
116
+
117
+ return {
118
+ r: round([v, c, b, b, d, v][module] * 255),
119
+ g: round([d, v, v, c, b, b][module] * 255),
120
+ b: round([b, b, d, v, v, c][module] * 255),
121
+ a: round(a, 2),
122
+ };
123
+ };
124
+
125
+ export const hsvaToRgbString = (hsva: HsvaColor): string => {
126
+ const { r, g, b } = hsvaToRgba(hsva);
127
+ return `rgb(${r}, ${g}, ${b})`;
128
+ };
129
+
130
+ export const hsvaToRgbaString = (hsva: HsvaColor): string => {
131
+ const { r, g, b, a } = hsvaToRgba(hsva);
132
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
133
+ };
134
+
135
+ export const hsvaStringToHsva = (hsvString: string): HsvaColor => {
136
+ const matcher = /hsva?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
137
+ const match = matcher.exec(hsvString);
138
+
139
+ if (!match) return { h: 0, s: 0, v: 0, a: 1 };
140
+
141
+ return roundHsva({
142
+ h: parseHue(match[1], match[2]),
143
+ s: Number(match[3]),
144
+ v: Number(match[4]),
145
+ a: match[5] === undefined ? 1 : Number(match[5]) / (match[6] ? 100 : 1),
146
+ });
147
+ };
148
+
149
+ export const hsvStringToHsva = hsvaStringToHsva;
150
+
151
+ export const rgbaStringToHsva = (rgbaString: string): HsvaColor => {
152
+ return rgbaToHsva(rgbaStringToRgba(rgbaString));
153
+ };
154
+
155
+ export const rgbaStringToRgba = (rgbaString: string): RgbaColor => {
156
+ const matcher = /rgba?\(?\s*(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
157
+ const match = matcher.exec(rgbaString);
158
+
159
+ if (!match) return { r: 0, g: 0, b: 0, a: 1 };
160
+
161
+ return {
162
+ r: Number(match[1]) / (match[2] ? 100 / 255 : 1),
163
+ g: Number(match[3]) / (match[4] ? 100 / 255 : 1),
164
+ b: Number(match[5]) / (match[6] ? 100 / 255 : 1),
165
+ a: match[7] === undefined ? 1 : Number(match[7]) / (match[8] ? 100 : 1),
166
+ };
167
+ };
168
+ export const rgbStringToRgba = rgbaStringToRgba;
169
+
170
+ export const rgbStringToHsva = rgbaStringToHsva;
171
+
172
+ const format = (number: number) => {
173
+ const hex = number.toString(16);
174
+ return hex.length < 2 ? "0" + hex : hex;
175
+ };
176
+
177
+ export const rgbaToHex = ({ r, g, b, a }: RgbaColor): string => {
178
+ const percentToHex = (p) => {
179
+ //const percent = Math.max(0, Math.min(100, p)); // bound percent from 0 to 100
180
+ const intValue = Math.round(p / 100 * 255); // map percent to nearest integer (0 - 255)
181
+ const hexValue = intValue.toString(16); // get hexadecimal representation
182
+ return hexValue.padStart(2, '0').toLowerCase(); // format with leading 0 and upper case characters
183
+ };
184
+ if (a === undefined || a === 1) {
185
+ return "#" + format(r) + format(g) + format(b);
186
+ } else {
187
+ return "#" + format(r) + format(g) + format(b) + percentToHex(a * 100);
188
+ }
189
+
190
+ };
191
+
192
+ export const rgbaToHsva = ({ r, g, b, a }: RgbaColor): HsvaColor => {
193
+
194
+ const max = Math.max(r, g, b);
195
+ const delta = max - Math.min(r, g, b);
196
+
197
+ // prettier-ignore
198
+ const hh = delta
199
+ ? max === r
200
+ ? (g - b) / delta
201
+ : max === g
202
+ ? 2 + (b - r) / delta
203
+ : 4 + (r - g) / delta
204
+ : 0;
205
+
206
+ return {
207
+ h: round(60 * (hh < 0 ? hh + 6 : hh)),
208
+ s: round(max ? (delta / max) * 100 : 0),
209
+ v: round((max / 255) * 100),
210
+ a,
211
+ };
212
+ };
213
+
214
+ export const roundHsva = (hsva: HsvaColor): HsvaColor => ({
215
+ h: round(hsva.h),
216
+ s: round(hsva.s),
217
+ v: round(hsva.v),
218
+ a: round(hsva.a, 2),
219
+ });
220
+
221
+ export const rgbaToRgb = ({ r, g, b }: RgbaColor): RgbColor => ({ r, g, b });
222
+
223
+ export const hslaToHsl = ({ h, s, l }: HslaColor): HslColor => ({ h, s, l });
224
+
225
+ export const hsvaToHsv = (hsva: HsvaColor): HsvColor => {
226
+ const { h, s, v } = roundHsva(hsva);
227
+ return { h, s, v };
228
+ };
@@ -0,0 +1,3 @@
1
+ export const round = (number: number, digits = 0, base = Math.pow(10, digits)): number => {
2
+ return Math.round(base * number) / base;
3
+ };
@@ -0,0 +1,40 @@
1
+ const split = (str: string, mode: 'rgba' | 'hsva') => {
2
+ // 12,32,43 => [12,32,43]
3
+ const reg = /^\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,?\s*([\d.]*)\s*$/;
4
+ const res = str.match(reg);
5
+ const result: number[] = [];
6
+ result[0] = Number(res?.[1]);
7
+ result[1] = Number(res?.[2]);
8
+ result[2] = Number(res?.[3]);
9
+ result[3] = Number((res?.[4] === undefined || res?.[4] === '') ? 1 : res?.[4]);
10
+
11
+ const check = (a: number, max: number) => {
12
+ return !(isNaN(a) || a < 0 || a > max);
13
+ };
14
+
15
+ const ok = check(result[0], mode === 'rgba' ? 255 : 360)
16
+ && check(result[1], mode === 'rgba' ? 255 : 100)
17
+ && check(result[2], mode === 'rgba' ? 255 : 100)
18
+ && check(result[3], 1);
19
+ if (ok) {
20
+ if (mode === 'rgba') {
21
+ return {
22
+ r: result[0],
23
+ g: result[1],
24
+ b: result[2],
25
+ a: result[3]
26
+ };
27
+ } else {
28
+ return {
29
+ h: result[0],
30
+ s: result[1],
31
+ v: result[2],
32
+ a: result[3]
33
+ };
34
+ }
35
+ } else {
36
+ return false;
37
+ }
38
+ };
39
+
40
+ export default split;
@@ -0,0 +1,28 @@
1
+ $radius-colorPicker-topLeft:8px; // 圆角 - 左上
2
+ $radius-colorPicker-topRight:8px; // 圆角 - 右上
3
+ $radius-colorPicker-bottomLeft:0px; // 圆角 - 左下
4
+ $radius-colorPicker-bottomRight:0px; // 圆角 - 右下
5
+ $radius-colorPicker-handle:var(--semi-border-radius-full); // 圆角 - 拖拽把手
6
+ $radius-colorPicker-alphaSliderInner:4px; // 圆角 - 透明度 Slider
7
+ $radius-colorPicker-demoBlock: 4px; // 圆角 - 颜色手动输入区域左侧当前选中颜色色块
8
+ $radius-colorPicker-defaultTrigger:4px; // 默认 trigger 圆角
9
+
10
+
11
+ $width-colorPicker_handle-border: 2px; // 把手宽度
12
+ $width-colorPicker-colorPickerInputNumber:58px; // 数组输入器宽度
13
+ $width-colorPicker-formatSelect:80px; // 格式选择下拉 Select 宽度
14
+ $width-colorPicker-defaultTrigger: 24px; // 默认 trigger 大小
15
+
16
+ $color-colorPicker_handle-border:var(--semi-color-white); // 把手边框颜色
17
+
18
+
19
+ $spacing-colorPicker_inputNumberSuffix-horizontal:4px; // 数字输入框后百分比水平距离
20
+ $spacing-colorPicker_inputGroup-marginLeft:4px; // 颜色手动输入区域 左侧距离色块距离
21
+ $spacing-colorPicker_popover-padding:8px; // 弹层模式时整体内边距
22
+ $spacing-colorPicker_inputNumberSuffix-vertical:4px; // 数字输入框后百分比垂直距离
23
+ $spacing-colorPicker_slider-marginTop:6px; // 滑动选择器上边距
24
+ $spacing-colorPicker_dataPart-marginTop:8px; // 颜色手动输入区域 上边距
25
+
26
+
27
+ $font-colorPicker_inputNumberSuffix-fontSize:14px; // 颜色手动输入区域百分比字体大小
28
+
@@ -209,23 +209,28 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
209
209
  };
210
210
 
211
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;
212
+ let angle = rotation % 360;
213
+ angle < 0 && (angle = 360 + angle);
214
+ switch (angle) {
215
+ case 0:
216
+ newTranslateX = (e.offsetX - 0.5 * width) * (1 - newZoom / currZoom) + translate.x;
217
+ newTranslateY = (e.offsetY - 0.5 * height) * (1 - newZoom / currZoom) + translate.y;
218
+ break;
219
+ case 90:
220
+ newTranslateX = (0.5 * height - e.offsetY) * (1 - newZoom / currZoom) + translate.x;
221
+ newTranslateY = (e.offsetX - 0.5 * width) * (1 - newZoom / currZoom) + translate.y;
222
+ break;
223
+ case 180:
224
+ newTranslateX = (0.5 * width - e.offsetX) * (1 - newZoom / currZoom) + translate.x;
225
+ newTranslateY = (0.5 * height - e.offsetY) * (1 - newZoom / currZoom) + translate.y;
226
+ break;
227
+ case 270:
228
+ newTranslateX = (e.offsetY - 0.5 * height) * (1 - newZoom / currZoom) + translate.x;
229
+ newTranslateY = (0.5 * width - e.offsetX ) * (1 - newZoom / currZoom) + translate.y;
230
+ break;
231
+ default:
232
+ break;
233
+ }
229
234
  }
230
235
 
231
236
  const newTranslate = this.getSafeTranslate(newImageBound.width, newImageBound.height, newTranslateX, newTranslateY);
@@ -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() {
@@ -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;
@@ -0,0 +1,42 @@
1
+ import BaseFoundation, { DefaultAdapter } from "../base/foundation";
2
+ import ColorPickerFoundation from "./foundation";
3
+ import { HsvaColor } from "./interface";
4
+ export interface ColorChooseAreaBaseProps {
5
+ hsva: HsvaColor;
6
+ onChange: (newColor: {
7
+ s: number;
8
+ v: number;
9
+ }) => void;
10
+ handleSize: number;
11
+ width: number;
12
+ height: number;
13
+ foundation: ColorPickerFoundation;
14
+ }
15
+ export interface ColorChooseAreaBaseState {
16
+ handlePosition: {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ isHandleGrabbing: boolean;
21
+ }
22
+ export interface ColorChooseAreaAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
23
+ getColorPickerFoundation: () => ColorPickerFoundation;
24
+ handleMouseDown: (e: any) => void;
25
+ handleMouseUp: (e: any) => void;
26
+ getDOM: () => HTMLDivElement;
27
+ notifyChange: (newColor: {
28
+ s: number;
29
+ v: number;
30
+ }) => void;
31
+ }
32
+ declare class ColorChooseAreaFoundation extends BaseFoundation<ColorChooseAreaAdapter<ColorChooseAreaBaseProps, ColorChooseAreaBaseState>, ColorChooseAreaBaseProps, ColorChooseAreaBaseState> {
33
+ constructor(adapter: ColorChooseAreaAdapter<ColorChooseAreaBaseProps, ColorChooseAreaBaseState>);
34
+ getHandlePositionByHSVA: () => {
35
+ x: number;
36
+ y: number;
37
+ };
38
+ handleMouseDown: (e: any) => void;
39
+ handleMouseUp: (e: any) => void;
40
+ setHandlePositionByMousePosition: (e: globalThis.MouseEvent) => void;
41
+ }
42
+ export default ColorChooseAreaFoundation;
@@ -0,0 +1,62 @@
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 ColorChooseAreaFoundation extends _foundation.default {
10
+ constructor(adapter) {
11
+ super(Object.assign({}, adapter));
12
+ this.getHandlePositionByHSVA = () => {
13
+ const {
14
+ hsva,
15
+ width,
16
+ height,
17
+ handleSize
18
+ } = this.getProps();
19
+ return this._adapter.getColorPickerFoundation().getHandlePositionByHSVA(hsva, {
20
+ width: width,
21
+ height: height
22
+ }, handleSize);
23
+ };
24
+ this.handleMouseDown = e => {
25
+ this._adapter.handleMouseDown(e);
26
+ };
27
+ this.handleMouseUp = e => {
28
+ this._adapter.handleMouseUp(e);
29
+ };
30
+ this.setHandlePositionByMousePosition = e => {
31
+ var _a;
32
+ const rect = (_a = this._adapter.getDOM()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
33
+ if (!rect) {
34
+ return;
35
+ }
36
+ const mousePosition = {
37
+ x: e.clientX - rect.x,
38
+ y: e.clientY - rect.y
39
+ };
40
+ const {
41
+ width,
42
+ height,
43
+ handleSize
44
+ } = this.getProps();
45
+ const colorPickerFoundation = this._adapter.getColorPickerFoundation();
46
+ const handlePosition = colorPickerFoundation.getHandlePositionByMousePosition(mousePosition, {
47
+ width,
48
+ height
49
+ }, handleSize);
50
+ if (handlePosition) {
51
+ this.setState({
52
+ handlePosition
53
+ });
54
+ this._adapter.notifyChange({
55
+ s: Math.round(mousePosition.x / width * 100),
56
+ v: Math.round(100 - Math.min(Math.max(mousePosition.y / height, 0), 1) * 100)
57
+ });
58
+ }
59
+ };
60
+ }
61
+ }
62
+ var _default = exports.default = ColorChooseAreaFoundation;
@@ -0,0 +1,26 @@
1
+ import BaseFoundation, { DefaultAdapter } from "../base/foundation";
2
+ import ColorPickerFoundation from "./foundation";
3
+ export interface ColorSliderBaseProps {
4
+ width: number;
5
+ height: number;
6
+ hue: number;
7
+ handleSize: number;
8
+ foundation: ColorPickerFoundation;
9
+ }
10
+ export interface ColorSliderBaseState {
11
+ handlePosition: number;
12
+ isHandleGrabbing: boolean;
13
+ }
14
+ export interface ColorSliderAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
15
+ handleMouseDown: (e: any) => void;
16
+ handleMouseUp: (e: any) => void;
17
+ getColorPickerFoundation: () => ColorPickerFoundation;
18
+ getDOM: () => HTMLDivElement;
19
+ }
20
+ declare class ColorSliderFoundation extends BaseFoundation<ColorSliderAdapter<ColorSliderBaseProps, ColorSliderBaseState>, ColorSliderBaseProps, ColorSliderBaseState> {
21
+ constructor(adapter: ColorSliderAdapter<ColorSliderBaseProps, ColorSliderBaseState>);
22
+ handleMouseDown: (e: any) => void;
23
+ handleMouseUp: (e: any) => void;
24
+ setHandlePositionByMousePosition: (e: MouseEvent) => void;
25
+ }
26
+ export default ColorSliderFoundation;
@@ -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 ColorSliderFoundation 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
+ colorPickerFoundation.handleColorChangeByHandle({
31
+ h: Math.round(Math.min(Math.max(mousePosition / width, 0), 1) * 360)
32
+ });
33
+ const handlePosition = colorPickerFoundation.getColorHandlePositionByMousePosition(mousePosition, width, handleSize);
34
+ this.setState({
35
+ handlePosition
36
+ });
37
+ };
38
+ }
39
+ }
40
+ var _default = exports.default = ColorSliderFoundation;