/**
@license
Copyright (c) 2017 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
*/
import e from"../src/apply-shim.js";import t from"../src/template-map.js";import{getIsExtends as s,toCssText as l,elementHasBuiltCss as o}from"../src/style-util.js";import*as r from"../src/apply-shim-utils.js";import{getComputedStyleValue as a,updateNativeProperties as i}from"../src/common-utils.js";import{CustomStyleInterfaceInterface as m}from"../src/custom-style-interface.js";import{nativeCssVariables as n,nativeShadow as S,cssBuild as u,disableRuntime as y}from"../src/style-settings.js";const c=new e;class ApplyShimInterface{constructor(){this.customStyleInterface=null,c.invalidCallback=r.invalidate}ensure(){this.customStyleInterface||window.ShadyCSS.CustomStyleInterface&&(this.customStyleInterface=window.ShadyCSS.CustomStyleInterface,this.customStyleInterface.transformCallback=e=>{c.transformCustomStyle(e)},this.customStyleInterface.validateCallback=()=>{requestAnimationFrame((()=>{this.customStyleInterface.enqueued&&this.flushCustomStyles()}))})}prepareTemplate(e,s){if(this.ensure(),o(e))return;t[s]=e;let l=c.transformTemplate(e,s);e._styleAst=l}flushCustomStyles(){if(this.ensure(),!this.customStyleInterface)return;let e=this.customStyleInterface.processStyles();if(this.customStyleInterface.enqueued){for(let t=0;t<e.length;t++){let s=e[t],l=this.customStyleInterface.getStyleForCustomStyle(s);l&&c.transformCustomStyle(l)}this.customStyleInterface.enqueued=!1}}styleSubtree(e,t){if(this.ensure(),t&&i(e,t),e.shadowRoot){this.styleElement(e);let t=e.shadowRoot.children||e.shadowRoot.childNodes;for(let e=0;e<t.length;e++)this.styleSubtree(t[e])}else{let t=e.children||e.childNodes;for(let e=0;e<t.length;e++)this.styleSubtree(t[e])}}styleElement(e){this.ensure();let{is:a}=s(e),i=t[a];if((!i||!o(i))&&i&&!r.templateIsValid(i)){r.templateIsValidating(i)||(this.prepareTemplate(i,a),r.startValidatingTemplate(i));let t=e.shadowRoot;if(t){let e=t.querySelector("style");e&&(e.__cssRules=i._styleAst,e.textContent=l(i._styleAst))}}}styleDocument(e){this.ensure(),this.styleSubtree(document.body,e)}}if(!window.ShadyCSS||!window.ShadyCSS.ScopingShim){const e=new ApplyShimInterface;let t=window.ShadyCSS&&window.ShadyCSS.CustomStyleInterface;window.ShadyCSS={prepareTemplate(t,s,l){e.flushCustomStyles(),e.prepareTemplate(t,s)},prepareTemplateStyles(e,t,s){window.ShadyCSS.prepareTemplate(e,t,s)},prepareTemplateDom(e,t){},styleSubtree(t,s){e.flushCustomStyles(),e.styleSubtree(t,s)},styleElement(t){e.flushCustomStyles(),e.styleElement(t)},styleDocument(t){e.flushCustomStyles(),e.styleDocument(t)},getComputedStyleValue:(e,t)=>a(e,t),flushCustomStyles(){e.flushCustomStyles()},nativeCss:n,nativeShadow:S,cssBuild:u,disableRuntime:y},t&&(window.ShadyCSS.CustomStyleInterface=t)}window.ShadyCSS.ApplyShim=c;