/*!
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
*/
import{inherits as e,createSuper as t,classCallCheck as i,defineProperty as o,assertThisInitialized as a,createClass as s,objectSpread2 as n}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"../../utils/util.js";import{SHORTCUT as y}from"../../events.js";import l from"../../plugin/basePlugin.js";import"../../../../../_virtual/delegate.js";function c(e){e.preventDefault(),e.returnValue=!1}function p(e){var t=e.tagName;return!("INPUT"!==t&&"TEXTAREA"!==t&&!e.isContentEditable)}var u=/* @__PURE__ */function(){e(d,l);var u=t(d);function d(){var e;i(this,d);for(var t=arguments.length,s=new Array(t),n=0;n<t;n++)s[n]=arguments[n];return e=u.call.apply(u,[this].concat(s)),o(a(e),"onBodyKeyDown",function(t){if(e.player){var i=t||window.event,o=i.keyCode,s=a(e),n=s._keyState,r=s.player,y=e.config,l=y.disable,c=y.disableBodyTrigger,u=y.isIgnoreUserActive;l||c||!r.isUserActive&&!u||p(i.target)||!e.checkIsVisible()||i.metaKey||i.altKey||i.ctrlKey?n.isBodyKeyDown=!1:(t.repeat||n.isKeyDown||((i.target===document.body||e.config.isGlobalTrigger&&!p(i.target))&&e.checkCode(o,!0)&&(n.isBodyKeyDown=!0),document.addEventListener("keyup",e.onBodyKeyUp)),n.isBodyKeyDown&&e.handleKeyDown(i))}}),o(a(e),"onBodyKeyUp",function(t){e.player&&(document.removeEventListener("keyup",e.onBodyKeyUp),e.handleKeyUp(t))}),o(a(e),"onKeydown",function(t){if(e.player){var i=t||window.event,o=a(e)._keyState;if(!i.repeat){if(e.config.disable||e.config.disableRootTrigger||i.metaKey||i.altKey||i.ctrlKey)return;!i||37!==i.keyCode&&!e.checkCode(i.keyCode)||i.target!==e.player.root&&i.target!==e.player.video&&i.target!==e.player.controls.el||(o.isKeyDown=!0),e.player.root.addEventListener("keyup",e.onKeyup)}o.isKeyDown&&e.handleKeyDown(i)}}),o(a(e),"onKeyup",function(t){e.player&&(e.player.root.removeEventListener("keyup",e.onKeyup),e.handleKeyUp(t))}),e}return s(d,[{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(o){t[i][o]&&(e.keyCodeMap[i][o]=t[i][o])}):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,o=e.bottom,a=window.innerHeight;return!(i<0&&i<0-.9*t||o>0&&o-a>.9*t)}},{key:"checkCode",value:function(e,t){var i=this,o=!1;return Object.keys(this.keyCodeMap).map(function(a){i.keyCodeMap[a]&&e===i.keyCodeMap[a].keyCode&&!i.keyCodeMap[a].disable&&(o=!t||t&&!i.keyCodeMap[a].noBodyTarget)}),o}},{key:"downVolume",value:function(e){var t=this.player;if(!(t.volume<=0)){var i=parseFloat((t.volume-.1).toFixed(1)),o={volume:{from:t.volume,to:i}};this.emitUserAction(e,"change_volume",{props:o}),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)),o={volume:{from:t.volume,to:i}};this.emitUserAction(e,"change_volume",{props:o}),t.volume=i<=1?i:1}}},{key:"seek",value:function(e){var t=this.player,i=t.currentTime,o=t.offsetCurrentTime,a=t.duration,s=t.offsetDuration,n=t.timeSegments,y=o>-1?o:i,l=s||a,c=e.repeat&&this.seekStep>=4?parseInt(this.seekStep/2,10):this.seekStep;y+c<=l?y+=c:y=l;var p=r.getCurrentTimeByOffset(y,n),u={currentTime:{from:i,to:p}};this.emitUserAction(e,"seek",{props:u}),this.player.currentTime=p}},{key:"seekBack",value:function(e){var t=this.player,i=t.currentTime,o=t.offsetCurrentTime,a=t.timeSegments,s=(o>-1?o:i)-(e.repeat?parseInt(this.seekStep/2,10):this.seekStep);s<0&&(s=0);var n={currentTime:{from:i,to:s=r.getCurrentTimeByOffset(s,a)}};this.emitUserAction(e,"seek",{props:n}),this.player.currentTime=s}},{key:"changePlaybackRate",value:function(e){var t=this._keyState,i=this.config,o=this.player;0===t.playbackRate&&(t.playbackRate=o.playbackRate,o.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,o=t.cssfullscreen;i&&(this.emitUserAction("keyup","switch_fullscreen",{prop:"fullscreen",from:i,to:!i}),t.exitFullscreen()),o&&(this.emitUserAction("keyup","switch_css_fullscreen",{prop:"cssfullscreen",from:o,to:!o}),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(e,t,i){for(var o=Object.keys(this.keyCodeMap),a=0;a<o.length;a++){var s=this.keyCodeMap[o[a]],r=s.action,l=s.keyCode,p=s.disable,u=s.pressAction,d=s.disablePress;if(l===e){if(!(p||i&&d)){var k=i&&u||r;"function"==typeof k?r(t,this.player,i):"string"==typeof k&&"function"==typeof this[k]&&this[k](t,this.player,i),this.emit(y,n({key:o[a],target:t.target,isPress:i},this.keyCodeMap[o[a]]))}c(t),t.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}}}]),d}();export{u as default};