jails-js 5.2.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/index.d.ts +8 -2
- package/package.json +1 -1
- package/readme.md +3 -7
- package/src/component.ts +2 -2
- package/src/element.ts +11 -3
- package/src/index.ts +5 -1
- package/src/template-system.ts +12 -15
- package/src/transpile.ts +1 -0
- package/src/utils/index.ts +40 -0
- package/index.html +0 -15
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).jails=t()}(this,(function(){"use strict";const e=new DOMParser;const t=(e,t,n)=>{var r,i;null==(r=t.parentNode)||r.insertBefore(e,t),null==(i=t.parentNode)||i.insertBefore(n,t.nextSibling)},n=e=>requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,1e3/60),r=e=>JSON.parse(JSON.stringify(e)),i=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<n;t+=1)i(e.childNodes[t])},o=(e,t)=>{try{return e()}catch(n){return t||""}},a=document.createElement("textarea"),s={tags:["${","}"]};function l(n,r){const i=function(n,r,i){const o=new RegExp(`\\${r.tags[0]}(.+?)\\${r.tags[1]}`,"g"),a=e.parseFromString(n.replace(/<\/?template[^>]*>/g,""),"text/html");return a.querySelectorAll("[html-for], [html-if], [html-inner], [html-class], [html-model]").forEach((e=>{const n=e.getAttribute("html-foreach"),r=e.getAttribute("html-for"),o=e.getAttribute("html-if"),a=e.getAttribute("html-inner"),s=e.getAttribute("html-class"),l=r||n;if(l){const n=r?"html-for":"html-foreach",o=l.match(/(.*)\sin\s(.*)/)||"",a=o[1],s=o[2];e.removeAttribute(n);const d=Array.from(e.querySelectorAll(`[tplid]:not([${n}] [tplid])`)).map((e=>{const t=e.getAttribute("tplid");return i[t]=[],t})),u=document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${s} }) ){ var ${a} = ${s}[$key]; ${JSON.stringify(d).replace(/\"/g,"'")}.map(function(id){ if($scopes[id]) { $scopes[id][$index] = { ${a}: ${s}[$key], $index: $index, $key: $key } } }); _%%`),c=document.createTextNode("%%_ $index++}})() _%%");t(u,e,c)}if(o){e.removeAttribute("html-if");const n=document.createTextNode(`%%_ if ( safe(function(){ return ${o} }) ){ _%%`),r=document.createTextNode("%%_ } _%%");t(n,e,r)}a&&(e.removeAttribute("html-inner"),e.innerHTML=`%%_=${a}_%%`),s&&(e.removeAttribute("html-class"),e.className=(e.className+` %%_=${s}_%%`).trim())})),a.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))}(n.outerHTML,s,r);a.innerHTML=i;const o=JSON.stringify(a.value);return new Function("$element","safe","$scopes",`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${o.replace(/%%_=(.+?)_%%/g,'"+safe(function(){return $1;})+"').replace(/%%_(.+?)_%%/g,'";$1\noutput+="')};return output;\n\t\t}\n\t`)}const d=(e,t,n,r)=>Array.from(e.querySelectorAll("*")).filter((e=>e.tagName.toLowerCase()in t)).reverse().map((e=>(Array.from(e.querySelectorAll("template")).map((e=>d(e.content,t,n,r))),u(e,n,r),e))),u=(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),t[r]=l(e,n)}},c={},f={},m=(e,t)=>{f[e]=Object.assign({},f[e],t),c[e]&&c[e].forEach((e=>e(t)))},p=(e,t)=>(c[e]=c[e]||[],c[e].push(t),e in f&&t(f[e]),()=>{c[e]=c[e].filter((e=>e!=t))});var h;var v="http://www.w3.org/1999/xhtml",b="undefined"==typeof document?void 0:document,g=!!b&&"content"in b.createElement("template"),_=!!b&&b.createRange&&"createContextualFragment"in b.createRange();function A(e){return e=e.trim(),g?function(e){var t=b.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(e):_?function(e){return h||(h=b.createRange()).selectNode(b.body),h.createContextualFragment(e).childNodes[0]}(e):function(e){var t=b.createElement("body");return t.innerHTML=e,t.childNodes[0]}(e)}function N(e,t){var n,r,i=e.nodeName,o=t.nodeName;return i===o||(n=i.charCodeAt(0),r=o.charCodeAt(0),n<=90&&r>=97?i===o.toUpperCase():r<=90&&n>=97&&o===i.toUpperCase())}function y(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n))}var E={OPTION:function(e,t){var n=e.parentNode;if(n){var r=n.nodeName.toUpperCase();"OPTGROUP"===r&&(r=(n=n.parentNode)&&n.nodeName.toUpperCase()),"SELECT"!==r||n.hasAttribute("multiple")||(e.hasAttribute("selected")&&!t.selected&&(e.setAttribute("selected","selected"),e.removeAttribute("selected")),n.selectedIndex=-1)}y(e,t,"selected")},INPUT:function(e,t){y(e,t,"checked"),y(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),t.hasAttribute("value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var r=e.firstChild;if(r){var i=r.nodeValue;if(i==n||!n&&i==e.placeholder)return;r.nodeValue=n}},SELECT:function(e,t){if(!t.hasAttribute("multiple")){for(var n,r,i=-1,o=0,a=e.firstChild;a;)if("OPTGROUP"===(r=a.nodeName&&a.nodeName.toUpperCase()))a=(n=a).firstChild;else{if("OPTION"===r){if(a.hasAttribute("selected")){i=o;break}o++}!(a=a.nextSibling)&&n&&(a=n.nextSibling,n=null)}e.selectedIndex=i}}};function x(){}function C(e){if(e)return e.getAttribute&&e.getAttribute("id")||e.id}var T,$=(T=function(e,t){var n,r,i,o,a=t.attributes;if(11!==t.nodeType&&11!==e.nodeType){for(var s=a.length-1;s>=0;s--)r=(n=a[s]).name,i=n.namespaceURI,o=n.value,i?(r=n.localName||r,e.getAttributeNS(i,r)!==o&&("xmlns"===n.prefix&&(r=n.name),e.setAttributeNS(i,r,o))):e.getAttribute(r)!==o&&e.setAttribute(r,o);for(var l=e.attributes,d=l.length-1;d>=0;d--)r=(n=l[d]).name,(i=n.namespaceURI)?(r=n.localName||r,t.hasAttributeNS(i,r)||e.removeAttributeNS(i,r)):t.hasAttribute(r)||e.removeAttribute(r)}},function(e,t,n){if(n||(n={}),"string"==typeof t)if("#document"===e.nodeName||"HTML"===e.nodeName||"BODY"===e.nodeName){var r=t;(t=b.createElement("html")).innerHTML=r}else t=A(t);else 11===t.nodeType&&(t=t.firstElementChild);var i=n.getNodeKey||C,o=n.onBeforeNodeAdded||x,a=n.onNodeAdded||x,s=n.onBeforeElUpdated||x,l=n.onElUpdated||x,d=n.onBeforeNodeDiscarded||x,u=n.onNodeDiscarded||x,c=n.onBeforeElChildrenUpdated||x,f=n.skipFromChildren||x,m=n.addChild||function(e,t){return e.appendChild(t)},p=!0===n.childrenOnly,h=Object.create(null),g=[];function _(e){g.push(e)}function y(e,t){if(1===e.nodeType)for(var n=e.firstChild;n;){var r=void 0;t&&(r=i(n))?_(r):(u(n),n.firstChild&&y(n,t)),n=n.nextSibling}}function $(e,t,n){!1!==d(e)&&(t&&t.removeChild(e),u(e),y(e,n))}function S(e){a(e);for(var t=e.firstChild;t;){var n=t.nextSibling,r=i(t);if(r){var o=h[r];o&&N(t,o)?(t.parentNode.replaceChild(o,t),w(o,t)):S(t)}else S(t);t=n}}function w(e,t,n){var r=i(t);if(r&&delete h[r],!n){if(!1===s(e,t))return;if(T(e,t),l(e),!1===c(e,t))return}"TEXTAREA"!==e.nodeName?function(e,t){var n,r,a,s,l,d=f(e),u=t.firstChild,c=e.firstChild;e:for(;u;){for(s=u.nextSibling,n=i(u);!d&&c;){if(a=c.nextSibling,u.isSameNode&&u.isSameNode(c)){u=s,c=a;continue e}r=i(c);var p=c.nodeType,v=void 0;if(p===u.nodeType&&(1===p?(n?n!==r&&((l=h[n])?a===l?v=!1:(e.insertBefore(l,c),r?_(r):$(c,e,!0),c=l):v=!1):r&&(v=!1),(v=!1!==v&&N(c,u))&&w(c,u)):3!==p&&8!=p||(v=!0,c.nodeValue!==u.nodeValue&&(c.nodeValue=u.nodeValue))),v){u=s,c=a;continue e}r?_(r):$(c,e,!0),c=a}if(n&&(l=h[n])&&N(l,u))d||m(e,l),w(l,u);else{var g=o(u);!1!==g&&(g&&(u=g),u.actualize&&(u=u.actualize(e.ownerDocument||b)),m(e,u),S(u))}u=s,c=a}!function(e,t,n){for(;t;){var r=t.nextSibling;(n=i(t))?_(n):$(t,e,!0),t=r}}(e,c,r);var A=E[e.nodeName];A&&A(e,t)}(e,t):E.TEXTAREA(e,t)}!function e(t){if(1===t.nodeType||11===t.nodeType)for(var n=t.firstChild;n;){var r=i(n);r&&(h[r]=n),e(n),n=n.nextSibling}}(e);var O,U,k=e,L=k.nodeType,R=t.nodeType;if(!p)if(1===L)1===R?N(e,t)||(u(e),k=function(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;t.appendChild(n),n=r}return t}(e,(O=t.nodeName,(U=t.namespaceURI)&&U!==v?b.createElementNS(U,O):b.createElement(O)))):k=t;else if(3===L||8===L){if(R===L)return k.nodeValue!==t.nodeValue&&(k.nodeValue=t.nodeValue),k;k=t}if(k===t)u(e);else{if(t.isSameNode&&t.isSameNode(k))return;if(w(k,t,p),g)for(var M=0,B=g.length;M<B;M++){var P=h[g[M]];P&&$(P,P.parentNode,!1)}}return!p&&k!==e&&e.parentNode&&(k.actualize&&(k=k.actualize(e.ownerDocument||b)),e.parentNode.replaceChild(k,e)),k});const S="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},w=(e,t)=>function(n){const r=this,i=n.detail||{};e.__events[t].forEach((e=>{e.handler.apply(r,[n].concat(i.args))}))},O=(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])},U=(e,t,n)=>function(r){const i=this,o=r.detail||{};let a=r.target;for(;a&&(a.matches(t)&&(r.delegateTarget=a,n.apply(i,[r].concat(o.args))),a!==e);)a=a.parentNode},k=(e,t,n,r)=>{if(e.__events=e.__events||{},e.__events[t]=e.__events[t]||[],!e.__events[t].length){const n=w(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:U(e,n,r),callback:r})},L=(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||O(e,t)}else O(e,t)},R=(e,t,n)=>{e.dispatchEvent(S(t,{bubbles:!0,detail:n}))};const M=e=>({main:e=>e,unmount:e=>e,onupdate:e=>e,view:e.view?e.view:e=>e}),B=e=>({onNodeAdded:V,onElUpdated:V,onBeforeElChildrenUpdated:P,onBeforeElUpdated:P}),P=e=>{if("html-static"in e.attributes)return!1},V=e=>(1!==e.nodeType||!e.getAttribute("tplid"))&&e;function j(e,t,a,s,l){return class extends HTMLElement{constructor(){super();const{base:i,options:u}=function(e,{module:t,dependencies:i,templates:a,components:s,$scopes:l}){const u=e.getAttribute("tplid"),c=M(t),f=new Function(`return ${e.getAttribute("html-model")||"{}"}`)();d(e,s,a,l);const h=u?a[u]:null,v={data:t.model?r(t.model):{}},b=l[u]&&l[u].length?l[u].shift():{};v.data=Object.assign(b,v.data,f);const g={template:h,elm:e,dependencies:i,publish:m,subscribe:p,main(e){c.main=e},unmount(e){c.unmount=e},onupdate(e){c.onupdate=e},on(t,n,r){k(e,t,n,r)},off(t,n){L(e,t,n)},trigger(t,n,r){n.constructor===String?Array.from(e.querySelectorAll(n)).forEach((e=>R(e,t,{args:r}))):R(e,t,{args:n})},emit:(...t)=>{R(e,t.shift(),{args:t})},state:{set(e){if(e.constructor===Function){const t=r(v.data);e(t),g.render(t)}else g.render(e);return new Promise((e=>n((t=>n((()=>e(v.data)))))))},get:()=>r(v.data),getRaw:()=>v.data},render(t=v.data){if(!document.body.contains(e))return;v.data=Object.assign(v.data,t);const i=r(v.data),a=g.template.call(c.view(i),e,o,l);$(e,a,B()),n((t=>{Array.from(e.querySelectorAll("[tplid]")).forEach((e=>{const t=Object.assign(e.base.state.getRaw(),i);e.options.onupdate(t),e.base.render(t)}))}))}};return{base:g,options:c}}(this,{module:e,dependencies:t,templates:a,components:s,$scopes:l});this.base=i,this.options=u,this.returns=e.default(i)}connectedCallback(){var e;this.base.render(),this.returns&&this.returns.constructor===Promise?this.returns.then((e=>{var t;this.base&&(null==(t=this.options.main())||t.forEach((e=>e(this.base))))})):null==(e=this.options.main())||e.forEach((e=>e(this.base)))}disconnectedCallback(){this.options.unmount(this.base),n((()=>{document.body.contains(this)||(this.__events&&(this.__events=null),this.base&&(this.base.elm=null),this.base&&(this.base=null),i(this))}))}attributeChangedCallback(){}}}const q={},F={},H={},I={templateConfig:e=>{Object.assign(s,e)},publish:m,subscribe:p,register(e,t,n){F[e]={name:e,module:t,dependencies:n}},start(e=document.body){d(e,F,q,H),D()}},D=()=>{Object.values(F).forEach((e=>{const{name:t,module:n,dependencies:r}=e,i=j(n,r,q,F,H);customElements.define(t,i)}))};return I}));
|
1
|
+
!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,i;null==(r=t.parentNode)||r.insertBefore(e,t),null==(i=t.parentNode)||i.insertBefore(n,t.nextSibling)},r=document.createElement("textarea"),i=e=>(r.innerHTML=e,r.value),o=e=>requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,1e3/60),a=e=>JSON.parse(JSON.stringify(e)),s=e=>{var t,n,r,i=e.attributes;if(i)for(t=i.length-1;t>=0;t-=1)"function"==typeof e[r=i[t].name]&&(e[r]=null);if(i=e.childNodes)for(n=i.length,t=0;t<n;t+=1)s(e.childNodes[t])},l=(e,t)=>{try{return e()}catch(n){return t||""}},d={tags:["${","}"]};function u(e,r){const o=function(e,r,i){const o=new RegExp(`\\${r.tags[0]}(.+?)\\${r.tags[1]}`,"g"),a=t.parseFromString(e.replace(/<\/?template[^>]*>/g,""),"text/html");return a.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"),a=e.getAttribute("html-inner"),s=e.getAttribute("html-class"),l=r||t;if(l){const t=r?"html-for":"html-foreach",o=l.match(/(.*)\sin\s(.*)/)||"",a=o[1],s=o[2];e.removeAttribute(t);const d=Array.from(e.querySelectorAll(`[tplid]:not([${t}] [tplid])`)).map((e=>{const t=e.getAttribute("tplid");return i[t]=[],t})),u=document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${s} }) ){ var ${a} = ${s}[$key]; ${JSON.stringify(d).replace(/\"/g,"'")}.map(function(id){ if($scopes[id]) { $scopes[id][$index] = { ${a}: ${s}[$key], $index: $index, $key: $key } } }); _%%`),c=document.createTextNode("%%_ $index++}})() _%%");n(u,e,c)}if(o){e.removeAttribute("html-if");const t=document.createTextNode(`%%_ if ( safe(function(){ return ${o} }) ){ _%%`),r=document.createTextNode("%%_ } _%%");n(t,e,r)}a&&(e.removeAttribute("html-inner"),e.innerHTML=`%%_=${a}_%%`),s&&(e.removeAttribute("html-class"),e.className=(e.className+` %%_=${s}_%%`).trim())})),a.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,d,r),a=JSON.stringify(o);return new Function("$element","safe","$scopes",`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${a.replace(/%%_=(.+?)_%%/g,(function(e,t){return'"+safe(function(){return '+i(t)+';})+"'})).replace(/%%_(.+?)_%%/g,(function(e,t){return'";'+i(t)+'\noutput+="'}))};return output;\n\t\t}\n\t`)}const c=(e,t,n,r)=>{Array.from(e.querySelectorAll(t)).reverse().forEach((e=>{e.querySelectorAll("template").forEach((e=>c(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),t[r]=u(e,n)}},m={},p={},h=(e,t)=>{p[e]=Object.assign({},p[e],t),m[e]&&m[e].forEach((e=>e(t)))},v=(e,t)=>(m[e]=m[e]||[],m[e].push(t),e in p&&t(p[e]),()=>{m[e]=m[e].filter((e=>e!=t))});var b;var g="http://www.w3.org/1999/xhtml",_="undefined"==typeof document?void 0:document,A=!!_&&"content"in _.createElement("template"),y=!!_&&_.createRange&&"createContextualFragment"in _.createRange();function N(e){return e=e.trim(),A?function(e){var t=_.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(e):y?function(e){return b||(b=_.createRange()).selectNode(_.body),b.createContextualFragment(e).childNodes[0]}(e):function(e){var t=_.createElement("body");return t.innerHTML=e,t.childNodes[0]}(e)}function E(e,t){var n,r,i=e.nodeName,o=t.nodeName;return i===o||(n=i.charCodeAt(0),r=o.charCodeAt(0),n<=90&&r>=97?i===o.toUpperCase():r<=90&&n>=97&&o===i.toUpperCase())}function x(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n))}var T={OPTION:function(e,t){var n=e.parentNode;if(n){var r=n.nodeName.toUpperCase();"OPTGROUP"===r&&(r=(n=n.parentNode)&&n.nodeName.toUpperCase()),"SELECT"!==r||n.hasAttribute("multiple")||(e.hasAttribute("selected")&&!t.selected&&(e.setAttribute("selected","selected"),e.removeAttribute("selected")),n.selectedIndex=-1)}x(e,t,"selected")},INPUT:function(e,t){x(e,t,"checked"),x(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),t.hasAttribute("value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var r=e.firstChild;if(r){var i=r.nodeValue;if(i==n||!n&&i==e.placeholder)return;r.nodeValue=n}},SELECT:function(e,t){if(!t.hasAttribute("multiple")){for(var n,r,i=-1,o=0,a=e.firstChild;a;)if("OPTGROUP"===(r=a.nodeName&&a.nodeName.toUpperCase()))a=(n=a).firstChild;else{if("OPTION"===r){if(a.hasAttribute("selected")){i=o;break}o++}!(a=a.nextSibling)&&n&&(a=n.nextSibling,n=null)}e.selectedIndex=i}}};function C(){}function $(e){if(e)return e.getAttribute&&e.getAttribute("id")||e.id}var S,w=(S=function(e,t){var n,r,i,o,a=t.attributes;if(11!==t.nodeType&&11!==e.nodeType){for(var s=a.length-1;s>=0;s--)r=(n=a[s]).name,i=n.namespaceURI,o=n.value,i?(r=n.localName||r,e.getAttributeNS(i,r)!==o&&("xmlns"===n.prefix&&(r=n.name),e.setAttributeNS(i,r,o))):e.getAttribute(r)!==o&&e.setAttribute(r,o);for(var l=e.attributes,d=l.length-1;d>=0;d--)r=(n=l[d]).name,(i=n.namespaceURI)?(r=n.localName||r,t.hasAttributeNS(i,r)||e.removeAttributeNS(i,r)):t.hasAttribute(r)||e.removeAttribute(r)}},function(e,t,n){if(n||(n={}),"string"==typeof t)if("#document"===e.nodeName||"HTML"===e.nodeName||"BODY"===e.nodeName){var r=t;(t=_.createElement("html")).innerHTML=r}else t=N(t);else 11===t.nodeType&&(t=t.firstElementChild);var i=n.getNodeKey||$,o=n.onBeforeNodeAdded||C,a=n.onNodeAdded||C,s=n.onBeforeElUpdated||C,l=n.onElUpdated||C,d=n.onBeforeNodeDiscarded||C,u=n.onNodeDiscarded||C,c=n.onBeforeElChildrenUpdated||C,f=n.skipFromChildren||C,m=n.addChild||function(e,t){return e.appendChild(t)},p=!0===n.childrenOnly,h=Object.create(null),v=[];function b(e){v.push(e)}function A(e,t){if(1===e.nodeType)for(var n=e.firstChild;n;){var r=void 0;t&&(r=i(n))?b(r):(u(n),n.firstChild&&A(n,t)),n=n.nextSibling}}function y(e,t,n){!1!==d(e)&&(t&&t.removeChild(e),u(e),A(e,n))}function x(e){a(e);for(var t=e.firstChild;t;){var n=t.nextSibling,r=i(t);if(r){var o=h[r];o&&E(t,o)?(t.parentNode.replaceChild(o,t),w(o,t)):x(t)}else x(t);t=n}}function w(e,t,n){var r=i(t);if(r&&delete h[r],!n){if(!1===s(e,t))return;if(S(e,t),l(e),!1===c(e,t))return}"TEXTAREA"!==e.nodeName?function(e,t){var n,r,a,s,l,d=f(e),u=t.firstChild,c=e.firstChild;e:for(;u;){for(s=u.nextSibling,n=i(u);!d&&c;){if(a=c.nextSibling,u.isSameNode&&u.isSameNode(c)){u=s,c=a;continue e}r=i(c);var p=c.nodeType,v=void 0;if(p===u.nodeType&&(1===p?(n?n!==r&&((l=h[n])?a===l?v=!1:(e.insertBefore(l,c),r?b(r):y(c,e,!0),c=l):v=!1):r&&(v=!1),(v=!1!==v&&E(c,u))&&w(c,u)):3!==p&&8!=p||(v=!0,c.nodeValue!==u.nodeValue&&(c.nodeValue=u.nodeValue))),v){u=s,c=a;continue e}r?b(r):y(c,e,!0),c=a}if(n&&(l=h[n])&&E(l,u))d||m(e,l),w(l,u);else{var g=o(u);!1!==g&&(g&&(u=g),u.actualize&&(u=u.actualize(e.ownerDocument||_)),m(e,u),x(u))}u=s,c=a}!function(e,t,n){for(;t;){var r=t.nextSibling;(n=i(t))?b(n):y(t,e,!0),t=r}}(e,c,r);var A=T[e.nodeName];A&&A(e,t)}(e,t):T.TEXTAREA(e,t)}!function e(t){if(1===t.nodeType||11===t.nodeType)for(var n=t.firstChild;n;){var r=i(n);r&&(h[r]=n),e(n),n=n.nextSibling}}(e);var O,k,U=e,R=U.nodeType,j=t.nodeType;if(!p)if(1===R)1===j?E(e,t)||(u(e),U=function(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;t.appendChild(n),n=r}return t}(e,(O=t.nodeName,(k=t.namespaceURI)&&k!==g?_.createElementNS(k,O):_.createElement(O)))):U=t;else if(3===R||8===R){if(j===R)return U.nodeValue!==t.nodeValue&&(U.nodeValue=t.nodeValue),U;U=t}if(U===t)u(e);else{if(t.isSameNode&&t.isSameNode(U))return;if(w(U,t,p),v)for(var L=0,M=v.length;L<M;L++){var P=h[v[L]];P&&y(P,P.parentNode,!1)}}return!p&&U!==e&&e.parentNode&&(U.actualize&&(U=U.actualize(e.ownerDocument||_)),e.parentNode.replaceChild(U,e)),U});const O="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},k=(e,t)=>function(n){const r=this,i=n.detail||{};e.__events[t].forEach((e=>{e.handler.apply(r,[n].concat(i.args))}))},U=(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])},R=(e,t,n)=>function(r){const i=this,o=r.detail||{};let a=r.target;for(;a&&(a.matches(t)&&(r.delegateTarget=a,n.apply(i,[r].concat(o.args))),a!==e);)a=a.parentNode},j=(e,t,n,r)=>{if(e.__events=e.__events||{},e.__events[t]=e.__events[t]||[],!e.__events[t].length){const n=k(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:R(e,n,r),callback:r})},L=(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||U(e,t)}else U(e,t)},M=(e,t,n)=>{e.dispatchEvent(O(t,{bubbles:!0,detail:n}))};const P=e=>({main:e=>e,unmount:e=>e,onupdate:e=>e,view:e.view?e.view:e=>e}),B=e=>({onNodeAdded:q,onElUpdated:q,onBeforeElChildrenUpdated:V,onBeforeElUpdated:V}),V=e=>{if("html-static"in e.attributes)return!1},q=e=>(1!==e.nodeType||!e.getAttribute("tplid"))&&e;function F(e,t,n,r,i){return class extends HTMLElement{constructor(){super();const{base:s,options:d}=function(e,{module:t,dependencies:n,templates:r,components:i,$scopes:s}){const d=e.getAttribute("tplid"),u=P(t),f=new Function(`return ${e.getAttribute("html-model")||"{}"}`)(),m=Object.keys(i).toString();c(e,m,r,s);const p=d?r[d]:null,b={data:t.model?a(t.model):{}},g=s[d]&&s[d].length?s[d].shift():{};b.data=Object.assign(g,b.data,f);const _={template:p,elm:e,dependencies:n,publish:h,subscribe:v,main(e){u.main=e},unmount(e){u.unmount=e},onupdate(e){u.onupdate=e},on(t,n,r){j(e,t,n,r)},off(t,n){L(e,t,n)},trigger(t,n,r){n.constructor===String?Array.from(e.querySelectorAll(n)).forEach((e=>M(e,t,{args:r}))):M(e,t,{args:n})},emit:(...t)=>{M(e,t.shift(),{args:t})},state:{set(e){if(e.constructor===Function){const t=a(b.data);e(t),_.render(t)}else _.render(e);return new Promise((e=>o((t=>o((()=>e(b.data)))))))},get:()=>a(b.data),getRaw:()=>b.data},render(t=b.data){if(!document.body.contains(e))return;b.data=Object.assign(b.data,t);const n=a(b.data),r=_.template.call(u.view(n),e,l,s);w(e,r,B()),o((t=>{Array.from(e.querySelectorAll("[tplid]")).forEach((e=>{const t=Object.assign(e.base.state.getRaw(),n);e.options.onupdate(t),e.base.render(t)}))}))}};return{base:_,options:u}}(this,{module:e,dependencies:t,templates:n,components:r,$scopes:i});this.base=s,this.options=d,this.returns=e.default(s)}connectedCallback(){if(this.base.render(),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),o((()=>{document.body.contains(this)||(this.__events&&(this.__events=null),this.base&&(this.base.elm=null),this.base&&(this.base=null),s(this))}))}attributeChangedCallback(){}}}const H={},I={},D={},z={templateConfig:e=>{Object.assign(d,e)},publish:h,subscribe:v,register(e,t,n){I[e]={name:e,module:t,dependencies:n}},start(e=document.body){const t=Object.keys(I).toString();c(e,t,H,D),J()}},J=()=>{Object.values(I).forEach((e=>{const{name:t,module:n,dependencies:r}=e,i=F(n,r,H,I,D);customElements.define(t,i)}))};e.default=z,e.html=(e,...t)=>{let n=e.raw,r="";return t.forEach(((e,t)=>{let i=n[t];Array.isArray(e)&&(e=e.join("")),r+=i,r+=e})),r+=n[n.length-1],r},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/transpile.ts","../src/utils/index.ts","../src/template-system.ts","../src/utils/pubsub.ts","../node_modules/morphdom/dist/morphdom-esm.js","../src/utils/events.ts","../src/component.ts","../src/element.ts","../src/index.ts"],"sourcesContent":["const parser = new DOMParser()\n\nexport default function Transpile(html, config, $scopes) {\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\n\t\t\tconst ids = Array.from(element.querySelectorAll(`[tplid]:not([${selector}] [tplid])`)).map((cp) => {\n\t\t\t\tconst tplid = cp.getAttribute('tplid')\n\t\t\t\t$scopes[tplid] = []\n\t\t\t\treturn tplid\n\t\t\t})\n\n\t\t\tconst open = document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${object} }) ){ var ${varname} = ${object}[$key]; ${JSON.stringify(ids).replace(/\\\"/g, \"'\")}.map(function(id){ if($scopes[id]) { $scopes[id][$index] = { ${varname}: ${object}[$key], $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","export 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\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 } from './utils'\n\nconst textarea = document.createElement('textarea')\n\nconst config = {\n\ttags: ['${', '}']\n}\n\nexport const templateConfig = (newconfig) => {\n\tObject.assign(config, newconfig)\n}\n\nexport default function Template(element, $scopes) {\n\n\tconst html = Transpile(element.outerHTML, config, $scopes)\n\ttextarea.innerHTML = html\n\tconst decodedHTML = JSON.stringify(textarea.value)\n\n\treturn new Function('$element', 'safe', '$scopes',`\n\t\tvar $data = this;\n\t\twith( $data ){\n\t\t\tvar output=${decodedHTML\n\t\t\t\t.replace(/%%_=(.+?)_%%/g, '\"+safe(function(){return $1;})+\"')\n\t\t\t\t.replace(/%%_(.+?)_%%/g, '\";$1\\noutput+=\"')};return output;\n\t\t}\n\t`)\n}\n\nexport const buildtemplates = ( target, components, templates, $scopes ) => {\n\treturn Array\n\t\t.from(target.querySelectorAll('*'))\n\t\t.filter((node:HTMLElement) => node.tagName.toLowerCase() in components)\n\t\t.reverse()\n\t\t.map((node:HTMLElement) => {\n\t\t\tArray.from(node.querySelectorAll('template'))\n\t\t\t\t.map((template) => buildtemplates(template.content, components, templates, $scopes))\n\t\t\tcreateTemplateId(node, templates, $scopes)\n\t\t\treturn node\n\t\t})\n}\n\nconst createTemplateId = (element, templates, $scopes ) => {\n\tconst tplid = element.getAttribute('tplid')\n\tif (!tplid) {\n\t\tconst id = uuid()\n\t\telement.setAttribute('tplid', id)\n\t\ttemplates[id] = Template(element, $scopes)\n\t}\n}\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","var DOCUMENT_FRAGMENT_NODE = 11;\n\nfunction morphAttrs(fromNode, toNode) {\n var toNodeAttrs = toNode.attributes;\n var attr;\n var attrName;\n var attrNamespaceURI;\n var attrValue;\n var fromValue;\n\n // document-fragments dont have attributes so lets not do anything\n if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE || fromNode.nodeType === DOCUMENT_FRAGMENT_NODE) {\n return;\n }\n\n // update attributes on original DOM element\n for (var i = toNodeAttrs.length - 1; i >= 0; i--) {\n attr = toNodeAttrs[i];\n attrName = attr.name;\n attrNamespaceURI = attr.namespaceURI;\n attrValue = attr.value;\n\n if (attrNamespaceURI) {\n attrName = attr.localName || attrName;\n fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);\n\n if (fromValue !== attrValue) {\n if (attr.prefix === 'xmlns'){\n attrName = attr.name; // It's not allowed to set an attribute with the XMLNS namespace without specifying the `xmlns` prefix\n }\n fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue);\n }\n } else {\n fromValue = fromNode.getAttribute(attrName);\n\n if (fromValue !== attrValue) {\n fromNode.setAttribute(attrName, attrValue);\n }\n }\n }\n\n // Remove any extra attributes found on the original DOM element that\n // weren't found on the target element.\n var fromNodeAttrs = fromNode.attributes;\n\n for (var d = fromNodeAttrs.length - 1; d >= 0; d--) {\n attr = fromNodeAttrs[d];\n attrName = attr.name;\n attrNamespaceURI = attr.namespaceURI;\n\n if (attrNamespaceURI) {\n attrName = attr.localName || attrName;\n\n if (!toNode.hasAttributeNS(attrNamespaceURI, attrName)) {\n fromNode.removeAttributeNS(attrNamespaceURI, attrName);\n }\n } else {\n if (!toNode.hasAttribute(attrName)) {\n fromNode.removeAttribute(attrName);\n }\n }\n }\n}\n\nvar range; // Create a range object for efficently rendering strings to elements.\nvar NS_XHTML = 'http://www.w3.org/1999/xhtml';\n\nvar doc = typeof document === 'undefined' ? undefined : document;\nvar HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template');\nvar HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange();\n\nfunction createFragmentFromTemplate(str) {\n var template = doc.createElement('template');\n template.innerHTML = str;\n return template.content.childNodes[0];\n}\n\nfunction createFragmentFromRange(str) {\n if (!range) {\n range = doc.createRange();\n range.selectNode(doc.body);\n }\n\n var fragment = range.createContextualFragment(str);\n return fragment.childNodes[0];\n}\n\nfunction createFragmentFromWrap(str) {\n var fragment = doc.createElement('body');\n fragment.innerHTML = str;\n return fragment.childNodes[0];\n}\n\n/**\n * This is about the same\n * var html = new DOMParser().parseFromString(str, 'text/html');\n * return html.body.firstChild;\n *\n * @method toElement\n * @param {String} str\n */\nfunction toElement(str) {\n str = str.trim();\n if (HAS_TEMPLATE_SUPPORT) {\n // avoid restrictions on content for things like `<tr><th>Hi</th></tr>` which\n // createContextualFragment doesn't support\n // <template> support not available in IE\n return createFragmentFromTemplate(str);\n } else if (HAS_RANGE_SUPPORT) {\n return createFragmentFromRange(str);\n }\n\n return createFragmentFromWrap(str);\n}\n\n/**\n * Returns true if two node's names are the same.\n *\n * NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same\n * nodeName and different namespace URIs.\n *\n * @param {Element} a\n * @param {Element} b The target element\n * @return {boolean}\n */\nfunction compareNodeNames(fromEl, toEl) {\n var fromNodeName = fromEl.nodeName;\n var toNodeName = toEl.nodeName;\n var fromCodeStart, toCodeStart;\n\n if (fromNodeName === toNodeName) {\n return true;\n }\n\n fromCodeStart = fromNodeName.charCodeAt(0);\n toCodeStart = toNodeName.charCodeAt(0);\n\n // If the target element is a virtual DOM node or SVG node then we may\n // need to normalize the tag name before comparing. Normal HTML elements that are\n // in the \"http://www.w3.org/1999/xhtml\"\n // are converted to upper case\n if (fromCodeStart <= 90 && toCodeStart >= 97) { // from is upper and to is lower\n return fromNodeName === toNodeName.toUpperCase();\n } else if (toCodeStart <= 90 && fromCodeStart >= 97) { // to is upper and from is lower\n return toNodeName === fromNodeName.toUpperCase();\n } else {\n return false;\n }\n}\n\n/**\n * Create an element, optionally with a known namespace URI.\n *\n * @param {string} name the element name, e.g. 'div' or 'svg'\n * @param {string} [namespaceURI] the element's namespace URI, i.e. the value of\n * its `xmlns` attribute or its inferred namespace.\n *\n * @return {Element}\n */\nfunction createElementNS(name, namespaceURI) {\n return !namespaceURI || namespaceURI === NS_XHTML ?\n doc.createElement(name) :\n doc.createElementNS(namespaceURI, name);\n}\n\n/**\n * Copies the children of one DOM element to another DOM element\n */\nfunction moveChildren(fromEl, toEl) {\n var curChild = fromEl.firstChild;\n while (curChild) {\n var nextChild = curChild.nextSibling;\n toEl.appendChild(curChild);\n curChild = nextChild;\n }\n return toEl;\n}\n\nfunction syncBooleanAttrProp(fromEl, toEl, name) {\n if (fromEl[name] !== toEl[name]) {\n fromEl[name] = toEl[name];\n if (fromEl[name]) {\n fromEl.setAttribute(name, '');\n } else {\n fromEl.removeAttribute(name);\n }\n }\n}\n\nvar specialElHandlers = {\n OPTION: function(fromEl, toEl) {\n var parentNode = fromEl.parentNode;\n if (parentNode) {\n var parentName = parentNode.nodeName.toUpperCase();\n if (parentName === 'OPTGROUP') {\n parentNode = parentNode.parentNode;\n parentName = parentNode && parentNode.nodeName.toUpperCase();\n }\n if (parentName === 'SELECT' && !parentNode.hasAttribute('multiple')) {\n if (fromEl.hasAttribute('selected') && !toEl.selected) {\n // Workaround for MS Edge bug where the 'selected' attribute can only be\n // removed if set to a non-empty value:\n // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12087679/\n fromEl.setAttribute('selected', 'selected');\n fromEl.removeAttribute('selected');\n }\n // We have to reset select element's selectedIndex to -1, otherwise setting\n // fromEl.selected using the syncBooleanAttrProp below has no effect.\n // The correct selectedIndex will be set in the SELECT special handler below.\n parentNode.selectedIndex = -1;\n }\n }\n syncBooleanAttrProp(fromEl, toEl, 'selected');\n },\n /**\n * The \"value\" attribute is special for the <input> element since it sets\n * the initial value. Changing the \"value\" attribute without changing the\n * \"value\" property will have no effect since it is only used to the set the\n * initial value. Similar for the \"checked\" attribute, and \"disabled\".\n */\n INPUT: function(fromEl, toEl) {\n syncBooleanAttrProp(fromEl, toEl, 'checked');\n syncBooleanAttrProp(fromEl, toEl, 'disabled');\n\n if (fromEl.value !== toEl.value) {\n fromEl.value = toEl.value;\n }\n\n if (!toEl.hasAttribute('value')) {\n fromEl.removeAttribute('value');\n }\n },\n\n TEXTAREA: function(fromEl, toEl) {\n var newValue = toEl.value;\n if (fromEl.value !== newValue) {\n fromEl.value = newValue;\n }\n\n var firstChild = fromEl.firstChild;\n if (firstChild) {\n // Needed for IE. Apparently IE sets the placeholder as the\n // node value and vise versa. This ignores an empty update.\n var oldValue = firstChild.nodeValue;\n\n if (oldValue == newValue || (!newValue && oldValue == fromEl.placeholder)) {\n return;\n }\n\n firstChild.nodeValue = newValue;\n }\n },\n SELECT: function(fromEl, toEl) {\n if (!toEl.hasAttribute('multiple')) {\n var selectedIndex = -1;\n var i = 0;\n // We have to loop through children of fromEl, not toEl since nodes can be moved\n // from toEl to fromEl directly when morphing.\n // At the time this special handler is invoked, all children have already been morphed\n // and appended to / removed from fromEl, so using fromEl here is safe and correct.\n var curChild = fromEl.firstChild;\n var optgroup;\n var nodeName;\n while(curChild) {\n nodeName = curChild.nodeName && curChild.nodeName.toUpperCase();\n if (nodeName === 'OPTGROUP') {\n optgroup = curChild;\n curChild = optgroup.firstChild;\n } else {\n if (nodeName === 'OPTION') {\n if (curChild.hasAttribute('selected')) {\n selectedIndex = i;\n break;\n }\n i++;\n }\n curChild = curChild.nextSibling;\n if (!curChild && optgroup) {\n curChild = optgroup.nextSibling;\n optgroup = null;\n }\n }\n }\n\n fromEl.selectedIndex = selectedIndex;\n }\n }\n};\n\nvar ELEMENT_NODE = 1;\nvar DOCUMENT_FRAGMENT_NODE$1 = 11;\nvar TEXT_NODE = 3;\nvar COMMENT_NODE = 8;\n\nfunction noop() {}\n\nfunction defaultGetNodeKey(node) {\n if (node) {\n return (node.getAttribute && node.getAttribute('id')) || node.id;\n }\n}\n\nfunction morphdomFactory(morphAttrs) {\n\n return function morphdom(fromNode, toNode, options) {\n if (!options) {\n options = {};\n }\n\n if (typeof toNode === 'string') {\n if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML' || fromNode.nodeName === 'BODY') {\n var toNodeHtml = toNode;\n toNode = doc.createElement('html');\n toNode.innerHTML = toNodeHtml;\n } else {\n toNode = toElement(toNode);\n }\n } else if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE$1) {\n toNode = toNode.firstElementChild;\n }\n\n var getNodeKey = options.getNodeKey || defaultGetNodeKey;\n var onBeforeNodeAdded = options.onBeforeNodeAdded || noop;\n var onNodeAdded = options.onNodeAdded || noop;\n var onBeforeElUpdated = options.onBeforeElUpdated || noop;\n var onElUpdated = options.onElUpdated || noop;\n var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;\n var onNodeDiscarded = options.onNodeDiscarded || noop;\n var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop;\n var skipFromChildren = options.skipFromChildren || noop;\n var addChild = options.addChild || function(parent, child){ return parent.appendChild(child); };\n var childrenOnly = options.childrenOnly === true;\n\n // This object is used as a lookup to quickly find all keyed elements in the original DOM tree.\n var fromNodesLookup = Object.create(null);\n var keyedRemovalList = [];\n\n function addKeyedRemoval(key) {\n keyedRemovalList.push(key);\n }\n\n function walkDiscardedChildNodes(node, skipKeyedNodes) {\n if (node.nodeType === ELEMENT_NODE) {\n var curChild = node.firstChild;\n while (curChild) {\n\n var key = undefined;\n\n if (skipKeyedNodes && (key = getNodeKey(curChild))) {\n // If we are skipping keyed nodes then we add the key\n // to a list so that it can be handled at the very end.\n addKeyedRemoval(key);\n } else {\n // Only report the node as discarded if it is not keyed. We do this because\n // at the end we loop through all keyed elements that were unmatched\n // and then discard them in one final pass.\n onNodeDiscarded(curChild);\n if (curChild.firstChild) {\n walkDiscardedChildNodes(curChild, skipKeyedNodes);\n }\n }\n\n curChild = curChild.nextSibling;\n }\n }\n }\n\n /**\n * Removes a DOM node out of the original DOM\n *\n * @param {Node} node The node to remove\n * @param {Node} parentNode The nodes parent\n * @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.\n * @return {undefined}\n */\n function removeNode(node, parentNode, skipKeyedNodes) {\n if (onBeforeNodeDiscarded(node) === false) {\n return;\n }\n\n if (parentNode) {\n parentNode.removeChild(node);\n }\n\n onNodeDiscarded(node);\n walkDiscardedChildNodes(node, skipKeyedNodes);\n }\n\n // // TreeWalker implementation is no faster, but keeping this around in case this changes in the future\n // function indexTree(root) {\n // var treeWalker = document.createTreeWalker(\n // root,\n // NodeFilter.SHOW_ELEMENT);\n //\n // var el;\n // while((el = treeWalker.nextNode())) {\n // var key = getNodeKey(el);\n // if (key) {\n // fromNodesLookup[key] = el;\n // }\n // }\n // }\n\n // // NodeIterator implementation is no faster, but keeping this around in case this changes in the future\n //\n // function indexTree(node) {\n // var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT);\n // var el;\n // while((el = nodeIterator.nextNode())) {\n // var key = getNodeKey(el);\n // if (key) {\n // fromNodesLookup[key] = el;\n // }\n // }\n // }\n\n function indexTree(node) {\n if (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE$1) {\n var curChild = node.firstChild;\n while (curChild) {\n var key = getNodeKey(curChild);\n if (key) {\n fromNodesLookup[key] = curChild;\n }\n\n // Walk recursively\n indexTree(curChild);\n\n curChild = curChild.nextSibling;\n }\n }\n }\n\n indexTree(fromNode);\n\n function handleNodeAdded(el) {\n onNodeAdded(el);\n\n var curChild = el.firstChild;\n while (curChild) {\n var nextSibling = curChild.nextSibling;\n\n var key = getNodeKey(curChild);\n if (key) {\n var unmatchedFromEl = fromNodesLookup[key];\n // if we find a duplicate #id node in cache, replace `el` with cache value\n // and morph it to the child node.\n if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) {\n curChild.parentNode.replaceChild(unmatchedFromEl, curChild);\n morphEl(unmatchedFromEl, curChild);\n } else {\n handleNodeAdded(curChild);\n }\n } else {\n // recursively call for curChild and it's children to see if we find something in\n // fromNodesLookup\n handleNodeAdded(curChild);\n }\n\n curChild = nextSibling;\n }\n }\n\n function cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey) {\n // We have processed all of the \"to nodes\". If curFromNodeChild is\n // non-null then we still have some from nodes left over that need\n // to be removed\n while (curFromNodeChild) {\n var fromNextSibling = curFromNodeChild.nextSibling;\n if ((curFromNodeKey = getNodeKey(curFromNodeChild))) {\n // Since the node is keyed it might be matched up later so we defer\n // the actual removal to later\n addKeyedRemoval(curFromNodeKey);\n } else {\n // NOTE: we skip nested keyed nodes from being removed since there is\n // still a chance they will be matched up later\n removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);\n }\n curFromNodeChild = fromNextSibling;\n }\n }\n\n function morphEl(fromEl, toEl, childrenOnly) {\n var toElKey = getNodeKey(toEl);\n\n if (toElKey) {\n // If an element with an ID is being morphed then it will be in the final\n // DOM so clear it out of the saved elements collection\n delete fromNodesLookup[toElKey];\n }\n\n if (!childrenOnly) {\n // optional\n if (onBeforeElUpdated(fromEl, toEl) === false) {\n return;\n }\n\n // update attributes on original DOM element first\n morphAttrs(fromEl, toEl);\n // optional\n onElUpdated(fromEl);\n\n if (onBeforeElChildrenUpdated(fromEl, toEl) === false) {\n return;\n }\n }\n\n if (fromEl.nodeName !== 'TEXTAREA') {\n morphChildren(fromEl, toEl);\n } else {\n specialElHandlers.TEXTAREA(fromEl, toEl);\n }\n }\n\n function morphChildren(fromEl, toEl) {\n var skipFrom = skipFromChildren(fromEl);\n var curToNodeChild = toEl.firstChild;\n var curFromNodeChild = fromEl.firstChild;\n var curToNodeKey;\n var curFromNodeKey;\n\n var fromNextSibling;\n var toNextSibling;\n var matchingFromEl;\n\n // walk the children\n outer: while (curToNodeChild) {\n toNextSibling = curToNodeChild.nextSibling;\n curToNodeKey = getNodeKey(curToNodeChild);\n\n // walk the fromNode children all the way through\n while (!skipFrom && curFromNodeChild) {\n fromNextSibling = curFromNodeChild.nextSibling;\n\n if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) {\n curToNodeChild = toNextSibling;\n curFromNodeChild = fromNextSibling;\n continue outer;\n }\n\n curFromNodeKey = getNodeKey(curFromNodeChild);\n\n var curFromNodeType = curFromNodeChild.nodeType;\n\n // this means if the curFromNodeChild doesnt have a match with the curToNodeChild\n var isCompatible = undefined;\n\n if (curFromNodeType === curToNodeChild.nodeType) {\n if (curFromNodeType === ELEMENT_NODE) {\n // Both nodes being compared are Element nodes\n\n if (curToNodeKey) {\n // The target node has a key so we want to match it up with the correct element\n // in the original DOM tree\n if (curToNodeKey !== curFromNodeKey) {\n // The current element in the original DOM tree does not have a matching key so\n // let's check our lookup to see if there is a matching element in the original\n // DOM tree\n if ((matchingFromEl = fromNodesLookup[curToNodeKey])) {\n if (fromNextSibling === matchingFromEl) {\n // Special case for single element removals. To avoid removing the original\n // DOM node out of the tree (since that can break CSS transitions, etc.),\n // we will instead discard the current node and wait until the next\n // iteration to properly match up the keyed target element with its matching\n // element in the original tree\n isCompatible = false;\n } else {\n // We found a matching keyed element somewhere in the original DOM tree.\n // Let's move the original DOM node into the current position and morph\n // it.\n\n // NOTE: We use insertBefore instead of replaceChild because we want to go through\n // the `removeNode()` function for the node that is being discarded so that\n // all lifecycle hooks are correctly invoked\n fromEl.insertBefore(matchingFromEl, curFromNodeChild);\n\n // fromNextSibling = curFromNodeChild.nextSibling;\n\n if (curFromNodeKey) {\n // Since the node is keyed it might be matched up later so we defer\n // the actual removal to later\n addKeyedRemoval(curFromNodeKey);\n } else {\n // NOTE: we skip nested keyed nodes from being removed since there is\n // still a chance they will be matched up later\n removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);\n }\n\n curFromNodeChild = matchingFromEl;\n }\n } else {\n // The nodes are not compatible since the \"to\" node has a key and there\n // is no matching keyed node in the source tree\n isCompatible = false;\n }\n }\n } else if (curFromNodeKey) {\n // The original has a key\n isCompatible = false;\n }\n\n isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild);\n if (isCompatible) {\n // We found compatible DOM elements so transform\n // the current \"from\" node to match the current\n // target DOM node.\n // MORPH\n morphEl(curFromNodeChild, curToNodeChild);\n }\n\n } else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {\n // Both nodes being compared are Text or Comment nodes\n isCompatible = true;\n // Simply update nodeValue on the original node to\n // change the text value\n if (curFromNodeChild.nodeValue !== curToNodeChild.nodeValue) {\n curFromNodeChild.nodeValue = curToNodeChild.nodeValue;\n }\n\n }\n }\n\n if (isCompatible) {\n // Advance both the \"to\" child and the \"from\" child since we found a match\n // Nothing else to do as we already recursively called morphChildren above\n curToNodeChild = toNextSibling;\n curFromNodeChild = fromNextSibling;\n continue outer;\n }\n\n // No compatible match so remove the old node from the DOM and continue trying to find a\n // match in the original DOM. However, we only do this if the from node is not keyed\n // since it is possible that a keyed node might match up with a node somewhere else in the\n // target tree and we don't want to discard it just yet since it still might find a\n // home in the final DOM tree. After everything is done we will remove any keyed nodes\n // that didn't find a home\n if (curFromNodeKey) {\n // Since the node is keyed it might be matched up later so we defer\n // the actual removal to later\n addKeyedRemoval(curFromNodeKey);\n } else {\n // NOTE: we skip nested keyed nodes from being removed since there is\n // still a chance they will be matched up later\n removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);\n }\n\n curFromNodeChild = fromNextSibling;\n } // END: while(curFromNodeChild) {}\n\n // If we got this far then we did not find a candidate match for\n // our \"to node\" and we exhausted all of the children \"from\"\n // nodes. Therefore, we will just append the current \"to\" node\n // to the end\n if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) {\n // MORPH\n if(!skipFrom){ addChild(fromEl, matchingFromEl); }\n morphEl(matchingFromEl, curToNodeChild);\n } else {\n var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild);\n if (onBeforeNodeAddedResult !== false) {\n if (onBeforeNodeAddedResult) {\n curToNodeChild = onBeforeNodeAddedResult;\n }\n\n if (curToNodeChild.actualize) {\n curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc);\n }\n addChild(fromEl, curToNodeChild);\n handleNodeAdded(curToNodeChild);\n }\n }\n\n curToNodeChild = toNextSibling;\n curFromNodeChild = fromNextSibling;\n }\n\n cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey);\n\n var specialElHandler = specialElHandlers[fromEl.nodeName];\n if (specialElHandler) {\n specialElHandler(fromEl, toEl);\n }\n } // END: morphChildren(...)\n\n var morphedNode = fromNode;\n var morphedNodeType = morphedNode.nodeType;\n var toNodeType = toNode.nodeType;\n\n if (!childrenOnly) {\n // Handle the case where we are given two DOM nodes that are not\n // compatible (e.g. <div> --> <span> or <div> --> TEXT)\n if (morphedNodeType === ELEMENT_NODE) {\n if (toNodeType === ELEMENT_NODE) {\n if (!compareNodeNames(fromNode, toNode)) {\n onNodeDiscarded(fromNode);\n morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI));\n }\n } else {\n // Going from an element node to a text node\n morphedNode = toNode;\n }\n } else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) { // Text or comment node\n if (toNodeType === morphedNodeType) {\n if (morphedNode.nodeValue !== toNode.nodeValue) {\n morphedNode.nodeValue = toNode.nodeValue;\n }\n\n return morphedNode;\n } else {\n // Text node to something else\n morphedNode = toNode;\n }\n }\n }\n\n if (morphedNode === toNode) {\n // The \"to node\" was not compatible with the \"from node\" so we had to\n // toss out the \"from node\" and use the \"to node\"\n onNodeDiscarded(fromNode);\n } else {\n if (toNode.isSameNode && toNode.isSameNode(morphedNode)) {\n return;\n }\n\n morphEl(morphedNode, toNode, childrenOnly);\n\n // We now need to loop over any keyed nodes that might need to be\n // removed. We only do the removal if we know that the keyed node\n // never found a match. When a keyed node is matched up we remove\n // it out of fromNodesLookup and we use fromNodesLookup to determine\n // if a keyed node has been matched up or not\n if (keyedRemovalList) {\n for (var i=0, len=keyedRemovalList.length; i<len; i++) {\n var elToRemove = fromNodesLookup[keyedRemovalList[i]];\n if (elToRemove) {\n removeNode(elToRemove, elToRemove.parentNode, false);\n }\n }\n }\n }\n\n if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {\n if (morphedNode.actualize) {\n morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc);\n }\n // If we had to swap out the from node with a new node because the old\n // node was not compatible with the target node then we need to\n // replace the old DOM node in the original DOM tree. This is only\n // possible if the original DOM node was part of a DOM tree which\n // we know is the case if it has a parent node.\n fromNode.parentNode.replaceChild(morphedNode, fromNode);\n }\n\n return morphedNode;\n };\n}\n\nvar morphdom = morphdomFactory(morphAttrs);\n\nexport default morphdom;\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 morphdom from 'morphdom'\n\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, $scopes }) {\n\n\tconst tplid = elm.getAttribute('tplid')\n\tconst options = getOptions( module )\n\tconst initialState = (new Function( `return ${elm.getAttribute('html-model') || '{}'}`))()\n\n\tbuildtemplates( elm, components, templates, $scopes )\n\n\tconst template = tplid ? templates[tplid] : null\n\tconst state = { data: module.model ? dup(module.model) : {} }\n\tconst scope = $scopes[tplid] && $scopes[tplid].length? $scopes[tplid].shift() : {}\n\tstate.data = Object.assign(scope, 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 = base.template.call(options.view(newdata), elm, safe, $scopes)\n\n\t\t\tmorphdom(elm, newhtml, morphdomOptions(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 data = Object.assign( child.base.state.getRaw(), newdata)\n\t\t\t\t\t\tchild.options.onupdate(data)\n\t\t\t\t\t\tchild.base.render(data)\n\t\t\t\t\t})\n\t\t\t})\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 morphdomOptions = (_parent ) => ({\n\tonNodeAdded: onUpdates,\n\tonElUpdated: onUpdates,\n\tonBeforeElChildrenUpdated: checkStatic,\n\tonBeforeElUpdated: checkStatic\n})\n\nconst checkStatic = (node) => {\n\tif ('html-static' in node.attributes) {\n\t\treturn false\n\t}\n}\n\nconst onUpdates = (node) => {\n\tif (node.nodeType === 1) {\n\t\tif ( node.getAttribute('tplid') ) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn node\n}\n","import Component from './component'\nimport { purge, rAF } from './utils'\n\nexport default function Element(module, dependencies, templates, components, $scopes) {\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\n\t\t\tsuper()\n\t\t\tconst { base, options } = Component(this, { module, dependencies, templates, components, $scopes })\n\n\t\t\tthis.base = base\n\t\t\tthis.options = options\n\t\t\tthis.returns = module.default(base)\n\t\t}\n\n\t\tconnectedCallback() {\n\n\t\t\tthis.base.render()\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 ) {\n\t\t\t\t\t\tthis.options.main()?.forEach(f => f(this.base))\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}else {\n\t\t\t\tthis.options.main()?.forEach(f => f(this.base))\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\n\t\t}\n\n\t\tattributeChangedCallback() {\n\t\t\t//TODO\n\t\t}\n\t}\n}\n","import { type Module } from '..'\nimport { templateConfig, buildtemplates } from './template-system'\nimport { publish, subscribe } from './utils/pubsub'\nimport Element from './element'\n\nconst templates = {}\nconst components = {}\nconst $scopes = {}\n\nexport default {\n\n\ttemplateConfig,\n\n\tpublish,\n\tsubscribe,\n\n\tregister( name:string, module: Module, dependencies: object ) {\n\t\tcomponents[name] = { name, module, dependencies }\n\t},\n\n\tstart( target = document.body ) {\n\t\tbuildtemplates( target, components, templates, $scopes )\n\t\tregisterComponents()\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\tconst Base = Element(module, dependencies, templates, components, $scopes)\n\t\t\tcustomElements.define(name, Base)\n\t\t})\n}\n"],"names":["parser","DOMParser","wrap","open","node","close","_a","parentNode","insertBefore","_b","nextSibling","rAF","fn","requestAnimationFrame","setTimeout","dup","o","JSON","parse","stringify","purge","d","i","l","n","a","attributes","length","name","childNodes","safe","execute","val","err","textarea","document","createElement","config","tags","Template","element","$scopes","html","regexTags","RegExp","virtual","parseFromString","replace","querySelectorAll","forEach","htmlForeach","getAttribute","htmlFor","htmlIf","htmlInner","htmlClass","forEachInstruction","selector","split","match","varname","object","removeAttribute","ids","Array","from","map","cp","tplid","createTextNode","innerHTML","className","trim","body","all","key","value","Transpile","outerHTML","decodedHTML","Function","buildtemplates","target","components","templates","filter","tagName","toLowerCase","reverse","template","content","createTemplateId","id","c","r","Math","random","toString","setAttribute","topics","_async","publish","params","Object","assign","topic","subscribe","method","push","range","NS_XHTML","doc","HAS_TEMPLATE_SUPPORT","HAS_RANGE_SUPPORT","createRange","toElement","str","createFragmentFromTemplate","selectNode","createContextualFragment","createFragmentFromRange","fragment","createFragmentFromWrap","compareNodeNames","fromEl","toEl","fromCodeStart","toCodeStart","fromNodeName","nodeName","toNodeName","charCodeAt","toUpperCase","syncBooleanAttrProp","specialElHandlers","OPTION","parentName","hasAttribute","selected","selectedIndex","INPUT","TEXTAREA","newValue","firstChild","oldValue","nodeValue","placeholder","SELECT","optgroup","curChild","noop","defaultGetNodeKey","morphAttrs","morphdom","fromNode","toNode","attr","attrName","attrNamespaceURI","attrValue","toNodeAttrs","nodeType","namespaceURI","localName","getAttributeNS","prefix","setAttributeNS","fromNodeAttrs","hasAttributeNS","removeAttributeNS","options","toNodeHtml","firstElementChild","getNodeKey","onBeforeNodeAdded","onNodeAdded","onBeforeElUpdated","onElUpdated","onBeforeNodeDiscarded","onNodeDiscarded","onBeforeElChildrenUpdated","skipFromChildren","addChild","parent","child","appendChild","childrenOnly","fromNodesLookup","create","keyedRemovalList","addKeyedRemoval","walkDiscardedChildNodes","skipKeyedNodes","removeNode","removeChild","handleNodeAdded","el","unmatchedFromEl","replaceChild","morphEl","toElKey","curToNodeKey","curFromNodeKey","fromNextSibling","toNextSibling","matchingFromEl","skipFrom","curToNodeChild","curFromNodeChild","outer","isSameNode","curFromNodeType","isCompatible","onBeforeNodeAddedResult","actualize","ownerDocument","cleanupFromEl","specialElHandler","morphChildren","indexTree","morphedNode","morphedNodeType","toNodeType","nextChild","moveChildren","createElementNS","len","elToRemove","customEvent","window","CustomEvent","data","newEvent","createEvent","initCustomEvent","handler","ev","e","scope","this","detail","__events","apply","concat","args","removeListener","listener","removeEventListener","delegate","callback","matches","delegateTarget","on","selectorOrCallback","addEventListener","call","off","old","trigger","dispatchEvent","bubbles","getOptions","module","main","unmount","onupdate","view","morphdomOptions","_parent","onUpdates","checkStatic","Element","dependencies","HTMLElement","constructor","base","elm","initialState","state","model","shift","eventName","String","children","emit","set","newstate","render","Promise","resolve","_","get","getRaw","contains","newdata","newhtml","Component","returns","default","connectedCallback","then","f","disconnectedCallback","attributeChangedCallback","index","templateConfig","newconfig","register","start","registerComponents","values","component","Base","customElements","define"],"mappings":"sOAAM,MAAAA,EAAS,IAAIC,UAuEnB,MAAMC,EAAO,CAACC,EAAMC,EAAMC,aACpB,OAAAC,EAAAF,EAAAG,aAAYD,EAAAE,aAAaL,EAAMC,GACpC,OAAAK,EAAAL,EAAKG,aAALE,EAAiBD,aAAaH,EAAOD,EAAKM,YAAA,ECzE9BC,EAAOC,GACfC,sBACIA,sBAAsBD,GAEtBE,WAAWF,EAAI,IAAO,IAWlBG,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,E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AW3C,MAEhD,GAGK4Q,EAAqB,KAC1B9M,OACE+M,OAAQnO,GACRlC,SAAUsQ,IACV,MAAM3R,KAAEA,EAAM0O,OAAAA,EAAAA,aAAQU,GAAiBuC,EACjCC,EAAOzC,EAAQT,EAAQU,EAAc5L,EAAWD,EAAY1C,GACnDgR,eAAAC,OAAO9R,EAAM4R,EAAI,GAChC","x_google_ignoreList":[4]}
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/transpile.ts","../src/utils/index.ts","../src/template-system.ts","../src/utils/pubsub.ts","../node_modules/morphdom/dist/morphdom-esm.js","../src/utils/events.ts","../src/component.ts","../src/element.ts","../src/index.ts"],"sourcesContent":["const parser = new DOMParser()\n\nexport default function Transpile(html, config, $scopes) {\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\n\t\t\tconst ids = Array.from(element.querySelectorAll(`[tplid]:not([${selector}] [tplid])`)).map((cp) => {\n\t\t\t\tconst tplid = cp.getAttribute('tplid')\n\t\t\t\t$scopes[tplid] = []\n\t\t\t\treturn tplid\n\t\t\t})\n\n\t\t\tconst open = document.createTextNode(`%%_(function(){ var $index = 0; for(var $key in safe(function(){ return ${object} }) ){ var ${varname} = ${object}[$key]; ${JSON.stringify(ids).replace(/\\\"/g, \"'\")}.map(function(id){ if($scopes[id]) { $scopes[id][$index] = { ${varname}: ${object}[$key], $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\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\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\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","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, $scopes) {\n\n\tconst html = Transpile(element.outerHTML, config, $scopes)\n\tconst decodedHTML = JSON.stringify(html)\n\n\treturn new Function('$element', 'safe', '$scopes',`\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, $scopes ) => {\n\tArray.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, $scopes))\n\t\t\tcreateTemplateId(node, templates, $scopes)\n\t\t})\n}\n\nconst createTemplateId = (element, templates, $scopes ) => {\n\tconst tplid = element.getAttribute('tplid')\n\tif (!tplid) {\n\t\tconst id = uuid()\n\t\telement.setAttribute('tplid', id)\n\t\ttemplates[id] = Template(element, $scopes)\n\t}\n}\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","var DOCUMENT_FRAGMENT_NODE = 11;\n\nfunction morphAttrs(fromNode, toNode) {\n var toNodeAttrs = toNode.attributes;\n var attr;\n var attrName;\n var attrNamespaceURI;\n var attrValue;\n var fromValue;\n\n // document-fragments dont have attributes so lets not do anything\n if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE || fromNode.nodeType === DOCUMENT_FRAGMENT_NODE) {\n return;\n }\n\n // update attributes on original DOM element\n for (var i = toNodeAttrs.length - 1; i >= 0; i--) {\n attr = toNodeAttrs[i];\n attrName = attr.name;\n attrNamespaceURI = attr.namespaceURI;\n attrValue = attr.value;\n\n if (attrNamespaceURI) {\n attrName = attr.localName || attrName;\n fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);\n\n if (fromValue !== attrValue) {\n if (attr.prefix === 'xmlns'){\n attrName = attr.name; // It's not allowed to set an attribute with the XMLNS namespace without specifying the `xmlns` prefix\n }\n fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue);\n }\n } else {\n fromValue = fromNode.getAttribute(attrName);\n\n if (fromValue !== attrValue) {\n fromNode.setAttribute(attrName, attrValue);\n }\n }\n }\n\n // Remove any extra attributes found on the original DOM element that\n // weren't found on the target element.\n var fromNodeAttrs = fromNode.attributes;\n\n for (var d = fromNodeAttrs.length - 1; d >= 0; d--) {\n attr = fromNodeAttrs[d];\n attrName = attr.name;\n attrNamespaceURI = attr.namespaceURI;\n\n if (attrNamespaceURI) {\n attrName = attr.localName || attrName;\n\n if (!toNode.hasAttributeNS(attrNamespaceURI, attrName)) {\n fromNode.removeAttributeNS(attrNamespaceURI, attrName);\n }\n } else {\n if (!toNode.hasAttribute(attrName)) {\n fromNode.removeAttribute(attrName);\n }\n }\n }\n}\n\nvar range; // Create a range object for efficently rendering strings to elements.\nvar NS_XHTML = 'http://www.w3.org/1999/xhtml';\n\nvar doc = typeof document === 'undefined' ? undefined : document;\nvar HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template');\nvar HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange();\n\nfunction createFragmentFromTemplate(str) {\n var template = doc.createElement('template');\n template.innerHTML = str;\n return template.content.childNodes[0];\n}\n\nfunction createFragmentFromRange(str) {\n if (!range) {\n range = doc.createRange();\n range.selectNode(doc.body);\n }\n\n var fragment = range.createContextualFragment(str);\n return fragment.childNodes[0];\n}\n\nfunction createFragmentFromWrap(str) {\n var fragment = doc.createElement('body');\n fragment.innerHTML = str;\n return fragment.childNodes[0];\n}\n\n/**\n * This is about the same\n * var html = new DOMParser().parseFromString(str, 'text/html');\n * return html.body.firstChild;\n *\n * @method toElement\n * @param {String} str\n */\nfunction toElement(str) {\n str = str.trim();\n if (HAS_TEMPLATE_SUPPORT) {\n // avoid restrictions on content for things like `<tr><th>Hi</th></tr>` which\n // createContextualFragment doesn't support\n // <template> support not available in IE\n return createFragmentFromTemplate(str);\n } else if (HAS_RANGE_SUPPORT) {\n return createFragmentFromRange(str);\n }\n\n return createFragmentFromWrap(str);\n}\n\n/**\n * Returns true if two node's names are the same.\n *\n * NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same\n * nodeName and different namespace URIs.\n *\n * @param {Element} a\n * @param {Element} b The target element\n * @return {boolean}\n */\nfunction compareNodeNames(fromEl, toEl) {\n var fromNodeName = fromEl.nodeName;\n var toNodeName = toEl.nodeName;\n var fromCodeStart, toCodeStart;\n\n if (fromNodeName === toNodeName) {\n return true;\n }\n\n fromCodeStart = fromNodeName.charCodeAt(0);\n toCodeStart = toNodeName.charCodeAt(0);\n\n // If the target element is a virtual DOM node or SVG node then we may\n // need to normalize the tag name before comparing. Normal HTML elements that are\n // in the \"http://www.w3.org/1999/xhtml\"\n // are converted to upper case\n if (fromCodeStart <= 90 && toCodeStart >= 97) { // from is upper and to is lower\n return fromNodeName === toNodeName.toUpperCase();\n } else if (toCodeStart <= 90 && fromCodeStart >= 97) { // to is upper and from is lower\n return toNodeName === fromNodeName.toUpperCase();\n } else {\n return false;\n }\n}\n\n/**\n * Create an element, optionally with a known namespace URI.\n *\n * @param {string} name the element name, e.g. 'div' or 'svg'\n * @param {string} [namespaceURI] the element's namespace URI, i.e. the value of\n * its `xmlns` attribute or its inferred namespace.\n *\n * @return {Element}\n */\nfunction createElementNS(name, namespaceURI) {\n return !namespaceURI || namespaceURI === NS_XHTML ?\n doc.createElement(name) :\n doc.createElementNS(namespaceURI, name);\n}\n\n/**\n * Copies the children of one DOM element to another DOM element\n */\nfunction moveChildren(fromEl, toEl) {\n var curChild = fromEl.firstChild;\n while (curChild) {\n var nextChild = curChild.nextSibling;\n toEl.appendChild(curChild);\n curChild = nextChild;\n }\n return toEl;\n}\n\nfunction syncBooleanAttrProp(fromEl, toEl, name) {\n if (fromEl[name] !== toEl[name]) {\n fromEl[name] = toEl[name];\n if (fromEl[name]) {\n fromEl.setAttribute(name, '');\n } else {\n fromEl.removeAttribute(name);\n }\n }\n}\n\nvar specialElHandlers = {\n OPTION: function(fromEl, toEl) {\n var parentNode = fromEl.parentNode;\n if (parentNode) {\n var parentName = parentNode.nodeName.toUpperCase();\n if (parentName === 'OPTGROUP') {\n parentNode = parentNode.parentNode;\n parentName = parentNode && parentNode.nodeName.toUpperCase();\n }\n if (parentName === 'SELECT' && !parentNode.hasAttribute('multiple')) {\n if (fromEl.hasAttribute('selected') && !toEl.selected) {\n // Workaround for MS Edge bug where the 'selected' attribute can only be\n // removed if set to a non-empty value:\n // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12087679/\n fromEl.setAttribute('selected', 'selected');\n fromEl.removeAttribute('selected');\n }\n // We have to reset select element's selectedIndex to -1, otherwise setting\n // fromEl.selected using the syncBooleanAttrProp below has no effect.\n // The correct selectedIndex will be set in the SELECT special handler below.\n parentNode.selectedIndex = -1;\n }\n }\n syncBooleanAttrProp(fromEl, toEl, 'selected');\n },\n /**\n * The \"value\" attribute is special for the <input> element since it sets\n * the initial value. Changing the \"value\" attribute without changing the\n * \"value\" property will have no effect since it is only used to the set the\n * initial value. Similar for the \"checked\" attribute, and \"disabled\".\n */\n INPUT: function(fromEl, toEl) {\n syncBooleanAttrProp(fromEl, toEl, 'checked');\n syncBooleanAttrProp(fromEl, toEl, 'disabled');\n\n if (fromEl.value !== toEl.value) {\n fromEl.value = toEl.value;\n }\n\n if (!toEl.hasAttribute('value')) {\n fromEl.removeAttribute('value');\n }\n },\n\n TEXTAREA: function(fromEl, toEl) {\n var newValue = toEl.value;\n if (fromEl.value !== newValue) {\n fromEl.value = newValue;\n }\n\n var firstChild = fromEl.firstChild;\n if (firstChild) {\n // Needed for IE. Apparently IE sets the placeholder as the\n // node value and vise versa. This ignores an empty update.\n var oldValue = firstChild.nodeValue;\n\n if (oldValue == newValue || (!newValue && oldValue == fromEl.placeholder)) {\n return;\n }\n\n firstChild.nodeValue = newValue;\n }\n },\n SELECT: function(fromEl, toEl) {\n if (!toEl.hasAttribute('multiple')) {\n var selectedIndex = -1;\n var i = 0;\n // We have to loop through children of fromEl, not toEl since nodes can be moved\n // from toEl to fromEl directly when morphing.\n // At the time this special handler is invoked, all children have already been morphed\n // and appended to / removed from fromEl, so using fromEl here is safe and correct.\n var curChild = fromEl.firstChild;\n var optgroup;\n var nodeName;\n while(curChild) {\n nodeName = curChild.nodeName && curChild.nodeName.toUpperCase();\n if (nodeName === 'OPTGROUP') {\n optgroup = curChild;\n curChild = optgroup.firstChild;\n } else {\n if (nodeName === 'OPTION') {\n if (curChild.hasAttribute('selected')) {\n selectedIndex = i;\n break;\n }\n i++;\n }\n curChild = curChild.nextSibling;\n if (!curChild && optgroup) {\n curChild = optgroup.nextSibling;\n optgroup = null;\n }\n }\n }\n\n fromEl.selectedIndex = selectedIndex;\n }\n }\n};\n\nvar ELEMENT_NODE = 1;\nvar DOCUMENT_FRAGMENT_NODE$1 = 11;\nvar TEXT_NODE = 3;\nvar COMMENT_NODE = 8;\n\nfunction noop() {}\n\nfunction defaultGetNodeKey(node) {\n if (node) {\n return (node.getAttribute && node.getAttribute('id')) || node.id;\n }\n}\n\nfunction morphdomFactory(morphAttrs) {\n\n return function morphdom(fromNode, toNode, options) {\n if (!options) {\n options = {};\n }\n\n if (typeof toNode === 'string') {\n if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML' || fromNode.nodeName === 'BODY') {\n var toNodeHtml = toNode;\n toNode = doc.createElement('html');\n toNode.innerHTML = toNodeHtml;\n } else {\n toNode = toElement(toNode);\n }\n } else if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE$1) {\n toNode = toNode.firstElementChild;\n }\n\n var getNodeKey = options.getNodeKey || defaultGetNodeKey;\n var onBeforeNodeAdded = options.onBeforeNodeAdded || noop;\n var onNodeAdded = options.onNodeAdded || noop;\n var onBeforeElUpdated = options.onBeforeElUpdated || noop;\n var onElUpdated = options.onElUpdated || noop;\n var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;\n var onNodeDiscarded = options.onNodeDiscarded || noop;\n var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop;\n var skipFromChildren = options.skipFromChildren || noop;\n var addChild = options.addChild || function(parent, child){ return parent.appendChild(child); };\n var childrenOnly = options.childrenOnly === true;\n\n // This object is used as a lookup to quickly find all keyed elements in the original DOM tree.\n var fromNodesLookup = Object.create(null);\n var keyedRemovalList = [];\n\n function addKeyedRemoval(key) {\n keyedRemovalList.push(key);\n }\n\n function walkDiscardedChildNodes(node, skipKeyedNodes) {\n if (node.nodeType === ELEMENT_NODE) {\n var curChild = node.firstChild;\n while (curChild) {\n\n var key = undefined;\n\n if (skipKeyedNodes && (key = getNodeKey(curChild))) {\n // If we are skipping keyed nodes then we add the key\n // to a list so that it can be handled at the very end.\n addKeyedRemoval(key);\n } else {\n // Only report the node as discarded if it is not keyed. We do this because\n // at the end we loop through all keyed elements that were unmatched\n // and then discard them in one final pass.\n onNodeDiscarded(curChild);\n if (curChild.firstChild) {\n walkDiscardedChildNodes(curChild, skipKeyedNodes);\n }\n }\n\n curChild = curChild.nextSibling;\n }\n }\n }\n\n /**\n * Removes a DOM node out of the original DOM\n *\n * @param {Node} node The node to remove\n * @param {Node} parentNode The nodes parent\n * @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.\n * @return {undefined}\n */\n function removeNode(node, parentNode, skipKeyedNodes) {\n if (onBeforeNodeDiscarded(node) === false) {\n return;\n }\n\n if (parentNode) {\n parentNode.removeChild(node);\n }\n\n onNodeDiscarded(node);\n walkDiscardedChildNodes(node, skipKeyedNodes);\n }\n\n // // TreeWalker implementation is no faster, but keeping this around in case this changes in the future\n // function indexTree(root) {\n // var treeWalker = document.createTreeWalker(\n // root,\n // NodeFilter.SHOW_ELEMENT);\n //\n // var el;\n // while((el = treeWalker.nextNode())) {\n // var key = getNodeKey(el);\n // if (key) {\n // fromNodesLookup[key] = el;\n // }\n // }\n // }\n\n // // NodeIterator implementation is no faster, but keeping this around in case this changes in the future\n //\n // function indexTree(node) {\n // var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT);\n // var el;\n // while((el = nodeIterator.nextNode())) {\n // var key = getNodeKey(el);\n // if (key) {\n // fromNodesLookup[key] = el;\n // }\n // }\n // }\n\n function indexTree(node) {\n if (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE$1) {\n var curChild = node.firstChild;\n while (curChild) {\n var key = getNodeKey(curChild);\n if (key) {\n fromNodesLookup[key] = curChild;\n }\n\n // Walk recursively\n indexTree(curChild);\n\n curChild = curChild.nextSibling;\n }\n }\n }\n\n indexTree(fromNode);\n\n function handleNodeAdded(el) {\n onNodeAdded(el);\n\n var curChild = el.firstChild;\n while (curChild) {\n var nextSibling = curChild.nextSibling;\n\n var key = getNodeKey(curChild);\n if (key) {\n var unmatchedFromEl = fromNodesLookup[key];\n // if we find a duplicate #id node in cache, replace `el` with cache value\n // and morph it to the child node.\n if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) {\n curChild.parentNode.replaceChild(unmatchedFromEl, curChild);\n morphEl(unmatchedFromEl, curChild);\n } else {\n handleNodeAdded(curChild);\n }\n } else {\n // recursively call for curChild and it's children to see if we find something in\n // fromNodesLookup\n handleNodeAdded(curChild);\n }\n\n curChild = nextSibling;\n }\n }\n\n function cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey) {\n // We have processed all of the \"to nodes\". If curFromNodeChild is\n // non-null then we still have some from nodes left over that need\n // to be removed\n while (curFromNodeChild) {\n var fromNextSibling = curFromNodeChild.nextSibling;\n if ((curFromNodeKey = getNodeKey(curFromNodeChild))) {\n // Since the node is keyed it might be matched up later so we defer\n // the actual removal to later\n addKeyedRemoval(curFromNodeKey);\n } else {\n // NOTE: we skip nested keyed nodes from being removed since there is\n // still a chance they will be matched up later\n removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);\n }\n curFromNodeChild = fromNextSibling;\n }\n }\n\n function morphEl(fromEl, toEl, childrenOnly) {\n var toElKey = getNodeKey(toEl);\n\n if (toElKey) {\n // If an element with an ID is being morphed then it will be in the final\n // DOM so clear it out of the saved elements collection\n delete fromNodesLookup[toElKey];\n }\n\n if (!childrenOnly) {\n // optional\n if (onBeforeElUpdated(fromEl, toEl) === false) {\n return;\n }\n\n // update attributes on original DOM element first\n morphAttrs(fromEl, toEl);\n // optional\n onElUpdated(fromEl);\n\n if (onBeforeElChildrenUpdated(fromEl, toEl) === false) {\n return;\n }\n }\n\n if (fromEl.nodeName !== 'TEXTAREA') {\n morphChildren(fromEl, toEl);\n } else {\n specialElHandlers.TEXTAREA(fromEl, toEl);\n }\n }\n\n function morphChildren(fromEl, toEl) {\n var skipFrom = skipFromChildren(fromEl);\n var curToNodeChild = toEl.firstChild;\n var curFromNodeChild = fromEl.firstChild;\n var curToNodeKey;\n var curFromNodeKey;\n\n var fromNextSibling;\n var toNextSibling;\n var matchingFromEl;\n\n // walk the children\n outer: while (curToNodeChild) {\n toNextSibling = curToNodeChild.nextSibling;\n curToNodeKey = getNodeKey(curToNodeChild);\n\n // walk the fromNode children all the way through\n while (!skipFrom && curFromNodeChild) {\n fromNextSibling = curFromNodeChild.nextSibling;\n\n if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) {\n curToNodeChild = toNextSibling;\n curFromNodeChild = fromNextSibling;\n continue outer;\n }\n\n curFromNodeKey = getNodeKey(curFromNodeChild);\n\n var curFromNodeType = curFromNodeChild.nodeType;\n\n // this means if the curFromNodeChild doesnt have a match with the curToNodeChild\n var isCompatible = undefined;\n\n if (curFromNodeType === curToNodeChild.nodeType) {\n if (curFromNodeType === ELEMENT_NODE) {\n // Both nodes being compared are Element nodes\n\n if (curToNodeKey) {\n // The target node has a key so we want to match it up with the correct element\n // in the original DOM tree\n if (curToNodeKey !== curFromNodeKey) {\n // The current element in the original DOM tree does not have a matching key so\n // let's check our lookup to see if there is a matching element in the original\n // DOM tree\n if ((matchingFromEl = fromNodesLookup[curToNodeKey])) {\n if (fromNextSibling === matchingFromEl) {\n // Special case for single element removals. To avoid removing the original\n // DOM node out of the tree (since that can break CSS transitions, etc.),\n // we will instead discard the current node and wait until the next\n // iteration to properly match up the keyed target element with its matching\n // element in the original tree\n isCompatible = false;\n } else {\n // We found a matching keyed element somewhere in the original DOM tree.\n // Let's move the original DOM node into the current position and morph\n // it.\n\n // NOTE: We use insertBefore instead of replaceChild because we want to go through\n // the `removeNode()` function for the node that is being discarded so that\n // all lifecycle hooks are correctly invoked\n fromEl.insertBefore(matchingFromEl, curFromNodeChild);\n\n // fromNextSibling = curFromNodeChild.nextSibling;\n\n if (curFromNodeKey) {\n // Since the node is keyed it might be matched up later so we defer\n // the actual removal to later\n addKeyedRemoval(curFromNodeKey);\n } else {\n // NOTE: we skip nested keyed nodes from being removed since there is\n // still a chance they will be matched up later\n removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);\n }\n\n curFromNodeChild = matchingFromEl;\n }\n } else {\n // The nodes are not compatible since the \"to\" node has a key and there\n // is no matching keyed node in the source tree\n isCompatible = false;\n }\n }\n } else if (curFromNodeKey) {\n // The original has a key\n isCompatible = false;\n }\n\n isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild);\n if (isCompatible) {\n // We found compatible DOM elements so transform\n // the current \"from\" node to match the current\n // target DOM node.\n // MORPH\n morphEl(curFromNodeChild, curToNodeChild);\n }\n\n } else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {\n // Both nodes being compared are Text or Comment nodes\n isCompatible = true;\n // Simply update nodeValue on the original node to\n // change the text value\n if (curFromNodeChild.nodeValue !== curToNodeChild.nodeValue) {\n curFromNodeChild.nodeValue = curToNodeChild.nodeValue;\n }\n\n }\n }\n\n if (isCompatible) {\n // Advance both the \"to\" child and the \"from\" child since we found a match\n // Nothing else to do as we already recursively called morphChildren above\n curToNodeChild = toNextSibling;\n curFromNodeChild = fromNextSibling;\n continue outer;\n }\n\n // No compatible match so remove the old node from the DOM and continue trying to find a\n // match in the original DOM. However, we only do this if the from node is not keyed\n // since it is possible that a keyed node might match up with a node somewhere else in the\n // target tree and we don't want to discard it just yet since it still might find a\n // home in the final DOM tree. After everything is done we will remove any keyed nodes\n // that didn't find a home\n if (curFromNodeKey) {\n // Since the node is keyed it might be matched up later so we defer\n // the actual removal to later\n addKeyedRemoval(curFromNodeKey);\n } else {\n // NOTE: we skip nested keyed nodes from being removed since there is\n // still a chance they will be matched up later\n removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);\n }\n\n curFromNodeChild = fromNextSibling;\n } // END: while(curFromNodeChild) {}\n\n // If we got this far then we did not find a candidate match for\n // our \"to node\" and we exhausted all of the children \"from\"\n // nodes. Therefore, we will just append the current \"to\" node\n // to the end\n if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) {\n // MORPH\n if(!skipFrom){ addChild(fromEl, matchingFromEl); }\n morphEl(matchingFromEl, curToNodeChild);\n } else {\n var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild);\n if (onBeforeNodeAddedResult !== false) {\n if (onBeforeNodeAddedResult) {\n curToNodeChild = onBeforeNodeAddedResult;\n }\n\n if (curToNodeChild.actualize) {\n curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc);\n }\n addChild(fromEl, curToNodeChild);\n handleNodeAdded(curToNodeChild);\n }\n }\n\n curToNodeChild = toNextSibling;\n curFromNodeChild = fromNextSibling;\n }\n\n cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey);\n\n var specialElHandler = specialElHandlers[fromEl.nodeName];\n if (specialElHandler) {\n specialElHandler(fromEl, toEl);\n }\n } // END: morphChildren(...)\n\n var morphedNode = fromNode;\n var morphedNodeType = morphedNode.nodeType;\n var toNodeType = toNode.nodeType;\n\n if (!childrenOnly) {\n // Handle the case where we are given two DOM nodes that are not\n // compatible (e.g. <div> --> <span> or <div> --> TEXT)\n if (morphedNodeType === ELEMENT_NODE) {\n if (toNodeType === ELEMENT_NODE) {\n if (!compareNodeNames(fromNode, toNode)) {\n onNodeDiscarded(fromNode);\n morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI));\n }\n } else {\n // Going from an element node to a text node\n morphedNode = toNode;\n }\n } else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) { // Text or comment node\n if (toNodeType === morphedNodeType) {\n if (morphedNode.nodeValue !== toNode.nodeValue) {\n morphedNode.nodeValue = toNode.nodeValue;\n }\n\n return morphedNode;\n } else {\n // Text node to something else\n morphedNode = toNode;\n }\n }\n }\n\n if (morphedNode === toNode) {\n // The \"to node\" was not compatible with the \"from node\" so we had to\n // toss out the \"from node\" and use the \"to node\"\n onNodeDiscarded(fromNode);\n } else {\n if (toNode.isSameNode && toNode.isSameNode(morphedNode)) {\n return;\n }\n\n morphEl(morphedNode, toNode, childrenOnly);\n\n // We now need to loop over any keyed nodes that might need to be\n // removed. We only do the removal if we know that the keyed node\n // never found a match. When a keyed node is matched up we remove\n // it out of fromNodesLookup and we use fromNodesLookup to determine\n // if a keyed node has been matched up or not\n if (keyedRemovalList) {\n for (var i=0, len=keyedRemovalList.length; i<len; i++) {\n var elToRemove = fromNodesLookup[keyedRemovalList[i]];\n if (elToRemove) {\n removeNode(elToRemove, elToRemove.parentNode, false);\n }\n }\n }\n }\n\n if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {\n if (morphedNode.actualize) {\n morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc);\n }\n // If we had to swap out the from node with a new node because the old\n // node was not compatible with the target node then we need to\n // replace the old DOM node in the original DOM tree. This is only\n // possible if the original DOM node was part of a DOM tree which\n // we know is the case if it has a parent node.\n fromNode.parentNode.replaceChild(morphedNode, fromNode);\n }\n\n return morphedNode;\n };\n}\n\nvar morphdom = morphdomFactory(morphAttrs);\n\nexport default morphdom;\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 morphdom from 'morphdom'\n\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, $scopes }) {\n\n\tconst tplid = elm.getAttribute('tplid')\n\tconst options = getOptions( module )\n\tconst initialState = (new Function( `return ${elm.getAttribute('html-model') || '{}'}`))()\n\tconst selector = Object.keys(components).toString()\n\tbuildtemplates( elm, selector, templates, $scopes )\n\n\tconst template = tplid ? templates[tplid] : null\n\tconst state = { data: module.model ? dup(module.model) : {} }\n\tconst scope = $scopes[tplid] && $scopes[tplid].length? $scopes[tplid].shift() : {}\n\tstate.data = Object.assign(scope, 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 = base.template.call(options.view(newdata), elm, safe, $scopes)\n\n\t\t\tmorphdom(elm, newhtml, morphdomOptions(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 data = Object.assign( child.base.state.getRaw(), newdata)\n\t\t\t\t\t\tchild.options.onupdate(data)\n\t\t\t\t\t\tchild.base.render(data)\n\t\t\t\t\t})\n\t\t\t})\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 morphdomOptions = (_parent ) => ({\n\tonNodeAdded: onUpdates,\n\tonElUpdated: onUpdates,\n\tonBeforeElChildrenUpdated: checkStatic,\n\tonBeforeElUpdated: checkStatic\n})\n\nconst checkStatic = (node) => {\n\tif ('html-static' in node.attributes) {\n\t\treturn false\n\t}\n}\n\nconst onUpdates = (node) => {\n\tif (node.nodeType === 1) {\n\t\tif ( node.getAttribute('tplid') ) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn node\n}\n","import Component from './component'\nimport { purge, rAF } from './utils'\n\nexport default function Element(module, dependencies, templates, components, $scopes) {\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\n\t\t\tsuper()\n\t\t\tconst { base, options } = Component(this, { module, dependencies, templates, components, $scopes })\n\n\t\t\tthis.base = base\n\t\t\tthis.options = options\n\t\t\tthis.returns = module.default(base)\n\t\t}\n\n\t\tconnectedCallback() {\n\n\t\t\tthis.base.render()\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\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\n\t\t}\n\n\t\tattributeChangedCallback() {\n\t\t\t//TODO\n\t\t}\n\t}\n}\n","import { type Module } from '..'\nimport { templateConfig, buildtemplates } from './template-system'\nimport { publish, subscribe } from './utils/pubsub'\nimport { html } from './utils'\nimport Element from './element'\n\nconst templates = {}\nconst components = {}\nconst $scopes = {}\n\nexport { html }\n\nexport default {\n\n\ttemplateConfig,\n\n\tpublish,\n\tsubscribe,\n\n\tregister( name:string, module: Module, dependencies: object ) {\n\t\tcomponents[name] = { name, module, dependencies }\n\t},\n\n\tstart( target = document.body ) {\n\t\tconst selector = Object.keys(components).toString()\n\t\tbuildtemplates( target, selector, templates, $scopes )\n\t\tregisterComponents()\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\tconst Base = Element(module, dependencies, templates, components, $scopes)\n\t\t\tcustomElements.define(name, Base)\n\t\t})\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","$scopes","html","regexTags","RegExp","virtual","parseFromString","replace","querySelectorAll","forEach","htmlForeach","getAttribute","htmlFor","htmlIf","htmlInner","htmlClass","forEachInstruction","selector","split","match","varname","object","removeAttribute","ids","Array","from","map","cp","tplid","createTextNode","className","trim","body","all","key","Transpile","outerHTML","decodedHTML","Function","_","variable","buildtemplates","target","templates","reverse","template","content","createTemplateId","id","c","r","Math","random","toString","setAttribute","topics","_async","publish","params","Object","assign","topic","subscribe","method","push","filter","range","NS_XHTML","doc","HAS_TEMPLATE_SUPPORT","HAS_RANGE_SUPPORT","createRange","toElement","str","createFragmentFromTemplate","selectNode","createContextualFragment","createFragmentFromRange","fragment","createFragmentFromWrap","compareNodeNames","fromEl","toEl","fromCodeStart","toCodeStart","fromNodeName","nodeName","toNodeName","charCodeAt","toUpperCase","syncBooleanAttrProp","specialElHandlers","OPTION","parentName","hasAttribute","selected","selectedIndex","INPUT","TEXTAREA","newValue","firstChild","oldValue","nodeValue","placeholder","SELECT","optgroup","curChild","noop","defaultGetNodeKey","morphAttrs","morphdom","fromNode","toNode","attr","attrName","attrNamespaceURI","attrValue","toNodeAttrs","nodeType","namespaceURI","localName","getAttributeNS","prefix","setAttributeNS","fromNodeAttrs","hasAttributeNS","removeAttributeNS","options","toNodeHtml","firstElementChild","getNodeKey","onBeforeNodeAdded","onNodeAdded","onBeforeElUpdated","onElUpdated","onBeforeNodeDiscarded","onNodeDiscarded","onBeforeElChildrenUpdated","skipFromChildren","addChild","parent","child","appendChild","childrenOnly","fromNodesLookup","create","keyedRemovalList","addKeyedRemoval","walkDiscardedChildNodes","skipKeyedNodes","removeNode","removeChild","handleNodeAdded","el","unmatchedFromEl","replaceChild","morphEl","toElKey","curToNodeKey","curFromNodeKey","fromNextSibling","toNextSibling","matchingFromEl","skipFrom","curToNodeChild","curFromNodeChild","outer","isSameNode","curFromNodeType","isCompatible","onBeforeNodeAddedResult","actualize","ownerDocument","cleanupFromEl","specialElHandler","morphChildren","indexTree","morphedNode","morphedNodeType","toNodeType","nextChild","moveChildren","createElementNS","len","elToRemove","customEvent","window","CustomEvent","data","newEvent","createEvent","initCustomEvent","handler","ev","e","scope","this","detail","__events","apply","concat","args","removeListener","listener","removeEventListener","delegate","callback","matches","delegateTarget","on","selectorOrCallback","addEventListener","call","off","old","trigger","dispatchEvent","bubbles","getOptions","module","main","unmount","onupdate","view","morphdomOptions","_parent","onUpdates","checkStatic","Element","dependencies","components","HTMLElement","constructor","base","elm","initialState","keys","state","model","shift","eventName","String","children","emit","set","newstate","render","Promise","resolve","get","getRaw","contains","newdata","newhtml","Component","returns","default","connectedCallback","then","array","f","disconnectedCallback","attributeChangedCallback","index","templateConfig","newconfig","register","start","registerComponents","values","component","Base","customElements","define","literalSections","substs","raw","result","subst","lit","isArray","join"],"mappings":"6OAAM,MAAAA,EAAS,IAAIC,UAwEnB,MAAMC,EAAO,CAACC,EAAMC,EAAMC,aACpB,OAAAC,EAAAF,EAAAG,aAAYD,EAAAE,aAAaL,EAAMC,GACpC,OAAAK,EAAAL,EAAKG,aAALE,EAAiBD,aAAaH,EAAOD,EAAKM,YAAA,EC1ErCC,EAAWC,SAASC,cAAc,YAE3BC,EAAcC,IAC1BJ,EAASK,UAAYD,EACdJ,EAASM,OAGJC,EAAOC,GACfC,sBACIA,sBAAsBD,GAEtBE,WAAWF,EAAI,IAAO,IAWlBG,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,EAC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Q,EAAS,EMQ/BhN,UACAK,YAEA,QAAA4M,CAAUnR,EAAaoO,EAAgBU,GACtCC,EAAW/O,GAAQ,CAAEA,OAAMoO,OAAAA,EAAQU,eACpC,EAEA,KAAAsC,CAAOjO,EAAS1E,SAASgE,MACxB,MAAMf,EAAW0C,OAAOiL,KAAKN,GAAYjL,WACzBZ,EAAAC,EAAQzB,EAAU0B,EAAW1C,MAE9C,GAGK2Q,EAAqB,KAC1BjN,OACEkN,OAAQvC,GACR7N,SAAUqQ,IACV,MAAMvR,KAAEA,EAAMoO,OAAAA,EAAAA,aAAQU,GAAiByC,EACjCC,EAAO3C,EAAQT,EAAQU,EAAc1L,EAAW2L,EAAYrO,GACnD+Q,eAAAC,OAAO1R,EAAMwR,EAAI,GAChC,qBPeiB,CAACG,KAAoBC,KAIxC,IAAIC,EAAMF,EAAgBE,IAEtBC,EAAS,GAsBN,OApBAF,EAAA1Q,SAAQ,CAAC6Q,EAAOrS,KAGlB,IAAAsS,EAAMH,EAAInS,GAKVuC,MAAMgQ,QAAQF,KACTA,EAAAA,EAAMG,KAAK,KAGVJ,GAAAE,EACAF,GAAAC,CAAA,IAKDD,GAAAD,EAAIA,EAAI9R,OAAO,GAElB+R,CAAA","x_google_ignoreList":[4]}
|
package/index.d.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
type EventCallback = ( Event: Event, data?:any ) => void
|
2
|
+
|
3
|
+
declare const html = ( value :string ) => string
|
1
4
|
|
2
5
|
declare const _default: {
|
3
6
|
publish( subject: string, data :any )
|
@@ -8,6 +11,7 @@ declare const _default: {
|
|
8
11
|
}
|
9
12
|
|
10
13
|
export default _default
|
14
|
+
export const html
|
11
15
|
|
12
16
|
export type Module = {
|
13
17
|
default: ((component:Component) => Promise<void> | void )
|
@@ -27,7 +31,7 @@ export type Component = {
|
|
27
31
|
getRaw() : object
|
28
32
|
}
|
29
33
|
|
30
|
-
main( mainArgs: ( t: Component ) => Array<Function> ): void
|
34
|
+
main( mainArgs: ( t: Component ) => Array<Function> | void ): void
|
31
35
|
|
32
36
|
publish( name: string, value: any ) : void
|
33
37
|
|
@@ -39,7 +43,7 @@ export type Component = {
|
|
39
43
|
|
40
44
|
onupdate( callback: () => void ) : void
|
41
45
|
|
42
|
-
on( eventName: string, selector: string, callback?:
|
46
|
+
on( eventName: string, selector: string | EventCallback, callback?: EventCallback ): void
|
43
47
|
|
44
48
|
emit( eventName: string, data: any ) : void
|
45
49
|
|
@@ -55,3 +59,5 @@ export type Model = {
|
|
55
59
|
}
|
56
60
|
|
57
61
|
export type View = ( state: object ) => object
|
62
|
+
|
63
|
+
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -59,16 +59,12 @@ Jails was designed to be:
|
|
59
59
|
|
60
60
|
`components/counter/index.ts`
|
61
61
|
```ts
|
62
|
-
export default function appCounter({ main, state ) {
|
62
|
+
export default function appCounter({ main, on, state ) {
|
63
63
|
|
64
|
-
main( _ =>
|
65
|
-
events
|
66
|
-
])
|
67
|
-
|
68
|
-
const events = ({ on }) => {
|
64
|
+
main( _ => {
|
69
65
|
on('click', '[data-add]', add)
|
70
66
|
on('click', '[data-subtract]', subtract)
|
71
|
-
}
|
67
|
+
})
|
72
68
|
|
73
69
|
const add = () => {
|
74
70
|
state.set( s => s.count+= 1 )
|
package/src/component.ts
CHANGED
@@ -11,8 +11,8 @@ export default function Component( elm, { module, dependencies, templates, compo
|
|
11
11
|
const tplid = elm.getAttribute('tplid')
|
12
12
|
const options = getOptions( module )
|
13
13
|
const initialState = (new Function( `return ${elm.getAttribute('html-model') || '{}'}`))()
|
14
|
-
|
15
|
-
buildtemplates( elm,
|
14
|
+
const selector = Object.keys(components).toString()
|
15
|
+
buildtemplates( elm, selector, templates, $scopes )
|
16
16
|
|
17
17
|
const template = tplid ? templates[tplid] : null
|
18
18
|
const state = { data: module.model ? dup(module.model) : {} }
|
package/src/element.ts
CHANGED
@@ -26,12 +26,20 @@ export default function Element(module, dependencies, templates, components, $sc
|
|
26
26
|
|
27
27
|
if( this.returns && this.returns.constructor === Promise ) {
|
28
28
|
this.returns.then( _ => {
|
29
|
-
if( this.base
|
30
|
-
this.options.main(
|
29
|
+
if( this.base && this.options.main) {
|
30
|
+
const array = this.options.main(this.base)
|
31
|
+
if( array && array.length ){
|
32
|
+
array.forEach(f => f(this.base))
|
33
|
+
}
|
31
34
|
}
|
32
35
|
})
|
33
36
|
}else {
|
34
|
-
this.options.main
|
37
|
+
if( this.base && this.options.main ){
|
38
|
+
const array = this.options.main(this.base)
|
39
|
+
if( array && array.length ) {
|
40
|
+
array.forEach(f => f(this.base))
|
41
|
+
}
|
42
|
+
}
|
35
43
|
}
|
36
44
|
}
|
37
45
|
|
package/src/index.ts
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
import { type Module } from '..'
|
2
2
|
import { templateConfig, buildtemplates } from './template-system'
|
3
3
|
import { publish, subscribe } from './utils/pubsub'
|
4
|
+
import { html } from './utils'
|
4
5
|
import Element from './element'
|
5
6
|
|
6
7
|
const templates = {}
|
7
8
|
const components = {}
|
8
9
|
const $scopes = {}
|
9
10
|
|
11
|
+
export { html }
|
12
|
+
|
10
13
|
export default {
|
11
14
|
|
12
15
|
templateConfig,
|
@@ -19,7 +22,8 @@ export default {
|
|
19
22
|
},
|
20
23
|
|
21
24
|
start( target = document.body ) {
|
22
|
-
|
25
|
+
const selector = Object.keys(components).toString()
|
26
|
+
buildtemplates( target, selector, templates, $scopes )
|
23
27
|
registerComponents()
|
24
28
|
}
|
25
29
|
}
|
package/src/template-system.ts
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
import Transpile from './transpile'
|
2
|
-
import { uuid } from './utils'
|
3
|
-
|
4
|
-
const textarea = document.createElement('textarea')
|
2
|
+
import { uuid, decodeHTML } from './utils'
|
5
3
|
|
6
4
|
const config = {
|
7
5
|
tags: ['${', '}']
|
@@ -14,29 +12,28 @@ export const templateConfig = (newconfig) => {
|
|
14
12
|
export default function Template(element, $scopes) {
|
15
13
|
|
16
14
|
const html = Transpile(element.outerHTML, config, $scopes)
|
17
|
-
|
18
|
-
const decodedHTML = JSON.stringify(textarea.value)
|
15
|
+
const decodedHTML = JSON.stringify(html)
|
19
16
|
|
20
17
|
return new Function('$element', 'safe', '$scopes',`
|
21
18
|
var $data = this;
|
22
19
|
with( $data ){
|
23
20
|
var output=${decodedHTML
|
24
|
-
.replace(/%%_=(.+?)_%%/g,
|
25
|
-
|
21
|
+
.replace(/%%_=(.+?)_%%/g, function(_, variable){
|
22
|
+
return '"+safe(function(){return '+decodeHTML(variable)+';})+"'
|
23
|
+
})
|
24
|
+
.replace(/%%_(.+?)_%%/g, function(_, variable){
|
25
|
+
return '";' + decodeHTML(variable) +'\noutput+="'
|
26
|
+
})};return output;
|
26
27
|
}
|
27
28
|
`)
|
28
29
|
}
|
29
30
|
|
30
|
-
export const buildtemplates = ( target,
|
31
|
-
|
32
|
-
.from(target.querySelectorAll('*'))
|
33
|
-
.filter((node:HTMLElement) => node.tagName.toLowerCase() in components)
|
31
|
+
export const buildtemplates = ( target, selector, templates, $scopes ) => {
|
32
|
+
Array.from(target.querySelectorAll( selector ))
|
34
33
|
.reverse()
|
35
|
-
.
|
36
|
-
|
37
|
-
.map((template) => buildtemplates(template.content, components, templates, $scopes))
|
34
|
+
.forEach( (node:HTMLElement) => {
|
35
|
+
node.querySelectorAll('template').forEach( template => buildtemplates(template.content, selector, templates, $scopes))
|
38
36
|
createTemplateId(node, templates, $scopes)
|
39
|
-
return node
|
40
37
|
})
|
41
38
|
}
|
42
39
|
|
package/src/transpile.ts
CHANGED
package/src/utils/index.ts
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
const textarea = document.createElement('textarea')
|
2
|
+
|
3
|
+
export const decodeHTML = (text) => {
|
4
|
+
textarea.innerHTML = text
|
5
|
+
return textarea.value
|
6
|
+
}
|
7
|
+
|
1
8
|
export const rAF = (fn) => {
|
2
9
|
if (requestAnimationFrame)
|
3
10
|
return requestAnimationFrame(fn)
|
@@ -40,3 +47,36 @@ export const purge = (d) => {
|
|
40
47
|
export const safe = (execute, val) => {
|
41
48
|
try{return execute()}catch(err){return val || ''}
|
42
49
|
}
|
50
|
+
|
51
|
+
// From
|
52
|
+
// https://2ality.com/2015/01/template-strings-html.html#comment-2078932192
|
53
|
+
export const html = (literalSections, ...substs) => {
|
54
|
+
|
55
|
+
// Use raw literal sections: we don’t want
|
56
|
+
// backslashes (\n etc.) to be interpreted
|
57
|
+
let raw = literalSections.raw
|
58
|
+
|
59
|
+
let result = ''
|
60
|
+
|
61
|
+
substs.forEach((subst, i) => {
|
62
|
+
// Retrieve the literal section preceding
|
63
|
+
// the current substitution
|
64
|
+
let lit = raw[i]
|
65
|
+
|
66
|
+
// In the example, map() returns an array:
|
67
|
+
// If substitution is an array (and not a string),
|
68
|
+
// we turn it into a string
|
69
|
+
if (Array.isArray(subst)) {
|
70
|
+
subst = subst.join('')
|
71
|
+
}
|
72
|
+
|
73
|
+
result += lit
|
74
|
+
result += subst
|
75
|
+
})
|
76
|
+
// Take care of last literal section
|
77
|
+
// (Never fails, because an empty template string
|
78
|
+
// produces one literal section, an empty string)
|
79
|
+
result += raw[raw.length-1] // (A)
|
80
|
+
|
81
|
+
return result
|
82
|
+
}
|
package/index.html
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8" />
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6
|
-
<link rel="icon" href="/logo.svg" />
|
7
|
-
<title>Testing Library</title>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<script type="module">
|
11
|
-
import jails from '/src/index.ts'
|
12
|
-
console.log(jails)
|
13
|
-
</script>
|
14
|
-
</body>
|
15
|
-
</html>
|