promogame-player 1.0.2 → 1.0.3

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.
@@ -1,683 +1,463 @@
1
- import { jsxs as P, Fragment as ce, jsx as $ } from "react/jsx-runtime";
2
- import * as de from "react";
3
- import g, { useRef as B, useImperativeHandle as ve, useEffect as F } from "react";
4
- import { cn as fe } from "../../utils.js";
5
- var j = {}, L = {}, S = {}, G;
6
- function ye() {
7
- if (G) return S;
8
- G = 1, Object.defineProperty(S, "__esModule", { value: !0 }), S.useUnityCanvasId = void 0;
9
- var l = g, c = 0, i = "react-unity-webgl-canvas", y = function(f) {
10
- if (f.id !== void 0)
11
- return f.id;
12
- var b = (0, l.useMemo)(function() {
13
- return [i, ++c].join("-");
1
+ import { jsxs as O, Fragment as Y, jsx as $ } from "react/jsx-runtime";
2
+ import * as Z from "react";
3
+ import k, { useRef as G, useImperativeHandle as p, useEffect as D } from "react";
4
+ import { cn as ee } from "../../utils.js";
5
+ var B = {}, E = {}, x = {}, F;
6
+ function te() {
7
+ if (F) return x;
8
+ F = 1, Object.defineProperty(x, "__esModule", { value: !0 }), x.useCanvasIdentifier = void 0;
9
+ var s = k, l = 0, v = "react-unity-webgl-canvas", o = function(y) {
10
+ var a = (0, s.useState)(0), e = a[0], n = a[1], r = (0, s.useCallback)(function() {
11
+ n(function(d) {
12
+ return d + 1;
13
+ });
14
14
  }, []);
15
- return b;
15
+ if (y !== void 0)
16
+ return [y, r];
17
+ var u = (0, s.useMemo)(function() {
18
+ return [v, l].join("-");
19
+ }, [e]);
20
+ return [u, r];
16
21
  };
17
- return S.useUnityCanvasId = y, S;
22
+ return x.useCanvasIdentifier = o, x;
18
23
  }
19
- var w = {}, p = {}, T;
20
- function ee() {
21
- if (T) return p;
22
- T = 1, Object.defineProperty(p, "__esModule", { value: !0 }), p.UnityLoaderStatus = void 0;
23
- var l;
24
- return function(c) {
25
- c.Idle = "Idle", c.Loading = "Loading", c.Loaded = "Loaded", c.Error = "Error";
26
- }(l || (p.UnityLoaderStatus = l = {})), p;
24
+ var M = {}, q = {}, z;
25
+ function X() {
26
+ return z || (z = 1, Object.defineProperty(q, "__esModule", { value: !0 }), q.isBrowserEnvironment = void 0, q.isBrowserEnvironment = typeof window < "u" && typeof document < "u"), q;
27
27
  }
28
- var q = {}, D;
29
- function A() {
30
- return D || (D = 1, Object.defineProperty(q, "__esModule", { value: !0 }), q.isBrowserEnvironment = void 0, q.isBrowserEnvironment = typeof window < "u" && typeof document < "u"), q;
28
+ var V;
29
+ function re() {
30
+ if (V) return M;
31
+ V = 1, Object.defineProperty(M, "__esModule", { value: !0 }), M.useUnityLoader = void 0;
32
+ var s = k, l = X(), v = function(o) {
33
+ var y = (0, s.useState)("Loading"), a = y[0], e = y[1];
34
+ return (0, s.useEffect)(function() {
35
+ if (l.isBrowserEnvironment !== !1) {
36
+ if (o === null) {
37
+ e("Idle");
38
+ return;
39
+ }
40
+ var n = window.document.querySelector('script[src="'.concat(o, '"]'));
41
+ n === null ? (n = window.document.createElement("script"), n.type = "text/javascript", n.src = o, n.async = !0, n.setAttribute("data-status", "loading"), window.document.body.appendChild(n), n.addEventListener("load", function() {
42
+ return n == null ? void 0 : n.setAttribute("data-status", "loaded");
43
+ }), n.addEventListener("error", function() {
44
+ return n == null ? void 0 : n.setAttribute("data-status", "error");
45
+ })) : e(n.getAttribute("data-status") === "loaded" ? "Loaded" : "Error");
46
+ var r = function(u) {
47
+ return e(u.type === "load" ? "Loaded" : "Error");
48
+ };
49
+ return n.addEventListener("load", r), n.addEventListener("error", r), function() {
50
+ n !== null && (n.removeEventListener("load", r), n.removeEventListener("error", r), n.remove());
51
+ };
52
+ }
53
+ }, [o]), a;
54
+ };
55
+ return M.useUnityLoader = v, M;
31
56
  }
32
- var z;
33
- function Ue() {
34
- if (z) return w;
35
- z = 1;
36
- var l = w && w.__awaiter || function(m, o, n, e) {
37
- function s(r) {
38
- return r instanceof n ? r : new n(function(t) {
39
- t(r);
57
+ var W;
58
+ function ne() {
59
+ if (W) return E;
60
+ W = 1;
61
+ var s = E && E.__awaiter || function(e, n, r, u) {
62
+ function d(t) {
63
+ return t instanceof r ? t : new r(function(c) {
64
+ c(t);
40
65
  });
41
66
  }
42
- return new (n || (n = Promise))(function(r, t) {
43
- function d(a) {
67
+ return new (r || (r = Promise))(function(t, c) {
68
+ function m(U) {
44
69
  try {
45
- u(e.next(a));
46
- } catch (v) {
47
- t(v);
70
+ i(u.next(U));
71
+ } catch (_) {
72
+ c(_);
48
73
  }
49
74
  }
50
- function U(a) {
75
+ function w(U) {
51
76
  try {
52
- u(e.throw(a));
53
- } catch (v) {
54
- t(v);
77
+ i(u.throw(U));
78
+ } catch (_) {
79
+ c(_);
55
80
  }
56
81
  }
57
- function u(a) {
58
- a.done ? r(a.value) : s(a.value).then(d, U);
82
+ function i(U) {
83
+ U.done ? t(U.value) : d(U.value).then(m, w);
59
84
  }
60
- u((e = e.apply(m, o || [])).next());
85
+ i((u = u.apply(e, n || [])).next());
61
86
  });
62
- }, c = w && w.__generator || function(m, o) {
63
- var n = { label: 0, sent: function() {
64
- if (r[0] & 1) throw r[1];
65
- return r[1];
66
- }, trys: [], ops: [] }, e, s, r, t = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
67
- return t.next = d(0), t.throw = d(1), t.return = d(2), typeof Symbol == "function" && (t[Symbol.iterator] = function() {
87
+ }, l = E && E.__generator || function(e, n) {
88
+ var r = { label: 0, sent: function() {
89
+ if (t[0] & 1) throw t[1];
90
+ return t[1];
91
+ }, trys: [], ops: [] }, u, d, t, c = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
92
+ return c.next = m(0), c.throw = m(1), c.return = m(2), typeof Symbol == "function" && (c[Symbol.iterator] = function() {
68
93
  return this;
69
- }), t;
70
- function d(u) {
71
- return function(a) {
72
- return U([u, a]);
94
+ }), c;
95
+ function m(i) {
96
+ return function(U) {
97
+ return w([i, U]);
73
98
  };
74
99
  }
75
- function U(u) {
76
- if (e) throw new TypeError("Generator is already executing.");
77
- for (; t && (t = 0, u[0] && (n = 0)), n; ) try {
78
- if (e = 1, s && (r = u[0] & 2 ? s.return : u[0] ? s.throw || ((r = s.return) && r.call(s), 0) : s.next) && !(r = r.call(s, u[1])).done) return r;
79
- switch (s = 0, r && (u = [u[0] & 2, r.value]), u[0]) {
100
+ function w(i) {
101
+ if (u) throw new TypeError("Generator is already executing.");
102
+ for (; c && (c = 0, i[0] && (r = 0)), r; ) try {
103
+ if (u = 1, d && (t = i[0] & 2 ? d.return : i[0] ? d.throw || ((t = d.return) && t.call(d), 0) : d.next) && !(t = t.call(d, i[1])).done) return t;
104
+ switch (d = 0, t && (i = [i[0] & 2, t.value]), i[0]) {
80
105
  case 0:
81
106
  case 1:
82
- r = u;
107
+ t = i;
83
108
  break;
84
109
  case 4:
85
- return n.label++, { value: u[1], done: !1 };
110
+ return r.label++, { value: i[1], done: !1 };
86
111
  case 5:
87
- n.label++, s = u[1], u = [0];
112
+ r.label++, d = i[1], i = [0];
88
113
  continue;
89
114
  case 7:
90
- u = n.ops.pop(), n.trys.pop();
115
+ i = r.ops.pop(), r.trys.pop();
91
116
  continue;
92
117
  default:
93
- if (r = n.trys, !(r = r.length > 0 && r[r.length - 1]) && (u[0] === 6 || u[0] === 2)) {
94
- n = 0;
118
+ if (t = r.trys, !(t = t.length > 0 && t[t.length - 1]) && (i[0] === 6 || i[0] === 2)) {
119
+ r = 0;
95
120
  continue;
96
121
  }
97
- if (u[0] === 3 && (!r || u[1] > r[0] && u[1] < r[3])) {
98
- n.label = u[1];
122
+ if (i[0] === 3 && (!t || i[1] > t[0] && i[1] < t[3])) {
123
+ r.label = i[1];
99
124
  break;
100
125
  }
101
- if (u[0] === 6 && n.label < r[1]) {
102
- n.label = r[1], r = u;
126
+ if (i[0] === 6 && r.label < t[1]) {
127
+ r.label = t[1], t = i;
103
128
  break;
104
129
  }
105
- if (r && n.label < r[2]) {
106
- n.label = r[2], n.ops.push(u);
130
+ if (t && r.label < t[2]) {
131
+ r.label = t[2], r.ops.push(i);
107
132
  break;
108
133
  }
109
- r[2] && n.ops.pop(), n.trys.pop();
134
+ t[2] && r.ops.pop(), r.trys.pop();
110
135
  continue;
111
136
  }
112
- u = o.call(m, n);
113
- } catch (a) {
114
- u = [6, a], s = 0;
137
+ i = n.call(e, r);
138
+ } catch (U) {
139
+ i = [6, U], d = 0;
115
140
  } finally {
116
- e = r = 0;
141
+ u = t = 0;
117
142
  }
118
- if (u[0] & 5) throw u[1];
119
- return { value: u[0] ? u[1] : void 0, done: !0 };
143
+ if (i[0] & 5) throw i[1];
144
+ return { value: i[0] ? i[1] : void 0, done: !0 };
120
145
  }
121
146
  };
122
- Object.defineProperty(w, "__esModule", { value: !0 }), w.useUnityInstance = void 0;
123
- var i = g, y = ee(), f = A(), b = function(m, o, n, e) {
124
- (0, i.useEffect)(function() {
125
- (function() {
126
- return l(void 0, void 0, void 0, function() {
127
- var s, r;
128
- return c(this, function(t) {
129
- switch (t.label) {
130
- case 0:
131
- if (f.isBrowserEnvironment === !1)
147
+ Object.defineProperty(E, "__esModule", { value: !0 }), E.Unity = void 0;
148
+ var v = k, o = te(), y = re(), a = (0, v.forwardRef)(
149
+ /**
150
+ * @param unityProps The Unity props provided the the Unity component.
151
+ * @param forwardedRef The forwarded ref to the Unity component.
152
+ * @returns The Unity canvas renderer.
153
+ */
154
+ function(e, n) {
155
+ var r = (0, v.useState)(null), u = r[0], d = r[1], t = (0, v.useState)(null), c = t[0], m = t[1], w = (0, o.useCanvasIdentifier)(e.id), i = w[0], U = w[1], _ = (0, y.useUnityLoader)(e.unityProvider.loaderUrl), h = (0, v.useCallback)(function(L) {
156
+ e.unityProvider.setLoadingProgression(L), L === 1 && e.unityProvider.setIsLoaded(!0);
157
+ }, [e.unityProvider]);
158
+ return (0, v.useEffect)(function() {
159
+ var L = function() {
160
+ return s(void 0, void 0, void 0, function() {
161
+ var b, g, I, f, C;
162
+ return l(this, function(P) {
163
+ switch (P.label) {
164
+ case 0:
165
+ if (!u || c || _ !== "Loaded")
166
+ return [
167
+ 2
168
+ /*return*/
169
+ ];
170
+ console.log("React Unity WebGL: Initializing Unity instance..."), e.unityProvider.setUnityInstance(null), m(null), e.unityProvider.setLoadingProgression(0), (C = (f = e.unityProvider).setIsLoaded) === null || C === void 0 || C.call(f, !1), e.unityProvider.setInitialisationError(void 0), U(), b = {
171
+ companyName: e.unityProvider.companyName,
172
+ productName: e.unityProvider.productName,
173
+ productVersion: e.unityProvider.productVersion,
174
+ dataUrl: e.unityProvider.dataUrl,
175
+ frameworkUrl: e.unityProvider.frameworkUrl,
176
+ codeUrl: e.unityProvider.codeUrl,
177
+ workerUrl: e.unityProvider.workerUrl,
178
+ memoryUrl: e.unityProvider.memoryUrl,
179
+ symbolsUrl: e.unityProvider.symbolsUrl,
180
+ streamingAssetsUrl: e.unityProvider.streamingAssetsUrl,
181
+ devicePixelRatio: e.devicePixelRatio,
182
+ webglContextAttributes: e.unityProvider.webglContextAttributes,
183
+ cacheControl: e.unityProvider.cacheControl,
184
+ autoSyncPersistentDataPath: e.unityProvider.autoSyncPersistentDataPath,
185
+ matchWebGLToCanvasSize: e.matchWebGLToCanvasSize,
186
+ disabledCanvasEvents: e.disabledCanvasEvents
187
+ }, Object.keys(b).forEach(function(N) {
188
+ (b[N] === null || b[N] === void 0) && delete b[N];
189
+ }), P.label = 1;
190
+ case 1:
191
+ return P.trys.push([1, 3, , 4]), [4, window.createUnityInstance(u, b, h)];
192
+ case 2:
193
+ return g = P.sent(), m(g), e.unityProvider.setUnityInstance(g), [3, 4];
194
+ case 3:
195
+ return I = P.sent(), console.error("React Unity WebGL: Error initializing Unity instance:", I), e.unityProvider.setInitialisationError(I), [3, 4];
196
+ case 4:
132
197
  return [
133
198
  2
134
199
  /*return*/
135
200
  ];
136
- if (m !== y.UnityLoaderStatus.Loaded || o === null)
137
- return e.setUnityInstance(null), e.setInitialisationError(null), [
201
+ }
202
+ });
203
+ });
204
+ }, A = function() {
205
+ return s(void 0, void 0, void 0, function() {
206
+ var b, g, I;
207
+ return l(this, function(f) {
208
+ switch (f.label) {
209
+ case 0:
210
+ return !c || !u ? [
211
+ 2
212
+ /*return*/
213
+ ] : (console.log("React Unity WebGL: Detaching Unity instance..."), e.unityProvider.setUnityInstance(null), m(null), e.unityProvider.setLoadingProgression(0), (I = (g = e.unityProvider).setIsLoaded) === null || I === void 0 || I.call(g, !1), e.unityProvider.setInitialisationError(void 0), b = document.createElement("canvas"), b.id = u.id, b.setAttribute("react-unity-webgl-role", "cleanup"), b.style.display = "none", document.body.appendChild(b), c.Module.canvas = b, m(null), [4, c.Quit()]);
214
+ case 1:
215
+ return f.sent(), document.body.removeChild(b), [
138
216
  2
139
217
  /*return*/
140
218
  ];
141
- t.label = 1;
142
- case 1:
143
- return t.trys.push([1, 3, , 4]), [4, window.createUnityInstance(o, n, e.setLoadingProgression)];
144
- case 2:
145
- return s = t.sent(), e.setUnityInstance(s), e.setInitialisationError(null), [3, 4];
146
- case 3:
147
- return r = t.sent(), e.setUnityInstance(null), e.setInitialisationError(r), [3, 4];
148
- case 4:
149
- return [
150
- 2
151
- /*return*/
152
- ];
153
- }
219
+ }
220
+ });
154
221
  });
155
- });
156
- })();
157
- }, [m, o, n, e]);
158
- };
159
- return w.useUnityInstance = b, w;
160
- }
161
- var M = {}, V;
162
- function me() {
163
- if (V) return M;
164
- V = 1, Object.defineProperty(M, "__esModule", { value: !0 }), M.useUnityArguments = void 0;
165
- var l = g, c = function(i) {
166
- return (0, l.useMemo)(function() {
167
- return {
168
- // Assigns the data URL, framework URL, and code URL to the Unity
169
- // arguments object.
170
- dataUrl: i.unityProvider.unityConfig.dataUrl,
171
- frameworkUrl: i.unityProvider.unityConfig.frameworkUrl,
172
- codeUrl: i.unityProvider.unityConfig.codeUrl,
173
- // Assigns the optional streaming assets URL, memory URL, symbols URL,
174
- // and worker URL to the Unity arguments object.
175
- streamingAssetsUrl: i.unityProvider.unityConfig.streamingAssetsUrl,
176
- memoryUrl: i.unityProvider.unityConfig.memoryUrl,
177
- symbolsUrl: i.unityProvider.unityConfig.symbolsUrl,
178
- workerUrl: i.unityProvider.unityConfig.workerUrl,
179
- // Assigns the optional company name, product name, and product version to
180
- // the Unity arguments object.
181
- companyName: i.unityProvider.unityConfig.companyName,
182
- productName: i.unityProvider.unityConfig.productName,
183
- productVersion: i.unityProvider.unityConfig.productVersion,
184
- // Assigns the webgl context attributes to the Unity arguments object.
185
- // If the webgl context attributes are not defined via the Unity Props,
186
- // the default value of an empty object will be used.
187
- webglContextAttributes: i.unityProvider.unityConfig.webglContextAttributes || {},
188
- // Assigns the cache control value to the Unity arguments object. If the
189
- // cache control value is not defined via the Unity Props, the default
190
- // value of always `must-revalidate` will be used.
191
- cacheControl: i.unityProvider.unityConfig.cacheControl || function() {
192
- return "must-revalidate";
193
- },
194
- // Assigns the device pixel ratio to the Unity arguments object. If the
195
- // device pixel ratio is not defined via the Unity Props, the default
196
- // value of `1` will be used.
197
- devicePixelRatio: i.devicePixelRatio || 1,
198
- // Assigns the auto sync persistent data path value to the Unity arguments
199
- // object. If the auto sync persistent data path value is not defined via
200
- // the Unity Props, the default value of `undefined` will be used.
201
- autoSyncPersistentDataPath: i.autoSyncPersistentDataPath,
202
- // Assigns the match WebGL to canvas size value to the Unity arguments
203
- // object. If the match WebGL to canvas size value is not defined via the
204
- // Unity Props, the default value of `true` will be used.
205
- matchWebGLToCanvasSize: typeof i.matchWebGLToCanvasSize == "boolean" ? i.matchWebGLToCanvasSize : !0,
206
- // Assigns the disabled canvas events to the Unity arguments object. If
207
- // the disabled canvas events are not defined via the Unity Props, the
208
- // default value of `contextmenu` and `dragstart` will be used.
209
- disabledCanvasEvents: i.disabledCanvasEvents || [
210
- "contextmenu",
211
- "dragstart"
212
- ],
213
- // Assigns the print hook to the Unity arguments object. This hook will
214
- // be called whenever the Unity instance prints a message.
215
- print: (
216
- /**
217
- * Intercept print events in order to catch messages and send them to
218
- * the unity context instead.
219
- * @param message The message to be printed.
220
- */
221
- function(y) {
222
- }
223
- ),
224
- // Assigns the print error hook to the Unity arguments object. This hook
225
- // will be called whenever the Unity instance prints an error.
226
- printErr: (
227
- /**
228
- * Intercept print error events in order to catch messages and send them
229
- * to the unity context instead.
230
- * @param error The error to be printed.
231
- */
232
- function(y) {
233
- }
234
- )
235
- };
236
- }, []);
237
- };
238
- return M.useUnityArguments = c, M;
239
- }
240
- var x = {}, W;
241
- function be() {
242
- if (W) return x;
243
- W = 1, Object.defineProperty(x, "__esModule", { value: !0 }), x.useUnityLoader = void 0;
244
- var l = g, c = A(), i = ee(), y = function(f) {
245
- var b = (0, l.useState)(i.UnityLoaderStatus.Loading), m = b[0], o = b[1];
246
- return (0, l.useEffect)(function() {
247
- if (c.isBrowserEnvironment !== !1) {
248
- if (f.loaderUrl === null) {
249
- o(i.UnityLoaderStatus.Idle);
250
- return;
251
- }
252
- var n = window.document.querySelector('script[src="'.concat(f.loaderUrl, '"]'));
253
- n === null ? (n = window.document.createElement("script"), n.type = "text/javascript", n.src = f.loaderUrl, n.async = !0, n.setAttribute("data-status", "loading"), window.document.body.appendChild(n), n.addEventListener("load", function() {
254
- return n == null ? void 0 : n.setAttribute("data-status", "loaded");
255
- }), n.addEventListener("error", function() {
256
- return n == null ? void 0 : n.setAttribute("data-status", "error");
257
- })) : o(n.getAttribute("data-status") === "loaded" ? i.UnityLoaderStatus.Loaded : i.UnityLoaderStatus.Error);
258
- var e = function(s) {
259
- return o(s.type === "load" ? i.UnityLoaderStatus.Loaded : i.UnityLoaderStatus.Error);
260
222
  };
261
- return n.addEventListener("load", e), n.addEventListener("error", e), function() {
262
- n !== null && (n.removeEventListener("load", e), n.removeEventListener("error", e), window.document.body.removeChild(n));
223
+ return L(), function() {
224
+ A();
263
225
  };
264
- }
265
- }, [f.loaderUrl]), m;
266
- };
267
- return x.useUnityLoader = y, x;
268
- }
269
- var H;
270
- function _e() {
271
- if (H) return L;
272
- H = 1, Object.defineProperty(L, "__esModule", { value: !0 }), L.Unity = void 0;
273
- var l = g, c = g, i = ye(), y = Ue(), f = me(), b = be(), m = (0, c.forwardRef)(
274
- /**
275
- * @param unityProps The Unity props provided the the Unity component.
276
- * @param forwardedRef The forwarded ref to the Unity component.
277
- * @returns The Unity canvas renderer.
278
- */
279
- function(o, n) {
280
- var e = (0, c.useRef)(null), s = (0, i.useUnityCanvasId)(o), r = (0, f.useUnityArguments)(o), t = (0, b.useUnityLoader)(o.unityProvider.unityConfig);
281
- return (0, y.useUnityInstance)(t, e.current, r, o.unityProvider), (0, l.useImperativeHandle)(n, function() {
282
- return e.current;
283
- }), (0, l.createElement)("canvas", {
284
- ref: e,
285
- id: s,
286
- style: o.style,
287
- className: o.className,
288
- tabIndex: o.tabIndex
226
+ }, [u, c, _, e.unityProvider]), (0, v.useImperativeHandle)(n, function() {
227
+ return u;
228
+ }), (0, v.createElement)("canvas", {
229
+ ref: d,
230
+ id: i,
231
+ style: e.style,
232
+ className: e.className,
233
+ tabIndex: e.tabIndex
289
234
  });
290
235
  }
291
236
  );
292
- return L.Unity = m, L;
237
+ return E.Unity = a, E;
293
238
  }
294
- var h = {}, k = {}, Q;
295
- function te() {
296
- if (Q) return k;
297
- Q = 1, Object.defineProperty(k, "__esModule", { value: !0 }), k.errorMessages = void 0;
298
- var l = {
299
- /**
300
- * A generic error message when the Unity Instance is not available.
301
- */
302
- genericNoUnityInstance: "No Unity Instance found.",
303
- /**
304
- * The error message for when no Unity Instance was found while trying to set
305
- * the fullscreen mode.
306
- */
307
- requestFullscreenNoUnityInstance: "Unable to Set Fullscreen while Unity is not Instantiated.",
308
- /**
309
- * The error message for when no Unity Instance was found while trying to
310
- * request the pointer lock.
311
- */
312
- requestPointerLockNoUnityInstanceOrCanvas: "Unable to Request Pointer Lock while Unity is not Instantiated or the Canvas is not found.",
313
- /**
314
- * The error message for when no Unity Instance was found while trying to send
315
- * a message.
316
- */
317
- sendMessageNoUnityInstance: "Unable to Send Message while Unity is not Instantiated.",
318
- /**
319
- * The error message for when no Unity Instance was found while trying to quit
320
- * the Unity Instance.
321
- */
322
- quitNoUnityInstance: "Unable to Quit Unity while Unity is not Instantiated.",
323
- /**
324
- * The error message for when no Unity Instance or Canvas was found while
325
- * trying to take a screenshot.
326
- */
327
- screenshotNoUnityInstanceOrCanvas: "Unable to Take Screenshot while Unity is not Instantiated or Canvas is not available.",
328
- /**
329
- * The error message for when no event listener was found in the event
330
- * system.
331
- */
332
- noEventListener: "Unable to find Event Listener in Event System for Event"
333
- };
334
- return k.errorMessages = l, k;
335
- }
336
- var E = {}, J;
337
- function we() {
338
- if (J) return E;
339
- J = 1;
340
- var l = E && E.__spreadArray || function(o, n, e) {
341
- if (e || arguments.length === 2) for (var s = 0, r = n.length, t; s < r; s++)
342
- (t || !(s in n)) && (t || (t = Array.prototype.slice.call(n, 0, s)), t[s] = n[s]);
343
- return o.concat(t || Array.prototype.slice.call(n));
239
+ var R = {}, S = {}, T;
240
+ function ie() {
241
+ if (T) return S;
242
+ T = 1;
243
+ var s = S && S.__spreadArray || function(e, n, r) {
244
+ if (r || arguments.length === 2) for (var u = 0, d = n.length, t; u < d; u++)
245
+ (t || !(u in n)) && (t || (t = Array.prototype.slice.call(n, 0, u)), t[u] = n[u]);
246
+ return e.concat(t || Array.prototype.slice.call(n));
344
247
  };
345
- Object.defineProperty(E, "__esModule", { value: !0 }), E.useEventSystem = void 0;
346
- var c = g, i = te(), y = A(), f = [], b = function(o) {
347
- for (var n = [], e = 1; e < arguments.length; e++)
348
- n[e - 1] = arguments[e];
349
- var s = void 0;
350
- return f.forEach(function(r) {
351
- s = r.apply(void 0, l([o], n, !1));
352
- }), s;
248
+ Object.defineProperty(S, "__esModule", { value: !0 }), S.useEventSystem = void 0;
249
+ var l = k, v = X(), o = [], y = function(e) {
250
+ for (var n = [], r = 1; r < arguments.length; r++)
251
+ n[r - 1] = arguments[r];
252
+ var u = void 0;
253
+ return o.forEach(function(d) {
254
+ u = d.apply(void 0, s([e], n, !1));
255
+ }), u;
353
256
  };
354
- y.isBrowserEnvironment === !0 && (window.dispatchReactUnityEvent = b);
355
- var m = function() {
356
- var o = (0, c.useRef)([]), n = (0, c.useCallback)(
257
+ v.isBrowserEnvironment === !0 && (window.dispatchReactUnityEvent = y);
258
+ var a = function() {
259
+ var e = (0, l.useRef)([]), n = (0, l.useCallback)(
357
260
  /**
358
261
  * @param eventName The name of the event to listen to.
359
262
  * @param callback The callback to invoke when the event is fired.
360
263
  */
361
- function(r, t) {
362
- o.current = l(l([], o.current, !0), [
363
- { eventName: r, callback: t }
264
+ function(d, t) {
265
+ e.current = s(s([], e.current, !0), [
266
+ { eventName: d, callback: t }
364
267
  ], !1);
365
268
  },
366
- [o]
367
- ), e = (0, c.useCallback)(
269
+ [e]
270
+ ), r = (0, l.useCallback)(
368
271
  /**
369
272
  * @param eventName The name of the event to remove.
370
273
  * @param callback The callback to remove.
371
274
  */
372
- function(r, t) {
373
- o.current = o.current.filter(function(d) {
374
- return d.eventName !== r && d.callback !== t;
275
+ function(d, t) {
276
+ e.current = e.current.filter(function(c) {
277
+ return c.eventName !== d && c.callback !== t;
375
278
  });
376
279
  },
377
- [o]
378
- ), s = (0, c.useCallback)(
280
+ [e]
281
+ ), u = (0, l.useCallback)(
379
282
  /**
380
283
  * @param eventName The name of the event to dispatch.
381
284
  * @param parameters The parameters to pass to the event listener.
382
285
  */
383
- function(r) {
384
- for (var t = [], d = 1; d < arguments.length; d++)
385
- t[d - 1] = arguments[d];
386
- var U = o.current.find(function(u) {
387
- return u.eventName === r;
286
+ function(d) {
287
+ for (var t = [], c = 1; c < arguments.length; c++)
288
+ t[c - 1] = arguments[c];
289
+ var m = e.current.find(function(w) {
290
+ return w.eventName === d;
388
291
  });
389
- if (typeof U > "u") {
390
- console.warn(i.errorMessages.noEventListener, { eventName: r });
391
- return;
392
- }
393
- return U.callback.apply(U, t);
292
+ if (!(typeof m > "u"))
293
+ return m.callback.apply(m, t);
394
294
  },
395
- [o]
295
+ [e]
396
296
  );
397
- return (0, c.useEffect)(function() {
398
- return f.push(s), function() {
399
- f.splice(f.indexOf(s), 1);
297
+ return (0, l.useEffect)(function() {
298
+ return o.push(u), function() {
299
+ o.splice(o.indexOf(u), 1);
400
300
  };
401
- }, [s]), {
301
+ }, [u]), {
402
302
  addEventListener: n,
403
- removeEventListener: e
303
+ removeEventListener: r
404
304
  };
405
305
  };
406
- return E.useEventSystem = m, E;
306
+ return S.useEventSystem = a, S;
407
307
  }
408
- var N = {}, K;
409
- function he() {
410
- if (K) return N;
411
- K = 1, Object.defineProperty(N, "__esModule", { value: !0 }), N.useNullableState = void 0;
412
- var l = g, c = function(i) {
413
- return (0, l.useState)(i || null);
308
+ var H;
309
+ function ae() {
310
+ if (H) return R;
311
+ H = 1, Object.defineProperty(R, "__esModule", { value: !0 }), R.useUnityContext = void 0;
312
+ var s = k, l = ie(), v = function(o) {
313
+ var y = (0, s.useState)(null), a = y[0], e = y[1], n = (0, s.useState)(0), r = n[0], u = n[1], d = (0, s.useState)(!1), t = d[0], c = d[1], m = (0, s.useState)(), w = m[0], i = m[1], U = (0, l.useEventSystem)(), _ = (0, s.useRef)({
314
+ companyName: o.companyName,
315
+ productName: o.productName,
316
+ productVersion: o.productVersion,
317
+ codeUrl: o.codeUrl,
318
+ dataUrl: o.dataUrl,
319
+ frameworkUrl: o.frameworkUrl,
320
+ loaderUrl: o.loaderUrl,
321
+ memoryUrl: o.memoryUrl,
322
+ symbolsUrl: o.symbolsUrl,
323
+ streamingAssetsUrl: o.streamingAssetsUrl,
324
+ workerUrl: o.workerUrl,
325
+ webglContextAttributes: o.webglContextAttributes,
326
+ cacheControl: o.cacheControl,
327
+ autoSyncPersistentDataPath: o.autoSyncPersistentDataPath,
328
+ setUnityInstance: e,
329
+ setLoadingProgression: u,
330
+ setIsLoaded: c,
331
+ setInitialisationError: i
332
+ }), h = (0, s.useCallback)(function(f) {
333
+ return a == null ? void 0 : a.SetFullscreen(f ? 1 : 0);
334
+ }, [a]), L = (0, s.useCallback)(function() {
335
+ var f;
336
+ return (f = a == null ? void 0 : a.Module.canvas) === null || f === void 0 ? void 0 : f.requestPointerLock();
337
+ }, [a]), A = (0, s.useCallback)(function(f, C, P) {
338
+ return a == null ? void 0 : a.SendMessage(f, C, P);
339
+ }, [a]), b = (0, s.useCallback)(function(f, C) {
340
+ var P;
341
+ return (P = a == null ? void 0 : a.Module.canvas) === null || P === void 0 ? void 0 : P.toDataURL(f, C);
342
+ }, [a]), g = (0, s.useCallback)(function() {
343
+ var f;
344
+ return (f = a == null ? void 0 : a.Quit()) !== null && f !== void 0 ? f : Promise.reject();
345
+ }, [a]), I = (0, s.useCallback)(function() {
346
+ var f;
347
+ return (f = a == null ? void 0 : a.GetMetricsInfo) === null || f === void 0 ? void 0 : f.call(a);
348
+ }, [a]);
349
+ return {
350
+ unityProvider: _.current,
351
+ loadingProgression: r,
352
+ isLoaded: t,
353
+ initialisationError: w,
354
+ requestFullscreen: h,
355
+ requestPointerLock: L,
356
+ sendMessage: A,
357
+ takeScreenshot: b,
358
+ unload: g,
359
+ getMetricsInfo: I,
360
+ addEventListener: U.addEventListener,
361
+ removeEventListener: U.removeEventListener,
362
+ UNSAFE__unityInstance: a
363
+ };
414
364
  };
415
- return N.useNullableState = c, N;
365
+ return R.useUnityContext = v, R;
416
366
  }
417
- var X;
418
- function ge() {
419
- if (X) return h;
420
- X = 1;
421
- var l = h && h.__awaiter || function(o, n, e, s) {
422
- function r(t) {
423
- return t instanceof e ? t : new e(function(d) {
424
- d(t);
425
- });
426
- }
427
- return new (e || (e = Promise))(function(t, d) {
428
- function U(v) {
429
- try {
430
- a(s.next(v));
431
- } catch (I) {
432
- d(I);
433
- }
434
- }
435
- function u(v) {
436
- try {
437
- a(s.throw(v));
438
- } catch (I) {
439
- d(I);
440
- }
441
- }
442
- function a(v) {
443
- v.done ? t(v.value) : r(v.value).then(U, u);
444
- }
445
- a((s = s.apply(o, n || [])).next());
446
- });
447
- }, c = h && h.__generator || function(o, n) {
448
- var e = { label: 0, sent: function() {
449
- if (t[0] & 1) throw t[1];
450
- return t[1];
451
- }, trys: [], ops: [] }, s, r, t, d = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
452
- return d.next = U(0), d.throw = U(1), d.return = U(2), typeof Symbol == "function" && (d[Symbol.iterator] = function() {
453
- return this;
454
- }), d;
455
- function U(a) {
456
- return function(v) {
457
- return u([a, v]);
367
+ var j = {}, Q;
368
+ function ue() {
369
+ if (Q) return j;
370
+ Q = 1, Object.defineProperty(j, "__esModule", { value: !0 }), j.useUnityMetricsInfo = void 0;
371
+ var s = k, l = function(v, o) {
372
+ var y = (0, s.useState)({}), a = y[0], e = y[1];
373
+ return (0, s.useEffect)(function() {
374
+ var n = setInterval(function() {
375
+ var r = v();
376
+ typeof r > "u" || e(r);
377
+ }, o.interval || 1e3);
378
+ return function() {
379
+ clearInterval(n);
458
380
  };
459
- }
460
- function u(a) {
461
- if (s) throw new TypeError("Generator is already executing.");
462
- for (; d && (d = 0, a[0] && (e = 0)), e; ) try {
463
- if (s = 1, r && (t = a[0] & 2 ? r.return : a[0] ? r.throw || ((t = r.return) && t.call(r), 0) : r.next) && !(t = t.call(r, a[1])).done) return t;
464
- switch (r = 0, t && (a = [a[0] & 2, t.value]), a[0]) {
465
- case 0:
466
- case 1:
467
- t = a;
468
- break;
469
- case 4:
470
- return e.label++, { value: a[1], done: !1 };
471
- case 5:
472
- e.label++, r = a[1], a = [0];
473
- continue;
474
- case 7:
475
- a = e.ops.pop(), e.trys.pop();
476
- continue;
477
- default:
478
- if (t = e.trys, !(t = t.length > 0 && t[t.length - 1]) && (a[0] === 6 || a[0] === 2)) {
479
- e = 0;
480
- continue;
481
- }
482
- if (a[0] === 3 && (!t || a[1] > t[0] && a[1] < t[3])) {
483
- e.label = a[1];
484
- break;
485
- }
486
- if (a[0] === 6 && e.label < t[1]) {
487
- e.label = t[1], t = a;
488
- break;
489
- }
490
- if (t && e.label < t[2]) {
491
- e.label = t[2], e.ops.push(a);
492
- break;
493
- }
494
- t[2] && e.ops.pop(), e.trys.pop();
495
- continue;
496
- }
497
- a = n.call(o, e);
498
- } catch (v) {
499
- a = [6, v], r = 0;
500
- } finally {
501
- s = t = 0;
502
- }
503
- if (a[0] & 5) throw a[1];
504
- return { value: a[0] ? a[1] : void 0, done: !0 };
505
- }
381
+ }, [v, o.interval]), a;
506
382
  };
507
- Object.defineProperty(h, "__esModule", { value: !0 }), h.useUnityContext = void 0;
508
- var i = g, y = te(), f = we(), b = he(), m = function(o) {
509
- var n = (0, b.useNullableState)(), e = n[0], s = n[1], r = (0, i.useState)(0), t = r[0], d = r[1], U = (0, i.useState)(!1), u = U[0], a = U[1], v = (0, b.useNullableState)(), I = v[0], ne = v[1], R = (0, f.useEventSystem)(), re = (0, i.useRef)({
510
- setLoadingProgression: d,
511
- setInitialisationError: ne,
512
- setUnityInstance: s,
513
- setIsLoaded: a,
514
- unityConfig: o
515
- }), ae = (0, i.useCallback)(
516
- /**
517
- * @param enabled Defines whether Unity should be in fullscreen.
518
- */
519
- function(_) {
520
- if (e === null) {
521
- console.warn(y.errorMessages.requestFullscreenNoUnityInstance);
522
- return;
523
- }
524
- e.SetFullscreen(_ === !0 ? 1 : 0);
525
- },
526
- [e]
527
- ), ie = (0, i.useCallback)(function() {
528
- if (e === null || typeof e.Module.canvas > "u") {
529
- console.warn(y.errorMessages.requestPointerLockNoUnityInstanceOrCanvas);
530
- return;
531
- }
532
- return e.Module.canvas.requestPointerLock();
533
- }, [e]), se = (0, i.useCallback)(
534
- /**
535
- * @param gameObjectName the name of the game object in your Unity scene.
536
- * @param methodName the name of the public method on the game object.
537
- * @param parameter an optional parameter to pass along to the method.
538
- */
539
- function(_, C, le) {
540
- if (e === null) {
541
- console.warn(y.errorMessages.sendMessageNoUnityInstance);
542
- return;
543
- }
544
- e.SendMessage(_, C, le);
545
- },
546
- [e]
547
- ), ue = (0, i.useCallback)(
548
- /**
549
- * @param dataType Defines the type of screenshot to take.
550
- * @param quality Defines the quality of the screenshot.
551
- * @returns A base 64 encoded string of the screenshot.
552
- */
553
- function(_, C) {
554
- if (e === null || typeof e.Module.canvas > "u") {
555
- console.warn(y.errorMessages.screenshotNoUnityInstanceOrCanvas);
556
- return;
557
- }
558
- return e.Module.canvas.toDataURL(_, C);
559
- },
560
- [e]
561
- ), O = (0, i.useCallback)(
562
- /**
563
- * @returns A promise that resolves when the UnityInstance has been unloaded.
564
- */
565
- function() {
566
- return e === null ? (console.warn(y.errorMessages.quitNoUnityInstance), Promise.reject()) : e.Quit();
567
- },
568
- [e]
569
- ), oe = (0, i.useCallback)(
570
- /**
571
- * @returns A promise that resolves when the UnityInstance has been unloaded.
572
- */
573
- function() {
574
- return l(void 0, void 0, void 0, function() {
575
- var _;
576
- return c(this, function(C) {
577
- switch (C.label) {
578
- case 0:
579
- return e === null || typeof e.Module.canvas > "u" ? (console.warn(y.errorMessages.genericNoUnityInstance), [2, Promise.reject()]) : (_ = e.Module.canvas, document.body.appendChild(_), _.style.display = "none", [4, O()]);
580
- case 1:
581
- return C.sent(), _.remove(), [
582
- 2
583
- /*return*/
584
- ];
585
- }
586
- });
587
- });
588
- },
589
- [e]
590
- );
591
- return (0, i.useEffect)(function() {
592
- a(t === 1);
593
- }, [t]), {
594
- unityProvider: re.current,
595
- loadingProgression: t,
596
- initialisationError: I,
597
- isLoaded: u,
598
- UNSAFE__unityInstance: e,
599
- requestFullscreen: ae,
600
- requestPointerLock: ie,
601
- sendMessage: se,
602
- takeScreenshot: ue,
603
- unload: O,
604
- UNSAFE__detachAndUnloadImmediate: oe,
605
- addEventListener: R.addEventListener,
606
- removeEventListener: R.removeEventListener
607
- };
608
- };
609
- return h.useUnityContext = m, h;
383
+ return j.useUnityMetricsInfo = l, j;
610
384
  }
611
- var Y;
612
- function Ie() {
613
- return Y || (Y = 1, function(l) {
614
- Object.defineProperty(l, "__esModule", { value: !0 }), l.useUnityContext = l.Unity = void 0;
615
- var c = _e();
616
- Object.defineProperty(l, "Unity", { enumerable: !0, get: function() {
617
- return c.Unity;
385
+ var J;
386
+ function se() {
387
+ return J || (J = 1, function(s) {
388
+ Object.defineProperty(s, "__esModule", { value: !0 }), s.useUnityMetricsInfo = s.useUnityContext = s.Unity = void 0;
389
+ var l = ne();
390
+ Object.defineProperty(s, "Unity", { enumerable: !0, get: function() {
391
+ return l.Unity;
392
+ } });
393
+ var v = ae();
394
+ Object.defineProperty(s, "useUnityContext", { enumerable: !0, get: function() {
395
+ return v.useUnityContext;
618
396
  } });
619
- var i = ge();
620
- Object.defineProperty(l, "useUnityContext", { enumerable: !0, get: function() {
621
- return i.useUnityContext;
397
+ var o = ue();
398
+ Object.defineProperty(s, "useUnityMetricsInfo", { enumerable: !0, get: function() {
399
+ return o.useUnityMetricsInfo;
622
400
  } });
623
- }(j)), j;
401
+ }(B)), B;
624
402
  }
625
- var Z = Ie();
626
- const Se = de.forwardRef(
627
- ({ className: l, gameLink: c, loadingComponent: i, registerEvents: y, onEventReceived: f }, b) => {
403
+ var K = se();
404
+ const le = Z.forwardRef(
405
+ ({ className: s, gameLink: l, loadingComponent: v, registerEvents: o, onEventReceived: y }, a) => {
628
406
  const {
629
- unityProvider: m,
630
- isLoaded: o,
631
- loadingProgression: n,
632
- UNSAFE__unityInstance: e,
633
- addEventListener: s,
634
- removeEventListener: r,
635
- unload: t
636
- } = Z.useUnityContext({
637
- loaderUrl: `${c}/Build/Build.loader.js`,
638
- dataUrl: `${c}/Build/Build.data.unityweb`,
639
- frameworkUrl: `${c}/Build/Build.framework.js.unityweb`,
640
- codeUrl: `${c}/Build/Build.wasm.unityweb`
641
- }), d = B(null), U = B([]);
642
- return ve(
643
- b,
407
+ unityProvider: e,
408
+ isLoaded: n,
409
+ loadingProgression: r,
410
+ UNSAFE__unityInstance: u,
411
+ addEventListener: d,
412
+ removeEventListener: t,
413
+ unload: c,
414
+ getMetricsInfo: m
415
+ } = K.useUnityContext({
416
+ loaderUrl: `${l}/Build/Build.loader.js`,
417
+ dataUrl: `${l}/Build/Build.data.unityweb`,
418
+ frameworkUrl: `${l}/Build/Build.framework.js.unityweb`,
419
+ codeUrl: `${l}/Build/Build.wasm.unityweb`
420
+ }), w = G(null), i = G([]);
421
+ return p(
422
+ a,
644
423
  () => ({
645
- unload: t,
646
- canvas: d.current
424
+ unload: c,
425
+ getMetricsInfo: m,
426
+ canvas: w.current
647
427
  }),
648
- [t]
649
- ), F(() => {
650
- if (!(y && f))
428
+ [c, m]
429
+ ), D(() => {
430
+ if (!(o && y))
651
431
  return () => {
652
432
  };
653
- const u = [];
654
- for (const a of y)
655
- if (!U.current.some((v) => v.key === a)) {
656
- const v = (I) => {
657
- f == null || f(a, I);
433
+ const U = [];
434
+ for (const _ of o)
435
+ if (!i.current.some((h) => h.key === _)) {
436
+ const h = (L) => {
437
+ y == null || y(_, L);
658
438
  };
659
- s(a, v), u.push({ key: a, event: v });
439
+ d(_, h), U.push({ key: _, event: h });
660
440
  }
661
- return U.current = [...U.current, ...u], () => {
662
- for (const { key: a, event: v } of U.current)
663
- r(a, v);
664
- U.current = [];
441
+ return i.current = [...i.current, ...U], () => {
442
+ for (const { key: _, event: h } of i.current)
443
+ t(_, h);
444
+ i.current = [];
665
445
  };
666
- }, [y, s, r, f]), F(() => {
667
- window && e && (window.unityInstance = e);
668
- }, [e]), /* @__PURE__ */ P(ce, { children: [
669
- !o && (i ? /* @__PURE__ */ $(i, { progress: n }) : /* @__PURE__ */ P("div", { className: "h-full w-full items-center justify-center text-center", children: [
446
+ }, [o, d, t, y]), D(() => {
447
+ window && u && (window.unityInstance = u);
448
+ }, [u]), /* @__PURE__ */ O(Y, { children: [
449
+ !n && (v ? /* @__PURE__ */ $(v, { progress: r }) : /* @__PURE__ */ O("div", { className: "h-full w-full items-center justify-center text-center", children: [
670
450
  "Loading $",
671
- n * 100,
451
+ r * 100,
672
452
  "%"
673
453
  ] })),
674
454
  /* @__PURE__ */ $(
675
- Z.Unity,
455
+ K.Unity,
676
456
  {
677
- ref: d,
457
+ ref: w,
678
458
  id: "unity-canvas",
679
- unityProvider: m,
680
- className: fe(l, !o && "hidden"),
459
+ unityProvider: e,
460
+ className: ee(s, !n && "hidden"),
681
461
  devicePixelRatio: (window == null ? void 0 : window.devicePixelRatio) || 1
682
462
  }
683
463
  )
@@ -685,5 +465,5 @@ const Se = de.forwardRef(
685
465
  }
686
466
  );
687
467
  export {
688
- Se as UnityGame
468
+ le as UnityGame
689
469
  };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { UnityInstance } from 'react-unity-webgl/declarations/unity-instance';
1
+ import { UnityInstance } from 'react-unity-webgl';
2
+ import { UnityMetricsInfo } from 'react-unity-webgl/distribution/types/unity-metrics-info';
2
3
  declare global {
3
4
  interface Window {
4
5
  APP_ID: string;
@@ -15,5 +16,6 @@ export declare enum EventName {
15
16
  }
16
17
  export interface PromogamePlayerHandle {
17
18
  unload: () => void;
19
+ getMetricsInfo: () => UnityMetricsInfo | undefined;
18
20
  canvas?: HTMLCanvasElement | null;
19
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promogame-player",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -16,7 +16,7 @@
16
16
  "@graphql-typed-document-node/core": "^3.2.0",
17
17
  "clsx": "^2.1.1",
18
18
  "graphql": "^16.11.0",
19
- "react-unity-webgl": "^9.8.0",
19
+ "react-unity-webgl": "^10.1.5",
20
20
  "tailwind-merge": "^3.3.0"
21
21
  },
22
22
  "devDependencies": {