UNPKG

1.33 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import { ArrayExt } from '@lumino/algorithm';
4import { UUID } from '@lumino/coreutils';
5import { ElementExt } from '@lumino/domutils';
6/**
7 * The namespace for DOM utilities.
8 */
9export var DOMUtils;
10(function (DOMUtils) {
11 /**
12 * Get the index of the node at a client position, or `-1`.
13 */
14 function hitTestNodes(nodes, x, y) {
15 return ArrayExt.findFirstIndex(nodes, node => {
16 return ElementExt.hitTest(node, x, y);
17 });
18 }
19 DOMUtils.hitTestNodes = hitTestNodes;
20 /**
21 * Find the first element matching a class name.
22 */
23 function findElement(parent, className) {
24 return parent.querySelector(`.${className}`);
25 }
26 DOMUtils.findElement = findElement;
27 /**
28 * Find the first element matching a class name.
29 */
30 function findElements(parent, className) {
31 return parent.getElementsByClassName(className);
32 }
33 DOMUtils.findElements = findElements;
34 /**
35 * Create a DOM id with prefix "id-" to solve bug for UUIDs beginning with numbers.
36 */
37 function createDomID() {
38 return `id-${UUID.uuid4()}`;
39 }
40 DOMUtils.createDomID = createDomID;
41})(DOMUtils || (DOMUtils = {}));
42//# sourceMappingURL=domutils.js.map
\No newline at end of file