@ttsc/playground 0.14.0-dev.20260528.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 +230 -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 +2 -0
  37. package/lib/src/compiler/internal/joinUnder.js +10 -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 +26 -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 +83 -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 +15 -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 +2 -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 +64 -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 +274 -0
  187. package/src/compiler/installDependenciesIntoMemFS.ts +28 -0
  188. package/src/compiler/installTypiaSourcePack.ts +24 -0
  189. package/src/compiler/internal/joinUnder.ts +5 -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 +23 -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 +288 -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 +79 -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 +95 -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 +15 -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 +9 -0
  230. package/src/structures/IPlaygroundExample.ts +16 -0
  231. package/src/structures/IPlaygroundShellProps.ts +77 -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,230 @@
1
+ # @ttsc/playground
2
+
3
+ > **API stability: experimental until v1.0.** Public signatures (the
4
+ > `createWorkerCompiler` options, `ICompilerService` contract, React
5
+ > component props) may change between minor releases. Pin exact versions in
6
+ > production playgrounds.
7
+
8
+ Reusable Web Worker + React scaffolding for in-browser
9
+ [`ttsc`](https://ttsc.dev) playgrounds. Built on top of
10
+ [`@ttsc/wasm`](https://github.com/samchon/ttsc/tree/master/packages/wasm).
11
+
12
+ The package handles the parts every browser playground needs — worker boot,
13
+ MemFS layout, race-guarded compile / lint / bundle calls, on-the-fly npm
14
+ dependency installer, typia source-pack mounting, console-capturing execute
15
+ sandbox — and ships a Tailwind-styled React shell that wires them all up.
16
+ Sites supply the wasm URL, a default script, and (optionally) examples,
17
+ brand slot, and an execute callback.
18
+
19
+ The ttsc website (`ttsc.dev`) and the typia website (`typia.io`) are the two
20
+ reference consumers.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install @ttsc/playground @ttsc/wasm \
26
+ @monaco-editor/react monaco-editor react react-dom tgrid tailwindcss
27
+ ```
28
+
29
+ `@monaco-editor/react`, `monaco-editor`, `react`, `react-dom`, `tgrid`, and
30
+ `@ttsc/wasm` are **peer dependencies**. `lz-string` is bundled.
31
+
32
+ The React components use Tailwind 4 utility classes — see
33
+ [Tailwind setup](#tailwind-setup) below.
34
+
35
+ ## What you get
36
+
37
+ | Layer | Exports |
38
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
39
+ | **Worker core** | `createWorkerCompiler`, `buildTsconfigJSON`, `installDependenciesIntoMemFS`, `mapDiagnostic`, `pickEmittedJS`, `DEFAULT_*` constants |
40
+ | **Typia integration** | `createTypiaSourcePackMount`, `installTypiaSourcePack`, `loadTypiaSourcePack` |
41
+ | **Npm installer** | `installPlaygroundDependencies`, `collectExternalPackageNames`, `packageNameFromSpecifier`, `BUILT_IN_PLAYGROUND_PACKAGES` |
42
+ | **Execute sandbox** | `createSandboxRequire`, `loadTypiaRuntimePack` |
43
+ | **React UI** | `PlaygroundShell`, `SourceEditor`, `ResultViewer`, `ConsoleViewer`, `OptionsPanel`, `DiagnosticsPanel`, `DependencyProgressModal`, `ExamplePicker`, `LintPane`, `createCompilerClient`, `DEFAULT_OPTION_TOGGLES` |
44
+ | **Types** | Everything under `./src/structures/` |
45
+
46
+ ## Architecture
47
+
48
+ ```
49
+ ┌─ Browser tab ───────────────────────────────────────────┐
50
+ │ │
51
+ │ <PlaygroundShell> ─── tgrid RPC ───┐ │
52
+ │ ↳ SourceEditor (Monaco) │ │
53
+ │ ↳ ResultViewer ▼ │
54
+ │ ↳ ConsoleViewer ┌────────────────┐│
55
+ │ ↳ DiagnosticsPanel │ Web Worker ││
56
+ │ ↳ DependencyProgressModal │ ││
57
+ │ ↳ ExamplePicker │ createWorker ││
58
+ │ ↳ OptionsPanel │ Compiler() ││
59
+ │ ↳ LintPane │ ↓ ││
60
+ │ │ @ttsc/wasm ││
61
+ │ (UI installs runtime npm deps │ bootTtsc() ││
62
+ │ into the same worker MemFS via │ ↓ ││
63
+ │ service.installDependencies()) │ MemFS ││
64
+ │ │ └─ /work/… ││
65
+ │ │ ttsc.wasm ││
66
+ │ └────────────────┘│
67
+ └─────────────────────────────────────────────────────────┘
68
+ ```
69
+
70
+ ## Worker entry (site-side)
71
+
72
+ The worker entry is two lines. Wire the wasm URL the site ships and the
73
+ `apiName` you used in `host.Expose` when you built the wasm.
74
+
75
+ ```ts
76
+ // site/src/compiler/index.ts (rspack target: "webworker")
77
+ import { createWorkerCompiler } from "@ttsc/playground";
78
+ import { WorkerServer } from "tgrid";
79
+
80
+ const service = createWorkerCompiler({
81
+ wasmUrl: "/compiler/playground.wasm",
82
+ wasmExecUrl: "/compiler/wasm_exec.js",
83
+ apiName: "ttscPlayground",
84
+ });
85
+
86
+ await new WorkerServer().open(service);
87
+ ```
88
+
89
+ Bundle this file with rspack/webpack/vite as a webworker target and serve
90
+ the output (e.g. at `/compiler/index.js`).
91
+
92
+ ## UI shell (site-side)
93
+
94
+ ```tsx
95
+ // site/src/components/playground/PlaygroundShell.tsx
96
+ "use client";
97
+ import { PlaygroundShell } from "@ttsc/playground";
98
+ import { PLAYGROUND_DEFAULT_SCRIPT, PLAYGROUND_EXAMPLES } from "../...";
99
+
100
+ export default function SitePlayground() {
101
+ return (
102
+ <PlaygroundShell
103
+ workerUrl="/compiler/index.js"
104
+ defaultScript={PLAYGROUND_DEFAULT_SCRIPT}
105
+ examples={PLAYGROUND_EXAMPLES}
106
+ brand={<a href="/">my-site</a>}
107
+ executeBundle={async (code, sandbox) => {
108
+ // run the compiled JS however you like; route console.* into sandbox.console
109
+ new Function("console", code)(sandbox.console);
110
+ }}
111
+ />
112
+ );
113
+ }
114
+ ```
115
+
116
+ ## Typia integration (optional)
117
+
118
+ When the wasm bundles the typia transform plugin, mount typia's source tree
119
+ into the MemFS so `import typia from "typia"` resolves:
120
+
121
+ ```ts
122
+ import {
123
+ createTypiaSourcePackMount,
124
+ createWorkerCompiler,
125
+ } from "@ttsc/playground";
126
+
127
+ const service = createWorkerCompiler({
128
+ wasmUrl: "/compiler/playground.wasm",
129
+ apiName: "ttscPlayground",
130
+ typiaPlugin: {
131
+ name: "typia",
132
+ transformModule: "typia/lib/transform",
133
+ mount: createTypiaSourcePackMount({
134
+ url: "/compiler/typia-pack.json",
135
+ }),
136
+ },
137
+ });
138
+ ```
139
+
140
+ The typia pack itself is built by the site (typically with a
141
+ `pack-typia-sources.cjs`-style script that bundles `typia/`, `@typia/utils`,
142
+ and `@typia/interface` into a flat JSON map). See the ttsc website's
143
+ [`build/pack-typia-sources.cjs`](https://github.com/samchon/ttsc/blob/master/website/build/pack-typia-sources.cjs)
144
+ for the reference implementation.
145
+
146
+ ## Runtime npm dependency installer
147
+
148
+ When the user types `import {v4} from "uuid"`, the shell auto-fetches `uuid`
149
+ (and its transitive deps) from the npm registry, unpacks the tgz in the
150
+ browser, and mounts the files into the wasm MemFS — no proxy server needed.
151
+
152
+ ```ts
153
+ import {
154
+ collectExternalPackageNames,
155
+ installPlaygroundDependencies,
156
+ } from "@ttsc/playground";
157
+
158
+ const names = collectExternalPackageNames(userSource);
159
+ const installed = await installPlaygroundDependencies(names, {
160
+ onProgress: (p) => console.log(p.phase, p.packageName),
161
+ });
162
+ // mount installed.compilerFiles into the wasm MemFS via service.installDependencies
163
+ ```
164
+
165
+ `PlaygroundShell` wires this automatically on every keystroke, debounced 900
166
+ ms, with an abort signal on source change.
167
+
168
+ ## Tailwind setup
169
+
170
+ The bundled React components use Tailwind 4 utility classes. The host site
171
+ must load Tailwind for them to render correctly.
172
+
173
+ `postcss.config.mjs`:
174
+
175
+ ```js
176
+ const config = { plugins: { "@tailwindcss/postcss": {} } };
177
+ export default config;
178
+ ```
179
+
180
+ `src/app/global.css`:
181
+
182
+ ```css
183
+ @import "tailwindcss";
184
+
185
+ /* Tell Tailwind 4 to scan @ttsc/playground's compiled output for utility
186
+ classes. Tailwind 4's @source takes a literal glob relative to this
187
+ CSS file — adjust the leading `../` segments to match how deep the
188
+ CSS file lives. Tailwind 4 follows the pnpm symlink at
189
+ node_modules/@ttsc/playground transparently. */
190
+ @source "../../node_modules/@ttsc/playground/lib/**/*.js";
191
+ ```
192
+
193
+ Then `import "./global.css"` from the root layout.
194
+
195
+ **`@ttsc/playground` must be a direct dependency** of the consuming
196
+ package. Tailwind only scans paths the consumer points at — a
197
+ transitively-installed copy (where @ttsc/playground is a dep of another
198
+ package) lives under a different node_modules layout and the glob above
199
+ won't find it without explicit re-targeting.
200
+
201
+ ## Booting a custom wasm
202
+
203
+ `createWorkerCompiler` is plugin-agnostic. To register a custom plugin set:
204
+
205
+ 1. Write a Go `main_wasm.go` that calls `host.Expose("myApi", host.Config{
206
+ Plugins: [...] })`. See [`@ttsc/wasm`](https://github.com/samchon/ttsc/tree/master/packages/wasm)
207
+ for the host helper and the plugin contract.
208
+ 2. Build the wasm with `GOOS=js GOARCH=wasm go build`.
209
+ 3. Ship the wasm at any URL and pass it to `createWorkerCompiler({wasmUrl,
210
+ apiName})`.
211
+
212
+ If the wasm registers plugins other than typia / `@ttsc/lint`, pass
213
+ `typiaPlugin: false` / `lintPlugin: false` to skip those default dispatchers
214
+ and use your own toggles via `optionToggles` + a custom worker wrapper.
215
+
216
+ ## Conventions
217
+
218
+ - **One type per file.** Public interfaces / types each live under
219
+ `src/structures/` in a file named after the type. The barrel
220
+ `structures/index.ts` re-exports everything.
221
+ - **One public function per file.** Internal helpers may be grouped in
222
+ `compiler/internal/` or `npm/internal/`.
223
+ - **No sub-path exports.** Every public symbol is importable from the
224
+ package root. Add a sub-path later only when a real consumer needs to
225
+ avoid pulling React into a Node-only context.
226
+
227
+ ## Documents
228
+
229
+ See the [`@ttsc/playground` guide](https://ttsc.dev/docs/playground) for the
230
+ 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,
7
+ * 199 = NodeNext, …). They are spelled numerically here because the wasm
8
+ * doesn't run the TS configuration parser through a string→enum step before
9
+ * Go reads 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,
10
+ * 199 = NodeNext, …). They are spelled numerically here because the wasm
11
+ * doesn't run the TS configuration parser through a string→enum step before
12
+ * Go reads 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
3
+ * typia 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
6
+ * typia 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;