1 | import { Observable } from '../../../data/observable';
|
2 | import { Trace } from '../../../trace';
|
3 | export class Style extends Observable {
|
4 | constructor(ownerView) {
|
5 | super();
|
6 | this.unscopedCssVariables = new Map();
|
7 | this.scopedCssVariables = new Map();
|
8 |
|
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 | removeScopedCssVariable(varName) {
|
23 | this.scopedCssVariables.delete(varName);
|
24 | }
|
25 | removeUnscopedCssVariable(varName) {
|
26 | this.unscopedCssVariables.delete(varName);
|
27 | }
|
28 | getCssVariable(varName) {
|
29 | const view = this.view;
|
30 | if (!view) {
|
31 | return null;
|
32 | }
|
33 | if (this.unscopedCssVariables.has(varName)) {
|
34 | return this.unscopedCssVariables.get(varName);
|
35 | }
|
36 | if (this.scopedCssVariables.has(varName)) {
|
37 | return this.scopedCssVariables.get(varName);
|
38 | }
|
39 | if (!view.parent || !view.parent.style) {
|
40 | return null;
|
41 | }
|
42 | return view.parent.style.getCssVariable(varName);
|
43 | }
|
44 | resetScopedCssVariables() {
|
45 | this.scopedCssVariables.clear();
|
46 | }
|
47 | resetUnscopedCssVariables() {
|
48 | this.unscopedCssVariables.clear();
|
49 | }
|
50 | toString() {
|
51 | const view = this.viewRef.get();
|
52 | if (!view) {
|
53 | Trace.write(`toString() of Style cannot execute correctly because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn);
|
54 | return '';
|
55 | }
|
56 | return `${view}.style`;
|
57 | }
|
58 | get view() {
|
59 | if (this.viewRef) {
|
60 | return this.viewRef.get();
|
61 | }
|
62 | return undefined;
|
63 | }
|
64 | }
|
65 | Style.prototype.PropertyBag = class {
|
66 | };
|
67 |
|
\ | No newline at end of file |