-
Notifications
You must be signed in to change notification settings - Fork 0
/
lite.min.js
1 lines (1 loc) · 14.5 KB
/
lite.min.js
1
(function(){"use strict";var n={enumerable:!1,configurable:!0,writable:!0},t=this.Object.defineProperty,e=function(n){var t=JSON.stringify(n,function(n,t){return"function"==typeof t?t.toString():t},2);return"\n>>> "+String(t).replace(/\n/g,"\n ")},r=function(n){return void 0!==n},i=function(n){return Array.isArray(n)},o=function(n){return"function"==typeof n},a=function(n){return"string"==typeof n},u=function(n){return!!n&&n.constructor===Object},d=function(n){if(void 0!==n)return JSON.parse(JSON.stringify(n))},c=function(n,t){for(var r=arguments.length,i=Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];if(!n)throw new Error("@okwolo."+t+i.map(e).join(""))},l=function(){var n=[],t=function(){var t=n[0];t&&t()};return{add:function(e){n.push(e),1===n.length&&t()},done:function(){n.shift(),t()}}},f=function(){for(var n=arguments.length,t=Array(n),e=0;e<n;e++)t[e]=arguments[e];return t.map(function(n){return a(n)?n:i(n)?f.apply(void 0,function(n){if(Array.isArray(n)){for(var t=0,e=Array(n.length);t<n.length;t++)e[t]=n[t];return e}return Array.from(n)}(n)):u(n)?f(Object.keys(n).map(function(t){return n[t]&&t})):void 0}).filter(Boolean).join(" ")},s=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];!function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),this.list=n;for(var t="#",e=0;e<this.list.length;++e){t+="→ ";var r=this.list[e].tag;t+=r.substr(0,16),r.length>16&&(t+="...")}this.formatted=t},b=s.prototype,h=function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return function(n,t){var e=[],r=!0,i=!1,o=void 0;try{for(var a,u=n[Symbol.iterator]();!(r=(a=u.next()).done)&&(e.push(a.value),!t||e.length!==t);r=!0);}catch(n){i=!0,o=n}finally{try{!r&&u.return&&u.return()}finally{if(i)throw o}}return e}(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},v=function(n,t){p.browser&&(g.defined(t)||(c("undefined"!=typeof window,"app : must be run in a browser environment"),t=window));var e=function(){},i=function(){return e.apply(void 0,arguments)},d=function(){var n={};return{on:function(t,e){c(a(t),"on : handler type is not a string",t),c(o(e),"on : handler is not a function",e),r(n[t])||(n[t]=[]),n[t].push(e)},send:function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),o=1;o<e;o++)i[o-1]=arguments[o];c(a(t),"send : event type is not a string",t);var u=n[t];if(r(u))for(var d=0;d<u.length;++d)u[d].apply(u,i)}}}(),l=d.on,f=d.send,s=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(e){for(var i=arguments.length,o=Array(i>1?i-1:0),d=1;d<i;d++)o[d-1]=arguments[d];if(a(e))n.apply(void 0,["blob."+e].concat(o));else{c(u(e),"use : blob is not an object",e);var l=e.name;if(r(l)){if(c(a(l),"utils.bus : blob name is not a string",l),r(t[l]))return;t[l]=!0}Object.keys(e).forEach(function(t){n("blob."+t,e[t])})}}}(f,{});return Object.assign(i,{on:l,send:f,use:s}),i.on("blob.api",function(n,t){c(g.object(n),"on.blob.api : additional api is not an object",n),Object.keys(n).forEach(function(e){t||c(!i[e],'on.blob.api : cannot add key "'+e+'" because it is already defined'),i[e]=n[e]})}),i.on("blob.primary",function(n){c(g.function(n),"on.blob.primary : primary is not a function",n),e=n}),w.forEach(function(n){n({on:i.on,send:i.send},t)}),g.defined(n)&&i.send("blob.target",n),i},p={kit:"lite",browser:!0},g={array:i,boolean:function(n){return"boolean"==typeof n},defined:r,function:o,node:function(n){return!!(n&&n.tagName&&n.nodeName&&n.ownerDocument&&n.removeAttribute)},null:function(n){return null===n},number:function(n){return"number"==typeof n},object:u,regExp:function(n){return n instanceof RegExp},string:a},y=this;n.value=function(n){return void 0===n?this.formatted:this.formatted+"→ {{"+n+"}}"},t(b,"f",n),n.value=function(n,t){return new s(this.list.concat([{tag:n,key:t}]))},t(b,"add",n),n.value=function(n,t){return this.list.push({tag:n,key:t}),this},t(b,"addUnsafe",n),n.value=function(){return new s(this.list.slice())},t(b,"copy",n),n.value=function(){if(this.list.length<2)return[];for(var n=Array(this.list.length-1),t=0;t<n.length;++t)n[t]=this.list[t+1].key;return n},t(b,"keys",n);var m=/:\w+/g,w=[function(n){var t=n.on,e=n.send,r={},i=r,o=void 0;t("state",function(n){i=n}),t("blob.handler",function(n){c(g.function(n),"on.blob.handler : handler generator is not a function",n);var t=n(function(){return i});c(g.function(t),"on.blob.handler : handler from generator is not a function",t),o=t}),e("blob.handler",function(){return function(n){e("state",n)}});e("blob.api",{setState:function(n){var t=g.function(n)?n(d(i)):n;o(t)},getState:function(){return c(i!==r,"state.getState : cannot get state before it has been set"),d(i)}})},function(n){var t=n.on,e=n.send,r=void 0,i=void 0,o=void 0,a=void 0,u=void 0,d=void 0,f=void 0;t("blob.target",function(n){r=n,e("update",!0)}),t("blob.builder",function(n){c(g.function(n),"on.blob.builder : builder is not a function",n),i=n,e("update",!1)}),t("blob.draw",function(n){c(g.function(n),"on.blob.draw : new draw is not a function",n),a=n,e("update",!0)}),t("blob.update",function(n){c(g.function(n),"on.blob.update : new target updater is not a function",n),u=n,e("update",!1)}),t("blob.build",function(n){c(g.function(n),"on.blob.build : new build is not a function",n),o=n,e("update",!1)}),t("state",function(n){c(g.defined(n),"on.state : new state is not defined",n),f=n,e("update",!1)});var s=!1,b=!1,h=null;t("update",function(n){if(!b){if(!(g.defined(r)&&g.defined(i)&&g.defined(f)))return void(h||(h=setTimeout(function(){var n={builder:i,state:f,target:r};Object.keys(n).forEach(function(t){n[t]=n[t]?"ok":"waiting"}),c(b,"view : still waiting to draw after "+Math.round(3)+"s",n)},3e3)));b=!0}var t=l();if(n||!s)return d=a(r,o(i(f),t)),s=!0,void t.done();d=u(r,o(i(f),t),[],d),t.done()}),t("sync",function(n,t,e){c(s,"view.sync : cannot sync component before app has drawn"),d=u(r,t,n,d,e)}),e("blob.api",{update:function(){y.console.warn("@okwolo.update : function will be deprecated in next major version (4.x)"),e("update",!1)}}),e("blob.primary",function(n){e("blob.builder",n())})},function(n,t){var e=n.send,r=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:500,t={},e=[];return{set:function(r,i){t[r]=i,e.push(r),e.length>n&&(t[e.shift()]=void 0)},get:function(n){return t[n]}}}(1e3);e("blob.build",function(n,t){return t.add(function(){}),function n(t,i,o,a,u,d){if(g.boolean(t)&&(t=""),g.null(t)&&(t=""),g.number(t)&&(t+=""),g.string(t))return u&&o.addUnsafe("textNode",a),{text:t,componentIdentity:d};var l=o.f(a);if(c(g.array(t),"view.build : vdom object is not a recognized type",l,t),g.function(t[0])){var s=h(t,3),b=s[0],v=s[1],p=void 0===v?{}:v,y=s[2],m=void 0===y?[]:y;c(g.object(p),"view.build : component's props is not an object",l,t,p),c(g.array(m),"view.build : component's children is not an array",l,t,m);var w=void 0,O=o;return u||(O=o.copy(),d={}),w=b(Object.assign({},p,{children:m}),function(){for(var t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];i.add(function(){e("sync",O.keys(),n(w.apply(void 0,r),i,O,a,!1,d),d),i.done()})}),c(g.function(w),"view.build : component should return a function",l,w),n(w(),i,O,a,!0,d)}var k=h(t,3),j=k[0],x=k[1],M=void 0===x?{}:x,D=k[2],A=void 0===D?[]:D;c(g.string(j),"view.build : tag property is not a string",l,t,j),c(g.object(M),"view.build : attributes is not an object",l,t,M),c(g.array(A),"view.build : children of vdom object is not an array",l,t,A);var E=r.get(j);g.defined(E)||(E=/^ *?(\w+?) *?(?:#([-\w\d]+?))? *?((?:\.[-\w\d]+?)*?)? *?(?:\|\s*?([^\s][^]*?))? *?$/.exec(j),c(g.array(E),"view.build : tag property cannot be parsed",l,j),r.set(j,E));var N=h(E,5),S=N[1],C=N[2],I=N[3],$=N[4];g.defined(C)&&!g.defined(M.id)&&(M.id=C.trim()),(g.defined(M.className)||g.defined(I))&&(M.className=f(M.className,I).replace(/\./g," ").replace(/ +/g," ").trim()),g.defined($)&&(g.defined(M.style)?M.style=($+";").replace(/;;$/g,";")+M.style:M.style=$);var T=a;"key"in M&&(T=M.key,c(g.number(T)||g.string(T),"view.build : invalid element key type",l,T),c((T=""+T).match(/^[\w\d-_]+$/g),"view.build : invalid character in element key",l,T),M.key=T),d?u&&o.addUnsafe(j,T):o=o.add(j,T);for(var R={},J=[],U=0;U<A.length;++U){var q=A[U],B=""+U,F=n(q,i,o,B);F.attributes&&"key"in F.attributes&&(B=F.attributes.key),c(!R[B],"view.build : duplicate child key (note that text elements and elements with no key attribute are given their array index as key)",o.f(),B),J.push(B),R[B]=F}return{tagName:S,attributes:M,children:R,childOrder:J,componentIdentity:d}}(n,t,new s)})},function(n,t){var e=n.send,r=function n(e){if(g.defined(e.text))return e.DOM=t.document.createTextNode(e.text),e;var r=t.document.createElement(e.tagName);Object.assign(r,e.attributes);for(var i=0;i<e.childOrder.length;++i){var o=e.childOrder[i],a=n(e.children[o]).DOM;r.appendChild(a)}return e.DOM=r,e},i=function n(t,e,i,a,u){if(g.defined(e)){if(!g.defined(i)){var d=a.DOM,c=e.DOM;return t.push(function(){d.removeChild(c)}),void delete a.children[u]}if(e.componentIdentity=i.componentIdentity,e.tagName!==i.tagName){var l=e.DOM,f=r(i),s=a.DOM,b=f.DOM;return t.push(function(){s.replaceChild(b,l)}),void Object.assign(e,{DOM:void 0,text:void 0,tagName:void 0,attributes:void 0,children:void 0,childOrder:void 0},f)}if(void 0===e.text){for(var h=function(n,t){for(var e=Object.keys(Object.assign({},n,t)),r=[],i=0;i<e.length;++i){var a=e[i],u=n[a],d=t[a];o(u)||o(d)?r.push(a):u!==d&&r.push(a)}return r}(e.attributes,i.attributes),v=function(n){var r=h[n],o=i.attributes[r];e.attributes[r]=o;var a=e.DOM;t.push(function(){a[r]=o})},p=0;p<h.length;++p)v(p);var y=e.childOrder.slice();e.childOrder=i.childOrder;var m=Object.keys(Object.assign({},e.children,i.children));for(p=0;p<m.length;++p){var w=m[p];e.children[w]?i.children[w]||y.splice(y.indexOf(w),1):y.push(w),n(t,e.children[w],i.children[w],e,w)}if(y.length){for(var O=function(n,t){for(var e=t.length,r=e/2,i=0,o=0,a=0;a<e;++a){for(var u=n.indexOf(t[a]),d=Math.min(e-u,e-a),c=1,l=1;l<d&&t[a+l]===n[u+l];++l)c+=1;if(c>i&&(i=c,o=a),i>=r)break}return{start:o,end:o+i-1}}(y,i.childOrder),k=O.start,j=O.end,x=i.childOrder.slice(0,k),M=function(n){var r=x[n],i=e.DOM,o=e.children[r].DOM;t.push(function(){i.insertBefore(o,i.firstChild)})},D=x.length-1;D>=0;--D)M(D);for(var A=i.childOrder.slice(j+1,1/0),E=function(n){var r=A[n],i=e.DOM,o=e.children[r].DOM;t.push(function(){i.appendChild(o)})},N=0;N<A.length;++N)E(N)}}else{var S=i.text;if(e.text!==S){var C=e.DOM;t.push(function(){C.nodeValue=S}),e.text=S}}}else{a.children[u]=r(i);var I=a.DOM,$=a.children[u].DOM;t.push(function(){I.appendChild($)})}};e("blob.draw",function(n,e){return c(g.node(n),"view.dom.draw : target is not a DOM node",n),r(e),t.requestAnimationFrame(function(){n.innerHTML="",n.appendChild(e.DOM)}),e}),e("blob.update",function n(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],a=arguments[3],u=arguments[4];c(g.node(e),"view.dom.update : target is not a DOM node",e);for(var d={DOM:e,children:{root:a},childOrder:["root"]},l="root",f=a,s=0;s<o.length;++s)if(l=o[s],d=f,f=f.children[l],!g.defined(f))return o.length>1?n(e,r,o.slice(1),a,u):(t.console.warn("view.dom.update : target of update does not exist (this could be caused by a component update function being called on a component that no longer exists)"),a);if(u&&f.componentIdentity!==u)return o.length>1?n(e,r,o.slice(1),a,u):(t.console.warn("view.dom.update : target of update has incorrect identity (this is generally caused by a component update function being called on a component that no longer exists)"),a);var b=[];return i(b,f,r,d,l),t.requestAnimationFrame(function(){try{for(var n=0;n<b.length;++n)b[n]()}catch(n){t.console.error("view.dom.update : error when applying computed changes"+n)}}),a})},function(n,t){var e=n.on,r=n.send,i=void 0,o="",a=void 0,u=void 0,d=!1,f=t.location.pathname,s=null!==t.window.origin&&"null"!==t.window.origin;s||(f="");var b=l(),h=function(n){var t=o.replace(/([^\w])/g,"\\$1");return n.replace(new RegExp("^"+t),"")||""};t.onpopstate=function(){b.add(function(){f=h(t.location.pathname),u(i,f),b.done()})},e("blob.route",function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=n.path,e=n.handler;c(g.string(t)||g.regExp(t),"on.blob.route : path is not a string or a regular expression",t),c(g.function(e),"on.blob.route : handler is not a function",t,e),c(g.function(a),"on.blob.route : register is not a function",a),b.add(function(){i=a(i,t,e),d||(d=!!u(i,f)),b.done()})}),e("blob.base",function(n){c(g.string(n),"on.blob.base : base url is not a string",n),b.add(function(){o=n,f=h(f),u(i,f),b.done()})}),e("blob.register",function(n){c(g.function(n),"on.blob.register : register is not a function",a),b.add(function(){a=n,b.done()})}),e("blob.fetch",function(n){c(g.function(n),"on.blob.fetch : fetch is not a function",u),b.add(function(){u=n,b.done()})}),e("redirect",function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};c(g.string(n),"on.redirect : path is not a string",n),c(g.object(e),"on.redirect : params is not an object",e),b.add(function(){f=n,s?t.history.pushState({},"",(o+f).replace(/^\/C\:/,"")):console.log("@okwolo : path changed to\n>>> "+f),u(i,f,e),b.done()})}),e("show",function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};c(g.string(n),"on.show : path is not a string",n),c(g.object(t),"on.show : params is not an object",t),b.add(function(){u(i,n,t),b.done()})}),r("blob.api",{redirect:function(n,t){return r("redirect",n,t)},show:function(n,t){return r("show",n,t)}})},function(n){(0,n.send)("blob.fetch",function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!1;return n.find(function(n){var i=n.pattern.exec(t);if(null!==i)return r=!0,i.shift(),n.keys.forEach(function(n,t){e[n.name]=i[t]}),n.handler(e),r}),r})},function(n){(0,n.send)("blob.register",function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],e=arguments[2];if("**"===t)return n.push({keys:[],pattern:/.*/g,handler:e}),n;if(g.regExp(t)){var r=new RegExp(t.toString()+"|").exec("").length-1;return n.push({keys:Array(r).fill(0).map(function(n,t){return{name:t}}),pattern:t,handler:e}),n}var i=(t.match(m)||[]).map(function(n){return{name:n.replace(/^:/g,"")}});return n.push({keys:i,pattern:function(n){var t=n.replace(/([^\w:])/g,"\\$1").replace(m,"([^/#?]*)");return new RegExp("^"+t+"(:?[?#][^]*)?$")}(t),handler:e}),n})},function(n){n.on;var t=n.send;t("blob.primary",function(n,e){g.function(n)?t("blob.builder",n()):t("blob.route",{path:n,handler:function(n){t("blob.builder",e(n))}})})}];v.kit="lite",v.version="3.4.5",v.lite=v,this.okwolo=v}).call(this);