{"version":3,"file":"PathManager.cjs","sources":["../../src/core/PathManager.js"],"sourcesContent":["/**\n * Manager for component position tracking and recycling.\n * @private\n */\nclass PathManager {\n    constructor() {}\n\n    /**\n     * Reset before render.\n     */\n    reset() {\n        this.paused = 0;\n        this.previous = this.tracked || new Map();\n        this.tracked = new Map();\n        this.positionStack = [0];\n    }\n\n    /**\n     * Push position to stack.\n     */\n    push() {\n        this.positionStack.push(0);\n    }\n\n    /**\n     * Pop position from stack.\n     */\n    pop() {\n        this.positionStack.pop();\n    }\n\n    /**\n     * Increment position.\n     */\n    increment() {\n        this.positionStack[this.positionStack.length - 1]++;\n    }\n\n    /**\n     * Pause tracking.\n     */\n    pause() {\n        this.paused++;\n    }\n\n    /**\n     * Resume tracking.\n     */\n    resume() {\n        this.paused--;\n    }\n\n    /**\n     * Get current path as array.\n     * @return {string} Current position path.\n     */\n    getPath() {\n        return this.positionStack.join('-');\n    }\n\n    /**\n     * Track component at current path.\n     * @param {Component} component The component to track.\n     * @return {Component} The component.\n     */\n    track(component) {\n        if (this.paused === 0) {\n            this.tracked.set(\n                this.getPath(),\n                component\n            );\n        }\n\n        return component;\n    }\n\n    /**\n     * Tell if there was only one component rendered in the previous and current tracked maps\n     * and that component instance is the same (was recycled).\n     * Used by Component to detect simple single component cases and skip DOM moves.\n     * @return {boolean} Returns true when there is exactly one component at the first level\n     *                   and it was successfully recycled.\n     */\n    hasSingleComponent() {\n        if (this.tracked.size !== 1 || this.previous.size !== 1) return false;\n        const [currentPath, currentComponent] = this.tracked.entries().next().value;\n        const [previousPath, previousComponent] = this.previous.entries().next().value;\n        // Ensure the component is at the root level (path '0') so it is not part of a deeper partial/array.\n        if (currentPath !== '0' || previousPath !== '0') return false;\n        return currentComponent === previousComponent;\n    }\n\n    /**\n     * Find a recyclable component for the current path based on constructor (type)\n     * when the component is un-keyed.\n     * @param {Component} candidate The candidate component instance.\n     * @return {Component|null} The recyclable component or null if none found.\n     */\n    findRecyclable(candidate) {\n        const previous = this.previous.get(this.getPath());\n        return previous && !previous.key && previous.constructor === candidate.constructor ? previous : null;\n    }\n}\n\nexport default PathManager;\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA,MAAM,WAAW,CAAC;AAClB,IAAI,WAAW,GAAG,CAAC;;AAEnB;AACA;AACA;AACA,IAAI,KAAK,GAAG;AACZ,QAAQ,IAAI,CAAC,MAAM,GAAG,CAAC;AACvB,QAAQ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,GAAG,EAAE;AACjD,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;AAChC,QAAQ,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;AAChC,IAAI;;AAEJ;AACA;AACA;AACA,IAAI,IAAI,GAAG;AACX,QAAQ,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AAClC,IAAI;;AAEJ;AACA;AACA;AACA,IAAI,GAAG,GAAG;AACV,QAAQ,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;AAChC,IAAI;;AAEJ;AACA;AACA;AACA,IAAI,SAAS,GAAG;AAChB,QAAQ,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;AAC3D,IAAI;;AAEJ;AACA;AACA;AACA,IAAI,KAAK,GAAG;AACZ,QAAQ,IAAI,CAAC,MAAM,EAAE;AACrB,IAAI;;AAEJ;AACA;AACA;AACA,IAAI,MAAM,GAAG;AACb,QAAQ,IAAI,CAAC,MAAM,EAAE;AACrB,IAAI;;AAEJ;AACA;AACA;AACA;AACA,IAAI,OAAO,GAAG;AACd,QAAQ,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC;AAC3C,IAAI;;AAEJ;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,SAAS,EAAE;AACrB,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EA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