import { __exports as util } from '../../../../_virtual/util.js';
import require$$0 from '../../../../_virtual/_monaco-editor.js';

(function (exports) {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.Emitter = exports.Event = exports.monacoToEmacsKey = exports.modifierKeys = void 0;
	var monaco = require$$0;
	exports.modifierKeys = {
	    Alt: 'M',
	    Control: 'C',
	    Ctrl: 'C',
	    Meta: 'CMD',
	    Shift: 'S',
	};
	var specialKeys = {
	    Enter: 'Return',
	    Space: 'SPC',
	    Backslash: '\\',
	    Slash: '/',
	    Backquote: '`',
	    BracketRight: ']',
	    BracketLeft: '[',
	    Comma: ',',
	    Period: '.',
	    Equal: '=',
	    Minus: '-',
	    Quote: '\'',
	    Semicolon: ';',
	};
	var oneCharKeyPrefixes = ['Key', 'Numpad'];
	var arrowSuffix = 'Arrow';
	function monacoToEmacsKey(ev) {
	    var keyName = monaco.KeyCode[ev.keyCode];
	    if (exports.modifierKeys[keyName]) {
	        return '';
	    }
	    var key = oneCharKeyPrefixes.some(function (prefix) { return keyName.startsWith(prefix); }) ? keyName[keyName.length - 1] : keyName;
	    if (keyName.endsWith(arrowSuffix)) {
	        key = keyName.substring(0, keyName.length - arrowSuffix.length);
	    }
	    else if (specialKeys[keyName]) {
	        key = specialKeys[key];
	    }
	    if (key.length === 1) {
	        key = key.toLowerCase();
	    }
	    if (ev.altKey) {
	        key = "".concat(exports.modifierKeys.Alt, "-").concat(key);
	    }
	    if (ev.ctrlKey) {
	        key = "".concat(exports.modifierKeys.Ctrl, "-").concat(key);
	    }
	    if (ev.metaKey) {
	        key = "".concat(exports.modifierKeys.Meta, "-").concat(key);
	    }
	    if (ev.shiftKey) {
	        key = "".concat(exports.modifierKeys.Shift, "-").concat(key);
	    }
	    return key;
	}
	exports.monacoToEmacsKey = monacoToEmacsKey;
	(function (Event) {
	    var _disposable = { dispose: function () { } };
	    Event.None = function () { return _disposable; };
	})(exports.Event || (exports.Event = {}));
	var Emitter = (function () {
	    function Emitter() {
	        this._listeners = [];
	    }
	    Object.defineProperty(Emitter.prototype, "event", {
	        get: function () {
	            var _this = this;
	            if (!this._event) {
	                this._event = function (listener) {
	                    _this._listeners.push(listener);
	                    var result = {
	                        dispose: function () {
	                            if (_this._disposed) {
	                                return;
	                            }
	                            var index = _this._listeners.indexOf(listener);
	                            if (index < 0) {
	                                return;
	                            }
	                            _this._listeners.splice(index, 1);
	                        }
	                    };
	                    return result;
	                };
	            }
	            return this._event;
	        },
	        enumerable: false,
	        configurable: true
	    });
	    Emitter.prototype.fire = function (ev) {
	        if (!this._listeners.length) {
	            return;
	        }
	        this._listeners.forEach(function (l) { return l(ev); });
	    };
	    Emitter.prototype.dispose = function () {
	        if (this._disposed) {
	            return;
	        }
	        this._listeners = undefined;
	        this._disposed = true;
	    };
	    return Emitter;
	}());
	exports.Emitter = Emitter; 
} (util));
