UNPKG

2.76 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@vue/composition-api")):"function"==typeof define&&define.amd?define(["@vue/composition-api"],t):(e=e||self).VPip=t(e.vueCompositionApi)}(this,(function(e){"use strict";const t=e.defineComponent({name:"VPip",props:{videoOptions:{type:Object,required:!1,default:function(){return{wrapper:"",src:"",poster:"",class:"",height:"100%",width:"100%"}}},buttonOptions:{type:Object,required:!1,default:function(){return{wrapper:"",type:"button",class:"",label:"Toggle picture-in-picture"}}},wrapper:{type:String,default:"",required:!1}},setup(t,n){var i=n.emit,o=e.ref(null),r=e.ref(!1);e.onMounted((function(){r.value="pictureInPictureEnabled"in document,o.value.addEventListener("enterpictureinpicture",(function(){i("video-in-pip",!0)})),o.value.addEventListener("leavepictureinpicture",(function(){i("video-in-pip",!1)}))})),e.onBeforeUnmount((function(){o.value.removeEventListener("enterpictureinpicture"),o.value.removeEventListener("leavepictureinpicture")}));return{video:o,isPipSupported:r,togglePip:function(){document.pictureInPictureElement?document.exitPictureInPicture().catch((function(e){i("exiting-pip-failure",e)})):o.value.requestPictureInPicture().catch((function(e){i("requesting-pip-failure",e)}))}}}});var n=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{class:e.wrapper},[n("div",{class:e.videoOptions.wrapper},[n("video",{ref:"video",class:e.videoOptions.class,attrs:{src:e.videoOptions.src,poster:e.videoOptions.poster,height:e.videoOptions.height,width:e.videoOptions.width,controls:""}})]),e._v(" "),n("div",{class:e.buttonOptions.wrapper},[e.isPipSupported?n("button",{class:e.buttonOptions.class,attrs:{type:e.buttonOptions.type},on:{click:e.togglePip}},[e._v("\n "+e._s(e.buttonOptions.label)+"\n ")]):e._e()])])};n._withStripped=!0;return function(e,t,n,i,o,r,s,p,u,c){"boolean"!=typeof s&&(u=p,p=s,s=!1);const d="function"==typeof n?n.options:n;let a;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,o&&(d.functional=!0)),i&&(d._scopeId=i),r?(a=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,u(e)),e&&e._registeredComponents&&e._registeredComponents.add(r)},d._ssrRegister=a):t&&(a=s?function(e){t.call(this,c(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,p(e))}),a)if(d.functional){const e=d.render;d.render=function(t,n){return a.call(n),e(t,n)}}else{const e=d.beforeCreate;d.beforeCreate=e?[].concat(e,a):[a]}return n}({render:n,staticRenderFns:[]},void 0,t,void 0,!1,void 0,!1,void 0,void 0,void 0)}));