UNPKG

sprotty

Version:

A next-gen framework for graphical views

76 lines 2.85 kB
"use strict"; /******************************************************************************** * Copyright (c) 2017-2018 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.isSVGGraphicsElement = exports.hitsMouseEvent = exports.getWindowScroll = exports.isCrossSite = exports.isMac = exports.isCtrlOrCmd = void 0; const sprotty_protocol_1 = require("sprotty-protocol"); /** * Returns whether the mouse or keyboard event includes the CMD key * on Mac or CTRL key on Linux / others. */ function isCtrlOrCmd(event) { if (isMac()) return event.metaKey; else return event.ctrlKey; } exports.isCtrlOrCmd = isCtrlOrCmd; function isMac() { return window.navigator.userAgent.indexOf("Mac") !== -1; } exports.isMac = isMac; function isCrossSite(url) { if (url && typeof window !== 'undefined' && window.location) { let baseURL = ''; if (window.location.protocol) baseURL += window.location.protocol + '//'; if (window.location.host) baseURL += window.location.host; return baseURL.length > 0 && !url.startsWith(baseURL); } return false; } exports.isCrossSite = isCrossSite; /** * Returns the amount of scroll of the browser window as a point. */ function getWindowScroll() { if (typeof window === 'undefined') { return sprotty_protocol_1.Point.ORIGIN; } return { x: window.pageXOffset, y: window.pageYOffset }; } exports.getWindowScroll = getWindowScroll; /** * Checks whether the given mouse event hits the given DOM element. */ function hitsMouseEvent(child, event) { const clientRect = child.getBoundingClientRect(); return event.clientX >= clientRect.left && event.clientX <= clientRect.right && event.clientY >= clientRect.top && event.clientY <= clientRect.bottom; } exports.hitsMouseEvent = hitsMouseEvent; /** * Checks whether the given DOM node is an SVG element. */ function isSVGGraphicsElement(node) { return typeof node.getBBox === 'function'; } exports.isSVGGraphicsElement = isSVGGraphicsElement; //# sourceMappingURL=browser.js.map