This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcomposi-core.js
2 lines (2 loc) · 4.86 KB
/
composi-core.js
1
2
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a.composi={})})(this,function(a){"use strict";function b(a,b,c,d){var e=4<arguments.length&&arguments[4]!==void 0?arguments[4]:null,f=5<arguments.length&&arguments[5]!==void 0?arguments[5]:null;return{type:a,props:b,children:c,node:d,flag:f,key:e}}function c(a,c){return b(a,p,q,c,null,3)}function d(c,a){return Object.assign({},c,a)}function e(a){this.handlers[a.type](a)}function f(a,b,c,f,g){if("key"===b);else if("style"===b&&"object"==typeof f)for(var h in d(c,f)){var i=null==f||null==f[h]?"":f[h];"-"===h[0]?a[b].setProperty(h,i):a[b][h]=i}else"o"===b[0]&&"n"===b[1]?((a.handlers||(a.handlers={}))[b=b.slice(2).toLowerCase()]=f)?!c&&a.addEventListener(b,e):a.removeEventListener(b,e):"list"!==b&&"form"!==b&&"type"!==b&&"draggable"!==b&&"spellcheck"!==b&&b in a&&!g?a[b]=null==f?"":f:null==f||!1===f?a.removeAttribute(b):a.setAttribute(b,f)}function g(a,b,c){var d=3===a.flag?document.createTextNode(a.type):(c=c||"svg"===a.type)?document.createElementNS("http://www.w3.org/2000/svg",a.type):document.createElement(a.type),e=a.props;for(var h in e.onmount&&b.push(function(){e.onmount(d)}),e)f(d,h,null,e[h],c);for(var j=0,k=a.children.length;j<k;j++)d.appendChild(g(a.children[j],b,c));return a.node=d}function h(a){return null==a?null:a.key}function j(a){for(var b=0,c=a.children.length;b<c;b++)j(a.children[b]);var d=a.props.ondestroy;return null!=d&&d(a.node),a.node}function k(a,b){var c=function(){a.removeChild(j(b))},d=b.props&&b.props.onunmount;null==d?c():d(b.node,c)}function l(a,b,c,e,j){if(c===e);else null!=c&&3===c.flag&&3===e.flag?c.type!==e.type&&(b.nodeValue=e.type):null==c||c.type!==e.type?(b=a.insertBefore(g(e,r,j),b),null!=c&&k(a,c)):function(){var a,m,n,o,p=c.props,q=e.props,s=c.children,t=e.children,u=0,v=0,w=s.length-1,x=t.length-1;for(var y in j=j||"svg"===e.type,d(p,q))("value"==y||"selected"==y||"checked"==y?b[y]:p[y])!==q[y]&&function(){f(b,y,p[y],q[y],j);var a=q.onupdate;null!=a&&r.push(function(){a(b,p,q)})}();for(;v<=x&&u<=w&&null!=(n=h(s[u]))&&n===h(t[v]);)l(b,s[u].node,s[u++],t[v++],j);for(;v<=x&&u<=w&&null!=(n=h(s[w]))&&n===h(t[x]);)l(b,s[w].node,s[w--],t[x--],j);if(u>w)for(;v<=x;)b.insertBefore(g(t[v++],r,j),(m=s[u])&&m.node);else if(v>x)for(;u<=w;)k(b,s[u++]);else{var i,z,A;for(i=u,z={},A={};i<=w;i++)null!=(n=s[i].key)&&(z[n]=s[i]);for(;v<=x;){if(n=h(m=s[u]),o=h(t[v]),A[n]||null!=o&&o===h(s[u+1])){null==n&&k(b,m),u++;continue}null==o||0===c.flag?(null==n&&(l(b,m&&m.node,m,t[v],j),v++),u++):(n===o?(l(b,m.node,m,t[v],j),A[o]=!0,u++):null==(a=z[o])?l(b,m&&m.node,null,t[v],j):(l(b,b.insertBefore(a.node,m&&m.node),a,t[v],j),A[o]=!0),v++)}for(;u<=w;)null==h(m=s[u++])&&k(b,m);for(var B in z)null==A[B]&&k(b,z[B])}}();return e.node=b}function m(a){return a.nodeType===3?c(a.nodeValue,a):b(a.nodeName.toLowerCase(),p,Array.prototype.map.call(a.childNodes,m),a,null,0)}function n(a,b){!a.vdom&&b.props.onmount&&r.push(function(){b.props.onmount(a)});for(var c=l(a.parentNode,a,a.vdom||m(a),b).vdom=b;0<r.length;)r.pop()();return c}function o(a){for(var b=Object.create(null),c=a=>a&&a.type,d=(a,b)=>(d,e)=>{var f=c(d),g=s.call(a,f)&&a[f];return g?g(d.data,e):b(e)},e=0,f=function(){var c=a[e];b[c]=a=>({type:c,data:a}),e++};e<a.length;)f();return{variants:b,match:function(a,b,c){return d(b,c)(a)}}}var p={},q=[],r=[],s=Object.prototype.hasOwnProperty;a.h=function(a,d){d=d||{};for(var e,f=[],g=[],h=arguments.length,i=Array(2<h?h-2:0),j=2;j<h;j++)i[j-2]=arguments[j];for(var k=i.length,l=d.key;0<k--;)f.push(i[k]);for(d.children&&(0>=f.length&&f.push(d.children),delete d.children);0<f.length;)if(Array.isArray(e=f.pop()))for(var m=e.length;0<m--;)f.push(e[m]);else if(!1===e||!0===e||null==e);else g.push("object"==typeof e?e:c(e));return"function"==typeof a?a(d,g):b(a,d,g,null,l)},a.render=function(a,b){if(Array.isArray(a))throw"Cannot insert Fragment tag directly into DOM.";var c="";if("string"==typeof b&&(c=b,b=document.querySelector(b)),!b){var d="";c&&(d=` The selector you provided was: "${c}"`),console.error(`@composi/core Error: The second parameter for render function was invalid. Check the selector you provided and make sure that it exists in the DOM before trying to render. ${d}`)}n(b,a)},a.run=function(a){function b(a){if(j)return c(g(d,a,b))}function c(a){a?d=a:e&&(d=e()),h&&k&&("function"==typeof h&&h(l,b),k=!1),f(d,b)}var d,e=a.init,f=a.view,g=a.update,h=a.subscriptions||a.subs,i=a.done,j=!0,k=!0,l=()=>d;return a.send=b,c(d),()=>{j&&(j=!1,i&&i(d))}},a.union=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];var d=o(b),e=d.variants,f=d.match;return e.match=f,e},a.batchEffects=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return(a,c)=>b.map(b=>b&&b(a,c))},a.Fragment=(a,b)=>Array.isArray(a)&&!b?a:b,Object.defineProperty(a,"__esModule",{value:!0})});
//# sourceMappingURL=composi-core.js.map