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 {applyStylePlaceHolder} from './style-util.js'; 14import {nativeShadow} from './style-settings.js'; 15 16/** @type {!Object<string, !Node>} */ 17const placeholderMap = {}; 18 19/** 20 * @param {string} elementName 21 * @return {Node} 22 */ 23export function getStylePlaceholder(elementName) { 24 return placeholderMap[elementName] || null; 25} 26 27/** 28 * @param {string} elementName 29 */ 30export function ensureStylePlaceholder(elementName) { 31 if (!placeholderMap[elementName]) { 32 placeholderMap[elementName] = applyStylePlaceHolder(elementName); 33 } 34} 35 36/** 37 * @const {CustomElementRegistry} 38 */ 39const ce = window['customElements']; 40if (ce && !nativeShadow) { 41 /** 42 * @const {function(this:CustomElementRegistry, string,function(new:HTMLElement),{extends: string}=)} 43 */ 44 const origDefine = ce['define']; 45 /** 46 * @param {string} name 47 * @param {function(new:HTMLElement)} clazz 48 * @param {{extends: string}=} options 49 */ 50 const wrappedDefine = (name, clazz, options) => { 51 ensureStylePlaceholder(name); 52 origDefine.call(/** @type {!CustomElementRegistry} */(ce), name, clazz, options); 53 }; 54 ce['define'] = wrappedDefine; 55}