virtual-keypad 5.11.0 → 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.
@@ -91,9 +91,6 @@
91
91
  for (let i=0; i<numberOfKeysToDisable; i++){
92
92
  keysToDisable.push(allKeys.splice(Math.floor(Math.random()*allKeys.length), 1)[0]);
93
93
  }
94
- console.log("keysToDisable", keysToDisable);
95
- console.log("ev.target.getAttribute('keys-disabled')", ev.target.getAttribute("keys-disabled"));
96
-
97
94
 
98
95
  if (ev.target.toggleAttribute("keys-disabled")) {
99
96
  receiver.disableKeys(keysToDisable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-keypad",
3
- "version": "5.11.0",
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
@@ -164,7 +164,6 @@ class Keypad extends KeypadPeer {
164
164
  keypadElem.appendChild(keypadHeader);
165
165
  keypadKeys.appendChild(keypadControlKeys);
166
166
  keypadElem.appendChild(keypadKeys);
167
- keypadElem.appendChild(keypadControlKeys);
168
167
  keypadElem.appendChild(keypadFooter);
169
168
  // Add keypad, ie container with header,keys,control keys to page where specified
170
169
  if (document.getElementById(this.targetElement)) {
@@ -178,7 +177,7 @@ class Keypad extends KeypadPeer {
178
177
  window.onbeforeunload = () => {this.conn?.close(); console.log("closing connection on page unload.")};
179
178
  window.onvisibilitychange = () => {this.conn?.close(); console.log("closing connection on page unload.")};
180
179
 
181
- window.onresize = () => {const resize = () => applyMaxKeySize(this.alphabet?.length); setTimeout(resize, 10); console.log("Repositioning buttons due to resize.")};
180
+ window.onresize = () => { applyMaxKeySize(this.alphabet?.length); }
182
181
  };
183
182
  #populateKeypad = () => {
184
183
  const buttonResponseFn = (button) => {
@@ -214,6 +213,7 @@ class Keypad extends KeypadPeer {
214
213
  button.id = symbol;
215
214
  button.className = "response-button";
216
215
  button.style.fontFamily = this.font;
216
+ button.style.visibility = "hidden"
217
217
 
218
218
  const feedbackAudio = document.getElementById("feedbackAudio");
219
219
 
@@ -299,7 +299,7 @@ class Keypad extends KeypadPeer {
299
299
  // Create new buttons
300
300
  this.alphabet.forEach((symbol) => createButton(symbol));
301
301
  // Manually style buttons, according to Denis' algorithm
302
- setTimeout(() => applyMaxKeySize(this.alphabet.length), 100);
302
+ setTimeout(() => applyMaxKeySize(this.alphabet.length), 3); // Why?
303
303
  };
304
304
  visualFeedbackThenReset = (delayTime = 800) => {
305
305
  // ie grey out keys just after use, to discourage rapid response
package/src/maxKeySize.js CHANGED
@@ -11,8 +11,6 @@ const getKeysDimensions = (elem, n, aspect=0.5) => {
11
11
  keyHeightPx= (-1+Math.sqrt(1+4*n*heightPx/widthPx))/(2*n/widthPx);
12
12
  keyHeightPx = (-1+Math.sqrt(1+4*n*heightPx*aspect/widthPx))/(2*aspect*n/widthPx);
13
13
 
14
- console.log(`n=${n}, aspect=${aspect}, widthPx=${widthPx}, heightPx=${heightPx}`);
15
- console.log(`100% efficiency would require keyHightPx ${keyHeightPx.toFixed(1)}`);
16
14
  while (n > (Math.floor(heightPx/keyHeightPx - 1)*Math.floor(widthPx/(aspect*keyHeightPx)))){
17
15
  // Round size down so that screen is a multiple.
18
16
  const ss=[heightPx/Math.ceil(heightPx/keyHeightPx), widthPx/Math.ceil(widthPx/(aspect*keyHeightPx))];
@@ -33,7 +31,6 @@ const getKeysDimensions = (elem, n, aspect=0.5) => {
33
31
  const numKeysHorizontally = Math.floor(widthPx/(aspect*keyHeightPx));
34
32
  const numKeysVertically = Math.floor(heightPx/keyHeightPx-1);
35
33
  const efficiency = 100*areaOfKeys/screenArea;
36
- console.log(`Best keyheightPx ${keyHeightPx} px. ${numKeysHorizontally} horizontally x ${numKeysVertically} vertically. Efficiency ${efficiency}`)
37
34
 
38
35
  return {keyHeightPx: keyHeightPx, cols: numKeysHorizontally, rows:numKeysVertically, widthPx: widthPx, heightPx: heightPx}
39
36
  };
@@ -47,7 +44,6 @@ export const applyMaxKeySize = (numberOfKeys) => {
47
44
  const gridCoords = keyElems.filter((k,i) => !controlKeyElemsMask[i]).map((k,i) => [Math.floor(i/cols), i%cols]);
48
45
  const widthUsed = cols*(keyHeightPx*aspect);
49
46
  const heightUsed = rows*keyHeightPx + keyHeightPx;
50
- console.log("gridCords", gridCoords);
51
47
  const freeHeight = heightPx - heightUsed;
52
48
  const freeWidth = widthPx - widthUsed;
53
49
  const verticalMarginOffset = Math.floor(freeHeight/2);
@@ -57,26 +53,37 @@ export const applyMaxKeySize = (numberOfKeys) => {
57
53
  keyElems.forEach((k,i) => {
58
54
  k.style.position = "fixed";
59
55
  const controlKey = controlKeyElemsMask[i];
60
- const height = `${keyHeightPx}px`;
61
56
  let top, left, width;
62
57
  if (controlKey) {
63
- top = (heightPx-keyHeightPx) - verticalMarginOffset + "px";
64
- left = (k.innerText.toLowerCase() === "space" ? 0 : widthPx/2 - horizontalMarginOffset) + horizontalMarginOffset + "px";
65
- 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";
66
76
  } else {
67
77
  width = keyHeightPx*aspect;
68
78
  const [y,x] = gridCoords[j];
69
79
  j += 1;
70
- console.log(`[x,y]: [${x},${y}]`);
71
- top = y*keyHeightPx + verticalMarginOffset + "px";
72
- left = `${x*width+horizontalMarginOffset}px`;
73
- width += "px";
80
+ top = y*keyHeightPx + verticalMarginOffset ;
81
+ left = x*width+horizontalMarginOffset;
74
82
  }
75
- console.log(`${k.id}, h: ${height}, w: ${width}, top: ${top}, left: ${left}`);
76
- k.style.width = width;
77
- k.style.height = height;
78
- k.style.top = top;
79
- 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";
80
88
  });
81
- console.log("\n");
82
89
  };