-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathUtils.ts
More file actions
85 lines (68 loc) · 2.2 KB
/
Utils.ts
File metadata and controls
85 lines (68 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { DockNode } from "./DockNode.js";
export class Utils {
private static _counter: number = 0;
static getPixels(pixels: string): number {
if (pixels === null) {
return 0;
}
return parseInt(pixels.replace('px', ''));
}
static disableGlobalTextSelection(element: HTMLElement) {
element.classList.add('disable-selection');
}
static enableGlobalTextSelection(element: HTMLElement) {
element.classList.remove('disable-selection');
}
static isPointInsideNode(px: number, py: number, node: DockNode): boolean {
let element = node.container.containerElement;
let rect = element.getBoundingClientRect();
return (
px >= rect.left &&
px <= rect.left + rect.width &&
py >= rect.top &&
py <= rect.top + rect.height
);
}
static getNextId(prefix: string): string {
return prefix + Utils._counter++;
}
static removeNode(node: Node): boolean {
if (node.parentNode === null) {
return false;
}
node.parentNode.removeChild(node);
return true;
}
static orderByIndexes<T>(array: T[], indexes: number[]) {
let sortedArray = [];
for (let i = 0; i < indexes.length; i++) {
sortedArray.push(array[indexes[i]]);
}
return sortedArray;
}
static arrayRemove<T>(array: T[], value: any): T[] | false {
let idx = array.indexOf(value);
if (idx !== -1) {
return array.splice(idx, 1);
}
return false;
}
static arrayContains<T>(array: T[], value: T): boolean {
let i = array.length;
while (i--) {
if (array[i] === value) {
return true;
}
}
return false;
}
static arrayEqual<T>(a: T[], b: T[]): boolean {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}
}