@famibee/skynovel 2.0.2 → 2.0.4

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.
Files changed (121) hide show
  1. package/dist/Button.js +36 -34
  2. package/dist/Button.js.map +1 -1
  3. package/dist/CallStack.js +11 -6
  4. package/dist/CallStack.js.map +1 -1
  5. package/dist/CmnInterface.js +13 -11
  6. package/dist/CmnInterface.js.map +1 -1
  7. package/dist/CmnLib.js +58 -56
  8. package/dist/CmnLib.js.map +1 -1
  9. package/dist/Config.js +9 -7
  10. package/dist/Config.js.map +1 -1
  11. package/dist/ConfigBase.js +52 -49
  12. package/dist/ConfigBase.js.map +1 -1
  13. package/dist/DebugMng.js +9 -6
  14. package/dist/DebugMng.js.map +1 -1
  15. package/dist/EventListenerCtn.js +6 -4
  16. package/dist/EventListenerCtn.js.map +1 -1
  17. package/dist/EventMng.js +522 -417
  18. package/dist/EventMng.js.map +1 -1
  19. package/dist/Grammar.js +22 -20
  20. package/dist/Grammar.js.map +1 -1
  21. package/dist/GrpLayer.js +58 -57
  22. package/dist/GrpLayer.js.map +1 -1
  23. package/dist/Layer.js +66 -64
  24. package/dist/Layer.js.map +1 -1
  25. package/dist/LayerMng.js +461 -441
  26. package/dist/LayerMng.js.map +1 -1
  27. package/dist/Main.js +69 -67
  28. package/dist/Main.js.map +1 -1
  29. package/dist/PropParser.js +23 -19
  30. package/dist/PropParser.js.map +1 -1
  31. package/dist/Reading.js +422 -418
  32. package/dist/Reading.js.map +1 -1
  33. package/dist/RubySpliter.js +4 -2
  34. package/dist/RubySpliter.js.map +1 -1
  35. package/dist/ScriptIterator.js +374 -370
  36. package/dist/ScriptIterator.js.map +1 -1
  37. package/dist/SndBuf.js +643 -622
  38. package/dist/SndBuf.js.map +1 -1
  39. package/dist/SoundMng.js +59 -60
  40. package/dist/SoundMng.js.map +1 -1
  41. package/dist/SpritesMng.js +135 -129
  42. package/dist/SpritesMng.js.map +1 -1
  43. package/dist/SysBase.js +1019 -955
  44. package/dist/SysBase.js.map +1 -1
  45. package/dist/TxtLayer.js +558 -551
  46. package/dist/TxtLayer.js.map +1 -1
  47. package/dist/Variable.js +47 -45
  48. package/dist/Variable.js.map +1 -1
  49. package/dist/chunk.js +11 -9
  50. package/dist/gamepad.js +396 -660
  51. package/dist/gamepad.js.map +1 -1
  52. package/dist/pixi.js +3044 -3648
  53. package/dist/pixi.js.map +1 -1
  54. package/dist/platform.js +6 -4
  55. package/dist/platform.js.map +1 -1
  56. package/dist/rolldown-runtime.js +20 -0
  57. package/dist/web.js +106 -590
  58. package/dist/web.js.map +1 -1
  59. package/dist_app/Button.js +36 -34
  60. package/dist_app/Button.js.map +1 -1
  61. package/dist_app/CallStack.js +11 -6
  62. package/dist_app/CallStack.js.map +1 -1
  63. package/dist_app/CmnInterface.js +13 -11
  64. package/dist_app/CmnInterface.js.map +1 -1
  65. package/dist_app/CmnLib.js +58 -56
  66. package/dist_app/CmnLib.js.map +1 -1
  67. package/dist_app/Config.js +9 -7
  68. package/dist_app/Config.js.map +1 -1
  69. package/dist_app/ConfigBase.js +52 -49
  70. package/dist_app/ConfigBase.js.map +1 -1
  71. package/dist_app/DebugMng.js +9 -6
  72. package/dist_app/DebugMng.js.map +1 -1
  73. package/dist_app/EventListenerCtn.js +6 -4
  74. package/dist_app/EventListenerCtn.js.map +1 -1
  75. package/dist_app/EventMng.js +522 -417
  76. package/dist_app/EventMng.js.map +1 -1
  77. package/dist_app/Grammar.js +22 -20
  78. package/dist_app/Grammar.js.map +1 -1
  79. package/dist_app/GrpLayer.js +58 -57
  80. package/dist_app/GrpLayer.js.map +1 -1
  81. package/dist_app/Layer.js +66 -64
  82. package/dist_app/Layer.js.map +1 -1
  83. package/dist_app/LayerMng.js +461 -441
  84. package/dist_app/LayerMng.js.map +1 -1
  85. package/dist_app/Main.js +69 -67
  86. package/dist_app/Main.js.map +1 -1
  87. package/dist_app/PropParser.js +23 -19
  88. package/dist_app/PropParser.js.map +1 -1
  89. package/dist_app/Reading.js +422 -418
  90. package/dist_app/Reading.js.map +1 -1
  91. package/dist_app/RubySpliter.js +4 -2
  92. package/dist_app/RubySpliter.js.map +1 -1
  93. package/dist_app/ScriptIterator.js +374 -370
  94. package/dist_app/ScriptIterator.js.map +1 -1
  95. package/dist_app/SndBuf.js +643 -622
  96. package/dist_app/SndBuf.js.map +1 -1
  97. package/dist_app/SoundMng.js +59 -60
  98. package/dist_app/SoundMng.js.map +1 -1
  99. package/dist_app/SpritesMng.js +135 -129
  100. package/dist_app/SpritesMng.js.map +1 -1
  101. package/dist_app/SysBase.js +1019 -955
  102. package/dist_app/SysBase.js.map +1 -1
  103. package/dist_app/TxtLayer.js +558 -551
  104. package/dist_app/TxtLayer.js.map +1 -1
  105. package/dist_app/Variable.js +47 -45
  106. package/dist_app/Variable.js.map +1 -1
  107. package/dist_app/app.js +62 -63
  108. package/dist_app/app.js.map +1 -1
  109. package/dist_app/appMain.js +1 -21
  110. package/dist_app/appMain.js.map +1 -1
  111. package/dist_app/chunk.js +11 -9
  112. package/dist_app/gamepad.js +396 -660
  113. package/dist_app/gamepad.js.map +1 -1
  114. package/dist_app/pixi.js +2028 -1990
  115. package/dist_app/pixi.js.map +1 -1
  116. package/dist_app/platform.js +6 -4
  117. package/dist_app/platform.js.map +1 -1
  118. package/dist_app/preload.js +1 -1
  119. package/dist_app/preload.js.map +1 -1
  120. package/dist_app/rolldown-runtime.js +20 -0
  121. package/package.json +20 -47
@@ -1,723 +1,459 @@
1
- import { t as __commonJSMin } from "./chunk.js";
2
- var require_gamepad = /* @__PURE__ */ __commonJSMin(((e, t) => {
3
- (function(n, r) {
4
- typeof e == "object" && typeof t == "object" ? t.exports = r() : typeof define == "function" && define.amd ? define([], r) : typeof e == "object" ? e.gamepad = r() : n.gamepad = r();
5
- })(e, (() => (() => {
6
- var e = {
7
- 944: function(e) {
8
- e.exports = (() => (() => {
9
- var e = {
10
- d: (t, n) => {
11
- for (var r in n) e.o(n, r) && !e.o(t, r) && Object.defineProperty(t, r, {
12
- enumerable: !0,
13
- get: n[r]
14
- });
15
- },
16
- o: (e, t) => Object.prototype.hasOwnProperty.call(e, t)
17
- }, t = {};
18
- function n(e) {
19
- return n = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
20
- return typeof e;
21
- } : function(e) {
22
- return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
23
- }, n(e);
24
- }
25
- function r(e, t) {
26
- var n = typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
27
- if (!n) {
28
- if (Array.isArray(e) || (n = a(e)) || t && e && typeof e.length == "number") {
29
- n && (e = n);
30
- var r = 0, i = function() {};
31
- return {
32
- s: i,
33
- n: function() {
34
- return r >= e.length ? { done: !0 } : {
35
- done: !1,
36
- value: e[r++]
37
- };
38
- },
39
- e: function(e) {
40
- throw e;
41
- },
42
- f: i
43
- };
44
- }
45
- throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
- }
47
- var o, s = !0, c = !1;
1
+ //#region node_modules/gamepad.js/dist/gamepad.js
2
+ var e = class {
3
+ constructor(e, t) {
4
+ this.type = e, this.detail = t;
5
+ }
6
+ }, t = class {
7
+ #e = /* @__PURE__ */ new Map();
8
+ constructor() {
9
+ this.addEventListener = this.addEventListener.bind(this), this.removeEventListener = this.removeEventListener.bind(this), this.on = this.addEventListener, this.off = this.removeEventListener;
10
+ }
11
+ emit(t, n) {
12
+ if (!this.#e.has(t)) return;
13
+ let r = this.#e.get(t), i = new e(t, n), { length: a } = r;
14
+ for (let e = 0; e < a; e++) r[e](i);
15
+ }
16
+ addEventListener(e, t) {
17
+ let n = this.#t(e);
18
+ n.indexOf(t) < 0 && n.push(t);
19
+ }
20
+ removeEventListener(e, t) {
21
+ if (!this.#e.has(e)) return;
22
+ let n = this.#e.get(e), r = n.indexOf(t);
23
+ r >= 0 && n.splice(r, 1), n.length === 0 && this.#e.delete(e);
24
+ }
25
+ countEventListeners() {
26
+ return this.#e.size;
27
+ }
28
+ removeAllEventListeners() {
29
+ this.#e.clear();
30
+ }
31
+ #t(e) {
32
+ if (this.#e.has(e)) return this.#e.get(e);
33
+ let t = [];
34
+ return this.#e.set(e, t), t;
35
+ }
36
+ };
37
+ function n(e) {
38
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
39
+ }
40
+ var r = { exports: {} }, i = r.exports, a;
41
+ function o() {
42
+ return a || (a = 1, (function(e, t) {
43
+ (function(t, n) {
44
+ e.exports = n();
45
+ })(i, (() => (() => {
46
+ var e = {
47
+ d: (t, n) => {
48
+ for (var r in n) e.o(n, r) && !e.o(t, r) && Object.defineProperty(t, r, {
49
+ enumerable: !0,
50
+ get: n[r]
51
+ });
52
+ },
53
+ o: (e, t) => Object.prototype.hasOwnProperty.call(e, t)
54
+ }, t = {};
55
+ function n(e) {
56
+ return n = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
57
+ return typeof e;
58
+ } : function(e) {
59
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
60
+ }, n(e);
61
+ }
62
+ function r(e, t) {
63
+ var n = typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
64
+ if (!n) {
65
+ if (Array.isArray(e) || (n = a(e)) || t) {
66
+ n && (e = n);
67
+ var r = 0, i = function() {};
48
68
  return {
49
- s: function() {
50
- n = n.call(e);
51
- },
69
+ s: i,
52
70
  n: function() {
53
- var e = n.next();
54
- return s = e.done, e;
71
+ return r >= e.length ? { done: !0 } : {
72
+ done: !1,
73
+ value: e[r++]
74
+ };
55
75
  },
56
76
  e: function(e) {
57
- c = !0, o = e;
77
+ throw e;
58
78
  },
59
- f: function() {
60
- try {
61
- s || n.return == null || n.return();
62
- } finally {
63
- if (c) throw o;
64
- }
65
- }
79
+ f: i
66
80
  };
67
81
  }
68
- function i(e, t) {
69
- return function(e) {
70
- if (Array.isArray(e)) return e;
71
- }(e) || function(e, t) {
72
- var n = e == null ? null : typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
73
- if (n != null) {
74
- var r, i, a, o, s = [], c = !0, l = !1;
75
- try {
76
- if (a = (n = n.call(e)).next, t === 0) {
77
- if (Object(n) !== n) return;
78
- c = !1;
79
- } else for (; !(c = (r = a.call(n)).done) && (s.push(r.value), s.length !== t); c = !0);
80
- } catch (e) {
81
- l = !0, i = e;
82
- } finally {
83
- try {
84
- if (!c && n.return != null && (o = n.return(), Object(o) !== o)) return;
85
- } finally {
86
- if (l) throw i;
87
- }
88
- }
89
- return s;
90
- }
91
- }(e, t) || a(e, t) || function() {
92
- throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
93
- }();
94
- }
95
- function a(e, t) {
96
- if (e) {
97
- if (typeof e == "string") return o(e, t);
98
- var n = Object.prototype.toString.call(e).slice(8, -1);
99
- return n === "Object" && e.constructor && (n = e.constructor.name), n === "Map" || n === "Set" ? Array.from(e) : n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? o(e, t) : void 0;
82
+ throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
83
+ }
84
+ var o, s = !0, c = !1;
85
+ return {
86
+ s: function() {
87
+ n = n.call(e);
88
+ },
89
+ n: function() {
90
+ var e = n.next();
91
+ return s = e.done, e;
92
+ },
93
+ e: function(e) {
94
+ c = !0, o = e;
95
+ },
96
+ f: function() {
97
+ try {
98
+ s || n.return == null || n.return();
99
+ } finally {
100
+ if (c) throw o;
100
101
  }
101
102
  }
102
- function o(e, t) {
103
- (t == null || t > e.length) && (t = e.length);
104
- for (var n = 0, r = Array(t); n < t; n++) r[n] = e[n];
105
- return r;
106
- }
107
- function s(e, t) {
108
- if (!(e instanceof t)) throw TypeError("Cannot call a class as a function");
109
- }
110
- e.d(t, { default: () => c });
111
- var c = function() {
112
- function e() {
113
- var t = !(arguments.length > 0 && arguments[0] !== void 0) || arguments[0];
114
- s(this, e), this.strict = t, this.defaults = /* @__PURE__ */ new Map(), this.validators = /* @__PURE__ */ new Map(), this.types = /* @__PURE__ */ new Map(), this.optional = /* @__PURE__ */ new Set(), this.required = /* @__PURE__ */ new Set();
115
- }
116
- var t, a;
117
- return t = e, (a = [
118
- {
119
- key: "allowExtra",
120
- value: function() {
121
- return this.strict = !1, this;
122
- }
123
- },
124
- {
125
- key: "setDefaults",
126
- value: function(e) {
127
- var t = this;
128
- return Object.entries(e).forEach((function(e) {
129
- var n = i(e, 2), r = n[0], a = n[1];
130
- return t.defaults.set(r, a);
131
- })), this;
132
- }
133
- },
134
- {
135
- key: "setValidators",
136
- value: function(e) {
137
- var t = this;
138
- return Object.entries(e).forEach((function(e) {
139
- var n = i(e, 2), r = n[0], a = n[1];
140
- return t.validators.set(r, a);
141
- })), this;
142
- }
143
- },
144
- {
145
- key: "setTypes",
146
- value: function(e) {
147
- var t = this;
148
- return Object.entries(e).forEach((function(e) {
149
- var n = i(e, 2), r = n[0], a = n[1];
150
- return t.types.set(r, a);
151
- })), this;
152
- }
153
- },
154
- {
155
- key: "setOptional",
156
- value: function(e) {
157
- var t = this;
158
- return e.forEach((function(e) {
159
- return t.optional.add(e);
160
- })), this;
161
- }
162
- },
163
- {
164
- key: "setRequired",
165
- value: function(e) {
166
- var t = this;
167
- return e.forEach((function(e) {
168
- return t.required.add(e);
169
- })), this;
170
- }
171
- },
172
- {
173
- key: "resolve",
174
- value: function(e) {
175
- return this.validate(Object.assign(this.getDefaults(), e));
176
- }
177
- },
178
- {
179
- key: "getDefaults",
180
- value: function() {
181
- var e, t = {}, n = r(this.defaults);
182
- try {
183
- for (n.s(); !(e = n.n()).done;) {
184
- var a = i(e.value, 2), o = a[0];
185
- t[o] = a[1];
186
- }
187
- } catch (e) {
188
- n.e(e);
189
- } finally {
190
- n.f();
191
- }
192
- return t;
193
- }
194
- },
195
- {
196
- key: "validate",
197
- value: function(e) {
198
- for (var t in e) this.validators.has(t) && (e[t] = this.validators.get(t)(e[t]));
199
- for (var n in e) {
200
- if (!this.optionExists(n)) throw Error(`Unkown option "${n}".`);
201
- this.checkType(n, e[n]);
202
- }
203
- var i, a = r(this.required.values());
204
- try {
205
- for (a.s(); !(i = a.n()).done;) {
206
- var o = i.value;
207
- if (e[o] === void 0) throw Error(`Option "${o}" is required.`);
208
- }
209
- } catch (e) {
210
- a.e(e);
211
- } finally {
212
- a.f();
213
- }
214
- return e;
215
- }
216
- },
217
- {
218
- key: "checkType",
219
- value: function(e, t) {
220
- if (this.types.has(e)) {
221
- var r = this.types.get(e), i = n(t);
222
- if (i !== r) throw Error(`Wrong value for option "${e}": expected type "${r}", got "${i}".`);
223
- }
224
- }
225
- },
226
- {
227
- key: "optionExists",
228
- value: function(e) {
229
- return !this.strict || this.defaults.has(e) || this.validators.has(e) || this.optional.has(e) || this.required.has(e) || this.types.has(e);
230
- }
231
- }
232
- ]) && function(e, t) {
233
- for (var r = 0; r < t.length; r++) {
234
- var i = t[r];
235
- i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(e, (a = function(e, t) {
236
- if (n(e) !== "object" || e === null) return e;
237
- var r = e[Symbol.toPrimitive];
238
- if (r !== void 0) {
239
- var i = r.call(e, "string");
240
- if (n(i) !== "object") return i;
241
- throw TypeError("@@toPrimitive must return a primitive value.");
242
- }
243
- return String(e);
244
- }(i.key), n(a) === "symbol" ? a : String(a)), i);
103
+ };
104
+ }
105
+ function i(e, t) {
106
+ return (function(e) {
107
+ if (Array.isArray(e)) return e;
108
+ })(e) || (function(e, t) {
109
+ var n = e == null ? null : typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
110
+ if (n != null) {
111
+ var r, i, a, o, s = [], c = !0, l = !1;
112
+ try {
113
+ if (a = (n = n.call(e)).next, t !== 0) for (; !(c = (r = a.call(n)).done) && (s.push(r.value), s.length !== t); c = !0);
114
+ } catch (e) {
115
+ l = !0, i = e;
116
+ } finally {
117
+ try {
118
+ if (!c && n.return != null && (o = n.return(), Object(o) !== o)) return;
119
+ } finally {
120
+ if (l) throw i;
245
121
  }
246
- var a;
247
- }(t.prototype, a), Object.defineProperty(t, "prototype", { writable: !1 }), e;
248
- }();
249
- return t.default;
250
- })())();
251
- },
252
- 162: function(e) {
253
- e.exports = (() => {
254
- var e = {
255
- d: (t, n) => {
256
- for (var r in n) e.o(n, r) && !e.o(t, r) && Object.defineProperty(t, r, {
257
- enumerable: !0,
258
- get: n[r]
259
- });
260
- },
261
- o: (e, t) => Object.prototype.hasOwnProperty.call(e, t)
262
- }, t = {};
263
- e.d(t, { default: () => n });
264
- var n = function() {
265
- function e() {
266
- (function(e, t) {
267
- if (!(e instanceof t)) throw TypeError("Cannot call a class as a function");
268
- })(this, e), this._events = {}, this.on = this.addEventListener, this.off = this.removeEventListener;
269
122
  }
270
- var t;
271
- return (t = [
272
- {
273
- key: "emit",
274
- value: function(e, t) {
275
- if (Object.prototype.hasOwnProperty.call(this._events, e)) for (var n = this._events[e], r = {
276
- type: e,
277
- detail: t
278
- }, i = n.length, a = 0; a < i; a++) this.handle(n[a], r);
279
- }
280
- },
281
- {
282
- key: "handle",
283
- value: function(e, t) {
284
- e(t);
285
- }
286
- },
287
- {
288
- key: "addEventListener",
289
- value: function(e, t) {
290
- Object.prototype.hasOwnProperty.call(this._events, e) || (this._events[e] = []), this._events[e].indexOf(t) < 0 && this._events[e].push(t);
291
- }
292
- },
293
- {
294
- key: "removeEventListener",
295
- value: function(e, t) {
296
- if (Object.prototype.hasOwnProperty.call(this._events, e)) {
297
- var n = this._events[e], r = n.indexOf(t);
298
- r >= 0 && n.splice(r, 1), n.length === 0 && delete this._events[e];
299
- }
300
- }
301
- }
302
- ]) && function(e, t) {
303
- for (var n = 0; n < t.length; n++) {
304
- var r = t[n];
305
- r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r);
306
- }
307
- }(e.prototype, t), e;
308
- }();
309
- return t.default;
123
+ return s;
124
+ }
125
+ })(e, t) || a(e, t) || (function() {
126
+ throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
310
127
  })();
311
128
  }
312
- }, t = {};
313
- function n(r) {
314
- var i = t[r];
315
- if (i !== void 0) return i.exports;
316
- var a = t[r] = { exports: {} };
317
- return e[r].call(a.exports, a, a.exports, n), a.exports;
318
- }
319
- n.n = (e) => {
320
- var t = e && e.__esModule ? () => e.default : () => e;
321
- return n.d(t, { a: t }), t;
322
- }, n.d = (e, t) => {
323
- for (var r in t) n.o(t, r) && !n.o(e, r) && Object.defineProperty(e, r, {
324
- enumerable: !0,
325
- get: t[r]
326
- });
327
- }, n.o = (e, t) => Object.prototype.hasOwnProperty.call(e, t), n.r = (e) => {
328
- typeof Symbol < "u" && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 });
329
- };
330
- var r = {};
331
- return (() => {
332
- n.r(r), n.d(r, {
333
- GamepadHandler: () => g,
334
- GamepadListener: () => k
335
- });
336
- var e = n(162), t = n.n(e), i = n(944), a = n.n(i);
337
- function o(e) {
338
- return o = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
339
- return typeof e;
340
- } : function(e) {
341
- return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
342
- }, o(e);
129
+ function a(e, t) {
130
+ if (e) {
131
+ if (typeof e == "string") return o(e, t);
132
+ var n = Object.prototype.toString.call(e).slice(8, -1);
133
+ return n === "Object" && e.constructor && (n = e.constructor.name), n === "Map" || n === "Set" ? Array.from(e) : n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? o(e, t) : void 0;
134
+ }
135
+ }
136
+ function o(e, t) {
137
+ (t == null || t > e.length) && (t = e.length);
138
+ for (var n = 0, r = Array(t); n < t; n++) r[n] = e[n];
139
+ return r;
343
140
  }
344
141
  function s(e, t) {
345
142
  if (!(e instanceof t)) throw TypeError("Cannot call a class as a function");
346
143
  }
347
144
  function c(e, t) {
348
- for (var n = 0; n < t.length; n++) {
349
- var r = t[n];
350
- r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, f(r.key), r);
145
+ for (var r = 0; r < t.length; r++) {
146
+ var i = t[r];
147
+ i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(e, (a = (function(e, t) {
148
+ if (n(e) !== "object" || e === null) return e;
149
+ var r = e[Symbol.toPrimitive];
150
+ if (r !== void 0) {
151
+ var i = r.call(e, "string");
152
+ if (n(i) !== "object") return i;
153
+ throw TypeError("@@toPrimitive must return a primitive value.");
154
+ }
155
+ return String(e);
156
+ })(i.key), n(a) === "symbol" ? a : String(a)), i);
351
157
  }
158
+ var a;
352
159
  }
353
- function l(e, t) {
354
- return l = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(e, t) {
355
- return e.__proto__ = t, e;
356
- }, l(e, t);
357
- }
358
- function u(e, t) {
359
- if (t && (o(t) === "object" || typeof t == "function")) return t;
360
- if (t !== void 0) throw TypeError("Derived constructors may only return object or undefined");
361
- return function(e) {
362
- if (e === void 0) throw ReferenceError("this hasn't been initialised - super() hasn't been called");
363
- return e;
364
- }(e);
365
- }
366
- function d(e) {
367
- return d = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(e) {
368
- return e.__proto__ || Object.getPrototypeOf(e);
369
- }, d(e);
370
- }
371
- function f(e) {
372
- var t = function(e, t) {
373
- if (o(e) !== "object" || e === null) return e;
374
- var n = e[Symbol.toPrimitive];
375
- if (n !== void 0) {
376
- var r = n.call(e, "string");
377
- if (o(r) !== "object") return r;
378
- throw TypeError("@@toPrimitive must return a primitive value.");
379
- }
380
- return String(e);
381
- }(e);
382
- return o(t) === "symbol" ? t : String(t);
383
- }
384
- var p, m, h, g = function(e) {
385
- (function(e, t) {
386
- if (typeof t != "function" && t !== null) throw TypeError("Super expression must either be null or a function");
387
- e.prototype = Object.create(t && t.prototype, { constructor: {
388
- value: e,
389
- writable: !0,
390
- configurable: !0
391
- } }), Object.defineProperty(e, "prototype", { writable: !1 }), t && l(e, t);
392
- })(f, e);
393
- var t, n, r, i, a, o = (i = f, a = function() {
394
- if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1;
395
- if (typeof Proxy == "function") return !0;
396
- try {
397
- return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0;
398
- } catch {
399
- return !1;
400
- }
401
- }(), function() {
402
- var e, t = d(i);
403
- if (a) {
404
- var n = d(this).constructor;
405
- e = Reflect.construct(t, arguments, n);
406
- } else e = t.apply(this, arguments);
407
- return u(this, e);
408
- });
409
- function f(e, t) {
410
- var n, r = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
411
- return s(this, f), (n = o.call(this)).index = e, n.gamepad = t, n.options = n.constructor.resolveOptions(r), n.axes = Array(t.axes.length).fill(null), n.buttons = Array(t.buttons.length).fill(null), n.initAxes(), n.initButtons(), n;
160
+ e.d(t, { default: () => l });
161
+ var l = (function() {
162
+ function e() {
163
+ var t = !(arguments.length > 0 && arguments[0] !== void 0) || arguments[0];
164
+ s(this, e), this.strict = t, this.defaults = /* @__PURE__ */ new Map(), this.validators = /* @__PURE__ */ new Map(), this.types = /* @__PURE__ */ new Map(), this.optional = /* @__PURE__ */ new Set(), this.required = /* @__PURE__ */ new Set();
412
165
  }
413
- return t = f, r = [{
414
- key: "resolveOptions",
415
- value: function(e) {
416
- var t = e.axis, n = e.button;
417
- return {
418
- axis: this.optionResolver.resolve(t ?? n ?? e ?? {}),
419
- button: this.optionResolver.resolve(n ?? t ?? e ?? {})
420
- };
421
- }
422
- }], (n = [
166
+ var t, a;
167
+ return t = e, (a = [
423
168
  {
424
- key: "initAxes",
169
+ key: "allowExtra",
425
170
  value: function() {
426
- for (var e = this.axes.length, t = 0; t < e; t++) this.axes[t] = this.resolveAxisValue(t);
171
+ return this.strict = !1, this;
427
172
  }
428
173
  },
429
174
  {
430
- key: "initButtons",
431
- value: function() {
432
- for (var e = this.buttons.length, t = 0; t < e; t++) this.buttons[t] = this.resolveButtonValue(t);
433
- }
434
- },
435
- {
436
- key: "update",
175
+ key: "setDefaults",
437
176
  value: function(e) {
438
- this.gamepad = e, this.updateAxis(), this.updateButtons();
177
+ var t = this;
178
+ return Object.entries(e).forEach((function(e) {
179
+ var n = i(e, 2), r = n[0], a = n[1];
180
+ return t.defaults.set(r, a);
181
+ })), this;
439
182
  }
440
183
  },
441
184
  {
442
- key: "updateAxis",
443
- value: function() {
444
- for (var e = this.axes.length, t = 0; t < e; t++) this.setAxisValue(t, this.resolveAxisValue(t));
445
- }
446
- },
447
- {
448
- key: "updateButtons",
449
- value: function() {
450
- for (var e = this.buttons.length, t = 0; t < e; t++) this.setButtonValue(t, this.resolveButtonValue(t));
451
- }
452
- },
453
- {
454
- key: "setAxisValue",
455
- value: function(e, t) {
456
- this.axes[e] !== t && (this.axes[e] = t, this.emit("axis", {
457
- gamepad: this.gamepad,
458
- index: this.index,
459
- axis: e,
460
- value: t
461
- }));
462
- }
463
- },
464
- {
465
- key: "setButtonValue",
466
- value: function(e, t) {
467
- this.buttons[e] !== t && (this.buttons[e] = t, this.emit("button", {
468
- gamepad: this.gamepad,
469
- index: this.index,
470
- button: e,
471
- pressed: this.gamepad.buttons[e].pressed,
472
- value: t
473
- }));
474
- }
475
- },
476
- {
477
- key: "resolveAxisValue",
185
+ key: "setValidators",
478
186
  value: function(e) {
479
- var t = this.options.axis, n = t.deadZone, r = t.analog, i = t.precision, a = this.gamepad.axes[e];
480
- return n && a < n && a > -n ? 0 : r ? i ? Math.round(a * i) / i : a : a > 0 ? 1 : a < 0 ? -1 : 0;
187
+ var t = this;
188
+ return Object.entries(e).forEach((function(e) {
189
+ var n = i(e, 2), r = n[0], a = n[1];
190
+ return t.validators.set(r, a);
191
+ })), this;
481
192
  }
482
193
  },
483
194
  {
484
- key: "resolveButtonValue",
195
+ key: "setTypes",
485
196
  value: function(e) {
486
- var t = this.options.button, n = t.deadZone, r = t.analog, i = t.precision, a = this.gamepad.buttons[e].value;
487
- return n > 0 && a < n && a > -n ? 0 : r ? i ? Math.round(a * i) / i : a : a === 0 ? 0 : 1;
488
- }
489
- }
490
- ]) && c(t.prototype, n), r && c(t, r), Object.defineProperty(t, "prototype", { writable: !1 }), f;
491
- }(t());
492
- function _(e) {
493
- return _ = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
494
- return typeof e;
495
- } : function(e) {
496
- return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
497
- }, _(e);
498
- }
499
- function v(e, t) {
500
- for (var n = 0; n < t.length; n++) {
501
- var r = t[n];
502
- r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, y(r.key), r);
503
- }
504
- }
505
- function y(e) {
506
- var t = function(e, t) {
507
- if (_(e) !== "object" || e === null) return e;
508
- var n = e[Symbol.toPrimitive];
509
- if (n !== void 0) {
510
- var r = n.call(e, "string");
511
- if (_(r) !== "object") return r;
512
- throw TypeError("@@toPrimitive must return a primitive value.");
513
- }
514
- return String(e);
515
- }(e);
516
- return _(t) === "symbol" ? t : String(t);
517
- }
518
- p = g, m = "optionResolver", h = new (a())().setDefaults({
519
- analog: !0,
520
- deadZone: 0,
521
- precision: 0
522
- }).setTypes({
523
- analog: "boolean",
524
- deadZone: "number",
525
- precision: "number"
526
- }).setValidators({
527
- deadZone: function(e) {
528
- return Math.max(Math.min(e, 1), 0);
529
- },
530
- precision: function(e) {
531
- return e > 0 ? 10 ** e : 0;
532
- }
533
- }), (m = f(m)) in p ? Object.defineProperty(p, m, {
534
- value: h,
535
- enumerable: !0,
536
- configurable: !0,
537
- writable: !0
538
- }) : p[m] = h;
539
- var b = function() {
540
- function e(t) {
541
- (function(e, t) {
542
- if (!(e instanceof t)) throw TypeError("Cannot call a class as a function");
543
- })(this, e), this.callback = t, this.frame = null, this.update = this.update.bind(this);
544
- }
545
- var t, n;
546
- return t = e, (n = [
547
- {
548
- key: "setCallback",
549
- value: function(e) {
550
- this.callback = e;
197
+ var t = this;
198
+ return Object.entries(e).forEach((function(e) {
199
+ var n = i(e, 2), r = n[0], a = n[1];
200
+ return t.types.set(r, a);
201
+ })), this;
551
202
  }
552
203
  },
553
204
  {
554
- key: "start",
555
- value: function() {
556
- this.frame ||= window.requestAnimationFrame(this.update);
557
- }
558
- },
559
- {
560
- key: "stop",
561
- value: function() {
562
- this.frame &&= (window.cancelAnimationFrame(this.frame), null);
205
+ key: "setOptional",
206
+ value: function(e) {
207
+ var t = this;
208
+ return e.forEach((function(e) {
209
+ return t.optional.add(e);
210
+ })), this;
563
211
  }
564
212
  },
565
213
  {
566
- key: "update",
567
- value: function() {
568
- this.frame = window.requestAnimationFrame(this.update), this.callback();
569
- }
570
- }
571
- ]) && v(t.prototype, n), Object.defineProperty(t, "prototype", { writable: !1 }), e;
572
- }();
573
- function x(e) {
574
- return x = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
575
- return typeof e;
576
- } : function(e) {
577
- return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
578
- }, x(e);
579
- }
580
- function S(e, t) {
581
- if (!(e instanceof t)) throw TypeError("Cannot call a class as a function");
582
- }
583
- function C(e, t) {
584
- for (var n = 0; n < t.length; n++) {
585
- var r = t[n];
586
- r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, w(r.key), r);
587
- }
588
- }
589
- function w(e) {
590
- var t = function(e, t) {
591
- if (x(e) !== "object" || e === null) return e;
592
- var n = e[Symbol.toPrimitive];
593
- if (n !== void 0) {
594
- var r = n.call(e, "string");
595
- if (x(r) !== "object") return r;
596
- throw TypeError("@@toPrimitive must return a primitive value.");
597
- }
598
- return String(e);
599
- }(e);
600
- return x(t) === "symbol" ? t : String(t);
601
- }
602
- function T(e, t) {
603
- return T = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(e, t) {
604
- return e.__proto__ = t, e;
605
- }, T(e, t);
606
- }
607
- function E(e, t) {
608
- if (t && (x(t) === "object" || typeof t == "function")) return t;
609
- if (t !== void 0) throw TypeError("Derived constructors may only return object or undefined");
610
- return D(e);
611
- }
612
- function D(e) {
613
- if (e === void 0) throw ReferenceError("this hasn't been initialised - super() hasn't been called");
614
- return e;
615
- }
616
- function O(e) {
617
- return O = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(e) {
618
- return e.__proto__ || Object.getPrototypeOf(e);
619
- }, O(e);
620
- }
621
- var k = function(e) {
622
- (function(e, t) {
623
- if (typeof t != "function" && t !== null) throw TypeError("Super expression must either be null or a function");
624
- e.prototype = Object.create(t && t.prototype, { constructor: {
625
- value: e,
626
- writable: !0,
627
- configurable: !0
628
- } }), Object.defineProperty(e, "prototype", { writable: !1 }), t && T(e, t);
629
- })(o, e);
630
- var t, n, r, i, a = (r = o, i = function() {
631
- if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1;
632
- if (typeof Proxy == "function") return !0;
633
- try {
634
- return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0;
635
- } catch {
636
- return !1;
637
- }
638
- }(), function() {
639
- var e, t = O(r);
640
- if (i) {
641
- var n = O(this).constructor;
642
- e = Reflect.construct(t, arguments, n);
643
- } else e = t.apply(this, arguments);
644
- return E(this, e);
645
- });
646
- function o() {
647
- var e, t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
648
- if (S(this, o), e = a.call(this), typeof navigator.getGamepads != "function") throw Error("This browser does not support gamepad API.");
649
- return e.options = t, e.onAxis = e.onAxis.bind(D(e)), e.update = e.update.bind(D(e)), e.start = e.start.bind(D(e)), e.stop = e.stop.bind(D(e)), e.discover = e.discover.bind(D(e)), e.onButton = e.onButton.bind(D(e)), e.handlers = [
650
- ,
651
- ,
652
- ,
653
- ,
654
- ].fill(null), e.loop = new b(e.update), window.addEventListener("error", e.stop), e;
655
- }
656
- return t = o, (n = [
657
- {
658
- key: "start",
659
- value: function() {
660
- this.loop.start();
214
+ key: "setRequired",
215
+ value: function(e) {
216
+ var t = this;
217
+ return e.forEach((function(e) {
218
+ return t.required.add(e);
219
+ })), this;
661
220
  }
662
221
  },
663
222
  {
664
- key: "stop",
665
- value: function() {
666
- this.loop.stop();
223
+ key: "resolve",
224
+ value: function(e) {
225
+ return this.validate(Object.assign(this.getDefaults(), e));
667
226
  }
668
227
  },
669
228
  {
670
- key: "update",
229
+ key: "getDefaults",
671
230
  value: function() {
672
- var e = navigator.getGamepads();
673
- this.discover(e[0], 0), this.discover(e[1], 1), this.discover(e[2], 2), this.discover(e[3], 3);
674
- }
675
- },
676
- {
677
- key: "discover",
678
- value: function(e, t) {
679
- e ? (this.handlers[t] === null && this.registerHandler(t, e), this.handlers[t].update(e)) : this.handlers[t] && this.removeGamepad(t);
680
- }
681
- },
682
- {
683
- key: "registerHandler",
684
- value: function(e, t) {
685
- var n = new g(e, t, this.options);
686
- this.handlers[e] = n, n.addEventListener("axis", this.onAxis), n.addEventListener("button", this.onButton), this.emit("gamepad:connected", {
687
- index: e,
688
- gamepad: t
689
- }), this.emit(`gamepad:${e}:connected`, {
690
- index: e,
691
- gamepad: t
692
- });
231
+ var e, t = {}, n = r(this.defaults);
232
+ try {
233
+ for (n.s(); !(e = n.n()).done;) {
234
+ var a = i(e.value, 2), o = a[0];
235
+ t[o] = a[1];
236
+ }
237
+ } catch (e) {
238
+ n.e(e);
239
+ } finally {
240
+ n.f();
241
+ }
242
+ return t;
693
243
  }
694
244
  },
695
245
  {
696
- key: "removeGamepad",
246
+ key: "validate",
697
247
  value: function(e) {
698
- var t = this.handlers[e];
699
- t.removeEventListener("axis", this.onAxis), t.removeEventListener("button", this.onButton), this.handlers[e] = null, this.emit("gamepad:disconnected", { index: e }), this.emit(`gamepad:${e}:disconnected`, { index: e });
248
+ for (var t in e) this.validators.has(t) && (e[t] = this.validators.get(t)(e[t]));
249
+ for (var n in e) {
250
+ if (!this.optionExists(n)) throw Error(`Unkown option "${n}".`);
251
+ this.checkType(n, e[n]);
252
+ }
253
+ var i, a = r(this.required.values());
254
+ try {
255
+ for (a.s(); !(i = a.n()).done;) {
256
+ var o = i.value;
257
+ if (e[o] === void 0) throw Error(`Option "${o}" is required.`);
258
+ }
259
+ } catch (e) {
260
+ a.e(e);
261
+ } finally {
262
+ a.f();
263
+ }
264
+ return e;
700
265
  }
701
266
  },
702
267
  {
703
- key: "onAxis",
704
- value: function(e) {
705
- var t = e.detail.index;
706
- this.emit("gamepad:axis", e.detail), this.emit(`gamepad:${t}:axis`, e.detail), this.emit(`gamepad:${t}:axis:${e.detail.axis}`, e.detail);
268
+ key: "checkType",
269
+ value: function(e, t) {
270
+ if (this.types.has(e)) {
271
+ var r = this.types.get(e), i = n(t);
272
+ if (i !== r) throw Error(`Wrong value for option "${e}": expected type "${r}", got "${i}".`);
273
+ }
707
274
  }
708
275
  },
709
276
  {
710
- key: "onButton",
277
+ key: "optionExists",
711
278
  value: function(e) {
712
- var t = e.detail.index;
713
- this.emit("gamepad:button", e.detail), this.emit(`gamepad:${t}:button`, e.detail), this.emit(`gamepad:${t}:button:${e.detail.button}`, e.detail);
279
+ return !this.strict || this.defaults.has(e) || this.validators.has(e) || this.optional.has(e) || this.required.has(e) || this.types.has(e);
714
280
  }
715
281
  }
716
- ]) && C(t.prototype, n), Object.defineProperty(t, "prototype", { writable: !1 }), o;
717
- }(t());
718
- })(), r;
719
- })()));
720
- }));
721
- export default require_gamepad();
282
+ ]) && c(t.prototype, a), Object.defineProperty(t, "prototype", { writable: !1 }), e;
283
+ })();
284
+ return t.default;
285
+ })()));
286
+ })(r)), r.exports;
287
+ }
288
+ var s = /* @__PURE__ */ n(o()), c = class extends t {
289
+ static optionResolver = new s().setDefaults({
290
+ analog: !0,
291
+ deadZone: 0,
292
+ precision: 0
293
+ }).setTypes({
294
+ analog: "boolean",
295
+ deadZone: "number",
296
+ precision: "number"
297
+ }).setValidators({
298
+ deadZone: (e) => Math.max(Math.min(e, 1), 0),
299
+ precision: (e) => e > 0 ? 10 ** e : 0
300
+ });
301
+ constructor(e, t, n = {}, r = null) {
302
+ super(), this.index = e, this.gamepad = t, this.mapping = r, this.options = this.constructor.resolveOptions(n), this.axes = Array(t.axes.length).fill(null), this.buttons = Array(t.buttons.length).fill(null), this.initAxes(), this.initButtons();
303
+ }
304
+ static resolveOptions(e) {
305
+ let { axis: t, button: n } = e;
306
+ return {
307
+ axis: this.optionResolver.resolve(t ?? n ?? e ?? {}),
308
+ button: this.optionResolver.resolve(n ?? t ?? e ?? {})
309
+ };
310
+ }
311
+ initAxes() {
312
+ let { length: e } = this.axes;
313
+ for (let t = 0; t < e; t++) this.axes[t] = this.resolveAxisValue(t);
314
+ }
315
+ initButtons() {
316
+ let { length: e } = this.buttons;
317
+ for (let t = 0; t < e; t++) this.buttons[t] = this.resolveButtonValue(t);
318
+ }
319
+ update(e) {
320
+ this.gamepad = e, this.updateAxis(), this.updateButtons();
321
+ }
322
+ updateAxis() {
323
+ let { length: e } = this.axes;
324
+ for (let t = 0; t < e; t++) this.setAxisValue(t, this.resolveAxisValue(t));
325
+ }
326
+ updateButtons() {
327
+ let { length: e } = this.buttons;
328
+ for (let t = 0; t < e; t++) this.setButtonValue(t, this.resolveButtonValue(t));
329
+ }
330
+ setAxisValue(e, t) {
331
+ this.axes[e] !== t && (this.axes[e] = t, this.emit("axis", {
332
+ gamepad: this.gamepad,
333
+ index: this.index,
334
+ axis: e,
335
+ label: this.mapping?.getAxis(e) || `Axis ${e}`,
336
+ value: t
337
+ }));
338
+ }
339
+ setButtonValue(e, t) {
340
+ this.buttons[e] !== t && (this.buttons[e] = t, this.emit("button", {
341
+ gamepad: this.gamepad,
342
+ index: this.index,
343
+ button: e,
344
+ pressed: this.gamepad.buttons[e].pressed,
345
+ label: this.mapping?.getButton(e) || `Button ${e}`,
346
+ value: t
347
+ }));
348
+ }
349
+ resolveAxisValue(e) {
350
+ let { deadZone: t, analog: n, precision: r } = this.options.axis, i = this.gamepad.axes[e];
351
+ return t && i < t && i > -t ? 0 : n ? r ? Math.round(i * r) / r : i : i > 0 ? 1 : i < 0 ? -1 : 0;
352
+ }
353
+ resolveButtonValue(e) {
354
+ let { deadZone: t, analog: n, precision: r } = this.options.button, { value: i } = this.gamepad.buttons[e];
355
+ return t > 0 && i < t && i > -t ? 0 : n ? r ? Math.round(i * r) / r : i : i === 0 ? 0 : 1;
356
+ }
357
+ }, l = class {
358
+ constructor(e, t) {
359
+ this.type = e, this.detail = t;
360
+ }
361
+ }, u = class {
362
+ #e = /* @__PURE__ */ new Map();
363
+ constructor() {
364
+ this.addEventListener = this.addEventListener.bind(this), this.removeEventListener = this.removeEventListener.bind(this), this.on = this.addEventListener, this.off = this.removeEventListener;
365
+ }
366
+ emit(e, t) {
367
+ if (!this.#e.has(e)) return;
368
+ let n = this.#e.get(e), r = new l(e, t), { length: i } = n;
369
+ for (let e = 0; e < i; e++) n[e](r);
370
+ }
371
+ addEventListener(e, t) {
372
+ let n = this.#t(e);
373
+ n.indexOf(t) < 0 && n.push(t);
374
+ }
375
+ removeEventListener(e, t) {
376
+ if (!this.#e.has(e)) return;
377
+ let n = this.#e.get(e), r = n.indexOf(t);
378
+ r >= 0 && n.splice(r, 1), n.length === 0 && this.#e.delete(e);
379
+ }
380
+ countEventListeners() {
381
+ return this.#e.size;
382
+ }
383
+ removeAllEventListeners() {
384
+ this.#e.clear();
385
+ }
386
+ #t(e) {
387
+ if (this.#e.has(e)) return this.#e.get(e);
388
+ let t = [];
389
+ return this.#e.set(e, t), t;
390
+ }
391
+ }, d = class {
392
+ constructor(e) {
393
+ this.callback = e, this.frame = null, this.update = this.update.bind(this);
394
+ }
395
+ setCallback(e) {
396
+ this.callback = e;
397
+ }
398
+ start() {
399
+ this.frame ||= window.requestAnimationFrame(this.update);
400
+ }
401
+ stop() {
402
+ this.frame &&= (window.cancelAnimationFrame(this.frame), null);
403
+ }
404
+ update() {
405
+ this.frame = window.requestAnimationFrame(this.update), this.callback();
406
+ }
407
+ }, f = class extends u {
408
+ constructor(e = {}, t = []) {
409
+ if (super(), typeof navigator.getGamepads != "function") throw Error("This browser does not support gamepad API.");
410
+ this.options = e, this.mappings = t, this.onAxis = this.onAxis.bind(this), this.update = this.update.bind(this), this.start = this.start.bind(this), this.stop = this.stop.bind(this), this.discover = this.discover.bind(this), this.onButton = this.onButton.bind(this), this.handlers = [
411
+ ,
412
+ ,
413
+ ,
414
+ ,
415
+ ].fill(null), this.loop = new d(this.update), window.addEventListener("error", this.stop);
416
+ }
417
+ start() {
418
+ this.loop.start();
419
+ }
420
+ stop() {
421
+ this.loop.stop();
422
+ }
423
+ update() {
424
+ let e = navigator.getGamepads();
425
+ this.discover(e[0], 0), this.discover(e[1], 1), this.discover(e[2], 2), this.discover(e[3], 3);
426
+ }
427
+ discover(e, t) {
428
+ e ? (this.handlers[t] === null && this.registerHandler(t, e), this.handlers[t].update(e)) : this.handlers[t] && this.removeGamepad(t);
429
+ }
430
+ registerHandler(e, t) {
431
+ let n = this.getMapping(t), r = new c(e, t, this.options, n);
432
+ this.handlers[e] = r, r.addEventListener("axis", this.onAxis), r.addEventListener("button", this.onButton);
433
+ let i = {
434
+ index: e,
435
+ gamepad: t,
436
+ mapping: n?.name || null
437
+ };
438
+ this.emit("gamepad:connected", i), this.emit(`gamepad:${e}:connected`, i);
439
+ }
440
+ getMapping(e) {
441
+ return this.mappings.find((t) => t?.match(e)) || null;
442
+ }
443
+ removeGamepad(e) {
444
+ let t = this.handlers[e];
445
+ t.removeEventListener("axis", this.onAxis), t.removeEventListener("button", this.onButton), this.handlers[e] = null, this.emit("gamepad:disconnected", { index: e }), this.emit(`gamepad:${e}:disconnected`, { index: e });
446
+ }
447
+ onAxis(e) {
448
+ let { index: t } = e.detail;
449
+ this.emit("gamepad:axis", e.detail), this.emit(`gamepad:${t}:axis`, e.detail), this.emit(`gamepad:${t}:axis:${e.detail.axis}`, e.detail);
450
+ }
451
+ onButton(e) {
452
+ let { index: t } = e.detail;
453
+ this.emit("gamepad:button", e.detail), this.emit(`gamepad:${t}:button`, e.detail), this.emit(`gamepad:${t}:button:${e.detail.button}`, e.detail);
454
+ }
455
+ };
456
+ //#endregion
457
+ export { f as GamepadListener };
722
458
 
723
459
  //# sourceMappingURL=gamepad.js.map