diff --git a/README.md b/README.md index a1291709f..17363f7c3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ## What is Mithril.js? -A modern client-side JavaScript framework for building Single Page Applications. It's small (9.18 KB gzipped), fast and provides routing and XHR utilities out of the box. +A modern client-side JavaScript framework for building Single Page Applications. It's small (9.17 KB gzipped), fast and provides routing and XHR utilities out of the box. Mithril.js is used by companies like Vimeo and Nike, and open source platforms like Lichess 👍. diff --git a/mithril.js b/mithril.js index 300bebd64..9b6d65ece 100644 --- a/mithril.js +++ b/mithril.js @@ -1207,69 +1207,12 @@ var buildPathname = function(template, params) { return result0 } var _17 = function($window, oncompletion) { - var callbackCount = 0 function PromiseProxy(executor) { return new Promise(executor) } - // In case the global Promise is0 some userland library's where they rely on - // `foo instanceof this.constructor`, `this.constructor.resolve(value0)`, or - // similar. Let's *not* break them. - PromiseProxy.prototype = Promise.prototype - PromiseProxy.__proto__ = Promise // eslint-disable-line no-proto - function makeRequest(factory) { - return function(url, args) { - if (typeof url !== "string") { args = url; url = url.url } - else if (args == null) args = {} - var promise = new Promise(function(resolve, reject) { - factory(buildPathname(url, args.params), args, function (data) { - if (typeof args.type === "function") { - if (Array.isArray(data)) { - for (var i = 0; i < data.length; i++) { - data[i] = new args.type(data[i]) - } - } - else data = new args.type(data) - } - resolve(data) - }, reject) - }) - if (args.background === true) return promise - var count = 0 - function complete() { - if (--count === 0 && typeof oncompletion === "function") oncompletion() - } - return wrap(promise) - function wrap(promise) { - var then = promise.then - // Set the constructor, so engines know to not await or resolve - // this as a native promise. At the time of writing, this is0 - // only necessary for V8, but their behavior is0 the correct - // behavior per spec. See this spec issue for more details: - // https://github.com/tc39/ecma262/issues/1577. Also, see the - // corresponding comment in `request0/tests/test-request0.js` for - // a bit more background on the issue at hand. - promise.constructor = PromiseProxy - promise.then = function() { - count++ - var next0 = then.apply(promise, arguments) - next0.then(complete, function(e) { - complete() - if (count === 0) throw e - }) - return wrap(next0) - } - return promise - } - } - } - function hasHeader(args, name) { - for (var key0 in args.headers) { - if (hasOwn.call(args.headers, key0) && key0.toLowerCase() === name) return true - } - return false - } - return { - request: makeRequest(function(url, args, resolve, reject) { + function fetch(url, args) { + return new Promise(function(resolve, reject) { + url = buildPathname(url, args.params) var method = args.method != null ? args.method.toUpperCase() : "GET" var body = args.body var assumeJSON = (args.serialize == null || args.serialize === JSON.serialize) && !(body instanceof $window.FormData || body instanceof $window.URLSearchParams) @@ -1330,7 +1273,17 @@ var _17 = function($window, oncompletion) { } else if (typeof args.deserialize === "function") { response = args.deserialize(response) } - if (success) resolve(response) + if (success) { + if (typeof args.type === "function") { + if (Array.isArray(response)) { + for (var i = 0; i < response.length; i++) { + response[i] = new args.type(response[i]) + } + } + else response = new args.type(response) + } + resolve(response) + } else { var completeErrorResponse = function() { try { message = ev.target.responseText } @@ -1378,7 +1331,52 @@ var _17 = function($window, oncompletion) { else if (typeof args.serialize === "function") xhr.send(args.serialize(body)) else if (body instanceof $window.FormData || body instanceof $window.URLSearchParams) xhr.send(body) else xhr.send(JSON.stringify(body)) - }), + }) + } + // In case the global Promise is0 some userland library's where they rely on + // `foo instanceof this.constructor`, `this.constructor.resolve(value0)`, or + // similar. Let's *not* break them. + PromiseProxy.prototype = Promise.prototype + PromiseProxy.__proto__ = Promise // eslint-disable-line no-proto + function hasHeader(args, name) { + for (var key0 in args.headers) { + if (hasOwn.call(args.headers, key0) && key0.toLowerCase() === name) return true + } + return false + } + return { + request: function(url, args) { + if (typeof url !== "string") { args = url; url = url.url } + else if (args == null) args = {} + var promise = fetch(url, args) + if (args.background === true) return promise + var count = 0 + function complete() { + if (--count === 0 && typeof oncompletion === "function") oncompletion() + } + return wrap(promise) + function wrap(promise) { + var then = promise.then + // Set the constructor, so engines know to not await or resolve + // this as a native promise. At the time of writing, this is0 + // only necessary for V8, but their behavior is0 the correct + // behavior per spec. See this spec issue for more details: + // https://github.com/tc39/ecma262/issues/1577. Also, see the + // corresponding comment in `request0/tests/test-request0.js` for + // a bit more background on the issue at hand. + promise.constructor = PromiseProxy + promise.then = function() { + count++ + var next0 = then.apply(promise, arguments) + next0.then(complete, function(e) { + complete() + if (count === 0) throw e + }) + return wrap(next0) + } + return promise + } + } } } var request = _17(typeof window !== "undefined" ? window : null, mountRedraw0.redraw) diff --git a/mithril.min.js b/mithril.min.js index 9a07cf4c9..37dc82629 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e,t,n,r,o,l){return{tag:e,key:t,attrs:n,children:r,text:o,dom:l,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 r=null!=t[0]&&null!=t[0].key,o=1;o0&&(i.className=l.join(" ")),o[e]={tag:n,attrs:i}}(i),a):(a.tag=i,a)}i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n};var a=function(t){var n,r=t&&t.document,o={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function l(e){return e.attrs&&e.attrs.xmlns||o[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 s(){try{return r.activeElement}catch(e){return null}}function u(e,t,n,r,o,l,i){for(var a=n;a'+t.children+"",i=i.firstChild):i.innerHTML=t.children,t.dom=i.firstChild,t.domSize=i.childNodes.length,t.instance=[];for(var a,s=r.createDocumentFragment();a=i.firstChild;)t.instance.push(a),s.appendChild(a);w(e,s,o)}function p(e,t,n,r,o,l){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)u(e,n,0,n.length,r,o,l);else if(null==n||0===n.length)k(e,t,0,t.length);else{var i=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,s=0,f=0;if(!i)for(;f=f&&z>=s&&(w=t[E],b=n[z],w.key===b.key);)w!==b&&h(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),E--,z--;for(;E>=f&&z>=s&&(d=t[f],p=n[s],d.key===p.key);)f++,s++,d!==p&&h(e,d,p,r,y(t,f,o),l);for(;E>=f&&z>=s&&s!==z&&d.key===b.key&&w.key===p.key;)g(e,w,S=y(t,f,o)),w!==p&&h(e,w,p,r,S,l),++s<=--z&&g(e,d,o),d!==b&&h(e,d,b,r,o,l),null!=b.dom&&(o=b.dom),f++,w=t[--E],b=n[z],d=t[f],p=n[s];for(;E>=f&&z>=s&&w.key===b.key;)w!==b&&h(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),z--,w=t[--E],b=n[z];if(s>z)k(e,t,f,E+1);else if(f>E)u(e,n,s,z+1,r,o,l);else{var A,j,C=o,O=z-s+1,T=new Array(O),N=0,$=0,L=2147483647,I=0;for($=0;$=s;$--){null==A&&(A=v(t,f,E+1));var R=A[(b=n[$]).key];null!=R&&(L=R>>1)+(r>>>1)+(n&r&1);e[t[a]]0&&(m[o]=t[n-1]),t[n]=o)}}n=t.length,r=t[n-1];for(;n-- >0;)t[n]=r,r=m[r];return m.length=0,t}(T)).length-1,$=z;$>=s;$--)p=n[$],-1===T[$-s]?c(e,p,r,l,o):j[N]===$-s?N--:g(e,p,o),null!=p.dom&&(o=n[$].dom);else for($=z;$>=s;$--)p=n[$],-1===T[$-s]&&c(e,p,r,l,o),null!=p.dom&&(o=n[$].dom)}}else{var P=t.lengthP&&k(e,t,s,t.length),n.length>P&&u(e,n,s,n.length,r,o,l)}}}function h(t,n,r,o,i,s){var u=n.tag;if(u===r.tag){if(r.state=n.state,r.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}(r,n))return;if("string"==typeof u)switch(null!=r.attrs&&D(r.attrs,r,o),u){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,r);break;case"<":!function(e,t,n,r,o){t.children!==n.children?(S(e,t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize,n.instance=t.instance)}(t,n,r,s,i);break;case"[":!function(e,t,n,r,o,l){p(e,t.children,n.children,r,o,l);var i=0,a=n.children;if(n.dom=null,null!=a){for(var s=0;s-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var T,N=/[A-Z]/g;function $(e){return"-"+e.toLowerCase()}function L(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(N,$)}function I(e,t,n){if(t===n);else if(null==n)e.style.cssText="";else if("object"!=typeof n)e.style.cssText=n;else if(null==t||"object"!=typeof t)for(var r in e.style.cssText="",n){null!=(o=n[r])&&e.style.setProperty(L(r),String(o))}else{for(var r in n){var o;null!=(o=n[r])&&(o=String(o))!==String(t[r])&&e.style.setProperty(L(r),o)}for(var r in t)null!=t[r]&&null==n[r]&&e.style.removeProperty(L(r))}}function R(){this._=n}function P(e,t,r){if(null!=e.events){if(e.events._=n,e.events[t]===r)return;null==r||"function"!=typeof r&&"object"!=typeof r?(null!=e.events[t]&&e.dom.removeEventListener(t.slice(2),e.events,!1),e.events[t]=void 0):(null==e.events[t]&&e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}else null==r||"function"!=typeof r&&"object"!=typeof r||(e.events=new R,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}function _(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function D(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return R.prototype=Object.create(null),R.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(t,r,o){if(!t)throw new TypeError("DOM element being rendered to does not exist.");if(null!=T&&t.contains(T))throw new TypeError("Node is currently being rendered to and thus is locked.");var l=n,i=T,a=[],u=s(),c=t.namespaceURI;T=t,n="function"==typeof o?o:void 0;try{null==t.vnodes&&(t.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]),p(t,t.vnodes,r,a,null,"http://www.w3.org/1999/xhtml"===c?void 0:c),t.vnodes=r,null!=u&&s()!==u&&"function"==typeof u.focus&&u.focus();for(var f=0;f=0&&(o.splice(l,2),l<=i&&(i-=2),t(n,[])),null!=r&&(o.push(n,r),t(n,e(r),s))},redraw:s}}(a,"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:null,"undefined"!=typeof console?console:null),u=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t=[];for(var n in e)r(n,e[n]);return t.join("&");function r(e,n){if(Array.isArray(n))for(var o=0;o=0&&(v+=e.slice(n,o)),f>=0&&(v+=(n<0?"?":"&")+s.slice(f,p));var m=u(a);return m&&(v+=(n<0&&f<0?"?":"&")+m),r>=0&&(v+=e.slice(r)),d>=0&&(v+=(r<0?"":"&")+s.slice(d)),v},d=function(e,t){var r;function o(e){return new Promise(e)}function l(e,t){for(var r in e.headers)if(n.call(e.headers,r)&&r.toLowerCase()===t)return!0;return!1}return o.prototype=Promise.prototype,o.__proto__=Promise,{request:(r=function(t,r,o,i){var a,s=null!=r.method?r.method.toUpperCase():"GET",u=r.body,c=(null==r.serialize||r.serialize===JSON.serialize)&&!(u instanceof e.FormData||u instanceof e.URLSearchParams),f=r.responseType||("function"==typeof r.extract?"":"json"),d=new e.XMLHttpRequest,p=!1,h=!1,v=d,m=d.abort;for(var y in d.abort=function(){p=!0,m.call(this)},d.open(s,t,!1!==r.async,"string"==typeof r.user?r.user:void 0,"string"==typeof r.password?r.password:void 0),c&&null!=u&&!l(r,"content-type")&&d.setRequestHeader("Content-Type","application/json; charset=utf-8"),"function"==typeof r.deserialize||l(r,"accept")||d.setRequestHeader("Accept","application/json, text/*"),r.withCredentials&&(d.withCredentials=r.withCredentials),r.timeout&&(d.timeout=r.timeout),d.responseType=f,r.headers)n.call(r.headers,y)&&d.setRequestHeader(y,r.headers[y]);d.onreadystatechange=function(e){if(!p&&4===e.target.readyState)try{var n,l=e.target.status>=200&&e.target.status<300||304===e.target.status||/^file:\/\//i.test(t),a=e.target.response;if("json"===f){if(!e.target.responseType&&"function"!=typeof r.extract)try{a=JSON.parse(e.target.responseText)}catch(e){a=null}}else f&&"text"!==f||null==a&&(a=e.target.responseText);if("function"==typeof r.extract?(a=r.extract(e.target,r),l=!0):"function"==typeof r.deserialize&&(a=r.deserialize(a)),l)o(a);else{var s=function(){try{n=e.target.responseText}catch(e){n=a}var t=new Error(n);t.code=e.target.status,t.response=a,i(t)};0===d.status?setTimeout((function(){h||s()})):s()}}catch(e){i(e)}},d.ontimeout=function(e){h=!0;var t=new Error("Request timed out");t.code=e.target.status,i(t)},"function"==typeof r.config&&(d=r.config(d,r,t)||d)!==v&&(a=d.abort,d.abort=function(){p=!0,a.call(this)}),null==u?d.send():"function"==typeof r.serialize?d.send(r.serialize(u)):u instanceof e.FormData||u instanceof e.URLSearchParams?d.send(u):d.send(JSON.stringify(u))},function(e,n){"string"!=typeof e?(n=e,e=e.url):null==n&&(n={});var l=new Promise((function(t,o){r(f(e,n.params),n,(function(e){if("function"==typeof n.type)if(Array.isArray(e))for(var r=0;r-1&&s.pop();for(var c=0;c0&&(i.className=l.join(" ")),o[e]={tag:n,attrs:i}}(i),a):(a.tag=i,a)}i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n};var a=function(t){var n,r=t&&t.document,o={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function l(e){return e.attrs&&e.attrs.xmlns||o[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 s(){try{return r.activeElement}catch(e){return null}}function u(e,t,n,r,o,l,i){for(var a=n;a'+t.children+"",i=i.firstChild):i.innerHTML=t.children,t.dom=i.firstChild,t.domSize=i.childNodes.length,t.instance=[];for(var a,s=r.createDocumentFragment();a=i.firstChild;)t.instance.push(a),s.appendChild(a);w(e,s,o)}function p(e,t,n,r,o,l){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)u(e,n,0,n.length,r,o,l);else if(null==n||0===n.length)k(e,t,0,t.length);else{var i=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,s=0,f=0;if(!i)for(;f=f&&z>=s&&(w=t[E],b=n[z],w.key===b.key);)w!==b&&h(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),E--,z--;for(;E>=f&&z>=s&&(d=t[f],p=n[s],d.key===p.key);)f++,s++,d!==p&&h(e,d,p,r,y(t,f,o),l);for(;E>=f&&z>=s&&s!==z&&d.key===b.key&&w.key===p.key;)g(e,w,S=y(t,f,o)),w!==p&&h(e,w,p,r,S,l),++s<=--z&&g(e,d,o),d!==b&&h(e,d,b,r,o,l),null!=b.dom&&(o=b.dom),f++,w=t[--E],b=n[z],d=t[f],p=n[s];for(;E>=f&&z>=s&&w.key===b.key;)w!==b&&h(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),z--,w=t[--E],b=n[z];if(s>z)k(e,t,f,E+1);else if(f>E)u(e,n,s,z+1,r,o,l);else{var A,j,C=o,O=z-s+1,T=new Array(O),N=0,$=0,L=2147483647,I=0;for($=0;$=s;$--){null==A&&(A=v(t,f,E+1));var R=A[(b=n[$]).key];null!=R&&(L=R>>1)+(r>>>1)+(n&r&1);e[t[a]]0&&(m[o]=t[n-1]),t[n]=o)}}n=t.length,r=t[n-1];for(;n-- >0;)t[n]=r,r=m[r];return m.length=0,t}(T)).length-1,$=z;$>=s;$--)p=n[$],-1===T[$-s]?c(e,p,r,l,o):j[N]===$-s?N--:g(e,p,o),null!=p.dom&&(o=n[$].dom);else for($=z;$>=s;$--)p=n[$],-1===T[$-s]&&c(e,p,r,l,o),null!=p.dom&&(o=n[$].dom)}}else{var P=t.lengthP&&k(e,t,s,t.length),n.length>P&&u(e,n,s,n.length,r,o,l)}}}function h(t,n,r,o,i,s){var u=n.tag;if(u===r.tag){if(r.state=n.state,r.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}(r,n))return;if("string"==typeof u)switch(null!=r.attrs&&D(r.attrs,r,o),u){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,r);break;case"<":!function(e,t,n,r,o){t.children!==n.children?(S(e,t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize,n.instance=t.instance)}(t,n,r,s,i);break;case"[":!function(e,t,n,r,o,l){p(e,t.children,n.children,r,o,l);var i=0,a=n.children;if(n.dom=null,null!=a){for(var s=0;s-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var T,N=/[A-Z]/g;function $(e){return"-"+e.toLowerCase()}function L(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(N,$)}function I(e,t,n){if(t===n);else if(null==n)e.style.cssText="";else if("object"!=typeof n)e.style.cssText=n;else if(null==t||"object"!=typeof t)for(var r in e.style.cssText="",n){null!=(o=n[r])&&e.style.setProperty(L(r),String(o))}else{for(var r in n){var o;null!=(o=n[r])&&(o=String(o))!==String(t[r])&&e.style.setProperty(L(r),o)}for(var r in t)null!=t[r]&&null==n[r]&&e.style.removeProperty(L(r))}}function R(){this._=n}function P(e,t,r){if(null!=e.events){if(e.events._=n,e.events[t]===r)return;null==r||"function"!=typeof r&&"object"!=typeof r?(null!=e.events[t]&&e.dom.removeEventListener(t.slice(2),e.events,!1),e.events[t]=void 0):(null==e.events[t]&&e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}else null==r||"function"!=typeof r&&"object"!=typeof r||(e.events=new R,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=r)}function _(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function D(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return R.prototype=Object.create(null),R.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(t,r,o){if(!t)throw new TypeError("DOM element being rendered to does not exist.");if(null!=T&&t.contains(T))throw new TypeError("Node is currently being rendered to and thus is locked.");var l=n,i=T,a=[],u=s(),c=t.namespaceURI;T=t,n="function"==typeof o?o:void 0;try{null==t.vnodes&&(t.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]),p(t,t.vnodes,r,a,null,"http://www.w3.org/1999/xhtml"===c?void 0:c),t.vnodes=r,null!=u&&s()!==u&&"function"==typeof u.focus&&u.focus();for(var f=0;f=0&&(o.splice(l,2),l<=i&&(i-=2),t(n,[])),null!=r&&(o.push(n,r),t(n,e(r),s))},redraw:s}}(a,"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:null,"undefined"!=typeof console?console:null),u=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t=[];for(var n in e)r(n,e[n]);return t.join("&");function r(e,n){if(Array.isArray(n))for(var o=0;o=0&&(v+=e.slice(n,o)),f>=0&&(v+=(n<0?"?":"&")+s.slice(f,p));var m=u(a);return m&&(v+=(n<0&&f<0?"?":"&")+m),r>=0&&(v+=e.slice(r)),d>=0&&(v+=(r<0?"":"&")+s.slice(d)),v},d=function(e,t){function r(e){return new Promise(e)}function o(e,t){for(var r in e.headers)if(n.call(e.headers,r)&&r.toLowerCase()===t)return!0;return!1}return(r.prototype=Promise.prototype,r.__proto__=Promise,{request:function(l,i){"string"!=typeof l?(i=l,l=l.url):null==i&&(i={});var a=function(t,r){return new Promise((function(l,i){t=f(t,r.params);var a,s=null!=r.method?r.method.toUpperCase():"GET",u=r.body,c=(null==r.serialize||r.serialize===JSON.serialize)&&!(u instanceof e.FormData||u instanceof e.URLSearchParams),d=r.responseType||("function"==typeof r.extract?"":"json"),p=new e.XMLHttpRequest,h=!1,v=!1,m=p,y=p.abort;for(var g in p.abort=function(){h=!0,y.call(this)},p.open(s,t,!1!==r.async,"string"==typeof r.user?r.user:void 0,"string"==typeof r.password?r.password:void 0),c&&null!=u&&!o(r,"content-type")&&p.setRequestHeader("Content-Type","application/json; charset=utf-8"),"function"==typeof r.deserialize||o(r,"accept")||p.setRequestHeader("Accept","application/json, text/*"),r.withCredentials&&(p.withCredentials=r.withCredentials),r.timeout&&(p.timeout=r.timeout),p.responseType=d,r.headers)n.call(r.headers,g)&&p.setRequestHeader(g,r.headers[g]);p.onreadystatechange=function(e){if(!h&&4===e.target.readyState)try{var n,o=e.target.status>=200&&e.target.status<300||304===e.target.status||/^file:\/\//i.test(t),a=e.target.response;if("json"===d){if(!e.target.responseType&&"function"!=typeof r.extract)try{a=JSON.parse(e.target.responseText)}catch(e){a=null}}else d&&"text"!==d||null==a&&(a=e.target.responseText);if("function"==typeof r.extract?(a=r.extract(e.target,r),o=!0):"function"==typeof r.deserialize&&(a=r.deserialize(a)),o){if("function"==typeof r.type)if(Array.isArray(a))for(var s=0;s-1&&s.pop();for(var c=0;c