gradio-pr-bot commited on
Commit
c1ac83e
·
verified ·
1 Parent(s): f2a4328

Upload folder using huggingface_hub

Browse files
6.25.0/atoms/package.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/atoms",
3
+ "version": "0.26.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.25.0/atoms/src/Block.svelte ADDED
@@ -0,0 +1,383 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+
4
+ let {
5
+ height = undefined,
6
+ min_height = undefined,
7
+ max_height = undefined,
8
+ width = undefined,
9
+ elem_id = "",
10
+ elem_classes = [],
11
+ variant = "solid",
12
+ border_mode = "base",
13
+ padding = true,
14
+ type = "normal",
15
+ test_id = undefined,
16
+ explicit_call = false,
17
+ container = true,
18
+ visible = true,
19
+ allow_overflow = true,
20
+ overflow_behavior = "auto",
21
+ scale = null,
22
+ min_width = 0,
23
+ flex = false,
24
+ resizable = false,
25
+ rtl = false,
26
+ fullscreen = $bindable(false),
27
+ label = undefined,
28
+ children
29
+ }: {
30
+ height?: number | string | undefined;
31
+ min_height?: number | string | undefined;
32
+ max_height?: number | string | undefined;
33
+ width?: number | string | undefined;
34
+ elem_id?: string;
35
+ elem_classes?: string[];
36
+ variant?: "solid" | "dashed" | "none";
37
+ border_mode?: "base" | "focus" | "contrast";
38
+ padding?: boolean;
39
+ type?: "normal" | "fieldset";
40
+ test_id?: string | undefined;
41
+ explicit_call?: boolean;
42
+ container?: boolean;
43
+ visible?: boolean | "hidden";
44
+ allow_overflow?: boolean;
45
+ overflow_behavior?: "visible" | "auto";
46
+ scale?: number | null;
47
+ min_width?: number;
48
+ flex?: boolean;
49
+ resizable?: boolean;
50
+ rtl?: boolean;
51
+ fullscreen?: boolean;
52
+ label?: string | undefined;
53
+ children?: Snippet;
54
+ } = $props();
55
+
56
+ let old_fullscreen = fullscreen;
57
+
58
+ let element: HTMLElement | undefined = $state();
59
+
60
+ let tag = $derived(type === "fieldset" ? "fieldset" : "div");
61
+
62
+ // When visible is false the block is not rendered at all, so flex is
63
+ // irrelevant; keep the historical behaviour of forcing it off.
64
+ let is_flex = $derived(visible ? flex : false);
65
+
66
+ let placeholder_height = $state(0);
67
+ let placeholder_width = $state(0);
68
+ let preexpansionBoundingRect: DOMRect | null = $state(null);
69
+ let portal_parent: (Node & ParentNode) | null = null;
70
+ let portal_marker: Comment | null = null;
71
+ // Kept outside `$state` so teardown can still reach the element after
72
+ // Svelte has cleared the `bind:this` binding.
73
+ let portal_element: HTMLElement | null = null;
74
+
75
+ function handleKeydown(event: KeyboardEvent): void {
76
+ if (fullscreen && event.key === "Escape") {
77
+ fullscreen = false;
78
+ }
79
+ }
80
+
81
+ // The app container carries the theme variables, so keep the block inside it.
82
+ function portal_target(el: HTMLElement): Node & ParentNode {
83
+ const root = el.getRootNode();
84
+ return (
85
+ el.closest(".gradio-container") ??
86
+ (root instanceof ShadowRoot ? root : document.body)
87
+ );
88
+ }
89
+
90
+ // Measures where a `position: fixed` element pinned to the top left at a
91
+ // 100% size lands when it is a child of `parent`.
92
+ function fixed_probe_rect(parent: Node & ParentNode): DOMRect {
93
+ const probe = document.createElement("div");
94
+ probe.style.cssText =
95
+ "position: fixed; top: 0; left: 0; width: 100%; height: 100%; visibility: hidden; pointer-events: none;";
96
+ parent.appendChild(probe);
97
+ const rect = probe.getBoundingClientRect();
98
+ probe.remove();
99
+ return rect;
100
+ }
101
+
102
+ // A `position: fixed` element is only laid out against the viewport when no
103
+ // ancestor establishes a containing block for fixed descendants. Anything
104
+ // with a transform, filter, backdrop-filter, perspective, contain or
105
+ // container-type does establish one — `gr.Sidebar` always sets a transform,
106
+ // for instance — and then top/left/width/height resolve against that
107
+ // ancestor instead. Rather than enumerate those properties, compare a probe
108
+ // where the block currently is with one in the container it would move to.
109
+ function needs_portal(el: HTMLElement, target: Node & ParentNode): boolean {
110
+ const parent = el.parentNode;
111
+ if (!parent || parent === target) return false;
112
+ const here = fixed_probe_rect(parent);
113
+ const there = fixed_probe_rect(target);
114
+ return (
115
+ Math.abs(here.top - there.top) > 1 ||
116
+ Math.abs(here.left - there.left) > 1 ||
117
+ Math.abs(here.width - there.width) > 1 ||
118
+ Math.abs(here.height - there.height) > 1
119
+ );
120
+ }
121
+
122
+ // Moves the block to the app container so that its fixed positioning
123
+ // resolves against the viewport. The placeholder that reserves the block's
124
+ // space stays behind in the original parent, and `exit_portal` puts the
125
+ // block back where it came from.
126
+ function enter_portal(el: HTMLElement, target: Node & ParentNode): void {
127
+ if (!el.parentNode || el.parentNode === target) return;
128
+ portal_parent = el.parentNode;
129
+ portal_element = el;
130
+ portal_marker = document.createComment("fullscreen block");
131
+ portal_parent.insertBefore(portal_marker, el);
132
+ target.appendChild(el);
133
+ }
134
+
135
+ function exit_portal(): void {
136
+ if (!portal_parent || !portal_element) return;
137
+ const marker =
138
+ portal_marker && portal_marker.parentNode === portal_parent
139
+ ? portal_marker
140
+ : null;
141
+ portal_parent.insertBefore(portal_element, marker);
142
+ marker?.remove();
143
+ portal_parent = null;
144
+ portal_marker = null;
145
+ portal_element = null;
146
+ }
147
+
148
+ $effect(() => {
149
+ const el = element;
150
+ if (fullscreen === old_fullscreen || !el) return;
151
+ old_fullscreen = fullscreen;
152
+ if (fullscreen) {
153
+ preexpansionBoundingRect = el.getBoundingClientRect();
154
+ placeholder_height = el.offsetHeight;
155
+ placeholder_width = el.offsetWidth;
156
+ const target = portal_target(el);
157
+ if (needs_portal(el, target)) {
158
+ enter_portal(el, target);
159
+ }
160
+ window.addEventListener("keydown", handleKeydown);
161
+ } else {
162
+ exit_portal();
163
+ preexpansionBoundingRect = null;
164
+ window.removeEventListener("keydown", handleKeydown);
165
+ }
166
+ });
167
+
168
+ // Nothing reactive is read here, so this effect runs once and its cleanup
169
+ // only fires on destroy — tearing down a block while it is fullscreen would
170
+ // otherwise leak the keydown listener. It cannot be folded into the effect
171
+ // above, which re-runs on every `fullscreen` change and would therefore
172
+ // remove the listener immediately after adding it.
173
+ $effect(() => {
174
+ return () => {
175
+ window.removeEventListener("keydown", handleKeydown);
176
+ exit_portal();
177
+ };
178
+ });
179
+
180
+ const get_dimension = (
181
+ dimension_value: string | number | undefined
182
+ ): string | undefined => {
183
+ if (dimension_value === undefined) {
184
+ return undefined;
185
+ }
186
+ if (typeof dimension_value === "number") {
187
+ return dimension_value + "px";
188
+ } else if (typeof dimension_value === "string") {
189
+ return dimension_value;
190
+ }
191
+ };
192
+
193
+ const resize = (e: MouseEvent): void => {
194
+ const el = element;
195
+ if (!el) return;
196
+ let prevY = e.clientY;
197
+ const onMouseMove = (e: MouseEvent): void => {
198
+ const dy: number = e.clientY - prevY;
199
+ prevY = e.clientY;
200
+ el.style.height = `${el.offsetHeight + dy}px`;
201
+ };
202
+ const onMouseUp = (): void => {
203
+ window.removeEventListener("mousemove", onMouseMove);
204
+ window.removeEventListener("mouseup", onMouseUp);
205
+ };
206
+ window.addEventListener("mousemove", onMouseMove);
207
+ window.addEventListener("mouseup", onMouseUp);
208
+ };
209
+ // When visible is False, we need to remove the component from the page
210
+ // We can remove it by either modifying the AppTree in Blocks or by hiding the component here
211
+ // We do it here because if visible is updated via an event, only the local state will be updated
212
+ // and we would have to flow the state back up to modify the AppTree
213
+ </script>
214
+
215
+ {#if visible === true || visible === "hidden"}
216
+ <svelte:element
217
+ this={tag}
218
+ bind:this={element}
219
+ data-testid={test_id}
220
+ id={elem_id}
221
+ class:hidden={visible === "hidden"}
222
+ class="block {elem_classes?.join(' ') || ''}"
223
+ class:padded={padding}
224
+ class:flex={is_flex}
225
+ class:border_focus={border_mode === "focus"}
226
+ class:border_contrast={border_mode === "contrast"}
227
+ class:hide-container={!explicit_call && !container}
228
+ style:height={fullscreen ? undefined : get_dimension(height)}
229
+ style:min-height={fullscreen ? undefined : get_dimension(min_height)}
230
+ style:max-height={fullscreen ? undefined : get_dimension(max_height)}
231
+ class:fullscreen
232
+ class:animating={fullscreen && preexpansionBoundingRect !== null}
233
+ style:--start-top={preexpansionBoundingRect
234
+ ? `${preexpansionBoundingRect.top}px`
235
+ : "0px"}
236
+ style:--start-left={preexpansionBoundingRect
237
+ ? `${preexpansionBoundingRect.left}px`
238
+ : "0px"}
239
+ style:--start-width={preexpansionBoundingRect
240
+ ? `${preexpansionBoundingRect.width}px`
241
+ : "0px"}
242
+ style:--start-height={preexpansionBoundingRect
243
+ ? `${preexpansionBoundingRect.height}px`
244
+ : "0px"}
245
+ style:width={fullscreen
246
+ ? undefined
247
+ : typeof width === "number"
248
+ ? `calc(min(${width}px, 100%))`
249
+ : get_dimension(width)}
250
+ style:border-style={variant}
251
+ style:overflow={allow_overflow ? overflow_behavior : "hidden"}
252
+ style:flex-grow={scale}
253
+ style:min-width={`calc(min(${min_width}px, 100%))`}
254
+ class:auto-margin={scale === null}
255
+ dir={rtl ? "rtl" : "ltr"}
256
+ aria-label={label}
257
+ >
258
+ {@render children?.()}
259
+ {#if resizable}
260
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
261
+ <svg
262
+ class="resize-handle"
263
+ xmlns="http://www.w3.org/2000/svg"
264
+ viewBox="0 0 10 10"
265
+ onmousedown={resize}
266
+ >
267
+ <line x1="1" y1="9" x2="9" y2="1" stroke="gray" stroke-width="0.5" />
268
+ <line x1="5" y1="9" x2="9" y2="5" stroke="gray" stroke-width="0.5" />
269
+ </svg>
270
+ {/if}
271
+ </svelte:element>
272
+ {#if fullscreen}
273
+ <div
274
+ class="placeholder"
275
+ style:height={placeholder_height + "px"}
276
+ style:width={placeholder_width + "px"}
277
+ ></div>
278
+ {/if}
279
+ {/if}
280
+
281
+ <style>
282
+ .block {
283
+ position: relative;
284
+ margin: 0;
285
+ box-shadow: var(--block-shadow);
286
+ border-width: var(--block-border-width);
287
+ border-color: var(--block-border-color);
288
+ border-radius: var(--block-radius);
289
+ background: var(--block-background-fill);
290
+ width: 100%;
291
+ line-height: var(--line-sm);
292
+ border-width: var(--block-border-width);
293
+ }
294
+ .block.fullscreen {
295
+ border-radius: 0;
296
+ }
297
+
298
+ .auto-margin {
299
+ margin-left: auto;
300
+ margin-right: auto;
301
+ }
302
+
303
+ .block.border_focus {
304
+ border-color: var(--color-accent);
305
+ }
306
+
307
+ .block.border_contrast {
308
+ border-color: var(--body-text-color);
309
+ }
310
+
311
+ .padded {
312
+ padding: var(--block-padding);
313
+ }
314
+
315
+ .flex {
316
+ display: flex;
317
+ flex-direction: column;
318
+ }
319
+
320
+ .hidden {
321
+ /* We use "hidden" class name in form/Index.svelte to hide parent forms, so if this class changes, edit form/Index.svelte accordingly */
322
+ display: none;
323
+ }
324
+ .hide-container:not(.fullscreen) {
325
+ margin: 0;
326
+ box-shadow: none;
327
+ border-width: 0;
328
+ background: transparent;
329
+ padding: 0;
330
+ overflow: visible;
331
+ }
332
+ .resize-handle {
333
+ position: absolute;
334
+ bottom: 0;
335
+ right: 0;
336
+ width: 10px;
337
+ height: 10px;
338
+ fill: var(--block-border-color);
339
+ cursor: nwse-resize;
340
+ }
341
+ .fullscreen {
342
+ position: fixed;
343
+ top: 0;
344
+ left: 0;
345
+ /* Percentages resolve against the viewport minus any classic window
346
+ scrollbar; 100vw/100vh would extend beneath it and hide the top-right
347
+ controls (#11982) */
348
+ width: 100%;
349
+ height: 100%;
350
+ z-index: 1000;
351
+ overflow: auto;
352
+ }
353
+
354
+ .animating {
355
+ animation: pop-out 0.1s ease-out forwards;
356
+ }
357
+
358
+ @keyframes pop-out {
359
+ 0% {
360
+ position: fixed;
361
+ top: var(--start-top);
362
+ left: var(--start-left);
363
+ width: var(--start-width);
364
+ height: var(--start-height);
365
+ z-index: 100;
366
+ }
367
+ 100% {
368
+ position: fixed;
369
+ top: 0;
370
+ left: 0;
371
+ width: 100%;
372
+ height: 100%;
373
+ z-index: 1000;
374
+ }
375
+ }
376
+
377
+ .placeholder {
378
+ border-radius: var(--block-radius);
379
+ border-width: var(--block-border-width);
380
+ border-color: var(--block-border-color);
381
+ border-style: dashed;
382
+ }
383
+ </style>
6.25.0/atoms/src/BlockLabel.svelte ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let {
3
+ label = null,
4
+ Icon,
5
+ show_label = true,
6
+ disable = false,
7
+ float = true,
8
+ rtl = false
9
+ }: {
10
+ label?: string | null;
11
+ Icon: any;
12
+ show_label?: boolean;
13
+ disable?: boolean;
14
+ float?: boolean;
15
+ rtl?: boolean;
16
+ } = $props();
17
+ </script>
18
+
19
+ <!-- svelte-ignore a11y_label_has_associated_control -->
20
+ <label
21
+ class:hide={!show_label}
22
+ class:sr-only={!show_label}
23
+ class:float
24
+ class:hide-label={disable}
25
+ data-testid="block-label"
26
+ dir={rtl ? "rtl" : "ltr"}
27
+ >
28
+ <span>
29
+ <Icon />
30
+ </span>
31
+ {label}
32
+ </label>
33
+
34
+ <style>
35
+ label {
36
+ display: inline-flex;
37
+ align-items: center;
38
+ z-index: var(--layer-2);
39
+ box-shadow: var(--block-label-shadow);
40
+ border: var(--block-label-border-width) solid
41
+ var(--block-label-border-color);
42
+ border-top: none;
43
+ border-left: none;
44
+ border-radius: var(--block-label-radius);
45
+ background: var(--block-label-background-fill);
46
+ padding: var(--block-label-padding);
47
+ pointer-events: none;
48
+ color: var(--block-label-text-color);
49
+ font-weight: var(--block-label-text-weight);
50
+ font-size: var(--block-label-text-size);
51
+ line-height: var(--line-sm);
52
+ }
53
+ :global(.gr-group) label {
54
+ border-top-left-radius: 0;
55
+ }
56
+
57
+ label.float {
58
+ position: absolute;
59
+ top: var(--block-label-margin);
60
+ left: var(--block-label-margin);
61
+ }
62
+ label:not(.float) {
63
+ position: static;
64
+ margin-top: var(--block-label-margin);
65
+ margin-left: var(--block-label-margin);
66
+ }
67
+
68
+ .hide {
69
+ display: none;
70
+ }
71
+
72
+ span {
73
+ opacity: 0.8;
74
+ margin-right: var(--size-2);
75
+ width: calc(var(--block-label-text-size) - 1px);
76
+ height: calc(var(--block-label-text-size) - 1px);
77
+ }
78
+ .hide-label {
79
+ box-shadow: none;
80
+ border-width: 0;
81
+ background: transparent;
82
+ overflow: visible;
83
+ }
84
+
85
+ label[dir="rtl"] {
86
+ border: var(--block-label-border-width) solid
87
+ var(--block-label-border-color);
88
+ border-top: none;
89
+ border-right: none;
90
+ border-bottom-left-radius: var(--block-radius);
91
+ border-bottom-right-radius: var(--block-label-radius);
92
+ border-top-left-radius: var(--block-label-radius);
93
+ }
94
+
95
+ label[dir="rtl"] span {
96
+ margin-left: var(--size-2);
97
+ margin-right: 0;
98
+ }
99
+ </style>
6.25.0/atoms/src/BlockTitle.svelte ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import Info from "./Info.svelte";
4
+
5
+ let {
6
+ show_label = true,
7
+ info = undefined,
8
+ rtl = false,
9
+ children
10
+ }: {
11
+ show_label?: boolean;
12
+ info?: string | undefined;
13
+ rtl?: boolean;
14
+ children?: Snippet;
15
+ } = $props();
16
+ </script>
17
+
18
+ <span
19
+ class:hide={!show_label}
20
+ class:has-info={info != null}
21
+ class:sr-only={!show_label}
22
+ data-testid="block-info"
23
+ dir={rtl ? "rtl" : "ltr"}
24
+ >
25
+ {@render children?.()}
26
+ </span>
27
+ {#if info}
28
+ <Info {info} />
29
+ {/if}
30
+
31
+ <style>
32
+ span.has-info {
33
+ margin-bottom: var(--spacing-xs);
34
+ }
35
+ span:not(.has-info) {
36
+ margin-bottom: var(--spacing-lg);
37
+ }
38
+ span {
39
+ display: inline-block;
40
+ position: relative;
41
+ z-index: var(--layer-4);
42
+ border: solid var(--block-title-border-width)
43
+ var(--block-title-border-color);
44
+ border-radius: var(--block-title-radius);
45
+ background: var(--block-title-background-fill);
46
+ padding: var(--block-title-padding);
47
+ color: var(--block-title-text-color);
48
+ font-weight: var(--block-title-text-weight);
49
+ font-size: var(--block-title-text-size);
50
+ line-height: var(--line-sm);
51
+ }
52
+
53
+ span[dir="rtl"] {
54
+ display: block;
55
+ }
56
+
57
+ .hide {
58
+ margin: 0;
59
+ height: 0;
60
+ }
61
+
62
+ .sr-only {
63
+ clip: rect(0, 0, 0, 0);
64
+ position: absolute;
65
+ margin: -1px;
66
+ border-width: 0;
67
+ padding: 0;
68
+ width: 1px;
69
+ height: 1px;
70
+ overflow: hidden;
71
+ white-space: nowrap;
72
+ }
73
+ </style>
6.25.0/atoms/src/CustomButton.svelte ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { CustomButton } from "@gradio/utils";
3
+
4
+ let {
5
+ button,
6
+ on_click
7
+ }: {
8
+ button: CustomButton;
9
+ on_click: (id: number) => void;
10
+ } = $props();
11
+ </script>
12
+
13
+ <button
14
+ class="custom-button"
15
+ onclick={() => on_click(button.id)}
16
+ title={button.value || ""}
17
+ aria-label={button.value || "Custom action"}
18
+ >
19
+ {#if button.value}
20
+ <span class="custom-button-label">{button.value}</span>
21
+ {/if}
22
+ </button>
23
+
24
+ <style>
25
+ .custom-button {
26
+ display: flex;
27
+ align-items: center;
28
+ justify-content: center;
29
+ gap: var(--size-1);
30
+ height: var(--size-6);
31
+ padding: var(--size-1) var(--size-2);
32
+ border: none;
33
+ border-radius: var(--radius-sm);
34
+ background: transparent;
35
+ color: var(--block-title-text-color);
36
+ cursor: pointer;
37
+ transition: all 0.2s;
38
+ font-size: var(--text-sm);
39
+ margin-left: var(--size-1);
40
+ }
41
+
42
+ .custom-button:hover {
43
+ background: var(--background-fill-secondary);
44
+ color: var(--body-text-color);
45
+ }
46
+
47
+ .custom-button-label {
48
+ white-space: nowrap;
49
+ }
50
+ </style>
6.25.0/atoms/src/DownloadLink.svelte ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { HTMLAnchorAttributes } from "svelte/elements";
3
+ import type { Snippet } from "svelte";
4
+
5
+ interface DownloadLinkAttributes extends Omit<
6
+ HTMLAnchorAttributes,
7
+ "target" | "children"
8
+ > {
9
+ // `null` omits the attribute entirely, which is how callers opt out of a
10
+ // native download (e.g. Colab, where the anchor has to open in a new tab).
11
+ download?: HTMLAnchorAttributes["download"] | null;
12
+ children?: Snippet;
13
+ }
14
+
15
+ let {
16
+ href = undefined,
17
+ download = undefined,
18
+ children,
19
+ ...rest
20
+ }: DownloadLinkAttributes = $props();
21
+ </script>
22
+
23
+ <a
24
+ style:position="relative"
25
+ class="download-link"
26
+ data-testid="download-link"
27
+ {href}
28
+ target={typeof window !== "undefined" && window.__is_colab__
29
+ ? "_blank"
30
+ : null}
31
+ rel="noopener noreferrer"
32
+ {download}
33
+ {...rest}
34
+ >
35
+ {@render children?.()}
36
+ </a>
37
+
38
+ <style>
39
+ .unstyled-link {
40
+ all: unset;
41
+ cursor: pointer;
42
+ }
43
+ </style>
6.25.0/atoms/src/Empty.svelte ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+
4
+ let {
5
+ size = "small",
6
+ unpadded_box = false,
7
+ children
8
+ }: {
9
+ size?: "small" | "large";
10
+ unpadded_box?: boolean;
11
+ children?: Snippet;
12
+ } = $props();
13
+
14
+ let el: HTMLDivElement | undefined = $state();
15
+ let parent_height = $derived(compare_el_to_parent(el));
16
+
17
+ function compare_el_to_parent(el: HTMLDivElement | undefined): boolean {
18
+ if (!el) return false;
19
+
20
+ const { height: el_height } = el.getBoundingClientRect();
21
+ const { height: parent_height } =
22
+ el.parentElement?.getBoundingClientRect() || { height: el_height };
23
+
24
+ return el_height > parent_height + 2;
25
+ }
26
+ </script>
27
+
28
+ <div
29
+ class="empty"
30
+ class:small={size === "small"}
31
+ class:large={size === "large"}
32
+ class:unpadded_box
33
+ bind:this={el}
34
+ class:small_parent={parent_height}
35
+ aria-label="Empty value"
36
+ >
37
+ <div class="icon">
38
+ {@render children?.()}
39
+ </div>
40
+ </div>
41
+
42
+ <style>
43
+ .empty {
44
+ display: flex;
45
+ justify-content: center;
46
+ align-items: center;
47
+ margin-top: calc(0px - var(--size-6));
48
+ height: var(--size-full);
49
+ }
50
+
51
+ .icon {
52
+ opacity: 0.5;
53
+ height: var(--size-5);
54
+ color: var(--body-text-color);
55
+ }
56
+
57
+ .small {
58
+ min-height: calc(var(--size-32) - 20px);
59
+ }
60
+
61
+ .large {
62
+ min-height: calc(var(--size-64) - 20px);
63
+ }
64
+
65
+ .unpadded_box {
66
+ margin-top: 0;
67
+ }
68
+
69
+ .small_parent {
70
+ min-height: 100% !important;
71
+ }
72
+ </style>
6.25.0/atoms/src/FullscreenButton.svelte ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.25.0/atoms/src/IconButton.svelte ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.25.0/atoms/src/IconButtonWrapper.svelte ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.25.0/atoms/src/Info.svelte ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { render_inline_markdown } from "./inline-markdown";
3
+ let { info }: { info: string } = $props();
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.25.0/atoms/src/ScrollFade.svelte ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.25.0/atoms/src/SelectSource.svelte ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.25.0/atoms/src/ShareButton.svelte ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import IconButton from "./IconButton.svelte";
3
+ import { Community } from "@gradio/icons";
4
+ import type { ShareData } from "@gradio/utils";
5
+ import { ShareError } from "@gradio/utils";
6
+ import type { I18nFormatter } from "@gradio/utils";
7
+
8
+ let {
9
+ formatter,
10
+ value,
11
+ i18n,
12
+ onshare,
13
+ onerror
14
+ }: {
15
+ formatter: (arg0: any) => Promise<string>;
16
+ value: any;
17
+ i18n: I18nFormatter;
18
+ onshare?: (data: ShareData) => void;
19
+ onerror?: (message: string) => void;
20
+ } = $props();
21
+
22
+ let pending = $state(false);
23
+ </script>
24
+
25
+ <IconButton
26
+ Icon={Community}
27
+ label={i18n("common.share")}
28
+ {pending}
29
+ onclick={async () => {
30
+ try {
31
+ pending = true;
32
+ const formatted = await formatter(value);
33
+ const data = {
34
+ description: formatted
35
+ };
36
+ onshare?.(data);
37
+ } catch (e) {
38
+ console.error(e);
39
+ let message = e instanceof ShareError ? e.message : "Share failed.";
40
+ onerror?.(message);
41
+ } finally {
42
+ pending = false;
43
+ }
44
+ }}
45
+ />
6.25.0/atoms/src/Toolbar.svelte ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+
4
+ let {
5
+ show_border = false,
6
+ children
7
+ }: {
8
+ show_border?: boolean;
9
+ children?: Snippet;
10
+ } = $props();
11
+ </script>
12
+
13
+ <div class:show_border>
14
+ {@render children?.()}
15
+ </div>
16
+
17
+ <style>
18
+ div {
19
+ border-top: 1px solid transparent;
20
+ display: flex;
21
+ max-height: 100%;
22
+ justify-content: center;
23
+ align-items: center;
24
+ gap: var(--spacing-sm);
25
+ height: auto;
26
+ align-items: flex-end;
27
+ color: var(--block-label-text-color);
28
+ flex-shrink: 0;
29
+ }
30
+
31
+ .show_border {
32
+ border-top: 1px solid var(--block-border-color);
33
+ margin-top: var(--spacing-xxl);
34
+ box-shadow: var(--shadow-drop);
35
+ }
36
+ </style>
6.25.0/atoms/src/UploadText.svelte ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ let {
7
+ type = "file",
8
+ i18n,
9
+ message = undefined,
10
+ mode = "full",
11
+ hovered = false,
12
+ placeholder = undefined
13
+ }: {
14
+ type?:
15
+ | "video"
16
+ | "image"
17
+ | "audio"
18
+ | "file"
19
+ | "csv"
20
+ | "clipboard"
21
+ | "gallery";
22
+ i18n: I18nFormatter;
23
+ message?: string | undefined;
24
+ mode?: "full" | "short";
25
+ hovered?: boolean;
26
+ placeholder?: string | undefined;
27
+ } = $props();
28
+
29
+ const defs = {
30
+ image: "upload_text.drop_image",
31
+ video: "upload_text.drop_video",
32
+ audio: "upload_text.drop_audio",
33
+ file: "upload_text.drop_file",
34
+ csv: "upload_text.drop_csv",
35
+ gallery: "upload_text.drop_gallery",
36
+ clipboard: "upload_text.paste_clipboard"
37
+ };
38
+
39
+ let parsed_placeholder = $derived<[string | false, string | false]>(
40
+ placeholder ? inject(placeholder) : [false, false]
41
+ );
42
+ let heading = $derived(parsed_placeholder[0]);
43
+ let paragraph = $derived(parsed_placeholder[1]);
44
+ </script>
45
+
46
+ <div class="wrap">
47
+ <span class="icon-wrap" class:hovered>
48
+ {#if type === "clipboard"}
49
+ <ImagePaste />
50
+ {:else}
51
+ <UploadIcon />
52
+ {/if}
53
+ </span>
54
+
55
+ {#if heading || paragraph}
56
+ {#if heading}
57
+ <h2>{heading}</h2>
58
+ {/if}
59
+ {#if paragraph}
60
+ <p>{paragraph}</p>
61
+ {/if}
62
+ {:else}
63
+ {i18n(defs[type] || defs.file)}
64
+
65
+ {#if mode !== "short"}
66
+ <span class="or">- {i18n("common.or")} -</span>
67
+ {message || i18n("upload_text.click_to_upload")}
68
+ {/if}
69
+ {/if}
70
+ </div>
71
+
72
+ <style>
73
+ h2 {
74
+ font-size: var(--text-xl) !important;
75
+ }
76
+
77
+ p,
78
+ h2 {
79
+ white-space: pre-line;
80
+ }
81
+
82
+ .wrap {
83
+ display: flex;
84
+ flex-direction: column;
85
+ justify-content: center;
86
+ align-items: center;
87
+ min-height: var(--size-60);
88
+ color: var(--block-label-text-color);
89
+ line-height: var(--line-md);
90
+ height: 100%;
91
+ padding-top: var(--size-3);
92
+ text-align: center;
93
+ margin: auto var(--spacing-lg);
94
+ }
95
+
96
+ .or {
97
+ color: var(--body-text-color-subdued);
98
+ display: flex;
99
+ }
100
+
101
+ .icon-wrap {
102
+ width: 30px;
103
+ margin-bottom: var(--spacing-lg);
104
+ }
105
+
106
+ @media (--screen-md) {
107
+ .wrap {
108
+ font-size: var(--text-lg);
109
+ }
110
+ }
111
+
112
+ .hovered {
113
+ color: var(--color-accent);
114
+ }
115
+ </style>
6.25.0/atoms/src/index.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.25.0/atoms/src/inline-markdown.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, "&amp;")
12
+ .replace(/</g, "&lt;")
13
+ .replace(/>/g, "&gt;")
14
+ .replace(/"/g, "&quot;");
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.25.0/atoms/src/utils/parse_placeholder.ts ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }