wraplet 1.0.0-beta.22 → 1.0.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,3 +3,5 @@
3
3
  [![Tests](https://github.com/wraplet/wraplet/actions/workflows/main.yml/badge.svg)](https://github.com/wraplet/wraplet/actions/workflows/main.yml)
4
4
 
5
5
  An object-oriented framework giving your JS/TS code structure.
6
+
7
+ Documentation: https://wraplet.dev
@@ -11,7 +11,6 @@ import { DDMStatus } from "./types/DDMStatus";
11
11
  export declare class DDM<N extends Node = Node, M extends WrapletDependencyMap = {}> implements DependencyManager<N, M> {
12
12
  node: N;
13
13
  [DependencyManagerSymbol]: true;
14
- private logger;
15
14
  private dependenciesAreInstantiated;
16
15
  private initializePromise;
17
16
  private destroyPromise;
@@ -1,10 +1,8 @@
1
1
  import { WrapletDependencyMap } from "../../Wraplet/types/WrapletDependencyMap";
2
2
  import { DependencyLifecycleAsyncListener } from "./DependencyLifecycleAsyncListener";
3
3
  import { DependencyLifecycleListener } from "./DependencyLifecycleListener";
4
- import { Logger } from "../../Logger/types/Logger";
5
4
  export type DDMOptions<M extends WrapletDependencyMap = WrapletDependencyMap> = {
6
5
  dependencyInstantiatedListeners?: Map<keyof M, DependencyLifecycleListener<M, keyof M>[]>;
7
6
  dependencyInitializedListeners?: Map<keyof M, DependencyLifecycleAsyncListener<M, keyof M>[]>;
8
7
  dependencyDestroyedListeners?: Map<keyof M, DependencyLifecycleAsyncListener<M, keyof M>[]>;
9
- logger?: Logger;
10
8
  };
@@ -4,6 +4,6 @@ export declare function isParentNode(node: Node): node is ParentNode;
4
4
  export declare function getWrapletsFromNode<N extends Node = Node>(node: N): WrapletSet | null;
5
5
  export declare function removeWrapletFromNode<N extends Node>(wraplet: Wraplet, node: N): boolean;
6
6
  export declare function addWrapletToNode<N extends Node>(wraplet: Wraplet, node: N): void;
7
- export declare function actOnNodesRecursively(node: Node, callback: (node: Node) => void): Promise<void>;
7
+ export declare function actOnNodesRecursively(node: Node, callback: (node: Node) => void): void;
8
8
  export declare function findWrapletsOutsideTheTree(wraplets: Wraplet[], node: Node): Promise<Wraplet[]>;
9
9
  export declare function destroyWrapletsRecursively(node: Node): Promise<void>;
@@ -1,11 +1,10 @@
1
- import { Wraplet, WrapletSymbol } from "./types/Wraplet";
1
+ import { Wraplet } from "./types/Wraplet";
2
2
  import { Constructable } from "../utils/types/Utils";
3
3
  import { NodeManager } from "./NodeManager";
4
4
  import { WrapletApi } from "./types/WrapletApi";
5
5
  import { WrapletApiFactoryBasicCallback } from "./types/WrapletApiFactoryCallbacks";
6
6
  export declare abstract class AbstractWraplet<N extends Node = Node> implements Wraplet {
7
7
  protected node: N;
8
- [WrapletSymbol]: true;
9
8
  wraplet: WrapletApi;
10
9
  private _nodeManager;
11
10
  constructor(node: N);
@@ -1,7 +1,5 @@
1
1
  import { WrapletApi } from "./WrapletApi";
2
- export declare const WrapletSymbol: unique symbol;
3
2
  export interface Wraplet {
4
- [WrapletSymbol]: true;
5
3
  wraplet: WrapletApi;
6
4
  }
7
- export declare function isWraplet(object: unknown): object is Wraplet;
5
+ export declare function isWraplet(value: unknown): value is Wraplet;
package/dist/ambient.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  class DDM<N extends Node = Node, M extends WrapletDependencyMap = {}> implements DependencyManager<N, M> {
2
2
  node: N;
3
3
  [DependencyManagerSymbol]: true;
4
- private logger;
5
4
  private dependenciesAreInstantiated;
6
5
  private initializePromise;
7
6
  private destroyPromise;
@@ -73,7 +72,6 @@ type DDMOptions<M extends WrapletDependencyMap = WrapletDependencyMap> = {
73
72
  dependencyInstantiatedListeners?: Map<keyof M, DependencyLifecycleListener<M, keyof M>[]>;
74
73
  dependencyInitializedListeners?: Map<keyof M, DependencyLifecycleAsyncListener<M, keyof M>[]>;
75
74
  dependencyDestroyedListeners?: Map<keyof M, DependencyLifecycleAsyncListener<M, keyof M>[]>;
76
- logger?: Logger;
77
75
  };
78
76
  interface DDMStatus {
79
77
  isInitialized: boolean;
@@ -156,15 +154,6 @@ type Injector<N extends Node = Node, M extends WrapletDependencyMap = WrapletDep
156
154
  data?: D;
157
155
  callback: (node: N, map: MapTreeBuilder<M>, data?: D) => unknown;
158
156
  };
159
- class ConsoleLogger implements Logger {
160
- #private;
161
- private constructor();
162
- dumpError(error: Error): void;
163
- static getGlobalLogger(): Logger;
164
- }
165
- interface Logger {
166
- dumpError(error: Error): void;
167
- }
168
157
  const MapTreeBuilderSymbol: unique symbol;
169
158
  class MapTreeBuilder<M extends WrapletDependencyMap = WrapletDependencyMap> {
170
159
  private parent?;
@@ -196,7 +185,7 @@ function isParentNode(node: Node): node is ParentNode;
196
185
  function getWrapletsFromNode<N extends Node = Node>(node: N): WrapletSet | null;
197
186
  function removeWrapletFromNode<N extends Node>(wraplet: Wraplet, node: N): boolean;
198
187
  function addWrapletToNode<N extends Node>(wraplet: Wraplet, node: N): void;
199
- function actOnNodesRecursively(node: Node, callback: (node: Node) => void): Promise<void>;
188
+ function actOnNodesRecursively(node: Node, callback: (node: Node) => void): void;
200
189
  function findWrapletsOutsideTheTree(wraplets: Wraplet[], node: Node): Promise<Wraplet[]>;
201
190
  function destroyWrapletsRecursively(node: Node): Promise<void>;
202
191
  class DefaultSearchableSet<T> extends Set<T> implements BaseSet<T> {
@@ -270,7 +259,6 @@ abstract class AbstractDependentWraplet<N extends Node = Node, M extends Wraplet
270
259
  }
271
260
  abstract class AbstractWraplet<N extends Node = Node> implements Wraplet {
272
261
  protected node: N;
273
- [WrapletSymbol]: true;
274
262
  wraplet: WrapletApi;
275
263
  private _nodeManager;
276
264
  constructor(node: N);
@@ -371,12 +359,10 @@ interface Status {
371
359
  type StatusWritable = {
372
360
  -readonly [K in keyof Status]: Status[K];
373
361
  };
374
- const WrapletSymbol: unique symbol;
375
362
  interface Wraplet {
376
- [WrapletSymbol]: true;
377
363
  wraplet: WrapletApi;
378
364
  }
379
- function isWraplet(object: unknown): object is Wraplet;
365
+ function isWraplet(value: unknown): value is Wraplet;
380
366
  const WrapletApiSymbol: unique symbol;
381
367
  interface WrapletApi {
382
368
  [WrapletApiSymbol]: true;
@@ -444,10 +430,6 @@ class UnsupportedNodeTypeError extends Error {
444
430
  }
445
431
  class LifecycleError extends Error {
446
432
  }
447
- class LifecycleAsyncErrors extends Error {
448
- errors: Error[];
449
- }
450
- function createLifecycleAsyncError(message: string, results: PromiseSettledResult<any>[], throwError?: boolean): LifecycleAsyncErrors | null;
451
433
  /**
452
434
  * Generic guard.
453
435
  */
@@ -462,3 +444,4 @@ type Nullable<T> = {
462
444
  [K in keyof T]: T[K] | null;
463
445
  };
464
446
  const RESOLVE: Promise<void>;
447
+ function throwIfErrors(errors: Error[], message: string): void;
package/dist/errors.d.ts CHANGED
@@ -14,6 +14,3 @@ export declare class UnsupportedNodeTypeError extends Error {
14
14
  }
15
15
  export declare class LifecycleError extends Error {
16
16
  }
17
- export declare class LifecycleAsyncErrors extends Error {
18
- errors: Error[];
19
- }
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AbstractDependentWraplet:()=>N,AbstractWraplet:()=>$,DDM:()=>k,DNTM:()=>R,DefaultWrapletSet:()=>z,DefaultWrapletSetReadonly:()=>_,DependenciesAreNotAvailableError:()=>r,InternalLogicError:()=>o,LifecycleAsyncErrors:()=>c,LifecycleError:()=>l,MapError:()=>i,MissingRequiredDependencyError:()=>n,RequiredDependencyDestroyedError:()=>s,TooManyChildrenFoundError:()=>a,UnsupportedNodeTypeError:()=>d,WrapletSymbol:()=>h,createOuterDestroyCallback:()=>j,createOuterInitializeCallback:()=>q,createWrapletApi:()=>O,destroyWrapletsRecursively:()=>M,getWrapletsFromNode:()=>v,isWraplet:()=>u});class n extends Error{}class i extends Error{}class s extends Error{}class r extends Error{}class a extends Error{}class o extends Error{}class d extends Error{}class l extends Error{}class c extends Error{errors=[]}const p=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],h=Symbol("Wraplet");function u(e){return p(e,h)}function y(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function f(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function w(e){if(!y(e))return!1;for(const t in e){if(!y(e[t]))return!1;if(!f(e[t]))return!1}return!0}const D=Symbol("WrapletSet");function m(e){return p(e,D)}class g extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const b=Symbol("WrapletSetReadonly");class z extends g{[b]=!0;[D]=!0}function E(e,t,n=!0){const i=new c(e);for(const e of t)"rejected"===e.status&&i.errors.push(e.reason);if(0===i.errors.length)return null;if(n)throw i;return i}function I(e){return"function"==typeof e.querySelectorAll}function v(e){const t=e.wraplets;return m(t)?t:null}async function W(e,t){t(e);const n=e.childNodes;for(const e of n)await W(e,t)}async function M(e){const t=[];await W(e,e=>{const n=v(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)}),E("Some wraplets threw exceptions during destruction",await Promise.allSettled(t.map(e=>e.wraplet.destroy())))}const L=Symbol("DependencyManager");class S{static#e=new S;constructor(){}dumpError(e){console.dir(e,{depth:null})}static getGlobalLogger(){return this.#e}}function A(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const P=Symbol("MapTreeBuilder");class C{parent;[P]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new C(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=A(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}const G=Promise.resolve();class k{node;[L]=!0;logger;dependenciesAreInstantiated=!1;initializePromise=null;destroyPromise=null;syncPromise=null;status={isDestroyed:!1,isGettingDestroyed:!1,isGettingSynced:!1,isInitialized:!1,isGettingInitialized:!1};mapTree;directDependencies={};wrappedDependencies={};instantiatedDependencyListeners;initializedDependencyListeners;destroyedDependencyListeners;constructor(e,t,n={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the DDM is not a valid node.");if(w(t))this.mapTree=new C,this.mapTree.setMap(t);else{if("object"!=typeof(s=t)||null===s||!(P in s))throw new i("The map provided to the DDM is not a valid map.");this.mapTree=t}var s;const r=Object.assign(this.defaultOptions(),n);this.logger=r.logger,this.instantiatedDependencyListeners=r.dependencyInstantiatedListeners,this.initializedDependencyListeners=r.dependencyInitializedListeners,this.destroyedDependencyListeners=r.dependencyDestroyedListeners}initializeDependencies(){return this.status.isInitialized?G:(this.initializePromise||(this.initializePromise=(async()=>{try{this.status.isGettingInitialized=!0,await this.initializeDeps(),this.status.isInitialized=!0}finally{this.initializePromise=null,this.status.isGettingInitialized=!1}})()),this.initializePromise)}async initializeDeps(){const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t)return;const n=m(t)?Array.from(t):[t],i=await Promise.allSettled(n.map(async t=>{if(t.wraplet.status.isInitialized||t.wraplet.status.isGettingInitialized)return;await t.wraplet.initialize();const n=await Promise.allSettled((this.initializedDependencyListeners.get(e)||[]).map(e=>e(t)));E(`Errors in the DDM's dependency "${e}" initialize listeners.`,n)}));E(`Error at "${e}" dependency's initialization.`,i)})),t=E("Error at DDM's initialization.",e,!1);if(t)throw this.logger.dumpError(t),t}syncDependencies(){return this.syncPromise||(this.syncPromise=(async()=>{try{this.status.isGettingSynced=!0,this.instantiateDeps(!0),await this.initializeDeps(),await this.destroyDeps(!0)}finally{this.syncPromise=null,this.status.isGettingSynced=!1}})()),this.syncPromise}get map(){return this.mapTree.getMap()}instantiateDeps(e=!1){const t=this.directDependencies;if(I(this.node))for(const n in this.map){const i=this.map[n],s=i.multiple;if(this.validateMapItem(n,i),s){t[n]||(t[n]=new z);const e=t[n],s=this.instantiateMultipleDependencies(i,this.node,n);for(const t of s)e.add(t);continue}const r=this.instantiateSingleWrapletDependency(i,this.node,n);r!==t[n]&&(e&&r&&t[n]&&t[n].wraplet.destroy(),t[n]=r)}else{for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}this.dependenciesAreInstantiated=!0}}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new l("Dependencies are already instantiated.");this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.instantiateDeps(),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!m(n))throw new o("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new o("Internal logic error. Multiple instances wrapping the same element found in the DDM.");return i[0]}if(!u(n))throw new o("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,t,n){if(!e.selector)return this.directDependencies[n]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[n])throw new i("It's not possible to provide a single-type dependency manually and use selector at the same time.");const s=e.selector,r=this.findChildrenElements(s,t);if(this.validateElements(n,r,e),0===r.length)return null;if(r.length>1)throw new a(`${this.constructor.name}: More than one element was found for the "${n}" dependency. Selector used: "${s}".`);const o=r[0];return this.instantiateWrapletItem(n,e,o)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let s;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!u(i))throw new Error("Created dependency is not a Wraplet instance.");s=i}catch(n){if(n instanceof d&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,s);for(const t of this.instantiatedDependencyListeners.get(e)||[])t(s);return s}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new z;const s=this.findChildrenElements(i,t);this.validateElements(n,s,e);const r=new z;for(const t of s){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&r.add(i)}return r}addDependencyInstantiatedListener(e,t){const n=this.instantiatedDependencyListeners.get(e)||[];n.push(t),this.instantiatedDependencyListeners.set(e,n)}addDependencyInitializedListener(e,t){const n=this.initializedDependencyListeners.get(e)||[];n.push(t),this.initializedDependencyListeners.set(e,n)}addDependencyDestroyedListener(e,t){const n=this.destroyedDependencyListeners.get(e)||[];n.push(t),this.destroyedDependencyListeners.set(e,n)}setExistingInstance(e,t){if(this.map[e].multiple)throw new i("This method can only be used to set a single-value dependency.");if(!u(t))throw new i("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,t),this.directDependencies[e]=t}addExistingInstance(e,t){if(!this.map[e].multiple)throw new i("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,t);const n=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new z;n.add(t),this.directDependencies[e]=n}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=await Promise.allSettled((this.destroyedDependencyListeners.get(e)||[]).map(e=>e(t))),i=this.validateRequiredDependencyAfterRemoval(e);i&&n.push({status:"rejected",reason:i}),E(`Errors in the destruction callbacks of the "${e} dependency."`,n)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed&&null===this.directDependencies[e]?new s(`Required dependency "${e}" has been destroyed.`):null}destroyDependencies(){return this.status.isDestroyed?G:(this.destroyPromise||(this.destroyPromise=(async()=>{try{if(this.status.isGettingDestroyed=!0,this.initializePromise&&await this.initializePromise,!this.status.isInitialized)return this.status.isDestroyed=!0,void(this.status.isGettingDestroyed=!1);await this.destroyDeps(),this.status.isInitialized=!1,this.status.isDestroyed=!0}finally{this.destroyPromise=null,this.status.isGettingDestroyed=!1}})()),this.destroyPromise)}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new r("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){m(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,t){const n=t.selector,s=t.required;if(!n&&s&&(!this.directDependencies[e]||m(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new i(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,t){if(t.required)throw new i(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(e,t,i){if(0===t.length&&i.required)throw new n(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:new Map,dependencyInitializedListeners:new Map,dependencyDestroyedListeners:new Map,logger:S.getGlobalLogger()}}async destroyDeps(e=!1){const t=await Promise.allSettled(Object.entries(this.directDependencies).map(async([t,n])=>{if(!n||!this.map[t].destructible)return;let i=[];if(m(n))for(const e of n)i.push(e);else i.push(n);if(e){if(!this.map[t].selector)return;i=await async function(e,t){const n=new z(e);return await W(t,e=>{const t=v(e);if(t)for(const e of t)n.delete(e)}),Array.from(n)}(i,this.node)}E(`Errors during destruction of the "${t}" dependency.`,await Promise.allSettled(i.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)return e.wraplet.destroy()})))})),n=E("Errors during the dependencies destruction.",t,!1);if(n)throw this.logger.dumpError(n),n}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let s=n;if(r=e,Number.isInteger(r))for(let t=0;t<e;t++)s=s.getParent();else{if(!w(e))throw new Error("Invalid map argument.");s.setMap(e)}var r;return new k(t,s,i)}}}}class x{node;listeners=new Map;constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n);const i=this.listeners.get(this.node)||[];i.push({callback:t,event:e,options:n}),this.listeners.set(this.node,i)}addListenerTo(e,t,n,i,s=!0){if(!I(this.node))throw new Error("Target node is not a parent node. Cannot add listener to its child.");const r=[];if("string"==typeof e?r.push(...Array.from(this.node.querySelectorAll(e))):r.push(...e(this.node)),s&&0===r.length)throw new Error("No nodes found");for(const e of r){e.addEventListener(t,n,i);const s=this.listeners.get(e)||[];s.push({event:t,callback:n,options:i}),this.listeners.set(e,s)}}destroy(){for(const e of this.listeners){const t=e[0],n=e[1];for(const e of n)t.removeEventListener(e.event,e.callback,e.options)}this.listeners.clear()}}const T=Symbol("WrapletApi");function j(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(!n.isDestroyed&&(n.isGettingDestroyed=!0,!n.isGettingInitialized)){if(!n.isInitialized)throw new l("Wraplet cannot be destroyed before it is initialized.");t&&await t(),n.isGettingDestroyed=!1,n.isInitialized=!1,n.isDestroyed=!0;for(const t of[...e.destroyListeners].reverse())await t(e.wraplet);e.destroyListeners.length=0}})().finally(()=>{n=null}),n)}}function q(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(n.isDestroyed||n.isGettingDestroyed)throw new l("Wraplet cannot be initialized when destroyed or in the process of being destroyed");n.isInitialized||n.isGettingInitialized||(n.isGettingInitialized=!0,t&&await t(),n.isInitialized=!0,n.isGettingInitialized=!1,n.isGettingDestroyed&&await e.destroyCallback())})().finally(()=>{n=null}),n)}}const O=e=>{!function(e){if(!u(e.wraplet))throw new Error("Correct wraplet instance has to be provided.");if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},s=[],r=j({status:n,wraplet:t.wraplet,destroyListeners:s},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=v(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=q({status:n,destroyCallback:r,wraplet:t.wraplet},async()=>{t.initializeCallback&&await t.initializeCallback()}).bind(i);var o,d;return t.node&&(o=t.wraplet,(d=t.node).wraplets||(d.wraplets=new z),d.wraplets.add(o)),Object.assign(i,{[T]:!0,__destroyListeners:s,status:n,addDestroyListener:e=>{s.push(e)},initialize:a,destroy:r})};class ${node;[h]=!0;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new d(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){return this.buildWrapletApi(this.onInitialize.bind(this),this.onDestroy.bind(this))}buildWrapletApi(e,t){return O({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new x(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}onInitialize(){return G}onDestroy(){return G}static createWraplets(e,t,n=[]){if(this===$)throw new Error("You cannot instantiate an abstract class.");const i=[];let s;"function"==typeof t?s=t(e):(e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n)),s=e.querySelectorAll(`[${t}]`));for(const e of s)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class N extends ${dm;constructor(e){if(!p(e,L))throw new Error("AbstractDependentWraplet requires an instance implementing the DependencyManager interface.");super(e.node),this.dm=e,e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(async()=>{await this.dm.initializeDependencies(),await this.onInitialize.bind(this)()},async()=>{await this.onDestroy.bind(this)(),await this.dm.destroyDependencies()})}onDestroy(){return G}onInitialize(){return G}get d(){return this.dm.dependencies}static createDependencyManager(e,t){return new k(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===N)throw new Error("You cannot instantiate an abstract class.");const s=this,r=[];let a;if("function"==typeof t)a=t(e);else{if(e instanceof Element&&e.hasAttribute(t)){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}a=e.querySelectorAll(`[${t}]`)}for(const e of a){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}return r}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const s=this.createDependentWraplets(e,t,n,i);for(const e of s)await e.wraplet.initialize();return s}}class _ extends g{[b]=!0}class R{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){E("There were errors during the node's initialization.",await Promise.allSettled(this.initializers.map(n=>n(e,t))))}async destroyNode(e){await M(e)}}var F=exports;for(var U in t)F[U]=t[U];t.__esModule&&Object.defineProperty(F,"__esModule",{value:!0});
1
+ var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AbstractDependentWraplet:()=>$,AbstractWraplet:()=>j,DDM:()=>C,DNTM:()=>O,DefaultWrapletSet:()=>b,DefaultWrapletSetReadonly:()=>q,DependenciesAreNotAvailableError:()=>r,InternalLogicError:()=>o,LifecycleError:()=>c,MapError:()=>i,MissingRequiredDependencyError:()=>n,RequiredDependencyDestroyedError:()=>s,TooManyChildrenFoundError:()=>a,UnsupportedNodeTypeError:()=>d,createOuterDestroyCallback:()=>T,createOuterInitializeCallback:()=>x,createWrapletApi:()=>G,destroyWrapletsRecursively:()=>A,getWrapletsFromNode:()=>v,isWraplet:()=>h});class n extends Error{}class i extends Error{}class s extends Error{}class r extends Error{}class a extends Error{}class o extends Error{}class d extends Error{}class c extends Error{}const l=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],p=Symbol("WrapletApi");function h(e){return"object"==typeof e&&null!==e&&l(e.wraplet,p)}function u(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function y(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function f(e){if(!u(e))return!1;for(const t in e){if(!u(e[t]))return!1;if(!y(e[t]))return!1}return!0}const w=Symbol("WrapletSet");function D(e){return l(e,w)}class m extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const g=Symbol("WrapletSetReadonly");class b extends m{[g]=!0;[w]=!0}const z=Promise.resolve();function I(e,t){if(0!==e.length)throw new AggregateError(e,`${t}`)}function E(e){return"function"==typeof e.querySelectorAll}function v(e){const t=e.wraplets;return D(t)?t:null}function W(e,t){const n=[e];for(;n.length>0;){const e=n.pop();t(e);const i=e.childNodes;for(let e=i.length-1;e>=0;e--)n.push(i[e])}}async function A(e){const t=[];W(e,e=>{const n=v(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)});const n=[];await Promise.all(t.map(async e=>{try{await e.wraplet.destroy()}catch(e){n.push(e)}})),I(n,"Some wraplets threw exceptions during destruction")}const M=Symbol("DependencyManager");function L(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const P=Symbol("MapTreeBuilder");class S{parent;[P]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new S(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=L(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}class C{node;[M]=!0;dependenciesAreInstantiated=!1;initializePromise=null;destroyPromise=null;syncPromise=null;status={isDestroyed:!1,isGettingDestroyed:!1,isGettingSynced:!1,isInitialized:!1,isGettingInitialized:!1};mapTree;directDependencies={};wrappedDependencies={};instantiatedDependencyListeners;initializedDependencyListeners;destroyedDependencyListeners;constructor(e,t,n={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the DDM is not a valid node.");if(f(t))this.mapTree=new S,this.mapTree.setMap(t);else{if("object"!=typeof(s=t)||null===s||!(P in s))throw new i("The map provided to the DDM is not a valid map.");this.mapTree=t}var s;const r=Object.assign(this.defaultOptions(),n);this.instantiatedDependencyListeners=r.dependencyInstantiatedListeners,this.initializedDependencyListeners=r.dependencyInitializedListeners,this.destroyedDependencyListeners=r.dependencyDestroyedListeners}initializeDependencies(){return this.status.isInitialized?z:(this.initializePromise||(this.initializePromise=(async()=>{try{this.status.isGettingInitialized=!0,await this.initializeDeps(),this.status.isInitialized=!0}finally{this.initializePromise=null,this.status.isGettingInitialized=!1}})()),this.initializePromise)}async initializeDeps(){const e=[];await Promise.all(Object.entries(this.directDependencies).map(async([t,n])=>{if(!n)return;const i=D(n)?Array.from(n):[n];await Promise.all(i.map(async n=>{if(n.wraplet.status.isInitialized||n.wraplet.status.isGettingInitialized)return;try{await n.wraplet.initialize()}catch(n){return void e.push(new AggregateError([n],`Error during initialization of the "${t}" dependency.`))}const i=[],s=this.initializedDependencyListeners.get(t);if(s){for(const e of s)try{await e(n)}catch(e){i.push(e)}i.length>0&&e.push(new AggregateError(i,`At least one listener of the "${t}" dependency threw exception`))}}))})),I(e,"Errors during the dependencies initialization.")}syncDependencies(){return this.syncPromise||(this.syncPromise=(async()=>{try{this.status.isGettingSynced=!0,this.instantiateDeps(!0),await this.initializeDeps(),await this.destroyDeps(!0)}finally{this.syncPromise=null,this.status.isGettingSynced=!1}})()),this.syncPromise}get map(){return this.mapTree.getMap()}instantiateDeps(e=!1){const t=this.directDependencies;if(E(this.node))for(const n in this.map){const i=this.map[n],s=i.multiple;if(this.validateMapItem(n,i),s){t[n]||(t[n]=new b);const e=t[n],s=this.instantiateMultipleDependencies(i,this.node,n);for(const t of s)e.add(t);continue}const r=this.instantiateSingleWrapletDependency(i,this.node,n);r!==t[n]&&(e&&r&&t[n]&&t[n].wraplet.destroy(),t[n]=r)}else{for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}this.dependenciesAreInstantiated=!0}}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new c("Dependencies are already instantiated.");this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.instantiateDeps(),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!D(n))throw new o("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new o("Internal logic error. Multiple instances wrapping the same element found in the DDM.");return i[0]}if(!h(n))throw new o("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,t,n){if(!e.selector)return this.directDependencies[n]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[n])throw new i("It's not possible to provide a single-type dependency manually and use selector at the same time.");const s=e.selector,r=this.findChildrenElements(s,t);if(this.validateElements(n,r,e),0===r.length)return null;if(r.length>1)throw new a(`${this.constructor.name}: More than one element was found for the "${n}" dependency. Selector used: "${s}".`);const o=r[0];return this.instantiateWrapletItem(n,e,o)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let s;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!h(i))throw new Error("Created dependency is not a Wraplet instance.");s=i}catch(n){if(n instanceof d&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,s);for(const t of this.instantiatedDependencyListeners.get(e)||[])t(s);return s}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new b;const s=this.findChildrenElements(i,t);this.validateElements(n,s,e);const r=new b;for(const t of s){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&r.add(i)}return r}addDependencyInstantiatedListener(e,t){const n=this.instantiatedDependencyListeners.get(e)||[];n.push(t),this.instantiatedDependencyListeners.set(e,n)}addDependencyInitializedListener(e,t){const n=this.initializedDependencyListeners.get(e)||[];n.push(t),this.initializedDependencyListeners.set(e,n)}addDependencyDestroyedListener(e,t){const n=this.destroyedDependencyListeners.get(e)||[];n.push(t),this.destroyedDependencyListeners.set(e,n)}setExistingInstance(e,t){if(this.map[e].multiple)throw new i("This method can only be used to set a single-value dependency.");if(!h(t))throw new i("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,t),this.directDependencies[e]=t}addExistingInstance(e,t){if(!this.map[e].multiple)throw new i("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,t);const n=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new b;n.add(t),this.directDependencies[e]=n}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=[],i=this.destroyedDependencyListeners.get(e);i&&i.length>0&&await Promise.all(i.map(async e=>{try{await e(t)}catch(e){n.push(e)}}));const s=this.validateRequiredDependencyAfterRemoval(e);s&&n.push(s),I(n,`Errors in the destruction callbacks of the "${e}" dependency.`)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed&&null===this.directDependencies[e]?new s(`Required dependency "${e}" has been destroyed.`):null}destroyDependencies(){return this.status.isDestroyed?z:(this.destroyPromise||(this.destroyPromise=(async()=>{try{if(this.status.isGettingDestroyed=!0,this.initializePromise&&await this.initializePromise,!this.status.isInitialized)return this.status.isDestroyed=!0,void(this.status.isGettingDestroyed=!1);await this.destroyDeps(),this.status.isInitialized=!1,this.status.isDestroyed=!0}finally{this.destroyPromise=null,this.status.isGettingDestroyed=!1}})()),this.destroyPromise)}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new r("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){D(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,t){const n=t.selector,s=t.required;if(!n&&s&&(!this.directDependencies[e]||D(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new i(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,t){if(t.required)throw new i(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(e,t,i){if(0===t.length&&i.required)throw new n(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:new Map,dependencyInitializedListeners:new Map,dependencyDestroyedListeners:new Map}}async destroyDeps(e=!1){const t=[];await Promise.all(Object.entries(this.directDependencies).map(async([n,i])=>{if(!i||!this.map[n].destructible)return;let s=D(i)?Array.from(i):[i];if(e){if(!this.map[n].selector)return;s=await async function(e,t){const n=new b(e);return W(t,e=>{const t=v(e);if(t)for(const e of t)n.delete(e)}),Array.from(n)}(s,this.node)}await Promise.all(s.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)try{await e.wraplet.destroy()}catch(e){t.push(new AggregateError([e],`There was an error during destruction of the "${n}" dependency.`))}}))})),I(t,"There were errors during the dependencies destruction.")}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let s=n;if(r=e,Number.isInteger(r))for(let t=0;t<e;t++)s=s.getParent();else{if(!f(e))throw new Error("Invalid map argument.");s.setMap(e)}var r;return new C(t,s,i)}}}}class k{node;listeners=new Map;constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n);const i=this.listeners.get(this.node)||[];i.push({callback:t,event:e,options:n}),this.listeners.set(this.node,i)}addListenerTo(e,t,n,i,s=!0){if(!E(this.node))throw new Error("Target node is not a parent node. Cannot add listener to its child.");const r=[];if("string"==typeof e?r.push(...Array.from(this.node.querySelectorAll(e))):r.push(...e(this.node)),s&&0===r.length)throw new Error("No nodes found");for(const e of r){e.addEventListener(t,n,i);const s=this.listeners.get(e)||[];s.push({event:t,callback:n,options:i}),this.listeners.set(e,s)}}destroy(){for(const e of this.listeners){const t=e[0],n=e[1];for(const e of n)t.removeEventListener(e.event,e.callback,e.options)}this.listeners.clear()}}function T(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(!n.isDestroyed&&(n.isGettingDestroyed=!0,!n.isGettingInitialized)){if(!n.isInitialized)throw new c("Wraplet cannot be destroyed before it is initialized.");t&&await t(),n.isGettingDestroyed=!1,n.isInitialized=!1,n.isDestroyed=!0;for(const t of[...e.destroyListeners].reverse())await t(e.wraplet);e.destroyListeners.length=0}})().finally(()=>{n=null}),n)}}function x(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(n.isDestroyed||n.isGettingDestroyed)throw new c("Wraplet cannot be initialized when destroyed or in the process of being destroyed");n.isInitialized||n.isGettingInitialized||(n.isGettingInitialized=!0,t&&await t(),n.isInitialized=!0,n.isGettingInitialized=!1,n.isGettingDestroyed&&await e.destroyCallback())})().finally(()=>{n=null}),n)}}const G=e=>{!function(e){if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},s=[],r=T({status:n,wraplet:t.wraplet,destroyListeners:s},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=v(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=x({status:n,destroyCallback:r,wraplet:t.wraplet},async()=>{t.initializeCallback&&await t.initializeCallback()}).bind(i);var o,d;return t.node&&(o=t.wraplet,(d=t.node).wraplets||(d.wraplets=new b),d.wraplets.add(o)),Object.assign(i,{[p]:!0,__destroyListeners:s,status:n,addDestroyListener:e=>{s.push(e)},initialize:a,destroy:r})};class j{node;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new d(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){return this.buildWrapletApi(this.onInitialize.bind(this),this.onDestroy.bind(this))}buildWrapletApi(e,t){return G({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new k(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}onInitialize(){return z}onDestroy(){return z}static createWraplets(e,t,n=[]){if(this===j)throw new Error("You cannot instantiate an abstract class.");const i=[];let s;"function"==typeof t?s=t(e):(e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n)),s=e.querySelectorAll(`[${t}]`));for(const e of s)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class $ extends j{dm;constructor(e){if(!l(e,M))throw new Error("AbstractDependentWraplet requires an instance implementing the DependencyManager interface.");super(e.node),this.dm=e,e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(async()=>{await this.dm.initializeDependencies(),await this.onInitialize.bind(this)()},async()=>{await this.onDestroy.bind(this)(),await this.dm.destroyDependencies()})}onDestroy(){return z}onInitialize(){return z}get d(){return this.dm.dependencies}static createDependencyManager(e,t){return new C(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===$)throw new Error("You cannot instantiate an abstract class.");const s=this,r=[];let a;if("function"==typeof t)a=t(e);else{if(e instanceof Element&&e.hasAttribute(t)){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}a=e.querySelectorAll(`[${t}]`)}for(const e of a){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}return r}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const s=this.createDependentWraplets(e,t,n,i);for(const e of s)await e.wraplet.initialize();return s}}class q extends m{[g]=!0}class O{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){const n=[];if(await Promise.all(this.initializers.map(async i=>{try{await i(e,t)}catch(e){n.push(e)}})),n.length>0)throw new AggregateError(n,"There were errors during the node's initialization.")}async destroyNode(e){await A(e)}}var N=exports;for(var _ in t)N[_]=t[_];t.__esModule&&Object.defineProperty(N,"__esModule",{value:!0});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","mappings":"AACA,IAAAA,EAAA,CCAAA,EAAA,CAAAC,EAAAC,KACA,QAAAC,KAAAD,EACAF,EAAAI,EAAAF,EAAAC,KAAAH,EAAAI,EAAAH,EAAAE,IACAE,OAAAC,eAAAL,EAAAE,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCH,EAAA,CAAAS,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAV,EAAAC,IACA,oBAAAa,QAAAA,OAAAC,aACAV,OAAAC,eAAAL,EAAAa,OAAAC,YAAA,CAAuDC,MAAA,WAEvDX,OAAAC,eAAAL,EAAA,cAAgDe,OAAA,kmBCLzC,MAAAC,UAAAC,OAEA,MAAAC,UAAAD,OAEA,MAAAE,UAAAF,OAEA,MAAAG,UAAAH,OAEA,MAAAI,UAAAJ,OAEA,MAAAK,UAAAL,OAEA,MAAAM,UAAAN,OAEA,MAAAO,UAAAP,OAEA,MAAAQ,UAAAR,MACPS,OAAA,GCdA,MAAAC,EAAA,CAAAC,EAAAC,IACA,iBAAAD,GACA,OAAAA,IACA,IAAAA,EAAAC,GCLOC,EAAAjB,OAAA,WACA,SAAAkB,EAAAH,GACP,OAAWD,EAAEC,EAAAE,EACb,CCJA,SAAAE,EAAAC,GACA,uBAAAA,GACA,OAAAA,GACA7B,OAAA8B,eAAAD,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,OAAAsN,EACA,UAAApP,MAAA,6CAEA,MAAA0P,EAAA5N,KACAgB,EAAA,GACA,IAAA2I,EACA,sBAAAqD,EACArD,EAAAqD,EAAA3L,OAEA,CACA,GAAAA,aAAA6L,SAAA7L,EAAA8L,aAAAH,GAAA,CACA,MAAAO,EAAAK,EAAAF,wBAAArM,EAAAgB,GACArB,EAAAf,KAAA,IAAAD,KAAAuN,KAAAN,GACA,CACAtD,EAAAtI,EAAAC,iBAAA,IAAiD0L,KACjD,CACA,UAAAI,KAAAzD,EAAA,CACA,MAAA4D,EAAAK,EAAAF,wBAAAN,EAAA/K,GACArB,EAAAf,KAAA,IAAAD,KAAAuN,KAAAN,GACA,CACA,OAAAjM,CACA,CAWA,iDAAA6M,CAAAxM,EAAA2L,EAAA3K,EAAA4K,EAAA,IACA,MACAzL,EADAxB,KACA2N,wBAAAtM,EAAA2L,EAAA3K,EAAA4K,GACA,UAAAjL,KAAAR,QACAQ,EAAAA,QAAA+D,aAEA,OAAAvE,CACA,EClGO,MAAAsM,UAAwCnO,EAC/Ce,CAAKA,IAAwB,ECDtB,MAAAqN,EACPC,aAAA,GACA,kBAAAC,CAAA7N,GACAJ,KAAAgO,aAAA/N,KAAAG,EACA,CACA,oBAAA8N,CAAA7M,EAAA8M,GAEQvN,EAAyB,4DADjCuB,QAAAC,WAAApC,KAAAgO,aAAA3L,IAAA+L,GAAAA,EAAA/M,EAAA8M,KAEA,CACA,iBAAAE,CAAAhN,SACcS,EAA0BT,EACxC","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/createLifecycleAsyncError.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Logger/ConsoleLogger.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/utils/utils.ts","webpack://wraplet/./src/DependencyManager/DDM.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DNTM.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\nexport class LifecycleAsyncErrors extends Error {\n errors = [];\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletSymbol = Symbol(\"Wraplet\");\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { LifecycleAsyncErrors } from \"../errors\";\nexport function createLifecycleAsyncError(message, results, throwError = true) {\n const error = new LifecycleAsyncErrors(message);\n for (const result of results) {\n if (result.status === \"rejected\") {\n error.errors.push(result.reason);\n }\n }\n if (error.errors.length === 0) {\n return null;\n }\n if (throwError) {\n throw error;\n }\n return error;\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport async function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function findWrapletsOutsideTheTree(wraplets, node) {\n const wrapletsOutsideTree = new DefaultWrapletSet(wraplets);\n await actOnNodesRecursively(node, (node) => {\n const nodeWraplets = getWrapletsFromNode(node);\n if (!nodeWraplets) {\n return;\n }\n for (const wraplet of nodeWraplets) {\n wrapletsOutsideTree.delete(wraplet);\n }\n });\n return Array.from(wrapletsOutsideTree);\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n await actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const results = await Promise.allSettled(allWraplets.map((wraplet) => wraplet.wraplet.destroy()));\n createLifecycleAsyncError(\"Some wraplets threw exceptions during destruction\", results);\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export class ConsoleLogger {\n static #instance = new ConsoleLogger();\n constructor() { }\n dumpError(error) {\n console.dir(error, { depth: null });\n }\n static getGlobalLogger() {\n return this.#instance;\n }\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","export const RESOLVE = Promise.resolve();\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { findWrapletsOutsideTheTree, isParentNode, } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { ConsoleLogger } from \"../Logger/ConsoleLogger\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class DDM {\n node;\n [DependencyManagerSymbol] = true;\n logger;\n dependenciesAreInstantiated = false;\n initializePromise = null;\n destroyPromise = null;\n syncPromise = null;\n status = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isGettingSynced: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n instantiatedDependencyListeners;\n initializedDependencyListeners;\n destroyedDependencyListeners;\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the DDM is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the DDM is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.logger = optionsWithDefaults.logger;\n this.instantiatedDependencyListeners =\n optionsWithDefaults.dependencyInstantiatedListeners;\n this.initializedDependencyListeners =\n optionsWithDefaults.dependencyInitializedListeners;\n this.destroyedDependencyListeners =\n optionsWithDefaults.dependencyDestroyedListeners;\n }\n initializeDependencies() {\n if (this.status.isInitialized) {\n return RESOLVE;\n }\n if (this.initializePromise) {\n return this.initializePromise;\n }\n this.initializePromise = (async () => {\n try {\n this.status.isGettingInitialized = true;\n await this.initializeDeps();\n this.status.isInitialized = true;\n }\n finally {\n this.initializePromise = null;\n this.status.isGettingInitialized = false;\n }\n })();\n return this.initializePromise;\n }\n /**\n * Initialize dependencies.\n */\n async initializeDeps() {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n await wraplet.wraplet.initialize();\n const listenerResults = await Promise.allSettled((this.initializedDependencyListeners.get(id) || []).map((fn) => fn(wraplet)));\n createLifecycleAsyncError(`Errors in the DDM's dependency \"${id}\" initialize listeners.`, listenerResults);\n }));\n createLifecycleAsyncError(`Error at \"${id}\" dependency's initialization.`, results);\n }));\n const error = createLifecycleAsyncError(`Error at DDM's initialization.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n syncDependencies() {\n if (this.syncPromise) {\n return this.syncPromise;\n }\n this.syncPromise = (async () => {\n try {\n this.status.isGettingSynced = true;\n this.instantiateDeps(true);\n await this.initializeDeps();\n await this.destroyDeps(true);\n }\n finally {\n this.syncPromise = null;\n this.status.isGettingSynced = false;\n }\n })();\n return this.syncPromise;\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDeps(sync = false) {\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n const newDep = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n // This might happen when we are syncing and the dependency hasn't changed.\n if (newDep === dependencies[id]) {\n continue;\n }\n // If we are syncing, invoke destruction of the old dependency.\n if (sync && newDep && dependencies[id]) {\n dependencies[id].wraplet.destroy();\n }\n dependencies[id] = newDep;\n }\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.instantiateDeps();\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the DDM.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners.get(id) || []) {\n listener(wraplet);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyInstantiatedListener(id, callback) {\n const listeners = this.instantiatedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.instantiatedDependencyListeners.set(id, listeners);\n }\n addDependencyInitializedListener(id, callback) {\n const listeners = this.initializedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.initializedDependencyListeners.set(id, listeners);\n }\n addDependencyDestroyedListener(id, callback) {\n const listeners = this.destroyedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.destroyedDependencyListeners.set(id, listeners);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const results = await Promise.allSettled((this.destroyedDependencyListeners.get(id) || []).map((fn) => fn(w)));\n // Collect the required-dependency error alongside listener results\n // so that everything surfaces through the same LifecycleError mechanism.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n results.push({ status: \"rejected\", reason: requiredError });\n }\n createLifecycleAsyncError(`Errors in the destruction callbacks of the \"${id} dependency.\"`, results);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the DDM\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required &&\n !this.status.isGettingDestroyed &&\n // Don't allow removing a required dependency only if there is no\n // replacement in place.\n this.directDependencies[id] === null) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n destroyDependencies() {\n if (this.status.isDestroyed) {\n return RESOLVE;\n }\n if (this.destroyPromise) {\n return this.destroyPromise;\n }\n this.destroyPromise = (async () => {\n try {\n this.status.isGettingDestroyed = true;\n if (this.initializePromise) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n await this.initializePromise;\n }\n if (!this.status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.status.isDestroyed = true;\n this.status.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.status.isInitialized = false;\n this.status.isDestroyed = true;\n }\n finally {\n this.destroyPromise = null;\n this.status.isGettingDestroyed = false;\n }\n })();\n return this.destroyPromise;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: new Map(),\n dependencyInitializedListeners: new Map(),\n dependencyDestroyedListeners: new Map(),\n logger: ConsoleLogger.getGlobalLogger(),\n };\n }\n async destroyDeps(sync = false) {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n let wraplets = [];\n if (isWrapletSet(dependency)) {\n for (const item of dependency) {\n wraplets.push(item);\n }\n }\n else {\n wraplets.push(dependency);\n }\n if (sync) {\n if (!this.map[id][\"selector\"]) {\n return;\n }\n wraplets = await findWrapletsOutsideTheTree(wraplets, this.node);\n }\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n return wraplet.wraplet.destroy();\n }));\n createLifecycleAsyncError(`Errors during destruction of the \"${id}\" dependency.`, results);\n }));\n const error = createLifecycleAsyncError(`Errors during the dependencies destruction.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new DDM(node, currentMap, data);\n },\n };\n }\n}\n","import { isParentNode } from \"../NodeTreeManager/utils\";\nexport class NodeManager {\n node;\n listeners = new Map();\n constructor(node) {\n this.node = node;\n }\n /**\n * Add a listener to the current node.\n */\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(this.node) || [];\n listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n this.listeners.set(this.node, listeners);\n }\n /**\n * Add a listener to one of the descendants.\n *\n * Note: Most of the time it's not recommended to use this\n * method because it makes a wraplet impure.\n *\n * Ideally, wraplet should directly interact only with its\n * own node. However, you can make a wraplet impure if you\n * know what you are doing.\n */\n addListenerTo(target, eventName, callback, options, required = true) {\n if (!isParentNode(this.node)) {\n throw new Error(\"Target node is not a parent node. Cannot add listener to its child.\");\n }\n const nodes = [];\n if (typeof target === \"string\") {\n nodes.push(...Array.from(this.node.querySelectorAll(target)));\n }\n else {\n nodes.push(...target(this.node));\n }\n if (required && nodes.length === 0) {\n throw new Error(\"No nodes found\");\n }\n for (const node of nodes) {\n node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(node) || [];\n listeners.push({\n event: eventName,\n callback,\n options,\n });\n this.listeners.set(node, listeners);\n }\n }\n destroy() {\n for (const listenerData of this.listeners) {\n const node = listenerData[0];\n const listeners = listenerData[1];\n for (const listener of listeners) {\n node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n }\n this.listeners.clear();\n }\n}\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed) {\n return;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...args.destroyListeners].reverse()) {\n await listener(args.wraplet);\n }\n args.destroyListeners.length = 0;\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed || status.isGettingDestroyed) {\n throw new LifecycleError(\"Wraplet cannot be initialized when destroyed or in the process of being destroyed\");\n }\n if (status.isInitialized || status.isGettingInitialized) {\n return;\n }\n status.isGettingInitialized = true;\n if (initializeLogic) {\n await initializeLogic();\n }\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await args.destroyCallback();\n }\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { isWraplet } from \"./types/Wraplet\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (!isWraplet(args.wraplet)) {\n throw new Error(\"Correct wraplet instance has to be provided.\");\n }\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n // Note that it's added immediately without initialization required.\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { UnsupportedNodeTypeError } from \"../errors\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n return this.buildWrapletApi(this.onInitialize.bind(this), this.onDestroy.bind(this));\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeGuard` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n onInitialize() {\n return RESOLVE;\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n onDestroy() {\n return RESOLVE;\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { DDM } from \"../DependencyManager/DDM\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing the DependencyManager interface.\");\n }\n super(dm.node);\n this.dm = dm;\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(async () => {\n await this.dm.initializeDependencies();\n await this.onInitialize.bind(this)();\n }, async () => {\n await this.onDestroy.bind(this)();\n await this.dm.destroyDependencies();\n });\n }\n onDestroy() {\n return RESOLVE;\n }\n onInitialize() {\n return RESOLVE;\n }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n static createDependencyManager(node, map) {\n return new DDM(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createDependentWraplets(node, attribute, map, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated and initialized wraplets.\n */\n static async createAndInitializeDependentWraplets(node, attribute, map, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, attribute, map, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport class DNTM {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const results = await Promise.allSettled(this.initializers.map((initializer) => initializer(node, context)));\n createLifecycleAsyncError(`There were errors during the node's initialization.`, results);\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","LifecycleAsyncErrors","errors","is","object","symbol","WrapletSymbol","isWraplet","isSimpleObject","input","getPrototypeOf","isDependencyMapItem","item","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","createLifecycleAsyncError","message","throwError","error","result","status","reason","length","isParentNode","node","querySelectorAll","getWrapletsFromNode","wraplets","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","allWraplets","wraplet","isGettingDestroyed","isDestroyed","Promise","allSettled","map","destroy","DependencyManagerSymbol","ConsoleLogger","static","constructor","dumpError","console","dir","depth","getGlobalLogger","instance","addDefaultsToDependencyDefinition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","RESOLVE","resolve","DDM","logger","dependenciesAreInstantiated","initializePromise","destroyPromise","syncPromise","isGettingSynced","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","instantiatedDependencyListeners","initializedDependencyListeners","destroyedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","initializeDeps","entries","dependency","initialize","listenerResults","fn","syncDependencies","instantiateDeps","destroyDeps","sync","dependencies","dependencyDefinition","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","newDep","instantiateSingleWrapletDependency","validateMapItemForNonParent","instantiateDependencies","wrapDependencies","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","Class","data","e","required","warn","prepareIndividualWraplet","listener","childElements","items","addDependencyInstantiatedListener","listeners","set","addDependencyInitializedListener","addDependencyDestroyedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDependencies","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","target","Map","wrapletsOutsideTree","nodeWraplets","findWrapletsOutsideTheTree","createInjector","map_or_position","currentMap","Number","isInteger","i","NodeManager","addListener","eventName","addEventListener","event","addListenerTo","nodes","listenerData","removeEventListener","clear","WrapletApiSymbol","createOuterDestroyCallback","destroyLogic","promise","destroyListeners","reverse","finally","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","buildWrapletApi","onInitialize","onDestroy","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","Element","hasAttribute","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DNTM","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
1
+ {"version":3,"file":"index.cjs","mappings":"AACA,IAAAA,EAAA,CCAAA,EAAA,CAAAC,EAAAC,KACA,QAAAC,KAAAD,EACAF,EAAAI,EAAAF,EAAAC,KAAAH,EAAAI,EAAAH,EAAAE,IACAE,OAAAC,eAAAL,EAAAE,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCH,EAAA,CAAAS,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAV,EAAAC,IACA,oBAAAa,QAAAA,OAAAC,aACAV,OAAAC,eAAAL,EAAAa,OAAAC,YAAA,CAAuDC,MAAA,WAEvDX,OAAAC,eAAAL,EAAA,cAAgDe,OAAA,mjBCLzC,MAAAC,UAAAC,OAEA,MAAAC,UAAAD,OAEA,MAAAE,UAAAF,OAEA,MAAAG,UAAAH,OAEA,MAAAI,UAAAJ,OAEA,MAAAK,UAAAL,OAEA,MAAAM,UAAAN,OAEA,MAAAO,UAAAP,OCXP,MAAAQ,EAAA,CAAAC,EAAAC,IACA,iBAAAD,GACA,OAAAA,IACA,IAAAA,EAAAC,GCLOC,EAAAf,OAAA,cCCA,SAAAgB,EAAAd,GACP,uBAAAA,GACA,OAAAA,GACQU,EAAEV,EAAAe,QAAgBF,EAC1B,CCNA,SAAAG,EAAAC,GACA,uBAAAA,GACA,OAAAA,GACA5B,OAAA6B,eAAAD,KAAA5B,OAAAM,SACA,CACA,SAAAwB,EAAAC,GACA,UAAAjC,KAAAE,OAAAgC,KAAAD,GACA,KACA,WACA,QACA,WACA,WACA,eACA,WACA,QACAE,SAAAnC,GACA,SAGA,0CAAAmC,gBAAAF,EAAA,WAGA,mBAAAA,EAAA,OAGA,kBAAAA,EAAA,UAGA,kBAAAA,EAAA,QACA,CACO,SAAAG,EAAAZ,GACP,IAAAK,E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AAAC,CACA,CAWA,iDAAAY,CAAAjM,EAAAmL,EAAAjK,EAAAkK,EAAA,IACA,MACAjL,EADAxB,KACAoN,wBAAA/L,EAAAmL,EAAAjK,EAAAkK,GACA,UAAAzN,KAAAwC,QACAxC,EAAAA,QAAAuG,aAEA,OAAA/D,CACA,EClGO,MAAA+L,UAAwC5N,EAC/Ce,CAAKA,IAAwB,ECFtB,MAAA8M,EACPC,aAAA,GACA,kBAAAC,CAAAtN,GACAJ,KAAAyN,aAAAxN,KAAAG,EACA,CACA,oBAAAuN,CAAAtM,EAAAuM,GACA,MAAA5M,EAAA,GASA,SARAH,QAAAyB,IAAAtC,KAAAyN,aAAAlL,IAAAP,MAAA6L,IACA,UACAA,EAAAxM,EAAAuM,EACA,CACA,MAAAnL,GACAzB,EAAAf,KAAAwC,EACA,KAEAzB,EAAAE,OAAA,EACA,UAAAC,eAAAH,EAAA,sDAEA,CACA,iBAAA8M,CAAAzM,SACcY,EAA0BZ,EACxC","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/utils.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/DependencyManager/DDM.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DNTM.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { is } from \"../../utils/is\";\nimport { WrapletApiSymbol } from \"./WrapletApi\";\nexport function isWraplet(value) {\n return (typeof value === \"object\" &&\n value !== null &&\n is(value.wraplet, WrapletApiSymbol));\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","export const RESOLVE = Promise.resolve();\nexport function throwIfErrors(errors, message) {\n if (errors.length === 0)\n return;\n throw new AggregateError(errors, `${message}`);\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { throwIfErrors } from \"../utils/utils\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport function actOnNodesRecursively(node, callback) {\n const stack = [node];\n while (stack.length > 0) {\n const current = stack.pop();\n callback(current);\n const children = current.childNodes;\n for (let i = children.length - 1; i >= 0; i--) {\n stack.push(children[i]);\n }\n }\n}\nexport async function findWrapletsOutsideTheTree(wraplets, node) {\n const wrapletsOutsideTree = new DefaultWrapletSet(wraplets);\n actOnNodesRecursively(node, (node) => {\n const nodeWraplets = getWrapletsFromNode(node);\n if (!nodeWraplets) {\n return;\n }\n for (const wraplet of nodeWraplets) {\n wrapletsOutsideTree.delete(wraplet);\n }\n });\n return Array.from(wrapletsOutsideTree);\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const errors = [];\n await Promise.all(allWraplets.map(async (wraplet) => {\n try {\n await wraplet.wraplet.destroy();\n }\n catch (error) {\n errors.push(error);\n }\n }));\n throwIfErrors(errors, \"Some wraplets threw exceptions during destruction\");\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { findWrapletsOutsideTheTree, isParentNode, } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nimport { RESOLVE, throwIfErrors } from \"../utils/utils\";\nexport class DDM {\n node;\n [DependencyManagerSymbol] = true;\n dependenciesAreInstantiated = false;\n initializePromise = null;\n destroyPromise = null;\n syncPromise = null;\n status = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isGettingSynced: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n instantiatedDependencyListeners;\n initializedDependencyListeners;\n destroyedDependencyListeners;\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the DDM is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the DDM is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.instantiatedDependencyListeners =\n optionsWithDefaults.dependencyInstantiatedListeners;\n this.initializedDependencyListeners =\n optionsWithDefaults.dependencyInitializedListeners;\n this.destroyedDependencyListeners =\n optionsWithDefaults.dependencyDestroyedListeners;\n }\n initializeDependencies() {\n if (this.status.isInitialized) {\n return RESOLVE;\n }\n if (this.initializePromise) {\n return this.initializePromise;\n }\n this.initializePromise = (async () => {\n try {\n this.status.isGettingInitialized = true;\n await this.initializeDeps();\n this.status.isInitialized = true;\n }\n finally {\n this.initializePromise = null;\n this.status.isGettingInitialized = false;\n }\n })();\n return this.initializePromise;\n }\n /**\n * Initialize dependencies.\n */\n async initializeDeps() {\n const errors = [];\n await Promise.all(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n await Promise.all(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n try {\n await wraplet.wraplet.initialize();\n }\n catch (error) {\n errors.push(new AggregateError([error], `Error during initialization of the \"${id}\" dependency.`));\n return;\n }\n const listenersErrors = [];\n const listeners = this.initializedDependencyListeners.get(id);\n if (listeners) {\n for (const fn of listeners) {\n try {\n await fn(wraplet);\n }\n catch (error) {\n listenersErrors.push(error);\n }\n }\n if (listenersErrors.length > 0) {\n errors.push(new AggregateError(listenersErrors, `At least one listener of the \"${id}\" dependency threw exception`));\n }\n }\n }));\n }));\n throwIfErrors(errors, `Errors during the dependencies initialization.`);\n }\n syncDependencies() {\n if (this.syncPromise) {\n return this.syncPromise;\n }\n this.syncPromise = (async () => {\n try {\n this.status.isGettingSynced = true;\n this.instantiateDeps(true);\n await this.initializeDeps();\n await this.destroyDeps(true);\n }\n finally {\n this.syncPromise = null;\n this.status.isGettingSynced = false;\n }\n })();\n return this.syncPromise;\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDeps(sync = false) {\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n const newDep = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n // This might happen when we are syncing and the dependency hasn't changed.\n if (newDep === dependencies[id]) {\n continue;\n }\n // If we are syncing, invoke destruction of the old dependency.\n if (sync && newDep && dependencies[id]) {\n dependencies[id].wraplet.destroy();\n }\n dependencies[id] = newDep;\n }\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.instantiateDeps();\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the DDM.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners.get(id) || []) {\n listener(wraplet);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyInstantiatedListener(id, callback) {\n const listeners = this.instantiatedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.instantiatedDependencyListeners.set(id, listeners);\n }\n addDependencyInitializedListener(id, callback) {\n const listeners = this.initializedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.initializedDependencyListeners.set(id, listeners);\n }\n addDependencyDestroyedListener(id, callback) {\n const listeners = this.destroyedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.destroyedDependencyListeners.set(id, listeners);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const errors = [];\n const listeners = this.destroyedDependencyListeners.get(id);\n if (listeners && listeners.length > 0) {\n await Promise.all(listeners.map(async (fn) => {\n try {\n await fn(w);\n }\n catch (error) {\n errors.push(error);\n }\n }));\n }\n // Collect the required-dependency error alongside listener errors\n // so that everything surfaces through the same error-aggregation pipeline.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n errors.push(requiredError);\n }\n throwIfErrors(errors, `Errors in the destruction callbacks of the \"${id}\" dependency.`);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the DDM\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required &&\n !this.status.isGettingDestroyed &&\n // Don't allow removing a required dependency only if there is no\n // replacement in place.\n this.directDependencies[id] === null) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n destroyDependencies() {\n if (this.status.isDestroyed) {\n return RESOLVE;\n }\n if (this.destroyPromise) {\n return this.destroyPromise;\n }\n this.destroyPromise = (async () => {\n try {\n this.status.isGettingDestroyed = true;\n if (this.initializePromise) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n await this.initializePromise;\n }\n if (!this.status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.status.isDestroyed = true;\n this.status.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.status.isInitialized = false;\n this.status.isDestroyed = true;\n }\n finally {\n this.destroyPromise = null;\n this.status.isGettingDestroyed = false;\n }\n })();\n return this.destroyPromise;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: new Map(),\n dependencyInitializedListeners: new Map(),\n dependencyDestroyedListeners: new Map(),\n };\n }\n async destroyDeps(sync = false) {\n const errors = [];\n await Promise.all(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n let wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n if (sync) {\n if (!this.map[id][\"selector\"]) {\n return;\n }\n wraplets = await findWrapletsOutsideTheTree(wraplets, this.node);\n }\n await Promise.all(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n try {\n await wraplet.wraplet.destroy();\n }\n catch (error) {\n errors.push(new AggregateError([error], `There was an error during destruction of the \"${id}\" dependency.`));\n }\n }));\n }));\n throwIfErrors(errors, `There were errors during the dependencies destruction.`);\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new DDM(node, currentMap, data);\n },\n };\n }\n}\n","import { isParentNode } from \"../NodeTreeManager/utils\";\nexport class NodeManager {\n node;\n listeners = new Map();\n constructor(node) {\n this.node = node;\n }\n /**\n * Add a listener to the current node.\n */\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(this.node) || [];\n listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n this.listeners.set(this.node, listeners);\n }\n /**\n * Add a listener to one of the descendants.\n *\n * Note: Most of the time it's not recommended to use this\n * method because it makes a wraplet impure.\n *\n * Ideally, wraplet should directly interact only with its\n * own node. However, you can make a wraplet impure if you\n * know what you are doing.\n */\n addListenerTo(target, eventName, callback, options, required = true) {\n if (!isParentNode(this.node)) {\n throw new Error(\"Target node is not a parent node. Cannot add listener to its child.\");\n }\n const nodes = [];\n if (typeof target === \"string\") {\n nodes.push(...Array.from(this.node.querySelectorAll(target)));\n }\n else {\n nodes.push(...target(this.node));\n }\n if (required && nodes.length === 0) {\n throw new Error(\"No nodes found\");\n }\n for (const node of nodes) {\n node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(node) || [];\n listeners.push({\n event: eventName,\n callback,\n options,\n });\n this.listeners.set(node, listeners);\n }\n }\n destroy() {\n for (const listenerData of this.listeners) {\n const node = listenerData[0];\n const listeners = listenerData[1];\n for (const listener of listeners) {\n node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n }\n this.listeners.clear();\n }\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed) {\n return;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...args.destroyListeners].reverse()) {\n await listener(args.wraplet);\n }\n args.destroyListeners.length = 0;\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed || status.isGettingDestroyed) {\n throw new LifecycleError(\"Wraplet cannot be initialized when destroyed or in the process of being destroyed\");\n }\n if (status.isInitialized || status.isGettingInitialized) {\n return;\n }\n status.isGettingInitialized = true;\n if (initializeLogic) {\n await initializeLogic();\n }\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await args.destroyCallback();\n }\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n // Note that it's added immediately without initialization required.\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { UnsupportedNodeTypeError } from \"../errors\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractWraplet {\n node;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n return this.buildWrapletApi(this.onInitialize.bind(this), this.onDestroy.bind(this));\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeGuard` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n onInitialize() {\n return RESOLVE;\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n onDestroy() {\n return RESOLVE;\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { DDM } from \"../DependencyManager/DDM\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing the DependencyManager interface.\");\n }\n super(dm.node);\n this.dm = dm;\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(async () => {\n await this.dm.initializeDependencies();\n await this.onInitialize.bind(this)();\n }, async () => {\n await this.onDestroy.bind(this)();\n await this.dm.destroyDependencies();\n });\n }\n onDestroy() {\n return RESOLVE;\n }\n onInitialize() {\n return RESOLVE;\n }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n static createDependencyManager(node, map) {\n return new DDM(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createDependentWraplets(node, attribute, map, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated and initialized wraplets.\n */\n static async createAndInitializeDependentWraplets(node, attribute, map, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, attribute, map, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport class DNTM {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const errors = [];\n await Promise.all(this.initializers.map(async (initializer) => {\n try {\n await initializer(node, context);\n }\n catch (error) {\n errors.push(error);\n }\n }));\n if (errors.length > 0) {\n throw new AggregateError(errors, `There were errors during the node's initialization.`);\n }\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","is","object","symbol","WrapletApiSymbol","isWraplet","wraplet","isSimpleObject","input","getPrototypeOf","isDependencyMapItem","item","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","RESOLVE","Promise","resolve","throwIfErrors","errors","message","length","AggregateError","isParentNode","node","querySelectorAll","getWrapletsFromNode","wraplets","actOnNodesRecursively","stack","current","pop","children","childNodes","i","async","destroyWrapletsRecursively","allWraplets","status","isGettingDestroyed","isDestroyed","all","map","destroy","error","DependencyManagerSymbol","addDefaultsToDependencyDefinition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","constructor","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","DDM","dependenciesAreInstantiated","initializePromise","destroyPromise","syncPromise","isGettingSynced","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","instantiatedDependencyListeners","initializedDependencyListeners","destroyedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","initializeDeps","entries","dependency","initialize","listenersErrors","listeners","fn","syncDependencies","instantiateDeps","destroyDeps","sync","dependencies","dependencyDefinition","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","newDep","instantiateSingleWrapletDependency","validateMapItemForNonParent","instantiateDependencies","wrapDependencies","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","instance","Class","data","e","required","console","warn","prepareIndividualWraplet","listener","childElements","items","addDependencyInstantiatedListener","set","addDependencyInitializedListener","addDependencyDestroyedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDependencies","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","target","Map","wrapletsOutsideTree","nodeWraplets","findWrapletsOutsideTheTree","createInjector","map_or_position","currentMap","Number","isInteger","NodeManager","addListener","eventName","addEventListener","event","addListenerTo","nodes","listenerData","removeEventListener","clear","createOuterDestroyCallback","destroyLogic","promise","destroyListeners","reverse","finally","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","buildWrapletApi","onInitialize","onDestroy","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","result","Element","hasAttribute","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DNTM","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export type { WrapletApiDebug } from "./Wraplet/types/WrapletApi";
15
15
  export type { WrapletApi } from "./Wraplet/types/WrapletApi";
16
16
  export type { WrapletApiFactoryArgs } from "./Wraplet/types/WrapletApiFactoryArgs";
17
17
  export type { Status } from "./Wraplet/types/Status";
18
- export { isWraplet, WrapletSymbol } from "./Wraplet/types/Wraplet";
18
+ export { isWraplet } from "./Wraplet/types/Wraplet";
19
19
  export * from "./Wraplet/createWrapletApi";
20
20
  export { createOuterDestroyCallback } from "./Wraplet/createOuterDestroyCallback";
21
21
  export { createOuterInitializeCallback } from "./Wraplet/createOuterInitializeCallback";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- class e extends Error{}class t extends Error{}class n extends Error{}class i extends Error{}class s extends Error{}class r extends Error{}class a extends Error{}class o extends Error{}class d extends Error{errors=[]}const l=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],c=Symbol("Wraplet");function p(e){return l(e,c)}function h(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function u(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function y(e){if(!h(e))return!1;for(const t in e){if(!h(e[t]))return!1;if(!u(e[t]))return!1}return!0}const f=Symbol("WrapletSet");function w(e){return l(e,f)}class D extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const m=Symbol("WrapletSetReadonly");class g extends D{[m]=!0;[f]=!0}function b(e,t,n=!0){const i=new d(e);for(const e of t)"rejected"===e.status&&i.errors.push(e.reason);if(0===i.errors.length)return null;if(n)throw i;return i}function z(e){return"function"==typeof e.querySelectorAll}function I(e){const t=e.wraplets;return w(t)?t:null}async function E(e,t){t(e);const n=e.childNodes;for(const e of n)await E(e,t)}async function v(e){const t=[];await E(e,e=>{const n=I(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)}),b("Some wraplets threw exceptions during destruction",await Promise.allSettled(t.map(e=>e.wraplet.destroy())))}const W=Symbol("DependencyManager");class L{static#e=new L;constructor(){}dumpError(e){console.dir(e,{depth:null})}static getGlobalLogger(){return this.#e}}function M(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const A=Symbol("MapTreeBuilder");class P{parent;[A]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new P(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=M(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}const S=Promise.resolve();class C{node;[W]=!0;logger;dependenciesAreInstantiated=!1;initializePromise=null;destroyPromise=null;syncPromise=null;status={isDestroyed:!1,isGettingDestroyed:!1,isGettingSynced:!1,isInitialized:!1,isGettingInitialized:!1};mapTree;directDependencies={};wrappedDependencies={};instantiatedDependencyListeners;initializedDependencyListeners;destroyedDependencyListeners;constructor(e,n,i={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the DDM is not a valid node.");if(y(n))this.mapTree=new P,this.mapTree.setMap(n);else{if("object"!=typeof(s=n)||null===s||!(A in s))throw new t("The map provided to the DDM is not a valid map.");this.mapTree=n}var s;const r=Object.assign(this.defaultOptions(),i);this.logger=r.logger,this.instantiatedDependencyListeners=r.dependencyInstantiatedListeners,this.initializedDependencyListeners=r.dependencyInitializedListeners,this.destroyedDependencyListeners=r.dependencyDestroyedListeners}initializeDependencies(){return this.status.isInitialized?S:(this.initializePromise||(this.initializePromise=(async()=>{try{this.status.isGettingInitialized=!0,await this.initializeDeps(),this.status.isInitialized=!0}finally{this.initializePromise=null,this.status.isGettingInitialized=!1}})()),this.initializePromise)}async initializeDeps(){const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t)return;const n=w(t)?Array.from(t):[t],i=await Promise.allSettled(n.map(async t=>{if(t.wraplet.status.isInitialized||t.wraplet.status.isGettingInitialized)return;await t.wraplet.initialize();const n=await Promise.allSettled((this.initializedDependencyListeners.get(e)||[]).map(e=>e(t)));b(`Errors in the DDM's dependency "${e}" initialize listeners.`,n)}));b(`Error at "${e}" dependency's initialization.`,i)})),t=b("Error at DDM's initialization.",e,!1);if(t)throw this.logger.dumpError(t),t}syncDependencies(){return this.syncPromise||(this.syncPromise=(async()=>{try{this.status.isGettingSynced=!0,this.instantiateDeps(!0),await this.initializeDeps(),await this.destroyDeps(!0)}finally{this.syncPromise=null,this.status.isGettingSynced=!1}})()),this.syncPromise}get map(){return this.mapTree.getMap()}instantiateDeps(e=!1){const t=this.directDependencies;if(z(this.node))for(const n in this.map){const i=this.map[n],s=i.multiple;if(this.validateMapItem(n,i),s){t[n]||(t[n]=new g);const e=t[n],s=this.instantiateMultipleDependencies(i,this.node,n);for(const t of s)e.add(t);continue}const r=this.instantiateSingleWrapletDependency(i,this.node,n);r!==t[n]&&(e&&r&&t[n]&&t[n].wraplet.destroy(),t[n]=r)}else{for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}this.dependenciesAreInstantiated=!0}}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new o("Dependencies are already instantiated.");this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.instantiateDeps(),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!w(n))throw new r("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new r("Internal logic error. Multiple instances wrapping the same element found in the DDM.");return i[0]}if(!p(n))throw new r("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,n,i){if(!e.selector)return this.directDependencies[i]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[i])throw new t("It's not possible to provide a single-type dependency manually and use selector at the same time.");const r=e.selector,a=this.findChildrenElements(r,n);if(this.validateElements(i,a,e),0===a.length)return null;if(a.length>1)throw new s(`${this.constructor.name}: More than one element was found for the "${i}" dependency. Selector used: "${r}".`);const o=a[0];return this.instantiateWrapletItem(i,e,o)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let s;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!p(i))throw new Error("Created dependency is not a Wraplet instance.");s=i}catch(n){if(n instanceof a&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,s);for(const t of this.instantiatedDependencyListeners.get(e)||[])t(s);return s}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new g;const s=this.findChildrenElements(i,t);this.validateElements(n,s,e);const r=new g;for(const t of s){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&r.add(i)}return r}addDependencyInstantiatedListener(e,t){const n=this.instantiatedDependencyListeners.get(e)||[];n.push(t),this.instantiatedDependencyListeners.set(e,n)}addDependencyInitializedListener(e,t){const n=this.initializedDependencyListeners.get(e)||[];n.push(t),this.initializedDependencyListeners.set(e,n)}addDependencyDestroyedListener(e,t){const n=this.destroyedDependencyListeners.get(e)||[];n.push(t),this.destroyedDependencyListeners.set(e,n)}setExistingInstance(e,n){if(this.map[e].multiple)throw new t("This method can only be used to set a single-value dependency.");if(!p(n))throw new t("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,n),this.directDependencies[e]=n}addExistingInstance(e,n){if(!this.map[e].multiple)throw new t("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,n);const i=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new g;i.add(n),this.directDependencies[e]=i}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=await Promise.allSettled((this.destroyedDependencyListeners.get(e)||[]).map(e=>e(t))),i=this.validateRequiredDependencyAfterRemoval(e);i&&n.push({status:"rejected",reason:i}),b(`Errors in the destruction callbacks of the "${e} dependency."`,n)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed&&null===this.directDependencies[e]?new n(`Required dependency "${e}" has been destroyed.`):null}destroyDependencies(){return this.status.isDestroyed?S:(this.destroyPromise||(this.destroyPromise=(async()=>{try{if(this.status.isGettingDestroyed=!0,this.initializePromise&&await this.initializePromise,!this.status.isInitialized)return this.status.isDestroyed=!0,void(this.status.isGettingDestroyed=!1);await this.destroyDeps(),this.status.isInitialized=!1,this.status.isDestroyed=!0}finally{this.destroyPromise=null,this.status.isGettingDestroyed=!1}})()),this.destroyPromise)}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new i("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){w(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,n){const i=n.selector,s=n.required;if(!i&&s&&(!this.directDependencies[e]||w(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new t(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,n){if(n.required)throw new t(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(t,n,i){if(0===n.length&&i.required)throw new e(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:new Map,dependencyInitializedListeners:new Map,dependencyDestroyedListeners:new Map,logger:L.getGlobalLogger()}}async destroyDeps(e=!1){const t=await Promise.allSettled(Object.entries(this.directDependencies).map(async([t,n])=>{if(!n||!this.map[t].destructible)return;let i=[];if(w(n))for(const e of n)i.push(e);else i.push(n);if(e){if(!this.map[t].selector)return;i=await async function(e,t){const n=new g(e);return await E(t,e=>{const t=I(e);if(t)for(const e of t)n.delete(e)}),Array.from(n)}(i,this.node)}b(`Errors during destruction of the "${t}" dependency.`,await Promise.allSettled(i.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)return e.wraplet.destroy()})))})),n=b("Errors during the dependencies destruction.",t,!1);if(n)throw this.logger.dumpError(n),n}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let s=n;if(r=e,Number.isInteger(r))for(let t=0;t<e;t++)s=s.getParent();else{if(!y(e))throw new Error("Invalid map argument.");s.setMap(e)}var r;return new C(t,s,i)}}}}class G{node;listeners=new Map;constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n);const i=this.listeners.get(this.node)||[];i.push({callback:t,event:e,options:n}),this.listeners.set(this.node,i)}addListenerTo(e,t,n,i,s=!0){if(!z(this.node))throw new Error("Target node is not a parent node. Cannot add listener to its child.");const r=[];if("string"==typeof e?r.push(...Array.from(this.node.querySelectorAll(e))):r.push(...e(this.node)),s&&0===r.length)throw new Error("No nodes found");for(const e of r){e.addEventListener(t,n,i);const s=this.listeners.get(e)||[];s.push({event:t,callback:n,options:i}),this.listeners.set(e,s)}}destroy(){for(const e of this.listeners){const t=e[0],n=e[1];for(const e of n)t.removeEventListener(e.event,e.callback,e.options)}this.listeners.clear()}}const x=Symbol("WrapletApi");function k(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(!n.isDestroyed&&(n.isGettingDestroyed=!0,!n.isGettingInitialized)){if(!n.isInitialized)throw new o("Wraplet cannot be destroyed before it is initialized.");t&&await t(),n.isGettingDestroyed=!1,n.isInitialized=!1,n.isDestroyed=!0;for(const t of[...e.destroyListeners].reverse())await t(e.wraplet);e.destroyListeners.length=0}})().finally(()=>{n=null}),n)}}function $(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(n.isDestroyed||n.isGettingDestroyed)throw new o("Wraplet cannot be initialized when destroyed or in the process of being destroyed");n.isInitialized||n.isGettingInitialized||(n.isGettingInitialized=!0,t&&await t(),n.isInitialized=!0,n.isGettingInitialized=!1,n.isGettingDestroyed&&await e.destroyCallback())})().finally(()=>{n=null}),n)}}const q=e=>{!function(e){if(!p(e.wraplet))throw new Error("Correct wraplet instance has to be provided.");if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},s=[],r=k({status:n,wraplet:t.wraplet,destroyListeners:s},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=I(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=$({status:n,destroyCallback:r,wraplet:t.wraplet},async()=>{t.initializeCallback&&await t.initializeCallback()}).bind(i);var o,d;return t.node&&(o=t.wraplet,(d=t.node).wraplets||(d.wraplets=new g),d.wraplets.add(o)),Object.assign(i,{[x]:!0,__destroyListeners:s,status:n,addDestroyListener:e=>{s.push(e)},initialize:a,destroy:r})};class T{node;[c]=!0;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new a(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){return this.buildWrapletApi(this.onInitialize.bind(this),this.onDestroy.bind(this))}buildWrapletApi(e,t){return q({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new G(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}onInitialize(){return S}onDestroy(){return S}static createWraplets(e,t,n=[]){if(this===T)throw new Error("You cannot instantiate an abstract class.");const i=[];let s;"function"==typeof t?s=t(e):(e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n)),s=e.querySelectorAll(`[${t}]`));for(const e of s)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class j extends T{dm;constructor(e){if(!l(e,W))throw new Error("AbstractDependentWraplet requires an instance implementing the DependencyManager interface.");super(e.node),this.dm=e,e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(async()=>{await this.dm.initializeDependencies(),await this.onInitialize.bind(this)()},async()=>{await this.onDestroy.bind(this)(),await this.dm.destroyDependencies()})}onDestroy(){return S}onInitialize(){return S}get d(){return this.dm.dependencies}static createDependencyManager(e,t){return new C(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===j)throw new Error("You cannot instantiate an abstract class.");const s=this,r=[];let a;if("function"==typeof t)a=t(e);else{if(e instanceof Element&&e.hasAttribute(t)){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}a=e.querySelectorAll(`[${t}]`)}for(const e of a){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}return r}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const s=this.createDependentWraplets(e,t,n,i);for(const e of s)await e.wraplet.initialize();return s}}class N extends D{[m]=!0}class O{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){b("There were errors during the node's initialization.",await Promise.allSettled(this.initializers.map(n=>n(e,t))))}async destroyNode(e){await v(e)}}export{j as AbstractDependentWraplet,T as AbstractWraplet,C as DDM,O as DNTM,g as DefaultWrapletSet,N as DefaultWrapletSetReadonly,i as DependenciesAreNotAvailableError,r as InternalLogicError,d as LifecycleAsyncErrors,o as LifecycleError,t as MapError,e as MissingRequiredDependencyError,n as RequiredDependencyDestroyedError,s as TooManyChildrenFoundError,a as UnsupportedNodeTypeError,c as WrapletSymbol,k as createOuterDestroyCallback,$ as createOuterInitializeCallback,q as createWrapletApi,v as destroyWrapletsRecursively,I as getWrapletsFromNode,p as isWraplet};
1
+ class e extends Error{}class t extends Error{}class n extends Error{}class i extends Error{}class s extends Error{}class r extends Error{}class a extends Error{}class o extends Error{}const d=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],c=Symbol("WrapletApi");function l(e){return"object"==typeof e&&null!==e&&d(e.wraplet,c)}function p(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function h(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function u(e){if(!p(e))return!1;for(const t in e){if(!p(e[t]))return!1;if(!h(e[t]))return!1}return!0}const y=Symbol("WrapletSet");function f(e){return d(e,y)}class w extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const D=Symbol("WrapletSetReadonly");class m extends w{[D]=!0;[y]=!0}const g=Promise.resolve();function b(e,t){if(0!==e.length)throw new AggregateError(e,`${t}`)}function z(e){return"function"==typeof e.querySelectorAll}function I(e){const t=e.wraplets;return f(t)?t:null}function E(e,t){const n=[e];for(;n.length>0;){const e=n.pop();t(e);const i=e.childNodes;for(let e=i.length-1;e>=0;e--)n.push(i[e])}}async function v(e){const t=[];E(e,e=>{const n=I(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)});const n=[];await Promise.all(t.map(async e=>{try{await e.wraplet.destroy()}catch(e){n.push(e)}})),b(n,"Some wraplets threw exceptions during destruction")}const A=Symbol("DependencyManager");function W(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const L=Symbol("MapTreeBuilder");class M{parent;[L]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new M(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=W(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}class P{node;[A]=!0;dependenciesAreInstantiated=!1;initializePromise=null;destroyPromise=null;syncPromise=null;status={isDestroyed:!1,isGettingDestroyed:!1,isGettingSynced:!1,isInitialized:!1,isGettingInitialized:!1};mapTree;directDependencies={};wrappedDependencies={};instantiatedDependencyListeners;initializedDependencyListeners;destroyedDependencyListeners;constructor(e,n,i={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the DDM is not a valid node.");if(u(n))this.mapTree=new M,this.mapTree.setMap(n);else{if("object"!=typeof(s=n)||null===s||!(L in s))throw new t("The map provided to the DDM is not a valid map.");this.mapTree=n}var s;const r=Object.assign(this.defaultOptions(),i);this.instantiatedDependencyListeners=r.dependencyInstantiatedListeners,this.initializedDependencyListeners=r.dependencyInitializedListeners,this.destroyedDependencyListeners=r.dependencyDestroyedListeners}initializeDependencies(){return this.status.isInitialized?g:(this.initializePromise||(this.initializePromise=(async()=>{try{this.status.isGettingInitialized=!0,await this.initializeDeps(),this.status.isInitialized=!0}finally{this.initializePromise=null,this.status.isGettingInitialized=!1}})()),this.initializePromise)}async initializeDeps(){const e=[];await Promise.all(Object.entries(this.directDependencies).map(async([t,n])=>{if(!n)return;const i=f(n)?Array.from(n):[n];await Promise.all(i.map(async n=>{if(n.wraplet.status.isInitialized||n.wraplet.status.isGettingInitialized)return;try{await n.wraplet.initialize()}catch(n){return void e.push(new AggregateError([n],`Error during initialization of the "${t}" dependency.`))}const i=[],s=this.initializedDependencyListeners.get(t);if(s){for(const e of s)try{await e(n)}catch(e){i.push(e)}i.length>0&&e.push(new AggregateError(i,`At least one listener of the "${t}" dependency threw exception`))}}))})),b(e,"Errors during the dependencies initialization.")}syncDependencies(){return this.syncPromise||(this.syncPromise=(async()=>{try{this.status.isGettingSynced=!0,this.instantiateDeps(!0),await this.initializeDeps(),await this.destroyDeps(!0)}finally{this.syncPromise=null,this.status.isGettingSynced=!1}})()),this.syncPromise}get map(){return this.mapTree.getMap()}instantiateDeps(e=!1){const t=this.directDependencies;if(z(this.node))for(const n in this.map){const i=this.map[n],s=i.multiple;if(this.validateMapItem(n,i),s){t[n]||(t[n]=new m);const e=t[n],s=this.instantiateMultipleDependencies(i,this.node,n);for(const t of s)e.add(t);continue}const r=this.instantiateSingleWrapletDependency(i,this.node,n);r!==t[n]&&(e&&r&&t[n]&&t[n].wraplet.destroy(),t[n]=r)}else{for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}this.dependenciesAreInstantiated=!0}}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new o("Dependencies are already instantiated.");this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.instantiateDeps(),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!f(n))throw new r("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new r("Internal logic error. Multiple instances wrapping the same element found in the DDM.");return i[0]}if(!l(n))throw new r("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,n,i){if(!e.selector)return this.directDependencies[i]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[i])throw new t("It's not possible to provide a single-type dependency manually and use selector at the same time.");const r=e.selector,a=this.findChildrenElements(r,n);if(this.validateElements(i,a,e),0===a.length)return null;if(a.length>1)throw new s(`${this.constructor.name}: More than one element was found for the "${i}" dependency. Selector used: "${r}".`);const o=a[0];return this.instantiateWrapletItem(i,e,o)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let s;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!l(i))throw new Error("Created dependency is not a Wraplet instance.");s=i}catch(n){if(n instanceof a&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,s);for(const t of this.instantiatedDependencyListeners.get(e)||[])t(s);return s}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new m;const s=this.findChildrenElements(i,t);this.validateElements(n,s,e);const r=new m;for(const t of s){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&r.add(i)}return r}addDependencyInstantiatedListener(e,t){const n=this.instantiatedDependencyListeners.get(e)||[];n.push(t),this.instantiatedDependencyListeners.set(e,n)}addDependencyInitializedListener(e,t){const n=this.initializedDependencyListeners.get(e)||[];n.push(t),this.initializedDependencyListeners.set(e,n)}addDependencyDestroyedListener(e,t){const n=this.destroyedDependencyListeners.get(e)||[];n.push(t),this.destroyedDependencyListeners.set(e,n)}setExistingInstance(e,n){if(this.map[e].multiple)throw new t("This method can only be used to set a single-value dependency.");if(!l(n))throw new t("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,n),this.directDependencies[e]=n}addExistingInstance(e,n){if(!this.map[e].multiple)throw new t("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,n);const i=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new m;i.add(n),this.directDependencies[e]=i}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=[],i=this.destroyedDependencyListeners.get(e);i&&i.length>0&&await Promise.all(i.map(async e=>{try{await e(t)}catch(e){n.push(e)}}));const s=this.validateRequiredDependencyAfterRemoval(e);s&&n.push(s),b(n,`Errors in the destruction callbacks of the "${e}" dependency.`)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed&&null===this.directDependencies[e]?new n(`Required dependency "${e}" has been destroyed.`):null}destroyDependencies(){return this.status.isDestroyed?g:(this.destroyPromise||(this.destroyPromise=(async()=>{try{if(this.status.isGettingDestroyed=!0,this.initializePromise&&await this.initializePromise,!this.status.isInitialized)return this.status.isDestroyed=!0,void(this.status.isGettingDestroyed=!1);await this.destroyDeps(),this.status.isInitialized=!1,this.status.isDestroyed=!0}finally{this.destroyPromise=null,this.status.isGettingDestroyed=!1}})()),this.destroyPromise)}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new i("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){f(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,n){const i=n.selector,s=n.required;if(!i&&s&&(!this.directDependencies[e]||f(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new t(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,n){if(n.required)throw new t(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(t,n,i){if(0===n.length&&i.required)throw new e(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:new Map,dependencyInitializedListeners:new Map,dependencyDestroyedListeners:new Map}}async destroyDeps(e=!1){const t=[];await Promise.all(Object.entries(this.directDependencies).map(async([n,i])=>{if(!i||!this.map[n].destructible)return;let s=f(i)?Array.from(i):[i];if(e){if(!this.map[n].selector)return;s=await async function(e,t){const n=new m(e);return E(t,e=>{const t=I(e);if(t)for(const e of t)n.delete(e)}),Array.from(n)}(s,this.node)}await Promise.all(s.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)try{await e.wraplet.destroy()}catch(e){t.push(new AggregateError([e],`There was an error during destruction of the "${n}" dependency.`))}}))})),b(t,"There were errors during the dependencies destruction.")}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let s=n;if(r=e,Number.isInteger(r))for(let t=0;t<e;t++)s=s.getParent();else{if(!u(e))throw new Error("Invalid map argument.");s.setMap(e)}var r;return new P(t,s,i)}}}}class C{node;listeners=new Map;constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n);const i=this.listeners.get(this.node)||[];i.push({callback:t,event:e,options:n}),this.listeners.set(this.node,i)}addListenerTo(e,t,n,i,s=!0){if(!z(this.node))throw new Error("Target node is not a parent node. Cannot add listener to its child.");const r=[];if("string"==typeof e?r.push(...Array.from(this.node.querySelectorAll(e))):r.push(...e(this.node)),s&&0===r.length)throw new Error("No nodes found");for(const e of r){e.addEventListener(t,n,i);const s=this.listeners.get(e)||[];s.push({event:t,callback:n,options:i}),this.listeners.set(e,s)}}destroy(){for(const e of this.listeners){const t=e[0],n=e[1];for(const e of n)t.removeEventListener(e.event,e.callback,e.options)}this.listeners.clear()}}function x(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(!n.isDestroyed&&(n.isGettingDestroyed=!0,!n.isGettingInitialized)){if(!n.isInitialized)throw new o("Wraplet cannot be destroyed before it is initialized.");t&&await t(),n.isGettingDestroyed=!1,n.isInitialized=!1,n.isDestroyed=!0;for(const t of[...e.destroyListeners].reverse())await t(e.wraplet);e.destroyListeners.length=0}})().finally(()=>{n=null}),n)}}function G(e,t){let n=null;return function(){return n||(n=(async()=>{const n=e.status;if(n.isDestroyed||n.isGettingDestroyed)throw new o("Wraplet cannot be initialized when destroyed or in the process of being destroyed");n.isInitialized||n.isGettingInitialized||(n.isGettingInitialized=!0,t&&await t(),n.isInitialized=!0,n.isGettingInitialized=!1,n.isGettingDestroyed&&await e.destroyCallback())})().finally(()=>{n=null}),n)}}const k=e=>{!function(e){if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},s=[],r=x({status:n,wraplet:t.wraplet,destroyListeners:s},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=I(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=G({status:n,destroyCallback:r,wraplet:t.wraplet},async()=>{t.initializeCallback&&await t.initializeCallback()}).bind(i);var o,d;return t.node&&(o=t.wraplet,(d=t.node).wraplets||(d.wraplets=new m),d.wraplets.add(o)),Object.assign(i,{[c]:!0,__destroyListeners:s,status:n,addDestroyListener:e=>{s.push(e)},initialize:a,destroy:r})};class S{node;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new a(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){return this.buildWrapletApi(this.onInitialize.bind(this),this.onDestroy.bind(this))}buildWrapletApi(e,t){return k({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new C(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}onInitialize(){return g}onDestroy(){return g}static createWraplets(e,t,n=[]){if(this===S)throw new Error("You cannot instantiate an abstract class.");const i=[];let s;"function"==typeof t?s=t(e):(e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n)),s=e.querySelectorAll(`[${t}]`));for(const e of s)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class $ extends S{dm;constructor(e){if(!d(e,A))throw new Error("AbstractDependentWraplet requires an instance implementing the DependencyManager interface.");super(e.node),this.dm=e,e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(async()=>{await this.dm.initializeDependencies(),await this.onInitialize.bind(this)()},async()=>{await this.onDestroy.bind(this)(),await this.dm.destroyDependencies()})}onDestroy(){return g}onInitialize(){return g}get d(){return this.dm.dependencies}static createDependencyManager(e,t){return new P(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===$)throw new Error("You cannot instantiate an abstract class.");const s=this,r=[];let a;if("function"==typeof t)a=t(e);else{if(e instanceof Element&&e.hasAttribute(t)){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}a=e.querySelectorAll(`[${t}]`)}for(const e of a){const t=s.createDependencyManager(e,n);r.push(new this(t,...i))}return r}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const s=this.createDependentWraplets(e,t,n,i);for(const e of s)await e.wraplet.initialize();return s}}class T extends w{[D]=!0}class q{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){const n=[];if(await Promise.all(this.initializers.map(async i=>{try{await i(e,t)}catch(e){n.push(e)}})),n.length>0)throw new AggregateError(n,"There were errors during the node's initialization.")}async destroyNode(e){await v(e)}}export{$ as AbstractDependentWraplet,S as AbstractWraplet,P as DDM,q as DNTM,m as DefaultWrapletSet,T as DefaultWrapletSetReadonly,i as DependenciesAreNotAvailableError,r as InternalLogicError,o as LifecycleError,t as MapError,e as MissingRequiredDependencyError,n as RequiredDependencyDestroyedError,s as TooManyChildrenFoundError,a as UnsupportedNodeTypeError,x as createOuterDestroyCallback,G as createOuterInitializeCallback,k as createWrapletApi,v as destroyWrapletsRecursively,I as getWrapletsFromNode,l as isWraplet};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":"AAAO,MAAAA,UAAAC,OAEA,MAAAC,UAAAD,OAEA,MAAAE,UA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AAAiN,KAEA,CACA,iBAAAE,CAAAnN,SACcS,EAA0BT,EACxC","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/createLifecycleAsyncError.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Logger/ConsoleLogger.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/utils/utils.ts","webpack://wraplet/./src/DependencyManager/DDM.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DNTM.ts"],"sourcesContent":["export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\nexport class LifecycleAsyncErrors extends Error {\n errors = [];\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletSymbol = Symbol(\"Wraplet\");\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { LifecycleAsyncErrors } from \"../errors\";\nexport function createLifecycleAsyncError(message, results, throwError = true) {\n const error = new LifecycleAsyncErrors(message);\n for (const result of results) {\n if (result.status === \"rejected\") {\n error.errors.push(result.reason);\n }\n }\n if (error.errors.length === 0) {\n return null;\n }\n if (throwError) {\n throw error;\n }\n return error;\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport async function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function findWrapletsOutsideTheTree(wraplets, node) {\n const wrapletsOutsideTree = new DefaultWrapletSet(wraplets);\n await actOnNodesRecursively(node, (node) => {\n const nodeWraplets = getWrapletsFromNode(node);\n if (!nodeWraplets) {\n return;\n }\n for (const wraplet of nodeWraplets) {\n wrapletsOutsideTree.delete(wraplet);\n }\n });\n return Array.from(wrapletsOutsideTree);\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n await actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const results = await Promise.allSettled(allWraplets.map((wraplet) => wraplet.wraplet.destroy()));\n createLifecycleAsyncError(\"Some wraplets threw exceptions during destruction\", results);\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export class ConsoleLogger {\n static #instance = new ConsoleLogger();\n constructor() { }\n dumpError(error) {\n console.dir(error, { depth: null });\n }\n static getGlobalLogger() {\n return this.#instance;\n }\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","export const RESOLVE = Promise.resolve();\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { findWrapletsOutsideTheTree, isParentNode, } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { ConsoleLogger } from \"../Logger/ConsoleLogger\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class DDM {\n node;\n [DependencyManagerSymbol] = true;\n logger;\n dependenciesAreInstantiated = false;\n initializePromise = null;\n destroyPromise = null;\n syncPromise = null;\n status = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isGettingSynced: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n instantiatedDependencyListeners;\n initializedDependencyListeners;\n destroyedDependencyListeners;\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the DDM is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the DDM is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.logger = optionsWithDefaults.logger;\n this.instantiatedDependencyListeners =\n optionsWithDefaults.dependencyInstantiatedListeners;\n this.initializedDependencyListeners =\n optionsWithDefaults.dependencyInitializedListeners;\n this.destroyedDependencyListeners =\n optionsWithDefaults.dependencyDestroyedListeners;\n }\n initializeDependencies() {\n if (this.status.isInitialized) {\n return RESOLVE;\n }\n if (this.initializePromise) {\n return this.initializePromise;\n }\n this.initializePromise = (async () => {\n try {\n this.status.isGettingInitialized = true;\n await this.initializeDeps();\n this.status.isInitialized = true;\n }\n finally {\n this.initializePromise = null;\n this.status.isGettingInitialized = false;\n }\n })();\n return this.initializePromise;\n }\n /**\n * Initialize dependencies.\n */\n async initializeDeps() {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n await wraplet.wraplet.initialize();\n const listenerResults = await Promise.allSettled((this.initializedDependencyListeners.get(id) || []).map((fn) => fn(wraplet)));\n createLifecycleAsyncError(`Errors in the DDM's dependency \"${id}\" initialize listeners.`, listenerResults);\n }));\n createLifecycleAsyncError(`Error at \"${id}\" dependency's initialization.`, results);\n }));\n const error = createLifecycleAsyncError(`Error at DDM's initialization.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n syncDependencies() {\n if (this.syncPromise) {\n return this.syncPromise;\n }\n this.syncPromise = (async () => {\n try {\n this.status.isGettingSynced = true;\n this.instantiateDeps(true);\n await this.initializeDeps();\n await this.destroyDeps(true);\n }\n finally {\n this.syncPromise = null;\n this.status.isGettingSynced = false;\n }\n })();\n return this.syncPromise;\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDeps(sync = false) {\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n const newDep = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n // This might happen when we are syncing and the dependency hasn't changed.\n if (newDep === dependencies[id]) {\n continue;\n }\n // If we are syncing, invoke destruction of the old dependency.\n if (sync && newDep && dependencies[id]) {\n dependencies[id].wraplet.destroy();\n }\n dependencies[id] = newDep;\n }\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.instantiateDeps();\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the DDM.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners.get(id) || []) {\n listener(wraplet);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyInstantiatedListener(id, callback) {\n const listeners = this.instantiatedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.instantiatedDependencyListeners.set(id, listeners);\n }\n addDependencyInitializedListener(id, callback) {\n const listeners = this.initializedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.initializedDependencyListeners.set(id, listeners);\n }\n addDependencyDestroyedListener(id, callback) {\n const listeners = this.destroyedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.destroyedDependencyListeners.set(id, listeners);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const results = await Promise.allSettled((this.destroyedDependencyListeners.get(id) || []).map((fn) => fn(w)));\n // Collect the required-dependency error alongside listener results\n // so that everything surfaces through the same LifecycleError mechanism.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n results.push({ status: \"rejected\", reason: requiredError });\n }\n createLifecycleAsyncError(`Errors in the destruction callbacks of the \"${id} dependency.\"`, results);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the DDM\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required &&\n !this.status.isGettingDestroyed &&\n // Don't allow removing a required dependency only if there is no\n // replacement in place.\n this.directDependencies[id] === null) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n destroyDependencies() {\n if (this.status.isDestroyed) {\n return RESOLVE;\n }\n if (this.destroyPromise) {\n return this.destroyPromise;\n }\n this.destroyPromise = (async () => {\n try {\n this.status.isGettingDestroyed = true;\n if (this.initializePromise) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n await this.initializePromise;\n }\n if (!this.status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.status.isDestroyed = true;\n this.status.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.status.isInitialized = false;\n this.status.isDestroyed = true;\n }\n finally {\n this.destroyPromise = null;\n this.status.isGettingDestroyed = false;\n }\n })();\n return this.destroyPromise;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: new Map(),\n dependencyInitializedListeners: new Map(),\n dependencyDestroyedListeners: new Map(),\n logger: ConsoleLogger.getGlobalLogger(),\n };\n }\n async destroyDeps(sync = false) {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n let wraplets = [];\n if (isWrapletSet(dependency)) {\n for (const item of dependency) {\n wraplets.push(item);\n }\n }\n else {\n wraplets.push(dependency);\n }\n if (sync) {\n if (!this.map[id][\"selector\"]) {\n return;\n }\n wraplets = await findWrapletsOutsideTheTree(wraplets, this.node);\n }\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n return wraplet.wraplet.destroy();\n }));\n createLifecycleAsyncError(`Errors during destruction of the \"${id}\" dependency.`, results);\n }));\n const error = createLifecycleAsyncError(`Errors during the dependencies destruction.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new DDM(node, currentMap, data);\n },\n };\n }\n}\n","import { isParentNode } from \"../NodeTreeManager/utils\";\nexport class NodeManager {\n node;\n listeners = new Map();\n constructor(node) {\n this.node = node;\n }\n /**\n * Add a listener to the current node.\n */\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(this.node) || [];\n listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n this.listeners.set(this.node, listeners);\n }\n /**\n * Add a listener to one of the descendants.\n *\n * Note: Most of the time it's not recommended to use this\n * method because it makes a wraplet impure.\n *\n * Ideally, wraplet should directly interact only with its\n * own node. However, you can make a wraplet impure if you\n * know what you are doing.\n */\n addListenerTo(target, eventName, callback, options, required = true) {\n if (!isParentNode(this.node)) {\n throw new Error(\"Target node is not a parent node. Cannot add listener to its child.\");\n }\n const nodes = [];\n if (typeof target === \"string\") {\n nodes.push(...Array.from(this.node.querySelectorAll(target)));\n }\n else {\n nodes.push(...target(this.node));\n }\n if (required && nodes.length === 0) {\n throw new Error(\"No nodes found\");\n }\n for (const node of nodes) {\n node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(node) || [];\n listeners.push({\n event: eventName,\n callback,\n options,\n });\n this.listeners.set(node, listeners);\n }\n }\n destroy() {\n for (const listenerData of this.listeners) {\n const node = listenerData[0];\n const listeners = listenerData[1];\n for (const listener of listeners) {\n node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n }\n this.listeners.clear();\n }\n}\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed) {\n return;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...args.destroyListeners].reverse()) {\n await listener(args.wraplet);\n }\n args.destroyListeners.length = 0;\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed || status.isGettingDestroyed) {\n throw new LifecycleError(\"Wraplet cannot be initialized when destroyed or in the process of being destroyed\");\n }\n if (status.isInitialized || status.isGettingInitialized) {\n return;\n }\n status.isGettingInitialized = true;\n if (initializeLogic) {\n await initializeLogic();\n }\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await args.destroyCallback();\n }\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { isWraplet } from \"./types/Wraplet\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (!isWraplet(args.wraplet)) {\n throw new Error(\"Correct wraplet instance has to be provided.\");\n }\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n // Note that it's added immediately without initialization required.\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { UnsupportedNodeTypeError } from \"../errors\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n return this.buildWrapletApi(this.onInitialize.bind(this), this.onDestroy.bind(this));\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeGuard` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n onInitialize() {\n return RESOLVE;\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n onDestroy() {\n return RESOLVE;\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { DDM } from \"../DependencyManager/DDM\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing the DependencyManager interface.\");\n }\n super(dm.node);\n this.dm = dm;\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(async () => {\n await this.dm.initializeDependencies();\n await this.onInitialize.bind(this)();\n }, async () => {\n await this.onDestroy.bind(this)();\n await this.dm.destroyDependencies();\n });\n }\n onDestroy() {\n return RESOLVE;\n }\n onInitialize() {\n return RESOLVE;\n }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n static createDependencyManager(node, map) {\n return new DDM(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createDependentWraplets(node, attribute, map, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated and initialized wraplets.\n */\n static async createAndInitializeDependentWraplets(node, attribute, map, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, attribute, map, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport class DNTM {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const results = await Promise.allSettled(this.initializers.map((initializer) => initializer(node, context)));\n createLifecycleAsyncError(`There were errors during the node's initialization.`, results);\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","LifecycleAsyncErrors","errors","is","object","symbol","WrapletSymbol","Symbol","isWraplet","isSimpleObject","input","Object","getPrototypeOf","prototype","isDependencyMapItem","item","key","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","createLifecycleAsyncError","message","throwError","error","result","status","reason","length","isParentNode","node","querySelectorAll","getWrapletsFromNode","wraplets","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","allWraplets","wraplet","isGettingDestroyed","isDestroyed","Promise","allSettled","map","destroy","DependencyManagerSymbol","ConsoleLogger","static","constructor","dumpError","console","dir","depth","getGlobalLogger","instance","addDefaultsToDependencyDefinition","definition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","RESOLVE","resolve","DDM","logger","dependenciesAreInstantiated","initializePromise","destroyPromise","syncPromise","isGettingSynced","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","instantiatedDependencyListeners","initializedDependencyListeners","destroyedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","initializeDeps","entries","dependency","initialize","listenerResults","get","fn","syncDependencies","instantiateDeps","destroyDeps","sync","dependencies","dependencyDefinition","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","newDep","instantiateSingleWrapletDependency","validateMapItemForNonParent","instantiateDependencies","wrapDependencies","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","Class","data","e","required","warn","prepareIndividualWraplet","listener","childElements","items","addDependencyInstantiatedListener","listeners","set","addDependencyInitializedListener","addDependencyDestroyedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDependencies","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","target","Map","wrapletsOutsideTree","nodeWraplets","findWrapletsOutsideTheTree","createInjector","map_or_position","currentMap","Number","isInteger","i","NodeManager","addListener","eventName","addEventListener","event","addListenerTo","nodes","listenerData","removeEventListener","clear","WrapletApiSymbol","createOuterDestroyCallback","destroyLogic","promise","destroyListeners","reverse","finally","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","value","buildWrapletApi","onInitialize","onDestroy","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","Element","hasAttribute","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DNTM","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
1
+ {"version":3,"file":"index.js","mappings":"AAAO,MAAAA,UAAAC,OAEA,MAAAC,UAAAD,OAEA,MAAAE,UAAAF,OAEA,MAAAG,UAAAH,OAE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src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/utils.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/DependencyManager/DDM.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DNTM.ts"],"sourcesContent":["export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { is } from \"../../utils/is\";\nimport { WrapletApiSymbol } from \"./WrapletApi\";\nexport function isWraplet(value) {\n return (typeof value === \"object\" &&\n value !== null &&\n is(value.wraplet, WrapletApiSymbol));\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","export const RESOLVE = Promise.resolve();\nexport function throwIfErrors(errors, message) {\n if (errors.length === 0)\n return;\n throw new AggregateError(errors, `${message}`);\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { throwIfErrors } from \"../utils/utils\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport function actOnNodesRecursively(node, callback) {\n const stack = [node];\n while (stack.length > 0) {\n const current = stack.pop();\n callback(current);\n const children = current.childNodes;\n for (let i = children.length - 1; i >= 0; i--) {\n stack.push(children[i]);\n }\n }\n}\nexport async function findWrapletsOutsideTheTree(wraplets, node) {\n const wrapletsOutsideTree = new DefaultWrapletSet(wraplets);\n actOnNodesRecursively(node, (node) => {\n const nodeWraplets = getWrapletsFromNode(node);\n if (!nodeWraplets) {\n return;\n }\n for (const wraplet of nodeWraplets) {\n wrapletsOutsideTree.delete(wraplet);\n }\n });\n return Array.from(wrapletsOutsideTree);\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const errors = [];\n await Promise.all(allWraplets.map(async (wraplet) => {\n try {\n await wraplet.wraplet.destroy();\n }\n catch (error) {\n errors.push(error);\n }\n }));\n throwIfErrors(errors, \"Some wraplets threw exceptions during destruction\");\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { findWrapletsOutsideTheTree, isParentNode, } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nimport { RESOLVE, throwIfErrors } from \"../utils/utils\";\nexport class DDM {\n node;\n [DependencyManagerSymbol] = true;\n dependenciesAreInstantiated = false;\n initializePromise = null;\n destroyPromise = null;\n syncPromise = null;\n status = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isGettingSynced: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n instantiatedDependencyListeners;\n initializedDependencyListeners;\n destroyedDependencyListeners;\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the DDM is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the DDM is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.instantiatedDependencyListeners =\n optionsWithDefaults.dependencyInstantiatedListeners;\n this.initializedDependencyListeners =\n optionsWithDefaults.dependencyInitializedListeners;\n this.destroyedDependencyListeners =\n optionsWithDefaults.dependencyDestroyedListeners;\n }\n initializeDependencies() {\n if (this.status.isInitialized) {\n return RESOLVE;\n }\n if (this.initializePromise) {\n return this.initializePromise;\n }\n this.initializePromise = (async () => {\n try {\n this.status.isGettingInitialized = true;\n await this.initializeDeps();\n this.status.isInitialized = true;\n }\n finally {\n this.initializePromise = null;\n this.status.isGettingInitialized = false;\n }\n })();\n return this.initializePromise;\n }\n /**\n * Initialize dependencies.\n */\n async initializeDeps() {\n const errors = [];\n await Promise.all(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n await Promise.all(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n try {\n await wraplet.wraplet.initialize();\n }\n catch (error) {\n errors.push(new AggregateError([error], `Error during initialization of the \"${id}\" dependency.`));\n return;\n }\n const listenersErrors = [];\n const listeners = this.initializedDependencyListeners.get(id);\n if (listeners) {\n for (const fn of listeners) {\n try {\n await fn(wraplet);\n }\n catch (error) {\n listenersErrors.push(error);\n }\n }\n if (listenersErrors.length > 0) {\n errors.push(new AggregateError(listenersErrors, `At least one listener of the \"${id}\" dependency threw exception`));\n }\n }\n }));\n }));\n throwIfErrors(errors, `Errors during the dependencies initialization.`);\n }\n syncDependencies() {\n if (this.syncPromise) {\n return this.syncPromise;\n }\n this.syncPromise = (async () => {\n try {\n this.status.isGettingSynced = true;\n this.instantiateDeps(true);\n await this.initializeDeps();\n await this.destroyDeps(true);\n }\n finally {\n this.syncPromise = null;\n this.status.isGettingSynced = false;\n }\n })();\n return this.syncPromise;\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDeps(sync = false) {\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n const newDep = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n // This might happen when we are syncing and the dependency hasn't changed.\n if (newDep === dependencies[id]) {\n continue;\n }\n // If we are syncing, invoke destruction of the old dependency.\n if (sync && newDep && dependencies[id]) {\n dependencies[id].wraplet.destroy();\n }\n dependencies[id] = newDep;\n }\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.instantiateDeps();\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the DDM.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners.get(id) || []) {\n listener(wraplet);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyInstantiatedListener(id, callback) {\n const listeners = this.instantiatedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.instantiatedDependencyListeners.set(id, listeners);\n }\n addDependencyInitializedListener(id, callback) {\n const listeners = this.initializedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.initializedDependencyListeners.set(id, listeners);\n }\n addDependencyDestroyedListener(id, callback) {\n const listeners = this.destroyedDependencyListeners.get(id) || [];\n listeners.push(callback);\n this.destroyedDependencyListeners.set(id, listeners);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const errors = [];\n const listeners = this.destroyedDependencyListeners.get(id);\n if (listeners && listeners.length > 0) {\n await Promise.all(listeners.map(async (fn) => {\n try {\n await fn(w);\n }\n catch (error) {\n errors.push(error);\n }\n }));\n }\n // Collect the required-dependency error alongside listener errors\n // so that everything surfaces through the same error-aggregation pipeline.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n errors.push(requiredError);\n }\n throwIfErrors(errors, `Errors in the destruction callbacks of the \"${id}\" dependency.`);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the DDM\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required &&\n !this.status.isGettingDestroyed &&\n // Don't allow removing a required dependency only if there is no\n // replacement in place.\n this.directDependencies[id] === null) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n destroyDependencies() {\n if (this.status.isDestroyed) {\n return RESOLVE;\n }\n if (this.destroyPromise) {\n return this.destroyPromise;\n }\n this.destroyPromise = (async () => {\n try {\n this.status.isGettingDestroyed = true;\n if (this.initializePromise) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n await this.initializePromise;\n }\n if (!this.status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.status.isDestroyed = true;\n this.status.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.status.isInitialized = false;\n this.status.isDestroyed = true;\n }\n finally {\n this.destroyPromise = null;\n this.status.isGettingDestroyed = false;\n }\n })();\n return this.destroyPromise;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: new Map(),\n dependencyInitializedListeners: new Map(),\n dependencyDestroyedListeners: new Map(),\n };\n }\n async destroyDeps(sync = false) {\n const errors = [];\n await Promise.all(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n let wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n if (sync) {\n if (!this.map[id][\"selector\"]) {\n return;\n }\n wraplets = await findWrapletsOutsideTheTree(wraplets, this.node);\n }\n await Promise.all(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n try {\n await wraplet.wraplet.destroy();\n }\n catch (error) {\n errors.push(new AggregateError([error], `There was an error during destruction of the \"${id}\" dependency.`));\n }\n }));\n }));\n throwIfErrors(errors, `There were errors during the dependencies destruction.`);\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new DDM(node, currentMap, data);\n },\n };\n }\n}\n","import { isParentNode } from \"../NodeTreeManager/utils\";\nexport class NodeManager {\n node;\n listeners = new Map();\n constructor(node) {\n this.node = node;\n }\n /**\n * Add a listener to the current node.\n */\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(this.node) || [];\n listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n this.listeners.set(this.node, listeners);\n }\n /**\n * Add a listener to one of the descendants.\n *\n * Note: Most of the time it's not recommended to use this\n * method because it makes a wraplet impure.\n *\n * Ideally, wraplet should directly interact only with its\n * own node. However, you can make a wraplet impure if you\n * know what you are doing.\n */\n addListenerTo(target, eventName, callback, options, required = true) {\n if (!isParentNode(this.node)) {\n throw new Error(\"Target node is not a parent node. Cannot add listener to its child.\");\n }\n const nodes = [];\n if (typeof target === \"string\") {\n nodes.push(...Array.from(this.node.querySelectorAll(target)));\n }\n else {\n nodes.push(...target(this.node));\n }\n if (required && nodes.length === 0) {\n throw new Error(\"No nodes found\");\n }\n for (const node of nodes) {\n node.addEventListener(eventName, callback, options);\n const listeners = this.listeners.get(node) || [];\n listeners.push({\n event: eventName,\n callback,\n options,\n });\n this.listeners.set(node, listeners);\n }\n }\n destroy() {\n for (const listenerData of this.listeners) {\n const node = listenerData[0];\n const listeners = listenerData[1];\n for (const listener of listeners) {\n node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n }\n this.listeners.clear();\n }\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed) {\n return;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...args.destroyListeners].reverse()) {\n await listener(args.wraplet);\n }\n args.destroyListeners.length = 0;\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { LifecycleError } from \"../errors\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n let promise = null;\n return function () {\n if (promise) {\n return promise;\n }\n promise = (async () => {\n const status = args.status;\n if (status.isDestroyed || status.isGettingDestroyed) {\n throw new LifecycleError(\"Wraplet cannot be initialized when destroyed or in the process of being destroyed\");\n }\n if (status.isInitialized || status.isGettingInitialized) {\n return;\n }\n status.isGettingInitialized = true;\n if (initializeLogic) {\n await initializeLogic();\n }\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await args.destroyCallback();\n }\n })().finally(() => {\n promise = null;\n });\n return promise;\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n // Note that it's added immediately without initialization required.\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { UnsupportedNodeTypeError } from \"../errors\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractWraplet {\n node;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n return this.buildWrapletApi(this.onInitialize.bind(this), this.onDestroy.bind(this));\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeGuard` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n onInitialize() {\n return RESOLVE;\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n onDestroy() {\n return RESOLVE;\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { DDM } from \"../DependencyManager/DDM\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nimport { RESOLVE } from \"../utils/utils\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing the DependencyManager interface.\");\n }\n super(dm.node);\n this.dm = dm;\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(async () => {\n await this.dm.initializeDependencies();\n await this.onInitialize.bind(this)();\n }, async () => {\n await this.onDestroy.bind(this)();\n await this.dm.destroyDependencies();\n });\n }\n onDestroy() {\n return RESOLVE;\n }\n onInitialize() {\n return RESOLVE;\n }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n static createDependencyManager(node, map) {\n return new DDM(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated wraplets.\n */\n static createDependentWraplets(node, attribute, map, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n let elements;\n if (typeof attribute === \"function\") {\n elements = attribute(node);\n }\n else {\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n elements = node.querySelectorAll(`[${attribute}]`);\n }\n for (const element of elements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n *\n * @param node - The ParentNode to instantiate wraplets on.\n * @param attribute - The attribute to look for or a function to retrieve nodes.\n * @param map - The dependency map for the wraplets.\n * @param additional_args - Additional arguments to pass to the wraplet constructor.\n *\n * @returns An array of instantiated and initialized wraplets.\n */\n static async createAndInitializeDependentWraplets(node, attribute, map, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, attribute, map, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport class DNTM {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const errors = [];\n await Promise.all(this.initializers.map(async (initializer) => {\n try {\n await initializer(node, context);\n }\n catch (error) {\n errors.push(error);\n }\n }));\n if (errors.length > 0) {\n throw new AggregateError(errors, `There were errors during the node's initialization.`);\n }\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","is","object","symbol","WrapletApiSymbol","Symbol","isWraplet","value","wraplet","isSimpleObject","input","Object","getPrototypeOf","prototype","isDependencyMapItem","item","key","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","RESOLVE","Promise","resolve","throwIfErrors","errors","message","length","AggregateError","isParentNode","node","querySelectorAll","getWrapletsFromNode","wraplets","actOnNodesRecursively","stack","current","pop","children","childNodes","i","async","destroyWrapletsRecursively","allWraplets","status","isGettingDestroyed","isDestroyed","all","map","destroy","error","DependencyManagerSymbol","addDefaultsToDependencyDefinition","definition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","constructor","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","DDM","dependenciesAreInstantiated","initializePromise","destroyPromise","syncPromise","isGettingSynced","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","instantiatedDependencyListeners","initializedDependencyListeners","destroyedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","initializeDeps","entries","dependency","initialize","listenersErrors","listeners","get","fn","syncDependencies","instantiateDeps","destroyDeps","sync","dependencies","dependencyDefinition","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","newDep","instantiateSingleWrapletDependency","validateMapItemForNonParent","instantiateDependencies","wrapDependencies","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","instance","Class","data","e","required","console","warn","prepareIndividualWraplet","listener","childElements","items","addDependencyInstantiatedListener","set","addDependencyInitializedListener","addDependencyDestroyedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDependencies","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","target","Map","wrapletsOutsideTree","nodeWraplets","findWrapletsOutsideTheTree","createInjector","map_or_position","currentMap","Number","isInteger","NodeManager","addListener","eventName","addEventListener","event","addListenerTo","nodes","listenerData","removeEventListener","clear","createOuterDestroyCallback","destroyLogic","promise","destroyListeners","reverse","finally","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","buildWrapletApi","onInitialize","onDestroy","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","result","Element","hasAttribute","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DNTM","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
@@ -1 +1,2 @@
1
1
  export declare const RESOLVE: Promise<void>;
2
+ export declare function throwIfErrors(errors: Error[], message: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wraplet",
3
- "version": "1.0.0-beta.22",
3
+ "version": "1.0.0-beta.24",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -20,9 +20,15 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
- "dependencies": {},
23
+ "size-limit": [
24
+ {
25
+ "path": "dist/index.js",
26
+ "limit": "5 kB"
27
+ }
28
+ ],
24
29
  "devDependencies": {
25
30
  "@eslint/js": "^10.0.1",
31
+ "@size-limit/preset-small-lib": "^12.1.0",
26
32
  "@types/jest": "^30.0.0",
27
33
  "@types/node": "^25.8.0",
28
34
  "@types/webpack": "^5.28.5",
@@ -36,6 +42,7 @@
36
42
  "jest-environment-jsdom": "^30.4.1",
37
43
  "prettier": "^3.8.3",
38
44
  "prettier-eslint": "^16.4.2",
45
+ "size-limit": "^12.1.0",
39
46
  "ts-jest": "^29.4.9",
40
47
  "ts-loader": "^9.5.7",
41
48
  "tsx": "^4.22.1",
@@ -51,6 +58,9 @@
51
58
  "dev:watch": "webpack --mode development --watch --config ./webpack.config.ts",
52
59
  "lint": "tsc --noemit && npx eslint './src/**/*.ts' './tests/**/*.ts'",
53
60
  "lint:fix": "npm exec eslint './src/**/*.ts' './tests/**/*.ts' --fix",
54
- "tests": "node --unhandled-rejections=throw ./node_modules/jest/bin/jest.js --coverage --detectOpenHandles"
61
+ "tests": "node --unhandled-rejections=throw ./node_modules/jest/bin/jest.js --coverage --detectOpenHandles",
62
+ "tests:perf": "node --env-file=.env.perf --unhandled-rejections=throw --expose-gc ./node_modules/jest/bin/jest.js --config jest.config.ts --runInBand",
63
+ "tests:all": "npm run tests && npm run tests:perf",
64
+ "size": "size-limit"
55
65
  }
56
66
  }
@@ -1,7 +0,0 @@
1
- import { Logger } from "./types/Logger";
2
- export declare class ConsoleLogger implements Logger {
3
- #private;
4
- private constructor();
5
- dumpError(error: Error): void;
6
- static getGlobalLogger(): Logger;
7
- }
@@ -1,3 +0,0 @@
1
- export interface Logger {
2
- dumpError(error: Error): void;
3
- }
@@ -1,2 +0,0 @@
1
- import { LifecycleAsyncErrors } from "../errors";
2
- export declare function createLifecycleAsyncError(message: string, results: PromiseSettledResult<any>[], throwError?: boolean): LifecycleAsyncErrors | null;