diff --git a/6.11.0/atoms/package.json b/6.11.0/atoms/package.json index 95f9bd4d625299d552ff81404f195b0343bf80a0..98eca40ae7b915c439d1fd87227eb59d3a3c0aa6 100644 --- a/6.11.0/atoms/package.json +++ b/6.11.0/atoms/package.json @@ -8,6 +8,7 @@ "license": "ISC", "dependencies": { "@gradio/icons": "workspace:^", + "@gradio/markdown-code": "workspace:^", "@gradio/utils": "workspace:^" }, "peerDependencies": { diff --git a/6.11.0/atoms/src/BlockTitle.svelte b/6.11.0/atoms/src/BlockTitle.svelte index c14be5cd912f30aa50e5733432e1abbf37f4354b..2db9434c29ae802bcb67cdb2fd5ce4c4b378828d 100644 --- a/6.11.0/atoms/src/BlockTitle.svelte +++ b/6.11.0/atoms/src/BlockTitle.svelte @@ -1,6 +1,5 @@ -
- {@html render_inline_markdown(info)} +
+
diff --git a/6.11.0/atoms/src/inline-markdown.ts b/6.11.0/atoms/src/inline-markdown.ts deleted file mode 100644 index 5eb55f4448ff41876211359dc2f94f5e61431173..0000000000000000000000000000000000000000 --- a/6.11.0/atoms/src/inline-markdown.ts +++ /dev/null @@ -1,40 +0,0 @@ -export const INLINE_CODE_RE = /`([^`]+)`/g; -export const LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g; -export const BOLD_ASTERISK_RE = /\*\*(.+?)\*\*/g; -export const BOLD_UNDERSCORE_RE = /__(.+?)__/g; -export const ITALIC_ASTERISK_RE = /\*(.+?)\*/g; -export const ITALIC_UNDERSCORE_RE = /(?/g, ">") - .replace(/"/g, """); -} - -function render_link(_match: string, text: string, url: string): string { - const trimmed = url.trim(); - if (PROTOCOL_RE.test(trimmed)) { - if (/^https?:/i.test(trimmed)) { - return `${text}`; - } - return text; - } - return `${text}`; -} - -export function render_inline_markdown(text: string): string { - let result = escape_html(text); - - result = result.replace(INLINE_CODE_RE, "$1"); - result = result.replace(LINK_RE, render_link); - result = result.replace(BOLD_ASTERISK_RE, "$1"); - result = result.replace(BOLD_UNDERSCORE_RE, "$1"); - result = result.replace(ITALIC_ASTERISK_RE, "$1"); - result = result.replace(ITALIC_UNDERSCORE_RE, "$1"); - result = result.replace(/\n/g, "
"); - - return result; -} diff --git a/6.11.0/gallery/shared/Gallery.svelte b/6.11.0/gallery/shared/Gallery.svelte index 174ee0f5766ddcae258cfcc9bec5d86f9518040a..2c078be1f39cd15dedee8365e16c65f7bf0248a2 100644 --- a/6.11.0/gallery/shared/Gallery.svelte +++ b/6.11.0/gallery/shared/Gallery.svelte @@ -229,13 +229,15 @@ } $effect(() => { - // Only trigger the effect if the selected_index has actually changed if (selected_index !== old_selected_index) { old_selected_index = selected_index; - - // Ensure we have a valid selection and data to work with - if (selected_index !== null && resolved_value !== null) { - // Notify the parent component or listener about the updated selection + if (selected_index !== null) { + if (resolved_value != null) { + selected_index = Math.max( + 0, + Math.min(selected_index, resolved_value.length - 1) + ); + } onselect({ index: selected_index, value: resolved_value?.[selected_index] diff --git a/6.11.0/preview/package.json b/6.11.0/preview/package.json index 2a7176875f2633bedfea6a809f120587fa22c344..38a3abd8ce4137386a611cec3fba8a01bb8673a7 100644 --- a/6.11.0/preview/package.json +++ b/6.11.0/preview/package.json @@ -1,6 +1,6 @@ { "name": "@gradio/preview", - "version": "0.16.2", + "version": "0.16.1", "description": "Gradio UI packages", "type": "module", "main": "dist/index.js", diff --git a/6.11.0/preview/src/build.ts b/6.11.0/preview/src/build.ts index a63d5e9f5efc3e932bbc3c71e2474a937bb57e89..1f4e5a7a16ff06eae8ad4f33267055b0879c5a0f 100644 --- a/6.11.0/preview/src/build.ts +++ b/6.11.0/preview/src/build.ts @@ -74,18 +74,14 @@ export async function make_build({ join(source_dir, pkg.exports["."].gradio) ] ], - ...(pkg.exports["./example"] - ? [ - [ - join(template_dir, "example"), - [ - join(__dirname, "svelte_runtime_entry.js"), - join(source_dir, pkg.exports["./example"].gradio) - ] - ] - ] - : []) - ]; + [ + join(template_dir, "example"), + [ + join(__dirname, "svelte_runtime_entry.js"), + join(source_dir, pkg.exports["./example"].gradio) + ] + ] + ].filter(([_, path]) => !!path); for (const [out_path, entry_path] of exports) { try { diff --git a/6.11.1/accordion/Index.svelte b/6.11.1/accordion/Index.svelte deleted file mode 100644 index 060b2c6e34c4199c5f9f1c05bdaedc51686203d2..0000000000000000000000000000000000000000 --- a/6.11.1/accordion/Index.svelte +++ /dev/null @@ -1,62 +0,0 @@ - - - - {#if gradio.shared.loading_status} - - {/if} - - { - gradio.dispatch("expand"); - gradio.dispatch("gradio_expand"); - }} - oncollapse={() => gradio.dispatch("collapse")} - > - - - - - diff --git a/6.11.1/accordion/package.json b/6.11.1/accordion/package.json deleted file mode 100644 index 4e8fb8b37e67c980624ec9a07ebecd55df4ab719..0000000000000000000000000000000000000000 --- a/6.11.1/accordion/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "@gradio/accordion", - "version": "0.5.34", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "main_changeset": true, - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/column": "workspace:^", - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/accordion" - } -} diff --git a/6.11.1/accordion/shared/Accordion.svelte b/6.11.1/accordion/shared/Accordion.svelte deleted file mode 100644 index b5f03ed0ac3ccf5a5fe8539fcb171337470e8790..0000000000000000000000000000000000000000 --- a/6.11.1/accordion/shared/Accordion.svelte +++ /dev/null @@ -1,55 +0,0 @@ - - - -
- -
- - diff --git a/6.11.1/accordion/types.ts b/6.11.1/accordion/types.ts deleted file mode 100644 index 55ce738d6a94da862f24fc2e5ce4f0a55a0d1c5b..0000000000000000000000000000000000000000 --- a/6.11.1/accordion/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface AccordionProps { - open: boolean; -} - -export interface AccordionEvents { - expand: never; - collapse: never; - gradio_expand: never; -} diff --git a/6.11.1/annotatedimage/Index.svelte b/6.11.1/annotatedimage/Index.svelte deleted file mode 100644 index 24d07cff4ff3949172d865d85bb4566b71f59bac..0000000000000000000000000000000000000000 --- a/6.11.1/annotatedimage/Index.svelte +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - -
- {#if gradio.props.value == null} - - {:else} -
- { - gradio.dispatch("custom_button_click", { id }); - }} - > - {#if (gradio.props.buttons || []).some((btn) => typeof btn === "string" && btn === "fullscreen")} - { - fullscreen = detail; - }} - /> - {/if} - - - the base file that is annotated - {#each gradio.props.value ? gradio.props.value.annotations : [] as ann, i} - segmentation mask identifying {gradio.shared
-							.label} within the uploaded file - {/each} -
- {#if gradio.props.show_legend && gradio.props.value} -
- {#each gradio.props.value.annotations as ann, i} - - {/each} -
- {/if} - {/if} -
-
- - diff --git a/6.11.1/annotatedimage/package.json b/6.11.1/annotatedimage/package.json deleted file mode 100644 index 52b41fd47c2104ece9017ac4b477693c4a49f0ba..0000000000000000000000000000000000000000 --- a/6.11.1/annotatedimage/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "@gradio/annotatedimage", - "version": "0.11.7", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/statustracker": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^", - "@gradio/client": "workspace:^" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/annotatedimage" - } -} diff --git a/6.11.1/annotatedimage/types.ts b/6.11.1/annotatedimage/types.ts deleted file mode 100644 index a67663c44b2a3e32e1db9e2e44560696c0e54df1..0000000000000000000000000000000000000000 --- a/6.11.1/annotatedimage/types.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { FileData } from "@gradio/client"; -import type { CustomButton } from "@gradio/utils"; - -export interface Annotation { - image: FileData; - label: string; -} - -export interface AnnotatedImageValue { - image: FileData; - annotations: Annotation[]; -} - -export interface AnnotatedImageProps { - value: AnnotatedImageValue | null; - show_legend: boolean; - height: number | undefined; - width: number | undefined; - color_map: Record; - buttons: (string | CustomButton)[]; -} - -export interface AnnotatedImageEvents { - change: never; - select: { index: number; value: string }; - custom_button_click: { id: number }; -} diff --git a/6.11.1/atoms/package.json b/6.11.1/atoms/package.json deleted file mode 100644 index 5422ff37cce83ddce0fbbcec76562da28f04bb47..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@gradio/atoms", - "version": "0.23.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/icons": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/atoms" - }, - "scripts": { - "sv-package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.11.1/atoms/src/Block.svelte b/6.11.1/atoms/src/Block.svelte deleted file mode 100644 index a9017a5136a582bde732d7a49081a6d5ccfd6322..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/Block.svelte +++ /dev/null @@ -1,256 +0,0 @@ - - -{#if visible === true || visible === "hidden"} - - - {#if resizable} - - - - - - {/if} - - {#if fullscreen} -
- {/if} -{/if} - - diff --git a/6.11.1/atoms/src/BlockLabel.svelte b/6.11.1/atoms/src/BlockLabel.svelte deleted file mode 100644 index e60ce34c2eb756ae99c414711c9be2156a58a296..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/BlockLabel.svelte +++ /dev/null @@ -1,90 +0,0 @@ - - - - - diff --git a/6.11.1/atoms/src/BlockTitle.svelte b/6.11.1/atoms/src/BlockTitle.svelte deleted file mode 100644 index c14be5cd912f30aa50e5733432e1abbf37f4354b..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/BlockTitle.svelte +++ /dev/null @@ -1,64 +0,0 @@ - - - - - -{#if info} - -{/if} - - diff --git a/6.11.1/atoms/src/CustomButton.svelte b/6.11.1/atoms/src/CustomButton.svelte deleted file mode 100644 index 9273358a1218ff5003a6a21f59092fb619d22015..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/CustomButton.svelte +++ /dev/null @@ -1,45 +0,0 @@ - - - - - diff --git a/6.11.1/atoms/src/DownloadLink.svelte b/6.11.1/atoms/src/DownloadLink.svelte deleted file mode 100644 index 52a856eb3b21faffc74b9d541e681264126e1842..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/DownloadLink.svelte +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - diff --git a/6.11.1/atoms/src/Empty.svelte b/6.11.1/atoms/src/Empty.svelte deleted file mode 100644 index 6bc3ab39a045d27498d50ec9c9804c4011af93f6..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/Empty.svelte +++ /dev/null @@ -1,63 +0,0 @@ - - -
-
- -
-
- - diff --git a/6.11.1/atoms/src/FullscreenButton.svelte b/6.11.1/atoms/src/FullscreenButton.svelte deleted file mode 100644 index 2689805a0724c8bc3ed1eb2059658f077de94381..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/FullscreenButton.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - -{#if fullscreen} - onclick(false)} - /> -{:else} - onclick(true)} - /> -{/if} diff --git a/6.11.1/atoms/src/IconButton.svelte b/6.11.1/atoms/src/IconButton.svelte deleted file mode 100644 index f69741583af000edb4cc94ca3d72fff7437b4603..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/IconButton.svelte +++ /dev/null @@ -1,161 +0,0 @@ - - - - - diff --git a/6.11.1/atoms/src/IconButtonWrapper.svelte b/6.11.1/atoms/src/IconButtonWrapper.svelte deleted file mode 100644 index 22678f406c9999ecd8c3a9e3c833e2fbad1e14f6..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/IconButtonWrapper.svelte +++ /dev/null @@ -1,116 +0,0 @@ - - -
- {#if children}{@render children()}{/if} - {#if buttons} - {#each buttons as btn} - {#if typeof btn !== "string"} - { - if (on_custom_button_click) { - on_custom_button_click(id); - } - }} - /> - {/if} - {/each} - {/if} -
- - diff --git a/6.11.1/atoms/src/Info.svelte b/6.11.1/atoms/src/Info.svelte deleted file mode 100644 index d657b5c5d327653f33fe7284dc3784072717e60e..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/Info.svelte +++ /dev/null @@ -1,28 +0,0 @@ - - -
- {@html render_inline_markdown(info)} -
- - diff --git a/6.11.1/atoms/src/ScrollFade.svelte b/6.11.1/atoms/src/ScrollFade.svelte deleted file mode 100644 index 4f41ee90a45057f39c09494597f08c27857355fe..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/ScrollFade.svelte +++ /dev/null @@ -1,37 +0,0 @@ - - -{#if visible} -
-{/if} - - diff --git a/6.11.1/atoms/src/SelectSource.svelte b/6.11.1/atoms/src/SelectSource.svelte deleted file mode 100644 index f5e0304f92c4c9ffb83e4d57793772cdd05fd9b5..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/SelectSource.svelte +++ /dev/null @@ -1,112 +0,0 @@ - - -{#if unique_sources.length > 1 || sources.includes("clipboard")} - - {#if sources.includes("upload")} - - {/if} - - {#if sources.includes("microphone")} - - {/if} - - {#if sources.includes("webcam")} - - {/if} - {#if sources.includes("webcam-video")} - - {/if} - {#if sources.includes("clipboard")} - - {/if} - -{/if} - - diff --git a/6.11.1/atoms/src/ShareButton.svelte b/6.11.1/atoms/src/ShareButton.svelte deleted file mode 100644 index 99a7ee08fc7acd68f5b27315af14539a2d02ad56..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/ShareButton.svelte +++ /dev/null @@ -1,39 +0,0 @@ - - - { - try { - pending = true; - const formatted = await formatter(value); - dispatch("share", { - description: formatted - }); - } catch (e) { - console.error(e); - let message = e instanceof ShareError ? e.message : "Share failed."; - dispatch("error", message); - } finally { - pending = false; - } - }} -/> diff --git a/6.11.1/atoms/src/Toolbar.svelte b/6.11.1/atoms/src/Toolbar.svelte deleted file mode 100644 index 389bb863402c939d2c7fca877c3275abd683e659..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/Toolbar.svelte +++ /dev/null @@ -1,28 +0,0 @@ - - -
- -
- - diff --git a/6.11.1/atoms/src/UploadText.svelte b/6.11.1/atoms/src/UploadText.svelte deleted file mode 100644 index 5902eb6666effc8c7281027174dd4a0c9e334df6..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/UploadText.svelte +++ /dev/null @@ -1,102 +0,0 @@ - - -
- - {#if type === "clipboard"} - - {:else} - - {/if} - - - {#if heading || paragraph} - {#if heading} -

{heading}

- {/if} - {#if paragraph} -

{paragraph}

- {/if} - {:else} - {i18n(defs[type] || defs.file)} - - {#if mode !== "short"} - - {i18n("common.or")} - - {message || i18n("upload_text.click_to_upload")} - {/if} - {/if} -
- - diff --git a/6.11.1/atoms/src/index.ts b/6.11.1/atoms/src/index.ts deleted file mode 100644 index fc6a8601e5d6448a2e1c5b0dad6f0b5274b59e2d..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -export { default as Block } from "./Block.svelte"; -export { default as BlockTitle } from "./BlockTitle.svelte"; -export { default as BlockLabel } from "./BlockLabel.svelte"; -export { default as DownloadLink } from "./DownloadLink.svelte"; -export { default as IconButton } from "./IconButton.svelte"; -export { default as Empty } from "./Empty.svelte"; -export { default as Info } from "./Info.svelte"; -export { default as ShareButton } from "./ShareButton.svelte"; -export { default as UploadText } from "./UploadText.svelte"; -export { default as Toolbar } from "./Toolbar.svelte"; -export { default as SelectSource } from "./SelectSource.svelte"; -export { default as IconButtonWrapper } from "./IconButtonWrapper.svelte"; -export { default as FullscreenButton } from "./FullscreenButton.svelte"; -export { default as CustomButton } from "./CustomButton.svelte"; -export { default as ScrollFade } from "./ScrollFade.svelte"; - -export const BLOCK_KEY = {}; diff --git a/6.11.1/atoms/src/inline-markdown.ts b/6.11.1/atoms/src/inline-markdown.ts deleted file mode 100644 index 5eb55f4448ff41876211359dc2f94f5e61431173..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/inline-markdown.ts +++ /dev/null @@ -1,40 +0,0 @@ -export const INLINE_CODE_RE = /`([^`]+)`/g; -export const LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g; -export const BOLD_ASTERISK_RE = /\*\*(.+?)\*\*/g; -export const BOLD_UNDERSCORE_RE = /__(.+?)__/g; -export const ITALIC_ASTERISK_RE = /\*(.+?)\*/g; -export const ITALIC_UNDERSCORE_RE = /(?/g, ">") - .replace(/"/g, """); -} - -function render_link(_match: string, text: string, url: string): string { - const trimmed = url.trim(); - if (PROTOCOL_RE.test(trimmed)) { - if (/^https?:/i.test(trimmed)) { - return `${text}`; - } - return text; - } - return `${text}`; -} - -export function render_inline_markdown(text: string): string { - let result = escape_html(text); - - result = result.replace(INLINE_CODE_RE, "$1"); - result = result.replace(LINK_RE, render_link); - result = result.replace(BOLD_ASTERISK_RE, "$1"); - result = result.replace(BOLD_UNDERSCORE_RE, "$1"); - result = result.replace(ITALIC_ASTERISK_RE, "$1"); - result = result.replace(ITALIC_UNDERSCORE_RE, "$1"); - result = result.replace(/\n/g, "
"); - - return result; -} diff --git a/6.11.1/atoms/src/utils/parse_placeholder.ts b/6.11.1/atoms/src/utils/parse_placeholder.ts deleted file mode 100644 index 2a562444d816df338509c915d48a82e4dcb0709c..0000000000000000000000000000000000000000 --- a/6.11.1/atoms/src/utils/parse_placeholder.ts +++ /dev/null @@ -1,27 +0,0 @@ -const RE_HEADING = /^(#\s*)(.+)$/m; - -export function inject(text: string): [string | false, string | false] { - const trimmed_text = text.trim(); - - const heading_match = trimmed_text.match(RE_HEADING); - if (!heading_match) { - return [false, trimmed_text || false]; - } - - const [full_match, , heading_content] = heading_match; - const _heading = heading_content.trim(); - - if (trimmed_text === full_match) { - return [_heading, false]; - } - - const heading_end_index = - heading_match.index !== undefined - ? heading_match.index + full_match.length - : 0; - const remaining_text = trimmed_text.substring(heading_end_index).trim(); - - const _paragraph = remaining_text || false; - - return [_heading, _paragraph]; -} diff --git a/6.11.1/audio/Example.svelte b/6.11.1/audio/Example.svelte deleted file mode 100644 index fc877b8bea36f28d38868c24716022a54a97fb80..0000000000000000000000000000000000000000 --- a/6.11.1/audio/Example.svelte +++ /dev/null @@ -1,25 +0,0 @@ - - -
- {value ? value : ""} -
- - diff --git a/6.11.1/audio/Index.svelte b/6.11.1/audio/Index.svelte deleted file mode 100644 index a4648bda9cdddd4e5a7e9d8c4ae93574e0905f55..0000000000000000000000000000000000000000 --- a/6.11.1/audio/Index.svelte +++ /dev/null @@ -1,234 +0,0 @@ - - - - -{#if !gradio.shared.interactive} - - - gradio.dispatch("clear_status", gradio.shared.loading_status)} - /> - - { - gradio.dispatch("custom_button_click", { id }); - }} - bind:playback_position={gradio.props.playback_position} - onshare={(detail) => gradio.dispatch("share", detail)} - onerror={(e) => gradio.dispatch("error", e.detail)} - onplay={() => gradio.dispatch("play")} - onpause={() => gradio.dispatch("pause")} - onstop={() => gradio.dispatch("stop")} - /> - -{:else} - - - gradio.dispatch("clear_status", gradio.shared.loading_status)} - /> - { - gradio.dispatch("custom_button_click", { id }); - }} - value={gradio.props.value} - subtitles={gradio.props.subtitles} - onchange={(detail) => (gradio.props.value = detail)} - onstream={(detail) => { - gradio.props.value = detail; - gradio.dispatch("stream", gradio.props.value); - }} - ondrag={(detail) => (dragging = detail)} - root={gradio.shared.root} - sources={gradio.props.sources} - active_source={active_source || undefined} - pending={gradio.shared.loading_status.pending} - streaming={gradio.props.streaming} - bind:recording - loop={gradio.props.loop} - max_file_size={gradio.shared.max_file_size} - {handle_reset_value} - editable={gradio.props.editable} - bind:dragging - bind:playback_position={gradio.props.playback_position} - onedit={() => gradio.dispatch("edit")} - onplay={() => gradio.dispatch("play")} - onpause={() => gradio.dispatch("pause")} - onstop={() => gradio.dispatch("stop")} - onstart_recording={() => gradio.dispatch("start_recording")} - onpause_recording={() => gradio.dispatch("pause_recording")} - onstop_recording={() => { - gradio.dispatch("stop_recording"); - gradio.dispatch("input"); - }} - onupload={() => { - gradio.dispatch("upload"); - gradio.dispatch("input"); - }} - onclear={() => { - gradio.dispatch("clear"); - gradio.dispatch("input"); - }} - onerror={handle_error} - onclose_stream={() => gradio.dispatch("close_stream", "stream")} - i18n={gradio.i18n} - {waveform_settings} - waveform_options={gradio.props.waveform_options} - {trim_region_settings} - stream_every={gradio.props.stream_every} - stream_state={gradio.shared.loading_status.stream_state} - upload={(...args) => gradio.shared.client.upload(...args)} - stream_handler={(...args) => gradio.shared.client.stream(...args)} - time_limit={gradio.shared.loading_status.time_limit} - > - - - -{/if} diff --git a/6.11.1/audio/index.ts b/6.11.1/audio/index.ts deleted file mode 100644 index c5bc9adbfd99bfba1587c0236e72968d6d91edee..0000000000000000000000000000000000000000 --- a/6.11.1/audio/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { default as Index } from "./Index.svelte"; -export default Index; -export { default as BaseStaticAudio } from "./static/StaticAudio.svelte"; -export { default as BaseInteractiveAudio } from "./interactive/InteractiveAudio.svelte"; -export { default as BasePlayer } from "./player/AudioPlayer.svelte"; -export type { WaveformOptions } from "./shared/types"; -export { default as BaseExample } from "./Example.svelte"; diff --git a/6.11.1/audio/interactive/InteractiveAudio.svelte b/6.11.1/audio/interactive/InteractiveAudio.svelte deleted file mode 100644 index c1202e280b6d582f16affa58c148fbb3feabd4bc..0000000000000000000000000000000000000000 --- a/6.11.1/audio/interactive/InteractiveAudio.svelte +++ /dev/null @@ -1,431 +0,0 @@ - - - -
- - {#if value == null || streaming} - {#if active_source === "microphone"} - - {#if streaming} - - {:else} - onstart_recording?.()} - onpauserecording={() => onpause_recording?.()} - onstoprecording={() => onstop_recording?.()} - /> - {/if} - {:else if active_source === "upload"} - - onerror?.(detail)} - {root} - {max_file_size} - {upload} - {stream_handler} - aria_label={i18n("audio.drop_to_upload")} - > - {#if children}{@render children()}{/if} - - {/if} - {:else} - { - mode = "edit"; - onedit?.(); - }} - download={buttons === null - ? value.url - : buttons.some((btn) => typeof btn === "string" && btn === "download") - ? value.url - : null} - > - {#if value !== null && buttons} - {#each buttons as btn} - {#if typeof btn === "string"} - {#if btn === "share"} - {}} - formatter={async (fileData: FileData) => { - if (!fileData || !fileData.url) return ""; - let url = await uploadToHuggingFace(fileData.url, "url"); - return ``; - }} - {value} - /> - {/if} - {:else} - { - if (on_custom_button_click) { - on_custom_button_click(id); - } - }} - /> - {/if} - {/each} - {/if} - - - - {/if} - -
- - diff --git a/6.11.1/audio/package.json b/6.11.1/audio/package.json deleted file mode 100644 index eb2a78d0db8fc72e97e46b25e4c2c746875b626d..0000000000000000000000000000000000000000 --- a/6.11.1/audio/package.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "name": "@gradio/audio", - "version": "0.23.1", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/statustracker": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^", - "extendable-media-recorder": "9.0.0", - "extendable-media-recorder-wav-encoder": "7.0.76", - "hls.js": "1.5.13", - "resize-observer-polyfill": "1.5.1", - "svelte-range-slider-pips": "4.1.0", - "wavesurfer.js": "7.11.0" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "main_changeset": true, - "main": "index.ts", - "exports": { - "./package.json": "./package.json", - ".": { - "gradio": "./index.ts", - "svelte": "./dist/index.js", - "types": "./dist/index.d.ts" - }, - "./example": { - "gradio": "./Example.svelte", - "svelte": "./dist/Example.svelte", - "types": "./dist/Example.svelte.d.ts" - }, - "./shared": { - "gradio": "./shared/index.ts", - "svelte": "./dist/shared/index.js", - "types": "./dist/shared/index.d.ts" - }, - "./base": { - "gradio": "./static/StaticAudio.svelte", - "svelte": "./dist/static/StaticAudio.svelte", - "types": "./dist/static/StaticAudio.svelte.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/audio" - } -} diff --git a/6.11.1/audio/player/AudioPlayer.svelte b/6.11.1/audio/player/AudioPlayer.svelte deleted file mode 100644 index e277b07d75f075ed7639dcafe860230e04dbb426..0000000000000000000000000000000000000000 --- a/6.11.1/audio/player/AudioPlayer.svelte +++ /dev/null @@ -1,525 +0,0 @@ - - - -{#if value === null} - - - -{:else if use_waveform} -
-
-
-
- -
- -
- {#if mode === "edit" && trimDuration > 0} - - {/if} - -
-
- -
- - -
-{/if} - - diff --git a/6.11.1/audio/recorder/AudioRecorder.svelte b/6.11.1/audio/recorder/AudioRecorder.svelte deleted file mode 100644 index e9f7c4049b0c1b90b67e99f34ca913f18cd92cc8..0000000000000000000000000000000000000000 --- a/6.11.1/audio/recorder/AudioRecorder.svelte +++ /dev/null @@ -1,315 +0,0 @@ - - -
-
-
- - {#if (timing || recordedAudio) && waveform_options.show_recording_waveform} -
- -
- {#if mode === "edit" && trimDuration > 0} - - {/if} - {#if timing} - - {:else} - - {/if} -
-
- {/if} - - {#if record_mounted && !recordedAudio} - - {/if} - - {#if recordingWaveform && recordedAudio} - - {/if} -
- - diff --git a/6.11.1/audio/shared/Audio.svelte b/6.11.1/audio/shared/Audio.svelte deleted file mode 100644 index ce12d5b360580e26b2edd4d9c88c5a586ba3a312..0000000000000000000000000000000000000000 --- a/6.11.1/audio/shared/Audio.svelte +++ /dev/null @@ -1,17 +0,0 @@ - - -
- {:else if checked || gradio.props.ui_mode !== "dialogue"} -
- {#if is_formatting} -
-
-
Converting to plain text...
-
- {/if} - - {/if} - {#if submit_btn} - - {/if} - {#if stop_btn} - - {/if} -
- - - diff --git a/6.12.0/textbox/types.ts b/6.12.0/textbox/types.ts deleted file mode 100644 index 8ec1cfc945755962a887be7207b0f60290ad929a..0000000000000000000000000000000000000000 --- a/6.12.0/textbox/types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type SelectData, - type CopyData, - type CustomButton -} from "@gradio/utils"; -import type { LoadingStatus } from "@gradio/statustracker"; - -export interface TextboxEvents { - change: string; - submit: never; - blur: never; - select: SelectData; - input: never; - focus: never; - stop: never; - clear_status: LoadingStatus; - copy: CopyData; - custom_button_click: { id: number }; -} - -export interface TextboxProps { - value: string; - info: string; - lines: number; - type: "text" | "password" | "email" | undefined; - rtl: boolean; - text_align: "right" | "left"; - max_lines: number; - placeholder: string; - submit_btn: string; - stop_btn: string; - buttons: (string | CustomButton)[] | null; - autofocus: boolean; - autoscroll: boolean; - max_length: number; - html_attributes: InputHTMLAttributes; - validation_error: string | null; -} - -type FullAutoFill = - | AutoFill - | "bday" - | `${OptionalPrefixToken}${"cc-additional-name"}` - | "nickname" - | "language" - | "organization-title" - | "photo" - | "sex" - | "url"; - -export interface InputHTMLAttributes { - autocapitalize?: - | "off" - | "none" - | "on" - | "sentences" - | "words" - | "characters" - | null; - autocorrect?: "on" | "off" | null; - spellcheck?: boolean | null; - autocomplete?: FullAutoFill | undefined | null; - tabindex?: number | null; - enterkeyhint?: - | "enter" - | "done" - | "go" - | "next" - | "previous" - | "search" - | "send" - | null; - lang?: string | null; -} diff --git a/6.12.0/theme/package.json b/6.12.0/theme/package.json deleted file mode 100644 index bb4343fa73bdf0fe073c0d611292babaf9cc8d6b..0000000000000000000000000000000000000000 --- a/6.12.0/theme/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@gradio/theme", - "version": "0.6.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": false, - "scripts": { - "generate": "pollen -c src/pollen.config.mjs", - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./reset.css": { - "gradio": "./src/reset.css", - "import": "./dist/src/reset.css" - }, - "./global.css": { - "gradio": "./src/global.css", - "import": "./dist/src/global.css" - }, - "./tokens": { - "gradio": "./src/tokens.ts", - "import": "./dist/src/tokens.js" - }, - "./typography.css": { - "gradio": "./src/typography.css", - "import": "./dist/src/typography.css" - }, - "./gradio-style.scss": { - "gradio": "./src/gradio-style.scss", - "import": "./dist/src/gradio-style.scss" - }, - "./pollen.css": { - "gradio": "./src/pollen.css", - "import": "./dist/src/pollen.css" - }, - "./package.json": "./package.json" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/theme" - } -} diff --git a/6.12.0/theme/src/colors.ts b/6.12.0/theme/src/colors.ts deleted file mode 100644 index 04a9c9b33c631635832a8fb982ce1d29e0176fa7..0000000000000000000000000000000000000000 --- a/6.12.0/theme/src/colors.ts +++ /dev/null @@ -1,350 +0,0 @@ -// import tw_colors from "tailwindcss/colors"; - -export const ordered_colors = [ - "red", - "green", - "blue", - "yellow", - "purple", - "teal", - "orange", - "cyan", - "lime", - "pink" -] as const; -interface ColorPair { - primary: string; - secondary: string; -} - -interface Colors { - red: ColorPair; - green: ColorPair; - blue: ColorPair; - yellow: ColorPair; - purple: ColorPair; - teal: ColorPair; - orange: ColorPair; - cyan: ColorPair; - lime: ColorPair; - pink: ColorPair; -} - -// https://play.tailwindcss.com/ZubQYya0aN -export const color_values = [ - { color: "red", primary: 600, secondary: 100 }, - { color: "green", primary: 600, secondary: 100 }, - { color: "blue", primary: 600, secondary: 100 }, - { color: "yellow", primary: 500, secondary: 100 }, - { color: "purple", primary: 600, secondary: 100 }, - { color: "teal", primary: 600, secondary: 100 }, - { color: "orange", primary: 600, secondary: 100 }, - { color: "cyan", primary: 600, secondary: 100 }, - { color: "lime", primary: 500, secondary: 100 }, - { color: "pink", primary: 600, secondary: 100 } -] as const; - -const tw_colors = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - slate: { - 50: "#f8fafc", - 100: "#f1f5f9", - 200: "#e2e8f0", - 300: "#cbd5e1", - 400: "#94a3b8", - 500: "#64748b", - 600: "#475569", - 700: "#334155", - 800: "#1e293b", - 900: "#0f172a", - 950: "#020617" - }, - gray: { - 50: "#f9fafb", - 100: "#f3f4f6", - 200: "#e5e7eb", - 300: "#d1d5db", - 400: "#9ca3af", - 500: "#6b7280", - 600: "#4b5563", - 700: "#374151", - 800: "#1f2937", - 900: "#111827", - 950: "#030712" - }, - zinc: { - 50: "#fafafa", - 100: "#f4f4f5", - 200: "#e4e4e7", - 300: "#d4d4d8", - 400: "#a1a1aa", - 500: "#71717a", - 600: "#52525b", - 700: "#3f3f46", - 800: "#27272a", - 900: "#18181b", - 950: "#09090b" - }, - neutral: { - 50: "#fafafa", - 100: "#f5f5f5", - 200: "#e5e5e5", - 300: "#d4d4d4", - 400: "#a3a3a3", - 500: "#737373", - 600: "#525252", - 700: "#404040", - 800: "#262626", - 900: "#171717", - 950: "#0a0a0a" - }, - stone: { - 50: "#fafaf9", - 100: "#f5f5f4", - 200: "#e7e5e4", - 300: "#d6d3d1", - 400: "#a8a29e", - 500: "#78716c", - 600: "#57534e", - 700: "#44403c", - 800: "#292524", - 900: "#1c1917", - 950: "#0c0a09" - }, - red: { - 50: "#fef2f2", - 100: "#fee2e2", - 200: "#fecaca", - 300: "#fca5a5", - 400: "#f87171", - 500: "#ef4444", - 600: "#dc2626", - 700: "#b91c1c", - 800: "#991b1b", - 900: "#7f1d1d", - 950: "#450a0a" - }, - orange: { - 50: "#fff7ed", - 100: "#ffedd5", - 200: "#fed7aa", - 300: "#fdba74", - 400: "#fb923c", - 500: "#f97316", - 600: "#ea580c", - 700: "#c2410c", - 800: "#9a3412", - 900: "#7c2d12", - 950: "#431407" - }, - amber: { - 50: "#fffbeb", - 100: "#fef3c7", - 200: "#fde68a", - 300: "#fcd34d", - 400: "#fbbf24", - 500: "#f59e0b", - 600: "#d97706", - 700: "#b45309", - 800: "#92400e", - 900: "#78350f", - 950: "#451a03" - }, - yellow: { - 50: "#fefce8", - 100: "#fef9c3", - 200: "#fef08a", - 300: "#fde047", - 400: "#facc15", - 500: "#eab308", - 600: "#ca8a04", - 700: "#a16207", - 800: "#854d0e", - 900: "#713f12", - 950: "#422006" - }, - lime: { - 50: "#f7fee7", - 100: "#ecfccb", - 200: "#d9f99d", - 300: "#bef264", - 400: "#a3e635", - 500: "#84cc16", - 600: "#65a30d", - 700: "#4d7c0f", - 800: "#3f6212", - 900: "#365314", - 950: "#1a2e05" - }, - green: { - 50: "#f0fdf4", - 100: "#dcfce7", - 200: "#bbf7d0", - 300: "#86efac", - 400: "#4ade80", - 500: "#22c55e", - 600: "#16a34a", - 700: "#15803d", - 800: "#166534", - 900: "#14532d", - 950: "#052e16" - }, - emerald: { - 50: "#ecfdf5", - 100: "#d1fae5", - 200: "#a7f3d0", - 300: "#6ee7b7", - 400: "#34d399", - 500: "#10b981", - 600: "#059669", - 700: "#047857", - 800: "#065f46", - 900: "#064e3b", - 950: "#022c22" - }, - teal: { - 50: "#f0fdfa", - 100: "#ccfbf1", - 200: "#99f6e4", - 300: "#5eead4", - 400: "#2dd4bf", - 500: "#14b8a6", - 600: "#0d9488", - 700: "#0f766e", - 800: "#115e59", - 900: "#134e4a", - 950: "#042f2e" - }, - cyan: { - 50: "#ecfeff", - 100: "#cffafe", - 200: "#a5f3fc", - 300: "#67e8f9", - 400: "#22d3ee", - 500: "#06b6d4", - 600: "#0891b2", - 700: "#0e7490", - 800: "#155e75", - 900: "#164e63", - 950: "#083344" - }, - sky: { - 50: "#f0f9ff", - 100: "#e0f2fe", - 200: "#bae6fd", - 300: "#7dd3fc", - 400: "#38bdf8", - 500: "#0ea5e9", - 600: "#0284c7", - 700: "#0369a1", - 800: "#075985", - 900: "#0c4a6e", - 950: "#082f49" - }, - blue: { - 50: "#eff6ff", - 100: "#dbeafe", - 200: "#bfdbfe", - 300: "#93c5fd", - 400: "#60a5fa", - 500: "#3b82f6", - 600: "#2563eb", - 700: "#1d4ed8", - 800: "#1e40af", - 900: "#1e3a8a", - 950: "#172554" - }, - indigo: { - 50: "#eef2ff", - 100: "#e0e7ff", - 200: "#c7d2fe", - 300: "#a5b4fc", - 400: "#818cf8", - 500: "#6366f1", - 600: "#4f46e5", - 700: "#4338ca", - 800: "#3730a3", - 900: "#312e81", - 950: "#1e1b4b" - }, - violet: { - 50: "#f5f3ff", - 100: "#ede9fe", - 200: "#ddd6fe", - 300: "#c4b5fd", - 400: "#a78bfa", - 500: "#8b5cf6", - 600: "#7c3aed", - 700: "#6d28d9", - 800: "#5b21b6", - 900: "#4c1d95", - 950: "#2e1065" - }, - purple: { - 50: "#faf5ff", - 100: "#f3e8ff", - 200: "#e9d5ff", - 300: "#d8b4fe", - 400: "#c084fc", - 500: "#a855f7", - 600: "#9333ea", - 700: "#7e22ce", - 800: "#6b21a8", - 900: "#581c87", - 950: "#3b0764" - }, - fuchsia: { - 50: "#fdf4ff", - 100: "#fae8ff", - 200: "#f5d0fe", - 300: "#f0abfc", - 400: "#e879f9", - 500: "#d946ef", - 600: "#c026d3", - 700: "#a21caf", - 800: "#86198f", - 900: "#701a75", - 950: "#4a044e" - }, - pink: { - 50: "#fdf2f8", - 100: "#fce7f3", - 200: "#fbcfe8", - 300: "#f9a8d4", - 400: "#f472b6", - 500: "#ec4899", - 600: "#db2777", - 700: "#be185d", - 800: "#9d174d", - 900: "#831843", - 950: "#500724" - }, - rose: { - 50: "#fff1f2", - 100: "#ffe4e6", - 200: "#fecdd3", - 300: "#fda4af", - 400: "#fb7185", - 500: "#f43f5e", - 600: "#e11d48", - 700: "#be123c", - 800: "#9f1239", - 900: "#881337", - 950: "#4c0519" - } -}; - -export const colors = color_values.reduce( - (acc, { color, primary, secondary }) => ({ - ...acc, - [color]: { - primary: tw_colors[color][primary], - secondary: tw_colors[color][secondary] - } - }), - {} as Colors -); diff --git a/6.12.0/theme/src/index.ts b/6.12.0/theme/src/index.ts deleted file mode 100644 index bd1cb299eaa9b1ae2f6bd0c1973fa12d0c4cdb57..0000000000000000000000000000000000000000 --- a/6.12.0/theme/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// export { default as reset } from "./reset.css"; -// export { default as global } from "./global.css"; -// export { default as css } from "./pollen.css"; -// export { default as typography } from "./typography.css"; - -export * from "./colors.js"; diff --git a/6.12.0/timer/Index.svelte b/6.12.0/timer/Index.svelte deleted file mode 100644 index 7fc7857ad7235b62c97ffb4fccba78a6c9d89fd9..0000000000000000000000000000000000000000 --- a/6.12.0/timer/Index.svelte +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/6.12.0/timer/package.json b/6.12.0/timer/package.json deleted file mode 100644 index 69e4fd022b1204bf416a79f66fbf6f1c0e859744..0000000000000000000000000000000000000000 --- a/6.12.0/timer/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@gradio/timer", - "version": "0.4.9", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "dependencies": { - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/timer" - } -} diff --git a/6.12.0/timer/types.ts b/6.12.0/timer/types.ts deleted file mode 100644 index 292d729b4daf9b93f8261167f14496b64a103084..0000000000000000000000000000000000000000 --- a/6.12.0/timer/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimerProps { - value: number; - active: boolean; -} - -export interface TimerEvents { - tick: never; - clear_status: never; -} diff --git a/6.12.0/tooltip/package.json b/6.12.0/tooltip/package.json deleted file mode 100644 index 1b699440866a7a7c79de9e7575bc07b5373465fe..0000000000000000000000000000000000000000 --- a/6.12.0/tooltip/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@gradio/tooltip", - "version": "0.2.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/tooltip" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.js", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - } -} diff --git a/6.12.0/tooltip/src/Tooltip.svelte b/6.12.0/tooltip/src/Tooltip.svelte deleted file mode 100644 index c9c9ecca6357234953144bcf6a0dbe7ee5e822de..0000000000000000000000000000000000000000 --- a/6.12.0/tooltip/src/Tooltip.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - {text} -
- - diff --git a/6.12.0/tooltip/src/index.ts b/6.12.0/tooltip/src/index.ts deleted file mode 100644 index b89ac870e5bbf6d90058c6e25cb9d74b626b3809..0000000000000000000000000000000000000000 --- a/6.12.0/tooltip/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { tooltip } from "./tooltip"; diff --git a/6.12.0/tooltip/src/tooltip.ts b/6.12.0/tooltip/src/tooltip.ts deleted file mode 100644 index 09403f9438805f29a32579b8e98a25f3aae37737..0000000000000000000000000000000000000000 --- a/6.12.0/tooltip/src/tooltip.ts +++ /dev/null @@ -1,49 +0,0 @@ -import Tooltip from "./Tooltip.svelte"; - -interface ActionArgs { - color: string; - text: string; -} - -export function tooltip( - element: HTMLElement | SVGElement, - { color, text }: ActionArgs -): any { - let tooltipComponent: Tooltip; - function mouse_over(event: MouseEvent): MouseEvent { - tooltipComponent = new Tooltip({ - props: { - text, - x: event.pageX, - y: event.pageY, - color - }, - target: document.body - }); - - return event; - } - function mouseMove(event: MouseEvent): void { - tooltipComponent.$set({ - x: event.pageX, - y: event.pageY - }); - } - function mouseLeave(): void { - tooltipComponent.$destroy(); - } - - const el = element as HTMLElement; - - el.addEventListener("mouseover", mouse_over); - el.addEventListener("mouseleave", mouseLeave); - el.addEventListener("mousemove", mouseMove); - - return { - destroy() { - el.removeEventListener("mouseover", mouse_over); - el.removeEventListener("mouseleave", mouseLeave); - el.removeEventListener("mousemove", mouseMove); - } - }; -} diff --git a/6.12.0/tootils/package.json b/6.12.0/tootils/package.json deleted file mode 100644 index 39683201d83bfc3a5ffaeb655426076b27f40944..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@self/tootils", - "version": "0.13.0", - "description": "Internal test utilities", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": "./src/index.ts", - "./render": "./src/render.ts", - "./shared-prop-tests": "./src/shared-prop-tests.ts", - "./app-launcher": "./src/app-launcher.ts", - "./download-command": "./src/download-command.ts" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.12.0/tootils/src/app-launcher.ts b/6.12.0/tootils/src/app-launcher.ts deleted file mode 100644 index a320667e5764ec306dec64eabbfa998bdd85169c..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/app-launcher.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { spawn, type ChildProcess } from "node:child_process"; -import http from "http"; -import net from "net"; -import path from "path"; -import fs from "fs"; -import os from "os"; -import url from "url"; - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -const ROOT_DIR = path.resolve(__dirname, "../../.."); - -export interface GradioApp { - port: number; - process: ChildProcess; -} - -export function killGradioApp(process: ChildProcess): void { - try { - process.kill("SIGTERM"); - } catch { - // Process may already be dead - } -} - -export async function findFreePort( - startPort: number, - endPort: number -): Promise { - for (let port = startPort; port < endPort; port++) { - if (await isPortFree(port)) { - return port; - } - } - throw new Error(`Could not find free port in range ${startPort}-${endPort}`); -} - -function isPortFree(port: number): Promise { - return new Promise((resolve, reject) => { - const sock = net.createConnection(port, "127.0.0.1"); - sock.once("connect", () => { - sock.end(); - resolve(false); - }); - sock.once("error", (e: NodeJS.ErrnoException) => { - sock.destroy(); - if (e.code === "ECONNREFUSED") { - resolve(true); - } else { - reject(e); - } - }); - }); -} - -/** - * Poll the server with HTTP GET requests until it returns a response. - * Gradio prints "Running on local URL:" before the server is fully ready, - * so we need to verify it actually responds to HTTP requests. - */ -async function waitForServerReady( - port: number, - timeoutMs: number = 15000 -): Promise { - const start = Date.now(); - const pollInterval = 200; - - while (Date.now() - start < timeoutMs) { - try { - await new Promise((resolve, reject) => { - // Use HEAD on /gradio_api/info to avoid triggering SSR rendering on - // the root URL, which could block Gradio's own startup health check. - const req = http.request( - `http://127.0.0.1:${port}/gradio_api/info`, - { method: "HEAD", timeout: 2000 }, - (res) => { - res.resume(); // drain the response - resolve(); - } - ); - req.on("error", reject); - req.on("timeout", () => { - req.destroy(); - reject(new Error("request timeout")); - }); - req.end(); - }); - return; // Server responded successfully - } catch { - // Server not ready yet, wait and retry - await new Promise((r) => setTimeout(r, pollInterval)); - } - } - throw new Error( - `Server on port ${port} did not become ready within ${timeoutMs}ms` - ); -} - -export function getTestcases(demoName: string): string[] { - const demoDir = path.join(ROOT_DIR, "demo", demoName); - if (!fs.existsSync(demoDir)) { - return []; - } - - return fs - .readdirSync(demoDir) - .filter((f) => f.endsWith("_testcase.py")) - .map((f) => path.basename(f, ".py")); -} - -// Check if a testcase file exists for this demo -export function hasTestcase(demoName: string, testcaseName: string): boolean { - const testcaseFile = path.join( - ROOT_DIR, - "demo", - demoName, - `${testcaseName}_testcase.py` - ); - return fs.existsSync(testcaseFile); -} - -// Get the path to a demo's Python file -function getDemoFilePath(demoName: string, testcaseName?: string): string { - if (testcaseName) { - return path.join(ROOT_DIR, "demo", demoName, `${testcaseName}_testcase.py`); - } - return path.join(ROOT_DIR, "demo", demoName, "run.py"); -} - -export async function launchGradioApp( - demoName: string, - workerIndex: number = 0, - timeout: number = 60000, - testcaseName?: string -): Promise { - // Partition ports by worker index to avoid collisions - const basePort = 7860 + workerIndex * 100; - const port = await findFreePort(basePort, basePort + 99); - - // Get the path to the demo file - const demoFilePath = getDemoFilePath(demoName, testcaseName); - - // Create unique directories for this instance to avoid cache conflicts - const instanceId = testcaseName - ? `${demoName}_${testcaseName}_${port}` - : `${demoName}_${port}`; - const instanceDir = path.join(os.tmpdir(), `gradio_test_${instanceId}`); - const cacheDir = path.join(instanceDir, "cached_examples"); - const tempDir = path.join(instanceDir, "temp"); - - if (!fs.existsSync(instanceDir)) { - fs.mkdirSync(instanceDir, { recursive: true }); - } - - // Run the demo file directly - the demo's own if __name__ == "__main__" block - // has the correct launch parameters (show_error, etc.) - const childProcess = spawn("python", [demoFilePath], { - stdio: "pipe", - cwd: ROOT_DIR, - env: { - ...process.env, - PYTHONUNBUFFERED: "true", - GRADIO_ANALYTICS_ENABLED: "False", - GRADIO_IS_E2E_TEST: "1", - GRADIO_RESET_EXAMPLES_CACHE: "True", - // Control the port via environment variable - GRADIO_SERVER_PORT: port.toString(), - // Use unique directories per instance to avoid conflicts - GRADIO_EXAMPLES_CACHE: cacheDir, - GRADIO_TEMP_DIR: tempDir - } - }); - - childProcess.stdout?.setEncoding("utf8"); - childProcess.stderr?.setEncoding("utf8"); - - // Wait for app to be ready - return new Promise((resolve, reject) => { - const timeoutId = setTimeout(() => { - killGradioApp(childProcess); - reject( - new Error(`Gradio app ${demoName} failed to start within ${timeout}ms`) - ); - }, timeout); - - let output = ""; - let startupDetected = false; - - function handleOutput(data: string): void { - output += data; - // Check for Gradio's startup message - if ( - !startupDetected && - (data.includes("Running on local URL:") || - data.includes(`Uvicorn running on`)) - ) { - startupDetected = true; - clearTimeout(timeoutId); - // The startup message is printed before the server is fully ready. - // Poll with HTTP requests to ensure it actually responds. - waitForServerReady(port) - .then(() => resolve({ port, process: childProcess })) - .catch(reject); - } - } - - childProcess.stdout?.on("data", handleOutput); - childProcess.stderr?.on("data", handleOutput); - - childProcess.on("error", (err) => { - clearTimeout(timeoutId); - reject(err); - }); - - childProcess.on("exit", (code) => { - if (code !== 0 && code !== null) { - clearTimeout(timeoutId); - reject( - new Error( - `Gradio app ${demoName} exited with code ${code}.\nOutput: ${output}` - ) - ); - } - }); - }); -} diff --git a/6.12.0/tootils/src/download-command.ts b/6.12.0/tootils/src/download-command.ts deleted file mode 100644 index 2d99d0883c6b5e985d21c18902e61db60ccaa6dc..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/download-command.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { BrowserCommand } from "vitest/node"; -import { resolve } from "path"; -import { readFile } from "fs/promises"; - -/** - * Vitest browser command that captures a real file download triggered by - * clicking an element. Runs server-side with access to the Playwright page. - * - * Sets up page.waitForEvent("download") BEFORE clicking, so the download - * event is never missed. - */ -export const expect_download: BrowserCommand< - [selector: string, options?: { timeout?: number }], - { suggested_filename: string; content: string | null } -> = async (context, selector, options) => { - const timeout = options?.timeout ?? 5000; - const provider = context.provider as any; - const page = provider.getPage(context.sessionId); - // Tests run inside an iframe; use the iframe locator to click - // but listen for the download event on the parent page. - const iframe = (context as any).iframe; - - const [download] = await Promise.all([ - page.waitForEvent("download", { timeout }), - iframe.locator(selector).click() - ]); - - const suggested_filename = download.suggestedFilename(); - const path = await download.path(); - - let content: string | null = null; - if (path) { - const fs = await import("fs/promises"); - content = await fs.readFile(path, "utf-8"); - } - - return { - suggested_filename, - content - }; -}; - -/** - * Vitest browser command that sets files on an element. - * Resolves fixture URL paths (e.g. "/test/test_files/bus.png") to absolute - * disk paths and uses Playwright's setInputFiles(). - */ -export const set_file_inputs: BrowserCommand< - [file_urls: string[], selector?: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - const iframe = (context as any).iframe; - - const paths = file_urls.map((url) => resolve(root, url.replace(/^\//, ""))); - - await iframe - .locator(selector ?? 'input[type="file"]') - .first() - .setInputFiles(paths); -}; - -interface Drop_file_spec { - data: string; // base64 - name: string; - mime_type: string; -} - -/** - * Vitest browser command that simulates dropping files onto an element. - * Reads files from disk, transfers them as base64 into the browser context, - * and dispatches dragenter, dragover, and drop events with a real DataTransfer. - */ -export const drop_files: BrowserCommand< - [file_urls: string[], selector: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - - const files: Drop_file_spec[] = await Promise.all( - file_urls.map(async (url) => { - const abs = resolve(root, url.replace(/^\//, "")); - const data = (await readFile(abs)).toString("base64"); - const name = abs.split("/").pop()!; - const ext = name.split(".").pop()!.toLowerCase(); - const mime_type = MIME_TYPES[ext] || "application/octet-stream"; - return { data, name, mime_type }; - }) - ); - - const iframe = (context as any).iframe; - await iframe - .locator(selector) - .first() - .evaluate((target: Element, files: Drop_file_spec[]) => { - const dt = new DataTransfer(); - for (const f of files) { - const bytes = Uint8Array.from(atob(f.data), (c) => c.charCodeAt(0)); - dt.items.add(new File([bytes], f.name, { type: f.mime_type })); - } - - target.dispatchEvent( - new DragEvent("dragenter", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("dragover", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("drop", { dataTransfer: dt, bubbles: true }) - ); - }, files); -}; - -const MIME_TYPES: Record = { - txt: "text/plain", - csv: "text/csv", - json: "application/json", - pdf: "application/pdf", - jpg: "image/jpeg", - jpeg: "image/jpeg", - png: "image/png", - gif: "image/gif", - webp: "image/webp", - svg: "image/svg+xml", - mp4: "video/mp4", - webm: "video/webm", - ogg: "video/ogg", - avi: "video/x-msvideo", - wav: "audio/wav", - mp3: "audio/mpeg", - flac: "audio/flac" -}; diff --git a/6.12.0/tootils/src/download.ts b/6.12.0/tootils/src/download.ts deleted file mode 100644 index c6217fc6695b81fe685bcff9593ed9cab6095a3a..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/download.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { commands } from "vitest/browser"; -import type { FileData } from "@gradio/client"; - -export interface DownloadResult { - suggested_filename: string; - content: string | null; -} - -/** - * Clicks an element and captures the resulting file download. - * - * Uses a real browser download via Playwright under the hood — - * the file is actually downloaded and its content is readable. - * - * @param selector - CSS selector for the element to click - * @param options - Optional timeout (default 5000ms) - * @returns The downloaded file's suggested filename and text content - * - * @example - * ```ts - * const { suggested_filename, content } = await download_file("a.download-link"); - * expect(suggested_filename).toBe("data.csv"); - * expect(content).toContain("col1,col2"); - * ``` - */ -export async function download_file( - selector: string, - options?: { timeout?: number } -): Promise { - return (commands as any).expect_download(selector, options); -} - -/** - * Sets files on an `` element using real file fixtures. - * - * Accepts one or more FileData fixtures (e.g. TEST_JPG, TEST_PNG) and - * sets them on the file input, triggering the browser's native change event. - * - * @param files - One or more FileData fixtures to upload - * @param selector - CSS selector for the file input (default: 'input[type="file"]') - * - * @example - * ```ts - * import { render, upload_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await upload_file(TEST_JPG); - * - * expect(upload).toHaveBeenCalled(); - * ``` - */ -export async function upload_file( - files: FileData | FileData[], - selector?: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).set_file_inputs(urls, selector); -} - -/** - * Simulates dragging and dropping files onto an element. - * - * Reads the fixture files from disk, constructs a real DataTransfer - * with File objects, and dispatches dragenter, dragover, and drop events - * on the target element. - * - * @param files - One or more FileData fixtures to drop - * @param selector - CSS selector for the drop target element - * - * @example - * ```ts - * import { render, drop_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await drop_file(TEST_JPG, "[aria-label='Click to upload or drop files']"); - * - * await vi.waitFor(() => expect(upload).toHaveBeenCalled()); - * ``` - */ -export async function drop_file( - files: FileData | FileData[], - selector: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).drop_files(urls, selector); -} diff --git a/6.12.0/tootils/src/fixtures.ts b/6.12.0/tootils/src/fixtures.ts deleted file mode 100644 index 95adcab69ee5186eb2533321b64e8fd08932a113..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/fixtures.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { FileData } from "@gradio/client"; - -const BASE = "/test/test_files"; - -function fixture(filename: string, mime_type: string, size: number): FileData { - const url = `${BASE}/${filename}`; - return new FileData({ - path: url, - url, - orig_name: filename, - size, - mime_type - }); -} - -export const TEST_TXT = fixture("alphabet.txt", "text/plain", 26); -export const TEST_JPG = fixture("cheetah1.jpg", "image/jpeg", 20552); -export const TEST_PNG = fixture("bus.png", "image/png", 1951); -export const TEST_MP4 = fixture("video_sample.mp4", "video/mp4", 261179); -export const TEST_WAV = fixture("audio_sample.wav", "audio/wav", 16136); -export const TEST_PDF = fixture("sample_file.pdf", "application/pdf", 10558); diff --git a/6.12.0/tootils/src/index.ts b/6.12.0/tootils/src/index.ts deleted file mode 100644 index 5ac7a8723c2c74c4d04fc0c2555ced0e6f8388f5..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/index.ts +++ /dev/null @@ -1,224 +0,0 @@ -import { test as base, type Locator, type Page } from "@playwright/test"; -import { spy } from "tinyspy"; -import url from "url"; -import path from "path"; -import fsPromises from "fs/promises"; -import type { ChildProcess } from "node:child_process"; - -import type { SvelteComponent } from "svelte"; -import type { SpyFn } from "tinyspy"; - -import { launchGradioApp, killGradioApp, hasTestcase } from "./app-launcher"; - -export function get_text(el: T): string { - return el.innerText.trim(); -} - -export function wait(n: number): Promise { - return new Promise((r) => setTimeout(r, n)); -} - -const ROOT_DIR = path.resolve( - url.fileURLToPath(import.meta.url), - "../../../.." -); - -// Extract testcase name from test title if present -// Test titles can be: -// - "case eager_caching_examples: ..." -// - "test case multimodal_messages chatinterface works..." -function extractTestcaseFromTitle( - title: string, - demoName: string -): string | undefined { - // Try pattern: "case :" or "test case " - const patterns = [/^case\s+(\w+):/, /^test case\s+(\w+)\s/]; - - for (const pattern of patterns) { - const match = title.match(pattern); - if (match) { - const caseName = match[1]; - // Check if this is a testcase (not the main demo) - if (hasTestcase(demoName, caseName)) { - return caseName; - } - } - } - return undefined; -} - -// Cache for launched apps - key is "demoName" or "demoName_testcaseName" -const appCache = new Map< - string, - { port: number; process: ChildProcess; refCount: number } ->(); - -// Test fixture that launches Gradio app per test -const test_normal = base.extend<{ setup: void }>({ - setup: [ - async ({ page }, use, testInfo): Promise => { - const { file, title } = testInfo; - const demoName = path.basename(file, ".spec.ts"); - - // Check if this is a reload test (they manage their own apps) - if (demoName.endsWith(".reload")) { - // For reload tests, don't launch an app - they handle it themselves - await use(); - return; - } - - // Check if this test is for a specific testcase - const testcaseName = extractTestcaseFromTitle(title, demoName); - - // Cache key includes testcase if present - const cacheKey = testcaseName ? `${demoName}_${testcaseName}` : demoName; - - let appInfo = appCache.get(cacheKey); - - if (!appInfo) { - // Launch the app for this test - const workerIndex = testInfo.workerIndex; - try { - const { port, process } = await launchGradioApp( - demoName, - workerIndex, - 60000, - testcaseName - ); - appInfo = { port, process, refCount: 0 }; - appCache.set(cacheKey, appInfo); - } catch (error) { - console.error(`Failed to launch app for ${cacheKey}:`, error); - throw error; - } - } - - appInfo.refCount++; - - // Navigate to the app - await page.goto(`http://localhost:${appInfo.port}`); - - if ( - process.env?.GRADIO_SSR_MODE?.toLowerCase() === "true" && - !( - demoName.includes("multipage") || - demoName.includes("chatinterface_deep_link") - ) - ) { - await page.waitForSelector("#svelte-announcer"); - } - await page.waitForLoadState("load"); - - await use(); - - // Decrement ref count - appInfo.refCount--; - - // Note: We don't kill the app here because other tests might - // still need it. The app will be killed when the process exits. - }, - { auto: true } - ] -}); - -// Cleanup apps when the process exits -process.on("exit", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } -}); - -process.on("SIGINT", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -process.on("SIGTERM", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -export const test = test_normal; - -export async function wait_for_event( - component: SvelteComponent, - event: string -): Promise { - const mock = spy(); - return new Promise((res) => { - component.$on(event, () => { - mock(); - res(mock); - }); - }); -} - -export interface ActionReturn< - Parameter = never, - Attributes extends Record = Record -> { - update?: [Parameter] extends [never] ? never : (parameter: Parameter) => void; - destroy?: () => void; - /** - * ### DO NOT USE THIS - * This exists solely for type-checking and has no effect at runtime. - * Set this through the `Attributes` generic instead. - */ - $$_attributes?: Attributes; -} - -export { expect } from "@playwright/test"; - -export const drag_and_drop_file = async ( - page: Page, - selector: string | Locator, - filePath: string, - fileName: string, - fileType = "", - count = 1 -): Promise => { - const buffer = (await fsPromises.readFile(filePath)).toString("base64"); - - const dataTransfer = await page.evaluateHandle( - async ({ bufferData, localFileName, localFileType, count }) => { - const dt = new DataTransfer(); - - const blobData = await fetch(bufferData).then((res) => res.blob()); - - const file = new File([blobData], localFileName, { - type: localFileType - }); - - for (let i = 0; i < count; i++) { - dt.items.add(file); - } - return dt; - }, - { - bufferData: `data:application/octet-stream;base64,${buffer}`, - localFileName: fileName, - localFileType: fileType, - count - } - ); - - if (typeof selector === "string") { - await page.dispatchEvent(selector, "drop", { dataTransfer }); - } else { - await selector.dispatchEvent("drop", { dataTransfer }); - } -}; - -export async function go_to_testcase( - page: Page, - _test_case: string -): Promise { - // With the new setup, each testcase launches its own Gradio app. - // The fixture detects the testcase from the test title and launches - // the correct app, so this function is now a no-op. - // The page is already at the correct testcase app. -} diff --git a/6.12.0/tootils/src/render.ts b/6.12.0/tootils/src/render.ts deleted file mode 100644 index 60bc02a263f3b8f2c32ef9b0cef57c0396a0fb21..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/render.ts +++ /dev/null @@ -1,314 +0,0 @@ -import { - getQueriesForElement, - prettyDOM, - fireEvent as dtlFireEvent -} from "@testing-library/dom"; -import { tick, mount, unmount } from "svelte"; -import type { SvelteComponent, Component } from "svelte"; - -import type { - queries, - Queries, - BoundFunction, - EventType -} from "@testing-library/dom"; -import { vi, type Mock } from "vitest"; -import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils"; -import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker"; -import { _ } from "svelte-i18n"; - -const containerCache = new Map(); -const componentCache = new Set(); - -type ComponentType = Component; - -export type RenderResult< - C extends SvelteComponent, - Q extends Queries = typeof queries -> = { - container: HTMLElement; - component: C; - debug: (el?: HTMLElement | DocumentFragment) => void; - unmount: () => void; -} & { [P in keyof Q]: BoundFunction }; -export interface ILoadingStatus { - eta: number | null; - status: "pending" | "error" | "complete" | "generating" | "streaming"; - queue: boolean; - queue_position: number | null; - queue_size?: number; - fn_index: number; - message?: string | null; - scroll_to_output?: boolean; - show_progress?: "full" | "minimal" | "hidden"; - time_limit?: number | null | undefined; - progress?: { - progress: number | null; - index: number | null; - length: number | null; - unit: string | null; - desc: string | null; - }[]; - validation_error?: string | null; - type: "input" | "output"; - stream_state: "open" | "closed" | "waiting" | null; -} - -const loading_status: ILoadingStatus = { - eta: 0, - queue_position: 1, - queue_size: 1, - queue: true, - message: null, - time_limit: null, - progress: [], - validation_error: null, - type: "output", - stream_state: null, - status: "complete" as ILoadingStatus["status"], - scroll_to_output: false, - fn_index: 0, - show_progress: "full" as ILoadingStatus["show_progress"] -}; - -export interface RenderOptions { - container?: HTMLElement; - queries?: Q; -} - -export async function render< - Events extends Record, - Props extends Record, - T extends SvelteComponent, - X extends Record ->( - Component: ComponentType | { default: ComponentType }, - props?: Omit & { - loading_status?: LoadingStatus; - }, - options?: { - container?: HTMLElement; - } -): Promise< - RenderResult & { - listen: (event_name: string, opts?: { retrospective?: boolean }) => Mock; - set_data: (data: Record) => Promise; - get_data: () => Promise>; - } -> { - let container: HTMLElement; - if (!options?.container) { - container = document.body; - } else { - container = options.container; - } - - const target = container.appendChild(document.createElement("div")); - - const ComponentConstructor: ComponentType = - //@ts-ignore - Component.default || Component; - - const id = Math.floor(Math.random() * 1000000); - - let component_set_data: (data: Record) => void; - let component_get_data: () => Promise>; - - const mock_register = ( - _id: number, - set_data: (data: Record) => void, - get_data: () => Promise> - ): void => { - component_set_data = set_data; - component_get_data = get_data; - }; - - const event_listeners = new Map void>>(); - const event_buffer: Array<{ event: string; data: any }> = []; - - function notify_listeners(event: string, data: any): void { - const listeners = event_listeners.get(event); - if (listeners) { - for (const listener of listeners) { - listener(data); - } - } - } - - const dispatcher = (_id: number, event: string, data: any): void => { - event_buffer.push({ event, data }); - notify_listeners(event, data); - }; - - function listen( - event_name: string, - opts?: { retrospective?: boolean } - ): Mock { - const fn = vi.fn(); - if (!event_listeners.has(event_name)) { - event_listeners.set(event_name, new Set()); - } - event_listeners.get(event_name)!.add(fn); - - if (opts?.retrospective) { - for (const entry of event_buffer) { - if (entry.event === event_name) { - fn(entry.data); - } - } - } - - return fn; - } - - const i18nFormatter = (s: string | null | undefined): string => s ?? ""; - - const shared_props_obj: Record = { - id, - target, - theme_mode: "light" as const, - version: "2.0.0", - formatter: i18nFormatter, - client: {} as any, - load_component: () => Promise.resolve({ default: {} as any }), - show_progress: true, - api_prefix: "", - server: {} as any, - show_label: true, - register_component: mock_register, - dispatcher - }; - - const component_props_obj: Record = { - i18n: i18nFormatter - }; - - if (props) { - for (const key in props) { - const value = (props as any)[key]; - if (allowed_shared_props.includes(key as any)) { - shared_props_obj[key] = value; - } else { - component_props_obj[key] = value; - } - } - } - - shared_props_obj.loading_status = props?.loading_status - ? props.loading_status - : loading_status; - - const componentProps = { - shared_props: shared_props_obj, - props: { - ...component_props_obj - }, - ...shared_props_obj - }; - - const component = mount(ComponentConstructor, { - target, - props: componentProps - }) as T; - - containerCache.set(container, { target, component }); - componentCache.add(component); - - await tick(); - - return { - container, - component, - listen, - set_data: async (data: Record) => { - const r = component_set_data(data); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return r; - }, - get_data: () => component_get_data(), - //@ts-ignore - debug: (el = container): void => console.warn(prettyDOM(el)), - unmount: (): void => { - if (componentCache.has(component)) { - unmount(component); - } - }, - ...getQueriesForElement(container) - }; -} - -const cleanupAtContainer = (container: HTMLElement): void => { - const { target, component } = containerCache.get(container); - - if (componentCache.has(component)) { - unmount(component); - } - - if (target.parentNode === document.body) { - document.body.removeChild(target); - } - - containerCache.delete(container); -}; - -export function cleanup(): void { - Array.from(containerCache.keys()).forEach(cleanupAtContainer); - document.body.innerHTML = ""; -} - -type AsyncFireObject = { - [K in EventType]: ( - element: Document | Element | Window | Node, - options?: object - ) => Promise; -}; - -export const fireEvent = Object.keys(dtlFireEvent).reduce((acc, key) => { - const _key = key as EventType; - return { - ...acc, - [_key]: async ( - element: Document | Element | Window, - options: object = {} - ): Promise => { - const event = dtlFireEvent[_key](element, options); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return event; - } - }; -}, {} as AsyncFireObject); - -export type FireFunction = ( - element: Document | Element | Window, - event: Event -) => Promise; - -export { download_file, upload_file, drop_file } from "./download.js"; - -/** - * Creates a mock client suitable for components that use file uploads. - * The upload mock echoes back the input FileData unchanged. - */ -export function mock_client(): Record { - return { - upload: async (file_data: any[]) => file_data, - stream: async () => ({ onmessage: null, close: () => {} }) - }; -} -export { - TEST_TXT, - TEST_JPG, - TEST_PNG, - TEST_MP4, - TEST_WAV, - TEST_PDF -} from "./fixtures.js"; -export * from "@testing-library/dom"; diff --git a/6.12.0/tootils/src/shared-prop-tests.ts b/6.12.0/tootils/src/shared-prop-tests.ts deleted file mode 100644 index b8f58e68a13e368fd4a1f1d6f2e246260b82bcd0..0000000000000000000000000000000000000000 --- a/6.12.0/tootils/src/shared-prop-tests.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, test, expect, afterEach } from "vitest"; -import { render, cleanup } from "./render"; - -const loading_status = { - status: "complete", - queue_position: null, - queue_size: null, - eta: null, - message: null -}; - -export interface SharedPropTestConfig { - /** The Svelte component to test */ - component: any; - /** Minimum props required to render the component without errors */ - base_props: Record; - /** Display name for test output */ - name: string; - /** - * Some components don't render labels (e.g. HTML, Markdown). - * Set to false to skip label-related tests. - * @default true - */ - has_label?: boolean; - /** - * Whether the component renders validation_error text. - * Not all components support this. Set to false to skip. - * @default true - */ - has_validation_error?: boolean; - /** - * Some components (e.g. Accordion) map visible=false to "hidden" - * instead of removing from the DOM. Set to true to expect hidden - * behaviour rather than removal. - * @default false - */ - visible_false_hides?: boolean; - /** - * Whether the component is wrapped in a Block (which renders a `.block` - * element). Components like Button render a bare element instead. - * Set to false to skip `.block` selector checks. - * @default true - */ - has_block_wrapper?: boolean; -} - -export function run_shared_prop_tests(config: SharedPropTestConfig): void { - const { - component, - base_props, - name, - has_label = true, - has_validation_error = true, - visible_false_hides = false, - has_block_wrapper = true - } = config; - - const label = "Test Label"; - - function make_props( - overrides: Record = {} - ): Record { - return { - ...base_props, - loading_status: { ...loading_status, ...overrides }, - label, - ...overrides - }; - } - - describe(`${name}: shared props`, () => { - afterEach(() => cleanup()); - - test("elem_id is applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_id: "my-test-id" }) - ); - const el = container.querySelector("#my-test-id"); - expect(el).not.toBeNull(); - }); - - test("elem_classes are applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_classes: ["my-test-class"] }) - ); - const el = container.querySelector(".my-test-class"); - expect(el).not.toBeNull(); - }); - - test("visible: true renders the component", async () => { - const { container } = await render( - component, - make_props({ visible: true, elem_id: "visible-test" }) - ); - const el = has_block_wrapper - ? container.querySelector(".block") - : container.querySelector("#visible-test"); - expect(el).not.toBeNull(); - }); - - test("visible: 'hidden' hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: "hidden", elem_id: "hidden-test" }) - ); - - const el = result.container.querySelector("#hidden-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - - if (visible_false_hides) { - test("visible: false hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - } else { - test("visible: false removes the component from the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).toBeNull(); - }); - } - - if (has_label) { - test("label text is rendered", async () => { - const result = await render( - component, - make_props({ label: "My Custom Label", show_label: true }) - ); - const el = result.getByText("My Custom Label"); - expect(el).toBeTruthy(); - }); - - test("show_label: true makes the label visible", async () => { - const result = await render( - component, - make_props({ label: "Visible Label", show_label: true }) - ); - const el = result.getByText("Visible Label"); - expect(el).toBeVisible(); - }); - - test("show_label: false hides the label visually but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ label: "Hidden Label", show_label: false }) - ); - const el = result.getByText("Hidden Label"); - // The label remains in the DOM for screen readers via sr-only. - // sr-only uses clip/1px dimensions rather than display:none, - // so toBeVisible() won't catch it. We check the class directly. - expect(el.closest("[data-testid='block-info']")).toHaveClass("sr-only"); - }); - } - - if (has_validation_error) { - test("validation_error displays error text visibly", async () => { - const result = await render( - component, - make_props({ - validation_error: "This field is required", - show_validation_error: true - }) - ); - const el = result.getByText("This field is required"); - expect(el).toBeVisible(); - }); - } - }); -} diff --git a/6.12.0/upload/package.json b/6.12.0/upload/package.json deleted file mode 100644 index ca17ce703ff779d7a44d90c69f2df20161e2b463..0000000000000000000000000000000000000000 --- a/6.12.0/upload/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@gradio/upload", - "version": "0.17.8", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/upload" - } -} diff --git a/6.12.0/upload/src/ModifyUpload.svelte b/6.12.0/upload/src/ModifyUpload.svelte deleted file mode 100644 index 7c8db47405576b3b590d9bcb394d5e5848f7e240..0000000000000000000000000000000000000000 --- a/6.12.0/upload/src/ModifyUpload.svelte +++ /dev/null @@ -1,61 +0,0 @@ - - - - {#if editable} - onedit?.()} - /> - {/if} - - {#if undoable} - onundo?.()} - /> - {/if} - - {#if download} - - - - {/if} - - {#if children}{@render children()}{/if} - - { - onclear?.(); - event.stopPropagation(); - }} - /> - diff --git a/6.12.0/upload/src/Upload.svelte b/6.12.0/upload/src/Upload.svelte deleted file mode 100644 index 27183d59b8604ce79d9e90d44269ffb32bdb7225..0000000000000000000000000000000000000000 --- a/6.12.0/upload/src/Upload.svelte +++ /dev/null @@ -1,398 +0,0 @@ - - -{#if filetype === "clipboard"} - -{:else if uploading && show_progress} - {#if !hidden} - - {/if} -{:else} - -{/if} - - diff --git a/6.12.0/upload/src/UploadProgress.svelte b/6.12.0/upload/src/UploadProgress.svelte deleted file mode 100644 index 0ee9995f6d036d79048aca2705d530d3453ae7a1..0000000000000000000000000000000000000000 --- a/6.12.0/upload/src/UploadProgress.svelte +++ /dev/null @@ -1,199 +0,0 @@ - - -
- Uploading {files_with_progress.length} - {files_with_progress.length > 1 ? "files" : "file"}... - - {#if file_to_display} -
- -
- {getProgress(file_to_display)} -
-
- - {file_to_display.orig_name} - -
- {/if} -
- - diff --git a/6.12.0/upload/src/index.ts b/6.12.0/upload/src/index.ts deleted file mode 100644 index 0c2bdb5d7b2eb9c39953af027ae57cc674a0e377..0000000000000000000000000000000000000000 --- a/6.12.0/upload/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Upload } from "./Upload.svelte"; -export { default as ModifyUpload } from "./ModifyUpload.svelte"; -export { default as UploadProgress } from "./UploadProgress.svelte"; -export { create_drag } from "./utils"; diff --git a/6.12.0/upload/src/utils.ts b/6.12.0/upload/src/utils.ts deleted file mode 100644 index e961b85f75d154896c4be1656ed4e383bae0305b..0000000000000000000000000000000000000000 --- a/6.12.0/upload/src/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -interface DragActionOptions { - disable_click?: boolean; - accepted_types?: string | string[] | null; - mode?: "single" | "multiple" | "directory"; - on_drag_change?: (dragging: boolean) => void; - on_files?: (files: File[]) => void; -} - -type ActionReturn = { - update: (new_options: DragActionOptions) => void; - destroy: () => void; -}; - -export function create_drag(): { - drag: (node: HTMLElement, options: DragActionOptions) => ActionReturn; - open_file_upload: () => void; -} { - let hidden_input: HTMLInputElement; - let _options: DragActionOptions; - return { - drag( - node: HTMLElement, - options: DragActionOptions = {} - ): { - update: (new_options: DragActionOptions) => void; - destroy: () => void; - } { - _options = options; - - // Create and configure hidden file input - function setup_hidden_input(): void { - hidden_input = document.createElement("input"); - hidden_input.type = "file"; - hidden_input.style.display = "none"; - hidden_input.setAttribute("aria-label", "File upload"); - hidden_input.setAttribute("data-testid", "file-upload"); - const accept_options = Array.isArray(_options.accepted_types) - ? _options.accepted_types.join(",") - : _options.accepted_types || undefined; - - if (accept_options) { - hidden_input.accept = accept_options; - } - - hidden_input.multiple = _options.mode === "multiple" || false; - if (_options.mode === "directory") { - hidden_input.webkitdirectory = true; - hidden_input.setAttribute("directory", ""); - hidden_input.setAttribute("mozdirectory", ""); - } - node.appendChild(hidden_input); - } - - setup_hidden_input(); - - function handle_drag(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - } - - function handle_drag_enter(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(true); - } - - function handle_drag_leave(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - } - - function handle_drop(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - - if (!e.dataTransfer?.files) return; - const files = Array.from(e.dataTransfer.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - - function handle_click(): void { - if (!_options.disable_click) { - hidden_input.value = ""; - hidden_input.click(); - } - } - - function handle_file_input_change(): void { - if (hidden_input.files) { - const files = Array.from(hidden_input.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - } - - // Add all event listeners - node.addEventListener("drag", handle_drag); - node.addEventListener("dragstart", handle_drag); - node.addEventListener("dragend", handle_drag); - node.addEventListener("dragover", handle_drag); - node.addEventListener("dragenter", handle_drag_enter); - node.addEventListener("dragleave", handle_drag_leave); - node.addEventListener("drop", handle_drop); - node.addEventListener("click", handle_click); - hidden_input!.addEventListener("change", handle_file_input_change); - - return { - update(new_options: DragActionOptions) { - _options = new_options; - // Recreate hidden input with new options - hidden_input.remove(); - setup_hidden_input(); - hidden_input.addEventListener("change", handle_file_input_change); - }, - destroy() { - node.removeEventListener("drag", handle_drag); - node.removeEventListener("dragstart", handle_drag); - node.removeEventListener("dragend", handle_drag); - node.removeEventListener("dragover", handle_drag); - node.removeEventListener("dragenter", handle_drag_enter); - node.removeEventListener("dragleave", handle_drag_leave); - node.removeEventListener("drop", handle_drop); - node.removeEventListener("click", handle_click); - hidden_input.removeEventListener("change", handle_file_input_change); - hidden_input.remove(); - } - }; - }, - open_file_upload(): void { - if (hidden_input) { - hidden_input.value = ""; - hidden_input.click(); - } - } - }; -} diff --git a/6.12.0/uploadbutton/Index.svelte b/6.12.0/uploadbutton/Index.svelte deleted file mode 100644 index f246c8f96ea948a81cd7bcd7a2412b089ebbaea1..0000000000000000000000000000000000000000 --- a/6.12.0/uploadbutton/Index.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - gradio.dispatch("click")} - onchange={(detail) => handle_event(detail, "change")} - onupload={(detail) => handle_event(detail, "upload")} - onerror={(detail) => { - gradio.dispatch("error", detail); - }} - upload={(...args) => gradio.shared.client.upload(...args)} -> - {gradio.shared.label ?? ""} - diff --git a/6.12.0/uploadbutton/package.json b/6.12.0/uploadbutton/package.json deleted file mode 100644 index 657726b0534b1c5731cdf917e9d630aa45093a12..0000000000000000000000000000000000000000 --- a/6.12.0/uploadbutton/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@gradio/uploadbutton", - "version": "0.9.18", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "main": "./Index.svelte", - "dependencies": { - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/uploadbutton" - } -} diff --git a/6.12.0/uploadbutton/shared/UploadButton.svelte b/6.12.0/uploadbutton/shared/UploadButton.svelte deleted file mode 100644 index 3cb3b534036b7d1fa652fddd293a00c4f5687e03..0000000000000000000000000000000000000000 --- a/6.12.0/uploadbutton/shared/UploadButton.svelte +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - {#if icon} - {`${value} - {/if} - {#if children}{@render children()}{/if} - - - diff --git a/6.12.0/uploadbutton/types.ts b/6.12.0/uploadbutton/types.ts deleted file mode 100644 index 100547b8f9293f9cd2a191b09a6003e7f071a585..0000000000000000000000000000000000000000 --- a/6.12.0/uploadbutton/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface UploadButtonProps { - value: null | FileData | FileData[]; - file_count: string; - file_types: string[]; - size: "sm" | "lg"; - icon: FileData | null; - variant: "primary" | "secondary" | "stop"; -} - -export interface UploadButtonEvents { - change: never; - upload: never; - click: never; - error: string; -} diff --git a/6.12.0/utils/package.json b/6.12.0/utils/package.json deleted file mode 100644 index 97e34911592ce8b15a54ea071d740237220295dc..0000000000000000000000000000000000000000 --- a/6.12.0/utils/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@gradio/utils", - "version": "0.12.2", - "description": "Gradio UI packages", - "type": "module", - "main": "./src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/theme": "workspace:^", - "svelte-i18n": "^4.0.1" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/utils" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.12.0/utils/src/color.ts b/6.12.0/utils/src/color.ts deleted file mode 100644 index 86d3fe6a5c35c450cc6517b5f3d4767ffda1bc2c..0000000000000000000000000000000000000000 --- a/6.12.0/utils/src/color.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { colors, ordered_colors } from "@gradio/theme"; - -export const get_next_color = (index: number): keyof typeof colors => { - return ordered_colors[index % ordered_colors.length]; -}; diff --git a/6.12.0/utils/src/index.ts b/6.12.0/utils/src/index.ts deleted file mode 100644 index 8db07c80fcf3416332b4ec11d86c06a0fdfb7e74..0000000000000000000000000000000000000000 --- a/6.12.0/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./color.js"; -export * from "./utils.svelte.js"; -export * from "./types.js"; diff --git a/6.12.0/utils/src/types.ts b/6.12.0/utils/src/types.ts deleted file mode 100644 index 8dd47a49c34d6da4ce4328aa99f9fe563ecc7d89..0000000000000000000000000000000000000000 --- a/6.12.0/utils/src/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface CustomButton { - id: number; - value: string | null; - icon: FileData | null; -} diff --git a/6.12.0/utils/src/utils.svelte.ts b/6.12.0/utils/src/utils.svelte.ts deleted file mode 100644 index 1a7d54a3cfac850fd1dedcf10907105b157ade26..0000000000000000000000000000000000000000 --- a/6.12.0/utils/src/utils.svelte.ts +++ /dev/null @@ -1,575 +0,0 @@ -import type { ActionReturn } from "svelte/action"; -import type { Client } from "@gradio/client"; -import type { ComponentType, SvelteComponent } from "svelte"; -import { tick, untrack } from "svelte"; -import type { Component } from "svelte"; -import { locale } from "svelte-i18n"; - -export const I18N_MARKER = "__i18n__"; -const TRANSLATABLE_PROPS = [ - "label", - "info", - "placeholder", - "description", - "title", - "value" -]; - -export interface SharedProps { - elem_id?: string; - elem_classes: string[]; - components?: string[]; - server_fns?: string[]; - interactive: boolean; - visible: boolean | "hidden"; - id: number; - container: boolean; - target: HTMLElement; - theme_mode: "light" | "dark" | "system"; - version: string; - root: string; - autoscroll: boolean; - max_file_size: number | null; - formatter: any; //I18nFormatter; - client: Client; - scale: number; - min_width: number; - padding: number; - load_component: load_component; - loading_status?: any; - label: string; - show_label: boolean; - validation_error?: string | null; - theme?: "light" | "dark"; - show_progress: boolean; - api_prefix: string; - server: ServerFunctions; - attached_events?: string[]; - register_component: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - dispatcher: Function; -} - -export type LoadingComponent = Promise<{ - default: Component; -}>; - -export const GRADIO_ROOT = "GRADIO_ROOT"; - -export interface ValueData { - value: any; - is_value_data: boolean; -} - -export interface SelectData { - row_value?: any[]; - col_value?: any[]; - index: number | [number, number]; - value: any; - selected?: boolean; -} - -export interface LikeData { - index: number | [number, number]; - value: any; - liked?: boolean | string; -} - -export interface KeyUpData { - key: string; - input_value: string; -} - -export interface ShareData { - description: string; - title?: string; -} - -export interface CopyData { - value: string; -} - -export class ShareError extends Error { - constructor(message: string) { - super(message); - this.name = "ShareError"; - } -} - -export async function uploadToHuggingFace( - data: string | { url?: string; path?: string }, - type: "base64" | "url" -): Promise { - if (window.__gradio_space__ == null) { - throw new ShareError("Must be on Spaces to share."); - } - let blob: Blob; - let contentType: string; - let filename: string; - if (type === "url") { - let url: string; - - if (typeof data === "object" && data.url) { - url = data.url; - } else if (typeof data === "string") { - url = data; - } else { - throw new Error("Invalid data format for URL type"); - } - - const response = await fetch(url); - blob = await response.blob(); - contentType = response.headers.get("content-type") || ""; - filename = response.headers.get("content-disposition") || ""; - } else { - let dataurl: string; - - if (typeof data === "object" && data.path) { - dataurl = data.path; - } else if (typeof data === "string") { - dataurl = data; - } else { - throw new Error("Invalid data format for base64 type"); - } - - blob = dataURLtoBlob(dataurl); - contentType = dataurl.split(";")[0].split(":")[1]; - filename = "file." + contentType.split("/")[1]; - } - - const file = new File([blob], filename, { type: contentType }); - - // Send file to endpoint - const uploadResponse = await fetch("https://huggingface.co/uploads", { - method: "POST", - body: file, - headers: { - "Content-Type": file.type, - "X-Requested-With": "XMLHttpRequest" - } - }); - - // Check status of response - if (!uploadResponse.ok) { - if ( - uploadResponse.headers.get("content-type")?.includes("application/json") - ) { - const error = await uploadResponse.json(); - throw new ShareError(`Upload failed: ${error.error}`); - } - throw new ShareError(`Upload failed.`); - } - - // Return response if needed - const result = await uploadResponse.text(); - return result; -} - -function dataURLtoBlob(dataurl: string): Blob { - var arr = dataurl.split(","), - mime = (arr[0].match(/:(.*?);/) as RegExpMatchArray)[1], - bstr = atob(arr[1]), - n = bstr.length, - u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} - -export function copy(node: HTMLDivElement): ActionReturn { - node.addEventListener("click", handle_copy); - - async function handle_copy(event: MouseEvent): Promise { - const path = event.composedPath() as HTMLButtonElement[]; - - const [copy_button] = path.filter( - (e) => e?.tagName === "BUTTON" && e.classList.contains("copy_code_button") - ); - - if (copy_button) { - event.stopImmediatePropagation(); - - const copy_text = copy_button.parentElement!.innerText.trim(); - const copy_sucess_button = Array.from( - copy_button.children - )[1] as HTMLDivElement; - - const copied = await copy_to_clipboard(copy_text); - - if (copied) copy_feedback(copy_sucess_button); - - function copy_feedback(_copy_sucess_button: HTMLDivElement): void { - _copy_sucess_button.style.opacity = "1"; - setTimeout(() => { - _copy_sucess_button.style.opacity = "0"; - }, 2000); - } - } - } - - return { - destroy(): void { - node.removeEventListener("click", handle_copy); - } - }; -} - -async function copy_to_clipboard(value: string): Promise { - let copied = false; - if ("clipboard" in navigator) { - await navigator.clipboard.writeText(value); - copied = true; - } else { - const textArea = document.createElement("textarea"); - textArea.value = value; - - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - copied = true; - } catch (error) { - console.error(error); - copied = false; - } finally { - textArea.remove(); - } - } - - return copied; -} - -export const format_time = (seconds: number): string => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const seconds_remainder = Math.round(seconds) % 60; - const padded_minutes = `${minutes < 10 ? "0" : ""}${minutes}`; - const padded_seconds = `${ - seconds_remainder < 10 ? "0" : "" - }${seconds_remainder}`; - - if (hours > 0) { - return `${hours}:${padded_minutes}:${padded_seconds}`; - } - return `${minutes}:${padded_seconds}`; -}; - -interface Args { - api_url: string; - name: string; - id?: string; - variant: "component" | "example" | "base"; -} - -export type component_loader = (args: Args) => { - component: { - default: ComponentType; - }; -}; - -export type LoadedComponentWithRuntime = { - component: LoadingComponent; - runtime: false | typeof import("svelte"); -}; - -export type load_component = ( - name: string, - variant: "component" | "example" | "base", - component_class_id?: string -) => LoadedComponentWithRuntime; - -const is_browser = typeof window !== "undefined"; - -export type ServerFunctions = Record Promise>; - -export const allowed_shared_props: (keyof SharedProps)[] = [ - "elem_id", - "elem_classes", - "visible", - "interactive", - "server_fns", - "server", - "id", - "target", - "theme_mode", - "version", - "root", - "autoscroll", - "max_file_size", - "formatter", - "client", - "load_component", - "scale", - "min_width", - "theme", - "padding", - "loading_status", - "label", - "show_label", - "validation_error", - "show_progress", - "api_prefix", - "container", - "attached_events", - "register_component", - "dispatcher" -] as const; - -export type I18nFormatter = any; - -export function has_i18n_marker(value: unknown): value is string { - return typeof value === "string" && value.includes(I18N_MARKER); -} - -export function translate_i18n_marker( - value: string, - translate: (key: string) => string -): string { - const start = value.indexOf(I18N_MARKER); - if (start === -1) return value; - - const json_start = start + I18N_MARKER.length; - const json_end = value.indexOf("}", json_start) + 1; - if (json_end === 0) return value; - - try { - const metadata = JSON.parse(value.slice(json_start, json_end)); - if (metadata?.key) { - const translated = translate(metadata.key); - const result = translated !== metadata.key ? translated : metadata.key; - return value.slice(0, start) + result + value.slice(json_end); - } - } catch {} - - return value; -} - -export class Gradio { - load_component: load_component; - shared: SharedProps = $state({} as SharedProps) as SharedProps; - props = $state({} as U) as U; - i18n: I18nFormatter = $state((v: string) => v) as any; - translatable_props: Record = {}; - dispatcher!: Function; - last_update: ReturnType | null = null; - shared_props: (keyof SharedProps)[] = allowed_shared_props; - mounted: boolean = false; - old_value: any; - register_component!: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - - constructor( - _props: { shared_props: SharedProps; props: U }, - default_values?: Partial - ) { - for (const key in _props.shared_props) { - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - - if (default_values) { - for (const key in default_values) { - if (this.props[key as keyof U] === undefined) { - // @ts-ignore - this.props[key] = default_values[key as keyof U]; - } - } - } - // @ts-ignore same here - this.i18n = this.props.i18n ?? ((v: string) => v); - - for (const key of TRANSLATABLE_PROPS) { - // @ts-ignore - this.shared[key] = this._translate_and_store( - "shared", - key, - // @ts-ignore - _props.shared_props[key] - ); - // @ts-ignore - this.props[key] = this._translate_and_store( - "props", - key, - // @ts-ignore - _props.props[key] - ); - } - - this.load_component = this.shared.load_component; - - this.register_component = this.shared.register_component || (() => {}); - this.dispatcher = this.shared.dispatcher || (() => {}); - - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - - $effect(() => { - // Need to update the props here - // otherwise UI won't reflect latest state from render - for (const key in _props.shared_props) { - // @ts-ignore - if (this._is_i18n_managed(`shared.${key}`, _props.shared_props[key])) - continue; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - if (this._is_i18n_managed(`props.${key}`, _props.props[key])) continue; - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - untrack(() => { - this.shared.id = _props.shared_props.id; - }); - }); - - // retranslate props when locale changes - if (Object.keys(this.translatable_props).length > 0) { - locale.subscribe(() => { - for (const [full_key, original] of Object.entries( - this.translatable_props - )) { - const [target, key] = full_key.split("."); - const translated = this.i18n(original); - // @ts-ignore - if (target === "shared") this.shared[key] = translated; - // @ts-ignore - else this.props[key] = translated; - } - }); - } - } - - // check if props are translatable - _is_i18n_managed(key: string, new_value: unknown): boolean { - const original_marker = this.translatable_props[key]; - if (!original_marker) return false; - if (new_value === original_marker) return true; - // if value has changed then remove key - delete this.translatable_props[key]; - return false; - } - - _translate_and_store( - target: "shared" | "props", - key: string, - value: unknown - ): unknown { - if (typeof value !== "string") return value; - const translated = this.i18n(value); - if (translated !== value) { - this.translatable_props[`${target}.${key}`] = value; - } - return translated; - } - - dispatch(event_name: E, data?: T[E]): void { - this.dispatcher(this.shared.id, event_name, data); - } - - async get_data() { - return $state.snapshot(this.props); - } - - update(data: Partial): void { - this.set_data(data as U & SharedProps); - } - - set_data(data: Partial): void { - for (const key in data) { - // @ts-ignore - const value = data[key]; - const translated = has_i18n_marker(value) - ? this._translate_and_store( - this.shared_props.includes(key as keyof SharedProps) - ? "shared" - : "props", - key, - value - ) - : value; - - if (this.shared_props.includes(key as keyof SharedProps)) { - const _key = key as keyof SharedProps; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[_key] = translated; - continue; - } - // @ts-ignore - this.props[key] = translated; - } - } - - watch_for_change() { - $effect(() => { - if (!this.mounted) { - // @ts-ignore - this.old_value = this.props.value; - this.mounted = true; - } - // @ts-ignore - if (this.old_value != this.props.value) { - // @ts-ignore - this.old_value = this.props.value; - // @ts-ignore - this.dispatch("change"); - } - }); - } -} - -// function _load_component( -// this: Gradio, -// name: string, -// variant: "component" | "example" | "base" = "component" -// ): ReturnType { -// return this._load_component!({ -// name, -// api_url: this.shared.client.config?.root!, -// variant -// }); -// } - -export const css_units = (dimension_value: string | number): string => { - return typeof dimension_value === "number" - ? dimension_value + "px" - : dimension_value; -}; - -export function should_show_scroll_fade( - container: HTMLElement | null -): boolean { - if (!container) return false; - const has_overflow = container.scrollHeight > container.clientHeight; - const at_bottom = - container.scrollTop >= container.scrollHeight - container.clientHeight - 1; - return has_overflow && !at_bottom; -} - -type MappedProps = { [K in keyof T]: T[K] }; -type MappedProp = { [P in K]: T[P] }; diff --git a/6.12.0/vibeeditor/Index.svelte b/6.12.0/vibeeditor/Index.svelte deleted file mode 100644 index 6db9b3cb7167948ae0f14cabd9d66c791deb9e2d..0000000000000000000000000000000000000000 --- a/6.12.0/vibeeditor/Index.svelte +++ /dev/null @@ -1,764 +0,0 @@ - - -
- -
- - -
- -
- {#if activeTab === "chat"} -
- {#each message_history as message, index} -
-
- - - - {#if !message.isBot && message.hash && !message.isPending} - - {/if} -
-
- {/each} - - {#if message_history.length === 0} -
No messages yet
- {/if} - - {#if message_history.length === 0} -
-
- {#each starterQueries as query} - - {/each} -
-
- {/if} -
- {:else if activeTab === "code"} -
-
- -
- - -
- {/if} -
- -
-
Powered by: gpt-oss
- - {#if showTagMenu && currentLineIndex === i} -
- [s, i])} - filtered_indices={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )} - active_index={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )[selectedOptionIndex]} - show_options={true} - onchange={(e) => insert_tag(e)} - {offset_from_top} - from_top={true} - /> -
- {/if} -
-
- {#if gradio.props.max_lines == undefined || (gradio.props.max_lines && i < gradio.props.max_lines - 1)} -
- -
- {/if} -
- -
-
- {/each} -
- {:else if checked || gradio.props.ui_mode !== "dialogue"} -
- {#if is_formatting} -
-
-
Converting to plain text...
-
- {/if} - - {/if} - {#if submit_btn} - - {/if} - {#if stop_btn} - - {/if} -
- - - diff --git a/6.12.1/textbox/types.ts b/6.12.1/textbox/types.ts deleted file mode 100644 index 8ec1cfc945755962a887be7207b0f60290ad929a..0000000000000000000000000000000000000000 --- a/6.12.1/textbox/types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type SelectData, - type CopyData, - type CustomButton -} from "@gradio/utils"; -import type { LoadingStatus } from "@gradio/statustracker"; - -export interface TextboxEvents { - change: string; - submit: never; - blur: never; - select: SelectData; - input: never; - focus: never; - stop: never; - clear_status: LoadingStatus; - copy: CopyData; - custom_button_click: { id: number }; -} - -export interface TextboxProps { - value: string; - info: string; - lines: number; - type: "text" | "password" | "email" | undefined; - rtl: boolean; - text_align: "right" | "left"; - max_lines: number; - placeholder: string; - submit_btn: string; - stop_btn: string; - buttons: (string | CustomButton)[] | null; - autofocus: boolean; - autoscroll: boolean; - max_length: number; - html_attributes: InputHTMLAttributes; - validation_error: string | null; -} - -type FullAutoFill = - | AutoFill - | "bday" - | `${OptionalPrefixToken}${"cc-additional-name"}` - | "nickname" - | "language" - | "organization-title" - | "photo" - | "sex" - | "url"; - -export interface InputHTMLAttributes { - autocapitalize?: - | "off" - | "none" - | "on" - | "sentences" - | "words" - | "characters" - | null; - autocorrect?: "on" | "off" | null; - spellcheck?: boolean | null; - autocomplete?: FullAutoFill | undefined | null; - tabindex?: number | null; - enterkeyhint?: - | "enter" - | "done" - | "go" - | "next" - | "previous" - | "search" - | "send" - | null; - lang?: string | null; -} diff --git a/6.12.1/theme/package.json b/6.12.1/theme/package.json deleted file mode 100644 index bb4343fa73bdf0fe073c0d611292babaf9cc8d6b..0000000000000000000000000000000000000000 --- a/6.12.1/theme/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@gradio/theme", - "version": "0.6.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": false, - "scripts": { - "generate": "pollen -c src/pollen.config.mjs", - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./reset.css": { - "gradio": "./src/reset.css", - "import": "./dist/src/reset.css" - }, - "./global.css": { - "gradio": "./src/global.css", - "import": "./dist/src/global.css" - }, - "./tokens": { - "gradio": "./src/tokens.ts", - "import": "./dist/src/tokens.js" - }, - "./typography.css": { - "gradio": "./src/typography.css", - "import": "./dist/src/typography.css" - }, - "./gradio-style.scss": { - "gradio": "./src/gradio-style.scss", - "import": "./dist/src/gradio-style.scss" - }, - "./pollen.css": { - "gradio": "./src/pollen.css", - "import": "./dist/src/pollen.css" - }, - "./package.json": "./package.json" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/theme" - } -} diff --git a/6.12.1/theme/src/colors.ts b/6.12.1/theme/src/colors.ts deleted file mode 100644 index 04a9c9b33c631635832a8fb982ce1d29e0176fa7..0000000000000000000000000000000000000000 --- a/6.12.1/theme/src/colors.ts +++ /dev/null @@ -1,350 +0,0 @@ -// import tw_colors from "tailwindcss/colors"; - -export const ordered_colors = [ - "red", - "green", - "blue", - "yellow", - "purple", - "teal", - "orange", - "cyan", - "lime", - "pink" -] as const; -interface ColorPair { - primary: string; - secondary: string; -} - -interface Colors { - red: ColorPair; - green: ColorPair; - blue: ColorPair; - yellow: ColorPair; - purple: ColorPair; - teal: ColorPair; - orange: ColorPair; - cyan: ColorPair; - lime: ColorPair; - pink: ColorPair; -} - -// https://play.tailwindcss.com/ZubQYya0aN -export const color_values = [ - { color: "red", primary: 600, secondary: 100 }, - { color: "green", primary: 600, secondary: 100 }, - { color: "blue", primary: 600, secondary: 100 }, - { color: "yellow", primary: 500, secondary: 100 }, - { color: "purple", primary: 600, secondary: 100 }, - { color: "teal", primary: 600, secondary: 100 }, - { color: "orange", primary: 600, secondary: 100 }, - { color: "cyan", primary: 600, secondary: 100 }, - { color: "lime", primary: 500, secondary: 100 }, - { color: "pink", primary: 600, secondary: 100 } -] as const; - -const tw_colors = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - slate: { - 50: "#f8fafc", - 100: "#f1f5f9", - 200: "#e2e8f0", - 300: "#cbd5e1", - 400: "#94a3b8", - 500: "#64748b", - 600: "#475569", - 700: "#334155", - 800: "#1e293b", - 900: "#0f172a", - 950: "#020617" - }, - gray: { - 50: "#f9fafb", - 100: "#f3f4f6", - 200: "#e5e7eb", - 300: "#d1d5db", - 400: "#9ca3af", - 500: "#6b7280", - 600: "#4b5563", - 700: "#374151", - 800: "#1f2937", - 900: "#111827", - 950: "#030712" - }, - zinc: { - 50: "#fafafa", - 100: "#f4f4f5", - 200: "#e4e4e7", - 300: "#d4d4d8", - 400: "#a1a1aa", - 500: "#71717a", - 600: "#52525b", - 700: "#3f3f46", - 800: "#27272a", - 900: "#18181b", - 950: "#09090b" - }, - neutral: { - 50: "#fafafa", - 100: "#f5f5f5", - 200: "#e5e5e5", - 300: "#d4d4d4", - 400: "#a3a3a3", - 500: "#737373", - 600: "#525252", - 700: "#404040", - 800: "#262626", - 900: "#171717", - 950: "#0a0a0a" - }, - stone: { - 50: "#fafaf9", - 100: "#f5f5f4", - 200: "#e7e5e4", - 300: "#d6d3d1", - 400: "#a8a29e", - 500: "#78716c", - 600: "#57534e", - 700: "#44403c", - 800: "#292524", - 900: "#1c1917", - 950: "#0c0a09" - }, - red: { - 50: "#fef2f2", - 100: "#fee2e2", - 200: "#fecaca", - 300: "#fca5a5", - 400: "#f87171", - 500: "#ef4444", - 600: "#dc2626", - 700: "#b91c1c", - 800: "#991b1b", - 900: "#7f1d1d", - 950: "#450a0a" - }, - orange: { - 50: "#fff7ed", - 100: "#ffedd5", - 200: "#fed7aa", - 300: "#fdba74", - 400: "#fb923c", - 500: "#f97316", - 600: "#ea580c", - 700: "#c2410c", - 800: "#9a3412", - 900: "#7c2d12", - 950: "#431407" - }, - amber: { - 50: "#fffbeb", - 100: "#fef3c7", - 200: "#fde68a", - 300: "#fcd34d", - 400: "#fbbf24", - 500: "#f59e0b", - 600: "#d97706", - 700: "#b45309", - 800: "#92400e", - 900: "#78350f", - 950: "#451a03" - }, - yellow: { - 50: "#fefce8", - 100: "#fef9c3", - 200: "#fef08a", - 300: "#fde047", - 400: "#facc15", - 500: "#eab308", - 600: "#ca8a04", - 700: "#a16207", - 800: "#854d0e", - 900: "#713f12", - 950: "#422006" - }, - lime: { - 50: "#f7fee7", - 100: "#ecfccb", - 200: "#d9f99d", - 300: "#bef264", - 400: "#a3e635", - 500: "#84cc16", - 600: "#65a30d", - 700: "#4d7c0f", - 800: "#3f6212", - 900: "#365314", - 950: "#1a2e05" - }, - green: { - 50: "#f0fdf4", - 100: "#dcfce7", - 200: "#bbf7d0", - 300: "#86efac", - 400: "#4ade80", - 500: "#22c55e", - 600: "#16a34a", - 700: "#15803d", - 800: "#166534", - 900: "#14532d", - 950: "#052e16" - }, - emerald: { - 50: "#ecfdf5", - 100: "#d1fae5", - 200: "#a7f3d0", - 300: "#6ee7b7", - 400: "#34d399", - 500: "#10b981", - 600: "#059669", - 700: "#047857", - 800: "#065f46", - 900: "#064e3b", - 950: "#022c22" - }, - teal: { - 50: "#f0fdfa", - 100: "#ccfbf1", - 200: "#99f6e4", - 300: "#5eead4", - 400: "#2dd4bf", - 500: "#14b8a6", - 600: "#0d9488", - 700: "#0f766e", - 800: "#115e59", - 900: "#134e4a", - 950: "#042f2e" - }, - cyan: { - 50: "#ecfeff", - 100: "#cffafe", - 200: "#a5f3fc", - 300: "#67e8f9", - 400: "#22d3ee", - 500: "#06b6d4", - 600: "#0891b2", - 700: "#0e7490", - 800: "#155e75", - 900: "#164e63", - 950: "#083344" - }, - sky: { - 50: "#f0f9ff", - 100: "#e0f2fe", - 200: "#bae6fd", - 300: "#7dd3fc", - 400: "#38bdf8", - 500: "#0ea5e9", - 600: "#0284c7", - 700: "#0369a1", - 800: "#075985", - 900: "#0c4a6e", - 950: "#082f49" - }, - blue: { - 50: "#eff6ff", - 100: "#dbeafe", - 200: "#bfdbfe", - 300: "#93c5fd", - 400: "#60a5fa", - 500: "#3b82f6", - 600: "#2563eb", - 700: "#1d4ed8", - 800: "#1e40af", - 900: "#1e3a8a", - 950: "#172554" - }, - indigo: { - 50: "#eef2ff", - 100: "#e0e7ff", - 200: "#c7d2fe", - 300: "#a5b4fc", - 400: "#818cf8", - 500: "#6366f1", - 600: "#4f46e5", - 700: "#4338ca", - 800: "#3730a3", - 900: "#312e81", - 950: "#1e1b4b" - }, - violet: { - 50: "#f5f3ff", - 100: "#ede9fe", - 200: "#ddd6fe", - 300: "#c4b5fd", - 400: "#a78bfa", - 500: "#8b5cf6", - 600: "#7c3aed", - 700: "#6d28d9", - 800: "#5b21b6", - 900: "#4c1d95", - 950: "#2e1065" - }, - purple: { - 50: "#faf5ff", - 100: "#f3e8ff", - 200: "#e9d5ff", - 300: "#d8b4fe", - 400: "#c084fc", - 500: "#a855f7", - 600: "#9333ea", - 700: "#7e22ce", - 800: "#6b21a8", - 900: "#581c87", - 950: "#3b0764" - }, - fuchsia: { - 50: "#fdf4ff", - 100: "#fae8ff", - 200: "#f5d0fe", - 300: "#f0abfc", - 400: "#e879f9", - 500: "#d946ef", - 600: "#c026d3", - 700: "#a21caf", - 800: "#86198f", - 900: "#701a75", - 950: "#4a044e" - }, - pink: { - 50: "#fdf2f8", - 100: "#fce7f3", - 200: "#fbcfe8", - 300: "#f9a8d4", - 400: "#f472b6", - 500: "#ec4899", - 600: "#db2777", - 700: "#be185d", - 800: "#9d174d", - 900: "#831843", - 950: "#500724" - }, - rose: { - 50: "#fff1f2", - 100: "#ffe4e6", - 200: "#fecdd3", - 300: "#fda4af", - 400: "#fb7185", - 500: "#f43f5e", - 600: "#e11d48", - 700: "#be123c", - 800: "#9f1239", - 900: "#881337", - 950: "#4c0519" - } -}; - -export const colors = color_values.reduce( - (acc, { color, primary, secondary }) => ({ - ...acc, - [color]: { - primary: tw_colors[color][primary], - secondary: tw_colors[color][secondary] - } - }), - {} as Colors -); diff --git a/6.12.1/theme/src/index.ts b/6.12.1/theme/src/index.ts deleted file mode 100644 index bd1cb299eaa9b1ae2f6bd0c1973fa12d0c4cdb57..0000000000000000000000000000000000000000 --- a/6.12.1/theme/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// export { default as reset } from "./reset.css"; -// export { default as global } from "./global.css"; -// export { default as css } from "./pollen.css"; -// export { default as typography } from "./typography.css"; - -export * from "./colors.js"; diff --git a/6.12.1/timer/Index.svelte b/6.12.1/timer/Index.svelte deleted file mode 100644 index 7fc7857ad7235b62c97ffb4fccba78a6c9d89fd9..0000000000000000000000000000000000000000 --- a/6.12.1/timer/Index.svelte +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/6.12.1/timer/package.json b/6.12.1/timer/package.json deleted file mode 100644 index 69e4fd022b1204bf416a79f66fbf6f1c0e859744..0000000000000000000000000000000000000000 --- a/6.12.1/timer/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@gradio/timer", - "version": "0.4.9", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "dependencies": { - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/timer" - } -} diff --git a/6.12.1/timer/types.ts b/6.12.1/timer/types.ts deleted file mode 100644 index 292d729b4daf9b93f8261167f14496b64a103084..0000000000000000000000000000000000000000 --- a/6.12.1/timer/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimerProps { - value: number; - active: boolean; -} - -export interface TimerEvents { - tick: never; - clear_status: never; -} diff --git a/6.12.1/tooltip/package.json b/6.12.1/tooltip/package.json deleted file mode 100644 index 1b699440866a7a7c79de9e7575bc07b5373465fe..0000000000000000000000000000000000000000 --- a/6.12.1/tooltip/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@gradio/tooltip", - "version": "0.2.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/tooltip" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.js", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - } -} diff --git a/6.12.1/tooltip/src/Tooltip.svelte b/6.12.1/tooltip/src/Tooltip.svelte deleted file mode 100644 index c9c9ecca6357234953144bcf6a0dbe7ee5e822de..0000000000000000000000000000000000000000 --- a/6.12.1/tooltip/src/Tooltip.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - {text} -
- - diff --git a/6.12.1/tooltip/src/index.ts b/6.12.1/tooltip/src/index.ts deleted file mode 100644 index b89ac870e5bbf6d90058c6e25cb9d74b626b3809..0000000000000000000000000000000000000000 --- a/6.12.1/tooltip/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { tooltip } from "./tooltip"; diff --git a/6.12.1/tooltip/src/tooltip.ts b/6.12.1/tooltip/src/tooltip.ts deleted file mode 100644 index 09403f9438805f29a32579b8e98a25f3aae37737..0000000000000000000000000000000000000000 --- a/6.12.1/tooltip/src/tooltip.ts +++ /dev/null @@ -1,49 +0,0 @@ -import Tooltip from "./Tooltip.svelte"; - -interface ActionArgs { - color: string; - text: string; -} - -export function tooltip( - element: HTMLElement | SVGElement, - { color, text }: ActionArgs -): any { - let tooltipComponent: Tooltip; - function mouse_over(event: MouseEvent): MouseEvent { - tooltipComponent = new Tooltip({ - props: { - text, - x: event.pageX, - y: event.pageY, - color - }, - target: document.body - }); - - return event; - } - function mouseMove(event: MouseEvent): void { - tooltipComponent.$set({ - x: event.pageX, - y: event.pageY - }); - } - function mouseLeave(): void { - tooltipComponent.$destroy(); - } - - const el = element as HTMLElement; - - el.addEventListener("mouseover", mouse_over); - el.addEventListener("mouseleave", mouseLeave); - el.addEventListener("mousemove", mouseMove); - - return { - destroy() { - el.removeEventListener("mouseover", mouse_over); - el.removeEventListener("mouseleave", mouseLeave); - el.removeEventListener("mousemove", mouseMove); - } - }; -} diff --git a/6.12.1/tootils/package.json b/6.12.1/tootils/package.json deleted file mode 100644 index 39683201d83bfc3a5ffaeb655426076b27f40944..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@self/tootils", - "version": "0.13.0", - "description": "Internal test utilities", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": "./src/index.ts", - "./render": "./src/render.ts", - "./shared-prop-tests": "./src/shared-prop-tests.ts", - "./app-launcher": "./src/app-launcher.ts", - "./download-command": "./src/download-command.ts" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.12.1/tootils/src/app-launcher.ts b/6.12.1/tootils/src/app-launcher.ts deleted file mode 100644 index a320667e5764ec306dec64eabbfa998bdd85169c..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/app-launcher.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { spawn, type ChildProcess } from "node:child_process"; -import http from "http"; -import net from "net"; -import path from "path"; -import fs from "fs"; -import os from "os"; -import url from "url"; - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -const ROOT_DIR = path.resolve(__dirname, "../../.."); - -export interface GradioApp { - port: number; - process: ChildProcess; -} - -export function killGradioApp(process: ChildProcess): void { - try { - process.kill("SIGTERM"); - } catch { - // Process may already be dead - } -} - -export async function findFreePort( - startPort: number, - endPort: number -): Promise { - for (let port = startPort; port < endPort; port++) { - if (await isPortFree(port)) { - return port; - } - } - throw new Error(`Could not find free port in range ${startPort}-${endPort}`); -} - -function isPortFree(port: number): Promise { - return new Promise((resolve, reject) => { - const sock = net.createConnection(port, "127.0.0.1"); - sock.once("connect", () => { - sock.end(); - resolve(false); - }); - sock.once("error", (e: NodeJS.ErrnoException) => { - sock.destroy(); - if (e.code === "ECONNREFUSED") { - resolve(true); - } else { - reject(e); - } - }); - }); -} - -/** - * Poll the server with HTTP GET requests until it returns a response. - * Gradio prints "Running on local URL:" before the server is fully ready, - * so we need to verify it actually responds to HTTP requests. - */ -async function waitForServerReady( - port: number, - timeoutMs: number = 15000 -): Promise { - const start = Date.now(); - const pollInterval = 200; - - while (Date.now() - start < timeoutMs) { - try { - await new Promise((resolve, reject) => { - // Use HEAD on /gradio_api/info to avoid triggering SSR rendering on - // the root URL, which could block Gradio's own startup health check. - const req = http.request( - `http://127.0.0.1:${port}/gradio_api/info`, - { method: "HEAD", timeout: 2000 }, - (res) => { - res.resume(); // drain the response - resolve(); - } - ); - req.on("error", reject); - req.on("timeout", () => { - req.destroy(); - reject(new Error("request timeout")); - }); - req.end(); - }); - return; // Server responded successfully - } catch { - // Server not ready yet, wait and retry - await new Promise((r) => setTimeout(r, pollInterval)); - } - } - throw new Error( - `Server on port ${port} did not become ready within ${timeoutMs}ms` - ); -} - -export function getTestcases(demoName: string): string[] { - const demoDir = path.join(ROOT_DIR, "demo", demoName); - if (!fs.existsSync(demoDir)) { - return []; - } - - return fs - .readdirSync(demoDir) - .filter((f) => f.endsWith("_testcase.py")) - .map((f) => path.basename(f, ".py")); -} - -// Check if a testcase file exists for this demo -export function hasTestcase(demoName: string, testcaseName: string): boolean { - const testcaseFile = path.join( - ROOT_DIR, - "demo", - demoName, - `${testcaseName}_testcase.py` - ); - return fs.existsSync(testcaseFile); -} - -// Get the path to a demo's Python file -function getDemoFilePath(demoName: string, testcaseName?: string): string { - if (testcaseName) { - return path.join(ROOT_DIR, "demo", demoName, `${testcaseName}_testcase.py`); - } - return path.join(ROOT_DIR, "demo", demoName, "run.py"); -} - -export async function launchGradioApp( - demoName: string, - workerIndex: number = 0, - timeout: number = 60000, - testcaseName?: string -): Promise { - // Partition ports by worker index to avoid collisions - const basePort = 7860 + workerIndex * 100; - const port = await findFreePort(basePort, basePort + 99); - - // Get the path to the demo file - const demoFilePath = getDemoFilePath(demoName, testcaseName); - - // Create unique directories for this instance to avoid cache conflicts - const instanceId = testcaseName - ? `${demoName}_${testcaseName}_${port}` - : `${demoName}_${port}`; - const instanceDir = path.join(os.tmpdir(), `gradio_test_${instanceId}`); - const cacheDir = path.join(instanceDir, "cached_examples"); - const tempDir = path.join(instanceDir, "temp"); - - if (!fs.existsSync(instanceDir)) { - fs.mkdirSync(instanceDir, { recursive: true }); - } - - // Run the demo file directly - the demo's own if __name__ == "__main__" block - // has the correct launch parameters (show_error, etc.) - const childProcess = spawn("python", [demoFilePath], { - stdio: "pipe", - cwd: ROOT_DIR, - env: { - ...process.env, - PYTHONUNBUFFERED: "true", - GRADIO_ANALYTICS_ENABLED: "False", - GRADIO_IS_E2E_TEST: "1", - GRADIO_RESET_EXAMPLES_CACHE: "True", - // Control the port via environment variable - GRADIO_SERVER_PORT: port.toString(), - // Use unique directories per instance to avoid conflicts - GRADIO_EXAMPLES_CACHE: cacheDir, - GRADIO_TEMP_DIR: tempDir - } - }); - - childProcess.stdout?.setEncoding("utf8"); - childProcess.stderr?.setEncoding("utf8"); - - // Wait for app to be ready - return new Promise((resolve, reject) => { - const timeoutId = setTimeout(() => { - killGradioApp(childProcess); - reject( - new Error(`Gradio app ${demoName} failed to start within ${timeout}ms`) - ); - }, timeout); - - let output = ""; - let startupDetected = false; - - function handleOutput(data: string): void { - output += data; - // Check for Gradio's startup message - if ( - !startupDetected && - (data.includes("Running on local URL:") || - data.includes(`Uvicorn running on`)) - ) { - startupDetected = true; - clearTimeout(timeoutId); - // The startup message is printed before the server is fully ready. - // Poll with HTTP requests to ensure it actually responds. - waitForServerReady(port) - .then(() => resolve({ port, process: childProcess })) - .catch(reject); - } - } - - childProcess.stdout?.on("data", handleOutput); - childProcess.stderr?.on("data", handleOutput); - - childProcess.on("error", (err) => { - clearTimeout(timeoutId); - reject(err); - }); - - childProcess.on("exit", (code) => { - if (code !== 0 && code !== null) { - clearTimeout(timeoutId); - reject( - new Error( - `Gradio app ${demoName} exited with code ${code}.\nOutput: ${output}` - ) - ); - } - }); - }); -} diff --git a/6.12.1/tootils/src/download-command.ts b/6.12.1/tootils/src/download-command.ts deleted file mode 100644 index 2d99d0883c6b5e985d21c18902e61db60ccaa6dc..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/download-command.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { BrowserCommand } from "vitest/node"; -import { resolve } from "path"; -import { readFile } from "fs/promises"; - -/** - * Vitest browser command that captures a real file download triggered by - * clicking an element. Runs server-side with access to the Playwright page. - * - * Sets up page.waitForEvent("download") BEFORE clicking, so the download - * event is never missed. - */ -export const expect_download: BrowserCommand< - [selector: string, options?: { timeout?: number }], - { suggested_filename: string; content: string | null } -> = async (context, selector, options) => { - const timeout = options?.timeout ?? 5000; - const provider = context.provider as any; - const page = provider.getPage(context.sessionId); - // Tests run inside an iframe; use the iframe locator to click - // but listen for the download event on the parent page. - const iframe = (context as any).iframe; - - const [download] = await Promise.all([ - page.waitForEvent("download", { timeout }), - iframe.locator(selector).click() - ]); - - const suggested_filename = download.suggestedFilename(); - const path = await download.path(); - - let content: string | null = null; - if (path) { - const fs = await import("fs/promises"); - content = await fs.readFile(path, "utf-8"); - } - - return { - suggested_filename, - content - }; -}; - -/** - * Vitest browser command that sets files on an element. - * Resolves fixture URL paths (e.g. "/test/test_files/bus.png") to absolute - * disk paths and uses Playwright's setInputFiles(). - */ -export const set_file_inputs: BrowserCommand< - [file_urls: string[], selector?: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - const iframe = (context as any).iframe; - - const paths = file_urls.map((url) => resolve(root, url.replace(/^\//, ""))); - - await iframe - .locator(selector ?? 'input[type="file"]') - .first() - .setInputFiles(paths); -}; - -interface Drop_file_spec { - data: string; // base64 - name: string; - mime_type: string; -} - -/** - * Vitest browser command that simulates dropping files onto an element. - * Reads files from disk, transfers them as base64 into the browser context, - * and dispatches dragenter, dragover, and drop events with a real DataTransfer. - */ -export const drop_files: BrowserCommand< - [file_urls: string[], selector: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - - const files: Drop_file_spec[] = await Promise.all( - file_urls.map(async (url) => { - const abs = resolve(root, url.replace(/^\//, "")); - const data = (await readFile(abs)).toString("base64"); - const name = abs.split("/").pop()!; - const ext = name.split(".").pop()!.toLowerCase(); - const mime_type = MIME_TYPES[ext] || "application/octet-stream"; - return { data, name, mime_type }; - }) - ); - - const iframe = (context as any).iframe; - await iframe - .locator(selector) - .first() - .evaluate((target: Element, files: Drop_file_spec[]) => { - const dt = new DataTransfer(); - for (const f of files) { - const bytes = Uint8Array.from(atob(f.data), (c) => c.charCodeAt(0)); - dt.items.add(new File([bytes], f.name, { type: f.mime_type })); - } - - target.dispatchEvent( - new DragEvent("dragenter", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("dragover", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("drop", { dataTransfer: dt, bubbles: true }) - ); - }, files); -}; - -const MIME_TYPES: Record = { - txt: "text/plain", - csv: "text/csv", - json: "application/json", - pdf: "application/pdf", - jpg: "image/jpeg", - jpeg: "image/jpeg", - png: "image/png", - gif: "image/gif", - webp: "image/webp", - svg: "image/svg+xml", - mp4: "video/mp4", - webm: "video/webm", - ogg: "video/ogg", - avi: "video/x-msvideo", - wav: "audio/wav", - mp3: "audio/mpeg", - flac: "audio/flac" -}; diff --git a/6.12.1/tootils/src/download.ts b/6.12.1/tootils/src/download.ts deleted file mode 100644 index c6217fc6695b81fe685bcff9593ed9cab6095a3a..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/download.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { commands } from "vitest/browser"; -import type { FileData } from "@gradio/client"; - -export interface DownloadResult { - suggested_filename: string; - content: string | null; -} - -/** - * Clicks an element and captures the resulting file download. - * - * Uses a real browser download via Playwright under the hood — - * the file is actually downloaded and its content is readable. - * - * @param selector - CSS selector for the element to click - * @param options - Optional timeout (default 5000ms) - * @returns The downloaded file's suggested filename and text content - * - * @example - * ```ts - * const { suggested_filename, content } = await download_file("a.download-link"); - * expect(suggested_filename).toBe("data.csv"); - * expect(content).toContain("col1,col2"); - * ``` - */ -export async function download_file( - selector: string, - options?: { timeout?: number } -): Promise { - return (commands as any).expect_download(selector, options); -} - -/** - * Sets files on an `` element using real file fixtures. - * - * Accepts one or more FileData fixtures (e.g. TEST_JPG, TEST_PNG) and - * sets them on the file input, triggering the browser's native change event. - * - * @param files - One or more FileData fixtures to upload - * @param selector - CSS selector for the file input (default: 'input[type="file"]') - * - * @example - * ```ts - * import { render, upload_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await upload_file(TEST_JPG); - * - * expect(upload).toHaveBeenCalled(); - * ``` - */ -export async function upload_file( - files: FileData | FileData[], - selector?: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).set_file_inputs(urls, selector); -} - -/** - * Simulates dragging and dropping files onto an element. - * - * Reads the fixture files from disk, constructs a real DataTransfer - * with File objects, and dispatches dragenter, dragover, and drop events - * on the target element. - * - * @param files - One or more FileData fixtures to drop - * @param selector - CSS selector for the drop target element - * - * @example - * ```ts - * import { render, drop_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await drop_file(TEST_JPG, "[aria-label='Click to upload or drop files']"); - * - * await vi.waitFor(() => expect(upload).toHaveBeenCalled()); - * ``` - */ -export async function drop_file( - files: FileData | FileData[], - selector: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).drop_files(urls, selector); -} diff --git a/6.12.1/tootils/src/fixtures.ts b/6.12.1/tootils/src/fixtures.ts deleted file mode 100644 index 95adcab69ee5186eb2533321b64e8fd08932a113..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/fixtures.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { FileData } from "@gradio/client"; - -const BASE = "/test/test_files"; - -function fixture(filename: string, mime_type: string, size: number): FileData { - const url = `${BASE}/${filename}`; - return new FileData({ - path: url, - url, - orig_name: filename, - size, - mime_type - }); -} - -export const TEST_TXT = fixture("alphabet.txt", "text/plain", 26); -export const TEST_JPG = fixture("cheetah1.jpg", "image/jpeg", 20552); -export const TEST_PNG = fixture("bus.png", "image/png", 1951); -export const TEST_MP4 = fixture("video_sample.mp4", "video/mp4", 261179); -export const TEST_WAV = fixture("audio_sample.wav", "audio/wav", 16136); -export const TEST_PDF = fixture("sample_file.pdf", "application/pdf", 10558); diff --git a/6.12.1/tootils/src/index.ts b/6.12.1/tootils/src/index.ts deleted file mode 100644 index 5ac7a8723c2c74c4d04fc0c2555ced0e6f8388f5..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/index.ts +++ /dev/null @@ -1,224 +0,0 @@ -import { test as base, type Locator, type Page } from "@playwright/test"; -import { spy } from "tinyspy"; -import url from "url"; -import path from "path"; -import fsPromises from "fs/promises"; -import type { ChildProcess } from "node:child_process"; - -import type { SvelteComponent } from "svelte"; -import type { SpyFn } from "tinyspy"; - -import { launchGradioApp, killGradioApp, hasTestcase } from "./app-launcher"; - -export function get_text(el: T): string { - return el.innerText.trim(); -} - -export function wait(n: number): Promise { - return new Promise((r) => setTimeout(r, n)); -} - -const ROOT_DIR = path.resolve( - url.fileURLToPath(import.meta.url), - "../../../.." -); - -// Extract testcase name from test title if present -// Test titles can be: -// - "case eager_caching_examples: ..." -// - "test case multimodal_messages chatinterface works..." -function extractTestcaseFromTitle( - title: string, - demoName: string -): string | undefined { - // Try pattern: "case :" or "test case " - const patterns = [/^case\s+(\w+):/, /^test case\s+(\w+)\s/]; - - for (const pattern of patterns) { - const match = title.match(pattern); - if (match) { - const caseName = match[1]; - // Check if this is a testcase (not the main demo) - if (hasTestcase(demoName, caseName)) { - return caseName; - } - } - } - return undefined; -} - -// Cache for launched apps - key is "demoName" or "demoName_testcaseName" -const appCache = new Map< - string, - { port: number; process: ChildProcess; refCount: number } ->(); - -// Test fixture that launches Gradio app per test -const test_normal = base.extend<{ setup: void }>({ - setup: [ - async ({ page }, use, testInfo): Promise => { - const { file, title } = testInfo; - const demoName = path.basename(file, ".spec.ts"); - - // Check if this is a reload test (they manage their own apps) - if (demoName.endsWith(".reload")) { - // For reload tests, don't launch an app - they handle it themselves - await use(); - return; - } - - // Check if this test is for a specific testcase - const testcaseName = extractTestcaseFromTitle(title, demoName); - - // Cache key includes testcase if present - const cacheKey = testcaseName ? `${demoName}_${testcaseName}` : demoName; - - let appInfo = appCache.get(cacheKey); - - if (!appInfo) { - // Launch the app for this test - const workerIndex = testInfo.workerIndex; - try { - const { port, process } = await launchGradioApp( - demoName, - workerIndex, - 60000, - testcaseName - ); - appInfo = { port, process, refCount: 0 }; - appCache.set(cacheKey, appInfo); - } catch (error) { - console.error(`Failed to launch app for ${cacheKey}:`, error); - throw error; - } - } - - appInfo.refCount++; - - // Navigate to the app - await page.goto(`http://localhost:${appInfo.port}`); - - if ( - process.env?.GRADIO_SSR_MODE?.toLowerCase() === "true" && - !( - demoName.includes("multipage") || - demoName.includes("chatinterface_deep_link") - ) - ) { - await page.waitForSelector("#svelte-announcer"); - } - await page.waitForLoadState("load"); - - await use(); - - // Decrement ref count - appInfo.refCount--; - - // Note: We don't kill the app here because other tests might - // still need it. The app will be killed when the process exits. - }, - { auto: true } - ] -}); - -// Cleanup apps when the process exits -process.on("exit", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } -}); - -process.on("SIGINT", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -process.on("SIGTERM", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -export const test = test_normal; - -export async function wait_for_event( - component: SvelteComponent, - event: string -): Promise { - const mock = spy(); - return new Promise((res) => { - component.$on(event, () => { - mock(); - res(mock); - }); - }); -} - -export interface ActionReturn< - Parameter = never, - Attributes extends Record = Record -> { - update?: [Parameter] extends [never] ? never : (parameter: Parameter) => void; - destroy?: () => void; - /** - * ### DO NOT USE THIS - * This exists solely for type-checking and has no effect at runtime. - * Set this through the `Attributes` generic instead. - */ - $$_attributes?: Attributes; -} - -export { expect } from "@playwright/test"; - -export const drag_and_drop_file = async ( - page: Page, - selector: string | Locator, - filePath: string, - fileName: string, - fileType = "", - count = 1 -): Promise => { - const buffer = (await fsPromises.readFile(filePath)).toString("base64"); - - const dataTransfer = await page.evaluateHandle( - async ({ bufferData, localFileName, localFileType, count }) => { - const dt = new DataTransfer(); - - const blobData = await fetch(bufferData).then((res) => res.blob()); - - const file = new File([blobData], localFileName, { - type: localFileType - }); - - for (let i = 0; i < count; i++) { - dt.items.add(file); - } - return dt; - }, - { - bufferData: `data:application/octet-stream;base64,${buffer}`, - localFileName: fileName, - localFileType: fileType, - count - } - ); - - if (typeof selector === "string") { - await page.dispatchEvent(selector, "drop", { dataTransfer }); - } else { - await selector.dispatchEvent("drop", { dataTransfer }); - } -}; - -export async function go_to_testcase( - page: Page, - _test_case: string -): Promise { - // With the new setup, each testcase launches its own Gradio app. - // The fixture detects the testcase from the test title and launches - // the correct app, so this function is now a no-op. - // The page is already at the correct testcase app. -} diff --git a/6.12.1/tootils/src/render.ts b/6.12.1/tootils/src/render.ts deleted file mode 100644 index 60bc02a263f3b8f2c32ef9b0cef57c0396a0fb21..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/render.ts +++ /dev/null @@ -1,314 +0,0 @@ -import { - getQueriesForElement, - prettyDOM, - fireEvent as dtlFireEvent -} from "@testing-library/dom"; -import { tick, mount, unmount } from "svelte"; -import type { SvelteComponent, Component } from "svelte"; - -import type { - queries, - Queries, - BoundFunction, - EventType -} from "@testing-library/dom"; -import { vi, type Mock } from "vitest"; -import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils"; -import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker"; -import { _ } from "svelte-i18n"; - -const containerCache = new Map(); -const componentCache = new Set(); - -type ComponentType = Component; - -export type RenderResult< - C extends SvelteComponent, - Q extends Queries = typeof queries -> = { - container: HTMLElement; - component: C; - debug: (el?: HTMLElement | DocumentFragment) => void; - unmount: () => void; -} & { [P in keyof Q]: BoundFunction }; -export interface ILoadingStatus { - eta: number | null; - status: "pending" | "error" | "complete" | "generating" | "streaming"; - queue: boolean; - queue_position: number | null; - queue_size?: number; - fn_index: number; - message?: string | null; - scroll_to_output?: boolean; - show_progress?: "full" | "minimal" | "hidden"; - time_limit?: number | null | undefined; - progress?: { - progress: number | null; - index: number | null; - length: number | null; - unit: string | null; - desc: string | null; - }[]; - validation_error?: string | null; - type: "input" | "output"; - stream_state: "open" | "closed" | "waiting" | null; -} - -const loading_status: ILoadingStatus = { - eta: 0, - queue_position: 1, - queue_size: 1, - queue: true, - message: null, - time_limit: null, - progress: [], - validation_error: null, - type: "output", - stream_state: null, - status: "complete" as ILoadingStatus["status"], - scroll_to_output: false, - fn_index: 0, - show_progress: "full" as ILoadingStatus["show_progress"] -}; - -export interface RenderOptions { - container?: HTMLElement; - queries?: Q; -} - -export async function render< - Events extends Record, - Props extends Record, - T extends SvelteComponent, - X extends Record ->( - Component: ComponentType | { default: ComponentType }, - props?: Omit & { - loading_status?: LoadingStatus; - }, - options?: { - container?: HTMLElement; - } -): Promise< - RenderResult & { - listen: (event_name: string, opts?: { retrospective?: boolean }) => Mock; - set_data: (data: Record) => Promise; - get_data: () => Promise>; - } -> { - let container: HTMLElement; - if (!options?.container) { - container = document.body; - } else { - container = options.container; - } - - const target = container.appendChild(document.createElement("div")); - - const ComponentConstructor: ComponentType = - //@ts-ignore - Component.default || Component; - - const id = Math.floor(Math.random() * 1000000); - - let component_set_data: (data: Record) => void; - let component_get_data: () => Promise>; - - const mock_register = ( - _id: number, - set_data: (data: Record) => void, - get_data: () => Promise> - ): void => { - component_set_data = set_data; - component_get_data = get_data; - }; - - const event_listeners = new Map void>>(); - const event_buffer: Array<{ event: string; data: any }> = []; - - function notify_listeners(event: string, data: any): void { - const listeners = event_listeners.get(event); - if (listeners) { - for (const listener of listeners) { - listener(data); - } - } - } - - const dispatcher = (_id: number, event: string, data: any): void => { - event_buffer.push({ event, data }); - notify_listeners(event, data); - }; - - function listen( - event_name: string, - opts?: { retrospective?: boolean } - ): Mock { - const fn = vi.fn(); - if (!event_listeners.has(event_name)) { - event_listeners.set(event_name, new Set()); - } - event_listeners.get(event_name)!.add(fn); - - if (opts?.retrospective) { - for (const entry of event_buffer) { - if (entry.event === event_name) { - fn(entry.data); - } - } - } - - return fn; - } - - const i18nFormatter = (s: string | null | undefined): string => s ?? ""; - - const shared_props_obj: Record = { - id, - target, - theme_mode: "light" as const, - version: "2.0.0", - formatter: i18nFormatter, - client: {} as any, - load_component: () => Promise.resolve({ default: {} as any }), - show_progress: true, - api_prefix: "", - server: {} as any, - show_label: true, - register_component: mock_register, - dispatcher - }; - - const component_props_obj: Record = { - i18n: i18nFormatter - }; - - if (props) { - for (const key in props) { - const value = (props as any)[key]; - if (allowed_shared_props.includes(key as any)) { - shared_props_obj[key] = value; - } else { - component_props_obj[key] = value; - } - } - } - - shared_props_obj.loading_status = props?.loading_status - ? props.loading_status - : loading_status; - - const componentProps = { - shared_props: shared_props_obj, - props: { - ...component_props_obj - }, - ...shared_props_obj - }; - - const component = mount(ComponentConstructor, { - target, - props: componentProps - }) as T; - - containerCache.set(container, { target, component }); - componentCache.add(component); - - await tick(); - - return { - container, - component, - listen, - set_data: async (data: Record) => { - const r = component_set_data(data); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return r; - }, - get_data: () => component_get_data(), - //@ts-ignore - debug: (el = container): void => console.warn(prettyDOM(el)), - unmount: (): void => { - if (componentCache.has(component)) { - unmount(component); - } - }, - ...getQueriesForElement(container) - }; -} - -const cleanupAtContainer = (container: HTMLElement): void => { - const { target, component } = containerCache.get(container); - - if (componentCache.has(component)) { - unmount(component); - } - - if (target.parentNode === document.body) { - document.body.removeChild(target); - } - - containerCache.delete(container); -}; - -export function cleanup(): void { - Array.from(containerCache.keys()).forEach(cleanupAtContainer); - document.body.innerHTML = ""; -} - -type AsyncFireObject = { - [K in EventType]: ( - element: Document | Element | Window | Node, - options?: object - ) => Promise; -}; - -export const fireEvent = Object.keys(dtlFireEvent).reduce((acc, key) => { - const _key = key as EventType; - return { - ...acc, - [_key]: async ( - element: Document | Element | Window, - options: object = {} - ): Promise => { - const event = dtlFireEvent[_key](element, options); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return event; - } - }; -}, {} as AsyncFireObject); - -export type FireFunction = ( - element: Document | Element | Window, - event: Event -) => Promise; - -export { download_file, upload_file, drop_file } from "./download.js"; - -/** - * Creates a mock client suitable for components that use file uploads. - * The upload mock echoes back the input FileData unchanged. - */ -export function mock_client(): Record { - return { - upload: async (file_data: any[]) => file_data, - stream: async () => ({ onmessage: null, close: () => {} }) - }; -} -export { - TEST_TXT, - TEST_JPG, - TEST_PNG, - TEST_MP4, - TEST_WAV, - TEST_PDF -} from "./fixtures.js"; -export * from "@testing-library/dom"; diff --git a/6.12.1/tootils/src/shared-prop-tests.ts b/6.12.1/tootils/src/shared-prop-tests.ts deleted file mode 100644 index b8f58e68a13e368fd4a1f1d6f2e246260b82bcd0..0000000000000000000000000000000000000000 --- a/6.12.1/tootils/src/shared-prop-tests.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, test, expect, afterEach } from "vitest"; -import { render, cleanup } from "./render"; - -const loading_status = { - status: "complete", - queue_position: null, - queue_size: null, - eta: null, - message: null -}; - -export interface SharedPropTestConfig { - /** The Svelte component to test */ - component: any; - /** Minimum props required to render the component without errors */ - base_props: Record; - /** Display name for test output */ - name: string; - /** - * Some components don't render labels (e.g. HTML, Markdown). - * Set to false to skip label-related tests. - * @default true - */ - has_label?: boolean; - /** - * Whether the component renders validation_error text. - * Not all components support this. Set to false to skip. - * @default true - */ - has_validation_error?: boolean; - /** - * Some components (e.g. Accordion) map visible=false to "hidden" - * instead of removing from the DOM. Set to true to expect hidden - * behaviour rather than removal. - * @default false - */ - visible_false_hides?: boolean; - /** - * Whether the component is wrapped in a Block (which renders a `.block` - * element). Components like Button render a bare element instead. - * Set to false to skip `.block` selector checks. - * @default true - */ - has_block_wrapper?: boolean; -} - -export function run_shared_prop_tests(config: SharedPropTestConfig): void { - const { - component, - base_props, - name, - has_label = true, - has_validation_error = true, - visible_false_hides = false, - has_block_wrapper = true - } = config; - - const label = "Test Label"; - - function make_props( - overrides: Record = {} - ): Record { - return { - ...base_props, - loading_status: { ...loading_status, ...overrides }, - label, - ...overrides - }; - } - - describe(`${name}: shared props`, () => { - afterEach(() => cleanup()); - - test("elem_id is applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_id: "my-test-id" }) - ); - const el = container.querySelector("#my-test-id"); - expect(el).not.toBeNull(); - }); - - test("elem_classes are applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_classes: ["my-test-class"] }) - ); - const el = container.querySelector(".my-test-class"); - expect(el).not.toBeNull(); - }); - - test("visible: true renders the component", async () => { - const { container } = await render( - component, - make_props({ visible: true, elem_id: "visible-test" }) - ); - const el = has_block_wrapper - ? container.querySelector(".block") - : container.querySelector("#visible-test"); - expect(el).not.toBeNull(); - }); - - test("visible: 'hidden' hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: "hidden", elem_id: "hidden-test" }) - ); - - const el = result.container.querySelector("#hidden-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - - if (visible_false_hides) { - test("visible: false hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - } else { - test("visible: false removes the component from the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).toBeNull(); - }); - } - - if (has_label) { - test("label text is rendered", async () => { - const result = await render( - component, - make_props({ label: "My Custom Label", show_label: true }) - ); - const el = result.getByText("My Custom Label"); - expect(el).toBeTruthy(); - }); - - test("show_label: true makes the label visible", async () => { - const result = await render( - component, - make_props({ label: "Visible Label", show_label: true }) - ); - const el = result.getByText("Visible Label"); - expect(el).toBeVisible(); - }); - - test("show_label: false hides the label visually but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ label: "Hidden Label", show_label: false }) - ); - const el = result.getByText("Hidden Label"); - // The label remains in the DOM for screen readers via sr-only. - // sr-only uses clip/1px dimensions rather than display:none, - // so toBeVisible() won't catch it. We check the class directly. - expect(el.closest("[data-testid='block-info']")).toHaveClass("sr-only"); - }); - } - - if (has_validation_error) { - test("validation_error displays error text visibly", async () => { - const result = await render( - component, - make_props({ - validation_error: "This field is required", - show_validation_error: true - }) - ); - const el = result.getByText("This field is required"); - expect(el).toBeVisible(); - }); - } - }); -} diff --git a/6.12.1/upload/package.json b/6.12.1/upload/package.json deleted file mode 100644 index ca17ce703ff779d7a44d90c69f2df20161e2b463..0000000000000000000000000000000000000000 --- a/6.12.1/upload/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@gradio/upload", - "version": "0.17.8", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/upload" - } -} diff --git a/6.12.1/upload/src/ModifyUpload.svelte b/6.12.1/upload/src/ModifyUpload.svelte deleted file mode 100644 index 7c8db47405576b3b590d9bcb394d5e5848f7e240..0000000000000000000000000000000000000000 --- a/6.12.1/upload/src/ModifyUpload.svelte +++ /dev/null @@ -1,61 +0,0 @@ - - - - {#if editable} - onedit?.()} - /> - {/if} - - {#if undoable} - onundo?.()} - /> - {/if} - - {#if download} - - - - {/if} - - {#if children}{@render children()}{/if} - - { - onclear?.(); - event.stopPropagation(); - }} - /> - diff --git a/6.12.1/upload/src/Upload.svelte b/6.12.1/upload/src/Upload.svelte deleted file mode 100644 index 27183d59b8604ce79d9e90d44269ffb32bdb7225..0000000000000000000000000000000000000000 --- a/6.12.1/upload/src/Upload.svelte +++ /dev/null @@ -1,398 +0,0 @@ - - -{#if filetype === "clipboard"} - -{:else if uploading && show_progress} - {#if !hidden} - - {/if} -{:else} - -{/if} - - diff --git a/6.12.1/upload/src/UploadProgress.svelte b/6.12.1/upload/src/UploadProgress.svelte deleted file mode 100644 index 0ee9995f6d036d79048aca2705d530d3453ae7a1..0000000000000000000000000000000000000000 --- a/6.12.1/upload/src/UploadProgress.svelte +++ /dev/null @@ -1,199 +0,0 @@ - - -
- Uploading {files_with_progress.length} - {files_with_progress.length > 1 ? "files" : "file"}... - - {#if file_to_display} -
- -
- {getProgress(file_to_display)} -
-
- - {file_to_display.orig_name} - -
- {/if} -
- - diff --git a/6.12.1/upload/src/index.ts b/6.12.1/upload/src/index.ts deleted file mode 100644 index 0c2bdb5d7b2eb9c39953af027ae57cc674a0e377..0000000000000000000000000000000000000000 --- a/6.12.1/upload/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Upload } from "./Upload.svelte"; -export { default as ModifyUpload } from "./ModifyUpload.svelte"; -export { default as UploadProgress } from "./UploadProgress.svelte"; -export { create_drag } from "./utils"; diff --git a/6.12.1/upload/src/utils.ts b/6.12.1/upload/src/utils.ts deleted file mode 100644 index e961b85f75d154896c4be1656ed4e383bae0305b..0000000000000000000000000000000000000000 --- a/6.12.1/upload/src/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -interface DragActionOptions { - disable_click?: boolean; - accepted_types?: string | string[] | null; - mode?: "single" | "multiple" | "directory"; - on_drag_change?: (dragging: boolean) => void; - on_files?: (files: File[]) => void; -} - -type ActionReturn = { - update: (new_options: DragActionOptions) => void; - destroy: () => void; -}; - -export function create_drag(): { - drag: (node: HTMLElement, options: DragActionOptions) => ActionReturn; - open_file_upload: () => void; -} { - let hidden_input: HTMLInputElement; - let _options: DragActionOptions; - return { - drag( - node: HTMLElement, - options: DragActionOptions = {} - ): { - update: (new_options: DragActionOptions) => void; - destroy: () => void; - } { - _options = options; - - // Create and configure hidden file input - function setup_hidden_input(): void { - hidden_input = document.createElement("input"); - hidden_input.type = "file"; - hidden_input.style.display = "none"; - hidden_input.setAttribute("aria-label", "File upload"); - hidden_input.setAttribute("data-testid", "file-upload"); - const accept_options = Array.isArray(_options.accepted_types) - ? _options.accepted_types.join(",") - : _options.accepted_types || undefined; - - if (accept_options) { - hidden_input.accept = accept_options; - } - - hidden_input.multiple = _options.mode === "multiple" || false; - if (_options.mode === "directory") { - hidden_input.webkitdirectory = true; - hidden_input.setAttribute("directory", ""); - hidden_input.setAttribute("mozdirectory", ""); - } - node.appendChild(hidden_input); - } - - setup_hidden_input(); - - function handle_drag(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - } - - function handle_drag_enter(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(true); - } - - function handle_drag_leave(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - } - - function handle_drop(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - - if (!e.dataTransfer?.files) return; - const files = Array.from(e.dataTransfer.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - - function handle_click(): void { - if (!_options.disable_click) { - hidden_input.value = ""; - hidden_input.click(); - } - } - - function handle_file_input_change(): void { - if (hidden_input.files) { - const files = Array.from(hidden_input.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - } - - // Add all event listeners - node.addEventListener("drag", handle_drag); - node.addEventListener("dragstart", handle_drag); - node.addEventListener("dragend", handle_drag); - node.addEventListener("dragover", handle_drag); - node.addEventListener("dragenter", handle_drag_enter); - node.addEventListener("dragleave", handle_drag_leave); - node.addEventListener("drop", handle_drop); - node.addEventListener("click", handle_click); - hidden_input!.addEventListener("change", handle_file_input_change); - - return { - update(new_options: DragActionOptions) { - _options = new_options; - // Recreate hidden input with new options - hidden_input.remove(); - setup_hidden_input(); - hidden_input.addEventListener("change", handle_file_input_change); - }, - destroy() { - node.removeEventListener("drag", handle_drag); - node.removeEventListener("dragstart", handle_drag); - node.removeEventListener("dragend", handle_drag); - node.removeEventListener("dragover", handle_drag); - node.removeEventListener("dragenter", handle_drag_enter); - node.removeEventListener("dragleave", handle_drag_leave); - node.removeEventListener("drop", handle_drop); - node.removeEventListener("click", handle_click); - hidden_input.removeEventListener("change", handle_file_input_change); - hidden_input.remove(); - } - }; - }, - open_file_upload(): void { - if (hidden_input) { - hidden_input.value = ""; - hidden_input.click(); - } - } - }; -} diff --git a/6.12.1/uploadbutton/Index.svelte b/6.12.1/uploadbutton/Index.svelte deleted file mode 100644 index f246c8f96ea948a81cd7bcd7a2412b089ebbaea1..0000000000000000000000000000000000000000 --- a/6.12.1/uploadbutton/Index.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - gradio.dispatch("click")} - onchange={(detail) => handle_event(detail, "change")} - onupload={(detail) => handle_event(detail, "upload")} - onerror={(detail) => { - gradio.dispatch("error", detail); - }} - upload={(...args) => gradio.shared.client.upload(...args)} -> - {gradio.shared.label ?? ""} - diff --git a/6.12.1/uploadbutton/package.json b/6.12.1/uploadbutton/package.json deleted file mode 100644 index 657726b0534b1c5731cdf917e9d630aa45093a12..0000000000000000000000000000000000000000 --- a/6.12.1/uploadbutton/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@gradio/uploadbutton", - "version": "0.9.18", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "main": "./Index.svelte", - "dependencies": { - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/uploadbutton" - } -} diff --git a/6.12.1/uploadbutton/shared/UploadButton.svelte b/6.12.1/uploadbutton/shared/UploadButton.svelte deleted file mode 100644 index 3cb3b534036b7d1fa652fddd293a00c4f5687e03..0000000000000000000000000000000000000000 --- a/6.12.1/uploadbutton/shared/UploadButton.svelte +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - {#if icon} - {`${value} - {/if} - {#if children}{@render children()}{/if} - - - diff --git a/6.12.1/uploadbutton/types.ts b/6.12.1/uploadbutton/types.ts deleted file mode 100644 index 100547b8f9293f9cd2a191b09a6003e7f071a585..0000000000000000000000000000000000000000 --- a/6.12.1/uploadbutton/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface UploadButtonProps { - value: null | FileData | FileData[]; - file_count: string; - file_types: string[]; - size: "sm" | "lg"; - icon: FileData | null; - variant: "primary" | "secondary" | "stop"; -} - -export interface UploadButtonEvents { - change: never; - upload: never; - click: never; - error: string; -} diff --git a/6.12.1/utils/package.json b/6.12.1/utils/package.json deleted file mode 100644 index 97e34911592ce8b15a54ea071d740237220295dc..0000000000000000000000000000000000000000 --- a/6.12.1/utils/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@gradio/utils", - "version": "0.12.2", - "description": "Gradio UI packages", - "type": "module", - "main": "./src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/theme": "workspace:^", - "svelte-i18n": "^4.0.1" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/utils" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.12.1/utils/src/color.ts b/6.12.1/utils/src/color.ts deleted file mode 100644 index 86d3fe6a5c35c450cc6517b5f3d4767ffda1bc2c..0000000000000000000000000000000000000000 --- a/6.12.1/utils/src/color.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { colors, ordered_colors } from "@gradio/theme"; - -export const get_next_color = (index: number): keyof typeof colors => { - return ordered_colors[index % ordered_colors.length]; -}; diff --git a/6.12.1/utils/src/index.ts b/6.12.1/utils/src/index.ts deleted file mode 100644 index 8db07c80fcf3416332b4ec11d86c06a0fdfb7e74..0000000000000000000000000000000000000000 --- a/6.12.1/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./color.js"; -export * from "./utils.svelte.js"; -export * from "./types.js"; diff --git a/6.12.1/utils/src/types.ts b/6.12.1/utils/src/types.ts deleted file mode 100644 index 8dd47a49c34d6da4ce4328aa99f9fe563ecc7d89..0000000000000000000000000000000000000000 --- a/6.12.1/utils/src/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface CustomButton { - id: number; - value: string | null; - icon: FileData | null; -} diff --git a/6.12.1/utils/src/utils.svelte.ts b/6.12.1/utils/src/utils.svelte.ts deleted file mode 100644 index 1a7d54a3cfac850fd1dedcf10907105b157ade26..0000000000000000000000000000000000000000 --- a/6.12.1/utils/src/utils.svelte.ts +++ /dev/null @@ -1,575 +0,0 @@ -import type { ActionReturn } from "svelte/action"; -import type { Client } from "@gradio/client"; -import type { ComponentType, SvelteComponent } from "svelte"; -import { tick, untrack } from "svelte"; -import type { Component } from "svelte"; -import { locale } from "svelte-i18n"; - -export const I18N_MARKER = "__i18n__"; -const TRANSLATABLE_PROPS = [ - "label", - "info", - "placeholder", - "description", - "title", - "value" -]; - -export interface SharedProps { - elem_id?: string; - elem_classes: string[]; - components?: string[]; - server_fns?: string[]; - interactive: boolean; - visible: boolean | "hidden"; - id: number; - container: boolean; - target: HTMLElement; - theme_mode: "light" | "dark" | "system"; - version: string; - root: string; - autoscroll: boolean; - max_file_size: number | null; - formatter: any; //I18nFormatter; - client: Client; - scale: number; - min_width: number; - padding: number; - load_component: load_component; - loading_status?: any; - label: string; - show_label: boolean; - validation_error?: string | null; - theme?: "light" | "dark"; - show_progress: boolean; - api_prefix: string; - server: ServerFunctions; - attached_events?: string[]; - register_component: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - dispatcher: Function; -} - -export type LoadingComponent = Promise<{ - default: Component; -}>; - -export const GRADIO_ROOT = "GRADIO_ROOT"; - -export interface ValueData { - value: any; - is_value_data: boolean; -} - -export interface SelectData { - row_value?: any[]; - col_value?: any[]; - index: number | [number, number]; - value: any; - selected?: boolean; -} - -export interface LikeData { - index: number | [number, number]; - value: any; - liked?: boolean | string; -} - -export interface KeyUpData { - key: string; - input_value: string; -} - -export interface ShareData { - description: string; - title?: string; -} - -export interface CopyData { - value: string; -} - -export class ShareError extends Error { - constructor(message: string) { - super(message); - this.name = "ShareError"; - } -} - -export async function uploadToHuggingFace( - data: string | { url?: string; path?: string }, - type: "base64" | "url" -): Promise { - if (window.__gradio_space__ == null) { - throw new ShareError("Must be on Spaces to share."); - } - let blob: Blob; - let contentType: string; - let filename: string; - if (type === "url") { - let url: string; - - if (typeof data === "object" && data.url) { - url = data.url; - } else if (typeof data === "string") { - url = data; - } else { - throw new Error("Invalid data format for URL type"); - } - - const response = await fetch(url); - blob = await response.blob(); - contentType = response.headers.get("content-type") || ""; - filename = response.headers.get("content-disposition") || ""; - } else { - let dataurl: string; - - if (typeof data === "object" && data.path) { - dataurl = data.path; - } else if (typeof data === "string") { - dataurl = data; - } else { - throw new Error("Invalid data format for base64 type"); - } - - blob = dataURLtoBlob(dataurl); - contentType = dataurl.split(";")[0].split(":")[1]; - filename = "file." + contentType.split("/")[1]; - } - - const file = new File([blob], filename, { type: contentType }); - - // Send file to endpoint - const uploadResponse = await fetch("https://huggingface.co/uploads", { - method: "POST", - body: file, - headers: { - "Content-Type": file.type, - "X-Requested-With": "XMLHttpRequest" - } - }); - - // Check status of response - if (!uploadResponse.ok) { - if ( - uploadResponse.headers.get("content-type")?.includes("application/json") - ) { - const error = await uploadResponse.json(); - throw new ShareError(`Upload failed: ${error.error}`); - } - throw new ShareError(`Upload failed.`); - } - - // Return response if needed - const result = await uploadResponse.text(); - return result; -} - -function dataURLtoBlob(dataurl: string): Blob { - var arr = dataurl.split(","), - mime = (arr[0].match(/:(.*?);/) as RegExpMatchArray)[1], - bstr = atob(arr[1]), - n = bstr.length, - u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} - -export function copy(node: HTMLDivElement): ActionReturn { - node.addEventListener("click", handle_copy); - - async function handle_copy(event: MouseEvent): Promise { - const path = event.composedPath() as HTMLButtonElement[]; - - const [copy_button] = path.filter( - (e) => e?.tagName === "BUTTON" && e.classList.contains("copy_code_button") - ); - - if (copy_button) { - event.stopImmediatePropagation(); - - const copy_text = copy_button.parentElement!.innerText.trim(); - const copy_sucess_button = Array.from( - copy_button.children - )[1] as HTMLDivElement; - - const copied = await copy_to_clipboard(copy_text); - - if (copied) copy_feedback(copy_sucess_button); - - function copy_feedback(_copy_sucess_button: HTMLDivElement): void { - _copy_sucess_button.style.opacity = "1"; - setTimeout(() => { - _copy_sucess_button.style.opacity = "0"; - }, 2000); - } - } - } - - return { - destroy(): void { - node.removeEventListener("click", handle_copy); - } - }; -} - -async function copy_to_clipboard(value: string): Promise { - let copied = false; - if ("clipboard" in navigator) { - await navigator.clipboard.writeText(value); - copied = true; - } else { - const textArea = document.createElement("textarea"); - textArea.value = value; - - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - copied = true; - } catch (error) { - console.error(error); - copied = false; - } finally { - textArea.remove(); - } - } - - return copied; -} - -export const format_time = (seconds: number): string => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const seconds_remainder = Math.round(seconds) % 60; - const padded_minutes = `${minutes < 10 ? "0" : ""}${minutes}`; - const padded_seconds = `${ - seconds_remainder < 10 ? "0" : "" - }${seconds_remainder}`; - - if (hours > 0) { - return `${hours}:${padded_minutes}:${padded_seconds}`; - } - return `${minutes}:${padded_seconds}`; -}; - -interface Args { - api_url: string; - name: string; - id?: string; - variant: "component" | "example" | "base"; -} - -export type component_loader = (args: Args) => { - component: { - default: ComponentType; - }; -}; - -export type LoadedComponentWithRuntime = { - component: LoadingComponent; - runtime: false | typeof import("svelte"); -}; - -export type load_component = ( - name: string, - variant: "component" | "example" | "base", - component_class_id?: string -) => LoadedComponentWithRuntime; - -const is_browser = typeof window !== "undefined"; - -export type ServerFunctions = Record Promise>; - -export const allowed_shared_props: (keyof SharedProps)[] = [ - "elem_id", - "elem_classes", - "visible", - "interactive", - "server_fns", - "server", - "id", - "target", - "theme_mode", - "version", - "root", - "autoscroll", - "max_file_size", - "formatter", - "client", - "load_component", - "scale", - "min_width", - "theme", - "padding", - "loading_status", - "label", - "show_label", - "validation_error", - "show_progress", - "api_prefix", - "container", - "attached_events", - "register_component", - "dispatcher" -] as const; - -export type I18nFormatter = any; - -export function has_i18n_marker(value: unknown): value is string { - return typeof value === "string" && value.includes(I18N_MARKER); -} - -export function translate_i18n_marker( - value: string, - translate: (key: string) => string -): string { - const start = value.indexOf(I18N_MARKER); - if (start === -1) return value; - - const json_start = start + I18N_MARKER.length; - const json_end = value.indexOf("}", json_start) + 1; - if (json_end === 0) return value; - - try { - const metadata = JSON.parse(value.slice(json_start, json_end)); - if (metadata?.key) { - const translated = translate(metadata.key); - const result = translated !== metadata.key ? translated : metadata.key; - return value.slice(0, start) + result + value.slice(json_end); - } - } catch {} - - return value; -} - -export class Gradio { - load_component: load_component; - shared: SharedProps = $state({} as SharedProps) as SharedProps; - props = $state({} as U) as U; - i18n: I18nFormatter = $state((v: string) => v) as any; - translatable_props: Record = {}; - dispatcher!: Function; - last_update: ReturnType | null = null; - shared_props: (keyof SharedProps)[] = allowed_shared_props; - mounted: boolean = false; - old_value: any; - register_component!: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - - constructor( - _props: { shared_props: SharedProps; props: U }, - default_values?: Partial - ) { - for (const key in _props.shared_props) { - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - - if (default_values) { - for (const key in default_values) { - if (this.props[key as keyof U] === undefined) { - // @ts-ignore - this.props[key] = default_values[key as keyof U]; - } - } - } - // @ts-ignore same here - this.i18n = this.props.i18n ?? ((v: string) => v); - - for (const key of TRANSLATABLE_PROPS) { - // @ts-ignore - this.shared[key] = this._translate_and_store( - "shared", - key, - // @ts-ignore - _props.shared_props[key] - ); - // @ts-ignore - this.props[key] = this._translate_and_store( - "props", - key, - // @ts-ignore - _props.props[key] - ); - } - - this.load_component = this.shared.load_component; - - this.register_component = this.shared.register_component || (() => {}); - this.dispatcher = this.shared.dispatcher || (() => {}); - - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - - $effect(() => { - // Need to update the props here - // otherwise UI won't reflect latest state from render - for (const key in _props.shared_props) { - // @ts-ignore - if (this._is_i18n_managed(`shared.${key}`, _props.shared_props[key])) - continue; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - if (this._is_i18n_managed(`props.${key}`, _props.props[key])) continue; - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - untrack(() => { - this.shared.id = _props.shared_props.id; - }); - }); - - // retranslate props when locale changes - if (Object.keys(this.translatable_props).length > 0) { - locale.subscribe(() => { - for (const [full_key, original] of Object.entries( - this.translatable_props - )) { - const [target, key] = full_key.split("."); - const translated = this.i18n(original); - // @ts-ignore - if (target === "shared") this.shared[key] = translated; - // @ts-ignore - else this.props[key] = translated; - } - }); - } - } - - // check if props are translatable - _is_i18n_managed(key: string, new_value: unknown): boolean { - const original_marker = this.translatable_props[key]; - if (!original_marker) return false; - if (new_value === original_marker) return true; - // if value has changed then remove key - delete this.translatable_props[key]; - return false; - } - - _translate_and_store( - target: "shared" | "props", - key: string, - value: unknown - ): unknown { - if (typeof value !== "string") return value; - const translated = this.i18n(value); - if (translated !== value) { - this.translatable_props[`${target}.${key}`] = value; - } - return translated; - } - - dispatch(event_name: E, data?: T[E]): void { - this.dispatcher(this.shared.id, event_name, data); - } - - async get_data() { - return $state.snapshot(this.props); - } - - update(data: Partial): void { - this.set_data(data as U & SharedProps); - } - - set_data(data: Partial): void { - for (const key in data) { - // @ts-ignore - const value = data[key]; - const translated = has_i18n_marker(value) - ? this._translate_and_store( - this.shared_props.includes(key as keyof SharedProps) - ? "shared" - : "props", - key, - value - ) - : value; - - if (this.shared_props.includes(key as keyof SharedProps)) { - const _key = key as keyof SharedProps; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[_key] = translated; - continue; - } - // @ts-ignore - this.props[key] = translated; - } - } - - watch_for_change() { - $effect(() => { - if (!this.mounted) { - // @ts-ignore - this.old_value = this.props.value; - this.mounted = true; - } - // @ts-ignore - if (this.old_value != this.props.value) { - // @ts-ignore - this.old_value = this.props.value; - // @ts-ignore - this.dispatch("change"); - } - }); - } -} - -// function _load_component( -// this: Gradio, -// name: string, -// variant: "component" | "example" | "base" = "component" -// ): ReturnType { -// return this._load_component!({ -// name, -// api_url: this.shared.client.config?.root!, -// variant -// }); -// } - -export const css_units = (dimension_value: string | number): string => { - return typeof dimension_value === "number" - ? dimension_value + "px" - : dimension_value; -}; - -export function should_show_scroll_fade( - container: HTMLElement | null -): boolean { - if (!container) return false; - const has_overflow = container.scrollHeight > container.clientHeight; - const at_bottom = - container.scrollTop >= container.scrollHeight - container.clientHeight - 1; - return has_overflow && !at_bottom; -} - -type MappedProps = { [K in keyof T]: T[K] }; -type MappedProp = { [P in K]: T[P] }; diff --git a/6.12.1/vibeeditor/Index.svelte b/6.12.1/vibeeditor/Index.svelte deleted file mode 100644 index 6db9b3cb7167948ae0f14cabd9d66c791deb9e2d..0000000000000000000000000000000000000000 --- a/6.12.1/vibeeditor/Index.svelte +++ /dev/null @@ -1,764 +0,0 @@ - - -
- -
- - -
- -
- {#if activeTab === "chat"} -
- {#each message_history as message, index} -
-
- - - - {#if !message.isBot && message.hash && !message.isPending} - - {/if} -
-
- {/each} - - {#if message_history.length === 0} -
No messages yet
- {/if} - - {#if message_history.length === 0} -
-
- {#each starterQueries as query} - - {/each} -
-
- {/if} -
- {:else if activeTab === "code"} -
-
- -
- - -
- {/if} -
- -
-
Powered by: gpt-oss
- - {#if showTagMenu && currentLineIndex === i} -
- [s, i])} - filtered_indices={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )} - active_index={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )[selectedOptionIndex]} - show_options={true} - onchange={(e) => insert_tag(e)} - {offset_from_top} - from_top={true} - /> -
- {/if} -
-
- {#if gradio.props.max_lines == undefined || (gradio.props.max_lines && i < gradio.props.max_lines - 1)} -
- -
- {/if} -
- -
-
- {/each} - - {:else if checked || gradio.props.ui_mode !== "dialogue"} -
- {#if is_formatting} -
-
-
Converting to plain text...
-
- {/if} - - {/if} - {#if submit_btn} - - {/if} - {#if stop_btn} - - {/if} -
- - - diff --git a/6.13.0/textbox/types.ts b/6.13.0/textbox/types.ts deleted file mode 100644 index 8ec1cfc945755962a887be7207b0f60290ad929a..0000000000000000000000000000000000000000 --- a/6.13.0/textbox/types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type SelectData, - type CopyData, - type CustomButton -} from "@gradio/utils"; -import type { LoadingStatus } from "@gradio/statustracker"; - -export interface TextboxEvents { - change: string; - submit: never; - blur: never; - select: SelectData; - input: never; - focus: never; - stop: never; - clear_status: LoadingStatus; - copy: CopyData; - custom_button_click: { id: number }; -} - -export interface TextboxProps { - value: string; - info: string; - lines: number; - type: "text" | "password" | "email" | undefined; - rtl: boolean; - text_align: "right" | "left"; - max_lines: number; - placeholder: string; - submit_btn: string; - stop_btn: string; - buttons: (string | CustomButton)[] | null; - autofocus: boolean; - autoscroll: boolean; - max_length: number; - html_attributes: InputHTMLAttributes; - validation_error: string | null; -} - -type FullAutoFill = - | AutoFill - | "bday" - | `${OptionalPrefixToken}${"cc-additional-name"}` - | "nickname" - | "language" - | "organization-title" - | "photo" - | "sex" - | "url"; - -export interface InputHTMLAttributes { - autocapitalize?: - | "off" - | "none" - | "on" - | "sentences" - | "words" - | "characters" - | null; - autocorrect?: "on" | "off" | null; - spellcheck?: boolean | null; - autocomplete?: FullAutoFill | undefined | null; - tabindex?: number | null; - enterkeyhint?: - | "enter" - | "done" - | "go" - | "next" - | "previous" - | "search" - | "send" - | null; - lang?: string | null; -} diff --git a/6.13.0/theme/package.json b/6.13.0/theme/package.json deleted file mode 100644 index bb4343fa73bdf0fe073c0d611292babaf9cc8d6b..0000000000000000000000000000000000000000 --- a/6.13.0/theme/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@gradio/theme", - "version": "0.6.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": false, - "scripts": { - "generate": "pollen -c src/pollen.config.mjs", - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./reset.css": { - "gradio": "./src/reset.css", - "import": "./dist/src/reset.css" - }, - "./global.css": { - "gradio": "./src/global.css", - "import": "./dist/src/global.css" - }, - "./tokens": { - "gradio": "./src/tokens.ts", - "import": "./dist/src/tokens.js" - }, - "./typography.css": { - "gradio": "./src/typography.css", - "import": "./dist/src/typography.css" - }, - "./gradio-style.scss": { - "gradio": "./src/gradio-style.scss", - "import": "./dist/src/gradio-style.scss" - }, - "./pollen.css": { - "gradio": "./src/pollen.css", - "import": "./dist/src/pollen.css" - }, - "./package.json": "./package.json" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/theme" - } -} diff --git a/6.13.0/theme/src/colors.ts b/6.13.0/theme/src/colors.ts deleted file mode 100644 index 04a9c9b33c631635832a8fb982ce1d29e0176fa7..0000000000000000000000000000000000000000 --- a/6.13.0/theme/src/colors.ts +++ /dev/null @@ -1,350 +0,0 @@ -// import tw_colors from "tailwindcss/colors"; - -export const ordered_colors = [ - "red", - "green", - "blue", - "yellow", - "purple", - "teal", - "orange", - "cyan", - "lime", - "pink" -] as const; -interface ColorPair { - primary: string; - secondary: string; -} - -interface Colors { - red: ColorPair; - green: ColorPair; - blue: ColorPair; - yellow: ColorPair; - purple: ColorPair; - teal: ColorPair; - orange: ColorPair; - cyan: ColorPair; - lime: ColorPair; - pink: ColorPair; -} - -// https://play.tailwindcss.com/ZubQYya0aN -export const color_values = [ - { color: "red", primary: 600, secondary: 100 }, - { color: "green", primary: 600, secondary: 100 }, - { color: "blue", primary: 600, secondary: 100 }, - { color: "yellow", primary: 500, secondary: 100 }, - { color: "purple", primary: 600, secondary: 100 }, - { color: "teal", primary: 600, secondary: 100 }, - { color: "orange", primary: 600, secondary: 100 }, - { color: "cyan", primary: 600, secondary: 100 }, - { color: "lime", primary: 500, secondary: 100 }, - { color: "pink", primary: 600, secondary: 100 } -] as const; - -const tw_colors = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - slate: { - 50: "#f8fafc", - 100: "#f1f5f9", - 200: "#e2e8f0", - 300: "#cbd5e1", - 400: "#94a3b8", - 500: "#64748b", - 600: "#475569", - 700: "#334155", - 800: "#1e293b", - 900: "#0f172a", - 950: "#020617" - }, - gray: { - 50: "#f9fafb", - 100: "#f3f4f6", - 200: "#e5e7eb", - 300: "#d1d5db", - 400: "#9ca3af", - 500: "#6b7280", - 600: "#4b5563", - 700: "#374151", - 800: "#1f2937", - 900: "#111827", - 950: "#030712" - }, - zinc: { - 50: "#fafafa", - 100: "#f4f4f5", - 200: "#e4e4e7", - 300: "#d4d4d8", - 400: "#a1a1aa", - 500: "#71717a", - 600: "#52525b", - 700: "#3f3f46", - 800: "#27272a", - 900: "#18181b", - 950: "#09090b" - }, - neutral: { - 50: "#fafafa", - 100: "#f5f5f5", - 200: "#e5e5e5", - 300: "#d4d4d4", - 400: "#a3a3a3", - 500: "#737373", - 600: "#525252", - 700: "#404040", - 800: "#262626", - 900: "#171717", - 950: "#0a0a0a" - }, - stone: { - 50: "#fafaf9", - 100: "#f5f5f4", - 200: "#e7e5e4", - 300: "#d6d3d1", - 400: "#a8a29e", - 500: "#78716c", - 600: "#57534e", - 700: "#44403c", - 800: "#292524", - 900: "#1c1917", - 950: "#0c0a09" - }, - red: { - 50: "#fef2f2", - 100: "#fee2e2", - 200: "#fecaca", - 300: "#fca5a5", - 400: "#f87171", - 500: "#ef4444", - 600: "#dc2626", - 700: "#b91c1c", - 800: "#991b1b", - 900: "#7f1d1d", - 950: "#450a0a" - }, - orange: { - 50: "#fff7ed", - 100: "#ffedd5", - 200: "#fed7aa", - 300: "#fdba74", - 400: "#fb923c", - 500: "#f97316", - 600: "#ea580c", - 700: "#c2410c", - 800: "#9a3412", - 900: "#7c2d12", - 950: "#431407" - }, - amber: { - 50: "#fffbeb", - 100: "#fef3c7", - 200: "#fde68a", - 300: "#fcd34d", - 400: "#fbbf24", - 500: "#f59e0b", - 600: "#d97706", - 700: "#b45309", - 800: "#92400e", - 900: "#78350f", - 950: "#451a03" - }, - yellow: { - 50: "#fefce8", - 100: "#fef9c3", - 200: "#fef08a", - 300: "#fde047", - 400: "#facc15", - 500: "#eab308", - 600: "#ca8a04", - 700: "#a16207", - 800: "#854d0e", - 900: "#713f12", - 950: "#422006" - }, - lime: { - 50: "#f7fee7", - 100: "#ecfccb", - 200: "#d9f99d", - 300: "#bef264", - 400: "#a3e635", - 500: "#84cc16", - 600: "#65a30d", - 700: "#4d7c0f", - 800: "#3f6212", - 900: "#365314", - 950: "#1a2e05" - }, - green: { - 50: "#f0fdf4", - 100: "#dcfce7", - 200: "#bbf7d0", - 300: "#86efac", - 400: "#4ade80", - 500: "#22c55e", - 600: "#16a34a", - 700: "#15803d", - 800: "#166534", - 900: "#14532d", - 950: "#052e16" - }, - emerald: { - 50: "#ecfdf5", - 100: "#d1fae5", - 200: "#a7f3d0", - 300: "#6ee7b7", - 400: "#34d399", - 500: "#10b981", - 600: "#059669", - 700: "#047857", - 800: "#065f46", - 900: "#064e3b", - 950: "#022c22" - }, - teal: { - 50: "#f0fdfa", - 100: "#ccfbf1", - 200: "#99f6e4", - 300: "#5eead4", - 400: "#2dd4bf", - 500: "#14b8a6", - 600: "#0d9488", - 700: "#0f766e", - 800: "#115e59", - 900: "#134e4a", - 950: "#042f2e" - }, - cyan: { - 50: "#ecfeff", - 100: "#cffafe", - 200: "#a5f3fc", - 300: "#67e8f9", - 400: "#22d3ee", - 500: "#06b6d4", - 600: "#0891b2", - 700: "#0e7490", - 800: "#155e75", - 900: "#164e63", - 950: "#083344" - }, - sky: { - 50: "#f0f9ff", - 100: "#e0f2fe", - 200: "#bae6fd", - 300: "#7dd3fc", - 400: "#38bdf8", - 500: "#0ea5e9", - 600: "#0284c7", - 700: "#0369a1", - 800: "#075985", - 900: "#0c4a6e", - 950: "#082f49" - }, - blue: { - 50: "#eff6ff", - 100: "#dbeafe", - 200: "#bfdbfe", - 300: "#93c5fd", - 400: "#60a5fa", - 500: "#3b82f6", - 600: "#2563eb", - 700: "#1d4ed8", - 800: "#1e40af", - 900: "#1e3a8a", - 950: "#172554" - }, - indigo: { - 50: "#eef2ff", - 100: "#e0e7ff", - 200: "#c7d2fe", - 300: "#a5b4fc", - 400: "#818cf8", - 500: "#6366f1", - 600: "#4f46e5", - 700: "#4338ca", - 800: "#3730a3", - 900: "#312e81", - 950: "#1e1b4b" - }, - violet: { - 50: "#f5f3ff", - 100: "#ede9fe", - 200: "#ddd6fe", - 300: "#c4b5fd", - 400: "#a78bfa", - 500: "#8b5cf6", - 600: "#7c3aed", - 700: "#6d28d9", - 800: "#5b21b6", - 900: "#4c1d95", - 950: "#2e1065" - }, - purple: { - 50: "#faf5ff", - 100: "#f3e8ff", - 200: "#e9d5ff", - 300: "#d8b4fe", - 400: "#c084fc", - 500: "#a855f7", - 600: "#9333ea", - 700: "#7e22ce", - 800: "#6b21a8", - 900: "#581c87", - 950: "#3b0764" - }, - fuchsia: { - 50: "#fdf4ff", - 100: "#fae8ff", - 200: "#f5d0fe", - 300: "#f0abfc", - 400: "#e879f9", - 500: "#d946ef", - 600: "#c026d3", - 700: "#a21caf", - 800: "#86198f", - 900: "#701a75", - 950: "#4a044e" - }, - pink: { - 50: "#fdf2f8", - 100: "#fce7f3", - 200: "#fbcfe8", - 300: "#f9a8d4", - 400: "#f472b6", - 500: "#ec4899", - 600: "#db2777", - 700: "#be185d", - 800: "#9d174d", - 900: "#831843", - 950: "#500724" - }, - rose: { - 50: "#fff1f2", - 100: "#ffe4e6", - 200: "#fecdd3", - 300: "#fda4af", - 400: "#fb7185", - 500: "#f43f5e", - 600: "#e11d48", - 700: "#be123c", - 800: "#9f1239", - 900: "#881337", - 950: "#4c0519" - } -}; - -export const colors = color_values.reduce( - (acc, { color, primary, secondary }) => ({ - ...acc, - [color]: { - primary: tw_colors[color][primary], - secondary: tw_colors[color][secondary] - } - }), - {} as Colors -); diff --git a/6.13.0/theme/src/index.ts b/6.13.0/theme/src/index.ts deleted file mode 100644 index bd1cb299eaa9b1ae2f6bd0c1973fa12d0c4cdb57..0000000000000000000000000000000000000000 --- a/6.13.0/theme/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// export { default as reset } from "./reset.css"; -// export { default as global } from "./global.css"; -// export { default as css } from "./pollen.css"; -// export { default as typography } from "./typography.css"; - -export * from "./colors.js"; diff --git a/6.13.0/timer/Index.svelte b/6.13.0/timer/Index.svelte deleted file mode 100644 index 7fc7857ad7235b62c97ffb4fccba78a6c9d89fd9..0000000000000000000000000000000000000000 --- a/6.13.0/timer/Index.svelte +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/6.13.0/timer/package.json b/6.13.0/timer/package.json deleted file mode 100644 index 69e4fd022b1204bf416a79f66fbf6f1c0e859744..0000000000000000000000000000000000000000 --- a/6.13.0/timer/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@gradio/timer", - "version": "0.4.9", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "dependencies": { - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/timer" - } -} diff --git a/6.13.0/timer/types.ts b/6.13.0/timer/types.ts deleted file mode 100644 index 292d729b4daf9b93f8261167f14496b64a103084..0000000000000000000000000000000000000000 --- a/6.13.0/timer/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimerProps { - value: number; - active: boolean; -} - -export interface TimerEvents { - tick: never; - clear_status: never; -} diff --git a/6.13.0/tooltip/package.json b/6.13.0/tooltip/package.json deleted file mode 100644 index 1b699440866a7a7c79de9e7575bc07b5373465fe..0000000000000000000000000000000000000000 --- a/6.13.0/tooltip/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@gradio/tooltip", - "version": "0.2.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/tooltip" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.js", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - } -} diff --git a/6.13.0/tooltip/src/Tooltip.svelte b/6.13.0/tooltip/src/Tooltip.svelte deleted file mode 100644 index c9c9ecca6357234953144bcf6a0dbe7ee5e822de..0000000000000000000000000000000000000000 --- a/6.13.0/tooltip/src/Tooltip.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - {text} -
- - diff --git a/6.13.0/tooltip/src/index.ts b/6.13.0/tooltip/src/index.ts deleted file mode 100644 index b89ac870e5bbf6d90058c6e25cb9d74b626b3809..0000000000000000000000000000000000000000 --- a/6.13.0/tooltip/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { tooltip } from "./tooltip"; diff --git a/6.13.0/tooltip/src/tooltip.ts b/6.13.0/tooltip/src/tooltip.ts deleted file mode 100644 index 09403f9438805f29a32579b8e98a25f3aae37737..0000000000000000000000000000000000000000 --- a/6.13.0/tooltip/src/tooltip.ts +++ /dev/null @@ -1,49 +0,0 @@ -import Tooltip from "./Tooltip.svelte"; - -interface ActionArgs { - color: string; - text: string; -} - -export function tooltip( - element: HTMLElement | SVGElement, - { color, text }: ActionArgs -): any { - let tooltipComponent: Tooltip; - function mouse_over(event: MouseEvent): MouseEvent { - tooltipComponent = new Tooltip({ - props: { - text, - x: event.pageX, - y: event.pageY, - color - }, - target: document.body - }); - - return event; - } - function mouseMove(event: MouseEvent): void { - tooltipComponent.$set({ - x: event.pageX, - y: event.pageY - }); - } - function mouseLeave(): void { - tooltipComponent.$destroy(); - } - - const el = element as HTMLElement; - - el.addEventListener("mouseover", mouse_over); - el.addEventListener("mouseleave", mouseLeave); - el.addEventListener("mousemove", mouseMove); - - return { - destroy() { - el.removeEventListener("mouseover", mouse_over); - el.removeEventListener("mouseleave", mouseLeave); - el.removeEventListener("mousemove", mouseMove); - } - }; -} diff --git a/6.13.0/tootils/package.json b/6.13.0/tootils/package.json deleted file mode 100644 index 39683201d83bfc3a5ffaeb655426076b27f40944..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@self/tootils", - "version": "0.13.0", - "description": "Internal test utilities", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": "./src/index.ts", - "./render": "./src/render.ts", - "./shared-prop-tests": "./src/shared-prop-tests.ts", - "./app-launcher": "./src/app-launcher.ts", - "./download-command": "./src/download-command.ts" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.13.0/tootils/src/app-launcher.ts b/6.13.0/tootils/src/app-launcher.ts deleted file mode 100644 index a320667e5764ec306dec64eabbfa998bdd85169c..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/app-launcher.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { spawn, type ChildProcess } from "node:child_process"; -import http from "http"; -import net from "net"; -import path from "path"; -import fs from "fs"; -import os from "os"; -import url from "url"; - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -const ROOT_DIR = path.resolve(__dirname, "../../.."); - -export interface GradioApp { - port: number; - process: ChildProcess; -} - -export function killGradioApp(process: ChildProcess): void { - try { - process.kill("SIGTERM"); - } catch { - // Process may already be dead - } -} - -export async function findFreePort( - startPort: number, - endPort: number -): Promise { - for (let port = startPort; port < endPort; port++) { - if (await isPortFree(port)) { - return port; - } - } - throw new Error(`Could not find free port in range ${startPort}-${endPort}`); -} - -function isPortFree(port: number): Promise { - return new Promise((resolve, reject) => { - const sock = net.createConnection(port, "127.0.0.1"); - sock.once("connect", () => { - sock.end(); - resolve(false); - }); - sock.once("error", (e: NodeJS.ErrnoException) => { - sock.destroy(); - if (e.code === "ECONNREFUSED") { - resolve(true); - } else { - reject(e); - } - }); - }); -} - -/** - * Poll the server with HTTP GET requests until it returns a response. - * Gradio prints "Running on local URL:" before the server is fully ready, - * so we need to verify it actually responds to HTTP requests. - */ -async function waitForServerReady( - port: number, - timeoutMs: number = 15000 -): Promise { - const start = Date.now(); - const pollInterval = 200; - - while (Date.now() - start < timeoutMs) { - try { - await new Promise((resolve, reject) => { - // Use HEAD on /gradio_api/info to avoid triggering SSR rendering on - // the root URL, which could block Gradio's own startup health check. - const req = http.request( - `http://127.0.0.1:${port}/gradio_api/info`, - { method: "HEAD", timeout: 2000 }, - (res) => { - res.resume(); // drain the response - resolve(); - } - ); - req.on("error", reject); - req.on("timeout", () => { - req.destroy(); - reject(new Error("request timeout")); - }); - req.end(); - }); - return; // Server responded successfully - } catch { - // Server not ready yet, wait and retry - await new Promise((r) => setTimeout(r, pollInterval)); - } - } - throw new Error( - `Server on port ${port} did not become ready within ${timeoutMs}ms` - ); -} - -export function getTestcases(demoName: string): string[] { - const demoDir = path.join(ROOT_DIR, "demo", demoName); - if (!fs.existsSync(demoDir)) { - return []; - } - - return fs - .readdirSync(demoDir) - .filter((f) => f.endsWith("_testcase.py")) - .map((f) => path.basename(f, ".py")); -} - -// Check if a testcase file exists for this demo -export function hasTestcase(demoName: string, testcaseName: string): boolean { - const testcaseFile = path.join( - ROOT_DIR, - "demo", - demoName, - `${testcaseName}_testcase.py` - ); - return fs.existsSync(testcaseFile); -} - -// Get the path to a demo's Python file -function getDemoFilePath(demoName: string, testcaseName?: string): string { - if (testcaseName) { - return path.join(ROOT_DIR, "demo", demoName, `${testcaseName}_testcase.py`); - } - return path.join(ROOT_DIR, "demo", demoName, "run.py"); -} - -export async function launchGradioApp( - demoName: string, - workerIndex: number = 0, - timeout: number = 60000, - testcaseName?: string -): Promise { - // Partition ports by worker index to avoid collisions - const basePort = 7860 + workerIndex * 100; - const port = await findFreePort(basePort, basePort + 99); - - // Get the path to the demo file - const demoFilePath = getDemoFilePath(demoName, testcaseName); - - // Create unique directories for this instance to avoid cache conflicts - const instanceId = testcaseName - ? `${demoName}_${testcaseName}_${port}` - : `${demoName}_${port}`; - const instanceDir = path.join(os.tmpdir(), `gradio_test_${instanceId}`); - const cacheDir = path.join(instanceDir, "cached_examples"); - const tempDir = path.join(instanceDir, "temp"); - - if (!fs.existsSync(instanceDir)) { - fs.mkdirSync(instanceDir, { recursive: true }); - } - - // Run the demo file directly - the demo's own if __name__ == "__main__" block - // has the correct launch parameters (show_error, etc.) - const childProcess = spawn("python", [demoFilePath], { - stdio: "pipe", - cwd: ROOT_DIR, - env: { - ...process.env, - PYTHONUNBUFFERED: "true", - GRADIO_ANALYTICS_ENABLED: "False", - GRADIO_IS_E2E_TEST: "1", - GRADIO_RESET_EXAMPLES_CACHE: "True", - // Control the port via environment variable - GRADIO_SERVER_PORT: port.toString(), - // Use unique directories per instance to avoid conflicts - GRADIO_EXAMPLES_CACHE: cacheDir, - GRADIO_TEMP_DIR: tempDir - } - }); - - childProcess.stdout?.setEncoding("utf8"); - childProcess.stderr?.setEncoding("utf8"); - - // Wait for app to be ready - return new Promise((resolve, reject) => { - const timeoutId = setTimeout(() => { - killGradioApp(childProcess); - reject( - new Error(`Gradio app ${demoName} failed to start within ${timeout}ms`) - ); - }, timeout); - - let output = ""; - let startupDetected = false; - - function handleOutput(data: string): void { - output += data; - // Check for Gradio's startup message - if ( - !startupDetected && - (data.includes("Running on local URL:") || - data.includes(`Uvicorn running on`)) - ) { - startupDetected = true; - clearTimeout(timeoutId); - // The startup message is printed before the server is fully ready. - // Poll with HTTP requests to ensure it actually responds. - waitForServerReady(port) - .then(() => resolve({ port, process: childProcess })) - .catch(reject); - } - } - - childProcess.stdout?.on("data", handleOutput); - childProcess.stderr?.on("data", handleOutput); - - childProcess.on("error", (err) => { - clearTimeout(timeoutId); - reject(err); - }); - - childProcess.on("exit", (code) => { - if (code !== 0 && code !== null) { - clearTimeout(timeoutId); - reject( - new Error( - `Gradio app ${demoName} exited with code ${code}.\nOutput: ${output}` - ) - ); - } - }); - }); -} diff --git a/6.13.0/tootils/src/download-command.ts b/6.13.0/tootils/src/download-command.ts deleted file mode 100644 index 2d99d0883c6b5e985d21c18902e61db60ccaa6dc..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/download-command.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { BrowserCommand } from "vitest/node"; -import { resolve } from "path"; -import { readFile } from "fs/promises"; - -/** - * Vitest browser command that captures a real file download triggered by - * clicking an element. Runs server-side with access to the Playwright page. - * - * Sets up page.waitForEvent("download") BEFORE clicking, so the download - * event is never missed. - */ -export const expect_download: BrowserCommand< - [selector: string, options?: { timeout?: number }], - { suggested_filename: string; content: string | null } -> = async (context, selector, options) => { - const timeout = options?.timeout ?? 5000; - const provider = context.provider as any; - const page = provider.getPage(context.sessionId); - // Tests run inside an iframe; use the iframe locator to click - // but listen for the download event on the parent page. - const iframe = (context as any).iframe; - - const [download] = await Promise.all([ - page.waitForEvent("download", { timeout }), - iframe.locator(selector).click() - ]); - - const suggested_filename = download.suggestedFilename(); - const path = await download.path(); - - let content: string | null = null; - if (path) { - const fs = await import("fs/promises"); - content = await fs.readFile(path, "utf-8"); - } - - return { - suggested_filename, - content - }; -}; - -/** - * Vitest browser command that sets files on an element. - * Resolves fixture URL paths (e.g. "/test/test_files/bus.png") to absolute - * disk paths and uses Playwright's setInputFiles(). - */ -export const set_file_inputs: BrowserCommand< - [file_urls: string[], selector?: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - const iframe = (context as any).iframe; - - const paths = file_urls.map((url) => resolve(root, url.replace(/^\//, ""))); - - await iframe - .locator(selector ?? 'input[type="file"]') - .first() - .setInputFiles(paths); -}; - -interface Drop_file_spec { - data: string; // base64 - name: string; - mime_type: string; -} - -/** - * Vitest browser command that simulates dropping files onto an element. - * Reads files from disk, transfers them as base64 into the browser context, - * and dispatches dragenter, dragover, and drop events with a real DataTransfer. - */ -export const drop_files: BrowserCommand< - [file_urls: string[], selector: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - - const files: Drop_file_spec[] = await Promise.all( - file_urls.map(async (url) => { - const abs = resolve(root, url.replace(/^\//, "")); - const data = (await readFile(abs)).toString("base64"); - const name = abs.split("/").pop()!; - const ext = name.split(".").pop()!.toLowerCase(); - const mime_type = MIME_TYPES[ext] || "application/octet-stream"; - return { data, name, mime_type }; - }) - ); - - const iframe = (context as any).iframe; - await iframe - .locator(selector) - .first() - .evaluate((target: Element, files: Drop_file_spec[]) => { - const dt = new DataTransfer(); - for (const f of files) { - const bytes = Uint8Array.from(atob(f.data), (c) => c.charCodeAt(0)); - dt.items.add(new File([bytes], f.name, { type: f.mime_type })); - } - - target.dispatchEvent( - new DragEvent("dragenter", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("dragover", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("drop", { dataTransfer: dt, bubbles: true }) - ); - }, files); -}; - -const MIME_TYPES: Record = { - txt: "text/plain", - csv: "text/csv", - json: "application/json", - pdf: "application/pdf", - jpg: "image/jpeg", - jpeg: "image/jpeg", - png: "image/png", - gif: "image/gif", - webp: "image/webp", - svg: "image/svg+xml", - mp4: "video/mp4", - webm: "video/webm", - ogg: "video/ogg", - avi: "video/x-msvideo", - wav: "audio/wav", - mp3: "audio/mpeg", - flac: "audio/flac" -}; diff --git a/6.13.0/tootils/src/download.ts b/6.13.0/tootils/src/download.ts deleted file mode 100644 index c6217fc6695b81fe685bcff9593ed9cab6095a3a..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/download.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { commands } from "vitest/browser"; -import type { FileData } from "@gradio/client"; - -export interface DownloadResult { - suggested_filename: string; - content: string | null; -} - -/** - * Clicks an element and captures the resulting file download. - * - * Uses a real browser download via Playwright under the hood — - * the file is actually downloaded and its content is readable. - * - * @param selector - CSS selector for the element to click - * @param options - Optional timeout (default 5000ms) - * @returns The downloaded file's suggested filename and text content - * - * @example - * ```ts - * const { suggested_filename, content } = await download_file("a.download-link"); - * expect(suggested_filename).toBe("data.csv"); - * expect(content).toContain("col1,col2"); - * ``` - */ -export async function download_file( - selector: string, - options?: { timeout?: number } -): Promise { - return (commands as any).expect_download(selector, options); -} - -/** - * Sets files on an `` element using real file fixtures. - * - * Accepts one or more FileData fixtures (e.g. TEST_JPG, TEST_PNG) and - * sets them on the file input, triggering the browser's native change event. - * - * @param files - One or more FileData fixtures to upload - * @param selector - CSS selector for the file input (default: 'input[type="file"]') - * - * @example - * ```ts - * import { render, upload_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await upload_file(TEST_JPG); - * - * expect(upload).toHaveBeenCalled(); - * ``` - */ -export async function upload_file( - files: FileData | FileData[], - selector?: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).set_file_inputs(urls, selector); -} - -/** - * Simulates dragging and dropping files onto an element. - * - * Reads the fixture files from disk, constructs a real DataTransfer - * with File objects, and dispatches dragenter, dragover, and drop events - * on the target element. - * - * @param files - One or more FileData fixtures to drop - * @param selector - CSS selector for the drop target element - * - * @example - * ```ts - * import { render, drop_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await drop_file(TEST_JPG, "[aria-label='Click to upload or drop files']"); - * - * await vi.waitFor(() => expect(upload).toHaveBeenCalled()); - * ``` - */ -export async function drop_file( - files: FileData | FileData[], - selector: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).drop_files(urls, selector); -} diff --git a/6.13.0/tootils/src/fixtures.ts b/6.13.0/tootils/src/fixtures.ts deleted file mode 100644 index 95adcab69ee5186eb2533321b64e8fd08932a113..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/fixtures.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { FileData } from "@gradio/client"; - -const BASE = "/test/test_files"; - -function fixture(filename: string, mime_type: string, size: number): FileData { - const url = `${BASE}/${filename}`; - return new FileData({ - path: url, - url, - orig_name: filename, - size, - mime_type - }); -} - -export const TEST_TXT = fixture("alphabet.txt", "text/plain", 26); -export const TEST_JPG = fixture("cheetah1.jpg", "image/jpeg", 20552); -export const TEST_PNG = fixture("bus.png", "image/png", 1951); -export const TEST_MP4 = fixture("video_sample.mp4", "video/mp4", 261179); -export const TEST_WAV = fixture("audio_sample.wav", "audio/wav", 16136); -export const TEST_PDF = fixture("sample_file.pdf", "application/pdf", 10558); diff --git a/6.13.0/tootils/src/index.ts b/6.13.0/tootils/src/index.ts deleted file mode 100644 index 5ac7a8723c2c74c4d04fc0c2555ced0e6f8388f5..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/index.ts +++ /dev/null @@ -1,224 +0,0 @@ -import { test as base, type Locator, type Page } from "@playwright/test"; -import { spy } from "tinyspy"; -import url from "url"; -import path from "path"; -import fsPromises from "fs/promises"; -import type { ChildProcess } from "node:child_process"; - -import type { SvelteComponent } from "svelte"; -import type { SpyFn } from "tinyspy"; - -import { launchGradioApp, killGradioApp, hasTestcase } from "./app-launcher"; - -export function get_text(el: T): string { - return el.innerText.trim(); -} - -export function wait(n: number): Promise { - return new Promise((r) => setTimeout(r, n)); -} - -const ROOT_DIR = path.resolve( - url.fileURLToPath(import.meta.url), - "../../../.." -); - -// Extract testcase name from test title if present -// Test titles can be: -// - "case eager_caching_examples: ..." -// - "test case multimodal_messages chatinterface works..." -function extractTestcaseFromTitle( - title: string, - demoName: string -): string | undefined { - // Try pattern: "case :" or "test case " - const patterns = [/^case\s+(\w+):/, /^test case\s+(\w+)\s/]; - - for (const pattern of patterns) { - const match = title.match(pattern); - if (match) { - const caseName = match[1]; - // Check if this is a testcase (not the main demo) - if (hasTestcase(demoName, caseName)) { - return caseName; - } - } - } - return undefined; -} - -// Cache for launched apps - key is "demoName" or "demoName_testcaseName" -const appCache = new Map< - string, - { port: number; process: ChildProcess; refCount: number } ->(); - -// Test fixture that launches Gradio app per test -const test_normal = base.extend<{ setup: void }>({ - setup: [ - async ({ page }, use, testInfo): Promise => { - const { file, title } = testInfo; - const demoName = path.basename(file, ".spec.ts"); - - // Check if this is a reload test (they manage their own apps) - if (demoName.endsWith(".reload")) { - // For reload tests, don't launch an app - they handle it themselves - await use(); - return; - } - - // Check if this test is for a specific testcase - const testcaseName = extractTestcaseFromTitle(title, demoName); - - // Cache key includes testcase if present - const cacheKey = testcaseName ? `${demoName}_${testcaseName}` : demoName; - - let appInfo = appCache.get(cacheKey); - - if (!appInfo) { - // Launch the app for this test - const workerIndex = testInfo.workerIndex; - try { - const { port, process } = await launchGradioApp( - demoName, - workerIndex, - 60000, - testcaseName - ); - appInfo = { port, process, refCount: 0 }; - appCache.set(cacheKey, appInfo); - } catch (error) { - console.error(`Failed to launch app for ${cacheKey}:`, error); - throw error; - } - } - - appInfo.refCount++; - - // Navigate to the app - await page.goto(`http://localhost:${appInfo.port}`); - - if ( - process.env?.GRADIO_SSR_MODE?.toLowerCase() === "true" && - !( - demoName.includes("multipage") || - demoName.includes("chatinterface_deep_link") - ) - ) { - await page.waitForSelector("#svelte-announcer"); - } - await page.waitForLoadState("load"); - - await use(); - - // Decrement ref count - appInfo.refCount--; - - // Note: We don't kill the app here because other tests might - // still need it. The app will be killed when the process exits. - }, - { auto: true } - ] -}); - -// Cleanup apps when the process exits -process.on("exit", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } -}); - -process.on("SIGINT", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -process.on("SIGTERM", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -export const test = test_normal; - -export async function wait_for_event( - component: SvelteComponent, - event: string -): Promise { - const mock = spy(); - return new Promise((res) => { - component.$on(event, () => { - mock(); - res(mock); - }); - }); -} - -export interface ActionReturn< - Parameter = never, - Attributes extends Record = Record -> { - update?: [Parameter] extends [never] ? never : (parameter: Parameter) => void; - destroy?: () => void; - /** - * ### DO NOT USE THIS - * This exists solely for type-checking and has no effect at runtime. - * Set this through the `Attributes` generic instead. - */ - $$_attributes?: Attributes; -} - -export { expect } from "@playwright/test"; - -export const drag_and_drop_file = async ( - page: Page, - selector: string | Locator, - filePath: string, - fileName: string, - fileType = "", - count = 1 -): Promise => { - const buffer = (await fsPromises.readFile(filePath)).toString("base64"); - - const dataTransfer = await page.evaluateHandle( - async ({ bufferData, localFileName, localFileType, count }) => { - const dt = new DataTransfer(); - - const blobData = await fetch(bufferData).then((res) => res.blob()); - - const file = new File([blobData], localFileName, { - type: localFileType - }); - - for (let i = 0; i < count; i++) { - dt.items.add(file); - } - return dt; - }, - { - bufferData: `data:application/octet-stream;base64,${buffer}`, - localFileName: fileName, - localFileType: fileType, - count - } - ); - - if (typeof selector === "string") { - await page.dispatchEvent(selector, "drop", { dataTransfer }); - } else { - await selector.dispatchEvent("drop", { dataTransfer }); - } -}; - -export async function go_to_testcase( - page: Page, - _test_case: string -): Promise { - // With the new setup, each testcase launches its own Gradio app. - // The fixture detects the testcase from the test title and launches - // the correct app, so this function is now a no-op. - // The page is already at the correct testcase app. -} diff --git a/6.13.0/tootils/src/render.ts b/6.13.0/tootils/src/render.ts deleted file mode 100644 index 60bc02a263f3b8f2c32ef9b0cef57c0396a0fb21..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/render.ts +++ /dev/null @@ -1,314 +0,0 @@ -import { - getQueriesForElement, - prettyDOM, - fireEvent as dtlFireEvent -} from "@testing-library/dom"; -import { tick, mount, unmount } from "svelte"; -import type { SvelteComponent, Component } from "svelte"; - -import type { - queries, - Queries, - BoundFunction, - EventType -} from "@testing-library/dom"; -import { vi, type Mock } from "vitest"; -import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils"; -import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker"; -import { _ } from "svelte-i18n"; - -const containerCache = new Map(); -const componentCache = new Set(); - -type ComponentType = Component; - -export type RenderResult< - C extends SvelteComponent, - Q extends Queries = typeof queries -> = { - container: HTMLElement; - component: C; - debug: (el?: HTMLElement | DocumentFragment) => void; - unmount: () => void; -} & { [P in keyof Q]: BoundFunction }; -export interface ILoadingStatus { - eta: number | null; - status: "pending" | "error" | "complete" | "generating" | "streaming"; - queue: boolean; - queue_position: number | null; - queue_size?: number; - fn_index: number; - message?: string | null; - scroll_to_output?: boolean; - show_progress?: "full" | "minimal" | "hidden"; - time_limit?: number | null | undefined; - progress?: { - progress: number | null; - index: number | null; - length: number | null; - unit: string | null; - desc: string | null; - }[]; - validation_error?: string | null; - type: "input" | "output"; - stream_state: "open" | "closed" | "waiting" | null; -} - -const loading_status: ILoadingStatus = { - eta: 0, - queue_position: 1, - queue_size: 1, - queue: true, - message: null, - time_limit: null, - progress: [], - validation_error: null, - type: "output", - stream_state: null, - status: "complete" as ILoadingStatus["status"], - scroll_to_output: false, - fn_index: 0, - show_progress: "full" as ILoadingStatus["show_progress"] -}; - -export interface RenderOptions { - container?: HTMLElement; - queries?: Q; -} - -export async function render< - Events extends Record, - Props extends Record, - T extends SvelteComponent, - X extends Record ->( - Component: ComponentType | { default: ComponentType }, - props?: Omit & { - loading_status?: LoadingStatus; - }, - options?: { - container?: HTMLElement; - } -): Promise< - RenderResult & { - listen: (event_name: string, opts?: { retrospective?: boolean }) => Mock; - set_data: (data: Record) => Promise; - get_data: () => Promise>; - } -> { - let container: HTMLElement; - if (!options?.container) { - container = document.body; - } else { - container = options.container; - } - - const target = container.appendChild(document.createElement("div")); - - const ComponentConstructor: ComponentType = - //@ts-ignore - Component.default || Component; - - const id = Math.floor(Math.random() * 1000000); - - let component_set_data: (data: Record) => void; - let component_get_data: () => Promise>; - - const mock_register = ( - _id: number, - set_data: (data: Record) => void, - get_data: () => Promise> - ): void => { - component_set_data = set_data; - component_get_data = get_data; - }; - - const event_listeners = new Map void>>(); - const event_buffer: Array<{ event: string; data: any }> = []; - - function notify_listeners(event: string, data: any): void { - const listeners = event_listeners.get(event); - if (listeners) { - for (const listener of listeners) { - listener(data); - } - } - } - - const dispatcher = (_id: number, event: string, data: any): void => { - event_buffer.push({ event, data }); - notify_listeners(event, data); - }; - - function listen( - event_name: string, - opts?: { retrospective?: boolean } - ): Mock { - const fn = vi.fn(); - if (!event_listeners.has(event_name)) { - event_listeners.set(event_name, new Set()); - } - event_listeners.get(event_name)!.add(fn); - - if (opts?.retrospective) { - for (const entry of event_buffer) { - if (entry.event === event_name) { - fn(entry.data); - } - } - } - - return fn; - } - - const i18nFormatter = (s: string | null | undefined): string => s ?? ""; - - const shared_props_obj: Record = { - id, - target, - theme_mode: "light" as const, - version: "2.0.0", - formatter: i18nFormatter, - client: {} as any, - load_component: () => Promise.resolve({ default: {} as any }), - show_progress: true, - api_prefix: "", - server: {} as any, - show_label: true, - register_component: mock_register, - dispatcher - }; - - const component_props_obj: Record = { - i18n: i18nFormatter - }; - - if (props) { - for (const key in props) { - const value = (props as any)[key]; - if (allowed_shared_props.includes(key as any)) { - shared_props_obj[key] = value; - } else { - component_props_obj[key] = value; - } - } - } - - shared_props_obj.loading_status = props?.loading_status - ? props.loading_status - : loading_status; - - const componentProps = { - shared_props: shared_props_obj, - props: { - ...component_props_obj - }, - ...shared_props_obj - }; - - const component = mount(ComponentConstructor, { - target, - props: componentProps - }) as T; - - containerCache.set(container, { target, component }); - componentCache.add(component); - - await tick(); - - return { - container, - component, - listen, - set_data: async (data: Record) => { - const r = component_set_data(data); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return r; - }, - get_data: () => component_get_data(), - //@ts-ignore - debug: (el = container): void => console.warn(prettyDOM(el)), - unmount: (): void => { - if (componentCache.has(component)) { - unmount(component); - } - }, - ...getQueriesForElement(container) - }; -} - -const cleanupAtContainer = (container: HTMLElement): void => { - const { target, component } = containerCache.get(container); - - if (componentCache.has(component)) { - unmount(component); - } - - if (target.parentNode === document.body) { - document.body.removeChild(target); - } - - containerCache.delete(container); -}; - -export function cleanup(): void { - Array.from(containerCache.keys()).forEach(cleanupAtContainer); - document.body.innerHTML = ""; -} - -type AsyncFireObject = { - [K in EventType]: ( - element: Document | Element | Window | Node, - options?: object - ) => Promise; -}; - -export const fireEvent = Object.keys(dtlFireEvent).reduce((acc, key) => { - const _key = key as EventType; - return { - ...acc, - [_key]: async ( - element: Document | Element | Window, - options: object = {} - ): Promise => { - const event = dtlFireEvent[_key](element, options); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return event; - } - }; -}, {} as AsyncFireObject); - -export type FireFunction = ( - element: Document | Element | Window, - event: Event -) => Promise; - -export { download_file, upload_file, drop_file } from "./download.js"; - -/** - * Creates a mock client suitable for components that use file uploads. - * The upload mock echoes back the input FileData unchanged. - */ -export function mock_client(): Record { - return { - upload: async (file_data: any[]) => file_data, - stream: async () => ({ onmessage: null, close: () => {} }) - }; -} -export { - TEST_TXT, - TEST_JPG, - TEST_PNG, - TEST_MP4, - TEST_WAV, - TEST_PDF -} from "./fixtures.js"; -export * from "@testing-library/dom"; diff --git a/6.13.0/tootils/src/shared-prop-tests.ts b/6.13.0/tootils/src/shared-prop-tests.ts deleted file mode 100644 index b8f58e68a13e368fd4a1f1d6f2e246260b82bcd0..0000000000000000000000000000000000000000 --- a/6.13.0/tootils/src/shared-prop-tests.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, test, expect, afterEach } from "vitest"; -import { render, cleanup } from "./render"; - -const loading_status = { - status: "complete", - queue_position: null, - queue_size: null, - eta: null, - message: null -}; - -export interface SharedPropTestConfig { - /** The Svelte component to test */ - component: any; - /** Minimum props required to render the component without errors */ - base_props: Record; - /** Display name for test output */ - name: string; - /** - * Some components don't render labels (e.g. HTML, Markdown). - * Set to false to skip label-related tests. - * @default true - */ - has_label?: boolean; - /** - * Whether the component renders validation_error text. - * Not all components support this. Set to false to skip. - * @default true - */ - has_validation_error?: boolean; - /** - * Some components (e.g. Accordion) map visible=false to "hidden" - * instead of removing from the DOM. Set to true to expect hidden - * behaviour rather than removal. - * @default false - */ - visible_false_hides?: boolean; - /** - * Whether the component is wrapped in a Block (which renders a `.block` - * element). Components like Button render a bare element instead. - * Set to false to skip `.block` selector checks. - * @default true - */ - has_block_wrapper?: boolean; -} - -export function run_shared_prop_tests(config: SharedPropTestConfig): void { - const { - component, - base_props, - name, - has_label = true, - has_validation_error = true, - visible_false_hides = false, - has_block_wrapper = true - } = config; - - const label = "Test Label"; - - function make_props( - overrides: Record = {} - ): Record { - return { - ...base_props, - loading_status: { ...loading_status, ...overrides }, - label, - ...overrides - }; - } - - describe(`${name}: shared props`, () => { - afterEach(() => cleanup()); - - test("elem_id is applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_id: "my-test-id" }) - ); - const el = container.querySelector("#my-test-id"); - expect(el).not.toBeNull(); - }); - - test("elem_classes are applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_classes: ["my-test-class"] }) - ); - const el = container.querySelector(".my-test-class"); - expect(el).not.toBeNull(); - }); - - test("visible: true renders the component", async () => { - const { container } = await render( - component, - make_props({ visible: true, elem_id: "visible-test" }) - ); - const el = has_block_wrapper - ? container.querySelector(".block") - : container.querySelector("#visible-test"); - expect(el).not.toBeNull(); - }); - - test("visible: 'hidden' hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: "hidden", elem_id: "hidden-test" }) - ); - - const el = result.container.querySelector("#hidden-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - - if (visible_false_hides) { - test("visible: false hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - } else { - test("visible: false removes the component from the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).toBeNull(); - }); - } - - if (has_label) { - test("label text is rendered", async () => { - const result = await render( - component, - make_props({ label: "My Custom Label", show_label: true }) - ); - const el = result.getByText("My Custom Label"); - expect(el).toBeTruthy(); - }); - - test("show_label: true makes the label visible", async () => { - const result = await render( - component, - make_props({ label: "Visible Label", show_label: true }) - ); - const el = result.getByText("Visible Label"); - expect(el).toBeVisible(); - }); - - test("show_label: false hides the label visually but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ label: "Hidden Label", show_label: false }) - ); - const el = result.getByText("Hidden Label"); - // The label remains in the DOM for screen readers via sr-only. - // sr-only uses clip/1px dimensions rather than display:none, - // so toBeVisible() won't catch it. We check the class directly. - expect(el.closest("[data-testid='block-info']")).toHaveClass("sr-only"); - }); - } - - if (has_validation_error) { - test("validation_error displays error text visibly", async () => { - const result = await render( - component, - make_props({ - validation_error: "This field is required", - show_validation_error: true - }) - ); - const el = result.getByText("This field is required"); - expect(el).toBeVisible(); - }); - } - }); -} diff --git a/6.13.0/upload/package.json b/6.13.0/upload/package.json deleted file mode 100644 index e69e58a5663f9425f287d6f4133191513f431980..0000000000000000000000000000000000000000 --- a/6.13.0/upload/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@gradio/upload", - "version": "0.17.9", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/upload" - } -} diff --git a/6.13.0/upload/src/ModifyUpload.svelte b/6.13.0/upload/src/ModifyUpload.svelte deleted file mode 100644 index 7c8db47405576b3b590d9bcb394d5e5848f7e240..0000000000000000000000000000000000000000 --- a/6.13.0/upload/src/ModifyUpload.svelte +++ /dev/null @@ -1,61 +0,0 @@ - - - - {#if editable} - onedit?.()} - /> - {/if} - - {#if undoable} - onundo?.()} - /> - {/if} - - {#if download} - - - - {/if} - - {#if children}{@render children()}{/if} - - { - onclear?.(); - event.stopPropagation(); - }} - /> - diff --git a/6.13.0/upload/src/Upload.svelte b/6.13.0/upload/src/Upload.svelte deleted file mode 100644 index 27183d59b8604ce79d9e90d44269ffb32bdb7225..0000000000000000000000000000000000000000 --- a/6.13.0/upload/src/Upload.svelte +++ /dev/null @@ -1,398 +0,0 @@ - - -{#if filetype === "clipboard"} - -{:else if uploading && show_progress} - {#if !hidden} - - {/if} -{:else} - -{/if} - - diff --git a/6.13.0/upload/src/UploadProgress.svelte b/6.13.0/upload/src/UploadProgress.svelte deleted file mode 100644 index 0ee9995f6d036d79048aca2705d530d3453ae7a1..0000000000000000000000000000000000000000 --- a/6.13.0/upload/src/UploadProgress.svelte +++ /dev/null @@ -1,199 +0,0 @@ - - -
- Uploading {files_with_progress.length} - {files_with_progress.length > 1 ? "files" : "file"}... - - {#if file_to_display} -
- -
- {getProgress(file_to_display)} -
-
- - {file_to_display.orig_name} - -
- {/if} -
- - diff --git a/6.13.0/upload/src/index.ts b/6.13.0/upload/src/index.ts deleted file mode 100644 index 0c2bdb5d7b2eb9c39953af027ae57cc674a0e377..0000000000000000000000000000000000000000 --- a/6.13.0/upload/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Upload } from "./Upload.svelte"; -export { default as ModifyUpload } from "./ModifyUpload.svelte"; -export { default as UploadProgress } from "./UploadProgress.svelte"; -export { create_drag } from "./utils"; diff --git a/6.13.0/upload/src/utils.ts b/6.13.0/upload/src/utils.ts deleted file mode 100644 index e961b85f75d154896c4be1656ed4e383bae0305b..0000000000000000000000000000000000000000 --- a/6.13.0/upload/src/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -interface DragActionOptions { - disable_click?: boolean; - accepted_types?: string | string[] | null; - mode?: "single" | "multiple" | "directory"; - on_drag_change?: (dragging: boolean) => void; - on_files?: (files: File[]) => void; -} - -type ActionReturn = { - update: (new_options: DragActionOptions) => void; - destroy: () => void; -}; - -export function create_drag(): { - drag: (node: HTMLElement, options: DragActionOptions) => ActionReturn; - open_file_upload: () => void; -} { - let hidden_input: HTMLInputElement; - let _options: DragActionOptions; - return { - drag( - node: HTMLElement, - options: DragActionOptions = {} - ): { - update: (new_options: DragActionOptions) => void; - destroy: () => void; - } { - _options = options; - - // Create and configure hidden file input - function setup_hidden_input(): void { - hidden_input = document.createElement("input"); - hidden_input.type = "file"; - hidden_input.style.display = "none"; - hidden_input.setAttribute("aria-label", "File upload"); - hidden_input.setAttribute("data-testid", "file-upload"); - const accept_options = Array.isArray(_options.accepted_types) - ? _options.accepted_types.join(",") - : _options.accepted_types || undefined; - - if (accept_options) { - hidden_input.accept = accept_options; - } - - hidden_input.multiple = _options.mode === "multiple" || false; - if (_options.mode === "directory") { - hidden_input.webkitdirectory = true; - hidden_input.setAttribute("directory", ""); - hidden_input.setAttribute("mozdirectory", ""); - } - node.appendChild(hidden_input); - } - - setup_hidden_input(); - - function handle_drag(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - } - - function handle_drag_enter(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(true); - } - - function handle_drag_leave(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - } - - function handle_drop(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - - if (!e.dataTransfer?.files) return; - const files = Array.from(e.dataTransfer.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - - function handle_click(): void { - if (!_options.disable_click) { - hidden_input.value = ""; - hidden_input.click(); - } - } - - function handle_file_input_change(): void { - if (hidden_input.files) { - const files = Array.from(hidden_input.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - } - - // Add all event listeners - node.addEventListener("drag", handle_drag); - node.addEventListener("dragstart", handle_drag); - node.addEventListener("dragend", handle_drag); - node.addEventListener("dragover", handle_drag); - node.addEventListener("dragenter", handle_drag_enter); - node.addEventListener("dragleave", handle_drag_leave); - node.addEventListener("drop", handle_drop); - node.addEventListener("click", handle_click); - hidden_input!.addEventListener("change", handle_file_input_change); - - return { - update(new_options: DragActionOptions) { - _options = new_options; - // Recreate hidden input with new options - hidden_input.remove(); - setup_hidden_input(); - hidden_input.addEventListener("change", handle_file_input_change); - }, - destroy() { - node.removeEventListener("drag", handle_drag); - node.removeEventListener("dragstart", handle_drag); - node.removeEventListener("dragend", handle_drag); - node.removeEventListener("dragover", handle_drag); - node.removeEventListener("dragenter", handle_drag_enter); - node.removeEventListener("dragleave", handle_drag_leave); - node.removeEventListener("drop", handle_drop); - node.removeEventListener("click", handle_click); - hidden_input.removeEventListener("change", handle_file_input_change); - hidden_input.remove(); - } - }; - }, - open_file_upload(): void { - if (hidden_input) { - hidden_input.value = ""; - hidden_input.click(); - } - } - }; -} diff --git a/6.13.0/uploadbutton/Index.svelte b/6.13.0/uploadbutton/Index.svelte deleted file mode 100644 index f246c8f96ea948a81cd7bcd7a2412b089ebbaea1..0000000000000000000000000000000000000000 --- a/6.13.0/uploadbutton/Index.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - gradio.dispatch("click")} - onchange={(detail) => handle_event(detail, "change")} - onupload={(detail) => handle_event(detail, "upload")} - onerror={(detail) => { - gradio.dispatch("error", detail); - }} - upload={(...args) => gradio.shared.client.upload(...args)} -> - {gradio.shared.label ?? ""} - diff --git a/6.13.0/uploadbutton/package.json b/6.13.0/uploadbutton/package.json deleted file mode 100644 index 657726b0534b1c5731cdf917e9d630aa45093a12..0000000000000000000000000000000000000000 --- a/6.13.0/uploadbutton/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@gradio/uploadbutton", - "version": "0.9.18", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "main": "./Index.svelte", - "dependencies": { - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/uploadbutton" - } -} diff --git a/6.13.0/uploadbutton/shared/UploadButton.svelte b/6.13.0/uploadbutton/shared/UploadButton.svelte deleted file mode 100644 index 3cb3b534036b7d1fa652fddd293a00c4f5687e03..0000000000000000000000000000000000000000 --- a/6.13.0/uploadbutton/shared/UploadButton.svelte +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - {#if icon} - {`${value} - {/if} - {#if children}{@render children()}{/if} - - - diff --git a/6.13.0/uploadbutton/types.ts b/6.13.0/uploadbutton/types.ts deleted file mode 100644 index 100547b8f9293f9cd2a191b09a6003e7f071a585..0000000000000000000000000000000000000000 --- a/6.13.0/uploadbutton/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface UploadButtonProps { - value: null | FileData | FileData[]; - file_count: string; - file_types: string[]; - size: "sm" | "lg"; - icon: FileData | null; - variant: "primary" | "secondary" | "stop"; -} - -export interface UploadButtonEvents { - change: never; - upload: never; - click: never; - error: string; -} diff --git a/6.13.0/utils/package.json b/6.13.0/utils/package.json deleted file mode 100644 index 97e34911592ce8b15a54ea071d740237220295dc..0000000000000000000000000000000000000000 --- a/6.13.0/utils/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@gradio/utils", - "version": "0.12.2", - "description": "Gradio UI packages", - "type": "module", - "main": "./src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/theme": "workspace:^", - "svelte-i18n": "^4.0.1" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/utils" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.13.0/utils/src/color.ts b/6.13.0/utils/src/color.ts deleted file mode 100644 index 86d3fe6a5c35c450cc6517b5f3d4767ffda1bc2c..0000000000000000000000000000000000000000 --- a/6.13.0/utils/src/color.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { colors, ordered_colors } from "@gradio/theme"; - -export const get_next_color = (index: number): keyof typeof colors => { - return ordered_colors[index % ordered_colors.length]; -}; diff --git a/6.13.0/utils/src/index.ts b/6.13.0/utils/src/index.ts deleted file mode 100644 index 8db07c80fcf3416332b4ec11d86c06a0fdfb7e74..0000000000000000000000000000000000000000 --- a/6.13.0/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./color.js"; -export * from "./utils.svelte.js"; -export * from "./types.js"; diff --git a/6.13.0/utils/src/types.ts b/6.13.0/utils/src/types.ts deleted file mode 100644 index 8dd47a49c34d6da4ce4328aa99f9fe563ecc7d89..0000000000000000000000000000000000000000 --- a/6.13.0/utils/src/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface CustomButton { - id: number; - value: string | null; - icon: FileData | null; -} diff --git a/6.13.0/utils/src/utils.svelte.ts b/6.13.0/utils/src/utils.svelte.ts deleted file mode 100644 index 1a7d54a3cfac850fd1dedcf10907105b157ade26..0000000000000000000000000000000000000000 --- a/6.13.0/utils/src/utils.svelte.ts +++ /dev/null @@ -1,575 +0,0 @@ -import type { ActionReturn } from "svelte/action"; -import type { Client } from "@gradio/client"; -import type { ComponentType, SvelteComponent } from "svelte"; -import { tick, untrack } from "svelte"; -import type { Component } from "svelte"; -import { locale } from "svelte-i18n"; - -export const I18N_MARKER = "__i18n__"; -const TRANSLATABLE_PROPS = [ - "label", - "info", - "placeholder", - "description", - "title", - "value" -]; - -export interface SharedProps { - elem_id?: string; - elem_classes: string[]; - components?: string[]; - server_fns?: string[]; - interactive: boolean; - visible: boolean | "hidden"; - id: number; - container: boolean; - target: HTMLElement; - theme_mode: "light" | "dark" | "system"; - version: string; - root: string; - autoscroll: boolean; - max_file_size: number | null; - formatter: any; //I18nFormatter; - client: Client; - scale: number; - min_width: number; - padding: number; - load_component: load_component; - loading_status?: any; - label: string; - show_label: boolean; - validation_error?: string | null; - theme?: "light" | "dark"; - show_progress: boolean; - api_prefix: string; - server: ServerFunctions; - attached_events?: string[]; - register_component: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - dispatcher: Function; -} - -export type LoadingComponent = Promise<{ - default: Component; -}>; - -export const GRADIO_ROOT = "GRADIO_ROOT"; - -export interface ValueData { - value: any; - is_value_data: boolean; -} - -export interface SelectData { - row_value?: any[]; - col_value?: any[]; - index: number | [number, number]; - value: any; - selected?: boolean; -} - -export interface LikeData { - index: number | [number, number]; - value: any; - liked?: boolean | string; -} - -export interface KeyUpData { - key: string; - input_value: string; -} - -export interface ShareData { - description: string; - title?: string; -} - -export interface CopyData { - value: string; -} - -export class ShareError extends Error { - constructor(message: string) { - super(message); - this.name = "ShareError"; - } -} - -export async function uploadToHuggingFace( - data: string | { url?: string; path?: string }, - type: "base64" | "url" -): Promise { - if (window.__gradio_space__ == null) { - throw new ShareError("Must be on Spaces to share."); - } - let blob: Blob; - let contentType: string; - let filename: string; - if (type === "url") { - let url: string; - - if (typeof data === "object" && data.url) { - url = data.url; - } else if (typeof data === "string") { - url = data; - } else { - throw new Error("Invalid data format for URL type"); - } - - const response = await fetch(url); - blob = await response.blob(); - contentType = response.headers.get("content-type") || ""; - filename = response.headers.get("content-disposition") || ""; - } else { - let dataurl: string; - - if (typeof data === "object" && data.path) { - dataurl = data.path; - } else if (typeof data === "string") { - dataurl = data; - } else { - throw new Error("Invalid data format for base64 type"); - } - - blob = dataURLtoBlob(dataurl); - contentType = dataurl.split(";")[0].split(":")[1]; - filename = "file." + contentType.split("/")[1]; - } - - const file = new File([blob], filename, { type: contentType }); - - // Send file to endpoint - const uploadResponse = await fetch("https://huggingface.co/uploads", { - method: "POST", - body: file, - headers: { - "Content-Type": file.type, - "X-Requested-With": "XMLHttpRequest" - } - }); - - // Check status of response - if (!uploadResponse.ok) { - if ( - uploadResponse.headers.get("content-type")?.includes("application/json") - ) { - const error = await uploadResponse.json(); - throw new ShareError(`Upload failed: ${error.error}`); - } - throw new ShareError(`Upload failed.`); - } - - // Return response if needed - const result = await uploadResponse.text(); - return result; -} - -function dataURLtoBlob(dataurl: string): Blob { - var arr = dataurl.split(","), - mime = (arr[0].match(/:(.*?);/) as RegExpMatchArray)[1], - bstr = atob(arr[1]), - n = bstr.length, - u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} - -export function copy(node: HTMLDivElement): ActionReturn { - node.addEventListener("click", handle_copy); - - async function handle_copy(event: MouseEvent): Promise { - const path = event.composedPath() as HTMLButtonElement[]; - - const [copy_button] = path.filter( - (e) => e?.tagName === "BUTTON" && e.classList.contains("copy_code_button") - ); - - if (copy_button) { - event.stopImmediatePropagation(); - - const copy_text = copy_button.parentElement!.innerText.trim(); - const copy_sucess_button = Array.from( - copy_button.children - )[1] as HTMLDivElement; - - const copied = await copy_to_clipboard(copy_text); - - if (copied) copy_feedback(copy_sucess_button); - - function copy_feedback(_copy_sucess_button: HTMLDivElement): void { - _copy_sucess_button.style.opacity = "1"; - setTimeout(() => { - _copy_sucess_button.style.opacity = "0"; - }, 2000); - } - } - } - - return { - destroy(): void { - node.removeEventListener("click", handle_copy); - } - }; -} - -async function copy_to_clipboard(value: string): Promise { - let copied = false; - if ("clipboard" in navigator) { - await navigator.clipboard.writeText(value); - copied = true; - } else { - const textArea = document.createElement("textarea"); - textArea.value = value; - - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - copied = true; - } catch (error) { - console.error(error); - copied = false; - } finally { - textArea.remove(); - } - } - - return copied; -} - -export const format_time = (seconds: number): string => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const seconds_remainder = Math.round(seconds) % 60; - const padded_minutes = `${minutes < 10 ? "0" : ""}${minutes}`; - const padded_seconds = `${ - seconds_remainder < 10 ? "0" : "" - }${seconds_remainder}`; - - if (hours > 0) { - return `${hours}:${padded_minutes}:${padded_seconds}`; - } - return `${minutes}:${padded_seconds}`; -}; - -interface Args { - api_url: string; - name: string; - id?: string; - variant: "component" | "example" | "base"; -} - -export type component_loader = (args: Args) => { - component: { - default: ComponentType; - }; -}; - -export type LoadedComponentWithRuntime = { - component: LoadingComponent; - runtime: false | typeof import("svelte"); -}; - -export type load_component = ( - name: string, - variant: "component" | "example" | "base", - component_class_id?: string -) => LoadedComponentWithRuntime; - -const is_browser = typeof window !== "undefined"; - -export type ServerFunctions = Record Promise>; - -export const allowed_shared_props: (keyof SharedProps)[] = [ - "elem_id", - "elem_classes", - "visible", - "interactive", - "server_fns", - "server", - "id", - "target", - "theme_mode", - "version", - "root", - "autoscroll", - "max_file_size", - "formatter", - "client", - "load_component", - "scale", - "min_width", - "theme", - "padding", - "loading_status", - "label", - "show_label", - "validation_error", - "show_progress", - "api_prefix", - "container", - "attached_events", - "register_component", - "dispatcher" -] as const; - -export type I18nFormatter = any; - -export function has_i18n_marker(value: unknown): value is string { - return typeof value === "string" && value.includes(I18N_MARKER); -} - -export function translate_i18n_marker( - value: string, - translate: (key: string) => string -): string { - const start = value.indexOf(I18N_MARKER); - if (start === -1) return value; - - const json_start = start + I18N_MARKER.length; - const json_end = value.indexOf("}", json_start) + 1; - if (json_end === 0) return value; - - try { - const metadata = JSON.parse(value.slice(json_start, json_end)); - if (metadata?.key) { - const translated = translate(metadata.key); - const result = translated !== metadata.key ? translated : metadata.key; - return value.slice(0, start) + result + value.slice(json_end); - } - } catch {} - - return value; -} - -export class Gradio { - load_component: load_component; - shared: SharedProps = $state({} as SharedProps) as SharedProps; - props = $state({} as U) as U; - i18n: I18nFormatter = $state((v: string) => v) as any; - translatable_props: Record = {}; - dispatcher!: Function; - last_update: ReturnType | null = null; - shared_props: (keyof SharedProps)[] = allowed_shared_props; - mounted: boolean = false; - old_value: any; - register_component!: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - - constructor( - _props: { shared_props: SharedProps; props: U }, - default_values?: Partial - ) { - for (const key in _props.shared_props) { - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - - if (default_values) { - for (const key in default_values) { - if (this.props[key as keyof U] === undefined) { - // @ts-ignore - this.props[key] = default_values[key as keyof U]; - } - } - } - // @ts-ignore same here - this.i18n = this.props.i18n ?? ((v: string) => v); - - for (const key of TRANSLATABLE_PROPS) { - // @ts-ignore - this.shared[key] = this._translate_and_store( - "shared", - key, - // @ts-ignore - _props.shared_props[key] - ); - // @ts-ignore - this.props[key] = this._translate_and_store( - "props", - key, - // @ts-ignore - _props.props[key] - ); - } - - this.load_component = this.shared.load_component; - - this.register_component = this.shared.register_component || (() => {}); - this.dispatcher = this.shared.dispatcher || (() => {}); - - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - - $effect(() => { - // Need to update the props here - // otherwise UI won't reflect latest state from render - for (const key in _props.shared_props) { - // @ts-ignore - if (this._is_i18n_managed(`shared.${key}`, _props.shared_props[key])) - continue; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - if (this._is_i18n_managed(`props.${key}`, _props.props[key])) continue; - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - untrack(() => { - this.shared.id = _props.shared_props.id; - }); - }); - - // retranslate props when locale changes - if (Object.keys(this.translatable_props).length > 0) { - locale.subscribe(() => { - for (const [full_key, original] of Object.entries( - this.translatable_props - )) { - const [target, key] = full_key.split("."); - const translated = this.i18n(original); - // @ts-ignore - if (target === "shared") this.shared[key] = translated; - // @ts-ignore - else this.props[key] = translated; - } - }); - } - } - - // check if props are translatable - _is_i18n_managed(key: string, new_value: unknown): boolean { - const original_marker = this.translatable_props[key]; - if (!original_marker) return false; - if (new_value === original_marker) return true; - // if value has changed then remove key - delete this.translatable_props[key]; - return false; - } - - _translate_and_store( - target: "shared" | "props", - key: string, - value: unknown - ): unknown { - if (typeof value !== "string") return value; - const translated = this.i18n(value); - if (translated !== value) { - this.translatable_props[`${target}.${key}`] = value; - } - return translated; - } - - dispatch(event_name: E, data?: T[E]): void { - this.dispatcher(this.shared.id, event_name, data); - } - - async get_data() { - return $state.snapshot(this.props); - } - - update(data: Partial): void { - this.set_data(data as U & SharedProps); - } - - set_data(data: Partial): void { - for (const key in data) { - // @ts-ignore - const value = data[key]; - const translated = has_i18n_marker(value) - ? this._translate_and_store( - this.shared_props.includes(key as keyof SharedProps) - ? "shared" - : "props", - key, - value - ) - : value; - - if (this.shared_props.includes(key as keyof SharedProps)) { - const _key = key as keyof SharedProps; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[_key] = translated; - continue; - } - // @ts-ignore - this.props[key] = translated; - } - } - - watch_for_change() { - $effect(() => { - if (!this.mounted) { - // @ts-ignore - this.old_value = this.props.value; - this.mounted = true; - } - // @ts-ignore - if (this.old_value != this.props.value) { - // @ts-ignore - this.old_value = this.props.value; - // @ts-ignore - this.dispatch("change"); - } - }); - } -} - -// function _load_component( -// this: Gradio, -// name: string, -// variant: "component" | "example" | "base" = "component" -// ): ReturnType { -// return this._load_component!({ -// name, -// api_url: this.shared.client.config?.root!, -// variant -// }); -// } - -export const css_units = (dimension_value: string | number): string => { - return typeof dimension_value === "number" - ? dimension_value + "px" - : dimension_value; -}; - -export function should_show_scroll_fade( - container: HTMLElement | null -): boolean { - if (!container) return false; - const has_overflow = container.scrollHeight > container.clientHeight; - const at_bottom = - container.scrollTop >= container.scrollHeight - container.clientHeight - 1; - return has_overflow && !at_bottom; -} - -type MappedProps = { [K in keyof T]: T[K] }; -type MappedProp = { [P in K]: T[P] }; diff --git a/6.13.0/vibeeditor/Index.svelte b/6.13.0/vibeeditor/Index.svelte deleted file mode 100644 index 6db9b3cb7167948ae0f14cabd9d66c791deb9e2d..0000000000000000000000000000000000000000 --- a/6.13.0/vibeeditor/Index.svelte +++ /dev/null @@ -1,764 +0,0 @@ - - -
- -
- - -
- -
- {#if activeTab === "chat"} -
- {#each message_history as message, index} -
-
- - - - {#if !message.isBot && message.hash && !message.isPending} - - {/if} -
-
- {/each} - - {#if message_history.length === 0} -
No messages yet
- {/if} - - {#if message_history.length === 0} -
-
- {#each starterQueries as query} - - {/each} -
-
- {/if} -
- {:else if activeTab === "code"} -
-
- -
- - -
- {/if} -
- -
-
Powered by: gpt-oss
- - {#if showTagMenu && currentLineIndex === i} -
- [s, i])} - filtered_indices={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )} - active_index={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )[selectedOptionIndex]} - show_options={true} - onchange={(e) => insert_tag(e)} - {offset_from_top} - from_top={true} - /> -
- {/if} -
-
- {#if gradio.props.max_lines == undefined || (gradio.props.max_lines && i < gradio.props.max_lines - 1)} -
- -
- {/if} -
- -
- - {/each} - - {:else if checked || gradio.props.ui_mode !== "dialogue"} -
- {#if is_formatting} -
-
-
Converting to plain text...
-
- {/if} - - {/if} - {#if submit_btn} - - {/if} - {#if stop_btn} - - {/if} -
- - - diff --git a/6.13.1/textbox/types.ts b/6.13.1/textbox/types.ts deleted file mode 100644 index 8ec1cfc945755962a887be7207b0f60290ad929a..0000000000000000000000000000000000000000 --- a/6.13.1/textbox/types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type SelectData, - type CopyData, - type CustomButton -} from "@gradio/utils"; -import type { LoadingStatus } from "@gradio/statustracker"; - -export interface TextboxEvents { - change: string; - submit: never; - blur: never; - select: SelectData; - input: never; - focus: never; - stop: never; - clear_status: LoadingStatus; - copy: CopyData; - custom_button_click: { id: number }; -} - -export interface TextboxProps { - value: string; - info: string; - lines: number; - type: "text" | "password" | "email" | undefined; - rtl: boolean; - text_align: "right" | "left"; - max_lines: number; - placeholder: string; - submit_btn: string; - stop_btn: string; - buttons: (string | CustomButton)[] | null; - autofocus: boolean; - autoscroll: boolean; - max_length: number; - html_attributes: InputHTMLAttributes; - validation_error: string | null; -} - -type FullAutoFill = - | AutoFill - | "bday" - | `${OptionalPrefixToken}${"cc-additional-name"}` - | "nickname" - | "language" - | "organization-title" - | "photo" - | "sex" - | "url"; - -export interface InputHTMLAttributes { - autocapitalize?: - | "off" - | "none" - | "on" - | "sentences" - | "words" - | "characters" - | null; - autocorrect?: "on" | "off" | null; - spellcheck?: boolean | null; - autocomplete?: FullAutoFill | undefined | null; - tabindex?: number | null; - enterkeyhint?: - | "enter" - | "done" - | "go" - | "next" - | "previous" - | "search" - | "send" - | null; - lang?: string | null; -} diff --git a/6.13.1/theme/package.json b/6.13.1/theme/package.json deleted file mode 100644 index bb4343fa73bdf0fe073c0d611292babaf9cc8d6b..0000000000000000000000000000000000000000 --- a/6.13.1/theme/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@gradio/theme", - "version": "0.6.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": false, - "scripts": { - "generate": "pollen -c src/pollen.config.mjs", - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./reset.css": { - "gradio": "./src/reset.css", - "import": "./dist/src/reset.css" - }, - "./global.css": { - "gradio": "./src/global.css", - "import": "./dist/src/global.css" - }, - "./tokens": { - "gradio": "./src/tokens.ts", - "import": "./dist/src/tokens.js" - }, - "./typography.css": { - "gradio": "./src/typography.css", - "import": "./dist/src/typography.css" - }, - "./gradio-style.scss": { - "gradio": "./src/gradio-style.scss", - "import": "./dist/src/gradio-style.scss" - }, - "./pollen.css": { - "gradio": "./src/pollen.css", - "import": "./dist/src/pollen.css" - }, - "./package.json": "./package.json" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/theme" - } -} diff --git a/6.13.1/theme/src/colors.ts b/6.13.1/theme/src/colors.ts deleted file mode 100644 index 04a9c9b33c631635832a8fb982ce1d29e0176fa7..0000000000000000000000000000000000000000 --- a/6.13.1/theme/src/colors.ts +++ /dev/null @@ -1,350 +0,0 @@ -// import tw_colors from "tailwindcss/colors"; - -export const ordered_colors = [ - "red", - "green", - "blue", - "yellow", - "purple", - "teal", - "orange", - "cyan", - "lime", - "pink" -] as const; -interface ColorPair { - primary: string; - secondary: string; -} - -interface Colors { - red: ColorPair; - green: ColorPair; - blue: ColorPair; - yellow: ColorPair; - purple: ColorPair; - teal: ColorPair; - orange: ColorPair; - cyan: ColorPair; - lime: ColorPair; - pink: ColorPair; -} - -// https://play.tailwindcss.com/ZubQYya0aN -export const color_values = [ - { color: "red", primary: 600, secondary: 100 }, - { color: "green", primary: 600, secondary: 100 }, - { color: "blue", primary: 600, secondary: 100 }, - { color: "yellow", primary: 500, secondary: 100 }, - { color: "purple", primary: 600, secondary: 100 }, - { color: "teal", primary: 600, secondary: 100 }, - { color: "orange", primary: 600, secondary: 100 }, - { color: "cyan", primary: 600, secondary: 100 }, - { color: "lime", primary: 500, secondary: 100 }, - { color: "pink", primary: 600, secondary: 100 } -] as const; - -const tw_colors = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - slate: { - 50: "#f8fafc", - 100: "#f1f5f9", - 200: "#e2e8f0", - 300: "#cbd5e1", - 400: "#94a3b8", - 500: "#64748b", - 600: "#475569", - 700: "#334155", - 800: "#1e293b", - 900: "#0f172a", - 950: "#020617" - }, - gray: { - 50: "#f9fafb", - 100: "#f3f4f6", - 200: "#e5e7eb", - 300: "#d1d5db", - 400: "#9ca3af", - 500: "#6b7280", - 600: "#4b5563", - 700: "#374151", - 800: "#1f2937", - 900: "#111827", - 950: "#030712" - }, - zinc: { - 50: "#fafafa", - 100: "#f4f4f5", - 200: "#e4e4e7", - 300: "#d4d4d8", - 400: "#a1a1aa", - 500: "#71717a", - 600: "#52525b", - 700: "#3f3f46", - 800: "#27272a", - 900: "#18181b", - 950: "#09090b" - }, - neutral: { - 50: "#fafafa", - 100: "#f5f5f5", - 200: "#e5e5e5", - 300: "#d4d4d4", - 400: "#a3a3a3", - 500: "#737373", - 600: "#525252", - 700: "#404040", - 800: "#262626", - 900: "#171717", - 950: "#0a0a0a" - }, - stone: { - 50: "#fafaf9", - 100: "#f5f5f4", - 200: "#e7e5e4", - 300: "#d6d3d1", - 400: "#a8a29e", - 500: "#78716c", - 600: "#57534e", - 700: "#44403c", - 800: "#292524", - 900: "#1c1917", - 950: "#0c0a09" - }, - red: { - 50: "#fef2f2", - 100: "#fee2e2", - 200: "#fecaca", - 300: "#fca5a5", - 400: "#f87171", - 500: "#ef4444", - 600: "#dc2626", - 700: "#b91c1c", - 800: "#991b1b", - 900: "#7f1d1d", - 950: "#450a0a" - }, - orange: { - 50: "#fff7ed", - 100: "#ffedd5", - 200: "#fed7aa", - 300: "#fdba74", - 400: "#fb923c", - 500: "#f97316", - 600: "#ea580c", - 700: "#c2410c", - 800: "#9a3412", - 900: "#7c2d12", - 950: "#431407" - }, - amber: { - 50: "#fffbeb", - 100: "#fef3c7", - 200: "#fde68a", - 300: "#fcd34d", - 400: "#fbbf24", - 500: "#f59e0b", - 600: "#d97706", - 700: "#b45309", - 800: "#92400e", - 900: "#78350f", - 950: "#451a03" - }, - yellow: { - 50: "#fefce8", - 100: "#fef9c3", - 200: "#fef08a", - 300: "#fde047", - 400: "#facc15", - 500: "#eab308", - 600: "#ca8a04", - 700: "#a16207", - 800: "#854d0e", - 900: "#713f12", - 950: "#422006" - }, - lime: { - 50: "#f7fee7", - 100: "#ecfccb", - 200: "#d9f99d", - 300: "#bef264", - 400: "#a3e635", - 500: "#84cc16", - 600: "#65a30d", - 700: "#4d7c0f", - 800: "#3f6212", - 900: "#365314", - 950: "#1a2e05" - }, - green: { - 50: "#f0fdf4", - 100: "#dcfce7", - 200: "#bbf7d0", - 300: "#86efac", - 400: "#4ade80", - 500: "#22c55e", - 600: "#16a34a", - 700: "#15803d", - 800: "#166534", - 900: "#14532d", - 950: "#052e16" - }, - emerald: { - 50: "#ecfdf5", - 100: "#d1fae5", - 200: "#a7f3d0", - 300: "#6ee7b7", - 400: "#34d399", - 500: "#10b981", - 600: "#059669", - 700: "#047857", - 800: "#065f46", - 900: "#064e3b", - 950: "#022c22" - }, - teal: { - 50: "#f0fdfa", - 100: "#ccfbf1", - 200: "#99f6e4", - 300: "#5eead4", - 400: "#2dd4bf", - 500: "#14b8a6", - 600: "#0d9488", - 700: "#0f766e", - 800: "#115e59", - 900: "#134e4a", - 950: "#042f2e" - }, - cyan: { - 50: "#ecfeff", - 100: "#cffafe", - 200: "#a5f3fc", - 300: "#67e8f9", - 400: "#22d3ee", - 500: "#06b6d4", - 600: "#0891b2", - 700: "#0e7490", - 800: "#155e75", - 900: "#164e63", - 950: "#083344" - }, - sky: { - 50: "#f0f9ff", - 100: "#e0f2fe", - 200: "#bae6fd", - 300: "#7dd3fc", - 400: "#38bdf8", - 500: "#0ea5e9", - 600: "#0284c7", - 700: "#0369a1", - 800: "#075985", - 900: "#0c4a6e", - 950: "#082f49" - }, - blue: { - 50: "#eff6ff", - 100: "#dbeafe", - 200: "#bfdbfe", - 300: "#93c5fd", - 400: "#60a5fa", - 500: "#3b82f6", - 600: "#2563eb", - 700: "#1d4ed8", - 800: "#1e40af", - 900: "#1e3a8a", - 950: "#172554" - }, - indigo: { - 50: "#eef2ff", - 100: "#e0e7ff", - 200: "#c7d2fe", - 300: "#a5b4fc", - 400: "#818cf8", - 500: "#6366f1", - 600: "#4f46e5", - 700: "#4338ca", - 800: "#3730a3", - 900: "#312e81", - 950: "#1e1b4b" - }, - violet: { - 50: "#f5f3ff", - 100: "#ede9fe", - 200: "#ddd6fe", - 300: "#c4b5fd", - 400: "#a78bfa", - 500: "#8b5cf6", - 600: "#7c3aed", - 700: "#6d28d9", - 800: "#5b21b6", - 900: "#4c1d95", - 950: "#2e1065" - }, - purple: { - 50: "#faf5ff", - 100: "#f3e8ff", - 200: "#e9d5ff", - 300: "#d8b4fe", - 400: "#c084fc", - 500: "#a855f7", - 600: "#9333ea", - 700: "#7e22ce", - 800: "#6b21a8", - 900: "#581c87", - 950: "#3b0764" - }, - fuchsia: { - 50: "#fdf4ff", - 100: "#fae8ff", - 200: "#f5d0fe", - 300: "#f0abfc", - 400: "#e879f9", - 500: "#d946ef", - 600: "#c026d3", - 700: "#a21caf", - 800: "#86198f", - 900: "#701a75", - 950: "#4a044e" - }, - pink: { - 50: "#fdf2f8", - 100: "#fce7f3", - 200: "#fbcfe8", - 300: "#f9a8d4", - 400: "#f472b6", - 500: "#ec4899", - 600: "#db2777", - 700: "#be185d", - 800: "#9d174d", - 900: "#831843", - 950: "#500724" - }, - rose: { - 50: "#fff1f2", - 100: "#ffe4e6", - 200: "#fecdd3", - 300: "#fda4af", - 400: "#fb7185", - 500: "#f43f5e", - 600: "#e11d48", - 700: "#be123c", - 800: "#9f1239", - 900: "#881337", - 950: "#4c0519" - } -}; - -export const colors = color_values.reduce( - (acc, { color, primary, secondary }) => ({ - ...acc, - [color]: { - primary: tw_colors[color][primary], - secondary: tw_colors[color][secondary] - } - }), - {} as Colors -); diff --git a/6.13.1/theme/src/index.ts b/6.13.1/theme/src/index.ts deleted file mode 100644 index bd1cb299eaa9b1ae2f6bd0c1973fa12d0c4cdb57..0000000000000000000000000000000000000000 --- a/6.13.1/theme/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// export { default as reset } from "./reset.css"; -// export { default as global } from "./global.css"; -// export { default as css } from "./pollen.css"; -// export { default as typography } from "./typography.css"; - -export * from "./colors.js"; diff --git a/6.13.1/timer/Index.svelte b/6.13.1/timer/Index.svelte deleted file mode 100644 index 7fc7857ad7235b62c97ffb4fccba78a6c9d89fd9..0000000000000000000000000000000000000000 --- a/6.13.1/timer/Index.svelte +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/6.13.1/timer/package.json b/6.13.1/timer/package.json deleted file mode 100644 index 69e4fd022b1204bf416a79f66fbf6f1c0e859744..0000000000000000000000000000000000000000 --- a/6.13.1/timer/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@gradio/timer", - "version": "0.4.9", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "dependencies": { - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/timer" - } -} diff --git a/6.13.1/timer/types.ts b/6.13.1/timer/types.ts deleted file mode 100644 index 292d729b4daf9b93f8261167f14496b64a103084..0000000000000000000000000000000000000000 --- a/6.13.1/timer/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimerProps { - value: number; - active: boolean; -} - -export interface TimerEvents { - tick: never; - clear_status: never; -} diff --git a/6.13.1/tooltip/package.json b/6.13.1/tooltip/package.json deleted file mode 100644 index 1b699440866a7a7c79de9e7575bc07b5373465fe..0000000000000000000000000000000000000000 --- a/6.13.1/tooltip/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@gradio/tooltip", - "version": "0.2.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/tooltip" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.js", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - } -} diff --git a/6.13.1/tooltip/src/Tooltip.svelte b/6.13.1/tooltip/src/Tooltip.svelte deleted file mode 100644 index c9c9ecca6357234953144bcf6a0dbe7ee5e822de..0000000000000000000000000000000000000000 --- a/6.13.1/tooltip/src/Tooltip.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - {text} -
- - diff --git a/6.13.1/tooltip/src/index.ts b/6.13.1/tooltip/src/index.ts deleted file mode 100644 index b89ac870e5bbf6d90058c6e25cb9d74b626b3809..0000000000000000000000000000000000000000 --- a/6.13.1/tooltip/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { tooltip } from "./tooltip"; diff --git a/6.13.1/tooltip/src/tooltip.ts b/6.13.1/tooltip/src/tooltip.ts deleted file mode 100644 index 09403f9438805f29a32579b8e98a25f3aae37737..0000000000000000000000000000000000000000 --- a/6.13.1/tooltip/src/tooltip.ts +++ /dev/null @@ -1,49 +0,0 @@ -import Tooltip from "./Tooltip.svelte"; - -interface ActionArgs { - color: string; - text: string; -} - -export function tooltip( - element: HTMLElement | SVGElement, - { color, text }: ActionArgs -): any { - let tooltipComponent: Tooltip; - function mouse_over(event: MouseEvent): MouseEvent { - tooltipComponent = new Tooltip({ - props: { - text, - x: event.pageX, - y: event.pageY, - color - }, - target: document.body - }); - - return event; - } - function mouseMove(event: MouseEvent): void { - tooltipComponent.$set({ - x: event.pageX, - y: event.pageY - }); - } - function mouseLeave(): void { - tooltipComponent.$destroy(); - } - - const el = element as HTMLElement; - - el.addEventListener("mouseover", mouse_over); - el.addEventListener("mouseleave", mouseLeave); - el.addEventListener("mousemove", mouseMove); - - return { - destroy() { - el.removeEventListener("mouseover", mouse_over); - el.removeEventListener("mouseleave", mouseLeave); - el.removeEventListener("mousemove", mouseMove); - } - }; -} diff --git a/6.13.1/tootils/package.json b/6.13.1/tootils/package.json deleted file mode 100644 index 39683201d83bfc3a5ffaeb655426076b27f40944..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@self/tootils", - "version": "0.13.0", - "description": "Internal test utilities", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": "./src/index.ts", - "./render": "./src/render.ts", - "./shared-prop-tests": "./src/shared-prop-tests.ts", - "./app-launcher": "./src/app-launcher.ts", - "./download-command": "./src/download-command.ts" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.13.1/tootils/src/app-launcher.ts b/6.13.1/tootils/src/app-launcher.ts deleted file mode 100644 index a320667e5764ec306dec64eabbfa998bdd85169c..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/app-launcher.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { spawn, type ChildProcess } from "node:child_process"; -import http from "http"; -import net from "net"; -import path from "path"; -import fs from "fs"; -import os from "os"; -import url from "url"; - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -const ROOT_DIR = path.resolve(__dirname, "../../.."); - -export interface GradioApp { - port: number; - process: ChildProcess; -} - -export function killGradioApp(process: ChildProcess): void { - try { - process.kill("SIGTERM"); - } catch { - // Process may already be dead - } -} - -export async function findFreePort( - startPort: number, - endPort: number -): Promise { - for (let port = startPort; port < endPort; port++) { - if (await isPortFree(port)) { - return port; - } - } - throw new Error(`Could not find free port in range ${startPort}-${endPort}`); -} - -function isPortFree(port: number): Promise { - return new Promise((resolve, reject) => { - const sock = net.createConnection(port, "127.0.0.1"); - sock.once("connect", () => { - sock.end(); - resolve(false); - }); - sock.once("error", (e: NodeJS.ErrnoException) => { - sock.destroy(); - if (e.code === "ECONNREFUSED") { - resolve(true); - } else { - reject(e); - } - }); - }); -} - -/** - * Poll the server with HTTP GET requests until it returns a response. - * Gradio prints "Running on local URL:" before the server is fully ready, - * so we need to verify it actually responds to HTTP requests. - */ -async function waitForServerReady( - port: number, - timeoutMs: number = 15000 -): Promise { - const start = Date.now(); - const pollInterval = 200; - - while (Date.now() - start < timeoutMs) { - try { - await new Promise((resolve, reject) => { - // Use HEAD on /gradio_api/info to avoid triggering SSR rendering on - // the root URL, which could block Gradio's own startup health check. - const req = http.request( - `http://127.0.0.1:${port}/gradio_api/info`, - { method: "HEAD", timeout: 2000 }, - (res) => { - res.resume(); // drain the response - resolve(); - } - ); - req.on("error", reject); - req.on("timeout", () => { - req.destroy(); - reject(new Error("request timeout")); - }); - req.end(); - }); - return; // Server responded successfully - } catch { - // Server not ready yet, wait and retry - await new Promise((r) => setTimeout(r, pollInterval)); - } - } - throw new Error( - `Server on port ${port} did not become ready within ${timeoutMs}ms` - ); -} - -export function getTestcases(demoName: string): string[] { - const demoDir = path.join(ROOT_DIR, "demo", demoName); - if (!fs.existsSync(demoDir)) { - return []; - } - - return fs - .readdirSync(demoDir) - .filter((f) => f.endsWith("_testcase.py")) - .map((f) => path.basename(f, ".py")); -} - -// Check if a testcase file exists for this demo -export function hasTestcase(demoName: string, testcaseName: string): boolean { - const testcaseFile = path.join( - ROOT_DIR, - "demo", - demoName, - `${testcaseName}_testcase.py` - ); - return fs.existsSync(testcaseFile); -} - -// Get the path to a demo's Python file -function getDemoFilePath(demoName: string, testcaseName?: string): string { - if (testcaseName) { - return path.join(ROOT_DIR, "demo", demoName, `${testcaseName}_testcase.py`); - } - return path.join(ROOT_DIR, "demo", demoName, "run.py"); -} - -export async function launchGradioApp( - demoName: string, - workerIndex: number = 0, - timeout: number = 60000, - testcaseName?: string -): Promise { - // Partition ports by worker index to avoid collisions - const basePort = 7860 + workerIndex * 100; - const port = await findFreePort(basePort, basePort + 99); - - // Get the path to the demo file - const demoFilePath = getDemoFilePath(demoName, testcaseName); - - // Create unique directories for this instance to avoid cache conflicts - const instanceId = testcaseName - ? `${demoName}_${testcaseName}_${port}` - : `${demoName}_${port}`; - const instanceDir = path.join(os.tmpdir(), `gradio_test_${instanceId}`); - const cacheDir = path.join(instanceDir, "cached_examples"); - const tempDir = path.join(instanceDir, "temp"); - - if (!fs.existsSync(instanceDir)) { - fs.mkdirSync(instanceDir, { recursive: true }); - } - - // Run the demo file directly - the demo's own if __name__ == "__main__" block - // has the correct launch parameters (show_error, etc.) - const childProcess = spawn("python", [demoFilePath], { - stdio: "pipe", - cwd: ROOT_DIR, - env: { - ...process.env, - PYTHONUNBUFFERED: "true", - GRADIO_ANALYTICS_ENABLED: "False", - GRADIO_IS_E2E_TEST: "1", - GRADIO_RESET_EXAMPLES_CACHE: "True", - // Control the port via environment variable - GRADIO_SERVER_PORT: port.toString(), - // Use unique directories per instance to avoid conflicts - GRADIO_EXAMPLES_CACHE: cacheDir, - GRADIO_TEMP_DIR: tempDir - } - }); - - childProcess.stdout?.setEncoding("utf8"); - childProcess.stderr?.setEncoding("utf8"); - - // Wait for app to be ready - return new Promise((resolve, reject) => { - const timeoutId = setTimeout(() => { - killGradioApp(childProcess); - reject( - new Error(`Gradio app ${demoName} failed to start within ${timeout}ms`) - ); - }, timeout); - - let output = ""; - let startupDetected = false; - - function handleOutput(data: string): void { - output += data; - // Check for Gradio's startup message - if ( - !startupDetected && - (data.includes("Running on local URL:") || - data.includes(`Uvicorn running on`)) - ) { - startupDetected = true; - clearTimeout(timeoutId); - // The startup message is printed before the server is fully ready. - // Poll with HTTP requests to ensure it actually responds. - waitForServerReady(port) - .then(() => resolve({ port, process: childProcess })) - .catch(reject); - } - } - - childProcess.stdout?.on("data", handleOutput); - childProcess.stderr?.on("data", handleOutput); - - childProcess.on("error", (err) => { - clearTimeout(timeoutId); - reject(err); - }); - - childProcess.on("exit", (code) => { - if (code !== 0 && code !== null) { - clearTimeout(timeoutId); - reject( - new Error( - `Gradio app ${demoName} exited with code ${code}.\nOutput: ${output}` - ) - ); - } - }); - }); -} diff --git a/6.13.1/tootils/src/download-command.ts b/6.13.1/tootils/src/download-command.ts deleted file mode 100644 index 2d99d0883c6b5e985d21c18902e61db60ccaa6dc..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/download-command.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { BrowserCommand } from "vitest/node"; -import { resolve } from "path"; -import { readFile } from "fs/promises"; - -/** - * Vitest browser command that captures a real file download triggered by - * clicking an element. Runs server-side with access to the Playwright page. - * - * Sets up page.waitForEvent("download") BEFORE clicking, so the download - * event is never missed. - */ -export const expect_download: BrowserCommand< - [selector: string, options?: { timeout?: number }], - { suggested_filename: string; content: string | null } -> = async (context, selector, options) => { - const timeout = options?.timeout ?? 5000; - const provider = context.provider as any; - const page = provider.getPage(context.sessionId); - // Tests run inside an iframe; use the iframe locator to click - // but listen for the download event on the parent page. - const iframe = (context as any).iframe; - - const [download] = await Promise.all([ - page.waitForEvent("download", { timeout }), - iframe.locator(selector).click() - ]); - - const suggested_filename = download.suggestedFilename(); - const path = await download.path(); - - let content: string | null = null; - if (path) { - const fs = await import("fs/promises"); - content = await fs.readFile(path, "utf-8"); - } - - return { - suggested_filename, - content - }; -}; - -/** - * Vitest browser command that sets files on an element. - * Resolves fixture URL paths (e.g. "/test/test_files/bus.png") to absolute - * disk paths and uses Playwright's setInputFiles(). - */ -export const set_file_inputs: BrowserCommand< - [file_urls: string[], selector?: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - const iframe = (context as any).iframe; - - const paths = file_urls.map((url) => resolve(root, url.replace(/^\//, ""))); - - await iframe - .locator(selector ?? 'input[type="file"]') - .first() - .setInputFiles(paths); -}; - -interface Drop_file_spec { - data: string; // base64 - name: string; - mime_type: string; -} - -/** - * Vitest browser command that simulates dropping files onto an element. - * Reads files from disk, transfers them as base64 into the browser context, - * and dispatches dragenter, dragover, and drop events with a real DataTransfer. - */ -export const drop_files: BrowserCommand< - [file_urls: string[], selector: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - - const files: Drop_file_spec[] = await Promise.all( - file_urls.map(async (url) => { - const abs = resolve(root, url.replace(/^\//, "")); - const data = (await readFile(abs)).toString("base64"); - const name = abs.split("/").pop()!; - const ext = name.split(".").pop()!.toLowerCase(); - const mime_type = MIME_TYPES[ext] || "application/octet-stream"; - return { data, name, mime_type }; - }) - ); - - const iframe = (context as any).iframe; - await iframe - .locator(selector) - .first() - .evaluate((target: Element, files: Drop_file_spec[]) => { - const dt = new DataTransfer(); - for (const f of files) { - const bytes = Uint8Array.from(atob(f.data), (c) => c.charCodeAt(0)); - dt.items.add(new File([bytes], f.name, { type: f.mime_type })); - } - - target.dispatchEvent( - new DragEvent("dragenter", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("dragover", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("drop", { dataTransfer: dt, bubbles: true }) - ); - }, files); -}; - -const MIME_TYPES: Record = { - txt: "text/plain", - csv: "text/csv", - json: "application/json", - pdf: "application/pdf", - jpg: "image/jpeg", - jpeg: "image/jpeg", - png: "image/png", - gif: "image/gif", - webp: "image/webp", - svg: "image/svg+xml", - mp4: "video/mp4", - webm: "video/webm", - ogg: "video/ogg", - avi: "video/x-msvideo", - wav: "audio/wav", - mp3: "audio/mpeg", - flac: "audio/flac" -}; diff --git a/6.13.1/tootils/src/download.ts b/6.13.1/tootils/src/download.ts deleted file mode 100644 index c6217fc6695b81fe685bcff9593ed9cab6095a3a..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/download.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { commands } from "vitest/browser"; -import type { FileData } from "@gradio/client"; - -export interface DownloadResult { - suggested_filename: string; - content: string | null; -} - -/** - * Clicks an element and captures the resulting file download. - * - * Uses a real browser download via Playwright under the hood — - * the file is actually downloaded and its content is readable. - * - * @param selector - CSS selector for the element to click - * @param options - Optional timeout (default 5000ms) - * @returns The downloaded file's suggested filename and text content - * - * @example - * ```ts - * const { suggested_filename, content } = await download_file("a.download-link"); - * expect(suggested_filename).toBe("data.csv"); - * expect(content).toContain("col1,col2"); - * ``` - */ -export async function download_file( - selector: string, - options?: { timeout?: number } -): Promise { - return (commands as any).expect_download(selector, options); -} - -/** - * Sets files on an `` element using real file fixtures. - * - * Accepts one or more FileData fixtures (e.g. TEST_JPG, TEST_PNG) and - * sets them on the file input, triggering the browser's native change event. - * - * @param files - One or more FileData fixtures to upload - * @param selector - CSS selector for the file input (default: 'input[type="file"]') - * - * @example - * ```ts - * import { render, upload_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await upload_file(TEST_JPG); - * - * expect(upload).toHaveBeenCalled(); - * ``` - */ -export async function upload_file( - files: FileData | FileData[], - selector?: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).set_file_inputs(urls, selector); -} - -/** - * Simulates dragging and dropping files onto an element. - * - * Reads the fixture files from disk, constructs a real DataTransfer - * with File objects, and dispatches dragenter, dragover, and drop events - * on the target element. - * - * @param files - One or more FileData fixtures to drop - * @param selector - CSS selector for the drop target element - * - * @example - * ```ts - * import { render, drop_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await drop_file(TEST_JPG, "[aria-label='Click to upload or drop files']"); - * - * await vi.waitFor(() => expect(upload).toHaveBeenCalled()); - * ``` - */ -export async function drop_file( - files: FileData | FileData[], - selector: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).drop_files(urls, selector); -} diff --git a/6.13.1/tootils/src/fixtures.ts b/6.13.1/tootils/src/fixtures.ts deleted file mode 100644 index 95adcab69ee5186eb2533321b64e8fd08932a113..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/fixtures.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { FileData } from "@gradio/client"; - -const BASE = "/test/test_files"; - -function fixture(filename: string, mime_type: string, size: number): FileData { - const url = `${BASE}/${filename}`; - return new FileData({ - path: url, - url, - orig_name: filename, - size, - mime_type - }); -} - -export const TEST_TXT = fixture("alphabet.txt", "text/plain", 26); -export const TEST_JPG = fixture("cheetah1.jpg", "image/jpeg", 20552); -export const TEST_PNG = fixture("bus.png", "image/png", 1951); -export const TEST_MP4 = fixture("video_sample.mp4", "video/mp4", 261179); -export const TEST_WAV = fixture("audio_sample.wav", "audio/wav", 16136); -export const TEST_PDF = fixture("sample_file.pdf", "application/pdf", 10558); diff --git a/6.13.1/tootils/src/index.ts b/6.13.1/tootils/src/index.ts deleted file mode 100644 index 5ac7a8723c2c74c4d04fc0c2555ced0e6f8388f5..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/index.ts +++ /dev/null @@ -1,224 +0,0 @@ -import { test as base, type Locator, type Page } from "@playwright/test"; -import { spy } from "tinyspy"; -import url from "url"; -import path from "path"; -import fsPromises from "fs/promises"; -import type { ChildProcess } from "node:child_process"; - -import type { SvelteComponent } from "svelte"; -import type { SpyFn } from "tinyspy"; - -import { launchGradioApp, killGradioApp, hasTestcase } from "./app-launcher"; - -export function get_text(el: T): string { - return el.innerText.trim(); -} - -export function wait(n: number): Promise { - return new Promise((r) => setTimeout(r, n)); -} - -const ROOT_DIR = path.resolve( - url.fileURLToPath(import.meta.url), - "../../../.." -); - -// Extract testcase name from test title if present -// Test titles can be: -// - "case eager_caching_examples: ..." -// - "test case multimodal_messages chatinterface works..." -function extractTestcaseFromTitle( - title: string, - demoName: string -): string | undefined { - // Try pattern: "case :" or "test case " - const patterns = [/^case\s+(\w+):/, /^test case\s+(\w+)\s/]; - - for (const pattern of patterns) { - const match = title.match(pattern); - if (match) { - const caseName = match[1]; - // Check if this is a testcase (not the main demo) - if (hasTestcase(demoName, caseName)) { - return caseName; - } - } - } - return undefined; -} - -// Cache for launched apps - key is "demoName" or "demoName_testcaseName" -const appCache = new Map< - string, - { port: number; process: ChildProcess; refCount: number } ->(); - -// Test fixture that launches Gradio app per test -const test_normal = base.extend<{ setup: void }>({ - setup: [ - async ({ page }, use, testInfo): Promise => { - const { file, title } = testInfo; - const demoName = path.basename(file, ".spec.ts"); - - // Check if this is a reload test (they manage their own apps) - if (demoName.endsWith(".reload")) { - // For reload tests, don't launch an app - they handle it themselves - await use(); - return; - } - - // Check if this test is for a specific testcase - const testcaseName = extractTestcaseFromTitle(title, demoName); - - // Cache key includes testcase if present - const cacheKey = testcaseName ? `${demoName}_${testcaseName}` : demoName; - - let appInfo = appCache.get(cacheKey); - - if (!appInfo) { - // Launch the app for this test - const workerIndex = testInfo.workerIndex; - try { - const { port, process } = await launchGradioApp( - demoName, - workerIndex, - 60000, - testcaseName - ); - appInfo = { port, process, refCount: 0 }; - appCache.set(cacheKey, appInfo); - } catch (error) { - console.error(`Failed to launch app for ${cacheKey}:`, error); - throw error; - } - } - - appInfo.refCount++; - - // Navigate to the app - await page.goto(`http://localhost:${appInfo.port}`); - - if ( - process.env?.GRADIO_SSR_MODE?.toLowerCase() === "true" && - !( - demoName.includes("multipage") || - demoName.includes("chatinterface_deep_link") - ) - ) { - await page.waitForSelector("#svelte-announcer"); - } - await page.waitForLoadState("load"); - - await use(); - - // Decrement ref count - appInfo.refCount--; - - // Note: We don't kill the app here because other tests might - // still need it. The app will be killed when the process exits. - }, - { auto: true } - ] -}); - -// Cleanup apps when the process exits -process.on("exit", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } -}); - -process.on("SIGINT", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -process.on("SIGTERM", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -export const test = test_normal; - -export async function wait_for_event( - component: SvelteComponent, - event: string -): Promise { - const mock = spy(); - return new Promise((res) => { - component.$on(event, () => { - mock(); - res(mock); - }); - }); -} - -export interface ActionReturn< - Parameter = never, - Attributes extends Record = Record -> { - update?: [Parameter] extends [never] ? never : (parameter: Parameter) => void; - destroy?: () => void; - /** - * ### DO NOT USE THIS - * This exists solely for type-checking and has no effect at runtime. - * Set this through the `Attributes` generic instead. - */ - $$_attributes?: Attributes; -} - -export { expect } from "@playwright/test"; - -export const drag_and_drop_file = async ( - page: Page, - selector: string | Locator, - filePath: string, - fileName: string, - fileType = "", - count = 1 -): Promise => { - const buffer = (await fsPromises.readFile(filePath)).toString("base64"); - - const dataTransfer = await page.evaluateHandle( - async ({ bufferData, localFileName, localFileType, count }) => { - const dt = new DataTransfer(); - - const blobData = await fetch(bufferData).then((res) => res.blob()); - - const file = new File([blobData], localFileName, { - type: localFileType - }); - - for (let i = 0; i < count; i++) { - dt.items.add(file); - } - return dt; - }, - { - bufferData: `data:application/octet-stream;base64,${buffer}`, - localFileName: fileName, - localFileType: fileType, - count - } - ); - - if (typeof selector === "string") { - await page.dispatchEvent(selector, "drop", { dataTransfer }); - } else { - await selector.dispatchEvent("drop", { dataTransfer }); - } -}; - -export async function go_to_testcase( - page: Page, - _test_case: string -): Promise { - // With the new setup, each testcase launches its own Gradio app. - // The fixture detects the testcase from the test title and launches - // the correct app, so this function is now a no-op. - // The page is already at the correct testcase app. -} diff --git a/6.13.1/tootils/src/render.ts b/6.13.1/tootils/src/render.ts deleted file mode 100644 index 60bc02a263f3b8f2c32ef9b0cef57c0396a0fb21..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/render.ts +++ /dev/null @@ -1,314 +0,0 @@ -import { - getQueriesForElement, - prettyDOM, - fireEvent as dtlFireEvent -} from "@testing-library/dom"; -import { tick, mount, unmount } from "svelte"; -import type { SvelteComponent, Component } from "svelte"; - -import type { - queries, - Queries, - BoundFunction, - EventType -} from "@testing-library/dom"; -import { vi, type Mock } from "vitest"; -import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils"; -import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker"; -import { _ } from "svelte-i18n"; - -const containerCache = new Map(); -const componentCache = new Set(); - -type ComponentType = Component; - -export type RenderResult< - C extends SvelteComponent, - Q extends Queries = typeof queries -> = { - container: HTMLElement; - component: C; - debug: (el?: HTMLElement | DocumentFragment) => void; - unmount: () => void; -} & { [P in keyof Q]: BoundFunction }; -export interface ILoadingStatus { - eta: number | null; - status: "pending" | "error" | "complete" | "generating" | "streaming"; - queue: boolean; - queue_position: number | null; - queue_size?: number; - fn_index: number; - message?: string | null; - scroll_to_output?: boolean; - show_progress?: "full" | "minimal" | "hidden"; - time_limit?: number | null | undefined; - progress?: { - progress: number | null; - index: number | null; - length: number | null; - unit: string | null; - desc: string | null; - }[]; - validation_error?: string | null; - type: "input" | "output"; - stream_state: "open" | "closed" | "waiting" | null; -} - -const loading_status: ILoadingStatus = { - eta: 0, - queue_position: 1, - queue_size: 1, - queue: true, - message: null, - time_limit: null, - progress: [], - validation_error: null, - type: "output", - stream_state: null, - status: "complete" as ILoadingStatus["status"], - scroll_to_output: false, - fn_index: 0, - show_progress: "full" as ILoadingStatus["show_progress"] -}; - -export interface RenderOptions { - container?: HTMLElement; - queries?: Q; -} - -export async function render< - Events extends Record, - Props extends Record, - T extends SvelteComponent, - X extends Record ->( - Component: ComponentType | { default: ComponentType }, - props?: Omit & { - loading_status?: LoadingStatus; - }, - options?: { - container?: HTMLElement; - } -): Promise< - RenderResult & { - listen: (event_name: string, opts?: { retrospective?: boolean }) => Mock; - set_data: (data: Record) => Promise; - get_data: () => Promise>; - } -> { - let container: HTMLElement; - if (!options?.container) { - container = document.body; - } else { - container = options.container; - } - - const target = container.appendChild(document.createElement("div")); - - const ComponentConstructor: ComponentType = - //@ts-ignore - Component.default || Component; - - const id = Math.floor(Math.random() * 1000000); - - let component_set_data: (data: Record) => void; - let component_get_data: () => Promise>; - - const mock_register = ( - _id: number, - set_data: (data: Record) => void, - get_data: () => Promise> - ): void => { - component_set_data = set_data; - component_get_data = get_data; - }; - - const event_listeners = new Map void>>(); - const event_buffer: Array<{ event: string; data: any }> = []; - - function notify_listeners(event: string, data: any): void { - const listeners = event_listeners.get(event); - if (listeners) { - for (const listener of listeners) { - listener(data); - } - } - } - - const dispatcher = (_id: number, event: string, data: any): void => { - event_buffer.push({ event, data }); - notify_listeners(event, data); - }; - - function listen( - event_name: string, - opts?: { retrospective?: boolean } - ): Mock { - const fn = vi.fn(); - if (!event_listeners.has(event_name)) { - event_listeners.set(event_name, new Set()); - } - event_listeners.get(event_name)!.add(fn); - - if (opts?.retrospective) { - for (const entry of event_buffer) { - if (entry.event === event_name) { - fn(entry.data); - } - } - } - - return fn; - } - - const i18nFormatter = (s: string | null | undefined): string => s ?? ""; - - const shared_props_obj: Record = { - id, - target, - theme_mode: "light" as const, - version: "2.0.0", - formatter: i18nFormatter, - client: {} as any, - load_component: () => Promise.resolve({ default: {} as any }), - show_progress: true, - api_prefix: "", - server: {} as any, - show_label: true, - register_component: mock_register, - dispatcher - }; - - const component_props_obj: Record = { - i18n: i18nFormatter - }; - - if (props) { - for (const key in props) { - const value = (props as any)[key]; - if (allowed_shared_props.includes(key as any)) { - shared_props_obj[key] = value; - } else { - component_props_obj[key] = value; - } - } - } - - shared_props_obj.loading_status = props?.loading_status - ? props.loading_status - : loading_status; - - const componentProps = { - shared_props: shared_props_obj, - props: { - ...component_props_obj - }, - ...shared_props_obj - }; - - const component = mount(ComponentConstructor, { - target, - props: componentProps - }) as T; - - containerCache.set(container, { target, component }); - componentCache.add(component); - - await tick(); - - return { - container, - component, - listen, - set_data: async (data: Record) => { - const r = component_set_data(data); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return r; - }, - get_data: () => component_get_data(), - //@ts-ignore - debug: (el = container): void => console.warn(prettyDOM(el)), - unmount: (): void => { - if (componentCache.has(component)) { - unmount(component); - } - }, - ...getQueriesForElement(container) - }; -} - -const cleanupAtContainer = (container: HTMLElement): void => { - const { target, component } = containerCache.get(container); - - if (componentCache.has(component)) { - unmount(component); - } - - if (target.parentNode === document.body) { - document.body.removeChild(target); - } - - containerCache.delete(container); -}; - -export function cleanup(): void { - Array.from(containerCache.keys()).forEach(cleanupAtContainer); - document.body.innerHTML = ""; -} - -type AsyncFireObject = { - [K in EventType]: ( - element: Document | Element | Window | Node, - options?: object - ) => Promise; -}; - -export const fireEvent = Object.keys(dtlFireEvent).reduce((acc, key) => { - const _key = key as EventType; - return { - ...acc, - [_key]: async ( - element: Document | Element | Window, - options: object = {} - ): Promise => { - const event = dtlFireEvent[_key](element, options); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return event; - } - }; -}, {} as AsyncFireObject); - -export type FireFunction = ( - element: Document | Element | Window, - event: Event -) => Promise; - -export { download_file, upload_file, drop_file } from "./download.js"; - -/** - * Creates a mock client suitable for components that use file uploads. - * The upload mock echoes back the input FileData unchanged. - */ -export function mock_client(): Record { - return { - upload: async (file_data: any[]) => file_data, - stream: async () => ({ onmessage: null, close: () => {} }) - }; -} -export { - TEST_TXT, - TEST_JPG, - TEST_PNG, - TEST_MP4, - TEST_WAV, - TEST_PDF -} from "./fixtures.js"; -export * from "@testing-library/dom"; diff --git a/6.13.1/tootils/src/shared-prop-tests.ts b/6.13.1/tootils/src/shared-prop-tests.ts deleted file mode 100644 index b8f58e68a13e368fd4a1f1d6f2e246260b82bcd0..0000000000000000000000000000000000000000 --- a/6.13.1/tootils/src/shared-prop-tests.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, test, expect, afterEach } from "vitest"; -import { render, cleanup } from "./render"; - -const loading_status = { - status: "complete", - queue_position: null, - queue_size: null, - eta: null, - message: null -}; - -export interface SharedPropTestConfig { - /** The Svelte component to test */ - component: any; - /** Minimum props required to render the component without errors */ - base_props: Record; - /** Display name for test output */ - name: string; - /** - * Some components don't render labels (e.g. HTML, Markdown). - * Set to false to skip label-related tests. - * @default true - */ - has_label?: boolean; - /** - * Whether the component renders validation_error text. - * Not all components support this. Set to false to skip. - * @default true - */ - has_validation_error?: boolean; - /** - * Some components (e.g. Accordion) map visible=false to "hidden" - * instead of removing from the DOM. Set to true to expect hidden - * behaviour rather than removal. - * @default false - */ - visible_false_hides?: boolean; - /** - * Whether the component is wrapped in a Block (which renders a `.block` - * element). Components like Button render a bare element instead. - * Set to false to skip `.block` selector checks. - * @default true - */ - has_block_wrapper?: boolean; -} - -export function run_shared_prop_tests(config: SharedPropTestConfig): void { - const { - component, - base_props, - name, - has_label = true, - has_validation_error = true, - visible_false_hides = false, - has_block_wrapper = true - } = config; - - const label = "Test Label"; - - function make_props( - overrides: Record = {} - ): Record { - return { - ...base_props, - loading_status: { ...loading_status, ...overrides }, - label, - ...overrides - }; - } - - describe(`${name}: shared props`, () => { - afterEach(() => cleanup()); - - test("elem_id is applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_id: "my-test-id" }) - ); - const el = container.querySelector("#my-test-id"); - expect(el).not.toBeNull(); - }); - - test("elem_classes are applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_classes: ["my-test-class"] }) - ); - const el = container.querySelector(".my-test-class"); - expect(el).not.toBeNull(); - }); - - test("visible: true renders the component", async () => { - const { container } = await render( - component, - make_props({ visible: true, elem_id: "visible-test" }) - ); - const el = has_block_wrapper - ? container.querySelector(".block") - : container.querySelector("#visible-test"); - expect(el).not.toBeNull(); - }); - - test("visible: 'hidden' hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: "hidden", elem_id: "hidden-test" }) - ); - - const el = result.container.querySelector("#hidden-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - - if (visible_false_hides) { - test("visible: false hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - } else { - test("visible: false removes the component from the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).toBeNull(); - }); - } - - if (has_label) { - test("label text is rendered", async () => { - const result = await render( - component, - make_props({ label: "My Custom Label", show_label: true }) - ); - const el = result.getByText("My Custom Label"); - expect(el).toBeTruthy(); - }); - - test("show_label: true makes the label visible", async () => { - const result = await render( - component, - make_props({ label: "Visible Label", show_label: true }) - ); - const el = result.getByText("Visible Label"); - expect(el).toBeVisible(); - }); - - test("show_label: false hides the label visually but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ label: "Hidden Label", show_label: false }) - ); - const el = result.getByText("Hidden Label"); - // The label remains in the DOM for screen readers via sr-only. - // sr-only uses clip/1px dimensions rather than display:none, - // so toBeVisible() won't catch it. We check the class directly. - expect(el.closest("[data-testid='block-info']")).toHaveClass("sr-only"); - }); - } - - if (has_validation_error) { - test("validation_error displays error text visibly", async () => { - const result = await render( - component, - make_props({ - validation_error: "This field is required", - show_validation_error: true - }) - ); - const el = result.getByText("This field is required"); - expect(el).toBeVisible(); - }); - } - }); -} diff --git a/6.13.1/upload/package.json b/6.13.1/upload/package.json deleted file mode 100644 index e69e58a5663f9425f287d6f4133191513f431980..0000000000000000000000000000000000000000 --- a/6.13.1/upload/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@gradio/upload", - "version": "0.17.9", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/upload" - } -} diff --git a/6.13.1/upload/src/ModifyUpload.svelte b/6.13.1/upload/src/ModifyUpload.svelte deleted file mode 100644 index 7c8db47405576b3b590d9bcb394d5e5848f7e240..0000000000000000000000000000000000000000 --- a/6.13.1/upload/src/ModifyUpload.svelte +++ /dev/null @@ -1,61 +0,0 @@ - - - - {#if editable} - onedit?.()} - /> - {/if} - - {#if undoable} - onundo?.()} - /> - {/if} - - {#if download} - - - - {/if} - - {#if children}{@render children()}{/if} - - { - onclear?.(); - event.stopPropagation(); - }} - /> - diff --git a/6.13.1/upload/src/Upload.svelte b/6.13.1/upload/src/Upload.svelte deleted file mode 100644 index 27183d59b8604ce79d9e90d44269ffb32bdb7225..0000000000000000000000000000000000000000 --- a/6.13.1/upload/src/Upload.svelte +++ /dev/null @@ -1,398 +0,0 @@ - - -{#if filetype === "clipboard"} - -{:else if uploading && show_progress} - {#if !hidden} - - {/if} -{:else} - -{/if} - - diff --git a/6.13.1/upload/src/UploadProgress.svelte b/6.13.1/upload/src/UploadProgress.svelte deleted file mode 100644 index 0ee9995f6d036d79048aca2705d530d3453ae7a1..0000000000000000000000000000000000000000 --- a/6.13.1/upload/src/UploadProgress.svelte +++ /dev/null @@ -1,199 +0,0 @@ - - -
- Uploading {files_with_progress.length} - {files_with_progress.length > 1 ? "files" : "file"}... - - {#if file_to_display} -
- -
- {getProgress(file_to_display)} -
-
- - {file_to_display.orig_name} - -
- {/if} -
- - diff --git a/6.13.1/upload/src/index.ts b/6.13.1/upload/src/index.ts deleted file mode 100644 index 0c2bdb5d7b2eb9c39953af027ae57cc674a0e377..0000000000000000000000000000000000000000 --- a/6.13.1/upload/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Upload } from "./Upload.svelte"; -export { default as ModifyUpload } from "./ModifyUpload.svelte"; -export { default as UploadProgress } from "./UploadProgress.svelte"; -export { create_drag } from "./utils"; diff --git a/6.13.1/upload/src/utils.ts b/6.13.1/upload/src/utils.ts deleted file mode 100644 index e961b85f75d154896c4be1656ed4e383bae0305b..0000000000000000000000000000000000000000 --- a/6.13.1/upload/src/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -interface DragActionOptions { - disable_click?: boolean; - accepted_types?: string | string[] | null; - mode?: "single" | "multiple" | "directory"; - on_drag_change?: (dragging: boolean) => void; - on_files?: (files: File[]) => void; -} - -type ActionReturn = { - update: (new_options: DragActionOptions) => void; - destroy: () => void; -}; - -export function create_drag(): { - drag: (node: HTMLElement, options: DragActionOptions) => ActionReturn; - open_file_upload: () => void; -} { - let hidden_input: HTMLInputElement; - let _options: DragActionOptions; - return { - drag( - node: HTMLElement, - options: DragActionOptions = {} - ): { - update: (new_options: DragActionOptions) => void; - destroy: () => void; - } { - _options = options; - - // Create and configure hidden file input - function setup_hidden_input(): void { - hidden_input = document.createElement("input"); - hidden_input.type = "file"; - hidden_input.style.display = "none"; - hidden_input.setAttribute("aria-label", "File upload"); - hidden_input.setAttribute("data-testid", "file-upload"); - const accept_options = Array.isArray(_options.accepted_types) - ? _options.accepted_types.join(",") - : _options.accepted_types || undefined; - - if (accept_options) { - hidden_input.accept = accept_options; - } - - hidden_input.multiple = _options.mode === "multiple" || false; - if (_options.mode === "directory") { - hidden_input.webkitdirectory = true; - hidden_input.setAttribute("directory", ""); - hidden_input.setAttribute("mozdirectory", ""); - } - node.appendChild(hidden_input); - } - - setup_hidden_input(); - - function handle_drag(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - } - - function handle_drag_enter(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(true); - } - - function handle_drag_leave(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - } - - function handle_drop(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - - if (!e.dataTransfer?.files) return; - const files = Array.from(e.dataTransfer.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - - function handle_click(): void { - if (!_options.disable_click) { - hidden_input.value = ""; - hidden_input.click(); - } - } - - function handle_file_input_change(): void { - if (hidden_input.files) { - const files = Array.from(hidden_input.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - } - - // Add all event listeners - node.addEventListener("drag", handle_drag); - node.addEventListener("dragstart", handle_drag); - node.addEventListener("dragend", handle_drag); - node.addEventListener("dragover", handle_drag); - node.addEventListener("dragenter", handle_drag_enter); - node.addEventListener("dragleave", handle_drag_leave); - node.addEventListener("drop", handle_drop); - node.addEventListener("click", handle_click); - hidden_input!.addEventListener("change", handle_file_input_change); - - return { - update(new_options: DragActionOptions) { - _options = new_options; - // Recreate hidden input with new options - hidden_input.remove(); - setup_hidden_input(); - hidden_input.addEventListener("change", handle_file_input_change); - }, - destroy() { - node.removeEventListener("drag", handle_drag); - node.removeEventListener("dragstart", handle_drag); - node.removeEventListener("dragend", handle_drag); - node.removeEventListener("dragover", handle_drag); - node.removeEventListener("dragenter", handle_drag_enter); - node.removeEventListener("dragleave", handle_drag_leave); - node.removeEventListener("drop", handle_drop); - node.removeEventListener("click", handle_click); - hidden_input.removeEventListener("change", handle_file_input_change); - hidden_input.remove(); - } - }; - }, - open_file_upload(): void { - if (hidden_input) { - hidden_input.value = ""; - hidden_input.click(); - } - } - }; -} diff --git a/6.13.1/uploadbutton/Index.svelte b/6.13.1/uploadbutton/Index.svelte deleted file mode 100644 index f246c8f96ea948a81cd7bcd7a2412b089ebbaea1..0000000000000000000000000000000000000000 --- a/6.13.1/uploadbutton/Index.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - gradio.dispatch("click")} - onchange={(detail) => handle_event(detail, "change")} - onupload={(detail) => handle_event(detail, "upload")} - onerror={(detail) => { - gradio.dispatch("error", detail); - }} - upload={(...args) => gradio.shared.client.upload(...args)} -> - {gradio.shared.label ?? ""} - diff --git a/6.13.1/uploadbutton/package.json b/6.13.1/uploadbutton/package.json deleted file mode 100644 index 657726b0534b1c5731cdf917e9d630aa45093a12..0000000000000000000000000000000000000000 --- a/6.13.1/uploadbutton/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@gradio/uploadbutton", - "version": "0.9.18", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "main": "./Index.svelte", - "dependencies": { - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/uploadbutton" - } -} diff --git a/6.13.1/uploadbutton/shared/UploadButton.svelte b/6.13.1/uploadbutton/shared/UploadButton.svelte deleted file mode 100644 index 3cb3b534036b7d1fa652fddd293a00c4f5687e03..0000000000000000000000000000000000000000 --- a/6.13.1/uploadbutton/shared/UploadButton.svelte +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - {#if icon} - {`${value} - {/if} - {#if children}{@render children()}{/if} - - - diff --git a/6.13.1/uploadbutton/types.ts b/6.13.1/uploadbutton/types.ts deleted file mode 100644 index 100547b8f9293f9cd2a191b09a6003e7f071a585..0000000000000000000000000000000000000000 --- a/6.13.1/uploadbutton/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface UploadButtonProps { - value: null | FileData | FileData[]; - file_count: string; - file_types: string[]; - size: "sm" | "lg"; - icon: FileData | null; - variant: "primary" | "secondary" | "stop"; -} - -export interface UploadButtonEvents { - change: never; - upload: never; - click: never; - error: string; -} diff --git a/6.13.1/utils/package.json b/6.13.1/utils/package.json deleted file mode 100644 index 97e34911592ce8b15a54ea071d740237220295dc..0000000000000000000000000000000000000000 --- a/6.13.1/utils/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@gradio/utils", - "version": "0.12.2", - "description": "Gradio UI packages", - "type": "module", - "main": "./src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/theme": "workspace:^", - "svelte-i18n": "^4.0.1" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/utils" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.13.1/utils/src/color.ts b/6.13.1/utils/src/color.ts deleted file mode 100644 index 86d3fe6a5c35c450cc6517b5f3d4767ffda1bc2c..0000000000000000000000000000000000000000 --- a/6.13.1/utils/src/color.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { colors, ordered_colors } from "@gradio/theme"; - -export const get_next_color = (index: number): keyof typeof colors => { - return ordered_colors[index % ordered_colors.length]; -}; diff --git a/6.13.1/utils/src/index.ts b/6.13.1/utils/src/index.ts deleted file mode 100644 index 8db07c80fcf3416332b4ec11d86c06a0fdfb7e74..0000000000000000000000000000000000000000 --- a/6.13.1/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./color.js"; -export * from "./utils.svelte.js"; -export * from "./types.js"; diff --git a/6.13.1/utils/src/types.ts b/6.13.1/utils/src/types.ts deleted file mode 100644 index 8dd47a49c34d6da4ce4328aa99f9fe563ecc7d89..0000000000000000000000000000000000000000 --- a/6.13.1/utils/src/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface CustomButton { - id: number; - value: string | null; - icon: FileData | null; -} diff --git a/6.13.1/utils/src/utils.svelte.ts b/6.13.1/utils/src/utils.svelte.ts deleted file mode 100644 index 1a7d54a3cfac850fd1dedcf10907105b157ade26..0000000000000000000000000000000000000000 --- a/6.13.1/utils/src/utils.svelte.ts +++ /dev/null @@ -1,575 +0,0 @@ -import type { ActionReturn } from "svelte/action"; -import type { Client } from "@gradio/client"; -import type { ComponentType, SvelteComponent } from "svelte"; -import { tick, untrack } from "svelte"; -import type { Component } from "svelte"; -import { locale } from "svelte-i18n"; - -export const I18N_MARKER = "__i18n__"; -const TRANSLATABLE_PROPS = [ - "label", - "info", - "placeholder", - "description", - "title", - "value" -]; - -export interface SharedProps { - elem_id?: string; - elem_classes: string[]; - components?: string[]; - server_fns?: string[]; - interactive: boolean; - visible: boolean | "hidden"; - id: number; - container: boolean; - target: HTMLElement; - theme_mode: "light" | "dark" | "system"; - version: string; - root: string; - autoscroll: boolean; - max_file_size: number | null; - formatter: any; //I18nFormatter; - client: Client; - scale: number; - min_width: number; - padding: number; - load_component: load_component; - loading_status?: any; - label: string; - show_label: boolean; - validation_error?: string | null; - theme?: "light" | "dark"; - show_progress: boolean; - api_prefix: string; - server: ServerFunctions; - attached_events?: string[]; - register_component: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - dispatcher: Function; -} - -export type LoadingComponent = Promise<{ - default: Component; -}>; - -export const GRADIO_ROOT = "GRADIO_ROOT"; - -export interface ValueData { - value: any; - is_value_data: boolean; -} - -export interface SelectData { - row_value?: any[]; - col_value?: any[]; - index: number | [number, number]; - value: any; - selected?: boolean; -} - -export interface LikeData { - index: number | [number, number]; - value: any; - liked?: boolean | string; -} - -export interface KeyUpData { - key: string; - input_value: string; -} - -export interface ShareData { - description: string; - title?: string; -} - -export interface CopyData { - value: string; -} - -export class ShareError extends Error { - constructor(message: string) { - super(message); - this.name = "ShareError"; - } -} - -export async function uploadToHuggingFace( - data: string | { url?: string; path?: string }, - type: "base64" | "url" -): Promise { - if (window.__gradio_space__ == null) { - throw new ShareError("Must be on Spaces to share."); - } - let blob: Blob; - let contentType: string; - let filename: string; - if (type === "url") { - let url: string; - - if (typeof data === "object" && data.url) { - url = data.url; - } else if (typeof data === "string") { - url = data; - } else { - throw new Error("Invalid data format for URL type"); - } - - const response = await fetch(url); - blob = await response.blob(); - contentType = response.headers.get("content-type") || ""; - filename = response.headers.get("content-disposition") || ""; - } else { - let dataurl: string; - - if (typeof data === "object" && data.path) { - dataurl = data.path; - } else if (typeof data === "string") { - dataurl = data; - } else { - throw new Error("Invalid data format for base64 type"); - } - - blob = dataURLtoBlob(dataurl); - contentType = dataurl.split(";")[0].split(":")[1]; - filename = "file." + contentType.split("/")[1]; - } - - const file = new File([blob], filename, { type: contentType }); - - // Send file to endpoint - const uploadResponse = await fetch("https://huggingface.co/uploads", { - method: "POST", - body: file, - headers: { - "Content-Type": file.type, - "X-Requested-With": "XMLHttpRequest" - } - }); - - // Check status of response - if (!uploadResponse.ok) { - if ( - uploadResponse.headers.get("content-type")?.includes("application/json") - ) { - const error = await uploadResponse.json(); - throw new ShareError(`Upload failed: ${error.error}`); - } - throw new ShareError(`Upload failed.`); - } - - // Return response if needed - const result = await uploadResponse.text(); - return result; -} - -function dataURLtoBlob(dataurl: string): Blob { - var arr = dataurl.split(","), - mime = (arr[0].match(/:(.*?);/) as RegExpMatchArray)[1], - bstr = atob(arr[1]), - n = bstr.length, - u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} - -export function copy(node: HTMLDivElement): ActionReturn { - node.addEventListener("click", handle_copy); - - async function handle_copy(event: MouseEvent): Promise { - const path = event.composedPath() as HTMLButtonElement[]; - - const [copy_button] = path.filter( - (e) => e?.tagName === "BUTTON" && e.classList.contains("copy_code_button") - ); - - if (copy_button) { - event.stopImmediatePropagation(); - - const copy_text = copy_button.parentElement!.innerText.trim(); - const copy_sucess_button = Array.from( - copy_button.children - )[1] as HTMLDivElement; - - const copied = await copy_to_clipboard(copy_text); - - if (copied) copy_feedback(copy_sucess_button); - - function copy_feedback(_copy_sucess_button: HTMLDivElement): void { - _copy_sucess_button.style.opacity = "1"; - setTimeout(() => { - _copy_sucess_button.style.opacity = "0"; - }, 2000); - } - } - } - - return { - destroy(): void { - node.removeEventListener("click", handle_copy); - } - }; -} - -async function copy_to_clipboard(value: string): Promise { - let copied = false; - if ("clipboard" in navigator) { - await navigator.clipboard.writeText(value); - copied = true; - } else { - const textArea = document.createElement("textarea"); - textArea.value = value; - - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - copied = true; - } catch (error) { - console.error(error); - copied = false; - } finally { - textArea.remove(); - } - } - - return copied; -} - -export const format_time = (seconds: number): string => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const seconds_remainder = Math.round(seconds) % 60; - const padded_minutes = `${minutes < 10 ? "0" : ""}${minutes}`; - const padded_seconds = `${ - seconds_remainder < 10 ? "0" : "" - }${seconds_remainder}`; - - if (hours > 0) { - return `${hours}:${padded_minutes}:${padded_seconds}`; - } - return `${minutes}:${padded_seconds}`; -}; - -interface Args { - api_url: string; - name: string; - id?: string; - variant: "component" | "example" | "base"; -} - -export type component_loader = (args: Args) => { - component: { - default: ComponentType; - }; -}; - -export type LoadedComponentWithRuntime = { - component: LoadingComponent; - runtime: false | typeof import("svelte"); -}; - -export type load_component = ( - name: string, - variant: "component" | "example" | "base", - component_class_id?: string -) => LoadedComponentWithRuntime; - -const is_browser = typeof window !== "undefined"; - -export type ServerFunctions = Record Promise>; - -export const allowed_shared_props: (keyof SharedProps)[] = [ - "elem_id", - "elem_classes", - "visible", - "interactive", - "server_fns", - "server", - "id", - "target", - "theme_mode", - "version", - "root", - "autoscroll", - "max_file_size", - "formatter", - "client", - "load_component", - "scale", - "min_width", - "theme", - "padding", - "loading_status", - "label", - "show_label", - "validation_error", - "show_progress", - "api_prefix", - "container", - "attached_events", - "register_component", - "dispatcher" -] as const; - -export type I18nFormatter = any; - -export function has_i18n_marker(value: unknown): value is string { - return typeof value === "string" && value.includes(I18N_MARKER); -} - -export function translate_i18n_marker( - value: string, - translate: (key: string) => string -): string { - const start = value.indexOf(I18N_MARKER); - if (start === -1) return value; - - const json_start = start + I18N_MARKER.length; - const json_end = value.indexOf("}", json_start) + 1; - if (json_end === 0) return value; - - try { - const metadata = JSON.parse(value.slice(json_start, json_end)); - if (metadata?.key) { - const translated = translate(metadata.key); - const result = translated !== metadata.key ? translated : metadata.key; - return value.slice(0, start) + result + value.slice(json_end); - } - } catch {} - - return value; -} - -export class Gradio { - load_component: load_component; - shared: SharedProps = $state({} as SharedProps) as SharedProps; - props = $state({} as U) as U; - i18n: I18nFormatter = $state((v: string) => v) as any; - translatable_props: Record = {}; - dispatcher!: Function; - last_update: ReturnType | null = null; - shared_props: (keyof SharedProps)[] = allowed_shared_props; - mounted: boolean = false; - old_value: any; - register_component!: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - - constructor( - _props: { shared_props: SharedProps; props: U }, - default_values?: Partial - ) { - for (const key in _props.shared_props) { - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - - if (default_values) { - for (const key in default_values) { - if (this.props[key as keyof U] === undefined) { - // @ts-ignore - this.props[key] = default_values[key as keyof U]; - } - } - } - // @ts-ignore same here - this.i18n = this.props.i18n ?? ((v: string) => v); - - for (const key of TRANSLATABLE_PROPS) { - // @ts-ignore - this.shared[key] = this._translate_and_store( - "shared", - key, - // @ts-ignore - _props.shared_props[key] - ); - // @ts-ignore - this.props[key] = this._translate_and_store( - "props", - key, - // @ts-ignore - _props.props[key] - ); - } - - this.load_component = this.shared.load_component; - - this.register_component = this.shared.register_component || (() => {}); - this.dispatcher = this.shared.dispatcher || (() => {}); - - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - - $effect(() => { - // Need to update the props here - // otherwise UI won't reflect latest state from render - for (const key in _props.shared_props) { - // @ts-ignore - if (this._is_i18n_managed(`shared.${key}`, _props.shared_props[key])) - continue; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - if (this._is_i18n_managed(`props.${key}`, _props.props[key])) continue; - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - untrack(() => { - this.shared.id = _props.shared_props.id; - }); - }); - - // retranslate props when locale changes - if (Object.keys(this.translatable_props).length > 0) { - locale.subscribe(() => { - for (const [full_key, original] of Object.entries( - this.translatable_props - )) { - const [target, key] = full_key.split("."); - const translated = this.i18n(original); - // @ts-ignore - if (target === "shared") this.shared[key] = translated; - // @ts-ignore - else this.props[key] = translated; - } - }); - } - } - - // check if props are translatable - _is_i18n_managed(key: string, new_value: unknown): boolean { - const original_marker = this.translatable_props[key]; - if (!original_marker) return false; - if (new_value === original_marker) return true; - // if value has changed then remove key - delete this.translatable_props[key]; - return false; - } - - _translate_and_store( - target: "shared" | "props", - key: string, - value: unknown - ): unknown { - if (typeof value !== "string") return value; - const translated = this.i18n(value); - if (translated !== value) { - this.translatable_props[`${target}.${key}`] = value; - } - return translated; - } - - dispatch(event_name: E, data?: T[E]): void { - this.dispatcher(this.shared.id, event_name, data); - } - - async get_data() { - return $state.snapshot(this.props); - } - - update(data: Partial): void { - this.set_data(data as U & SharedProps); - } - - set_data(data: Partial): void { - for (const key in data) { - // @ts-ignore - const value = data[key]; - const translated = has_i18n_marker(value) - ? this._translate_and_store( - this.shared_props.includes(key as keyof SharedProps) - ? "shared" - : "props", - key, - value - ) - : value; - - if (this.shared_props.includes(key as keyof SharedProps)) { - const _key = key as keyof SharedProps; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[_key] = translated; - continue; - } - // @ts-ignore - this.props[key] = translated; - } - } - - watch_for_change() { - $effect(() => { - if (!this.mounted) { - // @ts-ignore - this.old_value = this.props.value; - this.mounted = true; - } - // @ts-ignore - if (this.old_value != this.props.value) { - // @ts-ignore - this.old_value = this.props.value; - // @ts-ignore - this.dispatch("change"); - } - }); - } -} - -// function _load_component( -// this: Gradio, -// name: string, -// variant: "component" | "example" | "base" = "component" -// ): ReturnType { -// return this._load_component!({ -// name, -// api_url: this.shared.client.config?.root!, -// variant -// }); -// } - -export const css_units = (dimension_value: string | number): string => { - return typeof dimension_value === "number" - ? dimension_value + "px" - : dimension_value; -}; - -export function should_show_scroll_fade( - container: HTMLElement | null -): boolean { - if (!container) return false; - const has_overflow = container.scrollHeight > container.clientHeight; - const at_bottom = - container.scrollTop >= container.scrollHeight - container.clientHeight - 1; - return has_overflow && !at_bottom; -} - -type MappedProps = { [K in keyof T]: T[K] }; -type MappedProp = { [P in K]: T[P] }; diff --git a/6.13.1/vibeeditor/Index.svelte b/6.13.1/vibeeditor/Index.svelte deleted file mode 100644 index 6db9b3cb7167948ae0f14cabd9d66c791deb9e2d..0000000000000000000000000000000000000000 --- a/6.13.1/vibeeditor/Index.svelte +++ /dev/null @@ -1,764 +0,0 @@ - - -
- -
- - -
- -
- {#if activeTab === "chat"} -
- {#each message_history as message, index} -
-
- - - - {#if !message.isBot && message.hash && !message.isPending} - - {/if} -
-
- {/each} - - {#if message_history.length === 0} -
No messages yet
- {/if} - - {#if message_history.length === 0} -
-
- {#each starterQueries as query} - - {/each} -
-
- {/if} -
- {:else if activeTab === "code"} -
-
- -
- - -
- {/if} -
- -
-
Powered by: gpt-oss
- - {#if showTagMenu && currentLineIndex === i} -
- [s, i])} - filtered_indices={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )} - active_index={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )[selectedOptionIndex]} - show_options={true} - onchange={(e) => insert_tag(e)} - {offset_from_top} - from_top={true} - /> -
- {/if} -
-
- {#if gradio.props.max_lines == undefined || (gradio.props.max_lines && i < gradio.props.max_lines - 1)} -
- -
- {/if} -
- -
- - {/each} - - {:else if checked || gradio.props.ui_mode !== "dialogue"} -
- {#if is_formatting} -
-
-
Converting to plain text...
-
- {/if} - - {/if} - {#if submit_btn} - - {/if} - {#if stop_btn} - - {/if} -
- - - diff --git a/6.14.0/textbox/types.ts b/6.14.0/textbox/types.ts deleted file mode 100644 index 8ec1cfc945755962a887be7207b0f60290ad929a..0000000000000000000000000000000000000000 --- a/6.14.0/textbox/types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type SelectData, - type CopyData, - type CustomButton -} from "@gradio/utils"; -import type { LoadingStatus } from "@gradio/statustracker"; - -export interface TextboxEvents { - change: string; - submit: never; - blur: never; - select: SelectData; - input: never; - focus: never; - stop: never; - clear_status: LoadingStatus; - copy: CopyData; - custom_button_click: { id: number }; -} - -export interface TextboxProps { - value: string; - info: string; - lines: number; - type: "text" | "password" | "email" | undefined; - rtl: boolean; - text_align: "right" | "left"; - max_lines: number; - placeholder: string; - submit_btn: string; - stop_btn: string; - buttons: (string | CustomButton)[] | null; - autofocus: boolean; - autoscroll: boolean; - max_length: number; - html_attributes: InputHTMLAttributes; - validation_error: string | null; -} - -type FullAutoFill = - | AutoFill - | "bday" - | `${OptionalPrefixToken}${"cc-additional-name"}` - | "nickname" - | "language" - | "organization-title" - | "photo" - | "sex" - | "url"; - -export interface InputHTMLAttributes { - autocapitalize?: - | "off" - | "none" - | "on" - | "sentences" - | "words" - | "characters" - | null; - autocorrect?: "on" | "off" | null; - spellcheck?: boolean | null; - autocomplete?: FullAutoFill | undefined | null; - tabindex?: number | null; - enterkeyhint?: - | "enter" - | "done" - | "go" - | "next" - | "previous" - | "search" - | "send" - | null; - lang?: string | null; -} diff --git a/6.14.0/theme/package.json b/6.14.0/theme/package.json deleted file mode 100644 index bb4343fa73bdf0fe073c0d611292babaf9cc8d6b..0000000000000000000000000000000000000000 --- a/6.14.0/theme/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@gradio/theme", - "version": "0.6.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": false, - "scripts": { - "generate": "pollen -c src/pollen.config.mjs", - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./reset.css": { - "gradio": "./src/reset.css", - "import": "./dist/src/reset.css" - }, - "./global.css": { - "gradio": "./src/global.css", - "import": "./dist/src/global.css" - }, - "./tokens": { - "gradio": "./src/tokens.ts", - "import": "./dist/src/tokens.js" - }, - "./typography.css": { - "gradio": "./src/typography.css", - "import": "./dist/src/typography.css" - }, - "./gradio-style.scss": { - "gradio": "./src/gradio-style.scss", - "import": "./dist/src/gradio-style.scss" - }, - "./pollen.css": { - "gradio": "./src/pollen.css", - "import": "./dist/src/pollen.css" - }, - "./package.json": "./package.json" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/theme" - } -} diff --git a/6.14.0/theme/src/colors.ts b/6.14.0/theme/src/colors.ts deleted file mode 100644 index 04a9c9b33c631635832a8fb982ce1d29e0176fa7..0000000000000000000000000000000000000000 --- a/6.14.0/theme/src/colors.ts +++ /dev/null @@ -1,350 +0,0 @@ -// import tw_colors from "tailwindcss/colors"; - -export const ordered_colors = [ - "red", - "green", - "blue", - "yellow", - "purple", - "teal", - "orange", - "cyan", - "lime", - "pink" -] as const; -interface ColorPair { - primary: string; - secondary: string; -} - -interface Colors { - red: ColorPair; - green: ColorPair; - blue: ColorPair; - yellow: ColorPair; - purple: ColorPair; - teal: ColorPair; - orange: ColorPair; - cyan: ColorPair; - lime: ColorPair; - pink: ColorPair; -} - -// https://play.tailwindcss.com/ZubQYya0aN -export const color_values = [ - { color: "red", primary: 600, secondary: 100 }, - { color: "green", primary: 600, secondary: 100 }, - { color: "blue", primary: 600, secondary: 100 }, - { color: "yellow", primary: 500, secondary: 100 }, - { color: "purple", primary: 600, secondary: 100 }, - { color: "teal", primary: 600, secondary: 100 }, - { color: "orange", primary: 600, secondary: 100 }, - { color: "cyan", primary: 600, secondary: 100 }, - { color: "lime", primary: 500, secondary: 100 }, - { color: "pink", primary: 600, secondary: 100 } -] as const; - -const tw_colors = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - slate: { - 50: "#f8fafc", - 100: "#f1f5f9", - 200: "#e2e8f0", - 300: "#cbd5e1", - 400: "#94a3b8", - 500: "#64748b", - 600: "#475569", - 700: "#334155", - 800: "#1e293b", - 900: "#0f172a", - 950: "#020617" - }, - gray: { - 50: "#f9fafb", - 100: "#f3f4f6", - 200: "#e5e7eb", - 300: "#d1d5db", - 400: "#9ca3af", - 500: "#6b7280", - 600: "#4b5563", - 700: "#374151", - 800: "#1f2937", - 900: "#111827", - 950: "#030712" - }, - zinc: { - 50: "#fafafa", - 100: "#f4f4f5", - 200: "#e4e4e7", - 300: "#d4d4d8", - 400: "#a1a1aa", - 500: "#71717a", - 600: "#52525b", - 700: "#3f3f46", - 800: "#27272a", - 900: "#18181b", - 950: "#09090b" - }, - neutral: { - 50: "#fafafa", - 100: "#f5f5f5", - 200: "#e5e5e5", - 300: "#d4d4d4", - 400: "#a3a3a3", - 500: "#737373", - 600: "#525252", - 700: "#404040", - 800: "#262626", - 900: "#171717", - 950: "#0a0a0a" - }, - stone: { - 50: "#fafaf9", - 100: "#f5f5f4", - 200: "#e7e5e4", - 300: "#d6d3d1", - 400: "#a8a29e", - 500: "#78716c", - 600: "#57534e", - 700: "#44403c", - 800: "#292524", - 900: "#1c1917", - 950: "#0c0a09" - }, - red: { - 50: "#fef2f2", - 100: "#fee2e2", - 200: "#fecaca", - 300: "#fca5a5", - 400: "#f87171", - 500: "#ef4444", - 600: "#dc2626", - 700: "#b91c1c", - 800: "#991b1b", - 900: "#7f1d1d", - 950: "#450a0a" - }, - orange: { - 50: "#fff7ed", - 100: "#ffedd5", - 200: "#fed7aa", - 300: "#fdba74", - 400: "#fb923c", - 500: "#f97316", - 600: "#ea580c", - 700: "#c2410c", - 800: "#9a3412", - 900: "#7c2d12", - 950: "#431407" - }, - amber: { - 50: "#fffbeb", - 100: "#fef3c7", - 200: "#fde68a", - 300: "#fcd34d", - 400: "#fbbf24", - 500: "#f59e0b", - 600: "#d97706", - 700: "#b45309", - 800: "#92400e", - 900: "#78350f", - 950: "#451a03" - }, - yellow: { - 50: "#fefce8", - 100: "#fef9c3", - 200: "#fef08a", - 300: "#fde047", - 400: "#facc15", - 500: "#eab308", - 600: "#ca8a04", - 700: "#a16207", - 800: "#854d0e", - 900: "#713f12", - 950: "#422006" - }, - lime: { - 50: "#f7fee7", - 100: "#ecfccb", - 200: "#d9f99d", - 300: "#bef264", - 400: "#a3e635", - 500: "#84cc16", - 600: "#65a30d", - 700: "#4d7c0f", - 800: "#3f6212", - 900: "#365314", - 950: "#1a2e05" - }, - green: { - 50: "#f0fdf4", - 100: "#dcfce7", - 200: "#bbf7d0", - 300: "#86efac", - 400: "#4ade80", - 500: "#22c55e", - 600: "#16a34a", - 700: "#15803d", - 800: "#166534", - 900: "#14532d", - 950: "#052e16" - }, - emerald: { - 50: "#ecfdf5", - 100: "#d1fae5", - 200: "#a7f3d0", - 300: "#6ee7b7", - 400: "#34d399", - 500: "#10b981", - 600: "#059669", - 700: "#047857", - 800: "#065f46", - 900: "#064e3b", - 950: "#022c22" - }, - teal: { - 50: "#f0fdfa", - 100: "#ccfbf1", - 200: "#99f6e4", - 300: "#5eead4", - 400: "#2dd4bf", - 500: "#14b8a6", - 600: "#0d9488", - 700: "#0f766e", - 800: "#115e59", - 900: "#134e4a", - 950: "#042f2e" - }, - cyan: { - 50: "#ecfeff", - 100: "#cffafe", - 200: "#a5f3fc", - 300: "#67e8f9", - 400: "#22d3ee", - 500: "#06b6d4", - 600: "#0891b2", - 700: "#0e7490", - 800: "#155e75", - 900: "#164e63", - 950: "#083344" - }, - sky: { - 50: "#f0f9ff", - 100: "#e0f2fe", - 200: "#bae6fd", - 300: "#7dd3fc", - 400: "#38bdf8", - 500: "#0ea5e9", - 600: "#0284c7", - 700: "#0369a1", - 800: "#075985", - 900: "#0c4a6e", - 950: "#082f49" - }, - blue: { - 50: "#eff6ff", - 100: "#dbeafe", - 200: "#bfdbfe", - 300: "#93c5fd", - 400: "#60a5fa", - 500: "#3b82f6", - 600: "#2563eb", - 700: "#1d4ed8", - 800: "#1e40af", - 900: "#1e3a8a", - 950: "#172554" - }, - indigo: { - 50: "#eef2ff", - 100: "#e0e7ff", - 200: "#c7d2fe", - 300: "#a5b4fc", - 400: "#818cf8", - 500: "#6366f1", - 600: "#4f46e5", - 700: "#4338ca", - 800: "#3730a3", - 900: "#312e81", - 950: "#1e1b4b" - }, - violet: { - 50: "#f5f3ff", - 100: "#ede9fe", - 200: "#ddd6fe", - 300: "#c4b5fd", - 400: "#a78bfa", - 500: "#8b5cf6", - 600: "#7c3aed", - 700: "#6d28d9", - 800: "#5b21b6", - 900: "#4c1d95", - 950: "#2e1065" - }, - purple: { - 50: "#faf5ff", - 100: "#f3e8ff", - 200: "#e9d5ff", - 300: "#d8b4fe", - 400: "#c084fc", - 500: "#a855f7", - 600: "#9333ea", - 700: "#7e22ce", - 800: "#6b21a8", - 900: "#581c87", - 950: "#3b0764" - }, - fuchsia: { - 50: "#fdf4ff", - 100: "#fae8ff", - 200: "#f5d0fe", - 300: "#f0abfc", - 400: "#e879f9", - 500: "#d946ef", - 600: "#c026d3", - 700: "#a21caf", - 800: "#86198f", - 900: "#701a75", - 950: "#4a044e" - }, - pink: { - 50: "#fdf2f8", - 100: "#fce7f3", - 200: "#fbcfe8", - 300: "#f9a8d4", - 400: "#f472b6", - 500: "#ec4899", - 600: "#db2777", - 700: "#be185d", - 800: "#9d174d", - 900: "#831843", - 950: "#500724" - }, - rose: { - 50: "#fff1f2", - 100: "#ffe4e6", - 200: "#fecdd3", - 300: "#fda4af", - 400: "#fb7185", - 500: "#f43f5e", - 600: "#e11d48", - 700: "#be123c", - 800: "#9f1239", - 900: "#881337", - 950: "#4c0519" - } -}; - -export const colors = color_values.reduce( - (acc, { color, primary, secondary }) => ({ - ...acc, - [color]: { - primary: tw_colors[color][primary], - secondary: tw_colors[color][secondary] - } - }), - {} as Colors -); diff --git a/6.14.0/theme/src/index.ts b/6.14.0/theme/src/index.ts deleted file mode 100644 index bd1cb299eaa9b1ae2f6bd0c1973fa12d0c4cdb57..0000000000000000000000000000000000000000 --- a/6.14.0/theme/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// export { default as reset } from "./reset.css"; -// export { default as global } from "./global.css"; -// export { default as css } from "./pollen.css"; -// export { default as typography } from "./typography.css"; - -export * from "./colors.js"; diff --git a/6.14.0/timer/Index.svelte b/6.14.0/timer/Index.svelte deleted file mode 100644 index 7fc7857ad7235b62c97ffb4fccba78a6c9d89fd9..0000000000000000000000000000000000000000 --- a/6.14.0/timer/Index.svelte +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/6.14.0/timer/package.json b/6.14.0/timer/package.json deleted file mode 100644 index 69e4fd022b1204bf416a79f66fbf6f1c0e859744..0000000000000000000000000000000000000000 --- a/6.14.0/timer/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@gradio/timer", - "version": "0.4.9", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "dependencies": { - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/timer" - } -} diff --git a/6.14.0/timer/types.ts b/6.14.0/timer/types.ts deleted file mode 100644 index 292d729b4daf9b93f8261167f14496b64a103084..0000000000000000000000000000000000000000 --- a/6.14.0/timer/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimerProps { - value: number; - active: boolean; -} - -export interface TimerEvents { - tick: never; - clear_status: never; -} diff --git a/6.14.0/tooltip/package.json b/6.14.0/tooltip/package.json deleted file mode 100644 index 1b699440866a7a7c79de9e7575bc07b5373465fe..0000000000000000000000000000000000000000 --- a/6.14.0/tooltip/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@gradio/tooltip", - "version": "0.2.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/tooltip" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.js", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - } -} diff --git a/6.14.0/tooltip/src/Tooltip.svelte b/6.14.0/tooltip/src/Tooltip.svelte deleted file mode 100644 index c9c9ecca6357234953144bcf6a0dbe7ee5e822de..0000000000000000000000000000000000000000 --- a/6.14.0/tooltip/src/Tooltip.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - {text} -
- - diff --git a/6.14.0/tooltip/src/index.ts b/6.14.0/tooltip/src/index.ts deleted file mode 100644 index b89ac870e5bbf6d90058c6e25cb9d74b626b3809..0000000000000000000000000000000000000000 --- a/6.14.0/tooltip/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { tooltip } from "./tooltip"; diff --git a/6.14.0/tooltip/src/tooltip.ts b/6.14.0/tooltip/src/tooltip.ts deleted file mode 100644 index 09403f9438805f29a32579b8e98a25f3aae37737..0000000000000000000000000000000000000000 --- a/6.14.0/tooltip/src/tooltip.ts +++ /dev/null @@ -1,49 +0,0 @@ -import Tooltip from "./Tooltip.svelte"; - -interface ActionArgs { - color: string; - text: string; -} - -export function tooltip( - element: HTMLElement | SVGElement, - { color, text }: ActionArgs -): any { - let tooltipComponent: Tooltip; - function mouse_over(event: MouseEvent): MouseEvent { - tooltipComponent = new Tooltip({ - props: { - text, - x: event.pageX, - y: event.pageY, - color - }, - target: document.body - }); - - return event; - } - function mouseMove(event: MouseEvent): void { - tooltipComponent.$set({ - x: event.pageX, - y: event.pageY - }); - } - function mouseLeave(): void { - tooltipComponent.$destroy(); - } - - const el = element as HTMLElement; - - el.addEventListener("mouseover", mouse_over); - el.addEventListener("mouseleave", mouseLeave); - el.addEventListener("mousemove", mouseMove); - - return { - destroy() { - el.removeEventListener("mouseover", mouse_over); - el.removeEventListener("mouseleave", mouseLeave); - el.removeEventListener("mousemove", mouseMove); - } - }; -} diff --git a/6.14.0/tootils/package.json b/6.14.0/tootils/package.json deleted file mode 100644 index 48eb1d1965ba7996b019d3fb54d5d4641d35b44f..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@self/tootils", - "version": "0.14.0", - "description": "Internal test utilities", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": "./src/index.ts", - "./render": "./src/render.ts", - "./shared-prop-tests": "./src/shared-prop-tests.ts", - "./app-launcher": "./src/app-launcher.ts", - "./download-command": "./src/download-command.ts" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.14.0/tootils/src/app-launcher.ts b/6.14.0/tootils/src/app-launcher.ts deleted file mode 100644 index 64ea714de850dadb6875517d456b65952203ea49..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/app-launcher.ts +++ /dev/null @@ -1,276 +0,0 @@ -import { spawn, spawnSync, type ChildProcess } from "node:child_process"; -import http from "http"; -import net from "net"; -import path from "path"; -import fs from "fs"; -import os from "os"; -import url from "url"; - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -const ROOT_DIR = path.resolve(__dirname, "../../.."); - -export interface GradioApp { - port: number; - process: ChildProcess; -} - -export function killGradioApp(process: ChildProcess): void { - try { - process.kill("SIGTERM"); - } catch { - // Process may already be dead - } -} - -/** - * Sweep orphaned gradio demo python processes — i.e. processes running - * `python /run.py` whose parent has died (PPID == 1, reparented to - * init/launchd). Without this, a Playwright worker that crashes (e.g. - * after a test timeout) leaves its spawned demo apps behind: the new - * worker has an empty appCache and won't kill them, ports get squatted, - * and resources accumulate. Documented behavior, not a guess: in the SSR - * profile run, this orphaning produced 100+ leaked python procs / 7.5GB. - * - * Best-effort: failures in the sweep are swallowed so they can't block - * the spawn path itself. - */ -function reapOrphanedDemos(): void { - try { - const result = spawnSync("ps", ["-A", "-o", "pid=,ppid=,command="], { - encoding: "utf8" - }); - if (result.status !== 0 || !result.stdout) return; - - for (const line of result.stdout.split("\n")) { - const trimmed = line.trim(); - if (!trimmed) continue; - const match = trimmed.match(/^(\d+)\s+(\d+)\s+(.*)$/); - if (!match) continue; - const [, pidStr, ppidStr, cmd] = match; - if (ppidStr !== "1") continue; - // Only target our test demo apps (python running gradio demo files). - // Match `gradio/.../demo//.py` to avoid accidentally - // killing unrelated python processes. - if (!/python.*\/demo\/[^/]+\/[^/]+\.py/.test(cmd)) continue; - if (!cmd.includes("/gradio/")) continue; - try { - process.kill(Number(pidStr), "SIGTERM"); - } catch { - // already dead, or not ours to kill - } - } - } catch { - // ps unavailable or parse error — non-fatal - } -} - -export async function findFreePort( - startPort: number, - endPort: number -): Promise { - for (let port = startPort; port < endPort; port++) { - if (await isPortFree(port)) { - return port; - } - } - throw new Error(`Could not find free port in range ${startPort}-${endPort}`); -} - -function isPortFree(port: number): Promise { - return new Promise((resolve) => { - const sock = net.createConnection(port, "127.0.0.1"); - sock.once("connect", () => { - sock.end(); - resolve(false); - }); - sock.once("error", (e: NodeJS.ErrnoException) => { - sock.destroy(); - // ECONNREFUSED → no listener (free). Anything else (ECONNRESET from - // a half-closed socket left by a SIGTERM'd demo, ETIMEDOUT, etc.) - // → don't trust the port, skip to the next one. Previously we - // rejected on non-ECONNREFUSED errors, which aborted the whole - // findFreePort scan and surfaced as "Failed to launch app". - resolve(e.code === "ECONNREFUSED"); - }); - }); -} - -/** - * Poll the server with HTTP GET requests until it returns a response. - * Gradio prints "Running on local URL:" before the server is fully ready, - * so we need to verify it actually responds to HTTP requests. - */ -async function waitForServerReady( - port: number, - timeoutMs: number = 15000 -): Promise { - const start = Date.now(); - const pollInterval = 200; - - while (Date.now() - start < timeoutMs) { - try { - await new Promise((resolve, reject) => { - // Use HEAD on /gradio_api/info to avoid triggering SSR rendering on - // the root URL, which could block Gradio's own startup health check. - const req = http.request( - `http://127.0.0.1:${port}/gradio_api/info`, - { method: "HEAD", timeout: 2000 }, - (res) => { - res.resume(); // drain the response - resolve(); - } - ); - req.on("error", reject); - req.on("timeout", () => { - req.destroy(); - reject(new Error("request timeout")); - }); - req.end(); - }); - return; // Server responded successfully - } catch { - // Server not ready yet, wait and retry - await new Promise((r) => setTimeout(r, pollInterval)); - } - } - throw new Error( - `Server on port ${port} did not become ready within ${timeoutMs}ms` - ); -} - -export function getTestcases(demoName: string): string[] { - const demoDir = path.join(ROOT_DIR, "demo", demoName); - if (!fs.existsSync(demoDir)) { - return []; - } - - return fs - .readdirSync(demoDir) - .filter((f) => f.endsWith("_testcase.py")) - .map((f) => path.basename(f, ".py")); -} - -// Check if a testcase file exists for this demo -export function hasTestcase(demoName: string, testcaseName: string): boolean { - const testcaseFile = path.join( - ROOT_DIR, - "demo", - demoName, - `${testcaseName}_testcase.py` - ); - return fs.existsSync(testcaseFile); -} - -// Get the path to a demo's Python file -function getDemoFilePath(demoName: string, testcaseName?: string): string { - if (testcaseName) { - return path.join(ROOT_DIR, "demo", demoName, `${testcaseName}_testcase.py`); - } - return path.join(ROOT_DIR, "demo", demoName, "run.py"); -} - -export async function launchGradioApp( - demoName: string, - workerIndex: number = 0, - timeout: number = 60000, - testcaseName?: string -): Promise { - // Sweep orphaned demo apps from previous (crashed) worker generations - // before claiming a port — see reapOrphanedDemos() for rationale. - reapOrphanedDemos(); - - // Partition ports by worker index to avoid collisions - const basePort = 7860 + workerIndex * 100; - const port = await findFreePort(basePort, basePort + 99); - - // Get the path to the demo file - const demoFilePath = getDemoFilePath(demoName, testcaseName); - - // Create unique directories for this instance to avoid cache conflicts - const instanceId = testcaseName - ? `${demoName}_${testcaseName}_${port}` - : `${demoName}_${port}`; - const instanceDir = path.join(os.tmpdir(), `gradio_test_${instanceId}`); - const cacheDir = path.join(instanceDir, "cached_examples"); - const tempDir = path.join(instanceDir, "temp"); - - if (!fs.existsSync(instanceDir)) { - fs.mkdirSync(instanceDir, { recursive: true }); - } - - // Run the demo via _demo_runner.py instead of directly. The wrapper - // watches its stdin pipe: if the playwright worker that spawned us - // dies (cleanly or via SIGKILL on timeout), the kernel closes the pipe, - // stdin returns EOF and the demo self-exits immediately — instead of - // becoming an orphan that survives the rest of the suite. - const demoRunnerPath = path.join(__dirname, "_demo_runner.py"); - const childProcess = spawn("python", [demoRunnerPath, demoFilePath], { - stdio: "pipe", - cwd: ROOT_DIR, - env: { - ...process.env, - PYTHONUNBUFFERED: "true", - GRADIO_ANALYTICS_ENABLED: "False", - GRADIO_IS_E2E_TEST: "1", - GRADIO_RESET_EXAMPLES_CACHE: "True", - // Control the port via environment variable - GRADIO_SERVER_PORT: port.toString(), - // Use unique directories per instance to avoid conflicts - GRADIO_EXAMPLES_CACHE: cacheDir, - GRADIO_TEMP_DIR: tempDir - } - }); - - childProcess.stdout?.setEncoding("utf8"); - childProcess.stderr?.setEncoding("utf8"); - - // Wait for app to be ready - return new Promise((resolve, reject) => { - const timeoutId = setTimeout(() => { - killGradioApp(childProcess); - reject( - new Error(`Gradio app ${demoName} failed to start within ${timeout}ms`) - ); - }, timeout); - - let output = ""; - let startupDetected = false; - - function handleOutput(data: string): void { - output += data; - // Check for Gradio's startup message - if ( - !startupDetected && - (data.includes("Running on local URL:") || - data.includes(`Uvicorn running on`)) - ) { - startupDetected = true; - clearTimeout(timeoutId); - // The startup message is printed before the server is fully ready. - // Poll with HTTP requests to ensure it actually responds. - waitForServerReady(port) - .then(() => resolve({ port, process: childProcess })) - .catch(reject); - } - } - - childProcess.stdout?.on("data", handleOutput); - childProcess.stderr?.on("data", handleOutput); - - childProcess.on("error", (err) => { - clearTimeout(timeoutId); - reject(err); - }); - - childProcess.on("exit", (code) => { - if (code !== 0 && code !== null) { - clearTimeout(timeoutId); - reject( - new Error( - `Gradio app ${demoName} exited with code ${code}.\nOutput: ${output}` - ) - ); - } - }); - }); -} diff --git a/6.14.0/tootils/src/download-command.ts b/6.14.0/tootils/src/download-command.ts deleted file mode 100644 index 2d99d0883c6b5e985d21c18902e61db60ccaa6dc..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/download-command.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { BrowserCommand } from "vitest/node"; -import { resolve } from "path"; -import { readFile } from "fs/promises"; - -/** - * Vitest browser command that captures a real file download triggered by - * clicking an element. Runs server-side with access to the Playwright page. - * - * Sets up page.waitForEvent("download") BEFORE clicking, so the download - * event is never missed. - */ -export const expect_download: BrowserCommand< - [selector: string, options?: { timeout?: number }], - { suggested_filename: string; content: string | null } -> = async (context, selector, options) => { - const timeout = options?.timeout ?? 5000; - const provider = context.provider as any; - const page = provider.getPage(context.sessionId); - // Tests run inside an iframe; use the iframe locator to click - // but listen for the download event on the parent page. - const iframe = (context as any).iframe; - - const [download] = await Promise.all([ - page.waitForEvent("download", { timeout }), - iframe.locator(selector).click() - ]); - - const suggested_filename = download.suggestedFilename(); - const path = await download.path(); - - let content: string | null = null; - if (path) { - const fs = await import("fs/promises"); - content = await fs.readFile(path, "utf-8"); - } - - return { - suggested_filename, - content - }; -}; - -/** - * Vitest browser command that sets files on an element. - * Resolves fixture URL paths (e.g. "/test/test_files/bus.png") to absolute - * disk paths and uses Playwright's setInputFiles(). - */ -export const set_file_inputs: BrowserCommand< - [file_urls: string[], selector?: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - const iframe = (context as any).iframe; - - const paths = file_urls.map((url) => resolve(root, url.replace(/^\//, ""))); - - await iframe - .locator(selector ?? 'input[type="file"]') - .first() - .setInputFiles(paths); -}; - -interface Drop_file_spec { - data: string; // base64 - name: string; - mime_type: string; -} - -/** - * Vitest browser command that simulates dropping files onto an element. - * Reads files from disk, transfers them as base64 into the browser context, - * and dispatches dragenter, dragover, and drop events with a real DataTransfer. - */ -export const drop_files: BrowserCommand< - [file_urls: string[], selector: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - - const files: Drop_file_spec[] = await Promise.all( - file_urls.map(async (url) => { - const abs = resolve(root, url.replace(/^\//, "")); - const data = (await readFile(abs)).toString("base64"); - const name = abs.split("/").pop()!; - const ext = name.split(".").pop()!.toLowerCase(); - const mime_type = MIME_TYPES[ext] || "application/octet-stream"; - return { data, name, mime_type }; - }) - ); - - const iframe = (context as any).iframe; - await iframe - .locator(selector) - .first() - .evaluate((target: Element, files: Drop_file_spec[]) => { - const dt = new DataTransfer(); - for (const f of files) { - const bytes = Uint8Array.from(atob(f.data), (c) => c.charCodeAt(0)); - dt.items.add(new File([bytes], f.name, { type: f.mime_type })); - } - - target.dispatchEvent( - new DragEvent("dragenter", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("dragover", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("drop", { dataTransfer: dt, bubbles: true }) - ); - }, files); -}; - -const MIME_TYPES: Record = { - txt: "text/plain", - csv: "text/csv", - json: "application/json", - pdf: "application/pdf", - jpg: "image/jpeg", - jpeg: "image/jpeg", - png: "image/png", - gif: "image/gif", - webp: "image/webp", - svg: "image/svg+xml", - mp4: "video/mp4", - webm: "video/webm", - ogg: "video/ogg", - avi: "video/x-msvideo", - wav: "audio/wav", - mp3: "audio/mpeg", - flac: "audio/flac" -}; diff --git a/6.14.0/tootils/src/download.ts b/6.14.0/tootils/src/download.ts deleted file mode 100644 index c6217fc6695b81fe685bcff9593ed9cab6095a3a..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/download.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { commands } from "vitest/browser"; -import type { FileData } from "@gradio/client"; - -export interface DownloadResult { - suggested_filename: string; - content: string | null; -} - -/** - * Clicks an element and captures the resulting file download. - * - * Uses a real browser download via Playwright under the hood — - * the file is actually downloaded and its content is readable. - * - * @param selector - CSS selector for the element to click - * @param options - Optional timeout (default 5000ms) - * @returns The downloaded file's suggested filename and text content - * - * @example - * ```ts - * const { suggested_filename, content } = await download_file("a.download-link"); - * expect(suggested_filename).toBe("data.csv"); - * expect(content).toContain("col1,col2"); - * ``` - */ -export async function download_file( - selector: string, - options?: { timeout?: number } -): Promise { - return (commands as any).expect_download(selector, options); -} - -/** - * Sets files on an `` element using real file fixtures. - * - * Accepts one or more FileData fixtures (e.g. TEST_JPG, TEST_PNG) and - * sets them on the file input, triggering the browser's native change event. - * - * @param files - One or more FileData fixtures to upload - * @param selector - CSS selector for the file input (default: 'input[type="file"]') - * - * @example - * ```ts - * import { render, upload_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await upload_file(TEST_JPG); - * - * expect(upload).toHaveBeenCalled(); - * ``` - */ -export async function upload_file( - files: FileData | FileData[], - selector?: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).set_file_inputs(urls, selector); -} - -/** - * Simulates dragging and dropping files onto an element. - * - * Reads the fixture files from disk, constructs a real DataTransfer - * with File objects, and dispatches dragenter, dragover, and drop events - * on the target element. - * - * @param files - One or more FileData fixtures to drop - * @param selector - CSS selector for the drop target element - * - * @example - * ```ts - * import { render, drop_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await drop_file(TEST_JPG, "[aria-label='Click to upload or drop files']"); - * - * await vi.waitFor(() => expect(upload).toHaveBeenCalled()); - * ``` - */ -export async function drop_file( - files: FileData | FileData[], - selector: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).drop_files(urls, selector); -} diff --git a/6.14.0/tootils/src/fixtures.ts b/6.14.0/tootils/src/fixtures.ts deleted file mode 100644 index 75d8a6419d3a1da6526c64ba44280844cd54f122..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/fixtures.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { FileData } from "@gradio/client"; - -const BASE = "/test/test_files"; - -function fixture(filename: string, mime_type: string, size: number): FileData { - const url = `${BASE}/${filename}`; - return new FileData({ - path: url, - url, - orig_name: filename, - size, - mime_type - }); -} - -export const TEST_TXT = fixture("alphabet.txt", "text/plain", 26); -export const TEST_JPG = fixture("cheetah1.jpg", "image/jpeg", 20552); -export const TEST_PNG = fixture("bus.png", "image/png", 1951); -export const TEST_MP4 = fixture("video_sample.mp4", "video/mp4", 261179); -export const TEST_WAV = fixture("audio_sample.wav", "audio/wav", 16136); -export const TEST_PDF = fixture("sample_file.pdf", "application/pdf", 10558); -export const TEST_GLTF = fixture("Box.gltf", "model/gltf+json", 5249); -export const TEST_PLY = fixture("model.ply", "application/octet-stream", 413); -export const TEST_SPLAT = fixture( - "model.splat", - "application/octet-stream", - 32 -); diff --git a/6.14.0/tootils/src/index.ts b/6.14.0/tootils/src/index.ts deleted file mode 100644 index a85eba689e1f5600e909023c8c5bb68b68674bce..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/index.ts +++ /dev/null @@ -1,245 +0,0 @@ -import { test as base, type Locator, type Page } from "@playwright/test"; -import { spy } from "tinyspy"; -import url from "url"; -import path from "path"; -import fsPromises from "fs/promises"; -import type { ChildProcess } from "node:child_process"; - -import type { SvelteComponent } from "svelte"; -import type { SpyFn } from "tinyspy"; - -import { launchGradioApp, killGradioApp, hasTestcase } from "./app-launcher"; - -export function get_text(el: T): string { - return el.innerText.trim(); -} - -export function wait(n: number): Promise { - return new Promise((r) => setTimeout(r, n)); -} - -const ROOT_DIR = path.resolve( - url.fileURLToPath(import.meta.url), - "../../../.." -); - -// Extract testcase name from test title if present -// Test titles can be: -// - "case eager_caching_examples: ..." -// - "test case multimodal_messages chatinterface works..." -function extractTestcaseFromTitle( - title: string, - demoName: string -): string | undefined { - // Try pattern: "case :" or "test case " - const patterns = [/^case\s+(\w+):/, /^test case\s+(\w+)\s/]; - - for (const pattern of patterns) { - const match = title.match(pattern); - if (match) { - const caseName = match[1]; - // Check if this is a testcase (not the main demo) - if (hasTestcase(demoName, caseName)) { - return caseName; - } - } - } - return undefined; -} - -// Cache for launched apps - key is "demoName" or "demoName_testcaseName" -const appCache = new Map< - string, - { port: number; process: ChildProcess; refCount: number } ->(); - -// Track the cacheKey of the currently-running spec file so we can kill the -// previous spec's gradio app when the worker moves on. Without this, every -// app spawned during a worker's lifetime stayed resident until process exit -// (~50 python procs / 5GB RSS by end of suite — the tail of the run starved -// for CPU and tests timed out). -let currentCacheKey: string | null = null; - -function killAndEvict(cacheKey: string): void { - const info = appCache.get(cacheKey); - if (!info) return; - killGradioApp(info.process); - appCache.delete(cacheKey); -} - -// Test fixture that launches Gradio app per test -const test_normal = base.extend<{ setup: void }>({ - setup: [ - async ({ page }, use, testInfo): Promise => { - const { file, title } = testInfo; - const demoName = path.basename(file, ".spec.ts"); - - // Check if this is a reload test (they manage their own apps) - if (demoName.endsWith(".reload")) { - // For reload tests, don't launch an app - they handle it themselves - await use(); - return; - } - - // Check if this test is for a specific testcase - const testcaseName = extractTestcaseFromTitle(title, demoName); - - // Cache key includes testcase if present - const cacheKey = testcaseName ? `${demoName}_${testcaseName}` : demoName; - - // First test of a new spec file → previous file's app is no longer - // needed on this worker. fullyParallel=false in playwright.config - // guarantees a worker finishes a file before starting the next, so - // the kill is unconditional on the transition (we don't gate on - // refCount: a throw before `await use()` — e.g. a flaky SSR - // hydration wait — can leak refCount, which would otherwise pin - // the previous spec's app forever). - if (currentCacheKey !== null && currentCacheKey !== cacheKey) { - killAndEvict(currentCacheKey); - } - currentCacheKey = cacheKey; - - let appInfo = appCache.get(cacheKey); - - if (!appInfo) { - // Launch the app for this test - const workerIndex = testInfo.workerIndex; - try { - const { port, process } = await launchGradioApp( - demoName, - workerIndex, - 60000, - testcaseName - ); - appInfo = { port, process, refCount: 0 }; - appCache.set(cacheKey, appInfo); - } catch (error) { - console.error(`Failed to launch app for ${cacheKey}:`, error); - throw error; - } - } - - try { - // Navigate to the app - await page.goto(`http://localhost:${appInfo.port}`); - - if ( - process.env?.GRADIO_SSR_MODE?.toLowerCase() === "true" && - !( - demoName.includes("multipage") || - demoName.includes("chatinterface_deep_link") - ) - ) { - await page.waitForSelector("#svelte-announcer"); - } - await page.waitForLoadState("load"); - - await use(); - } finally { - } - }, - { auto: true } - ] -}); - -// Cleanup apps when the process exits -process.on("exit", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } -}); - -process.on("SIGINT", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -process.on("SIGTERM", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -export const test = test_normal; - -export async function wait_for_event( - component: SvelteComponent, - event: string -): Promise { - const mock = spy(); - return new Promise((res) => { - component.$on(event, () => { - mock(); - res(mock); - }); - }); -} - -export interface ActionReturn< - Parameter = never, - Attributes extends Record = Record -> { - update?: [Parameter] extends [never] ? never : (parameter: Parameter) => void; - destroy?: () => void; - /** - * ### DO NOT USE THIS - * This exists solely for type-checking and has no effect at runtime. - * Set this through the `Attributes` generic instead. - */ - $$_attributes?: Attributes; -} - -export { expect } from "@playwright/test"; - -export const drag_and_drop_file = async ( - page: Page, - selector: string | Locator, - filePath: string, - fileName: string, - fileType = "", - count = 1 -): Promise => { - const buffer = (await fsPromises.readFile(filePath)).toString("base64"); - - const dataTransfer = await page.evaluateHandle( - async ({ bufferData, localFileName, localFileType, count }) => { - const dt = new DataTransfer(); - - const blobData = await fetch(bufferData).then((res) => res.blob()); - - const file = new File([blobData], localFileName, { - type: localFileType - }); - - for (let i = 0; i < count; i++) { - dt.items.add(file); - } - return dt; - }, - { - bufferData: `data:application/octet-stream;base64,${buffer}`, - localFileName: fileName, - localFileType: fileType, - count - } - ); - - if (typeof selector === "string") { - await page.dispatchEvent(selector, "drop", { dataTransfer }); - } else { - await selector.dispatchEvent("drop", { dataTransfer }); - } -}; - -export async function go_to_testcase( - page: Page, - _test_case: string -): Promise { - // With the new setup, each testcase launches its own Gradio app. - // The fixture detects the testcase from the test title and launches - // the correct app, so this function is now a no-op. - // The page is already at the correct testcase app. -} diff --git a/6.14.0/tootils/src/render.ts b/6.14.0/tootils/src/render.ts deleted file mode 100644 index 292a39deb9ce1a30c73623e6d4e6e4e697ae2c01..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/render.ts +++ /dev/null @@ -1,317 +0,0 @@ -import { - getQueriesForElement, - prettyDOM, - fireEvent as dtlFireEvent -} from "@testing-library/dom"; -import { tick, mount, unmount } from "svelte"; -import type { SvelteComponent, Component } from "svelte"; - -import type { - queries, - Queries, - BoundFunction, - EventType -} from "@testing-library/dom"; -import { vi, type Mock } from "vitest"; -import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils"; -import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker"; -import { _ } from "svelte-i18n"; - -const containerCache = new Map(); -const componentCache = new Set(); - -type ComponentType = Component; - -export type RenderResult< - C extends SvelteComponent, - Q extends Queries = typeof queries -> = { - container: HTMLElement; - component: C; - debug: (el?: HTMLElement | DocumentFragment) => void; - unmount: () => void; -} & { [P in keyof Q]: BoundFunction }; -export interface ILoadingStatus { - eta: number | null; - status: "pending" | "error" | "complete" | "generating" | "streaming"; - queue: boolean; - queue_position: number | null; - queue_size?: number; - fn_index: number; - message?: string | null; - scroll_to_output?: boolean; - show_progress?: "full" | "minimal" | "hidden"; - time_limit?: number | null | undefined; - progress?: { - progress: number | null; - index: number | null; - length: number | null; - unit: string | null; - desc: string | null; - }[]; - validation_error?: string | null; - type: "input" | "output"; - stream_state: "open" | "closed" | "waiting" | null; -} - -const loading_status: ILoadingStatus = { - eta: 0, - queue_position: 1, - queue_size: 1, - queue: true, - message: null, - time_limit: null, - progress: [], - validation_error: null, - type: "output", - stream_state: null, - status: "complete" as ILoadingStatus["status"], - scroll_to_output: false, - fn_index: 0, - show_progress: "full" as ILoadingStatus["show_progress"] -}; - -export interface RenderOptions { - container?: HTMLElement; - queries?: Q; -} - -export async function render< - Events extends Record, - Props extends Record, - T extends SvelteComponent, - X extends Record ->( - Component: ComponentType | { default: ComponentType }, - props?: Omit & { - loading_status?: LoadingStatus; - }, - options?: { - container?: HTMLElement; - } -): Promise< - RenderResult & { - listen: (event_name: string, opts?: { retrospective?: boolean }) => Mock; - set_data: (data: Record) => Promise; - get_data: () => Promise>; - } -> { - let container: HTMLElement; - if (!options?.container) { - container = document.body; - } else { - container = options.container; - } - - const target = container.appendChild(document.createElement("div")); - - const ComponentConstructor: ComponentType = - //@ts-ignore - Component.default || Component; - - const id = Math.floor(Math.random() * 1000000); - - let component_set_data: (data: Record) => void; - let component_get_data: () => Promise>; - - const mock_register = ( - _id: number, - set_data: (data: Record) => void, - get_data: () => Promise> - ): void => { - component_set_data = set_data; - component_get_data = get_data; - }; - - const event_listeners = new Map void>>(); - const event_buffer: Array<{ event: string; data: any }> = []; - - function notify_listeners(event: string, data: any): void { - const listeners = event_listeners.get(event); - if (listeners) { - for (const listener of listeners) { - listener(data); - } - } - } - - const dispatcher = (_id: number, event: string, data: any): void => { - event_buffer.push({ event, data }); - notify_listeners(event, data); - }; - - function listen( - event_name: string, - opts?: { retrospective?: boolean } - ): Mock { - const fn = vi.fn(); - if (!event_listeners.has(event_name)) { - event_listeners.set(event_name, new Set()); - } - event_listeners.get(event_name)!.add(fn); - - if (opts?.retrospective) { - for (const entry of event_buffer) { - if (entry.event === event_name) { - fn(entry.data); - } - } - } - - return fn; - } - - const i18nFormatter = (s: string | null | undefined): string => s ?? ""; - - const shared_props_obj: Record = { - id, - target, - theme_mode: "light" as const, - version: "2.0.0", - formatter: i18nFormatter, - client: {} as any, - load_component: () => Promise.resolve({ default: {} as any }), - show_progress: true, - api_prefix: "", - server: {} as any, - show_label: true, - register_component: mock_register, - dispatcher - }; - - const component_props_obj: Record = { - i18n: i18nFormatter - }; - - if (props) { - for (const key in props) { - const value = (props as any)[key]; - if (allowed_shared_props.includes(key as any)) { - shared_props_obj[key] = value; - } else { - component_props_obj[key] = value; - } - } - } - - shared_props_obj.loading_status = props?.loading_status - ? props.loading_status - : loading_status; - - const componentProps = { - shared_props: shared_props_obj, - props: { - ...component_props_obj - }, - ...shared_props_obj - }; - - const component = mount(ComponentConstructor, { - target, - props: componentProps - }) as T; - - containerCache.set(container, { target, component }); - componentCache.add(component); - - await tick(); - - return { - container, - component, - listen, - set_data: async (data: Record) => { - const r = component_set_data(data); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return r; - }, - get_data: () => component_get_data(), - //@ts-ignore - debug: (el = container): void => console.warn(prettyDOM(el)), - unmount: (): void => { - if (componentCache.has(component)) { - unmount(component); - } - }, - ...getQueriesForElement(container) - }; -} - -const cleanupAtContainer = (container: HTMLElement): void => { - const { target, component } = containerCache.get(container); - - if (componentCache.has(component)) { - unmount(component); - } - - if (target.parentNode === document.body) { - document.body.removeChild(target); - } - - containerCache.delete(container); -}; - -export function cleanup(): void { - Array.from(containerCache.keys()).forEach(cleanupAtContainer); - document.body.innerHTML = ""; -} - -type AsyncFireObject = { - [K in EventType]: ( - element: Document | Element | Window | Node, - options?: object - ) => Promise; -}; - -export const fireEvent = Object.keys(dtlFireEvent).reduce((acc, key) => { - const _key = key as EventType; - return { - ...acc, - [_key]: async ( - element: Document | Element | Window, - options: object = {} - ): Promise => { - const event = dtlFireEvent[_key](element, options); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return event; - } - }; -}, {} as AsyncFireObject); - -export type FireFunction = ( - element: Document | Element | Window, - event: Event -) => Promise; - -export { download_file, upload_file, drop_file } from "./download.js"; - -/** - * Creates a mock client suitable for components that use file uploads. - * The upload mock echoes back the input FileData unchanged. - */ -export function mock_client(): Record { - return { - upload: async (file_data: any[]) => file_data, - stream: async () => ({ onmessage: null, close: () => {} }) - }; -} -export { - TEST_TXT, - TEST_JPG, - TEST_PNG, - TEST_MP4, - TEST_WAV, - TEST_PDF, - TEST_GLTF, - TEST_PLY, - TEST_SPLAT -} from "./fixtures.js"; -export * from "@testing-library/dom"; diff --git a/6.14.0/tootils/src/shared-prop-tests.ts b/6.14.0/tootils/src/shared-prop-tests.ts deleted file mode 100644 index b8f58e68a13e368fd4a1f1d6f2e246260b82bcd0..0000000000000000000000000000000000000000 --- a/6.14.0/tootils/src/shared-prop-tests.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, test, expect, afterEach } from "vitest"; -import { render, cleanup } from "./render"; - -const loading_status = { - status: "complete", - queue_position: null, - queue_size: null, - eta: null, - message: null -}; - -export interface SharedPropTestConfig { - /** The Svelte component to test */ - component: any; - /** Minimum props required to render the component without errors */ - base_props: Record; - /** Display name for test output */ - name: string; - /** - * Some components don't render labels (e.g. HTML, Markdown). - * Set to false to skip label-related tests. - * @default true - */ - has_label?: boolean; - /** - * Whether the component renders validation_error text. - * Not all components support this. Set to false to skip. - * @default true - */ - has_validation_error?: boolean; - /** - * Some components (e.g. Accordion) map visible=false to "hidden" - * instead of removing from the DOM. Set to true to expect hidden - * behaviour rather than removal. - * @default false - */ - visible_false_hides?: boolean; - /** - * Whether the component is wrapped in a Block (which renders a `.block` - * element). Components like Button render a bare element instead. - * Set to false to skip `.block` selector checks. - * @default true - */ - has_block_wrapper?: boolean; -} - -export function run_shared_prop_tests(config: SharedPropTestConfig): void { - const { - component, - base_props, - name, - has_label = true, - has_validation_error = true, - visible_false_hides = false, - has_block_wrapper = true - } = config; - - const label = "Test Label"; - - function make_props( - overrides: Record = {} - ): Record { - return { - ...base_props, - loading_status: { ...loading_status, ...overrides }, - label, - ...overrides - }; - } - - describe(`${name}: shared props`, () => { - afterEach(() => cleanup()); - - test("elem_id is applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_id: "my-test-id" }) - ); - const el = container.querySelector("#my-test-id"); - expect(el).not.toBeNull(); - }); - - test("elem_classes are applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_classes: ["my-test-class"] }) - ); - const el = container.querySelector(".my-test-class"); - expect(el).not.toBeNull(); - }); - - test("visible: true renders the component", async () => { - const { container } = await render( - component, - make_props({ visible: true, elem_id: "visible-test" }) - ); - const el = has_block_wrapper - ? container.querySelector(".block") - : container.querySelector("#visible-test"); - expect(el).not.toBeNull(); - }); - - test("visible: 'hidden' hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: "hidden", elem_id: "hidden-test" }) - ); - - const el = result.container.querySelector("#hidden-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - - if (visible_false_hides) { - test("visible: false hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - } else { - test("visible: false removes the component from the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).toBeNull(); - }); - } - - if (has_label) { - test("label text is rendered", async () => { - const result = await render( - component, - make_props({ label: "My Custom Label", show_label: true }) - ); - const el = result.getByText("My Custom Label"); - expect(el).toBeTruthy(); - }); - - test("show_label: true makes the label visible", async () => { - const result = await render( - component, - make_props({ label: "Visible Label", show_label: true }) - ); - const el = result.getByText("Visible Label"); - expect(el).toBeVisible(); - }); - - test("show_label: false hides the label visually but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ label: "Hidden Label", show_label: false }) - ); - const el = result.getByText("Hidden Label"); - // The label remains in the DOM for screen readers via sr-only. - // sr-only uses clip/1px dimensions rather than display:none, - // so toBeVisible() won't catch it. We check the class directly. - expect(el.closest("[data-testid='block-info']")).toHaveClass("sr-only"); - }); - } - - if (has_validation_error) { - test("validation_error displays error text visibly", async () => { - const result = await render( - component, - make_props({ - validation_error: "This field is required", - show_validation_error: true - }) - ); - const el = result.getByText("This field is required"); - expect(el).toBeVisible(); - }); - } - }); -} diff --git a/6.14.0/upload/package.json b/6.14.0/upload/package.json deleted file mode 100644 index e69e58a5663f9425f287d6f4133191513f431980..0000000000000000000000000000000000000000 --- a/6.14.0/upload/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@gradio/upload", - "version": "0.17.9", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/upload" - } -} diff --git a/6.14.0/upload/src/ModifyUpload.svelte b/6.14.0/upload/src/ModifyUpload.svelte deleted file mode 100644 index 7c8db47405576b3b590d9bcb394d5e5848f7e240..0000000000000000000000000000000000000000 --- a/6.14.0/upload/src/ModifyUpload.svelte +++ /dev/null @@ -1,61 +0,0 @@ - - - - {#if editable} - onedit?.()} - /> - {/if} - - {#if undoable} - onundo?.()} - /> - {/if} - - {#if download} - - - - {/if} - - {#if children}{@render children()}{/if} - - { - onclear?.(); - event.stopPropagation(); - }} - /> - diff --git a/6.14.0/upload/src/Upload.svelte b/6.14.0/upload/src/Upload.svelte deleted file mode 100644 index 27183d59b8604ce79d9e90d44269ffb32bdb7225..0000000000000000000000000000000000000000 --- a/6.14.0/upload/src/Upload.svelte +++ /dev/null @@ -1,398 +0,0 @@ - - -{#if filetype === "clipboard"} - -{:else if uploading && show_progress} - {#if !hidden} - - {/if} -{:else} - -{/if} - - diff --git a/6.14.0/upload/src/UploadProgress.svelte b/6.14.0/upload/src/UploadProgress.svelte deleted file mode 100644 index 0ee9995f6d036d79048aca2705d530d3453ae7a1..0000000000000000000000000000000000000000 --- a/6.14.0/upload/src/UploadProgress.svelte +++ /dev/null @@ -1,199 +0,0 @@ - - -
- Uploading {files_with_progress.length} - {files_with_progress.length > 1 ? "files" : "file"}... - - {#if file_to_display} -
- -
- {getProgress(file_to_display)} -
-
- - {file_to_display.orig_name} - -
- {/if} -
- - diff --git a/6.14.0/upload/src/index.ts b/6.14.0/upload/src/index.ts deleted file mode 100644 index 0c2bdb5d7b2eb9c39953af027ae57cc674a0e377..0000000000000000000000000000000000000000 --- a/6.14.0/upload/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Upload } from "./Upload.svelte"; -export { default as ModifyUpload } from "./ModifyUpload.svelte"; -export { default as UploadProgress } from "./UploadProgress.svelte"; -export { create_drag } from "./utils"; diff --git a/6.14.0/upload/src/utils.ts b/6.14.0/upload/src/utils.ts deleted file mode 100644 index e961b85f75d154896c4be1656ed4e383bae0305b..0000000000000000000000000000000000000000 --- a/6.14.0/upload/src/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -interface DragActionOptions { - disable_click?: boolean; - accepted_types?: string | string[] | null; - mode?: "single" | "multiple" | "directory"; - on_drag_change?: (dragging: boolean) => void; - on_files?: (files: File[]) => void; -} - -type ActionReturn = { - update: (new_options: DragActionOptions) => void; - destroy: () => void; -}; - -export function create_drag(): { - drag: (node: HTMLElement, options: DragActionOptions) => ActionReturn; - open_file_upload: () => void; -} { - let hidden_input: HTMLInputElement; - let _options: DragActionOptions; - return { - drag( - node: HTMLElement, - options: DragActionOptions = {} - ): { - update: (new_options: DragActionOptions) => void; - destroy: () => void; - } { - _options = options; - - // Create and configure hidden file input - function setup_hidden_input(): void { - hidden_input = document.createElement("input"); - hidden_input.type = "file"; - hidden_input.style.display = "none"; - hidden_input.setAttribute("aria-label", "File upload"); - hidden_input.setAttribute("data-testid", "file-upload"); - const accept_options = Array.isArray(_options.accepted_types) - ? _options.accepted_types.join(",") - : _options.accepted_types || undefined; - - if (accept_options) { - hidden_input.accept = accept_options; - } - - hidden_input.multiple = _options.mode === "multiple" || false; - if (_options.mode === "directory") { - hidden_input.webkitdirectory = true; - hidden_input.setAttribute("directory", ""); - hidden_input.setAttribute("mozdirectory", ""); - } - node.appendChild(hidden_input); - } - - setup_hidden_input(); - - function handle_drag(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - } - - function handle_drag_enter(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(true); - } - - function handle_drag_leave(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - } - - function handle_drop(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - - if (!e.dataTransfer?.files) return; - const files = Array.from(e.dataTransfer.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - - function handle_click(): void { - if (!_options.disable_click) { - hidden_input.value = ""; - hidden_input.click(); - } - } - - function handle_file_input_change(): void { - if (hidden_input.files) { - const files = Array.from(hidden_input.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - } - - // Add all event listeners - node.addEventListener("drag", handle_drag); - node.addEventListener("dragstart", handle_drag); - node.addEventListener("dragend", handle_drag); - node.addEventListener("dragover", handle_drag); - node.addEventListener("dragenter", handle_drag_enter); - node.addEventListener("dragleave", handle_drag_leave); - node.addEventListener("drop", handle_drop); - node.addEventListener("click", handle_click); - hidden_input!.addEventListener("change", handle_file_input_change); - - return { - update(new_options: DragActionOptions) { - _options = new_options; - // Recreate hidden input with new options - hidden_input.remove(); - setup_hidden_input(); - hidden_input.addEventListener("change", handle_file_input_change); - }, - destroy() { - node.removeEventListener("drag", handle_drag); - node.removeEventListener("dragstart", handle_drag); - node.removeEventListener("dragend", handle_drag); - node.removeEventListener("dragover", handle_drag); - node.removeEventListener("dragenter", handle_drag_enter); - node.removeEventListener("dragleave", handle_drag_leave); - node.removeEventListener("drop", handle_drop); - node.removeEventListener("click", handle_click); - hidden_input.removeEventListener("change", handle_file_input_change); - hidden_input.remove(); - } - }; - }, - open_file_upload(): void { - if (hidden_input) { - hidden_input.value = ""; - hidden_input.click(); - } - } - }; -} diff --git a/6.14.0/uploadbutton/Index.svelte b/6.14.0/uploadbutton/Index.svelte deleted file mode 100644 index f246c8f96ea948a81cd7bcd7a2412b089ebbaea1..0000000000000000000000000000000000000000 --- a/6.14.0/uploadbutton/Index.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - gradio.dispatch("click")} - onchange={(detail) => handle_event(detail, "change")} - onupload={(detail) => handle_event(detail, "upload")} - onerror={(detail) => { - gradio.dispatch("error", detail); - }} - upload={(...args) => gradio.shared.client.upload(...args)} -> - {gradio.shared.label ?? ""} - diff --git a/6.14.0/uploadbutton/package.json b/6.14.0/uploadbutton/package.json deleted file mode 100644 index 657726b0534b1c5731cdf917e9d630aa45093a12..0000000000000000000000000000000000000000 --- a/6.14.0/uploadbutton/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@gradio/uploadbutton", - "version": "0.9.18", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "main": "./Index.svelte", - "dependencies": { - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/uploadbutton" - } -} diff --git a/6.14.0/uploadbutton/shared/UploadButton.svelte b/6.14.0/uploadbutton/shared/UploadButton.svelte deleted file mode 100644 index 3cb3b534036b7d1fa652fddd293a00c4f5687e03..0000000000000000000000000000000000000000 --- a/6.14.0/uploadbutton/shared/UploadButton.svelte +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - {#if icon} - {`${value} - {/if} - {#if children}{@render children()}{/if} - - - diff --git a/6.14.0/uploadbutton/types.ts b/6.14.0/uploadbutton/types.ts deleted file mode 100644 index 100547b8f9293f9cd2a191b09a6003e7f071a585..0000000000000000000000000000000000000000 --- a/6.14.0/uploadbutton/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface UploadButtonProps { - value: null | FileData | FileData[]; - file_count: string; - file_types: string[]; - size: "sm" | "lg"; - icon: FileData | null; - variant: "primary" | "secondary" | "stop"; -} - -export interface UploadButtonEvents { - change: never; - upload: never; - click: never; - error: string; -} diff --git a/6.14.0/utils/package.json b/6.14.0/utils/package.json deleted file mode 100644 index 97e34911592ce8b15a54ea071d740237220295dc..0000000000000000000000000000000000000000 --- a/6.14.0/utils/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@gradio/utils", - "version": "0.12.2", - "description": "Gradio UI packages", - "type": "module", - "main": "./src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/theme": "workspace:^", - "svelte-i18n": "^4.0.1" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/utils" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.14.0/utils/src/color.ts b/6.14.0/utils/src/color.ts deleted file mode 100644 index 86d3fe6a5c35c450cc6517b5f3d4767ffda1bc2c..0000000000000000000000000000000000000000 --- a/6.14.0/utils/src/color.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { colors, ordered_colors } from "@gradio/theme"; - -export const get_next_color = (index: number): keyof typeof colors => { - return ordered_colors[index % ordered_colors.length]; -}; diff --git a/6.14.0/utils/src/index.ts b/6.14.0/utils/src/index.ts deleted file mode 100644 index 8db07c80fcf3416332b4ec11d86c06a0fdfb7e74..0000000000000000000000000000000000000000 --- a/6.14.0/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./color.js"; -export * from "./utils.svelte.js"; -export * from "./types.js"; diff --git a/6.14.0/utils/src/types.ts b/6.14.0/utils/src/types.ts deleted file mode 100644 index 8dd47a49c34d6da4ce4328aa99f9fe563ecc7d89..0000000000000000000000000000000000000000 --- a/6.14.0/utils/src/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface CustomButton { - id: number; - value: string | null; - icon: FileData | null; -} diff --git a/6.14.0/utils/src/utils.svelte.ts b/6.14.0/utils/src/utils.svelte.ts deleted file mode 100644 index 1a7d54a3cfac850fd1dedcf10907105b157ade26..0000000000000000000000000000000000000000 --- a/6.14.0/utils/src/utils.svelte.ts +++ /dev/null @@ -1,575 +0,0 @@ -import type { ActionReturn } from "svelte/action"; -import type { Client } from "@gradio/client"; -import type { ComponentType, SvelteComponent } from "svelte"; -import { tick, untrack } from "svelte"; -import type { Component } from "svelte"; -import { locale } from "svelte-i18n"; - -export const I18N_MARKER = "__i18n__"; -const TRANSLATABLE_PROPS = [ - "label", - "info", - "placeholder", - "description", - "title", - "value" -]; - -export interface SharedProps { - elem_id?: string; - elem_classes: string[]; - components?: string[]; - server_fns?: string[]; - interactive: boolean; - visible: boolean | "hidden"; - id: number; - container: boolean; - target: HTMLElement; - theme_mode: "light" | "dark" | "system"; - version: string; - root: string; - autoscroll: boolean; - max_file_size: number | null; - formatter: any; //I18nFormatter; - client: Client; - scale: number; - min_width: number; - padding: number; - load_component: load_component; - loading_status?: any; - label: string; - show_label: boolean; - validation_error?: string | null; - theme?: "light" | "dark"; - show_progress: boolean; - api_prefix: string; - server: ServerFunctions; - attached_events?: string[]; - register_component: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - dispatcher: Function; -} - -export type LoadingComponent = Promise<{ - default: Component; -}>; - -export const GRADIO_ROOT = "GRADIO_ROOT"; - -export interface ValueData { - value: any; - is_value_data: boolean; -} - -export interface SelectData { - row_value?: any[]; - col_value?: any[]; - index: number | [number, number]; - value: any; - selected?: boolean; -} - -export interface LikeData { - index: number | [number, number]; - value: any; - liked?: boolean | string; -} - -export interface KeyUpData { - key: string; - input_value: string; -} - -export interface ShareData { - description: string; - title?: string; -} - -export interface CopyData { - value: string; -} - -export class ShareError extends Error { - constructor(message: string) { - super(message); - this.name = "ShareError"; - } -} - -export async function uploadToHuggingFace( - data: string | { url?: string; path?: string }, - type: "base64" | "url" -): Promise { - if (window.__gradio_space__ == null) { - throw new ShareError("Must be on Spaces to share."); - } - let blob: Blob; - let contentType: string; - let filename: string; - if (type === "url") { - let url: string; - - if (typeof data === "object" && data.url) { - url = data.url; - } else if (typeof data === "string") { - url = data; - } else { - throw new Error("Invalid data format for URL type"); - } - - const response = await fetch(url); - blob = await response.blob(); - contentType = response.headers.get("content-type") || ""; - filename = response.headers.get("content-disposition") || ""; - } else { - let dataurl: string; - - if (typeof data === "object" && data.path) { - dataurl = data.path; - } else if (typeof data === "string") { - dataurl = data; - } else { - throw new Error("Invalid data format for base64 type"); - } - - blob = dataURLtoBlob(dataurl); - contentType = dataurl.split(";")[0].split(":")[1]; - filename = "file." + contentType.split("/")[1]; - } - - const file = new File([blob], filename, { type: contentType }); - - // Send file to endpoint - const uploadResponse = await fetch("https://huggingface.co/uploads", { - method: "POST", - body: file, - headers: { - "Content-Type": file.type, - "X-Requested-With": "XMLHttpRequest" - } - }); - - // Check status of response - if (!uploadResponse.ok) { - if ( - uploadResponse.headers.get("content-type")?.includes("application/json") - ) { - const error = await uploadResponse.json(); - throw new ShareError(`Upload failed: ${error.error}`); - } - throw new ShareError(`Upload failed.`); - } - - // Return response if needed - const result = await uploadResponse.text(); - return result; -} - -function dataURLtoBlob(dataurl: string): Blob { - var arr = dataurl.split(","), - mime = (arr[0].match(/:(.*?);/) as RegExpMatchArray)[1], - bstr = atob(arr[1]), - n = bstr.length, - u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} - -export function copy(node: HTMLDivElement): ActionReturn { - node.addEventListener("click", handle_copy); - - async function handle_copy(event: MouseEvent): Promise { - const path = event.composedPath() as HTMLButtonElement[]; - - const [copy_button] = path.filter( - (e) => e?.tagName === "BUTTON" && e.classList.contains("copy_code_button") - ); - - if (copy_button) { - event.stopImmediatePropagation(); - - const copy_text = copy_button.parentElement!.innerText.trim(); - const copy_sucess_button = Array.from( - copy_button.children - )[1] as HTMLDivElement; - - const copied = await copy_to_clipboard(copy_text); - - if (copied) copy_feedback(copy_sucess_button); - - function copy_feedback(_copy_sucess_button: HTMLDivElement): void { - _copy_sucess_button.style.opacity = "1"; - setTimeout(() => { - _copy_sucess_button.style.opacity = "0"; - }, 2000); - } - } - } - - return { - destroy(): void { - node.removeEventListener("click", handle_copy); - } - }; -} - -async function copy_to_clipboard(value: string): Promise { - let copied = false; - if ("clipboard" in navigator) { - await navigator.clipboard.writeText(value); - copied = true; - } else { - const textArea = document.createElement("textarea"); - textArea.value = value; - - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - copied = true; - } catch (error) { - console.error(error); - copied = false; - } finally { - textArea.remove(); - } - } - - return copied; -} - -export const format_time = (seconds: number): string => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const seconds_remainder = Math.round(seconds) % 60; - const padded_minutes = `${minutes < 10 ? "0" : ""}${minutes}`; - const padded_seconds = `${ - seconds_remainder < 10 ? "0" : "" - }${seconds_remainder}`; - - if (hours > 0) { - return `${hours}:${padded_minutes}:${padded_seconds}`; - } - return `${minutes}:${padded_seconds}`; -}; - -interface Args { - api_url: string; - name: string; - id?: string; - variant: "component" | "example" | "base"; -} - -export type component_loader = (args: Args) => { - component: { - default: ComponentType; - }; -}; - -export type LoadedComponentWithRuntime = { - component: LoadingComponent; - runtime: false | typeof import("svelte"); -}; - -export type load_component = ( - name: string, - variant: "component" | "example" | "base", - component_class_id?: string -) => LoadedComponentWithRuntime; - -const is_browser = typeof window !== "undefined"; - -export type ServerFunctions = Record Promise>; - -export const allowed_shared_props: (keyof SharedProps)[] = [ - "elem_id", - "elem_classes", - "visible", - "interactive", - "server_fns", - "server", - "id", - "target", - "theme_mode", - "version", - "root", - "autoscroll", - "max_file_size", - "formatter", - "client", - "load_component", - "scale", - "min_width", - "theme", - "padding", - "loading_status", - "label", - "show_label", - "validation_error", - "show_progress", - "api_prefix", - "container", - "attached_events", - "register_component", - "dispatcher" -] as const; - -export type I18nFormatter = any; - -export function has_i18n_marker(value: unknown): value is string { - return typeof value === "string" && value.includes(I18N_MARKER); -} - -export function translate_i18n_marker( - value: string, - translate: (key: string) => string -): string { - const start = value.indexOf(I18N_MARKER); - if (start === -1) return value; - - const json_start = start + I18N_MARKER.length; - const json_end = value.indexOf("}", json_start) + 1; - if (json_end === 0) return value; - - try { - const metadata = JSON.parse(value.slice(json_start, json_end)); - if (metadata?.key) { - const translated = translate(metadata.key); - const result = translated !== metadata.key ? translated : metadata.key; - return value.slice(0, start) + result + value.slice(json_end); - } - } catch {} - - return value; -} - -export class Gradio { - load_component: load_component; - shared: SharedProps = $state({} as SharedProps) as SharedProps; - props = $state({} as U) as U; - i18n: I18nFormatter = $state((v: string) => v) as any; - translatable_props: Record = {}; - dispatcher!: Function; - last_update: ReturnType | null = null; - shared_props: (keyof SharedProps)[] = allowed_shared_props; - mounted: boolean = false; - old_value: any; - register_component!: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - - constructor( - _props: { shared_props: SharedProps; props: U }, - default_values?: Partial - ) { - for (const key in _props.shared_props) { - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - - if (default_values) { - for (const key in default_values) { - if (this.props[key as keyof U] === undefined) { - // @ts-ignore - this.props[key] = default_values[key as keyof U]; - } - } - } - // @ts-ignore same here - this.i18n = this.props.i18n ?? ((v: string) => v); - - for (const key of TRANSLATABLE_PROPS) { - // @ts-ignore - this.shared[key] = this._translate_and_store( - "shared", - key, - // @ts-ignore - _props.shared_props[key] - ); - // @ts-ignore - this.props[key] = this._translate_and_store( - "props", - key, - // @ts-ignore - _props.props[key] - ); - } - - this.load_component = this.shared.load_component; - - this.register_component = this.shared.register_component || (() => {}); - this.dispatcher = this.shared.dispatcher || (() => {}); - - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - - $effect(() => { - // Need to update the props here - // otherwise UI won't reflect latest state from render - for (const key in _props.shared_props) { - // @ts-ignore - if (this._is_i18n_managed(`shared.${key}`, _props.shared_props[key])) - continue; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - if (this._is_i18n_managed(`props.${key}`, _props.props[key])) continue; - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - untrack(() => { - this.shared.id = _props.shared_props.id; - }); - }); - - // retranslate props when locale changes - if (Object.keys(this.translatable_props).length > 0) { - locale.subscribe(() => { - for (const [full_key, original] of Object.entries( - this.translatable_props - )) { - const [target, key] = full_key.split("."); - const translated = this.i18n(original); - // @ts-ignore - if (target === "shared") this.shared[key] = translated; - // @ts-ignore - else this.props[key] = translated; - } - }); - } - } - - // check if props are translatable - _is_i18n_managed(key: string, new_value: unknown): boolean { - const original_marker = this.translatable_props[key]; - if (!original_marker) return false; - if (new_value === original_marker) return true; - // if value has changed then remove key - delete this.translatable_props[key]; - return false; - } - - _translate_and_store( - target: "shared" | "props", - key: string, - value: unknown - ): unknown { - if (typeof value !== "string") return value; - const translated = this.i18n(value); - if (translated !== value) { - this.translatable_props[`${target}.${key}`] = value; - } - return translated; - } - - dispatch(event_name: E, data?: T[E]): void { - this.dispatcher(this.shared.id, event_name, data); - } - - async get_data() { - return $state.snapshot(this.props); - } - - update(data: Partial): void { - this.set_data(data as U & SharedProps); - } - - set_data(data: Partial): void { - for (const key in data) { - // @ts-ignore - const value = data[key]; - const translated = has_i18n_marker(value) - ? this._translate_and_store( - this.shared_props.includes(key as keyof SharedProps) - ? "shared" - : "props", - key, - value - ) - : value; - - if (this.shared_props.includes(key as keyof SharedProps)) { - const _key = key as keyof SharedProps; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[_key] = translated; - continue; - } - // @ts-ignore - this.props[key] = translated; - } - } - - watch_for_change() { - $effect(() => { - if (!this.mounted) { - // @ts-ignore - this.old_value = this.props.value; - this.mounted = true; - } - // @ts-ignore - if (this.old_value != this.props.value) { - // @ts-ignore - this.old_value = this.props.value; - // @ts-ignore - this.dispatch("change"); - } - }); - } -} - -// function _load_component( -// this: Gradio, -// name: string, -// variant: "component" | "example" | "base" = "component" -// ): ReturnType { -// return this._load_component!({ -// name, -// api_url: this.shared.client.config?.root!, -// variant -// }); -// } - -export const css_units = (dimension_value: string | number): string => { - return typeof dimension_value === "number" - ? dimension_value + "px" - : dimension_value; -}; - -export function should_show_scroll_fade( - container: HTMLElement | null -): boolean { - if (!container) return false; - const has_overflow = container.scrollHeight > container.clientHeight; - const at_bottom = - container.scrollTop >= container.scrollHeight - container.clientHeight - 1; - return has_overflow && !at_bottom; -} - -type MappedProps = { [K in keyof T]: T[K] }; -type MappedProp = { [P in K]: T[P] }; diff --git a/6.14.0/vibeeditor/Index.svelte b/6.14.0/vibeeditor/Index.svelte deleted file mode 100644 index 6db9b3cb7167948ae0f14cabd9d66c791deb9e2d..0000000000000000000000000000000000000000 --- a/6.14.0/vibeeditor/Index.svelte +++ /dev/null @@ -1,764 +0,0 @@ - - -
- -
- - -
- -
- {#if activeTab === "chat"} -
- {#each message_history as message, index} -
-
- - - - {#if !message.isBot && message.hash && !message.isPending} - - {/if} -
-
- {/each} - - {#if message_history.length === 0} -
No messages yet
- {/if} - - {#if message_history.length === 0} -
-
- {#each starterQueries as query} - - {/each} -
-
- {/if} -
- {:else if activeTab === "code"} -
-
- -
- - -
- {/if} -
- -
-
Powered by: gpt-oss
- - {#if showTagMenu && currentLineIndex === i} -
- [s, i])} - filtered_indices={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )} - active_index={filtered_tags.map((s) => - gradio.props.tags.indexOf(s) - )[selectedOptionIndex]} - show_options={true} - onchange={(e) => insert_tag(e)} - {offset_from_top} - from_top={true} - /> -
- {/if} -
-
- {#if gradio.props.max_lines == undefined || (gradio.props.max_lines && i < gradio.props.max_lines - 1)} -
- -
- {/if} -
- -
- - {/each} - - {:else if checked || gradio.props.ui_mode !== "dialogue"} -
- {#if is_formatting} -
-
-
Converting to plain text...
-
- {/if} - - {/if} - {#if submit_btn} - - {/if} - {#if stop_btn} - - {/if} -
- - - diff --git a/6.14.1/textbox/types.ts b/6.14.1/textbox/types.ts deleted file mode 100644 index 8ec1cfc945755962a887be7207b0f60290ad929a..0000000000000000000000000000000000000000 --- a/6.14.1/textbox/types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type SelectData, - type CopyData, - type CustomButton -} from "@gradio/utils"; -import type { LoadingStatus } from "@gradio/statustracker"; - -export interface TextboxEvents { - change: string; - submit: never; - blur: never; - select: SelectData; - input: never; - focus: never; - stop: never; - clear_status: LoadingStatus; - copy: CopyData; - custom_button_click: { id: number }; -} - -export interface TextboxProps { - value: string; - info: string; - lines: number; - type: "text" | "password" | "email" | undefined; - rtl: boolean; - text_align: "right" | "left"; - max_lines: number; - placeholder: string; - submit_btn: string; - stop_btn: string; - buttons: (string | CustomButton)[] | null; - autofocus: boolean; - autoscroll: boolean; - max_length: number; - html_attributes: InputHTMLAttributes; - validation_error: string | null; -} - -type FullAutoFill = - | AutoFill - | "bday" - | `${OptionalPrefixToken}${"cc-additional-name"}` - | "nickname" - | "language" - | "organization-title" - | "photo" - | "sex" - | "url"; - -export interface InputHTMLAttributes { - autocapitalize?: - | "off" - | "none" - | "on" - | "sentences" - | "words" - | "characters" - | null; - autocorrect?: "on" | "off" | null; - spellcheck?: boolean | null; - autocomplete?: FullAutoFill | undefined | null; - tabindex?: number | null; - enterkeyhint?: - | "enter" - | "done" - | "go" - | "next" - | "previous" - | "search" - | "send" - | null; - lang?: string | null; -} diff --git a/6.14.1/theme/package.json b/6.14.1/theme/package.json deleted file mode 100644 index bb4343fa73bdf0fe073c0d611292babaf9cc8d6b..0000000000000000000000000000000000000000 --- a/6.14.1/theme/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@gradio/theme", - "version": "0.6.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": false, - "scripts": { - "generate": "pollen -c src/pollen.config.mjs", - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./reset.css": { - "gradio": "./src/reset.css", - "import": "./dist/src/reset.css" - }, - "./global.css": { - "gradio": "./src/global.css", - "import": "./dist/src/global.css" - }, - "./tokens": { - "gradio": "./src/tokens.ts", - "import": "./dist/src/tokens.js" - }, - "./typography.css": { - "gradio": "./src/typography.css", - "import": "./dist/src/typography.css" - }, - "./gradio-style.scss": { - "gradio": "./src/gradio-style.scss", - "import": "./dist/src/gradio-style.scss" - }, - "./pollen.css": { - "gradio": "./src/pollen.css", - "import": "./dist/src/pollen.css" - }, - "./package.json": "./package.json" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/theme" - } -} diff --git a/6.14.1/theme/src/colors.ts b/6.14.1/theme/src/colors.ts deleted file mode 100644 index 04a9c9b33c631635832a8fb982ce1d29e0176fa7..0000000000000000000000000000000000000000 --- a/6.14.1/theme/src/colors.ts +++ /dev/null @@ -1,350 +0,0 @@ -// import tw_colors from "tailwindcss/colors"; - -export const ordered_colors = [ - "red", - "green", - "blue", - "yellow", - "purple", - "teal", - "orange", - "cyan", - "lime", - "pink" -] as const; -interface ColorPair { - primary: string; - secondary: string; -} - -interface Colors { - red: ColorPair; - green: ColorPair; - blue: ColorPair; - yellow: ColorPair; - purple: ColorPair; - teal: ColorPair; - orange: ColorPair; - cyan: ColorPair; - lime: ColorPair; - pink: ColorPair; -} - -// https://play.tailwindcss.com/ZubQYya0aN -export const color_values = [ - { color: "red", primary: 600, secondary: 100 }, - { color: "green", primary: 600, secondary: 100 }, - { color: "blue", primary: 600, secondary: 100 }, - { color: "yellow", primary: 500, secondary: 100 }, - { color: "purple", primary: 600, secondary: 100 }, - { color: "teal", primary: 600, secondary: 100 }, - { color: "orange", primary: 600, secondary: 100 }, - { color: "cyan", primary: 600, secondary: 100 }, - { color: "lime", primary: 500, secondary: 100 }, - { color: "pink", primary: 600, secondary: 100 } -] as const; - -const tw_colors = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - slate: { - 50: "#f8fafc", - 100: "#f1f5f9", - 200: "#e2e8f0", - 300: "#cbd5e1", - 400: "#94a3b8", - 500: "#64748b", - 600: "#475569", - 700: "#334155", - 800: "#1e293b", - 900: "#0f172a", - 950: "#020617" - }, - gray: { - 50: "#f9fafb", - 100: "#f3f4f6", - 200: "#e5e7eb", - 300: "#d1d5db", - 400: "#9ca3af", - 500: "#6b7280", - 600: "#4b5563", - 700: "#374151", - 800: "#1f2937", - 900: "#111827", - 950: "#030712" - }, - zinc: { - 50: "#fafafa", - 100: "#f4f4f5", - 200: "#e4e4e7", - 300: "#d4d4d8", - 400: "#a1a1aa", - 500: "#71717a", - 600: "#52525b", - 700: "#3f3f46", - 800: "#27272a", - 900: "#18181b", - 950: "#09090b" - }, - neutral: { - 50: "#fafafa", - 100: "#f5f5f5", - 200: "#e5e5e5", - 300: "#d4d4d4", - 400: "#a3a3a3", - 500: "#737373", - 600: "#525252", - 700: "#404040", - 800: "#262626", - 900: "#171717", - 950: "#0a0a0a" - }, - stone: { - 50: "#fafaf9", - 100: "#f5f5f4", - 200: "#e7e5e4", - 300: "#d6d3d1", - 400: "#a8a29e", - 500: "#78716c", - 600: "#57534e", - 700: "#44403c", - 800: "#292524", - 900: "#1c1917", - 950: "#0c0a09" - }, - red: { - 50: "#fef2f2", - 100: "#fee2e2", - 200: "#fecaca", - 300: "#fca5a5", - 400: "#f87171", - 500: "#ef4444", - 600: "#dc2626", - 700: "#b91c1c", - 800: "#991b1b", - 900: "#7f1d1d", - 950: "#450a0a" - }, - orange: { - 50: "#fff7ed", - 100: "#ffedd5", - 200: "#fed7aa", - 300: "#fdba74", - 400: "#fb923c", - 500: "#f97316", - 600: "#ea580c", - 700: "#c2410c", - 800: "#9a3412", - 900: "#7c2d12", - 950: "#431407" - }, - amber: { - 50: "#fffbeb", - 100: "#fef3c7", - 200: "#fde68a", - 300: "#fcd34d", - 400: "#fbbf24", - 500: "#f59e0b", - 600: "#d97706", - 700: "#b45309", - 800: "#92400e", - 900: "#78350f", - 950: "#451a03" - }, - yellow: { - 50: "#fefce8", - 100: "#fef9c3", - 200: "#fef08a", - 300: "#fde047", - 400: "#facc15", - 500: "#eab308", - 600: "#ca8a04", - 700: "#a16207", - 800: "#854d0e", - 900: "#713f12", - 950: "#422006" - }, - lime: { - 50: "#f7fee7", - 100: "#ecfccb", - 200: "#d9f99d", - 300: "#bef264", - 400: "#a3e635", - 500: "#84cc16", - 600: "#65a30d", - 700: "#4d7c0f", - 800: "#3f6212", - 900: "#365314", - 950: "#1a2e05" - }, - green: { - 50: "#f0fdf4", - 100: "#dcfce7", - 200: "#bbf7d0", - 300: "#86efac", - 400: "#4ade80", - 500: "#22c55e", - 600: "#16a34a", - 700: "#15803d", - 800: "#166534", - 900: "#14532d", - 950: "#052e16" - }, - emerald: { - 50: "#ecfdf5", - 100: "#d1fae5", - 200: "#a7f3d0", - 300: "#6ee7b7", - 400: "#34d399", - 500: "#10b981", - 600: "#059669", - 700: "#047857", - 800: "#065f46", - 900: "#064e3b", - 950: "#022c22" - }, - teal: { - 50: "#f0fdfa", - 100: "#ccfbf1", - 200: "#99f6e4", - 300: "#5eead4", - 400: "#2dd4bf", - 500: "#14b8a6", - 600: "#0d9488", - 700: "#0f766e", - 800: "#115e59", - 900: "#134e4a", - 950: "#042f2e" - }, - cyan: { - 50: "#ecfeff", - 100: "#cffafe", - 200: "#a5f3fc", - 300: "#67e8f9", - 400: "#22d3ee", - 500: "#06b6d4", - 600: "#0891b2", - 700: "#0e7490", - 800: "#155e75", - 900: "#164e63", - 950: "#083344" - }, - sky: { - 50: "#f0f9ff", - 100: "#e0f2fe", - 200: "#bae6fd", - 300: "#7dd3fc", - 400: "#38bdf8", - 500: "#0ea5e9", - 600: "#0284c7", - 700: "#0369a1", - 800: "#075985", - 900: "#0c4a6e", - 950: "#082f49" - }, - blue: { - 50: "#eff6ff", - 100: "#dbeafe", - 200: "#bfdbfe", - 300: "#93c5fd", - 400: "#60a5fa", - 500: "#3b82f6", - 600: "#2563eb", - 700: "#1d4ed8", - 800: "#1e40af", - 900: "#1e3a8a", - 950: "#172554" - }, - indigo: { - 50: "#eef2ff", - 100: "#e0e7ff", - 200: "#c7d2fe", - 300: "#a5b4fc", - 400: "#818cf8", - 500: "#6366f1", - 600: "#4f46e5", - 700: "#4338ca", - 800: "#3730a3", - 900: "#312e81", - 950: "#1e1b4b" - }, - violet: { - 50: "#f5f3ff", - 100: "#ede9fe", - 200: "#ddd6fe", - 300: "#c4b5fd", - 400: "#a78bfa", - 500: "#8b5cf6", - 600: "#7c3aed", - 700: "#6d28d9", - 800: "#5b21b6", - 900: "#4c1d95", - 950: "#2e1065" - }, - purple: { - 50: "#faf5ff", - 100: "#f3e8ff", - 200: "#e9d5ff", - 300: "#d8b4fe", - 400: "#c084fc", - 500: "#a855f7", - 600: "#9333ea", - 700: "#7e22ce", - 800: "#6b21a8", - 900: "#581c87", - 950: "#3b0764" - }, - fuchsia: { - 50: "#fdf4ff", - 100: "#fae8ff", - 200: "#f5d0fe", - 300: "#f0abfc", - 400: "#e879f9", - 500: "#d946ef", - 600: "#c026d3", - 700: "#a21caf", - 800: "#86198f", - 900: "#701a75", - 950: "#4a044e" - }, - pink: { - 50: "#fdf2f8", - 100: "#fce7f3", - 200: "#fbcfe8", - 300: "#f9a8d4", - 400: "#f472b6", - 500: "#ec4899", - 600: "#db2777", - 700: "#be185d", - 800: "#9d174d", - 900: "#831843", - 950: "#500724" - }, - rose: { - 50: "#fff1f2", - 100: "#ffe4e6", - 200: "#fecdd3", - 300: "#fda4af", - 400: "#fb7185", - 500: "#f43f5e", - 600: "#e11d48", - 700: "#be123c", - 800: "#9f1239", - 900: "#881337", - 950: "#4c0519" - } -}; - -export const colors = color_values.reduce( - (acc, { color, primary, secondary }) => ({ - ...acc, - [color]: { - primary: tw_colors[color][primary], - secondary: tw_colors[color][secondary] - } - }), - {} as Colors -); diff --git a/6.14.1/theme/src/index.ts b/6.14.1/theme/src/index.ts deleted file mode 100644 index bd1cb299eaa9b1ae2f6bd0c1973fa12d0c4cdb57..0000000000000000000000000000000000000000 --- a/6.14.1/theme/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// export { default as reset } from "./reset.css"; -// export { default as global } from "./global.css"; -// export { default as css } from "./pollen.css"; -// export { default as typography } from "./typography.css"; - -export * from "./colors.js"; diff --git a/6.14.1/timer/Index.svelte b/6.14.1/timer/Index.svelte deleted file mode 100644 index 7fc7857ad7235b62c97ffb4fccba78a6c9d89fd9..0000000000000000000000000000000000000000 --- a/6.14.1/timer/Index.svelte +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/6.14.1/timer/package.json b/6.14.1/timer/package.json deleted file mode 100644 index 69e4fd022b1204bf416a79f66fbf6f1c0e859744..0000000000000000000000000000000000000000 --- a/6.14.1/timer/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@gradio/timer", - "version": "0.4.9", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "dependencies": { - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/timer" - } -} diff --git a/6.14.1/timer/types.ts b/6.14.1/timer/types.ts deleted file mode 100644 index 292d729b4daf9b93f8261167f14496b64a103084..0000000000000000000000000000000000000000 --- a/6.14.1/timer/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimerProps { - value: number; - active: boolean; -} - -export interface TimerEvents { - tick: never; - clear_status: never; -} diff --git a/6.14.1/tooltip/package.json b/6.14.1/tooltip/package.json deleted file mode 100644 index 1b699440866a7a7c79de9e7575bc07b5373465fe..0000000000000000000000000000000000000000 --- a/6.14.1/tooltip/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@gradio/tooltip", - "version": "0.2.1", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/tooltip" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": { - "gradio": "./src/index.js", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./package.json": "./package.json" - } -} diff --git a/6.14.1/tooltip/src/Tooltip.svelte b/6.14.1/tooltip/src/Tooltip.svelte deleted file mode 100644 index c9c9ecca6357234953144bcf6a0dbe7ee5e822de..0000000000000000000000000000000000000000 --- a/6.14.1/tooltip/src/Tooltip.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - {text} -
- - diff --git a/6.14.1/tooltip/src/index.ts b/6.14.1/tooltip/src/index.ts deleted file mode 100644 index b89ac870e5bbf6d90058c6e25cb9d74b626b3809..0000000000000000000000000000000000000000 --- a/6.14.1/tooltip/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { tooltip } from "./tooltip"; diff --git a/6.14.1/tooltip/src/tooltip.ts b/6.14.1/tooltip/src/tooltip.ts deleted file mode 100644 index 09403f9438805f29a32579b8e98a25f3aae37737..0000000000000000000000000000000000000000 --- a/6.14.1/tooltip/src/tooltip.ts +++ /dev/null @@ -1,49 +0,0 @@ -import Tooltip from "./Tooltip.svelte"; - -interface ActionArgs { - color: string; - text: string; -} - -export function tooltip( - element: HTMLElement | SVGElement, - { color, text }: ActionArgs -): any { - let tooltipComponent: Tooltip; - function mouse_over(event: MouseEvent): MouseEvent { - tooltipComponent = new Tooltip({ - props: { - text, - x: event.pageX, - y: event.pageY, - color - }, - target: document.body - }); - - return event; - } - function mouseMove(event: MouseEvent): void { - tooltipComponent.$set({ - x: event.pageX, - y: event.pageY - }); - } - function mouseLeave(): void { - tooltipComponent.$destroy(); - } - - const el = element as HTMLElement; - - el.addEventListener("mouseover", mouse_over); - el.addEventListener("mouseleave", mouseLeave); - el.addEventListener("mousemove", mouseMove); - - return { - destroy() { - el.removeEventListener("mouseover", mouse_over); - el.removeEventListener("mouseleave", mouseLeave); - el.removeEventListener("mousemove", mouseMove); - } - }; -} diff --git a/6.14.1/tootils/package.json b/6.14.1/tootils/package.json deleted file mode 100644 index 48eb1d1965ba7996b019d3fb54d5d4641d35b44f..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@self/tootils", - "version": "0.14.0", - "description": "Internal test utilities", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "exports": { - ".": "./src/index.ts", - "./render": "./src/render.ts", - "./shared-prop-tests": "./src/shared-prop-tests.ts", - "./app-launcher": "./src/app-launcher.ts", - "./download-command": "./src/download-command.ts" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.14.1/tootils/src/app-launcher.ts b/6.14.1/tootils/src/app-launcher.ts deleted file mode 100644 index 64ea714de850dadb6875517d456b65952203ea49..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/app-launcher.ts +++ /dev/null @@ -1,276 +0,0 @@ -import { spawn, spawnSync, type ChildProcess } from "node:child_process"; -import http from "http"; -import net from "net"; -import path from "path"; -import fs from "fs"; -import os from "os"; -import url from "url"; - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -const ROOT_DIR = path.resolve(__dirname, "../../.."); - -export interface GradioApp { - port: number; - process: ChildProcess; -} - -export function killGradioApp(process: ChildProcess): void { - try { - process.kill("SIGTERM"); - } catch { - // Process may already be dead - } -} - -/** - * Sweep orphaned gradio demo python processes — i.e. processes running - * `python /run.py` whose parent has died (PPID == 1, reparented to - * init/launchd). Without this, a Playwright worker that crashes (e.g. - * after a test timeout) leaves its spawned demo apps behind: the new - * worker has an empty appCache and won't kill them, ports get squatted, - * and resources accumulate. Documented behavior, not a guess: in the SSR - * profile run, this orphaning produced 100+ leaked python procs / 7.5GB. - * - * Best-effort: failures in the sweep are swallowed so they can't block - * the spawn path itself. - */ -function reapOrphanedDemos(): void { - try { - const result = spawnSync("ps", ["-A", "-o", "pid=,ppid=,command="], { - encoding: "utf8" - }); - if (result.status !== 0 || !result.stdout) return; - - for (const line of result.stdout.split("\n")) { - const trimmed = line.trim(); - if (!trimmed) continue; - const match = trimmed.match(/^(\d+)\s+(\d+)\s+(.*)$/); - if (!match) continue; - const [, pidStr, ppidStr, cmd] = match; - if (ppidStr !== "1") continue; - // Only target our test demo apps (python running gradio demo files). - // Match `gradio/.../demo//.py` to avoid accidentally - // killing unrelated python processes. - if (!/python.*\/demo\/[^/]+\/[^/]+\.py/.test(cmd)) continue; - if (!cmd.includes("/gradio/")) continue; - try { - process.kill(Number(pidStr), "SIGTERM"); - } catch { - // already dead, or not ours to kill - } - } - } catch { - // ps unavailable or parse error — non-fatal - } -} - -export async function findFreePort( - startPort: number, - endPort: number -): Promise { - for (let port = startPort; port < endPort; port++) { - if (await isPortFree(port)) { - return port; - } - } - throw new Error(`Could not find free port in range ${startPort}-${endPort}`); -} - -function isPortFree(port: number): Promise { - return new Promise((resolve) => { - const sock = net.createConnection(port, "127.0.0.1"); - sock.once("connect", () => { - sock.end(); - resolve(false); - }); - sock.once("error", (e: NodeJS.ErrnoException) => { - sock.destroy(); - // ECONNREFUSED → no listener (free). Anything else (ECONNRESET from - // a half-closed socket left by a SIGTERM'd demo, ETIMEDOUT, etc.) - // → don't trust the port, skip to the next one. Previously we - // rejected on non-ECONNREFUSED errors, which aborted the whole - // findFreePort scan and surfaced as "Failed to launch app". - resolve(e.code === "ECONNREFUSED"); - }); - }); -} - -/** - * Poll the server with HTTP GET requests until it returns a response. - * Gradio prints "Running on local URL:" before the server is fully ready, - * so we need to verify it actually responds to HTTP requests. - */ -async function waitForServerReady( - port: number, - timeoutMs: number = 15000 -): Promise { - const start = Date.now(); - const pollInterval = 200; - - while (Date.now() - start < timeoutMs) { - try { - await new Promise((resolve, reject) => { - // Use HEAD on /gradio_api/info to avoid triggering SSR rendering on - // the root URL, which could block Gradio's own startup health check. - const req = http.request( - `http://127.0.0.1:${port}/gradio_api/info`, - { method: "HEAD", timeout: 2000 }, - (res) => { - res.resume(); // drain the response - resolve(); - } - ); - req.on("error", reject); - req.on("timeout", () => { - req.destroy(); - reject(new Error("request timeout")); - }); - req.end(); - }); - return; // Server responded successfully - } catch { - // Server not ready yet, wait and retry - await new Promise((r) => setTimeout(r, pollInterval)); - } - } - throw new Error( - `Server on port ${port} did not become ready within ${timeoutMs}ms` - ); -} - -export function getTestcases(demoName: string): string[] { - const demoDir = path.join(ROOT_DIR, "demo", demoName); - if (!fs.existsSync(demoDir)) { - return []; - } - - return fs - .readdirSync(demoDir) - .filter((f) => f.endsWith("_testcase.py")) - .map((f) => path.basename(f, ".py")); -} - -// Check if a testcase file exists for this demo -export function hasTestcase(demoName: string, testcaseName: string): boolean { - const testcaseFile = path.join( - ROOT_DIR, - "demo", - demoName, - `${testcaseName}_testcase.py` - ); - return fs.existsSync(testcaseFile); -} - -// Get the path to a demo's Python file -function getDemoFilePath(demoName: string, testcaseName?: string): string { - if (testcaseName) { - return path.join(ROOT_DIR, "demo", demoName, `${testcaseName}_testcase.py`); - } - return path.join(ROOT_DIR, "demo", demoName, "run.py"); -} - -export async function launchGradioApp( - demoName: string, - workerIndex: number = 0, - timeout: number = 60000, - testcaseName?: string -): Promise { - // Sweep orphaned demo apps from previous (crashed) worker generations - // before claiming a port — see reapOrphanedDemos() for rationale. - reapOrphanedDemos(); - - // Partition ports by worker index to avoid collisions - const basePort = 7860 + workerIndex * 100; - const port = await findFreePort(basePort, basePort + 99); - - // Get the path to the demo file - const demoFilePath = getDemoFilePath(demoName, testcaseName); - - // Create unique directories for this instance to avoid cache conflicts - const instanceId = testcaseName - ? `${demoName}_${testcaseName}_${port}` - : `${demoName}_${port}`; - const instanceDir = path.join(os.tmpdir(), `gradio_test_${instanceId}`); - const cacheDir = path.join(instanceDir, "cached_examples"); - const tempDir = path.join(instanceDir, "temp"); - - if (!fs.existsSync(instanceDir)) { - fs.mkdirSync(instanceDir, { recursive: true }); - } - - // Run the demo via _demo_runner.py instead of directly. The wrapper - // watches its stdin pipe: if the playwright worker that spawned us - // dies (cleanly or via SIGKILL on timeout), the kernel closes the pipe, - // stdin returns EOF and the demo self-exits immediately — instead of - // becoming an orphan that survives the rest of the suite. - const demoRunnerPath = path.join(__dirname, "_demo_runner.py"); - const childProcess = spawn("python", [demoRunnerPath, demoFilePath], { - stdio: "pipe", - cwd: ROOT_DIR, - env: { - ...process.env, - PYTHONUNBUFFERED: "true", - GRADIO_ANALYTICS_ENABLED: "False", - GRADIO_IS_E2E_TEST: "1", - GRADIO_RESET_EXAMPLES_CACHE: "True", - // Control the port via environment variable - GRADIO_SERVER_PORT: port.toString(), - // Use unique directories per instance to avoid conflicts - GRADIO_EXAMPLES_CACHE: cacheDir, - GRADIO_TEMP_DIR: tempDir - } - }); - - childProcess.stdout?.setEncoding("utf8"); - childProcess.stderr?.setEncoding("utf8"); - - // Wait for app to be ready - return new Promise((resolve, reject) => { - const timeoutId = setTimeout(() => { - killGradioApp(childProcess); - reject( - new Error(`Gradio app ${demoName} failed to start within ${timeout}ms`) - ); - }, timeout); - - let output = ""; - let startupDetected = false; - - function handleOutput(data: string): void { - output += data; - // Check for Gradio's startup message - if ( - !startupDetected && - (data.includes("Running on local URL:") || - data.includes(`Uvicorn running on`)) - ) { - startupDetected = true; - clearTimeout(timeoutId); - // The startup message is printed before the server is fully ready. - // Poll with HTTP requests to ensure it actually responds. - waitForServerReady(port) - .then(() => resolve({ port, process: childProcess })) - .catch(reject); - } - } - - childProcess.stdout?.on("data", handleOutput); - childProcess.stderr?.on("data", handleOutput); - - childProcess.on("error", (err) => { - clearTimeout(timeoutId); - reject(err); - }); - - childProcess.on("exit", (code) => { - if (code !== 0 && code !== null) { - clearTimeout(timeoutId); - reject( - new Error( - `Gradio app ${demoName} exited with code ${code}.\nOutput: ${output}` - ) - ); - } - }); - }); -} diff --git a/6.14.1/tootils/src/download-command.ts b/6.14.1/tootils/src/download-command.ts deleted file mode 100644 index 2d99d0883c6b5e985d21c18902e61db60ccaa6dc..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/download-command.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { BrowserCommand } from "vitest/node"; -import { resolve } from "path"; -import { readFile } from "fs/promises"; - -/** - * Vitest browser command that captures a real file download triggered by - * clicking an element. Runs server-side with access to the Playwright page. - * - * Sets up page.waitForEvent("download") BEFORE clicking, so the download - * event is never missed. - */ -export const expect_download: BrowserCommand< - [selector: string, options?: { timeout?: number }], - { suggested_filename: string; content: string | null } -> = async (context, selector, options) => { - const timeout = options?.timeout ?? 5000; - const provider = context.provider as any; - const page = provider.getPage(context.sessionId); - // Tests run inside an iframe; use the iframe locator to click - // but listen for the download event on the parent page. - const iframe = (context as any).iframe; - - const [download] = await Promise.all([ - page.waitForEvent("download", { timeout }), - iframe.locator(selector).click() - ]); - - const suggested_filename = download.suggestedFilename(); - const path = await download.path(); - - let content: string | null = null; - if (path) { - const fs = await import("fs/promises"); - content = await fs.readFile(path, "utf-8"); - } - - return { - suggested_filename, - content - }; -}; - -/** - * Vitest browser command that sets files on an element. - * Resolves fixture URL paths (e.g. "/test/test_files/bus.png") to absolute - * disk paths and uses Playwright's setInputFiles(). - */ -export const set_file_inputs: BrowserCommand< - [file_urls: string[], selector?: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - const iframe = (context as any).iframe; - - const paths = file_urls.map((url) => resolve(root, url.replace(/^\//, ""))); - - await iframe - .locator(selector ?? 'input[type="file"]') - .first() - .setInputFiles(paths); -}; - -interface Drop_file_spec { - data: string; // base64 - name: string; - mime_type: string; -} - -/** - * Vitest browser command that simulates dropping files onto an element. - * Reads files from disk, transfers them as base64 into the browser context, - * and dispatches dragenter, dragover, and drop events with a real DataTransfer. - */ -export const drop_files: BrowserCommand< - [file_urls: string[], selector: string] -> = async (context, file_urls, selector) => { - const root = context.project.config.root; - - const files: Drop_file_spec[] = await Promise.all( - file_urls.map(async (url) => { - const abs = resolve(root, url.replace(/^\//, "")); - const data = (await readFile(abs)).toString("base64"); - const name = abs.split("/").pop()!; - const ext = name.split(".").pop()!.toLowerCase(); - const mime_type = MIME_TYPES[ext] || "application/octet-stream"; - return { data, name, mime_type }; - }) - ); - - const iframe = (context as any).iframe; - await iframe - .locator(selector) - .first() - .evaluate((target: Element, files: Drop_file_spec[]) => { - const dt = new DataTransfer(); - for (const f of files) { - const bytes = Uint8Array.from(atob(f.data), (c) => c.charCodeAt(0)); - dt.items.add(new File([bytes], f.name, { type: f.mime_type })); - } - - target.dispatchEvent( - new DragEvent("dragenter", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("dragover", { - dataTransfer: dt, - bubbles: true - }) - ); - target.dispatchEvent( - new DragEvent("drop", { dataTransfer: dt, bubbles: true }) - ); - }, files); -}; - -const MIME_TYPES: Record = { - txt: "text/plain", - csv: "text/csv", - json: "application/json", - pdf: "application/pdf", - jpg: "image/jpeg", - jpeg: "image/jpeg", - png: "image/png", - gif: "image/gif", - webp: "image/webp", - svg: "image/svg+xml", - mp4: "video/mp4", - webm: "video/webm", - ogg: "video/ogg", - avi: "video/x-msvideo", - wav: "audio/wav", - mp3: "audio/mpeg", - flac: "audio/flac" -}; diff --git a/6.14.1/tootils/src/download.ts b/6.14.1/tootils/src/download.ts deleted file mode 100644 index c6217fc6695b81fe685bcff9593ed9cab6095a3a..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/download.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { commands } from "vitest/browser"; -import type { FileData } from "@gradio/client"; - -export interface DownloadResult { - suggested_filename: string; - content: string | null; -} - -/** - * Clicks an element and captures the resulting file download. - * - * Uses a real browser download via Playwright under the hood — - * the file is actually downloaded and its content is readable. - * - * @param selector - CSS selector for the element to click - * @param options - Optional timeout (default 5000ms) - * @returns The downloaded file's suggested filename and text content - * - * @example - * ```ts - * const { suggested_filename, content } = await download_file("a.download-link"); - * expect(suggested_filename).toBe("data.csv"); - * expect(content).toContain("col1,col2"); - * ``` - */ -export async function download_file( - selector: string, - options?: { timeout?: number } -): Promise { - return (commands as any).expect_download(selector, options); -} - -/** - * Sets files on an `` element using real file fixtures. - * - * Accepts one or more FileData fixtures (e.g. TEST_JPG, TEST_PNG) and - * sets them on the file input, triggering the browser's native change event. - * - * @param files - One or more FileData fixtures to upload - * @param selector - CSS selector for the file input (default: 'input[type="file"]') - * - * @example - * ```ts - * import { render, upload_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await upload_file(TEST_JPG); - * - * expect(upload).toHaveBeenCalled(); - * ``` - */ -export async function upload_file( - files: FileData | FileData[], - selector?: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).set_file_inputs(urls, selector); -} - -/** - * Simulates dragging and dropping files onto an element. - * - * Reads the fixture files from disk, constructs a real DataTransfer - * with File objects, and dispatches dragenter, dragover, and drop events - * on the target element. - * - * @param files - One or more FileData fixtures to drop - * @param selector - CSS selector for the drop target element - * - * @example - * ```ts - * import { render, drop_file, TEST_JPG } from "@self/tootils/render"; - * - * const { listen } = await render(ImageUpload, { interactive: true }); - * const upload = listen("upload"); - * - * await drop_file(TEST_JPG, "[aria-label='Click to upload or drop files']"); - * - * await vi.waitFor(() => expect(upload).toHaveBeenCalled()); - * ``` - */ -export async function drop_file( - files: FileData | FileData[], - selector: string -): Promise { - const file_list = Array.isArray(files) ? files : [files]; - const urls = file_list.map((f) => f.url ?? f.path); - return (commands as any).drop_files(urls, selector); -} diff --git a/6.14.1/tootils/src/fixtures.ts b/6.14.1/tootils/src/fixtures.ts deleted file mode 100644 index 75d8a6419d3a1da6526c64ba44280844cd54f122..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/fixtures.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { FileData } from "@gradio/client"; - -const BASE = "/test/test_files"; - -function fixture(filename: string, mime_type: string, size: number): FileData { - const url = `${BASE}/${filename}`; - return new FileData({ - path: url, - url, - orig_name: filename, - size, - mime_type - }); -} - -export const TEST_TXT = fixture("alphabet.txt", "text/plain", 26); -export const TEST_JPG = fixture("cheetah1.jpg", "image/jpeg", 20552); -export const TEST_PNG = fixture("bus.png", "image/png", 1951); -export const TEST_MP4 = fixture("video_sample.mp4", "video/mp4", 261179); -export const TEST_WAV = fixture("audio_sample.wav", "audio/wav", 16136); -export const TEST_PDF = fixture("sample_file.pdf", "application/pdf", 10558); -export const TEST_GLTF = fixture("Box.gltf", "model/gltf+json", 5249); -export const TEST_PLY = fixture("model.ply", "application/octet-stream", 413); -export const TEST_SPLAT = fixture( - "model.splat", - "application/octet-stream", - 32 -); diff --git a/6.14.1/tootils/src/index.ts b/6.14.1/tootils/src/index.ts deleted file mode 100644 index a85eba689e1f5600e909023c8c5bb68b68674bce..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/index.ts +++ /dev/null @@ -1,245 +0,0 @@ -import { test as base, type Locator, type Page } from "@playwright/test"; -import { spy } from "tinyspy"; -import url from "url"; -import path from "path"; -import fsPromises from "fs/promises"; -import type { ChildProcess } from "node:child_process"; - -import type { SvelteComponent } from "svelte"; -import type { SpyFn } from "tinyspy"; - -import { launchGradioApp, killGradioApp, hasTestcase } from "./app-launcher"; - -export function get_text(el: T): string { - return el.innerText.trim(); -} - -export function wait(n: number): Promise { - return new Promise((r) => setTimeout(r, n)); -} - -const ROOT_DIR = path.resolve( - url.fileURLToPath(import.meta.url), - "../../../.." -); - -// Extract testcase name from test title if present -// Test titles can be: -// - "case eager_caching_examples: ..." -// - "test case multimodal_messages chatinterface works..." -function extractTestcaseFromTitle( - title: string, - demoName: string -): string | undefined { - // Try pattern: "case :" or "test case " - const patterns = [/^case\s+(\w+):/, /^test case\s+(\w+)\s/]; - - for (const pattern of patterns) { - const match = title.match(pattern); - if (match) { - const caseName = match[1]; - // Check if this is a testcase (not the main demo) - if (hasTestcase(demoName, caseName)) { - return caseName; - } - } - } - return undefined; -} - -// Cache for launched apps - key is "demoName" or "demoName_testcaseName" -const appCache = new Map< - string, - { port: number; process: ChildProcess; refCount: number } ->(); - -// Track the cacheKey of the currently-running spec file so we can kill the -// previous spec's gradio app when the worker moves on. Without this, every -// app spawned during a worker's lifetime stayed resident until process exit -// (~50 python procs / 5GB RSS by end of suite — the tail of the run starved -// for CPU and tests timed out). -let currentCacheKey: string | null = null; - -function killAndEvict(cacheKey: string): void { - const info = appCache.get(cacheKey); - if (!info) return; - killGradioApp(info.process); - appCache.delete(cacheKey); -} - -// Test fixture that launches Gradio app per test -const test_normal = base.extend<{ setup: void }>({ - setup: [ - async ({ page }, use, testInfo): Promise => { - const { file, title } = testInfo; - const demoName = path.basename(file, ".spec.ts"); - - // Check if this is a reload test (they manage their own apps) - if (demoName.endsWith(".reload")) { - // For reload tests, don't launch an app - they handle it themselves - await use(); - return; - } - - // Check if this test is for a specific testcase - const testcaseName = extractTestcaseFromTitle(title, demoName); - - // Cache key includes testcase if present - const cacheKey = testcaseName ? `${demoName}_${testcaseName}` : demoName; - - // First test of a new spec file → previous file's app is no longer - // needed on this worker. fullyParallel=false in playwright.config - // guarantees a worker finishes a file before starting the next, so - // the kill is unconditional on the transition (we don't gate on - // refCount: a throw before `await use()` — e.g. a flaky SSR - // hydration wait — can leak refCount, which would otherwise pin - // the previous spec's app forever). - if (currentCacheKey !== null && currentCacheKey !== cacheKey) { - killAndEvict(currentCacheKey); - } - currentCacheKey = cacheKey; - - let appInfo = appCache.get(cacheKey); - - if (!appInfo) { - // Launch the app for this test - const workerIndex = testInfo.workerIndex; - try { - const { port, process } = await launchGradioApp( - demoName, - workerIndex, - 60000, - testcaseName - ); - appInfo = { port, process, refCount: 0 }; - appCache.set(cacheKey, appInfo); - } catch (error) { - console.error(`Failed to launch app for ${cacheKey}:`, error); - throw error; - } - } - - try { - // Navigate to the app - await page.goto(`http://localhost:${appInfo.port}`); - - if ( - process.env?.GRADIO_SSR_MODE?.toLowerCase() === "true" && - !( - demoName.includes("multipage") || - demoName.includes("chatinterface_deep_link") - ) - ) { - await page.waitForSelector("#svelte-announcer"); - } - await page.waitForLoadState("load"); - - await use(); - } finally { - } - }, - { auto: true } - ] -}); - -// Cleanup apps when the process exits -process.on("exit", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } -}); - -process.on("SIGINT", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -process.on("SIGTERM", () => { - for (const [, appInfo] of appCache) { - killGradioApp(appInfo.process); - } - process.exit(0); -}); - -export const test = test_normal; - -export async function wait_for_event( - component: SvelteComponent, - event: string -): Promise { - const mock = spy(); - return new Promise((res) => { - component.$on(event, () => { - mock(); - res(mock); - }); - }); -} - -export interface ActionReturn< - Parameter = never, - Attributes extends Record = Record -> { - update?: [Parameter] extends [never] ? never : (parameter: Parameter) => void; - destroy?: () => void; - /** - * ### DO NOT USE THIS - * This exists solely for type-checking and has no effect at runtime. - * Set this through the `Attributes` generic instead. - */ - $$_attributes?: Attributes; -} - -export { expect } from "@playwright/test"; - -export const drag_and_drop_file = async ( - page: Page, - selector: string | Locator, - filePath: string, - fileName: string, - fileType = "", - count = 1 -): Promise => { - const buffer = (await fsPromises.readFile(filePath)).toString("base64"); - - const dataTransfer = await page.evaluateHandle( - async ({ bufferData, localFileName, localFileType, count }) => { - const dt = new DataTransfer(); - - const blobData = await fetch(bufferData).then((res) => res.blob()); - - const file = new File([blobData], localFileName, { - type: localFileType - }); - - for (let i = 0; i < count; i++) { - dt.items.add(file); - } - return dt; - }, - { - bufferData: `data:application/octet-stream;base64,${buffer}`, - localFileName: fileName, - localFileType: fileType, - count - } - ); - - if (typeof selector === "string") { - await page.dispatchEvent(selector, "drop", { dataTransfer }); - } else { - await selector.dispatchEvent("drop", { dataTransfer }); - } -}; - -export async function go_to_testcase( - page: Page, - _test_case: string -): Promise { - // With the new setup, each testcase launches its own Gradio app. - // The fixture detects the testcase from the test title and launches - // the correct app, so this function is now a no-op. - // The page is already at the correct testcase app. -} diff --git a/6.14.1/tootils/src/render.ts b/6.14.1/tootils/src/render.ts deleted file mode 100644 index 292a39deb9ce1a30c73623e6d4e6e4e697ae2c01..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/render.ts +++ /dev/null @@ -1,317 +0,0 @@ -import { - getQueriesForElement, - prettyDOM, - fireEvent as dtlFireEvent -} from "@testing-library/dom"; -import { tick, mount, unmount } from "svelte"; -import type { SvelteComponent, Component } from "svelte"; - -import type { - queries, - Queries, - BoundFunction, - EventType -} from "@testing-library/dom"; -import { vi, type Mock } from "vitest"; -import { GRADIO_ROOT, allowed_shared_props } from "@gradio/utils"; -import type { LoadingStatus, ILoadingStatus } from "@gradio/statustracker"; -import { _ } from "svelte-i18n"; - -const containerCache = new Map(); -const componentCache = new Set(); - -type ComponentType = Component; - -export type RenderResult< - C extends SvelteComponent, - Q extends Queries = typeof queries -> = { - container: HTMLElement; - component: C; - debug: (el?: HTMLElement | DocumentFragment) => void; - unmount: () => void; -} & { [P in keyof Q]: BoundFunction }; -export interface ILoadingStatus { - eta: number | null; - status: "pending" | "error" | "complete" | "generating" | "streaming"; - queue: boolean; - queue_position: number | null; - queue_size?: number; - fn_index: number; - message?: string | null; - scroll_to_output?: boolean; - show_progress?: "full" | "minimal" | "hidden"; - time_limit?: number | null | undefined; - progress?: { - progress: number | null; - index: number | null; - length: number | null; - unit: string | null; - desc: string | null; - }[]; - validation_error?: string | null; - type: "input" | "output"; - stream_state: "open" | "closed" | "waiting" | null; -} - -const loading_status: ILoadingStatus = { - eta: 0, - queue_position: 1, - queue_size: 1, - queue: true, - message: null, - time_limit: null, - progress: [], - validation_error: null, - type: "output", - stream_state: null, - status: "complete" as ILoadingStatus["status"], - scroll_to_output: false, - fn_index: 0, - show_progress: "full" as ILoadingStatus["show_progress"] -}; - -export interface RenderOptions { - container?: HTMLElement; - queries?: Q; -} - -export async function render< - Events extends Record, - Props extends Record, - T extends SvelteComponent, - X extends Record ->( - Component: ComponentType | { default: ComponentType }, - props?: Omit & { - loading_status?: LoadingStatus; - }, - options?: { - container?: HTMLElement; - } -): Promise< - RenderResult & { - listen: (event_name: string, opts?: { retrospective?: boolean }) => Mock; - set_data: (data: Record) => Promise; - get_data: () => Promise>; - } -> { - let container: HTMLElement; - if (!options?.container) { - container = document.body; - } else { - container = options.container; - } - - const target = container.appendChild(document.createElement("div")); - - const ComponentConstructor: ComponentType = - //@ts-ignore - Component.default || Component; - - const id = Math.floor(Math.random() * 1000000); - - let component_set_data: (data: Record) => void; - let component_get_data: () => Promise>; - - const mock_register = ( - _id: number, - set_data: (data: Record) => void, - get_data: () => Promise> - ): void => { - component_set_data = set_data; - component_get_data = get_data; - }; - - const event_listeners = new Map void>>(); - const event_buffer: Array<{ event: string; data: any }> = []; - - function notify_listeners(event: string, data: any): void { - const listeners = event_listeners.get(event); - if (listeners) { - for (const listener of listeners) { - listener(data); - } - } - } - - const dispatcher = (_id: number, event: string, data: any): void => { - event_buffer.push({ event, data }); - notify_listeners(event, data); - }; - - function listen( - event_name: string, - opts?: { retrospective?: boolean } - ): Mock { - const fn = vi.fn(); - if (!event_listeners.has(event_name)) { - event_listeners.set(event_name, new Set()); - } - event_listeners.get(event_name)!.add(fn); - - if (opts?.retrospective) { - for (const entry of event_buffer) { - if (entry.event === event_name) { - fn(entry.data); - } - } - } - - return fn; - } - - const i18nFormatter = (s: string | null | undefined): string => s ?? ""; - - const shared_props_obj: Record = { - id, - target, - theme_mode: "light" as const, - version: "2.0.0", - formatter: i18nFormatter, - client: {} as any, - load_component: () => Promise.resolve({ default: {} as any }), - show_progress: true, - api_prefix: "", - server: {} as any, - show_label: true, - register_component: mock_register, - dispatcher - }; - - const component_props_obj: Record = { - i18n: i18nFormatter - }; - - if (props) { - for (const key in props) { - const value = (props as any)[key]; - if (allowed_shared_props.includes(key as any)) { - shared_props_obj[key] = value; - } else { - component_props_obj[key] = value; - } - } - } - - shared_props_obj.loading_status = props?.loading_status - ? props.loading_status - : loading_status; - - const componentProps = { - shared_props: shared_props_obj, - props: { - ...component_props_obj - }, - ...shared_props_obj - }; - - const component = mount(ComponentConstructor, { - target, - props: componentProps - }) as T; - - containerCache.set(container, { target, component }); - componentCache.add(component); - - await tick(); - - return { - container, - component, - listen, - set_data: async (data: Record) => { - const r = component_set_data(data); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return r; - }, - get_data: () => component_get_data(), - //@ts-ignore - debug: (el = container): void => console.warn(prettyDOM(el)), - unmount: (): void => { - if (componentCache.has(component)) { - unmount(component); - } - }, - ...getQueriesForElement(container) - }; -} - -const cleanupAtContainer = (container: HTMLElement): void => { - const { target, component } = containerCache.get(container); - - if (componentCache.has(component)) { - unmount(component); - } - - if (target.parentNode === document.body) { - document.body.removeChild(target); - } - - containerCache.delete(container); -}; - -export function cleanup(): void { - Array.from(containerCache.keys()).forEach(cleanupAtContainer); - document.body.innerHTML = ""; -} - -type AsyncFireObject = { - [K in EventType]: ( - element: Document | Element | Window | Node, - options?: object - ) => Promise; -}; - -export const fireEvent = Object.keys(dtlFireEvent).reduce((acc, key) => { - const _key = key as EventType; - return { - ...acc, - [_key]: async ( - element: Document | Element | Window, - options: object = {} - ): Promise => { - const event = dtlFireEvent[_key](element, options); - // we double tick here because the event may trigger state update inside the component - // the event may _only_ be fired in response to these state updates. - // so we want everything to settle before returning and continuing with the test. - await tick(); - await tick(); - return event; - } - }; -}, {} as AsyncFireObject); - -export type FireFunction = ( - element: Document | Element | Window, - event: Event -) => Promise; - -export { download_file, upload_file, drop_file } from "./download.js"; - -/** - * Creates a mock client suitable for components that use file uploads. - * The upload mock echoes back the input FileData unchanged. - */ -export function mock_client(): Record { - return { - upload: async (file_data: any[]) => file_data, - stream: async () => ({ onmessage: null, close: () => {} }) - }; -} -export { - TEST_TXT, - TEST_JPG, - TEST_PNG, - TEST_MP4, - TEST_WAV, - TEST_PDF, - TEST_GLTF, - TEST_PLY, - TEST_SPLAT -} from "./fixtures.js"; -export * from "@testing-library/dom"; diff --git a/6.14.1/tootils/src/shared-prop-tests.ts b/6.14.1/tootils/src/shared-prop-tests.ts deleted file mode 100644 index b8f58e68a13e368fd4a1f1d6f2e246260b82bcd0..0000000000000000000000000000000000000000 --- a/6.14.1/tootils/src/shared-prop-tests.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, test, expect, afterEach } from "vitest"; -import { render, cleanup } from "./render"; - -const loading_status = { - status: "complete", - queue_position: null, - queue_size: null, - eta: null, - message: null -}; - -export interface SharedPropTestConfig { - /** The Svelte component to test */ - component: any; - /** Minimum props required to render the component without errors */ - base_props: Record; - /** Display name for test output */ - name: string; - /** - * Some components don't render labels (e.g. HTML, Markdown). - * Set to false to skip label-related tests. - * @default true - */ - has_label?: boolean; - /** - * Whether the component renders validation_error text. - * Not all components support this. Set to false to skip. - * @default true - */ - has_validation_error?: boolean; - /** - * Some components (e.g. Accordion) map visible=false to "hidden" - * instead of removing from the DOM. Set to true to expect hidden - * behaviour rather than removal. - * @default false - */ - visible_false_hides?: boolean; - /** - * Whether the component is wrapped in a Block (which renders a `.block` - * element). Components like Button render a bare element instead. - * Set to false to skip `.block` selector checks. - * @default true - */ - has_block_wrapper?: boolean; -} - -export function run_shared_prop_tests(config: SharedPropTestConfig): void { - const { - component, - base_props, - name, - has_label = true, - has_validation_error = true, - visible_false_hides = false, - has_block_wrapper = true - } = config; - - const label = "Test Label"; - - function make_props( - overrides: Record = {} - ): Record { - return { - ...base_props, - loading_status: { ...loading_status, ...overrides }, - label, - ...overrides - }; - } - - describe(`${name}: shared props`, () => { - afterEach(() => cleanup()); - - test("elem_id is applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_id: "my-test-id" }) - ); - const el = container.querySelector("#my-test-id"); - expect(el).not.toBeNull(); - }); - - test("elem_classes are applied to the wrapper", async () => { - const { container } = await render( - component, - make_props({ elem_classes: ["my-test-class"] }) - ); - const el = container.querySelector(".my-test-class"); - expect(el).not.toBeNull(); - }); - - test("visible: true renders the component", async () => { - const { container } = await render( - component, - make_props({ visible: true, elem_id: "visible-test" }) - ); - const el = has_block_wrapper - ? container.querySelector(".block") - : container.querySelector("#visible-test"); - expect(el).not.toBeNull(); - }); - - test("visible: 'hidden' hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: "hidden", elem_id: "hidden-test" }) - ); - - const el = result.container.querySelector("#hidden-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - - if (visible_false_hides) { - test("visible: false hides the component but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).not.toBeNull(); - expect(el).not.toBeVisible(); - }); - } else { - test("visible: false removes the component from the DOM", async () => { - const result = await render( - component, - make_props({ visible: false, elem_id: "gone-test" }) - ); - - const el = result.container.querySelector("#gone-test"); - expect(el).toBeNull(); - }); - } - - if (has_label) { - test("label text is rendered", async () => { - const result = await render( - component, - make_props({ label: "My Custom Label", show_label: true }) - ); - const el = result.getByText("My Custom Label"); - expect(el).toBeTruthy(); - }); - - test("show_label: true makes the label visible", async () => { - const result = await render( - component, - make_props({ label: "Visible Label", show_label: true }) - ); - const el = result.getByText("Visible Label"); - expect(el).toBeVisible(); - }); - - test("show_label: false hides the label visually but keeps it in the DOM", async () => { - const result = await render( - component, - make_props({ label: "Hidden Label", show_label: false }) - ); - const el = result.getByText("Hidden Label"); - // The label remains in the DOM for screen readers via sr-only. - // sr-only uses clip/1px dimensions rather than display:none, - // so toBeVisible() won't catch it. We check the class directly. - expect(el.closest("[data-testid='block-info']")).toHaveClass("sr-only"); - }); - } - - if (has_validation_error) { - test("validation_error displays error text visibly", async () => { - const result = await render( - component, - make_props({ - validation_error: "This field is required", - show_validation_error: true - }) - ); - const el = result.getByText("This field is required"); - expect(el).toBeVisible(); - }); - } - }); -} diff --git a/6.14.1/upload/package.json b/6.14.1/upload/package.json deleted file mode 100644 index e69e58a5663f9425f287d6f4133191513f431980..0000000000000000000000000000000000000000 --- a/6.14.1/upload/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@gradio/upload", - "version": "0.17.9", - "description": "Gradio UI packages", - "type": "module", - "main": "src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./src/index.ts", - "svelte": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - } - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/upload" - } -} diff --git a/6.14.1/upload/src/ModifyUpload.svelte b/6.14.1/upload/src/ModifyUpload.svelte deleted file mode 100644 index 7c8db47405576b3b590d9bcb394d5e5848f7e240..0000000000000000000000000000000000000000 --- a/6.14.1/upload/src/ModifyUpload.svelte +++ /dev/null @@ -1,61 +0,0 @@ - - - - {#if editable} - onedit?.()} - /> - {/if} - - {#if undoable} - onundo?.()} - /> - {/if} - - {#if download} - - - - {/if} - - {#if children}{@render children()}{/if} - - { - onclear?.(); - event.stopPropagation(); - }} - /> - diff --git a/6.14.1/upload/src/Upload.svelte b/6.14.1/upload/src/Upload.svelte deleted file mode 100644 index 27183d59b8604ce79d9e90d44269ffb32bdb7225..0000000000000000000000000000000000000000 --- a/6.14.1/upload/src/Upload.svelte +++ /dev/null @@ -1,398 +0,0 @@ - - -{#if filetype === "clipboard"} - -{:else if uploading && show_progress} - {#if !hidden} - - {/if} -{:else} - -{/if} - - diff --git a/6.14.1/upload/src/UploadProgress.svelte b/6.14.1/upload/src/UploadProgress.svelte deleted file mode 100644 index 0ee9995f6d036d79048aca2705d530d3453ae7a1..0000000000000000000000000000000000000000 --- a/6.14.1/upload/src/UploadProgress.svelte +++ /dev/null @@ -1,199 +0,0 @@ - - -
- Uploading {files_with_progress.length} - {files_with_progress.length > 1 ? "files" : "file"}... - - {#if file_to_display} -
- -
- {getProgress(file_to_display)} -
-
- - {file_to_display.orig_name} - -
- {/if} -
- - diff --git a/6.14.1/upload/src/index.ts b/6.14.1/upload/src/index.ts deleted file mode 100644 index 0c2bdb5d7b2eb9c39953af027ae57cc674a0e377..0000000000000000000000000000000000000000 --- a/6.14.1/upload/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Upload } from "./Upload.svelte"; -export { default as ModifyUpload } from "./ModifyUpload.svelte"; -export { default as UploadProgress } from "./UploadProgress.svelte"; -export { create_drag } from "./utils"; diff --git a/6.14.1/upload/src/utils.ts b/6.14.1/upload/src/utils.ts deleted file mode 100644 index e961b85f75d154896c4be1656ed4e383bae0305b..0000000000000000000000000000000000000000 --- a/6.14.1/upload/src/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -interface DragActionOptions { - disable_click?: boolean; - accepted_types?: string | string[] | null; - mode?: "single" | "multiple" | "directory"; - on_drag_change?: (dragging: boolean) => void; - on_files?: (files: File[]) => void; -} - -type ActionReturn = { - update: (new_options: DragActionOptions) => void; - destroy: () => void; -}; - -export function create_drag(): { - drag: (node: HTMLElement, options: DragActionOptions) => ActionReturn; - open_file_upload: () => void; -} { - let hidden_input: HTMLInputElement; - let _options: DragActionOptions; - return { - drag( - node: HTMLElement, - options: DragActionOptions = {} - ): { - update: (new_options: DragActionOptions) => void; - destroy: () => void; - } { - _options = options; - - // Create and configure hidden file input - function setup_hidden_input(): void { - hidden_input = document.createElement("input"); - hidden_input.type = "file"; - hidden_input.style.display = "none"; - hidden_input.setAttribute("aria-label", "File upload"); - hidden_input.setAttribute("data-testid", "file-upload"); - const accept_options = Array.isArray(_options.accepted_types) - ? _options.accepted_types.join(",") - : _options.accepted_types || undefined; - - if (accept_options) { - hidden_input.accept = accept_options; - } - - hidden_input.multiple = _options.mode === "multiple" || false; - if (_options.mode === "directory") { - hidden_input.webkitdirectory = true; - hidden_input.setAttribute("directory", ""); - hidden_input.setAttribute("mozdirectory", ""); - } - node.appendChild(hidden_input); - } - - setup_hidden_input(); - - function handle_drag(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - } - - function handle_drag_enter(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(true); - } - - function handle_drag_leave(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - } - - function handle_drop(e: DragEvent): void { - e.preventDefault(); - e.stopPropagation(); - _options.on_drag_change?.(false); - - if (!e.dataTransfer?.files) return; - const files = Array.from(e.dataTransfer.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - - function handle_click(): void { - if (!_options.disable_click) { - hidden_input.value = ""; - hidden_input.click(); - } - } - - function handle_file_input_change(): void { - if (hidden_input.files) { - const files = Array.from(hidden_input.files); - if (files.length > 0) { - _options.on_files?.(files); - } - } - } - - // Add all event listeners - node.addEventListener("drag", handle_drag); - node.addEventListener("dragstart", handle_drag); - node.addEventListener("dragend", handle_drag); - node.addEventListener("dragover", handle_drag); - node.addEventListener("dragenter", handle_drag_enter); - node.addEventListener("dragleave", handle_drag_leave); - node.addEventListener("drop", handle_drop); - node.addEventListener("click", handle_click); - hidden_input!.addEventListener("change", handle_file_input_change); - - return { - update(new_options: DragActionOptions) { - _options = new_options; - // Recreate hidden input with new options - hidden_input.remove(); - setup_hidden_input(); - hidden_input.addEventListener("change", handle_file_input_change); - }, - destroy() { - node.removeEventListener("drag", handle_drag); - node.removeEventListener("dragstart", handle_drag); - node.removeEventListener("dragend", handle_drag); - node.removeEventListener("dragover", handle_drag); - node.removeEventListener("dragenter", handle_drag_enter); - node.removeEventListener("dragleave", handle_drag_leave); - node.removeEventListener("drop", handle_drop); - node.removeEventListener("click", handle_click); - hidden_input.removeEventListener("change", handle_file_input_change); - hidden_input.remove(); - } - }; - }, - open_file_upload(): void { - if (hidden_input) { - hidden_input.value = ""; - hidden_input.click(); - } - } - }; -} diff --git a/6.14.1/uploadbutton/Index.svelte b/6.14.1/uploadbutton/Index.svelte deleted file mode 100644 index f246c8f96ea948a81cd7bcd7a2412b089ebbaea1..0000000000000000000000000000000000000000 --- a/6.14.1/uploadbutton/Index.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - gradio.dispatch("click")} - onchange={(detail) => handle_event(detail, "change")} - onupload={(detail) => handle_event(detail, "upload")} - onerror={(detail) => { - gradio.dispatch("error", detail); - }} - upload={(...args) => gradio.shared.client.upload(...args)} -> - {gradio.shared.label ?? ""} - diff --git a/6.14.1/uploadbutton/package.json b/6.14.1/uploadbutton/package.json deleted file mode 100644 index 657726b0534b1c5731cdf917e9d630aa45093a12..0000000000000000000000000000000000000000 --- a/6.14.1/uploadbutton/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@gradio/uploadbutton", - "version": "0.9.18", - "description": "Gradio UI packages", - "type": "module", - "author": "", - "license": "ISC", - "private": false, - "main_changeset": true, - "exports": { - ".": { - "gradio": "./Index.svelte", - "svelte": "./dist/Index.svelte", - "types": "./dist/Index.svelte.d.ts" - }, - "./package.json": "./package.json" - }, - "main": "./Index.svelte", - "dependencies": { - "@gradio/button": "workspace:^", - "@gradio/client": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^" - }, - "devDependencies": { - "@gradio/preview": "workspace:^" - }, - "peerDependencies": { - "svelte": "^5.48.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/uploadbutton" - } -} diff --git a/6.14.1/uploadbutton/shared/UploadButton.svelte b/6.14.1/uploadbutton/shared/UploadButton.svelte deleted file mode 100644 index 3cb3b534036b7d1fa652fddd293a00c4f5687e03..0000000000000000000000000000000000000000 --- a/6.14.1/uploadbutton/shared/UploadButton.svelte +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - {#if icon} - {`${value} - {/if} - {#if children}{@render children()}{/if} - - - diff --git a/6.14.1/uploadbutton/types.ts b/6.14.1/uploadbutton/types.ts deleted file mode 100644 index 100547b8f9293f9cd2a191b09a6003e7f071a585..0000000000000000000000000000000000000000 --- a/6.14.1/uploadbutton/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface UploadButtonProps { - value: null | FileData | FileData[]; - file_count: string; - file_types: string[]; - size: "sm" | "lg"; - icon: FileData | null; - variant: "primary" | "secondary" | "stop"; -} - -export interface UploadButtonEvents { - change: never; - upload: never; - click: never; - error: string; -} diff --git a/6.14.1/utils/package.json b/6.14.1/utils/package.json deleted file mode 100644 index 97e34911592ce8b15a54ea071d740237220295dc..0000000000000000000000000000000000000000 --- a/6.14.1/utils/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@gradio/utils", - "version": "0.12.2", - "description": "Gradio UI packages", - "type": "module", - "main": "./src/index.ts", - "author": "", - "license": "ISC", - "dependencies": { - "@gradio/theme": "workspace:^", - "svelte-i18n": "^4.0.1" - }, - "main_changeset": true, - "repository": { - "type": "git", - "url": "git+https://github.com/gradio-app/gradio.git", - "directory": "js/utils" - }, - "exports": { - ".": { - "gradio": "./src/index.ts", - "types": "./dist/src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "package": "svelte-package --input=. --tsconfig=../../tsconfig.json" - } -} diff --git a/6.14.1/utils/src/color.ts b/6.14.1/utils/src/color.ts deleted file mode 100644 index 86d3fe6a5c35c450cc6517b5f3d4767ffda1bc2c..0000000000000000000000000000000000000000 --- a/6.14.1/utils/src/color.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { colors, ordered_colors } from "@gradio/theme"; - -export const get_next_color = (index: number): keyof typeof colors => { - return ordered_colors[index % ordered_colors.length]; -}; diff --git a/6.14.1/utils/src/index.ts b/6.14.1/utils/src/index.ts deleted file mode 100644 index 8db07c80fcf3416332b4ec11d86c06a0fdfb7e74..0000000000000000000000000000000000000000 --- a/6.14.1/utils/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./color.js"; -export * from "./utils.svelte.js"; -export * from "./types.js"; diff --git a/6.14.1/utils/src/types.ts b/6.14.1/utils/src/types.ts deleted file mode 100644 index 8dd47a49c34d6da4ce4328aa99f9fe563ecc7d89..0000000000000000000000000000000000000000 --- a/6.14.1/utils/src/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { FileData } from "@gradio/client"; - -export interface CustomButton { - id: number; - value: string | null; - icon: FileData | null; -} diff --git a/6.14.1/utils/src/utils.svelte.ts b/6.14.1/utils/src/utils.svelte.ts deleted file mode 100644 index 1a7d54a3cfac850fd1dedcf10907105b157ade26..0000000000000000000000000000000000000000 --- a/6.14.1/utils/src/utils.svelte.ts +++ /dev/null @@ -1,575 +0,0 @@ -import type { ActionReturn } from "svelte/action"; -import type { Client } from "@gradio/client"; -import type { ComponentType, SvelteComponent } from "svelte"; -import { tick, untrack } from "svelte"; -import type { Component } from "svelte"; -import { locale } from "svelte-i18n"; - -export const I18N_MARKER = "__i18n__"; -const TRANSLATABLE_PROPS = [ - "label", - "info", - "placeholder", - "description", - "title", - "value" -]; - -export interface SharedProps { - elem_id?: string; - elem_classes: string[]; - components?: string[]; - server_fns?: string[]; - interactive: boolean; - visible: boolean | "hidden"; - id: number; - container: boolean; - target: HTMLElement; - theme_mode: "light" | "dark" | "system"; - version: string; - root: string; - autoscroll: boolean; - max_file_size: number | null; - formatter: any; //I18nFormatter; - client: Client; - scale: number; - min_width: number; - padding: number; - load_component: load_component; - loading_status?: any; - label: string; - show_label: boolean; - validation_error?: string | null; - theme?: "light" | "dark"; - show_progress: boolean; - api_prefix: string; - server: ServerFunctions; - attached_events?: string[]; - register_component: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - dispatcher: Function; -} - -export type LoadingComponent = Promise<{ - default: Component; -}>; - -export const GRADIO_ROOT = "GRADIO_ROOT"; - -export interface ValueData { - value: any; - is_value_data: boolean; -} - -export interface SelectData { - row_value?: any[]; - col_value?: any[]; - index: number | [number, number]; - value: any; - selected?: boolean; -} - -export interface LikeData { - index: number | [number, number]; - value: any; - liked?: boolean | string; -} - -export interface KeyUpData { - key: string; - input_value: string; -} - -export interface ShareData { - description: string; - title?: string; -} - -export interface CopyData { - value: string; -} - -export class ShareError extends Error { - constructor(message: string) { - super(message); - this.name = "ShareError"; - } -} - -export async function uploadToHuggingFace( - data: string | { url?: string; path?: string }, - type: "base64" | "url" -): Promise { - if (window.__gradio_space__ == null) { - throw new ShareError("Must be on Spaces to share."); - } - let blob: Blob; - let contentType: string; - let filename: string; - if (type === "url") { - let url: string; - - if (typeof data === "object" && data.url) { - url = data.url; - } else if (typeof data === "string") { - url = data; - } else { - throw new Error("Invalid data format for URL type"); - } - - const response = await fetch(url); - blob = await response.blob(); - contentType = response.headers.get("content-type") || ""; - filename = response.headers.get("content-disposition") || ""; - } else { - let dataurl: string; - - if (typeof data === "object" && data.path) { - dataurl = data.path; - } else if (typeof data === "string") { - dataurl = data; - } else { - throw new Error("Invalid data format for base64 type"); - } - - blob = dataURLtoBlob(dataurl); - contentType = dataurl.split(";")[0].split(":")[1]; - filename = "file." + contentType.split("/")[1]; - } - - const file = new File([blob], filename, { type: contentType }); - - // Send file to endpoint - const uploadResponse = await fetch("https://huggingface.co/uploads", { - method: "POST", - body: file, - headers: { - "Content-Type": file.type, - "X-Requested-With": "XMLHttpRequest" - } - }); - - // Check status of response - if (!uploadResponse.ok) { - if ( - uploadResponse.headers.get("content-type")?.includes("application/json") - ) { - const error = await uploadResponse.json(); - throw new ShareError(`Upload failed: ${error.error}`); - } - throw new ShareError(`Upload failed.`); - } - - // Return response if needed - const result = await uploadResponse.text(); - return result; -} - -function dataURLtoBlob(dataurl: string): Blob { - var arr = dataurl.split(","), - mime = (arr[0].match(/:(.*?);/) as RegExpMatchArray)[1], - bstr = atob(arr[1]), - n = bstr.length, - u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} - -export function copy(node: HTMLDivElement): ActionReturn { - node.addEventListener("click", handle_copy); - - async function handle_copy(event: MouseEvent): Promise { - const path = event.composedPath() as HTMLButtonElement[]; - - const [copy_button] = path.filter( - (e) => e?.tagName === "BUTTON" && e.classList.contains("copy_code_button") - ); - - if (copy_button) { - event.stopImmediatePropagation(); - - const copy_text = copy_button.parentElement!.innerText.trim(); - const copy_sucess_button = Array.from( - copy_button.children - )[1] as HTMLDivElement; - - const copied = await copy_to_clipboard(copy_text); - - if (copied) copy_feedback(copy_sucess_button); - - function copy_feedback(_copy_sucess_button: HTMLDivElement): void { - _copy_sucess_button.style.opacity = "1"; - setTimeout(() => { - _copy_sucess_button.style.opacity = "0"; - }, 2000); - } - } - } - - return { - destroy(): void { - node.removeEventListener("click", handle_copy); - } - }; -} - -async function copy_to_clipboard(value: string): Promise { - let copied = false; - if ("clipboard" in navigator) { - await navigator.clipboard.writeText(value); - copied = true; - } else { - const textArea = document.createElement("textarea"); - textArea.value = value; - - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - copied = true; - } catch (error) { - console.error(error); - copied = false; - } finally { - textArea.remove(); - } - } - - return copied; -} - -export const format_time = (seconds: number): string => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const seconds_remainder = Math.round(seconds) % 60; - const padded_minutes = `${minutes < 10 ? "0" : ""}${minutes}`; - const padded_seconds = `${ - seconds_remainder < 10 ? "0" : "" - }${seconds_remainder}`; - - if (hours > 0) { - return `${hours}:${padded_minutes}:${padded_seconds}`; - } - return `${minutes}:${padded_seconds}`; -}; - -interface Args { - api_url: string; - name: string; - id?: string; - variant: "component" | "example" | "base"; -} - -export type component_loader = (args: Args) => { - component: { - default: ComponentType; - }; -}; - -export type LoadedComponentWithRuntime = { - component: LoadingComponent; - runtime: false | typeof import("svelte"); -}; - -export type load_component = ( - name: string, - variant: "component" | "example" | "base", - component_class_id?: string -) => LoadedComponentWithRuntime; - -const is_browser = typeof window !== "undefined"; - -export type ServerFunctions = Record Promise>; - -export const allowed_shared_props: (keyof SharedProps)[] = [ - "elem_id", - "elem_classes", - "visible", - "interactive", - "server_fns", - "server", - "id", - "target", - "theme_mode", - "version", - "root", - "autoscroll", - "max_file_size", - "formatter", - "client", - "load_component", - "scale", - "min_width", - "theme", - "padding", - "loading_status", - "label", - "show_label", - "validation_error", - "show_progress", - "api_prefix", - "container", - "attached_events", - "register_component", - "dispatcher" -] as const; - -export type I18nFormatter = any; - -export function has_i18n_marker(value: unknown): value is string { - return typeof value === "string" && value.includes(I18N_MARKER); -} - -export function translate_i18n_marker( - value: string, - translate: (key: string) => string -): string { - const start = value.indexOf(I18N_MARKER); - if (start === -1) return value; - - const json_start = start + I18N_MARKER.length; - const json_end = value.indexOf("}", json_start) + 1; - if (json_end === 0) return value; - - try { - const metadata = JSON.parse(value.slice(json_start, json_end)); - if (metadata?.key) { - const translated = translate(metadata.key); - const result = translated !== metadata.key ? translated : metadata.key; - return value.slice(0, start) + result + value.slice(json_end); - } - } catch {} - - return value; -} - -export class Gradio { - load_component: load_component; - shared: SharedProps = $state({} as SharedProps) as SharedProps; - props = $state({} as U) as U; - i18n: I18nFormatter = $state((v: string) => v) as any; - translatable_props: Record = {}; - dispatcher!: Function; - last_update: ReturnType | null = null; - shared_props: (keyof SharedProps)[] = allowed_shared_props; - mounted: boolean = false; - old_value: any; - register_component!: ( - id: number, - set_data: (data: Record & SharedProps) => void, - get_data: Function - ) => void; - - constructor( - _props: { shared_props: SharedProps; props: U }, - default_values?: Partial - ) { - for (const key in _props.shared_props) { - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - - if (default_values) { - for (const key in default_values) { - if (this.props[key as keyof U] === undefined) { - // @ts-ignore - this.props[key] = default_values[key as keyof U]; - } - } - } - // @ts-ignore same here - this.i18n = this.props.i18n ?? ((v: string) => v); - - for (const key of TRANSLATABLE_PROPS) { - // @ts-ignore - this.shared[key] = this._translate_and_store( - "shared", - key, - // @ts-ignore - _props.shared_props[key] - ); - // @ts-ignore - this.props[key] = this._translate_and_store( - "props", - key, - // @ts-ignore - _props.props[key] - ); - } - - this.load_component = this.shared.load_component; - - this.register_component = this.shared.register_component || (() => {}); - this.dispatcher = this.shared.dispatcher || (() => {}); - - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - - $effect(() => { - // Need to update the props here - // otherwise UI won't reflect latest state from render - for (const key in _props.shared_props) { - // @ts-ignore - if (this._is_i18n_managed(`shared.${key}`, _props.shared_props[key])) - continue; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[key] = _props.shared_props[key]; - } - for (const key in _props.props) { - if (this._is_i18n_managed(`props.${key}`, _props.props[key])) continue; - // @ts-ignore same here - this.props[key] = _props.props[key]; - } - this.register_component( - _props.shared_props.id, - // @ts-ignore - this.set_data.bind(this), - this.get_data.bind(this) - ); - untrack(() => { - this.shared.id = _props.shared_props.id; - }); - }); - - // retranslate props when locale changes - if (Object.keys(this.translatable_props).length > 0) { - locale.subscribe(() => { - for (const [full_key, original] of Object.entries( - this.translatable_props - )) { - const [target, key] = full_key.split("."); - const translated = this.i18n(original); - // @ts-ignore - if (target === "shared") this.shared[key] = translated; - // @ts-ignore - else this.props[key] = translated; - } - }); - } - } - - // check if props are translatable - _is_i18n_managed(key: string, new_value: unknown): boolean { - const original_marker = this.translatable_props[key]; - if (!original_marker) return false; - if (new_value === original_marker) return true; - // if value has changed then remove key - delete this.translatable_props[key]; - return false; - } - - _translate_and_store( - target: "shared" | "props", - key: string, - value: unknown - ): unknown { - if (typeof value !== "string") return value; - const translated = this.i18n(value); - if (translated !== value) { - this.translatable_props[`${target}.${key}`] = value; - } - return translated; - } - - dispatch(event_name: E, data?: T[E]): void { - this.dispatcher(this.shared.id, event_name, data); - } - - async get_data() { - return $state.snapshot(this.props); - } - - update(data: Partial): void { - this.set_data(data as U & SharedProps); - } - - set_data(data: Partial): void { - for (const key in data) { - // @ts-ignore - const value = data[key]; - const translated = has_i18n_marker(value) - ? this._translate_and_store( - this.shared_props.includes(key as keyof SharedProps) - ? "shared" - : "props", - key, - value - ) - : value; - - if (this.shared_props.includes(key as keyof SharedProps)) { - const _key = key as keyof SharedProps; - // @ts-ignore i'm not doing pointless typescript gymanstics - this.shared[_key] = translated; - continue; - } - // @ts-ignore - this.props[key] = translated; - } - } - - watch_for_change() { - $effect(() => { - if (!this.mounted) { - // @ts-ignore - this.old_value = this.props.value; - this.mounted = true; - } - // @ts-ignore - if (this.old_value != this.props.value) { - // @ts-ignore - this.old_value = this.props.value; - // @ts-ignore - this.dispatch("change"); - } - }); - } -} - -// function _load_component( -// this: Gradio, -// name: string, -// variant: "component" | "example" | "base" = "component" -// ): ReturnType { -// return this._load_component!({ -// name, -// api_url: this.shared.client.config?.root!, -// variant -// }); -// } - -export const css_units = (dimension_value: string | number): string => { - return typeof dimension_value === "number" - ? dimension_value + "px" - : dimension_value; -}; - -export function should_show_scroll_fade( - container: HTMLElement | null -): boolean { - if (!container) return false; - const has_overflow = container.scrollHeight > container.clientHeight; - const at_bottom = - container.scrollTop >= container.scrollHeight - container.clientHeight - 1; - return has_overflow && !at_bottom; -} - -type MappedProps = { [K in keyof T]: T[K] }; -type MappedProp = { [P in K]: T[P] }; diff --git a/6.14.1/vibeeditor/Index.svelte b/6.14.1/vibeeditor/Index.svelte deleted file mode 100644 index 6db9b3cb7167948ae0f14cabd9d66c791deb9e2d..0000000000000000000000000000000000000000 --- a/6.14.1/vibeeditor/Index.svelte +++ /dev/null @@ -1,764 +0,0 @@ - - -
- -
- - -
- -
- {#if activeTab === "chat"} -
- {#each message_history as message, index} -
-
- - - - {#if !message.isBot && message.hash && !message.isPending} - - {/if} -
-
- {/each} - - {#if message_history.length === 0} -
No messages yet
- {/if} - - {#if message_history.length === 0} -
-
- {#each starterQueries as query} - - {/each} -
-
- {/if} -
- {:else if activeTab === "code"} -
-
- -
- - -
- {/if} -
- -
-
Powered by: gpt-oss
-