{"version":3,"file":"Element.cjs","sources":["../../src/core/Element.js"],"sourcesContent":["import getAttributesDiff from '../utils/getAttributesDiff.js';\n\nconst SYNC_PROPS = ['value', 'checked', 'selected'];\n\n/**\n * Element reference for managing DOM element attributes.\n * @param {Object} options The options object.\n * @param {Function} options.getSelector Function that returns the CSS selector for the element.\n * @param {Function} options.getAttributes Function that returns the attributes object for the element.\n * @private\n */\nclass Element {\n    constructor(options) {\n        this.getSelector = options.getSelector;\n        this.getAttributes = options.getAttributes;\n        this.previousAttributes = {};\n    }\n\n    /**\n     * Attach the element reference to a DOM element.\n     * @param {Node} parent The parent node to search in.\n     */\n    hydrate(parent) {\n        this.ref = parent.querySelector(this.getSelector());\n    }\n\n    /**\n     * Update the element's attributes based on the difference with previous attributes.\n     */\n    update() {\n        // Attributes diff.\n        const attributes = this.getAttributes();\n        const { remove, add } = getAttributesDiff(attributes, this.previousAttributes);\n        // Store previous attributes.\n        this.previousAttributes = attributes;\n        // Remove attributes first so later `setAttribute` overrides if needed.\n        remove.forEach(attr => {\n            this.ref.removeAttribute(attr);\n            if (SYNC_PROPS.indexOf(attr) !== -1 && attr in this.ref) {\n                // Reset property to default.\n                this.ref[attr] = attr === 'value' ? '' : false;\n            }\n        });\n        // Add / update attributes.\n        Object.keys(add).forEach(attr => {\n            const value = add[attr];\n            this.ref.setAttribute(attr, value);\n            if (SYNC_PROPS.indexOf(attr) !== -1 && attr in this.ref) {\n                this.ref[attr] = attr === 'value' ? value : value !== false && value !== 'false';\n            }\n        });\n    }\n}\n\nexport default Element;\n"],"names":["getAttributesDiff"],"mappings":";;;;AAEA,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,OAAO,CAAC;AACd,IAAI,WAAW,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW;AAC9C,QAAQ,IAAI,CAAC,a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