@puzzmo/sdk 1.0.60 → 1.0.62

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 (41) hide show
  1. package/dist/bootstrapPayload.d.ts +8 -0
  2. package/dist/bootstrapPayload.d.ts.map +1 -0
  3. package/dist/contracts.d.ts +1 -1
  4. package/dist/{createSimulator-Dory7qUL.js → createSimulator-CdInpCHG.js} +220 -202
  5. package/dist/{createSimulator-Dory7qUL.js.map → createSimulator-CdInpCHG.js.map} +1 -1
  6. package/dist/{createSimulator-kGIstLy9.cjs → createSimulator-PNeBoNux.cjs} +22 -22
  7. package/dist/{createSimulator-kGIstLy9.cjs.map → createSimulator-PNeBoNux.cjs.map} +1 -1
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.global.js +1 -1
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +229 -179
  15. package/dist/index.js.map +1 -1
  16. package/dist/inputs/index.cjs +1 -1
  17. package/dist/inputs/index.js +1 -1
  18. package/dist/{lua-C3M-mB0u.js → lua-DKb2Tu2V.js} +2 -2
  19. package/dist/{lua-C3M-mB0u.js.map → lua-DKb2Tu2V.js.map} +1 -1
  20. package/dist/{lua-D5xtGGen.cjs → lua-QeU9Rzet.cjs} +2 -2
  21. package/dist/{lua-D5xtGGen.cjs.map → lua-QeU9Rzet.cjs.map} +1 -1
  22. package/dist/pico8/index.cjs +1 -1
  23. package/dist/pico8/index.js +3 -3
  24. package/dist/pico8/lua.d.ts +1 -1
  25. package/dist/sdk.d.ts.map +1 -1
  26. package/dist/simulator/createSimulator.d.ts.map +1 -1
  27. package/dist/simulator/index.cjs +1 -1
  28. package/dist/simulator/index.js +1 -1
  29. package/dist/simulator/standalone.cjs +1 -1
  30. package/dist/simulator/standalone.js +1 -1
  31. package/dist/types.d.ts +100 -51
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/vite.cjs +3 -3
  34. package/dist/vite.js +27 -27
  35. package/package.json +1 -1
  36. /package/dist/{asyncToGenerator-Dn36a-ch.js → asyncToGenerator-BotOOyB7.js} +0 -0
  37. /package/dist/{asyncToGenerator-DANjdFmB.cjs → asyncToGenerator-DIL7svO7.cjs} +0 -0
  38. /package/dist/{objectSpread2-C8x7fbpH.js → objectSpread2-BQwrzeNG.js} +0 -0
  39. /package/dist/{objectSpread2-DLgRiGrq.cjs → objectSpread2-CCAs_T0X.cjs} +0 -0
  40. /package/dist/{objectWithoutProperties-BVU0RRck.js → objectWithoutProperties-Bjd1IAMi.js} +0 -0
  41. /package/dist/{objectWithoutProperties-ChRmjIUS.cjs → objectWithoutProperties-Ee8z5QMa.cjs} +0 -0
package/dist/index.js CHANGED
@@ -1,14 +1,60 @@
1
- import { t as e } from "./objectSpread2-C8x7fbpH.js";
2
- import { t } from "./asyncToGenerator-Dn36a-ch.js";
3
- import { t as n } from "./objectWithoutProperties-BVU0RRck.js";
4
- var r = function() {
5
- var n = t(function* (t, n, r, i) {
1
+ import { t as e } from "./objectWithoutProperties-Bjd1IAMi.js";
2
+ import { t } from "./objectSpread2-BQwrzeNG.js";
3
+ import { t as n } from "./asyncToGenerator-BotOOyB7.js";
4
+ var r = ["startOrFindGameplay"], i = ["puzzle"], a = ["game", "viewerMetadata"];
5
+ /**
6
+ * Fills in `game` and `session` when READY_DATA comes from a host which only sends the older
7
+ * `startOrFindGameplay` nesting, so the SDK and games only ever see the new shape. A copy of
8
+ * upgradeBootstrapGameData in @puzzmo-com/shared, which the SDK can't depend on.
9
+ */
10
+ const o = (n) => {
11
+ var o, c, l;
12
+ let { startOrFindGameplay: u } = n, d = e(n, r);
13
+ if (d.game) return d;
14
+ let f = u == null ? void 0 : u.gamePlayed, p = s((o = f == null || (c = f.puzzle) == null ? void 0 : c.game) == null ? {} : o);
15
+ if (!f) return t(t({}, d), {}, { game: p });
16
+ let { puzzle: m } = f, h = e(f, i), { game: g, viewerMetadata: _ } = m, v = e(m, a);
17
+ return t(t({}, d), {}, {
18
+ game: p,
19
+ session: {
20
+ gameplay: h,
21
+ puzzle: v
22
+ },
23
+ viewerMetadata: (l = d.viewerMetadata) == null ? _ : l
24
+ });
25
+ };
26
+ /** Builds the game from the flattened fields older hosts put on `puzzle.game`, with no version IDs */
27
+ var s = (e) => {
28
+ var t, n, r, i, a, o, s, c;
29
+ let l = e.flagsArr;
30
+ return {
31
+ id: (t = e.id) == null ? "" : t,
32
+ slug: (n = e.slug) == null ? "" : n,
33
+ stableSlug: (r = (i = e.stableSlug) == null ? e.slug : i) == null ? "" : r,
34
+ displayName: (a = e.displayName) == null ? "" : a,
35
+ version: {
36
+ id: "",
37
+ label: null,
38
+ featuresArr: (o = e.featuresArr) == null ? [0] : o,
39
+ flagsArr: Array.isArray(l) ? l : typeof l == "number" ? [l] : [0],
40
+ runtime: {
41
+ id: "",
42
+ version: e.assetsSha || e.assetsBaseURL ? {
43
+ id: "",
44
+ assetsSha: (s = e.assetsSha) == null ? "" : s,
45
+ assetsBaseURL: (c = e.assetsBaseURL) == null ? "" : c
46
+ } : null
47
+ }
48
+ }
49
+ };
50
+ }, c = function() {
51
+ var e = n(function* (e, n, r, i) {
6
52
  try {
7
- let a = e(e({}, t), {}, {
53
+ let a = t(t({}, e), {}, {
8
54
  eventType: n,
9
55
  elapsedTimeOnComplete: i,
10
56
  metadata: r
11
- }), o = yield fetch(`${t.apiRoot}events`, {
57
+ }), o = yield fetch(`${e.apiRoot}events`, {
12
58
  method: "POST",
13
59
  headers: { "Content-Type": "application/json" },
14
60
  body: JSON.stringify(a),
@@ -19,11 +65,11 @@ var r = function() {
19
65
  console.warn(`Analytics event error: ${n}`, e);
20
66
  }
21
67
  });
22
- return function(e, t, r, i) {
23
- return n.apply(this, arguments);
68
+ return function(t, n, r, i) {
69
+ return e.apply(this, arguments);
24
70
  };
25
71
  }();
26
- const i = (e) => {
72
+ const l = (e) => {
27
73
  let t = {
28
74
  context: e,
29
75
  updateCount: 0,
@@ -37,30 +83,30 @@ const i = (e) => {
37
83
  };
38
84
  return {
39
85
  trackEvent: (e, n) => {
40
- let i = ((/* @__PURE__ */ new Date()).getTime() - t.startTime.getTime()) / 1e3;
86
+ let r = ((/* @__PURE__ */ new Date()).getTime() - t.startTime.getTime()) / 1e3;
41
87
  switch (e) {
42
88
  case "READY_GAME_LOADED":
43
- t.tracked.pageView || (r(t.context, "page_view"), t.tracked.pageView = !0);
89
+ t.tracked.pageView || (c(t.context, "page_view"), t.tracked.pageView = !0);
44
90
  break;
45
91
  case "UPLOAD_NEW_GAME_STATE":
46
- t.updateCount++, t.updateCount > 2 && !t.tracked.gameplayActive && (r(t.context, "gameplay_active"), t.tracked.gameplayActive = !0), i > 30 && (t.tracked.gameplayActive || (r(t.context, "gameplay_active"), t.tracked.gameplayActive = !0), t.tracked.active30s || (r(t.context, "active_30s"), t.tracked.active30s = !0));
92
+ t.updateCount++, t.updateCount > 2 && !t.tracked.gameplayActive && (c(t.context, "gameplay_active"), t.tracked.gameplayActive = !0), r > 30 && (t.tracked.gameplayActive || (c(t.context, "gameplay_active"), t.tracked.gameplayActive = !0), t.tracked.active30s || (c(t.context, "active_30s"), t.tracked.active30s = !0));
47
93
  break;
48
94
  case "GAME_COMPLETED":
49
- !t.tracked.completed && n != null && n.input && (r(t.context, "completed", {}, n.input.elapsedTimeSecs), t.tracked.completed = !0);
95
+ !t.tracked.completed && n != null && n.input && (c(t.context, "completed", {}, n.input.elapsedTimeSecs), t.tracked.completed = !0);
50
96
  break;
51
97
  }
52
98
  },
53
99
  trackLinkClick: (e) => {
54
- r(t.context, "link_click", e);
100
+ c(t.context, "link_click", e);
55
101
  }
56
102
  };
57
- }, a = (e) => {
58
- if (!d(e)) return null;
59
- let t = s();
103
+ }, u = (e) => {
104
+ if (!g(e)) return null;
105
+ let t = f();
60
106
  if (!t.enabled) return null;
61
- let n = c(e, t.apiRoot);
62
- return n ? i(n) : null;
63
- }, o = (e) => {
107
+ let n = p(e, t.apiRoot);
108
+ return n ? l(n) : null;
109
+ }, d = (e) => {
64
110
  if (typeof document > "u") return () => {};
65
111
  let t = (t) => {
66
112
  var n, r;
@@ -76,7 +122,7 @@ const i = (e) => {
76
122
  return document.addEventListener("click", t), () => document.removeEventListener("click", t);
77
123
  };
78
124
  /** Picks the events endpoint, and disables analytics entirely on localhost (dev + simulator). */
79
- var s = () => {
125
+ var f = () => {
80
126
  if (typeof window > "u" || !window.location) return {
81
127
  apiRoot: "",
82
128
  enabled: !1
@@ -89,38 +135,37 @@ var s = () => {
89
135
  apiRoot: e.includes("staging") ? "https://api-staging.puzzmo.com/" : "https://api.puzzmo.com/",
90
136
  enabled: !0
91
137
  };
92
- }, c = (e, t) => {
93
- var n, r, i, a, o, s, c, u, d, p, m;
94
- let h = e == null || (n = e.startOrFindGameplay) == null ? void 0 : n.gamePlayed;
95
- if (!h) return null;
96
- let g = h.puzzle, _ = (r = e == null ? void 0 : e.hostContext) == null ? [] : r;
138
+ }, p = (e, t) => {
139
+ var n, r, i, a, o, s, c, l, u;
140
+ let d = e == null ? void 0 : e.session;
141
+ if (!d) return null;
142
+ let f = d.gameplay, p = d.puzzle, h = (n = e == null ? void 0 : e.hostContext) == null ? [] : n;
97
143
  return {
98
- gameSlug: (i = (a = g.game) == null ? void 0 : a.slug) == null ? "unknown" : i,
99
- puzzleID: g.id,
100
- gameplayOwnerID: h.ownerID || (e == null || (o = e.userState) == null ? void 0 : o.id) || "unknown",
144
+ gameSlug: (e == null || (r = e.game) == null ? void 0 : r.slug) || "unknown",
145
+ puzzleID: p.id,
146
+ gameplayOwnerID: f.ownerID || (e == null || (i = e.userState) == null ? void 0 : i.id) || "unknown",
101
147
  apiRoot: t,
102
- userType: l(e == null || (s = e.currentUser) == null ? void 0 : s.type),
103
- runtimeType: f(_),
104
- userID: e == null || (c = e.currentUser) == null ? void 0 : c.id,
105
- teamSlug: ((u = g.team) == null ? void 0 : u.slug) || void 0,
106
- partnerSlug: ((d = _.find((e) => (e == null ? void 0 : e.type) === "embed")) == null || (d = d.partner) == null ? void 0 : d.slug) || void 0,
107
- dailyDateKey: (p = g.mostRecentDaily) == null || (p = p.daily) == null ? void 0 : p.dateKey,
108
- embedID: ((m = _.find((e) => (e == null ? void 0 : e.type) === "embed")) == null ? void 0 : m.embedID) || void 0
148
+ userType: m(e == null || (a = e.currentUser) == null ? void 0 : a.type),
149
+ runtimeType: _(h),
150
+ userID: e == null || (o = e.currentUser) == null ? void 0 : o.id,
151
+ teamSlug: ((s = p.team) == null ? void 0 : s.slug) || void 0,
152
+ partnerSlug: ((c = h.find((e) => (e == null ? void 0 : e.type) === "embed")) == null || (c = c.partner) == null ? void 0 : c.slug) || void 0,
153
+ dailyDateKey: (l = p.mostRecentDaily) == null || (l = l.daily) == null ? void 0 : l.dateKey,
154
+ embedID: ((u = h.find((e) => (e == null ? void 0 : e.type) === "embed")) == null ? void 0 : u.embedID) || void 0
109
155
  };
110
- }, l = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user", u = 512, d = (e) => {
156
+ }, m = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user", h = 512, g = (e) => {
111
157
  var t, n;
112
- let r = e == null || (t = e.startOrFindGameplay) == null || (t = t.gamePlayed) == null || (t = t.puzzle) == null ? void 0 : t.game, i = r == null ? void 0 : r.flagsArr;
113
- return ((Array.isArray(i) ? (n = i[0]) == null ? 0 : n : typeof i == "number" ? i : 0) & u) === u;
114
- }, f = (e) => {
158
+ return (((t = e == null || (n = e.game) == null ? void 0 : n.version.flagsArr[0]) == null ? 0 : t) & h) === h;
159
+ }, _ = (e) => {
115
160
  if (e.find((e) => (e == null ? void 0 : e.type) === "embed")) return "iframe";
116
161
  let t = e.find((e) => (e == null ? void 0 : e.type) === "app");
117
162
  return (t == null ? void 0 : t.host) === "__embed" ? "simple_embed" : (t == null ? void 0 : t.host) === "app-embed" ? "app_embed" : (t == null ? void 0 : t.host) === "ios-app" ? "ios_native" : "puzzmo_com";
118
- }, p = ["inputString"];
119
- function m(e) {
163
+ }, v = ["inputString"];
164
+ function y(e) {
120
165
  let t = e >= 3600 * 1e3;
121
166
  return new Date(e).toISOString().slice(t ? 11 : 14, -1).split(".")[0];
122
167
  }
123
- function h(e = 0, t = 0) {
168
+ function b(e = 0, t = 0) {
124
169
  let n = e, r = t, i = 0, a, o, s, c = () => {
125
170
  var e;
126
171
  if (o === void 0) return n + r;
@@ -167,11 +212,11 @@ function h(e = 0, t = 0) {
167
212
  isRunning: () => o !== void 0 && s === void 0,
168
213
  display: () => {
169
214
  let e = c() - r;
170
- return [m(Math.max(0, e)), r === 0 ? "" : m(r)];
215
+ return [y(Math.max(0, e)), r === 0 ? "" : y(r)];
171
216
  }
172
217
  };
173
218
  }
174
- function g() {
219
+ function x() {
175
220
  let e = /* @__PURE__ */ new Map();
176
221
  return typeof window < "u" && window.addEventListener("message", (t) => {
177
222
  var n;
@@ -200,137 +245,142 @@ function g() {
200
245
  })
201
246
  };
202
247
  }
203
- var _ = g();
248
+ /**
249
+ * The host<->game contract this SDK is built against, declared in READY and READY_GAME_LOADED.
250
+ * Stays "1.0" until every host supporting "1.1" is deployed: an older puzzmo.com reloads when it
251
+ * sees a contract it doesn't know.
252
+ */
253
+ var S = "1.0", C = x();
204
254
  /** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
205
- const v = (r = {}) => {
255
+ const w = (r = {}) => {
206
256
  var i;
207
- let s = null, c = null, l = () => {
257
+ let a = null, s = null, c = () => {
208
258
  var e;
209
- return s == null || (e = s.startOrFindGameplay) == null ? void 0 : e.gamePlayed;
210
- }, u = () => {
259
+ return a == null || (e = a.session) == null ? void 0 : e.gameplay;
260
+ }, l = () => {
211
261
  var e, t;
212
- return (e = (t = l()) == null ? void 0 : t.id) == null ? null : e;
213
- }, d = () => {
214
- var e, t;
215
- return (e = (t = l()) == null ? void 0 : t.puzzle.puzzle) == null ? null : e;
262
+ return (e = (t = c()) == null ? void 0 : t.id) == null ? null : e;
216
263
  }, f = () => {
217
264
  var e, t;
218
- return (e = (t = l()) == null ? void 0 : t.boardState) == null ? null : e;
265
+ return (e = a == null || (t = a.session) == null ? void 0 : t.puzzle.puzzle) == null ? null : e;
266
+ }, p = () => {
267
+ var e, t;
268
+ return (e = (t = c()) == null ? void 0 : t.boardState) == null ? null : e;
219
269
  }, m = () => {
220
270
  var e;
221
- return (e = s == null ? void 0 : s.theme) == null ? null : e;
222
- }, g = () => {
271
+ return (e = a == null ? void 0 : a.theme) == null ? null : e;
272
+ }, h = () => {
223
273
  var e, t;
224
- return (e = (t = l()) == null ? void 0 : t.completed) == null ? !1 : e;
225
- }, v = /* @__PURE__ */ new Map(), b = null, x = null, S = !1, C = (e, t) => {
226
- S || x == null || x.trackEvent(e, t);
227
- }, w = h(), T = null, E = null, D = () => {
228
- T || (T = setInterval(() => {
229
- if (w.isPaused()) return;
230
- let [e, t] = w.display();
231
- _.sendMessage("TIMER_TICK", { display: [e, t] });
232
- }, 500), E = setInterval(() => {
233
- w.isPaused() || _.sendMessage("TIMER_SYNC", Math.floor(w.timeWithoutPenaltySecs()));
274
+ return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
275
+ }, g = /* @__PURE__ */ new Map(), _ = null, y = null, x = !1, w = (e, t) => {
276
+ x || y == null || y.trackEvent(e, t);
277
+ }, E = b(), D = null, O = null, k = () => {
278
+ D || (D = setInterval(() => {
279
+ if (E.isPaused()) return;
280
+ let [e, t] = E.display();
281
+ C.sendMessage("TIMER_TICK", { display: [e, t] });
282
+ }, 500), O = setInterval(() => {
283
+ E.isPaused() || C.sendMessage("TIMER_SYNC", Math.floor(E.timeWithoutPenaltySecs()));
234
284
  }, 1e4));
235
- }, O = () => {
236
- T && (clearInterval(T), T = null), E && (clearInterval(E), E = null);
237
- }, k = (e, t) => {
238
- let n = v.get(e);
285
+ }, A = () => {
286
+ D && (clearInterval(D), D = null), O && (clearInterval(O), O = null);
287
+ }, j = (e, t) => {
288
+ let n = g.get(e);
239
289
  n && n.forEach((e) => e(t));
240
290
  };
241
- _.onMessage("START_GAME", () => {
242
- w._init(), D(), k("start");
291
+ C.onMessage("START_GAME", () => {
292
+ E._init(), k(), j("start");
243
293
  });
244
- let A = () => {
245
- let e = w.isPaused();
246
- w._pause(), w.isPaused() !== e && k("pause");
247
- }, j = () => {
248
- let e = w.isPaused();
249
- w._resume(), w.isPaused() !== e && k("resume");
294
+ let M = () => {
295
+ let e = E.isPaused();
296
+ E._pause(), E.isPaused() !== e && j("pause");
297
+ }, N = () => {
298
+ let e = E.isPaused();
299
+ E._resume(), E.isPaused() !== e && j("resume");
250
300
  };
251
- _.onMessage("PAUSE_GAME", A), _.onMessage("RESUME_GAME", j), _.onMessage("SETTINGS_UPDATE", (t) => {
252
- b = e(e({}, b), t), k("settingsUpdate", b);
253
- }), _.onMessage("KEYBOARD_KEY_PRESS", (e) => k("keyboardKeyPress", e)), _.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => k("keyboardCursorChange", e)), _.onMessage("KEYBOARD_CURSOR_END", () => k("keyboardCursorEnd")), _.onMessage("RETRY_PUZZLE", () => {
254
- w._reset(), O(), k("retry");
255
- }), _.onMessage("READY_DATA", (e) => {
301
+ C.onMessage("PAUSE_GAME", M), C.onMessage("RESUME_GAME", N), C.onMessage("SETTINGS_UPDATE", (e) => {
302
+ _ = t(t({}, _), e), j("settingsUpdate", _);
303
+ }), C.onMessage("KEYBOARD_KEY_PRESS", (e) => j("keyboardKeyPress", e)), C.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => j("keyboardCursorChange", e)), C.onMessage("KEYBOARD_CURSOR_END", () => j("keyboardCursorEnd")), C.onMessage("RETRY_PUZZLE", () => {
304
+ E._reset(), A(), j("retry");
305
+ }), C.onMessage("READY_DATA", (e) => {
256
306
  var t;
257
- let n = e;
258
- s = n;
259
- let r = (t = n.startOrFindGameplay) == null ? void 0 : t.gamePlayed;
260
- if (b === null) {
261
- var i, l, u;
262
- let e = r == null || (i = r.puzzle) == null || (i = i.game) == null ? void 0 : i.slug, t = e ? (l = n.userState) == null || (l = l.gameSettings) == null ? void 0 : l[e] : null;
307
+ let n = o(e);
308
+ a = n;
309
+ let r = (t = n.session) == null ? void 0 : t.gameplay;
310
+ if (_ === null) {
311
+ var i, c;
312
+ let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
263
313
  if (typeof t == "string") try {
264
314
  t = JSON.parse(t);
265
315
  } catch (e) {
266
316
  t = null;
267
317
  }
268
- b = (u = t) == null ? {} : u;
318
+ _ = (c = t) == null ? {} : c;
269
319
  }
270
320
  if (r) {
271
- var d, f;
272
- let e = ((d = r.elapsedTimeSecs) == null ? 0 : d) * 1e3, t = ((f = r.additionalTimeAddedSecs) == null ? 0 : f) * 1e3;
273
- w._reset(e, t);
321
+ var l, f;
322
+ let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((f = r.additionalTimeAddedSecs) == null ? 0 : f) * 1e3;
323
+ E._reset(e, t);
274
324
  }
275
- if (!x) {
325
+ if (!y) {
276
326
  var p;
277
- x = a(n), S = (p = r == null ? void 0 : r.completed) == null ? !1 : p, x && o((e) => x.trackLinkClick(e));
327
+ y = u(n), x = (p = r == null ? void 0 : r.completed) == null ? !1 : p, y && d((e) => y.trackLinkClick(e));
278
328
  }
279
- c && (c(n), c = null);
329
+ s && (s(n), s = null);
280
330
  });
281
- let M = {
282
- timeMs: () => w.timeMs(),
283
- timeSecs: () => w.timeSecs(),
284
- addedTimeMs: () => w.addedTimeMs(),
285
- addedTimeSecs: () => w.addedTimeSecs(),
286
- timeWithoutPenaltySecs: () => w.timeWithoutPenaltySecs(),
287
- display: () => w.display(),
288
- addPenalty: (e) => w.addPenalty(e),
289
- setPenalty: (e) => w.setPenalty(e),
290
- isPaused: () => w.isPaused(),
291
- isRunning: () => w.isRunning(),
292
- pause: A,
293
- resume: j
294
- }, N = {
295
- send: (e, t) => _.sendMessage(e, t),
296
- on: (e, t) => _.onMessage(e, t),
297
- timer: M,
298
- bootstrap: () => s
299
- }, P = {};
300
- for (let e of (i = r.plugins) == null ? [] : i) P[e.name] = e.setup(N);
331
+ let P = {
332
+ timeMs: () => E.timeMs(),
333
+ timeSecs: () => E.timeSecs(),
334
+ addedTimeMs: () => E.addedTimeMs(),
335
+ addedTimeSecs: () => E.addedTimeSecs(),
336
+ timeWithoutPenaltySecs: () => E.timeWithoutPenaltySecs(),
337
+ display: () => E.display(),
338
+ addPenalty: (e) => E.addPenalty(e),
339
+ setPenalty: (e) => E.setPenalty(e),
340
+ isPaused: () => E.isPaused(),
341
+ isRunning: () => E.isRunning(),
342
+ pause: M,
343
+ resume: N
344
+ }, F = {
345
+ send: (e, t) => C.sendMessage(e, t),
346
+ on: (e, t) => C.onMessage(e, t),
347
+ timer: P,
348
+ bootstrap: () => a
349
+ }, I = {};
350
+ for (let e of (i = r.plugins) == null ? [] : i) I[e.name] = e.setup(F);
301
351
  return {
302
- timer: M,
303
- plugins: P,
352
+ timer: P,
353
+ plugins: I,
304
354
  gameReady: function() {
305
- var e = t(function* () {
355
+ var e = n(function* () {
306
356
  var e;
307
- if (_.sendMessage("READY", {}), d()) {
308
- let e = f();
357
+ if (C.sendMessage("READY", { runtimeContract: S }), f()) {
358
+ let e = p();
309
359
  return {
310
- puzzleString: d(),
360
+ puzzleString: f(),
311
361
  inputString: e,
312
362
  boardState: e,
313
363
  theme: m(),
314
- completed: g(),
315
- readyData: s
364
+ completed: h(),
365
+ readyData: a
316
366
  };
317
367
  }
318
368
  let t = (e = r.timeout) == null ? 5e3 : e;
319
369
  yield new Promise((e, n) => {
320
- c = e, setTimeout(() => {
321
- c && (c = null, n(/* @__PURE__ */ Error(`Timeout waiting for READY_DATA after ${t}ms`)));
370
+ s = e, setTimeout(() => {
371
+ s && (s = null, n(/* @__PURE__ */ Error(`Timeout waiting for READY_DATA after ${t}ms`)));
322
372
  }, t);
323
373
  });
324
- let n = d();
374
+ let n = f();
325
375
  if (!n) throw Error("READY_DATA received but no puzzle data found");
326
- let i = f();
376
+ let i = p();
327
377
  return {
328
378
  puzzleString: n,
329
379
  inputString: i,
330
380
  boardState: i,
331
381
  theme: m(),
332
- completed: g(),
333
- readyData: s
382
+ completed: h(),
383
+ readyData: a
334
384
  };
335
385
  });
336
386
  return function() {
@@ -338,69 +388,69 @@ const v = (r = {}) => {
338
388
  };
339
389
  }(),
340
390
  gameLoaded: (e = {}) => {
341
- _.sendMessage("READY_GAME_LOADED", {
391
+ C.sendMessage("READY_GAME_LOADED", {
342
392
  state: e,
343
- gameRuntimeContract: "1.0",
393
+ gameRuntimeContract: S,
344
394
  embedRuntimeContract: "1.0"
345
- }), C("READY_GAME_LOADED");
395
+ }), w("READY_GAME_LOADED");
346
396
  },
347
- on: (e, t) => (v.has(e) || v.set(e, /* @__PURE__ */ new Set()), v.get(e).add(t), () => {
397
+ on: (e, t) => (g.has(e) || g.set(e, /* @__PURE__ */ new Set()), g.get(e).add(t), () => {
348
398
  var n;
349
- (n = v.get(e)) == null || n.delete(t);
399
+ (n = g.get(e)) == null || n.delete(t);
350
400
  }),
351
401
  off: (e, t) => {
352
402
  var n;
353
- (n = v.get(e)) == null || n.delete(t);
403
+ (n = g.get(e)) == null || n.delete(t);
354
404
  },
355
405
  updateGameState: (e, t) => {
356
406
  var n, r;
357
- let i = u();
358
- i && (_.sendMessage("UPLOAD_NEW_GAME_STATE", {
407
+ let i = l();
408
+ i && (C.sendMessage("UPLOAD_NEW_GAME_STATE", {
359
409
  id: i,
360
410
  input: {
361
411
  boardState: e,
362
- elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? w.timeWithoutPenaltySecs() : n,
363
- additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? w.addedTimeSecs() : r,
412
+ elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? E.timeWithoutPenaltySecs() : n,
413
+ additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? E.addedTimeSecs() : r,
364
414
  collabUserReferences: []
365
415
  }
366
- }), C("UPLOAD_NEW_GAME_STATE"));
416
+ }), w("UPLOAD_NEW_GAME_STATE"));
367
417
  },
368
- gameCompleted: (t, r) => {
418
+ gameCompleted: (n, r) => {
369
419
  var i, a, o, s, c;
370
- w._conclude(), O();
371
- let { inputString: l } = t, d = e(e({}, n(t, p)), {}, {
372
- boardState: l == null ? t.boardState : l,
373
- elapsedTimeSecs: (i = t.elapsedTimeSecs) == null ? w.timeWithoutPenaltySecs() : i,
374
- additionalTimeAddedSecs: (a = t.additionalTimeAddedSecs) == null ? w.addedTimeSecs() : a
420
+ E._conclude(), A();
421
+ let { inputString: u } = n, d = t(t({}, e(n, v)), {}, {
422
+ boardState: u == null ? n.boardState : u,
423
+ elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? E.timeWithoutPenaltySecs() : i,
424
+ additionalTimeAddedSecs: (a = n.additionalTimeAddedSecs) == null ? E.addedTimeSecs() : a
375
425
  }), f = (o = r == null ? void 0 : r.deeds) == null ? [] : o;
376
426
  f.push({
377
427
  id: "points",
378
- value: t.pointsAwarded
428
+ value: n.pointsAwarded
379
429
  }), f.push({
380
430
  id: "time",
381
431
  value: Math.round((s = d.elapsedTimeSecs) == null ? 0 : s) + Math.round((c = d.additionalTimeAddedSecs) == null ? 0 : c)
382
432
  });
383
- let m = u();
384
- m && (_.sendMessage("GAME_COMPLETED", {
385
- id: m,
433
+ let p = l();
434
+ p && (C.sendMessage("GAME_COMPLETED", {
435
+ id: p,
386
436
  input: d,
387
437
  config: r
388
- }), C("GAME_COMPLETED", { input: d }));
438
+ }), w("GAME_COMPLETED", { input: d }));
389
439
  },
390
440
  showCompletionScreen: (e) => {
391
- _.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
441
+ C.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
392
442
  results: e,
393
443
  showRetry: !0
394
444
  });
395
445
  },
396
446
  hitCheckpoint: (e, t, n) => {
397
447
  var r;
398
- if (!u()) return;
399
- let i = (r = f()) == null ? "" : r, a = {
400
- elapsedTimeSecs: w.timeWithoutPenaltySecs(),
401
- additionalTimeAddedSecs: w.addedTimeSecs()
448
+ if (!l()) return;
449
+ let i = (r = p()) == null ? "" : r, a = {
450
+ elapsedTimeSecs: E.timeWithoutPenaltySecs(),
451
+ additionalTimeAddedSecs: E.addedTimeSecs()
402
452
  };
403
- _.sendMessage("HIT_CHECKPOINT", {
453
+ C.sendMessage("HIT_CHECKPOINT", {
404
454
  checkpointName: e,
405
455
  gameplay: {
406
456
  inputStr: i,
@@ -411,22 +461,22 @@ const v = (r = {}) => {
411
461
  });
412
462
  },
413
463
  settings: {
414
- initialize: (t) => (b = e(e({}, y(t)), b), _.sendMessage("INITIALIZE_SETTINGS", {
415
- components: t,
416
- settings: b
417
- }), b),
464
+ initialize: (e) => (_ = t(t({}, T(e)), _), C.sendMessage("INITIALIZE_SETTINGS", {
465
+ components: e,
466
+ settings: _
467
+ }), _),
418
468
  get: () => {
419
469
  var e;
420
- return (e = b) == null ? {} : e;
470
+ return (e = _) == null ? {} : e;
421
471
  },
422
- update: (t) => (b = e(e({}, b), t), _.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: b }), b)
472
+ update: (e) => (_ = t(t({}, _), e), C.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: _ }), _)
423
473
  },
424
474
  keyboard: {
425
475
  show: (e) => {
426
- _.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
476
+ C.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
427
477
  },
428
478
  hide: () => {
429
- _.sendMessage("KEYBOARD_UPDATE_CONFIG", {
479
+ C.sendMessage("KEYBOARD_UPDATE_CONFIG", {
430
480
  layout: [],
431
481
  symbols: {},
432
482
  highlight: [],
@@ -439,18 +489,18 @@ const v = (r = {}) => {
439
489
  },
440
490
  haptics: { play: (e, t) => {
441
491
  var n;
442
- _.sendMessage("SENSORY_EVENT", {
492
+ C.sendMessage("SENSORY_EVENT", {
443
493
  id: (n = t == null ? void 0 : t.id) == null ? e : n,
444
494
  haptic: e
445
495
  });
446
496
  } },
447
- _hostAPI: _
497
+ _hostAPI: C
448
498
  };
449
499
  };
450
500
  /** Walks settings UI components (recursing into split groups) collecting name → defaultValue pairs */
451
- function y(e) {
501
+ function T(e) {
452
502
  let t = {};
453
- for (let n of e) n.type === "split" ? Object.assign(t, y(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
503
+ for (let n of e) n.type === "split" ? Object.assign(t, T(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
454
504
  return t;
455
505
  }
456
506
  /**
@@ -465,7 +515,7 @@ function y(e) {
465
515
  * // Extend with dynamic disabled letters
466
516
  * sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
467
517
  */
468
- const b = {
518
+ const E = {
469
519
  layout: [
470
520
  "qwertyuiop",
471
521
  "asdfghjkl",
@@ -481,21 +531,21 @@ const b = {
481
531
  xl: [],
482
532
  l: ["↵", "⌫"],
483
533
  supportsDragCursor: !1
484
- }, x = (t) => {
534
+ }, D = (e) => {
485
535
  let n = {};
486
- for (let a of t) for (let t of a.keys) {
536
+ for (let a of e) for (let e of a.keys) {
487
537
  var r, i;
488
- let o = {}, s = e(e({}, (r = n[t]) == null ? void 0 : r.text), a.text), c = e(e({}, (i = n[t]) == null ? void 0 : i.background), a.background);
489
- Object.keys(s).length && (o.text = s), Object.keys(c).length && (o.background = c), n[t] = o;
538
+ let o = {}, s = t(t({}, (r = n[e]) == null ? void 0 : r.text), a.text), c = t(t({}, (i = n[e]) == null ? void 0 : i.background), a.background);
539
+ Object.keys(s).length && (o.text = s), Object.keys(c).length && (o.background = c), n[e] = o;
490
540
  }
491
541
  return n;
492
542
  };
493
543
  /** Custom error class for workshop import failures */
494
- var S = class extends Error {
544
+ var O = class extends Error {
495
545
  constructor(e, t, n) {
496
546
  super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
497
547
  }
498
548
  };
499
- export { S as EditorImportError, v as createPuzzmoSDK, b as defaultKeyboardConfig, x as keyStylesFromRules };
549
+ export { O as EditorImportError, w as createPuzzmoSDK, E as defaultKeyboardConfig, D as keyStylesFromRules };
500
550
 
501
551
  //# sourceMappingURL=index.js.map