oeffisearch/client/js/lit-html.js

2 lines
9.6 KiB
JavaScript
Raw Normal View History

2020-02-07 14:09:42 +01:00
const t=new WeakMap,e=e=>(...s)=>{const n=e(...s);return t.set(n,!0),n},s=e=>"function"==typeof e&&t.has(e),n=void 0!==window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,i=(t,e,s=null,n=null)=>{let i=e;for(;i!==s;){const e=i.nextSibling;t.insertBefore(i,n),i=e}},o=(t,e,s=null)=>{let n=e;for(;n!==s;){const e=n.nextSibling;t.removeChild(n),n=e}},r={},l=`{{lit-${String(Math.random()).slice(2)}}}`,a=`\x3c!--${l}--\x3e`,h=new RegExp(`${l}|${a}`),c=(()=>{const t=document.createElement("div");return t.setAttribute("style","{{bad value}}"),"{{bad value}}"!==t.getAttribute("style")})();class d{constructor(t,e){this.parts=[],this.element=e;let s=-1,n=0;const i=[],o=e=>{const r=e.content,a=document.createTreeWalker(r,133,null,!1);let d,u;for(;a.nextNode();){s++,d=u;const e=u=a.currentNode;if(1===e.nodeType){if(e.hasAttributes()){const i=e.attributes;let o=0;for(let t=0;t<i.length;t++)i[t].value.indexOf(l)>=0&&o++;for(;o-- >0;){const i=t.strings[n],o=m.exec(i)[2],r=c&&"style"===o?"style$":/^[a-zA-Z-]*$/.test(o)?o:o.toLowerCase(),l=e.getAttribute(r).split(h);this.parts.push({type:"attribute",index:s,name:o,strings:l}),e.removeAttribute(r),n+=l.length-1}}"TEMPLATE"===e.tagName&&o(e)}else if(3===e.nodeType){const t=e.nodeValue;if(t.indexOf(l)<0)continue;const o=e.parentNode,r=t.split(h),a=r.length-1;n+=a;for(let t=0;t<a;t++)o.insertBefore(""===r[t]?p():document.createTextNode(r[t]),e),this.parts.push({type:"node",index:s++});o.insertBefore(""===r[a]?p():document.createTextNode(r[a]),e),i.push(e)}else if(8===e.nodeType)if(e.nodeValue===l){const t=e.parentNode,o=e.previousSibling;null===o||o!==d||o.nodeType!==Node.TEXT_NODE?t.insertBefore(p(),e):s--,this.parts.push({type:"node",index:s++}),i.push(e),null===e.nextSibling?t.insertBefore(p(),e):s--,u=d,n++}else{let t=-1;for(;-1!==(t=e.nodeValue.indexOf(l,t+1));)this.parts.push({type:"node",index:-1})}}};o(e);for(const t of i)t.parentNode.removeChild(t)}}const u=t=>-1!==t.index,p=()=>document.createComment(""),m=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F \x09\x0a\x0c\x0d"'>=\/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;class g{constructor(t,e,s){this._parts=[],this.template=t,this.processor=e,this.options=s}update(t){let e=0;for(const s of this._parts)void 0!==s&&s.setValue(t[e]),e++;for(const t of this._parts)void 0!==t&&t.commit()}_clone(){const t=n?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),e=this.template.parts;let s=0,i=0;const o=t=>{const n=document.createTreeWalker(t,133,null,!1);let r=n.nextNode();for(;s<e.length&&null!==r;){const t=e[s];if(u(t))if(i===t.index){if("node"===t.type){const t=this.processor.handleTextExpression(this.options);t.insertAfterNode(r),this._parts.push(t)}else this._parts.push(...this.processor.handleAttributeExpressions(r,t.name,t.strings,this.options));s++}else i++,"TEMPLATE"===r.nodeName&&o(r.content),r=n.nextNode();else this._parts.push(void 0),s++}};return o(t),n&&(document.adoptNode(t),customElements.upgrade(t)),t}}class v{constructor(t,e,s,n){this.strings=t,this.values=e,this.type=s,this.processor=n}getHTML(){const t=this.strings.length-1;let e="",s=!0;for(let n=0;n<t;n++){const t=this.strings[n];e+=t;const i=t.lastIndexOf(">");!(s=(i>-1||s)&&-1===t.indexOf("<",i+1))&&c&&(e=e.replace(m,(t,e,s,n)=>"style"===s?`${e}style$${n}`:t)),e+=s?a:l}return e+=this.strings[t]}getTemplateElement(){const t=document.createElement("template");return t.innerHTML=this.getHTML(),t}}class f extends v{getHTML(){return`<svg>${super.getHTML()}</svg>`}getTemplateElement(){const t=super.getTemplateElement(),e=t.content,s=e.firstChild;return e.removeChild(s),i(e,s.firstChild),t}}const x=t=>null===t||!("object"==typeof t||"function"==typeof t);class _{constructor(t,e,s){this.dirty=!0,this.element=t,this.name=e,this.strings=s,this.parts=[];for(let t=0;t<s.length-1;t++)this.parts[t]=this._createPart()}_createPart(){return new y(this)}_getValue(){const t=this.strings,e=t.length-1;let s="";for(let n=0;n<e;n++){s+=t[n];const e=this.parts[n];if(void 0!==e)