{
  "version": 3,
  "sources": ["../../src/elements/dom.ts", "../../src/getParentComponent.ts"],
  "sourcesContent": ["/**\r\n * Finds exactly one element matching the selector. When the selector starts\r\n * with `#`, both `id` and `name` attributes are tried.\r\n *\r\n * @example\r\n *     const input = selectOne<HTMLInputElement>('#email');\r\n *     const btn = selectOne<HTMLButtonElement>('.submit', form);\r\n */\r\nexport function selectOne<T extends Element = HTMLElement>(\r\n    selector: string,\r\n    parent?: Element | Document,\r\n): T {\r\n    const root = parent ?? document;\r\n\r\n    let el: Element | null;\r\n    if (selector.startsWith('#')) {\r\n        const name = selector.slice(1);\r\n        el = root.querySelector(`#${CSS.escape(name)}`)\r\n            ?? root.querySelector(`[name=\"${name}\"]`);\r\n    } else {\r\n        el = root.querySelector(selector);\r\n    }\r\n\r\n    if (!el) {\r\n        throw new Error(`No element found matching '${selector}'`);\r\n    }\r\n\r\n    return el as T;\r\n}\r\n\r\n/**\r\n * Sets a validation error on a form field found by selector. Supports native\r\n * form elements and form-associated custom elements using `ElementInternals`.\r\n *\r\n * @example\r\n *     formError('#email', 'Please enter a valid email');\r\n *     formError('#email', ''); // clears the error\r\n */\r\nexport function formError(\r\n    selector: string,\r\n    message: string,\r\n    parent?: Element | Document,\r\n): void {\r\n    const el = selectOne<HTMLElement>(selector, parent);\r\n\r\n    if (\r\n        el instanceof HTMLInputElement\r\n        || el instanceof HTMLSelectElement\r\n        || el instanceof HTMLTextAreaElement\r\n        || el instanceof HTMLButtonElement\r\n    ) {\r\n        el.setCustomValidity(message);\r\n        el.reportValidity();\r\n        return;\r\n    }\r\n\r\n    if (\r\n        (el.constructor as any).formAssociated === true\r\n        && 'setCustomValidity' in el\r\n    ) {\r\n        (el as any).setCustomValidity(message);\r\n        (el as any).reportValidity();\r\n        return;\r\n    }\r\n\r\n    throw new Error(\r\n        `Element matching '${selector}' is not a form field`,\r\n    );\r\n}\r\n", "/**\r\n * Finds the closest parent element of a specific Web Component type.\r\n * Traverses up the DOM tree looking for an ancestor matching the constructor.\r\n *\r\n * Useful for child components that need to communicate with or access\r\n * their parent container component, common in composite component patterns.\r\n *\r\n * @template T - The type of HTMLElement to find\r\n * @param node - The starting node to search from\r\n * @param constructor - The class constructor of the desired element type\r\n * @returns The matching parent element or null if not found\r\n *\r\n * @example\r\n * // Inside a child component, find the parent container\r\n * class ListItem extends HTMLElement {\r\n *     connectedCallback() {\r\n *         const list = getParentComponent(this, ListContainer);\r\n *         if (list) {\r\n *             list.registerItem(this);\r\n *         }\r\n *     }\r\n * }\r\n *\r\n * @example\r\n * // Access parent component's methods\r\n * class TabPanel extends HTMLElement {\r\n *     activate() {\r\n *         const tabs = getParentComponent(this, TabContainer);\r\n *         tabs?.selectPanel(this);\r\n *     }\r\n * }\r\n *\r\n * @example\r\n * // Handle case where parent might not exist\r\n * const form = getParentComponent(input, FormContainer);\r\n * if (!form) {\r\n *     console.warn('Input must be inside a FormContainer');\r\n *     return;\r\n * }\r\n */\r\nexport function getParentComponent<T extends HTMLElement>(\r\n    node: Node,\r\n    constructor: { new (...args: any[]): T }\r\n): T | null {\r\n    let current = node.parentElement;\r\n\r\n    while (current) {\r\n        if (current instanceof constructor) {\r\n            return current;\r\n        }\r\n        current = current.parentElement;\r\n    }\r\n\r\n    return null;\r\n}   "],
  "mappings": "AAQO,SAASA,EACZC,EACAC,EACC,CACD,IAAMC,EAAOD,GAAU,SAEnBE,EACJ,GAAIH,EAAS,WAAW,GAAG,EAAG,CAC1B,IAAMI,EAAOJ,EAAS,MAAM,CAAC,EAC7BG,EAAKD,EAAK,cAAc,IAAI,IAAI,OAAOE,CAAI,CAAC,EAAE,GACvCF,EAAK,cAAc,UAAUE,CAAI,IAAI,CAChD,MACID,EAAKD,EAAK,cAAcF,CAAQ,EAGpC,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,8BAA8BH,CAAQ,GAAG,EAG7D,OAAOG,CACX,CAUO,SAASE,EACZL,EACAM,EACAL,EACI,CACJ,IAAME,EAAKJ,EAAuBC,EAAUC,CAAM,EAElD,GACIE,aAAc,kBACXA,aAAc,mBACdA,aAAc,qBACdA,aAAc,kBACnB,CACEA,EAAG,kBAAkBG,CAAO,EAC5BH,EAAG,eAAe,EAClB,MACJ,CAEA,GACKA,EAAG,YAAoB,iBAAmB,IACxC,sBAAuBA,EAC5B,CACGA,EAAW,kBAAkBG,CAAO,EACpCH,EAAW,eAAe,EAC3B,MACJ,CAEA,MAAM,IAAI,MACN,qBAAqBH,CAAQ,uBACjC,CACJ,CC5BO,SAASO,EACZC,EACAC,EACQ,CACR,IAAIC,EAAUF,EAAK,cAEnB,KAAOE,GAAS,CACZ,GAAIA,aAAmBD,EACnB,OAAOC,EAEXA,EAAUA,EAAQ,aACtB,CAEA,OAAO,IACX",
  "names": ["selectOne", "selector", "parent", "root", "el", "name", "formError", "message", "getParentComponent", "node", "constructor", "current"]
}
