Socket
Socket
Sign inDemoInstall

deleight

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deleight - npm Package Compare versions

Comparing version 1.3.4 to 2.0.0

dist/eutility/cjs/eutility.d.ts

5

dist/actribute/cjs/actribute.d.ts

@@ -60,2 +60,3 @@ /**

attr?: string;
rattr?: string;
ctx?: any[];

@@ -80,3 +81,3 @@ } | Element | string | any[];

registry: {
[key: string | number]: Function;
[key: string | number]: IComponent;
};

@@ -170,3 +171,3 @@ /**

*/
process(options?: IProcessOptions): Actribute;
process(options?: IProcessOptions, recursiveComps?: Map<IComponent, Attr>): Actribute;
}

@@ -173,0 +174,0 @@ /**

2

dist/actribute/cjs/actribute.js

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

"use strict";const t=Symbol("Open component"),e=Symbol("Closed component");function r(t,e){const r=e.split(".");let o=t[r[0].trim()];for(let e=1;e<r.length&&("object"==typeof o||"function"==typeof o);e++)o=(t=o)[r[e].trim()];return o}exports.Actribute=class{registry={};openAttr;closedAttr;constructor(t){this.openAttr=t?.open||"o-pen",this.closedAttr=t?.closed||"c-losed"}register(t){return Object.assign(this.registry,t)&&this}process(r){let o,s,n;"string"==typeof r?s=r:r instanceof Element?o=r:r instanceof Array?n=r:"object"==typeof r&&(o=r.el,s=r.attr,n=r.ctx),o||(o=document.body),s||(s="c-"),n||(n=[]);const i=o.attributes,c=i.length;let l,p,h,f,u=!1,y=o.hasAttribute(this.openAttr),a=o.hasAttribute(this.closedAttr);for(p=0;p<c;p++)if(l=i[p],l&&l.name.startsWith(s)){if(u=!0,h=l.name.substring(s.length),this.registry.hasOwnProperty(h))f=this.registry[h](o,l,...n);else{if(!this.registry.hasOwnProperty("*"))throw new Error(`The component "${h}" was not found in the registry.`);f=this.registry["*"](o,l,...n)}f===t?y=!0:f===e&&(a=!0)}if(!u||y&&!a){let t=o.firstElementChild;for(;t;)t.hasAttribute(this.closedAttr)||this.process({el:t,attr:s,ctx:n}),t=t.nextElementSibling}return this}},exports.closed=e,exports.join=function(t,e){return(r,o,...s)=>{let n;for(let e of t)n=e(r,o,...s);return e||n}},exports.open=t,exports.props=function(t,e,o){"string"!=typeof t&&(t=t.toString());const s=[],n=e.length;let i,c,l;for(i of(t=t.trim()).split(o||" "))if(i=i.trim(),""!==i){for(c=void 0,l=-1;void 0===c&&++l<n;)c=r(e[l],i);if(void 0===c)throw new TypeError(`The property "${i}" was not found in any of the sources.`);s.push(c)}return s};
"use strict";const t=Symbol("Open component"),e=Symbol("Closed component");function r(t,e){const r=e.split(".");let s=t[r[0].trim()];for(let e=1;e<r.length&&("object"==typeof s||"function"==typeof s);e++)s=(t=s)[r[e].trim()];return s}exports.Actribute=class{registry={};openAttr;closedAttr;constructor(t){this.openAttr=t?.open||"o-pen",this.closedAttr=t?.closed||"c-losed"}register(t){return Object.assign(this.registry,t)&&this}process(r,s){let o,n,i,c;"string"==typeof r?n=r:r instanceof Element?o=r:r instanceof Array?c=r:"object"==typeof r&&(o=r.el,n=r.attr,i=r.rattr,c=r.ctx),o||(o=document.body),n||(n="c-"),i||(i="r-"),c||(c=[]),s||(s=new Map);const h=o.attributes,p=h.length;let l,f,a,u,y,m=!1,g=o.hasAttribute(this.openAttr),d=o.hasAttribute(this.closedAttr);for([u,l]of s.entries())u(o,l,...c);for(f=0;f<p;f++)if(l=h[f],l&&(l.name.startsWith(n)||l.name.startsWith(i))&&l.name!==this.openAttr&&l.name!==this.closedAttr){if(m=!0,a=l.name.substring(n.length),this.registry.hasOwnProperty(a))u=this.registry[a],l.name.startsWith(i)&&!s.has(u)&&s.set(u,l),y=u(o,l,...c);else{if(!this.registry.hasOwnProperty("*"))throw new Error(`The component "${a}" was not found in the registry.`);y=this.registry["*"](o,l,...c)}y===t?g=!0:y===e&&(d=!0)}if((!m||s.size||g)&&!d){let t=o.firstElementChild;const e=[];for(s.size&&e.push(s);t;)this.process({el:t,attr:n,rattr:i,ctx:c},...e),t=t.nextElementSibling}return this}},exports.closed=e,exports.join=function(t,e){return(r,s,...o)=>{let n;for(let e of t)n=e(r,s,...o);return e||n}},exports.open=t,exports.props=function(t,e,s){"string"!=typeof t&&(t=t.toString());const o=[],n=e.length;let i,c,h;for(i of(t=t.trim()).split(s||" "))if(i=i.trim(),""!==i){for(c=void 0,h=-1;void 0===c&&++h<n;)c=r(e[h],i);if(void 0===c)throw new TypeError(`The property "${i}" was not found in any of the sources.`);o.push(c)}return o};

@@ -60,2 +60,3 @@ /**

attr?: string;
rattr?: string;
ctx?: any[];

@@ -80,3 +81,3 @@ } | Element | string | any[];

registry: {
[key: string | number]: Function;
[key: string | number]: IComponent;
};

@@ -170,3 +171,3 @@ /**

*/
process(options?: IProcessOptions): Actribute;
process(options?: IProcessOptions, recursiveComps?: Map<IComponent, Attr>): Actribute;
}

@@ -173,0 +174,0 @@ /**

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

const t=Symbol("Open component"),e=Symbol("Closed component");class r{registry={};openAttr;closedAttr;constructor(t){this.openAttr=t?.open||"o-pen",this.closedAttr=t?.closed||"c-losed"}register(t){return Object.assign(this.registry,t)&&this}process(r){let o,s,n;"string"==typeof r?s=r:r instanceof Element?o=r:r instanceof Array?n=r:"object"==typeof r&&(o=r.el,s=r.attr,n=r.ctx),o||(o=document.body),s||(s="c-"),n||(n=[]);const i=o.attributes,c=i.length;let l,h,f,p,u=!1,y=o.hasAttribute(this.openAttr),a=o.hasAttribute(this.closedAttr);for(h=0;h<c;h++)if(l=i[h],l&&l.name.startsWith(s)){if(u=!0,f=l.name.substring(s.length),this.registry.hasOwnProperty(f))p=this.registry[f](o,l,...n);else{if(!this.registry.hasOwnProperty("*"))throw new Error(`The component "${f}" was not found in the registry.`);p=this.registry["*"](o,l,...n)}p===t?y=!0:p===e&&(a=!0)}if(!u||y&&!a){let t=o.firstElementChild;for(;t;)t.hasAttribute(this.closedAttr)||this.process({el:t,attr:s,ctx:n}),t=t.nextElementSibling}return this}}function o(t,e){const r=e.split(".");let o=t[r[0].trim()];for(let e=1;e<r.length&&("object"==typeof o||"function"==typeof o);e++)o=(t=o)[r[e].trim()];return o}function s(t,e,r){"string"!=typeof t&&(t=t.toString());const s=[],n=e.length;let i,c,l;for(i of(t=t.trim()).split(r||" "))if(i=i.trim(),""!==i){for(c=void 0,l=-1;void 0===c&&++l<n;)c=o(e[l],i);if(void 0===c)throw new TypeError(`The property "${i}" was not found in any of the sources.`);s.push(c)}return s}function n(t,e){return(r,o,...s)=>{let n;for(let e of t)n=e(r,o,...s);return e||n}}export{r as Actribute,e as closed,n as join,t as open,s as props};
const t=Symbol("Open component"),e=Symbol("Closed component");class r{registry={};openAttr;closedAttr;constructor(t){this.openAttr=t?.open||"o-pen",this.closedAttr=t?.closed||"c-losed"}register(t){return Object.assign(this.registry,t)&&this}process(r,s){let o,n,i,h;"string"==typeof r?n=r:r instanceof Element?o=r:r instanceof Array?h=r:"object"==typeof r&&(o=r.el,n=r.attr,i=r.rattr,h=r.ctx),o||(o=document.body),n||(n="c-"),i||(i="r-"),h||(h=[]),s||(s=new Map);const c=o.attributes,l=c.length;let f,a,p,u,y,m=!1,g=o.hasAttribute(this.openAttr),d=o.hasAttribute(this.closedAttr);for([u,f]of s.entries())u(o,f,...h);for(a=0;a<l;a++)if(f=c[a],f&&(f.name.startsWith(n)||f.name.startsWith(i))&&f.name!==this.openAttr&&f.name!==this.closedAttr){if(m=!0,p=f.name.substring(n.length),this.registry.hasOwnProperty(p))u=this.registry[p],f.name.startsWith(i)&&!s.has(u)&&s.set(u,f),y=u(o,f,...h);else{if(!this.registry.hasOwnProperty("*"))throw new Error(`The component "${p}" was not found in the registry.`);y=this.registry["*"](o,f,...h)}y===t?g=!0:y===e&&(d=!0)}if((!m||s.size||g)&&!d){let t=o.firstElementChild;const e=[];for(s.size&&e.push(s);t;)this.process({el:t,attr:n,rattr:i,ctx:h},...e),t=t.nextElementSibling}return this}}function s(t,e){const r=e.split(".");let s=t[r[0].trim()];for(let e=1;e<r.length&&("object"==typeof s||"function"==typeof s);e++)s=(t=s)[r[e].trim()];return s}function o(t,e,r){"string"!=typeof t&&(t=t.toString());const o=[],n=e.length;let i,h,c;for(i of(t=t.trim()).split(r||" "))if(i=i.trim(),""!==i){for(h=void 0,c=-1;void 0===h&&++c<n;)h=s(e[c],i);if(void 0===h)throw new TypeError(`The property "${i}" was not found in any of the sources.`);o.push(h)}return o}function n(t,e){return(r,s,...o)=>{let n;for(let e of t)n=e(r,s,...o);return e||n}}export{r as Actribute,e as closed,n as join,t as open,o as props};
/**
* This module enables reactivity by exporting primitives for multiplying the effects of single operations.
* This module enables reactivity by exporting primitives for multiplying the effects of single operations.
*/
/**
* Creates a One object which transmits a call, method dispatch, property
* get or set applied to the 'one' object to the 'many' objects.
*
* The recursive arg is used to ensure that getting properties always
* wraps the array results with `one` also.
*
* Items in the context arg will be passed to all delegated calls as the
* final arguments. An empty array is created if not specified.
*
* Sometimes, you may want to pass an array of 1 or more objects to provide a shared
* context for the items in many. Other times you may prefer no context because
* it may affect the behavior of the calls, since the functions or methods may
* be accepting optional arguments there. Passing your own arrays enable you to
* set the behavior however you like (by emptying or populating the array).
*
* @example
* import { one } from 'deleight/onetomany';
* const component = one([data(), view(table)], false, [{}]);
* component.create([10000]);
*
* @param {any[]} many An array of objects to delegat actios to
* @param {boolean} [recursive] Whether to return One instances in `get` calls
* @param {any[]} [context] Shared context for the 'many' functions or object methods
* @param {number} [mainItem] Set a main item (like 0 for the first item) if the one must behave
* like it. This way the main item can be simply replaced with the one in existing code.
* @returns
*/
declare function one(many: any[], recursive?: boolean, context?: any[], mainItem?: number): One;
/**
* Return a wrapped (proxied) One from a pure One.
*
* @example
* import { One, wrap } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.set('a', [4, 7]);
* const a = wrap(o).a // [4, 7]
*
* @param o
* @param {number} [mainItem] Set a main item (like 0 for the first item) if the one must behave
* like it. This way the main item can be simply replaced with the one in existing code.
* @returns
*/
declare function wrap(o: One, mainItem?: number): One;
/**
* Return a 'pure' One from a proxied One.
*
* @example
* import { one, unWrap } from 'deleight/onetomany';
* const o = one([{a: 1}, {a: 2}])
* o.a = [4, 7];
* const many = unWrap(o).many
*
* @param one
* @returns
*/
declare function unWrap(one: One): any;
/**
* A recursive One constructor. Used internally for recursive 'One's.
*/
interface IOneConstructor {
(many: any[], recursive?: boolean, context?: any[]): One;
}
/**
* An object which delegates actions on it to other objects
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.set('a', [4, 7]);
*
*/
declare class One {
type IExtend<T, U> = Omit<T, keyof U> & {
[key in (keyof T) & (keyof U)]: T[key] extends One<T> ? IExtend<T[key], U[key]> : U[key];
} & Omit<U, keyof T>;
type IKey = string | number | symbol;
type IObject = {
[key: IKey]: any;
};
type IKeyObject<T> = {
[key in keyof T]: IKey | IKey[];
};
type IViewMap<T> = {
[key in keyof T]: IKey;
};
type ILike<T> = {
[key in keyof T]: any;
};
declare const map: unique symbol;
declare const args: unique symbol;
declare class View<T> {
#private;
one: One<T>;
map: IViewMap<T>;
/**
* The many objects this One delegates to.
* Represents a single view of a `One` instance. A view can be described as an
* object comprising one property each from the different objects that are part of
* the `One` object. We can perform actions on a view without explicitly specifying
* the properties.
*
* @example
* import { One, View, args } from "deleight/onetomany";
* const one = new One({ a1: [], a2: [1, 2, 3, 4, 5] });
*
* const view = new View(one, { a1: 'push', a2: 'shift' })
* // push one array and simultaneously shift the other
* // to transfer content...
*
* view.call({ [args]: one.many.a2 })
*
* @param one
* @param map
*/
many: any[];
constructor(one: One<T>, map: IViewMap<T>);
get(): {};
set(what: any): One<T>;
delete(): One<T>;
call(what: any): {};
}
declare class One<T extends IObject> {
many: T;
/**
* Optionally set main item interpreted specially when the one is
* proxied.
* Creates a single object that propagates actions on it to multiple objects.
*
* @example
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
*
* // set the same value on all objects
* o1.set({ p1: 78 });
*
* @param many
*/
mainItem?: number;
constructor(many: T);
/**
* Whether this One will return other 'One's in calls to `get`.
* Joins `many` with `this.many` and returns `this`. The benefit of
* using this function instead of something like `Object.assign` is to handle some
* special cases and ensure that the updated `One` is (almost) correctly typed during
* development.
*
* If the same key exists in the joined objects, the new one will overwrite the
* current one, except if the current value is a `One` instance when `extend` will
* be called on it instead.
*
* @example
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* const o2 = o1.extend({ fourth });
* // One({ first, second, third, fourth })
*
* @param many
*/
recursive?: boolean;
extend<U extends object>(many: U): One<IExtend<T, U>>;
/**
* The constructor function used for creating new 'One's in calls to `get`.
* The opposite of extend. Removes the specified keys from `this.many` and
* returns `this` typed differently.
*
* @example
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* const o2 = o1.contract('first', 'third');
* // One({ second })
*
* @param keys
* @returns
*/
ctor?: IOneConstructor;
contract<U extends keyof T>(...keys: U[]): One<Omit<T, U>>;
/**
* The context shared by the many functions or methods of the objects in many.
* They all receive its items as their last set of arguments.
*/
context?: any[];
/**
* Creates a new One instance for propagating operations to all the items
* in many.
* Creates and returns another instance of `One` containing only the
* objects with these names. If a name is not present in `this.many`,
* a new object is created for it in the returned `One`.
*
* @param {any[]} many The many objects or functions this One will delegate to.
* @param {boolean} [recursive] Whether to wrap the arrays returned by `get` with another One.
* @param {any[]} context An optional shared context to be passed to all propagated method or function calls.
* This is an array of objects passed as the final arguments in calls. Empty array by default.
*
* @example
* import { One } from 'deleight/onetomany';
* const loginYes = new One([username => profileView(username)]);
* loginYes.call([[username]]);
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* const o2 = o1.slice('first', 'second')
* // One({ first, second })
*
* @constructor
* @param names
*/
constructor(many: any[], recursive?: boolean, context?: any[]);
slice(...names: (keyof T)[]): One<IObject>;
/**
* Gets corresponding properties from all the objects in many. If this is
* a recursive One and forceArray is falsy, the array result will be
* used as the 'many' argument in a call to this.ctor and the created One
* is returned instead of the array.
* Creates and returns an instance of `View` for only the
* specified properties. `what` is an object mapping object keys (in `this.many`)
* to the property names.
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.get('a'); // [1, 2]
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex } });
* o1.view({first: 'p1', second: 'p2'});
* view.get(); // { first: 78, second: 12 }
*
* @param {string | number | symbol | null} [prop]
* @param {boolean} [forceArray]
* @returns {any[]|One}
* @param map
*/
get(prop?: string | number | symbol | null, forceArray?: boolean): any[] | One;
view(map: IViewMap<T>): View<T>;
/**
* Sets corresponding property values in the objects in many.
* 'values' are treated similarly to 'args' in the call method.
* Gets the property (or properties) with the specified name(s) from all the
* objects in `this.many`.
*
* 1. if `what` is a string, returns only the property specified (as an object mapping
* object key to property value).
* 2. if `what` is an array of strings, returns 'sub-objects' of all the objects
* consisting of the specified property names (also mapped like 1).
* 3. if what is an object, it is treated as a map of object names to property
* name(s) to return.
* 4. if an object in `this.many` is a `One` instance, its `get` method is
* called for its property value(s).
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.set('a', [4, 7]);
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex } });
*
* @param {string | number | symbol | null} [prop]
* @param {any[]} [values]
* o1.get('p1');
* // { first: 78, second: 78, third: 78 }
*
* o1.get('p1', 'p2');
* // { first: { p1: 78, p2: 56 }, second: { p1: 78, p2: 12 }, third: { p1: 78, p2: 12 } }
*
* o1.get({ first: 'p2', second: 'p1' });
* // { first: 56, second: 78 }
*
* @param what
*/
set(prop?: string | number | symbol | null, values?: any[]): any;
get(what: (IKey) | IKey[] | IKeyObject<T>, valueKey?: IKey): {};
/**
* Delete the property from all objects in many.
* Sets one or more properties on all the objects in this instance.
* `what` is an object mapping property names to property values.
*
* Each value in `what` is set on all the objects in this `One`.
* The same value will be set unless the value is an object containing the `[map]` property.
* In such a case, the value of the property is treated as a map of object key (in `this.many`)
* to object property value. That is, the objects with corresponding
* keys will have their property values set to the corresponding values.
*
* This will call `set` on any nested `One` objects accordingly.
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.delete('a');
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex }, p3: complex });
*
* @param {string | number | symbol} prop
* o1.get('p2', 'p3');
* // { first: { p2: 56, p3: complex }, second: { p2: 12, p3: complex }, third: { p2: 12, p3: complex } }
*
* @param what
*/
delete(prop: string | number | symbol): void;
set(what: IObject, valueKey?: IKey): this;
/**
* Calls all the items in many (if method is not specified) or their
* corresponding methods (if method is specified). All the calls will
* receive any items in `this.context` as their final arguments to
* enable communication.
* Performs `delete` on the objects in this `One`. The argument is
* treated the same way as in `get`.
*
* args can be specified as follows:
* `[[a1, a2], [a1, a2], [a1, a2]]`
* @example
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex }, p3: complex });
*
* If `this.many` has 3 items, they will receive their own args. If there
* are more items in `this.many`, they will all get the last provided args array
* (here the one passed to the third item).
* o1.delete('p1', 'p2');
* // One({ first: { p3: complex }, second: { p3: complex }, third: { p3: complex } })
*
* The `one` function wraps created 'One's with a proxy to allow methods
* to be called directly on them. Assuming we want to pass the same args
* as above to such a method, the call will look like:
* @param what
*/
delete(what: (IKey) | IKey[] | IKeyObject<T>): this;
/**
* Calls corresponding methods in a similar way to set. In this
* case, call arguments are interpreted instead of property values.
*
* `object.method([a1, a2], [a1, a2], [a1, a2])`.
* Multiple arguments should be provided as an object with the `[arg]` property whose value
* should be an array containing the arguments. A regular array is considered a single argument.
*
* There is no need to wrap with the outer array in such cases.
* Nested one objects will have their call method invoked correspondingly.
*
* Call returns an array containing the return values of the individual
* calls to many items.
*
* @example
* import { One } from 'deleight/onetomany';
* const loginYes = new One([username => profileView(username)]);
* loginYes.call([[username]]);
* import { One, map, args } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const o4 = new One({ arr1, arr2, arr3 });
* o4.call({ push: 78 });
* o4.call({ push: { [args]: [56, 57] } });
* // arr1 = arr2 = arr3 = [78, 56, 57]
*
* @param {any[]} args The function or method arguments
* @param {string | number | symbol} [method] The name of a method to call.
* A function call is assumed if not specified.
*
* @returns {any[]}
* @param what
*/
call(args?: any[], method?: string | number | symbol): any[];
call(what: string | string[] | IObject): {};
}
/**
* A simple wrapper around `One` for a more concise syntax.
*
* @example
* import { one, map, args } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const o4 = one({ arr1, arr2, arr3 });
* o4.push(78, 56, 57);
* o4.push({ [map]: { arr1: 66, arr2: { [args]: [77, 88] }, arr3: 99 } });
* // arr1 === [78, 56, 57, 66]
* // arr2 === [78, 56, 57, 77, 88]
* // arr3 === [78, 56, 57, 99]
*
* @param many
* @returns
*/
declare function one<T extends object>(many: T): T[keyof T];
/**
* Wraps a pre-existing `One`
*
* @example
* import { One, wrap } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const o4 = new One({ arr1, arr2, arr3 });
* const wo4 = wrap(o4);
*
* @param one
* @returns
*/
declare function wrap<T>(one: One<T>): T[keyof T];
/**
* The opposite of `wrap`
*
* @example
* import { one, unwrap } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const wo4 = one({ arr1, arr2, arr3 });
* const o4 = unwrap(wo4);
*
* @param wrapped
* @returns
*/
declare function unwrap<T>(wrapped: any): One<T>;
export { type IOneConstructor, One, one, unWrap, wrap };
export { type IExtend, type IKey, type IKeyObject, type ILike, type IObject, type IViewMap, One, View, args, map, one, unwrap, wrap };

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

"use strict";function t(e,i,s,o){const c=new r(e,i,s);return c.ctor=t,void 0!==o&&(c.mainItem=o),new Proxy(c,n)}const e=Symbol();const n={get(t,n){if(n===e)return t;let i=t.get(n,!0);if(i.length&&"function"==typeof i[0])return void 0!==t.mainItem?(...e)=>t.call([e],n)[t.mainItem]:(...e)=>t.call(e,n);if(t.recursive){if(t.ctor){const n=t.ctor(i,!0,t.context);return(n[e]||n).ctor=t.ctor,n}return new r(i,!0,t.context)}return void 0!==t.mainItem?i[t.mainItem]:i},set:(t,e,n)=>(t.set(e,n),!0)};class r{many;mainItem;recursive;ctor;context;constructor(t,e,n){this.many=t,this.recursive=e,this.context=n||[]}get(t,n){const i=[],s=this.many.length;if(null!=t)for(let e=0;e<s;e++)i.push(this.many[e][t]);else for(let t=0;t<s;t++)i.push(this.many[t]);if(!this.recursive||n)return i;if(!this.ctor)return new r(i,this.recursive,this.context);{const t=this.ctor(i,this.recursive,this.context);(t[e]||t).ctor=this.ctor}}set(t,e){if(void 0===e)return this.set(t,this.get(t,!0));e instanceof Array||(e=[e]);const n=this.many.length,r=e.length;if(null!=t)for(let i=0;i<n;i++)this.many[i][t]=e[Math.min(i,r-1)];else for(let t=0;t<n;t++)this.many[t]=e[Math.min(t,r-1)]}delete(t){for(let e of this.many)delete e[t]}call(t,e){void 0!==t&&t.length||(t=[[]]);const n=[],r=this.many.length,i=t.length;let s,o;if(void 0!==e)for(let c=0;c<r;c++)s=t[Math.min(c,i-1)]||[],o=this.many[c][e](...s,...this.context),n.push(o);else for(let e=0;e<r;e++)s=t[Math.min(e,i-1)]||[],o=this.many[e](...s,...this.context),n.push(o);return n}}exports.One=r,exports.one=t,exports.unWrap=function(t){return t[e]||t},exports.wrap=function(e,r){return e.ctor=t,void 0!==r&&(e.mainItem=r),new Proxy(e,n)};
"use strict";const e=Symbol(),t=Symbol();class n{one;map;constructor(e,t){this.one=e,this.map=t}#e(t){const n={};if(t.hasOwnProperty(e)){let s;for(let[r,o]of Object.entries(t[e]))s=this.map[r],n.hasOwnProperty(s)||(n[s]={[e]:{}}),n[s][e][r]=o}else for(let[s,r]of Object.entries(this.map))n[r]={[e]:{[s]:t}};return n}get(){return this.one.get(this.map)}set(e){return this.one.set(this.#e(e))}delete(){return this.one.delete(this.map)}call(e){return this.one.call(this.#e(e))}}class s{many;constructor(e){this.many=e}extend(e){let t;for(let[n,r]of Object.entries(e))this.many.hasOwnProperty(n)?(t=this.many[n],t instanceof s?t.extend(r):this.many[n]=r):this.many[n]=r;return this}contract(...e){for(let t of e)delete this.many[t];return this}slice(...e){const t={};for(let n of e)t[n]=this.many[n]||{};return new s(t)}view(e){return new n(this,e)}get(e,t){const n={};let r,o,i,f,a;if("string"==typeof e)for([o,f]of Object.entries(this.many))f instanceof s?n[o]=f.get(e,t):(r=f[e],t&&r instanceof s&&(r=r.many[t]),n[o]=r);else if(e instanceof Array)for([o,f]of Object.entries(this.many))if(f instanceof s)n[o]=f.get(e,t);else for(i of(n[o]=r={},e))a=f[i],t&&a instanceof s&&(a=a.many[t]),r[i]=a;else if("object"==typeof e)for(let[o,c]of Object.entries(e))if(f=this.many[o],f instanceof s)n[o]=f.get(c,t);else if(c instanceof Array)for(i of(n[o]=r={},c))a=f[i],t&&a instanceof s&&(a=a.many[t]),r[i]=a;else r=f[c],t&&r instanceof s&&(r=r.many[t]),n[o]=r;return n}set(t,n){let r,o,i,f;for(let[a,c]of Object.entries(t))if(c.hasOwnProperty(e))for([r,i]of Object.entries(c[e]))o=this.many[r],o instanceof s?o.set({prop:i},n):n?(f=o[a],f instanceof s&&f.many.hasOwnProperty(n)&&(f.many[n]=i)):o[a]=i;else for([r,o]of Object.entries(this.many))o instanceof s?o.set({prop:c},n):n?(f=o[a],f instanceof s&&f.many.hasOwnProperty(n)&&(f.many[n]=c)):o[a]=c;return this}delete(e){let t,n,r;if("string"==typeof e)for([t,r]of Object.entries(this.many))r instanceof s?r.delete(e):delete r[e];else if(e instanceof Array)for([t,r]of Object.entries(this.many))if(r instanceof s)r.delete(e);else for(n of e)delete r[n];else if("object"==typeof e)for(let[t,o]of Object.entries(e))if(r=this.many[t],r instanceof s)r.delete(o);else if(o instanceof Array)for(n of o)delete r[n];else delete r[o];return this}call(n){let r,o,i;const f={};let a;if("string"==typeof n&&(n=[n]),n instanceof Array)for(let e of n)for([r,o]of Object.entries(this.many))f[r]=o[e]?.();else for(let[c,l]of Object.entries(n))if(f[c]=a={},l.hasOwnProperty(e))for([r,i]of Object.entries(l[e]))o=this.many[r],o instanceof s?a[r]=o.call({prop:i}):i.hasOwnProperty(t)?a[r]=o[c]?.(...i[t]):a[r]=o[c]?.(i);else for([r,o]of Object.entries(this.many))o instanceof s?a[r]=o.call({prop:l}):l.hasOwnProperty(t)?a[r]=o[c]?.(...l[t]):a[r]=o[c]?.(l);return f}}function r(e){return new Proxy(e,i)}const o=Symbol(),i={get:(n,s)=>s===o?n:Object.assign(((...r)=>{let o;return 1===r.length&&"object"==typeof(o=r[0])&&o.hasOwnProperty(e)?n.call({[s]:o}):n.call({[s]:{[t]:r}})}),{get value(){return n.get(s)}}),set:(e,t,n)=>(e.set({[t]:n}),!0),deleteProperty:(e,t)=>(e.delete(t),!0)};exports.One=s,exports.View=n,exports.args=t,exports.map=e,exports.one=function(e){return r(new s(e))},exports.unwrap=function(e){return e[o]},exports.wrap=r;
/**
* This module enables reactivity by exporting primitives for multiplying the effects of single operations.
* This module enables reactivity by exporting primitives for multiplying the effects of single operations.
*/
/**
* Creates a One object which transmits a call, method dispatch, property
* get or set applied to the 'one' object to the 'many' objects.
*
* The recursive arg is used to ensure that getting properties always
* wraps the array results with `one` also.
*
* Items in the context arg will be passed to all delegated calls as the
* final arguments. An empty array is created if not specified.
*
* Sometimes, you may want to pass an array of 1 or more objects to provide a shared
* context for the items in many. Other times you may prefer no context because
* it may affect the behavior of the calls, since the functions or methods may
* be accepting optional arguments there. Passing your own arrays enable you to
* set the behavior however you like (by emptying or populating the array).
*
* @example
* import { one } from 'deleight/onetomany';
* const component = one([data(), view(table)], false, [{}]);
* component.create([10000]);
*
* @param {any[]} many An array of objects to delegat actios to
* @param {boolean} [recursive] Whether to return One instances in `get` calls
* @param {any[]} [context] Shared context for the 'many' functions or object methods
* @param {number} [mainItem] Set a main item (like 0 for the first item) if the one must behave
* like it. This way the main item can be simply replaced with the one in existing code.
* @returns
*/
declare function one(many: any[], recursive?: boolean, context?: any[], mainItem?: number): One;
/**
* Return a wrapped (proxied) One from a pure One.
*
* @example
* import { One, wrap } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.set('a', [4, 7]);
* const a = wrap(o).a // [4, 7]
*
* @param o
* @param {number} [mainItem] Set a main item (like 0 for the first item) if the one must behave
* like it. This way the main item can be simply replaced with the one in existing code.
* @returns
*/
declare function wrap(o: One, mainItem?: number): One;
/**
* Return a 'pure' One from a proxied One.
*
* @example
* import { one, unWrap } from 'deleight/onetomany';
* const o = one([{a: 1}, {a: 2}])
* o.a = [4, 7];
* const many = unWrap(o).many
*
* @param one
* @returns
*/
declare function unWrap(one: One): any;
/**
* A recursive One constructor. Used internally for recursive 'One's.
*/
interface IOneConstructor {
(many: any[], recursive?: boolean, context?: any[]): One;
}
/**
* An object which delegates actions on it to other objects
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.set('a', [4, 7]);
*
*/
declare class One {
type IExtend<T, U> = Omit<T, keyof U> & {
[key in (keyof T) & (keyof U)]: T[key] extends One<T> ? IExtend<T[key], U[key]> : U[key];
} & Omit<U, keyof T>;
type IKey = string | number | symbol;
type IObject = {
[key: IKey]: any;
};
type IKeyObject<T> = {
[key in keyof T]: IKey | IKey[];
};
type IViewMap<T> = {
[key in keyof T]: IKey;
};
type ILike<T> = {
[key in keyof T]: any;
};
declare const map: unique symbol;
declare const args: unique symbol;
declare class View<T> {
#private;
one: One<T>;
map: IViewMap<T>;
/**
* The many objects this One delegates to.
* Represents a single view of a `One` instance. A view can be described as an
* object comprising one property each from the different objects that are part of
* the `One` object. We can perform actions on a view without explicitly specifying
* the properties.
*
* @example
* import { One, View, args } from "deleight/onetomany";
* const one = new One({ a1: [], a2: [1, 2, 3, 4, 5] });
*
* const view = new View(one, { a1: 'push', a2: 'shift' })
* // push one array and simultaneously shift the other
* // to transfer content...
*
* view.call({ [args]: one.many.a2 })
*
* @param one
* @param map
*/
many: any[];
constructor(one: One<T>, map: IViewMap<T>);
get(): {};
set(what: any): One<T>;
delete(): One<T>;
call(what: any): {};
}
declare class One<T extends IObject> {
many: T;
/**
* Optionally set main item interpreted specially when the one is
* proxied.
* Creates a single object that propagates actions on it to multiple objects.
*
* @example
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
*
* // set the same value on all objects
* o1.set({ p1: 78 });
*
* @param many
*/
mainItem?: number;
constructor(many: T);
/**
* Whether this One will return other 'One's in calls to `get`.
* Joins `many` with `this.many` and returns `this`. The benefit of
* using this function instead of something like `Object.assign` is to handle some
* special cases and ensure that the updated `One` is (almost) correctly typed during
* development.
*
* If the same key exists in the joined objects, the new one will overwrite the
* current one, except if the current value is a `One` instance when `extend` will
* be called on it instead.
*
* @example
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* const o2 = o1.extend({ fourth });
* // One({ first, second, third, fourth })
*
* @param many
*/
recursive?: boolean;
extend<U extends object>(many: U): One<IExtend<T, U>>;
/**
* The constructor function used for creating new 'One's in calls to `get`.
* The opposite of extend. Removes the specified keys from `this.many` and
* returns `this` typed differently.
*
* @example
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* const o2 = o1.contract('first', 'third');
* // One({ second })
*
* @param keys
* @returns
*/
ctor?: IOneConstructor;
contract<U extends keyof T>(...keys: U[]): One<Omit<T, U>>;
/**
* The context shared by the many functions or methods of the objects in many.
* They all receive its items as their last set of arguments.
*/
context?: any[];
/**
* Creates a new One instance for propagating operations to all the items
* in many.
* Creates and returns another instance of `One` containing only the
* objects with these names. If a name is not present in `this.many`,
* a new object is created for it in the returned `One`.
*
* @param {any[]} many The many objects or functions this One will delegate to.
* @param {boolean} [recursive] Whether to wrap the arrays returned by `get` with another One.
* @param {any[]} context An optional shared context to be passed to all propagated method or function calls.
* This is an array of objects passed as the final arguments in calls. Empty array by default.
*
* @example
* import { One } from 'deleight/onetomany';
* const loginYes = new One([username => profileView(username)]);
* loginYes.call([[username]]);
* import { One } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* const o2 = o1.slice('first', 'second')
* // One({ first, second })
*
* @constructor
* @param names
*/
constructor(many: any[], recursive?: boolean, context?: any[]);
slice(...names: (keyof T)[]): One<IObject>;
/**
* Gets corresponding properties from all the objects in many. If this is
* a recursive One and forceArray is falsy, the array result will be
* used as the 'many' argument in a call to this.ctor and the created One
* is returned instead of the array.
* Creates and returns an instance of `View` for only the
* specified properties. `what` is an object mapping object keys (in `this.many`)
* to the property names.
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.get('a'); // [1, 2]
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex } });
* o1.view({first: 'p1', second: 'p2'});
* view.get(); // { first: 78, second: 12 }
*
* @param {string | number | symbol | null} [prop]
* @param {boolean} [forceArray]
* @returns {any[]|One}
* @param map
*/
get(prop?: string | number | symbol | null, forceArray?: boolean): any[] | One;
view(map: IViewMap<T>): View<T>;
/**
* Sets corresponding property values in the objects in many.
* 'values' are treated similarly to 'args' in the call method.
* Gets the property (or properties) with the specified name(s) from all the
* objects in `this.many`.
*
* 1. if `what` is a string, returns only the property specified (as an object mapping
* object key to property value).
* 2. if `what` is an array of strings, returns 'sub-objects' of all the objects
* consisting of the specified property names (also mapped like 1).
* 3. if what is an object, it is treated as a map of object names to property
* name(s) to return.
* 4. if an object in `this.many` is a `One` instance, its `get` method is
* called for its property value(s).
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.set('a', [4, 7]);
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex } });
*
* @param {string | number | symbol | null} [prop]
* @param {any[]} [values]
* o1.get('p1');
* // { first: 78, second: 78, third: 78 }
*
* o1.get('p1', 'p2');
* // { first: { p1: 78, p2: 56 }, second: { p1: 78, p2: 12 }, third: { p1: 78, p2: 12 } }
*
* o1.get({ first: 'p2', second: 'p1' });
* // { first: 56, second: 78 }
*
* @param what
*/
set(prop?: string | number | symbol | null, values?: any[]): any;
get(what: (IKey) | IKey[] | IKeyObject<T>, valueKey?: IKey): {};
/**
* Delete the property from all objects in many.
* Sets one or more properties on all the objects in this instance.
* `what` is an object mapping property names to property values.
*
* Each value in `what` is set on all the objects in this `One`.
* The same value will be set unless the value is an object containing the `[map]` property.
* In such a case, the value of the property is treated as a map of object key (in `this.many`)
* to object property value. That is, the objects with corresponding
* keys will have their property values set to the corresponding values.
*
* This will call `set` on any nested `One` objects accordingly.
*
* @example
* import { One } from 'deleight/onetomany';
* const o = new One([{a: 1}, {a: 2}])
* o.delete('a');
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex }, p3: complex });
*
* @param {string | number | symbol} prop
* o1.get('p2', 'p3');
* // { first: { p2: 56, p3: complex }, second: { p2: 12, p3: complex }, third: { p2: 12, p3: complex } }
*
* @param what
*/
delete(prop: string | number | symbol): void;
set(what: IObject, valueKey?: IKey): this;
/**
* Calls all the items in many (if method is not specified) or their
* corresponding methods (if method is specified). All the calls will
* receive any items in `this.context` as their final arguments to
* enable communication.
* Performs `delete` on the objects in this `One`. The argument is
* treated the same way as in `get`.
*
* args can be specified as follows:
* `[[a1, a2], [a1, a2], [a1, a2]]`
* @example
* import { One, map } from "deleight/onetomany";
* const first = {}, second = {}, third = {}, fourth = {};
* const many = { first, second, third };
* const o1 = new One(many);
* o1.set({ p1: 78 });
* const complex = { first: 56, second: 12, third: 12 };
* o1.set({ p2: { [map]: complex }, p3: complex });
*
* If `this.many` has 3 items, they will receive their own args. If there
* are more items in `this.many`, they will all get the last provided args array
* (here the one passed to the third item).
* o1.delete('p1', 'p2');
* // One({ first: { p3: complex }, second: { p3: complex }, third: { p3: complex } })
*
* The `one` function wraps created 'One's with a proxy to allow methods
* to be called directly on them. Assuming we want to pass the same args
* as above to such a method, the call will look like:
* @param what
*/
delete(what: (IKey) | IKey[] | IKeyObject<T>): this;
/**
* Calls corresponding methods in a similar way to set. In this
* case, call arguments are interpreted instead of property values.
*
* `object.method([a1, a2], [a1, a2], [a1, a2])`.
* Multiple arguments should be provided as an object with the `[arg]` property whose value
* should be an array containing the arguments. A regular array is considered a single argument.
*
* There is no need to wrap with the outer array in such cases.
* Nested one objects will have their call method invoked correspondingly.
*
* Call returns an array containing the return values of the individual
* calls to many items.
*
* @example
* import { One } from 'deleight/onetomany';
* const loginYes = new One([username => profileView(username)]);
* loginYes.call([[username]]);
* import { One, map, args } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const o4 = new One({ arr1, arr2, arr3 });
* o4.call({ push: 78 });
* o4.call({ push: { [args]: [56, 57] } });
* // arr1 = arr2 = arr3 = [78, 56, 57]
*
* @param {any[]} args The function or method arguments
* @param {string | number | symbol} [method] The name of a method to call.
* A function call is assumed if not specified.
*
* @returns {any[]}
* @param what
*/
call(args?: any[], method?: string | number | symbol): any[];
call(what: string | string[] | IObject): {};
}
/**
* A simple wrapper around `One` for a more concise syntax.
*
* @example
* import { one, map, args } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const o4 = one({ arr1, arr2, arr3 });
* o4.push(78, 56, 57);
* o4.push({ [map]: { arr1: 66, arr2: { [args]: [77, 88] }, arr3: 99 } });
* // arr1 === [78, 56, 57, 66]
* // arr2 === [78, 56, 57, 77, 88]
* // arr3 === [78, 56, 57, 99]
*
* @param many
* @returns
*/
declare function one<T extends object>(many: T): T[keyof T];
/**
* Wraps a pre-existing `One`
*
* @example
* import { One, wrap } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const o4 = new One({ arr1, arr2, arr3 });
* const wo4 = wrap(o4);
*
* @param one
* @returns
*/
declare function wrap<T>(one: One<T>): T[keyof T];
/**
* The opposite of `wrap`
*
* @example
* import { one, unwrap } from "deleight/onetomany";
* const arr1 = [], arr2 = [], arr3 = [];
* const wo4 = one({ arr1, arr2, arr3 });
* const o4 = unwrap(wo4);
*
* @param wrapped
* @returns
*/
declare function unwrap<T>(wrapped: any): One<T>;
export { type IOneConstructor, One, one, unWrap, wrap };
export { type IExtend, type IKey, type IKeyObject, type ILike, type IObject, type IViewMap, One, View, args, map, one, unwrap, wrap };

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

function t(e,n,i,s){const c=new o(e,n,i);return c.ctor=t,void 0!==s&&(c.mainItem=s),new Proxy(c,r)}const e=Symbol();function n(e,n){return e.ctor=t,void 0!==n&&(e.mainItem=n),new Proxy(e,r)}function i(t){return t[e]||t}const r={get(t,n){if(n===e)return t;let i=t.get(n,!0);if(i.length&&"function"==typeof i[0])return void 0!==t.mainItem?(...e)=>t.call([e],n)[t.mainItem]:(...e)=>t.call(e,n);if(t.recursive){if(t.ctor){const n=t.ctor(i,!0,t.context);return(n[e]||n).ctor=t.ctor,n}return new o(i,!0,t.context)}return void 0!==t.mainItem?i[t.mainItem]:i},set:(t,e,n)=>(t.set(e,n),!0)};class o{many;mainItem;recursive;ctor;context;constructor(t,e,n){this.many=t,this.recursive=e,this.context=n||[]}get(t,n){const i=[],r=this.many.length;if(null!=t)for(let e=0;e<r;e++)i.push(this.many[e][t]);else for(let t=0;t<r;t++)i.push(this.many[t]);if(!this.recursive||n)return i;if(!this.ctor)return new o(i,this.recursive,this.context);{const t=this.ctor(i,this.recursive,this.context);(t[e]||t).ctor=this.ctor}}set(t,e){if(void 0===e)return this.set(t,this.get(t,!0));e instanceof Array||(e=[e]);const n=this.many.length,i=e.length;if(null!=t)for(let r=0;r<n;r++)this.many[r][t]=e[Math.min(r,i-1)];else for(let t=0;t<n;t++)this.many[t]=e[Math.min(t,i-1)]}delete(t){for(let e of this.many)delete e[t]}call(t,e){void 0!==t&&t.length||(t=[[]]);const n=[],i=this.many.length,r=t.length;let o,s;if(void 0!==e)for(let c=0;c<i;c++)o=t[Math.min(c,r-1)]||[],s=this.many[c][e](...o,...this.context),n.push(s);else for(let e=0;e<i;e++)o=t[Math.min(e,r-1)]||[],s=this.many[e](...o,...this.context),n.push(s);return n}}export{o as One,t as one,i as unWrap,n as wrap};
const e=Symbol(),t=Symbol();class n{one;map;constructor(e,t){this.one=e,this.map=t}#e(t){const n={};if(t.hasOwnProperty(e)){let s;for(let[r,o]of Object.entries(t[e]))s=this.map[r],n.hasOwnProperty(s)||(n[s]={[e]:{}}),n[s][e][r]=o}else for(let[s,r]of Object.entries(this.map))n[r]={[e]:{[s]:t}};return n}get(){return this.one.get(this.map)}set(e){return this.one.set(this.#e(e))}delete(){return this.one.delete(this.map)}call(e){return this.one.call(this.#e(e))}}class s{many;constructor(e){this.many=e}extend(e){let t;for(let[n,r]of Object.entries(e))this.many.hasOwnProperty(n)?(t=this.many[n],t instanceof s?t.extend(r):this.many[n]=r):this.many[n]=r;return this}contract(...e){for(let t of e)delete this.many[t];return this}slice(...e){const t={};for(let n of e)t[n]=this.many[n]||{};return new s(t)}view(e){return new n(this,e)}get(e,t){const n={};let r,o,i,f,a;if("string"==typeof e)for([o,f]of Object.entries(this.many))f instanceof s?n[o]=f.get(e,t):(r=f[e],t&&r instanceof s&&(r=r.many[t]),n[o]=r);else if(e instanceof Array)for([o,f]of Object.entries(this.many))if(f instanceof s)n[o]=f.get(e,t);else for(i of(n[o]=r={},e))a=f[i],t&&a instanceof s&&(a=a.many[t]),r[i]=a;else if("object"==typeof e)for(let[o,c]of Object.entries(e))if(f=this.many[o],f instanceof s)n[o]=f.get(c,t);else if(c instanceof Array)for(i of(n[o]=r={},c))a=f[i],t&&a instanceof s&&(a=a.many[t]),r[i]=a;else r=f[c],t&&r instanceof s&&(r=r.many[t]),n[o]=r;return n}set(t,n){let r,o,i,f;for(let[a,c]of Object.entries(t))if(c.hasOwnProperty(e))for([r,i]of Object.entries(c[e]))o=this.many[r],o instanceof s?o.set({prop:i},n):n?(f=o[a],f instanceof s&&f.many.hasOwnProperty(n)&&(f.many[n]=i)):o[a]=i;else for([r,o]of Object.entries(this.many))o instanceof s?o.set({prop:c},n):n?(f=o[a],f instanceof s&&f.many.hasOwnProperty(n)&&(f.many[n]=c)):o[a]=c;return this}delete(e){let t,n,r;if("string"==typeof e)for([t,r]of Object.entries(this.many))r instanceof s?r.delete(e):delete r[e];else if(e instanceof Array)for([t,r]of Object.entries(this.many))if(r instanceof s)r.delete(e);else for(n of e)delete r[n];else if("object"==typeof e)for(let[t,o]of Object.entries(e))if(r=this.many[t],r instanceof s)r.delete(o);else if(o instanceof Array)for(n of o)delete r[n];else delete r[o];return this}call(n){let r,o,i;const f={};let a;if("string"==typeof n&&(n=[n]),n instanceof Array)for(let e of n)for([r,o]of Object.entries(this.many))f[r]=o[e]?.();else for(let[c,l]of Object.entries(n))if(f[c]=a={},l.hasOwnProperty(e))for([r,i]of Object.entries(l[e]))o=this.many[r],o instanceof s?a[r]=o.call({prop:i}):i.hasOwnProperty(t)?a[r]=o[c]?.(...i[t]):a[r]=o[c]?.(i);else for([r,o]of Object.entries(this.many))o instanceof s?a[r]=o.call({prop:l}):l.hasOwnProperty(t)?a[r]=o[c]?.(...l[t]):a[r]=o[c]?.(l);return f}}function r(e){return o(new s(e))}function o(e){return new Proxy(e,a)}function i(e){return e[f]}const f=Symbol(),a={get:(n,s)=>s===f?n:Object.assign(((...r)=>{let o;return 1===r.length&&"object"==typeof(o=r[0])&&o.hasOwnProperty(e)?n.call({[s]:o}):n.call({[s]:{[t]:r}})}),{get value(){return n.get(s)}}),set:(e,t,n)=>(e.set({[t]:n}),!0),deleteProperty:(e,t)=>(e.delete(t),!0)};export{s as One,n as View,t as args,e as map,r as one,i as unwrap,o as wrap};
{
"name": "deleight",
"version": "1.3.4",
"description": "A group of 8 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.",
"version": "2.0.0",
"description": "A group of 10 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.",
"type": "module",
"exports": {
"./reftype": {
"require": "./dist/reftype/cjs/reftype.js",
"default": "./dist/reftype/esm/reftype.js"
},
"./appliance": {

@@ -15,5 +19,5 @@ "require": "./dist/appliance/cjs/appliance.js",

},
"./eventivity": {
"require": "./dist/eventivity/cjs/eventivity.js",
"default": "./dist/eventivity/esm/eventivity.js"
"./eutility": {
"require": "./dist/eutility/cjs/eutility.js",
"default": "./dist/eutility/esm/eutility.js"
},

@@ -32,5 +36,5 @@ "./generational": {

},
"./domitory": {
"require": "./dist/domitory/cjs/domitory.js",
"default": "./dist/domitory/esm/domitory.js"
"./queryoperator": {
"require": "./dist/queryoperator/cjs/queryoperator.js",
"default": "./dist/queryoperator/esm/queryoperator.js"
},

@@ -41,5 +45,5 @@ "./onetomany": {

},
"./withy": {
"require": "./dist/withy/cjs/withy.js",
"default": "./dist/withy/esm/withy.js"
"./withly": {
"require": "./dist/withly/cjs/withly.js",
"default": "./dist/withly/esm/withly.js"
}

@@ -71,11 +75,12 @@ },

"Deleight",
"Actribute",
"Appliance",
"Reftype",
"QueryOperator",
"Sophistry",
"Apriori",
"Eventivity",
"Sophistry",
"OneToMany",
"Appliance",
"Domitory",
"Actribute",
"Generational",
"withy"
"Eutility",
"withly"
],

@@ -82,0 +87,0 @@ "author": "Mark Sun",

@@ -5,11 +5,11 @@ # Deleight

This is a group of 9 libraies that simplify web frontend development in vanilla HTML, CSS and JavasSript. Deleight is an inclusive library that everyone operating on the web can benefit from.
This is now a group of 10 libraies that simplify web frontend development in vanilla HTML, CSS and JavasSript. Deleight is an inclusive library that everyone operating on the web can benefit from.
- Frontend JavaScript developers can create apps without worrying about control, modularity or maintainance. Not only is the framework flexible, modular and compact, it also aligns with familiar semantics. You also have the convenience of a declarative API.
- Frontend JavaScript developers can create apps without worrying about control, modularity or maintainance. Not only is the framework flexible, modular and compact, it also aligns with familiar semantics. Plus you have multiple declarative APIs to choose from.
- Distributed frontend teams can work freely in their favourite languages without worrying about interop. HTML experts can write pure HTML. JavaScript developers can write pure JavaScript. Designers can write pure CSS. Deleight will ensure that everything plays well together.
- Back-end developers using any technology can stop worrying about front-end complexity. Deleight ships modern ES6 modules which can be loaded directly into webpages. Because the framework is modular and compact, you only load the libraries you need into your pages. You can also compose them with your favourite back-end template engines to reduce the number of files to load. Finally, the [API](https://mksunny1.github.io/deleight-api-docs/main) is small and natural; it is very easy to pick up in a few hours.
- Backend developers using any technology can stop worrying about frontend complexity. Deleight ships modern ES6 modules which can be loaded directly into a webpage. Because the framework is modular and compact, you only load the libraries you need. You can also compose them with your favourite backend template engine to reduce the number of files to load. Finally, we try tom make the [API](https://mksunny1.github.io/deleight-api-docs/main) small and intuitive. There is not much to learn.
Apart from this brief guide and the [API](https://mksunny1.github.io/deleight-api-docs/main) documentation, there are also some examples which can be used to understand how the parts fit together and to develop a feel for using deleight. To play with the exmples, you can run the included server with `npm start` and visit http://localhost:8000/docs/examples/index.html. The demos are also hosted online [here](https://mksunny1.github.io/deleight/docs/examples).
Apart from this brief guide and the [documentation](https://mksunny1.github.io/deleight-api-docs/main), there are also some examples which can be used to understand how the parts fit together and to develop a feel for using deleight. To play with the exmples, you can run the included server with `npm start` and visit http://localhost:8000/docs/examples/index.html. The demos are also hosted online [here](https://mksunny1.github.io/deleight/docs/examples).

@@ -19,17 +19,35 @@ What follows is a brief description of the libraries and how to include them in your projects.

## Appliance
## Reftype
Appliance provides a powerful declarative API for manipulating the DOM and for structuring code in JavaScript. It can be used to attach behavior to HTML elements easily and efficiently. It is like custom elements without the DOM building aspects. Here the elements may already exist in the DOM. This can produce big gains in accessibility and flexibility as DOM can be built server-side or client-side using any technology of choice. This can also increase efficient=cy because all the elements can be set up in one call. When used in tandem with other primitives from `actribute`, `domitory` and `onetomany`, appiance will match and exceed advanced 'framework' functionality, like data-binding, state management and lifecycle hooks. Hydration is natural.
*Reftype* is the latest library in the stack. The main purpose is to relieve the burden on the JavaScript programmer to know about the markup layout and structure in a large web application. Without *Reftype*, we manipulate all aspects of the DOM explicitly with high-level primitives from Javascript. We may get some mileage from *Actribute* but the module is more abstract.
*Reftype* provides an alternative pattern quite similar to how *Vue.JS* and *Angular* operate. It lets you declaratively describe DOM operations using attribute directives. The major difference with *Reftype* is that it is more transparent, explicit and composable. It aligns with the policy of *Deleight* to use straight HTML, CSS and JavaScript. It is deliberately designed to be fast, lightweight and memory-efficient.
```html
<main>
<p t> mercury +&+ venus </p>
<p t> mercury + or +venus</p>
<p t>mercury + before + venus</p>
<section t>earth</section>
<article t class-a="color1| |color2">mars</article>
</main>
```
```js
import { apply } from 'deleight/appliance'
import { mySophistry } from './my-style-manager.js'
import { meEventivity } from './my-event-manager.js'
import { RefType } from 'deleight/reftype'
// apply used globally on all divs within the containingElement
function(containingElement) {
apply({
div: (...divs) => mySophistry.styles.style(...divs) || meEventivity.listener.listen('click', divs, myEventivity.options)
}, containingElement); // containingElement default to document.body.
}
const refs = {
mercury: 'Planet mercury',
venus: 'The second planet',
earth: 'Our planet!',
mars: 'Nearest planetary neighbor',
color1: 'red',
color2: 'green'
};
const reftype = new RefType(refs, { sep: { multivalue: '+' } });
reftype.add(document.querySelector('main'));
reftype.react(); // will apply all reactions
reftype.set({ color1: 'blue' }); // will apply specific reaction...
```

@@ -40,3 +58,3 @@

Actribute is a versatile library for associating element attributes with JavaScript code. In one instance it can be used as a more widely supported, flexible and powerful alternative to extending built-in HTML elements, using a similar API. In another, it can be used to establish conventions for automatically manipulating the DOM. Think about directives in Angular or Vue.
*Actribute* is a versatile library for associating element attributes with JavaScript code. In one instance it can be used as a more widely supported, flexible and powerful alternative to extending built-in HTML elements, exposing a similar API. In another, it can be used to establish conventions for manipulating the DOM. The library also has some notable enhancements including the ability to join or recurse components.

@@ -53,10 +71,14 @@ ```js

// register components:
act.register('comp1', (element, attr, ...context) => element.textContent = props(attr.value, context)[0]);
act.register('comp2', (element, attr) => element.style.left = attr.value);
// use in markup:
// &lt;section c-comp1="prop1" c-comp2="100px" &gt;
// First section
// &lt;/section&gt;
const comp1 = (element, attr, ...context) => element.textContent = props(attr.value, context)[0]);
const comp2 = (element, attr) => element.style.left = attr.value;
act.register({ comp1, comp2 })
```
```html
<section c-comp1="prop1" c-comp2="100px" >
First section
</section>
```
```js
// process components:

@@ -69,72 +91,46 @@ act.process({el: document.body, ctx: [{prop1: 2, prop3: 2}, fallbackProps]});

## Appliance
## Domitory
*Appliance* provides another declarative API for manipulating the DOM and for structuring code in JavaScript. It can be used to attach behavior to HTML elements easily and efficiently. It is like custom elements without the DOM building aspects. Here the elements may already exist in the DOM. This can produce big gains in accessibility and flexibility as DOM can be built server-side or client-side using any technology of choice. This can also increase efficiency because all the elements can be set up in one call.
This provides a painless SQLesque API for manipulating the DOM. The library exports `insert`, `set`, `update` and `remove` functions for bulk manipulation of things on the DOM. It is an efficient, consistent and simple API to use. See the examples and the API docs.
```js
import { apply } from 'deleight/appliance'
import { set } from 'deleight/domitory'
import { range } from 'deleight/generational'
import { mySophistry } from './my-style-manager.js'
import { myEutility } from './my-event-manager.js'
// set the text content of all selected div elements to its position in the array. We can set as many properties or attributes as we want at once.
function(containingElement) {
// apply used globally on all divs within the componentElement
function(componentElement) {
apply({
div: (...divs) => set(divs, {textContent: range(divs.length)})
}, containingElement);
div: (...divs) => mySophistry.styles.style(...divs) || myEutility.listener.listen('click', divs, myEutility.options)
}, componentElement); // componentElement defaults to document.body.
}
```
## Queryoperator
## Eventivity
This provides a painless SQLesque API for manipulating the DOM. The library exports `insert`, `set`, `update` and `remove` functions for bulk manipulation of things on the DOM. It is an efficient, consistent and simple API to use. See the examples and the API docs.
This library provides some useful primitives for simiplifying the code that must be included in every page where JavaScript is used to support interactivity. Most JavaScript code can only run in response to an event. Eventivity exports functions for:
- composing event handlers
- creating *lazy* handlers whose functionality can be injected later
- promoting handler reuse with different elements
- creating fewer event handlers by taking advantage of event bubbling
- disabling event firing until a running handler completes and all their promises get resolved.
- creating handlers for specific key events, like enter.
- creating reusable handler guards to stop event handling at any point.
- etc.
```js
import { EventListener } from 'deleight/eventivity'
import { set } from 'deleight/queryoperator'
import { range } from 'deleight/generational'
export const myEventivity = {
listener: new EventListener((e, runContext) => console.log({e.target, runContext}))
};
// set the text content of all selected div elements to its position in the array. We can set as many properties or attributes as we want at once.
function(componentElement) {
const links = componentElement.querySelectorAll('a');
const indices = [...range(links.length)]
set(links, { textContent: indices , _href: indices.map(i => `./page/${i}.html`) });
}
```
## OneToMany
OneToMany exports primitives to manipulate many objects simultaneously. There are methods for getting and setting properties and invoking functions and object methods. The library is simple, concise, explicit and transparent.
```js
import { One, one } from "deleight/onetomany";
const arr1 = [1, 2, 3, 4, 5];
const arr2 = ["a", "b", "c", "d"];
// not compulsory to have the same length
export const oneArray = new One([arr1, arr2]);
oneArray.many.unshift([true, true, false]);
// you can add or remove arrays later using its 'many' property
const wrappedOneArray = one([arr1, arr2]);
wrappedOneArray.push([6], ["e"]);
// wrapping enables shorthand syntax like this.
```
## Apriori
This is a fun library to use if you need to build part or all of your DOM with the help of JavaScript. It includes primitives for template creation, template rendering and document tree building. There are tools for building the DOM from in-page resources or dynamically loaded ones. This gives us the flexibility to choose whatever works best for a project.
This is a fun library to use if you need to build DOM with JavaScript. It includes primitives for template creation, template rendering and document tree building. There are tools for building DOM from in-page resources or dynamically loaded ones. This gives us the flexibility to choose whatever works best for a project.
```js
import { get, template } from "deleight/apriori";
export const myTemplate = template(await get("markup.html"));
const myTemplate = template(await get("markup.html"));
function(componentElement, ...args) {
componentElement.insertAdjacentHTML('beforeend', myTemplate(...args));
}
```

@@ -145,4 +141,6 @@

Styling is a crucial aspect of most pages on the web. We need to make the pages beautiful and improve the UX for visual users. CSS is easy to include globally in any page. However, when localising styles with Shadow DOM, one currently has to make the decision between writing duplicitive declarative styles vs writing JavaScript boilerplate to manage styles efficiently. Sophistry will help with efficiently scoping declaratively written styles to specific elements. The library provides an API which simplifies the code needed for such scoping. It will internally create open shadow roots where necessary. it maintains a cache to avoid reloading or re-processing the same styles (unless we request). Sophistry can also draw styles from anywhere.
Styling is a crucial aspect of most pages on the web. We need to make the pages beautiful and improve the UX for visual users. CSS is easy to include globally in any page, but when localising styles with Shadow DOM, one currently has to decide between writing duplicitive declarative styles vs writing JavaScript boilerplate to manage styles efficiently.
*Sophistry* enables efficiently scoping of declaratively written styles to specific elements. The library provides an API which simplifies the code needed for such. It will internally create open shadow roots where necessary. it maintains a cache to avoid reloading or re-processing the same styles (unless we request). *Sophistry* can draw styles from anywhere.
```js

@@ -157,3 +155,3 @@ import { Sophistry } from "deleight/sophistry";

Generational exports some useful generators to improve performance and reduce memory footprint. The `range` and `items` generators have been especially useful in the examples. They may not work in many places where arrays are expected because we can only iterate them once. Thus they should be used with caution. When in doubt, use an array.
*Generational* exports some useful generators to improve performance and reduce memory footprint. The `range` and `items` generators have been especially useful in the examples. They may not work in many places where an array is expected because we can only iterate them once. Thus they should be used with caution. When in doubt, use an array.

@@ -170,3 +168,3 @@ ```js

## Withy
## Withly

@@ -178,9 +176,60 @@ We are bringing `with` back to JavaScript with the help of Proxies. This functionality was removed from the language

```js
import { With, SET } from "deleight/withy";
import { With, SET } from "deleight/withly";
With(document.createElement('button'))[SET]({
textContent: 'Wow!', className: 'main'
})(btm => document.body.append(btn));
})(btm => document.body.appendChild(btn));
```
## OneToMany
*OneToMany* exports primitives to manipulate many objects simultaneously. There are methods for getting and setting properties and invoking object methods. It provides a potentially more extensible alternative to functions, although presently it is less performant and the usage pattern is not quite as natural.
```js
import { One, wrap, args } from "deleight/onetomany";
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [6, 7, 8, 9];
// not compulsory to have the same length
export const oneArray = new One({arr1, arr2});
oneArray.extend({arr3: [10, 11, 12]});
// you can add or remove objects later with `extend()` or `contract()`
oneArray.call( { push: 50 })
// push 50 to all the arrays
oneArray.call( { push: { [args]: [51, 52, 53, 54] } } )
// push 51-54 to all the arrays.
const wrappedOneArray = wrap(oneArray);
wrappedOneArray.push(99, 100, 101, 102, 103, 104);
// wrapping enables shorthand syntax like this.
```
## Eutility
This library provides some useful primitives for simiplifying the code that will likely be included in many simple pages where JavaScript is used to support interactivity. Most JavaScript code can only run in response to an event. *Eutility* exports functions for:
- composing event handlers
- creating *lazy* handlers whose functionality can be injected later
- promoting handler reuse with different elements
- creating fewer event handlers by taking advantage of event bubbling
- disabling event firing until a running handler completes and all their promises get resolved.
- creating handlers for specific key events, like enter.
- creating reusable handler guards to stop event handling at any point.
- etc.
```js
import { EventListener } from 'deleight/eutility'
export const myEutility = {
listener: new EventListener((e, runContext) => console.log({e.target, runContext}))
};
```
## Installation

@@ -207,4 +256,4 @@

```js
import { apply } from "./deleight/src/appliance.js";
import { One } from "./deleight/src/onetomany.js";
import { apply } from "./deleight/src/reftype.js";
import { One } from "./deleight/src/actribute.js";
// ...

@@ -216,4 +265,4 @@ ```

```js
import { apply } from "deleight/appliance";
import { One } from "deleight/onetomany";
import { apply } from "deleight/reftype";
import { One } from "deleight/actribute";
// ...

@@ -224,3 +273,3 @@ ```

If you like the concept and/or the direction of deleight, feel free to contribute to this project. We are accepting contributions in many areas. Sponsorship, issues, pull requests, benchmarks, picking up tickets, discussions, questions, examples; all are welcome. We only request that everyone maintains a positive disposition about this and about each-other.
If you like the concept and/or the direction of deleight, feel free to contribute to this project. We are accepting contributions in many areas. Sponsorship, issues, pull requests, benchmarks, testing, CI, examples; all are welcome. We only ask that everyone maintains a positive disposition about this and about each-other.

@@ -231,7 +280,6 @@ Thank you for contributing.

1. Complete testing on the tenth library (`reftype`) for referring to JavaScript variables directly in pure HTML. Everything is still transparent and explicit.
2. Complete the site (deleightjs.com).
3. Complete and add more examples.
4. Improve the documentation.
5. Fix the logo...
1. Complete the site (*deleightjs.com*).
2. Complete and add more examples.
3. Improve the documentation.
4. Fix the logo...

@@ -241,3 +289,3 @@ ## Ideas

- Progressive Web Apps.
- Efficient navigation library (not a router).
- Efficient navigation library.
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