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
1
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 0.3.4 to 0.3.5

2

dist/index.js

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

function T(d){for(let e of d){if(Array.isArray(e)){T(e);continue}e._$init()}}function g(d,e){for(let t of d){if(Array.isArray(t)){g(t,e);continue}t._$parentNode=e}}function p(d,e){for(let t of d)e(t)&&p(t._$nodes,e)}function f(d,e,t=!0){for(let s of d)[0,1].includes(s._$nodeType)?(e(s._$el,s),t&&f(s._$nodes,e)):f(s._$nodes,e,t)}function A(d){let e=[];return f(d,(t,s)=>{s._$nodeType===0&&e.push(t)},!1),e}var c=(r=>(r[r.HTML=0]="HTML",r[r.Text=1]="Text",r[r.Custom=2]="Custom",r[r.For=3]="For",r[r.If=4]="If",r[r.Env=5]="Env",r[r.Expression=6]="Expression",r))(c||{}),u=class{_$nodeType;__$el;get _$el(){return this.__$el??A(this._$nodes)}set _$el(e){this.__$el=e}_$parentNode;_$nodes=[];_$depObjectIds=[];_$detach(){this._$parentNode=void 0,this._$nodes=[],this._$depObjectIds=[],[1,0].includes(this._$nodeType)||(this.__$el=void 0),this._$beforeInitSubNodes=function(){}}_$beforeInitSubNodes(){}_$addBeforeInitSubNodes(e){let t=this._$beforeInitSubNodes;this._$beforeInitSubNodes=function(){t.call(this),e.call(this)}}_$bindNodes(){g(this._$nodes,this),this._$beforeInitSubNodes(),T(this._$nodes)}constructor(e){this._$nodeType=e}_$init(){}};function w(d,e,t,s,o,n,i){if(t in d){if(!n){d[t]=s;return}if(!(d[`_$$${t}`]!==`_$${e}`&&!(`_$$${t}`in d))){if(d[`_$$${t}`]===`_$${e}`){k(o,d,t,s,n);return}if(i&&`_$$${n[0]}`in o){B(o,d,t,s,n);return}q(o,d,t,s,n)}}}function k(d,e,t,s,o){let n={};e._$depObjectIds.push(n),e[t]=s(),d._$addDeps(o,n,()=>{e[t]=s(),e._$runDeps(t)})}function B(d,e,t,s,o){let n={};e._$depObjectIds.push(n);for(let i of o){let r=()=>d[i]=e[t];e._$addDeps([t],n,r),e[t]=s(),d._$addDeps(o,n,()=>{e._$deleteDep(t,n),e[t]=s(),e._$addDeps([t],n,r)})}}function q(d,e,t,s,o){let n={};e._$depObjectIds.push(n),e[`_$${t}`]=s(),d._$addDeps(o,n,()=>{e[`_$${t}`]=s(),e._$runDeps(t)})}function v(d,e){p(e,t=>{switch(t._$nodeType){case 1:case 0:d._$el.appendChild(t._$el);break;default:v(d,t._$nodes);break}return!1})}function y(d){J(d),f(d,(e,t)=>{!document.body.contains(e)||(t._$nodeType===0&&t.willDisappear(e,t),e.remove(),t._$nodeType===0&&t.didDisappear(e,t))}),Q(d)}function N(d){for(let e of d)e._$detach()}function $(d,e){p(d,t=>{for(let s of t._$depObjectIds)e._$deleteDeps(s);return t._$nodeType===2&&$(t._$children,e),!0})}function L(d,e,t,s){let o=s??t.childNodes.length;return z(d),f(d,(n,i)=>{let r=document.body.contains(n);[0].includes(i._$nodeType)&&!r&&i.willAppear(n,i),e===o?t.appendChild(n):t.insertBefore(n,t.childNodes[e]),[0].includes(i._$nodeType)&&!r&&i.didAppear(n,i),e++,o++},!1),G(d),[e,o]}function x(d,e){return j(d._$nodes,e)}function C(d){return j(d,void 0)}function j(d,e){let t=0,s=!1;return p(d,o=>s?!1:o===e?(s=!0,!1):[1,0].includes(o._$nodeType)?(t++,!1):!0),t}function M(d,e){p(d,t=>([2].includes(t._$nodeType)&&t[e](t),!0))}function z(d){M(d,"willMount")}function G(d){M(d,"didMount")}function J(d){M(d,"willUnmount")}function Q(d){M(d,"didUnmount")}var I=class extends u{_$deps={};_$envNodes;_$derivedPairs;_$tag="";constructor(){super(2)}_$addAfterset(e){let t=this.Afterset.bind(this);this.Afterset=function(){t(),e()}.bind(this)}_$runDeps(e){if(this._$deps[e]===void 0){console.warn(`${e} is not a dependency in ${this.constructor.name}`);return}for(let t of this._$deps[e].values())t.call(this)}_$children=[];_$addChildren(e){this._$children=e}_$resetChildren(){for(let e of this._$children)e._$nodes=[]}_$initDecorators(){if(this._$derivedPairs)for(let[e,t]of Object.entries(this._$derivedPairs)){let s=this[e];if(typeof s!="function")return;this[e]=this[e]();let o=this[e];this._$addDeps(t,{},()=>{let n=s();n!==o&&(this[e]=n,o=n,this._$runDeps(e))})}}_$addDeps(e,t,s){for(let o of e)this._$deps[o].set(t,s)}_$deleteDep(e,t){this._$deps[e].delete(t)}_$deleteDeps(e){for(let t in this._$deps)this._$deleteDep(t,e)}AfterConstruct(){}Preset(){}Afterset(){}_$init(){this.AfterConstruct(),this._$initDecorators(),this.Preset(),this._$nodes=(this.Body.bind(this)??(()=>[]))(),this.Afterset(),this._$bindNodes()}_$addProp(e,t,s,o,n){w(this,"prop",e,t,s,o,n)}willMount(e,t){}didMount(e,t){}willUnmount(e,t){}didUnmount(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(o,n){e.call(this,this._$el,this),s.call(this,this._$el,this)}}render(e){let t=new E("div");t._$addNodes([this]),t._$addProp("id",typeof e=="string"?e:e.id),t._$init(),this.willMount(this._$el,this),p(this._$nodes,s=>{switch(s._$nodeType){case 0:s.willAppear(s._$el,s);break;case 2:s.willMount(s._$el,s);break}return!0}),typeof e=="string"&&(e=document.getElementById(e)),e.replaceWith(t._$el),p(this._$nodes,s=>{switch(s._$nodeType){case 0:s.didAppear(s._$el,s);break;case 2:s.didMount(s._$el,s);break}return!0}),this.didMount(this._$el,this)}_$detach(){super._$detach(),N(this._$children)}};var E=class extends u{_$envNodes=[];constructor(e){super(0),this._$el=document.createElement(e)}_$init(){this._$bindNodes(),v(this,this._$nodes)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,o){let n;if(e[0]==="_"?n=a=>this._$el.style[e.slice(1)]=a:e==="className"?n=a=>this._$el.className=`${this._$el.className} ${a}`.trim():n=a=>this._$el[e]=a,!o){n(t);return}let i=t();n(i);let r=()=>{let a=t();i!==a&&(n(a),i=a)},h={};this._$depObjectIds.push(h),s._$addDeps(o,h,r)}willAppear(e,t){}didAppear(e,t){}willDisappear(e,t){}didDisappear(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(o,n,...i){return s.call(this,o,n),e.call(this,o,n)}}};var D=class extends u{afterUpdateNewNodes(e){}addAfterUpdateNewNodesFunc(e){let t=this.afterUpdateNewNodes;this.afterUpdateNewNodes=function(s){e.call(this,s),t.call(this,s)}}onUpdateNodes(e,t){}addOnUpdateNodesFunc(e){let t=this.onUpdateNodes;this.onUpdateNodes=function(s,o){e.call(this,s,o),t.call(this,s,o)}}_$bindNewNodes(e){g(e,this),this._$beforeInitSubNodes(),T(e),this.afterUpdateNewNodes(e)}_$detach(){super._$detach()}};var O=class extends D{keys=[];array=[];_$nodess=[];nodeFunc;keyFunc;arrayFunc;dlScope;listenDeps;nodesFunc;constructor(){super(3)}duplicatedOrNoKey=!1;_$getItem(e,t){let s=this.duplicatedOrNoKey?t:this.keys.indexOf(e);return this.array[s]}_$addNodeFunc(e){this.nodeFunc=e}_$addKeyFunc(e){this.keyFunc=e}_$addArrayFunc(e,t,s){this.dlScope=e,this.arrayFunc=t,this.listenDeps=s}_$addNodess(e){this.nodesFunc=e}setArray(){this.array=[...this.arrayFunc()]}setKeys(){if(!this.keyFunc){this.duplicatedOrNoKey=!0;return}let e=[...this.keyFunc()];if(e.length===[...new Set(e)].length){this.keys=e;return}this.keys=[...Array(this.array.length).keys()],console.warn("\u91CD\u590Dkey\u4E86"),this.duplicatedOrNoKey=!0}_$init(){if(!this.listenDeps){this._$nodess=this.nodesFunc(),this._$nodes=this._$nodess.flat(1),this._$bindNodes();return}let e=this._$parentNode;for(;e&&e._$nodeType!==0;)e=e._$parentNode;if(!e)return;let t=this.keyFunc?()=>this.updateWithKey(e):()=>this.updateWithOutKey(e),s={};if(this._$depObjectIds.push(s),this.dlScope._$addDeps(this.listenDeps,s,t),this.setArray(),this.setKeys(),this.duplicatedOrNoKey)for(let o of this.array.keys())this._$nodess.push(this.nodeFunc(null,o,this));else for(let[o,n]of this.keys.entries())this._$nodess.push(this.nodeFunc(n,o,this));this._$nodes=this._$nodess.flat(1),this._$bindNodes()}getNewNodes(e,t){let s=this.nodeFunc(e,t,this);return this._$bindNewNodes(s),s}updateWithOutKey(e){let t=e._$el,s=this.array.length;this.setArray();let o=this.array.length;if(s!==o){if(s<o){let n=x(e,this),i=t.childNodes.length;for(let r=0;r<o;r++){if(r<s){n+=C(this._$nodess[r]);continue}let h=this.getNewNodes(null,r);[n,i]=L(h,n,t,i),this._$nodess.push(h)}this._$nodes=this._$nodess.flat(1);return}for(let n=o;n<s;n++)$(this._$nodess[n],this.dlScope),y(this._$nodess[n]),N(this._$nodess[n]);this._$nodess=this._$nodess.slice(0,o),this._$nodes=this._$nodess.flat(1)}}updateWithKey(e){let t=e._$el,s=x(e,this),o=this.keys,n=[...this.array],i=[...this._$nodess],r=[...this._$nodes];this.setArray(),this.setKeys(),this.duplicatedOrNoKey&&(o=[...Array(n.length).keys()]);let h=[],a=[],W=[];for(let[l,_]of o.entries()){if(this.keys.includes(_)){h.push(_),a.push(i[l]);continue}$(i[l],this.dlScope),y(i[l]),N(i[l]),W.push(l)}o=h;let b=s,H=t.childNodes.length;for(let[l,_]of this.keys.entries()){if(o.includes(_)){b+=C(a[o.indexOf(_)]);continue}let m=this.getNewNodes(_,l);[b,H]=L(m,b,t,H),a.splice(l,0,m),o.splice(l,0,_)}b=s;for(let[l,_]of this.keys.entries()){let m=o.indexOf(_);if(m===l){b+=C(a[l]);continue}let F=a[m],V=o[m];[b,H]=L(F,b,t,H),a.splice(m,1),o.splice(m,1),a.splice(l+1,0,F),o.splice(l+1,0,V)}this._$nodess=a,this._$nodes=this._$nodess.flat(1),this.onUpdateNodes(r,this._$nodes)}_$listen(e,t,s,o){let n={};e._$depObjectIds.push(n),e._$addDeps(s,n,()=>{let i=t();if(i===void 0){e._$deleteDeps(n);return}o(i)})}_$detach(){super._$detach(),this._$nodess=[]}};var U=class extends D{conditionPairs=[];condition;listenDeps=[];dlScope;_$envNodes=[];constructor(){super(4)}_$addCond(e,t,s,o){this.conditionPairs.push({condition:e,node:t}),o&&(this.dlScope||(this.dlScope=s),this.listenDeps.push(...o))}_$init(){let e=[];for(let s of this.conditionPairs)if(s.condition()){this.condition=s.condition.toString(),e=s.node();break}this._$nodes=e;let t=this._$parentNode;for(;t&&t._$nodeType!==0;)t=t._$parentNode;if(t){let s={};this._$depObjectIds.push(s),this.dlScope?._$addDeps(this.listenDeps,s,()=>this.update(t))}this._$bindNodes()}update(e){let t=this._$nodes,s=this.condition;this._$nodes=[];for(let i of this.conditionPairs)if(i.condition()){this.condition!==i.condition.toString()?($(t,this.dlScope),y(t),this.condition=i.condition.toString(),this._$nodes=i.node(),this._$bindNewNodes(this._$nodes)):this._$nodes=t;break}if(t.length!==0&&this._$nodes.length===0&&(this.condition="[none]",$(t,this.dlScope),y(t)),s===this.condition)return;let o=x(e,this),n=e._$el;L(this._$nodes,o,n,n.childNodes.length),N(t),this.onUpdateNodes(t,this._$nodes)}};var P=class extends u{constructor(e,t,s){if(super(1),!s){this._$el=document.createTextNode(e);return}e=e;let o=e();this._$el=document.createTextNode(o);let n=()=>{let r=e();o!==r&&(this._$el.nodeValue=r,o=r)},i={};this._$depObjectIds.push(i),t._$addDeps(s,i,n)}};var S=class extends u{addPropFuncs=[];constructor(){super(5)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,o){this.addPropFuncs.push(n=>w(n,"env",e,t,s,o))}addProps(e){for(let t of this.addPropFuncs)t(e)}addPropsToNodes(e){p(e._$nodes,t=>(t._$addBeforeInitSubNodes(()=>{this.addPropsToNodes(t)}),t._$nodeType===2&&this.addProps(t),!1))}_$init(){this.addPropsToNodes(this),this._$bindNodes()}};var K=class extends D{nodeOrFunc;listenDeps;dlScope;propFuncs=[];constructor(e,t,s){if(super(6),!s){this._$nodes=this.formatNodes(e);return}this.nodeOrFunc=e,this.listenDeps=s,this.dlScope=t,this._$nodes=this.formatNodes(this.nodeOrFunc())}_$onUpdateNodes(e){p(this._$nodes,t=>([4,3,6].includes(t._$nodeType)&&t.addOnUpdateNodesFunc(e),!0))}_$addProp(e,t,s,o){let n=i=>{if(["willAppear","didAppear","willDisappear","didDisappear"].includes(e)){i._$addLifeCycle(t,e);return}e[0]==="_"&&(i._$el.style[e.slice(1)]??"").trim()!==""||!["className"].includes(e)&&e[0]!=="_"&&i._$el[e]!==void 0||i._$addProp(e,t,s,o)};this.propFuncs.push(()=>{for(let i of this._$nodes)switch(i._$nodeType){case 0:n(i);break;case 3:case 4:case 6:i.addAfterUpdateNewNodesFunc(r=>{f(r,(h,a)=>{a._$nodeType===0&&n(a)},!1)});default:f(i._$nodes,(r,h)=>{h._$nodeType===0&&n(h)},!1)}})}formatNodes(e){return Array.isArray(e)||(e=[e]),e=e.flat(1),e=e.filter(t=>t!=null&&typeof t!="boolean").map(t=>t._$nodeType!==void 0?t:new P(t)),e}_$init(){if(this.listenDeps===void 0){this._$bindNodes();for(let s of this.propFuncs)s();return}let e=this._$parentNode;for(;e&&e._$nodeType!==0;)e=e._$parentNode;if(!e)return;let t={};this._$depObjectIds.push(t),this.dlScope._$addDeps(this.listenDeps,t,()=>this.update(e)),this._$bindNodes();for(let s of this.propFuncs){s();let o={};this._$depObjectIds.push(o),this.dlScope._$addDeps(this.listenDeps,o,s)}}update(e){let t=this._$nodes;$(this._$nodes,this.dlScope),y(this._$nodes),this._$nodes=this.formatNodes(this.nodeOrFunc()),this._$bindNewNodes(this._$nodes);let s=e._$el,o=x(e,this);L(this._$nodes,o,s,s.childNodes.length),N(t),this.onUpdateNodes(t,this._$nodes)}};var Ye=I;function Ze(d,e){new e().render(d)}export{I as CustomNode,u as DLNode,c as DLNodeType,S as EnvNode,K as ExpressionNode,O as ForNode,E as HtmlNode,U as IfNode,P as TextNode,Ye as View,g as bindParentNode,T as initNodes,f as loopEls,p as loopNodes,Ze as render,A as toEls};
function T(d){for(let e of d){if(Array.isArray(e)){T(e);continue}e._$init()}}function g(d,e){for(let t of d){if(Array.isArray(t)){g(t,e);continue}t._$parentNode=e}}function p(d,e){for(let t of d)e(t)&&p(t._$nodes,e)}function f(d,e,t=!0){for(let s of d)[0,1].includes(s._$nodeType)?(e(s._$el,s),t&&f(s._$nodes,e)):f(s._$nodes,e,t)}function j(d){let e=[];return f(d,(t,s)=>{s._$nodeType===0&&e.push(t)},!1),e}var c=(r=>(r[r.HTML=0]="HTML",r[r.Text=1]="Text",r[r.Custom=2]="Custom",r[r.For=3]="For",r[r.If=4]="If",r[r.Env=5]="Env",r[r.Expression=6]="Expression",r))(c||{}),u=class{_$nodeType;__$el;get _$el(){return this.__$el??j(this._$nodes)}set _$el(e){this.__$el=e}_$parentNode;_$nodes=[];_$depObjectIds=[];_$detach(){this._$parentNode=void 0,this._$nodes=[],this._$depObjectIds=[],[1,0].includes(this._$nodeType)||(this.__$el=void 0),this._$beforeInitSubNodes=function(){}}_$beforeInitSubNodes(){}_$addBeforeInitSubNodes(e){let t=this._$beforeInitSubNodes;this._$beforeInitSubNodes=function(){t.call(this),e.call(this)}}_$bindNodes(){g(this._$nodes,this),this._$beforeInitSubNodes(),T(this._$nodes)}constructor(e){this._$nodeType=e}_$init(){}};function w(d,e,t,s,o,n,i){if(t in d){if(!n){d[t]=s;return}if(!(d[`_$$${t}`]!==`_$${e}`&&!(`_$$${t}`in d))){if(d[`_$$${t}`]===`_$${e}`){k(o,d,t,s,n);return}if(i&&`_$$${n[0]}`in o){B(o,d,t,s,n);return}q(o,d,t,s,n)}}}function k(d,e,t,s,o){let n={};e._$depObjectIds.push(n),e[t]=s(),d._$addDeps(o,n,()=>{e[t]=s(),e._$runDeps(t)})}function B(d,e,t,s,o){let n={};e._$depObjectIds.push(n);for(let i of o){let r=()=>d[i]=e[t];e._$addDeps([t],n,r),e[t]=s(),d._$addDeps(o,n,()=>{e._$deleteDep(t,n),e[t]=s(),e._$addDeps([t],n,r)})}}function q(d,e,t,s,o){let n={};e._$depObjectIds.push(n),e[`_$${t}`]=s(),d._$addDeps(o,n,()=>{e[`_$${t}`]=s(),e._$runDeps(t)})}function F(d,e){p(e,t=>{switch(t._$nodeType){case 1:case 0:d._$el.appendChild(t._$el);break;default:F(d,t._$nodes);break}return!1})}function y(d){J(d),f(d,(e,t)=>{!document.body.contains(e)||(t._$nodeType===0&&t.willDisappear(e,t),e.remove(),t._$nodeType===0&&t.didDisappear(e,t))}),Q(d)}function N(d){for(let e of d)e._$detach()}function $(d,e){p(d,t=>{for(let s of t._$depObjectIds)e._$deleteDeps(s);return t._$nodeType===2&&$(t._$children,e),!0})}function L(d,e,t,s){let o=s??t.childNodes.length;return z(d),f(d,(n,i)=>{let r=document.body.contains(n);[0].includes(i._$nodeType)&&!r&&i.willAppear(n,i),e===o?t.appendChild(n):t.insertBefore(n,t.childNodes[e]),[0].includes(i._$nodeType)&&!r&&i.didAppear(n,i),e++,o++},!1),G(d),[e,o]}function x(d,e){return O(d._$nodes,e)}function C(d){return O(d,void 0)}function O(d,e){let t=0,s=!1;return p(d,o=>s?!1:o===e?(s=!0,!1):[1,0].includes(o._$nodeType)?(t++,!1):!0),t}function M(d,e){p(d,t=>([2].includes(t._$nodeType)&&t[e](t),!0))}function z(d){M(d,"willMount")}function G(d){M(d,"didMount")}function J(d){M(d,"willUnmount")}function Q(d){M(d,"didUnmount")}var I=class extends u{_$deps={};_$envNodes;_$derivedPairs;_$tag="";constructor(){super(2)}_$addAfterset(e){let t=this.Afterset.bind(this);this.Afterset=function(){t(),e()}.bind(this)}_$runDeps(e){if(this._$deps[e]===void 0){console.warn(`${e} is not a dependency in ${this.constructor.name}`);return}for(let t of this._$deps[e].values())t.call(this)}_$children=[];_$addChildren(e){this._$children=e}_$resetChildren(){for(let e of this._$children)e._$nodes=[]}_$initDecorators(){if(this._$derivedPairs)for(let[e,t]of Object.entries(this._$derivedPairs)){let s=this[e];if(typeof s!="function")return;this[e]=this[e]();let o=this[e];this._$addDeps(t,{},()=>{let n=s();n!==o&&(this[e]=n,o=n,this._$runDeps(e))})}}_$addDeps(e,t,s){for(let o of e)this._$deps[o].set(t,s)}_$deleteDep(e,t){this._$deps[e].delete(t)}_$deleteDeps(e){for(let t in this._$deps)this._$deleteDep(t,e)}AfterConstruct(){}Preset(){}Afterset(){}_$init(){this.AfterConstruct(),this._$initDecorators(),this.Preset(),this._$nodes=(this.Body.bind(this)??(()=>[]))(),this.Afterset(),this._$bindNodes()}_$addProp(e,t,s,o,n){w(this,"prop",e,t,s,o,n)}willMount(e,t){}didMount(e,t){}willUnmount(e,t){}didUnmount(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(o,n){e.call(this,this._$el,this),s.call(this,this._$el,this)}}render(e){let t=new E("div");t._$addNodes([this]),t._$addProp("id",typeof e=="string"?e:e.id),t._$init(),this.willMount(this._$el,this),p(this._$nodes,s=>{switch(s._$nodeType){case 0:s.willAppear(s._$el,s);break;case 2:s.willMount(s._$el,s);break}return!0}),typeof e=="string"&&(e=document.getElementById(e)),e.replaceWith(t._$el),p(this._$nodes,s=>{switch(s._$nodeType){case 0:s.didAppear(s._$el,s);break;case 2:s.didMount(s._$el,s);break}return!0}),this.didMount(this._$el,this)}_$detach(){super._$detach(),N(this._$children)}};var E=class extends u{_$envNodes=[];constructor(e){super(0),this._$el=document.createElement(e)}_$init(){this._$bindNodes(),F(this,this._$nodes)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,o){let n;if(e[0]==="_")n=a=>this._$el.style[e.slice(1)]=a;else if(e==="className"){let a=this._$el.className;n=v=>this._$el.className=`${a} ${v}`.trim()}else n=a=>this._$el[e]=a;if(!o){n(t);return}let i=t();n(i);let r=()=>{let a=t();i!==a&&(n(a),i=a)},h={};this._$depObjectIds.push(h),s._$addDeps(o,h,r)}willAppear(e,t){}didAppear(e,t){}willDisappear(e,t){}didDisappear(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(o,n,...i){return s.call(this,o,n),e.call(this,o,n)}}};var D=class extends u{afterUpdateNewNodes(e){}addAfterUpdateNewNodesFunc(e){let t=this.afterUpdateNewNodes;this.afterUpdateNewNodes=function(s){e.call(this,s),t.call(this,s)}}onUpdateNodes(e,t){}addOnUpdateNodesFunc(e){let t=this.onUpdateNodes;this.onUpdateNodes=function(s,o){e.call(this,s,o),t.call(this,s,o)}}_$bindNewNodes(e){g(e,this),this._$beforeInitSubNodes(),T(e),this.afterUpdateNewNodes(e)}_$detach(){super._$detach()}};var U=class extends D{keys=[];array=[];_$nodess=[];nodeFunc;keyFunc;arrayFunc;dlScope;listenDeps;nodesFunc;constructor(){super(3)}duplicatedOrNoKey=!1;_$getItem(e,t){let s=this.duplicatedOrNoKey?t:this.keys.indexOf(e);return this.array[s]}_$addNodeFunc(e){this.nodeFunc=e}_$addKeyFunc(e){this.keyFunc=e}_$addArrayFunc(e,t,s){this.dlScope=e,this.arrayFunc=t,this.listenDeps=s}_$addNodess(e){this.nodesFunc=e}setArray(){this.array=[...this.arrayFunc()]}setKeys(){if(!this.keyFunc){this.duplicatedOrNoKey=!0;return}let e=[...this.keyFunc()];if(e.length===[...new Set(e)].length){this.keys=e;return}this.keys=[...Array(this.array.length).keys()],console.warn("\u91CD\u590Dkey\u4E86"),this.duplicatedOrNoKey=!0}_$init(){if(!this.listenDeps){this._$nodess=this.nodesFunc(),this._$nodes=this._$nodess.flat(1),this._$bindNodes();return}let e=this._$parentNode;for(;e&&e._$nodeType!==0;)e=e._$parentNode;if(!e)return;let t=this.keyFunc?()=>this.updateWithKey(e):()=>this.updateWithOutKey(e),s={};if(this._$depObjectIds.push(s),this.dlScope._$addDeps(this.listenDeps,s,t),this.setArray(),this.setKeys(),this.duplicatedOrNoKey)for(let o of this.array.keys())this._$nodess.push(this.nodeFunc(null,o,this));else for(let[o,n]of this.keys.entries())this._$nodess.push(this.nodeFunc(n,o,this));this._$nodes=this._$nodess.flat(1),this._$bindNodes()}getNewNodes(e,t){let s=this.nodeFunc(e,t,this);return this._$bindNewNodes(s),s}updateWithOutKey(e){let t=e._$el,s=this.array.length;this.setArray();let o=this.array.length;if(s!==o){if(s<o){let n=x(e,this),i=t.childNodes.length;for(let r=0;r<o;r++){if(r<s){n+=C(this._$nodess[r]);continue}let h=this.getNewNodes(null,r);[n,i]=L(h,n,t,i),this._$nodess.push(h)}this._$nodes=this._$nodess.flat(1);return}for(let n=o;n<s;n++)$(this._$nodess[n],this.dlScope),y(this._$nodess[n]),N(this._$nodess[n]);this._$nodess=this._$nodess.slice(0,o),this._$nodes=this._$nodess.flat(1)}}updateWithKey(e){let t=e._$el,s=x(e,this),o=this.keys,n=[...this.array],i=[...this._$nodess],r=[...this._$nodes];this.setArray(),this.setKeys(),this.duplicatedOrNoKey&&(o=[...Array(n.length).keys()]);let h=[],a=[],v=[];for(let[l,_]of o.entries()){if(this.keys.includes(_)){h.push(_),a.push(i[l]);continue}$(i[l],this.dlScope),y(i[l]),N(i[l]),v.push(l)}o=h;let b=s,H=t.childNodes.length;for(let[l,_]of this.keys.entries()){if(o.includes(_)){b+=C(a[o.indexOf(_)]);continue}let m=this.getNewNodes(_,l);[b,H]=L(m,b,t,H),a.splice(l,0,m),o.splice(l,0,_)}b=s;for(let[l,_]of this.keys.entries()){let m=o.indexOf(_);if(m===l){b+=C(a[l]);continue}let A=a[m],V=o[m];[b,H]=L(A,b,t,H),a.splice(m,1),o.splice(m,1),a.splice(l+1,0,A),o.splice(l+1,0,V)}this._$nodess=a,this._$nodes=this._$nodess.flat(1),this.onUpdateNodes(r,this._$nodes)}_$listen(e,t,s,o){let n={};e._$depObjectIds.push(n),e._$addDeps(s,n,()=>{let i=t();if(i===void 0){e._$deleteDeps(n);return}o(i)})}_$detach(){super._$detach(),this._$nodess=[]}};var S=class extends D{conditionPairs=[];condition;listenDeps=[];dlScope;_$envNodes=[];constructor(){super(4)}_$addCond(e,t,s,o){this.conditionPairs.push({condition:e,node:t}),o&&(this.dlScope||(this.dlScope=s),this.listenDeps.push(...o))}_$init(){let e=[];for(let s of this.conditionPairs)if(s.condition()){this.condition=s.condition.toString(),e=s.node();break}this._$nodes=e;let t=this._$parentNode;for(;t&&t._$nodeType!==0;)t=t._$parentNode;if(t){let s={};this._$depObjectIds.push(s),this.dlScope?._$addDeps(this.listenDeps,s,()=>this.update(t))}this._$bindNodes()}update(e){let t=this._$nodes,s=this.condition;this._$nodes=[];for(let i of this.conditionPairs)if(i.condition()){this.condition!==i.condition.toString()?($(t,this.dlScope),y(t),this.condition=i.condition.toString(),this._$nodes=i.node(),this._$bindNewNodes(this._$nodes)):this._$nodes=t;break}if(t.length!==0&&this._$nodes.length===0&&(this.condition="[none]",$(t,this.dlScope),y(t)),s===this.condition)return;let o=x(e,this),n=e._$el;L(this._$nodes,o,n,n.childNodes.length),N(t),this.onUpdateNodes(t,this._$nodes)}};var P=class extends u{constructor(e,t,s){if(super(1),!s){this._$el=document.createTextNode(e);return}e=e;let o=e();this._$el=document.createTextNode(o);let n=()=>{let r=e();o!==r&&(this._$el.nodeValue=r,o=r)},i={};this._$depObjectIds.push(i),t._$addDeps(s,i,n)}};var K=class extends u{addPropFuncs=[];constructor(){super(5)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,o){this.addPropFuncs.push(n=>w(n,"env",e,t,s,o))}addProps(e){for(let t of this.addPropFuncs)t(e)}addPropsToNodes(e){p(e._$nodes,t=>(t._$addBeforeInitSubNodes(()=>{this.addPropsToNodes(t)}),t._$nodeType===2&&this.addProps(t),!1))}_$init(){this.addPropsToNodes(this),this._$bindNodes()}};var W=class extends D{nodeOrFunc;listenDeps;dlScope;propFuncs=[];constructor(e,t,s){if(super(6),!s){this._$nodes=this.formatNodes(e);return}this.nodeOrFunc=e,this.listenDeps=s,this.dlScope=t,this._$nodes=this.formatNodes(this.nodeOrFunc())}_$onUpdateNodes(e){p(this._$nodes,t=>([4,3,6].includes(t._$nodeType)&&t.addOnUpdateNodesFunc(e),!0))}_$addProp(e,t,s,o){let n=i=>{if(["willAppear","didAppear","willDisappear","didDisappear"].includes(e)){i._$addLifeCycle(t,e);return}e[0]==="_"&&(i._$el.style[e.slice(1)]??"").trim()!==""||!["className"].includes(e)&&e[0]!=="_"&&i._$el[e]!==void 0||i._$addProp(e,t,s,o)};this.propFuncs.push(()=>{for(let i of this._$nodes)switch(i._$nodeType){case 0:n(i);break;case 3:case 4:case 6:i.addAfterUpdateNewNodesFunc(r=>{f(r,(h,a)=>{a._$nodeType===0&&n(a)},!1)});default:f(i._$nodes,(r,h)=>{h._$nodeType===0&&n(h)},!1)}})}formatNodes(e){return Array.isArray(e)||(e=[e]),e=e.flat(1),e=e.filter(t=>t!=null&&typeof t!="boolean").map(t=>t._$nodeType!==void 0?t:new P(t)),e}_$init(){if(this.listenDeps===void 0){this._$bindNodes();for(let s of this.propFuncs)s();return}let e=this._$parentNode;for(;e&&e._$nodeType!==0;)e=e._$parentNode;if(!e)return;let t={};this._$depObjectIds.push(t),this.dlScope._$addDeps(this.listenDeps,t,()=>this.update(e)),this._$bindNodes();for(let s of this.propFuncs){s();let o={};this._$depObjectIds.push(o),this.dlScope._$addDeps(this.listenDeps,o,s)}}update(e){let t=this._$nodes;$(this._$nodes,this.dlScope),y(this._$nodes),this._$nodes=this.formatNodes(this.nodeOrFunc()),this._$bindNewNodes(this._$nodes);let s=e._$el,o=x(e,this);L(this._$nodes,o,s,s.childNodes.length),N(t),this.onUpdateNodes(t,this._$nodes)}};var Ye=I;function Ze(d,e){new e().render(d)}export{I as CustomNode,u as DLNode,c as DLNodeType,K as EnvNode,W as ExpressionNode,U as ForNode,E as HtmlNode,S as IfNode,P as TextNode,Ye as View,g as bindParentNode,T as initNodes,f as loopEls,p as loopNodes,Ze as render,j as toEls};
{
"name": "@dlightjs/dlight",
"version": "0.3.4",
"version": "0.3.5",
"files": [

@@ -5,0 +5,0 @@ "dist"

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