text: /**
  @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"./boot.js";import{PropertyEffects as t}from"../mixins/property-effects.js";import{MutableData as e}from"../mixins/mutable-data.js";import{strictTemplatePolicy as o}from"./settings.js";import{wrap as n}from"./wrap.js";let s=null;function HTMLTemplateElementExtension(){return s}HTMLTemplateElementExtension.prototype=Object.create(HTMLTemplateElement.prototype,{constructor:{value:HTMLTemplateElementExtension,writable:!0}});const a=t(HTMLTemplateElementExtension),r=e(a);const p=t(class{});class TemplateInstanceBase extends p{constructor(t){super(),this._configureProperties(t),this.root=this._stampTemplate(this.__dataHost);let e=[];this.children=e;for(let t=this.root.firstChild;t;t=t.nextSibling)e.push(t),t.__templatizeInstance=this;this.__templatizeOwner&&this.__templatizeOwner.__hideTemplateChildren__&&this._showHideChildren(!0);let o=this.__templatizeOptions;(t&&o.instanceProps||!o.instanceProps)&&this._enableProperties()}_configureProperties(t){if(this.__templatizeOptions.forwardHostProp)for(let t in this.__hostProps)this._setPendingProperty(t,this.__dataHost["_host_"+t]);for(let e in t)this._setPendingProperty(e,t[e])}forwardHostProp(t,e){this._setPendingPropertyOrPath(t,e,!1,!0)&&this.__dataHost._enqueueClient(this)}_addEventListenerToNode(t,e,o){if(this._methodHost&&this.__templatizeOptions.parentModel)this._methodHost._addEventListenerToNode(t,e,t=>{t.model=this,o(t)});else{let n=this.__dataHost.__dataHost;n&&n._addEventListenerToNode(t,e,o)}}_showHideChildren(t){let e=this.children;for(let o=0;o<e.length;o++){let s=e[o];if(Boolean(t)!=Boolean(s.__hideTemplateChildren__))if(s.nodeType===Node.TEXT_NODE)t?(s.__polymerTextContent__=s.textContent,s.textContent=""):s.textContent=s.__polymerTextContent__;else if("slot"===s.localName)if(t)s.__polymerReplaced__=document.createComment("hidden-slot"),n(n(s).parentNode).replaceChild(s.__polymerReplaced__,s);else{const t=s.__polymerReplaced__;t&&n(n(t).parentNode).replaceChild(s,t)}else s.style&&(t?(s.__polymerDisplay__=s.style.display,s.style.display="none"):s.style.display=s.__polymerDisplay__);s.__hideTemplateChildren__=t,s._showHideChildren&&s._showHideChildren(t)}}_setUnmanagedPropertyToNode(t,e,o){t.__hideTemplateChildren__&&t.nodeType==Node.TEXT_NODE&&"textContent"==e?t.__polymerTextContent__=o:super._setUnmanagedPropertyToNode(t,e,o)}get parentModel(){let t=this.__parentModel;if(!t){let e;t=this;do{t=t.__dataHost.__dataHost}while((e=t.__templatizeOptions)&&!e.parentModel);this.__parentModel=t}return t}dispatchEvent(t){return!0}}TemplateInstanceBase.prototype.__dataHost,TemplateInstanceBase.prototype.__templatizeOptions,TemplateInstanceBase.prototype._methodHost,TemplateInstanceBase.prototype.__templatizeOwner,TemplateInstanceBase.prototype.__hostProps;const l=e(TemplateInstanceBase);function findMethodHost(t){let e=t.__dataHost;return e&&e._methodHost||e}function createTemplatizerClass(t,e,o){let n=o.mutableData?l:TemplateInstanceBase;templatize.mixin&&(n=templatize.mixin(n));let s=class extends n{};return s.prototype.__templatizeOptions=o,s.prototype._bindTemplate(t),function addNotifyEffects(t,e,o,n){let s=o.hostProps||{};for(let e in n.instanceProps){delete s[e];let o=n.notifyInstanceProp;o&&t.prototype._addPropertyEffect(e,t.prototype.PROPERTY_EFFECT_TYPES.NOTIFY,{fn:createNotifyInstancePropEffect(e,o)})}if(n.forwardHostProp&&e.__dataHost)for(let e in s)o.hasHostProps||(o.hasHostProps=!0),t.prototype._addPropertyEffect(e,t.prototype.PROPERTY_EFFECT_TYPES.NOTIFY,{fn:function notifyHostProp(t,e,o){t.__dataHost._setPendingPropertyOrPath("_host_"+e,o[e],!0,!0)}})}(s,t,e,o),s}function addPropagateEffects(t,e,o){let n=o.forwardHostProp;if(n&&e.hasHostProps){let p=e.templatizeTemplateClass;if(!p){let t=o.mutableData?r:a;p=e.templatizeTemplateClass=class TemplatizedTemplate extends t{};let s=e.hostProps;for(let t in s)p.prototype._addPropertyEffect("_host_"+t,p.prototype.PROPERTY_EFFECT_TYPES.PROPAGATE,{fn:createForwardHostPropEffect(t,n)}),p.prototype._createNotifyingProperty("_host_"+t)}!function upgradeTemplate(t,e){s=t,Object.setPrototypeOf(t,e.prototype),new e,s=null}(t,p),t.__dataProto&&Object.assign(t.__data,t.__dataProto),t.__dataTemp={},t.__dataPending=null,t.__dataOld=null,t._enableProperties()}}function createForwardHostPropEffect(t,e){return function forwardHostProp(t,o,n){e.call(t.__templatizeOwner,o.substring("_host_".length),n[o])}}function createNotifyInstancePropEffect(t,e){return function notifyInstanceProp(t,o,n){e.call(t.__templatizeOwner,t,o,n[o])}}export function templatize(t,e,n){if(o&&!findMethodHost(t))throw new Error("strictTemplatePolicy: template owner not trusted");if(n=n||{},t.__templatizeOwner)throw new Error("A <template> can only be templatized once");t.__templatizeOwner=e;let s=(e?e.constructor:TemplateInstanceBase)._parseTemplate(t),a=s.templatizeInstanceClass;a||(a=createTemplatizerClass(t,s,n),s.templatizeInstanceClass=a),addPropagateEffects(t,s,n);let r=class TemplateInstance extends a{};return r.prototype._methodHost=findMethodHost(t),r.prototype.__dataHost=t,r.prototype.__templatizeOwner=e,r.prototype.__hostProps=s.hostProps,r=r,r}export function modelForElement(t,e){let o;for(;e;)if(o=e.__templatizeInstance){if(o.__dataHost==t)return o;e=o.__dataHost}else e=n(e).parentNode;return null}export{TemplateInstanceBase};