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adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreScene, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { HideElementInstruction } from \"@adaas/are-html/instructions/HideElement.instruction\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n\n/**\n * `$show` directive — conditionally toggles an element's visibility.\n *\n * Unlike `$if`, `$show` keeps the element fully mounted at all times and only\n * flips its inline `display` (Vue `v-show` semantics). The element's subtree,\n * event listeners and scene state are preserved across toggles, which makes it\n * far cheaper than `$if` for things that flip on/off frequently. Use `$if` when\n * the hidden branch is expensive and rarely shown; use `$show` when it toggles\n * often.\n *\n * ⚠️ Known limitations:\n *  - Do NOT combine `$show` with `$if`/`$for` on the SAME element — they share\n *    an owner node and would fight over its host instruction. Wrap one in a\n *    parent element instead.\n *  - `$show` forces inline `display:none`, which beats stylesheet rules but will\n *    NOT override the element's own inline `:style=\"display:...\"` binding.\n */\n@A_Frame.Define({\n    namespace: 'a-are-html',\n    description: 'Built-in $show directive. Toggles an element\\'s visibility by flipping its inline display value based on a store expression, keeping the element mounted (subtree, listeners and scene state preserved) instead of unmounting it like $if.'\n})\n@AreDirective.Priority(3)\nexport class AreDirectiveShow extends AreDirective {\n\n\n    @AreDirective.Transform\n    transform(\n        @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n        @A_Inject(A_Logger) logger: A_Logger,\n        ...args: any[]\n    ) {\n        // $show makes no structural change to the tree — the element stays in\n        // place and is only hidden/shown at interpret time. Nothing to do here\n        // beyond overriding the base directive's default transform warning.\n        logger.debug(`[Transform] directive $SHOW for <${attribute.owner.aseid.toString()}> (no structural change)`)\n    }\n\n\n    @AreDirective.Compile\n    compile(\n        @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n        @A_Inject(AreStore) store: AreStore,\n        @A_Inject(AreScene) scene: AreScene,\n        @A_Inject(AreSyntax) syntax: AreSyntax,\n\n        @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n        ...args: any[]\n    ): void {\n        /**\n         * 1. Evaluate the expression to determine the initial visibility.\n         */\n        const visible = !!syntax.evaluate(attribute.content, store, {\n            ...(directiveContext?.scope || {}),\n        });\n\n        attribute.value = visible;\n\n        /**\n         * 2. Create a single reusable HideElement mutation parented to the\n         *    element's host instruction, and cache it on the attribute so\n         *    update() can plan/unplan the exact same instance.\n         */\n        const hide = new HideElementInstruction(scene.host!, {});\n        attribute.cache = hide;\n\n        /**\n         * 3. When initially hidden, plan the mutation so the first interpret\n         *    applies `display:none`. When visible, leave it unplanned.\n         */\n        if (!visible)\n            scene.plan(hide);\n    }\n\n\n    @AreDirective.Update\n    update(\n        @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n        @A_Inject(AreStore) store: AreStore,\n        @A_Inject(AreScene) scene: AreScene,\n        @A_Inject(AreSyntax) syntax: AreSyntax,\n\n        @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n        ...args: any[]\n    ): void {\n        /**\n         * 1. Re-evaluate the expression, forwarding the directive context scope\n         *    (e.g. a `$for` loop variable) so `$show` reacts correctly inside\n         *    loops.\n         */\n        const previous = !!attribute.value;\n        const next = !!syntax.evaluate(attribute.content, store, {\n            ...(directiveContext?.scope || {}),\n        });\n\n        attribute.value = next;\n\n        // Skip when visibility has not changed — avoids redundant DOM writes.\n        if (previous === next) return;\n\n        const hide = attribute.cache as HideElementInstruction | undefined;\n\n        if (!hide) return;\n\n        /**\n         * 2. Toggle the cached mutation: unplan to reveal, plan to hide. Then\n         *    re-interpret the owner so the scene diff applies/reverts it.\n         */\n        if (next)\n            scene.unPlan(hide);\n        else\n            scene.plan(hide);\n\n        attribute.owner.interpret();\n    }\n\n}\n"]}