-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathdom-utils.ts
77 lines (68 loc) · 2.14 KB
/
dom-utils.ts
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
import {
AnimationEvent,
AnimationPlayer,
NoopAnimationPlayer,
ɵAnimationGroupPlayer,
ɵStyleData,
} from "@angular/animations";
import { unsetValue } from "tns-core-modules/ui/core/view";
import { NgView } from "../element-types";
// overriden to use the default 'unsetValue'
// instead of empty string ''
export function eraseStylesOverride(element: NgView, styles: ɵStyleData) {
if (element["style"]) {
Object.keys(styles).forEach(prop => {
element.style[prop] = unsetValue;
});
}
}
export function cssClasses(element: NgView) {
if (!element.ngCssClasses) {
element.ngCssClasses = new Map<string, boolean>();
}
return element.ngCssClasses;
}
// The following functions are from
// the original DomAnimationEngine
export function getOrSetAsInMap(map: Map<any, any>, key: any, defaultValue: any) {
let value = map.get(key);
if (!value) {
map.set(key, value = defaultValue);
}
return value;
}
export function deleteFromArrayMap(map: Map<any, any[]>, key: any, value: any) {
let arr = map.get(key);
if (arr) {
const index = arr.indexOf(value);
if (index >= 0) {
arr.splice(index, 1);
if (arr.length === 0) {
map.delete(key);
}
}
}
}
export function optimizeGroupPlayer(players: AnimationPlayer[]): AnimationPlayer {
switch (players.length) {
case 0:
return new NoopAnimationPlayer();
case 1:
return players[0];
default:
return new ɵAnimationGroupPlayer(players);
}
}
export function copyArray(source: any[]): any[] {
return source ? source.splice(0) : [];
}
export function makeAnimationEvent(
element: NgView, triggerName: string, fromState: string, toState: string, phaseName: string,
totalTime: number): AnimationEvent {
return <AnimationEvent>{element, triggerName, fromState, toState, phaseName, totalTime};
}
export function setStyles(element: NgView, styles: ɵStyleData) {
if (element["style"]) {
Object.keys(styles).forEach(prop => element.style[prop] = styles[prop]);
}
}