novnc
Version:
An HTML5 VNC client
86 lines (85 loc) • 3.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.XVNC_BUTTONS = exports.MouseButtonMapper = void 0;
exports.xvncButtonToMask = xvncButtonToMask;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var XVNC_BUTTONS = {
LEFT_BUTTON: 1,
MIDDLE_BUTTON: 2,
RIGHT_BUTTON: 3,
TURN_SCROLL_WHEEL_UP: 4,
TURN_SCROLL_WHEEL_DOWN: 5,
PUSH_SCROLL_WHEEL_LEFT: 6,
PUSH_SCROLL_WHEEL_RIGHT: 7,
BACK_BUTTON: 8,
FORWARD_BUTTON: 9
};
exports.XVNC_BUTTONS = XVNC_BUTTONS;
function xvncButtonToMask(xvncButton) {
return 1 << xvncButton - 1;
}
var MouseButtonMapper = /*#__PURE__*/function () {
function MouseButtonMapper() {
_classCallCheck(this, MouseButtonMapper);
this.map = new Map();
}
_createClass(MouseButtonMapper, [{
key: "get",
value: function get(mouseButton) {
if (!this.map.has(mouseButton)) {
return mouseButton;
}
return this.map.get(mouseButton);
}
}, {
key: "set",
value: function set(mouseButton, xorgMouseButton) {
return this.map.set(mouseButton, xorgMouseButton);
}
}, {
key: "delete",
value: function _delete(mouseButton) {
return this.map["delete"](mouseButton);
}
}, {
key: "dump",
value: function dump() {
return JSON.stringify(this.map, this._replacer);
}
}, {
key: "load",
value: function load(json) {
this.map = JSON.parse(json, this._reviver);
}
}, {
key: "_replacer",
value: function _replacer(key, value) {
if (!(value instanceof Map)) {
return value;
}
return {
dataType: 'Map',
value: Array.from(value.entries())
};
}
}, {
key: "_reviver",
value: function _reviver(key, value) {
if (_typeof(value) === 'object' && value !== null) {
if (value.dataType === 'Map') {
return new Map(value.value);
}
}
return value;
}
}]);
return MouseButtonMapper;
}();
exports.MouseButtonMapper = exports["default"] = MouseButtonMapper;