@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.
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/boot.d.mts +16 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +20 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/browser.d.mts +2 -0
- package/dist/browser.mjs +1846 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/client.mjs +1071 -0
- package/dist/client.mjs.map +1 -0
- package/dist/config.d.mts +221 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/hydrate.d.mts +67 -0
- package/dist/hydrate.d.mts.map +1 -0
- package/dist/hydrate.mjs +3 -0
- package/dist/hydrate2.d.mts +2 -0
- package/dist/hydrate2.mjs +387 -0
- package/dist/hydrate2.mjs.map +1 -0
- package/dist/index.d.mts +88 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/payload.mjs +419 -0
- package/dist/payload.mjs.map +1 -0
- package/dist/plugin.d.mts +8 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +2 -0
- package/dist/plugin2.mjs +524 -0
- package/dist/plugin2.mjs.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ubugeeei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @ox-content/code-play
|
|
2
|
+
|
|
3
|
+
Opt-in Code Play plugin for Ox Content. It runs documentation samples on demand
|
|
4
|
+
and exposes a headless API plus Headless / preset UI.
|
|
5
|
+
|
|
6
|
+
Nothing runs until you install this package **and** enable specific languages.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @ox-content/code-play
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { oxContent } from "@ox-content/vite-plugin";
|
|
16
|
+
import { codePlay } from "@ox-content/code-play";
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
plugins: [
|
|
20
|
+
oxContent({ highlight: true }),
|
|
21
|
+
codePlay({
|
|
22
|
+
languages: {
|
|
23
|
+
typescript: { execute: true, typecheck: true },
|
|
24
|
+
rust: true,
|
|
25
|
+
},
|
|
26
|
+
ui: "default",
|
|
27
|
+
viewers: { config: true, stdio: true, stderr: true, provenance: true, timing: true },
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Authoring
|
|
34
|
+
|
|
35
|
+
````md
|
|
36
|
+
```ts play
|
|
37
|
+
const n: number = 1;
|
|
38
|
+
console.log(n);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```rust play typecheck
|
|
42
|
+
fn main() {
|
|
43
|
+
println!("ok");
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
````
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<CodePlay lang="python"> print("hello") </CodePlay>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Headless API
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { createCodePlay } from "@ox-content/code-play";
|
|
56
|
+
|
|
57
|
+
const play = createCodePlay({ languages: { typescript: true } });
|
|
58
|
+
const session = play.createSession({ language: "ts", code: "const n: number = 1;" });
|
|
59
|
+
const check = await session.typecheck();
|
|
60
|
+
const run = await session.run();
|
|
61
|
+
|
|
62
|
+
run.stdio;
|
|
63
|
+
run.stdout;
|
|
64
|
+
run.stderr;
|
|
65
|
+
run.provenance;
|
|
66
|
+
run.timing;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Security
|
|
70
|
+
|
|
71
|
+
`play` fences are trusted site content. Do not mark unreviewed or
|
|
72
|
+
visitor-supplied snippets as `play`.
|
|
73
|
+
|
|
74
|
+
- No sample is executed during Markdown transform or SSG.
|
|
75
|
+
- JavaScript and TypeScript run in `node:vm` on Node, or in
|
|
76
|
+
`<iframe sandbox="allow-scripts">` in the browser (no `allow-same-origin`).
|
|
77
|
+
They are never run with page-origin `Function`.
|
|
78
|
+
- Published widgets hide **Typecheck** unless `endpoints.typecheck` is set.
|
|
79
|
+
**Cancel** appears while a run is in flight.
|
|
80
|
+
- Framework previews use the same iframe flags and load runtimes from esm.sh.
|
|
81
|
+
- Rust and Go POST source to the official playgrounds (or your `endpoints`).
|
|
82
|
+
The Vite `/__ox-code-play/*` proxy is **dev-only**.
|
|
83
|
+
- Other languages need a Piston-compatible `endpoint` you trust.
|
|
84
|
+
- `sh` never spawns a local shell.
|
|
85
|
+
|
|
86
|
+
## Example
|
|
87
|
+
|
|
88
|
+
A runnable Vite site lives in [`examples/code-play`](../../examples/code-play):
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
corepack pnpm --filter ./examples/code-play dev
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The docs site also dogfoods JavaScript and TypeScript widgets on
|
|
95
|
+
[Code Play](../../docs/content/examples/code-play.md).
|
|
96
|
+
|
|
97
|
+
See [Code Play](../../docs/content/packages/code-play.md) in the docs site.
|
package/dist/boot.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/boot.d.ts
|
|
2
|
+
interface BootDocument {
|
|
3
|
+
readyState: string;
|
|
4
|
+
addEventListener(type: string, listener: () => void, options?: {
|
|
5
|
+
once?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Mount every `[data-ox-code-play]` widget. The SSG client (`ox-code-play.js`)
|
|
10
|
+
* calls this on load; apps that import `@ox-content/code-play/client` call it
|
|
11
|
+
* themselves.
|
|
12
|
+
*/
|
|
13
|
+
declare function bootCodePlay(hydrate?: (root?: ParentNode) => void, doc?: BootDocument | undefined): void;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { bootCodePlay as t };
|
|
16
|
+
//# sourceMappingURL=boot.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boot.d.mts","names":[],"sources":["../src/boot.ts"],"mappings":";UAEiB;EACf;EACA,iBAAiB,cAAc,sBAAsB;IAAY;;;;;;;;iBAQnD,aACd,WAAU,OAAO,qBACjB,MAAK"}
|
package/dist/boot.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as hydrateCodePlay } from "./hydrate2.mjs";
|
|
2
|
+
//#region src/boot.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mount every `[data-ox-code-play]` widget. The SSG client (`ox-code-play.js`)
|
|
5
|
+
* calls this on load; apps that import `@ox-content/code-play/client` call it
|
|
6
|
+
* themselves.
|
|
7
|
+
*/
|
|
8
|
+
function bootCodePlay(hydrate = hydrateCodePlay, doc = typeof document === "undefined" ? void 0 : document) {
|
|
9
|
+
if (!doc) return;
|
|
10
|
+
const run = () => hydrate();
|
|
11
|
+
if (doc.readyState === "loading") {
|
|
12
|
+
doc.addEventListener("DOMContentLoaded", run, { once: true });
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
run();
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { bootCodePlay as t };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=boot.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boot.mjs","names":[],"sources":["../src/boot.ts"],"sourcesContent":["import { hydrateCodePlay } from \"./hydrate\";\n\nexport interface BootDocument {\n readyState: string;\n addEventListener(type: string, listener: () => void, options?: { once?: boolean }): void;\n}\n\n/**\n * Mount every `[data-ox-code-play]` widget. The SSG client (`ox-code-play.js`)\n * calls this on load; apps that import `@ox-content/code-play/client` call it\n * themselves.\n */\nexport function bootCodePlay(\n hydrate: (root?: ParentNode) => void = hydrateCodePlay,\n doc: BootDocument | undefined = typeof document === \"undefined\" ? undefined : document,\n): void {\n if (!doc) {\n return;\n }\n const run = () => hydrate();\n if (doc.readyState === \"loading\") {\n doc.addEventListener(\"DOMContentLoaded\", run, { once: true });\n return;\n }\n run();\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,aACd,UAAuC,iBACvC,MAAgC,OAAO,aAAa,cAAc,KAAA,IAAY,UACxE;CACN,IAAI,CAAC,KACH;CAEF,MAAM,YAAY,QAAQ;CAC1B,IAAI,IAAI,eAAe,WAAW;EAChC,IAAI,iBAAiB,oBAAoB,KAAK,EAAE,MAAM,KAAK,CAAC;EAC5D;CACF;CACA,IAAI;AACN"}
|