import { w as writable, S as Static } from './Index-f62c49f9.js';
import { F as File } from './File-e96cd7d6.js';
import { B as Block } from './Button-723db480.js';
import { B as BlockLabel } from './BlockLabel-7be36365.js';
import { E as Empty } from './Empty-ee9cf9c4.js';
import './index-b5b16a51.js';
import './svelte/svelte.js';

var has = Object.prototype.hasOwnProperty;

function find(iter, tar, key) {
	for (key of iter.keys()) {
		if (dequal(key, tar)) return key;
	}
}

function dequal(foo, bar) {
	var ctor, len, tmp;
	if (foo === bar) return true;

	if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
		if (ctor === Date) return foo.getTime() === bar.getTime();
		if (ctor === RegExp) return foo.toString() === bar.toString();

		if (ctor === Array) {
			if ((len=foo.length) === bar.length) {
				while (len-- && dequal(foo[len], bar[len]));
			}
			return len === -1;
		}

		if (ctor === Set) {
			if (foo.size !== bar.size) {
				return false;
			}
			for (len of foo) {
				tmp = len;
				if (tmp && typeof tmp === 'object') {
					tmp = find(bar, tmp);
					if (!tmp) return false;
				}
				if (!bar.has(tmp)) return false;
			}
			return true;
		}

		if (ctor === Map) {
			if (foo.size !== bar.size) {
				return false;
			}
			for (len of foo) {
				tmp = len[0];
				if (tmp && typeof tmp === 'object') {
					tmp = find(bar, tmp);
					if (!tmp) return false;
				}
				if (!dequal(len[1], bar.get(tmp))) {
					return false;
				}
			}
			return true;
		}

		if (ctor === ArrayBuffer) {
			foo = new Uint8Array(foo);
			bar = new Uint8Array(bar);
		} else if (ctor === DataView) {
			if ((len=foo.byteLength) === bar.byteLength) {
				while (len-- && foo.getInt8(len) === bar.getInt8(len));
			}
			return len === -1;
		}

		if (ArrayBuffer.isView(foo)) {
			if ((len=foo.byteLength) === bar.byteLength) {
				while (len-- && foo[len] === bar[len]);
			}
			return len === -1;
		}

		if (!ctor || typeof foo === 'object') {
			len = 0;
			for (ctor in foo) {
				if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
				if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
			}
			return Object.keys(bar).length === len;
		}
	}

	return foo !== foo && bar !== bar;
}

/* home/runner/work/gradio/gradio/js/fileexplorer/shared/ArrowIcon.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$4,
	append: append$1,
	attr: attr$3,
	detach: detach$4,
	init: init$4,
	insert: insert$4,
	noop: noop$2,
	safe_not_equal: safe_not_equal$4,
	set_style,
	svg_element
} = window.__gradio__svelte__internal;
function create_fragment$4(ctx) {
	let svg;
	let g;
	let path;

	return {
		c() {
			svg = svg_element("svg");
			g = svg_element("g");
			path = svg_element("path");
			attr$3(path, "d", "M12.7,24.033C12.256,24.322 11.806,24.339 11.351,24.084C10.896,23.829 10.668,23.434 10.667,22.9L10.667,9.1C10.667,8.567 10.895,8.172 11.351,7.916C11.807,7.66 12.256,7.677 12.7,7.967L23.567,14.867C23.967,15.133 24.167,15.511 24.167,16C24.167,16.489 23.967,16.867 23.567,17.133L12.7,24.033Z");
			set_style(path, "fill", "currentColor");
			set_style(path, "fill-rule", "nonzero");
			attr$3(g, "transform", "matrix(1,0,0,1,-10.6667,-7.73588)");
			attr$3(svg, "width", "100%");
			attr$3(svg, "height", "100%");
			attr$3(svg, "viewBox", "0 0 14 17");
			attr$3(svg, "version", "1.1");
			set_style(svg, "fill-rule", "evenodd");
			set_style(svg, "clip-rule", "evenodd");
			set_style(svg, "stroke-linejoin", "round");
			set_style(svg, "stroke-miterlimit", "2");
		},
		m(target, anchor) {
			insert$4(target, svg, anchor);
			append$1(svg, g);
			append$1(g, path);
		},
		p: noop$2,
		i: noop$2,
		o: noop$2,
		d(detaching) {
			if (detaching) {
				detach$4(svg);
			}
		}
	};
}

class ArrowIcon extends SvelteComponent$4 {
	constructor(options) {
		super();
		init$4(this, options, null, create_fragment$4, safe_not_equal$4, {});
	}
}

const Checkbox_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/fileexplorer/shared/Checkbox.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$3,
	attr: attr$2,
	detach: detach$3,
	element: element$2,
	init: init$3,
	insert: insert$3,
	listen: listen$1,
	noop: noop$1,
	run_all: run_all$1,
	safe_not_equal: safe_not_equal$3,
	toggle_class: toggle_class$1
} = window.__gradio__svelte__internal;
const { createEventDispatcher: createEventDispatcher$2 } = window.__gradio__svelte__internal;
function create_fragment$3(ctx) {
	let input;
	let mounted;
	let dispose;

	return {
		c() {
			input = element$2("input");
			attr$2(input, "type", "checkbox");
			input.disabled = /*disabled*/ ctx[1];
			attr$2(input, "class", "svelte-8ywr9r");
			toggle_class$1(input, "disabled", /*disabled*/ ctx[1] && !/*value*/ ctx[0]);
		},
		m(target, anchor) {
			insert$3(target, input, anchor);
			input.checked = /*value*/ ctx[0];

			if (!mounted) {
				dispose = [
					listen$1(input, "change", /*input_change_handler*/ ctx[3]),
					listen$1(input, "click", /*click_handler*/ ctx[4]),
					listen$1(input, "keydown", /*keydown_handler*/ ctx[5])
				];

				mounted = true;
			}
		},
		p(ctx, [dirty]) {
			if (dirty & /*disabled*/ 2) {
				input.disabled = /*disabled*/ ctx[1];
			}

			if (dirty & /*value*/ 1) {
				input.checked = /*value*/ ctx[0];
			}

			if (dirty & /*disabled, value*/ 3) {
				toggle_class$1(input, "disabled", /*disabled*/ ctx[1] && !/*value*/ ctx[0]);
			}
		},
		i: noop$1,
		o: noop$1,
		d(detaching) {
			if (detaching) {
				detach$3(input);
			}

			mounted = false;
			run_all$1(dispose);
		}
	};
}

function instance$3($$self, $$props, $$invalidate) {
	let { value } = $$props;
	let { disabled } = $$props;
	const dispatch = createEventDispatcher$2();

	function input_change_handler() {
		value = this.checked;
		$$invalidate(0, value);
	}

	const click_handler = () => dispatch("change", value);
	const keydown_handler = ({ key }) => (key === " " || key === "Enter") && dispatch("change", value);

	$$self.$$set = $$props => {
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('disabled' in $$props) $$invalidate(1, disabled = $$props.disabled);
	};

	return [
		value,
		disabled,
		dispatch,
		input_change_handler,
		click_handler,
		keydown_handler
	];
}

class Checkbox extends SvelteComponent$3 {
	constructor(options) {
		super();
		init$3(this, options, instance$3, create_fragment$3, safe_not_equal$3, { value: 0, disabled: 1 });
	}
}

const FileIcon = ""+new URL('light-file-0e72c1e1.svg', import.meta.url).href+"";

const FileTree_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/fileexplorer/shared/FileTree.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$2,
	add_flush_callback: add_flush_callback$1,
	append,
	attr: attr$1,
	bind: bind$1,
	binding_callbacks: binding_callbacks$1,
	bubble,
	check_outros: check_outros$1,
	create_component: create_component$2,
	destroy_component: destroy_component$2,
	destroy_each,
	detach: detach$2,
	element: element$1,
	ensure_array_like,
	group_outros: group_outros$1,
	init: init$2,
	insert: insert$2,
	listen,
	mount_component: mount_component$2,
	noop,
	run_all,
	safe_not_equal: safe_not_equal$2,
	set_data,
	space: space$1,
	stop_propagation,
	text,
	toggle_class,
	transition_in: transition_in$2,
	transition_out: transition_out$2
} = window.__gradio__svelte__internal;
const { createEventDispatcher: createEventDispatcher$1, tick } = window.__gradio__svelte__internal;
function get_each_context(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[12] = list[i].type;
	child_ctx[13] = list[i].path;
	child_ctx[14] = list[i].children;
	child_ctx[15] = list[i].children_visible;
	child_ctx[16] = list[i].checked;
	child_ctx[17] = list;
	child_ctx[18] = i;
	return child_ctx;
}

// (45:4) {:else}
function create_else_block$1(ctx) {
	let span;

	return {
		c() {
			span = element$1("span");
			span.innerHTML = `<img src="${FileIcon}" alt="file icon" class="svelte-hyugph"/>`;
			attr$1(span, "class", "file-icon svelte-hyugph");
		},
		m(target, anchor) {
			insert$2(target, span, anchor);
		},
		p: noop,
		i: noop,
		o: noop,
		d(detaching) {
			if (detaching) {
				detach$2(span);
			}
		}
	};
}

// (31:4) {#if type === "folder"}
function create_if_block_1(ctx) {
	let span;
	let arrow;
	let current;
	let mounted;
	let dispose;
	arrow = new ArrowIcon({});

	function click_handler() {
		return /*click_handler*/ ctx[8](/*i*/ ctx[18]);
	}

	function keydown_handler(...args) {
		return /*keydown_handler*/ ctx[9](/*i*/ ctx[18], ...args);
	}

	return {
		c() {
			span = element$1("span");
			create_component$2(arrow.$$.fragment);
			attr$1(span, "class", "icon svelte-hyugph");
			attr$1(span, "role", "button");
			attr$1(span, "aria-label", "expand directory");
			attr$1(span, "tabindex", "0");
			toggle_class(span, "hidden", !/*tree*/ ctx[0][/*i*/ ctx[18]].children_visible);
		},
		m(target, anchor) {
			insert$2(target, span, anchor);
			mount_component$2(arrow, span, null);
			current = true;

			if (!mounted) {
				dispose = [
					listen(span, "click", stop_propagation(click_handler)),
					listen(span, "keydown", keydown_handler)
				];

				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;

			if (!current || dirty & /*tree*/ 1) {
				toggle_class(span, "hidden", !/*tree*/ ctx[0][/*i*/ ctx[18]].children_visible);
			}
		},
		i(local) {
			if (current) return;
			transition_in$2(arrow.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$2(arrow.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$2(span);
			}

			destroy_component$2(arrow);
			mounted = false;
			run_all(dispose);
		}
	};
}

// (52:3) {#if children && children_visible}
function create_if_block$1(ctx) {
	let filetree;
	let current;

	filetree = new FileTree({
			props: {
				tree: /*children*/ ctx[14],
				icons: /*icons*/ ctx[2],
				node_indices: [.../*node_indices*/ ctx[3], /*i*/ ctx[18]],
				interactive: /*interactive*/ ctx[1],
				file_count: /*file_count*/ ctx[4]
			}
		});

	filetree.$on("check", /*check_handler*/ ctx[10]);

	return {
		c() {
			create_component$2(filetree.$$.fragment);
		},
		m(target, anchor) {
			mount_component$2(filetree, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const filetree_changes = {};
			if (dirty & /*tree*/ 1) filetree_changes.tree = /*children*/ ctx[14];
			if (dirty & /*icons*/ 4) filetree_changes.icons = /*icons*/ ctx[2];
			if (dirty & /*node_indices*/ 8) filetree_changes.node_indices = [.../*node_indices*/ ctx[3], /*i*/ ctx[18]];
			if (dirty & /*interactive*/ 2) filetree_changes.interactive = /*interactive*/ ctx[1];
			if (dirty & /*file_count*/ 16) filetree_changes.file_count = /*file_count*/ ctx[4];
			filetree.$set(filetree_changes);
		},
		i(local) {
			if (current) return;
			transition_in$2(filetree.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$2(filetree.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component$2(filetree, detaching);
		}
	};
}

// (21:1) {#each tree as { type, path, children, children_visible, checked }
function create_each_block(ctx) {
	let li;
	let span;
	let checkbox;
	let updating_value;
	let t0;
	let current_block_type_index;
	let if_block0;
	let t1;
	let t2_value = /*path*/ ctx[13] + "";
	let t2;
	let t3;
	let t4;
	let current;

	function checkbox_value_binding(value) {
		/*checkbox_value_binding*/ ctx[6](value, /*checked*/ ctx[16], /*each_value*/ ctx[17], /*i*/ ctx[18]);
	}

	function change_handler() {
		return /*change_handler*/ ctx[7](/*i*/ ctx[18]);
	}

	let checkbox_props = {
		disabled: !/*interactive*/ ctx[1] || /*type*/ ctx[12] === "folder" && /*file_count*/ ctx[4] === "single"
	};

	if (/*checked*/ ctx[16] !== void 0) {
		checkbox_props.value = /*checked*/ ctx[16];
	}

	checkbox = new Checkbox({ props: checkbox_props });
	binding_callbacks$1.push(() => bind$1(checkbox, 'value', checkbox_value_binding));
	checkbox.$on("change", change_handler);
	const if_block_creators = [create_if_block_1, create_else_block$1];
	const if_blocks = [];

	function select_block_type(ctx, dirty) {
		if (/*type*/ ctx[12] === "folder") return 0;
		return 1;
	}

	current_block_type_index = select_block_type(ctx);
	if_block0 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
	let if_block1 = /*children*/ ctx[14] && /*children_visible*/ ctx[15] && create_if_block$1(ctx);

	return {
		c() {
			li = element$1("li");
			span = element$1("span");
			create_component$2(checkbox.$$.fragment);
			t0 = space$1();
			if_block0.c();
			t1 = space$1();
			t2 = text(t2_value);
			t3 = space$1();
			if (if_block1) if_block1.c();
			t4 = space$1();
			attr$1(span, "class", "wrap svelte-hyugph");
			attr$1(li, "class", "svelte-hyugph");
		},
		m(target, anchor) {
			insert$2(target, li, anchor);
			append(li, span);
			mount_component$2(checkbox, span, null);
			append(span, t0);
			if_blocks[current_block_type_index].m(span, null);
			append(span, t1);
			append(span, t2);
			append(li, t3);
			if (if_block1) if_block1.m(li, null);
			append(li, t4);
			current = true;
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			const checkbox_changes = {};
			if (dirty & /*interactive, tree, file_count*/ 19) checkbox_changes.disabled = !/*interactive*/ ctx[1] || /*type*/ ctx[12] === "folder" && /*file_count*/ ctx[4] === "single";

			if (!updating_value && dirty & /*tree*/ 1) {
				updating_value = true;
				checkbox_changes.value = /*checked*/ ctx[16];
				add_flush_callback$1(() => updating_value = false);
			}

			checkbox.$set(checkbox_changes);
			let previous_block_index = current_block_type_index;
			current_block_type_index = select_block_type(ctx);

			if (current_block_type_index === previous_block_index) {
				if_blocks[current_block_type_index].p(ctx, dirty);
			} else {
				group_outros$1();

				transition_out$2(if_blocks[previous_block_index], 1, 1, () => {
					if_blocks[previous_block_index] = null;
				});

				check_outros$1();
				if_block0 = if_blocks[current_block_type_index];

				if (!if_block0) {
					if_block0 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
					if_block0.c();
				} else {
					if_block0.p(ctx, dirty);
				}

				transition_in$2(if_block0, 1);
				if_block0.m(span, t1);
			}

			if ((!current || dirty & /*tree*/ 1) && t2_value !== (t2_value = /*path*/ ctx[13] + "")) set_data(t2, t2_value);

			if (/*children*/ ctx[14] && /*children_visible*/ ctx[15]) {
				if (if_block1) {
					if_block1.p(ctx, dirty);

					if (dirty & /*tree*/ 1) {
						transition_in$2(if_block1, 1);
					}
				} else {
					if_block1 = create_if_block$1(ctx);
					if_block1.c();
					transition_in$2(if_block1, 1);
					if_block1.m(li, t4);
				}
			} else if (if_block1) {
				group_outros$1();

				transition_out$2(if_block1, 1, 1, () => {
					if_block1 = null;
				});

				check_outros$1();
			}
		},
		i(local) {
			if (current) return;
			transition_in$2(checkbox.$$.fragment, local);
			transition_in$2(if_block0);
			transition_in$2(if_block1);
			current = true;
		},
		o(local) {
			transition_out$2(checkbox.$$.fragment, local);
			transition_out$2(if_block0);
			transition_out$2(if_block1);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$2(li);
			}

			destroy_component$2(checkbox);
			if_blocks[current_block_type_index].d();
			if (if_block1) if_block1.d();
		}
	};
}

function create_fragment$2(ctx) {
	let ul;
	let current;
	let each_value = ensure_array_like(/*tree*/ ctx[0]);
	let each_blocks = [];

	for (let i = 0; i < each_value.length; i += 1) {
		each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
	}

	const out = i => transition_out$2(each_blocks[i], 1, 1, () => {
		each_blocks[i] = null;
	});

	return {
		c() {
			ul = element$1("ul");

			for (let i = 0; i < each_blocks.length; i += 1) {
				each_blocks[i].c();
			}

			attr$1(ul, "class", "svelte-hyugph");
		},
		m(target, anchor) {
			insert$2(target, ul, anchor);

			for (let i = 0; i < each_blocks.length; i += 1) {
				if (each_blocks[i]) {
					each_blocks[i].m(ul, null);
				}
			}

			current = true;
		},
		p(ctx, [dirty]) {
			if (dirty & /*tree, icons, node_indices, interactive, file_count, dispatch_change*/ 63) {
				each_value = ensure_array_like(/*tree*/ ctx[0]);
				let i;

				for (i = 0; i < each_value.length; i += 1) {
					const child_ctx = get_each_context(ctx, each_value, i);

					if (each_blocks[i]) {
						each_blocks[i].p(child_ctx, dirty);
						transition_in$2(each_blocks[i], 1);
					} else {
						each_blocks[i] = create_each_block(child_ctx);
						each_blocks[i].c();
						transition_in$2(each_blocks[i], 1);
						each_blocks[i].m(ul, null);
					}
				}

				group_outros$1();

				for (i = each_value.length; i < each_blocks.length; i += 1) {
					out(i);
				}

				check_outros$1();
			}
		},
		i(local) {
			if (current) return;

			for (let i = 0; i < each_value.length; i += 1) {
				transition_in$2(each_blocks[i]);
			}

			current = true;
		},
		o(local) {
			each_blocks = each_blocks.filter(Boolean);

			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out$2(each_blocks[i]);
			}

			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$2(ul);
			}

			destroy_each(each_blocks, detaching);
		}
	};
}

function instance$2($$self, $$props, $$invalidate) {
	let { interactive } = $$props;
	let { tree = [] } = $$props;
	let { icons = {} } = $$props;
	let { node_indices = [] } = $$props;
	let { file_count = "multiple" } = $$props;
	const dispatch = createEventDispatcher$1();

	async function dispatch_change(i) {
		await tick();

		dispatch("check", {
			node_indices: [...node_indices, i],
			checked: !tree[i].checked
		});
	}

	function checkbox_value_binding(value, checked, each_value, i) {
		each_value[i].checked = value;
		$$invalidate(0, tree);
	}

	const change_handler = i => dispatch_change(i);
	const click_handler = i => $$invalidate(0, tree[i].children_visible = !tree[i].children_visible, tree);
	const keydown_handler = (i, { key }) => (key === " " || key === "Enter") && $$invalidate(0, tree[i].children_visible = !tree[i].children_visible, tree);

	function check_handler(event) {
		bubble.call(this, $$self, event);
	}

	$$self.$$set = $$props => {
		if ('interactive' in $$props) $$invalidate(1, interactive = $$props.interactive);
		if ('tree' in $$props) $$invalidate(0, tree = $$props.tree);
		if ('icons' in $$props) $$invalidate(2, icons = $$props.icons);
		if ('node_indices' in $$props) $$invalidate(3, node_indices = $$props.node_indices);
		if ('file_count' in $$props) $$invalidate(4, file_count = $$props.file_count);
	};

	return [
		tree,
		interactive,
		icons,
		node_indices,
		file_count,
		dispatch_change,
		checkbox_value_binding,
		change_handler,
		click_handler,
		keydown_handler,
		check_handler
	];
}

class FileTree extends SvelteComponent$2 {
	constructor(options) {
		super();

		init$2(this, options, instance$2, create_fragment$2, safe_not_equal$2, {
			interactive: 1,
			tree: 0,
			icons: 2,
			node_indices: 3,
			file_count: 4
		});
	}
}

const make_fs_store = () => {
  const { subscribe, set, update } = writable(null);
  let root = {
    type: "folder",
    path: "",
    checked: false,
    children_visible: false,
    parent: null
  };
  function create_fs_graph(serialised_node) {
    root.children = process_tree(serialised_node);
    set(root.children);
  }
  let old_checked_paths = [];
  function set_checked_from_paths(checked_paths) {
    if (dequal(checked_paths, old_checked_paths)) {
      return checked_paths;
    }
    old_checked_paths = checked_paths;
    check_node_and_children(root.children, false, []);
    const new_checked_paths = [];
    const seen_nodes = /* @__PURE__ */ new Set();
    for (let i = 0; i < checked_paths.length; i++) {
      let _node = root;
      let _path = [];
      for (let j = 0; j < checked_paths[i].length; j++) {
        if (!_node?.children) {
          continue;
        }
        _path.push(checked_paths[i][j]);
        _node = _node.children.find((v) => v.path === checked_paths[i][j]);
      }
      if (!_node) {
        continue;
      }
      _node.checked = true;
      ensure_visible(_node);
      const nodes = check_node_and_children(_node.children, true, [_node]);
      check_parent(_node);
      nodes.forEach((node) => {
        const path = get_full_path(node);
        if (seen_nodes.has(path.join("/"))) {
          return;
        }
        if (node.type === "file") {
          new_checked_paths.push(path);
        }
        seen_nodes.add(path.join("/"));
      });
    }
    set(root.children);
    return new_checked_paths;
  }
  function set_checked(indices, checked, checked_paths, file_count) {
    let _node = root;
    if (file_count === "single") {
      check_node_and_children(root.children, false, []);
      set(root.children);
    }
    for (let i = 0; i < indices.length; i++) {
      _node = _node.children[indices[i]];
    }
    _node.checked = checked;
    const nodes = check_node_and_children(_node.children, checked, [_node]);
    let new_checked_paths = new Map(checked_paths.map((v) => [v.join("/"), v]));
    for (let i = 0; i < nodes.length; i++) {
      const _path = get_full_path(nodes[i]);
      if (!checked) {
        new_checked_paths.delete(_path.join("/"));
      } else if (checked) {
        if (file_count === "single") {
          new_checked_paths = /* @__PURE__ */ new Map();
        }
        if (nodes[i].type === "file") {
          new_checked_paths.set(_path.join("/"), _path);
        }
      }
    }
    check_parent(_node);
    set(root.children);
    old_checked_paths = Array.from(new_checked_paths).map((v) => v[1]);
    return old_checked_paths;
  }
  return {
    subscribe,
    create_fs_graph,
    set_checked,
    set_checked_from_paths
  };
};
function ensure_visible(node) {
  if (node.parent) {
    node.parent.children_visible = true;
    ensure_visible(node.parent);
  }
}
function process_tree(node, depth = 0, path_segments = [], parent = null) {
  const folders = [];
  const files = [];
  for (let i = 0; i < node.length; i++) {
    let n = node[i];
    if (n.type === "file") {
      let index = files.findIndex(
        (v) => v.path.toLocaleLowerCase() >= n.path.toLocaleLowerCase()
      );
      const _node = {
        children: void 0,
        type: "file",
        path: n.path,
        checked: false,
        children_visible: false,
        parent
      };
      files.splice(index === -1 ? files.length : index, 0, _node);
    } else {
      let index = folders.findIndex(
        (v) => v.path.toLocaleLowerCase() >= n.path.toLocaleLowerCase()
      );
      const _node = {
        type: "folder",
        path: n.path,
        checked: false,
        children_visible: false,
        parent
      };
      const children = process_tree(
        n.children,
        depth + 1,
        [...path_segments, n.path],
        _node
      );
      _node.children = children;
      folders.splice(index === -1 ? folders.length : index, 0, _node);
    }
  }
  const last = files[files.length - 1] || folders[folders.length - 1];
  for (let i = 0; i < folders.length; i++) {
    folders[i].last = last;
    folders[i].previous = folders[i - 1] || null;
  }
  for (let i = 0; i < files.length; i++) {
    if (i === 0) {
      files[i].previous = folders[folders.length - 1] || null;
    } else {
      files[i].previous = files[i - 1] || null;
    }
    files[i].last = last;
  }
  return Array().concat(folders, files);
}
function get_full_path(node, path = []) {
  const new_path = [node.path, ...path];
  if (node.parent) {
    return get_full_path(node.parent, new_path);
  }
  return new_path;
}
function check_node_and_children(node, checked, checked_nodes) {
  if (node === null || node === void 0)
    return checked_nodes;
  for (let i = 0; i < node.length; i++) {
    node[i].checked = checked;
    checked_nodes.push(node[i]);
    if (checked)
      ensure_visible(node[i]);
    checked_nodes.concat(
      check_node_and_children(node[i].children, checked, checked_nodes)
    );
  }
  return checked_nodes;
}
function check_parent(node) {
  if (node === null || node === void 0 || !node.parent)
    return;
  let _node = node.last;
  let nodes_checked = [];
  while (_node) {
    nodes_checked.push(_node.checked);
    _node = _node.previous;
  }
  if (nodes_checked.every((v) => v === true)) {
    node.parent.checked = true;
    check_parent(node?.parent);
  } else if (nodes_checked.some((v) => v === false)) {
    node.parent.checked = false;
    check_parent(node?.parent);
  }
}

const DirectoryExplorer_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/fileexplorer/shared/DirectoryExplorer.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$1,
	attr,
	check_outros,
	component_subscribe,
	create_component: create_component$1,
	destroy_component: destroy_component$1,
	detach: detach$1,
	element,
	empty,
	group_outros,
	init: init$1,
	insert: insert$1,
	mount_component: mount_component$1,
	safe_not_equal: safe_not_equal$1,
	transition_in: transition_in$1,
	transition_out: transition_out$1
} = window.__gradio__svelte__internal;
const { createEventDispatcher } = window.__gradio__svelte__internal;
function create_else_block(ctx) {
	let empty_1;
	let current;

	empty_1 = new Empty({
			props: {
				size: "large",
				$$slots: { default: [create_default_slot$1] },
				$$scope: { ctx }
			}
		});

	return {
		c() {
			create_component$1(empty_1.$$.fragment);
		},
		m(target, anchor) {
			mount_component$1(empty_1, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const empty_1_changes = {};

			if (dirty & /*$$scope*/ 2048) {
				empty_1_changes.$$scope = { dirty, ctx };
			}

			empty_1.$set(empty_1_changes);
		},
		i(local) {
			if (current) return;
			transition_in$1(empty_1.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(empty_1.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component$1(empty_1, detaching);
		}
	};
}

// (35:0) {#if $tree && $tree.length}
function create_if_block(ctx) {
	let div;
	let filetree;
	let current;

	filetree = new FileTree({
			props: {
				tree: /*$tree*/ ctx[2],
				interactive: /*interactive*/ ctx[0],
				file_count: /*file_count*/ ctx[1]
			}
		});

	filetree.$on("check", /*check_handler*/ ctx[7]);

	return {
		c() {
			div = element("div");
			create_component$1(filetree.$$.fragment);
			attr(div, "class", "file-wrap svelte-dicskc");
		},
		m(target, anchor) {
			insert$1(target, div, anchor);
			mount_component$1(filetree, div, null);
			current = true;
		},
		p(ctx, dirty) {
			const filetree_changes = {};
			if (dirty & /*$tree*/ 4) filetree_changes.tree = /*$tree*/ ctx[2];
			if (dirty & /*interactive*/ 1) filetree_changes.interactive = /*interactive*/ ctx[0];
			if (dirty & /*file_count*/ 2) filetree_changes.file_count = /*file_count*/ ctx[1];
			filetree.$set(filetree_changes);
		},
		i(local) {
			if (current) return;
			transition_in$1(filetree.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(filetree.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(div);
			}

			destroy_component$1(filetree);
		}
	};
}

// (45:1) <Empty size="large">
function create_default_slot$1(ctx) {
	let file;
	let current;
	file = new File({});

	return {
		c() {
			create_component$1(file.$$.fragment);
		},
		m(target, anchor) {
			mount_component$1(file, target, anchor);
			current = true;
		},
		i(local) {
			if (current) return;
			transition_in$1(file.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(file.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component$1(file, detaching);
		}
	};
}

function create_fragment$1(ctx) {
	let current_block_type_index;
	let if_block;
	let if_block_anchor;
	let current;
	const if_block_creators = [create_if_block, create_else_block];
	const if_blocks = [];

	function select_block_type(ctx, dirty) {
		if (/*$tree*/ ctx[2] && /*$tree*/ ctx[2].length) return 0;
		return 1;
	}

	current_block_type_index = select_block_type(ctx);
	if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);

	return {
		c() {
			if_block.c();
			if_block_anchor = empty();
		},
		m(target, anchor) {
			if_blocks[current_block_type_index].m(target, anchor);
			insert$1(target, if_block_anchor, anchor);
			current = true;
		},
		p(ctx, [dirty]) {
			let previous_block_index = current_block_type_index;
			current_block_type_index = select_block_type(ctx);

			if (current_block_type_index === previous_block_index) {
				if_blocks[current_block_type_index].p(ctx, dirty);
			} else {
				group_outros();

				transition_out$1(if_blocks[previous_block_index], 1, 1, () => {
					if_blocks[previous_block_index] = null;
				});

				check_outros();
				if_block = if_blocks[current_block_type_index];

				if (!if_block) {
					if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
					if_block.c();
				} else {
					if_block.p(ctx, dirty);
				}

				transition_in$1(if_block, 1);
				if_block.m(if_block_anchor.parentNode, if_block_anchor);
			}
		},
		i(local) {
			if (current) return;
			transition_in$1(if_block);
			current = true;
		},
		o(local) {
			transition_out$1(if_block);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(if_block_anchor);
			}

			if_blocks[current_block_type_index].d(detaching);
		}
	};
}

function instance$1($$self, $$props, $$invalidate) {
	let $tree;
	let { interactive } = $$props;
	let { server } = $$props;
	let { file_count = "multiple" } = $$props;
	let { value = [] } = $$props;
	const dispatch = createEventDispatcher();
	const tree = make_fs_store();
	component_subscribe($$self, tree, value => $$invalidate(2, $tree = value));

	server.ls().then(v => {
		tree.create_fs_graph(v);
	});

	function set_checked_from_paths() {
		$$invalidate(5, value = file_count === "single" ? [value[0] || []] : value);
		$$invalidate(5, value = tree.set_checked_from_paths(value));

		if (!dequal(value, old_value)) {
			old_value = value;
			dispatch("change", value);
		}
	}

	let old_value = [];

	function handle_select({ node_indices, checked }) {
		$$invalidate(5, value = tree.set_checked(node_indices, checked, value, file_count));

		if (!dequal(value, old_value)) {
			old_value = value;
			dispatch("change", value);
		}
	}

	const check_handler = ({ detail }) => handle_select(detail);

	$$self.$$set = $$props => {
		if ('interactive' in $$props) $$invalidate(0, interactive = $$props.interactive);
		if ('server' in $$props) $$invalidate(6, server = $$props.server);
		if ('file_count' in $$props) $$invalidate(1, file_count = $$props.file_count);
		if ('value' in $$props) $$invalidate(5, value = $$props.value);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty & /*value, $tree*/ 36) {
			value.length && $tree && set_checked_from_paths();
		}
	};

	return [
		interactive,
		file_count,
		$tree,
		tree,
		handle_select,
		value,
		server,
		check_handler
	];
}

class DirectoryExplorer extends SvelteComponent$1 {
	constructor(options) {
		super();

		init$1(this, options, instance$1, create_fragment$1, safe_not_equal$1, {
			interactive: 0,
			server: 6,
			file_count: 1,
			value: 5
		});
	}
}

/* home/runner/work/gradio/gradio/js/fileexplorer/Index.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent,
	add_flush_callback,
	assign,
	bind,
	binding_callbacks,
	create_component,
	destroy_component,
	detach,
	flush,
	get_spread_object,
	get_spread_update,
	init,
	insert,
	mount_component,
	safe_not_equal,
	space,
	transition_in,
	transition_out
} = window.__gradio__svelte__internal;
function create_default_slot(ctx) {
	let statustracker;
	let t0;
	let blocklabel;
	let t1;
	let directoryexplorer;
	let updating_value;
	let current;

	const statustracker_spread_levels = [
		/*loading_status*/ ctx[8],
		{
			autoscroll: /*gradio*/ ctx[12].autoscroll
		},
		{ i18n: /*gradio*/ ctx[12].i18n }
	];

	let statustracker_props = {};

	for (let i = 0; i < statustracker_spread_levels.length; i += 1) {
		statustracker_props = assign(statustracker_props, statustracker_spread_levels[i]);
	}

	statustracker = new Static({ props: statustracker_props });

	blocklabel = new BlockLabel({
			props: {
				show_label: /*show_label*/ ctx[5],
				Icon: File,
				label: /*label*/ ctx[4] || "FileExplorer",
				float: false
			}
		});

	function directoryexplorer_value_binding(value) {
		/*directoryexplorer_value_binding*/ ctx[15](value);
	}

	let directoryexplorer_props = {
		file_count: /*file_count*/ ctx[7],
		server: /*server*/ ctx[13],
		interactive: /*interactive*/ ctx[14]
	};

	if (/*value*/ ctx[0] !== void 0) {
		directoryexplorer_props.value = /*value*/ ctx[0];
	}

	directoryexplorer = new DirectoryExplorer({ props: directoryexplorer_props });
	binding_callbacks.push(() => bind(directoryexplorer, 'value', directoryexplorer_value_binding));
	directoryexplorer.$on("change", /*change_handler*/ ctx[16]);

	return {
		c() {
			create_component(statustracker.$$.fragment);
			t0 = space();
			create_component(blocklabel.$$.fragment);
			t1 = space();
			create_component(directoryexplorer.$$.fragment);
		},
		m(target, anchor) {
			mount_component(statustracker, target, anchor);
			insert(target, t0, anchor);
			mount_component(blocklabel, target, anchor);
			insert(target, t1, anchor);
			mount_component(directoryexplorer, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const statustracker_changes = (dirty & /*loading_status, gradio*/ 4352)
			? get_spread_update(statustracker_spread_levels, [
					dirty & /*loading_status*/ 256 && get_spread_object(/*loading_status*/ ctx[8]),
					dirty & /*gradio*/ 4096 && {
						autoscroll: /*gradio*/ ctx[12].autoscroll
					},
					dirty & /*gradio*/ 4096 && { i18n: /*gradio*/ ctx[12].i18n }
				])
			: {};

			statustracker.$set(statustracker_changes);
			const blocklabel_changes = {};
			if (dirty & /*show_label*/ 32) blocklabel_changes.show_label = /*show_label*/ ctx[5];
			if (dirty & /*label*/ 16) blocklabel_changes.label = /*label*/ ctx[4] || "FileExplorer";
			blocklabel.$set(blocklabel_changes);
			const directoryexplorer_changes = {};
			if (dirty & /*file_count*/ 128) directoryexplorer_changes.file_count = /*file_count*/ ctx[7];
			if (dirty & /*server*/ 8192) directoryexplorer_changes.server = /*server*/ ctx[13];
			if (dirty & /*interactive*/ 16384) directoryexplorer_changes.interactive = /*interactive*/ ctx[14];

			if (!updating_value && dirty & /*value*/ 1) {
				updating_value = true;
				directoryexplorer_changes.value = /*value*/ ctx[0];
				add_flush_callback(() => updating_value = false);
			}

			directoryexplorer.$set(directoryexplorer_changes);
		},
		i(local) {
			if (current) return;
			transition_in(statustracker.$$.fragment, local);
			transition_in(blocklabel.$$.fragment, local);
			transition_in(directoryexplorer.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(statustracker.$$.fragment, local);
			transition_out(blocklabel.$$.fragment, local);
			transition_out(directoryexplorer.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(t0);
				detach(t1);
			}

			destroy_component(statustracker, detaching);
			destroy_component(blocklabel, detaching);
			destroy_component(directoryexplorer, detaching);
		}
	};
}

function create_fragment(ctx) {
	let block;
	let current;

	block = new Block({
			props: {
				visible: /*visible*/ ctx[3],
				variant: /*value*/ ctx[0] === null ? "dashed" : "solid",
				border_mode: "base",
				padding: false,
				elem_id: /*elem_id*/ ctx[1],
				elem_classes: /*elem_classes*/ ctx[2],
				container: /*container*/ ctx[9],
				scale: /*scale*/ ctx[10],
				min_width: /*min_width*/ ctx[11],
				allow_overflow: false,
				height: /*height*/ ctx[6],
				$$slots: { default: [create_default_slot] },
				$$scope: { ctx }
			}
		});

	return {
		c() {
			create_component(block.$$.fragment);
		},
		m(target, anchor) {
			mount_component(block, target, anchor);
			current = true;
		},
		p(ctx, [dirty]) {
			const block_changes = {};
			if (dirty & /*visible*/ 8) block_changes.visible = /*visible*/ ctx[3];
			if (dirty & /*value*/ 1) block_changes.variant = /*value*/ ctx[0] === null ? "dashed" : "solid";
			if (dirty & /*elem_id*/ 2) block_changes.elem_id = /*elem_id*/ ctx[1];
			if (dirty & /*elem_classes*/ 4) block_changes.elem_classes = /*elem_classes*/ ctx[2];
			if (dirty & /*container*/ 512) block_changes.container = /*container*/ ctx[9];
			if (dirty & /*scale*/ 1024) block_changes.scale = /*scale*/ ctx[10];
			if (dirty & /*min_width*/ 2048) block_changes.min_width = /*min_width*/ ctx[11];
			if (dirty & /*height*/ 64) block_changes.height = /*height*/ ctx[6];

			if (dirty & /*$$scope, file_count, server, interactive, value, gradio, show_label, label, loading_status*/ 160177) {
				block_changes.$$scope = { dirty, ctx };
			}

			block.$set(block_changes);
		},
		i(local) {
			if (current) return;
			transition_in(block.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(block.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component(block, detaching);
		}
	};
}

function instance($$self, $$props, $$invalidate) {
	let { elem_id = "" } = $$props;
	let { elem_classes = [] } = $$props;
	let { visible = true } = $$props;
	let { value } = $$props;
	let { label } = $$props;
	let { show_label } = $$props;
	let { height = undefined } = $$props;
	let { file_count = "multiple" } = $$props;
	let { loading_status } = $$props;
	let { container = true } = $$props;
	let { scale = null } = $$props;
	let { min_width = undefined } = $$props;
	let { gradio } = $$props;
	let { server } = $$props;
	let { interactive } = $$props;

	function directoryexplorer_value_binding(value$1) {
		value = value$1;
		$$invalidate(0, value);
	}

	const change_handler = () => gradio.dispatch("change");

	$$self.$$set = $$props => {
		if ('elem_id' in $$props) $$invalidate(1, elem_id = $$props.elem_id);
		if ('elem_classes' in $$props) $$invalidate(2, elem_classes = $$props.elem_classes);
		if ('visible' in $$props) $$invalidate(3, visible = $$props.visible);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('label' in $$props) $$invalidate(4, label = $$props.label);
		if ('show_label' in $$props) $$invalidate(5, show_label = $$props.show_label);
		if ('height' in $$props) $$invalidate(6, height = $$props.height);
		if ('file_count' in $$props) $$invalidate(7, file_count = $$props.file_count);
		if ('loading_status' in $$props) $$invalidate(8, loading_status = $$props.loading_status);
		if ('container' in $$props) $$invalidate(9, container = $$props.container);
		if ('scale' in $$props) $$invalidate(10, scale = $$props.scale);
		if ('min_width' in $$props) $$invalidate(11, min_width = $$props.min_width);
		if ('gradio' in $$props) $$invalidate(12, gradio = $$props.gradio);
		if ('server' in $$props) $$invalidate(13, server = $$props.server);
		if ('interactive' in $$props) $$invalidate(14, interactive = $$props.interactive);
	};

	return [
		value,
		elem_id,
		elem_classes,
		visible,
		label,
		show_label,
		height,
		file_count,
		loading_status,
		container,
		scale,
		min_width,
		gradio,
		server,
		interactive,
		directoryexplorer_value_binding,
		change_handler
	];
}

class Index extends SvelteComponent {
	constructor(options) {
		super();

		init(this, options, instance, create_fragment, safe_not_equal, {
			elem_id: 1,
			elem_classes: 2,
			visible: 3,
			value: 0,
			label: 4,
			show_label: 5,
			height: 6,
			file_count: 7,
			loading_status: 8,
			container: 9,
			scale: 10,
			min_width: 11,
			gradio: 12,
			server: 13,
			interactive: 14
		});
	}

	get elem_id() {
		return this.$$.ctx[1];
	}

	set elem_id(elem_id) {
		this.$$set({ elem_id });
		flush();
	}

	get elem_classes() {
		return this.$$.ctx[2];
	}

	set elem_classes(elem_classes) {
		this.$$set({ elem_classes });
		flush();
	}

	get visible() {
		return this.$$.ctx[3];
	}

	set visible(visible) {
		this.$$set({ visible });
		flush();
	}

	get value() {
		return this.$$.ctx[0];
	}

	set value(value) {
		this.$$set({ value });
		flush();
	}

	get label() {
		return this.$$.ctx[4];
	}

	set label(label) {
		this.$$set({ label });
		flush();
	}

	get show_label() {
		return this.$$.ctx[5];
	}

	set show_label(show_label) {
		this.$$set({ show_label });
		flush();
	}

	get height() {
		return this.$$.ctx[6];
	}

	set height(height) {
		this.$$set({ height });
		flush();
	}

	get file_count() {
		return this.$$.ctx[7];
	}

	set file_count(file_count) {
		this.$$set({ file_count });
		flush();
	}

	get loading_status() {
		return this.$$.ctx[8];
	}

	set loading_status(loading_status) {
		this.$$set({ loading_status });
		flush();
	}

	get container() {
		return this.$$.ctx[9];
	}

	set container(container) {
		this.$$set({ container });
		flush();
	}

	get scale() {
		return this.$$.ctx[10];
	}

	set scale(scale) {
		this.$$set({ scale });
		flush();
	}

	get min_width() {
		return this.$$.ctx[11];
	}

	set min_width(min_width) {
		this.$$set({ min_width });
		flush();
	}

	get gradio() {
		return this.$$.ctx[12];
	}

	set gradio(gradio) {
		this.$$set({ gradio });
		flush();
	}

	get server() {
		return this.$$.ctx[13];
	}

	set server(server) {
		this.$$set({ server });
		flush();
	}

	get interactive() {
		return this.$$.ctx[14];
	}

	set interactive(interactive) {
		this.$$set({ interactive });
		flush();
	}
}

export { Index as default };
//# sourceMappingURL=Index-8cb2750c.js.map
