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MAAA,CAAO;AAAA,IACd,MAAM,oBAAA,CAAqB,MAAA;AAAA,IAC3B,KAAA,EAAO,CAAC,qBAAqB;AAAA,GAChC,CAAA;AAAA,EAEI,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,OAAO,CAAA,CAAA;AAAA,EAChB,4BAAS,SAAS,CAAA,CAAA;AAAA,EAClB,4BAAS,QAAQ,CAAA;AAAA,CAAA,EA/Lb,gBAAA,CA2LT,SAAA,EAAA,0BAAA,EAAA,CAAA,CAAA;AA3LS,gBAAA,GAAN,eAAA,CAAA;AAAA,EAJN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACY,gBAAA,CAAA","file":"AreHTML.lifecycle.mjs","sourcesContent":["import { A_Caller, A_Feature, A_FormatterHelper, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { AreLifecycle, AreScene, AreAttributeFeatures, AreSignalsContext, AreNodeFeatures, AreFeatures } from \"@adaas/are\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreComponentNode } from \"@adaas/are-html/nodes/AreComponent\";\nimport { AreRootNode } from \"@adaas/are-html/nodes/AreRoot\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreDirectiveFeatures } from \"@adaas/are-html/directive/AreDirective.constants\";\nimport { AreHTMLEngineContext } from \"./AreHTML.context\";\nimport { AreHTMLNode } from \"../lib/AreHTMLNode/AreHTMLNode\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n    namespace: 'a-are-html',\n    description: 'HTML-specific lifecycle handler extending AreLifecycle. Wires DOM-aware init hooks for component nodes, root nodes, interpolations, text nodes, and directive attributes to the ARE rendering pipeline, connecting each entity to its HTML engine context and priming the scene for subsequent compilation and interpretation.'\n})\nexport class AreHTMLLifecycle extends AreLifecycle {\n\n    @AreLifecycle.Init(AreComponentNode)\n    initComponent(\n        @A_Inject(A_Caller) node: AreHTMLNode,\n        @A_Inject(A_Scope) scope: A_Scope,\n        @A_Inject(AreHTMLEngineContext) context: AreHTMLEngineContext,\n        @A_Inject(AreSignalsContext) signalsContext?: AreSignalsContext,\n        @A_Inject(A_Logger) logger?: A_Logger,\n        ...args: any[]\n    ): void {\n\n        if (node.component)\n            signalsContext?.subscribe(node);\n\n        super.init(node, scope, context, logger, ...args);\n    }\n\n\n    @AreLifecycle.Init(AreRootNode)\n    initRoot(\n        @A_Inject(A_Caller) node: AreHTMLNode,\n        @A_Inject(A_Scope) scope: A_Scope,\n        @A_Inject(AreHTMLEngineContext) context: AreHTMLEngineContext,\n        @A_Inject(AreSignalsContext) signalsContext?: AreSignalsContext,\n        @A_Inject(A_Logger) logger?: A_Logger,\n        ...args: any[]\n    ): void {\n        signalsContext?.subscribe(node);\n        super.init(node, scope, context, logger, ...args);\n    }\n\n\n    @AreLifecycle.Init(AreText)\n    initText(\n        @A_Inject(A_Caller) node: AreHTMLNode,\n        @A_Inject(A_Scope) scope: A_Scope,\n        @A_Inject(AreHTMLEngineContext) context: AreHTMLEngineContext,\n        @A_Inject(A_Logger) logger?: A_Logger,\n        ...args: any[]\n    ): void {\n        const scene = new AreScene(node.aseid);\n\n        scope.register(scene);\n    }\n\n\n    @AreLifecycle.Init(AreInterpolation)\n    initInterpolation(\n        @A_Inject(A_Caller) node: AreHTMLNode,\n        @A_Inject(A_Scope) scope: A_Scope,\n        @A_Inject(AreHTMLEngineContext) context: AreHTMLEngineContext,\n        @A_Inject(A_Logger) logger?: A_Logger,\n        ...args: any[]\n    ): void {\n        const scene = new AreScene(node.aseid);\n\n        scope.register(scene);\n    }\n\n    @A_Feature.Extend({\n        name: AreNodeFeatures.onMount,\n        scope: [AreHTMLNode]\n    })\n    mount(\n        /**\n         * Node to be mounted\n         */\n        @A_Inject(A_Caller) node: AreHTMLNode,\n        /**\n         * Node Content\n         */\n        @A_Inject(AreScene) scene: AreScene,\n\n        @A_Inject(A_Logger) logger?: A_Logger,\n        ...args: any[]\n    ): void | Promise<void> {\n\n        logger?.debug(`[Mount] Component Trigger for <${node.aseid.entity}>  with aseid :{${node.aseid.toString()}}`);\n\n        /**\n         * Skip mounting nodes whose scene has been deactivated (e.g. $if template nodes\n         * when the condition is false). Mirrors the guard in AreLifecycle.mount.\n         */\n        if (scene.isInactive) return;\n\n        /**\n         * Open a batching scope for the whole (synchronous) mount pass. Every\n         * element created below is built into a *detached* root and attached to\n         * the live DOM only when the batch flushes — turning O(nodes) reflows into\n         * a single one per mount root. `try/finally` guarantees the batch closes\n         * (and the depth counter stays balanced) even if interpretation throws.\n         *\n         * The context is resolved from the node's scope (the scope the onMount\n         * feature runs in) so the override keeps the base `mount` signature.\n         */\n        const context = node.scope.resolve<AreHTMLEngineContext>(AreHTMLEngineContext);\n\n        context?.beginBatch();\n\n        /**\n         * `onAfterMount` must observe the node already connected to the live\n         * document (consumer components may measure layout / focus there). Since\n         * the subtree is built off-document and attached only when the batch\n         * flushes, we collect the post-order `onAfterMount` targets here and fire\n         * them once the flush has connected everything.\n         */\n        const afterMountQueue: AreHTMLNode[] = [];\n\n        try {\n            /**\n             * 1. Render the root of this mount itself.\n             */\n            node.interpret();\n\n            /**\n             * 2. Walk the descendant subtree iteratively with an explicit enter/exit\n             *    stack. We keep the iterative (non-recursive) shape — it is cheaper\n             *    than deep recursion and gives us a single, clear place that owns the\n             *    per-node hook ordering:\n             *      - enter  → onBeforeMount, then (if active) interpret + queue children\n             *      - exit   → onAfterMount (fires AFTER the node's whole subtree, i.e.\n             *                 post-order, matching the recursive `node.mount()` contract)\n             *\n             * [!] The initial mount is intentionally ATOMIC (fully synchronous). It\n             *     does NOT time-slice / yield. Yielding mid-walk exposes a partially\n             *     mounted tree to the event loop: any update dispatched during a gap\n             *     (signal-driven re-render, async data load, etc.) interprets a node\n             *     whose parent has not been mounted yet — producing\n             *     `mount-point-not-found` and out-of-order DOM. The whole page must\n             *     therefore appear in the DOM in one uninterrupted pass. Heavy lists\n             *     are sliced at the source instead (see AreDirectiveFor), where the\n             *     batching is reentrancy-safe.\n             */\n            interface MountFrame { node: AreHTMLNode; entered: boolean; }\n\n            const stack: MountFrame[] = [];\n            for (let i = node.children.length - 1; i >= 0; i--) {\n                stack.push({ node: node.children[i] as AreHTMLNode, entered: false });\n            }\n\n            while (stack.length > 0) {\n                const frame = stack[stack.length - 1];\n                const current = frame.node;\n\n                if (frame.entered) {\n                    // Post-order exit: the whole subtree below `current` is mounted.\n                    // Defer the onAfterMount hook until after the batch flush so the\n                    // node is connected to the live DOM when it runs.\n                    stack.pop();\n                    afterMountQueue.push(current);\n                    continue;\n                }\n\n                frame.entered = true;\n\n                // onBeforeMount always fires (even for inactive nodes), matching the\n                // recursive AreNode.mount() semantics.\n                current.call(AreNodeFeatures.onBeforeMount, current.scope);\n\n                if (!current.scene.isInactive) {\n                    current.interpret();\n                    // Push children in reverse so they pop in document order.\n                    for (let i = current.children.length - 1; i >= 0; i--) {\n                        stack.push({ node: current.children[i] as AreHTMLNode, entered: false });\n                    }\n                }\n            }\n        } finally {\n            // Flush the deferred attachments — the fully built subtree lands in the\n            // live DOM in a single pass.\n            context?.endBatch();\n        }\n\n        // The subtree is now connected; fire onAfterMount in the original\n        // post-order, each with its node live in the document.\n        for (let i = 0; i < afterMountQueue.length; i++) {\n            const mounted = afterMountQueue[i];\n            mounted.call(AreNodeFeatures.onAfterMount, mounted.scope);\n        }\n    }\n\n\n    @A_Feature.Extend({\n        name: AreAttributeFeatures.Update,\n        scope: [AreDirectiveAttribute],\n    })\n    updateDirectiveAttribute(\n        @A_Inject(A_Caller) directive: AreDirectiveAttribute,\n        @A_Inject(A_Scope) scope: A_Scope,\n        @A_Inject(A_Feature) feature: A_Feature,\n        @A_Inject(A_Logger) logger?: A_Logger,\n        ...args: any[]\n    ) {\n        /**\n         * 3. If the attribute is a directive, then we should find a component that is responsible for\n         *    the directive compiling logic, and call it. \n         *    In case component is not found we just want to log a warning, \n         *    since the directive may be handled by some parent component or simply is a mistake in the template.\n         */\n        if (directive.component) {\n            feature.chain(directive.component, AreDirectiveFeatures.Update, directive.owner.scope);\n        } else {\n            logger?.warning(`Directive handler component not found for directive: ${directive.name}. Make sure to create a component named \"AreDirective${A_FormatterHelper.toPascalCase(directive.name)}\" to handle this directive.`);\n        }\n    }\n\n}"]}