Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/terminal/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const AceEditor = lazy(async () => {
await import("ace-builds/src-min-noconflict/mode-json");
await import("ace-builds/src-min-noconflict/mode-csv");
await import("ace-builds/src-min-noconflict/mode-text");
await import("ace-builds/src-min-noconflict/mode-dart");
return ace;
} else {
throw new Error("should not try SSR");
Expand Down
10 changes: 10 additions & 0 deletions app/terminal/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ export function LanguageIcon(props: Props) {
<path d="M31.584 15.615l-1.329-0.823c-0.009-0.131-0.020-0.261-0.036-0.385l1.141-1.063c0.244-0.235 0.161-0.647-0.152-0.765l-1.459-0.543c-0.036-0.129-0.072-0.255-0.113-0.38l0.905-1.26c0.204-0.276 0.043-0.661-0.296-0.719l-1.537-0.251c-0.057-0.115-0.12-0.229-0.181-0.344l0.645-1.416c0.068-0.145 0.052-0.312-0.036-0.443-0.089-0.131-0.24-0.208-0.396-0.203l-1.563 0.057c-0.079-0.105-0.161-0.204-0.245-0.303l0.36-1.516c0.077-0.333-0.219-0.629-0.552-0.552l-1.516 0.36c-0.099-0.084-0.197-0.167-0.303-0.245l0.057-1.563c0.016-0.339-0.339-0.577-0.645-0.432l-1.416 0.645c-0.115-0.061-0.229-0.124-0.349-0.181l-0.251-1.537c-0.057-0.333-0.443-0.495-0.719-0.296l-1.26 0.905c-0.125-0.041-0.251-0.077-0.375-0.113l-0.548-1.453c-0.119-0.319-0.531-0.401-0.76-0.157l-1.063 1.147c-0.129-0.016-0.26-0.032-0.391-0.041l-0.817-1.324c-0.177-0.291-0.599-0.291-0.776 0l-0.823 1.324c-0.131 0.009-0.26 0.025-0.385 0.041l-1.063-1.147c-0.235-0.244-0.645-0.167-0.765 0.157l-0.543 1.453c-0.129 0.036-0.249 0.077-0.38 0.113l-1.26-0.905c-0.276-0.199-0.661-0.037-0.719 0.296l-0.251 1.537c-0.115 0.057-0.228 0.12-0.343 0.181l-1.417-0.645c-0.312-0.14-0.661 0.093-0.645 0.432l0.052 1.563c-0.099 0.079-0.199 0.161-0.297 0.245l-1.52-0.36c-0.329-0.077-0.625 0.219-0.548 0.552l0.355 1.516c-0.084 0.099-0.161 0.197-0.245 0.303l-1.557-0.057c-0.343-0.011-0.572 0.339-0.432 0.645l0.647 1.416c-0.063 0.115-0.125 0.229-0.188 0.344l-1.536 0.251c-0.333 0.057-0.491 0.443-0.297 0.719l0.912 1.26c-0.043 0.131-0.079 0.251-0.115 0.38l-1.459 0.543c-0.317 0.119-0.396 0.531-0.151 0.765l1.14 1.063c-0.016 0.124-0.027 0.255-0.036 0.385l-1.328 0.823c-0.292 0.172-0.292 0.599 0 0.771l1.328 0.823c0.009 0.131 0.020 0.261 0.036 0.385l-1.14 1.068c-0.251 0.229-0.167 0.641 0.151 0.76l1.459 0.548c0.036 0.124 0.072 0.249 0.115 0.375l-0.912 1.26c-0.197 0.276-0.036 0.667 0.301 0.719l1.537 0.251c0.057 0.115 0.12 0.229 0.183 0.344l-0.647 1.416c-0.14 0.312 0.095 0.661 0.432 0.645l1.557-0.052c0.084 0.1 0.161 0.199 0.251 0.297l-0.36 1.521c-0.077 0.328 0.219 0.624 0.548 0.547l1.52-0.355c0.099 0.084 0.199 0.161 0.303 0.245l-0.057 1.557c-0.016 0.343 0.339 0.577 0.645 0.432l1.417-0.645c0.115 0.061 0.228 0.124 0.343 0.187l0.256 1.537c0.052 0.333 0.437 0.489 0.713 0.296l1.265-0.911c0.125 0.041 0.251 0.077 0.375 0.113l0.548 1.459c0.115 0.323 0.525 0.401 0.76 0.152l1.063-1.141c0.129 0.016 0.255 0.032 0.385 0.041l0.823 1.328c0.177 0.287 0.599 0.287 0.776 0l0.823-1.328c0.131-0.009 0.256-0.025 0.385-0.041l1.063 1.141c0.235 0.244 0.641 0.167 0.76-0.152l0.548-1.459c0.124-0.036 0.249-0.072 0.375-0.113l1.26 0.911c0.276 0.203 0.667 0.037 0.719-0.296l0.251-1.537c0.12-0.063 0.235-0.125 0.349-0.187l1.416 0.645c0.307 0.14 0.656-0.093 0.645-0.432l-0.057-1.557c0.105-0.084 0.204-0.161 0.297-0.245l1.521 0.355c0.328 0.077 0.624-0.219 0.552-0.547l-0.36-1.521c0.084-0.099 0.167-0.197 0.245-0.297l1.563 0.052c0.339 0.016 0.572-0.333 0.432-0.645l-0.645-1.416c0.061-0.115 0.124-0.229 0.181-0.344l1.537-0.251c0.333-0.057 0.495-0.443 0.296-0.719l-0.905-1.26 0.113-0.375 1.453-0.548c0.324-0.119 0.401-0.531 0.157-0.76l-1.141-1.068c0.011-0.124 0.027-0.255 0.036-0.385l1.329-0.823c0.291-0.172 0.291-0.599 0-0.771zM22.703 26.615c-1.224-0.26-0.833-2.099 0.396-1.839 0.505 0.109 0.828 0.609 0.719 1.12-0.109 0.505-0.609 0.828-1.115 0.719zM22.255 23.568c-0.463-0.099-0.921 0.197-1.015 0.661l-0.475 2.192c-1.453 0.661-3.068 1.032-4.765 1.032-1.683 0-3.344-0.365-4.864-1.073l-0.475-2.197c-0.099-0.464-0.552-0.761-1.016-0.656l-1.937 0.411c-0.364-0.369-0.697-0.765-1.005-1.183h9.443c0.105 0 0.177-0.015 0.177-0.115v-3.337c0-0.1-0.072-0.115-0.177-0.115h-2.765v-2.12h2.989c0.271 0 1.459 0.077 1.833 1.593 0.12 0.464 0.381 1.979 0.557 2.464 0.177 0.547 0.901 1.629 1.672 1.629h4.704c0.057 0 0.115-0.005 0.171-0.015-0.323 0.443-0.681 0.864-1.067 1.255zM9.197 26.573c-0.509 0.104-1.009-0.219-1.119-0.724-0.109-0.511 0.213-1.011 0.724-1.115 0.504-0.109 1.004 0.213 1.115 0.719 0.109 0.511-0.215 1.011-0.72 1.12zM5.615 12.047c0.229 0.48 0.021 1.052-0.464 1.271-0.484 0.213-1.052-0.015-1.255-0.505-0.459-1.124 1.192-1.859 1.719-0.765zM4.516 14.656l2.020-0.896c0.433-0.192 0.625-0.697 0.433-1.129l-0.417-0.943h1.641v7.38h-3.303c-0.407-1.432-0.536-2.932-0.375-4.412zM13.385 13.943v-2.177h3.896c0.203 0 1.421 0.235 1.421 1.147 0 0.76-0.937 1.031-1.703 1.031zM27.552 15.901c0 0.287-0.011 0.572-0.031 0.853h-1.188c-0.12 0-0.167 0.079-0.167 0.199v0.541c0 1.281-0.719 1.557-1.355 1.631-0.604 0.068-1.271-0.251-1.353-0.62-0.355-2-0.948-2.427-1.885-3.167 1.161-0.74 2.369-1.823 2.369-3.281 0-1.573-1.079-2.563-1.812-3.047-1.032-0.683-2.172-0.817-2.48-0.817h-12.255c1.692-1.896 3.964-3.177 6.459-3.652l1.448 1.521c0.323 0.339 0.869 0.353 1.208 0.025l1.615-1.547c3.339 0.625 6.229 2.683 7.911 5.631l-1.109 2.5c-0.187 0.432 0.005 0.937 0.437 1.131l2.131 0.947c0.036 0.381 0.052 0.761 0.052 1.152zM15.303 3.255c0.905-0.864 2.203 0.495 1.296 1.36-0.901 0.781-2.115-0.495-1.296-1.36zM26.287 12.093c0.208-0.473 0.76-0.687 1.235-0.479 0.771 0.339 0.744 1.437-0.037 1.74-0.787 0.301-1.541-0.495-1.197-1.261z" />
</svg>
);
case "dart":
return (
<svg
className={props.className}
fill="currentColor"
viewBox="0 0 24 24"
>
<path d="M14.314 0L2.3 12 0 14.3 3.5 21.6 8.3 24 24 8.3 14.314 0zm0 3.328l6.417 6.417L8.88 21.594l-3.328-1.428L3.328 14.314l8.88-8.88 2.106-2.106z" />
</svg>
);
default:
props.lang satisfies never;
console.warn("unknown lang for LanguageIcon:", props.lang);
Expand Down
8 changes: 8 additions & 0 deletions app/terminal/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import sub_h from "./samples/sub.h?raw";
import sub_cpp from "./samples/sub.cpp?raw";
import main2_rs from "./samples/main2.rs?raw";
import sub_rs from "./samples/sub.rs?raw";
import main_dart from "./samples/main.dart?raw";
import { DaisyInfoIcon } from "@/daisyAlertIcon";

export default function RuntimeTestPage() {
Expand Down Expand Up @@ -127,6 +128,13 @@ const sampleConfig: Record<RuntimeLang, SampleConfig> = {
},
exec: ["main2.rs"],
},
dart: {
repl: false,
editor: {
"main.dart": main_dart,
},
exec: ["main.dart"],
},
};
function RuntimeSample({
lang,
Expand Down
3 changes: 3 additions & 0 deletions app/terminal/samples/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void main() {
print("Hello, Dart!");
}
8 changes: 7 additions & 1 deletion packages/runtime/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { ReactNode, useEffect } from "react";
import { RuntimeContext } from "./interface";
import { RuntimeLang } from "./languages";
import { DartProvider, useDart } from "./dart/runtime";
import { TypeScriptProvider, useTypeScript } from "./typescript/runtime";
import { useWandbox, WandboxProvider } from "./wandbox/runtime";
import { JSEvalContext, useJSEval } from "./worker/jsEval";
Expand Down Expand Up @@ -34,6 +35,7 @@ export function useRuntimeAll(): Record<RuntimeLang, RuntimeContext> {
const typescript = useTypeScript(jsEval);
const wandboxCpp = useWandbox("cpp");
const wandboxRust = useWandbox("rust");
const dart = useDart();

// initはしない。呼び出し側でする必要がある
return {
Expand All @@ -43,6 +45,7 @@ export function useRuntimeAll(): Record<RuntimeLang, RuntimeContext> {
typescript: typescript,
cpp: wandboxCpp,
rust: wandboxRust,
dart: dart,
};
}
export function RuntimeProvider({ children }: { children: ReactNode }) {
Expand All @@ -51,10 +54,13 @@ export function RuntimeProvider({ children }: { children: ReactNode }) {
<WorkerProvider context={RubyContext} lang="ruby">
<WorkerProvider context={JSEvalContext} lang="javascript">
<WandboxProvider>
<TypeScriptProvider>{children}</TypeScriptProvider>
<TypeScriptProvider>
<DartProvider>{children}</DartProvider>
</TypeScriptProvider>
</WandboxProvider>
</WorkerProvider>
</WorkerProvider>
</WorkerProvider>
);
}

130 changes: 130 additions & 0 deletions packages/runtime/src/dart/dart-runner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/requirejs@2/require.min.js"></script>
</head>
<body>
<script>
const $artifactsUrl = "https://stable.api.dartpad.dev/artifacts/";
const iframeSender = "dart_frame";

// 親からの実行指示(コンパイル済みJS)を受け取る
window.addEventListener("message", function (event) {
const msg = event.data;
if (msg.type !== "EXECUTE_DART") return;

const $javaScript = msg.code;

/*
以下のコードは
https://github.com/dart-lang/dart-pad/blob/main/pkgs/dartpad_ui/lib/app/execution/view_factory/frame.dart
からのコピー。一部改変
*/

// Redirect print messages to the host.
// function dartPrint(message) {
window.dartPrint = function (message) {
parent.postMessage(
{
// 'sender': 'frame',
sender: iframeSender,
type: "stdout",
message: message.toString(),
},
"*"
);
};

// The JavaScript exception handling for DartPad catches both errors
// directly raised by `main()` (in which case we might have useful Dart
// exception information we don't want to discard), as well as errors
// generated by other means, like assertion errors when starting up
// asynchronous functions.
window.onerror = function (message, url, line, column, error) {
// var errorMessage = error == null ? '' : ', error: ' + error;
var msg = message;
if (error) {
var errStr = String(error);
var errStack = error.stack || "";
msg = errStr + (errStack ? "\\n" + errStack : "");
}
parent.postMessage(
{
// 'sender': 'frame',
sender: iframeSender,
type: "jserr",
// 'message': message + errorMessage
message: msg,
},
"*"
);
};

// Set the crossorigin: anonymous attribute on require.js scripts.
// For example, dart_sdk.js or flutter_web.js.
require.config({
baseUrl: $artifactsUrl,
waitSeconds: 60,
onNodeCreated: function (node, config, id, url) {
node.setAttribute("crossorigin", "anonymous");
},
});

// Add a block to scope the __ddcInitCode variable to this blob in case
// multiple blobs are loaded into the frame (as can happen in embedded
// frames).
{
// The code depends on ddc_module_loader already being loaded in the page.
// Wrap in a function that we'll call after the module loader is loaded.
// let __ddcInitCode = function () { $javaScript; };
let __ddcInitCode = new Function($javaScript);

function contextLoaded() {
// try-catchはmy-code用に独自追加
try {
__ddcInitCode();
dartDevEmbedder.runMain(
"package:dartpad_sample/bootstrap.dart",
{}
);
} catch (err) {
var msg =
String(err) + (err && err.stack ? "\\n" + err.stack : "");
window.parent.postMessage(
{
sender: iframeSender,
type: "jserr",
message: msg,
},
"*"
);
} finally {
setTimeout(function () {
window.parent.postMessage(
{
sender: iframeSender,
type: "done",
},
"*"
);
}, 100);
}
}
// if (isFlutter) {
// function moduleLoaderLoaded() {
// require(["dart_sdk_new", "flutter_web_new"], contextLoaded);
// }
// } else {
function moduleLoaderLoaded() {
require(["dart_sdk_new"], contextLoaded);
}
// }
require(["ddc_module_loader"], moduleLoaderLoaded);

// Close scope block.
}
});
</script>
</body>
</html>
Loading
Loading