1/** 2@license 3Copyright (c) 2017 The Polymer Project Authors. All rights reserved. 4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 7Code distributed by Google as part of the polymer project is also 8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 9*/ 10 11'use strict'; 12 13import { MIXIN_MATCH, VAR_ASSIGN } from './common-regex.js'; 14 15/** 16 * @param {Element} element 17 * @param {Object=} properties 18 */ 19export function updateNativeProperties(element, properties) { 20 // remove previous properties 21 for (let p in properties) { 22 // NOTE: for bc with shim, don't apply null values. 23 if (p === null) { 24 element.style.removeProperty(p); 25 } else { 26 element.style.setProperty(p, properties[p]); 27 } 28 } 29} 30 31/** 32 * @param {Element} element 33 * @param {string} property 34 * @return {string} 35 */ 36export function getComputedStyleValue(element, property) { 37 /** 38 * @const {string} 39 */ 40 const value = window.getComputedStyle(element).getPropertyValue(property); 41 if (!value) { 42 return ''; 43 } else { 44 return value.trim(); 45 } 46} 47 48/** 49 * return true if `cssText` contains a mixin definition or consumption 50 * @param {string} cssText 51 * @return {boolean} 52 */ 53export function detectMixin(cssText) { 54 const has = MIXIN_MATCH.test(cssText) || VAR_ASSIGN.test(cssText); 55 // reset state of the regexes 56 MIXIN_MATCH.lastIndex = 0; 57 VAR_ASSIGN.lastIndex = 0; 58 return has; 59} 60