Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
prevent automatic var injection for properties that accept `<dashed-i…
…dent>` for the value
  • Loading branch information
RobinMalfait committed Oct 18, 2023
commit b64f2568f4a06637cd1ab5b55606baca3ff53fff
2 changes: 1 addition & 1 deletion src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ function extractArbitraryProperty(classCandidate, context) {
return null
}

let normalized = normalize(value)
let normalized = normalize(value, { property })

if (!isParsableCssValue(property, normalized)) {
return null
Expand Down
31 changes: 28 additions & 3 deletions src/util/dataTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,35 @@ function isCSSFunction(value) {
return IS_CSS_FN.test(value)
}

// These properties accept a `<dashed-ident>` as one of the values. This means that you can use them
// as: `timeline-scope: --tl;`
//
// Without the `var(--tl)`, in these cases we don't want to normalize the value, and you should add
// the `var()` yourself.
//
// More info:
// - https://drafts.csswg.org/scroll-animations/#propdef-timeline-scope
// - https://developer.mozilla.org/en-US/docs/Web/CSS/timeline-scope#dashed-ident
//
const AUTO_VAR_INJECTION_EXCEPTIONS = new Set([
// Concrete properties
'scroll-timeline-name',
'timeline-scope',
'view-timeline-name',

// Shorthand properties
'scroll-timeline',
'animation-timeline',
'view-timeline',
])

// This is not a data type, but rather a function that can normalize the
// correct values.
export function normalize(value, isRoot = true) {
if (value.startsWith('--')) {
export function normalize(value, context = null, isRoot = true) {
if (
(context ? !AUTO_VAR_INJECTION_EXCEPTIONS.has(context.property) : true) &&
value.startsWith('--')
) {
return `var(${value})`
}

Expand All @@ -28,7 +53,7 @@ export function normalize(value, isRoot = true) {
return part
}

return normalize(part, false)
return normalize(part, context, false)
})
.join('')
}
Expand Down