{"version":3,"file":"getNumberFromStyle.mjs","sources":["../../../src/core/utils/getNumberFromStyle.ts"],"sourcesContent":["import { type NumberValue, type PositionKeyword } from '../types';\n\n/**\n * Converts a style value to a number. If the value is a percentage string,\n * it calculates the number based on the given size.\n *\n * @param value - The style value to convert. It can be a number or a percentage string (e.g., '50%').\n * @param size - The size to use for percentage calculations.\n * @returns The numeric value. If the input is a percentage string, it returns the calculated number based on the size.\n *          If the input is a number, it returns the number itself. If the input is neither, it returns 0.\n */\nexport function getNumberFromStyle(value: NumberValue, size?: number): number {\n    if (!value) return 0;\n    if (typeof value === 'number') {\n        // If the value is already a number, return it as is.\n        return value;\n    } else if (typeof value === 'string' && value.endsWith('%')) {\n        size ??= 1;\n\n        // If the value is a percentage string, calculate the number based on the size.\n        return size * (parseFloat(value) / 100);\n    } else if (!Number.isNaN(parseFloat(value))) {\n        // If the value is a number string, parse it as a number.\n        return parseFloat(value);\n    }\n\n    // If the value is neither a number nor a percentage string, return the value as a number.\n    return 0;\n}\n\n/**\n * Determines the type of a style value.\n *\n * @param value - The style value to check.\n * @returns The type of the style value. It can be 'number', 'percentage', or 'keyword'.\n */\nexport function getTypeFromStyle(value: NumberValue | PositionKeyword): 'number' | 'percentage' | 'keyword' {\n    if (typeof value === 'number') return 'number';\n    if (value.endsWith('%')) return 'percentage';\n    if (Number.isNaN(parseInt(value, 10))) return 'keyword';\n\n    return 'number';\n}\n"],"names":[],"mappings":"AAWgB,SAAA,mBAAmB,OAAoB,MAAuB;AACtE,MAAA,CAAC,MAAc,QAAA;AACf,MAAA,OAAO,UAAU,UAAU;AAEpB,WAAA;AAAA,EAAA,WACA,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG,GAAG;AAChD,oBAAA;AAGF,WAAA,QAAQ,WAAW,KAAK,IAAI;AAAA,EAAA,WAC5B,CAAC,OAAO,MAAM,WAAW,KAAK,CAAC,GAAG;AAEzC,WAAO,WAAW,KAAK;AAAA,EAAA;AAIpB,SAAA;AACX;AAQO,SAAS,iBAAiB,OAA2E;AACpG,MAAA,OAAO,UAAU,SAAiB,QAAA;AACtC,MAAI,MAAM,SAAS,GAAG,EAAU,QAAA;AAChC,MAAI,OAAO,MAAM,SAAS,OAAO,EAAE,CAAC,EAAU,QAAA;AAEvC,SAAA;AACX;"}