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) · 6.19 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,e,f){return e||(e=null),{type:a,props:b,children:c,element:d,key:e,flag:f}}function c(a,c){return c||(c=null),b(a,v,w,c,null,3)}function d(a){return"string"==typeof a&&(a=document.querySelector(a)),e(a),3===a.nodeType?c(a.nodeValue,a):b(a.nodeName.toLowerCase(),v,w.map.call(a.childNodes,d),a,null,0)}function e(a){for(var b,c=0;c<a.childNodes.length;c++)b=a.childNodes[c],8!==b.nodeType&&(3!==b.nodeType||/\S/.test(b.nodeValue))?1===b.nodeType&&e(b):(a.removeChild(b),c--)}function f(...a){function c(a,b=new WeakMap){if(Object(a)!==a)return a;if(b.has(a))return b.get(a);const d=a instanceof Date?new Date(a):a instanceof RegExp?new RegExp(a.source,a.flags):a.constructor?new a.constructor:Object.create(null);return b.set(a,d),Object.assign(d,...Object.keys(a).map(d=>({[d]:c(a[d],b)})))}return(Array.isArray(a[0])?a.unshift([]):a.unshift({}),Array.isArray(a[0]))?a.reduce((d,a)=>Array.prototype.concat(d,c(a))):"object"==typeof a[0]?a.reduce((d,a)=>Object.assign(d,c(a))):void 0}function g(a){return a.currentTarget.events[a.type](a)}function h(a){return null==a?null:a.key}function i(a,b,c){for(var d,e,f={};b<=c;)null!=(d=(e=a[b]).key)&&(f[d]=e),b++;return f}function j(a,b,c,d,e){if("key"!==b)if("style"===b&&"object"==typeof d)for(var h in f(c,d)){var i=null==d||null==d[h]?"":d[h];"-"===h[0]?a[b].setProperty(h,i):a[b][h]=i}else if("o"===b[0]&&"n"===b[1])b=b.slice(2).toLowerCase(),a.events||(a.events={}),a.events[b]=d,null==d?a.removeEventListener(b,g):null==c&&a.addEventListener(b,g);else{"list"!==b&&b in a&&!e?a[b]=null==d?"":d:null==d||!1===d?a.removeAttribute(b):"xlink-href"===b||"xlinkHref"===b?(a.setAttributeNS("http://www.w3.org/1999/xlink","href",d),a.setAttribute("href",d)):a.setAttribute(b,d)}}function k(a,b){var c=3===a.flag?document.createTextNode(a.type):(b=b||"svg"===a.type)?document.createElementNS("http://www.w3.org/2000/svg",a.type):document.createElement(a.type);var d=a.props;d.onmount&&x.push(function(){d.onmount(c)});for(var e=0,f=a.children.length;e<f;)c.appendChild(k(a.children[e],b)),e++;for(var g in d)j(c,g,null,d[g],b);return a.element=c}function l(a){for(var b=0,c=a.children.length;b<c;)l(a.children[b]),b++;return a.element}function m(a,b){var c=function(){a.removeChild(l(b))},d=b.props&&b.props.onunmount;null==d?c():d(c,b.element)}function n(a,b,c,d){for(var e in f(b,c))("value"==e||"checked"==e||"selected"==e?a[e]:b[e])!==c[e]&&j(a,e,b[e],c[e],d);var g=a.vnode&&a.vnode.type===0?c.onmount:c.onupdate;null!=g&&x.push(function(){g(a,b,c)})}function o(a,b,c,d,e){if(null!=c&&3===c.flag&&3===d.flag)c.type!==d.type&&(b.nodeValue=d.type);else if(null==c||c.type!==d.type){var f=a.insertBefore(k(d,e),b);null!=c&&m(a,c),b=f}else if(d!==c){n(b,c.props,d.props,e=e||"svg"===d.type);for(var g,j,l,p,q=c.children,r=0,s=q.length-1,t=d.children,u=0,v=t.length-1;u<=v&&r<=s&&(l=h(q[r]),p=h(t[u]),null!=l&&l===p);)o(b,q[r].element,q[r],t[u],e),r++,u++;for(;u<=v&&r<=s&&(l=h(q[s]),p=h(t[v]),null!=l&&l===p);)o(b,q[s].element,q[s],t[v],e),s--,v--;if(r>s)for(;u<=v;)b.insertBefore(k(t[u++],e),(j=q[r])&&j.element);else if(u>v)for(;r<=s;)m(b,q[r++]);else{for(var w=i(q,r,s),x={};u<=v;){if(l=h(j=q[r]),p=h(t[u]),x[l]||null!=p&&p===h(q[r+1])){null==l&&m(b,j),r++;continue}null==p||0===c.flag?(null==l&&(o(b,j&&j.element,j,t[u],e),u++),r++):(l===p?(o(b,j.element,j,t[u],e),x[p]=!0,r++):null==(g=w[p])?o(b,j&&j.element,null,t[u],e):(o(b,b.insertBefore(g.element,j&&j.element),g,t[u],e),x[p]=!0),u++)}for(;r<=s;)null==h(j=q[r++])&&m(b,j);for(var y in w)null==x[y]&&m(b,w[y])}}return b&&(d.element=b),d}function p(a,b,c){if("string"==typeof c&&(c=document.querySelector(c)),Array.isArray(b))throw new y;if(o(c,a&&a.element,a,b),b!==a)for(;0<x.length;)x.pop()();return b}function q(a,b){return r(a)||s(a,b)||t()}function r(a){if(Array.isArray(a))return a}function s(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function t(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function u(a){for(var b=Object.create(null),c=a=>a&&a.type,d=(a,b)=>(d,e)=>{var f=c(d),g=z.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 v={},w=[],x=[];class y{constructor(){this.message="Cannot insert Fragment tag directly into DOM.",this.toString=function(){return this.message}}}var z=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,d.children=g):b(a,d,g,null,l,1)},a.render=function(a,b,c){if(b="string"==typeof b?document.querySelector(b):b,!b)return console.error("@composi/core Error: You need to provide a valid container to render the component in. Check the element or selector you provided and make sure that it exists in the DOM before trying to render."),void console.error(`@composi/core Message: The container you provided was "${b}"`);var e;c?("string"==typeof c&&(c=document.querySelector(c)),e=b&&b.vnode||d(c)):e=b&&b.vnode;var f=p(e,a,b);b.vnode=f},a.run=function(a){function b(a){j&&c(f(d,a,b))}function c(c){var f,i=a.init();if(c){var j=q(c,2);d=j[0],e=j[1]}else if(i&&i.length){var l=q(i,2);d=l[0],e=l[1],h&&!k&&(f=h(d,b),"function"==typeof f&&f(d,b),k=!0)}else d=[];e&&e(d,b),g(d,b)}var d,e,f=a.update,g=a.view,h=a.subscriptions||a.subs,i=a.done,j=!0,k=!1;return a.send=b,c(d),()=>{j&&(j=!1,i&&i(d))}},a.union=function(a){var b=u(a),c=b.variants,d=b.match;return c.match=d,c},a.batchEffects=a=>(b,c)=>a.map(a=>a&&a(b,c)),a.Fragment=(a,b)=>Array.isArray(a)&&!b?a:b,Object.defineProperty(a,"__esModule",{value:!0})});
//# sourceMappingURL=composi-core.js.map