import { a as Button, B as Block } from './Button-723db480.js';
import { S as Static } from './Index-f62c49f9.js';
import { d as dequal } from './index-21d69e4c.js';
import { c as copy } from './utils-8f25e669.js';
import { U as Upload } from './Upload-8319436b.js';
/* empty css                                                     */import './Index.svelte_svelte_type_style_lang-03d7f969.js';
import { M as MarkdownCode } from './Example.svelte_svelte_type_style_lang-1f3550e5.js';
import { d as dsvFormat } from './dsv-a37bb3db.js';
export { default as BaseExample } from './Example-7d6bb9b6.js';
import './index-b5b16a51.js';
import './svelte/svelte.js';

const EditableCell_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/dataframe/shared/EditableCell.svelte generated by Svelte v4.2.2 */
const {
	HtmlTag,
	SvelteComponent: SvelteComponent$3,
	action_destroyer: action_destroyer$1,
	attr: attr$2,
	binding_callbacks: binding_callbacks$2,
	bubble,
	check_outros: check_outros$2,
	create_component: create_component$2,
	destroy_component: destroy_component$2,
	detach: detach$3,
	element: element$2,
	empty: empty$2,
	group_outros: group_outros$2,
	init: init$3,
	insert: insert$3,
	listen: listen$2,
	mount_component: mount_component$2,
	noop,
	prevent_default,
	run_all: run_all$1,
	safe_not_equal: safe_not_equal$3,
	set_data: set_data$1,
	set_input_value,
	space: space$3,
	text: text$2,
	toggle_class: toggle_class$1,
	transition_in: transition_in$3,
	transition_out: transition_out$3
} = window.__gradio__svelte__internal;
const { createEventDispatcher: createEventDispatcher$1 } = window.__gradio__svelte__internal;
function create_if_block_2$1(ctx) {
	let input;
	let mounted;
	let dispose;

	return {
		c() {
			input = element$2("input");
			attr$2(input, "tabindex", "-1");
			attr$2(input, "class", "svelte-q8uklq");
			toggle_class$1(input, "header", /*header*/ ctx[5]);
		},
		m(target, anchor) {
			insert$3(target, input, anchor);
			/*input_binding*/ ctx[18](input);
			set_input_value(input, /*_value*/ ctx[10]);

			if (!mounted) {
				dispose = [
					listen$2(input, "input", /*input_input_handler*/ ctx[19]),
					listen$2(input, "blur", /*handle_blur*/ ctx[12]),
					action_destroyer$1(/*use_focus*/ ctx[11].call(null, input)),
					listen$2(input, "keydown", /*keydown_handler*/ ctx[17])
				];

				mounted = true;
			}
		},
		p(ctx, dirty) {
			if (dirty & /*_value*/ 1024 && input.value !== /*_value*/ ctx[10]) {
				set_input_value(input, /*_value*/ ctx[10]);
			}

			if (dirty & /*header*/ 32) {
				toggle_class$1(input, "header", /*header*/ ctx[5]);
			}
		},
		d(detaching) {
			if (detaching) {
				detach$3(input);
			}

			/*input_binding*/ ctx[18](null);
			mounted = false;
			run_all$1(dispose);
		}
	};
}

// (62:1) {:else}
function create_else_block(ctx) {
	let t_value = (/*editable*/ ctx[9]
	? /*value*/ ctx[0]
	: /*display_value*/ ctx[3] || /*value*/ ctx[0]) + "";

	let t;

	return {
		c() {
			t = text$2(t_value);
		},
		m(target, anchor) {
			insert$3(target, t, anchor);
		},
		p(ctx, dirty) {
			if (dirty & /*editable, value, display_value*/ 521 && t_value !== (t_value = (/*editable*/ ctx[9]
			? /*value*/ ctx[0]
			: /*display_value*/ ctx[3] || /*value*/ ctx[0]) + "")) set_data$1(t, t_value);
		},
		i: noop,
		o: noop,
		d(detaching) {
			if (detaching) {
				detach$3(t);
			}
		}
	};
}

// (55:35) 
function create_if_block_1$1(ctx) {
	let markdowncode;
	let current;

	markdowncode = new MarkdownCode({
			props: {
				message: /*value*/ ctx[0].toLocaleString(),
				latex_delimiters: /*latex_delimiters*/ ctx[7],
				line_breaks: /*line_breaks*/ ctx[8],
				chatbot: false
			}
		});

	return {
		c() {
			create_component$2(markdowncode.$$.fragment);
		},
		m(target, anchor) {
			mount_component$2(markdowncode, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const markdowncode_changes = {};
			if (dirty & /*value*/ 1) markdowncode_changes.message = /*value*/ ctx[0].toLocaleString();
			if (dirty & /*latex_delimiters*/ 128) markdowncode_changes.latex_delimiters = /*latex_delimiters*/ ctx[7];
			if (dirty & /*line_breaks*/ 256) markdowncode_changes.line_breaks = /*line_breaks*/ ctx[8];
			markdowncode.$set(markdowncode_changes);
		},
		i(local) {
			if (current) return;
			transition_in$3(markdowncode.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$3(markdowncode.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component$2(markdowncode, detaching);
		}
	};
}

// (53:1) {#if datatype === "html"}
function create_if_block$2(ctx) {
	let html_tag;
	let html_anchor;

	return {
		c() {
			html_tag = new HtmlTag(false);
			html_anchor = empty$2();
			html_tag.a = html_anchor;
		},
		m(target, anchor) {
			html_tag.m(/*value*/ ctx[0], target, anchor);
			insert$3(target, html_anchor, anchor);
		},
		p(ctx, dirty) {
			if (dirty & /*value*/ 1) html_tag.p(/*value*/ ctx[0]);
		},
		i: noop,
		o: noop,
		d(detaching) {
			if (detaching) {
				detach$3(html_anchor);
				html_tag.d();
			}
		}
	};
}

function create_fragment$3(ctx) {
	let t;
	let span;
	let current_block_type_index;
	let if_block1;
	let current;
	let mounted;
	let dispose;
	let if_block0 = /*edit*/ ctx[2] && create_if_block_2$1(ctx);
	const if_block_creators = [create_if_block$2, create_if_block_1$1, create_else_block];
	const if_blocks = [];

	function select_block_type(ctx, dirty) {
		if (/*datatype*/ ctx[6] === "html") return 0;
		if (/*datatype*/ ctx[6] === "markdown") return 1;
		return 2;
	}

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

	return {
		c() {
			if (if_block0) if_block0.c();
			t = space$3();
			span = element$2("span");
			if_block1.c();
			attr$2(span, "tabindex", "-1");
			attr$2(span, "role", "button");
			attr$2(span, "style", /*styling*/ ctx[4]);
			attr$2(span, "class", "svelte-q8uklq");
			toggle_class$1(span, "edit", /*edit*/ ctx[2]);
		},
		m(target, anchor) {
			if (if_block0) if_block0.m(target, anchor);
			insert$3(target, t, anchor);
			insert$3(target, span, anchor);
			if_blocks[current_block_type_index].m(span, null);
			current = true;

			if (!mounted) {
				dispose = [
					listen$2(span, "dblclick", /*dblclick_handler*/ ctx[15]),
					listen$2(span, "focus", prevent_default(/*focus_handler*/ ctx[16]))
				];

				mounted = true;
			}
		},
		p(ctx, [dirty]) {
			if (/*edit*/ ctx[2]) {
				if (if_block0) {
					if_block0.p(ctx, dirty);
				} else {
					if_block0 = create_if_block_2$1(ctx);
					if_block0.c();
					if_block0.m(t.parentNode, t);
				}
			} else if (if_block0) {
				if_block0.d(1);
				if_block0 = null;
			}

			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$2();

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

				check_outros$2();
				if_block1 = if_blocks[current_block_type_index];

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

				transition_in$3(if_block1, 1);
				if_block1.m(span, null);
			}

			if (!current || dirty & /*styling*/ 16) {
				attr$2(span, "style", /*styling*/ ctx[4]);
			}

			if (!current || dirty & /*edit*/ 4) {
				toggle_class$1(span, "edit", /*edit*/ ctx[2]);
			}
		},
		i(local) {
			if (current) return;
			transition_in$3(if_block1);
			current = true;
		},
		o(local) {
			transition_out$3(if_block1);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$3(t);
				detach$3(span);
			}

			if (if_block0) if_block0.d(detaching);
			if_blocks[current_block_type_index].d();
			mounted = false;
			run_all$1(dispose);
		}
	};
}

function instance$3($$self, $$props, $$invalidate) {
	let _value;
	let { edit } = $$props;
	let { value = "" } = $$props;
	let { display_value = null } = $$props;
	let { styling = "" } = $$props;
	let { header = false } = $$props;
	let { datatype = "str" } = $$props;
	let { latex_delimiters } = $$props;
	let { clear_on_focus = false } = $$props;
	let { select_on_focus = false } = $$props;
	let { line_breaks = true } = $$props;
	let { editable = true } = $$props;
	const dispatch = createEventDispatcher$1();
	let { el } = $$props;

	function use_focus(node) {
		if (clear_on_focus) {
			$$invalidate(10, _value = "");
		}

		if (select_on_focus) {
			node.select();
		}

		node.focus();
		return {};
	}

	function handle_blur({ currentTarget }) {
		$$invalidate(0, value = currentTarget.value);
		dispatch("blur");
	}

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

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

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

	function input_binding($$value) {
		binding_callbacks$2[$$value ? 'unshift' : 'push'](() => {
			el = $$value;
			$$invalidate(1, el);
		});
	}

	function input_input_handler() {
		_value = this.value;
		($$invalidate(10, _value), $$invalidate(0, value));
	}

	$$self.$$set = $$props => {
		if ('edit' in $$props) $$invalidate(2, edit = $$props.edit);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('display_value' in $$props) $$invalidate(3, display_value = $$props.display_value);
		if ('styling' in $$props) $$invalidate(4, styling = $$props.styling);
		if ('header' in $$props) $$invalidate(5, header = $$props.header);
		if ('datatype' in $$props) $$invalidate(6, datatype = $$props.datatype);
		if ('latex_delimiters' in $$props) $$invalidate(7, latex_delimiters = $$props.latex_delimiters);
		if ('clear_on_focus' in $$props) $$invalidate(13, clear_on_focus = $$props.clear_on_focus);
		if ('select_on_focus' in $$props) $$invalidate(14, select_on_focus = $$props.select_on_focus);
		if ('line_breaks' in $$props) $$invalidate(8, line_breaks = $$props.line_breaks);
		if ('editable' in $$props) $$invalidate(9, editable = $$props.editable);
		if ('el' in $$props) $$invalidate(1, el = $$props.el);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty & /*value*/ 1) {
			$$invalidate(10, _value = value);
		}
	};

	return [
		value,
		el,
		edit,
		display_value,
		styling,
		header,
		datatype,
		latex_delimiters,
		line_breaks,
		editable,
		_value,
		use_focus,
		handle_blur,
		clear_on_focus,
		select_on_focus,
		dblclick_handler,
		focus_handler,
		keydown_handler,
		input_binding,
		input_input_handler
	];
}

class EditableCell extends SvelteComponent$3 {
	constructor(options) {
		super();

		init$3(this, options, instance$3, create_fragment$3, safe_not_equal$3, {
			edit: 2,
			value: 0,
			display_value: 3,
			styling: 4,
			header: 5,
			datatype: 6,
			latex_delimiters: 7,
			clear_on_focus: 13,
			select_on_focus: 14,
			line_breaks: 8,
			editable: 9,
			el: 1
		});
	}
}

const VirtualTable_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/dataframe/shared/VirtualTable.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$2,
	add_iframe_resize_listener: add_iframe_resize_listener$1,
	add_render_callback: add_render_callback$1,
	append: append$1,
	attr: attr$1,
	binding_callbacks: binding_callbacks$1,
	check_outros: check_outros$1,
	create_slot,
	detach: detach$2,
	element: element$1,
	empty: empty$1,
	ensure_array_like: ensure_array_like$1,
	get_all_dirty_from_scope,
	get_slot_changes,
	group_outros: group_outros$1,
	init: init$2,
	insert: insert$2,
	listen: listen$1,
	outro_and_destroy_block: outro_and_destroy_block$1,
	safe_not_equal: safe_not_equal$2,
	set_style: set_style$1,
	space: space$2,
	text: text$1,
	transition_in: transition_in$2,
	transition_out: transition_out$2,
	update_keyed_each: update_keyed_each$1,
	update_slot_base
} = window.__gradio__svelte__internal;
const { onMount: onMount$1, tick: tick$1 } = window.__gradio__svelte__internal;const get_tfoot_slot_changes = dirty => ({});
const get_tfoot_slot_context = ctx => ({});

function get_each_context$1(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[34] = list[i];
	return child_ctx;
}

const get_tbody_slot_changes = dirty => ({
	item: dirty[0] & /*visible*/ 256,
	index: dirty[0] & /*visible*/ 256
});

const get_tbody_slot_context = ctx => ({
	item: /*item*/ ctx[34].data,
	index: /*item*/ ctx[34].index
});

const get_thead_slot_changes = dirty => ({});
const get_thead_slot_context = ctx => ({});

// (217:3) {#if visible.length && visible[0].data.length}
function create_if_block$1(ctx) {
	let each_blocks = [];
	let each_1_lookup = new Map();
	let each_1_anchor;
	let current;
	let each_value = ensure_array_like$1(/*visible*/ ctx[8]);
	const get_key = ctx => /*item*/ ctx[34].data[0].id;

	for (let i = 0; i < each_value.length; i += 1) {
		let child_ctx = get_each_context$1(ctx, each_value, i);
		let key = get_key(child_ctx);
		each_1_lookup.set(key, each_blocks[i] = create_each_block$1(key, child_ctx));
	}

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

			each_1_anchor = empty$1();
		},
		m(target, anchor) {
			for (let i = 0; i < each_blocks.length; i += 1) {
				if (each_blocks[i]) {
					each_blocks[i].m(target, anchor);
				}
			}

			insert$2(target, each_1_anchor, anchor);
			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*$$scope, visible*/ 2097408) {
				each_value = ensure_array_like$1(/*visible*/ ctx[8]);
				group_outros$1();
				each_blocks = update_keyed_each$1(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, outro_and_destroy_block$1, create_each_block$1, each_1_anchor, get_each_context$1);
				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) {
			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out$2(each_blocks[i]);
			}

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

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

// (219:60)        Missing Table Row      
function fallback_block(ctx) {
	let t;

	return {
		c() {
			t = text$1("Missing Table Row\n\t\t\t\t\t");
		},
		m(target, anchor) {
			insert$2(target, t, anchor);
		},
		d(detaching) {
			if (detaching) {
				detach$2(t);
			}
		}
	};
}

// (218:4) {#each visible as item (item.data[0].id)}
function create_each_block$1(key_1, ctx) {
	let first;
	let current;
	const tbody_slot_template = /*#slots*/ ctx[22].tbody;
	const tbody_slot = create_slot(tbody_slot_template, ctx, /*$$scope*/ ctx[21], get_tbody_slot_context);
	const tbody_slot_or_fallback = tbody_slot || fallback_block();

	return {
		key: key_1,
		first: null,
		c() {
			first = empty$1();
			if (tbody_slot_or_fallback) tbody_slot_or_fallback.c();
			this.first = first;
		},
		m(target, anchor) {
			insert$2(target, first, anchor);

			if (tbody_slot_or_fallback) {
				tbody_slot_or_fallback.m(target, anchor);
			}

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

			if (tbody_slot) {
				if (tbody_slot.p && (!current || dirty[0] & /*$$scope, visible*/ 2097408)) {
					update_slot_base(
						tbody_slot,
						tbody_slot_template,
						ctx,
						/*$$scope*/ ctx[21],
						!current
						? get_all_dirty_from_scope(/*$$scope*/ ctx[21])
						: get_slot_changes(tbody_slot_template, /*$$scope*/ ctx[21], dirty, get_tbody_slot_changes),
						get_tbody_slot_context
					);
				}
			}
		},
		i(local) {
			if (current) return;
			transition_in$2(tbody_slot_or_fallback, local);
			current = true;
		},
		o(local) {
			transition_out$2(tbody_slot_or_fallback, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$2(first);
			}

			if (tbody_slot_or_fallback) tbody_slot_or_fallback.d(detaching);
		}
	};
}

function create_fragment$2(ctx) {
	let svelte_virtual_table_viewport;
	let table;
	let thead;
	let thead_resize_listener;
	let t0;
	let tbody;
	let t1;
	let tfoot;
	let tfoot_resize_listener;
	let table_resize_listener;
	let current;
	let mounted;
	let dispose;
	const thead_slot_template = /*#slots*/ ctx[22].thead;
	const thead_slot = create_slot(thead_slot_template, ctx, /*$$scope*/ ctx[21], get_thead_slot_context);
	let if_block = /*visible*/ ctx[8].length && /*visible*/ ctx[8][0].data.length && create_if_block$1(ctx);
	const tfoot_slot_template = /*#slots*/ ctx[22].tfoot;
	const tfoot_slot = create_slot(tfoot_slot_template, ctx, /*$$scope*/ ctx[21], get_tfoot_slot_context);

	return {
		c() {
			svelte_virtual_table_viewport = element$1("svelte-virtual-table-viewport");
			table = element$1("table");
			thead = element$1("thead");
			if (thead_slot) thead_slot.c();
			t0 = space$2();
			tbody = element$1("tbody");
			if (if_block) if_block.c();
			t1 = space$2();
			tfoot = element$1("tfoot");
			if (tfoot_slot) tfoot_slot.c();
			attr$1(thead, "class", "thead svelte-1jok1de");
			add_render_callback$1(() => /*thead_elementresize_handler*/ ctx[23].call(thead));
			attr$1(tbody, "class", "tbody svelte-1jok1de");
			attr$1(tfoot, "class", "tfoot svelte-1jok1de");
			add_render_callback$1(() => /*tfoot_elementresize_handler*/ ctx[25].call(tfoot));
			attr$1(table, "class", "table svelte-1jok1de");
			set_style$1(table, "height", height);
			set_style$1(table, "--bw-svt-p-top", /*top*/ ctx[5] + "px");
			set_style$1(table, "--bw-svt-p-bottom", /*bottom*/ ctx[1] + "px");
			set_style$1(table, "--bw-svt-head-height", /*head_height*/ ctx[3] + "px");
			set_style$1(table, "--bw-svt-foot-height", /*foot_height*/ ctx[4] + "px");
			set_style$1(table, "--bw-svt-avg-row-height", /*average_height*/ ctx[0] + "px");
			add_render_callback$1(() => /*table_elementresize_handler*/ ctx[27].call(table));
		},
		m(target, anchor) {
			insert$2(target, svelte_virtual_table_viewport, anchor);
			append$1(svelte_virtual_table_viewport, table);
			append$1(table, thead);

			if (thead_slot) {
				thead_slot.m(thead, null);
			}

			thead_resize_listener = add_iframe_resize_listener$1(thead, /*thead_elementresize_handler*/ ctx[23].bind(thead));
			append$1(table, t0);
			append$1(table, tbody);
			if (if_block) if_block.m(tbody, null);
			/*tbody_binding*/ ctx[24](tbody);
			append$1(table, t1);
			append$1(table, tfoot);

			if (tfoot_slot) {
				tfoot_slot.m(tfoot, null);
			}

			tfoot_resize_listener = add_iframe_resize_listener$1(tfoot, /*tfoot_elementresize_handler*/ ctx[25].bind(tfoot));
			/*table_binding*/ ctx[26](table);
			table_resize_listener = add_iframe_resize_listener$1(table, /*table_elementresize_handler*/ ctx[27].bind(table));
			current = true;

			if (!mounted) {
				dispose = listen$1(table, "scroll", /*handle_scroll*/ ctx[9]);
				mounted = true;
			}
		},
		p(ctx, dirty) {
			if (thead_slot) {
				if (thead_slot.p && (!current || dirty[0] & /*$$scope*/ 2097152)) {
					update_slot_base(
						thead_slot,
						thead_slot_template,
						ctx,
						/*$$scope*/ ctx[21],
						!current
						? get_all_dirty_from_scope(/*$$scope*/ ctx[21])
						: get_slot_changes(thead_slot_template, /*$$scope*/ ctx[21], dirty, get_thead_slot_changes),
						get_thead_slot_context
					);
				}
			}

			if (/*visible*/ ctx[8].length && /*visible*/ ctx[8][0].data.length) {
				if (if_block) {
					if_block.p(ctx, dirty);

					if (dirty[0] & /*visible*/ 256) {
						transition_in$2(if_block, 1);
					}
				} else {
					if_block = create_if_block$1(ctx);
					if_block.c();
					transition_in$2(if_block, 1);
					if_block.m(tbody, null);
				}
			} else if (if_block) {
				group_outros$1();

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

				check_outros$1();
			}

			if (tfoot_slot) {
				if (tfoot_slot.p && (!current || dirty[0] & /*$$scope*/ 2097152)) {
					update_slot_base(
						tfoot_slot,
						tfoot_slot_template,
						ctx,
						/*$$scope*/ ctx[21],
						!current
						? get_all_dirty_from_scope(/*$$scope*/ ctx[21])
						: get_slot_changes(tfoot_slot_template, /*$$scope*/ ctx[21], dirty, get_tfoot_slot_changes),
						get_tfoot_slot_context
					);
				}
			}

			if (!current || dirty[0] & /*top*/ 32) {
				set_style$1(table, "--bw-svt-p-top", /*top*/ ctx[5] + "px");
			}

			if (!current || dirty[0] & /*bottom*/ 2) {
				set_style$1(table, "--bw-svt-p-bottom", /*bottom*/ ctx[1] + "px");
			}

			if (!current || dirty[0] & /*head_height*/ 8) {
				set_style$1(table, "--bw-svt-head-height", /*head_height*/ ctx[3] + "px");
			}

			if (!current || dirty[0] & /*foot_height*/ 16) {
				set_style$1(table, "--bw-svt-foot-height", /*foot_height*/ ctx[4] + "px");
			}

			if (!current || dirty[0] & /*average_height*/ 1) {
				set_style$1(table, "--bw-svt-avg-row-height", /*average_height*/ ctx[0] + "px");
			}
		},
		i(local) {
			if (current) return;
			transition_in$2(thead_slot, local);
			transition_in$2(if_block);
			transition_in$2(tfoot_slot, local);
			current = true;
		},
		o(local) {
			transition_out$2(thead_slot, local);
			transition_out$2(if_block);
			transition_out$2(tfoot_slot, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$2(svelte_virtual_table_viewport);
			}

			if (thead_slot) thead_slot.d(detaching);
			thead_resize_listener();
			if (if_block) if_block.d();
			/*tbody_binding*/ ctx[24](null);
			if (tfoot_slot) tfoot_slot.d(detaching);
			tfoot_resize_listener();
			/*table_binding*/ ctx[26](null);
			table_resize_listener();
			mounted = false;
			dispose();
		}
	};
}

let height = "100%";

function get_computed_px_amount(elem, property) {
	if (!elem) {
		return 0;
	}

	const compStyle = getComputedStyle(elem);
	let x = parseInt(compStyle.getPropertyValue(property));
	return x;
}

function instance$2($$self, $$props, $$invalidate) {
	let sortedItems;
	let { $$slots: slots = {}, $$scope } = $$props;
	let { items = [] } = $$props;
	let { table_width } = $$props;
	let { max_height } = $$props;
	let { actual_height } = $$props;
	let { table_scrollbar_width } = $$props;
	let { start = 0 } = $$props;
	let { end = 0 } = $$props;
	let { selected } = $$props;
	let average_height;
	let bottom = 0;
	let contents;
	let head_height = 0;
	let foot_height = 0;
	let height_map = [];
	let mounted;
	let rows;
	let top = 0;
	let viewport;
	let viewport_height = 0;
	let visible = [];
	let content_height = 0;

	async function refresh_height_map(_items) {
		if (viewport_height === 0 || table_width === 0) {
			return;
		}

		const { scrollTop } = viewport;
		$$invalidate(13, table_scrollbar_width = viewport.offsetWidth - viewport.clientWidth);
		content_height = top - (scrollTop - head_height);
		let i = start;

		while (content_height < max_height && i < _items.length) {
			let row = rows[i - start];

			if (!row) {
				$$invalidate(11, end = i + 1);
				await tick$1(); // render the newly visible row
				row = rows[i - start];
			}

			let _h = row?.getBoundingClientRect().height;

			if (!_h) {
				_h = average_height;
			}

			const row_height = height_map[i] = _h;
			content_height += row_height;
			i += 1;
		}

		$$invalidate(11, end = i);
		const remaining = _items.length - end;
		const scrollbar_height = viewport.offsetHeight - viewport.clientHeight;

		if (scrollbar_height > 0) {
			content_height += scrollbar_height;
		}

		let filtered_height_map = height_map.filter(v => typeof v === "number");
		$$invalidate(0, average_height = filtered_height_map.reduce((a, b) => a + b, 0) / filtered_height_map.length);
		$$invalidate(1, bottom = remaining * average_height);
		height_map.length = _items.length;
		await tick$1();

		if (!max_height) {
			$$invalidate(12, actual_height = content_height + 1);
		} else if (content_height < max_height) {
			$$invalidate(12, actual_height = content_height + 2);
		} else {
			$$invalidate(12, actual_height = max_height);
		}

		await tick$1();
	}

	async function scroll_and_render(n) {
		requestAnimationFrame(async () => {
			if (typeof n !== "number") return;
			const direction = typeof n !== "number" ? false : is_in_view(n);

			if (direction === true) {
				return;
			}

			if (direction === "back") {
				await scroll_to_index(n, { behavior: "instant" });
			}

			if (direction === "forwards") {
				await scroll_to_index(n, { behavior: "instant" }, true);
			}
		});
	}

	function is_in_view(n) {
		const current = rows && rows[n - start];

		if (!current && n < start) {
			return "back";
		}

		if (!current && n >= end - 1) {
			return "forwards";
		}

		const { top: viewport_top } = viewport.getBoundingClientRect();
		const { top, bottom } = current.getBoundingClientRect();

		if (top - viewport_top < 37) {
			return "back";
		}

		if (bottom - viewport_top > viewport_height) {
			return "forwards";
		}

		return true;
	}

	async function handle_scroll(e) {
		const scroll_top = viewport.scrollTop;
		rows = contents.children;
		const is_start_overflow = sortedItems.length < start;
		const row_top_border = get_computed_px_amount(rows[1], "border-top-width");
		const actual_border_collapsed_width = 0;

		if (is_start_overflow) {
			await scroll_to_index(sortedItems.length - 1, { behavior: "auto" });
		}

		let new_start = 0;

		// acquire height map for currently visible rows
		for (let v = 0; v < rows.length; v += 1) {
			height_map[start + v] = rows[v].getBoundingClientRect().height;
		}

		let i = 0;

		// start from top: thead, with its borders, plus the first border to afterwards neglect
		let y = head_height + row_top_border / 2;

		let row_heights = [];

		// loop items to find new start
		while (i < sortedItems.length) {
			const row_height = height_map[i] || average_height;
			row_heights[i] = row_height;

			// we only want to jump if the full (incl. border) row is away
			if (y + row_height + actual_border_collapsed_width > scroll_top) {
				// this is the last index still inside the viewport
				new_start = i;

				$$invalidate(5, top = y - (head_height + row_top_border / 2));
				break;
			}

			y += row_height;
			i += 1;
		}

		new_start = Math.max(0, new_start);

		while (i < sortedItems.length) {
			const row_height = height_map[i] || average_height;
			y += row_height;
			i += 1;

			if (y > scroll_top + viewport_height) {
				break;
			}
		}

		$$invalidate(10, start = new_start);
		$$invalidate(11, end = i);
		const remaining = sortedItems.length - end;

		if (end === 0) {
			$$invalidate(11, end = 10);
		}

		$$invalidate(0, average_height = (y - head_height) / end);
		let remaining_height = remaining * average_height; // 0

		// compute height map for remaining items
		while (i < sortedItems.length) {
			i += 1;
			height_map[i] = average_height;
		}

		$$invalidate(1, bottom = remaining_height);

		if (!isFinite(bottom)) {
			$$invalidate(1, bottom = 200000);
		}
	}

	async function scroll_to_index(index, opts, align_end = false) {
		await tick$1();
		const _itemHeight = average_height;
		let distance = index * _itemHeight;

		if (align_end) {
			distance = distance - viewport_height + _itemHeight + head_height;
		}

		const scrollbar_height = viewport.offsetHeight - viewport.clientHeight;

		if (scrollbar_height > 0) {
			distance += scrollbar_height;
		}

		const _opts = {
			top: distance,
			behavior: "smooth",
			...opts
		};

		viewport.scrollTo(_opts);
	}

	onMount$1(() => {
		rows = contents.children;
		$$invalidate(19, mounted = true);
		refresh_height_map(items);
	});

	function thead_elementresize_handler() {
		head_height = this.offsetHeight;
		$$invalidate(3, head_height);
	}

	function tbody_binding($$value) {
		binding_callbacks$1[$$value ? 'unshift' : 'push'](() => {
			contents = $$value;
			$$invalidate(2, contents);
		});
	}

	function tfoot_elementresize_handler() {
		foot_height = this.offsetHeight;
		$$invalidate(4, foot_height);
	}

	function table_binding($$value) {
		binding_callbacks$1[$$value ? 'unshift' : 'push'](() => {
			viewport = $$value;
			$$invalidate(6, viewport);
		});
	}

	function table_elementresize_handler() {
		viewport_height = this.offsetHeight;
		$$invalidate(7, viewport_height);
	}

	$$self.$$set = $$props => {
		if ('items' in $$props) $$invalidate(14, items = $$props.items);
		if ('table_width' in $$props) $$invalidate(15, table_width = $$props.table_width);
		if ('max_height' in $$props) $$invalidate(16, max_height = $$props.max_height);
		if ('actual_height' in $$props) $$invalidate(12, actual_height = $$props.actual_height);
		if ('table_scrollbar_width' in $$props) $$invalidate(13, table_scrollbar_width = $$props.table_scrollbar_width);
		if ('start' in $$props) $$invalidate(10, start = $$props.start);
		if ('end' in $$props) $$invalidate(11, end = $$props.end);
		if ('selected' in $$props) $$invalidate(17, selected = $$props.selected);
		if ('$$scope' in $$props) $$invalidate(21, $$scope = $$props.$$scope);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty[0] & /*items*/ 16384) {
			$$invalidate(20, sortedItems = items);
		}

		if ($$self.$$.dirty[0] & /*mounted, sortedItems*/ 1572864) {
			if (mounted) requestAnimationFrame(() => refresh_height_map(sortedItems));
		}

		if ($$self.$$.dirty[0] & /*selected*/ 131072) {
			scroll_and_render(selected);
		}

		if ($$self.$$.dirty[0] & /*sortedItems, start, end*/ 1051648) {
			$$invalidate(8, visible = sortedItems.slice(start, end).map((data, i) => {
				return { index: i + start, data };
			}));
		}
	};

	return [
		average_height,
		bottom,
		contents,
		head_height,
		foot_height,
		top,
		viewport,
		viewport_height,
		visible,
		handle_scroll,
		start,
		end,
		actual_height,
		table_scrollbar_width,
		items,
		table_width,
		max_height,
		selected,
		scroll_to_index,
		mounted,
		sortedItems,
		$$scope,
		slots,
		thead_elementresize_handler,
		tbody_binding,
		tfoot_elementresize_handler,
		table_binding,
		table_elementresize_handler
	];
}

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

		init$2(
			this,
			options,
			instance$2,
			create_fragment$2,
			safe_not_equal$2,
			{
				items: 14,
				table_width: 15,
				max_height: 16,
				actual_height: 12,
				table_scrollbar_width: 13,
				start: 10,
				end: 11,
				selected: 17,
				scroll_to_index: 18
			},
			null,
			[-1, -1]
		);
	}

	get scroll_to_index() {
		return this.$$.ctx[18];
	}
}

const Table_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/dataframe/shared/Table.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$1,
	action_destroyer,
	add_flush_callback,
	add_iframe_resize_listener,
	add_render_callback,
	append,
	attr,
	bind,
	binding_callbacks,
	check_outros,
	create_component: create_component$1,
	destroy_component: destroy_component$1,
	detach: detach$1,
	element,
	empty,
	ensure_array_like,
	group_outros,
	init: init$1,
	insert: insert$1,
	listen,
	mount_component: mount_component$1,
	outro_and_destroy_block,
	run_all,
	safe_not_equal: safe_not_equal$1,
	set_data,
	set_style,
	space: space$1,
	svg_element,
	text,
	toggle_class,
	transition_in: transition_in$1,
	transition_out: transition_out$1,
	update_keyed_each
} = window.__gradio__svelte__internal;
const { createEventDispatcher, tick, onMount } = window.__gradio__svelte__internal;
function get_each_context_1(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[12] = list[i].value;
	child_ctx[87] = list[i].id;
	child_ctx[90] = list;
	child_ctx[91] = i;
	return child_ctx;
}

function get_each_context(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[12] = list[i].value;
	child_ctx[87] = list[i].id;
	child_ctx[88] = list;
	child_ctx[89] = i;
	return child_ctx;
}

function get_each_context_2(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[12] = list[i].value;
	child_ctx[87] = list[i].id;
	child_ctx[92] = list;
	child_ctx[89] = i;
	return child_ctx;
}

function get_each_context_3(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[12] = list[i].value;
	child_ctx[87] = list[i].id;
	child_ctx[91] = i;
	return child_ctx;
}

// (504:1) {#if label && label.length !== 0}
function create_if_block_5(ctx) {
	let p;
	let t;

	return {
		c() {
			p = element("p");
			t = text(/*label*/ ctx[1]);
			attr(p, "class", "svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, p, anchor);
			append(p, t);
		},
		p(ctx, dirty) {
			if (dirty[0] & /*label*/ 2) set_data(t, /*label*/ ctx[1]);
		},
		d(detaching) {
			if (detaching) {
				detach$1(p);
			}
		}
	};
}

// (524:3) {#if label && label.length !== 0}
function create_if_block_4(ctx) {
	let caption;
	let t;

	return {
		c() {
			caption = element("caption");
			t = text(/*label*/ ctx[1]);
			attr(caption, "class", "sr-only");
		},
		m(target, anchor) {
			insert$1(target, caption, anchor);
			append(caption, t);
		},
		p(ctx, dirty) {
			if (dirty[0] & /*label*/ 2) set_data(t, /*label*/ ctx[1]);
		},
		d(detaching) {
			if (detaching) {
				detach$1(caption);
			}
		}
	};
}

// (529:5) {#each _headers as { value, id }
function create_each_block_3(key_1, ctx) {
	let th;
	let div1;
	let editablecell;
	let t0;
	let div0;
	let svg;
	let path;
	let div0_class_value;
	let t1;
	let th_aria_sort_value;
	let current;

	editablecell = new EditableCell({
			props: {
				value: /*value*/ ctx[12],
				latex_delimiters: /*latex_delimiters*/ ctx[4],
				line_breaks: /*line_breaks*/ ctx[10],
				header: true,
				edit: false,
				el: null
			}
		});

	return {
		key: key_1,
		first: null,
		c() {
			th = element("th");
			div1 = element("div");
			create_component$1(editablecell.$$.fragment);
			t0 = space$1();
			div0 = element("div");
			svg = svg_element("svg");
			path = svg_element("path");
			t1 = space$1();
			attr(path, "d", "M4.49999 0L8.3971 6.75H0.602875L4.49999 0Z");
			attr(svg, "width", "1em");
			attr(svg, "height", "1em");
			attr(svg, "viewBox", "0 0 9 7");
			attr(svg, "fill", "none");
			attr(svg, "xmlns", "http://www.w3.org/2000/svg");
			attr(svg, "class", "svelte-1bvc1p0");
			attr(div0, "class", div0_class_value = "sort-button " + /*sort_direction*/ ctx[18] + "" + " svelte-1bvc1p0");
			toggle_class(div0, "sorted", /*sort_by*/ ctx[19] === /*i*/ ctx[91]);
			toggle_class(div0, "des", /*sort_by*/ ctx[19] === /*i*/ ctx[91] && /*sort_direction*/ ctx[18] === "des");
			attr(div1, "class", "cell-wrap svelte-1bvc1p0");
			attr(th, "aria-sort", th_aria_sort_value = /*get_sort_status*/ ctx[35](/*value*/ ctx[12], /*sort_by*/ ctx[19], /*sort_direction*/ ctx[18]));
			attr(th, "class", "svelte-1bvc1p0");
			toggle_class(th, "editing", /*header_edit*/ ctx[24] === /*i*/ ctx[91]);

			set_style(th, "width", /*column_widths*/ ctx[11].length
			? /*column_widths*/ ctx[11][/*i*/ ctx[91]]
			: undefined);

			this.first = th;
		},
		m(target, anchor) {
			insert$1(target, th, anchor);
			append(th, div1);
			mount_component$1(editablecell, div1, null);
			append(div1, t0);
			append(div1, div0);
			append(div0, svg);
			append(svg, path);
			append(th, t1);
			current = true;
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			const editablecell_changes = {};
			if (dirty[0] & /*_headers*/ 65536) editablecell_changes.value = /*value*/ ctx[12];
			if (dirty[0] & /*latex_delimiters*/ 16) editablecell_changes.latex_delimiters = /*latex_delimiters*/ ctx[4];
			if (dirty[0] & /*line_breaks*/ 1024) editablecell_changes.line_breaks = /*line_breaks*/ ctx[10];
			editablecell.$set(editablecell_changes);

			if (!current || dirty[0] & /*sort_direction*/ 262144 && div0_class_value !== (div0_class_value = "sort-button " + /*sort_direction*/ ctx[18] + "" + " svelte-1bvc1p0")) {
				attr(div0, "class", div0_class_value);
			}

			if (!current || dirty[0] & /*sort_direction, sort_by, _headers*/ 851968) {
				toggle_class(div0, "sorted", /*sort_by*/ ctx[19] === /*i*/ ctx[91]);
			}

			if (!current || dirty[0] & /*sort_direction, sort_by, _headers, sort_direction*/ 851968) {
				toggle_class(div0, "des", /*sort_by*/ ctx[19] === /*i*/ ctx[91] && /*sort_direction*/ ctx[18] === "des");
			}

			if (!current || dirty[0] & /*_headers, sort_by, sort_direction*/ 851968 && th_aria_sort_value !== (th_aria_sort_value = /*get_sort_status*/ ctx[35](/*value*/ ctx[12], /*sort_by*/ ctx[19], /*sort_direction*/ ctx[18]))) {
				attr(th, "aria-sort", th_aria_sort_value);
			}

			if (!current || dirty[0] & /*header_edit, _headers*/ 16842752) {
				toggle_class(th, "editing", /*header_edit*/ ctx[24] === /*i*/ ctx[91]);
			}

			if (dirty[0] & /*column_widths, _headers*/ 67584) {
				set_style(th, "width", /*column_widths*/ ctx[11].length
				? /*column_widths*/ ctx[11][/*i*/ ctx[91]]
				: undefined);
			}
		},
		i(local) {
			if (current) return;
			transition_in$1(editablecell.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(editablecell.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(th);
			}

			destroy_component$1(editablecell);
		}
	};
}

// (567:5) {#each max as { value, id }
function create_each_block_2(key_1, ctx) {
	let td;
	let div;
	let editablecell;
	let t;
	let j = /*j*/ ctx[89];
	let current;

	editablecell = new EditableCell({
			props: {
				value: /*value*/ ctx[12],
				latex_delimiters: /*latex_delimiters*/ ctx[4],
				line_breaks: /*line_breaks*/ ctx[10],
				datatype: Array.isArray(/*datatype*/ ctx[0])
				? /*datatype*/ ctx[0][/*j*/ ctx[89]]
				: /*datatype*/ ctx[0],
				edit: false,
				el: null
			}
		});

	const assign_td = () => /*td_binding*/ ctx[52](td, j);
	const unassign_td = () => /*td_binding*/ ctx[52](null, j);

	return {
		key: key_1,
		first: null,
		c() {
			td = element("td");
			div = element("div");
			create_component$1(editablecell.$$.fragment);
			t = space$1();
			attr(div, "class", "cell-wrap svelte-1bvc1p0");
			attr(td, "tabindex", "-1");
			attr(td, "class", "svelte-1bvc1p0");
			this.first = td;
		},
		m(target, anchor) {
			insert$1(target, td, anchor);
			append(td, div);
			mount_component$1(editablecell, div, null);
			append(td, t);
			assign_td();
			current = true;
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			const editablecell_changes = {};
			if (dirty[1] & /*max*/ 8) editablecell_changes.value = /*value*/ ctx[12];
			if (dirty[0] & /*latex_delimiters*/ 16) editablecell_changes.latex_delimiters = /*latex_delimiters*/ ctx[4];
			if (dirty[0] & /*line_breaks*/ 1024) editablecell_changes.line_breaks = /*line_breaks*/ ctx[10];

			if (dirty[0] & /*datatype*/ 1 | dirty[1] & /*max*/ 8) editablecell_changes.datatype = Array.isArray(/*datatype*/ ctx[0])
			? /*datatype*/ ctx[0][/*j*/ ctx[89]]
			: /*datatype*/ ctx[0];

			editablecell.$set(editablecell_changes);

			if (j !== /*j*/ ctx[89]) {
				unassign_td();
				j = /*j*/ ctx[89];
				assign_td();
			}
		},
		i(local) {
			if (current) return;
			transition_in$1(editablecell.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(editablecell.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(td);
			}

			destroy_component$1(editablecell);
			unassign_td();
		}
	};
}

// (601:4) {#if label && label.length !== 0}
function create_if_block_3(ctx) {
	let caption;
	let t;

	return {
		c() {
			caption = element("caption");
			t = text(/*label*/ ctx[1]);
			attr(caption, "class", "sr-only");
		},
		m(target, anchor) {
			insert$1(target, caption, anchor);
			append(caption, t);
		},
		p(ctx, dirty) {
			if (dirty[0] & /*label*/ 2) set_data(t, /*label*/ ctx[1]);
		},
		d(detaching) {
			if (detaching) {
				detach$1(caption);
			}
		}
	};
}

// (593:3) <VirtualTable     bind:items={data}     table_width={t_width}     max_height={height}     bind:actual_height={table_height}     bind:table_scrollbar_width={scrollbar_width}     selected={selected_index}    >
function create_default_slot_3(ctx) {
	let if_block_anchor;
	let if_block = /*label*/ ctx[1] && /*label*/ ctx[1].length !== 0 && create_if_block_3(ctx);

	return {
		c() {
			if (if_block) if_block.c();
			if_block_anchor = empty();
		},
		m(target, anchor) {
			if (if_block) if_block.m(target, anchor);
			insert$1(target, if_block_anchor, anchor);
		},
		p(ctx, dirty) {
			if (/*label*/ ctx[1] && /*label*/ ctx[1].length !== 0) {
				if (if_block) {
					if_block.p(ctx, dirty);
				} else {
					if_block = create_if_block_3(ctx);
					if_block.c();
					if_block.m(if_block_anchor.parentNode, if_block_anchor);
				}
			} else if (if_block) {
				if_block.d(1);
				if_block = null;
			}
		},
		d(detaching) {
			if (detaching) {
				detach$1(if_block_anchor);
			}

			if (if_block) if_block.d(detaching);
		}
	};
}

// (605:5) {#each _headers as { value, id }
function create_each_block_1(key_1, ctx) {
	let th;
	let div1;
	let editablecell;
	let updating_value;
	let updating_el;
	let t0;
	let div0;
	let svg;
	let path;
	let div0_class_value;
	let t1;
	let th_aria_sort_value;
	let current;
	let mounted;
	let dispose;

	function editablecell_value_binding_1(value) {
		/*editablecell_value_binding_1*/ ctx[61](value, /*i*/ ctx[91]);
	}

	function editablecell_el_binding_1(value) {
		/*editablecell_el_binding_1*/ ctx[62](value, /*id*/ ctx[87]);
	}

	function dblclick_handler_1() {
		return /*dblclick_handler_1*/ ctx[63](/*i*/ ctx[91]);
	}

	let editablecell_props = {
		latex_delimiters: /*latex_delimiters*/ ctx[4],
		line_breaks: /*line_breaks*/ ctx[10],
		edit: /*header_edit*/ ctx[24] === /*i*/ ctx[91],
		select_on_focus: /*select_on_focus*/ ctx[25],
		header: true
	};

	if (/*_headers*/ ctx[16][/*i*/ ctx[91]].value !== void 0) {
		editablecell_props.value = /*_headers*/ ctx[16][/*i*/ ctx[91]].value;
	}

	if (/*els*/ ctx[22][/*id*/ ctx[87]].input !== void 0) {
		editablecell_props.el = /*els*/ ctx[22][/*id*/ ctx[87]].input;
	}

	editablecell = new EditableCell({ props: editablecell_props });
	binding_callbacks.push(() => bind(editablecell, 'value', editablecell_value_binding_1));
	binding_callbacks.push(() => bind(editablecell, 'el', editablecell_el_binding_1));
	editablecell.$on("keydown", /*end_header_edit*/ ctx[41]);
	editablecell.$on("dblclick", dblclick_handler_1);

	function click_handler_1() {
		return /*click_handler_1*/ ctx[64](/*i*/ ctx[91]);
	}

	return {
		key: key_1,
		first: null,
		c() {
			th = element("th");
			div1 = element("div");
			create_component$1(editablecell.$$.fragment);
			t0 = space$1();
			div0 = element("div");
			svg = svg_element("svg");
			path = svg_element("path");
			t1 = space$1();
			attr(path, "d", "M4.49999 0L8.3971 6.75H0.602875L4.49999 0Z");
			attr(svg, "width", "1em");
			attr(svg, "height", "1em");
			attr(svg, "viewBox", "0 0 9 7");
			attr(svg, "fill", "none");
			attr(svg, "xmlns", "http://www.w3.org/2000/svg");
			attr(svg, "class", "svelte-1bvc1p0");
			attr(div0, "class", div0_class_value = "sort-button " + /*sort_direction*/ ctx[18] + "" + " svelte-1bvc1p0");
			toggle_class(div0, "sorted", /*sort_by*/ ctx[19] === /*i*/ ctx[91]);
			toggle_class(div0, "des", /*sort_by*/ ctx[19] === /*i*/ ctx[91] && /*sort_direction*/ ctx[18] === "des");
			attr(div1, "class", "cell-wrap svelte-1bvc1p0");
			attr(th, "aria-sort", th_aria_sort_value = /*get_sort_status*/ ctx[35](/*value*/ ctx[12], /*sort_by*/ ctx[19], /*sort_direction*/ ctx[18]));
			set_style(th, "width", "var(--cell-width-" + /*i*/ ctx[91] + ")");
			attr(th, "class", "svelte-1bvc1p0");
			toggle_class(th, "focus", /*header_edit*/ ctx[24] === /*i*/ ctx[91] || /*selected_header*/ ctx[26] === /*i*/ ctx[91]);
			this.first = th;
		},
		m(target, anchor) {
			insert$1(target, th, anchor);
			append(th, div1);
			mount_component$1(editablecell, div1, null);
			append(div1, t0);
			append(div1, div0);
			append(div0, svg);
			append(svg, path);
			append(th, t1);
			current = true;

			if (!mounted) {
				dispose = listen(div0, "click", click_handler_1);
				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			const editablecell_changes = {};
			if (dirty[0] & /*latex_delimiters*/ 16) editablecell_changes.latex_delimiters = /*latex_delimiters*/ ctx[4];
			if (dirty[0] & /*line_breaks*/ 1024) editablecell_changes.line_breaks = /*line_breaks*/ ctx[10];
			if (dirty[0] & /*header_edit, _headers*/ 16842752) editablecell_changes.edit = /*header_edit*/ ctx[24] === /*i*/ ctx[91];
			if (dirty[0] & /*select_on_focus*/ 33554432) editablecell_changes.select_on_focus = /*select_on_focus*/ ctx[25];

			if (!updating_value && dirty[0] & /*_headers*/ 65536) {
				updating_value = true;
				editablecell_changes.value = /*_headers*/ ctx[16][/*i*/ ctx[91]].value;
				add_flush_callback(() => updating_value = false);
			}

			if (!updating_el && dirty[0] & /*els, _headers*/ 4259840) {
				updating_el = true;
				editablecell_changes.el = /*els*/ ctx[22][/*id*/ ctx[87]].input;
				add_flush_callback(() => updating_el = false);
			}

			editablecell.$set(editablecell_changes);

			if (!current || dirty[0] & /*sort_direction*/ 262144 && div0_class_value !== (div0_class_value = "sort-button " + /*sort_direction*/ ctx[18] + "" + " svelte-1bvc1p0")) {
				attr(div0, "class", div0_class_value);
			}

			if (!current || dirty[0] & /*sort_direction, sort_by, _headers*/ 851968) {
				toggle_class(div0, "sorted", /*sort_by*/ ctx[19] === /*i*/ ctx[91]);
			}

			if (!current || dirty[0] & /*sort_direction, sort_by, _headers, sort_direction*/ 851968) {
				toggle_class(div0, "des", /*sort_by*/ ctx[19] === /*i*/ ctx[91] && /*sort_direction*/ ctx[18] === "des");
			}

			if (!current || dirty[0] & /*_headers, sort_by, sort_direction*/ 851968 && th_aria_sort_value !== (th_aria_sort_value = /*get_sort_status*/ ctx[35](/*value*/ ctx[12], /*sort_by*/ ctx[19], /*sort_direction*/ ctx[18]))) {
				attr(th, "aria-sort", th_aria_sort_value);
			}

			if (!current || dirty[0] & /*_headers*/ 65536) {
				set_style(th, "width", "var(--cell-width-" + /*i*/ ctx[91] + ")");
			}

			if (!current || dirty[0] & /*header_edit, _headers, selected_header*/ 83951616) {
				toggle_class(th, "focus", /*header_edit*/ ctx[24] === /*i*/ ctx[91] || /*selected_header*/ ctx[26] === /*i*/ ctx[91]);
			}
		},
		i(local) {
			if (current) return;
			transition_in$1(editablecell.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(editablecell.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(th);
			}

			destroy_component$1(editablecell);
			mounted = false;
			dispose();
		}
	};
}

// (604:4) 
function create_thead_slot(ctx) {
	let tr;
	let each_blocks = [];
	let each_1_lookup = new Map();
	let current;
	let each_value_1 = ensure_array_like(/*_headers*/ ctx[16]);
	const get_key = ctx => /*id*/ ctx[87];

	for (let i = 0; i < each_value_1.length; i += 1) {
		let child_ctx = get_each_context_1(ctx, each_value_1, i);
		let key = get_key(child_ctx);
		each_1_lookup.set(key, each_blocks[i] = create_each_block_1(key, child_ctx));
	}

	return {
		c() {
			tr = element("tr");

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

			attr(tr, "slot", "thead");
			attr(tr, "class", "svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, tr, anchor);

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

			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*_headers, sort_by, sort_direction, header_edit, selected_header, latex_delimiters, line_breaks, select_on_focus, els*/ 122487824 | dirty[1] & /*get_sort_status, handle_sort, end_header_edit, edit_header*/ 1808) {
				each_value_1 = ensure_array_like(/*_headers*/ ctx[16]);
				group_outros();
				each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value_1, each_1_lookup, tr, outro_and_destroy_block, create_each_block_1, null, get_each_context_1);
				check_outros();
			}
		},
		i(local) {
			if (current) return;

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

			current = true;
		},
		o(local) {
			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out$1(each_blocks[i]);
			}

			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(tr);
			}

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

// (649:5) {#each item as { value, id }
function create_each_block(key_1, ctx) {
	let td;
	let div;
	let editablecell;
	let updating_value;
	let updating_el;
	let t;
	let td_style_value;
	let style_width = `var(--cell-width-${/*j*/ ctx[89]})`;
	let current;
	let mounted;
	let dispose;

	function editablecell_value_binding(value) {
		/*editablecell_value_binding*/ ctx[55](value, /*index*/ ctx[85], /*j*/ ctx[89]);
	}

	function editablecell_el_binding(value) {
		/*editablecell_el_binding*/ ctx[56](value, /*id*/ ctx[87]);
	}

	let editablecell_props = {
		display_value: /*display_value*/ ctx[14]?.[/*index*/ ctx[85]]?.[/*j*/ ctx[89]],
		latex_delimiters: /*latex_delimiters*/ ctx[4],
		line_breaks: /*line_breaks*/ ctx[10],
		editable: /*editable*/ ctx[5],
		edit: dequal(/*editing*/ ctx[21], [/*index*/ ctx[85], /*j*/ ctx[89]]),
		datatype: Array.isArray(/*datatype*/ ctx[0])
		? /*datatype*/ ctx[0][/*j*/ ctx[89]]
		: /*datatype*/ ctx[0],
		clear_on_focus: /*clear_on_focus*/ ctx[23]
	};

	if (/*data*/ ctx[17][/*index*/ ctx[85]][/*j*/ ctx[89]].value !== void 0) {
		editablecell_props.value = /*data*/ ctx[17][/*index*/ ctx[85]][/*j*/ ctx[89]].value;
	}

	if (/*els*/ ctx[22][/*id*/ ctx[87]].input !== void 0) {
		editablecell_props.el = /*els*/ ctx[22][/*id*/ ctx[87]].input;
	}

	editablecell = new EditableCell({ props: editablecell_props });
	binding_callbacks.push(() => bind(editablecell, 'value', editablecell_value_binding));
	binding_callbacks.push(() => bind(editablecell, 'el', editablecell_el_binding));
	editablecell.$on("blur", /*blur_handler*/ ctx[57]);

	function touchstart_handler() {
		return /*touchstart_handler*/ ctx[58](/*index*/ ctx[85], /*j*/ ctx[89]);
	}

	function click_handler() {
		return /*click_handler*/ ctx[59](/*index*/ ctx[85], /*j*/ ctx[89]);
	}

	function dblclick_handler() {
		return /*dblclick_handler*/ ctx[60](/*index*/ ctx[85], /*j*/ ctx[89]);
	}

	return {
		key: key_1,
		first: null,
		c() {
			td = element("td");
			div = element("div");
			create_component$1(editablecell.$$.fragment);
			t = space$1();
			attr(div, "class", "cell-wrap svelte-1bvc1p0");
			attr(td, "tabindex", "0");
			attr(td, "style", td_style_value = /*styling*/ ctx[15]?.[/*index*/ ctx[85]]?.[/*j*/ ctx[89]] || "");
			attr(td, "class", "svelte-1bvc1p0");
			toggle_class(td, "focus", dequal(/*selected*/ ctx[13], [/*index*/ ctx[85], /*j*/ ctx[89]]));
			set_style(td, "width", style_width);
			this.first = td;
		},
		m(target, anchor) {
			insert$1(target, td, anchor);
			append(td, div);
			mount_component$1(editablecell, div, null);
			append(td, t);
			current = true;

			if (!mounted) {
				dispose = [
					listen(td, "touchstart", touchstart_handler, { passive: true }),
					listen(td, "click", click_handler),
					listen(td, "dblclick", dblclick_handler)
				];

				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			const editablecell_changes = {};
			if (dirty[0] & /*display_value*/ 16384 | dirty[2] & /*index, item*/ 25165824) editablecell_changes.display_value = /*display_value*/ ctx[14]?.[/*index*/ ctx[85]]?.[/*j*/ ctx[89]];
			if (dirty[0] & /*latex_delimiters*/ 16) editablecell_changes.latex_delimiters = /*latex_delimiters*/ ctx[4];
			if (dirty[0] & /*line_breaks*/ 1024) editablecell_changes.line_breaks = /*line_breaks*/ ctx[10];
			if (dirty[0] & /*editable*/ 32) editablecell_changes.editable = /*editable*/ ctx[5];
			if (dirty[0] & /*editing*/ 2097152 | dirty[2] & /*index, item*/ 25165824) editablecell_changes.edit = dequal(/*editing*/ ctx[21], [/*index*/ ctx[85], /*j*/ ctx[89]]);

			if (dirty[0] & /*datatype*/ 1 | dirty[2] & /*item*/ 16777216) editablecell_changes.datatype = Array.isArray(/*datatype*/ ctx[0])
			? /*datatype*/ ctx[0][/*j*/ ctx[89]]
			: /*datatype*/ ctx[0];

			if (dirty[0] & /*clear_on_focus*/ 8388608) editablecell_changes.clear_on_focus = /*clear_on_focus*/ ctx[23];

			if (!updating_value && dirty[0] & /*data*/ 131072 | dirty[2] & /*index, item*/ 25165824) {
				updating_value = true;
				editablecell_changes.value = /*data*/ ctx[17][/*index*/ ctx[85]][/*j*/ ctx[89]].value;
				add_flush_callback(() => updating_value = false);
			}

			if (!updating_el && dirty[0] & /*els*/ 4194304 | dirty[2] & /*item*/ 16777216) {
				updating_el = true;
				editablecell_changes.el = /*els*/ ctx[22][/*id*/ ctx[87]].input;
				add_flush_callback(() => updating_el = false);
			}

			editablecell.$set(editablecell_changes);

			if (!current || dirty[0] & /*styling*/ 32768 | dirty[2] & /*index, item*/ 25165824 && td_style_value !== (td_style_value = /*styling*/ ctx[15]?.[/*index*/ ctx[85]]?.[/*j*/ ctx[89]] || "")) {
				attr(td, "style", td_style_value);
			}

			if (!current || dirty[0] & /*selected*/ 8192 | dirty[2] & /*index, item*/ 25165824) {
				toggle_class(td, "focus", dequal(/*selected*/ ctx[13], [/*index*/ ctx[85], /*j*/ ctx[89]]));
			}

			const style_changed = dirty[0] & /*styling*/ 32768 | dirty[2] & /*index, item*/ 25165824;

			if (dirty[0] & /*styling*/ 32768 | dirty[2] & /*item, index*/ 25165824 && style_width !== (style_width = `var(--cell-width-${/*j*/ ctx[89]})`) || style_changed) {
				set_style(td, "width", style_width);
			}
		},
		i(local) {
			if (current) return;
			transition_in$1(editablecell.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(editablecell.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(td);
			}

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

// (648:4) 
function create_tbody_slot(ctx) {
	let tr;
	let each_blocks = [];
	let each_1_lookup = new Map();
	let current;
	let each_value = ensure_array_like(/*item*/ ctx[86]);
	const get_key = ctx => /*id*/ ctx[87];

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

	return {
		c() {
			tr = element("tr");

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

			attr(tr, "slot", "tbody");
			attr(tr, "class", "svelte-1bvc1p0");
			toggle_class(tr, "row_odd", /*index*/ ctx[85] % 2 === 0);
		},
		m(target, anchor) {
			insert$1(target, tr, anchor);

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

			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*styling, selected, display_value, latex_delimiters, line_breaks, editable, editing, datatype, clear_on_focus, data, els, parent*/ 551740465 | dirty[1] & /*start_edit, handle_cell_click*/ 160 | dirty[2] & /*index, item*/ 25165824) {
				each_value = ensure_array_like(/*item*/ ctx[86]);
				group_outros();
				each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, tr, outro_and_destroy_block, create_each_block, null, get_each_context);
				check_outros();
			}

			if (!current || dirty[2] & /*index*/ 8388608) {
				toggle_class(tr, "row_odd", /*index*/ ctx[85] % 2 === 0);
			}
		},
		i(local) {
			if (current) return;

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

			current = true;
		},
		o(local) {
			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out$1(each_blocks[i]);
			}

			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(tr);
			}

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

// (584:2) <Upload    flex={false}    center={false}    boundedheight={false}    disable_click={true}    {root}    on:load={(e) => blob_to_string(data_uri_to_blob(e.detail.data))}    bind:dragging   >
function create_default_slot_2(ctx) {
	let virtualtable;
	let updating_items;
	let updating_actual_height;
	let updating_table_scrollbar_width;
	let current;

	function virtualtable_items_binding(value) {
		/*virtualtable_items_binding*/ ctx[65](value);
	}

	function virtualtable_actual_height_binding(value) {
		/*virtualtable_actual_height_binding*/ ctx[66](value);
	}

	function virtualtable_table_scrollbar_width_binding(value) {
		/*virtualtable_table_scrollbar_width_binding*/ ctx[67](value);
	}

	let virtualtable_props = {
		table_width: /*t_width*/ ctx[28],
		max_height: /*height*/ ctx[9],
		selected: /*selected_index*/ ctx[33],
		$$slots: {
			tbody: [
				create_tbody_slot,
				({ index, item }) => ({ 85: index, 86: item }),
				({ index, item }) => [0, 0, (index ? 8388608 : 0) | (item ? 16777216 : 0)]
			],
			thead: [create_thead_slot],
			default: [create_default_slot_3]
		},
		$$scope: { ctx }
	};

	if (/*data*/ ctx[17] !== void 0) {
		virtualtable_props.items = /*data*/ ctx[17];
	}

	if (/*table_height*/ ctx[31] !== void 0) {
		virtualtable_props.actual_height = /*table_height*/ ctx[31];
	}

	if (/*scrollbar_width*/ ctx[32] !== void 0) {
		virtualtable_props.table_scrollbar_width = /*scrollbar_width*/ ctx[32];
	}

	virtualtable = new VirtualTable({ props: virtualtable_props });
	binding_callbacks.push(() => bind(virtualtable, 'items', virtualtable_items_binding));
	binding_callbacks.push(() => bind(virtualtable, 'actual_height', virtualtable_actual_height_binding));
	binding_callbacks.push(() => bind(virtualtable, 'table_scrollbar_width', virtualtable_table_scrollbar_width_binding));

	return {
		c() {
			create_component$1(virtualtable.$$.fragment);
		},
		m(target, anchor) {
			mount_component$1(virtualtable, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const virtualtable_changes = {};
			if (dirty[0] & /*t_width*/ 268435456) virtualtable_changes.table_width = /*t_width*/ ctx[28];
			if (dirty[0] & /*height*/ 512) virtualtable_changes.max_height = /*height*/ ctx[9];
			if (dirty[1] & /*selected_index*/ 4) virtualtable_changes.selected = /*selected_index*/ ctx[33];

			if (dirty[0] & /*styling, selected, display_value, latex_delimiters, line_breaks, editable, editing, datatype, clear_on_focus, data, els, parent, _headers, sort_by, sort_direction, header_edit, selected_header, select_on_focus, label*/ 670032947 | dirty[2] & /*index, item*/ 25165824 | dirty[3] & /*$$scope*/ 2) {
				virtualtable_changes.$$scope = { dirty, ctx };
			}

			if (!updating_items && dirty[0] & /*data*/ 131072) {
				updating_items = true;
				virtualtable_changes.items = /*data*/ ctx[17];
				add_flush_callback(() => updating_items = false);
			}

			if (!updating_actual_height && dirty[1] & /*table_height*/ 1) {
				updating_actual_height = true;
				virtualtable_changes.actual_height = /*table_height*/ ctx[31];
				add_flush_callback(() => updating_actual_height = false);
			}

			if (!updating_table_scrollbar_width && dirty[1] & /*scrollbar_width*/ 2) {
				updating_table_scrollbar_width = true;
				virtualtable_changes.table_scrollbar_width = /*scrollbar_width*/ ctx[32];
				add_flush_callback(() => updating_table_scrollbar_width = false);
			}

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

// (679:1) {#if editable}
function create_if_block(ctx) {
	let div;
	let t;
	let current;
	let if_block0 = /*row_count*/ ctx[3][1] === "dynamic" && create_if_block_2(ctx);
	let if_block1 = /*col_count*/ ctx[2][1] === "dynamic" && create_if_block_1(ctx);

	return {
		c() {
			div = element("div");
			if (if_block0) if_block0.c();
			t = space$1();
			if (if_block1) if_block1.c();
			attr(div, "class", "controls-wrap svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, div, anchor);
			if (if_block0) if_block0.m(div, null);
			append(div, t);
			if (if_block1) if_block1.m(div, null);
			current = true;
		},
		p(ctx, dirty) {
			if (/*row_count*/ ctx[3][1] === "dynamic") {
				if (if_block0) {
					if_block0.p(ctx, dirty);

					if (dirty[0] & /*row_count*/ 8) {
						transition_in$1(if_block0, 1);
					}
				} else {
					if_block0 = create_if_block_2(ctx);
					if_block0.c();
					transition_in$1(if_block0, 1);
					if_block0.m(div, t);
				}
			} else if (if_block0) {
				group_outros();

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

				check_outros();
			}

			if (/*col_count*/ ctx[2][1] === "dynamic") {
				if (if_block1) {
					if_block1.p(ctx, dirty);

					if (dirty[0] & /*col_count*/ 4) {
						transition_in$1(if_block1, 1);
					}
				} else {
					if_block1 = create_if_block_1(ctx);
					if_block1.c();
					transition_in$1(if_block1, 1);
					if_block1.m(div, null);
				}
			} else if (if_block1) {
				group_outros();

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

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

			if (if_block0) if_block0.d();
			if (if_block1) if_block1.d();
		}
	};
}

// (681:3) {#if row_count[1] === "dynamic"}
function create_if_block_2(ctx) {
	let span;
	let basebutton;
	let current;

	basebutton = new Button({
			props: {
				variant: "secondary",
				size: "sm",
				$$slots: { default: [create_default_slot_1] },
				$$scope: { ctx }
			}
		});

	basebutton.$on("click", /*click_handler_2*/ ctx[72]);

	return {
		c() {
			span = element("span");
			create_component$1(basebutton.$$.fragment);
			attr(span, "class", "button-wrap svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, span, anchor);
			mount_component$1(basebutton, span, null);
			current = true;
		},
		p(ctx, dirty) {
			const basebutton_changes = {};

			if (dirty[0] & /*i18n*/ 256 | dirty[3] & /*$$scope*/ 2) {
				basebutton_changes.$$scope = { dirty, ctx };
			}

			basebutton.$set(basebutton_changes);
		},
		i(local) {
			if (current) return;
			transition_in$1(basebutton.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(basebutton.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(span);
			}

			destroy_component$1(basebutton);
		}
	};
}

// (683:5) <BaseButton       variant="secondary"       size="sm"       on:click={(e) => (e.stopPropagation(), add_row())}      >
function create_default_slot_1(ctx) {
	let svg;
	let path;
	let t0;
	let t1_value = /*i18n*/ ctx[8]("dataframe.new_row") + "";
	let t1;

	return {
		c() {
			svg = svg_element("svg");
			path = svg_element("path");
			t0 = space$1();
			t1 = text(t1_value);
			attr(path, "fill", "currentColor");
			attr(path, "d", "M24.59 16.59L17 24.17V4h-2v20.17l-7.59-7.58L6 18l10 10l10-10l-1.41-1.41z");
			attr(svg, "xmlns", "http://www.w3.org/2000/svg");
			attr(svg, "xmlns:xlink", "http://www.w3.org/1999/xlink");
			attr(svg, "aria-hidden", "true");
			attr(svg, "role", "img");
			attr(svg, "width", "1em");
			attr(svg, "height", "1em");
			attr(svg, "preserveAspectRatio", "xMidYMid meet");
			attr(svg, "viewBox", "0 0 32 32");
			attr(svg, "class", "svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, svg, anchor);
			append(svg, path);
			insert$1(target, t0, anchor);
			insert$1(target, t1, anchor);
		},
		p(ctx, dirty) {
			if (dirty[0] & /*i18n*/ 256 && t1_value !== (t1_value = /*i18n*/ ctx[8]("dataframe.new_row") + "")) set_data(t1, t1_value);
		},
		d(detaching) {
			if (detaching) {
				detach$1(svg);
				detach$1(t0);
				detach$1(t1);
			}
		}
	};
}

// (707:3) {#if col_count[1] === "dynamic"}
function create_if_block_1(ctx) {
	let span;
	let basebutton;
	let current;

	basebutton = new Button({
			props: {
				variant: "secondary",
				size: "sm",
				$$slots: { default: [create_default_slot$1] },
				$$scope: { ctx }
			}
		});

	basebutton.$on("click", /*click_handler_3*/ ctx[73]);

	return {
		c() {
			span = element("span");
			create_component$1(basebutton.$$.fragment);
			attr(span, "class", "button-wrap svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, span, anchor);
			mount_component$1(basebutton, span, null);
			current = true;
		},
		p(ctx, dirty) {
			const basebutton_changes = {};

			if (dirty[0] & /*i18n*/ 256 | dirty[3] & /*$$scope*/ 2) {
				basebutton_changes.$$scope = { dirty, ctx };
			}

			basebutton.$set(basebutton_changes);
		},
		i(local) {
			if (current) return;
			transition_in$1(basebutton.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out$1(basebutton.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(span);
			}

			destroy_component$1(basebutton);
		}
	};
}

// (709:5) <BaseButton       variant="secondary"       size="sm"       on:click={(e) => (e.stopPropagation(), add_col())}      >
function create_default_slot$1(ctx) {
	let svg;
	let path;
	let t0;
	let t1_value = /*i18n*/ ctx[8]("dataframe.new_column") + "";
	let t1;

	return {
		c() {
			svg = svg_element("svg");
			path = svg_element("path");
			t0 = space$1();
			t1 = text(t1_value);
			attr(path, "fill", "currentColor");
			attr(path, "d", "m18 6l-1.43 1.393L24.15 15H4v2h20.15l-7.58 7.573L18 26l10-10L18 6z");
			attr(svg, "xmlns", "http://www.w3.org/2000/svg");
			attr(svg, "xmlns:xlink", "http://www.w3.org/1999/xlink");
			attr(svg, "aria-hidden", "true");
			attr(svg, "role", "img");
			attr(svg, "width", "1em");
			attr(svg, "height", "1em");
			attr(svg, "preserveAspectRatio", "xMidYMid meet");
			attr(svg, "viewBox", "0 0 32 32");
			attr(svg, "class", "svelte-1bvc1p0");
		},
		m(target, anchor) {
			insert$1(target, svg, anchor);
			append(svg, path);
			insert$1(target, t0, anchor);
			insert$1(target, t1, anchor);
		},
		p(ctx, dirty) {
			if (dirty[0] & /*i18n*/ 256 && t1_value !== (t1_value = /*i18n*/ ctx[8]("dataframe.new_column") + "")) set_data(t1, t1_value);
		},
		d(detaching) {
			if (detaching) {
				detach$1(svg);
				detach$1(t0);
				detach$1(t1);
			}
		}
	};
}

function create_fragment$1(ctx) {
	let div1;
	let t0;
	let div0;
	let table_1;
	let t1;
	let thead;
	let tr0;
	let each_blocks_1 = [];
	let each0_lookup = new Map();
	let t2;
	let tbody;
	let tr1;
	let each_blocks = [];
	let each1_lookup = new Map();
	let table_1_resize_listener;
	let t3;
	let upload;
	let updating_dragging;
	let t4;
	let current;
	let mounted;
	let dispose;
	let if_block0 = /*label*/ ctx[1] && /*label*/ ctx[1].length !== 0 && create_if_block_5(ctx);
	let if_block1 = /*label*/ ctx[1] && /*label*/ ctx[1].length !== 0 && create_if_block_4(ctx);
	let each_value_3 = ensure_array_like(/*_headers*/ ctx[16]);
	const get_key = ctx => /*id*/ ctx[87];

	for (let i = 0; i < each_value_3.length; i += 1) {
		let child_ctx = get_each_context_3(ctx, each_value_3, i);
		let key = get_key(child_ctx);
		each0_lookup.set(key, each_blocks_1[i] = create_each_block_3(key, child_ctx));
	}

	let each_value_2 = ensure_array_like(/*max*/ ctx[34]);
	const get_key_1 = ctx => /*id*/ ctx[87];

	for (let i = 0; i < each_value_2.length; i += 1) {
		let child_ctx = get_each_context_2(ctx, each_value_2, i);
		let key = get_key_1(child_ctx);
		each1_lookup.set(key, each_blocks[i] = create_each_block_2(key, child_ctx));
	}

	function upload_dragging_binding(value) {
		/*upload_dragging_binding*/ ctx[68](value);
	}

	let upload_props = {
		flex: false,
		center: false,
		boundedheight: false,
		disable_click: true,
		root: /*root*/ ctx[7],
		$$slots: { default: [create_default_slot_2] },
		$$scope: { ctx }
	};

	if (/*dragging*/ ctx[27] !== void 0) {
		upload_props.dragging = /*dragging*/ ctx[27];
	}

	upload = new Upload({ props: upload_props });
	binding_callbacks.push(() => bind(upload, 'dragging', upload_dragging_binding));
	upload.$on("load", /*load_handler*/ ctx[69]);
	let if_block2 = /*editable*/ ctx[5] && create_if_block(ctx);

	return {
		c() {
			div1 = element("div");
			if (if_block0) if_block0.c();
			t0 = space$1();
			div0 = element("div");
			table_1 = element("table");
			if (if_block1) if_block1.c();
			t1 = space$1();
			thead = element("thead");
			tr0 = element("tr");

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

			t2 = space$1();
			tbody = element("tbody");
			tr1 = element("tr");

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

			t3 = space$1();
			create_component$1(upload.$$.fragment);
			t4 = space$1();
			if (if_block2) if_block2.c();
			attr(tr0, "class", "svelte-1bvc1p0");
			attr(thead, "class", "svelte-1bvc1p0");
			attr(tr1, "class", "svelte-1bvc1p0");
			attr(table_1, "class", "svelte-1bvc1p0");
			add_render_callback(() => /*table_1_elementresize_handler*/ ctx[53].call(table_1));
			toggle_class(table_1, "fixed-layout", /*column_widths*/ ctx[11].length != 0);
			attr(div0, "class", "table-wrap svelte-1bvc1p0");
			set_style(div0, "height", /*table_height*/ ctx[31] + "px");
			attr(div0, "role", "grid");
			attr(div0, "tabindex", "0");
			toggle_class(div0, "dragging", /*dragging*/ ctx[27]);
			toggle_class(div0, "no-wrap", !/*wrap*/ ctx[6]);
			attr(div1, "class", "svelte-1bvc1p0");
			toggle_class(div1, "label", /*label*/ ctx[1] && /*label*/ ctx[1].length !== 0);
		},
		m(target, anchor) {
			insert$1(target, div1, anchor);
			if (if_block0) if_block0.m(div1, null);
			append(div1, t0);
			append(div1, div0);
			append(div0, table_1);
			if (if_block1) if_block1.m(table_1, null);
			append(table_1, t1);
			append(table_1, thead);
			append(thead, tr0);

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

			append(table_1, t2);
			append(table_1, tbody);
			append(tbody, tr1);

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

			table_1_resize_listener = add_iframe_resize_listener(table_1, /*table_1_elementresize_handler*/ ctx[53].bind(table_1));
			/*table_1_binding*/ ctx[54](table_1);
			append(div0, t3);
			mount_component$1(upload, div0, null);
			/*div0_binding*/ ctx[70](div0);
			append(div1, t4);
			if (if_block2) if_block2.m(div1, null);
			current = true;

			if (!mounted) {
				dispose = [
					listen(window, "click", /*handle_click_outside*/ ctx[44]),
					listen(window, "touchstart", /*handle_click_outside*/ ctx[44]),
					listen(window, "resize", /*resize_handler*/ ctx[51]),
					listen(div0, "keydown", /*keydown_handler*/ ctx[71]),
					action_destroyer(copy.call(null, div1))
				];

				mounted = true;
			}
		},
		p(ctx, dirty) {
			if (/*label*/ ctx[1] && /*label*/ ctx[1].length !== 0) {
				if (if_block0) {
					if_block0.p(ctx, dirty);
				} else {
					if_block0 = create_if_block_5(ctx);
					if_block0.c();
					if_block0.m(div1, t0);
				}
			} else if (if_block0) {
				if_block0.d(1);
				if_block0 = null;
			}

			if (/*label*/ ctx[1] && /*label*/ ctx[1].length !== 0) {
				if (if_block1) {
					if_block1.p(ctx, dirty);
				} else {
					if_block1 = create_if_block_4(ctx);
					if_block1.c();
					if_block1.m(table_1, t1);
				}
			} else if (if_block1) {
				if_block1.d(1);
				if_block1 = null;
			}

			if (dirty[0] & /*_headers, sort_by, sort_direction, header_edit, column_widths, latex_delimiters, line_breaks*/ 17632272 | dirty[1] & /*get_sort_status*/ 16) {
				each_value_3 = ensure_array_like(/*_headers*/ ctx[16]);
				group_outros();
				each_blocks_1 = update_keyed_each(each_blocks_1, dirty, get_key, 1, ctx, each_value_3, each0_lookup, tr0, outro_and_destroy_block, create_each_block_3, null, get_each_context_3);
				check_outros();
			}

			if (dirty[0] & /*cells, latex_delimiters, line_breaks, datatype*/ 1049617 | dirty[1] & /*max*/ 8) {
				each_value_2 = ensure_array_like(/*max*/ ctx[34]);
				group_outros();
				each_blocks = update_keyed_each(each_blocks, dirty, get_key_1, 1, ctx, each_value_2, each1_lookup, tr1, outro_and_destroy_block, create_each_block_2, null, get_each_context_2);
				check_outros();
			}

			if (!current || dirty[0] & /*column_widths*/ 2048) {
				toggle_class(table_1, "fixed-layout", /*column_widths*/ ctx[11].length != 0);
			}

			const upload_changes = {};
			if (dirty[0] & /*root*/ 128) upload_changes.root = /*root*/ ctx[7];

			if (dirty[0] & /*t_width, height, data, styling, selected, display_value, latex_delimiters, line_breaks, editable, editing, datatype, clear_on_focus, els, parent, _headers, sort_by, sort_direction, header_edit, selected_header, select_on_focus, label*/ 938468915 | dirty[1] & /*selected_index, table_height, scrollbar_width*/ 7 | dirty[3] & /*$$scope*/ 2) {
				upload_changes.$$scope = { dirty, ctx };
			}

			if (!updating_dragging && dirty[0] & /*dragging*/ 134217728) {
				updating_dragging = true;
				upload_changes.dragging = /*dragging*/ ctx[27];
				add_flush_callback(() => updating_dragging = false);
			}

			upload.$set(upload_changes);

			if (!current || dirty[1] & /*table_height*/ 1) {
				set_style(div0, "height", /*table_height*/ ctx[31] + "px");
			}

			if (!current || dirty[0] & /*dragging*/ 134217728) {
				toggle_class(div0, "dragging", /*dragging*/ ctx[27]);
			}

			if (!current || dirty[0] & /*wrap*/ 64) {
				toggle_class(div0, "no-wrap", !/*wrap*/ ctx[6]);
			}

			if (/*editable*/ ctx[5]) {
				if (if_block2) {
					if_block2.p(ctx, dirty);

					if (dirty[0] & /*editable*/ 32) {
						transition_in$1(if_block2, 1);
					}
				} else {
					if_block2 = create_if_block(ctx);
					if_block2.c();
					transition_in$1(if_block2, 1);
					if_block2.m(div1, null);
				}
			} else if (if_block2) {
				group_outros();

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

				check_outros();
			}

			if (!current || dirty[0] & /*label*/ 2) {
				toggle_class(div1, "label", /*label*/ ctx[1] && /*label*/ ctx[1].length !== 0);
			}
		},
		i(local) {
			if (current) return;

			for (let i = 0; i < each_value_3.length; i += 1) {
				transition_in$1(each_blocks_1[i]);
			}

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

			transition_in$1(upload.$$.fragment, local);
			transition_in$1(if_block2);
			current = true;
		},
		o(local) {
			for (let i = 0; i < each_blocks_1.length; i += 1) {
				transition_out$1(each_blocks_1[i]);
			}

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

			transition_out$1(upload.$$.fragment, local);
			transition_out$1(if_block2);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach$1(div1);
			}

			if (if_block0) if_block0.d();
			if (if_block1) if_block1.d();

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

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

			table_1_resize_listener();
			/*table_1_binding*/ ctx[54](null);
			destroy_component$1(upload);
			/*div0_binding*/ ctx[70](null);
			if (if_block2) if_block2.d();
			mounted = false;
			run_all(dispose);
		}
	};
}

function make_id() {
	return Math.random().toString(36).substring(2, 15);
}

function guess_delimitaor(text, possibleDelimiters) {
	return possibleDelimiters.filter(weedOut);

	function weedOut(delimiter) {
		var cache = -1;
		return text.split("\n").every(checkLength);

		function checkLength(line) {
			if (!line) {
				return true;
			}

			var length = line.split(delimiter).length;

			if (cache < 0) {
				cache = length;
			}

			return cache === length && length > 1;
		}
	}
}

function data_uri_to_blob(data_uri) {
	const byte_str = atob(data_uri.split(",")[1]);
	const mime_str = data_uri.split(",")[0].split(":")[1].split(";")[0];
	const ab = new ArrayBuffer(byte_str.length);
	const ia = new Uint8Array(ab);

	for (let i = 0; i < byte_str.length; i++) {
		ia[i] = byte_str.charCodeAt(i);
	}

	return new Blob([ab], { type: mime_str });
}

function instance$1($$self, $$props, $$invalidate) {
	let max;
	let selected_index;
	let { datatype } = $$props;
	let { label = null } = $$props;
	let { headers = [] } = $$props;
	let values;
	let { value } = $$props;
	let { col_count } = $$props;
	let { row_count } = $$props;
	let { latex_delimiters } = $$props;
	let { editable = true } = $$props;
	let { wrap = false } = $$props;
	let { root } = $$props;
	let { i18n } = $$props;
	let { height = 500 } = $$props;
	let { line_breaks = true } = $$props;
	let { column_widths = [] } = $$props;
	let selected = false;
	let display_value = value?.metadata?.display_value ?? null;
	let styling = value?.metadata?.styling ?? null;
	const dispatch = createEventDispatcher();
	let editing = false;
	const get_data_at = (row, col) => data?.[row]?.[col]?.value;
	let els = {};

	function make_headers(_head) {
		let _h = _head || [];

		if (col_count[1] === "fixed" && _h.length < col_count[0]) {
			const fill = Array(col_count[0] - _h.length).fill("").map((_, i) => `${i + _h.length}`);
			_h = _h.concat(fill);
		}

		if (!_h || _h.length === 0) {
			return Array(col_count[0]).fill(0).map((_, i) => {
				const _id = make_id();
				$$invalidate(22, els[_id] = { cell: null, input: null }, els);
				return { id: _id, value: JSON.stringify(i + 1) };
			});
		}

		return _h.map((h, i) => {
			const _id = make_id();
			$$invalidate(22, els[_id] = { cell: null, input: null }, els);
			return { id: _id, value: h ?? "" };
		});
	}

	function process_data(_values) {
		const data_row_length = _values.length;

		return Array(row_count[1] === "fixed"
		? row_count[0]
		: data_row_length < row_count[0]
			? row_count[0]
			: data_row_length).fill(0).map((_, i) => Array(col_count[1] === "fixed"
		? col_count[0]
		: data_row_length > 0 ? _values[0].length : headers.length).fill(0).map((_, j) => {
			const id = make_id();
			$$invalidate(22, els[id] = els[id] || { input: null, cell: null }, els);
			const obj = { value: _values?.[i]?.[j] ?? "", id };
			return obj;
		}));
	}

	let _headers = make_headers(headers);
	let old_headers;

	function trigger_headers() {
		$$invalidate(16, _headers = make_headers(headers));
		$$invalidate(49, old_headers = headers.slice());
	}

	let data = [[]];
	let old_val = undefined;

	function get_sort_status(name, _sort, direction) {
		if (!_sort) return "none";

		if (headers[_sort] === name) {
			if (direction === "asc") return "ascending";
			if (direction === "des") return "descending";
		}

		return "none";
	}

	function get_current_indices(id) {
		return data.reduce(
			(acc, arr, i) => {
				const j = arr.reduce((_acc, _data, k) => id === _data.id ? k : _acc, -1);
				return j === -1 ? acc : [i, j];
			},
			[-1, -1]
		);
	}

	async function start_edit(i, j) {
		if (!editable || dequal(editing, [i, j])) return;
		$$invalidate(21, editing = [i, j]);
	}

	function move_cursor(key, current_coords) {
		const dir = ({
			ArrowRight: [0, 1],
			ArrowLeft: [0, -1],
			ArrowDown: [1, 0],
			ArrowUp: [-1, 0]
		})[key];

		const i = current_coords[0] + dir[0];
		const j = current_coords[1] + dir[1];

		if (i < 0 && j <= 0) {
			$$invalidate(26, selected_header = j);
			$$invalidate(13, selected = false);
		} else {
			const is_data = data[i]?.[j];
			$$invalidate(13, selected = is_data ? [i, j] : selected);
		}
	}

	let clear_on_focus = false;

	// eslint-disable-next-line complexity
	async function handle_keydown(event) {
		if (selected_header !== false && header_edit === false) {
			switch (event.key) {
				case "ArrowDown":
					$$invalidate(13, selected = [0, selected_header]);
					$$invalidate(26, selected_header = false);
					return;
				case "ArrowLeft":
					$$invalidate(26, selected_header = selected_header > 0
					? selected_header - 1
					: selected_header);
					return;
				case "ArrowRight":
					$$invalidate(26, selected_header = selected_header < _headers.length - 1
					? selected_header + 1
					: selected_header);
					return;
				case "Escape":
					event.preventDefault();
					$$invalidate(26, selected_header = false);
					break;
				case "Enter":
					event.preventDefault();
					break;
			}
		}

		if (!selected) {
			return;
		}

		const [i, j] = selected;

		switch (event.key) {
			case "ArrowRight":
			case "ArrowLeft":
			case "ArrowDown":
			case "ArrowUp":
				if (editing) break;
				event.preventDefault();
				move_cursor(event.key, [i, j]);
				break;
			case "Escape":
				if (!editable) break;
				event.preventDefault();
				$$invalidate(21, editing = false);
				break;
			case "Enter":
				if (!editable) break;
				event.preventDefault();
				if (event.shiftKey) {
					add_row(i);
					await tick();
					$$invalidate(13, selected = [i + 1, j]);
				} else {
					if (dequal(editing, [i, j])) {
						$$invalidate(21, editing = false);
						await tick();
						$$invalidate(13, selected = [i, j]);
					} else {
						$$invalidate(21, editing = [i, j]);
					}
				}
				break;
			case "Backspace":
				if (!editable) break;
				if (!editing) {
					event.preventDefault();
					$$invalidate(17, data[i][j].value = "", data);
				}
				break;
			case "Delete":
				if (!editable) break;
				if (!editing) {
					event.preventDefault();
					$$invalidate(17, data[i][j].value = "", data);
				}
				break;
			case "Tab":
				let direction = event.shiftKey ? -1 : 1;
				let is_data_x = data[i][j + direction];
				let is_data_y = data?.[i + direction]?.[direction > 0 ? 0 : _headers.length - 1];
				if (is_data_x || is_data_y) {
					event.preventDefault();

					$$invalidate(13, selected = is_data_x
					? [i, j + direction]
					: [i + direction, direction > 0 ? 0 : _headers.length - 1]);
				}
				$$invalidate(21, editing = false);
				break;
			default:
				if (!editable) break;
				if ((!editing || editing && dequal(editing, [i, j])) && event.key.length === 1) {
					$$invalidate(23, clear_on_focus = true);
					$$invalidate(21, editing = [i, j]);
				}
		}
	}

	async function handle_cell_click(i, j) {
		if (dequal(editing, [i, j])) return;
		$$invalidate(24, header_edit = false);
		$$invalidate(26, selected_header = false);
		$$invalidate(21, editing = false);
		$$invalidate(13, selected = [i, j]);
		await tick();
		parent.focus();
	}

	let sort_direction;
	let sort_by;

	function handle_sort(col) {
		if (typeof sort_by !== "number" || sort_by !== col) {
			$$invalidate(18, sort_direction = "asc");
			$$invalidate(19, sort_by = col);
		} else {
			if (sort_direction === "asc") {
				$$invalidate(18, sort_direction = "des");
			} else if (sort_direction === "des") {
				$$invalidate(18, sort_direction = "asc");
			}
		}
	}

	let header_edit;
	let select_on_focus = false;
	let selected_header = false;

	async function edit_header(i, _select = false) {
		if (!editable || col_count[1] !== "dynamic" || header_edit === i) return;
		$$invalidate(13, selected = false);
		$$invalidate(26, selected_header = i);
		$$invalidate(24, header_edit = i);
		$$invalidate(25, select_on_focus = _select);
	}

	function end_header_edit(event) {
		if (!editable) return;

		switch (event.key) {
			case "Escape":
			case "Enter":
			case "Tab":
				event.preventDefault();
				$$invalidate(13, selected = false);
				$$invalidate(26, selected_header = header_edit);
				$$invalidate(24, header_edit = false);
				parent.focus();
				break;
		}
	}

	async function add_row(index) {
		parent.focus();
		if (row_count[1] !== "dynamic") return;

		if (data.length === 0) {
			$$invalidate(48, values = [Array(headers.length).fill("")]);
			return;
		}

		data.splice(index ? index + 1 : data.length, 0, Array(data[0].length).fill(0).map((_, i) => {
			const _id = make_id();
			$$invalidate(22, els[_id] = { cell: null, input: null }, els);
			return { id: _id, value: "" };
		}));

		((($$invalidate(17, data), $$invalidate(48, values)), $$invalidate(50, old_val)), $$invalidate(12, value));
		$$invalidate(13, selected = [index ? index + 1 : data.length - 1, 0]);
	}

	async function add_col() {
		parent.focus();
		if (col_count[1] !== "dynamic") return;

		for (let i = 0; i < data.length; i++) {
			const _id = make_id();
			$$invalidate(22, els[_id] = { cell: null, input: null }, els);
			data[i].push({ id: _id, value: "" });
		}

		headers.push(`Header ${headers.length + 1}`);
		((($$invalidate(17, data), $$invalidate(48, values)), $$invalidate(50, old_val)), $$invalidate(12, value));
		(($$invalidate(47, headers), $$invalidate(12, value)), $$invalidate(48, values));
		await tick();

		requestAnimationFrame(() => {
			edit_header(headers.length - 1, true);
			const new_w = parent.querySelectorAll("tbody")[1].offsetWidth;
			parent.querySelectorAll("table")[1].scrollTo({ left: new_w });
		});
	}

	function handle_click_outside(event) {
		event.stopImmediatePropagation();
		const [trigger] = event.composedPath();

		if (parent.contains(trigger)) {
			return;
		}

		$$invalidate(21, editing = false);
		$$invalidate(24, header_edit = false);
		$$invalidate(26, selected_header = false);
		$$invalidate(13, selected = false);
	}

	function blob_to_string(blob) {
		const reader = new FileReader();

		function handle_read(e) {
			if (!e?.target?.result || typeof e.target.result !== "string") return;
			const [delimiter] = guess_delimitaor(e.target.result, [",", "\t"]);
			const [head, ...rest] = dsvFormat(delimiter).parseRows(e.target.result);

			$$invalidate(16, _headers = make_headers(col_count[1] === "fixed"
			? head.slice(0, col_count[0])
			: head));

			$$invalidate(48, values = rest);
			reader.removeEventListener("loadend", handle_read);
		}

		reader.addEventListener("loadend", handle_read);
		reader.readAsText(blob);
	}

	let dragging = false;
	let t_width = 0;

	function get_max(_d) {
		let max = _d[0].slice();

		for (let i = 0; i < _d.length; i++) {
			for (let j = 0; j < _d[i].length; j++) {
				if (`${max[j].value}`.length < `${_d[i][j].value}`.length) {
					max[j] = _d[i][j];
				}
			}
		}

		return max;
	}

	let cells = [];
	let parent;
	let table;

	function set_cell_widths() {
		const widths = cells.map((el, i) => {
			return el?.clientWidth || 0;
		});

		if (widths.length === 0) return;

		for (let i = 0; i < widths.length; i++) {
			parent.style.setProperty(`--cell-width-${i}`, `${widths[i] - scrollbar_width / widths.length}px`);
		}
	}

	let table_height = height;
	let scrollbar_width = 0;

	function sort_data(_data, _display_value, _styling, col, dir) {
		let id = null;

		//Checks if the selected cell is still in the data
		if (selected && selected[0] in data && selected[1] in data[selected[0]]) {
			id = data[selected[0]][selected[1]].id;
		}

		if (typeof col !== "number" || !dir) {
			return;
		}

		const indices = [...Array(_data.length).keys()];

		if (dir === "asc") {
			indices.sort((i, j) => _data[i][col].value < _data[j][col].value ? -1 : 1);
		} else if (dir === "des") {
			indices.sort((i, j) => _data[i][col].value > _data[j][col].value ? -1 : 1);
		} else {
			return;
		}

		// sort all the data and metadata based on the values in the data
		const temp_data = [..._data];

		const temp_display_value = _display_value ? [..._display_value] : null;
		const temp_styling = _styling ? [..._styling] : null;

		indices.forEach((originalIndex, sortedIndex) => {
			_data[sortedIndex] = temp_data[originalIndex];
			if (_display_value && temp_display_value) _display_value[sortedIndex] = temp_display_value[originalIndex];
			if (_styling && temp_styling) _styling[sortedIndex] = temp_styling[originalIndex];
		});

		((($$invalidate(17, data), $$invalidate(48, values)), $$invalidate(50, old_val)), $$invalidate(12, value));

		if (id) {
			const [i, j] = get_current_indices(id);
			$$invalidate(13, selected = [i, j]);
		}
	}

	let is_visible = false;

	onMount(() => {
		const observer = new IntersectionObserver((entries, observer) => {
				entries.forEach(entry => {
					if (entry.isIntersecting && !is_visible) {
						set_cell_widths();
						((($$invalidate(17, data), $$invalidate(48, values)), $$invalidate(50, old_val)), $$invalidate(12, value));
					}

					is_visible = entry.isIntersecting;
				});
			});

		observer.observe(parent);

		return () => {
			observer.disconnect();
		};
	});

	const resize_handler = () => set_cell_widths();

	function td_binding($$value, j) {
		binding_callbacks[$$value ? 'unshift' : 'push'](() => {
			cells[j] = $$value;
			$$invalidate(20, cells);
		});
	}

	function table_1_elementresize_handler() {
		t_width = this.clientWidth;
		$$invalidate(28, t_width);
	}

	function table_1_binding($$value) {
		binding_callbacks[$$value ? 'unshift' : 'push'](() => {
			table = $$value;
			$$invalidate(30, table);
		});
	}

	function editablecell_value_binding(value$1, index, j) {
		if ($$self.$$.not_equal(data[index][j].value, value$1)) {
			data[index][j].value = value$1;
			((($$invalidate(17, data), $$invalidate(48, values)), $$invalidate(50, old_val)), $$invalidate(12, value));
		}
	}

	function editablecell_el_binding(value, id) {
		if ($$self.$$.not_equal(els[id].input, value)) {
			els[id].input = value;
			$$invalidate(22, els);
		}
	}

	const blur_handler = () => ($$invalidate(23, clear_on_focus = false), parent.focus());
	const touchstart_handler = (index, j) => start_edit(index, j);
	const click_handler = (index, j) => handle_cell_click(index, j);
	const dblclick_handler = (index, j) => start_edit(index, j);

	function editablecell_value_binding_1(value, i) {
		if ($$self.$$.not_equal(_headers[i].value, value)) {
			_headers[i].value = value;
			$$invalidate(16, _headers);
		}
	}

	function editablecell_el_binding_1(value, id) {
		if ($$self.$$.not_equal(els[id].input, value)) {
			els[id].input = value;
			$$invalidate(22, els);
		}
	}

	const dblclick_handler_1 = i => edit_header(i);
	const click_handler_1 = i => handle_sort(i);

	function virtualtable_items_binding(value$1) {
		data = value$1;
		((($$invalidate(17, data), $$invalidate(48, values)), $$invalidate(50, old_val)), $$invalidate(12, value));
	}

	function virtualtable_actual_height_binding(value) {
		table_height = value;
		$$invalidate(31, table_height);
	}

	function virtualtable_table_scrollbar_width_binding(value) {
		scrollbar_width = value;
		$$invalidate(32, scrollbar_width);
	}

	function upload_dragging_binding(value) {
		dragging = value;
		$$invalidate(27, dragging);
	}

	const load_handler = e => blob_to_string(data_uri_to_blob(e.detail.data));

	function div0_binding($$value) {
		binding_callbacks[$$value ? 'unshift' : 'push'](() => {
			parent = $$value;
			$$invalidate(29, parent);
		});
	}

	const keydown_handler = e => handle_keydown(e);
	const click_handler_2 = e => (e.stopPropagation(), add_row());
	const click_handler_3 = e => (e.stopPropagation(), add_col());

	$$self.$$set = $$props => {
		if ('datatype' in $$props) $$invalidate(0, datatype = $$props.datatype);
		if ('label' in $$props) $$invalidate(1, label = $$props.label);
		if ('headers' in $$props) $$invalidate(47, headers = $$props.headers);
		if ('value' in $$props) $$invalidate(12, value = $$props.value);
		if ('col_count' in $$props) $$invalidate(2, col_count = $$props.col_count);
		if ('row_count' in $$props) $$invalidate(3, row_count = $$props.row_count);
		if ('latex_delimiters' in $$props) $$invalidate(4, latex_delimiters = $$props.latex_delimiters);
		if ('editable' in $$props) $$invalidate(5, editable = $$props.editable);
		if ('wrap' in $$props) $$invalidate(6, wrap = $$props.wrap);
		if ('root' in $$props) $$invalidate(7, root = $$props.root);
		if ('i18n' in $$props) $$invalidate(8, i18n = $$props.i18n);
		if ('height' in $$props) $$invalidate(9, height = $$props.height);
		if ('line_breaks' in $$props) $$invalidate(10, line_breaks = $$props.line_breaks);
		if ('column_widths' in $$props) $$invalidate(11, column_widths = $$props.column_widths);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty[0] & /*value*/ 4096 | $$self.$$.dirty[1] & /*values*/ 131072) {
			{
				if (value) {
					$$invalidate(47, headers = value.headers);
					$$invalidate(48, values = value.data);
					$$invalidate(14, display_value = value?.metadata?.display_value ?? null);
					$$invalidate(15, styling = value?.metadata?.styling ?? null);
				} else if (values === null) {
					$$invalidate(48, values = []);
				}
			}
		}

		if ($$self.$$.dirty[0] & /*selected*/ 8192) {
			{
				if (selected !== false) {
					const [row, col] = selected;

					if (!isNaN(row) && !isNaN(col)) {
						dispatch("select", {
							index: [row, col],
							value: get_data_at(row, col)
						});
					}
				}
			}
		}

		if ($$self.$$.dirty[1] & /*headers, old_headers*/ 327680) {
			{
				if (!dequal(headers, old_headers)) {
					trigger_headers();
				}
			}
		}

		if ($$self.$$.dirty[1] & /*values, old_val*/ 655360) {
			if (!dequal(values, old_val)) {
				$$invalidate(17, data = process_data(values));
				$$invalidate(50, old_val = values);
			}
		}

		if ($$self.$$.dirty[0] & /*_headers, data, editable, display_value, styling*/ 245792) {
			_headers && dispatch("change", {
				data: data.map(r => r.map(({ value }) => value)),
				headers: _headers.map(h => h.value),
				metadata: editable ? null : { display_value, styling }
			});
		}

		if ($$self.$$.dirty[0] & /*data*/ 131072) {
			$$invalidate(34, max = get_max(data));
		}

		if ($$self.$$.dirty[0] & /*cells*/ 1048576) {
			cells[0] && set_cell_widths();
		}

		if ($$self.$$.dirty[0] & /*data, display_value, styling, sort_by, sort_direction*/ 966656) {
			sort_data(data, display_value, styling, sort_by, sort_direction);
		}

		if ($$self.$$.dirty[0] & /*selected*/ 8192) {
			$$invalidate(33, selected_index = !!selected && selected[0]);
		}
	};

	return [
		datatype,
		label,
		col_count,
		row_count,
		latex_delimiters,
		editable,
		wrap,
		root,
		i18n,
		height,
		line_breaks,
		column_widths,
		value,
		selected,
		display_value,
		styling,
		_headers,
		data,
		sort_direction,
		sort_by,
		cells,
		editing,
		els,
		clear_on_focus,
		header_edit,
		select_on_focus,
		selected_header,
		dragging,
		t_width,
		parent,
		table,
		table_height,
		scrollbar_width,
		selected_index,
		max,
		get_sort_status,
		start_edit,
		handle_keydown,
		handle_cell_click,
		handle_sort,
		edit_header,
		end_header_edit,
		add_row,
		add_col,
		handle_click_outside,
		blob_to_string,
		set_cell_widths,
		headers,
		values,
		old_headers,
		old_val,
		resize_handler,
		td_binding,
		table_1_elementresize_handler,
		table_1_binding,
		editablecell_value_binding,
		editablecell_el_binding,
		blur_handler,
		touchstart_handler,
		click_handler,
		dblclick_handler,
		editablecell_value_binding_1,
		editablecell_el_binding_1,
		dblclick_handler_1,
		click_handler_1,
		virtualtable_items_binding,
		virtualtable_actual_height_binding,
		virtualtable_table_scrollbar_width_binding,
		upload_dragging_binding,
		load_handler,
		div0_binding,
		keydown_handler,
		click_handler_2,
		click_handler_3
	];
}

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

		init$1(
			this,
			options,
			instance$1,
			create_fragment$1,
			safe_not_equal$1,
			{
				datatype: 0,
				label: 1,
				headers: 47,
				value: 12,
				col_count: 2,
				row_count: 3,
				latex_delimiters: 4,
				editable: 5,
				wrap: 6,
				root: 7,
				i18n: 8,
				height: 9,
				line_breaks: 10,
				column_widths: 11
			},
			null,
			[-1, -1, -1, -1]
		);
	}
}

const Table$1 = Table;

/* home/runner/work/gradio/gradio/js/dataframe/Index.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent,
	assign,
	create_component,
	destroy_component,
	detach,
	get_spread_object,
	get_spread_update,
	init,
	insert,
	mount_component,
	safe_not_equal,
	space,
	transition_in,
	transition_out
} = window.__gradio__svelte__internal;
const { afterUpdate } = window.__gradio__svelte__internal;
function create_default_slot(ctx) {
	let statustracker;
	let t;
	let table;
	let current;

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

	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 });

	table = new Table$1({
			props: {
				root: /*root*/ ctx[12],
				label: /*label*/ ctx[7],
				row_count: /*row_count*/ ctx[6],
				col_count: /*col_count*/ ctx[5],
				value: /*value*/ ctx[0],
				headers: /*headers*/ ctx[1],
				wrap: /*wrap*/ ctx[8],
				datatype: /*datatype*/ ctx[9],
				latex_delimiters: /*latex_delimiters*/ ctx[16],
				editable: /*interactive*/ ctx[19],
				height: /*height*/ ctx[17],
				i18n: /*gradio*/ ctx[15].i18n,
				line_breaks: /*line_breaks*/ ctx[13],
				column_widths: /*column_widths*/ ctx[14]
			}
		});

	table.$on("select", /*select_handler*/ ctx[22]);

	return {
		c() {
			create_component(statustracker.$$.fragment);
			t = space();
			create_component(table.$$.fragment);
		},
		m(target, anchor) {
			mount_component(statustracker, target, anchor);
			insert(target, t, anchor);
			mount_component(table, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const statustracker_changes = (dirty & /*gradio, loading_status*/ 294912)
			? get_spread_update(statustracker_spread_levels, [
					dirty & /*gradio*/ 32768 && {
						autoscroll: /*gradio*/ ctx[15].autoscroll
					},
					dirty & /*gradio*/ 32768 && { i18n: /*gradio*/ ctx[15].i18n },
					dirty & /*loading_status*/ 262144 && get_spread_object(/*loading_status*/ ctx[18])
				])
			: {};

			statustracker.$set(statustracker_changes);
			const table_changes = {};
			if (dirty & /*root*/ 4096) table_changes.root = /*root*/ ctx[12];
			if (dirty & /*label*/ 128) table_changes.label = /*label*/ ctx[7];
			if (dirty & /*row_count*/ 64) table_changes.row_count = /*row_count*/ ctx[6];
			if (dirty & /*col_count*/ 32) table_changes.col_count = /*col_count*/ ctx[5];
			if (dirty & /*value*/ 1) table_changes.value = /*value*/ ctx[0];
			if (dirty & /*headers*/ 2) table_changes.headers = /*headers*/ ctx[1];
			if (dirty & /*wrap*/ 256) table_changes.wrap = /*wrap*/ ctx[8];
			if (dirty & /*datatype*/ 512) table_changes.datatype = /*datatype*/ ctx[9];
			if (dirty & /*latex_delimiters*/ 65536) table_changes.latex_delimiters = /*latex_delimiters*/ ctx[16];
			if (dirty & /*interactive*/ 524288) table_changes.editable = /*interactive*/ ctx[19];
			if (dirty & /*height*/ 131072) table_changes.height = /*height*/ ctx[17];
			if (dirty & /*gradio*/ 32768) table_changes.i18n = /*gradio*/ ctx[15].i18n;
			if (dirty & /*line_breaks*/ 8192) table_changes.line_breaks = /*line_breaks*/ ctx[13];
			if (dirty & /*column_widths*/ 16384) table_changes.column_widths = /*column_widths*/ ctx[14];
			table.$set(table_changes);
		},
		i(local) {
			if (current) return;
			transition_in(statustracker.$$.fragment, local);
			transition_in(table.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(statustracker.$$.fragment, local);
			transition_out(table.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(t);
			}

			destroy_component(statustracker, detaching);
			destroy_component(table, detaching);
		}
	};
}

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

	block = new Block({
			props: {
				visible: /*visible*/ ctx[4],
				padding: false,
				elem_id: /*elem_id*/ ctx[2],
				elem_classes: /*elem_classes*/ ctx[3],
				container: false,
				scale: /*scale*/ ctx[10],
				min_width: /*min_width*/ ctx[11],
				allow_overflow: false,
				$$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*/ 16) block_changes.visible = /*visible*/ ctx[4];
			if (dirty & /*elem_id*/ 4) block_changes.elem_id = /*elem_id*/ ctx[2];
			if (dirty & /*elem_classes*/ 8) block_changes.elem_classes = /*elem_classes*/ ctx[3];
			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 & /*$$scope, root, label, row_count, col_count, value, headers, wrap, datatype, latex_delimiters, interactive, height, gradio, line_breaks, column_widths, loading_status*/ 17822691) {
				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 { headers = [] } = $$props;
	let { elem_id = "" } = $$props;
	let { elem_classes = [] } = $$props;
	let { visible = true } = $$props;

	let { value = {
		data: [["", "", ""]],
		headers: ["1", "2", "3"],
		metadata: null
	} } = $$props;

	let old_value = JSON.stringify(value);
	let { value_is_output = false } = $$props;
	let { col_count } = $$props;
	let { row_count } = $$props;
	let { label = null } = $$props;
	let { wrap } = $$props;
	let { datatype } = $$props;
	let { scale = null } = $$props;
	let { min_width = undefined } = $$props;
	let { root } = $$props;
	let { line_breaks = true } = $$props;
	let { column_widths = [] } = $$props;
	let { gradio } = $$props;
	let { latex_delimiters } = $$props;
	let { height = undefined } = $$props;
	let { loading_status } = $$props;
	let { interactive } = $$props;

	function handle_change() {
		gradio.dispatch("change");

		if (!value_is_output) {
			gradio.dispatch("input");
		}
	}

	afterUpdate(() => {
		$$invalidate(20, value_is_output = false);
	});

	if (Array.isArray(value) && value?.[0]?.length === 0 || value.data?.[0]?.length === 0) {
		value = {
			data: [Array(col_count?.[0] || 3).fill("")],
			headers: Array(col_count?.[0] || 3).fill("").map((_, i) => `${i + 1}`),
			metadata: null
		};
	}

	const select_handler = e => gradio.dispatch("select", e.detail);

	$$self.$$set = $$props => {
		if ('headers' in $$props) $$invalidate(1, headers = $$props.headers);
		if ('elem_id' in $$props) $$invalidate(2, elem_id = $$props.elem_id);
		if ('elem_classes' in $$props) $$invalidate(3, elem_classes = $$props.elem_classes);
		if ('visible' in $$props) $$invalidate(4, visible = $$props.visible);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('value_is_output' in $$props) $$invalidate(20, value_is_output = $$props.value_is_output);
		if ('col_count' in $$props) $$invalidate(5, col_count = $$props.col_count);
		if ('row_count' in $$props) $$invalidate(6, row_count = $$props.row_count);
		if ('label' in $$props) $$invalidate(7, label = $$props.label);
		if ('wrap' in $$props) $$invalidate(8, wrap = $$props.wrap);
		if ('datatype' in $$props) $$invalidate(9, datatype = $$props.datatype);
		if ('scale' in $$props) $$invalidate(10, scale = $$props.scale);
		if ('min_width' in $$props) $$invalidate(11, min_width = $$props.min_width);
		if ('root' in $$props) $$invalidate(12, root = $$props.root);
		if ('line_breaks' in $$props) $$invalidate(13, line_breaks = $$props.line_breaks);
		if ('column_widths' in $$props) $$invalidate(14, column_widths = $$props.column_widths);
		if ('gradio' in $$props) $$invalidate(15, gradio = $$props.gradio);
		if ('latex_delimiters' in $$props) $$invalidate(16, latex_delimiters = $$props.latex_delimiters);
		if ('height' in $$props) $$invalidate(17, height = $$props.height);
		if ('loading_status' in $$props) $$invalidate(18, loading_status = $$props.loading_status);
		if ('interactive' in $$props) $$invalidate(19, interactive = $$props.interactive);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty & /*value, old_value*/ 2097153) {
			{
				if (JSON.stringify(value) !== old_value) {
					$$invalidate(21, old_value = JSON.stringify(value));
					handle_change();
				}
			}
		}
	};

	return [
		value,
		headers,
		elem_id,
		elem_classes,
		visible,
		col_count,
		row_count,
		label,
		wrap,
		datatype,
		scale,
		min_width,
		root,
		line_breaks,
		column_widths,
		gradio,
		latex_delimiters,
		height,
		loading_status,
		interactive,
		value_is_output,
		old_value,
		select_handler
	];
}

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

		init(this, options, instance, create_fragment, safe_not_equal, {
			headers: 1,
			elem_id: 2,
			elem_classes: 3,
			visible: 4,
			value: 0,
			value_is_output: 20,
			col_count: 5,
			row_count: 6,
			label: 7,
			wrap: 8,
			datatype: 9,
			scale: 10,
			min_width: 11,
			root: 12,
			line_breaks: 13,
			column_widths: 14,
			gradio: 15,
			latex_delimiters: 16,
			height: 17,
			loading_status: 18,
			interactive: 19
		});
	}
}

export { Table$1 as BaseDataFrame, Index as default };
//# sourceMappingURL=Index-2d49afdc.js.map
