fix . insertion
This commit is contained in:
parent
9b6e1e91ec
commit
debfd73ab2
|
|
@ -101,7 +101,7 @@ export function stylesToCSS(): string {
|
||||||
for (const [selector, style] of Object.entries(styles)) {
|
for (const [selector, style] of Object.entries(styles)) {
|
||||||
if (Object.keys(style).length === 0) continue
|
if (Object.keys(style).length === 0) continue
|
||||||
|
|
||||||
out.push(`${expandSelector(selector)} { `)
|
out.push(`${selector} { `)
|
||||||
for (const [name, value] of Object.entries(style).sort(([a], [b]) => a.localeCompare(b)))
|
for (const [name, value] of Object.entries(style).sort(([a], [b]) => a.localeCompare(b)))
|
||||||
out.push(` ${name}: ${value};`)
|
out.push(` ${name}: ${value};`)
|
||||||
out.push(`}\n`)
|
out.push(`}\n`)
|
||||||
|
|
@ -110,10 +110,6 @@ export function stylesToCSS(): string {
|
||||||
return out.join('\n')
|
return out.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
function expandSelector(selector: string): string {
|
|
||||||
return selector.startsWith('.') ? selector : `.${selector}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// creates a CSS class name
|
// creates a CSS class name
|
||||||
function makeClassName(baseName: string, partName?: string, variantName?: string, variantKey?: string): string {
|
function makeClassName(baseName: string, partName?: string, variantName?: string, variantKey?: string): string {
|
||||||
const cls = partName ? `${baseName}_${partName}` : baseName
|
const cls = partName ? `${baseName}_${partName}` : baseName
|
||||||
|
|
@ -211,7 +207,7 @@ function stateName(state: string): string {
|
||||||
|
|
||||||
// Register base styles, selectors, and states for a class
|
// Register base styles, selectors, and states for a class
|
||||||
function registerClassStyles(name: string, className: string, def: TagDef) {
|
function registerClassStyles(name: string, className: string, def: TagDef) {
|
||||||
styles[className] ??= makeStyle(def)
|
styles[`.${className}`] ??= makeStyle(def)
|
||||||
|
|
||||||
for (let [selector, selectorDef] of Object.entries(def.selectors ?? {})) {
|
for (let [selector, selectorDef] of Object.entries(def.selectors ?? {})) {
|
||||||
selector = selector.replace(/@(\w+)/g, (_, partName) => `.${makeClassName(name, partName)}`)
|
selector = selector.replace(/@(\w+)/g, (_, partName) => `.${makeClassName(name, partName)}`)
|
||||||
|
|
@ -221,7 +217,7 @@ function registerClassStyles(name: string, className: string, def: TagDef) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [state, style] of Object.entries(def.states ?? {}))
|
for (const [state, style] of Object.entries(def.states ?? {}))
|
||||||
styles[`${className}${stateName(state)}`] = makeStyle(style)
|
styles[`.${className}${stateName(state)}`] = makeStyle(style)
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds CSS styles for tag definition
|
// adds CSS styles for tag definition
|
||||||
|
|
@ -287,7 +283,7 @@ export function define(nameOrDef: string | TagDef, defIfNamed?: TagDef) {
|
||||||
const def = defIfNamed ?? nameOrDef as TagDef
|
const def = defIfNamed ?? nameOrDef as TagDef
|
||||||
const name = defIfNamed ? (nameOrDef as string) : anonName(def)
|
const name = defIfNamed ? (nameOrDef as string) : anonName(def)
|
||||||
|
|
||||||
if (styles[name]) throw `${name} is already defined! Must use unique names.`
|
if (styles[`.${name}`]) throw `${name} is already defined! Must use unique names.`
|
||||||
registerStyles(name, def)
|
registerStyles(name, def)
|
||||||
|
|
||||||
return (props: Record<string, any>) => {
|
return (props: Record<string, any>) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user