mithril-vndb/mithril.min.js
2024-10-01 13:24:01 +02:00

1 line
No EOL
16 KiB
JavaScript

!function(){"use strict";function e(e,t,n,l,r,o){return{tag:e,key:t,attrs:n,children:l,text:r,dom:o,domSize:void 0,state:void 0,events:void 0,instance:void 0}}e.normalize=function(t){return Array.isArray(t)?e("[",void 0,void 0,e.normalizeChildren(t),void 0,void 0):null==t||"boolean"==typeof t?null:"object"==typeof t?t:e("#",void 0,void 0,String(t),void 0,void 0)},e.normalizeChildren=function(t){var n=[];if(t.length){for(var l=null!=t[0]&&null!=t[0].key,r=1;r<t.length;r++)if((null!=t[r]&&null!=t[r].key)!==l)throw new TypeError(!l||null==t[r]&&"boolean"!=typeof t[r]?"In fragments, vnodes must either all have keys or none have keys.":"In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole.");for(r=0;r<t.length;r++)n[r]=e.normalize(t[r])}return n};var t=function(){var t,n=arguments[this],l=this+1;if(null==n?n={}:("object"!=typeof n||null!=n.tag||Array.isArray(n))&&(n={},l=this),arguments.length===l+1)t=arguments[l],Array.isArray(t)||(t=[t]);else for(t=[];l<arguments.length;)t.push(arguments[l++]);return e("",n.key,n,t)},n={}.hasOwnProperty,l=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,r={};function o(e){for(var t,n="div",o=[],i={};t=l.exec(e);){var a=t[1],u=t[2];if(""===a&&""!==u)n=u;else if("#"===a)i.id=u;else if("."===a)o.push(u);else if("["===t[3][0]){var s=t[6];s&&(s=s.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===t[4]?o.push(s):i[t[4]]=""===s?s:s||!0}}return o.length>0&&(i.className=o.join(" ")),r[e]={tag:n,attrs:i}}function i(e,t){var l=t.attrs,r=n.call(l,"class"),o=r?l.class:l.className;if(t.tag=e.tag,!function(e){for(var t in e)if(n.call(e,t))return!1;return!0}(e.attrs)){var i={};for(var a in l)n.call(l,a)&&(i[a]=l[a]);l=i}for(var a in e.attrs)n.call(e.attrs,a)&&"className"!==a&&!n.call(l,a)&&(l[a]=e.attrs[a]);return null==o&&null==e.attrs.className||(l.className=null!=o?null!=e.attrs.className?String(e.attrs.className)+" "+String(o):o:null!=e.attrs.className?e.attrs.className:null),r&&(l.class=null),t.attrs=l,t}function a(n){if(null==n||"string"!=typeof n&&"function"!=typeof n&&"function"!=typeof n.view)throw Error("The selector must be either a string or a component.");var l=t.apply(1,arguments);return"string"==typeof n&&(l.children=e.normalizeChildren(l.children),"["!==n)?i(r[n]||o(n),l):(l.tag=n,l)}a.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},a.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n};var u=new WeakMap;var s={delayedRemoval:u,domFor:function*(e,t={}){var n=e.dom,l=e.domSize,r=t.generation;if(null!=n)do{var o=n.nextSibling;u.get(n)===r&&(yield n,l--),n=o}while(l)}},f=s.delayedRemoval,d=s.domFor,c=function(){var t,n,l={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function r(e){return e.ownerDocument}function o(e){return e.attrs&&e.attrs.xmlns||l[e.tag]}function i(e,t){if(e.state!==t)throw new Error("'vnode.state' must not be modified.")}function a(e){var t=e.state;try{return this.apply(t,arguments)}finally{i(e,t)}}function u(e){try{return r(e).activeElement}catch(e){return null}}function s(e,t,n,l,r,o,i){for(var a=n;a<l;a++){var u=t[a];null!=u&&c(e,u,r,i,o)}}function c(t,n,l,i,u){var f=n.tag;if("string"==typeof f)switch(n.state={},null!=n.attrs&&P(n.attrs,n,l),f){case"#":!function(e,t,n){t.dom=r(e).createTextNode(t.children),k(e,t.dom,n)}(t,n,u);break;case"<":v(t,n,i,u);break;case"[":!function(e,t,n,l,o){var i=r(e).createDocumentFragment();if(null!=t.children){var a=t.children;s(i,a,0,a.length,n,null,l)}t.dom=i.firstChild,t.domSize=i.childNodes.length,k(e,i,o)}(t,n,l,i,u);break;default:!function(e,t,n,l,i){var a=t.tag,u=t.attrs,f=u&&u.is,d=(l=o(t)||l)?f?r(e).createElementNS(l,a,{is:f}):r(e).createElementNS(l,a):f?r(e).createElement(a,{is:f}):r(e).createElement(a);t.dom=d,null!=u&&function(e,t,n){"input"===e.tag&&null!=t.type&&e.dom.setAttribute("type",t.type);var l=null!=t&&"input"===e.tag&&"file"===t.type;for(var r in t)$(e,r,null,t[r],n,l)}(t,u,l);if(k(e,d,i),!S(t)&&null!=t.children){var c=t.children;s(d,c,0,c.length,n,null,l),"select"===t.tag&&null!=u&&function(e,t){if("value"in t)if(null===t.value)-1!==e.dom.selectedIndex&&(e.dom.value=null);else{var n=""+t.value;e.dom.value===n&&-1!==e.dom.selectedIndex||(e.dom.value=n)}"selectedIndex"in t&&$(e,"selectedIndex",null,t.selectedIndex,void 0)}(t,u)}}(t,n,l,i,u)}else!function(t,n,l,r,o){(function(t,n){var l;if("function"==typeof t.tag.view){if(t.state=Object.create(t.tag),null!=(l=t.state.view).$$reentrantLock$$)return;l.$$reentrantLock$$=!0}else{if(t.state=void 0,null!=(l=t.tag).$$reentrantLock$$)return;l.$$reentrantLock$$=!0,t.state=null!=t.tag.prototype&&"function"==typeof t.tag.prototype.view?new t.tag(t):t.tag(t)}P(t.state,t,n),null!=t.attrs&&P(t.attrs,t,n);if(t.instance=e.normalize(a.call(t.state.view,t)),t.instance===t)throw Error("A view cannot return the vnode it received as argument");l.$$reentrantLock$$=null})(n,l),null!=n.instance?(c(t,n.instance,l,r,o),n.dom=n.instance.dom,n.domSize=null!=n.dom?n.instance.domSize:0):n.domSize=0}(t,n,l,i,u)}var m={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"};function v(e,t,n,l){var o=t.children.match(/^\s*?<(\w+)/im)||[],i=r(e).createElement(m[o[1]]||"div");"http://www.w3.org/2000/svg"===n?(i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg">'+t.children+"</svg>",i=i.firstChild):i.innerHTML=t.children,t.dom=i.firstChild,t.domSize=i.childNodes.length;for(var a,u=r(e).createDocumentFragment();a=i.firstChild;)u.appendChild(a);k(e,u,l)}function h(e,t,n,l,r,o){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)s(e,n,0,n.length,l,r,o);else if(null==n||0===n.length)x(e,t,0,t.length);else{var i=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,u=0,f=0;if(!i)for(;f<t.length&&null==t[f];)f++;if(!a)for(;u<n.length&&null==n[u];)u++;if(i!==a)x(e,t,f,t.length),s(e,n,u,n.length,l,r,o);else if(a){for(var d,m,v,h,k,S=t.length-1,A=n.length-1;S>=f&&A>=u&&(v=t[S],h=n[A],v.key===h.key);)v!==h&&g(e,v,h,l,r,o),null!=h.dom&&(r=h.dom),S--,A--;for(;S>=f&&A>=u&&(d=t[f],m=n[u],d.key===m.key);)f++,u++,d!==m&&g(e,d,m,l,w(t,f,r),o);for(;S>=f&&A>=u&&u!==A&&d.key===h.key&&v.key===m.key;)b(e,v,k=w(t,f,r)),v!==m&&g(e,v,m,l,k,o),++u<=--A&&b(e,d,r),d!==h&&g(e,d,h,l,r,o),null!=h.dom&&(r=h.dom),f++,v=t[--S],h=n[A],d=t[f],m=n[u];for(;S>=f&&A>=u&&v.key===h.key;)v!==h&&g(e,v,h,l,r,o),null!=h.dom&&(r=h.dom),A--,v=t[--S],h=n[A];if(u>A)x(e,t,f,S+1);else if(f>S)s(e,n,u,A+1,l,r,o);else{var E,$,N=r,C=A-u+1,j=new Array(C),L=0,T=0,F=2147483647,I=0;for(T=0;T<C;T++)j[T]=-1;for(T=A;T>=u;T--){null==E&&(E=p(t,f,S+1));var M=E[(h=n[T]).key];null!=M&&(F=M<F?M:-1,j[T-u]=M,v=t[M],t[M]=null,v!==h&&g(e,v,h,l,r,o),null!=h.dom&&(r=h.dom),I++)}if(r=N,I!==S-f+1&&x(e,t,f,S+1),0===I)s(e,n,u,A+1,l,r,o);else if(-1===F)for(L=($=function(e){var t=[0],n=0,l=0,r=0,o=y.length=e.length;for(r=0;r<o;r++)y[r]=e[r];for(r=0;r<o;++r)if(-1!==e[r]){var i=t[t.length-1];if(e[i]<e[r])y[r]=i,t.push(r);else{for(n=0,l=t.length-1;n<l;){var a=(n>>>1)+(l>>>1)+(n&l&1);e[t[a]]<e[r]?n=a+1:l=a}e[r]<e[t[n]]&&(n>0&&(y[r]=t[n-1]),t[n]=r)}}n=t.length,l=t[n-1];for(;n-- >0;)t[n]=l,l=y[l];return y.length=0,t}(j)).length-1,T=A;T>=u;T--)m=n[T],-1===j[T-u]?c(e,m,l,o,r):$[L]===T-u?L--:b(e,m,r),null!=m.dom&&(r=n[T].dom);else for(T=A;T>=u;T--)m=n[T],-1===j[T-u]&&c(e,m,l,o,r),null!=m.dom&&(r=n[T].dom)}}else{var O=t.length<n.length?t.length:n.length;for(u=u<f?u:f;u<O;u++)(d=t[u])===(m=n[u])||null==d&&null==m||(null==d?c(e,m,l,o,w(t,u+1,r)):null==m?z(e,d):g(e,d,m,l,w(t,u+1,r),o));t.length>O&&x(e,t,u,t.length),n.length>O&&s(e,n,u,n.length,l,r,o)}}}function g(t,n,l,r,i,u){var s=n.tag;if(s===l.tag){if(l.state=n.state,l.events=n.events,function(e,t){do{var n;if(null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate)if(void 0!==(n=a.call(e.attrs.onbeforeupdate,e,t))&&!n)break;if("string"!=typeof e.tag&&"function"==typeof e.state.onbeforeupdate)if(void 0!==(n=a.call(e.state.onbeforeupdate,e,t))&&!n)break;return!1}while(0);return e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,e.attrs=t.attrs,e.children=t.children,e.text=t.text,!0}(l,n))return;if("string"==typeof s)switch(null!=l.attrs&&H(l.attrs,l,r),s){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,l);break;case"<":!function(e,t,n,l,r){t.children!==n.children?(A(e,t,void 0),v(e,n,l,r)):(n.dom=t.dom,n.domSize=t.domSize)}(t,n,l,u,i);break;case"[":!function(e,t,n,l,r,o){h(e,t.children,n.children,l,r,o);var i=0,a=n.children;if(n.dom=null,null!=a){for(var u=0;u<a.length;u++){var s=a[u];null!=s&&null!=s.dom&&(null==n.dom&&(n.dom=s.dom),i+=s.domSize||1)}1!==i&&(n.domSize=i)}}(t,n,l,r,i,u);break;default:!function(e,t,n,l){var r=t.dom=e.dom;l=o(t)||l,function(e,t,n,l){t&&t===n&&console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major");if(null!=n){"input"===e.tag&&null!=n.type&&e.dom.setAttribute("type",n.type);var r="input"===e.tag&&"file"===n.type;for(var o in n)$(e,o,t&&t[o],n[o],l,r)}var i;if(null!=t)for(var o in t)null==(i=t[o])||null!=n&&null!=n[o]||N(e,o,i,l)}(t,e.attrs,t.attrs,l),S(t)||h(r,e.children,t.children,n,null,l)}(n,l,r,u)}else!function(t,n,l,r,o,i){if(l.instance=e.normalize(a.call(l.state.view,l)),l.instance===l)throw Error("A view cannot return the vnode it received as argument");H(l.state,l,r),null!=l.attrs&&H(l.attrs,l,r);null!=l.instance?(null==n.instance?c(t,l.instance,r,i,o):g(t,n.instance,l.instance,r,o,i),l.dom=l.instance.dom,l.domSize=l.instance.domSize):null!=n.instance?(z(t,n.instance),l.dom=void 0,l.domSize=0):(l.dom=n.dom,l.domSize=n.domSize)}(t,n,l,r,i,u)}else z(t,n),c(t,l,r,u,i)}function p(e,t,n){for(var l=Object.create(null);t<n;t++){var r=e[t];if(null!=r){var o=r.key;null!=o&&(l[o]=t)}}return l}var y=[];function w(e,t,n){for(;t<e.length;t++)if(null!=e[t]&&null!=e[t].dom)return e[t].dom;return n}function b(e,t,n){if(null!=t.dom){var l;if(null==t.domSize)l=t.dom;else for(var o of(l=r(e).createDocumentFragment(),d(t)))l.appendChild(o);k(e,l,n)}}function k(e,t,n){null!=n?e.insertBefore(t,n):e.appendChild(t)}function S(e){if(null==e.attrs||null==e.attrs.contenteditable&&null==e.attrs.contentEditable)return!1;var t=e.children;if(null!=t&&1===t.length&&"<"===t[0].tag){var n=t[0].children;e.dom.innerHTML!==n&&(e.dom.innerHTML=n)}else if(null!=t&&0!==t.length)throw new Error("Child node of a contenteditable must be trusted.");return!0}function x(e,t,n,l){for(var r=n;r<l;r++){var o=t[r];null!=o&&z(e,o)}}function z(e,t){var l,r,o,u,s=0,c=t.state;"string"!=typeof t.tag&&"function"==typeof t.state.onbeforeremove&&(null!=(o=a.call(t.state.onbeforeremove,t))&&"function"==typeof o.then&&(s=1,l=o));t.attrs&&"function"==typeof t.attrs.onbeforeremove&&(null!=(o=a.call(t.attrs.onbeforeremove,t))&&"function"==typeof o.then&&(s|=2,r=o));if(i(t,c),s){for(var m of(u=n,d(t)))f.set(m,u);null!=l&&l.finally((function(){1&s&&((s&=2)||(i(t,c),E(t),A(e,t,u)))})),null!=r&&r.finally((function(){2&s&&((s&=1)||(i(t,c),E(t),A(e,t,u)))}))}else E(t),A(e,t,u)}function A(e,t,n){if(null!=t.dom)if(null==t.domSize)f.get(t.dom)===n&&e.removeChild(t.dom);else for(var l of d(t,{generation:n}))e.removeChild(l)}function E(e){if("string"!=typeof e.tag&&"function"==typeof e.state.onremove&&a.call(e.state.onremove,e),e.attrs&&"function"==typeof e.attrs.onremove&&a.call(e.attrs.onremove,e),"string"!=typeof e.tag)null!=e.instance&&E(e.instance);else{var t=e.children;if(Array.isArray(t))for(var n=0;n<t.length;n++){var l=t[n];null!=l&&E(l)}}}function $(e,t,n,l,r,o){if(!("key"===t||"is"===t||null==l||C(t)||n===l&&!function(e,t){return"value"===t||"checked"===t||"selectedIndex"===t||"selected"===t&&e.dom===u(e.dom)||"option"===e.tag&&e.dom.parentNode===u(e.dom)}(e,t)&&"object"!=typeof l||"type"===t&&"input"===e.tag)){if("o"===t[0]&&"n"===t[1])return D(e,t,l);if("xlink:"===t.slice(0,6))e.dom.setAttributeNS("http://www.w3.org/1999/xlink",t.slice(6),l);else if("style"===t)M(e.dom,n,l);else if(j(e,t,r)){if("value"===t){if(("input"===e.tag||"textarea"===e.tag)&&e.dom.value===""+l&&(o||e.dom===u(e.dom)))return;if("select"===e.tag&&null!==n&&e.dom.value===""+l)return;if("option"===e.tag&&null!==n&&e.dom.value===""+l)return;if(o&&""+l!="")throw new Error("`value` is read-only on file inputs!")}e.dom[t]=l}else"boolean"==typeof l?l?e.dom.setAttribute(t,""):e.dom.removeAttribute(t):e.dom.setAttribute("className"===t?"class":t,l)}}function N(e,t,n,l){if("key"!==t&&"is"!==t&&null!=n&&!C(t))if("o"===t[0]&&"n"===t[1])D(e,t,void 0);else if("style"===t)M(e.dom,n,null);else if(!j(e,t,l)||"className"===t||"title"===t||"value"===t&&("option"===e.tag||"select"===e.tag&&-1===e.dom.selectedIndex&&e.dom===u(e.dom))||"input"===e.tag&&"type"===t){var r=t.indexOf(":");-1!==r&&(t=t.slice(r+1)),!1!==n&&e.dom.removeAttribute("className"===t?"class":t)}else e.dom[t]=null}function C(e){return"oninit"===e||"oncreate"===e||"onupdate"===e||"onremove"===e||"onbeforeremove"===e||"onbeforeupdate"===e}function j(e,t,n){return void 0===n&&(e.tag.indexOf("-")>-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var L,T=/[A-Z]/g;function F(e){return"-"+e.toLowerCase()}function I(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(T,F)}function M(e,t,n){if(t===n);else if(null==n)e.style="";else if("object"!=typeof n)e.style=n;else if(null==t||"object"!=typeof t)for(var l in e.style.cssText="",n){null!=(r=n[l])&&e.style.setProperty(I(l),String(r))}else{for(var l in n){var r;null!=(r=n[l])&&(r=String(r))!==String(t[l])&&e.style.setProperty(I(l),r)}for(var l in t)null!=t[l]&&null==n[l]&&e.style.removeProperty(I(l))}}function O(){this._=t}function D(e,n,l){if(null!=e.events){if(e.events._=t,e.events[n]===l)return;null==l||"function"!=typeof l&&"object"!=typeof l?(null!=e.events[n]&&e.dom.removeEventListener(n.slice(2),e.events,!1),e.events[n]=void 0):(null==e.events[n]&&e.dom.addEventListener(n.slice(2),e.events,!1),e.events[n]=l)}else null==l||"function"!=typeof l&&"object"!=typeof l||(e.events=new O,e.dom.addEventListener(n.slice(2),e.events,!1),e.events[n]=l)}function P(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function H(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return O.prototype=Object.create(null),O.prototype.handleEvent=function(e){var t,n=this["on"+e.type];"function"==typeof n?t=n.call(e.currentTarget,e):"function"==typeof n.handleEvent&&n.handleEvent(e),this._&&!1!==e.redraw&&(0,this._)(),!1===t&&(e.preventDefault(),e.stopPropagation())},function(l,r,o){if(!l)throw new TypeError("DOM element being rendered to does not exist.");if(null!=L&&l.contains(L))throw new TypeError("Node is currently being rendered to and thus is locked.");var i=t,a=L,s=[],f=u(l),d=l.namespaceURI;L=l,t="function"==typeof o?o:void 0,n={};try{null==l.vnodes&&(l.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]),h(l,l.vnodes,r,s,null,"http://www.w3.org/1999/xhtml"===d?void 0:d),l.vnodes=r,null!=f&&u(l)!==f&&"function"==typeof f.focus&&f.focus();for(var c=0;c<s.length;c++)s[c]()}finally{t=i,L=a}}}("undefined"!=typeof window&&window),m=function(t,n,l){var r=[],o=!1,i=-1;function a(){for(i=0;i<r.length;i+=2)t(r[i],e(r[i+1]),u);i=-1}function u(){o||(o=!0,n((function(){o=!1,a()})))}return u.sync=a,{mount:function(n,l){if(null!=l&&null==l.view&&"function"!=typeof l)throw new TypeError("m.mount expects a component, not a vnode.");var o=r.indexOf(n);o>=0&&(r.splice(o,2),o<=i&&(i-=2),t(n,[])),null!=l&&(r.push(n,l),t(n,e(l),u))},redraw:u}}(c,"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:null,"undefined"!=typeof console&&console),v=s,h=function(){return a.apply(this,arguments)};h.m=a,h.trust=a.trust,h.fragment=a.fragment,h.Fragment="[",h.mount=m.mount,h.render=c,h.redraw=m.redraw,h.vnode=e,h.domFor=v.domFor,"undefined"!=typeof module?module.exports=h:window.m=h}();