Skip to content

Accessing the raw values of semantic tokens. #2200

Answered by astahmer
MeanBoyCousin asked this question in Q&A
Discussion options

You must be logged in to vote

semanticTokens don't really have "raw" values as this depends heavily on the current condition (CSS selector/at-rule) applied
if this is something you need to do at runtime, you can do something like this (thanks gpt)

function getComputedCSSVariableValue(variable) {
    let value = getComputedStyle(document.documentElement).getPropertyValue(variable);

    while (value.startsWith('var(')) {
        // Extract the name of the referenced variable
        let referencedVarName = value.slice(4, value.length - 1);
        value = getComputedStyle(document.documentElement).getPropertyValue(referencedVarName);
    }

    return value.trim();
}

// Usage example
let computedValue = getComputedCSS…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by MeanBoyCousin
Comment options

You must be logged in to vote
3 replies
@theMasix
Comment options

@MeanBoyCousin
Comment options

@theMasix
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants