@@ -8,13 +8,15 @@ export class KY040Element extends LitElement {
8
8
@property ( ) stepSize = 18 ;
9
9
@property ( ) private pressed = false ;
10
10
11
+ private arrowTimer : ReturnType < typeof setInterval > | null = null ;
12
+
11
13
static get styles ( ) {
12
14
return css `
13
15
svg {
14
16
user-select: none;
15
17
}
16
18
17
- .arrow {
19
+ .arrow-container {
18
20
cursor: pointer;
19
21
}
20
22
@@ -25,8 +27,8 @@ export class KY040Element extends LitElement {
25
27
transition: stroke-width 0.3s;
26
28
}
27
29
28
- svg :hover .arrow:hover {
29
- fill: black ;
30
+ .arrow-container :hover .arrow {
31
+ fill: white ;
30
32
}
31
33
32
34
svg:hover .handle:hover {
@@ -45,6 +47,14 @@ export class KY040Element extends LitElement {
45
47
.handle {
46
48
cursor: pointer;
47
49
}
50
+
51
+ g[tabindex]:focus {
52
+ outline: none;
53
+ }
54
+
55
+ g[tabindex]:focus + .focus-indicator {
56
+ opacity: 1;
57
+ }
48
58
` ;
49
59
}
50
60
@@ -96,57 +106,77 @@ export class KY040Element extends LitElement {
96
106
</ g >
97
107
98
108
< g tabindex ="0 " @keydown =${ this . keydown } @keyup =${ this . keyup } >
99
- < rect
100
- x ="12.2 "
101
- y ="8.05 "
102
- width ="48.4 "
103
- height ="41 "
104
- rx ="7.12 "
105
- fill ="#e6e6e6 "
106
- fill-rule ="evenodd "
107
- />
108
- < g >
109
- < g fill-rule ="evenodd ">
110
- < circle cx ="36.6 " cy ="28.5 " r ="13.5 " fill ="#666 " />
111
- < rect x ="32.5 " y ="7.87 " width ="7.42 " height ="41.5 " fill ="#666 " />
112
-
113
- <!-- handle -->
114
- < path
115
- transform ="rotate(${ this . angle } , 36.244, 28.5) "
116
- d ="m36.3 21.4a7.03 7.14 0 0
109
+ < rect x ="12.2 " y ="8.05 " width ="48.4 " height ="41 " rx ="7.12 " fill ="#e6e6e6 " />
110
+
111
+ < circle cx ="36.6 " cy ="28.5 " r ="13.5 " fill ="#666 " />
112
+ < rect x ="32.5 " y ="7.87 " width ="7.42 " height ="41.5 " fill ="#666 " />
113
+
114
+ <!-- Handle -->
115
+ < path
116
+ transform ="rotate(${ this . angle } , 36.244, 28.5) "
117
+ d ="m36.3 21.4a7.03 7.14 0 0
117
118
0-3.74 1.1v12.1a7.03 7.14 0 0 0 3.74 1.1 7.03 7.14 0 0 0 7.03-7.14 7.03 7.14 0 0
118
119
0-7.03-7.14z "
119
- fill ="#ccc "
120
- stroke ="#060606 "
121
- stroke-width =".3 "
122
- class ="handle ${ this . pressed ? 'active' : '' } "
123
- @mousedown =${ this . press }
124
- @mouseup =${ this . release }
125
- />
126
- </ g >
127
-
128
- <!-- Counter Clockwise Arrow -->
120
+ fill ="#ccc "
121
+ stroke ="#060606 "
122
+ stroke-width =".3 "
123
+ class ="handle ${ this . pressed ? 'active' : '' } "
124
+ @mousedown =${ this . press }
125
+ @mouseup =${ this . release }
126
+ @mouseleave=${ this . release }
127
+ />
128
+
129
+ <!-- Counter Clockwise Arrow -->
130
+ < g
131
+ class ="arrow-container "
132
+ @click =${ this . counterClockwiseStep }
133
+ @mousedown =${ this . counterclockwiseArrowPress }
134
+ @mouseup=${ this . arrowRelease }
135
+ @mouseleave=${ this . arrowRelease }
136
+ >
137
+ < circle cx ="20 " cy ="43 " r ="12 " fill ="red " opacity ="0 " />
129
138
< path
130
139
d ="m21 44.5c-5.17-1.78-7.55-5.53-6.6-11.2 0.0662-0.327 0.107-0.938 0.272-1.06 0.204-0.137 0.312-0.116 0.39-0.1 0.0775 0.0152 0.139 0.0274 0.189 0.102 0.846 3.81 3.13 6.84 6.57 7.59 0.304-0.787 0.461-3.32 0.826-3.24 0.428 0.0848 4.31 5.73 4.93 6.65-0.978 0.839-6.07 4.44-6.95 4.28 0 0 0.206-2.19 0.362-2.96z "
131
140
fill ="#b3b3b3 "
132
141
stroke ="#000 "
133
142
stroke-width =".0625px "
134
143
class ="arrow "
135
- @click =${ this . counterClockwiseClick }
136
144
/>
145
+ </ g >
137
146
138
- <!-- Clockwise Arrow -->
147
+ <!-- Clockwise Arrow -->
148
+ < g
149
+ class ="arrow-container "
150
+ @click =${ this . clockwiseStep }
151
+ @mousedown =${ this . clockwiseArrowPress }
152
+ @mouseup=${ this . arrowRelease }
153
+ @mouseleave=${ this . arrowRelease }
154
+ >
155
+ < circle cx ="20 " cy ="15 " r ="12 " fill ="red " opacity ="0 " />
139
156
< path
140
157
d ="m21.2 12.1c-5.17 1.78-7.55 5.53-6.6 11.2 0.0662 0.327 0.107 0.938 0.272 1.06 0.204 0.137 0.312 0.116 0.39 0.1 0.0775-0.0152 0.139-0.0274 0.189-0.102 0.846-3.81 3.13-6.84 6.57-7.59 0.304 0.787 0.461 3.32 0.826 3.24 0.428-0.0848 4.31-5.73 4.93-6.65-0.978-0.839-6.07-4.44-6.95-4.28 0 0 0.206 2.19 0.362 2.96z "
141
158
fill ="#b3b3b3 "
142
159
stroke ="#022 "
143
160
stroke-width =".0625px "
144
161
class ="arrow "
145
- @click =${ this . clockwiseClick }
146
162
/>
147
163
</ g >
148
164
</ g >
149
165
166
+ <!-- Focus indicator for the group above-->
167
+ < rect
168
+ class ="focus-indicator "
169
+ x ="10.2 "
170
+ y ="6.05 "
171
+ width ="52.4 "
172
+ height ="45 "
173
+ rx ="7.12 "
174
+ stroke ="white "
175
+ stroke-width ="2 "
176
+ fill ="none "
177
+ opacity ="0 "
178
+ />
179
+
150
180
<!-- Chip Pins -->
151
181
< rect
152
182
x ="83 "
@@ -177,12 +207,12 @@ export class KY040Element extends LitElement {
177
207
` ;
178
208
}
179
209
180
- private clockwiseClick ( ) {
210
+ private clockwiseStep ( ) {
181
211
this . angle = ( this . angle + this . stepSize ) % 360 ;
182
212
this . dispatchEvent ( new InputEvent ( 'rotate-cw' ) ) ;
183
213
}
184
214
185
- private counterClockwiseClick ( ) {
215
+ private counterClockwiseStep ( ) {
186
216
this . angle = ( this . angle - this . stepSize + 360 ) % 360 ;
187
217
this . dispatchEvent ( new InputEvent ( 'rotate-ccw' ) ) ;
188
218
}
@@ -195,21 +225,42 @@ export class KY040Element extends LitElement {
195
225
}
196
226
197
227
private release ( ) {
198
- this . dispatchEvent ( new InputEvent ( 'button-release' ) ) ;
199
- this . pressed = false ;
228
+ if ( this . pressed ) {
229
+ this . dispatchEvent ( new InputEvent ( 'button-release' ) ) ;
230
+ this . pressed = false ;
231
+ }
232
+ }
233
+
234
+ private counterclockwiseArrowPress ( ) {
235
+ this . arrowTimer = setInterval ( ( ) => {
236
+ this . counterClockwiseStep ( ) ;
237
+ } , 300 ) ;
238
+ }
239
+
240
+ private clockwiseArrowPress ( ) {
241
+ this . arrowTimer = setInterval ( ( ) => {
242
+ this . clockwiseStep ( ) ;
243
+ } , 300 ) ;
244
+ }
245
+
246
+ private arrowRelease ( ) {
247
+ if ( this . arrowTimer != null ) {
248
+ clearInterval ( this . arrowTimer ) ;
249
+ this . arrowTimer = null ;
250
+ }
200
251
}
201
252
202
253
private keydown ( e : KeyboardEvent ) {
203
254
switch ( e . key ) {
204
255
case 'ArrowUp' :
205
256
case 'ArrowRight' :
206
- this . clockwiseClick ( ) ;
257
+ this . clockwiseStep ( ) ;
207
258
e . preventDefault ( ) ;
208
259
break ;
209
260
210
261
case 'ArrowDown' :
211
262
case 'ArrowLeft' :
212
- this . counterClockwiseClick ( ) ;
263
+ this . counterClockwiseStep ( ) ;
213
264
e . preventDefault ( ) ;
214
265
break ;
215
266
0 commit comments