closures 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +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}}));
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "closures",
3
+ "version": "0.7.1",
4
+ "description": "Minimalist virtual dom library",
5
+ "type": "module",
6
+ "main": "dist/closures.cjs",
7
+ "module": "dist/closures.js",
8
+ "unpkg": "dist/closures.min.js",
9
+ "umd:name": "closures",
10
+ "repository": "https://github.com/kevinfiol/closures",
11
+ "license": "MIT",
12
+ "engines": {
13
+ "node": ">=12.x"
14
+ },
15
+ "files": [
16
+ "*.d.ts",
17
+ "dist"
18
+ ],
19
+ "devDependencies": {
20
+ "bundt": "1.1.5",
21
+ "flitch": "0.7.2",
22
+ "jsdom": "^15.1.1"
23
+ },
24
+ "keywords": [
25
+ "javascript",
26
+ "virtual dom"
27
+ ],
28
+ "scripts": {
29
+ "test": "node test/index.js",
30
+ "build": "bundt index.js"
31
+ }
32
+ }