@ttsc/playground 0.14.0-dev.20250530.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.
Files changed (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -0
  3. package/lib/src/compiler/DEFAULT_ENTRY_FILE.d.ts +2 -0
  4. package/lib/src/compiler/DEFAULT_ENTRY_FILE.js +6 -0
  5. package/lib/src/compiler/DEFAULT_ENTRY_FILE.js.map +1 -0
  6. package/lib/src/compiler/DEFAULT_LINT_PLUGIN_NAME.d.ts +5 -0
  7. package/lib/src/compiler/DEFAULT_LINT_PLUGIN_NAME.js +9 -0
  8. package/lib/src/compiler/DEFAULT_LINT_PLUGIN_NAME.js.map +1 -0
  9. package/lib/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.d.ts +19 -0
  10. package/lib/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.js +23 -0
  11. package/lib/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.js.map +1 -0
  12. package/lib/src/compiler/DEFAULT_TSCONFIG_PATH.d.ts +2 -0
  13. package/lib/src/compiler/DEFAULT_TSCONFIG_PATH.js +6 -0
  14. package/lib/src/compiler/DEFAULT_TSCONFIG_PATH.js.map +1 -0
  15. package/lib/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.d.ts +6 -0
  16. package/lib/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.js +10 -0
  17. package/lib/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.js.map +1 -0
  18. package/lib/src/compiler/DEFAULT_WORK_DIR.d.ts +2 -0
  19. package/lib/src/compiler/DEFAULT_WORK_DIR.js +6 -0
  20. package/lib/src/compiler/DEFAULT_WORK_DIR.js.map +1 -0
  21. package/lib/src/compiler/buildTsconfigJSON.d.ts +9 -0
  22. package/lib/src/compiler/buildTsconfigJSON.js +24 -0
  23. package/lib/src/compiler/buildTsconfigJSON.js.map +1 -0
  24. package/lib/src/compiler/createTypiaSourcePackMount.d.ts +11 -0
  25. package/lib/src/compiler/createTypiaSourcePackMount.js +29 -0
  26. package/lib/src/compiler/createTypiaSourcePackMount.js.map +1 -0
  27. package/lib/src/compiler/createWorkerCompiler.d.ts +25 -0
  28. package/lib/src/compiler/createWorkerCompiler.js +227 -0
  29. package/lib/src/compiler/createWorkerCompiler.js.map +1 -0
  30. package/lib/src/compiler/installDependenciesIntoMemFS.d.ts +12 -0
  31. package/lib/src/compiler/installDependenciesIntoMemFS.js +25 -0
  32. package/lib/src/compiler/installDependenciesIntoMemFS.js.map +1 -0
  33. package/lib/src/compiler/installTypiaSourcePack.d.ts +11 -0
  34. package/lib/src/compiler/installTypiaSourcePack.js +21 -0
  35. package/lib/src/compiler/installTypiaSourcePack.js.map +1 -0
  36. package/lib/src/compiler/internal/joinUnder.d.ts +5 -0
  37. package/lib/src/compiler/internal/joinUnder.js +13 -0
  38. package/lib/src/compiler/internal/joinUnder.js.map +1 -0
  39. package/lib/src/compiler/internal/parseLintDiagnostics.d.ts +6 -0
  40. package/lib/src/compiler/internal/parseLintDiagnostics.js +57 -0
  41. package/lib/src/compiler/internal/parseLintDiagnostics.js.map +1 -0
  42. package/lib/src/compiler/internal/safeParseTypiaTransform.d.ts +11 -0
  43. package/lib/src/compiler/internal/safeParseTypiaTransform.js +21 -0
  44. package/lib/src/compiler/internal/safeParseTypiaTransform.js.map +1 -0
  45. package/lib/src/compiler/lineColumnOf.d.ts +5 -0
  46. package/lib/src/compiler/lineColumnOf.js +15 -0
  47. package/lib/src/compiler/lineColumnOf.js.map +1 -0
  48. package/lib/src/compiler/loadTypiaSourcePack.d.ts +8 -0
  49. package/lib/src/compiler/loadTypiaSourcePack.js +33 -0
  50. package/lib/src/compiler/loadTypiaSourcePack.js.map +1 -0
  51. package/lib/src/compiler/mapDiagnostic.d.ts +9 -0
  52. package/lib/src/compiler/mapDiagnostic.js +22 -0
  53. package/lib/src/compiler/mapDiagnostic.js.map +1 -0
  54. package/lib/src/compiler/normalizeError.d.ts +2 -0
  55. package/lib/src/compiler/normalizeError.js +14 -0
  56. package/lib/src/compiler/normalizeError.js.map +1 -0
  57. package/lib/src/compiler/normalizeNodeModulePath.d.ts +8 -0
  58. package/lib/src/compiler/normalizeNodeModulePath.js +19 -0
  59. package/lib/src/compiler/normalizeNodeModulePath.js.map +1 -0
  60. package/lib/src/compiler/pickEmittedJS.d.ts +6 -0
  61. package/lib/src/compiler/pickEmittedJS.js +21 -0
  62. package/lib/src/compiler/pickEmittedJS.js.map +1 -0
  63. package/lib/src/index.d.ts +47 -0
  64. package/lib/src/index.js +104 -0
  65. package/lib/src/index.js.map +1 -0
  66. package/lib/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.d.ts +6 -0
  67. package/lib/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.js +15 -0
  68. package/lib/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.js.map +1 -0
  69. package/lib/src/npm/collectExternalPackageNames.d.ts +5 -0
  70. package/lib/src/npm/collectExternalPackageNames.js +34 -0
  71. package/lib/src/npm/collectExternalPackageNames.js.map +1 -0
  72. package/lib/src/npm/installPlaygroundDependencies.d.ts +13 -0
  73. package/lib/src/npm/installPlaygroundDependencies.js +121 -0
  74. package/lib/src/npm/installPlaygroundDependencies.js.map +1 -0
  75. package/lib/src/npm/internal/npmRegistry.d.ts +57 -0
  76. package/lib/src/npm/internal/npmRegistry.js +216 -0
  77. package/lib/src/npm/internal/npmRegistry.js.map +1 -0
  78. package/lib/src/npm/packageNameFromSpecifier.d.ts +7 -0
  79. package/lib/src/npm/packageNameFromSpecifier.js +66 -0
  80. package/lib/src/npm/packageNameFromSpecifier.js.map +1 -0
  81. package/lib/src/react/ConsoleViewer.d.ts +7 -0
  82. package/lib/src/react/ConsoleViewer.js +57 -0
  83. package/lib/src/react/ConsoleViewer.js.map +1 -0
  84. package/lib/src/react/DEFAULT_OPTION_TOGGLES.d.ts +3 -0
  85. package/lib/src/react/DEFAULT_OPTION_TOGGLES.js +17 -0
  86. package/lib/src/react/DEFAULT_OPTION_TOGGLES.js.map +1 -0
  87. package/lib/src/react/DependencyProgressModal.d.ts +7 -0
  88. package/lib/src/react/DependencyProgressModal.js +16 -0
  89. package/lib/src/react/DependencyProgressModal.js.map +1 -0
  90. package/lib/src/react/DiagnosticsPanel.d.ts +4 -0
  91. package/lib/src/react/DiagnosticsPanel.js +15 -0
  92. package/lib/src/react/DiagnosticsPanel.js.map +1 -0
  93. package/lib/src/react/ExamplePicker.d.ts +9 -0
  94. package/lib/src/react/ExamplePicker.js +43 -0
  95. package/lib/src/react/ExamplePicker.js.map +1 -0
  96. package/lib/src/react/LintPane.d.ts +9 -0
  97. package/lib/src/react/LintPane.js +17 -0
  98. package/lib/src/react/LintPane.js.map +1 -0
  99. package/lib/src/react/OptionsPanel.d.ts +13 -0
  100. package/lib/src/react/OptionsPanel.js +43 -0
  101. package/lib/src/react/OptionsPanel.js.map +1 -0
  102. package/lib/src/react/PlaygroundShell.d.ts +2 -0
  103. package/lib/src/react/PlaygroundShell.js +609 -0
  104. package/lib/src/react/PlaygroundShell.js.map +1 -0
  105. package/lib/src/react/ResultViewer.d.ts +10 -0
  106. package/lib/src/react/ResultViewer.js +49 -0
  107. package/lib/src/react/ResultViewer.js.map +1 -0
  108. package/lib/src/react/SourceEditor.d.ts +2 -0
  109. package/lib/src/react/SourceEditor.js +74 -0
  110. package/lib/src/react/SourceEditor.js.map +1 -0
  111. package/lib/src/react/createCompilerClient.d.ts +14 -0
  112. package/lib/src/react/createCompilerClient.js +77 -0
  113. package/lib/src/react/createCompilerClient.js.map +1 -0
  114. package/lib/src/sandbox/createSandboxRequire.d.ts +11 -0
  115. package/lib/src/sandbox/createSandboxRequire.js +211 -0
  116. package/lib/src/sandbox/createSandboxRequire.js.map +1 -0
  117. package/lib/src/sandbox/loadTypiaRuntimePack.d.ts +7 -0
  118. package/lib/src/sandbox/loadTypiaRuntimePack.js +35 -0
  119. package/lib/src/sandbox/loadTypiaRuntimePack.js.map +1 -0
  120. package/lib/src/structures/IBuildTsconfigOptions.d.ts +19 -0
  121. package/lib/src/structures/IBuildTsconfigOptions.js +3 -0
  122. package/lib/src/structures/IBuildTsconfigOptions.js.map +1 -0
  123. package/lib/src/structures/ICompilerService.d.ts +84 -0
  124. package/lib/src/structures/ICompilerService.js +3 -0
  125. package/lib/src/structures/ICompilerService.js.map +1 -0
  126. package/lib/src/structures/IConsoleMessage.d.ts +10 -0
  127. package/lib/src/structures/IConsoleMessage.js +3 -0
  128. package/lib/src/structures/IConsoleMessage.js.map +1 -0
  129. package/lib/src/structures/ICreateCompilerClientOptions.d.ts +13 -0
  130. package/lib/src/structures/ICreateCompilerClientOptions.js +3 -0
  131. package/lib/src/structures/ICreateCompilerClientOptions.js.map +1 -0
  132. package/lib/src/structures/ICreateWorkerCompilerOptions.d.ts +35 -0
  133. package/lib/src/structures/ICreateWorkerCompilerOptions.js +3 -0
  134. package/lib/src/structures/ICreateWorkerCompilerOptions.js.map +1 -0
  135. package/lib/src/structures/IInstallTypiaSourcePackOptions.d.ts +18 -0
  136. package/lib/src/structures/IInstallTypiaSourcePackOptions.js +3 -0
  137. package/lib/src/structures/IInstallTypiaSourcePackOptions.js.map +1 -0
  138. package/lib/src/structures/ILintPluginConfig.d.ts +5 -0
  139. package/lib/src/structures/ILintPluginConfig.js +3 -0
  140. package/lib/src/structures/ILintPluginConfig.js.map +1 -0
  141. package/lib/src/structures/IOptionToggle.d.ts +12 -0
  142. package/lib/src/structures/IOptionToggle.js +3 -0
  143. package/lib/src/structures/IOptionToggle.js.map +1 -0
  144. package/lib/src/structures/IPlaygroundDependencyInstallOptions.d.ts +16 -0
  145. package/lib/src/structures/IPlaygroundDependencyInstallOptions.js +3 -0
  146. package/lib/src/structures/IPlaygroundDependencyInstallOptions.js.map +1 -0
  147. package/lib/src/structures/IPlaygroundDependencyInstallResult.d.ts +20 -0
  148. package/lib/src/structures/IPlaygroundDependencyInstallResult.js +3 -0
  149. package/lib/src/structures/IPlaygroundDependencyInstallResult.js.map +1 -0
  150. package/lib/src/structures/IPlaygroundDependencyPackage.d.ts +8 -0
  151. package/lib/src/structures/IPlaygroundDependencyPackage.js +3 -0
  152. package/lib/src/structures/IPlaygroundDependencyPackage.js.map +1 -0
  153. package/lib/src/structures/IPlaygroundDependencyProgress.d.ts +10 -0
  154. package/lib/src/structures/IPlaygroundDependencyProgress.js +3 -0
  155. package/lib/src/structures/IPlaygroundDependencyProgress.js.map +1 -0
  156. package/lib/src/structures/IPlaygroundDependencyProgressPhase.d.ts +5 -0
  157. package/lib/src/structures/IPlaygroundDependencyProgressPhase.js +3 -0
  158. package/lib/src/structures/IPlaygroundDependencyProgressPhase.js.map +1 -0
  159. package/lib/src/structures/IPlaygroundExample.d.ts +16 -0
  160. package/lib/src/structures/IPlaygroundExample.js +3 -0
  161. package/lib/src/structures/IPlaygroundExample.js.map +1 -0
  162. package/lib/src/structures/IPlaygroundShellProps.d.ts +70 -0
  163. package/lib/src/structures/IPlaygroundShellProps.js +3 -0
  164. package/lib/src/structures/IPlaygroundShellProps.js.map +1 -0
  165. package/lib/src/structures/ISourceEditorProps.d.ts +18 -0
  166. package/lib/src/structures/ISourceEditorProps.js +3 -0
  167. package/lib/src/structures/ISourceEditorProps.js.map +1 -0
  168. package/lib/src/structures/ITransformOptions.d.ts +15 -0
  169. package/lib/src/structures/ITransformOptions.js +3 -0
  170. package/lib/src/structures/ITransformOptions.js.map +1 -0
  171. package/lib/src/structures/ITypiaPluginConfig.d.ts +19 -0
  172. package/lib/src/structures/ITypiaPluginConfig.js +3 -0
  173. package/lib/src/structures/ITypiaPluginConfig.js.map +1 -0
  174. package/lib/src/structures/index.d.ts +18 -0
  175. package/lib/src/structures/index.js +35 -0
  176. package/lib/src/structures/index.js.map +1 -0
  177. package/package.json +66 -0
  178. package/src/compiler/DEFAULT_ENTRY_FILE.ts +2 -0
  179. package/src/compiler/DEFAULT_LINT_PLUGIN_NAME.ts +5 -0
  180. package/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.ts +19 -0
  181. package/src/compiler/DEFAULT_TSCONFIG_PATH.ts +2 -0
  182. package/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.ts +6 -0
  183. package/src/compiler/DEFAULT_WORK_DIR.ts +2 -0
  184. package/src/compiler/buildTsconfigJSON.ts +22 -0
  185. package/src/compiler/createTypiaSourcePackMount.ts +32 -0
  186. package/src/compiler/createWorkerCompiler.ts +273 -0
  187. package/src/compiler/installDependenciesIntoMemFS.ts +28 -0
  188. package/src/compiler/installTypiaSourcePack.ts +24 -0
  189. package/src/compiler/internal/joinUnder.ts +8 -0
  190. package/src/compiler/internal/parseLintDiagnostics.ts +61 -0
  191. package/src/compiler/internal/safeParseTypiaTransform.ts +24 -0
  192. package/src/compiler/lineColumnOf.ts +14 -0
  193. package/src/compiler/loadTypiaSourcePack.ts +37 -0
  194. package/src/compiler/mapDiagnostic.ts +26 -0
  195. package/src/compiler/normalizeError.ts +12 -0
  196. package/src/compiler/normalizeNodeModulePath.ts +13 -0
  197. package/src/compiler/pickEmittedJS.ts +18 -0
  198. package/src/index.ts +57 -0
  199. package/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.ts +11 -0
  200. package/src/npm/collectExternalPackageNames.ts +34 -0
  201. package/src/npm/installPlaygroundDependencies.ts +163 -0
  202. package/src/npm/internal/npmRegistry.ts +292 -0
  203. package/src/npm/packageNameFromSpecifier.ts +61 -0
  204. package/src/react/ConsoleViewer.tsx +121 -0
  205. package/src/react/DEFAULT_OPTION_TOGGLES.ts +15 -0
  206. package/src/react/DependencyProgressModal.tsx +73 -0
  207. package/src/react/DiagnosticsPanel.tsx +74 -0
  208. package/src/react/ExamplePicker.tsx +93 -0
  209. package/src/react/LintPane.tsx +58 -0
  210. package/src/react/OptionsPanel.tsx +132 -0
  211. package/src/react/PlaygroundShell.tsx +864 -0
  212. package/src/react/ResultViewer.tsx +75 -0
  213. package/src/react/SourceEditor.tsx +96 -0
  214. package/src/react/createCompilerClient.ts +80 -0
  215. package/src/sandbox/createSandboxRequire.ts +275 -0
  216. package/src/sandbox/loadTypiaRuntimePack.ts +36 -0
  217. package/src/structures/IBuildTsconfigOptions.ts +19 -0
  218. package/src/structures/ICompilerService.ts +96 -0
  219. package/src/structures/IConsoleMessage.ts +10 -0
  220. package/src/structures/ICreateCompilerClientOptions.ts +13 -0
  221. package/src/structures/ICreateWorkerCompilerOptions.ts +40 -0
  222. package/src/structures/IInstallTypiaSourcePackOptions.ts +18 -0
  223. package/src/structures/ILintPluginConfig.ts +5 -0
  224. package/src/structures/IOptionToggle.ts +12 -0
  225. package/src/structures/IPlaygroundDependencyInstallOptions.ts +17 -0
  226. package/src/structures/IPlaygroundDependencyInstallResult.ts +21 -0
  227. package/src/structures/IPlaygroundDependencyPackage.ts +8 -0
  228. package/src/structures/IPlaygroundDependencyProgress.ts +11 -0
  229. package/src/structures/IPlaygroundDependencyProgressPhase.ts +12 -0
  230. package/src/structures/IPlaygroundExample.ts +16 -0
  231. package/src/structures/IPlaygroundShellProps.ts +83 -0
  232. package/src/structures/ISourceEditorProps.ts +18 -0
  233. package/src/structures/ITransformOptions.ts +15 -0
  234. package/src/structures/ITypiaPluginConfig.ts +20 -0
  235. package/src/structures/index.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jeongho Nam
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,191 @@
1
+ # @ttsc/playground
2
+
3
+ > **API stability: experimental until v1.0.** Public signatures (the `createWorkerCompiler` options, `ICompilerService` contract, React component props) may change between minor releases. Pin exact versions in production playgrounds.
4
+
5
+ Reusable Web Worker + React scaffolding for in-browser [`ttsc`](https://ttsc.dev) playgrounds. Built on top of [`@ttsc/wasm`](https://github.com/samchon/ttsc/tree/master/packages/wasm).
6
+
7
+ The package handles the parts every browser playground needs, worker boot, MemFS layout, race-guarded compile / lint / bundle calls, on-the-fly npm dependency installer, typia source-pack mounting, console-capturing execute sandbox, and ships a Tailwind-styled React shell that wires them all up. Sites supply the wasm URL, a default script, and (optionally) examples, brand slot, and an execute callback.
8
+
9
+ The ttsc website (`ttsc.dev`) and the typia website (`typia.io`) are the two reference consumers.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @ttsc/playground @ttsc/wasm \
15
+ @monaco-editor/react monaco-editor react react-dom tgrid tailwindcss
16
+ ```
17
+
18
+ `@monaco-editor/react`, `monaco-editor`, `react`, `react-dom`, `tgrid`, and `@ttsc/wasm` are **peer dependencies**. `lz-string` is bundled.
19
+
20
+ The React components use Tailwind 4 utility classes. See [Tailwind setup](#tailwind-setup) below.
21
+
22
+ ## What you get
23
+
24
+ | Layer | Exports |
25
+ | --- | --- |
26
+ | **Worker core** | `createWorkerCompiler`, `buildTsconfigJSON`, `installDependenciesIntoMemFS`, `mapDiagnostic`, `pickEmittedJS`, `DEFAULT_*` constants |
27
+ | **Typia integration** | `createTypiaSourcePackMount`, `installTypiaSourcePack`, `loadTypiaSourcePack` |
28
+ | **Npm installer** | `installPlaygroundDependencies`, `collectExternalPackageNames`, `packageNameFromSpecifier`, `BUILT_IN_PLAYGROUND_PACKAGES` |
29
+ | **Execute sandbox** | `createSandboxRequire`, `loadTypiaRuntimePack` |
30
+ | **React UI** | `PlaygroundShell`, `SourceEditor`, `ResultViewer`, `ConsoleViewer`, `OptionsPanel`, `DiagnosticsPanel`, `DependencyProgressModal`, `ExamplePicker`, `LintPane`, `createCompilerClient`, `DEFAULT_OPTION_TOGGLES` |
31
+ | **Types** | Everything under `./src/structures/` |
32
+
33
+ ## Architecture
34
+
35
+ ```
36
+ ┌─ Browser tab ───────────────────────────────────────────┐
37
+ │ │
38
+ │ <PlaygroundShell> ─── tgrid RPC ───┐ │
39
+ │ ↳ SourceEditor (Monaco) │ │
40
+ │ ↳ ResultViewer ▼ │
41
+ │ ↳ ConsoleViewer ┌────────────────┐│
42
+ │ ↳ DiagnosticsPanel │ Web Worker ││
43
+ │ ↳ DependencyProgressModal │ ││
44
+ │ ↳ ExamplePicker │ createWorker ││
45
+ │ ↳ OptionsPanel │ Compiler() ││
46
+ │ ↳ LintPane │ ↓ ││
47
+ │ │ @ttsc/wasm ││
48
+ │ (UI installs runtime npm deps │ bootTtsc() ││
49
+ │ into the same worker MemFS via │ ↓ ││
50
+ │ service.installDependencies()) │ MemFS ││
51
+ │ │ └─ /work/… ││
52
+ │ │ ttsc.wasm ││
53
+ │ └────────────────┘│
54
+ └─────────────────────────────────────────────────────────┘
55
+ ```
56
+
57
+ ## Worker entry (site-side)
58
+
59
+ The worker entry is two lines. Wire the wasm URL the site ships and the `apiName` you used in `host.Expose` when you built the wasm.
60
+
61
+ ```ts
62
+ // site/src/compiler/index.ts (rspack target: "webworker")
63
+ import { createWorkerCompiler } from "@ttsc/playground";
64
+ import { WorkerServer } from "tgrid";
65
+
66
+ const service = createWorkerCompiler({
67
+ wasmUrl: "/compiler/playground.wasm",
68
+ wasmExecUrl: "/compiler/wasm_exec.js",
69
+ apiName: "ttscPlayground",
70
+ });
71
+
72
+ await new WorkerServer().open(service);
73
+ ```
74
+
75
+ Bundle this file with rspack/webpack/vite as a webworker target and serve the output (e.g. at `/compiler/index.js`).
76
+
77
+ ## UI shell (site-side)
78
+
79
+ ```tsx
80
+ // site/src/components/playground/PlaygroundShell.tsx
81
+ "use client";
82
+ import { PlaygroundShell } from "@ttsc/playground";
83
+ import { PLAYGROUND_DEFAULT_SCRIPT, PLAYGROUND_EXAMPLES } from "../...";
84
+
85
+ export default function SitePlayground() {
86
+ return (
87
+ <PlaygroundShell
88
+ workerUrl="/compiler/index.js"
89
+ defaultScript={PLAYGROUND_DEFAULT_SCRIPT}
90
+ examples={PLAYGROUND_EXAMPLES}
91
+ brand={<a href="/">my-site</a>}
92
+ executeBundle={async (code, sandbox) => {
93
+ // run the compiled JS however you like; route console.* into sandbox.console
94
+ new Function("console", code)(sandbox.console);
95
+ }}
96
+ />
97
+ );
98
+ }
99
+ ```
100
+
101
+ ## Typia integration (optional)
102
+
103
+ When the wasm bundles the typia transform plugin, mount typia's source tree into the MemFS so `import typia from "typia"` resolves:
104
+
105
+ ```ts
106
+ import {
107
+ createTypiaSourcePackMount,
108
+ createWorkerCompiler,
109
+ } from "@ttsc/playground";
110
+
111
+ const service = createWorkerCompiler({
112
+ wasmUrl: "/compiler/playground.wasm",
113
+ apiName: "ttscPlayground",
114
+ typiaPlugin: {
115
+ name: "typia",
116
+ transformModule: "typia/lib/transform",
117
+ mount: createTypiaSourcePackMount({
118
+ url: "/compiler/typia-pack.json",
119
+ }),
120
+ },
121
+ });
122
+ ```
123
+
124
+ The typia pack itself is built by the site (typically with a `pack-typia-sources.cjs`-style script that bundles `typia/`, `@typia/utils`, and `@typia/interface` into a flat JSON map). See the ttsc website's [`build/pack-typia-sources.cjs`](https://github.com/samchon/ttsc/blob/master/website/build/pack-typia-sources.cjs) for the reference implementation.
125
+
126
+ ## Runtime npm dependency installer
127
+
128
+ When the user types `import {v4} from "uuid"`, the shell auto-fetches `uuid` (and its transitive deps) from the npm registry, unpacks the tgz in the browser, and mounts the files into the wasm MemFS, no proxy server needed.
129
+
130
+ ```ts
131
+ import {
132
+ collectExternalPackageNames,
133
+ installPlaygroundDependencies,
134
+ } from "@ttsc/playground";
135
+
136
+ const names = collectExternalPackageNames(userSource);
137
+ const installed = await installPlaygroundDependencies(names, {
138
+ onProgress: (p) => console.log(p.phase, p.packageName),
139
+ });
140
+ // mount installed.compilerFiles into the wasm MemFS via service.installDependencies
141
+ ```
142
+
143
+ `PlaygroundShell` wires this automatically on every keystroke, debounced 900 ms, with an abort signal on source change.
144
+
145
+ ## Tailwind setup
146
+
147
+ The bundled React components use Tailwind 4 utility classes. The host site must load Tailwind for them to render correctly.
148
+
149
+ `postcss.config.mjs`:
150
+
151
+ ```js
152
+ const config = { plugins: { "@tailwindcss/postcss": {} } };
153
+ export default config;
154
+ ```
155
+
156
+ `src/app/global.css`:
157
+
158
+ ```css
159
+ @import "tailwindcss";
160
+
161
+ /* Tell Tailwind 4 to scan @ttsc/playground's compiled output for utility
162
+ classes. Tailwind 4's @source takes a literal glob relative to this
163
+ CSS file — adjust the leading `../` segments to match how deep the
164
+ CSS file lives. Tailwind 4 follows the pnpm symlink at
165
+ node_modules/@ttsc/playground transparently. */
166
+ @source "../../node_modules/@ttsc/playground/lib/**/*.js";
167
+ ```
168
+
169
+ Then `import "./global.css"` from the root layout.
170
+
171
+ **`@ttsc/playground` must be a direct dependency** of the consuming package. Tailwind only scans paths the consumer points at. A transitively-installed copy (where @ttsc/playground is a dep of another package) lives under a different node_modules layout and the glob above won't find it without explicit re-targeting.
172
+
173
+ ## Booting a custom wasm
174
+
175
+ `createWorkerCompiler` is plugin-agnostic. To register a custom plugin set:
176
+
177
+ 1. Write a Go `main_wasm.go` that calls `host.Expose("myApi", host.Config{ Plugins: [...] })`. See [`@ttsc/wasm`](https://github.com/samchon/ttsc/tree/master/packages/wasm) for the host helper and the plugin contract.
178
+ 2. Build the wasm with `GOOS=js GOARCH=wasm go build`.
179
+ 3. Ship the wasm at any URL and pass it to `createWorkerCompiler({wasmUrl, apiName})`.
180
+
181
+ If the wasm registers plugins other than typia / `@ttsc/lint`, pass `typiaPlugin: false` / `lintPlugin: false` to skip those default dispatchers and use your own toggles via `optionToggles` + a custom worker wrapper.
182
+
183
+ ## Conventions
184
+
185
+ - **One type per file.** Public interfaces / types each live under `src/structures/` in a file named after the type. The barrel `structures/index.ts` re-exports everything.
186
+ - **One public function per file.** Internal helpers may be grouped in `compiler/internal/` or `npm/internal/`.
187
+ - **No sub-path exports.** Every public symbol is importable from the package root. Add a sub-path later only when a real consumer needs to avoid pulling React into a Node-only context.
188
+
189
+ ## Documents
190
+
191
+ See the [`@ttsc/playground` guide](https://ttsc.dev/docs/playground) for the site-walkthrough version of this README.
@@ -0,0 +1,2 @@
1
+ /** Default entry source file inside the work dir. */
2
+ export declare const DEFAULT_ENTRY_FILE = "src/playground.ts";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ENTRY_FILE = void 0;
4
+ /** Default entry source file inside the work dir. */
5
+ exports.DEFAULT_ENTRY_FILE = "src/playground.ts";
6
+ //# sourceMappingURL=DEFAULT_ENTRY_FILE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DEFAULT_ENTRY_FILE.js","sourceRoot":"","sources":["../../../src/compiler/DEFAULT_ENTRY_FILE.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACxC,QAAA,kBAAkB,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Default plugin id for the `@ttsc/lint` check verb. Override via the
3
+ * `lintPlugin.name` option of {@link createWorkerCompiler}.
4
+ */
5
+ export declare const DEFAULT_LINT_PLUGIN_NAME = "@ttsc/lint";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_LINT_PLUGIN_NAME = void 0;
4
+ /**
5
+ * Default plugin id for the `@ttsc/lint` check verb. Override via the
6
+ * `lintPlugin.name` option of {@link createWorkerCompiler}.
7
+ */
8
+ exports.DEFAULT_LINT_PLUGIN_NAME = "@ttsc/lint";
9
+ //# sourceMappingURL=DEFAULT_LINT_PLUGIN_NAME.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DEFAULT_LINT_PLUGIN_NAME.js","sourceRoot":"","sources":["../../../src/compiler/DEFAULT_LINT_PLUGIN_NAME.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,wBAAwB,GAAG,YAAY,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The compiler options every playground tsconfig opts into by default. Sites
3
+ * pass these straight to `buildTsconfigJSON`; consumer code that needs a tweak
4
+ * spreads the constant and overrides individual fields.
5
+ *
6
+ * `target` and `module` are TypeScript's numeric enum values (99 = ESNext, 199
7
+ * = NodeNext, …). They are spelled numerically here because the wasm doesn't
8
+ * run the TS configuration parser through a string→enum step before Go reads
9
+ * the JSON; passing the canonical numbers avoids version-drift.
10
+ */
11
+ export declare const DEFAULT_PLAYGROUND_COMPILER_OPTIONS: {
12
+ readonly target: 99;
13
+ readonly esModuleInterop: true;
14
+ readonly forceConsistentCasingInFileNames: true;
15
+ readonly moduleResolution: 100;
16
+ readonly strict: true;
17
+ readonly skipLibCheck: true;
18
+ readonly experimentalDecorators: true;
19
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_PLAYGROUND_COMPILER_OPTIONS = void 0;
4
+ /**
5
+ * The compiler options every playground tsconfig opts into by default. Sites
6
+ * pass these straight to `buildTsconfigJSON`; consumer code that needs a tweak
7
+ * spreads the constant and overrides individual fields.
8
+ *
9
+ * `target` and `module` are TypeScript's numeric enum values (99 = ESNext, 199
10
+ * = NodeNext, …). They are spelled numerically here because the wasm doesn't
11
+ * run the TS configuration parser through a string→enum step before Go reads
12
+ * the JSON; passing the canonical numbers avoids version-drift.
13
+ */
14
+ exports.DEFAULT_PLAYGROUND_COMPILER_OPTIONS = {
15
+ target: 99,
16
+ esModuleInterop: true,
17
+ forceConsistentCasingInFileNames: true,
18
+ moduleResolution: 100,
19
+ strict: true,
20
+ skipLibCheck: true,
21
+ experimentalDecorators: true,
22
+ };
23
+ //# sourceMappingURL=DEFAULT_PLAYGROUND_COMPILER_OPTIONS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DEFAULT_PLAYGROUND_COMPILER_OPTIONS.js","sourceRoot":"","sources":["../../../src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACU,QAAA,mCAAmC,GAAG;IACjD,MAAM,EAAE,EAAE;IACV,eAAe,EAAE,IAAI;IACrB,gCAAgC,EAAE,IAAI;IACtC,gBAAgB,EAAE,GAAG;IACrB,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,sBAAsB,EAAE,IAAI;CACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Default tsconfig path inside the work dir. */
2
+ export declare const DEFAULT_TSCONFIG_PATH = "tsconfig.json";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TSCONFIG_PATH = void 0;
4
+ /** Default tsconfig path inside the work dir. */
5
+ exports.DEFAULT_TSCONFIG_PATH = "tsconfig.json";
6
+ //# sourceMappingURL=DEFAULT_TSCONFIG_PATH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DEFAULT_TSCONFIG_PATH.js","sourceRoot":"","sources":["../../../src/compiler/DEFAULT_TSCONFIG_PATH.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AACpC,QAAA,qBAAqB,GAAG,eAAe,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Default plugin id for the typia transformer. Sites that wire a renamed typia
3
+ * plugin override via the `typiaPlugin.name` option of
4
+ * {@link createWorkerCompiler}.
5
+ */
6
+ export declare const DEFAULT_TYPIA_PLUGIN_NAME = "typia";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TYPIA_PLUGIN_NAME = void 0;
4
+ /**
5
+ * Default plugin id for the typia transformer. Sites that wire a renamed typia
6
+ * plugin override via the `typiaPlugin.name` option of
7
+ * {@link createWorkerCompiler}.
8
+ */
9
+ exports.DEFAULT_TYPIA_PLUGIN_NAME = "typia";
10
+ //# sourceMappingURL=DEFAULT_TYPIA_PLUGIN_NAME.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DEFAULT_TYPIA_PLUGIN_NAME.js","sourceRoot":"","sources":["../../../src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACU,QAAA,yBAAyB,GAAG,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Default in-MemFS project root mounted by {@link createWorkerCompiler}. */
2
+ export declare const DEFAULT_WORK_DIR = "/work";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_WORK_DIR = void 0;
4
+ /** Default in-MemFS project root mounted by {@link createWorkerCompiler}. */
5
+ exports.DEFAULT_WORK_DIR = "/work";
6
+ //# sourceMappingURL=DEFAULT_WORK_DIR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DEFAULT_WORK_DIR.js","sourceRoot":"","sources":["../../../src/compiler/DEFAULT_WORK_DIR.ts"],"names":[],"mappings":";;;AAAA,6EAA6E;AAChE,QAAA,gBAAgB,GAAG,OAAO,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { IBuildTsconfigOptions } from "../structures/IBuildTsconfigOptions";
2
+ /**
3
+ * Serialize a tsconfig JSON document the wasm-side compiler can consume.
4
+ *
5
+ * `buildTsconfigJSON` is deliberately conservative — it returns a string the
6
+ * caller writes to MemFS as-is, so there's no schema validation here. Bad
7
+ * compiler options surface as wasm-side errors on the next build call.
8
+ */
9
+ export declare function buildTsconfigJSON(options: IBuildTsconfigOptions): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTsconfigJSON = buildTsconfigJSON;
4
+ const DEFAULT_PLAYGROUND_COMPILER_OPTIONS_1 = require("./DEFAULT_PLAYGROUND_COMPILER_OPTIONS");
5
+ /**
6
+ * Serialize a tsconfig JSON document the wasm-side compiler can consume.
7
+ *
8
+ * `buildTsconfigJSON` is deliberately conservative — it returns a string the
9
+ * caller writes to MemFS as-is, so there's no schema validation here. Bad
10
+ * compiler options surface as wasm-side errors on the next build call.
11
+ */
12
+ function buildTsconfigJSON(options) {
13
+ return JSON.stringify({
14
+ compilerOptions: {
15
+ ...DEFAULT_PLAYGROUND_COMPILER_OPTIONS_1.DEFAULT_PLAYGROUND_COMPILER_OPTIONS,
16
+ module: options.module,
17
+ outDir: options.outDir ?? "dist",
18
+ rootDir: options.rootDir ?? "src",
19
+ ...(options.compilerOptions ?? {}),
20
+ },
21
+ include: options.include ?? ["src"],
22
+ });
23
+ }
24
+ //# sourceMappingURL=buildTsconfigJSON.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTsconfigJSON.js","sourceRoot":"","sources":["../../../src/compiler/buildTsconfigJSON.ts"],"names":[],"mappings":";;;AACA,+FAA4F;AAE5F;;;;;;GAMG;AACH,2BAAkC,OAA8B;IAC9D,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,eAAe,EAAE;YACf,GAAG,yEAAmC;YACtC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,MAAM;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK;YACjC,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;SACnC;QACD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC;KACpC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { IMemFSHost } from "@ttsc/wasm";
2
+ import type { IInstallTypiaSourcePackOptions } from "../structures/IInstallTypiaSourcePackOptions";
3
+ /**
4
+ * Build a `mount` callback for the `typiaPlugin` config of
5
+ * {@link createWorkerCompiler}.
6
+ *
7
+ * The returned function fetches the pack once (cached per URL by
8
+ * {@link loadTypiaSourcePack}) and writes every entry to the MemFS the first
9
+ * time it is invoked on a given host.
10
+ */
11
+ export declare function createTypiaSourcePackMount(options: IInstallTypiaSourcePackOptions): (host: IMemFSHost, workDir?: string) => Promise<void>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTypiaSourcePackMount = createTypiaSourcePackMount;
4
+ const installTypiaSourcePack_1 = require("./installTypiaSourcePack");
5
+ /**
6
+ * Build a `mount` callback for the `typiaPlugin` config of
7
+ * {@link createWorkerCompiler}.
8
+ *
9
+ * The returned function fetches the pack once (cached per URL by
10
+ * {@link loadTypiaSourcePack}) and writes every entry to the MemFS the first
11
+ * time it is invoked on a given host.
12
+ */
13
+ function createTypiaSourcePackMount(options) {
14
+ return async (host, workDir) => {
15
+ // Honor the caller's workDir when the site did not pin mountRoot
16
+ // explicitly. Otherwise a `createWorkerCompiler({workDir: '/foo'})`
17
+ // would still mount typia under `/work/node_modules/` and tsgo would
18
+ // never resolve `typia` from the project root.
19
+ //
20
+ // `workDir` is intentionally optional so callers built against the
21
+ // previous single-arg signature (`mount(host)`) keep working — when
22
+ // both mountRoot and workDir are absent, installTypiaSourcePack falls
23
+ // back to its own default (`/work/node_modules`).
24
+ const mountRoot = options.mountRoot ??
25
+ (workDir ? `${workDir.replace(/\/+$/, "")}/node_modules` : undefined);
26
+ await (0, installTypiaSourcePack_1.installTypiaSourcePack)(host, { ...options, mountRoot });
27
+ };
28
+ }
29
+ //# sourceMappingURL=createTypiaSourcePackMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTypiaSourcePackMount.js","sourceRoot":"","sources":["../../../src/compiler/createTypiaSourcePackMount.ts"],"names":[],"mappings":";;;AAGA,qEAAkE;AAElE;;;;;;;GAOG;AACH,oCACE,OAAuC;IAEvC,OAAO,KAAK,EAAE,IAAgB,EAAE,OAAgB,EAAE,EAAE;QAClD,iEAAiE;QACjE,oEAAoE;QACpE,qEAAqE;QACrE,+CAA+C;QAC/C,EAAE;QACF,mEAAmE;QACnE,oEAAoE;QACpE,sEAAsE;QACtE,kDAAkD;QAClD,MAAM,SAAS,GACb,OAAO,CAAC,SAAS;YACjB,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACxE,MAAM,IAAA,+CAAsB,EAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { ICompilerService } from "../structures/ICompilerService";
2
+ import type { ICreateWorkerCompilerOptions } from "../structures/ICreateWorkerCompilerOptions";
3
+ /**
4
+ * Build an `ICompilerService` ready to register with tgrid's `WorkerServer`.
5
+ *
6
+ * Usage in the worker entry:
7
+ *
8
+ * ```ts
9
+ * import { createWorkerCompiler } from "@ttsc/playground";
10
+ * import { WorkerServer } from "tgrid";
11
+ *
12
+ * const service = createWorkerCompiler({
13
+ * wasmUrl: "/compiler/playground.wasm",
14
+ * apiName: "ttscPlayground",
15
+ * typiaPlugin: { mount: installTypiaPack },
16
+ * });
17
+ *
18
+ * const main = async () => {
19
+ * const worker = new WorkerServer();
20
+ * await worker.open(service);
21
+ * };
22
+ * void main();
23
+ * ```
24
+ */
25
+ export declare function createWorkerCompiler(options: ICreateWorkerCompilerOptions): ICompilerService;