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,QAAA,IAAA,CAAK,iBAAA,CAAkB,OAAO,KAAK,CAAA;AAAA,MACvC;AAEA,MAAA,IAAA,CAAK,iBAAA,CAAkB,OAAO,KAAK,CAAA;AAAA,IACvC,CAAA,MAAO;AACH,MAAA,IAAA,CAAK,iBAAA,CAAkB,GAAA,CAAI,KAAA,EAAO,KAAA,GAAQ,CAAC,CAAA;AAAA,IAC/C;AAAA,EACJ;AACJ;AA5Ia,UAAA,GAAN,eAAA,CAAA;AAAA,EAJN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,OAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACY,UAAA,CAAA","file":"Are.context.mjs","sourcesContent":["import { A_Context, A_Fragment } from \"@adaas/a-concept\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\nimport { A_SignalVector } from \"@adaas/a-utils/a-signal\";\nimport { AreNode } from \"@adaas/are/node/AreNode.entity\";\nimport { AreInstruction } from \"@adaas/are/instruction/AreInstruction.entity\";\nimport { A_ExecutionContext } from \"@adaas/a-utils/a-execution\";\n\n\n\n@A_Frame.Define({\n    namespace: 'A-ARE',\n    description: 'Context fragment for the A-Concept Rendering Engine (ARE) framework, serving as a foundational component for managing shared state and configurations within the ARE environment. This Context uses to encapsulate global settings, resources, and utilities that can be accessed by various ARE components and entities during the rendering and interaction processes.'\n})\nexport class AreContext extends A_ExecutionContext {\n\n    /**\n     * The source string represents the original template or input from which the ARE scene is generated. This can be used for debugging, error reporting, or any features that require access to the raw template data. The roots array holds references to the root nodes of the ARE scene, allowing for easy access and management of the top-level components in the rendering hierarchy. The signalsMap is a mapping between root nodes and their associated signal vectors, enabling efficient management of reactive updates and interactions within the ARE framework based on changes in the application state or user input.\n     */\n    protected _source: string;\n    /**\n     * The roots array holds references to the root nodes of the ARE scene, allowing for easy access and management of the top-level components in the rendering hierarchy. The signalsMap is a mapping between root nodes and their associated signal vectors, enabling efficient management of reactive updates and interactions within the ARE framework based on changes in the application state or user input.\n     */\n    protected _roots: Array<AreNode> = [];\n    /**\n     * This property stores a map between root node and conditions that should be met to render particular component inside the root node. This can be used to manage complex rendering logic and to optimize performance by ensuring that components are only rendered when necessary based on the defined conditions.\n     */\n    protected _signalsMap: Map<string, A_SignalVector> = new Map();\n\n    protected _performance = new Map<string, number>();\n    protected _performanceStart = new Map<string, number>();\n    protected _performanceDepth = new Map<string, number>();\n\n    /**\n     * The global object can be used to store any global data or configurations that need to be accessed across different components and entities within the ARE framework. This can include things like theme settings, user preferences, or any other shared data that is relevant to the entire scene or application. By centralizing this information in the context, it allows for easier management and access to global state without needing to pass it through multiple layers of components or entities.\n     */\n    get globals() {\n        return this.get('globals') || {};\n    }\n\n\n    constructor(\n        /**\n         * The source string represents the original template or input from which the ARE scene is generated. This can be used for debugging, error reporting, or any features that require access to the raw template data. The roots array holds references to the root nodes of the ARE scene, allowing for easy access and management of the top-level components in the rendering hierarchy. The signalsMap is a mapping between root nodes and their associated signal vectors, enabling efficient management of reactive updates and interactions within the ARE framework based on changes in the application state or user input.\n         */\n        source: string = ''\n    ) {\n        super('AreContext');\n        this._source = source;\n    }\n    /**\n     * The scope of the context, which can be used to access other entities and features within the same scope. This is particularly useful for components that need to interact with other parts of the scene or component, as it allows them to access shared data and functionality without needing to pass it explicitly through parameters.\n     */\n    get scope() {\n        return A_Context.scope(this);\n    }\n    /**\n     * The roots array holds references to the root nodes of the ARE scene, allowing for easy access and management of the top-level components in the rendering hierarchy. The signalsMap is a mapping between root nodes and their associated signal vectors, enabling efficient management of reactive updates and interactions within the ARE framework based on changes in the application state or user input.\n     */\n    get roots(): Array<AreNode> {\n        return this._roots;\n    }\n    /**\n     * This property stores a map between root node and conditions that should be met to render particular component inside the root node. This can be used to manage complex rendering logic and to optimize performance by ensuring that components are only rendered when necessary based on the defined conditions.\n     */\n    get source(): string {\n        return this._source;\n    }\n\n    get performance(): Array<string> {\n        const perfObj: Array<string> = [];\n        this._performance.forEach((value, key) => {\n            perfObj.push(`${key}: ${value} ms`);\n        });\n        return perfObj;\n    }\n\n\n    get stats() {\n        return [\n            `- Total Roots: ${this._roots.length}`,\n            `- Total Nodes in Scene: ${this._roots.reduce((acc, root) => acc + this.countNodes(root), 0,)}`,\n            `- Total Instructions: ${this._roots.reduce((acc, root) => acc + this.countInstructions(root), 0,)}`,\n        ]\n    }\n\n    protected countInstructions(node: AreNode): number {\n        let count = 0; // Count instructions for the current node\n        // Assuming each node has a method or property that returns its instructions\n        if (node.scene) {\n            count += node.scene.instructions.length;\n        }\n        for (const child of node.children) {\n            count += this.countInstructions(child); // Recursively count instructions in child nodes\n        }\n        return count;\n    }\n\n    protected countNodes(node: AreNode): number {\n        let count = 1; // Count the current node\n        for (const child of node.children) {\n            count += this.countNodes(child); // Recursively count child nodes\n        }\n        return count;\n    }\n\n    /**\n     * This property stores a map between root node and conditions that should be met to render particular component inside the root node. This can be used to manage complex rendering logic and to optimize performance by ensuring that components are only rendered when necessary based on the defined conditions.\n     * \n     * @param node \n     */\n    addRoot(node: AreNode) {\n        this._roots.push(node);\n        this.scope.register(node);\n    }\n    /**\n     * This property stores a map between root node and conditions that should be met to render particular component inside the root node. This can be used to manage complex rendering logic and to optimize performance by ensuring that components are only rendered when necessary based on the defined conditions.\n     * \n     * @param node \n     */\n    removeRoot(node: AreNode) {\n        this._roots = this._roots.filter(r => r.aseid.toString() !== node.aseid.toString());\n    }\n\n\n\n\n    startPerformance(label: string = 'default') {\n        const depth = this._performanceDepth.get(label) || 0;\n        this._performanceDepth.set(label, depth + 1);\n\n        if (depth === 0) {\n            this._performanceStart.set(label, Date.now());\n        }\n    }\n\n    endPerformance(label: string) {\n        const depth = this._performanceDepth.get(label) || 0;\n\n        if (depth <= 1) {\n            const startTime = this._performanceStart.get(label) || this._performanceStart.get('default');\n\n            if (startTime) {\n                const duration = Date.now() - startTime;\n                const accumulated = this._performance.get(label) || 0;\n                this._performance.set(label, accumulated + duration);\n                this._performanceStart.delete(label);\n            }\n\n            this._performanceDepth.delete(label);\n        } else {\n            this._performanceDepth.set(label, depth - 1);\n        }\n    }\n}\n"]}