Track theme variables
This commit is contained in:
parent
3bc80cda67
commit
3143eb6e7a
2 changed files with 14 additions and 5 deletions
|
|
@ -541,7 +541,7 @@ async function parseCss(
|
|||
|
||||
if (child.kind === 'comment') return
|
||||
if (child.kind === 'declaration' && child.property.startsWith('--')) {
|
||||
theme.add(unescape(child.property), child.value ?? '', themeOptions)
|
||||
theme.add(unescape(child.property), child.value ?? '', themeOptions, child.src)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -559,6 +559,7 @@ async function parseCss(
|
|||
// theme later, and delete any other `@theme` rules.
|
||||
if (!firstThemeRule) {
|
||||
firstThemeRule = styleRule(':root, :host', [])
|
||||
firstThemeRule.src = node.src
|
||||
replaceWith([firstThemeRule])
|
||||
} else {
|
||||
replaceWith([])
|
||||
|
|
@ -607,6 +608,7 @@ async function parseCss(
|
|||
for (let [key, value] of designSystem.theme.entries()) {
|
||||
if (value.options & ThemeOptions.REFERENCE) continue
|
||||
let node = decl(escape(key), value.value)
|
||||
node.src = value.src
|
||||
nodes.push(node)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { type AtRule } from './ast'
|
||||
import { type AtRule, type Declaration } from './ast'
|
||||
import { escape, unescape } from './utils/escape'
|
||||
|
||||
export const enum ThemeOptions {
|
||||
|
|
@ -40,11 +40,18 @@ export class Theme {
|
|||
public prefix: string | null = null
|
||||
|
||||
constructor(
|
||||
private values = new Map<string, { value: string; options: ThemeOptions }>(),
|
||||
private values = new Map<
|
||||
string,
|
||||
{
|
||||
value: string
|
||||
options: ThemeOptions
|
||||
src: Declaration['src']
|
||||
}
|
||||
>(),
|
||||
private keyframes = new Set<AtRule>([]),
|
||||
) {}
|
||||
|
||||
add(key: string, value: string, options = ThemeOptions.NONE): void {
|
||||
add(key: string, value: string, options = ThemeOptions.NONE, src?: Declaration['src']): void {
|
||||
if (key.endsWith('-*')) {
|
||||
if (value !== 'initial') {
|
||||
throw new Error(`Invalid theme value \`${value}\` for namespace \`${key}\``)
|
||||
|
|
@ -68,7 +75,7 @@ export class Theme {
|
|||
if (value === 'initial') {
|
||||
this.values.delete(key)
|
||||
} else {
|
||||
this.values.set(key, { value, options })
|
||||
this.values.set(key, { value, options, src })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue