{"version":3,"file":"percent.mjs","names":[],"sources":["../../../src/parser/percent.ts"],"sourcesContent":["import { ifNaN } from '../util/internals/ifNaN';\nimport { capValue } from '../util/misc/capValue';\n\n/**\n * Will loosely accept as percent numbers that are not like\n * 3.4a%. This function does not check for the correctness of a percentage\n * but it checks that values that are in theory correct are or arent percentages\n */\nexport function isPercent(value: string | null) {\n  // /%$/ Matches strings that end with a percent sign (%)\n  return value && /%$/.test(value) && Number.isFinite(parseFloat(value));\n}\n\n/**\n * Parse a percentage value in an svg.\n * @param value\n * @param fallback in case of not possible to parse the number\n * @returns ∈ [0, 1]\n */\nexport function parsePercent(\n  value: string | number | null | undefined,\n  valueIfNaN?: number,\n): number {\n  const parsed =\n    typeof value === 'number'\n      ? value\n      : typeof value === 'string'\n        ? parseFloat(value) / (isPercent(value) ? 100 : 1)\n        : NaN;\n  return capValue(0, ifNaN(parsed, valueIfNaN), 1);\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,UAAU,OAAsB;AAE9C,QAAO,SAAS,KAAK,KAAK,MAAM,IAAI,OAAO,SAAS,WAAW,MAAM,CAAC;;;;;;;;AASxE,SAAgB,aACd,OACA,YACQ;AAOR,QAAO,SAAS,GAAG,MALjB,OAAO,UAAU,WACb,QACA,OAAO,UAAU,WACf,WAAW,MAAM,IAAI,UAAU,MAAM,GAAG,MAAM,KAC9C,KACyB,WAAW,EAAE,EAAE"}