@ttsc/playground 0.23.0 → 0.25.0

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.
@@ -1,121 +1,121 @@
1
- "use client";
2
-
3
- import type { JSX } from "react";
4
-
5
- import type { IConsoleMessage } from "../structures/IConsoleMessage";
6
-
7
- interface ConsoleViewerProps {
8
- messages: IConsoleMessage[];
9
- empty?: string;
10
- }
11
-
12
- export function ConsoleViewer({
13
- messages,
14
- empty = "No output yet. Click Execute to run the compiled JavaScript.",
15
- }: ConsoleViewerProps) {
16
- if (messages.length === 0)
17
- return (
18
- <div className="flex h-full w-full items-center justify-center px-4 text-center font-mono text-[11px] text-slate-400">
19
- {empty}
20
- </div>
21
- );
22
- return (
23
- <div className="h-full w-full overflow-auto p-3 font-mono text-[12px] leading-snug">
24
- {messages.map((msg, i) => (
25
- <div
26
- key={i}
27
- className="flex gap-2 border-b border-[#d8e7f4] py-1 last:border-b-0"
28
- >
29
- <span
30
- className={`shrink-0 text-[10px] uppercase tracking-wider w-12 ${typeColor(
31
- msg.type,
32
- )}`}
33
- >
34
- {msg.type}
35
- </span>
36
- <span className="flex-1 whitespace-pre-wrap break-words text-slate-700">
37
- {(Array.isArray(msg.value) ? msg.value : [msg.value]).map(
38
- (arg, idx) => (
39
- <span key={idx}>
40
- {idx > 0 ? " " : ""}
41
- {formatValue(arg)}
42
- </span>
43
- ),
44
- )}
45
- </span>
46
- </div>
47
- ))}
48
- </div>
49
- );
50
- }
51
-
52
- function typeColor(type: IConsoleMessage["type"]): string {
53
- switch (type) {
54
- case "error":
55
- return "text-red-600";
56
- case "warn":
57
- return "text-amber-600";
58
- case "info":
59
- return "text-sky-700";
60
- case "debug":
61
- return "text-fuchsia-700";
62
- case "dir":
63
- case "table":
64
- return "text-cyan-700";
65
- default:
66
- return "text-emerald-700";
67
- }
68
- }
69
-
70
- function formatValue(value: unknown, depth = 0): JSX.Element {
71
- if (typeof value === "string")
72
- return <span className="text-amber-700">{JSON.stringify(value)}</span>;
73
- if (typeof value === "number")
74
- return <span className="text-purple-700">{String(value)}</span>;
75
- if (typeof value === "boolean")
76
- return <span className="text-sky-700">{String(value)}</span>;
77
- if (value === null) return <span className="text-slate-500">null</span>;
78
- if (value === undefined)
79
- return <span className="text-slate-500">undefined</span>;
80
- if (typeof value === "function")
81
- return <span className="text-slate-500">[Function]</span>;
82
- if (Array.isArray(value))
83
- return (
84
- <span>
85
- [
86
- {value.map((item, idx) => (
87
- <span key={idx}>
88
- {idx > 0 ? ", " : ""}
89
- {formatValue(item, depth + 1)}
90
- </span>
91
- ))}
92
- ]
93
- </span>
94
- );
95
- if (value instanceof Error)
96
- return (
97
- <span className="text-red-700">
98
- {value.name}: {value.message}
99
- </span>
100
- );
101
- try {
102
- const entries = Object.entries(value as Record<string, unknown>);
103
- if (entries.length === 0) return <span>{"{}"}</span>;
104
- if (depth > 4) return <span className="text-slate-500">[...]</span>;
105
- return (
106
- <span>
107
- {"{"}
108
- {entries.map(([k, v], idx) => (
109
- <span key={k}>
110
- {idx > 0 ? ", " : " "}
111
- <span className="text-[#3178c6]">{k}</span>:{" "}
112
- {formatValue(v, depth + 1)}
113
- </span>
114
- ))}
115
- {" }"}
116
- </span>
117
- );
118
- } catch {
119
- return <span>{String(value)}</span>;
120
- }
121
- }
1
+ "use client";
2
+
3
+ import type { JSX } from "react";
4
+
5
+ import type { IConsoleMessage } from "../structures/IConsoleMessage";
6
+
7
+ interface ConsoleViewerProps {
8
+ messages: IConsoleMessage[];
9
+ empty?: string;
10
+ }
11
+
12
+ export function ConsoleViewer({
13
+ messages,
14
+ empty = "No output yet. Click Execute to run the compiled JavaScript.",
15
+ }: ConsoleViewerProps) {
16
+ if (messages.length === 0)
17
+ return (
18
+ <div className="flex h-full w-full items-center justify-center px-4 text-center font-mono text-[11px] text-slate-400">
19
+ {empty}
20
+ </div>
21
+ );
22
+ return (
23
+ <div className="h-full w-full overflow-auto p-3 font-mono text-[12px] leading-snug">
24
+ {messages.map((msg, i) => (
25
+ <div
26
+ key={i}
27
+ className="flex gap-2 border-b border-[#d8e7f4] py-1 last:border-b-0"
28
+ >
29
+ <span
30
+ className={`shrink-0 text-[10px] uppercase tracking-wider w-12 ${typeColor(
31
+ msg.type,
32
+ )}`}
33
+ >
34
+ {msg.type}
35
+ </span>
36
+ <span className="flex-1 whitespace-pre-wrap break-words text-slate-700">
37
+ {(Array.isArray(msg.value) ? msg.value : [msg.value]).map(
38
+ (arg, idx) => (
39
+ <span key={idx}>
40
+ {idx > 0 ? " " : ""}
41
+ {formatValue(arg)}
42
+ </span>
43
+ ),
44
+ )}
45
+ </span>
46
+ </div>
47
+ ))}
48
+ </div>
49
+ );
50
+ }
51
+
52
+ function typeColor(type: IConsoleMessage["type"]): string {
53
+ switch (type) {
54
+ case "error":
55
+ return "text-red-600";
56
+ case "warn":
57
+ return "text-amber-600";
58
+ case "info":
59
+ return "text-sky-700";
60
+ case "debug":
61
+ return "text-fuchsia-700";
62
+ case "dir":
63
+ case "table":
64
+ return "text-cyan-700";
65
+ default:
66
+ return "text-emerald-700";
67
+ }
68
+ }
69
+
70
+ function formatValue(value: unknown, depth = 0): JSX.Element {
71
+ if (typeof value === "string")
72
+ return <span className="text-amber-700">{JSON.stringify(value)}</span>;
73
+ if (typeof value === "number")
74
+ return <span className="text-purple-700">{String(value)}</span>;
75
+ if (typeof value === "boolean")
76
+ return <span className="text-sky-700">{String(value)}</span>;
77
+ if (value === null) return <span className="text-slate-500">null</span>;
78
+ if (value === undefined)
79
+ return <span className="text-slate-500">undefined</span>;
80
+ if (typeof value === "function")
81
+ return <span className="text-slate-500">[Function]</span>;
82
+ if (Array.isArray(value))
83
+ return (
84
+ <span>
85
+ [
86
+ {value.map((item, idx) => (
87
+ <span key={idx}>
88
+ {idx > 0 ? ", " : ""}
89
+ {formatValue(item, depth + 1)}
90
+ </span>
91
+ ))}
92
+ ]
93
+ </span>
94
+ );
95
+ if (value instanceof Error)
96
+ return (
97
+ <span className="text-red-700">
98
+ {value.name}: {value.message}
99
+ </span>
100
+ );
101
+ try {
102
+ const entries = Object.entries(value as Record<string, unknown>);
103
+ if (entries.length === 0) return <span>{"{}"}</span>;
104
+ if (depth > 4) return <span className="text-slate-500">[...]</span>;
105
+ return (
106
+ <span>
107
+ {"{"}
108
+ {entries.map(([k, v], idx) => (
109
+ <span key={k}>
110
+ {idx > 0 ? ", " : " "}
111
+ <span className="text-[#3178c6]">{k}</span>:{" "}
112
+ {formatValue(v, depth + 1)}
113
+ </span>
114
+ ))}
115
+ {" }"}
116
+ </span>
117
+ );
118
+ } catch {
119
+ return <span>{String(value)}</span>;
120
+ }
121
+ }
@@ -1,73 +1,73 @@
1
- "use client";
2
-
3
- import type { IPlaygroundDependencyProgress } from "../structures/IPlaygroundDependencyProgress";
4
-
5
- interface DependencyProgressModalProps {
6
- progress: IPlaygroundDependencyProgress | null;
7
- packages: readonly string[];
8
- }
9
-
10
- export function DependencyProgressModal({
11
- progress,
12
- packages,
13
- }: DependencyProgressModalProps) {
14
- if (!progress) return null;
15
- const total = Math.max(progress.total, 1);
16
- const ratio = Math.min(1, Math.max(0, progress.completed / total));
17
- const activePackage =
18
- progress.packageName && progress.version
19
- ? `${progress.packageName}@${progress.version}`
20
- : progress.packageName;
21
-
22
- return (
23
- <div className="fixed inset-0 z-50 flex items-center justify-center bg-[#102a43]/35 px-4 backdrop-blur-sm">
24
- <div className="w-full max-w-md rounded-2xl border border-[#b9d5ee] bg-white p-5 shadow-[0_28px_70px_rgba(35,90,151,0.25)]">
25
- <div className="flex items-start justify-between gap-4">
26
- <div>
27
- <div className="font-mono text-[11px] uppercase text-[#3178c6]">
28
- Dependencies
29
- </div>
30
- <h2 className="mt-1 font-mono text-base text-[#102a43]">
31
- Installing npm packages
32
- </h2>
33
- </div>
34
- <div className="font-mono text-[11px] text-slate-500">
35
- {progress.completed}/{total}
36
- </div>
37
- </div>
38
-
39
- <div className="mt-4 h-2 overflow-hidden rounded-full bg-[#e7f0f8]">
40
- <div
41
- className="h-full bg-[#3178c6] transition-[width]"
42
- style={{ width: `${Math.max(8, ratio * 100)}%` }}
43
- />
44
- </div>
45
-
46
- <div className="mt-4 space-y-1 font-mono">
47
- {activePackage && (
48
- <div className="text-[12px] text-slate-700">{activePackage}</div>
49
- )}
50
- <div className="text-[11px] text-slate-500">{progress.message}</div>
51
- </div>
52
-
53
- {packages.length > 0 && (
54
- <div className="mt-4 flex flex-wrap gap-1.5">
55
- {packages.slice(0, 8).map((name) => (
56
- <span
57
- key={name}
58
- className="rounded border border-[#d2e4f4] bg-[#f7fbff] px-2 py-1 font-mono text-[10px] text-slate-600"
59
- >
60
- {name}
61
- </span>
62
- ))}
63
- {packages.length > 8 && (
64
- <span className="rounded border border-[#d2e4f4] bg-[#f7fbff] px-2 py-1 font-mono text-[10px] text-slate-500">
65
- +{packages.length - 8}
66
- </span>
67
- )}
68
- </div>
69
- )}
70
- </div>
71
- </div>
72
- );
73
- }
1
+ "use client";
2
+
3
+ import type { IPlaygroundDependencyProgress } from "../structures/IPlaygroundDependencyProgress";
4
+
5
+ interface DependencyProgressModalProps {
6
+ progress: IPlaygroundDependencyProgress | null;
7
+ packages: readonly string[];
8
+ }
9
+
10
+ export function DependencyProgressModal({
11
+ progress,
12
+ packages,
13
+ }: DependencyProgressModalProps) {
14
+ if (!progress) return null;
15
+ const total = Math.max(progress.total, 1);
16
+ const ratio = Math.min(1, Math.max(0, progress.completed / total));
17
+ const activePackage =
18
+ progress.packageName && progress.version
19
+ ? `${progress.packageName}@${progress.version}`
20
+ : progress.packageName;
21
+
22
+ return (
23
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-[#102a43]/35 px-4 backdrop-blur-sm">
24
+ <div className="w-full max-w-md rounded-2xl border border-[#b9d5ee] bg-white p-5 shadow-[0_28px_70px_rgba(35,90,151,0.25)]">
25
+ <div className="flex items-start justify-between gap-4">
26
+ <div>
27
+ <div className="font-mono text-[11px] uppercase text-[#3178c6]">
28
+ Dependencies
29
+ </div>
30
+ <h2 className="mt-1 font-mono text-base text-[#102a43]">
31
+ Installing npm packages
32
+ </h2>
33
+ </div>
34
+ <div className="font-mono text-[11px] text-slate-500">
35
+ {progress.completed}/{total}
36
+ </div>
37
+ </div>
38
+
39
+ <div className="mt-4 h-2 overflow-hidden rounded-full bg-[#e7f0f8]">
40
+ <div
41
+ className="h-full bg-[#3178c6] transition-[width]"
42
+ style={{ width: `${Math.max(8, ratio * 100)}%` }}
43
+ />
44
+ </div>
45
+
46
+ <div className="mt-4 space-y-1 font-mono">
47
+ {activePackage && (
48
+ <div className="text-[12px] text-slate-700">{activePackage}</div>
49
+ )}
50
+ <div className="text-[11px] text-slate-500">{progress.message}</div>
51
+ </div>
52
+
53
+ {packages.length > 0 && (
54
+ <div className="mt-4 flex flex-wrap gap-1.5">
55
+ {packages.slice(0, 8).map((name) => (
56
+ <span
57
+ key={name}
58
+ className="rounded border border-[#d2e4f4] bg-[#f7fbff] px-2 py-1 font-mono text-[10px] text-slate-600"
59
+ >
60
+ {name}
61
+ </span>
62
+ ))}
63
+ {packages.length > 8 && (
64
+ <span className="rounded border border-[#d2e4f4] bg-[#f7fbff] px-2 py-1 font-mono text-[10px] text-slate-500">
65
+ +{packages.length - 8}
66
+ </span>
67
+ )}
68
+ </div>
69
+ )}
70
+ </div>
71
+ </div>
72
+ );
73
+ }
@@ -1,74 +1,74 @@
1
- "use client";
2
-
3
- import { useState } from "react";
4
-
5
- import type { ICompilerService } from "../structures/ICompilerService";
6
-
7
- export function DiagnosticsPanel({
8
- diagnostics,
9
- }: {
10
- diagnostics: ICompilerService.IDiagnostic[];
11
- }) {
12
- const [expanded, setExpanded] = useState(false);
13
- const errorCount = diagnostics.filter((d) => d.severity === "error").length;
14
- const warnCount = diagnostics.filter((d) => d.severity === "warning").length;
15
-
16
- if (diagnostics.length === 0)
17
- return (
18
- <div className="flex shrink-0 items-center gap-3 border-t border-[#c7dff4] bg-[#eef6ff] px-4 py-2">
19
- <span className="text-emerald-400 text-xs">●</span>
20
- <span className="font-mono text-[12px] text-slate-600">
21
- 0 errors · 0 warnings
22
- </span>
23
- </div>
24
- );
25
-
26
- return (
27
- <div className="shrink-0 border-t border-[#c7dff4] bg-[#eef6ff]">
28
- <button
29
- onClick={() => setExpanded((v) => !v)}
30
- className="flex w-full items-center gap-3 px-4 py-2 text-left transition-colors hover:bg-[#e1effc]"
31
- >
32
- <span
33
- className={`text-xs ${
34
- errorCount > 0 ? "text-red-400" : "text-yellow-400"
35
- }`}
36
- >
37
-
38
- </span>
39
- <span className="font-mono text-[12px] text-slate-700">
40
- {errorCount} error{errorCount === 1 ? "" : "s"} · {warnCount} warning
41
- {warnCount === 1 ? "" : "s"}
42
- </span>
43
- <span className="ml-auto font-mono text-[10px] text-slate-400">
44
- {expanded ? "▲ collapse" : "▼ expand"}
45
- </span>
46
- </button>
47
- {expanded && (
48
- <div className="max-h-48 overflow-auto border-t border-[#c7dff4]">
49
- {diagnostics.map((d, i) => (
50
- <div
51
- key={i}
52
- className="flex gap-3 border-b border-[#d8e7f4] px-4 py-2 font-mono text-[12px] last:border-b-0"
53
- >
54
- <span
55
- className={`shrink-0 ${
56
- d.severity === "error" ? "text-red-400" : "text-yellow-400"
57
- }`}
58
- >
59
- {d.severity === "error" ? "✗" : "!"}
60
- </span>
61
- <span className="w-16 shrink-0 text-slate-500">
62
- {d.line}:{d.column}
63
- </span>
64
- <span className="w-16 shrink-0 text-slate-400">
65
- {d.code ?? ""}
66
- </span>
67
- <span className="text-slate-700">{d.message}</span>
68
- </div>
69
- ))}
70
- </div>
71
- )}
72
- </div>
73
- );
74
- }
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+
5
+ import type { ICompilerService } from "../structures/ICompilerService";
6
+
7
+ export function DiagnosticsPanel({
8
+ diagnostics,
9
+ }: {
10
+ diagnostics: ICompilerService.IDiagnostic[];
11
+ }) {
12
+ const [expanded, setExpanded] = useState(false);
13
+ const errorCount = diagnostics.filter((d) => d.severity === "error").length;
14
+ const warnCount = diagnostics.filter((d) => d.severity === "warning").length;
15
+
16
+ if (diagnostics.length === 0)
17
+ return (
18
+ <div className="flex shrink-0 items-center gap-3 border-t border-[#c7dff4] bg-[#eef6ff] px-4 py-2">
19
+ <span className="text-emerald-400 text-xs">●</span>
20
+ <span className="font-mono text-[12px] text-slate-600">
21
+ 0 errors · 0 warnings
22
+ </span>
23
+ </div>
24
+ );
25
+
26
+ return (
27
+ <div className="shrink-0 border-t border-[#c7dff4] bg-[#eef6ff]">
28
+ <button
29
+ onClick={() => setExpanded((v) => !v)}
30
+ className="flex w-full items-center gap-3 px-4 py-2 text-left transition-colors hover:bg-[#e1effc]"
31
+ >
32
+ <span
33
+ className={`text-xs ${
34
+ errorCount > 0 ? "text-red-400" : "text-yellow-400"
35
+ }`}
36
+ >
37
+
38
+ </span>
39
+ <span className="font-mono text-[12px] text-slate-700">
40
+ {errorCount} error{errorCount === 1 ? "" : "s"} · {warnCount} warning
41
+ {warnCount === 1 ? "" : "s"}
42
+ </span>
43
+ <span className="ml-auto font-mono text-[10px] text-slate-400">
44
+ {expanded ? "▲ collapse" : "▼ expand"}
45
+ </span>
46
+ </button>
47
+ {expanded && (
48
+ <div className="max-h-48 overflow-auto border-t border-[#c7dff4]">
49
+ {diagnostics.map((d, i) => (
50
+ <div
51
+ key={i}
52
+ className="flex gap-3 border-b border-[#d8e7f4] px-4 py-2 font-mono text-[12px] last:border-b-0"
53
+ >
54
+ <span
55
+ className={`shrink-0 ${
56
+ d.severity === "error" ? "text-red-400" : "text-yellow-400"
57
+ }`}
58
+ >
59
+ {d.severity === "error" ? "✗" : "!"}
60
+ </span>
61
+ <span className="w-16 shrink-0 text-slate-500">
62
+ {d.line}:{d.column}
63
+ </span>
64
+ <span className="w-16 shrink-0 text-slate-400">
65
+ {d.code ?? ""}
66
+ </span>
67
+ <span className="text-slate-700">{d.message}</span>
68
+ </div>
69
+ ))}
70
+ </div>
71
+ )}
72
+ </div>
73
+ );
74
+ }