@dlightjs/dlight
Advanced tools
Comparing version 1.0.0-alpha.38 to 1.0.0-alpha.39
@@ -1,2 +0,2 @@ | ||
var f={Comp:0,For:1,Cond:2,Env:3,Exp:4,Subview:5},d=class{_$dlNodeType;constructor(t){this._$dlNodeType=t}get _$el(){return d.toEls(this._$nodes)}_$parentEl;_$nodes;static toEls(t){let e=[];return this.loopShallowEls(t,s=>{e.push(s)}),e}static loopDLNodes(t,e){t.forEach(s=>{e(s),s._$nodes&&d.loopDLNodes(s._$nodes,e)})}static loopDLNodesInsideOut(t,e){t.forEach(s=>{s._$nodes&&d.loopDLNodesInsideOut(s._$nodes,e),e(s)})}static loopShallowEls(t,e){t.forEach(s=>{if(!("_$dlNodeType"in s))return e(s);s._$nodes&&d.loopShallowEls(s._$nodes,e)})}static loopShallowDLNodes(t,e){t.forEach(s=>{"_$dlNodeType"in s&&(e(s),s._$nodes&&d.loopShallowDLNodes(s._$nodes,e))})}static addParentEl(t,e){this.loopShallowDLNodes(t,s=>{s._$parentEl=e})}static getFlowIndexFromNodes(t,e){let s=0,n=[...t];for(;n.length>0;){let i=n.shift();if(i===e)break;"_$dlNodeType"in i?i._$nodes&&n.unshift(...i._$nodes):s++}return s}static appendNodesWithSibling(t,e,s){return s?this.insertNodesBefore(t,e,s):this.appendNodes(t,e)}static appendNodesWithIndex(t,e,s,n){return n=n??e.childNodes.length,n!==s?this.insertNodesBefore(t,e,e.childNodes[s]):this.appendNodes(t,e)}static insertNodesBefore(t,e,s){let n=0;return this.loopShallowEls(t,i=>{e.insertBefore(i,s),n++}),n}static appendNodes(t,e){let s=0;return this.loopShallowEls(t,n=>{e.appendChild(n),s++}),s}static willUnmountFunc(t,e){t(),e?.()}static addWillUnmount(t,e){t.willUnmount=this.willUnmountFunc.bind(this,e,t.willUnmount?.bind(t))}};var h={global:window,document};function M(o){h.global=o}function C(o){h.document=o}function H(o,t){Object.assign(o.style,t)}function K(o,t){Object.assign(o.dataset,t)}function S(o,t,e){let s=`$${t}`;s in o&&o[s]===e||(o[t]=e,o[s]=e)}function j(o,t){Object.entries(t).forEach(([e,s])=>{S(o,e,s)})}function F(o,t,e){let s=`$${t}`;s in o&&o[s]===e||(o.setAttribute(t,e),o[s]=e)}function B(o,t){Object.entries(t).forEach(([e,s])=>{F(o,e,s)})}function V(o,t,e){let s=o[`$on${t}`];s&&o.removeEventListener(t,s),o.addEventListener(t,e),o[`$on${t}`]=e}function R(o){let t=h.document.createElement("template");t.innerHTML=o;let e=t.content.firstChild;return()=>e.cloneNode(!0)}function X(o){return h.document.createElement(o)}function y(o,t,e){o._$nodes||(o._$nodes=Array.from(o.childNodes)),o._$nodes.splice(e,0,t);let s=d.getFlowIndexFromNodes(o._$nodes,t);d.appendNodesWithIndex([t],o,s),d.addParentEl([t],o)}function b(o,t,e){if(t==="style"){H(o,e);return}if(t==="dataset"){K(o,e);return}if(t!=="element"){if(t==="prop"){j(o,e);return}if(t==="attr"){B(o,e);return}if(t==="innerHTML"){S(o,"innerHTML",e);return}if(t!=="forwardProp"){if(t.startsWith("on")){V(o,t.slice(2).toLowerCase(),e);return}F(o,t,e)}}}var I=class extends d{constructor(){super(f.Comp)}_$init(t,e,s,n){this._$notInitd=!0,n&&n._$addForwardProps(this),e!==null&&this._$setContent(e),t&&Object.entries(t).forEach(([i,$])=>{this._$setProp(i,$)}),s&&(this._$children=s),h.global.DLEnvStore&&Object.entries(h.global.DLEnvStore.envs).forEach(([i,[$,a]])=>{a.addNode(this),this._$initEnv(i,$,a)}),this._$callUpdatesBeforeInit(),this.willMount?.(),this._$nodes=this.View?.()??[],this.didMount?.()}_$callUpdatesBeforeInit(){let t=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),e=Object.getOwnPropertyNames(this);[...t,...e].forEach(n=>{if(n.startsWith("$w$"))return this[n.slice(3)]();n.startsWith("$f$")&&(this[`$${n.slice(3)}`]=this[n])}),delete this._$notInitd}_$setForwardProp(t,e){if(t in this){this[t]=e;return}this._$forwardPropsId.push(t);let s=`$${t}`;this[s]=e,Object.defineProperty(this,t,{get(){return this[s]},set(n){this[s]!==n&&(this[s]=n,this._$forwardPropsSet?.forEach(i=>{i._$dlNodeType===f.Comp&&i._$setProp(t,n),i instanceof HTMLElement&&b(i,t,n)}))}})}_$addForwardProps(t){this._$forwardPropsSet.add(t),this._$forwardPropsId.forEach(e=>{let s=this[e];this._$forwardPropsSet?.forEach(n=>{n._$dlNodeType===f.Comp&&("_$forwardProps"in n&&n._$forwardPropsId.push(e),n._$setProp(e,s)),n instanceof HTMLElement&&b(n,e,s)})}),d.addWillUnmount(t,this._$forwardPropsSet.delete.bind(this._$forwardPropsSet,t))}_$setProp(t,e){"_$forwardProps"in this&&this._$setForwardProp(t,e),`$p$${t}`in this&&(this[t]=e)}_$initEnv(t,e,s){`$e$${t}`in this&&(this[t]=e,this[`$en$${t}`]=s)}_$updateEnv(t,e,s){`$e$${t}`in this&&s===this[`$en$${t}`]&&this[t]!==e&&(this[t]=e)}_$setContent(t){let e=this._$contentKey;e&&this[e]!==t&&(this[e]=t)}_$updateProp(t,e){let s=`$${t}`;this[s]!==e&&(this[s]=e,this._$updateDerived(t),this._$updateView(t))}_$updateDerived(t){"_$notInitd"in this||this[`$s$${t}`]?.forEach(e=>{`$w$${e}`in this?this[e]():this[`$${e}`]=this[`$f$${e}`]})}_$updateView(t){let e=this[`$$${t}`];e&&this._$update?.(e)}},et=I;function st(o,t){o._$updateDerived(t),o._$updateView(t)}var D=class{constructor(){this.envs={},this.currentEnvNodes=[]}addEnvNode(t){this.currentEnvNodes.push(t),this.mergeEnvs()}replaceEnvNodes(t){this.currentEnvNodes=t,this.mergeEnvs()}removeEnvNode(){this.currentEnvNodes.pop(),this.mergeEnvs()}mergeEnvs(){this.envs={},this.currentEnvNodes.forEach(t=>{Object.entries(t.envs).forEach(([e,s])=>{this.envs[e]=[s,t]})})}},P=class extends d{constructor(t){super(f.Env),h.global.DLEnvStore||(h.global.DLEnvStore=new D),this.envs=t,this.updateNodes=new Set,h.global.DLEnvStore.addEnvNode(this)}updateEnv(t,e){this.envs[t]=e,h.global.DLEnvStore.currentEnvNodes.includes(this)&&h.global.DLEnvStore.mergeEnvs(),this.updateNodes.forEach(s=>{s._$updateEnv(t,e,this)})}addNode(t){this.updateNodes.add(t),d.addWillUnmount(t,this.updateNodes.delete.bind(this.updateNodes,t))}initNodes(t){this._$nodes=t,h.global.DLEnvStore.removeEnvNode()}};function ht(o){return h.document.createTextNode(o)}function pt(o,t){o.textContent!==t&&(o.textContent=t)}var T=class{propViewFunc;dlUpdateFunc=new Set;constructor(t){this.propViewFunc=t}build(){let t,e=n=>{n.initd=!0,t=n,this.dlUpdateFunc.add(n)},s=this.propViewFunc(e);return s.length===0?[]:(t&&d.addWillUnmount(s[0],this.dlUpdateFunc.delete.bind(this.dlUpdateFunc,t)),s)}update(t){this.dlUpdateFunc.forEach(e=>{if(e.initd){delete e.initd;return}e(t)})}};var W=class extends d{constructor(){super(f.Subview)}};var p=class extends d{constructor(t){super(t),h.global.DLEnvStore&&h.global.DLEnvStore.currentEnvNodes.length>0&&(this.savedEnvNodes=[...h.global.DLEnvStore.currentEnvNodes])}initNewNodes(t){d.addParentEl(t,this._$parentEl)}geneNewNodesInEnv(t){if(!this.savedEnvNodes){let n=t();return this.initNewNodes(n),n}let e=h.global.DLEnvStore.currentEnvNodes;h.global.DLEnvStore.replaceEnvNodes(this.savedEnvNodes);let s=t();return h.global.DLEnvStore.replaceEnvNodes(e),this.initNewNodes(s),s}removeNodes(t){d.loopDLNodes(t,e=>e.willUnmount?.()),d.loopShallowEls(t,e=>{this._$parentEl?.removeChild(e)}),d.loopDLNodesInsideOut(t,e=>e.didUnmount?.())}};var w=class extends p{array;keys;nodeFunc;nodess;depNum;updateArr=[];constructor(t,e,s){super(f.For),this.array=[...t],this.keys=s,this.depNum=e}addNodeFunc(t){this.nodeFunc=t,this.nodess=this.array.map((e,s)=>t(e,this.updateArr,s)),this._$nodes=this.nodess.flat(1)}update(t){if(!(t&this.depNum))for(let e=0;e<this.array.length;e++)this.updateItem(e,t)}updateItem(t,e){this.updateArr[t]?.(e??this.depNum,this.array[t])}updateArray(t,e){if(e){this.updateWithKey(t,e);return}this.updateWithOutKey(t)}getNewNodes(t){return this.geneNewNodesInEnv(()=>this.nodeFunc(this.array[t],this.updateArr,t))}updateWithOutKey(t){let e=this.array.length,s=t.length;if(this.array=[...t],this.updateArr=this.updateArr.slice(0,s),e===s){for(let i=0;i<this.array.length;i++)this.updateItem(i);return}let n=this._$parentEl;if(e<s){let i=p.getFlowIndexFromNodes(n._$nodes,this),$=n.childNodes.length;for(let a=0;a<s;a++){if(a<e){i+=p.getFlowIndexFromNodes(this.nodess[a]),this.updateItem(a);continue}let l=this.getNewNodes(a);p.appendNodesWithIndex(l,n,i,$),this.nodess.push(l)}this._$nodes=this.nodess.flat(1);return}for(let i=0;i<s;i++)this.updateItem(i);for(let i=s;i<e;i++)this.removeNodes(this.nodess[i]);this.nodess=this.nodess.slice(0,s),this._$nodes=this.nodess.flat(1)}updateWithKey(t,e){let s=this.keys;if(this.array=[...t],this.keys=e,w.arrayEqual(s,this.keys)){for(let r=0;r<this.array.length;r++)this.updateItem(r);return}let n=this._$parentEl,i=this.nodess;if(this.keys.length===0){let r=n._$nodes??[];if(r.length===1&&r[0]===this)n.innerHTML="";else for(let c=0;c<s.length;c++)this.removeNodes(i[c]);this.nodess=[],this._$nodes=[],this.updateArr=[];return}let $=p.getFlowIndexFromNodes(n._$nodes,this);if(s.length===0){let r=n.childNodes[$];for(let c=0;c<this.keys.length;c++){let u=this.getNewNodes(c);p.appendNodesWithSibling(u,n,r),this.nodess.push(u)}this._$nodes=this.nodess.flat(1);return}let a=[],l=[],N=[];for(let r=0;r<s.length;r++){let c=s[r];if(this.keys.includes(c)){a.push(c),l.push(i[r]),N.push(this.updateArr[r]);continue}this.removeNodes(i[r])}let E=n.childNodes.length,m=$;for(let r=0;r<this.keys.length;r++){let c=this.keys[r],u=a.indexOf(c);if(u!==-1){m+=p.getFlowIndexFromNodes(l[u]),this.updateArr[u]?.(this.depNum,this.array[r]);continue}N.splice(r,0,null);let x=this.getNewNodes(r),v=p.appendNodesWithIndex(x,n,m,E);m+=v,E+=v,l.splice(r,0,x),a.splice(r,0,c)}if(w.arrayEqual(this.keys,a)){this.nodess=l,this._$nodes=this.nodess.flat(1),this.updateArr=N;return}m=$;let L=[];for(let r=0;r<this.keys.length;r++){let c=this.keys[r],u=a.indexOf(c),x=L[r];if(x){let _=p.appendNodesWithIndex(x,n,m+p.getFlowIndexFromNodes(x),E);m+=_,E+=_,L[r]=void 0}else if(u===r){m+=p.getFlowIndexFromNodes(l[r]);continue}else{L[this.keys.indexOf(a[r])]=l[r];let _=p.appendNodesWithIndex(l[u],n,m,E);m+=_,E+=_}let v=l[r];l[r]=l[u],l[u]=v;let O=a[r];a[r]=a[u],a[u]=O;let A=N[r];N[r]=N[u],N[u]=A}this.nodess=l,this._$nodes=this.nodess.flat(1),this.updateArr=N}static arrayEqual(t,e){return t.length!==e.length?!1:t.every((s,n)=>s===e[n])}};var g=class extends p{nodesFunc;constructor(t){super(f.Exp),this.nodesFunc=t,this._$nodes=g.formatNodes(t())}update(){let t=this.geneNewNodesInEnv(()=>g.formatNodes(this.nodesFunc()));if(this.removeNodes(this._$nodes),t.length===0){this._$nodes=[];return}let e=this._$parentEl,s=p.getFlowIndexFromNodes(e._$nodes,this),n=e.childNodes[s];p.appendNodesWithSibling(t,e,n),this._$nodes=t}static formatNodes(t){return Array.isArray(t)||(t=[t]),t.flat(1).filter(e=>e!=null&&typeof e!="boolean").map(e=>typeof e=="string"||typeof e=="number"||typeof e=="bigint"?h.document.createTextNode(`${e}`):"propViewFunc"in e?e.build():e).flat(1)}};var U=class extends p{condFunc;cond;depNum;constructor(t){super(f.Cond),this.depNum=t}addCondFunc(t){this.cond=-1,this.condFunc=t,this._$nodes=this.condFunc(this)}updateCond(){let t=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),t.length===0)return this._$nodes=[],this._$nodes;let e=this._$parentEl,s=p.getFlowIndexFromNodes(e._$nodes,this),n=e.childNodes[s];return p.appendNodesWithSibling(t,e,n),this._$nodes=t,this._$nodes}update(t){t&this.depNum||this.updateFunc?.(t)}};function yt(o,t){let e=o;if(typeof o=="string"){let n=h.document.getElementById(o);if(n)e=n;else throw new Error(`DLight: Element with id ${o} not found`)}e.innerHTML="";let s=new t;s._$init(),y(e,s,0)}function Pt(o,t){return o()}function q(o){return o}var Tt=q;export{Tt as $,I as CompNode,U as CondNode,P as EnvNode,g as ExpNode,w as ForNode,T as PropView,W as SubViewNode,et as View,X as createElement,R as createTemplate,ht as createTextNode,q as escape,b as forwardHTMLProp,y as insertNode,Pt as manual,yt as render,K as setDataset,C as setDocument,V as setEvent,M as setGlobal,F as setHTMLAttr,B as setHTMLAttrs,S as setHTMLProp,j as setHTMLProps,H as setStyle,st as update,pt as updateText}; | ||
var f={Comp:0,For:1,Cond:2,Env:3,Exp:4,Subview:5},d=class{_$dlNodeType;constructor(t){this._$dlNodeType=t}get _$el(){return d.toEls(this._$nodes)}_$parentEl;_$nodes;static toEls(t){let e=[];return this.loopShallowEls(t,s=>{e.push(s)}),e}static loopDLNodes(t,e){t.forEach(s=>{e(s),s._$nodes&&d.loopDLNodes(s._$nodes,e)})}static loopDLNodesInsideOut(t,e){t.forEach(s=>{s._$nodes&&d.loopDLNodesInsideOut(s._$nodes,e),e(s)})}static loopShallowEls(t,e){t.forEach(s=>{if(!("_$dlNodeType"in s))return e(s);s._$nodes&&d.loopShallowEls(s._$nodes,e)})}static loopShallowDLNodes(t,e){t.forEach(s=>{"_$dlNodeType"in s&&(e(s),s._$nodes&&d.loopShallowDLNodes(s._$nodes,e))})}static addParentEl(t,e){this.loopShallowDLNodes(t,s=>{s._$parentEl=e})}static getFlowIndexFromNodes(t,e){let s=0,n=[...t];for(;n.length>0;){let i=n.shift();if(i===e)break;"_$dlNodeType"in i?i._$nodes&&n.unshift(...i._$nodes):s++}return s}static appendNodesWithSibling(t,e,s){return s?this.insertNodesBefore(t,e,s):this.appendNodes(t,e)}static appendNodesWithIndex(t,e,s,n){return n=n??e.childNodes.length,n!==s?this.insertNodesBefore(t,e,e.childNodes[s]):this.appendNodes(t,e)}static insertNodesBefore(t,e,s){let n=0;return this.loopShallowEls(t,i=>{e.insertBefore(i,s),n++}),n}static appendNodes(t,e){let s=0;return this.loopShallowEls(t,n=>{e.appendChild(n),s++}),s}static willUnmountFunc(t,e){t(),e?.()}static addWillUnmount(t,e){t.willUnmount=this.willUnmountFunc.bind(this,e,t.willUnmount?.bind(t))}};import{Store as E}from"@dlightjs/store";"global"in E||(typeof window<"u"?E.global=window:typeof global<"u"?E.global=global:E.global={});"document"in E||typeof document<"u"&&(E.document=document);var h=E;function C(o){h.global=o}function H(o){h.document=o}function K(o,t){Object.assign(o.style,t)}function j(o,t){Object.assign(o.dataset,t)}function F(o,t,e){let s=`$${t}`;s in o&&o[s]===e||(o[t]=e,o[s]=e)}function B(o,t){Object.entries(t).forEach(([e,s])=>{F(o,e,s)})}function y(o,t,e){let s=`$${t}`;s in o&&o[s]===e||(o.setAttribute(t,e),o[s]=e)}function V(o,t){Object.entries(t).forEach(([e,s])=>{y(o,e,s)})}function q(o,t,e){let s=o[`$on${t}`];s&&o.removeEventListener(t,s),o.addEventListener(t,e),o[`$on${t}`]=e}function Y(o){let t=h.document.createElement("template");t.innerHTML=o;let e=t.content.firstChild;return()=>e.cloneNode(!0)}function Z(o){return h.document.createElement(o)}function P(o,t,e){o._$nodes||(o._$nodes=Array.from(o.childNodes)),o._$nodes.splice(e,0,t);let s=d.getFlowIndexFromNodes(o._$nodes,t);d.appendNodesWithIndex([t],o,s),d.addParentEl([t],o)}function I(o,t,e){if(t==="style"){K(o,e);return}if(t==="dataset"){j(o,e);return}if(t!=="element"){if(t==="prop"){B(o,e);return}if(t==="attr"){V(o,e);return}if(t==="innerHTML"){F(o,"innerHTML",e);return}if(t!=="forwardProp"){if(t.startsWith("on")){q(o,t.slice(2).toLowerCase(),e);return}y(o,t,e)}}}var D=class extends d{constructor(){super(f.Comp)}_$init(t,e,s,n){this._$notInitd=!0,n&&n._$addForwardProps(this),e!==null&&this._$setContent(e),t&&Object.entries(t).forEach(([i,$])=>{this._$setProp(i,$)}),s&&(this._$children=s),h.global.DLEnvStore&&Object.entries(h.global.DLEnvStore.envs).forEach(([i,[$,a]])=>{a.addNode(this),this._$initEnv(i,$,a)}),this._$callUpdatesBeforeInit(),this.willMount?.(),this._$nodes=this.View?.()??[],this.didMount?.()}_$callUpdatesBeforeInit(){let t=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),e=Object.getOwnPropertyNames(this);[...t,...e].forEach(n=>{if(n.startsWith("$w$"))return this[n.slice(3)]();n.startsWith("$f$")&&(this[`$${n.slice(3)}`]=this[n])}),delete this._$notInitd}_$setForwardProp(t,e){if(t in this){this[t]=e;return}this._$forwardPropsId.push(t);let s=`$${t}`;this[s]=e,Object.defineProperty(this,t,{get(){return this[s]},set(n){this[s]!==n&&(this[s]=n,this._$forwardPropsSet?.forEach(i=>{i._$dlNodeType===f.Comp&&i._$setProp(t,n),i instanceof HTMLElement&&I(i,t,n)}))}})}_$addForwardProps(t){this._$forwardPropsSet.add(t),this._$forwardPropsId.forEach(e=>{let s=this[e];this._$forwardPropsSet?.forEach(n=>{n._$dlNodeType===f.Comp&&("_$forwardProps"in n&&n._$forwardPropsId.push(e),n._$setProp(e,s)),n instanceof HTMLElement&&I(n,e,s)})}),d.addWillUnmount(t,this._$forwardPropsSet.delete.bind(this._$forwardPropsSet,t))}_$setProp(t,e){"_$forwardProps"in this&&this._$setForwardProp(t,e),`$p$${t}`in this&&(this[t]=e)}_$initEnv(t,e,s){`$e$${t}`in this&&(this[t]=e,this[`$en$${t}`]=s)}_$updateEnv(t,e,s){`$e$${t}`in this&&s===this[`$en$${t}`]&&this[t]!==e&&(this[t]=e)}_$setContent(t){let e=this._$contentKey;e&&this[e]!==t&&(this[e]=t)}_$updateProp(t,e){let s=`$${t}`;this[s]!==e&&(this[s]=e,this._$updateDerived(t),this._$updateView(t))}_$updateDerived(t){"_$notInitd"in this||this[`$s$${t}`]?.forEach(e=>{`$w$${e}`in this?this[e]():this[`$${e}`]=this[`$f$${e}`]})}_$updateView(t){let e=this[`$$${t}`];e&&this._$update?.(e)}},ot=D;function nt(o,t){o._$updateDerived(t),o._$updateView(t)}var S=class{constructor(){this.envs={},this.currentEnvNodes=[]}addEnvNode(t){this.currentEnvNodes.push(t),this.mergeEnvs()}replaceEnvNodes(t){this.currentEnvNodes=t,this.mergeEnvs()}removeEnvNode(){this.currentEnvNodes.pop(),this.mergeEnvs()}mergeEnvs(){this.envs={},this.currentEnvNodes.forEach(t=>{Object.entries(t.envs).forEach(([e,s])=>{this.envs[e]=[s,t]})})}},T=class extends d{constructor(t){super(f.Env),h.global.DLEnvStore||(h.global.DLEnvStore=new S),this.envs=t,this.updateNodes=new Set,h.global.DLEnvStore.addEnvNode(this)}updateEnv(t,e){this.envs[t]=e,h.global.DLEnvStore.currentEnvNodes.includes(this)&&h.global.DLEnvStore.mergeEnvs(),this.updateNodes.forEach(s=>{s._$updateEnv(t,e,this)})}addNode(t){this.updateNodes.add(t),d.addWillUnmount(t,this.updateNodes.delete.bind(this.updateNodes,t))}initNodes(t){this._$nodes=t,h.global.DLEnvStore.removeEnvNode()}};function at(o){return h.document.createTextNode(o)}function lt(o,t){o.textContent!==t&&(o.textContent=t)}var W=class{propViewFunc;dlUpdateFunc=new Set;constructor(t){this.propViewFunc=t}build(){let t,e=n=>{n.initd=!0,t=n,this.dlUpdateFunc.add(n)},s=this.propViewFunc(e);return s.length===0?[]:(t&&d.addWillUnmount(s[0],this.dlUpdateFunc.delete.bind(this.dlUpdateFunc,t)),s)}update(t){this.dlUpdateFunc.forEach(e=>{if(e.initd){delete e.initd;return}e(t)})}};var U=class extends d{constructor(){super(f.Subview)}};var p=class extends d{constructor(t){super(t),h.global.DLEnvStore&&h.global.DLEnvStore.currentEnvNodes.length>0&&(this.savedEnvNodes=[...h.global.DLEnvStore.currentEnvNodes])}initNewNodes(t){d.addParentEl(t,this._$parentEl)}geneNewNodesInEnv(t){if(!this.savedEnvNodes){let n=t();return this.initNewNodes(n),n}let e=h.global.DLEnvStore.currentEnvNodes;h.global.DLEnvStore.replaceEnvNodes(this.savedEnvNodes);let s=t();return h.global.DLEnvStore.replaceEnvNodes(e),this.initNewNodes(s),s}removeNodes(t){d.loopDLNodes(t,e=>e.willUnmount?.()),d.loopShallowEls(t,e=>{this._$parentEl?.removeChild(e)}),d.loopDLNodesInsideOut(t,e=>e.didUnmount?.())}};var g=class extends p{array;keys;nodeFunc;nodess;depNum;updateArr=[];constructor(t,e,s){super(f.For),this.array=[...t],this.keys=s,this.depNum=e}addNodeFunc(t){this.nodeFunc=t,this.nodess=this.array.map((e,s)=>t(e,this.updateArr,s)),this._$nodes=this.nodess.flat(1)}update(t){if(!(t&this.depNum))for(let e=0;e<this.array.length;e++)this.updateItem(e,t)}updateItem(t,e){this.updateArr[t]?.(e??this.depNum,this.array[t])}updateArray(t,e){if(e){this.updateWithKey(t,e);return}this.updateWithOutKey(t)}getNewNodes(t){return this.geneNewNodesInEnv(()=>this.nodeFunc(this.array[t],this.updateArr,t))}updateWithOutKey(t){let e=this.array.length,s=t.length;if(this.array=[...t],this.updateArr=this.updateArr.slice(0,s),e===s){for(let i=0;i<this.array.length;i++)this.updateItem(i);return}let n=this._$parentEl;if(e<s){let i=p.getFlowIndexFromNodes(n._$nodes,this),$=n.childNodes.length;for(let a=0;a<s;a++){if(a<e){i+=p.getFlowIndexFromNodes(this.nodess[a]),this.updateItem(a);continue}let l=this.getNewNodes(a);p.appendNodesWithIndex(l,n,i,$),this.nodess.push(l)}this._$nodes=this.nodess.flat(1);return}for(let i=0;i<s;i++)this.updateItem(i);for(let i=s;i<e;i++)this.removeNodes(this.nodess[i]);this.nodess=this.nodess.slice(0,s),this._$nodes=this.nodess.flat(1)}updateWithKey(t,e){let s=this.keys;if(this.array=[...t],this.keys=e,g.arrayEqual(s,this.keys)){for(let r=0;r<this.array.length;r++)this.updateItem(r);return}let n=this._$parentEl,i=this.nodess;if(this.keys.length===0){let r=n._$nodes??[];if(r.length===1&&r[0]===this)n.innerHTML="";else for(let c=0;c<s.length;c++)this.removeNodes(i[c]);this.nodess=[],this._$nodes=[],this.updateArr=[];return}let $=p.getFlowIndexFromNodes(n._$nodes,this);if(s.length===0){let r=n.childNodes[$];for(let c=0;c<this.keys.length;c++){let u=this.getNewNodes(c);p.appendNodesWithSibling(u,n,r),this.nodess.push(u)}this._$nodes=this.nodess.flat(1);return}let a=[],l=[],N=[];for(let r=0;r<s.length;r++){let c=s[r];if(this.keys.includes(c)){a.push(c),l.push(i[r]),N.push(this.updateArr[r]);continue}this.removeNodes(i[r])}let w=n.childNodes.length,m=$;for(let r=0;r<this.keys.length;r++){let c=this.keys[r],u=a.indexOf(c);if(u!==-1){m+=p.getFlowIndexFromNodes(l[u]),this.updateArr[u]?.(this.depNum,this.array[r]);continue}N.splice(r,0,null);let x=this.getNewNodes(r),b=p.appendNodesWithIndex(x,n,m,w);m+=b,w+=b,l.splice(r,0,x),a.splice(r,0,c)}if(g.arrayEqual(this.keys,a)){this.nodess=l,this._$nodes=this.nodess.flat(1),this.updateArr=N;return}m=$;let L=[];for(let r=0;r<this.keys.length;r++){let c=this.keys[r],u=a.indexOf(c),x=L[r];if(x){let _=p.appendNodesWithIndex(x,n,m+p.getFlowIndexFromNodes(x),w);m+=_,w+=_,L[r]=void 0}else if(u===r){m+=p.getFlowIndexFromNodes(l[r]);continue}else{L[this.keys.indexOf(a[r])]=l[r];let _=p.appendNodesWithIndex(l[u],n,m,w);m+=_,w+=_}let b=l[r];l[r]=l[u],l[u]=b;let A=a[r];a[r]=a[u],a[u]=A;let M=N[r];N[r]=N[u],N[u]=M}this.nodess=l,this._$nodes=this.nodess.flat(1),this.updateArr=N}static arrayEqual(t,e){return t.length!==e.length?!1:t.every((s,n)=>s===e[n])}};var v=class extends p{nodesFunc;constructor(t){super(f.Exp),this.nodesFunc=t,this._$nodes=v.formatNodes(t())}update(){let t=this.geneNewNodesInEnv(()=>v.formatNodes(this.nodesFunc()));if(this.removeNodes(this._$nodes),t.length===0){this._$nodes=[];return}let e=this._$parentEl,s=p.getFlowIndexFromNodes(e._$nodes,this),n=e.childNodes[s];p.appendNodesWithSibling(t,e,n),this._$nodes=t}static formatNodes(t){return Array.isArray(t)||(t=[t]),t.flat(1).filter(e=>e!=null&&typeof e!="boolean").map(e=>typeof e=="string"||typeof e=="number"||typeof e=="bigint"?h.document.createTextNode(`${e}`):"propViewFunc"in e?e.build():e).flat(1)}};var O=class extends p{condFunc;cond;depNum;constructor(t){super(f.Cond),this.depNum=t}addCondFunc(t){this.cond=-1,this.condFunc=t,this._$nodes=this.condFunc(this)}updateCond(){let t=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),t.length===0)return this._$nodes=[],this._$nodes;let e=this._$parentEl,s=p.getFlowIndexFromNodes(e._$nodes,this),n=e.childNodes[s];return p.appendNodesWithSibling(t,e,n),this._$nodes=t,this._$nodes}update(t){t&this.depNum||this.updateFunc?.(t)}};function Tt(o,t){let e=o;if(typeof o=="string"){let n=h.document.getElementById(o);if(n)e=n;else throw new Error(`DLight: Element with id ${o} not found`)}e.innerHTML="";let s=new t;s._$init(),P(e,s,0)}function Wt(o,t){return o()}function G(o){return o}var Ut=G;export{Ut as $,D as CompNode,O as CondNode,T as EnvNode,v as ExpNode,g as ForNode,W as PropView,U as SubViewNode,ot as View,Z as createElement,Y as createTemplate,at as createTextNode,G as escape,I as forwardHTMLProp,P as insertNode,Wt as manual,Tt as render,j as setDataset,H as setDocument,q as setEvent,C as setGlobal,y as setHTMLAttr,V as setHTMLAttrs,F as setHTMLProp,B as setHTMLProps,K as setStyle,nt as update,lt as updateText}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dlightjs/dlight", | ||
"version": "1.0.0-alpha.38", | ||
"version": "1.0.0-alpha.39", | ||
"description": "DX-first UI rendering library", | ||
@@ -21,2 +21,5 @@ "author": { | ||
"typings": "dist/index.d.ts", | ||
"dependencies": { | ||
"@dlightjs/store": "0.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -23,0 +26,0 @@ "tsup": "^6.5.0" |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
138844
102
1
3
+ Added@dlightjs/store@0.0.0
+ Added@dlightjs/store@0.0.0(transitive)