@haxtheweb/haxcms-nodejs
Version:
HAXcms single and multisite nodejs server, api, and administration
10 lines • 4.79 kB
JavaScript
/**
@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"../utils/boot.js";import{dedupingMixin as e}from"../utils/mixin.js";const t={"dom-if":!0,"dom-repeat":!0};let n=!1,o=!1;function fixPlaceholder(e){(function hasPlaceholderBug(){if(!n){n=!0;const e=document.createElement("textarea");e.placeholder="a",o=e.placeholder===e.textContent}return o})()&&"textarea"===e.localName&&e.placeholder&&e.placeholder===e.textContent&&(e.textContent=null)}const a=(()=>{const e=window.trustedTypes&&window.trustedTypes.createPolicy("polymer-template-event-attribute-policy",{createScript:e=>e});return(t,n,o)=>{const a=n.getAttribute(o);e&&o.startsWith("on-")?t.setAttribute(o,e.createScript(a,o)):t.setAttribute(o,a)}})();function wrapTemplateExtension(e){let n=e.getAttribute("is");if(n&&t[n]){let t=e;for(t.removeAttribute("is"),e=t.ownerDocument.createElement(n),t.parentNode.replaceChild(e,t),e.appendChild(t);t.attributes.length;){const{name:n}=t.attributes[0];a(e,t,n),t.removeAttribute(n)}}return e}function findTemplateNode(e,t){let n=t.parentInfo&&findTemplateNode(e,t.parentInfo);if(!n)return e;for(let e=n.firstChild,o=0;e;e=e.nextSibling)if(t.parentIndex===o++)return e}function applyIdToMap(e,t,n,o){o.id&&(t[o.id]=n)}function applyEventListener(e,t,n){if(n.events&&n.events.length)for(let o,a=0,r=n.events;a<r.length&&(o=r[a]);a++)e._addMethodEventListenerToNode(t,o.name,o.value,e)}function applyTemplateInfo(e,t,n,o){n.templateInfo&&(t._templateInfo=n.templateInfo,t._parentTemplateInfo=o)}export const TemplateStamp=e((e=>class TemplateStamp extends e{static _parseTemplate(e,t){if(!e._templateInfo){let n=e._templateInfo={};n.nodeInfoList=[],n.nestedTemplate=Boolean(t),n.stripWhiteSpace=t&&t.stripWhiteSpace||e.hasAttribute&&e.hasAttribute("strip-whitespace"),this._parseTemplateContent(e,n,{parent:null})}return e._templateInfo}static _parseTemplateContent(e,t,n){return this._parseTemplateNode(e.content,t,n)}static _parseTemplateNode(e,t,n){let o=!1,a=e;return"template"!=a.localName||a.hasAttribute("preserve-content")?"slot"===a.localName&&(t.hasInsertionPoint=!0):o=this._parseTemplateNestedTemplate(a,t,n)||o,fixPlaceholder(a),a.firstChild&&this._parseTemplateChildNodes(a,t,n),a.hasAttributes&&a.hasAttributes()&&(o=this._parseTemplateNodeAttributes(a,t,n)||o),o||n.noted}static _parseTemplateChildNodes(e,t,n){if("script"!==e.localName&&"style"!==e.localName)for(let o,a=e.firstChild,r=0;a;a=o){if("template"==a.localName&&(a=wrapTemplateExtension(a)),o=a.nextSibling,a.nodeType===Node.TEXT_NODE){let n=o;for(;n&&n.nodeType===Node.TEXT_NODE;)a.textContent+=n.textContent,o=n.nextSibling,e.removeChild(n),n=o;if(t.stripWhiteSpace&&!a.textContent.trim()){e.removeChild(a);continue}}let l={parentIndex:r,parentInfo:n};this._parseTemplateNode(a,t,l)&&(l.infoIndex=t.nodeInfoList.push(l)-1),a.parentNode&&r++}}static _parseTemplateNestedTemplate(e,t,n){let o=e,a=this._parseTemplate(o,t);return(a.content=o.content.ownerDocument.createDocumentFragment()).appendChild(o.content),n.templateInfo=a,!0}static _parseTemplateNodeAttributes(e,t,n){let o=!1,a=Array.from(e.attributes);for(let r,l=a.length-1;r=a[l];l--)o=this._parseTemplateNodeAttribute(e,t,n,r.name,r.value)||o;return o}static _parseTemplateNodeAttribute(e,t,n,o,a){return"on-"===o.slice(0,3)?(e.removeAttribute(o),n.events=n.events||[],n.events.push({name:o.slice(3),value:a}),!0):"id"===o&&(n.id=a,!0)}static _contentForTemplate(e){let t=e._templateInfo;return t&&t.content||e.content}_stampTemplate(e,t){e&&!e.content&&window.HTMLTemplateElement&&HTMLTemplateElement.decorate&&HTMLTemplateElement.decorate(e);let n=(t=t||this.constructor._parseTemplate(e)).nodeInfoList,o=t.content||e.content,a=document.importNode(o,!0);a.__noInsertionPoint=!t.hasInsertionPoint;let r=a.nodeList=new Array(n.length);a.$={};for(let e,o=0,l=n.length;o<l&&(e=n[o]);o++){let n=r[o]=findTemplateNode(a,e);applyIdToMap(0,a.$,n,e),applyTemplateInfo(0,n,e,t),applyEventListener(this,n,e)}return a}_addMethodEventListenerToNode(e,t,n,o){let a=function createNodeEventHandler(e,t,n){return e=e._methodHost||e,function(t){e[n]?e[n](t,t.detail):console.warn("listener method `"+n+"` not defined")}}(o=o||e,0,n);return this._addEventListenerToNode(e,t,a),a}_addEventListenerToNode(e,t,n){e.addEventListener(t,n)}_removeEventListenerFromNode(e,t,n){e.removeEventListener(t,n)}}));