/*!
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"),a=require("../../plugin/basePlugin.js");function o(e){e.preventDefault(),e.returnValue=!1}function s(e){var t=e.tagName;return!("INPUT"!==t&&"TEXTAREA"!==t&&!e.isContentEditable)}require("../../../../../_virtual/delegate.js");var r=function(a){e.inherits(n,a);var r=e.createSuper(n);function n(){var t;e.classCallCheck(this,n);for(var i=arguments.length,a=new Array(i),o=0;o<i;o++)a[o]=arguments[o];return t=r.call.apply(r,[this].concat(a)),e.defineProperty(e.assertThisInitialized(t),"onBodyKeyDown",function(i){if(t.player){var a=i||window.event,o=a.keyCode,r=e.assertThisInitialized(t),n=r._keyState,l=r.player,y=t.config,u=y.disable,c=y.disableBodyTrigger,p=y.isIgnoreUserActive;u||c||!l.isUserActive&&!p||s(a.target)||!t.checkIsVisible()||a.metaKey||a.altKey||a.ctrlKey?n.isBodyKeyDown=!1:(i.repeat||n.isKeyDown||((a.target===document.body||t.config.isGlobalTrigger&&!s(a.target))&&t.checkCode(o,!0)&&(n.isBodyKeyDown=!0),document.addEventListener("keyup",t.onBodyKeyUp)),n.isBodyKeyDown&&t.handleKeyDown(a))}}),e.defineProperty(e.assertThisInitialized(t),"onBodyKeyUp",function(e){t.player&&(document.removeEventListener("keyup",t.onBodyKeyUp),t.handleKeyUp(e))}),e.defineProperty(e.assertThisInitialized(t),"onKeydown",function(i){if(t.player){var a=i||window.event,o=e.assertThisInitialized(t)._keyState;if(!a.repeat){if(t.config.disable||t.config.disableRootTrigger||a.metaKey||a.altKey||a.ctrlKey)return;!a||37!==a.keyCode&&!t.checkCode(a.keyCode)||a.target!==t.player.root&&a.target!==t.player.video&&a.target!==t.player.controls.el||(o.isKeyDown=!0),t.player.root.addEventListener("keyup",t.onKeyup)}o.isKeyDown&&t.handleKeyDown(a)}}),e.defineProperty(e.assertThisInitialized(t),"onKeyup",function(e){t.player&&(t.player.root.removeEventListener("keyup",t.onKeyup),t.handleKeyUp(e))}),t}return e.createClass(n,[{key:"mergekeyCodeMap",value:function(){var e=this,t=this.config.keyCodeMap;t&&Object.keys(t).map(function(i){e.keyCodeMap[i]?["keyCode","action","disable","pressAction","disablePress","isBodyTarget"].map(function(a){t[i][a]&&(e.keyCodeMap[i][a]=t[i][a])}):e.keyCodeMap[i]=t[i]})}},{key:"afterCreate",value:function(){this.config.disable=!this.playerConfig.keyShortcut;var e="function"==typeof this.config.seekStep?this.config.seekStep(this.player):this.config.seekStep;e&&"number"==typeof e&&(this.seekStep=e),this.keyCodeMap={space:{keyCode:32,action:"playPause",disable:!1,disablePress:!1,noBodyTarget:!1},up:{keyCode:38,action:"upVolume",disable:!1,disablePress:!1,noBodyTarget:!0},down:{keyCode:40,action:"downVolume",disable:!1,disablePress:!1,noBodyTarget:!0},left:{keyCode:37,action:"seekBack",disablePress:!1,disable:!1},right:{keyCode:39,action:"seek",pressAction:"changePlaybackRate",disablePress:!1,disable:!1},esc:{keyCode:27,action:"exitFullscreen",disablePress:!0,disable:!1}},this.mergekeyCodeMap(),this._keyState={isKeyDown:!1,isBodyKeyDown:!1,isPress:!1,tt:0,playbackRate:0},this.player.root.addEventListener("keydown",this.onKeydown),document.addEventListener("keydown",this.onBodyKeyDown)}},{key:"setConfig",value:function(e){var t=this;Object.keys(e).forEach(function(i){t.config[i]=e[i]})}},{key:"checkIsVisible",value:function(){if(!this.config.checkVisible)return!0;var e=this.player.root.getBoundingClientRect(),t=e.height,i=e.top,a=e.bottom,o=window.innerHeight;return!(i<0&&i<0-.9*t||a>0&&a-o>.9*t)}},{key:"checkCode",value:function(e,t){var i=this,a=!1;return Object.keys(this.keyCodeMap).map(function(o){i.keyCodeMap[o]&&e===i.keyCodeMap[o].keyCode&&!i.keyCodeMap[o].disable&&(a=!t||t&&!i.keyCodeMap[o].noBodyTarget)}),a}},{key:"downVolume",value:function(e){var t=this.player;if(!(t.volume<=0)){var i=parseFloat((t.volume-.1).toFixed(1)),a={volume:{from:t.volume,to:i}};this.emitUserAction(e,"change_volume",{props:a}),t.volume=i>=0?i:0}}},{key:"upVolume",value:function(e){var t=this.player;if(!(t.volume>=1)){var i=parseFloat((t.volume+.1).toFixed(1)),a={volume:{from:t.volume,to:i}};this.emitUserAction(e,"change_volume",{props:a}),t.volume=i<=1?i:1}}},{key:"seek",value:function(e){var i=this.player,a=i.currentTime,o=i.offsetCurrentTime,s=i.duration,r=i.offsetDuration,n=i.timeSegments,l=o>-1?o:a,y=r||s,u=e.repeat&&this.seekStep>=4?parseInt(this.seekStep/2,10):this.seekStep;l+u<=y?l+=u:l=y;var c=t.default.getCurrentTimeByOffset(l,n),p={currentTime:{from:a,to:c}};this.emitUserAction(e,"seek",{props:p}),this.player.currentTime=c}},{key:"seekBack",value:function(e){var i=this.player,a=i.currentTime,o=i.offsetCurrentTime,s=i.timeSegments,r=(o>-1?o:a)-(e.repeat?parseInt(this.seekStep/2,10):this.seekStep);r<0&&(r=0);var n={currentTime:{from:a,to:r=t.default.getCurrentTimeByOffset(r,s)}};this.emitUserAction(e,"seek",{props:n}),this.player.currentTime=r}},{key:"changePlaybackRate",value:function(e){var t=this._keyState,i=this.config,a=this.player;0===t.playbackRate&&(t.playbackRate=a.playbackRate,a.playbackRate=i.playbackRate)}},{key:"playPause",value:function(e){var t=this.player;t&&(this.emitUserAction(e,"switch_play_pause"),t.paused?t.play():t.pause())}},{key:"exitFullscreen",value:function(e){var t=this.player,i=t.fullscreen,a=t.cssfullscreen;i&&(this.emitUserAction("keyup","switch_fullscreen",{prop:"fullscreen",from:i,to:!i}),t.exitFullscreen()),a&&(this.emitUserAction("keyup","switch_css_fullscreen",{prop:"cssfullscreen",from:a,to:!a}),t.exitCssFullscreen())}},{key:"handleKeyDown",value:function(e){var t=this._keyState;if(e.repeat){t.isPress=!0;var i=Date.now();if(i-t.tt<200)return;t.tt=i}this.handleKeyCode(e.keyCode,e,t.isPress)}},{key:"handleKeyUp",value:function(e){var t=this._keyState;t.playbackRate>0&&(this.player.playbackRate=t.playbackRate,t.playbackRate=0),t.isKeyDown=!1,t.isPress=!1,t.tt=0}},{key:"handleKeyCode",value:function(t,a,s){for(var r=Object.keys(this.keyCodeMap),n=0;n<r.length;n++){var l=this.keyCodeMap[r[n]],y=l.action,u=l.keyCode,c=l.disable,p=l.pressAction,d=l.disablePress;if(u===t){if(!(c||s&&d)){var k=s&&p||y;"function"==typeof k?y(a,this.player,s):"string"==typeof k&&"function"==typeof this[k]&&this[k](a,this.player,s),this.emit(i.SHORTCUT,e.objectSpread2({key:r[n],target:a.target,isPress:s},this.keyCodeMap[r[n]]))}o(a),a.stopPropagation();break}}}},{key:"destroy",value:function(){this.player.root.removeEventListener("keydown",this.onKeydown),document.removeEventListener("keydown",this.onBodyKeyDown),this.player.root.removeEventListener("keyup",this.onKeyup),document.removeEventListener("keyup",this.onBodyKeyUp)}},{key:"disable",value:function(){this.config.disable=!0}},{key:"enable",value:function(){this.config.disable=!1}}],[{key:"pluginName",get:function(){return"keyboard"}},{key:"defaultConfig",get:function(){return{seekStep:10,checkVisible:!1,disableBodyTrigger:!1,disableRootTrigger:!1,isGlobalTrigger:!0,keyCodeMap:{},disable:!1,playbackRate:2,isIgnoreUserActive:!0}}}]),n}(a.default);exports.default=r;