import{r as s,c as t,h as i,g as e}from"./p-811c9fd4.js";import{a,d as h}from"./p-f021dfd0.js";import"./p-8ffe7be8.js";import{e as r,p as n}from"./p-dbd3a850.js";import{L as o}from"./p-e056694f.js";let c=0;const d=new Set,l=class{constructor(i){s(this,i),this.vEmbedSrcChange=t(this,"vEmbedSrcChange",3),this.vEmbedMessage=t(this,"vEmbedMessage",3),this.vEmbedLoaded=t(this,"vEmbedLoaded",3),this.srcWithParams="",this.hasEnteredViewport=!1,this.embedSrc="",this.mediaTitle="",this.params="",this.preconnections=[]}srcChange(){this.srcWithParams=r(this.embedSrc,this.params)}srcWithParamsChange(){this.hasEnteredViewport||d.has(this.embedSrc)||n(this.srcWithParams)&&d.add(this.embedSrc),this.vEmbedSrcChange.emit(this.srcWithParams)}preconnectionsChange(){this.hasEnteredViewport||this.preconnections.filter((s=>!d.has(s))).forEach((s=>{n(s)&&d.add(s)}))}connectedCallback(){this.lazyLoader=new o(this.el,["data-src"],(s=>{const t=s.getAttribute("data-src");s.removeAttribute("src"),a(t)||s.setAttribute("src",t)})),this.srcChange(),this.genIframeId()}disconnectedCallback(){this.lazyLoader.destroy()}onWindowMessage(s){var t,i,e;if(s.source!==(null===(t=this.iframe)||void 0===t?void 0:t.contentWindow)||h(this.origin)&&this.origin!==s.origin)return;const a=null!==(e=null===(i=this.decoder)||void 0===i?void 0:i.call(this,s.data))&&void 0!==e?e:s.data;a&&this.vEmbedMessage.emit(a)}async postMessage(s,t){var i,e;null===(e=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===e||e.postMessage(JSON.stringify(s),null!=t?t:"*")}onLoad(){this.vEmbedLoaded.emit()}genIframeId(){c+=1,this.id="vime-iframe-"+c}render(){return i("iframe",{id:this.id,class:"lazy",title:this.mediaTitle,"data-src":this.srcWithParams,allowfullscreen:"1",allow:"autoplay; encrypted-media; picture-in-picture",onLoad:this.onLoad.bind(this),ref:s=>{this.iframe=s}})}get el(){return e(this)}static get watchers(){return{embedSrc:["srcChange"],params:["srcChange"],srcWithParams:["srcWithParamsChange"],preconnections:["preconnectionsChange"]}}};l.style="vime-embed>iframe{position:absolute;top:0;left:0;border:0;width:100%;height:100%;user-select:none;z-index:var(--vm-media-z-index)}";export{l as vime_embed}