UNPKG

@mango-js/runtime

Version:

Basic functions required for running Mango-powered applications.

1 lines 5.27 kB
(function(){document.createComment||(document.createComment=function(){return document.createElement("div")});var e=[];function n(e,t){if(e.$sc)return n(e.$sc);if(e.$d)return n(e.$d,t);if(e.$c&&e.$c(e),e.$bs)for(var r=0;r<e.$bs.length;r++)u(e.$bs[r],e);if(e.$ec)t||(d(e),e.parentNode.removeChild(e.$ec));else{var o=e.firstChild;if(o)do{n(o,!0)}while(o=o.nextSibling)}return e}function t(e,n){if(n){for(var t=[e()],r=function(){c(t,e())},u=0;u<n.length;u++)n[u]&&(o(n[u]),i(n[u],r));return t}return[e]}function r(e,n){e&&e.push(n)}function o(n){for(var t=1;t<e.length;t+=2)if(e[t]===n)return;e.push(n.push(null)-1,n)}function i(e,n){e.push(n)}function u(e,n){for(var t=1;t<e.length;t++)if(e[t]===n){for(var r=1;"function"==typeof e[t+r];)r++;e.splice(t,r);break}}function c(e,n,t){if(e[0]!==n){e[0]=n,e=e.slice();for(var r=1;r<e.length;){for(var o=1;"function"==typeof e[r+o];)e[r+o++](e[r]);r+=o}}else t&&(t.$ru=null);return n}function f(n,t){var o=n.$bs||[];o.length||function(n,t){for(;e.length;)t.push(e.pop()),t[t.length-1][e.pop()]=n}(n,o);for(var u=0;u<t.length;u++){for(var c=1;c<t[u].length;c++)if(t[u][c]){for(var f=!1,a=0;a<o.length;a++)if(o[a]===t[u][c]){f=!0;break}f||(o.push(t[u][c]),r(t[u][c],n)),i(t[u][c],t[u][0])}t[u][0](n)}return o.length&&(n.$bs=o),n}function a(e,n,t){for(var r=0;r<n.length;r++)null!==n[r]&&n[r]!==undefined&&!1!==n[r]&&(n[r].nodeType?s(e,n[r],t):n[r].push?a(e,n[r]):s(e,document.createTextNode(n[r]),t))}function l(){var e=document.createComment("");return e.$ec=document.createComment(""),e.$ec.$sc=e,e}function s(e,n,t){t?e.insertBefore(n,t):e.$ec?e.parentNode.insertBefore(n,e.$ec):e.appendChild(n)}function d(e){if(e.$ec)for(;e.nextSibling!==e.$ec;)e.parentNode.removeChild(n(e.nextSibling));else for(;e.lastChild;)e.removeChild(n(e.lastChild))}function h(e,n){if(n)for(var t=0;t<n.length;t++)e.$bs=[],n[t]&&(r(n[t],e),i(n[t],p),e.$bs.push(n[t]))}function p(e){var n=e.$dv();null===n||n===undefined||!1===n?d(e):n.push?(d(e),a(e,n)):n.nodeType?(d(e),s(e,n)):e.$ec&&3===e.nextSibling.nodeType&&e.nextSibling.nextSibling===e.$ec?e.nextSibling.nodeValue=n:e.$ec||!e.firstChild||3!==e.firstChild.nodeType||e.firstChild.nextSibling?(d(e),s(e,document.createTextNode(n))):e.firstChild.nodeValue=n}function v(e,n){return n}window.mango={a:t,b:function(e){return e?e[0]:undefined},c:c,d:function(e,n){for(var r=[[],[],[],n=n||v],o=0;o<e.length;o++)r[0].push(t(e[o])),r[2].push(n(e[o],o,e));return r},e:function(e,r){var o,i,u,f=e[0],l=e[2],d=[],h=[];for(o=0;o<r.length;o++)d.push(e[3](r[o],o,r));var p=Array(l.length+1);for(i=0;i<e[1].length;i+=2){var v=e[1][i],g=v.nextSibling;for(u=0;g!==v.$ec;)0===i&&(p[u]=[]),p[u++].push(g),g=g.$ec?g.$ec.nextSibling:g.nextSibling;0===i&&(p[u]=[]),p[u].push(g)}for(o=0;o<l.length;o++)if(-1===(T=d.indexOf(l[o]))){for(i=0;i<e[1].length;i+=2)(g=p[o][i/2]).parentNode.removeChild(n(g));l.splice(o,1),f.splice(o,1),p.splice(o--,1)}else h.push(T);var m=function(e,n){var t=e.length;if(0===t)return[];var r,o,i=[],u=Array(t);for(r=0;r<t;r++){for(var c=0,f=i.length;c<f;){var a=Math.floor((c+f)/2);e[i[a]]<e[r]?c=a+1:f=a}f<i.length?i[f]=r:i.push(r),f>0&&(u[r]=i[f-1])}var l=Array(i.length);for(o=i[r=i.length-1];o>=0;r--,o=u[o])l[r]=n[e[o]];return l}(h,d);for(o=0;o<d.length;o++){var $=l.indexOf(d[o]),x=-1!==$?f[$]:t(r[o]);if(-1!==$&&c(x,r[o]),-1===m.indexOf(d[o])){var b=d[o-1],y=l.indexOf(b);for(i=0;i<e[1].length;i+=2){var C=e[1][i].parentNode,S=p[y+1][i/2];if(-1===$){var w=e[1][i+1](x,o);w.push?a(C,w,S):s(C,w,S)}else s(C,p[$][i/2],S)}-1!==$&&(l.splice($,1),f.splice($,1),p.splice($,1));var T=l.indexOf(b)+1;l.splice(T,0,d[o]),f.splice(T,0,x),p.splice(T,0,[])}}},f:function(e,n,t){for(var o=0;o<n.length;o++)r(n[o],n),i(n[o],e);return t&&e(),n},g:function(e){for(var n=0;n<e.length;n++)u(e[n],e)},h:function(e,n){var t=l(),r=[t];e[1].push(t,n);for(var o=0;o<e[0].length;o++){var i=n(e[0][o],o);r.push(i)}return r.push(t.$ec),r},i:function(e,n){var t=l();return t.$dv=e,h(t,n),[t,e(),t.$ec]},j:function(e,n,t,r){var o=r&&document.createElementNS?document.createElementNS(1===r?"http://www.w3.org/2000/svg":"http://www.w3.org/1998/Math/MathML",e):document.createElement(e);if("function"==typeof t){var i=t();a(o,[i[0]()]),o.$dv=i[0],h(o,i[1])}else t&&a(o,t);return n&&f(o,n),o},k:function(e){var n,t,r=document.getElementsByTagName("head")[0],o=l();return s(r,o),a(r,e),s(r,o.$ec),n=o,(t=document.createComment("")).$d=n,t},l:f,m:function(e,t,r,o){r=r||document.createTextNode("");var i=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");return i.open("GET",e,!0),i.onreadystatechange=function(){if(4===i.readyState)if(i.status>=200&&i.status<400){var e=t(new Function("return "+i.responseText)());n(r).parentNode.replaceChild(e,r)}else n(r).parentNode.replaceChild(o(),r)},setTimeout((function(){i.send(null)}),0),r},n:function(e){return function(){var n=Array.prototype.slice.call(arguments);return new Promise((function(t,r){var o=new XMLHttpRequest;o.open("POST",e,!0),o.setRequestHeader("Content-Type","application/json"),o.onreadystatechange=function(){4===o.readyState&&(o.status>=200&&o.status<400?t(JSON.parse(o.responseText)):(console.error(o.responseText),r(JSON.parse(o.responseText))))},o.send(JSON.stringify(Array.prototype.slice.call(n)))}))}},o:a}})();