/*!
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("../../events.js"),i=require("../../plugin/plugin.js");var n=function(n){e.inherits(o,n);var a=e.createSuper(o);function o(){return e.classCallCheck(this,o),a.apply(this,arguments)}return e.createClass(o,[{key:"beforeCreate",value:function(e){"boolean"==typeof e.player.config.screenShot&&(e.config.disable=!e.player.config.screenShot)}},{key:"afterCreate",value:function(){e.get(e.getPrototypeOf(o.prototype),"afterCreate",this).call(this),this.appendChild(".xgplayer-icon",this.icons.screenshotIcon);var i=this.config;this.initSize=function(e){i.fitVideo&&(i.width=e.vWidth,i.height=e.vHeight)},this.once(t.VIDEO_RESIZE,this.initSize)}},{key:"onPluginsReady",value:function(){this.show(),this.onClickBtn=this.onClickBtn.bind(this),this.bind(["click","touchend"],this.onClickBtn)}},{key:"saveScreenShot",value:function(e,t){var i,n=document.createElement("a");n.href=e,n.download=t;try{"undefined"!=typeof MouseEvent?i=new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}):(i=document.createEvent("MouseEvents")).initMouseEvent("click",!0,!1,window,0,0,0,0,0,!1,!1,!1,!1,0,null)}catch(a){console.error("MouseEvent unsupported",a)}i&&n.dispatchEvent(i)}},{key:"createCanvas",value:function(e,t){var i=document.createElement("canvas"),n=i.getContext("2d");this.canvasCtx=n,this.canvas=i,i.width=e||this.config.width,i.height=t||this.config.height,n.imageSmoothingEnabled=!0,n.imageSmoothingEnabled&&(n.imageSmoothingQuality="high")}},{key:"onClickBtn",value:function(e){var i=this;e.preventDefault(),e.stopPropagation(),this.emitUserAction(e,"shot");var n=this.config;this.shot(n.width,n.height).then(function(e){i.emit(t.SCREEN_SHOT,e),n.saveImg&&i.saveScreenShot(e,n.name+n.format)})}},{key:"shot",value:function(e,t){var i=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{quality:.92,type:"image/png"},a=this.config,o=this.player,s=n.quality||a.quality,c=n.type||a.type;return new Promise(function(n,h){var r,l=null;if(o.media.canvas)l=o.media.canvas;else{i.canvas?(i.canvas.width=e||a.width,i.canvas.height=t||a.height):i.createCanvas(e,t),l=i.canvas,r=i.canvasCtx;var u,d,g,v,f=o.media.videoWidth/o.media.videoHeight,p=l.width/l.height,y=o.media.videoWidth,m=o.media.videoHeight;f>p?(g=l.width,v=l.width/f,u=0,d=Math.round((l.height-v)/2)):f===p?(g=l.width,v=l.height,u=0,d=0):f<p&&(g=l.height*f,v=l.height,u=Math.round((l.width-g)/2),d=0),r.drawImage(o.media,0,0,y,m,u,d,g,v)}var S=l.toDataURL(c,s).replace(c,"image/octet-stream");n(S=S.replace(/^data:image\/[^;]+/,"data:application/octet-stream"))})}},{key:"registerIcons",value:function(){return{screenshotIcon:null}}},{key:"destroy",value:function(){e.get(e.getPrototypeOf(o.prototype),"destroy",this).call(this),this.unbind(["click","touchend"],this.onClickBtn),this.off(t.VIDEO_RESIZE,this.initSize)}},{key:"render",value:function(){if(!this.config.disable){var e=this.icons.screenshotIcon?"xgplayer-icon":"xgplayer-icon btn-text",t="SCREENSHOT";return'\n      <xg-icon class="xgplayer-shot">\n      <div class="'.concat(e,'">\n      ').concat(this.icons.screenshotIcon?"":'<span lang-key="'.concat(this.i18nKeys[t],'">').concat(this.i18n[t],"</span>"),"\n      </div>\n    </xg-icon>")}}}],[{key:"pluginName",get:function(){return"screenShot"}},{key:"defaultConfig",get:function(){return{position:i.POSITIONS.CONTROLS_RIGHT,index:5,quality:.92,type:"image/png",format:".png",width:600,height:337,saveImg:!0,fitVideo:!0,disable:!1,name:"screenshot"}}}]),o}(require("../common/iconPlugin.js").default);exports.default=n;