@puzzmo/sdk 1.0.79 → 1.0.81

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.
package/dist/index.js CHANGED
@@ -184,12 +184,12 @@ var h = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user
184
184
  if (t) return t.host === "msn" ? "msn" : "iframe";
185
185
  let n = e.find((e) => (e == null ? void 0 : e.type) === "app");
186
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";
187
- }, y = ["inputString"];
188
- function b(e) {
187
+ }, y = ["inputString"], b = ["omit"];
188
+ function x(e) {
189
189
  let t = e >= 3600 * 1e3;
190
190
  return new Date(e).toISOString().slice(t ? 11 : 14, -1).split(".")[0];
191
191
  }
192
- function x(e = 0, t = 0) {
192
+ function S(e = 0, t = 0) {
193
193
  let n = e, r = t, i = 0, a, o, s, c = () => {
194
194
  var e;
195
195
  if (o === void 0) return n + r;
@@ -236,12 +236,12 @@ function x(e = 0, t = 0) {
236
236
  isRunning: () => o !== void 0 && s === void 0,
237
237
  display: () => {
238
238
  let e = c() - r;
239
- return [b(Math.max(0, e)), r === 0 ? "" : b(r)];
239
+ return [x(Math.max(0, e)), r === 0 ? "" : x(r)];
240
240
  }
241
241
  };
242
242
  }
243
- function S() {
244
- let e = /* @__PURE__ */ new Map();
243
+ function C() {
244
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
245
245
  return typeof window < "u" && window.addEventListener("message", (t) => {
246
246
  var n;
247
247
  if (!(!(t == null || (n = t.data) == null) && n.type)) return;
@@ -252,20 +252,30 @@ function S() {
252
252
  r !== "TIMER_TICK" && r !== "TIMER_SYNC" && console.log("[Puzzmo SDK] received:", r, e), i.forEach((t) => t(e));
253
253
  }
254
254
  }), {
255
- sendMessage: (e, t) => {
256
- var n, r;
257
- let i = {
255
+ sendMessage: (e, n) => {
256
+ var r, i, a;
257
+ let o = {
258
258
  type: e,
259
- json: t,
259
+ json: n,
260
260
  _: "p",
261
261
  __: "mp",
262
262
  private: !0
263
263
  };
264
- "parent" in window && window.parent !== window && window.parent.postMessage(i, "*"), window.postMessage(i, "*"), "webkit" in window && !((n = window.webkit) == null || (n = n.messageHandlers) == null) && n.app && window.webkit.messageHandlers.app.postMessage(i), "puzzmoMessageString" in window && window.puzzmoMessageString(JSON.stringify(i)), "ReactNativeWebView" in window && (r = window.ReactNativeWebView) != null && r.postMessage && window.ReactNativeWebView.postMessage(JSON.stringify(i)), e !== "TIMER_TICK" && e !== "TIMER_SYNC" && console.log("[Puzzmo SDK] sent:", e, t);
264
+ "parent" in window && window.parent !== window && window.parent.postMessage(o, "*"), window.postMessage(o, "*"), "webkit" in window && !((r = window.webkit) == null || (r = r.messageHandlers) == null) && r.app && window.webkit.messageHandlers.app.postMessage(o), "puzzmoMessageString" in window && window.puzzmoMessageString(JSON.stringify(o)), "ReactNativeWebView" in window && (i = window.ReactNativeWebView) != null && i.postMessage && window.ReactNativeWebView.postMessage(JSON.stringify(o)), e !== "TIMER_TICK" && e !== "TIMER_SYNC" && console.log("[Puzzmo SDK] sent:", e, n), (a = t.get(e)) == null || a.forEach((t) => {
265
+ try {
266
+ t(n);
267
+ } catch (t) {
268
+ console.error(`[Puzzmo SDK] a watcher of ${e} threw:`, t);
269
+ }
270
+ });
265
271
  },
266
272
  onMessage: (t, n) => (e.has(t) || e.set(t, /* @__PURE__ */ new Set()), e.get(t).add(n), () => {
267
273
  var r;
268
274
  (r = e.get(t)) == null || r.delete(n);
275
+ }),
276
+ onSend: (e, n) => (t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(n), () => {
277
+ var r;
278
+ (r = t.get(e)) == null || r.delete(n);
269
279
  })
270
280
  };
271
281
  }
@@ -273,9 +283,9 @@ function S() {
273
283
  * The host<->game contract this SDK speaks, declared in READY and READY_GAME_LOADED: games read
274
284
  * `game` and `session`, and handle `session` being absent. Hosts on "1.0" always send a session.
275
285
  */
276
- var C = "1.1", w = S(), T = 1e4;
286
+ var w = "1.1", T = C(), E = 1e4;
277
287
  /** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
278
- const E = (r = {}) => {
288
+ const D = (r = {}) => {
279
289
  var i;
280
290
  let a = null, s = null, c = () => {
281
291
  var e;
@@ -295,55 +305,55 @@ const E = (r = {}) => {
295
305
  }, h = null, g = 0, _ = 0, v = !1, b = () => {
296
306
  var e, t;
297
307
  return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
298
- }, S = !1, E = (e) => {
299
- if (S) return;
300
- S = !0;
308
+ }, x = !1, C = (e) => {
309
+ if (x) return;
310
+ x = !0;
301
311
  let t = a ? "the host sent no play session, so there is no gameplay to save to" : "it was called before gameReady() resolved";
302
312
  console.warn(`[Puzzmo SDK] ${e}() was ignored: ${t}`);
303
- }, k = /* @__PURE__ */ new Map(), A = null, j = null, M = !1, N = (e, t) => {
304
- M || j == null || j.trackEvent(e, t);
305
- }, P = x(), F = null, I = null, L = () => {
306
- F || (F = setInterval(() => {
307
- if (P.isPaused()) return;
308
- let [e, t] = P.display();
309
- w.sendMessage("TIMER_TICK", { display: [e, t] });
310
- }, 500), I = setInterval(() => {
311
- P.isPaused() || w.sendMessage("TIMER_SYNC", Math.floor(P.timeWithoutPenaltySecs()));
313
+ }, D = /* @__PURE__ */ new Map(), M = null, N = [], P = {}, F = () => t(t({}, M), P), I = null, L = !1, R = (e, t) => {
314
+ L || I == null || I.trackEvent(e, t);
315
+ }, z = S(), B = null, V = null, H = () => {
316
+ B || (B = setInterval(() => {
317
+ if (z.isPaused()) return;
318
+ let [e, t] = z.display();
319
+ T.sendMessage("TIMER_TICK", { display: [e, t] });
320
+ }, 500), V = setInterval(() => {
321
+ z.isPaused() || T.sendMessage("TIMER_SYNC", Math.floor(z.timeWithoutPenaltySecs()));
312
322
  }, 1e4));
313
- }, R = () => {
314
- F && (clearInterval(F), F = null), I && (clearInterval(I), I = null);
315
- }, z = (e, t) => {
316
- let n = k.get(e);
323
+ }, U = () => {
324
+ B && (clearInterval(B), B = null), V && (clearInterval(V), V = null);
325
+ }, W = (e, t) => {
326
+ let n = D.get(e);
317
327
  n && n.forEach((e) => e(t));
318
328
  };
319
- w.onMessage("START_GAME", () => {
320
- P._init(), L(), z("start");
329
+ T.onMessage("START_GAME", () => {
330
+ z._init(), H(), W("start");
321
331
  });
322
- let B = () => {
323
- let e = P.isPaused();
324
- P._pause(), P.isPaused() !== e && z("pause");
325
- }, V = () => {
326
- let e = P.isPaused();
327
- P._resume(), P.isPaused() !== e && z("resume");
332
+ let G = () => {
333
+ let e = z.isPaused();
334
+ z._pause(), z.isPaused() !== e && W("pause");
335
+ }, K = () => {
336
+ let e = z.isPaused();
337
+ z._resume(), z.isPaused() !== e && W("resume");
328
338
  };
329
- w.onMessage("PAUSE_GAME", B), w.onMessage("RESUME_GAME", V), w.onMessage("SETTINGS_UPDATE", (e) => {
330
- A = t(t({}, A), e), z("settingsUpdate", A);
331
- }), w.onMessage("KEYBOARD_KEY_PRESS", (e) => z("keyboardKeyPress", e)), w.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => z("keyboardCursorChange", e)), w.onMessage("KEYBOARD_CURSOR_END", () => z("keyboardCursorEnd")), w.onMessage("ACHIEVEMENTS_UNLOCKED", (e) => z("achievementsUnlocked", e));
332
- let H = /* @__PURE__ */ new Map(), U = 0;
333
- w.onMessage("PUZZLE_DATA", (e) => {
334
- let t = H.get(e.nonce);
335
- t && (H.delete(e.nonce), "failed" in e ? t.reject(Error(e.error)) : t.resolve({
339
+ T.onMessage("PAUSE_GAME", G), T.onMessage("RESUME_GAME", K), T.onMessage("SETTINGS_UPDATE", (e) => {
340
+ M = t(t({}, M), e), W("settingsUpdate", F());
341
+ }), T.onMessage("KEYBOARD_KEY_PRESS", (e) => W("keyboardKeyPress", e)), T.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => W("keyboardCursorChange", e)), T.onMessage("KEYBOARD_CURSOR_END", () => W("keyboardCursorEnd")), T.onMessage("ACHIEVEMENTS_UNLOCKED", (e) => W("achievementsUnlocked", e));
342
+ let q = /* @__PURE__ */ new Map(), J = 0;
343
+ T.onMessage("PUZZLE_DATA", (e) => {
344
+ let t = q.get(e.nonce);
345
+ t && (q.delete(e.nonce), "failed" in e ? t.reject(Error(e.error)) : t.resolve({
336
346
  puzzleKey: e.puzzle.key,
337
347
  puzzleString: e.puzzle.puzzle
338
348
  }));
339
- }), w.onMessage("RETRY_PUZZLE", () => {
340
- P._reset(), R(), z("retry");
341
- }), w.onMessage("READY_DATA", (e) => {
349
+ }), T.onMessage("RETRY_PUZZLE", () => {
350
+ z._reset(), U(), W("retry");
351
+ }), T.onMessage("READY_DATA", (e) => {
342
352
  var t;
343
353
  let n = o(e);
344
354
  a = n;
345
355
  let r = (t = n.session) == null ? void 0 : t.gameplay;
346
- if (A === null) {
356
+ if (M === null) {
347
357
  var i, c;
348
358
  let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
349
359
  if (typeof t == "string") try {
@@ -351,46 +361,47 @@ const E = (r = {}) => {
351
361
  } catch (e) {
352
362
  t = null;
353
363
  }
354
- A = (c = t) == null ? {} : c;
364
+ M = (c = t) == null ? {} : c;
355
365
  }
356
366
  if (r) {
357
367
  var l, u;
358
368
  let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((u = r.additionalTimeAddedSecs) == null ? 0 : u) * 1e3;
359
- P._reset(e, t);
369
+ z._reset(e, t);
360
370
  }
361
- if (!j) {
371
+ if (!I) {
362
372
  var p;
363
- j = d(n), M = (p = r == null ? void 0 : r.completed) == null ? !1 : p, j && f((e) => j.trackLinkClick(e));
373
+ I = d(n), L = (p = r == null ? void 0 : r.completed) == null ? !1 : p, I && f((e) => I.trackLinkClick(e));
364
374
  }
365
375
  s && (s(n), s = null);
366
376
  });
367
- let W = {
368
- timeMs: () => P.timeMs(),
369
- timeSecs: () => P.timeSecs(),
370
- addedTimeMs: () => P.addedTimeMs(),
371
- addedTimeSecs: () => P.addedTimeSecs(),
372
- timeWithoutPenaltySecs: () => P.timeWithoutPenaltySecs(),
373
- display: () => P.display(),
374
- addPenalty: (e) => P.addPenalty(e),
375
- setPenalty: (e) => P.setPenalty(e),
376
- isPaused: () => P.isPaused(),
377
- isRunning: () => P.isRunning(),
378
- pause: B,
379
- resume: V
380
- }, G = {
381
- send: (e, t) => w.sendMessage(e, t),
382
- on: (e, t) => w.onMessage(e, t),
383
- timer: W,
377
+ let Y = {
378
+ timeMs: () => z.timeMs(),
379
+ timeSecs: () => z.timeSecs(),
380
+ addedTimeMs: () => z.addedTimeMs(),
381
+ addedTimeSecs: () => z.addedTimeSecs(),
382
+ timeWithoutPenaltySecs: () => z.timeWithoutPenaltySecs(),
383
+ display: () => z.display(),
384
+ addPenalty: (e) => z.addPenalty(e),
385
+ setPenalty: (e) => z.setPenalty(e),
386
+ isPaused: () => z.isPaused(),
387
+ isRunning: () => z.isRunning(),
388
+ pause: G,
389
+ resume: K
390
+ }, X = {
391
+ send: (e, t) => T.sendMessage(e, t),
392
+ on: (e, t) => T.onMessage(e, t),
393
+ onSend: T.onSend,
394
+ timer: Y,
384
395
  bootstrap: () => a
385
- }, K = {};
386
- for (let e of (i = r.plugins) == null ? [] : i) K[e.name] = e.setup(G);
396
+ }, Z = {};
397
+ for (let e of (i = r.plugins) == null ? [] : i) Z[e.name] = e.setup(X);
387
398
  return {
388
- timer: W,
389
- plugins: K,
399
+ timer: Y,
400
+ plugins: Z,
390
401
  gameReady: function() {
391
402
  var e = n(function* () {
392
403
  var e, n;
393
- if (w.sendMessage("READY", { runtimeContract: C }), !a) {
404
+ if (T.sendMessage("READY", { runtimeContract: w }), !a) {
394
405
  var i;
395
406
  let e = (i = r.timeout) == null ? 5e3 : i;
396
407
  yield new Promise((t, n) => {
@@ -415,41 +426,41 @@ const E = (r = {}) => {
415
426
  };
416
427
  }(),
417
428
  gameLoaded: (e = {}) => {
418
- w.sendMessage("READY_GAME_LOADED", {
429
+ T.sendMessage("READY_GAME_LOADED", {
419
430
  state: e,
420
- gameRuntimeContract: C,
431
+ gameRuntimeContract: w,
421
432
  embedRuntimeContract: "1.0"
422
- }), N("READY_GAME_LOADED");
433
+ }), R("READY_GAME_LOADED");
423
434
  },
424
- on: (e, t) => (k.has(e) || k.set(e, /* @__PURE__ */ new Set()), k.get(e).add(t), () => {
435
+ on: (e, t) => (D.has(e) || D.set(e, /* @__PURE__ */ new Set()), D.get(e).add(t), () => {
425
436
  var n;
426
- (n = k.get(e)) == null || n.delete(t);
437
+ (n = D.get(e)) == null || n.delete(t);
427
438
  }),
428
439
  off: (e, t) => {
429
440
  var n;
430
- (n = k.get(e)) == null || n.delete(t);
441
+ (n = D.get(e)) == null || n.delete(t);
431
442
  },
432
443
  updateGameState: (e, t) => {
433
444
  var n, r;
434
445
  let i = l();
435
- if (!i) return E("updateGameState");
436
- w.sendMessage("UPLOAD_NEW_GAME_STATE", {
446
+ if (!i) return C("updateGameState");
447
+ T.sendMessage("UPLOAD_NEW_GAME_STATE", {
437
448
  id: i,
438
449
  input: {
439
450
  boardState: e,
440
- elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? P.timeWithoutPenaltySecs() : n,
441
- additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? P.addedTimeSecs() : r,
451
+ elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? z.timeWithoutPenaltySecs() : n,
452
+ additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? z.addedTimeSecs() : r,
442
453
  collabUserReferences: []
443
454
  }
444
- }), N("UPLOAD_NEW_GAME_STATE");
455
+ }), R("UPLOAD_NEW_GAME_STATE");
445
456
  },
446
457
  gameCompleted: (n, r) => {
447
458
  var i, o, s, c, u;
448
- P._conclude(), R();
459
+ z._conclude(), U();
449
460
  let { inputString: d } = n, f = t(t({}, e(n, y)), {}, {
450
461
  boardState: d == null ? n.boardState : d,
451
- elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? P.timeWithoutPenaltySecs() : i,
452
- additionalTimeAddedSecs: (o = n.additionalTimeAddedSecs) == null ? P.addedTimeSecs() : o
462
+ elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? z.timeWithoutPenaltySecs() : i,
463
+ additionalTimeAddedSecs: (o = n.additionalTimeAddedSecs) == null ? z.addedTimeSecs() : o
453
464
  }), p = (s = r == null ? void 0 : r.deeds) == null ? [] : s;
454
465
  p.push({
455
466
  id: "points",
@@ -459,26 +470,26 @@ const E = (r = {}) => {
459
470
  value: Math.round((c = f.elapsedTimeSecs) == null ? 0 : c) + Math.round((u = f.additionalTimeAddedSecs) == null ? 0 : u)
460
471
  });
461
472
  let m = l(), h = a && !a.session && a.appRuntimeContract === "1.1";
462
- m || h ? (w.sendMessage("GAME_COMPLETED", {
473
+ m || h ? (T.sendMessage("GAME_COMPLETED", {
463
474
  id: m == null ? void 0 : m,
464
475
  input: f,
465
476
  config: r
466
- }), N("GAME_COMPLETED", { input: f })) : E("gameCompleted");
477
+ }), R("GAME_COMPLETED", { input: f })) : C("gameCompleted");
467
478
  },
468
479
  showCompletionScreen: (e) => {
469
- w.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
480
+ T.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
470
481
  results: e,
471
482
  showRetry: !0
472
483
  });
473
484
  },
474
485
  hitCheckpoint: (e, t, n) => {
475
486
  var r;
476
- if (!l()) return E("hitCheckpoint");
487
+ if (!l()) return C("hitCheckpoint");
477
488
  let i = (r = p()) == null ? "" : r, a = {
478
- elapsedTimeSecs: P.timeWithoutPenaltySecs(),
479
- additionalTimeAddedSecs: P.addedTimeSecs()
489
+ elapsedTimeSecs: z.timeWithoutPenaltySecs(),
490
+ additionalTimeAddedSecs: z.addedTimeSecs()
480
491
  };
481
- w.sendMessage("HIT_CHECKPOINT", {
492
+ T.sendMessage("HIT_CHECKPOINT", {
482
493
  checkpointName: e,
483
494
  gameplay: {
484
495
  inputStr: i,
@@ -490,41 +501,44 @@ const E = (r = {}) => {
490
501
  },
491
502
  completeRepeatableRun: (e, n) => {
492
503
  var r, i;
493
- let a = P.timeWithoutPenaltySecs(), o = a >= g ? a - g : a;
504
+ let a = z.timeWithoutPenaltySecs(), o = a >= g ? a - g : a;
494
505
  g = a;
495
506
  let s = Math.round((r = e == null ? void 0 : e.elapsedTimeSecs) == null ? o : r), c = [...((i = n == null ? void 0 : n.deeds) == null ? [] : i).filter((e) => e.id !== "time"), {
496
507
  id: "time",
497
508
  value: s
498
509
  }], l = e == null ? void 0 : e.puzzleKey;
499
- w.sendMessage("COMPLETE_REPEATABLE_RUN", { input: t({
510
+ T.sendMessage("COMPLETE_REPEATABLE_RUN", { input: t({
500
511
  deedValues: c,
501
512
  elapsedTimeSecs: s
502
- }, l ? { puzzleKey: l } : {}) }), N("COMPLETE_REPEATABLE_RUN", { elapsedTimeSecs: s });
513
+ }, l ? { puzzleKey: l } : {}) }), R("COMPLETE_REPEATABLE_RUN", { elapsedTimeSecs: s });
503
514
  },
504
515
  rounds: {
505
516
  start: (e) => {
506
- _ = 0, w.sendMessage("START_REPEATABLE_ROUND", t({ reason: e.reason }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
517
+ _ = 0, T.sendMessage("START_REPEATABLE_ROUND", t({ reason: e.reason }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
507
518
  },
508
519
  resume: (e) => {
509
- _ = e.events.length, w.sendMessage("RESUME_REPEATABLE_ROUND", t({ events: e.events.map((e) => [...e]) }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
520
+ _ = e.events.length, T.sendMessage("RESUME_REPEATABLE_ROUND", t({ events: e.events.map((e) => [...e]) }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
510
521
  },
511
522
  log: (...e) => {
512
- e.length && (w.sendMessage("APPEND_REPEATABLE_ROUND_LOG", {
523
+ e.length && (T.sendMessage("APPEND_REPEATABLE_ROUND_LOG", {
513
524
  from: _,
514
525
  events: e.map((e) => [...e])
515
526
  }), _ += e.length);
516
527
  }
517
528
  },
529
+ table: { updateGameState: (e, n) => {
530
+ T.sendMessage("UPDATE_TABLE_GAME_STATE", t({ inputString: e }, (n == null ? void 0 : n.puzzleString) === void 0 ? {} : { puzzleString: n.puzzleString }));
531
+ } },
518
532
  requestPuzzle: (e) => new Promise((t, n) => {
519
- let r = `puzzle-${++U}`, i = setTimeout(() => {
520
- H.delete(r) && n(/* @__PURE__ */ Error(`Timeout waiting for PUZZLE_DATA after ${T}ms`));
521
- }, T), a = (e) => (t) => {
533
+ let r = `puzzle-${++J}`, i = setTimeout(() => {
534
+ q.delete(r) && n(/* @__PURE__ */ Error(`Timeout waiting for PUZZLE_DATA after ${E}ms`));
535
+ }, E), a = (e) => (t) => {
522
536
  clearTimeout(i), e(t);
523
537
  };
524
- H.set(r, {
538
+ q.set(r, {
525
539
  resolve: a(t),
526
540
  reject: a(n)
527
- }), w.sendMessage("REQUEST_PUZZLE", {
541
+ }), T.sendMessage("REQUEST_PUZZLE", {
528
542
  nonce: r,
529
543
  buckets: e != null && e.buckets ? [...e.buckets] : void 0,
530
544
  exclude: e != null && e.exclude ? [...e.exclude] : void 0
@@ -541,34 +555,40 @@ const E = (r = {}) => {
541
555
  },
542
556
  set: (e, t = 1) => {
543
557
  let n = new TextEncoder().encode(e).length;
544
- if (n > O) throw Error(`[sdk.storage] State is ${n} bytes, over the ${O} byte cap`);
558
+ if (n > j) throw Error(`[sdk.storage] State is ${n} bytes, over the ${j} byte cap`);
545
559
  if (!Number.isInteger(t) || t < 1) throw Error("[sdk.storage] stateVersion must be a positive integer");
546
560
  a && !a.repeatable && !v && (v = !0, console.warn("[sdk.storage] Only repeat play saves storage for now; this write lasts until the page reloads")), h = {
547
561
  state: e,
548
562
  stateVersion: t
549
- }, w.sendMessage("UPDATE_GAME_USER_STATE", {
563
+ }, T.sendMessage("UPDATE_GAME_USER_STATE", {
550
564
  state: e,
551
565
  stateVersion: t
552
566
  });
553
567
  }
554
568
  },
555
569
  settings: {
556
- initialize: (e) => (A = t(t({}, D(e)), A), w.sendMessage("INITIALIZE_SETTINGS", {
557
- components: e,
558
- settings: A
559
- }), A),
560
- get: () => {
561
- var e;
562
- return (e = A) == null ? {} : e;
570
+ initialize: (e) => {
571
+ let n = A(e, k(a));
572
+ N = n.components, P = n.locked, M = t(t({}, O(N)), M);
573
+ let r = F();
574
+ return T.sendMessage("INITIALIZE_SETTINGS", {
575
+ components: N,
576
+ settings: r
577
+ }), r;
563
578
  },
564
- update: (e) => (A = t(t({}, A), e), w.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: A }), A)
579
+ get: F,
580
+ update: (e) => {
581
+ let n = Object.entries(e == null ? {} : e).filter(([e]) => !(e in P));
582
+ return M = t(t({}, M), Object.fromEntries(n)), T.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: M }), F();
583
+ },
584
+ components: () => N
565
585
  },
566
586
  keyboard: {
567
587
  show: (e) => {
568
- w.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
588
+ T.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
569
589
  },
570
590
  hide: () => {
571
- w.sendMessage("KEYBOARD_UPDATE_CONFIG", {
591
+ T.sendMessage("KEYBOARD_UPDATE_CONFIG", {
572
592
  layout: [],
573
593
  symbols: {},
574
594
  highlight: [],
@@ -581,22 +601,50 @@ const E = (r = {}) => {
581
601
  },
582
602
  haptics: { play: (e, t) => {
583
603
  var n;
584
- w.sendMessage("SENSORY_EVENT", {
604
+ T.sendMessage("SENSORY_EVENT", {
585
605
  id: (n = t == null ? void 0 : t.id) == null ? e : n,
586
606
  haptic: e
587
607
  });
588
608
  } },
589
- _hostAPI: w
609
+ _hostAPI: T
590
610
  };
591
611
  };
592
612
  /** Walks settings UI components (recursing into split groups) collecting name → defaultValue pairs */
593
- function D(e) {
613
+ function O(e) {
594
614
  let t = {};
595
- for (let n of e) n.type === "split" ? Object.assign(t, D(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
615
+ for (let n of e) n.type === "split" ? Object.assign(t, O(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
596
616
  return t;
597
617
  }
618
+ /** The settings overrides an embed's host context holds for this game, under the game's slug */
619
+ function k(e) {
620
+ var t, n;
621
+ let r = e == null || (t = e.hostContext) == null ? void 0 : t.find((e) => e.type === "embed"), i = e == null || (n = e.game) == null ? void 0 : n.slug;
622
+ if (!r || !i) return [];
623
+ let a = r[i];
624
+ return Array.isArray(a == null ? void 0 : a.settingsUIOverrides) ? a.settingsUIOverrides : [];
625
+ }
626
+ /**
627
+ * Applies an embed's overrides to the components they match by `id`, recursing into split groups.
628
+ * `omit` marks the component `hidden`, and `locked` holds the value each omitted setting is kept at.
629
+ */
630
+ function A(n, r) {
631
+ let i = {};
632
+ if (!r.length) return {
633
+ components: n,
634
+ locked: i
635
+ };
636
+ let a = (n, o) => {
637
+ var s;
638
+ let c = (s = r.find((e) => e.id === n.id)) == null ? { id: n.id } : s, { omit: l } = c, u = e(c, b), d = o || !!l, f = t(t(t({}, n), u), d ? { hidden: !0 } : {});
639
+ return f.type === "split" ? t(t({}, f), {}, { content: f.content.map((e) => a(e, d)) }) : (d && "name" in f && (i[f.name] = f.defaultValue), f);
640
+ };
641
+ return {
642
+ components: n.map((e) => a(e, !1)),
643
+ locked: i
644
+ };
645
+ }
598
646
  /** The largest state `sdk.storage.set()` takes, matching the API's cap */
599
- var O = 64 * 1024;
647
+ var j = 64 * 1024;
600
648
  /**
601
649
  * A standard QWERTY layout with Enter and Backspace — a reasonable default for
602
650
  * any game that needs text input. Customize from here by spreading and overriding.
@@ -609,7 +657,7 @@ var O = 64 * 1024;
609
657
  * // Extend with dynamic disabled letters
610
658
  * sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
611
659
  */
612
- const k = {
660
+ const M = {
613
661
  layout: [
614
662
  "qwertyuiop",
615
663
  "asdfghjkl",
@@ -625,7 +673,7 @@ const k = {
625
673
  xl: [],
626
674
  l: ["↵", "⌫"],
627
675
  supportsDragCursor: !1
628
- }, A = (e) => {
676
+ }, N = (e) => {
629
677
  let n = {};
630
678
  for (let a of e) for (let e of a.keys) {
631
679
  var r, i;
@@ -635,11 +683,11 @@ const k = {
635
683
  return n;
636
684
  };
637
685
  /** Custom error class for workshop import failures */
638
- var j = class extends Error {
686
+ var P = class extends Error {
639
687
  constructor(e, t, n) {
640
688
  super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
641
689
  }
642
690
  };
643
- export { j as EditorImportError, E as createPuzzmoSDK, k as defaultKeyboardConfig, A as keyStylesFromRules };
691
+ export { P as EditorImportError, D as createPuzzmoSDK, M as defaultKeyboardConfig, N as keyStylesFromRules };
644
692
 
645
693
  //# sourceMappingURL=index.js.map