!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/x6")):"function"==typeof define&&define.amd?define(["exports","@antv/x6"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).X6PluginKeyboard={},t.X6)}(this,(function(t,e){"use strict";function n(t,e,n,r){var i,o=arguments.length,s=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(o<3?i(s):o>3?i(e,n,s):i(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s}var r={};!function(t){!function(e,n,r){if(e){for(var i,o={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},s={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},a={"~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},l={option:"alt",command:"meta",return:"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},c=1;c<20;++c)o[111+c]="f"+c;for(c=0;c<=9;++c)o[c+96]=c.toString();y.prototype.bind=function(t,e,n){var r=this;return t=t instanceof Array?t:[t],r._bindMultiple.call(r,t,e,n),r},y.prototype.unbind=function(t,e){return this.bind.call(this,t,(function(){}),e)},y.prototype.trigger=function(t,e){var n=this;return n._directMap[t+":"+e]&&n._directMap[t+":"+e]({},t),n},y.prototype.reset=function(){var t=this;return t._callbacks={},t._directMap={},t},y.prototype.stopCallback=function(t,e){if((" "+e.className+" ").indexOf(" mousetrap ")>-1)return!1;if(b(e,this.target))return!1;if("composedPath"in t&&"function"==typeof t.composedPath){var n=t.composedPath()[0];n!==t.target&&(e=n)}return"INPUT"==e.tagName||"SELECT"==e.tagName||"TEXTAREA"==e.tagName||e.isContentEditable},y.prototype.handleKey=function(){return this._handleKey.apply(this,arguments)},y.addKeycodes=function(t){for(var e in t)t.hasOwnProperty(e)&&(o[e]=t[e]);i=null},y.init=function(){var t=y(n);for(var e in t)"_"!==e.charAt(0)&&(y[e]=function(e){return function(){return t[e].apply(t,arguments)}}(e))},y.init(),e.Mousetrap=y,t.exports&&(t.exports=y)}function u(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent("on"+e,n)}function p(t){if("keypress"==t.type){var e=String.fromCharCode(t.which);return t.shiftKey||(e=e.toLowerCase()),e}return o[t.which]?o[t.which]:s[t.which]?s[t.which]:String.fromCharCode(t.which).toLowerCase()}function h(t){return"shift"==t||"ctrl"==t||"alt"==t||"meta"==t}function d(t,e,n){return n||(n=function(){if(!i)for(var t in i={},o)t>95&&t<112||o.hasOwnProperty(t)&&(i[o[t]]=t);return i}()[t]?"keydown":"keypress"),"keypress"==n&&e.length&&(n="keydown"),n}function f(t,e){var n,r,i,o=[];for(n=function(t){return"+"===t?["+"]:(t=t.replace(/\+{2}/g,"+plus")).split("+")}(t),i=0;i1?g(t,a,n,r):(s=f(t,r),e._callbacks[s.key]=e._callbacks[s.key]||[],c(s.key,s.modifiers,{type:s.action},i,t,o),e._callbacks[s.key][i?"unshift":"push"]({callback:n,modifiers:s.modifiers,action:s.action,seq:i,level:o,combo:t}))}e._handleKey=function(t,e,n){var r,i=c(t,e,n),o={},u=0,p=!1;for(r=0;rthis.formatkey(t)))}formatkey(t){const n=t.toLocaleLowerCase().replace(/\s/g,"").replace("delete","del").replace("cmd","command").replace("arrowup","up").replace("arrowright","right").replace("arrowdown","down").replace("arrowleft","left"),r=this.options.format;return r?e.FunctionExt.call(r,this.graph,n):n}isGraphEvent(t){const n=t.target,r=t.currentTarget;return!!n&&(n===this.target||r===this.target||n===document.body||e.Dom.contains(this.container,n))}isInputEvent(t){var n;const r=t.target,i=null===(n=null==r?void 0:r.tagName)||void 0===n?void 0:n.toLowerCase();let o=["input","textarea"].includes(i);return"true"===e.Dom.attr(r,"contenteditable")&&(o=!0),o}isEnabledForEvent(t){const n=!this.disabled&&this.isGraphEvent(t),r=this.isInputEvent(t);if(n){if(r&&("Backspace"===t.key||"Delete"===t.key))return!1;if(this.options.guard)return e.FunctionExt.call(this.options.guard,this.graph,t)}return n}dispose(){this.mousetrap.reset()}}n([e.Disposable.dispose()],o.prototype,"dispose",null),function(t){t.createMousetrap=function(t){const e=new i(t.target),n=e.stopCallback;return e.stopCallback=(r,i,o)=>!t.isEnabledForEvent(r)||!!n&&n.call(e,r,i,o),e}}(o||(o={})),e.Graph.prototype.isKeyboardEnabled=function(){const t=this.getPlugin("keyboard");return!!t&&t.isEnabled()},e.Graph.prototype.enableKeyboard=function(){const t=this.getPlugin("keyboard");return t&&t.enable(),this},e.Graph.prototype.disableKeyboard=function(){const t=this.getPlugin("keyboard");return t&&t.disable(),this},e.Graph.prototype.toggleKeyboard=function(t){const e=this.getPlugin("keyboard");return e&&e.toggleEnabled(t),this},e.Graph.prototype.bindKey=function(t,e,n){const r=this.getPlugin("keyboard");return r&&r.bindKey(t,e,n),this},e.Graph.prototype.unbindKey=function(t,e){const n=this.getPlugin("keyboard");return n&&n.unbindKey(t,e),this},e.Graph.prototype.clearKeys=function(){const t=this.getPlugin("keyboard");return t&&t.clear(),this},e.Graph.prototype.triggerKey=function(t,e){const n=this.getPlugin("keyboard");return n&&n.trigger(t,e),this};class s extends e.Disposable{constructor(t={}){super(),this.name="keyboard",this.options=Object.assign({enabled:!0},t)}init(t){this.keyboardImpl=new o(Object.assign(Object.assign({},this.options),{graph:t}))}isEnabled(){return!this.keyboardImpl.disabled}enable(){this.keyboardImpl.enable()}disable(){this.keyboardImpl.disable()}toggleEnabled(t){return null!=t?t!==this.isEnabled()&&(t?this.enable():this.disable()):this.isEnabled()?this.disable():this.enable(),this}bindKey(t,e,n){return this.keyboardImpl.on(t,e,n),this}trigger(t,e){return this.keyboardImpl.trigger(t,e),this}clear(){return this.keyboardImpl.clear(),this}unbindKey(t,e){return this.keyboardImpl.off(t,e),this}dispose(){this.keyboardImpl.dispose()}}n([e.Disposable.dispose()],s.prototype,"dispose",null),t.Keyboard=s}));