cssVars.ts 605 B

123456789101112131415161718192021222324
  1. /**
  2. * Normalize CSS var value created by `v-bind` in `<style>` block
  3. * See https://github.com/vuejs/core/pull/12461#issuecomment-2495804664
  4. */
  5. export function normalizeCssVarValue(value: unknown): string {
  6. if (value == null) {
  7. return 'initial'
  8. }
  9. if (typeof value === 'string') {
  10. return value === '' ? ' ' : value
  11. }
  12. if (typeof value !== 'number' || !Number.isFinite(value)) {
  13. if (__DEV__) {
  14. console.warn(
  15. '[Vue warn] Invalid value used for CSS binding. Expected a string or a finite number but received:',
  16. value,
  17. )
  18. }
  19. }
  20. return String(value)
  21. }