-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49b49cc
commit 8334726
Showing
8 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Scratch } from "@framework/internal"; | ||
import { Collaborator, Extension, Translator, Version, BlockType } from "@framework/structs"; | ||
import { GlobalContext, Unnecessary } from "@framework/tools"; | ||
import "./style.css"; | ||
const translator = Translator.create("zh-cn", { | ||
name: "内嵌Python", | ||
description: "使用pyscript嵌入Python", | ||
run: "设置[console:string]中的代码[code:string=print('hello world')]", | ||
create: "创建控制台[name:string]", | ||
startRendering: "开始渲染[console:string]" | ||
}); | ||
export default class FSIFrame extends Extension { | ||
id = "pyinner"; | ||
displayName = translator.load("name"); | ||
version = new Version(1, 0, 0); | ||
description = translator.load("description"); | ||
collaborators = [ | ||
new Collaborator("FallingShrimp", "https://rundll86.github.io") | ||
]; | ||
init(runtime: Scratch) { | ||
runtime.renderer.canvas.parentElement?.appendChild( | ||
dataStore.read("rootBase").result | ||
); | ||
document.head.appendChild( | ||
Unnecessary.elementTree("script") | ||
.attribute("src", "https://pyscript.net/releases/2024.11.1/core.js") | ||
.attribute("type", "module") | ||
.result | ||
); | ||
}; | ||
@BlockType.Command(translator.load("create")) | ||
create(arg: Record<string, any>) { | ||
dataStore.read("consoles")[arg.name] = Unnecessary.elementTree("mpy-script" as any); | ||
}; | ||
@BlockType.Command(translator.load("run")) | ||
run(arg: Record<string, any>) { | ||
dataStore.read("consoles")[arg.console].attribute("innerHTML", arg.code); | ||
}; | ||
@BlockType.Command(translator.load("startRendering")) | ||
startRendering(arg: Record<string, any>) { | ||
dataStore.read("rootBase").child(dataStore.read("consoles")[arg.console]); | ||
}; | ||
}; | ||
const dataStore = GlobalContext.createDataStore(FSIFrame, { | ||
consoles: {} as Record<string, any>, | ||
rootBase: Unnecessary.elementTree("div").class("fsi-base") | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.fsi-base { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
} | ||
|
||
.fsi-iframe { | ||
position: absolute; | ||
border:none; | ||
outline:none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { BlockType, Extension, Translator } from "@framework/structs"; | ||
import { GlobalContext } from "@framework/tools"; | ||
const translator = Translator.create("zh-cn", { | ||
name: "Run JS", | ||
description: "运行JS代码", | ||
run: "运行[js:string]", | ||
runAndGetResult: "运行[js:string]并返回结果", | ||
getStack: "上次JS运行异常的错误栈信息" | ||
}); | ||
export default class FallingAnchors extends Extension { | ||
id: string = "runjs"; | ||
displayName: string = translator.load("name"); | ||
description: string = translator.load("description"); | ||
allowSandboxed: boolean = false; | ||
@BlockType.Command(translator.load("run")) | ||
runJs(arg: Record<string, any>) { | ||
try { | ||
eval(arg.js); | ||
} catch (e: any) { | ||
dataStore.write("stack", e.stack); | ||
} | ||
} | ||
@BlockType.Reporter(translator.load("runAndGetResult")) | ||
runAndGetResult(arg: Record<string, any>) { | ||
try { | ||
return eval(arg.js); | ||
} catch (e: any) { | ||
dataStore.write("stack", e.stack); | ||
return undefined; | ||
} | ||
} | ||
@BlockType.Reporter(translator.load("getStack")) | ||
getStack(arg: Record<string, any>) { | ||
return dataStore.read("stack"); | ||
} | ||
}; | ||
const dataStore = GlobalContext.createDataStore(FallingAnchors, { | ||
stack: "" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters