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 0.4.13 to 0.5.0

46

dist/index.d.ts

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

type ObjectId = Record<string, unknown>;
declare enum DLNodeType {

@@ -10,4 +12,3 @@ HTML = 0,

}
declare class DLNode {
/**
/**
* @member _$id

@@ -44,2 +45,3 @@ * - 每一个Node都有id

*/
declare class DLNode {
_$nodeType: DLNodeType;

@@ -51,3 +53,3 @@ private __$el;

_$nodes: DLNode[];
_$depObjectIds: Object[];
_$depObjectIds: ObjectId[];
_$detach(): void;

@@ -62,3 +64,3 @@ _$beforeInitSubNodes(_nodes: DLNode[]): void;

declare class EnvNode extends DLNode {
addPropFuncs: ((node: CustomNode) => any)[];
addPropFuncs: Array<(node: CustomNode) => any>;
constructor();

@@ -133,9 +135,5 @@ _$addNodes(nodes: DLNode[]): void;

declare class CustomNode extends DLNode {
_$deps: {
[key: string]: Map<Object, () => any>;
};
_$deps: Record<string, Map<ObjectId, () => any>>;
_$envNodes?: EnvNode[];
_$derivedPairs?: {
[key: string]: string[];
};
_$derivedPairs?: Record<string, string[]>;
_$tag: string;

@@ -149,5 +147,5 @@ constructor();

_$initDecorators(): void;
_$addDeps(deps: string[], objectId: Object, func: (newValue?: any) => any): void;
_$deleteDep(depName: string, objectId: Object): void;
_$deleteDeps(objectId: Object): void;
_$addDeps(deps: string[], objectId: ObjectId, func: (newValue?: any) => any): void;
_$deleteDep(depName: string, objectId: ObjectId): void;
_$deleteDeps(objectId: ObjectId): void;
AfterConstruct(): void;

@@ -205,4 +203,4 @@ Preset(): void;

/**
* @methodGroup - 只有有deps的时候才需要用各种func
*/
* @methodGroup - 只有有deps的时候才需要用各种func
*/
_$addNodeFunc(nodeFunc: (key: any, idx: number, forNode: any) => DLNode[]): void;

@@ -212,4 +210,4 @@ _$addKeyFunc(keyFunc: (() => any[])): void;

/**
* @methodGroup - 无deps的时候直接加nodes
*/
* @methodGroup - 无deps的时候直接加nodes
*/
_$addNodess(nodesFunc: () => DLNode[][]): void;

@@ -221,9 +219,9 @@ setArray(): void;

/**
* 没有key这样是优化过的,非常快
*/
* 没有key这样是优化过的,非常快
*/
updateWithOutKey(parentNode: HtmlNode): void;
/**
* 有 key,三步走
*
*/
* 有 key,三步走
*
*/
updateWithKey(parentNode: HtmlNode): void;

@@ -259,3 +257,3 @@ _$listen(dlScope: CustomNode, itemFunc: () => any, listenDeps: string[], updateFunc: any): void;

dlScope?: CustomNode;
propFuncs: (() => any)[];
propFuncs: Array<() => any>;
constructor(nodeOrFunc: ExpressionNodeType | (() => ExpressionNodeType), dlScope?: CustomNode, listenDeps?: string[]);

@@ -276,4 +274,4 @@ _$onUpdateNodes(func: () => any): void;

declare const View: any;
declare function render(idOrEl: string | HTMLElement, dl: any): void;
declare function render(idOrEl: string | HTMLElement, DL: any): void;
export { CustomNode, DLNode, DLNodeType, EnvNode, ExpressionNode, ForNode, HtmlNode, IfNode, TextNode, View, bindParentNode, initNodes, loopEls, loopNodes, render, toEls };

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

function w(o){for(let e of o){if(Array.isArray(e)){w(e);continue}e._$init()}}function H(o,e){for(let t of o){if(Array.isArray(t)){H(t,e);continue}t._$parentNode=e}}function l(o,e){for(let t of o)e(t)&&l(t._$nodes,e)}function _(o,e,t=!0){for(let s of o)[0,1].includes(s._$nodeType)?(e(s._$el,s),t&&_(s._$nodes,e)):_(s._$nodes,e,t)}function j(o){let e=[];return _(o,(t,s)=>{s._$nodeType===0&&e.push(t)},!1),e}var $=(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))($||{}),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(e){}_$addBeforeInitSubNodes(e){let t=this._$beforeInitSubNodes;this._$beforeInitSubNodes=function(s){t.call(this,s),e.call(this,s)}}_$bindNodes(){H(this._$nodes,this),this._$beforeInitSubNodes(this._$nodes),w(this._$nodes)}constructor(e){this._$nodeType=e}_$init(){}};function q(o,e,t,s,n){o[`_$$${e}`]||(o[`_$$${e}`]=n?t():t,o[`_$$$${e}`]="_$prop",Object.defineProperty(o,e,{get(){return this[`_$$${e}`]},set(i){this[`_$$${e}`]!==i&&(this[`_$$${e}`]=i,this._$runDeps(e))}}),o._$deps[e]=new Map),n&&O(s,o,e,t,n)}function C(o,e,t,s,n,i,d){if(o?._$forwardProps&&e==="prop"){q(o,t,s,n,i);return}if(t in o){if(!i){o[t]=s;return}if(!(o[`_$$${t}`]!==`_$${e}`&&o[`_$$$${t}`]!==`_$${e}`)){if(o[`_$$${t}`]===`_$${e}`){z(n,o,t,s,i);return}if(d&&`_$$${i[0]}`in n){O(n,o,t,s,i);return}G(n,o,t,s,i)}}}function z(o,e,t,s,n){let i={};e._$depObjectIds.push(i),e[t]=s(),o._$addDeps(n,i,()=>{e[t]=s(),e._$runDeps(t)})}function O(o,e,t,s,n){let i={};e._$depObjectIds.push(i);for(let d of n){let r=()=>o[d]=e[t];e._$addDeps([t],i,r),e[t]=s(),o._$addDeps(n,i,()=>{e._$deleteDep(t,i),e[t]=s(),e._$addDeps([t],i,r)})}}function G(o,e,t,s,n){let i={};e._$depObjectIds.push(i),e[`_$${t}`]=s(),o._$addDeps(n,i,()=>{e[`_$${t}`]=s(),e._$runDeps(t)})}function F(o,e){l(e,t=>{switch(t._$nodeType){case 1:case 0:o._$el.appendChild(t._$el);break;default:F(o,t._$nodes);break}return!1})}function D(o){X(o),_(o,(e,t)=>{document.body.contains(e)&&(t._$nodeType===0&&t.willDisappear(e,t),e.remove(),t._$nodeType===0&&t.didDisappear(e,t))}),Y(o)}function m(o){for(let e of o)e._$detach()}function y(o,e){l(o,t=>{for(let s of t._$depObjectIds)e._$deleteDeps(s);return t._$nodeType===2&&y(t._$children,e),!0})}function b(o,e,t,s){let n=s??t.childNodes.length;return J(o),_(o,(i,d)=>{let r=document.body.contains(i);[0].includes(d._$nodeType)&&!r&&U(d,"willAppear"),e===n?t.appendChild(i):t.insertBefore(i,t.childNodes[e]),[0].includes(d._$nodeType)&&!r&&U(d,"didAppear"),e++,n++},!1),Q(o),[e,n]}function U(o,e){o[e](o._$el,o),_(o._$nodes,(t,s)=>{[0].includes(s._$nodeType)&&s[e](t,s)},!0)}function T(o,e){return S(o._$nodes,e)}function M(o){return S(o,void 0)}function S(o,e){let t=0,s=!1;return l(o,n=>s?!1:n===e?(s=!0,!1):[1,0].includes(n._$nodeType)?(t++,!1):!0),t}function I(o,e){l(o,t=>([2].includes(t._$nodeType)&&t[e](t),!0))}function J(o){I(o,"willMount")}function Q(o){I(o,"didMount")}function X(o){I(o,"willUnmount")}function Y(o){I(o,"didUnmount")}var P=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 n=this[e];this._$addDeps(t,{},()=>{let i=s();i!==n&&(this[e]=i,n=i,this._$runDeps(e))})}}_$addDeps(e,t,s){for(let n of e)this._$deps[n].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._$bindNodes(),this.Afterset()}_$addProp(e,t,s,n,i){C(this,"prop",e,t,s,n,i)}willMount(e,t){}didMount(e,t){}willUnmount(e,t){}didUnmount(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(n,i){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),l(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),l(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(),m(this._$children)}_$forwardProps=!1;forwardProps(e){let t=[...new Set(Object.getOwnPropertyNames(this).filter(s=>this[s]==="_$prop").map(s=>s.replace(/^_\$*/,"")))];for(let s of t)e._$addProp(s,()=>this[s],this,[s],!0);e._$nodeType===2?e._$children=this._$children:e._$nodes=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,n){let i;if(e[0]==="_")i=a=>this._$el.style[e.slice(1)]=a;else if(e==="className"){let a="\\*none\\*";i=g=>{let c=this._$el.className,f=c;new RegExp(a).test(c)?f=f.replace(new RegExp(a),g):f+=` ${g}`,a=g,this._$el.className=f}}else i=a=>this._$el[e]=a;if(!n){i(t);return}let d=t();i(d);let r=()=>{let a=t();d!==a&&(i(a),d=a)},h={};this._$depObjectIds.push(h),s._$addDeps(n,h,r)}willAppear(e,t){}didAppear(e,t){}willDisappear(e,t){}didDisappear(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(n,i){s.call(this,n,i),e.call(this,n,i)}}};var x=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,n){e.call(this,s,n),t.call(this,s,n)}}_$bindNewNodes(e){H(e,this),this._$beforeInitSubNodes(e),w(e),this.afterUpdateNewNodes(e)}_$detach(){super._$detach()}};var K=class extends x{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 n of this.array.keys())this._$nodess.push(this.nodeFunc(null,n,this));else for(let[n,i]of this.keys.entries())this._$nodess.push(this.nodeFunc(i,n,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 n=this.array.length;if(s!==n){if(s<n){let i=T(e,this),d=t.childNodes.length;for(let r=0;r<n;r++){if(r<s){i+=M(this._$nodess[r]);continue}let h=this.getNewNodes(null,r);[i,d]=b(h,i,t,d),this._$nodess.push(h)}this._$nodes=this._$nodess.flat(1);return}for(let i=n;i<s;i++)y(this._$nodess[i],this.dlScope),D(this._$nodess[i]),m(this._$nodess[i]);this._$nodess=this._$nodess.slice(0,n),this._$nodes=this._$nodess.flat(1)}}updateWithKey(e){let t=e._$el,s=T(e,this),n=this.keys,i=[...this.array],d=[...this._$nodess],r=[...this._$nodes];this.setArray(),this.setKeys(),this.duplicatedOrNoKey&&(n=[...Array(i.length).keys()]);let h=[],a=[],g=[];for(let[p,N]of n.entries()){if(this.keys.includes(N)){h.push(N),a.push(d[p]);continue}y(d[p],this.dlScope),D(d[p]),m(d[p]),g.push(p)}n=h;let c=s,f=t.childNodes.length;for(let[p,N]of this.keys.entries()){if(n.includes(N)){c+=M(a[n.indexOf(N)]);continue}let L=this.getNewNodes(N,p);[c,f]=b(L,c,t,f),a.splice(p,0,L),n.splice(p,0,N)}c=s;for(let[p,N]of this.keys.entries()){let L=n.indexOf(N);if(L===p){c+=M(a[p]);continue}let A=a[L],R=n[L];[c,f]=b(A,c,t,f),a.splice(L,1),n.splice(L,1),a.splice(p+1,0,A),n.splice(p+1,0,R)}this._$nodess=a,this._$nodes=this._$nodess.flat(1),this.onUpdateNodes(r,this._$nodes)}_$listen(e,t,s,n){let i={};e._$depObjectIds.push(i),e._$addDeps(s,i,()=>{let d=t();if(d===void 0){e._$deleteDeps(i);return}n(d)})}_$detach(){super._$detach(),this._$nodess=[]}};var W=class extends x{conditionPairs=[];condition;listenDeps=[];dlScope;_$envNodes=[];constructor(){super(4)}_$addCond(e,t,s,n){this.conditionPairs.push({condition:e,node:t}),n&&(this.dlScope||(this.dlScope=s),this.listenDeps.push(...n))}_$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 d of this.conditionPairs)if(d.condition()){this.condition!==d.condition.toString()?(y(t,this.dlScope),D(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),D(t)),s===this.condition)return;let n=T(e,this),i=e._$el;b(this._$nodes,n,i,i.childNodes.length),m(t),this.onUpdateNodes(t,this._$nodes)}};var v=class extends u{constructor(e,t,s){if(super(1),!s){this._$el=document.createTextNode(e);return}e=e;let n=e();this._$el=document.createTextNode(n);let i=()=>{let r=e();n!==r&&(this._$el.nodeValue=r,n=r)},d={};this._$depObjectIds.push(d),t._$addDeps(s,d,i)}};var V=class extends u{addPropFuncs=[];constructor(){super(5)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,n){this.addPropFuncs.push(i=>C(i,"env",e,t,s,n))}addProps(e){for(let t of this.addPropFuncs)t(e)}addPropsToNodes(e){l(e,t=>(t._$addBeforeInitSubNodes(s=>{this.addPropsToNodes(s)}),t._$nodeType===2&&this.addProps(t),!1))}_$init(){this.addPropsToNodes(this._$nodes),this._$bindNodes()}};var B=class extends x{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){l(this._$nodes,t=>([4,3,6].includes(t._$nodeType)&&t.addOnUpdateNodesFunc(e),!0))}_$addProp(e,t,s,n){let i=d=>{if(["willAppear","didAppear","willDisappear","didDisappear"].includes(e)){d._$addLifeCycle(t,e);return}e[0]==="_"&&(d._$el.style[e.slice(1)]??"").trim()!==""||!["className"].includes(e)&&e[0]!=="_"&&d._$el[e]!==void 0||d._$addProp(e,t,s,n)};this.propFuncs.push(()=>{for(let d of this._$nodes)switch(d._$nodeType){case 0:i(d);break;case 3:case 4:case 6:d.addAfterUpdateNewNodesFunc(r=>{_(r,(h,a)=>{a._$nodeType===0&&i(a)},!1)});default:_(d._$nodes,(r,h)=>{h._$nodeType===0&&i(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 v(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 n={};this._$depObjectIds.push(n),this.dlScope._$addDeps(this.listenDeps,n,s)}}update(e){let t=this._$nodes;y(this._$nodes,this.dlScope),D(this._$nodes),this._$nodes=this.formatNodes(this.nodeOrFunc()),this._$bindNewNodes(this._$nodes);let s=e._$el,n=T(e,this);b(this._$nodes,n,s,s.childNodes.length),m(t),this.onUpdateNodes(t,this._$nodes)}};var et=P;function tt(o,e){new e().render(o)}export{P as CustomNode,u as DLNode,$ as DLNodeType,V as EnvNode,B as ExpressionNode,K as ForNode,E as HtmlNode,W as IfNode,v as TextNode,et as View,H as bindParentNode,w as initNodes,_ as loopEls,l as loopNodes,tt as render,j as toEls};
function w(o){for(let e of o){if(Array.isArray(e)){w(e);continue}e._$init()}}function H(o,e){for(let t of o){if(Array.isArray(t)){H(t,e);continue}t._$parentNode=e}}function l(o,e){for(let t of o)e(t)&&l(t._$nodes,e)}function _(o,e,t=!0){for(let s of o)[0,1].includes(s._$nodeType)?(e(s._$el,s),t&&_(s._$nodes,e)):_(s._$nodes,e,t)}function j(o){let e=[];return _(o,(t,s)=>{s._$nodeType===0&&e.push(t)},!1),e}var $=(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=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(e){}_$addBeforeInitSubNodes(e){let t=this._$beforeInitSubNodes;this._$beforeInitSubNodes=function(s){t.call(this,s),e.call(this,s)}}_$bindNodes(){H(this._$nodes,this),this._$beforeInitSubNodes(this._$nodes),w(this._$nodes)}constructor(e){this._$nodeType=e}_$init(){}};function q(o,e,t,s,n){o[`_$$${e}`]||(o[`_$$${e}`]=n!=null?t():t,o[`_$$$${e}`]="_$prop",Object.defineProperty(o,e,{get(){return this[`_$$${e}`]},set(i){this[`_$$${e}`]!==i&&(this[`_$$${e}`]=i,this._$runDeps(e))}}),o._$deps[e]=new Map),n!=null&&O(s,o,e,t,n)}function C(o,e,t,s,n,i,d){if(o?._$forwardProps&&e==="prop"){q(o,t,s,n,i);return}if(t in o){if(i==null){o[t]=s;return}if(!(o[`_$$${t}`]!==`_$${e}`&&o[`_$$$${t}`]!==`_$${e}`)){if(o[`_$$${t}`]===`_$${e}`){z(n,o,t,s,i);return}if(d&&`_$$${i[0]}`in n){O(n,o,t,s,i);return}G(n,o,t,s,i)}}}function z(o,e,t,s,n){let i={};e._$depObjectIds.push(i),e[t]=s(),o._$addDeps(n,i,()=>{e[t]=s(),e._$runDeps(t)})}function O(o,e,t,s,n){let i={};e._$depObjectIds.push(i);for(let d of n){let r=()=>{o[d]=e[t]};e._$addDeps([t],i,r),e[t]=s(),o._$addDeps(n,i,()=>{e._$deleteDep(t,i),e[t]=s(),e._$addDeps([t],i,r)})}}function G(o,e,t,s,n){let i={};e._$depObjectIds.push(i),e[`_$${t}`]=s(),o._$addDeps(n,i,()=>{e[`_$${t}`]=s(),e._$runDeps(t)})}function A(o,e){l(e,t=>{switch(t._$nodeType){case 1:case 0:o._$el.appendChild(t._$el);break;default:A(o,t._$nodes);break}return!1})}function D(o){X(o),_(o,(e,t)=>{document.body.contains(e)&&(t._$nodeType===0&&t.willDisappear(e,t),e.remove(),t._$nodeType===0&&t.didDisappear(e,t))}),Y(o)}function m(o){for(let e of o)e._$detach()}function y(o,e){l(o,t=>{for(let s of t._$depObjectIds)e._$deleteDeps(s);return t._$nodeType===2&&y(t._$children,e),!0})}function b(o,e,t,s){let n=s??t.childNodes.length;return J(o),_(o,(i,d)=>{let r=document.body.contains(i);[0].includes(d._$nodeType)&&!r&&U(d,"willAppear"),e===n?t.appendChild(i):t.insertBefore(i,t.childNodes[e]),[0].includes(d._$nodeType)&&!r&&U(d,"didAppear"),e++,n++},!1),Q(o),[e,n]}function U(o,e){o[e](o._$el,o),_(o._$nodes,(t,s)=>{[0].includes(s._$nodeType)&&s[e](t,s)},!0)}function T(o,e){return S(o._$nodes,e)}function I(o){return S(o,void 0)}function S(o,e){let t=0,s=!1;return l(o,n=>s?!1:n===e?(s=!0,!1):[1,0].includes(n._$nodeType)?(t++,!1):!0),t}function M(o,e){l(o,t=>([2].includes(t._$nodeType)&&t[e](t),!0))}function J(o){M(o,"willMount")}function Q(o){M(o,"didMount")}function X(o){M(o,"willUnmount")}function Y(o){M(o,"didUnmount")}var P=class extends c{_$deps={};_$envNodes;_$derivedPairs;_$tag="";constructor(){super(2)}_$addAfterset(e){let t=this.Afterset.bind(this);this.Afterset=function(){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)}_$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 n=this[e];this._$addDeps(t,{},()=>{let i=s();i!==n&&(this[e]=i,n=i,this._$runDeps(e))})}}_$addDeps(e,t,s){for(let n of e)this._$deps[n].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._$bindNodes(),this.Afterset()}_$addProp(e,t,s,n,i){C(this,"prop",e,t,s,n,i)}willMount(e,t){}didMount(e,t){}willUnmount(e,t){}didUnmount(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(n,i){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),l(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),l(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(),m(this._$children)}_$forwardProps=!1;forwardProps(e){let t=[...new Set(Object.getOwnPropertyNames(this).filter(s=>this[s]==="_$prop").map(s=>s.replace(/^_\$*/,"")))];for(let s of t)e._$addProp(s,()=>this[s],this,[s],!0);e._$nodeType===2?e._$children=this._$children:e._$nodes=this._$children}};var E=class extends c{_$envNodes=[];constructor(e){super(0),this._$el=document.createElement(e)}_$init(){this._$bindNodes(),A(this,this._$nodes)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,n){let i;if(e[0]==="_")i=a=>{this._$el.style[e.slice(1)]=a};else if(e==="className"){let a="\\*none\\*";i=g=>{let u=this._$el.className,f=u;new RegExp(a).test(u)?f=f.replace(new RegExp(a),g):f+=` ${g}`,a=g,this._$el.className=f}}else i=a=>{this._$el[e]=a};if(!n){i(t);return}let d=t();i(d);let r=()=>{let a=t();d!==a&&(i(a),d=a)},h={};this._$depObjectIds.push(h),s._$addDeps(n,h,r)}willAppear(e,t){}didAppear(e,t){}willDisappear(e,t){}didDisappear(e,t){}_$addLifeCycle(e,t){let s=this[t];this[t]=function(n,i){s.call(this,n,i),e.call(this,n,i)}}};var x=class extends c{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,n){e.call(this,s,n),t.call(this,s,n)}}_$bindNewNodes(e){H(e,this),this._$beforeInitSubNodes(e),w(e),this.afterUpdateNewNodes(e)}_$detach(){super._$detach()}};var K=class extends x{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 n of this.array.keys())this._$nodess.push(this.nodeFunc(null,n,this));else for(let[n,i]of this.keys.entries())this._$nodess.push(this.nodeFunc(i,n,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 n=this.array.length;if(s!==n){if(s<n){let i=T(e,this),d=t.childNodes.length;for(let r=0;r<n;r++){if(r<s){i+=I(this._$nodess[r]);continue}let h=this.getNewNodes(null,r);[i,d]=b(h,i,t,d),this._$nodess.push(h)}this._$nodes=this._$nodess.flat(1);return}for(let i=n;i<s;i++)y(this._$nodess[i],this.dlScope),D(this._$nodess[i]),m(this._$nodess[i]);this._$nodess=this._$nodess.slice(0,n),this._$nodes=this._$nodess.flat(1)}}updateWithKey(e){let t=e._$el,s=T(e,this),n=this.keys,i=[...this.array],d=[...this._$nodess],r=[...this._$nodes];this.setArray(),this.setKeys(),this.duplicatedOrNoKey&&(n=[...Array(i.length).keys()]);let h=[],a=[],g=[];for(let[p,N]of n.entries()){if(this.keys.includes(N)){h.push(N),a.push(d[p]);continue}y(d[p],this.dlScope),D(d[p]),m(d[p]),g.push(p)}n=h;let u=s,f=t.childNodes.length;for(let[p,N]of this.keys.entries()){if(n.includes(N)){u+=I(a[n.indexOf(N)]);continue}let L=this.getNewNodes(N,p);[u,f]=b(L,u,t,f),a.splice(p,0,L),n.splice(p,0,N)}u=s;for(let[p,N]of this.keys.entries()){let L=n.indexOf(N);if(L===p){u+=I(a[p]);continue}let F=a[L],R=n[L];[u,f]=b(F,u,t,f),a.splice(L,1),n.splice(L,1),a.splice(p+1,0,F),n.splice(p+1,0,R)}this._$nodess=a,this._$nodes=this._$nodess.flat(1),this.onUpdateNodes(r,this._$nodes)}_$listen(e,t,s,n){let i={};e._$depObjectIds.push(i),e._$addDeps(s,i,()=>{let d=t();if(d===void 0){e._$deleteDeps(i);return}n(d)})}_$detach(){super._$detach(),this._$nodess=[]}};var W=class extends x{conditionPairs=[];condition;listenDeps=[];dlScope;_$envNodes=[];constructor(){super(4)}_$addCond(e,t,s,n){this.conditionPairs.push({condition:e,node:t}),n&&(this.dlScope||(this.dlScope=s),this.listenDeps.push(...n))}_$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 d of this.conditionPairs)if(d.condition()){this.condition!==d.condition.toString()?(y(t,this.dlScope),D(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),D(t)),s===this.condition)return;let n=T(e,this),i=e._$el;b(this._$nodes,n,i,i.childNodes.length),m(t),this.onUpdateNodes(t,this._$nodes)}};var v=class extends c{constructor(e,t,s){if(super(1),!s){this._$el=document.createTextNode(e);return}e=e;let n=e();this._$el=document.createTextNode(n);let i=()=>{let r=e();n!==r&&(this._$el.nodeValue=r,n=r)},d={};this._$depObjectIds.push(d),t._$addDeps(s,d,i)}};var V=class extends c{addPropFuncs=[];constructor(){super(5)}_$addNodes(e){this._$nodes=e}_$addProp(e,t,s,n){this.addPropFuncs.push(i=>{C(i,"env",e,t,s,n)})}addProps(e){for(let t of this.addPropFuncs)t(e)}addPropsToNodes(e){l(e,t=>(t._$addBeforeInitSubNodes(s=>{this.addPropsToNodes(s)}),t._$nodeType===2&&this.addProps(t),!1))}_$init(){this.addPropsToNodes(this._$nodes),this._$bindNodes()}};var B=class extends x{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){l(this._$nodes,t=>([4,3,6].includes(t._$nodeType)&&t.addOnUpdateNodesFunc(e),!0))}_$addProp(e,t,s,n){let i=d=>{if(["willAppear","didAppear","willDisappear","didDisappear"].includes(e)){d._$addLifeCycle(t,e);return}e[0]==="_"&&(d._$el.style[e.slice(1)]??"").trim()!==""||!["className"].includes(e)&&e[0]!=="_"&&d._$el[e]!==void 0||d._$addProp(e,t,s,n)};this.propFuncs.push(()=>{for(let d of this._$nodes)switch(d._$nodeType){case 0:i(d);break;case 3:case 4:case 6:d.addAfterUpdateNewNodesFunc(r=>{_(r,(h,a)=>{a._$nodeType===0&&i(a)},!1)});default:_(d._$nodes,(r,h)=>{h._$nodeType===0&&i(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 v(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 n={};this._$depObjectIds.push(n),this.dlScope._$addDeps(this.listenDeps,n,s)}}update(e){let t=this._$nodes;y(this._$nodes,this.dlScope),D(this._$nodes),this._$nodes=this.formatNodes(this.nodeOrFunc()),this._$bindNewNodes(this._$nodes);let s=e._$el,n=T(e,this);b(this._$nodes,n,s,s.childNodes.length),m(t),this.onUpdateNodes(t,this._$nodes)}};var Je=P;function Qe(o,e){new e().render(o)}export{P as CustomNode,c as DLNode,$ as DLNodeType,V as EnvNode,B as ExpressionNode,K as ForNode,E as HtmlNode,W as IfNode,v as TextNode,Je as View,H as bindParentNode,w as initNodes,_ as loopEls,l as loopNodes,Qe as render,j as toEls};
{
"name": "@dlightjs/dlight",
"version": "0.4.13",
"version": "0.5.0",
"files": [

@@ -20,3 +20,6 @@ "dist"

"author": "IanDx",
"license": "ISC"
"license": "ISC",
"scripts": {
"build": "tsup"
}
}

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