/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../../_virtual/_rollupPluginBabelHelpers.js"),t=require("../../utils/util.js"),i=require("../../utils/sniffer.js"),a=require("../../events.js"),n=require("../../utils/debug.js"),r=require("../../plugin/plugin.js");var s="realtime",o="firstframe",d="poster";var l=null,h=function(r){e.inherits(u,r);var h=e.createSuper(u);function u(){var i;e.classCallCheck(this,u);for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return i=h.call.apply(h,[this].concat(r)),e.defineProperty(e.assertThisInitialized(i),"onLoadedData",function(e){i.player&&(i._frameCount=i.config.startFrameCount,i.stop(),i.renderOnTimeupdate(e),i.off(a.TIME_UPDATE,i.renderOnTimeupdate),i.on(a.TIME_UPDATE,i.renderOnTimeupdate))}),e.defineProperty(e.assertThisInitialized(i),"onVisibilitychange",function(e){"visible"===document.visibilityState?i._checkIfCanStart()&&i.start():"hidden"===document.visibilityState&&i.stop()}),e.defineProperty(e.assertThisInitialized(i),"renderOnTimeupdate",function(e){if(i._frameCount>0)i.renderOnce(),i._frameCount--;else{i._isLoaded=!0,i.off(a.TIME_UPDATE,i.renderOnTimeupdate);var t=i.config.startInterval;!i.player.paused&&i._checkIfCanStart()&&i.start(0,t)}}),e.defineProperty(e.assertThisInitialized(i),"start",function(a,n){var r=i.player.video,o=function(){try{return parseInt(window.performance.now(),10)}catch(e){return(new Date).getTime()}}(),d=i.checkVideoIsSupport(r);d&&i.canvasCtx&&(n||(n=i.interval),i.stop(),r.videoWidth&&r.videoHeight&&(i.videoPI=r.videoHeight>0?parseInt(r.videoWidth/r.videoHeight*100,10):0,(i.config.mode===s||o-i.preTime>=n)&&(r&&r.videoWidth&&i.update(d,i.videoPI),i.preTime=o)),i.frameId="timer"===i._loopType?t.default.setTimeout(e.assertThisInitialized(i),i.start,n):t.default.requestAnimationFrame(i.start))}),e.defineProperty(e.assertThisInitialized(i),"stop",function(){i.frameId&&("timer"===i._loopType?t.default.clearTimeout(e.assertThisInitialized(i),i.frameId):t.default.cancelAnimationFrame(i.frameId),i.frameId=null)}),i}return e.createClass(u,[{key:"afterCreate",value:function(){var e=this;!0===this.playerConfig.dynamicBg&&(this.config.disable=!1),u.isSupport||(this.config.disable=!0);var t=this.config,i=t.disable,n=t.mode,r=t.frameRate;i||(this._pos={width:0,height:0,rwidth:0,rheight:0,x:0,y:0,pi:0},this.isStart=!1,this._isLoaded=!1,this.videoPI=0,this.preTime=0,this.interval=parseInt(1e3/r,10),this.canvas=null,this.canvasCtx=null,this._frameCount=0,this._loopType=this.config.mode!==s&&this.interval>=1e3?"timer":"animation",this.once(a.COMPLETE,function(){e.player&&(e.init(),e.renderByPoster(),e.player.paused||e.start())}),n!==d&&(n!==o&&(this.on(a.EMPTIED,function(){e.stop()}),this.on(a.PLAY,function(){var t=e.config.startInterval;e._checkIfCanStart()&&e.start(0,t)}),this.on(a.PAUSE,function(){e.stop()})),this.on(a.LOADED_DATA,this.onLoadedData),this.on(a.LOAD_START,function(){e._isLoaded=!1,e.stop()}),document.addEventListener("visibilitychange",this.onVisibilitychange)))}},{key:"setConfig",value:function(e){var t=this;Object.keys(e).forEach(function(i){"root"===i&&e[i]!==t.config[i]?t.reRender(e[i]):"frameRate"===i?t.interval=parseInt(1e3/e[i],10):"disable"===i&&e[i]&&t.stop(),t.config[i]=e[i]})}},{key:"init",value:function(e){var t=this.player,i=this.config;this.canvasFilter=u.supportCanvasFilter();try{var a=e||i.root;a||(a=i.isInnerRender&&t.innerContainer||t.root),a.insertAdjacentHTML("afterbegin",'<div class="xgplayer-dynamic-bg" data-index="'.concat(i.index,'"><canvas>\n        </canvas><xgmask></xgmask></div>')),this.root=a.children[0],this.canvas=this.find("canvas"),this.canvasFilter||(this.canvas.style.filter=i.filter,this.canvas.style.webkitFilter=i.filter),this.mask=this.find("xgmask"),i.addMask&&(this.mask.style.background=i.maskBg),this.canvasCtx=this.canvas.getContext("2d")}catch(r){n.default.logError("plugin:DynamicBg",r)}}},{key:"reRender",value:function(e){if(this.config.disable||this.root){this.stop();var t=this.root?this.root.parentElement:null;if(t!==e&&t.removeChild(this.root),e){this.init(e),this.renderOnce();var i=this.config.startInterval;this._checkIfCanStart()&&this.start(0,i)}else this.root=null}}},{key:"checkVideoIsSupport",value:function(e){if(!e)return null;var a=e&&e instanceof window.HTMLVideoElement?e:e.canvas?e.canvas:e.flyVideo?e.flyVideo:null;if(a&&("safari"!==i.default.browser||!t.default.isMSE(a)))return a;var n=a?a.tagName.toLowerCase():"";return"canvas"===n||"img"===n?a:null}},{key:"renderByPoster",value:function(){var e=this.playerConfig.poster;if(e){var i="String"===t.default.typeOf(e)?e:"String"===t.default.typeOf(e.poster)?e.poster:null;this.updateImg(i)}}},{key:"_checkIfCanStart",value:function(){var e=this.config.mode;return this._isLoaded&&!this.player.paused&&e!==o&&e!==d}},{key:"renderOnce",value:function(){var e=this.player.video;if(e.videoWidth&&e.videoHeight){this.videoPI=parseInt(e.videoWidth/e.videoHeight*100,10);var t=this.checkVideoIsSupport(e);t&&this.update(t,this.videoPI)}}},{key:"updateImg",value:function(e){var t=this;if(e){var i=this.canvas.getBoundingClientRect(),a=i.width,n=i.height,r=new window.Image;r.onload=function(){if(t.canvas&&!t.frameId&&!t.isStart){t.canvas.height=n,t.canvas.width=a;var e=parseInt(a/n*100,10);t.update(r,e),r=null}},r.src=e}}},{key:"update",value:function(e,t){if(this.canvas&&this.canvasCtx&&t)try{var i=this._pos,a=this.config,r=this.canvas.getBoundingClientRect(),s=r.width,o=r.height;if(s!==i.width||o!==i.height||i.pi!==t){var d=parseInt(s/o*100,10);i.pi=t,i.width!==s&&(i.width=this.canvas.width=s),i.height!==o&&(i.height=this.canvas.height=o);var l=o,h=s;d<t?h=parseInt(o*t/100,10):d>t&&(l=parseInt(100*s/t,10)),i.rwidth=h*a.multiple,i.rheight=l*a.multiple,i.x=(s-i.rwidth)/2,i.y=(o-i.rheight)/2}this.canvasFilter&&(this.canvasCtx.filter=a.filter),this.canvasCtx.drawImage(e,i.x,i.y,i.rwidth,i.rheight)}catch(u){n.default.logError("plugin:DynamicBg",u)}}},{key:"destroy",value:function(){this.stop(),document.removeEventListener("visibilitychange",this.onVisibilitychange),this.canvasCtx=null,this.canvas=null}},{key:"render",value:function(){return""}}],[{key:"pluginName",get:function(){return"dynamicBg"}},{key:"defaultConfig",get:function(){return{isInnerRender:!1,disable:!0,index:-1,mode:"framerate",frameRate:10,filter:"blur(50px)",startFrameCount:2,startInterval:0,addMask:!0,multiple:1.2,maskBg:"rgba(0,0,0,0.7)"}}},{key:"isSupport",get:function(){return"boolean"==typeof l?l:l=function(){try{return!!document.createElement("canvas").getContext}catch(e){return!1}}()}},{key:"supportCanvasFilter",value:function(){return!("safari"===i.default.browser||"firefox"===i.default.browser)}}]),u}(r.default);exports.default=h;