1
import "@gradio/theme/src/reset.css";
2
import "@gradio/theme/src/global.css";
3
import "@gradio/theme/src/pollen.css";
4
import "@gradio/theme/src/typography.css";
5
import { client, upload_files } from "@gradio/client";
6
import { mount_css } from "./css";
7
import type Index from "./Index.svelte";
9
import type { ThemeMode } from "./types";
12
import * as svelte from "./svelte/svelte.js";
14
declare let BUILD_MODE: string;
15
declare let GRADIO_VERSION: string;
17
const ENTRY_CSS = "__ENTRY_CSS__";
19
let FONTS: string | [];
21
FONTS = "__FONTS_CSS__";
23
let IndexComponent: typeof Index;
24
let _res: (value?: unknown) => void;
25
let pending = new Promise((res) => {
28
async function get_index(): Promise<void> {
29
IndexComponent = (await import("./Index.svelte")).default;
33
function create_custom_element(): void {
35
SvelteComponent: svelte.SvelteComponent
37
for (const key in svelte) {
38
if (key === "SvelteComponent") continue;
39
if (key === "SvelteComponentDev") {
41
o[key] = o["SvelteComponent"];
48
window.__gradio__svelte__internal = o;
49
class GradioApp extends HTMLElement {
50
control_page_title: string | null;
51
initial_height: string;
55
autoscroll: string | null;
57
theme_mode: ThemeMode | null;
63
updating: { name: string; value: string } | false;
67
this.host = this.getAttribute("host");
68
this.space = this.getAttribute("space");
69
this.src = this.getAttribute("src");
71
this.control_page_title = this.getAttribute("control_page_title");
72
this.initial_height = this.getAttribute("initial_height") ?? "300px"; // default: 300px
73
this.is_embed = this.getAttribute("embed") ?? "true"; // default: true
74
this.container = this.getAttribute("container") ?? "true"; // default: true
75
this.info = this.getAttribute("info") ?? true; // default: true
76
this.autoscroll = this.getAttribute("autoscroll");
77
this.eager = this.getAttribute("eager");
78
this.theme_mode = this.getAttribute("theme_mode") as ThemeMode | null;
79
this.updating = false;
83
async connectedCallback(): Promise<void> {
91
if (typeof FONTS !== "string") {
92
FONTS.forEach((f) => mount_css(f, document.head));
95
await mount_css(ENTRY_CSS, document.head);
97
const event = new CustomEvent("domchange", {
103
const observer = new MutationObserver((mutations) => {
104
this.dispatchEvent(event);
107
observer.observe(this, { childList: true });
109
this.app = new IndexComponent({
113
space: this.space ? this.space.trim() : this.space,
114
src: this.src ? this.src.trim() : this.src,
115
host: this.host ? this.host.trim() : this.host,
117
info: this.info === "false" ? false : true,
118
container: this.container === "false" ? false : true,
119
is_embed: this.is_embed === "false" ? false : true,
120
initial_height: this.initial_height,
121
eager: this.eager === "true" ? true : false,
123
version: GRADIO_VERSION,
124
theme_mode: this.theme_mode,
125
// misc global behaviour
126
autoscroll: this.autoscroll === "true" ? true : false,
127
control_page_title: this.control_page_title === "true" ? true : false,
132
// TODO: Remove -- i think this is just for autoscroll behavhiour, app vs embeds
133
app_mode: window.__gradio_mode__ === "app"
138
this.setAttribute(this.updating.name, this.updating.value);
141
this.loading = false;
144
static get observedAttributes(): ["src", "space", "host"] {
145
return ["src", "space", "host"];
148
async attributeChangedCallback(
155
(name === "host" || name === "space" || name === "src") &&
158
this.updating = { name, value: new_val };
159
if (this.loading) return;
169
if (name === "host") {
171
} else if (name === "space") {
172
this.space = new_val;
173
} else if (name === "src") {
177
this.app = new IndexComponent({
181
space: this.space ? this.space.trim() : this.space,
182
src: this.src ? this.src.trim() : this.src,
183
host: this.host ? this.host.trim() : this.host,
185
info: this.info === "false" ? false : true,
186
container: this.container === "false" ? false : true,
187
is_embed: this.is_embed === "false" ? false : true,
188
initial_height: this.initial_height,
189
eager: this.eager === "true" ? true : false,
191
version: GRADIO_VERSION,
192
theme_mode: this.theme_mode,
193
// misc global behaviour
194
autoscroll: this.autoscroll === "true" ? true : false,
196
this.control_page_title === "true" ? true : false,
201
// TODO: Remove -- i think this is just for autoscroll behavhiour, app vs embeds
202
app_mode: window.__gradio_mode__ === "app"
206
this.updating = false;
210
if (!customElements.get("gradio-app"))
211
customElements.define("gradio-app", GradioApp);
214
create_custom_element();