gradio-pr-bot commited on
Commit
0fbee3d
·
verified ·
1 Parent(s): 3f4714f

Upload folder using huggingface_hub

Browse files
6.7.1/html/Example.svelte ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ </script>
6
+
7
+ <div
8
+ class:table={type === "table"}
9
+ class:gallery={type === "gallery"}
10
+ class:selected
11
+ class="prose"
12
+ >
13
+ {@html value}
14
+ </div>
15
+
16
+ <style>
17
+ .gallery {
18
+ padding: var(--size-2);
19
+ }
20
+ </style>
6.7.1/html/Index.svelte ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseHTML } from "./shared/HTML.svelte";
3
+ export { default as BaseExample } from "./Example.svelte";
4
+ </script>
5
+
6
+ <script lang="ts">
7
+ import { Gradio } from "@gradio/utils";
8
+ import HTML from "./shared/HTML.svelte";
9
+ import { StatusTracker } from "@gradio/statustracker";
10
+ import { Block, BlockLabel, IconButtonWrapper } from "@gradio/atoms";
11
+ import { Code as CodeIcon } from "@gradio/icons";
12
+ import { css_units } from "@gradio/utils";
13
+ import type { HTMLProps, HTMLEvents } from "./types.ts";
14
+ import type { Snippet } from "svelte";
15
+
16
+ let props = $props();
17
+ let children: Snippet | undefined = props.children;
18
+ const gradio = new Gradio<HTMLEvents, HTMLProps>(props);
19
+
20
+ let _props = $derived({
21
+ value: gradio.props.value || "",
22
+ label: gradio.shared.label,
23
+ visible: gradio.shared.visible,
24
+ ...gradio.props.props
25
+ });
26
+
27
+ let old_value = $state(gradio.props.value);
28
+ $effect(() => {
29
+ if (JSON.stringify(old_value) !== JSON.stringify(gradio.props.value)) {
30
+ old_value = gradio.props.value;
31
+ gradio.dispatch("change");
32
+ }
33
+ });
34
+ </script>
35
+
36
+ <Block
37
+ visible={gradio.shared.visible}
38
+ elem_id={gradio.shared.elem_id}
39
+ elem_classes={gradio.shared.elem_classes}
40
+ container={gradio.shared.container}
41
+ padding={gradio.props.padding !== false}
42
+ overflow_behavior="visible"
43
+ >
44
+ {#if gradio.shared.show_label && gradio.props.buttons && gradio.props.buttons.length > 0}
45
+ <IconButtonWrapper
46
+ buttons={gradio.props.buttons}
47
+ on_custom_button_click={(id) => {
48
+ gradio.dispatch("custom_button_click", { id });
49
+ }}
50
+ />
51
+ {/if}
52
+ {#if gradio.shared.show_label}
53
+ <BlockLabel
54
+ Icon={CodeIcon}
55
+ show_label={gradio.shared.show_label}
56
+ label={gradio.shared.label}
57
+ float={true}
58
+ />
59
+ {/if}
60
+
61
+ <StatusTracker
62
+ autoscroll={gradio.shared.autoscroll}
63
+ i18n={gradio.i18n}
64
+ {...gradio.shared.loading_status}
65
+ variant="center"
66
+ on_clear_status={() => gradio.dispatch("clear_status", loading_status)}
67
+ />
68
+ <div
69
+ class="html-container"
70
+ class:pending={gradio.shared.loading_status?.status === "pending" &&
71
+ gradio.shared.loading_status?.show_progress !== "hidden"}
72
+ style:min-height={gradio.props.min_height &&
73
+ gradio.shared.loading_status?.status !== "pending"
74
+ ? css_units(gradio.props.min_height)
75
+ : undefined}
76
+ style:max-height={gradio.props.max_height
77
+ ? css_units(gradio.props.max_height)
78
+ : undefined}
79
+ style:overflow-y={gradio.props.max_height ? "auto" : undefined}
80
+ class:label-padding={gradio.shared.show_label ?? undefined}
81
+ >
82
+ <HTML
83
+ props={_props}
84
+ html_template={gradio.props.html_template}
85
+ css_template={gradio.props.css_template}
86
+ js_on_load={gradio.props.js_on_load}
87
+ elem_classes={gradio.shared.elem_classes}
88
+ visible={gradio.shared.visible}
89
+ autoscroll={gradio.shared.autoscroll}
90
+ apply_default_css={gradio.props.apply_default_css}
91
+ component_class_name={gradio.props.component_class_name}
92
+ server={gradio.shared.server}
93
+ on:event={(e) => {
94
+ gradio.dispatch(e.detail.type, e.detail.data);
95
+ }}
96
+ on:update_value={(e) => {
97
+ if (e.detail.property === "value") {
98
+ gradio.props.value = e.detail.data;
99
+ } else if (e.detail.property === "label") {
100
+ gradio.shared.label = e.detail.data;
101
+ } else if (e.detail.property === "visible") {
102
+ gradio.shared.visible = e.detail.data;
103
+ }
104
+ }}
105
+ >
106
+ {@render children?.()}
107
+ </HTML>
108
+ </div>
109
+ </Block>
110
+
111
+ <style>
112
+ .html-container {
113
+ padding: var(--block-padding);
114
+ }
115
+
116
+ .label-padding {
117
+ padding-top: var(--spacing-xxl);
118
+ }
119
+
120
+ div {
121
+ transition: 150ms;
122
+ }
123
+
124
+ .pending {
125
+ opacity: 0.2;
126
+ }
127
+ </style>
6.7.1/html/package.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/html",
3
+ "version": "0.10.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "dependencies": {
11
+ "@gradio/atoms": "workspace:^",
12
+ "@gradio/icons": "workspace:^",
13
+ "@gradio/statustracker": "workspace:^",
14
+ "@gradio/utils": "workspace:^",
15
+ "handlebars": "^4.7.8"
16
+ },
17
+ "devDependencies": {
18
+ "@gradio/preview": "workspace:^"
19
+ },
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "gradio": "./Index.svelte",
24
+ "svelte": "./dist/Index.svelte",
25
+ "types": "./dist/Index.svelte.d.ts"
26
+ },
27
+ "./example": {
28
+ "gradio": "./Example.svelte",
29
+ "svelte": "./dist/Example.svelte",
30
+ "types": "./dist/Example.svelte.d.ts"
31
+ },
32
+ "./base": {
33
+ "gradio": "./shared/HTML.svelte",
34
+ "svelte": "./dist/shared/HTML.svelte",
35
+ "types": "./dist/shared/HTML.svelte.d.ts"
36
+ }
37
+ },
38
+ "peerDependencies": {
39
+ "svelte": "^5.48.0"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/gradio-app/gradio.git",
44
+ "directory": "js/html"
45
+ }
46
+ }
6.7.1/html/shared/HTML.svelte ADDED
@@ -0,0 +1,511 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, tick } from "svelte";
3
+ import Handlebars from "handlebars";
4
+ import type { Snippet } from "svelte";
5
+
6
+ let {
7
+ elem_classes = [],
8
+ props = {},
9
+ html_template = "${value}",
10
+ css_template = "",
11
+ js_on_load = null,
12
+ head = null,
13
+ visible = true,
14
+ autoscroll = false,
15
+ apply_default_css = true,
16
+ component_class_name = "HTML",
17
+ server = {},
18
+ children
19
+ }: {
20
+ elem_classes: string[];
21
+ props: Record<string, any>;
22
+ html_template: string;
23
+ css_template: string;
24
+ js_on_load: string | null;
25
+ visible: boolean;
26
+ autoscroll: boolean;
27
+ apply_default_css: boolean;
28
+ component_class_name: string;
29
+ server: Record<string, (...args: any[]) => Promise<any>>;
30
+ children?: Snippet;
31
+ } = $props();
32
+
33
+ let [has_children, pre_html_template, post_html_template] = $derived.by(
34
+ () => {
35
+ if (html_template.includes("@children") && children) {
36
+ const parts = html_template.split("@children");
37
+ return [true, parts[0] || "", parts.slice(1).join("@children") || ""];
38
+ }
39
+ return [false, html_template, ""];
40
+ }
41
+ );
42
+
43
+ let old_props = $state(JSON.parse(JSON.stringify(props)));
44
+
45
+ const dispatch = createEventDispatcher<{
46
+ event: { type: "click" | "submit"; data: any };
47
+ update_value: { data: any; property: "value" | "label" | "visible" };
48
+ }>();
49
+
50
+ const trigger = (
51
+ event_type: "click" | "submit",
52
+ event_data: any = {}
53
+ ): void => {
54
+ dispatch("event", { type: event_type, data: event_data });
55
+ };
56
+
57
+ let element: HTMLDivElement;
58
+ let pre_element: HTMLDivElement;
59
+ let post_element: HTMLDivElement;
60
+ let scrollable_parent: HTMLElement | null = null;
61
+ let random_id = `html-${Math.random().toString(36).substring(2, 11)}`;
62
+ let style_element: HTMLStyleElement | null = null;
63
+ let reactiveProps: Record<string, any> = {};
64
+ let currentHtml = $state("");
65
+ let currentPreHtml = $state("");
66
+ let currentPostHtml = $state("");
67
+ let currentCss = $state("");
68
+ let renderScheduled = $state(false);
69
+ let mounted = $state(false);
70
+ let html_error_message: string | null = $state(null);
71
+ let css_error_message: string | null = $state(null);
72
+
73
+ function get_scrollable_parent(element: HTMLElement): HTMLElement | null {
74
+ let parent = element.parentElement;
75
+ while (parent) {
76
+ const style = window.getComputedStyle(parent);
77
+ if (
78
+ style.overflow === "auto" ||
79
+ style.overflow === "scroll" ||
80
+ style.overflowY === "auto" ||
81
+ style.overflowY === "scroll"
82
+ ) {
83
+ return parent;
84
+ }
85
+ parent = parent.parentElement;
86
+ }
87
+ return null;
88
+ }
89
+
90
+ function is_at_bottom(): boolean {
91
+ if (!element) return true;
92
+ if (!scrollable_parent) {
93
+ return (
94
+ window.innerHeight + window.scrollY >=
95
+ document.documentElement.scrollHeight - 100
96
+ );
97
+ }
98
+ return (
99
+ scrollable_parent.offsetHeight + scrollable_parent.scrollTop >=
100
+ scrollable_parent.scrollHeight - 100
101
+ );
102
+ }
103
+
104
+ function scroll_to_bottom(): void {
105
+ if (!element) return;
106
+ if (scrollable_parent) {
107
+ scrollable_parent.scrollTo(0, scrollable_parent.scrollHeight);
108
+ } else {
109
+ window.scrollTo(0, document.documentElement.scrollHeight);
110
+ }
111
+ }
112
+
113
+ async function scroll_on_html_update(): Promise<void> {
114
+ if (!autoscroll || !element) return;
115
+ if (!scrollable_parent) {
116
+ scrollable_parent = get_scrollable_parent(element);
117
+ }
118
+ if (is_at_bottom()) {
119
+ await new Promise((resolve) => setTimeout(resolve, 300));
120
+ scroll_to_bottom();
121
+ }
122
+ }
123
+
124
+ function render_template(
125
+ template: string,
126
+ props: Record<string, any>,
127
+ language: "html" | "css" = "html"
128
+ ): string {
129
+ try {
130
+ const handlebarsTemplate = Handlebars.compile(template);
131
+ const handlebarsRendered = handlebarsTemplate(props);
132
+
133
+ const propKeys = Object.keys(props);
134
+ const propValues = Object.values(props);
135
+ const templateFunc = new Function(
136
+ ...propKeys,
137
+ `return \`${handlebarsRendered}\`;`
138
+ );
139
+ if (language === "html") {
140
+ html_error_message = null;
141
+ } else if (language === "css") {
142
+ css_error_message = null;
143
+ }
144
+ return templateFunc(...propValues);
145
+ } catch (e) {
146
+ console.error("Error evaluating template:", e);
147
+ if (language === "html") {
148
+ html_error_message = e instanceof Error ? e.message : String(e);
149
+ } else if (language === "css") {
150
+ css_error_message = e instanceof Error ? e.message : String(e);
151
+ }
152
+ return "";
153
+ }
154
+ }
155
+
156
+ function update_css(): void {
157
+ if (typeof document === "undefined") return;
158
+ if (!style_element) {
159
+ style_element = document.createElement("style");
160
+ document.head.appendChild(style_element);
161
+ }
162
+ currentCss = render_template(css_template, reactiveProps, "css");
163
+ if (currentCss) {
164
+ style_element.textContent = `#${random_id} { ${currentCss} }`;
165
+ } else {
166
+ style_element.textContent = "";
167
+ }
168
+ }
169
+
170
+ function updateDOM(
171
+ _element: HTMLElement | undefined,
172
+ oldHtml: string,
173
+ newHtml: string
174
+ ): void {
175
+ if (!_element || oldHtml === newHtml) return;
176
+
177
+ const tempContainer = document.createElement("div");
178
+ tempContainer.innerHTML = newHtml;
179
+
180
+ const oldNodes = Array.from(_element.childNodes);
181
+ const newNodes = Array.from(tempContainer.childNodes);
182
+
183
+ const maxLength = Math.max(oldNodes.length, newNodes.length);
184
+
185
+ for (let i = 0; i < maxLength; i++) {
186
+ const oldNode = oldNodes[i];
187
+ const newNode = newNodes[i];
188
+
189
+ if (!oldNode && newNode) {
190
+ _element.appendChild(newNode.cloneNode(true));
191
+ } else if (oldNode && !newNode) {
192
+ _element.removeChild(oldNode);
193
+ } else if (oldNode && newNode) {
194
+ updateNode(oldNode, newNode);
195
+ }
196
+ }
197
+ }
198
+
199
+ // eslint-disable-next-line complexity
200
+ function updateNode(oldNode: Node, newNode: Node): void {
201
+ if (
202
+ oldNode.nodeType === Node.TEXT_NODE &&
203
+ newNode.nodeType === Node.TEXT_NODE
204
+ ) {
205
+ if (oldNode.textContent !== newNode.textContent) {
206
+ oldNode.textContent = newNode.textContent;
207
+ }
208
+ return;
209
+ }
210
+
211
+ if (
212
+ oldNode.nodeType === Node.ELEMENT_NODE &&
213
+ newNode.nodeType === Node.ELEMENT_NODE
214
+ ) {
215
+ const oldElement = oldNode as Element;
216
+ const newElement = newNode as Element;
217
+
218
+ if (oldElement.tagName !== newElement.tagName) {
219
+ oldNode.parentNode?.replaceChild(newNode.cloneNode(true), oldNode);
220
+ return;
221
+ }
222
+
223
+ const oldAttrs = Array.from(oldElement.attributes);
224
+ const newAttrs = Array.from(newElement.attributes);
225
+
226
+ for (const attr of oldAttrs) {
227
+ if (!newElement.hasAttribute(attr.name)) {
228
+ oldElement.removeAttribute(attr.name);
229
+ }
230
+ }
231
+
232
+ for (const attr of newAttrs) {
233
+ if (oldElement.getAttribute(attr.name) !== attr.value) {
234
+ oldElement.setAttribute(attr.name, attr.value);
235
+
236
+ if (
237
+ attr.name === "value" &&
238
+ (oldElement.tagName === "INPUT" ||
239
+ oldElement.tagName === "TEXTAREA" ||
240
+ oldElement.tagName === "SELECT")
241
+ ) {
242
+ (
243
+ oldElement as
244
+ | HTMLInputElement
245
+ | HTMLTextAreaElement
246
+ | HTMLSelectElement
247
+ ).value = attr.value;
248
+ }
249
+ }
250
+ }
251
+
252
+ const oldChildren = Array.from(oldElement.childNodes);
253
+ const newChildren = Array.from(newElement.childNodes);
254
+ const maxChildren = Math.max(oldChildren.length, newChildren.length);
255
+
256
+ for (let i = 0; i < maxChildren; i++) {
257
+ const oldChild = oldChildren[i];
258
+ const newChild = newChildren[i];
259
+
260
+ if (!oldChild && newChild) {
261
+ oldElement.appendChild(newChild.cloneNode(true));
262
+ } else if (oldChild && !newChild) {
263
+ oldElement.removeChild(oldChild);
264
+ } else if (oldChild && newChild) {
265
+ updateNode(oldChild, newChild);
266
+ }
267
+ }
268
+ } else {
269
+ oldNode.parentNode?.replaceChild(newNode.cloneNode(true), oldNode);
270
+ }
271
+ }
272
+
273
+ function renderHTML(): void {
274
+ if (has_children) {
275
+ const newPreHtml = render_template(
276
+ pre_html_template,
277
+ reactiveProps,
278
+ "html"
279
+ );
280
+ updateDOM(pre_element, currentPreHtml, newPreHtml);
281
+ currentPreHtml = newPreHtml;
282
+ const newPostHtml = render_template(
283
+ post_html_template,
284
+ reactiveProps,
285
+ "html"
286
+ );
287
+ updateDOM(post_element, currentPostHtml, newPostHtml);
288
+ currentPostHtml = newPostHtml;
289
+ } else {
290
+ const newHtml = render_template(html_template, reactiveProps, "html");
291
+ updateDOM(element, currentHtml, newHtml);
292
+ currentHtml = newHtml;
293
+ }
294
+ if (autoscroll) {
295
+ scroll_on_html_update();
296
+ }
297
+ }
298
+
299
+ function scheduleRender(): void {
300
+ if (!renderScheduled) {
301
+ renderScheduled = true;
302
+ queueMicrotask(() => {
303
+ renderScheduled = false;
304
+ renderHTML();
305
+ update_css();
306
+ });
307
+ }
308
+ }
309
+
310
+ async function loadHead(headHtml: string): Promise<void> {
311
+ if (!headHtml) return;
312
+ const parser = new DOMParser();
313
+ const doc = parser.parseFromString(`<head>${headHtml}</head>`, "text/html");
314
+ const promises: Promise<void>[] = [];
315
+ for (const el of Array.from(doc.head.children)) {
316
+ if (el.tagName === "SCRIPT") {
317
+ const src = (el as HTMLScriptElement).src;
318
+ if (src) {
319
+ if (document.querySelector(`script[src="${src}"]`)) continue;
320
+ const script = document.createElement("script");
321
+ script.src = src;
322
+ promises.push(
323
+ new Promise<void>((resolve, reject) => {
324
+ script.onload = () => resolve();
325
+ script.onerror = () =>
326
+ reject(new Error(`Failed to load script: ${src}`));
327
+ })
328
+ );
329
+ document.head.appendChild(script);
330
+ } else {
331
+ const script = document.createElement("script");
332
+ script.textContent = el.textContent;
333
+ document.head.appendChild(script);
334
+ }
335
+ } else {
336
+ const existing =
337
+ el.tagName === "LINK" && (el as HTMLLinkElement).href
338
+ ? document.querySelector(
339
+ `link[href="${(el as HTMLLinkElement).href}"]`
340
+ )
341
+ : null;
342
+ if (!existing) {
343
+ document.head.appendChild(el.cloneNode(true));
344
+ }
345
+ }
346
+ }
347
+ await Promise.all(promises);
348
+ }
349
+
350
+ // Mount effect
351
+ $effect(() => {
352
+ if (!element || mounted) return;
353
+ mounted = true;
354
+
355
+ reactiveProps = new Proxy(
356
+ { ...props },
357
+ {
358
+ set(target, property, value) {
359
+ const oldValue = target[property as string];
360
+ target[property as string] = value;
361
+
362
+ if (oldValue !== value) {
363
+ scheduleRender();
364
+
365
+ if (
366
+ property === "value" ||
367
+ property === "label" ||
368
+ property === "visible"
369
+ ) {
370
+ props[property] = value;
371
+ old_props[property] = value;
372
+ dispatch("update_value", { data: value, property });
373
+ }
374
+ }
375
+ return true;
376
+ }
377
+ }
378
+ );
379
+
380
+ if (has_children) {
381
+ currentPreHtml = render_template(
382
+ pre_html_template,
383
+ reactiveProps,
384
+ "html"
385
+ );
386
+ pre_element.innerHTML = currentPreHtml;
387
+ currentPostHtml = render_template(
388
+ post_html_template,
389
+ reactiveProps,
390
+ "html"
391
+ );
392
+ post_element.innerHTML = currentPostHtml;
393
+ } else {
394
+ currentHtml = render_template(html_template, reactiveProps, "html");
395
+ element.innerHTML = currentHtml;
396
+ }
397
+ update_css();
398
+
399
+ if (autoscroll) {
400
+ scroll_to_bottom();
401
+ }
402
+ scroll_on_html_update();
403
+
404
+ (async () => {
405
+ if (head) {
406
+ await loadHead(head);
407
+ }
408
+ if (js_on_load && element) {
409
+ try {
410
+ const func = new Function(
411
+ "element",
412
+ "trigger",
413
+ "props",
414
+ "server",
415
+ js_on_load
416
+ );
417
+ func(element, trigger, reactiveProps, server);
418
+ } catch (error) {
419
+ console.error("Error executing js_on_load:", error);
420
+ }
421
+ }
422
+ })();
423
+ });
424
+
425
+ // Props update effect
426
+ $effect(() => {
427
+ if (
428
+ reactiveProps &&
429
+ props &&
430
+ JSON.stringify(old_props) !== JSON.stringify(props)
431
+ ) {
432
+ for (const key in props) {
433
+ if (reactiveProps[key] !== props[key]) {
434
+ reactiveProps[key] = props[key];
435
+ }
436
+ }
437
+ old_props = props;
438
+ }
439
+ });
440
+ </script>
441
+
442
+ {#if html_error_message || css_error_message}
443
+ <div class="error-container">
444
+ <strong class="error-title"
445
+ >Error rendering <code class="error-component-name"
446
+ >{component_class_name}</code
447
+ >:</strong
448
+ >
449
+ <code class="error-message">{html_error_message || css_error_message}</code>
450
+ </div>
451
+ {:else}
452
+ <div
453
+ bind:this={element}
454
+ id={random_id}
455
+ class="{apply_default_css && !has_children
456
+ ? 'prose gradio-style'
457
+ : ''} {elem_classes.join(' ')}"
458
+ class:hide={!visible}
459
+ class:has_children
460
+ >
461
+ {#if has_children}
462
+ <div
463
+ class={apply_default_css ? "prose gradio-style" : ""}
464
+ bind:this={pre_element}
465
+ ></div>
466
+ {@render children?.()}
467
+ <div
468
+ class={apply_default_css ? "prose gradio-style" : ""}
469
+ bind:this={post_element}
470
+ ></div>
471
+ {/if}
472
+ </div>
473
+ {/if}
474
+
475
+ <style>
476
+ .hide {
477
+ display: none;
478
+ }
479
+
480
+ .has_children {
481
+ display: flex;
482
+ flex-direction: column;
483
+ gap: var(--layout-gap);
484
+ }
485
+
486
+ .error-container {
487
+ padding: 12px;
488
+ background-color: #fee;
489
+ border: 1px solid #fcc;
490
+ border-radius: 4px;
491
+ color: #c33;
492
+ font-family: monospace;
493
+ font-size: 13px;
494
+ }
495
+
496
+ .error-title {
497
+ display: block;
498
+ margin-bottom: 8px;
499
+ }
500
+
501
+ .error-component-name {
502
+ background-color: #fdd;
503
+ padding: 2px 4px;
504
+ border-radius: 2px;
505
+ }
506
+
507
+ .error-message {
508
+ white-space: pre-wrap;
509
+ word-break: break-word;
510
+ }
511
+ </style>
6.7.1/html/types.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { CustomButton } from "@gradio/utils";
2
+
3
+ export interface HTMLProps {
4
+ value: string;
5
+ html_template: string;
6
+ css_template: string;
7
+ js_on_load: string | null;
8
+ apply_default_css: boolean;
9
+ show_label: boolean;
10
+ min_height: number | undefined;
11
+ max_height: number | undefined;
12
+ props: Record<string, any>;
13
+ component_class_name: string;
14
+ buttons: (string | CustomButton)[] | null;
15
+ padding: boolean;
16
+ }
17
+
18
+ export interface HTMLEvents {
19
+ change: never;
20
+ click: never;
21
+ submit: never;
22
+ custom_button_click: { id: number };
23
+ }