gradio-pr-bot commited on
Commit
db539d3
·
verified ·
1 Parent(s): 7059078

Upload folder using huggingface_hub

Browse files
6.22.1/multimodaltextbox/Example.svelte ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { Image } from "@gradio/image/shared";
3
+ import { Video } from "@gradio/video/shared";
4
+ import type { FileData } from "@gradio/client";
5
+
6
+ let {
7
+ value = { text: "", files: [] },
8
+ type,
9
+ selected = false
10
+ }: {
11
+ value?: { text: string; files: FileData[] };
12
+ type: "gallery" | "table";
13
+ selected?: boolean;
14
+ } = $props();
15
+
16
+ let size = $state<number>(0);
17
+ let el: HTMLDivElement;
18
+
19
+ function set_styles(element: HTMLElement, el_width: number): void {
20
+ element.style.setProperty(
21
+ "--local-text-width",
22
+ `${el_width && el_width < 150 ? el_width : 200}px`
23
+ );
24
+ element.style.whiteSpace = "unset";
25
+ }
26
+
27
+ $effect(() => {
28
+ if (el && size) {
29
+ set_styles(el, size);
30
+ }
31
+ });
32
+ </script>
33
+
34
+ <div
35
+ class="container"
36
+ bind:clientWidth={size}
37
+ bind:this={el}
38
+ class:table={type === "table"}
39
+ class:gallery={type === "gallery"}
40
+ class:selected
41
+ class:border={value}
42
+ >
43
+ <p>{value.text ? value.text : ""}</p>
44
+ {#each value.files as file}
45
+ {#if file.mime_type && file.mime_type.includes("image")}
46
+ <Image src={file.url} alt="" />
47
+ {:else if file.mime_type && file.mime_type.includes("video")}
48
+ <Video src={file.url} alt="" loop={true} is_stream={false} />
49
+ {:else if file.mime_type && file.mime_type.includes("audio")}
50
+ <audio src={file.url} controls />
51
+ {:else}
52
+ {file.orig_name}
53
+ {/if}
54
+ {/each}
55
+ </div>
56
+
57
+ <style>
58
+ .gallery {
59
+ padding: var(--size-1) var(--size-2);
60
+ display: flex;
61
+ align-items: center;
62
+ gap: 20px;
63
+ overflow-x: auto;
64
+ }
65
+
66
+ div {
67
+ overflow: hidden;
68
+ min-width: var(--local-text-width);
69
+ white-space: nowrap;
70
+ }
71
+
72
+ .container :global(img),
73
+ .container :global(video) {
74
+ object-fit: contain;
75
+ width: 100px;
76
+ height: 100px;
77
+ }
78
+
79
+ .container.selected {
80
+ border-color: var(--border-color-accent);
81
+ }
82
+ .border.table {
83
+ border: 2px solid var(--border-color-primary);
84
+ }
85
+
86
+ .container.table {
87
+ margin: 0 auto;
88
+ border-radius: var(--radius-lg);
89
+ overflow-x: auto;
90
+ width: max-content;
91
+ height: max-content;
92
+ object-fit: cover;
93
+ padding: var(--size-2);
94
+ }
95
+
96
+ .container.gallery {
97
+ object-fit: cover;
98
+ }
99
+
100
+ div > :global(p) {
101
+ font-size: var(--text-lg);
102
+ white-space: normal;
103
+ }
104
+ </style>
6.22.1/multimodaltextbox/Index.svelte ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script context="module" lang="ts">
4
+ export { default as BaseMultimodalTextbox } from "./shared/MultimodalTextbox.svelte";
5
+ export { default as BaseExample } from "./Example.svelte";
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { Gradio, type SelectData } from "@gradio/utils";
10
+ import MultimodalTextbox from "./shared/MultimodalTextbox.svelte";
11
+ import { Block } from "@gradio/atoms";
12
+ import { StatusTracker } from "@gradio/statustracker";
13
+ import { onMount, tick } from "svelte";
14
+ import type { WaveformOptions } from "../audio/shared/types";
15
+ import type {
16
+ MultimodalTextboxProps,
17
+ MultimodalTextboxEvents
18
+ } from "./types";
19
+
20
+ let upload_promise = $state<Promise<any> | null>(null);
21
+
22
+ class MultimodalTextboxGradio extends Gradio<
23
+ MultimodalTextboxEvents,
24
+ MultimodalTextboxProps
25
+ > {
26
+ async get_data() {
27
+ if (upload_promise) {
28
+ await upload_promise;
29
+ await tick();
30
+ }
31
+ const data = await super.get_data();
32
+
33
+ return data;
34
+ }
35
+ }
36
+
37
+ let props = $props();
38
+ const gradio = new MultimodalTextboxGradio(props);
39
+
40
+ gradio.props.value = gradio.props.value ?? { text: "", files: [] };
41
+
42
+ let dragging = $state<boolean>(false);
43
+ let active_source = $state<"microphone" | null>(null);
44
+
45
+ let color_accent = "darkorange";
46
+
47
+ const waveform_settings = {
48
+ height: 50,
49
+ barWidth: 2,
50
+ barGap: 3,
51
+ cursorWidth: 2,
52
+ cursorColor: "#ddd5e9",
53
+ autoplay: false,
54
+ barRadius: 10,
55
+ dragToSeek: true,
56
+ normalize: true,
57
+ minPxPerSec: 20,
58
+ waveColor: "",
59
+ progressColor: "",
60
+ mediaControls: false as boolean | undefined,
61
+ sampleRate: 44100
62
+ };
63
+
64
+ onMount(() => {
65
+ color_accent = getComputedStyle(document?.documentElement).getPropertyValue(
66
+ "--color-accent"
67
+ );
68
+ set_trim_region_colour();
69
+ waveform_settings.waveColor =
70
+ gradio.props?.waveform_options?.waveform_color || "#9ca3af";
71
+ waveform_settings.progressColor =
72
+ gradio.props?.waveform_options?.waveform_progress_color || color_accent;
73
+ waveform_settings.mediaControls =
74
+ gradio.props?.waveform_options?.show_controls;
75
+ waveform_settings.sampleRate =
76
+ gradio.props?.waveform_options?.sample_rate || 44100;
77
+ });
78
+
79
+ const trim_region_settings = {
80
+ color: gradio.props?.waveform_options?.trim_region_color,
81
+ drag: true,
82
+ resize: true
83
+ };
84
+
85
+ function set_trim_region_colour(): void {
86
+ document.documentElement.style.setProperty(
87
+ "--trim-region-color",
88
+ trim_region_settings.color || color_accent
89
+ );
90
+ }
91
+
92
+ // Create const references to the callbacks so that afterUpdate in child is not called on every prop change
93
+ // in the DOM. See https://github.com/gradio-app/gradio/issues/11933
94
+
95
+ const upload_fn = (...args: Parameters<typeof gradio.shared.client.upload>) =>
96
+ gradio.shared.client.upload(...args);
97
+ const i18n = (s: string | null | undefined): string => gradio.i18n(s);
98
+ const stream_handler_fn = (
99
+ ...args: Parameters<typeof gradio.shared.client.stream>
100
+ ): EventSource => gradio.shared.client.stream(...args);
101
+
102
+ let sources_string = $derived(
103
+ gradio.props.sources.join(",") as
104
+ | "upload"
105
+ | "upload,microphone"
106
+ | "microphone"
107
+ | "microphone,upload"
108
+ );
109
+
110
+ let file_types_string = $derived.by(
111
+ () => (gradio.props.file_types || []).join(",") || null
112
+ );
113
+ </script>
114
+
115
+ <Block
116
+ visible={gradio.shared.visible}
117
+ elem_id={gradio.shared.elem_id}
118
+ elem_classes={[...(gradio.shared.elem_classes || []), "multimodal-textbox"]}
119
+ scale={gradio.shared.scale}
120
+ min_width={gradio.shared.min_width}
121
+ allow_overflow={false}
122
+ padding={false}
123
+ border_mode={dragging ? "focus" : "base"}
124
+ rtl={gradio.props.rtl}
125
+ >
126
+ {#if gradio.shared.loading_status}
127
+ <StatusTracker
128
+ autoscroll={gradio.shared.autoscroll}
129
+ i18n={gradio.i18n}
130
+ {...gradio.shared.loading_status}
131
+ on_clear_status={() =>
132
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
133
+ />
134
+ {/if}
135
+
136
+ <MultimodalTextbox
137
+ bind:upload_promise
138
+ bind:value={gradio.props.value}
139
+ value_is_output
140
+ bind:dragging
141
+ bind:active_source
142
+ {file_types_string}
143
+ root={gradio.shared.root}
144
+ label={gradio.shared.label || "MultimodalTextbox"}
145
+ info={gradio.props.info}
146
+ show_label={gradio.shared.show_label}
147
+ lines={gradio.props.lines}
148
+ rtl={gradio.props.rtl}
149
+ text_align={gradio.props.text_align}
150
+ waveform_settings={waveform_settings as WaveformOptions}
151
+ {i18n}
152
+ max_lines={!gradio.props.max_lines
153
+ ? gradio.props.lines + 1
154
+ : gradio.props.max_lines}
155
+ placeholder={gradio.props.placeholder}
156
+ submit_btn={gradio.props.submit_btn}
157
+ stop_btn={gradio.props.stop_btn}
158
+ autofocus={gradio.props.autofocus}
159
+ autoscroll={gradio.shared.autoscroll}
160
+ file_count={gradio.props.file_count}
161
+ {sources_string}
162
+ max_file_size={gradio.shared.max_file_size}
163
+ onchange={(e) => {
164
+ gradio.props.value = e;
165
+ gradio.dispatch("change", gradio.props.value);
166
+ }}
167
+ oninput={() => gradio.dispatch("input")}
168
+ onsubmit={() => gradio.dispatch("submit")}
169
+ onstop={() => gradio.dispatch("stop")}
170
+ onblur={() => gradio.dispatch("blur")}
171
+ onselect={(e) => gradio.dispatch("select", e)}
172
+ onfocus={() => gradio.dispatch("focus")}
173
+ onerror={(detail) => {
174
+ gradio.dispatch("error", detail);
175
+ }}
176
+ onstop_recording={() => gradio.dispatch("stop_recording")}
177
+ onupload={(e) => gradio.dispatch("upload", e)}
178
+ onclear={() => gradio.dispatch("clear")}
179
+ disabled={!gradio.shared.interactive}
180
+ upload={upload_fn}
181
+ stream_handler={stream_handler_fn}
182
+ max_plain_text_length={gradio.props.max_plain_text_length}
183
+ html_attributes={gradio.props.html_attributes}
184
+ />
185
+ </Block>
6.22.1/multimodaltextbox/package.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/multimodaltextbox",
3
+ "version": "0.14.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "Index.svelte",
11
+ "exports": {
12
+ ".": {
13
+ "gradio": "./Index.svelte",
14
+ "svelte": "./dist/Index.svelte",
15
+ "types": "./dist/Index.svelte.d.ts"
16
+ },
17
+ "./example": {
18
+ "gradio": "./Example.svelte",
19
+ "svelte": "./dist/Example.svelte",
20
+ "types": "./dist/Example.svelte.d.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "dependencies": {
25
+ "@gradio/atoms": "workspace:^",
26
+ "@gradio/icons": "workspace:^",
27
+ "@gradio/statustracker": "workspace:^",
28
+ "@gradio/utils": "workspace:^",
29
+ "@gradio/upload": "workspace:^",
30
+ "@gradio/image": "workspace:^",
31
+ "@gradio/video": "workspace:^",
32
+ "@gradio/client": "workspace:^",
33
+ "@gradio/audio": "workspace:^"
34
+ },
35
+ "devDependencies": {
36
+ "@gradio/preview": "workspace:^"
37
+ },
38
+ "peerDependencies": {
39
+ "svelte": "^5.48.0"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/gradio-app/gradio.git",
44
+ "directory": "js/multimodaltextbox"
45
+ }
46
+ }
6.22.1/multimodaltextbox/shared/MultimodalTextbox.svelte ADDED
@@ -0,0 +1,1074 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { tick } from "svelte";
3
+ import { text_area_resize, resize } from "../shared/utils";
4
+ import { BlockTitle, ScrollFade } from "@gradio/atoms";
5
+ import { Upload } from "@gradio/upload";
6
+ import { Image } from "@gradio/image/shared";
7
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
8
+ import type { FileData, Client } from "@gradio/client";
9
+ import type { WaveformOptions } from "@gradio/audio";
10
+ import {
11
+ Clear,
12
+ File,
13
+ Music,
14
+ Paperclip,
15
+ Video,
16
+ ArrowUp,
17
+ Square,
18
+ Microphone,
19
+ Check
20
+ } from "@gradio/icons";
21
+ import { should_show_scroll_fade, type SelectData } from "@gradio/utils";
22
+ import {
23
+ MinimalAudioPlayer,
24
+ MinimalAudioRecorder
25
+ } from "@gradio/audio/shared";
26
+ import type { InputHTMLAttributes } from "./types";
27
+
28
+ let {
29
+ value = $bindable<{ text: string; files: FileData[] }>({
30
+ text: "",
31
+ files: []
32
+ }),
33
+ value_is_output = false,
34
+ lines = 1,
35
+ i18n: _i18n,
36
+ placeholder = "",
37
+ disabled = false,
38
+ label,
39
+ info = undefined,
40
+ show_label = true,
41
+ max_lines,
42
+ submit_btn = null,
43
+ stop_btn = null,
44
+ rtl = false,
45
+ autofocus = false,
46
+ text_align = undefined,
47
+ autoscroll = true,
48
+ root,
49
+ file_types_string = null,
50
+ max_file_size = null,
51
+ upload,
52
+ stream_handler,
53
+ file_count = "multiple",
54
+ max_plain_text_length = 1000,
55
+ waveform_settings,
56
+ waveform_options: _waveform_options = { show_recording_waveform: true },
57
+ sources_string = "upload",
58
+ active_source = $bindable<"microphone" | null>(),
59
+ html_attributes = null,
60
+ upload_promise = $bindable<Promise<any> | null>(),
61
+ dragging = $bindable<boolean>(),
62
+ onchange,
63
+ onsubmit,
64
+ onstop,
65
+ onblur,
66
+ onselect,
67
+ oninput,
68
+ onfocus,
69
+ ondrag,
70
+ onupload,
71
+ onclear,
72
+ onload: _onload,
73
+ onerror,
74
+ onstop_recording
75
+ }: {
76
+ value?: { text: string; files: FileData[] };
77
+ value_is_output?: boolean;
78
+ lines?: number;
79
+ i18n: I18nFormatter;
80
+ placeholder?: string;
81
+ disabled?: boolean;
82
+ label: string;
83
+ info?: string | undefined;
84
+ show_label?: boolean;
85
+ max_lines: number;
86
+ submit_btn?: string | boolean | null;
87
+ stop_btn?: string | boolean | null;
88
+ rtl?: boolean;
89
+ autofocus?: boolean;
90
+ text_align?: "left" | "right" | undefined;
91
+ autoscroll?: boolean;
92
+ root: string;
93
+ file_types_string?: string | null;
94
+ max_file_size?: number | null;
95
+ upload: Client["upload"];
96
+ stream_handler: Client["stream"];
97
+ file_count?: "single" | "multiple" | "directory";
98
+ max_plain_text_length?: number;
99
+ waveform_settings: Record<string, any>;
100
+ waveform_options?: WaveformOptions;
101
+ sources_string?:
102
+ | "upload"
103
+ | "upload,microphone"
104
+ | "microphone"
105
+ | "microphone,upload";
106
+ active_source?: "microphone" | null;
107
+ html_attributes?: InputHTMLAttributes | null;
108
+ upload_promise?: Promise<any> | null;
109
+ dragging?: boolean;
110
+ onchange?: (value: { text: string; files: FileData[] }) => void;
111
+ onsubmit?: () => void;
112
+ onstop?: () => void;
113
+ onblur?: () => void;
114
+ onselect?: (data: SelectData) => void;
115
+ oninput?: () => void;
116
+ onfocus?: () => void;
117
+ ondrag?: (dragging: boolean) => void;
118
+ onupload?: (files: FileData[] | FileData) => void;
119
+ onclear?: () => void;
120
+ onload?: (files: FileData[] | FileData) => void;
121
+ onerror?: (error: string) => void;
122
+ onstop_recording?: () => void;
123
+ } = $props();
124
+
125
+ let upload_component: Upload;
126
+ let el: HTMLTextAreaElement | HTMLInputElement;
127
+ let can_scroll = $state(false);
128
+ let previous_scroll_top = $state(0);
129
+ let user_has_scrolled_up = $state(false);
130
+ let show_fade = $state(false);
131
+ let uploading = $state(false);
132
+ let oldValue = $state(value?.text ?? "");
133
+ let recording = $state(false);
134
+ let mic_audio = $state<FileData | null>(null);
135
+ let full_container: HTMLDivElement;
136
+
137
+ let sources = $derived(
138
+ sources_string
139
+ .split(",")
140
+ .map((s) => s.trim())
141
+ .filter((s) => s === "upload" || s === "microphone") as (
142
+ | "upload"
143
+ | "microphone"
144
+ )[]
145
+ );
146
+
147
+ let file_types = $derived(
148
+ file_types_string ? file_types_string.split(",").map((s) => s.trim()) : null
149
+ );
150
+
151
+ let show_upload = $derived(
152
+ sources &&
153
+ sources.includes("upload") &&
154
+ !(file_count === "single" && value?.files?.length > 0)
155
+ );
156
+
157
+ function update_fade(): void {
158
+ show_fade = should_show_scroll_fade(el);
159
+ }
160
+
161
+ $effect(() => {
162
+ if (el && value?.text !== undefined) {
163
+ tick().then(update_fade);
164
+ }
165
+ });
166
+
167
+ $effect(() => {
168
+ ondrag?.(dragging);
169
+ });
170
+
171
+ $effect(() => {
172
+ if (value && oldValue !== value.text) {
173
+ onchange?.(value);
174
+ oldValue = value.text;
175
+ }
176
+ });
177
+
178
+ $effect(() => {
179
+ value?.text;
180
+ if (el && lines !== max_lines) {
181
+ resize(el, lines, max_lines);
182
+ }
183
+ });
184
+
185
+ $effect.pre(() => {
186
+ if (el && el.offsetHeight + el.scrollTop > el.scrollHeight - 100) {
187
+ can_scroll = true;
188
+ }
189
+ });
190
+
191
+ const scroll = (): void => {
192
+ if (can_scroll && autoscroll && !user_has_scrolled_up) {
193
+ el.scrollTo(0, el.scrollHeight);
194
+ }
195
+ };
196
+
197
+ async function handle_change(): Promise<void> {
198
+ onchange?.(value);
199
+ if (!value_is_output) {
200
+ oninput?.();
201
+ }
202
+ }
203
+
204
+ $effect(() => {
205
+ value;
206
+ if (autofocus && el) {
207
+ el.focus();
208
+ }
209
+ });
210
+
211
+ $effect(() => {
212
+ if (can_scroll && autoscroll) {
213
+ scroll();
214
+ }
215
+ });
216
+
217
+ function handle_select(event: Event): void {
218
+ const target: HTMLTextAreaElement | HTMLInputElement = event.target as
219
+ | HTMLTextAreaElement
220
+ | HTMLInputElement;
221
+ const text = target.value;
222
+ const index: [number, number] = [
223
+ target.selectionStart as number,
224
+ target.selectionEnd as number
225
+ ];
226
+ onselect?.({ value: text.substring(...index), index: index });
227
+ }
228
+
229
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
230
+ if (e.key === "Enter" && e.shiftKey && lines > 1) {
231
+ e.preventDefault();
232
+ await tick();
233
+ onsubmit?.();
234
+ } else if (
235
+ e.key === "Enter" &&
236
+ !e.shiftKey &&
237
+ lines === 1 &&
238
+ max_lines >= 1
239
+ ) {
240
+ e.preventDefault();
241
+ add_mic_audio_to_files();
242
+ active_source = null;
243
+ await tick();
244
+ onsubmit?.();
245
+ }
246
+ }
247
+
248
+ function handle_scroll(event: Event): void {
249
+ const target = event.target as HTMLElement;
250
+ const current_scroll_top = target.scrollTop;
251
+ if (current_scroll_top < previous_scroll_top) {
252
+ user_has_scrolled_up = true;
253
+ }
254
+ previous_scroll_top = current_scroll_top;
255
+
256
+ const max_scroll_top = target.scrollHeight - target.clientHeight;
257
+ const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
258
+ if (user_has_scrolled_to_bottom) {
259
+ user_has_scrolled_up = false;
260
+ }
261
+ update_fade();
262
+ }
263
+
264
+ async function handle_upload(detail: FileData | FileData[]): Promise<void> {
265
+ handle_change();
266
+ if (Array.isArray(detail)) {
267
+ for (let file of detail) {
268
+ value.files.push(file);
269
+ }
270
+ value = value;
271
+ } else {
272
+ value.files.push(detail);
273
+ value = value;
274
+ }
275
+ await tick();
276
+ onchange?.(value);
277
+ onupload?.(detail);
278
+ }
279
+
280
+ function remove_thumbnail(event: MouseEvent, index: number): void {
281
+ handle_change();
282
+ event.stopPropagation();
283
+ value.files.splice(index, 1);
284
+ value = value;
285
+ }
286
+
287
+ function handle_upload_click(): void {
288
+ upload_component.open_upload();
289
+ }
290
+
291
+ function handle_stop(): void {
292
+ onstop?.();
293
+ }
294
+
295
+ function add_mic_audio_to_files(): void {
296
+ if (mic_audio) {
297
+ value.files.push(mic_audio);
298
+ value = value;
299
+ mic_audio = null;
300
+ onchange?.(value);
301
+ }
302
+ }
303
+
304
+ function handle_submit(): void {
305
+ add_mic_audio_to_files();
306
+ active_source = null;
307
+ onsubmit?.();
308
+ }
309
+
310
+ async function handle_paste(event: ClipboardEvent): Promise<void> {
311
+ if (!event.clipboardData) return;
312
+ const items = event.clipboardData.items;
313
+ const text = event.clipboardData.getData("text");
314
+
315
+ if (text && text.length > max_plain_text_length) {
316
+ event.preventDefault();
317
+ const file = new window.File([text], "pasted_text.txt", {
318
+ type: "text/plain",
319
+ lastModified: Date.now()
320
+ });
321
+ if (upload_component) {
322
+ upload_component.load_files([file]);
323
+ }
324
+ return;
325
+ }
326
+
327
+ for (let index in items) {
328
+ const item = items[index];
329
+ if (item.kind === "file" && item.type.includes("image")) {
330
+ const blob = item.getAsFile();
331
+ if (blob) upload_component.load_files([blob]);
332
+ }
333
+ }
334
+ }
335
+
336
+ function handle_dragenter(event: DragEvent): void {
337
+ event.preventDefault();
338
+ dragging = true;
339
+ }
340
+
341
+ function handle_dragleave(event: DragEvent): void {
342
+ event.preventDefault();
343
+ const rect = full_container.getBoundingClientRect();
344
+ const { clientX, clientY } = event;
345
+ if (
346
+ clientX <= rect.left ||
347
+ clientX >= rect.right ||
348
+ clientY <= rect.top ||
349
+ clientY >= rect.bottom
350
+ ) {
351
+ dragging = false;
352
+ }
353
+ }
354
+
355
+ function handle_drop(event: DragEvent): void {
356
+ event.preventDefault();
357
+ dragging = false;
358
+ if (event.dataTransfer && event.dataTransfer.files) {
359
+ const files = Array.from(event.dataTransfer.files);
360
+
361
+ if (file_types) {
362
+ const valid_files = files.filter((file) => {
363
+ return file_types.some((type) => {
364
+ if (type.startsWith(".")) {
365
+ return file.name.toLowerCase().endsWith(type.toLowerCase());
366
+ }
367
+ return file.type.match(new RegExp(type.replace("*", ".*")));
368
+ });
369
+ });
370
+
371
+ const invalid_files = files.length - valid_files.length;
372
+ if (invalid_files > 0) {
373
+ onerror?.(
374
+ `${invalid_files} file(s) were rejected. Accepted formats: ${file_types.join(", ")}`
375
+ );
376
+ }
377
+
378
+ if (valid_files.length > 0) {
379
+ upload_component.load_files(valid_files);
380
+ }
381
+ } else {
382
+ upload_component.load_files(files);
383
+ }
384
+ }
385
+ }
386
+ </script>
387
+
388
+ <div
389
+ class="full-container"
390
+ class:dragging
391
+ bind:this={full_container}
392
+ ondragenter={handle_dragenter}
393
+ ondragleave={handle_dragleave}
394
+ ondragover={(e) => e.preventDefault()}
395
+ ondrop={handle_drop}
396
+ role="group"
397
+ aria-label="Multimedia input field"
398
+ >
399
+ <BlockTitle {show_label} {info} {rtl}>{label}</BlockTitle>
400
+ <div class="input-container">
401
+ {#if sources && sources.includes("microphone") && active_source === "microphone"}
402
+ <div class="recording-overlay" class:has-audio={mic_audio !== null}>
403
+ {#if !mic_audio}
404
+ <div class="recording-content">
405
+ <MinimalAudioRecorder
406
+ label={label || "Audio"}
407
+ {waveform_settings}
408
+ {recording}
409
+ {upload}
410
+ {root}
411
+ {max_file_size}
412
+ bind:upload_promise
413
+ onchange={(audio_value) => {
414
+ mic_audio = audio_value;
415
+ }}
416
+ onstoprecording={() => {
417
+ recording = false;
418
+ onstop_recording?.();
419
+ }}
420
+ onclear={() => {
421
+ active_source = null;
422
+ recording = false;
423
+ mic_audio = null;
424
+ onclear?.();
425
+ }}
426
+ />
427
+ </div>
428
+ {:else}
429
+ <div class="recording-content">
430
+ <MinimalAudioPlayer
431
+ value={mic_audio}
432
+ label={label || "Audio"}
433
+ loop={false}
434
+ />
435
+ <div class="action-buttons">
436
+ <button
437
+ class="confirm-button"
438
+ onclick={() => {
439
+ add_mic_audio_to_files();
440
+ active_source = null;
441
+ recording = false;
442
+ }}
443
+ aria-label="Attach audio"
444
+ >
445
+ <Check />
446
+ </button>
447
+ <button
448
+ class="cancel-button"
449
+ onclick={() => {
450
+ active_source = null;
451
+ recording = false;
452
+ mic_audio = null;
453
+ }}
454
+ aria-label="Clear audio"
455
+ >
456
+ <Clear />
457
+ </button>
458
+ </div>
459
+ </div>
460
+ {/if}
461
+ </div>
462
+ {/if}
463
+ {#if show_upload}
464
+ <Upload
465
+ bind:upload_promise
466
+ bind:this={upload_component}
467
+ onload={handle_upload}
468
+ {file_count}
469
+ filetype={file_types}
470
+ {root}
471
+ {max_file_size}
472
+ bind:dragging
473
+ bind:uploading
474
+ show_progress={false}
475
+ disable_click={true}
476
+ {onerror}
477
+ hidden={true}
478
+ {upload}
479
+ {stream_handler}
480
+ />
481
+ {/if}
482
+
483
+ <div
484
+ class="input-wrapper"
485
+ class:has-files={(value?.files?.length ?? 0) > 0 || uploading}
486
+ >
487
+ {#if (value?.files?.length ?? 0) > 0 || uploading}
488
+ <div
489
+ class="thumbnails"
490
+ aria-label="Uploaded files"
491
+ data-testid="container_el"
492
+ >
493
+ {#if show_upload}
494
+ <button
495
+ data-testid="upload-button"
496
+ class="upload-button thumbnail-add"
497
+ {disabled}
498
+ onclick={handle_upload_click}
499
+ aria-label="Upload a file"
500
+ >
501
+ <Paperclip />
502
+ </button>
503
+ {/if}
504
+ {#each value?.files ?? [] as file, index}
505
+ <span
506
+ class="thumbnail-wrapper"
507
+ role="listitem"
508
+ aria-label="File thumbnail"
509
+ >
510
+ <div class="thumbnail-item thumbnail-small">
511
+ {#if file.mime_type && file.mime_type.includes("image")}
512
+ <Image
513
+ src={file.url}
514
+ restProps={{
515
+ title: null,
516
+ alt: "",
517
+ loading: "lazy",
518
+ class: "thumbnail-image"
519
+ }}
520
+ />
521
+ {:else if file.mime_type && file.mime_type.includes("audio")}
522
+ <Music />
523
+ {:else if file.mime_type && file.mime_type.includes("video")}
524
+ <Video />
525
+ {:else}
526
+ <File />
527
+ {/if}
528
+ <button
529
+ class="delete-button"
530
+ onclick={(event) => remove_thumbnail(event, index)}
531
+ aria-label="Remove file"
532
+ >
533
+ <Clear />
534
+ </button>
535
+ </div>
536
+ </span>
537
+ {/each}
538
+ {#if uploading}
539
+ <div class="loader" role="status" aria-label="Uploading"></div>
540
+ {/if}
541
+ </div>
542
+ {/if}
543
+
544
+ <div class="input-row">
545
+ {#if show_upload && (value?.files?.length ?? 0) === 0 && !uploading}
546
+ <button
547
+ data-testid="upload-button"
548
+ class="upload-button icon-button"
549
+ {disabled}
550
+ onclick={handle_upload_click}
551
+ aria-label="Upload a file"
552
+ >
553
+ <Paperclip />
554
+ </button>
555
+ {/if}
556
+ <div class="textarea-wrapper">
557
+ <textarea
558
+ data-testid="textbox"
559
+ use:text_area_resize={{
560
+ text: value.text,
561
+ lines: lines,
562
+ max_lines: max_lines
563
+ }}
564
+ class:no-label={!show_label}
565
+ dir={rtl ? "rtl" : "ltr"}
566
+ bind:value={value.text}
567
+ bind:this={el}
568
+ {placeholder}
569
+ rows={lines}
570
+ {disabled}
571
+ onkeypress={handle_keypress}
572
+ onblur={() => onblur?.()}
573
+ onselect={handle_select}
574
+ onfocus={() => onfocus?.()}
575
+ onscroll={handle_scroll}
576
+ onpaste={handle_paste}
577
+ style={text_align ? "text-align: " + text_align : ""}
578
+ autocapitalize={html_attributes?.autocapitalize}
579
+ autocorrect={html_attributes?.autocorrect}
580
+ spellcheck={html_attributes?.spellcheck}
581
+ autocomplete={html_attributes?.autocomplete}
582
+ tabindex={html_attributes?.tabindex}
583
+ enterkeyhint={html_attributes?.enterkeyhint}
584
+ lang={html_attributes?.lang}
585
+ />
586
+ <ScrollFade visible={show_fade} position="absolute" />
587
+ </div>
588
+
589
+ {#if sources && sources.includes("microphone")}
590
+ <button
591
+ data-testid="microphone-button"
592
+ class="microphone-button"
593
+ class:recording
594
+ {disabled}
595
+ onclick={async () => {
596
+ if (active_source !== "microphone") {
597
+ active_source = "microphone";
598
+ await tick();
599
+ recording = true;
600
+ } else {
601
+ active_source = null;
602
+ recording = false;
603
+ }
604
+ }}
605
+ aria-label="Record audio"
606
+ >
607
+ <Microphone />
608
+ </button>
609
+ {/if}
610
+
611
+ {#if submit_btn}
612
+ <button
613
+ class="submit-button"
614
+ data-testid="submit-button"
615
+ class:padded-button={submit_btn !== true}
616
+ {disabled}
617
+ onclick={handle_submit}
618
+ aria-label="Submit"
619
+ >
620
+ {#if submit_btn === true}
621
+ <ArrowUp />
622
+ {:else}
623
+ {submit_btn}
624
+ {/if}
625
+ </button>
626
+ {/if}
627
+ {#if stop_btn}
628
+ <button
629
+ class="stop-button"
630
+ class:padded-button={stop_btn !== true}
631
+ onclick={handle_stop}
632
+ aria-label="Stop"
633
+ >
634
+ {#if stop_btn === true}
635
+ <Square fill={"none"} stroke_width={2.5} />
636
+ {:else}
637
+ {stop_btn}
638
+ {/if}
639
+ </button>
640
+ {/if}
641
+ </div>
642
+ </div>
643
+ </div>
644
+ </div>
645
+
646
+ <style>
647
+ .full-container {
648
+ width: 100%;
649
+ position: relative;
650
+ padding: var(--block-padding);
651
+ border: 1px solid transparent;
652
+ }
653
+
654
+ .full-container.dragging {
655
+ border-color: var(--color-accent);
656
+ border-radius: calc(var(--radius-sm) - var(--size-px));
657
+ }
658
+
659
+ .full-container.dragging::after {
660
+ content: "";
661
+ position: absolute;
662
+ inset: 0;
663
+ pointer-events: none;
664
+ }
665
+
666
+ .input-container {
667
+ display: flex;
668
+ position: relative;
669
+ flex-direction: column;
670
+ gap: 0;
671
+ }
672
+
673
+ .input-wrapper {
674
+ display: flex;
675
+ position: relative;
676
+ flex-direction: column;
677
+ gap: 0;
678
+ background: var(--block-background-fill);
679
+ border-radius: var(--radius-xl);
680
+ padding: var(--spacing-sm) var(--spacing-sm) var(--spacing-sm) 0;
681
+ align-items: flex-start;
682
+ min-height: auto;
683
+ }
684
+
685
+ .input-wrapper.has-files {
686
+ padding-top: var(--spacing-xs);
687
+ }
688
+
689
+ .input-row {
690
+ display: flex;
691
+ align-items: flex-start;
692
+ gap: var(--spacing-sm);
693
+ width: 100%;
694
+ }
695
+
696
+ .thumbnails {
697
+ display: flex;
698
+ align-items: center;
699
+ gap: var(--spacing-sm);
700
+ padding: var(--spacing-xs) 0;
701
+ margin-bottom: var(--spacing-xs);
702
+ overflow-x: auto;
703
+ overflow-y: hidden;
704
+ scrollbar-width: none;
705
+ -ms-overflow-style: none;
706
+ flex-wrap: nowrap;
707
+ -webkit-overflow-scrolling: touch;
708
+ scroll-behavior: smooth;
709
+ overflow-y: scroll;
710
+ width: 100%;
711
+ }
712
+
713
+ .thumbnails::-webkit-scrollbar,
714
+ .thumbnails::-webkit-scrollbar-track,
715
+ .thumbnails::-webkit-scrollbar-thumb {
716
+ display: none;
717
+ }
718
+
719
+ .thumbnails :global(img) {
720
+ width: var(--size-full);
721
+ height: var(--size-full);
722
+ object-fit: cover;
723
+ border-radius: var(--radius-md);
724
+ }
725
+
726
+ .thumbnail-wrapper {
727
+ position: relative;
728
+ flex-shrink: 0;
729
+ }
730
+
731
+ .thumbnail-item {
732
+ position: relative;
733
+ display: flex;
734
+ justify-content: center;
735
+ align-items: center;
736
+ border-radius: var(--radius-md);
737
+ background: var(--background-fill-secondary);
738
+ width: var(--size-full);
739
+ height: var(--size-full);
740
+ cursor: default;
741
+ padding: 0;
742
+ }
743
+
744
+ .thumbnail-small {
745
+ width: var(--size-10);
746
+ height: var(--size-10);
747
+ }
748
+
749
+ .thumbnail-item :global(svg) {
750
+ width: var(--size-5);
751
+ height: var(--size-5);
752
+ }
753
+
754
+ .delete-button {
755
+ position: absolute;
756
+ inset: 0;
757
+ display: flex;
758
+ justify-content: center;
759
+ align-items: center;
760
+ color: var(--button-primary-text-color);
761
+ background: rgba(0, 0, 0, 0.6);
762
+ backdrop-filter: var(--blur-xs);
763
+ border-radius: var(--radius-md);
764
+ padding: 0;
765
+ z-index: var(--layer-1);
766
+ opacity: 0;
767
+ transition: opacity 0.1s var(--easing-standard);
768
+ }
769
+
770
+ .delete-button:hover {
771
+ background: rgba(0, 0, 0, 0.8);
772
+ }
773
+
774
+ .delete-button :global(svg) {
775
+ width: var(--size-5);
776
+ height: var(--size-5);
777
+ }
778
+
779
+ .thumbnail-item:hover .delete-button {
780
+ opacity: 1;
781
+ }
782
+
783
+ textarea {
784
+ flex-grow: 1;
785
+ outline: none !important;
786
+ background: transparent;
787
+ padding: var(--spacing-sm) 0;
788
+ color: var(--body-text-color);
789
+ font-weight: var(--input-text-weight);
790
+ font-size: var(--input-text-size);
791
+ border: none;
792
+ margin: 0;
793
+ resize: none;
794
+ position: relative;
795
+ z-index: var(--layer-1);
796
+ text-align: left;
797
+ }
798
+
799
+ textarea:disabled {
800
+ -webkit-opacity: 1;
801
+ opacity: 1;
802
+ }
803
+
804
+ textarea::placeholder {
805
+ color: var(--input-placeholder-color);
806
+ }
807
+
808
+ textarea[dir="rtl"] {
809
+ text-align: right;
810
+ }
811
+
812
+ textarea[dir="rtl"] ~ .submit-button :global(svg) {
813
+ transform: scaleX(-1);
814
+ }
815
+
816
+ .microphone-button,
817
+ .icon-button {
818
+ color: var(--body-text-color);
819
+ cursor: pointer;
820
+ padding: var(--spacing-sm);
821
+ display: flex;
822
+ justify-content: center;
823
+ align-items: center;
824
+ flex-shrink: 0;
825
+ border-radius: var(--radius-md);
826
+ }
827
+
828
+ .thumbnail-add {
829
+ background: var(--button-secondary-background-fill);
830
+ cursor: pointer;
831
+ display: flex;
832
+ justify-content: center;
833
+ align-items: center;
834
+ flex-shrink: 0;
835
+ width: var(--size-10);
836
+ height: var(--size-10);
837
+ border-radius: var(--radius-md);
838
+ z-index: var(--layer-1);
839
+ }
840
+
841
+ .thumbnail-add:hover:not(:disabled) {
842
+ background: var(--button-secondary-background-fill-hover);
843
+ }
844
+
845
+ .thumbnail-add:disabled {
846
+ opacity: 0.5;
847
+ cursor: not-allowed;
848
+ }
849
+
850
+ .thumbnail-add :global(svg) {
851
+ width: var(--size-5);
852
+ height: var(--size-5);
853
+ }
854
+
855
+ .microphone-button,
856
+ .icon-button {
857
+ width: var(--size-9);
858
+ height: var(--size-9);
859
+ }
860
+
861
+ .microphone-button:hover:not(:disabled),
862
+ .icon-button:hover:not(:disabled) {
863
+ background: var(--button-secondary-background-fill);
864
+ }
865
+
866
+ .microphone-button:disabled,
867
+ .icon-button:disabled {
868
+ opacity: 0.5;
869
+ cursor: not-allowed;
870
+ }
871
+
872
+ .microphone-button :global(svg),
873
+ .icon-button :global(svg) {
874
+ width: var(--size-5);
875
+ height: var(--size-5);
876
+ }
877
+
878
+ .submit-button,
879
+ .stop-button {
880
+ background: var(--button-secondary-background-fill);
881
+ cursor: pointer;
882
+ display: flex;
883
+ justify-content: center;
884
+ align-items: center;
885
+ flex-shrink: 0;
886
+ width: var(--size-9);
887
+ height: var(--size-9);
888
+ border-radius: var(--radius-md);
889
+ z-index: var(--layer-1);
890
+ }
891
+
892
+ .submit-button:hover:not(:disabled),
893
+ .stop-button:hover:not(:disabled) {
894
+ background: var(--button-secondary-background-fill-hover);
895
+ }
896
+
897
+ .submit-button:active:not(:disabled),
898
+ .stop-button:active:not(:disabled) {
899
+ box-shadow: var(--button-shadow-active);
900
+ }
901
+
902
+ .submit-button:disabled,
903
+ .stop-button:disabled {
904
+ cursor: not-allowed;
905
+ }
906
+
907
+ .submit-button :global(svg),
908
+ .stop-button :global(svg) {
909
+ width: var(--size-5);
910
+ height: var(--size-5);
911
+ }
912
+
913
+ .padded-button {
914
+ padding: 0 var(--spacing-lg);
915
+ width: auto;
916
+ border-radius: var(--radius-xl);
917
+ }
918
+
919
+ .loader {
920
+ display: flex;
921
+ justify-content: center;
922
+ align-items: center;
923
+ position: relative;
924
+ border: var(--size-1) solid var(--border-color-primary);
925
+ border-top-color: var(--color-accent);
926
+ border-radius: var(--radius-100);
927
+ width: var(--size-5);
928
+ height: var(--size-5);
929
+ animation: spin 1s linear infinite;
930
+ flex-shrink: 0;
931
+ }
932
+
933
+ @keyframes spin {
934
+ to {
935
+ transform: rotate(360deg);
936
+ }
937
+ }
938
+
939
+ .recording-overlay {
940
+ position: absolute;
941
+ top: 0;
942
+ left: 0;
943
+ right: 0;
944
+ bottom: 0;
945
+ background: var(--block-background-fill);
946
+ border-radius: var(--radius-xl);
947
+ display: flex;
948
+ align-items: center;
949
+ justify-content: center;
950
+ z-index: var(--layer-5);
951
+ padding: var(--spacing-lg);
952
+ backdrop-filter: blur(8px);
953
+ animation: fadeIn 0.2s var(--easing-standard);
954
+ }
955
+
956
+ @keyframes fadeIn {
957
+ from {
958
+ opacity: 0;
959
+ }
960
+ to {
961
+ opacity: 1;
962
+ }
963
+ }
964
+
965
+ .recording-content {
966
+ display: flex;
967
+ align-items: center;
968
+ gap: var(--spacing-lg);
969
+ width: 100%;
970
+ max-width: 700px;
971
+ }
972
+
973
+ .recording-content :global(.minimal-audio-recorder),
974
+ .recording-content :global(.minimal-audio-player) {
975
+ flex: 1;
976
+ }
977
+
978
+ .action-buttons {
979
+ display: flex;
980
+ align-items: center;
981
+ gap: var(--spacing-sm);
982
+ flex-shrink: 0;
983
+ }
984
+
985
+ .stop-button,
986
+ .confirm-button,
987
+ .cancel-button {
988
+ display: flex;
989
+ align-items: center;
990
+ justify-content: center;
991
+ width: var(--size-9);
992
+ height: var(--size-9);
993
+ padding: 0;
994
+ border-radius: var(--radius-md);
995
+ cursor: pointer;
996
+ flex-shrink: 0;
997
+ }
998
+
999
+ .stop-button {
1000
+ background: var(--button-secondary-background-fill);
1001
+ border-color: var(--border-color-primary);
1002
+ color: var(--error-500);
1003
+ }
1004
+
1005
+ .stop-button:hover {
1006
+ background: var(--button-secondary-background-fill-hover);
1007
+ color: var(--error-600);
1008
+ }
1009
+
1010
+ .stop-button:active {
1011
+ transform: scale(0.95);
1012
+ }
1013
+
1014
+ .confirm-button {
1015
+ background: var(--button-primary-background-fill);
1016
+ border-color: var(--button-primary-border-color);
1017
+ color: white;
1018
+ }
1019
+
1020
+ .confirm-button:hover {
1021
+ background: var(--button-primary-background-fill-hover);
1022
+ color: var(--button-primary-text-color-hover);
1023
+ }
1024
+
1025
+ .confirm-button:active {
1026
+ transform: scale(0.95);
1027
+ }
1028
+
1029
+ .cancel-button {
1030
+ background: var(--button-secondary-background-fill);
1031
+ color: var(--body-text-color);
1032
+ }
1033
+
1034
+ .cancel-button:hover {
1035
+ background: var(--button-secondary-background-fill-hover);
1036
+ }
1037
+
1038
+ .stop-button :global(svg),
1039
+ .confirm-button :global(svg),
1040
+ .cancel-button :global(svg) {
1041
+ width: var(--size-5);
1042
+ height: var(--size-5);
1043
+ }
1044
+
1045
+ @media (max-width: 768px) {
1046
+ .input-wrapper {
1047
+ padding: var(--spacing-xs);
1048
+ }
1049
+
1050
+ .thumbnails {
1051
+ padding: var(--spacing-xs) 0;
1052
+ margin-bottom: var(--spacing-md);
1053
+ }
1054
+
1055
+ .thumbnail-small,
1056
+ .thumbnail-add {
1057
+ width: var(--size-9);
1058
+ height: var(--size-9);
1059
+ }
1060
+
1061
+ .thumbnail-item:active .delete-button {
1062
+ opacity: 1;
1063
+ }
1064
+ }
1065
+
1066
+ .textarea-wrapper {
1067
+ position: relative;
1068
+ flex-grow: 1;
1069
+ }
1070
+
1071
+ .textarea-wrapper textarea {
1072
+ width: 100%;
1073
+ }
1074
+ </style>
6.22.1/multimodaltextbox/shared/types.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export type { InputHTMLAttributes } from "../../textbox/types";
6.22.1/multimodaltextbox/shared/utils.ts ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { tick } from "svelte";
2
+
3
+ interface Value {
4
+ lines: number;
5
+ max_lines: number;
6
+ text: string;
7
+ }
8
+
9
+ export async function resize(
10
+ target: HTMLTextAreaElement | HTMLInputElement,
11
+ lines: number,
12
+ max_lines: number
13
+ ): Promise<void> {
14
+ await tick();
15
+ if (lines === max_lines) return;
16
+
17
+ const computed_styles = window.getComputedStyle(target);
18
+ const padding_top = parseFloat(computed_styles.paddingTop);
19
+ const padding_bottom = parseFloat(computed_styles.paddingBottom);
20
+ const line_height = parseFloat(computed_styles.lineHeight);
21
+
22
+ let max =
23
+ max_lines === undefined
24
+ ? false
25
+ : padding_top + padding_bottom + line_height * max_lines;
26
+ let min = padding_top + padding_bottom + lines * line_height;
27
+
28
+ target.style.height = "1px";
29
+
30
+ let scroll_height;
31
+ if (max && target.scrollHeight > max) {
32
+ scroll_height = max;
33
+ } else if (target.scrollHeight < min) {
34
+ scroll_height = min;
35
+ } else {
36
+ scroll_height = target.scrollHeight;
37
+ }
38
+
39
+ target.style.height = `${scroll_height}px`;
40
+ update_scrollbar_visibility(target);
41
+ }
42
+
43
+ function update_scrollbar_visibility(
44
+ textarea: HTMLTextAreaElement | HTMLInputElement
45
+ ): void {
46
+ const content_height = textarea.scrollHeight;
47
+ const visible_height = textarea.clientHeight;
48
+ const computed_style = window.getComputedStyle(textarea);
49
+ const line_height = parseFloat(computed_style.lineHeight);
50
+ const threshold = Number.isFinite(line_height)
51
+ ? line_height
52
+ : parseFloat(computed_style.fontSize) * 1.2;
53
+ if (content_height > visible_height + threshold) {
54
+ textarea.style.overflowY = "scroll";
55
+ } else {
56
+ textarea.style.overflowY = "hidden";
57
+ }
58
+ }
59
+
60
+ export function text_area_resize(
61
+ _el: HTMLTextAreaElement,
62
+ _value: Value
63
+ ): any | undefined {
64
+ if (_value.lines === _value.max_lines) return;
65
+ update_scrollbar_visibility(_el);
66
+
67
+ function handle_input(event: Event): void {
68
+ resize(event.target as HTMLTextAreaElement, _value.lines, _value.max_lines);
69
+ }
70
+ _el.addEventListener("input", handle_input);
71
+
72
+ if (!_value.text.trim()) return;
73
+ resize(_el, _value.lines, _value.max_lines);
74
+
75
+ return {
76
+ destroy: () => _el.removeEventListener("input", handle_input)
77
+ };
78
+ }
6.22.1/multimodaltextbox/types.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { FileData } from "@gradio/client";
2
+ import type { SelectData } from "@gradio/utils";
3
+ import type { ILoadingStatus as LoadingStatus } from "@gradio/statustracker";
4
+ import type { InputHTMLAttributes } from "./shared/types";
5
+ import type { WaveformOptions } from "js/audio/shared/types";
6
+
7
+ export interface MultimodalTextboxEvents {
8
+ change: { text: string; files: FileData[] };
9
+ submit: never;
10
+ stop: never;
11
+ blur: never;
12
+ select: SelectData;
13
+ input: never;
14
+ focus: never;
15
+ error: string;
16
+ clear_status: LoadingStatus;
17
+ stop_recording: never;
18
+ upload: FileData[] | FileData;
19
+ clear: undefined;
20
+ }
21
+
22
+ export interface MultimodalTextboxProps {
23
+ value: { text: string; files: FileData[] };
24
+ file_types: string[] | null;
25
+ lines: number;
26
+ placeholder: string;
27
+ info: string | undefined;
28
+ max_lines: number;
29
+ submit_btn: string | boolean | null;
30
+ stop_btn: string | boolean | null;
31
+ value_is_output: boolean;
32
+ rtl: boolean;
33
+ text_align: "left" | "right" | undefined;
34
+ autofocus: boolean;
35
+ file_count: "single" | "multiple" | "directory";
36
+ max_plain_text_length: number;
37
+ sources: ("microphone" | "upload")[];
38
+ waveform_options: WaveformOptions;
39
+ html_attributes: InputHTMLAttributes | null;
40
+ }