|
import { type WorkerProxyOptions } from "@gradio/wasm"; |
|
import type { ThemeMode } from "@gradio/core"; |
|
import { bootstrap_custom_element } from "./custom-element"; |
|
|
|
declare let GRADIO_VERSION: string; |
|
|
|
import LiteIndex from "./LiteIndex.svelte"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface GradioAppController { |
|
run_code: (code: string) => Promise<void>; |
|
run_file: (path: string) => Promise<void>; |
|
write: ( |
|
path: string, |
|
data: string | ArrayBufferView, |
|
opts: any |
|
) => Promise<void>; |
|
rename: (old_path: string, new_path: string) => Promise<void>; |
|
unlink: (path: string) => Promise<void>; |
|
install: (requirements: string[]) => Promise<void>; |
|
unmount: () => void; |
|
} |
|
|
|
export interface Options { |
|
target: HTMLElement; |
|
files?: WorkerProxyOptions["files"]; |
|
requirements?: WorkerProxyOptions["requirements"]; |
|
code?: string; |
|
entrypoint?: string; |
|
sharedWorkerMode?: boolean; |
|
info: boolean; |
|
container: boolean; |
|
isEmbed: boolean; |
|
initialHeight?: string; |
|
eager: boolean; |
|
themeMode: ThemeMode | null; |
|
autoScroll: boolean; |
|
controlPageTitle: boolean; |
|
appMode: boolean; |
|
playground: boolean | undefined; |
|
layout: string | null; |
|
} |
|
export function create(options: Options): GradioAppController { |
|
|
|
|
|
const observer = new MutationObserver(() => { |
|
document.body.style.padding = "0"; |
|
}); |
|
|
|
observer.observe(options.target, { childList: true }); |
|
|
|
const app = new LiteIndex({ |
|
target: options.target, |
|
props: { |
|
info: options.info, |
|
container: options.container, |
|
is_embed: options.isEmbed, |
|
initial_height: options.initialHeight ?? "300px", |
|
eager: options.eager, |
|
version: GRADIO_VERSION, |
|
theme_mode: options.themeMode, |
|
autoscroll: options.autoScroll, |
|
control_page_title: options.controlPageTitle, |
|
app_mode: options.appMode, |
|
|
|
files: options.files, |
|
requirements: options.requirements, |
|
code: options.code, |
|
entrypoint: options.entrypoint, |
|
sharedWorkerMode: options.sharedWorkerMode, |
|
|
|
playground: options.playground, |
|
layout: options.layout |
|
} |
|
}); |
|
|
|
return { |
|
run_code: app.run_code, |
|
run_file: app.run_file, |
|
write: app.write, |
|
rename: app.rename, |
|
unlink: app.unlink, |
|
install: app.install, |
|
unmount() { |
|
app.$destroy(); |
|
} |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
globalThis.createGradioApp = create; |
|
|
|
bootstrap_custom_element(create); |
|
|
|
declare let BUILD_MODE: string; |
|
if (BUILD_MODE === "dev") { |
|
(async function () { |
|
const DevApp = (await import("./dev/App.svelte")).default; |
|
|
|
const app = new DevApp({ |
|
target: document.getElementById("dev-app")! |
|
}); |
|
})(); |
|
} |
|
|