1
+ <script lang="ts">
2
+ import { parseSearchParams } from ' ./utils' ;
3
+ const pickers = [' chrome' , ' sketch' , ' photoshop' , ' compact' , ' grayscale' , ' material' , ' slider' , ' twitter' , ' swatches' , ' hue' ] as const ;
4
+ const searchParams = parseSearchParams (location .search );
5
+ const manualEnabledPickers = searchParams .picker ?.split (' ,' );
6
+
7
+ function invertColor({ r , g , b , a }: { r: number ; g: number ; b: number , a: number }): string {
8
+ const invert = (val : number , alpha : number ) => alpha === 0 ? 0 : 255 - val ;
9
+ const inverted = {
10
+ r: invert (r , a ),
11
+ g: invert (g , a ),
12
+ b: invert (b , a ),
13
+ a: a < 0.5 ? 1 - a : a
14
+ };
15
+ return ` rgba(${inverted .r }, ${inverted .g }, ${inverted .b }, ${inverted .a }) ` ;
16
+ }
17
+
18
+ const hasInitialColor = !! searchParams .hex ;
19
+ const initialColor = ` #${searchParams .hex ?? ' F5F7FA' } ` ;
20
+ </script >
21
+
1
22
<script setup lang="ts">
2
23
import { watch , computed , reactive } from ' vue' ;
3
24
@@ -18,25 +39,30 @@ import {
18
39
19
40
// import '../dist/vue-color.css'
20
41
42
+ const showStatus: Record <(typeof pickers )[number ], boolean > = {} as Record <(typeof pickers )[number ], boolean >;
43
+ pickers .forEach ((picker ) => {
44
+ if (! manualEnabledPickers || manualEnabledPickers .length === 0 ) {
45
+ showStatus [picker ] = true ;
46
+ } else {
47
+ showStatus [picker ] = manualEnabledPickers .indexOf (picker ) > - 1 ;
48
+ }
49
+ });
50
+
21
51
const tinyColor = defineModel (' tinyColor' , {
22
- default: tinycolor (' #F5F7FA ' )
52
+ default: tinycolor (initialColor )
23
53
});
24
54
25
55
const color = defineModel ({
26
- default : () => reactive ({r: 0 , g: 0 , b: 255 , a: 1 })
56
+ default : () => {
57
+ if (hasInitialColor ) {
58
+ return initialColor ;
59
+ }
60
+ // #F5F7FA
61
+ return reactive ({r: 245 , g: 247 , b: 250 , a: 1 })
62
+ }
27
63
});
28
64
29
- watch (tinyColor , () => console .log (' color changed ==>' , tinyColor .value ));
30
-
31
- function invertColor(rgba : { r: number ; g: number ; b: number , a: number }): string {
32
- const inverted = {
33
- r: 255 - rgba .r ,
34
- g: 255 - rgba .g ,
35
- b: 255 - rgba .b ,
36
- a: rgba .a
37
- };
38
- return ` rgba(${inverted .r }, ${inverted .g }, ${inverted .b }, ${inverted .a }) ` ;
39
- }
65
+ watch (color , () => console .log (' changed ==>' , color .value ));
40
66
41
67
const hex = computed (() => {
42
68
return tinycolor (tinyColor .value ).toHex8String ();
@@ -69,11 +95,11 @@ const updateHue = (newHue: number) => {
69
95
<div class =" color-background" :style =" [background]" ></div >
70
96
<div class =" wrapper" >
71
97
<div >
72
- <div class =" title text" :style = " {color: textColor} " >
98
+ <div class =" title text" >
73
99
<h1 >Vue-color</h1 ><span class =" tag" >v3.0</span >
74
100
</div >
75
101
76
- <main class =" intro text" :style = " {color: textColor} " >
102
+ <main class =" intro text" >
77
103
A collection of efficient color pickers designed for modern web development.
78
104
<ul class =" feature-list text" :style =" {color: textColor, opacity: 0.75}" >
79
105
<li >✅ Modular & Tree-Shakable</li >
@@ -95,64 +121,64 @@ const updateHue = (newHue: number) => {
95
121
<div :style =" {flex: 0.8}" >
96
122
<div class =" row" >
97
123
<div class =" col" >
98
- <div class =" text current-color" :style = " {color: textColor, opacity: 0.5} " >
124
+ <div class =" text current-color" >
99
125
{{ hex }}<br />
100
126
{{ color }}<br />
101
127
{{ hsva }}
102
128
</div >
103
- <div class =" picker-container" >
129
+ <div class =" picker-container" v-if = " showStatus.chrome " >
104
130
<ChromePicker v-model:tinyColor =" tinyColor" v-model =" color" />
105
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; ChromePicker /> ; </div >
131
+ <div class =" picker-title text" >< ; ChromePicker /> ; </div >
106
132
</div >
107
133
</div >
108
134
109
- <div class =" picker-container" >
135
+ <div class =" picker-container" v-if = " showStatus.sketch " >
110
136
<div ><SketchPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
111
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; SketchPicker /> ; </div >
137
+ <div class =" picker-title text" >< ; SketchPicker /> ; </div >
112
138
</div >
113
139
114
- <div class =" picker-container" >
140
+ <div class =" picker-container" v-if = " showStatus.photoshop " >
115
141
<div ><PhotoshopPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
116
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; PhotoshopPicker /> ; </div >
142
+ <div class =" picker-title text" >< ; PhotoshopPicker /> ; </div >
117
143
</div >
118
144
</div >
119
145
<div class =" row" :style =" {marginTop: '5%'}" >
120
146
<div class =" col" >
121
- <div class =" picker-container" >
147
+ <div class =" picker-container" v-if = " showStatus.compact " >
122
148
<div ><CompactPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
123
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; CompactPicker /> ; </div >
149
+ <div class =" picker-title text" >< ; CompactPicker /> ; </div >
124
150
</div >
125
- <div class =" picker-container" >
151
+ <div class =" picker-container" v-if = " showStatus.grayscale " >
126
152
<div ><GrayscalePicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
127
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; GrayscalePicker /> ; </div >
153
+ <div class =" picker-title text" >< ; GrayscalePicker /> ; </div >
128
154
</div >
129
- <div class =" picker-container" >
155
+ <div class =" picker-container" v-if = " showStatus.material " >
130
156
<div ><MaterialPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
131
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; MaterialPicker /> ; </div >
157
+ <div class =" picker-title text" >< ; MaterialPicker /> ; </div >
132
158
</div >
133
159
</div >
134
160
135
161
<div class =" col" >
136
- <div class =" picker-container" >
162
+ <div class =" picker-container" v-if = " showStatus.hue " >
137
163
<div :style =" {width: '410px'}" ><HueSlider :modelValue =" hsva.h" @update:modelValue =" updateHue" /></div >
138
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; HueSlider /> ; </div >
164
+ <div class =" picker-title text" >< ; HueSlider /> ; </div >
139
165
</div >
140
166
141
- <div class =" picker-container" >
167
+ <div class =" picker-container" v-if = " showStatus.slider " >
142
168
<div ><SliderPicker v-model:tinyColor =" tinyColor" v-model =" color" :alpha =" true" /></div >
143
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; SliderPicker /> ; </div >
169
+ <div class =" picker-title text" >< ; SliderPicker /> ; </div >
144
170
</div >
145
171
146
- <div class =" picker-container" >
172
+ <div class =" picker-container" v-if = " showStatus.twitter " >
147
173
<div ><TwitterPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
148
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; TwitterPicker /> ; </div >
174
+ <div class =" picker-title text" >< ; TwitterPicker /> ; </div >
149
175
</div >
150
176
</div >
151
177
152
178
<div class =" col" >
153
- <div class =" picker-container" >
179
+ <div class =" picker-container" v-if = " showStatus.swatches " >
154
180
<div ><SwatchesPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
155
- <div class =" picker-title text" :style = " {color: textColor, opacity: 0.5} " >< ; SwatchesPicker /> ; </div >
181
+ <div class =" picker-title text" >< ; SwatchesPicker /> ; </div >
156
182
</div >
157
183
</div >
158
184
</div >
@@ -166,6 +192,7 @@ const updateHue = (newHue: number) => {
166
192
font-optical-sizing : auto ;
167
193
font-style : normal ;
168
194
font-variation-settings : " wdth" 100 ;
195
+ color : v-bind(textColor);
169
196
}
170
197
171
198
.placeholder {
@@ -260,6 +287,7 @@ const updateHue = (newHue: number) => {
260
287
.picker-title {
261
288
margin-top : 10px ;
262
289
font-size : 14px ;
290
+ opacity : 0.5 ;
263
291
}
264
292
265
293
.current-color {
0 commit comments