UNPKG

filepond

Version:

FilePond, where files go to stretch their bits.

210 lines (209 loc) • 7.39 kB
/*! * FilePond v5.0.2 * Copyright (c) 2017-2026 Pqina B.V. * Released under the MIT License * https://filepond.com */ import { onDestroy as ye } from "../../../../vendor/svelte/src/index-client.js"; import { user_effect as S, template_effect as H } from "../../../../vendor/svelte/src/internal/client/reactivity/effects.js"; import { pop as _e, push as Pe } from "../../../../vendor/svelte/src/internal/client/context.js"; import { get as e, untrack as y } from "../../../../vendor/svelte/src/internal/client/runtime.js"; import { first_child as Ae, child as Y } from "../../../../vendor/svelte/src/internal/client/dom/operations.js"; import { state as o, set as i } from "../../../../vendor/svelte/src/internal/client/reactivity/sources.js"; import { noop as Ee } from "../../../../vendor/svelte/src/internal/shared/utils.js"; import { event as _ } from "../../../../vendor/svelte/src/internal/client/dom/elements/events.js"; import { comment as Le, append as k, from_html as J } from "../../../../vendor/svelte/src/internal/client/dom/template.js"; import { user_derived as a } from "../../../../vendor/svelte/src/internal/client/reactivity/deriveds.js"; import { if_block as Fe } from "../../../../vendor/svelte/src/internal/client/dom/blocks/if.js"; import { snippet as Oe } from "../../../../vendor/svelte/src/internal/client/dom/blocks/snippet.js"; import { clsx as ke } from "../../../../vendor/svelte/src/internal/shared/attributes.js"; import { set_class as Me } from "../../../../vendor/svelte/src/internal/client/dom/elements/class.js"; import { bind_this as Re } from "../../../../vendor/svelte/src/internal/client/dom/elements/bindings/this.js"; import { prop as c } from "../../../../vendor/svelte/src/internal/client/reactivity/props.js"; import { toTime as B } from "../../../../utils/date.js"; import { isIOS as Ve, isSafari as N, isNumber as z } from "../../../../utils/test.js"; import { videoHasAudioTrack as xe } from "../../../../utils/dom.js"; import "../MediaPane/index.js"; import { once as je } from "../../../common/event.js"; import { createObjectURL as Ie } from "../../../../utils/objectURL.js"; import { getAppContext as Te } from "../../contexts/appContext.js"; import { getEntryContext as De } from "../../contexts/entryContext.js"; import { Status as P } from "../../../../common/status.js"; import { supportsRequestVideoFrameCallback as G } from "../../../../utils/support.js"; import we from "../MediaPane/index-svelte.js"; var Ce = J('<video playsinline=""><!></video>', 2), Ue = J("<media-video><!></media-video>", 2); function pt(K, u) { Pe(u, !0); let Q = c(u, "class", 3, void 0), X = c(u, "overflowAmount", 3, void 0), Z = c(u, "enableParallax", 3, void 0), $ = c(u, "objectFit", 3, void 0), A = c(u, "mute", 7, !0), ee = c(u, "children", 3, void 0); const { setEntryExtensionState: l, pushTask: M } = Te(), n = De(), te = a(() => n.current), E = a(() => e(te).file), R = a(() => e(E) !== null), V = Ve() && N(), m = a(() => V ? void 0 : e(R) ? Ie(e(E)) : void 0), h = a(() => V && e(R) ? e(E) : void 0); let t = o(void 0), re = 1 / 24, p = o(0), f = o(null), x = o(null), s = o(!1), g = o(!1), j = o(!1); const I = a(() => B(e(p))), ie = a(() => z(e(f)) ? B(e(f)) : void 0), oe = a(() => z(e(f)) ? `${e(f)}S` : void 0); function ne() { e(t) && (e(t).paused ? e(t).play().then(() => { l(n.current, { status: { type: P.System, code: "MEDIA_PLAY_BUSY" } }); }).catch((r) => { l(n.current, { status: { type: P.Error, code: "MEDIA_PLAY_ERROR", values: { error: r } } }); }) : (e(t).pause(), l(n.current, { status: { type: P.System, code: "MEDIA_PLAY_PAUSED" } }))); } function ae() { e(t) && A(!e(t).muted); } function de() { e(t) && (e(g) ? (document.exitFullscreen(), i(g, !1)) : e(t).requestFullscreen().then(() => i(g, !0))); } function T(r) { if (e(t)) { if (e(t).seeking) { e(t).onseeked = () => { e(t).onseeked = null, T(r); }; return; } e(t).currentTime = r, i(p, r); } } let D = o(void 0), w = o(void 0), b = o(!1), L = o(!0); function ue() { i(L, !1), i(D, e(t).videoWidth), i(w, e(t).videoHeight), i(f, e(t).duration), xe(e(t)).then((r) => { i(x, !r); }), G() || i(b, !0); } function se() { i(s, !0); } function C() { i(s, !1); } let U; function le() { cancelAnimationFrame(U), N() && (e(t).currentTime = e(p)); const r = () => { e(s) && (i(p, e(t).currentTime), U = requestAnimationFrame(r)); }; r(); } S(() => { e(s) && y(le); }); function W() { const { error: r } = e(t); l(n.current, { status: { type: P.Error, code: "MEDIA_LOAD_ERROR", values: { error: r, fileMainType: "fileMainTypeVideo" } } }), i(j, !0); } function me() { if (e(t).srcObject != e(h)) try { e(t).srcObject = e(h), e(t).load(); } catch { W(); } } function fe(r) { return new Promise((v, F) => { r.addEventListener("loadeddata", v), r.addEventListener("error", F); }); } async function ce() { e(t).src !== e(m) && (e(t).src = e(m), await fe(e(t))); } S(() => { !e(t) || !(e(m) ?? e(h)) || (G() && e(t).requestVideoFrameCallback(() => { i(b, !0); }), y(() => { if (e(m)) { M(n.current.id, ce, { parallel: 1, ignoreSoftFailure: !1 }); return; } e(h) && M(n.current.id, me, { parallel: 1, ignoreSoftFailure: !1 }); })); }), S(() => { const r = { isMute: e(x), isMuted: A(), isPaused: !e(s), isPlaying: e(s), isFullscreen: e(g), timeLabel: e(I), timeISO: e(I), time: e(p), duration: e(f), durationLabel: e(ie), durationISO: e(oe), framesPerSecond: re }; y(() => { l(n.current, { video: r }); }); }), S(() => { const r = { isReady: !e(L), isVisible: e(b) }; y(() => { l(n.current, { media: r }); }); }), ye(() => { e(s) && C(), e(m) && URL.revokeObjectURL(e(m)); }); var pe = { togglePlayback: ne, toggleAudio: ae, toggleFullscreen: de, setCurrentTime: T }, q = Le(), ve = Ae(q); { var he = (r) => { var v = Ue(), F = Y(v); we(F, { get enableParallax() { return Z(); }, get overflowAmount() { return X(); }, mediaInitialOpacity: 0, mediaInitialScalar: 0, get mediaObjectFit() { return $(); }, get mediaWidth() { return e(D); }, get mediaHeight() { return e(w); }, get mediaVisible() { return e(b); }, get mediaLoading() { return e(L); }, children: (ge, We) => { var d = Ce(), be = a(() => je(ue)), Se = Y(d); Oe(Se, () => ee() ?? Ee), Re(d, (O) => i(t, O), () => e(t)), H(() => d.muted = A()), _("play", d, se), _("pause", d, C), _("error", d, W), _("loadeddata", d, function(...O) { e(be)?.apply(this, O); }), k(ge, d); }, $$slots: { default: !0 } }), H(() => Me(v, 1, ke(Q()))), k(r, v); }; Fe(ve, (r) => { e(j) || r(he); }); } return k(K, q), _e(pe); } export { pt as default };