This repository was archived by the owner on Sep 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomposi.js
2 lines (2 loc) · 4.14 KB
/
composi.js
1
2
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports,require("@composi/merge-objects"),require("@composi/get-type")):"function"==typeof define&&define.amd?define(["exports","@composi/merge-objects","@composi/get-type"],b):b(a.composi={},a.mergeObjects,a.getType)})(this,function(a,b,c){"use strict";function d(a,b,c,d,e,f){return{type:a,props:b,children:c,element:d,key:e,flag:f}}function e(a,b){return d(a,t,u,b,null,q)}function f(a){return a.currentTarget.events[a.type](a)}function g(a){return null==a?null:a.key}function h(a,b,c){const d={};let e,f;for(;b<=c;b++)null!=(e=(f=a[b]).key)&&(d[e]=f);return d}function i(a,d,e,g,h){if(e!==g)if("style"===d&&"Object"===c.getType(g))for(let c in b.mergeObjects(e,g)){const b=null==g||null==g[c]?"":g[c];"-"===c[0]?a[d].setProperty(c,b):a[d][c]=b}else if("key"!==d)if("className"===d&&(d="class"),"o"===d[0]&&"n"===d[1])a.events||(a.events={}),d=d.slice(2).toLowerCase(),e||(e=a.events[d]),a.events[d]=g,null==g?a.removeEventListener(d,f):null==e&&a.addEventListener(d,f);else{const b=null==g||!1===g||"no"===g||"off"===g;d in a&&"list"!==d&&"type"!==d&&"draggable"!==d&&"spellcheck"!==d&&"translate"!==d&&!h?(a[d]=null==g?"":g,b&&a.removeAttribute(d)):"xlink-href"===d||"xlinkHref"===d?(a.setAttributeNS(r,"href",g),a.setAttribute("href",g)):b?a.removeAttribute(d):a.setAttribute(d,g)}}function j(a,b,c){let d=a.flag===q?document.createTextNode(a.type):(c=c||"svg"===a.type)?document.createElementNS(s,a.type):document.createElement(a.type);const e=a.props;e.onmount&&b.push(function(){e.onmount(d)});for(let e=0,f=a.children.length;e<f;e++)d.appendChild(j(a.children[e],b,c));for(let f in e)i(d,f,null,e[f],c);return a.element=d}function k(a){for(let b=0,c=a.children.length;b<c;b++)k(a.children[b]);return a.element}function l(a,b){function c(){a&&a.nodeType&&a.removeChild(k(b))}const d=b.props&&b.props.onunmount;null==d?c():d(c,b.element)}function m(a,c,d,e,f,g){for(let h in b.mergeObjects(c,d))("value"==h||"checked"==h?a[h]:c[h])!==d[h]&&i(a,h,c[h],d[h],f);const h=g?d.onmount:d.onupdate;null!=h&&e.push(function(){h(a,c,d)})}function n(a,b,c,d,e,f){if(d===c);else if(null!=c&&c.flag===q&&d.flag===q)c.type!==d.type&&(b.nodeValue=d.type);else if(null==c||c.type!==d.type){const g=a.insertBefore(j(d,e,f),b);null!=c&&l(a,c),b=g}else{m(b,c.props,d.props,e,f=f||"svg"===d.type,c.flag===p);let a,i,k;const o=c.children;let q,r=0,s=o.length-1;const t=d.children;let u=0,v=t.length-1;for(;u<=v&&r<=s&&(k=g(o[r]),q=g(t[u]),null!=k&&k===q);)n(b,o[r].element,o[r],t[u],e,f),r++,u++;for(;u<=v&&r<=s&&(k=g(o[s]),q=g(t[v]),null!=k&&k===q);)n(b,o[s].element,o[s],t[v],e,f),s--,v--;if(r>s)for(;u<=v;)b.insertBefore(j(t[u++],e,f),(i=o[r])&&i.element);else if(u>v)for(;r<=s;)l(b,o[r++]);else{let d=h(o,r,s);const j={};for(;u<=v;){if(k=g(i=o[r]),q=g(t[u]),j[k]||null!=q&&q===g(o[r+1])){null==k&&l(b,i),r++;continue}null==q||c.flag===p?(null==k&&(n(b,i&&i.element,i,t[u],e,f),u++),r++):(k===q?(n(b,i.element,i,t[u],e,f),j[q]=!0,r++):null==(a=d[q])?n(b,i&&i.element,null,t[u],e,f):(n(b,b.insertBefore(a.element,i&&i.element),a,t[u],e,f),j[q]=!0),u++)}for(;r<=s;)null==g(i=o[r++])&&l(b,i);for(let a in d)null==j[a]&&l(b,d[a])}}return d.element=b,d}function o(a,b,c){"string"==typeof b&&(b=document.querySelector(b));const d=[];if(!c){if(Array.isArray(a))throw new v;const c=j(a,d);b.appendChild(c),a.element=c}else n(b,c.element,c,a,d);if(a!==c)for(;0<d.length;)d.pop()();return a.element.isMounted=!0,a}const p=0,q=3,r="http://www.w3.org/1999/xlink",s="http://www.w3.org/2000/svg",t={},u=[];class v{constructor(){this.message="Cannot insert Fragment tag directly into DOM.",this.toString=function(){return this.message}}}a.Fragment=(a,b)=>b,a.h=function(a,b,...c){let f;const g=[],h=[];let i=c.length;b=b||{};const j=b.key;for(;0<i--;)g.push(c[i]);for(null!=b.children&&(0>=g.length&&g.push(b.children),delete b.children);0<g.length;)if(Array.isArray(f=g.pop()))for(i=f.length;0<i--;)g.push(f[i]);else if(!1===f||!0===f||null==f);else h.push("object"==typeof f?f:e(f));return delete b.key,"function"==typeof a?a(b,b.children=h):d(a,b,h,null,j,1)},a.render=function(a,b,c){return o(a,b,c)},Object.defineProperty(a,"__esModule",{value:!0})});
//# sourceMappingURL=composi.js.map