New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dlightjs/dlight

Package Overview
Dependencies
Maintainers
2
Versions
274
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dlightjs/dlight - npm Package Compare versions

Comparing version 1.0.0-alpha.26 to 1.0.0-alpha.27

1

dist/index.d.ts

@@ -220,2 +220,3 @@ type AnyDLNode = any;

updateNodes: Set<CompNode>;
envs: Record<string, any>;
/**

@@ -222,0 +223,0 @@ * @brief Constructor, Env type, accept a record of envs, add this node to DLEnvStore

2

dist/index.js

@@ -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 i=s.shift();if(i===t)break;"_$dlNodeType"in i?i._$nodes&&s.unshift(...i._$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,i=>{t.insertBefore(i,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)}};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 O(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 U(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"){O(o,t);return}if(e==="attr"){U(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(([i,c])=>{this._$setProp(i,c)}),n&&(this._$children=n),Object.entries(window.DLEnvStore.envs).forEach(([i,[c,p]])=>{p.addNode(this),this._$initEnv(i,c,p)}),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(i=>{i._$dlNodeType===0&&i._$setProp(e,s),i instanceof HTMLElement&&w(i,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 D=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 i=0;i<this.array.length;i++)this.updateItem(i);return}let s=this._$parentEl;if(t<n){let i=a.getFlowIndexFromNodes(s._$nodes,this),c=s.childNodes.length;for(let p=0;p<n;p++){if(p<t){i+=a.getFlowIndexFromNodes(this.nodess[p]),this.updateItem(p);continue}let u=this.getNewNodes(p);a.appendNodesWithIndex(u,s,i,c),this.nodess.push(u)}this._$nodes=this.nodess.flat(1);return}for(let i=0;i<n;i++)this.updateItem(i);for(let i=n;i<t;i++)this.removeNodes(this.nodess[i]);this.nodess=this.nodess.slice(0,n),this._$nodes=this.nodess.flat(1)}updateWithKey(e,t){let n=this.keys,s=this.array;if(this.array=[...e],this.keys=t,this.updateArr=this.updateArr.slice(0,this.keys.length),D.arrayEqual(n,this.keys)){for(let r=0;r<this.array.length;r++)this.updateItem(r);return}let i=this._$parentEl,c=this.nodess;if(this.keys.length===0){let r=i._$nodes??[];if(r.length===1&&r[0]===this)i.innerHTML="";else for(let h=0;h<n.length;h++)this.removeNodes(c[h]);this.nodess=[],this._$nodes=[];return}let p=a.getFlowIndexFromNodes(i._$nodes,this);if(n.length===0){let r=i.childNodes[p];for(let h=0;h<this.keys.length;h++){let N=this.getNewNodes(h);a.appendNodesWithSibling(N,i,r),this.nodess.push(N)}this._$nodes=this.nodess.flat(1);return}let u=[],l=[],S=[];for(let r=0;r<n.length;r++){let h=n[r];if(this.keys.includes(h)){u.push(h),l.push(c[r]),S.push(s[r]);continue}this.removeNodes(c[r])}let y=i.childNodes.length,f=p;for(let r=0;r<this.keys.length;r++){let h=this.keys[r],N=u.indexOf(h);if(N!==-1){f+=a.getFlowIndexFromNodes(l[N]),this.updateItem(r);continue}let m=this.getNewNodes(r),A=a.appendNodesWithIndex(m,i,f,y);f+=A,y+=A,l.splice(r,0,m),u.splice(r,0,h)}if(D.arrayEqual(this.keys,u)){this.nodess=l,this._$nodes=this.nodess.flat(1);return}f=p;let E=[];for(let r=0;r<this.keys.length;r++){let h=this.keys[r],N=u.indexOf(h),m=E[r];if(m){let L=a.appendNodesWithIndex(m,i,f+a.getFlowIndexFromNodes(m),y);f+=L,y+=L,E[r]=void 0}else if(N===r){f+=a.getFlowIndexFromNodes(l[r]);continue}else{E[this.keys.indexOf(u[r])]=l[r];let L=a.appendNodesWithIndex(l[N],i,f,y);f+=L,y+=L}let A=l[r];l[r]=l[N],l[N]=A;let P=u[r];u[r]=u[N],u[N]=P}this.nodess=l,this._$nodes=this.nodess.flat(1)}static arrayEqual(e,t){return e.length!==t.length?!1:e.every((n,s)=>n===t[s])}};var v=class extends a{nodesFunc;constructor(e){super(4),this.nodesFunc=e,this._$nodes=v.formatNodes(e())}update(){let e=this.geneNewNodesInEnv(()=>v.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;constructor(e){super(3),this.envs=e,window.DLEnvStore.addEnvNode(this),delete this.envs}updateEnv(e,t){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(o){return document.createTextNode(o)}function le(o,e){o.textContent!==e&&(o.textContent=e)}var F=class{propViewFunc;dlUpdateFunc=new Set;constructor(e){this.propViewFunc=e}build(){let e,t=s=>{e=s,this.dlUpdateFunc.add(s)},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=>{t(e)})}};var H=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;b(t,n,0)}function De(o,e){return o()}function j(o){return o}var ve=j;export{ve as $,g as CompNode,I as CondNode,M as EnvNode,v as ExpNode,D as ForNode,F as PropView,H as SubViewNode,Q as View,G as createElement,R as createTemplate,ue as createTextNode,j as escape,w as forwardHTMLProp,b as insertNode,De as manual,$e as render,W as setDataset,K as setEvent,T as setHTMLAttr,U as setHTMLAttrs,_ as setHTMLProp,O as setHTMLProps,C as setStyle,X as update,le 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,s=[...e];for(;s.length>0;){let i=s.shift();if(i===t)break;"_$dlNodeType"in i?i._$nodes&&s.unshift(...i._$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,i=>{t.insertBefore(i,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)}};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 O(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 U(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"){O(o,t);return}if(e==="attr"){U(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(([i,N])=>{this._$setProp(i,N)}),n&&(this._$children=n),Object.entries(window.DLEnvStore.envs).forEach(([i,[N,p]])=>{p.addNode(this),this._$initEnv(i,N,p)}),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(i=>{i._$dlNodeType===0&&i._$setProp(e,s),i instanceof HTMLElement&&w(i,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 i=0;i<this.array.length;i++)this.updateItem(i);return}let s=this._$parentEl;if(t<n){let i=a.getFlowIndexFromNodes(s._$nodes,this),N=s.childNodes.length;for(let p=0;p<n;p++){if(p<t){i+=a.getFlowIndexFromNodes(this.nodess[p]),this.updateItem(p);continue}let u=this.getNewNodes(p);a.appendNodesWithIndex(u,s,i,N),this.nodess.push(u)}this._$nodes=this.nodess.flat(1);return}for(let i=0;i<n;i++)this.updateItem(i);for(let i=n;i<t;i++)this.removeNodes(this.nodess[i]);this.nodess=this.nodess.slice(0,n),this._$nodes=this.nodess.flat(1)}updateWithKey(e,t){let n=this.keys,s=this.array;if(this.array=[...e],this.keys=t,this.updateArr=this.updateArr.slice(0,this.keys.length),v.arrayEqual(n,this.keys)){for(let r=0;r<this.array.length;r++)this.updateItem(r);return}let i=this._$parentEl,N=this.nodess;if(this.keys.length===0){let r=i._$nodes??[];if(r.length===1&&r[0]===this)i.innerHTML="";else for(let h=0;h<n.length;h++)this.removeNodes(N[h]);this.nodess=[],this._$nodes=[];return}let p=a.getFlowIndexFromNodes(i._$nodes,this);if(n.length===0){let r=i.childNodes[p];for(let h=0;h<this.keys.length;h++){let c=this.getNewNodes(h);a.appendNodesWithSibling(c,i,r),this.nodess.push(c)}this._$nodes=this.nodess.flat(1);return}let u=[],l=[],S=[];for(let r=0;r<n.length;r++){let h=n[r];if(this.keys.includes(h)){u.push(h),l.push(N[r]),S.push(s[r]);continue}this.removeNodes(N[r])}let y=i.childNodes.length,f=p;for(let r=0;r<this.keys.length;r++){let h=this.keys[r],c=u.indexOf(h);if(c!==-1){f+=a.getFlowIndexFromNodes(l[c]),this.updateItem(r);continue}let m=this.getNewNodes(r),A=a.appendNodesWithIndex(m,i,f,y);f+=A,y+=A,l.splice(r,0,m),u.splice(r,0,h)}if(v.arrayEqual(this.keys,u)){this.nodess=l,this._$nodes=this.nodess.flat(1);return}f=p;let E=[];for(let r=0;r<this.keys.length;r++){let h=this.keys[r],c=u.indexOf(h),m=E[r];if(m){let L=a.appendNodesWithIndex(m,i,f+a.getFlowIndexFromNodes(m),y);f+=L,y+=L,E[r]=void 0}else if(c===r){f+=a.getFlowIndexFromNodes(l[r]);continue}else{E[this.keys.indexOf(u[r])]=l[r];let L=a.appendNodesWithIndex(l[c],i,f,y);f+=L,y+=L}let A=l[r];l[r]=l[c],l[c]=A;let P=u[r];u[r]=u[c],u[c]=P}this.nodess=l,this._$nodes=this.nodess.flat(1)}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,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(o){return document.createTextNode(o)}function le(o,e){o.textContent!==e&&(o.textContent=e)}var F=class{propViewFunc;dlUpdateFunc=new Set;constructor(e){this.propViewFunc=e}build(){let e,t=s=>{e=s,this.dlUpdateFunc.add(s)},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=>{t(e)})}};var H=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;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,F as PropView,H 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,U as setHTMLAttrs,_ as setHTMLProp,O as setHTMLProps,C as setStyle,X as update,le as updateText};
//# sourceMappingURL=index.js.map
{
"name": "@dlightjs/dlight",
"version": "1.0.0-alpha.26",
"version": "1.0.0-alpha.27",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc