11import { customElement , html , LitElement , property , svg } from 'lit-element' ;
2+ import { pinsFemalePattern } from './patterns/pins-female' ;
23
34const SPACE_KEY = 32 ;
45
@@ -8,7 +9,15 @@ function isNumeric(text: string) {
89
910@customElement ( 'wokwi-membrane-keypad' )
1011export class MembraneKeypadElement extends LitElement {
11- @property ( ) threeColumns = false ;
12+ /**
13+ * Number of columns (3 or 4)
14+ */
15+ @property ( ) columns : '3' | '4' = '4' ;
16+
17+ /**
18+ * Whether to display a connector beneath the keypad
19+ */
20+ @property ( ) connector = false ;
1221
1322 private pressedKeys = new Set < string > ( ) ;
1423
@@ -39,9 +48,13 @@ export class MembraneKeypadElement extends LitElement {
3948 }
4049
4150 render ( ) {
42- const fourColumns = ! this . threeColumns ;
51+ const { connector } = this ;
52+ const fourColumns = this . columns === '4' ;
4353 const columnWidth = 15 ;
54+ const pinWidth = 2.54 ;
4455 const width = fourColumns ? 70.336 : 70.336 - columnWidth ;
56+ const connectorWidth = fourColumns ? pinWidth * 8 : pinWidth * 7 ;
57+ const height = 76 + ( connector ? 15 : 0 ) ;
4558
4659 return html `
4760 < style >
@@ -89,9 +102,9 @@ export class MembraneKeypadElement extends LitElement {
89102
90103 < svg
91104 width ="${ width } mm "
92- height ="76mm "
105+ height ="${ height } mm "
93106 version ="1.1 "
94- viewBox ="0 0 ${ width } 76 "
107+ viewBox ="0 0 ${ width } ${ height } "
95108 font-family ="sans-serif "
96109 font-size ="8.2px "
97110 text-anchor ="middle "
@@ -109,7 +122,16 @@ export class MembraneKeypadElement extends LitElement {
109122 stroke ="#b1b5b9 "
110123 stroke-width =".75 "
111124 />
112-
125+ < pattern id ="wires " width ="2.54 " height ="8 " patternUnits ="userSpaceOnUse ">
126+ < rect width ="2.54 " height ="8 " fill ="#eee " />
127+ < rect x ="0.77 " width ="1 " height ="6 " fill ="#d9d5bc " />
128+ < circle cx ="1.27 " cy ="6 " r ="0.75 " fill ="#d9d5bc " />
129+ < rect x ="0.52 " y ="6 " width ="1.5 " height ="2 " fill ="#d9d5bc " />
130+ </ pattern >
131+ < pattern id ="wires-marks " width ="2.54 " height ="8 " patternUnits ="userSpaceOnUse ">
132+ < rect x ="0.52 " y ="6 " width ="1.5 " height ="2 " fill ="#746d41 " />
133+ </ pattern >
134+ ${ pinsFemalePattern }
113135 < filter id ="shadow ">
114136 < feDropShadow dx ="0 " dy ="0 " stdDeviation ="0.5 " flood-color ="#ffff99 " />
115137 </ filter >
@@ -129,6 +151,18 @@ export class MembraneKeypadElement extends LitElement {
129151 stroke-width ="1 "
130152 />
131153
154+ <!-- Connector -->
155+ ${ connector
156+ ? svg `
157+ < g transform ="translate(${ ( width - connectorWidth ) / 2 } , 76) ">
158+ < rect width ="${ connectorWidth } " height ="8 " fill ="url(#wires) " />
159+ < rect width ="10.16 " height ="8 " fill ="url(#wires-marks) " />
160+ < rect y ="8 " width ="${ connectorWidth } " height ="7 " fill ="#333 " />
161+ < rect transform ="translate(0, 12) " width ="${ connectorWidth } " height ="2.54 " fill ="url(#pins-female) " />
162+ </ g >
163+ `
164+ : null }
165+
132166 <!-- Blue keys -->
133167 < g fill ="#4e90d7 ">
134168 < g > ${ this . renderKey ( '1' , 7 , 10.7 ) } </ g >
@@ -204,8 +238,10 @@ export class MembraneKeypadElement extends LitElement {
204238
205239 if ( key === 'Shift' ) {
206240 pressedKeys ?. forEach ( ( pressedKey ) => {
207- const pressedText = pressedKey . dataset . keyName ! ;
208- this . up ( pressedText , pressedKey ) ;
241+ const pressedText = pressedKey . dataset . keyName ;
242+ if ( pressedText ) {
243+ this . up ( pressedText , pressedKey ) ;
244+ }
209245 } ) ;
210246 }
211247
0 commit comments