@puzzmo/sdk 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{createSimulator-BZYymqOG.js → createSimulator-D4oY1VzY.js} +236 -233
- package/dist/{createSimulator-BZYymqOG.js.map → createSimulator-D4oY1VzY.js.map} +1 -1
- package/dist/{createSimulator-Ctg-fdCI.cjs → createSimulator-_TBV3Yo7.cjs} +30 -30
- package/dist/{createSimulator-Ctg-fdCI.cjs.map → createSimulator-_TBV3Yo7.cjs.map} +1 -1
- package/dist/simulator/createSimulator.d.ts +8 -7
- package/dist/simulator/createSimulator.d.ts.map +1 -1
- package/dist/simulator/index.cjs +1 -1
- package/dist/simulator/index.js +1 -1
- package/dist/simulator/standalone.cjs +1 -1
- package/dist/simulator/standalone.cjs.map +1 -1
- package/dist/simulator/standalone.js +4 -4
- package/dist/simulator/standalone.js.map +1 -1
- package/dist/simulator/types.d.ts +0 -2
- package/dist/simulator/types.d.ts.map +1 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +0 -2
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,15 +6,16 @@
|
|
|
6
6
|
* - Sending READY_DATA with puzzle data
|
|
7
7
|
* - Providing UI controls for START_GAME, PAUSE_GAME, RESUME_GAME, RETRY_PUZZLE
|
|
8
8
|
*
|
|
9
|
-
* Usage
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* Usage with Vite plugin (recommended):
|
|
10
|
+
* ```ts
|
|
11
|
+
* // vite.config.ts
|
|
12
|
+
* import { puzzmoSimulator } from "@puzzmo/sdk/vite"
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [puzzmoSimulator({ slug: "my-game", fixturesGlob: "./fixtures/puzzles/**\/*.json" })]
|
|
15
|
+
* })
|
|
15
16
|
* ```
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
+
* Usage with manual imports:
|
|
18
19
|
* ```html
|
|
19
20
|
* <script type="module">
|
|
20
21
|
* import { createSimulator } from "@puzzmo/sdk/simulator"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSimulator.d.ts","sourceRoot":"","sources":["../../src/simulator/createSimulator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"createSimulator.d.ts","sourceRoot":"","sources":["../../src/simulator/createSimulator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EAAE,eAAe,EAA4D,cAAc,EAAE,MAAM,SAAS,CAAA;AAkBxH,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,CAAA;AAG/C,UAAU,iBAAiB;IACzB,cAAc,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAA;IAClD,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAA;IAC1C,UAAU,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;CAC/B;AAGD;;;GAGG;AACH,iBAAS,eAAe,CAAC,MAAM,GAAE,eAAoB,GAAG,iBAAiB,CA2gBxE;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/simulator/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../createSimulator-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../createSimulator-_TBV3Yo7.cjs`);exports.createSimulator=e.t;
|
package/dist/simulator/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../createSimulator-
|
|
1
|
+
import { t as e } from "../createSimulator-D4oY1VzY.js";
|
|
2
2
|
export { e as createSimulator };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../createSimulator-
|
|
1
|
+
const e=require(`../createSimulator-_TBV3Yo7.cjs`);var t=()=>{var t;e.t((t=window.SIMULATOR_CONFIG)==null?{}:t)};document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,t):t();
|
|
2
2
|
//# sourceMappingURL=standalone.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone.cjs","names":[],"sources":["../../src/simulator/standalone.ts"],"sourcesContent":["/**\n * Standalone entry point for the simulator.\n *\n * Use as
|
|
1
|
+
{"version":3,"file":"standalone.cjs","names":[],"sources":["../../src/simulator/standalone.ts"],"sourcesContent":["/**\n * Standalone entry point for the simulator.\n *\n * Use as a script tag for non-Vite setups:\n * ```html\n * <script>\n * window.SIMULATOR_CONFIG = { slug: \"my-game\" }\n * </script>\n * <script src=\"https://cdn.jsdelivr.net/npm/@puzzmo/sdk/dist/simulator/standalone.js\"></script>\n * ```\n */\nimport { createSimulator } from \"./createSimulator\"\nimport type { SimulatorConfig } from \"./types\"\n\ndeclare global {\n interface Window {\n SIMULATOR_CONFIG?: SimulatorConfig\n }\n}\n\nconst init = () => {\n const config = window.SIMULATOR_CONFIG ?? {}\n createSimulator(config)\n}\n\nif (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", init)\n} else {\n init()\n}\n"],"mappings":"mDAoBA,IAAM,MAAa,OAEjB,EAAA,GAAA,EADe,OAAO,mBAAA,KAAoB,EAAE,CAAtB,EACC,EAGrB,SAAS,aAAe,UAC1B,SAAS,iBAAiB,mBAAoB,EAAK,CAEnD,GAAM"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { t as e } from "../createSimulator-
|
|
1
|
+
import { t as e } from "../createSimulator-D4oY1VzY.js";
|
|
2
2
|
/**
|
|
3
3
|
* Standalone entry point for the simulator.
|
|
4
4
|
*
|
|
5
|
-
* Use as
|
|
5
|
+
* Use as a script tag for non-Vite setups:
|
|
6
6
|
* ```html
|
|
7
7
|
* <script>
|
|
8
|
-
* window.SIMULATOR_CONFIG = {
|
|
8
|
+
* window.SIMULATOR_CONFIG = { slug: "my-game" }
|
|
9
9
|
* <\/script>
|
|
10
|
-
* <script src="
|
|
10
|
+
* <script src="https://cdn.jsdelivr.net/npm/@puzzmo/sdk/dist/simulator/standalone.js"><\/script>
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
var t = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone.js","names":[],"sources":["../../src/simulator/standalone.ts"],"sourcesContent":["/**\n * Standalone entry point for the simulator.\n *\n * Use as
|
|
1
|
+
{"version":3,"file":"standalone.js","names":[],"sources":["../../src/simulator/standalone.ts"],"sourcesContent":["/**\n * Standalone entry point for the simulator.\n *\n * Use as a script tag for non-Vite setups:\n * ```html\n * <script>\n * window.SIMULATOR_CONFIG = { slug: \"my-game\" }\n * </script>\n * <script src=\"https://cdn.jsdelivr.net/npm/@puzzmo/sdk/dist/simulator/standalone.js\"></script>\n * ```\n */\nimport { createSimulator } from \"./createSimulator\"\nimport type { SimulatorConfig } from \"./types\"\n\ndeclare global {\n interface Window {\n SIMULATOR_CONFIG?: SimulatorConfig\n }\n}\n\nconst init = () => {\n const config = window.SIMULATOR_CONFIG ?? {}\n createSimulator(config)\n}\n\nif (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", init)\n} else {\n init()\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAM,UAAa;;AAEjB,IAAA,IADe,OAAO,qBAAA,OAAoB,EAAE,GAAtB,EACC;;AAGrB,SAAS,eAAe,YAC1B,SAAS,iBAAiB,oBAAoB,EAAK,GAEnD,GAAM"}
|
|
@@ -4,8 +4,6 @@ export type FixtureImports = Record<string, {
|
|
|
4
4
|
default?: any;
|
|
5
5
|
}>;
|
|
6
6
|
export interface SimulatorConfig {
|
|
7
|
-
/** Path to the puzzle JSON file (default: "./sample-puzzle.json") */
|
|
8
|
-
puzzlePath?: string;
|
|
9
7
|
/** Whether to auto-start the game after READY (default: true) */
|
|
10
8
|
autoStart?: boolean;
|
|
11
9
|
/** Initial collapsed state (default: true) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/simulator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAExE,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC,CAAA;AAE9D,MAAM,WAAW,eAAe;IAC9B,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/simulator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAExE,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC,CAAA;AAE9D,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,oHAAoH;IACpH,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAE5B,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,GAAG,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IAC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AAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAA;IAChE,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAA;IAC9C,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,iCAAiC;IACjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,qBAAqB;IACrB,EAAE,EAAE,OAAO,CAAA;IACX,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,uCAAuC;IACvC,MAAM,IAAI,MAAM,CAAA;IAChB,wCAAwC;IACxC,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACrC,qCAAqC;IACrC,UAAU,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAC5C,yCAAyC;IACzC,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;CACrE"}
|
package/dist/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from \"vite\"\n\nexport type PuzzmoSimulatorPluginOptions = {\n /**
|
|
1
|
+
{"version":3,"file":"vite.cjs","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from \"vite\"\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 /** Game slug for API features (e.g. \"crossword\", \"my-game\") */\n slug?: string\n /** Glob pattern for fixture files, passed to import.meta.glob (e.g. \"./fixtures/puzzles/**\\/*.json\") */\n fixturesGlob?: string\n}\n\nconst SIMULATOR_URL = \"/@puzzmo-simulator-init.js\"\nconst VIRTUAL_ID = \"virtual:puzzmo-simulator\"\nconst RESOLVED_VIRTUAL_ID = \"\\0\" + VIRTUAL_ID\n\n/** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */\nexport function puzzmoSimulator(options: PuzzmoSimulatorPluginOptions = {}): Plugin {\n function generateCode(): string {\n const { fixturesGlob, ...config } = options\n\n const lines = [`import { createSimulator } from \"@puzzmo/sdk/simulator\"`]\n\n if (fixturesGlob) {\n lines.push(`const fixtures = import.meta.glob(${JSON.stringify(fixturesGlob)}, { eager: true })`)\n }\n\n const configEntries = Object.entries(config).filter(([, v]) => v !== undefined)\n const configParts = configEntries.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)\n if (fixturesGlob) configParts.push(\"fixtures\")\n\n lines.push(`createSimulator({ ${configParts.join(\", \")} })`)\n\n return lines.join(\"\\n\")\n }\n\n return {\n name: \"puzzmo-simulator\",\n apply: \"serve\",\n\n // Virtual module used internally for code generation and transformation.\n // Uses \\0 prefix so Vite's HTML processor won't try to inline it.\n resolveId(id) {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) return generateCode()\n },\n\n configureServer(server) {\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. Registered before Vite's internal\n // middleware so the SPA fallback doesn't intercept it.\n server.middlewares.use(async (req, res, next) => {\n if (req.url?.split(\"?\")[0] !== SIMULATOR_URL) return next()\n\n const result = await server.transformRequest(VIRTUAL_ID)\n if (!result) return next()\n res.setHeader(\"Content-Type\", \"application/javascript\")\n res.end(result.code)\n })\n },\n\n // Inject a script tag whose src the browser will fetch.\n // The URL is NOT resolvable via resolveId (intentionally), so Vite's\n // HTML processor won't inline it. The middleware above serves it instead.\n transformIndexHtml() {\n return [\n {\n tag: \"script\",\n attrs: { type: \"module\", src: SIMULATOR_URL },\n injectTo: \"head\",\n },\n ]\n },\n }\n}\n"],"mappings":"ueAoBY,eAAA,CAPN,EAAgB,6BAChB,EAAa,2BACb,EAAsB,KAAO,EAGnC,SAAgB,EAAgB,EAAwC,EAAE,CAAU,CAClF,SAAS,GAAuB,CAC9B,GAAM,CAAE,gBAAA,EAAiB,EAAA,EAAW,EAAA,EAAA,CAE9B,EAAQ,CAAC,0DAA0D,CAErE,GACF,EAAM,KAAK,qCAAqC,KAAK,UAAU,EAAa,CAAC,oBAAoB,CAInG,IAAM,EADgB,OAAO,QAAQ,EAAO,CAAC,QAAQ,EAAG,KAAO,IAAM,IAAA,GAAU,CAC7C,KAAK,CAAC,EAAG,KAAO,GAAG,EAAE,IAAI,KAAK,UAAU,EAAE,GAAG,CAK/E,OAJI,GAAc,EAAY,KAAK,WAAW,CAE9C,EAAM,KAAK,qBAAqB,EAAY,KAAK,KAAK,CAAC,KAAK,CAErD,EAAM,KAAK;EAAK,CAGzB,MAAO,CACL,KAAM,mBACN,MAAO,QAIP,UAAU,EAAI,CACZ,GAAI,IAAO,EAAY,OAAO,GAGhC,KAAK,EAAI,CACP,GAAI,IAAO,EAAqB,OAAO,GAAc,EAGvD,gBAAgB,EAAQ,CACtB,EAAO,YAAY,IAAI,mBAAoB,EAAM,IAAQ,CACvD,EAAI,UAAU,eAAgB,YAAY,CAC1C,EAAI,IAAI;;;;;;;;0BAQS,EACjB,CAIF,EAAO,YAAY,IAAA,UAAA,qBAAW,EAAK,EAAK,EAAS,OAC/C,KAAA,EAAI,EAAI,MAAA,KAAA,IAAA,GAAA,EAAK,MAAM,IAAI,CAAC,MAAO,EAAe,OAAO,GAAM,CAE3D,IAAM,EAAS,MAAM,EAAO,iBAAiB,EAAW,CACxD,GAAI,CAAC,EAAQ,OAAO,GAAM,CAC1B,EAAI,UAAU,eAAgB,yBAAyB,CACvD,EAAI,IAAI,EAAO,KAAK,mBANQ,EAAK,EAAK,EAAA,oCAOtC,EAMJ,oBAAqB,CACnB,MAAO,CACL,CACE,IAAK,SACL,MAAO,CAAE,KAAM,SAAU,IAAK,EAAe,CAC7C,SAAU,OACX,CACF,EAEJ"}
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
export type PuzzmoSimulatorPluginOptions = {
|
|
3
|
-
/** Path to the puzzle JSON file (default: "./sample-puzzle.json") */
|
|
4
|
-
puzzlePath?: string;
|
|
5
3
|
/** Whether to auto-start the game after READY (default: true) */
|
|
6
4
|
autoStart?: boolean;
|
|
7
5
|
/** Initial collapsed state (default: true) */
|
package/dist/vite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,MAAM,4BAA4B,GAAG;IACzC,
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,MAAM,4BAA4B,GAAG;IACzC,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wGAAwG;IACxG,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAMD,6FAA6F;AAC7F,wBAAgB,eAAe,CAAC,OAAO,GAAE,4BAAiC,GAAG,MAAM,CAwElF"}
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from \"vite\"\n\nexport type PuzzmoSimulatorPluginOptions = {\n /**
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from \"vite\"\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 /** Game slug for API features (e.g. \"crossword\", \"my-game\") */\n slug?: string\n /** Glob pattern for fixture files, passed to import.meta.glob (e.g. \"./fixtures/puzzles/**\\/*.json\") */\n fixturesGlob?: string\n}\n\nconst SIMULATOR_URL = \"/@puzzmo-simulator-init.js\"\nconst VIRTUAL_ID = \"virtual:puzzmo-simulator\"\nconst RESOLVED_VIRTUAL_ID = \"\\0\" + VIRTUAL_ID\n\n/** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */\nexport function puzzmoSimulator(options: PuzzmoSimulatorPluginOptions = {}): Plugin {\n function generateCode(): string {\n const { fixturesGlob, ...config } = options\n\n const lines = [`import { createSimulator } from \"@puzzmo/sdk/simulator\"`]\n\n if (fixturesGlob) {\n lines.push(`const fixtures = import.meta.glob(${JSON.stringify(fixturesGlob)}, { eager: true })`)\n }\n\n const configEntries = Object.entries(config).filter(([, v]) => v !== undefined)\n const configParts = configEntries.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)\n if (fixturesGlob) configParts.push(\"fixtures\")\n\n lines.push(`createSimulator({ ${configParts.join(\", \")} })`)\n\n return lines.join(\"\\n\")\n }\n\n return {\n name: \"puzzmo-simulator\",\n apply: \"serve\",\n\n // Virtual module used internally for code generation and transformation.\n // Uses \\0 prefix so Vite's HTML processor won't try to inline it.\n resolveId(id) {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) return generateCode()\n },\n\n configureServer(server) {\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. Registered before Vite's internal\n // middleware so the SPA fallback doesn't intercept it.\n server.middlewares.use(async (req, res, next) => {\n if (req.url?.split(\"?\")[0] !== SIMULATOR_URL) return next()\n\n const result = await server.transformRequest(VIRTUAL_ID)\n if (!result) return next()\n res.setHeader(\"Content-Type\", \"application/javascript\")\n res.end(result.code)\n })\n },\n\n // Inject a script tag whose src the browser will fetch.\n // The URL is NOT resolvable via resolveId (intentionally), so Vite's\n // HTML processor won't inline it. The middleware above serves it instead.\n transformIndexHtml() {\n return [\n {\n tag: \"script\",\n attrs: { type: \"module\", src: SIMULATOR_URL },\n injectTo: \"head\",\n },\n ]\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;SAoBY,eAAA,EAPN,IAAgB,8BAChB,IAAa,4BACb,IAAsB,OAAO;;AAGnC,SAAgB,EAAgB,IAAwC,EAAE,EAAU;CAClF,SAAS,IAAuB;EAC9B,IAAM,EAAE,oBAAA,GAAiB,IAAA,EAAW,GAAA,EAAA,EAE9B,IAAQ,CAAC,4DAA0D;AAEzE,EAAI,KACF,EAAM,KAAK,qCAAqC,KAAK,UAAU,EAAa,CAAC,oBAAoB;EAInG,IAAM,IADgB,OAAO,QAAQ,EAAO,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,EAAU,CAC7C,KAAK,CAAC,GAAG,OAAO,GAAG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