closures 0.7.3 → 0.7.4

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/dist/closures.cjs CHANGED
@@ -32,9 +32,9 @@ let NIL = void 0,
32
32
  NS_ATTRS = { show: XLINK_NS, actuate: XLINK_NS, href: XLINK_NS },
33
33
  REF_SINGLE = 1, // ref with single dom node
34
34
  VTYPE_ELEMENT = 1,
35
+ VTYPE_FUNCTION = 2,
35
36
  REF_ARRAY = 4, // ref with array of nodes
36
37
  REF_PARENT = 8, // ref with a child ref
37
- VTYPE_FUNCTION = 2,
38
38
  RETAIN_KEY = '=',
39
39
  generateClosureId = _ => NUM++,
40
40
  isFn = x => typeof x === 'function',
@@ -517,8 +517,6 @@ function h(_t, ...children) {
517
517
  let vtype =
518
518
  isStr(_t)
519
519
  ? VTYPE_ELEMENT
520
- : _t && isFn(_t.mount)
521
- ? VTYPE_COMPONENT
522
520
  : isFn(_t)
523
521
  ? VTYPE_FUNCTION
524
522
  : NIL;
@@ -527,7 +525,7 @@ function h(_t, ...children) {
527
525
 
528
526
  // returns a vnode
529
527
  return {
530
- vtype, // (number) VTYPE_ELEMENT | VTYPE_COMPONENT | VTYPE_FUNCTION
528
+ vtype, // (number) VTYPE_ELEMENT | VTYPE_FUNCTION
531
529
  _t, // (string | object | function)
532
530
  key: props.key, // string
533
531
  props // object
package/dist/closures.js CHANGED
@@ -32,9 +32,9 @@ let NIL = void 0,
32
32
  NS_ATTRS = { show: XLINK_NS, actuate: XLINK_NS, href: XLINK_NS },
33
33
  REF_SINGLE = 1, // ref with single dom node
34
34
  VTYPE_ELEMENT = 1,
35
+ VTYPE_FUNCTION = 2,
35
36
  REF_ARRAY = 4, // ref with array of nodes
36
37
  REF_PARENT = 8, // ref with a child ref
37
- VTYPE_FUNCTION = 2,
38
38
  RETAIN_KEY = '=',
39
39
  generateClosureId = _ => NUM++,
40
40
  isFn = x => typeof x === 'function',
@@ -517,8 +517,6 @@ export function h(_t, ...children) {
517
517
  let vtype =
518
518
  isStr(_t)
519
519
  ? VTYPE_ELEMENT
520
- : _t && isFn(_t.mount)
521
- ? VTYPE_COMPONENT
522
520
  : isFn(_t)
523
521
  ? VTYPE_FUNCTION
524
522
  : NIL;
@@ -527,7 +525,7 @@ export function h(_t, ...children) {
527
525
 
528
526
  // returns a vnode
529
527
  return {
530
- vtype, // (number) VTYPE_ELEMENT | VTYPE_COMPONENT | VTYPE_FUNCTION
528
+ vtype, // (number) VTYPE_ELEMENT | VTYPE_FUNCTION
531
529
  _t, // (string | object | function)
532
530
  key: props.key, // string
533
531
  props // object
@@ -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=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)}));
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,p=e=>"string"==typeof e,u=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=>p(e)||"number"==typeof e,g=e=>e&&1===e.vtype,k=e=>e&&2===e.vtype,R=e=>{let t=e.type;if(1===t)return e.node;if(8===t)return R(e.childRef);if(4===t)return R(e.children[0]);throw Error("Unknown ref type "+y(e))},S=e=>{let t=e.type;if(1===t)return e.node.nextSibling;if(8===t)return S(e.childRef);if(4===t)return S(e.children[e.children.length-1]);throw Error("Unknown ref type "+y(e))},_=(e,t,r)=>{let n=t.type;if(1===n)e.insertBefore(t.node,r);else if(8===n)_(e,t.childRef,r);else{if(4!==n)throw Error("Unknown ref type "+y(t));for(let n=0;n<t.children.length;n++)_(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&&_(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)=>{_(e,t,R(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(u(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),_(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,p,u,a=S(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(p===t)for(l=m,p={};l<=k;l++)c=n[l],c&&c.key!==t&&(p[c.key]=l);s=r[w],d=s&&s.key!==t?p[s.key]:t,d!==t?(c=n[d],f=v[d],h=y[w]=A(e,s,c,f,o),_(e,h,R(v[m])),h!==f&&(E(e,f),b(c,f,o)),v[d]=t):(h=y[w]=V(s,o),_(e,h,R(v[m]))),w++}else k--;else m++;for(u=g<r.length-1?R(y[g+1]):a;w<=g;)h=V(r[w],o),y[w]=h,_(e,h,u),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 G(e,...r){let n,i=r[0];if(!i||!u(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,p(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=p(e)?1:h(e)?2:t;if(o===t)throw new Error("Invalid VNode type");return{vtype:o,_t:e,key:i.key,props:i}}G.retain=e=>G("=");const C=G;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="",_(r,o,t),l.redraw=(t=e)=>{d.ref=x(r,t,d.vnode,d.ref,l),d.vnode=t}},e.h=G,e.m=C,e.onRemove=e=>o.push(e)}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "closures",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Minimalist virtual dom library",
5
5
  "type": "module",
6
6
  "main": "dist/closures.cjs",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "devDependencies": {
20
20
  "bundt": "1.1.5",
21
- "flitch": "0.7.2",
21
+ "flitch": "0.7.3",
22
22
  "jsdom": "^15.1.1"
23
23
  },
24
24
  "keywords": [