closures 0.7.1 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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={isSvg:!1,directives:{selected:x("selected"),checked:x("checked"),value:x("value"),innerHTML:x("innerHTML")}},r=[],i=[],o="http://www.w3.org/1999/xlink",l={show:o,actuate:o,href:o},d=1,f=new WeakMap,s=new WeakMap,c=new WeakMap,u=e=>{},p=e=>"function"==typeof e,h=e=>"string"==typeof e,a=e=>null!==e&&"object"==typeof e,g=e=>Array.isArray(e),v=e=>null===e||!1===e||void 0===e||g(e)&&0===e.length,y=e=>g(e)&&e.length>0,_=e=>h(e)||"number"==typeof e,m=e=>e&&1===e.vtype,w=e=>e&&2===e.vtype,S=e=>e&&4===e.vtype;const k=E;function E(e,...n){let r=n[0];if(!r||!a(r)||g(r)||r.__tag||r.props?r=t:n.shift(),r=n.length>1?Object.assign({},r,{children:n}):1===n.length?Object.assign({},r,{children:n[0]}):r,h(e)){let t=e.indexOf(".");if(~t){let n=e.slice(t+1).replace(/\./g," ");r.class=r.class?n+" "+String(r.class):n,e=e.slice(0,t)}e=e??"div"}return N(e,r,r.key)}function N(e,t,n){if(n!=n)throw new Error("Invalid NaN key");let r=h(e)?1:(i=e)&&p(i.mount)?4:p(e)?2:void 0;var i;if(void 0===r)throw new Error("Invalid VNode type");return{vtype:r,__tag:e,key:n,props:t}}class b{constructor(e,t){this.props=e,this._STATE_={env:t,vnode:null,parentDomNode:null,ref:R(null)},this.render=this.render.bind(this)}setProps(e){this.oldProps=this.props,this.props=e}render(e){let t=this._STATE_,n=t.vnode;if(t.vnode=e,null===t.parentDomNode){let n=function e(t){if(1===t.type)return t.node.parentNode;if(4===t.type)return e(t.children[0]);if(8===t.type)return e(t.childRef);throw new Error("Unkown ref type "+t)}(t.ref);if(null===n)return void(t.ref=R(e,t.env));t.parentDomNode=n}t.ref=O(t.parentDomNode,e,n,t.ref,t.env)}}function R(e,o=n){if(v(e))return{type:1,node:document.createComment("NULL")};if(_(e))return{type:1,node:document.createTextNode(e)};if(m(e)){let t,{__tag:n,props:r}=e;"svg"!==n||o.isSvg||(o=Object.assign({},o,{isSVG:!0})),t=o.isSVG?document.createElementNS("http://www.w3.org/2000/svg",n):document.createElement(n),p(r.oncreate)&&r.oncreate(t),function(e,t,n){for(var r in t)if("key"!==r&&"children"!==r&&!(r in n.directives))if(r.startsWith("on")){let n=i[i.length-1];e[r.toLowerCase()]=n?n.__tag.event(t[r]):t[r]}else V(e,r,t[r],n.isSVG)}(t,r,o);let l=null==r.children?r.children:R(r.children,o);return null!=l&&P(t,l),function(e,t,n){for(let r in t)r in n.directives&&n.directives[r].mount(e,t[r])}(t,r,o),{type:1,node:t,children:l}}if(y(e))return{type:4,children:e.map(e=>R(e,o))};if(w(e)){let n=e.__tag(e.props);if(p(n)){let o,l=n,p=(d++).toString(),h=f.get(e.__tag)??{};return e.id=p,o=function(e,n){let o=r.pop()??u,l={key:e.key,id:e.id,vtype:4,props:e.props||{},__tag:{view:n,removeFromParent:u,event:u,mount:d,patch:d,unmount:e=>{let n;if(o(),n=c.get(l)){for(let e=0;e<n.length;e++)A(n[e],t);c.delete(l)}l.__tag.removeFromParent()}}};function d(e){l.__tag.event=t=>r=>{t(r),i.push(l),e.render(n({...e.props})),i.pop()},i.push(l),e.render(n({...e.props})),i.pop()}return l}(e,l),h[p]=o,f.set(e.__tag,h),s.set(o,e.__tag),R(o)}return{type:8,childRef:R(n,o),childState:n}}if(S(e)){let t,n=new b(e.props,o);if(t=i[i.length-1]){let n=s.get(e),r=c.get(t)||[],i=r.length;e.__tag.removeFromParent=e=>r.splice(i,1),r.push({id:e.id,vtype:2,__tag:n}),c.set(t,r)}return e.__tag.mount(n),{type:8,childRef:n._STATE_.ref,childState:n}}if(e instanceof Node)return{type:1,node:e};if(void 0===e)throw new Error("mount: vnode is undefined!");throw new Error("mount: Invalid Vnode!")}function T(e,t,r,o,l=n){if(a(r)&&a(t)&&(t.id=r.id),r===t)return o;if(v(t)&&v(r))return o;if(_(t)&&_(r))return o.node.nodeValue=t,o;if(m(t)&&m(r)&&t.__tag===r.__tag){"svg"!==t.__tag||l.isSvg||(l=Object.assign({},l,{isSVG:!0})),function(e,t,n,r){for(var o in t)if("key"!==o&&"children"!==o&&!(o in r.directives)){var l=n[o],d=t[o];if(l!==d)if(o.startsWith("on")){let t=i[i.length-1];e[o.toLowerCase()]=t?t.__tag.event(d):d}else V(e,o,d,r.isSVG)}for(o in n)"key"===o||"children"===o||o in r.directives||o in t||(o.startsWith("on")?e[o.toLowerCase()]=null:e.removeAttribute(o))}(o.node,t.props,r.props,l);let e=r.props.children,n=t.props.children;return null==e?null!=n&&(o.children=R(n,l),P(o.node,o.children)):null==n?(o.node.textContent="",A(e,o.children,l),o.children=null):o.children=O(o.node,n,e,o.children,l),function(e,t,n,r){for(let i in t)i in r.directives&&r.directives[i].patch(e,t[i],n[i]);for(let i in n)i in r.directives&&!(i in t)&&r.directives[i].unmount(e,n[i])}(o.node,t.props,r.props,l),o}if(y(t)&&y(r))return function(e,t,n,r,i){let o,l,d,f,s,c=function e(t){if(1===t.type)return t.node.nextSibling;if(4===t.type)return e(t.children[t.children.length-1]);if(8===t.type)return e(t.childRef);throw new Error("Unkown ref type "+JSON.stringify(t))}(r),u=Array(t.length),p=r.children,h=0,a=0,g=t.length-1,v=n.length-1;for(;h<=g&&a<=v;){if(null===p[a]){a++;continue}if(null===p[v]){v--;continue}if(o=n[a],l=t[h],l.key===o.key){d=p[a],f=u[h]=O(e,l,o,d,i),h++,a++;continue}if(o=n[v],l=t[g],l.key===o.key){d=p[v],f=u[g]=O(e,l,o,d,i),g--,v--;continue}if(null==s){s={};for(let e=a;e<=v;e++)o=n[e],null!=o.key&&(s[o.key]=e)}l=t[h];let r=null!=l.key?s[l.key]:null;null!=r?(o=n[r],d=p[r],f=u[h]=T(e,l,o,d,i),P(e,f,j(p[a])),f!==d&&(U(e,d),A(o,d,i)),p[r]=null):(f=u[h]=R(l,i),P(e,f,j(p[a]))),h++}let y=g<t.length-1?j(u[g+1]):c;for(;h<=g;){let n=R(t[h],i);u[h]=n,P(e,n,y),h++}for(;a<=v;)d=p[a],null!=d&&(U(e,d),A(n[a],d,i)),a++;r.children=u}(e,t,r,o,l),o;if(w(t)&&w(r)&&t.__tag===r.__tag){let n=t.__tag;if(null!=n.shouldUpdate?n.shouldUpdate(r.props,t.props):function(e,t){if(e===t)return!1;for(let n in t)if(e[n]!==t[n])return!0;return!1}(r.props,t.props)){let i,d=r.id,s=f.get(n);if(s&&d&&(i=s[d]))return T(e,{...i,props:t.props},i,o);let c=n(t.props),u=T(e,c,o.childState,o.childRef,l);return u!==o.childRef?{type:8,childRef:u,childState:c}:(o.childState=c,o)}return o}if(S(t)&&S(r)&&t.__tag===r.__tag){let n=o.childState,r=n._STATE_;return r.env=l,r.parentNode=e,n.setProps(t.props),t.__tag.patch(n),o.childRef!==r.ref?{type:8,childRef:r.ref,childState:n}:o}return t instanceof Node&&r instanceof Node?(o.node=t,o):R(t,l)}function A(e,t,n){if(m(e))!function(e,t,n){for(let r in t)r in n.directives&&n.directives[r].unmount(e,t[r])}(t.node,e.props,n),null!=e.props.children&&A(e.props.children,t.children,n);else if(y(e))e.forEach((e,r)=>A(e,t.children[r],n));else if(w(e)){let r,i=f.get(e.__tag);if(i&&e.id&&(r=i[e.id]))return delete i[e.id],s.delete(r),A(r,t,n);A(t.childState,t.childRef,n)}else S(e)&&e.__tag.unmount(t.childState)}function O(e,t,n,r,i){let o=T(e,t,n,r,i);return o!==r&&(!function(e,t,n){P(e,t,j(n)),U(e,n)}(e,o,r),A(n,r,i)),o}function x(e){return{mount(t,n){t[e]=n},patch(t,n,r){n!==r&&(t[e]=n)},unmount(t,n){t[e]=null}}}function j(e){if(1===e.type)return e.node;if(4===e.type)return j(e.children[0]);if(8===e.type)return j(e.childRef);throw new Error("Unkown ref type "+JSON.stringify(e))}function P(e,t,n){if(1===t.type)e.insertBefore(t.node,n);else if(4===t.type)t.children.forEach(t=>{P(e,t,n)});else{if(8!==t.type)throw new Error("Unkown ref type "+JSON.stringify(t));P(e,t.childRef,n)}}function U(e,t){if(1===t.type)e.removeChild(t.node);else if(4===t.type)t.children.forEach(t=>{U(e,t)});else{if(8!==t.type)throw new Error("Unkown ref type "+t);U(e,t.childRef)}}function V(e,t,n,r){if(!0===n)e.setAttribute(t,"");else if(!1===n)e.removeAttribute(t);else{var i=r?l[t]:void 0;void 0!==i?e.setAttributeNS(i,t,n):e.setAttribute(t,n)}}e.Fragment=e=>e.children,e.h=E,e.jsx=N,e.m=k,e.onRemove=e=>r.push(e),e.render=function(e,t,r={}){let i=t.$$PETIT_DOM_REF,o=Object.assign({},n);if(Object.assign(o.directives,r.directives),null==i){let n=R(e,o);t.$$PETIT_DOM_REF={ref:n,vnode:e},t.textContent="",P(t,n,null)}else i.ref=O(t,e,i.vnode,i.ref,o),i.vnode=e}}));
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)}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "closures",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Minimalist virtual dom library",
5
5
  "type": "module",
6
6
  "main": "dist/closures.cjs",