Gradio Frontend
#1
by tabrezahmed51 - opened
This view is limited to 50 files because it contains too many changes. See the raw diff here.
- 6.11.0/atoms/package.json +1 -0
- 6.11.0/atoms/src/BlockTitle.svelte +1 -2
- 6.11.0/atoms/src/Info.svelte +8 -14
- 6.11.0/atoms/src/inline-markdown.ts +0 -40
- 6.11.0/gallery/shared/Gallery.svelte +7 -5
- 6.11.0/preview/package.json +1 -1
- 6.11.0/preview/src/build.ts +8 -12
- 6.11.1/accordion/Index.svelte +0 -62
- 6.11.1/accordion/package.json +0 -34
- 6.11.1/accordion/shared/Accordion.svelte +0 -55
- 6.11.1/accordion/types.ts +0 -9
- 6.11.1/annotatedimage/Index.svelte +0 -195
- 6.11.1/annotatedimage/package.json +0 -37
- 6.11.1/annotatedimage/types.ts +0 -27
- 6.11.1/atoms/package.json +0 -33
- 6.11.1/atoms/src/Block.svelte +0 -256
- 6.11.1/atoms/src/BlockLabel.svelte +0 -90
- 6.11.1/atoms/src/BlockTitle.svelte +0 -64
- 6.11.1/atoms/src/CustomButton.svelte +0 -45
- 6.11.1/atoms/src/DownloadLink.svelte +0 -39
- 6.11.1/atoms/src/Empty.svelte +0 -63
- 6.11.1/atoms/src/FullscreenButton.svelte +0 -26
- 6.11.1/atoms/src/IconButton.svelte +0 -161
- 6.11.1/atoms/src/IconButtonWrapper.svelte +0 -116
- 6.11.1/atoms/src/Info.svelte +0 -28
- 6.11.1/atoms/src/ScrollFade.svelte +0 -37
- 6.11.1/atoms/src/SelectSource.svelte +0 -112
- 6.11.1/atoms/src/ShareButton.svelte +0 -39
- 6.11.1/atoms/src/Toolbar.svelte +0 -28
- 6.11.1/atoms/src/UploadText.svelte +0 -102
- 6.11.1/atoms/src/index.ts +0 -17
- 6.11.1/atoms/src/inline-markdown.ts +0 -40
- 6.11.1/atoms/src/utils/parse_placeholder.ts +0 -27
- 6.11.1/audio/Example.svelte +0 -25
- 6.11.1/audio/Index.svelte +0 -234
- 6.11.1/audio/index.ts +0 -7
- 6.11.1/audio/interactive/InteractiveAudio.svelte +0 -431
- 6.11.1/audio/package.json +0 -60
- 6.11.1/audio/player/AudioPlayer.svelte +0 -525
- 6.11.1/audio/recorder/AudioRecorder.svelte +0 -315
- 6.11.1/audio/shared/Audio.svelte +0 -17
- 6.11.1/audio/shared/DeviceSelect.svelte +0 -73
- 6.11.1/audio/shared/MinimalAudioPlayer.svelte +0 -190
- 6.11.1/audio/shared/MinimalAudioRecorder.svelte +0 -379
- 6.11.1/audio/shared/VolumeControl.svelte +0 -86
- 6.11.1/audio/shared/VolumeLevels.svelte +0 -13
- 6.11.1/audio/shared/WaveformControls.svelte +0 -496
- 6.11.1/audio/shared/WaveformRecordControls.svelte +0 -311
- 6.11.1/audio/shared/audioBufferToWav.ts +0 -59
- 6.11.1/audio/shared/index.ts +0 -3
6.11.0/atoms/package.json
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
"license": "ISC",
|
| 9 |
"dependencies": {
|
| 10 |
"@gradio/icons": "workspace:^",
|
|
|
|
| 11 |
"@gradio/utils": "workspace:^"
|
| 12 |
},
|
| 13 |
"peerDependencies": {
|
|
|
|
| 8 |
"license": "ISC",
|
| 9 |
"dependencies": {
|
| 10 |
"@gradio/icons": "workspace:^",
|
| 11 |
+
"@gradio/markdown-code": "workspace:^",
|
| 12 |
"@gradio/utils": "workspace:^"
|
| 13 |
},
|
| 14 |
"peerDependencies": {
|
6.11.0/atoms/src/BlockTitle.svelte
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import Info from "./Info.svelte";
|
| 3 |
-
|
| 4 |
export let show_label = true;
|
| 5 |
export let info: string | undefined = undefined;
|
| 6 |
export let rtl = false;
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { default as Info } from "./Info.svelte";
|
|
|
|
| 3 |
export let show_label = true;
|
| 4 |
export let info: string | undefined = undefined;
|
| 5 |
export let rtl = false;
|
6.11.0/atoms/src/Info.svelte
CHANGED
|
@@ -1,28 +1,22 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import {
|
| 3 |
export let info: string;
|
| 4 |
</script>
|
| 5 |
|
| 6 |
-
<div
|
| 7 |
-
|
| 8 |
</div>
|
| 9 |
|
| 10 |
<style>
|
| 11 |
-
.
|
| 12 |
font-weight: var(--block-info-text-weight);
|
| 13 |
font-size: var(--block-info-text-size);
|
| 14 |
line-height: var(--line-sm);
|
| 15 |
-
color: var(--block-info-text-color);
|
| 16 |
-
margin-bottom: var(--spacing-md);
|
| 17 |
}
|
| 18 |
-
|
| 19 |
-
color: var(--
|
| 20 |
-
text-decoration: underline;
|
| 21 |
}
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
padding: 0.1em 0.3em;
|
| 25 |
-
border-radius: 3px;
|
| 26 |
-
font-size: 0.9em;
|
| 27 |
}
|
| 28 |
</style>
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { MarkdownCode as Markdown } from "@gradio/markdown-code";
|
| 3 |
export let info: string;
|
| 4 |
</script>
|
| 5 |
|
| 6 |
+
<div>
|
| 7 |
+
<Markdown message={info} sanitize_html={true} />
|
| 8 |
</div>
|
| 9 |
|
| 10 |
<style>
|
| 11 |
+
div > :global(.md.prose) {
|
| 12 |
font-weight: var(--block-info-text-weight);
|
| 13 |
font-size: var(--block-info-text-size);
|
| 14 |
line-height: var(--line-sm);
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
+
div > :global(.md.prose *) {
|
| 17 |
+
color: var(--block-info-text-color);
|
|
|
|
| 18 |
}
|
| 19 |
+
div {
|
| 20 |
+
margin-bottom: var(--spacing-md);
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
</style>
|
6.11.0/atoms/src/inline-markdown.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
export const INLINE_CODE_RE = /`([^`]+)`/g;
|
| 2 |
-
export const LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g;
|
| 3 |
-
export const BOLD_ASTERISK_RE = /\*\*(.+?)\*\*/g;
|
| 4 |
-
export const BOLD_UNDERSCORE_RE = /__(.+?)__/g;
|
| 5 |
-
export const ITALIC_ASTERISK_RE = /\*(.+?)\*/g;
|
| 6 |
-
export const ITALIC_UNDERSCORE_RE = /(?<!\w)_(.+?)_(?!\w)/g;
|
| 7 |
-
export const PROTOCOL_RE = /^\w+:/;
|
| 8 |
-
|
| 9 |
-
export function escape_html(text: string): string {
|
| 10 |
-
return text
|
| 11 |
-
.replace(/&/g, "&")
|
| 12 |
-
.replace(/</g, "<")
|
| 13 |
-
.replace(/>/g, ">")
|
| 14 |
-
.replace(/"/g, """);
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
function render_link(_match: string, text: string, url: string): string {
|
| 18 |
-
const trimmed = url.trim();
|
| 19 |
-
if (PROTOCOL_RE.test(trimmed)) {
|
| 20 |
-
if (/^https?:/i.test(trimmed)) {
|
| 21 |
-
return `<a href="${trimmed}" target="_blank" rel="noopener noreferrer">${text}</a>`;
|
| 22 |
-
}
|
| 23 |
-
return text;
|
| 24 |
-
}
|
| 25 |
-
return `<a href="${trimmed}" target="_blank" rel="noopener noreferrer">${text}</a>`;
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
export function render_inline_markdown(text: string): string {
|
| 29 |
-
let result = escape_html(text);
|
| 30 |
-
|
| 31 |
-
result = result.replace(INLINE_CODE_RE, "<code>$1</code>");
|
| 32 |
-
result = result.replace(LINK_RE, render_link);
|
| 33 |
-
result = result.replace(BOLD_ASTERISK_RE, "<strong>$1</strong>");
|
| 34 |
-
result = result.replace(BOLD_UNDERSCORE_RE, "<strong>$1</strong>");
|
| 35 |
-
result = result.replace(ITALIC_ASTERISK_RE, "<em>$1</em>");
|
| 36 |
-
result = result.replace(ITALIC_UNDERSCORE_RE, "<em>$1</em>");
|
| 37 |
-
result = result.replace(/\n/g, "<br>");
|
| 38 |
-
|
| 39 |
-
return result;
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.0/gallery/shared/Gallery.svelte
CHANGED
|
@@ -229,13 +229,15 @@
|
|
| 229 |
}
|
| 230 |
|
| 231 |
$effect(() => {
|
| 232 |
-
// Only trigger the effect if the selected_index has actually changed
|
| 233 |
if (selected_index !== old_selected_index) {
|
| 234 |
old_selected_index = selected_index;
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
| 239 |
onselect({
|
| 240 |
index: selected_index,
|
| 241 |
value: resolved_value?.[selected_index]
|
|
|
|
| 229 |
}
|
| 230 |
|
| 231 |
$effect(() => {
|
|
|
|
| 232 |
if (selected_index !== old_selected_index) {
|
| 233 |
old_selected_index = selected_index;
|
| 234 |
+
if (selected_index !== null) {
|
| 235 |
+
if (resolved_value != null) {
|
| 236 |
+
selected_index = Math.max(
|
| 237 |
+
0,
|
| 238 |
+
Math.min(selected_index, resolved_value.length - 1)
|
| 239 |
+
);
|
| 240 |
+
}
|
| 241 |
onselect({
|
| 242 |
index: selected_index,
|
| 243 |
value: resolved_value?.[selected_index]
|
6.11.0/preview/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/preview",
|
| 3 |
-
"version": "0.16.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"main": "dist/index.js",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/preview",
|
| 3 |
+
"version": "0.16.1",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"main": "dist/index.js",
|
6.11.0/preview/src/build.ts
CHANGED
|
@@ -74,18 +74,14 @@ export async function make_build({
|
|
| 74 |
join(source_dir, pkg.exports["."].gradio)
|
| 75 |
]
|
| 76 |
],
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
]
|
| 86 |
-
]
|
| 87 |
-
: [])
|
| 88 |
-
];
|
| 89 |
|
| 90 |
for (const [out_path, entry_path] of exports) {
|
| 91 |
try {
|
|
|
|
| 74 |
join(source_dir, pkg.exports["."].gradio)
|
| 75 |
]
|
| 76 |
],
|
| 77 |
+
[
|
| 78 |
+
join(template_dir, "example"),
|
| 79 |
+
[
|
| 80 |
+
join(__dirname, "svelte_runtime_entry.js"),
|
| 81 |
+
join(source_dir, pkg.exports["./example"].gradio)
|
| 82 |
+
]
|
| 83 |
+
]
|
| 84 |
+
].filter(([_, path]) => !!path);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
for (const [out_path, entry_path] of exports) {
|
| 87 |
try {
|
6.11.1/accordion/Index.svelte
DELETED
|
@@ -1,62 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import Accordion from "./shared/Accordion.svelte";
|
| 3 |
-
import { Block } from "@gradio/atoms";
|
| 4 |
-
import { StatusTracker } from "@gradio/statustracker";
|
| 5 |
-
|
| 6 |
-
import { BaseColumn } from "@gradio/column";
|
| 7 |
-
import { Gradio } from "@gradio/utils";
|
| 8 |
-
import type { SharedProps } from "@gradio/utils";
|
| 9 |
-
|
| 10 |
-
import type { AccordionProps, AccordionEvents } from "./types";
|
| 11 |
-
|
| 12 |
-
let props = $props();
|
| 13 |
-
class AccordionGradio extends Gradio<AccordionEvents, AccordionProps> {
|
| 14 |
-
set_data(data: Partial<object & SharedProps>): void {
|
| 15 |
-
if ("open" in data && data.open !== this.props.open) {
|
| 16 |
-
if (data.open) {
|
| 17 |
-
this.dispatch("expand");
|
| 18 |
-
this.dispatch("gradio_expand");
|
| 19 |
-
} else {
|
| 20 |
-
this.dispatch("collapse");
|
| 21 |
-
}
|
| 22 |
-
}
|
| 23 |
-
super.set_data(data);
|
| 24 |
-
this.shared.loading_status.status = "complete";
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
-
const gradio = new AccordionGradio(props);
|
| 28 |
-
|
| 29 |
-
let label = $derived(gradio.shared.label || "");
|
| 30 |
-
|
| 31 |
-
let visibility: boolean | "hidden" = $derived(
|
| 32 |
-
gradio.shared.visible === true ? true : "hidden"
|
| 33 |
-
);
|
| 34 |
-
</script>
|
| 35 |
-
|
| 36 |
-
<Block
|
| 37 |
-
elem_id={gradio.shared.elem_id}
|
| 38 |
-
elem_classes={gradio.shared.elem_classes}
|
| 39 |
-
visible={visibility}
|
| 40 |
-
>
|
| 41 |
-
{#if gradio.shared.loading_status}
|
| 42 |
-
<StatusTracker
|
| 43 |
-
autoscroll={gradio.shared.autoscroll}
|
| 44 |
-
i18n={gradio.i18n}
|
| 45 |
-
{...gradio.shared.loading_status}
|
| 46 |
-
/>
|
| 47 |
-
{/if}
|
| 48 |
-
|
| 49 |
-
<Accordion
|
| 50 |
-
{label}
|
| 51 |
-
open={gradio.props.open}
|
| 52 |
-
onexpand={() => {
|
| 53 |
-
gradio.dispatch("expand");
|
| 54 |
-
gradio.dispatch("gradio_expand");
|
| 55 |
-
}}
|
| 56 |
-
oncollapse={() => gradio.dispatch("collapse")}
|
| 57 |
-
>
|
| 58 |
-
<BaseColumn>
|
| 59 |
-
<slot />
|
| 60 |
-
</BaseColumn>
|
| 61 |
-
</Accordion>
|
| 62 |
-
</Block>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/accordion/package.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "@gradio/accordion",
|
| 3 |
-
"version": "0.5.34",
|
| 4 |
-
"description": "Gradio UI packages",
|
| 5 |
-
"type": "module",
|
| 6 |
-
"author": "",
|
| 7 |
-
"license": "ISC",
|
| 8 |
-
"main_changeset": true,
|
| 9 |
-
"dependencies": {
|
| 10 |
-
"@gradio/atoms": "workspace:^",
|
| 11 |
-
"@gradio/column": "workspace:^",
|
| 12 |
-
"@gradio/statustracker": "workspace:^",
|
| 13 |
-
"@gradio/utils": "workspace:^"
|
| 14 |
-
},
|
| 15 |
-
"peerDependencies": {
|
| 16 |
-
"svelte": "^5.48.0"
|
| 17 |
-
},
|
| 18 |
-
"devDependencies": {
|
| 19 |
-
"@gradio/preview": "workspace:^"
|
| 20 |
-
},
|
| 21 |
-
"exports": {
|
| 22 |
-
".": {
|
| 23 |
-
"gradio": "./Index.svelte",
|
| 24 |
-
"svelte": "./dist/Index.svelte",
|
| 25 |
-
"types": "./dist/Index.svelte.d.ts"
|
| 26 |
-
},
|
| 27 |
-
"./package.json": "./package.json"
|
| 28 |
-
},
|
| 29 |
-
"repository": {
|
| 30 |
-
"type": "git",
|
| 31 |
-
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 32 |
-
"directory": "js/accordion"
|
| 33 |
-
}
|
| 34 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/accordion/shared/Accordion.svelte
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
let {
|
| 3 |
-
open = $bindable(true),
|
| 4 |
-
label = "",
|
| 5 |
-
onexpand,
|
| 6 |
-
oncollapse
|
| 7 |
-
}: {
|
| 8 |
-
open: boolean;
|
| 9 |
-
label: string;
|
| 10 |
-
onexpand?: () => void;
|
| 11 |
-
oncollapse?: () => void;
|
| 12 |
-
} = $props();
|
| 13 |
-
</script>
|
| 14 |
-
|
| 15 |
-
<button
|
| 16 |
-
onclick={() => {
|
| 17 |
-
open = !open;
|
| 18 |
-
if (open) {
|
| 19 |
-
onexpand?.();
|
| 20 |
-
} else {
|
| 21 |
-
oncollapse?.();
|
| 22 |
-
}
|
| 23 |
-
}}
|
| 24 |
-
class="label-wrap"
|
| 25 |
-
class:open
|
| 26 |
-
>
|
| 27 |
-
<span>{label}</span>
|
| 28 |
-
<span style:transform={open ? "rotate(0)" : "rotate(90deg)"} class="icon">
|
| 29 |
-
▼
|
| 30 |
-
</span>
|
| 31 |
-
</button>
|
| 32 |
-
<div data-testid="accordion-content" style:display={open ? "block" : "none"}>
|
| 33 |
-
<slot />
|
| 34 |
-
</div>
|
| 35 |
-
|
| 36 |
-
<style>
|
| 37 |
-
span {
|
| 38 |
-
font-weight: var(--section-header-text-weight);
|
| 39 |
-
font-size: var(--section-header-text-size);
|
| 40 |
-
}
|
| 41 |
-
.label-wrap {
|
| 42 |
-
display: flex;
|
| 43 |
-
justify-content: space-between;
|
| 44 |
-
cursor: pointer;
|
| 45 |
-
width: var(--size-full);
|
| 46 |
-
color: var(--accordion-text-color);
|
| 47 |
-
}
|
| 48 |
-
.label-wrap.open {
|
| 49 |
-
margin-bottom: var(--size-2);
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
.icon {
|
| 53 |
-
transition: 150ms;
|
| 54 |
-
}
|
| 55 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/accordion/types.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
export interface AccordionProps {
|
| 2 |
-
open: boolean;
|
| 3 |
-
}
|
| 4 |
-
|
| 5 |
-
export interface AccordionEvents {
|
| 6 |
-
expand: never;
|
| 7 |
-
collapse: never;
|
| 8 |
-
gradio_expand: never;
|
| 9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/annotatedimage/Index.svelte
DELETED
|
@@ -1,195 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import {
|
| 3 |
-
Block,
|
| 4 |
-
BlockLabel,
|
| 5 |
-
Empty,
|
| 6 |
-
IconButtonWrapper,
|
| 7 |
-
FullscreenButton
|
| 8 |
-
} from "@gradio/atoms";
|
| 9 |
-
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 10 |
-
import { Image } from "@gradio/icons";
|
| 11 |
-
import { StatusTracker } from "@gradio/statustracker";
|
| 12 |
-
import { Gradio } from "@gradio/utils";
|
| 13 |
-
import type { AnnotatedImageProps, AnnotatedImageEvents } from "./types";
|
| 14 |
-
|
| 15 |
-
const props = $props();
|
| 16 |
-
const gradio = new Gradio<AnnotatedImageEvents, AnnotatedImageProps>(props);
|
| 17 |
-
|
| 18 |
-
let active: string | null = $state(null);
|
| 19 |
-
let image_container: HTMLElement;
|
| 20 |
-
let fullscreen = $state(false);
|
| 21 |
-
let label = $derived(
|
| 22 |
-
gradio.shared.label || gradio.i18n("annotated_image.annotated_image")
|
| 23 |
-
);
|
| 24 |
-
|
| 25 |
-
gradio.watch_for_change();
|
| 26 |
-
|
| 27 |
-
function handle_mouseover(_label: string): void {
|
| 28 |
-
active = _label;
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
function handle_mouseout(): void {
|
| 32 |
-
active = null;
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
function handle_click(i: number, value: string): void {
|
| 36 |
-
gradio.dispatch("select", {
|
| 37 |
-
value: value,
|
| 38 |
-
index: i
|
| 39 |
-
});
|
| 40 |
-
}
|
| 41 |
-
</script>
|
| 42 |
-
|
| 43 |
-
<Block
|
| 44 |
-
visible={gradio.shared.visible}
|
| 45 |
-
elem_id={gradio.shared.elem_id}
|
| 46 |
-
elem_classes={gradio.shared.elem_classes}
|
| 47 |
-
padding={false}
|
| 48 |
-
height={gradio.props.height}
|
| 49 |
-
width={gradio.props.width}
|
| 50 |
-
allow_overflow={false}
|
| 51 |
-
container={gradio.shared.container}
|
| 52 |
-
scale={gradio.shared.scale}
|
| 53 |
-
min_width={gradio.shared.min_width}
|
| 54 |
-
bind:fullscreen
|
| 55 |
-
>
|
| 56 |
-
<StatusTracker
|
| 57 |
-
autoscroll={gradio.shared.autoscroll}
|
| 58 |
-
i18n={gradio.i18n}
|
| 59 |
-
{...gradio.shared.loading_status}
|
| 60 |
-
/>
|
| 61 |
-
<BlockLabel show_label={gradio.shared.show_label} Icon={Image} {label} />
|
| 62 |
-
|
| 63 |
-
<div class="container">
|
| 64 |
-
{#if gradio.props.value == null}
|
| 65 |
-
<Empty size="large" unpadded_box={true}><Image /></Empty>
|
| 66 |
-
{:else}
|
| 67 |
-
<div class="image-container" bind:this={image_container}>
|
| 68 |
-
<IconButtonWrapper
|
| 69 |
-
buttons={gradio.props.buttons || []}
|
| 70 |
-
on_custom_button_click={(id) => {
|
| 71 |
-
gradio.dispatch("custom_button_click", { id });
|
| 72 |
-
}}
|
| 73 |
-
>
|
| 74 |
-
{#if (gradio.props.buttons || []).some((btn) => typeof btn === "string" && btn === "fullscreen")}
|
| 75 |
-
<FullscreenButton
|
| 76 |
-
{fullscreen}
|
| 77 |
-
on:fullscreen={({ detail }) => {
|
| 78 |
-
fullscreen = detail;
|
| 79 |
-
}}
|
| 80 |
-
/>
|
| 81 |
-
{/if}
|
| 82 |
-
</IconButtonWrapper>
|
| 83 |
-
|
| 84 |
-
<img
|
| 85 |
-
class="base-image"
|
| 86 |
-
class:fit-height={gradio.props.height && !fullscreen}
|
| 87 |
-
src={gradio.props.value ? gradio.props.value.image.url : null}
|
| 88 |
-
alt="the base file that is annotated"
|
| 89 |
-
/>
|
| 90 |
-
{#each gradio.props.value ? gradio.props.value.annotations : [] as ann, i}
|
| 91 |
-
<img
|
| 92 |
-
alt="segmentation mask identifying {gradio.shared
|
| 93 |
-
.label} within the uploaded file"
|
| 94 |
-
class="mask fit-height"
|
| 95 |
-
class:fit-height={!fullscreen}
|
| 96 |
-
class:active={active == ann.label}
|
| 97 |
-
class:inactive={active != ann.label && active != null}
|
| 98 |
-
src={ann.image.url}
|
| 99 |
-
style={gradio.props.color_map && ann.label in gradio.props.color_map
|
| 100 |
-
? null
|
| 101 |
-
: `filter: hue-rotate(${Math.round(
|
| 102 |
-
(i * 360) / (gradio.props.value?.annotations.length ?? 1)
|
| 103 |
-
)}deg);`}
|
| 104 |
-
/>
|
| 105 |
-
{/each}
|
| 106 |
-
</div>
|
| 107 |
-
{#if gradio.props.show_legend && gradio.props.value}
|
| 108 |
-
<div class="legend">
|
| 109 |
-
{#each gradio.props.value.annotations as ann, i}
|
| 110 |
-
<button
|
| 111 |
-
class="legend-item"
|
| 112 |
-
style="background-color: {gradio.props.color_map &&
|
| 113 |
-
ann.label in gradio.props.color_map
|
| 114 |
-
? gradio.props.color_map[ann.label] + '88'
|
| 115 |
-
: `hsla(${Math.round(
|
| 116 |
-
(i * 360) / gradio.props.value.annotations.length
|
| 117 |
-
)}, 100%, 50%, 0.3)`}"
|
| 118 |
-
on:mouseover={() => handle_mouseover(ann.label)}
|
| 119 |
-
on:focus={() => handle_mouseover(ann.label)}
|
| 120 |
-
on:mouseout={() => handle_mouseout()}
|
| 121 |
-
on:blur={() => handle_mouseout()}
|
| 122 |
-
on:click={() => handle_click(i, ann.label)}
|
| 123 |
-
>
|
| 124 |
-
{ann.label}
|
| 125 |
-
</button>
|
| 126 |
-
{/each}
|
| 127 |
-
</div>
|
| 128 |
-
{/if}
|
| 129 |
-
{/if}
|
| 130 |
-
</div>
|
| 131 |
-
</Block>
|
| 132 |
-
|
| 133 |
-
<style>
|
| 134 |
-
.base-image {
|
| 135 |
-
display: block;
|
| 136 |
-
width: 100%;
|
| 137 |
-
height: auto;
|
| 138 |
-
}
|
| 139 |
-
.container {
|
| 140 |
-
display: flex;
|
| 141 |
-
position: relative;
|
| 142 |
-
flex-direction: column;
|
| 143 |
-
justify-content: center;
|
| 144 |
-
align-items: center;
|
| 145 |
-
width: var(--size-full);
|
| 146 |
-
height: var(--size-full);
|
| 147 |
-
}
|
| 148 |
-
.image-container {
|
| 149 |
-
position: relative;
|
| 150 |
-
top: 0;
|
| 151 |
-
left: 0;
|
| 152 |
-
flex-grow: 1;
|
| 153 |
-
width: 100%;
|
| 154 |
-
overflow: hidden;
|
| 155 |
-
}
|
| 156 |
-
.fit-height {
|
| 157 |
-
top: 0;
|
| 158 |
-
left: 0;
|
| 159 |
-
width: 100%;
|
| 160 |
-
height: 100%;
|
| 161 |
-
object-fit: contain;
|
| 162 |
-
}
|
| 163 |
-
.mask {
|
| 164 |
-
opacity: 0.85;
|
| 165 |
-
transition: all 0.2s ease-in-out;
|
| 166 |
-
position: absolute;
|
| 167 |
-
}
|
| 168 |
-
.image-container:hover .mask {
|
| 169 |
-
opacity: 0.3;
|
| 170 |
-
}
|
| 171 |
-
.mask.active {
|
| 172 |
-
opacity: 1;
|
| 173 |
-
}
|
| 174 |
-
.mask.inactive {
|
| 175 |
-
opacity: 0;
|
| 176 |
-
}
|
| 177 |
-
.legend {
|
| 178 |
-
display: flex;
|
| 179 |
-
flex-direction: row;
|
| 180 |
-
flex-wrap: wrap;
|
| 181 |
-
align-content: center;
|
| 182 |
-
justify-content: center;
|
| 183 |
-
align-items: center;
|
| 184 |
-
gap: var(--spacing-sm);
|
| 185 |
-
padding: var(--spacing-sm);
|
| 186 |
-
}
|
| 187 |
-
.legend-item {
|
| 188 |
-
display: flex;
|
| 189 |
-
flex-direction: row;
|
| 190 |
-
align-items: center;
|
| 191 |
-
cursor: pointer;
|
| 192 |
-
border-radius: var(--radius-sm);
|
| 193 |
-
padding: var(--spacing-sm);
|
| 194 |
-
}
|
| 195 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/annotatedimage/package.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "@gradio/annotatedimage",
|
| 3 |
-
"version": "0.11.7",
|
| 4 |
-
"description": "Gradio UI packages",
|
| 5 |
-
"type": "module",
|
| 6 |
-
"author": "",
|
| 7 |
-
"license": "ISC",
|
| 8 |
-
"private": false,
|
| 9 |
-
"main_changeset": true,
|
| 10 |
-
"exports": {
|
| 11 |
-
".": {
|
| 12 |
-
"gradio": "./Index.svelte",
|
| 13 |
-
"svelte": "./dist/Index.svelte",
|
| 14 |
-
"types": "./dist/Index.svelte.d.ts"
|
| 15 |
-
},
|
| 16 |
-
"./package.json": "./package.json"
|
| 17 |
-
},
|
| 18 |
-
"devDependencies": {
|
| 19 |
-
"@gradio/preview": "workspace:^"
|
| 20 |
-
},
|
| 21 |
-
"peerDependencies": {
|
| 22 |
-
"svelte": "^5.48.0"
|
| 23 |
-
},
|
| 24 |
-
"dependencies": {
|
| 25 |
-
"@gradio/atoms": "workspace:^",
|
| 26 |
-
"@gradio/icons": "workspace:^",
|
| 27 |
-
"@gradio/statustracker": "workspace:^",
|
| 28 |
-
"@gradio/upload": "workspace:^",
|
| 29 |
-
"@gradio/utils": "workspace:^",
|
| 30 |
-
"@gradio/client": "workspace:^"
|
| 31 |
-
},
|
| 32 |
-
"repository": {
|
| 33 |
-
"type": "git",
|
| 34 |
-
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 35 |
-
"directory": "js/annotatedimage"
|
| 36 |
-
}
|
| 37 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/annotatedimage/types.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
import type { FileData } from "@gradio/client";
|
| 2 |
-
import type { CustomButton } from "@gradio/utils";
|
| 3 |
-
|
| 4 |
-
export interface Annotation {
|
| 5 |
-
image: FileData;
|
| 6 |
-
label: string;
|
| 7 |
-
}
|
| 8 |
-
|
| 9 |
-
export interface AnnotatedImageValue {
|
| 10 |
-
image: FileData;
|
| 11 |
-
annotations: Annotation[];
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
export interface AnnotatedImageProps {
|
| 15 |
-
value: AnnotatedImageValue | null;
|
| 16 |
-
show_legend: boolean;
|
| 17 |
-
height: number | undefined;
|
| 18 |
-
width: number | undefined;
|
| 19 |
-
color_map: Record<string, string>;
|
| 20 |
-
buttons: (string | CustomButton)[];
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
export interface AnnotatedImageEvents {
|
| 24 |
-
change: never;
|
| 25 |
-
select: { index: number; value: string };
|
| 26 |
-
custom_button_click: { id: number };
|
| 27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/package.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "@gradio/atoms",
|
| 3 |
-
"version": "0.23.1",
|
| 4 |
-
"description": "Gradio UI packages",
|
| 5 |
-
"type": "module",
|
| 6 |
-
"main": "src/index.ts",
|
| 7 |
-
"author": "",
|
| 8 |
-
"license": "ISC",
|
| 9 |
-
"dependencies": {
|
| 10 |
-
"@gradio/icons": "workspace:^",
|
| 11 |
-
"@gradio/utils": "workspace:^"
|
| 12 |
-
},
|
| 13 |
-
"peerDependencies": {
|
| 14 |
-
"svelte": "^5.48.0"
|
| 15 |
-
},
|
| 16 |
-
"exports": {
|
| 17 |
-
".": {
|
| 18 |
-
"gradio": "./src/index.ts",
|
| 19 |
-
"svelte": "./dist/src/index.js",
|
| 20 |
-
"types": "./dist/src/index.d.ts"
|
| 21 |
-
},
|
| 22 |
-
"./package.json": "./package.json"
|
| 23 |
-
},
|
| 24 |
-
"main_changeset": true,
|
| 25 |
-
"repository": {
|
| 26 |
-
"type": "git",
|
| 27 |
-
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 28 |
-
"directory": "js/atoms"
|
| 29 |
-
},
|
| 30 |
-
"scripts": {
|
| 31 |
-
"sv-package": "svelte-package --input=. --tsconfig=../../tsconfig.json"
|
| 32 |
-
}
|
| 33 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/Block.svelte
DELETED
|
@@ -1,256 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
export let height: number | string | undefined = undefined;
|
| 3 |
-
export let min_height: number | string | undefined = undefined;
|
| 4 |
-
export let max_height: number | string | undefined = undefined;
|
| 5 |
-
export let width: number | string | undefined = undefined;
|
| 6 |
-
export let elem_id = "";
|
| 7 |
-
export let elem_classes: string[] = [];
|
| 8 |
-
export let variant: "solid" | "dashed" | "none" = "solid";
|
| 9 |
-
export let border_mode: "base" | "focus" | "contrast" = "base";
|
| 10 |
-
export let padding = true;
|
| 11 |
-
export let type: "normal" | "fieldset" = "normal";
|
| 12 |
-
export let test_id: string | undefined = undefined;
|
| 13 |
-
export let explicit_call = false;
|
| 14 |
-
export let container = true;
|
| 15 |
-
export let visible: boolean | "hidden" = true;
|
| 16 |
-
export let allow_overflow = true;
|
| 17 |
-
export let overflow_behavior: "visible" | "auto" = "auto";
|
| 18 |
-
export let scale: number | null = null;
|
| 19 |
-
export let min_width = 0;
|
| 20 |
-
export let flex = false;
|
| 21 |
-
export let resizable = false;
|
| 22 |
-
export let rtl = false;
|
| 23 |
-
export let fullscreen = false;
|
| 24 |
-
export let label: string | undefined = undefined;
|
| 25 |
-
let old_fullscreen = fullscreen;
|
| 26 |
-
|
| 27 |
-
let element: HTMLElement;
|
| 28 |
-
|
| 29 |
-
let tag = type === "fieldset" ? "fieldset" : "div";
|
| 30 |
-
|
| 31 |
-
let placeholder_height = 0;
|
| 32 |
-
let placeholder_width = 0;
|
| 33 |
-
let preexpansionBoundingRect: DOMRect | null = null;
|
| 34 |
-
|
| 35 |
-
function handleKeydown(event: KeyboardEvent): void {
|
| 36 |
-
if (fullscreen && event.key === "Escape") {
|
| 37 |
-
fullscreen = false;
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
$: if (fullscreen !== old_fullscreen) {
|
| 42 |
-
old_fullscreen = fullscreen;
|
| 43 |
-
if (fullscreen) {
|
| 44 |
-
preexpansionBoundingRect = element.getBoundingClientRect();
|
| 45 |
-
placeholder_height = element.offsetHeight;
|
| 46 |
-
placeholder_width = element.offsetWidth;
|
| 47 |
-
window.addEventListener("keydown", handleKeydown);
|
| 48 |
-
} else {
|
| 49 |
-
preexpansionBoundingRect = null;
|
| 50 |
-
window.removeEventListener("keydown", handleKeydown);
|
| 51 |
-
}
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
const get_dimension = (
|
| 55 |
-
dimension_value: string | number | undefined
|
| 56 |
-
): string | undefined => {
|
| 57 |
-
if (dimension_value === undefined) {
|
| 58 |
-
return undefined;
|
| 59 |
-
}
|
| 60 |
-
if (typeof dimension_value === "number") {
|
| 61 |
-
return dimension_value + "px";
|
| 62 |
-
} else if (typeof dimension_value === "string") {
|
| 63 |
-
return dimension_value;
|
| 64 |
-
}
|
| 65 |
-
};
|
| 66 |
-
|
| 67 |
-
$: if (!visible) {
|
| 68 |
-
flex = false;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
const resize = (e: MouseEvent): void => {
|
| 72 |
-
let prevY = e.clientY;
|
| 73 |
-
const onMouseMove = (e: MouseEvent): void => {
|
| 74 |
-
const dy: number = e.clientY - prevY;
|
| 75 |
-
prevY = e.clientY;
|
| 76 |
-
element.style.height = `${element.offsetHeight + dy}px`;
|
| 77 |
-
};
|
| 78 |
-
const onMouseUp = (): void => {
|
| 79 |
-
window.removeEventListener("mousemove", onMouseMove);
|
| 80 |
-
window.removeEventListener("mouseup", onMouseUp);
|
| 81 |
-
};
|
| 82 |
-
window.addEventListener("mousemove", onMouseMove);
|
| 83 |
-
window.addEventListener("mouseup", onMouseUp);
|
| 84 |
-
};
|
| 85 |
-
// When visible is False, we need to remove the component from the page
|
| 86 |
-
// We can remove it by either modifying the AppTree in Blocks or by hiding the component here
|
| 87 |
-
// We do it here because if visible is updated via an event, only the local state will be updated
|
| 88 |
-
// and we would have to flow the state back up to modify the AppTree
|
| 89 |
-
</script>
|
| 90 |
-
|
| 91 |
-
{#if visible === true || visible === "hidden"}
|
| 92 |
-
<svelte:element
|
| 93 |
-
this={tag}
|
| 94 |
-
bind:this={element}
|
| 95 |
-
data-testid={test_id}
|
| 96 |
-
id={elem_id}
|
| 97 |
-
class:hidden={visible === "hidden"}
|
| 98 |
-
class="block {elem_classes?.join(' ') || ''}"
|
| 99 |
-
class:padded={padding}
|
| 100 |
-
class:flex
|
| 101 |
-
class:border_focus={border_mode === "focus"}
|
| 102 |
-
class:border_contrast={border_mode === "contrast"}
|
| 103 |
-
class:hide-container={!explicit_call && !container}
|
| 104 |
-
style:height={fullscreen ? undefined : get_dimension(height)}
|
| 105 |
-
style:min-height={fullscreen ? undefined : get_dimension(min_height)}
|
| 106 |
-
style:max-height={fullscreen ? undefined : get_dimension(max_height)}
|
| 107 |
-
class:fullscreen
|
| 108 |
-
class:animating={fullscreen && preexpansionBoundingRect !== null}
|
| 109 |
-
style:--start-top={preexpansionBoundingRect
|
| 110 |
-
? `${preexpansionBoundingRect.top}px`
|
| 111 |
-
: "0px"}
|
| 112 |
-
style:--start-left={preexpansionBoundingRect
|
| 113 |
-
? `${preexpansionBoundingRect.left}px`
|
| 114 |
-
: "0px"}
|
| 115 |
-
style:--start-width={preexpansionBoundingRect
|
| 116 |
-
? `${preexpansionBoundingRect.width}px`
|
| 117 |
-
: "0px"}
|
| 118 |
-
style:--start-height={preexpansionBoundingRect
|
| 119 |
-
? `${preexpansionBoundingRect.height}px`
|
| 120 |
-
: "0px"}
|
| 121 |
-
style:width={fullscreen
|
| 122 |
-
? undefined
|
| 123 |
-
: typeof width === "number"
|
| 124 |
-
? `calc(min(${width}px, 100%))`
|
| 125 |
-
: get_dimension(width)}
|
| 126 |
-
style:border-style={variant}
|
| 127 |
-
style:overflow={allow_overflow ? overflow_behavior : "hidden"}
|
| 128 |
-
style:flex-grow={scale}
|
| 129 |
-
style:min-width={`calc(min(${min_width}px, 100%))`}
|
| 130 |
-
class:auto-margin={scale === null}
|
| 131 |
-
dir={rtl ? "rtl" : "ltr"}
|
| 132 |
-
aria-label={label}
|
| 133 |
-
>
|
| 134 |
-
<slot />
|
| 135 |
-
{#if resizable}
|
| 136 |
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
| 137 |
-
<svg
|
| 138 |
-
class="resize-handle"
|
| 139 |
-
xmlns="http://www.w3.org/2000/svg"
|
| 140 |
-
viewBox="0 0 10 10"
|
| 141 |
-
on:mousedown={resize}
|
| 142 |
-
>
|
| 143 |
-
<line x1="1" y1="9" x2="9" y2="1" stroke="gray" stroke-width="0.5" />
|
| 144 |
-
<line x1="5" y1="9" x2="9" y2="5" stroke="gray" stroke-width="0.5" />
|
| 145 |
-
</svg>
|
| 146 |
-
{/if}
|
| 147 |
-
</svelte:element>
|
| 148 |
-
{#if fullscreen}
|
| 149 |
-
<div
|
| 150 |
-
class="placeholder"
|
| 151 |
-
style:height={placeholder_height + "px"}
|
| 152 |
-
style:width={placeholder_width + "px"}
|
| 153 |
-
></div>
|
| 154 |
-
{/if}
|
| 155 |
-
{/if}
|
| 156 |
-
|
| 157 |
-
<style>
|
| 158 |
-
.block {
|
| 159 |
-
position: relative;
|
| 160 |
-
margin: 0;
|
| 161 |
-
box-shadow: var(--block-shadow);
|
| 162 |
-
border-width: var(--block-border-width);
|
| 163 |
-
border-color: var(--block-border-color);
|
| 164 |
-
border-radius: var(--block-radius);
|
| 165 |
-
background: var(--block-background-fill);
|
| 166 |
-
width: 100%;
|
| 167 |
-
line-height: var(--line-sm);
|
| 168 |
-
border-width: var(--block-border-width);
|
| 169 |
-
}
|
| 170 |
-
.block.fullscreen {
|
| 171 |
-
border-radius: 0;
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
.auto-margin {
|
| 175 |
-
margin-left: auto;
|
| 176 |
-
margin-right: auto;
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
.block.border_focus {
|
| 180 |
-
border-color: var(--color-accent);
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
.block.border_contrast {
|
| 184 |
-
border-color: var(--body-text-color);
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
.padded {
|
| 188 |
-
padding: var(--block-padding);
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
.flex {
|
| 192 |
-
display: flex;
|
| 193 |
-
flex-direction: column;
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
.hidden {
|
| 197 |
-
/* We use "hidden" class name in form/Index.svelte to hide parent forms, so if this class changes, edit form/Index.svelte accordingly */
|
| 198 |
-
display: none;
|
| 199 |
-
}
|
| 200 |
-
.hide-container:not(.fullscreen) {
|
| 201 |
-
margin: 0;
|
| 202 |
-
box-shadow: none;
|
| 203 |
-
border-width: 0;
|
| 204 |
-
background: transparent;
|
| 205 |
-
padding: 0;
|
| 206 |
-
overflow: visible;
|
| 207 |
-
}
|
| 208 |
-
.resize-handle {
|
| 209 |
-
position: absolute;
|
| 210 |
-
bottom: 0;
|
| 211 |
-
right: 0;
|
| 212 |
-
width: 10px;
|
| 213 |
-
height: 10px;
|
| 214 |
-
fill: var(--block-border-color);
|
| 215 |
-
cursor: nwse-resize;
|
| 216 |
-
}
|
| 217 |
-
.fullscreen {
|
| 218 |
-
position: fixed;
|
| 219 |
-
top: 0;
|
| 220 |
-
left: 0;
|
| 221 |
-
width: 100vw;
|
| 222 |
-
height: 100vh;
|
| 223 |
-
z-index: 1000;
|
| 224 |
-
overflow: auto;
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
.animating {
|
| 228 |
-
animation: pop-out 0.1s ease-out forwards;
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
@keyframes pop-out {
|
| 232 |
-
0% {
|
| 233 |
-
position: fixed;
|
| 234 |
-
top: var(--start-top);
|
| 235 |
-
left: var(--start-left);
|
| 236 |
-
width: var(--start-width);
|
| 237 |
-
height: var(--start-height);
|
| 238 |
-
z-index: 100;
|
| 239 |
-
}
|
| 240 |
-
100% {
|
| 241 |
-
position: fixed;
|
| 242 |
-
top: 0vh;
|
| 243 |
-
left: 0vw;
|
| 244 |
-
width: 100vw;
|
| 245 |
-
height: 100vh;
|
| 246 |
-
z-index: 1000;
|
| 247 |
-
}
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
.placeholder {
|
| 251 |
-
border-radius: var(--block-radius);
|
| 252 |
-
border-width: var(--block-border-width);
|
| 253 |
-
border-color: var(--block-border-color);
|
| 254 |
-
border-style: dashed;
|
| 255 |
-
}
|
| 256 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/BlockLabel.svelte
DELETED
|
@@ -1,90 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
export let label: string | null = null;
|
| 3 |
-
export let Icon: any;
|
| 4 |
-
export let show_label = true;
|
| 5 |
-
export let disable = false;
|
| 6 |
-
export let float = true;
|
| 7 |
-
export let rtl = false;
|
| 8 |
-
</script>
|
| 9 |
-
|
| 10 |
-
<label
|
| 11 |
-
for=""
|
| 12 |
-
class:hide={!show_label}
|
| 13 |
-
class:sr-only={!show_label}
|
| 14 |
-
class:float
|
| 15 |
-
class:hide-label={disable}
|
| 16 |
-
data-testid="block-label"
|
| 17 |
-
dir={rtl ? "rtl" : "ltr"}
|
| 18 |
-
>
|
| 19 |
-
<span>
|
| 20 |
-
<Icon />
|
| 21 |
-
</span>
|
| 22 |
-
{label}
|
| 23 |
-
</label>
|
| 24 |
-
|
| 25 |
-
<style>
|
| 26 |
-
label {
|
| 27 |
-
display: inline-flex;
|
| 28 |
-
align-items: center;
|
| 29 |
-
z-index: var(--layer-2);
|
| 30 |
-
box-shadow: var(--block-label-shadow);
|
| 31 |
-
border: var(--block-label-border-width) solid
|
| 32 |
-
var(--block-label-border-color);
|
| 33 |
-
border-top: none;
|
| 34 |
-
border-left: none;
|
| 35 |
-
border-radius: var(--block-label-radius);
|
| 36 |
-
background: var(--block-label-background-fill);
|
| 37 |
-
padding: var(--block-label-padding);
|
| 38 |
-
pointer-events: none;
|
| 39 |
-
color: var(--block-label-text-color);
|
| 40 |
-
font-weight: var(--block-label-text-weight);
|
| 41 |
-
font-size: var(--block-label-text-size);
|
| 42 |
-
line-height: var(--line-sm);
|
| 43 |
-
}
|
| 44 |
-
:global(.gr-group) label {
|
| 45 |
-
border-top-left-radius: 0;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
label.float {
|
| 49 |
-
position: absolute;
|
| 50 |
-
top: var(--block-label-margin);
|
| 51 |
-
left: var(--block-label-margin);
|
| 52 |
-
}
|
| 53 |
-
label:not(.float) {
|
| 54 |
-
position: static;
|
| 55 |
-
margin-top: var(--block-label-margin);
|
| 56 |
-
margin-left: var(--block-label-margin);
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
.hide {
|
| 60 |
-
display: none;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
span {
|
| 64 |
-
opacity: 0.8;
|
| 65 |
-
margin-right: var(--size-2);
|
| 66 |
-
width: calc(var(--block-label-text-size) - 1px);
|
| 67 |
-
height: calc(var(--block-label-text-size) - 1px);
|
| 68 |
-
}
|
| 69 |
-
.hide-label {
|
| 70 |
-
box-shadow: none;
|
| 71 |
-
border-width: 0;
|
| 72 |
-
background: transparent;
|
| 73 |
-
overflow: visible;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
label[dir="rtl"] {
|
| 77 |
-
border: var(--block-label-border-width) solid
|
| 78 |
-
var(--block-label-border-color);
|
| 79 |
-
border-top: none;
|
| 80 |
-
border-right: none;
|
| 81 |
-
border-bottom-left-radius: var(--block-radius);
|
| 82 |
-
border-bottom-right-radius: var(--block-label-radius);
|
| 83 |
-
border-top-left-radius: var(--block-label-radius);
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
label[dir="rtl"] span {
|
| 87 |
-
margin-left: var(--size-2);
|
| 88 |
-
margin-right: 0;
|
| 89 |
-
}
|
| 90 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/BlockTitle.svelte
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import Info from "./Info.svelte";
|
| 3 |
-
|
| 4 |
-
export let show_label = true;
|
| 5 |
-
export let info: string | undefined = undefined;
|
| 6 |
-
export let rtl = false;
|
| 7 |
-
</script>
|
| 8 |
-
|
| 9 |
-
<span
|
| 10 |
-
class:hide={!show_label}
|
| 11 |
-
class:has-info={info != null}
|
| 12 |
-
class:sr-only={!show_label}
|
| 13 |
-
data-testid="block-info"
|
| 14 |
-
dir={rtl ? "rtl" : "ltr"}
|
| 15 |
-
>
|
| 16 |
-
<slot />
|
| 17 |
-
</span>
|
| 18 |
-
{#if info}
|
| 19 |
-
<Info {info} />
|
| 20 |
-
{/if}
|
| 21 |
-
|
| 22 |
-
<style>
|
| 23 |
-
span.has-info {
|
| 24 |
-
margin-bottom: var(--spacing-xs);
|
| 25 |
-
}
|
| 26 |
-
span:not(.has-info) {
|
| 27 |
-
margin-bottom: var(--spacing-lg);
|
| 28 |
-
}
|
| 29 |
-
span {
|
| 30 |
-
display: inline-block;
|
| 31 |
-
position: relative;
|
| 32 |
-
z-index: var(--layer-4);
|
| 33 |
-
border: solid var(--block-title-border-width)
|
| 34 |
-
var(--block-title-border-color);
|
| 35 |
-
border-radius: var(--block-title-radius);
|
| 36 |
-
background: var(--block-title-background-fill);
|
| 37 |
-
padding: var(--block-title-padding);
|
| 38 |
-
color: var(--block-title-text-color);
|
| 39 |
-
font-weight: var(--block-title-text-weight);
|
| 40 |
-
font-size: var(--block-title-text-size);
|
| 41 |
-
line-height: var(--line-sm);
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
span[dir="rtl"] {
|
| 45 |
-
display: block;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
.hide {
|
| 49 |
-
margin: 0;
|
| 50 |
-
height: 0;
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
.sr-only {
|
| 54 |
-
clip: rect(0, 0, 0, 0);
|
| 55 |
-
position: absolute;
|
| 56 |
-
margin: -1px;
|
| 57 |
-
border-width: 0;
|
| 58 |
-
padding: 0;
|
| 59 |
-
width: 1px;
|
| 60 |
-
height: 1px;
|
| 61 |
-
overflow: hidden;
|
| 62 |
-
white-space: nowrap;
|
| 63 |
-
}
|
| 64 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/CustomButton.svelte
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import type { CustomButton } from "@gradio/utils";
|
| 3 |
-
|
| 4 |
-
export let button: CustomButton;
|
| 5 |
-
export let on_click: (id: number) => void;
|
| 6 |
-
</script>
|
| 7 |
-
|
| 8 |
-
<button
|
| 9 |
-
class="custom-button"
|
| 10 |
-
on:click={() => on_click(button.id)}
|
| 11 |
-
title={button.value || ""}
|
| 12 |
-
aria-label={button.value || "Custom action"}
|
| 13 |
-
>
|
| 14 |
-
{#if button.value}
|
| 15 |
-
<span class="custom-button-label">{button.value}</span>
|
| 16 |
-
{/if}
|
| 17 |
-
</button>
|
| 18 |
-
|
| 19 |
-
<style>
|
| 20 |
-
.custom-button {
|
| 21 |
-
display: flex;
|
| 22 |
-
align-items: center;
|
| 23 |
-
justify-content: center;
|
| 24 |
-
gap: var(--size-1);
|
| 25 |
-
height: var(--size-6);
|
| 26 |
-
padding: var(--size-1) var(--size-2);
|
| 27 |
-
border: none;
|
| 28 |
-
border-radius: var(--radius-sm);
|
| 29 |
-
background: transparent;
|
| 30 |
-
color: var(--block-title-text-color);
|
| 31 |
-
cursor: pointer;
|
| 32 |
-
transition: all 0.2s;
|
| 33 |
-
font-size: var(--text-sm);
|
| 34 |
-
margin-left: var(--size-1);
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
.custom-button:hover {
|
| 38 |
-
background: var(--background-fill-secondary);
|
| 39 |
-
color: var(--body-text-color);
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
.custom-button-label {
|
| 43 |
-
white-space: nowrap;
|
| 44 |
-
}
|
| 45 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/DownloadLink.svelte
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import type { HTMLAnchorAttributes } from "svelte/elements";
|
| 3 |
-
import { createEventDispatcher } from "svelte";
|
| 4 |
-
|
| 5 |
-
interface DownloadLinkAttributes extends Omit<
|
| 6 |
-
HTMLAnchorAttributes,
|
| 7 |
-
"target"
|
| 8 |
-
> {
|
| 9 |
-
download: NonNullable<HTMLAnchorAttributes["download"]>;
|
| 10 |
-
}
|
| 11 |
-
type $$Props = DownloadLinkAttributes;
|
| 12 |
-
|
| 13 |
-
export let href: DownloadLinkAttributes["href"] = undefined;
|
| 14 |
-
export let download: DownloadLinkAttributes["download"];
|
| 15 |
-
|
| 16 |
-
const dispatch = createEventDispatcher();
|
| 17 |
-
</script>
|
| 18 |
-
|
| 19 |
-
<a
|
| 20 |
-
style:position="relative"
|
| 21 |
-
class="download-link"
|
| 22 |
-
{href}
|
| 23 |
-
target={typeof window !== "undefined" && window.__is_colab__
|
| 24 |
-
? "_blank"
|
| 25 |
-
: null}
|
| 26 |
-
rel="noopener noreferrer"
|
| 27 |
-
{download}
|
| 28 |
-
{...$$restProps}
|
| 29 |
-
on:click={dispatch.bind(null, "click")}
|
| 30 |
-
>
|
| 31 |
-
<slot />
|
| 32 |
-
</a>
|
| 33 |
-
|
| 34 |
-
<style>
|
| 35 |
-
.unstyled-link {
|
| 36 |
-
all: unset;
|
| 37 |
-
cursor: pointer;
|
| 38 |
-
}
|
| 39 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/Empty.svelte
DELETED
|
@@ -1,63 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
export let size: "small" | "large" = "small";
|
| 3 |
-
export let unpadded_box = false;
|
| 4 |
-
|
| 5 |
-
let el: HTMLDivElement;
|
| 6 |
-
$: parent_height = compare_el_to_parent(el);
|
| 7 |
-
|
| 8 |
-
function compare_el_to_parent(el: HTMLDivElement): boolean {
|
| 9 |
-
if (!el) return false;
|
| 10 |
-
|
| 11 |
-
const { height: el_height } = el.getBoundingClientRect();
|
| 12 |
-
const { height: parent_height } =
|
| 13 |
-
el.parentElement?.getBoundingClientRect() || { height: el_height };
|
| 14 |
-
|
| 15 |
-
return el_height > parent_height + 2;
|
| 16 |
-
}
|
| 17 |
-
</script>
|
| 18 |
-
|
| 19 |
-
<div
|
| 20 |
-
class="empty"
|
| 21 |
-
class:small={size === "small"}
|
| 22 |
-
class:large={size === "large"}
|
| 23 |
-
class:unpadded_box
|
| 24 |
-
bind:this={el}
|
| 25 |
-
class:small_parent={parent_height}
|
| 26 |
-
aria-label="Empty value"
|
| 27 |
-
>
|
| 28 |
-
<div class="icon">
|
| 29 |
-
<slot />
|
| 30 |
-
</div>
|
| 31 |
-
</div>
|
| 32 |
-
|
| 33 |
-
<style>
|
| 34 |
-
.empty {
|
| 35 |
-
display: flex;
|
| 36 |
-
justify-content: center;
|
| 37 |
-
align-items: center;
|
| 38 |
-
margin-top: calc(0px - var(--size-6));
|
| 39 |
-
height: var(--size-full);
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
.icon {
|
| 43 |
-
opacity: 0.5;
|
| 44 |
-
height: var(--size-5);
|
| 45 |
-
color: var(--body-text-color);
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
.small {
|
| 49 |
-
min-height: calc(var(--size-32) - 20px);
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
.large {
|
| 53 |
-
min-height: calc(var(--size-64) - 20px);
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
.unpadded_box {
|
| 57 |
-
margin-top: 0;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
.small_parent {
|
| 61 |
-
min-height: 100% !important;
|
| 62 |
-
}
|
| 63 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/FullscreenButton.svelte
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { IconButton } from "@gradio/atoms";
|
| 3 |
-
import { Maximize, Minimize } from "@gradio/icons";
|
| 4 |
-
|
| 5 |
-
let {
|
| 6 |
-
fullscreen,
|
| 7 |
-
onclick
|
| 8 |
-
}: {
|
| 9 |
-
fullscreen: boolean;
|
| 10 |
-
onclick: (fullscreen: boolean) => void;
|
| 11 |
-
} = $props();
|
| 12 |
-
</script>
|
| 13 |
-
|
| 14 |
-
{#if fullscreen}
|
| 15 |
-
<IconButton
|
| 16 |
-
Icon={Minimize}
|
| 17 |
-
label="Exit fullscreen mode"
|
| 18 |
-
onclick={() => onclick(false)}
|
| 19 |
-
/>
|
| 20 |
-
{:else}
|
| 21 |
-
<IconButton
|
| 22 |
-
Icon={Maximize}
|
| 23 |
-
label="Fullscreen"
|
| 24 |
-
onclick={() => onclick(true)}
|
| 25 |
-
/>
|
| 26 |
-
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/IconButton.svelte
DELETED
|
@@ -1,161 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { type Component, type Snippet } from "svelte";
|
| 3 |
-
|
| 4 |
-
let {
|
| 5 |
-
Icon,
|
| 6 |
-
label = "",
|
| 7 |
-
show_label = false,
|
| 8 |
-
pending = false,
|
| 9 |
-
size = "small",
|
| 10 |
-
padded = true,
|
| 11 |
-
highlight = false,
|
| 12 |
-
disabled = false,
|
| 13 |
-
hasPopup = false,
|
| 14 |
-
color = "var(--block-label-text-color)",
|
| 15 |
-
transparent = false,
|
| 16 |
-
background = "var(--block-background-fill)",
|
| 17 |
-
border = "transparent",
|
| 18 |
-
onclick,
|
| 19 |
-
children
|
| 20 |
-
}: {
|
| 21 |
-
Icon: Component;
|
| 22 |
-
label?: string;
|
| 23 |
-
show_label?: boolean;
|
| 24 |
-
pending?: boolean;
|
| 25 |
-
size?: "x-small" | "small" | "large" | "medium";
|
| 26 |
-
padded?: boolean;
|
| 27 |
-
highlight?: boolean;
|
| 28 |
-
disabled?: boolean;
|
| 29 |
-
hasPopup?: boolean;
|
| 30 |
-
color?: string;
|
| 31 |
-
transparent?: boolean;
|
| 32 |
-
background?: string;
|
| 33 |
-
border?: string;
|
| 34 |
-
onclick?: (event: MouseEvent) => void;
|
| 35 |
-
children?: Snippet;
|
| 36 |
-
} = $props();
|
| 37 |
-
|
| 38 |
-
let _color = $derived(highlight ? "var(--color-accent)" : color);
|
| 39 |
-
</script>
|
| 40 |
-
|
| 41 |
-
<button
|
| 42 |
-
class="icon-button"
|
| 43 |
-
{disabled}
|
| 44 |
-
{onclick}
|
| 45 |
-
aria-label={label}
|
| 46 |
-
aria-haspopup={hasPopup}
|
| 47 |
-
title={label}
|
| 48 |
-
class:pending
|
| 49 |
-
class:padded
|
| 50 |
-
class:highlight
|
| 51 |
-
class:transparent
|
| 52 |
-
style:--border-color={border}
|
| 53 |
-
style:color={!disabled && _color ? _color : "var(--block-label-text-color)"}
|
| 54 |
-
style:--bg-color={!disabled ? background : "auto"}
|
| 55 |
-
>
|
| 56 |
-
{#if show_label}<span>{label}</span>{/if}
|
| 57 |
-
<div
|
| 58 |
-
class:x-small={size === "x-small"}
|
| 59 |
-
class:small={size === "small"}
|
| 60 |
-
class:large={size === "large"}
|
| 61 |
-
class:medium={size === "medium"}
|
| 62 |
-
>
|
| 63 |
-
<Icon />
|
| 64 |
-
{#if children}{@render children()}{/if}
|
| 65 |
-
</div>
|
| 66 |
-
</button>
|
| 67 |
-
|
| 68 |
-
<style>
|
| 69 |
-
button {
|
| 70 |
-
display: flex;
|
| 71 |
-
justify-content: center;
|
| 72 |
-
align-items: center;
|
| 73 |
-
gap: 1px;
|
| 74 |
-
z-index: var(--layer-2);
|
| 75 |
-
border-radius: var(--radius-xs);
|
| 76 |
-
color: var(--block-label-text-color);
|
| 77 |
-
border: 1px solid var(--border-color);
|
| 78 |
-
padding: var(--spacing-xxs);
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
button:hover {
|
| 82 |
-
background-color: var(--background-fill-secondary);
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
button[disabled] {
|
| 86 |
-
opacity: 0.5;
|
| 87 |
-
box-shadow: none;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
button[disabled]:hover {
|
| 91 |
-
cursor: not-allowed;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
.padded {
|
| 95 |
-
background: var(--bg-color);
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
button:hover,
|
| 99 |
-
button.highlight {
|
| 100 |
-
cursor: pointer;
|
| 101 |
-
color: var(--color-accent);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
.padded:hover {
|
| 105 |
-
color: var(--block-label-text-color);
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
span {
|
| 109 |
-
padding: 0px 1px;
|
| 110 |
-
font-size: 10px;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
div {
|
| 114 |
-
display: flex;
|
| 115 |
-
align-items: center;
|
| 116 |
-
justify-content: center;
|
| 117 |
-
transition: filter 0.2s ease-in-out;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
.x-small {
|
| 121 |
-
width: 10px;
|
| 122 |
-
height: 10px;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
.small {
|
| 126 |
-
width: 14px;
|
| 127 |
-
height: 14px;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
.medium {
|
| 131 |
-
width: 20px;
|
| 132 |
-
height: 20px;
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
.large {
|
| 136 |
-
width: 22px;
|
| 137 |
-
height: 22px;
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
.pending {
|
| 141 |
-
animation: flash 0.5s infinite;
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
@keyframes flash {
|
| 145 |
-
0% {
|
| 146 |
-
opacity: 0.5;
|
| 147 |
-
}
|
| 148 |
-
50% {
|
| 149 |
-
opacity: 1;
|
| 150 |
-
}
|
| 151 |
-
100% {
|
| 152 |
-
opacity: 0.5;
|
| 153 |
-
}
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
.transparent {
|
| 157 |
-
background: transparent;
|
| 158 |
-
border: none;
|
| 159 |
-
box-shadow: none;
|
| 160 |
-
}
|
| 161 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/IconButtonWrapper.svelte
DELETED
|
@@ -1,116 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import CustomButton from "./CustomButton.svelte";
|
| 3 |
-
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 4 |
-
import type { Snippet } from "svelte";
|
| 5 |
-
|
| 6 |
-
let {
|
| 7 |
-
top_panel = true,
|
| 8 |
-
display_top_corner = false,
|
| 9 |
-
show_background = true,
|
| 10 |
-
buttons = null,
|
| 11 |
-
on_custom_button_click = null,
|
| 12 |
-
children
|
| 13 |
-
}: {
|
| 14 |
-
top_panel?: boolean;
|
| 15 |
-
display_top_corner?: boolean;
|
| 16 |
-
show_background?: boolean;
|
| 17 |
-
buttons?: (string | CustomButtonType)[] | null;
|
| 18 |
-
on_custom_button_click?: ((id: number) => void) | null;
|
| 19 |
-
children?: Snippet;
|
| 20 |
-
} = $props();
|
| 21 |
-
</script>
|
| 22 |
-
|
| 23 |
-
<div
|
| 24 |
-
class={`icon-button-wrapper ${top_panel ? "top-panel" : ""} ${display_top_corner ? "display-top-corner" : "hide-top-corner"} ${!show_background ? "no-background" : ""}`}
|
| 25 |
-
>
|
| 26 |
-
{#if children}{@render children()}{/if}
|
| 27 |
-
{#if buttons}
|
| 28 |
-
{#each buttons as btn}
|
| 29 |
-
{#if typeof btn !== "string"}
|
| 30 |
-
<CustomButton
|
| 31 |
-
button={btn}
|
| 32 |
-
on_click={(id) => {
|
| 33 |
-
if (on_custom_button_click) {
|
| 34 |
-
on_custom_button_click(id);
|
| 35 |
-
}
|
| 36 |
-
}}
|
| 37 |
-
/>
|
| 38 |
-
{/if}
|
| 39 |
-
{/each}
|
| 40 |
-
{/if}
|
| 41 |
-
</div>
|
| 42 |
-
|
| 43 |
-
<style>
|
| 44 |
-
.icon-button-wrapper {
|
| 45 |
-
display: flex;
|
| 46 |
-
flex-direction: row;
|
| 47 |
-
align-items: center;
|
| 48 |
-
justify-content: center;
|
| 49 |
-
z-index: var(--layer-2);
|
| 50 |
-
gap: var(--spacing-sm);
|
| 51 |
-
box-shadow: var(--shadow-drop);
|
| 52 |
-
border: 1px solid var(--border-color-primary);
|
| 53 |
-
background: var(--block-background-fill);
|
| 54 |
-
padding: var(--spacing-xxs);
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
.icon-button-wrapper.hide-top-corner {
|
| 58 |
-
border-top: none;
|
| 59 |
-
border-right: none;
|
| 60 |
-
border-radius: var(--block-label-right-radius);
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
.icon-button-wrapper.display-top-corner {
|
| 64 |
-
border-radius: var(--radius-sm) 0 0 var(--radius-sm);
|
| 65 |
-
top: var(--spacing-sm);
|
| 66 |
-
right: -1px;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
.icon-button-wrapper:not(.top-panel) {
|
| 70 |
-
border: 1px solid var(--border-color-primary);
|
| 71 |
-
border-radius: var(--radius-sm);
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
.top-panel {
|
| 75 |
-
position: absolute;
|
| 76 |
-
top: var(--block-label-margin);
|
| 77 |
-
right: var(--block-label-margin);
|
| 78 |
-
margin: 0;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
.icon-button-wrapper :global(button) {
|
| 82 |
-
margin: var(--spacing-xxs);
|
| 83 |
-
border-radius: var(--radius-xs);
|
| 84 |
-
position: relative;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
.icon-button-wrapper :global(a.download-link:not(:last-child)),
|
| 88 |
-
.icon-button-wrapper :global(button:not(:last-child)) {
|
| 89 |
-
margin-right: var(--spacing-xxs);
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
.icon-button-wrapper
|
| 93 |
-
:global(a.download-link:not(:last-child):not(.no-border *)::after),
|
| 94 |
-
.icon-button-wrapper
|
| 95 |
-
:global(button:not(:last-child):not(.no-border *)::after) {
|
| 96 |
-
content: "";
|
| 97 |
-
position: absolute;
|
| 98 |
-
right: -4.5px;
|
| 99 |
-
top: 15%;
|
| 100 |
-
height: 70%;
|
| 101 |
-
width: 1px;
|
| 102 |
-
background-color: var(--border-color-primary);
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
.icon-button-wrapper :global(> *) {
|
| 106 |
-
height: 100%;
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
.icon-button-wrapper.no-background {
|
| 110 |
-
box-shadow: none;
|
| 111 |
-
border: none;
|
| 112 |
-
background: none;
|
| 113 |
-
padding: 0;
|
| 114 |
-
z-index: var(--layer-1);
|
| 115 |
-
}
|
| 116 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/Info.svelte
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { render_inline_markdown } from "./inline-markdown";
|
| 3 |
-
export let info: string;
|
| 4 |
-
</script>
|
| 5 |
-
|
| 6 |
-
<div class="info-text">
|
| 7 |
-
{@html render_inline_markdown(info)}
|
| 8 |
-
</div>
|
| 9 |
-
|
| 10 |
-
<style>
|
| 11 |
-
.info-text {
|
| 12 |
-
font-weight: var(--block-info-text-weight);
|
| 13 |
-
font-size: var(--block-info-text-size);
|
| 14 |
-
line-height: var(--line-sm);
|
| 15 |
-
color: var(--block-info-text-color);
|
| 16 |
-
margin-bottom: var(--spacing-md);
|
| 17 |
-
}
|
| 18 |
-
.info-text :global(a) {
|
| 19 |
-
color: var(--link-text-color);
|
| 20 |
-
text-decoration: underline;
|
| 21 |
-
}
|
| 22 |
-
.info-text :global(code) {
|
| 23 |
-
background: var(--code-background-fill);
|
| 24 |
-
padding: 0.1em 0.3em;
|
| 25 |
-
border-radius: 3px;
|
| 26 |
-
font-size: 0.9em;
|
| 27 |
-
}
|
| 28 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/ScrollFade.svelte
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
let {
|
| 3 |
-
visible = false,
|
| 4 |
-
position = "sticky"
|
| 5 |
-
}: {
|
| 6 |
-
visible: boolean;
|
| 7 |
-
position?: "sticky" | "absolute";
|
| 8 |
-
} = $props();
|
| 9 |
-
</script>
|
| 10 |
-
|
| 11 |
-
{#if visible}
|
| 12 |
-
<div class="scroll-fade" class:absolute={position === "absolute"}></div>
|
| 13 |
-
{/if}
|
| 14 |
-
|
| 15 |
-
<style>
|
| 16 |
-
.scroll-fade {
|
| 17 |
-
position: sticky;
|
| 18 |
-
bottom: calc(0px - var(--size-2-5));
|
| 19 |
-
left: 0;
|
| 20 |
-
right: 0;
|
| 21 |
-
height: var(--size-6);
|
| 22 |
-
background: linear-gradient(
|
| 23 |
-
to top,
|
| 24 |
-
var(--block-background-fill) 30%,
|
| 25 |
-
transparent
|
| 26 |
-
);
|
| 27 |
-
pointer-events: none;
|
| 28 |
-
margin-top: calc(0px - var(--size-6));
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
.scroll-fade.absolute {
|
| 32 |
-
position: absolute;
|
| 33 |
-
bottom: 0;
|
| 34 |
-
margin-top: 0;
|
| 35 |
-
z-index: var(--layer-2);
|
| 36 |
-
}
|
| 37 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/SelectSource.svelte
DELETED
|
@@ -1,112 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { Microphone, Upload, Webcam, ImagePaste, Video } from "@gradio/icons";
|
| 3 |
-
|
| 4 |
-
type source_types =
|
| 5 |
-
| "upload"
|
| 6 |
-
| "microphone"
|
| 7 |
-
| "webcam"
|
| 8 |
-
| "clipboard"
|
| 9 |
-
| "webcam-video"
|
| 10 |
-
| null;
|
| 11 |
-
|
| 12 |
-
let {
|
| 13 |
-
sources,
|
| 14 |
-
active_source = $bindable(),
|
| 15 |
-
handle_clear = () => {},
|
| 16 |
-
handle_select = () => {}
|
| 17 |
-
}: {
|
| 18 |
-
sources: Partial<source_types>[];
|
| 19 |
-
active_source?: Partial<source_types>;
|
| 20 |
-
handle_clear?: () => void;
|
| 21 |
-
handle_select?: (source_type: Partial<source_types>) => void;
|
| 22 |
-
} = $props();
|
| 23 |
-
|
| 24 |
-
let unique_sources = $derived([...new Set(sources)]);
|
| 25 |
-
|
| 26 |
-
async function handle_select_source(
|
| 27 |
-
source: Partial<source_types>
|
| 28 |
-
): Promise<void> {
|
| 29 |
-
handle_clear();
|
| 30 |
-
active_source = source;
|
| 31 |
-
handle_select(source);
|
| 32 |
-
}
|
| 33 |
-
</script>
|
| 34 |
-
|
| 35 |
-
{#if unique_sources.length > 1 || sources.includes("clipboard")}
|
| 36 |
-
<span class="source-selection" data-testid="source-select">
|
| 37 |
-
{#if sources.includes("upload")}
|
| 38 |
-
<button
|
| 39 |
-
class="icon"
|
| 40 |
-
class:selected={active_source === "upload" || !active_source}
|
| 41 |
-
aria-label="Upload file"
|
| 42 |
-
onclick={() => handle_select_source("upload")}><Upload /></button
|
| 43 |
-
>
|
| 44 |
-
{/if}
|
| 45 |
-
|
| 46 |
-
{#if sources.includes("microphone")}
|
| 47 |
-
<button
|
| 48 |
-
class="icon"
|
| 49 |
-
class:selected={active_source === "microphone"}
|
| 50 |
-
aria-label="Record audio"
|
| 51 |
-
onclick={() => handle_select_source("microphone")}
|
| 52 |
-
><Microphone /></button
|
| 53 |
-
>
|
| 54 |
-
{/if}
|
| 55 |
-
|
| 56 |
-
{#if sources.includes("webcam")}
|
| 57 |
-
<button
|
| 58 |
-
class="icon"
|
| 59 |
-
class:selected={active_source === "webcam"}
|
| 60 |
-
aria-label="Capture from camera"
|
| 61 |
-
onclick={() => handle_select_source("webcam")}><Webcam /></button
|
| 62 |
-
>
|
| 63 |
-
{/if}
|
| 64 |
-
{#if sources.includes("webcam-video")}
|
| 65 |
-
<button
|
| 66 |
-
class="icon"
|
| 67 |
-
class:selected={active_source === "webcam-video"}
|
| 68 |
-
aria-label="Record video from camera"
|
| 69 |
-
onclick={() => handle_select_source("webcam-video")}><Video /></button
|
| 70 |
-
>
|
| 71 |
-
{/if}
|
| 72 |
-
{#if sources.includes("clipboard")}
|
| 73 |
-
<button
|
| 74 |
-
class="icon"
|
| 75 |
-
class:selected={active_source === "clipboard"}
|
| 76 |
-
aria-label="Paste from clipboard"
|
| 77 |
-
onclick={() => handle_select_source("clipboard")}><ImagePaste /></button
|
| 78 |
-
>
|
| 79 |
-
{/if}
|
| 80 |
-
</span>
|
| 81 |
-
{/if}
|
| 82 |
-
|
| 83 |
-
<style>
|
| 84 |
-
.source-selection {
|
| 85 |
-
display: flex;
|
| 86 |
-
align-items: center;
|
| 87 |
-
justify-content: center;
|
| 88 |
-
border-top: 1px solid var(--border-color-primary);
|
| 89 |
-
width: 100%;
|
| 90 |
-
margin-left: auto;
|
| 91 |
-
margin-right: auto;
|
| 92 |
-
height: var(--size-10);
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
.icon {
|
| 96 |
-
width: 22px;
|
| 97 |
-
height: 22px;
|
| 98 |
-
margin: var(--spacing-lg) var(--spacing-xs);
|
| 99 |
-
padding: var(--spacing-xs);
|
| 100 |
-
color: var(--neutral-400);
|
| 101 |
-
border-radius: var(--radius-md);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
.selected {
|
| 105 |
-
color: var(--color-accent);
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
.icon:hover,
|
| 109 |
-
.icon:focus {
|
| 110 |
-
color: var(--color-accent);
|
| 111 |
-
}
|
| 112 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/ShareButton.svelte
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import IconButton from "./IconButton.svelte";
|
| 3 |
-
import { Community } from "@gradio/icons";
|
| 4 |
-
import { createEventDispatcher } from "svelte";
|
| 5 |
-
import type { ShareData } from "@gradio/utils";
|
| 6 |
-
import { ShareError } from "@gradio/utils";
|
| 7 |
-
import type { I18nFormatter } from "@gradio/utils";
|
| 8 |
-
|
| 9 |
-
const dispatch = createEventDispatcher<{
|
| 10 |
-
share: ShareData;
|
| 11 |
-
error: string;
|
| 12 |
-
}>();
|
| 13 |
-
|
| 14 |
-
export let formatter: (arg0: any) => Promise<string>;
|
| 15 |
-
export let value: any;
|
| 16 |
-
export let i18n: I18nFormatter;
|
| 17 |
-
let pending = false;
|
| 18 |
-
</script>
|
| 19 |
-
|
| 20 |
-
<IconButton
|
| 21 |
-
Icon={Community}
|
| 22 |
-
label={i18n("common.share")}
|
| 23 |
-
{pending}
|
| 24 |
-
onclick={async () => {
|
| 25 |
-
try {
|
| 26 |
-
pending = true;
|
| 27 |
-
const formatted = await formatter(value);
|
| 28 |
-
dispatch("share", {
|
| 29 |
-
description: formatted
|
| 30 |
-
});
|
| 31 |
-
} catch (e) {
|
| 32 |
-
console.error(e);
|
| 33 |
-
let message = e instanceof ShareError ? e.message : "Share failed.";
|
| 34 |
-
dispatch("error", message);
|
| 35 |
-
} finally {
|
| 36 |
-
pending = false;
|
| 37 |
-
}
|
| 38 |
-
}}
|
| 39 |
-
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/Toolbar.svelte
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
export let show_border = false;
|
| 3 |
-
</script>
|
| 4 |
-
|
| 5 |
-
<div class:show_border>
|
| 6 |
-
<slot />
|
| 7 |
-
</div>
|
| 8 |
-
|
| 9 |
-
<style>
|
| 10 |
-
div {
|
| 11 |
-
border-top: 1px solid transparent;
|
| 12 |
-
display: flex;
|
| 13 |
-
max-height: 100%;
|
| 14 |
-
justify-content: center;
|
| 15 |
-
align-items: center;
|
| 16 |
-
gap: var(--spacing-sm);
|
| 17 |
-
height: auto;
|
| 18 |
-
align-items: flex-end;
|
| 19 |
-
color: var(--block-label-text-color);
|
| 20 |
-
flex-shrink: 0;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
.show_border {
|
| 24 |
-
border-top: 1px solid var(--block-border-color);
|
| 25 |
-
margin-top: var(--spacing-xxl);
|
| 26 |
-
box-shadow: var(--shadow-drop);
|
| 27 |
-
}
|
| 28 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/UploadText.svelte
DELETED
|
@@ -1,102 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import type { I18nFormatter } from "@gradio/utils";
|
| 3 |
-
import { Upload as UploadIcon, ImagePaste } from "@gradio/icons";
|
| 4 |
-
import { inject } from "./utils/parse_placeholder";
|
| 5 |
-
|
| 6 |
-
export let type:
|
| 7 |
-
| "video"
|
| 8 |
-
| "image"
|
| 9 |
-
| "audio"
|
| 10 |
-
| "file"
|
| 11 |
-
| "csv"
|
| 12 |
-
| "clipboard"
|
| 13 |
-
| "gallery" = "file";
|
| 14 |
-
export let i18n: I18nFormatter;
|
| 15 |
-
export let message: string | undefined = undefined;
|
| 16 |
-
export let mode: "full" | "short" = "full";
|
| 17 |
-
export let hovered = false;
|
| 18 |
-
export let placeholder: string | undefined = undefined;
|
| 19 |
-
|
| 20 |
-
const defs = {
|
| 21 |
-
image: "upload_text.drop_image",
|
| 22 |
-
video: "upload_text.drop_video",
|
| 23 |
-
audio: "upload_text.drop_audio",
|
| 24 |
-
file: "upload_text.drop_file",
|
| 25 |
-
csv: "upload_text.drop_csv",
|
| 26 |
-
gallery: "upload_text.drop_gallery",
|
| 27 |
-
clipboard: "upload_text.paste_clipboard"
|
| 28 |
-
};
|
| 29 |
-
|
| 30 |
-
$: [heading, paragraph] = placeholder ? inject(placeholder) : [false, false];
|
| 31 |
-
</script>
|
| 32 |
-
|
| 33 |
-
<div class="wrap">
|
| 34 |
-
<span class="icon-wrap" class:hovered>
|
| 35 |
-
{#if type === "clipboard"}
|
| 36 |
-
<ImagePaste />
|
| 37 |
-
{:else}
|
| 38 |
-
<UploadIcon />
|
| 39 |
-
{/if}
|
| 40 |
-
</span>
|
| 41 |
-
|
| 42 |
-
{#if heading || paragraph}
|
| 43 |
-
{#if heading}
|
| 44 |
-
<h2>{heading}</h2>
|
| 45 |
-
{/if}
|
| 46 |
-
{#if paragraph}
|
| 47 |
-
<p>{paragraph}</p>
|
| 48 |
-
{/if}
|
| 49 |
-
{:else}
|
| 50 |
-
{i18n(defs[type] || defs.file)}
|
| 51 |
-
|
| 52 |
-
{#if mode !== "short"}
|
| 53 |
-
<span class="or">- {i18n("common.or")} -</span>
|
| 54 |
-
{message || i18n("upload_text.click_to_upload")}
|
| 55 |
-
{/if}
|
| 56 |
-
{/if}
|
| 57 |
-
</div>
|
| 58 |
-
|
| 59 |
-
<style>
|
| 60 |
-
h2 {
|
| 61 |
-
font-size: var(--text-xl) !important;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
p,
|
| 65 |
-
h2 {
|
| 66 |
-
white-space: pre-line;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
.wrap {
|
| 70 |
-
display: flex;
|
| 71 |
-
flex-direction: column;
|
| 72 |
-
justify-content: center;
|
| 73 |
-
align-items: center;
|
| 74 |
-
min-height: var(--size-60);
|
| 75 |
-
color: var(--block-label-text-color);
|
| 76 |
-
line-height: var(--line-md);
|
| 77 |
-
height: 100%;
|
| 78 |
-
padding-top: var(--size-3);
|
| 79 |
-
text-align: center;
|
| 80 |
-
margin: auto var(--spacing-lg);
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
.or {
|
| 84 |
-
color: var(--body-text-color-subdued);
|
| 85 |
-
display: flex;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
.icon-wrap {
|
| 89 |
-
width: 30px;
|
| 90 |
-
margin-bottom: var(--spacing-lg);
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
@media (--screen-md) {
|
| 94 |
-
.wrap {
|
| 95 |
-
font-size: var(--text-lg);
|
| 96 |
-
}
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
.hovered {
|
| 100 |
-
color: var(--color-accent);
|
| 101 |
-
}
|
| 102 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
| 1 |
-
export { default as Block } from "./Block.svelte";
|
| 2 |
-
export { default as BlockTitle } from "./BlockTitle.svelte";
|
| 3 |
-
export { default as BlockLabel } from "./BlockLabel.svelte";
|
| 4 |
-
export { default as DownloadLink } from "./DownloadLink.svelte";
|
| 5 |
-
export { default as IconButton } from "./IconButton.svelte";
|
| 6 |
-
export { default as Empty } from "./Empty.svelte";
|
| 7 |
-
export { default as Info } from "./Info.svelte";
|
| 8 |
-
export { default as ShareButton } from "./ShareButton.svelte";
|
| 9 |
-
export { default as UploadText } from "./UploadText.svelte";
|
| 10 |
-
export { default as Toolbar } from "./Toolbar.svelte";
|
| 11 |
-
export { default as SelectSource } from "./SelectSource.svelte";
|
| 12 |
-
export { default as IconButtonWrapper } from "./IconButtonWrapper.svelte";
|
| 13 |
-
export { default as FullscreenButton } from "./FullscreenButton.svelte";
|
| 14 |
-
export { default as CustomButton } from "./CustomButton.svelte";
|
| 15 |
-
export { default as ScrollFade } from "./ScrollFade.svelte";
|
| 16 |
-
|
| 17 |
-
export const BLOCK_KEY = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/inline-markdown.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
export const INLINE_CODE_RE = /`([^`]+)`/g;
|
| 2 |
-
export const LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g;
|
| 3 |
-
export const BOLD_ASTERISK_RE = /\*\*(.+?)\*\*/g;
|
| 4 |
-
export const BOLD_UNDERSCORE_RE = /__(.+?)__/g;
|
| 5 |
-
export const ITALIC_ASTERISK_RE = /\*(.+?)\*/g;
|
| 6 |
-
export const ITALIC_UNDERSCORE_RE = /(?<!\w)_(.+?)_(?!\w)/g;
|
| 7 |
-
export const PROTOCOL_RE = /^\w+:/;
|
| 8 |
-
|
| 9 |
-
export function escape_html(text: string): string {
|
| 10 |
-
return text
|
| 11 |
-
.replace(/&/g, "&")
|
| 12 |
-
.replace(/</g, "<")
|
| 13 |
-
.replace(/>/g, ">")
|
| 14 |
-
.replace(/"/g, """);
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
function render_link(_match: string, text: string, url: string): string {
|
| 18 |
-
const trimmed = url.trim();
|
| 19 |
-
if (PROTOCOL_RE.test(trimmed)) {
|
| 20 |
-
if (/^https?:/i.test(trimmed)) {
|
| 21 |
-
return `<a href="${trimmed}" target="_blank" rel="noopener noreferrer">${text}</a>`;
|
| 22 |
-
}
|
| 23 |
-
return text;
|
| 24 |
-
}
|
| 25 |
-
return `<a href="${trimmed}" target="_blank" rel="noopener noreferrer">${text}</a>`;
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
export function render_inline_markdown(text: string): string {
|
| 29 |
-
let result = escape_html(text);
|
| 30 |
-
|
| 31 |
-
result = result.replace(INLINE_CODE_RE, "<code>$1</code>");
|
| 32 |
-
result = result.replace(LINK_RE, render_link);
|
| 33 |
-
result = result.replace(BOLD_ASTERISK_RE, "<strong>$1</strong>");
|
| 34 |
-
result = result.replace(BOLD_UNDERSCORE_RE, "<strong>$1</strong>");
|
| 35 |
-
result = result.replace(ITALIC_ASTERISK_RE, "<em>$1</em>");
|
| 36 |
-
result = result.replace(ITALIC_UNDERSCORE_RE, "<em>$1</em>");
|
| 37 |
-
result = result.replace(/\n/g, "<br>");
|
| 38 |
-
|
| 39 |
-
return result;
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/atoms/src/utils/parse_placeholder.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
const RE_HEADING = /^(#\s*)(.+)$/m;
|
| 2 |
-
|
| 3 |
-
export function inject(text: string): [string | false, string | false] {
|
| 4 |
-
const trimmed_text = text.trim();
|
| 5 |
-
|
| 6 |
-
const heading_match = trimmed_text.match(RE_HEADING);
|
| 7 |
-
if (!heading_match) {
|
| 8 |
-
return [false, trimmed_text || false];
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
const [full_match, , heading_content] = heading_match;
|
| 12 |
-
const _heading = heading_content.trim();
|
| 13 |
-
|
| 14 |
-
if (trimmed_text === full_match) {
|
| 15 |
-
return [_heading, false];
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
const heading_end_index =
|
| 19 |
-
heading_match.index !== undefined
|
| 20 |
-
? heading_match.index + full_match.length
|
| 21 |
-
: 0;
|
| 22 |
-
const remaining_text = trimmed_text.substring(heading_end_index).trim();
|
| 23 |
-
|
| 24 |
-
const _paragraph = remaining_text || false;
|
| 25 |
-
|
| 26 |
-
return [_heading, _paragraph];
|
| 27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/Example.svelte
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
let {
|
| 3 |
-
value,
|
| 4 |
-
type,
|
| 5 |
-
selected = false
|
| 6 |
-
}: {
|
| 7 |
-
value: string | null;
|
| 8 |
-
type: "gallery" | "table";
|
| 9 |
-
selected?: boolean;
|
| 10 |
-
} = $props();
|
| 11 |
-
</script>
|
| 12 |
-
|
| 13 |
-
<div
|
| 14 |
-
class:table={type === "table"}
|
| 15 |
-
class:gallery={type === "gallery"}
|
| 16 |
-
class:selected
|
| 17 |
-
>
|
| 18 |
-
{value ? value : ""}
|
| 19 |
-
</div>
|
| 20 |
-
|
| 21 |
-
<style>
|
| 22 |
-
.gallery {
|
| 23 |
-
padding: var(--size-1) var(--size-2);
|
| 24 |
-
}
|
| 25 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/Index.svelte
DELETED
|
@@ -1,234 +0,0 @@
|
|
| 1 |
-
<svelte:options accessors={true} />
|
| 2 |
-
|
| 3 |
-
<script lang="ts">
|
| 4 |
-
import { onMount, tick } from "svelte";
|
| 5 |
-
import { Gradio } from "@gradio/utils";
|
| 6 |
-
import { StatusTracker } from "@gradio/statustracker";
|
| 7 |
-
|
| 8 |
-
import StaticAudio from "./static/StaticAudio.svelte";
|
| 9 |
-
import InteractiveAudio from "./interactive/InteractiveAudio.svelte";
|
| 10 |
-
import { Block, UploadText } from "@gradio/atoms";
|
| 11 |
-
import type { AudioEvents, AudioProps } from "./shared/types";
|
| 12 |
-
|
| 13 |
-
let props = $props();
|
| 14 |
-
let upload_promise = $state<Promise<any>>();
|
| 15 |
-
|
| 16 |
-
props.props.stream_every = 0.1; // default to 0.1s stream interval
|
| 17 |
-
|
| 18 |
-
class AudioGradio extends Gradio<AudioEvents, AudioProps> {
|
| 19 |
-
async get_data() {
|
| 20 |
-
if (upload_promise) {
|
| 21 |
-
await upload_promise;
|
| 22 |
-
await tick();
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
const data = await super.get_data();
|
| 26 |
-
|
| 27 |
-
return data;
|
| 28 |
-
}
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
const gradio = new AudioGradio(props);
|
| 32 |
-
let label = $derived(gradio.shared.label || gradio.i18n("audio.audio"));
|
| 33 |
-
let minimal = $derived(
|
| 34 |
-
(props as any).minimal ?? (gradio.props as any).minimal ?? false
|
| 35 |
-
);
|
| 36 |
-
|
| 37 |
-
let active_source = $derived.by(() =>
|
| 38 |
-
gradio.props.sources ? gradio.props.sources[0] : null
|
| 39 |
-
);
|
| 40 |
-
let initial_value = $state(gradio.props.value);
|
| 41 |
-
|
| 42 |
-
const handle_reset_value = (): void => {
|
| 43 |
-
if (initial_value === null || gradio.props.value === initial_value) {
|
| 44 |
-
return;
|
| 45 |
-
}
|
| 46 |
-
gradio.props.value = initial_value;
|
| 47 |
-
};
|
| 48 |
-
|
| 49 |
-
let dragging = $state(false);
|
| 50 |
-
let recording = $state(gradio.props.recording ?? false);
|
| 51 |
-
$effect(() => {
|
| 52 |
-
gradio.props.recording = recording;
|
| 53 |
-
});
|
| 54 |
-
|
| 55 |
-
let color_accent = "darkorange";
|
| 56 |
-
|
| 57 |
-
let waveform_settings = $state({
|
| 58 |
-
height: 50,
|
| 59 |
-
barWidth: 2,
|
| 60 |
-
barGap: 3,
|
| 61 |
-
cursorWidth: 2,
|
| 62 |
-
cursorColor: "#ddd5e9",
|
| 63 |
-
autoplay: gradio.props.autoplay,
|
| 64 |
-
barRadius: 10,
|
| 65 |
-
dragToSeek: true,
|
| 66 |
-
normalize: true,
|
| 67 |
-
minPxPerSec: 20,
|
| 68 |
-
waveColor: gradio.props.waveform_options.waveform_color || "#9ca3af",
|
| 69 |
-
progressColor:
|
| 70 |
-
gradio.props.waveform_options.waveform_progress_color || color_accent,
|
| 71 |
-
mediaControls: gradio.props.waveform_options.show_controls ?? false,
|
| 72 |
-
sampleRate: gradio.props.waveform_options.sample_rate || 44100
|
| 73 |
-
});
|
| 74 |
-
|
| 75 |
-
const trim_region_settings = {
|
| 76 |
-
color: gradio.props.waveform_options.trim_region_color,
|
| 77 |
-
drag: true,
|
| 78 |
-
resize: true
|
| 79 |
-
};
|
| 80 |
-
|
| 81 |
-
function set_trim_region_colour(): void {
|
| 82 |
-
document.documentElement.style.setProperty(
|
| 83 |
-
"--trim-region-color",
|
| 84 |
-
trim_region_settings.color || color_accent
|
| 85 |
-
);
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
function handle_error(detail: string): void {
|
| 89 |
-
const [level, status] = detail.includes("Invalid file type")
|
| 90 |
-
? ["warning", "complete"]
|
| 91 |
-
: ["error", "error"];
|
| 92 |
-
if (gradio.shared.loading_status) {
|
| 93 |
-
(gradio.shared.loading_status as any).status = status;
|
| 94 |
-
(gradio.shared.loading_status as any).message = detail;
|
| 95 |
-
}
|
| 96 |
-
gradio.dispatch(level as "error" | "warning", detail);
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
gradio.watch_for_change();
|
| 100 |
-
|
| 101 |
-
onMount(() => {
|
| 102 |
-
set_trim_region_colour();
|
| 103 |
-
});
|
| 104 |
-
</script>
|
| 105 |
-
|
| 106 |
-
{#if !gradio.shared.interactive}
|
| 107 |
-
<Block
|
| 108 |
-
variant={"solid"}
|
| 109 |
-
border_mode={dragging ? "focus" : "base"}
|
| 110 |
-
padding={false}
|
| 111 |
-
allow_overflow={false}
|
| 112 |
-
elem_id={gradio.shared.elem_id}
|
| 113 |
-
elem_classes={gradio.shared.elem_classes}
|
| 114 |
-
visible={gradio.shared.visible}
|
| 115 |
-
container={gradio.shared.container}
|
| 116 |
-
scale={gradio.shared.scale}
|
| 117 |
-
min_width={gradio.shared.min_width}
|
| 118 |
-
>
|
| 119 |
-
<StatusTracker
|
| 120 |
-
autoscroll={gradio.shared.autoscroll}
|
| 121 |
-
i18n={gradio.i18n}
|
| 122 |
-
{...gradio.shared.loading_status}
|
| 123 |
-
on_clear_status={() =>
|
| 124 |
-
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
| 125 |
-
/>
|
| 126 |
-
|
| 127 |
-
<StaticAudio
|
| 128 |
-
i18n={gradio.i18n}
|
| 129 |
-
show_label={gradio.shared.show_label}
|
| 130 |
-
buttons={gradio.props.buttons ?? ["download", "share"]}
|
| 131 |
-
value={gradio.props.value}
|
| 132 |
-
subtitles={gradio.props.subtitles}
|
| 133 |
-
{label}
|
| 134 |
-
loop={gradio.props.loop}
|
| 135 |
-
{waveform_settings}
|
| 136 |
-
waveform_options={gradio.props.waveform_options}
|
| 137 |
-
editable={gradio.props.editable}
|
| 138 |
-
{minimal}
|
| 139 |
-
on_custom_button_click={(id) => {
|
| 140 |
-
gradio.dispatch("custom_button_click", { id });
|
| 141 |
-
}}
|
| 142 |
-
bind:playback_position={gradio.props.playback_position}
|
| 143 |
-
onshare={(detail) => gradio.dispatch("share", detail)}
|
| 144 |
-
onerror={(e) => gradio.dispatch("error", e.detail)}
|
| 145 |
-
onplay={() => gradio.dispatch("play")}
|
| 146 |
-
onpause={() => gradio.dispatch("pause")}
|
| 147 |
-
onstop={() => gradio.dispatch("stop")}
|
| 148 |
-
/>
|
| 149 |
-
</Block>
|
| 150 |
-
{:else}
|
| 151 |
-
<Block
|
| 152 |
-
variant={gradio.props.value === null && active_source === "upload"
|
| 153 |
-
? "dashed"
|
| 154 |
-
: "solid"}
|
| 155 |
-
border_mode={dragging ? "focus" : "base"}
|
| 156 |
-
padding={false}
|
| 157 |
-
allow_overflow={false}
|
| 158 |
-
elem_id={gradio.shared.elem_id}
|
| 159 |
-
elem_classes={gradio.shared.elem_classes}
|
| 160 |
-
visible={gradio.shared.visible}
|
| 161 |
-
container={gradio.shared.container}
|
| 162 |
-
scale={gradio.shared.scale}
|
| 163 |
-
min_width={gradio.shared.min_width}
|
| 164 |
-
>
|
| 165 |
-
<StatusTracker
|
| 166 |
-
autoscroll={gradio.shared.autoscroll}
|
| 167 |
-
i18n={gradio.i18n}
|
| 168 |
-
{...gradio.shared.loading_status}
|
| 169 |
-
on_clear_status={() =>
|
| 170 |
-
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
| 171 |
-
/>
|
| 172 |
-
<InteractiveAudio
|
| 173 |
-
bind:upload_promise
|
| 174 |
-
bind:initial_value
|
| 175 |
-
{label}
|
| 176 |
-
show_label={gradio.shared.show_label}
|
| 177 |
-
buttons={gradio.props.buttons ?? []}
|
| 178 |
-
on_custom_button_click={(id) => {
|
| 179 |
-
gradio.dispatch("custom_button_click", { id });
|
| 180 |
-
}}
|
| 181 |
-
value={gradio.props.value}
|
| 182 |
-
subtitles={gradio.props.subtitles}
|
| 183 |
-
onchange={(detail) => (gradio.props.value = detail)}
|
| 184 |
-
onstream={(detail) => {
|
| 185 |
-
gradio.props.value = detail;
|
| 186 |
-
gradio.dispatch("stream", gradio.props.value);
|
| 187 |
-
}}
|
| 188 |
-
ondrag={(detail) => (dragging = detail)}
|
| 189 |
-
root={gradio.shared.root}
|
| 190 |
-
sources={gradio.props.sources}
|
| 191 |
-
active_source={active_source || undefined}
|
| 192 |
-
pending={gradio.shared.loading_status.pending}
|
| 193 |
-
streaming={gradio.props.streaming}
|
| 194 |
-
bind:recording
|
| 195 |
-
loop={gradio.props.loop}
|
| 196 |
-
max_file_size={gradio.shared.max_file_size}
|
| 197 |
-
{handle_reset_value}
|
| 198 |
-
editable={gradio.props.editable}
|
| 199 |
-
bind:dragging
|
| 200 |
-
bind:playback_position={gradio.props.playback_position}
|
| 201 |
-
onedit={() => gradio.dispatch("edit")}
|
| 202 |
-
onplay={() => gradio.dispatch("play")}
|
| 203 |
-
onpause={() => gradio.dispatch("pause")}
|
| 204 |
-
onstop={() => gradio.dispatch("stop")}
|
| 205 |
-
onstart_recording={() => gradio.dispatch("start_recording")}
|
| 206 |
-
onpause_recording={() => gradio.dispatch("pause_recording")}
|
| 207 |
-
onstop_recording={() => {
|
| 208 |
-
gradio.dispatch("stop_recording");
|
| 209 |
-
gradio.dispatch("input");
|
| 210 |
-
}}
|
| 211 |
-
onupload={() => {
|
| 212 |
-
gradio.dispatch("upload");
|
| 213 |
-
gradio.dispatch("input");
|
| 214 |
-
}}
|
| 215 |
-
onclear={() => {
|
| 216 |
-
gradio.dispatch("clear");
|
| 217 |
-
gradio.dispatch("input");
|
| 218 |
-
}}
|
| 219 |
-
onerror={handle_error}
|
| 220 |
-
onclose_stream={() => gradio.dispatch("close_stream", "stream")}
|
| 221 |
-
i18n={gradio.i18n}
|
| 222 |
-
{waveform_settings}
|
| 223 |
-
waveform_options={gradio.props.waveform_options}
|
| 224 |
-
{trim_region_settings}
|
| 225 |
-
stream_every={gradio.props.stream_every}
|
| 226 |
-
stream_state={gradio.shared.loading_status.stream_state}
|
| 227 |
-
upload={(...args) => gradio.shared.client.upload(...args)}
|
| 228 |
-
stream_handler={(...args) => gradio.shared.client.stream(...args)}
|
| 229 |
-
time_limit={gradio.shared.loading_status.time_limit}
|
| 230 |
-
>
|
| 231 |
-
<UploadText i18n={gradio.i18n} type="audio" />
|
| 232 |
-
</InteractiveAudio>
|
| 233 |
-
</Block>
|
| 234 |
-
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
import { default as Index } from "./Index.svelte";
|
| 2 |
-
export default Index;
|
| 3 |
-
export { default as BaseStaticAudio } from "./static/StaticAudio.svelte";
|
| 4 |
-
export { default as BaseInteractiveAudio } from "./interactive/InteractiveAudio.svelte";
|
| 5 |
-
export { default as BasePlayer } from "./player/AudioPlayer.svelte";
|
| 6 |
-
export type { WaveformOptions } from "./shared/types";
|
| 7 |
-
export { default as BaseExample } from "./Example.svelte";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/interactive/InteractiveAudio.svelte
DELETED
|
@@ -1,431 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onDestroy } from "svelte";
|
| 3 |
-
import { Upload, ModifyUpload } from "@gradio/upload";
|
| 4 |
-
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
| 5 |
-
import { BlockLabel, ShareButton, CustomButton } from "@gradio/atoms";
|
| 6 |
-
import { Music } from "@gradio/icons";
|
| 7 |
-
import { uploadToHuggingFace } from "@gradio/utils";
|
| 8 |
-
import { StreamingBar } from "@gradio/statustracker";
|
| 9 |
-
import AudioPlayer from "../player/AudioPlayer.svelte";
|
| 10 |
-
|
| 11 |
-
import type { IBlobEvent, IMediaRecorder } from "extendable-media-recorder";
|
| 12 |
-
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
| 13 |
-
import AudioRecorder from "../recorder/AudioRecorder.svelte";
|
| 14 |
-
import StreamAudio from "../streaming/StreamAudio.svelte";
|
| 15 |
-
import { init_media_recorder } from "../streaming/media_recorder";
|
| 16 |
-
import type { IMediaRecorderConstructor } from "extendable-media-recorder";
|
| 17 |
-
import { SelectSource } from "@gradio/atoms";
|
| 18 |
-
import type { WaveformOptions, SubtitleData } from "../shared/types";
|
| 19 |
-
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 20 |
-
|
| 21 |
-
let {
|
| 22 |
-
value = $bindable(null),
|
| 23 |
-
subtitles = null,
|
| 24 |
-
label,
|
| 25 |
-
root,
|
| 26 |
-
loop,
|
| 27 |
-
show_label = true,
|
| 28 |
-
buttons = ["download", "share"],
|
| 29 |
-
on_custom_button_click = null,
|
| 30 |
-
sources = ["microphone", "upload"],
|
| 31 |
-
pending = false,
|
| 32 |
-
streaming = false,
|
| 33 |
-
i18n,
|
| 34 |
-
waveform_settings,
|
| 35 |
-
trim_region_settings = {},
|
| 36 |
-
waveform_options = {},
|
| 37 |
-
dragging = $bindable(false),
|
| 38 |
-
active_source = $bindable<"microphone" | "upload">("microphone"),
|
| 39 |
-
handle_reset_value = () => {},
|
| 40 |
-
editable = true,
|
| 41 |
-
max_file_size = null,
|
| 42 |
-
upload,
|
| 43 |
-
stream_handler,
|
| 44 |
-
stream_every = 0.1,
|
| 45 |
-
uploading = $bindable(false),
|
| 46 |
-
recording = $bindable(false),
|
| 47 |
-
class_name = "",
|
| 48 |
-
upload_promise = $bindable(),
|
| 49 |
-
initial_value = $bindable(),
|
| 50 |
-
playback_position = $bindable(),
|
| 51 |
-
time_limit = null,
|
| 52 |
-
stream_state = "closed",
|
| 53 |
-
onchange,
|
| 54 |
-
onstream,
|
| 55 |
-
onedit,
|
| 56 |
-
onplay,
|
| 57 |
-
onpause,
|
| 58 |
-
onstop,
|
| 59 |
-
ondrag,
|
| 60 |
-
onerror,
|
| 61 |
-
onupload,
|
| 62 |
-
onclear,
|
| 63 |
-
onstart_recording,
|
| 64 |
-
onpause_recording,
|
| 65 |
-
onstop_recording,
|
| 66 |
-
onclose_stream,
|
| 67 |
-
children
|
| 68 |
-
}: {
|
| 69 |
-
value?: null | FileData;
|
| 70 |
-
subtitles?: null | FileData | SubtitleData[];
|
| 71 |
-
label: string;
|
| 72 |
-
root: string;
|
| 73 |
-
loop?: boolean;
|
| 74 |
-
show_label?: boolean;
|
| 75 |
-
buttons?: (string | CustomButtonType)[];
|
| 76 |
-
on_custom_button_click?: ((id: number) => void) | null;
|
| 77 |
-
sources?:
|
| 78 |
-
| ["microphone"]
|
| 79 |
-
| ["upload"]
|
| 80 |
-
| ["microphone", "upload"]
|
| 81 |
-
| ["upload", "microphone"];
|
| 82 |
-
pending?: boolean;
|
| 83 |
-
streaming?: boolean;
|
| 84 |
-
i18n: I18nFormatter;
|
| 85 |
-
waveform_settings: Record<string, any>;
|
| 86 |
-
trim_region_settings?: Record<string, any>;
|
| 87 |
-
waveform_options?: WaveformOptions;
|
| 88 |
-
dragging?: boolean;
|
| 89 |
-
active_source?: "microphone" | "upload";
|
| 90 |
-
handle_reset_value?: () => void;
|
| 91 |
-
editable?: boolean;
|
| 92 |
-
max_file_size?: number | null;
|
| 93 |
-
upload: Client["upload"];
|
| 94 |
-
stream_handler: Client["stream"];
|
| 95 |
-
stream_every?: number;
|
| 96 |
-
uploading?: boolean;
|
| 97 |
-
recording?: boolean;
|
| 98 |
-
class_name?: string;
|
| 99 |
-
upload_promise?: Promise<any> | null;
|
| 100 |
-
initial_value?: FileData | null;
|
| 101 |
-
playback_position?: number;
|
| 102 |
-
time_limit?: number | null;
|
| 103 |
-
stream_state?: "open" | "waiting" | "closed";
|
| 104 |
-
onchange?: (value: FileData | null) => void;
|
| 105 |
-
onstream?: (value: FileData) => void;
|
| 106 |
-
onedit?: () => void;
|
| 107 |
-
onplay?: () => void;
|
| 108 |
-
onpause?: () => void;
|
| 109 |
-
onstop?: () => void;
|
| 110 |
-
ondrag?: (dragging: boolean) => void;
|
| 111 |
-
onerror?: (error: string) => void;
|
| 112 |
-
onupload?: (value: FileData) => void;
|
| 113 |
-
onclear?: () => void;
|
| 114 |
-
onstart_recording?: () => void;
|
| 115 |
-
onpause_recording?: () => void;
|
| 116 |
-
onstop_recording?: () => void;
|
| 117 |
-
onclose_stream?: () => void;
|
| 118 |
-
children?: import("svelte").Snippet;
|
| 119 |
-
} = $props();
|
| 120 |
-
|
| 121 |
-
$effect(() => {
|
| 122 |
-
ondrag?.(dragging);
|
| 123 |
-
});
|
| 124 |
-
|
| 125 |
-
// TODO: make use of this
|
| 126 |
-
// export let type: "normal" | "numpy" = "normal";
|
| 127 |
-
let recorder: IMediaRecorder;
|
| 128 |
-
let mode = $state("");
|
| 129 |
-
let header: Uint8Array | undefined = undefined;
|
| 130 |
-
let pending_stream: Uint8Array[] = [];
|
| 131 |
-
let submit_pending_stream_on_pending_end = false;
|
| 132 |
-
let inited = false;
|
| 133 |
-
let streaming_media_recorder: IMediaRecorderConstructor;
|
| 134 |
-
|
| 135 |
-
const NUM_HEADER_BYTES = 44;
|
| 136 |
-
let audio_chunks: Blob[] = [];
|
| 137 |
-
const is_browser = typeof window !== "undefined";
|
| 138 |
-
if (is_browser && streaming) {
|
| 139 |
-
init_media_recorder().then((a) => {
|
| 140 |
-
streaming_media_recorder = a;
|
| 141 |
-
});
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
const to_blob_parts = (parts: Uint8Array[] | Blob[]): BlobPart[] =>
|
| 145 |
-
parts.map((part) => {
|
| 146 |
-
if (part instanceof Blob) return part;
|
| 147 |
-
return part.slice();
|
| 148 |
-
});
|
| 149 |
-
|
| 150 |
-
const dispatch_blob = async (
|
| 151 |
-
blobs: Uint8Array[] | Blob[],
|
| 152 |
-
event: "stream" | "change" | "stop_recording"
|
| 153 |
-
): Promise<void> => {
|
| 154 |
-
let _audio_blob = new File(to_blob_parts(blobs), "audio.wav", {
|
| 155 |
-
type: "audio/wav"
|
| 156 |
-
});
|
| 157 |
-
if (_audio_blob.size === 0) {
|
| 158 |
-
return;
|
| 159 |
-
}
|
| 160 |
-
const val = await prepare_files([_audio_blob], event === "stream");
|
| 161 |
-
initial_value = value;
|
| 162 |
-
value = (
|
| 163 |
-
(await upload(val, root, undefined, max_file_size || undefined))?.filter(
|
| 164 |
-
Boolean
|
| 165 |
-
) as FileData[]
|
| 166 |
-
)[0];
|
| 167 |
-
if (event === "stream") {
|
| 168 |
-
onstream?.(value);
|
| 169 |
-
} else if (event === "change") {
|
| 170 |
-
onchange?.(value);
|
| 171 |
-
} else if (event === "stop_recording") {
|
| 172 |
-
onstop_recording?.();
|
| 173 |
-
}
|
| 174 |
-
};
|
| 175 |
-
|
| 176 |
-
onDestroy(() => {
|
| 177 |
-
if (streaming && recorder && recorder.state !== "inactive") {
|
| 178 |
-
recorder.stop();
|
| 179 |
-
}
|
| 180 |
-
});
|
| 181 |
-
|
| 182 |
-
async function prepare_audio(): Promise<void> {
|
| 183 |
-
let stream: MediaStream | null;
|
| 184 |
-
|
| 185 |
-
try {
|
| 186 |
-
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 187 |
-
} catch (err) {
|
| 188 |
-
if (!navigator.mediaDevices) {
|
| 189 |
-
onerror?.(i18n("audio.no_device_support"));
|
| 190 |
-
return;
|
| 191 |
-
}
|
| 192 |
-
if (err instanceof DOMException && err.name == "NotAllowedError") {
|
| 193 |
-
onerror?.(i18n("audio.allow_recording_access"));
|
| 194 |
-
return;
|
| 195 |
-
}
|
| 196 |
-
throw err;
|
| 197 |
-
}
|
| 198 |
-
if (stream == null) return;
|
| 199 |
-
if (streaming) {
|
| 200 |
-
recorder = new streaming_media_recorder(stream, {
|
| 201 |
-
mimeType: "audio/wav"
|
| 202 |
-
});
|
| 203 |
-
|
| 204 |
-
recorder.addEventListener("dataavailable", handle_chunk);
|
| 205 |
-
} else {
|
| 206 |
-
recorder = new MediaRecorder(stream);
|
| 207 |
-
recorder.addEventListener("dataavailable", (event) => {
|
| 208 |
-
audio_chunks.push(event.data);
|
| 209 |
-
});
|
| 210 |
-
}
|
| 211 |
-
recorder.addEventListener("stop", async () => {
|
| 212 |
-
recording = false;
|
| 213 |
-
recorder.stop();
|
| 214 |
-
await dispatch_blob(audio_chunks, "change");
|
| 215 |
-
await dispatch_blob(audio_chunks, "stop_recording");
|
| 216 |
-
audio_chunks = [];
|
| 217 |
-
});
|
| 218 |
-
inited = true;
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
async function handle_chunk(event: IBlobEvent): Promise<void> {
|
| 222 |
-
let buffer = await event.data.arrayBuffer();
|
| 223 |
-
let payload = new Uint8Array(buffer);
|
| 224 |
-
if (!header) {
|
| 225 |
-
header = new Uint8Array(buffer.slice(0, NUM_HEADER_BYTES));
|
| 226 |
-
payload = new Uint8Array(buffer.slice(NUM_HEADER_BYTES));
|
| 227 |
-
}
|
| 228 |
-
if (pending) {
|
| 229 |
-
pending_stream.push(payload);
|
| 230 |
-
} else {
|
| 231 |
-
let blobParts = [header].concat(pending_stream, [payload]);
|
| 232 |
-
if (!recording || stream_state === "waiting") return;
|
| 233 |
-
dispatch_blob(blobParts, "stream");
|
| 234 |
-
pending_stream = [];
|
| 235 |
-
}
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
$effect(() => {
|
| 239 |
-
if (submit_pending_stream_on_pending_end && pending === false) {
|
| 240 |
-
submit_pending_stream_on_pending_end = false;
|
| 241 |
-
if (header && pending_stream) {
|
| 242 |
-
let blobParts: Uint8Array[] = [header].concat(pending_stream);
|
| 243 |
-
pending_stream = [];
|
| 244 |
-
dispatch_blob(blobParts, "stream");
|
| 245 |
-
}
|
| 246 |
-
}
|
| 247 |
-
});
|
| 248 |
-
|
| 249 |
-
async function record(): Promise<void> {
|
| 250 |
-
recording = true;
|
| 251 |
-
onstart_recording?.();
|
| 252 |
-
if (!inited) await prepare_audio();
|
| 253 |
-
|
| 254 |
-
header = undefined;
|
| 255 |
-
if (streaming && recorder.state != "recording") {
|
| 256 |
-
recorder.start(stream_every * 1000);
|
| 257 |
-
}
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
function clear(): void {
|
| 261 |
-
onchange?.(null);
|
| 262 |
-
onclear?.();
|
| 263 |
-
mode = "";
|
| 264 |
-
value = null;
|
| 265 |
-
}
|
| 266 |
-
|
| 267 |
-
function handle_load(detail: FileData): void {
|
| 268 |
-
value = detail;
|
| 269 |
-
onchange?.(detail);
|
| 270 |
-
onupload?.(detail);
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
async function stop(): Promise<void> {
|
| 274 |
-
recording = false;
|
| 275 |
-
|
| 276 |
-
if (streaming) {
|
| 277 |
-
onclose_stream?.();
|
| 278 |
-
onstop_recording?.();
|
| 279 |
-
recorder.stop();
|
| 280 |
-
|
| 281 |
-
if (pending) {
|
| 282 |
-
submit_pending_stream_on_pending_end = true;
|
| 283 |
-
}
|
| 284 |
-
await dispatch_blob(audio_chunks, "stop_recording");
|
| 285 |
-
onclear?.();
|
| 286 |
-
mode = "";
|
| 287 |
-
}
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
$effect(() => {
|
| 291 |
-
if (!recording && recorder && mode !== "") stop();
|
| 292 |
-
});
|
| 293 |
-
|
| 294 |
-
$effect(() => {
|
| 295 |
-
if (recording && recorder) record();
|
| 296 |
-
});
|
| 297 |
-
</script>
|
| 298 |
-
|
| 299 |
-
<BlockLabel
|
| 300 |
-
{show_label}
|
| 301 |
-
Icon={Music}
|
| 302 |
-
float={active_source === "upload" && value === null}
|
| 303 |
-
label={label || i18n("audio.audio")}
|
| 304 |
-
/>
|
| 305 |
-
<div
|
| 306 |
-
class="audio-container {class_name}"
|
| 307 |
-
data-testid={label ? "waveform-" + label : "unlabelled-audio"}
|
| 308 |
-
>
|
| 309 |
-
<StreamingBar {time_limit} />
|
| 310 |
-
{#if value == null || streaming}
|
| 311 |
-
{#if active_source === "microphone"}
|
| 312 |
-
<ModifyUpload {i18n} onclear={clear} />
|
| 313 |
-
{#if streaming}
|
| 314 |
-
<StreamAudio
|
| 315 |
-
{record}
|
| 316 |
-
{recording}
|
| 317 |
-
{stop}
|
| 318 |
-
{i18n}
|
| 319 |
-
{waveform_settings}
|
| 320 |
-
{waveform_options}
|
| 321 |
-
waiting={stream_state === "waiting"}
|
| 322 |
-
/>
|
| 323 |
-
{:else}
|
| 324 |
-
<AudioRecorder
|
| 325 |
-
bind:mode
|
| 326 |
-
{i18n}
|
| 327 |
-
{editable}
|
| 328 |
-
{recording}
|
| 329 |
-
{dispatch_blob}
|
| 330 |
-
{waveform_settings}
|
| 331 |
-
{waveform_options}
|
| 332 |
-
{handle_reset_value}
|
| 333 |
-
onstartrecording={() => onstart_recording?.()}
|
| 334 |
-
onpauserecording={() => onpause_recording?.()}
|
| 335 |
-
onstoprecording={() => onstop_recording?.()}
|
| 336 |
-
/>
|
| 337 |
-
{/if}
|
| 338 |
-
{:else if active_source === "upload"}
|
| 339 |
-
<!-- explicitly listed out audio mimetypes due to iOS bug not recognizing audio/* -->
|
| 340 |
-
<Upload
|
| 341 |
-
bind:upload_promise
|
| 342 |
-
filetype="audio/aac,audio/midi,audio/mpeg,audio/ogg,audio/wav,audio/x-wav,audio/opus,audio/webm,audio/flac,audio/vnd.rn-realaudio,audio/x-ms-wma,audio/x-aiff,audio/amr,audio/*"
|
| 343 |
-
onload={handle_load}
|
| 344 |
-
bind:dragging
|
| 345 |
-
bind:uploading
|
| 346 |
-
onerror={(detail: string) => onerror?.(detail)}
|
| 347 |
-
{root}
|
| 348 |
-
{max_file_size}
|
| 349 |
-
{upload}
|
| 350 |
-
{stream_handler}
|
| 351 |
-
aria_label={i18n("audio.drop_to_upload")}
|
| 352 |
-
>
|
| 353 |
-
{#if children}{@render children()}{/if}
|
| 354 |
-
</Upload>
|
| 355 |
-
{/if}
|
| 356 |
-
{:else}
|
| 357 |
-
<ModifyUpload
|
| 358 |
-
{i18n}
|
| 359 |
-
onclear={clear}
|
| 360 |
-
onedit={() => {
|
| 361 |
-
mode = "edit";
|
| 362 |
-
onedit?.();
|
| 363 |
-
}}
|
| 364 |
-
download={buttons === null
|
| 365 |
-
? value.url
|
| 366 |
-
: buttons.some((btn) => typeof btn === "string" && btn === "download")
|
| 367 |
-
? value.url
|
| 368 |
-
: null}
|
| 369 |
-
>
|
| 370 |
-
{#if value !== null && buttons}
|
| 371 |
-
{#each buttons as btn}
|
| 372 |
-
{#if typeof btn === "string"}
|
| 373 |
-
{#if btn === "share"}
|
| 374 |
-
<ShareButton
|
| 375 |
-
{i18n}
|
| 376 |
-
{onerror}
|
| 377 |
-
onshare={() => {}}
|
| 378 |
-
formatter={async (fileData: FileData) => {
|
| 379 |
-
if (!fileData || !fileData.url) return "";
|
| 380 |
-
let url = await uploadToHuggingFace(fileData.url, "url");
|
| 381 |
-
return `<audio controls src="${url}"></audio>`;
|
| 382 |
-
}}
|
| 383 |
-
{value}
|
| 384 |
-
/>
|
| 385 |
-
{/if}
|
| 386 |
-
{:else}
|
| 387 |
-
<CustomButton
|
| 388 |
-
button={btn}
|
| 389 |
-
on_click={(id: number) => {
|
| 390 |
-
if (on_custom_button_click) {
|
| 391 |
-
on_custom_button_click(id);
|
| 392 |
-
}
|
| 393 |
-
}}
|
| 394 |
-
/>
|
| 395 |
-
{/if}
|
| 396 |
-
{/each}
|
| 397 |
-
{/if}
|
| 398 |
-
</ModifyUpload>
|
| 399 |
-
|
| 400 |
-
<AudioPlayer
|
| 401 |
-
bind:mode
|
| 402 |
-
{value}
|
| 403 |
-
subtitles={Array.isArray(subtitles) ? subtitles : subtitles?.url}
|
| 404 |
-
{label}
|
| 405 |
-
{i18n}
|
| 406 |
-
{dispatch_blob}
|
| 407 |
-
{waveform_settings}
|
| 408 |
-
{waveform_options}
|
| 409 |
-
{trim_region_settings}
|
| 410 |
-
{handle_reset_value}
|
| 411 |
-
{editable}
|
| 412 |
-
{loop}
|
| 413 |
-
bind:playback_position
|
| 414 |
-
interactive
|
| 415 |
-
{onstop}
|
| 416 |
-
{onplay}
|
| 417 |
-
{onpause}
|
| 418 |
-
{onedit}
|
| 419 |
-
/>
|
| 420 |
-
{/if}
|
| 421 |
-
<SelectSource {sources} bind:active_source handle_clear={clear} />
|
| 422 |
-
</div>
|
| 423 |
-
|
| 424 |
-
<style>
|
| 425 |
-
.audio-container {
|
| 426 |
-
height: calc(var(--size-full) - var(--size-6));
|
| 427 |
-
display: flex;
|
| 428 |
-
flex-direction: column;
|
| 429 |
-
justify-content: space-between;
|
| 430 |
-
}
|
| 431 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/package.json
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "@gradio/audio",
|
| 3 |
-
"version": "0.23.1",
|
| 4 |
-
"description": "Gradio UI packages",
|
| 5 |
-
"type": "module",
|
| 6 |
-
"author": "",
|
| 7 |
-
"license": "ISC",
|
| 8 |
-
"private": false,
|
| 9 |
-
"dependencies": {
|
| 10 |
-
"@gradio/atoms": "workspace:^",
|
| 11 |
-
"@gradio/button": "workspace:^",
|
| 12 |
-
"@gradio/client": "workspace:^",
|
| 13 |
-
"@gradio/icons": "workspace:^",
|
| 14 |
-
"@gradio/statustracker": "workspace:^",
|
| 15 |
-
"@gradio/upload": "workspace:^",
|
| 16 |
-
"@gradio/utils": "workspace:^",
|
| 17 |
-
"extendable-media-recorder": "9.0.0",
|
| 18 |
-
"extendable-media-recorder-wav-encoder": "7.0.76",
|
| 19 |
-
"hls.js": "1.5.13",
|
| 20 |
-
"resize-observer-polyfill": "1.5.1",
|
| 21 |
-
"svelte-range-slider-pips": "4.1.0",
|
| 22 |
-
"wavesurfer.js": "7.11.0"
|
| 23 |
-
},
|
| 24 |
-
"devDependencies": {
|
| 25 |
-
"@gradio/preview": "workspace:^"
|
| 26 |
-
},
|
| 27 |
-
"main_changeset": true,
|
| 28 |
-
"main": "index.ts",
|
| 29 |
-
"exports": {
|
| 30 |
-
"./package.json": "./package.json",
|
| 31 |
-
".": {
|
| 32 |
-
"gradio": "./index.ts",
|
| 33 |
-
"svelte": "./dist/index.js",
|
| 34 |
-
"types": "./dist/index.d.ts"
|
| 35 |
-
},
|
| 36 |
-
"./example": {
|
| 37 |
-
"gradio": "./Example.svelte",
|
| 38 |
-
"svelte": "./dist/Example.svelte",
|
| 39 |
-
"types": "./dist/Example.svelte.d.ts"
|
| 40 |
-
},
|
| 41 |
-
"./shared": {
|
| 42 |
-
"gradio": "./shared/index.ts",
|
| 43 |
-
"svelte": "./dist/shared/index.js",
|
| 44 |
-
"types": "./dist/shared/index.d.ts"
|
| 45 |
-
},
|
| 46 |
-
"./base": {
|
| 47 |
-
"gradio": "./static/StaticAudio.svelte",
|
| 48 |
-
"svelte": "./dist/static/StaticAudio.svelte",
|
| 49 |
-
"types": "./dist/static/StaticAudio.svelte.d.ts"
|
| 50 |
-
}
|
| 51 |
-
},
|
| 52 |
-
"peerDependencies": {
|
| 53 |
-
"svelte": "^5.48.0"
|
| 54 |
-
},
|
| 55 |
-
"repository": {
|
| 56 |
-
"type": "git",
|
| 57 |
-
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 58 |
-
"directory": "js/audio"
|
| 59 |
-
}
|
| 60 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/player/AudioPlayer.svelte
DELETED
|
@@ -1,525 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount, untrack } from "svelte";
|
| 3 |
-
import { Music } from "@gradio/icons";
|
| 4 |
-
import { format_time, type I18nFormatter } from "@gradio/utils";
|
| 5 |
-
import WaveSurfer from "wavesurfer.js";
|
| 6 |
-
import { skip_audio, process_audio } from "../shared/utils";
|
| 7 |
-
import WaveformControls from "../shared/WaveformControls.svelte";
|
| 8 |
-
import { Empty } from "@gradio/atoms";
|
| 9 |
-
import type { FileData } from "@gradio/client";
|
| 10 |
-
import type { WaveformOptions, SubtitleData } from "../shared/types";
|
| 11 |
-
|
| 12 |
-
import Hls from "hls.js";
|
| 13 |
-
|
| 14 |
-
let {
|
| 15 |
-
value = null,
|
| 16 |
-
subtitles = null,
|
| 17 |
-
label,
|
| 18 |
-
i18n,
|
| 19 |
-
dispatch_blob = () => Promise.resolve(),
|
| 20 |
-
interactive = false,
|
| 21 |
-
editable = true,
|
| 22 |
-
trim_region_settings = {},
|
| 23 |
-
waveform_settings,
|
| 24 |
-
waveform_options,
|
| 25 |
-
mode = $bindable(),
|
| 26 |
-
loop,
|
| 27 |
-
handle_reset_value = () => {},
|
| 28 |
-
playback_position = $bindable(),
|
| 29 |
-
onstop,
|
| 30 |
-
onplay,
|
| 31 |
-
onpause,
|
| 32 |
-
onedit,
|
| 33 |
-
onload
|
| 34 |
-
}: {
|
| 35 |
-
value?: null | FileData;
|
| 36 |
-
subtitles?: null | string | SubtitleData[];
|
| 37 |
-
label: string;
|
| 38 |
-
i18n: I18nFormatter;
|
| 39 |
-
dispatch_blob?: (
|
| 40 |
-
blobs: Uint8Array[] | Blob[],
|
| 41 |
-
event: "stream" | "change" | "stop_recording"
|
| 42 |
-
) => Promise<void>;
|
| 43 |
-
interactive?: boolean;
|
| 44 |
-
editable?: boolean;
|
| 45 |
-
trim_region_settings?: Record<string, any>;
|
| 46 |
-
waveform_settings: Record<string, any>;
|
| 47 |
-
waveform_options: WaveformOptions;
|
| 48 |
-
mode?: string;
|
| 49 |
-
loop?: boolean;
|
| 50 |
-
handle_reset_value?: () => void;
|
| 51 |
-
playback_position?: number;
|
| 52 |
-
onstop?: () => void;
|
| 53 |
-
onplay?: () => void;
|
| 54 |
-
onpause?: () => void;
|
| 55 |
-
onedit?: () => void;
|
| 56 |
-
onload?: () => void;
|
| 57 |
-
} = $props();
|
| 58 |
-
|
| 59 |
-
let url = $derived(value?.url);
|
| 60 |
-
let old_playback_position = $state(0);
|
| 61 |
-
|
| 62 |
-
let container: HTMLDivElement;
|
| 63 |
-
let waveform: WaveSurfer | undefined;
|
| 64 |
-
let waveform_ready = $state(false);
|
| 65 |
-
let waveform_component_wrapper: HTMLDivElement;
|
| 66 |
-
let playing = $state(false);
|
| 67 |
-
|
| 68 |
-
let subtitle_container: HTMLDivElement;
|
| 69 |
-
|
| 70 |
-
let timeRef: HTMLTimeElement;
|
| 71 |
-
let durationRef: HTMLTimeElement;
|
| 72 |
-
let audio_duration = $state<number>(0);
|
| 73 |
-
|
| 74 |
-
let trimDuration = $state(0);
|
| 75 |
-
|
| 76 |
-
let show_volume_slider = $state(false);
|
| 77 |
-
let audio_player: HTMLAudioElement;
|
| 78 |
-
|
| 79 |
-
let stream_active = false;
|
| 80 |
-
let subtitles_toggle = $state(true);
|
| 81 |
-
let subtitle_event_handlers: (() => void)[] = [];
|
| 82 |
-
|
| 83 |
-
let use_waveform = $derived(
|
| 84 |
-
waveform_options.show_recording_waveform && !value?.is_stream
|
| 85 |
-
);
|
| 86 |
-
|
| 87 |
-
$effect(() => {
|
| 88 |
-
if (
|
| 89 |
-
waveform_ready &&
|
| 90 |
-
old_playback_position !== playback_position &&
|
| 91 |
-
audio_duration
|
| 92 |
-
) {
|
| 93 |
-
waveform?.seekTo(playback_position / audio_duration);
|
| 94 |
-
old_playback_position = playback_position;
|
| 95 |
-
}
|
| 96 |
-
});
|
| 97 |
-
|
| 98 |
-
const create_waveform = (): void => {
|
| 99 |
-
waveform = WaveSurfer.create({
|
| 100 |
-
container: container,
|
| 101 |
-
...waveform_settings
|
| 102 |
-
});
|
| 103 |
-
if (subtitles && waveform) {
|
| 104 |
-
if (subtitles_toggle) {
|
| 105 |
-
add_subtitles_to_waveform(waveform, subtitles);
|
| 106 |
-
} else {
|
| 107 |
-
hide_subtitles();
|
| 108 |
-
}
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
waveform?.on("init", () => {
|
| 112 |
-
waveform_ready = true;
|
| 113 |
-
});
|
| 114 |
-
waveform?.on("decode", (duration: any) => {
|
| 115 |
-
audio_duration = duration;
|
| 116 |
-
durationRef && (durationRef.textContent = format_time(duration));
|
| 117 |
-
});
|
| 118 |
-
|
| 119 |
-
let firstTimeUpdate = true;
|
| 120 |
-
waveform?.on("timeupdate", (currentTime: any) => {
|
| 121 |
-
timeRef && (timeRef.textContent = format_time(currentTime));
|
| 122 |
-
if (firstTimeUpdate) {
|
| 123 |
-
firstTimeUpdate = false;
|
| 124 |
-
return;
|
| 125 |
-
}
|
| 126 |
-
playback_position = currentTime;
|
| 127 |
-
old_playback_position = currentTime;
|
| 128 |
-
});
|
| 129 |
-
|
| 130 |
-
waveform?.on("interaction", () => {
|
| 131 |
-
const currentTime = waveform?.getCurrentTime() || 0;
|
| 132 |
-
timeRef && (timeRef.textContent = format_time(currentTime));
|
| 133 |
-
playback_position = currentTime;
|
| 134 |
-
old_playback_position = currentTime;
|
| 135 |
-
});
|
| 136 |
-
|
| 137 |
-
waveform?.on("ready", () => {
|
| 138 |
-
if (!waveform_settings.autoplay) {
|
| 139 |
-
waveform?.stop();
|
| 140 |
-
} else {
|
| 141 |
-
waveform?.play();
|
| 142 |
-
}
|
| 143 |
-
});
|
| 144 |
-
|
| 145 |
-
waveform?.on("finish", () => {
|
| 146 |
-
if (loop) {
|
| 147 |
-
waveform?.play();
|
| 148 |
-
} else {
|
| 149 |
-
playing = false;
|
| 150 |
-
onstop?.();
|
| 151 |
-
}
|
| 152 |
-
});
|
| 153 |
-
waveform?.on("pause", () => {
|
| 154 |
-
playing = false;
|
| 155 |
-
onpause?.();
|
| 156 |
-
});
|
| 157 |
-
waveform?.on("play", () => {
|
| 158 |
-
playing = true;
|
| 159 |
-
onplay?.();
|
| 160 |
-
});
|
| 161 |
-
|
| 162 |
-
waveform?.on("load", () => {
|
| 163 |
-
onload?.();
|
| 164 |
-
});
|
| 165 |
-
};
|
| 166 |
-
|
| 167 |
-
$effect(() => {
|
| 168 |
-
if (url && waveform_ready) {
|
| 169 |
-
untrack(() => {
|
| 170 |
-
if (value?.url && waveform) {
|
| 171 |
-
waveform.load(value.url).catch((e) => {
|
| 172 |
-
if (e.name !== "AbortError") {
|
| 173 |
-
console.error("Waveform load error:", e);
|
| 174 |
-
}
|
| 175 |
-
});
|
| 176 |
-
}
|
| 177 |
-
});
|
| 178 |
-
}
|
| 179 |
-
});
|
| 180 |
-
|
| 181 |
-
const handle_trim_audio = async (
|
| 182 |
-
start: number,
|
| 183 |
-
end: number
|
| 184 |
-
): Promise<void> => {
|
| 185 |
-
mode = "";
|
| 186 |
-
const decodedData = waveform?.getDecodedData();
|
| 187 |
-
if (decodedData) {
|
| 188 |
-
const trimmedBlob = await process_audio(
|
| 189 |
-
decodedData,
|
| 190 |
-
start,
|
| 191 |
-
end,
|
| 192 |
-
waveform_settings.sampleRate
|
| 193 |
-
);
|
| 194 |
-
await dispatch_blob([trimmedBlob], "change");
|
| 195 |
-
}
|
| 196 |
-
onedit?.();
|
| 197 |
-
};
|
| 198 |
-
|
| 199 |
-
async function load_audio(data: string): Promise<void> {
|
| 200 |
-
stream_active = false;
|
| 201 |
-
|
| 202 |
-
if (waveform_options.show_recording_waveform) {
|
| 203 |
-
waveform?.load(data);
|
| 204 |
-
} else if (audio_player) {
|
| 205 |
-
audio_player.src = data;
|
| 206 |
-
}
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
$effect(() => {
|
| 210 |
-
if (subtitles && waveform) {
|
| 211 |
-
if (subtitles_toggle) {
|
| 212 |
-
add_subtitles_to_waveform(waveform, subtitles);
|
| 213 |
-
} else {
|
| 214 |
-
hide_subtitles();
|
| 215 |
-
}
|
| 216 |
-
}
|
| 217 |
-
});
|
| 218 |
-
|
| 219 |
-
function load_stream(value: FileData | null): void {
|
| 220 |
-
if (!value || !value.is_stream || !value.url) return;
|
| 221 |
-
|
| 222 |
-
if (Hls.isSupported() && !stream_active) {
|
| 223 |
-
// Set config to start playback after 1 second of data received
|
| 224 |
-
const hls = new Hls({
|
| 225 |
-
maxBufferLength: 1,
|
| 226 |
-
maxMaxBufferLength: 1,
|
| 227 |
-
lowLatencyMode: true
|
| 228 |
-
});
|
| 229 |
-
hls.loadSource(value.url);
|
| 230 |
-
hls.attachMedia(audio_player);
|
| 231 |
-
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
| 232 |
-
if (waveform_settings.autoplay) audio_player.play();
|
| 233 |
-
});
|
| 234 |
-
hls.on(Hls.Events.ERROR, function (event, data) {
|
| 235 |
-
console.error("HLS error:", event, data);
|
| 236 |
-
if (data.fatal) {
|
| 237 |
-
switch (data.type) {
|
| 238 |
-
case Hls.ErrorTypes.NETWORK_ERROR:
|
| 239 |
-
console.error(
|
| 240 |
-
"Fatal network error encountered, trying to recover"
|
| 241 |
-
);
|
| 242 |
-
hls.startLoad();
|
| 243 |
-
break;
|
| 244 |
-
case Hls.ErrorTypes.MEDIA_ERROR:
|
| 245 |
-
console.error("Fatal media error encountered, trying to recover");
|
| 246 |
-
hls.recoverMediaError();
|
| 247 |
-
break;
|
| 248 |
-
default:
|
| 249 |
-
console.error("Fatal error, cannot recover");
|
| 250 |
-
hls.destroy();
|
| 251 |
-
break;
|
| 252 |
-
}
|
| 253 |
-
}
|
| 254 |
-
});
|
| 255 |
-
stream_active = true;
|
| 256 |
-
} else if (!stream_active) {
|
| 257 |
-
audio_player.src = value.url;
|
| 258 |
-
if (waveform_settings.autoplay) audio_player.play();
|
| 259 |
-
stream_active = true;
|
| 260 |
-
}
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
$effect(() => {
|
| 264 |
-
if (audio_player && url && waveform_ready && url) {
|
| 265 |
-
load_audio(url);
|
| 266 |
-
}
|
| 267 |
-
});
|
| 268 |
-
|
| 269 |
-
$effect(() => {
|
| 270 |
-
if (audio_player && value?.is_stream) {
|
| 271 |
-
load_stream(value);
|
| 272 |
-
}
|
| 273 |
-
});
|
| 274 |
-
|
| 275 |
-
onMount(() => {
|
| 276 |
-
create_waveform();
|
| 277 |
-
const handleKeydown = (e: KeyboardEvent): void => {
|
| 278 |
-
if (!waveform || show_volume_slider) return;
|
| 279 |
-
|
| 280 |
-
const is_focused_in_waveform =
|
| 281 |
-
waveform_component_wrapper &&
|
| 282 |
-
waveform_component_wrapper.contains(document.activeElement);
|
| 283 |
-
if (!is_focused_in_waveform) return;
|
| 284 |
-
if (e.key === "ArrowRight" && mode !== "edit") {
|
| 285 |
-
skip_audio(waveform, 0.1);
|
| 286 |
-
} else if (e.key === "ArrowLeft" && mode !== "edit") {
|
| 287 |
-
skip_audio(waveform, -0.1);
|
| 288 |
-
}
|
| 289 |
-
};
|
| 290 |
-
window.addEventListener("keydown", handleKeydown);
|
| 291 |
-
|
| 292 |
-
return () => {
|
| 293 |
-
waveform?.destroy();
|
| 294 |
-
window.removeEventListener("keydown", handleKeydown);
|
| 295 |
-
};
|
| 296 |
-
});
|
| 297 |
-
|
| 298 |
-
async function add_subtitles_to_waveform(
|
| 299 |
-
wavesurfer: WaveSurfer,
|
| 300 |
-
subtitle_data: string | SubtitleData[]
|
| 301 |
-
): Promise<void> {
|
| 302 |
-
clear_subtitles();
|
| 303 |
-
try {
|
| 304 |
-
let subtitles: SubtitleData[];
|
| 305 |
-
if (Array.isArray(subtitle_data)) {
|
| 306 |
-
subtitles = subtitle_data;
|
| 307 |
-
} else {
|
| 308 |
-
const response = await fetch(subtitle_data);
|
| 309 |
-
const subtitle_content = await response.text();
|
| 310 |
-
subtitles = parse_subtitles(subtitle_content);
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
if (subtitles.length > 0) {
|
| 314 |
-
let current_subtitle = "";
|
| 315 |
-
if (subtitle_container) {
|
| 316 |
-
subtitle_container.style.display = "";
|
| 317 |
-
const audioProcessHandler = (time: number): void => {
|
| 318 |
-
const subtitle = subtitles.find(
|
| 319 |
-
(s) => time >= s.start && time <= s.end
|
| 320 |
-
);
|
| 321 |
-
if (subtitle && subtitle.text !== current_subtitle) {
|
| 322 |
-
current_subtitle = subtitle.text;
|
| 323 |
-
subtitle_container.textContent = current_subtitle;
|
| 324 |
-
} else if (!subtitle && current_subtitle !== "") {
|
| 325 |
-
current_subtitle = "";
|
| 326 |
-
subtitle_container.textContent = "";
|
| 327 |
-
}
|
| 328 |
-
};
|
| 329 |
-
wavesurfer.on("audioprocess", audioProcessHandler);
|
| 330 |
-
subtitle_event_handlers.push(() => {
|
| 331 |
-
wavesurfer.un("audioprocess", audioProcessHandler);
|
| 332 |
-
});
|
| 333 |
-
}
|
| 334 |
-
}
|
| 335 |
-
} catch (error) {}
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
function hide_subtitles(): void {
|
| 339 |
-
if (subtitle_container) {
|
| 340 |
-
subtitle_container.style.display = "none";
|
| 341 |
-
}
|
| 342 |
-
}
|
| 343 |
-
|
| 344 |
-
function clear_subtitles(): void {
|
| 345 |
-
if (subtitle_container) {
|
| 346 |
-
subtitle_container.textContent = "";
|
| 347 |
-
}
|
| 348 |
-
subtitle_event_handlers.forEach((handler) => handler());
|
| 349 |
-
subtitle_event_handlers = [];
|
| 350 |
-
}
|
| 351 |
-
|
| 352 |
-
function parse_subtitles(subtitle_content: string): SubtitleData[] {
|
| 353 |
-
const lines = subtitle_content.split("\n");
|
| 354 |
-
const subtitles: SubtitleData[] = [];
|
| 355 |
-
|
| 356 |
-
for (let i = 0; i < lines.length; i++) {
|
| 357 |
-
const line = lines[i].trim();
|
| 358 |
-
if (line.includes(" --> ")) {
|
| 359 |
-
const [start_time, end_time] = line.split(" --> ");
|
| 360 |
-
const start = parse_time_to_seconds(start_time);
|
| 361 |
-
const end = parse_time_to_seconds(end_time);
|
| 362 |
-
|
| 363 |
-
let text = "";
|
| 364 |
-
for (let j = i + 1; j < lines.length && lines[j].trim() !== ""; j++) {
|
| 365 |
-
if (text) text += " ";
|
| 366 |
-
text += lines[j].trim();
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
if (text) {
|
| 370 |
-
subtitles.push({ start, end, text });
|
| 371 |
-
}
|
| 372 |
-
}
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
return subtitles;
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
function parse_time_to_seconds(time_str: string): number {
|
| 379 |
-
const parts = time_str.split(":");
|
| 380 |
-
if (parts.length === 3) {
|
| 381 |
-
const hours = parseInt(parts[0]);
|
| 382 |
-
const minutes = parseInt(parts[1]);
|
| 383 |
-
const seconds = parseFloat(parts[2]);
|
| 384 |
-
return hours * 3600 + minutes * 60 + seconds;
|
| 385 |
-
}
|
| 386 |
-
return 0;
|
| 387 |
-
}
|
| 388 |
-
</script>
|
| 389 |
-
|
| 390 |
-
<audio
|
| 391 |
-
class="standard-player"
|
| 392 |
-
class:hidden={use_waveform}
|
| 393 |
-
controls
|
| 394 |
-
autoplay={waveform_settings.autoplay}
|
| 395 |
-
{onload}
|
| 396 |
-
bind:this={audio_player}
|
| 397 |
-
onended={() => onstop?.()}
|
| 398 |
-
onplay={() => onplay?.()}
|
| 399 |
-
preload="metadata"
|
| 400 |
-
>
|
| 401 |
-
</audio>
|
| 402 |
-
{#if value === null}
|
| 403 |
-
<Empty size="small">
|
| 404 |
-
<Music />
|
| 405 |
-
</Empty>
|
| 406 |
-
{:else if use_waveform}
|
| 407 |
-
<div
|
| 408 |
-
class="component-wrapper"
|
| 409 |
-
data-testid={label ? "waveform-" + label : "unlabelled-audio"}
|
| 410 |
-
bind:this={waveform_component_wrapper}
|
| 411 |
-
>
|
| 412 |
-
<div class="waveform-container">
|
| 413 |
-
<div
|
| 414 |
-
id="waveform"
|
| 415 |
-
bind:this={container}
|
| 416 |
-
style:height={container ? null : "58px"}
|
| 417 |
-
/>
|
| 418 |
-
</div>
|
| 419 |
-
|
| 420 |
-
<div class="timestamps">
|
| 421 |
-
<time bind:this={timeRef} id="time">0:00</time>
|
| 422 |
-
<div>
|
| 423 |
-
{#if mode === "edit" && trimDuration > 0}
|
| 424 |
-
<time id="trim-duration">{format_time(trimDuration)}</time>
|
| 425 |
-
{/if}
|
| 426 |
-
<time bind:this={durationRef} id="duration">0:00</time>
|
| 427 |
-
</div>
|
| 428 |
-
</div>
|
| 429 |
-
|
| 430 |
-
<div
|
| 431 |
-
bind:this={subtitle_container}
|
| 432 |
-
class="subtitle-display"
|
| 433 |
-
data-testid="subtitle-display"
|
| 434 |
-
></div>
|
| 435 |
-
|
| 436 |
-
<WaveformControls
|
| 437 |
-
{container}
|
| 438 |
-
{waveform}
|
| 439 |
-
{playing}
|
| 440 |
-
{audio_duration}
|
| 441 |
-
{i18n}
|
| 442 |
-
{interactive}
|
| 443 |
-
{handle_trim_audio}
|
| 444 |
-
bind:mode
|
| 445 |
-
bind:trimDuration
|
| 446 |
-
bind:show_volume_slider
|
| 447 |
-
bind:subtitles_toggle
|
| 448 |
-
show_redo={interactive}
|
| 449 |
-
{handle_reset_value}
|
| 450 |
-
{waveform_options}
|
| 451 |
-
{trim_region_settings}
|
| 452 |
-
{editable}
|
| 453 |
-
show_subtitles={subtitles !== null}
|
| 454 |
-
/>
|
| 455 |
-
</div>
|
| 456 |
-
{/if}
|
| 457 |
-
|
| 458 |
-
<style>
|
| 459 |
-
.component-wrapper {
|
| 460 |
-
padding: var(--size-3);
|
| 461 |
-
width: 100%;
|
| 462 |
-
}
|
| 463 |
-
|
| 464 |
-
:global(::part(wrapper)) {
|
| 465 |
-
margin-bottom: var(--size-2);
|
| 466 |
-
}
|
| 467 |
-
|
| 468 |
-
.timestamps {
|
| 469 |
-
display: flex;
|
| 470 |
-
justify-content: space-between;
|
| 471 |
-
align-items: center;
|
| 472 |
-
width: 100%;
|
| 473 |
-
padding: var(--size-1) 0;
|
| 474 |
-
}
|
| 475 |
-
|
| 476 |
-
#time {
|
| 477 |
-
color: var(--neutral-400);
|
| 478 |
-
}
|
| 479 |
-
|
| 480 |
-
#duration {
|
| 481 |
-
color: var(--neutral-400);
|
| 482 |
-
}
|
| 483 |
-
|
| 484 |
-
#trim-duration {
|
| 485 |
-
color: var(--color-accent);
|
| 486 |
-
margin-right: var(--spacing-sm);
|
| 487 |
-
}
|
| 488 |
-
.waveform-container {
|
| 489 |
-
display: flex;
|
| 490 |
-
align-items: center;
|
| 491 |
-
justify-content: center;
|
| 492 |
-
width: var(--size-full);
|
| 493 |
-
}
|
| 494 |
-
|
| 495 |
-
#waveform {
|
| 496 |
-
width: 100%;
|
| 497 |
-
height: 100%;
|
| 498 |
-
position: relative;
|
| 499 |
-
}
|
| 500 |
-
|
| 501 |
-
.standard-player {
|
| 502 |
-
width: 100%;
|
| 503 |
-
padding: var(--size-2);
|
| 504 |
-
}
|
| 505 |
-
|
| 506 |
-
.subtitle-display {
|
| 507 |
-
color: var(--text-secondary);
|
| 508 |
-
font-size: var(--text-lg);
|
| 509 |
-
text-align: center;
|
| 510 |
-
max-width: 600px;
|
| 511 |
-
line-height: 1.3;
|
| 512 |
-
min-height: var(--size-4);
|
| 513 |
-
font-family: var(--font-sans);
|
| 514 |
-
font-weight: normal;
|
| 515 |
-
margin: var(--size-2) auto;
|
| 516 |
-
padding: var(--size-1) var(--size-2);
|
| 517 |
-
border-radius: 2px;
|
| 518 |
-
transition: opacity 0.2s ease-in-out;
|
| 519 |
-
}
|
| 520 |
-
|
| 521 |
-
.hidden,
|
| 522 |
-
.subtitle-display:empty {
|
| 523 |
-
display: none;
|
| 524 |
-
}
|
| 525 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/recorder/AudioRecorder.svelte
DELETED
|
@@ -1,315 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount } from "svelte";
|
| 3 |
-
import type { I18nFormatter } from "@gradio/utils";
|
| 4 |
-
import WaveSurfer from "wavesurfer.js";
|
| 5 |
-
import { skip_audio, process_audio } from "../shared/utils";
|
| 6 |
-
import WSRecord from "wavesurfer.js/dist/plugins/record.js";
|
| 7 |
-
import WaveformControls from "../shared/WaveformControls.svelte";
|
| 8 |
-
import WaveformRecordControls from "../shared/WaveformRecordControls.svelte";
|
| 9 |
-
import RecordPlugin from "wavesurfer.js/dist/plugins/record.js";
|
| 10 |
-
import type { WaveformOptions } from "../shared/types";
|
| 11 |
-
import { format_time } from "@gradio/utils";
|
| 12 |
-
|
| 13 |
-
let {
|
| 14 |
-
mode = $bindable(),
|
| 15 |
-
i18n,
|
| 16 |
-
dispatch_blob,
|
| 17 |
-
waveform_settings,
|
| 18 |
-
waveform_options = { show_recording_waveform: true },
|
| 19 |
-
handle_reset_value,
|
| 20 |
-
editable = true,
|
| 21 |
-
recording = false,
|
| 22 |
-
onstartrecording,
|
| 23 |
-
onpauserecording,
|
| 24 |
-
onstoprecording,
|
| 25 |
-
onstop,
|
| 26 |
-
onplay,
|
| 27 |
-
onpause,
|
| 28 |
-
onedit
|
| 29 |
-
}: {
|
| 30 |
-
mode?: string;
|
| 31 |
-
i18n: I18nFormatter;
|
| 32 |
-
dispatch_blob: (
|
| 33 |
-
blobs: Uint8Array[] | Blob[],
|
| 34 |
-
event: "stream" | "change" | "stop_recording"
|
| 35 |
-
) => Promise<void> | undefined;
|
| 36 |
-
waveform_settings: Record<string, any>;
|
| 37 |
-
waveform_options?: WaveformOptions;
|
| 38 |
-
handle_reset_value: () => void;
|
| 39 |
-
editable?: boolean;
|
| 40 |
-
recording?: boolean;
|
| 41 |
-
onstartrecording?: () => void;
|
| 42 |
-
onpauserecording?: () => void;
|
| 43 |
-
onstoprecording?: () => void;
|
| 44 |
-
onstop?: () => void;
|
| 45 |
-
onplay?: () => void;
|
| 46 |
-
onpause?: () => void;
|
| 47 |
-
onedit?: () => void;
|
| 48 |
-
} = $props();
|
| 49 |
-
|
| 50 |
-
let micWaveform: WaveSurfer;
|
| 51 |
-
let recordingWaveform = $state<WaveSurfer | undefined>(undefined);
|
| 52 |
-
let playing = $state(false);
|
| 53 |
-
|
| 54 |
-
let recordingContainer: HTMLDivElement;
|
| 55 |
-
let microphoneContainer: HTMLDivElement;
|
| 56 |
-
|
| 57 |
-
let record = $state<WSRecord | undefined>(undefined);
|
| 58 |
-
let recordedAudio = $state<string | null>(null);
|
| 59 |
-
|
| 60 |
-
// timestamps
|
| 61 |
-
let timeRef: HTMLTimeElement;
|
| 62 |
-
let durationRef: HTMLTimeElement;
|
| 63 |
-
let audio_duration = $state(0);
|
| 64 |
-
let seconds = $state(0);
|
| 65 |
-
let interval: NodeJS.Timeout;
|
| 66 |
-
let timing = $state(false);
|
| 67 |
-
// trimming
|
| 68 |
-
let trimDuration = $state(0);
|
| 69 |
-
let record_mounted = $state(false);
|
| 70 |
-
|
| 71 |
-
const start_interval = (): void => {
|
| 72 |
-
clearInterval(interval);
|
| 73 |
-
interval = setInterval(() => {
|
| 74 |
-
seconds++;
|
| 75 |
-
}, 1000);
|
| 76 |
-
};
|
| 77 |
-
|
| 78 |
-
function record_start_callback(): void {
|
| 79 |
-
start_interval();
|
| 80 |
-
timing = true;
|
| 81 |
-
onstartrecording?.();
|
| 82 |
-
if (waveform_options.show_recording_waveform) {
|
| 83 |
-
let waveformCanvas = microphoneContainer;
|
| 84 |
-
if (waveformCanvas) waveformCanvas.style.display = "block";
|
| 85 |
-
}
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
async function record_end_callback(blob: Blob): Promise<void> {
|
| 89 |
-
seconds = 0;
|
| 90 |
-
timing = false;
|
| 91 |
-
clearInterval(interval);
|
| 92 |
-
try {
|
| 93 |
-
const array_buffer = await blob.arrayBuffer();
|
| 94 |
-
const context = new AudioContext({
|
| 95 |
-
sampleRate: waveform_settings.sampleRate
|
| 96 |
-
});
|
| 97 |
-
const audio_buffer = await context.decodeAudioData(array_buffer);
|
| 98 |
-
|
| 99 |
-
if (audio_buffer)
|
| 100 |
-
await process_audio(audio_buffer).then(async (audio: Uint8Array) => {
|
| 101 |
-
await dispatch_blob([audio], "change");
|
| 102 |
-
await dispatch_blob([audio], "stop_recording");
|
| 103 |
-
});
|
| 104 |
-
} catch (e) {
|
| 105 |
-
console.error(e);
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
$effect(() => {
|
| 110 |
-
record?.on("record-resume", () => {
|
| 111 |
-
start_interval();
|
| 112 |
-
});
|
| 113 |
-
});
|
| 114 |
-
|
| 115 |
-
$effect(() => {
|
| 116 |
-
recordingWaveform?.on("decode", (duration: any) => {
|
| 117 |
-
audio_duration = duration;
|
| 118 |
-
durationRef && (durationRef.textContent = format_time(duration));
|
| 119 |
-
});
|
| 120 |
-
});
|
| 121 |
-
|
| 122 |
-
$effect(() => {
|
| 123 |
-
recordingWaveform?.on(
|
| 124 |
-
"timeupdate",
|
| 125 |
-
(currentTime: any) =>
|
| 126 |
-
timeRef && (timeRef.textContent = format_time(currentTime))
|
| 127 |
-
);
|
| 128 |
-
});
|
| 129 |
-
|
| 130 |
-
$effect(() => {
|
| 131 |
-
recordingWaveform?.on("pause", () => {
|
| 132 |
-
onpause?.();
|
| 133 |
-
playing = false;
|
| 134 |
-
});
|
| 135 |
-
});
|
| 136 |
-
|
| 137 |
-
$effect(() => {
|
| 138 |
-
recordingWaveform?.on("play", () => {
|
| 139 |
-
onplay?.();
|
| 140 |
-
playing = true;
|
| 141 |
-
});
|
| 142 |
-
});
|
| 143 |
-
|
| 144 |
-
$effect(() => {
|
| 145 |
-
recordingWaveform?.on("finish", () => {
|
| 146 |
-
onstop?.();
|
| 147 |
-
playing = false;
|
| 148 |
-
});
|
| 149 |
-
});
|
| 150 |
-
|
| 151 |
-
const create_mic_waveform = (): void => {
|
| 152 |
-
if (microphoneContainer) microphoneContainer.innerHTML = "";
|
| 153 |
-
if (micWaveform !== undefined) micWaveform.destroy();
|
| 154 |
-
if (!microphoneContainer) return;
|
| 155 |
-
micWaveform = WaveSurfer.create({
|
| 156 |
-
...waveform_settings,
|
| 157 |
-
normalize: false,
|
| 158 |
-
container: microphoneContainer
|
| 159 |
-
});
|
| 160 |
-
|
| 161 |
-
record = micWaveform.registerPlugin(RecordPlugin.create());
|
| 162 |
-
record?.on("record-end", record_end_callback);
|
| 163 |
-
record?.on("record-start", record_start_callback);
|
| 164 |
-
record?.on("record-pause", () => {
|
| 165 |
-
onpauserecording?.();
|
| 166 |
-
clearInterval(interval);
|
| 167 |
-
});
|
| 168 |
-
|
| 169 |
-
record?.on("record-end", (blob) => {
|
| 170 |
-
recordedAudio = URL.createObjectURL(blob);
|
| 171 |
-
|
| 172 |
-
const microphone = microphoneContainer;
|
| 173 |
-
const recording = recordingContainer;
|
| 174 |
-
|
| 175 |
-
if (microphone) microphone.style.display = "none";
|
| 176 |
-
if (recording && recordedAudio) {
|
| 177 |
-
recording.innerHTML = "";
|
| 178 |
-
create_recording_waveform();
|
| 179 |
-
}
|
| 180 |
-
});
|
| 181 |
-
record_mounted = true;
|
| 182 |
-
};
|
| 183 |
-
|
| 184 |
-
const create_recording_waveform = (): void => {
|
| 185 |
-
let recording = recordingContainer;
|
| 186 |
-
if (!recordedAudio || !recording) return;
|
| 187 |
-
recordingWaveform = WaveSurfer.create({
|
| 188 |
-
container: recording,
|
| 189 |
-
url: recordedAudio,
|
| 190 |
-
...waveform_settings
|
| 191 |
-
});
|
| 192 |
-
};
|
| 193 |
-
|
| 194 |
-
const handle_trim_audio = async (
|
| 195 |
-
start: number,
|
| 196 |
-
end: number
|
| 197 |
-
): Promise<void> => {
|
| 198 |
-
mode = "edit";
|
| 199 |
-
const decodedData = recordingWaveform?.getDecodedData();
|
| 200 |
-
if (decodedData)
|
| 201 |
-
await process_audio(decodedData, start, end).then(
|
| 202 |
-
async (trimmedAudio: Uint8Array) => {
|
| 203 |
-
await dispatch_blob([trimmedAudio], "change");
|
| 204 |
-
await dispatch_blob([trimmedAudio], "stop_recording");
|
| 205 |
-
recordingWaveform?.destroy();
|
| 206 |
-
create_recording_waveform();
|
| 207 |
-
}
|
| 208 |
-
);
|
| 209 |
-
onedit?.();
|
| 210 |
-
};
|
| 211 |
-
|
| 212 |
-
onMount(() => {
|
| 213 |
-
create_mic_waveform();
|
| 214 |
-
|
| 215 |
-
window.addEventListener("keydown", (e) => {
|
| 216 |
-
const is_focused_in_waveform =
|
| 217 |
-
recordingContainer &&
|
| 218 |
-
recordingContainer.contains(document.activeElement);
|
| 219 |
-
if (!is_focused_in_waveform) return;
|
| 220 |
-
if (e.key === "ArrowRight") {
|
| 221 |
-
skip_audio(recordingWaveform, 0.1);
|
| 222 |
-
} else if (e.key === "ArrowLeft") {
|
| 223 |
-
skip_audio(recordingWaveform, -0.1);
|
| 224 |
-
}
|
| 225 |
-
});
|
| 226 |
-
});
|
| 227 |
-
</script>
|
| 228 |
-
|
| 229 |
-
<div class="component-wrapper">
|
| 230 |
-
<div
|
| 231 |
-
class="microphone"
|
| 232 |
-
bind:this={microphoneContainer}
|
| 233 |
-
data-testid="microphone-waveform"
|
| 234 |
-
/>
|
| 235 |
-
<div bind:this={recordingContainer} data-testid="recording-waveform" />
|
| 236 |
-
|
| 237 |
-
{#if (timing || recordedAudio) && waveform_options.show_recording_waveform}
|
| 238 |
-
<div class="timestamps">
|
| 239 |
-
<time bind:this={timeRef} class="time">0:00</time>
|
| 240 |
-
<div>
|
| 241 |
-
{#if mode === "edit" && trimDuration > 0}
|
| 242 |
-
<time class="trim-duration">{format_time(trimDuration)}</time>
|
| 243 |
-
{/if}
|
| 244 |
-
{#if timing}
|
| 245 |
-
<time class="duration">{format_time(seconds)}</time>
|
| 246 |
-
{:else}
|
| 247 |
-
<time bind:this={durationRef} class="duration">0:00</time>
|
| 248 |
-
{/if}
|
| 249 |
-
</div>
|
| 250 |
-
</div>
|
| 251 |
-
{/if}
|
| 252 |
-
|
| 253 |
-
{#if record_mounted && !recordedAudio}
|
| 254 |
-
<WaveformRecordControls
|
| 255 |
-
{record}
|
| 256 |
-
{i18n}
|
| 257 |
-
{timing}
|
| 258 |
-
{recording}
|
| 259 |
-
show_recording_waveform={waveform_options.show_recording_waveform}
|
| 260 |
-
record_time={format_time(seconds)}
|
| 261 |
-
/>
|
| 262 |
-
{/if}
|
| 263 |
-
|
| 264 |
-
{#if recordingWaveform && recordedAudio}
|
| 265 |
-
<WaveformControls
|
| 266 |
-
waveform={recordingWaveform}
|
| 267 |
-
container={recordingContainer}
|
| 268 |
-
{playing}
|
| 269 |
-
{audio_duration}
|
| 270 |
-
{i18n}
|
| 271 |
-
{editable}
|
| 272 |
-
interactive={true}
|
| 273 |
-
{handle_trim_audio}
|
| 274 |
-
bind:trimDuration
|
| 275 |
-
bind:mode
|
| 276 |
-
show_redo
|
| 277 |
-
{handle_reset_value}
|
| 278 |
-
{waveform_options}
|
| 279 |
-
/>
|
| 280 |
-
{/if}
|
| 281 |
-
</div>
|
| 282 |
-
|
| 283 |
-
<style>
|
| 284 |
-
.microphone {
|
| 285 |
-
width: 100%;
|
| 286 |
-
display: none;
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
.component-wrapper {
|
| 290 |
-
padding: var(--size-3);
|
| 291 |
-
width: 100%;
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
.timestamps {
|
| 295 |
-
display: flex;
|
| 296 |
-
justify-content: space-between;
|
| 297 |
-
align-items: center;
|
| 298 |
-
width: 100%;
|
| 299 |
-
padding: var(--size-1) 0;
|
| 300 |
-
margin: var(--spacing-md) 0;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
.time {
|
| 304 |
-
color: var(--neutral-400);
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
.duration {
|
| 308 |
-
color: var(--neutral-400);
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
.trim-duration {
|
| 312 |
-
color: var(--color-accent);
|
| 313 |
-
margin-right: var(--spacing-sm);
|
| 314 |
-
}
|
| 315 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/Audio.svelte
DELETED
|
@@ -1,17 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import type { HTMLAudioAttributes } from "svelte/elements";
|
| 3 |
-
|
| 4 |
-
let {
|
| 5 |
-
src = undefined,
|
| 6 |
-
onplay,
|
| 7 |
-
onpause,
|
| 8 |
-
onended,
|
| 9 |
-
...restProps
|
| 10 |
-
}: HTMLAudioAttributes & {
|
| 11 |
-
onplay?: () => void;
|
| 12 |
-
onpause?: () => void;
|
| 13 |
-
onended?: () => void;
|
| 14 |
-
} = $props();
|
| 15 |
-
</script>
|
| 16 |
-
|
| 17 |
-
<audio {src} {...restProps} {onplay} {onpause} {onended} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/DeviceSelect.svelte
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount } from "svelte";
|
| 3 |
-
import RecordPlugin from "wavesurfer.js/dist/plugins/record.js";
|
| 4 |
-
import type { I18nFormatter } from "@gradio/utils";
|
| 5 |
-
|
| 6 |
-
let {
|
| 7 |
-
i18n,
|
| 8 |
-
micDevices = $bindable(),
|
| 9 |
-
onerror
|
| 10 |
-
}: {
|
| 11 |
-
i18n: I18nFormatter;
|
| 12 |
-
micDevices?: MediaDeviceInfo[];
|
| 13 |
-
onerror?: (error: string) => void;
|
| 14 |
-
} = $props();
|
| 15 |
-
|
| 16 |
-
onMount(() => {
|
| 17 |
-
if (typeof window !== "undefined" && navigator.mediaDevices) {
|
| 18 |
-
let tempDevices: MediaDeviceInfo[] = [];
|
| 19 |
-
RecordPlugin.getAvailableAudioDevices()
|
| 20 |
-
.then((devices: MediaDeviceInfo[]) => {
|
| 21 |
-
micDevices = devices;
|
| 22 |
-
devices.forEach((device) => {
|
| 23 |
-
if (device.deviceId) {
|
| 24 |
-
tempDevices.push(device);
|
| 25 |
-
}
|
| 26 |
-
});
|
| 27 |
-
micDevices = tempDevices;
|
| 28 |
-
})
|
| 29 |
-
.catch((err) => {
|
| 30 |
-
if (err instanceof DOMException && err.name == "NotAllowedError") {
|
| 31 |
-
onerror?.(i18n("audio.allow_recording_access"));
|
| 32 |
-
}
|
| 33 |
-
});
|
| 34 |
-
}
|
| 35 |
-
});
|
| 36 |
-
</script>
|
| 37 |
-
|
| 38 |
-
<select
|
| 39 |
-
class="mic-select"
|
| 40 |
-
aria-label="Select input device"
|
| 41 |
-
disabled={!micDevices || micDevices.length === 0}
|
| 42 |
-
>
|
| 43 |
-
{#if !micDevices || micDevices.length === 0}
|
| 44 |
-
<option value="">{i18n("audio.no_microphone")}</option>
|
| 45 |
-
{:else}
|
| 46 |
-
{#each micDevices as micDevice}
|
| 47 |
-
<option value={micDevice.deviceId}>{micDevice.label}</option>
|
| 48 |
-
{/each}
|
| 49 |
-
{/if}
|
| 50 |
-
</select>
|
| 51 |
-
|
| 52 |
-
<style>
|
| 53 |
-
.mic-select {
|
| 54 |
-
height: var(--size-8);
|
| 55 |
-
background: var(--block-background-fill);
|
| 56 |
-
padding: 0px var(--spacing-xxl);
|
| 57 |
-
border-radius: var(--button-large-radius);
|
| 58 |
-
font-size: var(--text-md);
|
| 59 |
-
border: 1px solid var(--block-border-color);
|
| 60 |
-
gap: var(--size-1);
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
select {
|
| 64 |
-
text-overflow: ellipsis;
|
| 65 |
-
max-width: var(--size-40);
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
@media (max-width: 375px) {
|
| 69 |
-
select {
|
| 70 |
-
width: 100%;
|
| 71 |
-
}
|
| 72 |
-
}
|
| 73 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/MinimalAudioPlayer.svelte
DELETED
|
@@ -1,190 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount, onDestroy } from "svelte";
|
| 3 |
-
import WaveSurfer from "wavesurfer.js";
|
| 4 |
-
import type { FileData } from "@gradio/client";
|
| 5 |
-
import { format_time } from "@gradio/utils";
|
| 6 |
-
|
| 7 |
-
let {
|
| 8 |
-
value,
|
| 9 |
-
label,
|
| 10 |
-
loop = false
|
| 11 |
-
}: {
|
| 12 |
-
value: FileData;
|
| 13 |
-
label: string;
|
| 14 |
-
loop?: boolean;
|
| 15 |
-
} = $props();
|
| 16 |
-
|
| 17 |
-
let container: HTMLDivElement;
|
| 18 |
-
let waveform: WaveSurfer | undefined;
|
| 19 |
-
let playing = $state(false);
|
| 20 |
-
let duration = $state(0);
|
| 21 |
-
let currentTime = $state(0);
|
| 22 |
-
let waveform_ready = $state(false);
|
| 23 |
-
|
| 24 |
-
let resolved_src = $derived(value.url);
|
| 25 |
-
|
| 26 |
-
const create_waveform = async (): Promise<void> => {
|
| 27 |
-
if (!container || !resolved_src || waveform_ready) return;
|
| 28 |
-
|
| 29 |
-
if (waveform) {
|
| 30 |
-
waveform.destroy();
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
const accentColor =
|
| 34 |
-
getComputedStyle(document.documentElement).getPropertyValue(
|
| 35 |
-
"--color-accent"
|
| 36 |
-
) || "#ff7c00";
|
| 37 |
-
|
| 38 |
-
waveform = WaveSurfer.create({
|
| 39 |
-
container,
|
| 40 |
-
height: 32,
|
| 41 |
-
waveColor: "rgba(128, 128, 128, 0.5)",
|
| 42 |
-
progressColor: accentColor,
|
| 43 |
-
cursorColor: "transparent",
|
| 44 |
-
barWidth: 2,
|
| 45 |
-
barGap: 2,
|
| 46 |
-
barRadius: 2,
|
| 47 |
-
normalize: true,
|
| 48 |
-
interact: true,
|
| 49 |
-
dragToSeek: true,
|
| 50 |
-
hideScrollbar: true
|
| 51 |
-
});
|
| 52 |
-
|
| 53 |
-
waveform.on("play", () => (playing = true));
|
| 54 |
-
waveform.on("pause", () => (playing = false));
|
| 55 |
-
waveform.on("ready", () => {
|
| 56 |
-
duration = waveform?.getDuration() || 0;
|
| 57 |
-
waveform_ready = true;
|
| 58 |
-
});
|
| 59 |
-
waveform.on("audioprocess", () => {
|
| 60 |
-
currentTime = waveform?.getCurrentTime() || 0;
|
| 61 |
-
});
|
| 62 |
-
waveform.on("interaction", () => {
|
| 63 |
-
currentTime = waveform?.getCurrentTime() || 0;
|
| 64 |
-
});
|
| 65 |
-
waveform.on("finish", () => {
|
| 66 |
-
playing = false;
|
| 67 |
-
if (loop) {
|
| 68 |
-
waveform?.play();
|
| 69 |
-
}
|
| 70 |
-
});
|
| 71 |
-
|
| 72 |
-
await waveform.load(resolved_src);
|
| 73 |
-
};
|
| 74 |
-
|
| 75 |
-
onMount(async () => {
|
| 76 |
-
await create_waveform();
|
| 77 |
-
});
|
| 78 |
-
|
| 79 |
-
onDestroy(() => {
|
| 80 |
-
if (waveform) {
|
| 81 |
-
waveform.destroy();
|
| 82 |
-
}
|
| 83 |
-
});
|
| 84 |
-
|
| 85 |
-
const togglePlay = (): void => {
|
| 86 |
-
if (waveform) {
|
| 87 |
-
waveform.playPause();
|
| 88 |
-
}
|
| 89 |
-
};
|
| 90 |
-
</script>
|
| 91 |
-
|
| 92 |
-
<div
|
| 93 |
-
class="minimal-audio-player"
|
| 94 |
-
aria-label={label || "Audio"}
|
| 95 |
-
data-testid={label && typeof label === "string" && label.trim()
|
| 96 |
-
? "waveform-" + label
|
| 97 |
-
: "unlabelled-audio"}
|
| 98 |
-
>
|
| 99 |
-
<button
|
| 100 |
-
class="play-btn"
|
| 101 |
-
onclick={togglePlay}
|
| 102 |
-
aria-label={playing ? "Pause" : "Play"}
|
| 103 |
-
>
|
| 104 |
-
{#if playing}
|
| 105 |
-
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 106 |
-
<rect x="6" y="5" width="4" height="14" rx="1" fill="currentColor" />
|
| 107 |
-
<rect x="14" y="5" width="4" height="14" rx="1" fill="currentColor" />
|
| 108 |
-
</svg>
|
| 109 |
-
{:else}
|
| 110 |
-
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 111 |
-
<path
|
| 112 |
-
d="M8 5.74537C8 5.06444 8.77346 4.64713 9.35139 5.02248L18.0227 10.2771C18.5518 10.6219 18.5518 11.3781 18.0227 11.7229L9.35139 16.9775C8.77346 17.3529 8 16.9356 8 16.2546V5.74537Z"
|
| 113 |
-
fill="currentColor"
|
| 114 |
-
/>
|
| 115 |
-
</svg>
|
| 116 |
-
{/if}
|
| 117 |
-
</button>
|
| 118 |
-
|
| 119 |
-
<div class="waveform-wrapper" bind:this={container}></div>
|
| 120 |
-
|
| 121 |
-
<div class="timestamp">{format_time(playing ? currentTime : duration)}</div>
|
| 122 |
-
</div>
|
| 123 |
-
|
| 124 |
-
<style>
|
| 125 |
-
.minimal-audio-player {
|
| 126 |
-
display: flex;
|
| 127 |
-
align-items: center;
|
| 128 |
-
gap: var(--spacing-sm);
|
| 129 |
-
border-radius: var(--radius-sm);
|
| 130 |
-
width: var(--size-52);
|
| 131 |
-
padding: var(--spacing-sm);
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
.play-btn {
|
| 135 |
-
display: inline-flex;
|
| 136 |
-
align-items: center;
|
| 137 |
-
justify-content: center;
|
| 138 |
-
padding: 0;
|
| 139 |
-
border: none;
|
| 140 |
-
background: none;
|
| 141 |
-
color: var(--body-text-color);
|
| 142 |
-
opacity: 0.7;
|
| 143 |
-
cursor: pointer;
|
| 144 |
-
border-radius: 50%;
|
| 145 |
-
transition: all 0.2s ease;
|
| 146 |
-
flex-shrink: 0;
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
.play-btn:hover {
|
| 150 |
-
color: var(--color-accent);
|
| 151 |
-
opacity: 1;
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
.play-btn:active {
|
| 155 |
-
transform: scale(0.95);
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
.play-btn svg {
|
| 159 |
-
width: var(--size-5);
|
| 160 |
-
height: var(--size-5);
|
| 161 |
-
display: block;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
.waveform-wrapper {
|
| 165 |
-
flex: 1 1 auto;
|
| 166 |
-
cursor: pointer;
|
| 167 |
-
width: auto;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
.waveform-wrapper :global(::part(wrapper)) {
|
| 171 |
-
margin-bottom: 0;
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
.timestamp {
|
| 175 |
-
font-size: 13px;
|
| 176 |
-
font-weight: 500;
|
| 177 |
-
color: var(--body-text-color);
|
| 178 |
-
opacity: 0.7;
|
| 179 |
-
font-variant-numeric: tabular-nums;
|
| 180 |
-
flex-shrink: 0;
|
| 181 |
-
min-width: 40px;
|
| 182 |
-
text-align: center;
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
@media (prefers-reduced-motion: reduce) {
|
| 186 |
-
.play-btn {
|
| 187 |
-
transition: none;
|
| 188 |
-
}
|
| 189 |
-
}
|
| 190 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/MinimalAudioRecorder.svelte
DELETED
|
@@ -1,379 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount, onDestroy, tick } from "svelte";
|
| 3 |
-
import WaveSurfer from "wavesurfer.js";
|
| 4 |
-
import RecordPlugin from "wavesurfer.js/dist/plugins/record.js";
|
| 5 |
-
import { format_time } from "@gradio/utils";
|
| 6 |
-
import { process_audio } from "./utils";
|
| 7 |
-
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
| 8 |
-
import { Square } from "@gradio/icons";
|
| 9 |
-
|
| 10 |
-
let {
|
| 11 |
-
label,
|
| 12 |
-
waveform_settings = {},
|
| 13 |
-
recording = $bindable(),
|
| 14 |
-
upload,
|
| 15 |
-
root,
|
| 16 |
-
max_file_size = null,
|
| 17 |
-
upload_promise = $bindable(),
|
| 18 |
-
onchange,
|
| 19 |
-
onstoprecording,
|
| 20 |
-
onclear
|
| 21 |
-
}: {
|
| 22 |
-
label: string;
|
| 23 |
-
waveform_settings?: Record<string, any>;
|
| 24 |
-
recording?: boolean;
|
| 25 |
-
upload: Client["upload"];
|
| 26 |
-
root: string;
|
| 27 |
-
max_file_size?: number | null;
|
| 28 |
-
upload_promise?: Promise<any> | null;
|
| 29 |
-
onchange?: (value: FileData) => void;
|
| 30 |
-
onstoprecording?: () => void;
|
| 31 |
-
onclear?: () => void;
|
| 32 |
-
} = $props();
|
| 33 |
-
|
| 34 |
-
let container: HTMLDivElement;
|
| 35 |
-
let waveform: WaveSurfer | undefined;
|
| 36 |
-
let record: RecordPlugin | undefined = $state();
|
| 37 |
-
let seconds = $state(0);
|
| 38 |
-
let interval: NodeJS.Timeout;
|
| 39 |
-
let is_recording = $state(false);
|
| 40 |
-
let has_started = $state(false);
|
| 41 |
-
let mic_devices: MediaDeviceInfo[] = $state([]);
|
| 42 |
-
let selected_device_id: string = $state("");
|
| 43 |
-
let show_device_selection = $state(false);
|
| 44 |
-
|
| 45 |
-
const start_interval = (): void => {
|
| 46 |
-
clearInterval(interval);
|
| 47 |
-
interval = setInterval(() => {
|
| 48 |
-
seconds++;
|
| 49 |
-
}, 1000);
|
| 50 |
-
};
|
| 51 |
-
|
| 52 |
-
const create_waveform = async (): Promise<void> => {
|
| 53 |
-
if (!container) return;
|
| 54 |
-
|
| 55 |
-
if (waveform) {
|
| 56 |
-
waveform.destroy();
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
const accentColor =
|
| 60 |
-
getComputedStyle(document.documentElement).getPropertyValue(
|
| 61 |
-
"--color-accent"
|
| 62 |
-
) || "#ff7c00";
|
| 63 |
-
|
| 64 |
-
waveform = WaveSurfer.create({
|
| 65 |
-
container,
|
| 66 |
-
height: 32,
|
| 67 |
-
waveColor: "rgba(128, 128, 128, 0.5)",
|
| 68 |
-
progressColor: accentColor,
|
| 69 |
-
cursorColor: "transparent",
|
| 70 |
-
barWidth: 2,
|
| 71 |
-
barGap: 2,
|
| 72 |
-
barRadius: 2,
|
| 73 |
-
interact: false,
|
| 74 |
-
hideScrollbar: true,
|
| 75 |
-
...waveform_settings
|
| 76 |
-
});
|
| 77 |
-
|
| 78 |
-
record = waveform.registerPlugin(
|
| 79 |
-
RecordPlugin.create({
|
| 80 |
-
scrollingWaveform: true,
|
| 81 |
-
scrollingWaveformWindow: 7,
|
| 82 |
-
renderRecordedAudio: false
|
| 83 |
-
})
|
| 84 |
-
);
|
| 85 |
-
|
| 86 |
-
record.on("record-start", () => {
|
| 87 |
-
start_interval();
|
| 88 |
-
is_recording = true;
|
| 89 |
-
has_started = true;
|
| 90 |
-
});
|
| 91 |
-
|
| 92 |
-
record.on("record-end", async (blob: Blob) => {
|
| 93 |
-
clearInterval(interval);
|
| 94 |
-
is_recording = false;
|
| 95 |
-
|
| 96 |
-
upload_promise = (async () => {
|
| 97 |
-
try {
|
| 98 |
-
const array_buffer = await blob.arrayBuffer();
|
| 99 |
-
const context = new AudioContext({
|
| 100 |
-
sampleRate: waveform_settings.sampleRate || 44100
|
| 101 |
-
});
|
| 102 |
-
const audio_buffer = await context.decodeAudioData(array_buffer);
|
| 103 |
-
|
| 104 |
-
if (audio_buffer) {
|
| 105 |
-
const audio = await process_audio(audio_buffer);
|
| 106 |
-
const audio_blob = new File([audio], "audio.wav", {
|
| 107 |
-
type: "audio/wav"
|
| 108 |
-
});
|
| 109 |
-
|
| 110 |
-
const prepared_files = await prepare_files([audio_blob], false);
|
| 111 |
-
const uploaded_files = await upload(
|
| 112 |
-
prepared_files,
|
| 113 |
-
root,
|
| 114 |
-
undefined,
|
| 115 |
-
max_file_size || undefined
|
| 116 |
-
);
|
| 117 |
-
const file_data = uploaded_files?.[0];
|
| 118 |
-
|
| 119 |
-
if (file_data) {
|
| 120 |
-
onchange?.(file_data);
|
| 121 |
-
}
|
| 122 |
-
}
|
| 123 |
-
} catch (e) {
|
| 124 |
-
console.error("Error processing audio:", e);
|
| 125 |
-
} finally {
|
| 126 |
-
onstoprecording?.();
|
| 127 |
-
upload_promise = null;
|
| 128 |
-
}
|
| 129 |
-
})();
|
| 130 |
-
|
| 131 |
-
await upload_promise;
|
| 132 |
-
});
|
| 133 |
-
};
|
| 134 |
-
|
| 135 |
-
onMount(async () => {
|
| 136 |
-
try {
|
| 137 |
-
const devices = await RecordPlugin.getAvailableAudioDevices();
|
| 138 |
-
mic_devices = devices.filter((device) => device.deviceId);
|
| 139 |
-
if (mic_devices.length > 0) {
|
| 140 |
-
selected_device_id = mic_devices[0].deviceId;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
if (mic_devices.length > 1) {
|
| 144 |
-
show_device_selection = true;
|
| 145 |
-
} else {
|
| 146 |
-
await create_waveform();
|
| 147 |
-
}
|
| 148 |
-
} catch (err) {
|
| 149 |
-
await create_waveform();
|
| 150 |
-
}
|
| 151 |
-
});
|
| 152 |
-
|
| 153 |
-
onDestroy(() => {
|
| 154 |
-
clearInterval(interval);
|
| 155 |
-
if (record) {
|
| 156 |
-
record.stopMic();
|
| 157 |
-
}
|
| 158 |
-
if (waveform) {
|
| 159 |
-
waveform.destroy();
|
| 160 |
-
}
|
| 161 |
-
});
|
| 162 |
-
|
| 163 |
-
$effect(() => {
|
| 164 |
-
if (
|
| 165 |
-
recording &&
|
| 166 |
-
!is_recording &&
|
| 167 |
-
record &&
|
| 168 |
-
has_started === false &&
|
| 169 |
-
mic_devices.length <= 1
|
| 170 |
-
) {
|
| 171 |
-
record
|
| 172 |
-
.startMic({ deviceId: selected_device_id })
|
| 173 |
-
.then(() => {
|
| 174 |
-
record?.startRecording();
|
| 175 |
-
})
|
| 176 |
-
.catch((err) => {
|
| 177 |
-
console.error("Failed to access microphone:", err);
|
| 178 |
-
onclear?.();
|
| 179 |
-
});
|
| 180 |
-
} else if (!recording && is_recording && record) {
|
| 181 |
-
record.stopRecording();
|
| 182 |
-
seconds = 0;
|
| 183 |
-
}
|
| 184 |
-
});
|
| 185 |
-
|
| 186 |
-
async function startRecording(): Promise<void> {
|
| 187 |
-
show_device_selection = false;
|
| 188 |
-
has_started = true;
|
| 189 |
-
|
| 190 |
-
await tick();
|
| 191 |
-
await create_waveform();
|
| 192 |
-
|
| 193 |
-
if (!record) return;
|
| 194 |
-
|
| 195 |
-
try {
|
| 196 |
-
await record.startMic({ deviceId: selected_device_id });
|
| 197 |
-
record.startRecording();
|
| 198 |
-
} catch (err) {
|
| 199 |
-
console.error("Error starting recording:", err);
|
| 200 |
-
show_device_selection = mic_devices.length > 1;
|
| 201 |
-
has_started = false;
|
| 202 |
-
recording = false;
|
| 203 |
-
}
|
| 204 |
-
}
|
| 205 |
-
</script>
|
| 206 |
-
|
| 207 |
-
<div
|
| 208 |
-
class="minimal-audio-recorder"
|
| 209 |
-
aria-label={label || "Audio Recorder"}
|
| 210 |
-
data-testid="minimal-audio-recorder"
|
| 211 |
-
>
|
| 212 |
-
{#if show_device_selection}
|
| 213 |
-
<div class="device-selection-wrapper">
|
| 214 |
-
{#if mic_devices.length > 1}
|
| 215 |
-
<select
|
| 216 |
-
bind:value={selected_device_id}
|
| 217 |
-
class="device-select-large"
|
| 218 |
-
aria-label="Select input device"
|
| 219 |
-
>
|
| 220 |
-
{#each mic_devices as device}
|
| 221 |
-
<option value={device.deviceId}>{device.label}</option>
|
| 222 |
-
{/each}
|
| 223 |
-
</select>
|
| 224 |
-
{/if}
|
| 225 |
-
<button
|
| 226 |
-
class="record-button"
|
| 227 |
-
onclick={startRecording}
|
| 228 |
-
aria-label="Start recording"
|
| 229 |
-
>
|
| 230 |
-
</button>
|
| 231 |
-
</div>
|
| 232 |
-
{:else}
|
| 233 |
-
<div class="waveform-wrapper" bind:this={container}></div>
|
| 234 |
-
<div class="timestamp">{format_time(seconds)}</div>
|
| 235 |
-
<button
|
| 236 |
-
class="stop-button"
|
| 237 |
-
onclick={() => {
|
| 238 |
-
if (is_recording) {
|
| 239 |
-
recording = false;
|
| 240 |
-
} else {
|
| 241 |
-
onclear?.();
|
| 242 |
-
}
|
| 243 |
-
}}
|
| 244 |
-
aria-label="Stop recording"
|
| 245 |
-
>
|
| 246 |
-
<Square />
|
| 247 |
-
</button>
|
| 248 |
-
{/if}
|
| 249 |
-
</div>
|
| 250 |
-
|
| 251 |
-
<style>
|
| 252 |
-
.minimal-audio-recorder {
|
| 253 |
-
display: flex;
|
| 254 |
-
align-items: center;
|
| 255 |
-
gap: var(--spacing-sm);
|
| 256 |
-
border-radius: var(--radius-sm);
|
| 257 |
-
width: 100%;
|
| 258 |
-
padding: var(--spacing-sm);
|
| 259 |
-
}
|
| 260 |
-
|
| 261 |
-
.device-selection-wrapper {
|
| 262 |
-
display: flex;
|
| 263 |
-
flex-direction: row;
|
| 264 |
-
align-items: center;
|
| 265 |
-
justify-content: center;
|
| 266 |
-
gap: var(--spacing-md);
|
| 267 |
-
width: 100%;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
.waveform-wrapper {
|
| 271 |
-
flex: 1 1 auto;
|
| 272 |
-
min-width: 0;
|
| 273 |
-
width: 100%;
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
.waveform-wrapper :global(::part(wrapper)) {
|
| 277 |
-
margin-bottom: 0;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
.timestamp {
|
| 281 |
-
font-size: 13px;
|
| 282 |
-
font-weight: 500;
|
| 283 |
-
color: var(--body-text-color);
|
| 284 |
-
opacity: 0.7;
|
| 285 |
-
font-variant-numeric: tabular-nums;
|
| 286 |
-
flex-shrink: 0;
|
| 287 |
-
min-width: 40px;
|
| 288 |
-
text-align: center;
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
.device-select-large {
|
| 292 |
-
max-width: var(--size-60);
|
| 293 |
-
font-size: var(--text-sm);
|
| 294 |
-
padding: var(--spacing-sm) var(--spacing-md);
|
| 295 |
-
border: 1px solid var(--border-color-primary);
|
| 296 |
-
border-radius: var(--radius-md);
|
| 297 |
-
background: var(--background-fill-secondary);
|
| 298 |
-
color: var(--body-text-color);
|
| 299 |
-
cursor: pointer;
|
| 300 |
-
height: var(--size-9);
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
.record-button {
|
| 304 |
-
display: flex;
|
| 305 |
-
align-items: center;
|
| 306 |
-
justify-content: center;
|
| 307 |
-
height: var(--size-9);
|
| 308 |
-
width: var(--size-9);
|
| 309 |
-
padding: 0;
|
| 310 |
-
flex-shrink: 0;
|
| 311 |
-
background-color: var(--block-background-fill);
|
| 312 |
-
color: var(--body-text-color);
|
| 313 |
-
border: 1px solid var(--border-color-primary);
|
| 314 |
-
border-radius: var(--radius-md);
|
| 315 |
-
cursor: pointer;
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
.record-button::before {
|
| 319 |
-
content: "";
|
| 320 |
-
height: var(--size-4);
|
| 321 |
-
width: var(--size-4);
|
| 322 |
-
border-radius: var(--radius-full);
|
| 323 |
-
background: var(--primary-600);
|
| 324 |
-
flex-shrink: 0;
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
.record-button:hover {
|
| 328 |
-
background-color: var(--block-background-fill);
|
| 329 |
-
border-color: var(--border-color-accent);
|
| 330 |
-
}
|
| 331 |
-
|
| 332 |
-
.record-button:active {
|
| 333 |
-
transform: scale(0.98);
|
| 334 |
-
}
|
| 335 |
-
|
| 336 |
-
.stop-button {
|
| 337 |
-
display: flex;
|
| 338 |
-
align-items: center;
|
| 339 |
-
justify-content: center;
|
| 340 |
-
width: var(--size-9);
|
| 341 |
-
height: var(--size-9);
|
| 342 |
-
padding: 0;
|
| 343 |
-
border: var(--size-px) solid var(--border-color-primary);
|
| 344 |
-
border-radius: var(--radius-md);
|
| 345 |
-
background: var(--button-secondary-background-fill);
|
| 346 |
-
color: var(--error-500);
|
| 347 |
-
cursor: pointer;
|
| 348 |
-
flex-shrink: 0;
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
.stop-button:hover {
|
| 352 |
-
background: var(--button-secondary-background-fill-hover);
|
| 353 |
-
color: var(--error-600);
|
| 354 |
-
}
|
| 355 |
-
|
| 356 |
-
.stop-button:active {
|
| 357 |
-
transform: scale(0.95);
|
| 358 |
-
}
|
| 359 |
-
|
| 360 |
-
.stop-button :global(svg) {
|
| 361 |
-
width: var(--size-5);
|
| 362 |
-
height: var(--size-5);
|
| 363 |
-
}
|
| 364 |
-
|
| 365 |
-
@media (prefers-reduced-motion: reduce) {
|
| 366 |
-
.record-btn {
|
| 367 |
-
transition: none;
|
| 368 |
-
}
|
| 369 |
-
.record-btn.recording {
|
| 370 |
-
animation: none;
|
| 371 |
-
}
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
@media (max-width: 768px) {
|
| 375 |
-
.device-select-large {
|
| 376 |
-
max-width: var(--size-40);
|
| 377 |
-
}
|
| 378 |
-
}
|
| 379 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/VolumeControl.svelte
DELETED
|
@@ -1,86 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount } from "svelte";
|
| 3 |
-
import WaveSurfer from "wavesurfer.js";
|
| 4 |
-
|
| 5 |
-
let {
|
| 6 |
-
currentVolume = $bindable(),
|
| 7 |
-
show_volume_slider = $bindable(),
|
| 8 |
-
waveform
|
| 9 |
-
}: {
|
| 10 |
-
currentVolume?: number;
|
| 11 |
-
show_volume_slider?: boolean;
|
| 12 |
-
waveform: WaveSurfer | undefined;
|
| 13 |
-
} = $props();
|
| 14 |
-
|
| 15 |
-
let volumeElement: HTMLInputElement;
|
| 16 |
-
|
| 17 |
-
onMount(() => {
|
| 18 |
-
adjustSlider();
|
| 19 |
-
});
|
| 20 |
-
|
| 21 |
-
const adjustSlider = (): void => {
|
| 22 |
-
let slider = volumeElement;
|
| 23 |
-
if (!slider) return;
|
| 24 |
-
|
| 25 |
-
slider.style.background = `linear-gradient(to right, var(--color-accent) ${
|
| 26 |
-
currentVolume * 100
|
| 27 |
-
}%, var(--neutral-400) ${currentVolume * 100}%)`;
|
| 28 |
-
};
|
| 29 |
-
|
| 30 |
-
$effect(() => {
|
| 31 |
-
currentVolume;
|
| 32 |
-
adjustSlider();
|
| 33 |
-
});
|
| 34 |
-
</script>
|
| 35 |
-
|
| 36 |
-
<input
|
| 37 |
-
bind:this={volumeElement}
|
| 38 |
-
id="volume"
|
| 39 |
-
class="volume-slider"
|
| 40 |
-
type="range"
|
| 41 |
-
min="0"
|
| 42 |
-
max="1"
|
| 43 |
-
step="0.01"
|
| 44 |
-
value={currentVolume}
|
| 45 |
-
onfocusout={() => (show_volume_slider = false)}
|
| 46 |
-
oninput={(e) => {
|
| 47 |
-
if (e.target instanceof HTMLInputElement) {
|
| 48 |
-
currentVolume = parseFloat(e.target.value);
|
| 49 |
-
waveform?.setVolume(currentVolume);
|
| 50 |
-
}
|
| 51 |
-
}}
|
| 52 |
-
/>
|
| 53 |
-
|
| 54 |
-
<style>
|
| 55 |
-
.volume-slider {
|
| 56 |
-
-webkit-appearance: none;
|
| 57 |
-
appearance: none;
|
| 58 |
-
width: var(--size-20);
|
| 59 |
-
accent-color: var(--color-accent);
|
| 60 |
-
height: 4px;
|
| 61 |
-
cursor: pointer;
|
| 62 |
-
outline: none;
|
| 63 |
-
border-radius: 15px;
|
| 64 |
-
background-color: var(--neutral-400);
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
input[type="range"]::-webkit-slider-thumb {
|
| 68 |
-
-webkit-appearance: none;
|
| 69 |
-
appearance: none;
|
| 70 |
-
height: 15px;
|
| 71 |
-
width: 15px;
|
| 72 |
-
background-color: var(--color-accent);
|
| 73 |
-
border-radius: 50%;
|
| 74 |
-
border: none;
|
| 75 |
-
transition: 0.2s ease-in-out;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
input[type="range"]::-moz-range-thumb {
|
| 79 |
-
height: 15px;
|
| 80 |
-
width: 15px;
|
| 81 |
-
background-color: var(--color-accent);
|
| 82 |
-
border-radius: 50%;
|
| 83 |
-
border: none;
|
| 84 |
-
transition: 0.2s ease-in-out;
|
| 85 |
-
}
|
| 86 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/VolumeLevels.svelte
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { VolumeMuted, VolumeHigh, VolumeLow } from "@gradio/icons";
|
| 3 |
-
|
| 4 |
-
let { currentVolume }: { currentVolume: number } = $props();
|
| 5 |
-
</script>
|
| 6 |
-
|
| 7 |
-
{#if currentVolume == 0}
|
| 8 |
-
<VolumeMuted />
|
| 9 |
-
{:else if currentVolume < 0.5}
|
| 10 |
-
<VolumeLow />
|
| 11 |
-
{:else if currentVolume >= 0.5}
|
| 12 |
-
<VolumeHigh />
|
| 13 |
-
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/WaveformControls.svelte
DELETED
|
@@ -1,496 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import {
|
| 3 |
-
Play,
|
| 4 |
-
Pause,
|
| 5 |
-
Forward,
|
| 6 |
-
Backward,
|
| 7 |
-
ClosedCaption,
|
| 8 |
-
Undo,
|
| 9 |
-
Trim
|
| 10 |
-
} from "@gradio/icons";
|
| 11 |
-
import { get_skip_rewind_amount } from "../shared/utils";
|
| 12 |
-
import type { I18nFormatter } from "@gradio/utils";
|
| 13 |
-
import WaveSurfer from "wavesurfer.js";
|
| 14 |
-
import RegionsPlugin, {
|
| 15 |
-
type Region
|
| 16 |
-
} from "wavesurfer.js/dist/plugins/regions.js";
|
| 17 |
-
import type { WaveformOptions } from "./types";
|
| 18 |
-
import VolumeLevels from "./VolumeLevels.svelte";
|
| 19 |
-
import VolumeControl from "./VolumeControl.svelte";
|
| 20 |
-
import { onMount } from "svelte";
|
| 21 |
-
|
| 22 |
-
let {
|
| 23 |
-
waveform,
|
| 24 |
-
audio_duration,
|
| 25 |
-
i18n,
|
| 26 |
-
playing,
|
| 27 |
-
show_redo = false,
|
| 28 |
-
interactive = false,
|
| 29 |
-
handle_trim_audio,
|
| 30 |
-
mode = $bindable(),
|
| 31 |
-
container,
|
| 32 |
-
handle_reset_value,
|
| 33 |
-
waveform_options = {},
|
| 34 |
-
trim_region_settings = {},
|
| 35 |
-
show_volume_slider = $bindable(),
|
| 36 |
-
editable = true,
|
| 37 |
-
subtitles_toggle = $bindable(),
|
| 38 |
-
show_subtitles = false,
|
| 39 |
-
trimDuration = $bindable()
|
| 40 |
-
}: {
|
| 41 |
-
waveform: WaveSurfer | undefined;
|
| 42 |
-
audio_duration: number;
|
| 43 |
-
i18n: I18nFormatter;
|
| 44 |
-
playing: boolean;
|
| 45 |
-
show_redo?: boolean;
|
| 46 |
-
interactive?: boolean;
|
| 47 |
-
handle_trim_audio: (start: number, end: number) => void;
|
| 48 |
-
mode?: string;
|
| 49 |
-
container: HTMLDivElement;
|
| 50 |
-
handle_reset_value: () => void;
|
| 51 |
-
waveform_options?: WaveformOptions;
|
| 52 |
-
trim_region_settings?: WaveformOptions;
|
| 53 |
-
show_volume_slider?: boolean;
|
| 54 |
-
editable?: boolean;
|
| 55 |
-
subtitles_toggle?: boolean;
|
| 56 |
-
show_subtitles?: boolean;
|
| 57 |
-
trimDuration?: number;
|
| 58 |
-
} = $props();
|
| 59 |
-
|
| 60 |
-
let playbackSpeeds = [0.5, 1, 1.5, 2];
|
| 61 |
-
let playbackSpeed = $state(playbackSpeeds[1]);
|
| 62 |
-
|
| 63 |
-
let trimRegion: RegionsPlugin | null = $state(null);
|
| 64 |
-
let activeRegion: Region | null = $state(null);
|
| 65 |
-
|
| 66 |
-
let leftRegionHandle: HTMLDivElement | null = $state(null);
|
| 67 |
-
let rightRegionHandle: HTMLDivElement | null = $state(null);
|
| 68 |
-
let activeHandle = $state("");
|
| 69 |
-
|
| 70 |
-
let currentVolume = $state(1);
|
| 71 |
-
|
| 72 |
-
function ensureTrimRegion(): void {
|
| 73 |
-
if (container && waveform && !trimRegion) {
|
| 74 |
-
trimRegion = waveform.registerPlugin(RegionsPlugin.create());
|
| 75 |
-
}
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
onMount(() => {
|
| 79 |
-
ensureTrimRegion();
|
| 80 |
-
});
|
| 81 |
-
|
| 82 |
-
$effect(() => {
|
| 83 |
-
if (!trimRegion) return;
|
| 84 |
-
const handler = (region: Region): void => {
|
| 85 |
-
region.play();
|
| 86 |
-
};
|
| 87 |
-
trimRegion.on("region-out", handler);
|
| 88 |
-
return () => {
|
| 89 |
-
trimRegion?.un("region-out", handler);
|
| 90 |
-
};
|
| 91 |
-
});
|
| 92 |
-
|
| 93 |
-
$effect(() => {
|
| 94 |
-
if (!trimRegion) return;
|
| 95 |
-
const handler = (region: Region): void => {
|
| 96 |
-
trimDuration = region.end - region.start;
|
| 97 |
-
};
|
| 98 |
-
trimRegion.on("region-updated", handler);
|
| 99 |
-
return () => {
|
| 100 |
-
trimRegion?.un("region-updated", handler);
|
| 101 |
-
};
|
| 102 |
-
});
|
| 103 |
-
|
| 104 |
-
$effect(() => {
|
| 105 |
-
if (!trimRegion) return;
|
| 106 |
-
const handler = (region: Region, e: Event): void => {
|
| 107 |
-
e.stopPropagation();
|
| 108 |
-
activeRegion = region;
|
| 109 |
-
region.play();
|
| 110 |
-
};
|
| 111 |
-
trimRegion.on("region-clicked", handler);
|
| 112 |
-
return () => {
|
| 113 |
-
trimRegion?.un("region-clicked", handler);
|
| 114 |
-
};
|
| 115 |
-
});
|
| 116 |
-
|
| 117 |
-
const addTrimRegion = (): void => {
|
| 118 |
-
if (!trimRegion) return;
|
| 119 |
-
activeRegion = trimRegion?.addRegion({
|
| 120 |
-
start: audio_duration / 4,
|
| 121 |
-
end: audio_duration / 2,
|
| 122 |
-
...trim_region_settings
|
| 123 |
-
});
|
| 124 |
-
|
| 125 |
-
trimDuration = activeRegion.end - activeRegion.start;
|
| 126 |
-
};
|
| 127 |
-
|
| 128 |
-
$effect(() => {
|
| 129 |
-
if (activeRegion) {
|
| 130 |
-
const shadowRoot = container.children[0]!.shadowRoot!;
|
| 131 |
-
|
| 132 |
-
rightRegionHandle = shadowRoot.querySelector('[data-resize="right"]');
|
| 133 |
-
leftRegionHandle = shadowRoot.querySelector('[data-resize="left"]');
|
| 134 |
-
|
| 135 |
-
if (leftRegionHandle && rightRegionHandle) {
|
| 136 |
-
leftRegionHandle.setAttribute("role", "button");
|
| 137 |
-
rightRegionHandle.setAttribute("role", "button");
|
| 138 |
-
leftRegionHandle?.setAttribute(
|
| 139 |
-
"aria-label",
|
| 140 |
-
"Drag to adjust start time"
|
| 141 |
-
);
|
| 142 |
-
rightRegionHandle?.setAttribute(
|
| 143 |
-
"aria-label",
|
| 144 |
-
"Drag to adjust end time"
|
| 145 |
-
);
|
| 146 |
-
leftRegionHandle?.setAttribute("tabindex", "0");
|
| 147 |
-
rightRegionHandle?.setAttribute("tabindex", "0");
|
| 148 |
-
|
| 149 |
-
leftRegionHandle.addEventListener("focus", () => {
|
| 150 |
-
if (trimRegion) activeHandle = "left";
|
| 151 |
-
});
|
| 152 |
-
|
| 153 |
-
rightRegionHandle.addEventListener("focus", () => {
|
| 154 |
-
if (trimRegion) activeHandle = "right";
|
| 155 |
-
});
|
| 156 |
-
}
|
| 157 |
-
}
|
| 158 |
-
});
|
| 159 |
-
|
| 160 |
-
const trimAudio = (): void => {
|
| 161 |
-
if (waveform && trimRegion) {
|
| 162 |
-
if (activeRegion) {
|
| 163 |
-
const start = activeRegion.start;
|
| 164 |
-
const end = activeRegion.end;
|
| 165 |
-
handle_trim_audio(start, end);
|
| 166 |
-
mode = "";
|
| 167 |
-
activeRegion = null;
|
| 168 |
-
}
|
| 169 |
-
}
|
| 170 |
-
};
|
| 171 |
-
|
| 172 |
-
const clearRegions = (): void => {
|
| 173 |
-
trimRegion?.getRegions().forEach((region) => {
|
| 174 |
-
region.remove();
|
| 175 |
-
});
|
| 176 |
-
trimRegion?.clearRegions();
|
| 177 |
-
};
|
| 178 |
-
|
| 179 |
-
const toggleTrimmingMode = (): void => {
|
| 180 |
-
clearRegions();
|
| 181 |
-
if (mode) {
|
| 182 |
-
mode = "";
|
| 183 |
-
} else {
|
| 184 |
-
mode = "edit";
|
| 185 |
-
ensureTrimRegion();
|
| 186 |
-
addTrimRegion();
|
| 187 |
-
}
|
| 188 |
-
};
|
| 189 |
-
|
| 190 |
-
const toggleSubtitles = (): void => {
|
| 191 |
-
subtitles_toggle = !subtitles_toggle;
|
| 192 |
-
};
|
| 193 |
-
|
| 194 |
-
const adjustRegionHandles = (handle: string, key: string): void => {
|
| 195 |
-
let newStart;
|
| 196 |
-
let newEnd;
|
| 197 |
-
|
| 198 |
-
if (!activeRegion) return;
|
| 199 |
-
if (handle === "left") {
|
| 200 |
-
if (key === "ArrowLeft") {
|
| 201 |
-
newStart = activeRegion.start - 0.05;
|
| 202 |
-
newEnd = activeRegion.end;
|
| 203 |
-
} else {
|
| 204 |
-
newStart = activeRegion.start + 0.05;
|
| 205 |
-
newEnd = activeRegion.end;
|
| 206 |
-
}
|
| 207 |
-
} else {
|
| 208 |
-
if (key === "ArrowLeft") {
|
| 209 |
-
newStart = activeRegion.start;
|
| 210 |
-
newEnd = activeRegion.end - 0.05;
|
| 211 |
-
} else {
|
| 212 |
-
newStart = activeRegion.start;
|
| 213 |
-
newEnd = activeRegion.end + 0.05;
|
| 214 |
-
}
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
activeRegion.setOptions({
|
| 218 |
-
start: newStart,
|
| 219 |
-
end: newEnd
|
| 220 |
-
});
|
| 221 |
-
|
| 222 |
-
trimDuration = activeRegion.end - activeRegion.start;
|
| 223 |
-
};
|
| 224 |
-
|
| 225 |
-
$effect(() => {
|
| 226 |
-
if (trimRegion) {
|
| 227 |
-
const handleKeydown = (e: KeyboardEvent): void => {
|
| 228 |
-
if (e.key === "ArrowLeft") {
|
| 229 |
-
adjustRegionHandles(activeHandle, "ArrowLeft");
|
| 230 |
-
} else if (e.key === "ArrowRight") {
|
| 231 |
-
adjustRegionHandles(activeHandle, "ArrowRight");
|
| 232 |
-
}
|
| 233 |
-
};
|
| 234 |
-
window.addEventListener("keydown", handleKeydown);
|
| 235 |
-
return () => {
|
| 236 |
-
window.removeEventListener("keydown", handleKeydown);
|
| 237 |
-
};
|
| 238 |
-
}
|
| 239 |
-
});
|
| 240 |
-
</script>
|
| 241 |
-
|
| 242 |
-
<div class="controls" data-testid="waveform-controls">
|
| 243 |
-
<div class="control-wrapper">
|
| 244 |
-
<button
|
| 245 |
-
class="action icon volume"
|
| 246 |
-
style:color={show_volume_slider
|
| 247 |
-
? "var(--color-accent)"
|
| 248 |
-
: "var(--neutral-400)"}
|
| 249 |
-
aria-label="Adjust volume"
|
| 250 |
-
onclick={() => (show_volume_slider = !show_volume_slider)}
|
| 251 |
-
>
|
| 252 |
-
<VolumeLevels {currentVolume} />
|
| 253 |
-
</button>
|
| 254 |
-
|
| 255 |
-
{#if show_volume_slider}
|
| 256 |
-
<VolumeControl bind:currentVolume bind:show_volume_slider {waveform} />
|
| 257 |
-
{/if}
|
| 258 |
-
|
| 259 |
-
<button
|
| 260 |
-
class:hidden={show_volume_slider}
|
| 261 |
-
class="playback icon"
|
| 262 |
-
aria-label={`Adjust playback speed to ${
|
| 263 |
-
playbackSpeeds[
|
| 264 |
-
(playbackSpeeds.indexOf(playbackSpeed) + 1) % playbackSpeeds.length
|
| 265 |
-
]
|
| 266 |
-
}x`}
|
| 267 |
-
onclick={() => {
|
| 268 |
-
playbackSpeed =
|
| 269 |
-
playbackSpeeds[
|
| 270 |
-
(playbackSpeeds.indexOf(playbackSpeed) + 1) % playbackSpeeds.length
|
| 271 |
-
];
|
| 272 |
-
|
| 273 |
-
waveform?.setPlaybackRate(playbackSpeed);
|
| 274 |
-
}}
|
| 275 |
-
>
|
| 276 |
-
<span>{playbackSpeed}x</span>
|
| 277 |
-
</button>
|
| 278 |
-
</div>
|
| 279 |
-
|
| 280 |
-
<div class="play-pause-wrapper">
|
| 281 |
-
<button
|
| 282 |
-
class="rewind icon"
|
| 283 |
-
aria-label={`Skip backwards by ${get_skip_rewind_amount(
|
| 284 |
-
audio_duration,
|
| 285 |
-
waveform_options.skip_length
|
| 286 |
-
)} seconds`}
|
| 287 |
-
onclick={() =>
|
| 288 |
-
waveform?.skip(
|
| 289 |
-
get_skip_rewind_amount(audio_duration, waveform_options.skip_length) *
|
| 290 |
-
-1
|
| 291 |
-
)}
|
| 292 |
-
>
|
| 293 |
-
<Backward />
|
| 294 |
-
</button>
|
| 295 |
-
<button
|
| 296 |
-
class="play-pause-button icon"
|
| 297 |
-
onclick={() => waveform?.playPause()}
|
| 298 |
-
aria-label={playing ? i18n("audio.pause") : i18n("audio.play")}
|
| 299 |
-
>
|
| 300 |
-
{#if playing}
|
| 301 |
-
<Pause />
|
| 302 |
-
{:else}
|
| 303 |
-
<Play />
|
| 304 |
-
{/if}
|
| 305 |
-
</button>
|
| 306 |
-
<button
|
| 307 |
-
class="skip icon"
|
| 308 |
-
aria-label="Skip forward by {get_skip_rewind_amount(
|
| 309 |
-
audio_duration,
|
| 310 |
-
waveform_options.skip_length
|
| 311 |
-
)} seconds"
|
| 312 |
-
onclick={() =>
|
| 313 |
-
waveform?.skip(
|
| 314 |
-
get_skip_rewind_amount(audio_duration, waveform_options.skip_length)
|
| 315 |
-
)}
|
| 316 |
-
>
|
| 317 |
-
<Forward />
|
| 318 |
-
</button>
|
| 319 |
-
</div>
|
| 320 |
-
|
| 321 |
-
<div class="settings-wrapper">
|
| 322 |
-
{#if show_subtitles}
|
| 323 |
-
<button
|
| 324 |
-
class="action icon cc-button"
|
| 325 |
-
data-testid="subtitles-toggle"
|
| 326 |
-
style="color: {subtitles_toggle
|
| 327 |
-
? 'var(--color-accent)'
|
| 328 |
-
: 'var(--neutral-400)'}"
|
| 329 |
-
onclick={toggleSubtitles}
|
| 330 |
-
>
|
| 331 |
-
<ClosedCaption /></button
|
| 332 |
-
>
|
| 333 |
-
{/if}
|
| 334 |
-
{#if editable && interactive}
|
| 335 |
-
{#if show_redo && !mode}
|
| 336 |
-
<button
|
| 337 |
-
class="action icon"
|
| 338 |
-
aria-label="Reset audio"
|
| 339 |
-
onclick={() => {
|
| 340 |
-
handle_reset_value();
|
| 341 |
-
clearRegions();
|
| 342 |
-
mode = "";
|
| 343 |
-
}}
|
| 344 |
-
>
|
| 345 |
-
<Undo />
|
| 346 |
-
</button>
|
| 347 |
-
{/if}
|
| 348 |
-
|
| 349 |
-
{#if !mode}
|
| 350 |
-
<button
|
| 351 |
-
class="action icon"
|
| 352 |
-
aria-label="Trim audio to selection"
|
| 353 |
-
onclick={toggleTrimmingMode}
|
| 354 |
-
>
|
| 355 |
-
<Trim />
|
| 356 |
-
</button>
|
| 357 |
-
{:else}
|
| 358 |
-
<button class="text-button" onclick={trimAudio}>Trim</button>
|
| 359 |
-
<button class="text-button" onclick={toggleTrimmingMode}>Cancel</button>
|
| 360 |
-
{/if}
|
| 361 |
-
{/if}
|
| 362 |
-
</div>
|
| 363 |
-
</div>
|
| 364 |
-
|
| 365 |
-
<style>
|
| 366 |
-
.settings-wrapper {
|
| 367 |
-
display: flex;
|
| 368 |
-
justify-self: self-end;
|
| 369 |
-
align-items: center;
|
| 370 |
-
grid-area: editing;
|
| 371 |
-
}
|
| 372 |
-
.text-button {
|
| 373 |
-
border: 1px solid var(--neutral-400);
|
| 374 |
-
border-radius: var(--radius-sm);
|
| 375 |
-
font-weight: 300;
|
| 376 |
-
font-size: var(--size-3);
|
| 377 |
-
text-align: center;
|
| 378 |
-
color: var(--neutral-400);
|
| 379 |
-
height: var(--size-5);
|
| 380 |
-
font-weight: bold;
|
| 381 |
-
padding: 0 5px;
|
| 382 |
-
margin-left: 5px;
|
| 383 |
-
}
|
| 384 |
-
|
| 385 |
-
.text-button:hover,
|
| 386 |
-
.text-button:focus {
|
| 387 |
-
color: var(--color-accent);
|
| 388 |
-
border-color: var(--color-accent);
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
.controls {
|
| 392 |
-
display: grid;
|
| 393 |
-
grid-template-columns: 1fr 1fr 1fr;
|
| 394 |
-
grid-template-areas: "controls playback editing";
|
| 395 |
-
margin-top: 5px;
|
| 396 |
-
align-items: center;
|
| 397 |
-
position: relative;
|
| 398 |
-
flex-wrap: wrap;
|
| 399 |
-
justify-content: space-between;
|
| 400 |
-
}
|
| 401 |
-
.controls div {
|
| 402 |
-
margin: var(--size-1) 0;
|
| 403 |
-
}
|
| 404 |
-
|
| 405 |
-
@media (max-width: 600px) {
|
| 406 |
-
.controls {
|
| 407 |
-
grid-template-columns: 1fr 1fr;
|
| 408 |
-
grid-template-rows: auto auto;
|
| 409 |
-
grid-template-areas:
|
| 410 |
-
"playback playback"
|
| 411 |
-
"controls editing";
|
| 412 |
-
}
|
| 413 |
-
}
|
| 414 |
-
|
| 415 |
-
@media (max-width: 319px) {
|
| 416 |
-
.controls {
|
| 417 |
-
overflow-x: scroll;
|
| 418 |
-
}
|
| 419 |
-
}
|
| 420 |
-
|
| 421 |
-
.hidden {
|
| 422 |
-
display: none;
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
.control-wrapper {
|
| 426 |
-
display: flex;
|
| 427 |
-
justify-self: self-start;
|
| 428 |
-
align-items: center;
|
| 429 |
-
justify-content: space-between;
|
| 430 |
-
grid-area: controls;
|
| 431 |
-
}
|
| 432 |
-
|
| 433 |
-
.action {
|
| 434 |
-
width: var(--size-5);
|
| 435 |
-
color: var(--neutral-400);
|
| 436 |
-
margin-left: var(--spacing-md);
|
| 437 |
-
}
|
| 438 |
-
.icon:hover,
|
| 439 |
-
.icon:focus {
|
| 440 |
-
color: var(--color-accent);
|
| 441 |
-
}
|
| 442 |
-
.play-pause-wrapper {
|
| 443 |
-
display: flex;
|
| 444 |
-
justify-self: center;
|
| 445 |
-
grid-area: playback;
|
| 446 |
-
}
|
| 447 |
-
.cc-button {
|
| 448 |
-
width: var(--size-8);
|
| 449 |
-
}
|
| 450 |
-
|
| 451 |
-
@media (max-width: 600px) {
|
| 452 |
-
.play-pause-wrapper {
|
| 453 |
-
margin: var(--spacing-md);
|
| 454 |
-
}
|
| 455 |
-
}
|
| 456 |
-
.playback {
|
| 457 |
-
border: 1px solid var(--neutral-400);
|
| 458 |
-
border-radius: var(--radius-sm);
|
| 459 |
-
width: 5.5ch;
|
| 460 |
-
font-weight: 300;
|
| 461 |
-
font-size: var(--size-3);
|
| 462 |
-
text-align: center;
|
| 463 |
-
color: var(--neutral-400);
|
| 464 |
-
height: var(--size-5);
|
| 465 |
-
font-weight: bold;
|
| 466 |
-
}
|
| 467 |
-
|
| 468 |
-
.playback:hover,
|
| 469 |
-
.playback:focus {
|
| 470 |
-
color: var(--color-accent);
|
| 471 |
-
border-color: var(--color-accent);
|
| 472 |
-
}
|
| 473 |
-
|
| 474 |
-
.rewind,
|
| 475 |
-
.skip {
|
| 476 |
-
margin: 0 10px;
|
| 477 |
-
color: var(--neutral-400);
|
| 478 |
-
}
|
| 479 |
-
|
| 480 |
-
.play-pause-button {
|
| 481 |
-
width: var(--size-8);
|
| 482 |
-
display: flex;
|
| 483 |
-
align-items: center;
|
| 484 |
-
justify-content: center;
|
| 485 |
-
color: var(--neutral-400);
|
| 486 |
-
fill: var(--neutral-400);
|
| 487 |
-
}
|
| 488 |
-
|
| 489 |
-
.volume {
|
| 490 |
-
position: relative;
|
| 491 |
-
display: flex;
|
| 492 |
-
justify-content: center;
|
| 493 |
-
margin-right: var(--spacing-xl);
|
| 494 |
-
width: var(--size-5);
|
| 495 |
-
}
|
| 496 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/WaveformRecordControls.svelte
DELETED
|
@@ -1,311 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { onMount, onDestroy } from "svelte";
|
| 3 |
-
import { Pause } from "@gradio/icons";
|
| 4 |
-
import type { I18nFormatter } from "@gradio/utils";
|
| 5 |
-
import RecordPlugin from "wavesurfer.js/dist/plugins/record.js";
|
| 6 |
-
import DeviceSelect from "./DeviceSelect.svelte";
|
| 7 |
-
|
| 8 |
-
let {
|
| 9 |
-
record,
|
| 10 |
-
i18n,
|
| 11 |
-
recording = false,
|
| 12 |
-
record_time,
|
| 13 |
-
show_recording_waveform,
|
| 14 |
-
timing = false
|
| 15 |
-
}: {
|
| 16 |
-
record: RecordPlugin;
|
| 17 |
-
i18n: I18nFormatter;
|
| 18 |
-
recording?: boolean;
|
| 19 |
-
record_time: string;
|
| 20 |
-
show_recording_waveform: boolean | undefined;
|
| 21 |
-
timing?: boolean;
|
| 22 |
-
} = $props();
|
| 23 |
-
|
| 24 |
-
let micDevices: MediaDeviceInfo[] = $state([]);
|
| 25 |
-
let recordButton: HTMLButtonElement;
|
| 26 |
-
let pauseButton: HTMLButtonElement;
|
| 27 |
-
let resumeButton: HTMLButtonElement;
|
| 28 |
-
let stopButton: HTMLButtonElement;
|
| 29 |
-
let stopButtonPaused: HTMLButtonElement;
|
| 30 |
-
let recording_ongoing = $state(false);
|
| 31 |
-
|
| 32 |
-
const handleRecordStart = (): void => {
|
| 33 |
-
recordButton.style.display = "none";
|
| 34 |
-
stopButton.style.display = "flex";
|
| 35 |
-
pauseButton.style.display = "block";
|
| 36 |
-
};
|
| 37 |
-
|
| 38 |
-
const handleRecordEnd = (): void => {
|
| 39 |
-
if (record.isPaused()) {
|
| 40 |
-
record.resumeRecording();
|
| 41 |
-
record.stopRecording();
|
| 42 |
-
}
|
| 43 |
-
record.stopMic();
|
| 44 |
-
|
| 45 |
-
recordButton.style.display = "flex";
|
| 46 |
-
stopButton.style.display = "none";
|
| 47 |
-
pauseButton.style.display = "none";
|
| 48 |
-
recordButton.disabled = false;
|
| 49 |
-
};
|
| 50 |
-
|
| 51 |
-
const handleRecordPause = (): void => {
|
| 52 |
-
pauseButton.style.display = "none";
|
| 53 |
-
resumeButton.style.display = "block";
|
| 54 |
-
stopButton.style.display = "none";
|
| 55 |
-
stopButtonPaused.style.display = "flex";
|
| 56 |
-
};
|
| 57 |
-
|
| 58 |
-
const handleRecordResume = (): void => {
|
| 59 |
-
pauseButton.style.display = "block";
|
| 60 |
-
resumeButton.style.display = "none";
|
| 61 |
-
recordButton.style.display = "none";
|
| 62 |
-
stopButton.style.display = "flex";
|
| 63 |
-
stopButtonPaused.style.display = "none";
|
| 64 |
-
};
|
| 65 |
-
|
| 66 |
-
onMount(() => {
|
| 67 |
-
record.on("record-start", handleRecordStart);
|
| 68 |
-
record.on("record-end", handleRecordEnd);
|
| 69 |
-
record.on("record-pause", handleRecordPause);
|
| 70 |
-
record.on("record-resume", handleRecordResume);
|
| 71 |
-
});
|
| 72 |
-
|
| 73 |
-
onDestroy(() => {
|
| 74 |
-
record.un("record-start", handleRecordStart);
|
| 75 |
-
record.un("record-end", handleRecordEnd);
|
| 76 |
-
record.un("record-pause", handleRecordPause);
|
| 77 |
-
record.un("record-resume", handleRecordResume);
|
| 78 |
-
});
|
| 79 |
-
|
| 80 |
-
$effect(() => {
|
| 81 |
-
if (recording && !recording_ongoing) {
|
| 82 |
-
record.startMic().then(() => {
|
| 83 |
-
record.startRecording();
|
| 84 |
-
recording_ongoing = true;
|
| 85 |
-
});
|
| 86 |
-
} else if (!recording && recording_ongoing) {
|
| 87 |
-
if (record.isPaused()) {
|
| 88 |
-
record.resumeRecording();
|
| 89 |
-
}
|
| 90 |
-
record.stopRecording();
|
| 91 |
-
recording_ongoing = false;
|
| 92 |
-
}
|
| 93 |
-
});
|
| 94 |
-
</script>
|
| 95 |
-
|
| 96 |
-
<div class="controls">
|
| 97 |
-
<div class="wrapper">
|
| 98 |
-
<button
|
| 99 |
-
bind:this={recordButton}
|
| 100 |
-
class="record record-button"
|
| 101 |
-
onclick={() => record.startRecording()}>{i18n("audio.record")}</button
|
| 102 |
-
>
|
| 103 |
-
|
| 104 |
-
<button
|
| 105 |
-
bind:this={stopButton}
|
| 106 |
-
class="stop-button {record.isPaused() ? 'stop-button-paused' : ''}"
|
| 107 |
-
onclick={() => {
|
| 108 |
-
if (record.isPaused()) {
|
| 109 |
-
record.resumeRecording();
|
| 110 |
-
record.stopRecording();
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
record.stopRecording();
|
| 114 |
-
}}>{i18n("audio.stop")}</button
|
| 115 |
-
>
|
| 116 |
-
|
| 117 |
-
<button
|
| 118 |
-
bind:this={stopButtonPaused}
|
| 119 |
-
id="stop-paused"
|
| 120 |
-
class="stop-button-paused"
|
| 121 |
-
onclick={() => {
|
| 122 |
-
if (record.isPaused()) {
|
| 123 |
-
record.resumeRecording();
|
| 124 |
-
record.stopRecording();
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
record.stopRecording();
|
| 128 |
-
}}>{i18n("audio.stop")}</button
|
| 129 |
-
>
|
| 130 |
-
|
| 131 |
-
<button
|
| 132 |
-
aria-label="pause"
|
| 133 |
-
bind:this={pauseButton}
|
| 134 |
-
class="pause-button"
|
| 135 |
-
onclick={() => record.pauseRecording()}><Pause /></button
|
| 136 |
-
>
|
| 137 |
-
<button
|
| 138 |
-
bind:this={resumeButton}
|
| 139 |
-
class="resume-button"
|
| 140 |
-
onclick={() => record.resumeRecording()}>{i18n("audio.resume")}</button
|
| 141 |
-
>
|
| 142 |
-
{#if timing && !show_recording_waveform}
|
| 143 |
-
<time class="duration-button duration">{record_time}</time>
|
| 144 |
-
{/if}
|
| 145 |
-
</div>
|
| 146 |
-
<DeviceSelect bind:micDevices {i18n} />
|
| 147 |
-
</div>
|
| 148 |
-
|
| 149 |
-
<style>
|
| 150 |
-
.controls {
|
| 151 |
-
display: flex;
|
| 152 |
-
align-items: center;
|
| 153 |
-
justify-content: space-between;
|
| 154 |
-
flex-wrap: wrap;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
.wrapper {
|
| 158 |
-
display: flex;
|
| 159 |
-
align-items: center;
|
| 160 |
-
flex-wrap: wrap;
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
.record {
|
| 164 |
-
margin-right: var(--spacing-md);
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
.stop-button-paused {
|
| 168 |
-
display: none;
|
| 169 |
-
height: var(--size-8);
|
| 170 |
-
width: var(--size-20);
|
| 171 |
-
background-color: var(--block-background-fill);
|
| 172 |
-
border-radius: var(--button-large-radius);
|
| 173 |
-
align-items: center;
|
| 174 |
-
border: 1px solid var(--block-border-color);
|
| 175 |
-
margin: var(--size-1) var(--size-1) 0 0;
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
.stop-button-paused::before {
|
| 179 |
-
content: "";
|
| 180 |
-
height: var(--size-4);
|
| 181 |
-
width: var(--size-4);
|
| 182 |
-
border-radius: var(--radius-full);
|
| 183 |
-
background: var(--primary-600);
|
| 184 |
-
margin: 0 var(--spacing-xl);
|
| 185 |
-
}
|
| 186 |
-
.stop-button::before {
|
| 187 |
-
content: "";
|
| 188 |
-
height: var(--size-4);
|
| 189 |
-
width: var(--size-4);
|
| 190 |
-
border-radius: var(--radius-full);
|
| 191 |
-
background: var(--primary-600);
|
| 192 |
-
margin: 0 var(--spacing-xl);
|
| 193 |
-
animation: scaling 1800ms infinite;
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
.stop-button {
|
| 197 |
-
display: none;
|
| 198 |
-
height: var(--size-8);
|
| 199 |
-
width: var(--size-20);
|
| 200 |
-
background-color: var(--block-background-fill);
|
| 201 |
-
border-radius: var(--button-large-radius);
|
| 202 |
-
align-items: center;
|
| 203 |
-
border: 1px solid var(--primary-600);
|
| 204 |
-
margin: var(--size-1) var(--size-1) 0 0;
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
.record-button::before {
|
| 208 |
-
content: "";
|
| 209 |
-
height: var(--size-4);
|
| 210 |
-
width: var(--size-4);
|
| 211 |
-
border-radius: var(--radius-full);
|
| 212 |
-
background: var(--primary-600);
|
| 213 |
-
margin: 0 var(--spacing-xl);
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
.record-button {
|
| 217 |
-
height: var(--size-8);
|
| 218 |
-
background-color: var(--block-background-fill);
|
| 219 |
-
border-radius: var(--button-large-radius);
|
| 220 |
-
display: flex;
|
| 221 |
-
align-items: center;
|
| 222 |
-
border: 1px solid var(--block-border-color);
|
| 223 |
-
padding-right: var(--spacing-xl);
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
.duration-button {
|
| 227 |
-
border-radius: var(--button-large-radius);
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
.stop-button:disabled {
|
| 231 |
-
cursor: not-allowed;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
.record-button:disabled {
|
| 235 |
-
cursor: not-allowed;
|
| 236 |
-
opacity: 0.5;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
@keyframes scaling {
|
| 240 |
-
0% {
|
| 241 |
-
background-color: var(--primary-600);
|
| 242 |
-
scale: 1;
|
| 243 |
-
}
|
| 244 |
-
50% {
|
| 245 |
-
background-color: var(--primary-600);
|
| 246 |
-
scale: 1.2;
|
| 247 |
-
}
|
| 248 |
-
100% {
|
| 249 |
-
background-color: var(--primary-600);
|
| 250 |
-
scale: 1;
|
| 251 |
-
}
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
.pause-button {
|
| 255 |
-
display: none;
|
| 256 |
-
height: var(--size-8);
|
| 257 |
-
width: var(--size-20);
|
| 258 |
-
border: 1px solid var(--block-border-color);
|
| 259 |
-
border-radius: var(--button-large-radius);
|
| 260 |
-
padding: var(--spacing-md);
|
| 261 |
-
margin: var(--size-1) var(--size-1) 0 0;
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
.resume-button {
|
| 265 |
-
display: none;
|
| 266 |
-
height: var(--size-8);
|
| 267 |
-
width: var(--size-20);
|
| 268 |
-
border: 1px solid var(--block-border-color);
|
| 269 |
-
border-radius: var(--button-large-radius);
|
| 270 |
-
padding: var(--spacing-xl);
|
| 271 |
-
line-height: 1px;
|
| 272 |
-
font-size: var(--text-md);
|
| 273 |
-
margin: var(--size-1) var(--size-1) 0 0;
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
.duration {
|
| 277 |
-
display: flex;
|
| 278 |
-
height: var(--size-8);
|
| 279 |
-
width: var(--size-20);
|
| 280 |
-
border: 1px solid var(--block-border-color);
|
| 281 |
-
padding: var(--spacing-md);
|
| 282 |
-
align-items: center;
|
| 283 |
-
justify-content: center;
|
| 284 |
-
margin: var(--size-1) var(--size-1) 0 0;
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
:global(::part(region)) {
|
| 288 |
-
border-radius: var(--radius-md);
|
| 289 |
-
height: 98% !important;
|
| 290 |
-
border: 1px solid var(--trim-region-color);
|
| 291 |
-
background-color: unset;
|
| 292 |
-
border-width: 1px 3px;
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
:global(::part(region))::after {
|
| 296 |
-
content: "";
|
| 297 |
-
position: absolute;
|
| 298 |
-
top: 0;
|
| 299 |
-
left: 0;
|
| 300 |
-
width: 100%;
|
| 301 |
-
height: 100%;
|
| 302 |
-
background: var(--trim-region-color);
|
| 303 |
-
opacity: 0.2;
|
| 304 |
-
border-radius: var(--radius-md);
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
:global(::part(region-handle)) {
|
| 308 |
-
width: 5px !important;
|
| 309 |
-
border: none;
|
| 310 |
-
}
|
| 311 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/audioBufferToWav.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
export function audioBufferToWav(audioBuffer: AudioBuffer): Uint8Array {
|
| 2 |
-
const numOfChan = audioBuffer.numberOfChannels;
|
| 3 |
-
const length = audioBuffer.length * numOfChan * 2 + 44;
|
| 4 |
-
const buffer = new ArrayBuffer(length);
|
| 5 |
-
const view = new DataView(buffer);
|
| 6 |
-
let offset = 0;
|
| 7 |
-
|
| 8 |
-
// Write WAV header
|
| 9 |
-
const writeString = function (
|
| 10 |
-
view: DataView,
|
| 11 |
-
offset: number,
|
| 12 |
-
string: string
|
| 13 |
-
): void {
|
| 14 |
-
for (let i = 0; i < string.length; i++) {
|
| 15 |
-
view.setUint8(offset + i, string.charCodeAt(i));
|
| 16 |
-
}
|
| 17 |
-
};
|
| 18 |
-
|
| 19 |
-
writeString(view, offset, "RIFF");
|
| 20 |
-
offset += 4;
|
| 21 |
-
view.setUint32(offset, length - 8, true);
|
| 22 |
-
offset += 4;
|
| 23 |
-
writeString(view, offset, "WAVE");
|
| 24 |
-
offset += 4;
|
| 25 |
-
writeString(view, offset, "fmt ");
|
| 26 |
-
offset += 4;
|
| 27 |
-
view.setUint32(offset, 16, true);
|
| 28 |
-
offset += 4; // Sub-chunk size, 16 for PCM
|
| 29 |
-
view.setUint16(offset, 1, true);
|
| 30 |
-
offset += 2; // PCM format
|
| 31 |
-
view.setUint16(offset, numOfChan, true);
|
| 32 |
-
offset += 2;
|
| 33 |
-
view.setUint32(offset, audioBuffer.sampleRate, true);
|
| 34 |
-
offset += 4;
|
| 35 |
-
view.setUint32(offset, audioBuffer.sampleRate * 2 * numOfChan, true);
|
| 36 |
-
offset += 4;
|
| 37 |
-
view.setUint16(offset, numOfChan * 2, true);
|
| 38 |
-
offset += 2;
|
| 39 |
-
view.setUint16(offset, 16, true);
|
| 40 |
-
offset += 2;
|
| 41 |
-
writeString(view, offset, "data");
|
| 42 |
-
offset += 4;
|
| 43 |
-
view.setUint32(offset, audioBuffer.length * numOfChan * 2, true);
|
| 44 |
-
offset += 4;
|
| 45 |
-
|
| 46 |
-
// Write PCM audio data
|
| 47 |
-
for (let i = 0; i < audioBuffer.length; i++) {
|
| 48 |
-
for (let channel = 0; channel < numOfChan; channel++) {
|
| 49 |
-
const sample = Math.max(
|
| 50 |
-
-1,
|
| 51 |
-
Math.min(1, audioBuffer.getChannelData(channel)[i])
|
| 52 |
-
);
|
| 53 |
-
view.setInt16(offset, sample * 0x7fff, true);
|
| 54 |
-
offset += 2;
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
return new Uint8Array(buffer);
|
| 59 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6.11.1/audio/shared/index.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
export { default as Audio } from "./Audio.svelte";
|
| 2 |
-
export { default as MinimalAudioPlayer } from "./MinimalAudioPlayer.svelte";
|
| 3 |
-
export { default as MinimalAudioRecorder } from "./MinimalAudioRecorder.svelte";
|
|
|
|
|
|
|
|
|
|
|
|