OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * This library contains support for scoped CSS that uses the compilation |
| 7 * strategy of WebUI. This will likely become deprecated as we migrate over to |
| 8 * use runtime mechanisms to enforce scoped css rules. |
| 9 */ |
| 10 library scoped_css; |
| 11 |
| 12 /** |
| 13 * Maps CSS selectors (class and) to a mangled name and maps x-component name |
| 14 * to [is='x-component']. |
| 15 */ |
| 16 class ScopedCssMapper { |
| 17 final Map<String, String> _mapping; |
| 18 |
| 19 ScopedCssMapper(this._mapping); |
| 20 |
| 21 /** Returns mangled name of selector sans . or # character. */ |
| 22 String operator [](String selector) => _mapping[selector]; |
| 23 |
| 24 /** Returns mangled name of selector w/ . or # character. */ |
| 25 String getSelector(String selector) { |
| 26 var prefixedName = this[selector]; |
| 27 var selectorType = selector[0]; |
| 28 if (selectorType == '.' || selectorType == '#') { |
| 29 return '$selectorType${prefixedName}'; |
| 30 } |
| 31 |
| 32 return prefixedName; |
| 33 } |
| 34 } |
| 35 |
| 36 /** Any CSS selector (class, id or element) defined name to mangled name. */ |
| 37 Map<String, ScopedCssMapper> _mappers = {}; |
| 38 |
| 39 ScopedCssMapper getScopedCss(String componentName) => _mappers[componentName]; |
| 40 |
| 41 void setScopedCss(String componentName, Map<String, String> mapping) { |
| 42 _mappers.putIfAbsent(componentName, () => new ScopedCssMapper(mapping)); |
| 43 } |
OLD | NEW |