@puzzmo/sdk 1.0.71 → 1.0.72

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.
@@ -438,6 +438,7 @@ function ee(e, t, n) {
438
438
  puzzleData: f,
439
439
  originalPuzzle: f == null ? "" : f,
440
440
  currentInputStr: p == null ? "" : p,
441
+ userStorage: null,
441
442
  appliedPuzzleOverride: f,
442
443
  appliedInputOverride: p,
443
444
  completionData: null,
@@ -682,7 +683,7 @@ function B() {
682
683
  return null;
683
684
  }
684
685
  /** Generate a small thumbnail SVG for a given input string */
685
- function V(e, t) {
686
+ function se(e, t) {
686
687
  let n = B();
687
688
  if (!n) return "";
688
689
  try {
@@ -698,14 +699,14 @@ function V(e, t) {
698
699
  return "";
699
700
  }
700
701
  }
701
- var H = [];
702
- function U(e, t = 8) {
702
+ var V = [];
703
+ function H(e, t = 8) {
703
704
  let n = 14 * t + 8 + 4;
704
705
  e.style.height = "auto";
705
706
  let r = Math.min(Math.max(e.scrollHeight, 40), n);
706
707
  e.style.height = `${r}px`;
707
708
  }
708
- function se() {
709
+ function ce() {
709
710
  let e = "", t = "";
710
711
  return {
711
712
  id: "data",
@@ -723,18 +724,18 @@ function se() {
723
724
  let i = n.getElement(".data-view-container");
724
725
  i == null || i.querySelectorAll(".data-subtab-content").forEach((e) => {
725
726
  e.classList.toggle("active", e.id === `data-subtab-${t}`);
726
- }), t === "edit" ? ue(n) : t === "history" ? W(n) : t === "saves" && G(n);
727
+ }), t === "edit" ? de(n) : t === "history" ? U(n) : t === "saves" && W(n);
727
728
  });
728
729
  });
729
730
  let i = n.getElement("#simulator-puzzle"), a = n.getElement("#simulator-input"), o = n.getElement("#simulator-puzzle-reset"), s = n.getElement("#simulator-puzzle-apply"), u = n.getElement("#simulator-input-reset"), d = n.getElement("#simulator-input-apply");
730
731
  setTimeout(() => {
731
- i && n.state.originalPuzzle && document.activeElement !== i && (i.value = n.state.originalPuzzle, e = n.state.originalPuzzle, U(i)), a && n.state.currentInputStr && document.activeElement !== a && (a.value = n.state.currentInputStr, t = n.state.currentInputStr, U(a)), de(n);
732
+ i && n.state.originalPuzzle && document.activeElement !== i && (i.value = n.state.originalPuzzle, e = n.state.originalPuzzle, H(i)), a && n.state.currentInputStr && document.activeElement !== a && (a.value = n.state.currentInputStr, t = n.state.currentInputStr, H(a)), fe(n);
732
733
  }, 0), i == null || i.addEventListener("input", () => {
733
- U(i);
734
+ H(i);
734
735
  let t = i.value !== e;
735
736
  s && (s.disabled = !t);
736
737
  }), a == null || a.addEventListener("input", () => {
737
- U(a);
738
+ H(a);
738
739
  let e = a.value !== t;
739
740
  d && (d.disabled = !e);
740
741
  }), o == null || o.addEventListener("click", () => {
@@ -742,7 +743,7 @@ function se() {
742
743
  l("puzzle"), n.updateStatus("Restoring fixture puzzle...", "waiting"), window.location.reload();
743
744
  return;
744
745
  }
745
- i && (i.value = n.state.originalPuzzle, e = n.state.originalPuzzle, U(i), s && (s.disabled = !0));
746
+ i && (i.value = n.state.originalPuzzle, e = n.state.originalPuzzle, H(i), s && (s.disabled = !0));
746
747
  }), s == null || s.addEventListener("click", () => {
747
748
  if (i) {
748
749
  if (!c("puzzle", i.value)) {
@@ -756,7 +757,7 @@ function se() {
756
757
  l("input"), n.updateStatus("Clearing input...", "waiting"), window.location.reload();
757
758
  return;
758
759
  }
759
- a && (a.value = t, U(a), d && (d.disabled = !0));
760
+ a && (a.value = t, H(a), d && (d.disabled = !0));
760
761
  }), d == null || d.addEventListener("click", () => {
761
762
  if (a) {
762
763
  if (!c("input", a.value)) {
@@ -768,41 +769,41 @@ function se() {
768
769
  });
769
770
  let f = n.getElement("#simulator-history-clear");
770
771
  f == null || f.addEventListener("click", () => {
771
- H = [], W(n);
772
+ V = [], U(n);
772
773
  });
773
774
  let p = n.getElement("#simulator-save-name"), m = n.getElement("#simulator-save-btn");
774
775
  m == null || m.addEventListener("click", () => {
775
776
  if (!p || !p.value.trim()) return;
776
- let e = ce(), t = {
777
+ let e = le(), t = {
777
778
  name: p.value.trim(),
778
779
  puzzleStr: n.state.originalPuzzle,
779
780
  inputStr: n.state.currentInputStr,
780
781
  timestamp: Date.now()
781
782
  };
782
- e.push(t), localStorage.setItem(z, JSON.stringify(e)), p.value = "", G(n);
783
- }), G(n);
783
+ e.push(t), localStorage.setItem(z, JSON.stringify(e)), p.value = "", W(n);
784
+ }), W(n);
784
785
  },
785
786
  onActivate(n) {
786
- e = n.state.originalPuzzle, t = n.state.currentInputStr, ue(n), W(n);
787
+ e = n.state.originalPuzzle, t = n.state.currentInputStr, de(n), U(n);
787
788
  },
788
789
  onMessage(e, n, r) {
789
790
  var i, a;
790
791
  let o = r.getElement("#simulator-input"), s = r.getElement("#simulator-input-apply"), c = (i = n == null || (a = n.input) == null ? void 0 : a.boardState) == null ? n == null ? void 0 : n.boardState : i;
791
792
  if (e === "UPLOAD_NEW_GAME_STATE" && c) {
792
- if (r.state.currentInputStr = c, H.length === 0 || H[H.length - 1].value !== c) {
793
- H.push({
793
+ if (r.state.currentInputStr = c, V.length === 0 || V[V.length - 1].value !== c) {
794
+ V.push({
794
795
  value: c,
795
796
  timestamp: Date.now()
796
- }), H.length > 100 && (H = H.slice(-100));
797
+ }), V.length > 100 && (V = V.slice(-100));
797
798
  let e = r.getElement("#data-subtab-history");
798
- e != null && e.classList.contains("active") && W(r);
799
+ e != null && e.classList.contains("active") && U(r);
799
800
  }
800
- o && document.activeElement !== o && (o.value !== c && (o.value = c, U(o)), t = c, s && (s.disabled = !0));
801
+ o && document.activeElement !== o && (o.value !== c && (o.value = c, H(o)), t = c, s && (s.disabled = !0));
801
802
  }
802
803
  }
803
804
  };
804
805
  }
805
- function ce() {
806
+ function le() {
806
807
  try {
807
808
  let e = localStorage.getItem(z);
808
809
  return e ? JSON.parse(e) : [];
@@ -810,45 +811,45 @@ function ce() {
810
811
  return [];
811
812
  }
812
813
  }
813
- function W(e) {
814
+ function U(e) {
814
815
  let t = e.getElement("#simulator-history-list");
815
816
  if (t) {
816
- if (t.style.setProperty("--history-thumb-bg", e.state.selectedTheme.a_bg), H.length === 0) {
817
+ if (t.style.setProperty("--history-thumb-bg", e.state.selectedTheme.a_bg), V.length === 0) {
817
818
  t.innerHTML = "<div class=\"simulator-empty\">No history yet</div>";
818
819
  return;
819
820
  }
820
- t.innerHTML = [...H].reverse().map((t, n) => {
821
- let r = H.length - 1 - n, i = new Date(t.timestamp).toLocaleTimeString(), a = t.value.length > 60 ? t.value.slice(0, 60) + "..." : t.value;
821
+ t.innerHTML = [...V].reverse().map((t, n) => {
822
+ let r = V.length - 1 - n, i = new Date(t.timestamp).toLocaleTimeString(), a = t.value.length > 60 ? t.value.slice(0, 60) + "..." : t.value;
822
823
  return `
823
824
  <div class="history-item" data-history-idx="${r}">
824
- <div class="history-item-thumb">${V(e, t.value)}</div>
825
+ <div class="history-item-thumb">${se(e, t.value)}</div>
825
826
  <div class="history-item-content">
826
827
  <div class="history-item-header">
827
828
  <span class="history-item-num">#${r + 1}</span>
828
829
  <span class="history-item-time">${i}</span>
829
830
  <button class="simulator-btn tiny history-restore-btn" data-history-idx="${r}">Restore</button>
830
831
  </div>
831
- <div class="history-item-preview">${le(a)}</div>
832
+ <div class="history-item-preview">${ue(a)}</div>
832
833
  </div>
833
834
  </div>
834
835
  `;
835
836
  }).join(""), t.querySelectorAll(".history-restore-btn").forEach((t) => {
836
837
  t.addEventListener("click", (t) => {
837
- let n = parseInt(t.target.getAttribute("data-history-idx") || "0"), r = H[n];
838
+ let n = parseInt(t.target.getAttribute("data-history-idx") || "0"), r = V[n];
838
839
  if (r) {
839
840
  let t = e.getElement(".data-subtab[data-subtab=\"edit\"]");
840
841
  t == null || t.click();
841
842
  let n = e.getElement("#simulator-input"), i = e.getElement("#simulator-input-apply");
842
- n && (n.value = r.value, U(n)), i && (i.disabled = !1), e.updateStatus("Input restored — press Apply to load it", "ready");
843
+ n && (n.value = r.value, H(n)), i && (i.disabled = !1), e.updateStatus("Input restored — press Apply to load it", "ready");
843
844
  }
844
845
  });
845
846
  });
846
847
  }
847
848
  }
848
- function G(e) {
849
+ function W(e) {
849
850
  let t = e.getElement("#simulator-saves-list");
850
851
  if (!t) return;
851
- let n = ce();
852
+ let n = le();
852
853
  if (n.length === 0) {
853
854
  t.innerHTML = "<div class=\"simulator-empty\">No saved states</div>";
854
855
  return;
@@ -858,7 +859,7 @@ function G(e) {
858
859
  return `
859
860
  <div class="save-item">
860
861
  <div class="save-item-header">
861
- <span class="save-item-name">${le(e.name)}</span>
862
+ <span class="save-item-name">${ue(e.name)}</span>
862
863
  <span class="save-item-time">${i} ${a}</span>
863
864
  </div>
864
865
  <div class="save-item-actions">
@@ -881,25 +882,25 @@ function G(e) {
881
882
  }), t.querySelectorAll(".save-delete-btn").forEach((t) => {
882
883
  t.addEventListener("click", (t) => {
883
884
  let r = parseInt(t.target.getAttribute("data-save-idx") || "0"), i = n.filter((e, t) => t !== r);
884
- localStorage.setItem(z, JSON.stringify(i)), G(e);
885
+ localStorage.setItem(z, JSON.stringify(i)), W(e);
885
886
  });
886
887
  });
887
888
  }
888
- function le(e) {
889
+ function ue(e) {
889
890
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
890
891
  }
891
- function ue(e) {
892
+ function de(e) {
892
893
  let t = e.getElement("#simulator-puzzle"), n = e.getElement("#simulator-input"), r = e.getElement("#simulator-puzzle-apply"), i = e.getElement("#simulator-input-apply");
893
- t && e.state.originalPuzzle && (t.value = e.state.originalPuzzle, U(t), r && (r.disabled = !0)), n && (n.value = e.state.currentInputStr, U(n), i && (i.disabled = !0)), de(e);
894
+ t && e.state.originalPuzzle && (t.value = e.state.originalPuzzle, H(t), r && (r.disabled = !0)), n && (n.value = e.state.currentInputStr, H(n), i && (i.disabled = !0)), fe(e);
894
895
  }
895
- function de(e) {
896
+ function fe(e) {
896
897
  let t = e.getElement("#simulator-puzzle-override-tag"), n = e.getElement("#simulator-input-override-tag");
897
898
  t && (t.hidden = e.state.appliedPuzzleOverride === null), n && (n.hidden = e.state.appliedInputOverride === null);
898
899
  }
899
- function fe(e) {
900
+ function pe(e) {
900
901
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
901
902
  }
902
- function pe() {
903
+ function me() {
903
904
  let e = 0;
904
905
  return {
905
906
  id: "msgs",
@@ -926,7 +927,7 @@ function pe() {
926
927
  <span class="simulator-msg-type">${t.direction === "out" ? "→" : "←"} ${t.type}</span>
927
928
  <span class="simulator-msg-time">${t.time}</span>
928
929
  </div>
929
- ${a ? `<div class="simulator-msg-data">${fe(a)}</div>` : ""}
930
+ ${a ? `<div class="simulator-msg-data">${pe(a)}</div>` : ""}
930
931
  `;
931
932
  let o = i.querySelector(".simulator-msg-data");
932
933
  for (o && o.addEventListener("click", () => {
@@ -937,7 +938,7 @@ function pe() {
937
938
  }
938
939
  };
939
940
  }
940
- function me() {
941
+ function he() {
941
942
  return {
942
943
  id: "done",
943
944
  label: "Done",
@@ -974,7 +975,7 @@ function me() {
974
975
  }
975
976
  };
976
977
  }
977
- function he() {
978
+ function ge() {
978
979
  let e = [], t = () => (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: !1 }), n = (e) => {
979
980
  let { checkpointName: t, augConfig: n, time: r } = e, i = n == null ? void 0 : n.deeds;
980
981
  return `
@@ -1024,7 +1025,7 @@ function he() {
1024
1025
  }
1025
1026
  };
1026
1027
  }
1027
- var ge = /* @__PURE__ */ n(((e) => {
1028
+ var _e = /* @__PURE__ */ n(((e) => {
1028
1029
  var t = { document: {} }, n = Object.prototype.hasOwnProperty, r = function(e) {
1029
1030
  return v(e) ? e.toLowerCase() : e;
1030
1031
  }, i = Array.isArray;
@@ -2204,10 +2205,10 @@ var ge = /* @__PURE__ */ n(((e) => {
2204
2205
  return this.state[this.state.computing];
2205
2206
  }
2206
2207
  };
2207
- function V(e, t) {
2208
+ function se(e, t) {
2208
2209
  this.astBuilder = e, this.$filter = t;
2209
2210
  }
2210
- V.prototype = {
2211
+ se.prototype = {
2211
2212
  compile: function(e) {
2212
2213
  var t = this, n = this.astBuilder.ast(e);
2213
2214
  I(n, t.$filter);
@@ -2478,17 +2479,17 @@ var ge = /* @__PURE__ */ n(((e) => {
2478
2479
  /**
2479
2480
  * @constructor
2480
2481
  */
2481
- var H = function(e, t, n) {
2482
- this.lexer = e, this.$filter = t, n = n || {}, n.handleThis = n.handleThis == null ? !0 : n.handleThis, this.options = n, this.ast = new N(e, n), this.ast.selfReferential = { $locals: { type: N.LocalsExpression } }, n.handleThis && (this.ast.selfReferential.this = { type: N.ThisExpression }), this.astCompiler = n.csp ? new V(this.ast, t) : new B(this.ast, t);
2482
+ var V = function(e, t, n) {
2483
+ this.lexer = e, this.$filter = t, n = n || {}, n.handleThis = n.handleThis == null ? !0 : n.handleThis, this.options = n, this.ast = new N(e, n), this.ast.selfReferential = { $locals: { type: N.LocalsExpression } }, n.handleThis && (this.ast.selfReferential.this = { type: N.ThisExpression }), this.astCompiler = n.csp ? new se(this.ast, t) : new B(this.ast, t);
2483
2484
  };
2484
- H.prototype = {
2485
- constructor: H,
2485
+ V.prototype = {
2486
+ constructor: V,
2486
2487
  parse: function(e) {
2487
2488
  return this.astCompiler.compile(e);
2488
2489
  }
2489
- }, e.Lexer = M, e.Parser = H;
2490
- })), _e = (/* @__PURE__ */ n(((e) => {
2491
- var t = ge(), n = {}, r = t.Lexer, i = t.Parser;
2490
+ }, e.Lexer = M, e.Parser = V;
2491
+ })), ve = (/* @__PURE__ */ n(((e) => {
2492
+ var t = _e(), n = {}, r = t.Lexer, i = t.Parser;
2492
2493
  function a(e) {
2493
2494
  return e = e || {}, e.filters && (e.cache = e.cache || {}), e.cache = e.cache || s.cache, e.filters = e.filters || n, e;
2494
2495
  }
@@ -2526,7 +2527,7 @@ var ge = /* @__PURE__ */ n(((e) => {
2526
2527
  s.cache = Object.create(null), e.compile = s;
2527
2528
  })))();
2528
2529
  /** Cleans deeds the way puzzmo.com's PlayGameIframe and the API's `getDeedsFromCompletion` do, collecting what was dropped. */
2529
- const ve = (e, t) => {
2530
+ const ye = (e, t) => {
2530
2531
  let n = [];
2531
2532
  e !== void 0 && !Array.isArray(e) && n.push("deeds is not an array, the host ignores it");
2532
2533
  let r = [];
@@ -2560,17 +2561,17 @@ const ve = (e, t) => {
2560
2561
  })),
2561
2562
  warnings: n
2562
2563
  };
2563
- }, ye = (e) => {
2564
+ }, be = (e) => {
2564
2565
  let t = {};
2565
- for (let n of e) n.value !== void 0 && (t[Se(n.id)] = n.value);
2566
+ for (let n of e) n.value !== void 0 && (t[Ce(n.id)] = n.value);
2566
2567
  return t;
2567
- }, be = (e, t) => {
2568
+ }, xe = (e, t) => {
2568
2569
  try {
2569
- if (e.filterExp && !(0, _e.compile)(e.filterExp)(t) || !e.incrementExp) return {
2570
+ if (e.filterExp && !(0, ve.compile)(e.filterExp)(t) || !e.incrementExp) return {
2570
2571
  complete: !1,
2571
2572
  value: 0
2572
2573
  };
2573
- let n = (0, _e.compile)(e.incrementExp)(t);
2574
+ let n = (0, ve.compile)(e.incrementExp)(t);
2574
2575
  if (typeof n == "boolean" && (n = n ? 1 : 0), n === void 0 && (n = 0), typeof n != "number" || isNaN(n)) throw Error(`incrementExp must return a number, undefined or boolean, got ${n}`);
2575
2576
  let r = Math.floor(n);
2576
2577
  return {
@@ -2584,17 +2585,17 @@ const ve = (e, t) => {
2584
2585
  error: e.message
2585
2586
  };
2586
2587
  }
2587
- }, xe = (e) => {
2588
+ }, Se = (e) => {
2588
2589
  let { items: t, scope: n, mode: r } = e, i = Math.min(Math.max(e.index, 0), t.length), a;
2589
- for (; i < t.length && (a = be(t[i], n), !(!a.complete || r === "checkpoint" && !t[i].liveUpdate)); i++);
2590
+ for (; i < t.length && (a = xe(t[i], n), !(!a.complete || r === "checkpoint" && !t[i].liveUpdate)); i++);
2590
2591
  return {
2591
2592
  index: i,
2592
2593
  head: i < t.length ? a : void 0
2593
2594
  };
2594
2595
  };
2595
- var Se = (e) => e.replace(/-./g, (e) => e[1].toUpperCase());
2596
+ var Ce = (e) => e.replace(/-./g, (e) => e[1].toUpperCase());
2596
2597
  /** A minimal take on puzzmo.com's tutorial checklist, driven by deeds from checkpoints and completion. */
2597
- function Ce(e) {
2598
+ function we(e) {
2598
2599
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = null, i = 0, a, o = [], s = (e) => {
2599
2600
  var t;
2600
2601
  return `simulator-checklist:${(t = r) == null ? "game" : t}:${e}`;
@@ -2618,15 +2619,15 @@ function Ce(e) {
2618
2619
  t.liveUpdate ? "liveUpdate: checkpoints + completion" : "completion only"
2619
2620
  ].filter(Boolean).join("\n");
2620
2621
  return `${e.instructionsVisibleFromItemIndex === r && r > 0 ? "<div class=\"checklist-divider\"><span>full instructions unlock</span></div>" : ""}
2621
- <div class="checklist-item ${o}" title="${K(f)}">
2622
+ <div class="checklist-item ${o}" title="${G(f)}">
2622
2623
  <div class="checklist-row">
2623
2624
  <span class="checklist-tick">${o === "done" ? "■" : "□"}</span>
2624
- <span class="checklist-title">${K((a = t.title) == null ? `Step ${r + 1}` : a)}</span>
2625
+ <span class="checklist-title">${G((a = t.title) == null ? `Step ${r + 1}` : a)}</span>
2625
2626
  ${d ? `<span class="checklist-count">${d}</span>` : ""}
2626
- ${l ? `<button class="checklist-help${c ? " open" : ""}" data-help="${K(s)}">?</button>` : ""}
2627
+ ${l ? `<button class="checklist-help${c ? " open" : ""}" data-help="${G(s)}">?</button>` : ""}
2627
2628
  </div>
2628
- ${o === "active" && t.subtitle ? `<div class="checklist-subtitle">${K(t.subtitle)}</div>` : ""}
2629
- ${l && c ? `<pre class="checklist-expand">${K(t.expandMD)}</pre>` : ""}
2629
+ ${o === "active" && t.subtitle ? `<div class="checklist-subtitle">${G(t.subtitle)}</div>` : ""}
2630
+ ${l && c ? `<pre class="checklist-expand">${G(t.expandMD)}</pre>` : ""}
2630
2631
  </div>`;
2631
2632
  }, d = (e) => {
2632
2633
  var n, r, i, s;
@@ -2636,24 +2637,24 @@ function Ce(e) {
2636
2637
  <div class="checklist-header">
2637
2638
  <span class="simulator-label">Checklist</span>
2638
2639
  <span class="checklist-progress${d === l ? " complete" : ""}">${d}/${l}</span>
2639
- <button class="simulator-btn subtle small" data-reset="${K(e.stableID)}">Reset</button>
2640
+ <button class="simulator-btn subtle small" data-reset="${G(e.stableID)}">Reset</button>
2640
2641
  </div>
2641
2642
  <div class="checklist-items">
2642
2643
  ${e.items.map((t, n) => u(e, t, n, c)).join("")}
2643
2644
  </div>
2644
- ${a ? `<div class="checklist-footer">last eval: ${K(a)}</div>` : ""}
2645
- ${f ? `<div class="checklist-error">${K(f)}</div>` : ""}
2646
- ${o.map((e) => `<div class="checklist-error">${K(e)}</div>`).join("")}
2645
+ ${a ? `<div class="checklist-footer">last eval: ${G(a)}</div>` : ""}
2646
+ ${f ? `<div class="checklist-error">${G(f)}</div>` : ""}
2647
+ ${o.map((e) => `<div class="checklist-error">${G(e)}</div>`).join("")}
2647
2648
  </div>`;
2648
2649
  }, f = () => e.length === 0 ? "<div class=\"simulator-empty\">No checklists in puzzmo.json → integrations.checklists\n<pre class=\"checklist-expand\">\"checklists\": [{\n \"stableID\": \"my-game:tutorial\",\n \"type\": \"tutorial\",\n \"items\": [{ \"title\": \"Make a move\", \"incrementExp\": \"moves\", \"liveUpdate\": true }]\n}]</pre></div>" : e.map(d).join(""), p = (e) => {
2649
2650
  let t = e.getElement("#simulator-checklist-list");
2650
2651
  t && (t.innerHTML = f());
2651
2652
  }, m = (n, r, s, c) => {
2652
- let u = 0, d = ve(r, s), f = ye(d.deeds);
2653
+ let u = 0, d = ye(r, s), f = be(d.deeds);
2653
2654
  a = c, o = d.warnings;
2654
2655
  for (let n of e) {
2655
2656
  var m, h;
2656
- let e = (m = (h = t.get(n.stableID)) == null ? void 0 : h.index) == null ? 0 : m, r = xe({
2657
+ let e = (m = (h = t.get(n.stableID)) == null ? void 0 : h.index) == null ? 0 : m, r = Se({
2657
2658
  items: n.items,
2658
2659
  index: e,
2659
2660
  scope: f,
@@ -2691,9 +2692,9 @@ function Ce(e) {
2691
2692
  }
2692
2693
  };
2693
2694
  }
2694
- var K = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2695
+ var G = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2695
2696
  /** Find thumbnail function on globalThis (looks for functions ending in "Thumbnail") */
2696
- function we() {
2697
+ function Te() {
2697
2698
  let e = globalThis;
2698
2699
  for (let t of Object.keys(e)) if (t.endsWith("Thumbnail") && typeof e[t] == "function") return {
2699
2700
  name: t,
@@ -2702,23 +2703,23 @@ function we() {
2702
2703
  return null;
2703
2704
  }
2704
2705
  /** The bundle's `getShareString` (if any), exposed to the sim via vite.ts's bundle loader. */
2705
- function Te() {
2706
+ function Ee() {
2706
2707
  let e = globalThis.getShareString;
2707
2708
  return typeof e == "function" ? e : null;
2708
2709
  }
2709
- function Ee(e) {
2710
+ function De(e) {
2710
2711
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2711
2712
  }
2712
- function De() {
2713
+ function Oe() {
2713
2714
  let e = /* @__PURE__ */ new Date();
2714
2715
  return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
2715
2716
  }
2716
- function Oe(e) {
2717
+ function ke(e) {
2717
2718
  return e.charAt(0).toUpperCase() + e.slice(1);
2718
2719
  }
2719
2720
  /** Shown when Preview Kind = Text but the bundle doesn't export `getShareString`. */
2720
- var ke = "\n <div class=\"simulator-share-missing\">\n <p>The app bundle doesn't export <code>getShareString</code>.</p>\n <p>Add it to your app bundle to preview share strings here:</p>\n <pre>export const getShareString: AppBundle[\"getShareString\"] = (\n inputStr, title, { puzzleString, dateKey, gameplaySlug },\n) =&gt; ({ str: `${title}: ...` })</pre>\n </div>\n";
2721
- function Ae() {
2721
+ var Ae = "\n <div class=\"simulator-share-missing\">\n <p>The app bundle doesn't export <code>getShareString</code>.</p>\n <p>Add it to your app bundle to preview share strings here:</p>\n <pre>export const getShareString: AppBundle[\"getShareString\"] = (\n inputStr, title, { puzzleString, dateKey, gameplaySlug },\n) =&gt; ({ str: `${title}: ...` })</pre>\n </div>\n";
2722
+ function je() {
2722
2723
  return {
2723
2724
  id: "thumb",
2724
2725
  label: "Thumb",
@@ -2754,26 +2755,26 @@ function Ae() {
2754
2755
  updatePreview: (e) => {
2755
2756
  let t = e.getElement("#simulator-thumb-preview"), n = e.getElement("#simulator-thumb-fn");
2756
2757
  if (t == null || t.style.setProperty("--sim-thumb-bg", e.state.selectedTheme.g_bg), e.state.previewKind === "text") {
2757
- let s = Te();
2758
+ let s = Ee();
2758
2759
  if (!s) {
2759
- t && (t.innerHTML = ke), n && (n.textContent = "");
2760
+ t && (t.innerHTML = Ae), n && (n.textContent = "");
2760
2761
  return;
2761
2762
  }
2762
2763
  n && (n.textContent = "Using: getShareString()");
2763
2764
  try {
2764
2765
  var r, i, a, o;
2765
- let n = (r = e.gameSlug) == null ? "game" : r, c = s((i = e.state.currentInputStr) == null ? "" : i, Oe(n), {
2766
+ let n = (r = e.gameSlug) == null ? "game" : r, c = s((i = e.state.currentInputStr) == null ? "" : i, ke(n), {
2766
2767
  puzzleString: (a = e.state.puzzleData) == null ? "" : a,
2767
- dateKey: De(),
2768
+ dateKey: Oe(),
2768
2769
  gameplaySlug: `simulator:${n}`
2769
2770
  }), l = (o = c == null ? void 0 : c.str) == null ? "" : o;
2770
- t && (t.innerHTML = `<pre class="simulator-share-preview" style="color: ${e.state.selectedTheme.fg}">${Ee(l)}</pre>`);
2771
+ t && (t.innerHTML = `<pre class="simulator-share-preview" style="color: ${e.state.selectedTheme.fg}">${De(l)}</pre>`);
2771
2772
  } catch (e) {
2772
2773
  console.error("Simulator: Share string error", e), t && (t.innerHTML = `<span class="simulator-empty">Error: ${e}</span>`);
2773
2774
  }
2774
2775
  return;
2775
2776
  }
2776
- let s = we();
2777
+ let s = Te();
2777
2778
  if (!s) {
2778
2779
  t && (t.innerHTML = "<span class=\"simulator-empty\">No thumbnail function found</span>"), n && (n.textContent = "");
2779
2780
  return;
@@ -2796,7 +2797,7 @@ function Ae() {
2796
2797
  };
2797
2798
  }
2798
2799
  /** Generate theme preview HTML showing key colors */
2799
- function je(e) {
2800
+ function Me(e) {
2800
2801
  let t = [
2801
2802
  e.key,
2802
2803
  e.subBrand,
@@ -2807,7 +2808,7 @@ function je(e) {
2807
2808
  ].map((e) => `<div class="simulator-theme-preview-cell" style="background: ${e}"></div>`).join("");
2808
2809
  return `<div class="simulator-theme-preview" style="background: ${e.g_bg}">${t}</div>`;
2809
2810
  }
2810
- function Me() {
2811
+ function Ne() {
2811
2812
  return {
2812
2813
  id: "theme",
2813
2814
  label: "Theme",
@@ -2819,7 +2820,7 @@ function Me() {
2819
2820
  t && r.forEach((n) => {
2820
2821
  let r = document.createElement("div");
2821
2822
  r.className = `simulator-theme-item${n.name === e.state.selectedTheme.name ? " selected" : ""}`, r.innerHTML = `
2822
- ${je(n)}
2823
+ ${Me(n)}
2823
2824
  <div class="simulator-theme-name">${n.name}</div>
2824
2825
  <div class="simulator-theme-type">${n.type}</div>
2825
2826
  `, r.addEventListener("click", () => {
@@ -2829,7 +2830,7 @@ function Me() {
2829
2830
  }
2830
2831
  };
2831
2832
  }
2832
- var Ne = [
2833
+ var Pe = [
2833
2834
  {
2834
2835
  name: "app (desktop)",
2835
2836
  context: [{
@@ -2876,8 +2877,8 @@ var Ne = [
2876
2877
  * The bootstrap is only read at game boot, so applying a change persists it to localStorage and
2877
2878
  * restarts (reloads) the page — the same flow as the Theme tab.
2878
2879
  */
2879
- function Pe(e = []) {
2880
- let t = [...Ne, ...e];
2880
+ function Fe(e = []) {
2881
+ let t = [...Pe, ...e];
2881
2882
  return {
2882
2883
  id: "host",
2883
2884
  label: "Host",
@@ -2894,7 +2895,7 @@ function Pe(e = []) {
2894
2895
  <div class="host-note" id="host-source"></div>
2895
2896
  <select class="simulator-select" id="host-presets">
2896
2897
  <option value="">Preset…</option>
2897
- ${t.map((e, t) => `<option value="${t}">${Fe(e.name)}</option>`).join("")}
2898
+ ${t.map((e, t) => `<option value="${t}">${Ie(e.name)}</option>`).join("")}
2898
2899
  </select>
2899
2900
  <textarea class="simulator-textarea" id="host-json" spellcheck="false"></textarea>
2900
2901
  <div class="host-actions">
@@ -2931,16 +2932,16 @@ function Pe(e = []) {
2931
2932
  };
2932
2933
  }
2933
2934
  /** Minimal HTML-escape so preset names can't break the simulator markup. */
2934
- function Fe(e) {
2935
+ function Ie(e) {
2935
2936
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2936
2937
  }
2937
- var Ie = "puzzmo_sim_api_mode", Le = "http://localhost:8911", Re = "https://api.puzzmo.com", q = () => localStorage.getItem(Ie) === "dev" ? "dev" : "prod", ze = (e) => {
2938
- localStorage.setItem(Ie, e);
2938
+ var Le = "puzzmo_sim_api_mode", K = "http://localhost:8911", Re = "https://api.puzzmo.com", q = () => localStorage.getItem(Le) === "dev" ? "dev" : "prod", ze = (e) => {
2939
+ localStorage.setItem(Le, e);
2939
2940
  }, J = null, Be = function() {
2940
2941
  var e = t(function* () {
2941
2942
  if (J !== null) return J;
2942
2943
  try {
2943
- let e = new AbortController(), t = setTimeout(() => e.abort(), 1e3), n = yield fetch(`${Le}/healthz`, { signal: e.signal });
2944
+ let e = new AbortController(), t = setTimeout(() => e.abort(), 1e3), n = yield fetch(`${K}/healthz`, { signal: e.signal });
2944
2945
  return clearTimeout(t), J = n.ok, J;
2945
2946
  } catch (e) {
2946
2947
  return J = !1, !1;
@@ -2950,7 +2951,7 @@ var Ie = "puzzmo_sim_api_mode", Le = "http://localhost:8911", Re = "https://api.
2950
2951
  return e.apply(this, arguments);
2951
2952
  };
2952
2953
  }(), Ve = () => ({
2953
- apiURL: q() === "dev" ? Le : Re,
2954
+ apiURL: q() === "dev" ? K : Re,
2954
2955
  clientID: "protosdk:oauthclient",
2955
2956
  redirectUri: `${window.location.origin}/oauth/callback`
2956
2957
  }), He = () => {
@@ -3066,7 +3067,7 @@ function nt() {
3066
3067
  id: "auth",
3067
3068
  label: "Auth",
3068
3069
  render() {
3069
- let e = qe(), t = !!e, n = q(), r = n === "dev" ? Le : Re, i = `<button class="simulator-btn tiny" id="auth-dev-toggle" style="display: none;">${n === "dev" ? "Using Dev" : "Dev"}</button>`;
3070
+ let e = qe(), t = !!e, n = q(), r = n === "dev" ? K : Re, i = `<button class="simulator-btn tiny" id="auth-dev-toggle" style="display: none;">${n === "dev" ? "Using Dev" : "Dev"}</button>`;
3070
3071
  if (t) {
3071
3072
  let t = tt(e), n = t != null && t.exp ? (/* @__PURE__ */ new Date(t.exp * 1e3)).toLocaleString() : "Unknown", a = !!Je(), o = a ? tt(Je()) : null, s = o != null && o.exp ? (/* @__PURE__ */ new Date(o.exp * 1e3)).toLocaleString() : null;
3072
3073
  return `
@@ -3109,7 +3110,7 @@ function nt() {
3109
3110
  </div>
3110
3111
  <p class="auth-description">
3111
3112
  Login with your Puzzmo account to make authenticated API requests.
3112
- ${n === "dev" ? `<br><strong>Using local dev server:</strong> ${Le}` : ""}
3113
+ ${n === "dev" ? `<br><strong>Using local dev server:</strong> ${K}` : ""}
3113
3114
  </p>
3114
3115
  <div class="simulator-row">
3115
3116
  <button class="simulator-btn primary" id="auth-login">Login with Puzzmo</button>
@@ -3865,16 +3866,16 @@ function Gt(n = {}) {
3865
3866
  slug: n.slug,
3866
3867
  hasFixtures: !!n.fixtures
3867
3868
  }), $) return n.fixtures && (console.log("[Simulator] Instance already exists, updating fixtures"), $.updateFixtures(n.fixtures)), $;
3868
- let c = (r = n.autoStart) == null ? !0 : r, l = n.fixtures ? ie(n.fixtures) : null, u = l ? Array.from(l.keys()).sort() : [], d = pe(), f = Ae(), p = [
3869
+ let c = (r = n.autoStart) == null ? !0 : r, l = n.fixtures ? ie(n.fixtures) : null, u = l ? Array.from(l.keys()).sort() : [], d = me(), f = je(), p = [
3869
3870
  oe(),
3870
- se(),
3871
+ ce(),
3871
3872
  d,
3872
- me(),
3873
3873
  he(),
3874
- Ce((i = (a = n.integrations) == null ? void 0 : a.checklists) == null ? [] : i),
3874
+ ge(),
3875
+ we((i = (a = n.integrations) == null ? void 0 : a.checklists) == null ? [] : i),
3875
3876
  f,
3876
- Me(),
3877
- Pe(n.hostContextPresets),
3877
+ Ne(),
3878
+ Fe(n.hostContextPresets),
3878
3879
  nt(),
3879
3880
  xt(),
3880
3881
  Pt(),
@@ -5402,6 +5403,28 @@ function Gt(n = {}) {
5402
5403
  d.addLogEntry(e, H);
5403
5404
  }), B = (e, t) => {
5404
5405
  M(e, t, z);
5406
+ }, se = (e) => {
5407
+ var t;
5408
+ let n = (t = e.buckets) != null && t.length ? e.buckets : u, r = n.find((e) => {
5409
+ var t;
5410
+ return !(!(l == null || (t = l.get(e)) == null) && t.size);
5411
+ });
5412
+ if (r !== void 0 || !n.length) return {
5413
+ nonce: e.nonce,
5414
+ error: `No fixtures in "${r == null ? "" : r}" to stand in for a pool`,
5415
+ failed: !0
5416
+ };
5417
+ let i = n.flatMap((e) => [...l.get(e).keys()].map((t) => `fixtures/${e}/${t}`)), a = i.filter((t) => {
5418
+ var n;
5419
+ return !((n = e.exclude) != null && n.includes(t));
5420
+ }), o = a.length ? a : i, s = o[Math.floor(Math.random() * o.length)], [, c, ...d] = s.split("/");
5421
+ return {
5422
+ nonce: e.nonce,
5423
+ puzzle: {
5424
+ key: s,
5425
+ puzzle: l.get(c).get(d.join("/"))
5426
+ }
5427
+ };
5405
5428
  }, V = (e, t) => {
5406
5429
  let n = _.querySelector(`[data-badge="${e}"]`);
5407
5430
  n && (n.textContent = t && t > 0 ? String(t) : "");
@@ -5441,9 +5464,9 @@ function Gt(n = {}) {
5441
5464
  }), y.addEventListener("click", (e) => {
5442
5465
  h.isCollapsed && e.target !== T && I(!1);
5443
5466
  }), h.isCollapsed || F(h.activeTab);
5444
- let U = new URLSearchParams(window.location.search);
5445
- (U.has("code") || U.has("error")) && (I(!1), F("auth"));
5446
- let ce = (e) => {
5467
+ let le = new URLSearchParams(window.location.search);
5468
+ (le.has("code") || le.has("error")) && (I(!1), F("auth"));
5469
+ let U = (e) => {
5447
5470
  let t = {
5448
5471
  additionalTimeAddedSecs: 0,
5449
5472
  boardState: h.currentInputStr,
@@ -5481,16 +5504,17 @@ function Gt(n = {}) {
5481
5504
  },
5482
5505
  game: Kt,
5483
5506
  session: n,
5507
+ viewerStorage: h.userStorage,
5484
5508
  theme: h.selectedTheme,
5485
5509
  hostContext: h.hostContext,
5486
5510
  appRuntimeContract: "1.0"
5487
5511
  };
5488
- }, W = ["1.0", "1.1"], G = function() {
5512
+ }, W = ["1.0", "1.1"], ue = function() {
5489
5513
  var r = t(function* (t) {
5490
5514
  let r = n.session !== !1 || t === "1.0";
5491
5515
  r ? n.session === !1 && console.warn("Simulator: `session: false` needs a game built on an SDK speaking runtime contract 1.1 or later") : console.log("Simulator: Sending READY_DATA without a session"), j(r ? "Loading puzzle..." : "Sending READY_DATA...", "waiting");
5492
5516
  try {
5493
- let n = e(e({}, ce(r ? yield R() : null)), {}, { appRuntimeContract: t });
5517
+ let n = e(e({}, U(r ? yield R() : null)), {}, { appRuntimeContract: t });
5494
5518
  j("Sending READY_DATA...", "waiting"), B("READY_DATA", n), j("Waiting for game to load...", "waiting");
5495
5519
  } catch (e) {
5496
5520
  j(`Error: ${e}`, "paused");
@@ -5499,7 +5523,7 @@ function Gt(n = {}) {
5499
5523
  return function(e) {
5500
5524
  return r.apply(this, arguments);
5501
5525
  };
5502
- }(), le = () => {
5526
+ }(), de = () => {
5503
5527
  console.log("Simulator: Game loaded, ready to start"), C.disabled = !1, p.forEach((e) => {
5504
5528
  var t;
5505
5529
  return (t = e.onMessage) == null ? void 0 : t.call(e, "READY_GAME_LOADED", void 0, H);
@@ -5511,11 +5535,11 @@ function Gt(n = {}) {
5511
5535
  return N((e, t) => {
5512
5536
  var n, r;
5513
5537
  if (e === "READY") {
5514
- console.log("Simulator: Received READY from game"), G(W.includes(t == null ? void 0 : t.runtimeContract) ? t.runtimeContract : "1.0");
5538
+ console.log("Simulator: Received READY from game"), ue(W.includes(t == null ? void 0 : t.runtimeContract) ? t.runtimeContract : "1.0");
5515
5539
  return;
5516
5540
  }
5517
5541
  if (e === "READY_GAME_LOADED") {
5518
- le();
5542
+ de();
5519
5543
  return;
5520
5544
  }
5521
5545
  if (e === "TIMER_TICK") {
@@ -5535,7 +5559,18 @@ function Gt(n = {}) {
5535
5559
  return (r = n.onMessage) == null ? void 0 : r.call(n, e, t, H);
5536
5560
  });
5537
5561
  let i = (n = t == null || (r = t.input) == null ? void 0 : r.boardState) == null ? t == null ? void 0 : t.boardState : n;
5538
- e === "UPLOAD_NEW_GAME_STATE" && i && (h.currentInputStr = i, h.activeTab === "thumb" && L(), console.log("Simulator: Game state uploaded", t)), e === "GAME_COMPLETED" && (console.log("Simulator: Game completed!", t), S.disabled = !0, h.hasStarted = !1, j("Completed!", "complete"));
5562
+ if (e === "UPLOAD_NEW_GAME_STATE" && i && (h.currentInputStr = i, h.activeTab === "thumb" && L(), console.log("Simulator: Game state uploaded", t)), e === "COMPLETE_REPEATABLE_RUN" && console.log("Simulator: Repeatable run completed", t), e === "REQUEST_PUZZLE") {
5563
+ B("PUZZLE_DATA", se(t));
5564
+ return;
5565
+ }
5566
+ if (e === "UPDATE_GAME_USER_STATE" && typeof (t == null ? void 0 : t.state) == "string") {
5567
+ var a;
5568
+ h.userStorage = {
5569
+ state: t.state,
5570
+ stateVersion: (a = t.stateVersion) == null ? 1 : a
5571
+ }, console.log("Simulator: Game user storage updated", t);
5572
+ }
5573
+ e === "GAME_COMPLETED" && (console.log("Simulator: Game completed!", t), S.disabled = !0, h.hasStarted = !1, j("Completed!", "complete"));
5539
5574
  }, z), console.log("Simulator initialized"), $ = {
5540
5575
  updateFixtures: (e) => {
5541
5576
  l = ie(e), u = Array.from(l.keys()).sort(), H.fixtures = l, H.fixtureCategories = u;
@@ -5573,4 +5608,4 @@ var Kt = {
5573
5608
  };
5574
5609
  export { Bt as n, ae as r, Gt as t };
5575
5610
 
5576
- //# sourceMappingURL=createSimulator-treFHkmV.js.map
5611
+ //# sourceMappingURL=createSimulator-C5RgI7Gg.js.map