{"version":3,"file":"directive.cjs","sources":["../packages/directive/execute/execute.js","../packages/directive/adopted/adopted.js","../packages/directive/attributeChanged/attributeChanged.js","../packages/directive/attributeChanged/execute/execute.js","../packages/directive/connected/connected.js","../packages/directive/define/define.js","../packages/directive/disconnected/disconnected.js","../packages/directive/formAssociated/formAssociated.js","../packages/directive/formDisabled/formDisabled.js","../packages/directive/formReset/formReset.js","../packages/directive/formStateRestore/formStateRestore.js"],"sourcesContent":["/**\n * Creates a fluent API for executing a method after a lifecycle event.\n *\n * @param {string} method - Name of the method to execute.\n * @returns {Object} Fluent API with `on` method.\n *\n * @description\n * The `execute` function provides a fluent interface for hooking into\n * Custom Element lifecycle events. It allows you to specify a method\n * that should be executed after a particular lifecycle callback.\n *\n * @example\n * import { execute } from \"@hive/std/directive\";\n *\n * class MyComponent extends HTMLElement {\n *   constructor() {\n *     super();\n *     execute(\"init\").on(this).after(\"connectedCallback\");\n *   }\n *\n *   init() {\n *     console.log(\"Component initialized after connection\");\n *   }\n * }\n */\nconst execute = (method) => ({\n  on: (target) => ({\n    after: (event) => {\n      target[event] = new Proxy(target[event] || (() => {}), {\n        apply(original, context, args) {\n          original.apply(context, args);\n          context[method](...args);\n        },\n      });\n    },\n  }),\n});\n\nexport default execute;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when moving the Custom Element to another Document.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `adopted` decorator registers a specific method to be executed\n * automatically whenever the Custom Element is moved from one document to another,\n * using the `adoptedCallback` API with Proxy to maintain the original flow.\n *\n * @example\n * import { adopted } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   @adopted\n *   onAdopted() {\n *     console.log('Element moved to another document.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst adopted = (target, method) =>\n  execute(method).on(target).after(\"adoptedCallback\");\n\nexport default adopted;\n","import execute from \"@directive/attributeChanged/execute\";\n\n/**\n * Decorator that executes a setter when an observed attribute is changed.\n *\n * @param {string} attribute - Name of the attribute to be monitored.\n * @param {...Function} filters - Functions that transform the new value before assignment.\n * @returns {void}\n *\n * @description\n * The `attributeChanged` decorator registers the attribute as observed and\n * executes the decorated setter whenever it is changed, using\n * the `attributeChangedCallback` API. The new value can be transformed by filters.\n *\n * @example\n * import { attributeChanged } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   @attributeChanged('visible', value => value === 'true')\n *   set visible(value) {\n *     this.toggleAttribute('hidden', !value);\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst attributeChanged =\n  (attribute, ...filters) =>\n  (target, property) => {\n    execute(property)\n      .with(filters)\n      .from(target)\n      .whenAttributeChanges(attribute);\n  };\n\nexport default attributeChanged;\n","/**\n * Registra a execução de um setter ou método sempre que um atributo observado for alterado.\n *\n * @param {string|symbol} property - Nome do setter ou método a ser executado.\n * @returns {{ with: (filters: Function[]) => { from: (target: Object) => { whenAttributeChanges: (attribute: string) => void } } }}\n *\n * @description\n * A função `execute` permite registrar de forma fluente a execução de um setter ou método\n * sempre que um atributo observado for alterado, utilizando a API `attributeChangedCallback`.\n * O valor novo pode ser transformado por uma sequência de filtros definidos previamente.\n *\n * @example\n * execute('visible')\n *   .with([value => value === 'true'])\n *   .from(MyElement.prototype)\n *   .whenAttributeChanges('visible');\n */\nconst execute = (property) => ({\n  /**\n   * Define os filtros que serão aplicados ao novo valor do atributo.\n   *\n   * @param {Function[]} filters - Lista de funções de transformação para o novo valor.\n   * @returns {{ from: (target: Object) => { whenAttributeChanges: (attribute: string) => void } }}\n   */\n  with: (filters) => ({\n    /**\n     * Define o alvo (geralmente o prototype do Custom Element) onde a lógica será aplicada.\n     *\n     * @param {Object} target - Protótipo da classe onde o atributo será observado.\n     * @returns {{ whenAttributeChanges: (attribute: string) => void }}\n     */\n    from: (target) => ({\n      /**\n       * Finaliza o encadeamento: registra o atributo como observado e aplica o setter ao ser alterado.\n       *\n       * @param {string} attribute - Nome do atributo a ser monitorado.\n       * @returns {void}\n       */\n      whenAttributeChanges: (attribute) => {\n        target.constructor.observedAttributes = [\n          ...new Set([\n            ...(target.constructor.observedAttributes || []),\n            attribute,\n          ]),\n        ];\n\n        target.attributeChangedCallback = new Proxy(\n          target.attributeChangedCallback || (() => {}),\n          {\n            apply(original, context, [name, oldValue, newValue]) {\n              original.apply(context, [name, oldValue, newValue]);\n              if (name === attribute) {\n                context[property] = filters.reduce((v, fn) => fn(v), newValue);\n              }\n            },\n          },\n        );\n      },\n    }),\n  }),\n});\n\nexport default execute;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when inserting the Custom Element into the DOM.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `connected` decorator registers a specific method to be executed\n * automatically whenever the Custom Element is connected to the DOM.\n * Internally, the registration is performed using an interceptor to ensure\n * organized and predictable execution of the decorated method.\n *\n * @example\n * import { connected } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   @connected\n *   initializeComponent() {\n *     console.log('Component connected to the DOM.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst connected = (target, method) =>\n  execute(method).on(target).after(\"connectedCallback\");\n\nexport default connected;\n","/**\n * Defines and registers a Custom Element using a decorator.\n *\n * @param {string} name - Name of the Custom Element to be registered.\n * @param {ElementDefinitionOptions} [options] - Optional Custom Element configuration.\n * @returns {(target: CustomElementConstructor) => void} - Decorator that defines the Custom Element.\n *\n * @description\n * Uses the `customElements.define` API to register a class as a Custom Element.\n * If the Custom Element is already defined, no action is taken.\n *\n * @example\n * import { define } from '@hive/std/directive';\n *\n * @define('my-element', { extends: 'div' })\n * class MyElement extends HTMLDivElement {\n *   constructor() {\n *     super();\n *     this.textContent = 'Hello, world!';\n *   }\n * }\n */\nconst define = (name, options) => (target) =>\n  customElements.get(name) ?? customElements.define(name, target, options);\n\nexport default define;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when removing the Custom Element from the DOM.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `disconnected` decorator registers a specific method to be executed\n * automatically whenever the Custom Element is disconnected from the DOM,\n * using the `disconnectedCallback` API with Proxy to maintain the original flow.\n *\n * @example\n * import { disconnected } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   @disconnected\n *   cleanup() {\n *     console.log('Element removed from the DOM.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst disconnected = (target, method) =>\n  execute(method).on(target).after(\"disconnectedCallback\");\n\nexport default disconnected;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when the Custom Element is associated with a form.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `formAssociated` decorator registers a specific method to be executed\n * automatically when the Custom Element is associated with a `<form>`, using\n * the `formAssociatedCallback` API with Proxy to maintain the original flow.\n *\n * @example\n * import { formAssociated } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   static formAssociated = true;\n *\n *   @formAssociated\n *   onFormAssociated() {\n *     console.log('Element associated with form.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst formAssociated = (target, method) =>\n  execute(method).on(target).after(\"formAssociatedCallback\");\n\nexport default formAssociated;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when disabling the Custom Element via form.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `formDisabled` decorator registers a specific method to be executed\n * automatically when the Custom Element is disabled via form,\n * using the `formDisabledCallback` API with Proxy to maintain the original flow.\n *\n * @example\n * import { formDisabled } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   static formAssociated = true;\n *\n *   @formDisabled\n *   onFormDisabled() {\n *     console.log('Element disabled by form.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst formDisabled = (target, method) =>\n  execute(method).on(target).after(\"formDisabledCallback\");\n\nexport default formDisabled;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when resetting the form associated with the Custom Element.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `formReset` decorator registers a specific method to be executed\n * automatically when the form associated with the Custom Element is reset,\n * using the `formResetCallback` API with Proxy to maintain the original flow.\n *\n * @example\n * import { formReset } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   static formAssociated = true;\n *\n *   @formReset\n *   onFormReset() {\n *     console.log('Form reset.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst formReset = (target, method) =>\n  execute(method).on(target).after(\"formResetCallback\");\n\nexport default formReset;\n","import execute from \"@directive/execute\";\n\n/**\n * Decorator that executes a method when restoring the state of the associated form.\n *\n * @param {Object} target - Prototype of the decorated Custom Element.\n * @param {string|Symbol} method - Name of the method to be executed.\n * @returns {void}\n *\n * @description\n * The `formStateRestore` decorator registers a specific method to be executed\n * automatically when the form associated with the Custom Element has its state restored,\n * using the `formStateRestoreCallback` API with Proxy to maintain the original flow.\n *\n * @example\n * import { formStateRestore } from '@hive/std/directive';\n *\n * class MyElement extends HTMLElement {\n *   static formAssociated = true;\n *\n *   @formStateRestore\n *   onFormStateRestore() {\n *     console.log('Form state restored.');\n *   }\n * }\n *\n * customElements.define('my-element', MyElement);\n */\nconst formStateRestore = (target, method) =>\n  execute(method).on(target).after(\"formStateRestoreCallback\");\n\nexport default formStateRestore;\n"],"names":["execute","method","on","target","after","event","Proxy","original","context","args","apply","attribute","filters","property","with","from","whenAttributeChanges","constructor","observedAttributes","Set","attributeChangedCallback","name","oldValue","newValue","reduce","v","fn","options","customElements","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