virtual-keypad 5.11.4 → 5.12.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/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
- package/src/keypad.css +5 -5
- package/src/keypad.js +2 -2
- package/src/maxKeySize.js +36 -22
package/package.json
CHANGED
package/src/keypad.css
CHANGED
|
@@ -41,10 +41,6 @@
|
|
|
41
41
|
#keypad-keys {
|
|
42
42
|
/* Second row, within the keypad grid (ie whole page) */
|
|
43
43
|
grid-row: 2;
|
|
44
|
-
|
|
45
|
-
padding: 10px;
|
|
46
|
-
|
|
47
|
-
margin: 15px;
|
|
48
44
|
}
|
|
49
45
|
/* Hide scrollbar */
|
|
50
46
|
/* #keypad-keys::-webkit-scrollbar {
|
|
@@ -52,6 +48,7 @@
|
|
|
52
48
|
} */
|
|
53
49
|
|
|
54
50
|
.response-button {
|
|
51
|
+
/* border: 1px solid red; */
|
|
55
52
|
cursor: pointer;
|
|
56
53
|
|
|
57
54
|
/* Center text within button */
|
|
@@ -63,9 +60,12 @@
|
|
|
63
60
|
border-radius: min(25px, 15%);
|
|
64
61
|
|
|
65
62
|
/* Style button text */
|
|
66
|
-
font-size:
|
|
63
|
+
/* font-size: 3rem; */
|
|
64
|
+
font-size: xx-large;
|
|
67
65
|
font-weight: 700;
|
|
68
66
|
|
|
67
|
+
padding: 0;
|
|
68
|
+
margin: 0;
|
|
69
69
|
|
|
70
70
|
box-shadow: 1px 1px 2px #888888,
|
|
71
71
|
-1px -1px 2px #fff;
|
package/src/keypad.js
CHANGED
|
@@ -252,9 +252,9 @@ class Keypad extends KeypadPeer {
|
|
|
252
252
|
e.changedTouches[0].clientX,
|
|
253
253
|
e.changedTouches[0].clientY
|
|
254
254
|
);
|
|
255
|
-
switch (elementEndedOn
|
|
255
|
+
switch (elementEndedOn?.className) {
|
|
256
256
|
case "response-button-label noselect":
|
|
257
|
-
buttonResponseFn(elementEndedOn
|
|
257
|
+
buttonResponseFn(elementEndedOn?.parentElement); // e.target.click();
|
|
258
258
|
break;
|
|
259
259
|
case "response-button":
|
|
260
260
|
buttonResponseFn(elementEndedOn); // e.target.click();
|
package/src/maxKeySize.js
CHANGED
|
@@ -36,6 +36,7 @@ const getKeysDimensions = (elem, n, aspect=0.5) => {
|
|
|
36
36
|
|
|
37
37
|
export const applyMaxKeySize = (numberOfKeys) => {
|
|
38
38
|
const aspect = 1;
|
|
39
|
+
let margin = 5;
|
|
39
40
|
const keysElem = document.getElementById("keypad");
|
|
40
41
|
const {keyHeightPx, cols, rows, widthPx, heightPx} = getKeysDimensions(keysElem, numberOfKeys, aspect);
|
|
41
42
|
const keyElems = [...keysElem.getElementsByClassName("response-button")];
|
|
@@ -48,44 +49,57 @@ export const applyMaxKeySize = (numberOfKeys) => {
|
|
|
48
49
|
const verticalMarginOffset = Math.floor(freeHeight/2);
|
|
49
50
|
const horizontalMarginOffset = Math.floor(freeWidth/2);
|
|
50
51
|
|
|
52
|
+
let keyFontSize;
|
|
51
53
|
let j=0;
|
|
52
54
|
keyElems.forEach((k,i) => {
|
|
53
55
|
k.style.position = "fixed";
|
|
54
56
|
const controlKey = controlKeyElemsMask[i];
|
|
55
57
|
let top, left, width;
|
|
56
58
|
if (controlKey) {
|
|
57
|
-
top =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
top = heightPx-keyHeightPx;
|
|
60
|
+
width = widthPx/2 - horizontalMarginOffset - margin;
|
|
61
|
+
const m = horizontalMarginOffset + margin*0.5;
|
|
62
|
+
left = (k.id.toLowerCase().includes("space") ? m : m + width + margin);
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
k.style.width = "auto";
|
|
64
|
-
k.style.whiteSpace = "nowrap";
|
|
65
|
-
// Set to a nominal font size, s
|
|
66
|
-
const s = 20;
|
|
67
|
-
let w = k.getBoundingClientRect().width;
|
|
68
|
-
console.log("!. ~ file: maxKeySize.js:70 ~ keyElems.forEach ~ w:", w)
|
|
69
|
-
k.style.fontSize = s + "px";
|
|
70
|
-
// Measure width of elem, w
|
|
71
|
-
w = k.getBoundingClientRect().width;
|
|
72
|
-
const r = 1/(w/width)
|
|
73
|
-
// Set font size to s*r
|
|
74
|
-
const f = Math.floor(s*r);
|
|
64
|
+
const f = getLargeFontSize(k, width, keyHeightPx-margin);
|
|
75
65
|
k.style.fontSize = f + "px";
|
|
76
66
|
k.style.borderRadius = "25px";
|
|
77
|
-
k.style.height = (keyHeightPx -
|
|
67
|
+
k.style.height = (keyHeightPx - margin)+ "px";
|
|
78
68
|
} else {
|
|
79
|
-
|
|
69
|
+
const height = keyHeightPx - margin;
|
|
70
|
+
width = height*aspect;
|
|
80
71
|
const [y,x] = gridCoords[j];
|
|
81
72
|
j += 1;
|
|
82
|
-
top = y*
|
|
83
|
-
left = x*width+horizontalMarginOffset;
|
|
84
|
-
|
|
73
|
+
top = y*height + ((y+1)*margin) + verticalMarginOffset - margin/2;
|
|
74
|
+
left = x*width + ((x+1)*margin) + horizontalMarginOffset - margin/2;
|
|
75
|
+
if (!keyFontSize) {
|
|
76
|
+
keyFontSize = getLargeFontSize(k, width, height);
|
|
77
|
+
}
|
|
78
|
+
k.style.height = height + "px";
|
|
79
|
+
k.style.fontSize = height/2 + "px";
|
|
85
80
|
}
|
|
86
81
|
k.style.width = width + "px";
|
|
87
82
|
k.style.top = top + "px";
|
|
88
83
|
k.style.left = left + "px";
|
|
89
84
|
k.style.visibility = "visible";
|
|
90
85
|
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const getLargeFontSize = (k, width, height) => {
|
|
89
|
+
k.style.height = "auto";
|
|
90
|
+
k.style.width = "auto";
|
|
91
|
+
k.style.whiteSpace = "nowrap";
|
|
92
|
+
|
|
93
|
+
// Set to a nominal font size, s
|
|
94
|
+
const s = 20;
|
|
95
|
+
k.style.fontSize = s + "px";
|
|
96
|
+
// Measure width of elem, w
|
|
97
|
+
const w = k.getBoundingClientRect().width;
|
|
98
|
+
const h = k.getBoundingClientRect().height
|
|
99
|
+
const rW = 1/(w/width)
|
|
100
|
+
const rH = 1/(h/height)
|
|
101
|
+
const r = Math.min(rW, rH)
|
|
102
|
+
// Set font size to s*r
|
|
103
|
+
const f = Math.floor(s*r);
|
|
104
|
+
return f;
|
|
91
105
|
};
|