/
style-defaults.html
100 lines (87 loc) · 3.5 KB
/
style-defaults.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="style-util.html">
<link rel="import" href="style-cache.html">
<link rel="import" href="settings.html">
<script>
Polymer.StyleDefaults = (function() {
var styleProperties = Polymer.StyleProperties;
var StyleCache = Polymer.StyleCache;
var nativeVariables = Polymer.Settings.useNativeCSSProperties;
var api = {
_styles: [],
_properties: null,
customStyle: {},
_styleCache: new StyleCache(),
_element: Polymer.DomApi.wrap(document.documentElement),
addStyle: function(style) {
this._styles.push(style);
this._properties = null;
},
// NOTE: this object can be used as a styling scope so it has an api
// similar to that of an element wrt style properties
get _styleProperties() {
if (!this._properties) {
// force rules to reparse since they may be out of date
styleProperties.decorateStyles(this._styles, this);
// NOTE: reset cache for own properties; it may have been set when
// an element in an import applied styles (e.g. custom-style)
this._styles._scopeStyleProperties = null;
this._properties = styleProperties
.hostAndRootPropertiesForScope(this).rootProps;
// mixin customStyle
styleProperties.mixinCustomStyle(this._properties, this.customStyle);
styleProperties.reify(this._properties);
}
return this._properties;
},
hasStyleProperties: function() {
return Boolean(this._properties);
},
_needsStyleProperties: function() {},
_computeStyleProperties: function() {
return this._styleProperties;
},
/**
* Re-evaluates and applies custom CSS properties to all elements in the
* document based on dynamic changes, such as adding or removing classes.
*
* For performance reasons, Polymer's custom CSS property shim relies
* on this explicit signal from the user to indicate when changes have
* been made that affect the values of custom properties.
*
* @method updateStyles
* @param {Object=} properties Properties object which is mixed into
* the document root `customStyle` property. This argument provides a
* shortcut for setting `customStyle` and then calling `updateStyles`.
*/
updateStyles: function(properties) {
// force properties update.
this._properties = null;
if (properties) {
Polymer.Base.mixin(this.customStyle, properties);
}
// invalidate the cache
this._styleCache.clear();
// update any custom-styles we are tracking
for (var i=0, s; i < this._styles.length; i++) {
s = this._styles[i];
s = s.__importElement || s;
s._apply();
}
if (nativeVariables) {
styleProperties.updateNativeStyleProperties(document.documentElement, this.customStyle);
}
}
};
// exports
return api;
})();
</script>