@puzzmo/sdk 1.0.15 → 1.0.17
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/README.md +33 -0
- package/dist/{createSimulator-IMuPxYe-.js → createSimulator-BwucCTnM.js} +174 -25
- package/dist/createSimulator-BwucCTnM.js.map +1 -0
- package/dist/{createSimulator-CGTMmToi.cjs → createSimulator-HQPoM1pd.cjs} +85 -4
- package/dist/createSimulator-HQPoM1pd.cjs.map +1 -0
- package/dist/fonts.cjs +3 -0
- package/dist/fonts.cjs.map +1 -0
- package/dist/fonts.d.ts +26 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +29 -0
- package/dist/fonts.js.map +1 -0
- package/dist/simulator/createSimulator.d.ts +11 -14
- 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.js +1 -1
- package/dist/simulator/styles.d.ts +1 -1
- package/dist/simulator/styles.d.ts.map +1 -1
- package/dist/simulator/views/AuthView.d.ts.map +1 -1
- package/dist/simulator/views/KeyboardView.d.ts +3 -0
- package/dist/simulator/views/KeyboardView.d.ts.map +1 -0
- package/dist/simulator/views/index.d.ts +1 -0
- package/dist/simulator/views/index.d.ts.map +1 -1
- package/dist/svgJSX.cjs +2 -0
- package/dist/svgJSX.cjs.map +1 -0
- package/dist/svgJSX.d.ts +16 -0
- package/dist/svgJSX.d.ts.map +1 -0
- package/dist/svgJSX.js +60 -0
- package/dist/svgJSX.js.map +1 -0
- package/dist/vite.cjs +3 -3
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +18 -4
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +91 -47
- package/dist/vite.js.map +1 -1
- package/package.json +12 -1
- package/dist/createSimulator-CGTMmToi.cjs.map +0 -1
- package/dist/createSimulator-IMuPxYe-.js.map +0 -1
package/dist/vite.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { t as e } from "./asyncToGenerator-CPSNHDFw.js";
|
|
2
2
|
import { t } from "./objectSpread2-vLYiAtaU.js";
|
|
3
3
|
import { build as n } from "vite";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
enumerable: !(r = a(t, d)) || r.enumerable
|
|
8
|
-
});
|
|
9
|
-
return e;
|
|
10
|
-
}, d = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : r(s(e)), u(t || !e || !e.__esModule ? i(n, "default", {
|
|
11
|
-
value: e,
|
|
12
|
-
enumerable: !0
|
|
13
|
-
}) : n, e)))((/* @__PURE__ */ l(((e, t) => {
|
|
14
|
-
t.exports = {};
|
|
15
|
-
})))(), 1);
|
|
16
|
-
function f(e, t) {
|
|
4
|
+
import r from "path";
|
|
5
|
+
import i from "fs";
|
|
6
|
+
function a(e, t) {
|
|
17
7
|
if (e == null) return {};
|
|
18
8
|
var n = {};
|
|
19
9
|
for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
|
|
@@ -22,46 +12,86 @@ function f(e, t) {
|
|
|
22
12
|
}
|
|
23
13
|
return n;
|
|
24
14
|
}
|
|
25
|
-
function
|
|
15
|
+
function o(e, t) {
|
|
26
16
|
if (e == null) return {};
|
|
27
|
-
var n, r, i =
|
|
17
|
+
var n, r, i = a(e, t);
|
|
28
18
|
if (Object.getOwnPropertySymbols) {
|
|
29
|
-
var
|
|
30
|
-
for (r = 0; r <
|
|
19
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
20
|
+
for (r = 0; r < o.length; r++) n = o[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
|
|
31
21
|
}
|
|
32
22
|
return i;
|
|
33
23
|
}
|
|
34
|
-
var
|
|
24
|
+
var s = ["fixturesGlob"], c = "/@puzzmo-simulator-init.js", l = "virtual:puzzmo-simulator";
|
|
25
|
+
/** Discover all games from puzzmo.json files under a root directory. */
|
|
26
|
+
function u(e) {
|
|
27
|
+
let t = /* @__PURE__ */ new Map(), n = _(e, 3);
|
|
28
|
+
i.existsSync(r.join(e, "puzzmo.json")) && n.unshift(e);
|
|
29
|
+
for (let o of n) try {
|
|
30
|
+
var a;
|
|
31
|
+
let n = JSON.parse(i.readFileSync(r.join(o, "puzzmo.json"), "utf-8"));
|
|
32
|
+
if (!(!(n == null || (a = n.game) == null) && a.slug)) continue;
|
|
33
|
+
let s = r.join(o, "src", "appBundle.js"), c = null;
|
|
34
|
+
i.existsSync(s) && (c = "/" + r.relative(e, s).split(r.sep).join("/")), t.set(n.game.slug, {
|
|
35
|
+
dir: o,
|
|
36
|
+
slug: n.game.slug,
|
|
37
|
+
displayName: n.game.displayName,
|
|
38
|
+
appBundlePath: c
|
|
39
|
+
});
|
|
40
|
+
} catch (e) {}
|
|
41
|
+
return t;
|
|
42
|
+
}
|
|
43
|
+
/** Resolve which game a request belongs to using the referer URL */
|
|
44
|
+
function d(e, t, n) {
|
|
45
|
+
if (e) try {
|
|
46
|
+
let i = new URL(e).pathname;
|
|
47
|
+
for (let e of t.values()) {
|
|
48
|
+
let t = "/" + r.relative(n, e.dir).split(r.sep).join("/");
|
|
49
|
+
if (i.startsWith(t + "/") || i === t) return e;
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {}
|
|
52
|
+
if (t.size === 1) return t.values().next().value;
|
|
53
|
+
}
|
|
54
|
+
/** Generate the virtual module code for the simulator. */
|
|
55
|
+
function f(e, n) {
|
|
56
|
+
let { fixturesGlob: r } = e, i = o(e, s), a = r === !1 ? null : r == null ? "/fixtures/puzzles/**/*.json" : r, c = ["import { createSimulator } from \"@puzzmo/sdk/simulator\""];
|
|
57
|
+
a && c.push(`const fixtures = import.meta.glob(${JSON.stringify(a)}, { eager: true })`), n != null && n.appBundlePath && (c.push(`import(${JSON.stringify(n.appBundlePath)}).then(m => {`), c.push(" if (m.renderThumbnail) globalThis.renderThumbnail = m.renderThumbnail"), c.push("}).catch(() => {})"));
|
|
58
|
+
let l = t(t({}, i), n != null && n.slug ? { slug: n.slug } : {}), u = Object.entries(l).filter(([, e]) => e !== void 0).map(([e, t]) => `${e}: ${JSON.stringify(t)}`);
|
|
59
|
+
return a && u.push("fixtures"), c.push(`createSimulator({ ${u.join(", ")} })`), c.join("\n");
|
|
60
|
+
}
|
|
35
61
|
/** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
let { fixturesGlob: e } = t, n = p(t, m), r = ["import { createSimulator } from \"@puzzmo/sdk/simulator\""];
|
|
39
|
-
e && r.push(`const fixtures = import.meta.glob(${JSON.stringify(e)}, { eager: true })`);
|
|
40
|
-
let i = Object.entries(n).filter(([, e]) => e !== void 0).map(([e, t]) => `${e}: ${JSON.stringify(t)}`);
|
|
41
|
-
return e && i.push("fixtures"), r.push(`createSimulator({ ${i.join(", ")} })`), r.join("\n");
|
|
42
|
-
}
|
|
62
|
+
function p(t = {}) {
|
|
63
|
+
let n = /* @__PURE__ */ new Map(), r;
|
|
43
64
|
return {
|
|
44
65
|
name: "puzzmo-simulator",
|
|
45
66
|
apply: "serve",
|
|
67
|
+
configResolved(e) {
|
|
68
|
+
if (r = e.root, n = u(r), n.size === 0) e.logger.info("\x1B[33m\x1B[1m PUZZMO \x1B[22m\x1B[39m\x1B[2m no puzzmo.json files found\x1B[22m");
|
|
69
|
+
else {
|
|
70
|
+
let t = [...n.values()].map((e) => `\x1b[36m${e.slug}\x1b[39m`), r = n.size === 1 ? "game" : "games";
|
|
71
|
+
e.logger.info(`\x1b[33m\x1b[1m PUZZMO \x1b[22m\x1b[39m found ${n.size} ${r}: ${t.join("\x1B[2m, \x1B[22m")}`);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
46
74
|
resolveId(e) {
|
|
47
|
-
if (e ===
|
|
75
|
+
if (e === l || e.startsWith(l + "?")) return "\0" + e;
|
|
48
76
|
},
|
|
49
77
|
load(e) {
|
|
50
|
-
if (e
|
|
78
|
+
if (!e.startsWith("\0" + l)) return;
|
|
79
|
+
let r = new URLSearchParams(e.split("?")[1] || "").get("game");
|
|
80
|
+
return f(t, r ? n.get(r) : n.size === 1 ? n.values().next().value : void 0);
|
|
51
81
|
},
|
|
52
82
|
configureServer(t) {
|
|
53
83
|
t.middlewares.use("/oauth/callback", (e, t) => {
|
|
54
84
|
t.setHeader("Content-Type", "text/html"), t.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>");
|
|
55
85
|
}), t.middlewares.use(function() {
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
if (((
|
|
59
|
-
let
|
|
60
|
-
if (!
|
|
61
|
-
|
|
86
|
+
var i = e(function* (e, i, a) {
|
|
87
|
+
var o;
|
|
88
|
+
if (((o = e.url) == null ? void 0 : o.split("?")[0]) !== c) return a();
|
|
89
|
+
let s = d(e.headers.referer, n, r), u = l + (s ? `?game=${s.slug}` : ""), f = yield t.transformRequest(u);
|
|
90
|
+
if (!f) return a();
|
|
91
|
+
i.setHeader("Content-Type", "application/javascript"), i.end(f.code);
|
|
62
92
|
});
|
|
63
|
-
return function(e, t,
|
|
64
|
-
return
|
|
93
|
+
return function(e, t, n) {
|
|
94
|
+
return i.apply(this, arguments);
|
|
65
95
|
};
|
|
66
96
|
}());
|
|
67
97
|
},
|
|
@@ -70,18 +100,18 @@ function v(t = {}) {
|
|
|
70
100
|
tag: "script",
|
|
71
101
|
attrs: {
|
|
72
102
|
type: "module",
|
|
73
|
-
src:
|
|
103
|
+
src: c
|
|
74
104
|
},
|
|
75
105
|
injectTo: "head"
|
|
76
106
|
}];
|
|
77
107
|
}
|
|
78
108
|
};
|
|
79
109
|
}
|
|
80
|
-
function
|
|
81
|
-
return (
|
|
82
|
-
let { entry:
|
|
110
|
+
function m(i, a) {
|
|
111
|
+
return (o = {}) => {
|
|
112
|
+
let { entry: s, outputFile: c } = t(t({}, a), o);
|
|
83
113
|
return {
|
|
84
|
-
name:
|
|
114
|
+
name: i,
|
|
85
115
|
apply: "build",
|
|
86
116
|
closeBundle() {
|
|
87
117
|
return e(function* () {
|
|
@@ -91,16 +121,16 @@ function y(r, i) {
|
|
|
91
121
|
logLevel: "warn",
|
|
92
122
|
build: {
|
|
93
123
|
lib: {
|
|
94
|
-
entry:
|
|
124
|
+
entry: r.isAbsolute(s) ? s : r.resolve(process.cwd(), s),
|
|
95
125
|
formats: ["es"],
|
|
96
|
-
fileName: () =>
|
|
126
|
+
fileName: () => c
|
|
97
127
|
},
|
|
98
128
|
outDir: "dist",
|
|
99
129
|
emptyOutDir: !1
|
|
100
130
|
}
|
|
101
131
|
});
|
|
102
132
|
} catch (e) {
|
|
103
|
-
throw console.error(`[${
|
|
133
|
+
throw console.error(`[${i}] build failed:`, e), e;
|
|
104
134
|
}
|
|
105
135
|
})();
|
|
106
136
|
}
|
|
@@ -113,13 +143,27 @@ function y(r, i) {
|
|
|
113
143
|
* The bundle exports `renderThumbnail(puzzleStr, inputStr?, config?)` — a pure
|
|
114
144
|
* SVG-string renderer used by the Puzzmo platform for puzzle previews.
|
|
115
145
|
*/
|
|
116
|
-
const
|
|
146
|
+
const h = m("app-bundle", {
|
|
117
147
|
entry: "src/appBundle.js",
|
|
118
148
|
outputFile: "app-bundle.js"
|
|
119
|
-
}),
|
|
149
|
+
}), g = m("editor-bundle", {
|
|
120
150
|
entry: "src/editorBundle.js",
|
|
121
151
|
outputFile: "editor-bundle.js"
|
|
122
|
-
})
|
|
123
|
-
|
|
152
|
+
}), _ = (e, t, n = 0) => {
|
|
153
|
+
if (n >= t) return [];
|
|
154
|
+
let a = [], o;
|
|
155
|
+
try {
|
|
156
|
+
o = i.readdirSync(e, { withFileTypes: !0 });
|
|
157
|
+
} catch (e) {
|
|
158
|
+
return a;
|
|
159
|
+
}
|
|
160
|
+
for (let s of o) {
|
|
161
|
+
if (!s.isDirectory() || s.name.startsWith(".") || s.name === "node_modules") continue;
|
|
162
|
+
let o = r.join(e, s.name);
|
|
163
|
+
i.existsSync(r.join(o, "puzzmo.json")) && a.push(o), a.push(..._(o, t, n + 1));
|
|
164
|
+
}
|
|
165
|
+
return a;
|
|
166
|
+
};
|
|
167
|
+
export { h as appBundlePlugin, u as discoverGames, g as editorBundlePlugin, _ as findPuzzmoJsonDirs, f as generateSimulatorCode, p as puzzmoSimulator, d as resolveGameFromReferer };
|
|
124
168
|
|
|
125
169
|
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../__vite-browser-external","../src/vite.ts"],"sourcesContent":["module.exports = {}","import type { Plugin } from \"vite\"\nimport { build } from \"vite\"\nimport path from \"path\"\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\ntype BundlePluginOptions = {\n /** Entry file for the bundle */\n entry: string\n /** Output file name */\n outputFile: string\n}\n\nfunction createBundlePlugin(pluginName: string, defaults: BundlePluginOptions) {\n return (options: Partial<BundlePluginOptions> = {}): Plugin => {\n const { entry, outputFile } = { ...defaults, ...options }\n return {\n name: pluginName,\n apply: \"build\",\n async closeBundle() {\n try {\n await build({\n configFile: false,\n logLevel: \"warn\",\n build: {\n lib: {\n entry: path.isAbsolute(entry) ? entry : path.resolve(process.cwd(), entry),\n formats: [\"es\"],\n fileName: () => outputFile,\n },\n outDir: \"dist\",\n emptyOutDir: false,\n },\n })\n } catch (error) {\n console.error(`[${pluginName}] build failed:`, error)\n throw error\n }\n },\n }\n }\n}\n\nexport type AppBundlePluginOptions = Partial<BundlePluginOptions>\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(puzzleStr, inputStr?, config?)` — a pure\n * SVG-string renderer used by the Puzzmo platform for puzzle previews.\n */\nexport const appBundlePlugin = createBundlePlugin(\"app-bundle\", { entry: \"src/appBundle.js\", outputFile: \"app-bundle.js\" })\n\nexport type EditorBundlePluginOptions = Partial<BundlePluginOptions>\n\n/** Vite plugin that produces dist/editor-bundle.js after the main build for editor-level integrations. */\nexport const editorBundlePlugin = createBundlePlugin(\"editor-bundle\", { entry: \"src/editorBundle.js\", outputFile: \"editor-bundle.js\" })\n"],"mappings":";;;;;;;;;;;;;AAAA,GAAO,UAAU,EAAA;;;;;;;;;;;;;;;;;;;;SCsBL,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,GAA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AAQ,EAAA,QAAK,QAAQ,QAAQ,KAAK,EAAE,EAAM;SAC1E,SAAS,CAAC,KAAK;SACf,gBAAgB;SACjB;QACD,QAAQ;QACR,aAAa;QACd;OACF,CAAC;cACK,GAAO;AAEd,YADA,QAAQ,MAAM,IAAI,EAAW,kBAAkB,EAAM,EAC/C;;;;GAGX;;;;;;;;;AAYL,MAAa,IAAkB,EAAmB,cAAc;CAAE,OAAO;CAAoB,YAAY;CAAiB,CAAC,EAK9G,IAAqB,EAAmB,iBAAiB;CAAE,OAAO;CAAuB,YAAY;CAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin, ResolvedConfig } from \"vite\"\nimport { build } from \"vite\"\nimport path from \"path\"\nimport fs from \"fs\"\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 /** Glob pattern for fixture files, passed to import.meta.glob which is relative to the closest puzzmo.json. Defaults to \"/fixtures/puzzles/**\\/*.json\". Pass false to disable. */\n fixturesGlob?: string | false\n}\n\nconst simulatorURL = \"/@puzzmo-simulator-init.js\"\nconst virtualID = \"virtual:puzzmo-simulator\"\n\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}\n\n/** Discover all games from puzzmo.json files under a root directory. */\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 = path.join(dir, \"src\", \"appBundle.js\")\n let appBundle: string | null = null\n if (fs.existsSync(bundleEntry)) {\n const relative = path.relative(viteRoot, bundleEntry)\n appBundle = \"/\" + relative.split(path.sep).join(\"/\")\n }\n games.set(data.game.slug, { dir, slug: data.game.slug, displayName: data.game.displayName, appBundlePath: appBundle })\n } catch {\n // skip invalid files\n }\n }\n return games\n}\n\n/** Resolve which game a request belongs to using the referer URL */\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/** Generate the virtual module code for the simulator. */\nexport function generateSimulatorCode(options: PuzzmoSimulatorPluginOptions, game: GameInfo | undefined): string {\n const { fixturesGlob: fixturesOpt, ...config } = options\n const fixturesGlob = fixturesOpt === false ? null : (fixturesOpt ?? \"/fixtures/puzzles/**/*.json\")\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 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(`}).catch(() => {})`)\n }\n\n const simConfig = { ...config, ...(game?.slug ? { slug: game.slug } : {}) }\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\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 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}\n\nfunction createBundlePlugin(pluginName: string, defaults: BundlePluginOptions) {\n return (options: Partial<BundlePluginOptions> = {}): Plugin => {\n const { entry, outputFile } = { ...defaults, ...options }\n return {\n name: pluginName,\n apply: \"build\",\n async closeBundle() {\n try {\n await build({\n configFile: false,\n logLevel: \"warn\",\n build: {\n lib: {\n entry: path.isAbsolute(entry) ? entry : path.resolve(process.cwd(), entry),\n formats: [\"es\"],\n fileName: () => outputFile,\n },\n outDir: \"dist\",\n emptyOutDir: false,\n },\n })\n } catch (error) {\n console.error(`[${pluginName}] build failed:`, error)\n throw error\n }\n },\n }\n }\n}\n\nexport type AppBundlePluginOptions = Partial<BundlePluginOptions>\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(puzzleStr, inputStr?, config?)` — a pure\n * SVG-string renderer used by the Puzzmo platform for puzzle previews.\n */\nexport const appBundlePlugin = createBundlePlugin(\"app-bundle\", { entry: \"src/appBundle.js\", outputFile: \"app-bundle.js\" })\n\nexport type EditorBundlePluginOptions = Partial<BundlePluginOptions>\n\n/** Vite plugin that produces dist/editor-bundle.js after the main build for editor-level integrations. */\nexport const editorBundlePlugin = createBundlePlugin(\"editor-bundle\", { entry: \"src/editorBundle.js\", outputFile: \"editor-bundle.js\" })\n\n/** Recursively find directories containing puzzmo.json, up to `maxDepth` levels deep. */\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":";;;;;;;;;;;;;;;;;;;;;;;SAsEU,eAAA,EAxDJ,IAAe,8BACf,IAAY;;AAYlB,SAAgB,EAAc,GAAyC;CACrE,IAAM,oBAAQ,IAAI,KAAuB,EACnC,IAAa,EAAmB,GAAU,EAAE;AAClD,CAAI,EAAG,WAAW,EAAK,KAAK,GAAU,cAAc,CAAC,IACnD,EAAW,QAAQ,EAAS;AAE9B,MAAK,IAAM,KAAO,EAChB,KAAI;;EACF,IAAM,IAAO,KAAK,MAAM,EAAG,aAAa,EAAK,KAAK,GAAK,cAAc,EAAE,QAAQ,CAAC;AAChF,MAAI,EAAA,OAAA,SAAA,IAAC,EAAM,SAAA,SAAA,EAAM,MAAM;EACvB,IAAM,IAAc,EAAK,KAAK,GAAK,OAAO,eAAe,EACrD,IAA2B;AAK/B,EAJI,EAAG,WAAW,EAAY,KAE5B,IAAY,MADK,EAAK,SAAS,GAAU,EAAY,CAC1B,MAAM,EAAK,IAAI,CAAC,KAAK,IAAI,GAEtD,EAAM,IAAI,EAAK,KAAK,MAAM;GAAE;GAAK,MAAM,EAAK,KAAK;GAAM,aAAa,EAAK,KAAK;GAAa,eAAe;GAAW,CAAC;aAChH;AAIV,QAAO;;;AAIT,SAAgB,EAAuB,GAA6B,GAA8B,GAAwC;AACxI,KAAI,EACF,KAAI;EACF,IAAM,IAAU,IAAI,IAAI,EAAQ,CAAC;AACjC,OAAK,IAAM,KAAK,EAAM,QAAQ,EAAE;GAC9B,IAAM,IAAS,MAAM,EAAK,SAAS,GAAU,EAAE,IAAI,CAAC,MAAM,EAAK,IAAI,CAAC,KAAK,IAAI;AAC7E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"@puzzmo/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Puzzmo runtime SDK for game developers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -27,6 +27,16 @@
|
|
|
27
27
|
"import": "./dist/simulator/standalone.js",
|
|
28
28
|
"require": "./dist/simulator/standalone.cjs"
|
|
29
29
|
},
|
|
30
|
+
"./fonts": {
|
|
31
|
+
"types": "./dist/fonts.d.ts",
|
|
32
|
+
"import": "./dist/fonts.js",
|
|
33
|
+
"require": "./dist/fonts.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./svgJSX": {
|
|
36
|
+
"types": "./dist/svgJSX.d.ts",
|
|
37
|
+
"import": "./dist/svgJSX.js",
|
|
38
|
+
"require": "./dist/svgJSX.cjs"
|
|
39
|
+
},
|
|
30
40
|
"./vite": {
|
|
31
41
|
"types": "./dist/vite.d.ts",
|
|
32
42
|
"import": "./dist/vite.js",
|
|
@@ -38,6 +48,7 @@
|
|
|
38
48
|
],
|
|
39
49
|
"scripts": {
|
|
40
50
|
"build": "vite build && tsgo --project tsconfig.build.json",
|
|
51
|
+
"test": "vitest run",
|
|
41
52
|
"type-check": "tsgo --noEmit"
|
|
42
53
|
},
|
|
43
54
|
"keywords": [
|