UNPKG

domvm

Version:

DOM ViewModel - A thin, fast, dependency-free vdom view layer

2 lines 24.6 kB
// https://github.com/domvm/domvm (v3.4.14, dev build) var domvm=function(e){"use strict";const t="undefined"!=typeof window?document:{},n={};function l(){}const r=Array.isArray;function o(e){return null!=e&&e.constructor===Object}function a(e,t,n,l){e.splice.apply(e,[n,l].concat(t))}function i(e){return"function"==typeof e}function u(e){for(var t=arguments,n=1;t.length>n;n++)for(var l in t[n])e[l]=t[n][l];return e}function s(e,t){for(var n=[],l=t;e.length>l;l++)n.push(e[l]);return n}function d(e,t){return e===t||null!=t&&null!=e&&(r(e)?function(e,t){const n=e.length;if(t.length!==n)return!1;for(var l=0;n>l;l++)if(e[l]!==t[l])return!1;return!0}(e,t):!!o(e)&&function(e,t){for(var n in e)if(e[n]!==t[n])return!1;return!0}(e,t))}function f(e){return"."===e[0]}function c(e){return"o"===e[0]&&"n"===e[1]}function v(e){return"_"===e[0]}function y(e){return"style"===e}function p(e){e&&e.el&&e.el.getBoundingClientRect()}function m(e){return null!=e.node&&null!=e.node.el}function h(e,t){switch(t){case"value":case"checked":case"selected":return!0}return!1}function g(e){for(e=e||n;null==e.vm&&e.parent;)e=e.parent;return e.vm}function b(){}const w=b.prototype={constructor:b,type:null,vm:null,key:null,ref:null,data:null,hooks:null,ns:null,el:null,tag:null,attrs:null,body:null,flags:0,_diff:null,_dead:!1,_lis:!1,idx:null,parent:null};function k(e){let t=new b;return t.type=2,t.body=e,t}w._class=null;const _={},E=/\[([^=\]]+)=?([^\]]+)?\]/g,x={warnings:!0,verbose:!0,mutations:!0,DATA_REPLACED:function(e,t,n){if(i(e.view)&&e.view.length>1)return["A view's data was replaced. The data originally passed to the view closure during init is now stale. You may want to rely only on the data passed to render() or vm.data.",e,t,n]},UNKEYED_INPUT:function(e){return["Unkeyed <input> detected. Consider adding a name, id, _key, or _ref attr to avoid accidental DOM recycling between different <input> types.",e]},UNMOUNTED_REDRAW:function(e){return["Invoking redraw() of an unmounted (sub)view may result in errors.",e]},INLINE_HANDLER:function(e,t){return["Anonymous inline event handlers get re-created on every redraw, consider defining them outside of templates for better reuse.",e,t]},MISMATCHED_HANDLER:function(e,t,n){return["Patching of different event handler styles is not fully supported for performance reasons. Ensure that handlers are defined using the same style.",e,t,n]},SVG_WRONG_FACTORY:function(e){return["<svg> defined using domvm.defineElement. Use domvm.defineSvgElement for <svg> & child nodes.",e]},FOREIGN_ELEMENT:function(e){return["domvm stumbled upon an element in its DOM that it didn't create, which may be problematic. You can inject external elements into the vtree using domvm.injectElement.",e]},REUSED_ATTRS:function(e){return["Attrs objects may only be reused if they are truly static, as a perf optimization. Mutating & reusing them will have no effect on the DOM due to 0 diff.",e]},ADJACENT_TEXT:function(e,t,n){return["Adjacent text nodes will be merged. Consider concatentating them yourself in the template for improved perf.",e,t,n]},ARRAY_FLATTENED:function(e,t){return["Arrays within templates will be flattened. When they are leading or trailing, it's easy and more performant to just .concat() them in the template.",e,t]},ALREADY_HYDRATED:function(e){return["A child view failed to mount because it was already hydrated. Make sure not to invoke vm.redraw() or vm.update() on unmounted views.",e]},ATTACH_IMPLICIT_TBODY:function(e,t){return["<table><tr> was detected in the vtree, but the DOM will be <table><tbody><tr> after HTML's implicit parsing. You should create the <tbody> vnode explicitly to avoid SSR/attach() failures.",e,t]}};function T(e,t){if(x.warnings&&i(x[e])){var n=x[e].apply(null,t);n&&(n[0]=e+": "+(x.verbose?n[0]:""),console.warn.apply(console,n))}}function N(e,t,n,l){let r=new b;r.type=1,r.flags=l||0,r.attrs=t||null;var o=function(e){var t,n,l,r,o=_[e];if(null==o)for(_[e]=o={tag:(t=e.match(/^[-\w]+/))?t[0]:"div",id:(n=e.match(/#([-\w]+)/))?n[1]:null,class:(l=e.match(/\.([-\w.]+)/))?l[1].replace(/\./g," "):null,attrs:null};r=E.exec(e);)null==o.attrs&&(o.attrs={}),o.attrs[r[1]]=r[2]||"";return o}(e);e=o.tag;var a=null!=o.id,i=null!=o.class,u=null!=o.attrs;if(a||i||u){var s=r.attrs||{};if(a&&null==s.id&&(s.id=o.id),i&&(r._class=o.class,s.class=o.class+(null!=s.class?" "+s.class:"")),u)for(var d in o.attrs)null==s[d]&&(s[d]=o.attrs[d]);r.attrs=s}if(r.tag=e,null!=r.attrs){var f=r.attrs;null!=f._key&&(r.key=f._key),null!=f._ref&&(r.ref=f._ref),null!=f._hooks&&(r.hooks=f._hooks),null!=f._data&&(r.data=f._data),null!=f._flags&&(r.flags=f._flags),null==r.key&&(null!=r.ref?r.key=r.ref:null!=f.id?r.key=f.id:null!=f.name&&(r.key=f.name+("radio"===f.type||"checkbox"===f.type?f.value:"")))}return null!=n&&(r.body=n,n instanceof A&&(r.flags=n.flags)),"svg"===r.tag?setTimeout((function(){null==r.ns&&T("SVG_WRONG_FACTORY",[r])}),16):/^(?:input|textarea|select|datalist|output)$/.test(r.tag)&&null==r.key&&T("UNKEYED_INPUT",[r]),r}function A(e,t,n){var l,r=this,o=e.length;r.flags=8,r.items=e,r.length=o,r.key=()=>null,r.diff={val:function(n,l){return t.val(e[n],l)},eq:function(e,n){return t.eq(n._diff,r.diff.val(e))}},r.tpl=t=>l(e[t],t),r.map=e=>(l=e,r),r.body=function(e){for(var t=[],n=0;o>n;n++){var l=r.tpl(n);4!=l.type&&(l._diff=r.diff.val(n,e)),t.push(l)}e.body=t,Y(e)},null!=n&&(r.flags|=4,r.key=t=>n(e[t],t)),i(t)&&(r.diff={val:function(n){return t(e[n])},eq:function(e,t){return d(t._diff,r.diff.val(e))}})}let D=function(e){return e},R=l,C=l;var M={};let S=l,I=!1,L=l,O=l;function H(e){S=e.onevent||S,null!=e.onvnode&&(O=e.onvnode),null!=e.syncRedraw&&(I=e.syncRedraw),null!=e.didRedraws&&(L=e.didRedraws),e.onemit&&function(e){u(M,e)}(e.onemit),e.stream&&function(e){D=e.val,R=e.on,C=e.off}(e.stream)}function U(e,t,n,l){if(O(e,t,n,l),5!==e.type&&4!==e.type){e.parent=t,e.idx=n,e.vm=l,null!=e.ref&&function(e,t,n){!function(e,t,n){for(var l;l=t.shift();)e[l]=0===t.length?n:e=e[l]||{}}(e,("refs."+t).split("."),n)}(g(e),e.ref,e);var o=e.hooks,a=l&&l.hooks;(o&&(o.willRemove||o.didRemove)||a&&(a.willUnmount||a.didUnmount))&&function(e){for(;e=e.parent;)e.flags|=1}(e),r(e.body)?Y(e):""===e.body?e.body=null:(e.body=D(e.body,g(e)._stream),null==e.body||e.body instanceof A||(e.body=""+e.body))}}function Y(e){for(var t=e.body,n=0;t.length>n;n++){var l=t[n];!1===l||null==l?t.splice(n--,1):r(l)?(0!==n&&n!==t.length-1||T("ARRAY_FLATTENED",[e,l]),a(t,l,n--,1)):(null==l.type&&(t[n]=l=k(l)),2===l.type?null==l.body||""===l.body?t.splice(n--,1):n>0&&2===t[n-1].type?(T("ADJACENT_TEXT",[e,t[n-1].body,l.body]),t[n-1].body+=l.body,t.splice(n--,1)):U(l,e,n,null):U(l,e,n,null))}}const V={animationIterationCount:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridRow:!0,gridColumn:!0,order:!0,lineClamp:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0};function j(e,t){return isNaN(t)||V[e]?t:t+"px"}function F(e,t){var l=(e.attrs||n).style,r=t?(t.attrs||n).style:null;if(null==l||function(e){var t=typeof e;return"string"===t||"number"===t}(l))e.el.style.cssText=l;else{for(var o in l){var a=l[o];l[o]=a=D(a,g(e)._stream),(null==r||null!=a&&a!==r[o])&&(e.el.style[o]=j(o,a))}if(r)for(var i in r)null==l[i]&&(e.el.style[i]="")}}function P(e){let t=e.currentTarget,l=t._node.attrs["on"+e.type];if(r(l)){let r,o,a=l[0],i=l.slice(1),u=function(e){for(e=e||n;null==e._node&&e.parentNode;)e=e.parent;return e._node}(e.target),s=g(u),d=a.apply(t,i.concat([e,u,s,s.data]));r=s.onevent(e,u,s,s.data,i),o=S(e,u,s,s.data,i),!1!==d&&!1!==r&&!1!==o||e.preventDefault()}else l.call(t,e)}function G(e,t,n,l){if(n==l)return;null==n||i(n)||r(n)||T("INVALID_HANDLER",[e,n]),i(n)&&""==n.name&&T("INLINE_HANDLER",[e,n]);let o=e.el;null==n?o.removeEventListener(t.slice(2),P):null==l&&o.addEventListener(t.slice(2),P)}function q(e,t,n){f(t)&&(t=t.substr(1),n=!0),n?e.el[t]="":e.el.removeAttribute(t)}function W(e,t,n,l){var r=e.el;null!=e.ns?r.setAttribute(t,n):"class"===t?r.className=n:"id"===t||"boolean"==typeof n||l?r[t]=n:"."===t[0]?r[t.substr(1)]=n:r.setAttribute(t,n)}function B(e,t){const l=e.attrs||n,r=t.attrs||n;if(l===r)T("REUSED_ATTRS",[e]);else{for(var o in l){var a=l[o];if(null!=a){var i=h(0,o),u=i?e.el[o]:r[o];l[o]=a=D(a,(g(e)||n)._stream),a===u||(y(o)?F(e,t):v(o)||(c(o)?G(e,o,a,u):W(e,o,a,i)))}}for(var o in r)null==l[o]&&(c(o)?G(e,o,l[o],r[o]):v(o)||q(e,o,h(0,o)))}}function z(e,t,n,l){return 4===e.type&&(t=e.data,n=e.key,l=e.opts,e=e.view),new Ee(e,t,n,l)}const K=[];function X(e,t,n,l,r){if(null!=e){var o=n.hooks[t];if(o){if("d"!==t[0]||"i"!==t[1]||"d"!==t[2])return o(n,l);r?(p(n.parent),o(n,l)):K.push([o,n,l])}}}function $(e,t){var n;if(K.length)for(t&&p(e.node);n=K.shift();)n[0](n[1],n[2])}function J(e){return e.nextSibling}function Z(e){var t=e.vm,n=null!=t&&X(t.hooks,"willUnmount",t,t.data),l=X(e.hooks,"willRemove",e);if(1==(1&e.flags)&&r(e.body))for(var o=0;e.body.length>o;o++)Z(e.body[o]);return n||l}function Q(e,t){if(t){var n=e.vm;null!=n&&(n.node=n.refs=null)}var l=e.body;if(r(l))for(var o=0;l.length>o;o++)Q(l[o],!0)}function ee(e,t,n){var l=t._node,r=l.vm;if(Q(l,!0),1==(1&l.flags))for(var o=0;l.body.length>o;o++)ee(t,l.body[o].el);delete t._node,e.removeChild(t),X(l.hooks,"didRemove",l,null,n),null!=r&&(X(r.hooks,"didUnmount",r,r.data,n),r.node=null)}function te(e,t){var n=t._node;if(null==n)e.removeChild(t);else{if(n._dead)return;var l=Z(n);null!=l&&function(e){return"object"==typeof e&&i(e.then)}(l)?(n._dead=!0,l.then(function(e,t){return function(){return e.apply(undefined,t)}}(ee,[e,t,!0]))):ee(e,t)}}function ne(e){var t=e.el;if(0==(1&e.flags))Q(e,!1),t.textContent=null;else{var n=t.firstChild;if(null!=n)do{var l=J(n);te(t,n)}while(n=l)}}function le(e,t,n){var l=t._node,r=null!=t.parentNode,o=t!==n&&r?null:l.vm;null!=o&&X(o.hooks,"willMount",o,o.data),X(l.hooks,r?"willReinsert":"willInsert",l),e.insertBefore(t,n),X(l.hooks,r?"didReinsert":"didInsert",l),null!=o&&X(o.hooks,"didMount",o,o.data)}function re(e,t,n){le(e,t,n?J(n):null)}function oe(e){for(var t=0;e.body.length>t;t++){var n=e.body[t],l=n.type;if(l>3){if(4===l)l=(r=z(n.view,n.data,n.key,n.opts)._redraw(e,t,!1)).node.type,le(e.el,ae(r.node));else if(5===l){var r;(r=n.vm)._update(n.data,e,t,!0,!0),l=r.node.type,le(e.el,r.node.el)}}else le(e.el,ae(n))}}function ae(e,l){return null==e.el&&(1===e.type?(e.el=l||function(e,n){return null!=n?t.createElementNS(n,e):t.createElement(e)}(e.tag,e.ns),null!=e.attrs&&B(e,n),8==(8&e.flags)&&e.body.body(e),r(e.body)?oe(e):null!=e.body&&(e.el.textContent=e.body)):2===e.type?e.el=l||function(e){return t.createTextNode(e)}(e.body):3===e.type&&(e.el=l||function(e){return t.createComment(e)}(e.body))),e.el._node=e,e.el}function ie(e,t,n,l,r,o,a,i){return function(u,s,d,f,c,v){var y,p;if(null!=f[l]){if(null==(y=f[l]._node))return T("FOREIGN_ELEMENT",[f[l]]),void(f[l]=e(f[l]));if(function(e){return e.parent}(y)!==u)return p=e(f[l]),null!=y.vm?y.vm.unmount(!0):te(s,f[l]),void(f[l]=p)}if(f[r]==c)return 2;if(null==f[r].el)n(s,ae(f[r]),f[l]),f[r]=t(f[r],d);else if(f[r].el===f[l])f[r]=t(f[r],d),f[l]=e(f[l]);else{if(v||y!==f[a])return null!=f[r].vm&&T("ALREADY_HYDRATED",[f[r].vm]),v&&null!=f[l]?function(e,t,n,l,r,o,a,i,u){if(i._lis)n(o,u[r].el,u[l]),u[r]=t(u[r],a);else{var s=function(e,t){for(var n,l=0,r=t.length-1,o=2147483647>=r;r>=l;){if(t[n=o?l+r>>1:Math.floor((l+r)/2)]===e)return n;e>t[n]?l=n+1:r=n-1}return l==t.length?null:l}(i.idx,u.tombs);i._lis=!0;var d=e(u[l]);n(o,u[l],null!=s?a[u.tombs[s]].el:s),null==s?u.tombs.push(i.idx):u.tombs.splice(s,0,i.idx),u[l]=d}}(e,t,n,l,r,s,d,y,f):1;f[l]=e(p=f[l]),i(s,p,f[o]),f[o]=p}}}var ue=ie(J,(function(e,t){return t[e.idx+1]}),le,"lftSib","lftNode","rgtSib","rgtNode",re),se=ie((function(e){return e.previousSibling}),(function(e,t){return t[e.idx-1]}),re,"rgtSib","rgtNode","lftSib","lftNode",le);function de(e,t,n,l){var r=[],o=t.firstChild;do{var a=o._node;a.parent===e&&r.push(a.idx)}while(o=J(o));for(var i=function(e){const t=e.slice(),n=[];n[0]=0;let l,r,o,a=0,i=0;for(;e.length>i;++i){const u=e[i];if(o=n[a],u>e[o])t[i]=o,n[++a]=i;else{for(l=0,r=a;r>l;)o=l+r>>1,u>e[n[o]]?l=o+1:r=o;e[n[l]]>u&&(l>0&&(t[i]=n[l-1]),n[l]=i)}}for(r=n[a];a>=0;)n[a--]=r,r=t[r];return n}(r).map((e=>r[e])),u=0;i.length>u;u++)n[i[u]]._lis=!0;for(l.tombs=i;2!==ue(e,t,n,l,null,!0););}function fe(e){return e.el._node.parent!==e.parent}function ce(e,t,n){return t[n]}function ve(e,t,n){for(;t.length>n;n++){var l=t[n];if(null!=l.vm){if(4===e.type&&l.vm.view===e.view&&l.vm.key===e.key||5===e.type&&l.vm===e.vm)return l}else if(!fe(l)&&e.tag===l.tag&&e.type===l.type&&e.key===l.key&&(-2&e.flags)==(-2&l.flags))return l}return null}function ye(e,t,n){if(null==t._keys){if(t[n].key===e.key)return t[n];for(var l={},r=0;t.length>r;r++)l[t[r].key]=r;t._keys=l}return t[t._keys[e.key]]}function pe(e,t){X(t.hooks,"willRecycle",t,e);var o=e.el=t.el,a=t.body,i=e.body;if(o._node=e,2!==e.type||i===a){null==e.attrs&&null==t.attrs||B(e,t);var u=r(a),s=r(i);u?s||8==(8&e.flags)?function(e,t){var r=e.body,o=r.length,a=t.body,i=a.length,u=8==(8&e.flags),s=2==(2&e.flags),d=4==(4&e.flags),f=!s&&1===e.type,c=!0,v=0===i?l:d?ye:s||u?ce:ve;if(f&&0===o)return ne(t),void(u&&(e.body=[]));var y,p,h=0,g=!1,b=0;if(u)var w={key:null},k=e.body=Array(o);for(var _=0;o>_;_++){if(u){var E=!1;c&&(d&&(w.key=r.key(_)),y=v(w,a,b)),null!=y?(p=y.idx,r.diff.eq(_,y)?((x=y).parent=e,x.idx=_,x._lis=!1):E=!0):E=!0,E&&(4===(x=r.tpl(_)).type?x=null!=y?y.vm._update(x.data,e,_,!0,!0).node:z(x.view,x.data,x.key,x.opts)._redraw(e,_,!1).node:(U(x,e,_),x._diff=r.diff.val(_,e),null!=y&&pe(x,y))),k[_]=x}else{var x,T=(x=r[_]).type;if(T>3){if(4===T)(y=c&&v(x,a,b))?(p=y.idx,y.vm._update(x.data,e,_,!0,!0)):z(x.view,x.data,x.key,x.opts)._redraw(e,_,!1);else if(5===T){var N=x.vm,A=m(N);A&&N.node.parent!=t&&(N.unmount(!0),A=!1),N._update(x.data,e,_,A,!0)}}else(y=c&&v(x,a,b))&&(pe(x,y),p=y.idx)}if(null!=y&&(p===b?++b===i&&o>i&&(y=null,c=!1):g=!0,!d&&i>100&&g&&++h%10==0))for(;i>b&&fe(a[b]);)b++}f&&function(e,t){var l=t.body,r=e.el,o=e.body,a={lftNode:o[0],rgtNode:o[o.length-1],lftSib:(l[0]||n).el,rgtSib:(l[l.length-1]||n).el};e:for(;;){for(;;){var i=ue(e,r,o,a,null,!1);if(1===i)break;if(2===i)break e}for(;;){var u=se(e,r,o,a,a.lftNode,!1);if(1===u)break;if(2===u)break e}de(e,r,o,a);break}}(e,t)}(e,t):i!==a&&(null!=i?o.textContent=i:ne(t)):s?(ne(t),oe(e)):i!==a&&(null!=i&&null!=a?o.firstChild.nodeValue=i:o.textContent=i),X(t.hooks,"didRecycle",t,e)}else o.nodeValue=i}function me(e,t,n,l){var r,a;return null==n?o(t)?r=t:a=t:(r=t,a=n),N(e,r,a,l)}var he=new Set,ge=0;function be(){he.forEach((e=>{if(null!=e.node){for(var t=e;t=t.parent();)if(he.has(t))return;e.redraw(!0)}})),L(he),he.clear(),ge=0}var we=null;x.mutations&&(we=new function(){navigator.userAgent.indexOf("Edge");var e=-1!==navigator.userAgent.indexOf("Trident/"),t=Object.getOwnPropertyDescriptor,n=Object.defineProperty,l=Node.prototype,r=t(l,"textContent"),o=t(l,"nodeValue"),a=HTMLElement.prototype,i=t(a,"innerText"),u=Element.prototype,s=t(e?a:u,"innerHTML"),d=t(e?a:u,"className"),f=t(e?a:u,"id"),c=CSSStyleDeclaration.prototype,v=t(c,"cssText"),y=HTMLInputElement.prototype,p=HTMLTextAreaElement.prototype,m=HTMLSelectElement.prototype,h=HTMLOptionElement.prototype,g=t(y,"checked"),b=t(y,"value"),w=t(p,"value"),k=t(m,"value"),_=t(m,"selectedIndex"),E=t(h,"selected"),x={"document.createElement":null,"document.createElementNS":null,"document.createTextNode":null,"document.createComment":null,"document.createDocumentFragment":null,"DocumentFragment.prototype.insertBefore":null,"Element.prototype.appendChild":null,"Element.prototype.removeChild":null,"Element.prototype.insertBefore":null,"Element.prototype.replaceChild":null,"Element.prototype.remove":null,"Element.prototype.setAttribute":null,"Element.prototype.setAttributeNS":null,"Element.prototype.removeAttribute":null,"Element.prototype.removeAttributeNS":null},T={},N=null;function A(e){for(var t=e.split("."),n=window;t.length>1;)n=n[t.shift()];return{ctx:n,last:t[0]}}for(var D in x){var R=A(D);null===x[D]&&(x[D]=R.ctx[R.last]),function(e,t){T[t]=0,R.ctx[t]=function(){return T[t]++,x[e].apply(this,arguments)}}(D,R.last)}T.textContent=0,n(l,"textContent",{set:function(e){T.textContent++,r.set.call(this,e)}}),T.nodeValue=0,n(l,"nodeValue",{set:function(e){T.nodeValue++,o.set.call(this,e)}}),T.innerText=0,n(a,"innerText",{set:function(e){T.innerText++,i.set.call(this,e)}}),T.innerHTML=0,n(e?a:u,"innerHTML",{set:function(e){T.innerHTML++,s.set.call(this,e)}}),T.className=0,n(e?a:u,"className",{set:function(e){T.className++,d.set.call(this,e)}}),T.cssText=0,n(c,"cssText",{set:function(e){T.cssText++,v.set.call(this,e)}}),T.id=0,n(e?a:u,"id",{set:function(e){T.id++,f.set.call(this,e)}}),T.checked=0,n(y,"checked",{set:function(e){T.checked++,g.set.call(this,e)}}),T.value=0,n(y,"value",{set:function(e){T.value++,b.set.call(this,e)}}),n(p,"value",{set:function(e){T.value++,w.set.call(this,e)}}),n(m,"value",{set:function(e){T.value++,k.set.call(this,e)}}),T.selectedIndex=0,n(m,"selectedIndex",{set:function(e){T.selectedIndex++,_.set.call(this,e)}}),T.selected=0,n(h,"selected",{set:function(e){T.selected++,E.set.call(this,e)}}),this.start=function(){N=+new Date},this.end=function(){var e=+new Date-N;N=null;var t={};for(var n in T)T[n]>0&&(t[n]=T[n]);return function(){for(var e in T)T[e]=0}(),t._time=e,t}}(!0));var ke={class:"domvm-err",style:{color:"#fff",background:"#f00"}};function _e(e){var t="[DOMVM] "+e;return console.error(t),me("div",ke,t)}function Ee(e,t,n,l){var r,a,u,s=this;s.view=e,s.data=t,s.key=n,l&&(s.opts=l,s.cfg(l));try{r=o(e)?e:e.call(s,s,t,n,l)}catch(e){a=e}r&&(i(r)?u=r:(u=r.render,s.cfg(r))),s.render=function(){if(a)return _e(a);try{return u.apply(this,arguments)}catch(e){return _e(e)}},s.init&&s.init.call(s,s,s.data,s.key,l)}function xe(e,t,n){return d(t,n)}function Te(e){var t=this;return e.init&&(t.init=e.init),e.diff&&(t.diff=i(e.diff)?{val:e.diff,eq:xe}:e.diff),e.onevent&&(t.onevent=e.onevent),e.hooks&&(t.hooks=u(t.hooks||{},e.hooks)),e.onemit&&(t.onemit=u(t.onemit||{},e.onemit)),t}const Ne=Ee.prototype={constructor:Ee,init:null,view:null,key:null,data:null,state:null,api:null,opts:null,node:null,hooks:null,refs:null,render:null,mount:function(e,t){var n=this;return x.mutations&&we.start(),t?(ne({el:e,flags:0}),n._redraw(null,null,!1),e.nodeName.toLowerCase()!==n.node.tag?(ae(n.node),le(e.parentNode,n.node.el,e),e.parentNode.removeChild(e)):le(e.parentNode,ae(n.node,e),e)):(n._redraw(null,null),e&&le(e,n.node.el)),e&&$(n,!0),x.mutations&&console.log(we.end()),n},unmount:function(e){var t=this;C(t._stream),t._stream=null;var n=t.node;te(n.el.parentNode,n.el),n.el=null,e||$(t,!0)},cfg:Te,config:Te,parent:function(){return g(this.node.parent)},root:function(){for(var e=this.node;e.parent;)e=e.parent;return e.vm},redraw:function(e){var t=this;return null==e&&(e=I),e?t._redraw(null,null,m(t)):(he.add(t),0===ge&&(ge=requestAnimationFrame(be))),t},update:function(e,t){var n=this;return null==t&&(t=I),n._update(e,null,null,m(n),t),t||n.redraw(),n},_update:function(e,t,n,l,r){var o=this;return null!=e&&o.data!==e&&(T("DATA_REPLACED",[o,o.data,e]),X(o.hooks,"willUpdate",o,e),o.data=e),r?o._redraw(t,n,l):o},_redraw:function(e,t,n){const l=null==e;var r=this,o=r.node&&r.node.el&&r.node.el.parentNode;l&&r.node&&r.node.el&&!r.node.el.parentNode&&T("UNMOUNTED_REDRAW",[r]),l&&x.mutations&&o&&we.start();var a,i=null!=r.diff,u=r.node;if(null!=u&&l&&(e=u.parent,t=u.idx),i&&(a=r.diff.val(r,r.data,r.key,e,t),null!=u&&r.diff.eq(r,u._diff,a)))return u._diff=a,Ae(r,u,e,t);o&&X(r.hooks,"willRedraw",r,r.data);var s=r.render.call(r,r,r.data,r.key,e,t);if(i&&(s._diff=a),s===u)return Ae(r,u,e,t);if(r.refs=null,null!=r.key&&s.key!==r.key&&(s.key=r.key),r.node=s,r._stream=[],e?(U(s,e,t,r),e.body[t]=s):u&&u.parent?(U(s,u.parent,u.idx,r),u.parent.body[u.idx]=s):U(s,null,null,r),!1!==n)if(u)if(u.tag!==s.tag||u.key!==s.key){u.vm=s.vm=null;var d=u.el.parentNode,f=J(u.el);te(d,u.el),le(d,ae(s),f),u.el=s.el,s.vm=r}else pe(s,u);else ae(s);return D(r.data,r._stream),r._stream=R(r._stream,r),o&&X(r.hooks,"didRedraw",r,r.data),l&&o&&$(r,!0),l&&x.mutations&&o&&console.log(we.end()),r}};function Ae(e,t,n,l){return null!=n&&(n.body[l]=t,t.idx=l,t.parent=n,t._lis=!1),e}Ne.onevent=l;const De="http://www.w3.org/2000/svg";function Re(e,t,n,l){this.view=e,this.data=t,this.key=n,this.opts=l}function Ce(e,t){this.vm=e,this.data=t}function Me(e){var t,n,l=arguments,r=l.length;if(r>1){var a=1;o(l[1])&&(n=l[1],a=2),t=r!==a+1||l[a]instanceof b||l[a]instanceof Re||l[a]instanceof Ce?s(l,a):l[a]}return N(e,n,t)}function Se(e,t){var n=e.body;if(r(n))for(var l=0;n.length>l;l++){var o=n[l];null!=o.vm?t.push(o.vm):Se(o,t)}return t}function Ie(e,t){e.el=t,t._node=e;var n=e.attrs;for(var l in n){var o=n[l],a=h(0,l);y(l)||v(l)||(c(l)?G(e,l,o):null!=o&&a&&W(e,l,o,a))}if(8==(8&e.flags)&&e.body.body(e),r(e.body)&&e.body.length>0){var i=t.firstChild,u=0,s=e.body[u];do{4===s.type?s=z(s.view,s.data,s.key,s.opts)._redraw(e,u,!1).node:5===s.type&&(s=s.vm.node||s.vm._update(s.data,e,u,!1,!0).node),"table"===e.tag&&"tr"===s.tag&&T("ATTACH_IMPLICIT_TBODY",[e,s]),Ie(s,i)}while((i=i.nextSibling)&&(s=e.body[++u]))}var d=e.vm;null!=d&&X(d.hooks,"willMount",d,d.data),X(e.hooks,"willInsert",e),X(e.hooks,"didInsert",e),null!=d&&X(d.hooks,"didMount",d,d.data)}function Le(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Oe(e){var t="";for(var n in e)null!=e[n]&&(t+=Le(n)+": "+j(n,e[n])+"; ");return t}function He(e){return null==e?"":""+e}Re.prototype={constructor:Re,type:4,view:null,data:null,key:null,opts:null},Ce.prototype={constructor:Ce,type:5,vm:null,data:null},w.patch=function(e,t){!function(e,t,n){if(o(t)){var l=Object.create(e);l.attrs=u({},e.attrs),null!=t.class&&null!=e._class&&(t.class=e._class+" "+t.class),u(e.attrs,t),B(e,l),n&&p(e)}else{if(null!=e.vm)return;U(t,e.parent,e.idx,null),e.parent.body[e.idx]=t,pe(t,e),n&&p(t),$(g(t),!1)}}(this,e,t)},Ne.emit=function(e){var t=this,n=t,l=s(arguments,1).concat(n,n.data);do{var r=t.onemit,o=r?r[e]:null;if(o){o.apply(t,l);break}}while(t=t.parent());M[e]&&M[e].apply(t,l)},Ne.onemit=null,Ne.body=function(){return Se(this.node,[])},Ne._stream=null;const Ue={area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0};function Ye(e){e=He(e);for(var t=0,n="";e.length>t;t++)switch(e[t]){case"&":n+="&amp;";break;case"<":n+="&lt;";break;case">":n+="&gt;";break;default:n+=e[t]}return n}function Ve(e){e=He(e);for(var t=0,n="";e.length>t;t++)n+='"'===e[t]?"&quot;":e[t];return n}function je(e,t,n){for(var l="",r=0;e.length>r;r++)l+=Pe(e[r],t,n,r);return l}const Fe=".innerHTML";function Pe(e,t,n,l){var o,a;switch(e.type){case 4:o=z(e.view,e.data,e.key,e.opts).html(t,n,l);break;case 5:o=e.vm.html(t,n,l);break;case 1:case 0:if(null!=e.el&&null==e.tag){o=e.el.outerHTML;break}var i="";i+="<"+e.tag;var u=e.attrs,s=null!=u;if(s){for(var d in u)if(!(c(d)||f(d)||v(d)||!1===t&&h(0,d))){var y=u[d];"style"!==d||null==y?!0===y?i+=" "+Ye(d):!1===y||null!=y&&(i+=" "+Ye(d)+'="'+Ve(y)+'"'):a="object"==typeof y?Oe(y):y}null!=a&&(i+=' style="'+Ve(a.trim())+'"')}if(null==e.body&&null!=e.ns&&"svg"!==e.tag)return i+"/>";i+=">",Ue[e.tag]||(s&&null!=u[Fe]?i+=u[Fe]:r(e.body)?i+=je(e.body,t,e):8==(8&e.flags)?(e.body.body(e),i+=je(e.body,t,e)):i+=Ye(e.body),i+="</"+e.tag+">"),o=i;break;case 2:o=Ye(e.body);break;case 3:o="\x3c!--"+Ye(e.body)+"--\x3e"}return o}return Ne.attach=function(e){var t=this;return null==t.node&&t._redraw(null,null,!1),Ie(t.node,e),$(t,!1),t},Ne.html=function(e,t,n){var l=this;null==l.node&&l._redraw(t,n,!1);var r=Pe(l.node,e,t,n);return K.length=0,r},w.html=function(e,t,n){return Pe(this,e,t,n)},e.DEVMODE=x,e.FIXED_BODY=2,e.KEYED_LIST=4,e.VNode=b,e.ViewModel=Ee,e.cfg=H,e.config=H,e.createView=z,e.defineComment=function(e){let t=new b;return t.type=3,t.body=e,t},e.defineElement=me,e.defineElementSpread=Me,e.defineSvgElement=function(e,t,n,l){var r=me(e,t,n,l);return r.ns=De,r},e.defineSvgElementSpread=function(){var e=Me.apply(null,arguments);return e.ns=De,e},e.defineText=k,e.defineView=function(e,t,n,l){return new Re(e,t,n,l)},e.injectElement=function(e){let t=new b;return t.type=0,t.el=t.key=e,t},e.injectView=function(e,t){return new Ce(e,t)},e.list=function(e,t,n){return new A(e,t,n)},e}({});