@ox-content/code-play 3.0.0-alpha.1

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.
@@ -0,0 +1,419 @@
1
+ //#region src/catalog.ts
2
+ const rustSchema = [
3
+ {
4
+ key: "channel",
5
+ label: "Channel",
6
+ type: "select",
7
+ options: [
8
+ {
9
+ value: "stable",
10
+ label: "stable"
11
+ },
12
+ {
13
+ value: "beta",
14
+ label: "beta"
15
+ },
16
+ {
17
+ value: "nightly",
18
+ label: "nightly"
19
+ }
20
+ ],
21
+ default: "stable"
22
+ },
23
+ {
24
+ key: "edition",
25
+ label: "Edition",
26
+ type: "select",
27
+ options: [
28
+ {
29
+ value: "2018",
30
+ label: "2018"
31
+ },
32
+ {
33
+ value: "2021",
34
+ label: "2021"
35
+ },
36
+ {
37
+ value: "2024",
38
+ label: "2024"
39
+ }
40
+ ],
41
+ default: "2024"
42
+ },
43
+ {
44
+ key: "mode",
45
+ label: "Mode",
46
+ type: "select",
47
+ options: [{
48
+ value: "debug",
49
+ label: "debug"
50
+ }, {
51
+ value: "release",
52
+ label: "release"
53
+ }],
54
+ default: "debug"
55
+ },
56
+ {
57
+ key: "crateType",
58
+ label: "Crate type",
59
+ type: "select",
60
+ options: [
61
+ {
62
+ value: "auto",
63
+ label: "auto"
64
+ },
65
+ {
66
+ value: "bin",
67
+ label: "bin"
68
+ },
69
+ {
70
+ value: "lib",
71
+ label: "lib"
72
+ }
73
+ ],
74
+ default: "auto"
75
+ }
76
+ ];
77
+ const tsSchema = [
78
+ {
79
+ key: "strict",
80
+ label: "Strict",
81
+ type: "boolean",
82
+ default: true
83
+ },
84
+ {
85
+ key: "target",
86
+ label: "Target",
87
+ type: "select",
88
+ options: [
89
+ {
90
+ value: "ES2020",
91
+ label: "ES2020"
92
+ },
93
+ {
94
+ value: "ES2022",
95
+ label: "ES2022"
96
+ },
97
+ {
98
+ value: "ESNext",
99
+ label: "ESNext"
100
+ }
101
+ ],
102
+ default: "ES2022"
103
+ },
104
+ {
105
+ key: "jsx",
106
+ label: "JSX",
107
+ type: "select",
108
+ options: [{
109
+ value: "react-jsx",
110
+ label: "react-jsx"
111
+ }, {
112
+ value: "preserve",
113
+ label: "preserve"
114
+ }],
115
+ default: "react-jsx"
116
+ }
117
+ ];
118
+ function remote(id, name, aliases, pistonLanguage, extra = []) {
119
+ return {
120
+ id,
121
+ name,
122
+ aliases,
123
+ capabilities: {
124
+ execute: true,
125
+ typecheck: false
126
+ },
127
+ defaultConfig: { version: "*" },
128
+ configSchema: [{
129
+ key: "version",
130
+ label: "Runtime version",
131
+ type: "string",
132
+ default: "*"
133
+ }, ...extra],
134
+ backend: "remote",
135
+ remote: { pistonLanguage }
136
+ };
137
+ }
138
+ function framework(id, name, aliases) {
139
+ return {
140
+ id,
141
+ name,
142
+ aliases,
143
+ capabilities: {
144
+ execute: true,
145
+ typecheck: false
146
+ },
147
+ defaultConfig: {},
148
+ configSchema: [],
149
+ backend: "framework",
150
+ framework: id
151
+ };
152
+ }
153
+ const LANGUAGE_CATALOG = [
154
+ {
155
+ id: "typescript",
156
+ name: "TypeScript",
157
+ aliases: [
158
+ "ts",
159
+ "tsx",
160
+ "mts",
161
+ "cts"
162
+ ],
163
+ capabilities: {
164
+ execute: true,
165
+ typecheck: true
166
+ },
167
+ defaultConfig: {
168
+ strict: true,
169
+ target: "ES2022",
170
+ jsx: "react-jsx"
171
+ },
172
+ configSchema: tsSchema,
173
+ backend: "typescript"
174
+ },
175
+ {
176
+ id: "javascript",
177
+ name: "JavaScript",
178
+ aliases: [
179
+ "js",
180
+ "jsx",
181
+ "mjs",
182
+ "cjs"
183
+ ],
184
+ capabilities: {
185
+ execute: true,
186
+ typecheck: false
187
+ },
188
+ defaultConfig: {},
189
+ configSchema: [],
190
+ backend: "javascript"
191
+ },
192
+ {
193
+ id: "rust",
194
+ name: "Rust",
195
+ aliases: ["rs"],
196
+ capabilities: {
197
+ execute: true,
198
+ typecheck: true
199
+ },
200
+ defaultConfig: {
201
+ channel: "stable",
202
+ edition: "2024",
203
+ mode: "debug",
204
+ crateType: "auto"
205
+ },
206
+ configSchema: rustSchema,
207
+ backend: "rust-playground"
208
+ },
209
+ {
210
+ id: "go",
211
+ name: "Go",
212
+ aliases: ["golang"],
213
+ capabilities: {
214
+ execute: true,
215
+ typecheck: true
216
+ },
217
+ defaultConfig: { withVet: true },
218
+ configSchema: [{
219
+ key: "withVet",
220
+ label: "Run vet",
221
+ type: "boolean",
222
+ default: true
223
+ }],
224
+ backend: "go-playground"
225
+ },
226
+ framework("vue", "Vue", ["vue"]),
227
+ framework("react", "React", ["react"]),
228
+ framework("svelte", "Svelte", ["svelte"]),
229
+ framework("solid", "Solid", ["solid"]),
230
+ remote("python", "Python", ["py"], "python"),
231
+ remote("php", "PHP", [], "php"),
232
+ remote("ruby", "Ruby", ["rb"], "ruby"),
233
+ remote("sh", "sh", [
234
+ "bash",
235
+ "shell",
236
+ "zsh"
237
+ ], "bash", [{
238
+ key: "shell",
239
+ label: "Shell",
240
+ type: "select",
241
+ options: [{
242
+ value: "bash",
243
+ label: "bash"
244
+ }, {
245
+ value: "sh",
246
+ label: "sh"
247
+ }],
248
+ default: "bash"
249
+ }]),
250
+ remote("java", "Java", [], "java"),
251
+ remote("swift", "Swift", [], "swift"),
252
+ remote("kotlin", "Kotlin", ["kt"], "kotlin"),
253
+ remote("c", "C", [], "c"),
254
+ remote("cpp", "C++", [
255
+ "c++",
256
+ "cc",
257
+ "cxx"
258
+ ], "c++", [{
259
+ key: "std",
260
+ label: "Standard",
261
+ type: "select",
262
+ options: [
263
+ {
264
+ value: "c++17",
265
+ label: "C++17"
266
+ },
267
+ {
268
+ value: "c++20",
269
+ label: "C++20"
270
+ },
271
+ {
272
+ value: "c++23",
273
+ label: "C++23"
274
+ }
275
+ ],
276
+ default: "c++20"
277
+ }]),
278
+ remote("zig", "Zig", [], "zig"),
279
+ remote("haskell", "Haskell", ["hs"], "haskell"),
280
+ remote("ocaml", "OCaml", ["ml"], "ocaml"),
281
+ remote("csharp", "C#", ["cs", "c#"], "csharp"),
282
+ remote("elixir", "Elixir", ["ex"], "elixir"),
283
+ remote("fsharp", "F#", ["fs", "f#"], "fsharp"),
284
+ remote("clojure", "Clojure", ["clj", "cloujure"], "clojure"),
285
+ remote("scheme", "Scheme", ["scm"], "scheme"),
286
+ remote("moonbit", "MoonBit", ["mbt"], "moonbit"),
287
+ remote("lean", "Lean", ["lean4"], "lean"),
288
+ remote("rocq", "Rocq", ["coq"], "coq")
289
+ ];
290
+ const byId = new Map(LANGUAGE_CATALOG.map((language) => [language.id, language]));
291
+ const byAlias = /* @__PURE__ */ new Map();
292
+ for (const language of LANGUAGE_CATALOG) {
293
+ byAlias.set(language.id, language);
294
+ for (const alias of language.aliases) byAlias.set(alias.toLowerCase(), language);
295
+ }
296
+ function resolveLanguage(input) {
297
+ return byAlias.get(input.trim().toLowerCase()) ?? byId.get(input.trim().toLowerCase());
298
+ }
299
+ function listLanguages() {
300
+ return LANGUAGE_CATALOG.slice();
301
+ }
302
+ //#endregion
303
+ //#region src/config.ts
304
+ const DEFAULT_ENDPOINTS = {
305
+ rust: "https://play.rust-lang.org/execute",
306
+ go: "https://play.golang.org/compile"
307
+ };
308
+ /** Vite dev middleware only. Not present in production SSG output. */
309
+ const DEV_TYPECHECK_PATH = "/__ox-code-play/typecheck";
310
+ const DEFAULT_VIEWERS = {
311
+ config: true,
312
+ stdio: true,
313
+ stderr: true,
314
+ provenance: true,
315
+ timing: true
316
+ };
317
+ function resolveCodePlayOptions(options = {}) {
318
+ return {
319
+ languages: resolveEnabledLanguages(options.languages ?? {}),
320
+ timeoutMs: options.timeoutMs ?? 1e4,
321
+ ui: options.ui ?? "default",
322
+ viewers: {
323
+ ...DEFAULT_VIEWERS,
324
+ ...options.viewers
325
+ },
326
+ endpoints: {
327
+ ...DEFAULT_ENDPOINTS,
328
+ ...options.endpoints
329
+ },
330
+ srcDir: options.srcDir,
331
+ outDir: options.outDir,
332
+ base: normalizeBase(options.base ?? "/"),
333
+ proxy: options.proxy ?? true
334
+ };
335
+ }
336
+ function resolveEnabledLanguages(languages) {
337
+ const resolved = /* @__PURE__ */ new Map();
338
+ for (const [key, enable] of Object.entries(languages)) {
339
+ if (enable === false) continue;
340
+ const definition = resolveLanguage(key);
341
+ if (!definition) throw new Error(`Unknown Code Play language: ${key}.`);
342
+ const explicit = enable === true ? {} : enable;
343
+ resolved.set(definition.id, {
344
+ id: definition.id,
345
+ execute: explicit.execute ?? definition.capabilities.execute,
346
+ typecheck: explicit.typecheck ?? definition.capabilities.typecheck,
347
+ endpoint: explicit.endpoint,
348
+ config: {
349
+ ...definition.defaultConfig,
350
+ ...explicit.config
351
+ }
352
+ });
353
+ }
354
+ return resolved;
355
+ }
356
+ function mergeConfig(languageId, enabled, override) {
357
+ return {
358
+ ...resolveLanguage(languageId)?.defaultConfig,
359
+ ...enabled?.config,
360
+ ...override
361
+ };
362
+ }
363
+ function normalizeBase(base) {
364
+ if (base === "/" || base === "") return "/";
365
+ return base.endsWith("/") ? base : `${base}/`;
366
+ }
367
+ //#endregion
368
+ //#region src/escape.ts
369
+ function escapeHtml(value) {
370
+ return value.replace(/[&<>"']/g, (char) => {
371
+ switch (char) {
372
+ case "&": return "&amp;";
373
+ case "<": return "&lt;";
374
+ case ">": return "&gt;";
375
+ case "\"": return "&quot;";
376
+ default: return "&#39;";
377
+ }
378
+ });
379
+ }
380
+ function decodeHtml(value) {
381
+ return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&amp;/g, "&");
382
+ }
383
+ function escapeAttribute(value) {
384
+ return escapeHtml(value).replace(/`/g, "&#96;");
385
+ }
386
+ //#endregion
387
+ //#region src/payload.ts
388
+ function encodePayload(payload) {
389
+ return bytesToBase64(new TextEncoder().encode(JSON.stringify(payload)));
390
+ }
391
+ function decodePayload(value) {
392
+ const json = new TextDecoder().decode(base64ToBytes(value));
393
+ const parsed = JSON.parse(json);
394
+ if (!parsed || typeof parsed !== "object" || typeof parsed.language !== "string") throw new Error("Invalid Code Play payload.");
395
+ return {
396
+ ...parsed,
397
+ viewers: {
398
+ ...DEFAULT_VIEWERS,
399
+ ...parsed.viewers
400
+ }
401
+ };
402
+ }
403
+ function bytesToBase64(bytes) {
404
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
405
+ let binary = "";
406
+ for (const byte of bytes) binary += String.fromCharCode(byte);
407
+ return btoa(binary);
408
+ }
409
+ function base64ToBytes(value) {
410
+ if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(value, "base64"));
411
+ const binary = atob(value);
412
+ const bytes = new Uint8Array(binary.length);
413
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
414
+ return bytes;
415
+ }
416
+ //#endregion
417
+ export { escapeHtml as a, DEV_TYPECHECK_PATH as c, LANGUAGE_CATALOG as d, listLanguages as f, escapeAttribute as i, mergeConfig as l, encodePayload as n, DEFAULT_ENDPOINTS as o, resolveLanguage as p, decodeHtml as r, DEFAULT_VIEWERS as s, decodePayload as t, resolveCodePlayOptions as u };
418
+
419
+ //# sourceMappingURL=payload.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.mjs","names":[],"sources":["../src/catalog.ts","../src/config.ts","../src/escape.ts","../src/payload.ts"],"sourcesContent":["import type { ConfigField, LanguageDefinition } from \"./types\";\n\nconst rustSchema: ConfigField[] = [\n {\n key: \"channel\",\n label: \"Channel\",\n type: \"select\",\n options: [\n { value: \"stable\", label: \"stable\" },\n { value: \"beta\", label: \"beta\" },\n { value: \"nightly\", label: \"nightly\" },\n ],\n default: \"stable\",\n },\n {\n key: \"edition\",\n label: \"Edition\",\n type: \"select\",\n options: [\n { value: \"2018\", label: \"2018\" },\n { value: \"2021\", label: \"2021\" },\n { value: \"2024\", label: \"2024\" },\n ],\n default: \"2024\",\n },\n {\n key: \"mode\",\n label: \"Mode\",\n type: \"select\",\n options: [\n { value: \"debug\", label: \"debug\" },\n { value: \"release\", label: \"release\" },\n ],\n default: \"debug\",\n },\n {\n key: \"crateType\",\n label: \"Crate type\",\n type: \"select\",\n options: [\n { value: \"auto\", label: \"auto\" },\n { value: \"bin\", label: \"bin\" },\n { value: \"lib\", label: \"lib\" },\n ],\n default: \"auto\",\n },\n];\n\nconst tsSchema: ConfigField[] = [\n { key: \"strict\", label: \"Strict\", type: \"boolean\", default: true },\n {\n key: \"target\",\n label: \"Target\",\n type: \"select\",\n options: [\n { value: \"ES2020\", label: \"ES2020\" },\n { value: \"ES2022\", label: \"ES2022\" },\n { value: \"ESNext\", label: \"ESNext\" },\n ],\n default: \"ES2022\",\n },\n {\n key: \"jsx\",\n label: \"JSX\",\n type: \"select\",\n options: [\n { value: \"react-jsx\", label: \"react-jsx\" },\n { value: \"preserve\", label: \"preserve\" },\n ],\n default: \"react-jsx\",\n },\n];\n\nfunction remote(\n id: string,\n name: string,\n aliases: string[],\n pistonLanguage: string,\n extra: ConfigField[] = [],\n): LanguageDefinition {\n return {\n id,\n name,\n aliases,\n capabilities: { execute: true, typecheck: false },\n defaultConfig: { version: \"*\" },\n configSchema: [\n { key: \"version\", label: \"Runtime version\", type: \"string\", default: \"*\" },\n ...extra,\n ],\n backend: \"remote\",\n remote: { pistonLanguage },\n };\n}\n\nfunction framework(\n id: \"vue\" | \"react\" | \"svelte\" | \"solid\",\n name: string,\n aliases: string[],\n): LanguageDefinition {\n return {\n id,\n name,\n aliases,\n capabilities: { execute: true, typecheck: false },\n defaultConfig: {},\n configSchema: [],\n backend: \"framework\",\n framework: id,\n };\n}\n\nexport const LANGUAGE_CATALOG: LanguageDefinition[] = [\n {\n id: \"typescript\",\n name: \"TypeScript\",\n aliases: [\"ts\", \"tsx\", \"mts\", \"cts\"],\n capabilities: { execute: true, typecheck: true },\n defaultConfig: { strict: true, target: \"ES2022\", jsx: \"react-jsx\" },\n configSchema: tsSchema,\n backend: \"typescript\",\n },\n {\n id: \"javascript\",\n name: \"JavaScript\",\n aliases: [\"js\", \"jsx\", \"mjs\", \"cjs\"],\n capabilities: { execute: true, typecheck: false },\n defaultConfig: {},\n configSchema: [],\n backend: \"javascript\",\n },\n {\n id: \"rust\",\n name: \"Rust\",\n aliases: [\"rs\"],\n capabilities: { execute: true, typecheck: true },\n defaultConfig: { channel: \"stable\", edition: \"2024\", mode: \"debug\", crateType: \"auto\" },\n configSchema: rustSchema,\n backend: \"rust-playground\",\n },\n {\n id: \"go\",\n name: \"Go\",\n aliases: [\"golang\"],\n capabilities: { execute: true, typecheck: true },\n defaultConfig: { withVet: true },\n configSchema: [{ key: \"withVet\", label: \"Run vet\", type: \"boolean\", default: true }],\n backend: \"go-playground\",\n },\n framework(\"vue\", \"Vue\", [\"vue\"]),\n framework(\"react\", \"React\", [\"react\"]),\n framework(\"svelte\", \"Svelte\", [\"svelte\"]),\n framework(\"solid\", \"Solid\", [\"solid\"]),\n remote(\"python\", \"Python\", [\"py\"], \"python\"),\n remote(\"php\", \"PHP\", [], \"php\"),\n remote(\"ruby\", \"Ruby\", [\"rb\"], \"ruby\"),\n remote(\"sh\", \"sh\", [\"bash\", \"shell\", \"zsh\"], \"bash\", [\n {\n key: \"shell\",\n label: \"Shell\",\n type: \"select\",\n options: [\n { value: \"bash\", label: \"bash\" },\n { value: \"sh\", label: \"sh\" },\n ],\n default: \"bash\",\n },\n ]),\n remote(\"java\", \"Java\", [], \"java\"),\n remote(\"swift\", \"Swift\", [], \"swift\"),\n remote(\"kotlin\", \"Kotlin\", [\"kt\"], \"kotlin\"),\n remote(\"c\", \"C\", [], \"c\"),\n remote(\"cpp\", \"C++\", [\"c++\", \"cc\", \"cxx\"], \"c++\", [\n {\n key: \"std\",\n label: \"Standard\",\n type: \"select\",\n options: [\n { value: \"c++17\", label: \"C++17\" },\n { value: \"c++20\", label: \"C++20\" },\n { value: \"c++23\", label: \"C++23\" },\n ],\n default: \"c++20\",\n },\n ]),\n remote(\"zig\", \"Zig\", [], \"zig\"),\n remote(\"haskell\", \"Haskell\", [\"hs\"], \"haskell\"),\n remote(\"ocaml\", \"OCaml\", [\"ml\"], \"ocaml\"),\n remote(\"csharp\", \"C#\", [\"cs\", \"c#\"], \"csharp\"),\n remote(\"elixir\", \"Elixir\", [\"ex\"], \"elixir\"),\n remote(\"fsharp\", \"F#\", [\"fs\", \"f#\"], \"fsharp\"),\n remote(\"clojure\", \"Clojure\", [\"clj\", \"cloujure\"], \"clojure\"),\n remote(\"scheme\", \"Scheme\", [\"scm\"], \"scheme\"),\n remote(\"moonbit\", \"MoonBit\", [\"mbt\"], \"moonbit\"),\n remote(\"lean\", \"Lean\", [\"lean4\"], \"lean\"),\n remote(\"rocq\", \"Rocq\", [\"coq\"], \"coq\"),\n];\n\nconst byId = new Map(LANGUAGE_CATALOG.map((language) => [language.id, language]));\nconst byAlias = new Map<string, LanguageDefinition>();\nfor (const language of LANGUAGE_CATALOG) {\n byAlias.set(language.id, language);\n for (const alias of language.aliases) {\n byAlias.set(alias.toLowerCase(), language);\n }\n}\n\nexport function resolveLanguage(input: string): LanguageDefinition | undefined {\n return byAlias.get(input.trim().toLowerCase()) ?? byId.get(input.trim().toLowerCase());\n}\n\nexport function listLanguages(): LanguageDefinition[] {\n return LANGUAGE_CATALOG.slice();\n}\n","import { listLanguages, resolveLanguage } from \"./catalog\";\nimport type {\n CodePlayPreset,\n LanguageEnable,\n PlaygroundEndpoints,\n ResolvedLanguageEnable,\n ViewerFlags,\n} from \"./types\";\n\nexport interface ResolvedCodePlayOptions {\n languages: Map<string, ResolvedLanguageEnable>;\n timeoutMs: number;\n ui: CodePlayPreset;\n viewers: ViewerFlags;\n endpoints: PlaygroundEndpoints;\n srcDir?: string;\n outDir?: string;\n base: string;\n proxy: boolean;\n}\n\nexport interface RawCodePlayOptions {\n languages?: Record<string, LanguageEnable>;\n timeoutMs?: number;\n ui?: CodePlayPreset;\n viewers?: Partial<ViewerFlags>;\n endpoints?: Partial<PlaygroundEndpoints>;\n srcDir?: string;\n outDir?: string;\n base?: string;\n proxy?: boolean;\n}\n\nexport const DEFAULT_ENDPOINTS: PlaygroundEndpoints = {\n rust: \"https://play.rust-lang.org/execute\",\n go: \"https://play.golang.org/compile\",\n};\n\n/** Vite dev middleware only. Not present in production SSG output. */\nexport const DEV_TYPECHECK_PATH = \"/__ox-code-play/typecheck\";\n\nexport const DEFAULT_VIEWERS: ViewerFlags = {\n config: true,\n stdio: true,\n stderr: true,\n provenance: true,\n timing: true,\n};\n\nexport function resolveCodePlayOptions(options: RawCodePlayOptions = {}): ResolvedCodePlayOptions {\n return {\n languages: resolveEnabledLanguages(options.languages ?? {}),\n timeoutMs: options.timeoutMs ?? 10_000,\n ui: options.ui ?? \"default\",\n viewers: { ...DEFAULT_VIEWERS, ...options.viewers },\n endpoints: { ...DEFAULT_ENDPOINTS, ...options.endpoints },\n srcDir: options.srcDir,\n outDir: options.outDir,\n base: normalizeBase(options.base ?? \"/\"),\n proxy: options.proxy ?? true,\n };\n}\n\nexport function resolveEnabledLanguages(\n languages: Record<string, LanguageEnable>,\n): Map<string, ResolvedLanguageEnable> {\n const resolved = new Map<string, ResolvedLanguageEnable>();\n for (const [key, enable] of Object.entries(languages)) {\n if (enable === false) {\n continue;\n }\n const definition = resolveLanguage(key);\n if (!definition) {\n throw new Error(`Unknown Code Play language: ${key}.`);\n }\n const explicit = enable === true ? {} : enable;\n resolved.set(definition.id, {\n id: definition.id,\n execute: explicit.execute ?? definition.capabilities.execute,\n typecheck: explicit.typecheck ?? definition.capabilities.typecheck,\n endpoint: explicit.endpoint,\n config: { ...definition.defaultConfig, ...explicit.config },\n });\n }\n return resolved;\n}\n\nexport function mergeConfig(\n languageId: string,\n enabled: ResolvedLanguageEnable | undefined,\n override?: Record<string, unknown>,\n): Record<string, unknown> {\n const definition = resolveLanguage(languageId);\n return {\n ...definition?.defaultConfig,\n ...enabled?.config,\n ...override,\n };\n}\n\nexport function enabledLanguageIds(): string[] {\n return listLanguages().map((language) => language.id);\n}\n\nfunction normalizeBase(base: string): string {\n if (base === \"/\" || base === \"\") {\n return \"/\";\n }\n return base.endsWith(\"/\") ? base : `${base}/`;\n}\n","export function escapeHtml(value: string): string {\n return value.replace(/[&<>\"']/g, (char) => {\n switch (char) {\n case \"&\":\n return \"&amp;\";\n case \"<\":\n return \"&lt;\";\n case \">\":\n return \"&gt;\";\n case '\"':\n return \"&quot;\";\n default:\n return \"&#39;\";\n }\n });\n}\n\nexport function decodeHtml(value: string): string {\n return value\n .replace(/&lt;/g, \"<\")\n .replace(/&gt;/g, \">\")\n .replace(/&quot;/g, '\"')\n .replace(/&#39;/g, \"'\")\n .replace(/&amp;/g, \"&\");\n}\n\nexport function escapeAttribute(value: string): string {\n return escapeHtml(value).replace(/`/g, \"&#96;\");\n}\n","import { DEFAULT_VIEWERS } from \"./config\";\nimport type { PlayPayload } from \"./types\";\n\nexport function encodePayload(payload: PlayPayload): string {\n return bytesToBase64(new TextEncoder().encode(JSON.stringify(payload)));\n}\n\nexport function decodePayload(value: string): PlayPayload {\n const json = new TextDecoder().decode(base64ToBytes(value));\n const parsed = JSON.parse(json) as PlayPayload;\n if (!parsed || typeof parsed !== \"object\" || typeof parsed.language !== \"string\") {\n throw new Error(\"Invalid Code Play payload.\");\n }\n return {\n ...parsed,\n viewers: { ...DEFAULT_VIEWERS, ...parsed.viewers },\n };\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(bytes).toString(\"base64\");\n }\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n}\n\nfunction base64ToBytes(value: string): Uint8Array {\n if (typeof Buffer !== \"undefined\") {\n return new Uint8Array(Buffer.from(value, \"base64\"));\n }\n const binary = atob(value);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) {\n bytes[index] = binary.charCodeAt(index);\n }\n return bytes;\n}\n"],"mappings":";AAEA,MAAM,aAA4B;CAChC;EACE,KAAK;E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AAO,cAAc,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,UAAU,OAAO,CAAC,CAAC;AACxE;AAEA,SAAgB,cAAc,OAA4B;CACxD,MAAM,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,cAAc,KAAK,CAAC;CAC1D,MAAM,SAAS,KAAK,MAAM,IAAI;CAC9B,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,OAAO,OAAO,aAAa,UACtE,MAAM,IAAI,MAAM,4BAA4B;CAE9C,OAAO;EACL,GAAG;EACH,SAAS;GAAE,GAAG;GAAiB,GAAG,OAAO;EAAQ;CACnD;AACF;AAEA,SAAS,cAAc,OAA2B;CAChD,IAAI,OAAO,WAAW,aACpB,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,QAAQ;CAE7C,IAAI,SAAS;CACb,KAAK,MAAM,QAAQ,OACjB,UAAU,OAAO,aAAa,IAAI;CAEpC,OAAO,KAAK,MAAM;AACpB;AAEA,SAAS,cAAc,OAA2B;CAChD,IAAI,OAAO,WAAW,aACpB,OAAO,IAAI,WAAW,OAAO,KAAK,OAAO,QAAQ,CAAC;CAEpD,MAAM,SAAS,KAAK,KAAK;CACzB,MAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;CAC1C,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAClD,MAAM,SAAS,OAAO,WAAW,KAAK;CAExC,OAAO;AACT"}
@@ -0,0 +1,8 @@
1
+ import { r as RawCodePlayOptions } from "./config.mjs";
2
+ import { Plugin } from "vite";
3
+ //#region src/plugin.d.ts
4
+ type CodePlayPluginOptions = RawCodePlayOptions;
5
+ declare function codePlay(options?: CodePlayPluginOptions): Plugin;
6
+ //#endregion
7
+ export { type CodePlayPluginOptions as CodePlayOptions, CodePlayPluginOptions, codePlay };
8
+ //# sourceMappingURL=plugin.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;KAsBY,wBAAwB;iBAMpB,SAAS,UAAS,wBAA6B"}
@@ -0,0 +1,2 @@
1
+ import { t as codePlay } from "./plugin2.mjs";
2
+ export { codePlay };