@wwawing/virtual-pad 3.12.10 → 3.12.11

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/lib/VirtualPad.js CHANGED
@@ -1,4 +1,4 @@
1
- export var VirtualPadButtonCodes = [
1
+ export const VirtualPadButtonCodes = [
2
2
  "BUTTON_ENTER",
3
3
  "BUTTON_ESC",
4
4
  "BUTTON_SIDEBAR",
@@ -9,21 +9,15 @@ export var VirtualPadButtonCodes = [
9
9
  "BUTTON_RIGHT",
10
10
  "BUTTON_DOWN"
11
11
  ];
12
- var VirtualPadMoveButtonCodes = [
12
+ const VirtualPadMoveButtonCodes = [
13
13
  "BUTTON_LEFT",
14
14
  "BUTTON_UP",
15
15
  "BUTTON_RIGHT",
16
16
  "BUTTON_DOWN"
17
17
  ];
18
- var VirtualPadMoveButtonsSet = new Set(VirtualPadMoveButtonCodes);
19
- var VirtualPadStore = (function () {
20
- function VirtualPadStore(buttons, firstVisible, buttonWrapper, moveButtons, onTouchStart, onTouchEnd) {
21
- if (firstVisible === void 0) { firstVisible = false; }
22
- if (buttonWrapper === void 0) { buttonWrapper = null; }
23
- if (moveButtons === void 0) { moveButtons = null; }
24
- if (onTouchStart === void 0) { onTouchStart = null; }
25
- if (onTouchEnd === void 0) { onTouchEnd = null; }
26
- var _this = this;
18
+ const VirtualPadMoveButtonsSet = new Set(VirtualPadMoveButtonCodes);
19
+ export default class VirtualPadStore {
20
+ constructor(buttons, firstVisible = false, buttonWrapper = null, moveButtons = null, onTouchStart = null, onTouchEnd = null) {
27
21
  this._enabled = buttons !== null;
28
22
  this._visible = firstVisible;
29
23
  this._onTouchStart = onTouchStart || null;
@@ -42,65 +36,61 @@ var VirtualPadStore = (function () {
42
36
  if (buttons === null) {
43
37
  return;
44
38
  }
45
- var _loop_1 = function (buttonTypeString) {
46
- var button = buttons[buttonTypeString];
39
+ for (const buttonTypeString in buttons) {
40
+ const button = buttons[buttonTypeString];
47
41
  if (!button) {
48
- return "continue";
42
+ continue;
49
43
  }
50
- var buttonCode = buttonTypeString;
51
- this_1._availableButtons.push(buttonCode);
44
+ const buttonCode = buttonTypeString;
45
+ this._availableButtons.push(buttonCode);
52
46
  button.setAttribute("type", buttonTypeString);
53
- this_1._isTouchingButtons[buttonCode] = {
47
+ this._isTouchingButtons[buttonCode] = {
54
48
  prev: false,
55
49
  current: false,
56
50
  next: false
57
51
  };
58
- var cancelBrowserTouchEvent = function (event) {
52
+ const cancelBrowserTouchEvent = (event) => {
59
53
  if (event.cancelable) {
60
54
  event.preventDefault();
61
55
  }
62
56
  };
63
- var cancelVirtualPad = function (event) {
57
+ const cancelVirtualPad = (event) => {
64
58
  cancelBrowserTouchEvent(event);
65
- _this.allClear();
59
+ this.allClear();
66
60
  };
67
- button.addEventListener("touchstart", function (event) {
61
+ button.addEventListener("touchstart", (event) => {
68
62
  cancelBrowserTouchEvent(event);
69
- _this.setTouchInfo(buttonCode);
63
+ this.setTouchInfo(buttonCode);
70
64
  });
71
65
  button.addEventListener("touchcancel", cancelVirtualPad);
72
66
  if (VirtualPadStore.isMoveButton(buttonCode)) {
73
- button.addEventListener("touchmove", this_1._detectMovingMoveButton.bind(this_1));
74
- button.addEventListener("touchend", this_1.allMoveClear.bind(this_1));
67
+ button.addEventListener("touchmove", this._detectMovingMoveButton.bind(this));
68
+ button.addEventListener("touchend", this.allMoveClear.bind(this));
75
69
  }
76
70
  else {
77
- button.addEventListener("touchend", function (event) {
71
+ button.addEventListener("touchend", (event) => {
78
72
  cancelBrowserTouchEvent(event);
79
- _this.clearTouchInfo(buttonCode);
73
+ this.clearTouchInfo(buttonCode);
80
74
  });
81
75
  }
82
- };
83
- var this_1 = this;
84
- for (var buttonTypeString in buttons) {
85
- _loop_1(buttonTypeString);
86
76
  }
87
77
  if (moveButtons !== null) {
88
78
  moveButtons.addEventListener("touchmove", this._detectMovingMoveButton.bind(this));
89
79
  }
90
80
  }
91
- VirtualPadStore.prototype._detectMovingMoveButton = function (event) {
81
+ _detectMovingMoveButton(event) {
92
82
  event.preventDefault();
93
83
  this.allMoveClear();
94
- var touch = event.targetTouches.item(0);
84
+ const touch = event.targetTouches.item(0);
95
85
  if (!this._moveButtonsElement || touch === null) {
96
86
  return;
97
87
  }
98
- var moveButtonRect = this._moveButtonsElement.getBoundingClientRect();
99
- var bodyRect = document.body.getBoundingClientRect();
100
- var centerPositionX = moveButtonRect.left - bodyRect.left + (moveButtonRect.width / 2);
101
- var centerPositionY = moveButtonRect.top - bodyRect.top + (moveButtonRect.height / 2);
102
- var touchX = touch.pageX - centerPositionX;
103
- var touchY = touch.pageY - centerPositionY;
88
+ const moveButtonRect = this._moveButtonsElement.getBoundingClientRect();
89
+ const bodyRect = document.body.getBoundingClientRect();
90
+ const centerPositionX = moveButtonRect.left - bodyRect.left + (moveButtonRect.width / 2);
91
+ const centerPositionY = moveButtonRect.top - bodyRect.top + (moveButtonRect.height / 2);
92
+ const touchX = touch.pageX - centerPositionX;
93
+ const touchY = touch.pageY - centerPositionY;
104
94
  if (touchX >= touchY) {
105
95
  if (touchX <= -touchY) {
106
96
  this.setTouchInfo("BUTTON_UP");
@@ -117,8 +107,8 @@ var VirtualPadStore = (function () {
117
107
  this.setTouchInfo("BUTTON_LEFT");
118
108
  }
119
109
  }
120
- };
121
- VirtualPadStore.prototype._setVisible = function (visible) {
110
+ }
111
+ _setVisible(visible) {
122
112
  if (this._moveButtonsElement !== null) {
123
113
  this._moveButtonsElement.style.display = visible ? "grid" : "none";
124
114
  }
@@ -126,28 +116,28 @@ var VirtualPadStore = (function () {
126
116
  this._buttonWrapperElement.style.display = visible ? "grid" : "none";
127
117
  }
128
118
  this._visible = visible;
129
- };
130
- VirtualPadStore.prototype.checkTouchButton = function (buttonType) {
119
+ }
120
+ checkTouchButton(buttonType) {
131
121
  if (!this._enabled) {
132
122
  return false;
133
123
  }
134
- var state = this.getButtonState(buttonType);
124
+ const state = this.getButtonState(buttonType);
135
125
  return state === "TOUCH";
136
- };
137
- VirtualPadStore.prototype.checkTouchingButton = function (buttonType) {
126
+ }
127
+ checkTouchingButton(buttonType) {
138
128
  if (!this._enabled) {
139
129
  return false;
140
130
  }
141
- var state = this.getButtonState(buttonType);
131
+ const state = this.getButtonState(buttonType);
142
132
  return state === "TOUCH" || state === "TOUCHING";
143
- };
144
- VirtualPadStore.prototype.getButtonState = function (buttonType) {
145
- var button = this._isTouchingButtons[buttonType];
133
+ }
134
+ getButtonState(buttonType) {
135
+ const button = this._isTouchingButtons[buttonType];
146
136
  if (!this._enabled || button === undefined) {
147
137
  return "NONE";
148
138
  }
149
- var touched = button.prev;
150
- var isTouching = button.current;
139
+ const touched = button.prev;
140
+ const isTouching = button.current;
151
141
  if (touched && isTouching) {
152
142
  return "TOUCHING";
153
143
  }
@@ -158,69 +148,64 @@ var VirtualPadStore = (function () {
158
148
  return "LEAVE";
159
149
  }
160
150
  return "NONE";
161
- };
162
- VirtualPadStore.prototype.setTouchInfo = function (buttonType) {
163
- var button = this._isTouchingButtons[buttonType];
151
+ }
152
+ setTouchInfo(buttonType) {
153
+ const button = this._isTouchingButtons[buttonType];
164
154
  if (!this._enabled || button === undefined) {
165
155
  return;
166
156
  }
167
157
  button.next = true;
168
- };
169
- VirtualPadStore.prototype.clearTouchInfo = function (buttonType) {
170
- var button = this._isTouchingButtons[buttonType];
158
+ }
159
+ clearTouchInfo(buttonType) {
160
+ const button = this._isTouchingButtons[buttonType];
171
161
  if (!this._enabled || button === undefined) {
172
162
  return;
173
163
  }
174
164
  button.next = false;
175
- };
176
- VirtualPadStore.prototype.allMoveClear = function () {
177
- var _this = this;
178
- VirtualPadMoveButtonCodes.forEach(function (buttonCode) {
179
- if (_this._availableButtons.includes(buttonCode)) {
180
- _this.clearTouchInfo(buttonCode);
165
+ }
166
+ allMoveClear() {
167
+ VirtualPadMoveButtonCodes.forEach((buttonCode) => {
168
+ if (this._availableButtons.includes(buttonCode)) {
169
+ this.clearTouchInfo(buttonCode);
181
170
  }
182
171
  });
183
- };
184
- VirtualPadStore.prototype.allClear = function () {
185
- var _this = this;
186
- this._availableButtons.forEach(function (buttonCode) {
172
+ }
173
+ allClear() {
174
+ this._availableButtons.forEach((buttonCode) => {
187
175
  if (buttonCode !== undefined) {
188
- var button = _this._isTouchingButtons[buttonCode];
176
+ const button = this._isTouchingButtons[buttonCode];
189
177
  if (button !== undefined) {
190
178
  button.next = false;
191
179
  }
192
180
  }
193
181
  });
194
- };
195
- VirtualPadStore.isMoveButton = function (buttonType) {
182
+ }
183
+ static isMoveButton(buttonType) {
196
184
  return VirtualPadMoveButtonsSet.has(buttonType);
197
- };
198
- VirtualPadStore.prototype.update = function () {
199
- var _this = this;
200
- this._availableButtons.forEach(function (buttonCode) {
185
+ }
186
+ update() {
187
+ this._availableButtons.forEach((buttonCode) => {
201
188
  var _a, _b;
202
189
  if (buttonCode === undefined) {
203
190
  return;
204
191
  }
205
- var currentButtonTouching = _this._isTouchingButtons[buttonCode];
192
+ const currentButtonTouching = this._isTouchingButtons[buttonCode];
206
193
  if (currentButtonTouching === undefined) {
207
194
  return;
208
195
  }
209
- _this._isTouchingButtons[buttonCode].prev = currentButtonTouching.current;
210
- _this._isTouchingButtons[buttonCode].current = currentButtonTouching.next;
211
- switch (_this.getButtonState(buttonCode)) {
196
+ this._isTouchingButtons[buttonCode].prev = currentButtonTouching.current;
197
+ this._isTouchingButtons[buttonCode].current = currentButtonTouching.next;
198
+ switch (this.getButtonState(buttonCode)) {
212
199
  case "TOUCH":
213
- (_a = _this._onTouchStart) === null || _a === void 0 ? void 0 : _a.call(_this, buttonCode);
200
+ (_a = this._onTouchStart) === null || _a === void 0 ? void 0 : _a.call(this, buttonCode);
214
201
  break;
215
202
  case "LEAVE":
216
- (_b = _this._onTouchEnd) === null || _b === void 0 ? void 0 : _b.call(_this, buttonCode);
203
+ (_b = this._onTouchEnd) === null || _b === void 0 ? void 0 : _b.call(this, buttonCode);
217
204
  break;
218
205
  }
219
206
  });
220
- };
221
- VirtualPadStore.prototype.toggleVisible = function () {
207
+ }
208
+ toggleVisible() {
222
209
  this._setVisible(!this._visible);
223
- };
224
- return VirtualPadStore;
225
- }());
226
- export default VirtualPadStore;
210
+ }
211
+ }
package/lib/makeInject.js CHANGED
@@ -1,3 +1,16 @@
1
1
  export default function makeInject() {
2
- return "\n <div id=\"wwa-virtualpad-left\">\n <button class=\"wwa-virtualpad__button\" id=\"wwa-up-button\"></button>\n <button class=\"wwa-virtualpad__button\" id=\"wwa-left-button\"></button>\n <button class=\"wwa-virtualpad__button\" id=\"wwa-right-button\"></button>\n <button class=\"wwa-virtualpad__button\" id=\"wwa-down-button\"></button>\n <div class=\"wwa-virtualpad__hole\"></div>\n </div>\n <div id=\"wwa-virtualpad-right\">\n <button class=\"wwa-virtualpad__button\" id=\"wwa-slow-button\">I</button>\n <button class=\"wwa-virtualpad__button\" id=\"wwa-fast-button\">P</button>\n <button class=\"wwa-virtualpad__button\" id=\"wwa-enter-button\">Y</button>\n <button class=\"wwa-virtualpad__button\" id=\"wwa-esc-button\">N</button>\n </div>";
2
+ return `
3
+ <div id="wwa-virtualpad-left">
4
+ <button class="wwa-virtualpad__button" id="wwa-up-button"></button>
5
+ <button class="wwa-virtualpad__button" id="wwa-left-button"></button>
6
+ <button class="wwa-virtualpad__button" id="wwa-right-button"></button>
7
+ <button class="wwa-virtualpad__button" id="wwa-down-button"></button>
8
+ <div class="wwa-virtualpad__hole"></div>
9
+ </div>
10
+ <div id="wwa-virtualpad-right">
11
+ <button class="wwa-virtualpad__button" id="wwa-slow-button">I</button>
12
+ <button class="wwa-virtualpad__button" id="wwa-fast-button">P</button>
13
+ <button class="wwa-virtualpad__button" id="wwa-enter-button">Y</button>
14
+ <button class="wwa-virtualpad__button" id="wwa-esc-button">N</button>
15
+ </div>`;
3
16
  }
@@ -1,24 +1,24 @@
1
1
  export function initializeViewport() {
2
- var headElement = document.getElementsByTagName('head')[0];
3
- var viewportElement = document.createElement('meta');
2
+ const headElement = document.getElementsByTagName('head')[0];
3
+ let viewportElement = document.createElement('meta');
4
4
  viewportElement.setAttribute('name', 'viewport');
5
5
  headElement.appendChild(viewportElement);
6
6
  viewportFit();
7
7
  }
8
8
  export default function viewportFit() {
9
- var WWA_WIDTH = 560;
10
- var WWA_HEIGHT = 440;
11
- var BROWSER_MARGIN = 8;
12
- var viewportElement = document.querySelector("meta[name='viewport']");
13
- var browserWidth = window.innerWidth;
14
- var browserHeight = window.innerHeight;
15
- var viewportValue = "user-scalable=no";
9
+ const WWA_WIDTH = 560;
10
+ const WWA_HEIGHT = 440;
11
+ const BROWSER_MARGIN = 8;
12
+ const viewportElement = document.querySelector("meta[name='viewport']");
13
+ const browserWidth = window.innerWidth;
14
+ const browserHeight = window.innerHeight;
15
+ let viewportValue = "user-scalable=no";
16
16
  if (browserWidth > browserHeight) {
17
- var width = Math.floor((browserWidth / browserHeight) * (WWA_HEIGHT + (BROWSER_MARGIN) * 2));
18
- viewportValue = "width=".concat(width, ",").concat(viewportValue);
17
+ const width = Math.floor((browserWidth / browserHeight) * (WWA_HEIGHT + (BROWSER_MARGIN) * 2));
18
+ viewportValue = `width=${width},${viewportValue}`;
19
19
  }
20
20
  else if (browserWidth <= browserHeight) {
21
- viewportValue = "width=".concat(WWA_WIDTH + (BROWSER_MARGIN * 2), ",").concat(viewportValue);
21
+ viewportValue = `width=${WWA_WIDTH + (BROWSER_MARGIN * 2)},${viewportValue}`;
22
22
  }
23
- viewportElement === null || viewportElement === void 0 ? void 0 : viewportElement.setAttribute("content", "".concat(viewportValue));
23
+ viewportElement === null || viewportElement === void 0 ? void 0 : viewportElement.setAttribute("content", `${viewportValue}`);
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwawing/virtual-pad",
3
- "version": "3.12.10",
3
+ "version": "3.12.11",
4
4
  "description": "WWA Wing Virtual Pad for mobile phone",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -16,5 +16,5 @@
16
16
  "publishConfig": {
17
17
  "access": "public"
18
18
  },
19
- "gitHead": "5f1b484f4996daa4e6c7b5e2603e471d5db6a0fc"
19
+ "gitHead": "9cd59237d23c90c4d6c1a9eed2c5eae337948941"
20
20
  }