media-trimmer
Version:
A simple MP4 video trimmer using the WebCodecs API
3 lines (2 loc) • 1.3 kB
JavaScript
import{createEffectScope as t,ref as s}from"fine-jsx";import{H as e,r as i,V as r,t as o}from"./VideoTrimmerUI-DU4OMfli.js";const a=["source","start","end","mute"];class n extends e{static observedAttributes=a;#t=t();#s=s("");#e=s();#i;#r;#o=!1;get source(){return this.#s.value}set source(t){this.#s.value=t}get state(){return this.#e.value}set state(t){this.#e.value=t}attributeChangedCallback(t,s,e){"start"===t||"end"===t||"mute"===t?this.state={start:0,end:0,mute:!1,...this.state,[t]:e}:"source"===t&&(this[t]=e)}connectedCallback(){clearTimeout(this.#r),this.#i||(this.#i=this.#t.run((()=>i(r,{source:this.#s,state:this.#e,onChange:t=>this.#a("change",t),onError:t=>this.#a("error",t),onLoad:t=>this.#a("load",t)},this))))}disconnectedCallback(){this.#r=setTimeout((()=>{this.#i?.(),this.#i=void 0}),500)}async toBlob(){const{state:t,source:s}=this;if(this.#o)throw new Error("[media-trimmer] Trim is already in progress.");if(!s)throw new Error("[media-trimmer]: Can't export without source.");return this.#o=!0,!t||t.isFullDuration?await fetch(s).then((t=>t.blob())):await o(s,{...t,onProgress:t=>this.#a("progress",{progress:t})}).finally((()=>this.#o=!1))}#a(t,s){this.dispatchEvent(new CustomEvent(t,{detail:s}))}}export{n as M};
//# sourceMappingURL=MediaTrimmerElement-CItOT7nG.js.map