closures 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -1
- package/dist/closures.cjs +428 -618
- package/dist/closures.js +426 -614
- package/dist/closures.min.js +1 -1
- package/package.json +1 -1
package/dist/closures.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.closures={})}(this,(function(e){let t={},n={
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.closures={})}(this,(function(e){let t=void 0,r=e=>{},n=e=>({mount(t,r){t[e]=r},patch(t,r,n){r!==n&&(t[e]=r)},unmount(r){r[e]=t}}),i={isSVG:!1,redraw:r,directives:{selected:n("selected"),checked:n("checked"),value:n("value"),innerHTML:n("innerHTML")}},o=[],l=new WeakMap,d=1,c={},s="http://www.w3.org/1999/xlink",f={show:s,actuate:s,href:s},h=e=>"function"==typeof e,u=e=>"string"==typeof e,p=e=>null!==e&&"object"==typeof e,a=e=>Array.isArray(e),y=e=>JSON.stringify(e),v=e=>null===e||!1===e||e===t||a(e)&&0===e.length||e&&"="===e._t,w=e=>a(e)&&e.length>0,m=e=>u(e)||"number"==typeof e,g=e=>e&&1===e.vtype,k=e=>e&&2===e.vtype,_=e=>{let t=e.type;if(1===t)return e.node;if(8===t)return _(e.childRef);if(4===t)return _(e.children[0]);throw Error("Unknown ref type "+y(e))},R=e=>{let t=e.type;if(1===t)return e.node.nextSibling;if(8===t)return R(e.childRef);if(4===t)return R(e.children[e.children.length-1]);throw Error("Unknown ref type "+y(e))},S=(e,t,r)=>{let n=t.type;if(1===n)e.insertBefore(t.node,r);else if(8===n)S(e,t.childRef,r);else{if(4!==n)throw Error("Unknown ref type "+y(t));for(let n=0;n<t.children.length;n++)S(e,t.children[n],r)}},E=(e,t)=>{let r=t.type;if(1===r)e.removeChild(t.node);else if(8===r)E(e,t.childRef);else{if(4!==r)throw Error("Unknown ref type "+y(t));for(let r=0;r<t.children.length;r++)E(e,t.children[r])}},N=(e,t,r,n)=>{"className"===t&&(t="class"),!0===r?e.setAttribute(t,""):!1===r?e.removeAttribute(t):n&&f[t]?e.setAttributeNS(f[t],t,r):e.setAttribute(t,r)},V=(e,n,i,c,s=r)=>{let f={closureId:i,closure:c,onRemove:s};if(v(e))return{...f,type:1,node:document.createComment("NULL")};if(m(e))return{...f,type:1,node:document.createTextNode(e)};if(g(e)){let r,{_t:i,props:o}=e;"svg"!==i||n.isSVG||(n={...n,isSVG:!0}),r=n.isSVG?document.createElementNS("http://www.w3.org/2000/svg",i):document.createElement(i),h(o.oncreate)&&o.oncreate(r),((e,t,r)=>{for(let n in t)"key"===n||"children"===n||"oncreate"===n||n in r.directives||(n.startsWith("on")?e[n.toLowerCase()]=e=>{t[n](e),!r.manualRedraw&&r.redraw()}:N(e,n,t[n],r.isSVG))})(r,o,n);let l=o.children===t?o.children:V(o.children,n);return l!==t&&S(r,l),((e,t,r)=>{for(let n in t)n in r.directives&&r.directives[n].mount(e,t[n])})(r,o,n),{...f,type:1,node:r,children:l}}if(w(e)){let t=0,r=[];for(;t<e.length;t++)r.push(V(e[t],n));return{...f,type:4,children:r}}if(k(e)){let t=e._t(e.props);if(h(t)){let i=d++,c=l.get(e._t)||new Map,s=o.pop()||r;c.set(i,t),l.set(e._t,c);let f=e._t;return e._t=t,V(e,n,i,f,s)}return{...f,type:8,childRef:V(t,n),childState:t}}if(e instanceof Node)return{...f,type:1,node:e};if(e===t)throw Error("mount: vnode is undefined");throw Error("mount: Invalid vnode")},b=(e,r,n)=>{if(g(e))((e,t,r)=>{for(let n in t)n in r.directives&&r.directives[n].unmount(e,t[n])})(r.node,e.props,n),e.props.children!==t&&b(e.props.children,r.children,n);else if(w(e))for(let t=0;t<e.length;t++)b(e[t],r.children[t],n);else if(k(e)){let e=r.closure,t=r.closureId,i=r.onRemove,o=l.get(e);o&&t&&o.get(t)&&(o.delete(t),!o.size&&l.delete(e),i()),b(r.childState,r.childRef,n)}},x=(e,t,r,n,i)=>{let o=A(e,t,r,n,i);return o!==n&&(((e,t,r)=>{S(e,t,_(r)),E(e,r)})(e,o,n),b(r,n,i)),o},A=(e,r,n,o,d={...i})=>{if(r&&"="===r._t)return o;let c,s;if(p(o)&&(c=o.closure,s=o.closureId),k(r)&&k(n)&&(r._t===n._t||c&&s)){let t,n=r._t,i=l.get(c);i&&s&&(t=i.get(s))&&(n=t);let f=n(r.props),h=A(e,f,o.childState,o.childRef,d);return h!==o.childRef?{type:8,childRef:h,childState:f}:(o.childState=f,o)}if(n===r||v(r)&&v(n))return o;if(m(r)&&m(n))return o.node.nodeValue=r,o;if(g(r)&&g(n)&&r._t===n._t){"svg"!==r._t||d.isSVG||(d={...d,isSVG:!0}),((e,r,n,i)=>{let o;for(o in r){if("key"===o||"children"===o||"oncreate"===o||o in i.directives)continue;let t=n[o],l=r[o];t!==l&&(o.startsWith("on")?e[o.toLowerCase()]=e=>{l(e),!i.manualRedraw&&i.redraw()}:N(e,o,l,i.isSVG))}for(o in n)"key"===o||"children"===o||o in r||o in i.directives||(o.startsWith("on")?e[o.toLowerCase()]=t:e.removeAttribute(o))})(o.node,r.props,n.props,d);let e=n.props.children,i=r.props.children;return e===t?i!==t&&(o.children=V(i,d),S(o.node,o.children)):i===t?(o.node.textContent="",b(e,o.children,d),o.children=t):o.children=x(o.node,i,e,o.children,d),((e,t,r,n)=>{let i;for(i in t)i in n.directives&&n.directives[i].patch(e,t[i],r[i]);for(i in r)i in n.directives&&!(i in t)&&n.directives[i].unmount(e,r[i])})(o.node,r.props,n.props,d),o}return w(r)&&w(n)?(((e,r,n,i,o)=>{let l,d,c,s,f,h,u,p,a=R(i),y=Array(r.length),v=i.children,w=0,m=0,g=r.length-1,k=n.length-1;for(;w<=g&&m<=k;)if(v[m]!==t)if(v[k]!==t)if(c=n[m],s=r[w],c&&s&&s.key===c.key)f=v[m],h=y[w]=x(e,s,c,f,o),w++,m++;else if(c=n[k],s=r[g],c&&s&&s.key===c.key)f=v[k],h=y[g]=x(e,s,c,f,o),g--,k--;else{if(u===t)for(l=m,u={};l<=k;l++)c=n[l],c&&c.key!==t&&(u[c.key]=l);s=r[w],d=s&&s.key!==t?u[s.key]:t,d!==t?(c=n[d],f=v[d],h=y[w]=A(e,s,c,f,o),S(e,h,_(v[m])),h!==f&&(E(e,f),b(c,f,o)),v[d]=t):(h=y[w]=V(s,o),S(e,h,_(v[m]))),w++}else k--;else m++;for(p=g<r.length-1?_(y[g+1]):a;w<=g;)h=V(r[w],o),y[w]=h,S(e,h,p),w++;for(;m<=k;)f=v[m],f!==t&&(E(e,f),b(n[m],f,o)),m++;i.children=y})(e,r,n,o,d),o):r instanceof Node&&n instanceof Node?(o.node=r,o):V(r,d)};function C(e,...r){let n,i=r[0];if(!i||!p(i)||a(i)||i._t||i.props?i=c:r.shift(),i=r.length>1?{...i,children:r}:1===r.length?{...i,children:r[0]}:i,u(e)&&~(n=e.indexOf("."))){let t=e.slice(n+1).replace(/\./g," ");i.class=i.class?t+" "+String(i.class):t,e=e.slice(0,n)}if(i.key!=i.key)throw new Error("Invalid NaN key");let o=u(e)?1:e&&h(e.mount)?VTYPE_COMPONENT:h(e)?2:t;if(o===t)throw new Error("Invalid VNode type");return{vtype:o,_t:e,key:i.key,props:i}}C.retain=e=>C("=");const G=C;e.Fragment=e=>e.children,e.app=function(e,r,n={}){let o,l={...i,manualRedraw:n.manualRedraw},d=r.$_REF;if(l.directives={...l.directives,...n.directives||{}},d!==t)throw Error("App already mounted on this node");return o=V(e,l),d=r.$_REF={ref:o,vnode:e},r.textContent="",S(r,o,t),l.redraw=(t=e)=>{d.ref=x(r,t,d.vnode,d.ref,l),d.vnode=t}},e.h=C,e.m=G,e.onRemove=e=>o.push(e)}));
|