@dlightjs/dlight
Advanced tools
Comparing version 1.0.0-alpha.34 to 1.0.0-alpha.35
@@ -1,2 +0,2 @@ | ||
var d=class{_$dlNodeType;constructor(e){this._$dlNodeType=e}get _$el(){return d.toEls(this._$nodes)}_$parentEl;_$nodes;static toEls(e){let t=[];return this.loopShallowEls(e,n=>{t.push(n)}),t}static loopDLNodes(e,t){e.forEach(n=>{t(n),n._$nodes&&d.loopDLNodes(n._$nodes,t)})}static loopDLNodesInsideOut(e,t){e.forEach(n=>{n._$nodes&&d.loopDLNodesInsideOut(n._$nodes,t),t(n)})}static loopShallowEls(e,t){e.forEach(n=>{if(!("_$dlNodeType"in n))return t(n);n._$nodes&&d.loopShallowEls(n._$nodes,t)})}static loopShallowDLNodes(e,t){e.forEach(n=>{"_$dlNodeType"in n&&(t(n),n._$nodes&&d.loopShallowDLNodes(n._$nodes,t))})}static addParentEl(e,t){this.loopShallowDLNodes(e,n=>{n._$parentEl=t})}static getFlowIndexFromNodes(e,t){let n=0,s=[...e];for(;s.length>0;){let r=s.shift();if(r===t)break;"_$dlNodeType"in r?r._$nodes&&s.unshift(...r._$nodes):n++}return n}static appendNodesWithSibling(e,t,n){return n?this.insertNodesBefore(e,t,n):this.appendNodes(e,t)}static appendNodesWithIndex(e,t,n,s){return s=s??t.childNodes.length,s!==n?this.insertNodesBefore(e,t,t.childNodes[n]):this.appendNodes(e,t)}static insertNodesBefore(e,t,n){let s=0;return this.loopShallowEls(e,r=>{t.insertBefore(r,n),s++}),s}static appendNodes(e,t){let n=0;return this.loopShallowEls(e,s=>{t.appendChild(s),n++}),n}static willUnmountFunc(e,t){e(),t?.()}static addWillUnmount(e,t){e.willUnmount=this.willUnmountFunc.bind(this,t,e.willUnmount?.bind(e))}};function C(o,e){Object.entries(e).forEach(([t,n])=>{o.style[t]=n})}function W(o,e){Object.entries(e).forEach(([t,n])=>{o.dataset[t]=n})}function _(o,e,t){let n=`$${e}`;n in o&&o[n]===t||(o[e]=t,o[n]=t)}function U(o,e){Object.entries(e).forEach(([t,n])=>{_(o,t,n)})}function T(o,e,t){let n=`$${e}`;n in o&&o[n]===t||(o.setAttribute(e,t),o[n]=t)}function O(o,e){Object.entries(e).forEach(([t,n])=>{T(o,t,n)})}function K(o,e,t){let n=o[`$on${e}`];n&&o.removeEventListener(e,n),o.addEventListener(e,t),o[`$on${e}`]=t}function R(o){let e=document.createElement("template");e.innerHTML=o;let t=e.content.firstChild;return()=>t.cloneNode(!0)}function G(o){return document.createElement(o)}function b(o,e,t){o._$nodes||(o._$nodes=Array.from(o.childNodes)),o._$nodes.splice(t,0,e),d.appendNodesWithIndex([e],o,t),d.addParentEl([e],o)}function w(o,e,t){if(e==="style"){C(o,t);return}if(e==="dataset"){W(o,t);return}if(e!=="element"){if(e==="prop"){U(o,t);return}if(e==="attr"){O(o,t);return}if(e==="innerHTML"){_(o,"innerHTML",t);return}if(e!=="forwardProp"){if(e.startsWith("on")){K(o,e.slice(2).toLowerCase(),t);return}T(o,e,t)}}}var g=class extends d{constructor(){super(0)}_$init(e,t,n,s){this._$notInitd=!0,s&&s._$addForwardProps(this),t!==null&&this._$setContent(t),e&&Object.entries(e).forEach(([r,c])=>{this._$setProp(r,c)}),n&&(this._$children=n),Object.entries(window.DLEnvStore.envs).forEach(([r,[c,h]])=>{h.addNode(this),this._$initEnv(r,c,h)}),this._$callUpdatesBeforeInit(),this.willMount?.(),this._$nodes=this.View?.()??[],this.didMount?.()}_$callUpdatesBeforeInit(){let e=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),t=Object.getOwnPropertyNames(this);[...e,...t].forEach(s=>{if(s.startsWith("$w$"))return this[s.slice(3)]();s.startsWith("$f$")&&(this[`$${s.slice(3)}`]=this[s])}),delete this._$notInitd}_$setForwardProp(e,t){if(e in this){this[e]=t;return}this._$forwardPropsId.push(e);let n=`$${e}`;this[n]=t,Object.defineProperty(this,e,{get(){return this[n]},set(s){this[n]!==s&&(this[n]=s,this._$forwardPropsSet?.forEach(r=>{r._$dlNodeType===0&&r._$setProp(e,s),r instanceof HTMLElement&&w(r,e,s)}))}})}_$addForwardProps(e){this._$forwardPropsSet.add(e),this._$forwardPropsId.forEach(t=>{let n=this[t];this._$forwardPropsSet?.forEach(s=>{s._$dlNodeType===0&&("_$forwardProps"in s&&s._$forwardPropsId.push(t),s._$setProp(t,n)),s instanceof HTMLElement&&w(s,t,n)})}),d.addWillUnmount(e,this._$forwardPropsSet.delete.bind(this._$forwardPropsSet,e))}_$setProp(e,t){"_$forwardProps"in this&&this._$setForwardProp(e,t),`$p$${e}`in this&&(this[e]=t)}_$initEnv(e,t,n){`$e$${e}`in this&&(this[e]=t,this[`$en$${e}`]=n)}_$updateEnv(e,t,n){`$e$${e}`in this&&n===this[`$en$${e}`]&&this[e]!==t&&(this[e]=t)}_$setContent(e){let t=this._$contentKey;t&&this[t]!==e&&(this[t]=e)}_$updateProp(e,t){let n=`$${e}`;this[n]!==t&&(this[n]=t,this._$updateDerived(e),this._$updateView(e))}_$updateDerived(e){"_$notInitd"in this||this[`$s$${e}`]?.forEach(t=>{`$w$${t}`in this?this[t]():this[`$${t}`]=this[`$f$${t}`]})}_$updateView(e){let t=this[`$$${e}`];t&&this._$update?.(t)}},Q=g;function X(o,e){o._$updateDerived(e),o._$updateView(e)}var a=class extends d{constructor(e){super(e),window.DLEnvStore.currentEnvNodes.length>0&&(this.savedEnvNodes=[...window.DLEnvStore.currentEnvNodes])}initNewNodes(e){d.addParentEl(e,this._$parentEl)}geneNewNodesInEnv(e){if(!this.savedEnvNodes){let s=e();return this.initNewNodes(s),s}let t=window.DLEnvStore.currentEnvNodes;window.DLEnvStore.replaceEnvNodes(this.savedEnvNodes);let n=e();return window.DLEnvStore.replaceEnvNodes(t),this.initNewNodes(n),n}removeNodes(e){d.loopDLNodes(e,t=>t.willUnmount?.()),d.loopShallowEls(e,t=>{this._$parentEl?.removeChild(t)}),d.loopDLNodesInsideOut(e,t=>t.didUnmount?.())}};var v=class extends a{array;keys;nodeFunc;nodess;depNum;updateArr=[];constructor(e,t,n){super(1),this.array=[...e],this.keys=n,this.depNum=t}addNodeFunc(e){this.nodeFunc=e,this.nodess=this.array.map((t,n)=>e(t,this.updateArr,n)),this._$nodes=this.nodess.flat(1)}update(e){if(!(e&this.depNum))for(let t=0;t<this.array.length;t++)this.updateItem(t,e)}updateItem(e,t){this.updateArr[e]?.(t??this.depNum,this.array[e])}updateArray(e,t){if(t){this.updateWithKey(e,t);return}this.updateWithOutKey(e)}getNewNodes(e){return this.geneNewNodesInEnv(()=>this.nodeFunc(this.array[e],this.updateArr,e))}updateWithOutKey(e){let t=this.array.length,n=e.length;if(this.array=[...e],this.updateArr=this.updateArr.slice(0,n),t===n){for(let r=0;r<this.array.length;r++)this.updateItem(r);return}let s=this._$parentEl;if(t<n){let r=a.getFlowIndexFromNodes(s._$nodes,this),c=s.childNodes.length;for(let h=0;h<n;h++){if(h<t){r+=a.getFlowIndexFromNodes(this.nodess[h]),this.updateItem(h);continue}let p=this.getNewNodes(h);a.appendNodesWithIndex(p,s,r,c),this.nodess.push(p)}this._$nodes=this.nodess.flat(1);return}for(let r=0;r<n;r++)this.updateItem(r);for(let r=n;r<t;r++)this.removeNodes(this.nodess[r]);this.nodess=this.nodess.slice(0,n),this._$nodes=this.nodess.flat(1)}updateWithKey(e,t){let n=this.keys;if(this.array=[...e],this.keys=t,v.arrayEqual(n,this.keys)){for(let i=0;i<this.array.length;i++)this.updateItem(i);return}let s=this._$parentEl,r=this.nodess;if(this.keys.length===0){let i=s._$nodes??[];if(i.length===1&&i[0]===this)s.innerHTML="";else for(let l=0;l<n.length;l++)this.removeNodes(r[l]);this.nodess=[],this._$nodes=[],this.updateArr=[];return}let c=a.getFlowIndexFromNodes(s._$nodes,this);if(n.length===0){let i=s.childNodes[c];for(let l=0;l<this.keys.length;l++){let u=this.getNewNodes(l);a.appendNodesWithSibling(u,s,i),this.nodess.push(u)}this._$nodes=this.nodess.flat(1);return}let h=[],p=[],f=[];for(let i=0;i<n.length;i++){let l=n[i];if(this.keys.includes(l)){h.push(l),p.push(r[i]),f.push(this.updateArr[i]);continue}this.removeNodes(r[i])}console.log("called");let y=s.childNodes.length,N=c;for(let i=0;i<this.keys.length;i++){let l=this.keys[i],u=h.indexOf(l);if(u!==-1){N+=a.getFlowIndexFromNodes(p[u]),this.updateArr[u]?.(this.depNum,this.array[i]);continue}f.splice(i,0,null);let m=this.getNewNodes(i),A=a.appendNodesWithIndex(m,s,N,y);N+=A,y+=A,p.splice(i,0,m),h.splice(i,0,l)}if(v.arrayEqual(this.keys,h)){this.nodess=p,this._$nodes=this.nodess.flat(1),this.updateArr=f;return}N=c;let E=[];for(let i=0;i<this.keys.length;i++){let l=this.keys[i],u=h.indexOf(l),m=E[i];if(m){let L=a.appendNodesWithIndex(m,s,N+a.getFlowIndexFromNodes(m),y);N+=L,y+=L,E[i]=void 0}else if(u===i){N+=a.getFlowIndexFromNodes(p[i]);continue}else{E[this.keys.indexOf(h[i])]=p[i];let L=a.appendNodesWithIndex(p[u],s,N,y);N+=L,y+=L}let A=p[i];p[i]=p[u],p[u]=A;let S=h[i];h[i]=h[u],h[u]=S;let P=f[i];f[i]=f[u],f[u]=P}this.nodess=p,this._$nodes=this.nodess.flat(1),this.updateArr=f}static arrayEqual(e,t){return e.length!==t.length?!1:e.every((n,s)=>n===t[s])}};var D=class extends a{nodesFunc;constructor(e){super(4),this.nodesFunc=e,this._$nodes=D.formatNodes(e())}update(){let e=this.geneNewNodesInEnv(()=>D.formatNodes(this.nodesFunc()));if(this.removeNodes(this._$nodes),e.length===0){this._$nodes=[];return}let t=this._$parentEl,n=a.getFlowIndexFromNodes(t._$nodes,this),s=t.childNodes[n];a.appendNodesWithSibling(e,t,s),this._$nodes=e}static formatNodes(e){return Array.isArray(e)||(e=[e]),e.flat(1).filter(t=>t!=null&&typeof t!="boolean").map(t=>typeof t=="string"||typeof t=="number"||typeof t=="bigint"?document.createTextNode(`${t}`):"propViewFunc"in t?t.build():t).flat(1)}};var I=class extends a{condFunc;cond;depNum;constructor(e){super(2),this.depNum=e}addCondFunc(e){this.cond=-1,this.condFunc=e,this._$nodes=this.condFunc(this)}updateCond(){let e=this.geneNewNodesInEnv(()=>this.condFunc(this));if(this.didntChange)return this.didntChange=!1,this.updateFunc?.(this.depNum),this._$nodes;if(this._$nodes&&this._$nodes.length>0&&this.removeNodes(this._$nodes),e.length===0)return this._$nodes=[],this._$nodes;let t=this._$parentEl,n=a.getFlowIndexFromNodes(t._$nodes,this),s=t.childNodes[n];return a.appendNodesWithSibling(e,t,s),this._$nodes=e,this._$nodes}update(e){e&this.depNum||this.updateFunc?.(e)}};var x=class{envs={};currentEnvNodes=[];addEnvNode(e){this.currentEnvNodes.push(e),this.mergeEnvs()}replaceEnvNodes(e){this.currentEnvNodes=e,this.mergeEnvs()}removeEnvNode(){this.currentEnvNodes.pop(),this.mergeEnvs()}mergeEnvs(){this.envs={},this.currentEnvNodes.forEach(e=>{Object.entries(e.envs).forEach(([t,n])=>{this.envs[t]=[n,e]})})}};window.DLEnvStore||(window.DLEnvStore=new x);var M=class extends d{updateNodes=new Set;envs;constructor(e){super(3),this.envs=e,window.DLEnvStore.addEnvNode(this)}updateEnv(e,t){this.envs[e]=t,window.DLEnvStore.currentEnvNodes.includes(this)&&window.DLEnvStore.mergeEnvs(),this.updateNodes.forEach(n=>{n._$updateEnv(e,t,this)})}addNode(e){this.updateNodes.add(e),d.addWillUnmount(e,this.updateNodes.delete.bind(this.updateNodes,e))}initNodes(e){this._$nodes=e,window.DLEnvStore.removeEnvNode()}};function le(o){return document.createTextNode(o)}function ue(o,e){o.textContent!==e&&(o.textContent=e)}var H=class{propViewFunc;dlUpdateFunc=new Set;constructor(e){this.propViewFunc=e}build(){let e,t=s=>{s.initd=!0,e=s,this.dlUpdateFunc.add(s)},n=this.propViewFunc(t);return n.length===0?[]:(e&&(console.log(n),d.addWillUnmount(n[0],this.dlUpdateFunc.delete.bind(this.dlUpdateFunc,e))),n)}update(e){this.dlUpdateFunc.forEach(t=>{if(t.initd){delete t.initd;return}t(e)})}};var F=class extends d{constructor(){super(5)}};function $e(o,e){let t=o;if(typeof o=="string"){let s=document.getElementById(o);if(s)t=s;else throw new Error(`DLight: Element with id ${o} not found`)}t.innerHTML="";let n=new e;n._$init(),b(t,n,0)}function ve(o,e){return o()}function j(o){return o}var De=j;export{De as $,g as CompNode,I as CondNode,M as EnvNode,D as ExpNode,v as ForNode,H as PropView,F as SubViewNode,Q as View,G as createElement,R as createTemplate,le as createTextNode,j as escape,w as forwardHTMLProp,b as insertNode,ve as manual,$e as render,W as setDataset,K as setEvent,T as setHTMLAttr,O as setHTMLAttrs,_ as setHTMLProp,U as setHTMLProps,C as setStyle,X as update,ue as updateText}; | ||
var d=class{_$dlNodeType;constructor(e){this._$dlNodeType=e}get _$el(){return d.toEls(this._$nodes)}_$parentEl;_$nodes;static toEls(e){let t=[];return this.loopShallowEls(e,n=>{t.push(n)}),t}static loopDLNodes(e,t){e.forEach(n=>{t(n),n._$nodes&&d.loopDLNodes(n._$nodes,t)})}static loopDLNodesInsideOut(e,t){e.forEach(n=>{n._$nodes&&d.loopDLNodesInsideOut(n._$nodes,t),t(n)})}static loopShallowEls(e,t){e.forEach(n=>{if(!("_$dlNodeType"in n))return t(n);n._$nodes&&d.loopShallowEls(n._$nodes,t)})}static loopShallowDLNodes(e,t){e.forEach(n=>{"_$dlNodeType"in n&&(t(n),n._$nodes&&d.loopShallowDLNodes(n._$nodes,t))})}static addParentEl(e,t){this.loopShallowDLNodes(e,n=>{n._$parentEl=t})}static getFlowIndexFromNodes(e,t){let n=0,o=[...e];for(;o.length>0;){let r=o.shift();if(r===t)break;"_$dlNodeType"in r?r._$nodes&&o.unshift(...r._$nodes):n++}return n}static appendNodesWithSibling(e,t,n){return n?this.insertNodesBefore(e,t,n):this.appendNodes(e,t)}static appendNodesWithIndex(e,t,n,o){return o=o??t.childNodes.length,o!==n?this.insertNodesBefore(e,t,t.childNodes[n]):this.appendNodes(e,t)}static insertNodesBefore(e,t,n){let o=0;return this.loopShallowEls(e,r=>{t.insertBefore(r,n),o++}),o}static appendNodes(e,t){let n=0;return this.loopShallowEls(e,o=>{t.appendChild(o),n++}),n}static willUnmountFunc(e,t){e(),t?.()}static addWillUnmount(e,t){e.willUnmount=this.willUnmountFunc.bind(this,t,e.willUnmount?.bind(e))}};function C(s,e){Object.entries(e).forEach(([t,n])=>{s.style[t]=n})}function W(s,e){Object.entries(e).forEach(([t,n])=>{s.dataset[t]=n})}function _(s,e,t){let n=`$${e}`;n in s&&s[n]===t||(s[e]=t,s[n]=t)}function U(s,e){Object.entries(e).forEach(([t,n])=>{_(s,t,n)})}function T(s,e,t){let n=`$${e}`;n in s&&s[n]===t||(s.setAttribute(e,t),s[n]=t)}function O(s,e){Object.entries(e).forEach(([t,n])=>{T(s,t,n)})}function K(s,e,t){let n=s[`$on${e}`];n&&s.removeEventListener(e,n),s.addEventListener(e,t),s[`$on${e}`]=t}function R(s){let e=document.createElement("template");e.innerHTML=s;let t=e.content.firstChild;return()=>t.cloneNode(!0)}function G(s){return document.createElement(s)}function b(s,e,t){s._$nodes||(s._$nodes=Array.from(s.childNodes)),s._$nodes.splice(t,0,e),d.appendNodesWithIndex([e],s,t),d.addParentEl([e],s)}function w(s,e,t){if(e==="style"){C(s,t);return}if(e==="dataset"){W(s,t);return}if(e!=="element"){if(e==="prop"){U(s,t);return}if(e==="attr"){O(s,t);return}if(e==="innerHTML"){_(s,"innerHTML",t);return}if(e!=="forwardProp"){if(e.startsWith("on")){K(s,e.slice(2).toLowerCase(),t);return}T(s,e,t)}}}var g=class extends d{constructor(){super(0)}_$init(e,t,n,o){this._$notInitd=!0,o&&o._$addForwardProps(this),t!==null&&this._$setContent(t),e&&Object.entries(e).forEach(([r,N])=>{this._$setProp(r,N)}),n&&(this._$children=n),Object.entries(window.DLEnvStore.envs).forEach(([r,[N,h]])=>{h.addNode(this),this._$initEnv(r,N,h)}),this._$callUpdatesBeforeInit(),this.willMount?.(),this._$nodes=this.View?.()??[],this.didMount?.()}_$callUpdatesBeforeInit(){let e=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),t=Object.getOwnPropertyNames(this);[...e,...t].forEach(o=>{if(o.startsWith("$w$"))return this[o.slice(3)]();o.startsWith("$f$")&&(this[`$${o.slice(3)}`]=this[o])}),delete this._$notInitd}_$setForwardProp(e,t){if(e in this){this[e]=t;return}this._$forwardPropsId.push(e);let n=`$${e}`;this[n]=t,Object.defineProperty(this,e,{get(){return this[n]},set(o){this[n]!==o&&(this[n]=o,this._$forwardPropsSet?.forEach(r=>{r._$dlNodeType===0&&r._$setProp(e,o),r instanceof HTMLElement&&w(r,e,o)}))}})}_$addForwardProps(e){this._$forwardPropsSet.add(e),this._$forwardPropsId.forEach(t=>{let n=this[t];this._$forwardPropsSet?.forEach(o=>{o._$dlNodeType===0&&("_$forwardProps"in o&&o._$forwardPropsId.push(t),o._$setProp(t,n)),o instanceof HTMLElement&&w(o,t,n)})}),d.addWillUnmount(e,this._$forwardPropsSet.delete.bind(this._$forwardPropsSet,e))}_$setProp(e,t){"_$forwardProps"in this&&this._$setForwardProp(e,t),`$p$${e}`in this&&(this[e]=t)}_$initEnv(e,t,n){`$e$${e}`in this&&(this[e]=t,this[`$en$${e}`]=n)}_$updateEnv(e,t,n){`$e$${e}`in this&&n===this[`$en$${e}`]&&this[e]!==t&&(this[e]=t)}_$setContent(e){let t=this._$contentKey;t&&this[t]!==e&&(this[t]=e)}_$updateProp(e,t){let n=`$${e}`;this[n]!==t&&(this[n]=t,this._$updateDerived(e),this._$updateView(e))}_$updateDerived(e){"_$notInitd"in this||this[`$s$${e}`]?.forEach(t=>{`$w$${t}`in this?this[t]():this[`$${t}`]=this[`$f$${t}`]})}_$updateView(e){let t=this[`$$${e}`];t&&this._$update?.(t)}},Q=g;function X(s,e){s._$updateDerived(e),s._$updateView(e)}var a=class extends d{constructor(e){super(e),window.DLEnvStore.currentEnvNodes.length>0&&(this.savedEnvNodes=[...window.DLEnvStore.currentEnvNodes])}initNewNodes(e){d.addParentEl(e,this._$parentEl)}geneNewNodesInEnv(e){if(!this.savedEnvNodes){let o=e();return this.initNewNodes(o),o}let t=window.DLEnvStore.currentEnvNodes;window.DLEnvStore.replaceEnvNodes(this.savedEnvNodes);let n=e();return window.DLEnvStore.replaceEnvNodes(t),this.initNewNodes(n),n}removeNodes(e){d.loopDLNodes(e,t=>t.willUnmount?.()),d.loopShallowEls(e,t=>{this._$parentEl?.removeChild(t)}),d.loopDLNodesInsideOut(e,t=>t.didUnmount?.())}};var v=class extends a{array;keys;nodeFunc;nodess;depNum;updateArr=[];constructor(e,t,n){super(1),this.array=[...e],this.keys=n,this.depNum=t}addNodeFunc(e){this.nodeFunc=e,this.nodess=this.array.map((t,n)=>e(t,this.updateArr,n)),this._$nodes=this.nodess.flat(1)}update(e){if(!(e&this.depNum))for(let t=0;t<this.array.length;t++)this.updateItem(t,e)}updateItem(e,t){this.updateArr[e]?.(t??this.depNum,this.array[e])}updateArray(e,t){if(t){this.updateWithKey(e,t);return}this.updateWithOutKey(e)}getNewNodes(e){return this.geneNewNodesInEnv(()=>this.nodeFunc(this.array[e],this.updateArr,e))}updateWithOutKey(e){let t=this.array.length,n=e.length;if(this.array=[...e],this.updateArr=this.updateArr.slice(0,n),t===n){for(let r=0;r<this.array.length;r++)this.updateItem(r);return}let o=this._$parentEl;if(t<n){let r=a.getFlowIndexFromNodes(o._$nodes,this),N=o.childNodes.length;for(let h=0;h<n;h++){if(h<t){r+=a.getFlowIndexFromNodes(this.nodess[h]),this.updateItem(h);continue}let p=this.getNewNodes(h);a.appendNodesWithIndex(p,o,r,N),this.nodess.push(p)}this._$nodes=this.nodess.flat(1);return}for(let r=0;r<n;r++)this.updateItem(r);for(let r=n;r<t;r++)this.removeNodes(this.nodess[r]);this.nodess=this.nodess.slice(0,n),this._$nodes=this.nodess.flat(1)}updateWithKey(e,t){let n=this.keys;if(this.array=[...e],this.keys=t,v.arrayEqual(n,this.keys)){for(let i=0;i<this.array.length;i++)this.updateItem(i);return}let o=this._$parentEl,r=this.nodess;if(this.keys.length===0){let i=o._$nodes??[];if(i.length===1&&i[0]===this)o.innerHTML="";else for(let u=0;u<n.length;u++)this.removeNodes(r[u]);this.nodess=[],this._$nodes=[],this.updateArr=[];return}let N=a.getFlowIndexFromNodes(o._$nodes,this);if(n.length===0){let i=o.childNodes[N];for(let u=0;u<this.keys.length;u++){let l=this.getNewNodes(u);a.appendNodesWithSibling(l,o,i),this.nodess.push(l)}this._$nodes=this.nodess.flat(1);return}let h=[],p=[],f=[];for(let i=0;i<n.length;i++){let u=n[i];if(this.keys.includes(u)){h.push(u),p.push(r[i]),f.push(this.updateArr[i]);continue}this.removeNodes(r[i])}let y=o.childNodes.length,c=N;for(let i=0;i<this.keys.length;i++){let u=this.keys[i],l=h.indexOf(u);if(l!==-1){c+=a.getFlowIndexFromNodes(p[l]),this.updateArr[l]?.(this.depNum,this.array[i]);continue}f.splice(i,0,null);let m=this.getNewNodes(i),A=a.appendNodesWithIndex(m,o,c,y);c+=A,y+=A,p.splice(i,0,m),h.splice(i,0,u)}if(v.arrayEqual(this.keys,h)){this.nodess=p,this._$nodes=this.nodess.flat(1),this.updateArr=f;return}c=N;let E=[];for(let i=0;i<this.keys.length;i++){let u=this.keys[i],l=h.indexOf(u),m=E[i];if(m){let L=a.appendNodesWithIndex(m,o,c+a.getFlowIndexFromNodes(m),y);c+=L,y+=L,E[i]=void 0}else if(l===i){c+=a.getFlowIndexFromNodes(p[i]);continue}else{E[this.keys.indexOf(h[i])]=p[i];let L=a.appendNodesWithIndex(p[l],o,c,y);c+=L,y+=L}let A=p[i];p[i]=p[l],p[l]=A;let S=h[i];h[i]=h[l],h[l]=S;let P=f[i];f[i]=f[l],f[l]=P}this.nodess=p,this._$nodes=this.nodess.flat(1),this.updateArr=f}static arrayEqual(e,t){return e.length!==t.length?!1:e.every((n,o)=>n===t[o])}};var D=class extends a{nodesFunc;constructor(e){super(4),this.nodesFunc=e,this._$nodes=D.formatNodes(e())}update(){let e=this.geneNewNodesInEnv(()=>D.formatNodes(this.nodesFunc()));if(this.removeNodes(this._$nodes),e.length===0){this._$nodes=[];return}let t=this._$parentEl,n=a.getFlowIndexFromNodes(t._$nodes,this),o=t.childNodes[n];a.appendNodesWithSibling(e,t,o),this._$nodes=e}static formatNodes(e){return Array.isArray(e)||(e=[e]),e.flat(1).filter(t=>t!=null&&typeof t!="boolean").map(t=>typeof t=="string"||typeof t=="number"||typeof t=="bigint"?document.createTextNode(`${t}`):"propViewFunc"in t?t.build():t).flat(1)}};var I=class extends a{condFunc;cond;depNum;constructor(e){super(2),this.depNum=e}addCondFunc(e){this.cond=-1,this.condFunc=e,this._$nodes=this.condFunc(this)}updateCond(){let e=this.geneNewNodesInEnv(()=>this.condFunc(this));if(this.didntChange)return this.didntChange=!1,this.updateFunc?.(this.depNum),this._$nodes;if(this._$nodes&&this._$nodes.length>0&&this.removeNodes(this._$nodes),e.length===0)return this._$nodes=[],this._$nodes;let t=this._$parentEl,n=a.getFlowIndexFromNodes(t._$nodes,this),o=t.childNodes[n];return a.appendNodesWithSibling(e,t,o),this._$nodes=e,this._$nodes}update(e){e&this.depNum||this.updateFunc?.(e)}};var x=class{envs={};currentEnvNodes=[];addEnvNode(e){this.currentEnvNodes.push(e),this.mergeEnvs()}replaceEnvNodes(e){this.currentEnvNodes=e,this.mergeEnvs()}removeEnvNode(){this.currentEnvNodes.pop(),this.mergeEnvs()}mergeEnvs(){this.envs={},this.currentEnvNodes.forEach(e=>{Object.entries(e.envs).forEach(([t,n])=>{this.envs[t]=[n,e]})})}};window.DLEnvStore||(window.DLEnvStore=new x);var M=class extends d{updateNodes=new Set;envs;constructor(e){super(3),this.envs=e,window.DLEnvStore.addEnvNode(this)}updateEnv(e,t){this.envs[e]=t,window.DLEnvStore.currentEnvNodes.includes(this)&&window.DLEnvStore.mergeEnvs(),this.updateNodes.forEach(n=>{n._$updateEnv(e,t,this)})}addNode(e){this.updateNodes.add(e),d.addWillUnmount(e,this.updateNodes.delete.bind(this.updateNodes,e))}initNodes(e){this._$nodes=e,window.DLEnvStore.removeEnvNode()}};function ue(s){return document.createTextNode(s)}function le(s,e){s.textContent!==e&&(s.textContent=e)}var H=class{propViewFunc;dlUpdateFunc=new Set;constructor(e){this.propViewFunc=e}build(){let e,t=o=>{o.initd=!0,e=o,this.dlUpdateFunc.add(o)},n=this.propViewFunc(t);return n.length===0?[]:(e&&d.addWillUnmount(n[0],this.dlUpdateFunc.delete.bind(this.dlUpdateFunc,e)),n)}update(e){this.dlUpdateFunc.forEach(t=>{if(t.initd){delete t.initd;return}t(e)})}};var F=class extends d{constructor(){super(5)}};function $e(s,e){let t=s;if(typeof s=="string"){let o=document.getElementById(s);if(o)t=o;else throw new Error(`DLight: Element with id ${s} not found`)}t.innerHTML="";let n=new e;n._$init(),b(t,n,0)}function ve(s,e){return s()}function j(s){return s}var De=j;export{De as $,g as CompNode,I as CondNode,M as EnvNode,D as ExpNode,v as ForNode,H as PropView,F as SubViewNode,Q as View,G as createElement,R as createTemplate,ue as createTextNode,j as escape,w as forwardHTMLProp,b as insertNode,ve as manual,$e as render,W as setDataset,K as setEvent,T as setHTMLAttr,O as setHTMLAttrs,_ as setHTMLProp,U as setHTMLProps,C as setStyle,X as update,le as updateText}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dlightjs/dlight", | ||
"version": "1.0.0-alpha.34", | ||
"version": "1.0.0-alpha.35", | ||
"description": "DX-first UI rendering library", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159771
582