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 13/** @type {!Set<string>} */ 14const styleTextSet = new Set(); 15 16export const scopingAttribute = 'shady-unscoped'; 17 18/** 19 * Add a specifically-marked style to the document directly, and only one copy of that style. 20 * 21 * @param {!HTMLStyleElement} style 22 * @return {undefined} 23 */ 24export function processUnscopedStyle(style) { 25 const text = style.textContent; 26 if (!styleTextSet.has(text)) { 27 styleTextSet.add(text); 28 const newStyle = style.cloneNode(true); 29 document.head.appendChild(newStyle); 30 } 31} 32 33/** 34 * Check if a style is supposed to be unscoped 35 * @param {!HTMLStyleElement} style 36 * @return {boolean} true if the style has the unscoping attribute 37 */ 38export function isUnscopedStyle(style) { 39 return style.hasAttribute(scopingAttribute); 40}