Referencing in JavaScript
Most of the time when you need to reference your theme variables in JS you can just use the CSS variables directly, just like any other CSS value.
For example, the popular Motion library for React lets you animate to and from CSS variable values:
<motion.div animate={{ backgroundColor: "var(--color-blue-500)" }} />
If you need access to a resolved CSS variable value in JS, you can use getComputedStyle to get the value of a theme variable on the document root:
let styles = getComputedStyle(document.documentElement)
let shadow = styles.getPropertyValue('--shadow-xl')