{"version":3,"names":["minMaxStepTypes","patternTypes","minMaxLengthTypes","updateConstraintValidation","inputComponent","input","propName","matchesType","attributeName","toLowerCase","value","setAttribute","removeAttribute","syncHiddenFormInput","type","hiddenFormInput","isMinMaxStepType","includes","numericInputComponent","isMinMaxLengthType","textualInputComponent","isPatternType"],"sources":["src/components/input/common/input.ts"],"sourcesContent":["export type InputComponent = NumericInputComponent | TextualInputComponent | DateTimeInputComponent;\n\nexport interface DateTimeInputComponent {\n min: string;\n max: string;\n}\n\nexport interface NumericInputComponent {\n min: number;\n max: number;\n step: number | \"any\";\n}\n\nexport interface TextualInputComponent {\n pattern?: string;\n minLength: number;\n maxLength: number;\n}\n\n/**\n * Exported for testing purposes only\n */\nexport const minMaxStepTypes = [\"date\", \"datetime-local\", \"month\", \"number\", \"range\", \"time\", \"week\"];\n\n/**\n * Exported for testing purposes only\n */\nexport const patternTypes = [\"email\", \"password\", \"search\", \"tel\", \"text\", \"url\"];\n\n/**\n * Exported for testing purposes only\n */\nexport const minMaxLengthTypes = [\"email\", \"password\", \"search\", \"tel\", \"text\", \"textarea\", \"url\"];\n\nfunction updateConstraintValidation(\n inputComponent: InputComponent,\n input: HTMLInputElement,\n propName: string,\n matchesType: boolean,\n): void {\n const attributeName = propName.toLowerCase();\n const value = inputComponent[propName];\n\n if (matchesType && value != null) {\n input.setAttribute(attributeName, `${value}`);\n } else {\n // we remove the attribute to ensure validation-constraints are properly reset\n input.removeAttribute(attributeName);\n }\n}\n\n/**\n * Synchronizes the hidden form input with the validation-related input properties.\n *\n * Note: loss of precision is expected due to the hidden input's value and validation-constraint props being strings.\n *\n * @param type - The input type.\n * @param inputComponent\n * @param hiddenFormInput\n */\nexport function syncHiddenFormInput(\n type: HTMLInputElement[\"type\"] | \"textarea\",\n inputComponent: InputComponent,\n hiddenFormInput: HTMLInputElement,\n): void {\n hiddenFormInput.type = type === \"textarea\" ? \"text\" : type;\n\n const isMinMaxStepType = minMaxStepTypes.includes(type);\n const numericInputComponent = inputComponent as NumericInputComponent;\n\n updateConstraintValidation(numericInputComponent, hiddenFormInput, \"min\", isMinMaxStepType);\n updateConstraintValidation(numericInputComponent, hiddenFormInput, \"max\", isMinMaxStepType);\n updateConstraintValidation(numericInputComponent, hiddenFormInput, \"step\", isMinMaxStepType);\n\n const isMinMaxLengthType = minMaxLengthTypes.includes(type);\n\n const textualInputComponent = inputComponent as TextualInputComponent;\n\n updateConstraintValidation(textualInputComponent, hiddenFormInput, \"minLength\", isMinMaxLengthType);\n updateConstraintValidation(textualInputComponent, hiddenFormInput, \"maxLength\", isMinMaxLengthType);\n\n const isPatternType = patternTypes.includes(type);\n\n updateConstraintValidation(textualInputComponent, hiddenFormInput, \"pattern\", isPatternType);\n}\n"],"mappings":";;;;;AAsBO,MAAMA,EAAkB,CAAC,OAAQ,iBAAkB,QAAS,SAAU,QAAS,OAAQ,QAKvF,MAAMC,EAAe,CAAC,QAAS,WAAY,SAAU,MAAO,OAAQ,OAKpE,MAAMC,EAAoB,CAAC,QAAS,WAAY,SAAU,MAAO,OAAQ,WAAY,OAE5F,SAASC,EACPC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAgBF,EAASG,cAC/B,MAAMC,EAAQN,EAAeE,GAE7B,GAAIC,GAAeG,GAAS,KAAM,CAChCL,EAAMM,aAAaH,EAAe,GAAGE,I,KAChC,CAELL,EAAMO,gBAAgBJ,E,CAE1B,C,SAWgBK,EACdC,EACAV,EACAW,GAEAA,EAAgBD,KAAOA,IAAS,WAAa,OAASA,EAEtD,MAAME,EAAmBhB,EAAgBiB,SAASH,GAClD,MAAMI,EAAwBd,EAE9BD,EAA2Be,EAAuBH,EAAiB,MAAOC,GAC1Eb,EAA2Be,EAAuBH,EAAiB,MAAOC,GAC1Eb,EAA2Be,EAAuBH,EAAiB,OAAQC,GAE3E,MAAMG,EAAqBjB,EAAkBe,SAASH,GAEtD,MAAMM,EAAwBhB,EAE9BD,EAA2BiB,EAAuBL,EAAiB,YAAaI,GAChFhB,EAA2BiB,EAAuBL,EAAiB,YAAaI,GAEhF,MAAME,EAAgBpB,EAAagB,SAASH,GAE5CX,EAA2BiB,EAAuBL,EAAiB,UAAWM,EAChF,Q","ignoreList":[]}