@talyaron1/mithril 0.0.0-stage → 2.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/LICENSE +21 -0
- package/README.md +89 -2
- package/api/mount-redraw.js +49 -0
- package/api/router.js +252 -0
- package/browser.js +5 -0
- package/hyperscript.js +8 -0
- package/index.js +26 -0
- package/mithril.js +1775 -0
- package/mithril.min.js +1 -0
- package/mount-redraw.js +5 -0
- package/mount.js +3 -0
- package/package.json +36 -4
- package/pathname/build.js +45 -0
- package/pathname/compileTemplate.js +44 -0
- package/pathname/parse.js +25 -0
- package/querystring/build.js +26 -0
- package/querystring/parse.js +48 -0
- package/redraw.js +3 -0
- package/render/cachedAttrsIsStaticMap.js +12 -0
- package/render/delayedRemoval.js +3 -0
- package/render/domFor.js +24 -0
- package/render/emptyAttrs.js +4 -0
- package/render/fragment.js +13 -0
- package/render/hyperscript.js +101 -0
- package/render/hyperscriptVnode.js +23 -0
- package/render/render.js +964 -0
- package/render/trust.js +8 -0
- package/render/vnode.js +34 -0
- package/render.js +3 -0
- package/request/request.js +205 -0
- package/request.js +5 -0
- package/route.js +5 -0
- package/stream/stream.js +267 -0
- package/stream/stream.min.js +1 -0
- package/stream.js +3 -0
- package/util/censor.js +47 -0
- package/util/decodeURIComponentSafe.js +35 -0
- package/util/hasOwn.js +4 -0
package/mithril.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){"use strict";function e(e,t,n,r,i,o){return{tag:e,key:t,attrs:n,children:r,text:i,dom:o,is:void 0,domSize:void 0,state:void 0,events:void 0,instance:void 0}}e.normalize=function(t){if(Array.isArray(t))return e("[",void 0,void 0,e.normalizeChildren(t),void 0,void 0);if(null==t||"boolean"==typeof t)return null;if("object"==typeof t)return t;else return e("#",void 0,void 0,String(t),void 0,void 0)},e.normalizeChildren=function(t){for(var n=new Array(t.length),r=0,i=0;i<t.length;i++)if(n[i]=e.normalize(t[i]),null!==n[i]&&null!=n[i].key)r++;if(0!==r&&r!==t.length)throw new TypeError(n.includes(null)?"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.":"In fragments, vnodes must either all have keys or none have keys.");return n};var t=function(t,n){if(null==t||"object"==typeof t&&null==t.tag&&!Array.isArray(t)){if(1===n.length&&Array.isArray(n[0]))n=n[0]}else n=0===n.length&&Array.isArray(t)?t:[t,...n],t=void 0;return e("",t&&t.key,t,n)},n={}.hasOwnProperty,r={},i=new Map([[r,!0]]),o=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,l=Object.create(null);function a(e){for(var t in e)if(n.call(e,t))return!1;return!0}function f(e){for(var t,n,f="div",s=[],u={},c=!0;t=o.exec(e);){var d=t[1],v=t[2];if(""===d&&""!==v)f=v;else if("#"===d)u.id=v;else if("."===d)s.push(v);else if("["===t[3][0]){var p=t[6];if(p)p=p.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\");if("class"===t[4])s.push(p);else if(u[t[4]]=""===p?p:p||!0,"value"===(n=t[4])||"checked"===n||"selectedIndex"===n||"selected"===n)c=!1}}if(s.length>0)u.className=s.join(" ");if(a(u))u=r;else i.set(u,c);return l[e]={tag:f,attrs:u,is:u.is}}function s(e,t){t.tag=e.tag;var i=t.attrs;if(null==i)return t.attrs=e.attrs,t.is=e.is,t;if(n.call(i,"class")){if(null!=i.class)i.className=i.class;i.class=null}if(e.attrs!==r){var o=i.className;if(i=Object.assign({},e.attrs,i),null!=e.attrs.className)i.className=null!=o?String(e.attrs.className)+" "+String(o):e.attrs.className}if("input"===e.tag&&n.call(i,"type"))i=Object.assign({type:i.type},i);return t.is=i.is,t.attrs=i,t}function u(n,r,...i){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 o=t(r,i);if("string"==typeof n)if(o.children=e.normalizeChildren(o.children),"["!==n)return s(l[n]||f(n),o);if(null==o.attrs)o.attrs={};return o.tag=n,o}u.trust=function(t){if(null==t)t="";return e("<",void 0,void 0,t,void 0,void 0)},u.fragment=function(n,...r){var i=t(n,r);if(null==i.attrs)i.attrs={};return i.tag="[",i.children=e.normalizeChildren(i.children),i};var c=new WeakMap;function*d(e){var t=e.dom,n=e.domSize,r=c.get(t);if(null!=t)do{var i=t.nextSibling;if(c.get(t)===r)yield t,n--;t=i}while(n)}var v=function(){var t,n,r,o={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function l(e){return e.ownerDocument}function a(e){return e.attrs&&e.attrs.xmlns||o[e.tag]}function f(e,t){if(e.state!==t)throw new Error("'vnode.state' must not be modified.")}function s(e){var t=e.state;try{return this.apply(t,arguments)}finally{f(e,t)}}function u(e){try{return l(e).activeElement}catch(e){return null}}function v(e,t,n,r,i,o,l){for(var a=n;a<r;a++){var f=t[a];if(null!=f)p(e,f,i,l,o)}}function p(e,t,n,r,i){var o=t.tag;if("string"==typeof o){if(t.state={},null!=t.attrs)ne(t.attrs,t,n);switch(o){case"#":m(e,t,i);break;case"<":y(e,t,r,i);break;case"[":g(e,t,n,r,i);break;default:w(e,t,n,r,i)}}else z(e,t,n,r,i)}function m(e,t,n){t.dom=l(e).createTextNode(t.children),_(e,t.dom,n)}var h={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"};function y(e,t,n,r){var i=t.children.match(/^\s*?<(\w+)/im)||[],o=l(e).createElement(h[i[1]]||"div");if("http://www.w3.org/2000/svg"===n)o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg">'+t.children+"</svg>",o=o.firstChild;else o.innerHTML=t.children;t.dom=o.firstChild,t.domSize=o.childNodes.length;for(var a,f=l(e).createDocumentFragment();a=o.firstChild;)f.appendChild(a);_(e,f,r)}function g(e,t,n,r,i){var o=l(e).createDocumentFragment();if(null!=t.children){var a=t.children;v(o,a,0,a.length,n,null,r)}t.dom=o.firstChild,t.domSize=o.childNodes.length,_(e,o,i)}function w(e,t,n,r,i){var o=t.tag,f=t.attrs,s=t.is,u=(r=a(t)||r)?s?l(e).createElementNS(r,o,{is:s}):l(e).createElementNS(r,o):s?l(e).createElement(o,{is:s}):l(e).createElement(o);if(t.dom=u,null!=f)J(t,f,r);if(_(e,u,i),!D(t))if(null!=t.children){var c=t.children;if(v(u,c,0,c.length,n,null,r),"select"===t.tag&&null!=f)G(t,f)}}function b(){}function x(e){e.state={view:b},e.instance=void 0}function k(e){if(null==r)r=[e];else r.push(e)}function S(t,n){var r,i="function"==typeof t.tag.view;if(i){if(t.state=Object.create(t.tag),null!=(r=t.state.view).$$reentrantLock$$)return}else if(null!=(r=t.tag).$$reentrantLock$$)return x(t);r.$$reentrantLock$$=!0;try{if(!i)t.state=null!=t.tag.prototype&&"function"==typeof t.tag.prototype.view?new t.tag(t):t.tag(t);if(ne(t.state,t,n),null!=t.attrs)ne(t.attrs,t,n);if(t.instance=e.normalize(s.call(t.state.view,t)),t.instance===t)throw Error("A view cannot return the vnode it received as argument")}finally{r.$$reentrantLock$$=null}}function z(e,t,n,r,i){var o=n.length;try{S(t,n)}catch(e){n.length=o,x(t),k(e)}if(null!=t.instance)p(e,t.instance,n,r,i),t.dom=t.instance.dom,t.domSize=t.instance.domSize;else t.domSize=0}function E(e,t,n,r,i,o){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)v(e,n,0,n.length,r,i,o);else if(null==n||0===n.length)M(e,t,0,t.length);else{var l,a,f=null!=t[0]&&null!=t[0].key,s=null!=n[0]&&null!=n[0].key,u=0,c=0;if(f!==s)M(e,t,0,t.length),v(e,n,0,n.length,r,i,o);else if(!s){for(var d=t.length<n.length?t.length:n.length;c<t.length&&null==t[c];)c++;for(;u<n.length&&null==n[u];)u++;for(u=u<c?u:c;u<d;u++)if((l=t[u])!==(a=n[u])&&(null!=l||null!=a))if(null==l)p(e,a,r,o,I(t,u+1,t.length,i));else if(null==a)H(e,l);else j(e,l,a,r,I(t,u+1,t.length,i),o);if(t.length>d)M(e,t,u,t.length);if(n.length>d)v(e,n,u,n.length,r,i,o)}else{for(var m,h,y,g=t.length-1,w=n.length-1;g>=c&&w>=u&&(m=t[g],h=n[w],m.key===h.key);){if(m!==h)j(e,m,h,r,i,o);if(null!=h.dom)i=h.dom;g--,w--}for(;g>=c&&w>=u&&(l=t[c],a=n[u],l.key===a.key);)if(c++,u++,l!==a)j(e,l,a,r,I(t,c,g+1,i),o);for(;g>=c&&w>=u&&u!==w&&l.key===h.key&&m.key===a.key;){if(R(e,m,y=I(t,c,g,i)),m!==a)j(e,m,a,r,y,o);if(++u<=--w)R(e,l,i);if(l!==h)j(e,l,h,r,i,o);if(null!=h.dom)i=h.dom;c++,m=t[--g],h=n[w],l=t[c],a=n[u]}for(;g>=c&&w>=u&&m.key===h.key;){if(m!==h)j(e,m,h,r,i,o);if(null!=h.dom)i=h.dom;w--,m=t[--g],h=n[w]}if(u>w)M(e,t,c,g+1);else if(c>g)v(e,n,u,w+1,r,i,o);else{for(var b=i,x=2147483647,k=0,S=new Array(w-u+1).fill(-1),z=Object.create(null),E=u;E<=w;E++)z[n[E].key]=E;for(E=g;E>=c;E--){var O=z[(m=t[E]).key];if(null!=O){if(x=O<x?O:-1,S[O-u]=E,m!==(h=n[O]))j(e,m,h,r,i,o);if(null!=h.dom)i=h.dom;k++}}if(i=b,k!==g-c+1)for(E=c;E<=g;E++)if(null==z[t[E].key])H(e,t[E]);if(0===k)v(e,n,u,w+1,r,i,o);else if(-1===x){var A=P(S),C=A.length-1;for(E=w;E>=u;E--){if(h=n[E],-1===S[E-u])p(e,h,r,o,i);else if(A[C]===E-u)C--;else R(e,h,i);if(null!=h.dom)i=h.dom}}else for(E=w;E>=u;E--){if(h=n[E],-1===S[E-u])p(e,h,r,o,i);if(null!=h.dom)i=h.dom}}}}}function j(e,t,n,r,i,o){var l=t.tag;if(l===n.tag&&t.is===n.is)if(n.state=t.state,n.events=t.events,"string"==typeof l){if(ie(n,t))return;if(null!=n.attrs)re(n.attrs,n,r);switch(l){case"#":O(t,n);break;case"<":A(e,t,n,o,i);break;case"[":C(e,t,n,r,i,o);break;default:T(t,n,r,o)}}else N(e,t,n,r,i,o);else H(e,t),p(e,n,r,o,i)}function O(e,t){if(e.children.toString()!==t.children.toString())e.dom.nodeValue=t.children;t.dom=e.dom}function A(e,t,n,r,i){if(t.children!==n.children)U(e,t),y(e,n,r,i);else n.dom=t.dom,n.domSize=t.domSize}function C(e,t,n,r,i,o){E(e,t.children,n.children,r,i,o);var l=0,a=n.children;if(n.dom=null,null!=a)for(var f=0;f<a.length;f++){var s=a[f];if(null!=s&&null!=s.dom){if(null==n.dom)n.dom=s.dom;l+=s.domSize||1}}n.domSize=l}function T(e,t,n,r){var o=t.dom=e.dom;if(r=a(t)||r,e.attrs!=t.attrs||null!=t.attrs&&!i.get(t.attrs))V(t,e.attrs,t.attrs,r);if(!D(t))E(o,e.children,t.children,n,null,r)}function N(t,n,r,i,o,l){if(r.state.view!==b){try{if(ie(r,n))return;if(r.instance=e.normalize(s.call(r.state.view,r)),r.instance===r)throw Error("A view cannot return the vnode it received as argument")}catch(e){return oe(r,n),void k(e)}if(re(r.state,r,i),null!=r.attrs)re(r.attrs,r,i);if(null!=r.instance){if(null==n.instance)p(t,r.instance,i,l,o);else j(t,n.instance,r.instance,i,o,l);r.dom=r.instance.dom,r.domSize=r.instance.domSize}else{if(null!=n.instance)H(t,n.instance);r.domSize=0}}else r.domSize=0}var $,L=[];function P(e){var t=[0],n=0,r=0,i=0,o=L.length=e.length;for(i=0;i<o;i++)L[i]=e[i];for(i=0;i<o;++i)if(-1!==e[i]){var l=t[t.length-1];if(!(e[l]<e[i])){for(n=0,r=t.length-1;n<r;){var a=(n>>>1)+(r>>>1)+(n&r&1);if(e[t[a]]<e[i])n=a+1;else r=a}if(e[i]<e[t[n]]){if(n>0)L[i]=t[n-1];t[n]=i}}else L[i]=l,t.push(i)}for(r=t[(n=t.length)-1];n-- >0;)t[n]=r,r=L[r];return L.length=0,t}function I(e,t,n,r){for(;t<n;t++)if(null!=e[t]&&null!=e[t].dom)return e[t].dom;return r}function R(e,t,n){if(null!=t.dom){var r;if(null==t.domSize||1===t.domSize)r=t.dom;else for(var i of(r=l(e).createDocumentFragment(),d(t)))r.appendChild(i);_(e,r,n)}}function _(e,t,n){if(null!=n)e.insertBefore(t,n);else e.appendChild(t)}function D(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;if(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 M(e,t,n,r){for(var i=n;i<r;i++){var o=t[i];if(null!=o)H(e,o)}}function q(e,t,r,i){var o=t.state,l=s.call(r.onbeforeremove,t);if(null!=l){var a=n;for(var u of d(t))c.set(u,a);i.v++,Promise.resolve(l).finally((function(){f(t,o),F(e,t,i)}))}}function F(e,t,n){if(0==--n.v)K(t),U(e,t)}function H(e,t){var n={v:1};if("string"!=typeof t.tag&&"function"==typeof t.state.onbeforeremove)q(e,t,t.state,n);if(t.attrs&&"function"==typeof t.attrs.onbeforeremove)q(e,t,t.attrs,n);F(e,t,n)}function U(e,t){if(null!=t.dom)if(null==t.domSize||1===t.domSize)e.removeChild(t.dom);else for(var n of d(t))e.removeChild(n)}function K(e){if("string"!=typeof e.tag&&"function"==typeof e.state.onremove)s.call(e.state.onremove,e);if(e.attrs&&"function"==typeof e.attrs.onremove)s.call(e.attrs.onremove,e);if("string"!=typeof e.tag){if(null!=e.instance)K(e.instance)}else{if(null!=e.events)e.events._=null;var t=e.children;if(Array.isArray(t))for(var n=0;n<t.length;n++){var r=t[n];if(null!=r)K(r)}}}function J(e,t,n){for(var r in t)B(e,r,null,t[r],n)}function B(e,t,n,r,i){if("key"!==t&&null!=r&&!X(t)&&(n!==r||W(e,t)||"object"==typeof r)){if("o"===t[0]&&"n"===t[1])return te(e,t,r);if("xlink:"===t.slice(0,6))e.dom.setAttributeNS("http://www.w3.org/1999/xlink",t.slice(6),r);else if("style"===t)Z(e.dom,n,r);else if(Y(e,t,i)){if("value"===t){if(("input"===e.tag||"textarea"===e.tag)&&e.dom.value===""+r)return;if("select"===e.tag&&null!==n&&e.dom.value===""+r)return;if("option"===e.tag&&null!==n&&e.dom.value===""+r)return;if("input"===e.tag&&"file"===e.attrs.type&&""+r!="")return void console.error("`value` is read-only on file inputs!")}if("input"===e.tag&&"type"===t)e.dom.setAttribute(t,r);else e.dom[t]=r}else if("boolean"==typeof r)if(r)e.dom.setAttribute(t,"");else e.dom.removeAttribute(t);else e.dom.setAttribute("className"===t?"class":t,r)}}function Q(e,t,n,r){if("key"!==t&&null!=n&&!X(t))if("o"===t[0]&&"n"===t[1])te(e,t,void 0);else if("style"===t)Z(e.dom,n,null);else if(Y(e,t,r)&&"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))e.dom[t]=null;else{var i=t.indexOf(":");if(-1!==i)t=t.slice(i+1);if(!1!==n)e.dom.removeAttribute("className"===t?"class":t)}}function G(e,t){if("value"in t)if(null===t.value){if(-1!==e.dom.selectedIndex)e.dom.value=null}else{var n=""+t.value;if(e.dom.value!==n||-1===e.dom.selectedIndex)e.dom.value=n}if("selectedIndex"in t)B(e,"selectedIndex",null,t.selectedIndex,void 0)}function V(e,t,n,r){var o;if(null!=t){if(t===n&&!i.has(n))console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major");for(var l in t)if(null!=(o=t[l])&&(null==n||null==n[l]))Q(e,l,o,r)}if(null!=n)for(var l in n)B(e,l,t&&t[l],n[l],r)}function W(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))}function X(e){return"oninit"===e||"oncreate"===e||"onupdate"===e||"onremove"===e||"onbeforeremove"===e||"onbeforeupdate"===e}function Y(e,t,n){return void 0===n&&(e.tag.indexOf("-")>-1||e.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}function Z(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 r in e.style="",n){if(null!=(i=n[r]))if(r.includes("-"))e.style.setProperty(r,String(i));else e.style[r]=String(i)}else{for(var r in t)if(null!=t[r]&&null==n[r])if(r.includes("-"))e.style.removeProperty(r);else e.style[r]="";for(var r in n){var i;if(null!=(i=n[r])&&(i=String(i))!==String(t[r]))if(r.includes("-"))e.style.setProperty(r,i);else e.style[r]=i}}}function ee(){this._=t}function te(e,n,r){if(null!=e.events){if(e.events._=t,e.events[n]===r)return;if(null!=r&&("function"==typeof r||"object"==typeof r)){if(null==e.events[n])e.dom.addEventListener(n.slice(2),e.events,!1);e.events[n]=r}else{if(null!=e.events[n])e.dom.removeEventListener(n.slice(2),e.events,!1);e.events[n]=void 0}}else if(null!=r&&("function"==typeof r||"object"==typeof r))e.events=new ee,e.dom.addEventListener(n.slice(2),e.events,!1),e.events[n]=r}function ne(e,t,n){if("function"==typeof e.oninit)s.call(e.oninit,t);if("function"==typeof e.oncreate)n.push(s.bind(e.oncreate,t))}function re(e,t,n){if("function"==typeof e.onupdate)n.push(s.bind(e.onupdate,t))}function ie(e,t){do{if(null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate){if(void 0!==(n=s.call(e.attrs.onbeforeupdate,e,t))&&!n)break}if("string"!=typeof e.tag&&"function"==typeof e.state.onbeforeupdate){var n;if(void 0!==(n=s.call(e.state.onbeforeupdate,e,t))&&!n)break}return!1}while(0);return oe(e,t),!0}function oe(e,t){e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,e.attrs=t.attrs,e.children=t.children,e.text=t.text}return ee.prototype=Object.create(null),ee.prototype.handleEvent=function(e){var t,n=this["on"+e.type];if("function"==typeof n)t=n.call(e.currentTarget,e);else if("function"==typeof n.handleEvent)n.handleEvent(e);var r=this;if(null!=r._){if(!1!==e.redraw)(0,r._)();if(null!=t&&"function"==typeof t.then)Promise.resolve(t).then((function(){if(null!=r._&&!1!==e.redraw)(0,r._)()}))}if(!1===t)e.preventDefault(),e.stopPropagation()},function(i,o,l){if(!i)throw new TypeError("DOM element being rendered to does not exist.");if(null!=$&&i.contains($))throw new TypeError("Node is currently being rendered to and thus is locked.");var a,f=t,s=$,c=r,d=[],v=u(i),p=i.namespaceURI,m=!1;$=i,t="function"==typeof l?l:void 0,n={},r=null;try{if(null==i.vnodes)i.textContent="";if(o=e.normalizeChildren(Array.isArray(o)?o:[o]),E(i,i.vnodes,o,d,null,"http://www.w3.org/1999/xhtml"===p?void 0:p),i.vnodes=o,null!=v&&u(i)!==v&&"function"==typeof v.focus)v.focus();for(var h=0;h<d.length;h++)d[h]();m=!0}finally{if(a=r,r=c,t=f,$=s,null!=a)for(var y=m?1:0;y<a.length;y++)console.error(a[y])}if(null!=a)throw a[0]}}(),p=function(t,n,r){var i=[],o=!1,l=-1;function a(){for(l=0;l<i.length;l+=2)try{t(i[l],e(i[l+1]),f)}catch(e){r.error(e)}l=-1}function f(){if(!o)o=!0,n((function(){o=!1,a()}))}return f.sync=a,{mount:function(n,r){if(null!=r&&null==r.view&&"function"!=typeof r)throw new TypeError("m.mount expects a component, not a vnode.");var o=i.indexOf(n);if(o>=0){if(i.splice(o,2),o<=l)l-=2;t(n,[])}if(null!=r)i.push(n,r),t(n,e(r),f)},redraw:f}}(v,"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:null,"undefined"!=typeof console?console:null),m=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 i=0;i<n.length;i++)r(e+"["+i+"]",n[i]);else if("[object Object]"===Object.prototype.toString.call(n))for(var i in n)r(e+"["+i+"]",n[i]);else t.push(encodeURIComponent(e)+(null!=n&&""!==n?"="+encodeURIComponent(n):""))}},h=function(e,t){if(/:([^\/\.-]+)(\.{3})?:/.test(e))throw new SyntaxError("Template parameter names must be separated by either a '/', '-', or '.'.");if(null==t)return e;var n=e.indexOf("?"),r=e.indexOf("#"),i=r<0?e.length:r;if(n>i)n=-1;var o=n<0?i:n,l=e.slice(0,o),a={};Object.assign(a,t);var f=l.replace(/:([^\/\.-]+)(\.{3})?/g,(function(e,n,r){if(delete a[n],null==t[n])return e;else return r?t[n]:encodeURIComponent(String(t[n]))})),s=f.indexOf("?"),u=f.indexOf("#"),c=u<0?f.length:u;if(s>c)s=-1;var d=s<0?c:s,v=f.slice(0,d);if(n>=0)v+=e.slice(n,i);if(s>=0)v+=(n<0?"?":"&")+f.slice(s,c);var p=m(a);if(p)v+=(n<0&&s<0?"?":"&")+p;if(r>=0)v+=e.slice(r);if(u>=0)v+=(r<0?"":"&")+f.slice(u);return v},y=function(e,t){function r(e){return new Promise(e)}function i(t,r){return new Promise((function(i,l){t=h(t,r.params);var a,f=null!=r.method?r.method.toUpperCase():"GET",s=r.body,u=(null==r.serialize||r.serialize===JSON.stringify)&&!(s instanceof e.FormData||s instanceof e.URLSearchParams),c=r.responseType||("function"==typeof r.extract?"":"json"),d=new e.XMLHttpRequest,v=!1,p=!1,m=d,y=d.abort;if(d.abort=function(){v=!0,y.call(this)},d.open(f,t,!1!==r.async,"string"==typeof r.user?r.user:void 0,"string"==typeof r.password?r.password:void 0),u&&null!=s&&!o(r,"content-type"))d.setRequestHeader("Content-Type","application/json; charset=utf-8");if("function"!=typeof r.deserialize&&!o(r,"accept"))d.setRequestHeader("Accept","application/json, text/*");if(r.withCredentials)d.withCredentials=r.withCredentials;if(r.timeout)d.timeout=r.timeout;for(var g in d.responseType=c,r.headers)if(n.call(r.headers,g))d.setRequestHeader(g,r.headers[g]);if(d.onreadystatechange=function(e){if(!v)if(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"===c){if(!e.target.responseType&&"function"!=typeof r.extract)try{a=JSON.parse(e.target.responseText)}catch(e){a=null}}else if(!c||"text"===c)if(null==a)a=e.target.responseText;if("function"==typeof r.extract)a=r.extract(e.target,r),o=!0;else if("function"==typeof r.deserialize)a=r.deserialize(a);if(o){if("function"==typeof r.type)if(Array.isArray(a))for(var f=0;f<a.length;f++)a[f]=new r.type(a[f]);else a=new r.type(a);i(a)}else{var s=function(){try{n=e.target.responseText}catch(e){n=a}if("string"!=typeof n)try{n=JSON.stringify(n)}catch(e){n=String(n)}var t=new Error(n);t.code=e.target.status,t.response=a,l(t)};if(0===d.status)setTimeout((function(){if(!p)s()}));else s()}}catch(e){l(e)}},d.ontimeout=function(e){p=!0;var t=new Error("Request timed out");t.code=e.target.status,l(t)},"function"==typeof r.config)if((d=r.config(d,r,t)||d)!==m)a=d.abort,d.abort=function(){v=!0,a.call(this)};if(null==s)d.send();else if("function"==typeof r.serialize)d.send(r.serialize(s));else if(s instanceof e.FormData||s instanceof e.URLSearchParams)d.send(s);else d.send(JSON.stringify(s))}))}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(e,n){if("string"!=typeof e)n=e,e=e.url;else if(null==n)n={};var o=i(e,n);if(!0===n.background)return o;var l=0;function a(){if(0==--l&&"function"==typeof t)t()}return function e(t){var n=t.then;return t.constructor=r,t.then=function(){l++;var r=n.apply(t,arguments);return r.then(a,(function(e){if(a(),0===l)throw e})),e(r)},t}(o)}}}("undefined"!=typeof window?window:null,p.redraw),g=/%(?:[0-7]|(?!c[01]|e0%[89]|ed%[ab]|f0%8|f4%[9ab])(?:c|d|(?:e|f[0-4]%[89ab])[\da-f]%[89ab])[\da-f]%[89ab])[\da-f]/gi,w=function(e){return String(e).replace(g,decodeURIComponent)},b=function(e){if(""===e||null==e)return{};if("?"===e.charAt(0))e=e.slice(1);for(var t=e.split("&"),n={},r={},i=0;i<t.length;i++){var o=t[i],l=o.indexOf("="),a=w(l<0?o:o.slice(0,l)),f=l<0?"":w(o.slice(l+1));if("true"===f)f=!0;else if("false"===f)f=!1;var s=a.split(/\]\[?|\[/),u=r;if(a.indexOf("[")>-1)s.pop();for(var c=0;c<s.length;c++){var d=s[c],v=s[c+1],p=""==v||!isNaN(parseInt(v,10));if(""===d){if(null==n[a=s.slice(0,c).join()])n[a]=Array.isArray(u)?u.length:0;d=n[a]++}else if("__proto__"===d)break;if(c===s.length-1)u[d]=f;else{var m=Object.getOwnPropertyDescriptor(u,d);if(null!=m)m=m.value;if(null==m)u[d]=m=p?[]:{};u=m}}}return r},x=function(e){var t=e.indexOf("?"),n=e.indexOf("#"),r=n<0?e.length:n;if(t>r)t=-1;var i=t<0?r:t,o=e.slice(0,i).replace(/\/{2,}/g,"/");if(!o)o="/";else if("/"!==o[0])o="/"+o;return{path:o,params:t<0?{}:b(e.slice(t+1,r))}},k=/^(?:key|oninit|oncreate|onbeforeupdate|onupdate|onbeforeremove|onremove)$/,S=function(e,t){var r={};if(null!=t){for(var i in e)if(n.call(e,i)&&!k.test(i)&&t.indexOf(i)<0)r[i]=e[i]}else for(var i in e)if(n.call(e,i)&&!k.test(i))r[i]=e[i];return r},z=function(t,n){var r,i,o,l,a,f,s,c,d=Promise.resolve(),v=!1,p=!1,m=!1,y={onremove:function(){p=m=!1,t.removeEventListener("popstate",k,!1)},view:function(){var t=e(a,f.key,f);if(l)return l.render(t);else return[t]}},g=z.SKIP={};function b(){v=!1;var e=t.location.hash;if("#"!==z.prefix[0])if(e=t.location.search+e,"?"!==z.prefix[0])if("/"!==(e=t.location.pathname+e)[0])e="/"+e;var u=e.concat().replace(/(?:%[a-f89][a-f0-9])+/gim,w).slice(z.prefix.length),p=x(u);function h(e){console.error(e),z.set(o,null,{replace:!0})}Object.assign(p.params,t.history.state),function e(t){for(;t<i.length;t++)if(i[t].check(p)){var v=i[t].component,w=i[t].route,b=v,x=c=function(i){if(x===c){if(i===g)return e(t+1);if(a=null!=i&&("function"==typeof i.view||"function"==typeof i)?i:"div",f=p.params,s=u,c=null,l=v.render?v:null,m)n.redraw();else m=!0,n.mount(r,y)}};if(v.view||"function"==typeof v)v={},x(b);else if(v.onmatch)d.then((function(){return v.onmatch(p.params,u,w)})).then(x,u===o?null:function(e){if(x===c)h(e);else console.error(e)});else x();return}if(u===o)throw new Error("Could not resolve default route "+o+".");z.set(o,null,{replace:!0})}(0)}function k(){if(!v)v=!0,setTimeout(b)}function z(e,n,l){if(!e)throw new TypeError("DOM element being rendered to does not exist.");if(i=Object.keys(l).map((function(e){if("/"!==e[0])throw new SyntaxError("Routes must start with a '/'.");if(/:([^\/\.-]+)(\.{3})?:/.test(e))throw new SyntaxError("Route parameter names must be separated with either '/', '.', or '-'.");return{route:e,component:l[e],check:(t=e,n=x(t),r=Object.keys(n.params),i=[],o=new RegExp("^"+n.path.replace(/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,(function(e,t,n){if(null==t)return"\\"+e;if(i.push({k:t,r:"..."===n}),"..."===n)return"(.*)";if("."===n)return"([^/]+)\\.";else return"([^/]+)"+(n||"")}))+"\\/?$"),function(e){for(var t=0;t<r.length;t++)if(n.params[r[t]]!==e.params[r[t]])return!1;if(!i.length)return o.test(e.path);var l=o.exec(e.path);if(null==l)return!1;for(t=0;t<i.length;t++)e.params[i[t].k]=i[t].r?l[t+1]:w(l[t+1]);return!0})};var t,n,r,i,o})),o=n,null!=n){var a=x(n);if(!i.some((function(e){return e.check(a)})))throw new ReferenceError("Default route doesn't match any known routes.")}r=e,t.addEventListener("popstate",k,!1),p=!0,b()}return z.set=function(e,n,r){var i=null!=c||null!=r&&r.replace;if(c=null,e=h(e,n),p){k();var o=r?r.state:null,l=r?r.title:null;if(i)t.history.replaceState(o,l,z.prefix+e);else t.history.pushState(o,l,z.prefix+e)}else t.location.href=z.prefix+e},z.get=function(){return s},z.prefix="#!",z.Link={view:function(e){var t,n,r,i=u(e.attrs.selector||"a",S(e.attrs,["options","params","selector","onclick"]),e.children);if(i.attrs.disabled=Boolean(i.attrs.disabled))i.attrs.href=null,i.attrs["aria-disabled"]="true";else t=e.attrs.options,n=e.attrs.onclick,r=h(i.attrs.href,e.attrs.params),i.attrs.href=z.prefix+r,i.attrs.onclick=function(e){var i;if("function"==typeof n)i=n.call(e.currentTarget,e);else if(null==n||"object"!=typeof n);else if("function"==typeof n.handleEvent)n.handleEvent(e);if(!(!1===i||e.defaultPrevented||0!==e.button&&0!==e.which&&1!==e.which||e.currentTarget.target&&"_self"!==e.currentTarget.target||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey))e.preventDefault(),e.redraw=!1,z.set(r,null,t)};return i}},z.param=function(e){return f&&null!=e?f[e]:f},z}("undefined"!=typeof window?window:null,p),E=function(){return u.apply(this,arguments)};if(E.m=u,E.trust=u.trust,E.fragment=u.fragment,E.Fragment="[",E.mount=p.mount,E.route=z,E.render=v,E.redraw=p.redraw,E.request=y.request,E.parseQueryString=b,E.buildQueryString=m,E.parsePathname=x,E.buildPathname=h,E.vnode=e,E.censor=S,E.domFor=d,"undefined"!=typeof module)module.exports=E;else window.m=E}();
|
package/mount-redraw.js
ADDED
package/mount.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talyaron1/mithril",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "A framework for building brilliant applications (Mithril.js v2 with unreleased bug fixes)",
|
|
5
|
+
"author": "Leo Horie",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"unpkg": "mithril.min.js",
|
|
8
|
+
"jsdelivr": "mithril.min.js",
|
|
9
|
+
"repository": "github:talyaron/mithril.js",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"watch": "run-p watch:**",
|
|
15
|
+
"watch:js": "node scripts/bundler browser.js -output mithril.js -watch",
|
|
16
|
+
"build": "run-p build:browser build:min build:stream-min",
|
|
17
|
+
"build:browser": "node scripts/bundler browser.js -output mithril.js",
|
|
18
|
+
"build:min": "node scripts/bundler browser.js -output mithril.min.js -minify -save",
|
|
19
|
+
"build:stream-min": "node scripts/minify-stream",
|
|
20
|
+
"cleanup:lint": "rimraf .eslintcache",
|
|
21
|
+
"lint": "run-s -cn lint:**",
|
|
22
|
+
"lint:js": "eslint . --cache",
|
|
23
|
+
"perf": "node performance/test-perf.js",
|
|
24
|
+
"pretest": "npm run lint",
|
|
25
|
+
"test": "run-s test:js",
|
|
26
|
+
"test:js": "ospec"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"benchmark": "^2.1.4",
|
|
30
|
+
"chokidar": "^4.0.1",
|
|
31
|
+
"eslint": "^8.9.0",
|
|
32
|
+
"glob": "^13.0.0",
|
|
33
|
+
"npm-run-all": "^4.1.5",
|
|
34
|
+
"ospec": "4.2.1",
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
|
+
"terser": "^5.7.2"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var buildQueryString = require("../querystring/build")
|
|
4
|
+
|
|
5
|
+
// Returns `path` from `template` + `params`
|
|
6
|
+
module.exports = function(template, params) {
|
|
7
|
+
if ((/:([^\/\.-]+)(\.{3})?:/).test(template)) {
|
|
8
|
+
throw new SyntaxError("Template parameter names must be separated by either a '/', '-', or '.'.")
|
|
9
|
+
}
|
|
10
|
+
if (params == null) return template
|
|
11
|
+
var queryIndex = template.indexOf("?")
|
|
12
|
+
var hashIndex = template.indexOf("#")
|
|
13
|
+
var queryEnd = hashIndex < 0 ? template.length : hashIndex
|
|
14
|
+
// A `?` after the `#` belongs to the fragment, it doesn't start a query string.
|
|
15
|
+
if (queryIndex > queryEnd) queryIndex = -1
|
|
16
|
+
var pathEnd = queryIndex < 0 ? queryEnd : queryIndex
|
|
17
|
+
var path = template.slice(0, pathEnd)
|
|
18
|
+
var query = {}
|
|
19
|
+
|
|
20
|
+
Object.assign(query, params)
|
|
21
|
+
|
|
22
|
+
var resolved = path.replace(/:([^\/\.-]+)(\.{3})?/g, function(m, key, variadic) {
|
|
23
|
+
delete query[key]
|
|
24
|
+
// If no such parameter exists, don't interpolate it.
|
|
25
|
+
if (params[key] == null) return m
|
|
26
|
+
// Escape normal parameters, but not variadic ones.
|
|
27
|
+
return variadic ? params[key] : encodeURIComponent(String(params[key]))
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// In case the template substitution adds new query/hash parameters.
|
|
31
|
+
var newQueryIndex = resolved.indexOf("?")
|
|
32
|
+
var newHashIndex = resolved.indexOf("#")
|
|
33
|
+
var newQueryEnd = newHashIndex < 0 ? resolved.length : newHashIndex
|
|
34
|
+
if (newQueryIndex > newQueryEnd) newQueryIndex = -1
|
|
35
|
+
var newPathEnd = newQueryIndex < 0 ? newQueryEnd : newQueryIndex
|
|
36
|
+
var result = resolved.slice(0, newPathEnd)
|
|
37
|
+
|
|
38
|
+
if (queryIndex >= 0) result += template.slice(queryIndex, queryEnd)
|
|
39
|
+
if (newQueryIndex >= 0) result += (queryIndex < 0 ? "?" : "&") + resolved.slice(newQueryIndex, newQueryEnd)
|
|
40
|
+
var querystring = buildQueryString(query)
|
|
41
|
+
if (querystring) result += (queryIndex < 0 && newQueryIndex < 0 ? "?" : "&") + querystring
|
|
42
|
+
if (hashIndex >= 0) result += template.slice(hashIndex)
|
|
43
|
+
if (newHashIndex >= 0) result += (hashIndex < 0 ? "" : "&") + resolved.slice(newHashIndex)
|
|
44
|
+
return result
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var parsePathname = require("./parse")
|
|
4
|
+
var decodeURIComponentSafe = require("../util/decodeURIComponentSafe")
|
|
5
|
+
|
|
6
|
+
// Compiles a template into a function that takes a resolved path (without query
|
|
7
|
+
// strings) and returns an object containing the template parameters with their
|
|
8
|
+
// parsed values. This expects the input of the compiled template to be the
|
|
9
|
+
// output of `parsePathname`. Note that it does *not* remove query parameters
|
|
10
|
+
// specified in the template.
|
|
11
|
+
module.exports = function(template) {
|
|
12
|
+
var templateData = parsePathname(template)
|
|
13
|
+
var templateKeys = Object.keys(templateData.params)
|
|
14
|
+
var keys = []
|
|
15
|
+
var regexp = new RegExp("^" + templateData.path.replace(
|
|
16
|
+
// I escape literal text so people can use things like `:file.:ext` or
|
|
17
|
+
// `:lang-:locale` in routes. This is all merged into one pass so I
|
|
18
|
+
// don't also accidentally escape `-` and make it harder to detect it to
|
|
19
|
+
// ban it from template parameters.
|
|
20
|
+
/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,
|
|
21
|
+
function(m, key, extra) {
|
|
22
|
+
if (key == null) return "\\" + m
|
|
23
|
+
keys.push({k: key, r: extra === "..."})
|
|
24
|
+
if (extra === "...") return "(.*)"
|
|
25
|
+
if (extra === ".") return "([^/]+)\\."
|
|
26
|
+
return "([^/]+)" + (extra || "")
|
|
27
|
+
}
|
|
28
|
+
) + "\\/?$")
|
|
29
|
+
return function(data) {
|
|
30
|
+
// First, check the params. Usually, there isn't any, and it's just
|
|
31
|
+
// checking a static set.
|
|
32
|
+
for (var i = 0; i < templateKeys.length; i++) {
|
|
33
|
+
if (templateData.params[templateKeys[i]] !== data.params[templateKeys[i]]) return false
|
|
34
|
+
}
|
|
35
|
+
// If no interpolations exist, let's skip all the ceremony
|
|
36
|
+
if (!keys.length) return regexp.test(data.path)
|
|
37
|
+
var values = regexp.exec(data.path)
|
|
38
|
+
if (values == null) return false
|
|
39
|
+
for (var i = 0; i < keys.length; i++) {
|
|
40
|
+
data.params[keys[i].k] = keys[i].r ? values[i + 1] : decodeURIComponentSafe(values[i + 1])
|
|
41
|
+
}
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var parseQueryString = require("../querystring/parse")
|
|
4
|
+
|
|
5
|
+
// Returns `{path, params}` from `url`
|
|
6
|
+
module.exports = function(url) {
|
|
7
|
+
var queryIndex = url.indexOf("?")
|
|
8
|
+
var hashIndex = url.indexOf("#")
|
|
9
|
+
var queryEnd = hashIndex < 0 ? url.length : hashIndex
|
|
10
|
+
// A `?` after the `#` belongs to the fragment, it doesn't start a query string.
|
|
11
|
+
if (queryIndex > queryEnd) queryIndex = -1
|
|
12
|
+
var pathEnd = queryIndex < 0 ? queryEnd : queryIndex
|
|
13
|
+
var path = url.slice(0, pathEnd).replace(/\/{2,}/g, "/")
|
|
14
|
+
|
|
15
|
+
if (!path) path = "/"
|
|
16
|
+
else {
|
|
17
|
+
if (path[0] !== "/") path = "/" + path
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
path: path,
|
|
21
|
+
params: queryIndex < 0
|
|
22
|
+
? {}
|
|
23
|
+
: parseQueryString(url.slice(queryIndex + 1, queryEnd)),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
module.exports = function(object) {
|
|
4
|
+
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
|
|
5
|
+
|
|
6
|
+
var args = []
|
|
7
|
+
for (var key in object) {
|
|
8
|
+
destructure(key, object[key])
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return args.join("&")
|
|
12
|
+
|
|
13
|
+
function destructure(key, value) {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
for (var i = 0; i < value.length; i++) {
|
|
16
|
+
destructure(key + "[" + i + "]", value[i])
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (Object.prototype.toString.call(value) === "[object Object]") {
|
|
20
|
+
for (var i in value) {
|
|
21
|
+
destructure(key + "[" + i + "]", value[i])
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var decodeURIComponentSafe = require("../util/decodeURIComponentSafe")
|
|
4
|
+
|
|
5
|
+
module.exports = function(string) {
|
|
6
|
+
if (string === "" || string == null) return {}
|
|
7
|
+
if (string.charAt(0) === "?") string = string.slice(1)
|
|
8
|
+
|
|
9
|
+
var entries = string.split("&"), counters = {}, data = {}
|
|
10
|
+
for (var i = 0; i < entries.length; i++) {
|
|
11
|
+
// Only the first `=` separates the key from the value. The value may
|
|
12
|
+
// contain more of them, e.g. base64 padding or a nested URL.
|
|
13
|
+
var entry = entries[i]
|
|
14
|
+
var separator = entry.indexOf("=")
|
|
15
|
+
var key = decodeURIComponentSafe(separator < 0 ? entry : entry.slice(0, separator))
|
|
16
|
+
var value = separator < 0 ? "" : decodeURIComponentSafe(entry.slice(separator + 1))
|
|
17
|
+
|
|
18
|
+
if (value === "true") value = true
|
|
19
|
+
else if (value === "false") value = false
|
|
20
|
+
|
|
21
|
+
var levels = key.split(/\]\[?|\[/)
|
|
22
|
+
var cursor = data
|
|
23
|
+
if (key.indexOf("[") > -1) levels.pop()
|
|
24
|
+
for (var j = 0; j < levels.length; j++) {
|
|
25
|
+
var level = levels[j], nextLevel = levels[j + 1]
|
|
26
|
+
var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10))
|
|
27
|
+
if (level === "") {
|
|
28
|
+
var key = levels.slice(0, j).join()
|
|
29
|
+
if (counters[key] == null) {
|
|
30
|
+
counters[key] = Array.isArray(cursor) ? cursor.length : 0
|
|
31
|
+
}
|
|
32
|
+
level = counters[key]++
|
|
33
|
+
}
|
|
34
|
+
// Disallow direct prototype pollution
|
|
35
|
+
else if (level === "__proto__") break
|
|
36
|
+
if (j === levels.length - 1) cursor[level] = value
|
|
37
|
+
else {
|
|
38
|
+
// Read own properties exclusively to disallow indirect
|
|
39
|
+
// prototype pollution
|
|
40
|
+
var desc = Object.getOwnPropertyDescriptor(cursor, level)
|
|
41
|
+
if (desc != null) desc = desc.value
|
|
42
|
+
if (desc == null) cursor[level] = desc = isNumber ? [] : {}
|
|
43
|
+
cursor = desc
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return data
|
|
48
|
+
}
|
package/redraw.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var emptyAttrs = require("./emptyAttrs")
|
|
4
|
+
|
|
5
|
+
// This Map manages the following:
|
|
6
|
+
// - Whether an attrs is cached attrs generated by compileSelector().
|
|
7
|
+
// - Whether the cached attrs is "static", i.e., does not contain any form attributes.
|
|
8
|
+
// These information will be useful to skip updating attrs in render().
|
|
9
|
+
//
|
|
10
|
+
// Since the attrs used as keys in this map are not released from the selectorCache object,
|
|
11
|
+
// there is no risk of memory leaks. Therefore, Map is used here instead of WeakMap.
|
|
12
|
+
module.exports = new Map([[emptyAttrs, true]])
|
package/render/domFor.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var delayedRemoval = require("./delayedRemoval")
|
|
4
|
+
|
|
5
|
+
function *domFor(vnode) {
|
|
6
|
+
// To avoid unintended mangling of the internal bundler,
|
|
7
|
+
// parameter destructuring is not used here.
|
|
8
|
+
var dom = vnode.dom
|
|
9
|
+
var domSize = vnode.domSize
|
|
10
|
+
var generation = delayedRemoval.get(dom)
|
|
11
|
+
if (dom != null) do {
|
|
12
|
+
var nextSibling = dom.nextSibling
|
|
13
|
+
|
|
14
|
+
if (delayedRemoval.get(dom) === generation) {
|
|
15
|
+
yield dom
|
|
16
|
+
domSize--
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
dom = nextSibling
|
|
20
|
+
}
|
|
21
|
+
while (domSize)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = domFor
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var Vnode = require("../render/vnode")
|
|
4
|
+
var hyperscriptVnode = require("./hyperscriptVnode")
|
|
5
|
+
|
|
6
|
+
module.exports = function(attrs, ...children) {
|
|
7
|
+
var vnode = hyperscriptVnode(attrs, children)
|
|
8
|
+
|
|
9
|
+
if (vnode.attrs == null) vnode.attrs = {}
|
|
10
|
+
vnode.tag = "["
|
|
11
|
+
vnode.children = Vnode.normalizeChildren(vnode.children)
|
|
12
|
+
return vnode
|
|
13
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var Vnode = require("../render/vnode")
|
|
4
|
+
var hyperscriptVnode = require("./hyperscriptVnode")
|
|
5
|
+
var hasOwn = require("../util/hasOwn")
|
|
6
|
+
var emptyAttrs = require("./emptyAttrs")
|
|
7
|
+
var cachedAttrsIsStaticMap = require("./cachedAttrsIsStaticMap")
|
|
8
|
+
|
|
9
|
+
var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g
|
|
10
|
+
var selectorCache = Object.create(null)
|
|
11
|
+
|
|
12
|
+
function isEmpty(object) {
|
|
13
|
+
for (var key in object) if (hasOwn.call(object, key)) return false
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isFormAttributeKey(key) {
|
|
18
|
+
return key === "value" || key === "checked" || key === "selectedIndex" || key === "selected"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function compileSelector(selector) {
|
|
22
|
+
var match, tag = "div", classes = [], attrs = {}, isStatic = true
|
|
23
|
+
while (match = selectorParser.exec(selector)) {
|
|
24
|
+
var type = match[1], value = match[2]
|
|
25
|
+
if (type === "" && value !== "") tag = value
|
|
26
|
+
else if (type === "#") attrs.id = value
|
|
27
|
+
else if (type === ".") classes.push(value)
|
|
28
|
+
else if (match[3][0] === "[") {
|
|
29
|
+
var attrValue = match[6]
|
|
30
|
+
if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
|
|
31
|
+
if (match[4] === "class") classes.push(attrValue)
|
|
32
|
+
else {
|
|
33
|
+
attrs[match[4]] = attrValue === "" ? attrValue : attrValue || true
|
|
34
|
+
if (isFormAttributeKey(match[4])) isStatic = false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (classes.length > 0) attrs.className = classes.join(" ")
|
|
39
|
+
if (isEmpty(attrs)) attrs = emptyAttrs
|
|
40
|
+
else cachedAttrsIsStaticMap.set(attrs, isStatic)
|
|
41
|
+
return selectorCache[selector] = {tag: tag, attrs: attrs, is: attrs.is}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function execSelector(state, vnode) {
|
|
45
|
+
vnode.tag = state.tag
|
|
46
|
+
|
|
47
|
+
var attrs = vnode.attrs
|
|
48
|
+
if (attrs == null) {
|
|
49
|
+
vnode.attrs = state.attrs
|
|
50
|
+
vnode.is = state.is
|
|
51
|
+
return vnode
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (hasOwn.call(attrs, "class")) {
|
|
55
|
+
if (attrs.class != null) attrs.className = attrs.class
|
|
56
|
+
attrs.class = null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (state.attrs !== emptyAttrs) {
|
|
60
|
+
var className = attrs.className
|
|
61
|
+
attrs = Object.assign({}, state.attrs, attrs)
|
|
62
|
+
|
|
63
|
+
if (state.attrs.className != null) attrs.className =
|
|
64
|
+
className != null
|
|
65
|
+
? String(state.attrs.className) + " " + String(className)
|
|
66
|
+
: state.attrs.className
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// workaround for #2622 (reorder keys in attrs to set "type" first)
|
|
70
|
+
// The DOM does things to inputs based on the "type", so it needs set first.
|
|
71
|
+
// See: https://github.com/MithrilJS/mithril.js/issues/2622
|
|
72
|
+
if (state.tag === "input" && hasOwn.call(attrs, "type")) {
|
|
73
|
+
attrs = Object.assign({type: attrs.type}, attrs)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// This reduces the complexity of the evaluation of "is" within the render function.
|
|
77
|
+
vnode.is = attrs.is
|
|
78
|
+
|
|
79
|
+
vnode.attrs = attrs
|
|
80
|
+
|
|
81
|
+
return vnode
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function hyperscript(selector, attrs, ...children) {
|
|
85
|
+
if (selector == null || typeof selector !== "string" && typeof selector !== "function" && typeof selector.view !== "function") {
|
|
86
|
+
throw Error("The selector must be either a string or a component.");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var vnode = hyperscriptVnode(attrs, children)
|
|
90
|
+
|
|
91
|
+
if (typeof selector === "string") {
|
|
92
|
+
vnode.children = Vnode.normalizeChildren(vnode.children)
|
|
93
|
+
if (selector !== "[") return execSelector(selectorCache[selector] || compileSelector(selector), vnode)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (vnode.attrs == null) vnode.attrs = {}
|
|
97
|
+
vnode.tag = selector
|
|
98
|
+
return vnode
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = hyperscript
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var Vnode = require("../render/vnode")
|
|
4
|
+
|
|
5
|
+
// Note: the processing of variadic parameters is perf-sensitive.
|
|
6
|
+
//
|
|
7
|
+
// In native ES6, it might be preferable to define hyperscript and fragment
|
|
8
|
+
// factories with a final ...args parameter and call hyperscriptVnode(...args),
|
|
9
|
+
// since modern engines can optimize spread calls.
|
|
10
|
+
//
|
|
11
|
+
// However, benchmarks showed this was not faster. As a result, spread is used
|
|
12
|
+
// only in the parameter lists of hyperscript and fragment, while an array is
|
|
13
|
+
// passed to hyperscriptVnode.
|
|
14
|
+
module.exports = function(attrs, children) {
|
|
15
|
+
if (attrs == null || typeof attrs === "object" && attrs.tag == null && !Array.isArray(attrs)) {
|
|
16
|
+
if (children.length === 1 && Array.isArray(children[0])) children = children[0]
|
|
17
|
+
} else {
|
|
18
|
+
children = children.length === 0 && Array.isArray(attrs) ? attrs : [attrs, ...children]
|
|
19
|
+
attrs = undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return Vnode("", attrs && attrs.key, attrs, children)
|
|
23
|
+
}
|