@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
|
@@ -50,6 +50,7 @@ const {
|
|
|
50
50
|
class UploadFoundation extends _foundation.default {
|
|
51
51
|
constructor(adapter) {
|
|
52
52
|
super(Object.assign({}, adapter));
|
|
53
|
+
this.destroyState = false;
|
|
53
54
|
}
|
|
54
55
|
init() {
|
|
55
56
|
const {
|
|
@@ -69,6 +70,7 @@ class UploadFoundation extends _foundation.default {
|
|
|
69
70
|
if (!disabled) {
|
|
70
71
|
this.unbindPastingHandler();
|
|
71
72
|
}
|
|
73
|
+
this.destroyState = true;
|
|
72
74
|
}
|
|
73
75
|
getError(_ref) {
|
|
74
76
|
let {
|
|
@@ -577,22 +579,36 @@ class UploadFoundation extends _foundation.default {
|
|
|
577
579
|
xhr.withCredentials = true;
|
|
578
580
|
}
|
|
579
581
|
if (xhr.upload) {
|
|
580
|
-
xhr.upload.onprogress = e =>
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
582
|
+
xhr.upload.onprogress = e => {
|
|
583
|
+
if (!this.destroyState) {
|
|
584
|
+
this.handleProgress({
|
|
585
|
+
e,
|
|
586
|
+
fileInstance
|
|
587
|
+
});
|
|
588
|
+
} else {
|
|
589
|
+
xhr.abort();
|
|
590
|
+
}
|
|
591
|
+
};
|
|
584
592
|
}
|
|
585
593
|
// Callback function after upload is completed
|
|
586
|
-
xhr.onload = e =>
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
594
|
+
xhr.onload = e => {
|
|
595
|
+
if (!this.destroyState) {
|
|
596
|
+
this.handleOnLoad({
|
|
597
|
+
e,
|
|
598
|
+
xhr,
|
|
599
|
+
fileInstance
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
xhr.onerror = e => {
|
|
604
|
+
if (!this.destroyState) {
|
|
605
|
+
this.handleError({
|
|
606
|
+
e,
|
|
607
|
+
xhr,
|
|
608
|
+
fileInstance
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
};
|
|
596
612
|
// add headers
|
|
597
613
|
let headers = option.headers || {};
|
|
598
614
|
if (typeof headers === 'function') {
|
|
@@ -146,6 +146,24 @@ export default class CalendarFoundation extends BaseFoundation {
|
|
|
146
146
|
parsed.day = [];
|
|
147
147
|
}
|
|
148
148
|
parsed.day = parsed.day.map(item => renderDailyEvent(item));
|
|
149
|
+
// 将 startPos & endPos 完全相同的事件编为一组
|
|
150
|
+
const sameTimeRangeGroup = parsed.day.reduce((acc, item) => {
|
|
151
|
+
const key = `${item.startPos}-${item.endPos}`;
|
|
152
|
+
if (!acc[key]) {
|
|
153
|
+
acc[key] = [];
|
|
154
|
+
}
|
|
155
|
+
acc[key].push(item);
|
|
156
|
+
return acc;
|
|
157
|
+
}, {});
|
|
158
|
+
// 计算每个 item 的 left 值,
|
|
159
|
+
const eventCountMap = {};
|
|
160
|
+
parsed.day = parsed.day.map(item => {
|
|
161
|
+
const key = `${item.startPos}-${item.endPos}`;
|
|
162
|
+
let curCount = eventCountMap[key];
|
|
163
|
+
eventCountMap[key] = curCount === undefined ? 0 : ++curCount;
|
|
164
|
+
item.left = curCount !== 0 ? `${curCount / sameTimeRangeGroup[key].length * 100}%` : 0;
|
|
165
|
+
return item;
|
|
166
|
+
});
|
|
149
167
|
return parsed;
|
|
150
168
|
}
|
|
151
169
|
parseDailyEvents() {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/// <reference types="lodash" />
|
|
3
2
|
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
4
3
|
export interface Content {
|
|
@@ -27,7 +26,7 @@ export interface Message {
|
|
|
27
26
|
[x: string]: any;
|
|
28
27
|
}
|
|
29
28
|
export interface ChatAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
30
|
-
getContainerRef: () =>
|
|
29
|
+
getContainerRef: () => HTMLDivElement;
|
|
31
30
|
setWheelScroll: (flag: boolean) => void;
|
|
32
31
|
notifyChatsChange: (chats: Message[]) => void;
|
|
33
32
|
notifyLikeMessage: (message: Message) => void;
|
|
@@ -26,16 +26,14 @@ export default class ChatFoundation extends BaseFoundation {
|
|
|
26
26
|
this._adapter.notifyStopGenerate(e);
|
|
27
27
|
};
|
|
28
28
|
this.scrollToBottomImmediately = () => {
|
|
29
|
-
const
|
|
30
|
-
const element = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current;
|
|
29
|
+
const element = this._adapter.getContainerRef();
|
|
31
30
|
if (element) {
|
|
32
31
|
element.scrollTop = element.scrollHeight;
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
34
|
this.scrollToBottomWithAnimation = () => {
|
|
36
35
|
const duration = SCROLL_ANIMATION_TIME;
|
|
37
|
-
const
|
|
38
|
-
const element = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current;
|
|
36
|
+
const element = this._adapter.getContainerRef();
|
|
39
37
|
if (!element) {
|
|
40
38
|
return;
|
|
41
39
|
}
|
|
@@ -61,9 +59,6 @@ export default class ChatFoundation extends BaseFoundation {
|
|
|
61
59
|
this.animation.start();
|
|
62
60
|
};
|
|
63
61
|
this.containerScroll = e => {
|
|
64
|
-
if (e.target !== e.currentTarget) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
62
|
e.persist();
|
|
68
63
|
const update = () => {
|
|
69
64
|
this.getScroll(e.target);
|
|
@@ -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,33 @@
|
|
|
1
|
+
import BaseFoundation from "../base/foundation";
|
|
2
|
+
class AlphaSliderFoundation extends BaseFoundation {
|
|
3
|
+
constructor(adapter) {
|
|
4
|
+
super(Object.assign({}, adapter));
|
|
5
|
+
this.handleMouseDown = e => {
|
|
6
|
+
this._adapter.handleMouseDown(e);
|
|
7
|
+
};
|
|
8
|
+
this.handleMouseUp = e => {
|
|
9
|
+
this._adapter.handleMouseUp(e);
|
|
10
|
+
};
|
|
11
|
+
this.setHandlePositionByMousePosition = e => {
|
|
12
|
+
var _a;
|
|
13
|
+
const rect = (_a = this._adapter.getDOM()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
14
|
+
if (!rect) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const {
|
|
18
|
+
width,
|
|
19
|
+
handleSize
|
|
20
|
+
} = this._adapter.getProps();
|
|
21
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
22
|
+
const mousePosition = e.clientX - rect.x;
|
|
23
|
+
const handlePosition = colorPickerFoundation.getAlphaHandlePositionByMousePosition(mousePosition, width, handleSize);
|
|
24
|
+
colorPickerFoundation.handleAlphaChangeByHandle({
|
|
25
|
+
a: Number(Math.min(Math.max(mousePosition / width, 0), 1).toFixed(2))
|
|
26
|
+
});
|
|
27
|
+
this.setState({
|
|
28
|
+
handlePosition
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export 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,55 @@
|
|
|
1
|
+
import BaseFoundation from "../base/foundation";
|
|
2
|
+
class ColorChooseAreaFoundation extends BaseFoundation {
|
|
3
|
+
constructor(adapter) {
|
|
4
|
+
super(Object.assign({}, adapter));
|
|
5
|
+
this.getHandlePositionByHSVA = () => {
|
|
6
|
+
const {
|
|
7
|
+
hsva,
|
|
8
|
+
width,
|
|
9
|
+
height,
|
|
10
|
+
handleSize
|
|
11
|
+
} = this.getProps();
|
|
12
|
+
return this._adapter.getColorPickerFoundation().getHandlePositionByHSVA(hsva, {
|
|
13
|
+
width: width,
|
|
14
|
+
height: height
|
|
15
|
+
}, handleSize);
|
|
16
|
+
};
|
|
17
|
+
this.handleMouseDown = e => {
|
|
18
|
+
this._adapter.handleMouseDown(e);
|
|
19
|
+
};
|
|
20
|
+
this.handleMouseUp = e => {
|
|
21
|
+
this._adapter.handleMouseUp(e);
|
|
22
|
+
};
|
|
23
|
+
this.setHandlePositionByMousePosition = e => {
|
|
24
|
+
var _a;
|
|
25
|
+
const rect = (_a = this._adapter.getDOM()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
26
|
+
if (!rect) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const mousePosition = {
|
|
30
|
+
x: e.clientX - rect.x,
|
|
31
|
+
y: e.clientY - rect.y
|
|
32
|
+
};
|
|
33
|
+
const {
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
handleSize
|
|
37
|
+
} = this.getProps();
|
|
38
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
39
|
+
const handlePosition = colorPickerFoundation.getHandlePositionByMousePosition(mousePosition, {
|
|
40
|
+
width,
|
|
41
|
+
height
|
|
42
|
+
}, handleSize);
|
|
43
|
+
if (handlePosition) {
|
|
44
|
+
this.setState({
|
|
45
|
+
handlePosition
|
|
46
|
+
});
|
|
47
|
+
this._adapter.notifyChange({
|
|
48
|
+
s: Math.round(mousePosition.x / width * 100),
|
|
49
|
+
v: Math.round(100 - Math.min(Math.max(mousePosition.y / height, 0), 1) * 100)
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export 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,33 @@
|
|
|
1
|
+
import BaseFoundation from "../base/foundation";
|
|
2
|
+
class ColorSliderFoundation extends BaseFoundation {
|
|
3
|
+
constructor(adapter) {
|
|
4
|
+
super(Object.assign({}, adapter));
|
|
5
|
+
this.handleMouseDown = e => {
|
|
6
|
+
this._adapter.handleMouseDown(e);
|
|
7
|
+
};
|
|
8
|
+
this.handleMouseUp = e => {
|
|
9
|
+
this._adapter.handleMouseUp(e);
|
|
10
|
+
};
|
|
11
|
+
this.setHandlePositionByMousePosition = e => {
|
|
12
|
+
var _a;
|
|
13
|
+
const rect = (_a = this._adapter.getDOM()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
14
|
+
if (!rect) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const {
|
|
18
|
+
width,
|
|
19
|
+
handleSize
|
|
20
|
+
} = this._adapter.getProps();
|
|
21
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
22
|
+
const mousePosition = e.clientX - rect.x;
|
|
23
|
+
colorPickerFoundation.handleColorChangeByHandle({
|
|
24
|
+
h: Math.round(Math.min(Math.max(mousePosition / width, 0), 1) * 360)
|
|
25
|
+
});
|
|
26
|
+
const handlePosition = colorPickerFoundation.getColorHandlePositionByMousePosition(mousePosition, width, handleSize);
|
|
27
|
+
this.setState({
|
|
28
|
+
handlePosition
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default ColorSliderFoundation;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
2
|
+
import ColorPickerFoundation, { ColorPickerProps } from "./foundation";
|
|
3
|
+
import { HsvaColor, RgbaColor } from "./interface";
|
|
4
|
+
type Value = ColorPickerProps['value'];
|
|
5
|
+
export interface DataPartBaseProps {
|
|
6
|
+
currentColor: Value;
|
|
7
|
+
defaultFormat: 'hex' | 'rgba' | 'hsva';
|
|
8
|
+
width: number;
|
|
9
|
+
alpha?: boolean;
|
|
10
|
+
foundation: ColorPickerFoundation;
|
|
11
|
+
eyeDropper: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface DataPartBaseState {
|
|
14
|
+
format: 'hex' | 'rgba' | 'hsva';
|
|
15
|
+
inputValue: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DataPartAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
18
|
+
getColorPickerFoundation: () => ColorPickerFoundation;
|
|
19
|
+
}
|
|
20
|
+
declare class DataPartFoundation extends BaseFoundation<DataPartAdapter<DataPartBaseProps, DataPartBaseState>, DataPartBaseProps, DataPartBaseState> {
|
|
21
|
+
constructor(adapter: DataPartAdapter<DataPartBaseProps, DataPartBaseState>);
|
|
22
|
+
getInputValue: () => string;
|
|
23
|
+
getValueByInputValue: (value: string) => string | false | HsvaColor | RgbaColor;
|
|
24
|
+
handlePickValueWithStraw: () => Promise<void>;
|
|
25
|
+
handleInputValueChange: (value: string) => void;
|
|
26
|
+
handleFormatChange: (format: DataPartBaseState['format']) => void;
|
|
27
|
+
}
|
|
28
|
+
export default DataPartFoundation;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
import BaseFoundation from "../base/foundation";
|
|
29
|
+
import ColorPickerFoundation from "./foundation";
|
|
30
|
+
import split from "./utils/split";
|
|
31
|
+
class DataPartFoundation extends BaseFoundation {
|
|
32
|
+
constructor(adapter) {
|
|
33
|
+
super(Object.assign({}, adapter));
|
|
34
|
+
this.getInputValue = () => {
|
|
35
|
+
const {
|
|
36
|
+
currentColor
|
|
37
|
+
} = this._adapter.getProps();
|
|
38
|
+
const {
|
|
39
|
+
format
|
|
40
|
+
} = this._adapter.getStates();
|
|
41
|
+
const rgba = currentColor.rgba;
|
|
42
|
+
const hsva = currentColor.hsva;
|
|
43
|
+
const hex = currentColor.hex;
|
|
44
|
+
if (format === 'rgba') {
|
|
45
|
+
return `${rgba.r},${rgba.g},${rgba.b}`;
|
|
46
|
+
} else if (format === 'hsva') {
|
|
47
|
+
return `${hsva.h},${hsva.s},${hsva.v}`;
|
|
48
|
+
} else {
|
|
49
|
+
return hex.slice(0, 7);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.getValueByInputValue = value => {
|
|
53
|
+
const {
|
|
54
|
+
format
|
|
55
|
+
} = this.getStates();
|
|
56
|
+
if (format === 'rgba') {
|
|
57
|
+
const result = split(value, format);
|
|
58
|
+
if (result) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
} else if (format === 'hsva') {
|
|
62
|
+
const result = split(value, format);
|
|
63
|
+
if (result) {
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
} else if (format === 'hex') {
|
|
67
|
+
// hack chrome bug, format mismatch with w3c.
|
|
68
|
+
if (!value.startsWith('#')) {
|
|
69
|
+
value = '#' + value;
|
|
70
|
+
}
|
|
71
|
+
if (/#[\d\w]{6,8}/.test(value)) {
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
};
|
|
77
|
+
this.handlePickValueWithStraw = () => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
79
|
+
if (!window['EyeDropper']) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
//@ts-ignore
|
|
83
|
+
const eyeDropper = new EyeDropper();
|
|
84
|
+
try {
|
|
85
|
+
const result = yield eyeDropper.open();
|
|
86
|
+
const color = result['sRGBHex'];
|
|
87
|
+
if (color.startsWith("#")) {
|
|
88
|
+
colorPickerFoundation.handleChange(color, 'hex');
|
|
89
|
+
} else if (color.startsWith('rgba')) {
|
|
90
|
+
const rgba = ColorPickerFoundation.rgbaStringToRgba(color);
|
|
91
|
+
rgba.a = 1;
|
|
92
|
+
colorPickerFoundation.handleChange(rgba, 'rgba');
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {}
|
|
95
|
+
});
|
|
96
|
+
this.handleInputValueChange = value => {
|
|
97
|
+
this._adapter.setState({
|
|
98
|
+
inputValue: value
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
this.handleFormatChange = format => {
|
|
102
|
+
this._adapter.setState({
|
|
103
|
+
format
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export default DataPartFoundation;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* shadow */
|
|
2
|
+
/* sizing */
|
|
3
|
+
/* spacing */
|
|
4
|
+
.semi-colorPicker-colorChooseArea {
|
|
5
|
+
/**
|
|
6
|
+
* Referrer from https://github.com/web-padawan/vanilla-colorful/blob/5d219ee360ae2f29534864b28ca9e6074233b9ce/src/lib/styles/saturation.css
|
|
7
|
+
*/
|
|
8
|
+
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
|
|
9
|
+
position: relative;
|
|
10
|
+
flex-grow: 1;
|
|
11
|
+
border-color: transparent;
|
|
12
|
+
border-radius: 8px 8px 0px 0px;
|
|
13
|
+
background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)), linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
|
|
14
|
+
}
|
|
15
|
+
.semi-colorPicker-handle {
|
|
16
|
+
border-radius: var(--semi-border-radius-full);
|
|
17
|
+
border: 2px solid var(--semi-color-white);
|
|
18
|
+
position: absolute;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
cursor: grab;
|
|
21
|
+
}
|
|
22
|
+
.semi-colorPicker-alphaSlider {
|
|
23
|
+
position: relative;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
margin-top: 6px;
|
|
26
|
+
border-radius: var(--semi-border-radius-full);
|
|
27
|
+
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><rect x="8" width="8" height="8"/><rect y="8" width="8" height="8"/></svg>');
|
|
28
|
+
}
|
|
29
|
+
.semi-colorPicker-alphaSlider .semi-colorPicker-alphaSliderInner {
|
|
30
|
+
width: 100%;
|
|
31
|
+
height: 100%;
|
|
32
|
+
border-radius: 4px;
|
|
33
|
+
}
|
|
34
|
+
.semi-colorPicker-alphaSlider .semi-colorPicker-alphaHandle {
|
|
35
|
+
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><rect x="8" width="8" height="8"/><rect y="8" width="8" height="8"/></svg>');
|
|
36
|
+
border-radius: var(--semi-border-radius-full);
|
|
37
|
+
border: 2px solid var(--semi-color-white);
|
|
38
|
+
position: absolute;
|
|
39
|
+
box-sizing: border-box;
|
|
40
|
+
cursor: grab;
|
|
41
|
+
}
|
|
42
|
+
.semi-colorPicker-colorSlider {
|
|
43
|
+
position: relative;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
margin-top: 6px;
|
|
46
|
+
border-radius: var(--semi-border-radius-full);
|
|
47
|
+
background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
|
|
48
|
+
}
|
|
49
|
+
.semi-colorPicker-dataPart {
|
|
50
|
+
margin-top: 8px;
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
}
|
|
54
|
+
.semi-colorPicker-dataPart .semi-colorPicker-colorDemoBlock {
|
|
55
|
+
border-radius: 4px;
|
|
56
|
+
}
|
|
57
|
+
.semi-colorPicker-dataPart .semi-colorPicker-inputGroup {
|
|
58
|
+
margin-left: 4px;
|
|
59
|
+
width: 100%;
|
|
60
|
+
flex: 1;
|
|
61
|
+
flex-wrap: nowrap;
|
|
62
|
+
}
|
|
63
|
+
.semi-colorPicker-dataPart .semi-colorPicker-inputGroup .semi-colorPicker-colorPickerInput {
|
|
64
|
+
flex: 1;
|
|
65
|
+
}
|
|
66
|
+
.semi-colorPicker-dataPart .semi-colorPicker-inputGroup .semi-colorPicker-colorPickerInputNumber {
|
|
67
|
+
width: 58px;
|
|
68
|
+
}
|
|
69
|
+
.semi-colorPicker-dataPart .semi-colorPicker-inputGroup .semi-colorPicker-colorPickerInputNumber .semi-colorPicker-inputNumberSuffix {
|
|
70
|
+
font-size: 14px;
|
|
71
|
+
padding: 4px 4px;
|
|
72
|
+
}
|
|
73
|
+
.semi-colorPicker-dataPart .semi-colorPicker-formatSelect {
|
|
74
|
+
width: 80px;
|
|
75
|
+
}
|
|
76
|
+
.semi-colorPicker-popover {
|
|
77
|
+
padding: 8px;
|
|
78
|
+
}
|
|
79
|
+
.semi-colorPicker-popover-defaultChildren {
|
|
80
|
+
width: 24px;
|
|
81
|
+
height: 24px;
|
|
82
|
+
border-radius: 4px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|