{"version":3,"names":["OTP_VALIDATION_CONFIG","numeric","slotPattern","getRootPattern","length","regexp","inputMode","alpha","alphanumeric","getOTPValidationConfig","validationType","stripOTPWhitespace","value","replace","normalizeOTPValue","sanitizeValue","sanitizedValue","validation","Array","from","slice","Math","max","join","replaceOTPValue","currentValue","index","nextValue","normalizedValue","prefix","suffix","removeOTPCharacter"],"sources":["otp.ts"],"sourcesContent":["/**\n * Pure helpers shared between `<OTPField.Root>` and `<OTPField.Input>`. These\n * mirror Base UI React's `packages/react/src/otp-field/utils/otp.ts`\n * one-for-one — they are plain, non-reactive functions, safe to call from any\n * scope.\n */\n\ninterface OTPValidationConfig {\n\tslotPattern: string;\n\tgetRootPattern: (length: number) => string;\n\tregexp: RegExp;\n\tinputMode: \"numeric\" | \"text\";\n}\n\nexport type OTPValidationType = \"numeric\" | \"alpha\" | \"alphanumeric\" | \"none\";\n\nconst OTP_VALIDATION_CONFIG: Record<\n\tExclude<OTPValidationType, \"none\">,\n\tOTPValidationConfig\n> = {\n\tnumeric: {\n\t\tslotPattern: \"\\\\d{1}\",\n\t\tgetRootPattern: (length) => `\\\\d{${length}}`,\n\t\tregexp: /[^\\d]/g,\n\t\tinputMode: \"numeric\",\n\t},\n\talpha: {\n\t\tslotPattern: \"[a-zA-Z]{1}\",\n\t\tgetRootPattern: (length) => `[a-zA-Z]{${length}}`,\n\t\tregexp: /[^a-zA-Z]/g,\n\t\tinputMode: \"text\",\n\t},\n\talphanumeric: {\n\t\tslotPattern: \"[a-zA-Z0-9]{1}\",\n\t\tgetRootPattern: (length) => `[a-zA-Z0-9]{${length}}`,\n\t\tregexp: /[^a-zA-Z0-9]/g,\n\t\tinputMode: \"text\",\n\t},\n};\n\nexport function getOTPValidationConfig(\n\tvalidationType: OTPValidationType,\n): OTPValidationConfig | null {\n\tif (validationType === \"none\") return null;\n\treturn OTP_VALIDATION_CONFIG[validationType];\n}\n\nexport function stripOTPWhitespace(value: string | null | undefined): string {\n\treturn (value ?? \"\").replace(/\\s/g, \"\");\n}\n\n/**\n * Normalize user-entered OTP text by stripping whitespace, applying validation\n * or custom sanitization, then clamping the final value to the configured slot\n * count. Slicing uses `Array.from` so multi-byte characters stay atomic.\n */\nexport function normalizeOTPValue(\n\tvalue: string | null | undefined,\n\tlength: number,\n\tvalidationType: OTPValidationType,\n\tsanitizeValue?: ((value: string) => string) | undefined,\n): string {\n\tlet sanitizedValue = stripOTPWhitespace(value);\n\tconst validation = getOTPValidationConfig(validationType);\n\n\tif (validation) {\n\t\tsanitizedValue = sanitizedValue.replace(validation.regexp, \"\");\n\t} else if (sanitizeValue) {\n\t\tsanitizedValue = sanitizeValue(sanitizedValue);\n\t}\n\n\treturn Array.from(sanitizedValue).slice(0, Math.max(length, 0)).join(\"\");\n}\n\n/**\n * Replace characters starting at the provided slot index, then re-normalize\n * the result. Used by typing / paste flows where a multi-character edit must\n * stay contiguous and length-bounded.\n */\nexport function replaceOTPValue(\n\tcurrentValue: string,\n\tindex: number,\n\tnextValue: string,\n\tlength: number,\n\tvalidationType: OTPValidationType,\n\tsanitizeValue?: ((value: string) => string) | undefined,\n): string {\n\tconst normalizedValue = normalizeOTPValue(\n\t\tnextValue,\n\t\tlength,\n\t\tvalidationType,\n\t\tsanitizeValue,\n\t);\n\tconst prefix = currentValue.slice(0, index);\n\tconst suffix = currentValue.slice(index + normalizedValue.length);\n\n\treturn normalizeOTPValue(\n\t\t`${prefix}${normalizedValue}${suffix}`,\n\t\tlength,\n\t\tvalidationType,\n\t\tsanitizeValue,\n\t);\n}\n\nexport function removeOTPCharacter(\n\tcurrentValue: string,\n\tindex: number,\n): string {\n\tif (index < 0 || index >= currentValue.length) {\n\t\treturn currentValue;\n\t}\n\treturn `${currentValue.slice(0, index)}${currentValue.slice(index + 1)}`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAWA,MAAMA,qBAGL,GAAG;EACHC,OAAO,EAAE;IACRC,WAAW,EAAE,QAAQ;IACrBC,cAAc,EAAGC,MAAM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