UNPKG

1.95 kBJavaScriptView Raw
1import { Observable } from '../../../data/observable';
2import { Trace } from '../../../trace';
3export class Style extends Observable {
4 constructor(ownerView) {
5 super();
6 this.unscopedCssVariables = new Map();
7 this.scopedCssVariables = new Map();
8 // HACK: Could not find better way for cross platform WeakRef type checking.
9 if (ownerView.constructor.toString().indexOf('[native code]') !== -1) {
10 this.viewRef = ownerView;
11 }
12 else {
13 this.viewRef = new WeakRef(ownerView);
14 }
15 }
16 setScopedCssVariable(varName, value) {
17 this.scopedCssVariables.set(varName, value);
18 }
19 setUnscopedCssVariable(varName, value) {
20 this.unscopedCssVariables.set(varName, value);
21 }
22 getCssVariable(varName) {
23 const view = this.view;
24 if (!view) {
25 return null;
26 }
27 if (this.unscopedCssVariables.has(varName)) {
28 return this.unscopedCssVariables.get(varName);
29 }
30 if (this.scopedCssVariables.has(varName)) {
31 return this.scopedCssVariables.get(varName);
32 }
33 if (!view.parent || !view.parent.style) {
34 return null;
35 }
36 return view.parent.style.getCssVariable(varName);
37 }
38 resetScopedCssVariables() {
39 this.scopedCssVariables.clear();
40 }
41 resetUnscopedCssVariables() {
42 this.unscopedCssVariables.clear();
43 }
44 toString() {
45 const view = this.viewRef.get();
46 if (!view) {
47 Trace.write(`toString() of Style cannot execute correctly because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn);
48 return '';
49 }
50 return `${view}.style`;
51 }
52 get view() {
53 if (this.viewRef) {
54 return this.viewRef.get();
55 }
56 return undefined;
57 }
58}
59Style.prototype.PropertyBag = class {
60};
61//# sourceMappingURL=index.js.map
\No newline at end of file