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.0.10 to 0.0.11

5

dist/index.d.ts

@@ -136,3 +136,3 @@ declare enum DLNodeType {

Body: any;
constructor(tag?: string);
constructor();
_$addAfterset(func: () => any): void;

@@ -274,4 +274,5 @@ _$runDeps(depName: string): void;

declare const View: typeof CustomNode;
declare const required: any;
declare function render(id: string, dl: CustomNode): void;
export { CustomNode, DLNode, DLNodeType, EnvNode, ExpressionNode, ForNode, HTMLLifeCycleProp, HtmlNode, IfNode, TextNode, View, bindParentNode, initNodes, loopEls, loopNodes, render, toEls };
export { CustomNode, DLNode, DLNodeType, EnvNode, ExpressionNode, ForNode, HTMLLifeCycleProp, HtmlNode, IfNode, TextNode, View, bindParentNode, initNodes, loopEls, loopNodes, render, required, toEls };

2

dist/index.js

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

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

@@ -5,0 +5,0 @@ "type": "module",

@@ -8,4 +8,4 @@ import { HtmlNode } from "./Nodes"

export const View = CustomNode
export const required = undefined as any
export function render(id: string, dl: CustomNode) {

@@ -12,0 +12,0 @@ const appNode = new HtmlNode("div")

@@ -70,9 +70,8 @@ import { EnvNode } from "./EnvNode"

_$children?: DLNode[]
_$tag: string
_$tag: string = ""
Body: any
constructor(tag?: string) {
constructor() {
super(DLNodeType.Custom)
this._$tag = tag ?? this.constructor.name
}

@@ -79,0 +78,0 @@

@@ -56,4 +56,14 @@ import { loopEls, loopNodes } from '../../utils/nodes';

this.propFuncs.push(() => {
loopNodes(this._$nodes, node =>{
for (let node of this._$nodes) {
switch (node._$nodeType) {
case DLNodeType.HTML:
addHtmlNodeProp(node as HtmlNode)
if (deepLoopEl) {
// ---- 如果不是deepLoopEl,只要add自己就行了
loopEls(node._$nodes, (_: HTMLElement, node: HtmlNode) => {
if (node._$nodeType !== DLNodeType.HTML) return
addHtmlNodeProp(node)
}, true)
}
break
// ---- 这一些都是要bindNodes的,在bindNodes时候给里面的_$nodes进行遍历加prop

@@ -70,9 +80,9 @@ // 典型的如for循环,newNodes的时候也会bindNodes,也要加这些prop

})
break
case DLNodeType.HTML:
addHtmlNodeProp(node as HtmlNode)
break
default:
loopEls(node._$nodes, (_: HTMLElement, node: HtmlNode) => {
if (node._$nodeType !== DLNodeType.HTML) return
addHtmlNodeProp(node)
}, deepLoopEl)
}
return deepLoopEl
})
}
})

@@ -79,0 +89,0 @@ }

@@ -43,3 +43,3 @@ import { CustomNode } from "../CustomNode";

this._$depObjectIds.push(objectId)
this.dlScope!._$addDeps(this.listenDeps, objectId, () => this.update(parentNode as HtmlNode))
this.dlScope?._$addDeps(this.listenDeps, objectId, () => this.update(parentNode as HtmlNode))
}

@@ -46,0 +46,0 @@

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