promogame-player 0.0.25 → 0.0.27

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