/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/vpaid-html5-client@0.1.14/js/VPAIDHTML5Client.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var utils=require("./utils"),unique=utils.unique("vpaidIframe"),VPAIDAdUnit=require("./VPAIDAdUnit"),defaultTemplate='<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"></head><body style="margin:0;padding:0"><div class="ad-element"></div><script type="text/javascript" src="{{iframeURL_JS}}"><\/script><script type="text/javascript">window.parent.postMessage(\'{"event": "ready", "id": "{{iframeID}}"}\', \'{{origin}}\');<\/script></body></html>',AD_STOPPED="AdStopped";function VPAIDHTML5Client(t,e,i,n){i=i||{},this._id=unique(),this._destroyed=!1,this._frameContainer=utils.createElementInEl(t,"div"),this._videoEl=e,this._vpaidOptions=n||{timeout:1e4},this._templateConfig={template:i.template||defaultTemplate,extraOptions:i.extraOptions||{}}}function $removeEl(t){var e=this[t];e&&(e.remove(),delete this[t])}function $adDestroyed(){$removeAdElements.call(this),delete this._adUnit}function $unloadPreviousAdUnit(){$removeAdElements.call(this),$destroyAdUnit.call(this)}function $removeAdElements(){$removeEl.call(this,"_frame"),$destroyLoadListener.call(this)}function $destroyLoadListener(){this._onLoad&&(window.removeEventListener("message",this._onLoad),utils.clearCallbackTimeout(this._onLoad),delete this._onLoad)}function $destroyAdUnit(){this._adUnit&&(this._adUnit.stopAd(),delete this._adUnit)}function $throwIfDestroyed(){if(this._destroyed)throw new Error("VPAIDHTML5Client already destroyed!")}function getOrigin(){return window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"")}VPAIDHTML5Client.prototype.destroy=function(){this._destroyed||(this._destroyed=!0,$unloadPreviousAdUnit.call(this))},VPAIDHTML5Client.prototype.isDestroyed=function(){return this._destroyed},VPAIDHTML5Client.prototype.loadAdUnit=function(t,e){$throwIfDestroyed.call(this),$unloadPreviousAdUnit.call(this);var i=this,n=utils.createIframeWithContent(this._frameContainer,this._templateConfig.template,utils.extend({iframeURL_JS:t,iframeID:this.getID(),origin:getOrigin()},this._templateConfig.extraOptions));this._frame=n,this._onLoad=utils.callbackTimeout(this._vpaidOptions.timeout,function(t){if(t.origin!==getOrigin())return;var n,o,a;if(JSON.parse(t.data).id!==i.getID())return;i._frame.contentWindow?(a=i._frame.contentWindow.getVPAIDAd,o=utils.validate("function"==typeof a,"the ad didn't return a function to create an ad")):o="the iframe is not anymore in the DOM tree";if(!o){var d=i._frame.contentWindow.document.querySelector(".ad-element");(n=new VPAIDAdUnit(a(),d,i._videoEl,i._frame)).subscribe(AD_STOPPED,$adDestroyed.bind(i)),o=utils.validate(n.isValidVPAIDAd(),"the add is not fully complaint with VPAID specification")}return i._adUnit=n,$destroyLoadListener.call(i),e(o,o?null:n),!0}.bind(this),function(){e("timeout",null)}.bind(this)),window.addEventListener("message",this._onLoad)},VPAIDHTML5Client.prototype.unloadAdUnit=function(){$unloadPreviousAdUnit.call(this)},VPAIDHTML5Client.prototype.getID=function(){return this._id},module.exports=VPAIDHTML5Client;
//# sourceMappingURL=/sm/a9b53f8194e84634c6bef9b9076c7e01144166dd72e9ecf333049523ced98872.map