@puzzmo/sdk 1.0.81 → 1.0.82

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 (148) hide show
  1. package/dist/analytics.d.ts.map +1 -1
  2. package/dist/bootstrapPayload.d.ts.map +1 -1
  3. package/dist/bootstrapPayload.spec.d.ts.map +1 -1
  4. package/dist/bundles.cjs +1 -1
  5. package/dist/bundles.cjs.map +1 -1
  6. package/dist/bundles.d.ts +10 -2
  7. package/dist/bundles.d.ts.map +1 -1
  8. package/dist/bundles.js +2 -2
  9. package/dist/bundles.js.map +1 -1
  10. package/dist/contracts.d.ts.map +1 -1
  11. package/dist/createSimulator-CIE72Xs2.cjs +2233 -0
  12. package/dist/createSimulator-CIE72Xs2.cjs.map +1 -0
  13. package/dist/{createSimulator-2M7vXzRZ.js → createSimulator-Dz1KYZ25.js} +1579 -596
  14. package/dist/createSimulator-Dz1KYZ25.js.map +1 -0
  15. package/dist/easing.d.ts +6 -0
  16. package/dist/easing.d.ts.map +1 -0
  17. package/dist/editor.d.ts +25 -3
  18. package/dist/editor.d.ts.map +1 -1
  19. package/dist/fontFiles.gen.d.ts.map +1 -1
  20. package/dist/fonts-CP_kAAac.js +83 -0
  21. package/dist/fonts-CP_kAAac.js.map +1 -0
  22. package/dist/fonts-CS5qdLf3.cjs +3 -0
  23. package/dist/fonts-CS5qdLf3.cjs.map +1 -0
  24. package/dist/fonts.cjs +1 -3
  25. package/dist/fonts.d.ts +2 -0
  26. package/dist/fonts.d.ts.map +1 -1
  27. package/dist/fonts.js +2 -83
  28. package/dist/gameTracker.d.ts.map +1 -1
  29. package/dist/global.d.ts.map +1 -1
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.global.js.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/inputs/decoder.d.ts.map +1 -1
  36. package/dist/inputs/encoder.d.ts.map +1 -1
  37. package/dist/inputs/encodings.d.ts.map +1 -1
  38. package/dist/inputs/index.d.ts.map +1 -1
  39. package/dist/inputs/inputStringEncoder.spec.d.ts.map +1 -1
  40. package/dist/inputs/migration.d.ts.map +1 -1
  41. package/dist/inputs/types.d.ts.map +1 -1
  42. package/dist/keyboard.d.ts.map +1 -1
  43. package/dist/keyboard.spec.d.ts.map +1 -1
  44. package/dist/{lua-DKb2Tu2V.js → lua-B8exrfmB.js} +1 -1
  45. package/dist/{lua-DKb2Tu2V.js.map → lua-B8exrfmB.js.map} +1 -1
  46. package/dist/{lua-CclI-QKD.cjs → lua-C5r7UXeR.cjs} +1 -1
  47. package/dist/{lua-CclI-QKD.cjs.map → lua-C5r7UXeR.cjs.map} +1 -1
  48. package/dist/pico8/channel.d.ts.map +1 -1
  49. package/dist/pico8/index.cjs +1 -1
  50. package/dist/pico8/index.d.ts.map +1 -1
  51. package/dist/pico8/index.js +1 -1
  52. package/dist/pico8/lua.d.ts.map +1 -1
  53. package/dist/pico8/palette.d.ts.map +1 -1
  54. package/dist/pico8/pico8.spec.d.ts.map +1 -1
  55. package/dist/pico8/protocol.d.ts.map +1 -1
  56. package/dist/pico8/vitePlugin.d.ts.map +1 -1
  57. package/dist/plugins.d.ts.map +1 -1
  58. package/dist/plugins.spec.d.ts.map +1 -1
  59. package/dist/sdk.d.ts.map +1 -1
  60. package/dist/sdk.gameCompleted.spec.d.ts.map +1 -1
  61. package/dist/sdk.gameReady.spec.d.ts.map +1 -1
  62. package/dist/sdk.pause.spec.d.ts.map +1 -1
  63. package/dist/sdk.session.spec.d.ts.map +1 -1
  64. package/dist/settings.spec.d.ts.map +1 -1
  65. package/dist/simulator/checklistProgress.d.ts.map +1 -1
  66. package/dist/simulator/checklistProgress.spec.d.ts.map +1 -1
  67. package/dist/simulator/createSimulator.d.ts.map +1 -1
  68. package/dist/simulator/dockedKeyboard.d.ts.map +1 -1
  69. package/dist/simulator/fixtures.d.ts.map +1 -1
  70. package/dist/simulator/index.cjs +1 -1
  71. package/dist/simulator/index.d.ts.map +1 -1
  72. package/dist/simulator/index.js +2 -1
  73. package/dist/simulator/marker.d.ts.map +1 -1
  74. package/dist/simulator/messaging.d.ts.map +1 -1
  75. package/dist/simulator/normalizeThumbnail.d.ts.map +1 -1
  76. package/dist/simulator/pmmgOverlay.d.ts +36 -0
  77. package/dist/simulator/pmmgOverlay.d.ts.map +1 -0
  78. package/dist/simulator/pmmgOverlay.spec.d.ts +2 -0
  79. package/dist/simulator/pmmgOverlay.spec.d.ts.map +1 -0
  80. package/dist/simulator/pmmgRenderer.d.ts +86 -0
  81. package/dist/simulator/pmmgRenderer.d.ts.map +1 -0
  82. package/dist/simulator/pmmgRenderer.spec.d.ts +2 -0
  83. package/dist/simulator/pmmgRenderer.spec.d.ts.map +1 -0
  84. package/dist/simulator/standalone.cjs +1 -1
  85. package/dist/simulator/standalone.cjs.map +1 -1
  86. package/dist/simulator/standalone.d.ts.map +1 -1
  87. package/dist/simulator/standalone.js +2 -1
  88. package/dist/simulator/standalone.js.map +1 -1
  89. package/dist/simulator/state.d.ts +19 -0
  90. package/dist/simulator/state.d.ts.map +1 -1
  91. package/dist/simulator/state.spec.d.ts.map +1 -1
  92. package/dist/simulator/styles.d.ts +1 -1
  93. package/dist/simulator/styles.d.ts.map +1 -1
  94. package/dist/simulator/types.d.ts +5 -0
  95. package/dist/simulator/types.d.ts.map +1 -1
  96. package/dist/simulator/views/AuthView.d.ts.map +1 -1
  97. package/dist/simulator/views/ChecklistView.d.ts.map +1 -1
  98. package/dist/simulator/views/CheckpointsView.d.ts.map +1 -1
  99. package/dist/simulator/views/CtrlView.d.ts.map +1 -1
  100. package/dist/simulator/views/DataView.d.ts.map +1 -1
  101. package/dist/simulator/views/DoneView.d.ts.map +1 -1
  102. package/dist/simulator/views/FeaturesView.d.ts.map +1 -1
  103. package/dist/simulator/views/HostView.d.ts.map +1 -1
  104. package/dist/simulator/views/KeyboardView.d.ts.map +1 -1
  105. package/dist/simulator/views/MsgsView.d.ts.map +1 -1
  106. package/dist/simulator/views/PmmgView.d.ts +7 -0
  107. package/dist/simulator/views/PmmgView.d.ts.map +1 -0
  108. package/dist/simulator/views/SettingsView.d.ts.map +1 -1
  109. package/dist/simulator/views/SoundView.d.ts.map +1 -1
  110. package/dist/simulator/views/ThemeView.d.ts.map +1 -1
  111. package/dist/simulator/views/ThumbView.d.ts.map +1 -1
  112. package/dist/simulator/views/index.d.ts +1 -0
  113. package/dist/simulator/views/index.d.ts.map +1 -1
  114. package/dist/svgJSX.d.ts.map +1 -1
  115. package/dist/tableBoard-B0I9wVQq.js +635 -0
  116. package/dist/tableBoard-B0I9wVQq.js.map +1 -0
  117. package/dist/tableBoard-CLDBwRYs.cjs +2 -0
  118. package/dist/tableBoard-CLDBwRYs.cjs.map +1 -0
  119. package/dist/tableBoard.cjs +1 -0
  120. package/dist/tableBoard.d.ts +138 -0
  121. package/dist/tableBoard.d.ts.map +1 -0
  122. package/dist/tableBoard.js +2 -0
  123. package/dist/tableBoardScene.d.ts +21 -0
  124. package/dist/tableBoardScene.d.ts.map +1 -0
  125. package/dist/themes.d.ts +16 -16
  126. package/dist/themes.d.ts.map +1 -1
  127. package/dist/types.d.ts +161 -0
  128. package/dist/types.d.ts.map +1 -1
  129. package/dist/vite.cjs +3 -3
  130. package/dist/vite.cjs.map +1 -1
  131. package/dist/vite.d.ts +20 -0
  132. package/dist/vite.d.ts.map +1 -1
  133. package/dist/vite.js +72 -16
  134. package/dist/vite.js.map +1 -1
  135. package/package.json +5 -5
  136. package/dist/createSimulator-2M7vXzRZ.js.map +0 -1
  137. package/dist/createSimulator-B4QlohUV.cjs +0 -1930
  138. package/dist/createSimulator-B4QlohUV.cjs.map +0 -1
  139. package/dist/fonts.cjs.map +0 -1
  140. package/dist/fonts.js.map +0 -1
  141. package/dist/thumbnailMotion.cjs +0 -5
  142. package/dist/thumbnailMotion.cjs.map +0 -1
  143. package/dist/thumbnailMotion.d.ts +0 -119
  144. package/dist/thumbnailMotion.d.ts.map +0 -1
  145. package/dist/thumbnailMotion.js +0 -480
  146. package/dist/thumbnailMotion.js.map +0 -1
  147. package/dist/thumbnailMotion.spec.d.ts +0 -2
  148. package/dist/thumbnailMotion.spec.d.ts.map +0 -1
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as e } from "./objectWithoutProperties-54Cbyogk.js";
2
2
  import { t } from "./objectSpread2-BJrS9rM5.js";
3
3
  import { t as n } from "./asyncToGenerator-DSd3oTwb.js";
4
- import { t as r } from "./lua-DKb2Tu2V.js";
4
+ import { t as r } from "./lua-B8exrfmB.js";
5
5
  import { build as i } from "vite";
6
6
  import a from "path";
7
7
  import o from "fs";
@@ -179,21 +179,20 @@ var m = ["fixturesGlob", "viewFactories"], h = "/@puzzmo-simulator-init.js", g =
179
179
  * @internal
180
180
  */
181
181
  function _(e) {
182
- let t = /* @__PURE__ */ new Map(), n = D(e, 3);
182
+ let t = /* @__PURE__ */ new Map(), n = j(e, 3);
183
183
  o.existsSync(a.join(e, "puzzmo.json")) && n.unshift(e);
184
184
  for (let i of n) try {
185
185
  var r;
186
186
  let n = JSON.parse(o.readFileSync(a.join(i, "puzzmo.json"), "utf-8"));
187
187
  if (!(!(n == null || (r = n.game) == null) && r.slug)) continue;
188
- let s = C(i, "src/appBundle"), c = null;
189
- s && (c = "/" + a.relative(e, s).split(a.sep).join("/"));
190
- let l = n.integrations && typeof n.integrations == "object" ? n.integrations : void 0;
188
+ let s = n.integrations && typeof n.integrations == "object" ? n.integrations : void 0;
191
189
  t.set(n.game.slug, {
192
190
  dir: i,
193
191
  slug: n.game.slug,
194
192
  displayName: n.game.displayName,
195
- appBundlePath: c,
196
- integrations: l
193
+ appBundlePath: C(e, w(i, "src/appBundle")),
194
+ pmmgBundlePath: C(e, w(i, "src/pmmgBundle")),
195
+ integrations: s
197
196
  });
198
197
  } catch (e) {}
199
198
  return t;
@@ -223,7 +222,7 @@ function y(n, r) {
223
222
  for (let e of a == null ? [] : a) c.push(`import { ${e.export} } from ${JSON.stringify(e.module)}`);
224
223
  s && c.push(`const fixtures = import.meta.glob(${JSON.stringify(s)}, { query: "?raw", import: "default", eager: true })`), r != null && r.appBundlePath && (c.push(`import(${JSON.stringify(r.appBundlePath)}).then(m => {`), c.push(" if (m.renderThumbnail) globalThis.renderThumbnail = m.renderThumbnail"), c.push(" if (m.getShareString) globalThis.getShareString = m.getShareString"), c.push("}).catch(() => {})"));
225
224
  let l = t(t(t({}, o), r != null && r.slug ? { slug: r.slug } : {}), r != null && r.integrations ? { integrations: r.integrations } : {}), u = Object.entries(l).filter(([, e]) => e !== void 0).map(([e, t]) => `${e}: ${JSON.stringify(t)}`);
226
- return s && u.push("fixtures"), a != null && a.length && u.push(`views: [${a.map((e) => `${e.export}()`).join(", ")}]`), c.push(`createSimulator({ ${u.join(", ")} })`), c.join("\n");
225
+ return s && u.push("fixtures"), r != null && r.pmmgBundlePath && u.push(`pmmgBundle: () => import(${JSON.stringify(r.pmmgBundlePath)})`), a != null && a.length && u.push(`views: [${a.map((e) => `${e.export}()`).join(", ")}]`), c.push(`createSimulator({ ${u.join(", ")} })`), c.join("\n");
227
226
  }
228
227
  /** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */
229
228
  function b(e = {}) {
@@ -293,7 +292,7 @@ function x(e, r) {
293
292
  closeBundle() {
294
293
  return n(function* () {
295
294
  var t;
296
- let n = o.entry ? a.isAbsolute(s) ? s : a.resolve(process.cwd(), s) : (t = C(process.cwd(), S(s))) == null ? a.resolve(process.cwd(), s) : t;
295
+ let n = o.entry ? a.isAbsolute(s) ? s : a.resolve(process.cwd(), s) : (t = w(process.cwd(), S(s))) == null ? a.resolve(process.cwd(), s) : t;
297
296
  try {
298
297
  yield i({
299
298
  configFile: !1,
@@ -317,7 +316,7 @@ function x(e, r) {
317
316
  };
318
317
  }
319
318
  /** Strip the trailing extension from a default entry path so we can probe siblings. */
320
- var S = (e) => e.replace(/\.[jt]sx?$/i, ""), C = (e, t) => {
319
+ var S = (e) => e.replace(/\.[jt]sx?$/i, ""), C = (e, t) => t ? "/" + a.relative(e, t).split(a.sep).join("/") : null, w = (e, t) => {
321
320
  for (let n of [
322
321
  ".js",
323
322
  ".ts",
@@ -336,19 +335,76 @@ var S = (e) => e.replace(/\.[jt]sx?$/i, ""), C = (e, t) => {
336
335
  * returning the SVG and its dimensions (`{ svg, width, height }`), used by the Puzzmo
337
336
  * platform for puzzle previews.
338
337
  */
339
- const w = x("app-bundle", {
338
+ const T = x("app-bundle", {
340
339
  entry: "src/appBundle.js",
341
340
  outputFile: "app-bundle.js",
342
341
  outDir: "dist"
343
- }), T = x("server-bundle", {
342
+ }), E = x("server-bundle", {
344
343
  entry: "src/serverBundle.js",
345
344
  outputFile: "server-bundle.js",
346
345
  outDir: "dist-server"
347
- }), E = x("editor-bundle", {
346
+ });
347
+ var D = x("pmmg-bundle", {
348
+ entry: "src/pmmgBundle.js",
349
+ outputFile: "pmmg-bundle.js",
350
+ outDir: "dist"
351
+ });
352
+ /**
353
+ * Vite plugins for the game's pmmg bundle (see `PmmgBundle`), such as its boards at the table. After the main build
354
+ * they produce dist/pmmg-bundle.js, which is public and served with the rest of `dist`. In dev, `/pmmg-bundle.js` on
355
+ * the game's dev server is built from source on each request, so a Puzzmo page running with `?dev` draws boards from
356
+ * the code being worked on.
357
+ *
358
+ * Puzzmo imports it from an opaque-origin sandbox, so that one response answers any origin. It's a whole build rather
359
+ * than the dev server's modules, since letting `Origin: null` read those would let any page read the game's source.
360
+ */
361
+ const O = (e = {}) => [D(e), {
362
+ name: "pmmg-bundle-dev",
363
+ apply: "serve",
364
+ configureServer(t) {
365
+ let n;
366
+ t.middlewares.use((r, i, o) => {
367
+ var s;
368
+ if (!/^\/pmmg-bundle\.js(?:\?.*)?$/.test(r.url || "")) return o();
369
+ let c = (s = e.entry) == null ? w(t.config.root, "src/pmmgBundle") : s;
370
+ if (!c) return o();
371
+ n != null || (n = k(a.resolve(t.config.root, c)).finally(() => n = void 0)), n.then((e) => {
372
+ i.setHeader("Content-Type", "text/javascript"), i.setHeader("Access-Control-Allow-Origin", "*"), i.setHeader("Cache-Control", "no-store"), i.end(e);
373
+ }, (e) => {
374
+ var n;
375
+ t.config.logger.error(`[pmmg-bundle] build failed: ${(n = e == null ? void 0 : e.message) == null ? e : n}`), i.statusCode = 500, i.end();
376
+ });
377
+ });
378
+ }
379
+ }], k = function() {
380
+ var e = n(function* (e) {
381
+ let t = yield i({
382
+ configFile: !1,
383
+ logLevel: "warn",
384
+ build: {
385
+ write: !1,
386
+ copyPublicDir: !1,
387
+ minify: !1,
388
+ sourcemap: "inline",
389
+ lib: {
390
+ entry: e,
391
+ formats: ["es"],
392
+ fileName: () => "pmmg-bundle.js"
393
+ },
394
+ rolldownOptions: { output: { codeSplitting: !1 } }
395
+ }
396
+ }), n = (Array.isArray(t) ? t : "output" in t ? [t] : []).flatMap((e) => e.output).find((e) => e.type === "chunk" && e.isEntry);
397
+ if (!n || n.type !== "chunk") throw Error(`Building ${e} made no bundle`);
398
+ return n.code;
399
+ });
400
+ return function(t) {
401
+ return e.apply(this, arguments);
402
+ };
403
+ }(), A = x("editor-bundle", {
348
404
  entry: "src/editorBundle.js",
349
405
  outputFile: "editor-bundle.js",
350
406
  outDir: "dist"
351
- }), D = (e, t, n = 0) => {
407
+ }), j = (e, t, n = 0) => {
352
408
  if (n >= t) return [];
353
409
  let r = [], i;
354
410
  try {
@@ -359,10 +415,10 @@ const w = x("app-bundle", {
359
415
  for (let s of i) {
360
416
  if (!s.isDirectory() || s.name.startsWith(".") || s.name === "node_modules") continue;
361
417
  let i = a.join(e, s.name);
362
- o.existsSync(a.join(i, "puzzmo.json")) && r.push(i), r.push(...D(i, t, n + 1));
418
+ o.existsSync(a.join(i, "puzzmo.json")) && r.push(i), r.push(...j(i, t, n + 1));
363
419
  }
364
420
  return r;
365
421
  };
366
- export { w as appBundlePlugin, _ as discoverGames, E as editorBundlePlugin, D as findPuzzmoJsonDirs, y as generateSimulatorCode, p as puzzmoPico8, b as puzzmoSimulator, v as resolveGameFromReferer, T as serverBundlePlugin };
422
+ export { T as appBundlePlugin, k as buildPmmgBundleSource, _ as discoverGames, A as editorBundlePlugin, j as findPuzzmoJsonDirs, y as generateSimulatorCode, O as pmmgBundlePlugin, p as puzzmoPico8, b as puzzmoSimulator, v as resolveGameFromReferer, E as serverBundlePlugin };
367
423
 
368
424
  //# sourceMappingURL=vite.js.map
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","names":[],"sources":["../src/pico8/vitePlugin.ts","../src/vite.ts"],"sourcesContent":["import type { Plugin, ResolvedConfig } from \"vite\"\nimport { execFileSync } from \"child_process\"\nimport path from \"path\"\nimport fs from \"fs\"\nimport { puzzmoLua } from \"./lua\"\n\nexport type PuzzmoPico8PluginOptions = {\n /** The cart, relative to the page. Defaults to the only `.p8` file in `cart/`. */\n cart?: string\n /** Where PICO-8's HTML export lives, relative to the page. Defaults to `export`. Commit it, so builds don't need PICO-8. */\n exportDir?: string\n /**\n * The PICO-8 binary used to re-export the cart when it changes. Defaults to `$PICO8`, then `pico8` on your PATH,\n * then where PICO-8's installers put it. When it can't be found the committed export is used as-is. Pass false to\n * never export.\n */\n pico8?: string | false\n /** Keep `puzzmo.lua` next to the cart up to date. Defaults to true. */\n writeLua?: boolean\n}\n\n/** @internal */\nexport type Pico8Game = {\n /** The directory holding the page */\n dir: string\n cart: string\n /** The cart's name, which PICO-8 also uses for its export */\n name: string\n exportHTML: string\n exportJS: string\n}\n\n/** @internal Finds the PICO-8 game served by the page in `dir`, if there is one. */\nexport function findPico8Game(dir: string, options: PuzzmoPico8PluginOptions = {}): Pico8Game | null {\n let cart: string | undefined\n if (options.cart) cart = path.resolve(dir, options.cart)\n else {\n const cartDir = path.join(dir, \"cart\")\n const carts = fs.existsSync(cartDir) ? fs.readdirSync(cartDir).filter((f) => f.endsWith(\".p8\")) : []\n if (carts.length > 1) throw new Error(`[puzzmo-pico8] found ${carts.length} carts in ${cartDir}, pick one with the \\`cart\\` option`)\n if (carts.length === 1) cart = path.join(cartDir, carts[0])\n }\n if (!cart || !fs.existsSync(cart)) return null\n const name = path.basename(cart, \".p8\")\n const exportDir = path.resolve(dir, options.exportDir ?? \"export\")\n return { dir, cart, name, exportHTML: path.join(exportDir, `${name}.html`), exportJS: path.join(exportDir, `${name}.js`) }\n}\n\n/**\n * @internal\n * Turns PICO-8's exported page into a Puzzmo game's page. PICO-8's shell is a thousand lines of globals and handlers\n * its runtime expects to find, and it changes between versions, so rather than keep a copy we adjust theirs.\n */\nexport function patchPico8Export(html: string, name: string, scripts: string[]): string {\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\n // PICO-8 loads its runtime from a script element it builds itself. Point it at the copy we serve next to the page,\n // relative because Puzzmo serves games from a subfolder.\n const runtime = new RegExp(`((?:\\\\.src\\\\s*=\\\\s*|\\\\ssrc=)[\"'])[^\"']*${escaped}\\\\.js([\"'])`)\n if (!runtime.test(html)) throw new Error(`[puzzmo-pico8] couldn't find where PICO-8's page loads ${name}.js`)\n html = html.replace(runtime, `$1./${name}.js$2`)\n\n // Boot straight away. Otherwise the cart waits for a click on PICO-8's play button and the host never hears that\n // the game loaded. (Browsers which need a tap before audio can start, like iOS Safari, still show the button.)\n html = html.replace(/var\\s+p8_autoplay\\s*=\\s*false/, \"var p8_autoplay = true\")\n\n // The GPIO array, for shells old enough not to declare it themselves.\n if (!/var\\s+pico8_gpio\\s*=/.test(html)) html = html.replace(/<head>/i, \"<head>\\n<script>var pico8_gpio = new Array(128)</script>\")\n\n // Things a browser shrugs off and Vite doesn't: an HTML comment wrapped around the stylesheet, a stray\n // `-repeat center;` in it, and an `&nbsp` without its semicolon.\n html = html.replace(\n /(<style[^>]*>)([\\s\\S]*?)(<\\/style>)/gi,\n (_, open: string, css: string, close: string) =>\n open + css.replace(/<!--|-->/g, \"\").replace(/^[ \\t]*-repeat[^;\\n]*;[ \\t]*$/gm, \"\") + close,\n )\n html = html.replace(/&nbsp(?!;)/g, \"&nbsp;\")\n\n const bodyEnd = html.lastIndexOf(\"</body>\")\n if (bodyEnd === -1) throw new Error(\"[puzzmo-pico8] that doesn't look like a PICO-8 export, it has no </body>\")\n return html.slice(0, bodyEnd) + scripts.join(\"\\n\") + \"\\n\" + html.slice(bodyEnd)\n}\n\n/** Where PICO-8's own installers put it, for people who never added it to their PATH. */\nconst usualPico8Locations = [\n \"/Applications/PICO-8.app/Contents/MacOS/pico8\",\n \"C:\\\\Program Files (x86)\\\\PICO-8\\\\pico8.exe\",\n \"C:\\\\Program Files\\\\PICO-8\\\\pico8.exe\",\n]\n\n/** Finds an executable on the PATH without running it: `pico8` with no export arguments opens the whole app. */\nconst findExecutable = (bin: string): string | null => {\n if (bin.includes(\"/\") || bin.includes(\"\\\\\")) return fs.existsSync(bin) ? bin : null\n for (const dir of (process.env.PATH ?? \"\").split(path.delimiter)) {\n for (const ext of process.platform === \"win32\" ? [\".exe\", \".cmd\", \"\"] : [\"\"]) {\n const candidate = path.join(dir, bin + ext)\n if (fs.existsSync(candidate)) return candidate\n }\n }\n if (bin === \"pico8\") return usualPico8Locations.find((p) => fs.existsSync(p)) ?? null\n return null\n}\n\nconst mtime = (file: string) => (fs.existsSync(file) ? fs.statSync(file).mtimeMs : 0)\n\n/**\n * Vite plugin for games written as PICO-8 carts. Your `index.html` only needs your own script tag, the plugin swaps\n * in PICO-8's exported page around it, serves the PICO-8 runtime next to it, and copies it into the build.\n *\n * When PICO-8 is installed it also re-exports the cart whenever it (or a `.lua` file next to it) changes, and reloads\n * the page, so saving in PICO-8 is enough to see the change in the simulator.\n */\nexport function puzzmoPico8(options: PuzzmoPico8PluginOptions = {}): Plugin {\n let config: ResolvedConfig\n const games = new Map<string, Pico8Game>()\n const binary = options.pico8 === false ? null : (options.pico8 ?? process.env.PICO8 ?? \"pico8\")\n\n const log = (message: string) => config.logger.info(`\\x1b[33m\\x1b[1m PICO-8 \\x1b[22m\\x1b[39m${message}`)\n\n const writeLua = (game: Pico8Game) => {\n if (options.writeLua === false) return\n const file = path.join(path.dirname(game.cart), \"puzzmo.lua\")\n if (fs.existsSync(file) && fs.readFileSync(file, \"utf8\") === puzzmoLua) return\n fs.writeFileSync(file, puzzmoLua)\n log(`wrote ${path.relative(config.root, file)}`)\n }\n\n /** Re-exports the cart when it's newer than the export and PICO-8 is around to do it. */\n const exportIfStale = (game: Pico8Game) => {\n const cartDir = path.dirname(game.cart)\n const newest = Math.max(\n ...fs\n .readdirSync(cartDir)\n .filter((f) => /\\.(p8|lua)$/.test(f))\n .map((f) => mtime(path.join(cartDir, f))),\n )\n if (fs.existsSync(game.exportJS) && mtime(game.exportJS) >= newest) return\n\n const pico8 = binary ? findExecutable(binary) : null\n if (!pico8) {\n if (fs.existsSync(game.exportHTML)) {\n config.logger.warn(\n `[puzzmo-pico8] ${path.relative(config.root, game.cart)} is newer than its export, and PICO-8 isn't around to re-export it. Using the old export.`,\n )\n return\n }\n throw new Error(\n `[puzzmo-pico8] there's no export of ${path.relative(config.root, game.cart)} yet, and PICO-8 isn't on your PATH to make one.\\n` +\n `Export it inside PICO-8 with EXPORT ${game.name}.html into ${path.relative(config.root, path.dirname(game.exportHTML))}/, or set PICO8=/path/to/pico8.`,\n )\n }\n\n fs.mkdirSync(path.dirname(game.exportHTML), { recursive: true })\n const before = mtime(game.exportJS)\n let output = \"\"\n try {\n output = execFileSync(pico8, [game.cart, \"-export\", game.exportHTML], {\n encoding: \"utf8\",\n timeout: 60_000,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n })\n } catch (error) {\n output = String((error as { stdout?: string }).stdout ?? error)\n }\n if (mtime(game.exportJS) === before) {\n const hint = /label/i.test(output) ? \"\\nHTML exports need a label: run the cart in PICO-8, press CTRL-7, and save.\" : \"\"\n throw new Error(`[puzzmo-pico8] PICO-8 didn't export ${path.relative(config.root, game.cart)}:\\n${output.trim()}${hint}`)\n }\n log(`exported ${path.relative(config.root, game.cart)}`)\n }\n\n const gameForPage = (htmlFile: string) => {\n const dir = path.dirname(htmlFile)\n if (!games.has(dir)) {\n const game = findPico8Game(dir, options)\n if (!game) return null\n games.set(dir, game)\n }\n return games.get(dir)!\n }\n\n return {\n name: \"puzzmo-pico8\",\n\n config() {\n // The export is rewritten on every save, and Vite reloads the page for any .html it sees change. The plugin\n // reloads once the export is done, so Vite reloading too would boot the cart twice.\n const exportDir = options.exportDir ?? \"export\"\n const isExport = (file: string) =>\n /\\.(html|js)$/.test(file) &&\n path.basename(path.dirname(file)) === path.basename(exportDir) &&\n fs.existsSync(path.join(path.dirname(path.dirname(file)), \"cart\"))\n return { server: { watch: { ignored: [isExport] } } }\n },\n\n configResolved(resolved) {\n config = resolved\n },\n\n transformIndexHtml: {\n order: \"pre\",\n handler(html, ctx) {\n const game = gameForPage(ctx.filename)\n if (!game) return\n writeLua(game)\n exportIfStale(game)\n // Keep the page's own module scripts: that's the game code.\n const scripts = html.match(/<script\\b[^>]*type=[\"']module[\"'][^>]*>[\\s\\S]*?<\\/script>/gi) ?? []\n return patchPico8Export(fs.readFileSync(game.exportHTML, \"utf8\"), game.name, scripts)\n },\n },\n\n configureServer(devServer) {\n // Serve the runtime next to the page, untouched by Vite's transforms: it is a megabyte of emscripten output\n // which only works exactly as PICO-8 wrote it.\n devServer.middlewares.use((req, res, next) => {\n const url = decodeURIComponent((req.url ?? \"\").split(\"?\")[0])\n if (!url.endsWith(\".js\")) return next()\n const game = [...games.values()].find(\n (g) =>\n url ===\n \"/\" +\n path\n .relative(config.root, path.join(g.dir, `${g.name}.js`))\n .split(path.sep)\n .join(\"/\"),\n )\n if (!game || !fs.existsSync(game.exportJS)) return next()\n res.setHeader(\"Content-Type\", \"text/javascript\")\n res.end(fs.readFileSync(game.exportJS))\n })\n\n // Saving the cart in PICO-8 re-exports it and reloads the page.\n devServer.watcher.on(\"change\", (file) => {\n const game = [...games.values()].find((g) => path.dirname(file) === path.dirname(g.cart) && /\\.(p8|lua)$/.test(file))\n if (!game || path.basename(file) === \"puzzmo.lua\") return\n try {\n exportIfStale(game)\n devServer.ws.send({ type: \"full-reload\" })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n config.logger.error(message)\n devServer.ws.send({ type: \"error\", err: { message, stack: \"\" } })\n }\n })\n },\n\n generateBundle() {\n for (const game of games.values()) {\n const fileName = path\n .relative(config.root, path.join(game.dir, `${game.name}.js`))\n .split(path.sep)\n .join(\"/\")\n this.emitFile({ type: \"asset\", fileName, source: fs.readFileSync(game.exportJS) })\n }\n },\n }\n}\n","import type { Plugin, ResolvedConfig } from \"vite\"\nimport { build } from \"vite\"\nimport path from \"path\"\nimport fs from \"fs\"\nimport type { HostContext } from \"./types\"\nimport type { HostContextPreset, SimulatorIntegrations } from \"./simulator/types\"\n\nexport { puzzmoPico8, type PuzzmoPico8PluginOptions } from \"./pico8/vitePlugin\"\n\nexport type PuzzmoSimulatorPluginOptions = {\n /** Whether to auto-start the game after READY (default: true) */\n autoStart?: boolean\n /** Initial collapsed state (default: true) */\n collapsed?: boolean\n /**\n * Glob pattern for fixture files, passed to import.meta.glob which is relative to the closest puzzmo.json. Defaults\n * to `\"/fixtures/puzzles/**\\/*.{json,toml}\"`. Fixtures are loaded as raw strings (any text format works — JSON,\n * TOML, or a custom format) and delivered to the game verbatim, so the game parses them itself. Pass false to disable.\n */\n fixturesGlob?: string | false\n /**\n * Whether READY_DATA carries a play session (default: true). Set to false to run the game the way\n * a host will for a mode with no puzzle. Ignored for games built on an SDK from before runtime contract \"1.1\".\n */\n session?: boolean\n /**\n * The `hostContext` array the simulator sends in READY_DATA, so host-context-dependent features\n * (embed settings, sandbox mode, mobile layout, …) can be exercised locally. Must be\n * JSON-serializable. Defaults to a single desktop \"app\" context; the simulator's Host tab can\n * override it at runtime (persisted per-browser, applied on restart).\n *\n * @internal\n */\n hostContext?: HostContext[]\n /**\n * Extra named `hostContext` presets for the simulator's Host tab, alongside the generic\n * built-ins — how a game ships its own scenarios (e.g. crossword's partner-embed toolbar\n * settings). Must be JSON-serializable.\n *\n * @internal\n */\n hostContextPresets?: HostContextPreset[]\n /**\n * Plugin-provided simulator tabs, named rather than passed directly because this config is\n * serialized into a virtual module. Each entry is imported and called with no arguments, so the\n * export must be a `() => SimulatorView` factory — e.g.\n * `{ module: \"@puzzmo-com/shared/sdkPlugins\", export: \"createCollabSimulatorView\" }`.\n */\n viewFactories?: { module: string; export: string }[]\n}\n\nconst simulatorURL = \"/@puzzmo-simulator-init.js\"\nconst virtualID = \"virtual:puzzmo-simulator\"\n\n/** @internal */\nexport type GameInfo = {\n /** Directory containing the puzzmo.json */\n dir: string\n slug: string\n displayName: string\n /** Vite-root-relative path to app bundle entry, if it exists */\n appBundlePath: string | null\n /** `integrations` from the puzzmo.json, passed to simulator tabs that preview them */\n integrations?: SimulatorIntegrations\n}\n\n/**\n * Discover all games from puzzmo.json files under a root directory.\n *\n * @internal\n */\nexport function discoverGames(viteRoot: string): Map<string, GameInfo> {\n const games = new Map<string, GameInfo>()\n const candidates = findPuzzmoJsonDirs(viteRoot, 3)\n if (fs.existsSync(path.join(viteRoot, \"puzzmo.json\"))) {\n candidates.unshift(viteRoot)\n }\n for (const dir of candidates) {\n try {\n const data = JSON.parse(fs.readFileSync(path.join(dir, \"puzzmo.json\"), \"utf-8\"))\n if (!data?.game?.slug) continue\n const bundleEntry = resolveBundleEntry(dir, \"src/appBundle\")\n let appBundle: string | null = null\n if (bundleEntry) {\n const relative = path.relative(viteRoot, bundleEntry)\n appBundle = \"/\" + relative.split(path.sep).join(\"/\")\n }\n const integrations = data.integrations && typeof data.integrations === \"object\" ? data.integrations : undefined\n games.set(data.game.slug, { dir, slug: data.game.slug, displayName: data.game.displayName, appBundlePath: appBundle, integrations })\n } catch {\n // skip invalid files\n }\n }\n return games\n}\n\n/**\n * Resolve which game a request belongs to using the referer URL.\n *\n * @internal\n */\nexport function resolveGameFromReferer(referer: string | undefined, games: Map<string, GameInfo>, viteRoot: string): GameInfo | undefined {\n if (referer) {\n try {\n const refPath = new URL(referer).pathname\n for (const g of games.values()) {\n const relDir = \"/\" + path.relative(viteRoot, g.dir).split(path.sep).join(\"/\")\n if (refPath.startsWith(relDir + \"/\") || refPath === relDir) return g\n }\n } catch {\n // ignore malformed referer\n }\n }\n if (games.size === 1) return games.values().next().value\n return undefined\n}\n\n/**\n * Generate the virtual module code for the simulator.\n *\n * @internal\n */\nexport function generateSimulatorCode(options: PuzzmoSimulatorPluginOptions, game: GameInfo | undefined): string {\n const { fixturesGlob: fixturesOpt, viewFactories, ...config } = options\n const fixturesGlob = fixturesOpt === false ? null : (fixturesOpt ?? \"/fixtures/puzzles/**/*.{json,toml}\")\n\n const lines = [`import { createSimulator } from \"@puzzmo/sdk/simulator\"`]\n for (const view of viewFactories ?? []) {\n lines.push(`import { ${view.export} } from ${JSON.stringify(view.module)}`)\n }\n\n // Load fixtures as raw strings so any text format reaches the game verbatim; the game does its own parsing.\n if (fixturesGlob) {\n lines.push(`const fixtures = import.meta.glob(${JSON.stringify(fixturesGlob)}, { query: \"?raw\", import: \"default\", eager: true })`)\n }\n\n if (game?.appBundlePath) {\n lines.push(`import(${JSON.stringify(game.appBundlePath)}).then(m => {`)\n lines.push(` if (m.renderThumbnail) globalThis.renderThumbnail = m.renderThumbnail`)\n lines.push(` if (m.getShareString) globalThis.getShareString = m.getShareString`)\n lines.push(`}).catch(() => {})`)\n }\n\n const simConfig = {\n ...config,\n ...(game?.slug ? { slug: game.slug } : {}),\n ...(game?.integrations ? { integrations: game.integrations } : {}),\n }\n const configEntries = Object.entries(simConfig).filter(([, v]) => v !== undefined)\n const configParts = configEntries.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)\n if (fixturesGlob) configParts.push(\"fixtures\")\n if (viewFactories?.length) configParts.push(`views: [${viewFactories.map((v) => `${v.export}()`).join(\", \")}]`)\n\n lines.push(`createSimulator({ ${configParts.join(\", \")} })`)\n\n return lines.join(\"\\n\")\n}\n\n/** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */\nexport function puzzmoSimulator(options: PuzzmoSimulatorPluginOptions = {}): Plugin {\n let games = new Map<string, GameInfo>()\n let viteRoot: string\n\n return {\n name: \"puzzmo-simulator\",\n apply: \"serve\",\n\n configResolved(config: ResolvedConfig) {\n viteRoot = config.root\n games = discoverGames(viteRoot)\n\n if (games.size === 0) {\n config.logger.info(`\\x1b[33m\\x1b[1m PUZZMO \\x1b[22m\\x1b[39m\\x1b[2m no puzzmo.json files found\\x1b[22m`)\n } else {\n const names = [...games.values()].map((g) => `\\x1b[36m${g.slug}\\x1b[39m`)\n const label = games.size === 1 ? \"game\" : \"games\"\n config.logger.info(`\\x1b[33m\\x1b[1m PUZZMO \\x1b[22m\\x1b[39m found ${games.size} ${label}: ${names.join(\"\\x1b[2m, \\x1b[22m\")}`)\n }\n },\n\n resolveId(id) {\n if (id === virtualID || id.startsWith(virtualID + \"?\")) return \"\\0\" + id\n },\n\n load(id) {\n if (!id.startsWith(\"\\0\" + virtualID)) return\n const params = new URLSearchParams(id.split(\"?\")[1] || \"\")\n const gameSlug = params.get(\"game\")\n const game = gameSlug ? games.get(gameSlug) : games.size === 1 ? games.values().next().value : undefined\n return generateSimulatorCode(options, game)\n },\n\n configureServer(server) {\n // Re-read puzzmo.json on edit and reload the page so the simulator picks up its changes\n for (const g of games.values()) server.watcher.add(path.join(g.dir, \"puzzmo.json\"))\n server.watcher.on(\"change\", (file) => {\n if (path.basename(file) !== \"puzzmo.json\") return\n games = discoverGames(viteRoot)\n for (const mod of server.moduleGraph.idToModuleMap.values()) {\n if (mod.id?.startsWith(\"\\0\" + virtualID)) server.moduleGraph.invalidateModule(mod)\n }\n server.ws.send({ type: \"full-reload\" })\n })\n\n server.middlewares.use(\"/oauth/callback\", (_req, res) => {\n res.setHeader(\"Content-Type\", \"text/html\")\n res.end(`<!DOCTYPE html>\n<html><head><title>Puzzmo OAuth</title></head>\n<body><script>\nvar params = new URLSearchParams(window.location.search);\nvar returnUrl = sessionStorage.getItem(\"oauth_return_url\") || \"/\";\nvar url = new URL(returnUrl);\nparams.forEach(function(v, k) { url.searchParams.set(k, v); });\nwindow.location.href = url.toString();\n</script></body></html>`)\n })\n\n // Serve the simulator init module, resolving the game from the referer\n server.middlewares.use(async (req, res, next) => {\n if (req.url?.split(\"?\")[0] !== simulatorURL) return next()\n\n const game = resolveGameFromReferer(req.headers.referer, games, viteRoot)\n const moduleID = virtualID + (game ? `?game=${game.slug}` : \"\")\n const result = await server.transformRequest(moduleID)\n if (!result) return next()\n res.setHeader(\"Content-Type\", \"application/javascript\")\n res.end(result.code)\n })\n },\n\n transformIndexHtml() {\n return [\n {\n tag: \"script\",\n attrs: { type: \"module\", src: simulatorURL },\n injectTo: \"head\",\n },\n ]\n },\n }\n}\n\ntype BundlePluginOptions = {\n /** Entry file for the bundle */\n entry: string\n /** Output file name */\n outputFile: string\n /** Folder the bundle is written to */\n outDir: string\n}\n\nfunction createBundlePlugin(pluginName: string, defaults: BundlePluginOptions) {\n return (options: Partial<BundlePluginOptions> = {}): Plugin => {\n const { entry, outputFile, outDir } = { ...defaults, ...options }\n return {\n name: pluginName,\n apply: \"build\",\n async closeBundle() {\n // If the caller overrode `entry`, honor it as-is. Otherwise try `.js` first, then `.ts`.\n const resolvedEntry = options.entry\n ? path.isAbsolute(entry)\n ? entry\n : path.resolve(process.cwd(), entry)\n : (resolveBundleEntry(process.cwd(), stripBundleExt(entry)) ?? path.resolve(process.cwd(), entry))\n try {\n await build({\n configFile: false,\n logLevel: \"warn\",\n build: {\n lib: {\n entry: resolvedEntry,\n formats: [\"es\"],\n fileName: () => outputFile,\n },\n outDir,\n emptyOutDir: false,\n },\n })\n } catch (error) {\n console.error(`[${pluginName}] build failed:`, error)\n throw error\n }\n },\n }\n }\n}\n\n/** Strip the trailing extension from a default entry path so we can probe siblings. */\nconst stripBundleExt = (p: string) => p.replace(/\\.[jt]sx?$/i, \"\")\n\n/** Returns the absolute path to the first matching extension under `dir`, or null. */\nconst resolveBundleEntry = (dir: string, baseRelative: string): string | null => {\n // JSX last: a bundle written as JSX still needs the plain entry to win if both somehow exist.\n for (const ext of [\".js\", \".ts\", \".tsx\", \".jsx\"]) {\n const candidate = path.join(dir, baseRelative + ext)\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n\nexport type AppBundlePluginOptions = {\n /** Entry file for the app bundle (default: `src/appBundle.js`) */\n entry?: string\n /** Output file name (default: `app-bundle.js`) */\n outputFile?: string\n}\n\n/**\n * Vite plugin that produces dist/app-bundle.js after the main build for app-level integrations.\n *\n * The bundle exports `renderThumbnail(puzzleString, inputString?, config?)` — a pure renderer\n * returning the SVG and its dimensions (`{ svg, width, height }`), used by the Puzzmo\n * platform for puzzle previews.\n */\nexport const appBundlePlugin = createBundlePlugin(\"app-bundle\", { entry: \"src/appBundle.js\", outputFile: \"app-bundle.js\", outDir: \"dist\" })\n\nexport type ServerBundlePluginOptions = {\n /** Entry file for the server bundle (default: `src/serverBundle.js`, or `.ts`) */\n entry?: string\n /** Output file name (default: `server-bundle.js`) */\n outputFile?: string\n}\n\n/**\n * Vite plugin that produces dist-server/server-bundle.js after the main build: the game's private\n * server bundle (see `ServerBundle`). It goes in its own folder, never `dist`, so it can't be served to\n * players by mistake; `puzzmo games upload` finds it there and sends it to Puzzmo privately. A repo that\n * builds several games gives each its own `outputFile` and names it in that game's puzzmo.json as\n * `output.serverBundle`, since uploads refuse to send one file for more than one game.\n */\nexport const serverBundlePlugin = createBundlePlugin(\"server-bundle\", {\n entry: \"src/serverBundle.js\",\n outputFile: \"server-bundle.js\",\n outDir: \"dist-server\",\n})\n\nexport type EditorBundlePluginOptions = {\n /** Entry file for the editor bundle (default: `src/editorBundle.js`) */\n entry?: string\n /** Output file name (default: `editor-bundle.js`) */\n outputFile?: string\n}\n\n/** Vite plugin that produces dist/editor-bundle.js after the main build for editor-level integrations. */\nexport const editorBundlePlugin = createBundlePlugin(\"editor-bundle\", {\n entry: \"src/editorBundle.js\",\n outputFile: \"editor-bundle.js\",\n outDir: \"dist\",\n})\n\n/**\n * Recursively find directories containing puzzmo.json, up to `maxDepth` levels deep.\n *\n * @internal\n */\nexport const findPuzzmoJsonDirs = (root: string, maxDepth: number, depth = 0): string[] => {\n if (depth >= maxDepth) return []\n const results: string[] = []\n let entries: fs.Dirent[]\n try {\n entries = fs.readdirSync(root, { withFileTypes: true })\n } catch {\n return results\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name.startsWith(\".\") || entry.name === \"node_modules\") continue\n const dir = path.join(root, entry.name)\n if (fs.existsSync(path.join(dir, \"puzzmo.json\"))) {\n results.push(dir)\n }\n results.push(...findPuzzmoJsonDirs(dir, maxDepth, depth + 1))\n }\n return results\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAgB,EAAc,GAAa,IAAoC,EAAE,EAAoB;;CACnG,IAAI;AACJ,KAAI,EAAQ,KAAM,KAAO,EAAK,QAAQ,GAAK,EAAQ,KAAK;MACnD;EACH,IAAM,IAAU,EAAK,KAAK,GAAK,OAAO,EAChC,IAAQ,EAAG,WAAW,EAAQ,GAAG,EAAG,YAAY,EAAQ,CAAC,QAAQ,MAAM,EAAE,SAAS,MAAM,CAAC,GAAG,EAAE;AACpG,MAAI,EAAM,SAAS,EAAG,OAAU,MAAM,wBAAwB,EAAM,OAAO,YAAY,EAAQ,qCAAqC;AACpI,EAAI,EAAM,WAAW,MAAG,IAAO,EAAK,KAAK,GAAS,EAAM,GAAG;;AAE7D,KAAI,CAAC,KAAQ,CAAC,EAAG,WAAW,EAAK,CAAE,QAAO;CAC1C,IAAM,IAAO,EAAK,SAAS,GAAM,MAAM,EACjC,IAAY,EAAK,QAAQ,IAAA,IAAK,EAAQ,cAAA,OAAa,WAAb,EAAsB;AAClE,QAAO;EAAE;EAAK;EAAM;EAAM,YAAY,EAAK,KAAK,GAAW,GAAG,EAAK,OAAO;EAAE,UAAU,EAAK,KAAK,GAAW,GAAG,EAAK,KAAK;EAAE;;;;;;;AAQ5H,SAAgB,EAAiB,GAAc,GAAc,GAA2B;C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M,EAAK,KAAK,GAAM,EAAM,KAAK;AAIvC,EAHI,EAAG,WAAW,EAAK,KAAK,GAAK,cAAc,CAAC,IAC9C,EAAQ,KAAK,EAAI,EAEnB,EAAQ,KAAK,GAAG,EAAmB,GAAK,GAAU,IAAQ,EAAE,CAAC;;AAE/D,QAAO"}
1
+ {"version":3,"file":"vite.js","names":[],"sources":["../src/pico8/vitePlugin.ts","../src/vite.ts"],"sourcesContent":["import type { Plugin, ResolvedConfig } from \"vite\"\nimport { execFileSync } from \"child_process\"\nimport path from \"path\"\nimport fs from \"fs\"\nimport { puzzmoLua } from \"./lua\"\n\nexport type PuzzmoPico8PluginOptions = {\n /** The cart, relative to the page. Defaults to the only `.p8` file in `cart/`. */\n cart?: string\n /** Where PICO-8's HTML export lives, relative to the page. Defaults to `export`. Commit it, so builds don't need PICO-8. */\n exportDir?: string\n /**\n * The PICO-8 binary used to re-export the cart when it changes. Defaults to `$PICO8`, then `pico8` on your PATH,\n * then where PICO-8's installers put it. When it can't be found the committed export is used as-is. Pass false to\n * never export.\n */\n pico8?: string | false\n /** Keep `puzzmo.lua` next to the cart up to date. Defaults to true. */\n writeLua?: boolean\n}\n\n/** @internal */\nexport type Pico8Game = {\n /** The directory holding the page */\n dir: string\n cart: string\n /** The cart's name, which PICO-8 also uses for its export */\n name: string\n exportHTML: string\n exportJS: string\n}\n\n/** @internal Finds the PICO-8 game served by the page in `dir`, if there is one. */\nexport function findPico8Game(dir: string, options: PuzzmoPico8PluginOptions = {}): Pico8Game | null {\n let cart: string | undefined\n if (options.cart) cart = path.resolve(dir, options.cart)\n else {\n const cartDir = path.join(dir, \"cart\")\n const carts = fs.existsSync(cartDir) ? fs.readdirSync(cartDir).filter((f) => f.endsWith(\".p8\")) : []\n if (carts.length > 1) throw new Error(`[puzzmo-pico8] found ${carts.length} carts in ${cartDir}, pick one with the \\`cart\\` option`)\n if (carts.length === 1) cart = path.join(cartDir, carts[0])\n }\n if (!cart || !fs.existsSync(cart)) return null\n const name = path.basename(cart, \".p8\")\n const exportDir = path.resolve(dir, options.exportDir ?? \"export\")\n return { dir, cart, name, exportHTML: path.join(exportDir, `${name}.html`), exportJS: path.join(exportDir, `${name}.js`) }\n}\n\n/**\n * @internal\n * Turns PICO-8's exported page into a Puzzmo game's page. PICO-8's shell is a thousand lines of globals and handlers\n * its runtime expects to find, and it changes between versions, so rather than keep a copy we adjust theirs.\n */\nexport function patchPico8Export(html: string, name: string, scripts: string[]): string {\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\n // PICO-8 loads its runtime from a script element it builds itself. Point it at the copy we serve next to the page,\n // relative because Puzzmo serves games from a subfolder.\n const runtime = new RegExp(`((?:\\\\.src\\\\s*=\\\\s*|\\\\ssrc=)[\"'])[^\"']*${escaped}\\\\.js([\"'])`)\n if (!runtime.test(html)) throw new Error(`[puzzmo-pico8] couldn't find where PICO-8's page loads ${name}.js`)\n html = html.replace(runtime, `$1./${name}.js$2`)\n\n // Boot straight away. Otherwise the cart waits for a click on PICO-8's play button and the host never hears that\n // the game loaded. (Browsers which need a tap before audio can start, like iOS Safari, still show the button.)\n html = html.replace(/var\\s+p8_autoplay\\s*=\\s*false/, \"var p8_autoplay = true\")\n\n // The GPIO array, for shells old enough not to declare it themselves.\n if (!/var\\s+pico8_gpio\\s*=/.test(html)) html = html.replace(/<head>/i, \"<head>\\n<script>var pico8_gpio = new Array(128)</script>\")\n\n // Things a browser shrugs off and Vite doesn't: an HTML comment wrapped around the stylesheet, a stray\n // `-repeat center;` in it, and an `&nbsp` without its semicolon.\n html = html.replace(\n /(<style[^>]*>)([\\s\\S]*?)(<\\/style>)/gi,\n (_, open: string, css: string, close: string) =>\n open + css.replace(/<!--|-->/g, \"\").replace(/^[ \\t]*-repeat[^;\\n]*;[ \\t]*$/gm, \"\") + close,\n )\n html = html.replace(/&nbsp(?!;)/g, \"&nbsp;\")\n\n const bodyEnd = html.lastIndexOf(\"</body>\")\n if (bodyEnd === -1) throw new Error(\"[puzzmo-pico8] that doesn't look like a PICO-8 export, it has no </body>\")\n return html.slice(0, bodyEnd) + scripts.join(\"\\n\") + \"\\n\" + html.slice(bodyEnd)\n}\n\n/** Where PICO-8's own installers put it, for people who never added it to their PATH. */\nconst usualPico8Locations = [\n \"/Applications/PICO-8.app/Contents/MacOS/pico8\",\n \"C:\\\\Program Files (x86)\\\\PICO-8\\\\pico8.exe\",\n \"C:\\\\Program Files\\\\PICO-8\\\\pico8.exe\",\n]\n\n/** Finds an executable on the PATH without running it: `pico8` with no export arguments opens the whole app. */\nconst findExecutable = (bin: string): string | null => {\n if (bin.includes(\"/\") || bin.includes(\"\\\\\")) return fs.existsSync(bin) ? bin : null\n for (const dir of (process.env.PATH ?? \"\").split(path.delimiter)) {\n for (const ext of process.platform === \"win32\" ? [\".exe\", \".cmd\", \"\"] : [\"\"]) {\n const candidate = path.join(dir, bin + ext)\n if (fs.existsSync(candidate)) return candidate\n }\n }\n if (bin === \"pico8\") return usualPico8Locations.find((p) => fs.existsSync(p)) ?? null\n return null\n}\n\nconst mtime = (file: string) => (fs.existsSync(file) ? fs.statSync(file).mtimeMs : 0)\n\n/**\n * Vite plugin for games written as PICO-8 carts. Your `index.html` only needs your own script tag, the plugin swaps\n * in PICO-8's exported page around it, serves the PICO-8 runtime next to it, and copies it into the build.\n *\n * When PICO-8 is installed it also re-exports the cart whenever it (or a `.lua` file next to it) changes, and reloads\n * the page, so saving in PICO-8 is enough to see the change in the simulator.\n */\nexport function puzzmoPico8(options: PuzzmoPico8PluginOptions = {}): Plugin {\n let config: ResolvedConfig\n const games = new Map<string, Pico8Game>()\n const binary = options.pico8 === false ? null : (options.pico8 ?? process.env.PICO8 ?? \"pico8\")\n\n const log = (message: string) => config.logger.info(`\\x1b[33m\\x1b[1m PICO-8 \\x1b[22m\\x1b[39m${message}`)\n\n const writeLua = (game: Pico8Game) => {\n if (options.writeLua === false) return\n const file = path.join(path.dirname(game.cart), \"puzzmo.lua\")\n if (fs.existsSync(file) && fs.readFileSync(file, \"utf8\") === puzzmoLua) return\n fs.writeFileSync(file, puzzmoLua)\n log(`wrote ${path.relative(config.root, file)}`)\n }\n\n /** Re-exports the cart when it's newer than the export and PICO-8 is around to do it. */\n const exportIfStale = (game: Pico8Game) => {\n const cartDir = path.dirname(game.cart)\n const newest = Math.max(\n ...fs\n .readdirSync(cartDir)\n .filter((f) => /\\.(p8|lua)$/.test(f))\n .map((f) => mtime(path.join(cartDir, f))),\n )\n if (fs.existsSync(game.exportJS) && mtime(game.exportJS) >= newest) return\n\n const pico8 = binary ? findExecutable(binary) : null\n if (!pico8) {\n if (fs.existsSync(game.exportHTML)) {\n config.logger.warn(\n `[puzzmo-pico8] ${path.relative(config.root, game.cart)} is newer than its export, and PICO-8 isn't around to re-export it. Using the old export.`,\n )\n return\n }\n throw new Error(\n `[puzzmo-pico8] there's no export of ${path.relative(config.root, game.cart)} yet, and PICO-8 isn't on your PATH to make one.\\n` +\n `Export it inside PICO-8 with EXPORT ${game.name}.html into ${path.relative(config.root, path.dirname(game.exportHTML))}/, or set PICO8=/path/to/pico8.`,\n )\n }\n\n fs.mkdirSync(path.dirname(game.exportHTML), { recursive: true })\n const before = mtime(game.exportJS)\n let output = \"\"\n try {\n output = execFileSync(pico8, [game.cart, \"-export\", game.exportHTML], {\n encoding: \"utf8\",\n timeout: 60_000,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n })\n } catch (error) {\n output = String((error as { stdout?: string }).stdout ?? error)\n }\n if (mtime(game.exportJS) === before) {\n const hint = /label/i.test(output) ? \"\\nHTML exports need a label: run the cart in PICO-8, press CTRL-7, and save.\" : \"\"\n throw new Error(`[puzzmo-pico8] PICO-8 didn't export ${path.relative(config.root, game.cart)}:\\n${output.trim()}${hint}`)\n }\n log(`exported ${path.relative(config.root, game.cart)}`)\n }\n\n const gameForPage = (htmlFile: string) => {\n const dir = path.dirname(htmlFile)\n if (!games.has(dir)) {\n const game = findPico8Game(dir, options)\n if (!game) return null\n games.set(dir, game)\n }\n return games.get(dir)!\n }\n\n return {\n name: \"puzzmo-pico8\",\n\n config() {\n // The export is rewritten on every save, and Vite reloads the page for any .html it sees change. The plugin\n // reloads once the export is done, so Vite reloading too would boot the cart twice.\n const exportDir = options.exportDir ?? \"export\"\n const isExport = (file: string) =>\n /\\.(html|js)$/.test(file) &&\n path.basename(path.dirname(file)) === path.basename(exportDir) &&\n fs.existsSync(path.join(path.dirname(path.dirname(file)), \"cart\"))\n return { server: { watch: { ignored: [isExport] } } }\n },\n\n configResolved(resolved) {\n config = resolved\n },\n\n transformIndexHtml: {\n order: \"pre\",\n handler(html, ctx) {\n const game = gameForPage(ctx.filename)\n if (!game) return\n writeLua(game)\n exportIfStale(game)\n // Keep the page's own module scripts: that's the game code.\n const scripts = html.match(/<script\\b[^>]*type=[\"']module[\"'][^>]*>[\\s\\S]*?<\\/script>/gi) ?? []\n return patchPico8Export(fs.readFileSync(game.exportHTML, \"utf8\"), game.name, scripts)\n },\n },\n\n configureServer(devServer) {\n // Serve the runtime next to the page, untouched by Vite's transforms: it is a megabyte of emscripten output\n // which only works exactly as PICO-8 wrote it.\n devServer.middlewares.use((req, res, next) => {\n const url = decodeURIComponent((req.url ?? \"\").split(\"?\")[0])\n if (!url.endsWith(\".js\")) return next()\n const game = [...games.values()].find(\n (g) =>\n url ===\n \"/\" +\n path\n .relative(config.root, path.join(g.dir, `${g.name}.js`))\n .split(path.sep)\n .join(\"/\"),\n )\n if (!game || !fs.existsSync(game.exportJS)) return next()\n res.setHeader(\"Content-Type\", \"text/javascript\")\n res.end(fs.readFileSync(game.exportJS))\n })\n\n // Saving the cart in PICO-8 re-exports it and reloads the page.\n devServer.watcher.on(\"change\", (file) => {\n const game = [...games.values()].find((g) => path.dirname(file) === path.dirname(g.cart) && /\\.(p8|lua)$/.test(file))\n if (!game || path.basename(file) === \"puzzmo.lua\") return\n try {\n exportIfStale(game)\n devServer.ws.send({ type: \"full-reload\" })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n config.logger.error(message)\n devServer.ws.send({ type: \"error\", err: { message, stack: \"\" } })\n }\n })\n },\n\n generateBundle() {\n for (const game of games.values()) {\n const fileName = path\n .relative(config.root, path.join(game.dir, `${game.name}.js`))\n .split(path.sep)\n .join(\"/\")\n this.emitFile({ type: \"asset\", fileName, source: fs.readFileSync(game.exportJS) })\n }\n },\n }\n}\n","import type { Plugin, ResolvedConfig } from \"vite\"\nimport { build } from \"vite\"\nimport path from \"path\"\nimport fs from \"fs\"\nimport type { HostContext } from \"./types\"\nimport type { HostContextPreset, SimulatorIntegrations } from \"./simulator/types\"\n\nexport { puzzmoPico8, type PuzzmoPico8PluginOptions } from \"./pico8/vitePlugin\"\n\nexport type PuzzmoSimulatorPluginOptions = {\n /** Whether to auto-start the game after READY (default: true) */\n autoStart?: boolean\n /** Initial collapsed state (default: true) */\n collapsed?: boolean\n /**\n * Glob pattern for fixture files, passed to import.meta.glob which is relative to the closest puzzmo.json. Defaults\n * to `\"/fixtures/puzzles/**\\/*.{json,toml}\"`. Fixtures are loaded as raw strings (any text format works — JSON,\n * TOML, or a custom format) and delivered to the game verbatim, so the game parses them itself. Pass false to disable.\n */\n fixturesGlob?: string | false\n /**\n * Whether READY_DATA carries a play session (default: true). Set to false to run the game the way\n * a host will for a mode with no puzzle. Ignored for games built on an SDK from before runtime contract \"1.1\".\n */\n session?: boolean\n /**\n * The `hostContext` array the simulator sends in READY_DATA, so host-context-dependent features\n * (embed settings, sandbox mode, mobile layout, …) can be exercised locally. Must be\n * JSON-serializable. Defaults to a single desktop \"app\" context; the simulator's Host tab can\n * override it at runtime (persisted per-browser, applied on restart).\n *\n * @internal\n */\n hostContext?: HostContext[]\n /**\n * Extra named `hostContext` presets for the simulator's Host tab, alongside the generic\n * built-ins — how a game ships its own scenarios (e.g. crossword's partner-embed toolbar\n * settings). Must be JSON-serializable.\n *\n * @internal\n */\n hostContextPresets?: HostContextPreset[]\n /**\n * Plugin-provided simulator tabs, named rather than passed directly because this config is\n * serialized into a virtual module. Each entry is imported and called with no arguments, so the\n * export must be a `() => SimulatorView` factory — e.g.\n * `{ module: \"@puzzmo-com/shared/sdkPlugins\", export: \"createCollabSimulatorView\" }`.\n */\n viewFactories?: { module: string; export: string }[]\n}\n\nconst simulatorURL = \"/@puzzmo-simulator-init.js\"\nconst virtualID = \"virtual:puzzmo-simulator\"\n\n/** @internal */\nexport type GameInfo = {\n /** Directory containing the puzzmo.json */\n dir: string\n slug: string\n displayName: string\n /** Vite-root-relative path to app bundle entry, if it exists */\n appBundlePath: string | null\n /** Vite-root-relative path to the pmmg bundle entry, if it exists, for the simulator's Pmmg tab */\n pmmgBundlePath?: string | null\n /** `integrations` from the puzzmo.json, passed to simulator tabs that preview them */\n integrations?: SimulatorIntegrations\n}\n\n/**\n * Discover all games from puzzmo.json files under a root directory.\n *\n * @internal\n */\nexport function discoverGames(viteRoot: string): Map<string, GameInfo> {\n const games = new Map<string, GameInfo>()\n const candidates = findPuzzmoJsonDirs(viteRoot, 3)\n if (fs.existsSync(path.join(viteRoot, \"puzzmo.json\"))) {\n candidates.unshift(viteRoot)\n }\n for (const dir of candidates) {\n try {\n const data = JSON.parse(fs.readFileSync(path.join(dir, \"puzzmo.json\"), \"utf-8\"))\n if (!data?.game?.slug) continue\n const integrations = data.integrations && typeof data.integrations === \"object\" ? data.integrations : undefined\n games.set(data.game.slug, {\n dir,\n slug: data.game.slug,\n displayName: data.game.displayName,\n appBundlePath: viteRootPath(viteRoot, resolveBundleEntry(dir, \"src/appBundle\")),\n pmmgBundlePath: viteRootPath(viteRoot, resolveBundleEntry(dir, \"src/pmmgBundle\")),\n integrations,\n })\n } catch {\n // skip invalid files\n }\n }\n return games\n}\n\n/**\n * Resolve which game a request belongs to using the referer URL.\n *\n * @internal\n */\nexport function resolveGameFromReferer(referer: string | undefined, games: Map<string, GameInfo>, viteRoot: string): GameInfo | undefined {\n if (referer) {\n try {\n const refPath = new URL(referer).pathname\n for (const g of games.values()) {\n const relDir = \"/\" + path.relative(viteRoot, g.dir).split(path.sep).join(\"/\")\n if (refPath.startsWith(relDir + \"/\") || refPath === relDir) return g\n }\n } catch {\n // ignore malformed referer\n }\n }\n if (games.size === 1) return games.values().next().value\n return undefined\n}\n\n/**\n * Generate the virtual module code for the simulator.\n *\n * @internal\n */\nexport function generateSimulatorCode(options: PuzzmoSimulatorPluginOptions, game: GameInfo | undefined): string {\n const { fixturesGlob: fixturesOpt, viewFactories, ...config } = options\n const fixturesGlob = fixturesOpt === false ? null : (fixturesOpt ?? \"/fixtures/puzzles/**/*.{json,toml}\")\n\n const lines = [`import { createSimulator } from \"@puzzmo/sdk/simulator\"`]\n for (const view of viewFactories ?? []) {\n lines.push(`import { ${view.export} } from ${JSON.stringify(view.module)}`)\n }\n\n // Load fixtures as raw strings so any text format reaches the game verbatim; the game does its own parsing.\n if (fixturesGlob) {\n lines.push(`const fixtures = import.meta.glob(${JSON.stringify(fixturesGlob)}, { query: \"?raw\", import: \"default\", eager: true })`)\n }\n\n if (game?.appBundlePath) {\n lines.push(`import(${JSON.stringify(game.appBundlePath)}).then(m => {`)\n lines.push(` if (m.renderThumbnail) globalThis.renderThumbnail = m.renderThumbnail`)\n lines.push(` if (m.getShareString) globalThis.getShareString = m.getShareString`)\n lines.push(`}).catch(() => {})`)\n }\n\n const simConfig = {\n ...config,\n ...(game?.slug ? { slug: game.slug } : {}),\n ...(game?.integrations ? { integrations: game.integrations } : {}),\n }\n const configEntries = Object.entries(simConfig).filter(([, v]) => v !== undefined)\n const configParts = configEntries.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)\n if (fixturesGlob) configParts.push(\"fixtures\")\n // Loaded when the Pmmg tab opens, so a game page that never looks at it never imports it\n if (game?.pmmgBundlePath) configParts.push(`pmmgBundle: () => import(${JSON.stringify(game.pmmgBundlePath)})`)\n if (viewFactories?.length) configParts.push(`views: [${viewFactories.map((v) => `${v.export}()`).join(\", \")}]`)\n\n lines.push(`createSimulator({ ${configParts.join(\", \")} })`)\n\n return lines.join(\"\\n\")\n}\n\n/** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */\nexport function puzzmoSimulator(options: PuzzmoSimulatorPluginOptions = {}): Plugin {\n let games = new Map<string, GameInfo>()\n let viteRoot: string\n\n return {\n name: \"puzzmo-simulator\",\n apply: \"serve\",\n\n configResolved(config: ResolvedConfig) {\n viteRoot = config.root\n games = discoverGames(viteRoot)\n\n if (games.size === 0) {\n config.logger.info(`\\x1b[33m\\x1b[1m PUZZMO \\x1b[22m\\x1b[39m\\x1b[2m no puzzmo.json files found\\x1b[22m`)\n } else {\n const names = [...games.values()].map((g) => `\\x1b[36m${g.slug}\\x1b[39m`)\n const label = games.size === 1 ? \"game\" : \"games\"\n config.logger.info(`\\x1b[33m\\x1b[1m PUZZMO \\x1b[22m\\x1b[39m found ${games.size} ${label}: ${names.join(\"\\x1b[2m, \\x1b[22m\")}`)\n }\n },\n\n resolveId(id) {\n if (id === virtualID || id.startsWith(virtualID + \"?\")) return \"\\0\" + id\n },\n\n load(id) {\n if (!id.startsWith(\"\\0\" + virtualID)) return\n const params = new URLSearchParams(id.split(\"?\")[1] || \"\")\n const gameSlug = params.get(\"game\")\n const game = gameSlug ? games.get(gameSlug) : games.size === 1 ? games.values().next().value : undefined\n return generateSimulatorCode(options, game)\n },\n\n configureServer(server) {\n // Re-read puzzmo.json on edit and reload the page so the simulator picks up its changes\n for (const g of games.values()) server.watcher.add(path.join(g.dir, \"puzzmo.json\"))\n server.watcher.on(\"change\", (file) => {\n if (path.basename(file) !== \"puzzmo.json\") return\n games = discoverGames(viteRoot)\n for (const mod of server.moduleGraph.idToModuleMap.values()) {\n if (mod.id?.startsWith(\"\\0\" + virtualID)) server.moduleGraph.invalidateModule(mod)\n }\n server.ws.send({ type: \"full-reload\" })\n })\n\n server.middlewares.use(\"/oauth/callback\", (_req, res) => {\n res.setHeader(\"Content-Type\", \"text/html\")\n res.end(`<!DOCTYPE html>\n<html><head><title>Puzzmo OAuth</title></head>\n<body><script>\nvar params = new URLSearchParams(window.location.search);\nvar returnUrl = sessionStorage.getItem(\"oauth_return_url\") || \"/\";\nvar url = new URL(returnUrl);\nparams.forEach(function(v, k) { url.searchParams.set(k, v); });\nwindow.location.href = url.toString();\n</script></body></html>`)\n })\n\n // Serve the simulator init module, resolving the game from the referer\n server.middlewares.use(async (req, res, next) => {\n if (req.url?.split(\"?\")[0] !== simulatorURL) return next()\n\n const game = resolveGameFromReferer(req.headers.referer, games, viteRoot)\n const moduleID = virtualID + (game ? `?game=${game.slug}` : \"\")\n const result = await server.transformRequest(moduleID)\n if (!result) return next()\n res.setHeader(\"Content-Type\", \"application/javascript\")\n res.end(result.code)\n })\n },\n\n transformIndexHtml() {\n return [\n {\n tag: \"script\",\n attrs: { type: \"module\", src: simulatorURL },\n injectTo: \"head\",\n },\n ]\n },\n }\n}\n\ntype BundlePluginOptions = {\n /** Entry file for the bundle */\n entry: string\n /** Output file name */\n outputFile: string\n /** Folder the bundle is written to */\n outDir: string\n}\n\nfunction createBundlePlugin(pluginName: string, defaults: BundlePluginOptions) {\n return (options: Partial<BundlePluginOptions> = {}): Plugin => {\n const { entry, outputFile, outDir } = { ...defaults, ...options }\n return {\n name: pluginName,\n apply: \"build\",\n async closeBundle() {\n // If the caller overrode `entry`, honor it as-is. Otherwise try `.js` first, then `.ts`.\n const resolvedEntry = options.entry\n ? path.isAbsolute(entry)\n ? entry\n : path.resolve(process.cwd(), entry)\n : (resolveBundleEntry(process.cwd(), stripBundleExt(entry)) ?? path.resolve(process.cwd(), entry))\n try {\n await build({\n configFile: false,\n logLevel: \"warn\",\n build: {\n lib: {\n entry: resolvedEntry,\n formats: [\"es\"],\n fileName: () => outputFile,\n },\n outDir,\n emptyOutDir: false,\n },\n })\n } catch (error) {\n console.error(`[${pluginName}] build failed:`, error)\n throw error\n }\n },\n }\n }\n}\n\n/** Strip the trailing extension from a default entry path so we can probe siblings. */\nconst stripBundleExt = (p: string) => p.replace(/\\.[jt]sx?$/i, \"\")\n\n/** An absolute file as the path the dev server serves it at, or null for no file */\nconst viteRootPath = (viteRoot: string, file: string | null) =>\n file ? \"/\" + path.relative(viteRoot, file).split(path.sep).join(\"/\") : null\n\n/** Returns the absolute path to the first matching extension under `dir`, or null. */\nconst resolveBundleEntry = (dir: string, baseRelative: string): string | null => {\n // JSX last: a bundle written as JSX still needs the plain entry to win if both somehow exist.\n for (const ext of [\".js\", \".ts\", \".tsx\", \".jsx\"]) {\n const candidate = path.join(dir, baseRelative + ext)\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n\nexport type AppBundlePluginOptions = {\n /** Entry file for the app bundle (default: `src/appBundle.js`) */\n entry?: string\n /** Output file name (default: `app-bundle.js`) */\n outputFile?: string\n}\n\n/**\n * Vite plugin that produces dist/app-bundle.js after the main build for app-level integrations.\n *\n * The bundle exports `renderThumbnail(puzzleString, inputString?, config?)` — a pure renderer\n * returning the SVG and its dimensions (`{ svg, width, height }`), used by the Puzzmo\n * platform for puzzle previews.\n */\nexport const appBundlePlugin = createBundlePlugin(\"app-bundle\", { entry: \"src/appBundle.js\", outputFile: \"app-bundle.js\", outDir: \"dist\" })\n\nexport type ServerBundlePluginOptions = {\n /** Entry file for the server bundle (default: `src/serverBundle.js`, or `.ts`) */\n entry?: string\n /** Output file name (default: `server-bundle.js`) */\n outputFile?: string\n}\n\n/**\n * Vite plugin that produces dist-server/server-bundle.js after the main build: the game's private\n * server bundle (see `ServerBundle`). It goes in its own folder, never `dist`, so it can't be served to\n * players by mistake; `puzzmo games upload` finds it there and sends it to Puzzmo privately. A repo that\n * builds several games gives each its own `outputFile` and names it in that game's puzzmo.json as\n * `output.serverBundle`, since uploads refuse to send one file for more than one game.\n */\nexport const serverBundlePlugin = createBundlePlugin(\"server-bundle\", {\n entry: \"src/serverBundle.js\",\n outputFile: \"server-bundle.js\",\n outDir: \"dist-server\",\n})\n\nexport type PmmgBundlePluginOptions = {\n /** Entry file for the pmmg bundle (default: `src/pmmgBundle.js`, or `.ts`) */\n entry?: string\n /** Output file name (default: `pmmg-bundle.js`) */\n outputFile?: string\n}\n\nconst buildPmmgBundle = createBundlePlugin(\"pmmg-bundle\", { entry: \"src/pmmgBundle.js\", outputFile: \"pmmg-bundle.js\", outDir: \"dist\" })\n\n/**\n * Vite plugins for the game's pmmg bundle (see `PmmgBundle`), such as its boards at the table. After the main build\n * they produce dist/pmmg-bundle.js, which is public and served with the rest of `dist`. In dev, `/pmmg-bundle.js` on\n * the game's dev server is built from source on each request, so a Puzzmo page running with `?dev` draws boards from\n * the code being worked on.\n *\n * Puzzmo imports it from an opaque-origin sandbox, so that one response answers any origin. It's a whole build rather\n * than the dev server's modules, since letting `Origin: null` read those would let any page read the game's source.\n */\nexport const pmmgBundlePlugin = (options: PmmgBundlePluginOptions = {}): Plugin[] => [\n buildPmmgBundle(options),\n {\n name: \"pmmg-bundle-dev\",\n apply: \"serve\",\n configureServer(server) {\n // Requests that arrive while a build runs share it\n let building: Promise<string> | undefined\n server.middlewares.use((req, res, next) => {\n if (!/^\\/pmmg-bundle\\.js(?:\\?.*)?$/.test(req.url || \"\")) return next()\n const entry = options.entry ?? resolveBundleEntry(server.config.root, \"src/pmmgBundle\")\n if (!entry) return next()\n building ??= buildPmmgBundleSource(path.resolve(server.config.root, entry)).finally(() => (building = undefined))\n building.then(\n (code) => {\n res.setHeader(\"Content-Type\", \"text/javascript\")\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\")\n res.setHeader(\"Cache-Control\", \"no-store\")\n res.end(code)\n },\n (error) => {\n server.config.logger.error(`[pmmg-bundle] build failed: ${error?.message ?? error}`)\n res.statusCode = 500\n res.end()\n },\n )\n })\n },\n },\n]\n\n/** The pmmg bundle built as production builds it, as one file's source for the dev route */\nexport const buildPmmgBundleSource = async (entry: string): Promise<string> => {\n const result = await build({\n configFile: false,\n logLevel: \"warn\",\n build: {\n write: false,\n copyPublicDir: false,\n minify: false,\n sourcemap: \"inline\",\n lib: { entry, formats: [\"es\"], fileName: () => \"pmmg-bundle.js\" },\n // One file, as the route serves only the one\n rolldownOptions: { output: { codeSplitting: false } },\n },\n })\n const outputs = Array.isArray(result) ? result : \"output\" in result ? [result] : []\n const chunk = outputs.flatMap((output) => output.output).find((file) => file.type === \"chunk\" && file.isEntry)\n if (!chunk || chunk.type !== \"chunk\") throw new Error(`Building ${entry} made no bundle`)\n return chunk.code\n}\n\nexport type EditorBundlePluginOptions = {\n /** Entry file for the editor bundle (default: `src/editorBundle.js`) */\n entry?: string\n /** Output file name (default: `editor-bundle.js`) */\n outputFile?: string\n}\n\n/** Vite plugin that produces dist/editor-bundle.js after the main build for editor-level integrations. */\nexport const editorBundlePlugin = createBundlePlugin(\"editor-bundle\", {\n entry: \"src/editorBundle.js\",\n outputFile: \"editor-bundle.js\",\n outDir: \"dist\",\n})\n\n/**\n * Recursively find directories containing puzzmo.json, up to `maxDepth` levels deep.\n *\n * @internal\n */\nexport const findPuzzmoJsonDirs = (root: string, maxDepth: number, depth = 0): string[] => {\n if (depth >= maxDepth) return []\n const results: string[] = []\n let entries: fs.Dirent[]\n try {\n entries = fs.readdirSync(root, { withFileTypes: true })\n } catch {\n return results\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name.startsWith(\".\") || entry.name === \"node_modules\") continue\n const dir = path.join(root, entry.name)\n if (fs.existsSync(path.join(dir, \"puzzmo.json\"))) {\n results.push(dir)\n }\n results.push(...findPuzzmoJsonDirs(dir, maxDepth, depth + 1))\n }\n return results\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAgB,EAAc,GAAa,IAAoC,EAAE,EAAoB;;CACnG,IAAI;AACJ,KAAI,EAAQ,KAAM,KAAO,EAAK,QAAQ,GAAK,EAAQ,KAAK;MACnD;EACH,IAAM,IAAU,EAAK,KAAK,GAAK,OAAO,EAChC,IAAQ,EAAG,WAAW,EAAQ,GAAG,EAAG,YAAY,EAAQ,CAAC,QAAQ,MAAM,EAAE,SAAS,MAAM,CAAC,GAAG,EAAE;AACpG,MAAI,EAAM,SAAS,EAAG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P,eAAe;IACf,QAAQ;IACR,WAAW;IACX,KAAK;KAAE;KAAO,SAAS,CAAC,KAAK;KAAE,gBAAgB;KAAkB;IAEjE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,IAAO,EAAE;IACtD;GACF,CAAC,EAEI,KADU,MAAM,QAAQ,EAAO,GAAG,IAAS,YAAY,IAAS,CAAC,EAAO,GAAG,EAAE,EAC7D,SAAS,MAAW,EAAO,OAAO,CAAC,MAAM,MAAS,EAAK,SAAS,WAAW,EAAK,QAAQ;AAC9G,MAAI,CAAC,KAAS,EAAM,SAAS,QAAS,OAAU,MAAM,YAAY,EAAM,iBAAiB;AACzF,SAAO,EAAM;;iBAjB6B,GAAA;;;KA4B/B,IAAqB,EAAmB,iBAAiB;CACpE,OAAO;CACP,YAAY;CACZ,QAAQ;CACT,CAAC,EAOW,KAAsB,GAAc,GAAkB,IAAQ,MAAgB;AACzF,KAAI,KAAS,EAAU,QAAO,EAAE;CAChC,IAAM,IAAoB,EAAE,EACxB;AACJ,KAAI;AACF,MAAU,EAAG,YAAY,GAAM,EAAE,eAAe,IAAM,CAAC;aACjD;AACN,SAAO;;AAET,MAAK,IAAM,KAAS,GAAS;AAC3B,MAAI,CAAC,EAAM,aAAa,IAAI,EAAM,KAAK,WAAW,IAAI,IAAI,EAAM,SAAS,eAAgB;EACzF,IAAM,IAAM,EAAK,KAAK,GAAM,EAAM,KAAK;AAIvC,EAHI,EAAG,WAAW,EAAK,KAAK,GAAK,cAAc,CAAC,IAC9C,EAAQ,KAAK,EAAI,EAEnB,EAAQ,KAAK,GAAG,EAAmB,GAAK,GAAU,IAAQ,EAAE,CAAC;;AAE/D,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puzzmo/sdk",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "description": "Puzzmo runtime SDK for game developers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -59,10 +59,10 @@
59
59
  "import": "./dist/vite.js",
60
60
  "require": "./dist/vite.cjs"
61
61
  },
62
- "./thumbnail-motion": {
63
- "types": "./dist/thumbnailMotion.d.ts",
64
- "import": "./dist/thumbnailMotion.js",
65
- "require": "./dist/thumbnailMotion.cjs"
62
+ "./table-board": {
63
+ "types": "./dist/tableBoard.d.ts",
64
+ "import": "./dist/tableBoard.js",
65
+ "require": "./dist/tableBoard.cjs"
66
66
  }
67
67
  },
68
68
  "files": [