1import { a as Button } from './Button-20c14f3f.js'; 2import { g as get_fetchable_url_or_file, p as prepare_files, u as upload } from './index-6d9f7a14.js'; 3import './Index-34f70ab5.js'; 4import './svelte/svelte.js'; 5 6const UploadButton_svelte_svelte_type_style_lang = ''; 7 8/* home/runner/work/gradio/gradio/js/uploadbutton/shared/UploadButton.svelte generated by Svelte v4.2.2 */ 9const { 10 SvelteComponent: SvelteComponent$1, 11 attr, 12 binding_callbacks, 13 create_component: create_component$1, 14 create_slot, 15 destroy_component: destroy_component$1, 16 detach: detach$1, 17 element, 18 get_all_dirty_from_scope, 19 get_slot_changes, 20 init: init$1, 21 insert: insert$1, 22 listen, 23 mount_component: mount_component$1, 24 run_all, 25 safe_not_equal: safe_not_equal$1, 26 space, 27 src_url_equal, 28 transition_in: transition_in$1, 29 transition_out: transition_out$1, 30 update_slot_base 31} = window.__gradio__svelte__internal; 32const { tick, createEventDispatcher, getContext } = window.__gradio__svelte__internal; 33function create_if_block(ctx) { 34 let img; 35 let img_src_value; 36 let img_alt_value; 37 38 return { 39 c() { 40 img = element("img"); 41 attr(img, "class", "button-icon svelte-1rvxzzt"); 42 if (!src_url_equal(img.src, img_src_value = /*icon_path*/ ctx[14])) attr(img, "src", img_src_value); 43 attr(img, "alt", img_alt_value = `${/*value*/ ctx[0]} icon`); 44 }, 45 m(target, anchor) { 46 insert$1(target, img, anchor); 47 }, 48 p(ctx, dirty) { 49 if (dirty & /*icon_path*/ 16384 && !src_url_equal(img.src, img_src_value = /*icon_path*/ ctx[14])) { 50 attr(img, "src", img_src_value); 51 } 52 53 if (dirty & /*value*/ 1 && img_alt_value !== (img_alt_value = `${/*value*/ ctx[0]} icon`)) { 54 attr(img, "alt", img_alt_value); 55 } 56 }, 57 d(detaching) { 58 if (detaching) { 59 detach$1(img); 60 } 61 } 62 }; 63} 64 65// (82:0) <BaseButton {size} {variant} {elem_id} {elem_classes} {visible} on:click={openFileUpload} {scale} {min_width} {disabled} > 66function create_default_slot$1(ctx) { 67 let t; 68 let current; 69 let if_block = /*icon*/ ctx[7] && create_if_block(ctx); 70 const default_slot_template = /*#slots*/ ctx[20].default; 71 const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[22], null); 72 73 return { 74 c() { 75 if (if_block) if_block.c(); 76 t = space(); 77 if (default_slot) default_slot.c(); 78 }, 79 m(target, anchor) { 80 if (if_block) if_block.m(target, anchor); 81 insert$1(target, t, anchor); 82 83 if (default_slot) { 84 default_slot.m(target, anchor); 85 } 86 87 current = true; 88 }, 89 p(ctx, dirty) { 90 if (/*icon*/ ctx[7]) { 91 if (if_block) { 92 if_block.p(ctx, dirty); 93 } else { 94 if_block = create_if_block(ctx); 95 if_block.c(); 96 if_block.m(t.parentNode, t); 97 } 98 } else if (if_block) { 99 if_block.d(1); 100 if_block = null; 101 } 102 103 if (default_slot) { 104 if (default_slot.p && (!current || dirty & /*$$scope*/ 4194304)) { 105 update_slot_base( 106 default_slot, 107 default_slot_template, 108 ctx, 109 /*$$scope*/ ctx[22], 110 !current 111 ? get_all_dirty_from_scope(/*$$scope*/ ctx[22]) 112 : get_slot_changes(default_slot_template, /*$$scope*/ ctx[22], dirty, null), 113 null 114 ); 115 } 116 } 117 }, 118 i(local) { 119 if (current) return; 120 transition_in$1(default_slot, local); 121 current = true; 122 }, 123 o(local) { 124 transition_out$1(default_slot, local); 125 current = false; 126 }, 127 d(detaching) { 128 if (detaching) { 129 detach$1(t); 130 } 131 132 if (if_block) if_block.d(detaching); 133 if (default_slot) default_slot.d(detaching); 134 } 135 }; 136} 137 138function create_fragment$1(ctx) { 139 let input; 140 let input_multiple_value; 141 let input_webkitdirectory_value; 142 let input_mozdirectory_value; 143 let input_data_testid_value; 144 let t; 145 let basebutton; 146 let current; 147 let mounted; 148 let dispose; 149 150 basebutton = new Button({ 151 props: { 152 size: /*size*/ ctx[6], 153 variant: /*variant*/ ctx[10], 154 elem_id: /*elem_id*/ ctx[1], 155 elem_classes: /*elem_classes*/ ctx[2], 156 visible: /*visible*/ ctx[3], 157 scale: /*scale*/ ctx[8], 158 min_width: /*min_width*/ ctx[9], 159 disabled: /*disabled*/ ctx[11], 160 $$slots: { default: [create_default_slot$1] }, 161 $$scope: { ctx } 162 } 163 }); 164 165 basebutton.$on("click", /*openFileUpload*/ ctx[15]); 166 167 return { 168 c() { 169 input = element("input"); 170 t = space(); 171 create_component$1(basebutton.$$.fragment); 172 attr(input, "class", "hide svelte-1rvxzzt"); 173 attr(input, "accept", /*accept_file_types*/ ctx[13]); 174 attr(input, "type", "file"); 175 input.multiple = input_multiple_value = /*file_count*/ ctx[5] === "multiple" || undefined; 176 attr(input, "webkitdirectory", input_webkitdirectory_value = /*file_count*/ ctx[5] === "directory" || undefined); 177 attr(input, "mozdirectory", input_mozdirectory_value = /*file_count*/ ctx[5] === "directory" || undefined); 178 attr(input, "data-testid", input_data_testid_value = "" + (/*label*/ ctx[4] + "-upload-button")); 179 }, 180 m(target, anchor) { 181 insert$1(target, input, anchor); 182 /*input_binding*/ ctx[21](input); 183 insert$1(target, t, anchor);
184 mount_component$1(basebutton, target, anchor); 185 current = true; 186 187 if (!mounted) { 188 dispose = [ 189 listen(input, "change", /*loadFilesFromUpload*/ ctx[16]), 190 listen(input, "click", clearInputValue) 191 ]; 192 193 mounted = true; 194 } 195 }, 196 p(ctx, [dirty]) { 197 if (!current || dirty & /*accept_file_types*/ 8192) { 198 attr(input, "accept", /*accept_file_types*/ ctx[13]); 199 } 200 201 if (!current || dirty & /*file_count*/ 32 && input_multiple_value !== (input_multiple_value = /*file_count*/ ctx[5] === "multiple" || undefined)) { 202 input.multiple = input_multiple_value; 203 } 204 205 if (!current || dirty & /*file_count*/ 32 && input_webkitdirectory_value !== (input_webkitdirectory_value = /*file_count*/ ctx[5] === "directory" || undefined)) { 206 attr(input, "webkitdirectory", input_webkitdirectory_value); 207 } 208 209 if (!current || dirty & /*file_count*/ 32 && input_mozdirectory_value !== (input_mozdirectory_value = /*file_count*/ ctx[5] === "directory" || undefined)) { 210 attr(input, "mozdirectory", input_mozdirectory_value); 211 } 212 213 if (!current || dirty & /*label*/ 16 && input_data_testid_value !== (input_data_testid_value = "" + (/*label*/ ctx[4] + "-upload-button"))) { 214 attr(input, "data-testid", input_data_testid_value); 215 } 216 217 const basebutton_changes = {}; 218 if (dirty & /*size*/ 64) basebutton_changes.size = /*size*/ ctx[6]; 219 if (dirty & /*variant*/ 1024) basebutton_changes.variant = /*variant*/ ctx[10]; 220 if (dirty & /*elem_id*/ 2) basebutton_changes.elem_id = /*elem_id*/ ctx[1]; 221 if (dirty & /*elem_classes*/ 4) basebutton_changes.elem_classes = /*elem_classes*/ ctx[2]; 222 if (dirty & /*visible*/ 8) basebutton_changes.visible = /*visible*/ ctx[3]; 223 if (dirty & /*scale*/ 256) basebutton_changes.scale = /*scale*/ ctx[8]; 224 if (dirty & /*min_width*/ 512) basebutton_changes.min_width = /*min_width*/ ctx[9]; 225 if (dirty & /*disabled*/ 2048) basebutton_changes.disabled = /*disabled*/ ctx[11]; 226 227 if (dirty & /*$$scope, icon_path, value, icon*/ 4210817) { 228 basebutton_changes.$$scope = { dirty, ctx }; 229 } 230 231 basebutton.$set(basebutton_changes); 232 }, 233 i(local) { 234 if (current) return; 235 transition_in$1(basebutton.$$.fragment, local); 236 current = true; 237 }, 238 o(local) { 239 transition_out$1(basebutton.$$.fragment, local); 240 current = false; 241 }, 242 d(detaching) { 243 if (detaching) { 244 detach$1(input); 245 detach$1(t); 246 } 247 248 /*input_binding*/ ctx[21](null); 249 destroy_component$1(basebutton, detaching); 250 mounted = false; 251 run_all(dispose); 252 } 253 }; 254} 255 256function clearInputValue(e) { 257 const target = e.target; 258 if (target.value) target.value = ""; 259} 260 261function instance$1($$self, $$props, $$invalidate) { 262 let icon_path; 263 let { $$slots: slots = {}, $$scope } = $$props; 264 let { elem_id = "" } = $$props; 265 let { elem_classes = [] } = $$props; 266 let { visible = true } = $$props; 267 let { label } = $$props; 268 let { value } = $$props; 269 let { file_count } = $$props; 270 let { file_types = [] } = $$props; 271 let { root } = $$props; 272 let { size = "lg" } = $$props; 273 let { icon = null } = $$props; 274 let { scale = null } = $$props; 275 let { min_width = undefined } = $$props; 276 let { variant = "secondary" } = $$props; 277 let { disabled = false } = $$props; 278 let { proxy_url = null } = $$props; 279 const dispatch = createEventDispatcher(); 280 281 // Needed for wasm support 282 const upload_fn = getContext("upload_files"); 283 284 let hidden_upload; 285 let accept_file_types; 286 287 if (file_types == null) { 288 accept_file_types = null; 289 } else { 290 file_types = file_types.map(x => { 291 if (x.startsWith(".")) { 292 return x; 293 } 294 295 return x + "/*"; 296 }); 297 298 accept_file_types = file_types.join(", "); 299 } 300 301 function openFileUpload() { 302 dispatch("click"); 303 hidden_upload.click(); 304 } 305 306 async function loadFiles(files) { 307 let _files = Array.from(files); 308 309 if (!files.length) { 310 return; 311 } 312 313 if (file_count === "single") { 314 _files = [files[0]]; 315 } 316 317 let all_file_data = await prepare_files(_files); 318 await tick(); 319 all_file_data = (await upload(all_file_data, root, undefined, upload_fn))?.filter(x => x !== null); 320 321 $$invalidate(0, value = file_count === "single" 322 ? all_file_data?.[0] 323 : all_file_data); 324 325 dispatch("change", value); 326 dispatch("upload", value); 327 } 328 329 async function loadFilesFromUpload(e) { 330 const target = e.target; 331 if (!target.files) return; 332 await loadFiles(target.files); 333 } 334 335 function input_binding($$value) { 336 binding_callbacks[$$value ? 'unshift' : 'push'](() => { 337 hidden_upload = $$value;
338 $$invalidate(12, hidden_upload); 339 }); 340 } 341 342 $$self.$$set = $$props => { 343 if ('elem_id' in $$props) $$invalidate(1, elem_id = $$props.elem_id); 344 if ('elem_classes' in $$props) $$invalidate(2, elem_classes = $$props.elem_classes); 345 if ('visible' in $$props) $$invalidate(3, visible = $$props.visible); 346 if ('label' in $$props) $$invalidate(4, label = $$props.label); 347 if ('value' in $$props) $$invalidate(0, value = $$props.value); 348 if ('file_count' in $$props) $$invalidate(5, file_count = $$props.file_count); 349 if ('file_types' in $$props) $$invalidate(17, file_types = $$props.file_types); 350 if ('root' in $$props) $$invalidate(18, root = $$props.root); 351 if ('size' in $$props) $$invalidate(6, size = $$props.size); 352 if ('icon' in $$props) $$invalidate(7, icon = $$props.icon); 353 if ('scale' in $$props) $$invalidate(8, scale = $$props.scale); 354 if ('min_width' in $$props) $$invalidate(9, min_width = $$props.min_width); 355 if ('variant' in $$props) $$invalidate(10, variant = $$props.variant); 356 if ('disabled' in $$props) $$invali
356date(11, disabled = $$props.disabled); 357 if ('proxy_url' in $$props) $$invalidate(19, proxy_url = $$props.proxy_url); 358 if ('$$scope' in $$props) $$invalidate(22, $$scope = $$props.$$scope); 359 }; 360 361 $$self.$$.update = () => { 362 if ($$self.$$.dirty & /*icon, root, proxy_url*/ 786560) { 363 $$invalidate(14, icon_path = get_fetchable_url_or_file(icon, root, proxy_url)); 364 } 365 }; 366 367 return [ 368 value, 369 elem_id, 370 elem_classes, 371 visible, 372 label, 373 file_count, 374 size, 375 icon, 376 scale, 377 min_width, 378 variant, 379 disabled, 380 hidden_upload, 381 accept_file_types, 382 icon_path, 383 openFileUpload, 384 loadFilesFromUpload, 385 file_types, 386 root, 387 proxy_url, 388 slots, 389 input_binding, 390 $$scope 391 ]; 392} 393 394class UploadButton extends SvelteComponent$1 { 395 constructor(options) { 396 super(); 397 398 init$1(this, options, instance$1, create_fragment$1, safe_not_equal$1, { 399 elem_id: 1, 400 elem_classes: 2, 401 visible: 3, 402 label: 4, 403 value: 0, 404 file_count: 5, 405 file_types: 17, 406 root: 18, 407 size: 6, 408 icon: 7, 409 scale: 8, 410 min_width: 9, 411 variant: 10, 412 disabled: 11, 413 proxy_url: 19 414 }); 415 } 416} 417 418const UploadButton$1 = UploadButton; 419 420/* home/runner/work/gradio/gradio/js/uploadbutton/Index.svelte generated by Svelte v4.2.2 */ 421const { 422 SvelteComponent, 423 create_component, 424 destroy_component, 425 detach, 426 init, 427 insert, 428 mount_component, 429 safe_not_equal, 430 set_data, 431 text, 432 transition_in, 433 transition_out 434} = window.__gradio__svelte__internal; 435function create_default_slot(ctx) { 436 let t_value = /*gradio*/ ctx[13].i18n(/*label*/ ctx[4]) + ""; 437 let t; 438 439 return { 440 c() { 441 t = text(t_value); 442 }, 443 m(target, anchor) { 444 insert(target, t, anchor); 445 }, 446 p(ctx, dirty) { 447 if (dirty & /*gradio, label*/ 8208 && t_value !== (t_value = /*gradio*/ ctx[13].i18n(/*label*/ ctx[4]) + "")) set_data(t, t_value); 448 }, 449 d(detaching) { 450 if (detaching) { 451 detach(t); 452 } 453 } 454 }; 455} 456 457function create_fragment(ctx) { 458 let uploadbutton; 459 let current; 460 461 uploadbutton = new UploadButton$1({ 462 props: { 463 elem_id: /*elem_id*/ ctx[1], 464 elem_classes: /*elem_classes*/ ctx[2], 465 visible: /*visible*/ ctx[3], 466 file_count: /*file_count*/ ctx[5], 467 file_types: /*file_types*/ ctx[6], 468 size: /*size*/ ctx[8], 469 scale: /*scale*/ ctx[9], 470 icon: /*icon*/ ctx[10], 471 min_width: /*min_width*/ ctx[11], 472 root: /*root*/ ctx[7], 473 value: /*value*/ ctx[0], 474 disabled: /*disabled*/ ctx[15], 475 variant: /*variant*/ ctx[12], 476 label: /*label*/ ctx[4], 477 proxy_url: /*proxy_url*/ ctx[14], 478 $$slots: { default: [create_default_slot] }, 479 $$scope: { ctx } 480 } 481 }); 482 483 uploadbutton.$on("click", /*click_handler*/ ctx[18]); 484 uploadbutton.$on("change", /*change_handler*/ ctx[19]); 485 uploadbutton.$on("upload", /*upload_handler*/ ctx[20]); 486 487 return { 488 c() { 489 create_component(uploadbutton.$$.fragment); 490 }, 491 m(target, anchor) { 492 mount_component(uploadbutton, target, anchor); 493 current = true; 494 }, 495 p(ctx, [dirty]) { 496 const uploadbutton_changes = {}; 497 if (dirty & /*elem_id*/ 2) uploadbutton_changes.elem_id = /*elem_id*/ ctx[1]; 498 if (dirty & /*elem_classes*/ 4) uploadbutton_changes.elem_classes = /*elem_classes*/ ctx[2]; 499 if (dirty & /*visible*/ 8) uploadbutton_changes.visible = /*visible*/ ctx[3]; 500 if (dirty & /*file_count*/ 32) uploadbutton_changes.file_count = /*file_count*/ ctx[5]; 501 if (dirty & /*file_types*/ 64) uploadbutton_changes.file_types = /*file_types*/ ctx[6]; 502 if (dirty & /*size*/ 256) uploadbutton_changes.size = /*size*/ ctx[8]; 503 if (dirty & /*scale*/ 512) uploadbutton_changes.scale = /*scale*/ ctx[9]; 504 if (dirty & /*icon*/ 1024) uploadbutton_changes.icon = /*icon*/ ctx[10]; 505 if (dirty & /*min_width*/ 2048) uploadbutton_changes.min_width = /*min_width*/ ctx[11]; 506 if (dirty & /*root*/ 128) uploadbutton_changes.root = /*root*/ ctx[7]; 507 if (dirty & /*value*/ 1) uploadbutton_changes.value = /*value*/ ctx[0]; 508 if (dirty & /*disabled*/ 32768) uploadbutton_changes.disabled = /*disabled*/ ctx[15]; 509 if (dirty & /*variant*/ 4096) uploadbutton_changes.variant = /*variant*/ ctx[12]; 510 if (dirty & /*label*/ 16) uploadbutton_changes.label = /*label*/ ctx[4];
511 if (dirty & /*proxy_url*/ 16384) uploadbutton_changes.proxy_url = /*proxy_url*/ ctx[14]; 512 513 if (dirty & /*$$scope, gradio, label*/ 2105360) { 514 uploadbutton_changes.$$scope = { dirty, ctx }; 515 } 516 517 uploadbutton.$set(uploadbutton_changes); 518 }, 519 i(local) { 520 if (current) return; 521 transition_in(uploadbutton.$$.fragment, local); 522 current = true; 523 }, 524 o(local) { 525 transition_out(uploadbutton.$$.fragment, local); 526 current = false; 527 }, 528 d(detaching) { 529 destroy_component(uploadbutton, detaching); 530 } 531 }; 532} 533 534function instance($$self, $$props, $$invalidate) { 535 let disabled; 536 let { elem_id = "" } = $$props; 537 let { elem_classes = [] } = $$props; 538 let { visible = true } = $$props; 539 let { label } = $$props; 540 let { value } = $$props; 541 let { file_count } = $$props; 542 let { file_types = [] } = $$props; 543 let { root } = $$props; 544 let { size = "lg" } = $$props; 545 let { scale = null } = $$props; 546 let { icon = null } = $$props; 547 let { min_width = undefined } = $$props; 548 let { variant = "secondary" } = $$props; 549 let { gradio } = $$props; 550 let { interactive } = $$props; 551 let { proxy_url = null } = $$props; 552 553 async function handle_event(detail, event) { 554 $$invalidate(0, value = detail); 555 gradio.dispatch(event); 556 } 557 558 const click_handler = () => gradio.dispatch("click"); 559 const change_handler = ({ detail }) => handle_event(detail, "change"); 560 const upload_handler = ({ detail }) => handle_event(detail, "upload"); 561 562 $$self.$$set = $$props => {
563 if ('elem_id' in $$props) $$invalidate(1, elem_id = $$props.elem_id); 564 if ('elem_classes' in $$props) $$invalidate(2, elem_classes = $$props.elem_classes); 565 if ('visible' in $$props) $$invalidate(3, visible = $$props.visible); 566 if ('label' in $$props) $$invalidate(4, label = $$props.label); 567 if ('value' in $$props) $$invalidate(0, value = $$props.value); 568 if ('file_count' in $$props) $$invalidate(5, file_count = $$props.file_count); 569 if ('file_types' in $$props) $$invalidate(6, file_types = $$props.file_types); 570 if ('root' in $$props) $$invalidate(7, root = $$props.root); 571 if ('size' in $$props) $$invalidate(8, size = $$props.size); 572 if ('scale' in $$props) $$invalidate(9, scale = $$props.scale); 573 if ('icon' in $$props) $$invalidate(10, icon = $$props.icon); 574 if ('min_width' in $$props) $$invalidate(11, min_width = $$props.min_width); 575 if ('variant' in $$props) $$invalidate(12, variant = $$props.variant); 576 if ('gradio' in $$props) $$invalidate(13, gradio = $$props.gradio); 577 if ('interactive' in $$props) $$invali
577date(17, interactive = $$props.interactive); 578 if ('proxy_url' in $$props) $$invalidate(14, proxy_url = $$props.proxy_url); 579 }; 580 581 $$self.$$.update = () => { 582 if ($$self.$$.dirty & /*interactive*/ 131072) { 583 $$invalidate(15, disabled = !interactive); 584 } 585 }; 586 587 return [ 588 value, 589 elem_id, 590 elem_classes, 591 visible, 592 label, 593 file_count, 594 file_types, 595 root, 596 size, 597 scale, 598 icon, 599 min_width, 600 variant, 601 gradio, 602 proxy_url, 603 disabled, 604 handle_event, 605 interactive, 606 click_handler, 607 change_handler, 608 upload_handler 609 ]; 610} 611 612class Index extends SvelteComponent { 613 constructor(options) { 614 super(); 615 616 init(this, options, instance, create_fragment, safe_not_equal, { 617 elem_id: 1, 618 elem_classes: 2, 619 visible: 3, 620 label: 4, 621 value: 0, 622 file_count: 5, 623 file_types: 6, 624 root: 7, 625 size: 8, 626 scale: 9, 627 icon: 10, 628 min_width: 11, 629 variant: 12, 630 gradio: 13, 631 interactive: 17, 632 proxy_url: 14 633 }); 634 } 635} 636 637export { UploadButton$1 as BaseUploadButton, Index as default }; 638//# sourceMappingURL=Index-1358ea4a.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.