synks
Version:
Asynchronous view renderer
17 lines (14 loc) • 12.7 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=Symbol(),t=Symbol(),n=Symbol(),r=function(){function e(){var e=this;Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach((function(t){var r=e[t];r instanceof Function&&(e[t]=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];var o=r.apply(e,t);return e[n](),o})}))}return e.prototype[n]=function(){},e}();
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var i,o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function c(e,t,n,r){return new(n||(n=Promise))((function(i,o){function c(e){try{s(r.next(e))}catch(e){o(e)}}function a(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,a)}s((r=r.apply(e,t||[])).next())}))}function a(e,t){var n,r,i,o,c={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(i=c.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){c=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){c.label=o[1];break}if(6===o[0]&&c.label<i[1]){c.label=i[1],i=o;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(o);break}i[2]&&c.ops.pop(),c.trys.pop();continue}o=t.call(e,c)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(e,t,n){return void 0===t&&(t={}),c(this,void 0,void 0,(function(){var r,i,o;return a(this,(function(c){return e.target?[2,e.target]:(r=!!n&&!!(a=n,Array.prototype.slice.call(a.childNodes)).find((function(e){return e===t.target})),""===e.type?(null!=(i=e.props)&&"boolean"!=typeof i||(e.props=""),r&&t&&""===t.type&&t.target?(e.props!==t.props&&(t.target.nodeValue=String(e.props)),[2,t.target]):[2,new Text(String(e.props))]):(r||(t.props={},t.key=null),r&&t&&t.target&&e.type===t.type?[2,t.target]:(o=String(e.type),"svg"===e.type||n instanceof SVGElement?[2,document.createElementNS("http://www.w3.org/2000/svg",o)]:[2,document.createElement(String(o))])));var a}))}))}function u(e){return!!e&&Object.getPrototypeOf(e)===r}function l(e,t,n,r,i){return c(this,void 0,void 0,(function(){var o,c;return a(this,(function(a){switch(a.label){case 0:if(!u(i))return[2,i];if(o=i&&i.name,!(c=n[o]))throw new Error(o+" was called in <"+r.type.name+"> before it was defined");return-1===c[1].indexOf(t)&&c[1].push(t),[4,e.next(c[0])];case 1:return[2,a.sent().value]}}))}))}function f(e){return!!e&&"function"==typeof e.next&&"function"==typeof e.throw}function p(t,n,r,i,s){return c(this,void 0,void 0,(function(){var l,p,h;return a(this,(function(d){switch(d.label){case 0:return f(s)?[4,s.next()]:[2,s];case 1:l=d.sent(),d.label=2;case 2:if(!u(l.value)&&l.value!==e)return[3,7];if(!u(l.value))return[3,4];if(p=l.value&&l.value.name,!(h=r[p]))throw new Error(p+" was called from hook in <"+i.type.name+"> before it was defined");return-1===h[1].indexOf(n)&&h[1].push(n),[4,s.next(h[0])];case 3:l=d.sent(),d.label=4;case 4:return l.value!==e?[3,6]:[4,s.next(o(o({},n),{next:function(){return c(this,void 0,void 0,(function(){var e,t,r;return a(this,(function(i){switch(i.label){case 0:return void 0===l?[3,2]:(t=(e=Object).assign,r=[l],[4,s.next()]);case 1:t.apply(e,r.concat([i.sent()])),i.label=2;case 2:return[4,n.next()];case 3:return[2,i.sent()]}}))}))}}))];case 5:l=d.sent(),d.label=6;case 6:return[3,2];case 7:return[4,t.next(l)];case 8:return[2,d.sent().value]}}))}))}function h(e,t,n,r,i){return c(this,void 0,void 0,(function(){return a(this,(function(o){switch(o.label){case 0:return[4,e.next()];case 1:t=o.sent().value,o.label=2;case 2:return f(t)||u(t)?[4,p(e,n,i,r,t)]:[3,5];case 3:return t=o.sent(),[4,l(e,n,i,r,t)];case 4:return t=o.sent(),[3,2];case 5:return[2,t]}}))}))}function d(e,t){var n=e.target;if(e.type&&!(n instanceof Text)&&n){var r=e.props||{},o=t.props||{};Object.keys(r).forEach((function(e){if(e!==i.style){var t=r[e];if(t!==o[e]){if(t instanceof Function){if(t===n[e])return;return n[e]=t}if(null===t||!1===t||void 0===t)return n.removeAttribute(e);var c=String(t);return e===i.innerHTML?n[e]=c:n.setAttribute(e,c)}}})),t&&(Object.keys(o).forEach((function(e){if(e!==i.style&&(!r||null===r[e]||!1===r[e]||void 0===r[e]))return e===i.innerHTML?delete n[e]:n.removeAttribute(e)})),function(e,t){var n=e.target;if(e.type&&!(n instanceof Text)&&n){var r=(e.props||{}).style||{},i=(t.props||{}).style||{};Object.keys(r).forEach((function(e){var t=r[e];if(t!==i[e])return null===t||!1===t||void 0===t?delete n[e]:n.style[e]=String(t)})),t&&Object.keys(i).forEach((function(e){if(!r||null===r[e]||!1===r[e]||void 0===r[e])return delete n.style[e]}))}}(e,t))}}function y(e,t){if(e===t)return!0;if(!(e instanceof Object&&e))return!1;if(!(t instanceof Object&&t))return!1;var n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&function(e,t,n){for(var r=0,i=n;r<i.length;r++){var o=i[r];if("function"==typeof e[o]&&String(e[o])!==String(t[o]))return!1;if(JSON.stringify(e[o])!==JSON.stringify(t[o])&&e[o]!==t[o])return!1}return!0}(e,t,n)}function v(e){e instanceof Array?e.map(v):e&&e.target&&e.target.parentNode&&(e.target.parentNode.removeChild(e.target),e.scope&&e.scope.destroy())}function g(e){e instanceof Array&&e.forEach((function(e){null!==(e.instance||e).target&&v(e)}))}function b(e,t){return c(this,void 0,void 0,(function(){var n,r,i,o,c,s,u;return a(this,(function(a){switch(a.label){case 0:for(i in n=[],r=[],e)r.push(i);o=0,a.label=1;case 1:return o<r.length?(c=r[o],u=(s=n).push,[4,t(e[c],parseInt(c,10))]):[3,4];case 2:u.apply(s,[a.sent()]),a.label=3;case 3:return o++,[3,1];case 4:return[2,n]}}))}))}function w(e,t,n,r,i){return c(this,void 0,void 0,(function(){var o,s,u=this;return a(this,(function(l){switch(l.label){case 0:return o=r,[4,b(e,(function(e,r){return c(u,void 0,void 0,(function(){var c,s,u,l;return a(this,(function(a){switch(a.label){case 0:return c=t&&t[r],e instanceof Array?[4,w(e,c,n,o+parseInt(r,10),i)]:[3,2];case 1:return s=a.sent(),g(c),o+=Math.max([].concat.apply([],s).length-1,0),[2,s];case 2:if(e&&null!==e.key&&void 0!==e.key&&c&&t instanceof Array){if(c.key===e.key)return e.target=c.target,c.target=null,d(e,c),[2,e];u=t.find((function(t){return t.key===e.key})),c.key!==e.key&&u&&(e.target=u.target,u.target=null)}return[4,k(e,c,n,parseInt(r,10)+o,i)];case 3:return(l=a.sent())instanceof Array&&(o+=Math.max([].concat.apply([],l).length-1,0)),!(l instanceof Array)&&l.instance instanceof Array&&(o+=Math.max([].concat.apply([],l.instance).length-1,0)),[2,l]}}))}))}))];case 1:return s=l.sent(),g(t),[2,s]}}))}))}function m(e){return e instanceof Array?Object.assign(e,e.map(m)):(t=e)&&t instanceof Object?(e.children instanceof Array&&(e.children=e.children.map(m)),Object.assign(e,{type:e.type,props:e.props,key:void 0===e.key?null:e.key,children:e.children,target:null,instance:null,scope:null})):{type:"",props:e,key:null,children:void 0};var t}!function(e){e.innerHTML="innerHTML",e.style="style"}(i||(i={}));var O=[],x=[];function k(e,r,i,o,l){return void 0===r&&(r=e&&e.constructor()),c(this,void 0,void 0,(function(){var p,b,j,S,A,E,M,N,T,P,H,L,C,F,I,B,D,G,J,V,_=this;return a(this,(function(q){switch(q.label){case 0:return null==e?[2,m()]:e instanceof Array?(p=r instanceof Array?r:[r],[4,w(e.map(m),p,i,o,l)]):[3,2];case 1:return[2,q.sent()];case 2:return e=m(e),r&&r.type instanceof Function&&e&&e.type!==r.type?(b=r&&Object.assign({},r.instance),r.scope?[4,r.scope.destroy()]:[3,4]):[3,5];case 3:q.sent(),q.label=4;case 4:b&&x.push((function(){v(b)})),q.label=5;case 5:return e.type instanceof Function?u(j=e.type)?(S=new j(e.props),A=j.name,E=[],M=function(e){return c(_,void 0,void 0,(function(){var t,n,r,i;return a(this,(function(o){switch(o.label){case 0:O=function(e){for(var t=e.slice(),n=0;n<t.length;++n)for(var r=n+1;r<t.length;++r)t[n]===t[r]&&t.splice(r--,1);return t}(E.concat(O)),Object.assign(S,e),t=O.slice().filter((function(e){return e.mounted&&!e.rendering})),O=[],n=0,r=t,o.label=1;case 1:return n<r.length?!(i=r[n]).mounted||i.rendering?[3,3]:[4,i.next()]:[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2]}}))}))},S[n]=function(){return c(_,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,M.call(S)];case 1:return[2,e.sent()]}}))}))},l[A]=[S,E],[4,k(e.children,r.children,i,o,l)]):[3,7]:[3,9];case 6:return[2,q.sent()];case 7:return e.type===r.type&&r.instance&&(N=Object.assign({},e.props,{children:e.children}),T=Object.assign({},r.props,{children:r.children}),P=e.key,H=r.key,y(N,T)||null!==P&&P===H)?[2,Object.assign(e,r)]:(C=Object.assign({},e.props,{children:e.children}),(V={mounted:!0,rendering:!1})[t]=[],V.onMount=function(){return c(this,void 0,void 0,(function(){return a(this,(function(e){return[2]}))}))},V.onDestroy=function(){return c(this,void 0,void 0,(function(){return a(this,(function(e){return[2]}))}))},V.next=function(){return c(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return!F.mounted||F.rendering?[2]:[4,this.nextProps(C)];case 1:return e.sent(),[2]}}))}))},V.nextProps=function(t){return c(this,void 0,void 0,(function(){return a(this,(function(n){switch(n.label){case 0:return!F.mounted||F.rendering?[2]:(F.rendering=!0,[4,D(e.instance,t)]);case 1:return n.sent(),F.rendering=!1,[2]}}))}))},V.destroy=function(){return c(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return F.mounted?(F.mounted=!1,[4,F.onDestroy()]):[2];case 1:return n.sent(),F[t].forEach((function(e){e.destroy()})),F[t]=[],(e=l.scope&&l.scope[t])&&(l.scope[t]=e.filter((function(e){return e.mounted}))),[2]}}))}))},F=V,l.scope&&l.scope[t].push(F),I=Object.assign({},l,{scope:F}),e.scope=F,[4,(D=function(t,n){return c(_,void 0,void 0,(function(){var c;return a(this,(function(a){switch(a.label){case 0:return Object.assign(C,n),"function"!=typeof j?[3,3]:[4,j.call(F,n)];case 1:return f(L=a.sent())?(B||(B=L),[4,h(B,L,F,e,l)]):[3,3];case 2:L=a.sent(),a.label=3;case 3:return[4,k(L,t,i,o,I)];case 4:return c=a.sent(),s=x.slice(),x=[],s.forEach((function(e){return e()})),e instanceof Array||(e.instance=L),Object.assign(r,e),t&&Object.assign(t,c),r.target=null,[2,c]}var s}))}))})(r,C)]);case 8:return q.sent(),F.onMount(),[2,e];case 9:return G=e.target&&void 0!==r.key&&null!==r.key,J=e,[4,s(e,r,i)];case 10:return J.target=q.sent(),d(e,r),G?(i.insertBefore(e.target,i.childNodes[o+1]),[2,e]):((e.target===r.target||r.instance&&r.target===i)&&(r.target=null),e.children instanceof Array?[4,w(e.children,r.children,e.target,0,l)]:[3,12]);case 11:q.sent(),q.label=12;case 12:return r.target&&r.target.parentNode&&r.target!==e.target&&r.target!==i&&v(r),r&&r.children&&g(r.children),e.target.parentNode||i.insertBefore(e.target,i.childNodes[o]),[2,e]}}))}))}exports.Context=r,exports.SCOPE=e,exports.h=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=t&&t.key;return{type:e,props:t,children:n,key:void 0===i?null:i}},exports.mount=function(e,t,n){return void 0===t&&(t=document.body),void 0===n&&(n=e.constructor()),c(this,void 0,void 0,(function(){return a(this,(function(r){switch(r.label){case 0:if(!(t instanceof HTMLElement))throw new Error("[Synks] Container should be valid HTMLElement");return e instanceof Array||(e=[e]),[4,k(e,n,t,0,{})];case 1:return[2,r.sent()]}}))}))};