diff --git "a/src/backend/gradio_unifiedaudio/templates/component/index.js" "b/src/backend/gradio_unifiedaudio/templates/component/index.js" --- "a/src/backend/gradio_unifiedaudio/templates/component/index.js" +++ "b/src/backend/gradio_unifiedaudio/templates/component/index.js" @@ -1,8 +1,7562 @@ -import { E as s, a as t, A as i, S as o, I as r } from "./index-fdcab7e8.js"; +const No = [ + { color: "red", primary: 600, secondary: 100 }, + { color: "green", primary: 600, secondary: 100 }, + { color: "blue", primary: 600, secondary: 100 }, + { color: "yellow", primary: 500, secondary: 100 }, + { color: "purple", primary: 600, secondary: 100 }, + { color: "teal", primary: 600, secondary: 100 }, + { color: "orange", primary: 600, secondary: 100 }, + { color: "cyan", primary: 600, secondary: 100 }, + { color: "lime", primary: 500, secondary: 100 }, + { color: "pink", primary: 600, secondary: 100 } +], In = { + inherit: "inherit", + current: "currentColor", + transparent: "transparent", + black: "#000", + white: "#fff", + slate: { + 50: "#f8fafc", + 100: "#f1f5f9", + 200: "#e2e8f0", + 300: "#cbd5e1", + 400: "#94a3b8", + 500: "#64748b", + 600: "#475569", + 700: "#334155", + 800: "#1e293b", + 900: "#0f172a", + 950: "#020617" + }, + gray: { + 50: "#f9fafb", + 100: "#f3f4f6", + 200: "#e5e7eb", + 300: "#d1d5db", + 400: "#9ca3af", + 500: "#6b7280", + 600: "#4b5563", + 700: "#374151", + 800: "#1f2937", + 900: "#111827", + 950: "#030712" + }, + zinc: { + 50: "#fafafa", + 100: "#f4f4f5", + 200: "#e4e4e7", + 300: "#d4d4d8", + 400: "#a1a1aa", + 500: "#71717a", + 600: "#52525b", + 700: "#3f3f46", + 800: "#27272a", + 900: "#18181b", + 950: "#09090b" + }, + neutral: { + 50: "#fafafa", + 100: "#f5f5f5", + 200: "#e5e5e5", + 300: "#d4d4d4", + 400: "#a3a3a3", + 500: "#737373", + 600: "#525252", + 700: "#404040", + 800: "#262626", + 900: "#171717", + 950: "#0a0a0a" + }, + stone: { + 50: "#fafaf9", + 100: "#f5f5f4", + 200: "#e7e5e4", + 300: "#d6d3d1", + 400: "#a8a29e", + 500: "#78716c", + 600: "#57534e", + 700: "#44403c", + 800: "#292524", + 900: "#1c1917", + 950: "#0c0a09" + }, + red: { + 50: "#fef2f2", + 100: "#fee2e2", + 200: "#fecaca", + 300: "#fca5a5", + 400: "#f87171", + 500: "#ef4444", + 600: "#dc2626", + 700: "#b91c1c", + 800: "#991b1b", + 900: "#7f1d1d", + 950: "#450a0a" + }, + orange: { + 50: "#fff7ed", + 100: "#ffedd5", + 200: "#fed7aa", + 300: "#fdba74", + 400: "#fb923c", + 500: "#f97316", + 600: "#ea580c", + 700: "#c2410c", + 800: "#9a3412", + 900: "#7c2d12", + 950: "#431407" + }, + amber: { + 50: "#fffbeb", + 100: "#fef3c7", + 200: "#fde68a", + 300: "#fcd34d", + 400: "#fbbf24", + 500: "#f59e0b", + 600: "#d97706", + 700: "#b45309", + 800: "#92400e", + 900: "#78350f", + 950: "#451a03" + }, + yellow: { + 50: "#fefce8", + 100: "#fef9c3", + 200: "#fef08a", + 300: "#fde047", + 400: "#facc15", + 500: "#eab308", + 600: "#ca8a04", + 700: "#a16207", + 800: "#854d0e", + 900: "#713f12", + 950: "#422006" + }, + lime: { + 50: "#f7fee7", + 100: "#ecfccb", + 200: "#d9f99d", + 300: "#bef264", + 400: "#a3e635", + 500: "#84cc16", + 600: "#65a30d", + 700: "#4d7c0f", + 800: "#3f6212", + 900: "#365314", + 950: "#1a2e05" + }, + green: { + 50: "#f0fdf4", + 100: "#dcfce7", + 200: "#bbf7d0", + 300: "#86efac", + 400: "#4ade80", + 500: "#22c55e", + 600: "#16a34a", + 700: "#15803d", + 800: "#166534", + 900: "#14532d", + 950: "#052e16" + }, + emerald: { + 50: "#ecfdf5", + 100: "#d1fae5", + 200: "#a7f3d0", + 300: "#6ee7b7", + 400: "#34d399", + 500: "#10b981", + 600: "#059669", + 700: "#047857", + 800: "#065f46", + 900: "#064e3b", + 950: "#022c22" + }, + teal: { + 50: "#f0fdfa", + 100: "#ccfbf1", + 200: "#99f6e4", + 300: "#5eead4", + 400: "#2dd4bf", + 500: "#14b8a6", + 600: "#0d9488", + 700: "#0f766e", + 800: "#115e59", + 900: "#134e4a", + 950: "#042f2e" + }, + cyan: { + 50: "#ecfeff", + 100: "#cffafe", + 200: "#a5f3fc", + 300: "#67e8f9", + 400: "#22d3ee", + 500: "#06b6d4", + 600: "#0891b2", + 700: "#0e7490", + 800: "#155e75", + 900: "#164e63", + 950: "#083344" + }, + sky: { + 50: "#f0f9ff", + 100: "#e0f2fe", + 200: "#bae6fd", + 300: "#7dd3fc", + 400: "#38bdf8", + 500: "#0ea5e9", + 600: "#0284c7", + 700: "#0369a1", + 800: "#075985", + 900: "#0c4a6e", + 950: "#082f49" + }, + blue: { + 50: "#eff6ff", + 100: "#dbeafe", + 200: "#bfdbfe", + 300: "#93c5fd", + 400: "#60a5fa", + 500: "#3b82f6", + 600: "#2563eb", + 700: "#1d4ed8", + 800: "#1e40af", + 900: "#1e3a8a", + 950: "#172554" + }, + indigo: { + 50: "#eef2ff", + 100: "#e0e7ff", + 200: "#c7d2fe", + 300: "#a5b4fc", + 400: "#818cf8", + 500: "#6366f1", + 600: "#4f46e5", + 700: "#4338ca", + 800: "#3730a3", + 900: "#312e81", + 950: "#1e1b4b" + }, + violet: { + 50: "#f5f3ff", + 100: "#ede9fe", + 200: "#ddd6fe", + 300: "#c4b5fd", + 400: "#a78bfa", + 500: "#8b5cf6", + 600: "#7c3aed", + 700: "#6d28d9", + 800: "#5b21b6", + 900: "#4c1d95", + 950: "#2e1065" + }, + purple: { + 50: "#faf5ff", + 100: "#f3e8ff", + 200: "#e9d5ff", + 300: "#d8b4fe", + 400: "#c084fc", + 500: "#a855f7", + 600: "#9333ea", + 700: "#7e22ce", + 800: "#6b21a8", + 900: "#581c87", + 950: "#3b0764" + }, + fuchsia: { + 50: "#fdf4ff", + 100: "#fae8ff", + 200: "#f5d0fe", + 300: "#f0abfc", + 400: "#e879f9", + 500: "#d946ef", + 600: "#c026d3", + 700: "#a21caf", + 800: "#86198f", + 900: "#701a75", + 950: "#4a044e" + }, + pink: { + 50: "#fdf2f8", + 100: "#fce7f3", + 200: "#fbcfe8", + 300: "#f9a8d4", + 400: "#f472b6", + 500: "#ec4899", + 600: "#db2777", + 700: "#be185d", + 800: "#9d174d", + 900: "#831843", + 950: "#500724" + }, + rose: { + 50: "#fff1f2", + 100: "#ffe4e6", + 200: "#fecdd3", + 300: "#fda4af", + 400: "#fb7185", + 500: "#f43f5e", + 600: "#e11d48", + 700: "#be123c", + 800: "#9f1239", + 900: "#881337", + 950: "#4c0519" + } +}; +No.reduce( + (i, { color: e, primary: t, secondary: n }) => ({ + ...i, + [e]: { + primary: In[e][t], + secondary: In[e][n] + } + }), + {} +); +class Lt extends Error { + constructor(e) { + super(e), this.name = "ShareError"; + } +} +async function zo(i, e) { + var a; + if (window.__gradio_space__ == null) + throw new Lt("Must be on Spaces to share."); + let t, n, o; + { + const c = await fetch(i); + t = await c.blob(), n = c.headers.get("content-type") || "", o = c.headers.get("content-disposition") || ""; + } + const r = new File([t], o, { type: n }), s = await fetch("https://huggingface.co/uploads", { + method: "POST", + body: r, + headers: { + "Content-Type": r.type, + "X-Requested-With": "XMLHttpRequest" + } + }); + if (!s.ok) { + if ((a = s.headers.get("content-type")) != null && a.includes("application/json")) { + const c = await s.json(); + throw new Lt(`Upload failed: ${c.error}`); + } + throw new Lt("Upload failed."); + } + return await s.text(); +} +const { + SvelteComponent: Bo, + append: mn, + attr: Xe, + bubble: jo, + create_component: Io, + destroy_component: Fo, + detach: Ki, + element: pn, + init: Uo, + insert: Qi, + listen: Ho, + mount_component: Vo, + safe_not_equal: Go, + set_data: Xo, + space: Zo, + text: Jo, + toggle_class: qe, + transition_in: Yo, + transition_out: Ko +} = window.__gradio__svelte__internal; +function Fn(i) { + let e, t; + return { + c() { + e = pn("span"), t = Jo( + /*label*/ + i[1] + ), Xe(e, "class", "svelte-xtz2g8"); + }, + m(n, o) { + Qi(n, e, o), mn(e, t); + }, + p(n, o) { + o & /*label*/ + 2 && Xo( + t, + /*label*/ + n[1] + ); + }, + d(n) { + n && Ki(e); + } + }; +} +function Qo(i) { + let e, t, n, o, r, s, l, a = ( + /*show_label*/ + i[2] && Fn(i) + ); + return o = new /*Icon*/ + i[0]({}), { + c() { + e = pn("button"), a && a.c(), t = Zo(), n = pn("div"), Io(o.$$.fragment), Xe(n, "class", "svelte-xtz2g8"), qe( + n, + "small", + /*size*/ + i[4] === "small" + ), qe( + n, + "large", + /*size*/ + i[4] === "large" + ), Xe( + e, + "aria-label", + /*label*/ + i[1] + ), Xe( + e, + "title", + /*label*/ + i[1] + ), Xe(e, "class", "svelte-xtz2g8"), qe( + e, + "pending", + /*pending*/ + i[3] + ), qe( + e, + "padded", + /*padded*/ + i[5] + ); + }, + m(c, u) { + Qi(c, e, u), a && a.m(e, null), mn(e, t), mn(e, n), Vo(o, n, null), r = !0, s || (l = Ho( + e, + "click", + /*click_handler*/ + i[6] + ), s = !0); + }, + p(c, [u]) { + /*show_label*/ + c[2] ? a ? a.p(c, u) : (a = Fn(c), a.c(), a.m(e, t)) : a && (a.d(1), a = null), (!r || u & /*size*/ + 16) && qe( + n, + "small", + /*size*/ + c[4] === "small" + ), (!r || u & /*size*/ + 16) && qe( + n, + "large", + /*size*/ + c[4] === "large" + ), (!r || u & /*label*/ + 2) && Xe( + e, + "aria-label", + /*label*/ + c[1] + ), (!r || u & /*label*/ + 2) && Xe( + e, + "title", + /*label*/ + c[1] + ), (!r || u & /*pending*/ + 8) && qe( + e, + "pending", + /*pending*/ + c[3] + ), (!r || u & /*padded*/ + 32) && qe( + e, + "padded", + /*padded*/ + c[5] + ); + }, + i(c) { + r || (Yo(o.$$.fragment, c), r = !0); + }, + o(c) { + Ko(o.$$.fragment, c), r = !1; + }, + d(c) { + c && Ki(e), a && a.d(), Fo(o), s = !1, l(); + } + }; +} +function xo(i, e, t) { + let { Icon: n } = e, { label: o = "" } = e, { show_label: r = !1 } = e, { pending: s = !1 } = e, { size: l = "small" } = e, { padded: a = !0 } = e; + function c(u) { + jo.call(this, i, u); + } + return i.$$set = (u) => { + "Icon" in u && t(0, n = u.Icon), "label" in u && t(1, o = u.label), "show_label" in u && t(2, r = u.show_label), "pending" in u && t(3, s = u.pending), "size" in u && t(4, l = u.size), "padded" in u && t(5, a = u.padded); + }, [n, o, r, s, l, a, c]; +} +class $o extends Bo { + constructor(e) { + super(), Uo(this, e, xo, Qo, Go, { + Icon: 0, + label: 1, + show_label: 2, + pending: 3, + size: 4, + padded: 5 + }); + } +} +const { + SvelteComponent: es, + append: ts, + attr: Kt, + binding_callbacks: ns, + create_slot: is, + detach: os, + element: Un, + get_all_dirty_from_scope: ss, + get_slot_changes: rs, + init: ls, + insert: as, + safe_not_equal: cs, + toggle_class: We, + transition_in: us, + transition_out: ds, + update_slot_base: fs +} = window.__gradio__svelte__internal; +function hs(i) { + let e, t, n; + const o = ( + /*#slots*/ + i[5].default + ), r = is( + o, + i, + /*$$scope*/ + i[4], + null + ); + return { + c() { + e = Un("div"), t = Un("div"), r && r.c(), Kt(t, "class", "icon svelte-3w3rth"), Kt(e, "class", "empty svelte-3w3rth"), Kt(e, "aria-label", "Empty value"), We( + e, + "small", + /*size*/ + i[0] === "small" + ), We( + e, + "large", + /*size*/ + i[0] === "large" + ), We( + e, + "unpadded_box", + /*unpadded_box*/ + i[1] + ), We( + e, + "small_parent", + /*parent_height*/ + i[3] + ); + }, + m(s, l) { + as(s, e, l), ts(e, t), r && r.m(t, null), i[6](e), n = !0; + }, + p(s, [l]) { + r && r.p && (!n || l & /*$$scope*/ + 16) && fs( + r, + o, + s, + /*$$scope*/ + s[4], + n ? rs( + o, + /*$$scope*/ + s[4], + l, + null + ) : ss( + /*$$scope*/ + s[4] + ), + null + ), (!n || l & /*size*/ + 1) && We( + e, + "small", + /*size*/ + s[0] === "small" + ), (!n || l & /*size*/ + 1) && We( + e, + "large", + /*size*/ + s[0] === "large" + ), (!n || l & /*unpadded_box*/ + 2) && We( + e, + "unpadded_box", + /*unpadded_box*/ + s[1] + ), (!n || l & /*parent_height*/ + 8) && We( + e, + "small_parent", + /*parent_height*/ + s[3] + ); + }, + i(s) { + n || (us(r, s), n = !0); + }, + o(s) { + ds(r, s), n = !1; + }, + d(s) { + s && os(e), r && r.d(s), i[6](null); + } + }; +} +function _s(i, e, t) { + let n, { $$slots: o = {}, $$scope: r } = e, { size: s = "small" } = e, { unpadded_box: l = !1 } = e, a; + function c(d) { + var _; + if (!d) + return !1; + const { height: h } = d.getBoundingClientRect(), { height: f } = ((_ = d.parentElement) === null || _ === void 0 ? void 0 : _.getBoundingClientRect()) || { height: h }; + return h > f + 2; + } + function u(d) { + ns[d ? "unshift" : "push"](() => { + a = d, t(2, a); + }); + } + return i.$$set = (d) => { + "size" in d && t(0, s = d.size), "unpadded_box" in d && t(1, l = d.unpadded_box), "$$scope" in d && t(4, r = d.$$scope); + }, i.$$.update = () => { + i.$$.dirty & /*el*/ + 4 && t(3, n = c(a)); + }, [s, l, a, n, r, o, u]; +} +class xi extends es { + constructor(e) { + super(), ls(this, e, _s, hs, cs, { size: 0, unpadded_box: 1 }); + } +} +const { + SvelteComponent: ms, + append: ps, + attr: me, + detach: gs, + init: vs, + insert: bs, + noop: Qt, + safe_not_equal: ws, + svg_element: Hn +} = window.__gradio__svelte__internal; +function ys(i) { + let e, t; + return { + c() { + e = Hn("svg"), t = Hn("path"), me(t, "stroke", "currentColor"), me(t, "stroke-width", "1.5"), me(t, "stroke-linecap", "round"), me(t, "stroke-linejoin", "round"), me(t, "d", "M21.044 5.704a.6.6 0 0 1 .956.483v11.626a.6.6 0 0 1-.956.483l-7.889-5.813a.6.6 0 0 1 0-.966l7.89-5.813ZM10.044 5.704a.6.6 0 0 1 .956.483v11.626a.6.6 0 0 1-.956.483l-7.888-5.813a.6.6 0 0 1 0-.966l7.888-5.813Z"), me(e, "xmlns", "http://www.w3.org/2000/svg"), me(e, "width", "24px"), me(e, "height", "24px"), me(e, "fill", "currentColor"), me(e, "stroke-width", "1.5"), me(e, "viewBox", "0 0 24 24"), me(e, "color", "currentColor"); + }, + m(n, o) { + bs(n, e, o), ps(e, t); + }, + p: Qt, + i: Qt, + o: Qt, + d(n) { + n && gs(e); + } + }; +} +class ks extends ms { + constructor(e) { + super(), vs(this, e, null, ys, ws, {}); + } +} +const { + SvelteComponent: Cs, + append: Ss, + attr: _t, + detach: Es, + init: Ds, + insert: Rs, + noop: xt, + safe_not_equal: Ms, + svg_element: Vn +} = window.__gradio__svelte__internal; +function Ls(i) { + let e, t; + return { + c() { + e = Vn("svg"), t = Vn("path"), _t(t, "d", "M23,20a5,5,0,0,0-3.89,1.89L11.8,17.32a4.46,4.46,0,0,0,0-2.64l7.31-4.57A5,5,0,1,0,18,7a4.79,4.79,0,0,0,.2,1.32l-7.31,4.57a5,5,0,1,0,0,6.22l7.31,4.57A4.79,4.79,0,0,0,18,25a5,5,0,1,0,5-5ZM23,4a3,3,0,1,1-3,3A3,3,0,0,1,23,4ZM7,19a3,3,0,1,1,3-3A3,3,0,0,1,7,19Zm16,9a3,3,0,1,1,3-3A3,3,0,0,1,23,28Z"), _t(t, "fill", "currentColor"), _t(e, "id", "icon"), _t(e, "xmlns", "http://www.w3.org/2000/svg"), _t(e, "viewBox", "0 0 32 32"); + }, + m(n, o) { + Rs(n, e, o), Ss(e, t); + }, + p: xt, + i: xt, + o: xt, + d(n) { + n && Es(e); + } + }; +} +class Ps extends Cs { + constructor(e) { + super(), Ds(this, e, null, Ls, Ms, {}); + } +} +const { + SvelteComponent: Ts, + append: As, + attr: pe, + detach: Os, + init: qs, + insert: Ws, + noop: $t, + safe_not_equal: Ns, + svg_element: Gn +} = window.__gradio__svelte__internal; +function zs(i) { + let e, t; + return { + c() { + e = Gn("svg"), t = Gn("path"), pe(t, "stroke", "currentColor"), pe(t, "stroke-width", "1.5"), pe(t, "stroke-linecap", "round"), pe(t, "stroke-linejoin", "round"), pe(t, "d", "M2.956 5.704A.6.6 0 0 0 2 6.187v11.626a.6.6 0 0 0 .956.483l7.889-5.813a.6.6 0 0 0 0-.966l-7.89-5.813ZM13.956 5.704a.6.6 0 0 0-.956.483v11.626a.6.6 0 0 0 .956.483l7.889-5.813a.6.6 0 0 0 0-.966l-7.89-5.813Z"), pe(e, "xmlns", "http://www.w3.org/2000/svg"), pe(e, "width", "24px"), pe(e, "height", "24px"), pe(e, "fill", "currentColor"), pe(e, "stroke-width", "1.5"), pe(e, "viewBox", "0 0 24 24"), pe(e, "color", "currentColor"); + }, + m(n, o) { + Ws(n, e, o), As(e, t); + }, + p: $t, + i: $t, + o: $t, + d(n) { + n && Os(e); + } + }; +} +class Bs extends Ts { + constructor(e) { + super(), qs(this, e, null, zs, Ns, {}); + } +} +const { + SvelteComponent: js, + append: en, + attr: ie, + detach: Is, + init: Fs, + insert: Us, + noop: tn, + safe_not_equal: Hs, + svg_element: St +} = window.__gradio__svelte__internal; +function Vs(i) { + let e, t, n, o; + return { + c() { + e = St("svg"), t = St("path"), n = St("circle"), o = St("circle"), ie(t, "d", "M9 18V5l12-2v13"), ie(n, "cx", "6"), ie(n, "cy", "18"), ie(n, "r", "3"), ie(o, "cx", "18"), ie(o, "cy", "16"), ie(o, "r", "3"), ie(e, "xmlns", "http://www.w3.org/2000/svg"), ie(e, "width", "100%"), ie(e, "height", "100%"), ie(e, "viewBox", "0 0 24 24"), ie(e, "fill", "none"), ie(e, "stroke", "currentColor"), ie(e, "stroke-width", "1.5"), ie(e, "stroke-linecap", "round"), ie(e, "stroke-linejoin", "round"), ie(e, "class", "feather feather-music"); + }, + m(r, s) { + Us(r, e, s), en(e, t), en(e, n), en(e, o); + }, + p: tn, + i: tn, + o: tn, + d(r) { + r && Is(e); + } + }; +} +class $i extends js { + constructor(e) { + super(), Fs(this, e, null, Vs, Hs, {}); + } +} +const { + SvelteComponent: Gs, + append: Xn, + attr: oe, + detach: Xs, + init: Zs, + insert: Js, + noop: nn, + safe_not_equal: Ys, + svg_element: on +} = window.__gradio__svelte__internal; +function Ks(i) { + let e, t, n; + return { + c() { + e = on("svg"), t = on("rect"), n = on("rect"), oe(t, "x", "6"), oe(t, "y", "4"), oe(t, "width", "4"), oe(t, "height", "16"), oe(n, "x", "14"), oe(n, "y", "4"), oe(n, "width", "4"), oe(n, "height", "16"), oe(e, "xmlns", "http://www.w3.org/2000/svg"), oe(e, "width", "100%"), oe(e, "height", "100%"), oe(e, "viewBox", "0 0 24 24"), oe(e, "fill", "currentColor"), oe(e, "stroke", "currentColor"), oe(e, "stroke-width", "1.5"), oe(e, "stroke-linecap", "round"), oe(e, "stroke-linejoin", "round"); + }, + m(o, r) { + Js(o, e, r), Xn(e, t), Xn(e, n); + }, + p: nn, + i: nn, + o: nn, + d(o) { + o && Xs(e); + } + }; +} +class Qs extends Gs { + constructor(e) { + super(), Zs(this, e, null, Ks, Ys, {}); + } +} +const { + SvelteComponent: xs, + append: $s, + attr: De, + detach: er, + init: tr, + insert: nr, + noop: sn, + safe_not_equal: ir, + svg_element: Zn +} = window.__gradio__svelte__internal; +function or(i) { + let e, t; + return { + c() { + e = Zn("svg"), t = Zn("polygon"), De(t, "points", "5 3 19 12 5 21 5 3"), De(e, "xmlns", "http://www.w3.org/2000/svg"), De(e, "width", "100%"), De(e, "height", "100%"), De(e, "viewBox", "0 0 24 24"), De(e, "fill", "currentColor"), De(e, "stroke", "currentColor"), De(e, "stroke-width", "1.5"), De(e, "stroke-linecap", "round"), De(e, "stroke-linejoin", "round"); + }, + m(n, o) { + nr(n, e, o), $s(e, t); + }, + p: sn, + i: sn, + o: sn, + d(n) { + n && er(e); + } + }; +} +class sr extends xs { + constructor(e) { + super(), tr(this, e, null, or, ir, {}); + } +} +const { + SvelteComponent: rr, + append: mt, + attr: G, + detach: lr, + init: ar, + insert: cr, + noop: rn, + safe_not_equal: ur, + svg_element: et +} = window.__gradio__svelte__internal; +function dr(i) { + let e, t, n, o, r, s; + return { + c() { + e = et("svg"), t = et("circle"), n = et("circle"), o = et("line"), r = et("line"), s = et("line"), G(t, "cx", "6"), G(t, "cy", "6"), G(t, "r", "3"), G(n, "cx", "6"), G(n, "cy", "18"), G(n, "r", "3"), G(o, "x1", "20"), G(o, "y1", "4"), G(o, "x2", "8.12"), G(o, "y2", "15.88"), G(r, "x1", "14.47"), G(r, "y1", "14.48"), G(r, "x2", "20"), G(r, "y2", "20"), G(s, "x1", "8.12"), G(s, "y1", "8.12"), G(s, "x2", "12"), G(s, "y2", "12"), G(e, "xmlns", "http://www.w3.org/2000/svg"), G(e, "width", "20"), G(e, "height", "20"), G(e, "viewBox", "0 0 24 24"), G(e, "fill", "none"), G(e, "stroke", "currentColor"), G(e, "stroke-width", "2"), G(e, "stroke-linecap", "round"), G(e, "stroke-linejoin", "round"), G(e, "class", "feather feather-scissors"); + }, + m(l, a) { + cr(l, e, a), mt(e, t), mt(e, n), mt(e, o), mt(e, r), mt(e, s); + }, + p: rn, + i: rn, + o: rn, + d(l) { + l && lr(e); + } + }; +} +class fr extends rr { + constructor(e) { + super(), ar(this, e, null, dr, ur, {}); + } +} +const { + SvelteComponent: hr, + append: Jn, + attr: ge, + detach: _r, + init: mr, + insert: pr, + noop: ln, + safe_not_equal: gr, + svg_element: an +} = window.__gradio__svelte__internal; +function vr(i) { + let e, t, n; + return { + c() { + e = an("svg"), t = an("polyline"), n = an("path"), ge(t, "points", "1 4 1 10 7 10"), ge(n, "d", "M3.51 15a9 9 0 1 0 2.13-9.36L1 10"), ge(e, "xmlns", "http://www.w3.org/2000/svg"), ge(e, "width", "100%"), ge(e, "height", "100%"), ge(e, "viewBox", "0 0 24 24"), ge(e, "fill", "none"), ge(e, "stroke", "currentColor"), ge(e, "stroke-width", "2"), ge(e, "stroke-linecap", "round"), ge(e, "stroke-linejoin", "round"), ge(e, "class", "feather feather-rotate-ccw"); + }, + m(o, r) { + pr(o, e, r), Jn(e, t), Jn(e, n); + }, + p: ln, + i: ln, + o: ln, + d(o) { + o && _r(e); + } + }; +} +class br extends hr { + constructor(e) { + super(), mr(this, e, null, vr, gr, {}); + } +} +const { + SvelteComponent: wr, + create_component: yr, + destroy_component: kr, + init: Cr, + mount_component: Sr, + safe_not_equal: Er, + transition_in: Dr, + transition_out: Rr +} = window.__gradio__svelte__internal, { createEventDispatcher: Mr } = window.__gradio__svelte__internal; +function Lr(i) { + let e, t; + return e = new $o({ + props: { + Icon: Ps, + label: ( + /*i18n*/ + i[2]("common.share") + ), + pending: ( + /*pending*/ + i[3] + ) + } + }), e.$on( + "click", + /*click_handler*/ + i[5] + ), { + c() { + yr(e.$$.fragment); + }, + m(n, o) { + Sr(e, n, o), t = !0; + }, + p(n, [o]) { + const r = {}; + o & /*i18n*/ + 4 && (r.label = /*i18n*/ + n[2]("common.share")), o & /*pending*/ + 8 && (r.pending = /*pending*/ + n[3]), e.$set(r); + }, + i(n) { + t || (Dr(e.$$.fragment, n), t = !0); + }, + o(n) { + Rr(e.$$.fragment, n), t = !1; + }, + d(n) { + kr(e, n); + } + }; +} +function Pr(i, e, t) { + const n = Mr(); + let { formatter: o } = e, { value: r } = e, { i18n: s } = e, l = !1; + const a = async () => { + try { + t(3, l = !0); + const c = await o(r); + n("share", { description: c }); + } catch (c) { + console.error(c); + let u = c instanceof Lt ? c.message : "Share failed."; + n("error", u); + } finally { + t(3, l = !1); + } + }; + return i.$$set = (c) => { + "formatter" in c && t(0, o = c.formatter), "value" in c && t(1, r = c.value), "i18n" in c && t(2, s = c.i18n); + }, [o, r, s, l, n, a]; +} +class Tr extends wr { + constructor(e) { + super(), Cr(this, e, Pr, Lr, Er, { formatter: 0, value: 1, i18n: 2 }); + } +} +var cn = new Intl.Collator(0, { numeric: 1 }).compare; +function Yn(i, e, t) { + return i = i.split("."), e = e.split("."), cn(i[0], e[0]) || cn(i[1], e[1]) || (e[2] = e.slice(2).join("."), t = /[.-]/.test(i[2] = i.slice(2).join(".")), t == /[.-]/.test(e[2]) ? cn(i[2], e[2]) : t ? -1 : 1); +} +function Ne(i, e, t) { + return e.startsWith("http://") || e.startsWith("https://") ? t ? i : e : i + e; +} +function un(i) { + if (i.startsWith("http")) { + const { protocol: e, host: t } = new URL(i); + return t.endsWith("hf.space") ? { + ws_protocol: "wss", + host: t, + http_protocol: e + } : { + ws_protocol: e === "https:" ? "wss" : "ws", + http_protocol: e, + host: t + }; + } else if (i.startsWith("file:")) + return { + ws_protocol: "ws", + http_protocol: "http:", + host: "lite.local" + // Special fake hostname only used for this case. This matches the hostname allowed in `is_self_host()` in `js/wasm/network/host.ts`. + }; + return { + ws_protocol: "wss", + http_protocol: "https:", + host: i + }; +} +const eo = /^[^\/]*\/[^\/]*$/, Ar = /.*hf\.space\/{0,1}$/; +async function Or(i, e) { + const t = {}; + e && (t.Authorization = `Bearer ${e}`); + const n = i.trim(); + if (eo.test(n)) + try { + const o = await fetch( + `https://huggingface.co/api/spaces/${n}/host`, + { headers: t } + ); + if (o.status !== 200) + throw new Error("Space metadata could not be loaded."); + const r = (await o.json()).host; + return { + space_id: i, + ...un(r) + }; + } catch (o) { + throw new Error("Space metadata could not be loaded." + o.message); + } + if (Ar.test(n)) { + const { ws_protocol: o, http_protocol: r, host: s } = un(n); + return { + space_id: s.replace(".hf.space", ""), + ws_protocol: o, + http_protocol: r, + host: s + }; + } + return { + space_id: !1, + ...un(n) + }; +} +function qr(i) { + let e = {}; + return i.forEach(({ api_name: t }, n) => { + t && (e[t] = n); + }), e; +} +const Wr = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/; +async function Kn(i) { + try { + const t = (await fetch( + `https://huggingface.co/api/spaces/${i}/discussions`, + { + method: "HEAD" + } + )).headers.get("x-error-message"); + return !(t && Wr.test(t)); + } catch { + return !1; + } +} +function Ze(i, e, t) { + if (i == null) + return null; + if (Array.isArray(i)) { + const n = []; + for (const o of i) + o == null ? n.push(null) : n.push(Ze(o, e, t)); + return n; + } + return i.is_stream ? t == null ? new Ye({ + ...i, + url: e + "/stream/" + i.path + }) : new Ye({ + ...i, + url: "/proxy=" + t + "stream/" + i.path + }) : new Ye({ + ...i, + url: to(i.path, e, t) + }); +} +function Nr(i) { + try { + const e = new URL(i); + return e.protocol === "http:" || e.protocol === "https:"; + } catch { + return !1; + } +} +function to(i, e, t) { + return i == null ? t ? `/proxy=${t}file=` : `${e}/file=` : Nr(i) ? i : t ? `/proxy=${t}file=${i}` : `${e}/file=${i}`; +} +async function zr(i, e, t = Fr) { + let n = (Array.isArray(i) ? i : [i]).map( + (o) => o.blob + ); + return await Promise.all( + await t(e, n).then( + async (o) => { + if (o.error) + throw new Error(o.error); + return o.files ? o.files.map((r, s) => { + const l = new Ye({ ...i[s], path: r }); + return Ze(l, e, null); + }) : []; + } + ) + ); +} +async function Br(i, e) { + return i.map( + (t, n) => new Ye({ + path: t.name, + orig_name: t.name, + blob: t, + size: t.size, + mime_type: t.type, + is_stream: e + }) + ); +} +class Ye { + constructor({ + path: e, + url: t, + orig_name: n, + size: o, + blob: r, + is_stream: s, + mime_type: l, + alt_text: a + }) { + this.path = e, this.url = t, this.orig_name = n, this.size = o, this.blob = t ? void 0 : r, this.is_stream = s, this.mime_type = l, this.alt_text = a; + } +} +const jr = "This application is too busy. Keep trying!", pt = "Connection errored out."; +let no; +function Ir(i, e) { + return { post_data: t, upload_files: n, client: o, handle_blob: r }; + async function t(s, l, a) { + const c = { "Content-Type": "application/json" }; + a && (c.Authorization = `Bearer ${a}`); + try { + var u = await i(s, { + method: "POST", + body: JSON.stringify(l), + headers: c + }); + } catch { + return [{ error: pt }, 500]; + } + return [await u.json(), u.status]; + } + async function n(s, l, a) { + const c = {}; + a && (c.Authorization = `Bearer ${a}`); + const u = 1e3, d = []; + for (let h = 0; h < l.length; h += u) { + const f = l.slice(h, h + u), v = new FormData(); + f.forEach((p) => { + v.append("files", p); + }); + try { + var _ = await i(`${s}/upload`, { + method: "POST", + body: v, + headers: c + }); + } catch { + return { error: pt }; + } + const g = await _.json(); + d.push(...g); + } + return { files: d }; + } + async function o(s, l = { normalise_files: !0 }) { + return new Promise(async (a) => { + const { status_callback: c, hf_token: u, normalise_files: d } = l, _ = { + predict: H, + submit: X, + view_api: y, + component_server: F + }, h = d ?? !0; + if ((typeof window > "u" || !("WebSocket" in window)) && !global.Websocket) { + const S = await import("./wrapper-98f94c21-DwfcsYZ5.js"); + no = (await import("./__vite-browser-external-DYxpcVy9.js")).Blob, global.WebSocket = S.WebSocket; + } + const { ws_protocol: f, http_protocol: v, host: g, space_id: p } = await Or(s, u), m = Math.random().toString(36).substring(2), w = {}; + let k, A = {}, W = !1; + u && p && (W = await Hr(p, u)); + async function M(S) { + if (k = S, A = qr((S == null ? void 0 : S.dependencies) || []), k.auth_required) + return { + config: k, + ..._ + }; + try { + P = await y(k); + } catch (L) { + console.error(`Could not get api details: ${L.message}`); + } + return { + config: k, + ..._ + }; + } + let P; + async function U(S) { + if (c && c(S), S.status === "running") + try { + k = await ei( + i, + `${v}//${g}`, + u + ); + const L = await M(k); + a(L); + } catch (L) { + console.error(L), c && c({ + status: "error", + message: "Could not load this space.", + load_status: "error", + detail: "NOT_FOUND" + }); + } + } + try { + k = await ei( + i, + `${v}//${g}`, + u + ); + const S = await M(k); + a(S); + } catch (S) { + console.error(S), p ? vn( + p, + eo.test(p) ? "space_name" : "subdomain", + U + ) : c && c({ + status: "error", + message: "Could not load this space.", + load_status: "error", + detail: "NOT_FOUND" + }); + } + function H(S, L, b) { + let D = !1, E = !1, T; + if (typeof S == "number") + T = k.dependencies[S]; + else { + const B = S.replace(/^\//, ""); + T = k.dependencies[A[B]]; + } + if (T.types.continuous) + throw new Error( + "Cannot call predict on this function as it may run forever. Use submit instead" + ); + return new Promise((B, Z) => { + const q = X(S, L, b); + let C; + q.on("data", (J) => { + E && (q.destroy(), B(J)), D = !0, C = J; + }).on("status", (J) => { + J.stage === "error" && Z(J), J.stage === "complete" && (E = !0, D && (q.destroy(), B(C))); + }); + }); + } + function X(S, L, b) { + let D, E; + if (typeof S == "number") + D = S, E = P.unnamed_endpoints[D]; + else { + const V = S.replace(/^\//, ""); + D = A[V], E = P.named_endpoints[S.trim()]; + } + if (typeof D != "number") + throw new Error( + "There is no endpoint matching that name of fn_index matching that number." + ); + let T, B, Z = k.protocol ?? "sse"; + const q = typeof S == "number" ? "/predict" : S; + let C, J = null, ne = !1; + const le = {}; + let re = ""; + typeof window < "u" && (re = new URLSearchParams(window.location.search).toString()), r( + `${v}//${Ne(g, k.path, !0)}`, + L, + E, + u + ).then((V) => { + if (C = { data: V || [], event_data: b, fn_index: D }, Vr(D, k)) + j({ + type: "status", + endpoint: q, + stage: "pending", + queue: !1, + fn_index: D, + time: /* @__PURE__ */ new Date() + }), t( + `${v}//${Ne(g, k.path, !0)}/run${q.startsWith("/") ? q : `/${q}`}${re ? "?" + re : ""}`, + { + ...C, + session_hash: m + }, + u + ).then(([Y, $]) => { + const Oe = h ? dn( + Y.data, + E, + k.root, + k.root_url + ) : Y.data; + $ == 200 ? (j({ + type: "data", + endpoint: q, + fn_index: D, + data: Oe, + time: /* @__PURE__ */ new Date() + }), j({ + type: "status", + endpoint: q, + fn_index: D, + stage: "complete", + eta: Y.average_duration, + queue: !1, + time: /* @__PURE__ */ new Date() + })) : j({ + type: "status", + stage: "error", + endpoint: q, + fn_index: D, + message: Y.error, + queue: !1, + time: /* @__PURE__ */ new Date() + }); + }).catch((Y) => { + j({ + type: "status", + stage: "error", + message: Y.message, + endpoint: q, + fn_index: D, + queue: !1, + time: /* @__PURE__ */ new Date() + }); + }); + else if (Z == "ws") { + j({ + type: "status", + stage: "pending", + queue: !0, + endpoint: q, + fn_index: D, + time: /* @__PURE__ */ new Date() + }); + let Y = new URL(`${f}://${Ne( + g, + k.path, + !0 + )} + /queue/join${re ? "?" + re : ""}`); + W && Y.searchParams.set("__sign", W), T = e(Y), T.onclose = ($) => { + $.wasClean || j({ + type: "status", + stage: "error", + broken: !0, + message: pt, + queue: !0, + endpoint: q, + fn_index: D, + time: /* @__PURE__ */ new Date() + }); + }, T.onmessage = function($) { + const Oe = JSON.parse($.data), { type: _e, status: ee, data: ye } = ti( + Oe, + w[D] + ); + if (_e === "update" && ee && !ne) + j({ + type: "status", + endpoint: q, + fn_index: D, + time: /* @__PURE__ */ new Date(), + ...ee + }), ee.stage === "error" && T.close(); + else if (_e === "hash") { + T.send(JSON.stringify({ fn_index: D, session_hash: m })); + return; + } else + _e === "data" ? T.send(JSON.stringify({ ...C, session_hash: m })) : _e === "complete" ? ne = ee : _e === "log" ? j({ + type: "log", + log: ye.log, + level: ye.level, + endpoint: q, + fn_index: D + }) : _e === "generating" && j({ + type: "status", + time: /* @__PURE__ */ new Date(), + ...ee, + stage: ee == null ? void 0 : ee.stage, + queue: !0, + endpoint: q, + fn_index: D + }); + ye && (j({ + type: "data", + time: /* @__PURE__ */ new Date(), + data: h ? dn( + ye.data, + E, + k.root, + k.root_url + ) : ye.data, + endpoint: q, + fn_index: D + }), ne && (j({ + type: "status", + time: /* @__PURE__ */ new Date(), + ...ne, + stage: ee == null ? void 0 : ee.stage, + queue: !0, + endpoint: q, + fn_index: D + }), T.close())); + }, Yn(k.version || "2.0.0", "3.6") < 0 && addEventListener( + "open", + () => T.send(JSON.stringify({ hash: m })) + ); + } else { + j({ + type: "status", + stage: "pending", + queue: !0, + endpoint: q, + fn_index: D, + time: /* @__PURE__ */ new Date() + }); + var R = new URLSearchParams({ + fn_index: D.toString(), + session_hash: m + }).toString(); + let Y = new URL( + `${v}//${Ne( + g, + k.path, + !0 + )}/queue/join?${re ? re + "&" : ""}${R}` + ); + B = new EventSource(Y), B.onmessage = async function($) { + const Oe = JSON.parse($.data), { type: _e, status: ee, data: ye } = ti( + Oe, + w[D] + ); + if (_e === "update" && ee && !ne) + j({ + type: "status", + endpoint: q, + fn_index: D, + time: /* @__PURE__ */ new Date(), + ...ee + }), ee.stage === "error" && B.close(); + else if (_e === "data") { + J = Oe.event_id; + let [iu, Wo] = await t( + `${v}//${Ne( + g, + k.path, + !0 + )}/queue/data`, + { + ...C, + session_hash: m, + event_id: J + }, + u + ); + Wo !== 200 && (j({ + type: "status", + stage: "error", + message: pt, + queue: !0, + endpoint: q, + fn_index: D, + time: /* @__PURE__ */ new Date() + }), B.close()); + } else + _e === "complete" ? ne = ee : _e === "log" ? j({ + type: "log", + log: ye.log, + level: ye.level, + endpoint: q, + fn_index: D + }) : _e === "generating" && j({ + type: "status", + time: /* @__PURE__ */ new Date(), + ...ee, + stage: ee == null ? void 0 : ee.stage, + queue: !0, + endpoint: q, + fn_index: D + }); + ye && (j({ + type: "data", + time: /* @__PURE__ */ new Date(), + data: h ? dn( + ye.data, + E, + k.root, + k.root_url + ) : ye.data, + endpoint: q, + fn_index: D + }), ne && (j({ + type: "status", + time: /* @__PURE__ */ new Date(), + ...ne, + stage: ee == null ? void 0 : ee.stage, + queue: !0, + endpoint: q, + fn_index: D + }), B.close())); + }; + } + }); + function j(V) { + const Y = le[V.type] || []; + Y == null || Y.forEach(($) => $(V)); + } + function ae(V, R) { + const Y = le, $ = Y[V] || []; + return Y[V] = $, $ == null || $.push(R), { on: ae, off: Ae, cancel: Ge, destroy: Pe }; + } + function Ae(V, R) { + const Y = le; + let $ = Y[V] || []; + return $ = $ == null ? void 0 : $.filter((Oe) => Oe !== R), Y[V] = $, { on: ae, off: Ae, cancel: Ge, destroy: Pe }; + } + async function Ge() { + const V = { + stage: "complete", + queue: !1, + time: /* @__PURE__ */ new Date() + }; + ne = V, j({ + ...V, + type: "status", + endpoint: q, + fn_index: D + }); + let R = {}; + Z === "ws" ? (T && T.readyState === 0 ? T.addEventListener("open", () => { + T.close(); + }) : T.close(), R = { fn_index: D, session_hash: m }) : (B.close(), R = { event_id: J }); + try { + await i( + `${v}//${Ne( + g, + k.path, + !0 + )}/reset`, + { + headers: { "Content-Type": "application/json" }, + method: "POST", + body: JSON.stringify(R) + } + ); + } catch { + console.warn( + "The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable." + ); + } + } + function Pe() { + for (const V in le) + le[V].forEach((R) => { + Ae(V, R); + }); + } + return { + on: ae, + off: Ae, + cancel: Ge, + destroy: Pe + }; + } + async function F(S, L, b) { + var D; + const E = { "Content-Type": "application/json" }; + u && (E.Authorization = `Bearer ${u}`); + let T, B = k.components.find( + (C) => C.id === S + ); + (D = B == null ? void 0 : B.props) != null && D.root_url ? T = B.props.root_url : T = `${v}//${Ne( + g, + k.path, + !0 + )}/`; + const Z = await i( + `${T}component_server/`, + { + method: "POST", + body: JSON.stringify({ + data: b, + component_id: S, + fn_name: L, + session_hash: m + }), + headers: E + } + ); + if (!Z.ok) + throw new Error( + "Could not connect to component server: " + Z.statusText + ); + return await Z.json(); + } + async function y(S) { + if (P) + return P; + const L = { "Content-Type": "application/json" }; + u && (L.Authorization = `Bearer ${u}`); + let b; + if (Yn(S.version || "2.0.0", "3.30") < 0 ? b = await i( + "https://gradio-space-api-fetcher-v2.hf.space/api", + { + method: "POST", + body: JSON.stringify({ + serialize: !1, + config: JSON.stringify(S) + }), + headers: L + } + ) : b = await i(`${S.root}/info`, { + headers: L + }), !b.ok) + throw new Error(pt); + let D = await b.json(); + return "api" in D && (D = D.api), D.named_endpoints["/predict"] && !D.unnamed_endpoints[0] && (D.unnamed_endpoints[0] = D.named_endpoints["/predict"]), Ur(D, S, A); + } + }); + } + async function r(s, l, a, c) { + const u = await gn( + l, + void 0, + [], + !0, + a + ); + return Promise.all( + u.map(async ({ path: d, blob: _, type: h }) => { + if (_) { + const f = (await n(s, [_], c)).files[0]; + return { path: d, file_url: f, type: h, name: _ == null ? void 0 : _.name }; + } + return { path: d, type: h }; + }) + ).then((d) => (d.forEach(({ path: _, file_url: h, type: f, name: v }) => { + if (f === "Gallery") + $n(l, h, _); + else if (h) { + const g = new Ye({ path: h, orig_name: v }); + $n(l, g, _); + } + }), l)); + } +} +const { post_data: ou, upload_files: Fr, client: su, handle_blob: ru } = Ir( + fetch, + (...i) => new WebSocket(...i) +); +function dn(i, e, t, n) { + return i.map((o, r) => { + var s, l, a, c; + return ((l = (s = e == null ? void 0 : e.returns) == null ? void 0 : s[r]) == null ? void 0 : l.component) === "File" ? Ze(o, t, n) : ((c = (a = e == null ? void 0 : e.returns) == null ? void 0 : a[r]) == null ? void 0 : c.component) === "Gallery" ? o.map((u) => Array.isArray(u) ? [Ze(u[0], t, n), u[1]] : [Ze(u, t, n), null]) : typeof o == "object" && o.path ? Ze(o, t, n) : o; + }); +} +function Qn(i, e, t, n) { + switch (i.type) { + case "string": + return "string"; + case "boolean": + return "boolean"; + case "number": + return "number"; + } + if (t === "JSONSerializable" || t === "StringSerializable") + return "any"; + if (t === "ListStringSerializable") + return "string[]"; + if (e === "Image") + return n === "parameter" ? "Blob | File | Buffer" : "string"; + if (t === "FileSerializable") + return (i == null ? void 0 : i.type) === "array" ? n === "parameter" ? "(Blob | File | Buffer)[]" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]" : n === "parameter" ? "Blob | File | Buffer" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}"; + if (t === "GallerySerializable") + return n === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]"; +} +function xn(i, e) { + return e === "GallerySerializable" ? "array of [file, label] tuples" : e === "ListStringSerializable" ? "array of strings" : e === "FileSerializable" ? "array of files or single file" : i.description; +} +function Ur(i, e, t) { + const n = { + named_endpoints: {}, + unnamed_endpoints: {} + }; + for (const o in i) { + const r = i[o]; + for (const s in r) { + const l = e.dependencies[s] ? s : t[s.replace("/", "")], a = r[s]; + n[o][s] = {}, n[o][s].parameters = {}, n[o][s].returns = {}, n[o][s].type = e.dependencies[l].types, n[o][s].parameters = a.parameters.map( + ({ label: c, component: u, type: d, serializer: _ }) => ({ + label: c, + component: u, + type: Qn(d, u, _, "parameter"), + description: xn(d, _) + }) + ), n[o][s].returns = a.returns.map( + ({ label: c, component: u, type: d, serializer: _ }) => ({ + label: c, + component: u, + type: Qn(d, u, _, "return"), + description: xn(d, _) + }) + ); + } + } + return n; +} +async function Hr(i, e) { + try { + return (await (await fetch(`https://huggingface.co/api/spaces/${i}/jwt`, { + headers: { + Authorization: `Bearer ${e}` + } + })).json()).token || !1; + } catch (t) { + return console.error(t), !1; + } +} +function $n(i, e, t) { + for (; t.length > 1; ) + i = i[t.shift()]; + i[t.shift()] = e; +} +async function gn(i, e = void 0, t = [], n = !1, o = void 0) { + if (Array.isArray(i)) { + let r = []; + return await Promise.all( + i.map(async (s, l) => { + var a; + let c = t.slice(); + c.push(l); + const u = await gn( + i[l], + n ? ((a = o == null ? void 0 : o.parameters[l]) == null ? void 0 : a.component) || void 0 : e, + c, + !1, + o + ); + r = r.concat(u); + }) + ), r; + } else { + if (globalThis.Buffer && i instanceof globalThis.Buffer) + return [ + { + path: t, + blob: e === "Image" ? !1 : new no([i]), + type: e + } + ]; + if (typeof i == "object") { + let r = []; + for (let s in i) + if (i.hasOwnProperty(s)) { + let l = t.slice(); + l.push(s), r = r.concat( + await gn( + i[s], + void 0, + l, + !1, + o + ) + ); + } + return r; + } + } + return []; +} +function Vr(i, e) { + var t, n, o, r; + return !(((n = (t = e == null ? void 0 : e.dependencies) == null ? void 0 : t[i]) == null ? void 0 : n.queue) === null ? e.enable_queue : (r = (o = e == null ? void 0 : e.dependencies) == null ? void 0 : o[i]) != null && r.queue) || !1; +} +async function ei(i, e, t) { + const n = {}; + if (t && (n.Authorization = `Bearer ${t}`), typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876" && !window.gradio_config.dev_mode) { + const o = window.gradio_config.root, r = window.gradio_config; + return r.root = Ne(e, r.root, !1), { ...r, path: o }; + } else if (e) { + let o = await i(`${e}/config`, { + headers: n + }); + if (o.status === 200) { + const r = await o.json(); + return r.path = r.path ?? "", r.root = e, r; + } + throw new Error("Could not get config."); + } + throw new Error("No config or app endpoint found"); +} +async function vn(i, e, t) { + let n = e === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${i}` : `https://huggingface.co/api/spaces/${i}`, o, r; + try { + if (o = await fetch(n), r = o.status, r !== 200) + throw new Error(); + o = await o.json(); + } catch { + t({ + status: "error", + load_status: "error", + message: "Could not get space status", + detail: "NOT_FOUND" + }); + return; + } + if (!o || r !== 200) + return; + const { + runtime: { stage: s }, + id: l + } = o; + switch (s) { + case "STOPPED": + case "SLEEPING": + t({ + status: "sleeping", + load_status: "pending", + message: "Space is asleep. Waking it up...", + detail: s + }), setTimeout(() => { + vn(i, e, t); + }, 1e3); + break; + case "PAUSED": + t({ + status: "paused", + load_status: "error", + message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.", + detail: s, + discussions_enabled: await Kn(l) + }); + break; + case "RUNNING": + case "RUNNING_BUILDING": + t({ + status: "running", + load_status: "complete", + message: "", + detail: s + }); + break; + case "BUILDING": + t({ + status: "building", + load_status: "pending", + message: "Space is building...", + detail: s + }), setTimeout(() => { + vn(i, e, t); + }, 1e3); + break; + default: + t({ + status: "space_error", + load_status: "error", + message: "This space is experiencing an issue.", + detail: s, + discussions_enabled: await Kn(l) + }); + break; + } +} +function ti(i, e) { + switch (i.msg) { + case "send_data": + return { type: "data" }; + case "send_hash": + return { type: "hash" }; + case "queue_full": + return { + type: "update", + status: { + queue: !0, + message: jr, + stage: "error", + code: i.code, + success: i.success + } + }; + case "estimation": + return { + type: "update", + status: { + queue: !0, + stage: e || "pending", + code: i.code, + size: i.queue_size, + position: i.rank, + eta: i.rank_eta, + success: i.success + } + }; + case "progress": + return { + type: "update", + status: { + queue: !0, + stage: "pending", + code: i.code, + progress_data: i.progress_data, + success: i.success + } + }; + case "log": + return { type: "log", data: i }; + case "process_generating": + return { + type: "generating", + status: { + queue: !0, + message: i.success ? null : i.output.error, + stage: i.success ? "generating" : "error", + code: i.code, + progress_data: i.progress_data, + eta: i.average_duration + }, + data: i.success ? i.output : null + }; + case "process_completed": + return "error" in i.output ? { + type: "update", + status: { + queue: !0, + message: i.output.error, + stage: "error", + code: i.code, + success: i.success + } + } : { + type: "complete", + status: { + queue: !0, + message: i.success ? void 0 : i.output.error, + stage: i.success ? "complete" : "error", + code: i.code, + progress_data: i.progress_data, + eta: i.output.average_duration + }, + data: i.success ? i.output : null + }; + case "process_starts": + return { + type: "update", + status: { + queue: !0, + stage: "pending", + code: i.code, + size: i.rank, + position: 0, + success: i.success + } + }; + } + return { type: "none", status: { stage: "error", queue: !0 } }; +} +const { + SvelteComponent: Gr, + append: Ee, + attr: O, + binding_callbacks: Xr, + bubble: ni, + check_outros: io, + create_component: En, + destroy_block: oo, + destroy_component: Dn, + detach: de, + element: Fe, + empty: so, + ensure_array_like: zt, + group_outros: ro, + init: Zr, + insert: fe, + listen: Rn, + mount_component: Mn, + null_to_empty: Bt, + safe_not_equal: Jr, + set_style: lo, + space: wt, + src_url_equal: jt, + svg_element: Le, + transition_in: Ue, + transition_out: xe, + update_keyed_each: ao +} = window.__gradio__svelte__internal, { createEventDispatcher: Yr } = window.__gradio__svelte__internal; +function ii(i, e, t) { + const n = i.slice(); + return n[20] = e[t], n[22] = t, n; +} +function oi(i, e, t) { + const n = i.slice(); + return n[20] = e[t], n[22] = t, n; +} +function Kr(i) { + let e, t; + return e = new xi({ + props: { + size: "small", + $$slots: { default: [xr] }, + $$scope: { ctx: i } + } + }), { + c() { + En(e.$$.fragment); + }, + m(n, o) { + Mn(e, n, o), t = !0; + }, + p(n, o) { + const r = {}; + o & /*$$scope*/ + 16777216 && (r.$$scope = { dirty: o, ctx: n }), e.$set(r); + }, + i(n) { + t || (Ue(e.$$.fragment, n), t = !0); + }, + o(n) { + xe(e.$$.fragment, n), t = !1; + }, + d(n) { + Dn(e, n); + } + }; +} +function Qr(i) { + let e, t, n, o, r, s, l, a, c, u = ( + /*show_share_button*/ + i[2] && si(i) + ); + function d(f, v) { + return ( + /*image*/ + f[1] ? el : $r + ); + } + let _ = d(i), h = _(i); + return { + c() { + e = Fe("div"), u && u.c(), t = wt(), n = Fe("audio"), r = wt(), h.c(), s = so(), O(e, "class", "icon-buttons"), jt(n.src, o = /*value*/ + i[0].url) || O(n, "src", o), n.controls = !0, O(n, "class", "svelte-3kusfn"); + }, + m(f, v) { + fe(f, e, v), u && u.m(e, null), fe(f, t, v), fe(f, n, v), i[18](n), fe(f, r, v), h.m(f, v), fe(f, s, v), l = !0, a || (c = Rn( + n, + "ended", + /*handle_audio_end*/ + i[8] + ), a = !0); + }, + p(f, v) { + /*show_share_button*/ + f[2] ? u ? (u.p(f, v), v & /*show_share_button*/ + 4 && Ue(u, 1)) : (u = si(f), u.c(), Ue(u, 1), u.m(e, null)) : u && (ro(), xe(u, 1, 1, () => { + u = null; + }), io()), (!l || v & /*value*/ + 1 && !jt(n.src, o = /*value*/ + f[0].url)) && O(n, "src", o), _ === (_ = d(f)) && h ? h.p(f, v) : (h.d(1), h = _(f), h && (h.c(), h.m(s.parentNode, s))); + }, + i(f) { + l || (Ue(u), l = !0); + }, + o(f) { + xe(u), l = !1; + }, + d(f) { + f && (de(e), de(t), de(n), de(r), de(s)), u && u.d(), i[18](null), h.d(f), a = !1, c(); + } + }; +} +function xr(i) { + let e, t; + return e = new $i({}), { + c() { + En(e.$$.fragment); + }, + m(n, o) { + Mn(e, n, o), t = !0; + }, + i(n) { + t || (Ue(e.$$.fragment, n), t = !0); + }, + o(n) { + xe(e.$$.fragment, n), t = !1; + }, + d(n) { + Dn(e, n); + } + }; +} +function si(i) { + let e, t; + return e = new Tr({ + props: { + i18n: ( + /*i18n*/ + i[3] + ), + formatter: ( + /*func*/ + i[15] + ), + value: ( + /*value*/ + i[0] + ) + } + }), e.$on( + "error", + /*error_handler*/ + i[16] + ), e.$on( + "share", + /*share_handler*/ + i[17] + ), { + c() { + En(e.$$.fragment); + }, + m(n, o) { + Mn(e, n, o), t = !0; + }, + p(n, o) { + const r = {}; + o & /*i18n*/ + 8 && (r.i18n = /*i18n*/ + n[3]), o & /*value*/ + 1 && (r.value = /*value*/ + n[0]), e.$set(r); + }, + i(n) { + t || (Ue(e.$$.fragment, n), t = !0); + }, + o(n) { + xe(e.$$.fragment, n), t = !1; + }, + d(n) { + Dn(e, n); + } + }; +} +function $r(i) { + let e, t = [], n = /* @__PURE__ */ new Map(), o, r, s, l = zt(Array(15)); + const a = (_) => ( + /*i*/ + _[22] + ); + for (let _ = 0; _ < l.length; _ += 1) { + let h = ii(i, l, _), f = a(h); + n.set(f, t[_] = ri(f, h)); + } + function c(_, h) { + return ( + /*isPlaying*/ + _[6] ? tl : nl + ); + } + let u = c(i), d = u(i); + return { + c() { + e = Fe("div"); + for (let _ = 0; _ < t.length; _ += 1) + t[_].c(); + o = wt(), d.c(), O(e, "class", "circle-container svelte-3kusfn"), O(e, "role", "button"), O(e, "tabindex", "0"), O(e, "aria-hidden", "true"); + }, + m(_, h) { + fe(_, e, h); + for (let f = 0; f < t.length; f += 1) + t[f] && t[f].m(e, null); + Ee(e, o), d.m(e, null), r || (s = Rn( + e, + "click", + /*play_audio*/ + i[7] + ), r = !0); + }, + p(_, h) { + h & /*isPlaying, Array*/ + 64 && (l = zt(Array(15)), t = ao(t, h, a, 1, _, l, n, e, oo, ri, o, ii)), u !== (u = c(_)) && (d.d(1), d = u(_), d && (d.c(), d.m(e, null))); + }, + d(_) { + _ && de(e); + for (let h = 0; h < t.length; h += 1) + t[h].d(); + d.d(), r = !1, s(); + } + }; +} +function el(i) { + let e, t, n, o, r, s, l = [], a = /* @__PURE__ */ new Map(), c, u; + function d(g, p) { + return ( + /*isPlaying*/ + g[6] ? il : ol + ); + } + let _ = d(i), h = _(i), f = zt(Array(15)); + const v = (g) => ( + /*i*/ + g[22] + ); + for (let g = 0; g < f.length; g += 1) { + let p = oi(i, f, g), m = v(p); + a.set(m, l[g] = li(m, p)); + } + return { + c() { + e = Fe("div"), t = Fe("img"), o = wt(), h.c(), r = wt(), s = Fe("div"); + for (let g = 0; g < l.length; g += 1) + l[g].c(); + O(t, "class", "image-player svelte-3kusfn"), jt(t.src, n = /*image_path*/ + i[4]) || O(t, "src", n), O(t, "alt", "test"), O(s, "class", "circle-container waveform-image svelte-3kusfn"), O(e, "class", "image-container svelte-3kusfn"), O(e, "role", "button"), O(e, "tabindex", "0"), O(e, "aria-hidden", "true"); + }, + m(g, p) { + fe(g, e, p), Ee(e, t), Ee(e, o), h.m(e, null), Ee(e, r), Ee(e, s); + for (let m = 0; m < l.length; m += 1) + l[m] && l[m].m(s, null); + c || (u = Rn( + e, + "click", + /*play_audio*/ + i[7] + ), c = !0); + }, + p(g, p) { + p & /*image_path*/ + 16 && !jt(t.src, n = /*image_path*/ + g[4]) && O(t, "src", n), _ !== (_ = d(g)) && (h.d(1), h = _(g), h && (h.c(), h.m(e, r))), p & /*isPlaying, Array*/ + 64 && (f = zt(Array(15)), l = ao(l, p, v, 1, g, f, a, s, oo, li, null, oi)); + }, + d(g) { + g && de(e), h.d(); + for (let p = 0; p < l.length; p += 1) + l[p].d(); + c = !1, u(); + } + }; +} +function ri(i, e) { + let t, n; + return { + key: i, + first: null, + c() { + t = Fe("div"), O(t, "class", n = Bt(`waveform-bar ${/*isPlaying*/ + e[6] ? `waveform-animation-${/*i*/ + e[22] % 5}` : ""}`) + " svelte-3kusfn"), O(t, "style", `height: ${20 + /*i*/ + e[22] % 5 * 10}%`), this.first = t; + }, + m(o, r) { + fe(o, t, r); + }, + p(o, r) { + e = o, r & /*isPlaying*/ + 64 && n !== (n = Bt(`waveform-bar ${/*isPlaying*/ + e[6] ? `waveform-animation-${/*i*/ + e[22] % 5}` : ""}`) + " svelte-3kusfn") && O(t, "class", n); + }, + d(o) { + o && de(t); + } + }; +} +function tl(i) { + let e, t, n; + return { + c() { + e = Le("svg"), t = Le("rect"), n = Le("rect"), O(t, "x", "6"), O(t, "y", "4"), O(t, "width", "4"), O(t, "height", "16"), O(t, "fill", "currentColor"), O(n, "x", "14"), O(n, "y", "4"), O(n, "width", "4"), O(n, "height", "16"), O(n, "fill", "currentColor"), O(e, "class", "pause-icon svelte-3kusfn"), O(e, "viewBox", "0 0 24 24"), lo(e, "pointer-events", "none"); + }, + m(o, r) { + fe(o, e, r), Ee(e, t), Ee(e, n); + }, + d(o) { + o && de(e); + } + }; +} +function nl(i) { + let e, t; + return { + c() { + e = Le("svg"), t = Le("polygon"), O(t, "points", "5,3 19,12 5,21"), O(t, "fill", "currentColor"), O(e, "class", "play-icon svelte-3kusfn"), O(e, "viewBox", "0 0 24 24"), lo(e, "pointer-events", "none"); + }, + m(n, o) { + fe(n, e, o), Ee(e, t); + }, + d(n) { + n && de(e); + } + }; +} +function il(i) { + let e, t, n; + return { + c() { + e = Le("svg"), t = Le("rect"), n = Le("rect"), O(t, "x", "6"), O(t, "y", "4"), O(t, "width", "4"), O(t, "height", "16"), O(t, "fill", "currentColor"), O(n, "x", "14"), O(n, "y", "4"), O(n, "width", "4"), O(n, "height", "16"), O(n, "fill", "currentColor"), O(e, "class", "pause-icon svelte-3kusfn"), O(e, "viewBox", "0 0 24 24"); + }, + m(o, r) { + fe(o, e, r), Ee(e, t), Ee(e, n); + }, + d(o) { + o && de(e); + } + }; +} +function ol(i) { + let e, t; + return { + c() { + e = Le("svg"), t = Le("polygon"), O(t, "points", "5,3 19,12 5,21"), O(t, "fill", "currentColor"), O(e, "class", "play-icon svelte-3kusfn"), O(e, "viewBox", "0 0 24 24"); + }, + m(n, o) { + fe(n, e, o), Ee(e, t); + }, + d(n) { + n && de(e); + } + }; +} +function li(i, e) { + let t, n; + return { + key: i, + first: null, + c() { + t = Fe("div"), O(t, "class", n = Bt(`waveform-bar ${/*isPlaying*/ + e[6] ? `waveform-animation-${/*i*/ + e[22] % 5}` : ""}`) + " svelte-3kusfn"), O(t, "style", `height: ${20 + /*i*/ + e[22] % 5 * 10}%`), this.first = t; + }, + m(o, r) { + fe(o, t, r); + }, + p(o, r) { + e = o, r & /*isPlaying*/ + 64 && n !== (n = Bt(`waveform-bar ${/*isPlaying*/ + e[6] ? `waveform-animation-${/*i*/ + e[22] % 5}` : ""}`) + " svelte-3kusfn") && O(t, "class", n); + }, + d(o) { + o && de(t); + } + }; +} +function sl(i) { + let e, t, n, o; + const r = [Qr, Kr], s = []; + function l(a, c) { + return ( + /*value*/ + a[0] !== null ? 0 : 1 + ); + } + return e = l(i), t = s[e] = r[e](i), { + c() { + t.c(), n = so(); + }, + m(a, c) { + s[e].m(a, c), fe(a, n, c), o = !0; + }, + p(a, [c]) { + let u = e; + e = l(a), e === u ? s[e].p(a, c) : (ro(), xe(s[u], 1, 1, () => { + s[u] = null; + }), io(), t = s[e], t ? t.p(a, c) : (t = s[e] = r[e](a), t.c()), Ue(t, 1), t.m(n.parentNode, n)); + }, + i(a) { + o || (Ue(t), o = !0); + }, + o(a) { + xe(t), o = !1; + }, + d(a) { + a && de(n), s[e].d(a); + } + }; +} +function rl(i, e, t) { + let { value: n = null } = e, { image: o = null } = e, { label: r } = e, { show_label: s = !0 } = e, { show_download_button: l = !0 } = e, { show_share_button: a = !1 } = e, { i18n: c } = e, { waveform_settings: u = {} } = e, { root: d = "" } = e, { proxy_url: _ = null } = e, h; + const f = Yr(); + let v, g = !1; + function p() { + if (g) { + v.pause(), t(6, g = !1); + return; + } else + v.play(), t(6, g = !0); + } + function m() { + f("end"); + } + const w = async (M) => M ? `` : ""; + function k(M) { + ni.call(this, i, M); + } + function A(M) { + ni.call(this, i, M); + } + function W(M) { + Xr[M ? "unshift" : "push"](() => { + v = M, t(5, v); + }); + } + return i.$$set = (M) => { + "value" in M && t(0, n = M.value), "image" in M && t(1, o = M.image), "label" in M && t(9, r = M.label), "show_label" in M && t(10, s = M.show_label), "show_download_button" in M && t(11, l = M.show_download_button), "show_share_button" in M && t(2, a = M.show_share_button), "i18n" in M && t(3, c = M.i18n), "waveform_settings" in M && t(12, u = M.waveform_settings), "root" in M && t(13, d = M.root), "proxy_url" in M && t(14, _ = M.proxy_url); + }, i.$$.update = () => { + i.$$.dirty & /*image, root, proxy_url*/ + 24578 && (o instanceof Ye ? t(4, h = o.path) : t(4, h = to(o, d, _))), i.$$.dirty & /*value*/ + 1 && n && f("change", n); + }, [ + n, + o, + a, + c, + h, + v, + g, + p, + m, + r, + s, + l, + u, + d, + _, + w, + k, + A, + W + ]; +} +class ll extends Gr { + constructor(e) { + super(), Zr(this, e, rl, sl, Jr, { + value: 0, + image: 1, + label: 9, + show_label: 10, + show_download_button: 11, + show_share_button: 2, + i18n: 3, + waveform_settings: 12, + root: 13, + proxy_url: 14 + }); + } +} +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ +function te(i, e, t, n) { + return new (t || (t = Promise))(function(o, r) { + function s(c) { + try { + a(n.next(c)); + } catch (u) { + r(u); + } + } + function l(c) { + try { + a(n.throw(c)); + } catch (u) { + r(u); + } + } + function a(c) { + var u; + c.done ? o(c.value) : (u = c.value, u instanceof t ? u : new t(function(d) { + d(u); + })).then(s, l); + } + a((n = n.apply(i, [])).next()); + }); +} +let Ct = class { + constructor() { + this.listeners = {}; + } + on(e, t, n) { + if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(t), n == null ? void 0 : n.once) { + const o = () => { + this.un(e, o), this.un(e, t); + }; + return this.on(e, o), o; + } + return () => this.un(e, t); + } + un(e, t) { + var n; + (n = this.listeners[e]) === null || n === void 0 || n.delete(t); + } + once(e, t) { + return this.on(e, t, { once: !0 }); + } + unAll() { + this.listeners = {}; + } + emit(e, ...t) { + this.listeners[e] && this.listeners[e].forEach((n) => n(...t)); + } +}; +const ai = { decode: function(i, e) { + return te(this, void 0, void 0, function* () { + const t = new AudioContext({ sampleRate: e }); + return t.decodeAudioData(i).finally(() => t.close()); + }); +}, createBuffer: function(i, e) { + return typeof i[0] == "number" && (i = [i]), function(t) { + const n = t[0]; + if (n.some((o) => o > 1 || o < -1)) { + const o = n.length; + let r = 0; + for (let s = 0; s < o; s++) { + const l = Math.abs(n[s]); + l > r && (r = l); + } + for (const s of t) + for (let l = 0; l < o; l++) + s[l] /= r; + } + }(i), { duration: e, length: i[0].length, sampleRate: i[0].length / e, numberOfChannels: i.length, getChannelData: (t) => i == null ? void 0 : i[t], copyFromChannel: AudioBuffer.prototype.copyFromChannel, copyToChannel: AudioBuffer.prototype.copyToChannel }; +} }; +function co(i, e) { + const t = e.xmlns ? document.createElementNS(e.xmlns, i) : document.createElement(i); + for (const [n, o] of Object.entries(e)) + if (n === "children") + for (const [r, s] of Object.entries(e)) + typeof s == "string" ? t.appendChild(document.createTextNode(s)) : t.appendChild(co(r, s)); + else + n === "style" ? Object.assign(t.style, o) : n === "textContent" ? t.textContent = o : t.setAttribute(n, o.toString()); + return t; +} +function ci(i, e, t) { + const n = co(i, e || {}); + return t == null || t.appendChild(n), n; +} +var al = Object.freeze({ __proto__: null, createElement: ci, default: ci }); +const cl = { fetchBlob: function(i, e, t) { + return te(this, void 0, void 0, function* () { + const n = yield fetch(i, t); + if (n.status >= 400) + throw new Error(`Failed to fetch ${i}: ${n.status} (${n.statusText})`); + return function(o, r) { + te(this, void 0, void 0, function* () { + if (!o.body || !o.headers) + return; + const s = o.body.getReader(), l = Number(o.headers.get("Content-Length")) || 0; + let a = 0; + const c = (d) => te(this, void 0, void 0, function* () { + a += (d == null ? void 0 : d.length) || 0; + const _ = Math.round(a / l * 100); + r(_); + }), u = () => te(this, void 0, void 0, function* () { + let d; + try { + d = yield s.read(); + } catch { + return; + } + d.done || (c(d.value), yield u()); + }); + u(); + }); + }(n.clone(), e), n.blob(); + }); +} }; +class ul extends Ct { + constructor(e) { + super(), this.isExternalMedia = !1, e.media ? (this.media = e.media, this.isExternalMedia = !0) : this.media = document.createElement("audio"), e.mediaControls && (this.media.controls = !0), e.autoplay && (this.media.autoplay = !0), e.playbackRate != null && this.onceMediaEvent("canplay", () => { + e.playbackRate != null && (this.media.playbackRate = e.playbackRate); + }); + } + onMediaEvent(e, t, n) { + return this.media.addEventListener(e, t, n), () => this.media.removeEventListener(e, t); + } + onceMediaEvent(e, t) { + return this.onMediaEvent(e, t, { once: !0 }); + } + getSrc() { + return this.media.currentSrc || this.media.src || ""; + } + revokeSrc() { + const e = this.getSrc(); + e.startsWith("blob:") && URL.revokeObjectURL(e); + } + canPlayType(e) { + return this.media.canPlayType(e) !== ""; + } + setSrc(e, t) { + if (this.getSrc() === e) + return; + this.revokeSrc(); + const n = t instanceof Blob && this.canPlayType(t.type) ? URL.createObjectURL(t) : e; + this.media.src = n; + } + destroy() { + this.media.pause(), this.isExternalMedia || (this.media.remove(), this.revokeSrc(), this.media.src = "", this.media.load()); + } + setMediaElement(e) { + this.media = e; + } + play() { + return te(this, void 0, void 0, function* () { + if (this.media.src) + return this.media.play(); + }); + } + pause() { + this.media.pause(); + } + isPlaying() { + return !this.media.paused && !this.media.ended; + } + setTime(e) { + this.media.currentTime = e; + } + getDuration() { + return this.media.duration; + } + getCurrentTime() { + return this.media.currentTime; + } + getVolume() { + return this.media.volume; + } + setVolume(e) { + this.media.volume = e; + } + getMuted() { + return this.media.muted; + } + setMuted(e) { + this.media.muted = e; + } + getPlaybackRate() { + return this.media.playbackRate; + } + isSeeking() { + return this.media.seeking; + } + setPlaybackRate(e, t) { + t != null && (this.media.preservesPitch = t), this.media.playbackRate = e; + } + getMediaElement() { + return this.media; + } + setSinkId(e) { + return this.media.setSinkId(e); + } +} +class Jt extends Ct { + constructor(e, t) { + super(), this.timeouts = [], this.isScrollable = !1, this.audioData = null, this.resizeObserver = null, this.lastContainerWidth = 0, this.isDragging = !1, this.options = e; + const n = this.parentFromOptionsContainer(e.container); + this.parent = n; + const [o, r] = this.initHtml(); + n.appendChild(o), this.container = o, this.scrollContainer = r.querySelector(".scroll"), this.wrapper = r.querySelector(".wrapper"), this.canvasWrapper = r.querySelector(".canvases"), this.progressWrapper = r.querySelector(".progress"), this.cursor = r.querySelector(".cursor"), t && r.appendChild(t), this.initEvents(); + } + parentFromOptionsContainer(e) { + let t; + if (typeof e == "string" ? t = document.querySelector(e) : e instanceof HTMLElement && (t = e), !t) + throw new Error("Container not found"); + return t; + } + initEvents() { + const e = (n) => { + const o = this.wrapper.getBoundingClientRect(), r = n.clientX - o.left, s = n.clientX - o.left; + return [r / o.width, s / o.height]; + }; + this.wrapper.addEventListener("click", (n) => { + const [o, r] = e(n); + this.emit("click", o, r); + }), this.wrapper.addEventListener("dblclick", (n) => { + const [o, r] = e(n); + this.emit("dblclick", o, r); + }), this.options.dragToSeek && this.initDrag(), this.scrollContainer.addEventListener("scroll", () => { + const { scrollLeft: n, scrollWidth: o, clientWidth: r } = this.scrollContainer, s = n / o, l = (n + r) / o; + this.emit("scroll", s, l); + }); + const t = this.createDelay(100); + this.resizeObserver = new ResizeObserver(() => { + t().then(() => this.onContainerResize()).catch(() => { + }); + }), this.resizeObserver.observe(this.scrollContainer); + } + onContainerResize() { + const e = this.parent.clientWidth; + e === this.lastContainerWidth && this.options.height !== "auto" || (this.lastContainerWidth = e, this.reRender()); + } + initDrag() { + (function(e, t, n, o, r = 3, s = 0) { + if (!e) + return () => { + }; + let l = () => { + }; + const a = (c) => { + if (c.button !== s) + return; + c.preventDefault(), c.stopPropagation(); + let u = c.clientX, d = c.clientY, _ = !1; + const h = (m) => { + m.preventDefault(), m.stopPropagation(); + const w = m.clientX, k = m.clientY, A = w - u, W = k - d; + if (_ || Math.abs(A) > r || Math.abs(W) > r) { + const M = e.getBoundingClientRect(), { left: P, top: U } = M; + _ || (n == null || n(u - P, d - U), _ = !0), t(A, W, w - P, k - U), u = w, d = k; + } + }, f = () => { + _ && (o == null || o()), l(); + }, v = (m) => { + m.relatedTarget && m.relatedTarget !== document.documentElement || f(); + }, g = (m) => { + _ && (m.stopPropagation(), m.preventDefault()); + }, p = (m) => { + _ && m.preventDefault(); + }; + document.addEventListener("pointermove", h), document.addEventListener("pointerup", f), document.addEventListener("pointerout", v), document.addEventListener("pointercancel", v), document.addEventListener("touchmove", p, { passive: !1 }), document.addEventListener("click", g, { capture: !0 }), l = () => { + document.removeEventListener("pointermove", h), document.removeEventListener("pointerup", f), document.removeEventListener("pointerout", v), document.removeEventListener("pointercancel", v), document.removeEventListener("touchmove", p), setTimeout(() => { + document.removeEventListener("click", g, { capture: !0 }); + }, 10); + }; + }; + e.addEventListener("pointerdown", a); + })(this.wrapper, (e, t, n) => { + this.emit("drag", Math.max(0, Math.min(1, n / this.wrapper.getBoundingClientRect().width))); + }, () => this.isDragging = !0, () => this.isDragging = !1); + } + getHeight(e) { + return e == null ? 128 : isNaN(Number(e)) ? e === "auto" && this.parent.clientHeight || 128 : Number(e); + } + initHtml() { + const e = document.createElement("div"), t = e.attachShadow({ mode: "open" }); + return t.innerHTML = ` + + +
+
+
+
+
+
+
+ `, [e, t]; + } + setOptions(e) { + if (this.options.container !== e.container) { + const t = this.parentFromOptionsContainer(e.container); + t.appendChild(this.container), this.parent = t; + } + e.dragToSeek && !this.options.dragToSeek && this.initDrag(), this.options = e, this.reRender(); + } + getWrapper() { + return this.wrapper; + } + getScroll() { + return this.scrollContainer.scrollLeft; + } + destroy() { + var e; + this.container.remove(), (e = this.resizeObserver) === null || e === void 0 || e.disconnect(); + } + createDelay(e = 10) { + let t, n; + const o = () => { + t && clearTimeout(t), n && n(); + }; + return this.timeouts.push(o), () => new Promise((r, s) => { + o(), n = s, t = setTimeout(() => { + t = void 0, n = void 0, r(); + }, e); + }); + } + convertColorValues(e) { + if (!Array.isArray(e)) + return e || ""; + if (e.length < 2) + return e[0] || ""; + const t = document.createElement("canvas"), n = t.getContext("2d"), o = t.height * (window.devicePixelRatio || 1), r = n.createLinearGradient(0, 0, 0, o), s = 1 / (e.length - 1); + return e.forEach((l, a) => { + const c = a * s; + r.addColorStop(c, l); + }), r; + } + renderBarWaveform(e, t, n, o) { + const r = e[0], s = e[1] || e[0], l = r.length, { width: a, height: c } = n.canvas, u = c / 2, d = window.devicePixelRatio || 1, _ = t.barWidth ? t.barWidth * d : 1, h = t.barGap ? t.barGap * d : t.barWidth ? _ / 2 : 0, f = t.barRadius || 0, v = a / (_ + h) / l, g = f && "roundRect" in n ? "roundRect" : "rect"; + n.beginPath(); + let p = 0, m = 0, w = 0; + for (let k = 0; k <= l; k++) { + const A = Math.round(k * v); + if (A > p) { + const P = Math.round(m * u * o), U = P + Math.round(w * u * o) || 1; + let H = u - P; + t.barAlign === "top" ? H = 0 : t.barAlign === "bottom" && (H = c - U), n[g](p * (_ + h), H, _, U, f), p = A, m = 0, w = 0; + } + const W = Math.abs(r[k] || 0), M = Math.abs(s[k] || 0); + W > m && (m = W), M > w && (w = M); + } + n.fill(), n.closePath(); + } + renderLineWaveform(e, t, n, o) { + const r = (s) => { + const l = e[s] || e[0], a = l.length, { height: c } = n.canvas, u = c / 2, d = n.canvas.width / a; + n.moveTo(0, u); + let _ = 0, h = 0; + for (let f = 0; f <= a; f++) { + const v = Math.round(f * d); + if (v > _) { + const p = u + (Math.round(h * u * o) || 1) * (s === 0 ? -1 : 1); + n.lineTo(_, p), _ = v, h = 0; + } + const g = Math.abs(l[f] || 0); + g > h && (h = g); + } + n.lineTo(_, u); + }; + n.beginPath(), r(0), r(1), n.fill(), n.closePath(); + } + renderWaveform(e, t, n) { + if (n.fillStyle = this.convertColorValues(t.waveColor), t.renderFunction) + return void t.renderFunction(e, n); + let o = t.barHeight || 1; + if (t.normalize) { + const r = Array.from(e[0]).reduce((s, l) => Math.max(s, Math.abs(l)), 0); + o = r ? 1 / r : 1; + } + t.barWidth || t.barGap || t.barAlign ? this.renderBarWaveform(e, t, n, o) : this.renderLineWaveform(e, t, n, o); + } + renderSingleCanvas(e, t, n, o, r, s, l, a) { + const c = window.devicePixelRatio || 1, u = document.createElement("canvas"), d = e[0].length; + u.width = Math.round(n * (s - r) / d), u.height = o * c, u.style.width = `${Math.floor(u.width / c)}px`, u.style.height = `${o}px`, u.style.left = `${Math.floor(r * n / c / d)}px`, l.appendChild(u); + const _ = u.getContext("2d"); + if (this.renderWaveform(e.map((h) => h.slice(r, s)), t, _), u.width > 0 && u.height > 0) { + const h = u.cloneNode(), f = h.getContext("2d"); + f.drawImage(u, 0, 0), f.globalCompositeOperation = "source-in", f.fillStyle = this.convertColorValues(t.progressColor), f.fillRect(0, 0, u.width, u.height), a.appendChild(h); + } + } + renderChannel(e, t, n) { + return te(this, void 0, void 0, function* () { + const o = document.createElement("div"), r = this.getHeight(t.height); + o.style.height = `${r}px`, this.canvasWrapper.style.minHeight = `${r}px`, this.canvasWrapper.appendChild(o); + const s = o.cloneNode(); + this.progressWrapper.appendChild(s); + const l = e[0].length, a = (p, m) => { + this.renderSingleCanvas(e, t, n, r, Math.max(0, p), Math.min(m, l), o, s); + }; + if (!this.isScrollable) + return void a(0, l); + const { scrollLeft: c, scrollWidth: u, clientWidth: d } = this.scrollContainer, _ = l / u; + let h = Math.min(Jt.MAX_CANVAS_WIDTH, d); + if (t.barWidth || t.barGap) { + const p = t.barWidth || 0.5, m = p + (t.barGap || p / 2); + h % m != 0 && (h = Math.floor(h / m) * m); + } + const f = Math.floor(Math.abs(c) * _), v = Math.floor(f + h * _), g = v - f; + g <= 0 || (a(f, v), yield Promise.all([te(this, void 0, void 0, function* () { + if (f === 0) + return; + const p = this.createDelay(); + for (let m = f; m >= 0; m -= g) + yield p(), a(Math.max(0, m - g), m); + }), te(this, void 0, void 0, function* () { + if (v === l) + return; + const p = this.createDelay(); + for (let m = v; m < l; m += g) + yield p(), a(m, Math.min(l, m + g)); + })])); + }); + } + render(e) { + return te(this, void 0, void 0, function* () { + this.timeouts.forEach((l) => l()), this.timeouts = [], this.canvasWrapper.innerHTML = "", this.progressWrapper.innerHTML = "", this.options.width != null && (this.scrollContainer.style.width = typeof this.options.width == "number" ? `${this.options.width}px` : this.options.width); + const t = window.devicePixelRatio || 1, n = this.scrollContainer.clientWidth, o = Math.ceil(e.duration * (this.options.minPxPerSec || 0)); + this.isScrollable = o > n; + const r = this.options.fillParent && !this.isScrollable, s = (r ? n : o) * t; + this.wrapper.style.width = r ? "100%" : `${o}px`, this.scrollContainer.style.overflowX = this.isScrollable ? "auto" : "hidden", this.scrollContainer.classList.toggle("noScrollbar", !!this.options.hideScrollbar), this.cursor.style.backgroundColor = `${this.options.cursorColor || this.options.progressColor}`, this.cursor.style.width = `${this.options.cursorWidth}px`, this.audioData = e, this.emit("render"); + try { + if (this.options.splitChannels) + yield Promise.all(Array.from({ length: e.numberOfChannels }).map((l, a) => { + var c; + const u = Object.assign(Object.assign({}, this.options), (c = this.options.splitChannels) === null || c === void 0 ? void 0 : c[a]); + return this.renderChannel([e.getChannelData(a)], u, s); + })); + else { + const l = [e.getChannelData(0)]; + e.numberOfChannels > 1 && l.push(e.getChannelData(1)), yield this.renderChannel(l, this.options, s); + } + } catch { + return; + } + this.emit("rendered"); + }); + } + reRender() { + if (!this.audioData) + return; + const { scrollWidth: e } = this.scrollContainer, { right: t } = this.progressWrapper.getBoundingClientRect(); + if (this.render(this.audioData), this.isScrollable && e !== this.scrollContainer.scrollWidth) { + const { right: n } = this.progressWrapper.getBoundingClientRect(); + let o = n - t; + o *= 2, o = o < 0 ? Math.floor(o) : Math.ceil(o), o /= 2, this.scrollContainer.scrollLeft += o; + } + } + zoom(e) { + this.options.minPxPerSec = e, this.reRender(); + } + scrollIntoView(e, t = !1) { + const { scrollLeft: n, scrollWidth: o, clientWidth: r } = this.scrollContainer, s = e * o, l = n, a = n + r, c = r / 2; + if (this.isDragging) + s + 30 > a ? this.scrollContainer.scrollLeft += 30 : s - 30 < l && (this.scrollContainer.scrollLeft -= 30); + else { + (s < l || s > a) && (this.scrollContainer.scrollLeft = s - (this.options.autoCenter ? c : 0)); + const u = s - n - c; + t && this.options.autoCenter && u > 0 && (this.scrollContainer.scrollLeft += Math.min(u, 10)); + } + { + const u = this.scrollContainer.scrollLeft, d = u / o, _ = (u + r) / o; + this.emit("scroll", d, _); + } + } + renderProgress(e, t) { + if (isNaN(e)) + return; + const n = 100 * e; + this.canvasWrapper.style.clipPath = `polygon(${n}% 0, 100% 0, 100% 100%, ${n}% 100%)`, this.progressWrapper.style.width = `${n}%`, this.cursor.style.left = `${n}%`, this.cursor.style.transform = `translateX(-${Math.round(n) === 100 ? this.options.cursorWidth : 0}px)`, this.isScrollable && this.options.autoScroll && this.scrollIntoView(e, t); + } + exportImage(e, t, n) { + return te(this, void 0, void 0, function* () { + const o = this.canvasWrapper.querySelectorAll("canvas"); + if (!o.length) + throw new Error("No waveform data"); + if (n === "dataURL") { + const r = Array.from(o).map((s) => s.toDataURL(e, t)); + return Promise.resolve(r); + } + return Promise.all(Array.from(o).map((r) => new Promise((s, l) => { + r.toBlob((a) => { + a ? s(a) : l(new Error("Could not export image")); + }, e, t); + }))); + }); + } +} +Jt.MAX_CANVAS_WIDTH = 4e3; +class dl extends Ct { + constructor() { + super(...arguments), this.unsubscribe = () => { + }; + } + start() { + this.unsubscribe = this.on("tick", () => { + requestAnimationFrame(() => { + this.emit("tick"); + }); + }), this.emit("tick"); + } + stop() { + this.unsubscribe(); + } + destroy() { + this.unsubscribe(); + } +} +class fl extends Ct { + constructor(e = new AudioContext()) { + super(), this.bufferNode = null, this.autoplay = !1, this.playStartTime = 0, this.playedDuration = 0, this._muted = !1, this.buffer = null, this.currentSrc = "", this.paused = !0, this.crossOrigin = null, this.addEventListener = this.on, this.removeEventListener = this.un, this.audioContext = e, this.gainNode = this.audioContext.createGain(), this.gainNode.connect(this.audioContext.destination); + } + load() { + return te(this, void 0, void 0, function* () { + }); + } + get src() { + return this.currentSrc; + } + set src(e) { + if (this.currentSrc = e, !e) + return this.buffer = null, void this.emit("emptied"); + fetch(e).then((t) => t.arrayBuffer()).then((t) => this.currentSrc !== e ? null : this.audioContext.decodeAudioData(t)).then((t) => { + this.currentSrc === e && (this.buffer = t, this.emit("loadedmetadata"), this.emit("canplay"), this.autoplay && this.play()); + }); + } + _play() { + var e; + this.paused && (this.paused = !1, (e = this.bufferNode) === null || e === void 0 || e.disconnect(), this.bufferNode = this.audioContext.createBufferSource(), this.bufferNode.buffer = this.buffer, this.bufferNode.connect(this.gainNode), this.playedDuration >= this.duration && (this.playedDuration = 0), this.bufferNode.start(this.audioContext.currentTime, this.playedDuration), this.playStartTime = this.audioContext.currentTime, this.bufferNode.onended = () => { + this.currentTime >= this.duration && (this.pause(), this.emit("ended")); + }); + } + _pause() { + var e; + this.paused || (this.paused = !0, (e = this.bufferNode) === null || e === void 0 || e.stop(), this.playedDuration += this.audioContext.currentTime - this.playStartTime); + } + play() { + return te(this, void 0, void 0, function* () { + this._play(), this.emit("play"); + }); + } + pause() { + this._pause(), this.emit("pause"); + } + stopAt(e) { + var t, n; + const o = e - this.currentTime; + (t = this.bufferNode) === null || t === void 0 || t.stop(this.audioContext.currentTime + o), (n = this.bufferNode) === null || n === void 0 || n.addEventListener("ended", () => { + this.bufferNode = null, this.pause(); + }, { once: !0 }); + } + setSinkId(e) { + return te(this, void 0, void 0, function* () { + return this.audioContext.setSinkId(e); + }); + } + get playbackRate() { + var e, t; + return (t = (e = this.bufferNode) === null || e === void 0 ? void 0 : e.playbackRate.value) !== null && t !== void 0 ? t : 1; + } + set playbackRate(e) { + this.bufferNode && (this.bufferNode.playbackRate.value = e); + } + get currentTime() { + return this.paused ? this.playedDuration : this.playedDuration + this.audioContext.currentTime - this.playStartTime; + } + set currentTime(e) { + this.emit("seeking"), this.paused ? this.playedDuration = e : (this._pause(), this.playedDuration = e, this._play()), this.emit("timeupdate"); + } + get duration() { + var e; + return ((e = this.buffer) === null || e === void 0 ? void 0 : e.duration) || 0; + } + get volume() { + return this.gainNode.gain.value; + } + set volume(e) { + this.gainNode.gain.value = e, this.emit("volumechange"); + } + get muted() { + return this._muted; + } + set muted(e) { + this._muted !== e && (this._muted = e, this._muted ? this.gainNode.disconnect() : this.gainNode.connect(this.audioContext.destination)); + } + canPlayType(e) { + return /^(audio|video)\//.test(e); + } + getGainNode() { + return this.gainNode; + } + getChannelData() { + const e = []; + if (!this.buffer) + return e; + const t = this.buffer.numberOfChannels; + for (let n = 0; n < t; n++) + e.push(this.buffer.getChannelData(n)); + return e; + } +} +const hl = { waveColor: "#999", progressColor: "#555", cursorWidth: 1, minPxPerSec: 0, fillParent: !0, interact: !0, dragToSeek: !1, autoScroll: !0, autoCenter: !0, sampleRate: 8e3 }; +class Ve extends ul { + static create(e) { + return new Ve(e); + } + constructor(e) { + const t = e.media || (e.backend === "WebAudio" ? new fl() : void 0); + super({ media: t, mediaControls: e.mediaControls, autoplay: e.autoplay, playbackRate: e.audioRate }), this.plugins = [], this.decodedData = null, this.subscriptions = [], this.mediaSubscriptions = [], this.options = Object.assign({}, hl, e), this.timer = new dl(); + const n = t ? void 0 : this.getMediaElement(); + this.renderer = new Jt(this.options, n), this.initPlayerEvents(), this.initRendererEvents(), this.initTimerEvents(), this.initPlugins(), Promise.resolve().then(() => { + this.emit("init"); + const o = this.options.url || this.getSrc() || ""; + (o || this.options.peaks && this.options.duration) && this.load(o, this.options.peaks, this.options.duration); + }); + } + updateProgress(e = this.getCurrentTime()) { + return this.renderer.renderProgress(e / this.getDuration(), this.isPlaying()), e; + } + initTimerEvents() { + this.subscriptions.push(this.timer.on("tick", () => { + if (!this.isSeeking()) { + const e = this.updateProgress(); + this.emit("timeupdate", e), this.emit("audioprocess", e); + } + })); + } + initPlayerEvents() { + this.isPlaying() && (this.emit("play"), this.timer.start()), this.mediaSubscriptions.push(this.onMediaEvent("timeupdate", () => { + const e = this.updateProgress(); + this.emit("timeupdate", e); + }), this.onMediaEvent("play", () => { + this.emit("play"), this.timer.start(); + }), this.onMediaEvent("pause", () => { + this.emit("pause"), this.timer.stop(); + }), this.onMediaEvent("emptied", () => { + this.timer.stop(); + }), this.onMediaEvent("ended", () => { + this.emit("finish"); + }), this.onMediaEvent("seeking", () => { + this.emit("seeking", this.getCurrentTime()); + })); + } + initRendererEvents() { + this.subscriptions.push(this.renderer.on("click", (e, t) => { + this.options.interact && (this.seekTo(e), this.emit("interaction", e * this.getDuration()), this.emit("click", e, t)); + }), this.renderer.on("dblclick", (e, t) => { + this.emit("dblclick", e, t); + }), this.renderer.on("scroll", (e, t) => { + const n = this.getDuration(); + this.emit("scroll", e * n, t * n); + }), this.renderer.on("render", () => { + this.emit("redraw"); + }), this.renderer.on("rendered", () => { + this.emit("redrawcomplete"); + })); + { + let e; + this.subscriptions.push(this.renderer.on("drag", (t) => { + this.options.interact && (this.renderer.renderProgress(t), clearTimeout(e), e = setTimeout(() => { + this.seekTo(t); + }, this.isPlaying() ? 0 : 200), this.emit("interaction", t * this.getDuration()), this.emit("drag", t)); + })); + } + } + initPlugins() { + var e; + !((e = this.options.plugins) === null || e === void 0) && e.length && this.options.plugins.forEach((t) => { + this.registerPlugin(t); + }); + } + unsubscribePlayerEvents() { + this.mediaSubscriptions.forEach((e) => e()), this.mediaSubscriptions = []; + } + setOptions(e) { + this.options = Object.assign({}, this.options, e), this.renderer.setOptions(this.options), e.audioRate && this.setPlaybackRate(e.audioRate), e.mediaControls != null && (this.getMediaElement().controls = e.mediaControls); + } + registerPlugin(e) { + return e._init(this), this.plugins.push(e), this.subscriptions.push(e.once("destroy", () => { + this.plugins = this.plugins.filter((t) => t !== e); + })), e; + } + getWrapper() { + return this.renderer.getWrapper(); + } + getScroll() { + return this.renderer.getScroll(); + } + getActivePlugins() { + return this.plugins; + } + loadAudio(e, t, n, o) { + return te(this, void 0, void 0, function* () { + if (this.emit("load", e), !this.options.media && this.isPlaying() && this.pause(), this.decodedData = null, !t && !n) { + const s = (l) => this.emit("loading", l); + t = yield cl.fetchBlob(e, s, this.options.fetchParams); + } + this.setSrc(e, t); + const r = o || this.getDuration() || (yield new Promise((s) => { + this.onceMediaEvent("loadedmetadata", () => s(this.getDuration())); + })); + if (n) + this.decodedData = ai.createBuffer(n, r || 0); + else if (t) { + const s = yield t.arrayBuffer(); + this.decodedData = yield ai.decode(s, this.options.sampleRate); + } + this.decodedData && (this.emit("decode", this.getDuration()), this.renderer.render(this.decodedData)), this.emit("ready", this.getDuration()); + }); + } + load(e, t, n) { + return te(this, void 0, void 0, function* () { + yield this.loadAudio(e, void 0, t, n); + }); + } + loadBlob(e, t, n) { + return te(this, void 0, void 0, function* () { + yield this.loadAudio("blob", e, t, n); + }); + } + zoom(e) { + if (!this.decodedData) + throw new Error("No audio loaded"); + this.renderer.zoom(e), this.emit("zoom", e); + } + getDecodedData() { + return this.decodedData; + } + exportPeaks({ channels: e = 2, maxLength: t = 8e3, precision: n = 1e4 } = {}) { + if (!this.decodedData) + throw new Error("The audio has not been decoded yet"); + const o = Math.min(e, this.decodedData.numberOfChannels), r = []; + for (let s = 0; s < o; s++) { + const l = this.decodedData.getChannelData(s), a = [], c = Math.round(l.length / t); + for (let u = 0; u < t; u++) { + const d = l.slice(u * c, (u + 1) * c); + let _ = 0; + for (let h = 0; h < d.length; h++) { + const f = d[h]; + Math.abs(f) > Math.abs(_) && (_ = f); + } + a.push(Math.round(_ * n) / n); + } + r.push(a); + } + return r; + } + getDuration() { + let e = super.getDuration() || 0; + return e !== 0 && e !== 1 / 0 || !this.decodedData || (e = this.decodedData.duration), e; + } + toggleInteraction(e) { + this.options.interact = e; + } + setTime(e) { + super.setTime(e), this.updateProgress(e); + } + seekTo(e) { + const t = this.getDuration() * e; + this.setTime(t); + } + playPause() { + return te(this, void 0, void 0, function* () { + return this.isPlaying() ? this.pause() : this.play(); + }); + } + stop() { + this.pause(), this.setTime(0); + } + skip(e) { + this.setTime(this.getCurrentTime() + e); + } + empty() { + this.load("", [[0]], 1e-3); + } + setMediaElement(e) { + this.unsubscribePlayerEvents(), super.setMediaElement(e), this.initPlayerEvents(); + } + exportImage(e = "image/png", t = 1, n = "dataURL") { + return te(this, void 0, void 0, function* () { + return this.renderer.exportImage(e, t, n); + }); + } + destroy() { + this.emit("destroy"), this.plugins.forEach((e) => e.destroy()), this.subscriptions.forEach((e) => e()), this.unsubscribePlayerEvents(), this.timer.destroy(), this.renderer.destroy(), super.destroy(); + } +} +Ve.BasePlugin = class extends Ct { + constructor(i) { + super(), this.subscriptions = [], this.options = i; + } + onInit() { + } + _init(i) { + this.wavesurfer = i, this.onInit(); + } + destroy() { + this.emit("destroy"), this.subscriptions.forEach((i) => i()); + } +}, Ve.dom = al; +let uo = class { + constructor() { + this.listeners = {}; + } + on(e, t, n) { + if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(t), n == null ? void 0 : n.once) { + const o = () => { + this.un(e, o), this.un(e, t); + }; + return this.on(e, o), o; + } + return () => this.un(e, t); + } + un(e, t) { + var n; + (n = this.listeners[e]) === null || n === void 0 || n.delete(t); + } + once(e, t) { + return this.on(e, t, { once: !0 }); + } + unAll() { + this.listeners = {}; + } + emit(e, ...t) { + this.listeners[e] && this.listeners[e].forEach((n) => n(...t)); + } +}, _l = class extends uo { + constructor(e) { + super(), this.subscriptions = [], this.options = e; + } + onInit() { + } + _init(e) { + this.wavesurfer = e, this.onInit(); + } + destroy() { + this.emit("destroy"), this.subscriptions.forEach((e) => e()); + } +}; +function Pt(i, e, t, n, o = 3, r = 0) { + if (!i) + return () => { + }; + let s = () => { + }; + const l = (a) => { + if (a.button !== r) + return; + a.preventDefault(), a.stopPropagation(); + let c = a.clientX, u = a.clientY, d = !1; + const _ = (p) => { + p.preventDefault(), p.stopPropagation(); + const m = p.clientX, w = p.clientY, k = m - c, A = w - u; + if (d || Math.abs(k) > o || Math.abs(A) > o) { + const W = i.getBoundingClientRect(), { left: M, top: P } = W; + d || (t == null || t(c - M, u - P), d = !0), e(k, A, m - M, w - P), c = m, u = w; + } + }, h = () => { + d && (n == null || n()), s(); + }, f = (p) => { + p.relatedTarget && p.relatedTarget !== document.documentElement || h(); + }, v = (p) => { + d && (p.stopPropagation(), p.preventDefault()); + }, g = (p) => { + d && p.preventDefault(); + }; + document.addEventListener("pointermove", _), document.addEventListener("pointerup", h), document.addEventListener("pointerout", f), document.addEventListener("pointercancel", f), document.addEventListener("touchmove", g, { passive: !1 }), document.addEventListener("click", v, { capture: !0 }), s = () => { + document.removeEventListener("pointermove", _), document.removeEventListener("pointerup", h), document.removeEventListener("pointerout", f), document.removeEventListener("pointercancel", f), document.removeEventListener("touchmove", g), setTimeout(() => { + document.removeEventListener("click", v, { capture: !0 }); + }, 10); + }; + }; + return i.addEventListener("pointerdown", l), () => { + s(), i.removeEventListener("pointerdown", l); + }; +} +function fo(i, e) { + const t = e.xmlns ? document.createElementNS(e.xmlns, i) : document.createElement(i); + for (const [n, o] of Object.entries(e)) + if (n === "children") + for (const [r, s] of Object.entries(e)) + typeof s == "string" ? t.appendChild(document.createTextNode(s)) : t.appendChild(fo(r, s)); + else + n === "style" ? Object.assign(t.style, o) : n === "textContent" ? t.textContent = o : t.setAttribute(n, o.toString()); + return t; +} +function gt(i, e, t) { + const n = fo(i, e || {}); + return t == null || t.appendChild(n), n; +} +let ui = class extends uo { + constructor(e, t, n = 0) { + var o, r, s, l, a, c, u, d; + super(), this.totalDuration = t, this.numberOfChannels = n, this.minLength = 0, this.maxLength = 1 / 0, this.contentEditable = !1, this.id = e.id || `region-${Math.random().toString(32).slice(2)}`, this.start = this.clampPosition(e.start), this.end = this.clampPosition((o = e.end) !== null && o !== void 0 ? o : e.start), this.drag = (r = e.drag) === null || r === void 0 || r, this.resize = (s = e.resize) === null || s === void 0 || s, this.color = (l = e.color) !== null && l !== void 0 ? l : "rgba(0, 0, 0, 0.1)", this.minLength = (a = e.minLength) !== null && a !== void 0 ? a : this.minLength, this.maxLength = (c = e.maxLength) !== null && c !== void 0 ? c : this.maxLength, this.channelIdx = (u = e.channelIdx) !== null && u !== void 0 ? u : -1, this.contentEditable = (d = e.contentEditable) !== null && d !== void 0 ? d : this.contentEditable, this.element = this.initElement(), this.setContent(e.content), this.setPart(), this.renderPosition(), this.initMouseEvents(); + } + clampPosition(e) { + return Math.max(0, Math.min(this.totalDuration, e)); + } + setPart() { + const e = this.start === this.end; + this.element.setAttribute("part", `${e ? "marker" : "region"} ${this.id}`); + } + addResizeHandles(e) { + const t = { position: "absolute", zIndex: "2", width: "6px", height: "100%", top: "0", cursor: "ew-resize", wordBreak: "keep-all" }, n = gt("div", { part: "region-handle region-handle-left", style: Object.assign(Object.assign({}, t), { left: "0", borderLeft: "2px solid rgba(0, 0, 0, 0.5)", borderRadius: "2px 0 0 2px" }) }, e), o = gt("div", { part: "region-handle region-handle-right", style: Object.assign(Object.assign({}, t), { right: "0", borderRight: "2px solid rgba(0, 0, 0, 0.5)", borderRadius: "0 2px 2px 0" }) }, e); + Pt(n, (r) => this.onResize(r, "start"), () => null, () => this.onEndResizing(), 1), Pt(o, (r) => this.onResize(r, "end"), () => null, () => this.onEndResizing(), 1); + } + removeResizeHandles(e) { + const t = e.querySelector('[part*="region-handle-left"]'), n = e.querySelector('[part*="region-handle-right"]'); + t && e.removeChild(t), n && e.removeChild(n); + } + initElement() { + const e = this.start === this.end; + let t = 0, n = 100; + this.channelIdx >= 0 && this.channelIdx < this.numberOfChannels && (n = 100 / this.numberOfChannels, t = n * this.channelIdx); + const o = gt("div", { style: { position: "absolute", top: `${t}%`, height: `${n}%`, backgroundColor: e ? "none" : this.color, borderLeft: e ? "2px solid " + this.color : "none", borderRadius: "2px", boxSizing: "border-box", transition: "background-color 0.2s ease", cursor: this.drag ? "grab" : "default", pointerEvents: "all" } }); + return !e && this.resize && this.addResizeHandles(o), o; + } + renderPosition() { + const e = this.start / this.totalDuration, t = (this.totalDuration - this.end) / this.totalDuration; + this.element.style.left = 100 * e + "%", this.element.style.right = 100 * t + "%"; + } + toggleCursor(e) { + var t; + this.drag && (!((t = this.element) === null || t === void 0) && t.style) && (this.element.style.cursor = e ? "grabbing" : "grab"); + } + initMouseEvents() { + const { element: e } = this; + e && (e.addEventListener("click", (t) => this.emit("click", t)), e.addEventListener("mouseenter", (t) => this.emit("over", t)), e.addEventListener("mouseleave", (t) => this.emit("leave", t)), e.addEventListener("dblclick", (t) => this.emit("dblclick", t)), e.addEventListener("pointerdown", () => this.toggleCursor(!0)), e.addEventListener("pointerup", () => this.toggleCursor(!1)), Pt(e, (t) => this.onMove(t), () => this.toggleCursor(!0), () => { + this.toggleCursor(!1), this.drag && this.emit("update-end"); + }), this.contentEditable && this.content && (this.content.addEventListener("click", (t) => this.onContentClick(t)), this.content.addEventListener("blur", () => this.onContentBlur()))); + } + _onUpdate(e, t) { + if (!this.element.parentElement) + return; + const { width: n } = this.element.parentElement.getBoundingClientRect(), o = e / n * this.totalDuration, r = t && t !== "start" ? this.start : this.start + o, s = t && t !== "end" ? this.end : this.end + o, l = s - r; + r >= 0 && s <= this.totalDuration && r <= s && l >= this.minLength && l <= this.maxLength && (this.start = r, this.end = s, this.renderPosition(), this.emit("update", t)); + } + onMove(e) { + this.drag && this._onUpdate(e); + } + onResize(e, t) { + this.resize && this._onUpdate(e, t); + } + onEndResizing() { + this.resize && this.emit("update-end"); + } + onContentClick(e) { + e.stopPropagation(), e.target.focus(), this.emit("click", e); + } + onContentBlur() { + this.emit("update-end"); + } + _setTotalDuration(e) { + this.totalDuration = e, this.renderPosition(); + } + play() { + this.emit("play"); + } + setContent(e) { + var t; + if ((t = this.content) === null || t === void 0 || t.remove(), e) { + if (typeof e == "string") { + const n = this.start === this.end; + this.content = gt("div", { style: { padding: `0.2em ${n ? 0.2 : 0.4}em`, display: "inline-block" }, textContent: e }); + } else + this.content = e; + this.contentEditable && (this.content.contentEditable = "true"), this.content.setAttribute("part", "region-content"), this.element.appendChild(this.content); + } else + this.content = void 0; + } + setOptions(e) { + var t, n; + if (e.color && (this.color = e.color, this.element.style.backgroundColor = this.color), e.drag !== void 0 && (this.drag = e.drag, this.element.style.cursor = this.drag ? "grab" : "default"), e.start !== void 0 || e.end !== void 0) { + const o = this.start === this.end; + this.start = this.clampPosition((t = e.start) !== null && t !== void 0 ? t : this.start), this.end = this.clampPosition((n = e.end) !== null && n !== void 0 ? n : o ? this.start : this.end), this.renderPosition(), this.setPart(); + } + if (e.content && this.setContent(e.content), e.id && (this.id = e.id, this.setPart()), e.resize !== void 0 && e.resize !== this.resize) { + const o = this.start === this.end; + this.resize = e.resize, this.resize && !o ? this.addResizeHandles(this.element) : this.removeResizeHandles(this.element); + } + } + remove() { + this.emit("remove"), this.element.remove(), this.element = null; + } +}, ml = class ho extends _l { + constructor(e) { + super(e), this.regions = [], this.regionsContainer = this.initRegionsContainer(); + } + static create(e) { + return new ho(e); + } + onInit() { + if (!this.wavesurfer) + throw Error("WaveSurfer is not initialized"); + this.wavesurfer.getWrapper().appendChild(this.regionsContainer); + let e = []; + this.subscriptions.push(this.wavesurfer.on("timeupdate", (t) => { + const n = this.regions.filter((o) => o.start <= t && (o.end === o.start ? o.start + 0.05 : o.end) >= t); + n.forEach((o) => { + e.includes(o) || this.emit("region-in", o); + }), e.forEach((o) => { + n.includes(o) || this.emit("region-out", o); + }), e = n; + })); + } + initRegionsContainer() { + return gt("div", { style: { position: "absolute", top: "0", left: "0", width: "100%", height: "100%", zIndex: "3", pointerEvents: "none" } }); + } + getRegions() { + return this.regions; + } + avoidOverlapping(e) { + if (!e.content) + return; + const t = e.content, n = t.getBoundingClientRect(), o = this.regions.map((r) => { + if (r === e || !r.content) + return 0; + const s = r.content.getBoundingClientRect(); + return n.left < s.left + s.width && s.left < n.left + n.width ? s.height : 0; + }).reduce((r, s) => r + s, 0); + t.style.marginTop = `${o}px`; + } + adjustScroll(e) { + var t, n; + const o = (n = (t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getWrapper()) === null || n === void 0 ? void 0 : n.parentElement; + if (!o) + return; + const { clientWidth: r, scrollWidth: s } = o; + if (s <= r) + return; + const l = o.getBoundingClientRect(), a = e.element.getBoundingClientRect(), c = a.left - l.left, u = a.right - l.left; + c < 0 ? o.scrollLeft += c : u > r && (o.scrollLeft += u - r); + } + saveRegion(e) { + this.regionsContainer.appendChild(e.element), this.avoidOverlapping(e), this.regions.push(e); + const t = [e.on("update", (n) => { + n || this.adjustScroll(e); + }), e.on("update-end", () => { + this.avoidOverlapping(e), this.emit("region-updated", e); + }), e.on("play", () => { + var n, o; + (n = this.wavesurfer) === null || n === void 0 || n.play(), (o = this.wavesurfer) === null || o === void 0 || o.setTime(e.start); + }), e.on("click", (n) => { + this.emit("region-clicked", e, n); + }), e.on("dblclick", (n) => { + this.emit("region-double-clicked", e, n); + }), e.once("remove", () => { + t.forEach((n) => n()), this.regions = this.regions.filter((n) => n !== e), this.emit("region-removed", e); + })]; + this.subscriptions.push(...t), this.emit("region-created", e); + } + addRegion(e) { + var t, n; + if (!this.wavesurfer) + throw Error("WaveSurfer is not initialized"); + const o = this.wavesurfer.getDuration(), r = (n = (t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getDecodedData()) === null || n === void 0 ? void 0 : n.numberOfChannels, s = new ui(e, o, r); + return o ? this.saveRegion(s) : this.subscriptions.push(this.wavesurfer.once("ready", (l) => { + s._setTotalDuration(l), this.saveRegion(s); + })), s; + } + enableDragSelection(e, t = 3) { + var n; + const o = (n = this.wavesurfer) === null || n === void 0 ? void 0 : n.getWrapper(); + if (!(o && o instanceof HTMLElement)) + return () => { + }; + let r = null, s = 0; + return Pt(o, (l, a, c) => { + r && r._onUpdate(l, c > s ? "end" : "start"); + }, (l) => { + var a, c; + if (s = l, !this.wavesurfer) + return; + const u = this.wavesurfer.getDuration(), d = (c = (a = this.wavesurfer) === null || a === void 0 ? void 0 : a.getDecodedData()) === null || c === void 0 ? void 0 : c.numberOfChannels, { width: _ } = this.wavesurfer.getWrapper().getBoundingClientRect(), h = l / _ * u, f = (l + 5) / _ * u; + r = new ui(Object.assign(Object.assign({}, e), { start: h, end: f }), u, d), this.regionsContainer.appendChild(r.element); + }, () => { + r && (this.saveRegion(r), r = null); + }, t); + } + clearRegions() { + this.regions.forEach((e) => e.remove()); + } + destroy() { + this.clearRegions(), super.destroy(), this.regionsContainer.remove(); + } +}; +function pl(i) { + const e = i.numberOfChannels, t = i.length * e * 2 + 44, n = new ArrayBuffer(t), o = new DataView(n); + let r = 0; + const s = function(l, a, c) { + for (let u = 0; u < c.length; u++) + l.setUint8(a + u, c.charCodeAt(u)); + }; + s(o, r, "RIFF"), r += 4, o.setUint32(r, t - 8, !0), r += 4, s(o, r, "WAVE"), r += 4, s(o, r, "fmt "), r += 4, o.setUint32(r, 16, !0), r += 4, o.setUint16(r, 1, !0), r += 2, o.setUint16(r, e, !0), r += 2, o.setUint32(r, i.sampleRate, !0), r += 4, o.setUint32(r, i.sampleRate * 2 * e, !0), r += 4, o.setUint16(r, e * 2, !0), r += 2, o.setUint16(r, 16, !0), r += 2, s(o, r, "data"), r += 4, o.setUint32(r, i.length * e * 2, !0), r += 4; + for (let l = 0; l < i.numberOfChannels; l++) { + const a = i.getChannelData(l); + for (let c = 0; c < a.length; c++) + o.setInt16(r, a[c] * 65535, !0), r += 2; + } + return new Uint8Array(n); +} +const bn = async (i, e, t) => { + const n = new AudioContext(), o = i.numberOfChannels, r = i.sampleRate; + let s = i.length, l = 0; + e && t && (l = Math.round(e * r), s = Math.round(t * r) - l); + const a = n.createBuffer( + o, + s, + r + ); + for (let c = 0; c < o; c++) { + const u = i.getChannelData(c), d = a.getChannelData(c); + for (let _ = 0; _ < s; _++) + d[_] = u[l + _]; + } + return pl(a); +}, It = (i, e) => { + i && i.skip(e); +}, ot = (i, e) => i / 100 * (e || 5), { + SvelteComponent: gl, + append: ce, + attr: K, + check_outros: Tt, + create_component: at, + destroy_component: ct, + detach: Ke, + element: ve, + empty: vl, + group_outros: At, + init: bl, + insert: Qe, + listen: je, + mount_component: ut, + noop: vt, + run_all: _o, + safe_not_equal: wl, + set_data: yl, + space: it, + text: di, + transition_in: se, + transition_out: ue +} = window.__gradio__svelte__internal; +function kl(i) { + let e, t; + return e = new sr({}), { + c() { + at(e.$$.fragment); + }, + m(n, o) { + ut(e, n, o), t = !0; + }, + i(n) { + t || (se(e.$$.fragment, n), t = !0); + }, + o(n) { + ue(e.$$.fragment, n), t = !1; + }, + d(n) { + ct(e, n); + } + }; +} +function Cl(i) { + let e, t; + return e = new Qs({}), { + c() { + at(e.$$.fragment); + }, + m(n, o) { + ut(e, n, o), t = !0; + }, + i(n) { + t || (se(e.$$.fragment, n), t = !0); + }, + o(n) { + ue(e.$$.fragment, n), t = !1; + }, + d(n) { + ct(e, n); + } + }; +} +function fi(i) { + let e, t, n, o, r; + return t = new br({}), { + c() { + e = ve("button"), at(t.$$.fragment), K(e, "class", "action icon svelte-1duohn5"), K(e, "aria-label", "Reset audio"); + }, + m(s, l) { + Qe(s, e, l), ut(t, e, null), n = !0, o || (r = je( + e, + "click", + /*click_handler_4*/ + i[26] + ), o = !0); + }, + p: vt, + i(s) { + n || (se(t.$$.fragment, s), n = !0); + }, + o(s) { + ue(t.$$.fragment, s), n = !1; + }, + d(s) { + s && Ke(e), ct(t), o = !1, r(); + } + }; +} +function hi(i) { + let e, t, n, o; + const r = [El, Sl], s = []; + function l(a, c) { + return ( + /*mode*/ + a[0] === "" ? 0 : 1 + ); + } + return e = l(i), t = s[e] = r[e](i), { + c() { + t.c(), n = vl(); + }, + m(a, c) { + s[e].m(a, c), Qe(a, n, c), o = !0; + }, + p(a, c) { + let u = e; + e = l(a), e === u ? s[e].p(a, c) : (At(), ue(s[u], 1, 1, () => { + s[u] = null; + }), Tt(), t = s[e], t ? t.p(a, c) : (t = s[e] = r[e](a), t.c()), se(t, 1), t.m(n.parentNode, n)); + }, + i(a) { + o || (se(t), o = !0); + }, + o(a) { + ue(t), o = !1; + }, + d(a) { + a && Ke(n), s[e].d(a); + } + }; +} +function Sl(i) { + let e, t, n, o, r; + return { + c() { + e = ve("button"), e.textContent = "Trim", t = it(), n = ve("button"), n.textContent = "Cancel", K(e, "class", "text-button svelte-1duohn5"), K(n, "class", "text-button svelte-1duohn5"); + }, + m(s, l) { + Qe(s, e, l), Qe(s, t, l), Qe(s, n, l), o || (r = [ + je( + e, + "click", + /*trimAudio*/ + i[11] + ), + je( + n, + "click", + /*toggleTrimmingMode*/ + i[13] + ) + ], o = !0); + }, + p: vt, + i: vt, + o: vt, + d(s) { + s && (Ke(e), Ke(t), Ke(n)), o = !1, _o(r); + } + }; +} +function El(i) { + let e, t, n, o, r; + return t = new fr({}), { + c() { + e = ve("button"), at(t.$$.fragment), K(e, "class", "action icon svelte-1duohn5"), K(e, "aria-label", "Trim audio to selection"); + }, + m(s, l) { + Qe(s, e, l), ut(t, e, null), n = !0, o || (r = je( + e, + "click", + /*toggleTrimmingMode*/ + i[13] + ), o = !0); + }, + p: vt, + i(s) { + n || (se(t.$$.fragment, s), n = !0); + }, + o(s) { + ue(t.$$.fragment, s), n = !1; + }, + d(s) { + s && Ke(e), ct(t), o = !1, r(); + } + }; +} +function Dl(i) { + let e, t, n, o, r, s, l, a, c, u, d, _, h, f, v, g, p, m, w, k, A, W, M, P, U, H; + u = new ks({}); + const X = [Cl, kl], F = []; + function y(b, D) { + return ( + /*playing*/ + b[4] ? 0 : 1 + ); + } + f = y(i), v = F[f] = X[f](i), w = new Bs({}); + let S = ( + /*showRedo*/ + i[5] && /*mode*/ + i[0] === "" && fi(i) + ), L = ( + /*interactive*/ + i[6] && hi(i) + ); + return { + c() { + e = ve("div"), t = ve("button"), n = ve("span"), o = di( + /*playbackSpeed*/ + i[9] + ), r = di("x"), l = it(), a = ve("div"), c = ve("button"), at(u.$$.fragment), _ = it(), h = ve("button"), v.c(), p = it(), m = ve("button"), at(w.$$.fragment), A = it(), W = ve("div"), S && S.c(), M = it(), L && L.c(), K(n, "class", "svelte-1duohn5"), K(t, "class", "playback icon svelte-1duohn5"), K(t, "aria-label", s = `Adjust playback speed to ${/*playbackSpeeds*/ + i[10][ + /*playbackSpeeds*/ + (i[10].indexOf( + /*playbackSpeed*/ + i[9] + ) + 1) % /*playbackSpeeds*/ + i[10].length + ]}x`), K(c, "class", "rewind icon svelte-1duohn5"), K(c, "aria-label", d = `Skip backwards by ${ot( + /*audioDuration*/ + i[2], + /*waveform_settings*/ + i[8].skip_length + )} seconds`), K(h, "class", "play-pause-button icon svelte-1duohn5"), K(h, "aria-label", g = /*playing*/ + i[4] ? ( + /*i18n*/ + i[3]("common.play") + ) : ( + /*i18n*/ + i[3]("common.pause") + )), K(m, "class", "skip icon svelte-1duohn5"), K(m, "aria-label", k = "Skip forward by " + ot( + /*audioDuration*/ + i[2], + /*waveform_settings*/ + i[8].skip_length + ) + " seconds"), K(a, "class", "play-pause-wrapper svelte-1duohn5"), K(W, "class", "settings-wrapper svelte-1duohn5"), K(e, "class", "controls svelte-1duohn5"), K(e, "data-testid", "waveform-controls"); + }, + m(b, D) { + Qe(b, e, D), ce(e, t), ce(t, n), ce(n, o), ce(n, r), ce(e, l), ce(e, a), ce(a, c), ut(u, c, null), ce(a, _), ce(a, h), F[f].m(h, null), ce(a, p), ce(a, m), ut(w, m, null), ce(e, A), ce(e, W), S && S.m(W, null), ce(W, M), L && L.m(W, null), P = !0, U || (H = [ + je( + t, + "click", + /*click_handler*/ + i[22] + ), + je( + c, + "click", + /*click_handler_1*/ + i[23] + ), + je( + h, + "click", + /*click_handler_2*/ + i[24] + ), + je( + m, + "click", + /*click_handler_3*/ + i[25] + ) + ], U = !0); + }, + p(b, [D]) { + (!P || D & /*playbackSpeed*/ + 512) && yl( + o, + /*playbackSpeed*/ + b[9] + ), (!P || D & /*playbackSpeed*/ + 512 && s !== (s = `Adjust playback speed to ${/*playbackSpeeds*/ + b[10][ + /*playbackSpeeds*/ + (b[10].indexOf( + /*playbackSpeed*/ + b[9] + ) + 1) % /*playbackSpeeds*/ + b[10].length + ]}x`)) && K(t, "aria-label", s), (!P || D & /*audioDuration, waveform_settings*/ + 260 && d !== (d = `Skip backwards by ${ot( + /*audioDuration*/ + b[2], + /*waveform_settings*/ + b[8].skip_length + )} seconds`)) && K(c, "aria-label", d); + let E = f; + f = y(b), f !== E && (At(), ue(F[E], 1, 1, () => { + F[E] = null; + }), Tt(), v = F[f], v || (v = F[f] = X[f](b), v.c()), se(v, 1), v.m(h, null)), (!P || D & /*playing, i18n*/ + 24 && g !== (g = /*playing*/ + b[4] ? ( + /*i18n*/ + b[3]("common.play") + ) : ( + /*i18n*/ + b[3]("common.pause") + ))) && K(h, "aria-label", g), (!P || D & /*audioDuration, waveform_settings*/ + 260 && k !== (k = "Skip forward by " + ot( + /*audioDuration*/ + b[2], + /*waveform_settings*/ + b[8].skip_length + ) + " seconds")) && K(m, "aria-label", k), /*showRedo*/ + b[5] && /*mode*/ + b[0] === "" ? S ? (S.p(b, D), D & /*showRedo, mode*/ + 33 && se(S, 1)) : (S = fi(b), S.c(), se(S, 1), S.m(W, M)) : S && (At(), ue(S, 1, 1, () => { + S = null; + }), Tt()), /*interactive*/ + b[6] ? L ? (L.p(b, D), D & /*interactive*/ + 64 && se(L, 1)) : (L = hi(b), L.c(), se(L, 1), L.m(W, null)) : L && (At(), ue(L, 1, 1, () => { + L = null; + }), Tt()); + }, + i(b) { + P || (se(u.$$.fragment, b), se(v), se(w.$$.fragment, b), se(S), se(L), P = !0); + }, + o(b) { + ue(u.$$.fragment, b), ue(v), ue(w.$$.fragment, b), ue(S), ue(L), P = !1; + }, + d(b) { + b && Ke(e), ct(u), F[f].d(), ct(w), S && S.d(), L && L.d(), U = !1, _o(H); + } + }; +} +function Rl(i, e, t) { + let { waveform: n } = e, { audioDuration: o } = e, { i18n: r } = e, { playing: s } = e, { showRedo: l = !1 } = e, { interactive: a = !1 } = e, { handle_trim_audio: c } = e, { mode: u = "" } = e, { container: d } = e, { handle_reset_value: _ } = e, { waveform_settings: h = {} } = e, { trimDuration: f = 0 } = e, v = [0.5, 1, 1.5, 2], g = v[1], p, m = null, w, k, A = ""; + const W = () => { + t(18, m = p.addRegion({ + start: o / 4, + end: o / 2, + color: "hsla(15, 85%, 40%, 0.4)", + drag: !0, + resize: !0 + })), t(14, f = m.end - m.start); + }, M = () => { + if (n && p && m) { + const b = m.start, D = m.end; + c(b, D), t(0, u = ""), t(18, m = null); + } + }, P = () => { + p == null || p.getRegions().forEach((b) => { + b.remove(); + }), p == null || p.clearRegions(); + }, U = () => { + P(), u === "edit" ? t(0, u = "") : (t(0, u = "edit"), W()); + }, H = (b, D) => { + let E, T; + m && (b === "left" ? D === "ArrowLeft" ? (E = m.start - 0.05, T = m.end) : (E = m.start + 0.05, T = m.end) : D === "ArrowLeft" ? (E = m.start, T = m.end - 0.05) : (E = m.start, T = m.end + 0.05), m.setOptions({ start: E, end: T }), t(14, f = m.end - m.start)); + }, X = () => { + t(9, g = v[(v.indexOf(g) + 1) % v.length]), n.setPlaybackRate(g); + }, F = () => n.skip(ot(o, h.skip_length) * -1), y = () => n.playPause(), S = () => n.skip(ot(o, h.skip_length)), L = () => { + _(), P(), t(0, u = ""); + }; + return i.$$set = (b) => { + "waveform" in b && t(1, n = b.waveform), "audioDuration" in b && t(2, o = b.audioDuration), "i18n" in b && t(3, r = b.i18n), "playing" in b && t(4, s = b.playing), "showRedo" in b && t(5, l = b.showRedo), "interactive" in b && t(6, a = b.interactive), "handle_trim_audio" in b && t(15, c = b.handle_trim_audio), "mode" in b && t(0, u = b.mode), "container" in b && t(16, d = b.container), "handle_reset_value" in b && t(7, _ = b.handle_reset_value), "waveform_settings" in b && t(8, h = b.waveform_settings), "trimDuration" in b && t(14, f = b.trimDuration); + }, i.$$.update = () => { + if (i.$$.dirty & /*waveform*/ + 2 && t(17, p = n.registerPlugin(ml.create())), i.$$.dirty & /*trimRegion*/ + 131072 && (p == null || p.on("region-out", (b) => { + b.play(); + })), i.$$.dirty & /*trimRegion*/ + 131072 && (p == null || p.on("region-updated", (b) => { + t(14, f = b.end - b.start); + })), i.$$.dirty & /*trimRegion*/ + 131072 && (p == null || p.on("region-clicked", (b, D) => { + D.stopPropagation(), t(18, m = b), b.play(); + })), i.$$.dirty & /*activeRegion, container, leftRegionHandle, rightRegionHandle, trimRegion*/ + 2031616 && m) { + const b = d.children[0].shadowRoot; + t(20, k = b.querySelector('[data-resize="right"]')), t(19, w = b.querySelector('[data-resize="left"]')), w && k && (w.setAttribute("role", "button"), k.setAttribute("role", "button"), w == null || w.setAttribute("aria-label", "Drag to adjust start time"), k == null || k.setAttribute("aria-label", "Drag to adjust end time"), w == null || w.setAttribute("tabindex", "0"), k == null || k.setAttribute("tabindex", "0"), w.addEventListener("focus", () => { + p && t(21, A = "left"); + }), k.addEventListener("focus", () => { + p && t(21, A = "right"); + })); + } + i.$$.dirty & /*trimRegion, activeHandle*/ + 2228224 && p && window.addEventListener("keydown", (b) => { + b.key === "ArrowLeft" ? H(A, "ArrowLeft") : b.key === "ArrowRight" && H(A, "ArrowRight"); + }); + }, [ + u, + n, + o, + r, + s, + l, + a, + _, + h, + g, + v, + M, + P, + U, + f, + c, + d, + p, + m, + w, + k, + A, + X, + F, + y, + S, + L + ]; +} +class mo extends gl { + constructor(e) { + super(), bl(this, e, Rl, Dl, wl, { + waveform: 1, + audioDuration: 2, + i18n: 3, + playing: 4, + showRedo: 5, + interactive: 6, + handle_trim_audio: 15, + mode: 0, + container: 16, + handle_reset_value: 7, + waveform_settings: 8, + trimDuration: 14 + }); + } +} +const { + SvelteComponent: Ml, + attr: Ln, + binding_callbacks: _i, + detach: Pn, + element: Tn, + init: Ll, + insert: An, + listen: po, + noop: Ft, + safe_not_equal: Pl +} = window.__gradio__svelte__internal, { onMount: Tl } = window.__gradio__svelte__internal; +function Al(i) { + let e, t, n; + return { + c() { + e = Tn("button"), e.innerHTML = '
stop
', Ln(e, "class", "stop-button svelte-p78f4z"); + }, + m(o, r) { + An(o, e, r), i[7](e), t || (n = po( + e, + "click", + /*record_click*/ + i[3] + ), t = !0); + }, + p: Ft, + d(o) { + o && Pn(e), i[7](null), t = !1, n(); + } + }; +} +function Ol(i) { + let e, t, n; + return { + c() { + e = Tn("button"), e.innerHTML = '
microphone
', Ln(e, "class", "record-button svelte-p78f4z"); + }, + m(o, r) { + An(o, e, r), i[6](e), t || (n = po( + e, + "click", + /*record_click*/ + i[3] + ), t = !0); + }, + p: Ft, + d(o) { + o && Pn(e), i[6](null), t = !1, n(); + } + }; +} +function ql(i) { + let e; + function t(r, s) { + return ( + /*isRecording*/ + r[2] ? Al : Ol + ); + } + let n = t(i), o = n(i); + return { + c() { + e = Tn("div"), o.c(), Ln(e, "class", "wrapper svelte-p78f4z"); + }, + m(r, s) { + An(r, e, s), o.m(e, null); + }, + p(r, [s]) { + n === (n = t(r)) && o ? o.p(r, s) : (o.d(1), o = n(r), o && (o.c(), o.m(e, null))); + }, + i: Ft, + o: Ft, + d(r) { + r && Pn(e), o.d(); + } + }; +} +function Wl(i, e, t) { + let { record: n } = e, { dispatch: o } = e, r, s; + Tl(() => { + t(0, r = document.getElementById("record")), t(1, s = document.getElementById("stop")); + }); + function l() { + a ? (n.stopRecording(), o("stop_recording")) : (n.startRecording(), o("start_recording")), t(2, a = !a); + } + let a = !1; + function c(d) { + _i[d ? "unshift" : "push"](() => { + r = d, t(0, r); + }); + } + function u(d) { + _i[d ? "unshift" : "push"](() => { + s = d, t(1, s); + }); + } + return i.$$set = (d) => { + "record" in d && t(4, n = d.record), "dispatch" in d && t(5, o = d.dispatch); + }, [ + r, + s, + a, + l, + n, + o, + c, + u + ]; +} +class Nl extends Ml { + constructor(e) { + super(), Ll(this, e, Wl, ql, Pl, { record: 4, dispatch: 5 }); + } +} +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ +function fn(i, e, t, n) { + return new (t || (t = Promise))(function(o, r) { + function s(c) { + try { + a(n.next(c)); + } catch (u) { + r(u); + } + } + function l(c) { + try { + a(n.throw(c)); + } catch (u) { + r(u); + } + } + function a(c) { + var u; + c.done ? o(c.value) : (u = c.value, u instanceof t ? u : new t(function(d) { + d(u); + })).then(s, l); + } + a((n = n.apply(i, [])).next()); + }); +} +class go { + constructor() { + this.listeners = {}; + } + on(e, t, n) { + if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(t), n == null ? void 0 : n.once) { + const o = () => { + this.un(e, o), this.un(e, t); + }; + return this.on(e, o), o; + } + return () => this.un(e, t); + } + un(e, t) { + var n; + (n = this.listeners[e]) === null || n === void 0 || n.delete(t); + } + once(e, t) { + return this.on(e, t, { once: !0 }); + } + unAll() { + this.listeners = {}; + } + emit(e, ...t) { + this.listeners[e] && this.listeners[e].forEach((n) => n(...t)); + } +} +class zl extends go { + constructor(e) { + super(), this.subscriptions = [], this.options = e; + } + onInit() { + } + _init(e) { + this.wavesurfer = e, this.onInit(); + } + destroy() { + this.emit("destroy"), this.subscriptions.forEach((e) => e()); + } +} +class Bl extends go { + constructor() { + super(...arguments), this.unsubscribe = () => { + }; + } + start() { + this.unsubscribe = this.on("tick", () => { + requestAnimationFrame(() => { + this.emit("tick"); + }); + }), this.emit("tick"); + } + stop() { + this.unsubscribe(); + } + destroy() { + this.unsubscribe(); + } +} +const jl = ["audio/webm", "audio/wav", "audio/mpeg", "audio/mp4", "audio/mp3"]; +class Yt extends zl { + constructor(e) { + var t, n, o, r; + super(Object.assign(Object.assign({}, e), { audioBitsPerSecond: (t = e.audioBitsPerSecond) !== null && t !== void 0 ? t : 128e3, scrollingWaveform: (n = e.scrollingWaveform) !== null && n !== void 0 && n, scrollingWaveformWindow: (o = e.scrollingWaveformWindow) !== null && o !== void 0 ? o : 5, renderRecordedAudio: (r = e.renderRecordedAudio) === null || r === void 0 || r })), this.stream = null, this.mediaRecorder = null, this.dataWindow = null, this.isWaveformPaused = !1, this.lastStartTime = 0, this.lastDuration = 0, this.duration = 0, this.timer = new Bl(), this.subscriptions.push(this.timer.on("tick", () => { + const s = performance.now() - this.lastStartTime; + this.duration = this.isPaused() ? this.duration : this.lastDuration + s, this.emit("record-progress", this.duration); + })); + } + static create(e) { + return new Yt(e || {}); + } + renderMicStream(e) { + const t = new AudioContext(), n = t.createMediaStreamSource(e), o = t.createAnalyser(); + n.connect(o); + const r = o.frequencyBinCount, s = new Float32Array(r); + let l; + const a = Math.floor((this.options.scrollingWaveformWindow || 0) * t.sampleRate), c = () => { + var u; + if (this.isWaveformPaused) + return void (l = requestAnimationFrame(c)); + if (o.getFloatTimeDomainData(s), this.options.scrollingWaveform) { + const _ = Math.min(a, this.dataWindow ? this.dataWindow.length + r : r), h = new Float32Array(a); + if (this.dataWindow) { + const f = Math.max(0, a - this.dataWindow.length); + h.set(this.dataWindow.slice(-_ + r), f); + } + h.set(s, a - r), this.dataWindow = h; + } else + this.dataWindow = s; + const d = this.options.scrollingWaveformWindow; + this.wavesurfer && ((u = this.originalOptions) !== null && u !== void 0 || (this.originalOptions = { cursorWidth: this.wavesurfer.options.cursorWidth, interact: this.wavesurfer.options.interact }), this.wavesurfer.options.cursorWidth = 0, this.wavesurfer.options.interact = !1, this.wavesurfer.load("", [this.dataWindow], d)), l = requestAnimationFrame(c); + }; + return c(), { onDestroy: () => { + cancelAnimationFrame(l), n == null || n.disconnect(), t == null || t.close(); + }, onEnd: () => { + this.isWaveformPaused = !0, cancelAnimationFrame(l), this.stopMic(); + } }; + } + startMic(e) { + return fn(this, void 0, void 0, function* () { + let t; + try { + t = yield navigator.mediaDevices.getUserMedia({ audio: !(e != null && e.deviceId) || { deviceId: e.deviceId } }); + } catch (r) { + throw new Error("Error accessing the microphone: " + r.message); + } + const { onDestroy: n, onEnd: o } = this.renderMicStream(t); + return this.subscriptions.push(this.once("destroy", n)), this.subscriptions.push(this.once("record-end", o)), this.stream = t, t; + }); + } + stopMic() { + this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null, this.mediaRecorder = null); + } + startRecording(e) { + return fn(this, void 0, void 0, function* () { + const t = this.stream || (yield this.startMic(e)); + this.dataWindow = null; + const n = this.mediaRecorder || new MediaRecorder(t, { mimeType: this.options.mimeType || jl.find((s) => MediaRecorder.isTypeSupported(s)), audioBitsPerSecond: this.options.audioBitsPerSecond }); + this.mediaRecorder = n, this.stopRecording(); + const o = []; + n.ondataavailable = (s) => { + s.data.size > 0 && o.push(s.data); + }; + const r = (s) => { + var l; + const a = new Blob(o, { type: n.mimeType }); + this.emit(s, a), this.options.renderRecordedAudio && (this.applyOriginalOptionsIfNeeded(), (l = this.wavesurfer) === null || l === void 0 || l.load(URL.createObjectURL(a))); + }; + n.onpause = () => r("record-pause"), n.onstop = () => r("record-end"), n.start(), this.lastStartTime = performance.now(), this.lastDuration = 0, this.duration = 0, this.isWaveformPaused = !1, this.timer.start(), this.emit("record-start"); + }); + } + getDuration() { + return this.duration; + } + isRecording() { + var e; + return ((e = this.mediaRecorder) === null || e === void 0 ? void 0 : e.state) === "recording"; + } + isPaused() { + var e; + return ((e = this.mediaRecorder) === null || e === void 0 ? void 0 : e.state) === "paused"; + } + isActive() { + var e; + return ((e = this.mediaRecorder) === null || e === void 0 ? void 0 : e.state) !== "inactive"; + } + stopRecording() { + var e; + this.isActive() && ((e = this.mediaRecorder) === null || e === void 0 || e.stop(), this.timer.stop()); + } + pauseRecording() { + var e, t; + this.isRecording() && (this.isWaveformPaused = !0, (e = this.mediaRecorder) === null || e === void 0 || e.requestData(), (t = this.mediaRecorder) === null || t === void 0 || t.pause(), this.timer.stop(), this.lastDuration = this.duration); + } + resumeRecording() { + var e; + this.isPaused() && (this.isWaveformPaused = !1, (e = this.mediaRecorder) === null || e === void 0 || e.resume(), this.timer.start(), this.lastStartTime = performance.now(), this.emit("record-resume")); + } + static getAvailableAudioDevices() { + return fn(this, void 0, void 0, function* () { + return navigator.mediaDevices.enumerateDevices().then((e) => e.filter((t) => t.kind === "audioinput")); + }); + } + destroy() { + this.applyOriginalOptionsIfNeeded(), super.destroy(), this.stopRecording(), this.stopMic(); + } + applyOriginalOptionsIfNeeded() { + this.wavesurfer && this.originalOptions && (this.wavesurfer.options.cursorWidth = this.originalOptions.cursorWidth, this.wavesurfer.options.interact = this.originalOptions.interact, delete this.originalOptions); + } +} +const { + SvelteComponent: Il, + add_flush_callback: Ot, + append: hn, + attr: Et, + bind: qt, + binding_callbacks: Wt, + check_outros: mi, + create_component: vo, + destroy_component: bo, + detach: Fl, + element: pi, + group_outros: gi, + init: Ul, + insert: Hl, + mount_component: wo, + safe_not_equal: Vl, + space: vi, + transition_in: Be, + transition_out: st +} = window.__gradio__svelte__internal, { onMount: Gl } = window.__gradio__svelte__internal; +function bi(i) { + let e, t, n; + function o(s) { + i[18](s); + } + let r = { dispatch: ( + /*dispatch*/ + i[2] + ) }; + return ( + /*record*/ + i[6] !== void 0 && (r.record = /*record*/ + i[6]), e = new Nl({ props: r }), Wt.push(() => qt(e, "record", o)), { + c() { + vo(e.$$.fragment); + }, + m(s, l) { + wo(e, s, l), n = !0; + }, + p(s, l) { + const a = {}; + l & /*dispatch*/ + 4 && (a.dispatch = /*dispatch*/ + s[2]), !t && l & /*record*/ + 64 && (t = !0, a.record = /*record*/ + s[6], Ot(() => t = !1)), e.$set(a); + }, + i(s) { + n || (Be(e.$$.fragment, s), n = !0); + }, + o(s) { + st(e.$$.fragment, s), n = !1; + }, + d(s) { + bo(e, s); + } + } + ); +} +function wi(i) { + let e, t, n, o, r; + function s(u) { + i[19](u); + } + function l(u) { + i[20](u); + } + function a(u) { + i[21](u); + } + let c = { + container: ( + /*container*/ + i[12] + ), + playing: ( + /*playing*/ + i[9] + ), + audioDuration: ( + /*audioDuration*/ + i[10] + ), + i18n: ( + /*i18n*/ + i[1] + ), + interactive: !0, + handle_trim_audio: ( + /*handle_trim_audio*/ + i[13] + ), + showRedo: !0, + handle_reset_value: ( + /*handle_reset_value*/ + i[4] + ), + waveform_settings: ( + /*waveform_settings*/ + i[3] + ) + }; + return ( + /*recordingWaveform*/ + i[5] !== void 0 && (c.waveform = /*recordingWaveform*/ + i[5]), /*trimDuration*/ + i[11] !== void 0 && (c.trimDuration = /*trimDuration*/ + i[11]), /*mode*/ + i[0] !== void 0 && (c.mode = /*mode*/ + i[0]), e = new mo({ props: c }), Wt.push(() => qt(e, "waveform", s)), Wt.push(() => qt(e, "trimDuration", l)), Wt.push(() => qt(e, "mode", a)), { + c() { + vo(e.$$.fragment); + }, + m(u, d) { + wo(e, u, d), r = !0; + }, + p(u, d) { + const _ = {}; + d & /*playing*/ + 512 && (_.playing = /*playing*/ + u[9]), d & /*audioDuration*/ + 1024 && (_.audioDuration = /*audioDuration*/ + u[10]), d & /*i18n*/ + 2 && (_.i18n = /*i18n*/ + u[1]), d & /*handle_reset_value*/ + 16 && (_.handle_reset_value = /*handle_reset_value*/ + u[4]), d & /*waveform_settings*/ + 8 && (_.waveform_settings = /*waveform_settings*/ + u[3]), !t && d & /*recordingWaveform*/ + 32 && (t = !0, _.waveform = /*recordingWaveform*/ + u[5], Ot(() => t = !1)), !n && d & /*trimDuration*/ + 2048 && (n = !0, _.trimDuration = /*trimDuration*/ + u[11], Ot(() => n = !1)), !o && d & /*mode*/ + 1 && (o = !0, _.mode = /*mode*/ + u[0], Ot(() => o = !1)), e.$set(_); + }, + i(u) { + r || (Be(e.$$.fragment, u), r = !0); + }, + o(u) { + st(e.$$.fragment, u), r = !1; + }, + d(u) { + bo(e, u); + } + } + ); +} +function Xl(i) { + let e, t, n, o, r, s = ( + /*micWaveform*/ + i[8] && !/*recordedAudio*/ + i[7] && bi(i) + ), l = ( + /*recordingWaveform*/ + i[5] && /*recordedAudio*/ + i[7] && wi(i) + ); + return { + c() { + e = pi("div"), t = pi("div"), n = vi(), s && s.c(), o = vi(), l && l.c(), Et(t, "id", "microphone"), Et(t, "data-testid", "microphone-waveform"), Et(t, "class", "svelte-1smaui2"), Et(e, "class", "component-wrapper svelte-1smaui2"); + }, + m(a, c) { + Hl(a, e, c), hn(e, t), hn(e, n), s && s.m(e, null), hn(e, o), l && l.m(e, null), r = !0; + }, + p(a, [c]) { + /*micWaveform*/ + a[8] && !/*recordedAudio*/ + a[7] ? s ? (s.p(a, c), c & /*micWaveform, recordedAudio*/ + 384 && Be(s, 1)) : (s = bi(a), s.c(), Be(s, 1), s.m(e, o)) : s && (gi(), st(s, 1, 1, () => { + s = null; + }), mi()), /*recordingWaveform*/ + a[5] && /*recordedAudio*/ + a[7] ? l ? (l.p(a, c), c & /*recordingWaveform, recordedAudio*/ + 160 && Be(l, 1)) : (l = wi(a), l.c(), Be(l, 1), l.m(e, null)) : l && (gi(), st(l, 1, 1, () => { + l = null; + }), mi()); + }, + i(a) { + r || (Be(s), Be(l), r = !0); + }, + o(a) { + st(s), st(l), r = !1; + }, + d(a) { + a && Fl(e), s && s.d(), l && l.d(); + } + }; +} +function Zl(i, e, t) { + var n = this && this.__awaiter || function(y, S, L, b) { + function D(E) { + return E instanceof L ? E : new L(function(T) { + T(E); + }); + } + return new (L || (L = Promise))(function(E, T) { + function B(C) { + try { + q(b.next(C)); + } catch (J) { + T(J); + } + } + function Z(C) { + try { + q(b.throw(C)); + } catch (J) { + T(J); + } + } + function q(C) { + C.done ? E(C.value) : D(C.value).then(B, Z); + } + q((b = b.apply(y, S || [])).next()); + }); + }; + let { mode: o } = e, { i18n: r } = e, { dispatch: s } = e, { dispatch_blob: l } = e, { waveform_settings: a = {} } = e, { handle_reset_value: c } = e, u, d, _ = !1, h, f, v = null, g, p, m, w, k = 0; + const A = () => { + clearInterval(w), t(17, w = setInterval( + () => { + }, + 1e3 + )); + }, W = () => { + const y = document.getElementById("microphone"); + y && (y.innerHTML = ""), u !== void 0 && u.destroy(), y && (t(8, u = Ve.create(Object.assign(Object.assign({}, a), { container: y }))), t(6, f = u.registerPlugin(Yt.create())), f.startMic()); + }, M = () => { + let y = document.getElementById("recording"); + !v || !y || t(5, d = Ve.create(Object.assign({ container: y, url: v }, a))); + }, P = (y, S) => n(void 0, void 0, void 0, function* () { + t(0, o = "edit"); + const L = d.getDecodedData(); + L && (yield bn(L, y, S).then((b) => n(void 0, void 0, void 0, function* () { + yield l([b], "change"), d.destroy(), M(); + }))), s("edit"); + }); + Gl(() => { + W(), window.addEventListener("keydown", (y) => { + y.key === "ArrowRight" ? It(d, 0.1) : y.key === "ArrowLeft" && It(d, -0.1); + }); + }); + function U(y) { + f = y, t(6, f); + } + function H(y) { + d = y, t(5, d); + } + function X(y) { + k = y, t(11, k); + } + function F(y) { + o = y, t(0, o); + } + return i.$$set = (y) => { + "mode" in y && t(0, o = y.mode), "i18n" in y && t(1, r = y.i18n), "dispatch" in y && t(2, s = y.dispatch), "dispatch_blob" in y && t(14, l = y.dispatch_blob), "waveform_settings" in y && t(3, a = y.waveform_settings), "handle_reset_value" in y && t(4, c = y.handle_reset_value); + }, i.$$.update = () => { + i.$$.dirty & /*record, dispatch*/ + 68 && (f == null || f.on("record-start", () => { + A(), s("start_recording"); + })), i.$$.dirty & /*record, interval, dispatch_blob*/ + 147520 && (f == null || f.on("record-end", (y) => n(void 0, void 0, void 0, function* () { + clearInterval(w); + const S = yield y.arrayBuffer(), b = yield new AudioContext().decodeAudioData(S); + b && (yield bn(b).then((D) => n(void 0, void 0, void 0, function* () { + yield l([D], "change"), yield l([D], "stop_recording"); + }))); + }))), i.$$.dirty & /*record, dispatch, interval*/ + 131140 && (f == null || f.on("record-pause", () => { + s("pause_recording"), clearInterval(w); + })), i.$$.dirty & /*record*/ + 64 && (f == null || f.on("record-resume", () => { + A(); + })), i.$$.dirty & /*recordingWaveform, durationRef*/ + 65568 && (d == null || d.on("decode", (y) => { + t(10, m = y); + })), i.$$.dirty & /*recordingWaveform, timeRef*/ + 32800 && (d == null || d.on("timeupdate", (y) => g)), i.$$.dirty & /*recordingWaveform, dispatch*/ + 36 && (d == null || d.on("pause", () => { + s("pause"), t(9, _ = !1); + })), i.$$.dirty & /*recordingWaveform, dispatch*/ + 36 && (d == null || d.on("play", () => { + s("play"), t(9, _ = !0); + })), i.$$.dirty & /*recordingWaveform, dispatch*/ + 36 && (d == null || d.on("finish", () => { + s("stop"), s("end"), t(9, _ = !1); + })), i.$$.dirty & /*record, recordedAudio*/ + 192 && (f == null || f.on("record-end", (y) => { + t(7, v = URL.createObjectURL(y)); + const S = document.getElementById("microphone"), L = document.getElementById("recording"); + S && (S.style.display = "none"), L && v && (L.innerHTML = "", M()); + })); + }, [ + o, + r, + s, + a, + c, + d, + f, + v, + u, + _, + m, + k, + h, + P, + l, + g, + p, + w, + U, + H, + X, + F + ]; +} +class Jl extends Il { + constructor(e) { + super(), Ul(this, e, Zl, Xl, Vl, { + mode: 0, + i18n: 1, + dispatch: 2, + dispatch_blob: 14, + waveform_settings: 3, + handle_reset_value: 4 + }); + } +} +const { + SvelteComponent: Yl, + append: yi, + attr: Ut, + detach: On, + element: Ht, + init: Kl, + insert: qn, + listen: yo, + noop: Vt, + safe_not_equal: Ql, + set_style: ki, + space: xl +} = window.__gradio__svelte__internal, { onMount: $l } = window.__gradio__svelte__internal; +function ea(i) { + let e, t, n; + return { + c() { + e = Ht("button"), e.innerHTML = '
microphone
', Ut(e, "class", "record-button svelte-p78f4z"); + }, + m(o, r) { + qn(o, e, r), t || (n = yo( + e, + "click", + /*click_handler_1*/ + i[7] + ), t = !0); + }, + p: Vt, + d(o) { + o && On(e), t = !1, n(); + } + }; +} +function ta(i) { + let e, t, n; + return { + c() { + e = Ht("button"), e.innerHTML = '
stop
', Ut(e, "class", "stop-button pulsate svelte-p78f4z"); + }, + m(o, r) { + qn(o, e, r), t || (n = yo( + e, + "click", + /*click_handler*/ + i[6] + ), t = !0); + }, + p: Vt, + d(o) { + o && On(e), t = !1, n(); + } + }; +} +function na(i) { + let e, t, n; + function o(l, a) { + return ( + /*recording*/ + l[0] ? ta : ea + ); + } + let r = o(i), s = r(i); + return { + c() { + e = Ht("div"), t = Ht("div"), n = xl(), s.c(), Ut(t, "id", "microphone"), ki( + t, + "display", + /*recording*/ + i[0] ? "block" : "none" + ), Ut(e, "class", "wrapper svelte-p78f4z"); + }, + m(l, a) { + qn(l, e, a), yi(e, t), yi(e, n), s.m(e, null); + }, + p(l, [a]) { + a & /*recording*/ + 1 && ki( + t, + "display", + /*recording*/ + l[0] ? "block" : "none" + ), r === (r = o(l)) && s ? s.p(l, a) : (s.d(1), s = r(l), s && (s.c(), s.m(e, null))); + }, + i: Vt, + o: Vt, + d(l) { + l && On(e), s.d(); + } + }; +} +function ia(i, e, t) { + let { recording: n = !1 } = e, { paused_recording: o = !1 } = e, { stop: r } = e, { record: s } = e, { waveform_settings: l = {} } = e, a, c; + $l(() => { + u(); + }); + const u = () => { + a !== void 0 && a.destroy(), a = Ve.create(Object.assign(Object.assign({}, l), { height: 100, container: "#microphone" })), t(3, c = a.registerPlugin(Yt.create())); + }, d = () => { + c.stopMic(), r(); + }, _ = () => { + c.startMic(), s(); + }; + return i.$$set = (h) => { + "recording" in h && t(0, n = h.recording), "paused_recording" in h && t(4, o = h.paused_recording), "stop" in h && t(1, r = h.stop), "record" in h && t(2, s = h.record), "waveform_settings" in h && t(5, l = h.waveform_settings); + }, [ + n, + r, + s, + c, + o, + l, + d, + _ + ]; +} +class oa extends Yl { + constructor(e) { + super(), Kl(this, e, ia, na, Ql, { + recording: 0, + paused_recording: 4, + stop: 1, + record: 2, + waveform_settings: 5 + }); + } +} +const { + SvelteComponent: sa, + add_flush_callback: ra, + bind: la, + binding_callbacks: aa, + check_outros: ca, + create_component: ko, + destroy_component: Co, + detach: ua, + empty: da, + group_outros: fa, + init: ha, + insert: _a, + mount_component: So, + safe_not_equal: ma, + transition_in: Gt, + transition_out: Xt +} = window.__gradio__svelte__internal, { onDestroy: pa, createEventDispatcher: ga } = window.__gradio__svelte__internal; +function va(i) { + let e, t, n; + function o(s) { + i[22](s); + } + let r = { + i18n: ( + /*i18n*/ + i[1] + ), + dispatch: ( + /*dispatch*/ + i[6] + ), + dispatch_blob: ( + /*dispatch_blob*/ + i[7] + ), + waveform_settings: ( + /*waveform_settings*/ + i[2] + ), + handle_reset_value: ( + /*handle_reset_value*/ + i[3] + ) + }; + return ( + /*mode*/ + i[5] !== void 0 && (r.mode = /*mode*/ + i[5]), e = new Jl({ props: r }), aa.push(() => la(e, "mode", o)), { + c() { + ko(e.$$.fragment); + }, + m(s, l) { + So(e, s, l), n = !0; + }, + p(s, l) { + const a = {}; + l[0] & /*i18n*/ + 2 && (a.i18n = /*i18n*/ + s[1]), l[0] & /*waveform_settings*/ + 4 && (a.waveform_settings = /*waveform_settings*/ + s[2]), l[0] & /*handle_reset_value*/ + 8 && (a.handle_reset_value = /*handle_reset_value*/ + s[3]), !t && l[0] & /*mode*/ + 32 && (t = !0, a.mode = /*mode*/ + s[5], ra(() => t = !1)), e.$set(a); + }, + i(s) { + n || (Gt(e.$$.fragment, s), n = !0); + }, + o(s) { + Xt(e.$$.fragment, s), n = !1; + }, + d(s) { + Co(e, s); + } + } + ); +} +function ba(i) { + let e, t; + return e = new oa({ + props: { + record: ( + /*record*/ + i[8] + ), + recording: ( + /*recording*/ + i[4] + ), + stop: ( + /*stop*/ + i[9] + ), + waveform_settings: ( + /*waveform_settings*/ + i[2] + ) + } + }), { + c() { + ko(e.$$.fragment); + }, + m(n, o) { + So(e, n, o), t = !0; + }, + p(n, o) { + const r = {}; + o[0] & /*recording*/ + 16 && (r.recording = /*recording*/ + n[4]), o[0] & /*waveform_settings*/ + 4 && (r.waveform_settings = /*waveform_settings*/ + n[2]), e.$set(r); + }, + i(n) { + t || (Gt(e.$$.fragment, n), t = !0); + }, + o(n) { + Xt(e.$$.fragment, n), t = !1; + }, + d(n) { + Co(e, n); + } + }; +} +function wa(i) { + let e, t, n, o; + const r = [ba, va], s = []; + function l(a, c) { + return ( + /*streaming*/ + a[0] ? 0 : 1 + ); + } + return e = l(i), t = s[e] = r[e](i), { + c() { + t.c(), n = da(); + }, + m(a, c) { + s[e].m(a, c), _a(a, n, c), o = !0; + }, + p(a, c) { + let u = e; + e = l(a), e === u ? s[e].p(a, c) : (fa(), Xt(s[u], 1, 1, () => { + s[u] = null; + }), ca(), t = s[e], t ? t.p(a, c) : (t = s[e] = r[e](a), t.c()), Gt(t, 1), t.m(n.parentNode, n)); + }, + i(a) { + o || (Gt(t), o = !0); + }, + o(a) { + Xt(t), o = !1; + }, + d(a) { + a && ua(n), s[e].d(a); + } + }; +} +const ya = 500, Ci = 44; +function ka(i, e, t) { + var n = this && this.__awaiter || function(E, T, B, Z) { + function q(C) { + return C instanceof B ? C : new B(function(J) { + J(C); + }); + } + return new (B || (B = Promise))(function(C, J) { + function ne(j) { + try { + re(Z.next(j)); + } catch (ae) { + J(ae); + } + } + function le(j) { + try { + re(Z.throw(j)); + } catch (ae) { + J(ae); + } + } + function re(j) { + j.done ? C(j.value) : q(j.value).then(ne, le); + } + re((Z = Z.apply(E, T || [])).next()); + }); + }; + let { value: o = null } = e, { label: r } = e, { root: s } = e, { show_label: l = !0 } = e, { sources: a = ["microphone", "upload"] } = e, { pending: c = !1 } = e, { streaming: u = !1 } = e, { i18n: d } = e, { waveform_settings: _ = {} } = e, { dragging: h } = e, { active_source: f } = e, { waveform_options: v = {} } = e, { handle_reset_value: g = () => { + } } = e, p = !1, m, w = "", k, A = [], W = !1, M = !1, P = [], U; + function H() { + U = [ + import("./module-ORH6OG8U.js"), + import("./module-kgNHl8Dh.js") + ]; + } + u && H(); + const X = ga(), F = (E, T) => n(void 0, void 0, void 0, function* () { + var B; + let Z = new File(E, "audio.wav"); + const q = yield Br([Z], T === "stream"); + t(10, o = ((B = yield zr(q, s)) === null || B === void 0 ? void 0 : B.filter(Boolean))[0]), X(T, o); + }); + pa(() => { + u && m && m.state !== "inactive" && m.stop(); + }); + function y() { + return n(this, void 0, void 0, function* () { + let E; + try { + E = yield navigator.mediaDevices.getUserMedia({ audio: !0 }); + } catch (T) { + if (!navigator.mediaDevices) { + X("error", d("audio.no_device_support")); + return; + } + if (T instanceof DOMException && T.name == "NotAllowedError") { + X("error", d("audio.allow_recording_access")); + return; + } + throw T; + } + if (E != null) { + if (u) { + const [{ MediaRecorder: T, register: B }, { connect: Z }] = yield Promise.all(U); + try { + yield B(yield Z()); + } catch { + } + m = new T(E, { mimeType: "audio/wav" }), m.addEventListener("dataavailable", S); + } else + m = new MediaRecorder(E), m.addEventListener("dataavailable", (T) => { + P.push(T.data); + }), m.addEventListener("stop", () => n(this, void 0, void 0, function* () { + t(4, p = !1), yield F(P, "change"), yield F(P, "stop_recording"), P = []; + })); + M = !0; + } + }); + } + function S(E) { + return n(this, void 0, void 0, function* () { + let T = yield E.data.arrayBuffer(), B = new Uint8Array(T); + if (k || (t(19, k = new Uint8Array(T.slice(0, Ci))), B = new Uint8Array(T.slice(Ci))), c) + A.push(B); + else { + let Z = [k].concat(A, [B]); + F(Z, "stream"), t(20, A = []); + } + }); + } + function L() { + return n(this, void 0, void 0, function* () { + t(4, p = !0), X("start_recording"), M || (yield y()), t(19, k = void 0), u && m.start(ya); + }); + } + function b() { + t(4, p = !1), u && (X("stop_recording"), m.stop(), c && t(21, W = !0), F(P, "stop_recording"), X("clear"), t(5, w = "")); + } + function D(E) { + w = E, t(5, w); + } + return i.$$set = (E) => { + "value" in E && t(10, o = E.value), "label" in E && t(11, r = E.label), "root" in E && t(12, s = E.root), "show_label" in E && t(13, l = E.show_label), "sources" in E && t(14, a = E.sources), "pending" in E && t(15, c = E.pending), "streaming" in E && t(0, u = E.streaming), "i18n" in E && t(1, d = E.i18n), "waveform_settings" in E && t(2, _ = E.waveform_settings), "dragging" in E && t(16, h = E.dragging), "active_source" in E && t(17, f = E.active_source), "waveform_options" in E && t(18, v = E.waveform_options), "handle_reset_value" in E && t(3, g = E.handle_reset_value); + }, i.$$.update = () => { + if (i.$$.dirty[0] & /*dragging*/ + 65536 && X("drag", h), i.$$.dirty[0] & /*submit_pending_stream_on_pending_end, pending, header, pending_stream*/ + 3702784 && W && c === !1 && (t(21, W = !1), k && A)) { + let E = [k].concat(A); + t(20, A = []), F(E, "stream"); + } + }, [ + u, + d, + _, + g, + p, + w, + X, + F, + L, + b, + o, + r, + s, + l, + a, + c, + h, + f, + v, + k, + A, + W, + D + ]; +} +class Ca extends sa { + constructor(e) { + super(), ha( + this, + e, + ka, + wa, + ma, + { + value: 10, + label: 11, + root: 12, + show_label: 13, + sources: 14, + pending: 15, + streaming: 0, + i18n: 1, + waveform_settings: 2, + dragging: 16, + active_source: 17, + waveform_options: 18, + handle_reset_value: 3 + }, + null, + [-1, -1] + ); + } +} +function rt(i) { + let e = ["", "k", "M", "G", "T", "P", "E", "Z"], t = 0; + for (; i > 1e3 && t < e.length - 1; ) + i /= 1e3, t++; + let n = e[t]; + return (Number.isInteger(i) ? i : i.toFixed(1)) + n; +} +function Nt() { +} +function Sa(i, e) { + return i != i ? e == e : i !== e || i && typeof i == "object" || typeof i == "function"; +} +const Eo = typeof window < "u"; +let Si = Eo ? () => window.performance.now() : () => Date.now(), Do = Eo ? (i) => requestAnimationFrame(i) : Nt; +const lt = /* @__PURE__ */ new Set(); +function Ro(i) { + lt.forEach((e) => { + e.c(i) || (lt.delete(e), e.f()); + }), lt.size !== 0 && Do(Ro); +} +function Ea(i) { + let e; + return lt.size === 0 && Do(Ro), { + promise: new Promise((t) => { + lt.add(e = { c: i, f: t }); + }), + abort() { + lt.delete(e); + } + }; +} +const tt = []; +function Da(i, e = Nt) { + let t; + const n = /* @__PURE__ */ new Set(); + function o(l) { + if (Sa(i, l) && (i = l, t)) { + const a = !tt.length; + for (const c of n) + c[1](), tt.push(c, i); + if (a) { + for (let c = 0; c < tt.length; c += 2) + tt[c][0](tt[c + 1]); + tt.length = 0; + } + } + } + function r(l) { + o(l(i)); + } + function s(l, a = Nt) { + const c = [l, a]; + return n.add(c), n.size === 1 && (t = e(o, r) || Nt), l(i), () => { + n.delete(c), n.size === 0 && t && (t(), t = null); + }; + } + return { set: o, update: r, subscribe: s }; +} +function Ei(i) { + return Object.prototype.toString.call(i) === "[object Date]"; +} +function wn(i, e, t, n) { + if (typeof t == "number" || Ei(t)) { + const o = n - t, r = (t - e) / (i.dt || 1 / 60), s = i.opts.stiffness * o, l = i.opts.damping * r, a = (s - l) * i.inv_mass, c = (r + a) * i.dt; + return Math.abs(c) < i.opts.precision && Math.abs(o) < i.opts.precision ? n : (i.settled = !1, Ei(t) ? new Date(t.getTime() + c) : t + c); + } else { + if (Array.isArray(t)) + return t.map( + (o, r) => wn(i, e[r], t[r], n[r]) + ); + if (typeof t == "object") { + const o = {}; + for (const r in t) + o[r] = wn(i, e[r], t[r], n[r]); + return o; + } else + throw new Error(`Cannot spring ${typeof t} values`); + } +} +function Di(i, e = {}) { + const t = Da(i), { stiffness: n = 0.15, damping: o = 0.8, precision: r = 0.01 } = e; + let s, l, a, c = i, u = i, d = 1, _ = 0, h = !1; + function f(g, p = {}) { + u = g; + const m = a = {}; + return i == null || p.hard || v.stiffness >= 1 && v.damping >= 1 ? (h = !0, s = Si(), c = g, t.set(i = u), Promise.resolve()) : (p.soft && (_ = 1 / ((p.soft === !0 ? 0.5 : +p.soft) * 60), d = 0), l || (s = Si(), h = !1, l = Ea((w) => { + if (h) + return h = !1, l = null, !1; + d = Math.min(d + _, 1); + const k = { + inv_mass: d, + opts: v, + settled: !0, + dt: (w - s) * 60 / 1e3 + }, A = wn(k, c, i, u); + return s = w, c = i, t.set(i = A), k.settled && (l = null), !k.settled; + })), new Promise((w) => { + l.promise.then(() => { + m === a && w(); + }); + })); + } + const v = { + set: f, + update: (g, p) => f(g(u, i), p), + subscribe: t.subscribe, + stiffness: n, + damping: o, + precision: r + }; + return v; +} +const { + SvelteComponent: Ra, + append: ke, + attr: I, + component_subscribe: Ri, + detach: Ma, + element: La, + init: Pa, + insert: Ta, + noop: Mi, + safe_not_equal: Aa, + set_style: Dt, + svg_element: Ce, + toggle_class: Li +} = window.__gradio__svelte__internal, { onMount: Oa } = window.__gradio__svelte__internal; +function qa(i) { + let e, t, n, o, r, s, l, a, c, u, d, _; + return { + c() { + e = La("div"), t = Ce("svg"), n = Ce("g"), o = Ce("path"), r = Ce("path"), s = Ce("path"), l = Ce("path"), a = Ce("g"), c = Ce("path"), u = Ce("path"), d = Ce("path"), _ = Ce("path"), I(o, "d", "M255.926 0.754768L509.702 139.936V221.027L255.926 81.8465V0.754768Z"), I(o, "fill", "#FF7C00"), I(o, "fill-opacity", "0.4"), I(o, "class", "svelte-43sxxs"), I(r, "d", "M509.69 139.936L254.981 279.641V361.255L509.69 221.55V139.936Z"), I(r, "fill", "#FF7C00"), I(r, "class", "svelte-43sxxs"), I(s, "d", "M0.250138 139.937L254.981 279.641V361.255L0.250138 221.55V139.937Z"), I(s, "fill", "#FF7C00"), I(s, "fill-opacity", "0.4"), I(s, "class", "svelte-43sxxs"), I(l, "d", "M255.923 0.232622L0.236328 139.936V221.55L255.923 81.8469V0.232622Z"), I(l, "fill", "#FF7C00"), I(l, "class", "svelte-43sxxs"), Dt(n, "transform", "translate(" + /*$top*/ + i[1][0] + "px, " + /*$top*/ + i[1][1] + "px)"), I(c, "d", "M255.926 141.5L509.702 280.681V361.773L255.926 222.592V141.5Z"), I(c, "fill", "#FF7C00"), I(c, "fill-opacity", "0.4"), I(c, "class", "svelte-43sxxs"), I(u, "d", "M509.69 280.679L254.981 420.384V501.998L509.69 362.293V280.679Z"), I(u, "fill", "#FF7C00"), I(u, "class", "svelte-43sxxs"), I(d, "d", "M0.250138 280.681L254.981 420.386V502L0.250138 362.295V280.681Z"), I(d, "fill", "#FF7C00"), I(d, "fill-opacity", "0.4"), I(d, "class", "svelte-43sxxs"), I(_, "d", "M255.923 140.977L0.236328 280.68V362.294L255.923 222.591V140.977Z"), I(_, "fill", "#FF7C00"), I(_, "class", "svelte-43sxxs"), Dt(a, "transform", "translate(" + /*$bottom*/ + i[2][0] + "px, " + /*$bottom*/ + i[2][1] + "px)"), I(t, "viewBox", "-1200 -1200 3000 3000"), I(t, "fill", "none"), I(t, "xmlns", "http://www.w3.org/2000/svg"), I(t, "class", "svelte-43sxxs"), I(e, "class", "svelte-43sxxs"), Li( + e, + "margin", + /*margin*/ + i[0] + ); + }, + m(h, f) { + Ta(h, e, f), ke(e, t), ke(t, n), ke(n, o), ke(n, r), ke(n, s), ke(n, l), ke(t, a), ke(a, c), ke(a, u), ke(a, d), ke(a, _); + }, + p(h, [f]) { + f & /*$top*/ + 2 && Dt(n, "transform", "translate(" + /*$top*/ + h[1][0] + "px, " + /*$top*/ + h[1][1] + "px)"), f & /*$bottom*/ + 4 && Dt(a, "transform", "translate(" + /*$bottom*/ + h[2][0] + "px, " + /*$bottom*/ + h[2][1] + "px)"), f & /*margin*/ + 1 && Li( + e, + "margin", + /*margin*/ + h[0] + ); + }, + i: Mi, + o: Mi, + d(h) { + h && Ma(e); + } + }; +} +function Wa(i, e, t) { + let n, o; + var r = this && this.__awaiter || function(h, f, v, g) { + function p(m) { + return m instanceof v ? m : new v(function(w) { + w(m); + }); + } + return new (v || (v = Promise))(function(m, w) { + function k(M) { + try { + W(g.next(M)); + } catch (P) { + w(P); + } + } + function A(M) { + try { + W(g.throw(M)); + } catch (P) { + w(P); + } + } + function W(M) { + M.done ? m(M.value) : p(M.value).then(k, A); + } + W((g = g.apply(h, f || [])).next()); + }); + }; + let { margin: s = !0 } = e; + const l = Di([0, 0]); + Ri(i, l, (h) => t(1, n = h)); + const a = Di([0, 0]); + Ri(i, a, (h) => t(2, o = h)); + let c; + function u() { + return r(this, void 0, void 0, function* () { + yield Promise.all([l.set([125, 140]), a.set([-125, -140])]), yield Promise.all([l.set([-125, 140]), a.set([125, -140])]), yield Promise.all([l.set([-125, 0]), a.set([125, -0])]), yield Promise.all([l.set([125, 0]), a.set([-125, 0])]); + }); + } + function d() { + return r(this, void 0, void 0, function* () { + yield u(), c || d(); + }); + } + function _() { + return r(this, void 0, void 0, function* () { + yield Promise.all([l.set([125, 0]), a.set([-125, 0])]), d(); + }); + } + return Oa(() => (_(), () => c = !0)), i.$$set = (h) => { + "margin" in h && t(0, s = h.margin); + }, [s, n, o, l, a]; +} +class Na extends Ra { + constructor(e) { + super(), Pa(this, e, Wa, qa, Aa, { margin: 0 }); + } +} +const { + SvelteComponent: za, + append: Je, + attr: Re, + binding_callbacks: Pi, + check_outros: Mo, + create_component: Ba, + create_slot: ja, + destroy_component: Ia, + destroy_each: Lo, + detach: N, + element: Te, + empty: ht, + ensure_array_like: Zt, + get_all_dirty_from_scope: Fa, + get_slot_changes: Ua, + group_outros: Po, + init: Ha, + insert: z, + mount_component: Va, + noop: yn, + safe_not_equal: Ga, + set_data: we, + set_style: Ie, + space: Me, + text: Q, + toggle_class: be, + transition_in: dt, + transition_out: ft, + update_slot_base: Xa +} = window.__gradio__svelte__internal, { tick: Za } = window.__gradio__svelte__internal, { onDestroy: Ja } = window.__gradio__svelte__internal, Ya = (i) => ({}), Ti = (i) => ({}); +function Ai(i, e, t) { + const n = i.slice(); + return n[39] = e[t], n[41] = t, n; +} +function Oi(i, e, t) { + const n = i.slice(); + return n[39] = e[t], n; +} +function Ka(i) { + let e, t = ( + /*i18n*/ + i[1]("common.error") + "" + ), n, o, r; + const s = ( + /*#slots*/ + i[29].error + ), l = ja( + s, + i, + /*$$scope*/ + i[28], + Ti + ); + return { + c() { + e = Te("span"), n = Q(t), o = Me(), l && l.c(), Re(e, "class", "error svelte-14miwb5"); + }, + m(a, c) { + z(a, e, c), Je(e, n), z(a, o, c), l && l.m(a, c), r = !0; + }, + p(a, c) { + (!r || c[0] & /*i18n*/ + 2) && t !== (t = /*i18n*/ + a[1]("common.error") + "") && we(n, t), l && l.p && (!r || c[0] & /*$$scope*/ + 268435456) && Xa( + l, + s, + a, + /*$$scope*/ + a[28], + r ? Ua( + s, + /*$$scope*/ + a[28], + c, + Ya + ) : Fa( + /*$$scope*/ + a[28] + ), + Ti + ); + }, + i(a) { + r || (dt(l, a), r = !0); + }, + o(a) { + ft(l, a), r = !1; + }, + d(a) { + a && (N(e), N(o)), l && l.d(a); + } + }; +} +function Qa(i) { + let e, t, n, o, r, s, l, a, c, u = ( + /*variant*/ + i[8] === "default" && /*show_eta_bar*/ + i[18] && /*show_progress*/ + i[6] === "full" && qi(i) + ); + function d(w, k) { + if ( + /*progress*/ + w[7] + ) + return ec; + if ( + /*queue_position*/ + w[2] !== null && /*queue_size*/ + w[3] !== void 0 && /*queue_position*/ + w[2] >= 0 + ) + return $a; + if ( + /*queue_position*/ + w[2] === 0 + ) + return xa; + } + let _ = d(i), h = _ && _(i), f = ( + /*timer*/ + i[5] && zi(i) + ); + const v = [oc, ic], g = []; + function p(w, k) { + return ( + /*last_progress_level*/ + w[15] != null ? 0 : ( + /*show_progress*/ + w[6] === "full" ? 1 : -1 + ) + ); + } + ~(r = p(i)) && (s = g[r] = v[r](i)); + let m = !/*timer*/ + i[5] && Vi(i); + return { + c() { + u && u.c(), e = Me(), t = Te("div"), h && h.c(), n = Me(), f && f.c(), o = Me(), s && s.c(), l = Me(), m && m.c(), a = ht(), Re(t, "class", "progress-text svelte-14miwb5"), be( + t, + "meta-text-center", + /*variant*/ + i[8] === "center" + ), be( + t, + "meta-text", + /*variant*/ + i[8] === "default" + ); + }, + m(w, k) { + u && u.m(w, k), z(w, e, k), z(w, t, k), h && h.m(t, null), Je(t, n), f && f.m(t, null), z(w, o, k), ~r && g[r].m(w, k), z(w, l, k), m && m.m(w, k), z(w, a, k), c = !0; + }, + p(w, k) { + /*variant*/ + w[8] === "default" && /*show_eta_bar*/ + w[18] && /*show_progress*/ + w[6] === "full" ? u ? u.p(w, k) : (u = qi(w), u.c(), u.m(e.parentNode, e)) : u && (u.d(1), u = null), _ === (_ = d(w)) && h ? h.p(w, k) : (h && h.d(1), h = _ && _(w), h && (h.c(), h.m(t, n))), /*timer*/ + w[5] ? f ? f.p(w, k) : (f = zi(w), f.c(), f.m(t, null)) : f && (f.d(1), f = null), (!c || k[0] & /*variant*/ + 256) && be( + t, + "meta-text-center", + /*variant*/ + w[8] === "center" + ), (!c || k[0] & /*variant*/ + 256) && be( + t, + "meta-text", + /*variant*/ + w[8] === "default" + ); + let A = r; + r = p(w), r === A ? ~r && g[r].p(w, k) : (s && (Po(), ft(g[A], 1, 1, () => { + g[A] = null; + }), Mo()), ~r ? (s = g[r], s ? s.p(w, k) : (s = g[r] = v[r](w), s.c()), dt(s, 1), s.m(l.parentNode, l)) : s = null), /*timer*/ + w[5] ? m && (m.d(1), m = null) : m ? m.p(w, k) : (m = Vi(w), m.c(), m.m(a.parentNode, a)); + }, + i(w) { + c || (dt(s), c = !0); + }, + o(w) { + ft(s), c = !1; + }, + d(w) { + w && (N(e), N(t), N(o), N(l), N(a)), u && u.d(w), h && h.d(), f && f.d(), ~r && g[r].d(w), m && m.d(w); + } + }; +} +function qi(i) { + let e, t = `translateX(${/*eta_level*/ + (i[17] || 0) * 100 - 100}%)`; + return { + c() { + e = Te("div"), Re(e, "class", "eta-bar svelte-14miwb5"), Ie(e, "transform", t); + }, + m(n, o) { + z(n, e, o); + }, + p(n, o) { + o[0] & /*eta_level*/ + 131072 && t !== (t = `translateX(${/*eta_level*/ + (n[17] || 0) * 100 - 100}%)`) && Ie(e, "transform", t); + }, + d(n) { + n && N(e); + } + }; +} +function xa(i) { + let e; + return { + c() { + e = Q("processing |"); + }, + m(t, n) { + z(t, e, n); + }, + p: yn, + d(t) { + t && N(e); + } + }; +} +function $a(i) { + let e, t = ( + /*queue_position*/ + i[2] + 1 + "" + ), n, o, r, s; + return { + c() { + e = Q("queue: "), n = Q(t), o = Q("/"), r = Q( + /*queue_size*/ + i[3] + ), s = Q(" |"); + }, + m(l, a) { + z(l, e, a), z(l, n, a), z(l, o, a), z(l, r, a), z(l, s, a); + }, + p(l, a) { + a[0] & /*queue_position*/ + 4 && t !== (t = /*queue_position*/ + l[2] + 1 + "") && we(n, t), a[0] & /*queue_size*/ + 8 && we( + r, + /*queue_size*/ + l[3] + ); + }, + d(l) { + l && (N(e), N(n), N(o), N(r), N(s)); + } + }; +} +function ec(i) { + let e, t = Zt( + /*progress*/ + i[7] + ), n = []; + for (let o = 0; o < t.length; o += 1) + n[o] = Ni(Oi(i, t, o)); + return { + c() { + for (let o = 0; o < n.length; o += 1) + n[o].c(); + e = ht(); + }, + m(o, r) { + for (let s = 0; s < n.length; s += 1) + n[s] && n[s].m(o, r); + z(o, e, r); + }, + p(o, r) { + if (r[0] & /*progress*/ + 128) { + t = Zt( + /*progress*/ + o[7] + ); + let s; + for (s = 0; s < t.length; s += 1) { + const l = Oi(o, t, s); + n[s] ? n[s].p(l, r) : (n[s] = Ni(l), n[s].c(), n[s].m(e.parentNode, e)); + } + for (; s < n.length; s += 1) + n[s].d(1); + n.length = t.length; + } + }, + d(o) { + o && N(e), Lo(n, o); + } + }; +} +function Wi(i) { + let e, t = ( + /*p*/ + i[39].unit + "" + ), n, o, r = " ", s; + function l(u, d) { + return ( + /*p*/ + u[39].length != null ? nc : tc + ); + } + let a = l(i), c = a(i); + return { + c() { + c.c(), e = Me(), n = Q(t), o = Q(" | "), s = Q(r); + }, + m(u, d) { + c.m(u, d), z(u, e, d), z(u, n, d), z(u, o, d), z(u, s, d); + }, + p(u, d) { + a === (a = l(u)) && c ? c.p(u, d) : (c.d(1), c = a(u), c && (c.c(), c.m(e.parentNode, e))), d[0] & /*progress*/ + 128 && t !== (t = /*p*/ + u[39].unit + "") && we(n, t); + }, + d(u) { + u && (N(e), N(n), N(o), N(s)), c.d(u); + } + }; +} +function tc(i) { + let e = rt( + /*p*/ + i[39].index || 0 + ) + "", t; + return { + c() { + t = Q(e); + }, + m(n, o) { + z(n, t, o); + }, + p(n, o) { + o[0] & /*progress*/ + 128 && e !== (e = rt( + /*p*/ + n[39].index || 0 + ) + "") && we(t, e); + }, + d(n) { + n && N(t); + } + }; +} +function nc(i) { + let e = rt( + /*p*/ + i[39].index || 0 + ) + "", t, n, o = rt( + /*p*/ + i[39].length + ) + "", r; + return { + c() { + t = Q(e), n = Q("/"), r = Q(o); + }, + m(s, l) { + z(s, t, l), z(s, n, l), z(s, r, l); + }, + p(s, l) { + l[0] & /*progress*/ + 128 && e !== (e = rt( + /*p*/ + s[39].index || 0 + ) + "") && we(t, e), l[0] & /*progress*/ + 128 && o !== (o = rt( + /*p*/ + s[39].length + ) + "") && we(r, o); + }, + d(s) { + s && (N(t), N(n), N(r)); + } + }; +} +function Ni(i) { + let e, t = ( + /*p*/ + i[39].index != null && Wi(i) + ); + return { + c() { + t && t.c(), e = ht(); + }, + m(n, o) { + t && t.m(n, o), z(n, e, o); + }, + p(n, o) { + /*p*/ + n[39].index != null ? t ? t.p(n, o) : (t = Wi(n), t.c(), t.m(e.parentNode, e)) : t && (t.d(1), t = null); + }, + d(n) { + n && N(e), t && t.d(n); + } + }; +} +function zi(i) { + let e, t = ( + /*eta*/ + i[0] ? `/${/*formatted_eta*/ + i[19]}` : "" + ), n, o; + return { + c() { + e = Q( + /*formatted_timer*/ + i[20] + ), n = Q(t), o = Q("s"); + }, + m(r, s) { + z(r, e, s), z(r, n, s), z(r, o, s); + }, + p(r, s) { + s[0] & /*formatted_timer*/ + 1048576 && we( + e, + /*formatted_timer*/ + r[20] + ), s[0] & /*eta, formatted_eta*/ + 524289 && t !== (t = /*eta*/ + r[0] ? `/${/*formatted_eta*/ + r[19]}` : "") && we(n, t); + }, + d(r) { + r && (N(e), N(n), N(o)); + } + }; +} +function ic(i) { + let e, t; + return e = new Na({ + props: { margin: ( + /*variant*/ + i[8] === "default" + ) } + }), { + c() { + Ba(e.$$.fragment); + }, + m(n, o) { + Va(e, n, o), t = !0; + }, + p(n, o) { + const r = {}; + o[0] & /*variant*/ + 256 && (r.margin = /*variant*/ + n[8] === "default"), e.$set(r); + }, + i(n) { + t || (dt(e.$$.fragment, n), t = !0); + }, + o(n) { + ft(e.$$.fragment, n), t = !1; + }, + d(n) { + Ia(e, n); + } + }; +} +function oc(i) { + let e, t, n, o, r, s = `${/*last_progress_level*/ + i[15] * 100}%`, l = ( + /*progress*/ + i[7] != null && Bi(i) + ); + return { + c() { + e = Te("div"), t = Te("div"), l && l.c(), n = Me(), o = Te("div"), r = Te("div"), Re(t, "class", "progress-level-inner svelte-14miwb5"), Re(r, "class", "progress-bar svelte-14miwb5"), Ie(r, "width", s), Re(o, "class", "progress-bar-wrap svelte-14miwb5"), Re(e, "class", "progress-level svelte-14miwb5"); + }, + m(a, c) { + z(a, e, c), Je(e, t), l && l.m(t, null), Je(e, n), Je(e, o), Je(o, r), i[30](r); + }, + p(a, c) { + /*progress*/ + a[7] != null ? l ? l.p(a, c) : (l = Bi(a), l.c(), l.m(t, null)) : l && (l.d(1), l = null), c[0] & /*last_progress_level*/ + 32768 && s !== (s = `${/*last_progress_level*/ + a[15] * 100}%`) && Ie(r, "width", s); + }, + i: yn, + o: yn, + d(a) { + a && N(e), l && l.d(), i[30](null); + } + }; +} +function Bi(i) { + let e, t = Zt( + /*progress*/ + i[7] + ), n = []; + for (let o = 0; o < t.length; o += 1) + n[o] = Hi(Ai(i, t, o)); + return { + c() { + for (let o = 0; o < n.length; o += 1) + n[o].c(); + e = ht(); + }, + m(o, r) { + for (let s = 0; s < n.length; s += 1) + n[s] && n[s].m(o, r); + z(o, e, r); + }, + p(o, r) { + if (r[0] & /*progress_level, progress*/ + 16512) { + t = Zt( + /*progress*/ + o[7] + ); + let s; + for (s = 0; s < t.length; s += 1) { + const l = Ai(o, t, s); + n[s] ? n[s].p(l, r) : (n[s] = Hi(l), n[s].c(), n[s].m(e.parentNode, e)); + } + for (; s < n.length; s += 1) + n[s].d(1); + n.length = t.length; + } + }, + d(o) { + o && N(e), Lo(n, o); + } + }; +} +function ji(i) { + let e, t, n, o, r = ( + /*i*/ + i[41] !== 0 && sc() + ), s = ( + /*p*/ + i[39].desc != null && Ii(i) + ), l = ( + /*p*/ + i[39].desc != null && /*progress_level*/ + i[14] && /*progress_level*/ + i[14][ + /*i*/ + i[41] + ] != null && Fi() + ), a = ( + /*progress_level*/ + i[14] != null && Ui(i) + ); + return { + c() { + r && r.c(), e = Me(), s && s.c(), t = Me(), l && l.c(), n = Me(), a && a.c(), o = ht(); + }, + m(c, u) { + r && r.m(c, u), z(c, e, u), s && s.m(c, u), z(c, t, u), l && l.m(c, u), z(c, n, u), a && a.m(c, u), z(c, o, u); + }, + p(c, u) { + /*p*/ + c[39].desc != null ? s ? s.p(c, u) : (s = Ii(c), s.c(), s.m(t.parentNode, t)) : s && (s.d(1), s = null), /*p*/ + c[39].desc != null && /*progress_level*/ + c[14] && /*progress_level*/ + c[14][ + /*i*/ + c[41] + ] != null ? l || (l = Fi(), l.c(), l.m(n.parentNode, n)) : l && (l.d(1), l = null), /*progress_level*/ + c[14] != null ? a ? a.p(c, u) : (a = Ui(c), a.c(), a.m(o.parentNode, o)) : a && (a.d(1), a = null); + }, + d(c) { + c && (N(e), N(t), N(n), N(o)), r && r.d(c), s && s.d(c), l && l.d(c), a && a.d(c); + } + }; +} +function sc(i) { + let e; + return { + c() { + e = Q(" /"); + }, + m(t, n) { + z(t, e, n); + }, + d(t) { + t && N(e); + } + }; +} +function Ii(i) { + let e = ( + /*p*/ + i[39].desc + "" + ), t; + return { + c() { + t = Q(e); + }, + m(n, o) { + z(n, t, o); + }, + p(n, o) { + o[0] & /*progress*/ + 128 && e !== (e = /*p*/ + n[39].desc + "") && we(t, e); + }, + d(n) { + n && N(t); + } + }; +} +function Fi(i) { + let e; + return { + c() { + e = Q("-"); + }, + m(t, n) { + z(t, e, n); + }, + d(t) { + t && N(e); + } + }; +} +function Ui(i) { + let e = (100 * /*progress_level*/ + (i[14][ + /*i*/ + i[41] + ] || 0)).toFixed(1) + "", t, n; + return { + c() { + t = Q(e), n = Q("%"); + }, + m(o, r) { + z(o, t, r), z(o, n, r); + }, + p(o, r) { + r[0] & /*progress_level*/ + 16384 && e !== (e = (100 * /*progress_level*/ + (o[14][ + /*i*/ + o[41] + ] || 0)).toFixed(1) + "") && we(t, e); + }, + d(o) { + o && (N(t), N(n)); + } + }; +} +function Hi(i) { + let e, t = ( + /*p*/ + (i[39].desc != null || /*progress_level*/ + i[14] && /*progress_level*/ + i[14][ + /*i*/ + i[41] + ] != null) && ji(i) + ); + return { + c() { + t && t.c(), e = ht(); + }, + m(n, o) { + t && t.m(n, o), z(n, e, o); + }, + p(n, o) { + /*p*/ + n[39].desc != null || /*progress_level*/ + n[14] && /*progress_level*/ + n[14][ + /*i*/ + n[41] + ] != null ? t ? t.p(n, o) : (t = ji(n), t.c(), t.m(e.parentNode, e)) : t && (t.d(1), t = null); + }, + d(n) { + n && N(e), t && t.d(n); + } + }; +} +function Vi(i) { + let e, t; + return { + c() { + e = Te("p"), t = Q( + /*loading_text*/ + i[9] + ), Re(e, "class", "loading svelte-14miwb5"); + }, + m(n, o) { + z(n, e, o), Je(e, t); + }, + p(n, o) { + o[0] & /*loading_text*/ + 512 && we( + t, + /*loading_text*/ + n[9] + ); + }, + d(n) { + n && N(e); + } + }; +} +function rc(i) { + let e, t, n, o, r; + const s = [Qa, Ka], l = []; + function a(c, u) { + return ( + /*status*/ + c[4] === "pending" ? 0 : ( + /*status*/ + c[4] === "error" ? 1 : -1 + ) + ); + } + return ~(t = a(i)) && (n = l[t] = s[t](i)), { + c() { + e = Te("div"), n && n.c(), Re(e, "class", o = "wrap " + /*variant*/ + i[8] + " " + /*show_progress*/ + i[6] + " svelte-14miwb5"), be(e, "hide", !/*status*/ + i[4] || /*status*/ + i[4] === "complete" || /*show_progress*/ + i[6] === "hidden"), be( + e, + "translucent", + /*variant*/ + i[8] === "center" && /*status*/ + (i[4] === "pending" || /*status*/ + i[4] === "error") || /*translucent*/ + i[11] || /*show_progress*/ + i[6] === "minimal" + ), be( + e, + "generating", + /*status*/ + i[4] === "generating" + ), be( + e, + "border", + /*border*/ + i[12] + ), Ie( + e, + "position", + /*absolute*/ + i[10] ? "absolute" : "static" + ), Ie( + e, + "padding", + /*absolute*/ + i[10] ? "0" : "var(--size-8) 0" + ); + }, + m(c, u) { + z(c, e, u), ~t && l[t].m(e, null), i[31](e), r = !0; + }, + p(c, u) { + let d = t; + t = a(c), t === d ? ~t && l[t].p(c, u) : (n && (Po(), ft(l[d], 1, 1, () => { + l[d] = null; + }), Mo()), ~t ? (n = l[t], n ? n.p(c, u) : (n = l[t] = s[t](c), n.c()), dt(n, 1), n.m(e, null)) : n = null), (!r || u[0] & /*variant, show_progress*/ + 320 && o !== (o = "wrap " + /*variant*/ + c[8] + " " + /*show_progress*/ + c[6] + " svelte-14miwb5")) && Re(e, "class", o), (!r || u[0] & /*variant, show_progress, status, show_progress*/ + 336) && be(e, "hide", !/*status*/ + c[4] || /*status*/ + c[4] === "complete" || /*show_progress*/ + c[6] === "hidden"), (!r || u[0] & /*variant, show_progress, variant, status, translucent, show_progress*/ + 2384) && be( + e, + "translucent", + /*variant*/ + c[8] === "center" && /*status*/ + (c[4] === "pending" || /*status*/ + c[4] === "error") || /*translucent*/ + c[11] || /*show_progress*/ + c[6] === "minimal" + ), (!r || u[0] & /*variant, show_progress, status*/ + 336) && be( + e, + "generating", + /*status*/ + c[4] === "generating" + ), (!r || u[0] & /*variant, show_progress, border*/ + 4416) && be( + e, + "border", + /*border*/ + c[12] + ), u[0] & /*absolute*/ + 1024 && Ie( + e, + "position", + /*absolute*/ + c[10] ? "absolute" : "static" + ), u[0] & /*absolute*/ + 1024 && Ie( + e, + "padding", + /*absolute*/ + c[10] ? "0" : "var(--size-8) 0" + ); + }, + i(c) { + r || (dt(n), r = !0); + }, + o(c) { + ft(n), r = !1; + }, + d(c) { + c && N(e), ~t && l[t].d(), i[31](null); + } + }; +} +var lc = function(i, e, t, n) { + function o(r) { + return r instanceof t ? r : new t(function(s) { + s(r); + }); + } + return new (t || (t = Promise))(function(r, s) { + function l(u) { + try { + c(n.next(u)); + } catch (d) { + s(d); + } + } + function a(u) { + try { + c(n.throw(u)); + } catch (d) { + s(d); + } + } + function c(u) { + u.done ? r(u.value) : o(u.value).then(l, a); + } + c((n = n.apply(i, e || [])).next()); + }); +}; +let Rt = [], _n = !1; +function ac(i) { + return lc(this, arguments, void 0, function* (e, t = !0) { + if (!(window.__gradio_mode__ === "website" || window.__gradio_mode__ !== "app" && t !== !0)) { + if (Rt.push(e), !_n) + _n = !0; + else + return; + yield Za(), requestAnimationFrame(() => { + let n = [0, 0]; + for (let o = 0; o < Rt.length; o++) { + const s = Rt[o].getBoundingClientRect(); + (o === 0 || s.top + window.scrollY <= n[0]) && (n[0] = s.top + window.scrollY, n[1] = o); + } + window.scrollTo({ top: n[0] - 20, behavior: "smooth" }), _n = !1, Rt = []; + }); + } + }); +} +function cc(i, e, t) { + let n, { $$slots: o = {}, $$scope: r } = e; + this && this.__awaiter; + let { i18n: s } = e, { eta: l = null } = e, { queue: a = !1 } = e, { queue_position: c } = e, { queue_size: u } = e, { status: d } = e, { scroll_to_output: _ = !1 } = e, { timer: h = !0 } = e, { show_progress: f = "full" } = e, { message: v = null } = e, { progress: g = null } = e, { variant: p = "default" } = e, { loading_text: m = "Loading..." } = e, { absolute: w = !0 } = e, { translucent: k = !1 } = e, { border: A = !1 } = e, { autoscroll: W } = e, M, P = !1, U = 0, H = 0, X = null, F = 0, y = null, S, L = null, b = !0; + const D = () => { + t(25, U = performance.now()), t(26, H = 0), P = !0, E(); + }; + function E() { + requestAnimationFrame(() => { + t(26, H = (performance.now() - U) / 1e3), P && E(); + }); + } + function T() { + t(26, H = 0), P && (P = !1); + } + Ja(() => { + P && T(); + }); + let B = null; + function Z(C) { + Pi[C ? "unshift" : "push"](() => { + L = C, t(16, L), t(7, g), t(14, y), t(15, S); + }); + } + function q(C) { + Pi[C ? "unshift" : "push"](() => { + M = C, t(13, M); + }); + } + return i.$$set = (C) => { + "i18n" in C && t(1, s = C.i18n), "eta" in C && t(0, l = C.eta), "queue" in C && t(21, a = C.queue), "queue_position" in C && t(2, c = C.queue_position), "queue_size" in C && t(3, u = C.queue_size), "status" in C && t(4, d = C.status), "scroll_to_output" in C && t(22, _ = C.scroll_to_output), "timer" in C && t(5, h = C.timer), "show_progress" in C && t(6, f = C.show_progress), "message" in C && t(23, v = C.message), "progress" in C && t(7, g = C.progress), "variant" in C && t(8, p = C.variant), "loading_text" in C && t(9, m = C.loading_text), "absolute" in C && t(10, w = C.absolute), "translucent" in C && t(11, k = C.translucent), "border" in C && t(12, A = C.border), "autoscroll" in C && t(24, W = C.autoscroll), "$$scope" in C && t(28, r = C.$$scope); + }, i.$$.update = () => { + i.$$.dirty[0] & /*eta, old_eta, queue, timer_start*/ + 169869313 && (l === null ? t(0, l = X) : a && t(0, l = (performance.now() - U) / 1e3 + l), l != null && (t(19, B = l.toFixed(1)), t(27, X = l))), i.$$.dirty[0] & /*eta, timer_diff*/ + 67108865 && t(17, F = l === null || l <= 0 || !H ? null : Math.min(H / l, 1)), i.$$.dirty[0] & /*progress*/ + 128 && g != null && t(18, b = !1), i.$$.dirty[0] & /*progress, progress_level, progress_bar, last_progress_level*/ + 114816 && (g != null ? t(14, y = g.map((C) => { + if (C.index != null && C.length != null) + return C.index / C.length; + if (C.progress != null) + return C.progress; + })) : t(14, y = null), y ? (t(15, S = y[y.length - 1]), L && (S === 0 ? t(16, L.style.transition = "0", L) : t(16, L.style.transition = "150ms", L))) : t(15, S = void 0)), i.$$.dirty[0] & /*status*/ + 16 && (d === "pending" ? D() : T()), i.$$.dirty[0] & /*el, scroll_to_output, status, autoscroll*/ + 20979728 && M && _ && (d === "pending" || d === "complete") && ac(M, W), i.$$.dirty[0] & /*status, message*/ + 8388624, i.$$.dirty[0] & /*timer_diff*/ + 67108864 && t(20, n = H.toFixed(1)); + }, [ + l, + s, + c, + u, + d, + h, + f, + g, + p, + m, + w, + k, + A, + M, + y, + S, + L, + F, + b, + B, + n, + a, + _, + v, + W, + U, + H, + X, + r, + o, + Z, + q + ]; +} +class uc extends za { + constructor(e) { + super(), Ha( + this, + e, + cc, + rc, + Ga, + { + i18n: 1, + eta: 0, + queue: 21, + queue_position: 2, + queue_size: 3, + status: 4, + scroll_to_output: 22, + timer: 5, + show_progress: 6, + message: 23, + progress: 7, + variant: 8, + loading_text: 9, + absolute: 10, + translucent: 11, + border: 12, + autoscroll: 24 + }, + null, + [-1, -1] + ); + } +} +const { + SvelteComponent: dc, + add_flush_callback: fc, + assign: hc, + bind: _c, + binding_callbacks: mc, + check_outros: pc, + create_component: kn, + destroy_component: Cn, + detach: To, + empty: gc, + flush: x, + get_spread_object: vc, + get_spread_update: bc, + group_outros: wc, + init: yc, + insert: Ao, + mount_component: Sn, + safe_not_equal: kc, + space: Cc, + transition_in: yt, + transition_out: kt +} = window.__gradio__svelte__internal; +function Sc(i) { + let e, t, n; + function o(s) { + i[33](s); + } + let r = { + label: ( + /*label*/ + i[4] + ), + show_label: ( + /*show_label*/ + i[6] + ), + value: ( + /*_value*/ + i[13] + ), + root: ( + /*root*/ + i[5] + ), + sources: ( + /*sources*/ + i[2] + ), + active_source: ( + /*active_source*/ + i[14] + ), + pending: ( + /*pending*/ + i[10] + ), + streaming: ( + /*streaming*/ + i[11] + ), + handle_reset_value: ( + /*handle_reset_value*/ + i[16] + ), + i18n: ( + /*gradio*/ + i[12].i18n + ), + waveform_settings: ( + /*waveform_settings*/ + i[17] + ) + }; + return ( + /*dragging*/ + i[15] !== void 0 && (r.dragging = /*dragging*/ + i[15]), e = new Ca({ props: r }), mc.push(() => _c(e, "dragging", o)), e.$on( + "change", + /*change_handler*/ + i[34] + ), e.$on( + "stream", + /*stream_handler*/ + i[35] + ), e.$on( + "drag", + /*drag_handler*/ + i[36] + ), e.$on( + "edit", + /*edit_handler*/ + i[37] + ), e.$on( + "play", + /*play_handler*/ + i[38] + ), e.$on( + "pause", + /*pause_handler*/ + i[39] + ), e.$on( + "stop", + /*stop_handler*/ + i[40] + ), e.$on( + "end", + /*end_handler_1*/ + i[41] + ), e.$on( + "start_recording", + /*start_recording_handler*/ + i[42] + ), e.$on( + "pause_recording", + /*pause_recording_handler*/ + i[43] + ), e.$on( + "stop_recording", + /*stop_recording_handler*/ + i[44] + ), e.$on( + "upload", + /*upload_handler*/ + i[45] + ), e.$on( + "clear", + /*clear_handler*/ + i[46] + ), e.$on( + "error", + /*handle_error*/ + i[18] + ), { + c() { + kn(e.$$.fragment); + }, + m(s, l) { + Sn(e, s, l), n = !0; + }, + p(s, l) { + const a = {}; + l[0] & /*label*/ + 16 && (a.label = /*label*/ + s[4]), l[0] & /*show_label*/ + 64 && (a.show_label = /*show_label*/ + s[6]), l[0] & /*_value*/ + 8192 && (a.value = /*_value*/ + s[13]), l[0] & /*root*/ + 32 && (a.root = /*root*/ + s[5]), l[0] & /*sources*/ + 4 && (a.sources = /*sources*/ + s[2]), l[0] & /*active_source*/ + 16384 && (a.active_source = /*active_source*/ + s[14]), l[0] & /*pending*/ + 1024 && (a.pending = /*pending*/ + s[10]), l[0] & /*streaming*/ + 2048 && (a.streaming = /*streaming*/ + s[11]), l[0] & /*gradio*/ + 4096 && (a.i18n = /*gradio*/ + s[12].i18n), !t && l[0] & /*dragging*/ + 32768 && (t = !0, a.dragging = /*dragging*/ + s[15], fc(() => t = !1)), e.$set(a); + }, + i(s) { + n || (yt(e.$$.fragment, s), n = !0); + }, + o(s) { + kt(e.$$.fragment, s), n = !1; + }, + d(s) { + Cn(e, s); + } + } + ); +} +function Ec(i) { + let e, t, n, o; + const r = [ + { + autoscroll: ( + /*gradio*/ + i[12].autoscroll + ) + }, + { i18n: ( + /*gradio*/ + i[12].i18n + ) }, + /*loading_status*/ + i[1] + ]; + let s = {}; + for (let l = 0; l < r.length; l += 1) + s = hc(s, r[l]); + return e = new uc({ props: s }), n = new ll({ + props: { + i18n: ( + /*gradio*/ + i[12].i18n + ), + image: ( + /*image*/ + i[3] + ), + show_label: ( + /*show_label*/ + i[6] + ), + show_download_button: ( + /*show_download_button*/ + i[8] + ), + show_share_button: ( + /*show_share_button*/ + i[9] + ), + value: ( + /*_value*/ + i[13] + ), + label: ( + /*label*/ + i[4] + ), + root: ( + /*root*/ + i[5] + ), + proxy_url: ( + /*proxy_url*/ + i[7] + ), + waveform_settings: ( + /*waveform_settings*/ + i[17] + ) + } + }), n.$on( + "share", + /*share_handler*/ + i[30] + ), n.$on( + "error", + /*error_handler*/ + i[31] + ), n.$on( + "end", + /*end_handler*/ + i[32] + ), { + c() { + kn(e.$$.fragment), t = Cc(), kn(n.$$.fragment); + }, + m(l, a) { + Sn(e, l, a), Ao(l, t, a), Sn(n, l, a), o = !0; + }, + p(l, a) { + const c = a[0] & /*gradio, loading_status*/ + 4098 ? bc(r, [ + a[0] & /*gradio*/ + 4096 && { + autoscroll: ( + /*gradio*/ + l[12].autoscroll + ) + }, + a[0] & /*gradio*/ + 4096 && { i18n: ( + /*gradio*/ + l[12].i18n + ) }, + a[0] & /*loading_status*/ + 2 && vc( + /*loading_status*/ + l[1] + ) + ]) : {}; + e.$set(c); + const u = {}; + a[0] & /*gradio*/ + 4096 && (u.i18n = /*gradio*/ + l[12].i18n), a[0] & /*image*/ + 8 && (u.image = /*image*/ + l[3]), a[0] & /*show_label*/ + 64 && (u.show_label = /*show_label*/ + l[6]), a[0] & /*show_download_button*/ + 256 && (u.show_download_button = /*show_download_button*/ + l[8]), a[0] & /*show_share_button*/ + 512 && (u.show_share_button = /*show_share_button*/ + l[9]), a[0] & /*_value*/ + 8192 && (u.value = /*_value*/ + l[13]), a[0] & /*label*/ + 16 && (u.label = /*label*/ + l[4]), a[0] & /*root*/ + 32 && (u.root = /*root*/ + l[5]), a[0] & /*proxy_url*/ + 128 && (u.proxy_url = /*proxy_url*/ + l[7]), n.$set(u); + }, + i(l) { + o || (yt(e.$$.fragment, l), yt(n.$$.fragment, l), o = !0); + }, + o(l) { + kt(e.$$.fragment, l), kt(n.$$.fragment, l), o = !1; + }, + d(l) { + l && To(t), Cn(e, l), Cn(n, l); + } + }; +} +function Dc(i) { + let e, t, n, o; + const r = [Ec, Sc], s = []; + function l(a, c) { + return ( + /*value*/ + a[0] !== null && !/*streaming*/ + a[11] ? 0 : 1 + ); + } + return e = l(i), t = s[e] = r[e](i), { + c() { + t.c(), n = gc(); + }, + m(a, c) { + s[e].m(a, c), Ao(a, n, c), o = !0; + }, + p(a, c) { + let u = e; + e = l(a), e === u ? s[e].p(a, c) : (wc(), kt(s[u], 1, 1, () => { + s[u] = null; + }), pc(), t = s[e], t ? t.p(a, c) : (t = s[e] = r[e](a), t.c()), yt(t, 1), t.m(n.parentNode, n)); + }, + i(a) { + o || (yt(t), o = !0); + }, + o(a) { + kt(t), o = !1; + }, + d(a) { + a && To(n), s[e].d(a); + } + }; +} +function Rc(i, e, t) { + let { elem_id: n = "" } = e, { elem_classes: o = [] } = e, { visible: r = !0 } = e, { interactive: s } = e, { value: l = null } = e, { sources: a } = e, { image: c = null } = e, { label: u } = e, { root: d } = e, { show_label: _ } = e, { proxy_url: h } = e, { container: f = !0 } = e, { scale: v = null } = e, { min_width: g = void 0 } = e, { loading_status: p } = e, { autoplay: m = !1 } = e, { show_download_button: w = !0 } = e, { show_share_button: k = !1 } = e, { waveform_options: A = {} } = e, { pending: W } = e, { streaming: M } = e, { gradio: P } = e, U = null, H, X, F = l; + const y = () => { + F === null || l === F || t(0, l = F); + }; + let S; + const L = { + height: 50, + waveColor: A.waveform_color || "#9ca3af", + progressColor: A.waveform_progress_color || "#f97316", + barWidth: 2, + barGap: 3, + barHeight: 4, + cursorWidth: 2, + cursorColor: "#ddd5e9", + autoplay: m, + barRadius: 10, + dragToSeek: !0, + mediaControls: A.show_controls + }; + function b({ detail: R }) { + const [Y, $] = R.includes("Invalid file type") ? ["warning", "complete"] : ["error", "error"]; + t(1, p = p || {}), t(1, p.status = $, p), t(1, p.message = R, p), P.dispatch(Y, R); + } + const D = (R) => P.dispatch("share", R.detail), E = (R) => P.dispatch("error", R.detail), T = () => P.dispatch("end"); + function B(R) { + S = R, t(15, S); + } + const Z = ({ detail: R }) => t(0, l = R), q = ({ detail: R }) => { + t(0, l = R), P.dispatch("stream", l); + }, C = ({ detail: R }) => t(15, S = R), J = () => P.dispatch("edit"), ne = () => P.dispatch("play"), le = () => P.dispatch("pause"), re = () => P.dispatch("stop"), j = () => P.dispatch("end"), ae = () => P.dispatch("start_recording"), Ae = () => P.dispatch("pause_recording"), Ge = (R) => P.dispatch("stop_recording", R.detail), Pe = () => P.dispatch("upload"), V = () => P.dispatch("clear"); + return i.$$set = (R) => { + "elem_id" in R && t(19, n = R.elem_id), "elem_classes" in R && t(20, o = R.elem_classes), "visible" in R && t(21, r = R.visible), "interactive" in R && t(22, s = R.interactive), "value" in R && t(0, l = R.value), "sources" in R && t(2, a = R.sources), "image" in R && t(3, c = R.image), "label" in R && t(4, u = R.label), "root" in R && t(5, d = R.root), "show_label" in R && t(6, _ = R.show_label), "proxy_url" in R && t(7, h = R.proxy_url), "container" in R && t(23, f = R.container), "scale" in R && t(24, v = R.scale), "min_width" in R && t(25, g = R.min_width), "loading_status" in R && t(1, p = R.loading_status), "autoplay" in R && t(26, m = R.autoplay), "show_download_button" in R && t(8, w = R.show_download_button), "show_share_button" in R && t(9, k = R.show_share_button), "waveform_options" in R && t(27, A = R.waveform_options), "pending" in R && t(10, W = R.pending), "streaming" in R && t(11, M = R.streaming), "gradio" in R && t(12, P = R.gradio); + }, i.$$.update = () => { + i.$$.dirty[0] & /*value, root, proxy_url*/ + 161 && t(13, H = Ze(l, d, h)), i.$$.dirty[0] & /*value, initial_value*/ + 536870913 && l && F === null && t(29, F = l), i.$$.dirty[0] & /*value, old_value, gradio*/ + 268439553 && JSON.stringify(l) !== JSON.stringify(U) && (t(28, U = l), P.dispatch("change")), i.$$.dirty[0] & /*sources*/ + 4 && a && t(14, X = a[0]); + }, [ + l, + p, + a, + c, + u, + d, + _, + h, + w, + k, + W, + M, + P, + H, + X, + S, + y, + L, + b, + n, + o, + r, + s, + f, + v, + g, + m, + A, + U, + F, + D, + E, + T, + B, + Z, + q, + C, + J, + ne, + le, + re, + j, + ae, + Ae, + Ge, + Pe, + V + ]; +} +class du extends dc { + constructor(e) { + super(), yc( + this, + e, + Rc, + Dc, + kc, + { + elem_id: 19, + elem_classes: 20, + visible: 21, + interactive: 22, + value: 0, + sources: 2, + image: 3, + label: 4, + root: 5, + show_label: 6, + proxy_url: 7, + container: 23, + scale: 24, + min_width: 25, + loading_status: 1, + autoplay: 26, + show_download_button: 8, + show_share_button: 9, + waveform_options: 27, + pending: 10, + streaming: 11, + gradio: 12 + }, + null, + [-1, -1] + ); + } + get elem_id() { + return this.$$.ctx[19]; + } + set elem_id(e) { + this.$$set({ elem_id: e }), x(); + } + get elem_classes() { + return this.$$.ctx[20]; + } + set elem_classes(e) { + this.$$set({ elem_classes: e }), x(); + } + get visible() { + return this.$$.ctx[21]; + } + set visible(e) { + this.$$set({ visible: e }), x(); + } + get interactive() { + return this.$$.ctx[22]; + } + set interactive(e) { + this.$$set({ interactive: e }), x(); + } + get value() { + return this.$$.ctx[0]; + } + set value(e) { + this.$$set({ value: e }), x(); + } + get sources() { + return this.$$.ctx[2]; + } + set sources(e) { + this.$$set({ sources: e }), x(); + } + get image() { + return this.$$.ctx[3]; + } + set image(e) { + this.$$set({ image: e }), x(); + } + get label() { + return this.$$.ctx[4]; + } + set label(e) { + this.$$set({ label: e }), x(); + } + get root() { + return this.$$.ctx[5]; + } + set root(e) { + this.$$set({ root: e }), x(); + } + get show_label() { + return this.$$.ctx[6]; + } + set show_label(e) { + this.$$set({ show_label: e }), x(); + } + get proxy_url() { + return this.$$.ctx[7]; + } + set proxy_url(e) { + this.$$set({ proxy_url: e }), x(); + } + get container() { + return this.$$.ctx[23]; + } + set container(e) { + this.$$set({ container: e }), x(); + } + get scale() { + return this.$$.ctx[24]; + } + set scale(e) { + this.$$set({ scale: e }), x(); + } + get min_width() { + return this.$$.ctx[25]; + } + set min_width(e) { + this.$$set({ min_width: e }), x(); + } + get loading_status() { + return this.$$.ctx[1]; + } + set loading_status(e) { + this.$$set({ loading_status: e }), x(); + } + get autoplay() { + return this.$$.ctx[26]; + } + set autoplay(e) { + this.$$set({ autoplay: e }), x(); + } + get show_download_button() { + return this.$$.ctx[8]; + } + set show_download_button(e) { + this.$$set({ show_download_button: e }), x(); + } + get show_share_button() { + return this.$$.ctx[9]; + } + set show_share_button(e) { + this.$$set({ show_share_button: e }), x(); + } + get waveform_options() { + return this.$$.ctx[27]; + } + set waveform_options(e) { + this.$$set({ waveform_options: e }), x(); + } + get pending() { + return this.$$.ctx[10]; + } + set pending(e) { + this.$$set({ pending: e }), x(); + } + get streaming() { + return this.$$.ctx[11]; + } + set streaming(e) { + this.$$set({ streaming: e }), x(); + } + get gradio() { + return this.$$.ctx[12]; + } + set gradio(e) { + this.$$set({ gradio: e }), x(); + } +} +const { setContext: fu, getContext: Mc } = window.__gradio__svelte__internal, Lc = "WORKER_PROXY_CONTEXT_KEY"; +function Pc() { + return Mc(Lc); +} +function Tc(i) { + return i.host === window.location.host || i.host === "localhost:7860" || i.host === "127.0.0.1:7860" || // Ref: https://github.com/gradio-app/gradio/blob/v3.32.0/js/app/src/Index.svelte#L194 + i.host === "lite.local"; +} +async function Ac(i) { + if (i == null) + return i; + const e = new URL(i); + if (!Tc(e) || e.protocol !== "http:" && e.protocol !== "https:") + return i; + const t = Pc(); + if (t == null) + return i; + const n = e.pathname; + return t.httpRequest({ + method: "GET", + path: n, + headers: {}, + query_string: "" + }).then((o) => { + if (o.status !== 200) + throw new Error(`Failed to get file ${n} from the Wasm worker.`); + const r = new Blob([o.body], { + type: o.headers["Content-Type"] + }); + return URL.createObjectURL(r); + }); +} +const { + SvelteComponent: Oc, + add_flush_callback: Gi, + append: Se, + attr: he, + bind: Xi, + binding_callbacks: bt, + check_outros: Oo, + create_component: Wn, + destroy_component: Nn, + detach: zn, + element: ze, + empty: qc, + group_outros: qo, + init: Wc, + insert: Bn, + mount_component: jn, + safe_not_equal: Nc, + set_data: zc, + space: Mt, + text: Bc, + transition_in: He, + transition_out: $e +} = window.__gradio__svelte__internal, { onMount: jc } = window.__gradio__svelte__internal; +function Ic(i) { + let e, t, n, o, r, s, l, a, c, u, d, _, h, f = ( + /*mode*/ + i[0] === "edit" && /*trimDuration*/ + i[13] > 0 && Zi(i) + ), v = ( + /*waveform*/ + i[8] && Ji(i) + ); + return { + c() { + e = ze("div"), t = ze("div"), n = ze("div"), o = Mt(), r = ze("div"), s = ze("time"), s.textContent = "0:00", l = Mt(), a = ze("div"), f && f.c(), c = Mt(), u = ze("time"), u.textContent = "0:00", d = Mt(), v && v.c(), he(n, "id", "waveform"), he(n, "class", "svelte-1iry1ax"), he(t, "class", "waveform-container svelte-1iry1ax"), he(s, "id", "time"), he(s, "class", "svelte-1iry1ax"), he(u, "id", "duration"), he(u, "class", "svelte-1iry1ax"), he(r, "class", "timestamps svelte-1iry1ax"), he(e, "class", "component-wrapper svelte-1iry1ax"), he(e, "data-testid", _ = /*label*/ + i[2] ? "waveform-" + /*label*/ + i[2] : "unlabelled-audio"); + }, + m(g, p) { + Bn(g, e, p), Se(e, t), Se(t, n), i[18](n), Se(e, o), Se(e, r), Se(r, s), i[19](s), Se(r, l), Se(r, a), f && f.m(a, null), Se(a, c), Se(a, u), i[20](u), Se(e, d), v && v.m(e, null), h = !0; + }, + p(g, p) { + /*mode*/ + g[0] === "edit" && /*trimDuration*/ + g[13] > 0 ? f ? f.p(g, p) : (f = Zi(g), f.c(), f.m(a, c)) : f && (f.d(1), f = null), /*waveform*/ + g[8] ? v ? (v.p(g, p), p & /*waveform*/ + 256 && He(v, 1)) : (v = Ji(g), v.c(), He(v, 1), v.m(e, null)) : v && (qo(), $e(v, 1, 1, () => { + v = null; + }), Oo()), (!h || p & /*label*/ + 4 && _ !== (_ = /*label*/ + g[2] ? "waveform-" + /*label*/ + g[2] : "unlabelled-audio")) && he(e, "data-testid", _); + }, + i(g) { + h || (He(v), h = !0); + }, + o(g) { + $e(v), h = !1; + }, + d(g) { + g && zn(e), i[18](null), i[19](null), f && f.d(), i[20](null), v && v.d(); + } + }; +} +function Fc(i) { + let e, t; + return e = new xi({ + props: { + size: "small", + $$slots: { default: [Uc] }, + $$scope: { ctx: i } + } + }), { + c() { + Wn(e.$$.fragment); + }, + m(n, o) { + jn(e, n, o), t = !0; + }, + p(n, o) { + const r = {}; + o & /*$$scope*/ + 67108864 && (r.$$scope = { dirty: o, ctx: n }), e.$set(r); + }, + i(n) { + t || (He(e.$$.fragment, n), t = !0); + }, + o(n) { + $e(e.$$.fragment, n), t = !1; + }, + d(n) { + Nn(e, n); + } + }; +} +function Zi(i) { + let e, t = ( + /*formatTime*/ + i[14]( + /*trimDuration*/ + i[13] + ) + "" + ), n; + return { + c() { + e = ze("time"), n = Bc(t), he(e, "id", "trim-duration"), he(e, "class", "svelte-1iry1ax"); + }, + m(o, r) { + Bn(o, e, r), Se(e, n); + }, + p(o, r) { + r & /*trimDuration*/ + 8192 && t !== (t = /*formatTime*/ + o[14]( + /*trimDuration*/ + o[13] + ) + "") && zc(n, t); + }, + d(o) { + o && zn(e); + } + }; +} +function Ji(i) { + let e, t, n, o; + function r(a) { + i[21](a); + } + function s(a) { + i[22](a); + } + let l = { + container: ( + /*container*/ + i[7] + ), + waveform: ( + /*waveform*/ + i[8] + ), + playing: ( + /*playing*/ + i[11] + ), + audioDuration: ( + /*audioDuration*/ + i[12] + ), + i18n: ( + /*i18n*/ + i[3] + ), + interactive: ( + /*interactive*/ + i[4] + ), + handle_trim_audio: ( + /*handle_trim_audio*/ + i[15] + ), + showRedo: ( + /*interactive*/ + i[4] + ), + handle_reset_value: ( + /*handle_reset_value*/ + i[6] + ), + waveform_settings: ( + /*waveform_settings*/ + i[5] + ) + }; + return ( + /*mode*/ + i[0] !== void 0 && (l.mode = /*mode*/ + i[0]), /*trimDuration*/ + i[13] !== void 0 && (l.trimDuration = /*trimDuration*/ + i[13]), e = new mo({ props: l }), bt.push(() => Xi(e, "mode", r)), bt.push(() => Xi(e, "trimDuration", s)), { + c() { + Wn(e.$$.fragment); + }, + m(a, c) { + jn(e, a, c), o = !0; + }, + p(a, c) { + const u = {}; + c & /*container*/ + 128 && (u.container = /*container*/ + a[7]), c & /*waveform*/ + 256 && (u.waveform = /*waveform*/ + a[8]), c & /*playing*/ + 2048 && (u.playing = /*playing*/ + a[11]), c & /*audioDuration*/ + 4096 && (u.audioDuration = /*audioDuration*/ + a[12]), c & /*i18n*/ + 8 && (u.i18n = /*i18n*/ + a[3]), c & /*interactive*/ + 16 && (u.interactive = /*interactive*/ + a[4]), c & /*interactive*/ + 16 && (u.showRedo = /*interactive*/ + a[4]), c & /*handle_reset_value*/ + 64 && (u.handle_reset_value = /*handle_reset_value*/ + a[6]), c & /*waveform_settings*/ + 32 && (u.waveform_settings = /*waveform_settings*/ + a[5]), !t && c & /*mode*/ + 1 && (t = !0, u.mode = /*mode*/ + a[0], Gi(() => t = !1)), !n && c & /*trimDuration*/ + 8192 && (n = !0, u.trimDuration = /*trimDuration*/ + a[13], Gi(() => n = !1)), e.$set(u); + }, + i(a) { + o || (He(e.$$.fragment, a), o = !0); + }, + o(a) { + $e(e.$$.fragment, a), o = !1; + }, + d(a) { + Nn(e, a); + } + } + ); +} +function Uc(i) { + let e, t; + return e = new $i({}), { + c() { + Wn(e.$$.fragment); + }, + m(n, o) { + jn(e, n, o), t = !0; + }, + i(n) { + t || (He(e.$$.fragment, n), t = !0); + }, + o(n) { + $e(e.$$.fragment, n), t = !1; + }, + d(n) { + Nn(e, n); + } + }; +} +function Hc(i) { + let e, t, n, o; + const r = [Fc, Ic], s = []; + function l(a, c) { + return ( + /*value*/ + a[1] === null ? 0 : 1 + ); + } + return e = l(i), t = s[e] = r[e](i), { + c() { + t.c(), n = qc(); + }, + m(a, c) { + s[e].m(a, c), Bn(a, n, c), o = !0; + }, + p(a, [c]) { + let u = e; + e = l(a), e === u ? s[e].p(a, c) : (qo(), $e(s[u], 1, 1, () => { + s[u] = null; + }), Oo(), t = s[e], t ? t.p(a, c) : (t = s[e] = r[e](a), t.c()), He(t, 1), t.m(n.parentNode, n)); + }, + i(a) { + o || (He(t), o = !0); + }, + o(a) { + $e(t), o = !1; + }, + d(a) { + a && zn(n), s[e].d(a); + } + }; +} +function Vc(i, e, t) { + var n = this && this.__awaiter || function(y, S, L, b) { + function D(E) { + return E instanceof L ? E : new L(function(T) { + T(E); + }); + } + return new (L || (L = Promise))(function(E, T) { + function B(C) { + try { + q(b.next(C)); + } catch (J) { + T(J); + } + } + function Z(C) { + try { + q(b.throw(C)); + } catch (J) { + T(J); + } + } + function q(C) { + C.done ? E(C.value) : D(C.value).then(B, Z); + } + q((b = b.apply(y, S || [])).next()); + }); + }; + let { value: o = null } = e, { label: r } = e, { i18n: s } = e, { dispatch: l } = e, { dispatch_blob: a = () => Promise.resolve() } = e, { interactive: c = !1 } = e, { waveform_settings: u = {} } = e, { mode: d = "" } = e, { handle_reset_value: _ = () => { + } } = e, h, f, v = !1, g, p, m, w = 0; + const k = (y) => { + const S = Math.floor(y / 60), b = `0${Math.round(y) % 60}`.slice(-2); + return `${S}:${b}`; + }, A = () => { + t(8, f = Ve.create(Object.assign( + { + container: h, + url: o == null ? void 0 : o.url + }, + u + ))); + }, W = (y, S) => n(void 0, void 0, void 0, function* () { + t(0, d = ""); + const L = f.getDecodedData(); + L && (yield bn(L, y, S).then((b) => n(void 0, void 0, void 0, function* () { + yield a([b], "change"), f.destroy(), A(); + }))), l("edit"); + }); + function M(y) { + return n(this, void 0, void 0, function* () { + yield Ac(y).then((S) => { + if (S) + return f == null ? void 0 : f.load(S); + }); + }); + } + jc(() => { + window.addEventListener("keydown", (y) => { + y.key === "ArrowRight" && d !== "edit" ? It(f, 0.1) : y.key === "ArrowLeft" && d !== "edit" && It(f, -0.1); + }); + }); + function P(y) { + bt[y ? "unshift" : "push"](() => { + h = y, t(7, h), t(8, f); + }); + } + function U(y) { + bt[y ? "unshift" : "push"](() => { + g = y, t(9, g), t(8, f); + }); + } + function H(y) { + bt[y ? "unshift" : "push"](() => { + p = y, t(10, p), t(8, f); + }); + } + function X(y) { + d = y, t(0, d); + } + function F(y) { + w = y, t(13, w); + } + return i.$$set = (y) => { + "value" in y && t(1, o = y.value), "label" in y && t(2, r = y.label), "i18n" in y && t(3, s = y.i18n), "dispatch" in y && t(16, l = y.dispatch), "dispatch_blob" in y && t(17, a = y.dispatch_blob), "interactive" in y && t(4, c = y.interactive), "waveform_settings" in y && t(5, u = y.waveform_settings), "mode" in y && t(0, d = y.mode), "handle_reset_value" in y && t(6, _ = y.handle_reset_value); + }, i.$$.update = () => { + i.$$.dirty & /*container, waveform*/ + 384 && h !== void 0 && (f !== void 0 && f.destroy(), t(7, h.innerHTML = "", h), A(), t(11, v = !1)), i.$$.dirty & /*waveform, durationRef*/ + 1280 && (f == null || f.on("decode", (y) => { + t(12, m = y), p && t(10, p.textContent = k(y), p); + })), i.$$.dirty & /*waveform, timeRef*/ + 768 && (f == null || f.on("timeupdate", (y) => g && t(9, g.textContent = k(y), g))), i.$$.dirty & /*waveform, dispatch*/ + 65792 && (f == null || f.on("finish", () => { + t(11, v = !1), l("stop"), l("end"); + })), i.$$.dirty & /*waveform, dispatch*/ + 65792 && (f == null || f.on("pause", () => { + t(11, v = !1), l("pause"); + })), i.$$.dirty & /*waveform, dispatch*/ + 65792 && (f == null || f.on("play", () => { + t(11, v = !0), l("play"); + })), i.$$.dirty & /*value*/ + 2 && o != null && o.url && M(o.url); + }, [ + d, + o, + r, + s, + c, + u, + _, + h, + f, + g, + p, + v, + m, + w, + k, + W, + l, + a, + P, + U, + H, + X, + F + ]; +} +class hu extends Oc { + constructor(e) { + super(), Wc(this, e, Vc, Hc, Nc, { + value: 1, + label: 2, + i18n: 3, + dispatch: 16, + dispatch_blob: 17, + interactive: 4, + waveform_settings: 5, + mode: 0, + handle_reset_value: 6 + }); + } +} +const { + SvelteComponent: Gc, + append: Xc, + attr: Zc, + detach: Jc, + element: Yc, + init: Kc, + insert: Qc, + noop: Yi, + safe_not_equal: xc, + set_data: $c, + text: eu, + toggle_class: nt +} = window.__gradio__svelte__internal; +function tu(i) { + let e, t; + return { + c() { + e = Yc("div"), t = eu( + /*value*/ + i[0] + ), Zc(e, "class", "svelte-1gecy8w"), nt( + e, + "table", + /*type*/ + i[1] === "table" + ), nt( + e, + "gallery", + /*type*/ + i[1] === "gallery" + ), nt( + e, + "selected", + /*selected*/ + i[2] + ); + }, + m(n, o) { + Qc(n, e, o), Xc(e, t); + }, + p(n, [o]) { + o & /*value*/ + 1 && $c( + t, + /*value*/ + n[0] + ), o & /*type*/ + 2 && nt( + e, + "table", + /*type*/ + n[1] === "table" + ), o & /*type*/ + 2 && nt( + e, + "gallery", + /*type*/ + n[1] === "gallery" + ), o & /*selected*/ + 4 && nt( + e, + "selected", + /*selected*/ + n[2] + ); + }, + i: Yi, + o: Yi, + d(n) { + n && Jc(e); + } + }; +} +function nu(i, e, t) { + let { value: n } = e, { type: o } = e, { selected: r = !1 } = e; + return i.$$set = (s) => { + "value" in s && t(0, n = s.value), "type" in s && t(1, o = s.type), "selected" in s && t(2, r = s.selected); + }, [n, o, r]; +} +class _u extends Gc { + constructor(e) { + super(), Kc(this, e, nu, tu, xc, { value: 0, type: 1, selected: 2 }); + } +} export { - s as BaseExample, - t as BaseInteractiveAudio, - i as BasePlayer, - o as BaseStaticAudio, - r as default + _u as BaseExample, + Ca as BaseInteractiveAudio, + hu as BasePlayer, + ll as BaseStaticAudio, + du as default };