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.61 to 1.0.0-alpha.62

2

dist/index.js

@@ -1,2 +0,2 @@

import{Store as N}from"@dlightjs/store";"global"in N||(typeof window<"u"?N.global=window:typeof global<"u"?N.global=global:N.global={});"document"in N||typeof document<"u"&&(N.document=document);var o=N;function T(i){o.global=i}function y(i){o.document=i}var c={Comp:0,For:1,Cond:2,Env:3,Exp:4,Subview:5},h=class{_$dlNodeType;constructor(t){this._$dlNodeType=t}get _$el(){return h.toEls(this._$nodes)}static toEls(t){let e=[];return this.loopShallowEls(t,n=>{e.push(n)}),e}static loopShallowEls(t,e){t.forEach(n=>{if(!("_$dlNodeType"in n))return e(n);n._$nodes&&h.loopShallowEls(n._$nodes,e)})}static addParentEl(t,e){t.forEach(n=>{"_$dlNodeType"in n&&(n._$parentEl=e,n._$nodes&&h.addParentEl(n._$nodes,e))})}static getFlowIndexFromNodes(t,e){let n=0,s=[...t];for(;s.length>0;){let r=s.shift();if(r===e)break;"_$dlNodeType"in r?r._$nodes&&s.unshift(...r._$nodes):n++}return n}static appendNodesWithSibling(t,e,n){return n?this.insertNodesBefore(t,e,n):this.appendNodes(t,e)}static appendNodesWithIndex(t,e,n,s){return s=s??e.childNodes.length,s!==n?this.insertNodesBefore(t,e,e.childNodes[n]):this.appendNodes(t,e)}static insertNodesBefore(t,e,n){let s=0;return this.loopShallowEls(t,r=>{e.insertBefore(r,n),s++}),s}static appendNodes(t,e){let n=0;return this.loopShallowEls(t,s=>{e.appendChild(s),n++}),n}static addWillUnmount(t,e){let n=o.global.WillUnmountStore,s=n[n.length-1];s&&s.push(e.bind(null,t))}static addDidUnmount(t,e){let n=o.global.DidUnmountStore,s=n[n.length-1];s&&s.push(e.bind(null,t))}static addDidMount(t,e){o.global.DidMountStore||(o.global.DidMountStore=[]),o.global.DidMountStore.push(e.bind(null,t))}static runDidMount(){let t=o.global.DidMountStore;if(!(!t||t.length===0)){for(let e=t.length-1;e>=0;e--)t[e]();o.global.DidMountStore=[]}}};function O(i,t){Object.assign(i.style,t)}function H(i,t){Object.assign(i.dataset,t)}function S(i,t,e){let n=`$${t}`;n in i&&i[n]===e||(i[t]=e,i[n]=e)}function K(i,t){Object.entries(t).forEach(([e,n])=>{S(i,e,n)})}function _(i,t,e){let n=`$${t}`;n in i&&i[n]===e||(i.setAttribute(t,e),i[n]=e)}function j(i,t){Object.entries(t).forEach(([e,n])=>{_(i,e,n)})}function C(i,t,e){let n=i[`$on${t}`];n&&i.removeEventListener(t,n),i.addEventListener(t,e),i[`$on${t}`]=e}function R(i){return o.document.createElement(i)}function L(i,t,e){i._$nodes||(i._$nodes=Array.from(i.childNodes)),i._$nodes.splice(e,0,t);let n=h.getFlowIndexFromNodes(i._$nodes,t);h.appendNodesWithIndex([t],i,n),h.addParentEl([t],i)}function b(i,t,e){if(t==="style"){O(i,e);return}if(t==="dataset"){H(i,e);return}if(t!=="element"){if(t==="prop"){K(i,e);return}if(t==="attr"){j(i,e);return}if(t==="innerHTML"){S(i,"innerHTML",e);return}if(t!=="forwardProp"){if(t.startsWith("on")){C(i,t.slice(2).toLowerCase(),e);return}_(i,t,e)}}}var D=class extends h{constructor(){super(c.Comp)}_$init(t,e,n,s){this._$notInitd=!0,s&&s._$addForwardProps(this),e!==null&&this._$setContent(e),t&&Object.entries(t).forEach(([r,p])=>{this._$setProp(r,p)}),n&&(this._$children=n),o.global.DLEnvStore&&Object.entries(o.global.DLEnvStore.envs).forEach(([r,[p,a]])=>{a.addNode(this),this._$initEnv(r,p,a)}),this._$callUpdatesBeforeInit(),this.didMount&&h.addDidMount(this,this.didMount.bind(this)),this.willUnmount&&h.addWillUnmount(this,this.willUnmount.bind(this)),this.didUnmount&&h.addDidUnmount(this,this.didUnmount.bind(this)),this.willMount?.(),this._$nodes=this.View?.()??[]}_$callUpdatesBeforeInit(){let t=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),e=Object.getOwnPropertyNames(this);[...t,...e].forEach(s=>{if(s.startsWith("$w$"))return this[s.slice(3)]();s.startsWith("$f$")&&(this[`$${s.slice(3)}`]=this[s])}),delete this._$notInitd}_$setForwardProp(t,e){if(t in this){this[t]=e;return}this._$forwardPropsId.push(t);let n=`$${t}`;this[n]=e,Object.defineProperty(this,t,{get(){return this[n]},set(s){this[n]!==s&&(this[n]=s,this._$forwardPropsSet?.forEach(r=>{r._$dlNodeType===c.Comp&&r._$setProp(t,s),r instanceof HTMLElement&&b(r,t,s)}))}})}_$addForwardProps(t){this._$forwardPropsSet.add(t),this._$forwardPropsId.forEach(e=>{let n=this[e];this._$forwardPropsSet?.forEach(s=>{s._$dlNodeType===c.Comp&&("_$forwardProps"in s&&s._$forwardPropsId.push(e),s._$setProp(e,n)),s instanceof HTMLElement&&b(s,e,n)})}),h.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,n){`$e$${t}`in this&&(this[t]=e,this[`$en$${t}`]=n)}_$updateEnv(t,e,n){`$e$${t}`in this&&n===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 n=`$${t}`;if(this[n]===e)return;let s=this[n];this[n]=e,this._$updateDerived(t,s,e),this._$updateView(t,s,e)}_$updateDerived(t,e,n){"_$notInitd"in this||this[`$s$${t}`]?.forEach(s=>{`$w$${s}`in this?this[s](t,e,n):this[`$${s}`]=this[`$f$${s}`]})}_$updateView(t,e,n){let s=this[`$$${t}`];s&&this._$update?.(s,t,e,n)}},tt=D;function et(i,t){i._$updateDerived(t),i._$updateView(t)}var v=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,n])=>{this.envs[e]=[n,t]})})}},F=class extends h{constructor(t){super(c.Env),"DLEnvStore"in o.global||(o.global.DLEnvStore=new v),this.envs=t,this.updateNodes=new Set,o.global.DLEnvStore.addEnvNode(this)}updateEnv(t,e){this.envs[t]=e,o.global.DLEnvStore.currentEnvNodes.includes(this)&&o.global.DLEnvStore.mergeEnvs(),this.updateNodes.forEach(n=>{n._$updateEnv(t,e,this)})}addNode(t){this.updateNodes.add(t),h.addWillUnmount(t,this.updateNodes.delete.bind(this.updateNodes,t))}initNodes(t){this._$nodes=t,o.global.DLEnvStore.removeEnvNode()}};function dt(i){return o.document.createTextNode(i)}function ht(i,t){i.textContent!==t&&(i.textContent=t)}var I=class{propViewFunc;dlUpdateFunc=new Set;constructor(t){this.propViewFunc=t}build(){let t,e=s=>{t=s,this.dlUpdateFunc.add(s)},n=this.propViewFunc(e);return n.length===0?[]:(t&&h.addWillUnmount(n[0],this.dlUpdateFunc.delete.bind(this.dlUpdateFunc,t)),n)}update(...t){this.dlUpdateFunc.forEach(e=>{e(...t)})}};var W=class extends h{constructor(){super(c.Subview)}};var w=class extends h{constructor(t){super(t),o.global.DLEnvStore&&o.global.DLEnvStore.currentEnvNodes.length>0&&(this.savedEnvNodes=[...o.global.DLEnvStore.currentEnvNodes])}initNewNodes(t){h.addParentEl(t,this._$parentEl)}geneNewNodesInEnv(t){if(!this.savedEnvNodes){let s=t();return this.initNewNodes(s),s}let e=o.global.DLEnvStore.currentEnvNodes;o.global.DLEnvStore.replaceEnvNodes(this.savedEnvNodes);let n=t();return o.global.DLEnvStore.replaceEnvNodes(e),this.initNewNodes(n),n}initUnmountStore(){o.global.WillUnmountStore.push([]),o.global.DidUnmountStore.push([])}removeNodes(t){h.loopShallowEls(t,e=>{this._$parentEl.removeChild(e)})}};var l=class extends w{array;nodeFunc;depNum;nodesMap=new Map;updateMap=new Map;get _$nodes(){let t=[];for(let e=0;e<this.array.length;e++)t.push(...this.nodesMap.get(this.keys?.[e]??e));return t}constructor(t,e,n){super(c.For),this.array=[...t],this.keys=n,this.depNum=e}addNodeFunc(t){this.nodeFunc=t,this.array.forEach((e,n)=>{this.initUnmountStore();let s=this.keys?.[n]??n,r=t(e,this.updateMap,s);this.nodesMap.set(s,r),this.setUnmountMap(s)}),l.addWillUnmount(this,this.runAllWillUnmount.bind(this)),l.addDidUnmount(this,this.runAllDidUnmount.bind(this))}update(t,...e){if(!(t&this.depNum)){this.updateArgs=e;for(let n=0;n<this.array.length;n++)this.updateItem(n,this.array,t)}}updateItem(t,e,n){let s=this.keys?.[t]??t;this.updateMap.get(s)?.(n??this.depNum,...this.updateArgs,e[t])}updateArray(t,e,n,s,r){if(this.updateArgs=[e,n,s],r){this.updateWithKey(t,r);return}this.updateWithOutKey(t)}getNewNodes(t,e,n){this.initUnmountStore();let s=this.geneNewNodesInEnv(()=>this.nodeFunc(n[t],this.updateMap,e));return this.setUnmountMap(e),this.nodesMap.set(e,s),s}setUnmountMap(t){let e=o.global.WillUnmountStore.pop();e&&e.length>0&&(this.willUnmountMap||(this.willUnmountMap=new Map),this.willUnmountMap.set(t,e));let n=o.global.DidUnmountStore.pop();n&&n.length>0&&(this.didUnmountMap||(this.didUnmountMap=new Map),this.didUnmountMap.set(t,n))}runAllWillUnmount(){!this.willUnmountMap||this.willUnmountMap.size===0||(this.willUnmountMap.forEach(t=>{for(let e=0;e<t.length;e++)t[e]?.()}),this.willUnmountMap.clear())}runAllDidUnmount(){!this.didUnmountMap||this.didUnmountMap.size===0||(this.didUnmountMap.forEach(t=>{for(let e=t.length-1;e>=0;e--)t[e]?.()}),this.didUnmountMap.clear())}runWillUnmount(t){if(!this.willUnmountMap||this.willUnmountMap.size===0)return;let e=this.willUnmountMap.get(t);if(e){for(let n=0;n<e.length;n++)e[n]?.();this.willUnmountMap.delete(t)}}runDidUnmount(t){if(!this.didUnmountMap||this.didUnmountMap.size===0)return;let e=this.didUnmountMap.get(t);if(e){for(let n=e.length-1;n>=0;n--)e[n]?.();this.didUnmountMap.delete(t)}}removeNodes(t,e){this.runWillUnmount(e),super.removeNodes(t),this.runDidUnmount(e),this.updateMap.delete(e),this.nodesMap.delete(e)}updateWithOutKey(t){let e=this.array.length,n=t.length;if(e===n){for(let r=0;r<this.array.length;r++)this.updateItem(r,t);this.array=[...t];return}let s=this._$parentEl;if(e<n){let r=l.getFlowIndexFromNodes(s._$nodes,this),p=s.childNodes.length;for(let a=0;a<n;a++){if(a<e){r+=l.getFlowIndexFromNodes(this.nodesMap.get(a)),this.updateItem(a,t);continue}let f=this.getNewNodes(a,a,t);l.appendNodesWithIndex(f,s,r,p)}l.runDidMount(),this.array=[...t];return}for(let r=0;r<n;r++)this.updateItem(r,t);for(let r=n;r<e;r++){let p=this.nodesMap.get(r);this.removeNodes(p,r)}this.array=[...t]}updateWithKey(t,e){if(e.length!==new Set(e).size)throw new Error("DLight: Duplicate keys in for loop are not allowed");let n=this.keys;if(this.keys=e,l.arrayEqual(n,this.keys)){for(let d=0;d<t.length;d++)this.updateItem(d,t);this.array=[...t];return}let s=this._$parentEl;if(this.keys.length===0){let d=s._$nodes??[];if(d.length===1&&d[0]===this)this.runAllWillUnmount(),s.innerHTML="",this.runAllDidUnmount();else for(let u=0;u<n.length;u++){let m=n[u];this.removeNodes(this.nodesMap.get(m),m)}this.nodesMap.clear(),this.updateMap.clear(),this.array=[];return}let r=l.getFlowIndexFromNodes(s._$nodes,this);if(n.length===0){let d=s.childNodes[r];for(let u=0;u<this.keys.length;u++){let m=this.getNewNodes(u,this.keys[u],t);l.appendNodesWithSibling(m,s,d)}l.runDidMount(),this.array=[...t];return}let p=[];for(let d=0;d<n.length;d++){let u=n[d];if(this.keys.includes(u)){p.push(u);continue}this.removeNodes(this.nodesMap.get(u),u)}let a=s.childNodes.length,f=r;for(let d=0;d<this.keys.length;d++){let u=this.keys[d];if(p.includes(u)){f+=l.getFlowIndexFromNodes(this.nodesMap.get(u)),this.updateItem(d,t);continue}let m=this.getNewNodes(d,u,t);p.splice(d,0,u);let U=l.appendNodesWithIndex(m,s,f,a);f+=U,a+=U}if(l.runDidMount(),l.arrayEqual(this.keys,p)){this.array=[...t];return}f=r;let M=[];for(let d=0;d<this.keys.length;d++){let u=this.keys[d],m=p.indexOf(u),U=M[d];if(U){let x=l.appendNodesWithIndex(U,s,f+l.getFlowIndexFromNodes(U),a);f+=x,a+=x,M[d]=void 0}else if(m===d){f+=l.getFlowIndexFromNodes(this.nodesMap.get(u));continue}else{M[this.keys.indexOf(p[d])]=this.nodesMap.get(this.keys[m]);let x=l.appendNodesWithIndex(this.nodesMap.get(u),s,f,a);f+=x,a+=x}let P=p[d];p[d]=p[m],p[m]=P}this.array=[...t]}static arrayEqual(t,e){return t.length!==e.length?!1:t.every((n,s)=>n===e[s])}};var E=class extends w{willUnmountFuncs=[];didUnmountFuncs=[];setUnmountFuncs(){this.willUnmountFuncs=o.global.WillUnmountStore.pop(),this.didUnmountFuncs=o.global.DidUnmountStore.pop()}runWillUnmount(){for(let t=0;t<this.willUnmountFuncs.length;t++)this.willUnmountFuncs[t]()}runDidUnmount(){for(let t=this.didUnmountFuncs.length-1;t>=0;t--)this.didUnmountFuncs[t]()}removeNodes(t){this.runWillUnmount(),super.removeNodes(t),this.runDidUnmount()}geneNewNodesInEnv(t){this.initUnmountStore();let e=super.geneNewNodesInEnv(t);return this.setUnmountFuncs(),e}};var $=class extends E{nodesFunc;constructor(t){super(c.Exp),this.nodesFunc=t,this.initUnmountStore(),this._$nodes=$.formatNodes(t()),this.setUnmountFuncs(),$.addWillUnmount(this,this.runWillUnmount.bind(this)),$.addDidUnmount(this,this.runDidUnmount.bind(this))}update(){this.removeNodes(this._$nodes);let t=this.geneNewNodesInEnv(()=>$.formatNodes(this.nodesFunc()));if(t.length===0){this._$nodes=[];return}let e=this._$parentEl,n=$.getFlowIndexFromNodes(e._$nodes,this),s=e.childNodes[n];$.appendNodesWithSibling(t,e,s),$.runDidMount(),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"?o.document.createTextNode(`${e}`):"propViewFunc"in e?e.build():e).flat(1)}};var g=class extends E{condFunc;cond;depNum;constructor(t){super(c.Cond),this.depNum=t}addCondFunc(t){this.cond=-1,this.condFunc=t,this.initUnmountStore(),this._$nodes=this.condFunc(this),this.setUnmountFuncs(),g.addWillUnmount(this,this.runWillUnmount.bind(this)),g.addDidUnmount(this,this.runDidUnmount.bind(this))}updateCond(...t){let e=[this.willUnmountFuncs,this.didUnmountFuncs],n=this.geneNewNodesInEnv(()=>this.condFunc(this));if(this.didntChange)return[this.willUnmountFuncs,this.didUnmountFuncs]=e,this.didntChange=!1,this.updateFunc?.(this.depNum,...t),this._$nodes;let s=[this.willUnmountFuncs,this.didUnmountFuncs];if([this.willUnmountFuncs,this.didUnmountFuncs]=e,this._$nodes&&this._$nodes.length>0&&this.removeNodes(this._$nodes),[this.willUnmountFuncs,this.didUnmountFuncs]=s,n.length===0)return this._$nodes=[],this._$nodes;let r=this._$parentEl,p=g.getFlowIndexFromNodes(r._$nodes,this),a=r.childNodes[p];return g.appendNodesWithSibling(n,r,a),g.runDidMount(),this._$nodes=n,this._$nodes}update(t,...e){t&this.depNum||this.updateFunc?.(t,...e)}};function V(){o.global.WillUnmountStore=[],o.global.DidUnmountStore=[]}function Tt(i,t){let e=i;if(typeof i=="string"){let s=o.document.getElementById(i);if(s)e=s;else throw new Error(`DLight: Element with id ${i} not found`)}V(),e.innerHTML="";let n=new t;n._$init(),L(e,n,0),h.runDidMount()}function yt(i,t){return i()}function B(i){return i}var Ot=B;export{Ot as $,D as CompNode,g as CondNode,F as EnvNode,v as EnvStoreClass,$ as ExpNode,l as ForNode,I as PropView,W as SubViewNode,tt as View,R as createElement,dt as createTextNode,B as escape,b as forwardHTMLProp,L as insertNode,yt as manual,Tt as render,H as setDataset,y as setDocument,C as setEvent,T as setGlobal,_ as setHTMLAttr,j as setHTMLAttrs,S as setHTMLProp,K as setHTMLProps,O as setStyle,et as update,ht as updateText};
import{Store as N}from"@dlightjs/store";"global"in N||(typeof window<"u"?N.global=window:typeof global<"u"?N.global=global:N.global={});"document"in N||typeof document<"u"&&(N.document=document);var r=N;function O(i){r.global=i}function H(i){r.document=i}var c={Comp:0,For:1,Cond:2,Env:3,Exp:4,Subview:5},u=class{_$dlNodeType;constructor(t){this._$dlNodeType=t}get _$el(){return u.toEls(this._$nodes)}static toEls(t){let e=[];return this.loopShallowEls(t,n=>{e.push(n)}),e}static loopShallowEls(t,e){t.forEach(n=>{if(!("_$dlNodeType"in n))return e(n);n._$nodes&&u.loopShallowEls(n._$nodes,e)})}static addParentEl(t,e){t.forEach(n=>{"_$dlNodeType"in n&&(n._$parentEl=e,n._$nodes&&u.addParentEl(n._$nodes,e))})}static getFlowIndexFromNodes(t,e){let n=0,s=[...t];for(;s.length>0;){let o=s.shift();if(o===e)break;"_$dlNodeType"in o?o._$nodes&&s.unshift(...o._$nodes):n++}return n}static appendNodesWithSibling(t,e,n){return n?this.insertNodesBefore(t,e,n):this.appendNodes(t,e)}static appendNodesWithIndex(t,e,n,s){return s=s??e.childNodes.length,s!==n?this.insertNodesBefore(t,e,e.childNodes[n]):this.appendNodes(t,e)}static insertNodesBefore(t,e,n){let s=0;return this.loopShallowEls(t,o=>{e.insertBefore(o,n),s++}),s}static appendNodes(t,e){let n=0;return this.loopShallowEls(t,s=>{e.appendChild(s),n++}),n}static addWillUnmount(t,e){let n=r.global.WillUnmountStore,s=n[n.length-1];s&&s.push(e.bind(null,t))}static addDidUnmount(t,e){let n=r.global.DidUnmountStore,s=n[n.length-1];s&&s.push(e.bind(null,t))}static addDidMount(t,e){r.global.DidMountStore||(r.global.DidMountStore=[]),r.global.DidMountStore.push(e.bind(null,t))}static runDidMount(){let t=r.global.DidMountStore;if(!(!t||t.length===0)){for(let e=t.length-1;e>=0;e--)t[e]();r.global.DidMountStore=[]}}};function K(i,t){Object.assign(i.style,t)}function j(i,t){Object.assign(i.dataset,t)}function _(i,t,e){let n=`$${t}`;n in i&&i[n]===e||(i[t]=e,i[n]=e)}function A(i,t){Object.entries(t).forEach(([e,n])=>{_(i,e,n)})}function L(i,t,e){let n=`$${t}`;n in i&&i[n]===e||(i.setAttribute(t,e),i[n]=e)}function C(i,t){Object.entries(t).forEach(([e,n])=>{L(i,e,n)})}function V(i,t,e){let n=i[`$on${t}`];n&&i.removeEventListener(t,n),i.addEventListener(t,e),i[`$on${t}`]=e}function Y(i){return r.document.createElement(i)}function F(i,t,e){i._$nodes||(i._$nodes=Array.from(i.childNodes)),i._$nodes.splice(e,0,t);let n=u.getFlowIndexFromNodes(i._$nodes,t);u.appendNodesWithIndex([t],i,n),u.addParentEl([t],i)}function M(i,t,e){if(t==="style"){K(i,e);return}if(t==="dataset"){j(i,e);return}if(t!=="element"){if(t==="prop"){A(i,e);return}if(t==="attr"){C(i,e);return}if(t==="innerHTML"){_(i,"innerHTML",e);return}if(t!=="forwardProp"){if(t.startsWith("on")){V(i,t.slice(2).toLowerCase(),e);return}L(i,t,e)}}}var v=class extends u{constructor(){super(c.Comp)}_$init(t,e,n,s){this._$notInitd=!0,s&&s._$addForwardProps(this),e!==null&&this._$setContent(e),t&&Object.entries(t).forEach(([o,a])=>{this._$setProp(o,a)}),n&&(this._$children=n),r.global.DLEnvStore&&Object.entries(r.global.DLEnvStore.envs).forEach(([o,[a,h]])=>{h.addNode(this),this._$initEnv(o,a,h)}),this._$callUpdatesBeforeInit(),this.didMount&&u.addDidMount(this,this.didMount.bind(this)),this.willUnmount&&u.addWillUnmount(this,this.willUnmount.bind(this)),this.didUnmount&&u.addDidUnmount(this,this.didUnmount.bind(this)),this.willMount?.(),this._$nodes=this.View?.()??[]}_$callUpdatesBeforeInit(){let t=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),e=Object.getOwnPropertyNames(this);[...t,...e].forEach(s=>{if(s.startsWith("$w$"))return this[s.slice(3)]();s.startsWith("$f$")&&(this[`$${s.slice(3)}`]=this[s])}),delete this._$notInitd}_$setForwardProp(t,e){if(t in this){this[t]=e;return}this._$forwardPropsId.push(t);let n=`$${t}`;this[n]=e,Object.defineProperty(this,t,{get(){return this[n]},set(s){this[n]!==s&&(this[n]=s,this._$forwardPropsSet?.forEach(o=>{o._$dlNodeType===c.Comp&&o._$setProp(t,s),o instanceof HTMLElement&&M(o,t,s)}))}})}_$addForwardProps(t){this._$forwardPropsSet.add(t),this._$forwardPropsId.forEach(e=>{let n=this[e];this._$forwardPropsSet?.forEach(s=>{s._$dlNodeType===c.Comp&&("_$forwardProps"in s&&s._$forwardPropsId.push(e),s._$setProp(e,n)),s instanceof HTMLElement&&M(s,e,n)})}),u.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,n){`$e$${t}`in this&&(this[t]=e,this[`$en$${t}`]=n)}_$updateEnv(t,e,n){`$e$${t}`in this&&n===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 n=`$${t}`;if(this[n]===e)return;let s=this[n];this[n]=e,this._$updateDerived(t,s,e),this._$updateView(t,s,e)}_$updateDerived(t,e,n){"_$notInitd"in this||this[`$s$${t}`]?.forEach(s=>{`$w$${s}`in this?this[s](t,e,n):this[`$${s}`]=this[`$f$${s}`]})}_$updateView(t,e,n){let s=this[`$$${t}`];s&&this._$update?.(s,t,e,n)}},nt=v;function st(i,t){i._$updateDerived(t),i._$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,n])=>{this.envs[e]=[n,t]})})}},I=class extends u{constructor(t){super(c.Env),"DLEnvStore"in r.global||(r.global.DLEnvStore=new S),this.envs=t,this.updateNodes=new Set,r.global.DLEnvStore.addEnvNode(this)}updateEnv(t,e){this.envs[t]=e,r.global.DLEnvStore.currentEnvNodes.includes(this)&&r.global.DLEnvStore.mergeEnvs(),this.updateNodes.forEach(n=>{n._$updateEnv(t,e,this)})}addNode(t){this.updateNodes.add(t),u.addWillUnmount(t,this.updateNodes.delete.bind(this.updateNodes,t))}initNodes(t){this._$nodes=t,r.global.DLEnvStore.removeEnvNode()}};function ht(i){return r.document.createTextNode(i)}function lt(i,t){i.textContent!==t&&(i.textContent=t)}var W=class{propViewFunc;dlUpdateFunc=new Set;constructor(t){this.propViewFunc=t}build(){let t,e=s=>{t=s,this.dlUpdateFunc.add(s)},n=this.propViewFunc(e);return n.length===0?[]:(t&&u.addWillUnmount(n[0],this.dlUpdateFunc.delete.bind(this.dlUpdateFunc,t)),n)}update(...t){this.dlUpdateFunc.forEach(e=>{e(...t)})}};var P=class extends u{constructor(){super(c.Subview)}};var E=class extends u{constructor(t){super(t),r.global.DLEnvStore&&r.global.DLEnvStore.currentEnvNodes.length>0&&(this.savedEnvNodes=[...r.global.DLEnvStore.currentEnvNodes])}initNewNodes(t){u.addParentEl(t,this._$parentEl)}geneNewNodesInEnv(t){if(!this.savedEnvNodes){let s=t();return this.initNewNodes(s),s}let e=r.global.DLEnvStore.currentEnvNodes;r.global.DLEnvStore.replaceEnvNodes(this.savedEnvNodes);let n=t();return r.global.DLEnvStore.replaceEnvNodes(e),this.initNewNodes(n),n}initUnmountStore(){r.global.WillUnmountStore.push([]),r.global.DidUnmountStore.push([])}removeNodes(t){u.loopShallowEls(t,e=>{this._$parentEl.removeChild(e)})}};var p=class extends E{array;nodeFunc;depNum;nodesMap=new Map;updateArr=[];get _$nodes(){let t=[];for(let e=0;e<this.array.length;e++)t.push(...this.nodesMap.get(this.keys?.[e]??e));return t}constructor(t,e,n){super(c.For),this.array=[...t],this.keys=n,this.depNum=e}addNodeFunc(t){this.nodeFunc=t,this.array.forEach((e,n)=>{this.initUnmountStore();let s=this.keys?.[n]??n,o=t(e,this.updateArr,n);this.nodesMap.set(s,o),this.setUnmountMap(s)}),p.addWillUnmount(this,this.runAllWillUnmount.bind(this)),p.addDidUnmount(this,this.runAllDidUnmount.bind(this))}update(t,...e){if(!(t&this.depNum)){this.updateArgs=e;for(let n=0;n<this.array.length;n++)this.updateItem(n,this.array,t)}}updateItem(t,e,n){this.updateArr[t]?.(n??this.depNum,...this.updateArgs,e[t])}updateArray(t,e,n,s,o){if(this.updateArgs=[e,n,s],o){this.updateWithKey(t,o);return}this.updateWithOutKey(t)}getNewNodes(t,e,n,s){this.initUnmountStore();let o=this.geneNewNodesInEnv(()=>this.nodeFunc(n[t],s??this.updateArr,t));return this.setUnmountMap(e),this.nodesMap.set(e,o),o}setUnmountMap(t){let e=r.global.WillUnmountStore.pop();e&&e.length>0&&(this.willUnmountMap||(this.willUnmountMap=new Map),this.willUnmountMap.set(t,e));let n=r.global.DidUnmountStore.pop();n&&n.length>0&&(this.didUnmountMap||(this.didUnmountMap=new Map),this.didUnmountMap.set(t,n))}runAllWillUnmount(){!this.willUnmountMap||this.willUnmountMap.size===0||(this.willUnmountMap.forEach(t=>{for(let e=0;e<t.length;e++)t[e]?.()}),this.willUnmountMap.clear())}runAllDidUnmount(){!this.didUnmountMap||this.didUnmountMap.size===0||(this.didUnmountMap.forEach(t=>{for(let e=t.length-1;e>=0;e--)t[e]?.()}),this.didUnmountMap.clear())}runWillUnmount(t){if(!this.willUnmountMap||this.willUnmountMap.size===0)return;let e=this.willUnmountMap.get(t);if(e){for(let n=0;n<e.length;n++)e[n]?.();this.willUnmountMap.delete(t)}}runDidUnmount(t){if(!this.didUnmountMap||this.didUnmountMap.size===0)return;let e=this.didUnmountMap.get(t);if(e){for(let n=e.length-1;n>=0;n--)e[n]?.();this.didUnmountMap.delete(t)}}removeNodes(t,e){this.runWillUnmount(e),super.removeNodes(t),this.runDidUnmount(e),this.nodesMap.delete(e)}updateWithOutKey(t){let e=this.array.length,n=t.length;if(e===n){for(let o=0;o<this.array.length;o++)this.updateItem(o,t);this.array=[...t];return}let s=this._$parentEl;if(e<n){let o=p.getFlowIndexFromNodes(s._$nodes,this),a=s.childNodes.length;for(let h=0;h<n;h++){if(h<e){o+=p.getFlowIndexFromNodes(this.nodesMap.get(h)),this.updateItem(h,t);continue}let g=this.getNewNodes(h,h,t);p.appendNodesWithIndex(g,s,o,a)}p.runDidMount(),this.array=[...t];return}for(let o=0;o<n;o++)this.updateItem(o,t);for(let o=n;o<e;o++){let a=this.nodesMap.get(o);this.removeNodes(a,o)}this.updateArr.splice(n,e-n),this.array=[...t]}updateWithKey(t,e){if(e.length!==new Set(e).size)throw new Error("DLight: Duplicate keys in for loop are not allowed");let n=this.keys;if(this.keys=e,p.arrayEqual(n,this.keys)){for(let d=0;d<t.length;d++)this.updateItem(d,t);this.array=[...t];return}let s=this._$parentEl;if(this.keys.length===0){let d=s._$nodes??[];if(d.length===1&&d[0]===this)this.runAllWillUnmount(),s.innerHTML="",this.runAllDidUnmount();else for(let l=0;l<n.length;l++){let f=n[l];this.removeNodes(this.nodesMap.get(f),f)}this.nodesMap.clear(),this.updateArr=[],this.array=[];return}let o=p.getFlowIndexFromNodes(s._$nodes,this);if(n.length===0){let d=s.childNodes[o];for(let l=0;l<this.keys.length;l++){let f=this.getNewNodes(l,this.keys[l],t);p.appendNodesWithSibling(f,s,d)}p.runDidMount(),this.array=[...t];return}let a=[],h=[];for(let d=0;d<n.length;d++){let l=n[d];if(this.keys.includes(l)){a.push(l),h.push(this.updateArr[d]);continue}this.removeNodes(this.nodesMap.get(l),l)}let g=s.childNodes.length,$=o;for(let d=0;d<this.keys.length;d++){let l=this.keys[d];if(a.includes(l)){$+=p.getFlowIndexFromNodes(this.nodesMap.get(l)),this.updateItem(d,t);continue}h.splice(d,0,null);let f=this.getNewNodes(d,l,t,h);a.splice(d,0,l);let w=p.appendNodesWithIndex(f,s,$,g);$+=w,g+=w}if(p.runDidMount(),p.arrayEqual(this.keys,a)){this.array=[...t],this.updateArr=h;return}$=o;let D=[];for(let d=0;d<this.keys.length;d++){let l=this.keys[d],f=a.indexOf(l),w=D[d];if(w){let b=p.appendNodesWithIndex(w,s,$+p.getFlowIndexFromNodes(w),g);$+=b,g+=b,D[d]=void 0}else if(f===d){$+=p.getFlowIndexFromNodes(this.nodesMap.get(l));continue}else{D[this.keys.indexOf(a[d])]=this.nodesMap.get(this.keys[f]);let b=p.appendNodesWithIndex(this.nodesMap.get(l),s,$,g);$+=b,g+=b}let T=a[d];a[d]=a[f],a[f]=T;let y=h[d];h[d]=h[f],h[f]=y}this.array=[...t],this.updateArr=h}static arrayEqual(t,e){return t.length!==e.length?!1:t.every((n,s)=>n===e[s])}};var x=class extends E{willUnmountFuncs=[];didUnmountFuncs=[];setUnmountFuncs(){this.willUnmountFuncs=r.global.WillUnmountStore.pop(),this.didUnmountFuncs=r.global.DidUnmountStore.pop()}runWillUnmount(){for(let t=0;t<this.willUnmountFuncs.length;t++)this.willUnmountFuncs[t]()}runDidUnmount(){for(let t=this.didUnmountFuncs.length-1;t>=0;t--)this.didUnmountFuncs[t]()}removeNodes(t){this.runWillUnmount(),super.removeNodes(t),this.runDidUnmount()}geneNewNodesInEnv(t){this.initUnmountStore();let e=super.geneNewNodesInEnv(t);return this.setUnmountFuncs(),e}};var m=class extends x{nodesFunc;constructor(t){super(c.Exp),this.nodesFunc=t,this.initUnmountStore(),this._$nodes=m.formatNodes(t()),this.setUnmountFuncs(),m.addWillUnmount(this,this.runWillUnmount.bind(this)),m.addDidUnmount(this,this.runDidUnmount.bind(this))}update(){this.removeNodes(this._$nodes);let t=this.geneNewNodesInEnv(()=>m.formatNodes(this.nodesFunc()));if(t.length===0){this._$nodes=[];return}let e=this._$parentEl,n=m.getFlowIndexFromNodes(e._$nodes,this),s=e.childNodes[n];m.appendNodesWithSibling(t,e,s),m.runDidMount(),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"?r.document.createTextNode(`${e}`):"propViewFunc"in e?e.build():e).flat(1)}};var U=class extends x{condFunc;cond;depNum;constructor(t){super(c.Cond),this.depNum=t}addCondFunc(t){this.cond=-1,this.condFunc=t,this.initUnmountStore(),this._$nodes=this.condFunc(this),this.setUnmountFuncs(),U.addWillUnmount(this,this.runWillUnmount.bind(this)),U.addDidUnmount(this,this.runDidUnmount.bind(this))}updateCond(...t){let e=[this.willUnmountFuncs,this.didUnmountFuncs],n=this.geneNewNodesInEnv(()=>this.condFunc(this));if(this.didntChange)return[this.willUnmountFuncs,this.didUnmountFuncs]=e,this.didntChange=!1,this.updateFunc?.(this.depNum,...t),this._$nodes;let s=[this.willUnmountFuncs,this.didUnmountFuncs];if([this.willUnmountFuncs,this.didUnmountFuncs]=e,this._$nodes&&this._$nodes.length>0&&this.removeNodes(this._$nodes),[this.willUnmountFuncs,this.didUnmountFuncs]=s,n.length===0)return this._$nodes=[],this._$nodes;let o=this._$parentEl,a=U.getFlowIndexFromNodes(o._$nodes,this),h=o.childNodes[a];return U.appendNodesWithSibling(n,o,h),U.runDidMount(),this._$nodes=n,this._$nodes}update(t,...e){t&this.depNum||this.updateFunc?.(t,...e)}};function B(){r.global.WillUnmountStore=[],r.global.DidUnmountStore=[]}function Ot(i,t){let e=i;if(typeof i=="string"){let s=r.document.getElementById(i);if(s)e=s;else throw new Error(`DLight: Element with id ${i} not found`)}B(),e.innerHTML="";let n=new t;n._$init(),F(e,n,0),u.runDidMount()}function Ht(i,t){return i()}function z(i){return i}var Kt=z;export{Kt as $,v as CompNode,U as CondNode,I as EnvNode,S as EnvStoreClass,m as ExpNode,p as ForNode,W as PropView,P as SubViewNode,nt as View,Y as createElement,ht as createTextNode,z as escape,M as forwardHTMLProp,F as insertNode,Ht as manual,Ot as render,j as setDataset,H as setDocument,V as setEvent,O as setGlobal,L as setHTMLAttr,C as setHTMLAttrs,_ as setHTMLProp,A as setHTMLProps,K as setStyle,st as update,lt as updateText};
//# sourceMappingURL=index.js.map
{
"name": "@dlightjs/dlight",
"version": "1.0.0-alpha.61",
"version": "1.0.0-alpha.62",
"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