virtual-keypad 5.11.1 → 5.11.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-keypad",
3
- "version": "5.11.1",
3
+ "version": "5.11.2",
4
4
  "description": "User response at a distance. Simple utility to summon forth a virtual keypad webapp.",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
package/src/keypad.css CHANGED
@@ -111,35 +111,9 @@
111
111
  .response-button:active {
112
112
  box-shadow: 1px 2px 2px 1px #999;
113
113
  background-color: #aaa;
114
+ font-size: large;
114
115
  }
115
116
 
116
- /* #keypad-control-keys {
117
- grid-row: 3;
118
-
119
- display: grid;
120
- grid-template-columns: repeat(2, 1fr);
121
- align-items: center;
122
- justify-content: center;
123
- } */
124
- /* #keypad-control-keys > button {
125
- height: 95%;
126
- width: 95%;
127
- min-width: 95%;
128
- max-height: min(15vh, 150px);
129
- } */
130
-
131
- .response-button#SPACE {
132
- /* TODO actually make sure test doesn't clip */
133
- font-size: larger;
134
- /* grid-column: 1;
135
- grid-row: 1; */
136
- }
137
- .response-button#RETURN {
138
- /* TODO actually make sure test doesn't clip */
139
- font-size: larger;
140
- /* grid-column: 2;
141
- grid-row: 1; */
142
- }
143
117
  /* Only do on a hover-enabled device, ie not a phone/tablet */
144
118
  @media (hover: hover) {
145
119
  .response-button:hover {
package/src/keypad.js CHANGED
@@ -213,6 +213,7 @@ class Keypad extends KeypadPeer {
213
213
  button.id = symbol;
214
214
  button.className = "response-button";
215
215
  button.style.fontFamily = this.font;
216
+ button.style.visibility = "hidden"
216
217
 
217
218
  const feedbackAudio = document.getElementById("feedbackAudio");
218
219
 
@@ -298,7 +299,7 @@ class Keypad extends KeypadPeer {
298
299
  // Create new buttons
299
300
  this.alphabet.forEach((symbol) => createButton(symbol));
300
301
  // Manually style buttons, according to Denis' algorithm
301
- setTimeout(() => applyMaxKeySize(this.alphabet.length), 100);
302
+ setTimeout(() => applyMaxKeySize(this.alphabet.length), 3); // Why?
302
303
  };
303
304
  visualFeedbackThenReset = (delayTime = 800) => {
304
305
  // ie grey out keys just after use, to discourage rapid response
package/src/maxKeySize.js CHANGED
@@ -53,23 +53,37 @@ export const applyMaxKeySize = (numberOfKeys) => {
53
53
  keyElems.forEach((k,i) => {
54
54
  k.style.position = "fixed";
55
55
  const controlKey = controlKeyElemsMask[i];
56
- const height = `${keyHeightPx}px`;
57
56
  let top, left, width;
58
57
  if (controlKey) {
59
- top = (heightPx-keyHeightPx) - verticalMarginOffset + "px";
60
- left = (k.innerText.toLowerCase().includes("space") ? 0 : widthPx/2 - horizontalMarginOffset) + horizontalMarginOffset + "px";
61
- width = `${(widthPx - horizontalMarginOffset*2)/2}px`;
58
+ top = (heightPx-keyHeightPx) - verticalMarginOffset;
59
+ left = (k.id.toLowerCase().includes("space") ? 0 : widthPx/2 - horizontalMarginOffset) + horizontalMarginOffset;
60
+ width = (widthPx - horizontalMarginOffset*2)/2;
61
+
62
+ k.style.height = "auto";
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);
75
+ k.style.fontSize = f + "px";
62
76
  } else {
63
77
  width = keyHeightPx*aspect;
64
78
  const [y,x] = gridCoords[j];
65
79
  j += 1;
66
- top = y*keyHeightPx + verticalMarginOffset + "px";
67
- left = `${x*width+horizontalMarginOffset}px`;
68
- width += "px";
80
+ top = y*keyHeightPx + verticalMarginOffset ;
81
+ left = x*width+horizontalMarginOffset;
69
82
  }
70
- k.style.width = width;
71
- k.style.height = height;
72
- k.style.top = top;
73
- k.style.left = left;
83
+ k.style.width = width + "px";
84
+ k.style.height = keyHeightPx + "px";
85
+ k.style.top = top + "px";
86
+ k.style.left = left + "px";
87
+ k.style.visibility = "visible";
74
88
  });
75
89
  };