From 176ed41401a9a400c1ece98acf5ffa8dff8bc710 Mon Sep 17 00:00:00 2001 From: Javiani Date: Fri, 10 Jan 2025 19:19:25 -0300 Subject: [PATCH] Improving previous bug fix for more edge cases --- dist/jails.js | 2 +- dist/jails.js.map | 2 +- package.json | 2 +- src/template-system.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/jails.js b/dist/jails.js index 6cc173c..ea640d8 100644 --- a/dist/jails.js +++ b/dist/jails.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jails={})}(this,(function(e){"use strict";const t=new DOMParser;const n=(e,t,n)=>{var r,o;null==(r=t.parentNode)||r.insertBefore(e,t),null==(o=t.parentNode)||o.insertBefore(n,t.nextSibling)},r=document.createElement("textarea"),o=e=>(r.innerHTML=e,r.value),l=e=>requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,1e3/60),i=e=>JSON.parse(JSON.stringify(e)),a=e=>{var t,n,r,o=e.attributes;if(o)for(t=o.length-1;t>=0;t-=1)"function"==typeof e[r=o[t].name]&&(e[r]=null);if(o=e.childNodes)for(n=o.length,t=0;t{try{return e()}catch(n){return t||""}},c={tags:["{{","}}"]};function u(e){m(e);const r=function(e,r){const o=new RegExp(`\\${r.tags[0]}(.+?)\\${r.tags[1]}`,"g"),l=t.parseFromString(e.replace(/<\/?template[^>]*>/g,""),"text/html");return l.querySelectorAll("[html-for], [html-if], [html-inner], [html-class], [html-model]").forEach((e=>{const t=e.getAttribute("html-foreach"),r=e.getAttribute("html-for"),o=e.getAttribute("html-if"),l=e.getAttribute("html-inner"),i=e.getAttribute("html-class"),a=r||t;if(a){const t=r?"html-for":"html-foreach",o=a.match(/(.*)\sin\s(.*)/)||"",l=o[1],i=o[2];e.removeAttribute(t),e.setAttribute("scope","");const s=document.createElement("script");s.dataset.scope="",s.type="text/html",s.text="%%_= $scope _%%",e.appendChild(s);const c=document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${i} }) ){ var ${l} = ${i}[$key]; var $scope = JSON.stringify({ '${l}':${l}, $index: $index, $key:$key }); _%%`),u=document.createTextNode("%%_ $index++; } })() _%%");n(c,e,u)}if(o){e.removeAttribute("html-if");const t=document.createTextNode(`%%_ if ( safe(function(){ return ${o} }) ){ _%%`),r=document.createTextNode("%%_ } _%%");n(t,e,r)}l&&(e.removeAttribute("html-inner"),e.innerHTML=`%%_=${l}_%%`),i&&(e.removeAttribute("html-class"),e.className=(e.className+` %%_=${i}_%%`).trim())})),l.body.innerHTML.replace(o,"%%_=$1_%%").replace(/html-(allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|formnovalidate|inert|ismap|itemscope|loop|multiple|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|selected)=\"(.*?)\"/g,"%%_if(safe(function(){ return $2 })){_%%$1%%_}_%%").replace(/html-(.*?)=\"(.*?)\"/g,((e,t,n)=>"key"===t||"model"===t||"scope"==t?e:n?`${t}="%%_=safe(function(){ return ${n=n.replace(/^{|}$/g,"")} })_%%"`:e))}(e.outerHTML,c),l=JSON.stringify(r);return new Function("$element","safe",`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${l.replace(/%%_=(.+?)_%%/g,(function(e,t){return'"+safe(function(){return '+o(t)+';})+"'})).replace(/%%_(.+?)_%%/g,(function(e,t){return'";'+o(t)+'\noutput+="'}))};return output;\n\t\t}\n\t`)}const d=(e,t,n,r)=>{[].concat(e.matches&&e.matches(t)?e:[]).concat(Array.from(e.querySelectorAll(t))).reverse().forEach((e=>{e.querySelectorAll("template").forEach((e=>d(e.content,t,n,r))),f(e,n,r)}))},f=(e,t,n)=>{if(!e.getAttribute("tplid")){const r="xxxxxxxx".replace(/[xy]/g,(e=>{const t=8*Math.random()|0;return("x"==e?t:3&t|8).toString(8)}));e.setAttribute("tplid",r);const o=e.localName;if(o in n&&n[o].module.template){const l=e.innerHTML,i=n[o].module.template({children:l});i.constructor===Promise?(e.__template=i,i.then((n=>{e.innerHTML=n,t[r]=u(e)}))):e.innerHTML=i}t[r]=u(e)}},m=e=>{e.querySelectorAll("[html-if]").forEach((e=>{e.parentNode.insertBefore(document.createComment("[html-if]"),e.nextSibling)}))},h={},p={},b=(e,t)=>{p[e]=Object.assign({},p[e],t),h[e]&&h[e].forEach((e=>e(t)))},v=(e,t)=>(h[e]=h[e]||[],h[e].push(t),e in p&&t(p[e]),()=>{h[e]=h[e].filter((e=>e!=t))});var g=function(){let e=new Set,t={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:u,afterNodeAdded:u,beforeNodeMorphed:u,afterNodeMorphed:u,beforeNodeRemoved:u,afterNodeRemoved:u,beforeAttributeUpdated:u,beforeNodePantried:u},head:{style:"merge",shouldPreserve:function(e){return"true"===e.getAttribute("im-preserve")},shouldReAppend:function(e){return"true"===e.getAttribute("im-re-append")},shouldRemove:u,afterHeadMorphed:u}};function n(e,t,r){var i,a;if(r.head.block){let o=e.querySelector("head"),l=t.querySelector("head");if(o&&l){let i=c(l,o,r);return void Promise.all(i).then((function(){n(e,t,Object.assign(r,{head:{block:!1,ignore:!0}}))}))}}if("innerHTML"===r.morphStyle)return l(t,e,r),r.config.twoPass&&A(e,r),Array.from(e.children);if("outerHTML"!==r.morphStyle&&null!=r.morphStyle)throw"Do not understand how to morph style "+r.morphStyle;{let n=function(e,t,n){let r;r=e.firstChild;let o=r,l=0;for(;r;){let e=g(r,t,n);e>l&&(o=r,l=e),r=r.nextSibling}return o}(t,e,r),l=null!=(i=null==n?void 0:n.previousSibling)?i:null,s=null!=(a=null==n?void 0:n.nextSibling)?a:null,c=o(e,n,r);if(!n)return[];if(c){const e=function(e,t,n){var r,o;let l=[],i=[];for(;null!=e;)l.push(e),e=e.previousSibling;let a=l.pop();for(;void 0!==a;)i.push(a),null==(r=t.parentElement)||r.insertBefore(a,t),a=l.pop();i.push(t);for(;null!=n;)l.push(n),i.push(n),n=n.nextSibling;for(;l.length>0;){const e=l.pop();null==(o=t.parentElement)||o.insertBefore(e,t.nextSibling)}return i}(l,c,s);return r.config.twoPass&&A(c.parentNode,r),e}}}function r(e,t){return!!t.ignoreActiveValue&&e===document.activeElement&&e!==document.body}function o(e,t,n){var o,i;return n.ignoreActive&&e===document.activeElement?null:null==t?!1===n.callbacks.beforeNodeRemoved(e)?e:(null==(o=e.parentNode)||o.removeChild(e),n.callbacks.afterNodeRemoved(e),null):m(e,t)?(!1===n.callbacks.beforeNodeMorphed(e,t)||(e instanceof HTMLHeadElement&&n.head.ignore||(e instanceof HTMLHeadElement&&"morph"!==n.head.style?c(t,e,n):(a(t,e,n),r(e,n)||l(t,e,n))),n.callbacks.afterNodeMorphed(e,t)),e):!1===n.callbacks.beforeNodeRemoved(e)||!1===n.callbacks.beforeNodeAdded(t)?e:(null==(i=e.parentNode)||i.replaceChild(t,e),n.callbacks.afterNodeAdded(t),n.callbacks.afterNodeRemoved(e),t)}function l(e,t,n){e instanceof HTMLTemplateElement&&t instanceof HTMLTemplateElement&&(e=e.content,t=t.content);let r,l=e.firstChild,i=t.firstChild;for(;l;){if(r=l,l=r.nextSibling,null==i){if(n.config.twoPass&&n.persistentIds.has(r.id))t.appendChild(r);else{if(!1===n.callbacks.beforeNodeAdded(r))continue;t.appendChild(r),n.callbacks.afterNodeAdded(r)}S(n,r);continue}if(f(r,i,n)){o(i,r,n),i=i.nextSibling,S(n,r);continue}let a=p(e,t,r,i,n);if(a){i=h(i,a,n),o(a,r,n),S(n,r);continue}let s=b(e,t,r,i,n);if(s)i=h(i,s,n),o(s,r,n),S(n,r);else{if(n.config.twoPass&&n.persistentIds.has(r.id))t.insertBefore(r,i);else{if(!1===n.callbacks.beforeNodeAdded(r))continue;t.insertBefore(r,i),n.callbacks.afterNodeAdded(r)}S(n,r)}}for(;null!==i;){let e=i;i=i.nextSibling,_(e,n)}}function i(e,t,n,r){return!("value"!==e||!r.ignoreActiveValue||t!==document.activeElement)||!1===r.callbacks.beforeAttributeUpdated(e,t,n)}function a(e,t,n){let o=e.nodeType;if(1===o){const r=e,o=t,l=r.attributes,a=o.attributes;for(const e of l)i(e.name,o,"update",n)||o.getAttribute(e.name)!==e.value&&o.setAttribute(e.name,e.value);for(let e=a.length-1;0<=e;e--){const t=a[e];if(t&&!r.hasAttribute(t.name)){if(i(t.name,o,"remove",n))continue;o.removeAttribute(t.name)}}}8!==o&&3!==o||t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue),r(t,n)||function(e,t,n){if(e instanceof HTMLInputElement&&t instanceof HTMLInputElement&&"file"!==e.type){let r=e.value,o=t.value;s(e,t,"checked",n),s(e,t,"disabled",n),e.hasAttribute("value")?r!==o&&(i("value",t,"update",n)||(t.setAttribute("value",r),t.value=r)):i("value",t,"remove",n)||(t.value="",t.removeAttribute("value"))}else if(e instanceof HTMLOptionElement&&t instanceof HTMLOptionElement)s(e,t,"selected",n);else if(e instanceof HTMLTextAreaElement&&t instanceof HTMLTextAreaElement){let r=e.value,o=t.value;if(i("value",t,"update",n))return;r!==o&&(t.value=r),t.firstChild&&t.firstChild.nodeValue!==r&&(t.firstChild.nodeValue=r)}}(e,t,n)}function s(e,t,n,r){if(!(e instanceof Element&&t instanceof Element))return;const o=e[n];if(o!==t[n]){let l=i(n,t,"update",r);l||(t[n]=e[n]),o?l||t.setAttribute(n,o):i(n,t,"remove",r)||t.removeAttribute(n)}}function c(e,t,n){let r=[],o=[],l=[],i=[],a=n.head.style,s=new Map;for(const u of e.children)s.set(u.outerHTML,u);for(const u of t.children){let e=s.has(u.outerHTML),t=n.head.shouldReAppend(u),r=n.head.shouldPreserve(u);e||r?t?o.push(u):(s.delete(u.outerHTML),l.push(u)):"append"===a?t&&(o.push(u),i.push(u)):!1!==n.head.shouldRemove(u)&&o.push(u)}i.push(...s.values());let c=[];for(const u of i){let e=document.createRange().createContextualFragment(u.outerHTML).firstChild;if(!1!==n.callbacks.beforeNodeAdded(e)){if("href"in e&&e.href||"src"in e&&e.src){let t,n=new Promise((function(e){t=e}));e.addEventListener("load",(function(){t()})),c.push(n)}t.appendChild(e),n.callbacks.afterNodeAdded(e),r.push(e)}}for(const u of o)!1!==n.callbacks.beforeNodeRemoved(u)&&(t.removeChild(u),n.callbacks.afterNodeRemoved(u));return n.head.afterHeadMorphed(t,{added:r,kept:l,removed:o}),c}function u(){}function d(){const e=document.createElement("div");return e.hidden=!0,document.body.insertAdjacentElement("afterend",e),e}function f(e,t,n){return null!=e&&null!=t&&(e instanceof Element&&t instanceof Element&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||k(n,e,t)>0))}function m(e,t){return null!=e&&null!=t&&((!e.id||e.id===t.id)&&(e.nodeType===t.nodeType&&e.tagName===t.tagName))}function h(e,t,n){let r=e;for(;r!==t;){let e=r;r=e.nextSibling,_(e,n)}return S(n,t),t.nextSibling}function p(e,t,n,r,o){let l=k(o,n,t),i=null;if(l>0){i=r;let t=0;for(;null!=i;){if(f(n,i,o))return i;if(t+=k(o,i,e),t>l)return null;i=i.nextSibling}}return i}function b(e,t,n,r,o){let l=r,i=n.nextSibling,a=0;for(;null!=l;){if(k(o,l,e)>0)return null;if(m(l,n))return l;if(m(l,i)&&(a++,i=i.nextSibling,a>=2))return null;l=l.nextSibling}return l}const v=new WeakSet;function g(e,t,n){return m(t,e)?.5+k(n,e,t):0}function _(t,n){var r;if(S(n,t),n.config.twoPass&&function(t,n){for(const r of t.idMap.get(n)||e)if(t.persistentIds.has(r))return!0;return!1}(n,t)&&t instanceof Element)y(t,n);else{if(!1===n.callbacks.beforeNodeRemoved(t))return;null==(r=t.parentNode)||r.removeChild(t),n.callbacks.afterNodeRemoved(t)}}function y(e,t){var n;if(!1!==t.callbacks.beforeNodePantried(e))if(Array.from(e.childNodes).forEach((e=>{y(e,t)})),t.persistentIds.has(e.id))t.pantry.moveBefore?t.pantry.moveBefore(e,null):t.pantry.insertBefore(e,null);else{if(!1===t.callbacks.beforeNodeRemoved(e))return;null==(n=e.parentNode)||n.removeChild(e),t.callbacks.afterNodeRemoved(e)}}function A(e,t){e instanceof Element&&(Array.from(t.pantry.children).reverse().forEach((n=>{var r;const o=e.querySelector(`#${n.id}`);if(o){if(null==(r=o.parentElement)?void 0:r.moveBefore)for(o.parentElement.moveBefore(n,o);o.hasChildNodes();)n.moveBefore(o.firstChild,null);else for(o.before(n);o.firstChild;)n.insertBefore(o.firstChild,null);!1!==t.callbacks.beforeNodeMorphed(n,o)&&(a(o,n,t),t.callbacks.afterNodeMorphed(n,o)),o.remove()}})),t.pantry.remove())}function E(e,t){return!e.deadIds.has(t)}function N(t,n,r){return(t.idMap.get(r)||e).has(n)}function S(t,n){let r=t.idMap.get(n)||e;for(const e of r)t.deadIds.add(e)}function k(t,n,r){let o=t.idMap.get(n)||e,l=0;for(const e of o)E(t,e)&&N(t,e,r)&&++l;return l}function x(e){let t=Array.from(e.querySelectorAll("[id]"));return e.id&&t.push(e),t}function M(e,t){let n=e.parentElement;for(const r of x(e)){let e=r;for(;e!==n&&null!=e;){let n=t.get(e);null==n&&(n=new Set,t.set(e,n)),n.add(r.id),e=e.parentElement}}}function T(e,t){let n=new Map;return M(e,n),M(t,n),n}function w(e,t){const n=e=>e.tagName+"#"+e.id,r=new Set(x(e).map(n));let o=new Set;for(const l of x(t))r.has(n(l))&&o.add(l.id);return o}return{morph:function(e,r,o={}){e instanceof Document&&(e=e.documentElement),"string"==typeof r&&(r=function(e){let t=new DOMParser,n=e.replace(/]*>|>)([\s\S]*?)<\/svg>/gim,"");if(n.match(/<\/html>/)||n.match(/<\/head>/)||n.match(/<\/body>/)){let r=t.parseFromString(e,"text/html");if(n.match(/<\/html>/))return v.add(r),r;{let e=r.firstChild;return e?(v.add(e),e):null}}{let n=t.parseFromString("","text/html").body.querySelector("template").content;return v.add(n),n}}(r));let l=function(e){if(null==e){return document.createElement("div")}if(v.has(e))return e;if(e instanceof Node){const t=document.createElement("div");return t.append(e),t}{const t=document.createElement("div");for(const n of[...e])t.append(n);return t}}(r),i=function(e,n,r){const o=function(e){let n=Object.assign({},t);return Object.assign(n,e),n.callbacks=Object.assign({},t.callbacks,e.callbacks),n.head=Object.assign({},t.head,e.head),n}(r);return{target:e,newContent:n,config:o,morphStyle:o.morphStyle,ignoreActive:o.ignoreActive,ignoreActiveValue:o.ignoreActiveValue,idMap:T(e,n),deadIds:new Set,persistentIds:o.twoPass?w(e,n):new Set,pantry:o.twoPass?d():document.createElement("div"),callbacks:o.callbacks,head:o.head}}(e,l,o);return n(e,l,i)},defaults:t}}();const _="CustomEvent"in window&&"function"==typeof window.CustomEvent?(e,t)=>new CustomEvent(e,t):(e,t)=>{const n=document.createEvent("CustomEvent");return n.initCustomEvent(e,!0,!0,t),n},y=(e,t)=>function(n){const r=this,o=n.detail||{};e.__events[t].forEach((e=>{e.handler.apply(r,[n].concat(o.args))}))},A=(e,t)=>{e.__events[t]&&e.__events[t].listener&&(e.removeEventListener(t,e.__events[t].listener,"focus"==t||"blur"==t||"mouseenter"==t||"mouseleave"==t),delete e.__events[t])},E=(e,t,n)=>function(r){const o=this,l=r.detail||{};let i=r.target;for(;i&&(i.matches(t)&&(r.delegateTarget=i,n.apply(o,[r].concat(l.args))),i!==e);)i=i.parentNode},N=(e,t,n,r)=>{if(e.__events=e.__events||{},e.__events[t]=e.__events[t]||[],!e.__events[t].length){const n=y(e,t);e.addEventListener(t,n,"focus"==t||"blur"==t||"mouseenter"==t||"mouseleave"==t),e.__events[t].listener=n}n.call?e.__events[t].push({handler:n,callback:n}):e.__events[t].push({handler:E(e,n,r),callback:r})},S=(e,t,n)=>{if(n&&e.__events[t]&&e.__events[t].length){var r=e.__events[t];e.__events[t]=e.__events[t].filter((function(e){return e.callback!=n})),e.__events[t].listener=r.listener,e.__events[t].length||A(e,t)}else A(e,t)},k=(e,t,n)=>{e.dispatchEvent(_(t,{bubbles:!0,detail:n}))};const x=e=>({main:e=>e,unmount:e=>e,onupdate:e=>e,view:e.view?e.view:e=>e}),M=e=>{e.querySelectorAll("[scope]").forEach((e=>{e.querySelectorAll("[tplid]").forEach((t=>{if(!t.___scope___){const n=e.lastElementChild;t.___scope___="scope"in n.dataset?new Function(`return ${n.text}`)():{}}}))}))},T=e=>({callbacks:{beforeNodeMorphed(t){if(1===t.nodeType){if("html-static"in t.attributes)return!1;if(t.base&&t!==e)return!1}}}});function w(e,t,n,r){return class extends HTMLElement{constructor(){super()}connectedCallback(){const{base:o,options:a}=function(e,{module:t,dependencies:n,templates:r,components:o}){const a=x(t),c=new Function(`return ${e.getAttribute("html-model")||"{}"}`)(),u=Object.keys(o).toString();d(e,u,r,o);const f=e.getAttribute("tplid"),m=f?r[f]:null,h={data:t.model?i(t.model):{}};h.data=Object.assign(h.data,c);const p={template:m,elm:e,dependencies:n,publish:b,subscribe:v,main(e){a.main=e},unmount(e){a.unmount=e},onupdate(e){a.onupdate=e},on(t,n,r){N(e,t,n,r)},off(t,n){S(e,t,n)},trigger(t,n,r){n.constructor===String?Array.from(e.querySelectorAll(n)).forEach((e=>k(e,t,{args:r}))):k(e,t,{args:n})},emit:(...t)=>{k(e,t.shift(),{args:t})},state:{set(e){if(e.constructor===Function){const t=i(h.data);e(t),p.render(t)}else p.render(e);return new Promise((e=>l((t=>l((()=>e(h.data)))))))},get:()=>i(h.data),getRaw:()=>h.data},render(t=h.data){if(!document.body.contains(e))return;h.data=Object.assign(h.data,t);const n=i(h.data),o=r[f].call(Object.assign(a.view(n),e.___scope___),e,s);g.morph(e,o,T(e)),M(e),l((n=>{Array.from(e.querySelectorAll("[tplid]")).forEach((e=>{const n=Object.assign(e.base.state.getRaw(),t);e.options.onupdate(n),e.base.render(n)}))}))},innerHTML(t,n){const r=n?t:e,o=r.cloneNode(),i=n||t;o.innerHTML=i,l((e=>g.morph(r,o,T)))}};return{base:p,options:a}}(this,{module:e,dependencies:t,templates:n,components:r});if(this.base=o,this.options=a,this.base.render(),this.returns=e.default(o),this.__template&&this.__template.constructor===Promise)this.__template.then((e=>{if(this.base&&this.options.main){const e=this.options.main(this.base);e&&e.length&&e.forEach((e=>e(this.base)))}}));else if(this.returns&&this.returns.constructor===Promise)this.returns.then((e=>{if(this.base&&this.options.main){const e=this.options.main(this.base);e&&e.length&&e.forEach((e=>e(this.base)))}}));else if(this.base&&this.options.main){const e=this.options.main(this.base);e&&e.length&&e.forEach((e=>e(this.base)))}}disconnectedCallback(){this.options.unmount(this.base),l((()=>{document.body.contains(this)||(this.__events&&(this.__events=null),this.base&&(this.base.elm=null),this.base&&(this.base=null),a(this))}))}attributeChangedCallback(){}}}const C={},$={},H={templateConfig:e=>{Object.assign(c,e)},publish:b,subscribe:v,register(e,t,n={}){$[e]={name:e,module:t,dependencies:n}},start(e=document.body){const t=Object.keys($),n=t.toString();t.length&&(d(e,n,C,$),L())}},L=()=>{Object.values($).forEach((e=>{const{name:t,module:n,dependencies:r}=e;if(!customElements.get(t)){const e=w(n,r,C,$);customElements.define(t,e)}}))};e.attributes=e=>Object.entries(e).map((([e,t])=>""===t?e:`${e}="${t}"`)).join(" "),e.default=H,e.html=(e,...t)=>{let n=e.raw,r="";return t.forEach(((e,t)=>{let o=n[t];Array.isArray(e)&&(e=e.join("")),r+=o,r+=e})),r+=n[n.length-1],r},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jails={})}(this,(function(e){"use strict";const t=new DOMParser;const n=(e,t,n)=>{var r,o;null==(r=t.parentNode)||r.insertBefore(e,t),null==(o=t.parentNode)||o.insertBefore(n,t.nextSibling)},r=document.createElement("textarea"),o=e=>(r.innerHTML=e,r.value),l=e=>requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,1e3/60),i=e=>JSON.parse(JSON.stringify(e)),a=e=>{var t,n,r,o=e.attributes;if(o)for(t=o.length-1;t>=0;t-=1)"function"==typeof e[r=o[t].name]&&(e[r]=null);if(o=e.childNodes)for(n=o.length,t=0;t{try{return e()}catch(n){return t||""}},c={tags:["${","}"]};function u(e){m(e);const r=function(e,r){const o=new RegExp(`\\${r.tags[0]}(.+?)\\${r.tags[1]}`,"g"),l=t.parseFromString(e.replace(/<\/?template[^>]*>/g,""),"text/html");return l.querySelectorAll("[html-for], [html-if], [html-inner], [html-class], [html-model]").forEach((e=>{const t=e.getAttribute("html-foreach"),r=e.getAttribute("html-for"),o=e.getAttribute("html-if"),l=e.getAttribute("html-inner"),i=e.getAttribute("html-class"),a=r||t;if(a){const t=r?"html-for":"html-foreach",o=a.match(/(.*)\sin\s(.*)/)||"",l=o[1],i=o[2];e.removeAttribute(t),e.setAttribute("scope","");const s=document.createElement("script");s.dataset.scope="",s.type="text/html",s.text="%%_= $scope _%%",e.appendChild(s);const c=document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${i} }) ){ var ${l} = ${i}[$key]; var $scope = JSON.stringify({ '${l}':${l}, $index: $index, $key:$key }); _%%`),u=document.createTextNode("%%_ $index++; } })() _%%");n(c,e,u)}if(o){e.removeAttribute("html-if");const t=document.createTextNode(`%%_ if ( safe(function(){ return ${o} }) ){ _%%`),r=document.createTextNode("%%_ } _%%");n(t,e,r)}l&&(e.removeAttribute("html-inner"),e.innerHTML=`%%_=${l}_%%`),i&&(e.removeAttribute("html-class"),e.className=(e.className+` %%_=${i}_%%`).trim())})),l.body.innerHTML.replace(o,"%%_=$1_%%").replace(/html-(allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|formnovalidate|inert|ismap|itemscope|loop|multiple|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|selected)=\"(.*?)\"/g,"%%_if(safe(function(){ return $2 })){_%%$1%%_}_%%").replace(/html-(.*?)=\"(.*?)\"/g,((e,t,n)=>"key"===t||"model"===t||"scope"==t?e:n?`${t}="%%_=safe(function(){ return ${n=n.replace(/^{|}$/g,"")} })_%%"`:e))}(e.outerHTML,c),l=JSON.stringify(r);return new Function("$element","safe",`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${l.replace(/%%_=(.+?)_%%/g,(function(e,t){return'"+safe(function(){return '+o(t)+';})+"'})).replace(/%%_(.+?)_%%/g,(function(e,t){return'";'+o(t)+'\noutput+="'}))};return output;\n\t\t}\n\t`)}const d=(e,t,n,r)=>{[].concat(e.matches&&e.matches(t)?e:[]).concat(Array.from(e.querySelectorAll(t))).reverse().forEach((e=>{e.querySelectorAll("template").forEach((e=>d(e.content,t,n,r))),f(e,n,r)}))},f=(e,t,n)=>{if(!e.getAttribute("tplid")){const r="xxxxxxxx".replace(/[xy]/g,(e=>{const t=8*Math.random()|0;return("x"==e?t:3&t|8).toString(8)}));e.setAttribute("tplid",r);const o=e.localName;if(o in n&&n[o].module.template){const l=e.innerHTML,i=n[o].module.template({children:l});i.constructor===Promise?(e.__template=i,i.then((n=>{e.innerHTML=n,t[r]=u(e)}))):e.innerHTML=i}t[r]=u(e)}},m=e=>{e.querySelectorAll("[html-if]").forEach((e=>{e.parentNode.insertBefore(document.createComment(""),e.nextSibling)}))},h={},p={},b=(e,t)=>{p[e]=Object.assign({},p[e],t),h[e]&&h[e].forEach((e=>e(t)))},v=(e,t)=>(h[e]=h[e]||[],h[e].push(t),e in p&&t(p[e]),()=>{h[e]=h[e].filter((e=>e!=t))});var g=function(){let e=new Set,t={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:u,afterNodeAdded:u,beforeNodeMorphed:u,afterNodeMorphed:u,beforeNodeRemoved:u,afterNodeRemoved:u,beforeAttributeUpdated:u,beforeNodePantried:u},head:{style:"merge",shouldPreserve:function(e){return"true"===e.getAttribute("im-preserve")},shouldReAppend:function(e){return"true"===e.getAttribute("im-re-append")},shouldRemove:u,afterHeadMorphed:u}};function n(e,t,r){var i,a;if(r.head.block){let o=e.querySelector("head"),l=t.querySelector("head");if(o&&l){let i=c(l,o,r);return void Promise.all(i).then((function(){n(e,t,Object.assign(r,{head:{block:!1,ignore:!0}}))}))}}if("innerHTML"===r.morphStyle)return l(t,e,r),r.config.twoPass&&A(e,r),Array.from(e.children);if("outerHTML"!==r.morphStyle&&null!=r.morphStyle)throw"Do not understand how to morph style "+r.morphStyle;{let n=function(e,t,n){let r;r=e.firstChild;let o=r,l=0;for(;r;){let e=g(r,t,n);e>l&&(o=r,l=e),r=r.nextSibling}return o}(t,e,r),l=null!=(i=null==n?void 0:n.previousSibling)?i:null,s=null!=(a=null==n?void 0:n.nextSibling)?a:null,c=o(e,n,r);if(!n)return[];if(c){const e=function(e,t,n){var r,o;let l=[],i=[];for(;null!=e;)l.push(e),e=e.previousSibling;let a=l.pop();for(;void 0!==a;)i.push(a),null==(r=t.parentElement)||r.insertBefore(a,t),a=l.pop();i.push(t);for(;null!=n;)l.push(n),i.push(n),n=n.nextSibling;for(;l.length>0;){const e=l.pop();null==(o=t.parentElement)||o.insertBefore(e,t.nextSibling)}return i}(l,c,s);return r.config.twoPass&&A(c.parentNode,r),e}}}function r(e,t){return!!t.ignoreActiveValue&&e===document.activeElement&&e!==document.body}function o(e,t,n){var o,i;return n.ignoreActive&&e===document.activeElement?null:null==t?!1===n.callbacks.beforeNodeRemoved(e)?e:(null==(o=e.parentNode)||o.removeChild(e),n.callbacks.afterNodeRemoved(e),null):m(e,t)?(!1===n.callbacks.beforeNodeMorphed(e,t)||(e instanceof HTMLHeadElement&&n.head.ignore||(e instanceof HTMLHeadElement&&"morph"!==n.head.style?c(t,e,n):(a(t,e,n),r(e,n)||l(t,e,n))),n.callbacks.afterNodeMorphed(e,t)),e):!1===n.callbacks.beforeNodeRemoved(e)||!1===n.callbacks.beforeNodeAdded(t)?e:(null==(i=e.parentNode)||i.replaceChild(t,e),n.callbacks.afterNodeAdded(t),n.callbacks.afterNodeRemoved(e),t)}function l(e,t,n){e instanceof HTMLTemplateElement&&t instanceof HTMLTemplateElement&&(e=e.content,t=t.content);let r,l=e.firstChild,i=t.firstChild;for(;l;){if(r=l,l=r.nextSibling,null==i){if(n.config.twoPass&&n.persistentIds.has(r.id))t.appendChild(r);else{if(!1===n.callbacks.beforeNodeAdded(r))continue;t.appendChild(r),n.callbacks.afterNodeAdded(r)}S(n,r);continue}if(f(r,i,n)){o(i,r,n),i=i.nextSibling,S(n,r);continue}let a=p(e,t,r,i,n);if(a){i=h(i,a,n),o(a,r,n),S(n,r);continue}let s=b(e,t,r,i,n);if(s)i=h(i,s,n),o(s,r,n),S(n,r);else{if(n.config.twoPass&&n.persistentIds.has(r.id))t.insertBefore(r,i);else{if(!1===n.callbacks.beforeNodeAdded(r))continue;t.insertBefore(r,i),n.callbacks.afterNodeAdded(r)}S(n,r)}}for(;null!==i;){let e=i;i=i.nextSibling,_(e,n)}}function i(e,t,n,r){return!("value"!==e||!r.ignoreActiveValue||t!==document.activeElement)||!1===r.callbacks.beforeAttributeUpdated(e,t,n)}function a(e,t,n){let o=e.nodeType;if(1===o){const r=e,o=t,l=r.attributes,a=o.attributes;for(const e of l)i(e.name,o,"update",n)||o.getAttribute(e.name)!==e.value&&o.setAttribute(e.name,e.value);for(let e=a.length-1;0<=e;e--){const t=a[e];if(t&&!r.hasAttribute(t.name)){if(i(t.name,o,"remove",n))continue;o.removeAttribute(t.name)}}}8!==o&&3!==o||t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue),r(t,n)||function(e,t,n){if(e instanceof HTMLInputElement&&t instanceof HTMLInputElement&&"file"!==e.type){let r=e.value,o=t.value;s(e,t,"checked",n),s(e,t,"disabled",n),e.hasAttribute("value")?r!==o&&(i("value",t,"update",n)||(t.setAttribute("value",r),t.value=r)):i("value",t,"remove",n)||(t.value="",t.removeAttribute("value"))}else if(e instanceof HTMLOptionElement&&t instanceof HTMLOptionElement)s(e,t,"selected",n);else if(e instanceof HTMLTextAreaElement&&t instanceof HTMLTextAreaElement){let r=e.value,o=t.value;if(i("value",t,"update",n))return;r!==o&&(t.value=r),t.firstChild&&t.firstChild.nodeValue!==r&&(t.firstChild.nodeValue=r)}}(e,t,n)}function s(e,t,n,r){if(!(e instanceof Element&&t instanceof Element))return;const o=e[n];if(o!==t[n]){let l=i(n,t,"update",r);l||(t[n]=e[n]),o?l||t.setAttribute(n,o):i(n,t,"remove",r)||t.removeAttribute(n)}}function c(e,t,n){let r=[],o=[],l=[],i=[],a=n.head.style,s=new Map;for(const u of e.children)s.set(u.outerHTML,u);for(const u of t.children){let e=s.has(u.outerHTML),t=n.head.shouldReAppend(u),r=n.head.shouldPreserve(u);e||r?t?o.push(u):(s.delete(u.outerHTML),l.push(u)):"append"===a?t&&(o.push(u),i.push(u)):!1!==n.head.shouldRemove(u)&&o.push(u)}i.push(...s.values());let c=[];for(const u of i){let e=document.createRange().createContextualFragment(u.outerHTML).firstChild;if(!1!==n.callbacks.beforeNodeAdded(e)){if("href"in e&&e.href||"src"in e&&e.src){let t,n=new Promise((function(e){t=e}));e.addEventListener("load",(function(){t()})),c.push(n)}t.appendChild(e),n.callbacks.afterNodeAdded(e),r.push(e)}}for(const u of o)!1!==n.callbacks.beforeNodeRemoved(u)&&(t.removeChild(u),n.callbacks.afterNodeRemoved(u));return n.head.afterHeadMorphed(t,{added:r,kept:l,removed:o}),c}function u(){}function d(){const e=document.createElement("div");return e.hidden=!0,document.body.insertAdjacentElement("afterend",e),e}function f(e,t,n){return null!=e&&null!=t&&(e instanceof Element&&t instanceof Element&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||k(n,e,t)>0))}function m(e,t){return null!=e&&null!=t&&((!e.id||e.id===t.id)&&(e.nodeType===t.nodeType&&e.tagName===t.tagName))}function h(e,t,n){let r=e;for(;r!==t;){let e=r;r=e.nextSibling,_(e,n)}return S(n,t),t.nextSibling}function p(e,t,n,r,o){let l=k(o,n,t),i=null;if(l>0){i=r;let t=0;for(;null!=i;){if(f(n,i,o))return i;if(t+=k(o,i,e),t>l)return null;i=i.nextSibling}}return i}function b(e,t,n,r,o){let l=r,i=n.nextSibling,a=0;for(;null!=l;){if(k(o,l,e)>0)return null;if(m(l,n))return l;if(m(l,i)&&(a++,i=i.nextSibling,a>=2))return null;l=l.nextSibling}return l}const v=new WeakSet;function g(e,t,n){return m(t,e)?.5+k(n,e,t):0}function _(t,n){var r;if(S(n,t),n.config.twoPass&&function(t,n){for(const r of t.idMap.get(n)||e)if(t.persistentIds.has(r))return!0;return!1}(n,t)&&t instanceof Element)y(t,n);else{if(!1===n.callbacks.beforeNodeRemoved(t))return;null==(r=t.parentNode)||r.removeChild(t),n.callbacks.afterNodeRemoved(t)}}function y(e,t){var n;if(!1!==t.callbacks.beforeNodePantried(e))if(Array.from(e.childNodes).forEach((e=>{y(e,t)})),t.persistentIds.has(e.id))t.pantry.moveBefore?t.pantry.moveBefore(e,null):t.pantry.insertBefore(e,null);else{if(!1===t.callbacks.beforeNodeRemoved(e))return;null==(n=e.parentNode)||n.removeChild(e),t.callbacks.afterNodeRemoved(e)}}function A(e,t){e instanceof Element&&(Array.from(t.pantry.children).reverse().forEach((n=>{var r;const o=e.querySelector(`#${n.id}`);if(o){if(null==(r=o.parentElement)?void 0:r.moveBefore)for(o.parentElement.moveBefore(n,o);o.hasChildNodes();)n.moveBefore(o.firstChild,null);else for(o.before(n);o.firstChild;)n.insertBefore(o.firstChild,null);!1!==t.callbacks.beforeNodeMorphed(n,o)&&(a(o,n,t),t.callbacks.afterNodeMorphed(n,o)),o.remove()}})),t.pantry.remove())}function E(e,t){return!e.deadIds.has(t)}function N(t,n,r){return(t.idMap.get(r)||e).has(n)}function S(t,n){let r=t.idMap.get(n)||e;for(const e of r)t.deadIds.add(e)}function k(t,n,r){let o=t.idMap.get(n)||e,l=0;for(const e of o)E(t,e)&&N(t,e,r)&&++l;return l}function x(e){let t=Array.from(e.querySelectorAll("[id]"));return e.id&&t.push(e),t}function M(e,t){let n=e.parentElement;for(const r of x(e)){let e=r;for(;e!==n&&null!=e;){let n=t.get(e);null==n&&(n=new Set,t.set(e,n)),n.add(r.id),e=e.parentElement}}}function T(e,t){let n=new Map;return M(e,n),M(t,n),n}function w(e,t){const n=e=>e.tagName+"#"+e.id,r=new Set(x(e).map(n));let o=new Set;for(const l of x(t))r.has(n(l))&&o.add(l.id);return o}return{morph:function(e,r,o={}){e instanceof Document&&(e=e.documentElement),"string"==typeof r&&(r=function(e){let t=new DOMParser,n=e.replace(/]*>|>)([\s\S]*?)<\/svg>/gim,"");if(n.match(/<\/html>/)||n.match(/<\/head>/)||n.match(/<\/body>/)){let r=t.parseFromString(e,"text/html");if(n.match(/<\/html>/))return v.add(r),r;{let e=r.firstChild;return e?(v.add(e),e):null}}{let n=t.parseFromString("","text/html").body.querySelector("template").content;return v.add(n),n}}(r));let l=function(e){if(null==e){return document.createElement("div")}if(v.has(e))return e;if(e instanceof Node){const t=document.createElement("div");return t.append(e),t}{const t=document.createElement("div");for(const n of[...e])t.append(n);return t}}(r),i=function(e,n,r){const o=function(e){let n=Object.assign({},t);return Object.assign(n,e),n.callbacks=Object.assign({},t.callbacks,e.callbacks),n.head=Object.assign({},t.head,e.head),n}(r);return{target:e,newContent:n,config:o,morphStyle:o.morphStyle,ignoreActive:o.ignoreActive,ignoreActiveValue:o.ignoreActiveValue,idMap:T(e,n),deadIds:new Set,persistentIds:o.twoPass?w(e,n):new Set,pantry:o.twoPass?d():document.createElement("div"),callbacks:o.callbacks,head:o.head}}(e,l,o);return n(e,l,i)},defaults:t}}();const _="CustomEvent"in window&&"function"==typeof window.CustomEvent?(e,t)=>new CustomEvent(e,t):(e,t)=>{const n=document.createEvent("CustomEvent");return n.initCustomEvent(e,!0,!0,t),n},y=(e,t)=>function(n){const r=this,o=n.detail||{};e.__events[t].forEach((e=>{e.handler.apply(r,[n].concat(o.args))}))},A=(e,t)=>{e.__events[t]&&e.__events[t].listener&&(e.removeEventListener(t,e.__events[t].listener,"focus"==t||"blur"==t||"mouseenter"==t||"mouseleave"==t),delete e.__events[t])},E=(e,t,n)=>function(r){const o=this,l=r.detail||{};let i=r.target;for(;i&&(i.matches(t)&&(r.delegateTarget=i,n.apply(o,[r].concat(l.args))),i!==e);)i=i.parentNode},N=(e,t,n,r)=>{if(e.__events=e.__events||{},e.__events[t]=e.__events[t]||[],!e.__events[t].length){const n=y(e,t);e.addEventListener(t,n,"focus"==t||"blur"==t||"mouseenter"==t||"mouseleave"==t),e.__events[t].listener=n}n.call?e.__events[t].push({handler:n,callback:n}):e.__events[t].push({handler:E(e,n,r),callback:r})},S=(e,t,n)=>{if(n&&e.__events[t]&&e.__events[t].length){var r=e.__events[t];e.__events[t]=e.__events[t].filter((function(e){return e.callback!=n})),e.__events[t].listener=r.listener,e.__events[t].length||A(e,t)}else A(e,t)},k=(e,t,n)=>{e.dispatchEvent(_(t,{bubbles:!0,detail:n}))};const x=e=>({main:e=>e,unmount:e=>e,onupdate:e=>e,view:e.view?e.view:e=>e}),M=e=>{e.querySelectorAll("[scope]").forEach((e=>{e.querySelectorAll("[tplid]").forEach((t=>{if(!t.___scope___){const n=e.lastElementChild;t.___scope___="scope"in n.dataset?new Function(`return ${n.text}`)():{}}}))}))},T=e=>({callbacks:{beforeNodeMorphed(t){if(1===t.nodeType){if("html-static"in t.attributes)return!1;if(t.base&&t!==e)return!1}}}});function w(e,t,n,r){return class extends HTMLElement{constructor(){super()}connectedCallback(){const{base:o,options:a}=function(e,{module:t,dependencies:n,templates:r,components:o}){const a=x(t),c=new Function(`return ${e.getAttribute("html-model")||"{}"}`)(),u=Object.keys(o).toString();d(e,u,r,o);const f=e.getAttribute("tplid"),m=f?r[f]:null,h={data:t.model?i(t.model):{}};h.data=Object.assign(h.data,c);const p={template:m,elm:e,dependencies:n,publish:b,subscribe:v,main(e){a.main=e},unmount(e){a.unmount=e},onupdate(e){a.onupdate=e},on(t,n,r){N(e,t,n,r)},off(t,n){S(e,t,n)},trigger(t,n,r){n.constructor===String?Array.from(e.querySelectorAll(n)).forEach((e=>k(e,t,{args:r}))):k(e,t,{args:n})},emit:(...t)=>{k(e,t.shift(),{args:t})},state:{set(e){if(e.constructor===Function){const t=i(h.data);e(t),p.render(t)}else p.render(e);return new Promise((e=>l((t=>l((()=>e(h.data)))))))},get:()=>i(h.data),getRaw:()=>h.data},render(t=h.data){if(!document.body.contains(e))return;h.data=Object.assign(h.data,t);const n=i(h.data),o=r[f].call(Object.assign(a.view(n),e.___scope___),e,s);g.morph(e,o,T(e)),M(e),l((n=>{Array.from(e.querySelectorAll("[tplid]")).forEach((e=>{const n=Object.assign(e.base.state.getRaw(),t);e.options.onupdate(n),e.base.render(n)}))}))},innerHTML(t,n){const r=n?t:e,o=r.cloneNode(),i=n||t;o.innerHTML=i,l((e=>g.morph(r,o,T)))}};return{base:p,options:a}}(this,{module:e,dependencies:t,templates:n,components:r});if(this.base=o,this.options=a,this.base.render(),this.returns=e.default(o),this.__template&&this.__template.constructor===Promise)this.__template.then((e=>{if(this.base&&this.options.main){const e=this.options.main(this.base);e&&e.length&&e.forEach((e=>e(this.base)))}}));else if(this.returns&&this.returns.constructor===Promise)this.returns.then((e=>{if(this.base&&this.options.main){const e=this.options.main(this.base);e&&e.length&&e.forEach((e=>e(this.base)))}}));else if(this.base&&this.options.main){const e=this.options.main(this.base);e&&e.length&&e.forEach((e=>e(this.base)))}}disconnectedCallback(){this.options.unmount(this.base),l((()=>{document.body.contains(this)||(this.__events&&(this.__events=null),this.base&&(this.base.elm=null),this.base&&(this.base=null),a(this))}))}attributeChangedCallback(){}}}const $={},C={},H={templateConfig:e=>{Object.assign(c,e)},publish:b,subscribe:v,register(e,t,n={}){C[e]={name:e,module:t,dependencies:n}},start(e=document.body){const t=Object.keys(C),n=t.toString();t.length&&(d(e,n,$,C),L())}},L=()=>{Object.values(C).forEach((e=>{const{name:t,module:n,dependencies:r}=e;if(!customElements.get(t)){const e=w(n,r,$,C);customElements.define(t,e)}}))};e.attributes=e=>Object.entries(e).map((([e,t])=>""===t?e:`${e}="${t}"`)).join(" "),e.default=H,e.html=(e,...t)=>{let n=e.raw,r="";return t.forEach(((e,t)=>{let o=n[t];Array.isArray(e)&&(e=e.join("")),r+=o,r+=e})),r+=n[n.length-1],r},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); //# sourceMappingURL=jails.js.map diff --git a/dist/jails.js.map b/dist/jails.js.map index c6a66b0..4ab3fc5 100644 --- a/dist/jails.js.map +++ b/dist/jails.js.map @@ -1 +1 @@ -{"version":3,"file":"jails.js","sources":["../src/transpile.ts","../src/utils/index.ts","../src/template-system.ts","../src/utils/pubsub.ts","../node_modules/idiomorph/dist/idiomorph.esm.js","../src/utils/events.ts","../src/component.ts","../src/element.ts","../src/index.ts","../html.ts"],"sourcesContent":["import { uuid } from './utils'\n\nconst parser = new DOMParser()\n\nexport default function Transpile(html, config) {\n\n\tconst regexTags = new RegExp(`\\\\${config.tags[0]}(.+?)\\\\${config.tags[1]}`, 'g')\n\tconst virtual = parser.parseFromString(html.replace(/<\\/?template[^>]*>/g, ''), 'text/html')\n\n\tvirtual.querySelectorAll('[html-for], [html-if], [html-inner], [html-class], [html-model]').forEach((element) => {\n\n\t\tconst htmlForeach = element.getAttribute('html-foreach')\n\t\tconst htmlFor \t= element.getAttribute('html-for')\n\t\tconst htmlIf \t= element.getAttribute('html-if')\n\t\tconst htmlInner = element.getAttribute('html-inner')\n\t\tconst htmlClass = element.getAttribute('html-class')\n\t\tconst forEachInstruction = htmlFor || htmlForeach\n\n\t\tif ( forEachInstruction ) {\n\t\t\tconst selector = htmlFor? 'html-for': 'html-foreach'\n\t\t\tconst split = forEachInstruction.match(/(.*)\\sin\\s(.*)/) || ''\n\t\t\tconst varname = split[1]\n\t\t\tconst object = split[2]\n\n\t\t\telement.removeAttribute(selector)\n\t\t\telement.setAttribute('scope', '')\n\t\t\tconst script = document.createElement('script')\n\n\t\t\tscript.dataset.scope = ''\n\t\t\tscript.type = 'text/html'\n\t\t\tscript.text = `%%_= $scope _%%`\n\n\t\t\telement.appendChild( script )\n\n\t\t\tconst open = document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${object} }) ){ var ${varname} = ${object}[$key]; var $scope = JSON.stringify({ '${varname}':${varname}, $index: $index, $key:$key }); _%%`)\n\t\t\tconst close = document.createTextNode(`%%_ $index++; } })() _%%`)\n\t\t\twrap(open, element, close)\n\t\t}\n\t\tif (htmlIf) {\n\t\t\telement.removeAttribute('html-if')\n\t\t\tconst open = document.createTextNode(`%%_ if ( safe(function(){ return ${htmlIf} }) ){ _%%`)\n\t\t\tconst close = document.createTextNode(`%%_ } _%%`)\n\t\t\twrap(open, element, close)\n\t\t}\n\t\tif (htmlInner) {\n\t\t\telement.removeAttribute('html-inner')\n\t\t\telement.innerHTML = `%%_=${htmlInner}_%%`\n\t\t}\n\t\tif (htmlClass) {\n\t\t\telement.removeAttribute('html-class')\n\t\t\telement.className = (element.className + ` %%_=${htmlClass}_%%`).trim()\n\t\t}\n\t})\n\n\treturn (\n\t\tvirtual.body.innerHTML\n\t\t\t.replace(regexTags, '%%_=$1_%%')\n\t\t\t// Booleans\n\t\t\t// https://meiert.com/en/blog/boolean-attributes-of-html/\n\t\t\t.replace(/html-(allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|formnovalidate|inert|ismap|itemscope|loop|multiple|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|selected)=\\\"(.*?)\\\"/g, `%%_if(safe(function(){ return $2 })){_%%$1%%_}_%%`)\n\t\t\t// The rest\n\t\t\t.replace(/html-(.*?)=\\\"(.*?)\\\"/g, (all, key, value) => {\n\t\t\t\tif (key === 'key' || key === 'model' || key == 'scope') {\n\t\t\t\t\treturn all\n\t\t\t\t}\n\t\t\t\tif (value) {\n\t\t\t\t\tvalue = value.replace(/^{|}$/g, '')\n\t\t\t\t\treturn `${key}=\"%%_=safe(function(){ return ${value} })_%%\"`\n\t\t\t\t} else {\n\t\t\t\t\treturn all\n\t\t\t\t}\n\t\t\t})\n\t)\n}\n\nconst wrap = (open, node, close) => {\n\tnode.parentNode?.insertBefore(open, node)\n\tnode.parentNode?.insertBefore(close, node.nextSibling)\n}\n","const textarea = document.createElement('textarea')\n\nexport const decodeHTML = (text) => {\n\ttextarea.innerHTML = text\n\treturn textarea.value\n}\n\nexport const rAF = (fn) => {\n\tif (requestAnimationFrame)\n\t\treturn requestAnimationFrame(fn)\n\telse\n\t\treturn setTimeout(fn, 1000 / 60)\n}\n\nexport const uuid = () => {\n\treturn 'xxxxxxxx'.replace(/[xy]/g, (c) => {\n\t\tconst r = Math.random() * 8 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)\n\t\treturn v.toString(8)\n\t})\n}\n\nexport const dup = (o) => {\n\treturn JSON.parse(JSON.stringify(o))\n}\n\n// http://crockford.com/javascript/memory/leak.html\nexport const purge = (d) => {\n\tvar a = d.attributes, i, l, n\n\tif (a) {\n\t\tfor (i = a.length - 1; i >= 0; i -= 1) {\n\t\t\tn = a[i].name\n\t\t\tif (typeof d[n] === 'function') {\n\t\t\t\td[n] = null\n\t\t\t}\n\t\t}\n\t}\n\ta = d.childNodes\n\tif (a) {\n\t\tl = a.length\n\t\tfor (i = 0; i < l; i += 1) {\n\t\t\tpurge(d.childNodes[i])\n\t\t}\n\t}\n}\n\nexport const safe = (execute, val) => {\n\ttry{return execute()}catch(err){return val || ''}\n}\n","import Transpile from './transpile'\nimport { uuid, decodeHTML } from './utils'\n\nconst config = {\n\ttags: ['{{', '}}']\n}\n\nexport const templateConfig = (newconfig) => {\n\tObject.assign(config, newconfig)\n}\n\nexport default function Template(element) {\n\n\tfixDIffIf(element)\n\tconst html = Transpile(element.outerHTML, config)\n\tconst decodedHTML = JSON.stringify(html)\n\n\treturn new Function('$element', 'safe',`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${decodedHTML\n\t\t\t\t.replace(/%%_=(.+?)_%%/g, function(_, variable){\n\t\t\t\t\treturn '\"+safe(function(){return '+decodeHTML(variable)+';})+\"'\n\t\t\t\t})\n\t\t\t\t.replace(/%%_(.+?)_%%/g, function(_, variable){\n\t\t\t\t\treturn '\";' + decodeHTML(variable) +'\\noutput+=\"'\n\t\t\t\t})};return output;\n\t\t}\n\t`)\n}\n\nexport const buildtemplates = ( target, selector, templates, components ) => {\n\t[]\n\t\t.concat( target.matches? (target.matches(selector)? target : []) : [] )\n\t\t.concat( Array.from(target.querySelectorAll( selector )) )\n\t\t.reverse()\n\t\t.forEach( (node:HTMLElement) => {\n\t\t\tnode.querySelectorAll('template').forEach( template => buildtemplates(template.content, selector, templates, components ))\n\t\t\tcreateTemplateId(node, templates, components)\n\t\t})\n}\n\nconst createTemplateId = (element, templates, components ) => {\n\n\tconst tplid = element.getAttribute('tplid')\n\n\tif (!tplid) {\n\t\tconst id = uuid()\n\t\telement.setAttribute('tplid', id)\n\t\tconst name = element.localName\n\n\t\tif( name in components && components[name].module.template ) {\n\t\t\tconst children = element.innerHTML\n\t\t\tconst html = components[name].module.template({ children })\n\t\t\tif( html.constructor === Promise ) {\n\t\t\t\telement.__template = html\n\t\t\t\thtml.then( htmlstring => {\n\t\t\t\t\telement.innerHTML = htmlstring\n\t\t\t\t\ttemplates[id] = Template(element)\n\t\t\t\t})\n\t\t\t}else {\n\t\t\t\telement.innerHTML = html\n\t\t\t}\n\t\t}\n\t\ttemplates[id] = Template(element)\n\t}\n}\n\n// Sometimes we don't know why something works, especially when using third party code like Idiomorph.\n// So just letting anyone knows that this part has to be improved some time.\nconst fixDIffIf = (node) => {\n\tconst _if = node.querySelectorAll('[html-if]')\n\t_if.forEach( el => {\n\t\tel.parentNode.insertBefore(document.createComment('[html-if]'), el.nextSibling)\n\t})\n}\n","const topics: any = {}\nconst _async: any = {}\n\nexport const publish = (name, params) => {\n\t_async[name] = Object.assign({}, _async[name], params)\n\tif (topics[name])\n\t\ttopics[name].forEach(topic => topic(params))\n}\n\nexport const subscribe = (name, method) => {\n\ttopics[name] = topics[name] || []\n\ttopics[name].push(method)\n\tif (name in _async) {\n\t\tmethod(_async[name])\n\t}\n\treturn () => {\n\t\ttopics[name] = topics[name].filter( fn => fn != method )\n\t}\n}\n\n","/**\n * @typedef {object} ConfigHead\n *\n * @property {'merge' | 'append' | 'morph' | 'none'} [style]\n * @property {boolean} [block]\n * @property {boolean} [ignore]\n * @property {function(Element): boolean} [shouldPreserve]\n * @property {function(Element): boolean} [shouldReAppend]\n * @property {function(Element): boolean} [shouldRemove]\n * @property {function(Element, {added: Node[], kept: Element[], removed: Element[]}): void} [afterHeadMorphed]\n */\n\n/**\n * @typedef {object} ConfigCallbacks\n *\n * @property {function(Node): boolean} [beforeNodeAdded]\n * @property {function(Node): void} [afterNodeAdded]\n * @property {function(Element, Node): boolean} [beforeNodeMorphed]\n * @property {function(Element, Node): void} [afterNodeMorphed]\n * @property {function(Element): boolean} [beforeNodeRemoved]\n * @property {function(Element): void} [afterNodeRemoved]\n * @property {function(string, Element, \"update\" | \"remove\"): boolean} [beforeAttributeUpdated]\n * @property {function(Element): boolean} [beforeNodePantried]\n */\n\n/**\n * @typedef {object} Config\n *\n * @property {'outerHTML' | 'innerHTML'} [morphStyle]\n * @property {boolean} [ignoreActive]\n * @property {boolean} [ignoreActiveValue]\n * @property {ConfigCallbacks} [callbacks]\n * @property {ConfigHead} [head]\n */\n\n/**\n * @typedef {function} NoOp\n *\n * @returns {void}\n */\n\n/**\n * @typedef {object} ConfigHeadInternal\n *\n * @property {'merge' | 'append' | 'morph' | 'none'} style\n * @property {boolean} [block]\n * @property {boolean} [ignore]\n * @property {(function(Element): boolean) | NoOp} shouldPreserve\n * @property {(function(Element): boolean) | NoOp} shouldReAppend\n * @property {(function(Element): boolean) | NoOp} shouldRemove\n * @property {(function(Element, {added: Node[], kept: Element[], removed: Element[]}): void) | NoOp} afterHeadMorphed\n */\n\n/**\n * @typedef {object} ConfigCallbacksInternal\n *\n * @property {(function(Node): boolean) | NoOp} beforeNodeAdded\n * @property {(function(Node): void) | NoOp} afterNodeAdded\n * @property {(function(Node, Node): boolean) | NoOp} beforeNodeMorphed\n * @property {(function(Node, Node): void) | NoOp} afterNodeMorphed\n * @property {(function(Node): boolean) | NoOp} beforeNodeRemoved\n * @property {(function(Node): void) | NoOp} afterNodeRemoved\n * @property {(function(string, Element, \"update\" | \"remove\"): boolean) | NoOp} beforeAttributeUpdated\n * @property {(function(Node): boolean) | NoOp} beforeNodePantried\n */\n\n/**\n * @typedef {object} ConfigInternal\n *\n * @property {'outerHTML' | 'innerHTML'} morphStyle\n * @property {boolean} [ignoreActive]\n * @property {boolean} [ignoreActiveValue]\n * @property {ConfigCallbacksInternal} callbacks\n * @property {ConfigHeadInternal} head\n * @property {boolean} [twoPass]\n */\n\n/**\n * @typedef {Function} Morph\n *\n * @param {Element | Document} oldNode\n * @param {Element | Node | HTMLCollection | Node[] | string | null} newContent\n * @param {Config} [config]\n * @returns {undefined | Node[]}\n */\n\n// base IIFE to define idiomorph\n/**\n *\n * @type {{defaults: ConfigInternal, morph: Morph}}\n */\nvar Idiomorph = (function () {\n \"use strict\";\n\n /**\n * @typedef {object} MorphContext\n *\n * @property {Node} target\n * @property {Node} newContent\n * @property {ConfigInternal} config\n * @property {ConfigInternal['morphStyle']} morphStyle\n * @property {ConfigInternal['ignoreActive']} ignoreActive\n * @property {ConfigInternal['ignoreActiveValue']} ignoreActiveValue\n * @property {Map>} idMap\n * @property {Set} persistentIds\n * @property {Set} deadIds\n * @property {ConfigInternal['callbacks']} callbacks\n * @property {ConfigInternal['head']} head\n * @property {HTMLDivElement} pantry\n */\n\n //=============================================================================\n // AND NOW IT BEGINS...\n //=============================================================================\n\n /**\n *\n * @type {Set}\n */\n let EMPTY_SET = new Set();\n\n /**\n * Default configuration values, updatable by users now\n * @type {ConfigInternal}\n */\n let defaults = {\n morphStyle: \"outerHTML\",\n callbacks: {\n beforeNodeAdded: noOp,\n afterNodeAdded: noOp,\n beforeNodeMorphed: noOp,\n afterNodeMorphed: noOp,\n beforeNodeRemoved: noOp,\n afterNodeRemoved: noOp,\n beforeAttributeUpdated: noOp,\n beforeNodePantried: noOp,\n },\n head: {\n style: \"merge\",\n shouldPreserve: function (elt) {\n return elt.getAttribute(\"im-preserve\") === \"true\";\n },\n shouldReAppend: function (elt) {\n return elt.getAttribute(\"im-re-append\") === \"true\";\n },\n shouldRemove: noOp,\n afterHeadMorphed: noOp,\n },\n };\n\n /**\n * =============================================================================\n * Core Morphing Algorithm - morph, morphNormalizedContent, morphOldNodeTo, morphChildren\n * =============================================================================\n *\n * @param {Element | Document} oldNode\n * @param {Element | Node | HTMLCollection | Node[] | string | null} newContent\n * @param {Config} [config]\n * @returns {undefined | Node[]}\n */\n function morph(oldNode, newContent, config = {}) {\n if (oldNode instanceof Document) {\n oldNode = oldNode.documentElement;\n }\n\n if (typeof newContent === \"string\") {\n newContent = parseContent(newContent);\n }\n\n let normalizedContent = normalizeContent(newContent);\n\n let ctx = createMorphContext(oldNode, normalizedContent, config);\n\n return morphNormalizedContent(oldNode, normalizedContent, ctx);\n }\n\n /**\n *\n * @param {Element} oldNode\n * @param {Element} normalizedNewContent\n * @param {MorphContext} ctx\n * @returns {undefined | Node[]}\n */\n function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {\n if (ctx.head.block) {\n let oldHead = oldNode.querySelector(\"head\");\n let newHead = normalizedNewContent.querySelector(\"head\");\n if (oldHead && newHead) {\n let promises = handleHeadElement(newHead, oldHead, ctx);\n // when head promises resolve, call morph again, ignoring the head tag\n Promise.all(promises).then(function () {\n morphNormalizedContent(\n oldNode,\n normalizedNewContent,\n Object.assign(ctx, {\n head: {\n block: false,\n ignore: true,\n },\n }),\n );\n });\n return;\n }\n }\n\n if (ctx.morphStyle === \"innerHTML\") {\n // innerHTML, so we are only updating the children\n morphChildren(normalizedNewContent, oldNode, ctx);\n if (ctx.config.twoPass) {\n restoreFromPantry(oldNode, ctx);\n }\n return Array.from(oldNode.children);\n } else if (ctx.morphStyle === \"outerHTML\" || ctx.morphStyle == null) {\n // otherwise find the best element match in the new content, morph that, and merge its siblings\n // into either side of the best match\n let bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);\n\n // stash the siblings that will need to be inserted on either side of the best match\n let previousSibling = bestMatch?.previousSibling ?? null;\n let nextSibling = bestMatch?.nextSibling ?? null;\n\n // morph it\n let morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);\n\n if (bestMatch) {\n // if there was a best match, merge the siblings in too and return the\n // whole bunch\n if (morphedNode) {\n const elements = insertSiblings(\n previousSibling,\n morphedNode,\n nextSibling,\n );\n if (ctx.config.twoPass) {\n restoreFromPantry(morphedNode.parentNode, ctx);\n }\n return elements;\n }\n } else {\n // otherwise nothing was added to the DOM\n return [];\n }\n } else {\n throw \"Do not understand how to morph style \" + ctx.morphStyle;\n }\n }\n\n /**\n * @param {Node} possibleActiveElement\n * @param {MorphContext} ctx\n * @returns {boolean}\n */\n // TODO: ignoreActive and ignoreActiveValue are marked as optional since they are not\n // initialised in the default config object. As a result the && in the function body may\n // return undefined instead of boolean. Either expand the type of the return value to\n // include undefined or wrap the ctx.ignoreActiveValue into a Boolean()\n function ignoreValueOfActiveElement(possibleActiveElement, ctx) {\n return (\n !!ctx.ignoreActiveValue &&\n possibleActiveElement === document.activeElement &&\n possibleActiveElement !== document.body\n );\n }\n\n /**\n * @param {Node} oldNode root node to merge content into\n * @param {Node | null} newContent new content to merge\n * @param {MorphContext} ctx the merge context\n * @returns {Node | null} the element that ended up in the DOM\n */\n function morphOldNodeTo(oldNode, newContent, ctx) {\n if (ctx.ignoreActive && oldNode === document.activeElement) {\n // don't morph focused element\n } else if (newContent == null) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n\n oldNode.parentNode?.removeChild(oldNode);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return null;\n } else if (!isSoftMatch(oldNode, newContent)) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n if (ctx.callbacks.beforeNodeAdded(newContent) === false) return oldNode;\n\n oldNode.parentNode?.replaceChild(newContent, oldNode);\n ctx.callbacks.afterNodeAdded(newContent);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return newContent;\n } else {\n if (ctx.callbacks.beforeNodeMorphed(oldNode, newContent) === false)\n return oldNode;\n\n if (oldNode instanceof HTMLHeadElement && ctx.head.ignore) {\n // ignore the head element\n } else if (\n oldNode instanceof HTMLHeadElement &&\n ctx.head.style !== \"morph\"\n ) {\n // ok to cast: if newContent wasn't also a , it would've got caught in the `!isSoftMatch` branch above\n handleHeadElement(\n /** @type {HTMLHeadElement} */ (newContent),\n oldNode,\n ctx,\n );\n } else {\n syncNodeFrom(newContent, oldNode, ctx);\n if (!ignoreValueOfActiveElement(oldNode, ctx)) {\n morphChildren(newContent, oldNode, ctx);\n }\n }\n ctx.callbacks.afterNodeMorphed(oldNode, newContent);\n return oldNode;\n }\n return null;\n }\n\n /**\n * This is the core algorithm for matching up children. The idea is to use id sets to try to match up\n * nodes as faithfully as possible. We greedily match, which allows us to keep the algorithm fast, but\n * by using id sets, we are able to better match up with content deeper in the DOM.\n *\n * Basic algorithm is, for each node in the new content:\n *\n * - if we have reached the end of the old parent, append the new content\n * - if the new content has an id set match with the current insertion point, morph\n * - search for an id set match\n * - if id set match found, morph\n * - otherwise search for a \"soft\" match\n * - if a soft match is found, morph\n * - otherwise, prepend the new node before the current insertion point\n *\n * The two search algorithms terminate if competing node matches appear to outweigh what can be achieved\n * with the current node. See findIdSetMatch() and findSoftMatch() for details.\n *\n * @param {Node} newParent the parent element of the new content\n * @param {Node} oldParent the old content that we are merging the new content into\n * @param {MorphContext} ctx the merge context\n * @returns {void}\n */\n function morphChildren(newParent, oldParent, ctx) {\n if (\n newParent instanceof HTMLTemplateElement &&\n oldParent instanceof HTMLTemplateElement\n ) {\n newParent = newParent.content;\n oldParent = oldParent.content;\n }\n\n /**\n *\n * @type {Node | null}\n */\n let nextNewChild = newParent.firstChild;\n /**\n *\n * @type {Node | null}\n */\n let insertionPoint = oldParent.firstChild;\n let newChild;\n\n // run through all the new content\n while (nextNewChild) {\n newChild = nextNewChild;\n nextNewChild = newChild.nextSibling;\n\n // if we are at the end of the exiting parent's children, just append\n if (insertionPoint == null) {\n // skip add callbacks when we're going to be restoring this from the pantry in the second pass\n if (\n ctx.config.twoPass &&\n ctx.persistentIds.has(/** @type {Element} */ (newChild).id)\n ) {\n oldParent.appendChild(newChild);\n } else {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) continue;\n oldParent.appendChild(newChild);\n ctx.callbacks.afterNodeAdded(newChild);\n }\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // if the current node has an id set match then morph\n if (isIdSetMatch(newChild, insertionPoint, ctx)) {\n morphOldNodeTo(insertionPoint, newChild, ctx);\n insertionPoint = insertionPoint.nextSibling;\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // otherwise search forward in the existing old children for an id set match\n let idSetMatch = findIdSetMatch(\n newParent,\n oldParent,\n newChild,\n insertionPoint,\n ctx,\n );\n\n // if we found a potential match, remove the nodes until that point and morph\n if (idSetMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, idSetMatch, ctx);\n morphOldNodeTo(idSetMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // no id set match found, so scan forward for a soft match for the current node\n let softMatch = findSoftMatch(\n newParent,\n oldParent,\n newChild,\n insertionPoint,\n ctx,\n );\n\n // if we found a soft match for the current node, morph\n if (softMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, softMatch, ctx);\n morphOldNodeTo(softMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // abandon all hope of morphing, just insert the new child before the insertion point\n // and move on\n\n // skip add callbacks when we're going to be restoring this from the pantry in the second pass\n if (\n ctx.config.twoPass &&\n ctx.persistentIds.has(/** @type {Element} */ (newChild).id)\n ) {\n oldParent.insertBefore(newChild, insertionPoint);\n } else {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) continue;\n oldParent.insertBefore(newChild, insertionPoint);\n ctx.callbacks.afterNodeAdded(newChild);\n }\n removeIdsFromConsideration(ctx, newChild);\n }\n\n // remove any remaining old nodes that didn't match up with new content\n while (insertionPoint !== null) {\n let tempNode = insertionPoint;\n insertionPoint = insertionPoint.nextSibling;\n removeNode(tempNode, ctx);\n }\n }\n\n //=============================================================================\n // Attribute Syncing Code\n //=============================================================================\n\n /**\n * @param {string} attr the attribute to be mutated\n * @param {Element} to the element that is going to be updated\n * @param {\"update\" | \"remove\"} updateType\n * @param {MorphContext} ctx the merge context\n * @returns {boolean} true if the attribute should be ignored, false otherwise\n */\n function ignoreAttribute(attr, to, updateType, ctx) {\n if (\n attr === \"value\" &&\n ctx.ignoreActiveValue &&\n to === document.activeElement\n ) {\n return true;\n }\n return ctx.callbacks.beforeAttributeUpdated(attr, to, updateType) === false;\n }\n\n /**\n * syncs a given node with another node, copying over all attributes and\n * inner element state from the 'from' node to the 'to' node\n *\n * @param {Node} from the element to copy attributes & state from\n * @param {Node} to the element to copy attributes & state to\n * @param {MorphContext} ctx the merge context\n */\n function syncNodeFrom(from, to, ctx) {\n let type = from.nodeType;\n\n // if is an element type, sync the attributes from the\n // new node into the new node\n if (type === 1 /* element type */) {\n const fromEl = /** @type {Element} */ (from);\n const toEl = /** @type {Element} */ (to);\n const fromAttributes = fromEl.attributes;\n const toAttributes = toEl.attributes;\n for (const fromAttribute of fromAttributes) {\n if (ignoreAttribute(fromAttribute.name, toEl, \"update\", ctx)) {\n continue;\n }\n if (toEl.getAttribute(fromAttribute.name) !== fromAttribute.value) {\n toEl.setAttribute(fromAttribute.name, fromAttribute.value);\n }\n }\n // iterate backwards to avoid skipping over items when a delete occurs\n for (let i = toAttributes.length - 1; 0 <= i; i--) {\n const toAttribute = toAttributes[i];\n\n // toAttributes is a live NamedNodeMap, so iteration+mutation is unsafe\n // e.g. custom element attribute callbacks can remove other attributes\n if (!toAttribute) continue;\n\n if (!fromEl.hasAttribute(toAttribute.name)) {\n if (ignoreAttribute(toAttribute.name, toEl, \"remove\", ctx)) {\n continue;\n }\n toEl.removeAttribute(toAttribute.name);\n }\n }\n }\n\n // sync text nodes\n if (type === 8 /* comment */ || type === 3 /* text */) {\n if (to.nodeValue !== from.nodeValue) {\n to.nodeValue = from.nodeValue;\n }\n }\n\n if (!ignoreValueOfActiveElement(to, ctx)) {\n // sync input values\n syncInputValue(from, to, ctx);\n }\n }\n\n /**\n * @param {Element} from element to sync the value from\n * @param {Element} to element to sync the value to\n * @param {string} attributeName the attribute name\n * @param {MorphContext} ctx the merge context\n */\n function syncBooleanAttribute(from, to, attributeName, ctx) {\n // TODO: prefer set/getAttribute here\n if (!(from instanceof Element && to instanceof Element)) return;\n // @ts-ignore this function is only used on boolean attrs that are reflected as dom properties\n const fromLiveValue = from[attributeName],\n toLiveValue = to[attributeName];\n if (fromLiveValue !== toLiveValue) {\n let ignoreUpdate = ignoreAttribute(attributeName, to, \"update\", ctx);\n if (!ignoreUpdate) {\n // update attribute's associated DOM property\n // @ts-ignore this function is only used on boolean attrs that are reflected as dom properties\n to[attributeName] = from[attributeName];\n }\n if (fromLiveValue) {\n if (!ignoreUpdate) {\n // TODO: do we really want this? tests say so but it feels wrong\n to.setAttribute(attributeName, fromLiveValue);\n }\n } else {\n if (!ignoreAttribute(attributeName, to, \"remove\", ctx)) {\n to.removeAttribute(attributeName);\n }\n }\n }\n }\n\n /**\n * NB: many bothans died to bring us information:\n *\n * https://github.com/patrick-steele-idem/morphdom/blob/master/src/specialElHandlers.js\n * https://github.com/choojs/nanomorph/blob/master/lib/morph.jsL113\n *\n * @param {Node} from the element to sync the input value from\n * @param {Node} to the element to sync the input value to\n * @param {MorphContext} ctx the merge context\n */\n function syncInputValue(from, to, ctx) {\n if (\n from instanceof HTMLInputElement &&\n to instanceof HTMLInputElement &&\n from.type !== \"file\"\n ) {\n let fromValue = from.value;\n let toValue = to.value;\n\n // sync boolean attributes\n syncBooleanAttribute(from, to, \"checked\", ctx);\n syncBooleanAttribute(from, to, \"disabled\", ctx);\n\n if (!from.hasAttribute(\"value\")) {\n if (!ignoreAttribute(\"value\", to, \"remove\", ctx)) {\n to.value = \"\";\n to.removeAttribute(\"value\");\n }\n } else if (fromValue !== toValue) {\n if (!ignoreAttribute(\"value\", to, \"update\", ctx)) {\n to.setAttribute(\"value\", fromValue);\n to.value = fromValue;\n }\n }\n // TODO: QUESTION(1cg): this used to only check `from` unlike the other branches -- why?\n // did I break something?\n } else if (\n from instanceof HTMLOptionElement &&\n to instanceof HTMLOptionElement\n ) {\n syncBooleanAttribute(from, to, \"selected\", ctx);\n } else if (\n from instanceof HTMLTextAreaElement &&\n to instanceof HTMLTextAreaElement\n ) {\n let fromValue = from.value;\n let toValue = to.value;\n if (ignoreAttribute(\"value\", to, \"update\", ctx)) {\n return;\n }\n if (fromValue !== toValue) {\n to.value = fromValue;\n }\n if (to.firstChild && to.firstChild.nodeValue !== fromValue) {\n to.firstChild.nodeValue = fromValue;\n }\n }\n }\n\n /**\n * =============================================================================\n * The HEAD tag can be handled specially, either w/ a 'merge' or 'append' style\n * =============================================================================\n * @param {Element} newHeadTag\n * @param {Element} currentHead\n * @param {MorphContext} ctx\n * @returns {Promise[]}\n */\n function handleHeadElement(newHeadTag, currentHead, ctx) {\n /**\n * @type {Node[]}\n */\n let added = [];\n /**\n * @type {Element[]}\n */\n let removed = [];\n /**\n * @type {Element[]}\n */\n let preserved = [];\n /**\n * @type {Element[]}\n */\n let nodesToAppend = [];\n\n let headMergeStyle = ctx.head.style;\n\n // put all new head elements into a Map, by their outerHTML\n let srcToNewHeadNodes = new Map();\n for (const newHeadChild of newHeadTag.children) {\n srcToNewHeadNodes.set(newHeadChild.outerHTML, newHeadChild);\n }\n\n // for each elt in the current head\n for (const currentHeadElt of currentHead.children) {\n // If the current head element is in the map\n let inNewContent = srcToNewHeadNodes.has(currentHeadElt.outerHTML);\n let isReAppended = ctx.head.shouldReAppend(currentHeadElt);\n let isPreserved = ctx.head.shouldPreserve(currentHeadElt);\n if (inNewContent || isPreserved) {\n if (isReAppended) {\n // remove the current version and let the new version replace it and re-execute\n removed.push(currentHeadElt);\n } else {\n // this element already exists and should not be re-appended, so remove it from\n // the new content map, preserving it in the DOM\n srcToNewHeadNodes.delete(currentHeadElt.outerHTML);\n preserved.push(currentHeadElt);\n }\n } else {\n if (headMergeStyle === \"append\") {\n // we are appending and this existing element is not new content\n // so if and only if it is marked for re-append do we do anything\n if (isReAppended) {\n removed.push(currentHeadElt);\n nodesToAppend.push(currentHeadElt);\n }\n } else {\n // if this is a merge, we remove this content since it is not in the new head\n if (ctx.head.shouldRemove(currentHeadElt) !== false) {\n removed.push(currentHeadElt);\n }\n }\n }\n }\n\n // Push the remaining new head elements in the Map into the\n // nodes to append to the head tag\n nodesToAppend.push(...srcToNewHeadNodes.values());\n log(\"to append: \", nodesToAppend);\n\n let promises = [];\n for (const newNode of nodesToAppend) {\n log(\"adding: \", newNode);\n // TODO: This could theoretically be null, based on type\n let newElt = /** @type {ChildNode} */ (\n document.createRange().createContextualFragment(newNode.outerHTML)\n .firstChild\n );\n log(newElt);\n if (ctx.callbacks.beforeNodeAdded(newElt) !== false) {\n if (\n (\"href\" in newElt && newElt.href) ||\n (\"src\" in newElt && newElt.src)\n ) {\n /** @type {(result?: any) => void} */ let resolve;\n let promise = new Promise(function (_resolve) {\n resolve = _resolve;\n });\n newElt.addEventListener(\"load\", function () {\n resolve();\n });\n promises.push(promise);\n }\n currentHead.appendChild(newElt);\n ctx.callbacks.afterNodeAdded(newElt);\n added.push(newElt);\n }\n }\n\n // remove all removed elements, after we have appended the new elements to avoid\n // additional network requests for things like style sheets\n for (const removedElement of removed) {\n if (ctx.callbacks.beforeNodeRemoved(removedElement) !== false) {\n currentHead.removeChild(removedElement);\n ctx.callbacks.afterNodeRemoved(removedElement);\n }\n }\n\n ctx.head.afterHeadMorphed(currentHead, {\n added: added,\n kept: preserved,\n removed: removed,\n });\n return promises;\n }\n\n //=============================================================================\n // Misc\n //=============================================================================\n\n /**\n * @param {any[]} _args\n */\n function log(..._args) {\n //console.log(args);\n }\n\n function noOp() {}\n\n /**\n * Deep merges the config object and the Idiomoroph.defaults object to\n * produce a final configuration object\n * @param {Config} config\n * @returns {ConfigInternal}\n */\n function mergeDefaults(config) {\n /**\n * @type {ConfigInternal}\n */\n let finalConfig = Object.assign({}, defaults);\n\n // copy top level stuff into final config\n Object.assign(finalConfig, config);\n\n // copy callbacks into final config (do this to deep merge the callbacks)\n finalConfig.callbacks = Object.assign(\n {},\n defaults.callbacks,\n config.callbacks,\n );\n\n // copy head config into final config (do this to deep merge the head)\n finalConfig.head = Object.assign({}, defaults.head, config.head);\n\n return finalConfig;\n }\n\n /**\n *\n * @param {Element} oldNode\n * @param {Element} newContent\n * @param {Config} config\n * @returns {MorphContext}\n */\n function createMorphContext(oldNode, newContent, config) {\n const mergedConfig = mergeDefaults(config);\n return {\n target: oldNode,\n newContent: newContent,\n config: mergedConfig,\n morphStyle: mergedConfig.morphStyle,\n ignoreActive: mergedConfig.ignoreActive,\n ignoreActiveValue: mergedConfig.ignoreActiveValue,\n idMap: createIdMap(oldNode, newContent),\n deadIds: new Set(),\n persistentIds: mergedConfig.twoPass\n ? createPersistentIds(oldNode, newContent)\n : new Set(),\n pantry: mergedConfig.twoPass\n ? createPantry()\n : document.createElement(\"div\"),\n callbacks: mergedConfig.callbacks,\n head: mergedConfig.head,\n };\n }\n\n function createPantry() {\n const pantry = document.createElement(\"div\");\n pantry.hidden = true;\n document.body.insertAdjacentElement(\"afterend\", pantry);\n return pantry;\n }\n\n /**\n *\n * @param {Node | null} node1\n * @param {Node | null} node2\n * @param {MorphContext} ctx\n * @returns {boolean}\n */\n // TODO: The function handles this as if it's Element or null, but the function is called in\n // places where the arguments may be just a Node, not an Element\n function isIdSetMatch(node1, node2, ctx) {\n if (node1 == null || node2 == null) {\n return false;\n }\n if (\n node1 instanceof Element &&\n node2 instanceof Element &&\n node1.tagName === node2.tagName\n ) {\n if (node1.id !== \"\" && node1.id === node2.id) {\n return true;\n } else {\n return getIdIntersectionCount(ctx, node1, node2) > 0;\n }\n }\n return false;\n }\n\n /**\n *\n * @param {Node | null} oldNode\n * @param {Node | null} newNode\n * @returns {boolean}\n */\n function isSoftMatch(oldNode, newNode) {\n if (oldNode == null || newNode == null) {\n return false;\n }\n // ok to cast: if one is not element, `id` or `tagName` will be undefined and we'll compare that\n // If oldNode has an `id` with possible state and it doesn't match newNode.id then avoid morphing\n if (\n /** @type {Element} */ (oldNode).id &&\n /** @type {Element} */ (oldNode).id !==\n /** @type {Element} */ (newNode).id\n ) {\n return false;\n }\n return (\n oldNode.nodeType === newNode.nodeType &&\n /** @type {Element} */ (oldNode).tagName ===\n /** @type {Element} */ (newNode).tagName\n );\n }\n\n /**\n *\n * @param {Node} startInclusive\n * @param {Node} endExclusive\n * @param {MorphContext} ctx\n * @returns {Node | null}\n */\n function removeNodesBetween(startInclusive, endExclusive, ctx) {\n /** @type {Node | null} */ let cursor = startInclusive;\n while (cursor !== endExclusive) {\n let tempNode = /** @type {Node} */ (cursor);\n // TODO: Prefer assigning to a new variable here or expand the type of startInclusive\n // to be Node | null\n cursor = tempNode.nextSibling;\n removeNode(tempNode, ctx);\n }\n removeIdsFromConsideration(ctx, endExclusive);\n return endExclusive.nextSibling;\n }\n\n /**\n * =============================================================================\n * Scans forward from the insertionPoint in the old parent looking for a potential id match\n * for the newChild. We stop if we find a potential id match for the new child OR\n * if the number of potential id matches we are discarding is greater than the\n * potential id matches for the new child\n * =============================================================================\n * @param {Node} newContent\n * @param {Node} oldParent\n * @param {Node} newChild\n * @param {Node} insertionPoint\n * @param {MorphContext} ctx\n * @returns {null | Node}\n */\n function findIdSetMatch(\n newContent,\n oldParent,\n newChild,\n insertionPoint,\n ctx,\n ) {\n // max id matches we are willing to discard in our search\n let newChildPotentialIdCount = getIdIntersectionCount(\n ctx,\n newChild,\n oldParent,\n );\n\n /**\n * @type {Node | null}\n */\n let potentialMatch = null;\n\n // only search forward if there is a possibility of an id match\n if (newChildPotentialIdCount > 0) {\n // TODO: This is ghosting the potentialMatch variable outside of this block.\n // Probably an error\n potentialMatch = insertionPoint;\n // if there is a possibility of an id match, scan forward\n // keep track of the potential id match count we are discarding (the\n // newChildPotentialIdCount must be greater than this to make it likely\n // worth it)\n let otherMatchCount = 0;\n while (potentialMatch != null) {\n // If we have an id match, return the current potential match\n if (isIdSetMatch(newChild, potentialMatch, ctx)) {\n return potentialMatch;\n }\n\n // computer the other potential matches of this new content\n otherMatchCount += getIdIntersectionCount(\n ctx,\n potentialMatch,\n newContent,\n );\n if (otherMatchCount > newChildPotentialIdCount) {\n // if we have more potential id matches in _other_ content, we\n // do not have a good candidate for an id match, so return null\n return null;\n }\n\n // advanced to the next old content child\n potentialMatch = potentialMatch.nextSibling;\n }\n }\n return potentialMatch;\n }\n\n /**\n * =============================================================================\n * Scans forward from the insertionPoint in the old parent looking for a potential soft match\n * for the newChild. We stop if we find a potential soft match for the new child OR\n * if we find a potential id match in the old parents children OR if we find two\n * potential soft matches for the next two pieces of new content\n * =============================================================================\n * @param {Node} newContent\n * @param {Node} oldParent\n * @param {Node} newChild\n * @param {Node} insertionPoint\n * @param {MorphContext} ctx\n * @returns {null | Node}\n */\n function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n /**\n * @type {Node | null}\n */\n let potentialSoftMatch = insertionPoint;\n /**\n * @type {Node | null}\n */\n let nextSibling = newChild.nextSibling;\n let siblingSoftMatchCount = 0;\n\n while (potentialSoftMatch != null) {\n if (getIdIntersectionCount(ctx, potentialSoftMatch, newContent) > 0) {\n // the current potential soft match has a potential id set match with the remaining new\n // content so bail out of looking\n return null;\n }\n\n // if we have a soft match with the current node, return it\n if (isSoftMatch(potentialSoftMatch, newChild)) {\n return potentialSoftMatch;\n }\n\n if (isSoftMatch(potentialSoftMatch, nextSibling)) {\n // the next new node has a soft match with this node, so\n // increment the count of future soft matches\n siblingSoftMatchCount++;\n // ok to cast: if it was null it couldn't be a soft match\n nextSibling = /** @type {Node} */ (nextSibling).nextSibling;\n\n // If there are two future soft matches, bail to allow the siblings to soft match\n // so that we don't consume future soft matches for the sake of the current node\n if (siblingSoftMatchCount >= 2) {\n return null;\n }\n }\n\n // advanced to the next old content child\n potentialSoftMatch = potentialSoftMatch.nextSibling;\n }\n\n return potentialSoftMatch;\n }\n\n /** @type {WeakSet} */\n const generatedByIdiomorph = new WeakSet();\n\n /**\n *\n * @param {string} newContent\n * @returns {Node | null | DocumentFragment}\n */\n function parseContent(newContent) {\n let parser = new DOMParser();\n\n // remove svgs to avoid false-positive matches on head, etc.\n let contentWithSvgsRemoved = newContent.replace(\n /]*>|>)([\\s\\S]*?)<\\/svg>/gim,\n \"\",\n );\n\n // if the newContent contains a html, head or body tag, we can simply parse it w/o wrapping\n if (\n contentWithSvgsRemoved.match(/<\\/html>/) ||\n contentWithSvgsRemoved.match(/<\\/head>/) ||\n contentWithSvgsRemoved.match(/<\\/body>/)\n ) {\n let content = parser.parseFromString(newContent, \"text/html\");\n // if it is a full HTML document, return the document itself as the parent container\n if (contentWithSvgsRemoved.match(/<\\/html>/)) {\n generatedByIdiomorph.add(content);\n return content;\n } else {\n // otherwise return the html element as the parent container\n let htmlElement = content.firstChild;\n if (htmlElement) {\n generatedByIdiomorph.add(htmlElement);\n return htmlElement;\n } else {\n return null;\n }\n }\n } else {\n // if it is partial HTML, wrap it in a template tag to provide a parent element and also to help\n // deal with touchy tags like tr, tbody, etc.\n let responseDoc = parser.parseFromString(\n \"\",\n \"text/html\",\n );\n let content = /** @type {HTMLTemplateElement} */ (\n responseDoc.body.querySelector(\"template\")\n ).content;\n generatedByIdiomorph.add(content);\n return content;\n }\n }\n\n /**\n *\n * @param {null | Node | HTMLCollection | Node[] | Document & {generatedByIdiomorph:boolean}} newContent\n * @returns {Element}\n */\n function normalizeContent(newContent) {\n if (newContent == null) {\n // noinspection UnnecessaryLocalVariableJS\n const dummyParent = document.createElement(\"div\");\n return dummyParent;\n } else if (generatedByIdiomorph.has(/** @type {Element} */ (newContent))) {\n // the template tag created by idiomorph parsing can serve as a dummy parent\n return /** @type {Element} */ (newContent);\n } else if (newContent instanceof Node) {\n // a single node is added as a child to a dummy parent\n const dummyParent = document.createElement(\"div\");\n dummyParent.append(newContent);\n return dummyParent;\n } else {\n // all nodes in the array or HTMLElement collection are consolidated under\n // a single dummy parent element\n const dummyParent = document.createElement(\"div\");\n for (const elt of [...newContent]) {\n dummyParent.append(elt);\n }\n return dummyParent;\n }\n }\n\n /**\n *\n * @param {Node | null} previousSibling\n * @param {Node} morphedNode\n * @param {Node | null} nextSibling\n * @returns {Node[]}\n */\n function insertSiblings(previousSibling, morphedNode, nextSibling) {\n /**\n * @type {Node[]}\n */\n let stack = [];\n /**\n * @type {Node[]}\n */\n let added = [];\n while (previousSibling != null) {\n stack.push(previousSibling);\n previousSibling = previousSibling.previousSibling;\n }\n // Base the loop on the node variable, so that you do not need runtime checks for\n // undefined value inside the loop\n let node = stack.pop();\n while (node !== undefined) {\n added.push(node); // push added preceding siblings on in order and insert\n morphedNode.parentElement?.insertBefore(node, morphedNode);\n node = stack.pop();\n }\n added.push(morphedNode);\n while (nextSibling != null) {\n stack.push(nextSibling);\n added.push(nextSibling); // here we are going in order, so push on as we scan, rather than add\n nextSibling = nextSibling.nextSibling;\n }\n while (stack.length > 0) {\n const node = /** @type {Node} */ (stack.pop());\n morphedNode.parentElement?.insertBefore(node, morphedNode.nextSibling);\n }\n return added;\n }\n\n /**\n *\n * @param {Element} newContent\n * @param {Element} oldNode\n * @param {MorphContext} ctx\n * @returns {Node | null}\n */\n function findBestNodeMatch(newContent, oldNode, ctx) {\n /**\n * @type {Node | null}\n */\n let currentElement;\n currentElement = newContent.firstChild;\n /**\n * @type {Node | null}\n */\n let bestElement = currentElement;\n let score = 0;\n while (currentElement) {\n let newScore = scoreElement(currentElement, oldNode, ctx);\n if (newScore > score) {\n bestElement = currentElement;\n score = newScore;\n }\n currentElement = currentElement.nextSibling;\n }\n return bestElement;\n }\n\n /**\n *\n * @param {Node | null} node1\n * @param {Element} node2\n * @param {MorphContext} ctx\n * @returns {number}\n */\n // TODO: The function handles node1 and node2 as if they are Elements but the function is\n // called in places where node1 and node2 may be just Nodes, not Elements\n function scoreElement(node1, node2, ctx) {\n if (isSoftMatch(node2, node1)) {\n // ok to cast: isSoftMatch performs a null check\n return (\n 0.5 + getIdIntersectionCount(ctx, /** @type {Node} */ (node1), node2)\n );\n }\n return 0;\n }\n\n /**\n *\n * @param {Node} tempNode\n * @param {MorphContext} ctx\n */\n // TODO: The function handles tempNode as if it's Element but the function is called in\n // places where tempNode may be just a Node, not an Element\n function removeNode(tempNode, ctx) {\n removeIdsFromConsideration(ctx, tempNode);\n // skip remove callbacks when we're going to be restoring this from the pantry in the second pass\n if (\n ctx.config.twoPass &&\n hasPersistentIdNodes(ctx, tempNode) &&\n tempNode instanceof Element\n ) {\n moveToPantry(tempNode, ctx);\n } else {\n if (ctx.callbacks.beforeNodeRemoved(tempNode) === false) return;\n tempNode.parentNode?.removeChild(tempNode);\n ctx.callbacks.afterNodeRemoved(tempNode);\n }\n }\n\n /**\n *\n * @param {Node} node\n * @param {MorphContext} ctx\n */\n function moveToPantry(node, ctx) {\n if (ctx.callbacks.beforeNodePantried(node) === false) return;\n\n Array.from(node.childNodes).forEach((child) => {\n moveToPantry(child, ctx);\n });\n\n // After processing children, process the current node\n if (ctx.persistentIds.has(/** @type {Element} */ (node).id)) {\n // @ts-ignore - use proposed moveBefore feature\n if (ctx.pantry.moveBefore) {\n // @ts-ignore - use proposed moveBefore feature\n ctx.pantry.moveBefore(node, null);\n } else {\n ctx.pantry.insertBefore(node, null);\n }\n } else {\n if (ctx.callbacks.beforeNodeRemoved(node) === false) return;\n node.parentNode?.removeChild(node);\n ctx.callbacks.afterNodeRemoved(node);\n }\n }\n\n /**\n *\n * @param {Node | null} root\n * @param {MorphContext} ctx\n */\n function restoreFromPantry(root, ctx) {\n if (root instanceof Element) {\n Array.from(ctx.pantry.children)\n .reverse()\n .forEach((element) => {\n const matchElement = root.querySelector(`#${element.id}`);\n if (matchElement) {\n // @ts-ignore - use proposed moveBefore feature\n if (matchElement.parentElement?.moveBefore) {\n // @ts-ignore - use proposed moveBefore feature\n matchElement.parentElement.moveBefore(element, matchElement);\n while (matchElement.hasChildNodes()) {\n // @ts-ignore - use proposed moveBefore feature\n element.moveBefore(matchElement.firstChild, null);\n }\n } else {\n matchElement.before(element);\n while (matchElement.firstChild) {\n element.insertBefore(matchElement.firstChild, null);\n }\n }\n if (\n ctx.callbacks.beforeNodeMorphed(element, matchElement) !== false\n ) {\n syncNodeFrom(matchElement, element, ctx);\n ctx.callbacks.afterNodeMorphed(element, matchElement);\n }\n matchElement.remove();\n }\n });\n ctx.pantry.remove();\n }\n }\n\n //=============================================================================\n // ID Set Functions\n //=============================================================================\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {string} id\n * @returns {boolean}\n */\n function isIdInConsideration(ctx, id) {\n return !ctx.deadIds.has(id);\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {string} id\n * @param {Node} targetNode\n * @returns {boolean}\n */\n function idIsWithinNode(ctx, id, targetNode) {\n let idSet = ctx.idMap.get(targetNode) || EMPTY_SET;\n return idSet.has(id);\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {Node} node\n * @returns {void}\n */\n function removeIdsFromConsideration(ctx, node) {\n let idSet = ctx.idMap.get(node) || EMPTY_SET;\n for (const id of idSet) {\n ctx.deadIds.add(id);\n }\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {Node} node\n * @returns {boolean}\n */\n function hasPersistentIdNodes(ctx, node) {\n for (const id of ctx.idMap.get(node) || EMPTY_SET) {\n if (ctx.persistentIds.has(id)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {Node} node1\n * @param {Node} node2\n * @returns {number}\n */\n function getIdIntersectionCount(ctx, node1, node2) {\n let sourceSet = ctx.idMap.get(node1) || EMPTY_SET;\n let matchCount = 0;\n for (const id of sourceSet) {\n // a potential match is an id in the source and potentialIdsSet, but\n // that has not already been merged into the DOM\n if (isIdInConsideration(ctx, id) && idIsWithinNode(ctx, id, node2)) {\n ++matchCount;\n }\n }\n return matchCount;\n }\n\n /**\n * @param {Element} content\n * @returns {Element[]}\n */\n function nodesWithIds(content) {\n let nodes = Array.from(content.querySelectorAll(\"[id]\"));\n if (content.id) {\n nodes.push(content);\n }\n return nodes;\n }\n\n /**\n * A bottom up algorithm that finds all elements with ids in the node\n * argument and populates id sets for those nodes and all their parents, generating\n * a set of ids contained within all nodes for the entire hierarchy in the DOM\n *\n * @param {Element} node\n * @param {Map>} idMap\n */\n function populateIdMapForNode(node, idMap) {\n let nodeParent = node.parentElement;\n for (const elt of nodesWithIds(node)) {\n /**\n * @type {Element|null}\n */\n let current = elt;\n // walk up the parent hierarchy of that element, adding the id\n // of element to the parent's id set\n while (current !== nodeParent && current != null) {\n let idSet = idMap.get(current);\n // if the id set doesn't exist, create it and insert it in the map\n if (idSet == null) {\n idSet = new Set();\n idMap.set(current, idSet);\n }\n idSet.add(elt.id);\n current = current.parentElement;\n }\n }\n }\n\n /**\n * This function computes a map of nodes to all ids contained within that node (inclusive of the\n * node). This map can be used to ask if two nodes have intersecting sets of ids, which allows\n * for a looser definition of \"matching\" than tradition id matching, and allows child nodes\n * to contribute to a parent nodes matching.\n *\n * @param {Element} oldContent the old content that will be morphed\n * @param {Element} newContent the new content to morph to\n * @returns {Map>} a map of nodes to id sets for the\n */\n function createIdMap(oldContent, newContent) {\n /**\n *\n * @type {Map>}\n */\n let idMap = new Map();\n populateIdMapForNode(oldContent, idMap);\n populateIdMapForNode(newContent, idMap);\n return idMap;\n }\n\n /**\n * @param {Element} oldContent the old content that will be morphed\n * @param {Element} newContent the new content to morph to\n * @returns {Set} the id set of all persistent nodes that exist in both old and new content\n */\n function createPersistentIds(oldContent, newContent) {\n const toIdTagName = (node) => node.tagName + \"#\" + node.id;\n const oldIdSet = new Set(nodesWithIds(oldContent).map(toIdTagName));\n\n let matchIdSet = new Set();\n for (const newNode of nodesWithIds(newContent)) {\n if (oldIdSet.has(toIdTagName(newNode))) {\n matchIdSet.add(newNode.id);\n }\n }\n return matchIdSet;\n }\n\n //=============================================================================\n // This is what ends up becoming the Idiomorph global object\n //=============================================================================\n return {\n morph,\n defaults,\n };\n})();\n\nexport {Idiomorph};\n","const customEvent = (() => {\n\treturn ('CustomEvent' in window && typeof window.CustomEvent === 'function')\n\t\t? (name, data) => new CustomEvent(name, data)\n\t\t: (name, data) => {\n\t\t\tconst newEvent = document.createEvent('CustomEvent')\n\t\t\tnewEvent.initCustomEvent(name, true, true, data)\n\t\t\treturn newEvent\n\t\t}\n})()\n\nconst handler = (node, ev) => {\n\treturn function (e) {\n\t\tconst scope = this\n\t\tconst detail = e.detail || {}\n\t\tnode.__events[ev].forEach(o => {\n\t\t\to.handler.apply(scope, [e].concat(detail.args))\n\t\t})\n\t}\n}\n\nconst removeListener = (node, ev) => {\n\tif (node.__events[ev] && node.__events[ev].listener) {\n\t\tnode.removeEventListener(\n\t\t\tev,\n\t\t\tnode.__events[ev].listener,\n\t\t\t(ev == 'focus' || ev == 'blur' || ev == 'mouseenter' || ev == 'mouseleave'))\n\t\tdelete node.__events[ev]\n\t}\n}\n\nconst delegate = (node, selector, callback) => {\n\treturn function (e) {\n\n\t\tconst element = this\n\t\tconst detail = e.detail || {}\n\n\t\tlet parent = e.target\n\n\t\twhile (parent) {\n\t\t\tif (parent.matches(selector)) {\n\t\t\t\te.delegateTarget = parent\n\t\t\t\tcallback.apply(element, [e].concat(detail.args))\n\t\t\t}\n\t\t\tif (parent === node) break\n\t\t\tparent = parent.parentNode\n\t\t}\n\t}\n}\n\nexport const on = (node, ev, selectorOrCallback, callback) => {\n\n\tnode.__events = node.__events || {}\n\tnode.__events[ev] = (node.__events[ev] || [])\n\n\tif (!node.__events[ev].length) {\n\t\tconst fn = handler(node, ev)\n\t\tnode.addEventListener(\n\t\t\tev,\n\t\t\tfn,\n\t\t\t(ev == 'focus' || ev == 'blur' || ev == 'mouseenter' || ev == 'mouseleave'))\n\t\tnode.__events[ev].listener = fn\n\t}\n\n\tif (selectorOrCallback.call) {\n\t\tnode.__events[ev].push({ handler: selectorOrCallback, callback: selectorOrCallback })\n\t} else {\n\t\tnode.__events[ev].push({ handler: delegate(node, selectorOrCallback, callback), callback })\n\t}\n}\n\nexport const off = (node, ev, fn) => {\n\n\tif (fn && node.__events[ev] && node.__events[ev].length) {\n\t\tvar old = node.__events[ev]\n\t\tnode.__events[ev] = node.__events[ev].filter(function (o) { return o.callback != fn; })\n\t\tnode.__events[ev].listener = old.listener\n\t\tif (!node.__events[ev].length)\n\t\t\tremoveListener(node, ev)\n\t} else {\n\t\tremoveListener(node, ev)\n\t}\n}\n\nexport const trigger = (node, name, args) => {\n\tnode.dispatchEvent(customEvent(name, { bubbles: true, detail: args }))\n}\n","import { type Component } from '..'\nimport { Idiomorph } from 'idiomorph/dist/idiomorph.esm'\nimport { rAF, dup, safe } from './utils'\nimport { buildtemplates } from './template-system'\nimport { on, off, trigger } from './utils/events'\nimport { publish, subscribe } from './utils/pubsub'\n\nexport default function Component( elm, { module, dependencies, templates, components }) {\n\n\tconst options = getOptions( module )\n\tconst initialState = (new Function( `return ${elm.getAttribute('html-model') || '{}'}`))()\n\tconst selector = Object.keys(components).toString()\n\n\tbuildtemplates( elm, selector, templates, components )\n\n\tconst tplid = elm.getAttribute('tplid')\n\tconst template = tplid ? templates[tplid] : null\n\tconst state = { data: module.model ? dup(module.model) : {} }\n\tstate.data = Object.assign( state.data, initialState)\n\n\tconst base: Component = {\n\t\ttemplate,\n\t\telm,\n\t\tdependencies,\n\t\tpublish,\n\t\tsubscribe,\n\n\t\tmain(fn) {\n\t\t\toptions.main = fn\n\t\t},\n\n\t\tunmount(fn) {\n\t\t\toptions.unmount = fn\n\t\t},\n\n\t\tonupdate(fn) {\n\t\t\toptions.onupdate = fn\n\t\t},\n\n\t\ton(eventName, selectorOrCallback, callback) {\n\t\t\ton(elm, eventName, selectorOrCallback, callback)\n\t\t},\n\n\t\toff(eventName, callback) {\n\t\t\toff(elm, eventName, callback)\n\t\t},\n\n\t\ttrigger(eventName, target, args) {\n\t\t\tif (target.constructor === String) {\n\t\t\t\tArray\n\t\t\t\t\t.from(elm.querySelectorAll(target))\n\t\t\t\t\t.forEach( children => trigger(children, eventName, { args: args }) )\n\t\t\t}\n\t\t\telse trigger(elm, eventName, { args: target })\n\t\t},\n\n\t\temit: ( ...args ) => {\n\t\t\ttrigger(elm, args.shift(), { args: args })\n\t\t},\n\n\t\tstate: {\n\t\t\tset( data ) {\n\t\t\t\tif (data.constructor === Function) {\n\t\t\t\t\tconst newstate = dup(state.data)\n\t\t\t\t\tdata(newstate)\n\t\t\t\t\tbase.render(newstate)\n\t\t\t\t} else {\n\t\t\t\t\tbase.render(data)\n\t\t\t\t}\n\t\t\t\treturn new Promise((resolve) => rAF(_ => rAF(() => resolve(state.data))))\n\t\t\t},\n\t\t\tget() {\n\t\t\t\treturn dup(state.data)\n\t\t\t},\n\n\t\t\tgetRaw(){\n\t\t\t\treturn state.data\n\t\t\t}\n\t\t},\n\n\t\trender(data = state.data) {\n\n\t\t\tif (!document.body.contains(elm)) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tstate.data = Object.assign(state.data, data)\n\n\t\t\tconst newdata = dup(state.data)\n\t\t\tconst newhtml = templates[tplid].call(Object.assign(options.view(newdata), elm.___scope___), elm, safe)\n\n\t\t\tIdiomorph.morph(elm, newhtml, IdiomorphOptions(elm))\n\t\t\tupdateScope( elm )\n\n\t\t\trAF(_ => {\n\t\t\t\tArray\n\t\t\t\t\t.from(elm.querySelectorAll('[tplid]'))\n\t\t\t\t\t.forEach((child: any) => {\n\t\t\t\t\t\tconst props = Object.assign( child.base.state.getRaw(), data )\n\t\t\t\t\t\tchild.options.onupdate(props)\n\t\t\t\t\t\tchild.base.render(props)\n\t\t\t\t\t})\n\t\t\t})\n\t\t},\n\n\t\tinnerHTML( target, html_ ) {\n\n\t\t\tconst element = html_? target : elm\n\t\t\tconst clone = element.cloneNode()\n\t\t\tconst html = html_? html_ : target\n\t\t\tclone.innerHTML = html\n\n\t\t\trAF( _ => Idiomorph.morph(element, clone, IdiomorphOptions) )\n\t\t}\n\t}\n\n\treturn { base, options }\n}\n\nconst getOptions = (module) => ({\n\tmain: (a) => a,\n\tunmount: (a) => a,\n\tonupdate: (a) => a,\n\tview: module.view ? module.view : (a) => a\n})\n\nconst updateScope = (node) => {\n\tnode.querySelectorAll('[scope]').forEach( scopeElement => {\n\t\tscopeElement.querySelectorAll('[tplid]').forEach( cp => {\n\t\t\tif( !cp.___scope___ ) {\n\t\t\t\tconst script = scopeElement.lastElementChild\n\t\t\t\tcp.___scope___ = 'scope' in script.dataset? (new Function(`return ${script.text}`))() : {}\n\t\t\t}\n\t\t})\n\t})\n}\n\n\nconst IdiomorphOptions = (parent) => ({\n\n\tcallbacks: {\n\n\t\tbeforeNodeMorphed( node ) {\n\t\t\tif( node.nodeType === 1 ) {\n\t\t\t\tif( 'html-static' in node.attributes ) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t\tif( node.base && node !== parent ) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n})\n","import Component from './component'\nimport { purge, rAF } from './utils'\n\nexport default function Element(module, dependencies, templates, components) {\n\n\treturn class extends HTMLElement {\n\n\t\tbase: any\n\t\toptions: any\n\t\treturns : any\n\t\t__events: any\n\n\t\tconstructor() {\n\t\t\tsuper()\n\t\t}\n\n\t\tconnectedCallback() {\n\n\t\t\tconst { base, options } = Component(this, { module, dependencies, templates, components })\n\n\t\t\tthis.base = base\n\t\t\tthis.options = options\n\t\t\tthis.base.render()\n\t\t\tthis.returns = module.default(base)\n\n\t\t\tif( this.__template && this.__template.constructor === Promise ) {\n\t\t\t\tthis.__template.then( _ => {\n\t\t\t\t\tif( this.base && this.options.main) {\n\t\t\t\t\t\tconst array = this.options.main(this.base)\n\t\t\t\t\t\tif( array && array.length ){\n\t\t\t\t\t\t\tarray.forEach(f => f(this.base))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif( this.returns && this.returns.constructor === Promise ) {\n\t\t\t\tthis.returns.then( _ => {\n\t\t\t\t\tif( this.base && this.options.main) {\n\t\t\t\t\t\tconst array = this.options.main(this.base)\n\t\t\t\t\t\tif( array && array.length ){\n\t\t\t\t\t\t\tarray.forEach(f => f(this.base))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\n\t\t\t} else {\n\t\t\t\tif( this.base && this.options.main ){\n\t\t\t\t\tconst array = this.options.main(this.base)\n\t\t\t\t\tif( array && array.length ) {\n\t\t\t\t\t\tarray.forEach(f => f(this.base))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdisconnectedCallback() {\n\t\t\tthis.options.unmount(this.base)\n\t\t\trAF(() => {\n\t\t\t\tif(!document.body.contains(this) ) {\n\t\t\t\t\tthis.__events? this.__events = null : null\n\t\t\t\t\tthis.base? this.base.elm = null : null\n\t\t\t\t\tthis.base? this.base = null : null\n\t\t\t\t\tpurge(this)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tattributeChangedCallback() {\n\t\t\t//TODO\n\t\t}\n\t}\n}\n","import { templateConfig, buildtemplates } from './template-system'\nimport { publish, subscribe } from './utils/pubsub'\nimport { html, attributes } from '../html'\nimport Element from './element'\n\nconst templates = {}\nconst components = {}\n\nexport { html, attributes }\n\nexport default {\n\n\ttemplateConfig,\n\n\tpublish,\n\tsubscribe,\n\n\tregister( name, module, dependencies = {} ) {\n\t\tcomponents[name] = { name, module, dependencies }\n\t},\n\n\tstart( target = document.body ) {\n\t\tconst keys = Object.keys(components)\n\t\tconst selector = keys.toString()\n\t\tif( keys.length ) {\n\t\t\tbuildtemplates( target, selector, templates, components )\n\t\t\tregisterComponents()\n\t\t}\n\t}\n}\n\nconst registerComponents = () => {\n\tObject\n\t\t.values( components )\n\t\t.forEach( (component) => {\n\t\t\tconst { name, module, dependencies } = component as any\n\t\t\tif( !customElements.get(name) ){\n\t\t\t\tconst Base = Element(module, dependencies, templates, components)\n\t\t\t\tcustomElements.define(name, Base)\n\t\t\t}\n\t\t})\n}\n","\nexport const attributes = ( attrs ) => {\n\tconst result = Object.entries(attrs)\n\t\t.map(([key, value]) => {\n\t\t\tif( value === '' ) {\n\t\t\t\treturn key\n\t\t\t}\n\t\t\treturn `${key}=\"${value}\"`\n\t\t})\n\t\t.join(' ')\n\treturn result\n}\n\n// From\n// https://2ality.com/2015/01/template-strings-html.html#comment-2078932192\nexport const html = (literalSections, ...substs) => {\n\n\t// Use raw literal sections: we don’t want\n\t// backslashes (\\n etc.) to be interpreted\n\tlet raw = literalSections.raw\n\n\tlet result = ''\n\n\tsubsts.forEach((subst, i) => {\n\t\t// Retrieve the literal section preceding\n\t\t// the current substitution\n\t\tlet lit = raw[i]\n\n\t\t// In the example, map() returns an array:\n\t\t// If substitution is an array (and not a string),\n\t\t// we turn it into a string\n\t\tif (Array.isArray(subst)) {\n\t\t\tsubst = subst.join('')\n\t\t}\n\n\t\tresult += lit\n\t\tresult += subst\n\t})\n\t// Take care of last literal section\n\t// (Never fails, because an empty template string\n\t// produces one literal section, an empty string)\n\tresult += raw[raw.length-1] // (A)\n\n\treturn result\n}\n"],"names":["parser","DOMParser","wrap","open","node","close","_a","parentNode","insertBefore","_b","nextSibling","textarea","document","createElement","decodeHTML","text","innerHTML","value","rAF","fn","requestAnimationFrame","setTimeout","dup","o","JSON","parse","stringify","purge","d","i","l","n","a","attributes","length","name","childNodes","safe","execute","val","err","config","tags","Template","element","fixDIffIf","html","regexTags","RegExp","virtual","parseFromString","replace","querySelectorAll","forEach","htmlForeach","getAttribute","htmlFor","htmlIf","htmlInner","htmlClass","forEachInstruction","selector","split","match","varname","object","removeAttribute","setAttribute","script","dataset","scope","type","appendChild","createTextNode","className","trim","body","all","key","Transpile","outerHTML","decodedHTML","Function","_","variable","buildtemplates","target","templates","components","concat","matches","Array","from","reverse","template","content","createTemplateId","id","c","r","Math","random","toString","localName","module","children","constructor","Promise","__template","then","htmlstring","el","createComment","topics","_async","publish","params","Object","assign","topic","subscribe","method","push","filter","Idiomorph","EMPTY_SET","Set","defaults","morphStyle","callbacks","beforeNodeAdded","noOp","afterNodeAdded","beforeNodeMorphed","afterNodeMorphed","beforeNodeRemoved","afterNodeRemoved","beforeAttributeUpdated","beforeNodePantried","head","style","shouldPreserve","elt","shouldReAppend","shouldRemove","afterHeadMorphed","morphNormalizedContent","oldNode","normalizedNewContent","ctx","block","oldHead","querySelector","newHead","promises","handleHeadElement","ignore","morphChildren","twoPass","restoreFromPantry","bestMatch","newContent","currentElement","firstChild","bestElement","score","newScore","scoreElement","findBestNodeMatch","previousSibling","morphedNode","morphOldNodeTo","elements","stack","added","pop","parentElement","insertSiblings","ignoreValueOfActiveElement","possibleActiveElement","ignoreActiveValue","activeElement","ignoreActive","removeChild","isSoftMatch","HTMLHeadElement","syncNodeFrom","replaceChild","newParent","oldParent","HTMLTemplateElement","newChild","nextNewChild","insertionPoint","persistentIds","has","removeIdsFromConsideration","isIdSetMatch","idSetMatch","findIdSetMatch","removeNodesBetween","softMatch","findSoftMatch","tempNode","removeNode","ignoreAttribute","attr","to","updateType","nodeType","fromEl","toEl","fromAttributes","toAttributes","fromAttribute","toAttribute","hasAttribute","nodeValue","HTMLInputElement","fromValue","toValue","syncBooleanAttribute","HTMLOptionElement","HTMLTextAreaElement","syncInputValue","attributeName","Element","fromLiveValue","ignoreUpdate","newHeadTag","currentHead","removed","preserved","nodesToAppend","headMergeStyle","srcToNewHeadNodes","Map","newHeadChild","set","currentHeadElt","inNewContent","isReAppended","isPreserved","delete","values","newNode","newElt","createRange","createContextualFragment","href","src","resolve","promise","_resolve","addEventListener","removedElement","kept","createPantry","pantry","hidden","insertAdjacentElement","node1","node2","tagName","getIdIntersectionCount","startInclusive","endExclusive","cursor","newChildPotentialIdCount","potentialMatch","otherMatchCount","potentialSoftMatch","siblingSoftMatchCount","generatedByIdiomorph","WeakSet","idMap","get","hasPersistentIdNodes","moveToPantry","child","moveBefore","root","matchElement","hasChildNodes","before","remove","isIdInConsideration","deadIds","idIsWithinNode","targetNode","idSet","add","sourceSet","matchCount","nodesWithIds","nodes","populateIdMapForNode","nodeParent","current","createIdMap","oldContent","createPersistentIds","toIdTagName","oldIdSet","map","matchIdSet","morph","Document","documentElement","contentWithSvgsRemoved","htmlElement","parseContent","normalizedContent","Node","dummyParent","append","normalizeContent","mergedConfig","finalConfig","mergeDefaults","createMorphContext","customEvent","window","CustomEvent","data","newEvent","createEvent","initCustomEvent","handler","ev","e","this","detail","__events","apply","args","removeListener","listener","removeEventListener","delegate","callback","parent","delegateTarget","on","selectorOrCallback","call","off","old","trigger","dispatchEvent","bubbles","getOptions","main","unmount","onupdate","view","updateScope","scopeElement","cp","___scope___","lastElementChild","IdiomorphOptions","base","dependencies","HTMLElement","connectedCallback","options","elm","initialState","keys","tplid","state","model","eventName","String","emit","shift","newstate","render","getRaw","contains","newdata","newhtml","props","html_","clone","cloneNode","Component","returns","default","array","f","disconnectedCallback","attributeChangedCallback","index","templateConfig","newconfig","register","start","registerComponents","component","customElements","Base","define","attrs","entries","join","literalSections","substs","raw","result","subst","lit","isArray"],"mappings":"6OAEM,MAAAA,EAAS,IAAIC,UAyEnB,MAAMC,EAAO,CAACC,EAAMC,EAAMC,aACpB,OAAAC,EAAAF,EAAAG,aAAYD,EAAAE,aAAaL,EAAMC,GACpC,OAAAK,EAAAL,EAAKG,aAALE,EAAiBD,aAAaH,EAAOD,EAAKM,YAAA,EC7ErCC,EAAWC,SAASC,cAAc,YAE3BC,EAAcC,IAC1BJ,EAASK,UAAYD,EACdJ,EAASM,OAGJC,EAAOC,GACfC,sBACIA,sBAAsBD,GAEtBE,WAAWF,EAAI,IAAO,IAUlBG,EAAOC,GACZC,KAAKC,MAAMD,KAAKE,UAAUH,IAIrBI,EAASC,IACrB,IAAsBC,EAAGC,EAAGC,EAAxBC,EAAIJ,EAAEK,WACV,GAAID,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pEA,MAAMlT,EAAY,CAAA,EACZC,EAAa,CAAA,EAIJkT,EAAA,CAEdC,eNL8BC,IACvBvR,OAAAC,OAAO7E,EAAQmW,EAAS,EMM/BzR,UACAK,YAEA,QAAAqR,CAAU1W,EAAMqE,EAAQmQ,EAAe,CAAA,GACtCnR,EAAWrD,GAAQ,CAAEA,OAAMqE,OAAAA,EAAQmQ,eACpC,EAEA,KAAAmC,CAAOxT,EAAS1E,SAASgE,MAClB,MAAAqS,EAAO5P,OAAO4P,KAAKzR,GACnB3B,EAAWoT,EAAK3Q,WAClB2Q,EAAK/U,SACQmD,EAAAC,EAAQzB,EAAU0B,EAAWC,OAG/C,GAGKuT,EAAqB,KAC1B1R,OACE+H,OAAQ5J,GACRnC,SAAU2V,IACV,MAAM7W,KAAEA,EAAMqE,OAAAA,EAAAA,aAAQmQ,GAAiBqC,EACvC,IAAKC,eAAe7H,IAAIjP,GAAO,CAC9B,MAAM+W,EAAOhL,EAAQ1H,EAAQmQ,EAAcpR,EAAWC,GACvCyT,eAAAE,OAAOhX,EAAM+W,EAC7B,IACA,eCvCyBE,GACZ/R,OAAOgS,QAAQD,GAC5BpG,KAAI,EAAElO,EAAK7D,KACG,KAAVA,EACI6D,EAED,GAAGA,MAAQ7D,OAElBqY,KAAK,wBAMY,CAACC,KAAoBC,KAIxC,IAAIC,EAAMF,EAAgBE,IAEtBC,EAAS,GAsBN,OApBAF,EAAAnW,SAAQ,CAACsW,EAAO9X,KAGlB,IAAA+X,EAAMH,EAAI5X,GAKV8D,MAAMkU,QAAQF,KACTA,EAAAA,EAAML,KAAK,KAGVI,GAAAE,EACAF,GAAAC,CAAA,IAKDD,GAAAD,EAAIA,EAAIvX,OAAO,GAElBwX,CAAA","x_google_ignoreList":[4]} \ No newline at end of file +{"version":3,"file":"jails.js","sources":["../src/transpile.ts","../src/utils/index.ts","../src/template-system.ts","../src/utils/pubsub.ts","../node_modules/idiomorph/dist/idiomorph.esm.js","../src/utils/events.ts","../src/component.ts","../src/element.ts","../src/index.ts","../html.ts"],"sourcesContent":["import { uuid } from './utils'\n\nconst parser = new DOMParser()\n\nexport default function Transpile(html, config) {\n\n\tconst regexTags = new RegExp(`\\\\${config.tags[0]}(.+?)\\\\${config.tags[1]}`, 'g')\n\tconst virtual = parser.parseFromString(html.replace(/<\\/?template[^>]*>/g, ''), 'text/html')\n\n\tvirtual.querySelectorAll('[html-for], [html-if], [html-inner], [html-class], [html-model]').forEach((element) => {\n\n\t\tconst htmlForeach = element.getAttribute('html-foreach')\n\t\tconst htmlFor \t= element.getAttribute('html-for')\n\t\tconst htmlIf \t= element.getAttribute('html-if')\n\t\tconst htmlInner = element.getAttribute('html-inner')\n\t\tconst htmlClass = element.getAttribute('html-class')\n\t\tconst forEachInstruction = htmlFor || htmlForeach\n\n\t\tif ( forEachInstruction ) {\n\t\t\tconst selector = htmlFor? 'html-for': 'html-foreach'\n\t\t\tconst split = forEachInstruction.match(/(.*)\\sin\\s(.*)/) || ''\n\t\t\tconst varname = split[1]\n\t\t\tconst object = split[2]\n\n\t\t\telement.removeAttribute(selector)\n\t\t\telement.setAttribute('scope', '')\n\t\t\tconst script = document.createElement('script')\n\n\t\t\tscript.dataset.scope = ''\n\t\t\tscript.type = 'text/html'\n\t\t\tscript.text = `%%_= $scope _%%`\n\n\t\t\telement.appendChild( script )\n\n\t\t\tconst open = document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${object} }) ){ var ${varname} = ${object}[$key]; var $scope = JSON.stringify({ '${varname}':${varname}, $index: $index, $key:$key }); _%%`)\n\t\t\tconst close = document.createTextNode(`%%_ $index++; } })() _%%`)\n\t\t\twrap(open, element, close)\n\t\t}\n\t\tif (htmlIf) {\n\t\t\telement.removeAttribute('html-if')\n\t\t\tconst open = document.createTextNode(`%%_ if ( safe(function(){ return ${htmlIf} }) ){ _%%`)\n\t\t\tconst close = document.createTextNode(`%%_ } _%%`)\n\t\t\twrap(open, element, close)\n\t\t}\n\t\tif (htmlInner) {\n\t\t\telement.removeAttribute('html-inner')\n\t\t\telement.innerHTML = `%%_=${htmlInner}_%%`\n\t\t}\n\t\tif (htmlClass) {\n\t\t\telement.removeAttribute('html-class')\n\t\t\telement.className = (element.className + ` %%_=${htmlClass}_%%`).trim()\n\t\t}\n\t})\n\n\treturn (\n\t\tvirtual.body.innerHTML\n\t\t\t.replace(regexTags, '%%_=$1_%%')\n\t\t\t// Booleans\n\t\t\t// https://meiert.com/en/blog/boolean-attributes-of-html/\n\t\t\t.replace(/html-(allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|formnovalidate|inert|ismap|itemscope|loop|multiple|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|selected)=\\\"(.*?)\\\"/g, `%%_if(safe(function(){ return $2 })){_%%$1%%_}_%%`)\n\t\t\t// The rest\n\t\t\t.replace(/html-(.*?)=\\\"(.*?)\\\"/g, (all, key, value) => {\n\t\t\t\tif (key === 'key' || key === 'model' || key == 'scope') {\n\t\t\t\t\treturn all\n\t\t\t\t}\n\t\t\t\tif (value) {\n\t\t\t\t\tvalue = value.replace(/^{|}$/g, '')\n\t\t\t\t\treturn `${key}=\"%%_=safe(function(){ return ${value} })_%%\"`\n\t\t\t\t} else {\n\t\t\t\t\treturn all\n\t\t\t\t}\n\t\t\t})\n\t)\n}\n\nconst wrap = (open, node, close) => {\n\tnode.parentNode?.insertBefore(open, node)\n\tnode.parentNode?.insertBefore(close, node.nextSibling)\n}\n","const textarea = document.createElement('textarea')\n\nexport const decodeHTML = (text) => {\n\ttextarea.innerHTML = text\n\treturn textarea.value\n}\n\nexport const rAF = (fn) => {\n\tif (requestAnimationFrame)\n\t\treturn requestAnimationFrame(fn)\n\telse\n\t\treturn setTimeout(fn, 1000 / 60)\n}\n\nexport const uuid = () => {\n\treturn 'xxxxxxxx'.replace(/[xy]/g, (c) => {\n\t\tconst r = Math.random() * 8 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)\n\t\treturn v.toString(8)\n\t})\n}\n\nexport const dup = (o) => {\n\treturn JSON.parse(JSON.stringify(o))\n}\n\n// http://crockford.com/javascript/memory/leak.html\nexport const purge = (d) => {\n\tvar a = d.attributes, i, l, n\n\tif (a) {\n\t\tfor (i = a.length - 1; i >= 0; i -= 1) {\n\t\t\tn = a[i].name\n\t\t\tif (typeof d[n] === 'function') {\n\t\t\t\td[n] = null\n\t\t\t}\n\t\t}\n\t}\n\ta = d.childNodes\n\tif (a) {\n\t\tl = a.length\n\t\tfor (i = 0; i < l; i += 1) {\n\t\t\tpurge(d.childNodes[i])\n\t\t}\n\t}\n}\n\nexport const safe = (execute, val) => {\n\ttry{return execute()}catch(err){return val || ''}\n}\n","import Transpile from './transpile'\nimport { uuid, decodeHTML } from './utils'\n\nconst config = {\n\ttags: ['${', '}']\n}\n\nexport const templateConfig = (newconfig) => {\n\tObject.assign(config, newconfig)\n}\n\nexport default function Template(element) {\n\n\tfixDIffIf(element)\n\tconst html = Transpile(element.outerHTML, config)\n\tconst decodedHTML = JSON.stringify(html)\n\n\treturn new Function('$element', 'safe',`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${decodedHTML\n\t\t\t\t.replace(/%%_=(.+?)_%%/g, function(_, variable){\n\t\t\t\t\treturn '\"+safe(function(){return '+decodeHTML(variable)+';})+\"'\n\t\t\t\t})\n\t\t\t\t.replace(/%%_(.+?)_%%/g, function(_, variable){\n\t\t\t\t\treturn '\";' + decodeHTML(variable) +'\\noutput+=\"'\n\t\t\t\t})};return output;\n\t\t}\n\t`)\n}\n\nexport const buildtemplates = ( target, selector, templates, components ) => {\n\t[]\n\t\t.concat( target.matches? (target.matches(selector)? target : []) : [] )\n\t\t.concat( Array.from(target.querySelectorAll( selector )) )\n\t\t.reverse()\n\t\t.forEach( (node:HTMLElement) => {\n\t\t\tnode.querySelectorAll('template').forEach( template => buildtemplates(template.content, selector, templates, components ))\n\t\t\tcreateTemplateId(node, templates, components)\n\t\t})\n}\n\nconst createTemplateId = (element, templates, components ) => {\n\n\tconst tplid = element.getAttribute('tplid')\n\n\tif (!tplid) {\n\t\tconst id = uuid()\n\t\telement.setAttribute('tplid', id)\n\t\tconst name = element.localName\n\n\t\tif( name in components && components[name].module.template ) {\n\t\t\tconst children = element.innerHTML\n\t\t\tconst html = components[name].module.template({ children })\n\t\t\tif( html.constructor === Promise ) {\n\t\t\t\telement.__template = html\n\t\t\t\thtml.then( htmlstring => {\n\t\t\t\t\telement.innerHTML = htmlstring\n\t\t\t\t\ttemplates[id] = Template(element)\n\t\t\t\t})\n\t\t\t}else {\n\t\t\t\telement.innerHTML = html\n\t\t\t}\n\t\t}\n\t\ttemplates[id] = Template(element)\n\t}\n}\n\n// Sometimes we don't know why something works, especially when using third party code like Idiomorph.\n// So just letting anyone knows that this part has to be improved some time.\nconst fixDIffIf = (node) => {\n\tconst _if = node.querySelectorAll('[html-if]')\n\t_if.forEach( el => {\n\t\tel.parentNode.insertBefore(document.createComment(''), el.nextSibling)\n\t})\n}\n","const topics: any = {}\nconst _async: any = {}\n\nexport const publish = (name, params) => {\n\t_async[name] = Object.assign({}, _async[name], params)\n\tif (topics[name])\n\t\ttopics[name].forEach(topic => topic(params))\n}\n\nexport const subscribe = (name, method) => {\n\ttopics[name] = topics[name] || []\n\ttopics[name].push(method)\n\tif (name in _async) {\n\t\tmethod(_async[name])\n\t}\n\treturn () => {\n\t\ttopics[name] = topics[name].filter( fn => fn != method )\n\t}\n}\n\n","/**\n * @typedef {object} ConfigHead\n *\n * @property {'merge' | 'append' | 'morph' | 'none'} [style]\n * @property {boolean} [block]\n * @property {boolean} [ignore]\n * @property {function(Element): boolean} [shouldPreserve]\n * @property {function(Element): boolean} [shouldReAppend]\n * @property {function(Element): boolean} [shouldRemove]\n * @property {function(Element, {added: Node[], kept: Element[], removed: Element[]}): void} [afterHeadMorphed]\n */\n\n/**\n * @typedef {object} ConfigCallbacks\n *\n * @property {function(Node): boolean} [beforeNodeAdded]\n * @property {function(Node): void} [afterNodeAdded]\n * @property {function(Element, Node): boolean} [beforeNodeMorphed]\n * @property {function(Element, Node): void} [afterNodeMorphed]\n * @property {function(Element): boolean} [beforeNodeRemoved]\n * @property {function(Element): void} [afterNodeRemoved]\n * @property {function(string, Element, \"update\" | \"remove\"): boolean} [beforeAttributeUpdated]\n * @property {function(Element): boolean} [beforeNodePantried]\n */\n\n/**\n * @typedef {object} Config\n *\n * @property {'outerHTML' | 'innerHTML'} [morphStyle]\n * @property {boolean} [ignoreActive]\n * @property {boolean} [ignoreActiveValue]\n * @property {ConfigCallbacks} [callbacks]\n * @property {ConfigHead} [head]\n */\n\n/**\n * @typedef {function} NoOp\n *\n * @returns {void}\n */\n\n/**\n * @typedef {object} ConfigHeadInternal\n *\n * @property {'merge' | 'append' | 'morph' | 'none'} style\n * @property {boolean} [block]\n * @property {boolean} [ignore]\n * @property {(function(Element): boolean) | NoOp} shouldPreserve\n * @property {(function(Element): boolean) | NoOp} shouldReAppend\n * @property {(function(Element): boolean) | NoOp} shouldRemove\n * @property {(function(Element, {added: Node[], kept: Element[], removed: Element[]}): void) | NoOp} afterHeadMorphed\n */\n\n/**\n * @typedef {object} ConfigCallbacksInternal\n *\n * @property {(function(Node): boolean) | NoOp} beforeNodeAdded\n * @property {(function(Node): void) | NoOp} afterNodeAdded\n * @property {(function(Node, Node): boolean) | NoOp} beforeNodeMorphed\n * @property {(function(Node, Node): void) | NoOp} afterNodeMorphed\n * @property {(function(Node): boolean) | NoOp} beforeNodeRemoved\n * @property {(function(Node): void) | NoOp} afterNodeRemoved\n * @property {(function(string, Element, \"update\" | \"remove\"): boolean) | NoOp} beforeAttributeUpdated\n * @property {(function(Node): boolean) | NoOp} beforeNodePantried\n */\n\n/**\n * @typedef {object} ConfigInternal\n *\n * @property {'outerHTML' | 'innerHTML'} morphStyle\n * @property {boolean} [ignoreActive]\n * @property {boolean} [ignoreActiveValue]\n * @property {ConfigCallbacksInternal} callbacks\n * @property {ConfigHeadInternal} head\n * @property {boolean} [twoPass]\n */\n\n/**\n * @typedef {Function} Morph\n *\n * @param {Element | Document} oldNode\n * @param {Element | Node | HTMLCollection | Node[] | string | null} newContent\n * @param {Config} [config]\n * @returns {undefined | Node[]}\n */\n\n// base IIFE to define idiomorph\n/**\n *\n * @type {{defaults: ConfigInternal, morph: Morph}}\n */\nvar Idiomorph = (function () {\n \"use strict\";\n\n /**\n * @typedef {object} MorphContext\n *\n * @property {Node} target\n * @property {Node} newContent\n * @property {ConfigInternal} config\n * @property {ConfigInternal['morphStyle']} morphStyle\n * @property {ConfigInternal['ignoreActive']} ignoreActive\n * @property {ConfigInternal['ignoreActiveValue']} ignoreActiveValue\n * @property {Map>} idMap\n * @property {Set} persistentIds\n * @property {Set} deadIds\n * @property {ConfigInternal['callbacks']} callbacks\n * @property {ConfigInternal['head']} head\n * @property {HTMLDivElement} pantry\n */\n\n //=============================================================================\n // AND NOW IT BEGINS...\n //=============================================================================\n\n /**\n *\n * @type {Set}\n */\n let EMPTY_SET = new Set();\n\n /**\n * Default configuration values, updatable by users now\n * @type {ConfigInternal}\n */\n let defaults = {\n morphStyle: \"outerHTML\",\n callbacks: {\n beforeNodeAdded: noOp,\n afterNodeAdded: noOp,\n beforeNodeMorphed: noOp,\n afterNodeMorphed: noOp,\n beforeNodeRemoved: noOp,\n afterNodeRemoved: noOp,\n beforeAttributeUpdated: noOp,\n beforeNodePantried: noOp,\n },\n head: {\n style: \"merge\",\n shouldPreserve: function (elt) {\n return elt.getAttribute(\"im-preserve\") === \"true\";\n },\n shouldReAppend: function (elt) {\n return elt.getAttribute(\"im-re-append\") === \"true\";\n },\n shouldRemove: noOp,\n afterHeadMorphed: noOp,\n },\n };\n\n /**\n * =============================================================================\n * Core Morphing Algorithm - morph, morphNormalizedContent, morphOldNodeTo, morphChildren\n * =============================================================================\n *\n * @param {Element | Document} oldNode\n * @param {Element | Node | HTMLCollection | Node[] | string | null} newContent\n * @param {Config} [config]\n * @returns {undefined | Node[]}\n */\n function morph(oldNode, newContent, config = {}) {\n if (oldNode instanceof Document) {\n oldNode = oldNode.documentElement;\n }\n\n if (typeof newContent === \"string\") {\n newContent = parseContent(newContent);\n }\n\n let normalizedContent = normalizeContent(newContent);\n\n let ctx = createMorphContext(oldNode, normalizedContent, config);\n\n return morphNormalizedContent(oldNode, normalizedContent, ctx);\n }\n\n /**\n *\n * @param {Element} oldNode\n * @param {Element} normalizedNewContent\n * @param {MorphContext} ctx\n * @returns {undefined | Node[]}\n */\n function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {\n if (ctx.head.block) {\n let oldHead = oldNode.querySelector(\"head\");\n let newHead = normalizedNewContent.querySelector(\"head\");\n if (oldHead && newHead) {\n let promises = handleHeadElement(newHead, oldHead, ctx);\n // when head promises resolve, call morph again, ignoring the head tag\n Promise.all(promises).then(function () {\n morphNormalizedContent(\n oldNode,\n normalizedNewContent,\n Object.assign(ctx, {\n head: {\n block: false,\n ignore: true,\n },\n }),\n );\n });\n return;\n }\n }\n\n if (ctx.morphStyle === \"innerHTML\") {\n // innerHTML, so we are only updating the children\n morphChildren(normalizedNewContent, oldNode, ctx);\n if (ctx.config.twoPass) {\n restoreFromPantry(oldNode, ctx);\n }\n return Array.from(oldNode.children);\n } else if (ctx.morphStyle === \"outerHTML\" || ctx.morphStyle == null) {\n // otherwise find the best element match in the new content, morph that, and merge its siblings\n // into either side of the best match\n let bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);\n\n // stash the siblings that will need to be inserted on either side of the best match\n let previousSibling = bestMatch?.previousSibling ?? null;\n let nextSibling = bestMatch?.nextSibling ?? null;\n\n // morph it\n let morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);\n\n if (bestMatch) {\n // if there was a best match, merge the siblings in too and return the\n // whole bunch\n if (morphedNode) {\n const elements = insertSiblings(\n previousSibling,\n morphedNode,\n nextSibling,\n );\n if (ctx.config.twoPass) {\n restoreFromPantry(morphedNode.parentNode, ctx);\n }\n return elements;\n }\n } else {\n // otherwise nothing was added to the DOM\n return [];\n }\n } else {\n throw \"Do not understand how to morph style \" + ctx.morphStyle;\n }\n }\n\n /**\n * @param {Node} possibleActiveElement\n * @param {MorphContext} ctx\n * @returns {boolean}\n */\n // TODO: ignoreActive and ignoreActiveValue are marked as optional since they are not\n // initialised in the default config object. As a result the && in the function body may\n // return undefined instead of boolean. Either expand the type of the return value to\n // include undefined or wrap the ctx.ignoreActiveValue into a Boolean()\n function ignoreValueOfActiveElement(possibleActiveElement, ctx) {\n return (\n !!ctx.ignoreActiveValue &&\n possibleActiveElement === document.activeElement &&\n possibleActiveElement !== document.body\n );\n }\n\n /**\n * @param {Node} oldNode root node to merge content into\n * @param {Node | null} newContent new content to merge\n * @param {MorphContext} ctx the merge context\n * @returns {Node | null} the element that ended up in the DOM\n */\n function morphOldNodeTo(oldNode, newContent, ctx) {\n if (ctx.ignoreActive && oldNode === document.activeElement) {\n // don't morph focused element\n } else if (newContent == null) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n\n oldNode.parentNode?.removeChild(oldNode);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return null;\n } else if (!isSoftMatch(oldNode, newContent)) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n if (ctx.callbacks.beforeNodeAdded(newContent) === false) return oldNode;\n\n oldNode.parentNode?.replaceChild(newContent, oldNode);\n ctx.callbacks.afterNodeAdded(newContent);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return newContent;\n } else {\n if (ctx.callbacks.beforeNodeMorphed(oldNode, newContent) === false)\n return oldNode;\n\n if (oldNode instanceof HTMLHeadElement && ctx.head.ignore) {\n // ignore the head element\n } else if (\n oldNode instanceof HTMLHeadElement &&\n ctx.head.style !== \"morph\"\n ) {\n // ok to cast: if newContent wasn't also a , it would've got caught in the `!isSoftMatch` branch above\n handleHeadElement(\n /** @type {HTMLHeadElement} */ (newContent),\n oldNode,\n ctx,\n );\n } else {\n syncNodeFrom(newContent, oldNode, ctx);\n if (!ignoreValueOfActiveElement(oldNode, ctx)) {\n morphChildren(newContent, oldNode, ctx);\n }\n }\n ctx.callbacks.afterNodeMorphed(oldNode, newContent);\n return oldNode;\n }\n return null;\n }\n\n /**\n * This is the core algorithm for matching up children. The idea is to use id sets to try to match up\n * nodes as faithfully as possible. We greedily match, which allows us to keep the algorithm fast, but\n * by using id sets, we are able to better match up with content deeper in the DOM.\n *\n * Basic algorithm is, for each node in the new content:\n *\n * - if we have reached the end of the old parent, append the new content\n * - if the new content has an id set match with the current insertion point, morph\n * - search for an id set match\n * - if id set match found, morph\n * - otherwise search for a \"soft\" match\n * - if a soft match is found, morph\n * - otherwise, prepend the new node before the current insertion point\n *\n * The two search algorithms terminate if competing node matches appear to outweigh what can be achieved\n * with the current node. See findIdSetMatch() and findSoftMatch() for details.\n *\n * @param {Node} newParent the parent element of the new content\n * @param {Node} oldParent the old content that we are merging the new content into\n * @param {MorphContext} ctx the merge context\n * @returns {void}\n */\n function morphChildren(newParent, oldParent, ctx) {\n if (\n newParent instanceof HTMLTemplateElement &&\n oldParent instanceof HTMLTemplateElement\n ) {\n newParent = newParent.content;\n oldParent = oldParent.content;\n }\n\n /**\n *\n * @type {Node | null}\n */\n let nextNewChild = newParent.firstChild;\n /**\n *\n * @type {Node | null}\n */\n let insertionPoint = oldParent.firstChild;\n let newChild;\n\n // run through all the new content\n while (nextNewChild) {\n newChild = nextNewChild;\n nextNewChild = newChild.nextSibling;\n\n // if we are at the end of the exiting parent's children, just append\n if (insertionPoint == null) {\n // skip add callbacks when we're going to be restoring this from the pantry in the second pass\n if (\n ctx.config.twoPass &&\n ctx.persistentIds.has(/** @type {Element} */ (newChild).id)\n ) {\n oldParent.appendChild(newChild);\n } else {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) continue;\n oldParent.appendChild(newChild);\n ctx.callbacks.afterNodeAdded(newChild);\n }\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // if the current node has an id set match then morph\n if (isIdSetMatch(newChild, insertionPoint, ctx)) {\n morphOldNodeTo(insertionPoint, newChild, ctx);\n insertionPoint = insertionPoint.nextSibling;\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // otherwise search forward in the existing old children for an id set match\n let idSetMatch = findIdSetMatch(\n newParent,\n oldParent,\n newChild,\n insertionPoint,\n ctx,\n );\n\n // if we found a potential match, remove the nodes until that point and morph\n if (idSetMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, idSetMatch, ctx);\n morphOldNodeTo(idSetMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // no id set match found, so scan forward for a soft match for the current node\n let softMatch = findSoftMatch(\n newParent,\n oldParent,\n newChild,\n insertionPoint,\n ctx,\n );\n\n // if we found a soft match for the current node, morph\n if (softMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, softMatch, ctx);\n morphOldNodeTo(softMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // abandon all hope of morphing, just insert the new child before the insertion point\n // and move on\n\n // skip add callbacks when we're going to be restoring this from the pantry in the second pass\n if (\n ctx.config.twoPass &&\n ctx.persistentIds.has(/** @type {Element} */ (newChild).id)\n ) {\n oldParent.insertBefore(newChild, insertionPoint);\n } else {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) continue;\n oldParent.insertBefore(newChild, insertionPoint);\n ctx.callbacks.afterNodeAdded(newChild);\n }\n removeIdsFromConsideration(ctx, newChild);\n }\n\n // remove any remaining old nodes that didn't match up with new content\n while (insertionPoint !== null) {\n let tempNode = insertionPoint;\n insertionPoint = insertionPoint.nextSibling;\n removeNode(tempNode, ctx);\n }\n }\n\n //=============================================================================\n // Attribute Syncing Code\n //=============================================================================\n\n /**\n * @param {string} attr the attribute to be mutated\n * @param {Element} to the element that is going to be updated\n * @param {\"update\" | \"remove\"} updateType\n * @param {MorphContext} ctx the merge context\n * @returns {boolean} true if the attribute should be ignored, false otherwise\n */\n function ignoreAttribute(attr, to, updateType, ctx) {\n if (\n attr === \"value\" &&\n ctx.ignoreActiveValue &&\n to === document.activeElement\n ) {\n return true;\n }\n return ctx.callbacks.beforeAttributeUpdated(attr, to, updateType) === false;\n }\n\n /**\n * syncs a given node with another node, copying over all attributes and\n * inner element state from the 'from' node to the 'to' node\n *\n * @param {Node} from the element to copy attributes & state from\n * @param {Node} to the element to copy attributes & state to\n * @param {MorphContext} ctx the merge context\n */\n function syncNodeFrom(from, to, ctx) {\n let type = from.nodeType;\n\n // if is an element type, sync the attributes from the\n // new node into the new node\n if (type === 1 /* element type */) {\n const fromEl = /** @type {Element} */ (from);\n const toEl = /** @type {Element} */ (to);\n const fromAttributes = fromEl.attributes;\n const toAttributes = toEl.attributes;\n for (const fromAttribute of fromAttributes) {\n if (ignoreAttribute(fromAttribute.name, toEl, \"update\", ctx)) {\n continue;\n }\n if (toEl.getAttribute(fromAttribute.name) !== fromAttribute.value) {\n toEl.setAttribute(fromAttribute.name, fromAttribute.value);\n }\n }\n // iterate backwards to avoid skipping over items when a delete occurs\n for (let i = toAttributes.length - 1; 0 <= i; i--) {\n const toAttribute = toAttributes[i];\n\n // toAttributes is a live NamedNodeMap, so iteration+mutation is unsafe\n // e.g. custom element attribute callbacks can remove other attributes\n if (!toAttribute) continue;\n\n if (!fromEl.hasAttribute(toAttribute.name)) {\n if (ignoreAttribute(toAttribute.name, toEl, \"remove\", ctx)) {\n continue;\n }\n toEl.removeAttribute(toAttribute.name);\n }\n }\n }\n\n // sync text nodes\n if (type === 8 /* comment */ || type === 3 /* text */) {\n if (to.nodeValue !== from.nodeValue) {\n to.nodeValue = from.nodeValue;\n }\n }\n\n if (!ignoreValueOfActiveElement(to, ctx)) {\n // sync input values\n syncInputValue(from, to, ctx);\n }\n }\n\n /**\n * @param {Element} from element to sync the value from\n * @param {Element} to element to sync the value to\n * @param {string} attributeName the attribute name\n * @param {MorphContext} ctx the merge context\n */\n function syncBooleanAttribute(from, to, attributeName, ctx) {\n // TODO: prefer set/getAttribute here\n if (!(from instanceof Element && to instanceof Element)) return;\n // @ts-ignore this function is only used on boolean attrs that are reflected as dom properties\n const fromLiveValue = from[attributeName],\n toLiveValue = to[attributeName];\n if (fromLiveValue !== toLiveValue) {\n let ignoreUpdate = ignoreAttribute(attributeName, to, \"update\", ctx);\n if (!ignoreUpdate) {\n // update attribute's associated DOM property\n // @ts-ignore this function is only used on boolean attrs that are reflected as dom properties\n to[attributeName] = from[attributeName];\n }\n if (fromLiveValue) {\n if (!ignoreUpdate) {\n // TODO: do we really want this? tests say so but it feels wrong\n to.setAttribute(attributeName, fromLiveValue);\n }\n } else {\n if (!ignoreAttribute(attributeName, to, \"remove\", ctx)) {\n to.removeAttribute(attributeName);\n }\n }\n }\n }\n\n /**\n * NB: many bothans died to bring us information:\n *\n * https://github.com/patrick-steele-idem/morphdom/blob/master/src/specialElHandlers.js\n * https://github.com/choojs/nanomorph/blob/master/lib/morph.jsL113\n *\n * @param {Node} from the element to sync the input value from\n * @param {Node} to the element to sync the input value to\n * @param {MorphContext} ctx the merge context\n */\n function syncInputValue(from, to, ctx) {\n if (\n from instanceof HTMLInputElement &&\n to instanceof HTMLInputElement &&\n from.type !== \"file\"\n ) {\n let fromValue = from.value;\n let toValue = to.value;\n\n // sync boolean attributes\n syncBooleanAttribute(from, to, \"checked\", ctx);\n syncBooleanAttribute(from, to, \"disabled\", ctx);\n\n if (!from.hasAttribute(\"value\")) {\n if (!ignoreAttribute(\"value\", to, \"remove\", ctx)) {\n to.value = \"\";\n to.removeAttribute(\"value\");\n }\n } else if (fromValue !== toValue) {\n if (!ignoreAttribute(\"value\", to, \"update\", ctx)) {\n to.setAttribute(\"value\", fromValue);\n to.value = fromValue;\n }\n }\n // TODO: QUESTION(1cg): this used to only check `from` unlike the other branches -- why?\n // did I break something?\n } else if (\n from instanceof HTMLOptionElement &&\n to instanceof HTMLOptionElement\n ) {\n syncBooleanAttribute(from, to, \"selected\", ctx);\n } else if (\n from instanceof HTMLTextAreaElement &&\n to instanceof HTMLTextAreaElement\n ) {\n let fromValue = from.value;\n let toValue = to.value;\n if (ignoreAttribute(\"value\", to, \"update\", ctx)) {\n return;\n }\n if (fromValue !== toValue) {\n to.value = fromValue;\n }\n if (to.firstChild && to.firstChild.nodeValue !== fromValue) {\n to.firstChild.nodeValue = fromValue;\n }\n }\n }\n\n /**\n * =============================================================================\n * The HEAD tag can be handled specially, either w/ a 'merge' or 'append' style\n * =============================================================================\n * @param {Element} newHeadTag\n * @param {Element} currentHead\n * @param {MorphContext} ctx\n * @returns {Promise[]}\n */\n function handleHeadElement(newHeadTag, currentHead, ctx) {\n /**\n * @type {Node[]}\n */\n let added = [];\n /**\n * @type {Element[]}\n */\n let removed = [];\n /**\n * @type {Element[]}\n */\n let preserved = [];\n /**\n * @type {Element[]}\n */\n let nodesToAppend = [];\n\n let headMergeStyle = ctx.head.style;\n\n // put all new head elements into a Map, by their outerHTML\n let srcToNewHeadNodes = new Map();\n for (const newHeadChild of newHeadTag.children) {\n srcToNewHeadNodes.set(newHeadChild.outerHTML, newHeadChild);\n }\n\n // for each elt in the current head\n for (const currentHeadElt of currentHead.children) {\n // If the current head element is in the map\n let inNewContent = srcToNewHeadNodes.has(currentHeadElt.outerHTML);\n let isReAppended = ctx.head.shouldReAppend(currentHeadElt);\n let isPreserved = ctx.head.shouldPreserve(currentHeadElt);\n if (inNewContent || isPreserved) {\n if (isReAppended) {\n // remove the current version and let the new version replace it and re-execute\n removed.push(currentHeadElt);\n } else {\n // this element already exists and should not be re-appended, so remove it from\n // the new content map, preserving it in the DOM\n srcToNewHeadNodes.delete(currentHeadElt.outerHTML);\n preserved.push(currentHeadElt);\n }\n } else {\n if (headMergeStyle === \"append\") {\n // we are appending and this existing element is not new content\n // so if and only if it is marked for re-append do we do anything\n if (isReAppended) {\n removed.push(currentHeadElt);\n nodesToAppend.push(currentHeadElt);\n }\n } else {\n // if this is a merge, we remove this content since it is not in the new head\n if (ctx.head.shouldRemove(currentHeadElt) !== false) {\n removed.push(currentHeadElt);\n }\n }\n }\n }\n\n // Push the remaining new head elements in the Map into the\n // nodes to append to the head tag\n nodesToAppend.push(...srcToNewHeadNodes.values());\n log(\"to append: \", nodesToAppend);\n\n let promises = [];\n for (const newNode of nodesToAppend) {\n log(\"adding: \", newNode);\n // TODO: This could theoretically be null, based on type\n let newElt = /** @type {ChildNode} */ (\n document.createRange().createContextualFragment(newNode.outerHTML)\n .firstChild\n );\n log(newElt);\n if (ctx.callbacks.beforeNodeAdded(newElt) !== false) {\n if (\n (\"href\" in newElt && newElt.href) ||\n (\"src\" in newElt && newElt.src)\n ) {\n /** @type {(result?: any) => void} */ let resolve;\n let promise = new Promise(function (_resolve) {\n resolve = _resolve;\n });\n newElt.addEventListener(\"load\", function () {\n resolve();\n });\n promises.push(promise);\n }\n currentHead.appendChild(newElt);\n ctx.callbacks.afterNodeAdded(newElt);\n added.push(newElt);\n }\n }\n\n // remove all removed elements, after we have appended the new elements to avoid\n // additional network requests for things like style sheets\n for (const removedElement of removed) {\n if (ctx.callbacks.beforeNodeRemoved(removedElement) !== false) {\n currentHead.removeChild(removedElement);\n ctx.callbacks.afterNodeRemoved(removedElement);\n }\n }\n\n ctx.head.afterHeadMorphed(currentHead, {\n added: added,\n kept: preserved,\n removed: removed,\n });\n return promises;\n }\n\n //=============================================================================\n // Misc\n //=============================================================================\n\n /**\n * @param {any[]} _args\n */\n function log(..._args) {\n //console.log(args);\n }\n\n function noOp() {}\n\n /**\n * Deep merges the config object and the Idiomoroph.defaults object to\n * produce a final configuration object\n * @param {Config} config\n * @returns {ConfigInternal}\n */\n function mergeDefaults(config) {\n /**\n * @type {ConfigInternal}\n */\n let finalConfig = Object.assign({}, defaults);\n\n // copy top level stuff into final config\n Object.assign(finalConfig, config);\n\n // copy callbacks into final config (do this to deep merge the callbacks)\n finalConfig.callbacks = Object.assign(\n {},\n defaults.callbacks,\n config.callbacks,\n );\n\n // copy head config into final config (do this to deep merge the head)\n finalConfig.head = Object.assign({}, defaults.head, config.head);\n\n return finalConfig;\n }\n\n /**\n *\n * @param {Element} oldNode\n * @param {Element} newContent\n * @param {Config} config\n * @returns {MorphContext}\n */\n function createMorphContext(oldNode, newContent, config) {\n const mergedConfig = mergeDefaults(config);\n return {\n target: oldNode,\n newContent: newContent,\n config: mergedConfig,\n morphStyle: mergedConfig.morphStyle,\n ignoreActive: mergedConfig.ignoreActive,\n ignoreActiveValue: mergedConfig.ignoreActiveValue,\n idMap: createIdMap(oldNode, newContent),\n deadIds: new Set(),\n persistentIds: mergedConfig.twoPass\n ? createPersistentIds(oldNode, newContent)\n : new Set(),\n pantry: mergedConfig.twoPass\n ? createPantry()\n : document.createElement(\"div\"),\n callbacks: mergedConfig.callbacks,\n head: mergedConfig.head,\n };\n }\n\n function createPantry() {\n const pantry = document.createElement(\"div\");\n pantry.hidden = true;\n document.body.insertAdjacentElement(\"afterend\", pantry);\n return pantry;\n }\n\n /**\n *\n * @param {Node | null} node1\n * @param {Node | null} node2\n * @param {MorphContext} ctx\n * @returns {boolean}\n */\n // TODO: The function handles this as if it's Element or null, but the function is called in\n // places where the arguments may be just a Node, not an Element\n function isIdSetMatch(node1, node2, ctx) {\n if (node1 == null || node2 == null) {\n return false;\n }\n if (\n node1 instanceof Element &&\n node2 instanceof Element &&\n node1.tagName === node2.tagName\n ) {\n if (node1.id !== \"\" && node1.id === node2.id) {\n return true;\n } else {\n return getIdIntersectionCount(ctx, node1, node2) > 0;\n }\n }\n return false;\n }\n\n /**\n *\n * @param {Node | null} oldNode\n * @param {Node | null} newNode\n * @returns {boolean}\n */\n function isSoftMatch(oldNode, newNode) {\n if (oldNode == null || newNode == null) {\n return false;\n }\n // ok to cast: if one is not element, `id` or `tagName` will be undefined and we'll compare that\n // If oldNode has an `id` with possible state and it doesn't match newNode.id then avoid morphing\n if (\n /** @type {Element} */ (oldNode).id &&\n /** @type {Element} */ (oldNode).id !==\n /** @type {Element} */ (newNode).id\n ) {\n return false;\n }\n return (\n oldNode.nodeType === newNode.nodeType &&\n /** @type {Element} */ (oldNode).tagName ===\n /** @type {Element} */ (newNode).tagName\n );\n }\n\n /**\n *\n * @param {Node} startInclusive\n * @param {Node} endExclusive\n * @param {MorphContext} ctx\n * @returns {Node | null}\n */\n function removeNodesBetween(startInclusive, endExclusive, ctx) {\n /** @type {Node | null} */ let cursor = startInclusive;\n while (cursor !== endExclusive) {\n let tempNode = /** @type {Node} */ (cursor);\n // TODO: Prefer assigning to a new variable here or expand the type of startInclusive\n // to be Node | null\n cursor = tempNode.nextSibling;\n removeNode(tempNode, ctx);\n }\n removeIdsFromConsideration(ctx, endExclusive);\n return endExclusive.nextSibling;\n }\n\n /**\n * =============================================================================\n * Scans forward from the insertionPoint in the old parent looking for a potential id match\n * for the newChild. We stop if we find a potential id match for the new child OR\n * if the number of potential id matches we are discarding is greater than the\n * potential id matches for the new child\n * =============================================================================\n * @param {Node} newContent\n * @param {Node} oldParent\n * @param {Node} newChild\n * @param {Node} insertionPoint\n * @param {MorphContext} ctx\n * @returns {null | Node}\n */\n function findIdSetMatch(\n newContent,\n oldParent,\n newChild,\n insertionPoint,\n ctx,\n ) {\n // max id matches we are willing to discard in our search\n let newChildPotentialIdCount = getIdIntersectionCount(\n ctx,\n newChild,\n oldParent,\n );\n\n /**\n * @type {Node | null}\n */\n let potentialMatch = null;\n\n // only search forward if there is a possibility of an id match\n if (newChildPotentialIdCount > 0) {\n // TODO: This is ghosting the potentialMatch variable outside of this block.\n // Probably an error\n potentialMatch = insertionPoint;\n // if there is a possibility of an id match, scan forward\n // keep track of the potential id match count we are discarding (the\n // newChildPotentialIdCount must be greater than this to make it likely\n // worth it)\n let otherMatchCount = 0;\n while (potentialMatch != null) {\n // If we have an id match, return the current potential match\n if (isIdSetMatch(newChild, potentialMatch, ctx)) {\n return potentialMatch;\n }\n\n // computer the other potential matches of this new content\n otherMatchCount += getIdIntersectionCount(\n ctx,\n potentialMatch,\n newContent,\n );\n if (otherMatchCount > newChildPotentialIdCount) {\n // if we have more potential id matches in _other_ content, we\n // do not have a good candidate for an id match, so return null\n return null;\n }\n\n // advanced to the next old content child\n potentialMatch = potentialMatch.nextSibling;\n }\n }\n return potentialMatch;\n }\n\n /**\n * =============================================================================\n * Scans forward from the insertionPoint in the old parent looking for a potential soft match\n * for the newChild. We stop if we find a potential soft match for the new child OR\n * if we find a potential id match in the old parents children OR if we find two\n * potential soft matches for the next two pieces of new content\n * =============================================================================\n * @param {Node} newContent\n * @param {Node} oldParent\n * @param {Node} newChild\n * @param {Node} insertionPoint\n * @param {MorphContext} ctx\n * @returns {null | Node}\n */\n function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n /**\n * @type {Node | null}\n */\n let potentialSoftMatch = insertionPoint;\n /**\n * @type {Node | null}\n */\n let nextSibling = newChild.nextSibling;\n let siblingSoftMatchCount = 0;\n\n while (potentialSoftMatch != null) {\n if (getIdIntersectionCount(ctx, potentialSoftMatch, newContent) > 0) {\n // the current potential soft match has a potential id set match with the remaining new\n // content so bail out of looking\n return null;\n }\n\n // if we have a soft match with the current node, return it\n if (isSoftMatch(potentialSoftMatch, newChild)) {\n return potentialSoftMatch;\n }\n\n if (isSoftMatch(potentialSoftMatch, nextSibling)) {\n // the next new node has a soft match with this node, so\n // increment the count of future soft matches\n siblingSoftMatchCount++;\n // ok to cast: if it was null it couldn't be a soft match\n nextSibling = /** @type {Node} */ (nextSibling).nextSibling;\n\n // If there are two future soft matches, bail to allow the siblings to soft match\n // so that we don't consume future soft matches for the sake of the current node\n if (siblingSoftMatchCount >= 2) {\n return null;\n }\n }\n\n // advanced to the next old content child\n potentialSoftMatch = potentialSoftMatch.nextSibling;\n }\n\n return potentialSoftMatch;\n }\n\n /** @type {WeakSet} */\n const generatedByIdiomorph = new WeakSet();\n\n /**\n *\n * @param {string} newContent\n * @returns {Node | null | DocumentFragment}\n */\n function parseContent(newContent) {\n let parser = new DOMParser();\n\n // remove svgs to avoid false-positive matches on head, etc.\n let contentWithSvgsRemoved = newContent.replace(\n /]*>|>)([\\s\\S]*?)<\\/svg>/gim,\n \"\",\n );\n\n // if the newContent contains a html, head or body tag, we can simply parse it w/o wrapping\n if (\n contentWithSvgsRemoved.match(/<\\/html>/) ||\n contentWithSvgsRemoved.match(/<\\/head>/) ||\n contentWithSvgsRemoved.match(/<\\/body>/)\n ) {\n let content = parser.parseFromString(newContent, \"text/html\");\n // if it is a full HTML document, return the document itself as the parent container\n if (contentWithSvgsRemoved.match(/<\\/html>/)) {\n generatedByIdiomorph.add(content);\n return content;\n } else {\n // otherwise return the html element as the parent container\n let htmlElement = content.firstChild;\n if (htmlElement) {\n generatedByIdiomorph.add(htmlElement);\n return htmlElement;\n } else {\n return null;\n }\n }\n } else {\n // if it is partial HTML, wrap it in a template tag to provide a parent element and also to help\n // deal with touchy tags like tr, tbody, etc.\n let responseDoc = parser.parseFromString(\n \"\",\n \"text/html\",\n );\n let content = /** @type {HTMLTemplateElement} */ (\n responseDoc.body.querySelector(\"template\")\n ).content;\n generatedByIdiomorph.add(content);\n return content;\n }\n }\n\n /**\n *\n * @param {null | Node | HTMLCollection | Node[] | Document & {generatedByIdiomorph:boolean}} newContent\n * @returns {Element}\n */\n function normalizeContent(newContent) {\n if (newContent == null) {\n // noinspection UnnecessaryLocalVariableJS\n const dummyParent = document.createElement(\"div\");\n return dummyParent;\n } else if (generatedByIdiomorph.has(/** @type {Element} */ (newContent))) {\n // the template tag created by idiomorph parsing can serve as a dummy parent\n return /** @type {Element} */ (newContent);\n } else if (newContent instanceof Node) {\n // a single node is added as a child to a dummy parent\n const dummyParent = document.createElement(\"div\");\n dummyParent.append(newContent);\n return dummyParent;\n } else {\n // all nodes in the array or HTMLElement collection are consolidated under\n // a single dummy parent element\n const dummyParent = document.createElement(\"div\");\n for (const elt of [...newContent]) {\n dummyParent.append(elt);\n }\n return dummyParent;\n }\n }\n\n /**\n *\n * @param {Node | null} previousSibling\n * @param {Node} morphedNode\n * @param {Node | null} nextSibling\n * @returns {Node[]}\n */\n function insertSiblings(previousSibling, morphedNode, nextSibling) {\n /**\n * @type {Node[]}\n */\n let stack = [];\n /**\n * @type {Node[]}\n */\n let added = [];\n while (previousSibling != null) {\n stack.push(previousSibling);\n previousSibling = previousSibling.previousSibling;\n }\n // Base the loop on the node variable, so that you do not need runtime checks for\n // undefined value inside the loop\n let node = stack.pop();\n while (node !== undefined) {\n added.push(node); // push added preceding siblings on in order and insert\n morphedNode.parentElement?.insertBefore(node, morphedNode);\n node = stack.pop();\n }\n added.push(morphedNode);\n while (nextSibling != null) {\n stack.push(nextSibling);\n added.push(nextSibling); // here we are going in order, so push on as we scan, rather than add\n nextSibling = nextSibling.nextSibling;\n }\n while (stack.length > 0) {\n const node = /** @type {Node} */ (stack.pop());\n morphedNode.parentElement?.insertBefore(node, morphedNode.nextSibling);\n }\n return added;\n }\n\n /**\n *\n * @param {Element} newContent\n * @param {Element} oldNode\n * @param {MorphContext} ctx\n * @returns {Node | null}\n */\n function findBestNodeMatch(newContent, oldNode, ctx) {\n /**\n * @type {Node | null}\n */\n let currentElement;\n currentElement = newContent.firstChild;\n /**\n * @type {Node | null}\n */\n let bestElement = currentElement;\n let score = 0;\n while (currentElement) {\n let newScore = scoreElement(currentElement, oldNode, ctx);\n if (newScore > score) {\n bestElement = currentElement;\n score = newScore;\n }\n currentElement = currentElement.nextSibling;\n }\n return bestElement;\n }\n\n /**\n *\n * @param {Node | null} node1\n * @param {Element} node2\n * @param {MorphContext} ctx\n * @returns {number}\n */\n // TODO: The function handles node1 and node2 as if they are Elements but the function is\n // called in places where node1 and node2 may be just Nodes, not Elements\n function scoreElement(node1, node2, ctx) {\n if (isSoftMatch(node2, node1)) {\n // ok to cast: isSoftMatch performs a null check\n return (\n 0.5 + getIdIntersectionCount(ctx, /** @type {Node} */ (node1), node2)\n );\n }\n return 0;\n }\n\n /**\n *\n * @param {Node} tempNode\n * @param {MorphContext} ctx\n */\n // TODO: The function handles tempNode as if it's Element but the function is called in\n // places where tempNode may be just a Node, not an Element\n function removeNode(tempNode, ctx) {\n removeIdsFromConsideration(ctx, tempNode);\n // skip remove callbacks when we're going to be restoring this from the pantry in the second pass\n if (\n ctx.config.twoPass &&\n hasPersistentIdNodes(ctx, tempNode) &&\n tempNode instanceof Element\n ) {\n moveToPantry(tempNode, ctx);\n } else {\n if (ctx.callbacks.beforeNodeRemoved(tempNode) === false) return;\n tempNode.parentNode?.removeChild(tempNode);\n ctx.callbacks.afterNodeRemoved(tempNode);\n }\n }\n\n /**\n *\n * @param {Node} node\n * @param {MorphContext} ctx\n */\n function moveToPantry(node, ctx) {\n if (ctx.callbacks.beforeNodePantried(node) === false) return;\n\n Array.from(node.childNodes).forEach((child) => {\n moveToPantry(child, ctx);\n });\n\n // After processing children, process the current node\n if (ctx.persistentIds.has(/** @type {Element} */ (node).id)) {\n // @ts-ignore - use proposed moveBefore feature\n if (ctx.pantry.moveBefore) {\n // @ts-ignore - use proposed moveBefore feature\n ctx.pantry.moveBefore(node, null);\n } else {\n ctx.pantry.insertBefore(node, null);\n }\n } else {\n if (ctx.callbacks.beforeNodeRemoved(node) === false) return;\n node.parentNode?.removeChild(node);\n ctx.callbacks.afterNodeRemoved(node);\n }\n }\n\n /**\n *\n * @param {Node | null} root\n * @param {MorphContext} ctx\n */\n function restoreFromPantry(root, ctx) {\n if (root instanceof Element) {\n Array.from(ctx.pantry.children)\n .reverse()\n .forEach((element) => {\n const matchElement = root.querySelector(`#${element.id}`);\n if (matchElement) {\n // @ts-ignore - use proposed moveBefore feature\n if (matchElement.parentElement?.moveBefore) {\n // @ts-ignore - use proposed moveBefore feature\n matchElement.parentElement.moveBefore(element, matchElement);\n while (matchElement.hasChildNodes()) {\n // @ts-ignore - use proposed moveBefore feature\n element.moveBefore(matchElement.firstChild, null);\n }\n } else {\n matchElement.before(element);\n while (matchElement.firstChild) {\n element.insertBefore(matchElement.firstChild, null);\n }\n }\n if (\n ctx.callbacks.beforeNodeMorphed(element, matchElement) !== false\n ) {\n syncNodeFrom(matchElement, element, ctx);\n ctx.callbacks.afterNodeMorphed(element, matchElement);\n }\n matchElement.remove();\n }\n });\n ctx.pantry.remove();\n }\n }\n\n //=============================================================================\n // ID Set Functions\n //=============================================================================\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {string} id\n * @returns {boolean}\n */\n function isIdInConsideration(ctx, id) {\n return !ctx.deadIds.has(id);\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {string} id\n * @param {Node} targetNode\n * @returns {boolean}\n */\n function idIsWithinNode(ctx, id, targetNode) {\n let idSet = ctx.idMap.get(targetNode) || EMPTY_SET;\n return idSet.has(id);\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {Node} node\n * @returns {void}\n */\n function removeIdsFromConsideration(ctx, node) {\n let idSet = ctx.idMap.get(node) || EMPTY_SET;\n for (const id of idSet) {\n ctx.deadIds.add(id);\n }\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {Node} node\n * @returns {boolean}\n */\n function hasPersistentIdNodes(ctx, node) {\n for (const id of ctx.idMap.get(node) || EMPTY_SET) {\n if (ctx.persistentIds.has(id)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n *\n * @param {MorphContext} ctx\n * @param {Node} node1\n * @param {Node} node2\n * @returns {number}\n */\n function getIdIntersectionCount(ctx, node1, node2) {\n let sourceSet = ctx.idMap.get(node1) || EMPTY_SET;\n let matchCount = 0;\n for (const id of sourceSet) {\n // a potential match is an id in the source and potentialIdsSet, but\n // that has not already been merged into the DOM\n if (isIdInConsideration(ctx, id) && idIsWithinNode(ctx, id, node2)) {\n ++matchCount;\n }\n }\n return matchCount;\n }\n\n /**\n * @param {Element} content\n * @returns {Element[]}\n */\n function nodesWithIds(content) {\n let nodes = Array.from(content.querySelectorAll(\"[id]\"));\n if (content.id) {\n nodes.push(content);\n }\n return nodes;\n }\n\n /**\n * A bottom up algorithm that finds all elements with ids in the node\n * argument and populates id sets for those nodes and all their parents, generating\n * a set of ids contained within all nodes for the entire hierarchy in the DOM\n *\n * @param {Element} node\n * @param {Map>} idMap\n */\n function populateIdMapForNode(node, idMap) {\n let nodeParent = node.parentElement;\n for (const elt of nodesWithIds(node)) {\n /**\n * @type {Element|null}\n */\n let current = elt;\n // walk up the parent hierarchy of that element, adding the id\n // of element to the parent's id set\n while (current !== nodeParent && current != null) {\n let idSet = idMap.get(current);\n // if the id set doesn't exist, create it and insert it in the map\n if (idSet == null) {\n idSet = new Set();\n idMap.set(current, idSet);\n }\n idSet.add(elt.id);\n current = current.parentElement;\n }\n }\n }\n\n /**\n * This function computes a map of nodes to all ids contained within that node (inclusive of the\n * node). This map can be used to ask if two nodes have intersecting sets of ids, which allows\n * for a looser definition of \"matching\" than tradition id matching, and allows child nodes\n * to contribute to a parent nodes matching.\n *\n * @param {Element} oldContent the old content that will be morphed\n * @param {Element} newContent the new content to morph to\n * @returns {Map>} a map of nodes to id sets for the\n */\n function createIdMap(oldContent, newContent) {\n /**\n *\n * @type {Map>}\n */\n let idMap = new Map();\n populateIdMapForNode(oldContent, idMap);\n populateIdMapForNode(newContent, idMap);\n return idMap;\n }\n\n /**\n * @param {Element} oldContent the old content that will be morphed\n * @param {Element} newContent the new content to morph to\n * @returns {Set} the id set of all persistent nodes that exist in both old and new content\n */\n function createPersistentIds(oldContent, newContent) {\n const toIdTagName = (node) => node.tagName + \"#\" + node.id;\n const oldIdSet = new Set(nodesWithIds(oldContent).map(toIdTagName));\n\n let matchIdSet = new Set();\n for (const newNode of nodesWithIds(newContent)) {\n if (oldIdSet.has(toIdTagName(newNode))) {\n matchIdSet.add(newNode.id);\n }\n }\n return matchIdSet;\n }\n\n //=============================================================================\n // This is what ends up becoming the Idiomorph global object\n //=============================================================================\n return {\n morph,\n defaults,\n };\n})();\n\nexport {Idiomorph};\n","const customEvent = (() => {\n\treturn ('CustomEvent' in window && typeof window.CustomEvent === 'function')\n\t\t? (name, data) => new CustomEvent(name, data)\n\t\t: (name, data) => {\n\t\t\tconst newEvent = document.createEvent('CustomEvent')\n\t\t\tnewEvent.initCustomEvent(name, true, true, data)\n\t\t\treturn newEvent\n\t\t}\n})()\n\nconst handler = (node, ev) => {\n\treturn function (e) {\n\t\tconst scope = this\n\t\tconst detail = e.detail || {}\n\t\tnode.__events[ev].forEach(o => {\n\t\t\to.handler.apply(scope, [e].concat(detail.args))\n\t\t})\n\t}\n}\n\nconst removeListener = (node, ev) => {\n\tif (node.__events[ev] && node.__events[ev].listener) {\n\t\tnode.removeEventListener(\n\t\t\tev,\n\t\t\tnode.__events[ev].listener,\n\t\t\t(ev == 'focus' || ev == 'blur' || ev == 'mouseenter' || ev == 'mouseleave'))\n\t\tdelete node.__events[ev]\n\t}\n}\n\nconst delegate = (node, selector, callback) => {\n\treturn function (e) {\n\n\t\tconst element = this\n\t\tconst detail = e.detail || {}\n\n\t\tlet parent = e.target\n\n\t\twhile (parent) {\n\t\t\tif (parent.matches(selector)) {\n\t\t\t\te.delegateTarget = parent\n\t\t\t\tcallback.apply(element, [e].concat(detail.args))\n\t\t\t}\n\t\t\tif (parent === node) break\n\t\t\tparent = parent.parentNode\n\t\t}\n\t}\n}\n\nexport const on = (node, ev, selectorOrCallback, callback) => {\n\n\tnode.__events = node.__events || {}\n\tnode.__events[ev] = (node.__events[ev] || [])\n\n\tif (!node.__events[ev].length) {\n\t\tconst fn = handler(node, ev)\n\t\tnode.addEventListener(\n\t\t\tev,\n\t\t\tfn,\n\t\t\t(ev == 'focus' || ev == 'blur' || ev == 'mouseenter' || ev == 'mouseleave'))\n\t\tnode.__events[ev].listener = fn\n\t}\n\n\tif (selectorOrCallback.call) {\n\t\tnode.__events[ev].push({ handler: selectorOrCallback, callback: selectorOrCallback })\n\t} else {\n\t\tnode.__events[ev].push({ handler: delegate(node, selectorOrCallback, callback), callback })\n\t}\n}\n\nexport const off = (node, ev, fn) => {\n\n\tif (fn && node.__events[ev] && node.__events[ev].length) {\n\t\tvar old = node.__events[ev]\n\t\tnode.__events[ev] = node.__events[ev].filter(function (o) { return o.callback != fn; })\n\t\tnode.__events[ev].listener = old.listener\n\t\tif (!node.__events[ev].length)\n\t\t\tremoveListener(node, ev)\n\t} else {\n\t\tremoveListener(node, ev)\n\t}\n}\n\nexport const trigger = (node, name, args) => {\n\tnode.dispatchEvent(customEvent(name, { bubbles: true, detail: args }))\n}\n","import { type Component } from '..'\nimport { Idiomorph } from 'idiomorph/dist/idiomorph.esm'\nimport { rAF, dup, safe } from './utils'\nimport { buildtemplates } from './template-system'\nimport { on, off, trigger } from './utils/events'\nimport { publish, subscribe } from './utils/pubsub'\n\nexport default function Component( elm, { module, dependencies, templates, components }) {\n\n\tconst options = getOptions( module )\n\tconst initialState = (new Function( `return ${elm.getAttribute('html-model') || '{}'}`))()\n\tconst selector = Object.keys(components).toString()\n\n\tbuildtemplates( elm, selector, templates, components )\n\n\tconst tplid = elm.getAttribute('tplid')\n\tconst template = tplid ? templates[tplid] : null\n\tconst state = { data: module.model ? dup(module.model) : {} }\n\tstate.data = Object.assign( state.data, initialState)\n\n\tconst base: Component = {\n\t\ttemplate,\n\t\telm,\n\t\tdependencies,\n\t\tpublish,\n\t\tsubscribe,\n\n\t\tmain(fn) {\n\t\t\toptions.main = fn\n\t\t},\n\n\t\tunmount(fn) {\n\t\t\toptions.unmount = fn\n\t\t},\n\n\t\tonupdate(fn) {\n\t\t\toptions.onupdate = fn\n\t\t},\n\n\t\ton(eventName, selectorOrCallback, callback) {\n\t\t\ton(elm, eventName, selectorOrCallback, callback)\n\t\t},\n\n\t\toff(eventName, callback) {\n\t\t\toff(elm, eventName, callback)\n\t\t},\n\n\t\ttrigger(eventName, target, args) {\n\t\t\tif (target.constructor === String) {\n\t\t\t\tArray\n\t\t\t\t\t.from(elm.querySelectorAll(target))\n\t\t\t\t\t.forEach( children => trigger(children, eventName, { args: args }) )\n\t\t\t}\n\t\t\telse trigger(elm, eventName, { args: target })\n\t\t},\n\n\t\temit: ( ...args ) => {\n\t\t\ttrigger(elm, args.shift(), { args: args })\n\t\t},\n\n\t\tstate: {\n\t\t\tset( data ) {\n\t\t\t\tif (data.constructor === Function) {\n\t\t\t\t\tconst newstate = dup(state.data)\n\t\t\t\t\tdata(newstate)\n\t\t\t\t\tbase.render(newstate)\n\t\t\t\t} else {\n\t\t\t\t\tbase.render(data)\n\t\t\t\t}\n\t\t\t\treturn new Promise((resolve) => rAF(_ => rAF(() => resolve(state.data))))\n\t\t\t},\n\t\t\tget() {\n\t\t\t\treturn dup(state.data)\n\t\t\t},\n\n\t\t\tgetRaw(){\n\t\t\t\treturn state.data\n\t\t\t}\n\t\t},\n\n\t\trender(data = state.data) {\n\n\t\t\tif (!document.body.contains(elm)) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tstate.data = Object.assign(state.data, data)\n\n\t\t\tconst newdata = dup(state.data)\n\t\t\tconst newhtml = templates[tplid].call(Object.assign(options.view(newdata), elm.___scope___), elm, safe)\n\n\t\t\tIdiomorph.morph(elm, newhtml, IdiomorphOptions(elm))\n\t\t\tupdateScope( elm )\n\n\t\t\trAF(_ => {\n\t\t\t\tArray\n\t\t\t\t\t.from(elm.querySelectorAll('[tplid]'))\n\t\t\t\t\t.forEach((child: any) => {\n\t\t\t\t\t\tconst props = Object.assign( child.base.state.getRaw(), data )\n\t\t\t\t\t\tchild.options.onupdate(props)\n\t\t\t\t\t\tchild.base.render(props)\n\t\t\t\t\t})\n\t\t\t})\n\t\t},\n\n\t\tinnerHTML( target, html_ ) {\n\n\t\t\tconst element = html_? target : elm\n\t\t\tconst clone = element.cloneNode()\n\t\t\tconst html = html_? html_ : target\n\t\t\tclone.innerHTML = html\n\n\t\t\trAF( _ => Idiomorph.morph(element, clone, IdiomorphOptions) )\n\t\t}\n\t}\n\n\treturn { base, options }\n}\n\nconst getOptions = (module) => ({\n\tmain: (a) => a,\n\tunmount: (a) => a,\n\tonupdate: (a) => a,\n\tview: module.view ? module.view : (a) => a\n})\n\nconst updateScope = (node) => {\n\tnode.querySelectorAll('[scope]').forEach( scopeElement => {\n\t\tscopeElement.querySelectorAll('[tplid]').forEach( cp => {\n\t\t\tif( !cp.___scope___ ) {\n\t\t\t\tconst script = scopeElement.lastElementChild\n\t\t\t\tcp.___scope___ = 'scope' in script.dataset? (new Function(`return ${script.text}`))() : {}\n\t\t\t}\n\t\t})\n\t})\n}\n\n\nconst IdiomorphOptions = (parent) => ({\n\n\tcallbacks: {\n\n\t\tbeforeNodeMorphed( node ) {\n\t\t\tif( node.nodeType === 1 ) {\n\t\t\t\tif( 'html-static' in node.attributes ) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t\tif( node.base && node !== parent ) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n})\n","import Component from './component'\nimport { purge, rAF } from './utils'\n\nexport default function Element(module, dependencies, templates, components) {\n\n\treturn class extends HTMLElement {\n\n\t\tbase: any\n\t\toptions: any\n\t\treturns : any\n\t\t__events: any\n\n\t\tconstructor() {\n\t\t\tsuper()\n\t\t}\n\n\t\tconnectedCallback() {\n\n\t\t\tconst { base, options } = Component(this, { module, dependencies, templates, components })\n\n\t\t\tthis.base = base\n\t\t\tthis.options = options\n\t\t\tthis.base.render()\n\t\t\tthis.returns = module.default(base)\n\n\t\t\tif( this.__template && this.__template.constructor === Promise ) {\n\t\t\t\tthis.__template.then( _ => {\n\t\t\t\t\tif( this.base && this.options.main) {\n\t\t\t\t\t\tconst array = this.options.main(this.base)\n\t\t\t\t\t\tif( array && array.length ){\n\t\t\t\t\t\t\tarray.forEach(f => f(this.base))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif( this.returns && this.returns.constructor === Promise ) {\n\t\t\t\tthis.returns.then( _ => {\n\t\t\t\t\tif( this.base && this.options.main) {\n\t\t\t\t\t\tconst array = this.options.main(this.base)\n\t\t\t\t\t\tif( array && array.length ){\n\t\t\t\t\t\t\tarray.forEach(f => f(this.base))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\n\t\t\t} else {\n\t\t\t\tif( this.base && this.options.main ){\n\t\t\t\t\tconst array = this.options.main(this.base)\n\t\t\t\t\tif( array && array.length ) {\n\t\t\t\t\t\tarray.forEach(f => f(this.base))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdisconnectedCallback() {\n\t\t\tthis.options.unmount(this.base)\n\t\t\trAF(() => {\n\t\t\t\tif(!document.body.contains(this) ) {\n\t\t\t\t\tthis.__events? this.__events = null : null\n\t\t\t\t\tthis.base? this.base.elm = null : null\n\t\t\t\t\tthis.base? this.base = null : null\n\t\t\t\t\tpurge(this)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tattributeChangedCallback() {\n\t\t\t//TODO\n\t\t}\n\t}\n}\n","import { templateConfig, buildtemplates } from './template-system'\nimport { publish, subscribe } from './utils/pubsub'\nimport { html, attributes } from '../html'\nimport Element from './element'\n\nconst templates = {}\nconst components = {}\n\nexport { html, attributes }\n\nexport default {\n\n\ttemplateConfig,\n\n\tpublish,\n\tsubscribe,\n\n\tregister( name, module, dependencies = {} ) {\n\t\tcomponents[name] = { name, module, dependencies }\n\t},\n\n\tstart( target = document.body ) {\n\t\tconst keys = Object.keys(components)\n\t\tconst selector = keys.toString()\n\t\tif( keys.length ) {\n\t\t\tbuildtemplates( target, selector, templates, components )\n\t\t\tregisterComponents()\n\t\t}\n\t}\n}\n\nconst registerComponents = () => {\n\tObject\n\t\t.values( components )\n\t\t.forEach( (component) => {\n\t\t\tconst { name, module, dependencies } = component as any\n\t\t\tif( !customElements.get(name) ){\n\t\t\t\tconst Base = Element(module, dependencies, templates, components)\n\t\t\t\tcustomElements.define(name, Base)\n\t\t\t}\n\t\t})\n}\n","\nexport const attributes = ( attrs ) => {\n\tconst result = Object.entries(attrs)\n\t\t.map(([key, value]) => {\n\t\t\tif( value === '' ) {\n\t\t\t\treturn key\n\t\t\t}\n\t\t\treturn `${key}=\"${value}\"`\n\t\t})\n\t\t.join(' ')\n\treturn result\n}\n\n// From\n// https://2ality.com/2015/01/template-strings-html.html#comment-2078932192\nexport const html = (literalSections, ...substs) => {\n\n\t// Use raw literal sections: we don’t want\n\t// backslashes (\\n etc.) to be interpreted\n\tlet raw = literalSections.raw\n\n\tlet result = ''\n\n\tsubsts.forEach((subst, i) => {\n\t\t// Retrieve the literal section preceding\n\t\t// the current substitution\n\t\tlet lit = raw[i]\n\n\t\t// In the example, map() returns an array:\n\t\t// If substitution is an array (and not a string),\n\t\t// we turn it into a string\n\t\tif (Array.isArray(subst)) {\n\t\t\tsubst = subst.join('')\n\t\t}\n\n\t\tresult += lit\n\t\tresult += subst\n\t})\n\t// Take care of last literal section\n\t// (Never fails, because an empty template string\n\t// produces one literal section, an empty string)\n\tresult += raw[raw.length-1] // (A)\n\n\treturn result\n}\n"],"names":["parser","DOMParser","wrap","open","node","close","_a","parentNode","insertBefore","_b","nextSibling","textarea","document","createElement","decodeHTML","text","innerHTML","value","rAF","fn","requestAnimationFrame","setTimeout","dup","o","JSON","parse","stringify","purge","d","i","l","n","a","attributes","length","name","childNodes","safe","execute","val","err","config","tags","Template","element","fixDIffIf","html","regexTags","RegExp","virtual","parseFromString","replace","querySelectorAll","forEach","htmlForeach","getAttribute","htmlFor","htmlIf","htmlInner","htmlClass","forEachInstruction","selector","split","match","varname","object","removeAttribute","setAttribute","script","dataset","scope","type","appendChild","createTextNode","className","trim","body","all","key","Transpile","outerHTML","decodedHTML","Function","_","variable","buildtemplates","target","templates","components","concat","matches","Array","from","reverse","template","content","createTemplateId","id","c","r","Math","random","toString","localName","module","children","constructor","Promise","__template","then","htmlstring","el","createComment","topics","_async","publish","params","Object","assign","topic","subscribe","method","push","filter","Idiomorph","EMPTY_SET","Set","defaults","morphStyle","callbacks","beforeNodeAdded","noOp","afterNodeAdded","beforeNodeMorphed","afterNodeMorphed","beforeNodeRemoved","afterNodeRemoved","beforeAttributeUpdated","beforeNodePantried","head","style","shouldPreserve","elt","shouldReAppend","shouldRemove","afterHeadMorphed","morphNormalizedContent","oldNode","normalizedNewContent","ctx","block","oldHead","querySelector","newHead","promises","handleHeadElement","ignore","morphChildren","twoPass","restoreFromPantry","bestMatch","newContent","currentElement","firstChild","bestElement","score","newScore","scoreElement","findBestNodeMatch","previousSibling","morphedNode","morphOldNodeTo","elements","stack","added","pop","parentElement","insertSiblings","ignoreValueOfActiveElement","possibleActiveElement","ignoreActiveValue","activeElement","ignoreActive","removeChild","isSoftMatch","HTMLHeadElement","syncNodeFrom","replaceChild","newParent","oldParent","HTMLTemplateElement","newChild","nextNewChild","insertionPoint","persistentIds","has","removeIdsFromConsideration","isIdSetMatch","idSetMatch","findIdSetMatch","removeNodesBetween","softMatch","findSoftMatch","tempNode","removeNode","ignoreAttribute","attr","to","updateType","nodeType","fromEl","toEl","fromAttributes","toAttributes","fromAttribute","toAttribute","hasAttribute","nodeValue","HTMLInputElement","fromValue","toValue","syncBooleanAttribute","HTMLOptionElement","HTMLTextAreaElement","syncInputValue","attributeName","Element","fromLiveValue","ignoreUpdate","newHeadTag","currentHead","removed","preserved","nodesToAppend","headMergeStyle","srcToNewHeadNodes","Map","newHeadChild","set","currentHeadElt","inNewContent","isReAppended","isPreserved","delete","values","newNode","newElt","createRange","createContextualFragment","href","src","resolve","promise","_resolve","addEventListener","removedElement","kept","createPantry","pantry","hidden","insertAdjacentElement","node1","node2","tagName","getIdIntersectionCount","startInclusive","endExclusive","cursor","newChildPotentialIdCount","potentialMatch","otherMatchCount","potentialSoftMatch","siblingSoftMatchCount","generatedByIdiomorph","WeakSet","idMap","get","hasPersistentIdNodes","moveToPantry","child","moveBefore","root","matchElement","hasChildNodes","before","remove","isIdInConsideration","deadIds","idIsWithinNode","targetNode","idSet","add","sourceSet","matchCount","nodesWithIds","nodes","populateIdMapForNode","nodeParent","current","createIdMap","oldContent","createPersistentIds","toIdTagName","oldIdSet","map","matchIdSet","morph","Document","documentElement","contentWithSvgsRemoved","htmlElement","parseContent","normalizedContent","Node","dummyParent","append","normalizeContent","mergedConfig","finalConfig","mergeDefaults","createMorphContext","customEvent","window","CustomEvent","data","newEvent","createEvent","initCustomEvent","handler","ev","e","this","detail","__events","apply","args","removeListener","listener","removeEventListener","delegate","callback","parent","delegateTarget","on","selectorOrCallback","call","off","old","trigger","dispatchEvent","bubbles","getOptions","main","unmount","onupdate","view","updateScope","scopeElement","cp","___scope___","lastElementChild","IdiomorphOptions","base","dependencies","HTMLElement","connectedCallback","options","elm","initialState","keys","tplid","state","model","eventName","String","emit","shift","newstate","render","getRaw","contains","newdata","newhtml","props","html_","clone","cloneNode","Component","returns","default","array","f","disconnectedCallback","attributeChangedCallback","index","templateConfig","newconfig","register","start","registerComponents","component","customElements","Base","define","attrs","entries","join","literalSections","substs","raw","result","subst","lit","isArray"],"mappings":"6OAEM,MAAAA,EAAS,IAAIC,UAyEnB,MAAMC,EAAO,CAACC,EAAMC,EAAMC,aACpB,OAAAC,EAAAF,EAAAG,aAAYD,EAAAE,aAAaL,EAAMC,GACpC,OAAAK,EAAAL,EAAKG,aAALE,EAAiBD,aAAaH,EAAOD,EAAKM,YAAA,EC7ErCC,EAAWC,SAASC,cAAc,YAE3BC,EAAcC,IAC1BJ,EAASK,UAAYD,EACdJ,EAASM,OAGJC,EAAOC,GACfC,sBACIA,sBAAsBD,GAEtBE,WAAWF,EAAI,IAAO,IAUlBG,EAAOC,GACZC,KAAKC,MAAMD,KAAKE,UAAUH,IAIrBI,EAASC,IACrB,IAAsBC,EAAGC,EAAGC,EAAxBC,EAAIJ,EAAEK,WACV,GAAID,EACH,IAAKH,EAAIG,EAAEE,OAAS,EAAGL,GAAK,EAAGA,GAAK,EAEf,mBAATD,EADPG,EAAAC,EAAEH,GAAGM,QAERP,EAAEG,GAAK,MAKV,GADAC,EAAIJ,EAAEQ,WAGL,IADAN,EAAIE,EAAEE,OACDL,EAAI,EAAGA,EAAIC,EAAGD,GAAK,EACjBF,EAAAC,EAAEQ,WAAWP,GAErB,EAGYQ,EAAO,CAACC,EAASC,KAC1B,IAAC,OAAOD,UAAgBE,GAAK,OAAOD,GAAO,EAAE,GC3C3CE,EAA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q,WAClB2Q,EAAK/U,SACQmD,EAAAC,EAAQzB,EAAU0B,EAAWC,OAG/C,GAGKuT,EAAqB,KAC1B1R,OACE+H,OAAQ5J,GACRnC,SAAU2V,IACV,MAAM7W,KAAEA,EAAMqE,OAAAA,EAAAA,aAAQmQ,GAAiBqC,EACvC,IAAKC,eAAe7H,IAAIjP,GAAO,CAC9B,MAAM+W,EAAOhL,EAAQ1H,EAAQmQ,EAAcpR,EAAWC,GACvCyT,eAAAE,OAAOhX,EAAM+W,EAC7B,IACA,eCvCyBE,GACZ/R,OAAOgS,QAAQD,GAC5BpG,KAAI,EAAElO,EAAK7D,KACG,KAAVA,EACI6D,EAED,GAAGA,MAAQ7D,OAElBqY,KAAK,wBAMY,CAACC,KAAoBC,KAIxC,IAAIC,EAAMF,EAAgBE,IAEtBC,EAAS,GAsBN,OApBAF,EAAAnW,SAAQ,CAACsW,EAAO9X,KAGlB,IAAA+X,EAAMH,EAAI5X,GAKV8D,MAAMkU,QAAQF,KACTA,EAAAA,EAAML,KAAK,KAGVI,GAAAE,EACAF,GAAAC,CAAA,IAKDD,GAAAD,EAAIA,EAAIvX,OAAO,GAElBwX,CAAA","x_google_ignoreList":[4]} \ No newline at end of file diff --git a/package.json b/package.json index 2ada5e3..18aa0cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jails-js", - "version": "5.9.0", + "version": "5.8.7", "description": "Jails - Elegant and Minimalistic Javascript Application Library", "module": "./dist/jails.js", "main": "./dist/jails.js", diff --git a/src/template-system.ts b/src/template-system.ts index 67af31f..314e9a2 100644 --- a/src/template-system.ts +++ b/src/template-system.ts @@ -2,7 +2,7 @@ import Transpile from './transpile' import { uuid, decodeHTML } from './utils' const config = { - tags: ['{{', '}}'] + tags: ['${', '}'] } export const templateConfig = (newconfig) => { @@ -71,6 +71,6 @@ const createTemplateId = (element, templates, components ) => { const fixDIffIf = (node) => { const _if = node.querySelectorAll('[html-if]') _if.forEach( el => { - el.parentNode.insertBefore(document.createComment('[html-if]'), el.nextSibling) + el.parentNode.insertBefore(document.createComment(''), el.nextSibling) }) }