/*!
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("../../events.js"),n=require("../../plugin/plugin.js"),o=require("../common/iconTools.js"),r=require("../common/iconPlugin.js"),a=require("../assets/pipIcon.js"),c=require("../assets/pipIconExit.js");var s="picture-in-picture",l="inline",u="fullscreen",p=function(r){e.inherits(d,r);var p=e.createSuper(d);function d(){var t;e.classCallCheck(this,d);for(var i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return t=p.call.apply(p,[this].concat(n)),e.defineProperty(e.assertThisInitialized(t),"switchPIP",function(e){if(!t.isPIPAvailable())return!1;e.stopPropagation&&e.stopPropagation(),t.isPip?(t.exitPIP(),t.emitUserAction(e,"change_pip",{props:"pip",from:!0,to:!1}),t.setAttr("data-state","normal")):4===t.player.media.readyState&&(t.requestPIP(),t.emitUserAction(e,"change_pip",{props:"pip",from:!1,to:!0}),t.setAttr("data-state","pip"))}),t}return e.createClass(d,[{key:"beforeCreate",value:function(e){"boolean"==typeof e.player.config.pip&&(e.config.showIcon=e.player.config.pip)}},{key:"afterCreate",value:function(){var n=this;this.isPIPAvailable()&&(e.get(e.getPrototypeOf(d.prototype),"afterCreate",this).call(this),this.pMode=l,this.initPipEvents(),this.config.showIcon&&this.initIcons(),this.once(i.COMPLETE,function(){n.config.showIcon&&(t.default.removeClass(n.find(".xgplayer-icon"),"xg-icon-disable"),n.bind("click",n.switchPIP))}))}},{key:"registerIcons",value:function(){return{pipIcon:{icon:a.default,class:"xg-get-pip"},pipIconExit:{icon:c.default,class:"xg-exit-pip"}}}},{key:"initIcons",value:function(){var e=this.icons;this.appendChild(".xgplayer-icon",e.pipIcon),this.appendChild(".xgplayer-icon",e.pipIconExit)}},{key:"initPipEvents",value:function(){var e=this,n=this.player;this.leavePIPCallback=function(){var o=n.paused;t.default.setTimeout(e,function(){!o&&n.mediaPlay()},0),!o&&n.mediaPlay(),e.setAttr("data-state","normal"),e.pipWindow=null,n.emit(i.PIP_CHANGE,!1)},this.enterPIPCallback=function(t){n.emit(i.PIP_CHANGE,!0),null!=t&&t.pictureInPictureWindow&&(e.pipWindow=t.pictureInPictureWindow),e.setAttr("data-state","pip")},this.onWebkitpresentationmodechanged=function(t){var i=n.media.webkitPresentationMode;e.pMode===u&&i!==u&&n.onFullscreenChange(null,!1),e.pMode=i,i===s?e.enterPIPCallback(t):i===l&&e.leavePIPCallback(t)},n.media&&(n.media.addEventListener("enterpictureinpicture",this.enterPIPCallback),n.media.addEventListener("leavepictureinpicture",this.leavePIPCallback),d.checkWebkitSetPresentationMode(n.media)&&n.media.addEventListener("webkitpresentationmodechanged",this.onWebkitpresentationmodechanged))}},{key:"copyStyleIntoPiPWindow",value:function(t){var i=e.toConsumableArray(document.styleSheets).map(function(i){try{return e.toConsumableArray(i.cssRules).map(function(e){return e.cssText}).join("")}catch(o){var n=document.createElement("link");n.rel="stylesheet",n.type=i.type,n.media=i.media,n.href=i.href,t.document.head.appendChild(n)}return""}).filter(Boolean).join("\n"),n=document.createElement("style");n.textContent=i,t.document.head.appendChild(n)}},{key:"requestPIP",value:function(){var e=this,i=this.player,n=this.playerConfig,o=this.config;if(this.isPIPAvailable()&&!this.isPip)try{var r=n.poster;if(r&&(i.media.poster="String"===t.default.typeOf(r)?r:r.poster),o.preferDocument&&this.isDocPIPAvailable()){var a={};if(o.width&&o.height)a.width=o.width,a.height=o.height;else{var c=i.root.getBoundingClientRect();a.width=c.width,a.height=c.height}documentPictureInPicture.requestWindow(a).then(function(t){var n=o.docPiPNode,r=o.docPiPStyle;e.enterPIPCallback();var a=n||i.root,c=a.parentElement,s=a.previousSibling,l=a.nextSibling;e.copyStyleIntoPiPWindow(t);var u=document.createElement("style");if(u.append("body{padding:0; margin:0;}"),r){var p="";"string"==typeof r?p=r:"function"==typeof r&&(p=r.call(o)),p&&u.append(p)}else a===i.root&&u.append("\n              .xgplayer{width: 100%!important; height: 100%!important;}\n            ");t.document.head.append(u),t.document.body.append(a),t.addEventListener("pagehide",function(t){c&&(l?c.insertBefore(a,l):s?c.insertBefore(a,s.nextSibling):c.appendChild(a)),e.leavePIPCallback()},{once:!0})})}else d.checkWebkitSetPresentationMode(i.media)?i.media.webkitSetPresentationMode("picture-in-picture"):i.media.requestPictureInPicture();return!0}catch(s){return console.error("requestPiP",s),!1}}},{key:"exitPIP",value:function(){var e=this.player;try{var t;if(this.isPIPAvailable()&&this.isPip)this.isDocPIPAvailable()&&null!==(t=documentPictureInPicture)&&void 0!==t&&t.window?documentPictureInPicture.window.close():d.checkWebkitSetPresentationMode(e.media)?e.media.webkitSetPresentationMode("inline"):document.exitPictureInPicture();return!0}catch(i){return console.error("exitPIP",i),!1}}},{key:"isPip",get:function(){var e,t=this.player;return!(!this.isDocPIPAvailable()||null===(e=documentPictureInPicture)||void 0===e||!e.window)||document.pictureInPictureElement&&document.pictureInPictureElement===t.media||t.media.webkitPresentationMode===s}},{key:"isPIPAvailable",value:function(){var e=this.player.media;return"Boolean"===t.default.typeOf(document.pictureInPictureEnabled)&&document.pictureInPictureEnabled&&("Boolean"===t.default.typeOf(e.disablePictureInPicture)&&!e.disablePictureInPicture||e.webkitSupportsPresentationMode&&"Function"===t.default.typeOf(e.webkitSetPresentationMode))||this.isDocPIPAvailable()}},{key:"isDocPIPAvailable",value:function(){return"documentPictureInPicture"in window&&/^(https|file)/.test(location.protocol)}},{key:"destroy",value:function(){e.get(e.getPrototypeOf(d.prototype),"destroy",this).call(this);var t=this.player;t.media.removeEventListener("enterpictureinpicture",this.enterPIPCallback),t.media.removeEventListener("leavepictureinpicture",this.leavePIPCallback),d.checkWebkitSetPresentationMode(t.media)&&t.media.removeEventListener("webkitpresentationmodechanged",this.onWebkitpresentationmodechanged),this.exitPIP(),this.unbind("click",this.btnClick)}},{key:"render",value:function(){if(this.config.showIcon&&this.isPIPAvailable())return'<xg-icon class="xgplayer-pip">\n      <div class="xgplayer-icon xg-icon-disable">\n      </div>\n      '.concat(o.xgIconTips(this,"PIP",this.playerConfig.isHideTips),"\n    </xg-icon>")}}],[{key:"pluginName",get:function(){return"pip"}},{key:"defaultConfig",get:function(){return{position:n.POSITIONS.CONTROLS_RIGHT,index:6,showIcon:!1,preferDocument:!1,width:void 0,height:void 0,docPiPNode:void 0,docPiPStyle:void 0}}},{key:"checkWebkitSetPresentationMode",value:function(e){return"function"==typeof e.webkitSetPresentationMode}}]),d}(r.default);exports.default=p;