Files
drawNET/static/js/lib/x6-plugin-keyboard.js
T
2026-04-21 13:28:36 +09:00

2 lines
9.3 KiB
JavaScript

!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;i<n.length;++i)r=n[i],l[r]&&(r=l[r]),e&&"keypress"!=e&&a[r]&&(r=a[r],o.push("shift")),h(r)&&o.push(r);return{key:r,modifiers:o,action:e=d(r,o,e)}}function b(t,e){return null!==t&&t!==n&&(t===e||b(t.parentNode,e))}function y(t){var e=this;if(t=t||n,!(e instanceof y))return new y(t);e.target=t,e._callbacks={},e._directMap={};var r,i={},o=!1,s=!1,a=!1;function l(t){t=t||{};var e,n=!1;for(e in i)t[e]?n=!0:i[e]=0;n||(a=!1)}function c(t,n,r,o,s,a){var l,c,u,p,d=[],f=r.type;if(!e._callbacks[t])return[];for("keyup"==f&&h(t)&&(n=[t]),l=0;l<e._callbacks[t].length;++l)if(c=e._callbacks[t][l],(o||!c.seq||i[c.seq]==c.level)&&f==c.action&&("keypress"==f&&!r.metaKey&&!r.ctrlKey||(u=n,p=c.modifiers,u.sort().join(",")===p.sort().join(",")))){var b=!o&&c.combo==s,y=o&&c.seq==o&&c.level==a;(b||y)&&e._callbacks[t].splice(l,1),d.push(c)}return d}function d(t,n,r,i){e.stopCallback(n,n.target||n.srcElement,r,i)||!1===t(n,r)&&(function(t){t.preventDefault?t.preventDefault():t.returnValue=!1}(n),function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0}(n))}function b(t){"number"!=typeof t.which&&(t.which=t.keyCode);var n=p(t);n&&("keyup"!=t.type||o!==n?e.handleKey(n,function(t){var e=[];return t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),t.ctrlKey&&e.push("ctrl"),t.metaKey&&e.push("meta"),e}(t),t):o=!1)}function g(t,e,n,s){function c(e){return function(){a=e,++i[t],clearTimeout(r),r=setTimeout(l,1e3)}}function u(e){d(n,e,t),"keyup"!==s&&(o=p(e)),setTimeout(l,10)}i[t]=0;for(var h=0;h<e.length;++h){var b=h+1===e.length?u:c(s||f(e[h+1]).action);m(e[h],b,s,t,h)}}function m(t,n,r,i,o){e._directMap[t+":"+r]=n;var s,a=(t=t.replace(/\s+/g," ")).split(" ");a.length>1?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;r<i.length;++r)i[r].seq&&(u=Math.max(u,i[r].level));for(r=0;r<i.length;++r)if(i[r].seq){if(i[r].level!=u)continue;p=!0,o[i[r].seq]=1,d(i[r].callback,n,i[r].combo,i[r].seq)}else p||d(i[r].callback,n,i[r].combo);var f="keypress"==n.type&&s;n.type!=a||h(t)||f||l(o),s=p&&"keydown"==n.type},e._bindMultiple=function(t,e,n){for(var r=0;r<t.length;++r)m(t[r],e,n)},u(t,"keypress",b),u(t,"keydown",b),u(t,"keyup",b)}}("undefined"!=typeof window?window:null,"undefined"!=typeof window?document:null)}({get exports(){return r},set exports(t){r=t}});var i=r;class o extends e.Disposable{get graph(){return this.options.graph}constructor(t){super(),this.options=t;const e=this.graph.getPlugin("scroller");this.container=e?e.container:this.graph.container,t.global?this.target=document:(this.target=this.container,this.disabled||this.target.setAttribute("tabindex","-1"),this.graph.on("cell:mouseup",this.focus,this),this.graph.on("blank:mouseup",this.focus,this)),this.mousetrap=o.createMousetrap(this)}get disabled(){return!0!==this.options.enabled}enable(){this.disabled&&(this.options.enabled=!0,this.target instanceof HTMLElement&&this.target.setAttribute("tabindex","-1"))}disable(){this.disabled||(this.options.enabled=!1,this.target instanceof HTMLElement&&this.target.removeAttribute("tabindex"))}on(t,e,n){this.mousetrap.bind(this.getKeys(t),e,n)}off(t,e){this.mousetrap.unbind(this.getKeys(t),e)}clear(){this.mousetrap.reset()}trigger(t,e){this.mousetrap.trigger(t,e)}focus(t){if(this.isInputEvent(t.e))return;this.target.focus({preventScroll:!0})}getKeys(t){return(Array.isArray(t)?t:[t]).map((t=>this.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}));