@puzzmo/sdk 1.0.69 → 1.0.71

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 (37) hide show
  1. package/dist/analytics.d.ts +4 -0
  2. package/dist/analytics.d.ts.map +1 -1
  3. package/dist/bootstrapPayload.spec.d.ts +2 -0
  4. package/dist/bootstrapPayload.spec.d.ts.map +1 -0
  5. package/dist/{createSimulator-DUZOd1Hx.js → createSimulator-treFHkmV.js} +19 -18
  6. package/dist/{createSimulator-DUZOd1Hx.js.map → createSimulator-treFHkmV.js.map} +1 -1
  7. package/dist/{createSimulator-Ce3StrQI.cjs → createSimulator-uk8H5md8.cjs} +2 -2
  8. package/dist/{createSimulator-Ce3StrQI.cjs.map → createSimulator-uk8H5md8.cjs.map} +1 -1
  9. package/dist/gameTracker.d.ts.map +1 -1
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.cjs.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 +170 -158
  15. package/dist/index.js.map +1 -1
  16. package/dist/pico8/index.cjs.map +1 -1
  17. package/dist/pico8/index.d.ts +2 -2
  18. package/dist/pico8/index.d.ts.map +1 -1
  19. package/dist/pico8/index.js.map +1 -1
  20. package/dist/sdk.d.ts +13 -6
  21. package/dist/sdk.d.ts.map +1 -1
  22. package/dist/sdk.session.spec.d.ts +2 -0
  23. package/dist/sdk.session.spec.d.ts.map +1 -0
  24. package/dist/simulator/createSimulator.d.ts.map +1 -1
  25. package/dist/simulator/index.cjs +1 -1
  26. package/dist/simulator/index.js +1 -1
  27. package/dist/simulator/standalone.cjs +1 -1
  28. package/dist/simulator/standalone.js +1 -1
  29. package/dist/simulator/types.d.ts +5 -0
  30. package/dist/simulator/types.d.ts.map +1 -1
  31. package/dist/types.d.ts +2 -2
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/vite.cjs.map +1 -1
  34. package/dist/vite.d.ts +5 -0
  35. package/dist/vite.d.ts.map +1 -1
  36. package/dist/vite.js.map +1 -1
  37. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -70,8 +70,9 @@ var s = (e) => {
70
70
  };
71
71
  }();
72
72
  const l = (e) => {
73
- let t = {
74
- context: e,
73
+ var n;
74
+ let r = {
75
+ context: t(t({}, e), {}, { deviceType: (n = e.deviceType) == null ? u() : n }),
75
76
  updateCount: 0,
76
77
  startTime: /* @__PURE__ */ new Date(),
77
78
  tracked: {
@@ -82,31 +83,49 @@ const l = (e) => {
82
83
  }
83
84
  };
84
85
  return {
85
- trackEvent: (e, n) => {
86
- let r = ((/* @__PURE__ */ new Date()).getTime() - t.startTime.getTime()) / 1e3;
86
+ trackEvent: (e, t) => {
87
+ let n = ((/* @__PURE__ */ new Date()).getTime() - r.startTime.getTime()) / 1e3;
87
88
  switch (e) {
88
89
  case "READY_GAME_LOADED":
89
- t.tracked.pageView || (c(t.context, "page_view"), t.tracked.pageView = !0);
90
+ r.tracked.pageView || (c(r.context, "page_view"), r.tracked.pageView = !0);
90
91
  break;
91
92
  case "UPLOAD_NEW_GAME_STATE":
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));
93
+ r.updateCount++, r.updateCount > 2 && !r.tracked.gameplayActive && (c(r.context, "gameplay_active"), r.tracked.gameplayActive = !0), n > 30 && (r.tracked.gameplayActive || (c(r.context, "gameplay_active"), r.tracked.gameplayActive = !0), r.tracked.active30s || (c(r.context, "active_30s"), r.tracked.active30s = !0));
93
94
  break;
94
95
  case "GAME_COMPLETED":
95
- !t.tracked.completed && n != null && n.input && (c(t.context, "completed", {}, n.input.elapsedTimeSecs), t.tracked.completed = !0);
96
+ !r.tracked.completed && t != null && t.input && (c(r.context, "completed", {}, t.input.elapsedTimeSecs), r.tracked.completed = !0);
96
97
  break;
97
98
  }
98
99
  },
99
100
  trackLinkClick: (e) => {
100
- c(t.context, "link_click", e);
101
+ c(r.context, "link_click", e);
101
102
  }
102
103
  };
103
- }, u = (e) => {
104
- if (!g(e)) return null;
105
- let t = f();
104
+ };
105
+ /**
106
+ * The kind of device the game runs on, judged by the whole device rather than the game's frame. A copy of
107
+ * detectDeviceType in @puzzmo-com/clickhouse/deviceType, kept dependency-free for the published SDK.
108
+ */
109
+ var u = () => {
110
+ var e, t, n;
111
+ if (typeof navigator > "u" || typeof window > "u") return "unknown";
112
+ let r = navigator.userAgent;
113
+ if (/iPad/.test(r) || /Macintosh/.test(r) && navigator.maxTouchPoints > 1) return "tablet";
114
+ let i = (e = navigator.userAgentData) == null ? void 0 : e.mobile;
115
+ return /iPhone|iPod/.test(r) || i ? "mobile" : /Android/.test(r) ? /Mobile/.test(r) ? "mobile" : "tablet" : /Mobile|Windows Phone/.test(r) ? "mobile" : (t = (n = window).matchMedia) != null && t.call(n, "(pointer: coarse)").matches ? Math.min(screen.width, screen.height) < 600 ? "mobile" : "tablet" : "desktop";
116
+ };
117
+ /**
118
+ * Build the analytics tracker for a game, or null when analytics shouldn't run
119
+ * (the game doesn't bring its own runtime, no browser, running on localhost, or
120
+ * missing bootstrap data).
121
+ */
122
+ const d = (e) => {
123
+ if (!_(e)) return null;
124
+ let t = p();
106
125
  if (!t.enabled) return null;
107
- let n = p(e, t.apiRoot);
126
+ let n = m(e, t.apiRoot);
108
127
  return n ? l(n) : null;
109
- }, d = (e) => {
128
+ }, f = (e) => {
110
129
  if (typeof document > "u") return () => {};
111
130
  let t = (t) => {
112
131
  var n, r;
@@ -122,7 +141,7 @@ const l = (e) => {
122
141
  return document.addEventListener("click", t), () => document.removeEventListener("click", t);
123
142
  };
124
143
  /** Picks the events endpoint, and disables analytics entirely on localhost (dev + simulator). */
125
- var f = () => {
144
+ var p = () => {
126
145
  if (typeof window > "u" || !window.location) return {
127
146
  apiRoot: "",
128
147
  enabled: !1
@@ -137,40 +156,40 @@ var f = () => {
137
156
  };
138
157
  };
139
158
  /** Derive the analytics context from the host's bootstrap data, or null if a game isn't present. */
140
- const p = (e, t) => {
159
+ const m = (e, t) => {
141
160
  var n, r, i, a, o, s, c, l;
142
161
  let u = e == null ? void 0 : e.session;
143
162
  if (!u) return null;
144
- let d = u.gameplay, f = u.puzzle, p = (n = e == null ? void 0 : e.hostContext) == null ? [] : n, h = p.find((e) => (e == null ? void 0 : e.type) === "embed");
163
+ let d = u.gameplay, f = u.puzzle, p = (n = e == null ? void 0 : e.hostContext) == null ? [] : n, m = p.find((e) => (e == null ? void 0 : e.type) === "embed");
145
164
  return {
146
165
  gameSlug: (e == null || (r = e.game) == null ? void 0 : r.slug) || "unknown",
147
166
  puzzleID: f.id,
148
167
  gameplayOwnerID: d.ownerID || (e == null || (i = e.userState) == null ? void 0 : i.id) || "unknown",
149
168
  apiRoot: t,
150
- userType: m(e == null || (a = e.currentUser) == null ? void 0 : a.type),
151
- runtimeType: _(p),
169
+ userType: h(e == null || (a = e.currentUser) == null ? void 0 : a.type),
170
+ runtimeType: v(p),
152
171
  userID: e == null || (o = e.currentUser) == null ? void 0 : o.id,
153
172
  teamSlug: ((s = f.team) == null ? void 0 : s.slug) || void 0,
154
- partnerSlug: (h == null || (c = h.partner) == null ? void 0 : c.slug) || (e == null ? void 0 : e.partnerSlug) || void 0,
173
+ partnerSlug: (m == null || (c = m.partner) == null ? void 0 : c.slug) || (e == null ? void 0 : e.partnerSlug) || void 0,
155
174
  dailyDateKey: (l = f.mostRecentDaily) == null || (l = l.daily) == null ? void 0 : l.dateKey,
156
- embedID: (h == null ? void 0 : h.embedID) || void 0
175
+ embedID: (m == null ? void 0 : m.embedID) || void 0
157
176
  };
158
177
  };
159
178
  /** Map the user's subscription tier to the analytics user bucket. */
160
- var m = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user", h = 512, g = (e) => {
179
+ var h = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user", g = 512, _ = (e) => {
161
180
  var t, n;
162
- return (((t = e == null || (n = e.game) == null ? void 0 : n.version.flagsArr[0]) == null ? 0 : t) & h) === h;
163
- }, _ = (e) => {
181
+ return (((t = e == null || (n = e.game) == null ? void 0 : n.version.flagsArr[0]) == null ? 0 : t) & g) === g;
182
+ }, v = (e) => {
164
183
  let t = e.find((e) => (e == null ? void 0 : e.type) === "embed");
165
184
  if (t) return t.host === "msn" ? "msn" : "iframe";
166
185
  let n = e.find((e) => (e == null ? void 0 : e.type) === "app");
167
186
  return (n == null ? void 0 : n.host) === "__embed" ? "simple_embed" : (n == null ? void 0 : n.host) === "app-embed" ? "app_embed" : (n == null ? void 0 : n.host) === "ios-app" ? "ios_native" : "puzzmo_com";
168
- }, v = ["inputString"];
169
- function y(e) {
187
+ }, y = ["inputString"];
188
+ function b(e) {
170
189
  let t = e >= 3600 * 1e3;
171
190
  return new Date(e).toISOString().slice(t ? 11 : 14, -1).split(".")[0];
172
191
  }
173
- function b(e = 0, t = 0) {
192
+ function x(e = 0, t = 0) {
174
193
  let n = e, r = t, i = 0, a, o, s, c = () => {
175
194
  var e;
176
195
  if (o === void 0) return n + r;
@@ -217,11 +236,11 @@ function b(e = 0, t = 0) {
217
236
  isRunning: () => o !== void 0 && s === void 0,
218
237
  display: () => {
219
238
  let e = c() - r;
220
- return [y(Math.max(0, e)), r === 0 ? "" : y(r)];
239
+ return [b(Math.max(0, e)), r === 0 ? "" : b(r)];
221
240
  }
222
241
  };
223
242
  }
224
- function x() {
243
+ function S() {
225
244
  let e = /* @__PURE__ */ new Map();
226
245
  return typeof window < "u" && window.addEventListener("message", (t) => {
227
246
  var n;
@@ -251,13 +270,12 @@ function x() {
251
270
  };
252
271
  }
253
272
  /**
254
- * The host<->game contract this SDK is built against, declared in READY and READY_GAME_LOADED.
255
- * Stays "1.0" until every host supporting "1.1" is deployed: an older puzzmo.com reloads when it
256
- * sees a contract it doesn't know.
273
+ * The host<->game contract this SDK speaks, declared in READY and READY_GAME_LOADED: games read
274
+ * `game` and `session`, and handle `session` being absent. Hosts on "1.0" always send a session.
257
275
  */
258
- var S = "1.0", C = x();
276
+ var C = "1.1", w = S();
259
277
  /** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
260
- const w = (r = {}) => {
278
+ const T = (r = {}) => {
261
279
  var i;
262
280
  let a = null, s = null, c = () => {
263
281
  var e;
@@ -265,7 +283,7 @@ const w = (r = {}) => {
265
283
  }, l = () => {
266
284
  var e, t;
267
285
  return (e = (t = c()) == null ? void 0 : t.id) == null ? null : e;
268
- }, f = () => {
286
+ }, u = () => {
269
287
  var e, t;
270
288
  return (e = a == null || (t = a.session) == null ? void 0 : t.puzzle.puzzle) == null ? null : e;
271
289
  }, p = () => {
@@ -277,42 +295,47 @@ const w = (r = {}) => {
277
295
  }, h = () => {
278
296
  var e, t;
279
297
  return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
280
- }, g = /* @__PURE__ */ new Map(), _ = null, y = null, x = !1, w = (e, t) => {
281
- x || y == null || y.trackEvent(e, t);
282
- }, E = b(), D = null, O = null, k = () => {
283
- D || (D = setInterval(() => {
284
- if (E.isPaused()) return;
285
- let [e, t] = E.display();
286
- C.sendMessage("TIMER_TICK", { display: [e, t] });
287
- }, 500), O = setInterval(() => {
288
- E.isPaused() || C.sendMessage("TIMER_SYNC", Math.floor(E.timeWithoutPenaltySecs()));
298
+ }, g = !1, _ = (e) => {
299
+ if (g) return;
300
+ g = !0;
301
+ let t = a ? "the host sent no play session, so there is no gameplay to save to" : "it was called before gameReady() resolved";
302
+ console.warn(`[Puzzmo SDK] ${e}() was ignored: ${t}`);
303
+ }, v = /* @__PURE__ */ new Map(), b = null, S = null, T = !1, D = (e, t) => {
304
+ T || S == null || S.trackEvent(e, t);
305
+ }, O = x(), k = null, A = null, j = () => {
306
+ k || (k = setInterval(() => {
307
+ if (O.isPaused()) return;
308
+ let [e, t] = O.display();
309
+ w.sendMessage("TIMER_TICK", { display: [e, t] });
310
+ }, 500), A = setInterval(() => {
311
+ O.isPaused() || w.sendMessage("TIMER_SYNC", Math.floor(O.timeWithoutPenaltySecs()));
289
312
  }, 1e4));
290
- }, A = () => {
291
- D && (clearInterval(D), D = null), O && (clearInterval(O), O = null);
292
- }, j = (e, t) => {
293
- let n = g.get(e);
313
+ }, M = () => {
314
+ k && (clearInterval(k), k = null), A && (clearInterval(A), A = null);
315
+ }, N = (e, t) => {
316
+ let n = v.get(e);
294
317
  n && n.forEach((e) => e(t));
295
318
  };
296
- C.onMessage("START_GAME", () => {
297
- E._init(), k(), j("start");
319
+ w.onMessage("START_GAME", () => {
320
+ O._init(), j(), N("start");
298
321
  });
299
- let M = () => {
300
- let e = E.isPaused();
301
- E._pause(), E.isPaused() !== e && j("pause");
302
- }, N = () => {
303
- let e = E.isPaused();
304
- E._resume(), E.isPaused() !== e && j("resume");
322
+ let P = () => {
323
+ let e = O.isPaused();
324
+ O._pause(), O.isPaused() !== e && N("pause");
325
+ }, F = () => {
326
+ let e = O.isPaused();
327
+ O._resume(), O.isPaused() !== e && N("resume");
305
328
  };
306
- C.onMessage("PAUSE_GAME", M), C.onMessage("RESUME_GAME", N), C.onMessage("SETTINGS_UPDATE", (e) => {
307
- _ = t(t({}, _), e), j("settingsUpdate", _);
308
- }), 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", () => {
309
- E._reset(), A(), j("retry");
310
- }), C.onMessage("READY_DATA", (e) => {
329
+ w.onMessage("PAUSE_GAME", P), w.onMessage("RESUME_GAME", F), w.onMessage("SETTINGS_UPDATE", (e) => {
330
+ b = t(t({}, b), e), N("settingsUpdate", b);
331
+ }), w.onMessage("KEYBOARD_KEY_PRESS", (e) => N("keyboardKeyPress", e)), w.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => N("keyboardCursorChange", e)), w.onMessage("KEYBOARD_CURSOR_END", () => N("keyboardCursorEnd")), w.onMessage("RETRY_PUZZLE", () => {
332
+ O._reset(), M(), N("retry");
333
+ }), w.onMessage("READY_DATA", (e) => {
311
334
  var t;
312
335
  let n = o(e);
313
336
  a = n;
314
337
  let r = (t = n.session) == null ? void 0 : t.gameplay;
315
- if (_ === null) {
338
+ if (b === null) {
316
339
  var i, c;
317
340
  let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
318
341
  if (typeof t == "string") try {
@@ -320,142 +343,131 @@ const w = (r = {}) => {
320
343
  } catch (e) {
321
344
  t = null;
322
345
  }
323
- _ = (c = t) == null ? {} : c;
346
+ b = (c = t) == null ? {} : c;
324
347
  }
325
348
  if (r) {
326
- var l, f;
327
- let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((f = r.additionalTimeAddedSecs) == null ? 0 : f) * 1e3;
328
- E._reset(e, t);
349
+ var l, u;
350
+ let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((u = r.additionalTimeAddedSecs) == null ? 0 : u) * 1e3;
351
+ O._reset(e, t);
329
352
  }
330
- if (!y) {
353
+ if (!S) {
331
354
  var p;
332
- y = u(n), x = (p = r == null ? void 0 : r.completed) == null ? !1 : p, y && d((e) => y.trackLinkClick(e));
355
+ S = d(n), T = (p = r == null ? void 0 : r.completed) == null ? !1 : p, S && f((e) => S.trackLinkClick(e));
333
356
  }
334
357
  s && (s(n), s = null);
335
358
  });
336
- let P = {
337
- timeMs: () => E.timeMs(),
338
- timeSecs: () => E.timeSecs(),
339
- addedTimeMs: () => E.addedTimeMs(),
340
- addedTimeSecs: () => E.addedTimeSecs(),
341
- timeWithoutPenaltySecs: () => E.timeWithoutPenaltySecs(),
342
- display: () => E.display(),
343
- addPenalty: (e) => E.addPenalty(e),
344
- setPenalty: (e) => E.setPenalty(e),
345
- isPaused: () => E.isPaused(),
346
- isRunning: () => E.isRunning(),
347
- pause: M,
348
- resume: N
349
- }, F = {
350
- send: (e, t) => C.sendMessage(e, t),
351
- on: (e, t) => C.onMessage(e, t),
352
- timer: P,
359
+ let I = {
360
+ timeMs: () => O.timeMs(),
361
+ timeSecs: () => O.timeSecs(),
362
+ addedTimeMs: () => O.addedTimeMs(),
363
+ addedTimeSecs: () => O.addedTimeSecs(),
364
+ timeWithoutPenaltySecs: () => O.timeWithoutPenaltySecs(),
365
+ display: () => O.display(),
366
+ addPenalty: (e) => O.addPenalty(e),
367
+ setPenalty: (e) => O.setPenalty(e),
368
+ isPaused: () => O.isPaused(),
369
+ isRunning: () => O.isRunning(),
370
+ pause: P,
371
+ resume: F
372
+ }, L = {
373
+ send: (e, t) => w.sendMessage(e, t),
374
+ on: (e, t) => w.onMessage(e, t),
375
+ timer: I,
353
376
  bootstrap: () => a
354
- }, I = {};
355
- for (let e of (i = r.plugins) == null ? [] : i) I[e.name] = e.setup(F);
377
+ }, R = {};
378
+ for (let e of (i = r.plugins) == null ? [] : i) R[e.name] = e.setup(L);
356
379
  return {
357
- timer: P,
358
- plugins: I,
380
+ timer: I,
381
+ plugins: R,
359
382
  gameReady: function() {
360
383
  var e = n(function* () {
361
- var e;
362
- if (C.sendMessage("READY", { runtimeContract: S }), f()) {
363
- let e = p();
364
- return {
365
- puzzleString: f(),
366
- inputString: e,
367
- boardState: e,
368
- theme: m(),
369
- completed: h(),
370
- readyData: a
371
- };
384
+ if (w.sendMessage("READY", { runtimeContract: C }), !a) {
385
+ var e;
386
+ let t = (e = r.timeout) == null ? 5e3 : e;
387
+ yield new Promise((e, n) => {
388
+ s = e, setTimeout(() => {
389
+ s && (s = null, n(/* @__PURE__ */ Error(`Timeout waiting for READY_DATA after ${t}ms`)));
390
+ }, t);
391
+ });
372
392
  }
373
- let t = (e = r.timeout) == null ? 5e3 : e;
374
- yield new Promise((e, n) => {
375
- s = e, setTimeout(() => {
376
- s && (s = null, n(/* @__PURE__ */ Error(`Timeout waiting for READY_DATA after ${t}ms`)));
377
- }, t);
378
- });
379
- let n = f();
380
- if (!n) throw Error("READY_DATA received but no puzzle data found");
381
- let i = p();
382
- return {
383
- puzzleString: n,
384
- inputString: i,
385
- boardState: i,
393
+ let n = p();
394
+ return t(t({}, {
395
+ puzzleString: u(),
396
+ inputString: n,
386
397
  theme: m(),
387
398
  completed: h(),
388
399
  readyData: a
389
- };
400
+ }), {}, { boardState: n });
390
401
  });
391
402
  return function() {
392
403
  return e.apply(this, arguments);
393
404
  };
394
405
  }(),
395
406
  gameLoaded: (e = {}) => {
396
- C.sendMessage("READY_GAME_LOADED", {
407
+ w.sendMessage("READY_GAME_LOADED", {
397
408
  state: e,
398
- gameRuntimeContract: S,
409
+ gameRuntimeContract: C,
399
410
  embedRuntimeContract: "1.0"
400
- }), w("READY_GAME_LOADED");
411
+ }), D("READY_GAME_LOADED");
401
412
  },
402
- on: (e, t) => (g.has(e) || g.set(e, /* @__PURE__ */ new Set()), g.get(e).add(t), () => {
413
+ on: (e, t) => (v.has(e) || v.set(e, /* @__PURE__ */ new Set()), v.get(e).add(t), () => {
403
414
  var n;
404
- (n = g.get(e)) == null || n.delete(t);
415
+ (n = v.get(e)) == null || n.delete(t);
405
416
  }),
406
417
  off: (e, t) => {
407
418
  var n;
408
- (n = g.get(e)) == null || n.delete(t);
419
+ (n = v.get(e)) == null || n.delete(t);
409
420
  },
410
421
  updateGameState: (e, t) => {
411
422
  var n, r;
412
423
  let i = l();
413
- i && (C.sendMessage("UPLOAD_NEW_GAME_STATE", {
424
+ if (!i) return _("updateGameState");
425
+ w.sendMessage("UPLOAD_NEW_GAME_STATE", {
414
426
  id: i,
415
427
  input: {
416
428
  boardState: e,
417
- elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? E.timeWithoutPenaltySecs() : n,
418
- additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? E.addedTimeSecs() : r,
429
+ elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? O.timeWithoutPenaltySecs() : n,
430
+ additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? O.addedTimeSecs() : r,
419
431
  collabUserReferences: []
420
432
  }
421
- }), w("UPLOAD_NEW_GAME_STATE"));
433
+ }), D("UPLOAD_NEW_GAME_STATE");
422
434
  },
423
435
  gameCompleted: (n, r) => {
424
- var i, a, o, s, c;
425
- E._conclude(), A();
426
- let { inputString: u } = n, d = t(t({}, e(n, v)), {}, {
427
- boardState: u == null ? n.boardState : u,
428
- elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? E.timeWithoutPenaltySecs() : i,
429
- additionalTimeAddedSecs: (a = n.additionalTimeAddedSecs) == null ? E.addedTimeSecs() : a
430
- }), f = (o = r == null ? void 0 : r.deeds) == null ? [] : o;
431
- f.push({
436
+ var i, o, s, c, u;
437
+ O._conclude(), M();
438
+ let { inputString: d } = n, f = t(t({}, e(n, y)), {}, {
439
+ boardState: d == null ? n.boardState : d,
440
+ elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? O.timeWithoutPenaltySecs() : i,
441
+ additionalTimeAddedSecs: (o = n.additionalTimeAddedSecs) == null ? O.addedTimeSecs() : o
442
+ }), p = (s = r == null ? void 0 : r.deeds) == null ? [] : s;
443
+ p.push({
432
444
  id: "points",
433
445
  value: n.pointsAwarded
434
- }), f.push({
446
+ }), p.push({
435
447
  id: "time",
436
- value: Math.round((s = d.elapsedTimeSecs) == null ? 0 : s) + Math.round((c = d.additionalTimeAddedSecs) == null ? 0 : c)
448
+ value: Math.round((c = f.elapsedTimeSecs) == null ? 0 : c) + Math.round((u = f.additionalTimeAddedSecs) == null ? 0 : u)
437
449
  });
438
- let p = l();
439
- p && (C.sendMessage("GAME_COMPLETED", {
440
- id: p,
441
- input: d,
450
+ let m = l(), h = a && !a.session && a.appRuntimeContract === "1.1";
451
+ m || h ? (w.sendMessage("GAME_COMPLETED", {
452
+ id: m == null ? void 0 : m,
453
+ input: f,
442
454
  config: r
443
- }), w("GAME_COMPLETED", { input: d }));
455
+ }), D("GAME_COMPLETED", { input: f })) : _("gameCompleted");
444
456
  },
445
457
  showCompletionScreen: (e) => {
446
- C.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
458
+ w.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
447
459
  results: e,
448
460
  showRetry: !0
449
461
  });
450
462
  },
451
463
  hitCheckpoint: (e, t, n) => {
452
464
  var r;
453
- if (!l()) return;
465
+ if (!l()) return _("hitCheckpoint");
454
466
  let i = (r = p()) == null ? "" : r, a = {
455
- elapsedTimeSecs: E.timeWithoutPenaltySecs(),
456
- additionalTimeAddedSecs: E.addedTimeSecs()
467
+ elapsedTimeSecs: O.timeWithoutPenaltySecs(),
468
+ additionalTimeAddedSecs: O.addedTimeSecs()
457
469
  };
458
- C.sendMessage("HIT_CHECKPOINT", {
470
+ w.sendMessage("HIT_CHECKPOINT", {
459
471
  checkpointName: e,
460
472
  gameplay: {
461
473
  inputStr: i,
@@ -466,22 +478,22 @@ const w = (r = {}) => {
466
478
  });
467
479
  },
468
480
  settings: {
469
- initialize: (e) => (_ = t(t({}, T(e)), _), C.sendMessage("INITIALIZE_SETTINGS", {
481
+ initialize: (e) => (b = t(t({}, E(e)), b), w.sendMessage("INITIALIZE_SETTINGS", {
470
482
  components: e,
471
- settings: _
472
- }), _),
483
+ settings: b
484
+ }), b),
473
485
  get: () => {
474
486
  var e;
475
- return (e = _) == null ? {} : e;
487
+ return (e = b) == null ? {} : e;
476
488
  },
477
- update: (e) => (_ = t(t({}, _), e), C.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: _ }), _)
489
+ update: (e) => (b = t(t({}, b), e), w.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: b }), b)
478
490
  },
479
491
  keyboard: {
480
492
  show: (e) => {
481
- C.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
493
+ w.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
482
494
  },
483
495
  hide: () => {
484
- C.sendMessage("KEYBOARD_UPDATE_CONFIG", {
496
+ w.sendMessage("KEYBOARD_UPDATE_CONFIG", {
485
497
  layout: [],
486
498
  symbols: {},
487
499
  highlight: [],
@@ -494,18 +506,18 @@ const w = (r = {}) => {
494
506
  },
495
507
  haptics: { play: (e, t) => {
496
508
  var n;
497
- C.sendMessage("SENSORY_EVENT", {
509
+ w.sendMessage("SENSORY_EVENT", {
498
510
  id: (n = t == null ? void 0 : t.id) == null ? e : n,
499
511
  haptic: e
500
512
  });
501
513
  } },
502
- _hostAPI: C
514
+ _hostAPI: w
503
515
  };
504
516
  };
505
517
  /** Walks settings UI components (recursing into split groups) collecting name → defaultValue pairs */
506
- function T(e) {
518
+ function E(e) {
507
519
  let t = {};
508
- for (let n of e) n.type === "split" ? Object.assign(t, T(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
520
+ for (let n of e) n.type === "split" ? Object.assign(t, E(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
509
521
  return t;
510
522
  }
511
523
  /**
@@ -520,7 +532,7 @@ function T(e) {
520
532
  * // Extend with dynamic disabled letters
521
533
  * sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
522
534
  */
523
- const E = {
535
+ const D = {
524
536
  layout: [
525
537
  "qwertyuiop",
526
538
  "asdfghjkl",
@@ -536,7 +548,7 @@ const E = {
536
548
  xl: [],
537
549
  l: ["↵", "⌫"],
538
550
  supportsDragCursor: !1
539
- }, D = (e) => {
551
+ }, O = (e) => {
540
552
  let n = {};
541
553
  for (let a of e) for (let e of a.keys) {
542
554
  var r, i;
@@ -546,11 +558,11 @@ const E = {
546
558
  return n;
547
559
  };
548
560
  /** Custom error class for workshop import failures */
549
- var O = class extends Error {
561
+ var k = class extends Error {
550
562
  constructor(e, t, n) {
551
563
  super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
552
564
  }
553
565
  };
554
- export { O as EditorImportError, w as createPuzzmoSDK, E as defaultKeyboardConfig, D as keyStylesFromRules };
566
+ export { k as EditorImportError, T as createPuzzmoSDK, D as defaultKeyboardConfig, O as keyStylesFromRules };
555
567
 
556
568
  //# sourceMappingURL=index.js.map