@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
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { HsvaColor, RgbaColor } from './interface';
|
|
2
|
+
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
3
|
+
import {
|
|
4
|
+
hexToHsva,
|
|
5
|
+
hexToRgba,
|
|
6
|
+
hsvaToHex,
|
|
7
|
+
hsvaToHslaString,
|
|
8
|
+
hsvaToHslString,
|
|
9
|
+
hsvaToRgba, rgbaStringToHsva, rgbaStringToRgba,
|
|
10
|
+
rgbaToHex,
|
|
11
|
+
rgbaToHsva,
|
|
12
|
+
} from './utils/convert';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export type ColorValue = {
|
|
16
|
+
hsva: HsvaColor;
|
|
17
|
+
rgba: RgbaColor;
|
|
18
|
+
hex: string
|
|
19
|
+
}
|
|
20
|
+
export interface ColorPickerProps {
|
|
21
|
+
eyeDropper?: boolean;
|
|
22
|
+
defaultValue?: ColorValue;
|
|
23
|
+
value?: ColorValue;
|
|
24
|
+
onChange: (value: ColorValue) => void;
|
|
25
|
+
alpha: boolean;
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
defaultFormat: 'hex' | 'rgba' | 'hsva'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ColorPickerState {
|
|
32
|
+
currentColor: ColorValue
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export interface ColorPickerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
37
|
+
notifyChange: (value: ColorValue) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ColorPickerFoundation extends BaseFoundation<ColorPickerAdapter<ColorPickerProps, ColorPickerState>, ColorPickerProps, ColorPickerState> {
|
|
42
|
+
|
|
43
|
+
constructor(adapter: ColorPickerAdapter<ColorPickerProps, ColorPickerState>) {
|
|
44
|
+
super({
|
|
45
|
+
...adapter
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static hsvaToRgba = hsvaToRgba
|
|
50
|
+
static rgbaToHsva = rgbaToHsva
|
|
51
|
+
static rgbaToHex = rgbaToHex
|
|
52
|
+
static hsvaToHex = hsvaToHex
|
|
53
|
+
static hexToRgba = hexToRgba
|
|
54
|
+
static hexToHsva = hexToHsva
|
|
55
|
+
static hsvaToHslaString = hsvaToHslaString
|
|
56
|
+
static hsvaToHslString = hsvaToHslString
|
|
57
|
+
static rgbaStringToHsva = rgbaStringToHsva
|
|
58
|
+
static rgbaStringToRgba = rgbaStringToRgba
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
handleChangeH = (currentColor: ColorValue, newH: number) => {
|
|
62
|
+
|
|
63
|
+
const hsva = {
|
|
64
|
+
...currentColor.hsva,
|
|
65
|
+
h: newH
|
|
66
|
+
};
|
|
67
|
+
const rgba = hsvaToRgba(hsva);
|
|
68
|
+
const hex = hsvaToHex(hsva);
|
|
69
|
+
|
|
70
|
+
const newCurrentColor = {
|
|
71
|
+
rgba,
|
|
72
|
+
hsva,
|
|
73
|
+
hex
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this._adapter.notifyChange(newCurrentColor);
|
|
77
|
+
if (!this.getProp("value")) {
|
|
78
|
+
this._adapter.setState({ currentColor: newCurrentColor });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
handleChangeA = (currentColor: ColorValue, newAlpha: number) => {
|
|
85
|
+
let alpha = this._adapter.getProp('alpha');
|
|
86
|
+
if (!alpha) {
|
|
87
|
+
newAlpha = 1;
|
|
88
|
+
}
|
|
89
|
+
const rgba = {
|
|
90
|
+
...currentColor.rgba,
|
|
91
|
+
a: newAlpha
|
|
92
|
+
};
|
|
93
|
+
const hex = rgbaToHex(rgba);
|
|
94
|
+
currentColor = {
|
|
95
|
+
rgba,
|
|
96
|
+
hex: alpha ? hex : hex.slice(0, 7),
|
|
97
|
+
hsva: {
|
|
98
|
+
...currentColor.hsva,
|
|
99
|
+
a: newAlpha
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
this._adapter.notifyChange(currentColor);
|
|
103
|
+
if (!this.getProp("value")) {
|
|
104
|
+
this._adapter.setState({ currentColor: currentColor });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getCurrentColor = ()=>{
|
|
110
|
+
|
|
111
|
+
const value = this.getProp("value");
|
|
112
|
+
const currentColor = this.getState("currentColor");
|
|
113
|
+
return value || currentColor;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
handleChange = (color: HsvaColor|RgbaColor|string, format: 'hex'|'rgba'|'hsva')=>{
|
|
117
|
+
let currentColor;
|
|
118
|
+
|
|
119
|
+
if (format === 'hsva') {
|
|
120
|
+
currentColor = {
|
|
121
|
+
hsva: color as HsvaColor,
|
|
122
|
+
rgba: ColorPickerFoundation.hsvaToRgba(color as HsvaColor),
|
|
123
|
+
hex: ColorPickerFoundation.hsvaToHex(color as HsvaColor)
|
|
124
|
+
};
|
|
125
|
+
} else if (format === 'rgba') {
|
|
126
|
+
currentColor = {
|
|
127
|
+
rgba: color as RgbaColor,
|
|
128
|
+
hsva: ColorPickerFoundation.rgbaToHsva(color as RgbaColor),
|
|
129
|
+
hex: ColorPickerFoundation.rgbaToHex(color as RgbaColor)
|
|
130
|
+
};
|
|
131
|
+
} else if (format === 'hex') {
|
|
132
|
+
currentColor = {
|
|
133
|
+
hex: color as string,
|
|
134
|
+
hsva: ColorPickerFoundation.hexToHsva(color as string),
|
|
135
|
+
rgba: ColorPickerFoundation.hexToRgba(color as string)
|
|
136
|
+
};
|
|
137
|
+
} else {
|
|
138
|
+
throw new Error('format error');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this._adapter.notifyChange(currentColor);
|
|
142
|
+
if (!this.getProp("value")) {
|
|
143
|
+
this._adapter.setState({ currentColor: currentColor });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
handleAlphaChangeByHandle = (newAlpha: {a: number})=>{
|
|
150
|
+
this.handleChangeA(this.getCurrentColor(), newAlpha.a);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
handleColorChangeByHandle = (newHue: {h: number})=>{
|
|
154
|
+
this.handleChangeH(this.getCurrentColor(), newHue.h);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
getHandlePositionByHSVA = (hsva: HsvaColor, { width, height }: {width: number;height: number}, handleSize: number)=>{
|
|
159
|
+
|
|
160
|
+
const defaultColorPosition = { x: hsva.s / 100 * width, y: (1 - hsva.v / 100) * height };
|
|
161
|
+
return { x: defaultColorPosition.x - handleSize / 2, y: defaultColorPosition.y - handleSize / 2 };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getHandlePositionByMousePosition = (mousePosition: {x: number;y: number}, { width, height }: {width: number;height: number}, handleSize: number)=>{
|
|
165
|
+
if (mousePosition.x > width || mousePosition.x < 0) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (mousePosition.y > height || mousePosition.y < 0) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const handlePosition = {
|
|
174
|
+
x: mousePosition.x - handleSize / 2,
|
|
175
|
+
y: mousePosition.y - handleSize / 2
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return handlePosition;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
getAlphaHandlePositionByMousePosition = (mousePosition: number, width: number, handleSize: number)=>{
|
|
183
|
+
if (mousePosition < 0 || mousePosition > width) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return mousePosition - handleSize / 2;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getColorHandlePositionByMousePosition = (mousePosition: number, width: number, handleSize: number)=>{
|
|
190
|
+
if (mousePosition < 0 || mousePosition > width) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return mousePosition - handleSize / 2;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export default ColorPickerFoundation;
|
|
206
|
+
|
|
@@ -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,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
|
+
|
package/datePicker/foundation.ts
CHANGED
|
@@ -436,7 +436,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
436
436
|
*/
|
|
437
437
|
resetInnerSelectedStates(willUpdateDates?: Date[]) {
|
|
438
438
|
const { value } = this._adapter.getStates();
|
|
439
|
-
const needResetCachedSelectedValue = !this.isCachedSelectedValueValid(willUpdateDates) || this._adapter.needConfirm() && !this.clickConfirmButton;
|
|
439
|
+
const needResetCachedSelectedValue = isNullOrUndefined(willUpdateDates) || !this.isCachedSelectedValueValid(willUpdateDates) || this._adapter.needConfirm() && !this.clickConfirmButton;
|
|
440
440
|
if (needResetCachedSelectedValue) {
|
|
441
441
|
this.resetCachedSelectedValue(value);
|
|
442
442
|
}
|
package/image/image.scss
CHANGED
|
@@ -100,6 +100,7 @@ $module: #{$prefix}-image;
|
|
|
100
100
|
align-items: center;
|
|
101
101
|
padding: $spacing-image_preview_header-paddingY $spacing-image_preview_header-paddingX;
|
|
102
102
|
z-index: $z-image_preview_header;
|
|
103
|
+
pointer-events: none;
|
|
103
104
|
|
|
104
105
|
&-title {
|
|
105
106
|
flex: 1;
|
|
@@ -113,6 +114,7 @@ $module: #{$prefix}-image;
|
|
|
113
114
|
width: $width-image_preview_header_close;
|
|
114
115
|
height: $height-image_preview_header_close;
|
|
115
116
|
border-radius: 50%;
|
|
117
|
+
pointer-events: auto;
|
|
116
118
|
|
|
117
119
|
&:hover {
|
|
118
120
|
background-color: $color-image_header_close-bg;
|
|
@@ -192,11 +194,14 @@ $module: #{$prefix}-image;
|
|
|
192
194
|
&-image {
|
|
193
195
|
position: relative;
|
|
194
196
|
height: 100%;
|
|
197
|
+
display: flex;
|
|
198
|
+
justify-content: center;
|
|
199
|
+
align-items: center;
|
|
195
200
|
|
|
196
201
|
&-img {
|
|
197
202
|
position: absolute;
|
|
198
203
|
transform: scale3d($transform_scale3d-image_preview_image_img) $transform_rotate-image_preview_image_img;
|
|
199
|
-
transition: transform $transition_duration-image_preview_image_img $transition_delay-image_preview_image_img;
|
|
204
|
+
// transition: transform $transition_duration-image_preview_image_img $transition_delay-image_preview_image_img;
|
|
200
205
|
z-index: 0;
|
|
201
206
|
user-select: none;
|
|
202
207
|
}
|