wedux-ui 0.1.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/LICENSE +21 -0
- package/README.md +184 -0
- package/miniprogram_dist/behaviors/formField.js +35 -0
- package/miniprogram_dist/components/avatar/avatar.js +70 -0
- package/miniprogram_dist/components/avatar/avatar.json +4 -0
- package/miniprogram_dist/components/avatar/avatar.scss +68 -0
- package/miniprogram_dist/components/avatar/avatar.wxml +15 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.js +45 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.json +7 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.scss +4 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.wxml +3 -0
- package/miniprogram_dist/components/back-top/back-top.js +68 -0
- package/miniprogram_dist/components/back-top/back-top.json +4 -0
- package/miniprogram_dist/components/back-top/back-top.scss +43 -0
- package/miniprogram_dist/components/back-top/back-top.wxml +10 -0
- package/miniprogram_dist/components/badge/badge.js +100 -0
- package/miniprogram_dist/components/badge/badge.json +4 -0
- package/miniprogram_dist/components/badge/badge.scss +98 -0
- package/miniprogram_dist/components/badge/badge.wxml +11 -0
- package/miniprogram_dist/components/button/button.js +152 -0
- package/miniprogram_dist/components/button/button.json +4 -0
- package/miniprogram_dist/components/button/button.scss +499 -0
- package/miniprogram_dist/components/button/button.wxml +21 -0
- package/miniprogram_dist/components/button-group/button-group.js +51 -0
- package/miniprogram_dist/components/button-group/button-group.json +4 -0
- package/miniprogram_dist/components/button-group/button-group.scss +8 -0
- package/miniprogram_dist/components/button-group/button-group.wxml +3 -0
- package/miniprogram_dist/components/calendar/calendar.js +308 -0
- package/miniprogram_dist/components/calendar/calendar.json +4 -0
- package/miniprogram_dist/components/calendar/calendar.scss +141 -0
- package/miniprogram_dist/components/calendar/calendar.wxml +47 -0
- package/miniprogram_dist/components/card/card.js +44 -0
- package/miniprogram_dist/components/card/card.json +4 -0
- package/miniprogram_dist/components/card/card.scss +143 -0
- package/miniprogram_dist/components/card/card.wxml +31 -0
- package/miniprogram_dist/components/checkbox/checkbox.js +43 -0
- package/miniprogram_dist/components/checkbox/checkbox.json +4 -0
- package/miniprogram_dist/components/checkbox/checkbox.scss +77 -0
- package/miniprogram_dist/components/checkbox/checkbox.wxml +13 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.js +43 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.json +4 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.scss +39 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.wxml +8 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.js +84 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.json +4 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.scss +9 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.wxml +3 -0
- package/miniprogram_dist/components/color-picker/color-picker.js +348 -0
- package/miniprogram_dist/components/color-picker/color-picker.json +7 -0
- package/miniprogram_dist/components/color-picker/color-picker.scss +383 -0
- package/miniprogram_dist/components/color-picker/color-picker.wxml +232 -0
- package/miniprogram_dist/components/date-picker/date-picker.js +1289 -0
- package/miniprogram_dist/components/date-picker/date-picker.json +7 -0
- package/miniprogram_dist/components/date-picker/date-picker.scss +468 -0
- package/miniprogram_dist/components/date-picker/date-picker.wxml +214 -0
- package/miniprogram_dist/components/divider/divider.js +34 -0
- package/miniprogram_dist/components/divider/divider.json +4 -0
- package/miniprogram_dist/components/divider/divider.scss +75 -0
- package/miniprogram_dist/components/divider/divider.wxml +8 -0
- package/miniprogram_dist/components/drawer/drawer.js +104 -0
- package/miniprogram_dist/components/drawer/drawer.json +4 -0
- package/miniprogram_dist/components/drawer/drawer.scss +171 -0
- package/miniprogram_dist/components/drawer/drawer.wxml +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.js +38 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.json +4 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.scss +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.wxml +7 -0
- package/miniprogram_dist/components/flex/flex.js +81 -0
- package/miniprogram_dist/components/flex/flex.json +4 -0
- package/miniprogram_dist/components/flex/flex.scss +4 -0
- package/miniprogram_dist/components/flex/flex.wxml +3 -0
- package/miniprogram_dist/components/float-button/float-button.js +78 -0
- package/miniprogram_dist/components/float-button/float-button.json +4 -0
- package/miniprogram_dist/components/float-button/float-button.scss +54 -0
- package/miniprogram_dist/components/float-button/float-button.wxml +9 -0
- package/miniprogram_dist/components/form/form.js +142 -0
- package/miniprogram_dist/components/form/form.json +4 -0
- package/miniprogram_dist/components/form/form.scss +11 -0
- package/miniprogram_dist/components/form/form.wxml +3 -0
- package/miniprogram_dist/components/form/validator.js +220 -0
- package/miniprogram_dist/components/form-item/form-item.js +240 -0
- package/miniprogram_dist/components/form-item/form-item.json +4 -0
- package/miniprogram_dist/components/form-item/form-item.scss +59 -0
- package/miniprogram_dist/components/form-item/form-item.wxml +33 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.js +54 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.json +4 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.scss +7 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.wxml +1 -0
- package/miniprogram_dist/components/h/h.js +60 -0
- package/miniprogram_dist/components/h/h.json +4 -0
- package/miniprogram_dist/components/h/h.scss +53 -0
- package/miniprogram_dist/components/h/h.wxml +1 -0
- package/miniprogram_dist/components/highlight/highlight.js +77 -0
- package/miniprogram_dist/components/highlight/highlight.json +4 -0
- package/miniprogram_dist/components/highlight/highlight.scss +8 -0
- package/miniprogram_dist/components/highlight/highlight.wxml +12 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.js +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.json +4 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.scss +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.wxml +12 -0
- package/miniprogram_dist/components/input/input.js +59 -0
- package/miniprogram_dist/components/input/input.json +4 -0
- package/miniprogram_dist/components/input/input.scss +96 -0
- package/miniprogram_dist/components/input/input.wxml +34 -0
- package/miniprogram_dist/components/input-otp/input-otp.js +106 -0
- package/miniprogram_dist/components/input-otp/input-otp.json +4 -0
- package/miniprogram_dist/components/input-otp/input-otp.scss +122 -0
- package/miniprogram_dist/components/input-otp/input-otp.wxml +38 -0
- package/miniprogram_dist/components/layout/layout.js +50 -0
- package/miniprogram_dist/components/layout/layout.json +4 -0
- package/miniprogram_dist/components/layout/layout.scss +10 -0
- package/miniprogram_dist/components/layout/layout.wxml +3 -0
- package/miniprogram_dist/components/layout-content/layout-content.js +47 -0
- package/miniprogram_dist/components/layout-content/layout-content.json +4 -0
- package/miniprogram_dist/components/layout-content/layout-content.scss +5 -0
- package/miniprogram_dist/components/layout-content/layout-content.wxml +13 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.js +59 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.json +4 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.scss +23 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.wxml +16 -0
- package/miniprogram_dist/components/layout-header/layout-header.js +59 -0
- package/miniprogram_dist/components/layout-header/layout-header.json +4 -0
- package/miniprogram_dist/components/layout-header/layout-header.scss +23 -0
- package/miniprogram_dist/components/layout-header/layout-header.wxml +16 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.js +48 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.json +4 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.scss +13 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.wxml +5 -0
- package/miniprogram_dist/components/list/list.js +55 -0
- package/miniprogram_dist/components/list/list.json +4 -0
- package/miniprogram_dist/components/list/list.scss +51 -0
- package/miniprogram_dist/components/list/list.wxml +9 -0
- package/miniprogram_dist/components/list-item/list-item.js +24 -0
- package/miniprogram_dist/components/list-item/list-item.json +4 -0
- package/miniprogram_dist/components/list-item/list-item.scss +51 -0
- package/miniprogram_dist/components/list-item/list-item.wxml +14 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.js +77 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.json +4 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.scss +63 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.wxml +35 -0
- package/miniprogram_dist/components/number-animation/number-animation.js +124 -0
- package/miniprogram_dist/components/number-animation/number-animation.json +4 -0
- package/miniprogram_dist/components/number-animation/number-animation.scss +3 -0
- package/miniprogram_dist/components/number-animation/number-animation.wxml +1 -0
- package/miniprogram_dist/components/popover/popover.js +183 -0
- package/miniprogram_dist/components/popover/popover.json +4 -0
- package/miniprogram_dist/components/popover/popover.scss +69 -0
- package/miniprogram_dist/components/popover/popover.wxml +19 -0
- package/miniprogram_dist/components/qr-code/qr-code.js +216 -0
- package/miniprogram_dist/components/qr-code/qr-code.json +4 -0
- package/miniprogram_dist/components/qr-code/qr-code.scss +8 -0
- package/miniprogram_dist/components/qr-code/qr-code.wxml +16 -0
- package/miniprogram_dist/components/radio/radio.js +38 -0
- package/miniprogram_dist/components/radio/radio.json +4 -0
- package/miniprogram_dist/components/radio/radio.scss +50 -0
- package/miniprogram_dist/components/radio/radio.wxml +12 -0
- package/miniprogram_dist/components/radio-button/radio-button.js +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.json +4 -0
- package/miniprogram_dist/components/radio-button/radio-button.scss +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.wxml +8 -0
- package/miniprogram_dist/components/radio-group/radio-group.js +72 -0
- package/miniprogram_dist/components/radio-group/radio-group.json +4 -0
- package/miniprogram_dist/components/radio-group/radio-group.scss +9 -0
- package/miniprogram_dist/components/radio-group/radio-group.wxml +3 -0
- package/miniprogram_dist/components/rate/rate.js +90 -0
- package/miniprogram_dist/components/rate/rate.json +4 -0
- package/miniprogram_dist/components/rate/rate.scss +59 -0
- package/miniprogram_dist/components/rate/rate.wxml +16 -0
- package/miniprogram_dist/components/select/select.js +201 -0
- package/miniprogram_dist/components/select/select.json +7 -0
- package/miniprogram_dist/components/select/select.scss +235 -0
- package/miniprogram_dist/components/select/select.wxml +79 -0
- package/miniprogram_dist/components/stepper/stepper.js +113 -0
- package/miniprogram_dist/components/stepper/stepper.json +4 -0
- package/miniprogram_dist/components/stepper/stepper.scss +73 -0
- package/miniprogram_dist/components/stepper/stepper.wxml +23 -0
- package/miniprogram_dist/components/switch/switch.js +42 -0
- package/miniprogram_dist/components/switch/switch.json +4 -0
- package/miniprogram_dist/components/switch/switch.scss +77 -0
- package/miniprogram_dist/components/switch/switch.wxml +10 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.js +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.json +4 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.scss +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.wxml +12 -0
- package/miniprogram_dist/components/tag/tag.js +87 -0
- package/miniprogram_dist/components/tag/tag.json +4 -0
- package/miniprogram_dist/components/tag/tag.scss +138 -0
- package/miniprogram_dist/components/tag/tag.wxml +12 -0
- package/miniprogram_dist/components/textarea/textarea.js +46 -0
- package/miniprogram_dist/components/textarea/textarea.json +4 -0
- package/miniprogram_dist/components/textarea/textarea.scss +51 -0
- package/miniprogram_dist/components/textarea/textarea.wxml +20 -0
- package/miniprogram_dist/components/theme-provider/presets.js +101 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.js +34 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.json +4 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.scss +3 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.wxml +3 -0
- package/miniprogram_dist/components/time-picker/time-picker.js +136 -0
- package/miniprogram_dist/components/time-picker/time-picker.json +7 -0
- package/miniprogram_dist/components/time-picker/time-picker.scss +135 -0
- package/miniprogram_dist/components/time-picker/time-picker.wxml +47 -0
- package/miniprogram_dist/components/tooltip/tooltip.js +179 -0
- package/miniprogram_dist/components/tooltip/tooltip.json +4 -0
- package/miniprogram_dist/components/tooltip/tooltip.scss +66 -0
- package/miniprogram_dist/components/tooltip/tooltip.wxml +17 -0
- package/miniprogram_dist/components/tree/tree.js +647 -0
- package/miniprogram_dist/components/tree/tree.json +4 -0
- package/miniprogram_dist/components/tree/tree.scss +178 -0
- package/miniprogram_dist/components/tree/tree.wxml +59 -0
- package/miniprogram_dist/components/tree-select/tree-select.js +260 -0
- package/miniprogram_dist/components/tree-select/tree-select.json +8 -0
- package/miniprogram_dist/components/tree-select/tree-select.scss +250 -0
- package/miniprogram_dist/components/tree-select/tree-select.wxml +118 -0
- package/miniprogram_dist/components/upload/upload.js +387 -0
- package/miniprogram_dist/components/upload/upload.json +4 -0
- package/miniprogram_dist/components/upload/upload.scss +258 -0
- package/miniprogram_dist/components/upload/upload.wxml +142 -0
- package/miniprogram_dist/components/watermark/watermark.js +260 -0
- package/miniprogram_dist/components/watermark/watermark.json +4 -0
- package/miniprogram_dist/components/watermark/watermark.scss +35 -0
- package/miniprogram_dist/components/watermark/watermark.wxml +13 -0
- package/miniprogram_dist/libs/qrcodegen.js +714 -0
- package/miniprogram_dist/libs/seemly.min.js +547 -0
- package/miniprogram_dist/libs/tempo_1_0_0.js +1264 -0
- package/miniprogram_dist/libs/validator_13_56_26.min.js +5282 -0
- package/miniprogram_dist/styles/demo.scss +96 -0
- package/miniprogram_dist/styles/iconfont.scss +91 -0
- package/miniprogram_dist/styles/theme.scss +126 -0
- package/miniprogram_dist/styles/tokens.scss +292 -0
- package/miniprogram_dist/utils/relations.js +21 -0
- package/package.json +25 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hsv2rgb,
|
|
3
|
+
rgb2hsv,
|
|
4
|
+
rgb2hsl,
|
|
5
|
+
hsl2rgb,
|
|
6
|
+
rgba as parseRgba,
|
|
7
|
+
toHexString,
|
|
8
|
+
toHexaString,
|
|
9
|
+
roundChannel,
|
|
10
|
+
} from '../../libs/seemly.min';
|
|
11
|
+
|
|
12
|
+
const formField = require('../../behaviors/formField');
|
|
13
|
+
|
|
14
|
+
Component({
|
|
15
|
+
behaviors: ['wx://form-field', formField],
|
|
16
|
+
|
|
17
|
+
relations: {
|
|
18
|
+
'../form-item/form-item': {
|
|
19
|
+
type: 'ancestor',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
properties: {
|
|
24
|
+
value: { type: String, value: '' },
|
|
25
|
+
placeholder: { type: String, value: '请选择颜色' },
|
|
26
|
+
disabled: { type: Boolean, value: false },
|
|
27
|
+
readonly: { type: Boolean, value: false },
|
|
28
|
+
size: { type: String, value: '' },
|
|
29
|
+
status: { type: String, value: '' },
|
|
30
|
+
clearable: { type: Boolean, value: false },
|
|
31
|
+
showAlpha: { type: Boolean, value: false },
|
|
32
|
+
modes: { type: Array, value: null },
|
|
33
|
+
swatches: { type: Array, value: null },
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
data: {
|
|
37
|
+
_visible: false,
|
|
38
|
+
_h: 0,
|
|
39
|
+
_s: 100,
|
|
40
|
+
_v: 100,
|
|
41
|
+
_a: 1,
|
|
42
|
+
_displayText: '',
|
|
43
|
+
_displayColor: '',
|
|
44
|
+
_inputMode: 'hex',
|
|
45
|
+
_paletteHue: 'background-color: hsl(0, 100%, 50%)',
|
|
46
|
+
_handleX: 100,
|
|
47
|
+
_handleY: 0,
|
|
48
|
+
_hueX: 0,
|
|
49
|
+
_alphaX: 100,
|
|
50
|
+
_alphaGradient: '',
|
|
51
|
+
_previewColor: 'rgb(255, 0, 0)',
|
|
52
|
+
_hexVal: '#FF0000',
|
|
53
|
+
_rVal: '255',
|
|
54
|
+
_gVal: '0',
|
|
55
|
+
_bVal: '0',
|
|
56
|
+
_hslH: '0',
|
|
57
|
+
_hslS: '100',
|
|
58
|
+
_hslL: '50',
|
|
59
|
+
_aVal: '100',
|
|
60
|
+
_showModeToggle: true,
|
|
61
|
+
_hasModes: true,
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
lifetimes: {
|
|
65
|
+
attached() {
|
|
66
|
+
const modes = this.data.modes || ['hex', 'rgb', 'hsl', 'hsv'];
|
|
67
|
+
this.setData({
|
|
68
|
+
_inputMode: modes[0] || 'hex',
|
|
69
|
+
_showModeToggle: modes.length > 1,
|
|
70
|
+
_hasModes: modes.length > 0,
|
|
71
|
+
});
|
|
72
|
+
this._syncFromValue();
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
observers: {
|
|
77
|
+
value() {
|
|
78
|
+
this._syncFromValue();
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
methods: {
|
|
83
|
+
_syncFromValue() {
|
|
84
|
+
const { value, showAlpha } = this.data;
|
|
85
|
+
if (!value) {
|
|
86
|
+
this.setData({ _displayText: '', _displayColor: '' });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = parseRgba(value);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const [r, g, b, a] = parsed;
|
|
96
|
+
const [h, s, v] = rgb2hsv(r, g, b);
|
|
97
|
+
const alpha = showAlpha ? a : 1;
|
|
98
|
+
this.setData({
|
|
99
|
+
_h: Math.round(h),
|
|
100
|
+
_s: Math.round(s),
|
|
101
|
+
_v: Math.round(v),
|
|
102
|
+
_a: alpha,
|
|
103
|
+
_displayText: value,
|
|
104
|
+
_displayColor: showAlpha ? `rgba(${r},${g},${b},${a})` : `rgb(${r},${g},${b})`,
|
|
105
|
+
});
|
|
106
|
+
this._updateUI();
|
|
107
|
+
// Overwrite round-tripped display values with exact parsed values
|
|
108
|
+
const [hslH, hslS, hslL] = rgb2hsl(r, g, b).map(Math.round);
|
|
109
|
+
const exactHex =
|
|
110
|
+
showAlpha && alpha < 1 ? toHexaString([r, g, b, alpha]) : toHexString([r, g, b]);
|
|
111
|
+
this.setData({
|
|
112
|
+
_hexVal: exactHex,
|
|
113
|
+
_rVal: String(r),
|
|
114
|
+
_gVal: String(g),
|
|
115
|
+
_bVal: String(b),
|
|
116
|
+
_hslH: String(hslH),
|
|
117
|
+
_hslS: String(hslS),
|
|
118
|
+
_hslL: String(hslL),
|
|
119
|
+
_previewColor: showAlpha ? `rgba(${r},${g},${b},${alpha})` : `rgb(${r},${g},${b})`,
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
_updateUI() {
|
|
124
|
+
const { _h, _s, _v, _a, showAlpha } = this.data;
|
|
125
|
+
const [r, g, b] = hsv2rgb(_h, _s, _v).map(roundChannel);
|
|
126
|
+
const [hslH, hslS, hslL] = rgb2hsl(r, g, b).map(Math.round);
|
|
127
|
+
const hex = showAlpha && _a < 1 ? toHexaString([r, g, b, _a]) : toHexString([r, g, b]);
|
|
128
|
+
|
|
129
|
+
this.setData({
|
|
130
|
+
_paletteHue: `background-color: hsl(${_h}, 100%, 50%)`,
|
|
131
|
+
_handleX: _s,
|
|
132
|
+
_handleY: 100 - _v,
|
|
133
|
+
_hueX: (_h / 360) * 100,
|
|
134
|
+
_alphaX: _a * 100,
|
|
135
|
+
_alphaGradient: `background: linear-gradient(to right, rgba(${r},${g},${b},0), rgb(${r},${g},${b}))`,
|
|
136
|
+
_previewColor: showAlpha ? `rgba(${r},${g},${b},${_a})` : `rgb(${r},${g},${b})`,
|
|
137
|
+
_hexVal: hex,
|
|
138
|
+
_rVal: String(r),
|
|
139
|
+
_gVal: String(g),
|
|
140
|
+
_bVal: String(b),
|
|
141
|
+
_hslH: String(hslH),
|
|
142
|
+
_hslS: String(hslS),
|
|
143
|
+
_hslL: String(hslL),
|
|
144
|
+
_aVal: String(Math.round(_a * 100)),
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
_getOutputValue() {
|
|
149
|
+
const { _h, _s, _v, _a, showAlpha } = this.data;
|
|
150
|
+
const [r, g, b] = hsv2rgb(_h, _s, _v).map(roundChannel);
|
|
151
|
+
return showAlpha && _a < 1 ? toHexaString([r, g, b, _a]) : toHexString([r, g, b]);
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
handleTap() {
|
|
155
|
+
if (this._isDisabled() || this.data.readonly) return;
|
|
156
|
+
if (!this.data.value) {
|
|
157
|
+
this.setData({ _h: 0, _s: 100, _v: 100, _a: 1 });
|
|
158
|
+
this._updateUI();
|
|
159
|
+
}
|
|
160
|
+
this.setData({ _visible: true });
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
handleConfirm() {
|
|
164
|
+
const val = this._getOutputValue();
|
|
165
|
+
this.setData({ _visible: false, _displayText: val, _displayColor: this.data._previewColor });
|
|
166
|
+
this.triggerEvent('update:value', { value: val });
|
|
167
|
+
this.triggerEvent('confirm', { value: val });
|
|
168
|
+
this._notifyChange();
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
handleCancel() {
|
|
172
|
+
this.setData({ _visible: false });
|
|
173
|
+
this._syncFromValue();
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
handleClear(e) {
|
|
177
|
+
this.triggerEvent('update:value', { value: '' });
|
|
178
|
+
this.triggerEvent('clear');
|
|
179
|
+
this.setData({ _displayText: '', _displayColor: '' });
|
|
180
|
+
this._notifyChange();
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
// — Palette touch —
|
|
184
|
+
handlePaletteTouchStart(e) {
|
|
185
|
+
const query = this.createSelectorQuery();
|
|
186
|
+
query.select('.w-color-picker__palette').boundingClientRect();
|
|
187
|
+
query.exec((res) => {
|
|
188
|
+
if (!res[0]) return;
|
|
189
|
+
this._paletteRect = res[0];
|
|
190
|
+
this._updatePaletteFromTouch(e.touches[0]);
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
handlePaletteTouchMove(e) {
|
|
195
|
+
if (!this._paletteRect) return;
|
|
196
|
+
this._updatePaletteFromTouch(e.touches[0]);
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
_updatePaletteFromTouch(touch) {
|
|
200
|
+
const rect = this._paletteRect;
|
|
201
|
+
let x = (touch.pageX - rect.left) / rect.width;
|
|
202
|
+
let y = (touch.pageY - rect.top) / rect.height;
|
|
203
|
+
x = Math.max(0, Math.min(1, x));
|
|
204
|
+
y = Math.max(0, Math.min(1, y));
|
|
205
|
+
this.setData({
|
|
206
|
+
_s: Math.round(x * 100),
|
|
207
|
+
_v: Math.round((1 - y) * 100),
|
|
208
|
+
});
|
|
209
|
+
this._updateUI();
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
// — Hue touch —
|
|
213
|
+
handleHueTouchStart(e) {
|
|
214
|
+
const query = this.createSelectorQuery();
|
|
215
|
+
query.select('.w-color-picker__hue').boundingClientRect();
|
|
216
|
+
query.exec((res) => {
|
|
217
|
+
if (!res[0]) return;
|
|
218
|
+
this._hueRect = res[0];
|
|
219
|
+
this._updateHueFromTouch(e.touches[0]);
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
handleHueTouchMove(e) {
|
|
224
|
+
if (!this._hueRect) return;
|
|
225
|
+
this._updateHueFromTouch(e.touches[0]);
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
_updateHueFromTouch(touch) {
|
|
229
|
+
const rect = this._hueRect;
|
|
230
|
+
let x = (touch.pageX - rect.left) / rect.width;
|
|
231
|
+
x = Math.max(0, Math.min(1, x));
|
|
232
|
+
this.setData({ _h: Math.round(x * 360) });
|
|
233
|
+
this._updateUI();
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
// — Alpha touch —
|
|
237
|
+
handleAlphaTouchStart(e) {
|
|
238
|
+
const query = this.createSelectorQuery();
|
|
239
|
+
query.select('.w-color-picker__alpha').boundingClientRect();
|
|
240
|
+
query.exec((res) => {
|
|
241
|
+
if (!res[0]) return;
|
|
242
|
+
this._alphaRect = res[0];
|
|
243
|
+
this._updateAlphaFromTouch(e.touches[0]);
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
handleAlphaTouchMove(e) {
|
|
248
|
+
if (!this._alphaRect) return;
|
|
249
|
+
this._updateAlphaFromTouch(e.touches[0]);
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
_updateAlphaFromTouch(touch) {
|
|
253
|
+
const rect = this._alphaRect;
|
|
254
|
+
let x = (touch.pageX - rect.left) / rect.width;
|
|
255
|
+
x = Math.max(0, Math.min(1, x));
|
|
256
|
+
this.setData({ _a: Math.round(x * 100) / 100 });
|
|
257
|
+
this._updateUI();
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
// — Input handling —
|
|
261
|
+
handleModeToggle() {
|
|
262
|
+
const modes = this.data.modes || ['hex', 'rgb', 'hsl', 'hsv'];
|
|
263
|
+
if (modes.length <= 1) return;
|
|
264
|
+
const idx = modes.indexOf(this.data._inputMode);
|
|
265
|
+
const next = modes[(idx + 1) % modes.length];
|
|
266
|
+
this.setData({ _inputMode: next });
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
handleHexInput(e) {
|
|
270
|
+
let hex = e.detail.value.trim();
|
|
271
|
+
if (!hex.startsWith('#')) hex = `#${hex}`;
|
|
272
|
+
let parsed;
|
|
273
|
+
try {
|
|
274
|
+
parsed = parseRgba(hex);
|
|
275
|
+
} catch (err) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const [r, g, b, a] = parsed;
|
|
279
|
+
const [h, s, v] = rgb2hsv(r, g, b).map(Math.round);
|
|
280
|
+
this.setData({ _h: h, _s: s, _v: v, _a: a });
|
|
281
|
+
this._updateUI();
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
handleRgbInput(e) {
|
|
285
|
+
const { channel } = e.currentTarget.dataset;
|
|
286
|
+
const val = parseInt(e.detail.value, 10);
|
|
287
|
+
if (isNaN(val)) return;
|
|
288
|
+
const clamped = Math.max(0, Math.min(255, val));
|
|
289
|
+
const r = channel === 'r' ? clamped : parseInt(this.data._rVal, 10);
|
|
290
|
+
const g = channel === 'g' ? clamped : parseInt(this.data._gVal, 10);
|
|
291
|
+
const b = channel === 'b' ? clamped : parseInt(this.data._bVal, 10);
|
|
292
|
+
const [h, s, v] = rgb2hsv(r, g, b).map(Math.round);
|
|
293
|
+
this.setData({ _h: h, _s: s, _v: v });
|
|
294
|
+
this._updateUI();
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
handleHslInput(e) {
|
|
298
|
+
const { channel } = e.currentTarget.dataset;
|
|
299
|
+
const val = parseInt(e.detail.value, 10);
|
|
300
|
+
if (isNaN(val)) return;
|
|
301
|
+
let h = parseInt(this.data._hslH, 10);
|
|
302
|
+
let s = parseInt(this.data._hslS, 10);
|
|
303
|
+
let l = parseInt(this.data._hslL, 10);
|
|
304
|
+
if (channel === 'h') h = Math.max(0, Math.min(360, val));
|
|
305
|
+
if (channel === 's') s = Math.max(0, Math.min(100, val));
|
|
306
|
+
if (channel === 'l') l = Math.max(0, Math.min(100, val));
|
|
307
|
+
const [r, g, b] = hsl2rgb(h, s, l).map(roundChannel);
|
|
308
|
+
const [hh, ss, vv] = rgb2hsv(r, g, b).map(Math.round);
|
|
309
|
+
this.setData({ _h: hh, _s: ss, _v: vv });
|
|
310
|
+
this._updateUI();
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
handleHsvInput(e) {
|
|
314
|
+
const { channel } = e.currentTarget.dataset;
|
|
315
|
+
const val = parseInt(e.detail.value, 10);
|
|
316
|
+
if (isNaN(val)) return;
|
|
317
|
+
let h = this.data._h;
|
|
318
|
+
let s = this.data._s;
|
|
319
|
+
let v = this.data._v;
|
|
320
|
+
if (channel === 'h') h = Math.max(0, Math.min(360, val));
|
|
321
|
+
if (channel === 's') s = Math.max(0, Math.min(100, val));
|
|
322
|
+
if (channel === 'v') v = Math.max(0, Math.min(100, val));
|
|
323
|
+
this.setData({ _h: h, _s: s, _v: v });
|
|
324
|
+
this._updateUI();
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
handleAlphaInput(e) {
|
|
328
|
+
const val = parseInt(e.detail.value, 10);
|
|
329
|
+
if (isNaN(val)) return;
|
|
330
|
+
this.setData({ _a: Math.max(0, Math.min(100, val)) / 100 });
|
|
331
|
+
this._updateUI();
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
handleSwatchTap(e) {
|
|
335
|
+
const color = e.currentTarget.dataset.color;
|
|
336
|
+
let parsed;
|
|
337
|
+
try {
|
|
338
|
+
parsed = parseRgba(color);
|
|
339
|
+
} catch (err) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const [r, g, b, a] = parsed;
|
|
343
|
+
const [h, s, v] = rgb2hsv(r, g, b).map(Math.round);
|
|
344
|
+
this.setData({ _h: h, _s: s, _v: v, _a: a });
|
|
345
|
+
this._updateUI();
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
});
|