zenith 1.0.0-beta.14 → 1.0.0-beta.15

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.
@@ -24,5 +24,5 @@ export declare const elem: {
24
24
  export declare const compDef: (componentDefinition: VNodeCompDefinition) => VNodeCompDefinition;
25
25
  export declare const comp: (componentDefinition: VNodeCompDefinition, attrs?: VNodeCompAttributes) => VNodeComp;
26
26
  export declare const node: (el: Element) => VNodeNode;
27
- export declare const bind: (el: Element, vNodeAnyOrArray: VNodeAny | VNodeArray) => VNodeComp;
27
+ export declare const bind: (el: Element, vNodeAnyOrArray: VNodeAny | VNodeArray | null) => VNodeComp;
28
28
  export { ns };
@@ -62,7 +62,7 @@ export interface VNodeComp<A extends VNodeCompAttributes = VNodeCompAttributes>
62
62
  }
63
63
  export interface VNodeNode extends VNodeBase {
64
64
  is: typeof VNODE_NODE;
65
- $tag: string;
65
+ $tag: number;
66
66
  $def: null;
67
67
  attrs: null;
68
68
  nodes: null;
@@ -1,4 +1,4 @@
1
- /*! Zenith Helpers v1.0.0-beta.14 | MIT License | © 2022-2025 Daniel Barber */
1
+ /*! Zenith Helpers v1.0.0-beta.15 | MIT License | © 2022-2025 Daniel Barber */
2
2
  import { node, draw } from './zenith.js';
3
3
 
4
4
  const keep = () => true;
@@ -1,2 +1,2 @@
1
- /*! Zenith Helpers v1.0.0-beta.14 | MIT License | © 2022-2025 Daniel Barber */
1
+ /*! Zenith Helpers v1.0.0-beta.15 | MIT License | © 2022-2025 Daniel Barber */
2
2
  !function(e){"use strict";const signal=e=>{let t=e;const o=new Set,n=()=>{for(const e of o)e(t)};return{get val(){return t},set val(e){t!==e&&(t=e,n())},sub:e=>(o.add(e),()=>o.delete(e)),notify:n}},t={keep:()=>!0,is:{elem:1,text:2,comp:3,node:4,compDef:5},cls:(...e)=>e.filter(Boolean).join(" "),slot:(e,t)=>{if(e)return"function"==typeof e?e(t):e},html:t=>{const o=document.createElement("div");o.innerHTML=t+"";const n=[...o.childNodes].map(t=>e.node(t));return 1===n.length?n[0]:n},closest:(e,t)=>{for(let o=e.up;o;o=o.up)if(t(o))return o},inject:(e,...t)=>{const o={},n=new Set(t);for(let t=e.up;t&&n.size>0;t=t.up)if(3===t.is&&t.provide)for(const e of n)void 0!==t.provide[e]&&(o[e]=t.provide[e],n.delete(e));return o},signal:signal,derived:(e,t)=>{const o=signal(e()),n=t.map(t=>t.sub(()=>{o.val=e()}));return o.destroy=()=>{for(const e of n)e();n.length=0},o},router:(t,o={})=>{const n="history"===o.mode,r=n?"popstate":"hashchange",s=()=>n?location.pathname:location.hash.slice(1)||"/",c=[],a=e=>{for(const t of c){const o=e.match(t.regex);if(o){const e={};for(let n=0;t.keys.length>n;n++)e[t.keys[n]]=o[n+1];return{component:t.component,params:e}}}return{component:t["*"]||null,params:{}}};for(const e in t){const o=[],n=e.replace(/:[^/]+/g,e=>(o.push(e.slice(1)),"([^/]+)")).replace(/\*/g,"(.*)");c.push({regex:RegExp(`^${n}$`),keys:o,component:t[e]})}return{init:t=>{const o=t,n=a(s());o.route=n.component,o.params=n.params,o.onroute=()=>{const t=a(s());o.route=t.component,o.params=t.params,e.draw(o,!0)},window.addEventListener(r,o.onroute)},draw:e=>{var t;return null==(t=e.route)?void 0:t.call(e,e.params)},removed:e=>{e.onroute&&window.removeEventListener(r,e.onroute)}}},Portal:{to:e=>"string"==typeof e.attrs.to?document.querySelector(e.attrs.to):e.attrs.to,draw:e=>e.attrs.children}};window.zh=t}(z);
@@ -1,2 +1,2 @@
1
- /*! Zenith Helpers v1.0.0-beta.14 | MIT License | © 2022-2025 Daniel Barber */
1
+ /*! Zenith Helpers v1.0.0-beta.15 | MIT License | © 2022-2025 Daniel Barber */
2
2
  import{node as e,draw as t}from"./zenith.js";const keep=()=>!0,is={elem:1,text:2,comp:3,node:4,compDef:5},cls=(...e)=>e.filter(Boolean).join(" "),slot=(e,t)=>{if(e)return"function"==typeof e?e(t):e},html=t=>{const o=document.createElement("div");o.innerHTML=t+"";const n=[...o.childNodes].map(t=>e(t));return 1===n.length?n[0]:n},closest=(e,t)=>{for(let o=e.up;o;o=o.up)if(t(o))return o},inject=(e,...t)=>{const o={},n=new Set(t);for(let t=e.up;t&&n.size>0;t=t.up)if(3===t.is&&t.provide)for(const e of n)void 0!==t.provide[e]&&(o[e]=t.provide[e],n.delete(e));return o},signal=e=>{let t=e;const o=new Set,n=()=>{for(const e of o)e(t)};return{get val(){return t},set val(e){t!==e&&(t=e,n())},sub:e=>(o.add(e),()=>o.delete(e)),notify:n}},derived=(e,t)=>{const o=signal(e()),n=t.map(t=>t.sub(()=>{o.val=e()}));return o.destroy=()=>{for(const e of n)e();n.length=0},o},router=(e,o={})=>{const n="history"===o.mode,r=n?"popstate":"hashchange",s=()=>n?location.pathname:location.hash.slice(1)||"/",a=[],c=t=>{for(const e of a){const o=t.match(e.regex);if(o){const t={};for(let n=0;e.keys.length>n;n++)t[e.keys[n]]=o[n+1];return{component:e.component,params:t}}}return{component:e["*"]||null,params:{}}};for(const t in e){const o=[],n=t.replace(/:[^/]+/g,e=>(o.push(e.slice(1)),"([^/]+)")).replace(/\*/g,"(.*)");a.push({regex:RegExp(`^${n}$`),keys:o,component:e[t]})}return{init:e=>{const o=e,n=c(s());o.route=n.component,o.params=n.params,o.onroute=()=>{const e=c(s());o.route=e.component,o.params=e.params,t(o,!0)},window.addEventListener(r,o.onroute)},draw:e=>{var t;return null==(t=e.route)?void 0:t.call(e,e.params)},removed:e=>{e.onroute&&window.removeEventListener(r,e.onroute)}}},Portal={to:e=>"string"==typeof e.attrs.to?document.querySelector(e.attrs.to):e.attrs.to,draw:e=>e.attrs.children};export{Portal,closest,cls,derived,html,inject,is,keep,router,signal,slot};
@@ -1,4 +1,4 @@
1
- /*! Zenith v1.0.0-beta.14 | MIT License | © 2022-2025 Daniel Barber */
1
+ /*! Zenith v1.0.0-beta.15 | MIT License | © 2022-2025 Daniel Barber */
2
2
  const VNODE_ELEM = 1;
3
3
  const VNODE_TEXT = 2;
4
4
  const VNODE_COMP = 3;
@@ -45,7 +45,7 @@ const sync = () => {
45
45
  if (!--remaining) break;
46
46
  }
47
47
  if (redrawQueue.size) Promise.resolve().then(sync);
48
- if (active && active !== document.activeElement && typeof active.focus === "function") {
48
+ if (active && document.activeElement === document.body) {
49
49
  active.focus();
50
50
  }
51
51
  }
@@ -74,7 +74,7 @@ const draw = (vNode, surgical) => {
74
74
  const _flattenReusableArray = [];
75
75
  const _flatten = (nodes, offset = 0, arr = []) => {
76
76
  let node2;
77
- if (!(nodes && typeof nodes === "object" && nodes.length != null)) {
77
+ if (!nodes || nodes.length == null) {
78
78
  _flattenReusableArray[0] = nodes;
79
79
  nodes = _flattenReusableArray;
80
80
  }
@@ -131,7 +131,7 @@ const _place = (vNode, parentEl, next) => {
131
131
  }
132
132
  return next;
133
133
  };
134
- const _updateNode = (parentNode, parentEl, newNode, oldNode, xmlns, skipMemo) => {
134
+ const _updateNode = (parentNode, parentEl, newNode, oldNode, xmlns) => {
135
135
  if (oldNode.el) {
136
136
  const newNodeType = newNode.is;
137
137
  if (newNodeType === oldNode.is) {
@@ -166,7 +166,7 @@ const _updateNode = (parentNode, parentEl, newNode, oldNode, xmlns, skipMemo) =>
166
166
  newNode.el = oldNode.el;
167
167
  newNode.$h = oldNode.$h;
168
168
  newNode.nodes = oldNode.nodes;
169
- if (skipMemo || oldNode.$tag & FLAG_IS_STALE || !newNode.$def.$memo || (newNode.$def.$memo === true ? newNode.attrs !== oldNode.attrs : !newNode.$def.$memo(newNode.attrs, oldNode.attrs))) {
169
+ if (oldNode.$tag & FLAG_IS_STALE || !(newNode.$def.$memo && (newNode.$def.$memo === true ? newNode.attrs === oldNode.attrs : newNode.$def.$memo(newNode.attrs, oldNode.attrs)))) {
170
170
  newNode.$tag &= ~FLAG_IS_STALE;
171
171
  _redrawComponent(newNode, parentEl, xmlns);
172
172
  }
@@ -188,7 +188,7 @@ const _updateNode = (parentNode, parentEl, newNode, oldNode, xmlns, skipMemo) =>
188
188
  _create(parentNode, parentEl, newNode, xmlns);
189
189
  }
190
190
  };
191
- const _updateNodes = (parentNode, parentEl, newNodes, oldNodes, xmlns, depth = 0) => {
191
+ const _updateNodes = (parentNode, parentEl, newNodes, oldNodes, xmlns) => {
192
192
  const newNodesLength = newNodes.length;
193
193
  const oldNodesLength = oldNodes.length;
194
194
  if (newNodesLength) {
@@ -379,21 +379,21 @@ const _unmount = (nodes) => {
379
379
  nodes = nodes;
380
380
  for (let i = 0; i < nodes.length; i++) {
381
381
  const node2 = nodes[i];
382
+ redrawQueue.delete(node2);
382
383
  if (node2.is === VNODE_COMP) {
383
- if (node2.$tag & FLAG_HAS_REMOVE || node2.$def.remove) {
384
+ if (node2.$tag & FLAG_HAS_REMOVE) {
384
385
  if (!(node2.$tag & FLAG_REMOVE_CALLED)) {
385
386
  node2.$def.remove(node2);
386
387
  }
387
388
  }
388
- if (node2.$tag & FLAG_HAS_REMOVED || node2.$def.removed) {
389
+ if (node2.$tag & FLAG_HAS_REMOVED) {
389
390
  node2.$def.removed(node2);
390
391
  }
391
392
  }
392
- if (node2.$h && node2.nodes.length) {
393
+ if ((node2.$h || redrawQueue.size) && node2.nodes && node2.nodes.length) {
393
394
  _unmount(node2.nodes);
394
- node2.nodes = null;
395
395
  }
396
- node2.attrs = node2.nodes = node2.$tag = node2.$def = node2.el = node2.up = null;
396
+ node2.$tag = 0;
397
397
  }
398
398
  };
399
399
  const _detach = (vNode) => {
@@ -412,7 +412,7 @@ const _destroy = (vNode) => {
412
412
  };
413
413
  const _remove = (vNode) => {
414
414
  if (vNode.is === VNODE_COMP) {
415
- if (vNode.$tag & FLAG_HAS_REMOVE || vNode.$def.remove) {
415
+ if (vNode.$tag & FLAG_HAS_REMOVE) {
416
416
  if (vNode.$tag & FLAG_IS_REMOVING) {
417
417
  return false;
418
418
  }
@@ -511,10 +511,8 @@ const comp = (componentDefinition, attrs = ALWAYS_EMPTY_OBJECT) => {
511
511
  const node = (el) => {
512
512
  return {
513
513
  is: VNODE_NODE,
514
- $tag: el.nodeName.toLowerCase(),
515
- // string: element name
514
+ $tag: 0,
516
515
  $def: null,
517
- // always null for node
518
516
  attrs: null,
519
517
  nodes: null,
520
518
  up: null,
@@ -526,12 +524,20 @@ const RootWrapper = compDef({
526
524
  });
527
525
  const bind = (el, vNodeAnyOrArray) => {
528
526
  if (el == null) throw new Error("mount");
529
- const rootComp = boundNodes.get(el) || comp(RootWrapper);
530
- rootComp.attrs = { $nodes: vNodeAnyOrArray };
531
- boundNodes.set(rootComp.el = el, rootComp);
532
- draw(rootComp);
527
+ let root = boundNodes.get(el);
528
+ if (vNodeAnyOrArray === null) {
529
+ if (root) {
530
+ _destroy(root);
531
+ boundNodes.delete(el);
532
+ }
533
+ return null;
534
+ }
535
+ root = root || comp(RootWrapper);
536
+ root.attrs = { $nodes: vNodeAnyOrArray };
537
+ boundNodes.set(root.el = el, root);
538
+ draw(root);
533
539
  sync();
534
- return rootComp;
540
+ return root;
535
541
  };
536
542
 
537
543
  export { bind, comp, compDef, diff, draw, elem, node, ns, sync };
@@ -1,2 +1,2 @@
1
- /*! Zenith v1.0.0-beta.14 | MIT License | © 2022-2025 Daniel Barber */
2
- const e=new Map,t=new Set,ns={math:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg"},s=[],l={},n=new Map,sync=()=>{let s,l=t.size;if(l){const n=document.activeElement;for(const n of t)if(s=e.has(n.el)?n.el:n.attrs&&n.attrs.to||n.el&&n.el.parentNode||n.up&&n.up.el,t.delete(n),s&&g(n,s),! --l)break;t.size&&Promise.resolve().then(sync),n&&n!==document.activeElement&&"function"==typeof n.focus&&n.focus()}},draw=(e,s)=>{if(s)3===e.is&&(e.$tag|=2),t.add(e);else{let s;for(s=e;s.up;s=s.up);for(t.add(s),s=e;s.up;s=s.up)if(3===s.is){if(2&s.$tag)break;s.$tag|=2}}1===t.size&&Promise.resolve().then(sync)},r=[],o=(e,t=0,s=[])=>{let l;for(e&&"object"==typeof e&&null!=e.length||(r[0]=e,e=r);e.length>t;t++)if(l=e[t],Array.isArray(l))o(l,0,s);else if(null!=l)if(l.is){if(void 0===s.$keys)s.$keys=l.attrs&&"$key"in l.attrs?n:null;else if(!s.$keys!=!(l.attrs&&"$key"in l.attrs))throw Error("$keys");s.push(l)}else if(!0!==l&&!1!==l){if(void 0===s.$keys)s.$keys=null;else if(s.$keys)throw Error("$keys");s.push({is:2,$tag:l+"",$def:null,attrs:null,nodes:null,up:null,el:null})}return s},i=e=>{if(3===e.is&&!e.attrs.to){for(let t=e.nodes.length-1;t>=0;t--){const s=i(e.nodes[t]);if(s)return s}return null}return e.el},a=(e,t,s)=>{if(3!==e.is||e.attrs.to)e.el&&(e.el.nextSibling!==s&&t.insertBefore(e.el,s),s=e.el);else for(let l=e.nodes.length-1;l>=0;l--)s=a(e.nodes[l],t,s);return s},f=(e,t,s,l,n,r)=>{if(l.el){const o=s.is;if(o===l.is)if(1===o)if(s.up=e,s.$tag===l.$tag){s.el=l.el,s.$h=l.$h;const e=s.attrs.$diff||6;2&e&&$(s,l.attrs),4&e?d(s,s.el,s.nodes,l.nodes,s.attrs.xmlns||ns[s.$tag]||n):s.nodes=l.nodes}else u(e,t,s,n),t.insertBefore(s.el,l.el),h(l);else 2===o?(s.el=l.el,s.$tag!==l.$tag&&(s.el.textContent=s.$tag)):3===o?(4&l.$tag&&(l.$tag&=-5),s.up=e,s.$def===l.$def?(s.el=l.el,s.$h=l.$h,s.nodes=l.nodes,(r||2&l.$tag||!s.$def.$memo||(!0===s.$def.$memo?s.attrs!==l.attrs:!s.$def.$memo(s.attrs,l.attrs)))&&(s.$tag&=-3,g(s,t,n))):(u(e,t,s,n),h(l))):4===o&&s.el!==l.el&&(t.insertBefore(s.el,null),l.el.remove());else u(e,t,s,n),h(l)}else u(e,t,s,n)},d=(e,t,s,l,n,r=0)=>{const o=s.length,d=l.length;if(o){let r,$,g=0;if(d)if(s.$keys&&l.$keys){for(;o>g&&d>g&&s[g].attrs.$key===l[g].attrs.$key;)f(e,t,s[g],l[g],n),g++;if(o>g||d>g){const c=new Map;for(let e=g;d>e;e++)c.set(l[e].attrs.$key,l[e]);const m=i(l[d-1]);let p=m?m.nextSibling:null;for(let l=o-1;l>=g;l--){if($=s[l],r=c.get($.attrs.$key),r)if(c.delete($.attrs.$key),3===$.is&&$.attrs.$remove){if(!(4&r.$tag)&&h(r)){s.splice(l,1);continue}r.up=e,s[l]=r}else f(e,t,$,r,n);else{if($.attrs.$remove){s.splice(l,1);continue}u(e,t,$,n)}p=a(s[l],t,p)}for(const e of c.values())h(e)}}else{for(let e=o;d>e;e++)h(l[e]);for(let i=0;o>i;i++)r=l[i],$=s[i],r&&r.el?f(e,t,$,r,n):u(e,t,$,n)}else for(;o>g;g++)u(e,t,s[g],n)}else if(1===e.is)t.textContent="",m(l);else for(let e=0;d>e;e++)h(l[e]);e.nodes=s},$=(e,t=l)=>{let s,n;const r=e.el,o=e.attrs;for(s in"input"===e.$tag&&o.type&&r.setAttribute("type",o.type),o){const i=o[s];if("o"===s[0]&&"n"===s[1])i!==t[s]&&(r[s]="function"==typeof i?t=>{!1===i.call(t.currentTarget,t)&&(t.preventDefault(),t.stopPropagation()),!1!==t.draw&&draw(e)}:null);else if("$"!==s[0]&&("type"!==s||"input"!==e.$tag)&&"is"!==s&&"xmlns"!==s)if(n=typeof i,"string"===n||"number"===n)"value"===s?i!==t[s]&&(r.value=i):i!==t[s]&&r.setAttribute(s,i+"");else if(!0===i)!0!==t[s]&&r.setAttribute(s,s);else if(i){if("style"===s){if("string"==typeof t.style)r.removeAttribute("style");else for(const e in t.style||l)e in i||(r.style[e]="");Object.assign(r.style,i)}}else t[s]&&r.removeAttribute(s)}for(s in t)s in o||("o"===s[0]&&"n"===s[1]?r[s]=null:r.removeAttribute(s))},u=(e,t,s,l)=>{if(1===s.is){s.up=e,s.el=(l=s.attrs&&s.attrs.xmlns||ns[s.$tag]||l)?document.createElementNS(l,s.$tag,s.attrs.is?{is:s.attrs.is}:null):document.createElement(s.$tag,s.attrs.is?{is:s.attrs.is}:null),$(s);for(let e=0;s.nodes.length>e;e++)u(s,s.el,s.nodes[e],l);t.insertBefore(s.el,null)}else if(2===s.is)s.el=document.createTextNode(s.$tag),t.insertBefore(s.el,null);else if(3===s.is){if(s.up=e,s.$def.init&&s.$def.init(s),s.nodes=o(s.$def.draw(s)),8&s.$tag)for(let e=s;e&&!e.$h;e=e.up)e.$h=!0;s.attrs.to&&(s.el=document.createComment(""),t.insertBefore(s.el,null));for(let e=0;s.nodes.length>e;e++)u(s,s.attrs.to||t,s.nodes[e],l);s.el||(s.el=s.nodes[0]&&s.nodes[0].el),s.$def.drawn&&s.$def.drawn(s,!0)}else 4===s.is&&t.insertBefore(s.el,null)},g=(e,t,s)=>{const l=e.nodes,n=e.$def.draw(e,l);e.$tag&=-3,n!==l&&(d(e,e.attrs.to||t,o(n),l,s),e.el||(e.el=e.nodes[0]&&e.nodes[0].el)),e.$def.drawn&&e.$def.drawn(e)},c=[],m=e=>{Array.isArray(e)||(c[0]=e,e=c);for(let t=0;e.length>t;t++){const s=e[t];3===s.is&&((16&s.$tag||s.$def.remove)&&(64&s.$tag||s.$def.remove(s)),(32&s.$tag||s.$def.removed)&&s.$def.removed(s)),s.$h&&s.nodes.length&&(m(s.nodes),s.nodes=null),s.attrs=s.nodes=s.$tag=s.$def=s.el=s.up=null}},p=e=>{if(3===e.is){for(let t=0;e.nodes.length>t;t++)p(e.nodes[t]);e.attrs.to&&e.el&&e.el.remove()}else e.el&&e.el.remove()},y=e=>{p(e),m(e)},h=e=>{if(3===e.is&&(16&e.$tag||e.$def.remove)){if(4&e.$tag)return!1;e.$tag|=68;const t=e.$def.remove(e);if(t&&t.then){const s=()=>{if(4&e.$tag){const t=e.up;if(t){const s=t.nodes.indexOf(e);-1!==s&&t.nodes.splice(s,1)}y(e),draw(t)}};return t.then(s,s),!1}}return y(e),!0},compDef=e=>Object.freeze({is:5,$tag:1|(e.remove?16:0)|(e.removed?32:0)|(e.remove||e.removed?8:0),...e}),comp=(e,t=l)=>({is:3,$tag:e.$tag||0,$def:e,attrs:t,nodes:s,up:null,el:null}),v=compDef({draw:e=>e.attrs.$nodes});window.z={elem:function(e){const t=arguments[1],n=t&&"object"==typeof t&&!Array.isArray(t)&&!("$tag"in t);return{is:1,$tag:e,$def:null,attrs:n?t:l,nodes:arguments.length>(n?2:1)?o(arguments,n?2:1):s,up:null,el:null}},comp:comp,node:e=>({is:4,$tag:e.nodeName.toLowerCase(),$def:null,attrs:null,nodes:null,up:null,el:e}),compDef:compDef,bind:(t,s)=>{const l=e.get(t)||comp(v);return l.attrs={$nodes:s},e.set(l.el=t,l),draw(l),sync(),l},draw:draw,ns:ns,diff:{none:1,self:2,nodes:4,all:6}};
1
+ /*! Zenith v1.0.0-beta.15 | MIT License | © 2022-2025 Daniel Barber */
2
+ const e=new Map,t=new Set,ns={math:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg"},s=[],l={},n=new Map,sync=()=>{let s,l=t.size;if(l){const n=document.activeElement;for(const n of t)if(s=e.has(n.el)?n.el:n.attrs&&n.attrs.to||n.el&&n.el.parentNode||n.up&&n.up.el,t.delete(n),s&&g(n,s),! --l)break;t.size&&Promise.resolve().then(sync),n&&document.activeElement===document.body&&n.focus()}},draw=(e,s)=>{if(s)3===e.is&&(e.$tag|=2),t.add(e);else{let s;for(s=e;s.up;s=s.up);for(t.add(s),s=e;s.up;s=s.up)if(3===s.is){if(2&s.$tag)break;s.$tag|=2}}1===t.size&&Promise.resolve().then(sync)},r=[],o=(e,t=0,s=[])=>{let l;for(e&&null!=e.length||(r[0]=e,e=r);e.length>t;t++)if(l=e[t],Array.isArray(l))o(l,0,s);else if(null!=l)if(l.is){if(void 0===s.$keys)s.$keys=l.attrs&&"$key"in l.attrs?n:null;else if(!s.$keys!=!(l.attrs&&"$key"in l.attrs))throw Error("$keys");s.push(l)}else if(!0!==l&&!1!==l){if(void 0===s.$keys)s.$keys=null;else if(s.$keys)throw Error("$keys");s.push({is:2,$tag:l+"",$def:null,attrs:null,nodes:null,up:null,el:null})}return s},i=e=>{if(3===e.is&&!e.attrs.to){for(let t=e.nodes.length-1;t>=0;t--){const s=i(e.nodes[t]);if(s)return s}return null}return e.el},a=(e,t,s)=>{if(3!==e.is||e.attrs.to)e.el&&(e.el.nextSibling!==s&&t.insertBefore(e.el,s),s=e.el);else for(let l=e.nodes.length-1;l>=0;l--)s=a(e.nodes[l],t,s);return s},f=(e,t,s,l,n)=>{if(l.el){const r=s.is;if(r===l.is)if(1===r)if(s.up=e,s.$tag===l.$tag){s.el=l.el,s.$h=l.$h;const e=s.attrs.$diff||6;2&e&&$(s,l.attrs),4&e?d(s,s.el,s.nodes,l.nodes,s.attrs.xmlns||ns[s.$tag]||n):s.nodes=l.nodes}else u(e,t,s,n),t.insertBefore(s.el,l.el),h(l);else 2===r?(s.el=l.el,s.$tag!==l.$tag&&(s.el.textContent=s.$tag)):3===r?(4&l.$tag&&(l.$tag&=-5),s.up=e,s.$def===l.$def?(s.el=l.el,s.$h=l.$h,s.nodes=l.nodes,(2&l.$tag||!s.$def.$memo||!(!0===s.$def.$memo?s.attrs===l.attrs:s.$def.$memo(s.attrs,l.attrs)))&&(s.$tag&=-3,g(s,t,n))):(u(e,t,s,n),h(l))):4===r&&s.el!==l.el&&(t.insertBefore(s.el,null),l.el.remove());else u(e,t,s,n),h(l)}else u(e,t,s,n)},d=(e,t,s,l,n)=>{const r=s.length,o=l.length;if(r){let d,$,g=0;if(o)if(s.$keys&&l.$keys){for(;r>g&&o>g&&s[g].attrs.$key===l[g].attrs.$key;)f(e,t,s[g],l[g],n),g++;if(r>g||o>g){const c=new Map;for(let e=g;o>e;e++)c.set(l[e].attrs.$key,l[e]);const m=i(l[o-1]);let p=m?m.nextSibling:null;for(let l=r-1;l>=g;l--){if($=s[l],d=c.get($.attrs.$key),d)if(c.delete($.attrs.$key),3===$.is&&$.attrs.$remove){if(!(4&d.$tag)&&h(d)){s.splice(l,1);continue}d.up=e,s[l]=d}else f(e,t,$,d,n);else{if($.attrs.$remove){s.splice(l,1);continue}u(e,t,$,n)}p=a(s[l],t,p)}for(const e of c.values())h(e)}}else{for(let e=r;o>e;e++)h(l[e]);for(let o=0;r>o;o++)d=l[o],$=s[o],d&&d.el?f(e,t,$,d,n):u(e,t,$,n)}else for(;r>g;g++)u(e,t,s[g],n)}else if(1===e.is)t.textContent="",m(l);else for(let e=0;o>e;e++)h(l[e]);e.nodes=s},$=(e,t=l)=>{let s,n;const r=e.el,o=e.attrs;for(s in"input"===e.$tag&&o.type&&r.setAttribute("type",o.type),o){const i=o[s];if("o"===s[0]&&"n"===s[1])i!==t[s]&&(r[s]="function"==typeof i?t=>{!1===i.call(t.currentTarget,t)&&(t.preventDefault(),t.stopPropagation()),!1!==t.draw&&draw(e)}:null);else if("$"!==s[0]&&("type"!==s||"input"!==e.$tag)&&"is"!==s&&"xmlns"!==s)if(n=typeof i,"string"===n||"number"===n)"value"===s?i!==t[s]&&(r.value=i):i!==t[s]&&r.setAttribute(s,i+"");else if(!0===i)!0!==t[s]&&r.setAttribute(s,s);else if(i){if("style"===s){if("string"==typeof t.style)r.removeAttribute("style");else for(const e in t.style||l)e in i||(r.style[e]="");Object.assign(r.style,i)}}else t[s]&&r.removeAttribute(s)}for(s in t)s in o||("o"===s[0]&&"n"===s[1]?r[s]=null:r.removeAttribute(s))},u=(e,t,s,l)=>{if(1===s.is){s.up=e,s.el=(l=s.attrs&&s.attrs.xmlns||ns[s.$tag]||l)?document.createElementNS(l,s.$tag,s.attrs.is?{is:s.attrs.is}:null):document.createElement(s.$tag,s.attrs.is?{is:s.attrs.is}:null),$(s);for(let e=0;s.nodes.length>e;e++)u(s,s.el,s.nodes[e],l);t.insertBefore(s.el,null)}else if(2===s.is)s.el=document.createTextNode(s.$tag),t.insertBefore(s.el,null);else if(3===s.is){if(s.up=e,s.$def.init&&s.$def.init(s),s.nodes=o(s.$def.draw(s)),8&s.$tag)for(let e=s;e&&!e.$h;e=e.up)e.$h=!0;s.attrs.to&&(s.el=document.createComment(""),t.insertBefore(s.el,null));for(let e=0;s.nodes.length>e;e++)u(s,s.attrs.to||t,s.nodes[e],l);s.el||(s.el=s.nodes[0]&&s.nodes[0].el),s.$def.drawn&&s.$def.drawn(s,!0)}else 4===s.is&&t.insertBefore(s.el,null)},g=(e,t,s)=>{const l=e.nodes,n=e.$def.draw(e,l);e.$tag&=-3,n!==l&&(d(e,e.attrs.to||t,o(n),l,s),e.el||(e.el=e.nodes[0]&&e.nodes[0].el)),e.$def.drawn&&e.$def.drawn(e)},c=[],m=e=>{Array.isArray(e)||(c[0]=e,e=c);for(let s=0;e.length>s;s++){const l=e[s];t.delete(l),3===l.is&&(16&l.$tag&&(64&l.$tag||l.$def.remove(l)),32&l.$tag&&l.$def.removed(l)),(l.$h||t.size)&&l.nodes&&l.nodes.length&&m(l.nodes),l.$tag=0}},p=e=>{if(3===e.is){for(let t=0;e.nodes.length>t;t++)p(e.nodes[t]);e.attrs.to&&e.el&&e.el.remove()}else e.el&&e.el.remove()},y=e=>{p(e),m(e)},h=e=>{if(3===e.is&&16&e.$tag){if(4&e.$tag)return!1;e.$tag|=68;const t=e.$def.remove(e);if(t&&t.then){const s=()=>{if(4&e.$tag){const t=e.up;if(t){const s=t.nodes.indexOf(e);-1!==s&&t.nodes.splice(s,1)}y(e),draw(t)}};return t.then(s,s),!1}}return y(e),!0},compDef=e=>Object.freeze({is:5,$tag:1|(e.remove?16:0)|(e.removed?32:0)|(e.remove||e.removed?8:0),...e}),comp=(e,t=l)=>({is:3,$tag:e.$tag||0,$def:e,attrs:t,nodes:s,up:null,el:null}),v=compDef({draw:e=>e.attrs.$nodes});window.z={elem:function(e){const t=arguments[1],n=t&&"object"==typeof t&&!Array.isArray(t)&&!("$tag"in t);return{is:1,$tag:e,$def:null,attrs:n?t:l,nodes:arguments.length>(n?2:1)?o(arguments,n?2:1):s,up:null,el:null}},comp:comp,node:e=>({is:4,$tag:0,$def:null,attrs:null,nodes:null,up:null,el:e}),compDef:compDef,bind:(t,s)=>{let l=e.get(t);return null===s?(l&&(y(l),e.delete(t)),null):(l=l||comp(v),l.attrs={$nodes:s},e.set(l.el=t,l),draw(l),sync(),l)},draw:draw,ns:ns,diff:{none:1,self:2,nodes:4,all:6}};
package/dist/zenith.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! Zenith v1.0.0-beta.14 | MIT License | © 2022-2025 Daniel Barber */
2
- const e=new Map,t=new Set,ns={math:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg"},diff={none:1,self:2,nodes:4,all:6},s=[],l={},n=new Map,sync=()=>{let s,l=t.size;if(l){const n=document.activeElement;for(const n of t)if(s=e.has(n.el)?n.el:n.attrs&&n.attrs.to||n.el&&n.el.parentNode||n.up&&n.up.el,t.delete(n),s&&g(n,s),! --l)break;t.size&&Promise.resolve().then(sync),n&&n!==document.activeElement&&"function"==typeof n.focus&&n.focus()}},draw=(e,s)=>{if(s)3===e.is&&(e.$tag|=2),t.add(e);else{let s;for(s=e;s.up;s=s.up);for(t.add(s),s=e;s.up;s=s.up)if(3===s.is){if(2&s.$tag)break;s.$tag|=2}}1===t.size&&Promise.resolve().then(sync)},r=[],o=(e,t=0,s=[])=>{let l;for(e&&"object"==typeof e&&null!=e.length||(r[0]=e,e=r);e.length>t;t++)if(l=e[t],Array.isArray(l))o(l,0,s);else if(null!=l)if(l.is){if(void 0===s.$keys)s.$keys=l.attrs&&"$key"in l.attrs?n:null;else if(!s.$keys!=!(l.attrs&&"$key"in l.attrs))throw Error("$keys");s.push(l)}else if(!0!==l&&!1!==l){if(void 0===s.$keys)s.$keys=null;else if(s.$keys)throw Error("$keys");s.push({is:2,$tag:l+"",$def:null,attrs:null,nodes:null,up:null,el:null})}return s},i=e=>{if(3===e.is&&!e.attrs.to){for(let t=e.nodes.length-1;t>=0;t--){const s=i(e.nodes[t]);if(s)return s}return null}return e.el},a=(e,t,s)=>{if(3!==e.is||e.attrs.to)e.el&&(e.el.nextSibling!==s&&t.insertBefore(e.el,s),s=e.el);else for(let l=e.nodes.length-1;l>=0;l--)s=a(e.nodes[l],t,s);return s},f=(e,t,s,l,n,r)=>{if(l.el){const o=s.is;if(o===l.is)if(1===o)if(s.up=e,s.$tag===l.$tag){s.el=l.el,s.$h=l.$h;const e=s.attrs.$diff||6;2&e&&d(s,l.attrs),4&e?$(s,s.el,s.nodes,l.nodes,s.attrs.xmlns||ns[s.$tag]||n):s.nodes=l.nodes}else u(e,t,s,n),t.insertBefore(s.el,l.el),h(l);else 2===o?(s.el=l.el,s.$tag!==l.$tag&&(s.el.textContent=s.$tag)):3===o?(4&l.$tag&&(l.$tag&=-5),s.up=e,s.$def===l.$def?(s.el=l.el,s.$h=l.$h,s.nodes=l.nodes,(r||2&l.$tag||!s.$def.$memo||(!0===s.$def.$memo?s.attrs!==l.attrs:!s.$def.$memo(s.attrs,l.attrs)))&&(s.$tag&=-3,g(s,t,n))):(u(e,t,s,n),h(l))):4===o&&s.el!==l.el&&(t.insertBefore(s.el,null),l.el.remove());else u(e,t,s,n),h(l)}else u(e,t,s,n)},$=(e,t,s,l,n,r=0)=>{const o=s.length,$=l.length;if(o){let r,d,g=0;if($)if(s.$keys&&l.$keys){for(;o>g&&$>g&&s[g].attrs.$key===l[g].attrs.$key;)f(e,t,s[g],l[g],n),g++;if(o>g||$>g){const c=new Map;for(let e=g;$>e;e++)c.set(l[e].attrs.$key,l[e]);const p=i(l[$-1]);let m=p?p.nextSibling:null;for(let l=o-1;l>=g;l--){if(d=s[l],r=c.get(d.attrs.$key),r)if(c.delete(d.attrs.$key),3===d.is&&d.attrs.$remove){if(!(4&r.$tag)&&h(r)){s.splice(l,1);continue}r.up=e,s[l]=r}else f(e,t,d,r,n);else{if(d.attrs.$remove){s.splice(l,1);continue}u(e,t,d,n)}m=a(s[l],t,m)}for(const e of c.values())h(e)}}else{for(let e=o;$>e;e++)h(l[e]);for(let i=0;o>i;i++)r=l[i],d=s[i],r&&r.el?f(e,t,d,r,n):u(e,t,d,n)}else for(;o>g;g++)u(e,t,s[g],n)}else if(1===e.is)t.textContent="",p(l);else for(let e=0;$>e;e++)h(l[e]);e.nodes=s},d=(e,t=l)=>{let s,n;const r=e.el,o=e.attrs;for(s in"input"===e.$tag&&o.type&&r.setAttribute("type",o.type),o){const i=o[s];if("o"===s[0]&&"n"===s[1])i!==t[s]&&(r[s]="function"==typeof i?t=>{!1===i.call(t.currentTarget,t)&&(t.preventDefault(),t.stopPropagation()),!1!==t.draw&&draw(e)}:null);else if("$"!==s[0]&&("type"!==s||"input"!==e.$tag)&&"is"!==s&&"xmlns"!==s)if(n=typeof i,"string"===n||"number"===n)"value"===s?i!==t[s]&&(r.value=i):i!==t[s]&&r.setAttribute(s,i+"");else if(!0===i)!0!==t[s]&&r.setAttribute(s,s);else if(i){if("style"===s){if("string"==typeof t.style)r.removeAttribute("style");else for(const e in t.style||l)e in i||(r.style[e]="");Object.assign(r.style,i)}}else t[s]&&r.removeAttribute(s)}for(s in t)s in o||("o"===s[0]&&"n"===s[1]?r[s]=null:r.removeAttribute(s))},u=(e,t,s,l)=>{if(1===s.is){s.up=e,s.el=(l=s.attrs&&s.attrs.xmlns||ns[s.$tag]||l)?document.createElementNS(l,s.$tag,s.attrs.is?{is:s.attrs.is}:null):document.createElement(s.$tag,s.attrs.is?{is:s.attrs.is}:null),d(s);for(let e=0;s.nodes.length>e;e++)u(s,s.el,s.nodes[e],l);t.insertBefore(s.el,null)}else if(2===s.is)s.el=document.createTextNode(s.$tag),t.insertBefore(s.el,null);else if(3===s.is){if(s.up=e,s.$def.init&&s.$def.init(s),s.nodes=o(s.$def.draw(s)),8&s.$tag)for(let e=s;e&&!e.$h;e=e.up)e.$h=!0;s.attrs.to&&(s.el=document.createComment(""),t.insertBefore(s.el,null));for(let e=0;s.nodes.length>e;e++)u(s,s.attrs.to||t,s.nodes[e],l);s.el||(s.el=s.nodes[0]&&s.nodes[0].el),s.$def.drawn&&s.$def.drawn(s,!0)}else 4===s.is&&t.insertBefore(s.el,null)},g=(e,t,s)=>{const l=e.nodes,n=e.$def.draw(e,l);e.$tag&=-3,n!==l&&($(e,e.attrs.to||t,o(n),l,s),e.el||(e.el=e.nodes[0]&&e.nodes[0].el)),e.$def.drawn&&e.$def.drawn(e)},c=[],p=e=>{Array.isArray(e)||(c[0]=e,e=c);for(let t=0;e.length>t;t++){const s=e[t];3===s.is&&((16&s.$tag||s.$def.remove)&&(64&s.$tag||s.$def.remove(s)),(32&s.$tag||s.$def.removed)&&s.$def.removed(s)),s.$h&&s.nodes.length&&(p(s.nodes),s.nodes=null),s.attrs=s.nodes=s.$tag=s.$def=s.el=s.up=null}},m=e=>{if(3===e.is){for(let t=0;e.nodes.length>t;t++)m(e.nodes[t]);e.attrs.to&&e.el&&e.el.remove()}else e.el&&e.el.remove()},y=e=>{m(e),p(e)},h=e=>{if(3===e.is&&(16&e.$tag||e.$def.remove)){if(4&e.$tag)return!1;e.$tag|=68;const t=e.$def.remove(e);if(t&&t.then){const s=()=>{if(4&e.$tag){const t=e.up;if(t){const s=t.nodes.indexOf(e);-1!==s&&t.nodes.splice(s,1)}y(e),draw(t)}};return t.then(s,s),!1}}return y(e),!0},elem=function(e){const t=arguments[1],n=t&&"object"==typeof t&&!Array.isArray(t)&&!("$tag"in t);return{is:1,$tag:e,$def:null,attrs:n?t:l,nodes:arguments.length>(n?2:1)?o(arguments,n?2:1):s,up:null,el:null}},compDef=e=>Object.freeze({is:5,$tag:1|(e.remove?16:0)|(e.removed?32:0)|(e.remove||e.removed?8:0),...e}),comp=(e,t=l)=>({is:3,$tag:e.$tag||0,$def:e,attrs:t,nodes:s,up:null,el:null}),node=e=>({is:4,$tag:e.nodeName.toLowerCase(),$def:null,attrs:null,nodes:null,up:null,el:e}),v=compDef({draw:e=>e.attrs.$nodes}),bind=(t,s)=>{const l=e.get(t)||comp(v);return l.attrs={$nodes:s},e.set(l.el=t,l),draw(l),sync(),l};export{bind,comp,compDef,diff,draw,elem,node,ns,sync};
1
+ /*! Zenith v1.0.0-beta.15 | MIT License | © 2022-2025 Daniel Barber */
2
+ const e=new Map,t=new Set,ns={math:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg"},diff={none:1,self:2,nodes:4,all:6},s=[],l={},n=new Map,sync=()=>{let s,l=t.size;if(l){const n=document.activeElement;for(const n of t)if(s=e.has(n.el)?n.el:n.attrs&&n.attrs.to||n.el&&n.el.parentNode||n.up&&n.up.el,t.delete(n),s&&g(n,s),! --l)break;t.size&&Promise.resolve().then(sync),n&&document.activeElement===document.body&&n.focus()}},draw=(e,s)=>{if(s)3===e.is&&(e.$tag|=2),t.add(e);else{let s;for(s=e;s.up;s=s.up);for(t.add(s),s=e;s.up;s=s.up)if(3===s.is){if(2&s.$tag)break;s.$tag|=2}}1===t.size&&Promise.resolve().then(sync)},r=[],o=(e,t=0,s=[])=>{let l;for(e&&null!=e.length||(r[0]=e,e=r);e.length>t;t++)if(l=e[t],Array.isArray(l))o(l,0,s);else if(null!=l)if(l.is){if(void 0===s.$keys)s.$keys=l.attrs&&"$key"in l.attrs?n:null;else if(!s.$keys!=!(l.attrs&&"$key"in l.attrs))throw Error("$keys");s.push(l)}else if(!0!==l&&!1!==l){if(void 0===s.$keys)s.$keys=null;else if(s.$keys)throw Error("$keys");s.push({is:2,$tag:l+"",$def:null,attrs:null,nodes:null,up:null,el:null})}return s},i=e=>{if(3===e.is&&!e.attrs.to){for(let t=e.nodes.length-1;t>=0;t--){const s=i(e.nodes[t]);if(s)return s}return null}return e.el},a=(e,t,s)=>{if(3!==e.is||e.attrs.to)e.el&&(e.el.nextSibling!==s&&t.insertBefore(e.el,s),s=e.el);else for(let l=e.nodes.length-1;l>=0;l--)s=a(e.nodes[l],t,s);return s},f=(e,t,s,l,n)=>{if(l.el){const r=s.is;if(r===l.is)if(1===r)if(s.up=e,s.$tag===l.$tag){s.el=l.el,s.$h=l.$h;const e=s.attrs.$diff||6;2&e&&d(s,l.attrs),4&e?$(s,s.el,s.nodes,l.nodes,s.attrs.xmlns||ns[s.$tag]||n):s.nodes=l.nodes}else u(e,t,s,n),t.insertBefore(s.el,l.el),h(l);else 2===r?(s.el=l.el,s.$tag!==l.$tag&&(s.el.textContent=s.$tag)):3===r?(4&l.$tag&&(l.$tag&=-5),s.up=e,s.$def===l.$def?(s.el=l.el,s.$h=l.$h,s.nodes=l.nodes,(2&l.$tag||!s.$def.$memo||!(!0===s.$def.$memo?s.attrs===l.attrs:s.$def.$memo(s.attrs,l.attrs)))&&(s.$tag&=-3,g(s,t,n))):(u(e,t,s,n),h(l))):4===r&&s.el!==l.el&&(t.insertBefore(s.el,null),l.el.remove());else u(e,t,s,n),h(l)}else u(e,t,s,n)},$=(e,t,s,l,n)=>{const r=s.length,o=l.length;if(r){let $,d,g=0;if(o)if(s.$keys&&l.$keys){for(;r>g&&o>g&&s[g].attrs.$key===l[g].attrs.$key;)f(e,t,s[g],l[g],n),g++;if(r>g||o>g){const c=new Map;for(let e=g;o>e;e++)c.set(l[e].attrs.$key,l[e]);const p=i(l[o-1]);let m=p?p.nextSibling:null;for(let l=r-1;l>=g;l--){if(d=s[l],$=c.get(d.attrs.$key),$)if(c.delete(d.attrs.$key),3===d.is&&d.attrs.$remove){if(!(4&$.$tag)&&h($)){s.splice(l,1);continue}$.up=e,s[l]=$}else f(e,t,d,$,n);else{if(d.attrs.$remove){s.splice(l,1);continue}u(e,t,d,n)}m=a(s[l],t,m)}for(const e of c.values())h(e)}}else{for(let e=r;o>e;e++)h(l[e]);for(let o=0;r>o;o++)$=l[o],d=s[o],$&&$.el?f(e,t,d,$,n):u(e,t,d,n)}else for(;r>g;g++)u(e,t,s[g],n)}else if(1===e.is)t.textContent="",p(l);else for(let e=0;o>e;e++)h(l[e]);e.nodes=s},d=(e,t=l)=>{let s,n;const r=e.el,o=e.attrs;for(s in"input"===e.$tag&&o.type&&r.setAttribute("type",o.type),o){const i=o[s];if("o"===s[0]&&"n"===s[1])i!==t[s]&&(r[s]="function"==typeof i?t=>{!1===i.call(t.currentTarget,t)&&(t.preventDefault(),t.stopPropagation()),!1!==t.draw&&draw(e)}:null);else if("$"!==s[0]&&("type"!==s||"input"!==e.$tag)&&"is"!==s&&"xmlns"!==s)if(n=typeof i,"string"===n||"number"===n)"value"===s?i!==t[s]&&(r.value=i):i!==t[s]&&r.setAttribute(s,i+"");else if(!0===i)!0!==t[s]&&r.setAttribute(s,s);else if(i){if("style"===s){if("string"==typeof t.style)r.removeAttribute("style");else for(const e in t.style||l)e in i||(r.style[e]="");Object.assign(r.style,i)}}else t[s]&&r.removeAttribute(s)}for(s in t)s in o||("o"===s[0]&&"n"===s[1]?r[s]=null:r.removeAttribute(s))},u=(e,t,s,l)=>{if(1===s.is){s.up=e,s.el=(l=s.attrs&&s.attrs.xmlns||ns[s.$tag]||l)?document.createElementNS(l,s.$tag,s.attrs.is?{is:s.attrs.is}:null):document.createElement(s.$tag,s.attrs.is?{is:s.attrs.is}:null),d(s);for(let e=0;s.nodes.length>e;e++)u(s,s.el,s.nodes[e],l);t.insertBefore(s.el,null)}else if(2===s.is)s.el=document.createTextNode(s.$tag),t.insertBefore(s.el,null);else if(3===s.is){if(s.up=e,s.$def.init&&s.$def.init(s),s.nodes=o(s.$def.draw(s)),8&s.$tag)for(let e=s;e&&!e.$h;e=e.up)e.$h=!0;s.attrs.to&&(s.el=document.createComment(""),t.insertBefore(s.el,null));for(let e=0;s.nodes.length>e;e++)u(s,s.attrs.to||t,s.nodes[e],l);s.el||(s.el=s.nodes[0]&&s.nodes[0].el),s.$def.drawn&&s.$def.drawn(s,!0)}else 4===s.is&&t.insertBefore(s.el,null)},g=(e,t,s)=>{const l=e.nodes,n=e.$def.draw(e,l);e.$tag&=-3,n!==l&&($(e,e.attrs.to||t,o(n),l,s),e.el||(e.el=e.nodes[0]&&e.nodes[0].el)),e.$def.drawn&&e.$def.drawn(e)},c=[],p=e=>{Array.isArray(e)||(c[0]=e,e=c);for(let s=0;e.length>s;s++){const l=e[s];t.delete(l),3===l.is&&(16&l.$tag&&(64&l.$tag||l.$def.remove(l)),32&l.$tag&&l.$def.removed(l)),(l.$h||t.size)&&l.nodes&&l.nodes.length&&p(l.nodes),l.$tag=0}},m=e=>{if(3===e.is){for(let t=0;e.nodes.length>t;t++)m(e.nodes[t]);e.attrs.to&&e.el&&e.el.remove()}else e.el&&e.el.remove()},y=e=>{m(e),p(e)},h=e=>{if(3===e.is&&16&e.$tag){if(4&e.$tag)return!1;e.$tag|=68;const t=e.$def.remove(e);if(t&&t.then){const s=()=>{if(4&e.$tag){const t=e.up;if(t){const s=t.nodes.indexOf(e);-1!==s&&t.nodes.splice(s,1)}y(e),draw(t)}};return t.then(s,s),!1}}return y(e),!0},elem=function(e){const t=arguments[1],n=t&&"object"==typeof t&&!Array.isArray(t)&&!("$tag"in t);return{is:1,$tag:e,$def:null,attrs:n?t:l,nodes:arguments.length>(n?2:1)?o(arguments,n?2:1):s,up:null,el:null}},compDef=e=>Object.freeze({is:5,$tag:1|(e.remove?16:0)|(e.removed?32:0)|(e.remove||e.removed?8:0),...e}),comp=(e,t=l)=>({is:3,$tag:e.$tag||0,$def:e,attrs:t,nodes:s,up:null,el:null}),node=e=>({is:4,$tag:0,$def:null,attrs:null,nodes:null,up:null,el:e}),v=compDef({draw:e=>e.attrs.$nodes}),bind=(t,s)=>{let l=e.get(t);return null===s?(l&&(y(l),e.delete(t)),null):(l=l||comp(v),l.attrs={$nodes:s},e.set(l.el=t,l),draw(l),sync(),l)};export{bind,comp,compDef,diff,draw,elem,node,ns,sync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenith",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.15",
4
4
  "description": "Another front-end framework.",
5
5
  "type": "module",
6
6
  "main": "./dist/zenith.js",